@usethrottle/builder 0.0.0-stage → 0.2.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/README.md +57 -2
- package/dist/chunk-EERLS5TR.js +98 -0
- package/dist/chunk-UFIR4HJA.cjs +98 -0
- package/dist/index.cjs +533 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +533 -0
- package/dist/next.cjs +117 -0
- package/dist/next.d.cts +45 -0
- package/dist/next.d.ts +45 -0
- package/dist/next.js +117 -0
- package/dist/verify-CkxGofEg.d.cts +15 -0
- package/dist/verify-CkxGofEg.d.ts +15 -0
- package/dist/watch.cjs +103 -0
- package/dist/watch.js +83 -0
- package/package.json +93 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { PageDocument } from '@usethrottle/builder-schema';
|
|
2
|
+
export { v as verifyBuilderNotice } from './verify-CkxGofEg.cjs';
|
|
3
|
+
|
|
4
|
+
type BuilderUnavailableReason = 'timeout' | 'network' | 'status' | 'invalid-response' | 'unsupported-document';
|
|
5
|
+
/**
|
|
6
|
+
* The Builder could not answer: a timeout, a network failure, a non-success
|
|
7
|
+
* status, a body that is not what the read API sends, or a document from a
|
|
8
|
+
* newer schema than this build reads. A caller with no last good answer lets
|
|
9
|
+
* it reach the store's error boundary instead of rendering a blank page.
|
|
10
|
+
*/
|
|
11
|
+
declare class BuilderUnavailableError extends Error {
|
|
12
|
+
readonly reason: BuilderUnavailableReason;
|
|
13
|
+
/** The HTTP status, when the Builder answered. */
|
|
14
|
+
readonly status: number | undefined;
|
|
15
|
+
constructor(reason: BuilderUnavailableReason, message: string, options?: {
|
|
16
|
+
status?: number;
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** A page (or a bundle's page) that is not published and has no redirect: `404 PAGE_NOT_FOUND`. */
|
|
21
|
+
declare class BuilderNotFoundError extends Error {
|
|
22
|
+
readonly slug: string | undefined;
|
|
23
|
+
constructor(slug?: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The preview token is expired or not valid (`401 PREVIEW_EXPIRED`). A preview
|
|
27
|
+
* read never falls back to the published page: the caller shows that the link
|
|
28
|
+
* has expired.
|
|
29
|
+
*/
|
|
30
|
+
declare class PreviewExpiredError extends Error {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The release a build asked for does not exist (`404 RELEASE_NOT_FOUND`): a wrong
|
|
35
|
+
* `BUILDER_RELEASE_ID`, a release pruned from the history, or, for `latest`, a
|
|
36
|
+
* site that has never been released. A build with no release must fail, not
|
|
37
|
+
* publish an empty store.
|
|
38
|
+
*/
|
|
39
|
+
declare class BuilderReleaseNotFoundError extends Error {
|
|
40
|
+
readonly release: string;
|
|
41
|
+
constructor(release: string);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Published site settings resolved for one locale (localized values are strings). */
|
|
45
|
+
type BuilderSite = {
|
|
46
|
+
generation: number;
|
|
47
|
+
siteVersion: number;
|
|
48
|
+
settings: Record<string, unknown>;
|
|
49
|
+
};
|
|
50
|
+
type BuilderPageSummary = {
|
|
51
|
+
id: string;
|
|
52
|
+
slug: string;
|
|
53
|
+
pageType: string;
|
|
54
|
+
title: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
path: string;
|
|
57
|
+
/** The page asks search engines to skip it (`seo.noindex`). Absent from a Worker that predates it. */
|
|
58
|
+
noindex?: boolean;
|
|
59
|
+
};
|
|
60
|
+
/** A published page: its metadata and its document (with frozen custom widgets and assets). */
|
|
61
|
+
type LoadedPage = BuilderPageSummary & {
|
|
62
|
+
generation: number;
|
|
63
|
+
document: PageDocument;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
type PageRedirect = {
|
|
67
|
+
redirectTo: string;
|
|
68
|
+
};
|
|
69
|
+
/** A published part or slot document; an empty document when unpublished. */
|
|
70
|
+
type LoadedDocument = {
|
|
71
|
+
generation: number;
|
|
72
|
+
document: PageDocument;
|
|
73
|
+
};
|
|
74
|
+
type BuilderBundle = {
|
|
75
|
+
generation: number;
|
|
76
|
+
site: BuilderSite;
|
|
77
|
+
header: LoadedDocument;
|
|
78
|
+
footer: LoadedDocument;
|
|
79
|
+
page?: LoadedPage | PageRedirect;
|
|
80
|
+
/** Only the slots that were asked for. */
|
|
81
|
+
slots: Record<string, LoadedDocument>;
|
|
82
|
+
};
|
|
83
|
+
type PartName = 'header' | 'footer';
|
|
84
|
+
type BuilderClientOptions = {
|
|
85
|
+
/** The publishable key (`tb_pk_…`). Sent as `X-Builder-Key`. */
|
|
86
|
+
builderKey: string;
|
|
87
|
+
/** Defaults to `https://builder.usethrottle.dev`. */
|
|
88
|
+
baseUrl?: string;
|
|
89
|
+
fetch?: typeof fetch;
|
|
90
|
+
/** Per read, body included. Default 3000. */
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
/**
|
|
93
|
+
* A preview token (`getPreviewToken()` from `@usethrottle/builder/next`).
|
|
94
|
+
* Every read then sends `X-Builder-Preview`, reads drafts, is never cached
|
|
95
|
+
* and never answers from a last good. An expired token throws
|
|
96
|
+
* `PreviewExpiredError`.
|
|
97
|
+
*/
|
|
98
|
+
previewToken?: string | undefined;
|
|
99
|
+
};
|
|
100
|
+
type LocaleOptions = {
|
|
101
|
+
locale?: string;
|
|
102
|
+
};
|
|
103
|
+
type BuilderClient = {
|
|
104
|
+
/** `build` for a client made with `mode: 'build'`: it reads a frozen release and never the live API. */
|
|
105
|
+
readonly mode?: 'live' | 'build';
|
|
106
|
+
site(options?: LocaleOptions): Promise<BuilderSite>;
|
|
107
|
+
pages: {
|
|
108
|
+
list(): Promise<BuilderPageSummary[]>;
|
|
109
|
+
get(slug: string, options?: LocaleOptions): Promise<LoadedPage | PageRedirect>;
|
|
110
|
+
};
|
|
111
|
+
parts: {
|
|
112
|
+
get(name: PartName, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
113
|
+
};
|
|
114
|
+
slots: {
|
|
115
|
+
get(name: string, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
116
|
+
};
|
|
117
|
+
bundle(options?: LocaleOptions & {
|
|
118
|
+
page?: string;
|
|
119
|
+
slots?: readonly string[];
|
|
120
|
+
}): Promise<BuilderBundle>;
|
|
121
|
+
};
|
|
122
|
+
/** A published part or slot as a release holds it. */
|
|
123
|
+
type ReleaseDocument = {
|
|
124
|
+
version: number;
|
|
125
|
+
document: PageDocument;
|
|
126
|
+
};
|
|
127
|
+
/** One page of a release. Titles and `seo` text keep their locale maps; the document does too. */
|
|
128
|
+
type ReleasePage = {
|
|
129
|
+
id: string;
|
|
130
|
+
slug: string;
|
|
131
|
+
pageType: string;
|
|
132
|
+
path: string;
|
|
133
|
+
version: number;
|
|
134
|
+
publishedAt: string;
|
|
135
|
+
title: Record<string, string>;
|
|
136
|
+
seo: {
|
|
137
|
+
title?: Record<string, string>;
|
|
138
|
+
description?: Record<string, string>;
|
|
139
|
+
shareImage: unknown;
|
|
140
|
+
noindex: boolean;
|
|
141
|
+
};
|
|
142
|
+
document: PageDocument;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The whole site as one release froze it: `GET /v1/releases/:id/bundle`. The
|
|
146
|
+
* same release id always gives the same bundle. `site` holds the settings
|
|
147
|
+
* resolved for each locale of the site; the announcement is NOT windowed in it
|
|
148
|
+
* (`announcement.enabled` is the merchant's switch, `startsAt` and `endsAt`
|
|
149
|
+
* beside it), because the moment of a visit is not known when a release is
|
|
150
|
+
* built. The build client decides it at every read.
|
|
151
|
+
*/
|
|
152
|
+
type ReleaseBundle = {
|
|
153
|
+
bundleVersion: number;
|
|
154
|
+
releaseId: string;
|
|
155
|
+
kind: 'release' | 'rollback';
|
|
156
|
+
sourceReleaseId: string | null;
|
|
157
|
+
createdAt: string;
|
|
158
|
+
generation: number;
|
|
159
|
+
siteVersion: number;
|
|
160
|
+
defaultLocale: string;
|
|
161
|
+
locales: string[];
|
|
162
|
+
site: Record<string, {
|
|
163
|
+
brand: {
|
|
164
|
+
storeName: string;
|
|
165
|
+
};
|
|
166
|
+
settings: Record<string, unknown>;
|
|
167
|
+
}>;
|
|
168
|
+
pages: ReleasePage[];
|
|
169
|
+
header: ReleaseDocument;
|
|
170
|
+
footer: ReleaseDocument;
|
|
171
|
+
slots: Record<string, ReleaseDocument>;
|
|
172
|
+
/** An old slug and the store path of the page that lives there now. */
|
|
173
|
+
redirects: Record<string, string>;
|
|
174
|
+
/** The status each frozen custom widget had when the release was made. */
|
|
175
|
+
customWidgets: Record<string, 'active' | 'disabled'>;
|
|
176
|
+
};
|
|
177
|
+
type BuildClientCommon = {
|
|
178
|
+
mode: 'build';
|
|
179
|
+
/** Defaults to `https://builder.usethrottle.dev`. */
|
|
180
|
+
baseUrl?: string;
|
|
181
|
+
fetch?: typeof fetch;
|
|
182
|
+
/** The bundle read, body included. Default 60000 (a bundle is the whole site). */
|
|
183
|
+
timeoutMs?: number;
|
|
184
|
+
/**
|
|
185
|
+
* The release this client reads, instead of `BUILDER_RELEASE_ID`. A store sets it from a value Next inlines at
|
|
186
|
+
* build, so a page Next renders again later reads the release it was built from, not a newer one.
|
|
187
|
+
*/
|
|
188
|
+
release?: string;
|
|
189
|
+
/** The clock that decides the announcement window at every read. Default `Date.now`. */
|
|
190
|
+
now?: () => number;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* A build client needs a way to get its release: a key to read it with, or a bundle you already hold (a fixture, a
|
|
194
|
+
* file read at build). With neither the call does not compile.
|
|
195
|
+
*/
|
|
196
|
+
type BuildClientOptions = BuildClientCommon & ({
|
|
197
|
+
/**
|
|
198
|
+
* A publishable key of a server channel (`tb_pk_...`, the build key), or a secret key holding
|
|
199
|
+
* `releases:read` (`tb_sk_...`). Keep it on the server and in your build; never in a `NEXT_PUBLIC_` variable.
|
|
200
|
+
*/
|
|
201
|
+
builderKey: string;
|
|
202
|
+
/** A bundle you already hold: the client then makes no request at all. */
|
|
203
|
+
releaseBundle?: ReleaseBundle;
|
|
204
|
+
} | {
|
|
205
|
+
/** A bundle you already hold: the client then makes no request at all and needs no key. */
|
|
206
|
+
releaseBundle: ReleaseBundle;
|
|
207
|
+
builderKey?: string;
|
|
208
|
+
});
|
|
209
|
+
type BuildBuilderClient = BuilderClient & {
|
|
210
|
+
readonly mode: 'build';
|
|
211
|
+
/**
|
|
212
|
+
* The release's bundle, read once per process and kept in memory. The release
|
|
213
|
+
* is `release` when given, else the `BUILDER_RELEASE_ID` environment variable,
|
|
214
|
+
* else the newest (`latest`). Every other read of this client (`site`, `pages`,
|
|
215
|
+
* `parts`, `slots`, `bundle`) is answered from this bundle with no request.
|
|
216
|
+
*/
|
|
217
|
+
getReleaseBundle(options?: {
|
|
218
|
+
release?: string;
|
|
219
|
+
}): Promise<ReleaseBundle>;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
declare const DEFAULT_BASE_URL = "https://builder.usethrottle.dev";
|
|
223
|
+
declare const DEFAULT_TIMEOUT_MS = 3000;
|
|
224
|
+
/**
|
|
225
|
+
* `mode: 'build'` makes the client of a build-time site: it reads one frozen
|
|
226
|
+
* release (`getReleaseBundle`) and answers every other read from it. Without a
|
|
227
|
+
* mode, the client reads the live API.
|
|
228
|
+
*/
|
|
229
|
+
declare function createBuilderClient(options: BuildClientOptions): BuildBuilderClient;
|
|
230
|
+
declare function createBuilderClient(options: BuilderClientOptions): BuilderClient;
|
|
231
|
+
|
|
232
|
+
/** The bundle format this SDK reads (`BUNDLE_VERSION` of the Builder). */
|
|
233
|
+
declare const SUPPORTED_BUNDLE_VERSION = 1;
|
|
234
|
+
|
|
235
|
+
declare const BUILDER_TAGS: {
|
|
236
|
+
readonly all: "throttle-builder";
|
|
237
|
+
readonly site: "throttle-builder:site";
|
|
238
|
+
readonly pages: "throttle-builder:pages";
|
|
239
|
+
readonly page: (slug: string) => string;
|
|
240
|
+
readonly part: (name: string) => string;
|
|
241
|
+
readonly slot: (name: string) => string;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* The tags a change notice's scopes clear. `site` and `menus` clear the site,
|
|
245
|
+
* header and footer reads and never pages. `header` and `footer` clear their
|
|
246
|
+
* part, `pages` the list, `page:<slug>` and `slot:<name>` that one read. A
|
|
247
|
+
* scope this build does not know clears the coarse tag, so a newer Worker
|
|
248
|
+
* never leaves a store stale. In order, without repeats.
|
|
249
|
+
*/
|
|
250
|
+
declare function scopesToTags(scopes: readonly string[]): string[];
|
|
251
|
+
|
|
252
|
+
/** Next's `revalidate` for a published read: only a safety net behind the change notices. */
|
|
253
|
+
declare const UNTIL_CHANGED_REVALIDATE_S = 3600;
|
|
254
|
+
|
|
255
|
+
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { PageDocument } from '@usethrottle/builder-schema';
|
|
2
|
+
export { v as verifyBuilderNotice } from './verify-CkxGofEg.js';
|
|
3
|
+
|
|
4
|
+
type BuilderUnavailableReason = 'timeout' | 'network' | 'status' | 'invalid-response' | 'unsupported-document';
|
|
5
|
+
/**
|
|
6
|
+
* The Builder could not answer: a timeout, a network failure, a non-success
|
|
7
|
+
* status, a body that is not what the read API sends, or a document from a
|
|
8
|
+
* newer schema than this build reads. A caller with no last good answer lets
|
|
9
|
+
* it reach the store's error boundary instead of rendering a blank page.
|
|
10
|
+
*/
|
|
11
|
+
declare class BuilderUnavailableError extends Error {
|
|
12
|
+
readonly reason: BuilderUnavailableReason;
|
|
13
|
+
/** The HTTP status, when the Builder answered. */
|
|
14
|
+
readonly status: number | undefined;
|
|
15
|
+
constructor(reason: BuilderUnavailableReason, message: string, options?: {
|
|
16
|
+
status?: number;
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** A page (or a bundle's page) that is not published and has no redirect: `404 PAGE_NOT_FOUND`. */
|
|
21
|
+
declare class BuilderNotFoundError extends Error {
|
|
22
|
+
readonly slug: string | undefined;
|
|
23
|
+
constructor(slug?: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The preview token is expired or not valid (`401 PREVIEW_EXPIRED`). A preview
|
|
27
|
+
* read never falls back to the published page: the caller shows that the link
|
|
28
|
+
* has expired.
|
|
29
|
+
*/
|
|
30
|
+
declare class PreviewExpiredError extends Error {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The release a build asked for does not exist (`404 RELEASE_NOT_FOUND`): a wrong
|
|
35
|
+
* `BUILDER_RELEASE_ID`, a release pruned from the history, or, for `latest`, a
|
|
36
|
+
* site that has never been released. A build with no release must fail, not
|
|
37
|
+
* publish an empty store.
|
|
38
|
+
*/
|
|
39
|
+
declare class BuilderReleaseNotFoundError extends Error {
|
|
40
|
+
readonly release: string;
|
|
41
|
+
constructor(release: string);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Published site settings resolved for one locale (localized values are strings). */
|
|
45
|
+
type BuilderSite = {
|
|
46
|
+
generation: number;
|
|
47
|
+
siteVersion: number;
|
|
48
|
+
settings: Record<string, unknown>;
|
|
49
|
+
};
|
|
50
|
+
type BuilderPageSummary = {
|
|
51
|
+
id: string;
|
|
52
|
+
slug: string;
|
|
53
|
+
pageType: string;
|
|
54
|
+
title: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
path: string;
|
|
57
|
+
/** The page asks search engines to skip it (`seo.noindex`). Absent from a Worker that predates it. */
|
|
58
|
+
noindex?: boolean;
|
|
59
|
+
};
|
|
60
|
+
/** A published page: its metadata and its document (with frozen custom widgets and assets). */
|
|
61
|
+
type LoadedPage = BuilderPageSummary & {
|
|
62
|
+
generation: number;
|
|
63
|
+
document: PageDocument;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
type PageRedirect = {
|
|
67
|
+
redirectTo: string;
|
|
68
|
+
};
|
|
69
|
+
/** A published part or slot document; an empty document when unpublished. */
|
|
70
|
+
type LoadedDocument = {
|
|
71
|
+
generation: number;
|
|
72
|
+
document: PageDocument;
|
|
73
|
+
};
|
|
74
|
+
type BuilderBundle = {
|
|
75
|
+
generation: number;
|
|
76
|
+
site: BuilderSite;
|
|
77
|
+
header: LoadedDocument;
|
|
78
|
+
footer: LoadedDocument;
|
|
79
|
+
page?: LoadedPage | PageRedirect;
|
|
80
|
+
/** Only the slots that were asked for. */
|
|
81
|
+
slots: Record<string, LoadedDocument>;
|
|
82
|
+
};
|
|
83
|
+
type PartName = 'header' | 'footer';
|
|
84
|
+
type BuilderClientOptions = {
|
|
85
|
+
/** The publishable key (`tb_pk_…`). Sent as `X-Builder-Key`. */
|
|
86
|
+
builderKey: string;
|
|
87
|
+
/** Defaults to `https://builder.usethrottle.dev`. */
|
|
88
|
+
baseUrl?: string;
|
|
89
|
+
fetch?: typeof fetch;
|
|
90
|
+
/** Per read, body included. Default 3000. */
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
/**
|
|
93
|
+
* A preview token (`getPreviewToken()` from `@usethrottle/builder/next`).
|
|
94
|
+
* Every read then sends `X-Builder-Preview`, reads drafts, is never cached
|
|
95
|
+
* and never answers from a last good. An expired token throws
|
|
96
|
+
* `PreviewExpiredError`.
|
|
97
|
+
*/
|
|
98
|
+
previewToken?: string | undefined;
|
|
99
|
+
};
|
|
100
|
+
type LocaleOptions = {
|
|
101
|
+
locale?: string;
|
|
102
|
+
};
|
|
103
|
+
type BuilderClient = {
|
|
104
|
+
/** `build` for a client made with `mode: 'build'`: it reads a frozen release and never the live API. */
|
|
105
|
+
readonly mode?: 'live' | 'build';
|
|
106
|
+
site(options?: LocaleOptions): Promise<BuilderSite>;
|
|
107
|
+
pages: {
|
|
108
|
+
list(): Promise<BuilderPageSummary[]>;
|
|
109
|
+
get(slug: string, options?: LocaleOptions): Promise<LoadedPage | PageRedirect>;
|
|
110
|
+
};
|
|
111
|
+
parts: {
|
|
112
|
+
get(name: PartName, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
113
|
+
};
|
|
114
|
+
slots: {
|
|
115
|
+
get(name: string, options?: LocaleOptions): Promise<LoadedDocument>;
|
|
116
|
+
};
|
|
117
|
+
bundle(options?: LocaleOptions & {
|
|
118
|
+
page?: string;
|
|
119
|
+
slots?: readonly string[];
|
|
120
|
+
}): Promise<BuilderBundle>;
|
|
121
|
+
};
|
|
122
|
+
/** A published part or slot as a release holds it. */
|
|
123
|
+
type ReleaseDocument = {
|
|
124
|
+
version: number;
|
|
125
|
+
document: PageDocument;
|
|
126
|
+
};
|
|
127
|
+
/** One page of a release. Titles and `seo` text keep their locale maps; the document does too. */
|
|
128
|
+
type ReleasePage = {
|
|
129
|
+
id: string;
|
|
130
|
+
slug: string;
|
|
131
|
+
pageType: string;
|
|
132
|
+
path: string;
|
|
133
|
+
version: number;
|
|
134
|
+
publishedAt: string;
|
|
135
|
+
title: Record<string, string>;
|
|
136
|
+
seo: {
|
|
137
|
+
title?: Record<string, string>;
|
|
138
|
+
description?: Record<string, string>;
|
|
139
|
+
shareImage: unknown;
|
|
140
|
+
noindex: boolean;
|
|
141
|
+
};
|
|
142
|
+
document: PageDocument;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The whole site as one release froze it: `GET /v1/releases/:id/bundle`. The
|
|
146
|
+
* same release id always gives the same bundle. `site` holds the settings
|
|
147
|
+
* resolved for each locale of the site; the announcement is NOT windowed in it
|
|
148
|
+
* (`announcement.enabled` is the merchant's switch, `startsAt` and `endsAt`
|
|
149
|
+
* beside it), because the moment of a visit is not known when a release is
|
|
150
|
+
* built. The build client decides it at every read.
|
|
151
|
+
*/
|
|
152
|
+
type ReleaseBundle = {
|
|
153
|
+
bundleVersion: number;
|
|
154
|
+
releaseId: string;
|
|
155
|
+
kind: 'release' | 'rollback';
|
|
156
|
+
sourceReleaseId: string | null;
|
|
157
|
+
createdAt: string;
|
|
158
|
+
generation: number;
|
|
159
|
+
siteVersion: number;
|
|
160
|
+
defaultLocale: string;
|
|
161
|
+
locales: string[];
|
|
162
|
+
site: Record<string, {
|
|
163
|
+
brand: {
|
|
164
|
+
storeName: string;
|
|
165
|
+
};
|
|
166
|
+
settings: Record<string, unknown>;
|
|
167
|
+
}>;
|
|
168
|
+
pages: ReleasePage[];
|
|
169
|
+
header: ReleaseDocument;
|
|
170
|
+
footer: ReleaseDocument;
|
|
171
|
+
slots: Record<string, ReleaseDocument>;
|
|
172
|
+
/** An old slug and the store path of the page that lives there now. */
|
|
173
|
+
redirects: Record<string, string>;
|
|
174
|
+
/** The status each frozen custom widget had when the release was made. */
|
|
175
|
+
customWidgets: Record<string, 'active' | 'disabled'>;
|
|
176
|
+
};
|
|
177
|
+
type BuildClientCommon = {
|
|
178
|
+
mode: 'build';
|
|
179
|
+
/** Defaults to `https://builder.usethrottle.dev`. */
|
|
180
|
+
baseUrl?: string;
|
|
181
|
+
fetch?: typeof fetch;
|
|
182
|
+
/** The bundle read, body included. Default 60000 (a bundle is the whole site). */
|
|
183
|
+
timeoutMs?: number;
|
|
184
|
+
/**
|
|
185
|
+
* The release this client reads, instead of `BUILDER_RELEASE_ID`. A store sets it from a value Next inlines at
|
|
186
|
+
* build, so a page Next renders again later reads the release it was built from, not a newer one.
|
|
187
|
+
*/
|
|
188
|
+
release?: string;
|
|
189
|
+
/** The clock that decides the announcement window at every read. Default `Date.now`. */
|
|
190
|
+
now?: () => number;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* A build client needs a way to get its release: a key to read it with, or a bundle you already hold (a fixture, a
|
|
194
|
+
* file read at build). With neither the call does not compile.
|
|
195
|
+
*/
|
|
196
|
+
type BuildClientOptions = BuildClientCommon & ({
|
|
197
|
+
/**
|
|
198
|
+
* A publishable key of a server channel (`tb_pk_...`, the build key), or a secret key holding
|
|
199
|
+
* `releases:read` (`tb_sk_...`). Keep it on the server and in your build; never in a `NEXT_PUBLIC_` variable.
|
|
200
|
+
*/
|
|
201
|
+
builderKey: string;
|
|
202
|
+
/** A bundle you already hold: the client then makes no request at all. */
|
|
203
|
+
releaseBundle?: ReleaseBundle;
|
|
204
|
+
} | {
|
|
205
|
+
/** A bundle you already hold: the client then makes no request at all and needs no key. */
|
|
206
|
+
releaseBundle: ReleaseBundle;
|
|
207
|
+
builderKey?: string;
|
|
208
|
+
});
|
|
209
|
+
type BuildBuilderClient = BuilderClient & {
|
|
210
|
+
readonly mode: 'build';
|
|
211
|
+
/**
|
|
212
|
+
* The release's bundle, read once per process and kept in memory. The release
|
|
213
|
+
* is `release` when given, else the `BUILDER_RELEASE_ID` environment variable,
|
|
214
|
+
* else the newest (`latest`). Every other read of this client (`site`, `pages`,
|
|
215
|
+
* `parts`, `slots`, `bundle`) is answered from this bundle with no request.
|
|
216
|
+
*/
|
|
217
|
+
getReleaseBundle(options?: {
|
|
218
|
+
release?: string;
|
|
219
|
+
}): Promise<ReleaseBundle>;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
declare const DEFAULT_BASE_URL = "https://builder.usethrottle.dev";
|
|
223
|
+
declare const DEFAULT_TIMEOUT_MS = 3000;
|
|
224
|
+
/**
|
|
225
|
+
* `mode: 'build'` makes the client of a build-time site: it reads one frozen
|
|
226
|
+
* release (`getReleaseBundle`) and answers every other read from it. Without a
|
|
227
|
+
* mode, the client reads the live API.
|
|
228
|
+
*/
|
|
229
|
+
declare function createBuilderClient(options: BuildClientOptions): BuildBuilderClient;
|
|
230
|
+
declare function createBuilderClient(options: BuilderClientOptions): BuilderClient;
|
|
231
|
+
|
|
232
|
+
/** The bundle format this SDK reads (`BUNDLE_VERSION` of the Builder). */
|
|
233
|
+
declare const SUPPORTED_BUNDLE_VERSION = 1;
|
|
234
|
+
|
|
235
|
+
declare const BUILDER_TAGS: {
|
|
236
|
+
readonly all: "throttle-builder";
|
|
237
|
+
readonly site: "throttle-builder:site";
|
|
238
|
+
readonly pages: "throttle-builder:pages";
|
|
239
|
+
readonly page: (slug: string) => string;
|
|
240
|
+
readonly part: (name: string) => string;
|
|
241
|
+
readonly slot: (name: string) => string;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* The tags a change notice's scopes clear. `site` and `menus` clear the site,
|
|
245
|
+
* header and footer reads and never pages. `header` and `footer` clear their
|
|
246
|
+
* part, `pages` the list, `page:<slug>` and `slot:<name>` that one read. A
|
|
247
|
+
* scope this build does not know clears the coarse tag, so a newer Worker
|
|
248
|
+
* never leaves a store stale. In order, without repeats.
|
|
249
|
+
*/
|
|
250
|
+
declare function scopesToTags(scopes: readonly string[]): string[];
|
|
251
|
+
|
|
252
|
+
/** Next's `revalidate` for a published read: only a safety net behind the change notices. */
|
|
253
|
+
declare const UNTIL_CHANGED_REVALIDATE_S = 3600;
|
|
254
|
+
|
|
255
|
+
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 };
|