@zappie/sdk 0.12.0 → 0.14.0
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 +26 -0
- package/README.md +97 -4
- package/dist/config/index.d.ts +5 -1
- package/dist/debug.js +1 -1
- package/dist/index.js +1 -1
- package/dist/navigation-progress/index.d.ts +42 -0
- package/dist/navigation-progress/index.js +42 -0
- package/dist/navigation-progress/index.js.map +6 -0
- package/dist/navigation-progress/styles.css +37 -0
- package/dist/server/chosen-branch.js +24 -2
- package/dist/server/chosen-branch.js.map +1 -1
- package/dist/server/edge-cache.js +395 -0
- package/dist/server/edge-cache.js.map +6 -0
- package/dist/server/index.d.ts +161 -7
- package/dist/server/index.js +24 -0
- package/dist/server/index.js.map +1 -1
- package/dist/site-config/validate.js +8 -11
- package/dist/site-config/validate.js.map +1 -1
- package/dist/vite/index.d.ts +39 -4
- package/dist/vite/index.js +112 -7
- package/package.json +10 -3
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
// src/server/edge-cache.ts
|
|
2
|
+
import { createSecurityNonce } from "./security.js";
|
|
3
|
+
var EDGE_CACHE_HEADER = "x-zappie-edge-cache";
|
|
4
|
+
var STORED_AT = "x-zappie-stored-at";
|
|
5
|
+
var FRESH_FOR = "x-zappie-fresh-for";
|
|
6
|
+
var STALE_FOR = "x-zappie-stale-for";
|
|
7
|
+
var ORIGIN_CACHE_CONTROL = "x-zappie-origin-cache-control";
|
|
8
|
+
var CACHE_NAME = "zappie";
|
|
9
|
+
var opened;
|
|
10
|
+
function openEdgeCache() {
|
|
11
|
+
opened ?? (opened = (async () => {
|
|
12
|
+
try {
|
|
13
|
+
return typeof caches === "undefined" ? void 0 : await caches.open(CACHE_NAME);
|
|
14
|
+
} catch {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
})());
|
|
18
|
+
return opened;
|
|
19
|
+
}
|
|
20
|
+
async function sha256(value) {
|
|
21
|
+
const digest = await crypto.subtle.digest(
|
|
22
|
+
"SHA-256",
|
|
23
|
+
new TextEncoder().encode(value)
|
|
24
|
+
);
|
|
25
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
26
|
+
}
|
|
27
|
+
function sharedFreshness(cacheControl) {
|
|
28
|
+
if (!cacheControl || /\b(?:private|no-store|no-cache)\b/i.test(cacheControl)) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
const seconds = (name) => {
|
|
32
|
+
const match = new RegExp(`(?:^|[,\\s])${name}=(\\d+)`, "i").exec(
|
|
33
|
+
cacheControl
|
|
34
|
+
);
|
|
35
|
+
return match ? Number(match[1]) : void 0;
|
|
36
|
+
};
|
|
37
|
+
const fresh = seconds("s-maxage") ?? seconds("max-age") ?? 0;
|
|
38
|
+
if (fresh <= 0) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
return { fresh, stale: seconds("stale-while-revalidate") ?? 0 };
|
|
42
|
+
}
|
|
43
|
+
function storable(response, life, now) {
|
|
44
|
+
const headers = new Headers(response.headers);
|
|
45
|
+
headers.delete("set-cookie");
|
|
46
|
+
headers.delete(EDGE_CACHE_HEADER);
|
|
47
|
+
const origin = response.headers.get("cache-control");
|
|
48
|
+
if (origin) {
|
|
49
|
+
headers.set(ORIGIN_CACHE_CONTROL, origin);
|
|
50
|
+
}
|
|
51
|
+
headers.set(STORED_AT, String(now));
|
|
52
|
+
headers.set(FRESH_FOR, String(life.fresh));
|
|
53
|
+
headers.set(STALE_FOR, String(life.stale));
|
|
54
|
+
headers.set("cache-control", `public, max-age=${life.fresh + life.stale}`);
|
|
55
|
+
return new Response(response.body, { status: response.status, headers });
|
|
56
|
+
}
|
|
57
|
+
function served(cached, status, age) {
|
|
58
|
+
const headers = new Headers(cached.headers);
|
|
59
|
+
const origin = headers.get(ORIGIN_CACHE_CONTROL);
|
|
60
|
+
if (origin) {
|
|
61
|
+
headers.set("cache-control", origin);
|
|
62
|
+
} else {
|
|
63
|
+
headers.delete("cache-control");
|
|
64
|
+
}
|
|
65
|
+
for (const name of [STORED_AT, FRESH_FOR, STALE_FOR, ORIGIN_CACHE_CONTROL]) {
|
|
66
|
+
headers.delete(name);
|
|
67
|
+
}
|
|
68
|
+
headers.set("age", String(Math.max(0, Math.floor(age))));
|
|
69
|
+
headers.set(EDGE_CACHE_HEADER, status);
|
|
70
|
+
return new Response(cached.body, { status: cached.status, headers });
|
|
71
|
+
}
|
|
72
|
+
function discard(response) {
|
|
73
|
+
response.body?.cancel().catch(() => {
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function marked(response, status) {
|
|
77
|
+
const out = new Response(response.body, response);
|
|
78
|
+
out.headers.set(EDGE_CACHE_HEADER, status);
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
async function lookup(cache, key, now) {
|
|
82
|
+
const cached = await cache.match(key);
|
|
83
|
+
if (!cached) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const storedAt = Number(cached.headers.get(STORED_AT));
|
|
87
|
+
const life = {
|
|
88
|
+
fresh: Number(cached.headers.get(FRESH_FOR)),
|
|
89
|
+
stale: Number(cached.headers.get(STALE_FOR))
|
|
90
|
+
};
|
|
91
|
+
if (!Number.isFinite(storedAt) || !Number.isFinite(life.fresh) || !Number.isFinite(life.stale)) {
|
|
92
|
+
discard(cached);
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
return { response: cached, age: (now - storedAt) / 1e3, life };
|
|
96
|
+
}
|
|
97
|
+
var refreshing = /* @__PURE__ */ new Map();
|
|
98
|
+
function refreshOnce(ctx, key, refresh) {
|
|
99
|
+
if (refreshing.has(key.url)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const running = refresh().catch(() => {
|
|
103
|
+
}).finally(() => refreshing.delete(key.url));
|
|
104
|
+
refreshing.set(key.url, running);
|
|
105
|
+
ctx.waitUntil(running);
|
|
106
|
+
}
|
|
107
|
+
var SHARED_READS = /\/(?:store|menus)$/;
|
|
108
|
+
function apiCacheBypass(request) {
|
|
109
|
+
if (request.method !== "GET") {
|
|
110
|
+
return "method";
|
|
111
|
+
}
|
|
112
|
+
if (!SHARED_READS.test(new URL(request.url).pathname)) {
|
|
113
|
+
return "path";
|
|
114
|
+
}
|
|
115
|
+
if (!/^Bearer pk_(?:test|live)_/.test(
|
|
116
|
+
request.headers.get("authorization") ?? ""
|
|
117
|
+
)) {
|
|
118
|
+
return "credentials";
|
|
119
|
+
}
|
|
120
|
+
if (request.headers.has("cookie")) {
|
|
121
|
+
return "cookie";
|
|
122
|
+
}
|
|
123
|
+
if (request.headers.has("if-none-match")) {
|
|
124
|
+
return "conditional";
|
|
125
|
+
}
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
async function apiCacheKey(request) {
|
|
129
|
+
const key = (request.headers.get("authorization") ?? "").replace(
|
|
130
|
+
/^Bearer\s+/,
|
|
131
|
+
""
|
|
132
|
+
);
|
|
133
|
+
const url = new URL(request.url);
|
|
134
|
+
const identity = await sha256(
|
|
135
|
+
JSON.stringify([key, request.headers.get("zappie-version") ?? ""])
|
|
136
|
+
);
|
|
137
|
+
return new Request(
|
|
138
|
+
`https://zappie-api-cache.internal/${identity.slice(0, 40)}/${url.host}${url.pathname}${url.search}`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function cachedApiFetch(options = {}) {
|
|
142
|
+
const upstream = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
143
|
+
const now = options.now ?? Date.now;
|
|
144
|
+
const source = () => options.cache ?? openEdgeCache();
|
|
145
|
+
return async (input, init) => {
|
|
146
|
+
const request = new Request(input, init);
|
|
147
|
+
if (apiCacheBypass(request)) {
|
|
148
|
+
return upstream(request);
|
|
149
|
+
}
|
|
150
|
+
let cache;
|
|
151
|
+
let key;
|
|
152
|
+
let hit;
|
|
153
|
+
try {
|
|
154
|
+
cache = await source();
|
|
155
|
+
if (cache) {
|
|
156
|
+
key = await apiCacheKey(request);
|
|
157
|
+
hit = await lookup(cache, key, now());
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
cache = void 0;
|
|
161
|
+
}
|
|
162
|
+
if (!cache) {
|
|
163
|
+
return upstream(request);
|
|
164
|
+
}
|
|
165
|
+
const store = async (response) => {
|
|
166
|
+
const life = sharedFreshness(response.headers.get("cache-control"));
|
|
167
|
+
if (response.status !== 200 || !life || response.headers.has("set-cookie")) {
|
|
168
|
+
return response;
|
|
169
|
+
}
|
|
170
|
+
const copy = response.clone();
|
|
171
|
+
const put = cache.put(key, storable(copy, life, now())).catch(() => {
|
|
172
|
+
});
|
|
173
|
+
if (options.ctx) {
|
|
174
|
+
options.ctx.waitUntil(put);
|
|
175
|
+
} else {
|
|
176
|
+
await put;
|
|
177
|
+
}
|
|
178
|
+
return response;
|
|
179
|
+
};
|
|
180
|
+
if (hit && hit.age < hit.life.fresh) {
|
|
181
|
+
return served(hit.response, "HIT", hit.age);
|
|
182
|
+
}
|
|
183
|
+
if (hit && options.ctx && hit.age < hit.life.fresh + hit.life.stale) {
|
|
184
|
+
const etag = hit.response.headers.get("etag");
|
|
185
|
+
const kept = hit.response.clone();
|
|
186
|
+
refreshOnce(options.ctx, key, async () => {
|
|
187
|
+
const headers = new Headers(request.headers);
|
|
188
|
+
if (etag) {
|
|
189
|
+
headers.set("if-none-match", etag);
|
|
190
|
+
}
|
|
191
|
+
const response = await upstream(
|
|
192
|
+
new Request(request.url, {
|
|
193
|
+
method: "GET",
|
|
194
|
+
headers,
|
|
195
|
+
redirect: "manual"
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
if (response.status === 304) {
|
|
199
|
+
discard(response);
|
|
200
|
+
const life2 = sharedFreshness(response.headers.get("cache-control")) ?? hit.life;
|
|
201
|
+
const restamped = served(kept, "HIT", 0);
|
|
202
|
+
restamped.headers.delete("age");
|
|
203
|
+
restamped.headers.delete(EDGE_CACHE_HEADER);
|
|
204
|
+
await cache.put(key, storable(restamped, life2, now()));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const life = sharedFreshness(response.headers.get("cache-control"));
|
|
208
|
+
if (response.status === 200 && life && !response.headers.has("set-cookie")) {
|
|
209
|
+
await cache.put(key, storable(response, life, now()));
|
|
210
|
+
} else {
|
|
211
|
+
discard(response);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
return served(hit.response, "STALE", hit.age);
|
|
215
|
+
}
|
|
216
|
+
if (hit) {
|
|
217
|
+
discard(hit.response);
|
|
218
|
+
}
|
|
219
|
+
return store(await upstream(request));
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
var SESSION_COOKIE = /^(?:__Host-zappie_|__Host-zp_)|(?:^|[_-])(?:session|sess|sid|auth|token|jwt)(?:$|[_-])/i;
|
|
223
|
+
function cookieNames(request) {
|
|
224
|
+
return (request.headers.get("cookie") ?? "").split(";").map((part) => part.slice(0, part.indexOf("=") >>> 0).trim()).filter(Boolean);
|
|
225
|
+
}
|
|
226
|
+
function cookieValue(request, name) {
|
|
227
|
+
for (const part of (request.headers.get("cookie") ?? "").split(";")) {
|
|
228
|
+
const index = part.indexOf("=");
|
|
229
|
+
if (index > 0 && part.slice(0, index).trim() === name) {
|
|
230
|
+
return part.slice(index + 1).trim();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return "";
|
|
234
|
+
}
|
|
235
|
+
function pageCacheBypass(request, options = {}) {
|
|
236
|
+
if (request.method !== "GET") {
|
|
237
|
+
return "method";
|
|
238
|
+
}
|
|
239
|
+
if (["x-zappie-draft", "x-zappie-review", "x-zappie-preview"].some(
|
|
240
|
+
(name) => request.headers.has(name)
|
|
241
|
+
) || new URL(request.url).searchParams.has("preview")) {
|
|
242
|
+
return "preview";
|
|
243
|
+
}
|
|
244
|
+
if (request.headers.has("x-zappie-site-state")) {
|
|
245
|
+
return "closed";
|
|
246
|
+
}
|
|
247
|
+
if (request.headers.has("authorization")) {
|
|
248
|
+
return "authorization";
|
|
249
|
+
}
|
|
250
|
+
if (request.headers.has("x-forwarded-host") || request.headers.has("forwarded")) {
|
|
251
|
+
return "forwarded";
|
|
252
|
+
}
|
|
253
|
+
const own = new Set(options.privateCookies ?? []);
|
|
254
|
+
if (cookieNames(request).some(
|
|
255
|
+
(name) => own.has(name) || SESSION_COOKIE.test(name)
|
|
256
|
+
)) {
|
|
257
|
+
return "session";
|
|
258
|
+
}
|
|
259
|
+
return void 0;
|
|
260
|
+
}
|
|
261
|
+
async function pageCacheKey(request, options) {
|
|
262
|
+
const identity = await sha256(
|
|
263
|
+
JSON.stringify([
|
|
264
|
+
request.url,
|
|
265
|
+
options.branchCookie ? cookieValue(request, options.branchCookie) : "",
|
|
266
|
+
options.deployId,
|
|
267
|
+
request.headers.get("x-zappie-site") ?? "",
|
|
268
|
+
request.headers.get("x-zappie-key") ?? ""
|
|
269
|
+
])
|
|
270
|
+
);
|
|
271
|
+
return new Request(`https://zappie-page-cache.internal/${identity}`);
|
|
272
|
+
}
|
|
273
|
+
function pageStoreBypass(response, fallback) {
|
|
274
|
+
if (response.status !== 200) {
|
|
275
|
+
return "status";
|
|
276
|
+
}
|
|
277
|
+
if (response.headers.has("set-cookie")) {
|
|
278
|
+
return "set-cookie";
|
|
279
|
+
}
|
|
280
|
+
if (response.headers.has("x-zappie-closed-page")) {
|
|
281
|
+
return "closed";
|
|
282
|
+
}
|
|
283
|
+
if (/(?:^|,)\s*\*\s*(?:,|$)/.test(response.headers.get("vary") ?? "")) {
|
|
284
|
+
return "vary";
|
|
285
|
+
}
|
|
286
|
+
if (!sharedFreshness(response.headers.get("cache-control") ?? fallback ?? null)) {
|
|
287
|
+
return "cache-control";
|
|
288
|
+
}
|
|
289
|
+
return void 0;
|
|
290
|
+
}
|
|
291
|
+
var NONCE = /'nonce-([A-Za-z0-9_+/=-]+)'/;
|
|
292
|
+
var POLICY_HEADERS = [
|
|
293
|
+
"content-security-policy",
|
|
294
|
+
"content-security-policy-report-only"
|
|
295
|
+
];
|
|
296
|
+
async function rotatePageNonce(response, nonce = createSecurityNonce()) {
|
|
297
|
+
const old = POLICY_HEADERS.map(
|
|
298
|
+
(name) => NONCE.exec(response.headers.get(name) ?? "")?.[1]
|
|
299
|
+
).find(Boolean);
|
|
300
|
+
if (!old || !/^text\/html/i.test(response.headers.get("content-type") ?? "")) {
|
|
301
|
+
return response;
|
|
302
|
+
}
|
|
303
|
+
const headers = new Headers(response.headers);
|
|
304
|
+
for (const name of POLICY_HEADERS) {
|
|
305
|
+
const value = headers.get(name);
|
|
306
|
+
if (value) {
|
|
307
|
+
headers.set(name, value.replaceAll(`'nonce-${old}'`, `'nonce-${nonce}'`));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
headers.delete("content-length");
|
|
311
|
+
const body = (await response.text()).replaceAll(`nonce="${old}"`, `nonce="${nonce}"`).replaceAll(`nonce=${old}`, `nonce=${nonce}`);
|
|
312
|
+
return new Response(body, { status: response.status, headers });
|
|
313
|
+
}
|
|
314
|
+
async function cachePage(request, render, options) {
|
|
315
|
+
if (pageCacheBypass(request, options)) {
|
|
316
|
+
return marked(await render(request), "BYPASS");
|
|
317
|
+
}
|
|
318
|
+
const now = options.now ?? Date.now;
|
|
319
|
+
let cache;
|
|
320
|
+
let key;
|
|
321
|
+
let hit;
|
|
322
|
+
try {
|
|
323
|
+
cache = await (options.cache ?? openEdgeCache());
|
|
324
|
+
if (cache) {
|
|
325
|
+
key = await pageCacheKey(request, options);
|
|
326
|
+
hit = await lookup(cache, key, now());
|
|
327
|
+
}
|
|
328
|
+
} catch {
|
|
329
|
+
cache = void 0;
|
|
330
|
+
}
|
|
331
|
+
if (!cache || !key) {
|
|
332
|
+
return marked(await render(request), "BYPASS");
|
|
333
|
+
}
|
|
334
|
+
const fallback = () => options.cacheControl?.(new URL(request.url));
|
|
335
|
+
const keep = async (response) => {
|
|
336
|
+
const control = response.headers.get("cache-control") ?? fallback();
|
|
337
|
+
if (pageStoreBypass(response, control)) {
|
|
338
|
+
return void 0;
|
|
339
|
+
}
|
|
340
|
+
const life = sharedFreshness(control ?? null);
|
|
341
|
+
const shared = new Response(response.body, response);
|
|
342
|
+
if (control && !shared.headers.has("cache-control")) {
|
|
343
|
+
shared.headers.set("cache-control", control);
|
|
344
|
+
}
|
|
345
|
+
return { shared, life };
|
|
346
|
+
};
|
|
347
|
+
if (hit && hit.age < hit.life.fresh) {
|
|
348
|
+
return rotatePageNonce(served(hit.response, "HIT", hit.age));
|
|
349
|
+
}
|
|
350
|
+
if (hit && options.ctx && hit.age < hit.life.fresh + hit.life.stale) {
|
|
351
|
+
refreshOnce(options.ctx, key, async () => {
|
|
352
|
+
const kept2 = await keep(
|
|
353
|
+
await render(
|
|
354
|
+
new Request(request.url, { method: "GET", headers: request.headers })
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
if (kept2) {
|
|
358
|
+
await cache.put(key, storable(kept2.shared, kept2.life, now()));
|
|
359
|
+
} else {
|
|
360
|
+
await cache.delete(key);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
return rotatePageNonce(served(hit.response, "STALE", hit.age));
|
|
364
|
+
}
|
|
365
|
+
if (hit) {
|
|
366
|
+
discard(hit.response);
|
|
367
|
+
}
|
|
368
|
+
const rendered = await render(request);
|
|
369
|
+
const kept = await keep(rendered);
|
|
370
|
+
if (!kept) {
|
|
371
|
+
return marked(rendered, "MISS");
|
|
372
|
+
}
|
|
373
|
+
const put = cache.put(key, storable(kept.shared.clone(), kept.life, now())).catch(() => {
|
|
374
|
+
});
|
|
375
|
+
if (options.ctx) {
|
|
376
|
+
options.ctx.waitUntil(put);
|
|
377
|
+
} else {
|
|
378
|
+
await put;
|
|
379
|
+
}
|
|
380
|
+
return marked(kept.shared, "MISS");
|
|
381
|
+
}
|
|
382
|
+
export {
|
|
383
|
+
EDGE_CACHE_HEADER,
|
|
384
|
+
apiCacheBypass,
|
|
385
|
+
apiCacheKey,
|
|
386
|
+
cachePage,
|
|
387
|
+
cachedApiFetch,
|
|
388
|
+
openEdgeCache,
|
|
389
|
+
pageCacheBypass,
|
|
390
|
+
pageCacheKey,
|
|
391
|
+
pageStoreBypass,
|
|
392
|
+
rotatePageNonce,
|
|
393
|
+
sharedFreshness
|
|
394
|
+
};
|
|
395
|
+
//# sourceMappingURL=edge-cache.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/server/edge-cache.ts"],
|
|
4
|
+
"mappings": ";AAAA,SAAS,2BAA2B;AAS7B,IAAM,oBAAoB;AAEjC,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,uBAAuB;AAC7B,IAAM,aAAa;AASnB,IAAI;AAOG,SAAS,gBAAgD;AAC9D,uBAAY,YAAY;AACtB,QAAI;AACF,aAAO,OAAO,WAAW,cACrB,SACA,MAAM,OAAO,KAAK,UAAU;AAAA,IAClC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AACH,SAAO;AACT;AAGA,eAAe,OAAO,OAAgC;AACpD,QAAM,SAAS,MAAM,OAAO,OAAO;AAAA,IACjC;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,EAChC;AACA,SAAO,CAAC,GAAG,IAAI,WAAW,MAAM,CAAC,EAC9B,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAChD,KAAK,EAAE;AACZ;AAUO,SAAS,gBACd,cACuB;AACvB,MACE,CAAC,gBACD,qCAAqC,KAAK,YAAY,GACtD;AACA,WAAO;AAAA,EACT;AACA,QAAM,UAAU,CAAC,SAAiB;AAChC,UAAM,QAAQ,IAAI,OAAO,eAAe,IAAI,WAAW,GAAG,EAAE;AAAA,MAC1D;AAAA,IACF;AACA,WAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,IAAI;AAAA,EACpC;AACA,QAAM,Q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cAAM,MAAO,OAAO,GAAI;AAAA,MAC1B;AAAA,IACF,CAAC;AACD,WAAO,gBAAgB,OAAO,IAAI,UAAU,SAAS,IAAI,GAAG,CAAC;AAAA,EAC/D;AACA,MAAI,KAAK;AACP,YAAQ,IAAI,QAAQ;AAAA,EACtB;AACA,QAAM,WAAW,MAAM,OAAO,OAAO;AACrC,QAAM,OAAO,MAAM,KAAK,QAAQ;AAChC,MAAI,CAAC,MAAM;AACT,WAAO,OAAO,UAAU,MAAM;AAAA,EAChC;AACA,QAAM,MAAM,MACT,IAAI,KAAK,SAAS,KAAK,OAAO,MAAM,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC,EACxD,MAAM,MAAM;AAAA,EAAC,CAAC;AACjB,MAAI,QAAQ,KAAK;AACf,YAAQ,IAAI,UAAU,GAAG;AAAA,EAC3B,OAAO;AACL,UAAM;AAAA,EACR;AACA,SAAO,OAAO,KAAK,QAAQ,MAAM;AACnC;",
|
|
5
|
+
"names": ["life", "kept"]
|
|
6
|
+
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -363,8 +363,8 @@ declare function cookieSessionStore(options: CookieSessionStoreOptions): Session
|
|
|
363
363
|
|
|
364
364
|
/** Where a site keeps the shopper's branch choice. */
|
|
365
365
|
type ResolveBranchOptions = {
|
|
366
|
-
/** The cookie that remembers the shopper's branch, by id or slug. */
|
|
367
|
-
cookie
|
|
366
|
+
/** The cookie that remembers the shopper's branch, by id or slug. Leave it out when the site keeps no branch cookie. */
|
|
367
|
+
cookie?: string;
|
|
368
368
|
/** The branch to show when the shopper hasn't chosen one, by id or slug. Defaults to the store's default branch. */
|
|
369
369
|
fallback?: string;
|
|
370
370
|
/** The query parameter that names a branch in a link. Defaults to `branch`. */
|
|
@@ -418,9 +418,10 @@ type StoreAndMenu = ResolvedBranch & {
|
|
|
418
418
|
* the branch by ID (`br_…`), the menu read starts alongside the store read,
|
|
419
419
|
* so a page render waits for one round trip instead of two. The menu counts
|
|
420
420
|
* only once the store confirms that branch, so you get the same menu and the
|
|
421
|
-
* same errors as `store.get` followed by `menu.get`. A branch named by slug
|
|
422
|
-
*
|
|
423
|
-
*
|
|
421
|
+
* same errors as `store.get` followed by `menu.get`. A branch named by slug
|
|
422
|
+
* starts early too once a store read in the same Worker isolate has given
|
|
423
|
+
* that slug's ID. The first such request, or one naming no branch, reads the
|
|
424
|
+
* menu after the store, because the API takes branch IDs only.
|
|
424
425
|
*
|
|
425
426
|
* @example
|
|
426
427
|
* const { store, branch, chosen, mustChoose, menu } = await loadStoreAndMenu(client, request, {
|
|
@@ -435,6 +436,155 @@ type StoreAndMenu = ResolvedBranch & {
|
|
|
435
436
|
*/
|
|
436
437
|
declare function loadStoreAndMenu(client: Zappie, request: Request, options: ResolveBranchOptions): Promise<StoreAndMenu>;
|
|
437
438
|
|
|
439
|
+
/** The part of a Worker's `ExecutionContext` the edge cache uses: work that may finish after the response. */
|
|
440
|
+
type EdgeContext = {
|
|
441
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
442
|
+
};
|
|
443
|
+
/** How a response came from the edge cache, in the `x-zappie-edge-cache` response header. */
|
|
444
|
+
type EdgeCacheStatus = "HIT" | "STALE" | "MISS" | "BYPASS";
|
|
445
|
+
/** The response header that says how the edge cache answered. */
|
|
446
|
+
declare const EDGE_CACHE_HEADER = "x-zappie-edge-cache";
|
|
447
|
+
/** The part of the Cache API the edge cache uses: a Worker's `caches.open()` cache, or a stand-in in tests. */
|
|
448
|
+
type EdgeCache = {
|
|
449
|
+
match(request: Request): Promise<Response | undefined>;
|
|
450
|
+
put(request: Request, response: Response): Promise<void>;
|
|
451
|
+
delete(request: Request): Promise<boolean>;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Open the Worker's own cache, once per isolate. On Zappie hosting each site runs as a user Worker in a Workers for
|
|
455
|
+
* Platforms dispatch namespace, where `caches.default` is disabled and each Worker's `caches.open()` cache is its own.
|
|
456
|
+
* Outside a Worker, where there is no Cache API, it resolves to `undefined` and nothing is cached.
|
|
457
|
+
*/
|
|
458
|
+
declare function openEdgeCache(): Promise<EdgeCache | undefined>;
|
|
459
|
+
/** How long a response may be served fresh and then stale, in seconds, from its `Cache-Control`. */
|
|
460
|
+
type Freshness = {
|
|
461
|
+
fresh: number;
|
|
462
|
+
stale: number;
|
|
463
|
+
};
|
|
464
|
+
/**
|
|
465
|
+
* How long a shared cache may keep a response, from its `Cache-Control`: `s-maxage` (or `max-age`) fresh, then
|
|
466
|
+
* `stale-while-revalidate` stale. `undefined` when it may not be shared: `private`, `no-store`, `no-cache`, or no
|
|
467
|
+
* fresh lifetime.
|
|
468
|
+
*/
|
|
469
|
+
declare function sharedFreshness(cacheControl: string | null): Freshness | undefined;
|
|
470
|
+
type CacheSource = EdgeCache | undefined | Promise<EdgeCache | undefined>;
|
|
471
|
+
/** Options for {@link cachedApiFetch}. */
|
|
472
|
+
type CachedApiFetchOptions = {
|
|
473
|
+
/** The Worker's execution context. Without it a stale read is fetched again instead of refreshed after the response. */
|
|
474
|
+
ctx?: EdgeContext;
|
|
475
|
+
/** The cache to keep reads in. Defaults to {@link openEdgeCache}. */
|
|
476
|
+
cache?: CacheSource;
|
|
477
|
+
/** The fetch that reaches the API. Defaults to the global fetch. */
|
|
478
|
+
fetch?: typeof fetch;
|
|
479
|
+
/** The clock, in milliseconds. */
|
|
480
|
+
now?: () => number;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Why an API request can't come from the shared cache, or `undefined` when it can. Only a `GET` of the store or a
|
|
484
|
+
* menu, sent with a publishable key and no cookie, is shared. A customer's, cart's, order's or quote's call, or one
|
|
485
|
+
* signed in as a shopper, is never cached.
|
|
486
|
+
*
|
|
487
|
+
* @param request - The request the SDK is about to send to the storefront API.
|
|
488
|
+
*/
|
|
489
|
+
declare function apiCacheBypass(request: Request): string | undefined;
|
|
490
|
+
/**
|
|
491
|
+
* The cache key for a shared API read: the URL, the API version and a hash of the publishable key, so two stores
|
|
492
|
+
* never share an entry and the key itself is never stored.
|
|
493
|
+
*
|
|
494
|
+
* @param request - A request {@link apiCacheBypass} accepts.
|
|
495
|
+
*/
|
|
496
|
+
declare function apiCacheKey(request: Request): Promise<Request>;
|
|
497
|
+
/**
|
|
498
|
+
* A fetch for `createZappie` on the server that keeps the storefront API's store and menu reads in the Worker's
|
|
499
|
+
* cache, for as long as the API's own `Cache-Control` allows (`s-maxage`, then `stale-while-revalidate`). A stale
|
|
500
|
+
* read answers at once and refreshes after the response through `ctx.waitUntil`, with the menu's ETag when it has
|
|
501
|
+
* one. Every other call goes straight to the API. A cache that fails never fails the read.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* const client = createZappie({ store, key, baseUrl, fetch: cachedApiFetch({ ctx }) });
|
|
506
|
+
* ```
|
|
507
|
+
*
|
|
508
|
+
* @param options - The Worker's execution context, and optionally the cache, fetch and clock.
|
|
509
|
+
* @returns A fetch to pass as `createZappie({ fetch })`.
|
|
510
|
+
*/
|
|
511
|
+
declare function cachedApiFetch(options?: CachedApiFetchOptions): typeof fetch;
|
|
512
|
+
/** Options for {@link cachePage}. */
|
|
513
|
+
type PageCacheOptions = {
|
|
514
|
+
/** The Worker's execution context. Without it a stale page is rendered again instead of refreshed after the response. */
|
|
515
|
+
ctx?: EdgeContext;
|
|
516
|
+
/** Changes with every build, so a deploy never answers with the last deploy's pages. */
|
|
517
|
+
deployId: string;
|
|
518
|
+
/** The cookie that remembers the shopper's branch. Its value is part of the cache key. */
|
|
519
|
+
branchCookie?: string;
|
|
520
|
+
/** More cookie names that make a request the shopper's own, on top of Zappie's session cookies. */
|
|
521
|
+
privateCookies?: string[];
|
|
522
|
+
/**
|
|
523
|
+
* The `Cache-Control` for a response that sets none, such as a route's `.data`. Return `undefined` to keep it out
|
|
524
|
+
* of the cache.
|
|
525
|
+
*/
|
|
526
|
+
cacheControl?: (url: URL) => string | undefined;
|
|
527
|
+
/** The cache to keep pages in. Defaults to {@link openEdgeCache}. */
|
|
528
|
+
cache?: CacheSource;
|
|
529
|
+
/** The clock, in milliseconds. */
|
|
530
|
+
now?: () => number;
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* Why a page request can't come from the shared cache, or `undefined` when it can. A request that isn't a `GET`, a
|
|
534
|
+
* draft, review or preview, the closed page, one with an `Authorization` header, one naming another host through
|
|
535
|
+
* `X-Forwarded-Host` or `Forwarded` and one with a session or sign-in
|
|
536
|
+
* cookie all render afresh.
|
|
537
|
+
*
|
|
538
|
+
* @param request - The request the site Worker received.
|
|
539
|
+
* @param options - The site's own private cookies.
|
|
540
|
+
*/
|
|
541
|
+
declare function pageCacheBypass(request: Request, options?: Pick<PageCacheOptions, "privateCookies">): string | undefined;
|
|
542
|
+
/**
|
|
543
|
+
* The cache key for a shared page: the full URL, query included, the branch cookie's value, the deploy, and which
|
|
544
|
+
* site the host says this is (its id and a hash of its publishable key), so a Worker that serves several sites keeps
|
|
545
|
+
* each one's pages apart.
|
|
546
|
+
*
|
|
547
|
+
* @param request - A request {@link pageCacheBypass} accepts.
|
|
548
|
+
* @param options - The deploy id and the branch cookie.
|
|
549
|
+
*/
|
|
550
|
+
declare function pageCacheKey(request: Request, options: Pick<PageCacheOptions, "deployId" | "branchCookie">): Promise<Request>;
|
|
551
|
+
/**
|
|
552
|
+
* Why a rendered page can't be shared, or `undefined` when it can: it must be a `200` that sets no cookie, isn't the
|
|
553
|
+
* closed page, and whose `Cache-Control` (or `fallback`, when it sets none) lets a shared cache keep it.
|
|
554
|
+
*
|
|
555
|
+
* @param response - What the site rendered.
|
|
556
|
+
* @param fallback - The `Cache-Control` to use when the response sets none.
|
|
557
|
+
*/
|
|
558
|
+
declare function pageStoreBypass(response: Response, fallback?: string): string | undefined;
|
|
559
|
+
/**
|
|
560
|
+
* A cached HTML page with a new CSP nonce, in both its policy and its markup, so no two shoppers get the same nonce
|
|
561
|
+
* and an enforced policy stays as strong as on a page rendered for them. A page without a nonce is returned as is.
|
|
562
|
+
*
|
|
563
|
+
* @param response - A page from the cache.
|
|
564
|
+
* @param nonce - The new nonce. Defaults to a fresh one from `createSecurityNonce`.
|
|
565
|
+
*/
|
|
566
|
+
declare function rotatePageNonce(response: Response, nonce?: string): Promise<Response>;
|
|
567
|
+
/**
|
|
568
|
+
* Answer a site Worker's anonymous pages from the Worker's cache: documents, their `.data`, robots and the sitemap.
|
|
569
|
+
* A page is kept for as long as its own `Cache-Control` says (`s-maxage`, then `stale-while-revalidate`). A stale
|
|
570
|
+
* page answers at once and renders again after the response through `ctx.waitUntil`. Requests
|
|
571
|
+
* {@link pageCacheBypass} refuses, and responses {@link pageStoreBypass} refuses, are never shared. Each cached HTML
|
|
572
|
+
* page gets a new CSP nonce. Every response says how it was answered in `x-zappie-edge-cache`.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* export default {
|
|
577
|
+
* fetch: (request, env, ctx) =>
|
|
578
|
+
* cachePage(request, (fresh) => handle(fresh, siteContext(env, ctx)), { ctx, deployId }),
|
|
579
|
+
* };
|
|
580
|
+
* ```
|
|
581
|
+
*
|
|
582
|
+
* @param request - The request the Worker received.
|
|
583
|
+
* @param render - Renders the page. It may be called again after the response to refresh a stale page.
|
|
584
|
+
* @param options - The execution context, deploy id, branch cookie and cache rules.
|
|
585
|
+
*/
|
|
586
|
+
declare function cachePage(request: Request, render: (request: Request) => Promise<Response>, options: PageCacheOptions): Promise<Response>;
|
|
587
|
+
|
|
438
588
|
/**
|
|
439
589
|
* A branch catalogue as the edge keeps it: the SDK `Menu` that `menu.get()`
|
|
440
590
|
* returns, with the facts a snapshot writer and reader need around it.
|
|
@@ -566,6 +716,10 @@ type ZappieSiteConfig = {
|
|
|
566
716
|
store: string;
|
|
567
717
|
branches?: string[];
|
|
568
718
|
theme: string;
|
|
719
|
+
/**
|
|
720
|
+
* @deprecated Zappie hosting prerenders no page: every page renders in your Worker, and its page cache keeps the
|
|
721
|
+
* anonymous ones. `validateConfig` warns when it is set. Remove it.
|
|
722
|
+
*/
|
|
569
723
|
prerender?: string[];
|
|
570
724
|
menu?: {
|
|
571
725
|
hiddenCategories?: string[];
|
|
@@ -754,5 +908,5 @@ declare function createZappieServer({ secretKey, ...config }: ZappieServerConfig
|
|
|
754
908
|
};
|
|
755
909
|
}>;
|
|
756
910
|
|
|
757
|
-
export { STOREFRONT_QUERY_PARAMETERS, STOREFRONT_V1_QUERY_PARAMETERS, ZappieTokenError, ZappieWebhookSignatureError, applyAvailability, buildStorefrontUrl, canonicalJson, cookieSessionStore, createAvailabilityPatch, createMenuSnapshot, createPkce, createSecurityNonce, createStoreSnapshot, createTokenVerifier, createZappieServer, inlineScriptHashes, isMenuSnapshot, loadStoreAndMenu, menuSnapshotFromPayload, openSealedValue, parseStorefrontUrl, randomToken, requestedBranch, resolveBranch, sealValue, securityHeaders, signInRedirect, snapshotHash, snapshotKeys, storefrontRedirect, verifyWebhook };
|
|
758
|
-
export type { AvailabilityPatch, AvailabilityPatchInput, CookieSessionStoreOptions, EdgeSnapshotReader, IdTokenChecks, IdTokenClaims, MenuSnapshot, MenuSnapshotInput, MenuSnapshotPayloadInput, PkcePair, ResolveBranchOptions, ResolvedBranch, SealOptions, SealSecret, SecurityHeadersOptions, SessionData, SessionStore, SnapshotVersionRecord, StoreAndMenu, StoreSnapshot, StorefrontInstallation, StorefrontPageState, StorefrontQuery, StorefrontRoute, StorefrontUrlInput, StorefrontUrlOptions, TokenAlgorithm, TokenClaims, TokenErrorReason, TokenVerifier, TokenVerifierOptions, VerifyTokenChecks, VerifyWebhookOptions, WebhookEvent, WebhookEventType, ZappieServerConfig };
|
|
911
|
+
export { EDGE_CACHE_HEADER, STOREFRONT_QUERY_PARAMETERS, STOREFRONT_V1_QUERY_PARAMETERS, ZappieTokenError, ZappieWebhookSignatureError, apiCacheBypass, apiCacheKey, applyAvailability, buildStorefrontUrl, cachePage, cachedApiFetch, canonicalJson, cookieSessionStore, createAvailabilityPatch, createMenuSnapshot, createPkce, createSecurityNonce, createStoreSnapshot, createTokenVerifier, createZappieServer, inlineScriptHashes, isMenuSnapshot, loadStoreAndMenu, menuSnapshotFromPayload, openEdgeCache, openSealedValue, pageCacheBypass, pageCacheKey, pageStoreBypass, parseStorefrontUrl, randomToken, requestedBranch, resolveBranch, rotatePageNonce, sealValue, securityHeaders, sharedFreshness, signInRedirect, snapshotHash, snapshotKeys, storefrontRedirect, verifyWebhook };
|
|
912
|
+
export type { AvailabilityPatch, AvailabilityPatchInput, CachedApiFetchOptions, CookieSessionStoreOptions, EdgeCache, EdgeCacheStatus, EdgeContext, EdgeSnapshotReader, Freshness, IdTokenChecks, IdTokenClaims, MenuSnapshot, MenuSnapshotInput, MenuSnapshotPayloadInput, PageCacheOptions, PkcePair, ResolveBranchOptions, ResolvedBranch, SealOptions, SealSecret, SecurityHeadersOptions, SessionData, SessionStore, SnapshotVersionRecord, StoreAndMenu, StoreSnapshot, StorefrontInstallation, StorefrontPageState, StorefrontQuery, StorefrontRoute, StorefrontUrlInput, StorefrontUrlOptions, TokenAlgorithm, TokenClaims, TokenErrorReason, TokenVerifier, TokenVerifierOptions, VerifyTokenChecks, VerifyWebhookOptions, WebhookEvent, WebhookEventType, ZappieServerConfig };
|
package/dist/server/index.js
CHANGED
|
@@ -26,6 +26,19 @@ import {
|
|
|
26
26
|
requestedBranch,
|
|
27
27
|
resolveBranch
|
|
28
28
|
} from "./chosen-branch.js";
|
|
29
|
+
import {
|
|
30
|
+
apiCacheBypass,
|
|
31
|
+
apiCacheKey,
|
|
32
|
+
cachedApiFetch,
|
|
33
|
+
cachePage,
|
|
34
|
+
EDGE_CACHE_HEADER,
|
|
35
|
+
openEdgeCache,
|
|
36
|
+
pageCacheBypass,
|
|
37
|
+
pageCacheKey,
|
|
38
|
+
pageStoreBypass,
|
|
39
|
+
rotatePageNonce,
|
|
40
|
+
sharedFreshness
|
|
41
|
+
} from "./edge-cache.js";
|
|
29
42
|
import {
|
|
30
43
|
applyAvailability,
|
|
31
44
|
canonicalJson,
|
|
@@ -54,13 +67,18 @@ function createZappieServer({
|
|
|
54
67
|
return buildClient({ ...config, key: secretKey }, true);
|
|
55
68
|
}
|
|
56
69
|
export {
|
|
70
|
+
EDGE_CACHE_HEADER,
|
|
57
71
|
STOREFRONT_QUERY_PARAMETERS,
|
|
58
72
|
STOREFRONT_V1_QUERY_PARAMETERS,
|
|
59
73
|
VERSION,
|
|
60
74
|
ZappieTokenError,
|
|
61
75
|
ZappieWebhookSignatureError,
|
|
76
|
+
apiCacheBypass,
|
|
77
|
+
apiCacheKey,
|
|
62
78
|
applyAvailability,
|
|
63
79
|
buildStorefrontUrl,
|
|
80
|
+
cachePage,
|
|
81
|
+
cachedApiFetch,
|
|
64
82
|
canonicalJson,
|
|
65
83
|
cookieSessionStore,
|
|
66
84
|
createAvailabilityPatch,
|
|
@@ -74,13 +92,19 @@ export {
|
|
|
74
92
|
isMenuSnapshot,
|
|
75
93
|
loadStoreAndMenu,
|
|
76
94
|
menuSnapshotFromPayload,
|
|
95
|
+
openEdgeCache,
|
|
77
96
|
openSealedValue,
|
|
97
|
+
pageCacheBypass,
|
|
98
|
+
pageCacheKey,
|
|
99
|
+
pageStoreBypass,
|
|
78
100
|
parseStorefrontUrl,
|
|
79
101
|
randomToken,
|
|
80
102
|
requestedBranch,
|
|
81
103
|
resolveBranch,
|
|
104
|
+
rotatePageNonce,
|
|
82
105
|
sealValue,
|
|
83
106
|
securityHeaders,
|
|
107
|
+
sharedFreshness,
|
|
84
108
|
signInRedirect,
|
|
85
109
|
snapshotHash,
|
|
86
110
|
snapshotKeys,
|