@prismicio/client 7.0.0-alpha.5 → 7.0.1-alpha.0

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 (231) hide show
  1. package/dist/buildQueryURL.cjs.map +1 -1
  2. package/dist/buildQueryURL.d.ts +15 -14
  3. package/dist/buildQueryURL.js.map +1 -1
  4. package/dist/createClient.cjs +63 -30
  5. package/dist/createClient.cjs.map +1 -1
  6. package/dist/createClient.d.ts +95 -48
  7. package/dist/createClient.js +63 -30
  8. package/dist/createClient.js.map +1 -1
  9. package/dist/filter.cjs +39 -39
  10. package/dist/filter.cjs.map +1 -1
  11. package/dist/filter.d.ts +39 -39
  12. package/dist/filter.js +39 -39
  13. package/dist/filter.js.map +1 -1
  14. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  15. package/dist/getGraphQLEndpoint.d.ts +1 -0
  16. package/dist/getGraphQLEndpoint.js.map +1 -1
  17. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  18. package/dist/getRepositoryEndpoint.d.ts +2 -0
  19. package/dist/getRepositoryEndpoint.js.map +1 -1
  20. package/dist/getRepositoryName.cjs.map +1 -1
  21. package/dist/getRepositoryName.d.ts +1 -0
  22. package/dist/getRepositoryName.js.map +1 -1
  23. package/dist/getToolbarSrc.cjs.map +1 -1
  24. package/dist/getToolbarSrc.d.ts +1 -1
  25. package/dist/getToolbarSrc.js.map +1 -1
  26. package/dist/helpers/asDate.cjs.map +1 -1
  27. package/dist/helpers/asDate.d.ts +3 -2
  28. package/dist/helpers/asDate.js.map +1 -1
  29. package/dist/helpers/asHTML.cjs.map +1 -1
  30. package/dist/helpers/asHTML.d.ts +34 -28
  31. package/dist/helpers/asHTML.js.map +1 -1
  32. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  33. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +5 -5
  34. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  35. package/dist/helpers/asImageSrc.cjs.map +1 -1
  36. package/dist/helpers/asImageSrc.d.ts +3 -3
  37. package/dist/helpers/asImageSrc.js.map +1 -1
  38. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  39. package/dist/helpers/asImageWidthSrcSet.d.ts +6 -6
  40. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  41. package/dist/helpers/asLink.cjs.map +1 -1
  42. package/dist/helpers/asLink.d.ts +32 -23
  43. package/dist/helpers/asLink.js.map +1 -1
  44. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  45. package/dist/helpers/asLinkAttrs.d.ts +12 -7
  46. package/dist/helpers/asLinkAttrs.js.map +1 -1
  47. package/dist/helpers/asText.cjs.map +1 -1
  48. package/dist/helpers/asText.d.ts +18 -14
  49. package/dist/helpers/asText.js.map +1 -1
  50. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  51. package/dist/helpers/documentToLinkField.d.ts +2 -0
  52. package/dist/helpers/documentToLinkField.js.map +1 -1
  53. package/dist/helpers/isFilled.cjs +3 -1
  54. package/dist/helpers/isFilled.cjs.map +1 -1
  55. package/dist/helpers/isFilled.d.ts +24 -20
  56. package/dist/helpers/isFilled.js +3 -1
  57. package/dist/helpers/isFilled.js.map +1 -1
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.d.ts +13 -3
  60. package/dist/index.js.map +1 -1
  61. package/dist/lib/appendFilters.cjs.map +1 -1
  62. package/dist/lib/appendFilters.d.ts +4 -4
  63. package/dist/lib/appendFilters.js.map +1 -1
  64. package/dist/lib/castArray.cjs.map +1 -1
  65. package/dist/lib/castArray.d.ts +1 -0
  66. package/dist/lib/castArray.js.map +1 -1
  67. package/dist/lib/castThunk.cjs.map +1 -1
  68. package/dist/lib/castThunk.d.ts +2 -1
  69. package/dist/lib/castThunk.js.map +1 -1
  70. package/dist/lib/everyTagFilter.cjs.map +1 -1
  71. package/dist/lib/everyTagFilter.d.ts +2 -2
  72. package/dist/lib/everyTagFilter.js.map +1 -1
  73. package/dist/lib/findMasterRef.cjs.map +1 -1
  74. package/dist/lib/findMasterRef.d.ts +1 -0
  75. package/dist/lib/findMasterRef.js.map +1 -1
  76. package/dist/lib/findRef.cjs.map +1 -1
  77. package/dist/lib/findRef.d.ts +3 -2
  78. package/dist/lib/findRef.js.map +1 -1
  79. package/dist/lib/findRefByID.cjs.map +1 -1
  80. package/dist/lib/findRefByID.d.ts +1 -0
  81. package/dist/lib/findRefByID.js.map +1 -1
  82. package/dist/lib/findRefByLabel.cjs.map +1 -1
  83. package/dist/lib/findRefByLabel.d.ts +1 -0
  84. package/dist/lib/findRefByLabel.js.map +1 -1
  85. package/dist/package.json.cjs +1 -1
  86. package/dist/package.json.js +1 -1
  87. package/dist/types/api/query.d.ts +1 -0
  88. package/dist/types/api/release.d.ts +1 -0
  89. package/dist/types/api/repository.d.ts +2 -2
  90. package/dist/types/api/tags.d.ts +1 -0
  91. package/dist/types/model/boolean.d.ts +1 -1
  92. package/dist/types/model/color.d.ts +1 -1
  93. package/dist/types/model/contentRelationship.d.ts +2 -3
  94. package/dist/types/model/customType.d.ts +11 -11
  95. package/dist/types/model/date.d.ts +1 -1
  96. package/dist/types/model/embed.d.ts +1 -1
  97. package/dist/types/model/geoPoint.d.ts +1 -1
  98. package/dist/types/model/group.d.ts +1 -1
  99. package/dist/types/model/image.d.ts +3 -3
  100. package/dist/types/model/{integrationFields.d.ts → integration.d.ts} +3 -3
  101. package/dist/types/model/keyText.d.ts +1 -1
  102. package/dist/types/model/link.cjs.map +1 -1
  103. package/dist/types/model/link.d.ts +4 -6
  104. package/dist/types/model/link.js.map +1 -1
  105. package/dist/types/model/linkToMedia.d.ts +2 -3
  106. package/dist/types/model/number.d.ts +1 -1
  107. package/dist/types/model/richText.d.ts +3 -3
  108. package/dist/types/model/select.d.ts +1 -1
  109. package/dist/types/model/sharedSlice.d.ts +2 -2
  110. package/dist/types/model/sharedSliceVariation.d.ts +1 -1
  111. package/dist/types/model/slice.cjs.map +1 -1
  112. package/dist/types/model/slice.d.ts +1 -1
  113. package/dist/types/model/slice.js.map +1 -1
  114. package/dist/types/model/sliceZone.cjs.map +1 -1
  115. package/dist/types/model/sliceZone.d.ts +2 -2
  116. package/dist/types/model/sliceZone.js.map +1 -1
  117. package/dist/types/model/timestamp.d.ts +1 -1
  118. package/dist/types/model/title.d.ts +1 -1
  119. package/dist/types/model/types.cjs +5 -1
  120. package/dist/types/model/types.cjs.map +1 -1
  121. package/dist/types/model/types.d.ts +10 -6
  122. package/dist/types/model/types.js +5 -1
  123. package/dist/types/model/types.js.map +1 -1
  124. package/dist/types/model/uid.d.ts +1 -1
  125. package/dist/types/value/boolean.d.ts +1 -1
  126. package/dist/types/value/color.d.ts +2 -1
  127. package/dist/types/value/contentRelationship.d.ts +1 -1
  128. package/dist/types/value/date.d.ts +2 -1
  129. package/dist/types/value/document.d.ts +4 -4
  130. package/dist/types/value/embed.cjs.map +1 -1
  131. package/dist/types/value/embed.d.ts +2 -1
  132. package/dist/types/value/embed.js.map +1 -1
  133. package/dist/types/value/geoPoint.d.ts +2 -1
  134. package/dist/types/value/group.d.ts +1 -1
  135. package/dist/types/value/image.d.ts +5 -3
  136. package/dist/types/value/{integrationFields.d.ts → integration.d.ts} +3 -2
  137. package/dist/types/value/keyText.d.ts +2 -1
  138. package/dist/types/value/link.cjs.map +1 -1
  139. package/dist/types/value/link.d.ts +2 -2
  140. package/dist/types/value/link.js.map +1 -1
  141. package/dist/types/value/linkToMedia.d.ts +2 -2
  142. package/dist/types/value/number.d.ts +2 -1
  143. package/dist/types/value/richText.cjs.map +1 -1
  144. package/dist/types/value/richText.d.ts +26 -26
  145. package/dist/types/value/richText.js.map +1 -1
  146. package/dist/types/value/select.d.ts +2 -1
  147. package/dist/types/value/sharedSlice.d.ts +1 -1
  148. package/dist/types/value/sharedSliceVariation.d.ts +3 -0
  149. package/dist/types/value/slice.d.ts +1 -1
  150. package/dist/types/value/timestamp.d.ts +1 -1
  151. package/dist/types/value/title.d.ts +1 -1
  152. package/dist/types/value/types.d.ts +3 -2
  153. package/dist/types/webhook/apiUpdate.d.ts +1 -1
  154. package/package.json +4 -4
  155. package/src/buildQueryURL.ts +15 -14
  156. package/src/createClient.ts +112 -55
  157. package/src/filter.ts +43 -43
  158. package/src/getGraphQLEndpoint.ts +1 -0
  159. package/src/getRepositoryEndpoint.ts +2 -0
  160. package/src/getRepositoryName.ts +1 -0
  161. package/src/getToolbarSrc.ts +1 -1
  162. package/src/helpers/asDate.ts +3 -2
  163. package/src/helpers/asHTML.ts +36 -30
  164. package/src/helpers/asImagePixelDensitySrcSet.ts +5 -5
  165. package/src/helpers/asImageSrc.ts +3 -3
  166. package/src/helpers/asImageWidthSrcSet.ts +6 -6
  167. package/src/helpers/asLink.ts +36 -27
  168. package/src/helpers/asLinkAttrs.ts +12 -7
  169. package/src/helpers/asText.ts +18 -14
  170. package/src/helpers/documentToLinkField.ts +3 -1
  171. package/src/helpers/isFilled.ts +27 -22
  172. package/src/index.ts +20 -3
  173. package/src/lib/appendFilters.ts +4 -4
  174. package/src/lib/castArray.ts +1 -0
  175. package/src/lib/castThunk.ts +9 -2
  176. package/src/lib/everyTagFilter.ts +2 -2
  177. package/src/lib/findMasterRef.ts +1 -0
  178. package/src/lib/findRef.ts +3 -2
  179. package/src/lib/findRefByID.ts +1 -0
  180. package/src/lib/findRefByLabel.ts +1 -0
  181. package/src/types/api/query.ts +1 -0
  182. package/src/types/api/release.ts +1 -0
  183. package/src/types/api/repository.ts +2 -2
  184. package/src/types/api/tags.ts +1 -0
  185. package/src/types/model/boolean.ts +1 -1
  186. package/src/types/model/color.ts +1 -1
  187. package/src/types/model/contentRelationship.ts +2 -3
  188. package/src/types/model/customType.ts +11 -11
  189. package/src/types/model/date.ts +1 -1
  190. package/src/types/model/embed.ts +1 -1
  191. package/src/types/model/geoPoint.ts +1 -1
  192. package/src/types/model/group.ts +1 -1
  193. package/src/types/model/image.ts +3 -3
  194. package/src/types/model/{integrationFields.ts → integration.ts} +3 -3
  195. package/src/types/model/keyText.ts +1 -1
  196. package/src/types/model/link.ts +4 -6
  197. package/src/types/model/linkToMedia.ts +2 -3
  198. package/src/types/model/number.ts +1 -1
  199. package/src/types/model/richText.ts +3 -3
  200. package/src/types/model/select.ts +1 -1
  201. package/src/types/model/sharedSlice.ts +2 -2
  202. package/src/types/model/sharedSliceVariation.ts +1 -1
  203. package/src/types/model/slice.ts +1 -1
  204. package/src/types/model/sliceZone.ts +2 -2
  205. package/src/types/model/timestamp.ts +1 -1
  206. package/src/types/model/title.ts +1 -1
  207. package/src/types/model/types.ts +10 -6
  208. package/src/types/model/uid.ts +1 -1
  209. package/src/types/value/boolean.ts +1 -1
  210. package/src/types/value/color.ts +2 -1
  211. package/src/types/value/contentRelationship.ts +1 -1
  212. package/src/types/value/date.ts +2 -1
  213. package/src/types/value/document.ts +4 -4
  214. package/src/types/value/embed.ts +2 -1
  215. package/src/types/value/geoPoint.ts +2 -1
  216. package/src/types/value/group.ts +1 -1
  217. package/src/types/value/image.ts +6 -4
  218. package/src/types/value/{integrationFields.ts → integration.ts} +3 -2
  219. package/src/types/value/keyText.ts +2 -1
  220. package/src/types/value/link.ts +2 -2
  221. package/src/types/value/linkToMedia.ts +2 -2
  222. package/src/types/value/number.ts +2 -1
  223. package/src/types/value/richText.ts +26 -26
  224. package/src/types/value/select.ts +2 -1
  225. package/src/types/value/sharedSlice.ts +1 -1
  226. package/src/types/value/sharedSliceVariation.ts +3 -0
  227. package/src/types/value/slice.ts +1 -1
  228. package/src/types/value/timestamp.ts +1 -1
  229. package/src/types/value/title.ts +1 -1
  230. package/src/types/value/types.ts +3 -2
  231. package/src/types/webhook/apiUpdate.ts +1 -1
@@ -5,7 +5,7 @@ import type { DateField } from "./date";
5
5
  import type { EmbedField } from "./embed";
6
6
  import type { GeoPointField } from "./geoPoint";
7
7
  import type { ImageField } from "./image";
8
- import type { IntegrationFields } from "./integrationFields";
8
+ import type { IntegrationField } from "./integration";
9
9
  import type { KeyTextField } from "./keyText";
10
10
  import type { LinkField } from "./link";
11
11
  import type { LinkToMediaField } from "./linkToMedia";
@@ -25,7 +25,7 @@ export type FieldState = "empty" | "filled";
25
25
  /**
26
26
  * Any regular field that can be nested in a group-like field.
27
27
  */
28
- export type AnyRegularField = TitleField | RichTextField | ImageField | ContentRelationshipField | LinkField | LinkToMediaField | EmbedField | DateField | TimestampField | ColorField | NumberField | KeyTextField | SelectField | BooleanField | GeoPointField | IntegrationFields;
28
+ export type AnyRegularField = TitleField | RichTextField | ImageField | ContentRelationshipField | LinkField | LinkToMediaField | EmbedField | DateField | TimestampField | ColorField | NumberField | KeyTextField | SelectField | BooleanField | GeoPointField | IntegrationField;
29
29
  /**
30
30
  * Useful to flatten the type output to improve type hints shown in editors. And
31
31
  * also to transform an interface into a type to aide with assignability.
@@ -33,6 +33,7 @@ export type AnyRegularField = TitleField | RichTextField | ImageField | ContentR
33
33
  * Taken from the `type-fest` package.
34
34
  *
35
35
  * @typeParam T - The type to simplify.
36
+ *
36
37
  * @see https://github.com/sindresorhus/type-fest/blob/cbd7ec510bd136ac045bbc74e391ee686b8a9a2f/source/simplify.d.ts
37
38
  */
38
39
  export type Simplify<T> = {
@@ -22,7 +22,7 @@ interface WebhookBodyAPIUpdateOperations<T> {
22
22
  deletion?: T[];
23
23
  }
24
24
  /**
25
- * Metadata representing a mask (also called a Custom Type).
25
+ * Metadata representing a mask (also called a custom type).
26
26
  *
27
27
  * @see More details: {@link https://prismic.io/docs/custom-types}
28
28
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/client",
3
- "version": "7.0.0-alpha.5",
3
+ "version": "7.0.1-alpha.0",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "typescript",
@@ -43,8 +43,8 @@
43
43
  "prepare": "npm run build",
44
44
  "release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
45
45
  "release:dry": "standard-version --dry-run",
46
- "release:alpha": "npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
47
- "release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run",
46
+ "release:alpha": "npm run test && standard-version --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
47
+ "release:alpha:dry": "standard-version --prerelease alpha --dry-run",
48
48
  "lint": "eslint --ext .js,.ts .",
49
49
  "types": "tsc --noEmit",
50
50
  "unit": "vitest run --coverage",
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@prismicio/mock": "^0.2.0",
61
- "@prismicio/types-internal": "^1.5.3",
61
+ "@prismicio/types-internal": "2.0.0-alpha.11",
62
62
  "@size-limit/preset-small-lib": "^8.2.4",
63
63
  "@trivago/prettier-plugin-sort-imports": "^4.1.1",
64
64
  "@typescript-eslint/eslint-plugin": "^5.59.0",
@@ -53,7 +53,7 @@ export interface Ordering {
53
53
  */
54
54
  export interface Route {
55
55
  /**
56
- * The Custom Type of the document.
56
+ * The custom type of the document.
57
57
  */
58
58
  type: string;
59
59
 
@@ -156,18 +156,18 @@ export interface QueryParams {
156
156
  *
157
157
  * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}
158
158
  *
159
- * @remarks Strings and arrays of strings are deprecated as of
160
- * `@prismicio/client@7.0.0`. Please migrate to the more explicit
161
- * array of objects.
162
- *
159
+ * @remarks
160
+ * Strings and arrays of strings are deprecated as of
161
+ * `@prismicio/client@7.0.0`. Please migrate to the more explicit array of
162
+ * objects.
163
163
  * @example
164
164
  *
165
165
  * ```typescript
166
- * buildQueryURL(endpoint,{
167
- * orderings: [
168
- * { field: "my.product.price", direction: "desc" },
169
- * { field: "my.product.title" },
170
- * ],
166
+ * buildQueryURL(endpoint, {
167
+ * orderings: [
168
+ * { field: "my.product.price", direction: "desc" },
169
+ * { field: "my.product.title" },
170
+ * ],
171
171
  * });
172
172
  * ```
173
173
  */
@@ -184,8 +184,8 @@ export interface QueryParams {
184
184
 
185
185
  /**
186
186
  * The `brokenRoute` option allows you to define the route populated in the
187
- * `url` property for broken Link or Content Relationship fields. A broken
188
- * link is a Link or Content Relationship field whose linked document has been
187
+ * `url` property for broken link or content relationship fields. A broken
188
+ * link is a link or content relationship field whose linked document has been
189
189
  * unpublished or deleted.
190
190
  *
191
191
  * {@link https://prismic.io/docs/route-resolver}
@@ -205,7 +205,7 @@ type BuildQueryURLParams = {
205
205
  ref: string;
206
206
 
207
207
  /**
208
- * Ref used to populate Integration Fields with the latest content.
208
+ * Ref used to populate integration fields with the latest content.
209
209
  *
210
210
  * {@link https://prismic.io/docs/integration-fields}
211
211
  */
@@ -219,7 +219,8 @@ type BuildQueryURLParams = {
219
219
  filters?: string | string[];
220
220
 
221
221
  /**
222
- * @deprecated Renamed to `filters`. Ensure the value is an array of filters, not a single, non-array filter.
222
+ * @deprecated Renamed to `filters`. Ensure the value is an array of filters,
223
+ * not a single, non-array filter.
223
224
  */
224
225
  predicates?: string | string[];
225
226
  };
@@ -106,7 +106,8 @@ export interface RequestInitLike extends Pick<RequestInit, "cache"> {
106
106
  /**
107
107
  * An AbortSignal to set the `fetch()` request's signal.
108
108
  *
109
- * See: \<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\>
109
+ * See:
110
+ * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
110
111
  */
111
112
  // NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`
112
113
  // for backwards compatibility (the type is exported) and to signal to
@@ -216,6 +217,22 @@ type RefStringOrThunk =
216
217
  | string
217
218
  | (() => string | undefined | Promise<string | undefined>);
218
219
 
220
+ /**
221
+ * Options or a function that returns options provided to the client's `fetch()`
222
+ * on all network requests. These options will be merged with internally
223
+ * required options. They can also be overriden on a per-query basis using the
224
+ * query's `fetchOptions` parameter.
225
+ *
226
+ * If the options must be determined on-demand, a function can be provided. This
227
+ * function can be asynchronous.
228
+ */
229
+ export type RequestInitLikeOrThunk =
230
+ | RequestInitLike
231
+ | ((
232
+ url: string,
233
+ init?: RequestInitLike,
234
+ ) => RequestInitLike | undefined | Promise<RequestInitLike | undefined>);
235
+
219
236
  /**
220
237
  * Configuration for clients that determine how content is queried.
221
238
  */
@@ -234,8 +251,8 @@ export type ClientConfig = {
234
251
  ref?: RefStringOrThunk;
235
252
 
236
253
  /**
237
- * A list of Route Resolver objects that define how a document's `url` field
238
- * is resolved.
254
+ * A list of route resolver objects that define how a document's `url`
255
+ * property is resolved.
239
256
  *
240
257
  * {@link https://prismic.io/docs/route-resolver}
241
258
  */
@@ -243,8 +260,8 @@ export type ClientConfig = {
243
260
 
244
261
  /**
245
262
  * The `brokenRoute` option allows you to define the route populated in the
246
- * `url` property for broken Link or Content Relationship fields. A broken
247
- * link is a Link or Content Relationship field whose linked document has been
263
+ * `url` property for broken link or content relationship fields. A broken
264
+ * link is a link or content relationship field whose linked document has been
248
265
  * unpublished or deleted.
249
266
  *
250
267
  * {@link https://prismic.io/docs/route-resolver}
@@ -268,12 +285,17 @@ export type ClientConfig = {
268
285
  fetch?: FetchLike;
269
286
 
270
287
  /**
271
- * Options provided to the client's `fetch()` on all network requests.
272
- * These options will be merged with internally required options. They
273
- * can also be overriden on a per-query basis using the query's
274
- * `fetchOptions` parameter.
288
+ * Options or a function that returns options provided to the client's
289
+ * `fetch()` on all network requests. These options will be merged with
290
+ * internally required options. They can also be overriden on a per-query
291
+ * basis using the query's `fetchOptions` parameter.
292
+ *
293
+ * If the options must be determined on-demand, a function can be provided.
294
+ * This function can be asynchronous.
295
+ *
296
+ * @experimental
275
297
  */
276
- fetchOptions?: RequestInitLike;
298
+ fetchOptions?: RequestInitLikeOrThunk;
277
299
  };
278
300
 
279
301
  /**
@@ -281,26 +303,25 @@ export type ClientConfig = {
281
303
  */
282
304
  type FetchParams = {
283
305
  /**
284
- * Options provided to the client's `fetch()` on all network requests.
285
- * These options will be merged with internally required options. They
286
- * can also be overriden on a per-query basis using the query's
287
- * `fetchOptions` parameter.
306
+ * Options or a function that returns options provided to the client's
307
+ * `fetch()` on all network requests. These options will be merged with
308
+ * internally required options. They can also be overriden on a per-query
309
+ * basis using the query's `fetchOptions` parameter.
310
+ *
311
+ * If the options must be determined on-demand, a function can be provided.
312
+ * This function can be asynchronous.
313
+ *
314
+ * @experimental
288
315
  */
289
- fetchOptions?: RequestInitLike;
316
+ fetchOptions?: RequestInitLikeOrThunk;
290
317
 
291
318
  /**
292
319
  * An `AbortSignal` provided by an `AbortController`. This allows the network
293
320
  * request to be cancelled if necessary.
294
321
  *
295
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
296
- *
297
322
  * @deprecated Move the `signal` parameter into `fetchOptions.signal`:
298
323
  *
299
- * ```typescript
300
- * client.getByUID("page", "home",{
301
- * fetchOptions: { signal }
302
- * });
303
- * ```
324
+ * @see \<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\>
304
325
  */
305
326
  signal?: AbortSignalLike;
306
327
  };
@@ -327,7 +348,7 @@ type ResolvePreviewArgs<LinkResolverReturnType> = {
327
348
  linkResolver?: LinkResolverFunction<LinkResolverReturnType>;
328
349
 
329
350
  /**
330
- * A fallback URL if the Link Resolver does not return a value.
351
+ * A fallback URL if the link resolver does not return a value.
331
352
  */
332
353
  defaultURL: string;
333
354
 
@@ -415,7 +436,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
415
436
  accessToken?: string;
416
437
 
417
438
  /**
418
- * A list of Route Resolver objects that define how a document's `url` field
439
+ * A list of route resolver objects that define how a document's `url` field
419
440
  * is resolved.
420
441
  *
421
442
  * {@link https://prismic.io/docs/route-resolver}
@@ -424,8 +445,8 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
424
445
 
425
446
  /**
426
447
  * The `brokenRoute` option allows you to define the route populated in the
427
- * `url` property for broken Link or Content Relationship fields. A broken
428
- * link is a Link or Content Relationship field whose linked document has been
448
+ * `url` property for broken link or content relationship fields. A broken
449
+ * link is a link or content relationship field whose linked document has been
429
450
  * unpublished or deleted.
430
451
  *
431
452
  * {@link https://prismic.io/docs/route-resolver}
@@ -439,7 +460,18 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
439
460
  */
440
461
  fetchFn: FetchLike;
441
462
 
442
- fetchOptions?: RequestInitLike;
463
+ /**
464
+ * Options or a function that returns options provided to the client's
465
+ * `fetch()` on all network requests. These options will be merged with
466
+ * internally required options. They can also be overriden on a per-query
467
+ * basis using the query's `fetchOptions` parameter.
468
+ *
469
+ * If the options must be determined on-demand, a function can be provided.
470
+ * This function can be asynchronous.
471
+ *
472
+ * @experimental
473
+ */
474
+ fetchOptions?: RequestInitLikeOrThunk;
443
475
 
444
476
  /**
445
477
  * Default parameters that will be sent with each query. These parameters can
@@ -627,6 +659,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
627
659
  * ```
628
660
  *
629
661
  * @typeParam TDocument - Type of Prismic documents returned.
662
+ *
630
663
  * @param params - Parameters to filter, sort, and paginate results.
631
664
  *
632
665
  * @returns A paginated response containing the result of the query.
@@ -650,6 +683,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
650
683
  * ```
651
684
  *
652
685
  * @typeParam TDocument - Type of the Prismic document returned.
686
+ *
653
687
  * @param params - Parameters to filter, sort, and paginate results. @returns
654
688
  * The first result of the query, if any.
655
689
  */
@@ -690,6 +724,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
690
724
  * ```
691
725
  *
692
726
  * @typeParam TDocument - Type of Prismic documents returned.
727
+ *
693
728
  * @param params - Parameters to filter, sort, and paginate results.
694
729
  *
695
730
  * @returns A list of documents matching the query.
@@ -735,7 +770,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
735
770
  * A document's UID is different from its ID. An ID is automatically generated
736
771
  * for all documents and is made available on its `id` property. A UID is
737
772
  * provided in the Prismic editor and is unique among all documents of its
738
- * Custom Type.
773
+ * custom type.
739
774
  * @example
740
775
  *
741
776
  * ```ts
@@ -743,6 +778,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
743
778
  * ```
744
779
  *
745
780
  * @typeParam TDocument- Type of the Prismic document returned.
781
+ *
746
782
  * @param id - ID of the document.
747
783
  * @param params - Parameters to filter, sort, and paginate the results.
748
784
  *
@@ -765,7 +801,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
765
801
  * A document's UID is different from its ID. An ID is automatically generated
766
802
  * for all documents and is made available on its `id` property. A UID is
767
803
  * provided in the Prismic editor and is unique among all documents of its
768
- * Custom Type.
804
+ * custom type.
769
805
  * @example
770
806
  *
771
807
  * ```ts
@@ -776,6 +812,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
776
812
  * ```
777
813
  *
778
814
  * @typeParam TDocument - Type of Prismic documents returned.
815
+ *
779
816
  * @param ids - A list of document IDs.
780
817
  * @param params - Parameters to filter, sort, and paginate the results.
781
818
  *
@@ -801,7 +838,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
801
838
  * A document's UID is different from its ID. An ID is automatically generated
802
839
  * for all documents and is made available on its `id` property. A UID is
803
840
  * provided in the Prismic editor and is unique among all documents of its
804
- * Custom Type.
841
+ * custom type.
805
842
  * @example
806
843
  *
807
844
  * ```ts
@@ -812,6 +849,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
812
849
  * ```
813
850
  *
814
851
  * @typeParam TDocument - Type of Prismic documents returned.
852
+ *
815
853
  * @param ids - A list of document IDs.
816
854
  * @param params - Parameters to filter, sort, and paginate the results.
817
855
  *
@@ -828,13 +866,13 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
828
866
 
829
867
  /**
830
868
  * Queries a document from the Prismic repository with a specific UID and
831
- * Custom Type.
869
+ * custom type.
832
870
  *
833
871
  * @remarks
834
872
  * A document's UID is different from its ID. An ID is automatically generated
835
873
  * for all documents and is made available on its `id` property. A UID is
836
874
  * provided in the Prismic editor and is unique among all documents of its
837
- * Custom Type.
875
+ * custom type.
838
876
  * @example
839
877
  *
840
878
  * ```ts
@@ -842,7 +880,8 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
842
880
  * ```
843
881
  *
844
882
  * @typeParam TDocument - Type of the Prismic document returned.
845
- * @param documentType - The API ID of the document's Custom Type.
883
+ *
884
+ * @param documentType - The API ID of the document's custom type.
846
885
  * @param uid - UID of the document.
847
886
  * @param params - Parameters to filter, sort, and paginate the results.
848
887
  *
@@ -873,7 +912,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
873
912
  * A document's UID is different from its ID. An ID is automatically generated
874
913
  * for all documents and is made available on its `id` property. A UID is
875
914
  * provided in the Prismic editor and is unique among all documents of its
876
- * Custom Type.
915
+ * custom type.
877
916
  * @example
878
917
  *
879
918
  * ```ts
@@ -884,7 +923,8 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
884
923
  * ```
885
924
  *
886
925
  * @typeParam TDocument - Type of the Prismic document returned.
887
- * @param documentType - The API ID of the document's Custom Type.
926
+ *
927
+ * @param documentType - The API ID of the document's custom type.
888
928
  * @param uids - A list of document UIDs.
889
929
  * @param params - Parameters to filter, sort, and paginate the results.
890
930
  *
@@ -909,7 +949,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
909
949
 
910
950
  /**
911
951
  * Queries all documents from the Prismic repository with specific UIDs and
912
- * Custom Type.
952
+ * custom type.
913
953
  *
914
954
  * This method may make multiple network requests to query all matching
915
955
  * content.
@@ -918,7 +958,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
918
958
  * A document's UID is different from its ID. An ID is automatically generated
919
959
  * for all documents and is made available on its `id` property. A UID is
920
960
  * provided in the Prismic editor and is unique among all documents of its
921
- * Custom Type.
961
+ * custom type.
922
962
  * @example
923
963
  *
924
964
  * ```ts
@@ -929,7 +969,8 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
929
969
  * ```
930
970
  *
931
971
  * @typeParam TDocument - Type of Prismic documents returned.
932
- * @param documentType - The API ID of the document's Custom Type.
972
+ *
973
+ * @param documentType - The API ID of the document's custom type.
933
974
  * @param uids - A list of document UIDs.
934
975
  * @param params - Parameters to filter, sort, and paginate the results.
935
976
  *
@@ -955,12 +996,12 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
955
996
 
956
997
  /**
957
998
  * Queries a singleton document from the Prismic repository for a specific
958
- * Custom Type.
999
+ * custom type.
959
1000
  *
960
1001
  * @remarks
961
1002
  * A singleton document is one that is configured in Prismic to only allow one
962
1003
  * instance. For example, a repository may be configured to contain just one
963
- * Settings document. This is in contrast to a repeatable Custom Type which
1004
+ * Settings document. This is in contrast to a repeatable custom type which
964
1005
  * allows multiple instances of itself.
965
1006
  * @example
966
1007
  *
@@ -969,10 +1010,11 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
969
1010
  * ```
970
1011
  *
971
1012
  * @typeParam TDocument - Type of the Prismic document returned.
972
- * @param documentType - The API ID of the singleton Custom Type.
1013
+ *
1014
+ * @param documentType - The API ID of the singleton custom type.
973
1015
  * @param params - Parameters to filter, sort, and paginate the results.
974
1016
  *
975
- * @returns The singleton document for the Custom Type, if a matching document
1017
+ * @returns The singleton document for the custom type, if a matching document
976
1018
  * exists.
977
1019
  */
978
1020
  async getSingle<
@@ -988,10 +1030,10 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
988
1030
  }
989
1031
 
990
1032
  /**
991
- * Queries documents from the Prismic repository for a specific Custom Type.
1033
+ * Queries documents from the Prismic repository for a specific custom type.
992
1034
  *
993
1035
  * Use `getAllByType` instead if you need to query all documents for a
994
- * specific Custom Type.
1036
+ * specific custom type.
995
1037
  *
996
1038
  * @example
997
1039
  *
@@ -1000,10 +1042,11 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1000
1042
  * ```
1001
1043
  *
1002
1044
  * @typeParam TDocument - Type of Prismic documents returned.
1003
- * @param documentType - The API ID of the Custom Type.
1045
+ *
1046
+ * @param documentType - The API ID of the custom type.
1004
1047
  * @param params - Parameters to filter, sort, and paginate the results.
1005
1048
  *
1006
- * @returns A paginated response containing documents of the Custom Type.
1049
+ * @returns A paginated response containing documents of the custom type.
1007
1050
  */
1008
1051
  async getByType<
1009
1052
  TDocument extends TDocuments,
@@ -1031,10 +1074,11 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1031
1074
  * ```
1032
1075
  *
1033
1076
  * @typeParam TDocument - Type of Prismic documents returned.
1034
- * @param documentType - The API ID of the Custom Type.
1077
+ *
1078
+ * @param documentType - The API ID of the custom type.
1035
1079
  * @param params - Parameters to filter, sort, and paginate the results.
1036
1080
  *
1037
- * @returns A list of all documents of the Custom Type.
1081
+ * @returns A list of all documents of the custom type.
1038
1082
  */
1039
1083
  async getAllByType<
1040
1084
  TDocument extends TDocuments,
@@ -1063,6 +1107,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1063
1107
  * ```
1064
1108
  *
1065
1109
  * @typeParam TDocument - Type of Prismic documents returned.
1110
+ *
1066
1111
  * @param tag - The tag that must be included on a document.
1067
1112
  * @param params - Parameters to filter, sort, and paginate the results.
1068
1113
  *
@@ -1090,6 +1135,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1090
1135
  * ```
1091
1136
  *
1092
1137
  * @typeParam TDocument - Type of Prismic documents returned.
1138
+ *
1093
1139
  * @param tag - The tag that must be included on a document.
1094
1140
  * @param params - Parameters to filter, sort, and paginate the results.
1095
1141
  *
@@ -1117,6 +1163,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1117
1163
  * ```
1118
1164
  *
1119
1165
  * @typeParam TDocument - Type of Prismic documents returned.
1166
+ *
1120
1167
  * @param tags - A list of tags that must be included on a document.
1121
1168
  * @param params - Parameters to filter, sort, and paginate the results.
1122
1169
  *
@@ -1145,6 +1192,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1145
1192
  * ```
1146
1193
  *
1147
1194
  * @typeParam TDocument - Type of Prismic documents returned.
1195
+ *
1148
1196
  * @param tags - A list of tags that must be included on a document.
1149
1197
  * @param params - Parameters to filter, sort, and paginate the results.
1150
1198
  *
@@ -1173,6 +1221,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1173
1221
  * ```
1174
1222
  *
1175
1223
  * @typeParam TDocument - Type of Prismic documents returned.
1224
+ *
1176
1225
  * @param tags - A list of tags that must be included on a document.
1177
1226
  * @param params - Parameters to filter, sort, and paginate the results.
1178
1227
  *
@@ -1203,6 +1252,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1203
1252
  * ```
1204
1253
  *
1205
1254
  * @typeParam TDocument - Type of Prismic documents returned.
1255
+ *
1206
1256
  * @param tags - A list of tags that must be included on a document.
1207
1257
  * @param params - Parameters to filter, sort, and paginate the results.
1208
1258
  *
@@ -1573,6 +1623,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1573
1623
  * supported.
1574
1624
  *
1575
1625
  * @returns The `fetch()` Response for the request.
1626
+ *
1576
1627
  * @experimental
1577
1628
  */
1578
1629
  async graphQLFetch(
@@ -1667,6 +1718,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1667
1718
  * @param name - Name of the form.
1668
1719
  *
1669
1720
  * @returns The repository form.
1721
+ *
1670
1722
  * @throws If a matching form cannot be found.
1671
1723
  */
1672
1724
  private async getCachedRepositoryForm(
@@ -1765,6 +1817,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1765
1817
  * normalizes unsuccessful network requests.
1766
1818
  *
1767
1819
  * @typeParam T - The JSON response.
1820
+ *
1768
1821
  * @param url - URL to the resource to fetch.
1769
1822
  * @param params - Prismic REST API parameters for the network request.
1770
1823
  *
@@ -1774,17 +1827,21 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1774
1827
  url: string,
1775
1828
  params: FetchParams = {},
1776
1829
  ): Promise<T> {
1830
+ const paramsFetchOptions = await castThunk(params.fetchOptions)(url);
1831
+ const thisFetchOptions = await castThunk(this.fetchOptions)(
1832
+ url,
1833
+ paramsFetchOptions,
1834
+ );
1835
+
1777
1836
  const requestInit: RequestInitLike = {
1778
- ...this.fetchOptions,
1779
- ...params.fetchOptions,
1837
+ ...paramsFetchOptions,
1838
+ ...thisFetchOptions,
1780
1839
  headers: {
1781
- ...this.fetchOptions?.headers,
1782
- ...params.fetchOptions?.headers,
1840
+ ...paramsFetchOptions?.headers,
1841
+ ...thisFetchOptions?.headers,
1783
1842
  },
1784
1843
  signal:
1785
- params.fetchOptions?.signal ||
1786
- params.signal ||
1787
- this.fetchOptions?.signal,
1844
+ paramsFetchOptions?.signal || params.signal || thisFetchOptions?.signal,
1788
1845
  };
1789
1846
 
1790
1847
  let job: Promise<FetchJobResult>;