@prismicio/client 7.21.0-pr.418.8bcf835 → 7.21.0-pr.419.1e13842
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/Client.cjs +315 -462
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.cts +208 -361
- package/dist/Client.d.cts.map +1 -1
- package/dist/Client.d.ts +208 -361
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +315 -462
- package/dist/Client.js.map +1 -1
- package/dist/WriteClient.cjs +8 -5
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.js +8 -5
- package/dist/WriteClient.js.map +1 -1
- package/dist/lib/castThunk.cjs +19 -0
- package/dist/lib/castThunk.cjs.map +1 -0
- package/dist/lib/castThunk.js +18 -0
- package/dist/lib/castThunk.js.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +1 -1
- package/src/Client.ts +438 -525
- package/src/WriteClient.ts +10 -6
package/dist/Client.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_filter = require('./filter.cjs');
|
|
2
2
|
const require_appendFilters = require('./lib/appendFilters.cjs');
|
|
3
|
+
const require_castThunk = require('./lib/castThunk.cjs');
|
|
3
4
|
const require_devMsg = require('./lib/devMsg.cjs');
|
|
4
5
|
const require_everyTagFilter = require('./lib/everyTagFilter.cjs');
|
|
5
6
|
const require_PrismicError = require('./errors/PrismicError.cjs');
|
|
@@ -53,6 +54,28 @@ const GET_ALL_QUERY_DELAY = 500;
|
|
|
53
54
|
*/
|
|
54
55
|
const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
|
|
55
56
|
/**
|
|
57
|
+
* Modes for client ref management.
|
|
58
|
+
*/
|
|
59
|
+
var RefStateMode = /* @__PURE__ */ function(RefStateMode$1) {
|
|
60
|
+
/**
|
|
61
|
+
* Use the repository's master ref.
|
|
62
|
+
*/
|
|
63
|
+
RefStateMode$1["Master"] = "Master";
|
|
64
|
+
/**
|
|
65
|
+
* Use a given Release identified by its ID.
|
|
66
|
+
*/
|
|
67
|
+
RefStateMode$1["ReleaseID"] = "ReleaseID";
|
|
68
|
+
/**
|
|
69
|
+
* Use a given Release identified by its label.
|
|
70
|
+
*/
|
|
71
|
+
RefStateMode$1["ReleaseLabel"] = "ReleaseLabel";
|
|
72
|
+
/**
|
|
73
|
+
* Use a given ref.
|
|
74
|
+
*/
|
|
75
|
+
RefStateMode$1["Manual"] = "Manual";
|
|
76
|
+
return RefStateMode$1;
|
|
77
|
+
}(RefStateMode || {});
|
|
78
|
+
/**
|
|
56
79
|
* A client that allows querying content from a Prismic repository.
|
|
57
80
|
*
|
|
58
81
|
* If used in an environment where a global `fetch` function is unavailable,
|
|
@@ -135,9 +158,14 @@ var Client = class {
|
|
|
135
158
|
* be overridden on each query if needed.
|
|
136
159
|
*/
|
|
137
160
|
defaultParams;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
161
|
+
/**
|
|
162
|
+
* The client's ref mode state. This determines which ref is used during
|
|
163
|
+
* queries.
|
|
164
|
+
*/
|
|
165
|
+
refState = {
|
|
166
|
+
mode: RefStateMode.Master,
|
|
167
|
+
autoPreviewsEnabled: true
|
|
168
|
+
};
|
|
141
169
|
#cachedRepository;
|
|
142
170
|
#cachedRepositoryExpiration = 0;
|
|
143
171
|
/**
|
|
@@ -186,11 +214,7 @@ var Client = class {
|
|
|
186
214
|
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
187
215
|
}
|
|
188
216
|
/**
|
|
189
|
-
* Enables the client to automatically query content from a preview session
|
|
190
|
-
* one is active in browser environments. This is enabled by default in the
|
|
191
|
-
* browser.
|
|
192
|
-
*
|
|
193
|
-
* For server environments, use `enableAutoPreviewsFromReq`.
|
|
217
|
+
* Enables the client to automatically query content from a preview session.
|
|
194
218
|
*
|
|
195
219
|
* @example
|
|
196
220
|
*
|
|
@@ -198,126 +222,95 @@ var Client = class {
|
|
|
198
222
|
* client.enableAutoPreviews()
|
|
199
223
|
* ```
|
|
200
224
|
*
|
|
201
|
-
* @see
|
|
225
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
|
|
202
226
|
*/
|
|
203
227
|
enableAutoPreviews() {
|
|
204
|
-
this
|
|
228
|
+
this.refState.autoPreviewsEnabled = true;
|
|
205
229
|
}
|
|
206
230
|
/**
|
|
207
|
-
* Enables the client to automatically query content from a preview session
|
|
208
|
-
*
|
|
209
|
-
* server.
|
|
210
|
-
*
|
|
211
|
-
* For browser environments, use `enableAutoPreviews`.
|
|
231
|
+
* Enables the client to automatically query content from a preview session
|
|
232
|
+
* using an HTTP request object.
|
|
212
233
|
*
|
|
213
234
|
* @example
|
|
214
235
|
*
|
|
215
236
|
* ```ts
|
|
216
|
-
*
|
|
217
|
-
* app.get("/", function (req, res) {
|
|
218
|
-
* client.enableAutoPreviewsFromReq(req)
|
|
219
|
-
* })
|
|
237
|
+
* client.enableAutoPreviewsFromReq(req)
|
|
220
238
|
* ```
|
|
221
239
|
*
|
|
222
|
-
* @
|
|
223
|
-
* cookies.
|
|
240
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
|
|
224
241
|
*/
|
|
225
|
-
enableAutoPreviewsFromReq(
|
|
226
|
-
this.
|
|
227
|
-
this
|
|
242
|
+
enableAutoPreviewsFromReq(req) {
|
|
243
|
+
this.refState.httpRequest = req;
|
|
244
|
+
this.refState.autoPreviewsEnabled = true;
|
|
228
245
|
}
|
|
229
246
|
/**
|
|
230
247
|
* Disables the client from automatically querying content from a preview
|
|
231
|
-
* session
|
|
232
|
-
*
|
|
233
|
-
* Automatic preview content querying is enabled by default unless this method
|
|
234
|
-
* is called.
|
|
248
|
+
* session.
|
|
235
249
|
*
|
|
236
250
|
* @example
|
|
237
251
|
*
|
|
238
252
|
* ```ts
|
|
239
253
|
* client.disableAutoPreviews()
|
|
240
254
|
* ```
|
|
255
|
+
*
|
|
256
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
|
|
241
257
|
*/
|
|
242
258
|
disableAutoPreviews() {
|
|
243
|
-
this
|
|
244
|
-
this.#autoPreviewsRequest = void 0;
|
|
259
|
+
this.refState.autoPreviewsEnabled = false;
|
|
245
260
|
}
|
|
246
261
|
/**
|
|
247
|
-
*
|
|
262
|
+
* Fetches pages based on the `params` argument. Results are paginated.
|
|
248
263
|
*
|
|
249
264
|
* @example
|
|
250
265
|
*
|
|
251
266
|
* ```ts
|
|
252
|
-
* const response = await client.get()
|
|
267
|
+
* const response = await client.get({ pageSize: 10 })
|
|
253
268
|
* ```
|
|
254
269
|
*
|
|
255
|
-
* @
|
|
256
|
-
*
|
|
257
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
258
|
-
*
|
|
259
|
-
* @returns A paginated response containing the result of the query.
|
|
270
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
|
|
260
271
|
*/
|
|
261
272
|
async get(params) {
|
|
262
|
-
|
|
263
|
-
return data;
|
|
273
|
+
return await (await this.#internalGet(params)).json();
|
|
264
274
|
}
|
|
265
275
|
/**
|
|
266
|
-
*
|
|
267
|
-
* result, if any.
|
|
276
|
+
* Fetches the first page returned based on the `params` argument.
|
|
268
277
|
*
|
|
269
278
|
* @example
|
|
270
279
|
*
|
|
271
280
|
* ```ts
|
|
272
|
-
* const
|
|
281
|
+
* const page = await client.getFirst()
|
|
273
282
|
* ```
|
|
274
283
|
*
|
|
275
|
-
* @
|
|
276
|
-
*
|
|
277
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
278
|
-
*
|
|
279
|
-
* @returns The first result of the query, if any.
|
|
284
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
|
|
280
285
|
*/
|
|
281
286
|
async getFirst(params) {
|
|
282
|
-
const actualParams =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
|
|
287
|
+
const actualParams = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params.pageSize) ? params : {
|
|
288
|
+
...params,
|
|
289
|
+
pageSize: 1
|
|
290
|
+
};
|
|
291
|
+
const response = await this.#internalGet(actualParams);
|
|
292
|
+
const { results } = await response.clone().json();
|
|
293
|
+
if (results[0]) return results[0];
|
|
294
|
+
throw new require_NotFoundError.NotFoundError("No documents were returned", response.url, void 0);
|
|
291
295
|
}
|
|
292
296
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* filter by filters such as `getAllByType`.
|
|
296
|
-
*
|
|
297
|
-
* Queries content from the Prismic repository and returns all matching
|
|
298
|
-
* content. If no filters are provided, all documents will be fetched.
|
|
299
|
-
*
|
|
300
|
-
* This method may make multiple network requests to query all matching
|
|
301
|
-
* content.
|
|
297
|
+
* Fetches all pages based on the `params` argument. This method may make
|
|
298
|
+
* multiple network requests to fetch all matching pages.
|
|
302
299
|
*
|
|
303
300
|
* @example
|
|
304
301
|
*
|
|
305
302
|
* ```ts
|
|
306
|
-
* const
|
|
303
|
+
* const pages = await client.dangerouslyGetAll()
|
|
307
304
|
* ```
|
|
308
305
|
*
|
|
309
|
-
* @
|
|
310
|
-
*
|
|
311
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
312
|
-
*
|
|
313
|
-
* @returns A list of documents matching the query.
|
|
306
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
|
|
314
307
|
*/
|
|
315
308
|
async dangerouslyGetAll(params = {}) {
|
|
316
|
-
var _this$
|
|
309
|
+
var _this$defaultParams;
|
|
317
310
|
const { limit = Infinity,...actualParams } = params;
|
|
318
311
|
const resolvedParams = {
|
|
319
312
|
...actualParams,
|
|
320
|
-
pageSize: Math.min(limit, actualParams.pageSize || ((_this$
|
|
313
|
+
pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) || MAX_PAGE_SIZE)
|
|
321
314
|
};
|
|
322
315
|
const documents = [];
|
|
323
316
|
let latestResult;
|
|
@@ -333,39 +326,21 @@ var Client = class {
|
|
|
333
326
|
return documents.slice(0, limit);
|
|
334
327
|
}
|
|
335
328
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @remarks
|
|
339
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
340
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
341
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
342
|
-
* custom type.
|
|
329
|
+
* Fetches a page with a specific ID.
|
|
343
330
|
*
|
|
344
331
|
* @example
|
|
345
332
|
*
|
|
346
333
|
* ```ts
|
|
347
|
-
* const
|
|
334
|
+
* const page = await client.getByID("WW4bKScAAMAqmluX")
|
|
348
335
|
* ```
|
|
349
336
|
*
|
|
350
|
-
* @
|
|
351
|
-
*
|
|
352
|
-
* @param id - ID of the document.
|
|
353
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
354
|
-
*
|
|
355
|
-
* @returns The document with an ID matching the `id` parameter, if a matching
|
|
356
|
-
* document exists.
|
|
337
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
|
|
357
338
|
*/
|
|
358
339
|
async getByID(id, params) {
|
|
359
340
|
return await this.getFirst(require_appendFilters.appendFilters(params, require_filter.filter.at("document.id", id)));
|
|
360
341
|
}
|
|
361
342
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* @remarks
|
|
365
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
366
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
367
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
368
|
-
* custom type.
|
|
343
|
+
* Fetches pages with specific IDs. Results are paginated.
|
|
369
344
|
*
|
|
370
345
|
* @example
|
|
371
346
|
*
|
|
@@ -376,172 +351,95 @@ var Client = class {
|
|
|
376
351
|
* ])
|
|
377
352
|
* ```
|
|
378
353
|
*
|
|
379
|
-
* @
|
|
380
|
-
*
|
|
381
|
-
* @param ids - A list of document IDs.
|
|
382
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
383
|
-
*
|
|
384
|
-
* @returns A paginated response containing documents with IDs matching the
|
|
385
|
-
* `ids` parameter.
|
|
354
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
|
|
386
355
|
*/
|
|
387
356
|
async getByIDs(ids, params) {
|
|
388
357
|
return await this.get(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
389
358
|
}
|
|
390
359
|
/**
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
* This method may make multiple network requests to query all matching
|
|
394
|
-
* content.
|
|
395
|
-
*
|
|
396
|
-
* @remarks
|
|
397
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
398
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
399
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
400
|
-
* custom type.
|
|
360
|
+
* Fetches pages with specific IDs. This method may make multiple network
|
|
361
|
+
* requests to fetch all matching pages.
|
|
401
362
|
*
|
|
402
363
|
* @example
|
|
403
364
|
*
|
|
404
365
|
* ```ts
|
|
405
|
-
* const
|
|
366
|
+
* const pages = await client.getAllByIDs([
|
|
406
367
|
* "WW4bKScAAMAqmluX",
|
|
407
368
|
* "U1kTRgEAAC8A5ldS",
|
|
408
369
|
* ])
|
|
409
370
|
* ```
|
|
410
371
|
*
|
|
411
|
-
* @
|
|
412
|
-
*
|
|
413
|
-
* @param ids - A list of document IDs.
|
|
414
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
415
|
-
*
|
|
416
|
-
* @returns A list of documents with IDs matching the `ids` parameter.
|
|
372
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
|
|
417
373
|
*/
|
|
418
374
|
async getAllByIDs(ids, params) {
|
|
419
375
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
420
376
|
}
|
|
421
377
|
/**
|
|
422
|
-
*
|
|
423
|
-
* custom type.
|
|
424
|
-
*
|
|
425
|
-
* @remarks
|
|
426
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
427
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
428
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
429
|
-
* custom type.
|
|
378
|
+
* Fetches a page with a specific UID and type.
|
|
430
379
|
*
|
|
431
380
|
* @example
|
|
432
381
|
*
|
|
433
382
|
* ```ts
|
|
434
|
-
* const
|
|
383
|
+
* const page = await client.getByUID("blog_post", "my-first-post")
|
|
435
384
|
* ```
|
|
436
385
|
*
|
|
437
|
-
* @
|
|
438
|
-
*
|
|
439
|
-
* @param documentType - The API ID of the document's custom type.
|
|
440
|
-
* @param uid - UID of the document.
|
|
441
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
442
|
-
*
|
|
443
|
-
* @returns The document with a UID matching the `uid` parameter, if a
|
|
444
|
-
* matching document exists.
|
|
386
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
|
|
445
387
|
*/
|
|
446
388
|
async getByUID(documentType, uid, params) {
|
|
447
389
|
return await this.getFirst(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)]));
|
|
448
390
|
}
|
|
449
391
|
/**
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* @remarks
|
|
454
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
455
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
456
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
457
|
-
* custom type.
|
|
392
|
+
* Fetches pages with specific UIDs and a specific type. Results are
|
|
393
|
+
* paginated.
|
|
458
394
|
*
|
|
459
395
|
* @example
|
|
460
396
|
*
|
|
461
397
|
* ```ts
|
|
462
|
-
* const
|
|
398
|
+
* const response = await client.getByUIDs("blog_post", [
|
|
463
399
|
* "my-first-post",
|
|
464
400
|
* "my-second-post",
|
|
465
401
|
* ])
|
|
466
402
|
* ```
|
|
467
403
|
*
|
|
468
|
-
* @
|
|
469
|
-
*
|
|
470
|
-
* @param documentType - The API ID of the document's custom type.
|
|
471
|
-
* @param uids - A list of document UIDs.
|
|
472
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
473
|
-
*
|
|
474
|
-
* @returns A paginated response containing documents with UIDs matching the
|
|
475
|
-
* `uids` parameter.
|
|
404
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
|
|
476
405
|
*/
|
|
477
406
|
async getByUIDs(documentType, uids, params) {
|
|
478
407
|
return await this.get(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
|
|
479
408
|
}
|
|
480
409
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* This method may make multiple network requests to query all matching
|
|
485
|
-
* content.
|
|
486
|
-
*
|
|
487
|
-
* @remarks
|
|
488
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
489
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
490
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
491
|
-
* custom type.
|
|
410
|
+
* Fetches pages with specific UIDs and a specific type. This method may make
|
|
411
|
+
* multiple network requests to fetch all matching pages.
|
|
492
412
|
*
|
|
493
413
|
* @example
|
|
494
414
|
*
|
|
495
415
|
* ```ts
|
|
496
|
-
* const
|
|
416
|
+
* const pages = await client.getAllByUIDs("blog_post", [
|
|
497
417
|
* "my-first-post",
|
|
498
418
|
* "my-second-post",
|
|
499
419
|
* ])
|
|
500
420
|
* ```
|
|
501
421
|
*
|
|
502
|
-
* @
|
|
503
|
-
*
|
|
504
|
-
* @param documentType - The API ID of the document's custom type.
|
|
505
|
-
* @param uids - A list of document UIDs.
|
|
506
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
507
|
-
*
|
|
508
|
-
* @returns A list of documents with UIDs matching the `uids` parameter.
|
|
422
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
|
|
509
423
|
*/
|
|
510
424
|
async getAllByUIDs(documentType, uids, params) {
|
|
511
425
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
|
|
512
426
|
}
|
|
513
427
|
/**
|
|
514
|
-
*
|
|
515
|
-
* custom type.
|
|
516
|
-
*
|
|
517
|
-
* @remarks
|
|
518
|
-
* A singleton document is one that is configured in Prismic to only allow one
|
|
519
|
-
* instance. For example, a repository may be configured to contain just one
|
|
520
|
-
* Settings document. This is in contrast to a repeatable custom type which
|
|
521
|
-
* allows multiple instances of itself.
|
|
428
|
+
* Fetches a specific single type page.
|
|
522
429
|
*
|
|
523
430
|
* @example
|
|
524
431
|
*
|
|
525
432
|
* ```ts
|
|
526
|
-
* const
|
|
433
|
+
* const page = await client.getSingle("settings")
|
|
527
434
|
* ```
|
|
528
435
|
*
|
|
529
|
-
* @
|
|
530
|
-
*
|
|
531
|
-
* @param documentType - The API ID of the singleton custom type.
|
|
532
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
533
|
-
*
|
|
534
|
-
* @returns The singleton document for the custom type, if a matching document
|
|
535
|
-
* exists.
|
|
436
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
|
|
536
437
|
*/
|
|
537
438
|
async getSingle(documentType, params) {
|
|
538
439
|
return await this.getFirst(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
539
440
|
}
|
|
540
441
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
* Use `getAllByType` instead if you need to query all documents for a
|
|
544
|
-
* specific custom type.
|
|
442
|
+
* Fetches pages with a specific type. Results are paginated.
|
|
545
443
|
*
|
|
546
444
|
* @example
|
|
547
445
|
*
|
|
@@ -549,177 +447,124 @@ var Client = class {
|
|
|
549
447
|
* const response = await client.getByType("blog_post")
|
|
550
448
|
* ```
|
|
551
449
|
*
|
|
552
|
-
* @
|
|
553
|
-
*
|
|
554
|
-
* @param documentType - The API ID of the custom type.
|
|
555
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
556
|
-
*
|
|
557
|
-
* @returns A paginated response containing documents of the custom type.
|
|
450
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
|
|
558
451
|
*/
|
|
559
452
|
async getByType(documentType, params) {
|
|
560
453
|
return await this.get(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
561
454
|
}
|
|
562
455
|
/**
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
* This method may make multiple network requests to query all matching
|
|
567
|
-
* content.
|
|
456
|
+
* Fetches pages with a specific type. This method may make multiple network
|
|
457
|
+
* requests to fetch all matching documents.
|
|
568
458
|
*
|
|
569
459
|
* @example
|
|
570
460
|
*
|
|
571
461
|
* ```ts
|
|
572
|
-
* const
|
|
462
|
+
* const pages = await client.getAllByType("blog_post")
|
|
573
463
|
* ```
|
|
574
464
|
*
|
|
575
|
-
* @
|
|
576
|
-
*
|
|
577
|
-
* @param documentType - The API ID of the custom type.
|
|
578
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
579
|
-
*
|
|
580
|
-
* @returns A list of all documents of the custom type.
|
|
465
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
|
|
581
466
|
*/
|
|
582
467
|
async getAllByType(documentType, params) {
|
|
583
468
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
584
469
|
}
|
|
585
470
|
/**
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
* Use `getAllByTag` instead if you need to query all documents with a
|
|
589
|
-
* specific tag.
|
|
471
|
+
* Fetches pages with a specific tag. Results are paginated.
|
|
590
472
|
*
|
|
591
473
|
* @example
|
|
592
474
|
*
|
|
593
475
|
* ```ts
|
|
594
|
-
* const response = await client.getByTag("
|
|
476
|
+
* const response = await client.getByTag("featured")
|
|
595
477
|
* ```
|
|
596
478
|
*
|
|
597
|
-
* @
|
|
598
|
-
*
|
|
599
|
-
* @param tag - The tag that must be included on a document.
|
|
600
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
601
|
-
*
|
|
602
|
-
* @returns A paginated response containing documents with the tag.
|
|
479
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
|
|
603
480
|
*/
|
|
604
481
|
async getByTag(tag, params) {
|
|
605
482
|
return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
|
|
606
483
|
}
|
|
607
484
|
/**
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
* This method may make multiple network requests to query all matching
|
|
611
|
-
* content.
|
|
485
|
+
* Fetches pages with a specific tag. This method may make multiple network
|
|
486
|
+
* requests to fetch all matching documents.
|
|
612
487
|
*
|
|
613
488
|
* @example
|
|
614
489
|
*
|
|
615
490
|
* ```ts
|
|
616
|
-
* const
|
|
491
|
+
* const pages = await client.getAllByTag("featured")
|
|
617
492
|
* ```
|
|
618
493
|
*
|
|
619
|
-
* @
|
|
620
|
-
*
|
|
621
|
-
* @param tag - The tag that must be included on a document.
|
|
622
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
623
|
-
*
|
|
624
|
-
* @returns A list of all documents with the tag.
|
|
494
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
|
|
625
495
|
*/
|
|
626
496
|
async getAllByTag(tag, params) {
|
|
627
497
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
|
|
628
498
|
}
|
|
629
499
|
/**
|
|
630
|
-
*
|
|
631
|
-
* document must be tagged with all of the queried tags to be included.
|
|
500
|
+
* Fetches pages with every tag from a list of tags. Results are paginated.
|
|
632
501
|
*
|
|
633
502
|
* @example
|
|
634
503
|
*
|
|
635
504
|
* ```ts
|
|
636
|
-
* const response = await client.getByEveryTag(["
|
|
505
|
+
* const response = await client.getByEveryTag(["featured", "homepage"])
|
|
637
506
|
* ```
|
|
638
507
|
*
|
|
639
|
-
* @
|
|
640
|
-
*
|
|
641
|
-
* @param tags - A list of tags that must be included on a document.
|
|
642
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
643
|
-
*
|
|
644
|
-
* @returns A paginated response containing documents with the tags.
|
|
508
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
|
|
645
509
|
*/
|
|
646
510
|
async getByEveryTag(tags, params) {
|
|
647
511
|
return await this.get(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
|
|
648
512
|
}
|
|
649
513
|
/**
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
* This method may make multiple network requests to query all matching
|
|
654
|
-
* content.
|
|
514
|
+
* Fetches pages with every tag from a list of tags. This method may make
|
|
515
|
+
* multiple network requests to fetch all matching pages.
|
|
655
516
|
*
|
|
656
517
|
* @example
|
|
657
518
|
*
|
|
658
519
|
* ```ts
|
|
659
|
-
* const
|
|
520
|
+
* const pages = await client.getAllByEveryTag(["featured", "homepage"])
|
|
660
521
|
* ```
|
|
661
522
|
*
|
|
662
|
-
* @
|
|
663
|
-
*
|
|
664
|
-
* @param tags - A list of tags that must be included on a document.
|
|
665
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
666
|
-
*
|
|
667
|
-
* @returns A list of all documents with the tags.
|
|
523
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
|
|
668
524
|
*/
|
|
669
525
|
async getAllByEveryTag(tags, params) {
|
|
670
526
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
|
|
671
527
|
}
|
|
672
528
|
/**
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
* included.
|
|
529
|
+
* Fetches pages with at least one tag from a list of tags. Results are
|
|
530
|
+
* paginated.
|
|
676
531
|
*
|
|
677
532
|
* @example
|
|
678
533
|
*
|
|
679
534
|
* ```ts
|
|
680
|
-
* const response = await client.
|
|
535
|
+
* const response = await client.getBySomeTags(["featured", "homepage"])
|
|
681
536
|
* ```
|
|
682
537
|
*
|
|
683
|
-
* @
|
|
684
|
-
*
|
|
685
|
-
* @param tags - A list of tags that must be included on a document.
|
|
686
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
687
|
-
*
|
|
688
|
-
* @returns A paginated response containing documents with at least one of the
|
|
689
|
-
* tags.
|
|
538
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
|
|
690
539
|
*/
|
|
691
540
|
async getBySomeTags(tags, params) {
|
|
692
541
|
return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
|
|
693
542
|
}
|
|
694
543
|
/**
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
* included.
|
|
698
|
-
*
|
|
699
|
-
* This method may make multiple network requests to query all matching
|
|
700
|
-
* content.
|
|
544
|
+
* Fetches pages with at least one tag from a list of tags. This method may
|
|
545
|
+
* make multiple network requests to fetch all matching documents.
|
|
701
546
|
*
|
|
702
547
|
* @example
|
|
703
548
|
*
|
|
704
549
|
* ```ts
|
|
705
|
-
* const
|
|
550
|
+
* const pages = await client.getAllBySomeTags(["featured", "homepage"])
|
|
706
551
|
* ```
|
|
707
552
|
*
|
|
708
|
-
* @
|
|
709
|
-
*
|
|
710
|
-
* @param tags - A list of tags that must be included on a document.
|
|
711
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
712
|
-
*
|
|
713
|
-
* @returns A list of all documents with at least one of the tags.
|
|
553
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
|
|
714
554
|
*/
|
|
715
555
|
async getAllBySomeTags(tags, params) {
|
|
716
556
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
|
|
717
557
|
}
|
|
718
558
|
/**
|
|
719
|
-
*
|
|
720
|
-
*
|
|
559
|
+
* Fetches metadata about the client's Prismic repository.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
*
|
|
563
|
+
* ```ts
|
|
564
|
+
* const repository = await client.getRepository()
|
|
565
|
+
* ```
|
|
721
566
|
*
|
|
722
|
-
* @
|
|
567
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrepository}
|
|
723
568
|
*/
|
|
724
569
|
async getRepository(params) {
|
|
725
570
|
if (this.#cachedRepository && this.#cachedRepositoryExpiration > Date.now()) return this.#cachedRepository;
|
|
@@ -727,93 +572,124 @@ var Client = class {
|
|
|
727
572
|
const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
|
|
728
573
|
if (accessToken) url.searchParams.set("access_token", accessToken);
|
|
729
574
|
const response = await this.#request(url, params);
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
return this.#cachedRepository;
|
|
735
|
-
case 401: {
|
|
736
|
-
const json = await response.json();
|
|
737
|
-
throw new require_ForbiddenError.ForbiddenError(json.error, url.toString(), json);
|
|
738
|
-
}
|
|
739
|
-
case 404: throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
|
|
740
|
-
default: throw new require_PrismicError.PrismicError(void 0, url.toString(), await response.text());
|
|
575
|
+
if (response.ok) {
|
|
576
|
+
this.#cachedRepository = await response.json();
|
|
577
|
+
this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
578
|
+
return this.#cachedRepository;
|
|
741
579
|
}
|
|
580
|
+
if (response.status === 404) throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
|
|
581
|
+
return await this.#throwContentAPIError(response, url.toString());
|
|
742
582
|
}
|
|
743
583
|
/**
|
|
744
|
-
*
|
|
584
|
+
* Fetches the repository's active refs.
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
745
587
|
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
588
|
+
* ```ts
|
|
589
|
+
* const refs = await client.getRefs()
|
|
590
|
+
* ```
|
|
749
591
|
*
|
|
750
|
-
* @
|
|
592
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefs}
|
|
751
593
|
*/
|
|
752
594
|
async getRefs(params) {
|
|
753
595
|
return (await this.getRepository(params)).refs;
|
|
754
596
|
}
|
|
755
597
|
/**
|
|
756
|
-
*
|
|
598
|
+
* Fetches a ref by its ID.
|
|
757
599
|
*
|
|
758
|
-
* @
|
|
600
|
+
* @example
|
|
601
|
+
*
|
|
602
|
+
* ```ts
|
|
603
|
+
* const ref = await client.getRefByID("YhE3YhEAACIA4321")
|
|
604
|
+
* ```
|
|
759
605
|
*
|
|
760
|
-
* @
|
|
606
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
|
|
761
607
|
*/
|
|
762
608
|
async getRefByID(id, params) {
|
|
763
609
|
return require_findRefByID.findRefByID(await this.getRefs(params), id);
|
|
764
610
|
}
|
|
765
611
|
/**
|
|
766
|
-
*
|
|
612
|
+
* Fetches a ref by its label. A release ref's label is its name shown in the
|
|
613
|
+
* Page Builder.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
767
616
|
*
|
|
768
|
-
*
|
|
617
|
+
* ```ts
|
|
618
|
+
* const ref = await client.getRefByLabel("My Release")
|
|
619
|
+
* ```
|
|
769
620
|
*
|
|
770
|
-
* @
|
|
621
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
|
|
771
622
|
*/
|
|
772
623
|
async getRefByLabel(label, params) {
|
|
773
624
|
return require_findRefByLabel.findRefByLabel(await this.getRefs(params), label);
|
|
774
625
|
}
|
|
775
626
|
/**
|
|
776
|
-
*
|
|
777
|
-
*
|
|
627
|
+
* Fetches the repository's master ref.
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
*
|
|
631
|
+
* ```ts
|
|
632
|
+
* const masterRef = await client.getMasterRef()
|
|
633
|
+
* ```
|
|
778
634
|
*
|
|
779
|
-
* @
|
|
635
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
|
|
780
636
|
*/
|
|
781
637
|
async getMasterRef(params) {
|
|
782
638
|
return require_findMasterRef.findMasterRef(await this.getRefs(params));
|
|
783
639
|
}
|
|
784
640
|
/**
|
|
785
|
-
*
|
|
786
|
-
* used to group content changes before publishing.
|
|
641
|
+
* Fetches the repository's active releases.
|
|
787
642
|
*
|
|
788
|
-
* @
|
|
643
|
+
* @example
|
|
644
|
+
*
|
|
645
|
+
* ```ts
|
|
646
|
+
* const releases = await client.getReleases()
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleases}
|
|
789
650
|
*/
|
|
790
651
|
async getReleases(params) {
|
|
791
652
|
return (await this.getRefs(params)).filter((ref) => !ref.isMasterRef);
|
|
792
653
|
}
|
|
793
654
|
/**
|
|
794
|
-
*
|
|
655
|
+
* Fetches a release with a specific ID.
|
|
795
656
|
*
|
|
796
|
-
* @
|
|
657
|
+
* @example
|
|
797
658
|
*
|
|
798
|
-
*
|
|
659
|
+
* ```ts
|
|
660
|
+
* const release = await client.getReleaseByID("YhE3YhEAACIA4321")
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
|
|
799
664
|
*/
|
|
800
665
|
async getReleaseByID(id, params) {
|
|
801
666
|
return require_findRefByID.findRefByID(await this.getReleases(params), id);
|
|
802
667
|
}
|
|
803
668
|
/**
|
|
804
|
-
*
|
|
669
|
+
* Fetches a release by its label. A release ref's label is its name shown in
|
|
670
|
+
* the Page Builder.
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
805
673
|
*
|
|
806
|
-
*
|
|
674
|
+
* ```ts
|
|
675
|
+
* const release = await client.getReleaseByLabel("My Release")
|
|
676
|
+
* ```
|
|
807
677
|
*
|
|
808
|
-
* @
|
|
678
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
|
|
809
679
|
*/
|
|
810
680
|
async getReleaseByLabel(label, params) {
|
|
811
681
|
return require_findRefByLabel.findRefByLabel(await this.getReleases(params), label);
|
|
812
682
|
}
|
|
813
683
|
/**
|
|
814
|
-
*
|
|
684
|
+
* Fetches the repository's page tags.
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
815
687
|
*
|
|
816
|
-
*
|
|
688
|
+
* ```ts
|
|
689
|
+
* const tags = await client.getTags()
|
|
690
|
+
* ```
|
|
691
|
+
*
|
|
692
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#gettags}
|
|
817
693
|
*/
|
|
818
694
|
async getTags(params) {
|
|
819
695
|
const repository = await this.getRepository(params);
|
|
@@ -827,14 +703,20 @@ var Client = class {
|
|
|
827
703
|
return repository.tags;
|
|
828
704
|
}
|
|
829
705
|
/**
|
|
830
|
-
* Builds a
|
|
706
|
+
* Builds a Content API query URL with a set of parameters.
|
|
831
707
|
*
|
|
832
|
-
* @
|
|
708
|
+
* @example
|
|
833
709
|
*
|
|
834
|
-
*
|
|
710
|
+
* ```ts
|
|
711
|
+
* const url = await client.buildQueryURL({
|
|
712
|
+
* filters: [filter.at("document.type", "blog_post")],
|
|
713
|
+
* })
|
|
714
|
+
* ```
|
|
715
|
+
*
|
|
716
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
|
|
835
717
|
*/
|
|
836
718
|
async buildQueryURL({ signal, fetchOptions,...params } = {}) {
|
|
837
|
-
const ref = params.ref || await this
|
|
719
|
+
const ref = params.ref || await this.getResolvedRefString({
|
|
838
720
|
accessToken: params.accessToken,
|
|
839
721
|
signal,
|
|
840
722
|
fetchOptions
|
|
@@ -855,23 +737,18 @@ var Client = class {
|
|
|
855
737
|
});
|
|
856
738
|
}
|
|
857
739
|
/**
|
|
858
|
-
*
|
|
859
|
-
* session. The result of this method should be used to redirect the user to
|
|
860
|
-
* the document's URL.
|
|
740
|
+
* Fetches a previewed page's URL using a preview token and page ID.
|
|
861
741
|
*
|
|
862
742
|
* @example
|
|
863
743
|
*
|
|
864
744
|
* ```ts
|
|
865
|
-
*
|
|
866
|
-
* linkResolver
|
|
867
|
-
* defaultURL:
|
|
868
|
-
*
|
|
745
|
+
* const url = await client.resolvePreviewURL({
|
|
746
|
+
* linkResolver,
|
|
747
|
+
* defaultURL: "/",
|
|
748
|
+
* })
|
|
869
749
|
* ```
|
|
870
750
|
*
|
|
871
|
-
* @
|
|
872
|
-
*
|
|
873
|
-
* @returns The URL for the previewed document during an active preview
|
|
874
|
-
* session. The user should be redirected to this URL.
|
|
751
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#resolvepreviewurl}
|
|
875
752
|
*/
|
|
876
753
|
async resolvePreviewURL(args) {
|
|
877
754
|
let documentID = args.documentID;
|
|
@@ -880,13 +757,13 @@ var Client = class {
|
|
|
880
757
|
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
881
758
|
documentID = documentID || searchParams.get("documentId");
|
|
882
759
|
previewToken = previewToken || searchParams.get("token");
|
|
883
|
-
} else if (this
|
|
884
|
-
if ("query" in this
|
|
885
|
-
var _this$
|
|
886
|
-
documentID = documentID || ((_this$
|
|
887
|
-
previewToken = previewToken || ((_this$
|
|
888
|
-
} else if ("url" in this
|
|
889
|
-
const searchParams = new URL(this
|
|
760
|
+
} else if (this.refState.httpRequest) {
|
|
761
|
+
if ("query" in this.refState.httpRequest) {
|
|
762
|
+
var _this$refState$httpRe, _this$refState$httpRe2;
|
|
763
|
+
documentID = documentID || ((_this$refState$httpRe = this.refState.httpRequest.query) === null || _this$refState$httpRe === void 0 ? void 0 : _this$refState$httpRe.documentId);
|
|
764
|
+
previewToken = previewToken || ((_this$refState$httpRe2 = this.refState.httpRequest.query) === null || _this$refState$httpRe2 === void 0 ? void 0 : _this$refState$httpRe2.token);
|
|
765
|
+
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
766
|
+
const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
|
|
890
767
|
documentID = documentID || searchParams.get("documentId");
|
|
891
768
|
previewToken = previewToken || searchParams.get("token");
|
|
892
769
|
}
|
|
@@ -903,96 +780,88 @@ var Client = class {
|
|
|
903
780
|
return args.defaultURL;
|
|
904
781
|
}
|
|
905
782
|
/**
|
|
906
|
-
* Configures the client to query the latest published content
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
910
|
-
* that query.
|
|
783
|
+
* Configures the client to query the latest published content. This is the
|
|
784
|
+
* client's default mode.
|
|
911
785
|
*
|
|
912
786
|
* @example
|
|
913
787
|
*
|
|
914
788
|
* ```ts
|
|
915
|
-
*
|
|
916
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
789
|
+
* client.queryLatestContent()
|
|
917
790
|
* ```
|
|
791
|
+
*
|
|
792
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
|
|
918
793
|
*/
|
|
919
794
|
queryLatestContent() {
|
|
920
|
-
this
|
|
795
|
+
this.refState.mode = RefStateMode.Master;
|
|
921
796
|
}
|
|
922
797
|
/**
|
|
923
|
-
* Configures the client to query content from a specific
|
|
924
|
-
* by its ID for all future queries.
|
|
925
|
-
*
|
|
926
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
927
|
-
* that query.
|
|
798
|
+
* Configures the client to query content from a release with a specific ID.
|
|
928
799
|
*
|
|
929
800
|
* @example
|
|
930
801
|
*
|
|
931
802
|
* ```ts
|
|
932
|
-
*
|
|
933
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
803
|
+
* client.queryContentFromReleaseByID("YhE3YhEAACIA4321")
|
|
934
804
|
* ```
|
|
935
805
|
*
|
|
936
|
-
* @
|
|
806
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
|
|
937
807
|
*/
|
|
938
|
-
queryContentFromReleaseByID(
|
|
939
|
-
this
|
|
940
|
-
|
|
808
|
+
queryContentFromReleaseByID(releaseID) {
|
|
809
|
+
this.refState = {
|
|
810
|
+
...this.refState,
|
|
811
|
+
mode: RefStateMode.ReleaseID,
|
|
812
|
+
releaseID
|
|
941
813
|
};
|
|
942
814
|
}
|
|
943
815
|
/**
|
|
944
|
-
* Configures the client to query content from a
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
948
|
-
* that query.
|
|
816
|
+
* Configures the client to query content from a release with a specific
|
|
817
|
+
* label.
|
|
949
818
|
*
|
|
950
819
|
* @example
|
|
951
820
|
*
|
|
952
821
|
* ```ts
|
|
953
|
-
*
|
|
954
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
822
|
+
* client.queryContentFromReleaseByLabel("My Release")
|
|
955
823
|
* ```
|
|
956
824
|
*
|
|
957
|
-
* @
|
|
825
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
|
|
958
826
|
*/
|
|
959
|
-
queryContentFromReleaseByLabel(
|
|
960
|
-
this
|
|
961
|
-
|
|
827
|
+
queryContentFromReleaseByLabel(releaseLabel) {
|
|
828
|
+
this.refState = {
|
|
829
|
+
...this.refState,
|
|
830
|
+
mode: RefStateMode.ReleaseLabel,
|
|
831
|
+
releaseLabel
|
|
962
832
|
};
|
|
963
833
|
}
|
|
964
834
|
/**
|
|
965
|
-
* Configures the client to query content from a specific ref.
|
|
966
|
-
* provided as a string or a function.
|
|
967
|
-
*
|
|
968
|
-
* If a function is provided, the ref is fetched lazily before each query. The
|
|
969
|
-
* function may also be asynchronous.
|
|
835
|
+
* Configures the client to query content from a specific ref.
|
|
970
836
|
*
|
|
971
837
|
* @example
|
|
972
838
|
*
|
|
973
839
|
* ```ts
|
|
974
|
-
*
|
|
975
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
840
|
+
* client.queryContentFromRef("my-ref")
|
|
976
841
|
* ```
|
|
977
842
|
*
|
|
978
|
-
* @
|
|
979
|
-
* content.
|
|
843
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
|
|
980
844
|
*/
|
|
981
845
|
queryContentFromRef(ref) {
|
|
982
|
-
this
|
|
846
|
+
this.refState = {
|
|
847
|
+
...this.refState,
|
|
848
|
+
mode: RefStateMode.Manual,
|
|
849
|
+
ref
|
|
850
|
+
};
|
|
983
851
|
}
|
|
984
852
|
/**
|
|
985
|
-
* A `fetch()` function
|
|
986
|
-
*
|
|
987
|
-
* and Authorization headers. Queries will automatically be minified by
|
|
988
|
-
* removing whitespace where possible.
|
|
853
|
+
* A preconfigured `fetch()` function for Prismic's GraphQL API that can be
|
|
854
|
+
* provided to GraphQL clients.
|
|
989
855
|
*
|
|
990
856
|
* @example
|
|
991
857
|
*
|
|
992
858
|
* ```ts
|
|
859
|
+
* import { createClient, getGraphQLEndpoint } from "@prismicio/client"
|
|
860
|
+
*
|
|
861
|
+
* const client = createClient("example-prismic-repo")
|
|
993
862
|
* const graphQLClient = new ApolloClient({
|
|
994
863
|
* link: new HttpLink({
|
|
995
|
-
* uri:
|
|
864
|
+
* uri: getGraphQLEndpoint(client.repositoryName),
|
|
996
865
|
* // Provide `client.graphQLFetch` as the fetch implementation.
|
|
997
866
|
* fetch: client.graphQLFetch,
|
|
998
867
|
* // Using GET is required.
|
|
@@ -1002,17 +871,11 @@ var Client = class {
|
|
|
1002
871
|
* })
|
|
1003
872
|
* ```
|
|
1004
873
|
*
|
|
1005
|
-
* @
|
|
1006
|
-
* @param init - The `fetch()` `init` parameter. Only plain objects are
|
|
1007
|
-
* supported.
|
|
1008
|
-
*
|
|
1009
|
-
* @returns The `fetch()` Response for the request.
|
|
1010
|
-
*
|
|
1011
|
-
* @experimental
|
|
874
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
|
|
1012
875
|
*/
|
|
1013
876
|
async graphQLFetch(input, init) {
|
|
1014
877
|
const repository = await this.getRepository();
|
|
1015
|
-
const ref = await this
|
|
878
|
+
const ref = await this.getResolvedRefString();
|
|
1016
879
|
const unsanitizedHeaders = {
|
|
1017
880
|
"Prismic-ref": ref,
|
|
1018
881
|
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
@@ -1053,79 +916,72 @@ var Client = class {
|
|
|
1053
916
|
*
|
|
1054
917
|
* @returns The ref to use during a query.
|
|
1055
918
|
*/
|
|
1056
|
-
async
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
919
|
+
async getResolvedRefString(params) {
|
|
920
|
+
if (this.refState.autoPreviewsEnabled) {
|
|
921
|
+
var _this$refState$httpRe3, _globalThis$document;
|
|
922
|
+
let previewRef;
|
|
923
|
+
let cookieJar;
|
|
924
|
+
if ((_this$refState$httpRe3 = this.refState.httpRequest) === null || _this$refState$httpRe3 === void 0 ? void 0 : _this$refState$httpRe3.headers) {
|
|
925
|
+
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
926
|
+
else if ("cookie" in this.refState.httpRequest.headers) cookieJar = this.refState.httpRequest.headers.cookie;
|
|
927
|
+
} else if ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) cookieJar = globalThis.document.cookie;
|
|
928
|
+
if (cookieJar) previewRef = require_getPreviewCookie.getPreviewCookie(cookieJar);
|
|
1061
929
|
if (previewRef) return previewRef;
|
|
1062
930
|
}
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
return (
|
|
931
|
+
const repository = await this.getRepository(params);
|
|
932
|
+
const refModeType = this.refState.mode;
|
|
933
|
+
if (refModeType === RefStateMode.ReleaseID) return require_findRefByID.findRefByID(repository.refs, this.refState.releaseID).ref;
|
|
934
|
+
else if (refModeType === RefStateMode.ReleaseLabel) return require_findRefByLabel.findRefByLabel(repository.refs, this.refState.releaseLabel).ref;
|
|
935
|
+
else if (refModeType === RefStateMode.Manual) {
|
|
936
|
+
const res = await require_castThunk.castThunk(this.refState.ref)();
|
|
937
|
+
if (typeof res === "string") return res;
|
|
938
|
+
}
|
|
939
|
+
return require_findMasterRef.findMasterRef(repository.refs).ref;
|
|
1066
940
|
}
|
|
1067
|
-
|
|
1068
|
-
* The private implementation of `this.get`. It returns the API response and
|
|
1069
|
-
* the URL used to make the request. The URL is sometimes used in the public
|
|
1070
|
-
* method to include in thrown errors.
|
|
1071
|
-
*
|
|
1072
|
-
* This method retries requests that throw `RefNotFoundError` or
|
|
1073
|
-
* `RefExpiredError`. It contains special logic to retry with the latest
|
|
1074
|
-
* master ref, provided in the API's error message.
|
|
1075
|
-
*
|
|
1076
|
-
* @typeParam TDocument - Type of Prismic documents returned.
|
|
1077
|
-
*
|
|
1078
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
1079
|
-
*
|
|
1080
|
-
* @returns An object containing the paginated response containing the result
|
|
1081
|
-
* of the query and the URL used to make the API request.
|
|
1082
|
-
*/
|
|
1083
|
-
async _get(params, attemptCount = 0) {
|
|
941
|
+
async #internalGet(params, attempt = 1) {
|
|
1084
942
|
const url = await this.buildQueryURL(params);
|
|
943
|
+
const response = await this.#request(new URL(url), params);
|
|
944
|
+
if (response.ok) return response;
|
|
1085
945
|
try {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
946
|
+
return await this.#throwContentAPIError(response, url);
|
|
947
|
+
} catch (error) {
|
|
948
|
+
if ((error instanceof require_RefNotFoundError.RefNotFoundError || error instanceof require_RefExpiredError.RefExpiredError) && attempt < MAX_INVALID_REF_RETRY_ATTEMPTS) {
|
|
949
|
+
var _error$message$match;
|
|
950
|
+
if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
|
|
951
|
+
const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
|
|
952
|
+
if (!masterRef) throw error;
|
|
953
|
+
require_throttledLog.throttledLog(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_RefNotFoundError.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, { level: "warn" });
|
|
954
|
+
return await this.#internalGet({
|
|
955
|
+
...params,
|
|
956
|
+
ref: masterRef
|
|
957
|
+
}, attempt + 1);
|
|
958
|
+
}
|
|
959
|
+
throw error;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
async #throwContentAPIError(response, url) {
|
|
963
|
+
switch (response.status) {
|
|
964
|
+
case 400: {
|
|
965
|
+
const json = await response.clone().json();
|
|
966
|
+
throw new require_ParsingError.ParsingError(json.message, url, json);
|
|
967
|
+
}
|
|
968
|
+
case 401: {
|
|
969
|
+
const json = await response.clone().json();
|
|
970
|
+
throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
|
|
971
|
+
}
|
|
972
|
+
case 404: {
|
|
973
|
+
const json = await response.clone().json();
|
|
974
|
+
switch (json.type) {
|
|
975
|
+
case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
|
|
976
|
+
case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
|
|
977
|
+
default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
|
|
1115
978
|
}
|
|
1116
|
-
default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
|
|
1117
979
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
if (!masterRef) throw error;
|
|
1124
|
-
require_throttledLog.throttledLog(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_RefNotFoundError.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, { level: "warn" });
|
|
1125
|
-
return await this._get({
|
|
1126
|
-
...params,
|
|
1127
|
-
ref: masterRef
|
|
1128
|
-
}, attemptCount + 1);
|
|
980
|
+
case 410: {
|
|
981
|
+
const json = await response.clone().json();
|
|
982
|
+
throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
|
|
983
|
+
}
|
|
984
|
+
default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
|
|
1129
985
|
}
|
|
1130
986
|
}
|
|
1131
987
|
/**
|
|
@@ -1138,11 +994,8 @@ var Client = class {
|
|
|
1138
994
|
* @returns The response from the fetch request.
|
|
1139
995
|
*/
|
|
1140
996
|
async #request(url, params) {
|
|
1141
|
-
return await require_request.request(url, this._buildRequestInit(params), this.fetchFn);
|
|
1142
|
-
}
|
|
1143
|
-
_buildRequestInit(params) {
|
|
1144
997
|
var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
|
|
1145
|
-
return {
|
|
998
|
+
return await require_request.request(url, {
|
|
1146
999
|
...this.fetchOptions,
|
|
1147
1000
|
...params === null || params === void 0 ? void 0 : params.fetchOptions,
|
|
1148
1001
|
headers: {
|
|
@@ -1150,7 +1003,7 @@ var Client = class {
|
|
|
1150
1003
|
...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
|
|
1151
1004
|
},
|
|
1152
1005
|
signal: (params === null || params === void 0 || (_params$fetchOptions2 = params.fetchOptions) === null || _params$fetchOptions2 === void 0 ? void 0 : _params$fetchOptions2.signal) || (params === null || params === void 0 ? void 0 : params.signal) || ((_this$fetchOptions2 = this.fetchOptions) === null || _this$fetchOptions2 === void 0 ? void 0 : _this$fetchOptions2.signal)
|
|
1153
|
-
};
|
|
1006
|
+
}, this.fetchFn);
|
|
1154
1007
|
}
|
|
1155
1008
|
};
|
|
1156
1009
|
|