@usethrottle/builder 0.5.0 → 0.6.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/dist/{chunk-CYA6NLSC.cjs → chunk-53B64NRG.cjs} +85 -8
- package/dist/{chunk-TWEYA32T.js → chunk-RXLU55OZ.js} +87 -10
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +43 -2
- package/dist/index.d.ts +43 -2
- package/dist/index.js +3 -1
- package/dist/next.cjs +9 -9
- package/dist/next.js +1 -1
- package/package.json +2 -2
|
@@ -51,6 +51,11 @@ var _builderschema = require('@usethrottle/builder-schema');
|
|
|
51
51
|
|
|
52
52
|
// src/documents.ts
|
|
53
53
|
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
54
59
|
var MAX_NAME_CHARS = 128;
|
|
55
60
|
function isRecord(value) {
|
|
56
61
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -60,6 +65,19 @@ function checkName(kind, value) {
|
|
|
60
65
|
throw new TypeError(`A Builder ${kind} is a non-empty string of at most ${String(MAX_NAME_CHARS)} characters`);
|
|
61
66
|
return value;
|
|
62
67
|
}
|
|
68
|
+
function checkTemplateName(value) {
|
|
69
|
+
if (!_builderschema.TEMPLATE_NAMES.includes(value))
|
|
70
|
+
throw new TypeError(`A Builder template is one of: ${_builderschema.TEMPLATE_NAMES.join(", ")}`);
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function emptyTemplate() {
|
|
74
|
+
return {
|
|
75
|
+
document: _builderschema.emptyDocument.call(void 0, ),
|
|
76
|
+
meta: {},
|
|
77
|
+
customWidgets: {},
|
|
78
|
+
code: { enabled: false, scriptOrigin: "", codeSiteId: null }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
63
81
|
function currentDocument(answer, where) {
|
|
64
82
|
const doc = answer.document;
|
|
65
83
|
if (!isRecord(doc))
|
|
@@ -116,7 +134,15 @@ function readBundle(body) {
|
|
|
116
134
|
pages: body.pages.map(readPage),
|
|
117
135
|
header: readDocument(body.header, "header"),
|
|
118
136
|
footer: readDocument(body.footer, "footer"),
|
|
119
|
-
slots: Object.fromEntries(Object.entries(body.slots).map(([name, value]) => [name, readDocument(value, `slot ${name}`)]))
|
|
137
|
+
slots: Object.fromEntries(Object.entries(body.slots).map(([name, value]) => [name, readDocument(value, `slot ${name}`)])),
|
|
138
|
+
...isRecord(body.templates) ? {
|
|
139
|
+
templates: Object.fromEntries(
|
|
140
|
+
Object.entries(body.templates).map(([name, value]) => [
|
|
141
|
+
name,
|
|
142
|
+
{ ...readDocument(value, `template ${name}`), ...isRecord(value) && isRecord(value.meta) ? { meta: value.meta } : {} }
|
|
143
|
+
])
|
|
144
|
+
)
|
|
145
|
+
} : {}
|
|
120
146
|
};
|
|
121
147
|
}
|
|
122
148
|
async function fetchBundle({ base, key, ref, timeoutMs, doFetch }) {
|
|
@@ -203,8 +229,19 @@ function siteFor(bundle, locale, now) {
|
|
|
203
229
|
enabled: announcement.enabled === true && (announcement.startsAt == null || Date.parse(String(announcement.startsAt)) <= now) && (announcement.endsAt == null || now < Date.parse(String(announcement.endsAt)))
|
|
204
230
|
}
|
|
205
231
|
} : settings;
|
|
206
|
-
return {
|
|
232
|
+
return {
|
|
233
|
+
generation: bundle.generation,
|
|
234
|
+
siteVersion: bundle.siteVersion,
|
|
235
|
+
settings: windowed,
|
|
236
|
+
catalogInstalled: typeof bundle.catalogInstalled === "boolean" ? bundle.catalogInstalled : null,
|
|
237
|
+
...isRecord(bundle.theme) ? { theme: bundle.theme } : {}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function templateFor(bundle, name) {
|
|
241
|
+
const held = Object.hasOwn(_nullishCoalesce(bundle.templates, () => ( {})), name) ? bundle.templates[name] : void 0;
|
|
242
|
+
return { ...documentOf(bundle, held), meta: _nullishCoalesce(_optionalChain([held, 'optionalAccess', _10 => _10.meta]), () => ( {})) };
|
|
207
243
|
}
|
|
244
|
+
var templatesOf = (bundle, names) => names.length === 0 ? {} : { templates: Object.fromEntries(names.map((name) => [name, templateFor(bundle, name)])) };
|
|
208
245
|
function summaryOf(page, chain) {
|
|
209
246
|
return {
|
|
210
247
|
id: page.id,
|
|
@@ -285,8 +322,13 @@ function createBuildClient(options) {
|
|
|
285
322
|
return documentOf(bundle, Object.hasOwn(bundle.slots, name) ? bundle.slots[name] : void 0);
|
|
286
323
|
}
|
|
287
324
|
},
|
|
288
|
-
|
|
325
|
+
getTemplate: async (name) => {
|
|
326
|
+
checkTemplateName(name);
|
|
327
|
+
return templateFor(await getReleaseBundle(), name);
|
|
328
|
+
},
|
|
329
|
+
bundle: async ({ page: pageSlug, slots, templates, locale } = {}) => {
|
|
289
330
|
const names = [...new Set(_nullishCoalesce(slots, () => ( [])))].map((name) => checkName("slot name", name)).sort();
|
|
331
|
+
const templateNames = [...new Set(_nullishCoalesce(templates, () => ( [])))].map(checkTemplateName).sort();
|
|
290
332
|
if (pageSlug !== void 0) checkName("page slug", pageSlug);
|
|
291
333
|
const bundle = await getReleaseBundle();
|
|
292
334
|
return {
|
|
@@ -298,6 +340,7 @@ function createBuildClient(options) {
|
|
|
298
340
|
slots: Object.fromEntries(
|
|
299
341
|
names.map((name) => [name, documentOf(bundle, Object.hasOwn(bundle.slots, name) ? bundle.slots[name] : void 0)])
|
|
300
342
|
),
|
|
343
|
+
...templatesOf(bundle, templateNames),
|
|
301
344
|
...sharedOf(bundle)
|
|
302
345
|
};
|
|
303
346
|
}
|
|
@@ -313,8 +356,10 @@ var BUILDER_TAGS = {
|
|
|
313
356
|
pages: `${TAG}:pages`,
|
|
314
357
|
page: (slug) => `${TAG}:page:${slug}`,
|
|
315
358
|
part: (name) => `${TAG}:part:${name}`,
|
|
316
|
-
slot: (name) => `${TAG}:slot:${name}
|
|
359
|
+
slot: (name) => `${TAG}:slot:${name}`,
|
|
360
|
+
template: (name) => `${TAG}:template:${name}`
|
|
317
361
|
};
|
|
362
|
+
var templateTag = (name) => BUILDER_TAGS.template(name);
|
|
318
363
|
function fitTags(tags) {
|
|
319
364
|
return [...new Set(tags)].filter((tag) => tag.length <= TAG_MAX_CHARS);
|
|
320
365
|
}
|
|
@@ -331,6 +376,7 @@ function scopesToTags(scopes) {
|
|
|
331
376
|
else if (colon < 0 && scope === "pages") out.push(BUILDER_TAGS.pages);
|
|
332
377
|
else if (rest !== "" && name === "page") out.push(BUILDER_TAGS.page(rest));
|
|
333
378
|
else if (rest !== "" && name === "slot") out.push(BUILDER_TAGS.slot(rest));
|
|
379
|
+
else if (rest !== "" && name === "template") out.push(BUILDER_TAGS.template(rest));
|
|
334
380
|
else out.push(BUILDER_TAGS.all);
|
|
335
381
|
}
|
|
336
382
|
return fitTags(out);
|
|
@@ -384,7 +430,12 @@ function readSite(answer) {
|
|
|
384
430
|
if (typeof answer.siteVersion !== "number" || !Number.isSafeInteger(answer.siteVersion))
|
|
385
431
|
throw invalid2("Builder site answer has no siteVersion");
|
|
386
432
|
if (!isRecord(answer.settings)) throw invalid2("Builder site answer has no settings");
|
|
387
|
-
return answer;
|
|
433
|
+
return { ...answer, catalogInstalled: typeof answer.catalogInstalled === "boolean" ? answer.catalogInstalled : null };
|
|
434
|
+
}
|
|
435
|
+
function readTemplate(answer, name) {
|
|
436
|
+
const meta = answer.meta === void 0 ? {} : answer.meta;
|
|
437
|
+
if (!isRecord(meta)) throw invalid2(`Builder template ${name} answer has meta that is not an object`);
|
|
438
|
+
return { ...answer, document: currentDocument(answer, `template ${name}`), meta };
|
|
388
439
|
}
|
|
389
440
|
var SUMMARY_KEYS = ["id", "slug", "pageType", "title", "updatedAt", "path"];
|
|
390
441
|
function readPages(answer) {
|
|
@@ -411,9 +462,19 @@ function readBundle2(answer) {
|
|
|
411
462
|
throw invalid2("Builder bundle answer has no site, header or footer");
|
|
412
463
|
const slots = answer.slots === void 0 ? {} : answer.slots;
|
|
413
464
|
if (!isRecord(slots)) throw invalid2("Builder bundle answer has slots that are not an object");
|
|
465
|
+
const templates = answer.templates === void 0 ? {} : answer.templates;
|
|
466
|
+
if (!isRecord(templates)) throw invalid2("Builder bundle answer has templates that are not an object");
|
|
414
467
|
return {
|
|
415
468
|
generation,
|
|
416
469
|
site: readSite(answer.site),
|
|
470
|
+
...answer.templates === void 0 ? {} : {
|
|
471
|
+
templates: Object.fromEntries(
|
|
472
|
+
Object.entries(templates).map(([name, value]) => {
|
|
473
|
+
if (!isRecord(value)) throw invalid2(`Builder template ${name} answer is not an object`);
|
|
474
|
+
return [name, readTemplate(value, name)];
|
|
475
|
+
})
|
|
476
|
+
)
|
|
477
|
+
},
|
|
417
478
|
header: readDocument2(answer.header, "header"),
|
|
418
479
|
footer: readDocument2(answer.footer, "footer"),
|
|
419
480
|
...isRecord(answer.page) ? { page: readPage2(answer.page) } : {},
|
|
@@ -532,19 +593,34 @@ function createLiveClient(options) {
|
|
|
532
593
|
(answer) => readDocument2(answer, `slot ${name}`)
|
|
533
594
|
)
|
|
534
595
|
},
|
|
535
|
-
|
|
596
|
+
getTemplate: async (name, { locale } = {}) => {
|
|
597
|
+
checkTemplateName(name);
|
|
598
|
+
try {
|
|
599
|
+
return await read(
|
|
600
|
+
`/v1/templates/${name}`,
|
|
601
|
+
{ query: { locale }, tags: [BUILDER_TAGS.all, templateTag(name)] },
|
|
602
|
+
(answer) => readTemplate(answer, name)
|
|
603
|
+
);
|
|
604
|
+
} catch (error) {
|
|
605
|
+
if (error instanceof BuilderUnavailableError && error.status === 404) return emptyTemplate();
|
|
606
|
+
throw error;
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
bundle: async ({ page: pageSlug, slots, templates, locale } = {}) => {
|
|
536
610
|
const names = [...new Set(_nullishCoalesce(slots, () => ( [])))].map((name) => checkName("slot name", name)).sort();
|
|
611
|
+
const templateNames = [...new Set(_nullishCoalesce(templates, () => ( [])))].map(checkTemplateName).sort();
|
|
537
612
|
if (pageSlug !== void 0) checkName("page slug", pageSlug);
|
|
538
613
|
return read(
|
|
539
614
|
"/v1/bundle",
|
|
540
615
|
{
|
|
541
|
-
query: { page: pageSlug, slots: names.join(","), locale },
|
|
616
|
+
query: { page: pageSlug, slots: names.join(","), templates: templateNames.join(","), locale },
|
|
542
617
|
pageSlug,
|
|
543
618
|
tags: [
|
|
544
619
|
BUILDER_TAGS.all,
|
|
545
620
|
BUILDER_TAGS.site,
|
|
546
621
|
BUILDER_TAGS.part("header"),
|
|
547
622
|
BUILDER_TAGS.part("footer"),
|
|
623
|
+
...templateNames.map((name) => templateTag(name)),
|
|
548
624
|
...pageSlug === void 0 ? [] : [BUILDER_TAGS.page(pageSlug)],
|
|
549
625
|
...names.map((name) => BUILDER_TAGS.slot(name))
|
|
550
626
|
]
|
|
@@ -623,4 +699,5 @@ async function verifyBuilderNotice(input) {
|
|
|
623
699
|
|
|
624
700
|
|
|
625
701
|
|
|
626
|
-
|
|
702
|
+
|
|
703
|
+
exports.BuilderUnavailableError = BuilderUnavailableError; exports.BuilderNotFoundError = BuilderNotFoundError; exports.PreviewExpiredError = PreviewExpiredError; exports.BuilderReleaseNotFoundError = BuilderReleaseNotFoundError; exports.UNTIL_CHANGED_REVALIDATE_S = UNTIL_CHANGED_REVALIDATE_S; exports.SUPPORTED_BUNDLE_VERSION = SUPPORTED_BUNDLE_VERSION; exports.TAG_MAX_CHARS = TAG_MAX_CHARS; exports.BUILDER_TAGS = BUILDER_TAGS; exports.templateTag = templateTag; exports.scopesToTags = scopesToTags; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL2; exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS; exports.createBuilderClient = createBuilderClient; exports.verifyBuilderNotice = verifyBuilderNotice;
|
|
@@ -47,10 +47,15 @@ function cacheInit(tags, preview) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// src/release.ts
|
|
50
|
-
import { emptyDocument } from "@usethrottle/builder-schema";
|
|
50
|
+
import { emptyDocument as emptyDocument2 } from "@usethrottle/builder-schema";
|
|
51
51
|
|
|
52
52
|
// src/documents.ts
|
|
53
|
-
import {
|
|
53
|
+
import {
|
|
54
|
+
CURRENT_SCHEMA_VERSION,
|
|
55
|
+
TEMPLATE_NAMES,
|
|
56
|
+
emptyDocument,
|
|
57
|
+
upgradeDocument
|
|
58
|
+
} from "@usethrottle/builder-schema";
|
|
54
59
|
var MAX_NAME_CHARS = 128;
|
|
55
60
|
function isRecord(value) {
|
|
56
61
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -60,6 +65,19 @@ function checkName(kind, value) {
|
|
|
60
65
|
throw new TypeError(`A Builder ${kind} is a non-empty string of at most ${String(MAX_NAME_CHARS)} characters`);
|
|
61
66
|
return value;
|
|
62
67
|
}
|
|
68
|
+
function checkTemplateName(value) {
|
|
69
|
+
if (!TEMPLATE_NAMES.includes(value))
|
|
70
|
+
throw new TypeError(`A Builder template is one of: ${TEMPLATE_NAMES.join(", ")}`);
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function emptyTemplate() {
|
|
74
|
+
return {
|
|
75
|
+
document: emptyDocument(),
|
|
76
|
+
meta: {},
|
|
77
|
+
customWidgets: {},
|
|
78
|
+
code: { enabled: false, scriptOrigin: "", codeSiteId: null }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
63
81
|
function currentDocument(answer, where) {
|
|
64
82
|
const doc = answer.document;
|
|
65
83
|
if (!isRecord(doc))
|
|
@@ -116,7 +134,15 @@ function readBundle(body) {
|
|
|
116
134
|
pages: body.pages.map(readPage),
|
|
117
135
|
header: readDocument(body.header, "header"),
|
|
118
136
|
footer: readDocument(body.footer, "footer"),
|
|
119
|
-
slots: Object.fromEntries(Object.entries(body.slots).map(([name, value]) => [name, readDocument(value, `slot ${name}`)]))
|
|
137
|
+
slots: Object.fromEntries(Object.entries(body.slots).map(([name, value]) => [name, readDocument(value, `slot ${name}`)])),
|
|
138
|
+
...isRecord(body.templates) ? {
|
|
139
|
+
templates: Object.fromEntries(
|
|
140
|
+
Object.entries(body.templates).map(([name, value]) => [
|
|
141
|
+
name,
|
|
142
|
+
{ ...readDocument(value, `template ${name}`), ...isRecord(value) && isRecord(value.meta) ? { meta: value.meta } : {} }
|
|
143
|
+
])
|
|
144
|
+
)
|
|
145
|
+
} : {}
|
|
120
146
|
};
|
|
121
147
|
}
|
|
122
148
|
async function fetchBundle({ base, key, ref, timeoutMs, doFetch }) {
|
|
@@ -203,8 +229,19 @@ function siteFor(bundle, locale, now) {
|
|
|
203
229
|
enabled: announcement.enabled === true && (announcement.startsAt == null || Date.parse(String(announcement.startsAt)) <= now) && (announcement.endsAt == null || now < Date.parse(String(announcement.endsAt)))
|
|
204
230
|
}
|
|
205
231
|
} : settings;
|
|
206
|
-
return {
|
|
232
|
+
return {
|
|
233
|
+
generation: bundle.generation,
|
|
234
|
+
siteVersion: bundle.siteVersion,
|
|
235
|
+
settings: windowed,
|
|
236
|
+
catalogInstalled: typeof bundle.catalogInstalled === "boolean" ? bundle.catalogInstalled : null,
|
|
237
|
+
...isRecord(bundle.theme) ? { theme: bundle.theme } : {}
|
|
238
|
+
};
|
|
207
239
|
}
|
|
240
|
+
function templateFor(bundle, name) {
|
|
241
|
+
const held = Object.hasOwn(bundle.templates ?? {}, name) ? bundle.templates[name] : void 0;
|
|
242
|
+
return { ...documentOf(bundle, held), meta: held?.meta ?? {} };
|
|
243
|
+
}
|
|
244
|
+
var templatesOf = (bundle, names) => names.length === 0 ? {} : { templates: Object.fromEntries(names.map((name) => [name, templateFor(bundle, name)])) };
|
|
208
245
|
function summaryOf(page, chain) {
|
|
209
246
|
return {
|
|
210
247
|
id: page.id,
|
|
@@ -242,7 +279,7 @@ function pageFor(bundle, slug, chain) {
|
|
|
242
279
|
var sharedOf = (bundle) => isRecord(bundle.savedSections) ? { savedSections: bundle.savedSections } : {};
|
|
243
280
|
var documentOf = (bundle, held) => ({
|
|
244
281
|
generation: bundle.generation,
|
|
245
|
-
document: held === void 0 ?
|
|
282
|
+
document: held === void 0 ? emptyDocument2() : held.document,
|
|
246
283
|
...sharedOf(bundle)
|
|
247
284
|
});
|
|
248
285
|
function createBuildClient(options) {
|
|
@@ -285,8 +322,13 @@ function createBuildClient(options) {
|
|
|
285
322
|
return documentOf(bundle, Object.hasOwn(bundle.slots, name) ? bundle.slots[name] : void 0);
|
|
286
323
|
}
|
|
287
324
|
},
|
|
288
|
-
|
|
325
|
+
getTemplate: async (name) => {
|
|
326
|
+
checkTemplateName(name);
|
|
327
|
+
return templateFor(await getReleaseBundle(), name);
|
|
328
|
+
},
|
|
329
|
+
bundle: async ({ page: pageSlug, slots, templates, locale } = {}) => {
|
|
289
330
|
const names = [...new Set(slots ?? [])].map((name) => checkName("slot name", name)).sort();
|
|
331
|
+
const templateNames = [...new Set(templates ?? [])].map(checkTemplateName).sort();
|
|
290
332
|
if (pageSlug !== void 0) checkName("page slug", pageSlug);
|
|
291
333
|
const bundle = await getReleaseBundle();
|
|
292
334
|
return {
|
|
@@ -298,6 +340,7 @@ function createBuildClient(options) {
|
|
|
298
340
|
slots: Object.fromEntries(
|
|
299
341
|
names.map((name) => [name, documentOf(bundle, Object.hasOwn(bundle.slots, name) ? bundle.slots[name] : void 0)])
|
|
300
342
|
),
|
|
343
|
+
...templatesOf(bundle, templateNames),
|
|
301
344
|
...sharedOf(bundle)
|
|
302
345
|
};
|
|
303
346
|
}
|
|
@@ -313,8 +356,10 @@ var BUILDER_TAGS = {
|
|
|
313
356
|
pages: `${TAG}:pages`,
|
|
314
357
|
page: (slug) => `${TAG}:page:${slug}`,
|
|
315
358
|
part: (name) => `${TAG}:part:${name}`,
|
|
316
|
-
slot: (name) => `${TAG}:slot:${name}
|
|
359
|
+
slot: (name) => `${TAG}:slot:${name}`,
|
|
360
|
+
template: (name) => `${TAG}:template:${name}`
|
|
317
361
|
};
|
|
362
|
+
var templateTag = (name) => BUILDER_TAGS.template(name);
|
|
318
363
|
function fitTags(tags) {
|
|
319
364
|
return [...new Set(tags)].filter((tag) => tag.length <= TAG_MAX_CHARS);
|
|
320
365
|
}
|
|
@@ -331,6 +376,7 @@ function scopesToTags(scopes) {
|
|
|
331
376
|
else if (colon < 0 && scope === "pages") out.push(BUILDER_TAGS.pages);
|
|
332
377
|
else if (rest !== "" && name === "page") out.push(BUILDER_TAGS.page(rest));
|
|
333
378
|
else if (rest !== "" && name === "slot") out.push(BUILDER_TAGS.slot(rest));
|
|
379
|
+
else if (rest !== "" && name === "template") out.push(BUILDER_TAGS.template(rest));
|
|
334
380
|
else out.push(BUILDER_TAGS.all);
|
|
335
381
|
}
|
|
336
382
|
return fitTags(out);
|
|
@@ -384,7 +430,12 @@ function readSite(answer) {
|
|
|
384
430
|
if (typeof answer.siteVersion !== "number" || !Number.isSafeInteger(answer.siteVersion))
|
|
385
431
|
throw invalid2("Builder site answer has no siteVersion");
|
|
386
432
|
if (!isRecord(answer.settings)) throw invalid2("Builder site answer has no settings");
|
|
387
|
-
return answer;
|
|
433
|
+
return { ...answer, catalogInstalled: typeof answer.catalogInstalled === "boolean" ? answer.catalogInstalled : null };
|
|
434
|
+
}
|
|
435
|
+
function readTemplate(answer, name) {
|
|
436
|
+
const meta = answer.meta === void 0 ? {} : answer.meta;
|
|
437
|
+
if (!isRecord(meta)) throw invalid2(`Builder template ${name} answer has meta that is not an object`);
|
|
438
|
+
return { ...answer, document: currentDocument(answer, `template ${name}`), meta };
|
|
388
439
|
}
|
|
389
440
|
var SUMMARY_KEYS = ["id", "slug", "pageType", "title", "updatedAt", "path"];
|
|
390
441
|
function readPages(answer) {
|
|
@@ -411,9 +462,19 @@ function readBundle2(answer) {
|
|
|
411
462
|
throw invalid2("Builder bundle answer has no site, header or footer");
|
|
412
463
|
const slots = answer.slots === void 0 ? {} : answer.slots;
|
|
413
464
|
if (!isRecord(slots)) throw invalid2("Builder bundle answer has slots that are not an object");
|
|
465
|
+
const templates = answer.templates === void 0 ? {} : answer.templates;
|
|
466
|
+
if (!isRecord(templates)) throw invalid2("Builder bundle answer has templates that are not an object");
|
|
414
467
|
return {
|
|
415
468
|
generation,
|
|
416
469
|
site: readSite(answer.site),
|
|
470
|
+
...answer.templates === void 0 ? {} : {
|
|
471
|
+
templates: Object.fromEntries(
|
|
472
|
+
Object.entries(templates).map(([name, value]) => {
|
|
473
|
+
if (!isRecord(value)) throw invalid2(`Builder template ${name} answer is not an object`);
|
|
474
|
+
return [name, readTemplate(value, name)];
|
|
475
|
+
})
|
|
476
|
+
)
|
|
477
|
+
},
|
|
417
478
|
header: readDocument2(answer.header, "header"),
|
|
418
479
|
footer: readDocument2(answer.footer, "footer"),
|
|
419
480
|
...isRecord(answer.page) ? { page: readPage2(answer.page) } : {},
|
|
@@ -532,19 +593,34 @@ function createLiveClient(options) {
|
|
|
532
593
|
(answer) => readDocument2(answer, `slot ${name}`)
|
|
533
594
|
)
|
|
534
595
|
},
|
|
535
|
-
|
|
596
|
+
getTemplate: async (name, { locale } = {}) => {
|
|
597
|
+
checkTemplateName(name);
|
|
598
|
+
try {
|
|
599
|
+
return await read(
|
|
600
|
+
`/v1/templates/${name}`,
|
|
601
|
+
{ query: { locale }, tags: [BUILDER_TAGS.all, templateTag(name)] },
|
|
602
|
+
(answer) => readTemplate(answer, name)
|
|
603
|
+
);
|
|
604
|
+
} catch (error) {
|
|
605
|
+
if (error instanceof BuilderUnavailableError && error.status === 404) return emptyTemplate();
|
|
606
|
+
throw error;
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
bundle: async ({ page: pageSlug, slots, templates, locale } = {}) => {
|
|
536
610
|
const names = [...new Set(slots ?? [])].map((name) => checkName("slot name", name)).sort();
|
|
611
|
+
const templateNames = [...new Set(templates ?? [])].map(checkTemplateName).sort();
|
|
537
612
|
if (pageSlug !== void 0) checkName("page slug", pageSlug);
|
|
538
613
|
return read(
|
|
539
614
|
"/v1/bundle",
|
|
540
615
|
{
|
|
541
|
-
query: { page: pageSlug, slots: names.join(","), locale },
|
|
616
|
+
query: { page: pageSlug, slots: names.join(","), templates: templateNames.join(","), locale },
|
|
542
617
|
pageSlug,
|
|
543
618
|
tags: [
|
|
544
619
|
BUILDER_TAGS.all,
|
|
545
620
|
BUILDER_TAGS.site,
|
|
546
621
|
BUILDER_TAGS.part("header"),
|
|
547
622
|
BUILDER_TAGS.part("footer"),
|
|
623
|
+
...templateNames.map((name) => templateTag(name)),
|
|
548
624
|
...pageSlug === void 0 ? [] : [BUILDER_TAGS.page(pageSlug)],
|
|
549
625
|
...names.map((name) => BUILDER_TAGS.slot(name))
|
|
550
626
|
]
|
|
@@ -618,6 +694,7 @@ export {
|
|
|
618
694
|
SUPPORTED_BUNDLE_VERSION,
|
|
619
695
|
TAG_MAX_CHARS,
|
|
620
696
|
BUILDER_TAGS,
|
|
697
|
+
templateTag,
|
|
621
698
|
scopesToTags,
|
|
622
699
|
DEFAULT_BASE_URL2 as DEFAULT_BASE_URL,
|
|
623
700
|
DEFAULT_TIMEOUT_MS,
|
package/dist/index.cjs
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var _chunkCYA6NLSCcjs = require('./chunk-CYA6NLSC.cjs');
|
|
15
14
|
|
|
15
|
+
var _chunk53B64NRGcjs = require('./chunk-53B64NRG.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
@@ -25,4 +25,6 @@ var _chunkCYA6NLSCcjs = require('./chunk-CYA6NLSC.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.BUILDER_TAGS = _chunk53B64NRGcjs.BUILDER_TAGS; exports.BuilderNotFoundError = _chunk53B64NRGcjs.BuilderNotFoundError; exports.BuilderReleaseNotFoundError = _chunk53B64NRGcjs.BuilderReleaseNotFoundError; exports.BuilderUnavailableError = _chunk53B64NRGcjs.BuilderUnavailableError; exports.DEFAULT_BASE_URL = _chunk53B64NRGcjs.DEFAULT_BASE_URL; exports.DEFAULT_TIMEOUT_MS = _chunk53B64NRGcjs.DEFAULT_TIMEOUT_MS; exports.PreviewExpiredError = _chunk53B64NRGcjs.PreviewExpiredError; exports.SUPPORTED_BUNDLE_VERSION = _chunk53B64NRGcjs.SUPPORTED_BUNDLE_VERSION; exports.UNTIL_CHANGED_REVALIDATE_S = _chunk53B64NRGcjs.UNTIL_CHANGED_REVALIDATE_S; exports.createBuilderClient = _chunk53B64NRGcjs.createBuilderClient; exports.scopesToTags = _chunk53B64NRGcjs.scopesToTags; exports.templateTag = _chunk53B64NRGcjs.templateTag; exports.verifyBuilderNotice = _chunk53B64NRGcjs.verifyBuilderNotice;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageDocument, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
|
|
1
|
+
import { PageDocument, SavedSectionsAnswer, CodeRuntimeAnswer, TemplateName, TemplateMeta, AnyCustomWidgetSnapshot } from '@usethrottle/builder-schema';
|
|
2
2
|
export { v as verifyBuilderNotice } from './verify-CkxGofEg.cjs';
|
|
3
3
|
|
|
4
4
|
type BuilderUnavailableReason = 'timeout' | 'network' | 'status' | 'invalid-response' | 'unsupported-document';
|
|
@@ -46,6 +46,16 @@ type BuilderSite = {
|
|
|
46
46
|
generation: number;
|
|
47
47
|
siteVersion: number;
|
|
48
48
|
settings: Record<string, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the Product Catalog is installed (the Worker's presence check). `null` is unknown, and an
|
|
51
|
+
* older Worker that sends nothing reads as `null`; routing counts `null` as installed.
|
|
52
|
+
*/
|
|
53
|
+
catalogInstalled: boolean | null;
|
|
54
|
+
/** Site theme output. `customCssHref` is the stylesheet of the merchant's custom CSS, when there is one. */
|
|
55
|
+
theme?: {
|
|
56
|
+
customCssHref?: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
};
|
|
49
59
|
};
|
|
50
60
|
type BuilderPageSummary = {
|
|
51
61
|
id: string;
|
|
@@ -79,6 +89,14 @@ type LoadedDocument = {
|
|
|
79
89
|
/** Whether the store runs code widgets and where their scripts come from. */
|
|
80
90
|
code?: CodeRuntimeAnswer;
|
|
81
91
|
};
|
|
92
|
+
/** A published template (`GET /v1/templates/:name`); an empty document and `{}` meta when unpublished. */
|
|
93
|
+
type TemplateAnswer = Omit<LoadedDocument, 'generation'> & {
|
|
94
|
+
/** Not part of the Worker's template answer; present only if a Worker sends one. */
|
|
95
|
+
generation?: number;
|
|
96
|
+
meta: TemplateMeta;
|
|
97
|
+
/** The custom widgets the template frozen at publish, when the Worker sends them. */
|
|
98
|
+
customWidgets?: Record<string, AnyCustomWidgetSnapshot>;
|
|
99
|
+
};
|
|
82
100
|
type BuilderBundle = {
|
|
83
101
|
generation: number;
|
|
84
102
|
site: BuilderSite;
|
|
@@ -87,6 +105,8 @@ type BuilderBundle = {
|
|
|
87
105
|
page?: LoadedPage | PageRedirect;
|
|
88
106
|
/** Only the slots that were asked for. */
|
|
89
107
|
slots: Record<string, LoadedDocument>;
|
|
108
|
+
/** Every published template by name, when the Builder sends them with the bundle. */
|
|
109
|
+
templates?: Partial<Record<TemplateName, TemplateAnswer>>;
|
|
90
110
|
/** Saved sections of every document in the answer, when the Builder sends them once for all. */
|
|
91
111
|
savedSections?: SavedSectionsAnswer;
|
|
92
112
|
/** The code runtime of the store, when the Builder sends it once for all. */
|
|
@@ -119,6 +139,12 @@ type BuilderClient = {
|
|
|
119
139
|
pages: {
|
|
120
140
|
list(): Promise<BuilderPageSummary[]>;
|
|
121
141
|
get(slug: string, options?: LocaleOptions): Promise<LoadedPage | PageRedirect>;
|
|
142
|
+
/**
|
|
143
|
+
* The page that answers at its own path (`/about`), or a redirect when the path is an old one of a page
|
|
144
|
+
* (`slug_redirects`). Optional: a client without it is read through `list()` (the summaries carry `path`).
|
|
145
|
+
* Rejects with `BuilderNotFoundError` when no page has the path.
|
|
146
|
+
*/
|
|
147
|
+
getByPath?(path: string, options?: LocaleOptions): Promise<LoadedPage | PageRedirect>;
|
|
122
148
|
};
|
|
123
149
|
parts: {
|
|
124
150
|
get(name: PartName, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
@@ -126,9 +152,12 @@ type BuilderClient = {
|
|
|
126
152
|
slots: {
|
|
127
153
|
get(name: string, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
128
154
|
};
|
|
155
|
+
getTemplate(name: TemplateName, options?: LocaleOptions): Promise<TemplateAnswer>;
|
|
156
|
+
/** `templates` names the templates to answer (and to tag the read with); without it the answer has none. */
|
|
129
157
|
bundle(options?: LocaleOptions & {
|
|
130
158
|
page?: string;
|
|
131
159
|
slots?: readonly string[];
|
|
160
|
+
templates?: readonly TemplateName[];
|
|
132
161
|
}): Promise<BuilderBundle>;
|
|
133
162
|
};
|
|
134
163
|
/** A published part or slot as a release holds it. */
|
|
@@ -136,6 +165,10 @@ type ReleaseDocument = {
|
|
|
136
165
|
version: number;
|
|
137
166
|
document: PageDocument;
|
|
138
167
|
};
|
|
168
|
+
/** A published template as a release holds it. */
|
|
169
|
+
type ReleaseTemplate = ReleaseDocument & {
|
|
170
|
+
meta?: TemplateMeta;
|
|
171
|
+
};
|
|
139
172
|
/** One page of a release. Titles and `seo` text keep their locale maps; the document does too. */
|
|
140
173
|
type ReleasePage = {
|
|
141
174
|
id: string;
|
|
@@ -181,6 +214,12 @@ type ReleaseBundle = {
|
|
|
181
214
|
header: ReleaseDocument;
|
|
182
215
|
footer: ReleaseDocument;
|
|
183
216
|
slots: Record<string, ReleaseDocument>;
|
|
217
|
+
/** The published templates by name. Absent from a release made before templates. */
|
|
218
|
+
templates?: Partial<Record<TemplateName, ReleaseTemplate>>;
|
|
219
|
+
/** The catalog-installed signal at release time. Absent reads as `null` (unknown). */
|
|
220
|
+
catalogInstalled?: boolean | null;
|
|
221
|
+
/** Site theme output (`customCssHref`), when the release holds one. */
|
|
222
|
+
theme?: BuilderSite['theme'];
|
|
184
223
|
/** The published saved sections the release's documents reference, by the id of their document. */
|
|
185
224
|
savedSections?: SavedSectionsAnswer;
|
|
186
225
|
/** An old slug and the store path of the page that lives there now. */
|
|
@@ -253,7 +292,9 @@ declare const BUILDER_TAGS: {
|
|
|
253
292
|
readonly page: (slug: string) => string;
|
|
254
293
|
readonly part: (name: string) => string;
|
|
255
294
|
readonly slot: (name: string) => string;
|
|
295
|
+
readonly template: (name: string) => string;
|
|
256
296
|
};
|
|
297
|
+
declare const templateTag: (name: string) => string;
|
|
257
298
|
/**
|
|
258
299
|
* The tags a change notice's scopes clear. `site` and `menus` clear the site,
|
|
259
300
|
* header and footer reads and never pages. `header` and `footer` clear their
|
|
@@ -266,4 +307,4 @@ declare function scopesToTags(scopes: readonly string[]): string[];
|
|
|
266
307
|
/** Next's `revalidate` for a published read: only a safety net behind the change notices. */
|
|
267
308
|
declare const UNTIL_CHANGED_REVALIDATE_S = 3600;
|
|
268
309
|
|
|
269
|
-
export { BUILDER_TAGS, type BuildBuilderClient, type BuildClientOptions, type BuilderBundle, type BuilderClient, type BuilderClientOptions, BuilderNotFoundError, type BuilderPageSummary, BuilderReleaseNotFoundError, type BuilderSite, BuilderUnavailableError, type BuilderUnavailableReason, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type LoadedDocument, type LoadedPage, type LocaleOptions, type PageRedirect, type PartName, PreviewExpiredError, type ReleaseBundle, type ReleaseDocument, type ReleasePage, SUPPORTED_BUNDLE_VERSION, UNTIL_CHANGED_REVALIDATE_S, createBuilderClient, scopesToTags };
|
|
310
|
+
export { BUILDER_TAGS, type BuildBuilderClient, type BuildClientOptions, type BuilderBundle, type BuilderClient, type BuilderClientOptions, BuilderNotFoundError, type BuilderPageSummary, BuilderReleaseNotFoundError, type BuilderSite, BuilderUnavailableError, type BuilderUnavailableReason, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type LoadedDocument, type LoadedPage, type LocaleOptions, type PageRedirect, type PartName, PreviewExpiredError, type ReleaseBundle, type ReleaseDocument, type ReleasePage, type ReleaseTemplate, SUPPORTED_BUNDLE_VERSION, type TemplateAnswer, UNTIL_CHANGED_REVALIDATE_S, createBuilderClient, scopesToTags, templateTag };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageDocument, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
|
|
1
|
+
import { PageDocument, SavedSectionsAnswer, CodeRuntimeAnswer, TemplateName, TemplateMeta, AnyCustomWidgetSnapshot } from '@usethrottle/builder-schema';
|
|
2
2
|
export { v as verifyBuilderNotice } from './verify-CkxGofEg.js';
|
|
3
3
|
|
|
4
4
|
type BuilderUnavailableReason = 'timeout' | 'network' | 'status' | 'invalid-response' | 'unsupported-document';
|
|
@@ -46,6 +46,16 @@ type BuilderSite = {
|
|
|
46
46
|
generation: number;
|
|
47
47
|
siteVersion: number;
|
|
48
48
|
settings: Record<string, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the Product Catalog is installed (the Worker's presence check). `null` is unknown, and an
|
|
51
|
+
* older Worker that sends nothing reads as `null`; routing counts `null` as installed.
|
|
52
|
+
*/
|
|
53
|
+
catalogInstalled: boolean | null;
|
|
54
|
+
/** Site theme output. `customCssHref` is the stylesheet of the merchant's custom CSS, when there is one. */
|
|
55
|
+
theme?: {
|
|
56
|
+
customCssHref?: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
};
|
|
49
59
|
};
|
|
50
60
|
type BuilderPageSummary = {
|
|
51
61
|
id: string;
|
|
@@ -79,6 +89,14 @@ type LoadedDocument = {
|
|
|
79
89
|
/** Whether the store runs code widgets and where their scripts come from. */
|
|
80
90
|
code?: CodeRuntimeAnswer;
|
|
81
91
|
};
|
|
92
|
+
/** A published template (`GET /v1/templates/:name`); an empty document and `{}` meta when unpublished. */
|
|
93
|
+
type TemplateAnswer = Omit<LoadedDocument, 'generation'> & {
|
|
94
|
+
/** Not part of the Worker's template answer; present only if a Worker sends one. */
|
|
95
|
+
generation?: number;
|
|
96
|
+
meta: TemplateMeta;
|
|
97
|
+
/** The custom widgets the template frozen at publish, when the Worker sends them. */
|
|
98
|
+
customWidgets?: Record<string, AnyCustomWidgetSnapshot>;
|
|
99
|
+
};
|
|
82
100
|
type BuilderBundle = {
|
|
83
101
|
generation: number;
|
|
84
102
|
site: BuilderSite;
|
|
@@ -87,6 +105,8 @@ type BuilderBundle = {
|
|
|
87
105
|
page?: LoadedPage | PageRedirect;
|
|
88
106
|
/** Only the slots that were asked for. */
|
|
89
107
|
slots: Record<string, LoadedDocument>;
|
|
108
|
+
/** Every published template by name, when the Builder sends them with the bundle. */
|
|
109
|
+
templates?: Partial<Record<TemplateName, TemplateAnswer>>;
|
|
90
110
|
/** Saved sections of every document in the answer, when the Builder sends them once for all. */
|
|
91
111
|
savedSections?: SavedSectionsAnswer;
|
|
92
112
|
/** The code runtime of the store, when the Builder sends it once for all. */
|
|
@@ -119,6 +139,12 @@ type BuilderClient = {
|
|
|
119
139
|
pages: {
|
|
120
140
|
list(): Promise<BuilderPageSummary[]>;
|
|
121
141
|
get(slug: string, options?: LocaleOptions): Promise<LoadedPage | PageRedirect>;
|
|
142
|
+
/**
|
|
143
|
+
* The page that answers at its own path (`/about`), or a redirect when the path is an old one of a page
|
|
144
|
+
* (`slug_redirects`). Optional: a client without it is read through `list()` (the summaries carry `path`).
|
|
145
|
+
* Rejects with `BuilderNotFoundError` when no page has the path.
|
|
146
|
+
*/
|
|
147
|
+
getByPath?(path: string, options?: LocaleOptions): Promise<LoadedPage | PageRedirect>;
|
|
122
148
|
};
|
|
123
149
|
parts: {
|
|
124
150
|
get(name: PartName, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
@@ -126,9 +152,12 @@ type BuilderClient = {
|
|
|
126
152
|
slots: {
|
|
127
153
|
get(name: string, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
128
154
|
};
|
|
155
|
+
getTemplate(name: TemplateName, options?: LocaleOptions): Promise<TemplateAnswer>;
|
|
156
|
+
/** `templates` names the templates to answer (and to tag the read with); without it the answer has none. */
|
|
129
157
|
bundle(options?: LocaleOptions & {
|
|
130
158
|
page?: string;
|
|
131
159
|
slots?: readonly string[];
|
|
160
|
+
templates?: readonly TemplateName[];
|
|
132
161
|
}): Promise<BuilderBundle>;
|
|
133
162
|
};
|
|
134
163
|
/** A published part or slot as a release holds it. */
|
|
@@ -136,6 +165,10 @@ type ReleaseDocument = {
|
|
|
136
165
|
version: number;
|
|
137
166
|
document: PageDocument;
|
|
138
167
|
};
|
|
168
|
+
/** A published template as a release holds it. */
|
|
169
|
+
type ReleaseTemplate = ReleaseDocument & {
|
|
170
|
+
meta?: TemplateMeta;
|
|
171
|
+
};
|
|
139
172
|
/** One page of a release. Titles and `seo` text keep their locale maps; the document does too. */
|
|
140
173
|
type ReleasePage = {
|
|
141
174
|
id: string;
|
|
@@ -181,6 +214,12 @@ type ReleaseBundle = {
|
|
|
181
214
|
header: ReleaseDocument;
|
|
182
215
|
footer: ReleaseDocument;
|
|
183
216
|
slots: Record<string, ReleaseDocument>;
|
|
217
|
+
/** The published templates by name. Absent from a release made before templates. */
|
|
218
|
+
templates?: Partial<Record<TemplateName, ReleaseTemplate>>;
|
|
219
|
+
/** The catalog-installed signal at release time. Absent reads as `null` (unknown). */
|
|
220
|
+
catalogInstalled?: boolean | null;
|
|
221
|
+
/** Site theme output (`customCssHref`), when the release holds one. */
|
|
222
|
+
theme?: BuilderSite['theme'];
|
|
184
223
|
/** The published saved sections the release's documents reference, by the id of their document. */
|
|
185
224
|
savedSections?: SavedSectionsAnswer;
|
|
186
225
|
/** An old slug and the store path of the page that lives there now. */
|
|
@@ -253,7 +292,9 @@ declare const BUILDER_TAGS: {
|
|
|
253
292
|
readonly page: (slug: string) => string;
|
|
254
293
|
readonly part: (name: string) => string;
|
|
255
294
|
readonly slot: (name: string) => string;
|
|
295
|
+
readonly template: (name: string) => string;
|
|
256
296
|
};
|
|
297
|
+
declare const templateTag: (name: string) => string;
|
|
257
298
|
/**
|
|
258
299
|
* The tags a change notice's scopes clear. `site` and `menus` clear the site,
|
|
259
300
|
* header and footer reads and never pages. `header` and `footer` clear their
|
|
@@ -266,4 +307,4 @@ declare function scopesToTags(scopes: readonly string[]): string[];
|
|
|
266
307
|
/** Next's `revalidate` for a published read: only a safety net behind the change notices. */
|
|
267
308
|
declare const UNTIL_CHANGED_REVALIDATE_S = 3600;
|
|
268
309
|
|
|
269
|
-
export { BUILDER_TAGS, type BuildBuilderClient, type BuildClientOptions, type BuilderBundle, type BuilderClient, type BuilderClientOptions, BuilderNotFoundError, type BuilderPageSummary, BuilderReleaseNotFoundError, type BuilderSite, BuilderUnavailableError, type BuilderUnavailableReason, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type LoadedDocument, type LoadedPage, type LocaleOptions, type PageRedirect, type PartName, PreviewExpiredError, type ReleaseBundle, type ReleaseDocument, type ReleasePage, SUPPORTED_BUNDLE_VERSION, UNTIL_CHANGED_REVALIDATE_S, createBuilderClient, scopesToTags };
|
|
310
|
+
export { BUILDER_TAGS, type BuildBuilderClient, type BuildClientOptions, type BuilderBundle, type BuilderClient, type BuilderClientOptions, BuilderNotFoundError, type BuilderPageSummary, BuilderReleaseNotFoundError, type BuilderSite, BuilderUnavailableError, type BuilderUnavailableReason, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type LoadedDocument, type LoadedPage, type LocaleOptions, type PageRedirect, type PartName, PreviewExpiredError, type ReleaseBundle, type ReleaseDocument, type ReleasePage, type ReleaseTemplate, SUPPORTED_BUNDLE_VERSION, type TemplateAnswer, UNTIL_CHANGED_REVALIDATE_S, createBuilderClient, scopesToTags, templateTag };
|
package/dist/index.js
CHANGED
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
UNTIL_CHANGED_REVALIDATE_S,
|
|
11
11
|
createBuilderClient,
|
|
12
12
|
scopesToTags,
|
|
13
|
+
templateTag,
|
|
13
14
|
verifyBuilderNotice
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-RXLU55OZ.js";
|
|
15
16
|
export {
|
|
16
17
|
BUILDER_TAGS,
|
|
17
18
|
BuilderNotFoundError,
|
|
@@ -24,5 +25,6 @@ export {
|
|
|
24
25
|
UNTIL_CHANGED_REVALIDATE_S,
|
|
25
26
|
createBuilderClient,
|
|
26
27
|
scopesToTags,
|
|
28
|
+
templateTag,
|
|
27
29
|
verifyBuilderNotice
|
|
28
30
|
};
|
package/dist/next.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk53B64NRGcjs = require('./chunk-53B64NRG.cjs');
|
|
8
8
|
|
|
9
9
|
// src/next/index.ts
|
|
10
10
|
require('server-only');
|
|
@@ -47,7 +47,7 @@ function parseNotice(rawBody) {
|
|
|
47
47
|
if (typeof value !== "object" || value === null) return null;
|
|
48
48
|
const { type, generation, scopes } = value;
|
|
49
49
|
if (type !== "builder.changed" || typeof generation !== "number" || !Number.isSafeInteger(generation) || generation < 0 || !Array.isArray(scopes) || scopes.length === 0 || scopes.length > MAX_SCOPES || !scopes.every(
|
|
50
|
-
(scope) => typeof scope === "string" && scope.length > 0 && scope.length <=
|
|
50
|
+
(scope) => typeof scope === "string" && scope.length > 0 && scope.length <= _chunk53B64NRGcjs.TAG_MAX_CHARS
|
|
51
51
|
))
|
|
52
52
|
return null;
|
|
53
53
|
return { generation, scopes };
|
|
@@ -72,12 +72,12 @@ function createRevalidateHandler(options) {
|
|
|
72
72
|
const now = Math.floor(Date.now() / 1e3);
|
|
73
73
|
let verified = false;
|
|
74
74
|
for (const secret of secrets)
|
|
75
|
-
verified = await
|
|
75
|
+
verified = await _chunk53B64NRGcjs.verifyBuilderNotice.call(void 0, { rawBody, header, secret, now }) || verified;
|
|
76
76
|
if (!verified) return json(401, { error: "invalid signature" });
|
|
77
77
|
const notice = parseNotice(rawBody);
|
|
78
78
|
if (notice === null) return json(400, { error: "invalid body" });
|
|
79
|
-
const mapped =
|
|
80
|
-
const tags = mapped.length > MAX_TAGS_PER_NOTICE ? [
|
|
79
|
+
const mapped = _chunk53B64NRGcjs.scopesToTags.call(void 0, notice.scopes);
|
|
80
|
+
const tags = mapped.length > MAX_TAGS_PER_NOTICE ? [_chunk53B64NRGcjs.BUILDER_TAGS.all] : mapped;
|
|
81
81
|
const revalidate = await _asyncNullishCoalesce(options.revalidateTag, async () => ( await defaultRevalidateTag()));
|
|
82
82
|
for (const tag of tags) revalidate(tag);
|
|
83
83
|
return json(200, { revalidated: tags });
|
|
@@ -102,7 +102,7 @@ function createWatchSyncHandler(options) {
|
|
|
102
102
|
let running;
|
|
103
103
|
const run = async (key) => {
|
|
104
104
|
const doFetch = _nullishCoalesce(options.fetch, () => ( fetch));
|
|
105
|
-
const base = (_nullishCoalesce(options.baseUrl, () => (
|
|
105
|
+
const base = (_nullishCoalesce(options.baseUrl, () => ( _chunk53B64NRGcjs.DEFAULT_BASE_URL))).replace(/\/+$/u, "");
|
|
106
106
|
const read = async (init) => {
|
|
107
107
|
const response = await doFetch(`${base}/v1/site`, {
|
|
108
108
|
headers: { "X-Builder-Key": key },
|
|
@@ -118,14 +118,14 @@ function createWatchSyncHandler(options) {
|
|
|
118
118
|
let generation;
|
|
119
119
|
let recorded;
|
|
120
120
|
try {
|
|
121
|
-
recorded = await read({ next: { tags: [
|
|
121
|
+
recorded = await read({ next: { tags: [_chunk53B64NRGcjs.BUILDER_TAGS.all], revalidate: false } });
|
|
122
122
|
generation = await read({ cache: "no-store" });
|
|
123
123
|
} catch (e2) {
|
|
124
124
|
return json2(502, { error: "The Builder could not be read." });
|
|
125
125
|
}
|
|
126
126
|
if (generation === recorded) return json2(200, { changed: false, generation });
|
|
127
127
|
const revalidate = await _asyncNullishCoalesce(options.revalidateTag, async () => ( await defaultRevalidateTag2()));
|
|
128
|
-
revalidate(
|
|
128
|
+
revalidate(_chunk53B64NRGcjs.BUILDER_TAGS.all);
|
|
129
129
|
return json2(200, { changed: true, generation });
|
|
130
130
|
};
|
|
131
131
|
return () => {
|
|
@@ -182,4 +182,4 @@ async function getPreviewToken() {
|
|
|
182
182
|
|
|
183
183
|
|
|
184
184
|
|
|
185
|
-
exports.PREVIEW_COOKIE = PREVIEW_COOKIE; exports.createRevalidateHandler = createRevalidateHandler; exports.createWatchSyncHandler = createWatchSyncHandler; exports.getPreviewToken = getPreviewToken; exports.previewMiddleware = previewMiddleware; exports.verifyBuilderNotice =
|
|
185
|
+
exports.PREVIEW_COOKIE = PREVIEW_COOKIE; exports.createRevalidateHandler = createRevalidateHandler; exports.createWatchSyncHandler = createWatchSyncHandler; exports.getPreviewToken = getPreviewToken; exports.previewMiddleware = previewMiddleware; exports.verifyBuilderNotice = _chunk53B64NRGcjs.verifyBuilderNotice;
|
package/dist/next.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Headless client for Throttle Builder: read published pages, parts, slots and site settings from a storefront, with Next.js cache, revalidation and preview helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"server-only": "0.0.1",
|
|
62
|
-
"@usethrottle/builder-schema": "^0.
|
|
62
|
+
"@usethrottle/builder-schema": "^0.4.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=14",
|