@prismicio/client 6.4.3 → 6.6.0

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/index.d.ts CHANGED
@@ -53,6 +53,35 @@ declare const isRepositoryName: (input: string) => boolean;
53
53
  */
54
54
  declare const isRepositoryEndpoint: (input: string) => boolean;
55
55
 
56
+ /**
57
+ * Functions like TypeScript's native `Extract` utility type with added support
58
+ * to fall back to a value if the resulting union is `never`.
59
+ *
60
+ * @example
61
+ *
62
+ * ```ts
63
+ * ExtractOrFallback<"a" | "b", "a"> // => "a"
64
+ * ExtractOrFallback<"a" | "b", "c"> // => "a" | "b"
65
+ * ExtractOrFallback<"a" | "b", "c", "foo"> // => "foo"
66
+ * ```
67
+ *
68
+ * @typeParam T - The union from which values will be extracted.
69
+ * @typeParam U - The extraction condition.
70
+ * @typeParam Fallback - The value to return if the resulting union is `never`.
71
+ * Defaults to `T`.
72
+ */
73
+ declare type ExtractOrFallback<T, U, Fallback = T> = Extract<T, U> extends never ? Fallback : Extract<T, U>;
74
+ /**
75
+ * Extracts one or more Prismic document types that match a given Prismic
76
+ * document type. If no matches are found, no extraction is performed and the
77
+ * union of all provided Prismic document types are returned.
78
+ *
79
+ * @typeParam TDocuments - Prismic document types from which to extract.
80
+ * @typeParam TDocumentType - Type(s) to match `TDocuments` against.
81
+ */
82
+ declare type ExtractDocumentType<TDocuments extends prismicT.PrismicDocument, TDocumentType extends TDocuments["type"]> = ExtractOrFallback<TDocuments, {
83
+ type: TDocumentType;
84
+ }>;
56
85
  /**
57
86
  * A universal API to make network requests. A subset of the `fetch()` API.
58
87
  *
@@ -71,6 +100,8 @@ declare type AbortSignalLike = {
71
100
  removeEventListener: any;
72
101
  dispatchEvent: any;
73
102
  onabort: any;
103
+ reason: any;
104
+ throwIfAborted: any;
74
105
  };
75
106
  /**
76
107
  * The minimum required properties from RequestInit.
@@ -90,12 +121,25 @@ interface ResponseLike {
90
121
  * The minimum required properties to treat as an HTTP Request for automatic
91
122
  * Prismic preview support.
92
123
  */
93
- interface HttpRequestLike {
124
+ declare type HttpRequestLike = /**
125
+ * Web API Request
126
+ *
127
+ * @see http://developer.mozilla.org/en-US/docs/Web/API/Request
128
+ */ {
129
+ headers?: {
130
+ get(name: string): string | null;
131
+ };
132
+ url?: string;
133
+ }
134
+ /**
135
+ * Express-style Request
136
+ */
137
+ | {
94
138
  headers?: {
95
139
  cookie?: string;
96
140
  };
97
141
  query?: Record<string, unknown>;
98
- }
142
+ };
99
143
  /**
100
144
  * An `orderings` parameter that orders the results by the specified field.
101
145
  *
@@ -328,6 +372,13 @@ declare type ResolvePreviewArgs<LinkResolverReturnType> = {
328
372
  */
329
373
  documentID?: string;
330
374
  };
375
+ /**
376
+ * Type definitions for the `createClient()` function. May be augmented by
377
+ * third-party libraries.
378
+ */
379
+ interface CreateClient {
380
+ <TDocuments extends prismicT.PrismicDocument>(...args: ConstructorParameters<typeof Client>): Client<TDocuments>;
381
+ }
331
382
  /**
332
383
  * Creates a Prismic client that can be used to query a repository.
333
384
  *
@@ -341,6 +392,8 @@ declare type ResolvePreviewArgs<LinkResolverReturnType> = {
341
392
  * createClient("https://qwerty.cdn.prismic.io/api/v2");
342
393
  * ```
343
394
  *
395
+ * @typeParam TDocuments - A map of Prismic document type IDs mapped to their
396
+ * TypeScript type.
344
397
  * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
345
398
  * API V2 endpoint for the repository.
346
399
  * @param options - Configuration that determines how content will be queried
@@ -348,15 +401,18 @@ declare type ResolvePreviewArgs<LinkResolverReturnType> = {
348
401
  *
349
402
  * @returns A client that can query content from the repository.
350
403
  */
351
- declare const createClient: (repositoryNameOrEndpoint: string, options?: ClientConfig | undefined) => Client;
404
+ declare const createClient: CreateClient;
352
405
  /**
353
406
  * A client that allows querying content from a Prismic repository.
354
407
  *
355
408
  * If used in an environment where a global `fetch` function is unavailable,
356
409
  * such as Node.js, the `fetch` option must be provided as part of the `options`
357
410
  * parameter.
411
+ *
412
+ * @typeParam TDocuments - Document types that are registered for the Prismic
413
+ * repository. Query methods will automatically be typed based on this type.
358
414
  */
359
- declare class Client {
415
+ declare class Client<TDocuments extends prismicT.PrismicDocument = prismicT.PrismicDocument> {
360
416
  /**
361
417
  * The Prismic REST API V2 endpoint for the repository (use
362
418
  * `prismic.getRepositoryEndpoint` for the default endpoint).
@@ -478,7 +534,7 @@ declare class Client {
478
534
  *
479
535
  * @returns A paginated response containing the result of the query.
480
536
  */
481
- query<TDocument extends prismicT.PrismicDocument>(predicates: NonNullable<BuildQueryURLArgs["predicates"]>, params?: Partial<Omit<BuildQueryURLArgs, "predicates">> & FetchParams): Promise<prismicT.Query<TDocument>>;
537
+ query<TDocument extends TDocuments>(predicates: NonNullable<BuildQueryURLArgs["predicates"]>, params?: Partial<Omit<BuildQueryURLArgs, "predicates">> & FetchParams): Promise<prismicT.Query<TDocument>>;
482
538
  /**
483
539
  * Queries content from the Prismic repository.
484
540
  *
@@ -493,7 +549,7 @@ declare class Client {
493
549
  *
494
550
  * @returns A paginated response containing the result of the query.
495
551
  */
496
- get<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
552
+ get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
497
553
  /**
498
554
  * Queries content from the Prismic repository and returns only the first
499
555
  * result, if any.
@@ -508,7 +564,7 @@ declare class Client {
508
564
  * @param params - Parameters to filter, sort, and paginate results. @returns
509
565
  * The first result of the query, if any.
510
566
  */
511
- getFirst<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
567
+ getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
512
568
  /**
513
569
  * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
514
570
  * require more resources than other methods. Prefer using other methods that
@@ -530,7 +586,7 @@ declare class Client {
530
586
  *
531
587
  * @returns A list of documents matching the query.
532
588
  */
533
- dangerouslyGetAll<TDocument extends prismicT.PrismicDocument>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
589
+ dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
534
590
  /**
535
591
  * Queries a document from the Prismic repository with a specific ID.
536
592
  *
@@ -551,7 +607,7 @@ declare class Client {
551
607
  * @returns The document with an ID matching the `id` parameter, if a matching
552
608
  * document exists.
553
609
  */
554
- getByID<TDocument extends prismicT.PrismicDocument>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
610
+ getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
555
611
  /**
556
612
  * Queries documents from the Prismic repository with specific IDs.
557
613
  *
@@ -575,7 +631,7 @@ declare class Client {
575
631
  * @returns A paginated response containing documents with IDs matching the
576
632
  * `ids` parameter.
577
633
  */
578
- getByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
634
+ getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
579
635
  /**
580
636
  * Queries all documents from the Prismic repository with specific IDs.
581
637
  *
@@ -600,7 +656,7 @@ declare class Client {
600
656
  *
601
657
  * @returns A list of documents with IDs matching the `ids` parameter.
602
658
  */
603
- getAllByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
659
+ getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
604
660
  /**
605
661
  * Queries a document from the Prismic repository with a specific UID and Custom Type.
606
662
  *
@@ -622,7 +678,7 @@ declare class Client {
622
678
  * @returns The document with a UID matching the `uid` parameter, if a
623
679
  * matching document exists.
624
680
  */
625
- getByUID<TDocument extends prismicT.PrismicDocument>(documentType: string, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
681
+ getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocuments, TDocumentType>>;
626
682
  /**
627
683
  * Queries document from the Prismic repository with specific UIDs and Custom Type.
628
684
  *
@@ -647,7 +703,7 @@ declare class Client {
647
703
  * @returns A paginated response containing documents with UIDs matching the
648
704
  * `uids` parameter.
649
705
  */
650
- getByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
706
+ getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<ExtractDocumentType<TDocuments, TDocumentType>>>;
651
707
  /**
652
708
  * Queries all documents from the Prismic repository with specific UIDs and Custom Type.
653
709
  *
@@ -673,7 +729,7 @@ declare class Client {
673
729
  *
674
730
  * @returns A list of documents with UIDs matching the `uids` parameter.
675
731
  */
676
- getAllByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
732
+ getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocuments, TDocumentType>[]>;
677
733
  /**
678
734
  * Queries a singleton document from the Prismic repository for a specific Custom Type.
679
735
  *
@@ -694,7 +750,7 @@ declare class Client {
694
750
  *
695
751
  * @returns The singleton document for the Custom Type, if a matching document exists.
696
752
  */
697
- getSingle<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
753
+ getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocuments, TDocumentType>>;
698
754
  /**
699
755
  * Queries documents from the Prismic repository for a specific Custom Type.
700
756
  *
@@ -713,7 +769,7 @@ declare class Client {
713
769
  *
714
770
  * @returns A paginated response containing documents of the Custom Type.
715
771
  */
716
- getByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
772
+ getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<ExtractDocumentType<TDocuments, TDocumentType>>>;
717
773
  /**
718
774
  * Queries all documents from the Prismic repository for a specific Custom Type.
719
775
  *
@@ -731,7 +787,7 @@ declare class Client {
731
787
  *
732
788
  * @returns A list of all documents of the Custom Type.
733
789
  */
734
- getAllByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
790
+ getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocuments, TDocumentType>[]>;
735
791
  /**
736
792
  * Queries documents from the Prismic repository with a specific tag.
737
793
  *
@@ -749,7 +805,7 @@ declare class Client {
749
805
  *
750
806
  * @returns A paginated response containing documents with the tag.
751
807
  */
752
- getByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
808
+ getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
753
809
  /**
754
810
  * Queries all documents from the Prismic repository with a specific tag.
755
811
  *
@@ -767,7 +823,7 @@ declare class Client {
767
823
  *
768
824
  * @returns A list of all documents with the tag.
769
825
  */
770
- getAllByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
826
+ getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
771
827
  /**
772
828
  * Queries documents from the Prismic repository with specific tags. A
773
829
  * document must be tagged with all of the queried tags to be included.
@@ -784,7 +840,7 @@ declare class Client {
784
840
  *
785
841
  * @returns A paginated response containing documents with the tags.
786
842
  */
787
- getByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
843
+ getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
788
844
  /**
789
845
  * Queries documents from the Prismic repository with specific tags. A
790
846
  * document must be tagged with all of the queried tags to be included.
@@ -803,7 +859,7 @@ declare class Client {
803
859
  *
804
860
  * @returns A list of all documents with the tags.
805
861
  */
806
- getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
862
+ getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
807
863
  /**
808
864
  * Queries documents from the Prismic repository with specific tags. A
809
865
  * document must be tagged with at least one of the queried tags to be included.
@@ -820,7 +876,7 @@ declare class Client {
820
876
  *
821
877
  * @returns A paginated response containing documents with at least one of the tags.
822
878
  */
823
- getBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
879
+ getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
824
880
  /**
825
881
  * Queries documents from the Prismic repository with specific tags. A
826
882
  * document must be tagged with at least one of the queried tags to be included.
@@ -839,7 +895,7 @@ declare class Client {
839
895
  *
840
896
  * @returns A list of all documents with at least one of the tags.
841
897
  */
842
- getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
898
+ getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
843
899
  /**
844
900
  * Returns metadata about the Prismic repository, such as its refs, releases,
845
901
  * and custom types.
@@ -1002,7 +1058,7 @@ declare class Client {
1002
1058
  /**
1003
1059
  * @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
1004
1060
  */
1005
- graphqlFetch: (input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
1061
+ graphqlFetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
1006
1062
  /**
1007
1063
  * A `fetch()` function to be used with GraphQL clients configured for
1008
1064
  * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
@@ -1093,11 +1149,11 @@ declare const predicate: {
1093
1149
  at: (path: string, value: string | number | boolean | Date | string[]) => string;
1094
1150
  /**
1095
1151
  * The `not` predicate checks that the path doesn't match the provided value
1096
- * exactly. It takes a single value as the argument.
1152
+ * exactly. It takes a single value for a field or an array (only for tags).
1097
1153
  *
1098
1154
  * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#not}
1099
1155
  */
1100
- not: (path: string, value: string | number | boolean | Date) => string;
1156
+ not: (path: string, value: string | number | boolean | Date | string[]) => string;
1101
1157
  /**
1102
1158
  * The `any` predicate takes an array of values. It works exactly the same way
1103
1159
  * as the `at` operator, but checks whether the fragment matches any of the
@@ -1345,7 +1401,7 @@ declare const getEndpoint: <RepositoryName extends string>(repositoryName: Repos
1345
1401
  */
1346
1402
  declare const predicates: {
1347
1403
  at: (path: string, value: string | number | boolean | Date | string[]) => string;
1348
- not: (path: string, value: string | number | boolean | Date) => string;
1404
+ not: (path: string, value: string | number | boolean | Date | string[]) => string;
1349
1405
  any: (path: string, values: (string | number | boolean | Date)[]) => string;
1350
1406
  in: (path: string, values: string[]) => string;
1351
1407
  fulltext: (path: string, searchTerms: string) => string;
@@ -1378,7 +1434,7 @@ declare const predicates: {
1378
1434
  */
1379
1435
  declare const Predicates: {
1380
1436
  at: (path: string, value: string | number | boolean | Date | string[]) => string;
1381
- not: (path: string, value: string | number | boolean | Date) => string;
1437
+ not: (path: string, value: string | number | boolean | Date | string[]) => string;
1382
1438
  any: (path: string, values: (string | number | boolean | Date)[]) => string;
1383
1439
  in: (path: string, values: string[]) => string;
1384
1440
  fulltext: (path: string, searchTerms: string) => string;
@@ -1407,4 +1463,4 @@ declare const Predicates: {
1407
1463
  dateHourBefore: (path: string, hour: number) => string;
1408
1464
  };
1409
1465
 
1410
- export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, getRepositoryEndpoint, getRepositoryName, isRepositoryEndpoint, isRepositoryName, predicate, predicates };
1466
+ export { BuildQueryURLArgs, Client, ClientConfig, CreateClient, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, getRepositoryEndpoint, getRepositoryName, isRepositoryEndpoint, isRepositoryName, predicate, predicates };
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ const parse = (cookieString) => {
131
131
  return result;
132
132
  };
133
133
  const getAll = (cookieStore) => parse(cookieStore);
134
- const getCookie = (name, cookieStore) => getAll(cookieStore)[name];
134
+ const getCookie = (name, cookieJar) => getAll(cookieJar)[name];
135
135
 
136
136
  const minifyGraphQLQuery = (query) => {
137
137
  return query.replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
@@ -224,7 +224,7 @@ const GET_ALL_QUERY_DELAY = 500;
224
224
  const typePredicate = (documentType) => predicate.at("document.type", documentType);
225
225
  const everyTagPredicate = (tags) => predicate.at("document.tags", castArray(tags));
226
226
  const someTagsPredicate = (tags) => predicate.any("document.tags", castArray(tags));
227
- const createClient = (...args) => new Client(...args);
227
+ const createClient = (repositoryNameOrEndpoint, options) => new Client(repositoryNameOrEndpoint, options);
228
228
  class Client {
229
229
  constructor(repositoryNameOrEndpoint, options = {}) {
230
230
  this.refState = {
@@ -397,7 +397,11 @@ class Client {
397
397
  async getTags(params) {
398
398
  try {
399
399
  const tagsForm = await this.getCachedRepositoryForm("tags", params);
400
- return await this.fetch(tagsForm.action);
400
+ const url = new URL(tagsForm.action);
401
+ if (this.accessToken) {
402
+ url.searchParams.set("access_token", this.accessToken);
403
+ }
404
+ return await this.fetch(url.toString(), params);
401
405
  } catch (e) {
402
406
  const repository = await this.getRepository(params);
403
407
  return repository.tags;
@@ -419,16 +423,22 @@ class Client {
419
423
  });
420
424
  }
421
425
  async resolvePreviewURL(args) {
422
- var _a;
426
+ var _a, _b;
423
427
  let documentID = args.documentID;
424
428
  let previewToken = args.previewToken;
425
429
  if (typeof globalThis.location !== "undefined") {
426
430
  const searchParams = new URLSearchParams(globalThis.location.search);
427
- documentID = documentID || searchParams.get("documentId") || void 0;
428
- previewToken = previewToken || searchParams.get("token") || void 0;
429
- } else if ((_a = this.refState.httpRequest) == null ? void 0 : _a.query) {
430
- documentID = documentID || this.refState.httpRequest.query.documentId;
431
- previewToken = previewToken || this.refState.httpRequest.query.token;
431
+ documentID = documentID || searchParams.get("documentId");
432
+ previewToken = previewToken || searchParams.get("token");
433
+ } else if (this.refState.httpRequest) {
434
+ if ("query" in this.refState.httpRequest) {
435
+ documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
436
+ previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
437
+ } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
438
+ const searchParams = new URL(this.refState.httpRequest.url).searchParams;
439
+ documentID = documentID || searchParams.get("documentId");
440
+ previewToken = previewToken || searchParams.get("token");
441
+ }
432
442
  }
433
443
  if (documentID != null && previewToken != null) {
434
444
  const document = await this.getByID(documentID, {
@@ -509,13 +519,21 @@ class Client {
509
519
  return form;
510
520
  }
511
521
  async getResolvedRefString(params) {
512
- var _a, _b, _c;
522
+ var _a, _b;
513
523
  if (this.refState.autoPreviewsEnabled) {
514
- let previewRef = void 0;
524
+ let previewRef;
525
+ let cookieJar;
515
526
  if ((_a = globalThis.document) == null ? void 0 : _a.cookie) {
516
- previewRef = getCookie(preview, globalThis.document.cookie);
517
- } else if ((_c = (_b = this.refState.httpRequest) == null ? void 0 : _b.headers) == null ? void 0 : _c.cookie) {
518
- previewRef = getCookie(preview, this.refState.httpRequest.headers.cookie);
527
+ cookieJar = globalThis.document.cookie;
528
+ } else if ((_b = this.refState.httpRequest) == null ? void 0 : _b.headers) {
529
+ if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
530
+ cookieJar = this.refState.httpRequest.headers.get("cookie");
531
+ } else if ("cookie" in this.refState.httpRequest.headers) {
532
+ cookieJar = this.refState.httpRequest.headers.cookie;
533
+ }
534
+ }
535
+ if (cookieJar) {
536
+ previewRef = getCookie(preview, cookieJar);
519
537
  }
520
538
  if (previewRef) {
521
539
  return previewRef;