@prismicio/client 7.0.0-alpha.3 → 7.0.0-alpha.4

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.
Files changed (45) hide show
  1. package/dist/createClient.cjs +57 -76
  2. package/dist/createClient.cjs.map +1 -1
  3. package/dist/createClient.d.ts +61 -69
  4. package/dist/createClient.js +57 -76
  5. package/dist/createClient.js.map +1 -1
  6. package/dist/helpers/asHTML.cjs +17 -4
  7. package/dist/helpers/asHTML.cjs.map +1 -1
  8. package/dist/helpers/asHTML.d.ts +55 -13
  9. package/dist/helpers/asHTML.js +17 -4
  10. package/dist/helpers/asHTML.js.map +1 -1
  11. package/dist/helpers/asImagePixelDensitySrcSet.cjs +2 -2
  12. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  13. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +2 -2
  14. package/dist/helpers/asImagePixelDensitySrcSet.js +2 -2
  15. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  16. package/dist/helpers/asImageSrc.cjs +2 -2
  17. package/dist/helpers/asImageSrc.cjs.map +1 -1
  18. package/dist/helpers/asImageSrc.d.ts +2 -2
  19. package/dist/helpers/asImageSrc.js +2 -2
  20. package/dist/helpers/asImageSrc.js.map +1 -1
  21. package/dist/helpers/asImageWidthSrcSet.cjs +2 -2
  22. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  23. package/dist/helpers/asImageWidthSrcSet.d.ts +2 -2
  24. package/dist/helpers/asImageWidthSrcSet.js +2 -2
  25. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  26. package/dist/helpers/asLink.cjs +12 -3
  27. package/dist/helpers/asLink.cjs.map +1 -1
  28. package/dist/helpers/asLink.d.ts +55 -15
  29. package/dist/helpers/asLink.js +12 -3
  30. package/dist/helpers/asLink.js.map +1 -1
  31. package/dist/helpers/asText.cjs +11 -2
  32. package/dist/helpers/asText.cjs.map +1 -1
  33. package/dist/helpers/asText.d.ts +44 -10
  34. package/dist/helpers/asText.js +11 -2
  35. package/dist/helpers/asText.js.map +1 -1
  36. package/dist/package.json.cjs +1 -1
  37. package/dist/package.json.js +1 -1
  38. package/package.json +1 -1
  39. package/src/createClient.ts +176 -251
  40. package/src/helpers/asHTML.ts +99 -25
  41. package/src/helpers/asImagePixelDensitySrcSet.ts +3 -3
  42. package/src/helpers/asImageSrc.ts +3 -3
  43. package/src/helpers/asImageWidthSrcSet.ts +3 -3
  44. package/src/helpers/asLink.ts +102 -18
  45. package/src/helpers/asText.ts +71 -12
@@ -46,15 +46,17 @@ export type FetchLike = (input: string, init?: RequestInitLike) => Promise<Respo
46
46
  */
47
47
  export type AbortSignalLike = any;
48
48
  /**
49
- * The minimum required properties from RequestInit.
49
+ * A subset of RequestInit properties to configure a `fetch()` request.
50
50
  */
51
- export interface RequestInitLike {
51
+ export interface RequestInitLike extends Pick<RequestInit, "cache"> {
52
+ /**
53
+ * An object literal to set the `fetch()` request's headers.
54
+ */
52
55
  headers?: Record<string, string>;
53
56
  /**
54
- * An object that allows you to abort a `fetch()` request if needed via an
55
- * `AbortController` object
57
+ * An AbortSignal to set the `fetch()` request's signal.
56
58
  *
57
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
59
+ * See: \<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\>
58
60
  */
59
61
  signal?: AbortSignalLike;
60
62
  }
@@ -136,48 +138,41 @@ export type ClientConfig = {
136
138
  * Node.js, this function must be provided.
137
139
  */
138
140
  fetch?: FetchLike;
139
- } & OptimizeParams;
141
+ /**
142
+ * Options provided to the client's `fetch()` on all network requests.
143
+ * These options will be merged with internally required options. They
144
+ * can also be overriden on a per-query basis using the query's
145
+ * `fetchOptions` parameter.
146
+ */
147
+ fetchOptions?: RequestInitLike;
148
+ };
140
149
  /**
141
- * Parameters for any client method that use `fetch()`. Only a subset of
142
- * `fetch()` parameters are exposed.
150
+ * Parameters for any client method that use `fetch()`.
143
151
  */
144
152
  type FetchParams = {
153
+ /**
154
+ * Options provided to the client's `fetch()` on all network requests.
155
+ * These options will be merged with internally required options. They
156
+ * can also be overriden on a per-query basis using the query's
157
+ * `fetchOptions` parameter.
158
+ */
159
+ fetchOptions?: RequestInitLike;
145
160
  /**
146
161
  * An `AbortSignal` provided by an `AbortController`. This allows the network
147
162
  * request to be cancelled if necessary.
148
163
  *
149
164
  * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
165
+ *
166
+ * @deprecated Move the `signal` parameter into `fetchOptions.signal`:
167
+ *
168
+ * ```typescript
169
+ * client.getByUID("page", "home",{
170
+ * fetchOptions: { signal }
171
+ * });
172
+ * ```
150
173
  */
151
174
  signal?: AbortSignalLike;
152
175
  };
153
- /**
154
- * Parameters that determine if or how the client is optimized.
155
- */
156
- type OptimizeParams = {
157
- /**
158
- * Options that determine if or how the client is optimized.
159
- */
160
- optimize?: {
161
- /**
162
- * Determines if fetching repository metadata should be optimized. The
163
- * optimizations result in faster queries, less network requests, and more
164
- * accurate cache-busting.
165
- *
166
- * Only opt out of this optimization if you know what you are doing.
167
- *
168
- * @defaultValue `true`
169
- */
170
- repositoryRequests?: boolean;
171
- /**
172
- * Determines if concurrent requests to the same URL should be optimized. The optimizations result in less network requests and quicker responses.
173
- *
174
- * Only opt out of this optimization if you know what you are doing.
175
- *
176
- * @defaultValue `true`
177
- */
178
- concurrentRequests?: boolean;
179
- };
180
- };
181
176
  /**
182
177
  * Parameters specific to client methods that fetch all documents. These methods
183
178
  * start with `getAll` (for example, `getAllByType`).
@@ -286,15 +281,12 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
286
281
  * Node.js, this function must be provided.
287
282
  */
288
283
  fetchFn: FetchLike;
284
+ fetchOptions?: RequestInitLike;
289
285
  /**
290
286
  * Default parameters that will be sent with each query. These parameters can
291
287
  * be overridden on each query if needed.
292
288
  */
293
289
  defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes">;
294
- /**
295
- * Options that determine if or how the client is optimized.
296
- */
297
- optimize: NonNullable<OptimizeParams["optimize"]>;
298
290
  /**
299
291
  * The client's ref mode state. This determines which ref is used during
300
292
  * queries.
@@ -391,7 +383,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
391
383
  *
392
384
  * @returns A paginated response containing the result of the query.
393
385
  */
394
- get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
386
+ get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
395
387
  /**
396
388
  * Queries content from the Prismic repository and returns only the first
397
389
  * result, if any.
@@ -406,7 +398,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
406
398
  * @param params - Parameters to filter, sort, and paginate results. @returns
407
399
  * The first result of the query, if any.
408
400
  */
409
- getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<TDocument>;
401
+ getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
410
402
  /**
411
403
  * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
412
404
  * require more resources than other methods. Prefer using other methods that
@@ -429,7 +421,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
429
421
  *
430
422
  * @returns A list of documents matching the query.
431
423
  */
432
- dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
424
+ dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
433
425
  /**
434
426
  * Queries a document from the Prismic repository with a specific ID.
435
427
  *
@@ -451,7 +443,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
451
443
  * @returns The document with an ID matching the `id` parameter, if a matching
452
444
  * document exists.
453
445
  */
454
- getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<TDocument>;
446
+ getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
455
447
  /**
456
448
  * Queries documents from the Prismic repository with specific IDs.
457
449
  *
@@ -476,7 +468,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
476
468
  * @returns A paginated response containing documents with IDs matching the
477
469
  * `ids` parameter.
478
470
  */
479
- getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
471
+ getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
480
472
  /**
481
473
  * Queries all documents from the Prismic repository with specific IDs.
482
474
  *
@@ -503,7 +495,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
503
495
  *
504
496
  * @returns A list of documents with IDs matching the `ids` parameter.
505
497
  */
506
- getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
498
+ getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
507
499
  /**
508
500
  * Queries a document from the Prismic repository with a specific UID and
509
501
  * Custom Type.
@@ -527,7 +519,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
527
519
  * @returns The document with a UID matching the `uid` parameter, if a
528
520
  * matching document exists.
529
521
  */
530
- getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
522
+ getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
531
523
  /**
532
524
  * Queries document from the Prismic repository with specific UIDs and Custom
533
525
  * Type.
@@ -554,7 +546,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
554
546
  * @returns A paginated response containing documents with UIDs matching the
555
547
  * `uids` parameter.
556
548
  */
557
- getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
549
+ getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
558
550
  /**
559
551
  * Queries all documents from the Prismic repository with specific UIDs and
560
552
  * Custom Type.
@@ -583,7 +575,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
583
575
  *
584
576
  * @returns A list of documents with UIDs matching the `uids` parameter.
585
577
  */
586
- getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
578
+ getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
587
579
  /**
588
580
  * Queries a singleton document from the Prismic repository for a specific
589
581
  * Custom Type.
@@ -606,7 +598,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
606
598
  * @returns The singleton document for the Custom Type, if a matching document
607
599
  * exists.
608
600
  */
609
- getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
601
+ getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
610
602
  /**
611
603
  * Queries documents from the Prismic repository for a specific Custom Type.
612
604
  *
@@ -625,7 +617,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
625
617
  *
626
618
  * @returns A paginated response containing documents of the Custom Type.
627
619
  */
628
- getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
620
+ getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
629
621
  /**
630
622
  * Queries all documents from the Prismic repository for a specific Custom
631
623
  * Type.
@@ -645,7 +637,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
645
637
  *
646
638
  * @returns A list of all documents of the Custom Type.
647
639
  */
648
- getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
640
+ getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
649
641
  /**
650
642
  * Queries documents from the Prismic repository with a specific tag.
651
643
  *
@@ -664,7 +656,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
664
656
  *
665
657
  * @returns A paginated response containing documents with the tag.
666
658
  */
667
- getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
659
+ getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
668
660
  /**
669
661
  * Queries all documents from the Prismic repository with a specific tag.
670
662
  *
@@ -683,7 +675,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
683
675
  *
684
676
  * @returns A list of all documents with the tag.
685
677
  */
686
- getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
678
+ getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
687
679
  /**
688
680
  * Queries documents from the Prismic repository with specific tags. A
689
681
  * document must be tagged with all of the queried tags to be included.
@@ -700,7 +692,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
700
692
  *
701
693
  * @returns A paginated response containing documents with the tags.
702
694
  */
703
- getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
695
+ getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
704
696
  /**
705
697
  * Queries documents from the Prismic repository with specific tags. A
706
698
  * document must be tagged with all of the queried tags to be included.
@@ -720,7 +712,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
720
712
  *
721
713
  * @returns A list of all documents with the tags.
722
714
  */
723
- getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
715
+ getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
724
716
  /**
725
717
  * Queries documents from the Prismic repository with specific tags. A
726
718
  * document must be tagged with at least one of the queried tags to be
@@ -739,7 +731,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
739
731
  * @returns A paginated response containing documents with at least one of the
740
732
  * tags.
741
733
  */
742
- getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
734
+ getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
743
735
  /**
744
736
  * Queries documents from the Prismic repository with specific tags. A
745
737
  * document must be tagged with at least one of the queried tags to be
@@ -760,14 +752,14 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
760
752
  *
761
753
  * @returns A list of all documents with at least one of the tags.
762
754
  */
763
- getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
755
+ getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
764
756
  /**
765
757
  * Returns metadata about the Prismic repository, such as its refs, releases,
766
758
  * and custom types.
767
759
  *
768
760
  * @returns Repository metadata.
769
761
  */
770
- getRepository(params?: FetchParams & OptimizeParams): Promise<Repository>;
762
+ getRepository(params?: FetchParams): Promise<Repository>;
771
763
  /**
772
764
  * Returns a list of all refs for the Prismic repository.
773
765
  *
@@ -777,7 +769,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
777
769
  *
778
770
  * @returns A list of all refs for the Prismic repository.
779
771
  */
780
- getRefs(params?: FetchParams & OptimizeParams): Promise<Ref[]>;
772
+ getRefs(params?: FetchParams): Promise<Ref[]>;
781
773
  /**
782
774
  * Returns a ref for the Prismic repository with a matching ID.
783
775
  *
@@ -785,7 +777,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
785
777
  *
786
778
  * @returns The ref with a matching ID, if it exists.
787
779
  */
788
- getRefByID(id: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
780
+ getRefByID(id: string, params?: FetchParams): Promise<Ref>;
789
781
  /**
790
782
  * Returns a ref for the Prismic repository with a matching label.
791
783
  *
@@ -793,21 +785,21 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
793
785
  *
794
786
  * @returns The ref with a matching label, if it exists.
795
787
  */
796
- getRefByLabel(label: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
788
+ getRefByLabel(label: string, params?: FetchParams): Promise<Ref>;
797
789
  /**
798
790
  * Returns the master ref for the Prismic repository. The master ref points to
799
791
  * the repository's latest published content.
800
792
  *
801
793
  * @returns The repository's master ref.
802
794
  */
803
- getMasterRef(params?: FetchParams & OptimizeParams): Promise<Ref>;
795
+ getMasterRef(params?: FetchParams): Promise<Ref>;
804
796
  /**
805
797
  * Returns a list of all Releases for the Prismic repository. Releases are
806
798
  * used to group content changes before publishing.
807
799
  *
808
800
  * @returns A list of all Releases for the Prismic repository.
809
801
  */
810
- getReleases(params?: FetchParams & OptimizeParams): Promise<Ref[]>;
802
+ getReleases(params?: FetchParams): Promise<Ref[]>;
811
803
  /**
812
804
  * Returns a Release for the Prismic repository with a matching ID.
813
805
  *
@@ -815,7 +807,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
815
807
  *
816
808
  * @returns The Release with a matching ID, if it exists.
817
809
  */
818
- getReleaseByID(id: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
810
+ getReleaseByID(id: string, params?: FetchParams): Promise<Ref>;
819
811
  /**
820
812
  * Returns a Release for the Prismic repository with a matching label.
821
813
  *
@@ -823,13 +815,13 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
823
815
  *
824
816
  * @returns The ref with a matching label, if it exists.
825
817
  */
826
- getReleaseByLabel(label: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
818
+ getReleaseByLabel(label: string, params?: FetchParams): Promise<Ref>;
827
819
  /**
828
820
  * Returns a list of all tags used in the Prismic repository.
829
821
  *
830
822
  * @returns A list of all tags used in the repository.
831
823
  */
832
- getTags(params?: FetchParams & OptimizeParams): Promise<string[]>;
824
+ getTags(params?: FetchParams): Promise<string[]>;
833
825
  /**
834
826
  * Builds a URL used to query content from the Prismic repository.
835
827
  *
@@ -837,7 +829,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
837
829
  *
838
830
  * @returns A URL string that can be requested to query content.
839
831
  */
840
- buildQueryURL({ signal, optimize, ...params }?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<string>;
832
+ buildQueryURL({ signal, fetchOptions, ...params }?: Partial<BuildQueryURLArgs> & FetchParams): Promise<string>;
841
833
  /**
842
834
  * Determines the URL for a previewed document during an active preview
843
835
  * session. The result of this method should be used to redirect the user to
@@ -857,7 +849,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
857
849
  * @returns The URL for the previewed document during an active preview
858
850
  * session. The user should be redirected to this URL.
859
851
  */
860
- resolvePreviewURL<LinkResolverReturnType>(args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams & OptimizeParams): Promise<string>;
852
+ resolvePreviewURL<LinkResolverReturnType>(args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams): Promise<string>;
861
853
  /**
862
854
  * Configures the client to query the latest published content for all future
863
855
  * queries.
@@ -6,6 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import { appendFilters } from "./lib/appendFilters.js";
8
8
  import { castThunk } from "./lib/castThunk.js";
9
+ import { devMsg } from "./lib/devMsg.js";
9
10
  import { everyTagFilter } from "./lib/everyTagFilter.js";
10
11
  import { findMasterRef } from "./lib/findMasterRef.js";
11
12
  import { findRefByID } from "./lib/findRefByID.js";
@@ -22,11 +23,11 @@ import { asLink } from "./helpers/asLink.js";
22
23
  import { buildQueryURL } from "./buildQueryURL.js";
23
24
  import { filter } from "./filter.js";
24
25
  import { getRepositoryEndpoint } from "./getRepositoryEndpoint.js";
26
+ import { getRepositoryName } from "./getRepositoryName.js";
25
27
  import { isRepositoryEndpoint } from "./isRepositoryEndpoint.js";
26
28
  const MAX_PAGE_SIZE = 100;
27
29
  const REPOSITORY_CACHE_TTL = 5e3;
28
30
  const GET_ALL_QUERY_DELAY = 500;
29
- const OPTIMIZE_REPOSITORY_REQUESTS_VALID_UNTIL_PARAMETER_NAME = "x-valid-until";
30
31
  var RefStateMode;
31
32
  (function(RefStateMode2) {
32
33
  RefStateMode2["Master"] = "Master";
@@ -85,15 +86,12 @@ class Client {
85
86
  * Node.js, this function must be provided.
86
87
  */
87
88
  __publicField(this, "fetchFn");
89
+ __publicField(this, "fetchOptions");
88
90
  /**
89
91
  * Default parameters that will be sent with each query. These parameters can
90
92
  * be overridden on each query if needed.
91
93
  */
92
94
  __publicField(this, "defaultParams");
93
- /**
94
- * Options that determine if or how the client is optimized.
95
- */
96
- __publicField(this, "optimize");
97
95
  /**
98
96
  * The client's ref mode state. This determines which ref is used during
99
97
  * queries.
@@ -114,10 +112,17 @@ class Client {
114
112
  * Active `fetch()` jobs keyed by URL and AbortSignal (if it exists).
115
113
  */
116
114
  __publicField(this, "fetchJobs", {});
117
- var _a, _b;
118
115
  if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
119
- if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)) {
120
- throw new PrismicError("@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
116
+ if (process.env.NODE_ENV === "development") {
117
+ if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(repositoryNameOrEndpoint)) {
118
+ throw new PrismicError("@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
119
+ }
120
+ const hostname = new URL(repositoryNameOrEndpoint).hostname.toLowerCase();
121
+ if (hostname.endsWith(".prismic.io") && !hostname.endsWith(".cdn.prismic.io")) {
122
+ const repositoryName = getRepositoryName(repositoryNameOrEndpoint);
123
+ const dotCDNEndpoint = getRepositoryEndpoint(repositoryName);
124
+ console.warn(`[@prismicio/client] A non-.cdn endpoint was provided to create a client with (\`${repositoryNameOrEndpoint}\`). Non-.cdn endpoints can have unexpected side-effects and cause performance issues when querying Prismic. Please convert it to the \`.cdn\` alternative (\`${dotCDNEndpoint}\`) or use the repository name directly instead (\`${repositoryName}\`). For more details, see ${devMsg("endpoint-must-use-cdn")}`);
125
+ }
121
126
  }
122
127
  this.endpoint = repositoryNameOrEndpoint;
123
128
  } else {
@@ -126,11 +131,8 @@ class Client {
126
131
  this.accessToken = options.accessToken;
127
132
  this.routes = options.routes;
128
133
  this.brokenRoute = options.brokenRoute;
134
+ this.fetchOptions = options.fetchOptions;
129
135
  this.defaultParams = options.defaultParams;
130
- this.optimize = {
131
- repositoryRequests: ((_a = options.optimize) == null ? void 0 : _a.repositoryRequests) ?? true,
132
- concurrentRequests: ((_b = options.optimize) == null ? void 0 : _b.concurrentRequests) ?? true
133
- };
134
136
  if (options.ref) {
135
137
  this.queryContentFromRef(options.ref);
136
138
  }
@@ -667,14 +669,10 @@ class Client {
667
669
  * @returns Repository metadata.
668
670
  */
669
671
  async getRepository(params) {
670
- var _a;
671
672
  const url = new URL(this.endpoint);
672
673
  if (this.accessToken) {
673
674
  url.searchParams.set("access_token", this.accessToken);
674
675
  }
675
- if (((_a = params == null ? void 0 : params.optimize) == null ? void 0 : _a.repositoryRequests) ?? this.optimize.repositoryRequests) {
676
- url.searchParams.set(OPTIMIZE_REPOSITORY_REQUESTS_VALID_UNTIL_PARAMETER_NAME, (Math.floor(Date.now() / REPOSITORY_CACHE_TTL) * REPOSITORY_CACHE_TTL + REPOSITORY_CACHE_TTL).toString());
677
- }
678
676
  return await this.fetch(url.toString(), params);
679
677
  }
680
678
  /**
@@ -779,9 +777,9 @@ class Client {
779
777
  *
780
778
  * @returns A URL string that can be requested to query content.
781
779
  */
782
- async buildQueryURL({ signal, optimize, ...params } = {}) {
783
- const ref = params.ref || await this.getResolvedRefString({ signal, optimize });
784
- const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, optimize })).integrationFieldsRef || void 0;
780
+ async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
781
+ const ref = params.ref || await this.getResolvedRefString({ signal, fetchOptions });
782
+ const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, fetchOptions })).integrationFieldsRef || void 0;
785
783
  return buildQueryURL(this.endpoint, {
786
784
  ...this.defaultParams,
787
785
  ...params,
@@ -824,19 +822,19 @@ class Client {
824
822
  documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
825
823
  previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
826
824
  } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
827
- const searchParams = new URL(this.refState.httpRequest.url).searchParams;
825
+ const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
828
826
  documentID = documentID || searchParams.get("documentId");
829
827
  previewToken = previewToken || searchParams.get("token");
830
828
  }
831
829
  }
832
830
  if (documentID != null && previewToken != null) {
833
831
  const document = await this.getByID(documentID, {
834
- optimize: args.optimize,
835
- signal: args.signal,
836
832
  ref: previewToken,
837
- lang: "*"
833
+ lang: "*",
834
+ signal: args.signal,
835
+ fetchOptions: args.fetchOptions
838
836
  });
839
- const url = asLink(document, args.linkResolver);
837
+ const url = asLink(document, { linkResolver: args.linkResolver });
840
838
  if (typeof url === "string") {
841
839
  return url;
842
840
  }
@@ -1008,16 +1006,11 @@ class Client {
1008
1006
  * @returns Cached repository metadata.
1009
1007
  */
1010
1008
  async getCachedRepository(params) {
1011
- var _a;
1012
- if (((_a = params == null ? void 0 : params.optimize) == null ? void 0 : _a.repositoryRequests) ?? this.optimize.repositoryRequests) {
1013
- if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
1014
- this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
1015
- this.cachedRepository = await this.getRepository(params);
1016
- }
1017
- return this.cachedRepository;
1018
- } else {
1019
- return await this.getRepository(params);
1009
+ if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
1010
+ this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
1011
+ this.cachedRepository = await this.getRepository(params);
1020
1012
  }
1013
+ return this.cachedRepository;
1021
1014
  }
1022
1015
  /**
1023
1016
  * Returns a cached Prismic repository form. Forms are used to determine API
@@ -1106,52 +1099,40 @@ class Client {
1106
1099
  * @returns The JSON response from the network request.
1107
1100
  */
1108
1101
  async fetch(url, params = {}) {
1109
- var _a;
1110
- let res;
1111
- if (((_a = params.optimize) == null ? void 0 : _a.concurrentRequests) ?? this.optimize.concurrentRequests) {
1112
- let job;
1113
- const fetchJobKeyInstance = new URL(url);
1114
- fetchJobKeyInstance.searchParams.delete(OPTIMIZE_REPOSITORY_REQUESTS_VALID_UNTIL_PARAMETER_NAME);
1115
- const fetchJobKey = fetchJobKeyInstance.toString();
1116
- if (this.fetchJobs[fetchJobKey] && this.fetchJobs[fetchJobKey].has(params.signal)) {
1117
- job = this.fetchJobs[fetchJobKey].get(params.signal);
1118
- } else {
1119
- this.fetchJobs[fetchJobKey] = this.fetchJobs[fetchJobKey] || /* @__PURE__ */ new Map();
1120
- job = this.fetchFn(url, {
1121
- signal: params.signal
1122
- }).then(async (res2) => {
1123
- let json = void 0;
1124
- try {
1125
- json = await res2.json();
1126
- } catch {
1127
- }
1128
- return {
1129
- status: res2.status,
1130
- json
1131
- };
1132
- }).finally(() => {
1133
- this.fetchJobs[fetchJobKey].delete(params.signal);
1134
- if (this.fetchJobs[fetchJobKey].size === 0) {
1135
- delete this.fetchJobs[fetchJobKey];
1136
- }
1137
- });
1138
- this.fetchJobs[fetchJobKey].set(params.signal, job);
1139
- }
1140
- res = await job;
1102
+ var _a, _b, _c, _d;
1103
+ const requestInit = {
1104
+ ...this.fetchOptions,
1105
+ ...params.fetchOptions,
1106
+ headers: {
1107
+ ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
1108
+ ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
1109
+ },
1110
+ signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
1111
+ };
1112
+ let job;
1113
+ if (this.fetchJobs[url] && this.fetchJobs[url].has(requestInit.signal)) {
1114
+ job = this.fetchJobs[url].get(requestInit.signal);
1141
1115
  } else {
1142
- const job = await this.fetchFn(url, {
1143
- signal: params.signal
1116
+ this.fetchJobs[url] = this.fetchJobs[url] || /* @__PURE__ */ new Map();
1117
+ job = this.fetchFn(url, requestInit).then(async (res2) => {
1118
+ let json = void 0;
1119
+ try {
1120
+ json = await res2.json();
1121
+ } catch {
1122
+ }
1123
+ return {
1124
+ status: res2.status,
1125
+ json
1126
+ };
1127
+ }).finally(() => {
1128
+ this.fetchJobs[url].delete(requestInit.signal);
1129
+ if (this.fetchJobs[url].size === 0) {
1130
+ delete this.fetchJobs[url];
1131
+ }
1144
1132
  });
1145
- let json = void 0;
1146
- try {
1147
- json = await job.json();
1148
- } catch {
1149
- }
1150
- res = {
1151
- status: job.status,
1152
- json
1153
- };
1133
+ this.fetchJobs[url].set(requestInit.signal, job);
1154
1134
  }
1135
+ const res = await job;
1155
1136
  if (res.status !== 404 && res.json == null) {
1156
1137
  throw new PrismicError(void 0, url, res.json);
1157
1138
  }