@moonbase.sh/react 1.4.0 → 1.4.2
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 +6 -0
- package/dist/index.cjs +13 -3
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +15 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -133,6 +133,12 @@ identity across renders, so it can go in a dependency list or to a memoized chil
|
|
|
133
133
|
own site, not Moonbase's. Redirecting makes the hosted checkout the top-level document, so the wallets appear. `'auto'`
|
|
134
134
|
takes that trade only on mobile, where wallet usage concentrates, and keeps the overlay on desktop.
|
|
135
135
|
|
|
136
|
+
A cross-origin isolated page (one that sends `Cross-Origin-Embedder-Policy` and `Cross-Origin-Opener-Policy`, say to
|
|
137
|
+
use `SharedArrayBuffer`) cannot frame the overlay, so checkout always redirects there, whatever `redirect` says. When
|
|
138
|
+
the buyer comes back, the order is finished without the overlay once `<StorefrontProvider>` has hydrated:
|
|
139
|
+
`checkoutCompleted` fires and the cart clears, but no receipt opens over the page, since the hosted checkout has just
|
|
140
|
+
shown it.
|
|
141
|
+
|
|
136
142
|
When the call redirects it cannot report an outcome, since the result arrives on the return page, so it resolves with
|
|
137
143
|
`{ completed: false, redirected: true }`. Check `redirected` before treating `completed: false` as a failure.
|
|
138
144
|
|
package/dist/index.cjs
CHANGED
|
@@ -67,7 +67,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
67
67
|
var import_storefront_api13 = require("@moonbase.sh/storefront-api");
|
|
68
68
|
|
|
69
69
|
// package.json
|
|
70
|
-
var version = "1.4.
|
|
70
|
+
var version = "1.4.2";
|
|
71
71
|
|
|
72
72
|
// src/storefront.ts
|
|
73
73
|
var import_storefront_api5 = require("@moonbase.sh/storefront-api");
|
|
@@ -789,7 +789,9 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
789
789
|
const finalEndpoint = new URL(decodeURIComponent(endpoint));
|
|
790
790
|
for (const [key, value] of Object.entries(parameters))
|
|
791
791
|
finalEndpoint.searchParams.append(key, value);
|
|
792
|
-
if (intent === "checkout")
|
|
792
|
+
if (intent === "checkout" && (0, import_storefront_api5.isCrossOriginIsolated)())
|
|
793
|
+
this.checkoutReturnToSettle = finalEndpoint.toString();
|
|
794
|
+
else if (intent === "checkout")
|
|
793
795
|
(0, import_storefront_api5.mountCheckout)(finalEndpoint.toString());
|
|
794
796
|
else
|
|
795
797
|
(0, import_storefront_api5.mountSubscription)(finalEndpoint.toString());
|
|
@@ -850,11 +852,19 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
850
852
|
* Next.js's router is why: it reads the address before any of the page's own code runs, and writes it
|
|
851
853
|
* back as the page hydrates. It is told with a `popstate`, as for Back, since it ignores an address
|
|
852
854
|
* changed under the history entry it wrote, and `useSearchParams()` would go on listing the parameters.
|
|
855
|
+
*
|
|
856
|
+
* On a cross-origin isolated page, which cannot frame the overlay, this is also where the order the
|
|
857
|
+
* buyer paid for is finished (`settleCheckoutReturn`): `checkoutCompleted` has to wait for the
|
|
858
|
+
* components that listen with `useStorefrontEvent`, and they are mounted by now.
|
|
853
859
|
*/
|
|
854
860
|
clearCheckoutReturn() {
|
|
855
861
|
if (!this.tookCheckoutReturn || this.disposed || typeof window === "undefined")
|
|
856
862
|
return;
|
|
857
863
|
this.tookCheckoutReturn = false;
|
|
864
|
+
const toSettle = this.checkoutReturnToSettle;
|
|
865
|
+
this.checkoutReturnToSettle = void 0;
|
|
866
|
+
if (toSettle)
|
|
867
|
+
void (0, import_storefront_api5.settleCheckoutReturn)(toSettle, (orderId) => this.client.orders.get(orderId));
|
|
858
868
|
const address = (0, import_storefront_api5.withoutHandshakeParams)(window.location.href);
|
|
859
869
|
if (address === window.location.href)
|
|
860
870
|
return;
|
|
@@ -1366,7 +1376,7 @@ function useStorefrontEvent(event, handler) {
|
|
|
1366
1376
|
(0, import_react.useEffect)(() => {
|
|
1367
1377
|
latest.current = handler;
|
|
1368
1378
|
});
|
|
1369
|
-
(0, import_react.useEffect)(() => storefront.on(event, (...args) => latest.current(...args)), [storefront, event]);
|
|
1379
|
+
(0, import_react.useEffect)(() => storefront.on(event, ((...args) => latest.current(...args))), [storefront, event]);
|
|
1370
1380
|
}
|
|
1371
1381
|
|
|
1372
1382
|
// src/hooks/catalog.ts
|
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,
|
|
1
|
+
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, MoonbaseClient, Storefront, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, GiftClaim, 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
|
|
|
@@ -309,6 +309,8 @@ declare class MoonbaseStorefront {
|
|
|
309
309
|
private readonly lifetime;
|
|
310
310
|
/** Whether the storefront took the hosted checkout's parameters off the address as it was made. */
|
|
311
311
|
private tookCheckoutReturn;
|
|
312
|
+
/** The checkout a buyer came back from on a cross-origin isolated page, for `clearCheckoutReturn` to finish. */
|
|
313
|
+
private checkoutReturnToSettle;
|
|
312
314
|
private catalogRefreshesStarted;
|
|
313
315
|
private catalogRefreshLanded;
|
|
314
316
|
constructor(configuration: MoonbaseConfiguration, client: MoonbaseClient, options?: Pick<StorefrontOptions, 'initialCatalog' | 'autoApplyItemOffers'>);
|
|
@@ -345,6 +347,10 @@ declare class MoonbaseStorefront {
|
|
|
345
347
|
* Next.js's router is why: it reads the address before any of the page's own code runs, and writes it
|
|
346
348
|
* back as the page hydrates. It is told with a `popstate`, as for Back, since it ignores an address
|
|
347
349
|
* changed under the history entry it wrote, and `useSearchParams()` would go on listing the parameters.
|
|
350
|
+
*
|
|
351
|
+
* On a cross-origin isolated page, which cannot frame the overlay, this is also where the order the
|
|
352
|
+
* buyer paid for is finished (`settleCheckoutReturn`): `checkoutCompleted` has to wait for the
|
|
353
|
+
* components that listen with `useStorefrontEvent`, and they are mounted by now.
|
|
348
354
|
*/
|
|
349
355
|
clearCheckoutReturn(): void;
|
|
350
356
|
get hasUtm(): boolean;
|
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,
|
|
1
|
+
import { User, Address, SignUpOptions, SignUpResult, CommunicationPreferences, UserAccountConfirmed, ConnectableAccountProvider, CheckoutRedirectMode, StorefrontProduct, StorefrontBundle, PricingVariation, StorefrontOffer, LineItem, MoonbaseConfiguration, MoonbaseClient, Storefront, Order, UrchinTrackingModule, OpenOrder, Money, CheckoutPaymentFailure, CompletedOrder, AdConsentReport, AdSignals, OfferConditionContext, StorefrontPromotion, OfferProgress, OwnedProduct, Activation, License, Subscription, ActivationRequest, CartTotal, SubscribeInput, CommunicationPreferencesInput, GiftClaim, 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
|
|
|
@@ -309,6 +309,8 @@ declare class MoonbaseStorefront {
|
|
|
309
309
|
private readonly lifetime;
|
|
310
310
|
/** Whether the storefront took the hosted checkout's parameters off the address as it was made. */
|
|
311
311
|
private tookCheckoutReturn;
|
|
312
|
+
/** The checkout a buyer came back from on a cross-origin isolated page, for `clearCheckoutReturn` to finish. */
|
|
313
|
+
private checkoutReturnToSettle;
|
|
312
314
|
private catalogRefreshesStarted;
|
|
313
315
|
private catalogRefreshLanded;
|
|
314
316
|
constructor(configuration: MoonbaseConfiguration, client: MoonbaseClient, options?: Pick<StorefrontOptions, 'initialCatalog' | 'autoApplyItemOffers'>);
|
|
@@ -345,6 +347,10 @@ declare class MoonbaseStorefront {
|
|
|
345
347
|
* Next.js's router is why: it reads the address before any of the page's own code runs, and writes it
|
|
346
348
|
* back as the page hydrates. It is told with a `popstate`, as for Back, since it ignores an address
|
|
347
349
|
* changed under the history entry it wrote, and `useSearchParams()` would go on listing the parameters.
|
|
350
|
+
*
|
|
351
|
+
* On a cross-origin isolated page, which cannot frame the overlay, this is also where the order the
|
|
352
|
+
* buyer paid for is finished (`settleCheckoutReturn`): `checkoutCompleted` has to wait for the
|
|
353
|
+
* components that listen with `useStorefrontEvent`, and they are mounted by now.
|
|
348
354
|
*/
|
|
349
355
|
clearCheckoutReturn(): void;
|
|
350
356
|
get hasUtm(): boolean;
|
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 = "1.4.
|
|
5
|
+
var version = "1.4.2";
|
|
6
6
|
|
|
7
7
|
// src/storefront.ts
|
|
8
8
|
import {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
globalPrivacyControlRefuses,
|
|
15
15
|
grantsClickIds,
|
|
16
16
|
hasCampaignData,
|
|
17
|
+
isCrossOriginIsolated,
|
|
17
18
|
isSameArrival,
|
|
18
19
|
landingHere,
|
|
19
20
|
mountCheckout as mountCheckout3,
|
|
@@ -36,6 +37,7 @@ import {
|
|
|
36
37
|
resolveUtm,
|
|
37
38
|
schemas as schemas2,
|
|
38
39
|
sendsGlobalPrivacyControl,
|
|
40
|
+
settleCheckoutReturn,
|
|
39
41
|
StoreClosedError,
|
|
40
42
|
storedAnswerTime,
|
|
41
43
|
TokenStore,
|
|
@@ -796,7 +798,9 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
796
798
|
const finalEndpoint = new URL(decodeURIComponent(endpoint));
|
|
797
799
|
for (const [key, value] of Object.entries(parameters))
|
|
798
800
|
finalEndpoint.searchParams.append(key, value);
|
|
799
|
-
if (intent === "checkout")
|
|
801
|
+
if (intent === "checkout" && isCrossOriginIsolated())
|
|
802
|
+
this.checkoutReturnToSettle = finalEndpoint.toString();
|
|
803
|
+
else if (intent === "checkout")
|
|
800
804
|
mountCheckout3(finalEndpoint.toString());
|
|
801
805
|
else
|
|
802
806
|
mountSubscription(finalEndpoint.toString());
|
|
@@ -857,11 +861,19 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
|
|
|
857
861
|
* Next.js's router is why: it reads the address before any of the page's own code runs, and writes it
|
|
858
862
|
* back as the page hydrates. It is told with a `popstate`, as for Back, since it ignores an address
|
|
859
863
|
* changed under the history entry it wrote, and `useSearchParams()` would go on listing the parameters.
|
|
864
|
+
*
|
|
865
|
+
* On a cross-origin isolated page, which cannot frame the overlay, this is also where the order the
|
|
866
|
+
* buyer paid for is finished (`settleCheckoutReturn`): `checkoutCompleted` has to wait for the
|
|
867
|
+
* components that listen with `useStorefrontEvent`, and they are mounted by now.
|
|
860
868
|
*/
|
|
861
869
|
clearCheckoutReturn() {
|
|
862
870
|
if (!this.tookCheckoutReturn || this.disposed || typeof window === "undefined")
|
|
863
871
|
return;
|
|
864
872
|
this.tookCheckoutReturn = false;
|
|
873
|
+
const toSettle = this.checkoutReturnToSettle;
|
|
874
|
+
this.checkoutReturnToSettle = void 0;
|
|
875
|
+
if (toSettle)
|
|
876
|
+
void settleCheckoutReturn(toSettle, (orderId) => this.client.orders.get(orderId));
|
|
865
877
|
const address = withoutHandshakeParams2(window.location.href);
|
|
866
878
|
if (address === window.location.href)
|
|
867
879
|
return;
|
|
@@ -1373,7 +1385,7 @@ function useStorefrontEvent(event, handler) {
|
|
|
1373
1385
|
useEffect(() => {
|
|
1374
1386
|
latest.current = handler;
|
|
1375
1387
|
});
|
|
1376
|
-
useEffect(() => storefront.on(event, (...args) => latest.current(...args)), [storefront, event]);
|
|
1388
|
+
useEffect(() => storefront.on(event, ((...args) => latest.current(...args))), [storefront, event]);
|
|
1377
1389
|
}
|
|
1378
1390
|
|
|
1379
1391
|
// src/hooks/catalog.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.2",
|
|
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": "3.
|
|
19
|
+
"@moonbase.sh/storefront-api": "3.22.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.5.4",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"rimraf": "^5.0.10",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
31
|
"typescript": "~5.8.3",
|
|
32
|
-
"vitest": "^
|
|
32
|
+
"vitest": "^4.1.12"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|