@prismicio/client 7.21.0-canary.85959a7 → 7.21.0-canary.bd2c015

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