@flare-engine/ui-shop 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { EntitlementStore, ProductCatalog, ProductId, PurchaseResult } from "@flare-engine/iap";
2
- //#region src/types.d.ts
3
2
  /** Per-product copy the host provides; never touches i18n directly. */
4
3
  interface ShopItemCopy {
5
4
  titleKey: string;
@@ -35,8 +34,6 @@ interface RestoreStrings {
35
34
  * dependency — the caller owns the translation lookup.
36
35
  */
37
36
  type LocalizeFn = (key: string) => string;
38
- //#endregion
39
- //#region src/PaywallModal.d.ts
40
37
  interface PaywallModalProps {
41
38
  readonly visible: boolean;
42
39
  readonly productId: ProductId;
@@ -51,9 +48,7 @@ interface PaywallModalProps {
51
48
  * Parent owns visibility — the paywall never hides itself except on successful
52
49
  * purchase. This keeps routing logic in the caller and avoids double-close races.
53
50
  */
54
- declare function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }: PaywallModalProps): React.ReactNode;
55
- //#endregion
56
- //#region src/RestorePurchasesButton.d.ts
51
+ export declare function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }: PaywallModalProps): React.ReactNode;
57
52
  interface RestorePurchasesButtonProps {
58
53
  readonly entitlementStore: EntitlementStore;
59
54
  readonly strings: RestoreStrings;
@@ -61,9 +56,7 @@ interface RestorePurchasesButtonProps {
61
56
  readonly onComplete?: (results: readonly PurchaseResult[]) => void;
62
57
  readonly onError?: (error: Error) => void;
63
58
  }
64
- declare function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError }: RestorePurchasesButtonProps): React.ReactNode;
65
- //#endregion
66
- //#region src/ShopScreen.d.ts
59
+ export declare function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError }: RestorePurchasesButtonProps): React.ReactNode;
67
60
  interface ShopScreenProps {
68
61
  /**
69
62
  * Product catalog. Its identity (and the ambient IAP provider's) keys the
@@ -80,7 +73,6 @@ interface ShopScreenProps {
80
73
  readonly onPurchase?: (productId: ProductId, result: PurchaseResult) => void;
81
74
  readonly onError?: (error: Error) => void;
82
75
  }
83
- declare function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError }: ShopScreenProps): React.ReactNode;
84
- //#endregion
85
- export { type LocalizeFn, PaywallModal, type PaywallModalProps, type PaywallStrings, RestorePurchasesButton, type RestorePurchasesButtonProps, type RestoreStrings, type ShopItemCopy, type ShopPanelStrings, ShopScreen, type ShopScreenProps };
76
+ export declare function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError }: ShopScreenProps): React.ReactNode;
77
+ export type { LocalizeFn, PaywallModalProps, PaywallStrings, RestorePurchasesButtonProps, RestoreStrings, ShopItemCopy, ShopPanelStrings, ShopScreenProps };
86
78
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"mappings":";;;UACiB;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;;;;;;KAOU,cAAc;;;UC/BT;WACN;WACA,WAAW;WACX,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV;WACA,eAAe,QAAQ;WACvB,WAAW,OAAO;;;;;;iBAOb,eACd,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACC,oBAAoB,MAAM;;;UCtBZ;WACN,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV,cAAc,kBAAkB;WAChC,WAAW,OAAO;;iBAGb,yBACd,kBACA,SACA,UACA,YACA,WACC,8BAA8B,MAAM;;;UCVtB;;;;;;;;WAQN,SAAS;WACT,kBAAkB;WAClB,MAAM,OAAO,WAAW;WACxB,SAAS;WACT,UAAU;WACV,cAAc,WAAW,WAAW,QAAQ;WAC5C,WAAW,OAAO;;iBAGb,aACd,SACA,kBACA,MACA,SACA,UACA,YACA,WACC,kBAAkB,MAAM"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"mappings":";;UACiB;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;;;;;;KAOU,cAAc;UC/BT;WACN;WACA,WAAW;WACX,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV;WACA,eAAe,QAAQ;WACvB,WAAW,OAAO;;;;;;wBAOb,eACd,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACC,oBAAoB,MAAM;UCtBZ;WACN,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV,cAAc,kBAAkB;WAChC,WAAW,OAAO;;wBAGb,yBACd,kBACA,SACA,UACA,YACA,WACC,8BAA8B,MAAM;UCVtB;;;;;;;;WAQN,SAAS;WACT,kBAAkB;WAClB,MAAM,OAAO,WAAW;WACxB,SAAS;WACT,UAAU;WACV,cAAc,WAAW,WAAW,QAAQ;WAC5C,WAAW,OAAO;;wBAGb,aACd,SACA,kBACA,MACA,SACA,UACA,YACA,WACC,kBAAkB,MAAM"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { EntitlementStore, ProductCatalog, ProductId, PurchaseResult } from "@flare-engine/iap";
2
- //#region src/types.d.ts
3
2
  /** Per-product copy the host provides; never touches i18n directly. */
4
3
  interface ShopItemCopy {
5
4
  titleKey: string;
@@ -35,8 +34,6 @@ interface RestoreStrings {
35
34
  * dependency — the caller owns the translation lookup.
36
35
  */
37
36
  type LocalizeFn = (key: string) => string;
38
- //#endregion
39
- //#region src/PaywallModal.d.ts
40
37
  interface PaywallModalProps {
41
38
  readonly visible: boolean;
42
39
  readonly productId: ProductId;
@@ -51,9 +48,7 @@ interface PaywallModalProps {
51
48
  * Parent owns visibility — the paywall never hides itself except on successful
52
49
  * purchase. This keeps routing logic in the caller and avoids double-close races.
53
50
  */
54
- declare function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }: PaywallModalProps): React.ReactNode;
55
- //#endregion
56
- //#region src/RestorePurchasesButton.d.ts
51
+ export declare function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }: PaywallModalProps): React.ReactNode;
57
52
  interface RestorePurchasesButtonProps {
58
53
  readonly entitlementStore: EntitlementStore;
59
54
  readonly strings: RestoreStrings;
@@ -61,9 +56,7 @@ interface RestorePurchasesButtonProps {
61
56
  readonly onComplete?: (results: readonly PurchaseResult[]) => void;
62
57
  readonly onError?: (error: Error) => void;
63
58
  }
64
- declare function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError }: RestorePurchasesButtonProps): React.ReactNode;
65
- //#endregion
66
- //#region src/ShopScreen.d.ts
59
+ export declare function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError }: RestorePurchasesButtonProps): React.ReactNode;
67
60
  interface ShopScreenProps {
68
61
  /**
69
62
  * Product catalog. Its identity (and the ambient IAP provider's) keys the
@@ -80,7 +73,6 @@ interface ShopScreenProps {
80
73
  readonly onPurchase?: (productId: ProductId, result: PurchaseResult) => void;
81
74
  readonly onError?: (error: Error) => void;
82
75
  }
83
- declare function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError }: ShopScreenProps): React.ReactNode;
84
- //#endregion
85
- export { type LocalizeFn, PaywallModal, type PaywallModalProps, type PaywallStrings, RestorePurchasesButton, type RestorePurchasesButtonProps, type RestoreStrings, type ShopItemCopy, type ShopPanelStrings, ShopScreen, type ShopScreenProps };
76
+ export declare function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError }: ShopScreenProps): React.ReactNode;
77
+ export type { LocalizeFn, PaywallModalProps, PaywallStrings, RestorePurchasesButtonProps, RestoreStrings, ShopItemCopy, ShopPanelStrings, ShopScreenProps };
86
78
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"mappings":";;;UACiB;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;;;;;;KAOU,cAAc;;;UC/BT;WACN;WACA,WAAW;WACX,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV;WACA,eAAe,QAAQ;WACvB,WAAW,OAAO;;;;;;iBAOb,eACd,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACC,oBAAoB,MAAM;;;UCtBZ;WACN,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV,cAAc,kBAAkB;WAChC,WAAW,OAAO;;iBAGb,yBACd,kBACA,SACA,UACA,YACA,WACC,8BAA8B,MAAM;;;UCVtB;;;;;;;;WAQN,SAAS;WACT,kBAAkB;WAClB,MAAM,OAAO,WAAW;WACxB,SAAS;WACT,UAAU;WACV,cAAc,WAAW,WAAW,QAAQ;WAC5C,WAAW,OAAO;;iBAGb,aACd,SACA,kBACA,MACA,SACA,UACA,YACA,WACC,kBAAkB,MAAM"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"mappings":";;UACiB;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;;;;;;KAOU,cAAc;UC/BT;WACN;WACA,WAAW;WACX,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV;WACA,eAAe,QAAQ;WACvB,WAAW,OAAO;;;;;;wBAOb,eACd,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACC,oBAAoB,MAAM;UCtBZ;WACN,kBAAkB;WAClB,SAAS;WACT,UAAU;WACV,cAAc,kBAAkB;WAChC,WAAW,OAAO;;wBAGb,yBACd,kBACA,SACA,UACA,YACA,WACC,8BAA8B,MAAM;UCVtB;;;;;;;;WAQN,SAAS;WACT,kBAAkB;WAClB,MAAM,OAAO,WAAW;WACxB,SAAS;WACT,UAAU;WACV,cAAc,WAAW,WAAW,QAAQ;WAC5C,WAAW,OAAO;;wBAGb,aACd,SACA,kBACA,MACA,SACA,UACA,YACA,WACC,kBAAkB,MAAM"}
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ let _flare_engine_ui = require("@flare-engine/ui");
4
4
  let react = require("react");
5
5
  let react_native = require("react-native");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
- //#region src/PaywallModal.tsx
7
+ // src/PaywallModal.tsx
8
8
  /**
9
9
  * Parent owns visibility — the paywall never hides itself except on successful
10
10
  * purchase. This keeps routing logic in the caller and avoids double-close races.
@@ -69,8 +69,7 @@ function PaywallModal({ visible, productId, entitlementStore, strings, localize,
69
69
  ]
70
70
  });
71
71
  }
72
- //#endregion
73
- //#region src/RestorePurchasesButton.tsx
72
+ // src/RestorePurchasesButton.tsx
74
73
  function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError }) {
75
74
  const provider = (0, _flare_engine_iap.useIAP)();
76
75
  const [restoring, setRestoring] = (0, react.useState)(false);
@@ -119,8 +118,7 @@ function RestorePurchasesButton({ entitlementStore, strings, localize, onComplet
119
118
  children: [localize(strings.errorKey), bannerError !== null ? `: ${bannerError.message}` : ""]
120
119
  }) : null] });
121
120
  }
122
- //#endregion
123
- //#region src/ShopScreen.tsx
121
+ // src/ShopScreen.tsx
124
122
  function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError }) {
125
123
  const provider = (0, _flare_engine_iap.useIAP)();
126
124
  const [products, setProducts] = (0, react.useState)(null);
@@ -241,7 +239,6 @@ function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurc
241
239
  ]
242
240
  });
243
241
  }
244
- //#endregion
245
242
  exports.PaywallModal = PaywallModal;
246
243
  exports.RestorePurchasesButton = RestorePurchasesButton;
247
244
  exports.ShopScreen = ShopScreen;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Modal","Label","View","Button","View","Button","Label","Panel","Label","View","Button"],"sources":["../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"sourcesContent":["import type { EntitlementStore, ProductId, PurchaseResult } 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 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 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.grantProduct(productId);\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={purchasing ? undefined : 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","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 ShopScreenProps {\n /**\n * Product catalog. Its identity (and the ambient IAP provider's) keys the\n * product fetch: a change refetches and resets to the loading state — that is\n * how a Noop→concrete provider swap picks up real products. Pass a stable\n * reference (a memoized/singleton catalog), not a value rebuilt every render,\n * or the fetch will re-run on each parent render.\n */\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 ShopScreen({\n catalog,\n entitlementStore,\n copy,\n strings,\n localize,\n onPurchase,\n onError,\n}: ShopScreenProps): 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 // Latest-ref for onError so a fresh inline callback identity cannot re-trigger\n // the fetch effect (which is keyed to catalog/provider identity only).\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n // Refetch whenever the catalog or the IAP provider identity changes (e.g. a\n // Noop→concrete provider swap), resetting to the loading state; a cancelled\n // flag drops a stale in-flight response from the previous provider.\n useEffect(() => {\n let cancelled = false;\n setProducts(null);\n setLoadError(null);\n const ids = catalog.entries.map((e) => e.productId);\n provider\n .getProducts(ids)\n .then((p) => {\n if (!cancelled) setProducts(p);\n })\n .catch((err: unknown) => {\n if (cancelled) return;\n const e = err instanceof Error ? err : new Error(String(err));\n setLoadError(e);\n onErrorRef.current?.(e);\n });\n return () => {\n cancelled = true;\n };\n }, [catalog, provider]);\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"],"mappings":";;;;;;;;;;;AAsBA,SAAgB,aAAa,EAC3B,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACqC;CACrC,MAAM,YAAA,GAAA,kBAAA,OAAA,CAAkB;CACxB,MAAM,CAAC,YAAY,kB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ClB,iBAAA,GAAA,kBAAA,KAAA,CAACD,aAAAA,MAAD,EAAA,UAAA,CACE,iBAAA,GAAA,kBAAA,IAAA,CAACD,iBAAAA,OAAD;IAAO,SAAQ;IAAK,MAAK;cACtB,SAAS,QAAQ,mBAAmB;GAChC,CAAA,GACN,UAAU,KAAK,MAAM;IACpB,MAAM,WAAW,KAAK,EAAE;IACxB,MAAM,aAAa,aAAa,EAAE;IAClC,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACC,aAAAA,MAAD,EAAA,UAAA;KACE,iBAAA,GAAA,kBAAA,IAAA,CAACD,iBAAAA,OAAD;MAAO,SAAQ;gBAAM,WAAW,SAAS,SAAS,QAAQ,IAAI,EAAE;KAAa,CAAA;KAC5E,WACC,iBAAA,GAAA,kBAAA,IAAA,CAACA,iBAAAA,OAAD;MAAO,SAAQ;MAAK,MAAK;gBACtB,SAAS,SAAS,cAAc;KAC5B,CAAA,IACL;KACJ,iBAAA,GAAA,kBAAA,IAAA,CAACE,iBAAAA,QAAD;MACE,OACE,aACI,SAAS,QAAQ,UAAU,IAC3B,WACE,SAAS,SAAS,MAAM,IACxB,EAAE;MAEV,SAAQ;MACR,UAAU;MACV,eAAe;OACb,eAAoB,EAAE,EAAE;MAC1B;KACD,CAAA;IACG,EAAA,GArBK,EAAE,EAqBP;GAEV,CAAC,CACG,EAAA,CAAA,IACJ;EACC;;AAEX"}
1
+ {"version":3,"file":"index.js","names":["useIAP","useState","Modal","Label","View","Button","useIAP","useState","View","Button","Label","useIAP","useState","useRef","Panel","Label","View","Button"],"sources":["../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"sourcesContent":["import type { EntitlementStore, ProductId, PurchaseResult } 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 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 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.grantProduct(productId);\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={purchasing ? undefined : 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","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 ShopScreenProps {\n /**\n * Product catalog. Its identity (and the ambient IAP provider's) keys the\n * product fetch: a change refetches and resets to the loading state — that is\n * how a Noop→concrete provider swap picks up real products. Pass a stable\n * reference (a memoized/singleton catalog), not a value rebuilt every render,\n * or the fetch will re-run on each parent render.\n */\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 ShopScreen({\n catalog,\n entitlementStore,\n copy,\n strings,\n localize,\n onPurchase,\n onError,\n}: ShopScreenProps): 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 // Latest-ref for onError so a fresh inline callback identity cannot re-trigger\n // the fetch effect (which is keyed to catalog/provider identity only).\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n // Refetch whenever the catalog or the IAP provider identity changes (e.g. a\n // Noop→concrete provider swap), resetting to the loading state; a cancelled\n // flag drops a stale in-flight response from the previous provider.\n useEffect(() => {\n let cancelled = false;\n setProducts(null);\n setLoadError(null);\n const ids = catalog.entries.map((e) => e.productId);\n provider\n .getProducts(ids)\n .then((p) => {\n if (!cancelled) setProducts(p);\n })\n .catch((err: unknown) => {\n if (cancelled) return;\n const e = err instanceof Error ? err : new Error(String(err));\n setLoadError(e);\n onErrorRef.current?.(e);\n });\n return () => {\n cancelled = true;\n };\n }, [catalog, provider]);\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"],"mappings":";;;;;;;;;;;AAsBA,SAAgB,aAAa,EAC3B,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACqC;CACrC,MAAM,YAAA,GAAWA,kBAAAA,OAAAA,CAAO;CACxB,MAAM,CAAC,YAAY,kBAAA,GAAiBC,MAAAA,SAAAA,CAAS,KAAK;CAClD,MAAM,CAAC,eAAe,qBAAA,GAAoBA,MAAAA,SAAAA,CAAuB,IAAI;CAErE,IAAI,CAAC,SAAS,OAAO;CAErB,eAAe,iBAAgC;EAC7C,cAAc,IAAI;EAClB,iBAAiB,IAAI;EACrB,IAAI;GACF,MAAM,SAAS,MAAM,SAAS,SAAS,SAAS;GAChD,IAAI,OAAO,WAAW,aAAa;IACjC,iBAAiB,aAAa,SAAS;IACvC,cAAc,MAAM;IACpB,UAAU;GACZ,OAAO,IAAI,OAAO,WAAW,UAAU;IACrC,MAAM,IAAI,OAAO,yBAAS,IAAI,MAAM,iBAAiB;IACrD,iBAAiB,CAAC;IAClB,UAAU,CAAC;GACb;EAEF,SAAS,KAAc;GACrB,MAAM,IAAI,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;GAC5D,iBAAiB,CAAC;GAClB,UAAU,CAAC;EACb,UAAU;GACR,cAAc,KAAK;EACr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AA,kBAAA,IAAA,CAACA,iBAAAA,OAAD;MAAO,SAAQ;MAAK,MAAK;MACtB,UAAA,SAAS,SAAS,cAAc;KAC5B,CAAA,IACL;KACJ,iBAAA,GAAA,kBAAA,IAAA,CAACE,iBAAAA,QAAD;MACE,OACE,aACI,SAAS,QAAQ,UAAU,IAC3B,WACE,SAAS,SAAS,MAAM,IACxB,EAAE;MAEV,SAAQ;MACR,UAAU;MACV,eAAe;OACb,eAAoB,EAAE,EAAE;MAC1B;KACD,CAAA;IACG,EAAA,GArBK,EAAE,EAqBP;GAEV,CAAC,CACG,EAAA,CAAA,IACJ;EACC;;AAEX"}
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { Button, Label, Modal, Panel } from "@flare-engine/ui";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { View } from "react-native";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- //#region src/PaywallModal.tsx
6
+ // src/PaywallModal.tsx
7
7
  /**
8
8
  * Parent owns visibility — the paywall never hides itself except on successful
9
9
  * purchase. This keeps routing logic in the caller and avoids double-close races.
@@ -68,8 +68,7 @@ function PaywallModal({ visible, productId, entitlementStore, strings, localize,
68
68
  ]
69
69
  });
70
70
  }
71
- //#endregion
72
- //#region src/RestorePurchasesButton.tsx
71
+ // src/RestorePurchasesButton.tsx
73
72
  function RestorePurchasesButton({ entitlementStore, strings, localize, onComplete, onError }) {
74
73
  const provider = useIAP();
75
74
  const [restoring, setRestoring] = useState(false);
@@ -118,8 +117,7 @@ function RestorePurchasesButton({ entitlementStore, strings, localize, onComplet
118
117
  children: [localize(strings.errorKey), bannerError !== null ? `: ${bannerError.message}` : ""]
119
118
  }) : null] });
120
119
  }
121
- //#endregion
122
- //#region src/ShopScreen.tsx
120
+ // src/ShopScreen.tsx
123
121
  function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurchase, onError }) {
124
122
  const provider = useIAP();
125
123
  const [products, setProducts] = useState(null);
@@ -240,7 +238,6 @@ function ShopScreen({ catalog, entitlementStore, copy, strings, localize, onPurc
240
238
  ]
241
239
  });
242
240
  }
243
- //#endregion
244
241
  export { PaywallModal, RestorePurchasesButton, ShopScreen };
245
242
 
246
243
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"sourcesContent":["import type { EntitlementStore, ProductId, PurchaseResult } 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 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 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.grantProduct(productId);\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={purchasing ? undefined : 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","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 ShopScreenProps {\n /**\n * Product catalog. Its identity (and the ambient IAP provider's) keys the\n * product fetch: a change refetches and resets to the loading state — that is\n * how a Noop→concrete provider swap picks up real products. Pass a stable\n * reference (a memoized/singleton catalog), not a value rebuilt every render,\n * or the fetch will re-run on each parent render.\n */\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 ShopScreen({\n catalog,\n entitlementStore,\n copy,\n strings,\n localize,\n onPurchase,\n onError,\n}: ShopScreenProps): 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 // Latest-ref for onError so a fresh inline callback identity cannot re-trigger\n // the fetch effect (which is keyed to catalog/provider identity only).\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n // Refetch whenever the catalog or the IAP provider identity changes (e.g. a\n // Noop→concrete provider swap), resetting to the loading state; a cancelled\n // flag drops a stale in-flight response from the previous provider.\n useEffect(() => {\n let cancelled = false;\n setProducts(null);\n setLoadError(null);\n const ids = catalog.entries.map((e) => e.productId);\n provider\n .getProducts(ids)\n .then((p) => {\n if (!cancelled) setProducts(p);\n })\n .catch((err: unknown) => {\n if (cancelled) return;\n const e = err instanceof Error ? err : new Error(String(err));\n setLoadError(e);\n onErrorRef.current?.(e);\n });\n return () => {\n cancelled = true;\n };\n }, [catalog, provider]);\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"],"mappings":";;;;;;;;;;AAsBA,SAAgB,aAAa,EAC3B,SACA,WACA,kBACA,SACA,UACA,WACA,aACA,WACqC;CACrC,MAAM,WAAW,OAAO;CACxB,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,eAAe,oBAAoB,SAAuB,IAAI;CAErE,IAAI,CAAC,SAAS,OAAO;CAErB,eAAe,iBAAgC;EAC7C,cAAc,IAAI;EAClB,iBAAiB,IAAI;EACrB,IAAI;GACF,MAAM,SAAS,MA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mBAAmB;GAChC,CAAA,GACN,UAAU,KAAK,MAAM;IACpB,MAAM,WAAW,KAAK,EAAE;IACxB,MAAM,aAAa,aAAa,EAAE;IAClC,OACE,qBAAC,MAAD,EAAA,UAAA;KACE,oBAAC,OAAD;MAAO,SAAQ;gBAAM,WAAW,SAAS,SAAS,QAAQ,IAAI,EAAE;KAAa,CAAA;KAC5E,WACC,oBAAC,OAAD;MAAO,SAAQ;MAAK,MAAK;gBACtB,SAAS,SAAS,cAAc;KAC5B,CAAA,IACL;KACJ,oBAAC,QAAD;MACE,OACE,aACI,SAAS,QAAQ,UAAU,IAC3B,WACE,SAAS,SAAS,MAAM,IACxB,EAAE;MAEV,SAAQ;MACR,UAAU;MACV,eAAe;OACb,eAAoB,EAAE,EAAE;MAC1B;KACD,CAAA;IACG,EAAA,GArBK,EAAE,EAqBP;GAEV,CAAC,CACG,EAAA,CAAA,IACJ;EACC;;AAEX"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"sourcesContent":["import type { EntitlementStore, ProductId, PurchaseResult } 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 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 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.grantProduct(productId);\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={purchasing ? undefined : 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","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 ShopScreenProps {\n /**\n * Product catalog. Its identity (and the ambient IAP provider's) keys the\n * product fetch: a change refetches and resets to the loading state — that is\n * how a Noop→concrete provider swap picks up real products. Pass a stable\n * reference (a memoized/singleton catalog), not a value rebuilt every render,\n * or the fetch will re-run on each parent render.\n */\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 ShopScreen({\n catalog,\n entitlementStore,\n copy,\n strings,\n localize,\n onPurchase,\n onError,\n}: ShopScreenProps): 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 // Latest-ref for onError so a fresh inline callback identity cannot re-trigger\n // the fetch effect (which is keyed to catalog/provider identity only).\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n // Refetch whenever the catalog or the IAP provider identity changes (e.g. a\n // Noop→concrete provider swap), resetting to the loading state; a cancelled\n // flag drops a stale in-flight response from the previous provider.\n useEffect(() => {\n let cancelled = false;\n setProducts(null);\n setLoadError(null);\n const ids = catalog.entries.map((e) => e.productId);\n provider\n .getProducts(ids)\n .then((p) => {\n if (!cancelled) setProducts(p);\n })\n .catch((err: unknown) => {\n if (cancelled) return;\n const e = err instanceof Error ? err : new Error(String(err));\n setLoadError(e);\n onErrorRef.current?.(e);\n });\n return () => {\n cancelled = true;\n };\n }, [catalog, provider]);\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}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qBAAC,MAAD,EAAA,UAAA;KACE,oBAAC,OAAD;MAAO,SAAQ;MAAM,UAAA,WAAW,SAAS,SAAS,QAAQ,IAAI,EAAE;KAAa,CAAA;KAC5E,WACC,oBAAC,OAAD;MAAO,SAAQ;MAAK,MAAK;MACtB,UAAA,SAAS,SAAS,cAAc;KAC5B,CAAA,IACL;KACJ,oBAAC,QAAD;MACE,OACE,WAAW,SAAS,SAAS,aAAa,IAAI,SAAS,QAAQ,eAAe;MAEhF,SAAQ;MACR,UAAA;KACD,CAAA;IACG,EAAA,GAdK,EAAE,EAcP;GAEV,CAAC,CACG,EAAA,CAAA,IACJ;GACH,UAAU,SAAS,IAClB,qBAAC,MAAD,EAAA,UAAA,CACE,oBAAC,OAAD;IAAO,SAAQ;IAAK,MAAK;IACtB,UAAA,SAAS,QAAQ,mBAAmB;GAChC,CAAA,GACN,UAAU,KAAK,MAAM;IACpB,MAAM,WAAW,KAAK,EAAE;IACxB,MAAM,aAAa,aAAa,EAAE;IAClC,OACE,qBAAC,MAAD,EAAA,UAAA;KACE,oBAAC,OAAD;MAAO,SAAQ;MAAM,UAAA,WAAW,SAAS,SAAS,QAAQ,IAAI,EAAE;KAAa,CAAA;KAC5E,WACC,oBAAC,OAAD;MAAO,SAAQ;MAAK,MAAK;MACtB,UAAA,SAAS,SAAS,cAAc;KAC5B,CAAA,IACL;KACJ,oBAAC,QAAD;MACE,OACE,aACI,SAAS,QAAQ,UAAU,IAC3B,WACE,SAAS,SAAS,MAAM,IACxB,EAAE;MAEV,SAAQ;MACR,UAAU;MACV,eAAe;OACb,eAAoB,EAAE,EAAE;MAC1B;KACD,CAAA;IACG,EAAA,GArBK,EAAE,EAqBP;GAEV,CAAC,CACG,EAAA,CAAA,IACJ;EACC;;AAEX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/ui-shop",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "Reusable ShopPanel, PaywallModal, and RestorePurchasesButton consuming IAPContext + EntitlementStore",
5
5
  "keywords": ["flare-engine", "ui", "shop", "iap", "paywall", "react-native"],
6
6
  "license": "Apache-2.0",
@@ -37,15 +37,15 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "dependencies": {
40
- "@flare-engine/iap": "^0.4.6",
41
- "@flare-engine/ui": "^0.4.6"
40
+ "@flare-engine/iap": "^0.4.8",
41
+ "@flare-engine/ui": "^0.4.8"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": ">=19.0.0",
45
45
  "react-native": ">=0.79.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/react": "^19.0.0"
48
+ "@types/react": "^19.3.0"
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=20"