@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/src/client.ts
CHANGED
|
@@ -1207,19 +1207,27 @@ export class Client {
|
|
|
1207
1207
|
async resolvePreviewURL<LinkResolverReturnType>(
|
|
1208
1208
|
args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams,
|
|
1209
1209
|
): Promise<string> {
|
|
1210
|
-
let documentID = args.documentID;
|
|
1211
|
-
let previewToken = args.previewToken;
|
|
1210
|
+
let documentID: string | undefined | null = args.documentID;
|
|
1211
|
+
let previewToken: string | undefined | null = args.previewToken;
|
|
1212
1212
|
|
|
1213
1213
|
if (typeof globalThis.location !== "undefined") {
|
|
1214
1214
|
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
1215
1215
|
|
|
1216
|
-
documentID = documentID || searchParams.get("documentId")
|
|
1217
|
-
previewToken = previewToken || searchParams.get("token")
|
|
1218
|
-
} else if (this.refState.httpRequest
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1216
|
+
documentID = documentID || searchParams.get("documentId");
|
|
1217
|
+
previewToken = previewToken || searchParams.get("token");
|
|
1218
|
+
} else if (this.refState.httpRequest) {
|
|
1219
|
+
if (this.refState.httpRequest.url) {
|
|
1220
|
+
const searchParams = new URL(this.refState.httpRequest.url)
|
|
1221
|
+
.searchParams;
|
|
1222
|
+
|
|
1223
|
+
documentID = documentID || searchParams.get("documentId");
|
|
1224
|
+
previewToken = previewToken || searchParams.get("token");
|
|
1225
|
+
} else {
|
|
1226
|
+
documentID =
|
|
1227
|
+
documentID || (this.refState.httpRequest.query?.documentId as string);
|
|
1228
|
+
previewToken =
|
|
1229
|
+
previewToken || (this.refState.httpRequest.query?.token as string);
|
|
1230
|
+
}
|
|
1223
1231
|
}
|
|
1224
1232
|
|
|
1225
1233
|
if (documentID != null && previewToken != null) {
|
|
@@ -1492,15 +1500,27 @@ export class Client {
|
|
|
1492
1500
|
*/
|
|
1493
1501
|
private async getResolvedRefString(params?: FetchParams): Promise<string> {
|
|
1494
1502
|
if (this.refState.autoPreviewsEnabled) {
|
|
1495
|
-
let previewRef: string | undefined
|
|
1503
|
+
let previewRef: string | undefined;
|
|
1504
|
+
|
|
1505
|
+
let cookieJar: string | null | undefined;
|
|
1496
1506
|
|
|
1497
1507
|
if (globalThis.document?.cookie) {
|
|
1498
|
-
|
|
1499
|
-
} else if (this.refState.httpRequest?.headers
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
this.refState.httpRequest.headers.
|
|
1503
|
-
)
|
|
1508
|
+
cookieJar = globalThis.document.cookie;
|
|
1509
|
+
} else if (this.refState.httpRequest?.headers) {
|
|
1510
|
+
if (
|
|
1511
|
+
"get" in this.refState.httpRequest.headers &&
|
|
1512
|
+
typeof this.refState.httpRequest.headers.get === "function"
|
|
1513
|
+
) {
|
|
1514
|
+
// Web API Headers
|
|
1515
|
+
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1516
|
+
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
1517
|
+
// Express-style headers
|
|
1518
|
+
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
if (cookieJar) {
|
|
1523
|
+
previewRef = getCookie(cookie.preview, cookieJar);
|
|
1504
1524
|
}
|
|
1505
1525
|
|
|
1506
1526
|
if (previewRef) {
|
package/src/lib/getCookie.ts
CHANGED
|
@@ -47,12 +47,12 @@ const getAll = (cookieStore: string): { [name: string]: string } =>
|
|
|
47
47
|
/**
|
|
48
48
|
* Returns the value of a cookie from a given cookie store.
|
|
49
49
|
*
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
50
|
+
* @param name - Of the cookie.
|
|
51
|
+
* @param cookieJar - The stringified cookie store from which to read the cookie.
|
|
52
52
|
*
|
|
53
53
|
* @returns The value of the cookie, if it exists.
|
|
54
54
|
*/
|
|
55
55
|
export const getCookie = (
|
|
56
56
|
name: string,
|
|
57
|
-
|
|
58
|
-
): string | undefined => getAll(
|
|
57
|
+
cookieJar: string,
|
|
58
|
+
): string | undefined => getAll(cookieJar)[name];
|
package/src/predicate.ts
CHANGED
|
@@ -104,11 +104,13 @@ export const predicate = {
|
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* The `not` predicate checks that the path doesn't match the provided value
|
|
107
|
-
* exactly. It takes a single value
|
|
107
|
+
* exactly. It takes a single value for a field or an array (only for tags).
|
|
108
108
|
*
|
|
109
109
|
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#not}
|
|
110
110
|
*/
|
|
111
|
-
not: pathWithArgsPredicate<
|
|
111
|
+
not: pathWithArgsPredicate<
|
|
112
|
+
[value: string | number | boolean | Date | string[]]
|
|
113
|
+
>("not"),
|
|
112
114
|
|
|
113
115
|
/**
|
|
114
116
|
* The `any` predicate takes an array of values. It works exactly the same way
|
package/src/types.ts
CHANGED
|
@@ -43,6 +43,10 @@ export type AbortSignalLike = {
|
|
|
43
43
|
dispatchEvent: any;
|
|
44
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
45
|
onabort: any;
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
reason: any;
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
throwIfAborted: any;
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
/**
|
|
@@ -68,12 +72,30 @@ export interface ResponseLike {
|
|
|
68
72
|
* The minimum required properties to treat as an HTTP Request for automatic
|
|
69
73
|
* Prismic preview support.
|
|
70
74
|
*/
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
export type HttpRequestLike =
|
|
76
|
+
| /**
|
|
77
|
+
* Web API Request
|
|
78
|
+
*
|
|
79
|
+
* @see http://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
80
|
+
*/
|
|
81
|
+
{
|
|
82
|
+
headers?: {
|
|
83
|
+
get(name: string): string | null;
|
|
84
|
+
};
|
|
85
|
+
url?: string;
|
|
86
|
+
query?: never;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Express-style Request
|
|
91
|
+
*/
|
|
92
|
+
| {
|
|
93
|
+
headers?: {
|
|
94
|
+
cookie?: string;
|
|
95
|
+
};
|
|
96
|
+
query?: Record<string, unknown>;
|
|
97
|
+
url?: never;
|
|
98
|
+
};
|
|
77
99
|
|
|
78
100
|
/**
|
|
79
101
|
* An `orderings` parameter that orders the results by the specified field.
|