@superwall/runtime 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +93 -0
  3. package/dist/bridge/base64.d.ts +9 -0
  4. package/dist/bridge/base64.js +34 -0
  5. package/dist/bridge/index.d.ts +30 -0
  6. package/dist/bridge/index.js +49 -0
  7. package/dist/bridge/transport.d.ts +14 -0
  8. package/dist/bridge/transport.js +43 -0
  9. package/dist/config.d.ts +237 -0
  10. package/dist/config.js +138 -0
  11. package/dist/index.d.ts +12 -0
  12. package/dist/index.js +11 -0
  13. package/dist/localization/index.d.ts +24 -0
  14. package/dist/localization/index.js +71 -0
  15. package/dist/localization/periods.d.ts +1 -0
  16. package/dist/localization/periods.js +753 -0
  17. package/dist/mock.d.ts +74 -0
  18. package/dist/mock.js +206 -0
  19. package/dist/products.d.ts +62 -0
  20. package/dist/products.js +105 -0
  21. package/dist/session/index.d.ts +103 -0
  22. package/dist/session/index.js +732 -0
  23. package/dist/session/state.d.ts +27 -0
  24. package/dist/session/state.js +60 -0
  25. package/dist/session/types.d.ts +93 -0
  26. package/dist/session/types.js +1 -0
  27. package/dist/session/variables.d.ts +121 -0
  28. package/dist/session/variables.js +5 -0
  29. package/package.json +51 -0
  30. package/src/bridge/base64.ts +56 -0
  31. package/src/bridge/index.ts +77 -0
  32. package/src/bridge/transport.ts +63 -0
  33. package/src/config.ts +408 -0
  34. package/src/index.ts +57 -0
  35. package/src/localization/index.ts +110 -0
  36. package/src/localization/periods.ts +790 -0
  37. package/src/mock.ts +333 -0
  38. package/src/products.ts +221 -0
  39. package/src/session/index.ts +1066 -0
  40. package/src/session/state.ts +112 -0
  41. package/src/session/types.ts +123 -0
  42. package/src/session/variables.ts +139 -0
package/dist/mock.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ import type { ITransport, TIncomingHandler, TIncomingMessage, TIncomingMessageCallbackResult, TOutgoingMessage, TPermissionStatus, TPermissionTypeMessage } from "@superwall/protocol";
2
+ import { type SuperwallConfig } from "./config";
3
+ import { type SuperwallProduct, type SuperwallProductInput } from "./products";
4
+ import type { SuperwallDeviceVariables, SuperwallExperiment, SuperwallPlacementParams, SuperwallUserVariables } from "./session/variables";
5
+ export type SuperwallMockPurchaseOutcome = "completed" | "abandoned";
6
+ export type SuperwallMockPurchaseContext = {
7
+ reference: string;
8
+ productIdentifier?: string;
9
+ };
10
+ export type SuperwallMockCallbackResult = {
11
+ status: TIncomingMessageCallbackResult["status"];
12
+ data?: Record<string, unknown>;
13
+ };
14
+ export type SuperwallMockOptions = {
15
+ /** Identity sent in `paywall_open`. */
16
+ paywall?: {
17
+ id?: string;
18
+ identifier?: string;
19
+ };
20
+ /**
21
+ * Products the mock SDK delivers. Defaults to the config's product slots,
22
+ * carrying only the product identifier — real product data comes from
23
+ * Superwall, never from the mock.
24
+ */
25
+ products?: readonly SuperwallProductInput[];
26
+ /** Device variables merged over the mock defaults. */
27
+ device?: SuperwallDeviceVariables;
28
+ /** User attributes delivered with template variables. */
29
+ user?: SuperwallUserVariables;
30
+ /** Placement params delivered with template variables. */
31
+ params?: SuperwallPlacementParams;
32
+ /** Experiment assignment to report. Omitted by default. */
33
+ experiment?: SuperwallExperiment;
34
+ /** Extra top-level template variables. */
35
+ variables?: Record<string, unknown>;
36
+ /**
37
+ * Introductory-offer eligibility the mock reports. Defaults to true when
38
+ * any product has trial variables.
39
+ */
40
+ trialEligible?: boolean;
41
+ purchaseOutcome?: SuperwallMockPurchaseOutcome | ((context: SuperwallMockPurchaseContext) => SuperwallMockPurchaseOutcome | Promise<SuperwallMockPurchaseOutcome>);
42
+ /** Whether restore emits a `transaction_complete`. Defaults to "completed". */
43
+ restoreOutcome?: "completed" | "none";
44
+ /** Permission request responses. Defaults to "granted". */
45
+ permissions?: Partial<Record<TPermissionTypeMessage, TPermissionStatus>>;
46
+ /** Answers a permission request per call, for hosts that decide at runtime. */
47
+ onPermission?: (permissionType: TPermissionTypeMessage) => TPermissionStatus | Promise<TPermissionStatus>;
48
+ /** Answers a callback request per call, for hosts that decide at runtime. */
49
+ onCallback?: (name: string, variables?: Record<string, unknown>) => SuperwallMockCallbackResult | Promise<SuperwallMockCallbackResult>;
50
+ callbacks?: Record<string, SuperwallMockCallbackResult | ((variables?: Record<string, unknown>) => SuperwallMockCallbackResult | Promise<SuperwallMockCallbackResult>)>;
51
+ /** Simulated SDK response delay. Defaults to 0. */
52
+ latencyMs?: number;
53
+ /** Observe every message the paywall sends to the mock host. */
54
+ onOutgoing?: (message: TOutgoingMessage) => void;
55
+ };
56
+ export declare const MOCK_DEVICE_VARIABLES: SuperwallDeviceVariables;
57
+ export declare const mockProductsFromConfig: (config: SuperwallConfig | undefined, devicePlatform?: string) => SuperwallProduct[];
58
+ export declare const mockOptionsFromConfig: (config: SuperwallConfig | undefined, options?: SuperwallMockOptions) => SuperwallMockOptions;
59
+ export declare class MockSuperwallTransport implements ITransport {
60
+ private handlers;
61
+ private listening;
62
+ private options;
63
+ private products;
64
+ constructor(options?: SuperwallMockOptions);
65
+ addListener(handler: TIncomingHandler): void;
66
+ startListening(): void;
67
+ accept(message: TIncomingMessage): void;
68
+ postMessage(message: TOutgoingMessage): void;
69
+ private get trialEligible();
70
+ private respond;
71
+ private handleOutgoing;
72
+ private resolvePurchaseOutcome;
73
+ }
74
+ export declare const createMockSuperwallTransport: (options?: SuperwallMockOptions) => MockSuperwallTransport;
package/dist/mock.js ADDED
@@ -0,0 +1,206 @@
1
+ import { normalizePlatform, normalizeProductSlot } from "./config";
2
+ import { createSuperwallProduct, } from "./products";
3
+ export const MOCK_DEVICE_VARIABLES = {
4
+ platform: "iOS",
5
+ deviceModel: "iPhone17,2",
6
+ osVersion: "18.0",
7
+ appVersion: "1.0.0",
8
+ deviceLocale: "en_US",
9
+ deviceLanguageCode: "en",
10
+ regionCode: "US",
11
+ preferredLocale: "en-US",
12
+ preferredLanguageCode: "en",
13
+ preferredRegionCode: "US",
14
+ deviceCurrencyCode: "USD",
15
+ deviceCurrencySymbol: "$",
16
+ interfaceStyle: "Light",
17
+ isSandbox: "true",
18
+ sdkVersion: "4.0.0",
19
+ daysSinceInstall: 0,
20
+ totalPaywallViews: 1,
21
+ };
22
+ export const mockProductsFromConfig = (config, devicePlatform) => Object.entries(config?.products ?? {}).map(([reference, input]) => {
23
+ const slot = normalizeProductSlot(input, normalizePlatform(devicePlatform));
24
+ const productId = slot.productId ?? reference;
25
+ return {
26
+ reference,
27
+ product: reference,
28
+ id: productId,
29
+ productId,
30
+ productIdentifier: productId,
31
+ variables: { identifier: productId },
32
+ source: "placeholder",
33
+ };
34
+ });
35
+ export const mockOptionsFromConfig = (config, options = {}) => ({
36
+ ...options,
37
+ products: options.products ??
38
+ mockProductsFromConfig(config, typeof options.device?.platform === "string" ? options.device.platform : undefined),
39
+ });
40
+ const DAY_MS = 24 * 60 * 60 * 1000;
41
+ const trialPeriodDaysOf = (product) => {
42
+ // The SDK sends period counts as strings ("7"), so a `typeof === "number"`
43
+ // check silently reports every product as trial-less on a device.
44
+ const days = Number(product.variables.trialPeriodDays);
45
+ return Number.isFinite(days) ? days : 0;
46
+ };
47
+ export class MockSuperwallTransport {
48
+ handlers = [];
49
+ listening = false;
50
+ options;
51
+ products;
52
+ constructor(options = {}) {
53
+ this.options = options;
54
+ this.products = (options.products ?? []).map((input) => {
55
+ const product = createSuperwallProduct(input);
56
+ return product.source === "unknown" ? { ...product, source: "placeholder" } : product;
57
+ });
58
+ }
59
+ addListener(handler) {
60
+ this.handlers.push(handler);
61
+ }
62
+ startListening() {
63
+ this.listening = true;
64
+ }
65
+ accept(message) {
66
+ if (!this.listening)
67
+ return;
68
+ this.handlers.forEach((handler) => handler(message));
69
+ }
70
+ postMessage(message) {
71
+ this.options.onOutgoing?.(message);
72
+ this.handleOutgoing(message).catch((error) => {
73
+ console.error("[MockSuperwallTransport] Failed to handle outgoing message", {
74
+ event: message.event_name,
75
+ error,
76
+ });
77
+ });
78
+ }
79
+ get trialEligible() {
80
+ return (this.options.trialEligible ?? this.products.some((product) => trialPeriodDaysOf(product) > 0));
81
+ }
82
+ respond(messages) {
83
+ const deliver = () => {
84
+ messages.forEach((message) => this.accept(message));
85
+ };
86
+ const latency = this.options.latencyMs ?? 0;
87
+ if (latency > 0) {
88
+ setTimeout(deliver, latency);
89
+ }
90
+ else {
91
+ queueMicrotask(deliver);
92
+ }
93
+ }
94
+ async handleOutgoing(message) {
95
+ switch (message.event_name) {
96
+ case "ping": {
97
+ const replies = [
98
+ {
99
+ event_name: "paywall_open",
100
+ paywall_id: this.options.paywall?.id ?? "mock-paywall",
101
+ paywall_identifier: this.options.paywall?.identifier ?? "mock-paywall-identifier",
102
+ },
103
+ {
104
+ event_name: "products",
105
+ products: this.products.map((product) => ({
106
+ product: product.reference,
107
+ productId: product.productIdentifier ?? product.productId ?? product.reference,
108
+ })),
109
+ },
110
+ {
111
+ event_name: "template_variables",
112
+ variables: {
113
+ ...this.options.variables,
114
+ device: { ...MOCK_DEVICE_VARIABLES, ...this.options.device },
115
+ user: this.options.user ?? {},
116
+ params: this.options.params ?? {},
117
+ products: [
118
+ Object.fromEntries(this.products.map((product) => [product.reference, product.variables])),
119
+ ],
120
+ },
121
+ },
122
+ {
123
+ event_name: "template_substitutions_prefix",
124
+ prefix: this.trialEligible ? "freeTrial" : null,
125
+ },
126
+ ];
127
+ if (this.options.experiment) {
128
+ replies.push({ event_name: "experiment", ...this.options.experiment });
129
+ }
130
+ this.respond(replies);
131
+ break;
132
+ }
133
+ case "purchase": {
134
+ const outcome = await this.resolvePurchaseOutcome({
135
+ reference: message.product,
136
+ productIdentifier: message.product_identifier,
137
+ });
138
+ const replies = [
139
+ {
140
+ event_name: outcome === "completed" ? "transaction_complete" : "transaction_abandon",
141
+ product: message.product,
142
+ product_identifier: message.product_identifier,
143
+ },
144
+ ];
145
+ const product = this.products.find((candidate) => candidate.reference === message.product);
146
+ const trialDays = product ? trialPeriodDaysOf(product) : 0;
147
+ if (outcome === "completed" && this.trialEligible && trialDays > 0) {
148
+ replies.push({
149
+ event_name: "freeTrial_start",
150
+ product_identifier: message.product_identifier,
151
+ trial_end_date: new Date(Date.now() + trialDays * DAY_MS).toISOString(),
152
+ });
153
+ }
154
+ this.respond(replies);
155
+ break;
156
+ }
157
+ case "restore": {
158
+ if ((this.options.restoreOutcome ?? "completed") === "completed") {
159
+ this.respond([{ event_name: "transaction_complete" }]);
160
+ }
161
+ break;
162
+ }
163
+ case "request_permission": {
164
+ const status = this.options.permissions?.[message.permission_type] ??
165
+ (this.options.onPermission
166
+ ? await this.options.onPermission(message.permission_type)
167
+ : "granted");
168
+ this.respond([
169
+ {
170
+ event_name: "permission_result",
171
+ permission_type: message.permission_type,
172
+ request_id: message.request_id,
173
+ status,
174
+ },
175
+ ]);
176
+ break;
177
+ }
178
+ case "request_callback": {
179
+ const callback = this.options.callbacks?.[message.name];
180
+ const result = typeof callback === "function"
181
+ ? await callback(message.variables)
182
+ : (callback ??
183
+ (this.options.onCallback
184
+ ? await this.options.onCallback(message.name, message.variables)
185
+ : { status: "success" }));
186
+ this.respond([
187
+ {
188
+ event_name: "callback_result",
189
+ request_id: message.request_id,
190
+ name: message.name,
191
+ status: result.status,
192
+ data: result.data,
193
+ },
194
+ ]);
195
+ break;
196
+ }
197
+ default:
198
+ break;
199
+ }
200
+ }
201
+ resolvePurchaseOutcome(context) {
202
+ const outcome = this.options.purchaseOutcome ?? "completed";
203
+ return typeof outcome === "function" ? outcome(context) : outcome;
204
+ }
205
+ }
206
+ export const createMockSuperwallTransport = (options = {}) => new MockSuperwallTransport(options);
@@ -0,0 +1,62 @@
1
+ import type { ProductIdentifierAndType, TIncomingMessageProducts, TIncomingMessageTemplateVariables } from "@superwall/protocol";
2
+ export type SuperwallKnownProductVariables = {
3
+ identifier?: string;
4
+ price?: string;
5
+ rawPrice?: string | number;
6
+ period?: string;
7
+ periodAlt?: string;
8
+ localizedPeriod?: string;
9
+ periodly?: string;
10
+ periodDays?: string | number;
11
+ periodWeeks?: string | number;
12
+ periodMonths?: string | number;
13
+ periodYears?: string | number;
14
+ dailyPrice?: string;
15
+ weeklyPrice?: string;
16
+ monthlyPrice?: string;
17
+ yearlyPrice?: string;
18
+ trialPeriodPrice?: string;
19
+ rawTrialPeriodPrice?: string | number;
20
+ trialPeriodDailyPrice?: string;
21
+ trialPeriodWeeklyPrice?: string;
22
+ trialPeriodMonthlyPrice?: string;
23
+ trialPeriodYearlyPrice?: string;
24
+ trialPeriodDays?: string | number;
25
+ trialPeriodWeeks?: string | number;
26
+ trialPeriodMonths?: string | number;
27
+ trialPeriodYears?: string | number;
28
+ trialPeriodText?: string;
29
+ trialPeriodEndDate?: string;
30
+ currencyCode?: string;
31
+ currencySymbol?: string;
32
+ locale?: string;
33
+ languageCode?: string;
34
+ isSubscribed?: boolean;
35
+ };
36
+ export type SuperwallProductVariables = SuperwallKnownProductVariables;
37
+ export type SuperwallProductSource = "sdk" | "inline" | "placeholder" | "unknown";
38
+ export type SuperwallProduct<TVariables extends SuperwallProductVariables = SuperwallProductVariables> = {
39
+ reference: string;
40
+ product: string;
41
+ id?: string;
42
+ productId?: string;
43
+ productIdentifier?: string;
44
+ variables: TVariables;
45
+ source: SuperwallProductSource;
46
+ };
47
+ export type SuperwallProductInput<TProduct extends SuperwallProduct = SuperwallProduct> = string | TProduct | {
48
+ reference: string;
49
+ product?: string;
50
+ id?: string;
51
+ productId?: string;
52
+ productIdentifier?: string;
53
+ variables?: SuperwallProductVariables;
54
+ source?: SuperwallProductSource;
55
+ };
56
+ export declare const createSuperwallProduct: (input: SuperwallProductInput, variables?: SuperwallProductVariables) => SuperwallProduct;
57
+ export declare const productReferenceFromInput: (input: SuperwallProductInput) => string;
58
+ export declare const productsByReference: <TProduct extends SuperwallProduct>(products: readonly TProduct[]) => Readonly<Record<string, TProduct>>;
59
+ export declare const productVariablesFromTemplateVariables: (variables: TIncomingMessageTemplateVariables["variables"]) => Map<string, SuperwallProductVariables>;
60
+ export declare const productsFromIncomingMessage: (message: TIncomingMessageProducts) => SuperwallProduct[];
61
+ export declare const mergeIncomingProducts: (current: readonly SuperwallProduct[], incoming: readonly ProductIdentifierAndType[]) => SuperwallProduct[];
62
+ export declare const mergeProductVariables: (current: readonly SuperwallProduct[], variables: Map<string, SuperwallProductVariables>) => SuperwallProduct[];
@@ -0,0 +1,105 @@
1
+ const legacyProductReferences = ["primary", "secondary", "tertiary"];
2
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
+ export const createSuperwallProduct = (input, variables = {}) => {
4
+ if (typeof input === "string") {
5
+ return {
6
+ reference: input,
7
+ product: input,
8
+ variables,
9
+ source: "unknown",
10
+ };
11
+ }
12
+ const reference = input.reference ?? input.product;
13
+ const productId = input.productId ?? input.productIdentifier ?? input.id;
14
+ return {
15
+ reference,
16
+ product: input.product ?? reference,
17
+ id: input.id ?? productId,
18
+ productId,
19
+ productIdentifier: input.productIdentifier ?? productId,
20
+ variables: input.variables ?? variables,
21
+ source: input.source ?? "unknown",
22
+ };
23
+ };
24
+ export const productReferenceFromInput = (input) => typeof input === "string" ? input : input.reference;
25
+ export const productsByReference = (products) => {
26
+ const indexed = {};
27
+ for (const product of products) {
28
+ indexed[product.reference] = product;
29
+ }
30
+ return indexed;
31
+ };
32
+ /**
33
+ * SDK-delivered variable records are trusted, not validated: the declared
34
+ * shapes are the SDK's side of the protocol contract. Numeric-looking fields
35
+ * arrive as strings ("59.99", "7"), which is why they are typed
36
+ * `string | number` — coerce with `Number()` before doing arithmetic.
37
+ */
38
+ const asProductVariables = (record) => record;
39
+ export const productVariablesFromTemplateVariables = (variables) => {
40
+ const result = new Map();
41
+ if (Array.isArray(variables.products)) {
42
+ for (const productEntry of variables.products) {
43
+ if (!isRecord(productEntry))
44
+ continue;
45
+ for (const [reference, productVariables] of Object.entries(productEntry)) {
46
+ if (isRecord(productVariables)) {
47
+ result.set(reference, asProductVariables(productVariables));
48
+ }
49
+ }
50
+ }
51
+ }
52
+ for (const reference of legacyProductReferences) {
53
+ const productVariables = variables[reference];
54
+ if (isRecord(productVariables) && !result.has(reference)) {
55
+ result.set(reference, asProductVariables(productVariables));
56
+ }
57
+ }
58
+ return result;
59
+ };
60
+ export const productsFromIncomingMessage = (message) => message.products.map((product) => createSuperwallProduct({
61
+ reference: product.product,
62
+ product: product.product,
63
+ productId: product.productId,
64
+ productIdentifier: product.productId,
65
+ source: "sdk",
66
+ }));
67
+ export const mergeIncomingProducts = (current, incoming) => {
68
+ const next = new Map();
69
+ for (const product of current) {
70
+ next.set(product.reference, product);
71
+ }
72
+ for (const product of incoming) {
73
+ const existing = next.get(product.product);
74
+ next.set(product.product, {
75
+ ...createSuperwallProduct({
76
+ reference: product.product,
77
+ product: product.product,
78
+ productId: product.productId,
79
+ productIdentifier: product.productId,
80
+ source: "sdk",
81
+ }),
82
+ variables: existing?.variables ?? {},
83
+ });
84
+ }
85
+ return Array.from(next.values());
86
+ };
87
+ export const mergeProductVariables = (current, variables) => {
88
+ const next = new Map();
89
+ for (const product of current) {
90
+ next.set(product.reference, product);
91
+ }
92
+ for (const [reference, productVariables] of variables) {
93
+ const existing = next.get(reference);
94
+ next.set(reference, {
95
+ ...createSuperwallProduct(existing ?? {
96
+ reference,
97
+ product: reference,
98
+ source: "sdk",
99
+ }, productVariables),
100
+ variables: productVariables,
101
+ source: existing?.source ?? "sdk",
102
+ });
103
+ }
104
+ return Array.from(next.values());
105
+ };
@@ -0,0 +1,103 @@
1
+ import { type TIncomingMessage, type TOutgoingMessage, type TPermissionStatus, type TPermissionTypeMessage } from "@superwall/protocol";
2
+ import { type SuperwallConfig } from "../config";
3
+ import { type SuperwallTranslateValues } from "../localization";
4
+ import { type SuperwallProduct, type SuperwallProductInput } from "../products";
5
+ import type { SuperwallCallbackResult, SuperwallEventMap, SuperwallEventName, SuperwallPurchaseOptions, SuperwallPurchaseResult, SuperwallRuntimeSnapshot, SuperwallSessionOptions, SuperwallSessionStartOptions } from "./types";
6
+ export * from "./types";
7
+ export type PageViewInput = {
8
+ type: Extract<TOutgoingMessage, {
9
+ event_name: "page_view";
10
+ }>["type"];
11
+ name: string;
12
+ navigationId: string;
13
+ position: number;
14
+ previousName?: string;
15
+ previousPosition?: number;
16
+ timeOnPreviousMs?: number;
17
+ };
18
+ /**
19
+ * The session's public contract, separated from the implementation so the
20
+ * product generic can be declared covariant (`out`): `TProduct` appears in
21
+ * output positions only, so a session refined with custom product variables
22
+ * is always usable where a base session is expected (e.g. a shared React
23
+ * context). The implementation is written against the base `SuperwallProduct`
24
+ * — refinement happens once, in `createSuperwallSession`.
25
+ */
26
+ export interface SuperwallSession<out TProduct extends SuperwallProduct = SuperwallProduct> {
27
+ /**
28
+ * Subscribes to a single incoming SDK event by name, or "message" for all
29
+ * incoming messages. Returns an unsubscribe function.
30
+ */
31
+ on: <E extends SuperwallEventName>(event: E, handler: (payload: SuperwallEventMap[E]) => void) => () => void;
32
+ /** Subscribes to snapshot changes (`useSyncExternalStore`-compatible). */
33
+ subscribe: (listener: () => void) => () => void;
34
+ getSnapshot: () => SuperwallRuntimeSnapshot<TProduct>;
35
+ readonly products: readonly TProduct[];
36
+ readonly config: SuperwallConfig | undefined;
37
+ readonly locale: string;
38
+ /**
39
+ * Resolves a message key for the active locale, interpolating `{name}`
40
+ * params. Unknown keys return the key itself, so literal copy is safe.
41
+ */
42
+ t: (key: string, values?: SuperwallTranslateValues) => string;
43
+ /** Overrides the locale (normally auto-detected from the device). */
44
+ setLocale: (locale: string | undefined) => void;
45
+ configure: (config: SuperwallConfig) => void;
46
+ start: (options?: SuperwallSessionStartOptions) => void;
47
+ postMessage: (message: TOutgoingMessage) => void;
48
+ accept: (messages: TIncomingMessage[]) => void;
49
+ accept64: (message: string) => void;
50
+ ping: (message?: Partial<Extract<TOutgoingMessage, {
51
+ event_name: "ping";
52
+ }>>) => void;
53
+ close: () => void;
54
+ /**
55
+ * Asks the SDK to restore purchases. The message protocol has no restore
56
+ * result event; successful restores surface as `transaction_complete` or a
57
+ * dismissed paywall.
58
+ */
59
+ restore: () => void;
60
+ openUrl: (url: string, options?: {
61
+ browserType?: "payment_sheet";
62
+ }) => void;
63
+ openExternalUrl: (url: string) => void;
64
+ openDeepLink: (link: string) => void;
65
+ custom: (data: string) => void;
66
+ customPlacement: (name: string, params?: Record<string, unknown>) => void;
67
+ requestStoreReview: (reviewType: Extract<TOutgoingMessage, {
68
+ event_name: "request_store_review";
69
+ }>["review_type"]) => void;
70
+ setUserAttributes: (attributes: Record<string, string>) => void;
71
+ pageView: (input: PageViewInput) => void;
72
+ scheduleTrialReminder: (input: {
73
+ id: string;
74
+ title: string;
75
+ subtitle?: string;
76
+ body: string;
77
+ delayMs: number;
78
+ }) => void;
79
+ hapticFeedback: (hapticType: Extract<TOutgoingMessage, {
80
+ event_name: "haptic_feedback";
81
+ }>["haptic_type"]) => void;
82
+ requestPermission: (permissionType: TPermissionTypeMessage) => Promise<TPermissionStatus>;
83
+ requestCallback: <TData extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: {
84
+ behavior?: "blocking" | "non-blocking";
85
+ variables?: Record<string, unknown>;
86
+ }) => Promise<SuperwallCallbackResult<TData>>;
87
+ /**
88
+ * Starts a purchase and resolves with the outcome — never throws for flow
89
+ * results: `{ status: "completed" | "abandoned" | "failed" }`.
90
+ */
91
+ purchase: (input: SuperwallProductInput, options?: SuperwallPurchaseOptions) => Promise<SuperwallPurchaseResult<TProduct>>;
92
+ getProduct: (reference: string) => TProduct | undefined;
93
+ }
94
+ /**
95
+ * Creates a runtime session.
96
+ *
97
+ * `TProduct` is the caller's declaration of what SDK-delivered products look
98
+ * like (custom template variables layered over the known ones). The runtime
99
+ * cannot verify it — the SDK owns the values — so this downcast is the single
100
+ * seam where the claim is applied; every refined type downstream derives from
101
+ * it.
102
+ */
103
+ export declare const createSuperwallSession: <TProduct extends SuperwallProduct = SuperwallProduct>(options?: SuperwallSessionOptions<TProduct>) => SuperwallSession<TProduct>;