@usethrottle/builder 0.7.1 → 0.7.3
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/README.md +3 -1
- package/dist/{chunk-YLRXAP4J.cjs → chunk-DZMWUQSG.cjs} +17 -5
- package/dist/{chunk-SRTHMABZ.js → chunk-M6GBKCCG.js} +16 -4
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +1 -1
- package/dist/next.cjs +25 -10
- package/dist/next.d.cts +8 -1
- package/dist/next.d.ts +8 -1
- package/dist/next.js +16 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,9 @@ const { site, header, footer, slots } = await builder.bundle({ page: 'about', sl
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Errors: `BuilderUnavailableError` (timeout after 3 s, network, 5xx), `BuilderNotFoundError`
|
|
15
|
-
(an unpublished page)
|
|
15
|
+
(an unpublished page). A preview token the Builder refuses (401: expired, invalid, forged) is
|
|
16
|
+
answered by the published site, and `onPreviewExpired` fires once (clear the cookie with
|
|
17
|
+
`clearPreviewCookie()` from `/next` in a route handler or server action). A read that fails within 10 minutes of a
|
|
16
18
|
good one answers the good one (per process) and logs once.
|
|
17
19
|
|
|
18
20
|
## Caching (Next.js)
|
|
@@ -542,12 +542,13 @@ function createBuilderClient(options) {
|
|
|
542
542
|
}
|
|
543
543
|
function createLiveClient(options) {
|
|
544
544
|
const { builderKey, previewToken } = options;
|
|
545
|
+
const opts = options;
|
|
545
546
|
if (typeof builderKey !== "string" || builderKey === "")
|
|
546
547
|
throw new TypeError("createBuilderClient needs a builderKey");
|
|
547
548
|
if (builderKey.startsWith("tb_sk_"))
|
|
548
549
|
throw new TypeError("createBuilderClient takes the publishable Builder key (tb_pk_\u2026), never a secret key");
|
|
549
550
|
const previewHeader = previewToken !== void 0 && previewToken !== "" ? previewToken : void 0;
|
|
550
|
-
|
|
551
|
+
let tokenExpired = false;
|
|
551
552
|
const base = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL2))).replace(/\/+$/u, "");
|
|
552
553
|
const timeoutMs = _nullishCoalesce(options.timeoutMs, () => ( DEFAULT_TIMEOUT_MS));
|
|
553
554
|
const doFetch = options.fetch;
|
|
@@ -577,14 +578,14 @@ function createLiveClient(options) {
|
|
|
577
578
|
clearTimeout(timer);
|
|
578
579
|
}
|
|
579
580
|
}
|
|
580
|
-
async function fetchAnswer(path, read2) {
|
|
581
|
+
async function fetchAnswer(path, read2, preview) {
|
|
581
582
|
const headers = {
|
|
582
583
|
accept: "application/json",
|
|
583
584
|
"X-Builder-Key": builderKey,
|
|
584
585
|
[SCHEMA_MIN_HEADER]: BUILDER_SCHEMA_MIN,
|
|
585
586
|
...mediaHeaders(mediaBaseOf(base, options.media))
|
|
586
587
|
};
|
|
587
|
-
if (previewHeader !== void 0) headers["X-Builder-Preview"] = previewHeader;
|
|
588
|
+
if (preview && previewHeader !== void 0) headers["X-Builder-Preview"] = previewHeader;
|
|
588
589
|
const url = `${base}${path}${queryString(_nullishCoalesce(read2.query, () => ( {})))}`;
|
|
589
590
|
const init = { method: "GET", headers, ...cacheInit(fitTags(read2.tags), preview) };
|
|
590
591
|
const { body, status } = await once(url, init);
|
|
@@ -600,11 +601,22 @@ function createLiveClient(options) {
|
|
|
600
601
|
}
|
|
601
602
|
async function read(path, options2, shape) {
|
|
602
603
|
const goodKey = `${base}|${builderKey}|${path}${queryString(_nullishCoalesce(options2.query, () => ( {})))}`;
|
|
604
|
+
const preview = previewHeader !== void 0 && !tokenExpired;
|
|
603
605
|
try {
|
|
604
|
-
const value = shape(await fetchAnswer(path, options2));
|
|
606
|
+
const value = shape(await fetchAnswer(path, options2, preview));
|
|
605
607
|
if (!preview) rememberGood(goodKey, value);
|
|
606
608
|
return value;
|
|
607
609
|
} catch (error) {
|
|
610
|
+
if (error instanceof PreviewExpiredError) {
|
|
611
|
+
if (!tokenExpired) {
|
|
612
|
+
tokenExpired = true;
|
|
613
|
+
try {
|
|
614
|
+
_optionalChain([opts, 'access', _11 => _11.onPreviewExpired, 'optionalCall', _12 => _12()]);
|
|
615
|
+
} catch (e2) {
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return read(path, options2, shape);
|
|
619
|
+
}
|
|
608
620
|
if (preview || !(error instanceof BuilderUnavailableError)) throw error;
|
|
609
621
|
const good = recallGood(goodKey, () => {
|
|
610
622
|
console.warn(
|
|
@@ -746,7 +758,7 @@ async function verifyBuilderNotice(input) {
|
|
|
746
758
|
let matched = false;
|
|
747
759
|
for (const digest of digests) matched = constantTimeEqual(expected, fromHex(digest)) || matched;
|
|
748
760
|
return matched;
|
|
749
|
-
} catch (
|
|
761
|
+
} catch (e3) {
|
|
750
762
|
return false;
|
|
751
763
|
}
|
|
752
764
|
}
|
|
@@ -542,12 +542,13 @@ function createBuilderClient(options) {
|
|
|
542
542
|
}
|
|
543
543
|
function createLiveClient(options) {
|
|
544
544
|
const { builderKey, previewToken } = options;
|
|
545
|
+
const opts = options;
|
|
545
546
|
if (typeof builderKey !== "string" || builderKey === "")
|
|
546
547
|
throw new TypeError("createBuilderClient needs a builderKey");
|
|
547
548
|
if (builderKey.startsWith("tb_sk_"))
|
|
548
549
|
throw new TypeError("createBuilderClient takes the publishable Builder key (tb_pk_\u2026), never a secret key");
|
|
549
550
|
const previewHeader = previewToken !== void 0 && previewToken !== "" ? previewToken : void 0;
|
|
550
|
-
|
|
551
|
+
let tokenExpired = false;
|
|
551
552
|
const base = (options.baseUrl ?? DEFAULT_BASE_URL2).replace(/\/+$/u, "");
|
|
552
553
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
553
554
|
const doFetch = options.fetch;
|
|
@@ -577,14 +578,14 @@ function createLiveClient(options) {
|
|
|
577
578
|
clearTimeout(timer);
|
|
578
579
|
}
|
|
579
580
|
}
|
|
580
|
-
async function fetchAnswer(path, read2) {
|
|
581
|
+
async function fetchAnswer(path, read2, preview) {
|
|
581
582
|
const headers = {
|
|
582
583
|
accept: "application/json",
|
|
583
584
|
"X-Builder-Key": builderKey,
|
|
584
585
|
[SCHEMA_MIN_HEADER]: BUILDER_SCHEMA_MIN,
|
|
585
586
|
...mediaHeaders(mediaBaseOf(base, options.media))
|
|
586
587
|
};
|
|
587
|
-
if (previewHeader !== void 0) headers["X-Builder-Preview"] = previewHeader;
|
|
588
|
+
if (preview && previewHeader !== void 0) headers["X-Builder-Preview"] = previewHeader;
|
|
588
589
|
const url = `${base}${path}${queryString(read2.query ?? {})}`;
|
|
589
590
|
const init = { method: "GET", headers, ...cacheInit(fitTags(read2.tags), preview) };
|
|
590
591
|
const { body, status } = await once(url, init);
|
|
@@ -600,11 +601,22 @@ function createLiveClient(options) {
|
|
|
600
601
|
}
|
|
601
602
|
async function read(path, options2, shape) {
|
|
602
603
|
const goodKey = `${base}|${builderKey}|${path}${queryString(options2.query ?? {})}`;
|
|
604
|
+
const preview = previewHeader !== void 0 && !tokenExpired;
|
|
603
605
|
try {
|
|
604
|
-
const value = shape(await fetchAnswer(path, options2));
|
|
606
|
+
const value = shape(await fetchAnswer(path, options2, preview));
|
|
605
607
|
if (!preview) rememberGood(goodKey, value);
|
|
606
608
|
return value;
|
|
607
609
|
} catch (error) {
|
|
610
|
+
if (error instanceof PreviewExpiredError) {
|
|
611
|
+
if (!tokenExpired) {
|
|
612
|
+
tokenExpired = true;
|
|
613
|
+
try {
|
|
614
|
+
opts.onPreviewExpired?.();
|
|
615
|
+
} catch {
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return read(path, options2, shape);
|
|
619
|
+
}
|
|
608
620
|
if (preview || !(error instanceof BuilderUnavailableError)) throw error;
|
|
609
621
|
const good = recallGood(goodKey, () => {
|
|
610
622
|
console.warn(
|
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _chunkDZMWUQSGcjs = require('./chunk-DZMWUQSG.cjs');
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
@@ -31,4 +31,4 @@ var _chunkYLRXAP4Jcjs = require('./chunk-YLRXAP4J.cjs');
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
exports.BUILDER_SCHEMA_MIN =
|
|
34
|
+
exports.BUILDER_SCHEMA_MIN = _chunkDZMWUQSGcjs.BUILDER_SCHEMA_MIN; exports.BUILDER_TAGS = _chunkDZMWUQSGcjs.BUILDER_TAGS; exports.BuilderNotFoundError = _chunkDZMWUQSGcjs.BuilderNotFoundError; exports.BuilderReleaseNotFoundError = _chunkDZMWUQSGcjs.BuilderReleaseNotFoundError; exports.BuilderUnavailableError = _chunkDZMWUQSGcjs.BuilderUnavailableError; exports.BuilderValidationError = _chunkDZMWUQSGcjs.BuilderValidationError; exports.DEFAULT_BASE_URL = _chunkDZMWUQSGcjs.DEFAULT_BASE_URL; exports.DEFAULT_TIMEOUT_MS = _chunkDZMWUQSGcjs.DEFAULT_TIMEOUT_MS; exports.PreviewExpiredError = _chunkDZMWUQSGcjs.PreviewExpiredError; exports.SUPPORTED_BUNDLE_VERSION = _chunkDZMWUQSGcjs.SUPPORTED_BUNDLE_VERSION; exports.UNTIL_CHANGED_REVALIDATE_S = _chunkDZMWUQSGcjs.UNTIL_CHANGED_REVALIDATE_S; exports.createBuilderClient = _chunkDZMWUQSGcjs.createBuilderClient; exports.scopesToTags = _chunkDZMWUQSGcjs.scopesToTags; exports.templateTag = _chunkDZMWUQSGcjs.templateTag; exports.verifyBuilderNotice = _chunkDZMWUQSGcjs.verifyBuilderNotice;
|
package/dist/index.d.cts
CHANGED
|
@@ -32,9 +32,9 @@ declare class BuilderValidationError extends Error {
|
|
|
32
32
|
constructor(message: string, status?: number);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* The preview token is expired or not valid (`401 PREVIEW_EXPIRED`).
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* The preview token is expired or not valid (`401 PREVIEW_EXPIRED`). The live
|
|
36
|
+
* client catches it itself and reads the published site instead (see
|
|
37
|
+
* `onPreviewExpired`), so a store never sees it from `createBuilderClient`.
|
|
38
38
|
*/
|
|
39
39
|
declare class PreviewExpiredError extends Error {
|
|
40
40
|
constructor();
|
|
@@ -138,10 +138,20 @@ type BuilderClientOptions = {
|
|
|
138
138
|
/**
|
|
139
139
|
* A preview token (`getPreviewToken()` from `@usethrottle/builder/next`).
|
|
140
140
|
* Every read then sends `X-Builder-Preview`, reads drafts, is never cached
|
|
141
|
-
* and never answers from a last good.
|
|
142
|
-
* `
|
|
141
|
+
* and never answers from a last good. When the Builder refuses the token
|
|
142
|
+
* (expired, invalid or forged: `401`), the read is answered from the
|
|
143
|
+
* published site instead, every later read of this client is a published
|
|
144
|
+
* read, and `onPreviewExpired` is called once. A published outage still
|
|
145
|
+
* throws `BuilderUnavailableError`.
|
|
143
146
|
*/
|
|
144
147
|
previewToken?: string | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Called once, when the Builder refuses `previewToken`. Use it to clear the
|
|
150
|
+
* cookie where you control the response (`clearPreviewCookie()` from
|
|
151
|
+
* `@usethrottle/builder/next` in a route handler or server action). It must
|
|
152
|
+
* not throw; a throw is swallowed.
|
|
153
|
+
*/
|
|
154
|
+
onPreviewExpired?: (() => void) | undefined;
|
|
145
155
|
};
|
|
146
156
|
type LocaleOptions = {
|
|
147
157
|
locale?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,9 +32,9 @@ declare class BuilderValidationError extends Error {
|
|
|
32
32
|
constructor(message: string, status?: number);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* The preview token is expired or not valid (`401 PREVIEW_EXPIRED`).
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* The preview token is expired or not valid (`401 PREVIEW_EXPIRED`). The live
|
|
36
|
+
* client catches it itself and reads the published site instead (see
|
|
37
|
+
* `onPreviewExpired`), so a store never sees it from `createBuilderClient`.
|
|
38
38
|
*/
|
|
39
39
|
declare class PreviewExpiredError extends Error {
|
|
40
40
|
constructor();
|
|
@@ -138,10 +138,20 @@ type BuilderClientOptions = {
|
|
|
138
138
|
/**
|
|
139
139
|
* A preview token (`getPreviewToken()` from `@usethrottle/builder/next`).
|
|
140
140
|
* Every read then sends `X-Builder-Preview`, reads drafts, is never cached
|
|
141
|
-
* and never answers from a last good.
|
|
142
|
-
* `
|
|
141
|
+
* and never answers from a last good. When the Builder refuses the token
|
|
142
|
+
* (expired, invalid or forged: `401`), the read is answered from the
|
|
143
|
+
* published site instead, every later read of this client is a published
|
|
144
|
+
* read, and `onPreviewExpired` is called once. A published outage still
|
|
145
|
+
* throws `BuilderUnavailableError`.
|
|
143
146
|
*/
|
|
144
147
|
previewToken?: string | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Called once, when the Builder refuses `previewToken`. Use it to clear the
|
|
150
|
+
* cookie where you control the response (`clearPreviewCookie()` from
|
|
151
|
+
* `@usethrottle/builder/next` in a route handler or server action). It must
|
|
152
|
+
* not throw; a throw is swallowed.
|
|
153
|
+
*/
|
|
154
|
+
onPreviewExpired?: (() => void) | undefined;
|
|
145
155
|
};
|
|
146
156
|
type LocaleOptions = {
|
|
147
157
|
locale?: string;
|
package/dist/index.js
CHANGED
package/dist/next.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkDZMWUQSGcjs = require('./chunk-DZMWUQSG.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 <= _chunkDZMWUQSGcjs.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 _chunkDZMWUQSGcjs.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 = _chunkDZMWUQSGcjs.scopesToTags.call(void 0, notice.scopes);
|
|
82
|
+
const tags = mapped.length > MAX_TAGS_PER_NOTICE ? [_chunkDZMWUQSGcjs.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, () => ( _chunkDZMWUQSGcjs.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, [_chunkDZMWUQSGcjs.SCHEMA_MIN_HEADER]: _chunkDZMWUQSGcjs.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: [_chunkDZMWUQSGcjs.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(_chunkDZMWUQSGcjs.BUILDER_TAGS.all);
|
|
131
131
|
return json2(200, { changed: true, generation });
|
|
132
132
|
};
|
|
133
133
|
return () => {
|
|
@@ -171,6 +171,19 @@ function previewMiddleware(req) {
|
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
+
function expiredPreviewCookie() {
|
|
175
|
+
return `${PREVIEW_COOKIE}=; Max-Age=0; Path=/; HttpOnly; Secure; SameSite=Lax`;
|
|
176
|
+
}
|
|
177
|
+
async function clearPreviewCookie() {
|
|
178
|
+
try {
|
|
179
|
+
const { cookies } = await Promise.resolve().then(() => _interopRequireWildcard(require("next/headers")));
|
|
180
|
+
const store = await cookies();
|
|
181
|
+
store.delete(PREVIEW_COOKIE);
|
|
182
|
+
return true;
|
|
183
|
+
} catch (e3) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
174
187
|
async function getPreviewToken() {
|
|
175
188
|
const { cookies } = await Promise.resolve().then(() => _interopRequireWildcard(require("next/headers")));
|
|
176
189
|
const store = await cookies();
|
|
@@ -184,4 +197,6 @@ async function getPreviewToken() {
|
|
|
184
197
|
|
|
185
198
|
|
|
186
199
|
|
|
187
|
-
|
|
200
|
+
|
|
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 = _chunkDZMWUQSGcjs.verifyBuilderNotice;
|
package/dist/next.d.cts
CHANGED
|
@@ -62,6 +62,13 @@ declare const PREVIEW_COOKIE = "throttle_builder_preview";
|
|
|
62
62
|
* and a token of an unexpected shape, returns `null`.
|
|
63
63
|
*/
|
|
64
64
|
declare function previewMiddleware(req: Request): Response | null;
|
|
65
|
+
/** A `Set-Cookie` value that deletes the preview cookie, for a middleware or route that builds its own response. */
|
|
66
|
+
declare function expiredPreviewCookie(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Deletes the preview cookie through `cookies()`. Next allows that only in a route handler or server action; in a
|
|
69
|
+
* server component it throws, so this answers `false` there instead (rendering must not fail over a cookie).
|
|
70
|
+
*/
|
|
71
|
+
declare function clearPreviewCookie(): Promise<boolean>;
|
|
65
72
|
/**
|
|
66
73
|
* The preview token of the current request (the `throttle_builder_preview`
|
|
67
74
|
* cookie), for `createBuilderClient({ previewToken })`. Reads `cookies()` from
|
|
@@ -72,4 +79,4 @@ declare function previewMiddleware(req: Request): Response | null;
|
|
|
72
79
|
*/
|
|
73
80
|
declare function getPreviewToken(): Promise<string | undefined>;
|
|
74
81
|
|
|
75
|
-
export { type CreateRevalidateHandlerOptions, type CreateWatchSyncHandlerOptions, PREVIEW_COOKIE, createRevalidateHandler, createWatchSyncHandler, getPreviewToken, previewMiddleware };
|
|
82
|
+
export { type CreateRevalidateHandlerOptions, type CreateWatchSyncHandlerOptions, PREVIEW_COOKIE, clearPreviewCookie, createRevalidateHandler, createWatchSyncHandler, expiredPreviewCookie, getPreviewToken, previewMiddleware };
|
package/dist/next.d.ts
CHANGED
|
@@ -62,6 +62,13 @@ declare const PREVIEW_COOKIE = "throttle_builder_preview";
|
|
|
62
62
|
* and a token of an unexpected shape, returns `null`.
|
|
63
63
|
*/
|
|
64
64
|
declare function previewMiddleware(req: Request): Response | null;
|
|
65
|
+
/** A `Set-Cookie` value that deletes the preview cookie, for a middleware or route that builds its own response. */
|
|
66
|
+
declare function expiredPreviewCookie(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Deletes the preview cookie through `cookies()`. Next allows that only in a route handler or server action; in a
|
|
69
|
+
* server component it throws, so this answers `false` there instead (rendering must not fail over a cookie).
|
|
70
|
+
*/
|
|
71
|
+
declare function clearPreviewCookie(): Promise<boolean>;
|
|
65
72
|
/**
|
|
66
73
|
* The preview token of the current request (the `throttle_builder_preview`
|
|
67
74
|
* cookie), for `createBuilderClient({ previewToken })`. Reads `cookies()` from
|
|
@@ -72,4 +79,4 @@ declare function previewMiddleware(req: Request): Response | null;
|
|
|
72
79
|
*/
|
|
73
80
|
declare function getPreviewToken(): Promise<string | undefined>;
|
|
74
81
|
|
|
75
|
-
export { type CreateRevalidateHandlerOptions, type CreateWatchSyncHandlerOptions, PREVIEW_COOKIE, createRevalidateHandler, createWatchSyncHandler, getPreviewToken, previewMiddleware };
|
|
82
|
+
export { type CreateRevalidateHandlerOptions, type CreateWatchSyncHandlerOptions, PREVIEW_COOKIE, clearPreviewCookie, createRevalidateHandler, createWatchSyncHandler, expiredPreviewCookie, getPreviewToken, previewMiddleware };
|
package/dist/next.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
TAG_MAX_CHARS,
|
|
7
7
|
scopesToTags,
|
|
8
8
|
verifyBuilderNotice
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-M6GBKCCG.js";
|
|
10
10
|
|
|
11
11
|
// src/next/index.ts
|
|
12
12
|
import "server-only";
|
|
@@ -171,6 +171,19 @@ function previewMiddleware(req) {
|
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
+
function expiredPreviewCookie() {
|
|
175
|
+
return `${PREVIEW_COOKIE}=; Max-Age=0; Path=/; HttpOnly; Secure; SameSite=Lax`;
|
|
176
|
+
}
|
|
177
|
+
async function clearPreviewCookie() {
|
|
178
|
+
try {
|
|
179
|
+
const { cookies } = await import("next/headers");
|
|
180
|
+
const store = await cookies();
|
|
181
|
+
store.delete(PREVIEW_COOKIE);
|
|
182
|
+
return true;
|
|
183
|
+
} catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
174
187
|
async function getPreviewToken() {
|
|
175
188
|
const { cookies } = await import("next/headers");
|
|
176
189
|
const store = await cookies();
|
|
@@ -179,8 +192,10 @@ async function getPreviewToken() {
|
|
|
179
192
|
}
|
|
180
193
|
export {
|
|
181
194
|
PREVIEW_COOKIE,
|
|
195
|
+
clearPreviewCookie,
|
|
182
196
|
createRevalidateHandler,
|
|
183
197
|
createWatchSyncHandler,
|
|
198
|
+
expiredPreviewCookie,
|
|
184
199
|
getPreviewToken,
|
|
185
200
|
previewMiddleware,
|
|
186
201
|
verifyBuilderNotice
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
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",
|