@prismicio/client 6.7.3 → 6.8.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/ForbiddenError.d.ts +11 -11
- package/dist/NotFoundError.d.ts +3 -3
- package/dist/ParsingError.d.ts +12 -12
- package/dist/PrismicError.d.ts +5 -5
- package/dist/buildQueryURL.d.ts +130 -130
- package/dist/client.cjs +16 -6
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +943 -929
- package/dist/client.js +16 -6
- package/dist/client.js.map +1 -1
- package/dist/cookie.d.ts +5 -5
- package/dist/getGraphQLEndpoint.d.ts +9 -9
- package/dist/getRepositoryEndpoint.d.ts +10 -10
- package/dist/getRepositoryName.d.ts +13 -13
- package/dist/index.d.ts +88 -88
- package/dist/isRepositoryEndpoint.d.ts +10 -10
- package/dist/isRepositoryName.d.ts +9 -9
- package/dist/lib/appendPredicates.d.ts +18 -18
- package/dist/lib/castArray.d.ts +11 -11
- package/dist/lib/castThunk.d.ts +10 -10
- package/dist/lib/findMasterRef.d.ts +10 -10
- package/dist/lib/findRef.d.ts +13 -13
- package/dist/lib/findRefByID.d.ts +11 -11
- package/dist/lib/findRefByLabel.d.ts +11 -11
- package/dist/lib/getPreviewCookie.d.ts +9 -9
- package/dist/lib/minifyGraphQLQuery.d.ts +8 -8
- package/dist/lib/orElseThrow.d.ts +11 -11
- package/dist/predicate.d.ts +209 -209
- package/dist/types.d.ts +158 -156
- package/package.json +1 -1
- package/src/client.ts +38 -6
- package/src/types.ts +12 -5
package/dist/ForbiddenError.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PrismicError } from "./PrismicError";
|
|
2
|
-
type ForbiddenErrorRepositoryAPIResponse = {
|
|
3
|
-
type: string;
|
|
4
|
-
message: string;
|
|
5
|
-
};
|
|
6
|
-
type ForbiddenErrorQueryAPIResponse = {
|
|
7
|
-
error: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class ForbiddenError extends PrismicError<ForbiddenErrorRepositoryAPIResponse | ForbiddenErrorQueryAPIResponse> {
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
1
|
+
import { PrismicError } from "./PrismicError";
|
|
2
|
+
type ForbiddenErrorRepositoryAPIResponse = {
|
|
3
|
+
type: string;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
type ForbiddenErrorQueryAPIResponse = {
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class ForbiddenError extends PrismicError<ForbiddenErrorRepositoryAPIResponse | ForbiddenErrorQueryAPIResponse> {
|
|
10
|
+
}
|
|
11
|
+
export {};
|
package/dist/NotFoundError.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { PrismicError } from "./PrismicError";
|
|
2
|
-
export declare class NotFoundError extends PrismicError<undefined> {
|
|
3
|
-
}
|
|
1
|
+
import { PrismicError } from "./PrismicError";
|
|
2
|
+
export declare class NotFoundError extends PrismicError<undefined> {
|
|
3
|
+
}
|
package/dist/ParsingError.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { PrismicError } from "./PrismicError";
|
|
2
|
-
type ParsingErrorAPIResponse = {
|
|
3
|
-
type: "parsing-error";
|
|
4
|
-
message: string;
|
|
5
|
-
line: number;
|
|
6
|
-
column: number;
|
|
7
|
-
id: number;
|
|
8
|
-
location: string;
|
|
9
|
-
};
|
|
10
|
-
export declare class ParsingError extends PrismicError<ParsingErrorAPIResponse> {
|
|
11
|
-
}
|
|
12
|
-
export {};
|
|
1
|
+
import { PrismicError } from "./PrismicError";
|
|
2
|
+
type ParsingErrorAPIResponse = {
|
|
3
|
+
type: "parsing-error";
|
|
4
|
+
message: string;
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
id: number;
|
|
8
|
+
location: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class ParsingError extends PrismicError<ParsingErrorAPIResponse> {
|
|
11
|
+
}
|
|
12
|
+
export {};
|
package/dist/PrismicError.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare class PrismicError<Response> extends Error {
|
|
2
|
-
url?: string;
|
|
3
|
-
response: Response;
|
|
4
|
-
constructor(message: string | undefined, url: string | undefined, response: Response);
|
|
5
|
-
}
|
|
1
|
+
export declare class PrismicError<Response> extends Error {
|
|
2
|
+
url?: string;
|
|
3
|
+
response: Response;
|
|
4
|
+
constructor(message: string | undefined, url: string | undefined, response: Response);
|
|
5
|
+
}
|
package/dist/buildQueryURL.d.ts
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
import { Ordering, Route } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Parameters for the Prismic REST API V2.
|
|
4
|
-
*
|
|
5
|
-
* {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api}
|
|
6
|
-
*/
|
|
7
|
-
export interface QueryParams {
|
|
8
|
-
/**
|
|
9
|
-
* The secure token for accessing the API (only needed if your repository is
|
|
10
|
-
* set to private).
|
|
11
|
-
*
|
|
12
|
-
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
|
|
13
|
-
*/
|
|
14
|
-
accessToken?: string;
|
|
15
|
-
/**
|
|
16
|
-
* The `pageSize` parameter defines the maximum number of documents that the
|
|
17
|
-
* API will return for your query.
|
|
18
|
-
*
|
|
19
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#pagesize}
|
|
20
|
-
*/
|
|
21
|
-
pageSize?: number;
|
|
22
|
-
/**
|
|
23
|
-
* The `page` parameter defines the pagination for the result of your query.
|
|
24
|
-
*
|
|
25
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#page}
|
|
26
|
-
*/
|
|
27
|
-
page?: number;
|
|
28
|
-
/**
|
|
29
|
-
* The `after` parameter can be used along with the orderings option. It will
|
|
30
|
-
* remove all the documents except for those after the specified document in
|
|
31
|
-
* the list.
|
|
32
|
-
*
|
|
33
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#after}
|
|
34
|
-
*/
|
|
35
|
-
after?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The `fetch` parameter is used to make queries faster by only retrieving the
|
|
38
|
-
* specified field(s).
|
|
39
|
-
*
|
|
40
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetch}
|
|
41
|
-
*/
|
|
42
|
-
fetch?: string | string[];
|
|
43
|
-
/**
|
|
44
|
-
* The `fetchLinks` parameter allows you to retrieve a specific content field
|
|
45
|
-
* from a linked document and add it to the document response object.
|
|
46
|
-
*
|
|
47
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetchlinks}
|
|
48
|
-
*/
|
|
49
|
-
fetchLinks?: string | string[];
|
|
50
|
-
/**
|
|
51
|
-
* The `graphQuery` parameter allows you to specify which fields to retrieve
|
|
52
|
-
* and what content to retrieve from Linked Documents / Content
|
|
53
|
-
* Relationships.
|
|
54
|
-
*
|
|
55
|
-
* {@link https://prismic.io/docs/technologies/graphquery-rest-api}
|
|
56
|
-
*/
|
|
57
|
-
graphQuery?: string;
|
|
58
|
-
/**
|
|
59
|
-
* The `lang` option defines the language code for the results of your query.
|
|
60
|
-
*
|
|
61
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#lang}
|
|
62
|
-
*/
|
|
63
|
-
lang?: string;
|
|
64
|
-
/**
|
|
65
|
-
* The `orderings` parameter orders the results by the specified field(s). You
|
|
66
|
-
* can specify as many fields as you want.
|
|
67
|
-
*
|
|
68
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}
|
|
69
|
-
*/
|
|
70
|
-
orderings?: Ordering | string | (Ordering | string)[];
|
|
71
|
-
/**
|
|
72
|
-
* The `routes` option allows you to define how a document's `url` field is
|
|
73
|
-
* resolved.
|
|
74
|
-
*
|
|
75
|
-
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
76
|
-
*/
|
|
77
|
-
routes?: Route | string | (Route | string)[];
|
|
78
|
-
/**
|
|
79
|
-
* The `brokenRoute` option allows you to define the route populated in the
|
|
80
|
-
* `url` property for broken Link or Content Relationship fields. A broken
|
|
81
|
-
* link is a Link or Content Relationship field whose linked document has been
|
|
82
|
-
* unpublished or deleted.
|
|
83
|
-
*
|
|
84
|
-
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
85
|
-
*/
|
|
86
|
-
brokenRoute?: string;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Arguments for `buildQueryURL` to construct a Query URL.
|
|
90
|
-
*/
|
|
91
|
-
type BuildQueryURLParams = {
|
|
92
|
-
/**
|
|
93
|
-
* Ref used to query documents.
|
|
94
|
-
*
|
|
95
|
-
* {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
|
|
96
|
-
*/
|
|
97
|
-
ref: string;
|
|
98
|
-
/**
|
|
99
|
-
* Ref used to populate Integration Fields with the latest content.
|
|
100
|
-
*
|
|
101
|
-
* {@link https://prismic.io/docs/core-concepts/integration-fields}
|
|
102
|
-
*/
|
|
103
|
-
integrationFieldsRef?: string;
|
|
104
|
-
/**
|
|
105
|
-
* One or more predicates to filter documents for the query.
|
|
106
|
-
*
|
|
107
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}
|
|
108
|
-
*/
|
|
109
|
-
predicates?: string | string[];
|
|
110
|
-
};
|
|
111
|
-
export type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;
|
|
112
|
-
/**
|
|
113
|
-
* Build a Prismic REST API V2 URL to request documents from a repository. The
|
|
114
|
-
* paginated response for this URL includes documents matching the parameters.
|
|
115
|
-
*
|
|
116
|
-
* A ref is required to make a request. Request the `endpoint` URL to retrieve a
|
|
117
|
-
* list of available refs.
|
|
118
|
-
*
|
|
119
|
-
* Type the JSON response with `Query`.
|
|
120
|
-
*
|
|
121
|
-
* {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
|
|
122
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}
|
|
123
|
-
*
|
|
124
|
-
* @param endpoint - URL to the repository's REST API V2.
|
|
125
|
-
* @param args - Arguments to filter and scope the query.
|
|
126
|
-
*
|
|
127
|
-
* @returns URL that can be used to request documents from the repository.
|
|
128
|
-
*/
|
|
129
|
-
export declare const buildQueryURL: (endpoint: string, args: BuildQueryURLArgs) => string;
|
|
130
|
-
export {};
|
|
1
|
+
import { Ordering, Route } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for the Prismic REST API V2.
|
|
4
|
+
*
|
|
5
|
+
* {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api}
|
|
6
|
+
*/
|
|
7
|
+
export interface QueryParams {
|
|
8
|
+
/**
|
|
9
|
+
* The secure token for accessing the API (only needed if your repository is
|
|
10
|
+
* set to private).
|
|
11
|
+
*
|
|
12
|
+
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
|
|
13
|
+
*/
|
|
14
|
+
accessToken?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The `pageSize` parameter defines the maximum number of documents that the
|
|
17
|
+
* API will return for your query.
|
|
18
|
+
*
|
|
19
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#pagesize}
|
|
20
|
+
*/
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The `page` parameter defines the pagination for the result of your query.
|
|
24
|
+
*
|
|
25
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#page}
|
|
26
|
+
*/
|
|
27
|
+
page?: number;
|
|
28
|
+
/**
|
|
29
|
+
* The `after` parameter can be used along with the orderings option. It will
|
|
30
|
+
* remove all the documents except for those after the specified document in
|
|
31
|
+
* the list.
|
|
32
|
+
*
|
|
33
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#after}
|
|
34
|
+
*/
|
|
35
|
+
after?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The `fetch` parameter is used to make queries faster by only retrieving the
|
|
38
|
+
* specified field(s).
|
|
39
|
+
*
|
|
40
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetch}
|
|
41
|
+
*/
|
|
42
|
+
fetch?: string | string[];
|
|
43
|
+
/**
|
|
44
|
+
* The `fetchLinks` parameter allows you to retrieve a specific content field
|
|
45
|
+
* from a linked document and add it to the document response object.
|
|
46
|
+
*
|
|
47
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetchlinks}
|
|
48
|
+
*/
|
|
49
|
+
fetchLinks?: string | string[];
|
|
50
|
+
/**
|
|
51
|
+
* The `graphQuery` parameter allows you to specify which fields to retrieve
|
|
52
|
+
* and what content to retrieve from Linked Documents / Content
|
|
53
|
+
* Relationships.
|
|
54
|
+
*
|
|
55
|
+
* {@link https://prismic.io/docs/technologies/graphquery-rest-api}
|
|
56
|
+
*/
|
|
57
|
+
graphQuery?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The `lang` option defines the language code for the results of your query.
|
|
60
|
+
*
|
|
61
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#lang}
|
|
62
|
+
*/
|
|
63
|
+
lang?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The `orderings` parameter orders the results by the specified field(s). You
|
|
66
|
+
* can specify as many fields as you want.
|
|
67
|
+
*
|
|
68
|
+
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}
|
|
69
|
+
*/
|
|
70
|
+
orderings?: Ordering | string | (Ordering | string)[];
|
|
71
|
+
/**
|
|
72
|
+
* The `routes` option allows you to define how a document's `url` field is
|
|
73
|
+
* resolved.
|
|
74
|
+
*
|
|
75
|
+
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
76
|
+
*/
|
|
77
|
+
routes?: Route | string | (Route | string)[];
|
|
78
|
+
/**
|
|
79
|
+
* The `brokenRoute` option allows you to define the route populated in the
|
|
80
|
+
* `url` property for broken Link or Content Relationship fields. A broken
|
|
81
|
+
* link is a Link or Content Relationship field whose linked document has been
|
|
82
|
+
* unpublished or deleted.
|
|
83
|
+
*
|
|
84
|
+
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
85
|
+
*/
|
|
86
|
+
brokenRoute?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Arguments for `buildQueryURL` to construct a Query URL.
|
|
90
|
+
*/
|
|
91
|
+
type BuildQueryURLParams = {
|
|
92
|
+
/**
|
|
93
|
+
* Ref used to query documents.
|
|
94
|
+
*
|
|
95
|
+
* {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
|
|
96
|
+
*/
|
|
97
|
+
ref: string;
|
|
98
|
+
/**
|
|
99
|
+
* Ref used to populate Integration Fields with the latest content.
|
|
100
|
+
*
|
|
101
|
+
* {@link https://prismic.io/docs/core-concepts/integration-fields}
|
|
102
|
+
*/
|
|
103
|
+
integrationFieldsRef?: string;
|
|
104
|
+
/**
|
|
105
|
+
* One or more predicates to filter documents for the query.
|
|
106
|
+
*
|
|
107
|
+
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}
|
|
108
|
+
*/
|
|
109
|
+
predicates?: string | string[];
|
|
110
|
+
};
|
|
111
|
+
export type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;
|
|
112
|
+
/**
|
|
113
|
+
* Build a Prismic REST API V2 URL to request documents from a repository. The
|
|
114
|
+
* paginated response for this URL includes documents matching the parameters.
|
|
115
|
+
*
|
|
116
|
+
* A ref is required to make a request. Request the `endpoint` URL to retrieve a
|
|
117
|
+
* list of available refs.
|
|
118
|
+
*
|
|
119
|
+
* Type the JSON response with `Query`.
|
|
120
|
+
*
|
|
121
|
+
* {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
|
|
122
|
+
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}
|
|
123
|
+
*
|
|
124
|
+
* @param endpoint - URL to the repository's REST API V2.
|
|
125
|
+
* @param args - Arguments to filter and scope the query.
|
|
126
|
+
*
|
|
127
|
+
* @returns URL that can be used to request documents from the repository.
|
|
128
|
+
*/
|
|
129
|
+
export declare const buildQueryURL: (endpoint: string, args: BuildQueryURLArgs) => string;
|
|
130
|
+
export {};
|
package/dist/client.cjs
CHANGED
|
@@ -61,6 +61,7 @@ class Client {
|
|
|
61
61
|
__publicField(this, "routes");
|
|
62
62
|
__publicField(this, "brokenRoute");
|
|
63
63
|
__publicField(this, "fetchFn");
|
|
64
|
+
__publicField(this, "fetchOptions");
|
|
64
65
|
__publicField(this, "defaultParams");
|
|
65
66
|
__publicField(this, "refState", {
|
|
66
67
|
mode: RefStateMode.Master,
|
|
@@ -80,6 +81,7 @@ class Client {
|
|
|
80
81
|
this.accessToken = options.accessToken;
|
|
81
82
|
this.routes = options.routes;
|
|
82
83
|
this.brokenRoute = options.brokenRoute;
|
|
84
|
+
this.fetchOptions = options.fetchOptions;
|
|
83
85
|
this.defaultParams = options.defaultParams;
|
|
84
86
|
if (options.ref) {
|
|
85
87
|
this.queryContentFromRef(options.ref);
|
|
@@ -249,9 +251,9 @@ class Client {
|
|
|
249
251
|
return repository.tags;
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
|
-
async buildQueryURL({ signal, ...params } = {}) {
|
|
253
|
-
const ref = params.ref || await this.getResolvedRefString();
|
|
254
|
-
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal })).integrationFieldsRef || void 0;
|
|
254
|
+
async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
|
|
255
|
+
const ref = params.ref || await this.getResolvedRefString({ signal, fetchOptions });
|
|
256
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, fetchOptions })).integrationFieldsRef || void 0;
|
|
255
257
|
return buildQueryURL.buildQueryURL(this.endpoint, {
|
|
256
258
|
...this.defaultParams,
|
|
257
259
|
...params,
|
|
@@ -282,9 +284,10 @@ class Client {
|
|
|
282
284
|
}
|
|
283
285
|
if (documentID != null && previewToken != null) {
|
|
284
286
|
const document = await this.getByID(documentID, {
|
|
285
|
-
signal: args.signal,
|
|
286
287
|
ref: previewToken,
|
|
287
|
-
lang: "*"
|
|
288
|
+
lang: "*",
|
|
289
|
+
signal: args.signal,
|
|
290
|
+
fetchOptions: args.fetchOptions
|
|
288
291
|
});
|
|
289
292
|
const url = prismicH__namespace.asLink(document, args.linkResolver);
|
|
290
293
|
if (typeof url === "string") {
|
|
@@ -401,8 +404,15 @@ class Client {
|
|
|
401
404
|
return findMasterRef.findMasterRef(cachedRepository.refs).ref;
|
|
402
405
|
}
|
|
403
406
|
async fetch(url, params = {}) {
|
|
407
|
+
var _a, _b, _c, _d;
|
|
404
408
|
const res = await this.fetchFn(url, {
|
|
405
|
-
|
|
409
|
+
...this.fetchOptions,
|
|
410
|
+
...params.fetchOptions,
|
|
411
|
+
headers: {
|
|
412
|
+
...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
|
|
413
|
+
...(_b = params.fetchOptions) == null ? void 0 : _b.headers
|
|
414
|
+
},
|
|
415
|
+
signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
|
|
406
416
|
});
|
|
407
417
|
let json;
|
|
408
418
|
try {
|