@rocapine/react-native-onboarding 1.60.0 → 1.61.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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/infra/provider/OnboardingProvider.d.ts +12 -1
- package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
- package/dist/infra/provider/OnboardingProvider.js +15 -1
- package/dist/infra/provider/OnboardingProvider.js.map +1 -1
- package/dist/products/adapters/expoIap.d.ts +4 -0
- package/dist/products/adapters/expoIap.d.ts.map +1 -0
- package/dist/products/adapters/expoIap.js +95 -0
- package/dist/products/adapters/expoIap.js.map +1 -0
- package/dist/products/adapters/revenueCat.d.ts +7 -0
- package/dist/products/adapters/revenueCat.d.ts.map +1 -0
- package/dist/products/adapters/revenueCat.js +116 -0
- package/dist/products/adapters/revenueCat.js.map +1 -0
- package/dist/products/adapters/stub.d.ts +8 -0
- package/dist/products/adapters/stub.d.ts.map +1 -0
- package/dist/products/adapters/stub.js +21 -0
- package/dist/products/adapters/stub.js.map +1 -0
- package/dist/products/derive.d.ts +19 -0
- package/dist/products/derive.d.ts.map +1 -0
- package/dist/products/derive.js +79 -0
- package/dist/products/derive.js.map +1 -0
- package/dist/products/duration.d.ts +3 -0
- package/dist/products/duration.d.ts.map +1 -0
- package/dist/products/duration.js +25 -0
- package/dist/products/duration.js.map +1 -0
- package/dist/products/index.d.ts +9 -0
- package/dist/products/index.d.ts.map +1 -0
- package/dist/products/index.js +20 -0
- package/dist/products/index.js.map +1 -0
- package/dist/products/toVariables.d.ts +18 -0
- package/dist/products/toVariables.d.ts.map +1 -0
- package/dist/products/toVariables.js +52 -0
- package/dist/products/toVariables.js.map +1 -0
- package/dist/products/types.d.ts +96 -0
- package/dist/products/types.d.ts.map +1 -0
- package/dist/products/types.js +3 -0
- package/dist/products/types.js.map +1 -0
- package/dist/products/useProducts.d.ts +12 -0
- package/dist/products/useProducts.d.ts.map +1 -0
- package/dist/products/useProducts.js +90 -0
- package/dist/products/useProducts.js.map +1 -0
- package/dist/screens/elements/AnimatedTextElement.d.ts +1 -24
- package/dist/screens/elements/AnimatedTextElement.d.ts.map +1 -1
- package/dist/screens/elements/BaseBoxProps.d.ts +1 -24
- package/dist/screens/elements/BaseBoxProps.d.ts.map +1 -1
- package/dist/screens/elements/ButtonElement.d.ts +6 -121
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/CarouselElement.d.ts +1 -24
- package/dist/screens/elements/CarouselElement.d.ts.map +1 -1
- package/dist/screens/elements/CheckboxGroupElement.d.ts +1 -24
- package/dist/screens/elements/CheckboxGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/DatePickerElement.d.ts +1 -24
- package/dist/screens/elements/DatePickerElement.d.ts.map +1 -1
- package/dist/screens/elements/DrawingPadElement.d.ts +1 -24
- package/dist/screens/elements/DrawingPadElement.d.ts.map +1 -1
- package/dist/screens/elements/IconElement.d.ts +1 -24
- package/dist/screens/elements/IconElement.d.ts.map +1 -1
- package/dist/screens/elements/ImageElement.d.ts +1 -24
- package/dist/screens/elements/ImageElement.d.ts.map +1 -1
- package/dist/screens/elements/InputElement.d.ts +1 -24
- package/dist/screens/elements/InputElement.d.ts.map +1 -1
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts +1 -24
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts.map +1 -1
- package/dist/screens/elements/LottieElement.d.ts +1 -24
- package/dist/screens/elements/LottieElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressIndicatorElement.d.ts +1 -24
- package/dist/screens/elements/ProgressIndicatorElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts +1 -24
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts.map +1 -1
- package/dist/screens/elements/RadioGroupElement.d.ts +1 -24
- package/dist/screens/elements/RadioGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/RichTextElement.d.ts +1 -24
- package/dist/screens/elements/RichTextElement.d.ts.map +1 -1
- package/dist/screens/elements/RiveElement.d.ts +1 -24
- package/dist/screens/elements/RiveElement.d.ts.map +1 -1
- package/dist/screens/elements/SafeAreaViewElement.d.ts +1 -24
- package/dist/screens/elements/SafeAreaViewElement.d.ts.map +1 -1
- package/dist/screens/elements/ScrollViewElement.d.ts +1 -24
- package/dist/screens/elements/ScrollViewElement.d.ts.map +1 -1
- package/dist/screens/elements/SliderElement.d.ts +1 -24
- package/dist/screens/elements/SliderElement.d.ts.map +1 -1
- package/dist/screens/elements/StackElement.d.ts +1 -24
- package/dist/screens/elements/StackElement.d.ts.map +1 -1
- package/dist/screens/elements/TextElement.d.ts +1 -24
- package/dist/screens/elements/TextElement.d.ts.map +1 -1
- package/dist/screens/elements/TypewriterTextElement.d.ts +1 -24
- package/dist/screens/elements/TypewriterTextElement.d.ts.map +1 -1
- package/dist/screens/elements/VideoElement.d.ts +1 -24
- package/dist/screens/elements/VideoElement.d.ts.map +1 -1
- package/dist/screens/elements/WheelPickerElement.d.ts +1 -24
- package/dist/screens/elements/WheelPickerElement.d.ts.map +1 -1
- package/dist/screens/elements/ZStackElement.d.ts +1 -24
- package/dist/screens/elements/ZStackElement.d.ts.map +1 -1
- package/dist/steps/Carousel/types.d.ts +1 -1
- package/dist/steps/Commitment/types.d.ts +1 -1
- package/dist/steps/ComposableScreen/types.d.ts +1 -1
- package/dist/steps/Loader/types.d.ts +1 -1
- package/dist/steps/MediaContent/types.d.ts +1 -1
- package/dist/steps/Picker/types.d.ts +1 -1
- package/dist/steps/Question/types.d.ts +1 -1
- package/dist/steps/Ratings/types.d.ts +1 -1
- package/dist/steps/common.types.d.ts +23 -30
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +18 -3
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/productAdapters.test.ts +58 -0
- package/src/__tests__/productDerive.test.ts +111 -0
- package/src/__tests__/productVariables.test.ts +109 -0
- package/src/index.ts +2 -0
- package/src/infra/provider/OnboardingProvider.tsx +29 -0
- package/src/products/adapters/expoIap.ts +93 -0
- package/src/products/adapters/revenueCat.ts +108 -0
- package/src/products/adapters/stub.ts +20 -0
- package/src/products/derive.ts +93 -0
- package/src/products/duration.ts +21 -0
- package/src/products/index.ts +19 -0
- package/src/products/toVariables.ts +54 -0
- package/src/products/types.ts +88 -0
- package/src/products/useProducts.ts +106 -0
- package/src/steps/common.types.ts +50 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.d.ts","sourceRoot":"","sources":["../../src/steps/common.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB,kEAA0C,CAAC;AAE3E,eAAO,MAAM,iBAAiB;;;;;;mBAS5B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;iBAI5B,CAAC;AAEH,eAAO,MAAM,aAAa;;;iBAGxB,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;iBAG9B,CAAC;AAMH,eAAO,MAAM,iBAAiB;;;;;;;EAO5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAQ5D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAA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MAAM,oBAAoB,0IAK/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;iBAc5B,CAAC;AACL,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,KAAK,CAAC,aAAa,GAAG,cAAc,CAAC,CAAC;CACnD,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAO1D,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;iBAGvB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;mBAMX,CAAC;AACjB,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAIhD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa7B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseStepTypeSchema = exports.ONBOARDING_END_STEP_ID = exports.NextStepSchema = exports.BranchSchema = exports.ConditionGroupSchema = exports.LeafConditionSchema = exports.ConditionValueSchema = exports.isUnaryConditionOperator = exports.UNARY_CONDITION_OPERATORS = exports.ConditionOperatorSchema = exports.ButtonActionSchema = exports.SetVariableButtonActionSchema = exports.CustomButtonActionSchema = exports.HapticStyleSchema = exports.ButtonSectionSchema = exports.InfoBoxSchema = exports.SocialProofSchema = exports.MediaSourceSchema = exports.CustomPayloadSchema = void 0;
|
|
3
|
+
exports.BaseStepTypeSchema = exports.ONBOARDING_END_STEP_ID = exports.NextStepSchema = exports.BranchSchema = exports.ConditionGroupSchema = exports.LeafConditionSchema = exports.ConditionValueSchema = exports.isUnaryConditionOperator = exports.UNARY_CONDITION_OPERATORS = exports.ConditionOperatorSchema = exports.ButtonActionSchema = exports.RestoreButtonActionSchema = exports.PurchaseButtonActionSchema = exports.SetVariableButtonActionSchema = exports.CustomButtonActionSchema = exports.HapticStyleSchema = exports.ButtonSectionSchema = exports.InfoBoxSchema = exports.SocialProofSchema = exports.MediaSourceSchema = exports.CustomPayloadSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.CustomPayloadSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any()).nullish();
|
|
6
6
|
exports.MediaSourceSchema = zod_1.z.union([
|
|
@@ -52,11 +52,26 @@ exports.SetVariableButtonActionSchema = zod_1.z.object({
|
|
|
52
52
|
kind: zod_1.z.enum(["int", "float", "string"]).optional(),
|
|
53
53
|
arrayOp: zod_1.z.enum(["append", "remove", "toggle"]).optional(),
|
|
54
54
|
});
|
|
55
|
-
exports.
|
|
55
|
+
exports.PurchaseButtonActionSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
56
|
+
type: zod_1.z.literal("purchase"),
|
|
57
|
+
product: zod_1.z.string().min(1, "product must not be empty"),
|
|
58
|
+
onSuccess: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
59
|
+
onCancel: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
60
|
+
onError: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
61
|
+
}));
|
|
62
|
+
exports.RestoreButtonActionSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
63
|
+
type: zod_1.z.literal("restore"),
|
|
64
|
+
onSuccess: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
65
|
+
onNothingToRestore: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
66
|
+
onError: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
67
|
+
}));
|
|
68
|
+
exports.ButtonActionSchema = zod_1.z.lazy(() => zod_1.z.union([
|
|
56
69
|
zod_1.z.literal("continue"),
|
|
57
70
|
exports.CustomButtonActionSchema,
|
|
58
71
|
exports.SetVariableButtonActionSchema,
|
|
59
|
-
|
|
72
|
+
exports.PurchaseButtonActionSchema,
|
|
73
|
+
exports.RestoreButtonActionSchema,
|
|
74
|
+
]));
|
|
60
75
|
// ── Branching / nextStep schemas ─────────────────────────────────────────────
|
|
61
76
|
exports.ConditionOperatorSchema = zod_1.z.enum([
|
|
62
77
|
"eq",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.js","sourceRoot":"","sources":["../../src/steps/common.types.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAE9D,QAAA,iBAAiB,GAAG,OAAC,CAAC,KAAK,CAAC;IACvC,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7F,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;KACxB,CAAC;IACF,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAA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;IAC9B,QAAQ,EAAE,sBAAc;CACzB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.61.0",
|
|
4
4
|
"description": "Headless React Native SDK for Rocapine Onboarding Studio - Data fetching, state management, and hooks",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import type { ProductRef, ResolvedProduct } from "../products/types";
|
|
3
|
+
|
|
4
|
+
// Neither react-native-purchases nor expo-iap is a dependency of this repo —
|
|
5
|
+
// their absence IS the condition under test (not simulated). Mirrors the
|
|
6
|
+
// `react-native` mock getOnboarding.query.test.ts already uses for the same
|
|
7
|
+
// import, so `Platform` resolves without pulling in real react-native.
|
|
8
|
+
vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
|
|
9
|
+
|
|
10
|
+
const REF: ProductRef = { key: "yearly", ios: "com.app.yearly" };
|
|
11
|
+
|
|
12
|
+
const FAKE_PRODUCT: ResolvedProduct = {
|
|
13
|
+
key: "yearly",
|
|
14
|
+
productId: "com.app.yearly",
|
|
15
|
+
store: "app_store",
|
|
16
|
+
title: "Yearly",
|
|
17
|
+
description: "",
|
|
18
|
+
price: "$59.99",
|
|
19
|
+
priceAmount: 59.99,
|
|
20
|
+
currencyCode: "USD",
|
|
21
|
+
period: "year",
|
|
22
|
+
periodCount: 1,
|
|
23
|
+
periodIso: "P1Y",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe("revenueCatProductProvider — degrades cleanly when react-native-purchases is absent", () => {
|
|
27
|
+
it("importing the module and calling the factory do not throw", async () => {
|
|
28
|
+
const { revenueCatProductProvider } = await import("../products/adapters/revenueCat");
|
|
29
|
+
expect(() => revenueCatProductProvider()).not.toThrow();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("defers the missing-dependency error to call time, and names the missing package", async () => {
|
|
33
|
+
const { revenueCatProductProvider } = await import("../products/adapters/revenueCat");
|
|
34
|
+
const provider = revenueCatProductProvider();
|
|
35
|
+
await expect(provider.getProducts([REF])).rejects.toThrow(
|
|
36
|
+
/react-native-purchases is not installed/
|
|
37
|
+
);
|
|
38
|
+
await expect(provider.purchase(FAKE_PRODUCT)).rejects.toThrow(
|
|
39
|
+
/react-native-purchases is not installed/
|
|
40
|
+
);
|
|
41
|
+
await expect(provider.restore()).rejects.toThrow(/react-native-purchases is not installed/);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("expoIapProductProvider — degrades cleanly when expo-iap is absent", () => {
|
|
46
|
+
it("importing the module and calling the factory do not throw", async () => {
|
|
47
|
+
const { expoIapProductProvider } = await import("../products/adapters/expoIap");
|
|
48
|
+
expect(() => expoIapProductProvider()).not.toThrow();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("defers the missing-dependency error to call time, and names the missing package", async () => {
|
|
52
|
+
const { expoIapProductProvider } = await import("../products/adapters/expoIap");
|
|
53
|
+
const provider = expoIapProductProvider();
|
|
54
|
+
await expect(provider.getProducts([REF])).rejects.toThrow(/expo-iap is not installed/);
|
|
55
|
+
await expect(provider.purchase(FAKE_PRODUCT)).rejects.toThrow(/expo-iap is not installed/);
|
|
56
|
+
await expect(provider.restore()).rejects.toThrow(/expo-iap is not installed/);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { parseIsoDuration } from "../products/duration";
|
|
3
|
+
import { formatCurrency, deriveProductFields, deriveAll } from "../products/derive";
|
|
4
|
+
import type { ResolvedProduct, ProductRef } from "../products/types";
|
|
5
|
+
|
|
6
|
+
const make = (over: Partial<ResolvedProduct> = {}): ResolvedProduct => ({
|
|
7
|
+
key: "yearly",
|
|
8
|
+
productId: "com.app.yearly",
|
|
9
|
+
store: "app_store",
|
|
10
|
+
title: "Yearly",
|
|
11
|
+
description: "",
|
|
12
|
+
price: "$59.99",
|
|
13
|
+
priceAmount: 59.99,
|
|
14
|
+
currencyCode: "USD",
|
|
15
|
+
period: "year",
|
|
16
|
+
periodCount: 1,
|
|
17
|
+
periodIso: "P1Y",
|
|
18
|
+
...over,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("parseIsoDuration", () => {
|
|
22
|
+
it("parses the store-standard periods to days", () => {
|
|
23
|
+
expect(parseIsoDuration("P1W")).toBe(7);
|
|
24
|
+
expect(parseIsoDuration("P1M")).toBe(30);
|
|
25
|
+
expect(parseIsoDuration("P3M")).toBe(90);
|
|
26
|
+
expect(parseIsoDuration("P6M")).toBe(180);
|
|
27
|
+
expect(parseIsoDuration("P1Y")).toBe(365);
|
|
28
|
+
expect(parseIsoDuration("P7D")).toBe(7);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("returns null for junk rather than guessing", () => {
|
|
32
|
+
expect(parseIsoDuration("")).toBeNull();
|
|
33
|
+
expect(parseIsoDuration("1Y")).toBeNull();
|
|
34
|
+
expect(parseIsoDuration("PT1H")).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("formatCurrency", () => {
|
|
39
|
+
it("formats in the product's currency, not the device's", () => {
|
|
40
|
+
expect(formatCurrency(1.15, "USD", "en-US")).toBe("$1.15");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("falls back to a plain amount+code string when Intl rejects the currency code", () => {
|
|
44
|
+
// "XYZ" is syntactically valid (3 letters) and Intl accepts it even though it's
|
|
45
|
+
// not a real currency, so it never exercises the catch branch. "ZZZZZZ" is the
|
|
46
|
+
// wrong shape and Intl genuinely throws on it.
|
|
47
|
+
expect(formatCurrency(5, "ZZZZZZ", "en-US")).toBe("5.00 ZZZZZZ");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("deriveProductFields", () => {
|
|
52
|
+
it("computes per-period prices from the ISO period", () => {
|
|
53
|
+
const d = deriveProductFields(make(), { locale: "en-US" });
|
|
54
|
+
// 59.99 / (365/7) weeks
|
|
55
|
+
expect(d.pricePerWeekAmount).toBeCloseTo(1.1504, 3);
|
|
56
|
+
expect(d.pricePerWeek).toBe("$1.15");
|
|
57
|
+
expect(d.pricePerMonthAmount).toBeCloseTo(4.9307, 3);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("leaves savingsPct undefined without a compareTo", () => {
|
|
61
|
+
expect(deriveProductFields(make(), { locale: "en-US" }).savingsPct).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("computes savingsPct against a normalized per-day comparison", () => {
|
|
65
|
+
const yearly = make(); // 59.99 / 365d
|
|
66
|
+
const monthly = make({ key: "monthly", priceAmount: 9.99, periodIso: "P1M" }); // 9.99 / 30d
|
|
67
|
+
const d = deriveProductFields(yearly, { compareTo: monthly, locale: "en-US" });
|
|
68
|
+
// yearly/day = 0.16436, monthly/day = 0.333 → ~51% cheaper
|
|
69
|
+
expect(d.savingsPct).toBe(51);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("omits savingsPct when the comparison is not cheaper", () => {
|
|
73
|
+
const a = make({ priceAmount: 400 });
|
|
74
|
+
const b = make({ key: "monthly", priceAmount: 9.99, periodIso: "P1M" });
|
|
75
|
+
expect(deriveProductFields(a, { compareTo: b }).savingsPct).toBeUndefined();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("derives trialDays from the trial period", () => {
|
|
79
|
+
const p = make({ trial: { period: "week", periodCount: 1, days: 0 } });
|
|
80
|
+
expect(deriveProductFields(p).trialDays).toBe(7);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("returns no per-period prices when the period is unparseable", () => {
|
|
84
|
+
const d = deriveProductFields(make({ periodIso: null, period: null }));
|
|
85
|
+
expect(d.pricePerWeek).toBeUndefined();
|
|
86
|
+
expect(d.pricePerWeekAmount).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("deriveAll", () => {
|
|
91
|
+
const refs: ProductRef[] = [
|
|
92
|
+
{ key: "yearly", ios: "com.app.yearly", compareTo: "monthly" },
|
|
93
|
+
{ key: "monthly", ios: "com.app.monthly" },
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
it("keys results by ref key and resolves compareTo between them", () => {
|
|
97
|
+
const products = [
|
|
98
|
+
make(),
|
|
99
|
+
make({ key: "monthly", priceAmount: 9.99, periodIso: "P1M", period: "month" }),
|
|
100
|
+
];
|
|
101
|
+
const out = deriveAll(products, refs, "en-US");
|
|
102
|
+
expect(Object.keys(out).sort()).toEqual(["monthly", "yearly"]);
|
|
103
|
+
expect(out.yearly.savingsPct).toBe(51);
|
|
104
|
+
expect(out.monthly.savingsPct).toBeUndefined();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("ignores a compareTo pointing at a missing key", () => {
|
|
108
|
+
const out = deriveAll([make()], [{ key: "yearly", compareTo: "nope" }], "en-US");
|
|
109
|
+
expect(out.yearly.savingsPct).toBeUndefined();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { productVariables } from "../products/toVariables";
|
|
3
|
+
import type { ProductWithDerived } from "../products/types";
|
|
4
|
+
|
|
5
|
+
const yearly: ProductWithDerived = {
|
|
6
|
+
key: "yearly",
|
|
7
|
+
productId: "com.app.yearly",
|
|
8
|
+
store: "app_store",
|
|
9
|
+
title: "Yearly Plan",
|
|
10
|
+
description: "A year",
|
|
11
|
+
price: "$59.99",
|
|
12
|
+
priceAmount: 59.99,
|
|
13
|
+
currencyCode: "USD",
|
|
14
|
+
period: "year",
|
|
15
|
+
periodCount: 1,
|
|
16
|
+
periodIso: "P1Y",
|
|
17
|
+
pricePerWeek: "$1.15",
|
|
18
|
+
pricePerWeekAmount: 1.1504,
|
|
19
|
+
savingsPct: 51,
|
|
20
|
+
trialDays: 7,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Every optional field populated, so the dotted-key test below catches both a
|
|
24
|
+
// typo in an emitted key and an accidentally-dropped field.
|
|
25
|
+
const complete: ProductWithDerived = {
|
|
26
|
+
...yearly,
|
|
27
|
+
key: "complete",
|
|
28
|
+
productId: "com.app.complete",
|
|
29
|
+
pricePerMonth: "$4.93",
|
|
30
|
+
pricePerMonthAmount: 4.9307,
|
|
31
|
+
pricePerYear: "$59.99",
|
|
32
|
+
pricePerYearAmount: 59.99,
|
|
33
|
+
introOffer: { price: "$0.99", priceAmount: 0.99, period: "month", periodCount: 1, cycles: 1 },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe("productVariables", () => {
|
|
37
|
+
it("emits flat dotted keys the interpolator can resolve", () => {
|
|
38
|
+
const v = productVariables({ products: { yearly }, status: "ready", purchasing: false });
|
|
39
|
+
expect(v["product.yearly.price"].value).toBe("$59.99");
|
|
40
|
+
expect(v["product.yearly.pricePerWeek"].value).toBe("$1.15");
|
|
41
|
+
expect(v["product.yearly.savingsPct"].value).toBe("51");
|
|
42
|
+
expect(v["product.yearly.trialDays"].value).toBe("7");
|
|
43
|
+
expect(v["product.yearly.title"].value).toBe("Yearly Plan");
|
|
44
|
+
expect(v["product.yearly.period"].value).toBe("year");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("stringifies every value — the variable bag is string-based", () => {
|
|
48
|
+
const v = productVariables({ products: { yearly }, status: "ready", purchasing: false });
|
|
49
|
+
for (const entry of Object.values(v)) {
|
|
50
|
+
expect(typeof entry.value).toBe("string");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("emits the complete set of dotted keys for a fully-populated product", () => {
|
|
55
|
+
const v = productVariables({ products: { complete }, status: "ready", purchasing: false });
|
|
56
|
+
expect(Object.keys(v).sort()).toEqual(
|
|
57
|
+
[
|
|
58
|
+
"product.complete.productId",
|
|
59
|
+
"product.complete.title",
|
|
60
|
+
"product.complete.description",
|
|
61
|
+
"product.complete.price",
|
|
62
|
+
"product.complete.priceAmount",
|
|
63
|
+
"product.complete.currencyCode",
|
|
64
|
+
"product.complete.period",
|
|
65
|
+
"product.complete.periodCount",
|
|
66
|
+
"product.complete.pricePerWeek",
|
|
67
|
+
"product.complete.pricePerWeekAmount",
|
|
68
|
+
"product.complete.pricePerMonth",
|
|
69
|
+
"product.complete.pricePerMonthAmount",
|
|
70
|
+
"product.complete.pricePerYear",
|
|
71
|
+
"product.complete.pricePerYearAmount",
|
|
72
|
+
"product.complete.savingsPct",
|
|
73
|
+
"product.complete.trialDays",
|
|
74
|
+
"product.complete.introPrice",
|
|
75
|
+
"products.loaded",
|
|
76
|
+
"products.purchasing",
|
|
77
|
+
"products.error",
|
|
78
|
+
].sort()
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("omits absent optional fields rather than emitting empty strings", () => {
|
|
83
|
+
const bare = { ...yearly, savingsPct: undefined, trialDays: undefined };
|
|
84
|
+
const v = productVariables({ products: { yearly: bare }, status: "ready", purchasing: false });
|
|
85
|
+
expect(v["product.yearly.savingsPct"]).toBeUndefined();
|
|
86
|
+
expect(v["product.yearly.trialDays"]).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("publishes status flags authors gate the CTA on", () => {
|
|
90
|
+
const ready = productVariables({ products: {}, status: "ready", purchasing: false });
|
|
91
|
+
expect(ready["products.loaded"].value).toBe("true");
|
|
92
|
+
expect(ready["products.purchasing"].value).toBe("false");
|
|
93
|
+
expect(ready["products.error"].value).toBe("");
|
|
94
|
+
|
|
95
|
+
const failed = productVariables({
|
|
96
|
+
products: {},
|
|
97
|
+
status: "error",
|
|
98
|
+
error: "network down",
|
|
99
|
+
purchasing: false,
|
|
100
|
+
});
|
|
101
|
+
expect(failed["products.loaded"].value).toBe("false");
|
|
102
|
+
expect(failed["products.error"].value).toBe("network down");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("reports loaded=false while still loading", () => {
|
|
106
|
+
const v = productVariables({ products: {}, status: "loading", purchasing: false });
|
|
107
|
+
expect(v["products.loaded"].value).toBe("false");
|
|
108
|
+
});
|
|
109
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { extractAssetUrls } from "../preload/extractAssetUrls";
|
|
|
10
10
|
import { preloadAssets } from "../preload/preloadAssets";
|
|
11
11
|
import { OnboardingNavigationAdapter } from "../navigation/types";
|
|
12
12
|
import { expoRouterAdapter } from "../navigation/expoRouterAdapter";
|
|
13
|
+
import { useProducts } from "../../products/useProducts";
|
|
14
|
+
import { ProductProvider, ProductRef, ProductRuntime } from "../../products/types";
|
|
13
15
|
|
|
14
16
|
const queryClient = new QueryClient({
|
|
15
17
|
defaultOptions: {
|
|
@@ -19,6 +21,17 @@ const queryClient = new QueryClient({
|
|
|
19
21
|
},
|
|
20
22
|
})
|
|
21
23
|
|
|
24
|
+
// Module-scope so the context default is referentially stable — an inline
|
|
25
|
+
// object literal here would allocate a fresh value on every read of the
|
|
26
|
+
// default, defeating the same stability contract useProducts upholds.
|
|
27
|
+
const EMPTY_PRODUCT_RUNTIME: ProductRuntime = {
|
|
28
|
+
products: {},
|
|
29
|
+
status: "idle",
|
|
30
|
+
purchasing: false,
|
|
31
|
+
purchase: async () => ({ status: "error", error: new Error("No ProductProvider") }),
|
|
32
|
+
restore: async () => ({ status: "error", error: new Error("No ProductProvider") }),
|
|
33
|
+
};
|
|
34
|
+
|
|
22
35
|
export type CustomActionHandler = (args: {
|
|
23
36
|
variables: Record<string, ComposableVariableEntry | undefined>;
|
|
24
37
|
/**
|
|
@@ -81,6 +94,15 @@ interface OnboardingProviderProps {
|
|
|
81
94
|
* logic (mark onboarding done, navigate to paywall/home, etc.). Optional.
|
|
82
95
|
*/
|
|
83
96
|
onComplete?: OnboardingCompleteHandler;
|
|
97
|
+
/**
|
|
98
|
+
* Billing adapter. Omit for an app with no paywall. Must be a stable reference.
|
|
99
|
+
*/
|
|
100
|
+
productProvider?: ProductProvider;
|
|
101
|
+
/**
|
|
102
|
+
* Product slots to resolve at mount, e.g.
|
|
103
|
+
* `[{ key: "yearly", ios: "com.app.yr", android: "com.app.yr:p1y", compareTo: "monthly" }]`.
|
|
104
|
+
*/
|
|
105
|
+
productRefs?: ProductRef[];
|
|
84
106
|
}
|
|
85
107
|
|
|
86
108
|
interface OnboardingDataGateProps {
|
|
@@ -135,6 +157,8 @@ export const OnboardingProvider = ({
|
|
|
135
157
|
fontsFallback,
|
|
136
158
|
navigation = expoRouterAdapter,
|
|
137
159
|
onComplete,
|
|
160
|
+
productProvider,
|
|
161
|
+
productRefs,
|
|
138
162
|
}: OnboardingProviderProps) => {
|
|
139
163
|
const [activeStep, setActiveStep] = useState({
|
|
140
164
|
number: 0,
|
|
@@ -177,6 +201,8 @@ export const OnboardingProvider = ({
|
|
|
177
201
|
});
|
|
178
202
|
}, [onComplete, onboarding]);
|
|
179
203
|
|
|
204
|
+
const productRuntime = useProducts(productRefs, productProvider, locale);
|
|
205
|
+
|
|
180
206
|
return (
|
|
181
207
|
<QueryClientProvider client={queryClient}>
|
|
182
208
|
<OnboardingProgressContext.Provider
|
|
@@ -198,6 +224,7 @@ export const OnboardingProvider = ({
|
|
|
198
224
|
completeOnboarding,
|
|
199
225
|
customActions,
|
|
200
226
|
navigation,
|
|
227
|
+
products: productRuntime,
|
|
201
228
|
}}
|
|
202
229
|
>
|
|
203
230
|
<OnboardingDataGate
|
|
@@ -232,6 +259,7 @@ export const OnboardingProgressContext = createContext<{
|
|
|
232
259
|
completeOnboarding: () => void;
|
|
233
260
|
customActions: CustomActions;
|
|
234
261
|
navigation: OnboardingNavigationAdapter;
|
|
262
|
+
products: ProductRuntime;
|
|
235
263
|
}>({
|
|
236
264
|
activeStep: { number: 0, displayProgressHeader: false },
|
|
237
265
|
setActiveStep: () => { },
|
|
@@ -250,4 +278,5 @@ export const OnboardingProgressContext = createContext<{
|
|
|
250
278
|
completeOnboarding: () => { },
|
|
251
279
|
customActions: {},
|
|
252
280
|
navigation: expoRouterAdapter,
|
|
281
|
+
products: EMPTY_PRODUCT_RUNTIME,
|
|
253
282
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
import type { ProductProvider, ProductRef, ProductPeriod, ResolvedProduct } from "../types";
|
|
3
|
+
|
|
4
|
+
// Optional peer: expo-iap. Same dynamic-require pattern as elements/haptics.ts.
|
|
5
|
+
let IAP: any;
|
|
6
|
+
try {
|
|
7
|
+
IAP = require("expo-iap");
|
|
8
|
+
} catch {
|
|
9
|
+
IAP = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const toPeriod = (iso: string | null | undefined): { period: ProductPeriod | null; count: number } => {
|
|
13
|
+
if (!iso) return { period: null, count: 0 };
|
|
14
|
+
const m = /^P(\d+)([DWMY])$/.exec(iso);
|
|
15
|
+
if (!m) return { period: null, count: 0 };
|
|
16
|
+
const map: Record<string, ProductPeriod> = { D: "week", W: "week", M: "month", Y: "year" };
|
|
17
|
+
return { period: map[m[2]] ?? null, count: Number(m[1]) };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// expo-iap surfaces a user cancellation as a code rather than a typed error.
|
|
21
|
+
const isCancellation = (e: any): boolean =>
|
|
22
|
+
e?.code === "E_USER_CANCELLED" || e?.code === "USER_CANCELED" || e?.userCancelled === true;
|
|
23
|
+
|
|
24
|
+
const idFor = (ref: ProductRef): string | undefined =>
|
|
25
|
+
Platform.OS === "ios" ? ref.ios : ref.android;
|
|
26
|
+
|
|
27
|
+
/** Direct StoreKit / Play Billing provider, no vendor in the path. */
|
|
28
|
+
export const expoIapProductProvider = (Iap: any = IAP): ProductProvider => {
|
|
29
|
+
const required = () => {
|
|
30
|
+
if (!Iap) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"expoIapProductProvider: expo-iap is not installed. Install it, or pass a different ProductProvider."
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return Iap;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
async getProducts(refs: ProductRef[]): Promise<ResolvedProduct[]> {
|
|
40
|
+
const M = required();
|
|
41
|
+
const wanted = refs.map((r) => ({ ref: r, id: idFor(r) })).filter((x) => !!x.id);
|
|
42
|
+
if (wanted.length === 0) return [];
|
|
43
|
+
const skus = wanted.map((w) => w.id as string);
|
|
44
|
+
const store = await M.getProducts(skus);
|
|
45
|
+
const byId = new Map<string, any>(store.map((s: any) => [s.id ?? s.productId, s]));
|
|
46
|
+
const out: ResolvedProduct[] = [];
|
|
47
|
+
for (const { ref, id } of wanted) {
|
|
48
|
+
const s = byId.get(id as string);
|
|
49
|
+
if (!s) continue;
|
|
50
|
+
const iso = s.subscriptionPeriodISO ?? s.subscriptionPeriod ?? null;
|
|
51
|
+
const { period, count } = toPeriod(iso);
|
|
52
|
+
out.push({
|
|
53
|
+
key: ref.key,
|
|
54
|
+
productId: s.id ?? s.productId,
|
|
55
|
+
store: Platform.OS === "ios" ? "app_store" : "play_store",
|
|
56
|
+
title: s.title ?? "",
|
|
57
|
+
description: s.description ?? "",
|
|
58
|
+
price: s.displayPrice ?? s.localizedPrice ?? "",
|
|
59
|
+
priceAmount: Number(s.price ?? 0),
|
|
60
|
+
currencyCode: s.currency ?? s.currencyCode ?? "",
|
|
61
|
+
period,
|
|
62
|
+
periodCount: count,
|
|
63
|
+
periodIso: iso,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
async purchase(product) {
|
|
70
|
+
const M = required();
|
|
71
|
+
try {
|
|
72
|
+
await M.requestPurchase({ request: { sku: product.productId } });
|
|
73
|
+
return { status: "purchased", productKey: product.key };
|
|
74
|
+
} catch (e: any) {
|
|
75
|
+
if (isCancellation(e)) return { status: "cancelled" };
|
|
76
|
+
return { status: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
async restore() {
|
|
81
|
+
const M = required();
|
|
82
|
+
try {
|
|
83
|
+
const purchases = await M.getAvailablePurchases();
|
|
84
|
+
const ids: string[] = (purchases ?? []).map((p: any) => p.id ?? p.productId).filter(Boolean);
|
|
85
|
+
return ids.length > 0
|
|
86
|
+
? { status: "restored", entitlements: ids }
|
|
87
|
+
: { status: "nothing_to_restore" };
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return { status: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
import type { ProductProvider, ProductRef, ProductPeriod, ResolvedProduct } from "../types";
|
|
3
|
+
|
|
4
|
+
// Optional peer: react-native-purchases. Same dynamic-require pattern as
|
|
5
|
+
// elements/haptics.ts — absent is not a crash, it is a clear error at call time.
|
|
6
|
+
let RC: any;
|
|
7
|
+
try {
|
|
8
|
+
RC = require("react-native-purchases");
|
|
9
|
+
} catch {
|
|
10
|
+
RC = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const PERIOD_UNIT: Record<string, ProductPeriod> = {
|
|
14
|
+
DAY: "week", WEEK: "week", MONTH: "month", YEAR: "year",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const toPeriod = (iso: string | null | undefined): { period: ProductPeriod | null; count: number } => {
|
|
18
|
+
if (!iso) return { period: null, count: 0 };
|
|
19
|
+
const m = /^P(\d+)([DWMY])$/.exec(iso);
|
|
20
|
+
if (!m) return { period: null, count: 0 };
|
|
21
|
+
const unit = { D: "DAY", W: "WEEK", M: "MONTH", Y: "YEAR" }[m[2]]!;
|
|
22
|
+
return { period: PERIOD_UNIT[unit] ?? null, count: Number(m[1]) };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const idFor = (ref: ProductRef): string | undefined =>
|
|
26
|
+
Platform.OS === "ios" ? ref.ios : ref.android;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* RevenueCat-backed provider. Pass the `Purchases` module explicitly if you have
|
|
30
|
+
* a custom instance; otherwise the installed one is used.
|
|
31
|
+
*/
|
|
32
|
+
export const revenueCatProductProvider = (Purchases: any = RC?.default ?? RC): ProductProvider => {
|
|
33
|
+
const required = () => {
|
|
34
|
+
if (!Purchases) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"revenueCatProductProvider: react-native-purchases is not installed. Install it, or pass a different ProductProvider."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return Purchases;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
async getProducts(refs: ProductRef[]): Promise<ResolvedProduct[]> {
|
|
44
|
+
const P = required();
|
|
45
|
+
const wanted = refs.map((r) => ({ ref: r, id: idFor(r) })).filter((x) => !!x.id);
|
|
46
|
+
if (wanted.length === 0) return [];
|
|
47
|
+
const store = await P.getProducts(wanted.map((w) => w.id as string));
|
|
48
|
+
const byId = new Map<string, any>(store.map((s: any) => [s.identifier, s]));
|
|
49
|
+
const out: ResolvedProduct[] = [];
|
|
50
|
+
for (const { ref, id } of wanted) {
|
|
51
|
+
const s = byId.get(id as string);
|
|
52
|
+
if (!s) continue;
|
|
53
|
+
const { period, count } = toPeriod(s.subscriptionPeriod);
|
|
54
|
+
out.push({
|
|
55
|
+
key: ref.key,
|
|
56
|
+
productId: s.identifier,
|
|
57
|
+
store: Platform.OS === "ios" ? "app_store" : "play_store",
|
|
58
|
+
title: s.title ?? "",
|
|
59
|
+
description: s.description ?? "",
|
|
60
|
+
price: s.priceString,
|
|
61
|
+
priceAmount: s.price,
|
|
62
|
+
currencyCode: s.currencyCode,
|
|
63
|
+
period,
|
|
64
|
+
periodCount: count,
|
|
65
|
+
periodIso: s.subscriptionPeriod ?? null,
|
|
66
|
+
trial: s.introPrice && s.introPrice.price === 0
|
|
67
|
+
? {
|
|
68
|
+
period: toPeriod(s.introPrice.periodISO).period ?? "week",
|
|
69
|
+
periodCount: toPeriod(s.introPrice.periodISO).count,
|
|
70
|
+
days: 0,
|
|
71
|
+
}
|
|
72
|
+
: undefined,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
async purchase(product) {
|
|
79
|
+
const P = required();
|
|
80
|
+
try {
|
|
81
|
+
const store = await P.getProducts([product.productId]);
|
|
82
|
+
if (!store[0]) return { status: "error", error: new Error(`Unknown product ${product.productId}`) };
|
|
83
|
+
const res = await P.purchaseStoreProduct(store[0]);
|
|
84
|
+
return {
|
|
85
|
+
status: "purchased",
|
|
86
|
+
productKey: product.key,
|
|
87
|
+
entitlements: Object.keys(res?.customerInfo?.entitlements?.active ?? {}),
|
|
88
|
+
};
|
|
89
|
+
} catch (e: any) {
|
|
90
|
+
if (e?.userCancelled) return { status: "cancelled" };
|
|
91
|
+
return { status: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
async restore() {
|
|
96
|
+
const P = required();
|
|
97
|
+
try {
|
|
98
|
+
const info = await P.restorePurchases();
|
|
99
|
+
const ents = Object.keys(info?.entitlements?.active ?? {});
|
|
100
|
+
return ents.length > 0
|
|
101
|
+
? { status: "restored", entitlements: ents }
|
|
102
|
+
: { status: "nothing_to_restore" };
|
|
103
|
+
} catch (e) {
|
|
104
|
+
return { status: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
};
|