@prismicio/client 6.4.3 → 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.cjs +26 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -7
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/client.ts +36 -16
- package/src/lib/getCookie.ts +4 -4
- package/src/predicate.ts +4 -2
- package/src/types.ts +28 -6
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
|
-
|
|
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
|
*
|
|
@@ -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
|
|
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`
|
|
@@ -1093,11 +1110,11 @@ declare const predicate: {
|
|
|
1093
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
|
|
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 | boolean | Date) => 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
|
|
@@ -1345,7 +1362,7 @@ declare const getEndpoint: <RepositoryName extends string>(repositoryName: Repos
|
|
|
1345
1362
|
*/
|
|
1346
1363
|
declare const predicates: {
|
|
1347
1364
|
at: (path: string, value: string | number | boolean | Date | string[]) => string;
|
|
1348
|
-
not: (path: string, value: string | number | boolean | Date) => string;
|
|
1365
|
+
not: (path: string, value: string | number | boolean | Date | string[]) => string;
|
|
1349
1366
|
any: (path: string, values: (string | number | boolean | Date)[]) => string;
|
|
1350
1367
|
in: (path: string, values: string[]) => string;
|
|
1351
1368
|
fulltext: (path: string, searchTerms: string) => string;
|
|
@@ -1378,7 +1395,7 @@ declare const predicates: {
|
|
|
1378
1395
|
*/
|
|
1379
1396
|
declare const Predicates: {
|
|
1380
1397
|
at: (path: string, value: string | number | boolean | Date | string[]) => string;
|
|
1381
|
-
not: (path: string, value: string | number | boolean | Date) => string;
|
|
1398
|
+
not: (path: string, value: string | number | boolean | Date | string[]) => string;
|
|
1382
1399
|
any: (path: string, values: (string | number | boolean | Date)[]) => string;
|
|
1383
1400
|
in: (path: string, values: string[]) => string;
|
|
1384
1401
|
fulltext: (path: string, searchTerms: string) => 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,
|
|
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);
|
|
@@ -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")
|
|
428
|
-
previewToken = previewToken || searchParams.get("token")
|
|
429
|
-
} else if (
|
|
430
|
-
|
|
431
|
-
|
|
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
|
|
518
|
+
var _a, _b;
|
|
513
519
|
if (this.refState.autoPreviewsEnabled) {
|
|
514
|
-
let previewRef
|
|
520
|
+
let previewRef;
|
|
521
|
+
let cookieJar;
|
|
515
522
|
if ((_a = globalThis.document) == null ? void 0 : _a.cookie) {
|
|
516
|
-
|
|
517
|
-
} else if ((
|
|
518
|
-
|
|
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;
|