@prismicio/client 7.20.2-alpha.0 → 7.20.3
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/Client.cjs +120 -132
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.ts +7 -7
- package/dist/Client.js +120 -132
- package/dist/Client.js.map +1 -1
- package/dist/Migration.cjs +83 -101
- package/dist/Migration.cjs.map +1 -1
- package/dist/Migration.d.ts +9 -9
- package/dist/Migration.js +83 -101
- package/dist/Migration.js.map +1 -1
- package/dist/WriteClient.cjs +115 -92
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.ts +6 -6
- package/dist/WriteClient.js +115 -92
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +29 -21
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +13 -10
- package/dist/createClient.js.map +1 -1
- package/dist/createMigration.cjs.map +1 -1
- package/dist/createMigration.d.ts +2 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createWriteClient.cjs.map +1 -1
- package/dist/createWriteClient.d.ts +2 -2
- package/dist/errors/ForbiddenError.d.ts +1 -1
- package/dist/errors/InvalidDataError.d.ts +1 -1
- package/dist/errors/NotFoundError.d.ts +1 -1
- package/dist/errors/ParsingError.d.ts +1 -1
- package/dist/errors/PreviewTokenExpired.d.ts +1 -1
- package/dist/errors/PrismicError.cjs +2 -5
- package/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/errors/PrismicError.js +2 -5
- package/dist/errors/PrismicError.js.map +1 -1
- package/dist/errors/RefExpiredError.d.ts +1 -1
- package/dist/errors/RefNotFoundError.d.ts +1 -1
- package/dist/errors/RepositoryNotFoundError.d.ts +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.d.ts +9 -2
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +13 -6
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs +22 -22
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +37 -29
- package/dist/helpers/asHTML.js +22 -22
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +17 -16
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +12 -11
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +19 -18
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +36 -35
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +11 -14
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +21 -11
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs +1 -2
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts +2 -2
- package/dist/helpers/documentToLinkField.js +1 -2
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +35 -34
- package/dist/helpers/isFilled.js +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +11 -11
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +120 -120
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +2 -2
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/everyTagFilter.js.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +1 -1
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +1 -1
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +1 -1
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +1 -1
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
- package/dist/lib/getOptionalLinkProperties.d.ts +1 -1
- package/dist/lib/getOptionalLinkProperties.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/isMigrationValue.cjs.map +1 -1
- package/dist/lib/isMigrationValue.d.ts +8 -8
- package/dist/lib/isMigrationValue.js.map +1 -1
- package/dist/lib/isValue.cjs.map +1 -1
- package/dist/lib/isValue.d.ts +10 -10
- package/dist/lib/isValue.js.map +1 -1
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
- package/dist/lib/minifyGraphQLQuery.js.map +1 -1
- package/dist/lib/pLimit.cjs +3 -4
- package/dist/lib/pLimit.cjs.map +1 -1
- package/dist/lib/pLimit.js +3 -4
- package/dist/lib/pLimit.js.map +1 -1
- package/dist/lib/request.cjs +8 -10
- package/dist/lib/request.cjs.map +1 -1
- package/dist/lib/request.js +8 -10
- package/dist/lib/request.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs +4 -6
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.d.ts +8 -8
- package/dist/lib/resolveMigrationDocumentData.js +4 -6
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +2 -2
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +3 -3
- package/dist/lib/serializerHelpers.js +2 -2
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs.map +1 -1
- package/dist/lib/someTagsFilter.js.map +1 -1
- package/dist/lib/throttledLog.cjs.map +1 -1
- package/dist/lib/throttledLog.js.map +1 -1
- package/dist/lib/typeFilter.cjs.map +1 -1
- package/dist/lib/typeFilter.js.map +1 -1
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.d.ts +1 -1
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.ts +6 -6
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.ts +2 -2
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/index.d.ts +7 -7
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +10 -10
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +7 -7
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/api/asset/asset.d.ts +1 -1
- package/dist/types/api/integration.d.ts +1 -1
- package/dist/types/api/migration/document.d.ts +1 -1
- package/dist/types/api/query.d.ts +1 -1
- package/dist/types/api/release.d.ts +1 -1
- package/dist/types/api/repository.d.ts +1 -1
- package/dist/types/migration/Asset.cjs +12 -15
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.d.ts +7 -7
- package/dist/types/migration/Asset.js +12 -15
- package/dist/types/migration/Asset.js.map +1 -1
- package/dist/types/migration/ContentRelationship.d.ts +3 -3
- package/dist/types/migration/Document.cjs +24 -27
- package/dist/types/migration/Document.cjs.map +1 -1
- package/dist/types/migration/Document.d.ts +9 -9
- package/dist/types/migration/Document.js +24 -27
- package/dist/types/migration/Document.js.map +1 -1
- package/dist/types/migration/Link.d.ts +1 -1
- package/dist/types/model/boolean.d.ts +1 -1
- package/dist/types/model/color.d.ts +1 -1
- package/dist/types/model/contentRelationship.d.ts +3 -2
- package/dist/types/model/customType.d.ts +1 -1
- package/dist/types/model/date.d.ts +1 -1
- package/dist/types/model/embed.d.ts +1 -1
- package/dist/types/model/geoPoint.d.ts +1 -1
- package/dist/types/model/group.d.ts +1 -1
- package/dist/types/model/image.d.ts +1 -1
- package/dist/types/model/integration.d.ts +1 -1
- package/dist/types/model/keyText.d.ts +1 -1
- package/dist/types/model/link.d.ts +1 -1
- package/dist/types/model/linkToMedia.d.ts +2 -2
- package/dist/types/model/number.d.ts +1 -1
- package/dist/types/model/range.d.ts +1 -1
- package/dist/types/model/richText.d.ts +1 -1
- package/dist/types/model/select.d.ts +1 -1
- package/dist/types/model/separator.d.ts +1 -1
- package/dist/types/model/sharedSlice.d.ts +2 -2
- package/dist/types/model/sharedSliceVariation.d.ts +1 -1
- package/dist/types/model/slice.d.ts +3 -3
- package/dist/types/model/sliceZone.d.ts +2 -2
- package/dist/types/model/table.d.ts +1 -1
- package/dist/types/model/timestamp.d.ts +1 -1
- package/dist/types/model/title.d.ts +1 -1
- package/dist/types/model/types.d.ts +22 -22
- package/dist/types/model/uid.d.ts +1 -1
- package/dist/types/value/color.d.ts +1 -1
- package/dist/types/value/contentRelationship.d.ts +3 -3
- package/dist/types/value/date.d.ts +1 -1
- package/dist/types/value/document.d.ts +4 -4
- package/dist/types/value/embed.d.ts +1 -1
- package/dist/types/value/geoPoint.d.ts +1 -1
- package/dist/types/value/group.d.ts +1 -1
- package/dist/types/value/image.d.ts +1 -1
- package/dist/types/value/integration.d.ts +1 -1
- package/dist/types/value/keyText.d.ts +1 -1
- package/dist/types/value/link.d.ts +5 -5
- package/dist/types/value/linkToMedia.d.ts +2 -2
- package/dist/types/value/number.d.ts +1 -1
- package/dist/types/value/richText.d.ts +3 -3
- package/dist/types/value/select.d.ts +1 -1
- package/dist/types/value/sharedSlice.d.ts +1 -1
- package/dist/types/value/sharedSliceVariation.d.ts +1 -1
- package/dist/types/value/slice.d.ts +1 -1
- package/dist/types/value/sliceZone.d.ts +3 -3
- package/dist/types/value/table.d.ts +2 -2
- package/dist/types/value/timestamp.d.ts +2 -2
- package/dist/types/value/title.d.ts +2 -2
- package/dist/types/value/types.d.ts +18 -18
- package/dist/types/webhook/apiUpdate.d.ts +1 -1
- package/dist/types/webhook/testTrigger.d.ts +1 -1
- package/dist/types/webhook/types.d.ts +2 -2
- package/package.json +11 -11
- package/src/WriteClient.ts +32 -21
- package/src/buildQueryURL.ts +29 -21
- package/src/createClient.ts +11 -8
- package/src/getRepositoryEndpoint.ts +9 -2
- package/src/helpers/asDate.ts +11 -4
- package/src/helpers/asHTML.ts +34 -26
- package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
- package/src/helpers/asImageSrc.ts +11 -10
- package/src/helpers/asImageWidthSrcSet.ts +18 -17
- package/src/helpers/asLink.ts +33 -32
- package/src/helpers/asLinkAttrs.ts +6 -9
- package/src/helpers/asText.ts +20 -10
- package/src/helpers/isFilled.ts +15 -14
- package/src/helpers/mapSliceZone.ts +10 -10
- package/src/index.ts +2 -2
- package/src/isRepositoryEndpoint.ts +2 -2
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/serialize.ts +8 -8
- package/src/richtext/types.ts +6 -6
- package/src/types/migration/Asset.ts +10 -2
- package/src/types/model/contentRelationship.ts +1 -0
package/dist/Client.cjs
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __typeError = (msg) => {
|
|
4
|
-
throw TypeError(msg);
|
|
5
|
-
};
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
9
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
10
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
11
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
12
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
13
|
-
var _repositoryName, _Client_instances, request_fn;
|
|
14
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
15
3
|
const appendFilters = require("./lib/appendFilters.cjs");
|
|
16
4
|
const castThunk = require("./lib/castThunk.cjs");
|
|
@@ -51,6 +39,98 @@ var RefStateMode;
|
|
|
51
39
|
RefStateMode2["Manual"] = "Manual";
|
|
52
40
|
})(RefStateMode || (RefStateMode = {}));
|
|
53
41
|
class Client {
|
|
42
|
+
/**
|
|
43
|
+
* The function used to make network requests to the Prismic REST API. In
|
|
44
|
+
* environments where a global `fetch` function does not exist, such as
|
|
45
|
+
* Node.js, this function must be provided.
|
|
46
|
+
*/
|
|
47
|
+
fetchFn;
|
|
48
|
+
fetchOptions;
|
|
49
|
+
#repositoryName;
|
|
50
|
+
/**
|
|
51
|
+
* The Prismic repository's name.
|
|
52
|
+
*/
|
|
53
|
+
set repositoryName(value) {
|
|
54
|
+
this.#repositoryName = value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The Prismic repository's name.
|
|
58
|
+
*/
|
|
59
|
+
get repositoryName() {
|
|
60
|
+
if (!this.#repositoryName) {
|
|
61
|
+
throw new PrismicError.PrismicError(`A repository name is required for this method but one could not be inferred from the provided API endpoint (\`${this.documentAPIEndpoint}\`). To fix this error, provide a repository name when creating the client. For more details, see ${devMsg.devMsg("prefer-repository-name")}`, void 0, void 0);
|
|
62
|
+
}
|
|
63
|
+
return this.#repositoryName;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The Prismic REST API V2 endpoint for the repository (use
|
|
67
|
+
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
68
|
+
*/
|
|
69
|
+
documentAPIEndpoint;
|
|
70
|
+
/**
|
|
71
|
+
* The Prismic REST API V2 endpoint for the repository (use
|
|
72
|
+
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
73
|
+
*
|
|
74
|
+
* @deprecated Use `documentAPIEndpoint` instead.
|
|
75
|
+
*/
|
|
76
|
+
// TODO: Remove in v8.
|
|
77
|
+
set endpoint(value) {
|
|
78
|
+
this.documentAPIEndpoint = value;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The Prismic REST API V2 endpoint for the repository (use
|
|
82
|
+
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
83
|
+
*
|
|
84
|
+
* @deprecated Use `documentAPIEndpoint` instead.
|
|
85
|
+
*/
|
|
86
|
+
// TODO: Remove in v8.
|
|
87
|
+
get endpoint() {
|
|
88
|
+
return this.documentAPIEndpoint;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The secure token for accessing the API (only needed if your repository is
|
|
92
|
+
* set to private).
|
|
93
|
+
*
|
|
94
|
+
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
|
|
95
|
+
*/
|
|
96
|
+
accessToken;
|
|
97
|
+
/**
|
|
98
|
+
* A list of route resolver objects that define how a document's `url` field
|
|
99
|
+
* is resolved.
|
|
100
|
+
*
|
|
101
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
102
|
+
*/
|
|
103
|
+
routes;
|
|
104
|
+
/**
|
|
105
|
+
* The `brokenRoute` option allows you to define the route populated in the
|
|
106
|
+
* `url` property for broken link or content relationship fields. A broken
|
|
107
|
+
* link is a link or content relationship field whose linked document has been
|
|
108
|
+
* unpublished or deleted.
|
|
109
|
+
*
|
|
110
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
111
|
+
*/
|
|
112
|
+
brokenRoute;
|
|
113
|
+
/**
|
|
114
|
+
* Default parameters that will be sent with each query. These parameters can
|
|
115
|
+
* be overridden on each query if needed.
|
|
116
|
+
*/
|
|
117
|
+
defaultParams;
|
|
118
|
+
/**
|
|
119
|
+
* The client's ref mode state. This determines which ref is used during
|
|
120
|
+
* queries.
|
|
121
|
+
*/
|
|
122
|
+
refState = {
|
|
123
|
+
mode: RefStateMode.Master,
|
|
124
|
+
autoPreviewsEnabled: true
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Cached repository value.
|
|
128
|
+
*/
|
|
129
|
+
cachedRepository;
|
|
130
|
+
/**
|
|
131
|
+
* Timestamp at which the cached repository data is considered stale.
|
|
132
|
+
*/
|
|
133
|
+
cachedRepositoryExpiration = 0;
|
|
54
134
|
/**
|
|
55
135
|
* Creates a Prismic client that can be used to query a repository.
|
|
56
136
|
*
|
|
@@ -66,64 +146,6 @@ class Client {
|
|
|
66
146
|
* @returns A client that can query content from the repository.
|
|
67
147
|
*/
|
|
68
148
|
constructor(repositoryNameOrEndpoint, options = {}) {
|
|
69
|
-
__privateAdd(this, _Client_instances);
|
|
70
|
-
/**
|
|
71
|
-
* The function used to make network requests to the Prismic REST API. In
|
|
72
|
-
* environments where a global `fetch` function does not exist, such as
|
|
73
|
-
* Node.js, this function must be provided.
|
|
74
|
-
*/
|
|
75
|
-
__publicField(this, "fetchFn");
|
|
76
|
-
__publicField(this, "fetchOptions");
|
|
77
|
-
__privateAdd(this, _repositoryName);
|
|
78
|
-
/**
|
|
79
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
80
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
81
|
-
*/
|
|
82
|
-
__publicField(this, "documentAPIEndpoint");
|
|
83
|
-
/**
|
|
84
|
-
* The secure token for accessing the API (only needed if your repository is
|
|
85
|
-
* set to private).
|
|
86
|
-
*
|
|
87
|
-
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
|
|
88
|
-
*/
|
|
89
|
-
__publicField(this, "accessToken");
|
|
90
|
-
/**
|
|
91
|
-
* A list of route resolver objects that define how a document's `url` field
|
|
92
|
-
* is resolved.
|
|
93
|
-
*
|
|
94
|
-
* {@link https://prismic.io/docs/route-resolver}
|
|
95
|
-
*/
|
|
96
|
-
__publicField(this, "routes");
|
|
97
|
-
/**
|
|
98
|
-
* The `brokenRoute` option allows you to define the route populated in the
|
|
99
|
-
* `url` property for broken link or content relationship fields. A broken
|
|
100
|
-
* link is a link or content relationship field whose linked document has been
|
|
101
|
-
* unpublished or deleted.
|
|
102
|
-
*
|
|
103
|
-
* {@link https://prismic.io/docs/route-resolver}
|
|
104
|
-
*/
|
|
105
|
-
__publicField(this, "brokenRoute");
|
|
106
|
-
/**
|
|
107
|
-
* Default parameters that will be sent with each query. These parameters can
|
|
108
|
-
* be overridden on each query if needed.
|
|
109
|
-
*/
|
|
110
|
-
__publicField(this, "defaultParams");
|
|
111
|
-
/**
|
|
112
|
-
* The client's ref mode state. This determines which ref is used during
|
|
113
|
-
* queries.
|
|
114
|
-
*/
|
|
115
|
-
__publicField(this, "refState", {
|
|
116
|
-
mode: RefStateMode.Master,
|
|
117
|
-
autoPreviewsEnabled: true
|
|
118
|
-
});
|
|
119
|
-
/**
|
|
120
|
-
* Cached repository value.
|
|
121
|
-
*/
|
|
122
|
-
__publicField(this, "cachedRepository");
|
|
123
|
-
/**
|
|
124
|
-
* Timestamp at which the cached repository data is considered stale.
|
|
125
|
-
*/
|
|
126
|
-
__publicField(this, "cachedRepositoryExpiration", 0);
|
|
127
149
|
this.fetchOptions = options.fetchOptions;
|
|
128
150
|
if (typeof options.fetch === "function") {
|
|
129
151
|
this.fetchFn = options.fetch;
|
|
@@ -168,41 +190,6 @@ class Client {
|
|
|
168
190
|
}
|
|
169
191
|
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
170
192
|
}
|
|
171
|
-
/**
|
|
172
|
-
* The Prismic repository's name.
|
|
173
|
-
*/
|
|
174
|
-
set repositoryName(value) {
|
|
175
|
-
__privateSet(this, _repositoryName, value);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* The Prismic repository's name.
|
|
179
|
-
*/
|
|
180
|
-
get repositoryName() {
|
|
181
|
-
if (!__privateGet(this, _repositoryName)) {
|
|
182
|
-
throw new PrismicError.PrismicError(`A repository name is required for this method but one could not be inferred from the provided API endpoint (\`${this.documentAPIEndpoint}\`). To fix this error, provide a repository name when creating the client. For more details, see ${devMsg.devMsg("prefer-repository-name")}`, void 0, void 0);
|
|
183
|
-
}
|
|
184
|
-
return __privateGet(this, _repositoryName);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
188
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
189
|
-
*
|
|
190
|
-
* @deprecated Use `documentAPIEndpoint` instead.
|
|
191
|
-
*/
|
|
192
|
-
// TODO: Remove in v8.
|
|
193
|
-
set endpoint(value) {
|
|
194
|
-
this.documentAPIEndpoint = value;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
198
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
199
|
-
*
|
|
200
|
-
* @deprecated Use `documentAPIEndpoint` instead.
|
|
201
|
-
*/
|
|
202
|
-
// TODO: Remove in v8.
|
|
203
|
-
get endpoint() {
|
|
204
|
-
return this.documentAPIEndpoint;
|
|
205
|
-
}
|
|
206
193
|
/**
|
|
207
194
|
* Enables the client to automatically query content from a preview session if
|
|
208
195
|
* one is active in browser environments. This is enabled by default in the
|
|
@@ -296,10 +283,9 @@ class Client {
|
|
|
296
283
|
* @returns The first result of the query, if any.
|
|
297
284
|
*/
|
|
298
285
|
async getFirst(params) {
|
|
299
|
-
var _a;
|
|
300
286
|
const actualParams = { ...params };
|
|
301
|
-
if (!(params && params.page) && !
|
|
302
|
-
actualParams.pageSize =
|
|
287
|
+
if (!(params && params.page) && !params?.pageSize) {
|
|
288
|
+
actualParams.pageSize = this.defaultParams?.pageSize ?? 1;
|
|
303
289
|
}
|
|
304
290
|
const { data, url } = await this._get(actualParams);
|
|
305
291
|
const firstResult = data.results[0];
|
|
@@ -332,11 +318,10 @@ class Client {
|
|
|
332
318
|
* @returns A list of documents matching the query.
|
|
333
319
|
*/
|
|
334
320
|
async dangerouslyGetAll(params = {}) {
|
|
335
|
-
var _a;
|
|
336
321
|
const { limit = Infinity, ...actualParams } = params;
|
|
337
322
|
const resolvedParams = {
|
|
338
323
|
...actualParams,
|
|
339
|
-
pageSize: Math.min(limit, actualParams.pageSize ||
|
|
324
|
+
pageSize: Math.min(limit, actualParams.pageSize || this.defaultParams?.pageSize || MAX_PAGE_SIZE)
|
|
340
325
|
};
|
|
341
326
|
const documents = [];
|
|
342
327
|
let latestResult;
|
|
@@ -753,7 +738,7 @@ class Client {
|
|
|
753
738
|
if (this.accessToken) {
|
|
754
739
|
url.searchParams.set("access_token", this.accessToken);
|
|
755
740
|
}
|
|
756
|
-
const response = await
|
|
741
|
+
const response = await this.#request(url, params);
|
|
757
742
|
switch (response.status) {
|
|
758
743
|
case 200: {
|
|
759
744
|
return await response.json();
|
|
@@ -860,7 +845,7 @@ class Client {
|
|
|
860
845
|
if (this.accessToken) {
|
|
861
846
|
url.searchParams.set("access_token", this.accessToken);
|
|
862
847
|
}
|
|
863
|
-
const response = await
|
|
848
|
+
const response = await this.#request(url, params);
|
|
864
849
|
if (response.ok) {
|
|
865
850
|
return await response.json();
|
|
866
851
|
}
|
|
@@ -908,7 +893,6 @@ class Client {
|
|
|
908
893
|
* session. The user should be redirected to this URL.
|
|
909
894
|
*/
|
|
910
895
|
async resolvePreviewURL(args) {
|
|
911
|
-
var _a, _b;
|
|
912
896
|
let documentID = args.documentID;
|
|
913
897
|
let previewToken = args.previewToken;
|
|
914
898
|
if (typeof globalThis.location !== "undefined") {
|
|
@@ -917,8 +901,8 @@ class Client {
|
|
|
917
901
|
previewToken = previewToken || searchParams.get("token");
|
|
918
902
|
} else if (this.refState.httpRequest) {
|
|
919
903
|
if ("query" in this.refState.httpRequest) {
|
|
920
|
-
documentID = documentID ||
|
|
921
|
-
previewToken = previewToken ||
|
|
904
|
+
documentID = documentID || this.refState.httpRequest.query?.documentId;
|
|
905
|
+
previewToken = previewToken || this.refState.httpRequest.query?.token;
|
|
922
906
|
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
923
907
|
const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
|
|
924
908
|
documentID = documentID || searchParams.get("documentId");
|
|
@@ -1135,17 +1119,16 @@ class Client {
|
|
|
1135
1119
|
* @returns The ref to use during a query.
|
|
1136
1120
|
*/
|
|
1137
1121
|
async getResolvedRefString(params) {
|
|
1138
|
-
var _a, _b;
|
|
1139
1122
|
if (this.refState.autoPreviewsEnabled) {
|
|
1140
1123
|
let previewRef;
|
|
1141
1124
|
let cookieJar;
|
|
1142
|
-
if (
|
|
1125
|
+
if (this.refState.httpRequest?.headers) {
|
|
1143
1126
|
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
1144
1127
|
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1145
1128
|
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
1146
1129
|
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1147
1130
|
}
|
|
1148
|
-
} else if (
|
|
1131
|
+
} else if (globalThis.document?.cookie) {
|
|
1149
1132
|
cookieJar = globalThis.document.cookie;
|
|
1150
1133
|
}
|
|
1151
1134
|
if (cookieJar) {
|
|
@@ -1186,10 +1169,9 @@ class Client {
|
|
|
1186
1169
|
* of the query and the URL used to make the API request.
|
|
1187
1170
|
*/
|
|
1188
1171
|
async _get(params, attemptCount = 0) {
|
|
1189
|
-
var _a, _b;
|
|
1190
1172
|
const url = await this.buildQueryURL(params);
|
|
1191
1173
|
try {
|
|
1192
|
-
const response = await
|
|
1174
|
+
const response = await this.#request(new URL(url), params);
|
|
1193
1175
|
switch (response.status) {
|
|
1194
1176
|
case 200: {
|
|
1195
1177
|
try {
|
|
@@ -1237,10 +1219,10 @@ class Client {
|
|
|
1237
1219
|
if (!(error instanceof RefNotFoundError.RefNotFoundError || error instanceof RefExpiredError.RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) {
|
|
1238
1220
|
throw error;
|
|
1239
1221
|
}
|
|
1240
|
-
if (!
|
|
1222
|
+
if (!params?.ref) {
|
|
1241
1223
|
this.cachedRepository = void 0;
|
|
1242
1224
|
}
|
|
1243
|
-
const masterRef =
|
|
1225
|
+
const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)?.groups?.ref;
|
|
1244
1226
|
if (!masterRef) {
|
|
1245
1227
|
throw error;
|
|
1246
1228
|
}
|
|
@@ -1250,24 +1232,30 @@ class Client {
|
|
|
1250
1232
|
return await this._get({ ...params, ref: masterRef }, attemptCount + 1);
|
|
1251
1233
|
}
|
|
1252
1234
|
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Makes an HTTP request using the client's configured fetch function and
|
|
1237
|
+
* options.
|
|
1238
|
+
*
|
|
1239
|
+
* @param url - The URL to request.
|
|
1240
|
+
* @param params - Fetch options.
|
|
1241
|
+
*
|
|
1242
|
+
* @returns The response from the fetch request.
|
|
1243
|
+
*/
|
|
1244
|
+
async #request(url, params) {
|
|
1245
|
+
return await request.request(url, this._buildRequestInit(params), this.fetchFn);
|
|
1246
|
+
}
|
|
1253
1247
|
_buildRequestInit(params) {
|
|
1254
|
-
var _a, _b, _c, _d;
|
|
1255
1248
|
return {
|
|
1256
1249
|
...this.fetchOptions,
|
|
1257
|
-
...params
|
|
1250
|
+
...params?.fetchOptions,
|
|
1258
1251
|
headers: {
|
|
1259
|
-
...
|
|
1260
|
-
...
|
|
1252
|
+
...this.fetchOptions?.headers,
|
|
1253
|
+
...params?.fetchOptions?.headers
|
|
1261
1254
|
},
|
|
1262
|
-
signal:
|
|
1255
|
+
signal: params?.fetchOptions?.signal || params?.signal || this.fetchOptions?.signal
|
|
1263
1256
|
};
|
|
1264
1257
|
}
|
|
1265
1258
|
}
|
|
1266
|
-
_repositoryName = new WeakMap();
|
|
1267
|
-
_Client_instances = new WeakSet();
|
|
1268
|
-
request_fn = async function(url, params) {
|
|
1269
|
-
return await request.request(url, this._buildRequestInit(params), this.fetchFn);
|
|
1270
|
-
};
|
|
1271
1259
|
exports.Client = Client;
|
|
1272
1260
|
exports.GET_ALL_QUERY_DELAY = GET_ALL_QUERY_DELAY;
|
|
1273
1261
|
exports.REPOSITORY_CACHE_TTL = REPOSITORY_CACHE_TTL;
|