@prismicio/client 7.21.0-alpha.1 → 7.21.0-pr.414.8f3ed35
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 +14 -21
- 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.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __typeError = (msg) => {
|
|
3
|
-
throw TypeError(msg);
|
|
4
|
-
};
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
8
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
|
-
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);
|
|
10
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
-
var _repositoryName, _Client_instances, request_fn;
|
|
13
1
|
import { appendFilters } from "./lib/appendFilters.js";
|
|
14
2
|
import { castThunk } from "./lib/castThunk.js";
|
|
15
3
|
import { devMsg } from "./lib/devMsg.js";
|
|
@@ -49,6 +37,98 @@ var RefStateMode;
|
|
|
49
37
|
RefStateMode2["Manual"] = "Manual";
|
|
50
38
|
})(RefStateMode || (RefStateMode = {}));
|
|
51
39
|
class Client {
|
|
40
|
+
/**
|
|
41
|
+
* The function used to make network requests to the Prismic REST API. In
|
|
42
|
+
* environments where a global `fetch` function does not exist, such as
|
|
43
|
+
* Node.js, this function must be provided.
|
|
44
|
+
*/
|
|
45
|
+
fetchFn;
|
|
46
|
+
fetchOptions;
|
|
47
|
+
#repositoryName;
|
|
48
|
+
/**
|
|
49
|
+
* The Prismic repository's name.
|
|
50
|
+
*/
|
|
51
|
+
set repositoryName(value) {
|
|
52
|
+
this.#repositoryName = value;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The Prismic repository's name.
|
|
56
|
+
*/
|
|
57
|
+
get repositoryName() {
|
|
58
|
+
if (!this.#repositoryName) {
|
|
59
|
+
throw new 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("prefer-repository-name")}`, void 0, void 0);
|
|
60
|
+
}
|
|
61
|
+
return this.#repositoryName;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The Prismic REST API V2 endpoint for the repository (use
|
|
65
|
+
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
66
|
+
*/
|
|
67
|
+
documentAPIEndpoint;
|
|
68
|
+
/**
|
|
69
|
+
* The Prismic REST API V2 endpoint for the repository (use
|
|
70
|
+
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
71
|
+
*
|
|
72
|
+
* @deprecated Use `documentAPIEndpoint` instead.
|
|
73
|
+
*/
|
|
74
|
+
// TODO: Remove in v8.
|
|
75
|
+
set endpoint(value) {
|
|
76
|
+
this.documentAPIEndpoint = value;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The Prismic REST API V2 endpoint for the repository (use
|
|
80
|
+
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
81
|
+
*
|
|
82
|
+
* @deprecated Use `documentAPIEndpoint` instead.
|
|
83
|
+
*/
|
|
84
|
+
// TODO: Remove in v8.
|
|
85
|
+
get endpoint() {
|
|
86
|
+
return this.documentAPIEndpoint;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The secure token for accessing the API (only needed if your repository is
|
|
90
|
+
* set to private).
|
|
91
|
+
*
|
|
92
|
+
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
|
|
93
|
+
*/
|
|
94
|
+
accessToken;
|
|
95
|
+
/**
|
|
96
|
+
* A list of route resolver objects that define how a document's `url` field
|
|
97
|
+
* is resolved.
|
|
98
|
+
*
|
|
99
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
100
|
+
*/
|
|
101
|
+
routes;
|
|
102
|
+
/**
|
|
103
|
+
* The `brokenRoute` option allows you to define the route populated in the
|
|
104
|
+
* `url` property for broken link or content relationship fields. A broken
|
|
105
|
+
* link is a link or content relationship field whose linked document has been
|
|
106
|
+
* unpublished or deleted.
|
|
107
|
+
*
|
|
108
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
109
|
+
*/
|
|
110
|
+
brokenRoute;
|
|
111
|
+
/**
|
|
112
|
+
* Default parameters that will be sent with each query. These parameters can
|
|
113
|
+
* be overridden on each query if needed.
|
|
114
|
+
*/
|
|
115
|
+
defaultParams;
|
|
116
|
+
/**
|
|
117
|
+
* The client's ref mode state. This determines which ref is used during
|
|
118
|
+
* queries.
|
|
119
|
+
*/
|
|
120
|
+
refState = {
|
|
121
|
+
mode: RefStateMode.Master,
|
|
122
|
+
autoPreviewsEnabled: true
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Cached repository value.
|
|
126
|
+
*/
|
|
127
|
+
cachedRepository;
|
|
128
|
+
/**
|
|
129
|
+
* Timestamp at which the cached repository data is considered stale.
|
|
130
|
+
*/
|
|
131
|
+
cachedRepositoryExpiration = 0;
|
|
52
132
|
/**
|
|
53
133
|
* Creates a Prismic client that can be used to query a repository.
|
|
54
134
|
*
|
|
@@ -64,64 +144,6 @@ class Client {
|
|
|
64
144
|
* @returns A client that can query content from the repository.
|
|
65
145
|
*/
|
|
66
146
|
constructor(repositoryNameOrEndpoint, options = {}) {
|
|
67
|
-
__privateAdd(this, _Client_instances);
|
|
68
|
-
/**
|
|
69
|
-
* The function used to make network requests to the Prismic REST API. In
|
|
70
|
-
* environments where a global `fetch` function does not exist, such as
|
|
71
|
-
* Node.js, this function must be provided.
|
|
72
|
-
*/
|
|
73
|
-
__publicField(this, "fetchFn");
|
|
74
|
-
__publicField(this, "fetchOptions");
|
|
75
|
-
__privateAdd(this, _repositoryName);
|
|
76
|
-
/**
|
|
77
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
78
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
79
|
-
*/
|
|
80
|
-
__publicField(this, "documentAPIEndpoint");
|
|
81
|
-
/**
|
|
82
|
-
* The secure token for accessing the API (only needed if your repository is
|
|
83
|
-
* set to private).
|
|
84
|
-
*
|
|
85
|
-
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
|
|
86
|
-
*/
|
|
87
|
-
__publicField(this, "accessToken");
|
|
88
|
-
/**
|
|
89
|
-
* A list of route resolver objects that define how a document's `url` field
|
|
90
|
-
* is resolved.
|
|
91
|
-
*
|
|
92
|
-
* {@link https://prismic.io/docs/route-resolver}
|
|
93
|
-
*/
|
|
94
|
-
__publicField(this, "routes");
|
|
95
|
-
/**
|
|
96
|
-
* The `brokenRoute` option allows you to define the route populated in the
|
|
97
|
-
* `url` property for broken link or content relationship fields. A broken
|
|
98
|
-
* link is a link or content relationship field whose linked document has been
|
|
99
|
-
* unpublished or deleted.
|
|
100
|
-
*
|
|
101
|
-
* {@link https://prismic.io/docs/route-resolver}
|
|
102
|
-
*/
|
|
103
|
-
__publicField(this, "brokenRoute");
|
|
104
|
-
/**
|
|
105
|
-
* Default parameters that will be sent with each query. These parameters can
|
|
106
|
-
* be overridden on each query if needed.
|
|
107
|
-
*/
|
|
108
|
-
__publicField(this, "defaultParams");
|
|
109
|
-
/**
|
|
110
|
-
* The client's ref mode state. This determines which ref is used during
|
|
111
|
-
* queries.
|
|
112
|
-
*/
|
|
113
|
-
__publicField(this, "refState", {
|
|
114
|
-
mode: RefStateMode.Master,
|
|
115
|
-
autoPreviewsEnabled: true
|
|
116
|
-
});
|
|
117
|
-
/**
|
|
118
|
-
* Cached repository value.
|
|
119
|
-
*/
|
|
120
|
-
__publicField(this, "cachedRepository");
|
|
121
|
-
/**
|
|
122
|
-
* Timestamp at which the cached repository data is considered stale.
|
|
123
|
-
*/
|
|
124
|
-
__publicField(this, "cachedRepositoryExpiration", 0);
|
|
125
147
|
this.fetchOptions = options.fetchOptions;
|
|
126
148
|
if (typeof options.fetch === "function") {
|
|
127
149
|
this.fetchFn = options.fetch;
|
|
@@ -166,41 +188,6 @@ class Client {
|
|
|
166
188
|
}
|
|
167
189
|
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
168
190
|
}
|
|
169
|
-
/**
|
|
170
|
-
* The Prismic repository's name.
|
|
171
|
-
*/
|
|
172
|
-
set repositoryName(value) {
|
|
173
|
-
__privateSet(this, _repositoryName, value);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* The Prismic repository's name.
|
|
177
|
-
*/
|
|
178
|
-
get repositoryName() {
|
|
179
|
-
if (!__privateGet(this, _repositoryName)) {
|
|
180
|
-
throw new 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("prefer-repository-name")}`, void 0, void 0);
|
|
181
|
-
}
|
|
182
|
-
return __privateGet(this, _repositoryName);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
186
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
187
|
-
*
|
|
188
|
-
* @deprecated Use `documentAPIEndpoint` instead.
|
|
189
|
-
*/
|
|
190
|
-
// TODO: Remove in v8.
|
|
191
|
-
set endpoint(value) {
|
|
192
|
-
this.documentAPIEndpoint = value;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
196
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
197
|
-
*
|
|
198
|
-
* @deprecated Use `documentAPIEndpoint` instead.
|
|
199
|
-
*/
|
|
200
|
-
// TODO: Remove in v8.
|
|
201
|
-
get endpoint() {
|
|
202
|
-
return this.documentAPIEndpoint;
|
|
203
|
-
}
|
|
204
191
|
/**
|
|
205
192
|
* Enables the client to automatically query content from a preview session if
|
|
206
193
|
* one is active in browser environments. This is enabled by default in the
|
|
@@ -294,10 +281,9 @@ class Client {
|
|
|
294
281
|
* @returns The first result of the query, if any.
|
|
295
282
|
*/
|
|
296
283
|
async getFirst(params) {
|
|
297
|
-
var _a;
|
|
298
284
|
const actualParams = { ...params };
|
|
299
|
-
if (!(params && params.page) && !
|
|
300
|
-
actualParams.pageSize =
|
|
285
|
+
if (!(params && params.page) && !params?.pageSize) {
|
|
286
|
+
actualParams.pageSize = this.defaultParams?.pageSize ?? 1;
|
|
301
287
|
}
|
|
302
288
|
const { data, url } = await this._get(actualParams);
|
|
303
289
|
const firstResult = data.results[0];
|
|
@@ -330,11 +316,10 @@ class Client {
|
|
|
330
316
|
* @returns A list of documents matching the query.
|
|
331
317
|
*/
|
|
332
318
|
async dangerouslyGetAll(params = {}) {
|
|
333
|
-
var _a;
|
|
334
319
|
const { limit = Infinity, ...actualParams } = params;
|
|
335
320
|
const resolvedParams = {
|
|
336
321
|
...actualParams,
|
|
337
|
-
pageSize: Math.min(limit, actualParams.pageSize ||
|
|
322
|
+
pageSize: Math.min(limit, actualParams.pageSize || this.defaultParams?.pageSize || MAX_PAGE_SIZE)
|
|
338
323
|
};
|
|
339
324
|
const documents = [];
|
|
340
325
|
let latestResult;
|
|
@@ -748,10 +733,11 @@ class Client {
|
|
|
748
733
|
*/
|
|
749
734
|
async getRepository(params) {
|
|
750
735
|
const url = new URL(this.documentAPIEndpoint);
|
|
751
|
-
|
|
752
|
-
|
|
736
|
+
const accessToken = params?.accessToken || this.accessToken;
|
|
737
|
+
if (accessToken) {
|
|
738
|
+
url.searchParams.set("access_token", accessToken);
|
|
753
739
|
}
|
|
754
|
-
const response = await
|
|
740
|
+
const response = await this.#request(url, params);
|
|
755
741
|
switch (response.status) {
|
|
756
742
|
case 200: {
|
|
757
743
|
return await response.json();
|
|
@@ -858,7 +844,7 @@ class Client {
|
|
|
858
844
|
if (this.accessToken) {
|
|
859
845
|
url.searchParams.set("access_token", this.accessToken);
|
|
860
846
|
}
|
|
861
|
-
const response = await
|
|
847
|
+
const response = await this.#request(url, params);
|
|
862
848
|
if (response.ok) {
|
|
863
849
|
return await response.json();
|
|
864
850
|
}
|
|
@@ -874,8 +860,16 @@ class Client {
|
|
|
874
860
|
* @returns A URL string that can be requested to query content.
|
|
875
861
|
*/
|
|
876
862
|
async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
|
|
877
|
-
const ref = params.ref || await this.getResolvedRefString({
|
|
878
|
-
|
|
863
|
+
const ref = params.ref || await this.getResolvedRefString({
|
|
864
|
+
accessToken: params.accessToken,
|
|
865
|
+
signal,
|
|
866
|
+
fetchOptions
|
|
867
|
+
});
|
|
868
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({
|
|
869
|
+
accessToken: params.accessToken,
|
|
870
|
+
signal,
|
|
871
|
+
fetchOptions
|
|
872
|
+
})).integrationFieldsRef || void 0;
|
|
879
873
|
return buildQueryURL(this.documentAPIEndpoint, {
|
|
880
874
|
...this.defaultParams,
|
|
881
875
|
...params,
|
|
@@ -906,7 +900,6 @@ class Client {
|
|
|
906
900
|
* session. The user should be redirected to this URL.
|
|
907
901
|
*/
|
|
908
902
|
async resolvePreviewURL(args) {
|
|
909
|
-
var _a, _b;
|
|
910
903
|
let documentID = args.documentID;
|
|
911
904
|
let previewToken = args.previewToken;
|
|
912
905
|
if (typeof globalThis.location !== "undefined") {
|
|
@@ -915,8 +908,8 @@ class Client {
|
|
|
915
908
|
previewToken = previewToken || searchParams.get("token");
|
|
916
909
|
} else if (this.refState.httpRequest) {
|
|
917
910
|
if ("query" in this.refState.httpRequest) {
|
|
918
|
-
documentID = documentID ||
|
|
919
|
-
previewToken = previewToken ||
|
|
911
|
+
documentID = documentID || this.refState.httpRequest.query?.documentId;
|
|
912
|
+
previewToken = previewToken || this.refState.httpRequest.query?.token;
|
|
920
913
|
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
921
914
|
const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
|
|
922
915
|
documentID = documentID || searchParams.get("documentId");
|
|
@@ -1133,17 +1126,16 @@ class Client {
|
|
|
1133
1126
|
* @returns The ref to use during a query.
|
|
1134
1127
|
*/
|
|
1135
1128
|
async getResolvedRefString(params) {
|
|
1136
|
-
var _a, _b;
|
|
1137
1129
|
if (this.refState.autoPreviewsEnabled) {
|
|
1138
1130
|
let previewRef;
|
|
1139
1131
|
let cookieJar;
|
|
1140
|
-
if (
|
|
1132
|
+
if (this.refState.httpRequest?.headers) {
|
|
1141
1133
|
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
1142
1134
|
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1143
1135
|
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
1144
1136
|
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1145
1137
|
}
|
|
1146
|
-
} else if (
|
|
1138
|
+
} else if (globalThis.document?.cookie) {
|
|
1147
1139
|
cookieJar = globalThis.document.cookie;
|
|
1148
1140
|
}
|
|
1149
1141
|
if (cookieJar) {
|
|
@@ -1184,10 +1176,9 @@ class Client {
|
|
|
1184
1176
|
* of the query and the URL used to make the API request.
|
|
1185
1177
|
*/
|
|
1186
1178
|
async _get(params, attemptCount = 0) {
|
|
1187
|
-
var _a, _b;
|
|
1188
1179
|
const url = await this.buildQueryURL(params);
|
|
1189
1180
|
try {
|
|
1190
|
-
const response = await
|
|
1181
|
+
const response = await this.#request(new URL(url), params);
|
|
1191
1182
|
switch (response.status) {
|
|
1192
1183
|
case 200: {
|
|
1193
1184
|
try {
|
|
@@ -1235,10 +1226,10 @@ class Client {
|
|
|
1235
1226
|
if (!(error instanceof RefNotFoundError || error instanceof RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) {
|
|
1236
1227
|
throw error;
|
|
1237
1228
|
}
|
|
1238
|
-
if (!
|
|
1229
|
+
if (!params?.ref) {
|
|
1239
1230
|
this.cachedRepository = void 0;
|
|
1240
1231
|
}
|
|
1241
|
-
const masterRef =
|
|
1232
|
+
const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)?.groups?.ref;
|
|
1242
1233
|
if (!masterRef) {
|
|
1243
1234
|
throw error;
|
|
1244
1235
|
}
|
|
@@ -1248,24 +1239,30 @@ class Client {
|
|
|
1248
1239
|
return await this._get({ ...params, ref: masterRef }, attemptCount + 1);
|
|
1249
1240
|
}
|
|
1250
1241
|
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Makes an HTTP request using the client's configured fetch function and
|
|
1244
|
+
* options.
|
|
1245
|
+
*
|
|
1246
|
+
* @param url - The URL to request.
|
|
1247
|
+
* @param params - Fetch options.
|
|
1248
|
+
*
|
|
1249
|
+
* @returns The response from the fetch request.
|
|
1250
|
+
*/
|
|
1251
|
+
async #request(url, params) {
|
|
1252
|
+
return await request(url, this._buildRequestInit(params), this.fetchFn);
|
|
1253
|
+
}
|
|
1251
1254
|
_buildRequestInit(params) {
|
|
1252
|
-
var _a, _b, _c, _d;
|
|
1253
1255
|
return {
|
|
1254
1256
|
...this.fetchOptions,
|
|
1255
|
-
...params
|
|
1257
|
+
...params?.fetchOptions,
|
|
1256
1258
|
headers: {
|
|
1257
|
-
...
|
|
1258
|
-
...
|
|
1259
|
+
...this.fetchOptions?.headers,
|
|
1260
|
+
...params?.fetchOptions?.headers
|
|
1259
1261
|
},
|
|
1260
|
-
signal:
|
|
1262
|
+
signal: params?.fetchOptions?.signal || params?.signal || this.fetchOptions?.signal
|
|
1261
1263
|
};
|
|
1262
1264
|
}
|
|
1263
1265
|
}
|
|
1264
|
-
_repositoryName = new WeakMap();
|
|
1265
|
-
_Client_instances = new WeakSet();
|
|
1266
|
-
request_fn = async function(url, params) {
|
|
1267
|
-
return await request(url, this._buildRequestInit(params), this.fetchFn);
|
|
1268
|
-
};
|
|
1269
1266
|
export {
|
|
1270
1267
|
Client,
|
|
1271
1268
|
GET_ALL_QUERY_DELAY,
|