@superwall/runtime 1.7.0 → 2.0.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.
@@ -5,4 +5,4 @@ export { PING_VERSION, type PageViewInput } from "./outgoing";
5
5
  export type { CallbackBehavior } from "./requests";
6
6
  export { buildSuperwallState, type BuildSuperwallStateOptions, type SuperwallCallbackState, type SuperwallCallbackStates, type SuperwallPermissionStatuses, type SuperwallSdkState, } from "./state";
7
7
  export * from "./types";
8
- export { recordFromVariables, type SuperwallCapability, type SuperwallCustomerInfo, type SuperwallDeviceEntitlement, type SuperwallDeviceTransaction, type SuperwallDeviceVariables, type SuperwallExperiment, type SuperwallPlacementParams, type SuperwallUserVariables, } from "./variables";
8
+ export { recordFromVariables, type SuperwallCapability, type SuperwallCustomerInfo, type SuperwallDeviceEntitlement, type SuperwallDeviceTransaction, type SuperwallDeviceVariables, type SuperwallExperiment, type SuperwallPlacementParams, type SuperwallSafeAreaInsets, type SuperwallUserVariables, } from "./variables";
@@ -115,7 +115,11 @@ const createSession = (options) => {
115
115
  lastPurchaseFailure: undefined,
116
116
  });
117
117
  };
118
+ let hostAnswered = false;
119
+ let unconfirmed;
118
120
  const handleIncoming = (message) => {
121
+ if (message.event_name === "template_variables")
122
+ hostAnswered = true;
119
123
  switch (message.event_name) {
120
124
  case "paywall_open":
121
125
  purchases.failAll("superseded");
@@ -174,7 +178,15 @@ const createSession = (options) => {
174
178
  default:
175
179
  break;
176
180
  }
177
- commit(snapshotPatchFor(snapshot, message) ?? {});
181
+ const patch = snapshotPatchFor(snapshot, message) ?? {};
182
+ if (message.event_name === "template_variables" && unconfirmed) {
183
+ const user = { ...patch.user, ...unconfirmed };
184
+ unconfirmed = undefined;
185
+ commit({ ...patch, user, variables: { ...patch.variables, user } });
186
+ }
187
+ else {
188
+ commit(patch);
189
+ }
178
190
  emit(message.event_name, message);
179
191
  emit("message", message);
180
192
  };
@@ -256,10 +268,10 @@ const createSession = (options) => {
256
268
  if (entries.length === 0)
257
269
  return;
258
270
  post(outgoing.userAttributeUpdated(entries));
259
- const user = {
260
- ...snapshot.user,
261
- ...Object.fromEntries(entries.map(({ key, value }) => [key, value])),
262
- };
271
+ const written = Object.fromEntries(entries.map(({ key, value }) => [key, value]));
272
+ if (!hostAnswered)
273
+ unconfirmed = { ...unconfirmed, ...written };
274
+ const user = { ...snapshot.user, ...written };
263
275
  commit({ user, variables: { ...snapshot.variables, user } });
264
276
  },
265
277
  requestStoreReview: (reviewType) => post(outgoing.requestStoreReview(reviewType)),
@@ -50,6 +50,7 @@ export type SuperwallDeviceVariables = {
50
50
  bundleId?: string;
51
51
  osVersion?: string;
52
52
  deviceModel?: string;
53
+ simulatorModel?: string;
53
54
  deviceLocale?: string;
54
55
  preferredLocale?: string;
55
56
  deviceLanguageCode?: string;
@@ -98,6 +99,13 @@ export type SuperwallDeviceVariables = {
98
99
  swiftVersion?: string;
99
100
  compilerVersion?: string;
100
101
  localResourceIds?: string;
102
+ safeAreaInsets?: SuperwallSafeAreaInsets;
103
+ };
104
+ export type SuperwallSafeAreaInsets = {
105
+ top: number;
106
+ right: number;
107
+ bottom: number;
108
+ left: number;
101
109
  };
102
110
  export type SuperwallUserVariables = {
103
111
  seed?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superwall/runtime",
3
- "version": "1.7.0",
3
+ "version": "2.0.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": "1.7.0"
42
+ "@superwall/protocol": "2.0.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@superwall/host": "workspace:*",
@@ -174,7 +174,11 @@ const createSession = (options: SuperwallSessionOptions): SuperwallSession => {
174
174
  });
175
175
  };
176
176
 
177
+ let hostAnswered = false;
178
+ let unconfirmed: Record<string, string> | undefined;
179
+
177
180
  const handleIncoming = (message: TIncomingMessage) => {
181
+ if (message.event_name === "template_variables") hostAnswered = true;
178
182
  switch (message.event_name) {
179
183
  case "paywall_open":
180
184
  purchases.failAll("superseded");
@@ -231,7 +235,14 @@ const createSession = (options: SuperwallSessionOptions): SuperwallSession => {
231
235
  break;
232
236
  }
233
237
 
234
- commit(snapshotPatchFor(snapshot, message) ?? {});
238
+ const patch = snapshotPatchFor(snapshot, message) ?? {};
239
+ if (message.event_name === "template_variables" && unconfirmed) {
240
+ const user = { ...patch.user, ...unconfirmed };
241
+ unconfirmed = undefined;
242
+ commit({ ...patch, user, variables: { ...patch.variables, user } });
243
+ } else {
244
+ commit(patch);
245
+ }
235
246
  emit(message.event_name, message);
236
247
  emit("message", message);
237
248
  };
@@ -314,10 +325,9 @@ const createSession = (options: SuperwallSessionOptions): SuperwallSession => {
314
325
  }));
315
326
  if (entries.length === 0) return;
316
327
  post(outgoing.userAttributeUpdated(entries));
317
- const user = {
318
- ...snapshot.user,
319
- ...Object.fromEntries(entries.map(({ key, value }) => [key, value])),
320
- };
328
+ const written = Object.fromEntries(entries.map(({ key, value }) => [key, value]));
329
+ if (!hostAnswered) unconfirmed = { ...unconfirmed, ...written };
330
+ const user = { ...snapshot.user, ...written };
321
331
  commit({ user, variables: { ...snapshot.variables, user } });
322
332
  },
323
333
  requestStoreReview: (reviewType) => post(outgoing.requestStoreReview(reviewType)),
@@ -376,5 +386,6 @@ export {
376
386
  type SuperwallDeviceVariables,
377
387
  type SuperwallExperiment,
378
388
  type SuperwallPlacementParams,
389
+ type SuperwallSafeAreaInsets,
379
390
  type SuperwallUserVariables,
380
391
  } from "./variables";
@@ -55,6 +55,7 @@ export type SuperwallDeviceVariables = {
55
55
  bundleId?: string;
56
56
  osVersion?: string;
57
57
  deviceModel?: string;
58
+ simulatorModel?: string;
58
59
  deviceLocale?: string;
59
60
  preferredLocale?: string;
60
61
  deviceLanguageCode?: string;
@@ -103,6 +104,14 @@ export type SuperwallDeviceVariables = {
103
104
  swiftVersion?: string;
104
105
  compilerVersion?: string;
105
106
  localResourceIds?: string;
107
+ safeAreaInsets?: SuperwallSafeAreaInsets;
108
+ };
109
+
110
+ export type SuperwallSafeAreaInsets = {
111
+ top: number;
112
+ right: number;
113
+ bottom: number;
114
+ left: number;
106
115
  };
107
116
 
108
117
  export type SuperwallUserVariables = {