@prismicio/client 7.21.0-alpha.1 → 7.21.0-pr.414.3336f00
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 +133 -136
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.ts +8 -8
- package/dist/Client.js +133 -136
- 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 +114 -99
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.ts +6 -6
- package/dist/WriteClient.js +114 -99
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs +4 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +29 -21
- package/dist/buildQueryURL.js +4 -1
- 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 +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +121 -120
- package/dist/index.js +2 -0
- 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.cjs.map +1 -1
- package/dist/types/model/types.d.ts +22 -23
- package/dist/types/model/types.js.map +1 -1
- 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 +2 -2
- 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 -3
- 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 +15 -25
- package/src/Client.ts +25 -8
- package/src/WriteClient.ts +22 -33
- package/src/buildQueryURL.ts +33 -22
- 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 +3 -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/src/types/model/types.ts +0 -2
- package/src/types/value/date.ts +1 -1
- package/src/types/value/timestamp.ts +1 -5
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;
|
|
@@ -750,10 +735,11 @@ class Client {
|
|
|
750
735
|
*/
|
|
751
736
|
async getRepository(params) {
|
|
752
737
|
const url = new URL(this.documentAPIEndpoint);
|
|
753
|
-
|
|
754
|
-
|
|
738
|
+
const accessToken = params?.accessToken || this.accessToken;
|
|
739
|
+
if (accessToken) {
|
|
740
|
+
url.searchParams.set("access_token", accessToken);
|
|
755
741
|
}
|
|
756
|
-
const response = await
|
|
742
|
+
const response = await this.#request(url, params);
|
|
757
743
|
switch (response.status) {
|
|
758
744
|
case 200: {
|
|
759
745
|
return await response.json();
|
|
@@ -860,7 +846,7 @@ class Client {
|
|
|
860
846
|
if (this.accessToken) {
|
|
861
847
|
url.searchParams.set("access_token", this.accessToken);
|
|
862
848
|
}
|
|
863
|
-
const response = await
|
|
849
|
+
const response = await this.#request(url, params);
|
|
864
850
|
if (response.ok) {
|
|
865
851
|
return await response.json();
|
|
866
852
|
}
|
|
@@ -876,8 +862,16 @@ class Client {
|
|
|
876
862
|
* @returns A URL string that can be requested to query content.
|
|
877
863
|
*/
|
|
878
864
|
async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
|
|
879
|
-
const ref = params.ref || await this.getResolvedRefString({
|
|
880
|
-
|
|
865
|
+
const ref = params.ref || await this.getResolvedRefString({
|
|
866
|
+
accessToken: params.accessToken,
|
|
867
|
+
signal,
|
|
868
|
+
fetchOptions
|
|
869
|
+
});
|
|
870
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({
|
|
871
|
+
accessToken: params.accessToken,
|
|
872
|
+
signal,
|
|
873
|
+
fetchOptions
|
|
874
|
+
})).integrationFieldsRef || void 0;
|
|
881
875
|
return buildQueryURL.buildQueryURL(this.documentAPIEndpoint, {
|
|
882
876
|
...this.defaultParams,
|
|
883
877
|
...params,
|
|
@@ -908,7 +902,6 @@ class Client {
|
|
|
908
902
|
* session. The user should be redirected to this URL.
|
|
909
903
|
*/
|
|
910
904
|
async resolvePreviewURL(args) {
|
|
911
|
-
var _a, _b;
|
|
912
905
|
let documentID = args.documentID;
|
|
913
906
|
let previewToken = args.previewToken;
|
|
914
907
|
if (typeof globalThis.location !== "undefined") {
|
|
@@ -917,8 +910,8 @@ class Client {
|
|
|
917
910
|
previewToken = previewToken || searchParams.get("token");
|
|
918
911
|
} else if (this.refState.httpRequest) {
|
|
919
912
|
if ("query" in this.refState.httpRequest) {
|
|
920
|
-
documentID = documentID ||
|
|
921
|
-
previewToken = previewToken ||
|
|
913
|
+
documentID = documentID || this.refState.httpRequest.query?.documentId;
|
|
914
|
+
previewToken = previewToken || this.refState.httpRequest.query?.token;
|
|
922
915
|
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
923
916
|
const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
|
|
924
917
|
documentID = documentID || searchParams.get("documentId");
|
|
@@ -1135,17 +1128,16 @@ class Client {
|
|
|
1135
1128
|
* @returns The ref to use during a query.
|
|
1136
1129
|
*/
|
|
1137
1130
|
async getResolvedRefString(params) {
|
|
1138
|
-
var _a, _b;
|
|
1139
1131
|
if (this.refState.autoPreviewsEnabled) {
|
|
1140
1132
|
let previewRef;
|
|
1141
1133
|
let cookieJar;
|
|
1142
|
-
if (
|
|
1134
|
+
if (this.refState.httpRequest?.headers) {
|
|
1143
1135
|
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
1144
1136
|
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1145
1137
|
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
1146
1138
|
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1147
1139
|
}
|
|
1148
|
-
} else if (
|
|
1140
|
+
} else if (globalThis.document?.cookie) {
|
|
1149
1141
|
cookieJar = globalThis.document.cookie;
|
|
1150
1142
|
}
|
|
1151
1143
|
if (cookieJar) {
|
|
@@ -1186,10 +1178,9 @@ class Client {
|
|
|
1186
1178
|
* of the query and the URL used to make the API request.
|
|
1187
1179
|
*/
|
|
1188
1180
|
async _get(params, attemptCount = 0) {
|
|
1189
|
-
var _a, _b;
|
|
1190
1181
|
const url = await this.buildQueryURL(params);
|
|
1191
1182
|
try {
|
|
1192
|
-
const response = await
|
|
1183
|
+
const response = await this.#request(new URL(url), params);
|
|
1193
1184
|
switch (response.status) {
|
|
1194
1185
|
case 200: {
|
|
1195
1186
|
try {
|
|
@@ -1237,10 +1228,10 @@ class Client {
|
|
|
1237
1228
|
if (!(error instanceof RefNotFoundError.RefNotFoundError || error instanceof RefExpiredError.RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) {
|
|
1238
1229
|
throw error;
|
|
1239
1230
|
}
|
|
1240
|
-
if (!
|
|
1231
|
+
if (!params?.ref) {
|
|
1241
1232
|
this.cachedRepository = void 0;
|
|
1242
1233
|
}
|
|
1243
|
-
const masterRef =
|
|
1234
|
+
const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)?.groups?.ref;
|
|
1244
1235
|
if (!masterRef) {
|
|
1245
1236
|
throw error;
|
|
1246
1237
|
}
|
|
@@ -1250,24 +1241,30 @@ class Client {
|
|
|
1250
1241
|
return await this._get({ ...params, ref: masterRef }, attemptCount + 1);
|
|
1251
1242
|
}
|
|
1252
1243
|
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Makes an HTTP request using the client's configured fetch function and
|
|
1246
|
+
* options.
|
|
1247
|
+
*
|
|
1248
|
+
* @param url - The URL to request.
|
|
1249
|
+
* @param params - Fetch options.
|
|
1250
|
+
*
|
|
1251
|
+
* @returns The response from the fetch request.
|
|
1252
|
+
*/
|
|
1253
|
+
async #request(url, params) {
|
|
1254
|
+
return await request.request(url, this._buildRequestInit(params), this.fetchFn);
|
|
1255
|
+
}
|
|
1253
1256
|
_buildRequestInit(params) {
|
|
1254
|
-
var _a, _b, _c, _d;
|
|
1255
1257
|
return {
|
|
1256
1258
|
...this.fetchOptions,
|
|
1257
|
-
...params
|
|
1259
|
+
...params?.fetchOptions,
|
|
1258
1260
|
headers: {
|
|
1259
|
-
...
|
|
1260
|
-
...
|
|
1261
|
+
...this.fetchOptions?.headers,
|
|
1262
|
+
...params?.fetchOptions?.headers
|
|
1261
1263
|
},
|
|
1262
|
-
signal:
|
|
1264
|
+
signal: params?.fetchOptions?.signal || params?.signal || this.fetchOptions?.signal
|
|
1263
1265
|
};
|
|
1264
1266
|
}
|
|
1265
1267
|
}
|
|
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
1268
|
exports.Client = Client;
|
|
1272
1269
|
exports.GET_ALL_QUERY_DELAY = GET_ALL_QUERY_DELAY;
|
|
1273
1270
|
exports.REPOSITORY_CACHE_TTL = REPOSITORY_CACHE_TTL;
|