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