@superwall/runtime 2.1.0 → 2.2.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.
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +1 -0
- package/dist/config/teleport.d.ts +65 -0
- package/dist/config/teleport.js +12 -0
- package/dist/session/incoming.js +19 -1
- package/dist/session/index.js +1 -0
- package/dist/session/outgoing.d.ts +1 -0
- package/dist/session/outgoing.js +1 -0
- package/dist/session/types.d.ts +9 -0
- package/package.json +2 -2
- package/src/config/index.ts +15 -0
- package/src/config/teleport.ts +89 -0
- package/src/session/incoming.ts +40 -2
- package/src/session/index.ts +1 -0
- package/src/session/outgoing.ts +2 -0
- package/src/session/types.ts +10 -0
package/dist/config/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { SuperwallNotificationsConfig } from "./notifications";
|
|
|
7
7
|
import type { SuperwallPresentationConfig } from "./presentation";
|
|
8
8
|
import type { SuperwallPostPurchase } from "./postPurchase";
|
|
9
9
|
import type { SuperwallProductSlotInput } from "./products";
|
|
10
|
+
import type { SuperwallTeleportConfig } from "./teleport";
|
|
10
11
|
export type SuperwallIntroductoryOfferEligibility = "automatic" | "eligible" | "ineligible";
|
|
11
12
|
/**
|
|
12
13
|
* A paywall's contract: product slots, presentation, gating, notifications,
|
|
@@ -74,6 +75,13 @@ export type SuperwallConfig<TLocale extends string = string, TStripeReference ex
|
|
|
74
75
|
* `{ defaultLocale: "en" }`; file-based catalogs need no config.
|
|
75
76
|
*/
|
|
76
77
|
localization?: SuperwallLocalizationConfig<TLocale>;
|
|
78
|
+
/**
|
|
79
|
+
* Continue the flow on the web when it is shown in an iOS app, and sell
|
|
80
|
+
* Stripe products there: `true` for every default, or the options to
|
|
81
|
+
* change. Default: off, every route runs in the app. See
|
|
82
|
+
* `SuperwallTeleportOptions`.
|
|
83
|
+
*/
|
|
84
|
+
teleport?: SuperwallTeleportConfig<TStripeReference>;
|
|
77
85
|
/**
|
|
78
86
|
* Hosts this surface may reach over the network, as bare hostnames —
|
|
79
87
|
* `["api.example.com"]`. Superwall and Stripe are always reachable;
|
|
@@ -91,4 +99,5 @@ export type { SuperwallNotificationsConfig, SuperwallTrialReminderConfig, Superw
|
|
|
91
99
|
export { normalizePlatform, SUPERWALL_PLATFORMS, type SuperwallPlatform } from "./platforms";
|
|
92
100
|
export { dismissesOnPurchase, type SuperwallPostPurchase } from "./postPurchase";
|
|
93
101
|
export type { SuperwallPresentationConfig, SuperwallPresentationStyle } from "./presentation";
|
|
102
|
+
export { teleportOf, type ResolvedTeleport, type SuperwallTeleportConfig, type SuperwallTeleportOptions, } from "./teleport";
|
|
94
103
|
export { isPlatformProductIds, productIdFor, type SuperwallPlatformProductIds, type SuperwallProductSlot, type SuperwallProductSlotInput, } from "./products";
|
package/dist/config/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { checkoutManagedPaymentsOf, checkoutModeOf, checkoutPrefetchOf, } from "
|
|
|
4
4
|
export { INSET_EDGES, insetsOf, } from "./insets";
|
|
5
5
|
export { normalizePlatform, SUPERWALL_PLATFORMS } from "./platforms";
|
|
6
6
|
export { dismissesOnPurchase } from "./postPurchase";
|
|
7
|
+
export { teleportOf, } from "./teleport";
|
|
7
8
|
export { isPlatformProductIds, productIdFor, } from "./products";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SuperwallIntroductoryOfferEligibility } from "./index";
|
|
2
|
+
/**
|
|
3
|
+
* How teleport behaves: from a route on, a flow shown in an iOS app
|
|
4
|
+
* continues on the web. `router.push(route, { teleport: true })`, a push to
|
|
5
|
+
* `route`, or buying a Stripe product opens the route in the shopper's
|
|
6
|
+
* browser on your project's web paywall domain, with the flow's
|
|
7
|
+
* `useQueryState` values carried along; the shopper pays there with Stripe
|
|
8
|
+
* and is sent back to the app, which is credited automatically. Needs
|
|
9
|
+
* SuperwallKit 4.18.0 or later; on an older SDK the route opens in the app as
|
|
10
|
+
* usual and a Stripe purchase goes to the hosted checkout page.
|
|
11
|
+
*/
|
|
12
|
+
export type SuperwallTeleportOptions<TStripeReference extends string = string, TStoreReference extends string = string, TRoute extends string = string> = {
|
|
13
|
+
/**
|
|
14
|
+
* The route the web half opens on by default: a push to it teleports, a
|
|
15
|
+
* Stripe purchase teleports to it, and it is warmed when the paywall
|
|
16
|
+
* opens. Default: none — a Stripe purchase teleports the route it was
|
|
17
|
+
* tapped on, and only `router.push(route, { teleport: true })` teleports a
|
|
18
|
+
* push.
|
|
19
|
+
*/
|
|
20
|
+
route?: TRoute;
|
|
21
|
+
/**
|
|
22
|
+
* Show Superwall's teleport screen over the paywall while the shopper is in
|
|
23
|
+
* the browser ("Finish in your browser", reopen, cancel). `false` keeps
|
|
24
|
+
* the paywall as it is, for a flow that leaves midway, or for your own
|
|
25
|
+
* screen drawn from `useTeleport()`. The purchase is watched either way.
|
|
26
|
+
* Default: `true`.
|
|
27
|
+
*/
|
|
28
|
+
overlay?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* A store product the teleport screen offers in place of a Stripe one,
|
|
31
|
+
* keyed by the Stripe product's reference: "Continue In-App Instead" buys
|
|
32
|
+
* it through the store. Shown only once the store has priced it.
|
|
33
|
+
* Default: none.
|
|
34
|
+
*/
|
|
35
|
+
fallbacks?: Partial<Record<TStripeReference, TStoreReference>>;
|
|
36
|
+
/**
|
|
37
|
+
* What the web page does once the purchase completes: `"confirmation"`
|
|
38
|
+
* shows "You're all set" with a Return to App button, `"direct"` opens the
|
|
39
|
+
* app at once. Either way the app is opened through its universal link,
|
|
40
|
+
* falling back to its URL scheme when the link doesn't open it.
|
|
41
|
+
* Default: `"confirmation"`.
|
|
42
|
+
*/
|
|
43
|
+
completion?: "confirmation" | "direct";
|
|
44
|
+
/**
|
|
45
|
+
* Whether the web checkout offers the trial: `"automatic"` when the app's
|
|
46
|
+
* store says the shopper is eligible, `"eligible"` always, `"ineligible"`
|
|
47
|
+
* never. The App Store's trial history does not bind a Stripe purchase, so
|
|
48
|
+
* this is separate from the paywall's own `introductoryOfferEligibility`.
|
|
49
|
+
* Default: `"automatic"`.
|
|
50
|
+
*/
|
|
51
|
+
introductoryOfferEligibility?: SuperwallIntroductoryOfferEligibility;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Turn teleport on: `true` for every default, or the options to change.
|
|
55
|
+
* Default: off.
|
|
56
|
+
*/
|
|
57
|
+
export type SuperwallTeleportConfig<TStripeReference extends string = string, TStoreReference extends string = string, TRoute extends string = string> = boolean | SuperwallTeleportOptions<TStripeReference, TStoreReference, TRoute>;
|
|
58
|
+
export type ResolvedTeleport = {
|
|
59
|
+
route?: string;
|
|
60
|
+
overlay: boolean;
|
|
61
|
+
fallbacks: Partial<Record<string, string>>;
|
|
62
|
+
completion: "confirmation" | "direct";
|
|
63
|
+
introductoryOfferEligibility: SuperwallIntroductoryOfferEligibility;
|
|
64
|
+
};
|
|
65
|
+
export declare const teleportOf: (teleport: SuperwallTeleportConfig | undefined) => ResolvedTeleport | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const teleportOf = (teleport) => {
|
|
2
|
+
if (teleport === undefined || teleport === false)
|
|
3
|
+
return undefined;
|
|
4
|
+
const options = teleport === true ? {} : teleport;
|
|
5
|
+
return {
|
|
6
|
+
...(options.route === undefined ? {} : { route: options.route }),
|
|
7
|
+
overlay: options.overlay ?? true,
|
|
8
|
+
fallbacks: options.fallbacks ?? {},
|
|
9
|
+
completion: options.completion ?? "confirmation",
|
|
10
|
+
introductoryOfferEligibility: options.introductoryOfferEligibility ?? "automatic",
|
|
11
|
+
};
|
|
12
|
+
};
|
package/dist/session/incoming.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import { permissionStateName } from "./requests";
|
|
2
2
|
import { recordFromVariables } from "./variables";
|
|
3
|
+
const PRESENTED_BY = ["placement", "event"];
|
|
4
|
+
const PRESENTATION_SOURCE_TYPES = ["implicit", "getPaywall", "register"];
|
|
5
|
+
const nonEmpty = (value) => value === undefined || value === "" ? undefined : value;
|
|
6
|
+
const presentationOf = (message) => {
|
|
7
|
+
const id = nonEmpty(message.presentation_id);
|
|
8
|
+
const presentedBy = PRESENTED_BY.find((value) => value === message.presented_by);
|
|
9
|
+
const sourceType = PRESENTATION_SOURCE_TYPES.find((value) => value === message.presentation_source_type);
|
|
10
|
+
const eventId = nonEmpty(message.presented_by_event_id);
|
|
11
|
+
const eventName = nonEmpty(message.presented_by_event_name);
|
|
12
|
+
return {
|
|
13
|
+
...(id === undefined ? {} : { id }),
|
|
14
|
+
...(presentedBy === undefined ? {} : { presentedBy }),
|
|
15
|
+
...(sourceType === undefined ? {} : { sourceType }),
|
|
16
|
+
...(eventId === undefined ? {} : { eventId }),
|
|
17
|
+
...(eventName === undefined ? {} : { eventName }),
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const withPresentation = (paywall, presentation) => Object.keys(presentation).length === 0 ? paywall : { ...paywall, presentation };
|
|
3
21
|
export const snapshotPatchFor = (snapshot, message) => {
|
|
4
22
|
switch (message.event_name) {
|
|
5
23
|
case "paywall_open":
|
|
6
24
|
return {
|
|
7
|
-
paywall: { id: message.paywall_id, identifier: message.paywall_identifier },
|
|
25
|
+
paywall: withPresentation({ id: message.paywall_id, identifier: message.paywall_identifier }, presentationOf(message)),
|
|
8
26
|
pendingPurchase: undefined,
|
|
9
27
|
lastTransaction: undefined,
|
|
10
28
|
lastPurchaseFailure: undefined,
|
package/dist/session/index.js
CHANGED
|
@@ -274,6 +274,7 @@ const createSession = (options) => {
|
|
|
274
274
|
openUrl: (url, urlOptions = {}) => post(outgoing.openUrl(url, urlOptions.browserType)),
|
|
275
275
|
openExternalUrl: (url) => post(outgoing.openExternalUrl(url)),
|
|
276
276
|
openDeepLink: (link) => post(outgoing.openDeepLink(link)),
|
|
277
|
+
customAction: (name) => post(outgoing.custom(name)),
|
|
277
278
|
customPlacement: (name, params = {}) => post(outgoing.customPlacement(name, params)),
|
|
278
279
|
setUserAttributes: (attributes) => {
|
|
279
280
|
const entries = Object.entries(attributes).map(([key, value]) => ({
|
|
@@ -10,6 +10,7 @@ export declare const restore: () => Outgoing<"restore">;
|
|
|
10
10
|
export declare const openUrl: (url: string, browserType?: "payment_sheet") => Outgoing<"open_url">;
|
|
11
11
|
export declare const openExternalUrl: (url: string) => Outgoing<"open_url_external">;
|
|
12
12
|
export declare const openDeepLink: (link: string) => Outgoing<"open_deep_link">;
|
|
13
|
+
export declare const custom: (name: string) => Outgoing<"custom">;
|
|
13
14
|
export declare const customPlacement: (name: string, params: Record<string, unknown>) => Outgoing<"custom_placement">;
|
|
14
15
|
export declare const userAttributeUpdated: (attributes: Outgoing<"user_attribute_updated">["attributes"]) => Outgoing<"user_attribute_updated">;
|
|
15
16
|
export declare const requestStoreReview: (reviewType: Outgoing<"request_store_review">["review_type"]) => Outgoing<"request_store_review">;
|
package/dist/session/outgoing.js
CHANGED
|
@@ -20,6 +20,7 @@ export const openDeepLink = (link) => ({
|
|
|
20
20
|
event_name: "open_deep_link",
|
|
21
21
|
link,
|
|
22
22
|
});
|
|
23
|
+
export const custom = (name) => ({ event_name: "custom", data: name });
|
|
23
24
|
export const customPlacement = (name, params) => ({ event_name: "custom_placement", name, params });
|
|
24
25
|
export const userAttributeUpdated = (attributes) => ({ event_name: "user_attribute_updated", attributes });
|
|
25
26
|
export const requestStoreReview = (reviewType) => ({
|
package/dist/session/types.d.ts
CHANGED
|
@@ -7,9 +7,17 @@ import type { CallbackBehavior } from "./requests";
|
|
|
7
7
|
import type { SuperwallCallbackStates, SuperwallPermissionStatuses, SuperwallSdkState } from "./state";
|
|
8
8
|
import type { SuperwallDeviceVariables, SuperwallExperiment, SuperwallPlacementParams, SuperwallUserVariables } from "./variables";
|
|
9
9
|
export type SuperwallRuntimeStatus = "idle" | "listening";
|
|
10
|
+
export type SuperwallPresentation = {
|
|
11
|
+
id?: string;
|
|
12
|
+
presentedBy?: "placement" | "event";
|
|
13
|
+
sourceType?: "implicit" | "getPaywall" | "register";
|
|
14
|
+
eventId?: string;
|
|
15
|
+
eventName?: string;
|
|
16
|
+
};
|
|
10
17
|
export type SuperwallPaywallIdentity = {
|
|
11
18
|
id: string;
|
|
12
19
|
identifier: string;
|
|
20
|
+
presentation?: SuperwallPresentation;
|
|
13
21
|
};
|
|
14
22
|
export type SuperwallPendingPurchase<out TProduct extends SuperwallProduct = SuperwallProduct> = {
|
|
15
23
|
reference: string;
|
|
@@ -136,6 +144,7 @@ export interface SuperwallSession<out TProduct extends SuperwallProduct = Superw
|
|
|
136
144
|
}) => void;
|
|
137
145
|
openExternalUrl: (url: string) => void;
|
|
138
146
|
openDeepLink: (link: string) => void;
|
|
147
|
+
customAction: (name: string) => void;
|
|
139
148
|
customPlacement: (name: string, params?: Record<string, unknown>) => void;
|
|
140
149
|
setUserAttributes: (attributes: SuperwallUserAttributes) => void;
|
|
141
150
|
requestStoreReview: (reviewType: Outgoing<"request_store_review">["review_type"]) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superwall/runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Framework-agnostic runtime for headless Superwall paywalls: bridge, session, products, localization, mock host.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paywall",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"clean": "rm -rf dist coverage"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@superwall/protocol": "2.
|
|
42
|
+
"@superwall/protocol": "2.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@superwall/host": "workspace:*",
|
package/src/config/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { SuperwallNotificationsConfig } from "./notifications";
|
|
|
7
7
|
import type { SuperwallPresentationConfig } from "./presentation";
|
|
8
8
|
import type { SuperwallPostPurchase } from "./postPurchase";
|
|
9
9
|
import type { SuperwallProductSlotInput } from "./products";
|
|
10
|
+
import type { SuperwallTeleportConfig } from "./teleport";
|
|
10
11
|
|
|
11
12
|
export type SuperwallIntroductoryOfferEligibility = "automatic" | "eligible" | "ineligible";
|
|
12
13
|
|
|
@@ -92,6 +93,14 @@ export type SuperwallConfig<
|
|
|
92
93
|
*/
|
|
93
94
|
localization?: SuperwallLocalizationConfig<TLocale>;
|
|
94
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Continue the flow on the web when it is shown in an iOS app, and sell
|
|
98
|
+
* Stripe products there: `true` for every default, or the options to
|
|
99
|
+
* change. Default: off, every route runs in the app. See
|
|
100
|
+
* `SuperwallTeleportOptions`.
|
|
101
|
+
*/
|
|
102
|
+
teleport?: SuperwallTeleportConfig<TStripeReference>;
|
|
103
|
+
|
|
95
104
|
/**
|
|
96
105
|
* Hosts this surface may reach over the network, as bare hostnames —
|
|
97
106
|
* `["api.example.com"]`. Superwall and Stripe are always reachable;
|
|
@@ -140,6 +149,12 @@ export type {
|
|
|
140
149
|
export { normalizePlatform, SUPERWALL_PLATFORMS, type SuperwallPlatform } from "./platforms";
|
|
141
150
|
export { dismissesOnPurchase, type SuperwallPostPurchase } from "./postPurchase";
|
|
142
151
|
export type { SuperwallPresentationConfig, SuperwallPresentationStyle } from "./presentation";
|
|
152
|
+
export {
|
|
153
|
+
teleportOf,
|
|
154
|
+
type ResolvedTeleport,
|
|
155
|
+
type SuperwallTeleportConfig,
|
|
156
|
+
type SuperwallTeleportOptions,
|
|
157
|
+
} from "./teleport";
|
|
143
158
|
export {
|
|
144
159
|
isPlatformProductIds,
|
|
145
160
|
productIdFor,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { SuperwallIntroductoryOfferEligibility } from "./index";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How teleport behaves: from a route on, a flow shown in an iOS app
|
|
5
|
+
* continues on the web. `router.push(route, { teleport: true })`, a push to
|
|
6
|
+
* `route`, or buying a Stripe product opens the route in the shopper's
|
|
7
|
+
* browser on your project's web paywall domain, with the flow's
|
|
8
|
+
* `useQueryState` values carried along; the shopper pays there with Stripe
|
|
9
|
+
* and is sent back to the app, which is credited automatically. Needs
|
|
10
|
+
* SuperwallKit 4.18.0 or later; on an older SDK the route opens in the app as
|
|
11
|
+
* usual and a Stripe purchase goes to the hosted checkout page.
|
|
12
|
+
*/
|
|
13
|
+
export type SuperwallTeleportOptions<
|
|
14
|
+
TStripeReference extends string = string,
|
|
15
|
+
TStoreReference extends string = string,
|
|
16
|
+
TRoute extends string = string,
|
|
17
|
+
> = {
|
|
18
|
+
/**
|
|
19
|
+
* The route the web half opens on by default: a push to it teleports, a
|
|
20
|
+
* Stripe purchase teleports to it, and it is warmed when the paywall
|
|
21
|
+
* opens. Default: none — a Stripe purchase teleports the route it was
|
|
22
|
+
* tapped on, and only `router.push(route, { teleport: true })` teleports a
|
|
23
|
+
* push.
|
|
24
|
+
*/
|
|
25
|
+
route?: TRoute;
|
|
26
|
+
/**
|
|
27
|
+
* Show Superwall's teleport screen over the paywall while the shopper is in
|
|
28
|
+
* the browser ("Finish in your browser", reopen, cancel). `false` keeps
|
|
29
|
+
* the paywall as it is, for a flow that leaves midway, or for your own
|
|
30
|
+
* screen drawn from `useTeleport()`. The purchase is watched either way.
|
|
31
|
+
* Default: `true`.
|
|
32
|
+
*/
|
|
33
|
+
overlay?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* A store product the teleport screen offers in place of a Stripe one,
|
|
36
|
+
* keyed by the Stripe product's reference: "Continue In-App Instead" buys
|
|
37
|
+
* it through the store. Shown only once the store has priced it.
|
|
38
|
+
* Default: none.
|
|
39
|
+
*/
|
|
40
|
+
fallbacks?: Partial<Record<TStripeReference, TStoreReference>>;
|
|
41
|
+
/**
|
|
42
|
+
* What the web page does once the purchase completes: `"confirmation"`
|
|
43
|
+
* shows "You're all set" with a Return to App button, `"direct"` opens the
|
|
44
|
+
* app at once. Either way the app is opened through its universal link,
|
|
45
|
+
* falling back to its URL scheme when the link doesn't open it.
|
|
46
|
+
* Default: `"confirmation"`.
|
|
47
|
+
*/
|
|
48
|
+
completion?: "confirmation" | "direct";
|
|
49
|
+
/**
|
|
50
|
+
* Whether the web checkout offers the trial: `"automatic"` when the app's
|
|
51
|
+
* store says the shopper is eligible, `"eligible"` always, `"ineligible"`
|
|
52
|
+
* never. The App Store's trial history does not bind a Stripe purchase, so
|
|
53
|
+
* this is separate from the paywall's own `introductoryOfferEligibility`.
|
|
54
|
+
* Default: `"automatic"`.
|
|
55
|
+
*/
|
|
56
|
+
introductoryOfferEligibility?: SuperwallIntroductoryOfferEligibility;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Turn teleport on: `true` for every default, or the options to change.
|
|
61
|
+
* Default: off.
|
|
62
|
+
*/
|
|
63
|
+
export type SuperwallTeleportConfig<
|
|
64
|
+
TStripeReference extends string = string,
|
|
65
|
+
TStoreReference extends string = string,
|
|
66
|
+
TRoute extends string = string,
|
|
67
|
+
> = boolean | SuperwallTeleportOptions<TStripeReference, TStoreReference, TRoute>;
|
|
68
|
+
|
|
69
|
+
export type ResolvedTeleport = {
|
|
70
|
+
route?: string;
|
|
71
|
+
overlay: boolean;
|
|
72
|
+
fallbacks: Partial<Record<string, string>>;
|
|
73
|
+
completion: "confirmation" | "direct";
|
|
74
|
+
introductoryOfferEligibility: SuperwallIntroductoryOfferEligibility;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const teleportOf = (
|
|
78
|
+
teleport: SuperwallTeleportConfig | undefined,
|
|
79
|
+
): ResolvedTeleport | undefined => {
|
|
80
|
+
if (teleport === undefined || teleport === false) return undefined;
|
|
81
|
+
const options = teleport === true ? {} : teleport;
|
|
82
|
+
return {
|
|
83
|
+
...(options.route === undefined ? {} : { route: options.route }),
|
|
84
|
+
overlay: options.overlay ?? true,
|
|
85
|
+
fallbacks: options.fallbacks ?? {},
|
|
86
|
+
completion: options.completion ?? "confirmation",
|
|
87
|
+
introductoryOfferEligibility: options.introductoryOfferEligibility ?? "automatic",
|
|
88
|
+
};
|
|
89
|
+
};
|
package/src/session/incoming.ts
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
import type { TIncomingMessage } from "@superwall/protocol";
|
|
2
2
|
import { permissionStateName } from "./requests";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
SuperwallPaywallIdentity,
|
|
5
|
+
SuperwallPresentation,
|
|
6
|
+
SuperwallRuntimeSnapshot,
|
|
7
|
+
} from "./types";
|
|
4
8
|
import { recordFromVariables } from "./variables";
|
|
5
9
|
|
|
10
|
+
const PRESENTED_BY = ["placement", "event"] as const;
|
|
11
|
+
const PRESENTATION_SOURCE_TYPES = ["implicit", "getPaywall", "register"] as const;
|
|
12
|
+
|
|
13
|
+
const nonEmpty = (value: string | undefined): string | undefined =>
|
|
14
|
+
value === undefined || value === "" ? undefined : value;
|
|
15
|
+
|
|
16
|
+
const presentationOf = (
|
|
17
|
+
message: Extract<TIncomingMessage, { event_name: "paywall_open" }>,
|
|
18
|
+
): SuperwallPresentation => {
|
|
19
|
+
const id = nonEmpty(message.presentation_id);
|
|
20
|
+
const presentedBy = PRESENTED_BY.find((value) => value === message.presented_by);
|
|
21
|
+
const sourceType = PRESENTATION_SOURCE_TYPES.find(
|
|
22
|
+
(value) => value === message.presentation_source_type,
|
|
23
|
+
);
|
|
24
|
+
const eventId = nonEmpty(message.presented_by_event_id);
|
|
25
|
+
const eventName = nonEmpty(message.presented_by_event_name);
|
|
26
|
+
return {
|
|
27
|
+
...(id === undefined ? {} : { id }),
|
|
28
|
+
...(presentedBy === undefined ? {} : { presentedBy }),
|
|
29
|
+
...(sourceType === undefined ? {} : { sourceType }),
|
|
30
|
+
...(eventId === undefined ? {} : { eventId }),
|
|
31
|
+
...(eventName === undefined ? {} : { eventName }),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const withPresentation = (
|
|
36
|
+
paywall: SuperwallPaywallIdentity,
|
|
37
|
+
presentation: SuperwallPresentation,
|
|
38
|
+
): SuperwallPaywallIdentity =>
|
|
39
|
+
Object.keys(presentation).length === 0 ? paywall : { ...paywall, presentation };
|
|
40
|
+
|
|
6
41
|
export const snapshotPatchFor = (
|
|
7
42
|
snapshot: SuperwallRuntimeSnapshot,
|
|
8
43
|
message: TIncomingMessage,
|
|
@@ -10,7 +45,10 @@ export const snapshotPatchFor = (
|
|
|
10
45
|
switch (message.event_name) {
|
|
11
46
|
case "paywall_open":
|
|
12
47
|
return {
|
|
13
|
-
paywall:
|
|
48
|
+
paywall: withPresentation(
|
|
49
|
+
{ id: message.paywall_id, identifier: message.paywall_identifier },
|
|
50
|
+
presentationOf(message),
|
|
51
|
+
),
|
|
14
52
|
pendingPurchase: undefined,
|
|
15
53
|
lastTransaction: undefined,
|
|
16
54
|
lastPurchaseFailure: undefined,
|
package/src/session/index.ts
CHANGED
|
@@ -331,6 +331,7 @@ const createSession = (options: SuperwallSessionOptions): SuperwallSession => {
|
|
|
331
331
|
openUrl: (url, urlOptions = {}) => post(outgoing.openUrl(url, urlOptions.browserType)),
|
|
332
332
|
openExternalUrl: (url) => post(outgoing.openExternalUrl(url)),
|
|
333
333
|
openDeepLink: (link) => post(outgoing.openDeepLink(link)),
|
|
334
|
+
customAction: (name) => post(outgoing.custom(name)),
|
|
334
335
|
customPlacement: (name, params = {}) => post(outgoing.customPlacement(name, params)),
|
|
335
336
|
setUserAttributes: (attributes) => {
|
|
336
337
|
const entries = Object.entries(attributes).map(([key, value]) => ({
|
package/src/session/outgoing.ts
CHANGED
|
@@ -35,6 +35,8 @@ export const openDeepLink = (link: string): Outgoing<"open_deep_link"> => ({
|
|
|
35
35
|
link,
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
export const custom = (name: string): Outgoing<"custom"> => ({ event_name: "custom", data: name });
|
|
39
|
+
|
|
38
40
|
export const customPlacement = (
|
|
39
41
|
name: string,
|
|
40
42
|
params: Record<string, unknown>,
|
package/src/session/types.ts
CHANGED
|
@@ -33,9 +33,18 @@ import type {
|
|
|
33
33
|
|
|
34
34
|
export type SuperwallRuntimeStatus = "idle" | "listening";
|
|
35
35
|
|
|
36
|
+
export type SuperwallPresentation = {
|
|
37
|
+
id?: string;
|
|
38
|
+
presentedBy?: "placement" | "event";
|
|
39
|
+
sourceType?: "implicit" | "getPaywall" | "register";
|
|
40
|
+
eventId?: string;
|
|
41
|
+
eventName?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
36
44
|
export type SuperwallPaywallIdentity = {
|
|
37
45
|
id: string;
|
|
38
46
|
identifier: string;
|
|
47
|
+
presentation?: SuperwallPresentation;
|
|
39
48
|
};
|
|
40
49
|
|
|
41
50
|
export type SuperwallPendingPurchase<out TProduct extends SuperwallProduct = SuperwallProduct> = {
|
|
@@ -182,6 +191,7 @@ export interface SuperwallSession<out TProduct extends SuperwallProduct = Superw
|
|
|
182
191
|
openUrl: (url: string, options?: { browserType?: "payment_sheet" }) => void;
|
|
183
192
|
openExternalUrl: (url: string) => void;
|
|
184
193
|
openDeepLink: (link: string) => void;
|
|
194
|
+
customAction: (name: string) => void;
|
|
185
195
|
customPlacement: (name: string, params?: Record<string, unknown>) => void;
|
|
186
196
|
setUserAttributes: (attributes: SuperwallUserAttributes) => void;
|
|
187
197
|
requestStoreReview: (reviewType: Outgoing<"request_store_review">["review_type"]) => void;
|