@amboras-dev/storefront-core 2026.11.14 → 2026.11.16-rc.1
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/CHANGELOG.md +116 -0
- package/README.md +19 -3
- package/core-manifest.json +16 -1
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -0
- package/dist/config/index.js.map +1 -1
- package/dist/edge/proxy.d.ts.map +1 -1
- package/dist/edge/proxy.js +51 -13
- package/dist/edge/proxy.js.map +1 -1
- package/dist/edge/url-map.d.ts +40 -5
- package/dist/edge/url-map.d.ts.map +1 -1
- package/dist/edge/url-map.js +146 -22
- package/dist/edge/url-map.js.map +1 -1
- package/dist/hooks/use-checkout-gate.d.ts +10 -1
- package/dist/hooks/use-checkout-gate.d.ts.map +1 -1
- package/dist/hooks/use-checkout-gate.js +13 -1
- package/dist/hooks/use-checkout-gate.js.map +1 -1
- package/dist/hooks/use-checkout.d.ts +7 -3
- package/dist/hooks/use-checkout.d.ts.map +1 -1
- package/dist/hooks/use-checkout.js +124 -8
- package/dist/hooks/use-checkout.js.map +1 -1
- package/dist/lib/brand.d.ts +4 -1
- package/dist/lib/brand.d.ts.map +1 -1
- package/dist/lib/brand.js +16 -20
- package/dist/lib/brand.js.map +1 -1
- package/dist/lib/cart-permalink.d.ts +25 -0
- package/dist/lib/cart-permalink.d.ts.map +1 -0
- package/dist/lib/cart-permalink.js +78 -0
- package/dist/lib/cart-permalink.js.map +1 -0
- package/dist/lib/checkout/required-checkout-fields.d.ts +32 -0
- package/dist/lib/checkout/required-checkout-fields.d.ts.map +1 -0
- package/dist/lib/checkout/required-checkout-fields.js +47 -0
- package/dist/lib/checkout/required-checkout-fields.js.map +1 -0
- package/dist/lib/checkout-config.d.ts +3 -1
- package/dist/lib/checkout-config.d.ts.map +1 -1
- package/dist/lib/checkout-config.js +12 -12
- package/dist/lib/checkout-config.js.map +1 -1
- package/dist/lib/discount-link.d.ts +18 -0
- package/dist/lib/discount-link.d.ts.map +1 -0
- package/dist/lib/discount-link.js +73 -0
- package/dist/lib/discount-link.js.map +1 -0
- package/dist/lib/l10n/checkout-messages-de.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages-de.js +1 -0
- package/dist/lib/l10n/checkout-messages-de.js.map +1 -1
- package/dist/lib/l10n/checkout-messages-en.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages-en.js +1 -0
- package/dist/lib/l10n/checkout-messages-en.js.map +1 -1
- package/dist/lib/l10n/checkout-messages-fr.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages-fr.js +1 -0
- package/dist/lib/l10n/checkout-messages-fr.js.map +1 -1
- package/dist/lib/l10n/checkout-messages-pt-br.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages-pt-br.js +1 -0
- package/dist/lib/l10n/checkout-messages-pt-br.js.map +1 -1
- package/dist/lib/l10n/checkout-messages-pt-pt.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages-pt-pt.js +1 -0
- package/dist/lib/l10n/checkout-messages-pt-pt.js.map +1 -1
- package/dist/lib/l10n/checkout-messages-vi.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages-vi.js +1 -0
- package/dist/lib/l10n/checkout-messages-vi.js.map +1 -1
- package/dist/lib/l10n/checkout-messages.d.ts +2 -0
- package/dist/lib/l10n/checkout-messages.d.ts.map +1 -1
- package/dist/lib/l10n/checkout-messages.js.map +1 -1
- package/dist/lib/market-selection.d.ts +80 -0
- package/dist/lib/market-selection.d.ts.map +1 -0
- package/dist/lib/market-selection.js +226 -0
- package/dist/lib/market-selection.js.map +1 -0
- package/dist/lib/market.d.ts +22 -1
- package/dist/lib/market.d.ts.map +1 -1
- package/dist/lib/market.js +51 -7
- package/dist/lib/market.js.map +1 -1
- package/dist/lib/medusa-client.d.ts +10 -0
- package/dist/lib/medusa-client.d.ts.map +1 -1
- package/dist/lib/medusa-client.js +17 -6
- package/dist/lib/medusa-client.js.map +1 -1
- package/dist/lib/payment-providers/cod.d.ts +6 -0
- package/dist/lib/payment-providers/cod.d.ts.map +1 -1
- package/dist/lib/payment-providers/cod.js +13 -0
- package/dist/lib/payment-providers/cod.js.map +1 -1
- package/dist/lib/redirects.js +1 -1
- package/dist/lib/redirects.js.map +1 -1
- package/dist/lib/store-api.d.ts +15 -3
- package/dist/lib/store-api.d.ts.map +1 -1
- package/dist/lib/store-api.js +18 -7
- package/dist/lib/store-api.js.map +1 -1
- package/package.json +1 -1
package/dist/edge/url-map.d.ts
CHANGED
|
@@ -2,9 +2,19 @@ import { type StoreUrlMap } from '../lib/market.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* The proxy's in-memory copy of the store's URL map (`GET /store/url-map`, AMB-2174).
|
|
4
4
|
*
|
|
5
|
-
* - Refreshed
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
5
|
+
* - Refreshed every 30 s per instance with `If-None-Match` (a `304` keeps the copy), plus the fresh reads below.
|
|
6
|
+
* - A cold instance (no copy yet) or a copy older than MAX_REDIRECT_AGE_MS (an instance idle that long) waits for
|
|
7
|
+
* Medusa. With a younger copy the request is served from it and the refresh runs in the background (`waitUntil`).
|
|
8
|
+
* One read is in flight per instance.
|
|
9
|
+
* - A page whose market-shaped first segment the copy sends to the root (`/en-ca` set up since the last refresh) also
|
|
10
|
+
* waits for one fresh read (`getFreshUrlMap`): past the CDN, at most one per 10 s per instance, none while the copy
|
|
11
|
+
* is stale or since a fresh read failed. A request waits for the map 1 500 ms at most in all.
|
|
12
|
+
* - Medusa's per-tenant revision (`x-url-map-revision`) orders the answers: a `200` with a revision strictly lower
|
|
13
|
+
* than the copy's is ignored (the CDN or another Medusa task can still hold an older map after a fresh read brought
|
|
14
|
+
* a newer one), for LOWER_REVISION_ANSWERS plain refreshes in a row at most; an equal or higher one replaces the
|
|
15
|
+
* copy, so a change undone (a higher revision, the old map) is served at once. Without the header (an older Medusa,
|
|
16
|
+
* or one that cannot read its revision) any `200` replaces it. Another store API (Medusa URL or store id) starts
|
|
17
|
+
* over: its revisions are its own.
|
|
8
18
|
* - A 404 or 410 with no good copy yet (an older Medusa without the route) means the store has no URL map: the copy
|
|
9
19
|
* is an empty map (the root everywhere, no cold-start 503), retried in 30 s.
|
|
10
20
|
* - Anything else that is not a map (a 5xx, a 401/403 after a key rotation, a 429, a WAF block, a 404 after a good
|
|
@@ -27,12 +37,17 @@ export interface UrlMapCopy {
|
|
|
27
37
|
/** Milliseconds since Medusa last confirmed this copy (a 200 or a 304). */
|
|
28
38
|
age: number;
|
|
29
39
|
}
|
|
30
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* A copy older than this still routes, but never redirects: a 30x from a long-stale copy could send people away. So
|
|
42
|
+
* a page request with a copy this old awaits its due refresh instead of running it in the background (`getUrlMap`).
|
|
43
|
+
*/
|
|
31
44
|
export declare const MAX_REDIRECT_AGE_MS: number;
|
|
32
45
|
/**
|
|
33
46
|
* The URL map for this request, or null when none was ever read (no Medusa URL, or Medusa never answered).
|
|
34
47
|
* `waitUntil` (the proxy's `event.waitUntil`) lets a warm instance refresh in the background; without it every
|
|
35
|
-
* refresh is awaited.
|
|
48
|
+
* refresh is awaited. A due refresh of a copy older than MAX_REDIRECT_AGE_MS is awaited too (at most 1 500 ms), so
|
|
49
|
+
* an instance idle that long decides on a fresh map, not on one that never redirects; if it fails, the old copy is
|
|
50
|
+
* served (it routes, never redirects).
|
|
36
51
|
*/
|
|
37
52
|
export declare function getUrlMap(env?: Env, waitUntil?: (promise: Promise<unknown>) => void): Promise<UrlMapCopy | null>;
|
|
38
53
|
/**
|
|
@@ -41,6 +56,26 @@ export declare function getUrlMap(env?: Env, waitUntil?: (promise: Promise<unkno
|
|
|
41
56
|
* without it.
|
|
42
57
|
*/
|
|
43
58
|
export declare function peekUrlMap(env?: Env, waitUntil?: (promise: Promise<unknown>) => void): UrlMapCopy | null;
|
|
59
|
+
export interface FreshReadOptions {
|
|
60
|
+
/** The proxy's `event.waitUntil`: a read still running when the request stops waiting finishes through it. */
|
|
61
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
62
|
+
/** When the request first waited for the map (before `getUrlMap`): the 1 500 ms wait is counted from it. */
|
|
63
|
+
since?: number;
|
|
64
|
+
/** Whether the request still needs a fresh read on this copy (after joining the read in flight); default yes. */
|
|
65
|
+
needs?: (copy: UrlMapCopy) => boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The copy after one fresh read, for a page whose market-shaped first segment the copy sends to the root: the URL may
|
|
69
|
+
* have been set up, or its market gone live, since the last refresh. Joins the read in flight first (never two at
|
|
70
|
+
* once; it went through the CDN, so it may be as old) and stops there when its map no longer `needs` one. Otherwise it
|
|
71
|
+
* reads past the CDN, at most once per `freshUrlMapPath` value (10 s) per instance and never while the copy is stale
|
|
72
|
+
* (in an outage the 30 s retry is the only read) or since a fresh read failed (until the plain refresh answers). A
|
|
73
|
+
* failed fresh read keeps the copy as it is; an answer at a lower revision than the copy is ignored (`refresh`).
|
|
74
|
+
*
|
|
75
|
+
* Joining and the fresh read share one 1 500 ms wait counted from `since`, so a request never waits for the map longer
|
|
76
|
+
* than one read; a read still running then finishes through `waitUntil` for the next request.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getFreshUrlMap(env?: Env, { waitUntil, since, needs }?: FreshReadOptions): Promise<UrlMapCopy | null>;
|
|
44
79
|
/** A cold instance's 503 for a market-shaped path gives up after this long without a map (a revoked key, a WAF). */
|
|
45
80
|
export declare const MAX_COLD_503_MS: number;
|
|
46
81
|
/** Milliseconds since this instance's first failed read with no map yet; 0 once it has one (or before it tried). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-map.d.ts","sourceRoot":"","sources":["../../src/edge/url-map.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"url-map.d.ts","sourceRoot":"","sources":["../../src/edge/url-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,KAAK,W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c,CAAC,GAAG,GAAE,GAAiB,EAAE,EAAE,SAAS,EAAE,KAAkB,EAAE,KAAK,EAAE,GAAE,gBAAqB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAcxJ;AAED,oHAAoH;AACpH,eAAO,MAAM,eAAe,QAAc,CAAA;AAE1C,oHAAoH;AACpH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,gBAAgB,CAAA;AAKvG;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,GAAG,GAAE,GAAiB,GAAG,IAAI,CAanJ;AAED,uDAAuD;AACvD,wBAAgB,WAAW,IAAI,IAAI,CAWlC"}
|
package/dist/edge/url-map.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isNoUrlMapStatus, parseStoreUrlMap } from '../lib/market.js';
|
|
1
|
+
import { freshUrlMapPath, isNoUrlMapStatus, parseStoreUrlMap } from '../lib/market.js';
|
|
2
|
+
import { within } from '../lib/utils/within.js';
|
|
2
3
|
export function edgeStoreEnv(env = process.env) {
|
|
3
4
|
return {
|
|
4
5
|
medusaUrl: env.NEXT_PUBLIC_MEDUSA_BACKEND_URL,
|
|
@@ -14,12 +15,23 @@ function storeRouteHeaders({ publishableKey, storeId }) {
|
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
const storeApiBase = (store) => store.medusaUrl?.replace(/\/+$/, '') || undefined;
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* A copy older than this still routes, but never redirects: a 30x from a long-stale copy could send people away. So
|
|
20
|
+
* a page request with a copy this old awaits its due refresh instead of running it in the background (`getUrlMap`).
|
|
21
|
+
*/
|
|
18
22
|
export const MAX_REDIRECT_AGE_MS = 10 * 60_000;
|
|
19
23
|
const REFRESH_MS = 30_000;
|
|
24
|
+
/**
|
|
25
|
+
* How many plain refreshes in a row a lower revision is ignored for. An older map held by the CDN (30 s) or another
|
|
26
|
+
* Medusa task's memo (30 s) is gone by then; a lower revision still answered after that is Medusa's own (its revision
|
|
27
|
+
* went back: a Redis failover that lost increments, another Medusa endpoint), so it replaces the copy instead of
|
|
28
|
+
* holding it until it stops redirecting.
|
|
29
|
+
*/
|
|
30
|
+
const LOWER_REVISION_ANSWERS = 3;
|
|
20
31
|
/** After a failed read with no copy, the next try waits this long (a burst of cold requests never hammers Medusa). */
|
|
21
32
|
const COLD_RETRY_MS = 5_000;
|
|
22
33
|
const FETCH_TIMEOUT_MS = 1_500;
|
|
34
|
+
/** `revision`: Medusa's `x-url-map-revision` for this copy, null when its answer had none (or the empty map). */
|
|
23
35
|
let copy = null;
|
|
24
36
|
/** The map of a store API that has none: no market URL, nothing to resolve. */
|
|
25
37
|
const NO_MAP = { version: '', hreflang: false, language: '', rootCountries: [], presences: [] };
|
|
@@ -28,62 +40,139 @@ let nextTryAt = Number.NEGATIVE_INFINITY;
|
|
|
28
40
|
/** When the first read of a cold instance failed (null: a copy exists, or no read failed yet). */
|
|
29
41
|
let coldSince = null;
|
|
30
42
|
let refreshing = null;
|
|
31
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The `?fresh=` value (`freshUrlMapPath`) of the last fresh read tried: one per value per instance (a second would get
|
|
45
|
+
* the CDN's copy of the first). An attempt marker on purpose, set before the read, so a read that fails or hangs uses
|
|
46
|
+
* up its 10 s too and a bot's made-up `/en-xx` paths never make a read each.
|
|
47
|
+
*/
|
|
48
|
+
let freshReadPath = null;
|
|
49
|
+
/**
|
|
50
|
+
* The last fresh read failed (the plain refresh has not succeeded since). It stops the fresh reads, as `stale` does,
|
|
51
|
+
* but the copy is not stale: the plain refresh confirmed it, and a fresh read that times out must not send a
|
|
52
|
+
* `map_stale` beacon or hold back the rechecks of a healthy store for 30 s.
|
|
53
|
+
*/
|
|
54
|
+
let freshFailed = false;
|
|
55
|
+
/** Plain refreshes in a row answered at a lower revision than the copy (ignored), up to LOWER_REVISION_ANSWERS. */
|
|
56
|
+
let lowerAnswers = 0;
|
|
57
|
+
/** The store API (Medusa URL and store id) the copy is of; null after a reset. */
|
|
58
|
+
let copyStore = null;
|
|
59
|
+
/**
|
|
60
|
+
* Medusa's `x-url-map-revision`: a decimal integer per tenant, strictly increasing on every write that changes the
|
|
61
|
+
* map (medusa-backend-orchestrator `/store/url-map`). Null when absent (an older Medusa, or one that cannot read its
|
|
62
|
+
* revision from Redis) or malformed: no order, the answer replaces the copy. A `bigint`, so no size of it loses
|
|
63
|
+
* precision.
|
|
64
|
+
*/
|
|
65
|
+
function revisionOf(res) {
|
|
66
|
+
const value = res.headers.get('x-url-map-revision')?.trim();
|
|
67
|
+
return value && /^\d+$/.test(value) ? BigInt(value) : null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `freshPath` (`freshUrlMapPath`, taken once by the caller, so the read is the value it recorded): read past the CDN
|
|
71
|
+
* in front of Medusa. It leaves the 30 s refresh clock alone: a failed one must not hold the next refresh back 30 s;
|
|
72
|
+
* the refresh comes when it was due.
|
|
73
|
+
*/
|
|
74
|
+
async function refresh(base, store, freshPath = null) {
|
|
75
|
+
const fresh = freshPath !== null;
|
|
76
|
+
const owner = copyStore;
|
|
32
77
|
try {
|
|
33
|
-
const res = await fetch(`${base}/store/url-map`, {
|
|
78
|
+
const res = await fetch(`${base}${freshPath ?? '/store/url-map'}`, {
|
|
34
79
|
headers: { ...storeRouteHeaders(store), ...(copy?.etag ? { 'if-none-match': copy.etag } : {}) },
|
|
35
80
|
cache: 'no-store',
|
|
36
81
|
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
37
82
|
});
|
|
83
|
+
const body = res.ok ? await res.json().catch(() => undefined) : undefined;
|
|
84
|
+
if (owner !== copyStore)
|
|
85
|
+
return; // the store API changed while this read ran: the answer is not this copy's
|
|
86
|
+
const revision = revisionOf(res);
|
|
87
|
+
// An older map (the CDN's 30 s copy or another task's memo, after a fresh read brought a newer one): copy stays.
|
|
88
|
+
const lower = res.ok && copy !== null && copy.revision !== null && revision !== null && revision < copy.revision;
|
|
89
|
+
if (lower && (fresh || lowerAnswers < LOWER_REVISION_ANSWERS)) {
|
|
90
|
+
if (!fresh)
|
|
91
|
+
lowerAnswers++;
|
|
92
|
+
answered(fresh);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
lowerAnswers = 0;
|
|
96
|
+
// A 304 is the copy's own revision: Medusa folds the revision into the ETag.
|
|
38
97
|
if (res.status === 304 && copy) {
|
|
39
98
|
copy.confirmedAt = Date.now();
|
|
40
|
-
|
|
99
|
+
answered(fresh);
|
|
41
100
|
return;
|
|
42
101
|
}
|
|
43
102
|
const goodCopy = copy !== null && copy.value !== NO_MAP;
|
|
44
103
|
if (isNoUrlMapStatus(res.status) && !goodCopy) {
|
|
45
|
-
copy = { value: NO_MAP, etag: null, confirmedAt: Date.now() };
|
|
46
|
-
|
|
104
|
+
copy = { value: NO_MAP, etag: null, confirmedAt: Date.now(), revision: null };
|
|
105
|
+
answered(fresh);
|
|
47
106
|
return;
|
|
48
107
|
}
|
|
49
|
-
const value = res.ok ? parseStoreUrlMap(
|
|
108
|
+
const value = res.ok ? parseStoreUrlMap(body) : null;
|
|
50
109
|
if (!value)
|
|
51
110
|
throw new Error(`url-map: HTTP ${res.status}`);
|
|
52
|
-
copy = { value, etag: res.headers.get('etag'), confirmedAt: Date.now() };
|
|
53
|
-
|
|
111
|
+
copy = { value, etag: res.headers.get('etag'), confirmedAt: Date.now(), revision };
|
|
112
|
+
answered(fresh);
|
|
54
113
|
}
|
|
55
114
|
catch {
|
|
56
|
-
|
|
115
|
+
if (owner !== copyStore)
|
|
116
|
+
return;
|
|
117
|
+
if (fresh)
|
|
118
|
+
freshFailed = true;
|
|
119
|
+
else
|
|
120
|
+
stale = true;
|
|
57
121
|
}
|
|
58
122
|
finally {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
123
|
+
if (owner === copyStore) {
|
|
124
|
+
coldSince = copy ? null : (coldSince ?? Date.now());
|
|
125
|
+
// With a copy the next try is in 30 s; without one, in 5 s.
|
|
126
|
+
if (!fresh)
|
|
127
|
+
nextTryAt = Date.now() + (copy ? REFRESH_MS : COLD_RETRY_MS);
|
|
128
|
+
}
|
|
62
129
|
}
|
|
63
130
|
}
|
|
64
|
-
/**
|
|
65
|
-
function
|
|
131
|
+
/** Medusa answered: the copy is not stale, and a plain refresh's answer lets fresh reads go again. */
|
|
132
|
+
function answered(fresh) {
|
|
133
|
+
stale = false;
|
|
134
|
+
if (!fresh)
|
|
135
|
+
freshFailed = false;
|
|
136
|
+
}
|
|
137
|
+
/** The refresh in flight, starting one when due (or a fresh read of `freshPath`); null when none is or no store API. */
|
|
138
|
+
function refreshIfDue(env, freshPath = null) {
|
|
66
139
|
const store = edgeStoreEnv(env);
|
|
67
140
|
const base = storeApiBase(store);
|
|
68
|
-
if (!base || (!refreshing && Date.now() < nextTryAt))
|
|
141
|
+
if (!base || (!refreshing && freshPath === null && Date.now() < nextTryAt))
|
|
69
142
|
return null;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
143
|
+
if (!refreshing) {
|
|
144
|
+
const read = refresh(base, store, freshPath).finally(() => {
|
|
145
|
+
if (refreshing === read)
|
|
146
|
+
refreshing = null; // a read from before a store change never clears a later one
|
|
147
|
+
});
|
|
148
|
+
refreshing = read;
|
|
149
|
+
}
|
|
73
150
|
return refreshing;
|
|
74
151
|
}
|
|
152
|
+
/** The copy is of the store API `env` names (Medusa URL and store id); for another one it starts over. */
|
|
153
|
+
function forStore(env) {
|
|
154
|
+
const { medusaUrl, storeId } = edgeStoreEnv(env);
|
|
155
|
+
const key = `${medusaUrl ?? ''} ${storeId ?? ''}`;
|
|
156
|
+
if (key === copyStore)
|
|
157
|
+
return;
|
|
158
|
+
resetUrlMap();
|
|
159
|
+
copyStore = key;
|
|
160
|
+
}
|
|
75
161
|
const currentCopy = () => copy && { value: copy.value, stale, age: Date.now() - copy.confirmedAt };
|
|
76
162
|
/**
|
|
77
163
|
* The URL map for this request, or null when none was ever read (no Medusa URL, or Medusa never answered).
|
|
78
164
|
* `waitUntil` (the proxy's `event.waitUntil`) lets a warm instance refresh in the background; without it every
|
|
79
|
-
* refresh is awaited.
|
|
165
|
+
* refresh is awaited. A due refresh of a copy older than MAX_REDIRECT_AGE_MS is awaited too (at most 1 500 ms), so
|
|
166
|
+
* an instance idle that long decides on a fresh map, not on one that never redirects; if it fails, the old copy is
|
|
167
|
+
* served (it routes, never redirects).
|
|
80
168
|
*/
|
|
81
169
|
export async function getUrlMap(env = process.env, waitUntil) {
|
|
170
|
+
forStore(env);
|
|
82
171
|
if (!storeApiBase(edgeStoreEnv(env)))
|
|
83
172
|
return null;
|
|
84
173
|
const pending = refreshIfDue(env);
|
|
85
174
|
if (pending) {
|
|
86
|
-
if (copy && waitUntil)
|
|
175
|
+
if (copy && waitUntil && Date.now() - copy.confirmedAt < MAX_REDIRECT_AGE_MS)
|
|
87
176
|
waitUntil(pending);
|
|
88
177
|
else
|
|
89
178
|
await pending;
|
|
@@ -96,11 +185,42 @@ export async function getUrlMap(env = process.env, waitUntil) {
|
|
|
96
185
|
* without it.
|
|
97
186
|
*/
|
|
98
187
|
export function peekUrlMap(env = process.env, waitUntil) {
|
|
188
|
+
forStore(env);
|
|
99
189
|
const pending = waitUntil ? refreshIfDue(env) : null;
|
|
100
190
|
if (pending)
|
|
101
191
|
waitUntil?.(pending);
|
|
102
192
|
return currentCopy();
|
|
103
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* The copy after one fresh read, for a page whose market-shaped first segment the copy sends to the root: the URL may
|
|
196
|
+
* have been set up, or its market gone live, since the last refresh. Joins the read in flight first (never two at
|
|
197
|
+
* once; it went through the CDN, so it may be as old) and stops there when its map no longer `needs` one. Otherwise it
|
|
198
|
+
* reads past the CDN, at most once per `freshUrlMapPath` value (10 s) per instance and never while the copy is stale
|
|
199
|
+
* (in an outage the 30 s retry is the only read) or since a fresh read failed (until the plain refresh answers). A
|
|
200
|
+
* failed fresh read keeps the copy as it is; an answer at a lower revision than the copy is ignored (`refresh`).
|
|
201
|
+
*
|
|
202
|
+
* Joining and the fresh read share one 1 500 ms wait counted from `since`, so a request never waits for the map longer
|
|
203
|
+
* than one read; a read still running then finishes through `waitUntil` for the next request.
|
|
204
|
+
*/
|
|
205
|
+
export async function getFreshUrlMap(env = process.env, { waitUntil, since = Date.now(), needs } = {}) {
|
|
206
|
+
forStore(env);
|
|
207
|
+
const deadline = since + FETCH_TIMEOUT_MS;
|
|
208
|
+
if (refreshing)
|
|
209
|
+
await within(refreshing, deadline - Date.now());
|
|
210
|
+
const joined = currentCopy();
|
|
211
|
+
if (joined && needs && !needs(joined))
|
|
212
|
+
return joined;
|
|
213
|
+
const path = freshUrlMapPath();
|
|
214
|
+
if (!refreshing && !stale && !freshFailed && path !== freshReadPath) {
|
|
215
|
+
freshReadPath = path;
|
|
216
|
+
const read = refreshIfDue(env, path);
|
|
217
|
+
if (read)
|
|
218
|
+
waitUntil?.(read);
|
|
219
|
+
}
|
|
220
|
+
if (refreshing)
|
|
221
|
+
await within(refreshing, deadline - Date.now());
|
|
222
|
+
return currentCopy();
|
|
223
|
+
}
|
|
104
224
|
/** A cold instance's 503 for a market-shaped path gives up after this long without a map (a revoked key, a WAF). */
|
|
105
225
|
export const MAX_COLD_503_MS = 10 * 60_000;
|
|
106
226
|
/** Milliseconds since this instance's first failed read with no map yet; 0 once it has one (or before it tried). */
|
|
@@ -134,6 +254,10 @@ export function resetUrlMap() {
|
|
|
134
254
|
coldSince = null;
|
|
135
255
|
stale = false;
|
|
136
256
|
nextTryAt = Number.NEGATIVE_INFINITY;
|
|
257
|
+
freshReadPath = null;
|
|
258
|
+
freshFailed = false;
|
|
259
|
+
lowerAnswers = 0;
|
|
260
|
+
copyStore = null;
|
|
137
261
|
refreshing = null;
|
|
138
262
|
signalledAt.clear();
|
|
139
263
|
}
|
package/dist/edge/url-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-map.js","sourceRoot":"","sources":["../../src/edge/url-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAoB,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"url-map.js","sourceRoot":"","sources":["../../src/edge/url-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAoB,MAAM,kBAAkB,CAAA;AACxG,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAmC/C,MAAM,UAAU,YAAY,CAAC,MAAW,OAAO,CAAC,GAAG;IACjD,OAAO;QACL,SAAS,EAAE,GAAG,CAAC,8BAA8B;QAC7C,cAAc,EAAE,GAAG,CAAC,kCAAkC;QACtD,OAAO,EAAE,GAAG,CAAC,oBAAoB;KAClC,CAAA;AACH,CAAC;AAED,gHAAgH;AAChH,SAAS,iBAAiB,CAAC,EAAE,cAAc,EAAE,OAAO,EAAgB;IAClE,OAAO;QACL,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,uBAAuB,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,wBAAwB,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAA;AACH,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,KAAmB,EAAsB,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,SAAS,CAAA;AAUnH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,MAAM,CAAA;AAE9C,MAAM,UAAU,GAAG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,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACtB,IAAI,CAAC,IAAI,IAAI,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,iBAAiB,CAAC,GAAG,eAAe;QAAE,OAAM;IAChG,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,IAAI,uBAAuB,EAAE;QACjD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,EAAE;QAC5E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC;QAC9B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC;KAC9C,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IACzB,SAAS,EAAE,CAAC,IAAI,CAAC,CAAA;AACnB,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,WAAW;IACzB,IAAI,GAAG,IAAI,CAAA;IACX,SAAS,GAAG,IAAI,CAAA;IAChB,KAAK,GAAG,KAAK,CAAA;IACb,SAAS,GAAG,MAAM,CAAC,iBAAiB,CAAA;IACpC,aAAa,GAAG,IAAI,CAAA;IACpB,WAAW,GAAG,KAAK,CAAA;IACnB,YAAY,GAAG,CAAC,CAAA;IAChB,SAAS,GAAG,IAAI,CAAA;IAChB,UAAU,GAAG,IAAI,CAAA;IACjB,WAAW,CAAC,KAAK,EAAE,CAAA;AACrB,CAAC"}
|
|
@@ -92,7 +92,13 @@ export interface UseCheckoutGateParams {
|
|
|
92
92
|
export interface UseCheckoutGateResult {
|
|
93
93
|
/** Contact section is ready for payment: logged in, or a valid email typed. */
|
|
94
94
|
contactReady: boolean;
|
|
95
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Every field the CURRENT country requires is filled in, plus the phone and
|
|
97
|
+
* address line 2 when the merchant made them required in Settings > Checkout.
|
|
98
|
+
* Shipping form only: a separate billing address missing a required line 2
|
|
99
|
+
* is not caught here. The server refuses its session and useCheckout retries
|
|
100
|
+
* once the billing address on the cart has it.
|
|
101
|
+
*/
|
|
96
102
|
addressFilled: boolean;
|
|
97
103
|
/** No react-hook-form validation errors on any address field. */
|
|
98
104
|
addressNoErrors: boolean;
|
|
@@ -120,6 +126,9 @@ export interface UseCheckoutGateResult {
|
|
|
120
126
|
* Pure derivation of checkout purchase-readiness, extracted verbatim out of
|
|
121
127
|
* app/checkout/page.tsx. No side effects, no state — every value here is
|
|
122
128
|
* recomputed from its inputs each call, exactly as it was inline in the page.
|
|
129
|
+
* The one outside input is the merchant's checkout settings, read from the
|
|
130
|
+
* shared ['store-config'] cache, so every store gets the required-field rules
|
|
131
|
+
* without its page having to pass them.
|
|
123
132
|
*
|
|
124
133
|
* This hook lives under hooks/ specifically so the Pay-now gating logic stays
|
|
125
134
|
* correct regardless of how the surrounding checkout page gets restructured.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkout-gate.d.ts","sourceRoot":"","sources":["../../src/hooks/use-checkout-gate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-checkout-gate.d.ts","sourceRoot":"","sources":["../../src/hooks/use-checkout-gate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AA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4,10 +4,15 @@ import { hasNoPostalCode, getPostalCodeRule } from '../lib/checkout/postal-codes
|
|
|
4
4
|
import { getRegionRule } from '../lib/checkout/region-rules.js';
|
|
5
5
|
import { countryDisplayName } from '../lib/checkout/country-selection.js';
|
|
6
6
|
import { checkoutMessages, configuredLocale } from '../lib/l10n/checkout-messages.js';
|
|
7
|
+
import { useCheckoutSettings } from './use-checkout-settings.js';
|
|
8
|
+
import { requiredAddressFields } from '../lib/checkout/required-checkout-fields.js';
|
|
7
9
|
/**
|
|
8
10
|
* Pure derivation of checkout purchase-readiness, extracted verbatim out of
|
|
9
11
|
* app/checkout/page.tsx. No side effects, no state — every value here is
|
|
10
12
|
* recomputed from its inputs each call, exactly as it was inline in the page.
|
|
13
|
+
* The one outside input is the merchant's checkout settings, read from the
|
|
14
|
+
* shared ['store-config'] cache, so every store gets the required-field rules
|
|
15
|
+
* without its page having to pass them.
|
|
11
16
|
*
|
|
12
17
|
* This hook lives under hooks/ specifically so the Pay-now gating logic stays
|
|
13
18
|
* correct regardless of how the surrounding checkout page gets restructured.
|
|
@@ -16,6 +21,8 @@ export function useCheckoutGate(params) {
|
|
|
16
21
|
const { hasItems, isDigitalOnly, isUpdating, isPlacingOrder, expressBusy, paymentAuthorized, isLoggedIn, address, errors, selectedShipping, hasShippingMethod, shippingCountryBlocked, cartCountryMatchesForm, addressSaveError, billingComplete, availableProviders, selectedProviderId, sessions, confirmReady, codSelected, noPaymentRequired, zeroTotalBlocked, } = params;
|
|
17
22
|
const locale = params.locale ?? configuredLocale();
|
|
18
23
|
const { gate } = checkoutMessages(locale);
|
|
24
|
+
const { data: checkoutSettings } = useCheckoutSettings();
|
|
25
|
+
const merchantRequires = requiredAddressFields(checkoutSettings);
|
|
19
26
|
// Contact is "ready" for payment when the buyer is logged in (email is on
|
|
20
27
|
// the account) or has a valid email typed in. This gates the Pay-now flow
|
|
21
28
|
// so that clearing the email after Stripe has initialized can't complete
|
|
@@ -41,7 +48,12 @@ export function useCheckoutGate(params) {
|
|
|
41
48
|
!!address.city &&
|
|
42
49
|
(!acPostalNeeded || !!address.postal_code) &&
|
|
43
50
|
(!acRegionNeeded || !!address.province) &&
|
|
44
|
-
(!acIsMexico || !!address.address_2)
|
|
51
|
+
(!acIsMexico || !!address.address_2) &&
|
|
52
|
+
// The server refuses the payment session without these (required_checkout_fields_missing).
|
|
53
|
+
// Leaving them out here let the address auto-save and collapse with them empty, and the
|
|
54
|
+
// card form then waited forever on a session that was never created.
|
|
55
|
+
(!merchantRequires.phone || !!address.phone?.trim()) &&
|
|
56
|
+
(!merchantRequires.address2 || !!address.address_2?.trim());
|
|
45
57
|
const addressNoErrors = !errors.country_code &&
|
|
46
58
|
!errors.first_name &&
|
|
47
59
|
!errors.last_name &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkout-gate.js","sourceRoot":"","sources":["../../src/hooks/use-checkout-gate.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AACzE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"use-checkout-gate.js","sourceRoot":"","sources":["../../src/hooks/use-checkout-gate.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AACzE,OAAO,EAAE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,CAAC,CAAC,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC,sBAAsB,CAAA;IAC1D,IAAI,CAAC,CAAC,CAAC,gBAAgB;QAAE,OAAO,IAAI,CAAC,qBAAqB,CAAA;IAC1D,IAAI,CAAC,CAAC,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC,gBAAgB,CAAA;IACjD,IAAI,CAAC,CAAC,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC,mBAAmB,CAAA;IACpD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -69,9 +69,13 @@ export declare function describeUnauthorizedIntent(status?: string | null, local
|
|
|
69
69
|
export type SessionDataMap = Record<string, Record<string, unknown> | null>;
|
|
70
70
|
/**
|
|
71
71
|
* Shown next to the shipping method after the backend refused a payment
|
|
72
|
-
* session because the carrier rate changed (409 `shipping_rate_changed`)
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* session because the carrier rate changed (409 `shipping_rate_changed`),
|
|
73
|
+
* refused the chosen method itself (kind `unavailable`, cleared by the next
|
|
74
|
+
* address save), or no longer offers the cart's method for its address (kind
|
|
75
|
+
* `unavailable`, cleared once the cart holds an offered method). `keepSelection`
|
|
76
|
+
* false: the chosen option is gone, refused, or
|
|
77
|
+
* a second refusal followed the automatic retry, so the shopper must pick a
|
|
78
|
+
* method again.
|
|
75
79
|
*/
|
|
76
80
|
export interface ShippingNotice {
|
|
77
81
|
change: ShippingRateChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkout.d.ts","sourceRoot":"","sources":["../../src/hooks/use-checkout.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,0CAA0C,CAAA;
|
|
1
|
+
{"version":3,"file":"use-checkout.d.ts","sourceRoot":"","sources":["../../src/hooks/use-checkout.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,0CAA0C,CAAA;AASjD,OAAO,EAAmC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