@prismicio/client 6.4.2 → 6.5.1
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 +27 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1384 -1369
- package/dist/index.js +27 -13
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/client.ts +60 -27
- package/src/lib/getCookie.ts +4 -4
- package/src/predicate.ts +4 -2
- package/src/types.ts +26 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/client",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.1",
|
|
4
4
|
"description": "The official JavaScript + TypeScript client library for Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismic",
|
|
@@ -48,31 +48,31 @@
|
|
|
48
48
|
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@prismicio/helpers": "^2.
|
|
51
|
+
"@prismicio/helpers": "^2.3.0",
|
|
52
52
|
"@prismicio/types": "^0.1.27"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
56
56
|
"@types/sinon": "^10.0.11",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
58
|
-
"@typescript-eslint/parser": "^5.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
58
|
+
"@typescript-eslint/parser": "^5.26.0",
|
|
59
59
|
"abort-controller": "^3.0.0",
|
|
60
|
-
"ava": "^4.
|
|
60
|
+
"ava": "^4.2.0",
|
|
61
61
|
"esbuild-register": "^3.3.2",
|
|
62
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.16.0",
|
|
63
63
|
"eslint-config-prettier": "^8.5.0",
|
|
64
64
|
"eslint-plugin-prettier": "^4.0.0",
|
|
65
|
-
"eslint-plugin-tsdoc": "^0.2.
|
|
66
|
-
"msw": "^0.
|
|
67
|
-
"node-fetch": "^3.2.
|
|
65
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
66
|
+
"msw": "^0.41.0",
|
|
67
|
+
"node-fetch": "^3.2.4",
|
|
68
68
|
"nyc": "^15.1.0",
|
|
69
|
-
"prettier": "^2.6.
|
|
70
|
-
"prettier-plugin-jsdoc": "^0.3.
|
|
71
|
-
"sinon": "^
|
|
69
|
+
"prettier": "^2.6.2",
|
|
70
|
+
"prettier-plugin-jsdoc": "^0.3.38",
|
|
71
|
+
"sinon": "^14.0.0",
|
|
72
72
|
"siroc": "^0.16.0",
|
|
73
73
|
"size-limit": "^7.0.8",
|
|
74
|
-
"standard-version": "^9.
|
|
75
|
-
"typescript": "^4.
|
|
74
|
+
"standard-version": "^9.5.0",
|
|
75
|
+
"typescript": "^4.7.2"
|
|
76
76
|
},
|
|
77
77
|
"engines": {
|
|
78
78
|
"node": ">=12.13.0"
|
package/src/client.ts
CHANGED
|
@@ -218,7 +218,7 @@ const typePredicate = (documentType: string): string =>
|
|
|
218
218
|
* Creates a predicate to filter content by document tags. All tags are required
|
|
219
219
|
* on the document.
|
|
220
220
|
*
|
|
221
|
-
* @param
|
|
221
|
+
* @param tags - Document tags to filter queried content.
|
|
222
222
|
*
|
|
223
223
|
* @returns A predicate that can be used in a Prismic REST API V2 request.
|
|
224
224
|
*/
|
|
@@ -229,7 +229,7 @@ const everyTagPredicate = (tags: string | string[]): string =>
|
|
|
229
229
|
* Creates a predicate to filter content by document tags. At least one matching
|
|
230
230
|
* tag is required on the document.
|
|
231
231
|
*
|
|
232
|
-
* @param
|
|
232
|
+
* @param tags - Document tags to filter queried content.
|
|
233
233
|
*
|
|
234
234
|
* @returns A predicate that can be used in a Prismic REST API V2 request.
|
|
235
235
|
*/
|
|
@@ -547,8 +547,10 @@ export class Client {
|
|
|
547
547
|
const { limit = Infinity, ...actualParams } = params;
|
|
548
548
|
const resolvedParams = {
|
|
549
549
|
...actualParams,
|
|
550
|
-
pageSize:
|
|
550
|
+
pageSize: Math.min(
|
|
551
|
+
limit,
|
|
551
552
|
actualParams.pageSize || this.defaultParams?.pageSize || MAX_PAGE_SIZE,
|
|
553
|
+
),
|
|
552
554
|
};
|
|
553
555
|
|
|
554
556
|
const documents: TDocument[] = [];
|
|
@@ -658,7 +660,7 @@ export class Client {
|
|
|
658
660
|
*/
|
|
659
661
|
async getAllByIDs<TDocument extends prismicT.PrismicDocument>(
|
|
660
662
|
ids: string[],
|
|
661
|
-
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
663
|
+
params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,
|
|
662
664
|
): Promise<TDocument[]> {
|
|
663
665
|
return await this.dangerouslyGetAll<TDocument>(
|
|
664
666
|
appendPredicates(params, predicate.in("document.id", ids)),
|
|
@@ -764,7 +766,7 @@ export class Client {
|
|
|
764
766
|
async getAllByUIDs<TDocument extends prismicT.PrismicDocument>(
|
|
765
767
|
documentType: string,
|
|
766
768
|
uids: string[],
|
|
767
|
-
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
769
|
+
params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,
|
|
768
770
|
): Promise<TDocument[]> {
|
|
769
771
|
return await this.dangerouslyGetAll<TDocument>(
|
|
770
772
|
appendPredicates(params, [
|
|
@@ -849,7 +851,9 @@ export class Client {
|
|
|
849
851
|
*/
|
|
850
852
|
async getAllByType<TDocument extends prismicT.PrismicDocument>(
|
|
851
853
|
documentType: string,
|
|
852
|
-
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
854
|
+
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
855
|
+
GetAllParams &
|
|
856
|
+
FetchParams,
|
|
853
857
|
): Promise<TDocument[]> {
|
|
854
858
|
return await this.dangerouslyGetAll<TDocument>(
|
|
855
859
|
appendPredicates(params, typePredicate(documentType)),
|
|
@@ -901,7 +905,9 @@ export class Client {
|
|
|
901
905
|
*/
|
|
902
906
|
async getAllByTag<TDocument extends prismicT.PrismicDocument>(
|
|
903
907
|
tag: string,
|
|
904
|
-
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
908
|
+
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
909
|
+
GetAllParams &
|
|
910
|
+
FetchParams,
|
|
905
911
|
): Promise<TDocument[]> {
|
|
906
912
|
return await this.dangerouslyGetAll<TDocument>(
|
|
907
913
|
appendPredicates(params, someTagsPredicate(tag)),
|
|
@@ -953,7 +959,9 @@ export class Client {
|
|
|
953
959
|
*/
|
|
954
960
|
async getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(
|
|
955
961
|
tags: string[],
|
|
956
|
-
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
962
|
+
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
963
|
+
GetAllParams &
|
|
964
|
+
FetchParams,
|
|
957
965
|
): Promise<TDocument[]> {
|
|
958
966
|
return await this.dangerouslyGetAll<TDocument>(
|
|
959
967
|
appendPredicates(params, everyTagPredicate(tags)),
|
|
@@ -1005,7 +1013,9 @@ export class Client {
|
|
|
1005
1013
|
*/
|
|
1006
1014
|
async getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(
|
|
1007
1015
|
tags: string[],
|
|
1008
|
-
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
1016
|
+
params?: Partial<Omit<BuildQueryURLArgs, "page">> &
|
|
1017
|
+
GetAllParams &
|
|
1018
|
+
FetchParams,
|
|
1009
1019
|
): Promise<TDocument[]> {
|
|
1010
1020
|
return await this.dangerouslyGetAll<TDocument>(
|
|
1011
1021
|
appendPredicates(params, someTagsPredicate(tags)),
|
|
@@ -1197,19 +1207,30 @@ export class Client {
|
|
|
1197
1207
|
async resolvePreviewURL<LinkResolverReturnType>(
|
|
1198
1208
|
args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams,
|
|
1199
1209
|
): Promise<string> {
|
|
1200
|
-
let documentID = args.documentID;
|
|
1201
|
-
let previewToken = args.previewToken;
|
|
1210
|
+
let documentID: string | undefined | null = args.documentID;
|
|
1211
|
+
let previewToken: string | undefined | null = args.previewToken;
|
|
1202
1212
|
|
|
1203
1213
|
if (typeof globalThis.location !== "undefined") {
|
|
1204
1214
|
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
1205
1215
|
|
|
1206
|
-
documentID = documentID || searchParams.get("documentId")
|
|
1207
|
-
previewToken = previewToken || searchParams.get("token")
|
|
1208
|
-
} else if (this.refState.httpRequest
|
|
1209
|
-
|
|
1210
|
-
documentID
|
|
1211
|
-
|
|
1212
|
-
previewToken
|
|
1216
|
+
documentID = documentID || searchParams.get("documentId");
|
|
1217
|
+
previewToken = previewToken || searchParams.get("token");
|
|
1218
|
+
} else if (this.refState.httpRequest) {
|
|
1219
|
+
if ("query" in this.refState.httpRequest) {
|
|
1220
|
+
documentID =
|
|
1221
|
+
documentID || (this.refState.httpRequest.query?.documentId as string);
|
|
1222
|
+
previewToken =
|
|
1223
|
+
previewToken || (this.refState.httpRequest.query?.token as string);
|
|
1224
|
+
} else if (
|
|
1225
|
+
"url" in this.refState.httpRequest &&
|
|
1226
|
+
this.refState.httpRequest.url
|
|
1227
|
+
) {
|
|
1228
|
+
const searchParams = new URL(this.refState.httpRequest.url)
|
|
1229
|
+
.searchParams;
|
|
1230
|
+
|
|
1231
|
+
documentID = documentID || searchParams.get("documentId");
|
|
1232
|
+
previewToken = previewToken || searchParams.get("token");
|
|
1233
|
+
}
|
|
1213
1234
|
}
|
|
1214
1235
|
|
|
1215
1236
|
if (documentID != null && previewToken != null) {
|
|
@@ -1258,7 +1279,7 @@ export class Client {
|
|
|
1258
1279
|
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
1259
1280
|
* ```
|
|
1260
1281
|
*
|
|
1261
|
-
* @param
|
|
1282
|
+
* @param releaseID - The ID of the Release.
|
|
1262
1283
|
*/
|
|
1263
1284
|
queryContentFromReleaseByID(releaseID: string): void {
|
|
1264
1285
|
this.refState = {
|
|
@@ -1281,7 +1302,7 @@ export class Client {
|
|
|
1281
1302
|
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
1282
1303
|
* ```
|
|
1283
1304
|
*
|
|
1284
|
-
* @param
|
|
1305
|
+
* @param releaseLabel - The label of the Release.
|
|
1285
1306
|
*/
|
|
1286
1307
|
queryContentFromReleaseByLabel(releaseLabel: string): void {
|
|
1287
1308
|
this.refState = {
|
|
@@ -1482,15 +1503,27 @@ export class Client {
|
|
|
1482
1503
|
*/
|
|
1483
1504
|
private async getResolvedRefString(params?: FetchParams): Promise<string> {
|
|
1484
1505
|
if (this.refState.autoPreviewsEnabled) {
|
|
1485
|
-
let previewRef: string | undefined
|
|
1506
|
+
let previewRef: string | undefined;
|
|
1507
|
+
|
|
1508
|
+
let cookieJar: string | null | undefined;
|
|
1486
1509
|
|
|
1487
1510
|
if (globalThis.document?.cookie) {
|
|
1488
|
-
|
|
1489
|
-
} else if (this.refState.httpRequest?.headers
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
this.refState.httpRequest.headers.
|
|
1493
|
-
)
|
|
1511
|
+
cookieJar = globalThis.document.cookie;
|
|
1512
|
+
} else if (this.refState.httpRequest?.headers) {
|
|
1513
|
+
if (
|
|
1514
|
+
"get" in this.refState.httpRequest.headers &&
|
|
1515
|
+
typeof this.refState.httpRequest.headers.get === "function"
|
|
1516
|
+
) {
|
|
1517
|
+
// Web API Headers
|
|
1518
|
+
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1519
|
+
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
1520
|
+
// Express-style headers
|
|
1521
|
+
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
if (cookieJar) {
|
|
1526
|
+
previewRef = getCookie(cookie.preview, cookieJar);
|
|
1494
1527
|
}
|
|
1495
1528
|
|
|
1496
1529
|
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,28 @@ 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
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Express-style Request
|
|
90
|
+
*/
|
|
91
|
+
| {
|
|
92
|
+
headers?: {
|
|
93
|
+
cookie?: string;
|
|
94
|
+
};
|
|
95
|
+
query?: Record<string, unknown>;
|
|
96
|
+
};
|
|
77
97
|
|
|
78
98
|
/**
|
|
79
99
|
* An `orderings` parameter that orders the results by the specified field.
|