@moonbase.sh/react 0.0.0-next-20261111171533 → 0.0.0-next-20261111171855
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 +42 -0
- package/dist/index.cjs +199 -65
- package/dist/index.d.cts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.js +161 -34
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -97,6 +97,9 @@ identity across renders, so it can go in a dependency list or to a memoized chil
|
|
|
97
97
|
- `useInventory()` - owned products, licenses and the computers they're activated on, downloads, and subscriptions:
|
|
98
98
|
cancelling, renewing, changing plan and changing the card they're paid with.
|
|
99
99
|
- `useOrders()` - the signed-in customer's completed orders, newest first, and their receipt PDFs.
|
|
100
|
+
- `useOwnedProducts()`, `useOwnedProduct(id)`, `useProductActivations(id)`, `useProductLicenses(id)`,
|
|
101
|
+
`useOrderHistory()`, `useSubscriptions()`, `useSubscription(id)` - the signed-in customer's account data, loaded for
|
|
102
|
+
you (see [Account pages](#account-pages)).
|
|
100
103
|
- `useVoucher()` - what a voucher code gives, and redeeming it.
|
|
101
104
|
- `useActivationRequest(token, options)` - activating a product in the browser: the request the app made, granting it a
|
|
102
105
|
license or a trial, and waiting for the app to pick it up. With `{ autoFulfill: true }` it activates with the signed-in
|
|
@@ -158,6 +161,45 @@ function CheckoutButton() {
|
|
|
158
161
|
}
|
|
159
162
|
```
|
|
160
163
|
|
|
164
|
+
## Account pages
|
|
165
|
+
|
|
166
|
+
The account data hooks load what they show for whoever is signed in, and load it again when that changes. Each returns
|
|
167
|
+
`{ data, loading, error, reload }`, and the lists, which Moonbase hands out a page at a time, add `hasMore` and
|
|
168
|
+
`loadMore`, with `data` holding every page loaded so far:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { useOrderHistory } from '@moonbase.sh/react'
|
|
172
|
+
|
|
173
|
+
function Purchases() {
|
|
174
|
+
const orders = useOrderHistory()
|
|
175
|
+
|
|
176
|
+
if (orders.error)
|
|
177
|
+
return <p role="alert">{orders.error.message}</p>
|
|
178
|
+
if (!orders.data)
|
|
179
|
+
return <p>Loading…</p>
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<>
|
|
183
|
+
{orders.data.length === 0 && <p>No purchases yet.</p>}
|
|
184
|
+
<ul>
|
|
185
|
+
{orders.data.map(order => <li key={order.id}>{order.id}</li>)}
|
|
186
|
+
</ul>
|
|
187
|
+
{orders.hasMore && (
|
|
188
|
+
<button disabled={orders.loading} onClick={orders.loadMore}>Show more</button>
|
|
189
|
+
)}
|
|
190
|
+
</>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
`data` is null while it first loads, with nobody signed in, and for an ID of `null` or `undefined`, which asks for nothing.
|
|
196
|
+
`loading` is true while a request is in flight and until the storefront knows who is signed in, so a page doesn't flash
|
|
197
|
+
"Nothing here" before it does. What a hook loaded is kept for as long as the same customer is signed in: a component
|
|
198
|
+
that mounts again, such as a tab the customer comes back to, shows it at once and asks again in the background.
|
|
199
|
+
Components asking for the same thing at once share one request. After changing something, call `reload`, which goes
|
|
200
|
+
back to a list's first page. `reload` and `loadMore` never reject: a failure lands in `error`, and `data` keeps what was
|
|
201
|
+
there.
|
|
202
|
+
|
|
161
203
|
## Checkout events
|
|
162
204
|
|
|
163
205
|
```tsx
|
package/dist/index.cjs
CHANGED
|
@@ -42,23 +42,30 @@ __export(index_exports, {
|
|
|
42
42
|
useLockedOffers: () => useLockedOffers,
|
|
43
43
|
useOffer: () => useOffer,
|
|
44
44
|
useOffers: () => useOffers,
|
|
45
|
+
useOrderHistory: () => useOrderHistory,
|
|
45
46
|
useOrders: () => useOrders,
|
|
47
|
+
useOwnedProduct: () => useOwnedProduct,
|
|
48
|
+
useOwnedProducts: () => useOwnedProducts,
|
|
46
49
|
usePrice: () => usePrice,
|
|
47
50
|
useProduct: () => useProduct,
|
|
51
|
+
useProductActivations: () => useProductActivations,
|
|
52
|
+
useProductLicenses: () => useProductLicenses,
|
|
48
53
|
useProducts: () => useProducts,
|
|
49
54
|
usePromotions: () => usePromotions,
|
|
50
55
|
useReviews: () => useReviews,
|
|
51
56
|
useStorefront: () => useStorefront,
|
|
52
57
|
useStorefrontEvent: () => useStorefrontEvent,
|
|
53
58
|
useStorefrontState: () => useStorefrontState,
|
|
59
|
+
useSubscription: () => useSubscription,
|
|
60
|
+
useSubscriptions: () => useSubscriptions,
|
|
54
61
|
useVendor: () => useVendor,
|
|
55
62
|
useVoucher: () => useVoucher
|
|
56
63
|
});
|
|
57
64
|
module.exports = __toCommonJS(index_exports);
|
|
58
|
-
var
|
|
65
|
+
var import_storefront_api13 = require("@moonbase.sh/storefront-api");
|
|
59
66
|
|
|
60
67
|
// package.json
|
|
61
|
-
var version = "0.0.0-next-
|
|
68
|
+
var version = "0.0.0-next-20261111171855";
|
|
62
69
|
|
|
63
70
|
// src/storefront.ts
|
|
64
71
|
var import_storefront_api5 = require("@moonbase.sh/storefront-api");
|
|
@@ -1403,12 +1410,132 @@ function useCartOffer() {
|
|
|
1403
1410
|
return (0, import_react2.useMemo)(() => cartOfferState(catalog, order), [catalog, order]);
|
|
1404
1411
|
}
|
|
1405
1412
|
|
|
1406
|
-
// src/hooks/
|
|
1413
|
+
// src/hooks/useAccountData.ts
|
|
1407
1414
|
var import_storefront_api7 = require("@moonbase.sh/storefront-api");
|
|
1408
1415
|
var import_react3 = require("react");
|
|
1416
|
+
var caches = /* @__PURE__ */ new WeakMap();
|
|
1417
|
+
function cacheOf(storefront) {
|
|
1418
|
+
var _a;
|
|
1419
|
+
let cache = caches.get(storefront);
|
|
1420
|
+
if (!cache) {
|
|
1421
|
+
const created = new import_storefront_api7.AccountDataCache();
|
|
1422
|
+
let customer = (_a = storefront.getState().user) == null ? void 0 : _a.id;
|
|
1423
|
+
storefront.subscribe(() => {
|
|
1424
|
+
var _a2;
|
|
1425
|
+
const now = (_a2 = storefront.getState().user) == null ? void 0 : _a2.id;
|
|
1426
|
+
if (now !== customer) {
|
|
1427
|
+
customer = now;
|
|
1428
|
+
created.clear();
|
|
1429
|
+
}
|
|
1430
|
+
});
|
|
1431
|
+
caches.set(storefront, created);
|
|
1432
|
+
cache = created;
|
|
1433
|
+
}
|
|
1434
|
+
return cache;
|
|
1435
|
+
}
|
|
1436
|
+
var nothing = { data: null, loading: false, error: null, hasMore: false, next: null };
|
|
1437
|
+
async function noop() {
|
|
1438
|
+
}
|
|
1439
|
+
function useEntry(resource) {
|
|
1440
|
+
const storefront = useStorefront();
|
|
1441
|
+
const cache = cacheOf(storefront);
|
|
1442
|
+
const customer = useStorefrontState((state) => {
|
|
1443
|
+
var _a, _b;
|
|
1444
|
+
return (_b = (_a = state.user) == null ? void 0 : _a.id) != null ? _b : null;
|
|
1445
|
+
});
|
|
1446
|
+
const userLoaded = useStorefrontState((state) => state.userLoaded);
|
|
1447
|
+
const key = customer && resource !== null ? `${customer}
|
|
1448
|
+
${resource}` : null;
|
|
1449
|
+
const entry = (0, import_react3.useSyncExternalStore)(
|
|
1450
|
+
cache.subscribe,
|
|
1451
|
+
() => {
|
|
1452
|
+
var _a;
|
|
1453
|
+
return (_a = key ? cache.get(key) : void 0) != null ? _a : nothing;
|
|
1454
|
+
},
|
|
1455
|
+
() => nothing
|
|
1456
|
+
);
|
|
1457
|
+
const pending = resource !== null && (customer ? entry === nothing : !userLoaded);
|
|
1458
|
+
return { storefront, cache, key, entry, pending };
|
|
1459
|
+
}
|
|
1460
|
+
function useAccountItem(kind, id, fetch) {
|
|
1461
|
+
const resource = id == null ? null : `${kind}
|
|
1462
|
+
${id}`;
|
|
1463
|
+
const { storefront, cache, key, entry, pending } = useEntry(resource);
|
|
1464
|
+
const reload = (0, import_react3.useCallback)(
|
|
1465
|
+
() => key && id != null ? cache.refresh(key, () => fetch(storefront.client, id)) : noop(),
|
|
1466
|
+
[cache, key, id, fetch, storefront]
|
|
1467
|
+
);
|
|
1468
|
+
(0, import_react3.useEffect)(() => {
|
|
1469
|
+
if (key)
|
|
1470
|
+
cache.ensure(key, reload);
|
|
1471
|
+
}, [cache, key, reload]);
|
|
1472
|
+
return (0, import_react3.useMemo)(() => ({
|
|
1473
|
+
data: entry.data,
|
|
1474
|
+
loading: entry.loading || pending,
|
|
1475
|
+
error: entry.error,
|
|
1476
|
+
reload
|
|
1477
|
+
}), [entry, pending, reload]);
|
|
1478
|
+
}
|
|
1479
|
+
function useAccountPages(kind, id, fetchPage) {
|
|
1480
|
+
const resource = id == null ? null : `${kind}
|
|
1481
|
+
${id}`;
|
|
1482
|
+
const { storefront, cache, key, entry, pending } = useEntry(resource);
|
|
1483
|
+
const reload = (0, import_react3.useCallback)(
|
|
1484
|
+
() => key && id != null ? cache.refreshPages(key, (next) => fetchPage(storefront.client, id, next)) : noop(),
|
|
1485
|
+
[cache, key, id, fetchPage, storefront]
|
|
1486
|
+
);
|
|
1487
|
+
const loadMore = (0, import_react3.useCallback)(
|
|
1488
|
+
() => key && id != null ? cache.loadMore(key, (next) => fetchPage(storefront.client, id, next)) : noop(),
|
|
1489
|
+
[cache, key, id, fetchPage, storefront]
|
|
1490
|
+
);
|
|
1491
|
+
(0, import_react3.useEffect)(() => {
|
|
1492
|
+
if (key)
|
|
1493
|
+
cache.ensure(key, reload);
|
|
1494
|
+
}, [cache, key, reload]);
|
|
1495
|
+
return (0, import_react3.useMemo)(() => ({
|
|
1496
|
+
data: entry.data,
|
|
1497
|
+
loading: entry.loading || pending,
|
|
1498
|
+
error: entry.error,
|
|
1499
|
+
hasMore: entry.hasMore,
|
|
1500
|
+
reload,
|
|
1501
|
+
loadMore
|
|
1502
|
+
}), [entry, pending, reload, loadMore]);
|
|
1503
|
+
}
|
|
1504
|
+
var ownedProducts = (client, _, next) => client.inventory.products.getOwned(next);
|
|
1505
|
+
var ownedProduct = (client, productId) => client.inventory.products.get(productId);
|
|
1506
|
+
var productActivations = (client, productId, next) => client.inventory.products.getActivations(productId, next);
|
|
1507
|
+
var productLicenses = (client, productId, next) => client.inventory.products.getLicenses(productId, next);
|
|
1508
|
+
var orderHistory = (client, _, next) => client.orders.getHistory(next);
|
|
1509
|
+
var subscriptions = (client, _, next) => client.inventory.subscriptions.get(next);
|
|
1510
|
+
var subscription = (client, subscriptionId) => client.inventory.subscriptions.getById(subscriptionId);
|
|
1511
|
+
function useOwnedProducts() {
|
|
1512
|
+
return useAccountPages("products", "", ownedProducts);
|
|
1513
|
+
}
|
|
1514
|
+
function useOwnedProduct(productId) {
|
|
1515
|
+
return useAccountItem("product", productId, ownedProduct);
|
|
1516
|
+
}
|
|
1517
|
+
function useProductActivations(productId) {
|
|
1518
|
+
return useAccountPages("product-activations", productId, productActivations);
|
|
1519
|
+
}
|
|
1520
|
+
function useProductLicenses(productId) {
|
|
1521
|
+
return useAccountPages("product-licenses", productId, productLicenses);
|
|
1522
|
+
}
|
|
1523
|
+
function useOrderHistory() {
|
|
1524
|
+
return useAccountPages("orders", "", orderHistory);
|
|
1525
|
+
}
|
|
1526
|
+
function useSubscriptions() {
|
|
1527
|
+
return useAccountPages("subscriptions", "", subscriptions);
|
|
1528
|
+
}
|
|
1529
|
+
function useSubscription(subscriptionId) {
|
|
1530
|
+
return useAccountItem("subscription", subscriptionId, subscription);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
// src/hooks/useActivationRequest.ts
|
|
1534
|
+
var import_storefront_api8 = require("@moonbase.sh/storefront-api");
|
|
1535
|
+
var import_react4 = require("react");
|
|
1409
1536
|
var pollInterval = 1500;
|
|
1410
1537
|
function errorMessage(err) {
|
|
1411
|
-
return err instanceof
|
|
1538
|
+
return err instanceof import_storefront_api8.NotAuthenticatedError ? "You need to be signed in to do this" : err.message;
|
|
1412
1539
|
}
|
|
1413
1540
|
function useActivationRequest(token, options = {}) {
|
|
1414
1541
|
var _a, _b, _c;
|
|
@@ -1417,18 +1544,18 @@ function useActivationRequest(token, options = {}) {
|
|
|
1417
1544
|
var _a2, _b2;
|
|
1418
1545
|
return (_b2 = (_a2 = state.user) == null ? void 0 : _a2.id) != null ? _b2 : null;
|
|
1419
1546
|
});
|
|
1420
|
-
const [activationRequest, setActivationRequest] = (0,
|
|
1421
|
-
const [fetched, setFetched] = (0,
|
|
1422
|
-
const [fulfilling, setFulfilling] = (0,
|
|
1423
|
-
const [completing, setCompleting] = (0,
|
|
1424
|
-
const [error, setError] = (0,
|
|
1425
|
-
const adopt = (0,
|
|
1547
|
+
const [activationRequest, setActivationRequest] = (0, import_react4.useState)(null);
|
|
1548
|
+
const [fetched, setFetched] = (0, import_react4.useState)(null);
|
|
1549
|
+
const [fulfilling, setFulfilling] = (0, import_react4.useState)(false);
|
|
1550
|
+
const [completing, setCompleting] = (0, import_react4.useState)(false);
|
|
1551
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
1552
|
+
const adopt = (0, import_react4.useCallback)((request) => {
|
|
1426
1553
|
setActivationRequest(request);
|
|
1427
|
-
if (request.status ===
|
|
1554
|
+
if (request.status === import_storefront_api8.ActivationRequestStatus.Fulfilled)
|
|
1428
1555
|
setCompleting(true);
|
|
1429
1556
|
}, []);
|
|
1430
1557
|
const upToDate = !!token && (fetched == null ? void 0 : fetched.token) === token && (fetched.userId === userId || !!((_a = activationRequest == null ? void 0 : activationRequest.licenseEligibility) == null ? void 0 : _a.eligible));
|
|
1431
|
-
(0,
|
|
1558
|
+
(0, import_react4.useEffect)(() => {
|
|
1432
1559
|
if (!token || upToDate)
|
|
1433
1560
|
return;
|
|
1434
1561
|
let current = true;
|
|
@@ -1438,7 +1565,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1438
1565
|
};
|
|
1439
1566
|
}, [storefront, token, userId, upToDate, adopt]);
|
|
1440
1567
|
const requestId = activationRequest == null ? void 0 : activationRequest.id;
|
|
1441
|
-
(0,
|
|
1568
|
+
(0, import_react4.useEffect)(() => {
|
|
1442
1569
|
if (!completing || !requestId)
|
|
1443
1570
|
return;
|
|
1444
1571
|
let current = true;
|
|
@@ -1449,7 +1576,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1449
1576
|
if (!current)
|
|
1450
1577
|
return;
|
|
1451
1578
|
if (completed) {
|
|
1452
|
-
setActivationRequest((request) => request && { ...request, status:
|
|
1579
|
+
setActivationRequest((request) => request && { ...request, status: import_storefront_api8.ActivationRequestStatus.Completed });
|
|
1453
1580
|
setCompleting(false);
|
|
1454
1581
|
return;
|
|
1455
1582
|
}
|
|
@@ -1465,7 +1592,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1465
1592
|
clearTimeout(timeout);
|
|
1466
1593
|
};
|
|
1467
1594
|
}, [storefront, completing, requestId]);
|
|
1468
|
-
const fulfillLicense = (0,
|
|
1595
|
+
const fulfillLicense = (0, import_react4.useCallback)(async () => {
|
|
1469
1596
|
if (!requestId)
|
|
1470
1597
|
return;
|
|
1471
1598
|
setError(null);
|
|
@@ -1477,7 +1604,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1477
1604
|
setFulfilling(false);
|
|
1478
1605
|
}
|
|
1479
1606
|
}, [storefront, requestId, adopt]);
|
|
1480
|
-
const fulfillTrial = (0,
|
|
1607
|
+
const fulfillTrial = (0, import_react4.useCallback)(async (newsletterOptIn = false) => {
|
|
1481
1608
|
if (!requestId)
|
|
1482
1609
|
return;
|
|
1483
1610
|
setError(null);
|
|
@@ -1501,9 +1628,9 @@ function useActivationRequest(token, options = {}) {
|
|
|
1501
1628
|
}
|
|
1502
1629
|
}, [storefront, requestId, adopt]);
|
|
1503
1630
|
const autoFulfill = (_b = options.autoFulfill) != null ? _b : false;
|
|
1504
|
-
const autoFulfilled = (0,
|
|
1505
|
-
const eligible = (activationRequest == null ? void 0 : activationRequest.status) ===
|
|
1506
|
-
(0,
|
|
1631
|
+
const autoFulfilled = (0, import_react4.useRef)(null);
|
|
1632
|
+
const eligible = (activationRequest == null ? void 0 : activationRequest.status) === import_storefront_api8.ActivationRequestStatus.Requested && !!((_c = activationRequest.licenseEligibility) == null ? void 0 : _c.eligible);
|
|
1633
|
+
(0, import_react4.useEffect)(() => {
|
|
1507
1634
|
if (!autoFulfill || !eligible || !requestId || autoFulfilled.current === requestId)
|
|
1508
1635
|
return;
|
|
1509
1636
|
autoFulfilled.current = requestId;
|
|
@@ -1512,8 +1639,8 @@ function useActivationRequest(token, options = {}) {
|
|
|
1512
1639
|
setError(errorMessage(err));
|
|
1513
1640
|
});
|
|
1514
1641
|
}, [autoFulfill, eligible, requestId, fulfillLicense]);
|
|
1515
|
-
const cancel = (0,
|
|
1516
|
-
if (!activationRequest || activationRequest.status ===
|
|
1642
|
+
const cancel = (0, import_react4.useCallback)(async () => {
|
|
1643
|
+
if (!activationRequest || activationRequest.status === import_storefront_api8.ActivationRequestStatus.Cancelled)
|
|
1517
1644
|
return;
|
|
1518
1645
|
adopt(await storefront.client.activationRequests.cancel(activationRequest.id));
|
|
1519
1646
|
}, [storefront, activationRequest, adopt]);
|
|
@@ -1523,7 +1650,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1523
1650
|
fulfilling,
|
|
1524
1651
|
completing,
|
|
1525
1652
|
error,
|
|
1526
|
-
isInstalled: (activationRequest == null ? void 0 : activationRequest.status) ===
|
|
1653
|
+
isInstalled: (activationRequest == null ? void 0 : activationRequest.status) === import_storefront_api8.ActivationRequestStatus.Completed,
|
|
1527
1654
|
fulfillLicense,
|
|
1528
1655
|
fulfillTrial,
|
|
1529
1656
|
cancel
|
|
@@ -1531,29 +1658,29 @@ function useActivationRequest(token, options = {}) {
|
|
|
1531
1658
|
}
|
|
1532
1659
|
|
|
1533
1660
|
// src/hooks/useAuth.ts
|
|
1534
|
-
var
|
|
1661
|
+
var import_react5 = require("react");
|
|
1535
1662
|
function useAuth() {
|
|
1536
1663
|
const storefront = useStorefront();
|
|
1537
1664
|
const user = useStorefrontState((state) => state.user);
|
|
1538
1665
|
const loaded = useStorefrontState((state) => state.userLoaded);
|
|
1539
|
-
return (0,
|
|
1666
|
+
return (0, import_react5.useMemo)(() => ({ ...storefront.auth, user, loaded }), [storefront, user, loaded]);
|
|
1540
1667
|
}
|
|
1541
1668
|
|
|
1542
1669
|
// src/hooks/useCart.ts
|
|
1543
|
-
var
|
|
1544
|
-
var
|
|
1670
|
+
var import_storefront_api9 = require("@moonbase.sh/storefront-api");
|
|
1671
|
+
var import_react6 = require("react");
|
|
1545
1672
|
function useCart() {
|
|
1546
1673
|
const storefront = useStorefront();
|
|
1547
1674
|
const catalog = useStorefrontState((state) => state.catalog);
|
|
1548
1675
|
const order = useStorefrontState((state) => state.order);
|
|
1549
|
-
return (0,
|
|
1550
|
-
const currency = (0,
|
|
1551
|
-
const breakdown =
|
|
1676
|
+
return (0, import_react6.useMemo)(() => {
|
|
1677
|
+
const currency = (0, import_storefront_api9.resolveDisplayCurrency)(order, catalog);
|
|
1678
|
+
const breakdown = import_storefront_api9.CartUtils.total(catalog, order, currency);
|
|
1552
1679
|
const items = enrichLineItems(catalog, order);
|
|
1553
1680
|
return {
|
|
1554
1681
|
...storefront.cart,
|
|
1555
1682
|
items,
|
|
1556
|
-
soldOutItems: items.filter((item) =>
|
|
1683
|
+
soldOutItems: items.filter((item) => import_storefront_api9.CartUtils.isSoldOut(catalog, item)),
|
|
1557
1684
|
currency,
|
|
1558
1685
|
total: { amount: breakdown.amount, currency: breakdown.currency },
|
|
1559
1686
|
breakdown,
|
|
@@ -1562,24 +1689,24 @@ function useCart() {
|
|
|
1562
1689
|
}, [storefront, catalog, order]);
|
|
1563
1690
|
}
|
|
1564
1691
|
function useCurrency() {
|
|
1565
|
-
return useStorefrontState((state) => (0,
|
|
1692
|
+
return useStorefrontState((state) => (0, import_storefront_api9.resolveDisplayCurrency)(state.order, state.catalog));
|
|
1566
1693
|
}
|
|
1567
1694
|
function useCartActions() {
|
|
1568
1695
|
return useStorefront().cart;
|
|
1569
1696
|
}
|
|
1570
1697
|
|
|
1571
1698
|
// src/hooks/useCheckout.ts
|
|
1572
|
-
var
|
|
1699
|
+
var import_react7 = require("react");
|
|
1573
1700
|
function useCheckout() {
|
|
1574
1701
|
const storefront = useStorefront();
|
|
1575
|
-
return (0,
|
|
1702
|
+
return (0, import_react7.useCallback)((items, options) => storefront.checkout(items, options), [storefront]);
|
|
1576
1703
|
}
|
|
1577
1704
|
|
|
1578
1705
|
// src/hooks/useCommunicationPreferences.ts
|
|
1579
|
-
var
|
|
1706
|
+
var import_react8 = require("react");
|
|
1580
1707
|
function useCommunicationPreferences() {
|
|
1581
1708
|
const storefront = useStorefront();
|
|
1582
|
-
return (0,
|
|
1709
|
+
return (0, import_react8.useMemo)(() => {
|
|
1583
1710
|
const communications = storefront.client.communications;
|
|
1584
1711
|
return {
|
|
1585
1712
|
subscribe: (input) => communications.subscribe(input, storefront.adSignals()),
|
|
@@ -1592,17 +1719,17 @@ function useCommunicationPreferences() {
|
|
|
1592
1719
|
}
|
|
1593
1720
|
|
|
1594
1721
|
// src/hooks/useGroups.ts
|
|
1595
|
-
var
|
|
1722
|
+
var import_react9 = require("react");
|
|
1596
1723
|
function useGroups() {
|
|
1597
1724
|
const storefront = useStorefront();
|
|
1598
|
-
return (0,
|
|
1725
|
+
return (0, import_react9.useMemo)(() => ({ join: (groupId) => storefront.client.groups.join(groupId) }), [storefront]);
|
|
1599
1726
|
}
|
|
1600
1727
|
|
|
1601
1728
|
// src/hooks/useInventory.ts
|
|
1602
|
-
var
|
|
1729
|
+
var import_react10 = require("react");
|
|
1603
1730
|
|
|
1604
1731
|
// src/inventory.ts
|
|
1605
|
-
var
|
|
1732
|
+
var import_storefront_api10 = require("@moonbase.sh/storefront-api");
|
|
1606
1733
|
function createInventory(storefront) {
|
|
1607
1734
|
const inventory = storefront.client.inventory;
|
|
1608
1735
|
return {
|
|
@@ -1629,23 +1756,23 @@ function createInventory(storefront) {
|
|
|
1629
1756
|
renewSubscription: async (subscriptionId, options = {}) => {
|
|
1630
1757
|
if (checkoutInProgress())
|
|
1631
1758
|
return waitForCheckoutClose();
|
|
1632
|
-
const redirect = (0,
|
|
1759
|
+
const redirect = (0, import_storefront_api10.resolveRedirect)(options.redirect);
|
|
1633
1760
|
const { location: url } = await inventory.subscriptions.renew(subscriptionId, checkoutReturnUrl(options.returnUrl), !redirect);
|
|
1634
1761
|
if (redirect) {
|
|
1635
|
-
window.location.href = (0,
|
|
1762
|
+
window.location.href = (0, import_storefront_api10.withPriceFormat)(url);
|
|
1636
1763
|
return { next: void 0, completed: false, redirected: true };
|
|
1637
1764
|
}
|
|
1638
1765
|
const closed = waitForCheckoutClose();
|
|
1639
|
-
(0,
|
|
1766
|
+
(0, import_storefront_api10.mountCheckout)(url);
|
|
1640
1767
|
return closed;
|
|
1641
1768
|
},
|
|
1642
|
-
updateSubscriptionPaymentMethod: async (
|
|
1643
|
-
const response = await inventory.subscriptions.getById(
|
|
1769
|
+
updateSubscriptionPaymentMethod: async (subscription2, options = {}) => {
|
|
1770
|
+
const response = await inventory.subscriptions.getById(subscription2.id, {
|
|
1644
1771
|
toUpdatePaymentMethod: true,
|
|
1645
1772
|
returnUrl: checkoutReturnUrl(options.returnUrl)
|
|
1646
1773
|
});
|
|
1647
1774
|
window.dispatchEvent(new CustomEvent("moonbase-subscription-payment-method-update-initiated", {
|
|
1648
|
-
detail: { subscription }
|
|
1775
|
+
detail: { subscription: subscription2 }
|
|
1649
1776
|
}));
|
|
1650
1777
|
const url = response.embeddedUpdatePaymentUrl;
|
|
1651
1778
|
if (!url)
|
|
@@ -1654,7 +1781,7 @@ function createInventory(storefront) {
|
|
|
1654
1781
|
window.addEventListener("moonbase-subscription-closed", (event) => {
|
|
1655
1782
|
resolve({ completed: event.detail.completed });
|
|
1656
1783
|
}, { once: true });
|
|
1657
|
-
(0,
|
|
1784
|
+
(0, import_storefront_api10.mountSubscription)(url);
|
|
1658
1785
|
});
|
|
1659
1786
|
}
|
|
1660
1787
|
};
|
|
@@ -1663,14 +1790,14 @@ function createInventory(storefront) {
|
|
|
1663
1790
|
// src/hooks/useInventory.ts
|
|
1664
1791
|
function useInventory() {
|
|
1665
1792
|
const storefront = useStorefront();
|
|
1666
|
-
return (0,
|
|
1793
|
+
return (0, import_react10.useMemo)(() => createInventory(storefront), [storefront]);
|
|
1667
1794
|
}
|
|
1668
1795
|
|
|
1669
1796
|
// src/hooks/useOrders.ts
|
|
1670
|
-
var
|
|
1797
|
+
var import_react11 = require("react");
|
|
1671
1798
|
function useOrders() {
|
|
1672
1799
|
const storefront = useStorefront();
|
|
1673
|
-
return (0,
|
|
1800
|
+
return (0, import_react11.useMemo)(() => ({
|
|
1674
1801
|
getOrders: (nextUrl) => storefront.client.orders.getHistory(nextUrl),
|
|
1675
1802
|
getReceipt: (order) => storefront.client.orders.getReceipt(order.id),
|
|
1676
1803
|
downloadReceipt: async (order) => {
|
|
@@ -1688,30 +1815,30 @@ function useOrders() {
|
|
|
1688
1815
|
}
|
|
1689
1816
|
|
|
1690
1817
|
// src/hooks/usePrice.ts
|
|
1691
|
-
var
|
|
1692
|
-
var
|
|
1818
|
+
var import_storefront_api11 = require("@moonbase.sh/storefront-api");
|
|
1819
|
+
var import_react12 = require("react");
|
|
1693
1820
|
function usePrice(variation, format) {
|
|
1694
1821
|
const currency = useCurrency();
|
|
1695
|
-
return (0,
|
|
1822
|
+
return (0, import_react12.useMemo)(() => {
|
|
1696
1823
|
const amount = variation == null ? void 0 : variation.price[currency];
|
|
1697
1824
|
const original = (variation == null ? void 0 : variation.hasDiscount) ? variation.originalPrice[currency] : void 0;
|
|
1698
1825
|
const saving = amount !== void 0 && original !== void 0 ? Number((original - amount).toFixed(6)) : void 0;
|
|
1699
1826
|
return {
|
|
1700
1827
|
currency,
|
|
1701
|
-
price: amount === void 0 ? void 0 : (0,
|
|
1702
|
-
originalPrice: original === void 0 ? void 0 : (0,
|
|
1703
|
-
saving: saving === void 0 || saving <= 0 ? void 0 : (0,
|
|
1828
|
+
price: amount === void 0 ? void 0 : (0, import_storefront_api11.formatMoney)(amount, currency, format),
|
|
1829
|
+
originalPrice: original === void 0 ? void 0 : (0, import_storefront_api11.formatMoney)(original, currency, format),
|
|
1830
|
+
saving: saving === void 0 || saving <= 0 ? void 0 : (0, import_storefront_api11.formatMoney)(saving, currency, format),
|
|
1704
1831
|
amount
|
|
1705
1832
|
};
|
|
1706
1833
|
}, [variation, currency, format]);
|
|
1707
1834
|
}
|
|
1708
1835
|
|
|
1709
1836
|
// src/hooks/useReviews.ts
|
|
1710
|
-
var
|
|
1837
|
+
var import_react13 = require("react");
|
|
1711
1838
|
function useReviews() {
|
|
1712
1839
|
const storefront = useStorefront();
|
|
1713
1840
|
const enabled = useStorefrontState((state) => !!state.catalog.reviewsEnabled);
|
|
1714
|
-
return (0,
|
|
1841
|
+
return (0, import_react13.useMemo)(() => {
|
|
1715
1842
|
const reviews = storefront.client.reviews;
|
|
1716
1843
|
return {
|
|
1717
1844
|
enabled,
|
|
@@ -1726,11 +1853,11 @@ function useReviews() {
|
|
|
1726
1853
|
}
|
|
1727
1854
|
|
|
1728
1855
|
// src/hooks/useVendor.ts
|
|
1729
|
-
var
|
|
1856
|
+
var import_react14 = require("react");
|
|
1730
1857
|
function useVendor() {
|
|
1731
1858
|
const storefront = useStorefront();
|
|
1732
|
-
const [state, setState] = (0,
|
|
1733
|
-
(0,
|
|
1859
|
+
const [state, setState] = (0, import_react14.useState)({ vendor: null, loading: true });
|
|
1860
|
+
(0, import_react14.useEffect)(() => {
|
|
1734
1861
|
let current = true;
|
|
1735
1862
|
storefront.client.vendor.get().then((vendor) => current && setState({ vendor, loading: false })).catch(() => current && setState({ vendor: null, loading: false }));
|
|
1736
1863
|
return () => {
|
|
@@ -1741,16 +1868,16 @@ function useVendor() {
|
|
|
1741
1868
|
}
|
|
1742
1869
|
|
|
1743
1870
|
// src/hooks/useVoucher.ts
|
|
1744
|
-
var
|
|
1745
|
-
var
|
|
1871
|
+
var import_storefront_api12 = require("@moonbase.sh/storefront-api");
|
|
1872
|
+
var import_react15 = require("react");
|
|
1746
1873
|
function useVoucher() {
|
|
1747
1874
|
const storefront = useStorefront();
|
|
1748
|
-
return (0,
|
|
1875
|
+
return (0, import_react15.useMemo)(() => {
|
|
1749
1876
|
const known = async (lookup) => {
|
|
1750
1877
|
try {
|
|
1751
1878
|
return await lookup;
|
|
1752
1879
|
} catch (err) {
|
|
1753
|
-
if (err instanceof
|
|
1880
|
+
if (err instanceof import_storefront_api12.NotFoundError)
|
|
1754
1881
|
throw new Error("Voucher code invalid");
|
|
1755
1882
|
throw err;
|
|
1756
1883
|
}
|
|
@@ -1773,7 +1900,7 @@ function createStorefront(endpoint, options = {}) {
|
|
|
1773
1900
|
// Named in `x-mb-client` ahead of `@moonbase.sh/storefront-api`, after any SDK wrapping this one.
|
|
1774
1901
|
sdk: `${(_a = config.sdk) != null ? _a : ""} @moonbase.sh/react/${version}`.trim().replace(/\s+/g, " ")
|
|
1775
1902
|
};
|
|
1776
|
-
return new MoonbaseStorefront(configuration, new
|
|
1903
|
+
return new MoonbaseStorefront(configuration, new import_storefront_api13.MoonbaseClient(configuration), { initialCatalog, autoApplyItemOffers });
|
|
1777
1904
|
}
|
|
1778
1905
|
var browserStorefronts = /* @__PURE__ */ new Map();
|
|
1779
1906
|
function getStorefront(endpoint, options = {}) {
|
|
@@ -1809,15 +1936,22 @@ function getStorefront(endpoint, options = {}) {
|
|
|
1809
1936
|
useLockedOffers,
|
|
1810
1937
|
useOffer,
|
|
1811
1938
|
useOffers,
|
|
1939
|
+
useOrderHistory,
|
|
1812
1940
|
useOrders,
|
|
1941
|
+
useOwnedProduct,
|
|
1942
|
+
useOwnedProducts,
|
|
1813
1943
|
usePrice,
|
|
1814
1944
|
useProduct,
|
|
1945
|
+
useProductActivations,
|
|
1946
|
+
useProductLicenses,
|
|
1815
1947
|
useProducts,
|
|
1816
1948
|
usePromotions,
|
|
1817
1949
|
useReviews,
|
|
1818
1950
|
useStorefront,
|
|
1819
1951
|
useStorefrontEvent,
|
|
1820
1952
|
useStorefrontState,
|
|
1953
|
+
useSubscription,
|
|
1954
|
+
useSubscriptions,
|
|
1821
1955
|
useVendor,
|
|
1822
1956
|
useVoucher,
|
|
1823
1957
|
...require("@moonbase.sh/storefront-api")
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput,
|
|
1
|
+
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, ActivationMethod, Download, SubscriptionCancellationFeedback, Page, PriceFormat, ProductReviewSort, SubmitReviewRequest, ReviewVoteDirection, Vendor, Voucher } from '@moonbase.sh/storefront-api';
|
|
2
2
|
export * from '@moonbase.sh/storefront-api';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
@@ -497,6 +497,50 @@ declare function useLockedOffers(): LockedOffer[];
|
|
|
497
497
|
/** What the cart's offer meter shows: the cart offer the buyer has earned, the next one to reach, or both. */
|
|
498
498
|
declare function useCartOffer(): CartOfferState | null;
|
|
499
499
|
|
|
500
|
+
/** Part of the signed-in customer's account, as a hook loads it. */
|
|
501
|
+
interface AccountData<T> {
|
|
502
|
+
/**
|
|
503
|
+
* The data, or null: while it loads, with nobody signed in, and for no ID. A component that mounts
|
|
504
|
+
* again gets what was loaded before at once, and the hook asks for it again in the background.
|
|
505
|
+
*/
|
|
506
|
+
data: T | null;
|
|
507
|
+
/**
|
|
508
|
+
* Whether it is loading: while a request is in flight, a background refresh of `data` included, and
|
|
509
|
+
* until the storefront knows who is signed in. Show a placeholder while this is true and `data` is null.
|
|
510
|
+
*/
|
|
511
|
+
loading: boolean;
|
|
512
|
+
/** Why the last request failed, until one succeeds. */
|
|
513
|
+
error: Error | null;
|
|
514
|
+
/** Asks for it again, as after changing it. Settles once the answer is in, and never rejects. */
|
|
515
|
+
reload: () => Promise<void>;
|
|
516
|
+
}
|
|
517
|
+
/** A list in the signed-in customer's account, which Moonbase hands out a page at a time. */
|
|
518
|
+
interface PagedAccountData<T> extends AccountData<T[]> {
|
|
519
|
+
/**
|
|
520
|
+
* Every item loaded so far, or null. `reload` goes back to the first page. A page can hold more items
|
|
521
|
+
* than Moonbase's page size, so count what is here rather than pages.
|
|
522
|
+
*/
|
|
523
|
+
data: T[] | null;
|
|
524
|
+
/** Whether Moonbase has more after what is loaded. */
|
|
525
|
+
hasMore: boolean;
|
|
526
|
+
/** Adds the next page to `data`. Settles once it is in, and never rejects. */
|
|
527
|
+
loadMore: () => Promise<void>;
|
|
528
|
+
}
|
|
529
|
+
/** The products the signed-in customer owns, or has a trial of, a page at a time. */
|
|
530
|
+
declare function useOwnedProducts(): PagedAccountData<OwnedProduct>;
|
|
531
|
+
/** One product the signed-in customer owns, with its downloads. Null for no ID. */
|
|
532
|
+
declare function useOwnedProduct(productId: string | null | undefined): AccountData<OwnedProduct>;
|
|
533
|
+
/** The computers the signed-in customer's licenses for a product are activated on, a page at a time. */
|
|
534
|
+
declare function useProductActivations(productId: string | null | undefined): PagedAccountData<Activation>;
|
|
535
|
+
/** The signed-in customer's licenses for a product, a page at a time. */
|
|
536
|
+
declare function useProductLicenses(productId: string | null | undefined): PagedAccountData<License>;
|
|
537
|
+
/** The signed-in customer's completed orders, newest first, a page at a time. */
|
|
538
|
+
declare function useOrderHistory(): PagedAccountData<CompletedOrder>;
|
|
539
|
+
/** The signed-in customer's subscriptions, a page at a time. */
|
|
540
|
+
declare function useSubscriptions(): PagedAccountData<Subscription>;
|
|
541
|
+
/** One of the signed-in customer's subscriptions. Null for no ID. */
|
|
542
|
+
declare function useSubscription(subscriptionId: string | null | undefined): AccountData<Subscription>;
|
|
543
|
+
|
|
500
544
|
interface ActivationRequestState {
|
|
501
545
|
/** The request the app on the customer's computer made, or null until it has loaded. */
|
|
502
546
|
activationRequest: ActivationRequest | null;
|
|
@@ -810,4 +854,4 @@ declare function createStorefront(endpoint: string, options?: StorefrontOptions)
|
|
|
810
854
|
*/
|
|
811
855
|
declare function getStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
|
|
812
856
|
|
|
813
|
-
export { type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrders, usePrice, useProduct, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useVendor, useVoucher };
|
|
857
|
+
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type PagedAccountData, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrderHistory, useOrders, useOwnedProduct, useOwnedProducts, usePrice, useProduct, useProductActivations, useProductLicenses, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useSubscription, useSubscriptions, useVendor, useVoucher };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput,
|
|
1
|
+
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, Storefront, MoonbaseClient, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, ActivationMethod, Download, SubscriptionCancellationFeedback, Page, PriceFormat, ProductReviewSort, SubmitReviewRequest, ReviewVoteDirection, Vendor, Voucher } from '@moonbase.sh/storefront-api';
|
|
2
2
|
export * from '@moonbase.sh/storefront-api';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
@@ -497,6 +497,50 @@ declare function useLockedOffers(): LockedOffer[];
|
|
|
497
497
|
/** What the cart's offer meter shows: the cart offer the buyer has earned, the next one to reach, or both. */
|
|
498
498
|
declare function useCartOffer(): CartOfferState | null;
|
|
499
499
|
|
|
500
|
+
/** Part of the signed-in customer's account, as a hook loads it. */
|
|
501
|
+
interface AccountData<T> {
|
|
502
|
+
/**
|
|
503
|
+
* The data, or null: while it loads, with nobody signed in, and for no ID. A component that mounts
|
|
504
|
+
* again gets what was loaded before at once, and the hook asks for it again in the background.
|
|
505
|
+
*/
|
|
506
|
+
data: T | null;
|
|
507
|
+
/**
|
|
508
|
+
* Whether it is loading: while a request is in flight, a background refresh of `data` included, and
|
|
509
|
+
* until the storefront knows who is signed in. Show a placeholder while this is true and `data` is null.
|
|
510
|
+
*/
|
|
511
|
+
loading: boolean;
|
|
512
|
+
/** Why the last request failed, until one succeeds. */
|
|
513
|
+
error: Error | null;
|
|
514
|
+
/** Asks for it again, as after changing it. Settles once the answer is in, and never rejects. */
|
|
515
|
+
reload: () => Promise<void>;
|
|
516
|
+
}
|
|
517
|
+
/** A list in the signed-in customer's account, which Moonbase hands out a page at a time. */
|
|
518
|
+
interface PagedAccountData<T> extends AccountData<T[]> {
|
|
519
|
+
/**
|
|
520
|
+
* Every item loaded so far, or null. `reload` goes back to the first page. A page can hold more items
|
|
521
|
+
* than Moonbase's page size, so count what is here rather than pages.
|
|
522
|
+
*/
|
|
523
|
+
data: T[] | null;
|
|
524
|
+
/** Whether Moonbase has more after what is loaded. */
|
|
525
|
+
hasMore: boolean;
|
|
526
|
+
/** Adds the next page to `data`. Settles once it is in, and never rejects. */
|
|
527
|
+
loadMore: () => Promise<void>;
|
|
528
|
+
}
|
|
529
|
+
/** The products the signed-in customer owns, or has a trial of, a page at a time. */
|
|
530
|
+
declare function useOwnedProducts(): PagedAccountData<OwnedProduct>;
|
|
531
|
+
/** One product the signed-in customer owns, with its downloads. Null for no ID. */
|
|
532
|
+
declare function useOwnedProduct(productId: string | null | undefined): AccountData<OwnedProduct>;
|
|
533
|
+
/** The computers the signed-in customer's licenses for a product are activated on, a page at a time. */
|
|
534
|
+
declare function useProductActivations(productId: string | null | undefined): PagedAccountData<Activation>;
|
|
535
|
+
/** The signed-in customer's licenses for a product, a page at a time. */
|
|
536
|
+
declare function useProductLicenses(productId: string | null | undefined): PagedAccountData<License>;
|
|
537
|
+
/** The signed-in customer's completed orders, newest first, a page at a time. */
|
|
538
|
+
declare function useOrderHistory(): PagedAccountData<CompletedOrder>;
|
|
539
|
+
/** The signed-in customer's subscriptions, a page at a time. */
|
|
540
|
+
declare function useSubscriptions(): PagedAccountData<Subscription>;
|
|
541
|
+
/** One of the signed-in customer's subscriptions. Null for no ID. */
|
|
542
|
+
declare function useSubscription(subscriptionId: string | null | undefined): AccountData<Subscription>;
|
|
543
|
+
|
|
500
544
|
interface ActivationRequestState {
|
|
501
545
|
/** The request the app on the customer's computer made, or null until it has loaded. */
|
|
502
546
|
activationRequest: ActivationRequest | null;
|
|
@@ -810,4 +854,4 @@ declare function createStorefront(endpoint: string, options?: StorefrontOptions)
|
|
|
810
854
|
*/
|
|
811
855
|
declare function getStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
|
|
812
856
|
|
|
813
|
-
export { type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrders, usePrice, useProduct, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useVendor, useVoucher };
|
|
857
|
+
export { type AccountData, type ActivationRequestOptions, type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type PagedAccountData, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VariationPrice, type VendorState, type Vouchers, createStorefront, getStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartActions, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useCurrency, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrderHistory, useOrders, useOwnedProduct, useOwnedProducts, usePrice, useProduct, useProductActivations, useProductLicenses, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useSubscription, useSubscriptions, useVendor, useVoucher };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { MoonbaseClient } from "@moonbase.sh/storefront-api";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "0.0.0-next-
|
|
5
|
+
var version = "0.0.0-next-20261111171855";
|
|
6
6
|
|
|
7
7
|
// src/storefront.ts
|
|
8
8
|
import {
|
|
@@ -1414,9 +1414,129 @@ function useCartOffer() {
|
|
|
1414
1414
|
return useMemo(() => cartOfferState(catalog, order), [catalog, order]);
|
|
1415
1415
|
}
|
|
1416
1416
|
|
|
1417
|
+
// src/hooks/useAccountData.ts
|
|
1418
|
+
import { AccountDataCache } from "@moonbase.sh/storefront-api";
|
|
1419
|
+
import { useCallback, useEffect as useEffect2, useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
1420
|
+
var caches = /* @__PURE__ */ new WeakMap();
|
|
1421
|
+
function cacheOf(storefront) {
|
|
1422
|
+
var _a;
|
|
1423
|
+
let cache = caches.get(storefront);
|
|
1424
|
+
if (!cache) {
|
|
1425
|
+
const created = new AccountDataCache();
|
|
1426
|
+
let customer = (_a = storefront.getState().user) == null ? void 0 : _a.id;
|
|
1427
|
+
storefront.subscribe(() => {
|
|
1428
|
+
var _a2;
|
|
1429
|
+
const now = (_a2 = storefront.getState().user) == null ? void 0 : _a2.id;
|
|
1430
|
+
if (now !== customer) {
|
|
1431
|
+
customer = now;
|
|
1432
|
+
created.clear();
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
caches.set(storefront, created);
|
|
1436
|
+
cache = created;
|
|
1437
|
+
}
|
|
1438
|
+
return cache;
|
|
1439
|
+
}
|
|
1440
|
+
var nothing = { data: null, loading: false, error: null, hasMore: false, next: null };
|
|
1441
|
+
async function noop() {
|
|
1442
|
+
}
|
|
1443
|
+
function useEntry(resource) {
|
|
1444
|
+
const storefront = useStorefront();
|
|
1445
|
+
const cache = cacheOf(storefront);
|
|
1446
|
+
const customer = useStorefrontState((state) => {
|
|
1447
|
+
var _a, _b;
|
|
1448
|
+
return (_b = (_a = state.user) == null ? void 0 : _a.id) != null ? _b : null;
|
|
1449
|
+
});
|
|
1450
|
+
const userLoaded = useStorefrontState((state) => state.userLoaded);
|
|
1451
|
+
const key = customer && resource !== null ? `${customer}
|
|
1452
|
+
${resource}` : null;
|
|
1453
|
+
const entry = useSyncExternalStore2(
|
|
1454
|
+
cache.subscribe,
|
|
1455
|
+
() => {
|
|
1456
|
+
var _a;
|
|
1457
|
+
return (_a = key ? cache.get(key) : void 0) != null ? _a : nothing;
|
|
1458
|
+
},
|
|
1459
|
+
() => nothing
|
|
1460
|
+
);
|
|
1461
|
+
const pending = resource !== null && (customer ? entry === nothing : !userLoaded);
|
|
1462
|
+
return { storefront, cache, key, entry, pending };
|
|
1463
|
+
}
|
|
1464
|
+
function useAccountItem(kind, id, fetch) {
|
|
1465
|
+
const resource = id == null ? null : `${kind}
|
|
1466
|
+
${id}`;
|
|
1467
|
+
const { storefront, cache, key, entry, pending } = useEntry(resource);
|
|
1468
|
+
const reload = useCallback(
|
|
1469
|
+
() => key && id != null ? cache.refresh(key, () => fetch(storefront.client, id)) : noop(),
|
|
1470
|
+
[cache, key, id, fetch, storefront]
|
|
1471
|
+
);
|
|
1472
|
+
useEffect2(() => {
|
|
1473
|
+
if (key)
|
|
1474
|
+
cache.ensure(key, reload);
|
|
1475
|
+
}, [cache, key, reload]);
|
|
1476
|
+
return useMemo2(() => ({
|
|
1477
|
+
data: entry.data,
|
|
1478
|
+
loading: entry.loading || pending,
|
|
1479
|
+
error: entry.error,
|
|
1480
|
+
reload
|
|
1481
|
+
}), [entry, pending, reload]);
|
|
1482
|
+
}
|
|
1483
|
+
function useAccountPages(kind, id, fetchPage) {
|
|
1484
|
+
const resource = id == null ? null : `${kind}
|
|
1485
|
+
${id}`;
|
|
1486
|
+
const { storefront, cache, key, entry, pending } = useEntry(resource);
|
|
1487
|
+
const reload = useCallback(
|
|
1488
|
+
() => key && id != null ? cache.refreshPages(key, (next) => fetchPage(storefront.client, id, next)) : noop(),
|
|
1489
|
+
[cache, key, id, fetchPage, storefront]
|
|
1490
|
+
);
|
|
1491
|
+
const loadMore = useCallback(
|
|
1492
|
+
() => key && id != null ? cache.loadMore(key, (next) => fetchPage(storefront.client, id, next)) : noop(),
|
|
1493
|
+
[cache, key, id, fetchPage, storefront]
|
|
1494
|
+
);
|
|
1495
|
+
useEffect2(() => {
|
|
1496
|
+
if (key)
|
|
1497
|
+
cache.ensure(key, reload);
|
|
1498
|
+
}, [cache, key, reload]);
|
|
1499
|
+
return useMemo2(() => ({
|
|
1500
|
+
data: entry.data,
|
|
1501
|
+
loading: entry.loading || pending,
|
|
1502
|
+
error: entry.error,
|
|
1503
|
+
hasMore: entry.hasMore,
|
|
1504
|
+
reload,
|
|
1505
|
+
loadMore
|
|
1506
|
+
}), [entry, pending, reload, loadMore]);
|
|
1507
|
+
}
|
|
1508
|
+
var ownedProducts = (client, _, next) => client.inventory.products.getOwned(next);
|
|
1509
|
+
var ownedProduct = (client, productId) => client.inventory.products.get(productId);
|
|
1510
|
+
var productActivations = (client, productId, next) => client.inventory.products.getActivations(productId, next);
|
|
1511
|
+
var productLicenses = (client, productId, next) => client.inventory.products.getLicenses(productId, next);
|
|
1512
|
+
var orderHistory = (client, _, next) => client.orders.getHistory(next);
|
|
1513
|
+
var subscriptions = (client, _, next) => client.inventory.subscriptions.get(next);
|
|
1514
|
+
var subscription = (client, subscriptionId) => client.inventory.subscriptions.getById(subscriptionId);
|
|
1515
|
+
function useOwnedProducts() {
|
|
1516
|
+
return useAccountPages("products", "", ownedProducts);
|
|
1517
|
+
}
|
|
1518
|
+
function useOwnedProduct(productId) {
|
|
1519
|
+
return useAccountItem("product", productId, ownedProduct);
|
|
1520
|
+
}
|
|
1521
|
+
function useProductActivations(productId) {
|
|
1522
|
+
return useAccountPages("product-activations", productId, productActivations);
|
|
1523
|
+
}
|
|
1524
|
+
function useProductLicenses(productId) {
|
|
1525
|
+
return useAccountPages("product-licenses", productId, productLicenses);
|
|
1526
|
+
}
|
|
1527
|
+
function useOrderHistory() {
|
|
1528
|
+
return useAccountPages("orders", "", orderHistory);
|
|
1529
|
+
}
|
|
1530
|
+
function useSubscriptions() {
|
|
1531
|
+
return useAccountPages("subscriptions", "", subscriptions);
|
|
1532
|
+
}
|
|
1533
|
+
function useSubscription(subscriptionId) {
|
|
1534
|
+
return useAccountItem("subscription", subscriptionId, subscription);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1417
1537
|
// src/hooks/useActivationRequest.ts
|
|
1418
1538
|
import { ActivationRequestStatus, NotAuthenticatedError as NotAuthenticatedError2 } from "@moonbase.sh/storefront-api";
|
|
1419
|
-
import { useCallback, useEffect as
|
|
1539
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef2, useState } from "react";
|
|
1420
1540
|
var pollInterval = 1500;
|
|
1421
1541
|
function errorMessage(err) {
|
|
1422
1542
|
return err instanceof NotAuthenticatedError2 ? "You need to be signed in to do this" : err.message;
|
|
@@ -1433,13 +1553,13 @@ function useActivationRequest(token, options = {}) {
|
|
|
1433
1553
|
const [fulfilling, setFulfilling] = useState(false);
|
|
1434
1554
|
const [completing, setCompleting] = useState(false);
|
|
1435
1555
|
const [error, setError] = useState(null);
|
|
1436
|
-
const adopt =
|
|
1556
|
+
const adopt = useCallback2((request) => {
|
|
1437
1557
|
setActivationRequest(request);
|
|
1438
1558
|
if (request.status === ActivationRequestStatus.Fulfilled)
|
|
1439
1559
|
setCompleting(true);
|
|
1440
1560
|
}, []);
|
|
1441
1561
|
const upToDate = !!token && (fetched == null ? void 0 : fetched.token) === token && (fetched.userId === userId || !!((_a = activationRequest == null ? void 0 : activationRequest.licenseEligibility) == null ? void 0 : _a.eligible));
|
|
1442
|
-
|
|
1562
|
+
useEffect3(() => {
|
|
1443
1563
|
if (!token || upToDate)
|
|
1444
1564
|
return;
|
|
1445
1565
|
let current = true;
|
|
@@ -1449,7 +1569,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1449
1569
|
};
|
|
1450
1570
|
}, [storefront, token, userId, upToDate, adopt]);
|
|
1451
1571
|
const requestId = activationRequest == null ? void 0 : activationRequest.id;
|
|
1452
|
-
|
|
1572
|
+
useEffect3(() => {
|
|
1453
1573
|
if (!completing || !requestId)
|
|
1454
1574
|
return;
|
|
1455
1575
|
let current = true;
|
|
@@ -1476,7 +1596,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1476
1596
|
clearTimeout(timeout);
|
|
1477
1597
|
};
|
|
1478
1598
|
}, [storefront, completing, requestId]);
|
|
1479
|
-
const fulfillLicense =
|
|
1599
|
+
const fulfillLicense = useCallback2(async () => {
|
|
1480
1600
|
if (!requestId)
|
|
1481
1601
|
return;
|
|
1482
1602
|
setError(null);
|
|
@@ -1488,7 +1608,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1488
1608
|
setFulfilling(false);
|
|
1489
1609
|
}
|
|
1490
1610
|
}, [storefront, requestId, adopt]);
|
|
1491
|
-
const fulfillTrial =
|
|
1611
|
+
const fulfillTrial = useCallback2(async (newsletterOptIn = false) => {
|
|
1492
1612
|
if (!requestId)
|
|
1493
1613
|
return;
|
|
1494
1614
|
setError(null);
|
|
@@ -1514,7 +1634,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1514
1634
|
const autoFulfill = (_b = options.autoFulfill) != null ? _b : false;
|
|
1515
1635
|
const autoFulfilled = useRef2(null);
|
|
1516
1636
|
const eligible = (activationRequest == null ? void 0 : activationRequest.status) === ActivationRequestStatus.Requested && !!((_c = activationRequest.licenseEligibility) == null ? void 0 : _c.eligible);
|
|
1517
|
-
|
|
1637
|
+
useEffect3(() => {
|
|
1518
1638
|
if (!autoFulfill || !eligible || !requestId || autoFulfilled.current === requestId)
|
|
1519
1639
|
return;
|
|
1520
1640
|
autoFulfilled.current = requestId;
|
|
@@ -1523,7 +1643,7 @@ function useActivationRequest(token, options = {}) {
|
|
|
1523
1643
|
setError(errorMessage(err));
|
|
1524
1644
|
});
|
|
1525
1645
|
}, [autoFulfill, eligible, requestId, fulfillLicense]);
|
|
1526
|
-
const cancel =
|
|
1646
|
+
const cancel = useCallback2(async () => {
|
|
1527
1647
|
if (!activationRequest || activationRequest.status === ActivationRequestStatus.Cancelled)
|
|
1528
1648
|
return;
|
|
1529
1649
|
adopt(await storefront.client.activationRequests.cancel(activationRequest.id));
|
|
@@ -1542,22 +1662,22 @@ function useActivationRequest(token, options = {}) {
|
|
|
1542
1662
|
}
|
|
1543
1663
|
|
|
1544
1664
|
// src/hooks/useAuth.ts
|
|
1545
|
-
import { useMemo as
|
|
1665
|
+
import { useMemo as useMemo3 } from "react";
|
|
1546
1666
|
function useAuth() {
|
|
1547
1667
|
const storefront = useStorefront();
|
|
1548
1668
|
const user = useStorefrontState((state) => state.user);
|
|
1549
1669
|
const loaded = useStorefrontState((state) => state.userLoaded);
|
|
1550
|
-
return
|
|
1670
|
+
return useMemo3(() => ({ ...storefront.auth, user, loaded }), [storefront, user, loaded]);
|
|
1551
1671
|
}
|
|
1552
1672
|
|
|
1553
1673
|
// src/hooks/useCart.ts
|
|
1554
1674
|
import { CartUtils as CartUtils5, resolveDisplayCurrency as resolveDisplayCurrency5 } from "@moonbase.sh/storefront-api";
|
|
1555
|
-
import { useMemo as
|
|
1675
|
+
import { useMemo as useMemo4 } from "react";
|
|
1556
1676
|
function useCart() {
|
|
1557
1677
|
const storefront = useStorefront();
|
|
1558
1678
|
const catalog = useStorefrontState((state) => state.catalog);
|
|
1559
1679
|
const order = useStorefrontState((state) => state.order);
|
|
1560
|
-
return
|
|
1680
|
+
return useMemo4(() => {
|
|
1561
1681
|
const currency = resolveDisplayCurrency5(order, catalog);
|
|
1562
1682
|
const breakdown = CartUtils5.total(catalog, order, currency);
|
|
1563
1683
|
const items = enrichLineItems(catalog, order);
|
|
@@ -1580,17 +1700,17 @@ function useCartActions() {
|
|
|
1580
1700
|
}
|
|
1581
1701
|
|
|
1582
1702
|
// src/hooks/useCheckout.ts
|
|
1583
|
-
import { useCallback as
|
|
1703
|
+
import { useCallback as useCallback3 } from "react";
|
|
1584
1704
|
function useCheckout() {
|
|
1585
1705
|
const storefront = useStorefront();
|
|
1586
|
-
return
|
|
1706
|
+
return useCallback3((items, options) => storefront.checkout(items, options), [storefront]);
|
|
1587
1707
|
}
|
|
1588
1708
|
|
|
1589
1709
|
// src/hooks/useCommunicationPreferences.ts
|
|
1590
|
-
import { useMemo as
|
|
1710
|
+
import { useMemo as useMemo5 } from "react";
|
|
1591
1711
|
function useCommunicationPreferences() {
|
|
1592
1712
|
const storefront = useStorefront();
|
|
1593
|
-
return
|
|
1713
|
+
return useMemo5(() => {
|
|
1594
1714
|
const communications = storefront.client.communications;
|
|
1595
1715
|
return {
|
|
1596
1716
|
subscribe: (input) => communications.subscribe(input, storefront.adSignals()),
|
|
@@ -1603,14 +1723,14 @@ function useCommunicationPreferences() {
|
|
|
1603
1723
|
}
|
|
1604
1724
|
|
|
1605
1725
|
// src/hooks/useGroups.ts
|
|
1606
|
-
import { useMemo as
|
|
1726
|
+
import { useMemo as useMemo6 } from "react";
|
|
1607
1727
|
function useGroups() {
|
|
1608
1728
|
const storefront = useStorefront();
|
|
1609
|
-
return
|
|
1729
|
+
return useMemo6(() => ({ join: (groupId) => storefront.client.groups.join(groupId) }), [storefront]);
|
|
1610
1730
|
}
|
|
1611
1731
|
|
|
1612
1732
|
// src/hooks/useInventory.ts
|
|
1613
|
-
import { useMemo as
|
|
1733
|
+
import { useMemo as useMemo7 } from "react";
|
|
1614
1734
|
|
|
1615
1735
|
// src/inventory.ts
|
|
1616
1736
|
import { mountCheckout as mountCheckout4, mountSubscription as mountSubscription2, resolveRedirect as resolveRedirect3, withPriceFormat } from "@moonbase.sh/storefront-api";
|
|
@@ -1650,13 +1770,13 @@ function createInventory(storefront) {
|
|
|
1650
1770
|
mountCheckout4(url);
|
|
1651
1771
|
return closed;
|
|
1652
1772
|
},
|
|
1653
|
-
updateSubscriptionPaymentMethod: async (
|
|
1654
|
-
const response = await inventory.subscriptions.getById(
|
|
1773
|
+
updateSubscriptionPaymentMethod: async (subscription2, options = {}) => {
|
|
1774
|
+
const response = await inventory.subscriptions.getById(subscription2.id, {
|
|
1655
1775
|
toUpdatePaymentMethod: true,
|
|
1656
1776
|
returnUrl: checkoutReturnUrl(options.returnUrl)
|
|
1657
1777
|
});
|
|
1658
1778
|
window.dispatchEvent(new CustomEvent("moonbase-subscription-payment-method-update-initiated", {
|
|
1659
|
-
detail: { subscription }
|
|
1779
|
+
detail: { subscription: subscription2 }
|
|
1660
1780
|
}));
|
|
1661
1781
|
const url = response.embeddedUpdatePaymentUrl;
|
|
1662
1782
|
if (!url)
|
|
@@ -1674,14 +1794,14 @@ function createInventory(storefront) {
|
|
|
1674
1794
|
// src/hooks/useInventory.ts
|
|
1675
1795
|
function useInventory() {
|
|
1676
1796
|
const storefront = useStorefront();
|
|
1677
|
-
return
|
|
1797
|
+
return useMemo7(() => createInventory(storefront), [storefront]);
|
|
1678
1798
|
}
|
|
1679
1799
|
|
|
1680
1800
|
// src/hooks/useOrders.ts
|
|
1681
|
-
import { useMemo as
|
|
1801
|
+
import { useMemo as useMemo8 } from "react";
|
|
1682
1802
|
function useOrders() {
|
|
1683
1803
|
const storefront = useStorefront();
|
|
1684
|
-
return
|
|
1804
|
+
return useMemo8(() => ({
|
|
1685
1805
|
getOrders: (nextUrl) => storefront.client.orders.getHistory(nextUrl),
|
|
1686
1806
|
getReceipt: (order) => storefront.client.orders.getReceipt(order.id),
|
|
1687
1807
|
downloadReceipt: async (order) => {
|
|
@@ -1700,10 +1820,10 @@ function useOrders() {
|
|
|
1700
1820
|
|
|
1701
1821
|
// src/hooks/usePrice.ts
|
|
1702
1822
|
import { formatMoney } from "@moonbase.sh/storefront-api";
|
|
1703
|
-
import { useMemo as
|
|
1823
|
+
import { useMemo as useMemo9 } from "react";
|
|
1704
1824
|
function usePrice(variation, format) {
|
|
1705
1825
|
const currency = useCurrency();
|
|
1706
|
-
return
|
|
1826
|
+
return useMemo9(() => {
|
|
1707
1827
|
const amount = variation == null ? void 0 : variation.price[currency];
|
|
1708
1828
|
const original = (variation == null ? void 0 : variation.hasDiscount) ? variation.originalPrice[currency] : void 0;
|
|
1709
1829
|
const saving = amount !== void 0 && original !== void 0 ? Number((original - amount).toFixed(6)) : void 0;
|
|
@@ -1718,11 +1838,11 @@ function usePrice(variation, format) {
|
|
|
1718
1838
|
}
|
|
1719
1839
|
|
|
1720
1840
|
// src/hooks/useReviews.ts
|
|
1721
|
-
import { useMemo as
|
|
1841
|
+
import { useMemo as useMemo10 } from "react";
|
|
1722
1842
|
function useReviews() {
|
|
1723
1843
|
const storefront = useStorefront();
|
|
1724
1844
|
const enabled = useStorefrontState((state) => !!state.catalog.reviewsEnabled);
|
|
1725
|
-
return
|
|
1845
|
+
return useMemo10(() => {
|
|
1726
1846
|
const reviews = storefront.client.reviews;
|
|
1727
1847
|
return {
|
|
1728
1848
|
enabled,
|
|
@@ -1737,11 +1857,11 @@ function useReviews() {
|
|
|
1737
1857
|
}
|
|
1738
1858
|
|
|
1739
1859
|
// src/hooks/useVendor.ts
|
|
1740
|
-
import { useEffect as
|
|
1860
|
+
import { useEffect as useEffect4, useState as useState2 } from "react";
|
|
1741
1861
|
function useVendor() {
|
|
1742
1862
|
const storefront = useStorefront();
|
|
1743
1863
|
const [state, setState] = useState2({ vendor: null, loading: true });
|
|
1744
|
-
|
|
1864
|
+
useEffect4(() => {
|
|
1745
1865
|
let current = true;
|
|
1746
1866
|
storefront.client.vendor.get().then((vendor) => current && setState({ vendor, loading: false })).catch(() => current && setState({ vendor: null, loading: false }));
|
|
1747
1867
|
return () => {
|
|
@@ -1753,10 +1873,10 @@ function useVendor() {
|
|
|
1753
1873
|
|
|
1754
1874
|
// src/hooks/useVoucher.ts
|
|
1755
1875
|
import { NotFoundError as NotFoundError2 } from "@moonbase.sh/storefront-api";
|
|
1756
|
-
import { useMemo as
|
|
1876
|
+
import { useMemo as useMemo11 } from "react";
|
|
1757
1877
|
function useVoucher() {
|
|
1758
1878
|
const storefront = useStorefront();
|
|
1759
|
-
return
|
|
1879
|
+
return useMemo11(() => {
|
|
1760
1880
|
const known = async (lookup) => {
|
|
1761
1881
|
try {
|
|
1762
1882
|
return await lookup;
|
|
@@ -1819,15 +1939,22 @@ export {
|
|
|
1819
1939
|
useLockedOffers,
|
|
1820
1940
|
useOffer,
|
|
1821
1941
|
useOffers,
|
|
1942
|
+
useOrderHistory,
|
|
1822
1943
|
useOrders,
|
|
1944
|
+
useOwnedProduct,
|
|
1945
|
+
useOwnedProducts,
|
|
1823
1946
|
usePrice,
|
|
1824
1947
|
useProduct,
|
|
1948
|
+
useProductActivations,
|
|
1949
|
+
useProductLicenses,
|
|
1825
1950
|
useProducts,
|
|
1826
1951
|
usePromotions,
|
|
1827
1952
|
useReviews,
|
|
1828
1953
|
useStorefront,
|
|
1829
1954
|
useStorefrontEvent,
|
|
1830
1955
|
useStorefrontState,
|
|
1956
|
+
useSubscription,
|
|
1957
|
+
useSubscriptions,
|
|
1831
1958
|
useVendor,
|
|
1832
1959
|
useVoucher
|
|
1833
1960
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next-
|
|
4
|
+
"version": "0.0.0-next-20261111171855",
|
|
5
5
|
"description": "Package to let you build React storefronts with Moonbase.sh as payment and delivery provider",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"react": ">=18"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@moonbase.sh/storefront-api": "0.0.0-next-
|
|
19
|
+
"@moonbase.sh/storefront-api": "0.0.0-next-20261111171855"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.5.4",
|