@codual/react-native-ui 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +18 -2
- package/dist/announce.d.ts +2 -0
- package/dist/announce.js +8 -0
- package/dist/charts/data.d.ts +32 -0
- package/dist/charts/data.js +13 -0
- package/dist/charts/labels.d.ts +54 -0
- package/dist/charts/labels.js +91 -0
- package/dist/charts/machine.d.ts +62 -0
- package/dist/charts/machine.js +144 -0
- package/dist/charts/points.d.ts +23 -0
- package/dist/charts/points.js +46 -0
- package/dist/charts/summary.d.ts +29 -0
- package/dist/charts/summary.js +45 -0
- package/dist/charts/use-chart-interaction.d.ts +62 -0
- package/dist/charts/use-chart-interaction.js +79 -0
- package/dist/forms/async-checks.d.ts +34 -0
- package/dist/forms/async-checks.js +77 -0
- package/dist/forms/field-errors.d.ts +8 -0
- package/dist/forms/field-errors.js +16 -0
- package/dist/forms/form-types.d.ts +43 -0
- package/dist/forms/form-types.js +2 -0
- package/dist/forms/machine.d.ts +63 -0
- package/dist/forms/machine.js +251 -0
- package/dist/forms/numbers.d.ts +5 -0
- package/dist/forms/numbers.js +83 -0
- package/dist/forms/rules.d.ts +47 -0
- package/dist/forms/rules.js +72 -0
- package/dist/forms/server-errors.d.ts +17 -0
- package/dist/forms/server-errors.js +22 -0
- package/dist/forms/use-form.d.ts +49 -0
- package/dist/forms/use-form.js +61 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +94 -0
- package/dist/lists/PagedList.d.ts +47 -0
- package/dist/lists/PagedList.js +81 -0
- package/dist/lists/controller.d.ts +23 -0
- package/dist/lists/controller.js +20 -0
- package/dist/lists/inverted-list.d.ts +23 -0
- package/dist/lists/inverted-list.js +60 -0
- package/dist/lists/machine.d.ts +81 -0
- package/dist/lists/machine.js +252 -0
- package/dist/lists/newest-end.d.ts +30 -0
- package/dist/lists/newest-end.js +58 -0
- package/dist/lists/paged-content.d.ts +46 -0
- package/dist/lists/paged-content.js +65 -0
- package/dist/lists/paged-list-types.d.ts +56 -0
- package/dist/lists/paged-list-types.js +2 -0
- package/dist/lists/system-footer.d.ts +28 -0
- package/dist/lists/system-footer.js +50 -0
- package/dist/lists/use-paged-list.d.ts +25 -0
- package/dist/lists/use-paged-list.js +34 -0
- package/dist/permissions/access.d.ts +30 -0
- package/dist/permissions/access.js +2 -0
- package/dist/permissions/android-permission.d.ts +52 -0
- package/dist/permissions/android-permission.js +143 -0
- package/dist/permissions/permission.d.ts +69 -0
- package/dist/permissions/permission.js +201 -0
- package/dist/permissions/setup.d.ts +25 -0
- package/dist/permissions/setup.js +41 -0
- package/dist/permissions/status.d.ts +29 -0
- package/dist/permissions/status.js +18 -0
- package/dist/permissions/use-permission.d.ts +23 -0
- package/dist/permissions/use-permission.js +29 -0
- package/dist/purchases/Paywall.d.ts +27 -0
- package/dist/purchases/Paywall.js +28 -0
- package/dist/purchases/paywall-content.d.ts +20 -0
- package/dist/purchases/paywall-content.js +34 -0
- package/dist/purchases/purchases.d.ts +92 -0
- package/dist/purchases/purchases.js +236 -0
- package/dist/purchases/status.d.ts +62 -0
- package/dist/purchases/status.js +25 -0
- package/dist/purchases/store.d.ts +71 -0
- package/dist/purchases/store.js +2 -0
- package/dist/purchases/system-views.d.ts +49 -0
- package/dist/purchases/system-views.js +91 -0
- package/dist/purchases/use-purchases.d.ts +3 -0
- package/dist/purchases/use-purchases.js +8 -0
- package/dist/react-native-iap/iap-purchases.d.ts +24 -0
- package/dist/react-native-iap/iap-purchases.js +90 -0
- package/dist/react-native-iap/iap-store.d.ts +56 -0
- package/dist/react-native-iap/iap-store.js +249 -0
- package/dist/react-native-iap/iap-types.d.ts +12 -0
- package/dist/react-native-iap/iap-types.js +11 -0
- package/dist/react-native-iap/index.d.ts +31 -0
- package/dist/react-native-iap/index.js +24 -0
- package/dist/react-native-permissions/index.d.ts +24 -0
- package/dist/react-native-permissions/index.js +88 -0
- package/dist/screen-states/ScreenStates.d.ts +38 -0
- package/dist/screen-states/ScreenStates.js +69 -0
- package/dist/screen-states/errors.d.ts +9 -0
- package/dist/screen-states/errors.js +24 -0
- package/dist/screen-states/machine.d.ts +97 -0
- package/dist/screen-states/machine.js +172 -0
- package/dist/screen-states/system-views.d.ts +40 -0
- package/dist/screen-states/system-views.js +66 -0
- package/dist/screen-states/use-screen-states.d.ts +23 -0
- package/dist/screen-states/use-screen-states.js +41 -0
- package/dist/search/SearchResults.d.ts +22 -0
- package/dist/search/SearchResults.js +25 -0
- package/dist/search/announcements.d.ts +17 -0
- package/dist/search/announcements.js +31 -0
- package/dist/search/labels.d.ts +15 -0
- package/dist/search/labels.js +14 -0
- package/dist/search/machine.d.ts +65 -0
- package/dist/search/machine.js +241 -0
- package/dist/search/recent-search-sync.d.ts +32 -0
- package/dist/search/recent-search-sync.js +87 -0
- package/dist/search/recent-searches.d.ts +22 -0
- package/dist/search/recent-searches.js +40 -0
- package/dist/search/system-views.d.ts +11 -0
- package/dist/search/system-views.js +16 -0
- package/dist/search/types.d.ts +51 -0
- package/dist/search/types.js +2 -0
- package/dist/search/use-search.d.ts +73 -0
- package/dist/search/use-search.js +123 -0
- package/dist/selection/config.d.ts +34 -0
- package/dist/selection/config.js +13 -0
- package/dist/selection/labels.d.ts +19 -0
- package/dist/selection/labels.js +23 -0
- package/dist/selection/machine.d.ts +80 -0
- package/dist/selection/machine.js +274 -0
- package/dist/selection/snapshot.d.ts +54 -0
- package/dist/selection/snapshot.js +45 -0
- package/dist/selection/state.d.ts +25 -0
- package/dist/selection/state.js +24 -0
- package/dist/selection/system-views.d.ts +11 -0
- package/dist/selection/system-views.js +22 -0
- package/dist/selection/use-selection.d.ts +73 -0
- package/dist/selection/use-selection.js +100 -0
- package/dist/sheets/machine.d.ts +101 -0
- package/dist/sheets/machine.js +213 -0
- package/dist/sheets/use-sheet.d.ts +78 -0
- package/dist/sheets/use-sheet.js +103 -0
- package/dist/victory-native/index.d.ts +37 -0
- package/dist/victory-native/index.js +41 -0
- package/package.json +94 -4
- package/react-native-iap/package.json +4 -0
- package/react-native-permissions/package.json +4 -0
- package/victory-native/package.json +4 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PaywallContent } from "./paywall-content";
|
|
2
|
+
import { type PurchaseMessage } from "./status";
|
|
3
|
+
import type { StoreProduct } from "./store";
|
|
4
|
+
/** The text of the paywall's system parts. Pass `labels` to translate it. */
|
|
5
|
+
export interface PaywallLabels {
|
|
6
|
+
readonly buy: string;
|
|
7
|
+
readonly buyFor: (price: string) => string;
|
|
8
|
+
/** What a screen reader says for the buy button. */
|
|
9
|
+
readonly buyProduct: (name: string, price: string) => string;
|
|
10
|
+
readonly purchasing: string;
|
|
11
|
+
readonly purchased: string;
|
|
12
|
+
readonly restore: string;
|
|
13
|
+
readonly restoring: string;
|
|
14
|
+
readonly pending: string;
|
|
15
|
+
readonly pendingMessage: string;
|
|
16
|
+
readonly failed: string;
|
|
17
|
+
readonly failedMessage: string;
|
|
18
|
+
readonly offlineMessage: string;
|
|
19
|
+
readonly restored: string;
|
|
20
|
+
readonly nothingToRestore: string;
|
|
21
|
+
readonly nothingToRestoreMessage: string;
|
|
22
|
+
readonly restoreFailed: string;
|
|
23
|
+
readonly ok: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const defaultPaywallLabels: PaywallLabels;
|
|
26
|
+
/** A product as a selectable row: its name, description and store price. */
|
|
27
|
+
export declare function SystemProductRow(props: {
|
|
28
|
+
readonly product: StoreProduct;
|
|
29
|
+
readonly paywall: PaywallContent;
|
|
30
|
+
}): import("react").JSX.Element;
|
|
31
|
+
/** Buys the selected product, labeled with its price; disabled while busy, with nothing selected, or when owned. */
|
|
32
|
+
export declare function SystemBuyButton(props: {
|
|
33
|
+
readonly paywall: PaywallContent;
|
|
34
|
+
readonly labels?: Partial<PaywallLabels>;
|
|
35
|
+
}): import("react").JSX.Element;
|
|
36
|
+
/** Restores purchases; disabled while a purchase or restore runs. */
|
|
37
|
+
export declare function SystemRestoreButton(props: {
|
|
38
|
+
readonly paywall: PaywallContent;
|
|
39
|
+
readonly labels?: Partial<PaywallLabels>;
|
|
40
|
+
}): import("react").JSX.Element;
|
|
41
|
+
/**
|
|
42
|
+
* Shows a purchase message as a system alert, once per message even when React runs the effect twice (Strict
|
|
43
|
+
* Mode), and dismisses it when the alert closes. Renders nothing.
|
|
44
|
+
*/
|
|
45
|
+
export declare function SystemPurchaseMessageAlert(props: {
|
|
46
|
+
readonly message: PurchaseMessage;
|
|
47
|
+
readonly dismiss: () => void;
|
|
48
|
+
readonly labels: PaywallLabels;
|
|
49
|
+
}): null;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultPaywallLabels = void 0;
|
|
4
|
+
exports.SystemProductRow = SystemProductRow;
|
|
5
|
+
exports.SystemBuyButton = SystemBuyButton;
|
|
6
|
+
exports.SystemRestoreButton = SystemRestoreButton;
|
|
7
|
+
exports.SystemPurchaseMessageAlert = SystemPurchaseMessageAlert;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const react_native_1 = require("react-native");
|
|
11
|
+
const system_views_1 = require("../screen-states/system-views");
|
|
12
|
+
const status_1 = require("./status");
|
|
13
|
+
exports.defaultPaywallLabels = {
|
|
14
|
+
buy: "Buy",
|
|
15
|
+
buyFor: (price) => `Buy for ${price}`,
|
|
16
|
+
buyProduct: (name, price) => `Buy ${name}, ${price}`,
|
|
17
|
+
purchasing: "Purchasing",
|
|
18
|
+
purchased: "Purchased",
|
|
19
|
+
restore: "Restore Purchases",
|
|
20
|
+
restoring: "Restoring",
|
|
21
|
+
pending: "Waiting for Approval",
|
|
22
|
+
pendingMessage: "Your purchase will finish once it's approved.",
|
|
23
|
+
failed: "Purchase Failed",
|
|
24
|
+
failedMessage: system_views_1.defaultScreenStatesLabels.failedMessage,
|
|
25
|
+
offlineMessage: system_views_1.defaultScreenStatesLabels.offlineMessage,
|
|
26
|
+
restored: "Purchases Restored",
|
|
27
|
+
nothingToRestore: "Nothing to Restore",
|
|
28
|
+
nothingToRestoreMessage: "There are no purchases to restore for this account.",
|
|
29
|
+
restoreFailed: "Couldn't Restore",
|
|
30
|
+
ok: system_views_1.defaultScreenStatesLabels.ok,
|
|
31
|
+
};
|
|
32
|
+
// System components only, with no styles of their own.
|
|
33
|
+
/** A product as a selectable row: its name, description and store price. */
|
|
34
|
+
function SystemProductRow(props) {
|
|
35
|
+
const { product, paywall } = props;
|
|
36
|
+
const isSelected = paywall.isSelected(product);
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "radio", accessibilityState: { checked: isSelected, selected: isSelected }, accessibilityLabel: `${product.displayName}, ${product.description}, ${product.displayPrice}`, onPress: () => paywall.select(product), children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { children: product.displayName }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { children: product.description }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { children: product.displayPrice })] }) }));
|
|
38
|
+
}
|
|
39
|
+
/** Buys the selected product, labeled with its price; disabled while busy, with nothing selected, or when owned. */
|
|
40
|
+
function SystemBuyButton(props) {
|
|
41
|
+
const labels = { ...exports.defaultPaywallLabels, ...props.labels };
|
|
42
|
+
const state = props.paywall.buyButton;
|
|
43
|
+
switch (state.status) {
|
|
44
|
+
case "ready": {
|
|
45
|
+
const { displayName, displayPrice } = state.product;
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Button, { title: labels.buyFor(displayPrice), accessibilityLabel: labels.buyProduct(displayName, displayPrice), onPress: props.paywall.buy }));
|
|
47
|
+
}
|
|
48
|
+
case "purchasing":
|
|
49
|
+
return (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: labels.purchasing, disabled: true, onPress: props.paywall.buy });
|
|
50
|
+
case "owned":
|
|
51
|
+
return (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: labels.purchased, disabled: true, onPress: props.paywall.buy });
|
|
52
|
+
case "unavailable":
|
|
53
|
+
return (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: labels.buy, disabled: true, onPress: props.paywall.buy });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Restores purchases; disabled while a purchase or restore runs. */
|
|
57
|
+
function SystemRestoreButton(props) {
|
|
58
|
+
const labels = { ...exports.defaultPaywallLabels, ...props.labels };
|
|
59
|
+
const { status } = props.paywall;
|
|
60
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Button, { title: status.status === "restoring" ? labels.restoring : labels.restore, disabled: (0, status_1.isBusy)(status), onPress: props.paywall.restore }));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Shows a purchase message as a system alert, once per message even when React runs the effect twice (Strict
|
|
64
|
+
* Mode), and dismisses it when the alert closes. Renders nothing.
|
|
65
|
+
*/
|
|
66
|
+
function SystemPurchaseMessageAlert(props) {
|
|
67
|
+
const { message, dismiss, labels } = props;
|
|
68
|
+
const alerted = (0, react_1.useRef)(undefined);
|
|
69
|
+
(0, react_1.useEffect)(() => {
|
|
70
|
+
if (alerted.current === message)
|
|
71
|
+
return;
|
|
72
|
+
alerted.current = message;
|
|
73
|
+
const [title, detail] = messageText(message, labels);
|
|
74
|
+
react_native_1.Alert.alert(title, detail, [{ text: labels.ok, onPress: dismiss }], { onDismiss: dismiss });
|
|
75
|
+
}, [message, dismiss, labels]);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
function messageText(message, labels) {
|
|
79
|
+
switch (message.status) {
|
|
80
|
+
case "pending":
|
|
81
|
+
return [labels.pending, labels.pendingMessage];
|
|
82
|
+
case "failed":
|
|
83
|
+
return [labels.failed, (0, system_views_1.failureMessage)(message.error, labels)];
|
|
84
|
+
case "restored":
|
|
85
|
+
return [labels.restored, undefined];
|
|
86
|
+
case "nothing-to-restore":
|
|
87
|
+
return [labels.nothingToRestore, labels.nothingToRestoreMessage];
|
|
88
|
+
case "restore-failed":
|
|
89
|
+
return [labels.restoreFailed, (0, system_views_1.failureMessage)(message.error, labels)];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePurchases = usePurchases;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/** The status and entitlements of `purchases`, re-rendering the component when either changes. */
|
|
6
|
+
function usePurchases(purchases) {
|
|
7
|
+
return (0, react_1.useSyncExternalStore)(purchases.subscribe, purchases.getSnapshot);
|
|
8
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Purchase } from "react-native-iap" with { "resolution-mode": "import" };
|
|
2
|
+
import type { Entitlement, StoreProduct } from "../purchases/store";
|
|
3
|
+
import type { ReactNativeIap } from "./iap-types";
|
|
4
|
+
export declare const USER_CANCELLED = "user-cancelled";
|
|
5
|
+
export declare const ALREADY_OWNED = "already-owned";
|
|
6
|
+
export declare const DEFERRED_PAYMENT = "deferred-payment";
|
|
7
|
+
export declare const PENDING = "pending";
|
|
8
|
+
/** The purchase's token, the proof a server verifies, or undefined when the library gave none. */
|
|
9
|
+
export declare function proofOf(purchase: Purchase): string | undefined;
|
|
10
|
+
export declare function isRevoked(purchase: Purchase): boolean;
|
|
11
|
+
export declare function isSuspended(purchase: Purchase): boolean;
|
|
12
|
+
export declare function isAcknowledged(purchase: Purchase): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Per product, the entitlement of the latest owned purchase still in force: unexpired, or in its grace period. The
|
|
15
|
+
* App Store's "active only" list leaves out one in its billing grace period, so the store reads every transaction.
|
|
16
|
+
*/
|
|
17
|
+
export declare function entitlementsOf(owned: readonly Purchase[], now: number): readonly Entitlement[];
|
|
18
|
+
export type PurchaseRequest = Parameters<ReactNativeIap["requestPurchase"]>[0];
|
|
19
|
+
/**
|
|
20
|
+
* The request for the product: a one-time purchase, or a subscription through its Google Play offer, switching the
|
|
21
|
+
* purchase it replaces, if any.
|
|
22
|
+
*/
|
|
23
|
+
export declare function purchaseRequest(product: StoreProduct, offerToken: string | undefined, replacing: Purchase | undefined): PurchaseRequest;
|
|
24
|
+
export declare function errorCode(error: unknown): unknown;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PENDING = exports.DEFERRED_PAYMENT = exports.ALREADY_OWNED = exports.USER_CANCELLED = void 0;
|
|
4
|
+
exports.proofOf = proofOf;
|
|
5
|
+
exports.isRevoked = isRevoked;
|
|
6
|
+
exports.isSuspended = isSuspended;
|
|
7
|
+
exports.isAcknowledged = isAcknowledged;
|
|
8
|
+
exports.entitlementsOf = entitlementsOf;
|
|
9
|
+
exports.purchaseRequest = purchaseRequest;
|
|
10
|
+
exports.errorCode = errorCode;
|
|
11
|
+
// react-native-iap's error codes, as strings so this module needs nothing of the library at runtime.
|
|
12
|
+
exports.USER_CANCELLED = "user-cancelled";
|
|
13
|
+
exports.ALREADY_OWNED = "already-owned";
|
|
14
|
+
exports.DEFERRED_PAYMENT = "deferred-payment";
|
|
15
|
+
exports.PENDING = "pending";
|
|
16
|
+
/** How the App Store names a product shared through Family Sharing (StoreKit's `familyShared`). */
|
|
17
|
+
const FAMILY_SHARED = /^family[-_]?shared$/i;
|
|
18
|
+
/** The purchase's token, the proof a server verifies, or undefined when the library gave none. */
|
|
19
|
+
function proofOf(purchase) {
|
|
20
|
+
const token = purchase.purchaseToken;
|
|
21
|
+
return token == null || token === "" ? undefined : token;
|
|
22
|
+
}
|
|
23
|
+
function isRevoked(purchase) {
|
|
24
|
+
return "revocationDateIOS" in purchase && purchase.revocationDateIOS != null;
|
|
25
|
+
}
|
|
26
|
+
function isSuspended(purchase) {
|
|
27
|
+
return "isSuspendedAndroid" in purchase && purchase.isSuspendedAndroid === true;
|
|
28
|
+
}
|
|
29
|
+
function isAcknowledged(purchase) {
|
|
30
|
+
return "isAcknowledgedAndroid" in purchase && purchase.isAcknowledgedAndroid === true;
|
|
31
|
+
}
|
|
32
|
+
/** The purchase as an entitlement; a subscription in its billing grace period lasts until the grace period ends. */
|
|
33
|
+
function entitlement(purchase) {
|
|
34
|
+
const expiration = "expirationDateIOS" in purchase ? purchase.expirationDateIOS : undefined;
|
|
35
|
+
const grace = "renewalInfoIOS" in purchase ? purchase.renewalInfoIOS?.gracePeriodExpirationDate : undefined;
|
|
36
|
+
const expiresAt = expiration == null ? undefined : Math.max(expiration, grace ?? 0);
|
|
37
|
+
const firstPurchase = "originalTransactionDateIOS" in purchase ? purchase.originalTransactionDateIOS : undefined;
|
|
38
|
+
const purchasedAt = firstPurchase ?? (purchase.transactionDate > 0 ? purchase.transactionDate : undefined);
|
|
39
|
+
const ownership = "ownershipTypeIOS" in purchase ? purchase.ownershipTypeIOS : undefined;
|
|
40
|
+
return {
|
|
41
|
+
productId: purchase.productId,
|
|
42
|
+
...(expiresAt == null ? {} : { expiresAt }),
|
|
43
|
+
...(purchasedAt == null ? {} : { purchasedAt }),
|
|
44
|
+
...(ownership == null ? {} : { isFamilyShared: FAMILY_SHARED.test(ownership) }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Per product, the entitlement of the latest owned purchase still in force: unexpired, or in its grace period. The
|
|
49
|
+
* App Store's "active only" list leaves out one in its billing grace period, so the store reads every transaction.
|
|
50
|
+
*/
|
|
51
|
+
function entitlementsOf(owned, now) {
|
|
52
|
+
const latest = new Map();
|
|
53
|
+
for (const purchase of owned) {
|
|
54
|
+
const candidate = entitlement(purchase);
|
|
55
|
+
if (candidate.expiresAt !== undefined && candidate.expiresAt <= now)
|
|
56
|
+
continue;
|
|
57
|
+
const kept = latest.get(candidate.productId);
|
|
58
|
+
if (kept === undefined || (candidate.expiresAt ?? Infinity) > (kept.expiresAt ?? Infinity)) {
|
|
59
|
+
latest.set(candidate.productId, candidate);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return [...latest.values()];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The request for the product: a one-time purchase, or a subscription through its Google Play offer, switching the
|
|
66
|
+
* purchase it replaces, if any.
|
|
67
|
+
*/
|
|
68
|
+
function purchaseRequest(product, offerToken, replacing) {
|
|
69
|
+
const sku = product.id;
|
|
70
|
+
if (product.kind !== "subscription") {
|
|
71
|
+
return { type: "in-app", request: { apple: { sku }, google: { skus: [sku] } } };
|
|
72
|
+
}
|
|
73
|
+
const subscriptionOffers = offerToken === undefined ? [] : [{ sku, offerToken }];
|
|
74
|
+
const replacement = replacing === undefined
|
|
75
|
+
? {}
|
|
76
|
+
: {
|
|
77
|
+
purchaseToken: replacing.purchaseToken ?? null,
|
|
78
|
+
subscriptionProductReplacementParams: {
|
|
79
|
+
oldProductId: replacing.productId,
|
|
80
|
+
replacementMode: "with-time-proration",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
type: "subs",
|
|
85
|
+
request: { apple: { sku }, google: { skus: [sku], subscriptionOffers, ...replacement } },
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function errorCode(error) {
|
|
89
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
|
|
90
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Entitlement, StoreProduct, StorePurchaseResult, StoreSyncResult, StoreTransaction, StoreUpdate } from "../purchases/store";
|
|
2
|
+
import { type ReactNativeIap, type ReactNativeIapStore } from "./iap-types";
|
|
3
|
+
/** The App Store and Google Play through react-native-iap, for `createReactNativeIapStore`. */
|
|
4
|
+
export declare class IapStore implements ReactNativeIapStore {
|
|
5
|
+
private readonly iap;
|
|
6
|
+
private readonly consumables;
|
|
7
|
+
private readonly replacedSubscription;
|
|
8
|
+
private connection;
|
|
9
|
+
private flow;
|
|
10
|
+
private readonly loaded;
|
|
11
|
+
/** The library's own purchases, by transaction ID, until they are finished. */
|
|
12
|
+
private readonly purchases;
|
|
13
|
+
private readonly listeners;
|
|
14
|
+
private readonly subscriptions;
|
|
15
|
+
constructor(iap: ReactNativeIap, consumables: ReadonlySet<string>, replacedSubscription: (product: StoreProduct) => string | undefined);
|
|
16
|
+
readonly dispose: () => void;
|
|
17
|
+
products(ids: readonly string[]): Promise<readonly StoreProduct[]>;
|
|
18
|
+
purchase(product: StoreProduct): Promise<StorePurchaseResult>;
|
|
19
|
+
subscribe(listener: (update: StoreUpdate) => void): () => void;
|
|
20
|
+
unfinishedTransactions(): Promise<readonly StoreTransaction[]>;
|
|
21
|
+
currentEntitlements(): Promise<readonly Entitlement[]>;
|
|
22
|
+
finish(transaction: StoreTransaction): Promise<void>;
|
|
23
|
+
sync(): Promise<StoreSyncResult>;
|
|
24
|
+
/** The store sheet's answer goes to the purchase waiting for it; anything else came from outside the flow. */
|
|
25
|
+
private purchaseUpdated;
|
|
26
|
+
/**
|
|
27
|
+
* Sends a purchase from outside the flow once its product is known, so a consumable is described as one. If the
|
|
28
|
+
* product can't be loaded now, the purchase stays unfinished and the next refresh finds it.
|
|
29
|
+
*/
|
|
30
|
+
private sendDescribed;
|
|
31
|
+
/** Loads the products of these purchases that no paywall has loaded yet: their type says what each one is. */
|
|
32
|
+
private loadProductsOf;
|
|
33
|
+
private send;
|
|
34
|
+
/** An error with no purchase waiting for it has no one to tell; the next check of entitlements is still right. */
|
|
35
|
+
private purchaseFailed;
|
|
36
|
+
/** A purchase made elsewhere that this device hadn't seen: the purchase the store has for it. */
|
|
37
|
+
private alreadyOwned;
|
|
38
|
+
/** A purchase the store gave no proof for can't be verified or finished, so it fails the purchase. */
|
|
39
|
+
private resolveWith;
|
|
40
|
+
/** The user's Google Play purchase of the subscription the app says this one replaces, if they have it. */
|
|
41
|
+
private replacedPurchase;
|
|
42
|
+
/** Google Play sells a subscription through an offer: its base plan's, or its first. */
|
|
43
|
+
private basePlanOfferToken;
|
|
44
|
+
/** Connects once; a connection that fails or answers false is tried again by the next call. */
|
|
45
|
+
private connect;
|
|
46
|
+
private productKind;
|
|
47
|
+
private isConsumable;
|
|
48
|
+
/** Purchased and in force; one with no token has no proof to verify, so it owns nothing either. */
|
|
49
|
+
private isOwned;
|
|
50
|
+
private needsFinishing;
|
|
51
|
+
/**
|
|
52
|
+
* Keeps the library's purchase until it is finished, and describes it for `Purchases`. Throws for a purchase with
|
|
53
|
+
* no token: with no proof, nothing could verify it.
|
|
54
|
+
*/
|
|
55
|
+
private transaction;
|
|
56
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IapStore = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const iap_purchases_1 = require("./iap-purchases");
|
|
6
|
+
const iap_types_1 = require("./iap-types");
|
|
7
|
+
/** The App Store and Google Play through react-native-iap, for `createReactNativeIapStore`. */
|
|
8
|
+
class IapStore {
|
|
9
|
+
iap;
|
|
10
|
+
consumables;
|
|
11
|
+
replacedSubscription;
|
|
12
|
+
connection;
|
|
13
|
+
flow;
|
|
14
|
+
loaded = new Map();
|
|
15
|
+
/** The library's own purchases, by transaction ID, until they are finished. */
|
|
16
|
+
purchases = new Map();
|
|
17
|
+
listeners = new Set();
|
|
18
|
+
subscriptions;
|
|
19
|
+
constructor(iap, consumables, replacedSubscription) {
|
|
20
|
+
this.iap = iap;
|
|
21
|
+
this.consumables = consumables;
|
|
22
|
+
this.replacedSubscription = replacedSubscription;
|
|
23
|
+
this.subscriptions = [
|
|
24
|
+
iap.purchaseUpdatedListener((purchase) => this.purchaseUpdated(purchase)),
|
|
25
|
+
iap.purchaseErrorListener((error) => this.purchaseFailed(error)),
|
|
26
|
+
// Google Play tells the app nothing of refunds, so each return to the foreground checks again.
|
|
27
|
+
react_native_1.AppState.addEventListener("change", (state) => {
|
|
28
|
+
if (state === "active")
|
|
29
|
+
this.send({ type: "entitlements-may-have-changed" });
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
dispose = () => {
|
|
34
|
+
for (const subscription of this.subscriptions)
|
|
35
|
+
subscription.remove();
|
|
36
|
+
this.listeners.clear();
|
|
37
|
+
};
|
|
38
|
+
async products(ids) {
|
|
39
|
+
await this.connect();
|
|
40
|
+
const products = (await this.iap.fetchProducts({ skus: [...ids], type: "all" })) ?? [];
|
|
41
|
+
for (const product of products)
|
|
42
|
+
this.loaded.set(product.id, product);
|
|
43
|
+
return products.map((product) => ({
|
|
44
|
+
id: product.id,
|
|
45
|
+
displayName: product.displayName ?? product.title,
|
|
46
|
+
description: product.description,
|
|
47
|
+
displayPrice: product.displayPrice,
|
|
48
|
+
kind: this.productKind(product),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
async purchase(product) {
|
|
52
|
+
await this.connect();
|
|
53
|
+
const answer = new Promise((resolve, reject) => {
|
|
54
|
+
this.flow = { productId: product.id, resolve, reject };
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
const replacing = product.kind === "subscription" ? await this.replacedPurchase(product) : undefined;
|
|
58
|
+
await this.iap.requestPurchase((0, iap_purchases_1.purchaseRequest)(product, this.basePlanOfferToken(product.id), replacing));
|
|
59
|
+
return await answer;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
this.flow = undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
subscribe(listener) {
|
|
66
|
+
this.listeners.add(listener);
|
|
67
|
+
return () => this.listeners.delete(listener);
|
|
68
|
+
}
|
|
69
|
+
async unfinishedTransactions() {
|
|
70
|
+
await this.connect();
|
|
71
|
+
const unfinished = react_native_1.Platform.OS === "ios"
|
|
72
|
+
? await this.iap.getPendingTransactionsIOS()
|
|
73
|
+
: (await this.iap.getAvailablePurchases()).filter((purchase) => this.needsFinishing(purchase));
|
|
74
|
+
const purchased = unfinished.filter((purchase) => purchase.purchaseState === "purchased");
|
|
75
|
+
await this.loadProductsOf(purchased);
|
|
76
|
+
return purchased.map((purchase) => this.transaction(purchase));
|
|
77
|
+
}
|
|
78
|
+
async currentEntitlements() {
|
|
79
|
+
await this.connect();
|
|
80
|
+
const purchases = await this.iap.getAvailablePurchases({ onlyIncludeActiveItemsIOS: false });
|
|
81
|
+
return (0, iap_purchases_1.entitlementsOf)(purchases.filter((purchase) => this.isOwned(purchase)), Date.now());
|
|
82
|
+
}
|
|
83
|
+
async finish(transaction) {
|
|
84
|
+
const purchase = this.purchases.get(transaction.id);
|
|
85
|
+
if (purchase === undefined)
|
|
86
|
+
return;
|
|
87
|
+
await this.iap.finishTransaction({ purchase, isConsumable: transaction.kind === "consumable" });
|
|
88
|
+
this.purchases.delete(transaction.id);
|
|
89
|
+
}
|
|
90
|
+
async sync() {
|
|
91
|
+
await this.connect();
|
|
92
|
+
try {
|
|
93
|
+
await this.iap.restorePurchases();
|
|
94
|
+
return "synced";
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if ((0, iap_purchases_1.errorCode)(error) === iap_purchases_1.USER_CANCELLED)
|
|
98
|
+
return "cancelled";
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** The store sheet's answer goes to the purchase waiting for it; anything else came from outside the flow. */
|
|
103
|
+
purchaseUpdated(purchase) {
|
|
104
|
+
const flow = this.flow;
|
|
105
|
+
if (flow !== undefined && flow.productId === purchase.productId) {
|
|
106
|
+
if (purchase.purchaseState === "pending")
|
|
107
|
+
flow.resolve({ status: "pending" });
|
|
108
|
+
else
|
|
109
|
+
this.resolveWith(flow, purchase);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (purchase.purchaseState === "purchased")
|
|
113
|
+
void this.sendDescribed(purchase);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Sends a purchase from outside the flow once its product is known, so a consumable is described as one. If the
|
|
117
|
+
* product can't be loaded now, the purchase stays unfinished and the next refresh finds it.
|
|
118
|
+
*/
|
|
119
|
+
async sendDescribed(purchase) {
|
|
120
|
+
let transaction;
|
|
121
|
+
try {
|
|
122
|
+
await this.loadProductsOf([purchase]);
|
|
123
|
+
transaction = this.transaction(purchase);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.send({ type: "transaction", transaction });
|
|
129
|
+
}
|
|
130
|
+
/** Loads the products of these purchases that no paywall has loaded yet: their type says what each one is. */
|
|
131
|
+
async loadProductsOf(purchases) {
|
|
132
|
+
const missing = [...new Set(purchases.map((purchase) => purchase.productId))].filter((id) => !this.loaded.has(id));
|
|
133
|
+
if (missing.length === 0)
|
|
134
|
+
return;
|
|
135
|
+
await this.products(missing);
|
|
136
|
+
}
|
|
137
|
+
send(update) {
|
|
138
|
+
for (const listener of this.listeners)
|
|
139
|
+
listener(update);
|
|
140
|
+
}
|
|
141
|
+
/** An error with no purchase waiting for it has no one to tell; the next check of entitlements is still right. */
|
|
142
|
+
purchaseFailed(error) {
|
|
143
|
+
const flow = this.flow;
|
|
144
|
+
if (flow === undefined)
|
|
145
|
+
return;
|
|
146
|
+
const code = error.code;
|
|
147
|
+
switch (code) {
|
|
148
|
+
case iap_purchases_1.USER_CANCELLED:
|
|
149
|
+
flow.resolve({ status: "cancelled" });
|
|
150
|
+
break;
|
|
151
|
+
case iap_purchases_1.DEFERRED_PAYMENT:
|
|
152
|
+
case iap_purchases_1.PENDING:
|
|
153
|
+
flow.resolve({ status: "pending" });
|
|
154
|
+
break;
|
|
155
|
+
case iap_purchases_1.ALREADY_OWNED:
|
|
156
|
+
void this.alreadyOwned(flow, error);
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
flow.reject(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** A purchase made elsewhere that this device hadn't seen: the purchase the store has for it. */
|
|
163
|
+
async alreadyOwned(flow, error) {
|
|
164
|
+
const purchases = await this.iap.getAvailablePurchases().catch(() => []);
|
|
165
|
+
const owned = purchases.find((purchase) => purchase.productId === flow.productId && this.isOwned(purchase));
|
|
166
|
+
if (owned === undefined)
|
|
167
|
+
flow.reject(error);
|
|
168
|
+
else
|
|
169
|
+
this.resolveWith(flow, owned);
|
|
170
|
+
}
|
|
171
|
+
/** A purchase the store gave no proof for can't be verified or finished, so it fails the purchase. */
|
|
172
|
+
resolveWith(flow, purchase) {
|
|
173
|
+
try {
|
|
174
|
+
flow.resolve({ status: "purchased", transaction: this.transaction(purchase) });
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
flow.reject(error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** The user's Google Play purchase of the subscription the app says this one replaces, if they have it. */
|
|
181
|
+
async replacedPurchase(product) {
|
|
182
|
+
if (react_native_1.Platform.OS !== "android")
|
|
183
|
+
return undefined;
|
|
184
|
+
const replaced = this.replacedSubscription(product);
|
|
185
|
+
if (replaced === undefined)
|
|
186
|
+
return undefined;
|
|
187
|
+
const purchases = await this.iap.getAvailablePurchases();
|
|
188
|
+
return purchases.find((purchase) => purchase.productId === replaced && this.isOwned(purchase));
|
|
189
|
+
}
|
|
190
|
+
/** Google Play sells a subscription through an offer: its base plan's, or its first. */
|
|
191
|
+
basePlanOfferToken(sku) {
|
|
192
|
+
const offers = this.loaded.get(sku)?.subscriptionOffers ?? [];
|
|
193
|
+
const basePlan = offers.find((offer) => offer.id === offer.basePlanIdAndroid) ?? offers[0];
|
|
194
|
+
return basePlan?.offerTokenAndroid ?? undefined;
|
|
195
|
+
}
|
|
196
|
+
/** Connects once; a connection that fails or answers false is tried again by the next call. */
|
|
197
|
+
connect() {
|
|
198
|
+
this.connection ??= this.iap
|
|
199
|
+
.initConnection()
|
|
200
|
+
.then((isConnected) => {
|
|
201
|
+
if (!isConnected)
|
|
202
|
+
throw new iap_types_1.ReactNativeIapConnectionError();
|
|
203
|
+
})
|
|
204
|
+
.catch((error) => {
|
|
205
|
+
this.connection = undefined;
|
|
206
|
+
throw error;
|
|
207
|
+
});
|
|
208
|
+
return this.connection;
|
|
209
|
+
}
|
|
210
|
+
productKind(product) {
|
|
211
|
+
if (product.type === "subs")
|
|
212
|
+
return "subscription";
|
|
213
|
+
if (this.consumables.has(product.id))
|
|
214
|
+
return "consumable";
|
|
215
|
+
return product.platform === "ios" && product.typeIOS === "consumable" ? "consumable" : "non-consumable";
|
|
216
|
+
}
|
|
217
|
+
isConsumable(productId) {
|
|
218
|
+
const product = this.loaded.get(productId);
|
|
219
|
+
return (this.consumables.has(productId) || (product !== undefined && this.productKind(product) === "consumable"));
|
|
220
|
+
}
|
|
221
|
+
/** Purchased and in force; one with no token has no proof to verify, so it owns nothing either. */
|
|
222
|
+
isOwned(purchase) {
|
|
223
|
+
if (purchase.purchaseState !== "purchased" || this.isConsumable(purchase.productId))
|
|
224
|
+
return false;
|
|
225
|
+
return (0, iap_purchases_1.proofOf)(purchase) !== undefined && !(0, iap_purchases_1.isSuspended)(purchase) && !(0, iap_purchases_1.isRevoked)(purchase);
|
|
226
|
+
}
|
|
227
|
+
needsFinishing(purchase) {
|
|
228
|
+
return !(0, iap_purchases_1.isAcknowledged)(purchase) || this.isConsumable(purchase.productId);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Keeps the library's purchase until it is finished, and describes it for `Purchases`. Throws for a purchase with
|
|
232
|
+
* no token: with no proof, nothing could verify it.
|
|
233
|
+
*/
|
|
234
|
+
transaction(purchase) {
|
|
235
|
+
const proof = (0, iap_purchases_1.proofOf)(purchase);
|
|
236
|
+
if (proof === undefined)
|
|
237
|
+
throw new Error(`react-native-iap gave no purchase token for ${purchase.productId}`);
|
|
238
|
+
const id = purchase.store === "apple" ? purchase.id : proof;
|
|
239
|
+
this.purchases.set(id, purchase);
|
|
240
|
+
const product = this.loaded.get(purchase.productId);
|
|
241
|
+
const kind = this.isConsumable(purchase.productId)
|
|
242
|
+
? "consumable"
|
|
243
|
+
: product?.type === "subs" || purchase.isAutoRenewing
|
|
244
|
+
? "subscription"
|
|
245
|
+
: "non-consumable";
|
|
246
|
+
return { id, productId: purchase.productId, kind, proof, isRevoked: (0, iap_purchases_1.isRevoked)(purchase) };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.IapStore = IapStore;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as ReactNativeIapModule from "react-native-iap" with { "resolution-mode": "import" };
|
|
2
|
+
import type { PurchaseStore } from "../purchases/store";
|
|
3
|
+
/** The parts of react-native-iap the store uses: pass `import * as iap from "react-native-iap"`. */
|
|
4
|
+
export type ReactNativeIap = Pick<typeof ReactNativeIapModule, "initConnection" | "fetchProducts" | "requestPurchase" | "purchaseUpdatedListener" | "purchaseErrorListener" | "getAvailablePurchases" | "getPendingTransactionsIOS" | "finishTransaction" | "restorePurchases">;
|
|
5
|
+
/** A react-native-iap store; `dispose` stops it listening to the library and to the app's state. */
|
|
6
|
+
export interface ReactNativeIapStore extends PurchaseStore {
|
|
7
|
+
readonly dispose: () => void;
|
|
8
|
+
}
|
|
9
|
+
/** react-native-iap's `initConnection` answering false: the store can't be reached on this device now. */
|
|
10
|
+
export declare class ReactNativeIapConnectionError extends Error {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactNativeIapConnectionError = void 0;
|
|
4
|
+
/** react-native-iap's `initConnection` answering false: the store can't be reached on this device now. */
|
|
5
|
+
class ReactNativeIapConnectionError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super("react-native-iap couldn't connect to the store");
|
|
8
|
+
this.name = "ReactNativeIapConnectionError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ReactNativeIapConnectionError = ReactNativeIapConnectionError;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StoreProduct } from "../purchases/store";
|
|
2
|
+
import type { ReactNativeIap, ReactNativeIapStore } from "./iap-types";
|
|
3
|
+
export { type ReactNativeIap, ReactNativeIapConnectionError, type ReactNativeIapStore } from "./iap-types";
|
|
4
|
+
export interface ReactNativeIapStoreOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The products bought again and again (a tip, coins). The App Store knows its consumables; Google Play doesn't, so
|
|
7
|
+
* list them here to have them consumed instead of acknowledged.
|
|
8
|
+
*/
|
|
9
|
+
readonly consumableProductIds?: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* For a subscription about to be bought on Google Play, the ID of the user's subscription it replaces (an upgrade,
|
|
12
|
+
* a downgrade, another period), so Google Play switches it, with time proration. The App Store switches
|
|
13
|
+
* subscriptions in one group by itself.
|
|
14
|
+
*/
|
|
15
|
+
readonly replacedSubscription?: (product: StoreProduct) => string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The App Store and Google Play through react-native-iap (an optional peer dependency): call it once when the app
|
|
19
|
+
* starts, and give the store to `createPurchases`. It checks entitlements again each time the app returns to the
|
|
20
|
+
* foreground, since Google Play tells the app nothing about refunds.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import * as iap from "react-native-iap";
|
|
24
|
+
* import { createReactNativeIapStore } from "@codual/react-native-ui/react-native-iap";
|
|
25
|
+
* const purchases = createPurchases(createReactNativeIapStore(iap, { consumableProductIds: ["tip"] }));
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Create one store for the app; a second one (after Fast Refresh, say) needs the first one's `dispose`, or both hear
|
|
29
|
+
* every purchase.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createReactNativeIapStore(iap: ReactNativeIap, options?: ReactNativeIapStoreOptions): ReactNativeIapStore;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactNativeIapConnectionError = void 0;
|
|
4
|
+
exports.createReactNativeIapStore = createReactNativeIapStore;
|
|
5
|
+
const iap_store_1 = require("./iap-store");
|
|
6
|
+
var iap_types_1 = require("./iap-types");
|
|
7
|
+
Object.defineProperty(exports, "ReactNativeIapConnectionError", { enumerable: true, get: function () { return iap_types_1.ReactNativeIapConnectionError; } });
|
|
8
|
+
/**
|
|
9
|
+
* The App Store and Google Play through react-native-iap (an optional peer dependency): call it once when the app
|
|
10
|
+
* starts, and give the store to `createPurchases`. It checks entitlements again each time the app returns to the
|
|
11
|
+
* foreground, since Google Play tells the app nothing about refunds.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import * as iap from "react-native-iap";
|
|
15
|
+
* import { createReactNativeIapStore } from "@codual/react-native-ui/react-native-iap";
|
|
16
|
+
* const purchases = createPurchases(createReactNativeIapStore(iap, { consumableProductIds: ["tip"] }));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Create one store for the app; a second one (after Fast Refresh, say) needs the first one's `dispose`, or both hear
|
|
20
|
+
* every purchase.
|
|
21
|
+
*/
|
|
22
|
+
function createReactNativeIapStore(iap, options = {}) {
|
|
23
|
+
return new iap_store_1.IapStore(iap, new Set(options.consumableProductIds), options.replacedSubscription ?? (() => undefined));
|
|
24
|
+
}
|