@prismicio/client 7.1.0 → 7.2.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/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +1 -0
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs +23 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +15 -0
- package/dist/createClient.js +23 -1
- package/dist/createClient.js.map +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.d.ts +1 -0
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +0 -6
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +2 -1
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +2 -1
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +2 -1
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +3 -4
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +3 -1
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +0 -4
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/isFilled.d.ts +13 -10
- package/dist/helpers/unstable_mapSliceZone.cjs.map +1 -1
- package/dist/helpers/unstable_mapSliceZone.d.ts +12 -5
- package/dist/helpers/unstable_mapSliceZone.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/types/api/repository.d.ts +6 -1
- package/package.json +20 -20
- package/src/buildQueryURL.ts +1 -0
- package/src/createClient.ts +47 -1
- package/src/getRepositoryName.ts +1 -0
- package/src/helpers/asHTML.ts +0 -6
- package/src/helpers/asImagePixelDensitySrcSet.ts +1 -0
- package/src/helpers/asImageSrc.ts +1 -0
- package/src/helpers/asImageWidthSrcSet.ts +1 -0
- package/src/helpers/asLink.ts +3 -4
- package/src/helpers/asLinkAttrs.ts +2 -0
- package/src/helpers/asText.ts +0 -4
- package/src/helpers/unstable_mapSliceZone.ts +19 -8
- package/src/types/api/repository.ts +6 -2
package/src/createClient.ts
CHANGED
|
@@ -51,6 +51,15 @@ export const REPOSITORY_CACHE_TTL = 5000;
|
|
|
51
51
|
*/
|
|
52
52
|
export const GET_ALL_QUERY_DELAY = 500;
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The default number of milliseconds to wait before retrying a rate-limited
|
|
56
|
+
* `fetch()` request (429 response code). The default value is only used if the
|
|
57
|
+
* response does not include a `retry-after` header.
|
|
58
|
+
*
|
|
59
|
+
* The API allows up to 200 requests per second.
|
|
60
|
+
*/
|
|
61
|
+
const DEFUALT_RETRY_AFTER_MS = 1000;
|
|
62
|
+
|
|
54
63
|
/**
|
|
55
64
|
* Extracts one or more Prismic document types that match a given Prismic
|
|
56
65
|
* document type. If no matches are found, no extraction is performed and the
|
|
@@ -120,10 +129,18 @@ export interface RequestInitLike extends Pick<RequestInit, "cache"> {
|
|
|
120
129
|
*/
|
|
121
130
|
export interface ResponseLike {
|
|
122
131
|
status: number;
|
|
132
|
+
headers: HeadersLike;
|
|
123
133
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
134
|
json(): Promise<any>;
|
|
125
135
|
}
|
|
126
136
|
|
|
137
|
+
/**
|
|
138
|
+
* The minimum required properties from Headers.
|
|
139
|
+
*/
|
|
140
|
+
export interface HeadersLike {
|
|
141
|
+
get(name: string): string | null;
|
|
142
|
+
}
|
|
143
|
+
|
|
127
144
|
/**
|
|
128
145
|
* The minimum required properties to treat as an HTTP Request for automatic
|
|
129
146
|
* Prismic preview support.
|
|
@@ -342,6 +359,7 @@ type ResolvePreviewArgs<LinkResolverReturnType> = {
|
|
|
342
359
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
343
360
|
type FetchJobResult<TJSON = any> = {
|
|
344
361
|
status: number;
|
|
362
|
+
headers: HeadersLike;
|
|
345
363
|
json: TJSON;
|
|
346
364
|
};
|
|
347
365
|
|
|
@@ -370,6 +388,7 @@ export interface CreateClient {
|
|
|
370
388
|
*
|
|
371
389
|
* @typeParam TDocuments - A map of Prismic document type IDs mapped to their
|
|
372
390
|
* TypeScript type.
|
|
391
|
+
*
|
|
373
392
|
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
|
|
374
393
|
* API V2 endpoint for the repository.
|
|
375
394
|
* @param options - Configuration that determines how content will be queried
|
|
@@ -664,7 +683,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
664
683
|
return firstResult;
|
|
665
684
|
}
|
|
666
685
|
|
|
667
|
-
throw new
|
|
686
|
+
throw new NotFoundError("No documents were returned", url, undefined);
|
|
668
687
|
}
|
|
669
688
|
|
|
670
689
|
/**
|
|
@@ -732,6 +751,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
732
751
|
* for all documents and is made available on its `id` property. A UID is
|
|
733
752
|
* provided in the Prismic editor and is unique among all documents of its
|
|
734
753
|
* custom type.
|
|
754
|
+
*
|
|
735
755
|
* @example
|
|
736
756
|
*
|
|
737
757
|
* ```ts
|
|
@@ -763,6 +783,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
763
783
|
* for all documents and is made available on its `id` property. A UID is
|
|
764
784
|
* provided in the Prismic editor and is unique among all documents of its
|
|
765
785
|
* custom type.
|
|
786
|
+
*
|
|
766
787
|
* @example
|
|
767
788
|
*
|
|
768
789
|
* ```ts
|
|
@@ -800,6 +821,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
800
821
|
* for all documents and is made available on its `id` property. A UID is
|
|
801
822
|
* provided in the Prismic editor and is unique among all documents of its
|
|
802
823
|
* custom type.
|
|
824
|
+
*
|
|
803
825
|
* @example
|
|
804
826
|
*
|
|
805
827
|
* ```ts
|
|
@@ -834,6 +856,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
834
856
|
* for all documents and is made available on its `id` property. A UID is
|
|
835
857
|
* provided in the Prismic editor and is unique among all documents of its
|
|
836
858
|
* custom type.
|
|
859
|
+
*
|
|
837
860
|
* @example
|
|
838
861
|
*
|
|
839
862
|
* ```ts
|
|
@@ -874,6 +897,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
874
897
|
* for all documents and is made available on its `id` property. A UID is
|
|
875
898
|
* provided in the Prismic editor and is unique among all documents of its
|
|
876
899
|
* custom type.
|
|
900
|
+
*
|
|
877
901
|
* @example
|
|
878
902
|
*
|
|
879
903
|
* ```ts
|
|
@@ -920,6 +944,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
920
944
|
* for all documents and is made available on its `id` property. A UID is
|
|
921
945
|
* provided in the Prismic editor and is unique among all documents of its
|
|
922
946
|
* custom type.
|
|
947
|
+
*
|
|
923
948
|
* @example
|
|
924
949
|
*
|
|
925
950
|
* ```ts
|
|
@@ -964,6 +989,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
964
989
|
* instance. For example, a repository may be configured to contain just one
|
|
965
990
|
* Settings document. This is in contrast to a repeatable custom type which
|
|
966
991
|
* allows multiple instances of itself.
|
|
992
|
+
*
|
|
967
993
|
* @example
|
|
968
994
|
*
|
|
969
995
|
* ```ts
|
|
@@ -1831,6 +1857,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
1831
1857
|
|
|
1832
1858
|
return {
|
|
1833
1859
|
status: res.status,
|
|
1860
|
+
headers: res.headers,
|
|
1834
1861
|
json,
|
|
1835
1862
|
};
|
|
1836
1863
|
})
|
|
@@ -1888,6 +1915,25 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
1888
1915
|
undefined,
|
|
1889
1916
|
);
|
|
1890
1917
|
}
|
|
1918
|
+
|
|
1919
|
+
// Too Many Requests
|
|
1920
|
+
// - Exceeded the maximum number of requests per second
|
|
1921
|
+
case 429: {
|
|
1922
|
+
const parsedRetryAfter = Number(res.headers.get("retry-after"));
|
|
1923
|
+
const delay = Number.isNaN(parsedRetryAfter)
|
|
1924
|
+
? DEFUALT_RETRY_AFTER_MS
|
|
1925
|
+
: parsedRetryAfter;
|
|
1926
|
+
|
|
1927
|
+
return await new Promise((resolve, reject) => {
|
|
1928
|
+
setTimeout(async () => {
|
|
1929
|
+
try {
|
|
1930
|
+
resolve(await this.fetch(url, params));
|
|
1931
|
+
} catch (error) {
|
|
1932
|
+
reject(error);
|
|
1933
|
+
}
|
|
1934
|
+
}, delay);
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1891
1937
|
}
|
|
1892
1938
|
|
|
1893
1939
|
throw new PrismicError(undefined, url, res.json);
|
package/src/getRepositoryName.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { PrismicError } from "./errors/PrismicError";
|
|
|
6
6
|
*
|
|
7
7
|
* @typeParam RepositoryEndpoint - Prismic Rest API V2 endpoint for the
|
|
8
8
|
* repository.
|
|
9
|
+
*
|
|
9
10
|
* @param repositoryEndpoint - Prismic Rest API V2 endpoint for the repository.
|
|
10
11
|
*
|
|
11
12
|
* @returns The Prismic repository's name.
|
package/src/helpers/asHTML.ts
CHANGED
|
@@ -255,12 +255,6 @@ export const asHTML: {
|
|
|
255
255
|
*
|
|
256
256
|
* @deprecated Use object-style configuration instead.
|
|
257
257
|
*
|
|
258
|
-
* ```ts
|
|
259
|
-
* asHTML(field);
|
|
260
|
-
* asHTML(field, { linkResolver });
|
|
261
|
-
* asHTML(field, { serializer });
|
|
262
|
-
* asHTML(field, { linkResolver, serializer });
|
|
263
|
-
* ```
|
|
264
258
|
* @param richTextField - A rich text or title field from Prismic
|
|
265
259
|
* @param linkResolver - An optional link resolver function to resolve links,
|
|
266
260
|
* without it you're expected to use the `routes` options from the API
|
|
@@ -70,6 +70,7 @@ type AsImagePixelDensitySrcSetReturnType<
|
|
|
70
70
|
*
|
|
71
71
|
* @returns A `srcset` attribute value for the image field with Imgix URL
|
|
72
72
|
* parameters (if given). If the image field is empty, `null` is returned.
|
|
73
|
+
*
|
|
73
74
|
* @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
|
|
74
75
|
*/
|
|
75
76
|
export const asImagePixelDensitySrcSet = <
|
|
@@ -27,6 +27,7 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =
|
|
|
27
27
|
*
|
|
28
28
|
* @returns The image field's image URL with transformations applied (if given).
|
|
29
29
|
* If the image field is empty, `null` is returned.
|
|
30
|
+
*
|
|
30
31
|
* @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
|
|
31
32
|
*/
|
|
32
33
|
export const asImageSrc = <Field extends ImageFieldImage | null | undefined>(
|
|
@@ -74,6 +74,7 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
|
74
74
|
*
|
|
75
75
|
* @returns A `srcset` attribute value for the image field with Imgix URL
|
|
76
76
|
* parameters (if given). If the image field is empty, `null` is returned.
|
|
77
|
+
*
|
|
77
78
|
* @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
|
|
78
79
|
*/
|
|
79
80
|
export const asImageWidthSrcSet = <
|
package/src/helpers/asLink.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { documentToLinkField } from "./documentToLinkField";
|
|
|
10
10
|
*
|
|
11
11
|
* @typeParam ReturnType - Return type of your link resolver function, useful if
|
|
12
12
|
* you prefer to return a complex object
|
|
13
|
+
*
|
|
13
14
|
* @param linkToDocumentField - A document link field to resolve
|
|
14
15
|
*
|
|
15
16
|
* @returns Resolved URL
|
|
@@ -75,6 +76,7 @@ export const asLink: {
|
|
|
75
76
|
*
|
|
76
77
|
* @returns Resolved URL or, if the provided link field or document is empty,
|
|
77
78
|
* `null`
|
|
79
|
+
*
|
|
78
80
|
* @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
79
81
|
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
80
82
|
*/
|
|
@@ -95,10 +97,6 @@ export const asLink: {
|
|
|
95
97
|
*
|
|
96
98
|
* @deprecated Use object-style configuration instead.
|
|
97
99
|
*
|
|
98
|
-
* ```ts
|
|
99
|
-
* asLink(field);
|
|
100
|
-
* asLink(field, { linkResolver });
|
|
101
|
-
* ```
|
|
102
100
|
* @typeParam LinkResolverFunctionReturnType - link resolver function return
|
|
103
101
|
* type
|
|
104
102
|
* @typeParam Field - Link field or Prismic document to resolve to a URL
|
|
@@ -110,6 +108,7 @@ export const asLink: {
|
|
|
110
108
|
*
|
|
111
109
|
* @returns Resolved URL or, if the provided link field or document is empty,
|
|
112
110
|
* `null`
|
|
111
|
+
*
|
|
113
112
|
* @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
114
113
|
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
115
114
|
*/
|
|
@@ -77,11 +77,13 @@ type AsLinkAttrsReturnType<
|
|
|
77
77
|
* type
|
|
78
78
|
* @typeParam Field - Link field or Prismic document to resolve to link
|
|
79
79
|
* attributes
|
|
80
|
+
*
|
|
80
81
|
* @param linkFieldOrDocument - Any kind of link field or a document to resolve
|
|
81
82
|
* @param config - Configuration that determines the output of `asLinkAttrs()`
|
|
82
83
|
*
|
|
83
84
|
* @returns Resolved set of link attributes or, if the provided link field or
|
|
84
85
|
* document is empty, and empty object
|
|
86
|
+
*
|
|
85
87
|
* @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
86
88
|
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
87
89
|
*/
|
package/src/helpers/asText.ts
CHANGED
|
@@ -47,10 +47,6 @@ export const asText: {
|
|
|
47
47
|
*
|
|
48
48
|
* @deprecated Use object-style configuration instead.
|
|
49
49
|
*
|
|
50
|
-
* ```ts
|
|
51
|
-
* asText(field);
|
|
52
|
-
* asText(field, { separator });
|
|
53
|
-
* ```
|
|
54
50
|
* @param richTextField - A rich text or title field from Prismic
|
|
55
51
|
* @param separator - Separator used to join each element, defaults to a space
|
|
56
52
|
*
|
|
@@ -18,17 +18,28 @@ type MaybeLazyModule<T> = T | LazyModule<T>;
|
|
|
18
18
|
*/
|
|
19
19
|
type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
|
|
20
20
|
? TSlice["slice_type"]
|
|
21
|
-
: TSlice extends
|
|
21
|
+
: TSlice extends SliceLikeGraphQL
|
|
22
22
|
? TSlice["type"]
|
|
23
23
|
: never;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
27
|
+
* Rest API V2 for the `unstable_mapSliceZone()` helper.
|
|
28
|
+
*
|
|
29
|
+
* @typeParam SliceType - Type name of the Slice.
|
|
30
|
+
*/
|
|
31
|
+
type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
32
|
+
Slice<TSliceType>,
|
|
33
|
+
"id" | "slice_type"
|
|
34
|
+
>;
|
|
35
|
+
|
|
25
36
|
/**
|
|
26
37
|
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
27
38
|
* GraphQL API for the `unstable_mapSliceZone()` helper.
|
|
28
39
|
*
|
|
29
40
|
* @typeParam SliceType - Type name of the Slice.
|
|
30
41
|
*/
|
|
31
|
-
type
|
|
42
|
+
type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
32
43
|
type: Slice<TSliceType>["slice_type"];
|
|
33
44
|
};
|
|
34
45
|
|
|
@@ -42,8 +53,8 @@ type SliceGraphQLLike<TSliceType extends string = string> = {
|
|
|
42
53
|
* @typeParam SliceType - Type name of the Slice.
|
|
43
54
|
*/
|
|
44
55
|
type SliceLike<TSliceType extends string = string> =
|
|
45
|
-
|
|
|
46
|
-
|
|
|
56
|
+
| SliceLikeRestV2<TSliceType>
|
|
57
|
+
| SliceLikeGraphQL<TSliceType>;
|
|
47
58
|
|
|
48
59
|
/**
|
|
49
60
|
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
@@ -101,7 +112,7 @@ type SliceMapperArgs<
|
|
|
101
112
|
// union of Slice types, it would include TSlice. This causes TypeScript to
|
|
102
113
|
// throw a compilation error.
|
|
103
114
|
slices: SliceZoneLike<
|
|
104
|
-
TSlice extends
|
|
115
|
+
TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2
|
|
105
116
|
>;
|
|
106
117
|
|
|
107
118
|
/**
|
|
@@ -171,7 +182,7 @@ type MapSliceLike<
|
|
|
171
182
|
TMappers extends Mappers,
|
|
172
183
|
> = TSliceLike extends Slice
|
|
173
184
|
? TSliceLike["slice_type"] extends keyof TMappers
|
|
174
|
-
?
|
|
185
|
+
? SliceLikeRestV2<TSliceLike["slice_type"]> &
|
|
175
186
|
MappedSliceLike &
|
|
176
187
|
Awaited<
|
|
177
188
|
ReturnType<
|
|
@@ -179,9 +190,9 @@ type MapSliceLike<
|
|
|
179
190
|
>
|
|
180
191
|
>
|
|
181
192
|
: TSliceLike
|
|
182
|
-
: TSliceLike extends
|
|
193
|
+
: TSliceLike extends SliceLikeGraphQL
|
|
183
194
|
? TSliceLike["type"] extends keyof TMappers
|
|
184
|
-
?
|
|
195
|
+
? SliceLikeGraphQL<TSliceLike["type"]> &
|
|
185
196
|
MappedSliceLike &
|
|
186
197
|
Awaited<
|
|
187
198
|
ReturnType<ResolveLazyMapperModule<TMappers[TSliceLike["type"]]>>
|
|
@@ -34,7 +34,9 @@ export interface Repository {
|
|
|
34
34
|
types: Record<string, string>;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* @deprecated Tags are only available in the forms object.
|
|
38
|
+
*
|
|
39
|
+
* @see More details in the blog post "A change to how the Prismic API handles tags": {@link https://prismic.io/blog/a-change-to-how-the-prismic-api-handles-tags}
|
|
38
40
|
*/
|
|
39
41
|
tags: string[];
|
|
40
42
|
|
|
@@ -50,7 +52,9 @@ export interface Repository {
|
|
|
50
52
|
*/
|
|
51
53
|
oauth_initiate: string;
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The token used for the OAuth process for the repository.
|
|
57
|
+
*/
|
|
54
58
|
oauth_token: string;
|
|
55
59
|
|
|
56
60
|
/**
|