@prismicio/client 7.21.0-pr.419.4409b0e → 7.21.0-pr.420.7e9c320
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.
- package/dist/Client.cjs +274 -417
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.cts +194 -342
- package/dist/Client.d.cts.map +1 -1
- package/dist/Client.d.ts +194 -342
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +274 -417
- package/dist/Client.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +1 -1
- package/src/Client.ts +361 -510
package/dist/Client.cjs
CHANGED
|
@@ -183,42 +183,35 @@ var Client = class {
|
|
|
183
183
|
* @returns A client that can query content from the repository.
|
|
184
184
|
*/
|
|
185
185
|
constructor(repositoryNameOrEndpoint, options = {}) {
|
|
186
|
-
|
|
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
|
-
}
|
|
186
|
+
const { documentAPIEndpoint, accessToken, ref, routes, brokenRoute, defaultParams, fetchOptions = {}, fetch = globalThis.fetch } = options;
|
|
198
187
|
if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
|
|
199
|
-
this.documentAPIEndpoint = repositoryNameOrEndpoint;
|
|
200
188
|
try {
|
|
201
189
|
this.repositoryName = require_getRepositoryName.getRepositoryName(repositoryNameOrEndpoint);
|
|
202
190
|
} catch {
|
|
203
191
|
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
192
|
}
|
|
193
|
+
this.documentAPIEndpoint = documentAPIEndpoint || repositoryNameOrEndpoint;
|
|
205
194
|
} else {
|
|
206
|
-
this.documentAPIEndpoint = options.documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
|
|
207
195
|
this.repositoryName = repositoryNameOrEndpoint;
|
|
196
|
+
this.documentAPIEndpoint = documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
|
|
208
197
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
if (
|
|
198
|
+
if (!fetch) 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);
|
|
199
|
+
if (typeof fetch !== "function") throw new require_PrismicError.PrismicError(`fetch must be a function, but received: ${typeof fetch}`, void 0, void 0);
|
|
200
|
+
if (!require_isRepositoryEndpoint.isRepositoryEndpoint(this.documentAPIEndpoint)) throw new require_PrismicError.PrismicError(`documentAPIEndpoint is not a valid URL: ${documentAPIEndpoint}`, void 0, void 0);
|
|
201
|
+
if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(this.documentAPIEndpoint) && process.env.NODE_ENV === "development") 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);
|
|
202
|
+
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")}`);
|
|
203
|
+
this.accessToken = accessToken;
|
|
204
|
+
this.routes = routes;
|
|
205
|
+
this.brokenRoute = brokenRoute;
|
|
206
|
+
this.defaultParams = defaultParams;
|
|
207
|
+
this.fetchOptions = fetchOptions;
|
|
208
|
+
this.fetchFn = fetch;
|
|
209
|
+
if (this.fetchFn === globalThis.fetch) this.fetchFn = this.fetchFn.bind(globalThis);
|
|
210
|
+
if (ref) this.queryContentFromRef(ref);
|
|
214
211
|
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
215
212
|
}
|
|
216
213
|
/**
|
|
217
|
-
* Enables the client to automatically query content from a preview session
|
|
218
|
-
* one is active in browser environments. This is enabled by default in the
|
|
219
|
-
* browser.
|
|
220
|
-
*
|
|
221
|
-
* For server environments, use `enableAutoPreviewsFromReq`.
|
|
214
|
+
* Enables the client to automatically query content from a preview session.
|
|
222
215
|
*
|
|
223
216
|
* @example
|
|
224
217
|
*
|
|
@@ -226,29 +219,22 @@ var Client = class {
|
|
|
226
219
|
* client.enableAutoPreviews()
|
|
227
220
|
* ```
|
|
228
221
|
*
|
|
229
|
-
* @see
|
|
222
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
|
|
230
223
|
*/
|
|
231
224
|
enableAutoPreviews() {
|
|
232
225
|
this.refState.autoPreviewsEnabled = true;
|
|
233
226
|
}
|
|
234
227
|
/**
|
|
235
|
-
* Enables the client to automatically query content from a preview session
|
|
236
|
-
*
|
|
237
|
-
* server.
|
|
238
|
-
*
|
|
239
|
-
* For browser environments, use `enableAutoPreviews`.
|
|
228
|
+
* Enables the client to automatically query content from a preview session
|
|
229
|
+
* using an HTTP request object.
|
|
240
230
|
*
|
|
241
231
|
* @example
|
|
242
232
|
*
|
|
243
233
|
* ```ts
|
|
244
|
-
*
|
|
245
|
-
* app.get("/", function (req, res) {
|
|
246
|
-
* client.enableAutoPreviewsFromReq(req)
|
|
247
|
-
* })
|
|
234
|
+
* client.enableAutoPreviewsFromReq(req)
|
|
248
235
|
* ```
|
|
249
236
|
*
|
|
250
|
-
* @
|
|
251
|
-
* cookies.
|
|
237
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
|
|
252
238
|
*/
|
|
253
239
|
enableAutoPreviewsFromReq(req) {
|
|
254
240
|
this.refState.httpRequest = req;
|
|
@@ -256,93 +242,74 @@ var Client = class {
|
|
|
256
242
|
}
|
|
257
243
|
/**
|
|
258
244
|
* Disables the client from automatically querying content from a preview
|
|
259
|
-
* session
|
|
260
|
-
*
|
|
261
|
-
* Automatic preview content querying is enabled by default unless this method
|
|
262
|
-
* is called.
|
|
245
|
+
* session.
|
|
263
246
|
*
|
|
264
247
|
* @example
|
|
265
248
|
*
|
|
266
249
|
* ```ts
|
|
267
250
|
* client.disableAutoPreviews()
|
|
268
251
|
* ```
|
|
252
|
+
*
|
|
253
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
|
|
269
254
|
*/
|
|
270
255
|
disableAutoPreviews() {
|
|
271
256
|
this.refState.autoPreviewsEnabled = false;
|
|
272
257
|
}
|
|
273
258
|
/**
|
|
274
|
-
*
|
|
259
|
+
* Fetches pages based on the `params` argument. Results are paginated.
|
|
275
260
|
*
|
|
276
261
|
* @example
|
|
277
262
|
*
|
|
278
263
|
* ```ts
|
|
279
|
-
* const response = await client.get()
|
|
264
|
+
* const response = await client.get({ pageSize: 10 })
|
|
280
265
|
* ```
|
|
281
266
|
*
|
|
282
|
-
* @
|
|
283
|
-
*
|
|
284
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
285
|
-
*
|
|
286
|
-
* @returns A paginated response containing the result of the query.
|
|
267
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
|
|
287
268
|
*/
|
|
288
269
|
async get(params) {
|
|
289
|
-
|
|
270
|
+
const { data } = await this._get(params);
|
|
271
|
+
return data;
|
|
290
272
|
}
|
|
291
273
|
/**
|
|
292
|
-
*
|
|
293
|
-
* result, if any.
|
|
274
|
+
* Fetches the first page returned based on the `params` argument.
|
|
294
275
|
*
|
|
295
276
|
* @example
|
|
296
277
|
*
|
|
297
278
|
* ```ts
|
|
298
|
-
* const
|
|
279
|
+
* const page = await client.getFirst()
|
|
299
280
|
* ```
|
|
300
281
|
*
|
|
301
|
-
* @
|
|
302
|
-
*
|
|
303
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
304
|
-
*
|
|
305
|
-
* @returns The first result of the query, if any.
|
|
282
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
|
|
306
283
|
*/
|
|
307
284
|
async getFirst(params) {
|
|
308
|
-
const actualParams =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const {
|
|
314
|
-
|
|
315
|
-
|
|
285
|
+
const actualParams = { ...params };
|
|
286
|
+
if (!(params && params.page) && !(params === null || params === void 0 ? void 0 : params.pageSize)) {
|
|
287
|
+
var _this$defaultParams;
|
|
288
|
+
actualParams.pageSize = ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) ?? 1;
|
|
289
|
+
}
|
|
290
|
+
const { data, url } = await this._get(actualParams);
|
|
291
|
+
const firstResult = data.results[0];
|
|
292
|
+
if (firstResult) return firstResult;
|
|
293
|
+
throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
|
|
316
294
|
}
|
|
317
295
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* filter by filters such as `getAllByType`.
|
|
321
|
-
*
|
|
322
|
-
* Queries content from the Prismic repository and returns all matching
|
|
323
|
-
* content. If no filters are provided, all documents will be fetched.
|
|
324
|
-
*
|
|
325
|
-
* This method may make multiple network requests to query all matching
|
|
326
|
-
* content.
|
|
296
|
+
* Fetches all pages based on the `params` argument. This method may make
|
|
297
|
+
* multiple network requests to fetch all matching pages.
|
|
327
298
|
*
|
|
328
299
|
* @example
|
|
329
300
|
*
|
|
330
301
|
* ```ts
|
|
331
|
-
* const
|
|
302
|
+
* const pages = await client.dangerouslyGetAll()
|
|
332
303
|
* ```
|
|
333
304
|
*
|
|
334
|
-
* @
|
|
335
|
-
*
|
|
336
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
337
|
-
*
|
|
338
|
-
* @returns A list of documents matching the query.
|
|
305
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
|
|
339
306
|
*/
|
|
340
307
|
async dangerouslyGetAll(params = {}) {
|
|
341
|
-
var _this$
|
|
308
|
+
var _this$defaultParams2;
|
|
342
309
|
const { limit = Infinity,...actualParams } = params;
|
|
343
310
|
const resolvedParams = {
|
|
344
311
|
...actualParams,
|
|
345
|
-
pageSize: Math.min(limit, actualParams.pageSize || ((_this$
|
|
312
|
+
pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams2 = this.defaultParams) === null || _this$defaultParams2 === void 0 ? void 0 : _this$defaultParams2.pageSize) || MAX_PAGE_SIZE)
|
|
346
313
|
};
|
|
347
314
|
const documents = [];
|
|
348
315
|
let latestResult;
|
|
@@ -358,39 +325,21 @@ var Client = class {
|
|
|
358
325
|
return documents.slice(0, limit);
|
|
359
326
|
}
|
|
360
327
|
/**
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
* @remarks
|
|
364
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
365
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
366
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
367
|
-
* custom type.
|
|
328
|
+
* Fetches a page with a specific ID.
|
|
368
329
|
*
|
|
369
330
|
* @example
|
|
370
331
|
*
|
|
371
332
|
* ```ts
|
|
372
|
-
* const
|
|
333
|
+
* const page = await client.getByID("WW4bKScAAMAqmluX")
|
|
373
334
|
* ```
|
|
374
335
|
*
|
|
375
|
-
* @
|
|
376
|
-
*
|
|
377
|
-
* @param id - ID of the document.
|
|
378
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
379
|
-
*
|
|
380
|
-
* @returns The document with an ID matching the `id` parameter, if a matching
|
|
381
|
-
* document exists.
|
|
336
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
|
|
382
337
|
*/
|
|
383
338
|
async getByID(id, params) {
|
|
384
339
|
return await this.getFirst(require_appendFilters.appendFilters(params, require_filter.filter.at("document.id", id)));
|
|
385
340
|
}
|
|
386
341
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* @remarks
|
|
390
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
391
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
392
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
393
|
-
* custom type.
|
|
342
|
+
* Fetches pages with specific IDs. Results are paginated.
|
|
394
343
|
*
|
|
395
344
|
* @example
|
|
396
345
|
*
|
|
@@ -401,172 +350,95 @@ var Client = class {
|
|
|
401
350
|
* ])
|
|
402
351
|
* ```
|
|
403
352
|
*
|
|
404
|
-
* @
|
|
405
|
-
*
|
|
406
|
-
* @param ids - A list of document IDs.
|
|
407
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
408
|
-
*
|
|
409
|
-
* @returns A paginated response containing documents with IDs matching the
|
|
410
|
-
* `ids` parameter.
|
|
353
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
|
|
411
354
|
*/
|
|
412
355
|
async getByIDs(ids, params) {
|
|
413
356
|
return await this.get(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
414
357
|
}
|
|
415
358
|
/**
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
* This method may make multiple network requests to query all matching
|
|
419
|
-
* content.
|
|
420
|
-
*
|
|
421
|
-
* @remarks
|
|
422
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
423
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
424
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
425
|
-
* custom type.
|
|
359
|
+
* Fetches pages with specific IDs. This method may make multiple network
|
|
360
|
+
* requests to fetch all matching pages.
|
|
426
361
|
*
|
|
427
362
|
* @example
|
|
428
363
|
*
|
|
429
364
|
* ```ts
|
|
430
|
-
* const
|
|
365
|
+
* const pages = await client.getAllByIDs([
|
|
431
366
|
* "WW4bKScAAMAqmluX",
|
|
432
367
|
* "U1kTRgEAAC8A5ldS",
|
|
433
368
|
* ])
|
|
434
369
|
* ```
|
|
435
370
|
*
|
|
436
|
-
* @
|
|
437
|
-
*
|
|
438
|
-
* @param ids - A list of document IDs.
|
|
439
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
440
|
-
*
|
|
441
|
-
* @returns A list of documents with IDs matching the `ids` parameter.
|
|
371
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
|
|
442
372
|
*/
|
|
443
373
|
async getAllByIDs(ids, params) {
|
|
444
374
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
445
375
|
}
|
|
446
376
|
/**
|
|
447
|
-
*
|
|
448
|
-
* custom type.
|
|
449
|
-
*
|
|
450
|
-
* @remarks
|
|
451
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
452
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
453
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
454
|
-
* custom type.
|
|
377
|
+
* Fetches a page with a specific UID and type.
|
|
455
378
|
*
|
|
456
379
|
* @example
|
|
457
380
|
*
|
|
458
381
|
* ```ts
|
|
459
|
-
* const
|
|
382
|
+
* const page = await client.getByUID("blog_post", "my-first-post")
|
|
460
383
|
* ```
|
|
461
384
|
*
|
|
462
|
-
* @
|
|
463
|
-
*
|
|
464
|
-
* @param documentType - The API ID of the document's custom type.
|
|
465
|
-
* @param uid - UID of the document.
|
|
466
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
467
|
-
*
|
|
468
|
-
* @returns The document with a UID matching the `uid` parameter, if a
|
|
469
|
-
* matching document exists.
|
|
385
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
|
|
470
386
|
*/
|
|
471
387
|
async getByUID(documentType, uid, params) {
|
|
472
388
|
return await this.getFirst(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)]));
|
|
473
389
|
}
|
|
474
390
|
/**
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
* @remarks
|
|
479
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
480
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
481
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
482
|
-
* custom type.
|
|
391
|
+
* Fetches pages with specific UIDs and a specific type. Results are
|
|
392
|
+
* paginated.
|
|
483
393
|
*
|
|
484
394
|
* @example
|
|
485
395
|
*
|
|
486
396
|
* ```ts
|
|
487
|
-
* const
|
|
397
|
+
* const response = await client.getByUIDs("blog_post", [
|
|
488
398
|
* "my-first-post",
|
|
489
399
|
* "my-second-post",
|
|
490
400
|
* ])
|
|
491
401
|
* ```
|
|
492
402
|
*
|
|
493
|
-
* @
|
|
494
|
-
*
|
|
495
|
-
* @param documentType - The API ID of the document's custom type.
|
|
496
|
-
* @param uids - A list of document UIDs.
|
|
497
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
498
|
-
*
|
|
499
|
-
* @returns A paginated response containing documents with UIDs matching the
|
|
500
|
-
* `uids` parameter.
|
|
403
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
|
|
501
404
|
*/
|
|
502
405
|
async getByUIDs(documentType, uids, params) {
|
|
503
406
|
return await this.get(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
|
|
504
407
|
}
|
|
505
408
|
/**
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
* This method may make multiple network requests to query all matching
|
|
510
|
-
* content.
|
|
511
|
-
*
|
|
512
|
-
* @remarks
|
|
513
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
514
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
515
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
516
|
-
* custom type.
|
|
409
|
+
* Fetches pages with specific UIDs and a specific type. This method may make
|
|
410
|
+
* multiple network requests to fetch all matching pages.
|
|
517
411
|
*
|
|
518
412
|
* @example
|
|
519
413
|
*
|
|
520
414
|
* ```ts
|
|
521
|
-
* const
|
|
415
|
+
* const pages = await client.getAllByUIDs("blog_post", [
|
|
522
416
|
* "my-first-post",
|
|
523
417
|
* "my-second-post",
|
|
524
418
|
* ])
|
|
525
419
|
* ```
|
|
526
420
|
*
|
|
527
|
-
* @
|
|
528
|
-
*
|
|
529
|
-
* @param documentType - The API ID of the document's custom type.
|
|
530
|
-
* @param uids - A list of document UIDs.
|
|
531
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
532
|
-
*
|
|
533
|
-
* @returns A list of documents with UIDs matching the `uids` parameter.
|
|
421
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
|
|
534
422
|
*/
|
|
535
423
|
async getAllByUIDs(documentType, uids, params) {
|
|
536
424
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
|
|
537
425
|
}
|
|
538
426
|
/**
|
|
539
|
-
*
|
|
540
|
-
* custom type.
|
|
541
|
-
*
|
|
542
|
-
* @remarks
|
|
543
|
-
* A singleton document is one that is configured in Prismic to only allow one
|
|
544
|
-
* instance. For example, a repository may be configured to contain just one
|
|
545
|
-
* Settings document. This is in contrast to a repeatable custom type which
|
|
546
|
-
* allows multiple instances of itself.
|
|
427
|
+
* Fetches a specific single type page.
|
|
547
428
|
*
|
|
548
429
|
* @example
|
|
549
430
|
*
|
|
550
431
|
* ```ts
|
|
551
|
-
* const
|
|
432
|
+
* const page = await client.getSingle("settings")
|
|
552
433
|
* ```
|
|
553
434
|
*
|
|
554
|
-
* @
|
|
555
|
-
*
|
|
556
|
-
* @param documentType - The API ID of the singleton custom type.
|
|
557
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
558
|
-
*
|
|
559
|
-
* @returns The singleton document for the custom type, if a matching document
|
|
560
|
-
* exists.
|
|
435
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
|
|
561
436
|
*/
|
|
562
437
|
async getSingle(documentType, params) {
|
|
563
438
|
return await this.getFirst(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
564
439
|
}
|
|
565
440
|
/**
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
* Use `getAllByType` instead if you need to query all documents for a
|
|
569
|
-
* specific custom type.
|
|
441
|
+
* Fetches pages with a specific type. Results are paginated.
|
|
570
442
|
*
|
|
571
443
|
* @example
|
|
572
444
|
*
|
|
@@ -574,177 +446,124 @@ var Client = class {
|
|
|
574
446
|
* const response = await client.getByType("blog_post")
|
|
575
447
|
* ```
|
|
576
448
|
*
|
|
577
|
-
* @
|
|
578
|
-
*
|
|
579
|
-
* @param documentType - The API ID of the custom type.
|
|
580
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
581
|
-
*
|
|
582
|
-
* @returns A paginated response containing documents of the custom type.
|
|
449
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
|
|
583
450
|
*/
|
|
584
451
|
async getByType(documentType, params) {
|
|
585
452
|
return await this.get(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
586
453
|
}
|
|
587
454
|
/**
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* This method may make multiple network requests to query all matching
|
|
592
|
-
* content.
|
|
455
|
+
* Fetches pages with a specific type. This method may make multiple network
|
|
456
|
+
* requests to fetch all matching documents.
|
|
593
457
|
*
|
|
594
458
|
* @example
|
|
595
459
|
*
|
|
596
460
|
* ```ts
|
|
597
|
-
* const
|
|
461
|
+
* const pages = await client.getAllByType("blog_post")
|
|
598
462
|
* ```
|
|
599
463
|
*
|
|
600
|
-
* @
|
|
601
|
-
*
|
|
602
|
-
* @param documentType - The API ID of the custom type.
|
|
603
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
604
|
-
*
|
|
605
|
-
* @returns A list of all documents of the custom type.
|
|
464
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
|
|
606
465
|
*/
|
|
607
466
|
async getAllByType(documentType, params) {
|
|
608
467
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
609
468
|
}
|
|
610
469
|
/**
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
* Use `getAllByTag` instead if you need to query all documents with a
|
|
614
|
-
* specific tag.
|
|
470
|
+
* Fetches pages with a specific tag. Results are paginated.
|
|
615
471
|
*
|
|
616
472
|
* @example
|
|
617
473
|
*
|
|
618
474
|
* ```ts
|
|
619
|
-
* const response = await client.getByTag("
|
|
475
|
+
* const response = await client.getByTag("featured")
|
|
620
476
|
* ```
|
|
621
477
|
*
|
|
622
|
-
* @
|
|
623
|
-
*
|
|
624
|
-
* @param tag - The tag that must be included on a document.
|
|
625
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
626
|
-
*
|
|
627
|
-
* @returns A paginated response containing documents with the tag.
|
|
478
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
|
|
628
479
|
*/
|
|
629
480
|
async getByTag(tag, params) {
|
|
630
481
|
return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
|
|
631
482
|
}
|
|
632
483
|
/**
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
* This method may make multiple network requests to query all matching
|
|
636
|
-
* content.
|
|
484
|
+
* Fetches pages with a specific tag. This method may make multiple network
|
|
485
|
+
* requests to fetch all matching documents.
|
|
637
486
|
*
|
|
638
487
|
* @example
|
|
639
488
|
*
|
|
640
489
|
* ```ts
|
|
641
|
-
* const
|
|
490
|
+
* const pages = await client.getAllByTag("featured")
|
|
642
491
|
* ```
|
|
643
492
|
*
|
|
644
|
-
* @
|
|
645
|
-
*
|
|
646
|
-
* @param tag - The tag that must be included on a document.
|
|
647
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
648
|
-
*
|
|
649
|
-
* @returns A list of all documents with the tag.
|
|
493
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
|
|
650
494
|
*/
|
|
651
495
|
async getAllByTag(tag, params) {
|
|
652
496
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
|
|
653
497
|
}
|
|
654
498
|
/**
|
|
655
|
-
*
|
|
656
|
-
* document must be tagged with all of the queried tags to be included.
|
|
499
|
+
* Fetches pages with every tag from a list of tags. Results are paginated.
|
|
657
500
|
*
|
|
658
501
|
* @example
|
|
659
502
|
*
|
|
660
503
|
* ```ts
|
|
661
|
-
* const response = await client.getByEveryTag(["
|
|
504
|
+
* const response = await client.getByEveryTag(["featured", "homepage"])
|
|
662
505
|
* ```
|
|
663
506
|
*
|
|
664
|
-
* @
|
|
665
|
-
*
|
|
666
|
-
* @param tags - A list of tags that must be included on a document.
|
|
667
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
668
|
-
*
|
|
669
|
-
* @returns A paginated response containing documents with the tags.
|
|
507
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
|
|
670
508
|
*/
|
|
671
509
|
async getByEveryTag(tags, params) {
|
|
672
510
|
return await this.get(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
|
|
673
511
|
}
|
|
674
512
|
/**
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
* This method may make multiple network requests to query all matching
|
|
679
|
-
* content.
|
|
513
|
+
* Fetches pages with every tag from a list of tags. This method may make
|
|
514
|
+
* multiple network requests to fetch all matching pages.
|
|
680
515
|
*
|
|
681
516
|
* @example
|
|
682
517
|
*
|
|
683
518
|
* ```ts
|
|
684
|
-
* const
|
|
519
|
+
* const pages = await client.getAllByEveryTag(["featured", "homepage"])
|
|
685
520
|
* ```
|
|
686
521
|
*
|
|
687
|
-
* @
|
|
688
|
-
*
|
|
689
|
-
* @param tags - A list of tags that must be included on a document.
|
|
690
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
691
|
-
*
|
|
692
|
-
* @returns A list of all documents with the tags.
|
|
522
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
|
|
693
523
|
*/
|
|
694
524
|
async getAllByEveryTag(tags, params) {
|
|
695
525
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
|
|
696
526
|
}
|
|
697
527
|
/**
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* included.
|
|
528
|
+
* Fetches pages with at least one tag from a list of tags. Results are
|
|
529
|
+
* paginated.
|
|
701
530
|
*
|
|
702
531
|
* @example
|
|
703
532
|
*
|
|
704
533
|
* ```ts
|
|
705
|
-
* const response = await client.
|
|
534
|
+
* const response = await client.getBySomeTags(["featured", "homepage"])
|
|
706
535
|
* ```
|
|
707
536
|
*
|
|
708
|
-
* @
|
|
709
|
-
*
|
|
710
|
-
* @param tags - A list of tags that must be included on a document.
|
|
711
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
712
|
-
*
|
|
713
|
-
* @returns A paginated response containing documents with at least one of the
|
|
714
|
-
* tags.
|
|
537
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
|
|
715
538
|
*/
|
|
716
539
|
async getBySomeTags(tags, params) {
|
|
717
540
|
return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
|
|
718
541
|
}
|
|
719
542
|
/**
|
|
720
|
-
*
|
|
721
|
-
*
|
|
722
|
-
* included.
|
|
723
|
-
*
|
|
724
|
-
* This method may make multiple network requests to query all matching
|
|
725
|
-
* content.
|
|
543
|
+
* Fetches pages with at least one tag from a list of tags. This method may
|
|
544
|
+
* make multiple network requests to fetch all matching documents.
|
|
726
545
|
*
|
|
727
546
|
* @example
|
|
728
547
|
*
|
|
729
548
|
* ```ts
|
|
730
|
-
* const
|
|
549
|
+
* const pages = await client.getAllBySomeTags(["featured", "homepage"])
|
|
731
550
|
* ```
|
|
732
551
|
*
|
|
733
|
-
* @
|
|
734
|
-
*
|
|
735
|
-
* @param tags - A list of tags that must be included on a document.
|
|
736
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
737
|
-
*
|
|
738
|
-
* @returns A list of all documents with at least one of the tags.
|
|
552
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
|
|
739
553
|
*/
|
|
740
554
|
async getAllBySomeTags(tags, params) {
|
|
741
555
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
|
|
742
556
|
}
|
|
743
557
|
/**
|
|
744
|
-
*
|
|
745
|
-
* and custom types.
|
|
558
|
+
* Fetches metadata about the client's Prismic repository.
|
|
746
559
|
*
|
|
747
|
-
* @
|
|
560
|
+
* @example
|
|
561
|
+
*
|
|
562
|
+
* ```ts
|
|
563
|
+
* const repository = await client.getRepository()
|
|
564
|
+
* ```
|
|
565
|
+
*
|
|
566
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrepository}
|
|
748
567
|
*/
|
|
749
568
|
async getRepository(params) {
|
|
750
569
|
if (this.#cachedRepository && this.#cachedRepositoryExpiration > Date.now()) return this.#cachedRepository;
|
|
@@ -752,88 +571,129 @@ var Client = class {
|
|
|
752
571
|
const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
|
|
753
572
|
if (accessToken) url.searchParams.set("access_token", accessToken);
|
|
754
573
|
const response = await this.#request(url, params);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
574
|
+
switch (response.status) {
|
|
575
|
+
case 200:
|
|
576
|
+
this.#cachedRepository = await response.json();
|
|
577
|
+
this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
578
|
+
return this.#cachedRepository;
|
|
579
|
+
case 401: {
|
|
580
|
+
const json = await response.json();
|
|
581
|
+
throw new require_ForbiddenError.ForbiddenError(json.error, url.toString(), json);
|
|
582
|
+
}
|
|
583
|
+
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);
|
|
584
|
+
default: throw new require_PrismicError.PrismicError(void 0, url.toString(), await response.text());
|
|
759
585
|
}
|
|
760
|
-
if (response.status === 404) throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
|
|
761
|
-
return await this.#throwContentAPIError(response, url.toString());
|
|
762
586
|
}
|
|
763
587
|
/**
|
|
764
|
-
*
|
|
588
|
+
* Fetches the repository's active refs.
|
|
765
589
|
*
|
|
766
|
-
*
|
|
767
|
-
* be queried. All repositories will have at least one ref pointing to the
|
|
768
|
-
* latest published content called the "master ref".
|
|
590
|
+
* @example
|
|
769
591
|
*
|
|
770
|
-
*
|
|
592
|
+
* ```ts
|
|
593
|
+
* const refs = await client.getRefs()
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefs}
|
|
771
597
|
*/
|
|
772
598
|
async getRefs(params) {
|
|
773
599
|
return (await this.getRepository(params)).refs;
|
|
774
600
|
}
|
|
775
601
|
/**
|
|
776
|
-
*
|
|
602
|
+
* Fetches a ref by its ID.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
777
605
|
*
|
|
778
|
-
*
|
|
606
|
+
* ```ts
|
|
607
|
+
* const ref = await client.getRefByID("YhE3YhEAACIA4321")
|
|
608
|
+
* ```
|
|
779
609
|
*
|
|
780
|
-
* @
|
|
610
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
|
|
781
611
|
*/
|
|
782
612
|
async getRefByID(id, params) {
|
|
783
613
|
return require_findRefByID.findRefByID(await this.getRefs(params), id);
|
|
784
614
|
}
|
|
785
615
|
/**
|
|
786
|
-
*
|
|
616
|
+
* Fetches a ref by its label. A release ref's label is its name shown in the
|
|
617
|
+
* Page Builder.
|
|
787
618
|
*
|
|
788
|
-
* @
|
|
619
|
+
* @example
|
|
789
620
|
*
|
|
790
|
-
*
|
|
621
|
+
* ```ts
|
|
622
|
+
* const ref = await client.getRefByLabel("My Release")
|
|
623
|
+
* ```
|
|
624
|
+
*
|
|
625
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
|
|
791
626
|
*/
|
|
792
627
|
async getRefByLabel(label, params) {
|
|
793
628
|
return require_findRefByLabel.findRefByLabel(await this.getRefs(params), label);
|
|
794
629
|
}
|
|
795
630
|
/**
|
|
796
|
-
*
|
|
797
|
-
* the repository's latest published content.
|
|
631
|
+
* Fetches the repository's master ref.
|
|
798
632
|
*
|
|
799
|
-
* @
|
|
633
|
+
* @example
|
|
634
|
+
*
|
|
635
|
+
* ```ts
|
|
636
|
+
* const masterRef = await client.getMasterRef()
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
|
|
800
640
|
*/
|
|
801
641
|
async getMasterRef(params) {
|
|
802
642
|
return require_findMasterRef.findMasterRef(await this.getRefs(params));
|
|
803
643
|
}
|
|
804
644
|
/**
|
|
805
|
-
*
|
|
806
|
-
*
|
|
645
|
+
* Fetches the repository's active releases.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
807
648
|
*
|
|
808
|
-
*
|
|
649
|
+
* ```ts
|
|
650
|
+
* const releases = await client.getReleases()
|
|
651
|
+
* ```
|
|
652
|
+
*
|
|
653
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleases}
|
|
809
654
|
*/
|
|
810
655
|
async getReleases(params) {
|
|
811
656
|
return (await this.getRefs(params)).filter((ref) => !ref.isMasterRef);
|
|
812
657
|
}
|
|
813
658
|
/**
|
|
814
|
-
*
|
|
659
|
+
* Fetches a release with a specific ID.
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
815
662
|
*
|
|
816
|
-
*
|
|
663
|
+
* ```ts
|
|
664
|
+
* const release = await client.getReleaseByID("YhE3YhEAACIA4321")
|
|
665
|
+
* ```
|
|
817
666
|
*
|
|
818
|
-
* @
|
|
667
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
|
|
819
668
|
*/
|
|
820
669
|
async getReleaseByID(id, params) {
|
|
821
670
|
return require_findRefByID.findRefByID(await this.getReleases(params), id);
|
|
822
671
|
}
|
|
823
672
|
/**
|
|
824
|
-
*
|
|
673
|
+
* Fetches a release by its label. A release ref's label is its name shown in
|
|
674
|
+
* the Page Builder.
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
825
677
|
*
|
|
826
|
-
*
|
|
678
|
+
* ```ts
|
|
679
|
+
* const release = await client.getReleaseByLabel("My Release")
|
|
680
|
+
* ```
|
|
827
681
|
*
|
|
828
|
-
* @
|
|
682
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
|
|
829
683
|
*/
|
|
830
684
|
async getReleaseByLabel(label, params) {
|
|
831
685
|
return require_findRefByLabel.findRefByLabel(await this.getReleases(params), label);
|
|
832
686
|
}
|
|
833
687
|
/**
|
|
834
|
-
*
|
|
688
|
+
* Fetches the repository's page tags.
|
|
835
689
|
*
|
|
836
|
-
* @
|
|
690
|
+
* @example
|
|
691
|
+
*
|
|
692
|
+
* ```ts
|
|
693
|
+
* const tags = await client.getTags()
|
|
694
|
+
* ```
|
|
695
|
+
*
|
|
696
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#gettags}
|
|
837
697
|
*/
|
|
838
698
|
async getTags(params) {
|
|
839
699
|
const repository = await this.getRepository(params);
|
|
@@ -847,11 +707,17 @@ var Client = class {
|
|
|
847
707
|
return repository.tags;
|
|
848
708
|
}
|
|
849
709
|
/**
|
|
850
|
-
* Builds a
|
|
710
|
+
* Builds a Content API query URL with a set of parameters.
|
|
851
711
|
*
|
|
852
|
-
* @
|
|
712
|
+
* @example
|
|
713
|
+
*
|
|
714
|
+
* ```ts
|
|
715
|
+
* const url = await client.buildQueryURL({
|
|
716
|
+
* filters: [filter.at("document.type", "blog_post")],
|
|
717
|
+
* })
|
|
718
|
+
* ```
|
|
853
719
|
*
|
|
854
|
-
* @
|
|
720
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
|
|
855
721
|
*/
|
|
856
722
|
async buildQueryURL({ signal, fetchOptions,...params } = {}) {
|
|
857
723
|
const ref = params.ref || await this.getResolvedRefString({
|
|
@@ -875,23 +741,18 @@ var Client = class {
|
|
|
875
741
|
});
|
|
876
742
|
}
|
|
877
743
|
/**
|
|
878
|
-
*
|
|
879
|
-
* session. The result of this method should be used to redirect the user to
|
|
880
|
-
* the document's URL.
|
|
744
|
+
* Fetches a previewed page's URL using a preview token and page ID.
|
|
881
745
|
*
|
|
882
746
|
* @example
|
|
883
747
|
*
|
|
884
748
|
* ```ts
|
|
885
|
-
*
|
|
886
|
-
* linkResolver
|
|
887
|
-
* defaultURL:
|
|
888
|
-
*
|
|
749
|
+
* const url = await client.resolvePreviewURL({
|
|
750
|
+
* linkResolver,
|
|
751
|
+
* defaultURL: "/",
|
|
752
|
+
* })
|
|
889
753
|
* ```
|
|
890
754
|
*
|
|
891
|
-
* @
|
|
892
|
-
*
|
|
893
|
-
* @returns The URL for the previewed document during an active preview
|
|
894
|
-
* session. The user should be redirected to this URL.
|
|
755
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#resolvepreviewurl}
|
|
895
756
|
*/
|
|
896
757
|
async resolvePreviewURL(args) {
|
|
897
758
|
let documentID = args.documentID;
|
|
@@ -923,37 +784,30 @@ var Client = class {
|
|
|
923
784
|
return args.defaultURL;
|
|
924
785
|
}
|
|
925
786
|
/**
|
|
926
|
-
* Configures the client to query the latest published content
|
|
927
|
-
*
|
|
928
|
-
*
|
|
929
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
930
|
-
* that query.
|
|
787
|
+
* Configures the client to query the latest published content. This is the
|
|
788
|
+
* client's default mode.
|
|
931
789
|
*
|
|
932
790
|
* @example
|
|
933
791
|
*
|
|
934
792
|
* ```ts
|
|
935
|
-
*
|
|
936
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
793
|
+
* client.queryLatestContent()
|
|
937
794
|
* ```
|
|
795
|
+
*
|
|
796
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
|
|
938
797
|
*/
|
|
939
798
|
queryLatestContent() {
|
|
940
799
|
this.refState.mode = RefStateMode.Master;
|
|
941
800
|
}
|
|
942
801
|
/**
|
|
943
|
-
* Configures the client to query content from a specific
|
|
944
|
-
* by its ID for all future queries.
|
|
945
|
-
*
|
|
946
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
947
|
-
* that query.
|
|
802
|
+
* Configures the client to query content from a release with a specific ID.
|
|
948
803
|
*
|
|
949
804
|
* @example
|
|
950
805
|
*
|
|
951
806
|
* ```ts
|
|
952
|
-
*
|
|
953
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
807
|
+
* client.queryContentFromReleaseByID("YhE3YhEAACIA4321")
|
|
954
808
|
* ```
|
|
955
809
|
*
|
|
956
|
-
* @
|
|
810
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
|
|
957
811
|
*/
|
|
958
812
|
queryContentFromReleaseByID(releaseID) {
|
|
959
813
|
this.refState = {
|
|
@@ -963,20 +817,16 @@ var Client = class {
|
|
|
963
817
|
};
|
|
964
818
|
}
|
|
965
819
|
/**
|
|
966
|
-
* Configures the client to query content from a
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
970
|
-
* that query.
|
|
820
|
+
* Configures the client to query content from a release with a specific
|
|
821
|
+
* label.
|
|
971
822
|
*
|
|
972
823
|
* @example
|
|
973
824
|
*
|
|
974
825
|
* ```ts
|
|
975
|
-
*
|
|
976
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
826
|
+
* client.queryContentFromReleaseByLabel("My Release")
|
|
977
827
|
* ```
|
|
978
828
|
*
|
|
979
|
-
* @
|
|
829
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
|
|
980
830
|
*/
|
|
981
831
|
queryContentFromReleaseByLabel(releaseLabel) {
|
|
982
832
|
this.refState = {
|
|
@@ -986,21 +836,15 @@ var Client = class {
|
|
|
986
836
|
};
|
|
987
837
|
}
|
|
988
838
|
/**
|
|
989
|
-
* Configures the client to query content from a specific ref.
|
|
990
|
-
* provided as a string or a function.
|
|
991
|
-
*
|
|
992
|
-
* If a function is provided, the ref is fetched lazily before each query. The
|
|
993
|
-
* function may also be asynchronous.
|
|
839
|
+
* Configures the client to query content from a specific ref.
|
|
994
840
|
*
|
|
995
841
|
* @example
|
|
996
842
|
*
|
|
997
843
|
* ```ts
|
|
998
|
-
*
|
|
999
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
844
|
+
* client.queryContentFromRef("my-ref")
|
|
1000
845
|
* ```
|
|
1001
846
|
*
|
|
1002
|
-
* @
|
|
1003
|
-
* content.
|
|
847
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
|
|
1004
848
|
*/
|
|
1005
849
|
queryContentFromRef(ref) {
|
|
1006
850
|
this.refState = {
|
|
@@ -1010,17 +854,18 @@ var Client = class {
|
|
|
1010
854
|
};
|
|
1011
855
|
}
|
|
1012
856
|
/**
|
|
1013
|
-
* A `fetch()` function
|
|
1014
|
-
*
|
|
1015
|
-
* and Authorization headers. Queries will automatically be minified by
|
|
1016
|
-
* removing whitespace where possible.
|
|
857
|
+
* A preconfigured `fetch()` function for Prismic's GraphQL API that can be
|
|
858
|
+
* provided to GraphQL clients.
|
|
1017
859
|
*
|
|
1018
860
|
* @example
|
|
1019
861
|
*
|
|
1020
862
|
* ```ts
|
|
863
|
+
* import { createClient, getGraphQLEndpoint } from "@prismicio/client"
|
|
864
|
+
*
|
|
865
|
+
* const client = createClient("example-prismic-repo")
|
|
1021
866
|
* const graphQLClient = new ApolloClient({
|
|
1022
867
|
* link: new HttpLink({
|
|
1023
|
-
* uri:
|
|
868
|
+
* uri: getGraphQLEndpoint(client.repositoryName),
|
|
1024
869
|
* // Provide `client.graphQLFetch` as the fetch implementation.
|
|
1025
870
|
* fetch: client.graphQLFetch,
|
|
1026
871
|
* // Using GET is required.
|
|
@@ -1030,13 +875,7 @@ var Client = class {
|
|
|
1030
875
|
* })
|
|
1031
876
|
* ```
|
|
1032
877
|
*
|
|
1033
|
-
* @
|
|
1034
|
-
* @param init - The `fetch()` `init` parameter. Only plain objects are
|
|
1035
|
-
* supported.
|
|
1036
|
-
*
|
|
1037
|
-
* @returns The `fetch()` Response for the request.
|
|
1038
|
-
*
|
|
1039
|
-
* @experimental
|
|
878
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
|
|
1040
879
|
*/
|
|
1041
880
|
async graphQLFetch(input, init) {
|
|
1042
881
|
const repository = await this.getRepository();
|
|
@@ -1103,50 +942,68 @@ var Client = class {
|
|
|
1103
942
|
}
|
|
1104
943
|
return require_findMasterRef.findMasterRef(repository.refs).ref;
|
|
1105
944
|
}
|
|
1106
|
-
|
|
945
|
+
/**
|
|
946
|
+
* The private implementation of `this.get`. It returns the API response and
|
|
947
|
+
* the URL used to make the request. The URL is sometimes used in the public
|
|
948
|
+
* method to include in thrown errors.
|
|
949
|
+
*
|
|
950
|
+
* This method retries requests that throw `RefNotFoundError` or
|
|
951
|
+
* `RefExpiredError`. It contains special logic to retry with the latest
|
|
952
|
+
* master ref, provided in the API's error message.
|
|
953
|
+
*
|
|
954
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
955
|
+
*
|
|
956
|
+
* @param params - Parameters to filter, sort, and paginate results.
|
|
957
|
+
*
|
|
958
|
+
* @returns An object containing the paginated response containing the result
|
|
959
|
+
* of the query and the URL used to make the API request.
|
|
960
|
+
*/
|
|
961
|
+
async _get(params, attemptCount = 0) {
|
|
1107
962
|
const url = await this.buildQueryURL(params);
|
|
1108
|
-
const response = await this.#request(new URL(url), params);
|
|
1109
|
-
if (response.ok) return response;
|
|
1110
963
|
try {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
...params,
|
|
1121
|
-
ref: masterRef
|
|
1122
|
-
}, attempt + 1);
|
|
1123
|
-
}
|
|
1124
|
-
throw error;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
async #throwContentAPIError(response, url) {
|
|
1128
|
-
switch (response.status) {
|
|
1129
|
-
case 400: {
|
|
1130
|
-
const json = await response.clone().json();
|
|
1131
|
-
throw new require_ParsingError.ParsingError(json.message, url, json);
|
|
1132
|
-
}
|
|
1133
|
-
case 401: {
|
|
1134
|
-
const json = await response.clone().json();
|
|
1135
|
-
throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
|
|
1136
|
-
}
|
|
1137
|
-
case 404: {
|
|
1138
|
-
const json = await response.clone().json();
|
|
1139
|
-
switch (json.type) {
|
|
1140
|
-
case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
|
|
1141
|
-
case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
|
|
1142
|
-
default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
|
|
964
|
+
const response = await this.#request(new URL(url), params);
|
|
965
|
+
switch (response.status) {
|
|
966
|
+
case 200: try {
|
|
967
|
+
return {
|
|
968
|
+
data: await response.clone().json(),
|
|
969
|
+
url
|
|
970
|
+
};
|
|
971
|
+
} catch {
|
|
972
|
+
throw new require_PrismicError.PrismicError(void 0, url, await response.text());
|
|
1143
973
|
}
|
|
974
|
+
case 400: {
|
|
975
|
+
const json = await response.json();
|
|
976
|
+
throw new require_ParsingError.ParsingError(json.message, url, json);
|
|
977
|
+
}
|
|
978
|
+
case 401: {
|
|
979
|
+
const json = await response.json();
|
|
980
|
+
throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
|
|
981
|
+
}
|
|
982
|
+
case 404: {
|
|
983
|
+
const json = await response.json();
|
|
984
|
+
switch (json.type) {
|
|
985
|
+
case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
|
|
986
|
+
case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
|
|
987
|
+
default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
case 410: {
|
|
991
|
+
const json = await response.json();
|
|
992
|
+
throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
|
|
993
|
+
}
|
|
994
|
+
default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
|
|
1144
995
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
996
|
+
} catch (error) {
|
|
997
|
+
var _error$message$match;
|
|
998
|
+
if (!(error instanceof require_RefNotFoundError.RefNotFoundError || error instanceof require_RefExpiredError.RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) throw error;
|
|
999
|
+
if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
|
|
1000
|
+
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;
|
|
1001
|
+
if (!masterRef) throw error;
|
|
1002
|
+
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" });
|
|
1003
|
+
return await this._get({
|
|
1004
|
+
...params,
|
|
1005
|
+
ref: masterRef
|
|
1006
|
+
}, attemptCount + 1);
|
|
1150
1007
|
}
|
|
1151
1008
|
}
|
|
1152
1009
|
/**
|