@rocapine/react-native-onboarding 1.69.0 → 1.70.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/OnboardingStudioClient.d.ts +4 -4
- package/dist/OnboardingStudioClient.js +7 -7
- package/dist/OnboardingStudioClient.js.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +24 -7
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +80 -42
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/present.d.ts +60 -14
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +67 -18
- package/dist/paywalls/present.js.map +1 -1
- package/dist/paywalls/types.d.ts +48 -23
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/paywalls/types.js +0 -7
- package/dist/paywalls/types.js.map +1 -1
- package/dist/paywalls/usePaywall.d.ts +5 -5
- package/dist/paywalls/usePaywall.d.ts.map +1 -1
- package/dist/products/adapters/stripeLink.d.ts +57 -0
- package/dist/products/adapters/stripeLink.d.ts.map +1 -0
- package/dist/products/adapters/stripeLink.js +158 -0
- package/dist/products/adapters/stripeLink.js.map +1 -0
- package/dist/products/index.d.ts +4 -1
- package/dist/products/index.d.ts.map +1 -1
- package/dist/products/index.js +5 -1
- package/dist/products/index.js.map +1 -1
- package/dist/products/refIdentity.d.ts +3 -0
- package/dist/products/refIdentity.d.ts.map +1 -0
- package/dist/products/refIdentity.js +37 -0
- package/dist/products/refIdentity.js.map +1 -0
- package/dist/products/types.d.ts +29 -1
- package/dist/products/types.d.ts.map +1 -1
- package/dist/products/useProducts.d.ts.map +1 -1
- package/dist/products/useProducts.js +7 -1
- package/dist/products/useProducts.js.map +1 -1
- package/package.json +1 -1
- package/src/OnboardingStudioClient.ts +7 -7
- package/src/paywalls/PaywallProvider.tsx +109 -46
- package/src/paywalls/__tests__/getPaywalls.test.ts +15 -12
- package/src/paywalls/__tests__/present.test.ts +149 -28
- package/src/paywalls/present.ts +74 -21
- package/src/paywalls/types.ts +49 -23
- package/src/paywalls/usePaywall.ts +5 -5
- package/src/products/__tests__/refIdentity.test.ts +44 -0
- package/src/products/adapters/__tests__/stripeLink.test.ts +179 -0
- package/src/products/adapters/stripeLink.ts +245 -0
- package/src/products/index.ts +4 -0
- package/src/products/refIdentity.ts +33 -0
- package/src/products/types.ts +30 -1
- package/src/products/useProducts.ts +7 -4
package/src/products/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type {
|
|
2
2
|
ProductRef,
|
|
3
|
+
StripeProductRef,
|
|
3
4
|
ProductPeriod,
|
|
4
5
|
ResolvedProduct,
|
|
5
6
|
DerivedProductFields,
|
|
@@ -13,8 +14,11 @@ export type {
|
|
|
13
14
|
export { parseIsoDuration } from "./duration";
|
|
14
15
|
export { formatCurrency, deriveProductFields, deriveAll } from "./derive";
|
|
15
16
|
export { productVariables } from "./toVariables";
|
|
17
|
+
export { productRefIdentity } from "./refIdentity";
|
|
16
18
|
export { useProducts } from "./useProducts";
|
|
17
19
|
export { ProductRuntimeContext, useProductRuntime } from "./ProductRuntimeContext";
|
|
18
20
|
export { stubProductProvider } from "./adapters/stub";
|
|
19
21
|
export { revenueCatProductProvider } from "./adapters/revenueCat";
|
|
20
22
|
export { expoIapProductProvider } from "./adapters/expoIap";
|
|
23
|
+
export { stripeLinkProductProvider } from "./adapters/stripeLink";
|
|
24
|
+
export type { StripeLinkProviderConfig } from "./adapters/stripeLink";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ProductRef } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The content identity of a `ProductRef` — the ONE place its fields are
|
|
5
|
+
* enumerated.
|
|
6
|
+
*
|
|
7
|
+
* Two callers depend on this and neither fails loudly when it is wrong:
|
|
8
|
+
* `useProducts`'s `refsKey` (a stale identity means a changed ref never
|
|
9
|
+
* refetches) and `collectProductRefs`'s dedup (a colliding identity means two
|
|
10
|
+
* distinct refs collapse into one and the second is never resolved). Both used
|
|
11
|
+
* to hand-roll the same template string, so adding a field to `ProductRef`
|
|
12
|
+
* meant remembering two places. Add new fields HERE and both callers follow.
|
|
13
|
+
*
|
|
14
|
+
* A unit separator (U+001F) rather than a printable one: a Play id is
|
|
15
|
+
* `productId:basePlanId` and a Payment Link is a URL, both of which can
|
|
16
|
+
* contain almost any printable character, so a printable separator risks
|
|
17
|
+
* `{ios:"a",android:"b"}` and `{ios:"a|b"}` hashing alike.
|
|
18
|
+
*/
|
|
19
|
+
const SEP = "\u001F";
|
|
20
|
+
|
|
21
|
+
export const productRefIdentity = (ref: ProductRef): string =>
|
|
22
|
+
[
|
|
23
|
+
ref.key,
|
|
24
|
+
ref.ios ?? "",
|
|
25
|
+
ref.android ?? "",
|
|
26
|
+
ref.compareTo ?? "",
|
|
27
|
+
ref.stripe?.paymentLink ?? "",
|
|
28
|
+
ref.stripe?.priceId ?? "",
|
|
29
|
+
ref.stripe?.amount ?? "",
|
|
30
|
+
ref.stripe?.currency ?? "",
|
|
31
|
+
ref.stripe?.periodIso ?? "",
|
|
32
|
+
ref.stripe?.trialDays ?? "",
|
|
33
|
+
].join(SEP);
|
package/src/products/types.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Stripe Payment Link and the price to render beside it.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `ios`/`android` — which are ids a store resolves at runtime — this
|
|
5
|
+
* block is the RESOLVED product. There is no Stripe runtime to ask: listing a
|
|
6
|
+
* price needs a secret key, and by design nobody in this system holds one
|
|
7
|
+
* (not the host, not Onboarding Studio). So the studio copies the authored
|
|
8
|
+
* price onto the ref, and `stripeLinkProductProvider` synthesises a
|
|
9
|
+
* `ResolvedProduct` from it without any network call.
|
|
10
|
+
*
|
|
11
|
+
* Consequence the author owns: this price can DRIFT from Stripe. Nothing
|
|
12
|
+
* reconciles them.
|
|
13
|
+
*/
|
|
14
|
+
export type StripeProductRef = {
|
|
15
|
+
/** `https://buy.stripe.com/...`, pre-created in Stripe. Required — nothing to open without it. */
|
|
16
|
+
paymentLink: string;
|
|
17
|
+
/** `price_...`. Informational in this version; kept for reconciliation and a future proxy mode. */
|
|
18
|
+
priceId?: string;
|
|
19
|
+
/** Major units (79, not 7900), matching `project_products.stripe_price.amount`. */
|
|
20
|
+
amount: number;
|
|
21
|
+
/** ISO-4217, e.g. "USD". */
|
|
22
|
+
currency: string;
|
|
23
|
+
/** ISO-8601, e.g. "P1Y". Drives `pricePerWeek` and friends via `deriveProductFields`. */
|
|
24
|
+
periodIso?: string | null;
|
|
25
|
+
trialDays?: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
1
28
|
/** A product slot declared by the author: a stable key plus per-store ids. */
|
|
2
29
|
export type ProductRef = {
|
|
3
30
|
/** Author-chosen slot name used in variables, e.g. "yearly" → product.yearly.price */
|
|
@@ -6,6 +33,8 @@ export type ProductRef = {
|
|
|
6
33
|
ios?: string;
|
|
7
34
|
/** Play product identifier. `productId:basePlanId` — RevenueCat's convention. */
|
|
8
35
|
android?: string;
|
|
36
|
+
/** Stripe Payment Link + authored price. Present only on a `billing: "stripe"` paywall's refs. */
|
|
37
|
+
stripe?: StripeProductRef;
|
|
9
38
|
/** Another slot's key; savingsPct is computed against it. */
|
|
10
39
|
compareTo?: string;
|
|
11
40
|
};
|
|
@@ -17,7 +46,7 @@ export type ResolvedProduct = {
|
|
|
17
46
|
key: string;
|
|
18
47
|
/** The identifier resolved for THIS platform. */
|
|
19
48
|
productId: string;
|
|
20
|
-
store: "app_store" | "play_store";
|
|
49
|
+
store: "app_store" | "play_store" | "stripe";
|
|
21
50
|
title: string;
|
|
22
51
|
description: string;
|
|
23
52
|
/** Store-localized, pre-formatted, e.g. "$59.99". Display this. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { deriveAll } from "./derive";
|
|
3
|
+
import { productRefIdentity } from "./refIdentity";
|
|
3
4
|
import type {
|
|
4
5
|
ProductProvider,
|
|
5
6
|
ProductRef,
|
|
@@ -39,10 +40,12 @@ export const useProducts = (
|
|
|
39
40
|
|
|
40
41
|
// Key the effect on the refs' identity CONTENT, not the array identity — a
|
|
41
42
|
// host passing an inline array literal would otherwise refetch every render.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
// `productRefIdentity` owns the field list; see its doc for why it is shared
|
|
44
|
+
// with `collectProductRefs` rather than duplicated here.
|
|
45
|
+
// "\u001E" (record separator) BETWEEN refs, distinct from the "\u001F"
|
|
46
|
+
// `productRefIdentity` puts between FIELDS — one separator for each nesting
|
|
47
|
+
// level, so no arrangement of ids can produce two identical keys.
|
|
48
|
+
const refsKey = useMemo(() => (refs ?? []).map(productRefIdentity).join("\u001E"), [refs]);
|
|
46
49
|
const refsRef = useRef(refs);
|
|
47
50
|
refsRef.current = refs;
|
|
48
51
|
|