Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.8 KB
Raw Blame
import type { LicenseNotice } from "@editor/types/types";

export const SERVER_LICENSE_REQUEST_EVENT = "stirling:server-license-requested";
export const UPGRADE_BANNER_TEST_EVENT = "stirling:upgrade-banner-test";
export const UPGRADE_BANNER_ALERT_EVENT = "stirling:upgrade-banner-alert";
export const START_TOUR_EVENT = "stirling:start-tour";
export const TOUR_STATE_EVENT = "stirling:tour-state";

export interface ServerLicenseRequestPayload {
  licenseNotice?: Partial<LicenseNotice>;
  deferUntilTourComplete?: boolean;
  selfReportedAdmin?: boolean;
}

export type UpgradeBannerTestScenario =
  | "friendly"
  | "urgent-admin"
  | "urgent-user"
  | null;

export interface UpgradeBannerTestPayload {
  scenario: UpgradeBannerTestScenario;
}

export interface UpgradeBannerAlertPayload {
  active: boolean;
  audience?: "admin" | "user";
  totalUsers?: number | null;
  freeTierLimit?: number;
}

// Open string keyed into the tour registry (see tourRegistry.ts). Kept as a
// named alias so intent is clear at call sites; known ids are "admin", "tools",
// "whatsnew" but builds/features may register their own.
export type TourType = string;

export interface StartTourPayload {
  tourType: TourType;
}

export interface TourStatePayload {
  isOpen: boolean;
}

/** Helper to dispatch the start tour event */
export function requestStartTour(tourType: TourType): void {
  if (typeof window === "undefined") return;
  window.dispatchEvent(
    new CustomEvent<StartTourPayload>(START_TOUR_EVENT, {
      detail: { tourType },
    }),
  );
}

/** Helper to dispatch tour state changes (for hiding cookie consent during tour) */
export function dispatchTourState(isOpen: boolean): void {
  if (typeof window === "undefined") return;
  window.dispatchEvent(
    new CustomEvent<TourStatePayload>(TOUR_STATE_EVENT, { detail: { isOpen } }),
  );
}