@prismicio/client 7.21.0-pr.421.abcd1e9 → 7.21.0-pr.422.5240efd

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 (216) hide show
  1. package/dist/Client.cjs +222 -336
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.cts +101 -194
  4. package/dist/Client.d.cts.map +1 -1
  5. package/dist/Client.d.ts +101 -194
  6. package/dist/Client.d.ts.map +1 -1
  7. package/dist/Client.js +219 -333
  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/getGraphQLEndpoint.cjs +2 -2
  32. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  33. package/dist/getGraphQLEndpoint.js +1 -1
  34. package/dist/getGraphQLEndpoint.js.map +1 -1
  35. package/dist/getRepositoryEndpoint.cjs +2 -2
  36. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  37. package/dist/getRepositoryEndpoint.js +1 -1
  38. package/dist/getRepositoryEndpoint.js.map +1 -1
  39. package/dist/getRepositoryName.cjs +2 -2
  40. package/dist/getRepositoryName.cjs.map +1 -1
  41. package/dist/getRepositoryName.js +1 -1
  42. package/dist/getRepositoryName.js.map +1 -1
  43. package/dist/getToolbarSrc.cjs +2 -2
  44. package/dist/getToolbarSrc.cjs.map +1 -1
  45. package/dist/getToolbarSrc.js +1 -1
  46. package/dist/getToolbarSrc.js.map +1 -1
  47. package/dist/index.cjs +10 -18
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.cts +1 -9
  50. package/dist/index.d.cts.map +1 -1
  51. package/dist/index.d.ts +1 -9
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1 -9
  54. package/dist/index.js.map +1 -1
  55. package/dist/lib/{throttledLog.js → throttledWarn.cjs} +7 -7
  56. package/dist/lib/throttledWarn.cjs.map +1 -0
  57. package/dist/lib/{throttledLog.cjs → throttledWarn.js} +6 -8
  58. package/dist/lib/throttledWarn.js.map +1 -0
  59. package/dist/lib/validateAssetMetadata.cjs +2 -2
  60. package/dist/lib/validateAssetMetadata.cjs.map +1 -1
  61. package/dist/lib/validateAssetMetadata.js +1 -1
  62. package/dist/lib/validateAssetMetadata.js.map +1 -1
  63. package/dist/package.cjs +1 -1
  64. package/dist/package.cjs.map +1 -1
  65. package/dist/package.js +1 -1
  66. package/dist/package.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/Client.ts +477 -656
  69. package/src/WriteClient.ts +16 -10
  70. package/src/buildQueryURL.ts +10 -19
  71. package/src/errors.ts +94 -0
  72. package/src/getGraphQLEndpoint.ts +1 -1
  73. package/src/getRepositoryEndpoint.ts +1 -1
  74. package/src/getRepositoryName.ts +1 -1
  75. package/src/getToolbarSrc.ts +1 -1
  76. package/src/index.ts +11 -9
  77. package/src/lib/{throttledLog.ts → throttledWarn.ts} +3 -13
  78. package/src/lib/validateAssetMetadata.ts +1 -1
  79. package/dist/errors/ForbiddenError.cjs +0 -8
  80. package/dist/errors/ForbiddenError.cjs.map +0 -1
  81. package/dist/errors/ForbiddenError.d.cts +0 -14
  82. package/dist/errors/ForbiddenError.d.cts.map +0 -1
  83. package/dist/errors/ForbiddenError.d.ts +0 -14
  84. package/dist/errors/ForbiddenError.d.ts.map +0 -1
  85. package/dist/errors/ForbiddenError.js +0 -8
  86. package/dist/errors/ForbiddenError.js.map +0 -1
  87. package/dist/errors/InvalidDataError.cjs +0 -8
  88. package/dist/errors/InvalidDataError.cjs.map +0 -1
  89. package/dist/errors/InvalidDataError.d.cts +0 -7
  90. package/dist/errors/InvalidDataError.d.cts.map +0 -1
  91. package/dist/errors/InvalidDataError.d.ts +0 -7
  92. package/dist/errors/InvalidDataError.d.ts.map +0 -1
  93. package/dist/errors/InvalidDataError.js +0 -8
  94. package/dist/errors/InvalidDataError.js.map +0 -1
  95. package/dist/errors/NotFoundError.cjs +0 -8
  96. package/dist/errors/NotFoundError.cjs.map +0 -1
  97. package/dist/errors/NotFoundError.d.cts +0 -7
  98. package/dist/errors/NotFoundError.d.cts.map +0 -1
  99. package/dist/errors/NotFoundError.d.ts +0 -7
  100. package/dist/errors/NotFoundError.d.ts.map +0 -1
  101. package/dist/errors/NotFoundError.js +0 -8
  102. package/dist/errors/NotFoundError.js.map +0 -1
  103. package/dist/errors/ParsingError.cjs +0 -8
  104. package/dist/errors/ParsingError.cjs.map +0 -1
  105. package/dist/errors/ParsingError.d.cts +0 -17
  106. package/dist/errors/ParsingError.d.cts.map +0 -1
  107. package/dist/errors/ParsingError.d.ts +0 -17
  108. package/dist/errors/ParsingError.d.ts.map +0 -1
  109. package/dist/errors/ParsingError.js +0 -8
  110. package/dist/errors/ParsingError.js.map +0 -1
  111. package/dist/errors/PreviewTokenExpired.cjs +0 -8
  112. package/dist/errors/PreviewTokenExpired.cjs.map +0 -1
  113. package/dist/errors/PreviewTokenExpired.d.cts +0 -11
  114. package/dist/errors/PreviewTokenExpired.d.cts.map +0 -1
  115. package/dist/errors/PreviewTokenExpired.d.ts +0 -11
  116. package/dist/errors/PreviewTokenExpired.d.ts.map +0 -1
  117. package/dist/errors/PreviewTokenExpired.js +0 -8
  118. package/dist/errors/PreviewTokenExpired.js.map +0 -1
  119. package/dist/errors/PrismicError.cjs +0 -15
  120. package/dist/errors/PrismicError.cjs.map +0 -1
  121. package/dist/errors/PrismicError.d.cts +0 -9
  122. package/dist/errors/PrismicError.d.cts.map +0 -1
  123. package/dist/errors/PrismicError.d.ts +0 -9
  124. package/dist/errors/PrismicError.d.ts.map +0 -1
  125. package/dist/errors/PrismicError.js +0 -14
  126. package/dist/errors/PrismicError.js.map +0 -1
  127. package/dist/errors/RefExpiredError.cjs +0 -8
  128. package/dist/errors/RefExpiredError.cjs.map +0 -1
  129. package/dist/errors/RefExpiredError.d.cts +0 -11
  130. package/dist/errors/RefExpiredError.d.cts.map +0 -1
  131. package/dist/errors/RefExpiredError.d.ts +0 -11
  132. package/dist/errors/RefExpiredError.d.ts.map +0 -1
  133. package/dist/errors/RefExpiredError.js +0 -8
  134. package/dist/errors/RefExpiredError.js.map +0 -1
  135. package/dist/errors/RefNotFoundError.cjs +0 -8
  136. package/dist/errors/RefNotFoundError.cjs.map +0 -1
  137. package/dist/errors/RefNotFoundError.d.cts +0 -11
  138. package/dist/errors/RefNotFoundError.d.cts.map +0 -1
  139. package/dist/errors/RefNotFoundError.d.ts +0 -11
  140. package/dist/errors/RefNotFoundError.d.ts.map +0 -1
  141. package/dist/errors/RefNotFoundError.js +0 -8
  142. package/dist/errors/RefNotFoundError.js.map +0 -1
  143. package/dist/errors/RepositoryNotFoundError.cjs +0 -8
  144. package/dist/errors/RepositoryNotFoundError.cjs.map +0 -1
  145. package/dist/errors/RepositoryNotFoundError.d.cts +0 -7
  146. package/dist/errors/RepositoryNotFoundError.d.cts.map +0 -1
  147. package/dist/errors/RepositoryNotFoundError.d.ts +0 -7
  148. package/dist/errors/RepositoryNotFoundError.d.ts.map +0 -1
  149. package/dist/errors/RepositoryNotFoundError.js +0 -8
  150. package/dist/errors/RepositoryNotFoundError.js.map +0 -1
  151. package/dist/lib/appendFilters.cjs +0 -24
  152. package/dist/lib/appendFilters.cjs.map +0 -1
  153. package/dist/lib/appendFilters.js +0 -24
  154. package/dist/lib/appendFilters.js.map +0 -1
  155. package/dist/lib/castArray.cjs +0 -20
  156. package/dist/lib/castArray.cjs.map +0 -1
  157. package/dist/lib/castArray.js +0 -19
  158. package/dist/lib/castArray.js.map +0 -1
  159. package/dist/lib/castThunk.cjs +0 -19
  160. package/dist/lib/castThunk.cjs.map +0 -1
  161. package/dist/lib/castThunk.js +0 -18
  162. package/dist/lib/castThunk.js.map +0 -1
  163. package/dist/lib/everyTagFilter.cjs +0 -19
  164. package/dist/lib/everyTagFilter.cjs.map +0 -1
  165. package/dist/lib/everyTagFilter.js +0 -19
  166. package/dist/lib/everyTagFilter.js.map +0 -1
  167. package/dist/lib/findMasterRef.cjs +0 -19
  168. package/dist/lib/findMasterRef.cjs.map +0 -1
  169. package/dist/lib/findMasterRef.js +0 -19
  170. package/dist/lib/findMasterRef.js.map +0 -1
  171. package/dist/lib/findRef.cjs +0 -24
  172. package/dist/lib/findRef.cjs.map +0 -1
  173. package/dist/lib/findRef.js +0 -24
  174. package/dist/lib/findRef.js.map +0 -1
  175. package/dist/lib/findRefByID.cjs +0 -20
  176. package/dist/lib/findRefByID.cjs.map +0 -1
  177. package/dist/lib/findRefByID.js +0 -20
  178. package/dist/lib/findRefByID.js.map +0 -1
  179. package/dist/lib/findRefByLabel.cjs +0 -20
  180. package/dist/lib/findRefByLabel.cjs.map +0 -1
  181. package/dist/lib/findRefByLabel.js +0 -20
  182. package/dist/lib/findRefByLabel.js.map +0 -1
  183. package/dist/lib/minifyGraphQLQuery.cjs +0 -16
  184. package/dist/lib/minifyGraphQLQuery.cjs.map +0 -1
  185. package/dist/lib/minifyGraphQLQuery.js +0 -15
  186. package/dist/lib/minifyGraphQLQuery.js.map +0 -1
  187. package/dist/lib/someTagsFilter.cjs +0 -19
  188. package/dist/lib/someTagsFilter.cjs.map +0 -1
  189. package/dist/lib/someTagsFilter.js +0 -19
  190. package/dist/lib/someTagsFilter.js.map +0 -1
  191. package/dist/lib/throttledLog.cjs.map +0 -1
  192. package/dist/lib/throttledLog.js.map +0 -1
  193. package/dist/lib/typeFilter.cjs +0 -17
  194. package/dist/lib/typeFilter.cjs.map +0 -1
  195. package/dist/lib/typeFilter.js +0 -17
  196. package/dist/lib/typeFilter.js.map +0 -1
  197. package/src/errors/ForbiddenError.ts +0 -16
  198. package/src/errors/InvalidDataError.ts +0 -5
  199. package/src/errors/NotFoundError.ts +0 -5
  200. package/src/errors/ParsingError.ts +0 -16
  201. package/src/errors/PreviewTokenExpired.ts +0 -12
  202. package/src/errors/PrismicError.ts +0 -15
  203. package/src/errors/RefExpiredError.ts +0 -14
  204. package/src/errors/RefNotFoundError.ts +0 -14
  205. package/src/errors/RepositoryNotFoundError.ts +0 -5
  206. package/src/lib/appendFilters.ts +0 -26
  207. package/src/lib/castArray.ts +0 -14
  208. package/src/lib/castThunk.ts +0 -13
  209. package/src/lib/everyTagFilter.ts +0 -15
  210. package/src/lib/findMasterRef.ts +0 -16
  211. package/src/lib/findRef.ts +0 -25
  212. package/src/lib/findRefByID.ts +0 -17
  213. package/src/lib/findRefByLabel.ts +0 -17
  214. package/src/lib/minifyGraphQLQuery.ts +0 -13
  215. package/src/lib/someTagsFilter.ts +0 -15
  216. package/src/lib/typeFilter.ts +0 -12
package/dist/Client.cjs CHANGED
@@ -1,25 +1,9 @@
1
1
  const require_filter = require('./filter.cjs');
2
- const require_appendFilters = require('./lib/appendFilters.cjs');
3
- const require_castThunk = require('./lib/castThunk.cjs');
4
2
  const require_devMsg = require('./lib/devMsg.cjs');
5
- const require_everyTagFilter = require('./lib/everyTagFilter.cjs');
6
- const require_PrismicError = require('./errors/PrismicError.cjs');
7
- const require_findMasterRef = require('./lib/findMasterRef.cjs');
8
- const require_findRefByID = require('./lib/findRefByID.cjs');
9
- const require_findRefByLabel = require('./lib/findRefByLabel.cjs');
10
3
  const require_getPreviewCookie = require('./lib/getPreviewCookie.cjs');
11
- const require_minifyGraphQLQuery = require('./lib/minifyGraphQLQuery.cjs');
12
4
  const require_request = require('./lib/request.cjs');
13
- const require_someTagsFilter = require('./lib/someTagsFilter.cjs');
14
- const require_throttledLog = require('./lib/throttledLog.cjs');
15
- const require_typeFilter = require('./lib/typeFilter.cjs');
16
- const require_ForbiddenError = require('./errors/ForbiddenError.cjs');
17
- const require_NotFoundError = require('./errors/NotFoundError.cjs');
18
- const require_ParsingError = require('./errors/ParsingError.cjs');
19
- const require_PreviewTokenExpired = require('./errors/PreviewTokenExpired.cjs');
20
- const require_RefExpiredError = require('./errors/RefExpiredError.cjs');
21
- const require_RefNotFoundError = require('./errors/RefNotFoundError.cjs');
22
- const require_RepositoryNotFoundError = require('./errors/RepositoryNotFoundError.cjs');
5
+ const require_throttledWarn = require('./lib/throttledWarn.cjs');
6
+ const require_errors = require('./errors.cjs');
23
7
  const require_asLink = require('./helpers/asLink.cjs');
24
8
  const require_buildQueryURL = require('./buildQueryURL.cjs');
25
9
  const require_getRepositoryEndpoint = require('./getRepositoryEndpoint.cjs');
@@ -27,191 +11,123 @@ const require_getRepositoryName = require('./getRepositoryName.cjs');
27
11
  const require_isRepositoryEndpoint = require('./isRepositoryEndpoint.cjs');
28
12
 
29
13
  //#region src/Client.ts
30
- /**
31
- * The largest page size allowed by the Prismic REST API V2. This value is used
32
- * to minimize the number of requests required to query content.
33
- */
34
14
  const MAX_PAGE_SIZE = 100;
35
- /**
36
- * The number of milliseconds in which repository metadata is considered valid.
37
- * A ref can be invalidated quickly depending on how frequently content is
38
- * updated in the Prismic repository. As such, repository's metadata can only be
39
- * considered valid for a short amount of time.
40
- */
41
15
  const REPOSITORY_CACHE_TTL = 5e3;
42
- /**
43
- * The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,
44
- * `getAllByType`, `getAllByTag`) will wait between individual page requests.
45
- *
46
- * This is done to ensure API performance is sustainable and reduces the chance
47
- * of a failed API request due to overloading.
48
- */
49
16
  const GET_ALL_QUERY_DELAY = 500;
50
- /**
51
- * The maximum number of attempts to retry a query with an invalid ref. We allow
52
- * multiple attempts since each attempt may use a different (and possibly
53
- * invalid) ref. Capping the number of attempts prevents infinite loops.
54
- */
55
17
  const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
56
18
  /**
57
- * Modes for client ref management.
58
- */
59
- var RefStateMode = /* @__PURE__ */ function(RefStateMode$1) {
60
- /**
61
- * Use the repository's master ref.
62
- */
63
- RefStateMode$1["Master"] = "Master";
64
- /**
65
- * Use a given Release identified by its ID.
66
- */
67
- RefStateMode$1["ReleaseID"] = "ReleaseID";
68
- /**
69
- * Use a given Release identified by its label.
70
- */
71
- RefStateMode$1["ReleaseLabel"] = "ReleaseLabel";
72
- /**
73
- * Use a given ref.
74
- */
75
- RefStateMode$1["Manual"] = "Manual";
76
- return RefStateMode$1;
77
- }(RefStateMode || {});
78
- /**
79
- * A client that allows querying content from a Prismic repository.
80
- *
81
- * If used in an environment where a global `fetch` function is unavailable,
82
- * such as Node.js, the `fetch` option must be provided as part of the `options`
83
- * parameter.
19
+ * A client for fetching content from a Prismic repository.
84
20
  *
85
- * @typeParam TDocuments - Document types that are registered for the Prismic
86
- * 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}
87
23
  */
88
24
  var Client = class {
89
25
  /**
90
- * The function used to make network requests to the Prismic REST API. In
91
- * environments where a global `fetch` function does not exist, such as
92
- * Node.js, this function must be provided.
93
- */
94
- fetchFn;
95
- fetchOptions;
96
- #repositoryName;
97
- /**
98
- * The Prismic repository's name.
99
- */
100
- set repositoryName(value) {
101
- this.#repositoryName = value;
102
- }
103
- /**
104
- * The Prismic repository's name.
105
- */
106
- get repositoryName() {
107
- 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);
108
- return this.#repositoryName;
109
- }
110
- /**
111
- * The Prismic REST API V2 endpoint for the repository (use
112
- * `prismic.getRepositoryEndpoint` for the default endpoint).
113
- */
114
- documentAPIEndpoint;
115
- /**
116
- * The Prismic REST API V2 endpoint for the repository (use
117
- * `prismic.getRepositoryEndpoint` for the default endpoint).
26
+ * The client's Content API endpoint.
118
27
  *
119
- * @deprecated Use `documentAPIEndpoint` instead.
28
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
120
29
  */
121
- set endpoint(value) {
122
- this.documentAPIEndpoint = value;
123
- }
124
- /**
125
- * The Prismic REST API V2 endpoint for the repository (use
126
- * `prismic.getRepositoryEndpoint` for the default endpoint).
127
- *
128
- * @deprecated Use `documentAPIEndpoint` instead.
129
- */
130
- get endpoint() {
131
- return this.documentAPIEndpoint;
132
- }
30
+ documentAPIEndpoint;
133
31
  /**
134
- * The secure token for accessing the API (only needed if your repository is
135
- * set to private).
32
+ * The secure token used for the Content API.
136
33
  *
137
- * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
34
+ * @see {@link https://prismic.io/docs/fetch-content#content-visibility}
138
35
  */
139
36
  accessToken;
140
37
  /**
141
- * A list of route resolver objects that define how a document's `url` field
142
- * is resolved.
38
+ * A list of route resolver objects that define how a document's `url`
39
+ * property is resolved.
143
40
  *
144
- * {@link https://prismic.io/docs/route-resolver}
41
+ * @see {@link https://prismic.io/docs/routes}
42
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
145
43
  */
146
44
  routes;
147
45
  /**
148
- * The `brokenRoute` option allows you to define the route populated in the
149
- * `url` property for broken link or content relationship fields. A broken
150
- * link is a link or content relationship field whose linked document has been
151
- * unpublished or deleted.
46
+ * The URL used for link or content relationship fields that point to an
47
+ * archived or deleted page.
152
48
  *
153
- * {@link https://prismic.io/docs/route-resolver}
49
+ * @see {@link https://prismic.io/docs/routes}
50
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
154
51
  */
155
52
  brokenRoute;
156
53
  /**
157
- * Default parameters that will be sent with each query. These parameters can
158
- * be overridden on each query if needed.
54
+ * Default parameters sent with each Content API request. These parameters can
55
+ * be overridden on each method.
56
+ *
57
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
159
58
  */
160
59
  defaultParams;
161
60
  /**
162
- * The client's ref mode state. This determines which ref is used during
163
- * queries.
61
+ * The `fetch` function used to make network requests.
62
+ *
63
+ * @default The global `fetch` function.
64
+ *
65
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
164
66
  */
165
- refState = {
166
- mode: RefStateMode.Master,
167
- autoPreviewsEnabled: true
168
- };
67
+ fetchFn;
68
+ /**
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}
73
+ */
74
+ fetchOptions;
75
+ #repositoryName;
76
+ #getRef;
77
+ #autoPreviews = true;
78
+ #autoPreviewsRequest;
169
79
  #cachedRepository;
170
80
  #cachedRepositoryExpiration = 0;
171
81
  /**
172
- * Creates a Prismic client that can be used to query a repository.
173
- *
174
- * If used in an environment where a global `fetch` function is unavailable,
175
- * such as in some Node.js versions, the `fetch` option must be provided as
176
- * part of the `options` parameter.
177
- *
178
- * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
179
- * API V2 endpoint for the repository.
180
- * @param options - Configuration that determines how content will be queried
181
- * from the Prismic repository.
182
- *
183
- * @returns A client that can query content from the repository.
82
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full
83
+ * Content API endpoint for the repository.
84
+ * @param config - Client configuration.
184
85
  */
185
- constructor(repositoryNameOrEndpoint, options = {}) {
186
- this.fetchOptions = options.fetchOptions;
187
- if (typeof options.fetch === "function") this.fetchFn = options.fetch;
188
- else if (typeof globalThis.fetch === "function") this.fetchFn = globalThis.fetch;
189
- 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);
190
- if (this.fetchFn === globalThis.fetch) this.fetchFn = this.fetchFn.bind(globalThis);
191
- if ((options.documentAPIEndpoint || require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) && process.env.NODE_ENV === "development") {
192
- const documentAPIEndpoint = options.documentAPIEndpoint || repositoryNameOrEndpoint;
193
- 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);
194
- const hostname = new URL(documentAPIEndpoint).hostname.toLowerCase();
195
- 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")}`);
196
- 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")}`);
197
- }
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;
198
89
  if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
199
- this.documentAPIEndpoint = repositoryNameOrEndpoint;
200
90
  try {
201
91
  this.repositoryName = require_getRepositoryName.getRepositoryName(repositoryNameOrEndpoint);
202
92
  } catch {
203
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")}`);
204
94
  }
95
+ this.documentAPIEndpoint = documentAPIEndpoint || repositoryNameOrEndpoint;
205
96
  } else {
206
- this.documentAPIEndpoint = options.documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
207
97
  this.repositoryName = repositoryNameOrEndpoint;
98
+ this.documentAPIEndpoint = documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
208
99
  }
209
- this.accessToken = options.accessToken;
210
- this.routes = options.routes;
211
- this.brokenRoute = options.brokenRoute;
212
- this.defaultParams = options.defaultParams;
213
- 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;
214
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;
215
131
  }
216
132
  /**
217
133
  * Enables the client to automatically query content from a preview session.
@@ -225,7 +141,7 @@ var Client = class {
225
141
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
226
142
  */
227
143
  enableAutoPreviews() {
228
- this.refState.autoPreviewsEnabled = true;
144
+ this.#autoPreviews = true;
229
145
  }
230
146
  /**
231
147
  * Enables the client to automatically query content from a preview session
@@ -239,9 +155,9 @@ var Client = class {
239
155
  *
240
156
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
241
157
  */
242
- enableAutoPreviewsFromReq(req) {
243
- this.refState.httpRequest = req;
244
- this.refState.autoPreviewsEnabled = true;
158
+ enableAutoPreviewsFromReq(request$1) {
159
+ this.enableAutoPreviews();
160
+ this.#autoPreviewsRequest = request$1;
245
161
  }
246
162
  /**
247
163
  * Disables the client from automatically querying content from a preview
@@ -256,7 +172,8 @@ var Client = class {
256
172
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
257
173
  */
258
174
  disableAutoPreviews() {
259
- this.refState.autoPreviewsEnabled = false;
175
+ this.#autoPreviews = false;
176
+ this.#autoPreviewsRequest = void 0;
260
177
  }
261
178
  /**
262
179
  * Fetches pages based on the `params` argument. Results are paginated.
@@ -270,8 +187,7 @@ var Client = class {
270
187
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
271
188
  */
272
189
  async get(params) {
273
- const { data } = await this._get(params);
274
- return data;
190
+ return await (await this.#internalGet(params)).json();
275
191
  }
276
192
  /**
277
193
  * Fetches the first page returned based on the `params` argument.
@@ -285,15 +201,14 @@ var Client = class {
285
201
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
286
202
  */
287
203
  async getFirst(params) {
288
- const actualParams = { ...params };
289
- if (!(params && params.page) && !(params === null || params === void 0 ? void 0 : params.pageSize)) {
290
- var _this$defaultParams;
291
- actualParams.pageSize = ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) ?? 1;
292
- }
293
- const { data, url } = await this._get(actualParams);
294
- const firstResult = data.results[0];
295
- if (firstResult) return firstResult;
296
- throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
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);
297
212
  }
298
213
  /**
299
214
  * Fetches all pages based on the `params` argument. This method may make
@@ -308,11 +223,11 @@ var Client = class {
308
223
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
309
224
  */
310
225
  async dangerouslyGetAll(params = {}) {
311
- var _this$defaultParams2;
226
+ var _this$defaultParams;
312
227
  const { limit = Infinity,...actualParams } = params;
313
228
  const resolvedParams = {
314
229
  ...actualParams,
315
- 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)
316
231
  };
317
232
  const documents = [];
318
233
  let latestResult;
@@ -339,7 +254,7 @@ var Client = class {
339
254
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
340
255
  */
341
256
  async getByID(id, params) {
342
- 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)));
343
258
  }
344
259
  /**
345
260
  * Fetches pages with specific IDs. Results are paginated.
@@ -356,7 +271,7 @@ var Client = class {
356
271
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
357
272
  */
358
273
  async getByIDs(ids, params) {
359
- 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)));
360
275
  }
361
276
  /**
362
277
  * Fetches pages with specific IDs. This method may make multiple network
@@ -374,7 +289,7 @@ var Client = class {
374
289
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
375
290
  */
376
291
  async getAllByIDs(ids, params) {
377
- 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)));
378
293
  }
379
294
  /**
380
295
  * Fetches a page with a specific UID and type.
@@ -388,7 +303,7 @@ var Client = class {
388
303
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
389
304
  */
390
305
  async getByUID(documentType, uid, params) {
391
- 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)));
392
307
  }
393
308
  /**
394
309
  * Fetches pages with specific UIDs and a specific type. Results are
@@ -406,7 +321,7 @@ var Client = class {
406
321
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
407
322
  */
408
323
  async getByUIDs(documentType, uids, params) {
409
- 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)));
410
325
  }
411
326
  /**
412
327
  * Fetches pages with specific UIDs and a specific type. This method may make
@@ -424,7 +339,7 @@ var Client = class {
424
339
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
425
340
  */
426
341
  async getAllByUIDs(documentType, uids, params) {
427
- 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)));
428
343
  }
429
344
  /**
430
345
  * Fetches a specific single type page.
@@ -438,7 +353,7 @@ var Client = class {
438
353
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
439
354
  */
440
355
  async getSingle(documentType, params) {
441
- 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)));
442
357
  }
443
358
  /**
444
359
  * Fetches pages with a specific type. Results are paginated.
@@ -452,7 +367,7 @@ var Client = class {
452
367
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
453
368
  */
454
369
  async getByType(documentType, params) {
455
- 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)));
456
371
  }
457
372
  /**
458
373
  * Fetches pages with a specific type. This method may make multiple network
@@ -467,7 +382,7 @@ var Client = class {
467
382
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
468
383
  */
469
384
  async getAllByType(documentType, params) {
470
- 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)));
471
386
  }
472
387
  /**
473
388
  * Fetches pages with a specific tag. Results are paginated.
@@ -481,7 +396,7 @@ var Client = class {
481
396
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
482
397
  */
483
398
  async getByTag(tag, params) {
484
- 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])));
485
400
  }
486
401
  /**
487
402
  * Fetches pages with a specific tag. This method may make multiple network
@@ -496,7 +411,7 @@ var Client = class {
496
411
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
497
412
  */
498
413
  async getAllByTag(tag, params) {
499
- 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])));
500
415
  }
501
416
  /**
502
417
  * Fetches pages with every tag from a list of tags. Results are paginated.
@@ -510,7 +425,7 @@ var Client = class {
510
425
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
511
426
  */
512
427
  async getByEveryTag(tags, params) {
513
- 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)));
514
429
  }
515
430
  /**
516
431
  * Fetches pages with every tag from a list of tags. This method may make
@@ -525,7 +440,7 @@ var Client = class {
525
440
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
526
441
  */
527
442
  async getAllByEveryTag(tags, params) {
528
- 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)));
529
444
  }
530
445
  /**
531
446
  * Fetches pages with at least one tag from a list of tags. Results are
@@ -540,7 +455,7 @@ var Client = class {
540
455
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
541
456
  */
542
457
  async getBySomeTags(tags, params) {
543
- 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)));
544
459
  }
545
460
  /**
546
461
  * Fetches pages with at least one tag from a list of tags. This method may
@@ -555,7 +470,7 @@ var Client = class {
555
470
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
556
471
  */
557
472
  async getAllBySomeTags(tags, params) {
558
- 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)));
559
474
  }
560
475
  /**
561
476
  * Fetches metadata about the client's Prismic repository.
@@ -574,18 +489,13 @@ var Client = class {
574
489
  const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
575
490
  if (accessToken) url.searchParams.set("access_token", accessToken);
576
491
  const response = await this.#request(url, params);
577
- switch (response.status) {
578
- case 200:
579
- this.#cachedRepository = await response.json();
580
- this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
581
- return this.#cachedRepository;
582
- case 401: {
583
- const json = await response.json();
584
- throw new require_ForbiddenError.ForbiddenError(json.error, url.toString(), json);
585
- }
586
- case 404: throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
587
- default: throw new require_PrismicError.PrismicError(void 0, url.toString(), await response.text());
492
+ if (response.ok) {
493
+ this.#cachedRepository = await response.json();
494
+ this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
495
+ return this.#cachedRepository;
588
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());
589
499
  }
590
500
  /**
591
501
  * Fetches the repository's active refs.
@@ -613,7 +523,9 @@ var Client = class {
613
523
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
614
524
  */
615
525
  async getRefByID(id, params) {
616
- 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;
617
529
  }
618
530
  /**
619
531
  * Fetches a ref by its label. A release ref's label is its name shown in the
@@ -628,7 +540,9 @@ var Client = class {
628
540
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
629
541
  */
630
542
  async getRefByLabel(label, params) {
631
- 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;
632
546
  }
633
547
  /**
634
548
  * Fetches the repository's master ref.
@@ -642,7 +556,9 @@ var Client = class {
642
556
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
643
557
  */
644
558
  async getMasterRef(params) {
645
- 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;
646
562
  }
647
563
  /**
648
564
  * Fetches the repository's active releases.
@@ -670,7 +586,9 @@ var Client = class {
670
586
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
671
587
  */
672
588
  async getReleaseByID(id, params) {
673
- 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;
674
592
  }
675
593
  /**
676
594
  * Fetches a release by its label. A release ref's label is its name shown in
@@ -685,7 +603,9 @@ var Client = class {
685
603
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
686
604
  */
687
605
  async getReleaseByLabel(label, params) {
688
- 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;
689
609
  }
690
610
  /**
691
611
  * Fetches the repository's page tags.
@@ -723,7 +643,7 @@ var Client = class {
723
643
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
724
644
  */
725
645
  async buildQueryURL({ signal, fetchOptions,...params } = {}) {
726
- const ref = params.ref || await this.getResolvedRefString({
646
+ const ref = params.ref || await this.#getResolvedRef({
727
647
  accessToken: params.accessToken,
728
648
  signal,
729
649
  fetchOptions
@@ -764,13 +684,13 @@ var Client = class {
764
684
  const searchParams = new URLSearchParams(globalThis.location.search);
765
685
  documentID = documentID || searchParams.get("documentId");
766
686
  previewToken = previewToken || searchParams.get("token");
767
- } else if (this.refState.httpRequest) {
768
- if ("query" in this.refState.httpRequest) {
769
- var _this$refState$httpRe, _this$refState$httpRe2;
770
- documentID = documentID || ((_this$refState$httpRe = this.refState.httpRequest.query) === null || _this$refState$httpRe === void 0 ? void 0 : _this$refState$httpRe.documentId);
771
- previewToken = previewToken || ((_this$refState$httpRe2 = this.refState.httpRequest.query) === null || _this$refState$httpRe2 === void 0 ? void 0 : _this$refState$httpRe2.token);
772
- } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
773
- const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
687
+ } else if (this.#autoPreviewsRequest) {
688
+ if ("query" in this.#autoPreviewsRequest) {
689
+ var _this$autoPreviewsReq, _this$autoPreviewsReq2;
690
+ documentID = documentID || ((_this$autoPreviewsReq = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq === void 0 ? void 0 : _this$autoPreviewsReq.documentId);
691
+ previewToken = previewToken || ((_this$autoPreviewsReq2 = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq2 === void 0 ? void 0 : _this$autoPreviewsReq2.token);
692
+ } else if ("url" in this.#autoPreviewsRequest && this.#autoPreviewsRequest.url) {
693
+ const searchParams = new URL(this.#autoPreviewsRequest.url, "missing-host://").searchParams;
774
694
  documentID = documentID || searchParams.get("documentId");
775
695
  previewToken = previewToken || searchParams.get("token");
776
696
  }
@@ -799,7 +719,7 @@ var Client = class {
799
719
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
800
720
  */
801
721
  queryLatestContent() {
802
- this.refState.mode = RefStateMode.Master;
722
+ this.#getRef = void 0;
803
723
  }
804
724
  /**
805
725
  * Configures the client to query content from a release with a specific ID.
@@ -812,11 +732,9 @@ var Client = class {
812
732
  *
813
733
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
814
734
  */
815
- queryContentFromReleaseByID(releaseID) {
816
- this.refState = {
817
- ...this.refState,
818
- mode: RefStateMode.ReleaseID,
819
- releaseID
735
+ queryContentFromReleaseByID(id) {
736
+ this.#getRef = async (params) => {
737
+ return (await this.getReleaseByID(id, params)).ref;
820
738
  };
821
739
  }
822
740
  /**
@@ -831,11 +749,9 @@ var Client = class {
831
749
  *
832
750
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
833
751
  */
834
- queryContentFromReleaseByLabel(releaseLabel) {
835
- this.refState = {
836
- ...this.refState,
837
- mode: RefStateMode.ReleaseLabel,
838
- releaseLabel
752
+ queryContentFromReleaseByLabel(label) {
753
+ this.#getRef = async (params) => {
754
+ return (await this.getReleaseByLabel(label, params)).ref;
839
755
  };
840
756
  }
841
757
  /**
@@ -850,11 +766,7 @@ var Client = class {
850
766
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
851
767
  */
852
768
  queryContentFromRef(ref) {
853
- this.refState = {
854
- ...this.refState,
855
- mode: RefStateMode.Manual,
856
- ref
857
- };
769
+ this.#getRef = typeof ref === "string" ? () => ref : ref;
858
770
  }
859
771
  /**
860
772
  * A preconfigured `fetch()` function for Prismic's GraphQL API that can be
@@ -881,20 +793,21 @@ var Client = class {
881
793
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
882
794
  */
883
795
  async graphQLFetch(input, init) {
884
- const repository = await this.getRepository();
885
- const ref = await this.getResolvedRefString();
886
- const unsanitizedHeaders = {
887
- "Prismic-ref": ref,
888
- Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
889
- ...init ? init.headers : {}
796
+ const params = {
797
+ accessToken: this.accessToken,
798
+ fetchOptions: this.fetchOptions
890
799
  };
891
- if (repository.integrationFieldsRef) unsanitizedHeaders["Prismic-integration-field-ref"] = repository.integrationFieldsRef;
800
+ const repository = await this.getRepository(params);
801
+ const ref = await this.#getResolvedRef(params);
892
802
  const headers = {};
893
- for (const key in unsanitizedHeaders) if (unsanitizedHeaders[key]) headers[key.toLowerCase()] = unsanitizedHeaders[key];
894
- 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);
895
810
  url.searchParams.set("ref", ref);
896
- const query = url.searchParams.get("query");
897
- if (query) url.searchParams.set("query", require_minifyGraphQLQuery.minifyGraphQLQuery(query));
898
811
  return await this.fetchFn(url.toString(), {
899
812
  ...init,
900
813
  headers
@@ -905,7 +818,7 @@ var Client = class {
905
818
  * method may make a network request to fetch a ref or resolve the user's ref
906
819
  * thunk.
907
820
  *
908
- * If auto previews are enabled, the preview ref takes priority if available.
821
+ * If auto previews are enabled, the preview ref takes priority.
909
822
  *
910
823
  * The following strategies are used depending on the client's state:
911
824
  *
@@ -920,110 +833,76 @@ var Client = class {
920
833
  * release is fetched.
921
834
  * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
922
835
  * to the master ref if the ref is not a string.
923
- *
924
- * @returns The ref to use during a query.
925
836
  */
926
- async getResolvedRefString(params) {
927
- if (this.refState.autoPreviewsEnabled) {
928
- var _this$refState$httpRe3, _globalThis$document;
929
- let previewRef;
930
- let cookieJar;
931
- if ((_this$refState$httpRe3 = this.refState.httpRequest) === null || _this$refState$httpRe3 === void 0 ? void 0 : _this$refState$httpRe3.headers) {
932
- if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") cookieJar = this.refState.httpRequest.headers.get("cookie");
933
- else if ("cookie" in this.refState.httpRequest.headers) cookieJar = this.refState.httpRequest.headers.cookie;
934
- } else if ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) cookieJar = globalThis.document.cookie;
935
- if (cookieJar) previewRef = require_getPreviewCookie.getPreviewCookie(cookieJar);
837
+ async #getResolvedRef(params) {
838
+ var _this$getRef;
839
+ if (this.#autoPreviews) {
840
+ var _this$autoPreviewsReq3, _globalThis$document;
841
+ const previewRef = require_getPreviewCookie.getPreviewCookie((((_this$autoPreviewsReq3 = this.#autoPreviewsRequest) === null || _this$autoPreviewsReq3 === void 0 ? void 0 : _this$autoPreviewsReq3.headers) ? "get" in this.#autoPreviewsRequest.headers ? this.#autoPreviewsRequest.headers.get("cookie") : this.#autoPreviewsRequest.headers.cookie : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) ?? "");
936
842
  if (previewRef) return previewRef;
937
843
  }
938
- const repository = await this.getRepository(params);
939
- const refModeType = this.refState.mode;
940
- if (refModeType === RefStateMode.ReleaseID) return require_findRefByID.findRefByID(repository.refs, this.refState.releaseID).ref;
941
- else if (refModeType === RefStateMode.ReleaseLabel) return require_findRefByLabel.findRefByLabel(repository.refs, this.refState.releaseLabel).ref;
942
- else if (refModeType === RefStateMode.Manual) {
943
- const res = await require_castThunk.castThunk(this.refState.ref)();
944
- if (typeof res === "string") return res;
945
- }
946
- return require_findMasterRef.findMasterRef(repository.refs).ref;
844
+ const ref = await ((_this$getRef = this.#getRef) === null || _this$getRef === void 0 ? void 0 : _this$getRef.call(this, params));
845
+ if (ref) return ref;
846
+ return (await this.getMasterRef(params)).ref;
947
847
  }
948
848
  /**
949
- * The private implementation of `this.get`. It returns the API response and
950
- * the URL used to make the request. The URL is sometimes used in the public
951
- * method to include in thrown errors.
952
- *
953
- * This method retries requests that throw `RefNotFoundError` or
954
- * `RefExpiredError`. It contains special logic to retry with the latest
955
- * master ref, provided in the API's error message.
956
- *
957
- * @typeParam TDocument - Type of Prismic documents returned.
958
- *
959
- * @param params - Parameters to filter, sort, and paginate results.
960
- *
961
- * @returns An object containing the paginated response containing the result
962
- * of the query and the URL used to make the API request.
849
+ * Performs a low-level Content API request with the given parameters.
850
+ * Automatically retries if an invalid ref is used.
963
851
  */
964
- async _get(params, attemptCount = 0) {
852
+ async #internalGet(params, attempt = 1) {
965
853
  const url = await this.buildQueryURL(params);
854
+ const response = await this.#request(new URL(url), params);
855
+ if (response.ok) return response;
966
856
  try {
967
- const response = await this.#request(new URL(url), params);
968
- switch (response.status) {
969
- case 200: try {
970
- return {
971
- data: await response.clone().json(),
972
- url
973
- };
974
- } catch {
975
- throw new require_PrismicError.PrismicError(void 0, url, await response.text());
976
- }
977
- case 400: {
978
- const json = await response.json();
979
- throw new require_ParsingError.ParsingError(json.message, url, json);
980
- }
981
- case 401: {
982
- const json = await response.json();
983
- throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
984
- }
985
- case 404: {
986
- const json = await response.json();
987
- switch (json.type) {
988
- case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
989
- case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
990
- default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
991
- }
992
- }
993
- case 410: {
994
- const json = await response.json();
995
- throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
996
- }
997
- default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
998
- }
857
+ return await this.#throwContentAPIError(response, url);
999
858
  } catch (error) {
1000
- var _error$message$match;
1001
- if (!(error instanceof require_RefNotFoundError.RefNotFoundError || error instanceof require_RefExpiredError.RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) throw error;
1002
- if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
1003
- const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
1004
- if (!masterRef) throw error;
1005
- require_throttledLog.throttledLog(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_RefNotFoundError.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, { level: "warn" });
1006
- return await this._get({
1007
- ...params,
1008
- ref: masterRef
1009
- }, attemptCount + 1);
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;
1010
871
  }
1011
872
  }
1012
873
  /**
1013
- * Makes an HTTP request using the client's configured fetch function and
1014
- * options.
1015
- *
1016
- * @param url - The URL to request.
1017
- * @param params - Fetch options.
1018
- *
1019
- * @returns The response from the fetch request.
874
+ * Throws an error based on a Content API response. Only call in known-errored
875
+ * states.
1020
876
  */
1021
- async #request(url, params) {
1022
- 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
+ }
1023
901
  }
1024
- _buildRequestInit(params) {
902
+ /** Performs a low-level network request with the client's fetch options. */
903
+ async #request(url, params) {
1025
904
  var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
1026
- return {
905
+ return await require_request.request(url, {
1027
906
  ...this.fetchOptions,
1028
907
  ...params === null || params === void 0 ? void 0 : params.fetchOptions,
1029
908
  headers: {
@@ -1031,9 +910,16 @@ var Client = class {
1031
910
  ...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
1032
911
  },
1033
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)
1034
- };
913
+ }, this.fetchFn);
1035
914
  }
1036
915
  };
916
+ /** Appends filters to a params object. */
917
+ function appendFilters(params = {}, ...filters) {
918
+ return {
919
+ ...params,
920
+ filters: [...params.filters ?? [], ...filters]
921
+ };
922
+ }
1037
923
 
1038
924
  //#endregion
1039
925
  exports.Client = Client;