@revenuecat/purchases-ui-js
Version:
Web components for Paywalls. Powered by RevenueCat
50 lines (49 loc) • 2.74 kB
TypeScript
/**
* Runtime loader for the RevenueCat web-components HOST bridge.
*
* The host bridge is deliberately NOT bundled into purchases-ui-js. It is
* dynamic-imported from the CDN by protocol major, so a `web_view` with
* `protocol_version: N` always gets the host build that matches the content build
* injected into its iframe. Both are served from a stable, rolling per-major path:
*
* https://sdk.revenuecat-static.com/v<major>/rc-host.js (ESM, exports createHostBridge)
*
* Shipping a new SDK patch just republishes that path, so neither this code nor any
* stored bundle HTML needs to change. Embedding apps must allow the SDK origin in
* their CSP `script-src` for the module import to succeed; if it fails, the caller
* keeps the plain (render-only) iframe.
*
* Message names, payload types, and the bridge/config shapes come from
* `@revenuecat/workflow-web-components-sdk` (the source of truth) rather than being
* mirrored here; only the CDN loader is local.
*
* Operational note: compile-time types come from the pinned npm package, while the
* runtime host build is loaded from the rolling per-major CDN path (`/v<major>/rc-host.js`).
* Dynamic `import()` cannot use SRI; a failed import is handled by the caller.
*/
import type { Bridge, HostBridgeConfig } from "@revenuecat/workflow-web-components-sdk";
export { FIT_MESSAGE, RESIZE_MESSAGE, } from "@revenuecat/workflow-web-components-sdk";
export type { ResizePayload } from "@revenuecat/workflow-web-components-sdk";
/** Base origin the versioned SDK builds are served from. */
export declare const SDK_BASE_URL = "https://sdk.revenuecat-static.com";
/**
* The subset of the SDK bridge purchases-ui-js uses: subscribe to a message, run
* a callback once the channel opens, fire-and-forget, and tear down.
*/
export type WebViewHostBridge = Pick<Bridge, "on" | "onReady" | "send" | "destroy">;
export type CreateHostBridge = (config: HostBridgeConfig) => Bridge;
/** Stable, rolling per-major URL of the host bridge ESM build. */
export declare function hostSdkUrl(protocolVersion: number): string;
type ModuleImporter = (url: string) => Promise<unknown>;
/**
* Resolve `createHostBridge` for a protocol major from the CDN. Rejects if the
* module can't be loaded or doesn't export the factory, so callers can degrade to
* a render-only iframe.
*/
export declare function loadCreateHostBridge(protocolVersion: number): Promise<CreateHostBridge>;
/**
* Override the module importer (and clear the cache). Intended for tests, which
* inject a fake so no real network/module resolution happens. Pass `null` to
* restore the default dynamic import.
*/
export declare function __setHostModuleImporterForTests(fn: ModuleImporter | null): void;