@flare-engine/ui-shop 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grzegorz Otto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @flare-engine/ui-shop
2
+
3
+ Reusable React Native UI primitives for in-app-purchase flows. Consumes
4
+ `@flare-engine/iap` (`IAPContext` + `EntitlementStore` + `ProductCatalog`)
5
+ and `@flare-engine/ui` (Panel / Button / Label / Modal) for rendering.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add @flare-engine/ui-shop @flare-engine/iap @flare-engine/ui
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { IAPContext, createEntitlementStore, createProductCatalog } from '@flare-engine/iap';
17
+ import { ShopPanel, PaywallModal, RestorePurchasesButton } from '@flare-engine/ui-shop';
18
+ import type { ShopPanelStrings, PaywallStrings, RestoreStrings } from '@flare-engine/ui-shop';
19
+
20
+ const catalog = createProductCatalog([
21
+ { productId: 'game.full', grants: ['full_game'], type: 'non-consumable' },
22
+ ]);
23
+ const store = createEntitlementStore(catalog);
24
+
25
+ const shopStrings: ShopPanelStrings = {
26
+ headingKey: 'shop.heading', emptyKey: 'shop.empty',
27
+ loadingKey: 'shop.loading', errorKey: 'shop.error',
28
+ ownedSectionKey: 'shop.owned', availableSectionKey: 'shop.available',
29
+ };
30
+ const paywallStrings: PaywallStrings = {
31
+ headingKey: 'pw.heading', bodyKey: 'pw.body', ctaKey: 'pw.cta',
32
+ dismissKey: 'pw.dismiss', loadingKey: 'pw.loading', errorKey: 'pw.error',
33
+ };
34
+ const restoreStrings: RestoreStrings = {
35
+ ctaKey: 'restore.cta', loadingKey: 'restore.loading',
36
+ successKey: 'restore.success', emptyKey: 'restore.empty', errorKey: 'restore.error',
37
+ };
38
+
39
+ // Wrap with IAPContext.Provider supplying a concrete adapter (e.g. createRevenueCatProvider)
40
+ <IAPContext.Provider value={provider}>
41
+ <ShopPanel
42
+ catalog={catalog}
43
+ entitlementStore={store}
44
+ copy={{ 'game.full': { titleKey: 'p.full.title', descriptionKey: 'p.full.desc', ctaKey: 'p.full.cta', ownedLabelKey: 'p.full.owned' } }}
45
+ strings={shopStrings}
46
+ localize={(key) => t(key)}
47
+ onPurchase={(id, result) => console.log(id, result.status)}
48
+ />
49
+
50
+ <PaywallModal
51
+ visible={paywallOpen}
52
+ productId="game.full"
53
+ entitlementKey="full_game"
54
+ entitlementStore={store}
55
+ strings={paywallStrings}
56
+ localize={(key) => t(key)}
57
+ onDismiss={() => setPaywallOpen(false)}
58
+ onPurchased={(result) => console.log('purchased', result)}
59
+ />
60
+
61
+ <RestorePurchasesButton
62
+ entitlementStore={store}
63
+ strings={restoreStrings}
64
+ localize={(key) => t(key)}
65
+ onComplete={(results) => console.log('restored', results.length)}
66
+ />
67
+ </IAPContext.Provider>
68
+ ```
@@ -0,0 +1,76 @@
1
+ import { ProductCatalog, EntitlementStore, ProductId, PurchaseResult, EntitlementKey } from '@flare-engine/iap';
2
+
3
+ /** Per-product copy the host provides; never touches i18n directly. */
4
+ interface ShopItemCopy {
5
+ titleKey: string;
6
+ descriptionKey: string;
7
+ ctaKey: string;
8
+ ownedLabelKey: string;
9
+ }
10
+ interface ShopPanelStrings {
11
+ headingKey: string;
12
+ emptyKey: string;
13
+ loadingKey: string;
14
+ errorKey: string;
15
+ ownedSectionKey: string;
16
+ availableSectionKey: string;
17
+ }
18
+ interface PaywallStrings {
19
+ headingKey: string;
20
+ bodyKey: string;
21
+ ctaKey: string;
22
+ dismissKey: string;
23
+ loadingKey: string;
24
+ errorKey: string;
25
+ }
26
+ interface RestoreStrings {
27
+ ctaKey: string;
28
+ loadingKey: string;
29
+ successKey: string;
30
+ emptyKey: string;
31
+ errorKey: string;
32
+ }
33
+ /**
34
+ * Host-supplied localizer. Keeps the engine free of any i18n framework
35
+ * dependency — the caller owns the translation lookup.
36
+ */
37
+ type LocalizeFn = (key: string) => string;
38
+
39
+ interface ShopPanelProps {
40
+ readonly catalog: ProductCatalog;
41
+ readonly entitlementStore: EntitlementStore;
42
+ readonly copy: Record<ProductId, ShopItemCopy>;
43
+ readonly strings: ShopPanelStrings;
44
+ readonly localize: LocalizeFn;
45
+ readonly onPurchase?: (productId: ProductId, result: PurchaseResult) => void;
46
+ readonly onError?: (error: Error) => void;
47
+ }
48
+ declare function ShopPanel({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError, }: ShopPanelProps): React.ReactNode;
49
+
50
+ interface PaywallModalProps {
51
+ readonly visible: boolean;
52
+ readonly productId: ProductId;
53
+ readonly entitlementKey: EntitlementKey;
54
+ readonly entitlementStore: EntitlementStore;
55
+ readonly strings: PaywallStrings;
56
+ readonly localize: LocalizeFn;
57
+ readonly onDismiss: () => void;
58
+ readonly onPurchased?: (result: PurchaseResult) => void;
59
+ readonly onError?: (error: Error) => void;
60
+ }
61
+ /**
62
+ * Parent owns visibility — the paywall never hides itself except on successful
63
+ * purchase. This keeps routing logic in the caller and avoids double-close races.
64
+ */
65
+ declare function PaywallModal({ visible, productId, entitlementKey, entitlementStore, strings, localize, onDismiss, onPurchased, onError, }: PaywallModalProps): React.ReactNode;
66
+
67
+ interface RestorePurchasesButtonProps {
68
+ readonly entitlementStore: EntitlementStore;
69
+ readonly strings: RestoreStrings;
70
+ readonly localize: LocalizeFn;
71
+ readonly onComplete?: (results: readonly PurchaseResult[]) => void;
72
+ readonly onError?: (error: Error) => void;
73
+ }
74
+ declare function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError, }: RestorePurchasesButtonProps): React.ReactNode;
75
+
76
+ export { type LocalizeFn, PaywallModal, type PaywallModalProps, type PaywallStrings, RestorePurchasesButton, type RestorePurchasesButtonProps, type RestoreStrings, type ShopItemCopy, ShopPanel, type ShopPanelProps, type ShopPanelStrings };
@@ -0,0 +1,76 @@
1
+ import { ProductCatalog, EntitlementStore, ProductId, PurchaseResult, EntitlementKey } from '@flare-engine/iap';
2
+
3
+ /** Per-product copy the host provides; never touches i18n directly. */
4
+ interface ShopItemCopy {
5
+ titleKey: string;
6
+ descriptionKey: string;
7
+ ctaKey: string;
8
+ ownedLabelKey: string;
9
+ }
10
+ interface ShopPanelStrings {
11
+ headingKey: string;
12
+ emptyKey: string;
13
+ loadingKey: string;
14
+ errorKey: string;
15
+ ownedSectionKey: string;
16
+ availableSectionKey: string;
17
+ }
18
+ interface PaywallStrings {
19
+ headingKey: string;
20
+ bodyKey: string;
21
+ ctaKey: string;
22
+ dismissKey: string;
23
+ loadingKey: string;
24
+ errorKey: string;
25
+ }
26
+ interface RestoreStrings {
27
+ ctaKey: string;
28
+ loadingKey: string;
29
+ successKey: string;
30
+ emptyKey: string;
31
+ errorKey: string;
32
+ }
33
+ /**
34
+ * Host-supplied localizer. Keeps the engine free of any i18n framework
35
+ * dependency — the caller owns the translation lookup.
36
+ */
37
+ type LocalizeFn = (key: string) => string;
38
+
39
+ interface ShopPanelProps {
40
+ readonly catalog: ProductCatalog;
41
+ readonly entitlementStore: EntitlementStore;
42
+ readonly copy: Record<ProductId, ShopItemCopy>;
43
+ readonly strings: ShopPanelStrings;
44
+ readonly localize: LocalizeFn;
45
+ readonly onPurchase?: (productId: ProductId, result: PurchaseResult) => void;
46
+ readonly onError?: (error: Error) => void;
47
+ }
48
+ declare function ShopPanel({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError, }: ShopPanelProps): React.ReactNode;
49
+
50
+ interface PaywallModalProps {
51
+ readonly visible: boolean;
52
+ readonly productId: ProductId;
53
+ readonly entitlementKey: EntitlementKey;
54
+ readonly entitlementStore: EntitlementStore;
55
+ readonly strings: PaywallStrings;
56
+ readonly localize: LocalizeFn;
57
+ readonly onDismiss: () => void;
58
+ readonly onPurchased?: (result: PurchaseResult) => void;
59
+ readonly onError?: (error: Error) => void;
60
+ }
61
+ /**
62
+ * Parent owns visibility — the paywall never hides itself except on successful
63
+ * purchase. This keeps routing logic in the caller and avoids double-close races.
64
+ */
65
+ declare function PaywallModal({ visible, productId, entitlementKey, entitlementStore, strings, localize, onDismiss, onPurchased, onError, }: PaywallModalProps): React.ReactNode;
66
+
67
+ interface RestorePurchasesButtonProps {
68
+ readonly entitlementStore: EntitlementStore;
69
+ readonly strings: RestoreStrings;
70
+ readonly localize: LocalizeFn;
71
+ readonly onComplete?: (results: readonly PurchaseResult[]) => void;
72
+ readonly onError?: (error: Error) => void;
73
+ }
74
+ declare function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError, }: RestorePurchasesButtonProps): React.ReactNode;
75
+
76
+ export { type LocalizeFn, PaywallModal, type PaywallModalProps, type PaywallStrings, RestorePurchasesButton, type RestorePurchasesButtonProps, type RestoreStrings, type ShopItemCopy, ShopPanel, type ShopPanelProps, type ShopPanelStrings };
package/dist/index.js ADDED
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PaywallModal: () => PaywallModal,
24
+ RestorePurchasesButton: () => RestorePurchasesButton,
25
+ ShopPanel: () => ShopPanel
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/ShopPanel.tsx
30
+ var import_iap = require("@flare-engine/iap");
31
+ var import_ui = require("@flare-engine/ui");
32
+ var import_react = require("react");
33
+ var import_react_native = require("react-native");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ function ShopPanel({
36
+ catalog,
37
+ entitlementStore,
38
+ copy,
39
+ strings,
40
+ localize,
41
+ onPurchase,
42
+ onError
43
+ }) {
44
+ const provider = (0, import_iap.useIAP)();
45
+ const [products, setProducts] = (0, import_react.useState)(null);
46
+ const [loadError, setLoadError] = (0, import_react.useState)(null);
47
+ const [inFlight, setInFlight] = (0, import_react.useState)(null);
48
+ const [entitlementTick, setEntitlementTick] = (0, import_react.useState)(0);
49
+ const fetched = (0, import_react.useRef)(false);
50
+ (0, import_react.useEffect)(() => {
51
+ if (fetched.current) return;
52
+ fetched.current = true;
53
+ const ids = catalog.entries.map((e) => e.productId);
54
+ provider.getProducts(ids).then(setProducts).catch((err) => {
55
+ const e = err instanceof Error ? err : new Error(String(err));
56
+ setLoadError(e);
57
+ onError?.(e);
58
+ });
59
+ }, [catalog, provider, onError]);
60
+ (0, import_react.useEffect)(() => {
61
+ return entitlementStore.onChange.add(() => {
62
+ setEntitlementTick((n) => n + 1);
63
+ });
64
+ }, [entitlementStore]);
65
+ void entitlementTick;
66
+ async function handlePurchase(id) {
67
+ setInFlight(id);
68
+ try {
69
+ const result = await provider.purchase(id);
70
+ if (result.status === "purchased") {
71
+ entitlementStore.grantProduct(id);
72
+ }
73
+ onPurchase?.(id, result);
74
+ } catch (err) {
75
+ const e = err instanceof Error ? err : new Error(String(err));
76
+ onError?.(e);
77
+ } finally {
78
+ setInFlight(null);
79
+ }
80
+ }
81
+ if (loadError !== null) {
82
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Panel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { tone: "danger", children: localize(strings.errorKey) }) });
83
+ }
84
+ if (products === null) {
85
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Panel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { tone: "muted", children: localize(strings.loadingKey) }) });
86
+ }
87
+ if (products.length === 0) {
88
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Panel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { tone: "muted", children: localize(strings.emptyKey) }) });
89
+ }
90
+ const owned = products.filter((p) => {
91
+ const entry = catalog.entries.find((e) => e.productId === p.id);
92
+ return entry?.grants.some((k) => entitlementStore.isEntitled(k)) ?? false;
93
+ });
94
+ const available = products.filter((p) => !owned.includes(p));
95
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Panel, { variant: "elevated", padding: "md", children: [
96
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "lg", children: localize(strings.headingKey) }),
97
+ owned.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { children: [
98
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "sm", tone: "muted", children: localize(strings.ownedSectionKey) }),
99
+ owned.map((p) => {
100
+ const itemCopy = copy[p.id];
101
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { children: [
102
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "md", children: itemCopy ? localize(itemCopy.titleKey) : p.title }),
103
+ itemCopy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "sm", tone: "muted", children: localize(itemCopy.descriptionKey) }) : null,
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
105
+ import_ui.Button,
106
+ {
107
+ label: itemCopy ? localize(itemCopy.ownedLabelKey) : localize(strings.ownedSectionKey),
108
+ variant: "ghost",
109
+ disabled: true
110
+ }
111
+ )
112
+ ] }, p.id);
113
+ })
114
+ ] }) : null,
115
+ available.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { children: [
116
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "sm", tone: "muted", children: localize(strings.availableSectionKey) }),
117
+ available.map((p) => {
118
+ const itemCopy = copy[p.id];
119
+ const purchasing = inFlight === p.id;
120
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { children: [
121
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "md", children: itemCopy ? localize(itemCopy.titleKey) : p.title }),
122
+ itemCopy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Label, { variant: "sm", tone: "muted", children: localize(itemCopy.descriptionKey) }) : null,
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ import_ui.Button,
125
+ {
126
+ label: purchasing ? localize(strings.loadingKey) : itemCopy ? localize(itemCopy.ctaKey) : p.priceDisplay,
127
+ variant: "primary",
128
+ disabled: purchasing,
129
+ onPress: () => {
130
+ void handlePurchase(p.id);
131
+ }
132
+ }
133
+ )
134
+ ] }, p.id);
135
+ })
136
+ ] }) : null
137
+ ] });
138
+ }
139
+
140
+ // src/PaywallModal.tsx
141
+ var import_iap2 = require("@flare-engine/iap");
142
+ var import_ui2 = require("@flare-engine/ui");
143
+ var import_react2 = require("react");
144
+ var import_react_native2 = require("react-native");
145
+ var import_jsx_runtime2 = require("react/jsx-runtime");
146
+ function PaywallModal({
147
+ visible,
148
+ productId,
149
+ entitlementKey,
150
+ entitlementStore,
151
+ strings,
152
+ localize,
153
+ onDismiss,
154
+ onPurchased,
155
+ onError
156
+ }) {
157
+ const provider = (0, import_iap2.useIAP)();
158
+ const [purchasing, setPurchasing] = (0, import_react2.useState)(false);
159
+ const [purchaseError, setPurchaseError] = (0, import_react2.useState)(null);
160
+ if (!visible) return null;
161
+ async function handlePurchase() {
162
+ setPurchasing(true);
163
+ setPurchaseError(null);
164
+ try {
165
+ const result = await provider.purchase(productId);
166
+ if (result.status === "purchased") {
167
+ entitlementStore.grant(entitlementKey);
168
+ onPurchased?.(result);
169
+ onDismiss();
170
+ } else if (result.status === "failed") {
171
+ const e = result.error ?? new Error("Purchase failed");
172
+ setPurchaseError(e);
173
+ onError?.(e);
174
+ }
175
+ } catch (err) {
176
+ const e = err instanceof Error ? err : new Error(String(err));
177
+ setPurchaseError(e);
178
+ onError?.(e);
179
+ } finally {
180
+ setPurchasing(false);
181
+ }
182
+ }
183
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui2.Modal, { visible, onBackdropPress: onDismiss, children: [
184
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui2.Label, { variant: "lg", children: localize(strings.headingKey) }),
185
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui2.Label, { variant: "sm", tone: "muted", children: localize(strings.bodyKey) }),
186
+ purchaseError !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui2.Label, { tone: "danger", children: localize(strings.errorKey) }) : null,
187
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { children: [
188
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
189
+ import_ui2.Button,
190
+ {
191
+ label: purchasing ? localize(strings.loadingKey) : localize(strings.ctaKey),
192
+ variant: "primary",
193
+ disabled: purchasing,
194
+ onPress: () => {
195
+ void handlePurchase();
196
+ }
197
+ }
198
+ ),
199
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
200
+ import_ui2.Button,
201
+ {
202
+ label: localize(strings.dismissKey),
203
+ variant: "ghost",
204
+ disabled: purchasing,
205
+ onPress: onDismiss
206
+ }
207
+ )
208
+ ] })
209
+ ] });
210
+ }
211
+
212
+ // src/RestorePurchasesButton.tsx
213
+ var import_iap3 = require("@flare-engine/iap");
214
+ var import_ui3 = require("@flare-engine/ui");
215
+ var import_react3 = require("react");
216
+ var import_react_native3 = require("react-native");
217
+ var import_jsx_runtime3 = require("react/jsx-runtime");
218
+ function RestorePurchasesButton({
219
+ entitlementStore,
220
+ strings,
221
+ localize,
222
+ onComplete,
223
+ onError
224
+ }) {
225
+ const provider = (0, import_iap3.useIAP)();
226
+ const [restoring, setRestoring] = (0, import_react3.useState)(false);
227
+ const [banner, setBanner] = (0, import_react3.useState)(null);
228
+ const [bannerError, setBannerError] = (0, import_react3.useState)(null);
229
+ async function handleRestore() {
230
+ setRestoring(true);
231
+ setBanner(null);
232
+ setBannerError(null);
233
+ try {
234
+ const results = await provider.restore();
235
+ let granted = 0;
236
+ for (let i = 0; i < results.length; i++) {
237
+ const r = results[i];
238
+ if (r && r.status === "purchased" && r.transaction) {
239
+ entitlementStore.grantProduct(r.transaction.productId);
240
+ granted++;
241
+ }
242
+ }
243
+ setBanner(granted > 0 ? "success" : "empty");
244
+ onComplete?.(results);
245
+ } catch (err) {
246
+ const e = err instanceof Error ? err : new Error(String(err));
247
+ setBanner("error");
248
+ setBannerError(e);
249
+ onError?.(e);
250
+ } finally {
251
+ setRestoring(false);
252
+ }
253
+ }
254
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native3.View, { children: [
255
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
256
+ import_ui3.Button,
257
+ {
258
+ label: restoring ? localize(strings.loadingKey) : localize(strings.ctaKey),
259
+ variant: "secondary",
260
+ disabled: restoring,
261
+ onPress: () => {
262
+ void handleRestore();
263
+ }
264
+ }
265
+ ),
266
+ banner === "success" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { tone: "success", children: localize(strings.successKey) }) : banner === "empty" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { tone: "muted", children: localize(strings.emptyKey) }) : banner === "error" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.Label, { tone: "danger", children: [
267
+ localize(strings.errorKey),
268
+ bannerError !== null ? `: ${bannerError.message}` : ""
269
+ ] }) : null
270
+ ] });
271
+ }
272
+ // Annotate the CommonJS export names for ESM import in node:
273
+ 0 && (module.exports = {
274
+ PaywallModal,
275
+ RestorePurchasesButton,
276
+ ShopPanel
277
+ });
278
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/ShopPanel.tsx","../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx"],"sourcesContent":["export { ShopPanel, type ShopPanelProps } from './ShopPanel.js';\nexport { PaywallModal, type PaywallModalProps } from './PaywallModal.js';\nexport {\n RestorePurchasesButton,\n type RestorePurchasesButtonProps,\n} from './RestorePurchasesButton.js';\nexport type {\n ShopItemCopy,\n ShopPanelStrings,\n PaywallStrings,\n RestoreStrings,\n LocalizeFn,\n} from './types.js';\n","import type {\n EntitlementStore,\n Product,\n ProductCatalog,\n ProductId,\n PurchaseResult,\n} from '@flare-engine/iap';\nimport { useIAP } from '@flare-engine/iap';\nimport { Button, Label, Panel } from '@flare-engine/ui';\nimport { useEffect, useRef, useState } from 'react';\nimport { View } from 'react-native';\nimport type { LocalizeFn, ShopItemCopy, ShopPanelStrings } from './types.js';\n\nexport interface ShopPanelProps {\n readonly catalog: ProductCatalog;\n readonly entitlementStore: EntitlementStore;\n readonly copy: Record<ProductId, ShopItemCopy>;\n readonly strings: ShopPanelStrings;\n readonly localize: LocalizeFn;\n readonly onPurchase?: (productId: ProductId, result: PurchaseResult) => void;\n readonly onError?: (error: Error) => void;\n}\n\nexport function ShopPanel({\n catalog,\n entitlementStore,\n copy,\n strings,\n localize,\n onPurchase,\n onError,\n}: ShopPanelProps): React.ReactNode {\n const provider = useIAP();\n const [products, setProducts] = useState<readonly Product[] | null>(null);\n const [loadError, setLoadError] = useState<Error | null>(null);\n const [inFlight, setInFlight] = useState<ProductId | null>(null);\n // Bumped on every EntitlementStore change to trigger re-render.\n const [entitlementTick, setEntitlementTick] = useState(0);\n const fetched = useRef(false);\n\n useEffect(() => {\n if (fetched.current) return;\n fetched.current = true;\n const ids = catalog.entries.map((e) => e.productId);\n provider\n .getProducts(ids)\n .then(setProducts)\n .catch((err: unknown) => {\n const e = err instanceof Error ? err : new Error(String(err));\n setLoadError(e);\n onError?.(e);\n });\n }, [catalog, provider, onError]);\n\n useEffect(() => {\n return entitlementStore.onChange.add(() => {\n setEntitlementTick((n) => n + 1);\n });\n }, [entitlementStore]);\n\n // entitlementTick read in render to keep the lint rule happy.\n void entitlementTick;\n\n async function handlePurchase(id: ProductId): Promise<void> {\n setInFlight(id);\n try {\n const result = await provider.purchase(id);\n if (result.status === 'purchased') {\n entitlementStore.grantProduct(id);\n }\n onPurchase?.(id, result);\n } catch (err: unknown) {\n const e = err instanceof Error ? err : new Error(String(err));\n onError?.(e);\n } finally {\n setInFlight(null);\n }\n }\n\n if (loadError !== null) {\n return (\n <Panel>\n <Label tone=\"danger\">{localize(strings.errorKey)}</Label>\n </Panel>\n );\n }\n\n if (products === null) {\n return (\n <Panel>\n <Label tone=\"muted\">{localize(strings.loadingKey)}</Label>\n </Panel>\n );\n }\n\n if (products.length === 0) {\n return (\n <Panel>\n <Label tone=\"muted\">{localize(strings.emptyKey)}</Label>\n </Panel>\n );\n }\n\n const owned: readonly Product[] = products.filter((p) => {\n const entry = catalog.entries.find((e) => e.productId === p.id);\n return entry?.grants.some((k) => entitlementStore.isEntitled(k)) ?? false;\n });\n const available: readonly Product[] = products.filter((p) => !owned.includes(p));\n\n return (\n <Panel variant=\"elevated\" padding=\"md\">\n <Label variant=\"lg\">{localize(strings.headingKey)}</Label>\n {owned.length > 0 ? (\n <View>\n <Label variant=\"sm\" tone=\"muted\">\n {localize(strings.ownedSectionKey)}\n </Label>\n {owned.map((p) => {\n const itemCopy = copy[p.id];\n return (\n <View key={p.id}>\n <Label variant=\"md\">{itemCopy ? localize(itemCopy.titleKey) : p.title}</Label>\n {itemCopy ? (\n <Label variant=\"sm\" tone=\"muted\">\n {localize(itemCopy.descriptionKey)}\n </Label>\n ) : null}\n <Button\n label={\n itemCopy ? localize(itemCopy.ownedLabelKey) : localize(strings.ownedSectionKey)\n }\n variant=\"ghost\"\n disabled\n />\n </View>\n );\n })}\n </View>\n ) : null}\n {available.length > 0 ? (\n <View>\n <Label variant=\"sm\" tone=\"muted\">\n {localize(strings.availableSectionKey)}\n </Label>\n {available.map((p) => {\n const itemCopy = copy[p.id];\n const purchasing = inFlight === p.id;\n return (\n <View key={p.id}>\n <Label variant=\"md\">{itemCopy ? localize(itemCopy.titleKey) : p.title}</Label>\n {itemCopy ? (\n <Label variant=\"sm\" tone=\"muted\">\n {localize(itemCopy.descriptionKey)}\n </Label>\n ) : null}\n <Button\n label={\n purchasing\n ? localize(strings.loadingKey)\n : itemCopy\n ? localize(itemCopy.ctaKey)\n : p.priceDisplay\n }\n variant=\"primary\"\n disabled={purchasing}\n onPress={() => {\n void handlePurchase(p.id);\n }}\n />\n </View>\n );\n })}\n </View>\n ) : null}\n </Panel>\n );\n}\n","import type {\n EntitlementKey,\n EntitlementStore,\n ProductId,\n PurchaseResult,\n} from '@flare-engine/iap';\nimport { useIAP } from '@flare-engine/iap';\nimport { Button, Label, Modal } from '@flare-engine/ui';\nimport { useState } from 'react';\nimport { View } from 'react-native';\nimport type { LocalizeFn, PaywallStrings } from './types.js';\n\nexport interface PaywallModalProps {\n readonly visible: boolean;\n readonly productId: ProductId;\n readonly entitlementKey: EntitlementKey;\n readonly entitlementStore: EntitlementStore;\n readonly strings: PaywallStrings;\n readonly localize: LocalizeFn;\n readonly onDismiss: () => void;\n readonly onPurchased?: (result: PurchaseResult) => void;\n readonly onError?: (error: Error) => void;\n}\n\n/**\n * Parent owns visibility — the paywall never hides itself except on successful\n * purchase. This keeps routing logic in the caller and avoids double-close races.\n */\nexport function PaywallModal({\n visible,\n productId,\n entitlementKey,\n entitlementStore,\n strings,\n localize,\n onDismiss,\n onPurchased,\n onError,\n}: PaywallModalProps): React.ReactNode {\n const provider = useIAP();\n const [purchasing, setPurchasing] = useState(false);\n const [purchaseError, setPurchaseError] = useState<Error | null>(null);\n\n if (!visible) return null;\n\n async function handlePurchase(): Promise<void> {\n setPurchasing(true);\n setPurchaseError(null);\n try {\n const result = await provider.purchase(productId);\n if (result.status === 'purchased') {\n entitlementStore.grant(entitlementKey);\n onPurchased?.(result);\n onDismiss();\n } else if (result.status === 'failed') {\n const e = result.error ?? new Error('Purchase failed');\n setPurchaseError(e);\n onError?.(e);\n }\n // 'cancelled' — stay open, no error shown\n } catch (err: unknown) {\n const e = err instanceof Error ? err : new Error(String(err));\n setPurchaseError(e);\n onError?.(e);\n } finally {\n setPurchasing(false);\n }\n }\n\n return (\n <Modal visible={visible} onBackdropPress={onDismiss}>\n <Label variant=\"lg\">{localize(strings.headingKey)}</Label>\n <Label variant=\"sm\" tone=\"muted\">\n {localize(strings.bodyKey)}\n </Label>\n {purchaseError !== null ? <Label tone=\"danger\">{localize(strings.errorKey)}</Label> : null}\n <View>\n <Button\n label={purchasing ? localize(strings.loadingKey) : localize(strings.ctaKey)}\n variant=\"primary\"\n disabled={purchasing}\n onPress={() => {\n void handlePurchase();\n }}\n />\n <Button\n label={localize(strings.dismissKey)}\n variant=\"ghost\"\n disabled={purchasing}\n onPress={onDismiss}\n />\n </View>\n </Modal>\n );\n}\n","import type { EntitlementStore, PurchaseResult } from '@flare-engine/iap';\nimport { useIAP } from '@flare-engine/iap';\nimport { Button, Label } from '@flare-engine/ui';\nimport { useState } from 'react';\nimport { View } from 'react-native';\nimport type { LocalizeFn, RestoreStrings } from './types.js';\n\ntype BannerKind = 'success' | 'empty' | 'error';\n\nexport interface RestorePurchasesButtonProps {\n readonly entitlementStore: EntitlementStore;\n readonly strings: RestoreStrings;\n readonly localize: LocalizeFn;\n readonly onComplete?: (results: readonly PurchaseResult[]) => void;\n readonly onError?: (error: Error) => void;\n}\n\nexport function RestorePurchasesButton({\n entitlementStore,\n strings,\n localize,\n onComplete,\n onError,\n}: RestorePurchasesButtonProps): React.ReactNode {\n const provider = useIAP();\n const [restoring, setRestoring] = useState(false);\n const [banner, setBanner] = useState<BannerKind | null>(null);\n const [bannerError, setBannerError] = useState<Error | null>(null);\n\n async function handleRestore(): Promise<void> {\n setRestoring(true);\n setBanner(null);\n setBannerError(null);\n try {\n const results = await provider.restore();\n let granted = 0;\n for (let i = 0; i < results.length; i++) {\n const r = results[i];\n if (r && r.status === 'purchased' && r.transaction) {\n entitlementStore.grantProduct(r.transaction.productId);\n granted++;\n }\n }\n setBanner(granted > 0 ? 'success' : 'empty');\n onComplete?.(results);\n } catch (err: unknown) {\n const e = err instanceof Error ? err : new Error(String(err));\n setBanner('error');\n setBannerError(e);\n onError?.(e);\n } finally {\n setRestoring(false);\n }\n }\n\n return (\n <View>\n <Button\n label={restoring ? localize(strings.loadingKey) : localize(strings.ctaKey)}\n variant=\"secondary\"\n disabled={restoring}\n onPress={() => {\n void handleRestore();\n }}\n />\n {banner === 'success' ? (\n <Label tone=\"success\">{localize(strings.successKey)}</Label>\n ) : banner === 'empty' ? (\n <Label tone=\"muted\">{localize(strings.emptyKey)}</Label>\n ) : banner === 'error' ? (\n <Label tone=\"danger\">\n {localize(strings.errorKey)}\n {bannerError !== null ? `: ${bannerError.message}` : ''}\n </Label>\n ) : null}\n </View>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,iBAAuB;AACvB,gBAAqC;AACrC,mBAA4C;AAC5C,0BAAqB;AAwEb;AA3DD,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoC;AAClC,QAAM,eAAW,mBAAO;AACxB,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAoC,IAAI;AACxE,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAuB,IAAI;AAC7D,QAAM,CAAC,UAAU,WAAW,QAAI,uBAA2B,IAAI;AAE/D,QAAM,CAAC,iBAAiB,kBAAkB,QAAI,uBAAS,CAAC;AACxD,QAAM,cAAU,qBAAO,KAAK;AAE5B,8BAAU,MAAM;AACd,QAAI,QAAQ,QAAS;AACrB,YAAQ,UAAU;AAClB,UAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,MAAM,EAAE,SAAS;AAClD,aACG,YAAY,GAAG,EACf,KAAK,WAAW,EAChB,MAAM,CAAC,QAAiB;AACvB,YAAM,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;AAC5D,mBAAa,CAAC;AACd,gBAAU,CAAC;AAAA,IACb,CAAC;AAAA,EACL,GAAG,CAAC,SAAS,UAAU,OAAO,CAAC;AAE/B,8BAAU,MAAM;AACd,WAAO,iBAAiB,SAAS,IAAI,MAAM;AACzC,yBAAmB,CAAC,MAAM,IAAI,CAAC;AAAA,IACjC,CAAC;AAAA,EACH,GAAG,CAAC,gBAAgB,CAA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,qBAAe,CAAC;AAChB,gBAAU,CAAC;AAAA,IACb,UAAE;AACA,mBAAa,KAAK;AAAA,IACpB;AAAA,EACF;AAEA,SACE,8CAAC,6BACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,YAAY,SAAS,QAAQ,UAAU,IAAI,SAAS,QAAQ,MAAM;AAAA,QACzE,SAAQ;AAAA,QACR,UAAU;AAAA,QACV,SAAS,MAAM;AACb,eAAK,cAAc;AAAA,QACrB;AAAA;AAAA,IACF;AAAA,IACC,WAAW,YACV,6CAAC,oBAAM,MAAK,WAAW,mBAAS,QAAQ,UAAU,GAAE,IAClD,WAAW,UACb,6CAAC,oBAAM,MAAK,SAAS,mBAAS,QAAQ,QAAQ,GAAE,IAC9C,WAAW,UACb,8CAAC,oBAAM,MAAK,UACT;AAAA,eAAS,QAAQ,QAAQ;AAAA,MACzB,gBAAgB,OAAO,KAAK,YAAY,OAAO,KAAK;AAAA,OACvD,IACE;AAAA,KACN;AAEJ;","names":["import_iap","import_ui","import_react","import_react_native","import_jsx_runtime","import_iap","import_ui","import_react","import_react_native","import_jsx_runtime"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,249 @@
1
+ // src/ShopPanel.tsx
2
+ import { useIAP } from "@flare-engine/iap";
3
+ import { Button, Label, Panel } from "@flare-engine/ui";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { View } from "react-native";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ function ShopPanel({
8
+ catalog,
9
+ entitlementStore,
10
+ copy,
11
+ strings,
12
+ localize,
13
+ onPurchase,
14
+ onError
15
+ }) {
16
+ const provider = useIAP();
17
+ const [products, setProducts] = useState(null);
18
+ const [loadError, setLoadError] = useState(null);
19
+ const [inFlight, setInFlight] = useState(null);
20
+ const [entitlementTick, setEntitlementTick] = useState(0);
21
+ const fetched = useRef(false);
22
+ useEffect(() => {
23
+ if (fetched.current) return;
24
+ fetched.current = true;
25
+ const ids = catalog.entries.map((e) => e.productId);
26
+ provider.getProducts(ids).then(setProducts).catch((err) => {
27
+ const e = err instanceof Error ? err : new Error(String(err));
28
+ setLoadError(e);
29
+ onError?.(e);
30
+ });
31
+ }, [catalog, provider, onError]);
32
+ useEffect(() => {
33
+ return entitlementStore.onChange.add(() => {
34
+ setEntitlementTick((n) => n + 1);
35
+ });
36
+ }, [entitlementStore]);
37
+ void entitlementTick;
38
+ async function handlePurchase(id) {
39
+ setInFlight(id);
40
+ try {
41
+ const result = await provider.purchase(id);
42
+ if (result.status === "purchased") {
43
+ entitlementStore.grantProduct(id);
44
+ }
45
+ onPurchase?.(id, result);
46
+ } catch (err) {
47
+ const e = err instanceof Error ? err : new Error(String(err));
48
+ onError?.(e);
49
+ } finally {
50
+ setInFlight(null);
51
+ }
52
+ }
53
+ if (loadError !== null) {
54
+ return /* @__PURE__ */ jsx(Panel, { children: /* @__PURE__ */ jsx(Label, { tone: "danger", children: localize(strings.errorKey) }) });
55
+ }
56
+ if (products === null) {
57
+ return /* @__PURE__ */ jsx(Panel, { children: /* @__PURE__ */ jsx(Label, { tone: "muted", children: localize(strings.loadingKey) }) });
58
+ }
59
+ if (products.length === 0) {
60
+ return /* @__PURE__ */ jsx(Panel, { children: /* @__PURE__ */ jsx(Label, { tone: "muted", children: localize(strings.emptyKey) }) });
61
+ }
62
+ const owned = products.filter((p) => {
63
+ const entry = catalog.entries.find((e) => e.productId === p.id);
64
+ return entry?.grants.some((k) => entitlementStore.isEntitled(k)) ?? false;
65
+ });
66
+ const available = products.filter((p) => !owned.includes(p));
67
+ return /* @__PURE__ */ jsxs(Panel, { variant: "elevated", padding: "md", children: [
68
+ /* @__PURE__ */ jsx(Label, { variant: "lg", children: localize(strings.headingKey) }),
69
+ owned.length > 0 ? /* @__PURE__ */ jsxs(View, { children: [
70
+ /* @__PURE__ */ jsx(Label, { variant: "sm", tone: "muted", children: localize(strings.ownedSectionKey) }),
71
+ owned.map((p) => {
72
+ const itemCopy = copy[p.id];
73
+ return /* @__PURE__ */ jsxs(View, { children: [
74
+ /* @__PURE__ */ jsx(Label, { variant: "md", children: itemCopy ? localize(itemCopy.titleKey) : p.title }),
75
+ itemCopy ? /* @__PURE__ */ jsx(Label, { variant: "sm", tone: "muted", children: localize(itemCopy.descriptionKey) }) : null,
76
+ /* @__PURE__ */ jsx(
77
+ Button,
78
+ {
79
+ label: itemCopy ? localize(itemCopy.ownedLabelKey) : localize(strings.ownedSectionKey),
80
+ variant: "ghost",
81
+ disabled: true
82
+ }
83
+ )
84
+ ] }, p.id);
85
+ })
86
+ ] }) : null,
87
+ available.length > 0 ? /* @__PURE__ */ jsxs(View, { children: [
88
+ /* @__PURE__ */ jsx(Label, { variant: "sm", tone: "muted", children: localize(strings.availableSectionKey) }),
89
+ available.map((p) => {
90
+ const itemCopy = copy[p.id];
91
+ const purchasing = inFlight === p.id;
92
+ return /* @__PURE__ */ jsxs(View, { children: [
93
+ /* @__PURE__ */ jsx(Label, { variant: "md", children: itemCopy ? localize(itemCopy.titleKey) : p.title }),
94
+ itemCopy ? /* @__PURE__ */ jsx(Label, { variant: "sm", tone: "muted", children: localize(itemCopy.descriptionKey) }) : null,
95
+ /* @__PURE__ */ jsx(
96
+ Button,
97
+ {
98
+ label: purchasing ? localize(strings.loadingKey) : itemCopy ? localize(itemCopy.ctaKey) : p.priceDisplay,
99
+ variant: "primary",
100
+ disabled: purchasing,
101
+ onPress: () => {
102
+ void handlePurchase(p.id);
103
+ }
104
+ }
105
+ )
106
+ ] }, p.id);
107
+ })
108
+ ] }) : null
109
+ ] });
110
+ }
111
+
112
+ // src/PaywallModal.tsx
113
+ import { useIAP as useIAP2 } from "@flare-engine/iap";
114
+ import { Button as Button2, Label as Label2, Modal } from "@flare-engine/ui";
115
+ import { useState as useState2 } from "react";
116
+ import { View as View2 } from "react-native";
117
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
118
+ function PaywallModal({
119
+ visible,
120
+ productId,
121
+ entitlementKey,
122
+ entitlementStore,
123
+ strings,
124
+ localize,
125
+ onDismiss,
126
+ onPurchased,
127
+ onError
128
+ }) {
129
+ const provider = useIAP2();
130
+ const [purchasing, setPurchasing] = useState2(false);
131
+ const [purchaseError, setPurchaseError] = useState2(null);
132
+ if (!visible) return null;
133
+ async function handlePurchase() {
134
+ setPurchasing(true);
135
+ setPurchaseError(null);
136
+ try {
137
+ const result = await provider.purchase(productId);
138
+ if (result.status === "purchased") {
139
+ entitlementStore.grant(entitlementKey);
140
+ onPurchased?.(result);
141
+ onDismiss();
142
+ } else if (result.status === "failed") {
143
+ const e = result.error ?? new Error("Purchase failed");
144
+ setPurchaseError(e);
145
+ onError?.(e);
146
+ }
147
+ } catch (err) {
148
+ const e = err instanceof Error ? err : new Error(String(err));
149
+ setPurchaseError(e);
150
+ onError?.(e);
151
+ } finally {
152
+ setPurchasing(false);
153
+ }
154
+ }
155
+ return /* @__PURE__ */ jsxs2(Modal, { visible, onBackdropPress: onDismiss, children: [
156
+ /* @__PURE__ */ jsx2(Label2, { variant: "lg", children: localize(strings.headingKey) }),
157
+ /* @__PURE__ */ jsx2(Label2, { variant: "sm", tone: "muted", children: localize(strings.bodyKey) }),
158
+ purchaseError !== null ? /* @__PURE__ */ jsx2(Label2, { tone: "danger", children: localize(strings.errorKey) }) : null,
159
+ /* @__PURE__ */ jsxs2(View2, { children: [
160
+ /* @__PURE__ */ jsx2(
161
+ Button2,
162
+ {
163
+ label: purchasing ? localize(strings.loadingKey) : localize(strings.ctaKey),
164
+ variant: "primary",
165
+ disabled: purchasing,
166
+ onPress: () => {
167
+ void handlePurchase();
168
+ }
169
+ }
170
+ ),
171
+ /* @__PURE__ */ jsx2(
172
+ Button2,
173
+ {
174
+ label: localize(strings.dismissKey),
175
+ variant: "ghost",
176
+ disabled: purchasing,
177
+ onPress: onDismiss
178
+ }
179
+ )
180
+ ] })
181
+ ] });
182
+ }
183
+
184
+ // src/RestorePurchasesButton.tsx
185
+ import { useIAP as useIAP3 } from "@flare-engine/iap";
186
+ import { Button as Button3, Label as Label3 } from "@flare-engine/ui";
187
+ import { useState as useState3 } from "react";
188
+ import { View as View3 } from "react-native";
189
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
190
+ function RestorePurchasesButton({
191
+ entitlementStore,
192
+ strings,
193
+ localize,
194
+ onComplete,
195
+ onError
196
+ }) {
197
+ const provider = useIAP3();
198
+ const [restoring, setRestoring] = useState3(false);
199
+ const [banner, setBanner] = useState3(null);
200
+ const [bannerError, setBannerError] = useState3(null);
201
+ async function handleRestore() {
202
+ setRestoring(true);
203
+ setBanner(null);
204
+ setBannerError(null);
205
+ try {
206
+ const results = await provider.restore();
207
+ let granted = 0;
208
+ for (let i = 0; i < results.length; i++) {
209
+ const r = results[i];
210
+ if (r && r.status === "purchased" && r.transaction) {
211
+ entitlementStore.grantProduct(r.transaction.productId);
212
+ granted++;
213
+ }
214
+ }
215
+ setBanner(granted > 0 ? "success" : "empty");
216
+ onComplete?.(results);
217
+ } catch (err) {
218
+ const e = err instanceof Error ? err : new Error(String(err));
219
+ setBanner("error");
220
+ setBannerError(e);
221
+ onError?.(e);
222
+ } finally {
223
+ setRestoring(false);
224
+ }
225
+ }
226
+ return /* @__PURE__ */ jsxs3(View3, { children: [
227
+ /* @__PURE__ */ jsx3(
228
+ Button3,
229
+ {
230
+ label: restoring ? localize(strings.loadingKey) : localize(strings.ctaKey),
231
+ variant: "secondary",
232
+ disabled: restoring,
233
+ onPress: () => {
234
+ void handleRestore();
235
+ }
236
+ }
237
+ ),
238
+ banner === "success" ? /* @__PURE__ */ jsx3(Label3, { tone: "success", children: localize(strings.successKey) }) : banner === "empty" ? /* @__PURE__ */ jsx3(Label3, { tone: "muted", children: localize(strings.emptyKey) }) : banner === "error" ? /* @__PURE__ */ jsxs3(Label3, { tone: "danger", children: [
239
+ localize(strings.errorKey),
240
+ bannerError !== null ? `: ${bannerError.message}` : ""
241
+ ] }) : null
242
+ ] });
243
+ }
244
+ export {
245
+ PaywallModal,
246
+ RestorePurchasesButton,
247
+ ShopPanel
248
+ };
249
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ShopPanel.tsx","../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx"],"sourcesContent":["import type {\n EntitlementStore,\n Product,\n ProductCatalog,\n ProductId,\n PurchaseResult,\n} from '@flare-engine/iap';\nimport { useIAP } from '@flare-engine/iap';\nimport { Button, Label, Panel } from '@flare-engine/ui';\nimport { useEffect, useRef, useState } from 'react';\nimport { View } from 'react-native';\nimport type { LocalizeFn, ShopItemCopy, ShopPanelStrings } from './types.js';\n\nexport interface ShopPanelProps {\n readonly catalog: ProductCatalog;\n readonly entitlementStore: EntitlementStore;\n readonly copy: Record<ProductId, ShopItemCopy>;\n readonly strings: ShopPanelStrings;\n readonly localize: LocalizeFn;\n readonly onPurchase?: (productId: ProductId, result: PurchaseResult) => void;\n readonly onError?: (error: Error) => void;\n}\n\nexport function ShopPanel({\n catalog,\n entitlementStore,\n copy,\n strings,\n localize,\n onPurchase,\n onError,\n}: ShopPanelProps): React.ReactNode {\n const provider = useIAP();\n const [products, setProducts] = useState<readonly Product[] | null>(null);\n const [loadError, setLoadError] = useState<Error | null>(null);\n const [inFlight, setInFlight] = useState<ProductId | null>(null);\n // Bumped on every EntitlementStore change to trigger re-render.\n const [entitlementTick, setEntitlementTick] = useState(0);\n const fetched = useRef(false);\n\n useEffect(() => {\n if (fetched.current) return;\n fetched.current = true;\n const ids = catalog.entries.map((e) => e.productId);\n provider\n .getProducts(ids)\n .then(setProducts)\n .catch((err: unknown) => {\n const e = err instanceof Error ? err : new Error(String(err));\n setLoadError(e);\n onError?.(e);\n });\n }, [catalog, provider, onError]);\n\n useEffect(() => {\n return entitlementStore.onChange.add(() => {\n setEntitlementTick((n) => n + 1);\n });\n }, [entitlementStore]);\n\n // entitlementTick read in render to keep the lint rule happy.\n void entitlementTick;\n\n async function handlePurchase(id: ProductId): Promise<void> {\n setInFlight(id);\n try {\n const result = await provider.purchase(id);\n if (result.status === 'purchased') {\n entitlementStore.grantProduct(id);\n }\n onPurchase?.(id, result);\n } catch (err: unknown) {\n const e = err instanceof Error ? err : new Error(String(err));\n onError?.(e);\n } finally {\n setInFlight(null);\n }\n }\n\n if (loadError !== null) {\n return (\n <Panel>\n <Label tone=\"danger\">{localize(strings.errorKey)}</Label>\n </Panel>\n );\n }\n\n if (products === null) {\n return (\n <Panel>\n <Label tone=\"muted\">{localize(strings.loadingKey)}</Label>\n </Panel>\n );\n }\n\n if (products.length === 0) {\n return (\n <Panel>\n <Label tone=\"muted\">{localize(strings.emptyKey)}</Label>\n </Panel>\n );\n }\n\n const owned: readonly Product[] = products.filter((p) => {\n const entry = catalog.entries.find((e) => e.productId === p.id);\n return entry?.grants.some((k) => entitlementStore.isEntitled(k)) ?? false;\n });\n const available: readonly Product[] = products.filter((p) => !owned.includes(p));\n\n return (\n <Panel variant=\"elevated\" padding=\"md\">\n <Label variant=\"lg\">{localize(strings.headingKey)}</Label>\n {owned.length > 0 ? (\n <View>\n <Label variant=\"sm\" tone=\"muted\">\n {localize(strings.ownedSectionKey)}\n </Label>\n {owned.map((p) => {\n const itemCopy = copy[p.id];\n return (\n <View key={p.id}>\n <Label variant=\"md\">{itemCopy ? localize(itemCopy.titleKey) : p.title}</Label>\n {itemCopy ? (\n <Label variant=\"sm\" tone=\"muted\">\n {localize(itemCopy.descriptionKey)}\n </Label>\n ) : null}\n <Button\n label={\n itemCopy ? localize(itemCopy.ownedLabelKey) : localize(strings.ownedSectionKey)\n }\n variant=\"ghost\"\n disabled\n />\n </View>\n );\n })}\n </View>\n ) : null}\n {available.length > 0 ? (\n <View>\n <Label variant=\"sm\" tone=\"muted\">\n {localize(strings.availableSectionKey)}\n </Label>\n {available.map((p) => {\n const itemCopy = copy[p.id];\n const purchasing = inFlight === p.id;\n return (\n <View key={p.id}>\n <Label variant=\"md\">{itemCopy ? localize(itemCopy.titleKey) : p.title}</Label>\n {itemCopy ? (\n <Label variant=\"sm\" tone=\"muted\">\n {localize(itemCopy.descriptionKey)}\n </Label>\n ) : null}\n <Button\n label={\n purchasing\n ? localize(strings.loadingKey)\n : itemCopy\n ? localize(itemCopy.ctaKey)\n : p.priceDisplay\n }\n variant=\"primary\"\n disabled={purchasing}\n onPress={() => {\n void handlePurchase(p.id);\n }}\n />\n </View>\n );\n })}\n </View>\n ) : null}\n </Panel>\n );\n}\n","import type {\n EntitlementKey,\n EntitlementStore,\n ProductId,\n PurchaseResult,\n} from '@flare-engine/iap';\nimport { useIAP } from '@flare-engine/iap';\nimport { Button, Label, Modal } from '@flare-engine/ui';\nimport { useState } from 'react';\nimport { View } from 'react-native';\nimport type { LocalizeFn, PaywallStrings } from './types.js';\n\nexport interface PaywallModalProps {\n readonly visible: boolean;\n readonly productId: ProductId;\n readonly entitlementKey: EntitlementKey;\n readonly entitlementStore: EntitlementStore;\n readonly strings: PaywallStrings;\n readonly localize: LocalizeFn;\n readonly onDismiss: () => void;\n readonly onPurchased?: (result: PurchaseResult) => void;\n readonly onError?: (error: Error) => void;\n}\n\n/**\n * Parent owns visibility — the paywall never hides itself except on successful\n * purchase. This keeps routing logic in the caller and avoids double-close races.\n */\nexport function PaywallModal({\n visible,\n productId,\n entitlementKey,\n entitlementStore,\n strings,\n localize,\n onDismiss,\n onPurchased,\n onError,\n}: PaywallModalProps): React.ReactNode {\n const provider = useIAP();\n const [purchasing, setPurchasing] = useState(false);\n const [purchaseError, setPurchaseError] = useState<Error | null>(null);\n\n if (!visible) return null;\n\n async function handlePurchase(): Promise<void> {\n setPurchasing(true);\n setPurchaseError(null);\n try {\n const result = await provider.purchase(productId);\n if (result.status === 'purchased') {\n entitlementStore.grant(entitlementKey);\n onPurchased?.(result);\n onDismiss();\n } else if (result.status === 'failed') {\n const e = result.error ?? new Error('Purchase failed');\n setPurchaseError(e);\n onError?.(e);\n }\n // 'cancelled' — stay open, no error shown\n } catch (err: unknown) {\n const e = err instanceof Error ? err : new Error(String(err));\n setPurchaseError(e);\n onError?.(e);\n } finally {\n setPurchasing(false);\n }\n }\n\n return (\n <Modal visible={visible} onBackdropPress={onDismiss}>\n <Label variant=\"lg\">{localize(strings.headingKey)}</Label>\n <Label variant=\"sm\" tone=\"muted\">\n {localize(strings.bodyKey)}\n </Label>\n {purchaseError !== null ? <Label tone=\"danger\">{localize(strings.errorKey)}</Label> : null}\n <View>\n <Button\n label={purchasing ? localize(strings.loadingKey) : localize(strings.ctaKey)}\n variant=\"primary\"\n disabled={purchasing}\n onPress={() => {\n void handlePurchase();\n }}\n />\n <Button\n label={localize(strings.dismissKey)}\n variant=\"ghost\"\n disabled={purchasing}\n onPress={onDismiss}\n />\n </View>\n </Modal>\n );\n}\n","import type { EntitlementStore, PurchaseResult } from '@flare-engine/iap';\nimport { useIAP } from '@flare-engine/iap';\nimport { Button, Label } from '@flare-engine/ui';\nimport { useState } from 'react';\nimport { View } from 'react-native';\nimport type { LocalizeFn, RestoreStrings } from './types.js';\n\ntype BannerKind = 'success' | 'empty' | 'error';\n\nexport interface RestorePurchasesButtonProps {\n readonly entitlementStore: EntitlementStore;\n readonly strings: RestoreStrings;\n readonly localize: LocalizeFn;\n readonly onComplete?: (results: readonly PurchaseResult[]) => void;\n readonly onError?: (error: Error) => void;\n}\n\nexport function RestorePurchasesButton({\n entitlementStore,\n strings,\n localize,\n onComplete,\n onError,\n}: RestorePurchasesButtonProps): React.ReactNode {\n const provider = useIAP();\n const [restoring, setRestoring] = useState(false);\n const [banner, setBanner] = useState<BannerKind | null>(null);\n const [bannerError, setBannerError] = useState<Error | null>(null);\n\n async function handleRestore(): Promise<void> {\n setRestoring(true);\n setBanner(null);\n setBannerError(null);\n try {\n const results = await provider.restore();\n let granted = 0;\n for (let i = 0; i < results.length; i++) {\n const r = results[i];\n if (r && r.status === 'purchased' && r.transaction) {\n entitlementStore.grantProduct(r.transaction.productId);\n granted++;\n }\n }\n setBanner(granted > 0 ? 'success' : 'empty');\n onComplete?.(results);\n } catch (err: unknown) {\n const e = err instanceof Error ? err : new Error(String(err));\n setBanner('error');\n setBannerError(e);\n onError?.(e);\n } finally {\n setRestoring(false);\n }\n }\n\n return (\n <View>\n <Button\n label={restoring ? localize(strings.loadingKey) : localize(strings.ctaKey)}\n variant=\"secondary\"\n disabled={restoring}\n onPress={() => {\n void handleRestore();\n }}\n />\n {banner === 'success' ? (\n <Label tone=\"success\">{localize(strings.successKey)}</Label>\n ) : banner === 'empty' ? (\n <Label tone=\"muted\">{localize(strings.emptyKey)}</Label>\n ) : banner === 'error' ? (\n <Label tone=\"danger\">\n {localize(strings.errorKey)}\n {bannerError !== null ? `: ${bannerError.message}` : ''}\n </Label>\n ) : null}\n </View>\n );\n}\n"],"mappings":";AAOA,SAAS,cAAc;AACvB,SAAS,QAAQ,OAAO,aAAa;AACrC,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,YAAY;AAwEb,cAsCM,YAtCN;AA3DD,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoC;AAClC,QAAM,WAAW,OAAO;AACxB,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoC,IAAI;AACxE,QAAM,CAAC,WAAW,YAAY,IAAI,SAAuB,IAAI;AAC7D,QAAM,CAAC,UAAU,WAAW,IAAI,SAA2B,IAAI;AAE/D,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAS,CAAC;AACxD,QAAM,UAAU,OAAO,KAAK;AAE5B,YAAU,MAAM;AACd,QAAI,QAAQ,QAAS;AACrB,YAAQ,UAAU;AAClB,UAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,MAAM,EAAE,SAAS;AAClD,aACG,YAAY,GAAG,EACf,KAAK,WAAW,EAChB,MAAM,CAAC,QAAiB;AACvB,YAAM,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;AAC5D,mBAAa,CAAC;AACd,gBAAU,CAAC;AAAA,IACb,CAAC;AAAA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,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,cAAM,IAAI,QAAQ,CAAC;AACnB,YAAI,KAAK,EAAE,WAAW,eAAe,EAAE,aAAa;AAClD,2BAAiB,aAAa,EAAE,YAAY,SAAS;AACrD;AAAA,QACF;AAAA,MACF;AACA,gBAAU,UAAU,IAAI,YAAY,OAAO;AAC3C,mBAAa,OAAO;AAAA,IACtB,SAAS,KAAc;AACrB,YAAM,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;AAC5D,gBAAU,OAAO;AACjB,qBAAe,CAAC;AAChB,gBAAU,CAAC;AAAA,IACb,UAAE;AACA,mBAAa,KAAK;AAAA,IACpB;AAAA,EACF;AAEA,SACE,gBAAAG,MAACF,OAAA,EACC;AAAA,oBAAAC;AAAA,MAACJ;AAAA,MAAA;AAAA,QACC,OAAO,YAAY,SAAS,QAAQ,UAAU,IAAI,SAAS,QAAQ,MAAM;AAAA,QACzE,SAAQ;AAAA,QACR,UAAU;AAAA,QACV,SAAS,MAAM;AACb,eAAK,cAAc;AAAA,QACrB;AAAA;AAAA,IACF;AAAA,IACC,WAAW,YACV,gBAAAI,KAACH,QAAA,EAAM,MAAK,WAAW,mBAAS,QAAQ,UAAU,GAAE,IAClD,WAAW,UACb,gBAAAG,KAACH,QAAA,EAAM,MAAK,SAAS,mBAAS,QAAQ,QAAQ,GAAE,IAC9C,WAAW,UACb,gBAAAI,MAACJ,QAAA,EAAM,MAAK,UACT;AAAA,eAAS,QAAQ,QAAQ;AAAA,MACzB,gBAAgB,OAAO,KAAK,YAAY,OAAO,KAAK;AAAA,OACvD,IACE;AAAA,KACN;AAEJ;","names":["useIAP","Button","Label","useState","View","jsx","jsxs","useIAP","Button","Label","useState","View","jsx","jsxs"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@flare-engine/ui-shop",
3
+ "version": "0.1.0",
4
+ "description": "Reusable ShopPanel, PaywallModal, and RestorePurchasesButton consuming IAPContext + EntitlementStore",
5
+ "keywords": ["flare-engine", "ui", "shop", "iap", "paywall", "react-native"],
6
+ "license": "MIT",
7
+ "author": "Grzegorz Otto",
8
+ "homepage": "https://github.com/grzott/flare-engine#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/grzott/flare-engine/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/grzott/flare-engine.git",
15
+ "directory": "packages/ui-shop"
16
+ },
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": ["dist", "README.md", "LICENSE"],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "bun test",
31
+ "lint": "biome check src/",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@flare-engine/events": "^0.1.0",
36
+ "@flare-engine/iap": "^0.1.0",
37
+ "@flare-engine/ui": "^0.1.0"
38
+ },
39
+ "peerDependencies": {
40
+ "react": ">=18.0.0",
41
+ "react-native": ">=0.74.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "^18.0.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "restricted",
48
+ "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "sideEffects": false
51
+ }