@prismicio/client 7.21.0-canary.85959a7 → 7.21.0-canary.bd2c015
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 +210 -421
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.cts +184 -379
- package/dist/Client.d.cts.map +1 -1
- package/dist/Client.d.ts +184 -379
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +210 -421
- 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 +225 -485
- package/dist/lib/castThunk.cjs +0 -19
- package/dist/lib/castThunk.cjs.map +0 -1
- package/dist/lib/castThunk.js +0 -18
- package/dist/lib/castThunk.js.map +0 -1
package/dist/Client.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_filter = require('./filter.cjs');
|
|
2
2
|
const require_appendFilters = require('./lib/appendFilters.cjs');
|
|
3
|
-
const require_castThunk = require('./lib/castThunk.cjs');
|
|
4
3
|
const require_devMsg = require('./lib/devMsg.cjs');
|
|
5
4
|
const require_everyTagFilter = require('./lib/everyTagFilter.cjs');
|
|
6
5
|
const require_PrismicError = require('./errors/PrismicError.cjs');
|
|
@@ -54,28 +53,6 @@ const GET_ALL_QUERY_DELAY = 500;
|
|
|
54
53
|
*/
|
|
55
54
|
const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
|
|
56
55
|
/**
|
|
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
56
|
* A client that allows querying content from a Prismic repository.
|
|
80
57
|
*
|
|
81
58
|
* If used in an environment where a global `fetch` function is unavailable,
|
|
@@ -158,14 +135,9 @@ var Client = class {
|
|
|
158
135
|
* be overridden on each query if needed.
|
|
159
136
|
*/
|
|
160
137
|
defaultParams;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*/
|
|
165
|
-
refState = {
|
|
166
|
-
mode: RefStateMode.Master,
|
|
167
|
-
autoPreviewsEnabled: true
|
|
168
|
-
};
|
|
138
|
+
#getRef;
|
|
139
|
+
#autoPreviews = true;
|
|
140
|
+
#autoPreviewsRequest;
|
|
169
141
|
#cachedRepository;
|
|
170
142
|
#cachedRepositoryExpiration = 0;
|
|
171
143
|
/**
|
|
@@ -214,11 +186,7 @@ var Client = class {
|
|
|
214
186
|
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
215
187
|
}
|
|
216
188
|
/**
|
|
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`.
|
|
189
|
+
* Enables the client to automatically query content from a preview session.
|
|
222
190
|
*
|
|
223
191
|
* @example
|
|
224
192
|
*
|
|
@@ -226,84 +194,68 @@ var Client = class {
|
|
|
226
194
|
* client.enableAutoPreviews()
|
|
227
195
|
* ```
|
|
228
196
|
*
|
|
229
|
-
* @see
|
|
197
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
|
|
230
198
|
*/
|
|
231
199
|
enableAutoPreviews() {
|
|
232
|
-
this
|
|
200
|
+
this.#autoPreviews = true;
|
|
233
201
|
}
|
|
234
202
|
/**
|
|
235
|
-
* Enables the client to automatically query content from a preview session
|
|
236
|
-
*
|
|
237
|
-
* server.
|
|
238
|
-
*
|
|
239
|
-
* For browser environments, use `enableAutoPreviews`.
|
|
203
|
+
* Enables the client to automatically query content from a preview session
|
|
204
|
+
* using an HTTP request object.
|
|
240
205
|
*
|
|
241
206
|
* @example
|
|
242
207
|
*
|
|
243
208
|
* ```ts
|
|
244
|
-
*
|
|
245
|
-
* app.get("/", function (req, res) {
|
|
246
|
-
* client.enableAutoPreviewsFromReq(req)
|
|
247
|
-
* })
|
|
209
|
+
* client.enableAutoPreviewsFromReq(req)
|
|
248
210
|
* ```
|
|
249
211
|
*
|
|
250
|
-
* @
|
|
251
|
-
* cookies.
|
|
212
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
|
|
252
213
|
*/
|
|
253
|
-
enableAutoPreviewsFromReq(
|
|
254
|
-
this.
|
|
255
|
-
this
|
|
214
|
+
enableAutoPreviewsFromReq(request$1) {
|
|
215
|
+
this.enableAutoPreviews();
|
|
216
|
+
this.#autoPreviewsRequest = request$1;
|
|
256
217
|
}
|
|
257
218
|
/**
|
|
258
219
|
* 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.
|
|
220
|
+
* session.
|
|
263
221
|
*
|
|
264
222
|
* @example
|
|
265
223
|
*
|
|
266
224
|
* ```ts
|
|
267
225
|
* client.disableAutoPreviews()
|
|
268
226
|
* ```
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
|
|
269
229
|
*/
|
|
270
230
|
disableAutoPreviews() {
|
|
271
|
-
this
|
|
231
|
+
this.#autoPreviews = false;
|
|
232
|
+
this.#autoPreviewsRequest = void 0;
|
|
272
233
|
}
|
|
273
234
|
/**
|
|
274
|
-
*
|
|
235
|
+
* Fetches pages based on the `params` argument. Results are paginated.
|
|
275
236
|
*
|
|
276
237
|
* @example
|
|
277
238
|
*
|
|
278
239
|
* ```ts
|
|
279
|
-
* const response = await client.get()
|
|
240
|
+
* const response = await client.get({ pageSize: 10 })
|
|
280
241
|
* ```
|
|
281
242
|
*
|
|
282
|
-
* @
|
|
283
|
-
*
|
|
284
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
285
|
-
*
|
|
286
|
-
* @returns A paginated response containing the result of the query.
|
|
243
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
|
|
287
244
|
*/
|
|
288
245
|
async get(params) {
|
|
289
246
|
const { data } = await this._get(params);
|
|
290
247
|
return data;
|
|
291
248
|
}
|
|
292
249
|
/**
|
|
293
|
-
*
|
|
294
|
-
* result, if any.
|
|
250
|
+
* Fetches the first page returned based on the `params` argument.
|
|
295
251
|
*
|
|
296
252
|
* @example
|
|
297
253
|
*
|
|
298
254
|
* ```ts
|
|
299
|
-
* const
|
|
255
|
+
* const page = await client.getFirst()
|
|
300
256
|
* ```
|
|
301
257
|
*
|
|
302
|
-
* @
|
|
303
|
-
*
|
|
304
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
305
|
-
*
|
|
306
|
-
* @returns The first result of the query, if any.
|
|
258
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
|
|
307
259
|
*/
|
|
308
260
|
async getFirst(params) {
|
|
309
261
|
const actualParams = { ...params };
|
|
@@ -317,27 +269,16 @@ var Client = class {
|
|
|
317
269
|
throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
|
|
318
270
|
}
|
|
319
271
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* filter by filters such as `getAllByType`.
|
|
323
|
-
*
|
|
324
|
-
* Queries content from the Prismic repository and returns all matching
|
|
325
|
-
* content. If no filters are provided, all documents will be fetched.
|
|
326
|
-
*
|
|
327
|
-
* This method may make multiple network requests to query all matching
|
|
328
|
-
* content.
|
|
272
|
+
* Fetches all pages based on the `params` argument. This method may make
|
|
273
|
+
* multiple network requests to fetch all matching pages.
|
|
329
274
|
*
|
|
330
275
|
* @example
|
|
331
276
|
*
|
|
332
277
|
* ```ts
|
|
333
|
-
* const
|
|
278
|
+
* const pages = await client.dangerouslyGetAll()
|
|
334
279
|
* ```
|
|
335
280
|
*
|
|
336
|
-
* @
|
|
337
|
-
*
|
|
338
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
339
|
-
*
|
|
340
|
-
* @returns A list of documents matching the query.
|
|
281
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
|
|
341
282
|
*/
|
|
342
283
|
async dangerouslyGetAll(params = {}) {
|
|
343
284
|
var _this$defaultParams2;
|
|
@@ -360,39 +301,21 @@ var Client = class {
|
|
|
360
301
|
return documents.slice(0, limit);
|
|
361
302
|
}
|
|
362
303
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
* @remarks
|
|
366
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
367
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
368
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
369
|
-
* custom type.
|
|
304
|
+
* Fetches a page with a specific ID.
|
|
370
305
|
*
|
|
371
306
|
* @example
|
|
372
307
|
*
|
|
373
308
|
* ```ts
|
|
374
|
-
* const
|
|
309
|
+
* const page = await client.getByID("WW4bKScAAMAqmluX")
|
|
375
310
|
* ```
|
|
376
311
|
*
|
|
377
|
-
* @
|
|
378
|
-
*
|
|
379
|
-
* @param id - ID of the document.
|
|
380
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
381
|
-
*
|
|
382
|
-
* @returns The document with an ID matching the `id` parameter, if a matching
|
|
383
|
-
* document exists.
|
|
312
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
|
|
384
313
|
*/
|
|
385
314
|
async getByID(id, params) {
|
|
386
315
|
return await this.getFirst(require_appendFilters.appendFilters(params, require_filter.filter.at("document.id", id)));
|
|
387
316
|
}
|
|
388
317
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* @remarks
|
|
392
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
393
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
394
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
395
|
-
* custom type.
|
|
318
|
+
* Fetches pages with specific IDs. Results are paginated.
|
|
396
319
|
*
|
|
397
320
|
* @example
|
|
398
321
|
*
|
|
@@ -403,172 +326,95 @@ var Client = class {
|
|
|
403
326
|
* ])
|
|
404
327
|
* ```
|
|
405
328
|
*
|
|
406
|
-
* @
|
|
407
|
-
*
|
|
408
|
-
* @param ids - A list of document IDs.
|
|
409
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
410
|
-
*
|
|
411
|
-
* @returns A paginated response containing documents with IDs matching the
|
|
412
|
-
* `ids` parameter.
|
|
329
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
|
|
413
330
|
*/
|
|
414
331
|
async getByIDs(ids, params) {
|
|
415
332
|
return await this.get(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
416
333
|
}
|
|
417
334
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* This method may make multiple network requests to query all matching
|
|
421
|
-
* content.
|
|
422
|
-
*
|
|
423
|
-
* @remarks
|
|
424
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
425
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
426
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
427
|
-
* custom type.
|
|
335
|
+
* Fetches pages with specific IDs. This method may make multiple network
|
|
336
|
+
* requests to fetch all matching pages.
|
|
428
337
|
*
|
|
429
338
|
* @example
|
|
430
339
|
*
|
|
431
340
|
* ```ts
|
|
432
|
-
* const
|
|
341
|
+
* const pages = await client.getAllByIDs([
|
|
433
342
|
* "WW4bKScAAMAqmluX",
|
|
434
343
|
* "U1kTRgEAAC8A5ldS",
|
|
435
344
|
* ])
|
|
436
345
|
* ```
|
|
437
346
|
*
|
|
438
|
-
* @
|
|
439
|
-
*
|
|
440
|
-
* @param ids - A list of document IDs.
|
|
441
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
442
|
-
*
|
|
443
|
-
* @returns A list of documents with IDs matching the `ids` parameter.
|
|
347
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
|
|
444
348
|
*/
|
|
445
349
|
async getAllByIDs(ids, params) {
|
|
446
350
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
447
351
|
}
|
|
448
352
|
/**
|
|
449
|
-
*
|
|
450
|
-
* custom type.
|
|
451
|
-
*
|
|
452
|
-
* @remarks
|
|
453
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
454
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
455
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
456
|
-
* custom type.
|
|
353
|
+
* Fetches a page with a specific UID and type.
|
|
457
354
|
*
|
|
458
355
|
* @example
|
|
459
356
|
*
|
|
460
357
|
* ```ts
|
|
461
|
-
* const
|
|
358
|
+
* const page = await client.getByUID("blog_post", "my-first-post")
|
|
462
359
|
* ```
|
|
463
360
|
*
|
|
464
|
-
* @
|
|
465
|
-
*
|
|
466
|
-
* @param documentType - The API ID of the document's custom type.
|
|
467
|
-
* @param uid - UID of the document.
|
|
468
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
469
|
-
*
|
|
470
|
-
* @returns The document with a UID matching the `uid` parameter, if a
|
|
471
|
-
* matching document exists.
|
|
361
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
|
|
472
362
|
*/
|
|
473
363
|
async getByUID(documentType, uid, params) {
|
|
474
364
|
return await this.getFirst(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)]));
|
|
475
365
|
}
|
|
476
366
|
/**
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* @remarks
|
|
481
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
482
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
483
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
484
|
-
* custom type.
|
|
367
|
+
* Fetches pages with specific UIDs and a specific type. Results are
|
|
368
|
+
* paginated.
|
|
485
369
|
*
|
|
486
370
|
* @example
|
|
487
371
|
*
|
|
488
372
|
* ```ts
|
|
489
|
-
* const
|
|
373
|
+
* const response = await client.getByUIDs("blog_post", [
|
|
490
374
|
* "my-first-post",
|
|
491
375
|
* "my-second-post",
|
|
492
376
|
* ])
|
|
493
377
|
* ```
|
|
494
378
|
*
|
|
495
|
-
* @
|
|
496
|
-
*
|
|
497
|
-
* @param documentType - The API ID of the document's custom type.
|
|
498
|
-
* @param uids - A list of document UIDs.
|
|
499
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
500
|
-
*
|
|
501
|
-
* @returns A paginated response containing documents with UIDs matching the
|
|
502
|
-
* `uids` parameter.
|
|
379
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
|
|
503
380
|
*/
|
|
504
381
|
async getByUIDs(documentType, uids, params) {
|
|
505
382
|
return await this.get(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
|
|
506
383
|
}
|
|
507
384
|
/**
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* This method may make multiple network requests to query all matching
|
|
512
|
-
* content.
|
|
513
|
-
*
|
|
514
|
-
* @remarks
|
|
515
|
-
* A document's UID is different from its ID. An ID is automatically generated
|
|
516
|
-
* for all documents and is made available on its `id` property. A UID is
|
|
517
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
518
|
-
* custom type.
|
|
385
|
+
* Fetches pages with specific UIDs and a specific type. This method may make
|
|
386
|
+
* multiple network requests to fetch all matching pages.
|
|
519
387
|
*
|
|
520
388
|
* @example
|
|
521
389
|
*
|
|
522
390
|
* ```ts
|
|
523
|
-
* const
|
|
391
|
+
* const pages = await client.getAllByUIDs("blog_post", [
|
|
524
392
|
* "my-first-post",
|
|
525
393
|
* "my-second-post",
|
|
526
394
|
* ])
|
|
527
395
|
* ```
|
|
528
396
|
*
|
|
529
|
-
* @
|
|
530
|
-
*
|
|
531
|
-
* @param documentType - The API ID of the document's custom type.
|
|
532
|
-
* @param uids - A list of document UIDs.
|
|
533
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
534
|
-
*
|
|
535
|
-
* @returns A list of documents with UIDs matching the `uids` parameter.
|
|
397
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
|
|
536
398
|
*/
|
|
537
399
|
async getAllByUIDs(documentType, uids, params) {
|
|
538
400
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, [require_typeFilter.typeFilter(documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)]));
|
|
539
401
|
}
|
|
540
402
|
/**
|
|
541
|
-
*
|
|
542
|
-
* custom type.
|
|
543
|
-
*
|
|
544
|
-
* @remarks
|
|
545
|
-
* A singleton document is one that is configured in Prismic to only allow one
|
|
546
|
-
* instance. For example, a repository may be configured to contain just one
|
|
547
|
-
* Settings document. This is in contrast to a repeatable custom type which
|
|
548
|
-
* allows multiple instances of itself.
|
|
403
|
+
* Fetches a specific single type page.
|
|
549
404
|
*
|
|
550
405
|
* @example
|
|
551
406
|
*
|
|
552
407
|
* ```ts
|
|
553
|
-
* const
|
|
408
|
+
* const page = await client.getSingle("settings")
|
|
554
409
|
* ```
|
|
555
410
|
*
|
|
556
|
-
* @
|
|
557
|
-
*
|
|
558
|
-
* @param documentType - The API ID of the singleton custom type.
|
|
559
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
560
|
-
*
|
|
561
|
-
* @returns The singleton document for the custom type, if a matching document
|
|
562
|
-
* exists.
|
|
411
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
|
|
563
412
|
*/
|
|
564
413
|
async getSingle(documentType, params) {
|
|
565
414
|
return await this.getFirst(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
566
415
|
}
|
|
567
416
|
/**
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* Use `getAllByType` instead if you need to query all documents for a
|
|
571
|
-
* specific custom type.
|
|
417
|
+
* Fetches pages with a specific type. Results are paginated.
|
|
572
418
|
*
|
|
573
419
|
* @example
|
|
574
420
|
*
|
|
@@ -576,177 +422,124 @@ var Client = class {
|
|
|
576
422
|
* const response = await client.getByType("blog_post")
|
|
577
423
|
* ```
|
|
578
424
|
*
|
|
579
|
-
* @
|
|
580
|
-
*
|
|
581
|
-
* @param documentType - The API ID of the custom type.
|
|
582
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
583
|
-
*
|
|
584
|
-
* @returns A paginated response containing documents of the custom type.
|
|
425
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
|
|
585
426
|
*/
|
|
586
427
|
async getByType(documentType, params) {
|
|
587
428
|
return await this.get(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
588
429
|
}
|
|
589
430
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* This method may make multiple network requests to query all matching
|
|
594
|
-
* content.
|
|
431
|
+
* Fetches pages with a specific type. This method may make multiple network
|
|
432
|
+
* requests to fetch all matching documents.
|
|
595
433
|
*
|
|
596
434
|
* @example
|
|
597
435
|
*
|
|
598
436
|
* ```ts
|
|
599
|
-
* const
|
|
437
|
+
* const pages = await client.getAllByType("blog_post")
|
|
600
438
|
* ```
|
|
601
439
|
*
|
|
602
|
-
* @
|
|
603
|
-
*
|
|
604
|
-
* @param documentType - The API ID of the custom type.
|
|
605
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
606
|
-
*
|
|
607
|
-
* @returns A list of all documents of the custom type.
|
|
440
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
|
|
608
441
|
*/
|
|
609
442
|
async getAllByType(documentType, params) {
|
|
610
443
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_typeFilter.typeFilter(documentType)));
|
|
611
444
|
}
|
|
612
445
|
/**
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* Use `getAllByTag` instead if you need to query all documents with a
|
|
616
|
-
* specific tag.
|
|
446
|
+
* Fetches pages with a specific tag. Results are paginated.
|
|
617
447
|
*
|
|
618
448
|
* @example
|
|
619
449
|
*
|
|
620
450
|
* ```ts
|
|
621
|
-
* const response = await client.getByTag("
|
|
451
|
+
* const response = await client.getByTag("featured")
|
|
622
452
|
* ```
|
|
623
453
|
*
|
|
624
|
-
* @
|
|
625
|
-
*
|
|
626
|
-
* @param tag - The tag that must be included on a document.
|
|
627
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
628
|
-
*
|
|
629
|
-
* @returns A paginated response containing documents with the tag.
|
|
454
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
|
|
630
455
|
*/
|
|
631
456
|
async getByTag(tag, params) {
|
|
632
457
|
return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
|
|
633
458
|
}
|
|
634
459
|
/**
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
* This method may make multiple network requests to query all matching
|
|
638
|
-
* content.
|
|
460
|
+
* Fetches pages with a specific tag. This method may make multiple network
|
|
461
|
+
* requests to fetch all matching documents.
|
|
639
462
|
*
|
|
640
463
|
* @example
|
|
641
464
|
*
|
|
642
465
|
* ```ts
|
|
643
|
-
* const
|
|
466
|
+
* const pages = await client.getAllByTag("featured")
|
|
644
467
|
* ```
|
|
645
468
|
*
|
|
646
|
-
* @
|
|
647
|
-
*
|
|
648
|
-
* @param tag - The tag that must be included on a document.
|
|
649
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
650
|
-
*
|
|
651
|
-
* @returns A list of all documents with the tag.
|
|
469
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
|
|
652
470
|
*/
|
|
653
471
|
async getAllByTag(tag, params) {
|
|
654
472
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tag)));
|
|
655
473
|
}
|
|
656
474
|
/**
|
|
657
|
-
*
|
|
658
|
-
* document must be tagged with all of the queried tags to be included.
|
|
475
|
+
* Fetches pages with every tag from a list of tags. Results are paginated.
|
|
659
476
|
*
|
|
660
477
|
* @example
|
|
661
478
|
*
|
|
662
479
|
* ```ts
|
|
663
|
-
* const response = await client.getByEveryTag(["
|
|
480
|
+
* const response = await client.getByEveryTag(["featured", "homepage"])
|
|
664
481
|
* ```
|
|
665
482
|
*
|
|
666
|
-
* @
|
|
667
|
-
*
|
|
668
|
-
* @param tags - A list of tags that must be included on a document.
|
|
669
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
670
|
-
*
|
|
671
|
-
* @returns A paginated response containing documents with the tags.
|
|
483
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
|
|
672
484
|
*/
|
|
673
485
|
async getByEveryTag(tags, params) {
|
|
674
486
|
return await this.get(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
|
|
675
487
|
}
|
|
676
488
|
/**
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
* This method may make multiple network requests to query all matching
|
|
681
|
-
* content.
|
|
489
|
+
* Fetches pages with every tag from a list of tags. This method may make
|
|
490
|
+
* multiple network requests to fetch all matching pages.
|
|
682
491
|
*
|
|
683
492
|
* @example
|
|
684
493
|
*
|
|
685
494
|
* ```ts
|
|
686
|
-
* const
|
|
495
|
+
* const pages = await client.getAllByEveryTag(["featured", "homepage"])
|
|
687
496
|
* ```
|
|
688
497
|
*
|
|
689
|
-
* @
|
|
690
|
-
*
|
|
691
|
-
* @param tags - A list of tags that must be included on a document.
|
|
692
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
693
|
-
*
|
|
694
|
-
* @returns A list of all documents with the tags.
|
|
498
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
|
|
695
499
|
*/
|
|
696
500
|
async getAllByEveryTag(tags, params) {
|
|
697
501
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_everyTagFilter.everyTagFilter(tags)));
|
|
698
502
|
}
|
|
699
503
|
/**
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
* included.
|
|
504
|
+
* Fetches pages with at least one tag from a list of tags. Results are
|
|
505
|
+
* paginated.
|
|
703
506
|
*
|
|
704
507
|
* @example
|
|
705
508
|
*
|
|
706
509
|
* ```ts
|
|
707
|
-
* const response = await client.
|
|
510
|
+
* const response = await client.getBySomeTags(["featured", "homepage"])
|
|
708
511
|
* ```
|
|
709
512
|
*
|
|
710
|
-
* @
|
|
711
|
-
*
|
|
712
|
-
* @param tags - A list of tags that must be included on a document.
|
|
713
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
714
|
-
*
|
|
715
|
-
* @returns A paginated response containing documents with at least one of the
|
|
716
|
-
* tags.
|
|
513
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
|
|
717
514
|
*/
|
|
718
515
|
async getBySomeTags(tags, params) {
|
|
719
516
|
return await this.get(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
|
|
720
517
|
}
|
|
721
518
|
/**
|
|
722
|
-
*
|
|
723
|
-
*
|
|
724
|
-
* included.
|
|
725
|
-
*
|
|
726
|
-
* This method may make multiple network requests to query all matching
|
|
727
|
-
* content.
|
|
519
|
+
* Fetches pages with at least one tag from a list of tags. This method may
|
|
520
|
+
* make multiple network requests to fetch all matching documents.
|
|
728
521
|
*
|
|
729
522
|
* @example
|
|
730
523
|
*
|
|
731
524
|
* ```ts
|
|
732
|
-
* const
|
|
525
|
+
* const pages = await client.getAllBySomeTags(["featured", "homepage"])
|
|
733
526
|
* ```
|
|
734
527
|
*
|
|
735
|
-
* @
|
|
736
|
-
*
|
|
737
|
-
* @param tags - A list of tags that must be included on a document.
|
|
738
|
-
* @param params - Parameters to filter, sort, and paginate the results.
|
|
739
|
-
*
|
|
740
|
-
* @returns A list of all documents with at least one of the tags.
|
|
528
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
|
|
741
529
|
*/
|
|
742
530
|
async getAllBySomeTags(tags, params) {
|
|
743
531
|
return await this.dangerouslyGetAll(require_appendFilters.appendFilters(params, require_someTagsFilter.someTagsFilter(tags)));
|
|
744
532
|
}
|
|
745
533
|
/**
|
|
746
|
-
*
|
|
747
|
-
*
|
|
534
|
+
* Fetches metadata about the client's Prismic repository.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
*
|
|
538
|
+
* ```ts
|
|
539
|
+
* const repository = await client.getRepository()
|
|
540
|
+
* ```
|
|
748
541
|
*
|
|
749
|
-
* @
|
|
542
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrepository}
|
|
750
543
|
*/
|
|
751
544
|
async getRepository(params) {
|
|
752
545
|
if (this.#cachedRepository && this.#cachedRepositoryExpiration > Date.now()) return this.#cachedRepository;
|
|
@@ -768,79 +561,115 @@ var Client = class {
|
|
|
768
561
|
}
|
|
769
562
|
}
|
|
770
563
|
/**
|
|
771
|
-
*
|
|
564
|
+
* Fetches the repository's active refs.
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
772
567
|
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
*
|
|
568
|
+
* ```ts
|
|
569
|
+
* const refs = await client.getRefs()
|
|
570
|
+
* ```
|
|
776
571
|
*
|
|
777
|
-
* @
|
|
572
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefs}
|
|
778
573
|
*/
|
|
779
574
|
async getRefs(params) {
|
|
780
575
|
return (await this.getRepository(params)).refs;
|
|
781
576
|
}
|
|
782
577
|
/**
|
|
783
|
-
*
|
|
578
|
+
* Fetches a ref by its ID.
|
|
784
579
|
*
|
|
785
|
-
* @
|
|
580
|
+
* @example
|
|
581
|
+
*
|
|
582
|
+
* ```ts
|
|
583
|
+
* const ref = await client.getRefByID("YhE3YhEAACIA4321")
|
|
584
|
+
* ```
|
|
786
585
|
*
|
|
787
|
-
* @
|
|
586
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
|
|
788
587
|
*/
|
|
789
588
|
async getRefByID(id, params) {
|
|
790
589
|
return require_findRefByID.findRefByID(await this.getRefs(params), id);
|
|
791
590
|
}
|
|
792
591
|
/**
|
|
793
|
-
*
|
|
592
|
+
* Fetches a ref by its label. A release ref's label is its name shown in the
|
|
593
|
+
* Page Builder.
|
|
794
594
|
*
|
|
795
|
-
* @
|
|
595
|
+
* @example
|
|
796
596
|
*
|
|
797
|
-
*
|
|
597
|
+
* ```ts
|
|
598
|
+
* const ref = await client.getRefByLabel("My Release")
|
|
599
|
+
* ```
|
|
600
|
+
*
|
|
601
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
|
|
798
602
|
*/
|
|
799
603
|
async getRefByLabel(label, params) {
|
|
800
604
|
return require_findRefByLabel.findRefByLabel(await this.getRefs(params), label);
|
|
801
605
|
}
|
|
802
606
|
/**
|
|
803
|
-
*
|
|
804
|
-
*
|
|
607
|
+
* Fetches the repository's master ref.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
*
|
|
611
|
+
* ```ts
|
|
612
|
+
* const masterRef = await client.getMasterRef()
|
|
613
|
+
* ```
|
|
805
614
|
*
|
|
806
|
-
* @
|
|
615
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
|
|
807
616
|
*/
|
|
808
617
|
async getMasterRef(params) {
|
|
809
618
|
return require_findMasterRef.findMasterRef(await this.getRefs(params));
|
|
810
619
|
}
|
|
811
620
|
/**
|
|
812
|
-
*
|
|
813
|
-
* used to group content changes before publishing.
|
|
621
|
+
* Fetches the repository's active releases.
|
|
814
622
|
*
|
|
815
|
-
* @
|
|
623
|
+
* @example
|
|
624
|
+
*
|
|
625
|
+
* ```ts
|
|
626
|
+
* const releases = await client.getReleases()
|
|
627
|
+
* ```
|
|
628
|
+
*
|
|
629
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleases}
|
|
816
630
|
*/
|
|
817
631
|
async getReleases(params) {
|
|
818
632
|
return (await this.getRefs(params)).filter((ref) => !ref.isMasterRef);
|
|
819
633
|
}
|
|
820
634
|
/**
|
|
821
|
-
*
|
|
635
|
+
* Fetches a release with a specific ID.
|
|
822
636
|
*
|
|
823
|
-
* @
|
|
637
|
+
* @example
|
|
638
|
+
*
|
|
639
|
+
* ```ts
|
|
640
|
+
* const release = await client.getReleaseByID("YhE3YhEAACIA4321")
|
|
641
|
+
* ```
|
|
824
642
|
*
|
|
825
|
-
* @
|
|
643
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
|
|
826
644
|
*/
|
|
827
645
|
async getReleaseByID(id, params) {
|
|
828
646
|
return require_findRefByID.findRefByID(await this.getReleases(params), id);
|
|
829
647
|
}
|
|
830
648
|
/**
|
|
831
|
-
*
|
|
649
|
+
* Fetches a release by its label. A release ref's label is its name shown in
|
|
650
|
+
* the Page Builder.
|
|
832
651
|
*
|
|
833
|
-
* @
|
|
652
|
+
* @example
|
|
834
653
|
*
|
|
835
|
-
*
|
|
654
|
+
* ```ts
|
|
655
|
+
* const release = await client.getReleaseByLabel("My Release")
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
|
|
836
659
|
*/
|
|
837
660
|
async getReleaseByLabel(label, params) {
|
|
838
661
|
return require_findRefByLabel.findRefByLabel(await this.getReleases(params), label);
|
|
839
662
|
}
|
|
840
663
|
/**
|
|
841
|
-
*
|
|
664
|
+
* Fetches the repository's page tags.
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
*
|
|
668
|
+
* ```ts
|
|
669
|
+
* const tags = await client.getTags()
|
|
670
|
+
* ```
|
|
842
671
|
*
|
|
843
|
-
* @
|
|
672
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#gettags}
|
|
844
673
|
*/
|
|
845
674
|
async getTags(params) {
|
|
846
675
|
const repository = await this.getRepository(params);
|
|
@@ -854,14 +683,20 @@ var Client = class {
|
|
|
854
683
|
return repository.tags;
|
|
855
684
|
}
|
|
856
685
|
/**
|
|
857
|
-
* Builds a
|
|
686
|
+
* Builds a Content API query URL with a set of parameters.
|
|
858
687
|
*
|
|
859
|
-
* @
|
|
688
|
+
* @example
|
|
689
|
+
*
|
|
690
|
+
* ```ts
|
|
691
|
+
* const url = await client.buildQueryURL({
|
|
692
|
+
* filters: [filter.at("document.type", "blog_post")],
|
|
693
|
+
* })
|
|
694
|
+
* ```
|
|
860
695
|
*
|
|
861
|
-
* @
|
|
696
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
|
|
862
697
|
*/
|
|
863
698
|
async buildQueryURL({ signal, fetchOptions,...params } = {}) {
|
|
864
|
-
const ref = params.ref || await this
|
|
699
|
+
const ref = params.ref || await this.#getResolvedRef({
|
|
865
700
|
accessToken: params.accessToken,
|
|
866
701
|
signal,
|
|
867
702
|
fetchOptions
|
|
@@ -882,23 +717,18 @@ var Client = class {
|
|
|
882
717
|
});
|
|
883
718
|
}
|
|
884
719
|
/**
|
|
885
|
-
*
|
|
886
|
-
* session. The result of this method should be used to redirect the user to
|
|
887
|
-
* the document's URL.
|
|
720
|
+
* Fetches a previewed page's URL using a preview token and page ID.
|
|
888
721
|
*
|
|
889
722
|
* @example
|
|
890
723
|
*
|
|
891
724
|
* ```ts
|
|
892
|
-
*
|
|
893
|
-
* linkResolver
|
|
894
|
-
* defaultURL:
|
|
895
|
-
*
|
|
725
|
+
* const url = await client.resolvePreviewURL({
|
|
726
|
+
* linkResolver,
|
|
727
|
+
* defaultURL: "/",
|
|
728
|
+
* })
|
|
896
729
|
* ```
|
|
897
730
|
*
|
|
898
|
-
* @
|
|
899
|
-
*
|
|
900
|
-
* @returns The URL for the previewed document during an active preview
|
|
901
|
-
* session. The user should be redirected to this URL.
|
|
731
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#resolvepreviewurl}
|
|
902
732
|
*/
|
|
903
733
|
async resolvePreviewURL(args) {
|
|
904
734
|
let documentID = args.documentID;
|
|
@@ -907,13 +737,13 @@ var Client = class {
|
|
|
907
737
|
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
908
738
|
documentID = documentID || searchParams.get("documentId");
|
|
909
739
|
previewToken = previewToken || searchParams.get("token");
|
|
910
|
-
} else if (this
|
|
911
|
-
if ("query" in this
|
|
912
|
-
var _this$
|
|
913
|
-
documentID = documentID || ((_this$
|
|
914
|
-
previewToken = previewToken || ((_this$
|
|
915
|
-
} else if ("url" in this
|
|
916
|
-
const searchParams = new URL(this.
|
|
740
|
+
} else if (this.#autoPreviewsRequest) {
|
|
741
|
+
if ("query" in this.#autoPreviewsRequest) {
|
|
742
|
+
var _this$autoPreviewsReq, _this$autoPreviewsReq2;
|
|
743
|
+
documentID = documentID || ((_this$autoPreviewsReq = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq === void 0 ? void 0 : _this$autoPreviewsReq.documentId);
|
|
744
|
+
previewToken = previewToken || ((_this$autoPreviewsReq2 = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq2 === void 0 ? void 0 : _this$autoPreviewsReq2.token);
|
|
745
|
+
} else if ("url" in this.#autoPreviewsRequest && this.#autoPreviewsRequest.url) {
|
|
746
|
+
const searchParams = new URL(this.#autoPreviewsRequest.url, "missing-host://").searchParams;
|
|
917
747
|
documentID = documentID || searchParams.get("documentId");
|
|
918
748
|
previewToken = previewToken || searchParams.get("token");
|
|
919
749
|
}
|
|
@@ -930,104 +760,80 @@ var Client = class {
|
|
|
930
760
|
return args.defaultURL;
|
|
931
761
|
}
|
|
932
762
|
/**
|
|
933
|
-
* Configures the client to query the latest published content
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
937
|
-
* that query.
|
|
763
|
+
* Configures the client to query the latest published content. This is the
|
|
764
|
+
* client's default mode.
|
|
938
765
|
*
|
|
939
766
|
* @example
|
|
940
767
|
*
|
|
941
768
|
* ```ts
|
|
942
|
-
*
|
|
943
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
769
|
+
* client.queryLatestContent()
|
|
944
770
|
* ```
|
|
771
|
+
*
|
|
772
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
|
|
945
773
|
*/
|
|
946
774
|
queryLatestContent() {
|
|
947
|
-
this
|
|
775
|
+
this.#getRef = void 0;
|
|
948
776
|
}
|
|
949
777
|
/**
|
|
950
|
-
* Configures the client to query content from a specific
|
|
951
|
-
* by its ID for all future queries.
|
|
952
|
-
*
|
|
953
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
954
|
-
* that query.
|
|
778
|
+
* Configures the client to query content from a release with a specific ID.
|
|
955
779
|
*
|
|
956
780
|
* @example
|
|
957
781
|
*
|
|
958
782
|
* ```ts
|
|
959
|
-
*
|
|
960
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
783
|
+
* client.queryContentFromReleaseByID("YhE3YhEAACIA4321")
|
|
961
784
|
* ```
|
|
962
785
|
*
|
|
963
|
-
* @
|
|
786
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
|
|
964
787
|
*/
|
|
965
|
-
queryContentFromReleaseByID(
|
|
966
|
-
this
|
|
967
|
-
|
|
968
|
-
mode: RefStateMode.ReleaseID,
|
|
969
|
-
releaseID
|
|
788
|
+
queryContentFromReleaseByID(id) {
|
|
789
|
+
this.#getRef = async (params) => {
|
|
790
|
+
return (await this.getReleaseByID(id, params)).ref;
|
|
970
791
|
};
|
|
971
792
|
}
|
|
972
793
|
/**
|
|
973
|
-
* Configures the client to query content from a
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
977
|
-
* that query.
|
|
794
|
+
* Configures the client to query content from a release with a specific
|
|
795
|
+
* label.
|
|
978
796
|
*
|
|
979
797
|
* @example
|
|
980
798
|
*
|
|
981
799
|
* ```ts
|
|
982
|
-
*
|
|
983
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
800
|
+
* client.queryContentFromReleaseByLabel("My Release")
|
|
984
801
|
* ```
|
|
985
802
|
*
|
|
986
|
-
* @
|
|
803
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
|
|
987
804
|
*/
|
|
988
|
-
queryContentFromReleaseByLabel(
|
|
989
|
-
this
|
|
990
|
-
|
|
991
|
-
mode: RefStateMode.ReleaseLabel,
|
|
992
|
-
releaseLabel
|
|
805
|
+
queryContentFromReleaseByLabel(label) {
|
|
806
|
+
this.#getRef = async (params) => {
|
|
807
|
+
return (await this.getReleaseByLabel(label, params)).ref;
|
|
993
808
|
};
|
|
994
809
|
}
|
|
995
810
|
/**
|
|
996
|
-
* Configures the client to query content from a specific ref.
|
|
997
|
-
* provided as a string or a function.
|
|
998
|
-
*
|
|
999
|
-
* If a function is provided, the ref is fetched lazily before each query. The
|
|
1000
|
-
* function may also be asynchronous.
|
|
811
|
+
* Configures the client to query content from a specific ref.
|
|
1001
812
|
*
|
|
1002
813
|
* @example
|
|
1003
814
|
*
|
|
1004
815
|
* ```ts
|
|
1005
|
-
*
|
|
1006
|
-
* const document = await client.getByID("WW4bKScAAMAqmluX")
|
|
816
|
+
* client.queryContentFromRef("my-ref")
|
|
1007
817
|
* ```
|
|
1008
818
|
*
|
|
1009
|
-
* @
|
|
1010
|
-
* content.
|
|
819
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
|
|
1011
820
|
*/
|
|
1012
821
|
queryContentFromRef(ref) {
|
|
1013
|
-
this
|
|
1014
|
-
...this.refState,
|
|
1015
|
-
mode: RefStateMode.Manual,
|
|
1016
|
-
ref
|
|
1017
|
-
};
|
|
822
|
+
this.#getRef = typeof ref === "string" ? () => ref : ref;
|
|
1018
823
|
}
|
|
1019
824
|
/**
|
|
1020
|
-
* A `fetch()` function
|
|
1021
|
-
*
|
|
1022
|
-
* and Authorization headers. Queries will automatically be minified by
|
|
1023
|
-
* removing whitespace where possible.
|
|
825
|
+
* A preconfigured `fetch()` function for Prismic's GraphQL API that can be
|
|
826
|
+
* provided to GraphQL clients.
|
|
1024
827
|
*
|
|
1025
828
|
* @example
|
|
1026
829
|
*
|
|
1027
830
|
* ```ts
|
|
831
|
+
* import { createClient, getGraphQLEndpoint } from "@prismicio/client"
|
|
832
|
+
*
|
|
833
|
+
* const client = createClient("example-prismic-repo")
|
|
1028
834
|
* const graphQLClient = new ApolloClient({
|
|
1029
835
|
* link: new HttpLink({
|
|
1030
|
-
* uri:
|
|
836
|
+
* uri: getGraphQLEndpoint(client.repositoryName),
|
|
1031
837
|
* // Provide `client.graphQLFetch` as the fetch implementation.
|
|
1032
838
|
* fetch: client.graphQLFetch,
|
|
1033
839
|
* // Using GET is required.
|
|
@@ -1037,17 +843,11 @@ var Client = class {
|
|
|
1037
843
|
* })
|
|
1038
844
|
* ```
|
|
1039
845
|
*
|
|
1040
|
-
* @
|
|
1041
|
-
* @param init - The `fetch()` `init` parameter. Only plain objects are
|
|
1042
|
-
* supported.
|
|
1043
|
-
*
|
|
1044
|
-
* @returns The `fetch()` Response for the request.
|
|
1045
|
-
*
|
|
1046
|
-
* @experimental
|
|
846
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
|
|
1047
847
|
*/
|
|
1048
848
|
async graphQLFetch(input, init) {
|
|
1049
849
|
const repository = await this.getRepository();
|
|
1050
|
-
const ref = await this
|
|
850
|
+
const ref = await this.#getResolvedRef();
|
|
1051
851
|
const unsanitizedHeaders = {
|
|
1052
852
|
"Prismic-ref": ref,
|
|
1053
853
|
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
@@ -1088,27 +888,16 @@ var Client = class {
|
|
|
1088
888
|
*
|
|
1089
889
|
* @returns The ref to use during a query.
|
|
1090
890
|
*/
|
|
1091
|
-
async
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
if ((_this$refState$httpRe3 = this.refState.httpRequest) === null || _this$refState$httpRe3 === void 0 ? void 0 : _this$refState$httpRe3.headers) {
|
|
1097
|
-
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1098
|
-
else if ("cookie" in this.refState.httpRequest.headers) cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1099
|
-
} else if ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) cookieJar = globalThis.document.cookie;
|
|
1100
|
-
if (cookieJar) previewRef = require_getPreviewCookie.getPreviewCookie(cookieJar);
|
|
891
|
+
async #getResolvedRef(params) {
|
|
892
|
+
var _this$getRef;
|
|
893
|
+
if (this.#autoPreviews) {
|
|
894
|
+
var _this$autoPreviewsReq3, _globalThis$document;
|
|
895
|
+
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) ?? "");
|
|
1101
896
|
if (previewRef) return previewRef;
|
|
1102
897
|
}
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
else if (refModeType === RefStateMode.ReleaseLabel) return require_findRefByLabel.findRefByLabel(repository.refs, this.refState.releaseLabel).ref;
|
|
1107
|
-
else if (refModeType === RefStateMode.Manual) {
|
|
1108
|
-
const res = await require_castThunk.castThunk(this.refState.ref)();
|
|
1109
|
-
if (typeof res === "string") return res;
|
|
1110
|
-
}
|
|
1111
|
-
return require_findMasterRef.findMasterRef(repository.refs).ref;
|
|
898
|
+
const ref = await ((_this$getRef = this.#getRef) === null || _this$getRef === void 0 ? void 0 : _this$getRef.call(this, params));
|
|
899
|
+
if (ref) return ref;
|
|
900
|
+
return (await this.getMasterRef(params)).ref;
|
|
1112
901
|
}
|
|
1113
902
|
/**
|
|
1114
903
|
* The private implementation of `this.get`. It returns the API response and
|