@flare-engine/ui-shop 0.3.0 → 0.4.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/README.md +0 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntitlementStore, ProductCatalog, ProductId, PurchaseResult } from "@flare-engine/iap";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
3
|
/** Per-product copy the host provides; never touches i18n directly. */
|
|
4
4
|
interface ShopItemCopy {
|
|
@@ -40,7 +40,6 @@ type LocalizeFn = (key: string) => string;
|
|
|
40
40
|
interface PaywallModalProps {
|
|
41
41
|
readonly visible: boolean;
|
|
42
42
|
readonly productId: ProductId;
|
|
43
|
-
readonly entitlementKey: EntitlementKey;
|
|
44
43
|
readonly entitlementStore: EntitlementStore;
|
|
45
44
|
readonly strings: PaywallStrings;
|
|
46
45
|
readonly localize: LocalizeFn;
|
|
@@ -52,7 +51,7 @@ interface PaywallModalProps {
|
|
|
52
51
|
* Parent owns visibility — the paywall never hides itself except on successful
|
|
53
52
|
* purchase. This keeps routing logic in the caller and avoids double-close races.
|
|
54
53
|
*/
|
|
55
|
-
declare function PaywallModal({ visible, productId,
|
|
54
|
+
declare function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }: PaywallModalProps): React.ReactNode;
|
|
56
55
|
//#endregion
|
|
57
56
|
//#region src/RestorePurchasesButton.d.ts
|
|
58
57
|
interface RestorePurchasesButtonProps {
|
package/dist/index.d.mts.map
CHANGED
|
@@ -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;;;
|
|
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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntitlementStore, ProductCatalog, ProductId, PurchaseResult } from "@flare-engine/iap";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
3
|
/** Per-product copy the host provides; never touches i18n directly. */
|
|
4
4
|
interface ShopItemCopy {
|
|
@@ -40,7 +40,6 @@ type LocalizeFn = (key: string) => string;
|
|
|
40
40
|
interface PaywallModalProps {
|
|
41
41
|
readonly visible: boolean;
|
|
42
42
|
readonly productId: ProductId;
|
|
43
|
-
readonly entitlementKey: EntitlementKey;
|
|
44
43
|
readonly entitlementStore: EntitlementStore;
|
|
45
44
|
readonly strings: PaywallStrings;
|
|
46
45
|
readonly localize: LocalizeFn;
|
|
@@ -52,7 +51,7 @@ interface PaywallModalProps {
|
|
|
52
51
|
* Parent owns visibility — the paywall never hides itself except on successful
|
|
53
52
|
* purchase. This keeps routing logic in the caller and avoids double-close races.
|
|
54
53
|
*/
|
|
55
|
-
declare function PaywallModal({ visible, productId,
|
|
54
|
+
declare function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }: PaywallModalProps): React.ReactNode;
|
|
56
55
|
//#endregion
|
|
57
56
|
//#region src/RestorePurchasesButton.d.ts
|
|
58
57
|
interface RestorePurchasesButtonProps {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;;;
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
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.
|
|
11
11
|
*/
|
|
12
|
-
function PaywallModal({ visible, productId,
|
|
12
|
+
function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }) {
|
|
13
13
|
const provider = (0, _flare_engine_iap.useIAP)();
|
|
14
14
|
const [purchasing, setPurchasing] = (0, react.useState)(false);
|
|
15
15
|
const [purchaseError, setPurchaseError] = (0, react.useState)(null);
|
|
@@ -20,7 +20,7 @@ function PaywallModal({ visible, productId, entitlementKey, entitlementStore, st
|
|
|
20
20
|
try {
|
|
21
21
|
const result = await provider.purchase(productId);
|
|
22
22
|
if (result.status === "purchased") {
|
|
23
|
-
entitlementStore.
|
|
23
|
+
entitlementStore.grantProduct(productId);
|
|
24
24
|
onPurchased?.(result);
|
|
25
25
|
onDismiss();
|
|
26
26
|
} else if (result.status === "failed") {
|
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 {\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={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":";;;;;;;;;;;AA4BA,SAAgB,aAAa,EAC3B,SACA,WACA,gBACA,kBACA,SACA,UACA,WACA,aACA,WACqC;CACrC,MAAM,YAAA,GAAA,kBAAA,OAAA,CAAkB;CACxB,MAAM,CAAC,YAAY,kBAAA,GAAA,MAAA,SAAA,CAA0B,KAAK;CAClD,MAAM,CAAC,eAAe,qBAAA,GAAA,MAAA,SAAA,CAA2C,IAAI;CAErE,IAAI,CAAC,SAAS,OAAO;CAErB,eAAe,iBAAgC;EAC7C,cAAc,IAAI;EAClB,iBAAiB,IAAI;EACrB,IAAI;GACF,MAAM,SAAS,MAAM,SAAS,SAAS,SAAS;G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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":["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,kBAAA,GAAA,MAAA,SAAA,CAA0B,KAAK;CAClD,MAAM,CAAC,eAAe,qBAAA,GAAA,MAAA,SAAA,CAA2C,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;EACrB;CACF;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACA,iBAAAA,OAAD;EAAgB;EAAS,iBAAiB,aAAa,KAAA,IAAY;YAAnE;GACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,iBAAAA,OAAD;IAAO,SAAQ;cAAM,SAAS,QAAQ,UAAU;GAAS,CAAA;GACzD,iBAAA,GAAA,kBAAA,IAAA,CAACA,iBAAAA,OAAD;IAAO,SAAQ;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7 +8,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
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.
|
|
10
10
|
*/
|
|
11
|
-
function PaywallModal({ visible, productId,
|
|
11
|
+
function PaywallModal({ visible, productId, entitlementStore, strings, localize, onDismiss, onPurchased, onError }) {
|
|
12
12
|
const provider = useIAP();
|
|
13
13
|
const [purchasing, setPurchasing] = useState(false);
|
|
14
14
|
const [purchaseError, setPurchaseError] = useState(null);
|
|
@@ -19,7 +19,7 @@ function PaywallModal({ visible, productId, entitlementKey, entitlementStore, st
|
|
|
19
19
|
try {
|
|
20
20
|
const result = await provider.purchase(productId);
|
|
21
21
|
if (result.status === "purchased") {
|
|
22
|
-
entitlementStore.
|
|
22
|
+
entitlementStore.grantProduct(productId);
|
|
23
23
|
onPurchased?.(result);
|
|
24
24
|
onDismiss();
|
|
25
25
|
} else if (result.status === "failed") {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/PaywallModal.tsx","../src/RestorePurchasesButton.tsx","../src/ShopScreen.tsx"],"sourcesContent":["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={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":";;;;;;;;;;AA4BA,SAAgB,aAAa,EAC3B,SACA,WACA,gBACA,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,MAAM,SAAS,SAAS,SAAS;GAChD,IAAI,OAAO,WAAW,aAAa;IACjC,iBAAiB,MAAM,cAAc;IACrC,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;EACrB;CACF;CAEA,OACE,qBAAC,OAAD;EAAgB;EAAS,iBAAiB,aAAa,KAAA,IAAY;YAAnE;GACE,oBAAC,OAAD;IAAO,SAAQ;cAAM,SAAS,QAAQ,UAAU;GAAS,CAAA;GACzD,oBAAC,OAAD;IAAO,SAAQ;IAAK,MAAK;cACtB,SAAS,QAAQ,OAAO;GACpB,CAAA;GACN,kBAAkB,OAAO,oBAAC,OAAD;IAAO,MAAK;c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],"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,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,KAA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AO,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/ui-shop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsdown",
|
|
35
|
-
"test": "bun test",
|
|
35
|
+
"test": "bun ../../scripts/test-isolated.mjs",
|
|
36
36
|
"lint": "biome check src/",
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@flare-engine/iap": "^0.
|
|
41
|
-
"@flare-engine/ui": "^0.
|
|
40
|
+
"@flare-engine/iap": "^0.4.0",
|
|
41
|
+
"@flare-engine/ui": "^0.4.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": ">=19.0.0",
|