@prismicio/client 7.21.0-pr.421.abcd1e9 → 7.21.0-pr.422.63e7930

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 +218 -330
  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 +213 -325
  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 +421 -604
  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,173 +11,90 @@ 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;
86
+ constructor(repositoryNameOrEndpoint, config = {}) {
87
+ this.fetchOptions = config.fetchOptions;
88
+ if (typeof config.fetch === "function") this.fetchFn = config.fetch;
188
89
  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);
90
+ else throw new require_errors.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
91
  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);
92
+ if ((config.documentAPIEndpoint || require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) && process.env.NODE_ENV === "development") {
93
+ const documentAPIEndpoint = config.documentAPIEndpoint || repositoryNameOrEndpoint;
94
+ if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(documentAPIEndpoint)) 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);
194
95
  const hostname = new URL(documentAPIEndpoint).hostname.toLowerCase();
195
96
  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")}`);
97
+ if (config.documentAPIEndpoint && require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint) && repositoryNameOrEndpoint !== config.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
98
  }
198
99
  if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
199
100
  this.documentAPIEndpoint = repositoryNameOrEndpoint;
@@ -203,16 +104,33 @@ var Client = class {
203
104
  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
105
  }
205
106
  } else {
206
- this.documentAPIEndpoint = options.documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
107
+ this.documentAPIEndpoint = config.documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
207
108
  this.repositoryName = repositoryNameOrEndpoint;
208
109
  }
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);
110
+ this.accessToken = config.accessToken;
111
+ this.routes = config.routes;
112
+ this.brokenRoute = config.brokenRoute;
113
+ this.defaultParams = config.defaultParams;
114
+ if (config.ref) this.queryContentFromRef(config.ref);
214
115
  this.graphQLFetch = this.graphQLFetch.bind(this);
215
116
  }
117
+ /** The Prismic repository's name. */
118
+ set repositoryName(value) {
119
+ this.#repositoryName = value;
120
+ }
121
+ /** The Prismic repository's name. */
122
+ get repositoryName() {
123
+ 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);
124
+ return this.#repositoryName;
125
+ }
126
+ /** @deprecated Replace with `documentAPIEndpoint`. */
127
+ set endpoint(value) {
128
+ this.documentAPIEndpoint = value;
129
+ }
130
+ /** @deprecated Replace with `documentAPIEndpoint`. */
131
+ get endpoint() {
132
+ return this.documentAPIEndpoint;
133
+ }
216
134
  /**
217
135
  * Enables the client to automatically query content from a preview session.
218
136
  *
@@ -225,7 +143,7 @@ var Client = class {
225
143
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
226
144
  */
227
145
  enableAutoPreviews() {
228
- this.refState.autoPreviewsEnabled = true;
146
+ this.#autoPreviews = true;
229
147
  }
230
148
  /**
231
149
  * Enables the client to automatically query content from a preview session
@@ -239,9 +157,9 @@ var Client = class {
239
157
  *
240
158
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
241
159
  */
242
- enableAutoPreviewsFromReq(req) {
243
- this.refState.httpRequest = req;
244
- this.refState.autoPreviewsEnabled = true;
160
+ enableAutoPreviewsFromReq(request$1) {
161
+ this.enableAutoPreviews();
162
+ this.#autoPreviewsRequest = request$1;
245
163
  }
246
164
  /**
247
165
  * Disables the client from automatically querying content from a preview
@@ -256,7 +174,8 @@ var Client = class {
256
174
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
257
175
  */
258
176
  disableAutoPreviews() {
259
- this.refState.autoPreviewsEnabled = false;
177
+ this.#autoPreviews = false;
178
+ this.#autoPreviewsRequest = void 0;
260
179
  }
261
180
  /**
262
181
  * Fetches pages based on the `params` argument. Results are paginated.
@@ -270,8 +189,7 @@ var Client = class {
270
189
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
271
190
  */
272
191
  async get(params) {
273
- const { data } = await this._get(params);
274
- return data;
192
+ return await (await this.#internalGet(params)).json();
275
193
  }
276
194
  /**
277
195
  * Fetches the first page returned based on the `params` argument.
@@ -285,15 +203,14 @@ var Client = class {
285
203
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
286
204
  */
287
205
  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);
206
+ const actualParams = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params.pageSize) ? params : {
207
+ ...params,
208
+ pageSize: 1
209
+ };
210
+ const response = await this.#internalGet(actualParams);
211
+ const { results } = await response.clone().json();
212
+ if (results[0]) return results[0];
213
+ throw new require_errors.NotFoundError("No documents were returned", response.url, void 0);
297
214
  }
298
215
  /**
299
216
  * Fetches all pages based on the `params` argument. This method may make
@@ -308,11 +225,11 @@ var Client = class {
308
225
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
309
226
  */
310
227
  async dangerouslyGetAll(params = {}) {
311
- var _this$defaultParams2;
228
+ var _this$defaultParams;
312
229
  const { limit = Infinity,...actualParams } = params;
313
230
  const resolvedParams = {
314
231
  ...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)
232
+ pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) || MAX_PAGE_SIZE)
316
233
  };
317
234
  const documents = [];
318
235
  let latestResult;
@@ -339,7 +256,7 @@ var Client = class {
339
256
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
340
257
  */
341
258
  async getByID(id, params) {
342
- return await this.getFirst(require_appendFilters.appendFilters(params, require_filter.filter.at("document.id", id)));
259
+ return await this.getFirst(appendFilters(params, require_filter.filter.at("document.id", id)));
343
260
  }
344
261
  /**
345
262
  * Fetches pages with specific IDs. Results are paginated.
@@ -356,7 +273,7 @@ var Client = class {
356
273
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
357
274
  */
358
275
  async getByIDs(ids, params) {
359
- return await this.get(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
276
+ return await this.get(appendFilters(params, require_filter.filter.in("document.id", ids)));
360
277
  }
361
278
  /**
362
279
  * Fetches pages with specific IDs. This method may make multiple network
@@ -374,7 +291,7 @@ var Client = class {
374
291
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
375
292
  */
376
293
  async getAllByIDs(ids, params) {
377
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
294
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.in("document.id", ids)));
378
295
  }
379
296
  /**
380
297
  * Fetches a page with a specific UID and type.
@@ -388,7 +305,7 @@ var Client = class {
388
305
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
389
306
  */
390
307
  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)]));
308
+ return await this.getFirst(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)));
392
309
  }
393
310
  /**
394
311
  * Fetches pages with specific UIDs and a specific type. Results are
@@ -406,7 +323,7 @@ var Client = class {
406
323
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
407
324
  */
408
325
  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)]));
326
+ return await this.get(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)));
410
327
  }
411
328
  /**
412
329
  * Fetches pages with specific UIDs and a specific type. This method may make
@@ -424,7 +341,7 @@ var Client = class {
424
341
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
425
342
  */
426
343
  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)]));
344
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)));
428
345
  }
429
346
  /**
430
347
  * Fetches a specific single type page.
@@ -438,7 +355,7 @@ var Client = class {
438
355
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
439
356
  */
440
357
  async getSingle(documentType, params) {
441
- return await this.getFirst(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
358
+ return await this.getFirst(appendFilters(params, require_filter.filter.at("document.type", documentType)));
442
359
  }
443
360
  /**
444
361
  * Fetches pages with a specific type. Results are paginated.
@@ -452,7 +369,7 @@ var Client = class {
452
369
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
453
370
  */
454
371
  async getByType(documentType, params) {
455
- return await this.get(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
372
+ return await this.get(appendFilters(params, require_filter.filter.at("document.type", documentType)));
456
373
  }
457
374
  /**
458
375
  * Fetches pages with a specific type. This method may make multiple network
@@ -467,7 +384,7 @@ var Client = class {
467
384
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
468
385
  */
469
386
  async getAllByType(documentType, params) {
470
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
387
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.type", documentType)));
471
388
  }
472
389
  /**
473
390
  * Fetches pages with a specific tag. Results are paginated.
@@ -481,7 +398,7 @@ var Client = class {
481
398
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
482
399
  */
483
400
  async getByTag(tag, params) {
484
- return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
401
+ return await this.get(appendFilters(params, require_filter.filter.any("document.tags", [tag])));
485
402
  }
486
403
  /**
487
404
  * Fetches pages with a specific tag. This method may make multiple network
@@ -496,7 +413,7 @@ var Client = class {
496
413
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
497
414
  */
498
415
  async getAllByTag(tag, params) {
499
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
416
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.any("document.tags", [tag])));
500
417
  }
501
418
  /**
502
419
  * Fetches pages with every tag from a list of tags. Results are paginated.
@@ -510,7 +427,7 @@ var Client = class {
510
427
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
511
428
  */
512
429
  async getByEveryTag(tags, params) {
513
- return await this.get(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
430
+ return await this.get(appendFilters(params, require_filter.filter.at("document.tags", tags)));
514
431
  }
515
432
  /**
516
433
  * Fetches pages with every tag from a list of tags. This method may make
@@ -525,7 +442,7 @@ var Client = class {
525
442
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
526
443
  */
527
444
  async getAllByEveryTag(tags, params) {
528
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
445
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.tags", tags)));
529
446
  }
530
447
  /**
531
448
  * Fetches pages with at least one tag from a list of tags. Results are
@@ -540,7 +457,7 @@ var Client = class {
540
457
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
541
458
  */
542
459
  async getBySomeTags(tags, params) {
543
- return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
460
+ return await this.get(appendFilters(params, require_filter.filter.any("document.tags", tags)));
544
461
  }
545
462
  /**
546
463
  * Fetches pages with at least one tag from a list of tags. This method may
@@ -555,7 +472,7 @@ var Client = class {
555
472
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
556
473
  */
557
474
  async getAllBySomeTags(tags, params) {
558
- return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
475
+ return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.any("document.tags", tags)));
559
476
  }
560
477
  /**
561
478
  * Fetches metadata about the client's Prismic repository.
@@ -574,18 +491,13 @@ var Client = class {
574
491
  const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
575
492
  if (accessToken) url.searchParams.set("access_token", accessToken);
576
493
  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());
494
+ if (response.ok) {
495
+ this.#cachedRepository = await response.json();
496
+ this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
497
+ return this.#cachedRepository;
588
498
  }
499
+ 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);
500
+ return await this.#throwContentAPIError(response, url.toString());
589
501
  }
590
502
  /**
591
503
  * Fetches the repository's active refs.
@@ -613,7 +525,9 @@ var Client = class {
613
525
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
614
526
  */
615
527
  async getRefByID(id, params) {
616
- return require_findRefByID.findRefByID(await this.getRefs(params), id);
528
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.id === id);
529
+ if (!ref) throw new require_errors.PrismicError(`Ref with ID "${id}" could not be found.`, void 0, void 0);
530
+ return ref;
617
531
  }
618
532
  /**
619
533
  * Fetches a ref by its label. A release ref's label is its name shown in the
@@ -628,7 +542,9 @@ var Client = class {
628
542
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
629
543
  */
630
544
  async getRefByLabel(label, params) {
631
- return require_findRefByLabel.findRefByLabel(await this.getRefs(params), label);
545
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.label === label);
546
+ if (!ref) throw new require_errors.PrismicError(`Ref with label "${label}" could not be found.`, void 0, void 0);
547
+ return ref;
632
548
  }
633
549
  /**
634
550
  * Fetches the repository's master ref.
@@ -642,7 +558,9 @@ var Client = class {
642
558
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
643
559
  */
644
560
  async getMasterRef(params) {
645
- return require_findMasterRef.findMasterRef(await this.getRefs(params));
561
+ const ref = (await this.getRefs(params)).find((ref$1) => ref$1.isMasterRef);
562
+ if (!ref) throw new require_errors.PrismicError("Master ref could not be found.", void 0, void 0);
563
+ return ref;
646
564
  }
647
565
  /**
648
566
  * Fetches the repository's active releases.
@@ -670,7 +588,9 @@ var Client = class {
670
588
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
671
589
  */
672
590
  async getReleaseByID(id, params) {
673
- return require_findRefByID.findRefByID(await this.getReleases(params), id);
591
+ const release = (await this.getReleases(params)).find((ref) => ref.id === id);
592
+ if (!release) throw new require_errors.PrismicError(`Release with ID "${id}" could not be found.`, void 0, void 0);
593
+ return release;
674
594
  }
675
595
  /**
676
596
  * Fetches a release by its label. A release ref's label is its name shown in
@@ -685,7 +605,9 @@ var Client = class {
685
605
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
686
606
  */
687
607
  async getReleaseByLabel(label, params) {
688
- return require_findRefByLabel.findRefByLabel(await this.getReleases(params), label);
608
+ const release = (await this.getReleases(params)).find((ref) => ref.label === label);
609
+ if (!release) throw new require_errors.PrismicError(`Release with label "${label}" could not be found.`, void 0, void 0);
610
+ return release;
689
611
  }
690
612
  /**
691
613
  * Fetches the repository's page tags.
@@ -723,7 +645,7 @@ var Client = class {
723
645
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
724
646
  */
725
647
  async buildQueryURL({ signal, fetchOptions,...params } = {}) {
726
- const ref = params.ref || await this.getResolvedRefString({
648
+ const ref = params.ref || await this.#getResolvedRef({
727
649
  accessToken: params.accessToken,
728
650
  signal,
729
651
  fetchOptions
@@ -764,13 +686,13 @@ var Client = class {
764
686
  const searchParams = new URLSearchParams(globalThis.location.search);
765
687
  documentID = documentID || searchParams.get("documentId");
766
688
  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;
689
+ } else if (this.#autoPreviewsRequest) {
690
+ if ("query" in this.#autoPreviewsRequest) {
691
+ var _this$autoPreviewsReq, _this$autoPreviewsReq2;
692
+ documentID = documentID || ((_this$autoPreviewsReq = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq === void 0 ? void 0 : _this$autoPreviewsReq.documentId);
693
+ previewToken = previewToken || ((_this$autoPreviewsReq2 = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq2 === void 0 ? void 0 : _this$autoPreviewsReq2.token);
694
+ } else if ("url" in this.#autoPreviewsRequest && this.#autoPreviewsRequest.url) {
695
+ const searchParams = new URL(this.#autoPreviewsRequest.url, "missing-host://").searchParams;
774
696
  documentID = documentID || searchParams.get("documentId");
775
697
  previewToken = previewToken || searchParams.get("token");
776
698
  }
@@ -799,7 +721,7 @@ var Client = class {
799
721
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
800
722
  */
801
723
  queryLatestContent() {
802
- this.refState.mode = RefStateMode.Master;
724
+ this.#getRef = void 0;
803
725
  }
804
726
  /**
805
727
  * Configures the client to query content from a release with a specific ID.
@@ -812,11 +734,9 @@ var Client = class {
812
734
  *
813
735
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
814
736
  */
815
- queryContentFromReleaseByID(releaseID) {
816
- this.refState = {
817
- ...this.refState,
818
- mode: RefStateMode.ReleaseID,
819
- releaseID
737
+ queryContentFromReleaseByID(id) {
738
+ this.#getRef = async (params) => {
739
+ return (await this.getReleaseByID(id, params)).ref;
820
740
  };
821
741
  }
822
742
  /**
@@ -831,11 +751,9 @@ var Client = class {
831
751
  *
832
752
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
833
753
  */
834
- queryContentFromReleaseByLabel(releaseLabel) {
835
- this.refState = {
836
- ...this.refState,
837
- mode: RefStateMode.ReleaseLabel,
838
- releaseLabel
754
+ queryContentFromReleaseByLabel(label) {
755
+ this.#getRef = async (params) => {
756
+ return (await this.getReleaseByLabel(label, params)).ref;
839
757
  };
840
758
  }
841
759
  /**
@@ -850,11 +768,7 @@ var Client = class {
850
768
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
851
769
  */
852
770
  queryContentFromRef(ref) {
853
- this.refState = {
854
- ...this.refState,
855
- mode: RefStateMode.Manual,
856
- ref
857
- };
771
+ this.#getRef = typeof ref === "string" ? () => ref : ref;
858
772
  }
859
773
  /**
860
774
  * A preconfigured `fetch()` function for Prismic's GraphQL API that can be
@@ -881,20 +795,21 @@ var Client = class {
881
795
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
882
796
  */
883
797
  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 : {}
798
+ const params = {
799
+ accessToken: this.accessToken,
800
+ fetchOptions: this.fetchOptions
890
801
  };
891
- if (repository.integrationFieldsRef) unsanitizedHeaders["Prismic-integration-field-ref"] = repository.integrationFieldsRef;
802
+ const repository = await this.getRepository(params);
803
+ const ref = await this.#getResolvedRef(params);
892
804
  const headers = {};
893
- for (const key in unsanitizedHeaders) if (unsanitizedHeaders[key]) headers[key.toLowerCase()] = unsanitizedHeaders[key];
894
- const url = new URL(input);
805
+ headers["prismic-ref"] = ref;
806
+ if (this.accessToken) headers["authorization"] = `Token ${this.accessToken}`;
807
+ if (repository.integrationFieldsRef) headers["prismic-integration-field-ref"] = repository.integrationFieldsRef;
808
+ for (const [key, value] of Object.entries((init === null || init === void 0 ? void 0 : init.headers) ?? {})) headers[key.toLowerCase()] = value;
809
+ const url = new URL(typeof input === "string" ? input : input.url);
810
+ const query = (url.searchParams.get("query") ?? "").replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
811
+ url.searchParams.set("query", query);
895
812
  url.searchParams.set("ref", ref);
896
- const query = url.searchParams.get("query");
897
- if (query) url.searchParams.set("query", require_minifyGraphQLQuery.minifyGraphQLQuery(query));
898
813
  return await this.fetchFn(url.toString(), {
899
814
  ...init,
900
815
  headers
@@ -905,7 +820,7 @@ var Client = class {
905
820
  * method may make a network request to fetch a ref or resolve the user's ref
906
821
  * thunk.
907
822
  *
908
- * If auto previews are enabled, the preview ref takes priority if available.
823
+ * If auto previews are enabled, the preview ref takes priority.
909
824
  *
910
825
  * The following strategies are used depending on the client's state:
911
826
  *
@@ -920,110 +835,76 @@ var Client = class {
920
835
  * release is fetched.
921
836
  * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
922
837
  * to the master ref if the ref is not a string.
923
- *
924
- * @returns The ref to use during a query.
925
838
  */
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);
839
+ async #getResolvedRef(params) {
840
+ var _this$getRef;
841
+ if (this.#autoPreviews) {
842
+ var _this$autoPreviewsReq3, _globalThis$document;
843
+ 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
844
  if (previewRef) return previewRef;
937
845
  }
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;
846
+ const ref = await ((_this$getRef = this.#getRef) === null || _this$getRef === void 0 ? void 0 : _this$getRef.call(this, params));
847
+ if (ref) return ref;
848
+ return (await this.getMasterRef(params)).ref;
947
849
  }
948
850
  /**
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.
851
+ * Performs a low-level Content API request with the given parameters.
852
+ * Automatically retries if an invalid ref is used.
963
853
  */
964
- async _get(params, attemptCount = 0) {
854
+ async #internalGet(params, attempt = 1) {
965
855
  const url = await this.buildQueryURL(params);
856
+ const response = await this.#request(new URL(url), params);
857
+ if (response.ok) return response;
966
858
  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
- }
859
+ return await this.#throwContentAPIError(response, url);
999
860
  } 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);
861
+ if ((error instanceof require_errors.RefNotFoundError || error instanceof require_errors.RefExpiredError) && attempt < MAX_INVALID_REF_RETRY_ATTEMPTS) {
862
+ var _error$message$match;
863
+ if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
864
+ 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;
865
+ if (!masterRef) throw error;
866
+ 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.`);
867
+ return await this.#internalGet({
868
+ ...params,
869
+ ref: masterRef
870
+ }, attempt + 1);
871
+ }
872
+ throw error;
1010
873
  }
1011
874
  }
1012
875
  /**
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.
876
+ * Throws an error based on a Content API response. Only call in known-errored
877
+ * states.
1020
878
  */
1021
- async #request(url, params) {
1022
- return await require_request.request(url, this._buildRequestInit(params), this.fetchFn);
879
+ async #throwContentAPIError(response, url) {
880
+ switch (response.status) {
881
+ case 400: {
882
+ const json = await response.clone().json();
883
+ throw new require_errors.ParsingError(json.message, url, json);
884
+ }
885
+ case 401: {
886
+ const json = await response.clone().json();
887
+ throw new require_errors.ForbiddenError(json.message, url, json);
888
+ }
889
+ case 404: {
890
+ const json = await response.clone().json();
891
+ switch (json.type) {
892
+ case "api_notfound_error": throw new require_errors.RefNotFoundError(json.message, url, json);
893
+ case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_errors.PreviewTokenExpiredError(json.message, url, json);
894
+ default: throw new require_errors.NotFoundError(json.message, url, json);
895
+ }
896
+ }
897
+ case 410: {
898
+ const json = await response.clone().json();
899
+ throw new require_errors.RefExpiredError(json.message, url, json);
900
+ }
901
+ default: throw new require_errors.PrismicError(void 0, url, await response.text());
902
+ }
1023
903
  }
1024
- _buildRequestInit(params) {
904
+ /** Performs a low-level network request with the client's fetch options. */
905
+ async #request(url, params) {
1025
906
  var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
1026
- return {
907
+ return await require_request.request(url, {
1027
908
  ...this.fetchOptions,
1028
909
  ...params === null || params === void 0 ? void 0 : params.fetchOptions,
1029
910
  headers: {
@@ -1031,9 +912,16 @@ var Client = class {
1031
912
  ...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
1032
913
  },
1033
914
  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
- };
915
+ }, this.fetchFn);
1035
916
  }
1036
917
  };
918
+ /** Appends filters to a params object. */
919
+ function appendFilters(params = {}, ...filters) {
920
+ return {
921
+ ...params,
922
+ filters: [...params.filters ?? [], ...filters]
923
+ };
924
+ }
1037
925
 
1038
926
  //#endregion
1039
927
  exports.Client = Client;