@usethrottle/builder 0.4.1 → 0.5.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/dist/{chunk-ZLNUG6ZZ.cjs → chunk-CYA6NLSC.cjs} +11 -4
- package/dist/{chunk-XYWLWXKG.js → chunk-TWEYA32T.js} +11 -4
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +1 -1
- package/dist/next.cjs +9 -9
- package/dist/next.js +1 -1
- package/package.json +2 -2
|
@@ -235,12 +235,15 @@ function pageFor(bundle, slug, chain) {
|
|
|
235
235
|
shareImage: page.seo.shareImage,
|
|
236
236
|
noindex: page.seo.noindex
|
|
237
237
|
},
|
|
238
|
-
document: page.document
|
|
238
|
+
document: page.document,
|
|
239
|
+
...sharedOf(bundle)
|
|
239
240
|
};
|
|
240
241
|
}
|
|
242
|
+
var sharedOf = (bundle) => isRecord(bundle.savedSections) ? { savedSections: bundle.savedSections } : {};
|
|
241
243
|
var documentOf = (bundle, held) => ({
|
|
242
244
|
generation: bundle.generation,
|
|
243
|
-
document: held === void 0 ? _builderschema.emptyDocument.call(void 0, ) : held.document
|
|
245
|
+
document: held === void 0 ? _builderschema.emptyDocument.call(void 0, ) : held.document,
|
|
246
|
+
...sharedOf(bundle)
|
|
244
247
|
});
|
|
245
248
|
function createBuildClient(options) {
|
|
246
249
|
const builderKey = _nullishCoalesce(options.builderKey, () => ( ""));
|
|
@@ -294,7 +297,8 @@ function createBuildClient(options) {
|
|
|
294
297
|
...pageSlug === void 0 ? {} : { page: pageFor(bundle, pageSlug, chainOf(bundle, locale)) },
|
|
295
298
|
slots: Object.fromEntries(
|
|
296
299
|
names.map((name) => [name, documentOf(bundle, Object.hasOwn(bundle.slots, name) ? bundle.slots[name] : void 0)])
|
|
297
|
-
)
|
|
300
|
+
),
|
|
301
|
+
...sharedOf(bundle)
|
|
298
302
|
};
|
|
299
303
|
}
|
|
300
304
|
};
|
|
@@ -418,7 +422,10 @@ function readBundle2(answer) {
|
|
|
418
422
|
if (!isRecord(value)) throw invalid2(`Builder slot ${name} answer is not an object`);
|
|
419
423
|
return [name, readDocument2(value, `slot ${name}`)];
|
|
420
424
|
})
|
|
421
|
-
)
|
|
425
|
+
),
|
|
426
|
+
// Passed through as the Worker sent them: the renderer checks what it uses.
|
|
427
|
+
...isRecord(answer.savedSections) ? { savedSections: answer.savedSections } : {},
|
|
428
|
+
...isRecord(answer.code) ? { code: answer.code } : {}
|
|
422
429
|
};
|
|
423
430
|
}
|
|
424
431
|
function createBuilderClient(options) {
|
|
@@ -235,12 +235,15 @@ function pageFor(bundle, slug, chain) {
|
|
|
235
235
|
shareImage: page.seo.shareImage,
|
|
236
236
|
noindex: page.seo.noindex
|
|
237
237
|
},
|
|
238
|
-
document: page.document
|
|
238
|
+
document: page.document,
|
|
239
|
+
...sharedOf(bundle)
|
|
239
240
|
};
|
|
240
241
|
}
|
|
242
|
+
var sharedOf = (bundle) => isRecord(bundle.savedSections) ? { savedSections: bundle.savedSections } : {};
|
|
241
243
|
var documentOf = (bundle, held) => ({
|
|
242
244
|
generation: bundle.generation,
|
|
243
|
-
document: held === void 0 ? emptyDocument() : held.document
|
|
245
|
+
document: held === void 0 ? emptyDocument() : held.document,
|
|
246
|
+
...sharedOf(bundle)
|
|
244
247
|
});
|
|
245
248
|
function createBuildClient(options) {
|
|
246
249
|
const builderKey = options.builderKey ?? "";
|
|
@@ -294,7 +297,8 @@ function createBuildClient(options) {
|
|
|
294
297
|
...pageSlug === void 0 ? {} : { page: pageFor(bundle, pageSlug, chainOf(bundle, locale)) },
|
|
295
298
|
slots: Object.fromEntries(
|
|
296
299
|
names.map((name) => [name, documentOf(bundle, Object.hasOwn(bundle.slots, name) ? bundle.slots[name] : void 0)])
|
|
297
|
-
)
|
|
300
|
+
),
|
|
301
|
+
...sharedOf(bundle)
|
|
298
302
|
};
|
|
299
303
|
}
|
|
300
304
|
};
|
|
@@ -418,7 +422,10 @@ function readBundle2(answer) {
|
|
|
418
422
|
if (!isRecord(value)) throw invalid2(`Builder slot ${name} answer is not an object`);
|
|
419
423
|
return [name, readDocument2(value, `slot ${name}`)];
|
|
420
424
|
})
|
|
421
|
-
)
|
|
425
|
+
),
|
|
426
|
+
// Passed through as the Worker sent them: the renderer checks what it uses.
|
|
427
|
+
...isRecord(answer.savedSections) ? { savedSections: answer.savedSections } : {},
|
|
428
|
+
...isRecord(answer.code) ? { code: answer.code } : {}
|
|
422
429
|
};
|
|
423
430
|
}
|
|
424
431
|
function createBuilderClient(options) {
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkCYA6NLSCcjs = require('./chunk-CYA6NLSC.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -25,4 +25,4 @@ var _chunkZLNUG6ZZcjs = require('./chunk-ZLNUG6ZZ.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
exports.BUILDER_TAGS =
|
|
28
|
+
exports.BUILDER_TAGS = _chunkCYA6NLSCcjs.BUILDER_TAGS; exports.BuilderNotFoundError = _chunkCYA6NLSCcjs.BuilderNotFoundError; exports.BuilderReleaseNotFoundError = _chunkCYA6NLSCcjs.BuilderReleaseNotFoundError; exports.BuilderUnavailableError = _chunkCYA6NLSCcjs.BuilderUnavailableError; exports.DEFAULT_BASE_URL = _chunkCYA6NLSCcjs.DEFAULT_BASE_URL; exports.DEFAULT_TIMEOUT_MS = _chunkCYA6NLSCcjs.DEFAULT_TIMEOUT_MS; exports.PreviewExpiredError = _chunkCYA6NLSCcjs.PreviewExpiredError; exports.SUPPORTED_BUNDLE_VERSION = _chunkCYA6NLSCcjs.SUPPORTED_BUNDLE_VERSION; exports.UNTIL_CHANGED_REVALIDATE_S = _chunkCYA6NLSCcjs.UNTIL_CHANGED_REVALIDATE_S; exports.createBuilderClient = _chunkCYA6NLSCcjs.createBuilderClient; exports.scopesToTags = _chunkCYA6NLSCcjs.scopesToTags; exports.verifyBuilderNotice = _chunkCYA6NLSCcjs.verifyBuilderNotice;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageDocument } from '@usethrottle/builder-schema';
|
|
1
|
+
import { PageDocument, SavedSectionsAnswer, CodeRuntimeAnswer } 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';
|
|
@@ -61,6 +61,10 @@ type BuilderPageSummary = {
|
|
|
61
61
|
type LoadedPage = BuilderPageSummary & {
|
|
62
62
|
generation: number;
|
|
63
63
|
document: PageDocument;
|
|
64
|
+
/** The published saved sections the document references, by the id of their document. */
|
|
65
|
+
savedSections?: SavedSectionsAnswer;
|
|
66
|
+
/** Whether the store runs code widgets and where their scripts come from. */
|
|
67
|
+
code?: CodeRuntimeAnswer;
|
|
64
68
|
[key: string]: unknown;
|
|
65
69
|
};
|
|
66
70
|
type PageRedirect = {
|
|
@@ -70,6 +74,10 @@ type PageRedirect = {
|
|
|
70
74
|
type LoadedDocument = {
|
|
71
75
|
generation: number;
|
|
72
76
|
document: PageDocument;
|
|
77
|
+
/** The published saved sections the document references, by the id of their document. */
|
|
78
|
+
savedSections?: SavedSectionsAnswer;
|
|
79
|
+
/** Whether the store runs code widgets and where their scripts come from. */
|
|
80
|
+
code?: CodeRuntimeAnswer;
|
|
73
81
|
};
|
|
74
82
|
type BuilderBundle = {
|
|
75
83
|
generation: number;
|
|
@@ -79,6 +87,10 @@ type BuilderBundle = {
|
|
|
79
87
|
page?: LoadedPage | PageRedirect;
|
|
80
88
|
/** Only the slots that were asked for. */
|
|
81
89
|
slots: Record<string, LoadedDocument>;
|
|
90
|
+
/** Saved sections of every document in the answer, when the Builder sends them once for all. */
|
|
91
|
+
savedSections?: SavedSectionsAnswer;
|
|
92
|
+
/** The code runtime of the store, when the Builder sends it once for all. */
|
|
93
|
+
code?: CodeRuntimeAnswer;
|
|
82
94
|
};
|
|
83
95
|
type PartName = 'header' | 'footer';
|
|
84
96
|
type BuilderClientOptions = {
|
|
@@ -169,6 +181,8 @@ type ReleaseBundle = {
|
|
|
169
181
|
header: ReleaseDocument;
|
|
170
182
|
footer: ReleaseDocument;
|
|
171
183
|
slots: Record<string, ReleaseDocument>;
|
|
184
|
+
/** The published saved sections the release's documents reference, by the id of their document. */
|
|
185
|
+
savedSections?: SavedSectionsAnswer;
|
|
172
186
|
/** An old slug and the store path of the page that lives there now. */
|
|
173
187
|
redirects: Record<string, string>;
|
|
174
188
|
/** The status each frozen custom widget had when the release was made. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageDocument } from '@usethrottle/builder-schema';
|
|
1
|
+
import { PageDocument, SavedSectionsAnswer, CodeRuntimeAnswer } 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';
|
|
@@ -61,6 +61,10 @@ type BuilderPageSummary = {
|
|
|
61
61
|
type LoadedPage = BuilderPageSummary & {
|
|
62
62
|
generation: number;
|
|
63
63
|
document: PageDocument;
|
|
64
|
+
/** The published saved sections the document references, by the id of their document. */
|
|
65
|
+
savedSections?: SavedSectionsAnswer;
|
|
66
|
+
/** Whether the store runs code widgets and where their scripts come from. */
|
|
67
|
+
code?: CodeRuntimeAnswer;
|
|
64
68
|
[key: string]: unknown;
|
|
65
69
|
};
|
|
66
70
|
type PageRedirect = {
|
|
@@ -70,6 +74,10 @@ type PageRedirect = {
|
|
|
70
74
|
type LoadedDocument = {
|
|
71
75
|
generation: number;
|
|
72
76
|
document: PageDocument;
|
|
77
|
+
/** The published saved sections the document references, by the id of their document. */
|
|
78
|
+
savedSections?: SavedSectionsAnswer;
|
|
79
|
+
/** Whether the store runs code widgets and where their scripts come from. */
|
|
80
|
+
code?: CodeRuntimeAnswer;
|
|
73
81
|
};
|
|
74
82
|
type BuilderBundle = {
|
|
75
83
|
generation: number;
|
|
@@ -79,6 +87,10 @@ type BuilderBundle = {
|
|
|
79
87
|
page?: LoadedPage | PageRedirect;
|
|
80
88
|
/** Only the slots that were asked for. */
|
|
81
89
|
slots: Record<string, LoadedDocument>;
|
|
90
|
+
/** Saved sections of every document in the answer, when the Builder sends them once for all. */
|
|
91
|
+
savedSections?: SavedSectionsAnswer;
|
|
92
|
+
/** The code runtime of the store, when the Builder sends it once for all. */
|
|
93
|
+
code?: CodeRuntimeAnswer;
|
|
82
94
|
};
|
|
83
95
|
type PartName = 'header' | 'footer';
|
|
84
96
|
type BuilderClientOptions = {
|
|
@@ -169,6 +181,8 @@ type ReleaseBundle = {
|
|
|
169
181
|
header: ReleaseDocument;
|
|
170
182
|
footer: ReleaseDocument;
|
|
171
183
|
slots: Record<string, ReleaseDocument>;
|
|
184
|
+
/** The published saved sections the release's documents reference, by the id of their document. */
|
|
185
|
+
savedSections?: SavedSectionsAnswer;
|
|
172
186
|
/** An old slug and the store path of the page that lives there now. */
|
|
173
187
|
redirects: Record<string, string>;
|
|
174
188
|
/** The status each frozen custom widget had when the release was made. */
|
package/dist/index.js
CHANGED
package/dist/next.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkCYA6NLSCcjs = require('./chunk-CYA6NLSC.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 <= _chunkCYA6NLSCcjs.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 _chunkCYA6NLSCcjs.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 = _chunkCYA6NLSCcjs.scopesToTags.call(void 0, notice.scopes);
|
|
80
|
+
const tags = mapped.length > MAX_TAGS_PER_NOTICE ? [_chunkCYA6NLSCcjs.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, () => ( _chunkCYA6NLSCcjs.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: [_chunkCYA6NLSCcjs.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(_chunkCYA6NLSCcjs.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 = _chunkCYA6NLSCcjs.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.5.1",
|
|
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.3.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=14",
|