@tokenoftrust/storefront-runner 4.2.3 → 4.2.4

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.
@@ -90,12 +90,17 @@ export function lazyCheckoutLoaderJs(options: LazyCheckoutLoaderOptions): string
90
90
  try { return new URL(url, document.baseURI).origin === cartOrigin; } catch (e) { return false; }
91
91
  }
92
92
  // Foxy copies the Referer onto cart_cancel_and_continue_link and ignores a
93
- // continue parameter. The document policy stays strict-origin. A cart script
94
- // snapshots the Referer while its src is assigned, so that assignment uses the
95
- // store-home URL and restores the page before the turn ends. A cart navigation
96
- // sends the full document URL through the element's referrerPolicy. That URL
97
- // already includes the store origin and tenant path, and the history entry
98
- // stays the page that opened the cart.
93
+ // continue parameter. The document policy is strict-origin-when-cross-origin,
94
+ // so a cross-origin request drops the tenant path. A cart script snapshots the
95
+ // Referer while its src is assigned: that assignment uses the store-home URL
96
+ // (origin plus cookie path) and restores the page before the turn ends. A cart
97
+ // navigation uses that same URL, then puts the shopper's URL back when the page
98
+ // hides or is restored from the back-forward cache, so Back returns to the page
99
+ // that opened the cart. A form has no referrerPolicy, so a cart submit also sets
100
+ // a referrer meta for that navigation and puts the document policy back after it.
101
+ var pendingReturn = null;
102
+ var referrerMeta = null;
103
+ var documentReferrerPolicy = "strict-origin-when-cross-origin";
99
104
  function storeHome() {
100
105
  return location.origin + cookiePath;
101
106
  }
@@ -107,6 +112,41 @@ export function lazyCheckoutLoaderJs(options: LazyCheckoutLoaderOptions): string
107
112
  function restoreHref(current) {
108
113
  if (location.href !== current) window.history.replaceState(window.history.state, "", current);
109
114
  }
115
+ function revealForNavigation() {
116
+ var current = location.href;
117
+ if (current === storeHome()) return;
118
+ pendingReturn = current;
119
+ revealStoreHome();
120
+ }
121
+ function restorePendingReturn() {
122
+ if (!pendingReturn) return;
123
+ var back = pendingReturn;
124
+ restoreHref(back);
125
+ if (location.href === back) pendingReturn = null;
126
+ }
127
+ function loosenReferrer() {
128
+ if (!referrerMeta) {
129
+ referrerMeta = document.createElement("meta");
130
+ referrerMeta.setAttribute("name", "referrer");
131
+ (document.head || document.documentElement).appendChild(referrerMeta);
132
+ }
133
+ referrerMeta.setAttribute("content", referrerPolicy);
134
+ }
135
+ function tightenReferrer() {
136
+ if (!referrerMeta) return;
137
+ referrerMeta.setAttribute("content", documentReferrerPolicy);
138
+ }
139
+ function endCartNavigation() {
140
+ restorePendingReturn();
141
+ tightenReferrer();
142
+ }
143
+ document.addEventListener("visibilitychange", function () {
144
+ if (document.visibilityState === "hidden") endCartNavigation();
145
+ });
146
+ window.addEventListener("pagehide", endCartNavigation);
147
+ window.addEventListener("pageshow", function (event) {
148
+ if (event.persisted) endCartNavigation();
149
+ });
110
150
  var origCreate = document.createElement;
111
151
  document.createElement = function (name) {
112
152
  var el = origCreate.apply(document, arguments);
@@ -254,6 +294,7 @@ export function lazyCheckoutLoaderJs(options: LazyCheckoutLoaderOptions): string
254
294
  anchor.referrerPolicy = referrerPolicy;
255
295
  if (state === 'ready') {
256
296
  stampAnchor(anchor);
297
+ if (!event.defaultPrevented) revealForNavigation();
257
298
  return;
258
299
  }
259
300
  if (event.defaultPrevented) return;
@@ -314,6 +355,11 @@ export function lazyCheckoutLoaderJs(options: LazyCheckoutLoaderOptions): string
314
355
  if (!cartForm || state === 'ready') {
315
356
  if (!event.defaultPrevented && state === 'ready') {
316
357
  form.referrerPolicy = referrerPolicy;
358
+ if (cartForm) {
359
+ form.setAttribute("referrerpolicy", referrerPolicy);
360
+ loosenReferrer();
361
+ revealForNavigation();
362
+ }
317
363
  }
318
364
  return;
319
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",