@prismicio/client 7.21.0-canary.bd2c015 → 7.21.0-pr.315.0b13c69

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 (217) hide show
  1. package/dist/Client.cjs +190 -258
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.cts +93 -156
  4. package/dist/Client.d.cts.map +1 -1
  5. package/dist/Client.d.ts +93 -156
  6. package/dist/Client.d.ts.map +1 -1
  7. package/dist/Client.js +187 -255
  8. package/dist/Client.js.map +1 -1
  9. package/dist/WriteClient.cjs +19 -19
  10. package/dist/WriteClient.cjs.map +1 -1
  11. package/dist/WriteClient.d.cts.map +1 -1
  12. package/dist/WriteClient.d.ts.map +1 -1
  13. package/dist/WriteClient.js +9 -9
  14. package/dist/WriteClient.js.map +1 -1
  15. package/dist/buildQueryURL.cjs +9 -9
  16. package/dist/buildQueryURL.cjs.map +1 -1
  17. package/dist/buildQueryURL.d.cts +4 -12
  18. package/dist/buildQueryURL.d.cts.map +1 -1
  19. package/dist/buildQueryURL.d.ts +4 -12
  20. package/dist/buildQueryURL.d.ts.map +1 -1
  21. package/dist/buildQueryURL.js +4 -4
  22. package/dist/buildQueryURL.js.map +1 -1
  23. package/dist/errors.cjs +31 -0
  24. package/dist/errors.cjs.map +1 -0
  25. package/dist/errors.d.cts +46 -0
  26. package/dist/errors.d.cts.map +1 -0
  27. package/dist/errors.d.ts +46 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +22 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/filter.cjs +1 -1
  32. package/dist/filter.cjs.map +1 -1
  33. package/dist/filter.js +1 -1
  34. package/dist/filter.js.map +1 -1
  35. package/dist/getGraphQLEndpoint.cjs +2 -2
  36. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  37. package/dist/getGraphQLEndpoint.js +1 -1
  38. package/dist/getGraphQLEndpoint.js.map +1 -1
  39. package/dist/getRepositoryEndpoint.cjs +2 -2
  40. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  41. package/dist/getRepositoryEndpoint.js +1 -1
  42. package/dist/getRepositoryEndpoint.js.map +1 -1
  43. package/dist/getRepositoryName.cjs +2 -2
  44. package/dist/getRepositoryName.cjs.map +1 -1
  45. package/dist/getRepositoryName.js +1 -1
  46. package/dist/getRepositoryName.js.map +1 -1
  47. package/dist/getToolbarSrc.cjs +2 -2
  48. package/dist/getToolbarSrc.cjs.map +1 -1
  49. package/dist/getToolbarSrc.js +1 -1
  50. package/dist/getToolbarSrc.js.map +1 -1
  51. package/dist/index.cjs +10 -18
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +1 -9
  54. package/dist/index.d.cts.map +1 -1
  55. package/dist/index.d.ts +1 -9
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +1 -9
  58. package/dist/index.js.map +1 -1
  59. package/dist/lib/{throttledLog.js → throttledWarn.cjs} +7 -7
  60. package/dist/lib/throttledWarn.cjs.map +1 -0
  61. package/dist/lib/{throttledLog.cjs → throttledWarn.js} +6 -8
  62. package/dist/lib/throttledWarn.js.map +1 -0
  63. package/dist/lib/validateAssetMetadata.cjs +2 -2
  64. package/dist/lib/validateAssetMetadata.cjs.map +1 -1
  65. package/dist/lib/validateAssetMetadata.js +1 -1
  66. package/dist/lib/validateAssetMetadata.js.map +1 -1
  67. package/dist/package.cjs +1 -1
  68. package/dist/package.cjs.map +1 -1
  69. package/dist/package.js +1 -1
  70. package/dist/package.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/Client.ts +430 -514
  73. package/src/WriteClient.ts +16 -10
  74. package/src/buildQueryURL.ts +10 -19
  75. package/src/errors.ts +94 -0
  76. package/src/filter.ts +1 -1
  77. package/src/getGraphQLEndpoint.ts +1 -1
  78. package/src/getRepositoryEndpoint.ts +1 -1
  79. package/src/getRepositoryName.ts +1 -1
  80. package/src/getToolbarSrc.ts +1 -1
  81. package/src/index.ts +11 -9
  82. package/src/lib/{throttledLog.ts → throttledWarn.ts} +3 -13
  83. package/src/lib/validateAssetMetadata.ts +1 -1
  84. package/dist/errors/ForbiddenError.cjs +0 -8
  85. package/dist/errors/ForbiddenError.cjs.map +0 -1
  86. package/dist/errors/ForbiddenError.d.cts +0 -14
  87. package/dist/errors/ForbiddenError.d.cts.map +0 -1
  88. package/dist/errors/ForbiddenError.d.ts +0 -14
  89. package/dist/errors/ForbiddenError.d.ts.map +0 -1
  90. package/dist/errors/ForbiddenError.js +0 -8
  91. package/dist/errors/ForbiddenError.js.map +0 -1
  92. package/dist/errors/InvalidDataError.cjs +0 -8
  93. package/dist/errors/InvalidDataError.cjs.map +0 -1
  94. package/dist/errors/InvalidDataError.d.cts +0 -7
  95. package/dist/errors/InvalidDataError.d.cts.map +0 -1
  96. package/dist/errors/InvalidDataError.d.ts +0 -7
  97. package/dist/errors/InvalidDataError.d.ts.map +0 -1
  98. package/dist/errors/InvalidDataError.js +0 -8
  99. package/dist/errors/InvalidDataError.js.map +0 -1
  100. package/dist/errors/NotFoundError.cjs +0 -8
  101. package/dist/errors/NotFoundError.cjs.map +0 -1
  102. package/dist/errors/NotFoundError.d.cts +0 -7
  103. package/dist/errors/NotFoundError.d.cts.map +0 -1
  104. package/dist/errors/NotFoundError.d.ts +0 -7
  105. package/dist/errors/NotFoundError.d.ts.map +0 -1
  106. package/dist/errors/NotFoundError.js +0 -8
  107. package/dist/errors/NotFoundError.js.map +0 -1
  108. package/dist/errors/ParsingError.cjs +0 -8
  109. package/dist/errors/ParsingError.cjs.map +0 -1
  110. package/dist/errors/ParsingError.d.cts +0 -17
  111. package/dist/errors/ParsingError.d.cts.map +0 -1
  112. package/dist/errors/ParsingError.d.ts +0 -17
  113. package/dist/errors/ParsingError.d.ts.map +0 -1
  114. package/dist/errors/ParsingError.js +0 -8
  115. package/dist/errors/ParsingError.js.map +0 -1
  116. package/dist/errors/PreviewTokenExpired.cjs +0 -8
  117. package/dist/errors/PreviewTokenExpired.cjs.map +0 -1
  118. package/dist/errors/PreviewTokenExpired.d.cts +0 -11
  119. package/dist/errors/PreviewTokenExpired.d.cts.map +0 -1
  120. package/dist/errors/PreviewTokenExpired.d.ts +0 -11
  121. package/dist/errors/PreviewTokenExpired.d.ts.map +0 -1
  122. package/dist/errors/PreviewTokenExpired.js +0 -8
  123. package/dist/errors/PreviewTokenExpired.js.map +0 -1
  124. package/dist/errors/PrismicError.cjs +0 -15
  125. package/dist/errors/PrismicError.cjs.map +0 -1
  126. package/dist/errors/PrismicError.d.cts +0 -9
  127. package/dist/errors/PrismicError.d.cts.map +0 -1
  128. package/dist/errors/PrismicError.d.ts +0 -9
  129. package/dist/errors/PrismicError.d.ts.map +0 -1
  130. package/dist/errors/PrismicError.js +0 -14
  131. package/dist/errors/PrismicError.js.map +0 -1
  132. package/dist/errors/RefExpiredError.cjs +0 -8
  133. package/dist/errors/RefExpiredError.cjs.map +0 -1
  134. package/dist/errors/RefExpiredError.d.cts +0 -11
  135. package/dist/errors/RefExpiredError.d.cts.map +0 -1
  136. package/dist/errors/RefExpiredError.d.ts +0 -11
  137. package/dist/errors/RefExpiredError.d.ts.map +0 -1
  138. package/dist/errors/RefExpiredError.js +0 -8
  139. package/dist/errors/RefExpiredError.js.map +0 -1
  140. package/dist/errors/RefNotFoundError.cjs +0 -8
  141. package/dist/errors/RefNotFoundError.cjs.map +0 -1
  142. package/dist/errors/RefNotFoundError.d.cts +0 -11
  143. package/dist/errors/RefNotFoundError.d.cts.map +0 -1
  144. package/dist/errors/RefNotFoundError.d.ts +0 -11
  145. package/dist/errors/RefNotFoundError.d.ts.map +0 -1
  146. package/dist/errors/RefNotFoundError.js +0 -8
  147. package/dist/errors/RefNotFoundError.js.map +0 -1
  148. package/dist/errors/RepositoryNotFoundError.cjs +0 -8
  149. package/dist/errors/RepositoryNotFoundError.cjs.map +0 -1
  150. package/dist/errors/RepositoryNotFoundError.d.cts +0 -7
  151. package/dist/errors/RepositoryNotFoundError.d.cts.map +0 -1
  152. package/dist/errors/RepositoryNotFoundError.d.ts +0 -7
  153. package/dist/errors/RepositoryNotFoundError.d.ts.map +0 -1
  154. package/dist/errors/RepositoryNotFoundError.js +0 -8
  155. package/dist/errors/RepositoryNotFoundError.js.map +0 -1
  156. package/dist/lib/appendFilters.cjs +0 -24
  157. package/dist/lib/appendFilters.cjs.map +0 -1
  158. package/dist/lib/appendFilters.js +0 -24
  159. package/dist/lib/appendFilters.js.map +0 -1
  160. package/dist/lib/castArray.cjs +0 -20
  161. package/dist/lib/castArray.cjs.map +0 -1
  162. package/dist/lib/castArray.js +0 -19
  163. package/dist/lib/castArray.js.map +0 -1
  164. package/dist/lib/everyTagFilter.cjs +0 -19
  165. package/dist/lib/everyTagFilter.cjs.map +0 -1
  166. package/dist/lib/everyTagFilter.js +0 -19
  167. package/dist/lib/everyTagFilter.js.map +0 -1
  168. package/dist/lib/findMasterRef.cjs +0 -19
  169. package/dist/lib/findMasterRef.cjs.map +0 -1
  170. package/dist/lib/findMasterRef.js +0 -19
  171. package/dist/lib/findMasterRef.js.map +0 -1
  172. package/dist/lib/findRef.cjs +0 -24
  173. package/dist/lib/findRef.cjs.map +0 -1
  174. package/dist/lib/findRef.js +0 -24
  175. package/dist/lib/findRef.js.map +0 -1
  176. package/dist/lib/findRefByID.cjs +0 -20
  177. package/dist/lib/findRefByID.cjs.map +0 -1
  178. package/dist/lib/findRefByID.js +0 -20
  179. package/dist/lib/findRefByID.js.map +0 -1
  180. package/dist/lib/findRefByLabel.cjs +0 -20
  181. package/dist/lib/findRefByLabel.cjs.map +0 -1
  182. package/dist/lib/findRefByLabel.js +0 -20
  183. package/dist/lib/findRefByLabel.js.map +0 -1
  184. package/dist/lib/minifyGraphQLQuery.cjs +0 -16
  185. package/dist/lib/minifyGraphQLQuery.cjs.map +0 -1
  186. package/dist/lib/minifyGraphQLQuery.js +0 -15
  187. package/dist/lib/minifyGraphQLQuery.js.map +0 -1
  188. package/dist/lib/someTagsFilter.cjs +0 -19
  189. package/dist/lib/someTagsFilter.cjs.map +0 -1
  190. package/dist/lib/someTagsFilter.js +0 -19
  191. package/dist/lib/someTagsFilter.js.map +0 -1
  192. package/dist/lib/throttledLog.cjs.map +0 -1
  193. package/dist/lib/throttledLog.js.map +0 -1
  194. package/dist/lib/typeFilter.cjs +0 -17
  195. package/dist/lib/typeFilter.cjs.map +0 -1
  196. package/dist/lib/typeFilter.js +0 -17
  197. package/dist/lib/typeFilter.js.map +0 -1
  198. package/src/errors/ForbiddenError.ts +0 -16
  199. package/src/errors/InvalidDataError.ts +0 -5
  200. package/src/errors/NotFoundError.ts +0 -5
  201. package/src/errors/ParsingError.ts +0 -16
  202. package/src/errors/PreviewTokenExpired.ts +0 -12
  203. package/src/errors/PrismicError.ts +0 -15
  204. package/src/errors/RefExpiredError.ts +0 -14
  205. package/src/errors/RefNotFoundError.ts +0 -14
  206. package/src/errors/RepositoryNotFoundError.ts +0 -5
  207. package/src/lib/appendFilters.ts +0 -26
  208. package/src/lib/castArray.ts +0 -14
  209. package/src/lib/castThunk.ts +0 -13
  210. package/src/lib/everyTagFilter.ts +0 -15
  211. package/src/lib/findMasterRef.ts +0 -16
  212. package/src/lib/findRef.ts +0 -25
  213. package/src/lib/findRefByID.ts +0 -17
  214. package/src/lib/findRefByLabel.ts +0 -17
  215. package/src/lib/minifyGraphQLQuery.ts +0 -13
  216. package/src/lib/someTagsFilter.ts +0 -15
  217. package/src/lib/typeFilter.ts +0 -12
package/dist/Client.cjs CHANGED
@@ -1,24 +1,9 @@
1
1
  const require_filter = require('./filter.cjs');
2
- const require_appendFilters = require('./lib/appendFilters.cjs');
3
2
  const require_devMsg = require('./lib/devMsg.cjs');
4
- const require_everyTagFilter = require('./lib/everyTagFilter.cjs');
5
- const require_PrismicError = require('./errors/PrismicError.cjs');
6
- const require_findMasterRef = require('./lib/findMasterRef.cjs');
7
- const require_findRefByID = require('./lib/findRefByID.cjs');
8
- const require_findRefByLabel = require('./lib/findRefByLabel.cjs');
9
3
  const require_getPreviewCookie = require('./lib/getPreviewCookie.cjs');
10
- const require_minifyGraphQLQuery = require('./lib/minifyGraphQLQuery.cjs');
11
4
  const require_request = require('./lib/request.cjs');
12
- const require_someTagsFilter = require('./lib/someTagsFilter.cjs');
13
- const require_throttledLog = require('./lib/throttledLog.cjs');
14
- const require_typeFilter = require('./lib/typeFilter.cjs');
15
- const require_ForbiddenError = require('./errors/ForbiddenError.cjs');
16
- const require_NotFoundError = require('./errors/NotFoundError.cjs');
17
- const require_ParsingError = require('./errors/ParsingError.cjs');
18
- const require_PreviewTokenExpired = require('./errors/PreviewTokenExpired.cjs');
19
- const require_RefExpiredError = require('./errors/RefExpiredError.cjs');
20
- const require_RefNotFoundError = require('./errors/RefNotFoundError.cjs');
21
- const require_RepositoryNotFoundError = require('./errors/RepositoryNotFoundError.cjs');
5
+ const require_throttledWarn = require('./lib/throttledWarn.cjs');
6
+ const require_errors = require('./errors.cjs');
22
7
  const require_asLink = require('./helpers/asLink.cjs');
23
8
  const require_buildQueryURL = require('./buildQueryURL.cjs');
24
9
  const require_getRepositoryEndpoint = require('./getRepositoryEndpoint.cjs');
@@ -26,164 +11,123 @@ const require_getRepositoryName = require('./getRepositoryName.cjs');
26
11
  const require_isRepositoryEndpoint = require('./isRepositoryEndpoint.cjs');
27
12
 
28
13
  //#region src/Client.ts
29
- /**
30
- * The largest page size allowed by the Prismic REST API V2. This value is used
31
- * to minimize the number of requests required to query content.
32
- */
33
14
  const MAX_PAGE_SIZE = 100;
34
- /**
35
- * The number of milliseconds in which repository metadata is considered valid.
36
- * A ref can be invalidated quickly depending on how frequently content is
37
- * updated in the Prismic repository. As such, repository's metadata can only be
38
- * considered valid for a short amount of time.
39
- */
40
15
  const REPOSITORY_CACHE_TTL = 5e3;
41
- /**
42
- * The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,
43
- * `getAllByType`, `getAllByTag`) will wait between individual page requests.
44
- *
45
- * This is done to ensure API performance is sustainable and reduces the chance
46
- * of a failed API request due to overloading.
47
- */
48
16
  const GET_ALL_QUERY_DELAY = 500;
49
- /**
50
- * The maximum number of attempts to retry a query with an invalid ref. We allow
51
- * multiple attempts since each attempt may use a different (and possibly
52
- * invalid) ref. Capping the number of attempts prevents infinite loops.
53
- */
54
17
  const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
55
18
  /**
56
- * A client that allows querying content from a Prismic repository.
19
+ * A client for fetching content from a Prismic repository.
57
20
  *
58
- * If used in an environment where a global `fetch` function is unavailable,
59
- * such as Node.js, the `fetch` option must be provided as part of the `options`
60
- * parameter.
61
- *
62
- * @typeParam TDocuments - Document types that are registered for the Prismic
63
- * repository. Query methods will automatically be typed based on this type.
21
+ * @see {@link https://prismic.io/docs/fetch-content}
22
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
64
23
  */
65
24
  var Client = class {
66
25
  /**
67
- * The function used to make network requests to the Prismic REST API. In
68
- * environments where a global `fetch` function does not exist, such as
69
- * Node.js, this function must be provided.
70
- */
71
- fetchFn;
72
- fetchOptions;
73
- #repositoryName;
74
- /**
75
- * The Prismic repository's name.
76
- */
77
- set repositoryName(value) {
78
- this.#repositoryName = value;
79
- }
80
- /**
81
- * The Prismic repository's name.
82
- */
83
- get repositoryName() {
84
- if (!this.#repositoryName) throw new require_PrismicError.PrismicError(`A repository name is required for this method but one could not be inferred from the provided API endpoint (\`${this.documentAPIEndpoint}\`). To fix this error, provide a repository name when creating the client. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`, void 0, void 0);
85
- return this.#repositoryName;
86
- }
87
- /**
88
- * The Prismic REST API V2 endpoint for the repository (use
89
- * `prismic.getRepositoryEndpoint` for the default endpoint).
26
+ * The client's Content API endpoint.
27
+ *
28
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
90
29
  */
91
30
  documentAPIEndpoint;
92
31
  /**
93
- * The Prismic REST API V2 endpoint for the repository (use
94
- * `prismic.getRepositoryEndpoint` for the default endpoint).
32
+ * The secure token used for the Content API.
95
33
  *
96
- * @deprecated Use `documentAPIEndpoint` instead.
34
+ * @see {@link https://prismic.io/docs/fetch-content#content-visibility}
97
35
  */
98
- set endpoint(value) {
99
- this.documentAPIEndpoint = value;
100
- }
36
+ accessToken;
101
37
  /**
102
- * The Prismic REST API V2 endpoint for the repository (use
103
- * `prismic.getRepositoryEndpoint` for the default endpoint).
38
+ * A list of route resolver objects that define how a document's `url`
39
+ * property is resolved.
104
40
  *
105
- * @deprecated Use `documentAPIEndpoint` instead.
41
+ * @see {@link https://prismic.io/docs/routes}
42
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
106
43
  */
107
- get endpoint() {
108
- return this.documentAPIEndpoint;
109
- }
44
+ routes;
110
45
  /**
111
- * The secure token for accessing the API (only needed if your repository is
112
- * set to private).
46
+ * The URL used for link or content relationship fields that point to an
47
+ * archived or deleted page.
113
48
  *
114
- * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
49
+ * @see {@link https://prismic.io/docs/routes}
50
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
115
51
  */
116
- accessToken;
52
+ brokenRoute;
117
53
  /**
118
- * A list of route resolver objects that define how a document's `url` field
119
- * is resolved.
54
+ * Default parameters sent with each Content API request. These parameters can
55
+ * be overridden on each method.
120
56
  *
121
- * {@link https://prismic.io/docs/route-resolver}
57
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
122
58
  */
123
- routes;
59
+ defaultParams;
124
60
  /**
125
- * The `brokenRoute` option allows you to define the route populated in the
126
- * `url` property for broken link or content relationship fields. A broken
127
- * link is a link or content relationship field whose linked document has been
128
- * unpublished or deleted.
61
+ * The `fetch` function used to make network requests.
129
62
  *
130
- * {@link https://prismic.io/docs/route-resolver}
63
+ * @default The global `fetch` function.
64
+ *
65
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
131
66
  */
132
- brokenRoute;
67
+ fetchFn;
133
68
  /**
134
- * Default parameters that will be sent with each query. These parameters can
135
- * be overridden on each query if needed.
69
+ * The default `fetch` options sent with each Content API request. These
70
+ * parameters can be overriden on each method.
71
+ *
72
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
136
73
  */
137
- defaultParams;
74
+ fetchOptions;
75
+ #repositoryName;
138
76
  #getRef;
139
77
  #autoPreviews = true;
140
78
  #autoPreviewsRequest;
141
79
  #cachedRepository;
142
80
  #cachedRepositoryExpiration = 0;
143
81
  /**
144
- * Creates a Prismic client that can be used to query a repository.
145
- *
146
- * If used in an environment where a global `fetch` function is unavailable,
147
- * such as in some Node.js versions, the `fetch` option must be provided as
148
- * part of the `options` parameter.
149
- *
150
- * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
151
- * API V2 endpoint for the repository.
152
- * @param options - Configuration that determines how content will be queried
153
- * from the Prismic repository.
154
- *
155
- * @returns A client that can query content from the repository.
156
- */
157
- constructor(repositoryNameOrEndpoint, options = {}) {
158
- this.fetchOptions = options.fetchOptions;
159
- if (typeof options.fetch === "function") this.fetchFn = options.fetch;
160
- else if (typeof globalThis.fetch === "function") this.fetchFn = globalThis.fetch;
161
- else throw new require_PrismicError.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
162
- if (this.fetchFn === globalThis.fetch) this.fetchFn = this.fetchFn.bind(globalThis);
163
- if ((options.documentAPIEndpoint || require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) && process.env.NODE_ENV === "development") {
164
- const documentAPIEndpoint = options.documentAPIEndpoint || repositoryNameOrEndpoint;
165
- if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(documentAPIEndpoint)) throw new require_PrismicError.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);
166
- const hostname = new URL(documentAPIEndpoint).hostname.toLowerCase();
167
- if (hostname.endsWith(".prismic.io") && !hostname.endsWith(".cdn.prismic.io")) console.warn(`[@prismicio/client] The client was created with a non-CDN endpoint. Convert it to the CDN endpoint for better performance. For more details, see ${require_devMsg.devMsg("endpoint-must-use-cdn")}`);
168
- if (options.documentAPIEndpoint && require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint) && repositoryNameOrEndpoint !== options.documentAPIEndpoint) console.warn(`[@prismicio/client] Multiple incompatible endpoints were provided. Create the client using a repository name to prevent this error. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`);
169
- }
82
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full
83
+ * Content API endpoint for the repository.
84
+ * @param config - Client configuration.
85
+ */
86
+ constructor(repositoryNameOrEndpoint, config = {}) {
87
+ var _globalThis$fetch;
88
+ const { documentAPIEndpoint, accessToken, ref, routes, brokenRoute, defaultParams, fetchOptions = {}, fetch = (_globalThis$fetch = globalThis.fetch) === null || _globalThis$fetch === void 0 ? void 0 : _globalThis$fetch.bind(globalThis) } = config;
170
89
  if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
171
- this.documentAPIEndpoint = repositoryNameOrEndpoint;
172
90
  try {
173
91
  this.repositoryName = require_getRepositoryName.getRepositoryName(repositoryNameOrEndpoint);
174
92
  } catch {
175
93
  console.warn(`[@prismicio/client] A repository name could not be inferred from the provided endpoint (\`${repositoryNameOrEndpoint}\`). Some methods will be disabled. Create the client using a repository name to prevent this warning. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`);
176
94
  }
95
+ this.documentAPIEndpoint = documentAPIEndpoint || repositoryNameOrEndpoint;
177
96
  } else {
178
- this.documentAPIEndpoint = options.documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
179
97
  this.repositoryName = repositoryNameOrEndpoint;
98
+ this.documentAPIEndpoint = documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
180
99
  }
181
- this.accessToken = options.accessToken;
182
- this.routes = options.routes;
183
- this.brokenRoute = options.brokenRoute;
184
- this.defaultParams = options.defaultParams;
185
- if (options.ref) this.queryContentFromRef(options.ref);
100
+ if (!fetch) throw new require_errors.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available, a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
101
+ if (typeof fetch !== "function") throw new require_errors.PrismicError(`fetch must be a function, but received: ${typeof fetch}`, void 0, void 0);
102
+ if (!require_isRepositoryEndpoint.isRepositoryEndpoint(this.documentAPIEndpoint)) throw new require_errors.PrismicError(`documentAPIEndpoint is not a valid URL: ${documentAPIEndpoint}`, void 0, void 0);
103
+ if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint) && documentAPIEndpoint && repositoryNameOrEndpoint !== documentAPIEndpoint) console.warn(`[@prismicio/client] Multiple incompatible endpoints were provided. Create the client using a repository name to prevent this error. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`);
104
+ if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(this.documentAPIEndpoint) && process.env.NODE_ENV === "development") throw new require_errors.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);
105
+ if (/(?<!\.cdn)\.prismic\.io$/i.test(new URL(this.documentAPIEndpoint).hostname) && process.env.NODE_ENV === "development") console.warn(`[@prismicio/client] The client was created with a non-CDN endpoint. Convert it to the CDN endpoint for better performance. For more details, see ${require_devMsg.devMsg("endpoint-must-use-cdn")}`);
106
+ this.accessToken = accessToken;
107
+ this.routes = routes;
108
+ this.brokenRoute = brokenRoute;
109
+ this.defaultParams = defaultParams;
110
+ this.fetchOptions = fetchOptions;
111
+ this.fetchFn = fetch;
186
112
  this.graphQLFetch = this.graphQLFetch.bind(this);
113
+ if (ref) this.queryContentFromRef(ref);
114
+ }
115
+ /** The Prismic repository's name. */
116
+ set repositoryName(value) {
117
+ this.#repositoryName = value;
118
+ }
119
+ /** The Prismic repository's name. */
120
+ get repositoryName() {
121
+ if (!this.#repositoryName) throw new require_errors.PrismicError(`A repository name is required for this method but one could not be inferred from the provided API endpoint (\`${this.documentAPIEndpoint}\`). To fix this error, provide a repository name when creating the client. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`, void 0, void 0);
122
+ return this.#repositoryName;
123
+ }
124
+ /** @deprecated Replace with `documentAPIEndpoint`. */
125
+ set endpoint(value) {
126
+ this.documentAPIEndpoint = value;
127
+ }
128
+ /** @deprecated Replace with `documentAPIEndpoint`. */
129
+ get endpoint() {
130
+ return this.documentAPIEndpoint;
187
131
  }
188
132
  /**
189
133
  * Enables the client to automatically query content from a preview session.
@@ -243,8 +187,7 @@ var Client = class {
243
187
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
244
188
  */
245
189
  async get(params) {
246
- const { data } = await this._get(params);
247
- return data;
190
+ return await (await this.#internalGet(params)).json();
248
191
  }
249
192
  /**
250
193
  * Fetches the first page returned based on the `params` argument.
@@ -258,15 +201,14 @@ var Client = class {
258
201
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
259
202
  */
260
203
  async getFirst(params) {
261
- const actualParams = { ...params };
262
- if (!(params && params.page) && !(params === null || params === void 0 ? void 0 : params.pageSize)) {
263
- var _this$defaultParams;
264
- actualParams.pageSize = ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) ?? 1;
265
- }
266
- const { data, url } = await this._get(actualParams);
267
- const firstResult = data.results[0];
268
- if (firstResult) return firstResult;
269
- throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
204
+ const actualParams = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params.pageSize) ? params : {
205
+ ...params,
206
+ pageSize: 1
207
+ };
208
+ const response = await this.#internalGet(actualParams);
209
+ const { results } = await response.clone().json();
210
+ if (results[0]) return results[0];
211
+ throw new require_errors.NotFoundError("No documents were returned", response.url, void 0);
270
212
  }
271
213
  /**
272
214
  * Fetches all pages based on the `params` argument. This method may make
@@ -281,11 +223,11 @@ var Client = class {
281
223
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
282
224
  */
283
225
  async dangerouslyGetAll(params = {}) {
284
- var _this$defaultParams2;
226
+ var _this$defaultParams;
285
227
  const { limit = Infinity,...actualParams } = params;
286
228
  const resolvedParams = {
287
229
  ...actualParams,
288
- pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams2 = this.defaultParams) === null || _this$defaultParams2 === void 0 ? void 0 : _this$defaultParams2.pageSize) || MAX_PAGE_SIZE)
230
+ pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) || MAX_PAGE_SIZE)
289
231
  };
290
232
  const documents = [];
291
233
  let latestResult;
@@ -312,7 +254,7 @@ var Client = class {
312
254
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
313
255
  */
314
256
  async getByID(id, params) {
315
- return await this.getFirst(require_appendFilters.appendFilters(params, require_filter.filter.at("document.id", id)));
257
+ return await this.getFirst(appendFilters(params, require_filter.filter.at("document.id", id)));
316
258
  }
317
259
  /**
318
260
  * Fetches pages with specific IDs. Results are paginated.
@@ -329,7 +271,7 @@ var Client = class {
329
271
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
330
272
  */
331
273
  async getByIDs(ids, params) {
332
- return await this.get(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
274
+ return await this.get(appendFilters(params, require_filter.filter.in("document.id", ids)));
333
275
  }
334
276
  /**
335
277
  * Fetches pages with specific IDs. This method may make multiple network
@@ -347,7 +289,7 @@ var Client = class {
347
289
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
348
290
  */
349
291
  async getAllByIDs(ids, params) {
350
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
292
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.in("document.id", ids)));
351
293
  }
352
294
  /**
353
295
  * Fetches a page with a specific UID and type.
@@ -361,7 +303,7 @@ var Client = class {
361
303
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
362
304
  */
363
305
  async getByUID(documentType, uid, params) {
364
- return await this.getFirst(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)]));
306
+ return await this.getFirst(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)));
365
307
  }
366
308
  /**
367
309
  * Fetches pages with specific UIDs and a specific type. Results are
@@ -379,7 +321,7 @@ var Client = class {
379
321
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
380
322
  */
381
323
  async getByUIDs(documentType, uids, params) {
382
- return await this.get(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
324
+ return await this.get(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)));
383
325
  }
384
326
  /**
385
327
  * Fetches pages with specific UIDs and a specific type. This method may make
@@ -397,7 +339,7 @@ var Client = class {
397
339
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
398
340
  */
399
341
  async getAllByUIDs(documentType, uids, params) {
400
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
342
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)));
401
343
  }
402
344
  /**
403
345
  * Fetches a specific single type page.
@@ -411,7 +353,7 @@ var Client = class {
411
353
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
412
354
  */
413
355
  async getSingle(documentType, params) {
414
- return await this.getFirst(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
356
+ return await this.getFirst(appendFilters(params, require_filter.filter.at("document.type", documentType)));
415
357
  }
416
358
  /**
417
359
  * Fetches pages with a specific type. Results are paginated.
@@ -425,7 +367,7 @@ var Client = class {
425
367
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
426
368
  */
427
369
  async getByType(documentType, params) {
428
- return await this.get(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
370
+ return await this.get(appendFilters(params, require_filter.filter.at("document.type", documentType)));
429
371
  }
430
372
  /**
431
373
  * Fetches pages with a specific type. This method may make multiple network
@@ -440,7 +382,7 @@ var Client = class {
440
382
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
441
383
  */
442
384
  async getAllByType(documentType, params) {
443
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
385
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.type", documentType)));
444
386
  }
445
387
  /**
446
388
  * Fetches pages with a specific tag. Results are paginated.
@@ -454,7 +396,7 @@ var Client = class {
454
396
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
455
397
  */
456
398
  async getByTag(tag, params) {
457
- return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
399
+ return await this.get(appendFilters(params, require_filter.filter.any("document.tags", [tag])));
458
400
  }
459
401
  /**
460
402
  * Fetches pages with a specific tag. This method may make multiple network
@@ -469,7 +411,7 @@ var Client = class {
469
411
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
470
412
  */
471
413
  async getAllByTag(tag, params) {
472
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
414
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.any("document.tags", [tag])));
473
415
  }
474
416
  /**
475
417
  * Fetches pages with every tag from a list of tags. Results are paginated.
@@ -483,7 +425,7 @@ var Client = class {
483
425
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
484
426
  */
485
427
  async getByEveryTag(tags, params) {
486
- return await this.get(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
428
+ return await this.get(appendFilters(params, require_filter.filter.at("document.tags", tags)));
487
429
  }
488
430
  /**
489
431
  * Fetches pages with every tag from a list of tags. This method may make
@@ -498,7 +440,7 @@ var Client = class {
498
440
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
499
441
  */
500
442
  async getAllByEveryTag(tags, params) {
501
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
443
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.tags", tags)));
502
444
  }
503
445
  /**
504
446
  * Fetches pages with at least one tag from a list of tags. Results are
@@ -513,7 +455,7 @@ var Client = class {
513
455
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
514
456
  */
515
457
  async getBySomeTags(tags, params) {
516
- return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
458
+ return await this.get(appendFilters(params, require_filter.filter.any("document.tags", tags)));
517
459
  }
518
460
  /**
519
461
  * Fetches pages with at least one tag from a list of tags. This method may
@@ -528,7 +470,7 @@ var Client = class {
528
470
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
529
471
  */
530
472
  async getAllBySomeTags(tags, params) {
531
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
473
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.any("document.tags", tags)));
532
474
  }
533
475
  /**
534
476
  * Fetches metadata about the client's Prismic repository.
@@ -547,18 +489,13 @@ var Client = class {
547
489
  const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
548
490
  if (accessToken) url.searchParams.set("access_token", accessToken);
549
491
  const response = await this.#request(url, params);
550
- switch (response.status) {
551
- case 200:
552
- this.#cachedRepository = await response.json();
553
- this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
554
- return this.#cachedRepository;
555
- case 401: {
556
- const json = await response.json();
557
- throw new require_ForbiddenError.ForbiddenError(json.error, url.toString(), json);
558
- }
559
- case 404: throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
560
- default: throw new require_PrismicError.PrismicError(void 0, url.toString(), await response.text());
492
+ if (response.ok) {
493
+ this.#cachedRepository = await response.json();
494
+ this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
495
+ return this.#cachedRepository;
561
496
  }
497
+ if (response.status === 404) throw new require_errors.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
498
+ return await this.#throwContentAPIError(response, url.toString());
562
499
  }
563
500
  /**
564
501
  * Fetches the repository's active refs.
@@ -586,7 +523,9 @@ var Client = class {
586
523
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
587
524
  */
588
525
  async getRefByID(id, params) {
589
- return require_findRefByID.findRefByID(await this.getRefs(params), id);
526
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.id === id);
527
+ if (!ref) throw new require_errors.PrismicError(`Ref with ID "${id}" could not be found.`, void 0, void 0);
528
+ return ref;
590
529
  }
591
530
  /**
592
531
  * Fetches a ref by its label. A release ref's label is its name shown in the
@@ -601,7 +540,9 @@ var Client = class {
601
540
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
602
541
  */
603
542
  async getRefByLabel(label, params) {
604
- return require_findRefByLabel.findRefByLabel(await this.getRefs(params), label);
543
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.label === label);
544
+ if (!ref) throw new require_errors.PrismicError(`Ref with label "${label}" could not be found.`, void 0, void 0);
545
+ return ref;
605
546
  }
606
547
  /**
607
548
  * Fetches the repository's master ref.
@@ -615,7 +556,9 @@ var Client = class {
615
556
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
616
557
  */
617
558
  async getMasterRef(params) {
618
- return require_findMasterRef.findMasterRef(await this.getRefs(params));
559
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.isMasterRef);
560
+ if (!ref) throw new require_errors.PrismicError("Master ref could not be found.", void 0, void 0);
561
+ return ref;
619
562
  }
620
563
  /**
621
564
  * Fetches the repository's active releases.
@@ -643,7 +586,9 @@ var Client = class {
643
586
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
644
587
  */
645
588
  async getReleaseByID(id, params) {
646
- return require_findRefByID.findRefByID(await this.getReleases(params), id);
589
+ const release = (await this.getReleases(params)).find((ref) => ref.id === id);
590
+ if (!release) throw new require_errors.PrismicError(`Release with ID "${id}" could not be found.`, void 0, void 0);
591
+ return release;
647
592
  }
648
593
  /**
649
594
  * Fetches a release by its label. A release ref's label is its name shown in
@@ -658,7 +603,9 @@ var Client = class {
658
603
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
659
604
  */
660
605
  async getReleaseByLabel(label, params) {
661
- return require_findRefByLabel.findRefByLabel(await this.getReleases(params), label);
606
+ const release = (await this.getReleases(params)).find((ref) => ref.label === label);
607
+ if (!release) throw new require_errors.PrismicError(`Release with label "${label}" could not be found.`, void 0, void 0);
608
+ return release;
662
609
  }
663
610
  /**
664
611
  * Fetches the repository's page tags.
@@ -846,20 +793,21 @@ var Client = class {
846
793
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
847
794
  */
848
795
  async graphQLFetch(input, init) {
849
- const repository = await this.getRepository();
850
- const ref = await this.#getResolvedRef();
851
- const unsanitizedHeaders = {
852
- "Prismic-ref": ref,
853
- Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
854
- ...init ? init.headers : {}
796
+ const params = {
797
+ accessToken: this.accessToken,
798
+ fetchOptions: this.fetchOptions
855
799
  };
856
- if (repository.integrationFieldsRef) unsanitizedHeaders["Prismic-integration-field-ref"] = repository.integrationFieldsRef;
800
+ const repository = await this.getRepository(params);
801
+ const ref = await this.#getResolvedRef(params);
857
802
  const headers = {};
858
- for (const key in unsanitizedHeaders) if (unsanitizedHeaders[key]) headers[key.toLowerCase()] = unsanitizedHeaders[key];
859
- const url = new URL(input);
803
+ headers["prismic-ref"] = ref;
804
+ if (this.accessToken) headers["authorization"] = `Token ${this.accessToken}`;
805
+ if (repository.integrationFieldsRef) headers["prismic-integration-field-ref"] = repository.integrationFieldsRef;
806
+ for (const [key, value] of Object.entries((init === null || init === void 0 ? void 0 : init.headers) ?? {})) headers[key.toLowerCase()] = value;
807
+ const url = new URL(typeof input === "string" ? input : input.url);
808
+ const query = (url.searchParams.get("query") ?? "").replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
809
+ url.searchParams.set("query", query);
860
810
  url.searchParams.set("ref", ref);
861
- const query = url.searchParams.get("query");
862
- if (query) url.searchParams.set("query", require_minifyGraphQLQuery.minifyGraphQLQuery(query));
863
811
  return await this.fetchFn(url.toString(), {
864
812
  ...init,
865
813
  headers
@@ -870,7 +818,7 @@ var Client = class {
870
818
  * method may make a network request to fetch a ref or resolve the user's ref
871
819
  * thunk.
872
820
  *
873
- * If auto previews are enabled, the preview ref takes priority if available.
821
+ * If auto previews are enabled, the preview ref takes priority.
874
822
  *
875
823
  * The following strategies are used depending on the client's state:
876
824
  *
@@ -885,8 +833,6 @@ var Client = class {
885
833
  * release is fetched.
886
834
  * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
887
835
  * to the master ref if the ref is not a string.
888
- *
889
- * @returns The ref to use during a query.
890
836
  */
891
837
  async #getResolvedRef(params) {
892
838
  var _this$getRef;
@@ -900,84 +846,63 @@ var Client = class {
900
846
  return (await this.getMasterRef(params)).ref;
901
847
  }
902
848
  /**
903
- * The private implementation of `this.get`. It returns the API response and
904
- * the URL used to make the request. The URL is sometimes used in the public
905
- * method to include in thrown errors.
906
- *
907
- * This method retries requests that throw `RefNotFoundError` or
908
- * `RefExpiredError`. It contains special logic to retry with the latest
909
- * master ref, provided in the API's error message.
910
- *
911
- * @typeParam TDocument - Type of Prismic documents returned.
912
- *
913
- * @param params - Parameters to filter, sort, and paginate results.
914
- *
915
- * @returns An object containing the paginated response containing the result
916
- * of the query and the URL used to make the API request.
849
+ * Performs a low-level Content API request with the given parameters.
850
+ * Automatically retries if an invalid ref is used.
917
851
  */
918
- async _get(params, attemptCount = 0) {
852
+ async #internalGet(params, attempt = 1) {
919
853
  const url = await this.buildQueryURL(params);
854
+ const response = await this.#request(new URL(url), params);
855
+ if (response.ok) return response;
920
856
  try {
921
- const response = await this.#request(new URL(url), params);
922
- switch (response.status) {
923
- case 200: try {
924
- return {
925
- data: await response.clone().json(),
926
- url
927
- };
928
- } catch {
929
- throw new require_PrismicError.PrismicError(void 0, url, await response.text());
930
- }
931
- case 400: {
932
- const json = await response.json();
933
- throw new require_ParsingError.ParsingError(json.message, url, json);
934
- }
935
- case 401: {
936
- const json = await response.json();
937
- throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
938
- }
939
- case 404: {
940
- const json = await response.json();
941
- switch (json.type) {
942
- case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
943
- case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
944
- default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
945
- }
946
- }
947
- case 410: {
948
- const json = await response.json();
949
- throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
950
- }
951
- default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
952
- }
857
+ return await this.#throwContentAPIError(response, url);
953
858
  } catch (error) {
954
- var _error$message$match;
955
- if (!(error instanceof require_RefNotFoundError.RefNotFoundError || error instanceof require_RefExpiredError.RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) throw error;
956
- if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
957
- const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
958
- if (!masterRef) throw error;
959
- require_throttledLog.throttledLog(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_RefNotFoundError.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, { level: "warn" });
960
- return await this._get({
961
- ...params,
962
- ref: masterRef
963
- }, attemptCount + 1);
859
+ if ((error instanceof require_errors.RefNotFoundError || error instanceof require_errors.RefExpiredError) && attempt < MAX_INVALID_REF_RETRY_ATTEMPTS) {
860
+ var _error$message$match;
861
+ if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
862
+ const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
863
+ if (!masterRef) throw error;
864
+ require_throttledWarn.throttledWarn(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_errors.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`);
865
+ return await this.#internalGet({
866
+ ...params,
867
+ ref: masterRef
868
+ }, attempt + 1);
869
+ }
870
+ throw error;
964
871
  }
965
872
  }
966
873
  /**
967
- * Makes an HTTP request using the client's configured fetch function and
968
- * options.
969
- *
970
- * @param url - The URL to request.
971
- * @param params - Fetch options.
972
- *
973
- * @returns The response from the fetch request.
874
+ * Throws an error based on a Content API response. Only call in known-errored
875
+ * states.
974
876
  */
975
- async #request(url, params) {
976
- return await require_request.request(url, this._buildRequestInit(params), this.fetchFn);
877
+ async #throwContentAPIError(response, url) {
878
+ switch (response.status) {
879
+ case 400: {
880
+ const json = await response.clone().json();
881
+ throw new require_errors.ParsingError(json.message, url, json);
882
+ }
883
+ case 401: {
884
+ const json = await response.clone().json();
885
+ throw new require_errors.ForbiddenError(json.message, url, json);
886
+ }
887
+ case 404: {
888
+ const json = await response.clone().json();
889
+ switch (json.type) {
890
+ case "api_notfound_error": throw new require_errors.RefNotFoundError(json.message, url, json);
891
+ case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_errors.PreviewTokenExpiredError(json.message, url, json);
892
+ default: throw new require_errors.NotFoundError(json.message, url, json);
893
+ }
894
+ }
895
+ case 410: {
896
+ const json = await response.clone().json();
897
+ throw new require_errors.RefExpiredError(json.message, url, json);
898
+ }
899
+ default: throw new require_errors.PrismicError(void 0, url, await response.text());
900
+ }
977
901
  }
978
- _buildRequestInit(params) {
902
+ /** Performs a low-level network request with the client's fetch options. */
903
+ async #request(url, params) {
979
904
  var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
980
- return {
905
+ return await require_request.request(url, {
981
906
  ...this.fetchOptions,
982
907
  ...params === null || params === void 0 ? void 0 : params.fetchOptions,
983
908
  headers: {
@@ -985,9 +910,16 @@ var Client = class {
985
910
  ...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
986
911
  },
987
912
  signal: (params === null || params === void 0 || (_params$fetchOptions2 = params.fetchOptions) === null || _params$fetchOptions2 === void 0 ? void 0 : _params$fetchOptions2.signal) || (params === null || params === void 0 ? void 0 : params.signal) || ((_this$fetchOptions2 = this.fetchOptions) === null || _this$fetchOptions2 === void 0 ? void 0 : _this$fetchOptions2.signal)
988
- };
913
+ }, this.fetchFn);
989
914
  }
990
915
  };
916
+ /** Appends filters to a params object. */
917
+ function appendFilters(params = {}, ...filters) {
918
+ return {
919
+ ...params,
920
+ filters: [...params.filters ?? [], ...filters]
921
+ };
922
+ }
991
923
 
992
924
  //#endregion
993
925
  exports.Client = Client;