@usethrottle/builder 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DZMWUQSG.cjs → chunk-BO5V65VO.cjs} +1 -1
- package/dist/{chunk-M6GBKCCG.js → chunk-JCWVCDYJ.js} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/next.cjs +10 -10
- package/dist/next.js +1 -1
- package/dist/watch.cjs +1 -1
- package/dist/watch.js +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _chunkBO5V65VOcjs = require('./chunk-BO5V65VO.cjs');
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
@@ -31,4 +31,4 @@ var _chunkDZMWUQSGcjs = require('./chunk-DZMWUQSG.cjs');
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
exports.BUILDER_SCHEMA_MIN =
|
|
34
|
+
exports.BUILDER_SCHEMA_MIN = _chunkBO5V65VOcjs.BUILDER_SCHEMA_MIN; exports.BUILDER_TAGS = _chunkBO5V65VOcjs.BUILDER_TAGS; exports.BuilderNotFoundError = _chunkBO5V65VOcjs.BuilderNotFoundError; exports.BuilderReleaseNotFoundError = _chunkBO5V65VOcjs.BuilderReleaseNotFoundError; exports.BuilderUnavailableError = _chunkBO5V65VOcjs.BuilderUnavailableError; exports.BuilderValidationError = _chunkBO5V65VOcjs.BuilderValidationError; exports.DEFAULT_BASE_URL = _chunkBO5V65VOcjs.DEFAULT_BASE_URL; exports.DEFAULT_TIMEOUT_MS = _chunkBO5V65VOcjs.DEFAULT_TIMEOUT_MS; exports.PreviewExpiredError = _chunkBO5V65VOcjs.PreviewExpiredError; exports.SUPPORTED_BUNDLE_VERSION = _chunkBO5V65VOcjs.SUPPORTED_BUNDLE_VERSION; exports.UNTIL_CHANGED_REVALIDATE_S = _chunkBO5V65VOcjs.UNTIL_CHANGED_REVALIDATE_S; exports.createBuilderClient = _chunkBO5V65VOcjs.createBuilderClient; exports.scopesToTags = _chunkBO5V65VOcjs.scopesToTags; exports.templateTag = _chunkBO5V65VOcjs.templateTag; exports.verifyBuilderNotice = _chunkBO5V65VOcjs.verifyBuilderNotice;
|
package/dist/index.d.cts
CHANGED
|
@@ -350,10 +350,10 @@ declare const UNTIL_CHANGED_REVALIDATE_S = 3600;
|
|
|
350
350
|
|
|
351
351
|
/**
|
|
352
352
|
* The `x-builder-schema-min` request header: the builder-schema version this package reads. The Builder Worker
|
|
353
|
-
* serves v2 published site settings only to a client that sends a version of at least 0.4.0 (R2); one that sends
|
|
353
|
+
* serves v2 published site settings only to a client that sends a version of at least 0.4.0 (R2), and `shopDisplay.product.units` only from 0.5.0; one that sends
|
|
354
354
|
* none gets the v1 downgrade. Kept equal to `packages/builder-schema/package.json` by `schema-min-header.test.ts`:
|
|
355
355
|
* bump both together.
|
|
356
356
|
*/
|
|
357
|
-
declare const BUILDER_SCHEMA_MIN = "0.
|
|
357
|
+
declare const BUILDER_SCHEMA_MIN = "0.5.0";
|
|
358
358
|
|
|
359
359
|
export { BUILDER_SCHEMA_MIN, BUILDER_TAGS, type BuildBuilderClient, type BuildClientOptions, type BuilderBundle, type BuilderClient, type BuilderClientOptions, BuilderNotFoundError, type BuilderPageSummary, BuilderReleaseNotFoundError, type BuilderSite, BuilderUnavailableError, type BuilderUnavailableReason, BuilderValidationError, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type LoadedDocument, type LoadedPage, type LocaleOptions, type PageByPathClient, 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
|
@@ -350,10 +350,10 @@ declare const UNTIL_CHANGED_REVALIDATE_S = 3600;
|
|
|
350
350
|
|
|
351
351
|
/**
|
|
352
352
|
* The `x-builder-schema-min` request header: the builder-schema version this package reads. The Builder Worker
|
|
353
|
-
* serves v2 published site settings only to a client that sends a version of at least 0.4.0 (R2); one that sends
|
|
353
|
+
* serves v2 published site settings only to a client that sends a version of at least 0.4.0 (R2), and `shopDisplay.product.units` only from 0.5.0; one that sends
|
|
354
354
|
* none gets the v1 downgrade. Kept equal to `packages/builder-schema/package.json` by `schema-min-header.test.ts`:
|
|
355
355
|
* bump both together.
|
|
356
356
|
*/
|
|
357
|
-
declare const BUILDER_SCHEMA_MIN = "0.
|
|
357
|
+
declare const BUILDER_SCHEMA_MIN = "0.5.0";
|
|
358
358
|
|
|
359
359
|
export { BUILDER_SCHEMA_MIN, BUILDER_TAGS, type BuildBuilderClient, type BuildClientOptions, type BuilderBundle, type BuilderClient, type BuilderClientOptions, BuilderNotFoundError, type BuilderPageSummary, BuilderReleaseNotFoundError, type BuilderSite, BuilderUnavailableError, type BuilderUnavailableReason, BuilderValidationError, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type LoadedDocument, type LoadedPage, type LocaleOptions, type PageByPathClient, 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
package/dist/next.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkBO5V65VOcjs = require('./chunk-BO5V65VO.cjs');
|
|
10
10
|
|
|
11
11
|
// src/next/index.ts
|
|
12
12
|
require('server-only');
|
|
@@ -49,7 +49,7 @@ function parseNotice(rawBody) {
|
|
|
49
49
|
if (typeof value !== "object" || value === null) return null;
|
|
50
50
|
const { type, generation, scopes } = value;
|
|
51
51
|
if (type !== "builder.changed" || typeof generation !== "number" || !Number.isSafeInteger(generation) || generation < 0 || !Array.isArray(scopes) || scopes.length === 0 || scopes.length > MAX_SCOPES || !scopes.every(
|
|
52
|
-
(scope) => typeof scope === "string" && scope.length > 0 && scope.length <=
|
|
52
|
+
(scope) => typeof scope === "string" && scope.length > 0 && scope.length <= _chunkBO5V65VOcjs.TAG_MAX_CHARS
|
|
53
53
|
))
|
|
54
54
|
return null;
|
|
55
55
|
return { generation, scopes };
|
|
@@ -74,12 +74,12 @@ function createRevalidateHandler(options) {
|
|
|
74
74
|
const now = Math.floor(Date.now() / 1e3);
|
|
75
75
|
let verified = false;
|
|
76
76
|
for (const secret of secrets)
|
|
77
|
-
verified = await
|
|
77
|
+
verified = await _chunkBO5V65VOcjs.verifyBuilderNotice.call(void 0, { rawBody, header, secret, now }) || verified;
|
|
78
78
|
if (!verified) return json(401, { error: "invalid signature" });
|
|
79
79
|
const notice = parseNotice(rawBody);
|
|
80
80
|
if (notice === null) return json(400, { error: "invalid body" });
|
|
81
|
-
const mapped =
|
|
82
|
-
const tags = mapped.length > MAX_TAGS_PER_NOTICE ? [
|
|
81
|
+
const mapped = _chunkBO5V65VOcjs.scopesToTags.call(void 0, notice.scopes);
|
|
82
|
+
const tags = mapped.length > MAX_TAGS_PER_NOTICE ? [_chunkBO5V65VOcjs.BUILDER_TAGS.all] : mapped;
|
|
83
83
|
const revalidate = await _asyncNullishCoalesce(options.revalidateTag, async () => ( await defaultRevalidateTag()));
|
|
84
84
|
for (const tag of tags) revalidate(tag);
|
|
85
85
|
return json(200, { revalidated: tags });
|
|
@@ -104,10 +104,10 @@ function createWatchSyncHandler(options) {
|
|
|
104
104
|
let running;
|
|
105
105
|
const run = async (key) => {
|
|
106
106
|
const doFetch = _nullishCoalesce(options.fetch, () => ( fetch));
|
|
107
|
-
const base = (_nullishCoalesce(options.baseUrl, () => (
|
|
107
|
+
const base = (_nullishCoalesce(options.baseUrl, () => ( _chunkBO5V65VOcjs.DEFAULT_BASE_URL))).replace(/\/+$/u, "");
|
|
108
108
|
const read = async (init) => {
|
|
109
109
|
const response = await doFetch(`${base}/v1/site`, {
|
|
110
|
-
headers: { "X-Builder-Key": key, [
|
|
110
|
+
headers: { "X-Builder-Key": key, [_chunkBO5V65VOcjs.SCHEMA_MIN_HEADER]: _chunkBO5V65VOcjs.BUILDER_SCHEMA_MIN },
|
|
111
111
|
signal: AbortSignal.timeout(READ_TIMEOUT_MS),
|
|
112
112
|
...init
|
|
113
113
|
});
|
|
@@ -120,14 +120,14 @@ function createWatchSyncHandler(options) {
|
|
|
120
120
|
let generation;
|
|
121
121
|
let recorded;
|
|
122
122
|
try {
|
|
123
|
-
recorded = await read({ next: { tags: [
|
|
123
|
+
recorded = await read({ next: { tags: [_chunkBO5V65VOcjs.BUILDER_TAGS.all], revalidate: false } });
|
|
124
124
|
generation = await read({ cache: "no-store" });
|
|
125
125
|
} catch (e2) {
|
|
126
126
|
return json2(502, { error: "The Builder could not be read." });
|
|
127
127
|
}
|
|
128
128
|
if (generation === recorded) return json2(200, { changed: false, generation });
|
|
129
129
|
const revalidate = await _asyncNullishCoalesce(options.revalidateTag, async () => ( await defaultRevalidateTag2()));
|
|
130
|
-
revalidate(
|
|
130
|
+
revalidate(_chunkBO5V65VOcjs.BUILDER_TAGS.all);
|
|
131
131
|
return json2(200, { changed: true, generation });
|
|
132
132
|
};
|
|
133
133
|
return () => {
|
|
@@ -199,4 +199,4 @@ async function getPreviewToken() {
|
|
|
199
199
|
|
|
200
200
|
|
|
201
201
|
|
|
202
|
-
exports.PREVIEW_COOKIE = PREVIEW_COOKIE; exports.clearPreviewCookie = clearPreviewCookie; exports.createRevalidateHandler = createRevalidateHandler; exports.createWatchSyncHandler = createWatchSyncHandler; exports.expiredPreviewCookie = expiredPreviewCookie; exports.getPreviewToken = getPreviewToken; exports.previewMiddleware = previewMiddleware; exports.verifyBuilderNotice =
|
|
202
|
+
exports.PREVIEW_COOKIE = PREVIEW_COOKIE; exports.clearPreviewCookie = clearPreviewCookie; exports.createRevalidateHandler = createRevalidateHandler; exports.createWatchSyncHandler = createWatchSyncHandler; exports.expiredPreviewCookie = expiredPreviewCookie; exports.getPreviewToken = getPreviewToken; exports.previewMiddleware = previewMiddleware; exports.verifyBuilderNotice = _chunkBO5V65VOcjs.verifyBuilderNotice;
|
package/dist/next.js
CHANGED
package/dist/watch.cjs
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(generation_watch_exports);
|
|
|
30
30
|
var import_react = require("react");
|
|
31
31
|
|
|
32
32
|
// src/schema-min.ts
|
|
33
|
-
var BUILDER_SCHEMA_MIN = "0.
|
|
33
|
+
var BUILDER_SCHEMA_MIN = "0.5.0";
|
|
34
34
|
var SCHEMA_MIN_HEADER = "x-builder-schema-min";
|
|
35
35
|
|
|
36
36
|
// src/generation-watch.ts
|
package/dist/watch.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
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.5.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=14",
|