@superwall/runtime 1.2.0 → 1.3.0-beta.4

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 (95) hide show
  1. package/README.md +65 -49
  2. package/dist/bridge/base64.d.ts +0 -6
  3. package/dist/bridge/base64.js +5 -25
  4. package/dist/bridge/index.d.ts +2 -30
  5. package/dist/bridge/index.js +2 -49
  6. package/dist/bridge/transport.d.ts +2 -9
  7. package/dist/bridge/transport.js +9 -30
  8. package/dist/config/background.d.ts +16 -0
  9. package/dist/config/background.js +13 -0
  10. package/dist/config/checkout.d.ts +26 -0
  11. package/dist/config/checkout.js +2 -0
  12. package/dist/config/index.d.ts +66 -0
  13. package/dist/config/index.js +4 -0
  14. package/dist/config/localization.d.ts +13 -0
  15. package/dist/config/localization.js +1 -0
  16. package/dist/config/notifications.d.ts +40 -0
  17. package/dist/config/notifications.js +1 -0
  18. package/dist/config/platforms.d.ts +3 -0
  19. package/dist/config/platforms.js +5 -0
  20. package/dist/config/presentation.d.ts +22 -0
  21. package/dist/config/presentation.js +1 -0
  22. package/dist/config/products.d.ts +23 -0
  23. package/dist/config/products.js +10 -0
  24. package/dist/index.d.ts +2 -7
  25. package/dist/index.js +1 -6
  26. package/dist/localization/catalog.d.ts +8 -0
  27. package/dist/localization/catalog.js +21 -0
  28. package/dist/localization/index.d.ts +3 -24
  29. package/dist/localization/index.js +3 -71
  30. package/dist/localization/locale.d.ts +2 -0
  31. package/dist/localization/locale.js +22 -0
  32. package/dist/localization/periods.d.ts +1 -0
  33. package/dist/localization/periods.js +13 -5
  34. package/dist/products/derive.d.ts +4 -0
  35. package/dist/products/derive.js +45 -0
  36. package/dist/{products.d.ts → products/index.d.ts} +6 -14
  37. package/dist/products/index.js +15 -0
  38. package/dist/products/merge.d.ts +5 -0
  39. package/dist/products/merge.js +51 -0
  40. package/dist/session/incoming.d.ts +3 -0
  41. package/dist/session/incoming.js +47 -0
  42. package/dist/session/index.d.ts +7 -102
  43. package/dist/session/index.js +243 -694
  44. package/dist/session/outgoing.d.ts +42 -0
  45. package/dist/session/outgoing.js +70 -0
  46. package/dist/session/purchases.d.ts +18 -0
  47. package/dist/session/purchases.js +44 -0
  48. package/dist/session/reminders.d.ts +11 -0
  49. package/dist/session/reminders.js +41 -0
  50. package/dist/session/requests.d.ts +19 -0
  51. package/dist/session/requests.js +56 -0
  52. package/dist/session/restores.d.ts +6 -0
  53. package/dist/session/restores.js +20 -0
  54. package/dist/session/state.d.ts +3 -3
  55. package/dist/session/state.js +14 -39
  56. package/dist/session/types.d.ts +60 -29
  57. package/dist/session/variables.d.ts +3 -7
  58. package/package.json +3 -2
  59. package/src/bridge/base64.ts +10 -46
  60. package/src/bridge/index.ts +7 -77
  61. package/src/bridge/transport.ts +11 -46
  62. package/src/config/background.ts +24 -0
  63. package/src/config/checkout.ts +32 -0
  64. package/src/config/index.ts +102 -0
  65. package/src/config/localization.ts +12 -0
  66. package/src/config/notifications.ts +49 -0
  67. package/src/config/platforms.ts +8 -0
  68. package/src/config/presentation.ts +22 -0
  69. package/src/config/products.ts +39 -0
  70. package/src/index.ts +2 -43
  71. package/src/localization/catalog.ts +45 -0
  72. package/src/localization/index.ts +7 -110
  73. package/src/localization/locale.ts +25 -0
  74. package/src/localization/periods.ts +23 -8
  75. package/src/products/derive.ts +65 -0
  76. package/src/products/index.ts +87 -0
  77. package/src/products/merge.ts +78 -0
  78. package/src/session/incoming.ts +53 -0
  79. package/src/session/index.ts +286 -985
  80. package/src/session/outgoing.ts +132 -0
  81. package/src/session/purchases.ts +66 -0
  82. package/src/session/reminders.ts +56 -0
  83. package/src/session/requests.ts +87 -0
  84. package/src/session/restores.ts +27 -0
  85. package/src/session/state.ts +19 -59
  86. package/src/session/types.ts +78 -30
  87. package/src/session/variables.ts +3 -7
  88. package/dist/config.d.ts +0 -237
  89. package/dist/config.js +0 -138
  90. package/dist/mock.d.ts +0 -74
  91. package/dist/mock.js +0 -206
  92. package/dist/products.js +0 -105
  93. package/src/config.ts +0 -408
  94. package/src/mock.ts +0 -333
  95. package/src/products.ts +0 -221
@@ -1,110 +1,7 @@
1
- import type { SuperwallLocalizationConfig, SuperwallMessages } from "../config";
2
-
3
- export type SuperwallTranslateValues = Record<string, string | number>;
4
-
5
- export type SuperwallTranslator = {
6
- /**
7
- * Resolves a message key ("paywall.title") for the active locale,
8
- * interpolating `{name}` params. Unknown keys return the key itself, so
9
- * passing literal copy through `t()` is always safe.
10
- */
11
- t: (key: string, values?: SuperwallTranslateValues) => string;
12
- locale: string;
13
- /** Locales with a message catalog. */
14
- locales: readonly string[];
15
- };
16
-
17
- const lookupMessage = (messages: SuperwallMessages | undefined, key: string) => {
18
- if (!messages) return undefined;
19
-
20
- let current: SuperwallMessages | string | undefined = messages;
21
- for (const segment of key.split(".")) {
22
- if (typeof current !== "object" || current === null) return undefined;
23
- current = current[segment];
24
- }
25
-
26
- return typeof current === "string" ? current : undefined;
27
- };
28
-
29
- const interpolate = (template: string, values: SuperwallTranslateValues = {}) =>
30
- template.replace(/\{(\w+)\}/g, (match, name: string) =>
31
- name in values ? String(values[name]) : match,
32
- );
33
-
34
- /**
35
- * Language candidates for the shared period-translation table
36
- * ("de-DE" / "de_DE" → ["de_DE", "de"]), matching its underscore keys.
37
- */
38
- export const languageCandidates = (locale: string | undefined): string[] => {
39
- if (!locale) return ["en"];
40
-
41
- const normalized = locale.replace(/-/g, "_");
42
- const [language] = normalized.split("_");
43
- const candidates = [normalized];
44
-
45
- if (language && language !== normalized) {
46
- candidates.push(language.toLowerCase());
47
- }
48
-
49
- return candidates;
50
- };
51
-
52
- /** Normalizes "en_US" / "en-us" → "en-US"; returns [exact, language] candidates. */
53
- const localeCandidates = (locale: string): string[] => {
54
- const normalized = locale.replace(/_/g, "-");
55
- const [language, region] = normalized.split("-");
56
- const candidates: string[] = [];
57
-
58
- if (language && region) {
59
- candidates.push(`${language.toLowerCase()}-${region.toUpperCase()}`);
60
- }
61
- if (language) {
62
- candidates.push(language.toLowerCase());
63
- }
64
-
65
- return candidates;
66
- };
67
-
68
- /**
69
- * Picks the best available locale: exact match ("pt-BR"), then language
70
- * ("pt"), then the default locale.
71
- */
72
- export const resolveLocale = (
73
- requested: string | undefined,
74
- localization: SuperwallLocalizationConfig | undefined,
75
- ): string => {
76
- const defaultLocale = localization?.defaultLocale ?? "en";
77
- const messages = localization?.messages;
78
- if (!requested || !messages) return defaultLocale;
79
-
80
- const available = Object.keys(messages);
81
- const availableLower = new Map(available.map((locale) => [locale.toLowerCase(), locale]));
82
-
83
- for (const candidate of localeCandidates(requested)) {
84
- const match = availableLower.get(candidate.toLowerCase());
85
- if (match) return match;
86
- }
87
-
88
- return defaultLocale;
89
- };
90
-
91
- export const createTranslator = (
92
- localization: SuperwallLocalizationConfig | undefined,
93
- locale: string,
94
- ): SuperwallTranslator => {
95
- const messages = localization?.messages;
96
- const defaultLocale = localization?.defaultLocale ?? "en";
97
-
98
- const t = (key: string, values?: SuperwallTranslateValues) => {
99
- const resolved =
100
- lookupMessage(messages?.[locale], key) ?? lookupMessage(messages?.[defaultLocale], key);
101
-
102
- return interpolate(resolved ?? key, values);
103
- };
104
-
105
- return {
106
- t,
107
- locale,
108
- locales: messages ? Object.keys(messages) : [defaultLocale],
109
- };
110
- };
1
+ export {
2
+ createTranslator,
3
+ type SuperwallTranslateValues,
4
+ type SuperwallTranslator,
5
+ } from "./catalog";
6
+ export { resolveLocale } from "./locale";
7
+ export { getLocalizedPeriod, languageCandidates } from "./periods";
@@ -0,0 +1,25 @@
1
+ import type { SuperwallLocalizationConfig } from "../config/localization";
2
+
3
+ const localeCandidates = (locale: string): string[] => {
4
+ const [language, region] = locale.replace(/_/g, "-").split("-");
5
+ const candidates: string[] = [];
6
+ if (language && region) candidates.push(`${language.toLowerCase()}-${region.toUpperCase()}`);
7
+ if (language) candidates.push(language.toLowerCase());
8
+ return candidates;
9
+ };
10
+
11
+ export const resolveLocale = (
12
+ requested: string | undefined,
13
+ localization: SuperwallLocalizationConfig | undefined,
14
+ ): string => {
15
+ const defaultLocale = localization?.defaultLocale ?? "en";
16
+ const messages = localization?.messages;
17
+ if (!requested || !messages) return defaultLocale;
18
+
19
+ const available = new Map(Object.keys(messages).map((locale) => [locale.toLowerCase(), locale]));
20
+ for (const candidate of localeCandidates(requested)) {
21
+ const match = available.get(candidate.toLowerCase());
22
+ if (match) return match;
23
+ }
24
+ return defaultLocale;
25
+ };
@@ -676,18 +676,21 @@ const periodTranslations: Record<string, Record<PeriodKey, string>> = {
676
676
  },
677
677
  };
678
678
 
679
- const formatDynamicPeriod = (count: number, unit: string, locale: string): string => {
679
+ const DYNAMIC_UNITS = ["day", "week", "month", "year"] as const;
680
+
681
+ type DynamicUnit = (typeof DYNAMIC_UNITS)[number];
682
+
683
+ const formatDynamicPeriod = (count: number, unit: DynamicUnit, locale: string): string => {
680
684
  try {
681
685
  return new Intl.NumberFormat(locale.replace(/_/g, "-"), {
682
686
  style: "unit",
683
- unit: (unit.endsWith("s") ? unit.slice(0, -1) : unit) as Intl.NumberFormatOptions["unit"],
687
+ unit,
684
688
  unitDisplay: "long",
685
689
  })
686
690
  .format(count)
687
691
  .replace(/\u00a0/g, " ");
688
692
  } catch {
689
- const singularUnit = unit.endsWith("s") ? unit.slice(0, -1) : unit;
690
- return `${count} ${count === 1 ? singularUnit : `${singularUnit}s`}`;
693
+ return `${count} ${count === 1 ? unit : `${unit}s`}`;
691
694
  }
692
695
  };
693
696
 
@@ -716,12 +719,16 @@ const getDynamicPeriodlyFormatter = (locale: string): DynamicPeriodlyFormatter |
716
719
  );
717
720
  };
718
721
 
719
- const formatDynamicLocalizedValue = (count: number, unit: string, languages: string[]): string => {
722
+ const formatDynamicLocalizedValue = (
723
+ count: number,
724
+ unit: DynamicUnit,
725
+ languages: string[],
726
+ ): string => {
720
727
  const preferredLocale = languages.find((language) => language.trim());
721
728
  return formatDynamicPeriod(count, unit, preferredLocale || "en");
722
729
  };
723
730
 
724
- const formatDynamicPeriodly = (count: number, unit: string, languages: string[]): string => {
731
+ const formatDynamicPeriodly = (count: number, unit: DynamicUnit, languages: string[]): string => {
725
732
  for (const language of languages) {
726
733
  const formatter = getDynamicPeriodlyFormatter(language);
727
734
  if (!formatter) {
@@ -746,9 +753,10 @@ const getDynamicLocalizedPeriod = (value: string, languages: string[]): string |
746
753
 
747
754
  const count = Number.parseInt(match[1]!, 10);
748
755
  const rawUnit = match[2]!;
749
- const unit = rawUnit.endsWith("s") ? rawUnit.slice(0, -1) : rawUnit;
756
+ const singular = rawUnit.endsWith("s") ? rawUnit.slice(0, -1) : rawUnit;
757
+ const unit = DYNAMIC_UNITS.find((candidate) => candidate === singular);
750
758
 
751
- if (!["day", "week", "month", "year"].includes(unit) || !Number.isFinite(count)) {
759
+ if (!unit) {
752
760
  return null;
753
761
  }
754
762
 
@@ -759,6 +767,13 @@ const getDynamicLocalizedPeriod = (value: string, languages: string[]): string |
759
767
  return formatDynamicLocalizedValue(count, unit, languages);
760
768
  };
761
769
 
770
+ export const languageCandidates = (locale: string | undefined): string[] => {
771
+ if (!locale) return ["en"];
772
+ const normalized = locale.replace(/-/g, "_");
773
+ const [language] = normalized.split("_");
774
+ return language && language !== normalized ? [normalized, language.toLowerCase()] : [normalized];
775
+ };
776
+
762
777
  export function getLocalizedPeriod(value: string, languages: string[]): string {
763
778
  for (const lang of languages) {
764
779
  const translations = periodTranslations[lang];
@@ -0,0 +1,65 @@
1
+ import { getLocalizedPeriod } from "../localization/periods";
2
+ import type { SuperwallProduct } from "./index";
3
+
4
+ export const trialPeriodEndDate = (
5
+ trialPeriodDays: unknown,
6
+ language: string | undefined,
7
+ ): string | undefined => {
8
+ const days = typeof trialPeriodDays === "number" ? trialPeriodDays : Number(trialPeriodDays);
9
+ if (!Number.isFinite(days) || days <= 0) return undefined;
10
+
11
+ const endDate = new Date();
12
+ endDate.setDate(endDate.getDate() + Math.trunc(days));
13
+
14
+ let month: string;
15
+ try {
16
+ month = endDate.toLocaleString(language?.replace(/_/g, "-") ?? "default", { month: "short" });
17
+ } catch {
18
+ month = endDate.toLocaleString("default", { month: "short" });
19
+ }
20
+ return `${month} ${endDate.getDate()}, ${endDate.getFullYear()}`;
21
+ };
22
+
23
+ const localizeProduct = (
24
+ product: SuperwallProduct,
25
+ languages: readonly string[],
26
+ ): SuperwallProduct => {
27
+ const { period, periodly, trialPeriodDays, trialPeriodEndDate: endDate } = product.variables;
28
+ const derivedEndDate =
29
+ endDate === undefined ? trialPeriodEndDate(trialPeriodDays, languages[0]) : undefined;
30
+
31
+ if (typeof period !== "string" && typeof periodly !== "string" && derivedEndDate === undefined) {
32
+ return product;
33
+ }
34
+
35
+ return {
36
+ ...product,
37
+ variables: {
38
+ ...product.variables,
39
+ ...(typeof period === "string" ? { period: getLocalizedPeriod(period, [...languages]) } : {}),
40
+ ...(typeof periodly === "string"
41
+ ? { periodly: getLocalizedPeriod(periodly, [...languages]) }
42
+ : {}),
43
+ ...(derivedEndDate === undefined ? {} : { trialPeriodEndDate: derivedEndDate }),
44
+ },
45
+ };
46
+ };
47
+
48
+ export type ProductDeriver = (
49
+ raw: readonly SuperwallProduct[],
50
+ languages: readonly string[],
51
+ ) => readonly SuperwallProduct[];
52
+
53
+ export const createProductDeriver = (): ProductDeriver => {
54
+ let last:
55
+ | { raw: readonly SuperwallProduct[]; key: string; products: readonly SuperwallProduct[] }
56
+ | undefined;
57
+
58
+ return (raw, languages) => {
59
+ const key = languages.join(",");
60
+ if (last && last.raw === raw && last.key === key) return last.products;
61
+ const products = raw.map((product) => localizeProduct(product, languages));
62
+ last = { raw, key, products };
63
+ return products;
64
+ };
65
+ };
@@ -0,0 +1,87 @@
1
+ export type SuperwallKnownProductVariables = {
2
+ identifier?: string;
3
+ price?: string;
4
+ rawPrice?: string | number;
5
+ period?: string;
6
+ periodAlt?: string;
7
+ localizedPeriod?: string;
8
+ periodly?: string;
9
+ periodDays?: string | number;
10
+ periodWeeks?: string | number;
11
+ periodMonths?: string | number;
12
+ periodYears?: string | number;
13
+ dailyPrice?: string;
14
+ weeklyPrice?: string;
15
+ monthlyPrice?: string;
16
+ yearlyPrice?: string;
17
+ trialPeriodPrice?: string;
18
+ rawTrialPeriodPrice?: string | number;
19
+ trialPeriodDailyPrice?: string;
20
+ trialPeriodWeeklyPrice?: string;
21
+ trialPeriodMonthlyPrice?: string;
22
+ trialPeriodYearlyPrice?: string;
23
+ trialPeriodDays?: string | number;
24
+ trialPeriodWeeks?: string | number;
25
+ trialPeriodMonths?: string | number;
26
+ trialPeriodYears?: string | number;
27
+ trialPeriodText?: string;
28
+ trialPeriodEndDate?: string;
29
+ currencyCode?: string;
30
+ currencySymbol?: string;
31
+ locale?: string;
32
+ languageCode?: string;
33
+ isSubscribed?: boolean;
34
+ };
35
+
36
+ export type SuperwallProductVariables = SuperwallKnownProductVariables;
37
+
38
+ export type SuperwallProductSource = "sdk" | "inline" | "unknown";
39
+
40
+ export type SuperwallProduct<
41
+ TVariables extends SuperwallProductVariables = SuperwallProductVariables,
42
+ > = {
43
+ reference: string;
44
+ productId?: string;
45
+ variables: TVariables;
46
+ source: SuperwallProductSource;
47
+ };
48
+
49
+ export type SuperwallProductInput =
50
+ | string
51
+ | {
52
+ reference: string;
53
+ productId?: string;
54
+ variables?: SuperwallProductVariables;
55
+ source?: SuperwallProductSource;
56
+ };
57
+
58
+ export const createSuperwallProduct = (input: SuperwallProductInput): SuperwallProduct => {
59
+ if (typeof input === "string") return { reference: input, variables: {}, source: "unknown" };
60
+ return {
61
+ reference: input.reference,
62
+ ...(input.productId === undefined ? {} : { productId: input.productId }),
63
+ variables: input.variables ?? {},
64
+ source: input.source ?? "unknown",
65
+ };
66
+ };
67
+
68
+ export const productReferenceFromInput = (input: SuperwallProductInput): string =>
69
+ typeof input === "string" ? input : input.reference;
70
+
71
+ export const productsByReference = <TProduct extends SuperwallProduct>(
72
+ products: readonly TProduct[],
73
+ ): Readonly<Record<string, TProduct>> =>
74
+ Object.fromEntries(products.map((product) => [product.reference, product]));
75
+
76
+ export const findProductByStoreId = <TProduct extends SuperwallProduct>(
77
+ products: readonly TProduct[],
78
+ productId: string | undefined,
79
+ ): TProduct | undefined =>
80
+ productId === undefined ? undefined : products.find((product) => product.productId === productId);
81
+
82
+ export {
83
+ mergeIncomingProducts,
84
+ mergeProductVariables,
85
+ productVariablesFromTemplateVariables,
86
+ } from "./merge";
87
+ export { createProductDeriver, trialPeriodEndDate } from "./derive";
@@ -0,0 +1,78 @@
1
+ import type {
2
+ ProductIdentifierAndType,
3
+ TIncomingMessageTemplateVariables,
4
+ } from "@superwall/protocol";
5
+ import {
6
+ createSuperwallProduct,
7
+ type SuperwallProduct,
8
+ type SuperwallProductVariables,
9
+ } from "./index";
10
+
11
+ const LEGACY_REFERENCES = ["primary", "secondary", "tertiary"] as const;
12
+
13
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
14
+ typeof value === "object" && value !== null && !Array.isArray(value);
15
+
16
+ /**
17
+ * SDK-delivered variable records are trusted, not validated: the declared
18
+ * shapes are the SDK's side of the protocol contract. Numeric-looking fields
19
+ * arrive as strings ("59.99", "7"), which is why they are typed
20
+ * `string | number` — coerce with `Number()` before doing arithmetic.
21
+ */
22
+ const asProductVariables = (record: Record<string, unknown>): SuperwallProductVariables =>
23
+ record as SuperwallProductVariables;
24
+
25
+ export const productVariablesFromTemplateVariables = (
26
+ variables: TIncomingMessageTemplateVariables["variables"],
27
+ ): Map<string, SuperwallProductVariables> => {
28
+ const result = new Map<string, SuperwallProductVariables>();
29
+
30
+ if (Array.isArray(variables.products)) {
31
+ for (const entry of variables.products) {
32
+ if (!isRecord(entry)) continue;
33
+ for (const [reference, productVariables] of Object.entries(entry)) {
34
+ if (isRecord(productVariables)) result.set(reference, asProductVariables(productVariables));
35
+ }
36
+ }
37
+ }
38
+
39
+ for (const reference of LEGACY_REFERENCES) {
40
+ const productVariables = variables[reference];
41
+ if (isRecord(productVariables) && !result.has(reference)) {
42
+ result.set(reference, asProductVariables(productVariables));
43
+ }
44
+ }
45
+
46
+ return result;
47
+ };
48
+
49
+ const indexed = (products: readonly SuperwallProduct[]): Map<string, SuperwallProduct> =>
50
+ new Map(products.map((product) => [product.reference, product]));
51
+
52
+ export const mergeIncomingProducts = (
53
+ current: readonly SuperwallProduct[],
54
+ incoming: readonly ProductIdentifierAndType[],
55
+ ): SuperwallProduct[] => {
56
+ const next = indexed(current);
57
+ for (const { product: reference, productId } of incoming) {
58
+ next.set(reference, {
59
+ reference,
60
+ productId,
61
+ variables: next.get(reference)?.variables ?? {},
62
+ source: "sdk",
63
+ });
64
+ }
65
+ return Array.from(next.values());
66
+ };
67
+
68
+ export const mergeProductVariables = (
69
+ current: readonly SuperwallProduct[],
70
+ variables: ReadonlyMap<string, SuperwallProductVariables>,
71
+ ): SuperwallProduct[] => {
72
+ const next = indexed(current);
73
+ for (const [reference, productVariables] of variables) {
74
+ const existing = next.get(reference) ?? createSuperwallProduct({ reference, source: "sdk" });
75
+ next.set(reference, { ...existing, variables: productVariables });
76
+ }
77
+ return Array.from(next.values());
78
+ };
@@ -0,0 +1,53 @@
1
+ import type { TIncomingMessage } from "@superwall/protocol";
2
+ import { permissionStateName } from "./requests";
3
+ import type { SuperwallRuntimeSnapshot } from "./types";
4
+ import { recordFromVariables } from "./variables";
5
+
6
+ export const snapshotPatchFor = (
7
+ snapshot: SuperwallRuntimeSnapshot,
8
+ message: TIncomingMessage,
9
+ ): Partial<SuperwallRuntimeSnapshot> | undefined => {
10
+ switch (message.event_name) {
11
+ case "paywall_open":
12
+ return {
13
+ paywall: { id: message.paywall_id, identifier: message.paywall_identifier },
14
+ pendingPurchase: undefined,
15
+ lastTransaction: undefined,
16
+ lastPurchaseFailure: undefined,
17
+ };
18
+ case "template_variables":
19
+ return {
20
+ variables: message.variables,
21
+ device: recordFromVariables(message.variables, "device"),
22
+ user: recordFromVariables(message.variables, "user"),
23
+ params: recordFromVariables(message.variables, "params"),
24
+ };
25
+ case "template_substitutions_prefix":
26
+ return { introductoryOffer: { eligible: message.prefix === "freeTrial" } };
27
+ case "experiment":
28
+ return {
29
+ experiment: {
30
+ experimentId: message.experimentId,
31
+ variantId: message.variantId,
32
+ campaignId: message.campaignId,
33
+ },
34
+ };
35
+ case "restore_start":
36
+ return { restore: { status: "started" } };
37
+ case "restore_complete":
38
+ return { restore: { status: "completed" } };
39
+ case "restore_fail":
40
+ return { restore: { status: "failed" } };
41
+ case "event_tracking_behavior":
42
+ return { eventTrackingBehavior: message.behavior };
43
+ case "permission_result":
44
+ return {
45
+ permissionStatuses: {
46
+ ...snapshot.permissionStatuses,
47
+ [permissionStateName(message.permission_type)]: message.status,
48
+ },
49
+ };
50
+ default:
51
+ return undefined;
52
+ }
53
+ };