@superwall/runtime 2.2.0 → 2.3.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.
@@ -21,13 +21,25 @@ export type SuperwallCheckoutMode = "external" | "sheet" | "applePay";
21
21
  * - `managedPayments` overrides the account's Stripe managed-payments
22
22
  * setting for this paywall: `true` forces it on, `false` forces it off.
23
23
  * Omitted, the account setting applies.
24
+ * - `prepaidCards` decides whether Stripe Checkout accepts prepaid cards.
25
+ * Default: `"allow"`. See `SuperwallPrepaidCards`.
24
26
  */
25
27
  export type SuperwallCheckoutConfig<TReference extends string = string> = SuperwallCheckoutMode | {
26
28
  mode: SuperwallCheckoutMode;
27
29
  prefetch?: TReference | false;
28
30
  managedPayments?: boolean;
31
+ prepaidCards?: SuperwallPrepaidCards;
29
32
  };
33
+ /**
34
+ * Whether a web checkout accepts prepaid cards: `"allow"` (the default) or
35
+ * `"block"`, which makes Stripe refuse them, a defence against free-trial
36
+ * abuse. It applies to the sheet and the hosted checkout page; an Apple Pay
37
+ * payment can't be filtered by card type, so in `applePay` mode only the
38
+ * sheet fallback refuses them. Store purchases ignore it.
39
+ */
40
+ export type SuperwallPrepaidCards = "allow" | "block";
30
41
  export type SuperwallManagedPaymentsOverride = "USE_MANAGED_PAYMENTS" | "USE_DEFAULT_PAYMENTS";
31
42
  export declare const checkoutModeOf: (checkout: SuperwallCheckoutConfig | undefined) => SuperwallCheckoutMode | undefined;
32
43
  export declare const checkoutPrefetchOf: (checkout: SuperwallCheckoutConfig | undefined) => string | false | undefined;
33
44
  export declare const checkoutManagedPaymentsOf: (checkout: SuperwallCheckoutConfig | undefined) => SuperwallManagedPaymentsOverride | undefined;
45
+ export declare const checkoutPrepaidCardsOf: (checkout: SuperwallCheckoutConfig | undefined) => SuperwallPrepaidCards;
@@ -6,3 +6,4 @@ export const checkoutManagedPaymentsOf = (checkout) => {
6
6
  return undefined;
7
7
  return override ? "USE_MANAGED_PAYMENTS" : "USE_DEFAULT_PAYMENTS";
8
8
  };
9
+ export const checkoutPrepaidCardsOf = (checkout) => (typeof checkout === "object" ? checkout.prepaidCards : undefined) ?? "allow";
@@ -92,7 +92,7 @@ export type SuperwallConfig<TLocale extends string = string, TStripeReference ex
92
92
  };
93
93
  export { allowedHostsOf, LOOPBACK_HOST, MAX_ALLOWED_HOSTS, type ResolvedAllowedHosts, type SuperwallAllowedHostsConfig, } from "./allowedHosts";
94
94
  export { backgroundOf, type ResolvedBackground, type SuperwallBackgroundConfig, } from "./background";
95
- export { checkoutManagedPaymentsOf, checkoutModeOf, checkoutPrefetchOf, type SuperwallCheckoutConfig, type SuperwallCheckoutMode, type SuperwallManagedPaymentsOverride, } from "./checkout";
95
+ export { checkoutManagedPaymentsOf, checkoutModeOf, checkoutPrefetchOf, checkoutPrepaidCardsOf, type SuperwallCheckoutConfig, type SuperwallCheckoutMode, type SuperwallManagedPaymentsOverride, type SuperwallPrepaidCards, } from "./checkout";
96
96
  export { INSET_EDGES, insetsOf, type InsetEdge, type ResolvedInsets, type SuperwallInsetSide, type SuperwallInsetsConfig, } from "./insets";
97
97
  export type { SuperwallLocalizationConfig, SuperwallMessages } from "./localization";
98
98
  export type { SuperwallNotificationsConfig, SuperwallTrialReminderConfig, SuperwallTrialReminderContext, SuperwallTrialReminderNotification, SuperwallTrialReminderStaticConfig, } from "./notifications";
@@ -100,4 +100,4 @@ export { normalizePlatform, SUPERWALL_PLATFORMS, type SuperwallPlatform } from "
100
100
  export { dismissesOnPurchase, type SuperwallPostPurchase } from "./postPurchase";
101
101
  export type { SuperwallPresentationConfig, SuperwallPresentationStyle } from "./presentation";
102
102
  export { teleportOf, type ResolvedTeleport, type SuperwallTeleportConfig, type SuperwallTeleportOptions, } from "./teleport";
103
- export { isPlatformProductIds, productIdFor, type SuperwallPlatformProductIds, type SuperwallProductSlot, type SuperwallProductSlotInput, } from "./products";
103
+ export { billingPlanFor, isPlatformProductIds, productIdFor, productIdsOf, SUPERWALL_BILLING_PLANS, type SuperwallBillingPlan, type SuperwallPlatformProductIds, type SuperwallProductSlot, type SuperwallProductSlotInput, } from "./products";
@@ -1,8 +1,8 @@
1
1
  export { allowedHostsOf, LOOPBACK_HOST, MAX_ALLOWED_HOSTS, } from "./allowedHosts";
2
2
  export { backgroundOf, } from "./background";
3
- export { checkoutManagedPaymentsOf, checkoutModeOf, checkoutPrefetchOf, } from "./checkout";
3
+ export { checkoutManagedPaymentsOf, checkoutModeOf, checkoutPrefetchOf, checkoutPrepaidCardsOf, } from "./checkout";
4
4
  export { INSET_EDGES, insetsOf, } from "./insets";
5
5
  export { normalizePlatform, SUPERWALL_PLATFORMS } from "./platforms";
6
6
  export { dismissesOnPurchase } from "./postPurchase";
7
7
  export { teleportOf, } from "./teleport";
8
- export { isPlatformProductIds, productIdFor, } from "./products";
8
+ export { billingPlanFor, isPlatformProductIds, productIdFor, productIdsOf, SUPERWALL_BILLING_PLANS, } from "./products";
@@ -1,4 +1,11 @@
1
- import type { SuperwallPlatform } from "./platforms";
1
+ import { type SuperwallPlatform } from "./platforms";
2
+ /**
3
+ * How an App Store slot bills a product that offers Apple's monthly plan
4
+ * (a 12-month commitment paid monthly): `"monthly"` sells that plan,
5
+ * `"upFront"` sells the year paid at once.
6
+ */
7
+ export type SuperwallBillingPlan = "monthly" | "upFront";
8
+ export declare const SUPERWALL_BILLING_PLANS: readonly SuperwallBillingPlan[];
2
9
  /**
3
10
  * A product slot the paywall renders, keyed by reference in
4
11
  * `SuperwallConfig["products"]`. Product data (price, period, trial…) is
@@ -7,13 +14,27 @@ import type { SuperwallPlatform } from "./platforms";
7
14
  export type SuperwallProductSlot = {
8
15
  /** Store product identifier this slot maps to (e.g. "pro_3999_year"). */
9
16
  productId?: string;
17
+ /**
18
+ * Which Apple billing plan this slot sells, when its App Store product
19
+ * offers the monthly plan. iOS only: Android and web have no such plan and
20
+ * ignore it. Defaults to `"monthly"` for a product that offers the monthly
21
+ * plan; has no effect on one that does not.
22
+ */
23
+ billingPlan?: SuperwallBillingPlan;
10
24
  };
11
25
  /**
12
26
  * One store identifier per platform the paywall ships to, for a slot whose
13
27
  * underlying product differs by store — the same `purchase("annual")` buys
14
28
  * the App Store product on iOS and the Play product on Android.
15
29
  */
16
- export type SuperwallPlatformProductIds = Partial<Record<SuperwallPlatform, string>>;
30
+ export type SuperwallPlatformProductIds = Partial<Record<SuperwallPlatform, string>> & {
31
+ /**
32
+ * Which Apple billing plan the iOS product sells, when it offers the
33
+ * monthly plan. Android and web ignore it. Defaults to `"monthly"` for a
34
+ * product that offers the monthly plan; has no effect on one that does not.
35
+ */
36
+ billingPlan?: SuperwallBillingPlan;
37
+ };
17
38
  /**
18
39
  * A slot object, the store product identifier as shorthand, or one
19
40
  * identifier per platform.
@@ -21,3 +42,5 @@ export type SuperwallPlatformProductIds = Partial<Record<SuperwallPlatform, stri
21
42
  export type SuperwallProductSlotInput = string | SuperwallProductSlot | SuperwallPlatformProductIds;
22
43
  export declare const isPlatformProductIds: (input: SuperwallProductSlotInput) => input is SuperwallPlatformProductIds;
23
44
  export declare const productIdFor: (input: SuperwallProductSlotInput, platform?: SuperwallPlatform) => string | undefined;
45
+ export declare const productIdsOf: (input: SuperwallProductSlotInput) => string[];
46
+ export declare const billingPlanFor: (input: SuperwallProductSlotInput, label?: string) => SuperwallBillingPlan | undefined;
@@ -1,4 +1,11 @@
1
+ import { SUPERWALL_PLATFORMS } from "./platforms";
2
+ export const SUPERWALL_BILLING_PLANS = ["monthly", "upFront"];
1
3
  export const isPlatformProductIds = (input) => typeof input === "object" && input !== null && !("productId" in input);
4
+ const isPlatformKey = (key) => SUPERWALL_PLATFORMS.some((platform) => platform === key);
5
+ const platformIdsOf = (input) => Object.keys(input)
6
+ .filter(isPlatformKey)
7
+ .map((platform) => input[platform])
8
+ .filter((id) => typeof id === "string");
2
9
  export const productIdFor = (input, platform) => {
3
10
  if (typeof input === "string")
4
11
  return input;
@@ -6,5 +13,24 @@ export const productIdFor = (input, platform) => {
6
13
  return input.productId;
7
14
  if (platform !== undefined)
8
15
  return input[platform];
9
- return Object.values(input).find((id) => typeof id === "string");
16
+ return platformIdsOf(input)[0];
17
+ };
18
+ export const productIdsOf = (input) => {
19
+ if (typeof input === "string")
20
+ return [input];
21
+ if (isPlatformProductIds(input))
22
+ return [...new Set(platformIdsOf(input))];
23
+ return [input.productId].filter((id) => typeof id === "string");
24
+ };
25
+ export const billingPlanFor = (input, label = "billingPlan") => {
26
+ if (typeof input === "string")
27
+ return undefined;
28
+ const plan = input.billingPlan;
29
+ if (plan === undefined)
30
+ return undefined;
31
+ const known = SUPERWALL_BILLING_PLANS.find((candidate) => candidate === plan);
32
+ if (known === undefined) {
33
+ throw new Error(`${label} must be one of ${SUPERWALL_BILLING_PLANS.map((value) => `"${value}"`).join(", ")}, got ${JSON.stringify(plan)}.`);
34
+ }
35
+ return known;
10
36
  };
@@ -1,5 +1,5 @@
1
1
  import type { ITransport, TEventTrackingBehavior, TIncomingMessage, TIncomingMessageCallbackResult, TIncomingMessageTransactionAbandon, TIncomingMessageTransactionComplete, TOutgoingMessage, TPermissionStatus, TPermissionTypeMessage, TransportKind } from "@superwall/protocol";
2
- import type { SuperwallCheckoutMode, SuperwallConfig, SuperwallPostPurchase } from "../config";
2
+ import type { SuperwallCheckoutMode, SuperwallConfig, SuperwallPostPurchase, SuperwallPrepaidCards } from "../config";
3
3
  import type { SuperwallTranslateValues } from "../localization";
4
4
  import type { SuperwallProduct, SuperwallProductInput, SuperwallProductVariables } from "../products";
5
5
  import type { Outgoing, PageViewInput } from "./outgoing";
@@ -104,6 +104,13 @@ export type SuperwallPurchaseOptions = {
104
104
  * Default: the config's `checkout` mode.
105
105
  */
106
106
  checkout?: SuperwallCheckoutMode;
107
+ /**
108
+ * Whether this purchase's web checkout accepts prepaid cards, overriding
109
+ * the config's `checkout.prepaidCards` for this call. See
110
+ * `SuperwallPrepaidCards`. Ignored by store purchases.
111
+ * Default: the config's `checkout.prepaidCards`, else `"allow"`.
112
+ */
113
+ prepaidCards?: SuperwallPrepaidCards;
107
114
  };
108
115
  export type SuperwallCallbackOptions = {
109
116
  behavior?: CallbackBehavior;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superwall/runtime",
3
- "version": "2.2.0",
3
+ "version": "2.3.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.2.0"
42
+ "@superwall/protocol": "2.3.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@superwall/host": "workspace:*",
@@ -22,10 +22,26 @@ export type SuperwallCheckoutMode = "external" | "sheet" | "applePay";
22
22
  * - `managedPayments` overrides the account's Stripe managed-payments
23
23
  * setting for this paywall: `true` forces it on, `false` forces it off.
24
24
  * Omitted, the account setting applies.
25
+ * - `prepaidCards` decides whether Stripe Checkout accepts prepaid cards.
26
+ * Default: `"allow"`. See `SuperwallPrepaidCards`.
25
27
  */
26
28
  export type SuperwallCheckoutConfig<TReference extends string = string> =
27
29
  | SuperwallCheckoutMode
28
- | { mode: SuperwallCheckoutMode; prefetch?: TReference | false; managedPayments?: boolean };
30
+ | {
31
+ mode: SuperwallCheckoutMode;
32
+ prefetch?: TReference | false;
33
+ managedPayments?: boolean;
34
+ prepaidCards?: SuperwallPrepaidCards;
35
+ };
36
+
37
+ /**
38
+ * Whether a web checkout accepts prepaid cards: `"allow"` (the default) or
39
+ * `"block"`, which makes Stripe refuse them, a defence against free-trial
40
+ * abuse. It applies to the sheet and the hosted checkout page; an Apple Pay
41
+ * payment can't be filtered by card type, so in `applePay` mode only the
42
+ * sheet fallback refuses them. Store purchases ignore it.
43
+ */
44
+ export type SuperwallPrepaidCards = "allow" | "block";
29
45
 
30
46
  export type SuperwallManagedPaymentsOverride = "USE_MANAGED_PAYMENTS" | "USE_DEFAULT_PAYMENTS";
31
47
 
@@ -44,3 +60,8 @@ export const checkoutManagedPaymentsOf = (
44
60
  if (override === undefined) return undefined;
45
61
  return override ? "USE_MANAGED_PAYMENTS" : "USE_DEFAULT_PAYMENTS";
46
62
  };
63
+
64
+ export const checkoutPrepaidCardsOf = (
65
+ checkout: SuperwallCheckoutConfig | undefined,
66
+ ): SuperwallPrepaidCards =>
67
+ (typeof checkout === "object" ? checkout.prepaidCards : undefined) ?? "allow";
@@ -126,9 +126,11 @@ export {
126
126
  checkoutManagedPaymentsOf,
127
127
  checkoutModeOf,
128
128
  checkoutPrefetchOf,
129
+ checkoutPrepaidCardsOf,
129
130
  type SuperwallCheckoutConfig,
130
131
  type SuperwallCheckoutMode,
131
132
  type SuperwallManagedPaymentsOverride,
133
+ type SuperwallPrepaidCards,
132
134
  } from "./checkout";
133
135
  export {
134
136
  INSET_EDGES,
@@ -156,8 +158,12 @@ export {
156
158
  type SuperwallTeleportOptions,
157
159
  } from "./teleport";
158
160
  export {
161
+ billingPlanFor,
159
162
  isPlatformProductIds,
160
163
  productIdFor,
164
+ productIdsOf,
165
+ SUPERWALL_BILLING_PLANS,
166
+ type SuperwallBillingPlan,
161
167
  type SuperwallPlatformProductIds,
162
168
  type SuperwallProductSlot,
163
169
  type SuperwallProductSlotInput,
@@ -1,4 +1,13 @@
1
- import type { SuperwallPlatform } from "./platforms";
1
+ import { SUPERWALL_PLATFORMS, type SuperwallPlatform } from "./platforms";
2
+
3
+ /**
4
+ * How an App Store slot bills a product that offers Apple's monthly plan
5
+ * (a 12-month commitment paid monthly): `"monthly"` sells that plan,
6
+ * `"upFront"` sells the year paid at once.
7
+ */
8
+ export type SuperwallBillingPlan = "monthly" | "upFront";
9
+
10
+ export const SUPERWALL_BILLING_PLANS: readonly SuperwallBillingPlan[] = ["monthly", "upFront"];
2
11
 
3
12
  /**
4
13
  * A product slot the paywall renders, keyed by reference in
@@ -8,6 +17,13 @@ import type { SuperwallPlatform } from "./platforms";
8
17
  export type SuperwallProductSlot = {
9
18
  /** Store product identifier this slot maps to (e.g. "pro_3999_year"). */
10
19
  productId?: string;
20
+ /**
21
+ * Which Apple billing plan this slot sells, when its App Store product
22
+ * offers the monthly plan. iOS only: Android and web have no such plan and
23
+ * ignore it. Defaults to `"monthly"` for a product that offers the monthly
24
+ * plan; has no effect on one that does not.
25
+ */
26
+ billingPlan?: SuperwallBillingPlan;
11
27
  };
12
28
 
13
29
  /**
@@ -15,7 +31,14 @@ export type SuperwallProductSlot = {
15
31
  * underlying product differs by store — the same `purchase("annual")` buys
16
32
  * the App Store product on iOS and the Play product on Android.
17
33
  */
18
- export type SuperwallPlatformProductIds = Partial<Record<SuperwallPlatform, string>>;
34
+ export type SuperwallPlatformProductIds = Partial<Record<SuperwallPlatform, string>> & {
35
+ /**
36
+ * Which Apple billing plan the iOS product sells, when it offers the
37
+ * monthly plan. Android and web ignore it. Defaults to `"monthly"` for a
38
+ * product that offers the monthly plan; has no effect on one that does not.
39
+ */
40
+ billingPlan?: SuperwallBillingPlan;
41
+ };
19
42
 
20
43
  /**
21
44
  * A slot object, the store product identifier as shorthand, or one
@@ -28,6 +51,15 @@ export const isPlatformProductIds = (
28
51
  ): input is SuperwallPlatformProductIds =>
29
52
  typeof input === "object" && input !== null && !("productId" in input);
30
53
 
54
+ const isPlatformKey = (key: string): key is SuperwallPlatform =>
55
+ SUPERWALL_PLATFORMS.some((platform) => platform === key);
56
+
57
+ const platformIdsOf = (input: SuperwallPlatformProductIds): string[] =>
58
+ Object.keys(input)
59
+ .filter(isPlatformKey)
60
+ .map((platform) => input[platform])
61
+ .filter((id): id is string => typeof id === "string");
62
+
31
63
  export const productIdFor = (
32
64
  input: SuperwallProductSlotInput,
33
65
  platform?: SuperwallPlatform,
@@ -35,5 +67,27 @@ export const productIdFor = (
35
67
  if (typeof input === "string") return input;
36
68
  if (!isPlatformProductIds(input)) return input.productId;
37
69
  if (platform !== undefined) return input[platform];
38
- return Object.values(input).find((id) => typeof id === "string");
70
+ return platformIdsOf(input)[0];
71
+ };
72
+
73
+ export const productIdsOf = (input: SuperwallProductSlotInput): string[] => {
74
+ if (typeof input === "string") return [input];
75
+ if (isPlatformProductIds(input)) return [...new Set(platformIdsOf(input))];
76
+ return [input.productId].filter((id): id is string => typeof id === "string");
77
+ };
78
+
79
+ export const billingPlanFor = (
80
+ input: SuperwallProductSlotInput,
81
+ label = "billingPlan",
82
+ ): SuperwallBillingPlan | undefined => {
83
+ if (typeof input === "string") return undefined;
84
+ const plan: unknown = input.billingPlan;
85
+ if (plan === undefined) return undefined;
86
+ const known = SUPERWALL_BILLING_PLANS.find((candidate) => candidate === plan);
87
+ if (known === undefined) {
88
+ throw new Error(
89
+ `${label} must be one of ${SUPERWALL_BILLING_PLANS.map((value) => `"${value}"`).join(", ")}, got ${JSON.stringify(plan)}.`,
90
+ );
91
+ }
92
+ return known;
39
93
  };
@@ -10,7 +10,12 @@ import type {
10
10
  TPermissionTypeMessage,
11
11
  TransportKind,
12
12
  } from "@superwall/protocol";
13
- import type { SuperwallCheckoutMode, SuperwallConfig, SuperwallPostPurchase } from "../config";
13
+ import type {
14
+ SuperwallCheckoutMode,
15
+ SuperwallConfig,
16
+ SuperwallPostPurchase,
17
+ SuperwallPrepaidCards,
18
+ } from "../config";
14
19
  import type { SuperwallTranslateValues } from "../localization";
15
20
  import type {
16
21
  SuperwallProduct,
@@ -143,6 +148,13 @@ export type SuperwallPurchaseOptions = {
143
148
  * Default: the config's `checkout` mode.
144
149
  */
145
150
  checkout?: SuperwallCheckoutMode;
151
+ /**
152
+ * Whether this purchase's web checkout accepts prepaid cards, overriding
153
+ * the config's `checkout.prepaidCards` for this call. See
154
+ * `SuperwallPrepaidCards`. Ignored by store purchases.
155
+ * Default: the config's `checkout.prepaidCards`, else `"allow"`.
156
+ */
157
+ prepaidCards?: SuperwallPrepaidCards;
146
158
  };
147
159
 
148
160
  export type SuperwallCallbackOptions = {