@superwall/runtime 2.0.0 → 2.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.
- package/dist/session/index.js +18 -3
- package/dist/session/types.d.ts +12 -2
- package/package.json +2 -2
- package/src/session/index.ts +17 -3
- package/src/session/types.ts +16 -2
package/dist/session/index.js
CHANGED
|
@@ -18,14 +18,24 @@ const createSession = (options) => {
|
|
|
18
18
|
const restores = createRestoreTracker();
|
|
19
19
|
const requests = createRequestTracker();
|
|
20
20
|
const derive = createProductDeriver();
|
|
21
|
-
|
|
21
|
+
const inline = options.inlineProducts ?? {};
|
|
22
|
+
let raw = Object.entries(inline).map(([reference, variables]) => {
|
|
23
|
+
const slot = options.config?.products?.[reference];
|
|
24
|
+
return createSuperwallProduct({
|
|
25
|
+
reference,
|
|
26
|
+
productId: slot === undefined ? undefined : productIdFor(slot),
|
|
27
|
+
variables,
|
|
28
|
+
source: "inline",
|
|
29
|
+
});
|
|
30
|
+
});
|
|
22
31
|
let localeOverride;
|
|
23
32
|
let translator = createTranslator(options.config?.localization, resolveLocale(undefined, options.config?.localization));
|
|
33
|
+
const seeded = derive(raw, languageCandidates(undefined));
|
|
24
34
|
let snapshot = {
|
|
25
35
|
status: "idle",
|
|
26
36
|
config: options.config,
|
|
27
|
-
products:
|
|
28
|
-
productsByReference:
|
|
37
|
+
products: seeded,
|
|
38
|
+
productsByReference: productsByReference(seeded),
|
|
29
39
|
variables: {},
|
|
30
40
|
device: {},
|
|
31
41
|
user: {},
|
|
@@ -129,6 +139,11 @@ const createSession = (options) => {
|
|
|
129
139
|
break;
|
|
130
140
|
case "template_variables": {
|
|
131
141
|
const variables = productVariablesFromTemplateVariables(message.variables);
|
|
142
|
+
for (const [reference, delivered] of variables) {
|
|
143
|
+
const baked = inline[reference];
|
|
144
|
+
if (baked)
|
|
145
|
+
variables.set(reference, { ...baked, ...delivered });
|
|
146
|
+
}
|
|
132
147
|
if (variables.size > 0)
|
|
133
148
|
raw = mergeProductVariables(raw, variables);
|
|
134
149
|
break;
|
package/dist/session/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ITransport, TEventTrackingBehavior, TIncomingMessage, TIncomingMessageCallbackResult, TIncomingMessageTransactionAbandon, TIncomingMessageTransactionComplete, TOutgoingMessage, TPermissionStatus, TPermissionTypeMessage, TransportKind } from "@superwall/protocol";
|
|
2
|
-
import type { SuperwallConfig, SuperwallPostPurchase } from "../config";
|
|
2
|
+
import type { SuperwallCheckoutMode, SuperwallConfig, SuperwallPostPurchase } from "../config";
|
|
3
3
|
import type { SuperwallTranslateValues } from "../localization";
|
|
4
|
-
import type { SuperwallProduct, SuperwallProductInput } from "../products";
|
|
4
|
+
import type { SuperwallProduct, SuperwallProductInput, SuperwallProductVariables } from "../products";
|
|
5
5
|
import type { Outgoing, PageViewInput } from "./outgoing";
|
|
6
6
|
import type { CallbackBehavior } from "./requests";
|
|
7
7
|
import type { SuperwallCallbackStates, SuperwallPermissionStatuses, SuperwallSdkState } from "./state";
|
|
@@ -87,6 +87,15 @@ export type SuperwallPurchaseOptions = {
|
|
|
87
87
|
* store purchases, which have no Stripe object to write to.
|
|
88
88
|
*/
|
|
89
89
|
stripeMetadata?: Readonly<Record<string, string>>;
|
|
90
|
+
/**
|
|
91
|
+
* How this purchase checks out on the web when the product is a Stripe
|
|
92
|
+
* product, overriding the config's `checkout` mode for this call — a
|
|
93
|
+
* button that always opens the sheet on a paywall whose default is
|
|
94
|
+
* `"applePay"`. Inside an iOS app a Stripe purchase always opens the
|
|
95
|
+
* hosted checkout whatever this says. Ignored by store purchases.
|
|
96
|
+
* Default: the config's `checkout` mode.
|
|
97
|
+
*/
|
|
98
|
+
checkout?: SuperwallCheckoutMode;
|
|
90
99
|
};
|
|
91
100
|
export type SuperwallCallbackOptions = {
|
|
92
101
|
behavior?: CallbackBehavior;
|
|
@@ -103,6 +112,7 @@ export type SuperwallSessionStartOptions = {
|
|
|
103
112
|
};
|
|
104
113
|
export type SuperwallSessionOptions = {
|
|
105
114
|
config?: SuperwallConfig;
|
|
115
|
+
inlineProducts?: Readonly<Record<string, SuperwallProductVariables>>;
|
|
106
116
|
transport?: ITransport;
|
|
107
117
|
transportKind?: TransportKind;
|
|
108
118
|
onDecodeError?: (error: unknown) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superwall/runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.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.1.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@superwall/host": "workspace:*",
|
package/src/session/index.ts
CHANGED
|
@@ -54,18 +54,28 @@ const createSession = (options: SuperwallSessionOptions): SuperwallSession => {
|
|
|
54
54
|
const requests = createRequestTracker();
|
|
55
55
|
const derive = createProductDeriver();
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
const inline = options.inlineProducts ?? {};
|
|
58
|
+
let raw: readonly SuperwallProduct[] = Object.entries(inline).map(([reference, variables]) => {
|
|
59
|
+
const slot = options.config?.products?.[reference];
|
|
60
|
+
return createSuperwallProduct({
|
|
61
|
+
reference,
|
|
62
|
+
productId: slot === undefined ? undefined : productIdFor(slot),
|
|
63
|
+
variables,
|
|
64
|
+
source: "inline",
|
|
65
|
+
});
|
|
66
|
+
});
|
|
58
67
|
let localeOverride: string | undefined;
|
|
59
68
|
let translator = createTranslator(
|
|
60
69
|
options.config?.localization,
|
|
61
70
|
resolveLocale(undefined, options.config?.localization),
|
|
62
71
|
);
|
|
72
|
+
const seeded = derive(raw, languageCandidates(undefined));
|
|
63
73
|
|
|
64
74
|
let snapshot: SuperwallRuntimeSnapshot = {
|
|
65
75
|
status: "idle",
|
|
66
76
|
config: options.config,
|
|
67
|
-
products:
|
|
68
|
-
productsByReference:
|
|
77
|
+
products: seeded,
|
|
78
|
+
productsByReference: productsByReference(seeded),
|
|
69
79
|
variables: {},
|
|
70
80
|
device: {},
|
|
71
81
|
user: {},
|
|
@@ -188,6 +198,10 @@ const createSession = (options: SuperwallSessionOptions): SuperwallSession => {
|
|
|
188
198
|
break;
|
|
189
199
|
case "template_variables": {
|
|
190
200
|
const variables = productVariablesFromTemplateVariables(message.variables);
|
|
201
|
+
for (const [reference, delivered] of variables) {
|
|
202
|
+
const baked = inline[reference];
|
|
203
|
+
if (baked) variables.set(reference, { ...baked, ...delivered });
|
|
204
|
+
}
|
|
191
205
|
if (variables.size > 0) raw = mergeProductVariables(raw, variables);
|
|
192
206
|
break;
|
|
193
207
|
}
|
package/src/session/types.ts
CHANGED
|
@@ -10,9 +10,13 @@ import type {
|
|
|
10
10
|
TPermissionTypeMessage,
|
|
11
11
|
TransportKind,
|
|
12
12
|
} from "@superwall/protocol";
|
|
13
|
-
import type { SuperwallConfig, SuperwallPostPurchase } from "../config";
|
|
13
|
+
import type { SuperwallCheckoutMode, SuperwallConfig, SuperwallPostPurchase } from "../config";
|
|
14
14
|
import type { SuperwallTranslateValues } from "../localization";
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
SuperwallProduct,
|
|
17
|
+
SuperwallProductInput,
|
|
18
|
+
SuperwallProductVariables,
|
|
19
|
+
} from "../products";
|
|
16
20
|
import type { Outgoing, PageViewInput } from "./outgoing";
|
|
17
21
|
import type { CallbackBehavior } from "./requests";
|
|
18
22
|
import type {
|
|
@@ -121,6 +125,15 @@ export type SuperwallPurchaseOptions = {
|
|
|
121
125
|
* store purchases, which have no Stripe object to write to.
|
|
122
126
|
*/
|
|
123
127
|
stripeMetadata?: Readonly<Record<string, string>>;
|
|
128
|
+
/**
|
|
129
|
+
* How this purchase checks out on the web when the product is a Stripe
|
|
130
|
+
* product, overriding the config's `checkout` mode for this call — a
|
|
131
|
+
* button that always opens the sheet on a paywall whose default is
|
|
132
|
+
* `"applePay"`. Inside an iOS app a Stripe purchase always opens the
|
|
133
|
+
* hosted checkout whatever this says. Ignored by store purchases.
|
|
134
|
+
* Default: the config's `checkout` mode.
|
|
135
|
+
*/
|
|
136
|
+
checkout?: SuperwallCheckoutMode;
|
|
124
137
|
};
|
|
125
138
|
|
|
126
139
|
export type SuperwallCallbackOptions = {
|
|
@@ -142,6 +155,7 @@ export type SuperwallSessionStartOptions = {
|
|
|
142
155
|
|
|
143
156
|
export type SuperwallSessionOptions = {
|
|
144
157
|
config?: SuperwallConfig;
|
|
158
|
+
inlineProducts?: Readonly<Record<string, SuperwallProductVariables>>;
|
|
145
159
|
transport?: ITransport;
|
|
146
160
|
transportKind?: TransportKind;
|
|
147
161
|
onDecodeError?: (error: unknown) => void;
|