@prismicio/client 6.4.1 → 6.5.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
@@ -71,6 +71,8 @@ declare type AbortSignalLike = {
71
71
  removeEventListener: any;
72
72
  dispatchEvent: any;
73
73
  onabort: any;
74
+ reason: any;
75
+ throwIfAborted: any;
74
76
  };
75
77
  /**
76
78
  * The minimum required properties from RequestInit.
@@ -90,12 +92,27 @@ interface ResponseLike {
90
92
  * The minimum required properties to treat as an HTTP Request for automatic
91
93
  * Prismic preview support.
92
94
  */
93
- interface HttpRequestLike {
95
+ declare type HttpRequestLike = /**
96
+ * Web API Request
97
+ *
98
+ * @see http://developer.mozilla.org/en-US/docs/Web/API/Request
99
+ */ {
100
+ headers?: {
101
+ get(name: string): string | null;
102
+ };
103
+ url?: string;
104
+ query?: never;
105
+ }
106
+ /**
107
+ * Express-style Request
108
+ */
109
+ | {
94
110
  headers?: {
95
111
  cookie?: string;
96
112
  };
97
113
  query?: Record<string, unknown>;
98
- }
114
+ url?: never;
115
+ };
99
116
  /**
100
117
  * An `orderings` parameter that orders the results by the specified field.
101
118
  *
@@ -600,7 +617,7 @@ declare class Client {
600
617
  *
601
618
  * @returns A list of documents with IDs matching the `ids` parameter.
602
619
  */
603
- getAllByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument[]>;
620
+ getAllByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
604
621
  /**
605
622
  * Queries a document from the Prismic repository with a specific UID and Custom Type.
606
623
  *
@@ -673,7 +690,7 @@ declare class Client {
673
690
  *
674
691
  * @returns A list of documents with UIDs matching the `uids` parameter.
675
692
  */
676
- getAllByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument[]>;
693
+ getAllByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
677
694
  /**
678
695
  * Queries a singleton document from the Prismic repository for a specific Custom Type.
679
696
  *
@@ -731,7 +748,7 @@ declare class Client {
731
748
  *
732
749
  * @returns A list of all documents of the Custom Type.
733
750
  */
734
- getAllByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
751
+ getAllByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
735
752
  /**
736
753
  * Queries documents from the Prismic repository with a specific tag.
737
754
  *
@@ -767,7 +784,7 @@ declare class Client {
767
784
  *
768
785
  * @returns A list of all documents with the tag.
769
786
  */
770
- getAllByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
787
+ getAllByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
771
788
  /**
772
789
  * Queries documents from the Prismic repository with specific tags. A
773
790
  * document must be tagged with all of the queried tags to be included.
@@ -803,7 +820,7 @@ declare class Client {
803
820
  *
804
821
  * @returns A list of all documents with the tags.
805
822
  */
806
- getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
823
+ getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
807
824
  /**
808
825
  * Queries documents from the Prismic repository with specific tags. A
809
826
  * document must be tagged with at least one of the queried tags to be included.
@@ -839,7 +856,7 @@ declare class Client {
839
856
  *
840
857
  * @returns A list of all documents with at least one of the tags.
841
858
  */
842
- getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
859
+ getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
843
860
  /**
844
861
  * Returns metadata about the Prismic repository, such as its refs, releases,
845
862
  * and custom types.
@@ -963,7 +980,7 @@ declare class Client {
963
980
  * const document = await client.getByID("WW4bKScAAMAqmluX");
964
981
  * ```
965
982
  *
966
- * @param id - The ID of the Release.
983
+ * @param releaseID - The ID of the Release.
967
984
  */
968
985
  queryContentFromReleaseByID(releaseID: string): void;
969
986
  /**
@@ -979,7 +996,7 @@ declare class Client {
979
996
  * const document = await client.getByID("WW4bKScAAMAqmluX");
980
997
  * ```
981
998
  *
982
- * @param label - The label of the Release.
999
+ * @param releaseLabel - The label of the Release.
983
1000
  */
984
1001
  queryContentFromReleaseByLabel(releaseLabel: string): void;
985
1002
  /**
@@ -1002,7 +1019,7 @@ declare class Client {
1002
1019
  /**
1003
1020
  * @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
1004
1021
  */
1005
- graphqlFetch: (input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
1022
+ graphqlFetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
1006
1023
  /**
1007
1024
  * A `fetch()` function to be used with GraphQL clients configured for
1008
1025
  * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
@@ -1090,14 +1107,14 @@ declare const predicate: {
1090
1107
  *
1091
1108
  * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#at}
1092
1109
  */
1093
- at: (path: string, value: string | number | (string | number)[]) => string;
1110
+ at: (path: string, value: string | number | boolean | Date | string[]) => string;
1094
1111
  /**
1095
1112
  * The `not` predicate checks that the path doesn't match the provided value
1096
- * exactly. It takes a single value as the argument.
1113
+ * exactly. It takes a single value for a field or an array (only for tags).
1097
1114
  *
1098
1115
  * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#not}
1099
1116
  */
1100
- not: (path: string, value: string | number | (string | number)[]) => string;
1117
+ not: (path: string, value: string | number | boolean | Date | string[]) => string;
1101
1118
  /**
1102
1119
  * The `any` predicate takes an array of values. It works exactly the same way
1103
1120
  * as the `at` operator, but checks whether the fragment matches any of the
@@ -1105,7 +1122,7 @@ declare const predicate: {
1105
1122
  *
1106
1123
  * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#any}
1107
1124
  */
1108
- any: (path: string, value: string | number | (string | number)[]) => string;
1125
+ any: (path: string, values: (string | number | boolean | Date)[]) => string;
1109
1126
  /**
1110
1127
  * The `in` predicate is used specifically to retrieve an array of documents
1111
1128
  * by their IDs or UIDs. This predicate is much more efficient at this than
@@ -1113,7 +1130,7 @@ declare const predicate: {
1113
1130
  *
1114
1131
  * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#in}
1115
1132
  */
1116
- in: (path: string, value: string | number | (string | number)[]) => string;
1133
+ in: (path: string, values: string[]) => string;
1117
1134
  /**
1118
1135
  * The `fulltext` predicate provides two capabilities:
1119
1136
  *
@@ -1124,7 +1141,7 @@ declare const predicate: {
1124
1141
  *
1125
1142
  * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#fulltext}
1126
1143
  */
1127
- fulltext: (path: string, value: string | number | (string | number)[]) => string;
1144
+ fulltext: (path: string, searchTerms: string) => string;
1128
1145
  /**
1129
1146
  * The `has` predicate checks whether a fragment has a value. It will return
1130
1147
  * all the documents of the specified type that contain a value for the
@@ -1344,11 +1361,11 @@ declare const getEndpoint: <RepositoryName extends string>(repositoryName: Repos
1344
1361
  * @deprecated Renamed to `predicate` (without an "s").
1345
1362
  */
1346
1363
  declare const predicates: {
1347
- at: (path: string, value: string | number | (string | number)[]) => string;
1348
- not: (path: string, value: string | number | (string | number)[]) => string;
1349
- any: (path: string, value: string | number | (string | number)[]) => string;
1350
- in: (path: string, value: string | number | (string | number)[]) => string;
1351
- fulltext: (path: string, value: string | number | (string | number)[]) => string;
1364
+ at: (path: string, value: string | number | boolean | Date | string[]) => string;
1365
+ not: (path: string, value: string | number | boolean | Date | string[]) => string;
1366
+ any: (path: string, values: (string | number | boolean | Date)[]) => string;
1367
+ in: (path: string, values: string[]) => string;
1368
+ fulltext: (path: string, searchTerms: string) => string;
1352
1369
  has: (path: string) => string;
1353
1370
  missing: (path: string) => string;
1354
1371
  similar: (id: string, value: number) => string;
@@ -1377,11 +1394,11 @@ declare const predicates: {
1377
1394
  * @deprecated Renamed to `predicate` (lowercase and without an "s").
1378
1395
  */
1379
1396
  declare const Predicates: {
1380
- at: (path: string, value: string | number | (string | number)[]) => string;
1381
- not: (path: string, value: string | number | (string | number)[]) => string;
1382
- any: (path: string, value: string | number | (string | number)[]) => string;
1383
- in: (path: string, value: string | number | (string | number)[]) => string;
1384
- fulltext: (path: string, value: string | number | (string | number)[]) => string;
1397
+ at: (path: string, value: string | number | boolean | Date | string[]) => string;
1398
+ not: (path: string, value: string | number | boolean | Date | string[]) => string;
1399
+ any: (path: string, values: (string | number | boolean | Date)[]) => string;
1400
+ in: (path: string, values: string[]) => string;
1401
+ fulltext: (path: string, searchTerms: string) => string;
1385
1402
  has: (path: string) => string;
1386
1403
  missing: (path: string) => string;
1387
1404
  similar: (id: string, value: number) => string;
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);
@@ -291,7 +291,7 @@ class Client {
291
291
  const { limit = Infinity, ...actualParams } = params;
292
292
  const resolvedParams = {
293
293
  ...actualParams,
294
- pageSize: actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE
294
+ pageSize: Math.min(limit, actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE)
295
295
  };
296
296
  const documents = [];
297
297
  let latestResult;
@@ -419,16 +419,22 @@ class Client {
419
419
  });
420
420
  }
421
421
  async resolvePreviewURL(args) {
422
- var _a;
422
+ var _a, _b;
423
423
  let documentID = args.documentID;
424
424
  let previewToken = args.previewToken;
425
425
  if (typeof globalThis.location !== "undefined") {
426
426
  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;
427
+ documentID = documentID || searchParams.get("documentId");
428
+ previewToken = previewToken || searchParams.get("token");
429
+ } else if (this.refState.httpRequest) {
430
+ if (this.refState.httpRequest.url) {
431
+ const searchParams = new URL(this.refState.httpRequest.url).searchParams;
432
+ documentID = documentID || searchParams.get("documentId");
433
+ previewToken = previewToken || searchParams.get("token");
434
+ } else {
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
+ }
432
438
  }
433
439
  if (documentID != null && previewToken != null) {
434
440
  const document = await this.getByID(documentID, {
@@ -509,13 +515,21 @@ class Client {
509
515
  return form;
510
516
  }
511
517
  async getResolvedRefString(params) {
512
- var _a, _b, _c;
518
+ var _a, _b;
513
519
  if (this.refState.autoPreviewsEnabled) {
514
- let previewRef = void 0;
520
+ let previewRef;
521
+ let cookieJar;
515
522
  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);
523
+ cookieJar = globalThis.document.cookie;
524
+ } else if ((_b = this.refState.httpRequest) == null ? void 0 : _b.headers) {
525
+ if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
526
+ cookieJar = this.refState.httpRequest.headers.get("cookie");
527
+ } else if ("cookie" in this.refState.httpRequest.headers) {
528
+ cookieJar = this.refState.httpRequest.headers.cookie;
529
+ }
530
+ }
531
+ if (cookieJar) {
532
+ previewRef = getCookie(preview, cookieJar);
519
533
  }
520
534
  if (previewRef) {
521
535
  return previewRef;