@prismicio/client 6.6.3 → 6.7.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/index.cjs +154 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +74 -12
- package/dist/index.js +154 -66
- package/dist/index.js.map +1 -1
- package/package.json +16 -15
- package/src/buildQueryURL.ts +10 -0
- package/src/client.ts +40 -17
- package/src/index.ts +1 -0
- package/src/lib/getPreviewCookie.ts +30 -0
- package/src/types.ts +49 -16
- package/src/lib/getCookie.ts +0 -58
package/dist/index.d.ts
CHANGED
|
@@ -94,19 +94,19 @@ declare type FetchLike = (input: string, init?: RequestInitLike) => Promise<Resp
|
|
|
94
94
|
*
|
|
95
95
|
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
96
96
|
*/
|
|
97
|
-
declare type AbortSignalLike =
|
|
98
|
-
aborted: any;
|
|
99
|
-
addEventListener: any;
|
|
100
|
-
removeEventListener: any;
|
|
101
|
-
dispatchEvent: any;
|
|
102
|
-
onabort: any;
|
|
103
|
-
};
|
|
97
|
+
declare type AbortSignalLike = any;
|
|
104
98
|
/**
|
|
105
99
|
* The minimum required properties from RequestInit.
|
|
106
100
|
*/
|
|
107
101
|
interface RequestInitLike {
|
|
108
102
|
headers?: Record<string, string>;
|
|
109
|
-
|
|
103
|
+
/**
|
|
104
|
+
* An object that allows you to abort a `fetch()` request if needed via an
|
|
105
|
+
* `AbortController` object
|
|
106
|
+
*
|
|
107
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
108
|
+
*/
|
|
109
|
+
signal?: AbortSignalLike;
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* The minimum required properties from Response.
|
|
@@ -150,6 +150,27 @@ interface Ordering {
|
|
|
150
150
|
/**
|
|
151
151
|
* A `routes` parameter that determines how a document's URL field is resolved.
|
|
152
152
|
*
|
|
153
|
+
* @example With a document's UID field.
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* {
|
|
157
|
+
* "type": "page",
|
|
158
|
+
* "path": "/:uid"
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @example With a Content Relationship `parent` field.
|
|
163
|
+
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* {
|
|
166
|
+
* "type": "page",
|
|
167
|
+
* "path": "/:parent?/:uid",
|
|
168
|
+
* "resolvers": {
|
|
169
|
+
* "parent": "parent"
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
153
174
|
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
154
175
|
*/
|
|
155
176
|
interface Route {
|
|
@@ -157,6 +178,16 @@ interface Route {
|
|
|
157
178
|
* The Custom Type of the document.
|
|
158
179
|
*/
|
|
159
180
|
type: string;
|
|
181
|
+
/**
|
|
182
|
+
* A specific UID to which this route definition is scoped. The route is only
|
|
183
|
+
* defined for the document whose UID matches the given UID.
|
|
184
|
+
*/
|
|
185
|
+
uid?: string;
|
|
186
|
+
/**
|
|
187
|
+
* A specific language to which this route definition is scoped. The route is
|
|
188
|
+
* only defined for documents whose language matches the given language.
|
|
189
|
+
*/
|
|
190
|
+
lang?: string;
|
|
160
191
|
/**
|
|
161
192
|
* The resolved path of the document with optional placeholders.
|
|
162
193
|
*/
|
|
@@ -240,6 +271,15 @@ interface QueryParams {
|
|
|
240
271
|
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
241
272
|
*/
|
|
242
273
|
routes?: Route | string | (Route | string)[];
|
|
274
|
+
/**
|
|
275
|
+
* The `brokenRoute` option allows you to define the route populated in the
|
|
276
|
+
* `url` property for broken Link or Content Relationship fields. A broken
|
|
277
|
+
* link is a Link or Content Relationship field whose linked document has been
|
|
278
|
+
* unpublished or deleted.
|
|
279
|
+
*
|
|
280
|
+
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
281
|
+
*/
|
|
282
|
+
brokenRoute?: string;
|
|
243
283
|
}
|
|
244
284
|
/**
|
|
245
285
|
* Arguments for `buildQueryURL` to construct a Query URL.
|
|
@@ -312,11 +352,20 @@ declare type ClientConfig = {
|
|
|
312
352
|
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
313
353
|
*/
|
|
314
354
|
routes?: NonNullable<BuildQueryURLArgs["routes"]>;
|
|
355
|
+
/**
|
|
356
|
+
* The `brokenRoute` option allows you to define the route populated in the
|
|
357
|
+
* `url` property for broken Link or Content Relationship fields. A broken
|
|
358
|
+
* link is a Link or Content Relationship field whose linked document has been
|
|
359
|
+
* unpublished or deleted.
|
|
360
|
+
*
|
|
361
|
+
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
362
|
+
*/
|
|
363
|
+
brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
|
|
315
364
|
/**
|
|
316
365
|
* Default parameters that will be sent with each query. These parameters can
|
|
317
366
|
* be overridden on each query if needed.
|
|
318
367
|
*/
|
|
319
|
-
defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes">;
|
|
368
|
+
defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes" | "brokenRoute">;
|
|
320
369
|
/**
|
|
321
370
|
* The function used to make network requests to the Prismic REST API. In
|
|
322
371
|
* environments where a global `fetch` function does not exist, such as
|
|
@@ -430,6 +479,15 @@ declare class Client<TDocuments extends prismicT.PrismicDocument = prismicT.Pris
|
|
|
430
479
|
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
431
480
|
*/
|
|
432
481
|
routes?: NonNullable<BuildQueryURLArgs["routes"]>;
|
|
482
|
+
/**
|
|
483
|
+
* The `brokenRoute` option allows you to define the route populated in the
|
|
484
|
+
* `url` property for broken Link or Content Relationship fields. A broken
|
|
485
|
+
* link is a Link or Content Relationship field whose linked document has been
|
|
486
|
+
* unpublished or deleted.
|
|
487
|
+
*
|
|
488
|
+
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
489
|
+
*/
|
|
490
|
+
brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
|
|
433
491
|
/**
|
|
434
492
|
* The function used to make network requests to the Prismic REST API. In
|
|
435
493
|
* environments where a global `fetch` function does not exist, such as
|
|
@@ -1056,7 +1114,9 @@ declare class Client<TDocuments extends prismicT.PrismicDocument = prismicT.Pris
|
|
|
1056
1114
|
/**
|
|
1057
1115
|
* @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
|
|
1058
1116
|
*/
|
|
1059
|
-
graphqlFetch: (input: RequestInfo, init?: RequestInit
|
|
1117
|
+
graphqlFetch: (input: RequestInfo, init?: Omit<RequestInit, "signal"> & {
|
|
1118
|
+
signal?: AbortSignalLike;
|
|
1119
|
+
}) => Promise<Response>;
|
|
1060
1120
|
/**
|
|
1061
1121
|
* A `fetch()` function to be used with GraphQL clients configured for
|
|
1062
1122
|
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
|
|
@@ -1084,7 +1144,9 @@ declare class Client<TDocuments extends prismicT.PrismicDocument = prismicT.Pris
|
|
|
1084
1144
|
* @returns The `fetch()` Response for the request.
|
|
1085
1145
|
* @experimental
|
|
1086
1146
|
*/
|
|
1087
|
-
graphQLFetch(input: RequestInfo, init?: RequestInit
|
|
1147
|
+
graphQLFetch(input: RequestInfo, init?: Omit<RequestInit, "signal"> & {
|
|
1148
|
+
signal?: AbortSignalLike;
|
|
1149
|
+
}): Promise<Response>;
|
|
1088
1150
|
/**
|
|
1089
1151
|
* Returns a cached version of `getRepository` with a TTL.
|
|
1090
1152
|
*
|
|
@@ -1461,4 +1523,4 @@ declare const Predicates: {
|
|
|
1461
1523
|
dateHourBefore: (path: string, hour: number) => string;
|
|
1462
1524
|
};
|
|
1463
1525
|
|
|
1464
|
-
export { BuildQueryURLArgs, Client, ClientConfig, CreateClient, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, getRepositoryEndpoint, getRepositoryName, isRepositoryEndpoint, isRepositoryName, predicate, predicates };
|
|
1526
|
+
export { AbortSignalLike, BuildQueryURLArgs, Client, ClientConfig, CreateClient, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, getRepositoryEndpoint, getRepositoryName, isRepositoryEndpoint, isRepositoryName, predicate, predicates };
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,11 @@ const getRepositoryEndpoint = (repositoryName) => {
|
|
|
16
16
|
if (isRepositoryName(repositoryName)) {
|
|
17
17
|
return `https://${repositoryName}.cdn.prismic.io/api/v2`;
|
|
18
18
|
} else {
|
|
19
|
-
throw new PrismicError(
|
|
19
|
+
throw new PrismicError(
|
|
20
|
+
`An invalid Prismic repository name was given: ${repositoryName}`,
|
|
21
|
+
void 0,
|
|
22
|
+
void 0
|
|
23
|
+
);
|
|
20
24
|
}
|
|
21
25
|
};
|
|
22
26
|
|
|
@@ -24,7 +28,11 @@ const getRepositoryName = (repositoryEndpoint) => {
|
|
|
24
28
|
try {
|
|
25
29
|
return new URL(repositoryEndpoint).hostname.split(".")[0];
|
|
26
30
|
} catch (e) {
|
|
27
|
-
throw new PrismicError(
|
|
31
|
+
throw new PrismicError(
|
|
32
|
+
`An invalid Prismic Rest API V2 endpoint was provided: ${repositoryEndpoint}`,
|
|
33
|
+
void 0,
|
|
34
|
+
void 0
|
|
35
|
+
);
|
|
28
36
|
}
|
|
29
37
|
};
|
|
30
38
|
|
|
@@ -32,7 +40,11 @@ const getGraphQLEndpoint = (repositoryName) => {
|
|
|
32
40
|
if (isRepositoryName(repositoryName)) {
|
|
33
41
|
return `https://${repositoryName}.cdn.prismic.io/graphql`;
|
|
34
42
|
} else {
|
|
35
|
-
throw new PrismicError(
|
|
43
|
+
throw new PrismicError(
|
|
44
|
+
`An invalid Prismic repository name was given: ${repositoryName}`,
|
|
45
|
+
void 0,
|
|
46
|
+
void 0
|
|
47
|
+
);
|
|
36
48
|
}
|
|
37
49
|
};
|
|
38
50
|
|
|
@@ -116,34 +128,37 @@ const findRefByLabel = (refs, label) => {
|
|
|
116
128
|
return findRef(refs, (ref) => ref.label === label);
|
|
117
129
|
};
|
|
118
130
|
|
|
131
|
+
const preview = "io.prismic.preview";
|
|
132
|
+
|
|
133
|
+
var cookie = /*#__PURE__*/Object.freeze({
|
|
134
|
+
__proto__: null,
|
|
135
|
+
preview: preview
|
|
136
|
+
});
|
|
137
|
+
|
|
119
138
|
const readValue = (value) => {
|
|
120
139
|
return value.replace(/%3B/g, ";");
|
|
121
140
|
};
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
141
|
+
const getPreviewCookie = (cookieJar) => {
|
|
142
|
+
const cookies = cookieJar.split("; ");
|
|
143
|
+
let value;
|
|
125
144
|
for (const cookie of cookies) {
|
|
126
145
|
const parts = cookie.split("=");
|
|
127
|
-
const value = parts.slice(1).join("=");
|
|
128
146
|
const name = readValue(parts[0]).replace(/%3D/g, "=");
|
|
129
|
-
|
|
147
|
+
if (name === preview) {
|
|
148
|
+
value = readValue(parts.slice(1).join("="));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
130
151
|
}
|
|
131
|
-
return
|
|
152
|
+
return value;
|
|
132
153
|
};
|
|
133
|
-
const getAll = (cookieStore) => parse(cookieStore);
|
|
134
|
-
const getCookie = (name, cookieJar) => getAll(cookieJar)[name];
|
|
135
154
|
|
|
136
155
|
const minifyGraphQLQuery = (query) => {
|
|
137
|
-
return query.replace(
|
|
156
|
+
return query.replace(
|
|
157
|
+
/(\n| )*( |{|})(\n| )*/gm,
|
|
158
|
+
(_chars, _spaces, brackets) => brackets
|
|
159
|
+
);
|
|
138
160
|
};
|
|
139
161
|
|
|
140
|
-
const preview = "io.prismic.preview";
|
|
141
|
-
|
|
142
|
-
var cookie = /*#__PURE__*/Object.freeze({
|
|
143
|
-
__proto__: null,
|
|
144
|
-
preview: preview
|
|
145
|
-
});
|
|
146
|
-
|
|
147
162
|
class ForbiddenError extends PrismicError {
|
|
148
163
|
}
|
|
149
164
|
|
|
@@ -190,7 +205,9 @@ const argsPredicate = (name) => {
|
|
|
190
205
|
const predicate = {
|
|
191
206
|
at: pathWithArgsPredicate("at"),
|
|
192
207
|
not: pathWithArgsPredicate("not"),
|
|
193
|
-
any: pathWithArgsPredicate(
|
|
208
|
+
any: pathWithArgsPredicate(
|
|
209
|
+
"any"
|
|
210
|
+
),
|
|
194
211
|
in: pathWithArgsPredicate("in"),
|
|
195
212
|
fulltext: pathWithArgsPredicate("fulltext"),
|
|
196
213
|
has: pathPredicate("has"),
|
|
@@ -199,16 +216,26 @@ const predicate = {
|
|
|
199
216
|
geopointNear: pathWithArgsPredicate("geopoint.near"),
|
|
200
217
|
numberLessThan: pathWithArgsPredicate("number.lt"),
|
|
201
218
|
numberGreaterThan: pathWithArgsPredicate("number.gt"),
|
|
202
|
-
numberInRange: pathWithArgsPredicate(
|
|
219
|
+
numberInRange: pathWithArgsPredicate(
|
|
220
|
+
"number.inRange"
|
|
221
|
+
),
|
|
203
222
|
dateAfter: pathWithArgsPredicate("date.after"),
|
|
204
223
|
dateBefore: pathWithArgsPredicate("date.before"),
|
|
205
224
|
dateBetween: pathWithArgsPredicate("date.between"),
|
|
206
225
|
dateDayOfMonth: pathWithArgsPredicate("date.day-of-month"),
|
|
207
|
-
dateDayOfMonthAfter: pathWithArgsPredicate(
|
|
208
|
-
|
|
226
|
+
dateDayOfMonthAfter: pathWithArgsPredicate(
|
|
227
|
+
"date.day-of-month-after"
|
|
228
|
+
),
|
|
229
|
+
dateDayOfMonthBefore: pathWithArgsPredicate(
|
|
230
|
+
"date.day-of-month-before"
|
|
231
|
+
),
|
|
209
232
|
dateDayOfWeek: pathWithArgsPredicate("date.day-of-week"),
|
|
210
|
-
dateDayOfWeekAfter: pathWithArgsPredicate(
|
|
211
|
-
|
|
233
|
+
dateDayOfWeekAfter: pathWithArgsPredicate(
|
|
234
|
+
"date.day-of-week-after"
|
|
235
|
+
),
|
|
236
|
+
dateDayOfWeekBefore: pathWithArgsPredicate(
|
|
237
|
+
"date.day-of-week-before"
|
|
238
|
+
),
|
|
212
239
|
dateMonth: pathWithArgsPredicate("date.month"),
|
|
213
240
|
dateMonthAfter: pathWithArgsPredicate("date.month-after"),
|
|
214
241
|
dateMonthBefore: pathWithArgsPredicate("date.month-before"),
|
|
@@ -235,7 +262,11 @@ class Client {
|
|
|
235
262
|
this.graphqlFetch = this.graphQLFetch.bind(this);
|
|
236
263
|
if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
|
|
237
264
|
if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)) {
|
|
238
|
-
throw new PrismicError(
|
|
265
|
+
throw new PrismicError(
|
|
266
|
+
"@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.",
|
|
267
|
+
void 0,
|
|
268
|
+
void 0
|
|
269
|
+
);
|
|
239
270
|
}
|
|
240
271
|
this.endpoint = repositoryNameOrEndpoint;
|
|
241
272
|
} else {
|
|
@@ -243,6 +274,7 @@ class Client {
|
|
|
243
274
|
}
|
|
244
275
|
this.accessToken = options.accessToken;
|
|
245
276
|
this.routes = options.routes;
|
|
277
|
+
this.brokenRoute = options.brokenRoute;
|
|
246
278
|
this.defaultParams = options.defaultParams;
|
|
247
279
|
if (options.ref) {
|
|
248
280
|
this.queryContentFromRef(options.ref);
|
|
@@ -252,7 +284,11 @@ class Client {
|
|
|
252
284
|
} else if (typeof globalThis.fetch === "function") {
|
|
253
285
|
this.fetchFn = globalThis.fetch;
|
|
254
286
|
} else {
|
|
255
|
-
throw new PrismicError(
|
|
287
|
+
throw new PrismicError(
|
|
288
|
+
"A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.",
|
|
289
|
+
void 0,
|
|
290
|
+
void 0
|
|
291
|
+
);
|
|
256
292
|
}
|
|
257
293
|
if (this.fetchFn === globalThis.fetch) {
|
|
258
294
|
this.fetchFn = this.fetchFn.bind(globalThis);
|
|
@@ -278,11 +314,12 @@ class Client {
|
|
|
278
314
|
return await this.fetch(url, params);
|
|
279
315
|
}
|
|
280
316
|
async getFirst(params) {
|
|
281
|
-
var _a;
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
317
|
+
var _a, _b;
|
|
318
|
+
const actualParams = { ...params };
|
|
319
|
+
if (!(params && params.page) && !(params == null ? void 0 : params.pageSize)) {
|
|
320
|
+
actualParams.pageSize = (_b = (_a = this.defaultParams) == null ? void 0 : _a.pageSize) != null ? _b : 1;
|
|
321
|
+
}
|
|
322
|
+
const url = await this.buildQueryURL(actualParams);
|
|
286
323
|
const result = await this.fetch(url, params);
|
|
287
324
|
const firstResult = result.results[0];
|
|
288
325
|
if (firstResult) {
|
|
@@ -295,7 +332,10 @@ class Client {
|
|
|
295
332
|
const { limit = Infinity, ...actualParams } = params;
|
|
296
333
|
const resolvedParams = {
|
|
297
334
|
...actualParams,
|
|
298
|
-
pageSize: Math.min(
|
|
335
|
+
pageSize: Math.min(
|
|
336
|
+
limit,
|
|
337
|
+
actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE
|
|
338
|
+
)
|
|
299
339
|
};
|
|
300
340
|
const documents = [];
|
|
301
341
|
let latestResult;
|
|
@@ -310,58 +350,86 @@ class Client {
|
|
|
310
350
|
return documents.slice(0, limit);
|
|
311
351
|
}
|
|
312
352
|
async getByID(id, params) {
|
|
313
|
-
return await this.getFirst(
|
|
353
|
+
return await this.getFirst(
|
|
354
|
+
appendPredicates(params, predicate.at("document.id", id))
|
|
355
|
+
);
|
|
314
356
|
}
|
|
315
357
|
async getByIDs(ids, params) {
|
|
316
|
-
return await this.get(
|
|
358
|
+
return await this.get(
|
|
359
|
+
appendPredicates(params, predicate.in("document.id", ids))
|
|
360
|
+
);
|
|
317
361
|
}
|
|
318
362
|
async getAllByIDs(ids, params) {
|
|
319
|
-
return await this.dangerouslyGetAll(
|
|
363
|
+
return await this.dangerouslyGetAll(
|
|
364
|
+
appendPredicates(params, predicate.in("document.id", ids))
|
|
365
|
+
);
|
|
320
366
|
}
|
|
321
367
|
async getByUID(documentType, uid, params) {
|
|
322
|
-
return await this.getFirst(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
368
|
+
return await this.getFirst(
|
|
369
|
+
appendPredicates(params, [
|
|
370
|
+
typePredicate(documentType),
|
|
371
|
+
predicate.at(`my.${documentType}.uid`, uid)
|
|
372
|
+
])
|
|
373
|
+
);
|
|
326
374
|
}
|
|
327
375
|
async getByUIDs(documentType, uids, params) {
|
|
328
|
-
return await this.get(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
376
|
+
return await this.get(
|
|
377
|
+
appendPredicates(params, [
|
|
378
|
+
typePredicate(documentType),
|
|
379
|
+
predicate.in(`my.${documentType}.uid`, uids)
|
|
380
|
+
])
|
|
381
|
+
);
|
|
332
382
|
}
|
|
333
383
|
async getAllByUIDs(documentType, uids, params) {
|
|
334
|
-
return await this.dangerouslyGetAll(
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
384
|
+
return await this.dangerouslyGetAll(
|
|
385
|
+
appendPredicates(params, [
|
|
386
|
+
typePredicate(documentType),
|
|
387
|
+
predicate.in(`my.${documentType}.uid`, uids)
|
|
388
|
+
])
|
|
389
|
+
);
|
|
338
390
|
}
|
|
339
391
|
async getSingle(documentType, params) {
|
|
340
|
-
return await this.getFirst(
|
|
392
|
+
return await this.getFirst(
|
|
393
|
+
appendPredicates(params, typePredicate(documentType))
|
|
394
|
+
);
|
|
341
395
|
}
|
|
342
396
|
async getByType(documentType, params) {
|
|
343
|
-
return await this.get(
|
|
397
|
+
return await this.get(
|
|
398
|
+
appendPredicates(params, typePredicate(documentType))
|
|
399
|
+
);
|
|
344
400
|
}
|
|
345
401
|
async getAllByType(documentType, params) {
|
|
346
402
|
return await this.dangerouslyGetAll(appendPredicates(params, typePredicate(documentType)));
|
|
347
403
|
}
|
|
348
404
|
async getByTag(tag, params) {
|
|
349
|
-
return await this.get(
|
|
405
|
+
return await this.get(
|
|
406
|
+
appendPredicates(params, someTagsPredicate(tag))
|
|
407
|
+
);
|
|
350
408
|
}
|
|
351
409
|
async getAllByTag(tag, params) {
|
|
352
|
-
return await this.dangerouslyGetAll(
|
|
410
|
+
return await this.dangerouslyGetAll(
|
|
411
|
+
appendPredicates(params, someTagsPredicate(tag))
|
|
412
|
+
);
|
|
353
413
|
}
|
|
354
414
|
async getByEveryTag(tags, params) {
|
|
355
|
-
return await this.get(
|
|
415
|
+
return await this.get(
|
|
416
|
+
appendPredicates(params, everyTagPredicate(tags))
|
|
417
|
+
);
|
|
356
418
|
}
|
|
357
419
|
async getAllByEveryTag(tags, params) {
|
|
358
|
-
return await this.dangerouslyGetAll(
|
|
420
|
+
return await this.dangerouslyGetAll(
|
|
421
|
+
appendPredicates(params, everyTagPredicate(tags))
|
|
422
|
+
);
|
|
359
423
|
}
|
|
360
424
|
async getBySomeTags(tags, params) {
|
|
361
|
-
return await this.get(
|
|
425
|
+
return await this.get(
|
|
426
|
+
appendPredicates(params, someTagsPredicate(tags))
|
|
427
|
+
);
|
|
362
428
|
}
|
|
363
429
|
async getAllBySomeTags(tags, params) {
|
|
364
|
-
return await this.dangerouslyGetAll(
|
|
430
|
+
return await this.dangerouslyGetAll(
|
|
431
|
+
appendPredicates(params, someTagsPredicate(tags))
|
|
432
|
+
);
|
|
365
433
|
}
|
|
366
434
|
async getRepository(params) {
|
|
367
435
|
const url = new URL(this.endpoint);
|
|
@@ -423,6 +491,7 @@ class Client {
|
|
|
423
491
|
ref,
|
|
424
492
|
integrationFieldsRef,
|
|
425
493
|
routes: params.routes || this.routes,
|
|
494
|
+
brokenRoute: params.brokenRoute || this.brokenRoute,
|
|
426
495
|
accessToken: params.accessToken || this.accessToken
|
|
427
496
|
});
|
|
428
497
|
}
|
|
@@ -486,21 +555,28 @@ class Client {
|
|
|
486
555
|
const ref = await this.getResolvedRefString();
|
|
487
556
|
const unsanitizedHeaders = {
|
|
488
557
|
"Prismic-ref": ref,
|
|
489
|
-
"Prismic-integration-field-ref": cachedRepository.integrationFieldsRef || "",
|
|
490
558
|
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
491
559
|
...init ? init.headers : {}
|
|
492
560
|
};
|
|
561
|
+
if (cachedRepository.integrationFieldsRef) {
|
|
562
|
+
unsanitizedHeaders["Prismic-integration-field-ref"] = cachedRepository.integrationFieldsRef;
|
|
563
|
+
}
|
|
493
564
|
const headers = {};
|
|
494
565
|
for (const key in unsanitizedHeaders) {
|
|
495
566
|
if (unsanitizedHeaders[key]) {
|
|
496
567
|
headers[key.toLowerCase()] = unsanitizedHeaders[key];
|
|
497
568
|
}
|
|
498
569
|
}
|
|
499
|
-
const url = new URL(
|
|
570
|
+
const url = new URL(
|
|
571
|
+
input
|
|
572
|
+
);
|
|
500
573
|
url.searchParams.set("ref", ref);
|
|
501
574
|
const query = url.searchParams.get("query");
|
|
502
575
|
if (query) {
|
|
503
|
-
url.searchParams.set(
|
|
576
|
+
url.searchParams.set(
|
|
577
|
+
"query",
|
|
578
|
+
minifyGraphQLQuery(query)
|
|
579
|
+
);
|
|
504
580
|
}
|
|
505
581
|
return await this.fetchFn(url.toString(), {
|
|
506
582
|
...init,
|
|
@@ -518,7 +594,11 @@ class Client {
|
|
|
518
594
|
const cachedRepository = await this.getCachedRepository(params);
|
|
519
595
|
const form = cachedRepository.forms[name];
|
|
520
596
|
if (!form) {
|
|
521
|
-
throw new PrismicError(
|
|
597
|
+
throw new PrismicError(
|
|
598
|
+
`Form with name "${name}" could not be found`,
|
|
599
|
+
void 0,
|
|
600
|
+
void 0
|
|
601
|
+
);
|
|
522
602
|
}
|
|
523
603
|
return form;
|
|
524
604
|
}
|
|
@@ -527,17 +607,17 @@ class Client {
|
|
|
527
607
|
if (this.refState.autoPreviewsEnabled) {
|
|
528
608
|
let previewRef;
|
|
529
609
|
let cookieJar;
|
|
530
|
-
if ((_a =
|
|
531
|
-
cookieJar = globalThis.document.cookie;
|
|
532
|
-
} else if ((_b = this.refState.httpRequest) == null ? void 0 : _b.headers) {
|
|
610
|
+
if ((_a = this.refState.httpRequest) == null ? void 0 : _a.headers) {
|
|
533
611
|
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
534
612
|
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
535
613
|
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
536
614
|
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
537
615
|
}
|
|
616
|
+
} else if ((_b = globalThis.document) == null ? void 0 : _b.cookie) {
|
|
617
|
+
cookieJar = globalThis.document.cookie;
|
|
538
618
|
}
|
|
539
619
|
if (cookieJar) {
|
|
540
|
-
previewRef =
|
|
620
|
+
previewRef = getPreviewCookie(cookieJar);
|
|
541
621
|
}
|
|
542
622
|
if (previewRef) {
|
|
543
623
|
return previewRef;
|
|
@@ -566,7 +646,11 @@ class Client {
|
|
|
566
646
|
json = await res.json();
|
|
567
647
|
} catch (e) {
|
|
568
648
|
if (res.status === 404) {
|
|
569
|
-
throw new NotFoundError(
|
|
649
|
+
throw new NotFoundError(
|
|
650
|
+
`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`,
|
|
651
|
+
url,
|
|
652
|
+
void 0
|
|
653
|
+
);
|
|
570
654
|
} else {
|
|
571
655
|
throw new PrismicError(void 0, url, void 0);
|
|
572
656
|
}
|
|
@@ -580,7 +664,11 @@ class Client {
|
|
|
580
664
|
}
|
|
581
665
|
case 401:
|
|
582
666
|
case 403: {
|
|
583
|
-
throw new ForbiddenError(
|
|
667
|
+
throw new ForbiddenError(
|
|
668
|
+
"error" in json ? json.error : json.message,
|
|
669
|
+
url,
|
|
670
|
+
json
|
|
671
|
+
);
|
|
584
672
|
}
|
|
585
673
|
}
|
|
586
674
|
throw new PrismicError(void 0, url, json);
|