@moonbase.sh/react 1.4.1 → 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 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.1";
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;
package/dist/index.d.cts CHANGED
@@ -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
@@ -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.1";
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/react",
3
3
  "type": "module",
4
- "version": "1.4.1",
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.21.1"
19
+ "@moonbase.sh/storefront-api": "3.22.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.5.4",