@prismicio/client 7.21.0-pr.421.a498326 → 7.21.0-pr.422.63e7930
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 +218 -330
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.cts +101 -194
- package/dist/Client.d.cts.map +1 -1
- package/dist/Client.d.ts +101 -194
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +213 -325
- package/dist/Client.js.map +1 -1
- package/dist/WriteClient.cjs +19 -19
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.cts.map +1 -1
- package/dist/WriteClient.d.ts.map +1 -1
- package/dist/WriteClient.js +9 -9
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs +9 -9
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.cts +4 -12
- package/dist/buildQueryURL.d.cts.map +1 -1
- package/dist/buildQueryURL.d.ts +4 -12
- package/dist/buildQueryURL.d.ts.map +1 -1
- package/dist/buildQueryURL.js +4 -4
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/errors.cjs +31 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +46 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.ts +46 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +22 -0
- package/dist/errors.js.map +1 -0
- package/dist/getGraphQLEndpoint.cjs +2 -2
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs +2 -2
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.js +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs +2 -2
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs +2 -2
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/index.cjs +10 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -9
- package/dist/index.js.map +1 -1
- package/dist/lib/{throttledLog.js → throttledWarn.cjs} +7 -7
- package/dist/lib/throttledWarn.cjs.map +1 -0
- package/dist/lib/{throttledLog.cjs → throttledWarn.js} +6 -8
- package/dist/lib/throttledWarn.js.map +1 -0
- package/dist/lib/validateAssetMetadata.cjs +2 -2
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.js +1 -1
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +1 -1
- package/src/Client.ts +421 -604
- package/src/WriteClient.ts +16 -10
- package/src/buildQueryURL.ts +10 -19
- package/src/errors.ts +94 -0
- package/src/getGraphQLEndpoint.ts +1 -1
- package/src/getRepositoryEndpoint.ts +1 -1
- package/src/getRepositoryName.ts +1 -1
- package/src/getToolbarSrc.ts +1 -1
- package/src/index.ts +11 -9
- package/src/lib/{throttledLog.ts → throttledWarn.ts} +3 -13
- package/src/lib/validateAssetMetadata.ts +1 -1
- package/dist/errors/ForbiddenError.cjs +0 -8
- package/dist/errors/ForbiddenError.cjs.map +0 -1
- package/dist/errors/ForbiddenError.d.cts +0 -14
- package/dist/errors/ForbiddenError.d.cts.map +0 -1
- package/dist/errors/ForbiddenError.d.ts +0 -14
- package/dist/errors/ForbiddenError.d.ts.map +0 -1
- package/dist/errors/ForbiddenError.js +0 -8
- package/dist/errors/ForbiddenError.js.map +0 -1
- package/dist/errors/InvalidDataError.cjs +0 -8
- package/dist/errors/InvalidDataError.cjs.map +0 -1
- package/dist/errors/InvalidDataError.d.cts +0 -7
- package/dist/errors/InvalidDataError.d.cts.map +0 -1
- package/dist/errors/InvalidDataError.d.ts +0 -7
- package/dist/errors/InvalidDataError.d.ts.map +0 -1
- package/dist/errors/InvalidDataError.js +0 -8
- package/dist/errors/InvalidDataError.js.map +0 -1
- package/dist/errors/NotFoundError.cjs +0 -8
- package/dist/errors/NotFoundError.cjs.map +0 -1
- package/dist/errors/NotFoundError.d.cts +0 -7
- package/dist/errors/NotFoundError.d.cts.map +0 -1
- package/dist/errors/NotFoundError.d.ts +0 -7
- package/dist/errors/NotFoundError.d.ts.map +0 -1
- package/dist/errors/NotFoundError.js +0 -8
- package/dist/errors/NotFoundError.js.map +0 -1
- package/dist/errors/ParsingError.cjs +0 -8
- package/dist/errors/ParsingError.cjs.map +0 -1
- package/dist/errors/ParsingError.d.cts +0 -17
- package/dist/errors/ParsingError.d.cts.map +0 -1
- package/dist/errors/ParsingError.d.ts +0 -17
- package/dist/errors/ParsingError.d.ts.map +0 -1
- package/dist/errors/ParsingError.js +0 -8
- package/dist/errors/ParsingError.js.map +0 -1
- package/dist/errors/PreviewTokenExpired.cjs +0 -8
- package/dist/errors/PreviewTokenExpired.cjs.map +0 -1
- package/dist/errors/PreviewTokenExpired.d.cts +0 -11
- package/dist/errors/PreviewTokenExpired.d.cts.map +0 -1
- package/dist/errors/PreviewTokenExpired.d.ts +0 -11
- package/dist/errors/PreviewTokenExpired.d.ts.map +0 -1
- package/dist/errors/PreviewTokenExpired.js +0 -8
- package/dist/errors/PreviewTokenExpired.js.map +0 -1
- package/dist/errors/PrismicError.cjs +0 -15
- package/dist/errors/PrismicError.cjs.map +0 -1
- package/dist/errors/PrismicError.d.cts +0 -9
- package/dist/errors/PrismicError.d.cts.map +0 -1
- package/dist/errors/PrismicError.d.ts +0 -9
- package/dist/errors/PrismicError.d.ts.map +0 -1
- package/dist/errors/PrismicError.js +0 -14
- package/dist/errors/PrismicError.js.map +0 -1
- package/dist/errors/RefExpiredError.cjs +0 -8
- package/dist/errors/RefExpiredError.cjs.map +0 -1
- package/dist/errors/RefExpiredError.d.cts +0 -11
- package/dist/errors/RefExpiredError.d.cts.map +0 -1
- package/dist/errors/RefExpiredError.d.ts +0 -11
- package/dist/errors/RefExpiredError.d.ts.map +0 -1
- package/dist/errors/RefExpiredError.js +0 -8
- package/dist/errors/RefExpiredError.js.map +0 -1
- package/dist/errors/RefNotFoundError.cjs +0 -8
- package/dist/errors/RefNotFoundError.cjs.map +0 -1
- package/dist/errors/RefNotFoundError.d.cts +0 -11
- package/dist/errors/RefNotFoundError.d.cts.map +0 -1
- package/dist/errors/RefNotFoundError.d.ts +0 -11
- package/dist/errors/RefNotFoundError.d.ts.map +0 -1
- package/dist/errors/RefNotFoundError.js +0 -8
- package/dist/errors/RefNotFoundError.js.map +0 -1
- package/dist/errors/RepositoryNotFoundError.cjs +0 -8
- package/dist/errors/RepositoryNotFoundError.cjs.map +0 -1
- package/dist/errors/RepositoryNotFoundError.d.cts +0 -7
- package/dist/errors/RepositoryNotFoundError.d.cts.map +0 -1
- package/dist/errors/RepositoryNotFoundError.d.ts +0 -7
- package/dist/errors/RepositoryNotFoundError.d.ts.map +0 -1
- package/dist/errors/RepositoryNotFoundError.js +0 -8
- package/dist/errors/RepositoryNotFoundError.js.map +0 -1
- package/dist/lib/appendFilters.cjs +0 -24
- package/dist/lib/appendFilters.cjs.map +0 -1
- package/dist/lib/appendFilters.js +0 -24
- package/dist/lib/appendFilters.js.map +0 -1
- package/dist/lib/castArray.cjs +0 -20
- package/dist/lib/castArray.cjs.map +0 -1
- package/dist/lib/castArray.js +0 -19
- package/dist/lib/castArray.js.map +0 -1
- package/dist/lib/castThunk.cjs +0 -19
- package/dist/lib/castThunk.cjs.map +0 -1
- package/dist/lib/castThunk.js +0 -18
- package/dist/lib/castThunk.js.map +0 -1
- package/dist/lib/everyTagFilter.cjs +0 -19
- package/dist/lib/everyTagFilter.cjs.map +0 -1
- package/dist/lib/everyTagFilter.js +0 -19
- package/dist/lib/everyTagFilter.js.map +0 -1
- package/dist/lib/findMasterRef.cjs +0 -19
- package/dist/lib/findMasterRef.cjs.map +0 -1
- package/dist/lib/findMasterRef.js +0 -19
- package/dist/lib/findMasterRef.js.map +0 -1
- package/dist/lib/findRef.cjs +0 -24
- package/dist/lib/findRef.cjs.map +0 -1
- package/dist/lib/findRef.js +0 -24
- package/dist/lib/findRef.js.map +0 -1
- package/dist/lib/findRefByID.cjs +0 -20
- package/dist/lib/findRefByID.cjs.map +0 -1
- package/dist/lib/findRefByID.js +0 -20
- package/dist/lib/findRefByID.js.map +0 -1
- package/dist/lib/findRefByLabel.cjs +0 -20
- package/dist/lib/findRefByLabel.cjs.map +0 -1
- package/dist/lib/findRefByLabel.js +0 -20
- package/dist/lib/findRefByLabel.js.map +0 -1
- package/dist/lib/minifyGraphQLQuery.cjs +0 -16
- package/dist/lib/minifyGraphQLQuery.cjs.map +0 -1
- package/dist/lib/minifyGraphQLQuery.js +0 -15
- package/dist/lib/minifyGraphQLQuery.js.map +0 -1
- package/dist/lib/someTagsFilter.cjs +0 -19
- package/dist/lib/someTagsFilter.cjs.map +0 -1
- package/dist/lib/someTagsFilter.js +0 -19
- package/dist/lib/someTagsFilter.js.map +0 -1
- package/dist/lib/throttledLog.cjs.map +0 -1
- package/dist/lib/throttledLog.js.map +0 -1
- package/dist/lib/typeFilter.cjs +0 -17
- package/dist/lib/typeFilter.cjs.map +0 -1
- package/dist/lib/typeFilter.js +0 -17
- package/dist/lib/typeFilter.js.map +0 -1
- package/src/errors/ForbiddenError.ts +0 -16
- package/src/errors/InvalidDataError.ts +0 -5
- package/src/errors/NotFoundError.ts +0 -5
- package/src/errors/ParsingError.ts +0 -16
- package/src/errors/PreviewTokenExpired.ts +0 -12
- package/src/errors/PrismicError.ts +0 -15
- package/src/errors/RefExpiredError.ts +0 -14
- package/src/errors/RefNotFoundError.ts +0 -14
- package/src/errors/RepositoryNotFoundError.ts +0 -5
- package/src/lib/appendFilters.ts +0 -26
- package/src/lib/castArray.ts +0 -14
- package/src/lib/castThunk.ts +0 -13
- package/src/lib/everyTagFilter.ts +0 -15
- package/src/lib/findMasterRef.ts +0 -16
- package/src/lib/findRef.ts +0 -25
- package/src/lib/findRefByID.ts +0 -17
- package/src/lib/findRefByLabel.ts +0 -17
- package/src/lib/minifyGraphQLQuery.ts +0 -13
- package/src/lib/someTagsFilter.ts +0 -15
- package/src/lib/typeFilter.ts +0 -12
package/dist/Client.cjs
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
const require_filter = require('./filter.cjs');
|
|
2
|
-
const require_appendFilters = require('./lib/appendFilters.cjs');
|
|
3
|
-
const require_castThunk = require('./lib/castThunk.cjs');
|
|
4
2
|
const require_devMsg = require('./lib/devMsg.cjs');
|
|
5
|
-
const require_everyTagFilter = require('./lib/everyTagFilter.cjs');
|
|
6
|
-
const require_PrismicError = require('./errors/PrismicError.cjs');
|
|
7
|
-
const require_findMasterRef = require('./lib/findMasterRef.cjs');
|
|
8
|
-
const require_findRefByID = require('./lib/findRefByID.cjs');
|
|
9
|
-
const require_findRefByLabel = require('./lib/findRefByLabel.cjs');
|
|
10
3
|
const require_getPreviewCookie = require('./lib/getPreviewCookie.cjs');
|
|
11
|
-
const require_minifyGraphQLQuery = require('./lib/minifyGraphQLQuery.cjs');
|
|
12
4
|
const require_request = require('./lib/request.cjs');
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const require_typeFilter = require('./lib/typeFilter.cjs');
|
|
16
|
-
const require_ForbiddenError = require('./errors/ForbiddenError.cjs');
|
|
17
|
-
const require_NotFoundError = require('./errors/NotFoundError.cjs');
|
|
18
|
-
const require_ParsingError = require('./errors/ParsingError.cjs');
|
|
19
|
-
const require_PreviewTokenExpired = require('./errors/PreviewTokenExpired.cjs');
|
|
20
|
-
const require_RefExpiredError = require('./errors/RefExpiredError.cjs');
|
|
21
|
-
const require_RefNotFoundError = require('./errors/RefNotFoundError.cjs');
|
|
22
|
-
const require_RepositoryNotFoundError = require('./errors/RepositoryNotFoundError.cjs');
|
|
5
|
+
const require_throttledWarn = require('./lib/throttledWarn.cjs');
|
|
6
|
+
const require_errors = require('./errors.cjs');
|
|
23
7
|
const require_asLink = require('./helpers/asLink.cjs');
|
|
24
8
|
const require_buildQueryURL = require('./buildQueryURL.cjs');
|
|
25
9
|
const require_getRepositoryEndpoint = require('./getRepositoryEndpoint.cjs');
|
|
@@ -27,173 +11,90 @@ const require_getRepositoryName = require('./getRepositoryName.cjs');
|
|
|
27
11
|
const require_isRepositoryEndpoint = require('./isRepositoryEndpoint.cjs');
|
|
28
12
|
|
|
29
13
|
//#region src/Client.ts
|
|
30
|
-
/**
|
|
31
|
-
* The largest page size allowed by the Prismic REST API V2. This value is used
|
|
32
|
-
* to minimize the number of requests required to query content.
|
|
33
|
-
*/
|
|
34
14
|
const MAX_PAGE_SIZE = 100;
|
|
35
|
-
/**
|
|
36
|
-
* The number of milliseconds in which repository metadata is considered valid.
|
|
37
|
-
* A ref can be invalidated quickly depending on how frequently content is
|
|
38
|
-
* updated in the Prismic repository. As such, repository's metadata can only be
|
|
39
|
-
* considered valid for a short amount of time.
|
|
40
|
-
*/
|
|
41
15
|
const REPOSITORY_CACHE_TTL = 5e3;
|
|
42
|
-
/**
|
|
43
|
-
* The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,
|
|
44
|
-
* `getAllByType`, `getAllByTag`) will wait between individual page requests.
|
|
45
|
-
*
|
|
46
|
-
* This is done to ensure API performance is sustainable and reduces the chance
|
|
47
|
-
* of a failed API request due to overloading.
|
|
48
|
-
*/
|
|
49
16
|
const GET_ALL_QUERY_DELAY = 500;
|
|
50
|
-
/**
|
|
51
|
-
* The maximum number of attempts to retry a query with an invalid ref. We allow
|
|
52
|
-
* multiple attempts since each attempt may use a different (and possibly
|
|
53
|
-
* invalid) ref. Capping the number of attempts prevents infinite loops.
|
|
54
|
-
*/
|
|
55
17
|
const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
|
|
56
18
|
/**
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
var RefStateMode = /* @__PURE__ */ function(RefStateMode$1) {
|
|
60
|
-
/**
|
|
61
|
-
* Use the repository's master ref.
|
|
62
|
-
*/
|
|
63
|
-
RefStateMode$1["Master"] = "Master";
|
|
64
|
-
/**
|
|
65
|
-
* Use a given Release identified by its ID.
|
|
66
|
-
*/
|
|
67
|
-
RefStateMode$1["ReleaseID"] = "ReleaseID";
|
|
68
|
-
/**
|
|
69
|
-
* Use a given Release identified by its label.
|
|
70
|
-
*/
|
|
71
|
-
RefStateMode$1["ReleaseLabel"] = "ReleaseLabel";
|
|
72
|
-
/**
|
|
73
|
-
* Use a given ref.
|
|
74
|
-
*/
|
|
75
|
-
RefStateMode$1["Manual"] = "Manual";
|
|
76
|
-
return RefStateMode$1;
|
|
77
|
-
}(RefStateMode || {});
|
|
78
|
-
/**
|
|
79
|
-
* A client that allows querying content from a Prismic repository.
|
|
80
|
-
*
|
|
81
|
-
* If used in an environment where a global `fetch` function is unavailable,
|
|
82
|
-
* such as Node.js, the `fetch` option must be provided as part of the `options`
|
|
83
|
-
* parameter.
|
|
19
|
+
* A client for fetching content from a Prismic repository.
|
|
84
20
|
*
|
|
85
|
-
* @
|
|
86
|
-
*
|
|
21
|
+
* @see {@link https://prismic.io/docs/fetch-content}
|
|
22
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
87
23
|
*/
|
|
88
24
|
var Client = class {
|
|
89
25
|
/**
|
|
90
|
-
* The
|
|
91
|
-
* environments where a global `fetch` function does not exist, such as
|
|
92
|
-
* Node.js, this function must be provided.
|
|
93
|
-
*/
|
|
94
|
-
fetchFn;
|
|
95
|
-
fetchOptions;
|
|
96
|
-
#repositoryName;
|
|
97
|
-
/**
|
|
98
|
-
* The Prismic repository's name.
|
|
99
|
-
*/
|
|
100
|
-
set repositoryName(value) {
|
|
101
|
-
this.#repositoryName = value;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* The Prismic repository's name.
|
|
105
|
-
*/
|
|
106
|
-
get repositoryName() {
|
|
107
|
-
if (!this.#repositoryName) throw new require_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 ${require_devMsg.devMsg("prefer-repository-name")}`, void 0, void 0);
|
|
108
|
-
return this.#repositoryName;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
112
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
113
|
-
*/
|
|
114
|
-
documentAPIEndpoint;
|
|
115
|
-
/**
|
|
116
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
117
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
26
|
+
* The client's Content API endpoint.
|
|
118
27
|
*
|
|
119
|
-
* @
|
|
28
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
|
|
120
29
|
*/
|
|
121
|
-
|
|
122
|
-
this.documentAPIEndpoint = value;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* The Prismic REST API V2 endpoint for the repository (use
|
|
126
|
-
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
127
|
-
*
|
|
128
|
-
* @deprecated Use `documentAPIEndpoint` instead.
|
|
129
|
-
*/
|
|
130
|
-
get endpoint() {
|
|
131
|
-
return this.documentAPIEndpoint;
|
|
132
|
-
}
|
|
30
|
+
documentAPIEndpoint;
|
|
133
31
|
/**
|
|
134
|
-
* The secure token for
|
|
135
|
-
* set to private).
|
|
32
|
+
* The secure token used for the Content API.
|
|
136
33
|
*
|
|
137
|
-
* {@link https://
|
|
34
|
+
* @see {@link https://prismic.io/docs/fetch-content#content-visibility}
|
|
138
35
|
*/
|
|
139
36
|
accessToken;
|
|
140
37
|
/**
|
|
141
|
-
* A list of route resolver objects that define how a document's `url`
|
|
142
|
-
* is resolved.
|
|
38
|
+
* A list of route resolver objects that define how a document's `url`
|
|
39
|
+
* property is resolved.
|
|
143
40
|
*
|
|
144
|
-
* {@link https://prismic.io/docs/
|
|
41
|
+
* @see {@link https://prismic.io/docs/routes}
|
|
42
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
|
|
145
43
|
*/
|
|
146
44
|
routes;
|
|
147
45
|
/**
|
|
148
|
-
* The
|
|
149
|
-
*
|
|
150
|
-
* link is a link or content relationship field whose linked document has been
|
|
151
|
-
* unpublished or deleted.
|
|
46
|
+
* The URL used for link or content relationship fields that point to an
|
|
47
|
+
* archived or deleted page.
|
|
152
48
|
*
|
|
153
|
-
* {@link https://prismic.io/docs/
|
|
49
|
+
* @see {@link https://prismic.io/docs/routes}
|
|
50
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
|
|
154
51
|
*/
|
|
155
52
|
brokenRoute;
|
|
156
53
|
/**
|
|
157
|
-
* Default parameters
|
|
158
|
-
* be overridden on each
|
|
54
|
+
* Default parameters sent with each Content API request. These parameters can
|
|
55
|
+
* be overridden on each method.
|
|
56
|
+
*
|
|
57
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
|
|
159
58
|
*/
|
|
160
59
|
defaultParams;
|
|
161
60
|
/**
|
|
162
|
-
* The
|
|
163
|
-
*
|
|
61
|
+
* The `fetch` function used to make network requests.
|
|
62
|
+
*
|
|
63
|
+
* @default The global `fetch` function.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
|
|
164
66
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
67
|
+
fetchFn;
|
|
68
|
+
/**
|
|
69
|
+
* The default `fetch` options sent with each Content API request. These
|
|
70
|
+
* parameters can be overriden on each method.
|
|
71
|
+
*
|
|
72
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#config-options}
|
|
73
|
+
*/
|
|
74
|
+
fetchOptions;
|
|
75
|
+
#repositoryName;
|
|
76
|
+
#getRef;
|
|
77
|
+
#autoPreviews = true;
|
|
78
|
+
#autoPreviewsRequest;
|
|
169
79
|
#cachedRepository;
|
|
170
80
|
#cachedRepositoryExpiration = 0;
|
|
171
81
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* such as in some Node.js versions, the `fetch` option must be provided as
|
|
176
|
-
* part of the `options` parameter.
|
|
177
|
-
*
|
|
178
|
-
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
|
|
179
|
-
* API V2 endpoint for the repository.
|
|
180
|
-
* @param options - Configuration that determines how content will be queried
|
|
181
|
-
* from the Prismic repository.
|
|
182
|
-
*
|
|
183
|
-
* @returns A client that can query content from the repository.
|
|
82
|
+
* @param repositoryNameOrEndpoint - The Prismic repository name or full
|
|
83
|
+
* Content API endpoint for the repository.
|
|
84
|
+
* @param config - Client configuration.
|
|
184
85
|
*/
|
|
185
|
-
constructor(repositoryNameOrEndpoint,
|
|
186
|
-
this.fetchOptions =
|
|
187
|
-
if (typeof
|
|
86
|
+
constructor(repositoryNameOrEndpoint, config = {}) {
|
|
87
|
+
this.fetchOptions = config.fetchOptions;
|
|
88
|
+
if (typeof config.fetch === "function") this.fetchFn = config.fetch;
|
|
188
89
|
else if (typeof globalThis.fetch === "function") this.fetchFn = globalThis.fetch;
|
|
189
|
-
else throw new
|
|
90
|
+
else throw new require_errors.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
|
|
190
91
|
if (this.fetchFn === globalThis.fetch) this.fetchFn = this.fetchFn.bind(globalThis);
|
|
191
|
-
if ((
|
|
192
|
-
const documentAPIEndpoint =
|
|
193
|
-
if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(documentAPIEndpoint)) throw new
|
|
92
|
+
if ((config.documentAPIEndpoint || require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) && process.env.NODE_ENV === "development") {
|
|
93
|
+
const documentAPIEndpoint = config.documentAPIEndpoint || repositoryNameOrEndpoint;
|
|
94
|
+
if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(documentAPIEndpoint)) throw new require_errors.PrismicError("@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
|
|
194
95
|
const hostname = new URL(documentAPIEndpoint).hostname.toLowerCase();
|
|
195
96
|
if (hostname.endsWith(".prismic.io") && !hostname.endsWith(".cdn.prismic.io")) console.warn(`[@prismicio/client] The client was created with a non-CDN endpoint. Convert it to the CDN endpoint for better performance. For more details, see ${require_devMsg.devMsg("endpoint-must-use-cdn")}`);
|
|
196
|
-
if (
|
|
97
|
+
if (config.documentAPIEndpoint && require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint) && repositoryNameOrEndpoint !== config.documentAPIEndpoint) console.warn(`[@prismicio/client] Multiple incompatible endpoints were provided. Create the client using a repository name to prevent this error. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`);
|
|
197
98
|
}
|
|
198
99
|
if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
|
|
199
100
|
this.documentAPIEndpoint = repositoryNameOrEndpoint;
|
|
@@ -203,16 +104,33 @@ var Client = class {
|
|
|
203
104
|
console.warn(`[@prismicio/client] A repository name could not be inferred from the provided endpoint (\`${repositoryNameOrEndpoint}\`). Some methods will be disabled. Create the client using a repository name to prevent this warning. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`);
|
|
204
105
|
}
|
|
205
106
|
} else {
|
|
206
|
-
this.documentAPIEndpoint =
|
|
107
|
+
this.documentAPIEndpoint = config.documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
|
|
207
108
|
this.repositoryName = repositoryNameOrEndpoint;
|
|
208
109
|
}
|
|
209
|
-
this.accessToken =
|
|
210
|
-
this.routes =
|
|
211
|
-
this.brokenRoute =
|
|
212
|
-
this.defaultParams =
|
|
213
|
-
if (
|
|
110
|
+
this.accessToken = config.accessToken;
|
|
111
|
+
this.routes = config.routes;
|
|
112
|
+
this.brokenRoute = config.brokenRoute;
|
|
113
|
+
this.defaultParams = config.defaultParams;
|
|
114
|
+
if (config.ref) this.queryContentFromRef(config.ref);
|
|
214
115
|
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
215
116
|
}
|
|
117
|
+
/** The Prismic repository's name. */
|
|
118
|
+
set repositoryName(value) {
|
|
119
|
+
this.#repositoryName = value;
|
|
120
|
+
}
|
|
121
|
+
/** The Prismic repository's name. */
|
|
122
|
+
get repositoryName() {
|
|
123
|
+
if (!this.#repositoryName) throw new require_errors.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 ${require_devMsg.devMsg("prefer-repository-name")}`, void 0, void 0);
|
|
124
|
+
return this.#repositoryName;
|
|
125
|
+
}
|
|
126
|
+
/** @deprecated Replace with `documentAPIEndpoint`. */
|
|
127
|
+
set endpoint(value) {
|
|
128
|
+
this.documentAPIEndpoint = value;
|
|
129
|
+
}
|
|
130
|
+
/** @deprecated Replace with `documentAPIEndpoint`. */
|
|
131
|
+
get endpoint() {
|
|
132
|
+
return this.documentAPIEndpoint;
|
|
133
|
+
}
|
|
216
134
|
/**
|
|
217
135
|
* Enables the client to automatically query content from a preview session.
|
|
218
136
|
*
|
|
@@ -225,7 +143,7 @@ var Client = class {
|
|
|
225
143
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
|
|
226
144
|
*/
|
|
227
145
|
enableAutoPreviews() {
|
|
228
|
-
this
|
|
146
|
+
this.#autoPreviews = true;
|
|
229
147
|
}
|
|
230
148
|
/**
|
|
231
149
|
* Enables the client to automatically query content from a preview session
|
|
@@ -239,9 +157,9 @@ var Client = class {
|
|
|
239
157
|
*
|
|
240
158
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
|
|
241
159
|
*/
|
|
242
|
-
enableAutoPreviewsFromReq(
|
|
243
|
-
this.
|
|
244
|
-
this
|
|
160
|
+
enableAutoPreviewsFromReq(request$1) {
|
|
161
|
+
this.enableAutoPreviews();
|
|
162
|
+
this.#autoPreviewsRequest = request$1;
|
|
245
163
|
}
|
|
246
164
|
/**
|
|
247
165
|
* Disables the client from automatically querying content from a preview
|
|
@@ -256,7 +174,8 @@ var Client = class {
|
|
|
256
174
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
|
|
257
175
|
*/
|
|
258
176
|
disableAutoPreviews() {
|
|
259
|
-
this
|
|
177
|
+
this.#autoPreviews = false;
|
|
178
|
+
this.#autoPreviewsRequest = void 0;
|
|
260
179
|
}
|
|
261
180
|
/**
|
|
262
181
|
* Fetches pages based on the `params` argument. Results are paginated.
|
|
@@ -270,8 +189,7 @@ var Client = class {
|
|
|
270
189
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
|
|
271
190
|
*/
|
|
272
191
|
async get(params) {
|
|
273
|
-
|
|
274
|
-
return data;
|
|
192
|
+
return await (await this.#internalGet(params)).json();
|
|
275
193
|
}
|
|
276
194
|
/**
|
|
277
195
|
* Fetches the first page returned based on the `params` argument.
|
|
@@ -285,15 +203,14 @@ var Client = class {
|
|
|
285
203
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
|
|
286
204
|
*/
|
|
287
205
|
async getFirst(params) {
|
|
288
|
-
const actualParams =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
|
|
206
|
+
const actualParams = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params.pageSize) ? params : {
|
|
207
|
+
...params,
|
|
208
|
+
pageSize: 1
|
|
209
|
+
};
|
|
210
|
+
const response = await this.#internalGet(actualParams);
|
|
211
|
+
const { results } = await response.clone().json();
|
|
212
|
+
if (results[0]) return results[0];
|
|
213
|
+
throw new require_errors.NotFoundError("No documents were returned", response.url, void 0);
|
|
297
214
|
}
|
|
298
215
|
/**
|
|
299
216
|
* Fetches all pages based on the `params` argument. This method may make
|
|
@@ -308,11 +225,11 @@ var Client = class {
|
|
|
308
225
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
|
|
309
226
|
*/
|
|
310
227
|
async dangerouslyGetAll(params = {}) {
|
|
311
|
-
var _this$
|
|
228
|
+
var _this$defaultParams;
|
|
312
229
|
const { limit = Infinity,...actualParams } = params;
|
|
313
230
|
const resolvedParams = {
|
|
314
231
|
...actualParams,
|
|
315
|
-
pageSize: Math.min(limit, actualParams.pageSize || ((_this$
|
|
232
|
+
pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) || MAX_PAGE_SIZE)
|
|
316
233
|
};
|
|
317
234
|
const documents = [];
|
|
318
235
|
let latestResult;
|
|
@@ -339,7 +256,7 @@ var Client = class {
|
|
|
339
256
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyid}
|
|
340
257
|
*/
|
|
341
258
|
async getByID(id, params) {
|
|
342
|
-
return await this.getFirst(
|
|
259
|
+
return await this.getFirst(appendFilters(params, require_filter.filter.at("document.id", id)));
|
|
343
260
|
}
|
|
344
261
|
/**
|
|
345
262
|
* Fetches pages with specific IDs. Results are paginated.
|
|
@@ -356,7 +273,7 @@ var Client = class {
|
|
|
356
273
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyids}
|
|
357
274
|
*/
|
|
358
275
|
async getByIDs(ids, params) {
|
|
359
|
-
return await this.get(
|
|
276
|
+
return await this.get(appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
360
277
|
}
|
|
361
278
|
/**
|
|
362
279
|
* Fetches pages with specific IDs. This method may make multiple network
|
|
@@ -374,7 +291,7 @@ var Client = class {
|
|
|
374
291
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyids}
|
|
375
292
|
*/
|
|
376
293
|
async getAllByIDs(ids, params) {
|
|
377
|
-
return await this.dangerouslyGetAll(
|
|
294
|
+
return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.in("document.id", ids)));
|
|
378
295
|
}
|
|
379
296
|
/**
|
|
380
297
|
* Fetches a page with a specific UID and type.
|
|
@@ -388,7 +305,7 @@ var Client = class {
|
|
|
388
305
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuid}
|
|
389
306
|
*/
|
|
390
307
|
async getByUID(documentType, uid, params) {
|
|
391
|
-
return await this.getFirst(
|
|
308
|
+
return await this.getFirst(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.at(`my.${documentType}.uid`, uid)));
|
|
392
309
|
}
|
|
393
310
|
/**
|
|
394
311
|
* Fetches pages with specific UIDs and a specific type. Results are
|
|
@@ -406,7 +323,7 @@ var Client = class {
|
|
|
406
323
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyuids}
|
|
407
324
|
*/
|
|
408
325
|
async getByUIDs(documentType, uids, params) {
|
|
409
|
-
return await this.get(
|
|
326
|
+
return await this.get(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)));
|
|
410
327
|
}
|
|
411
328
|
/**
|
|
412
329
|
* Fetches pages with specific UIDs and a specific type. This method may make
|
|
@@ -424,7 +341,7 @@ var Client = class {
|
|
|
424
341
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyuids}
|
|
425
342
|
*/
|
|
426
343
|
async getAllByUIDs(documentType, uids, params) {
|
|
427
|
-
return await this.dangerouslyGetAll(
|
|
344
|
+
return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.type", documentType), require_filter.filter.in(`my.${documentType}.uid`, uids)));
|
|
428
345
|
}
|
|
429
346
|
/**
|
|
430
347
|
* Fetches a specific single type page.
|
|
@@ -438,7 +355,7 @@ var Client = class {
|
|
|
438
355
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getsingle}
|
|
439
356
|
*/
|
|
440
357
|
async getSingle(documentType, params) {
|
|
441
|
-
return await this.getFirst(
|
|
358
|
+
return await this.getFirst(appendFilters(params, require_filter.filter.at("document.type", documentType)));
|
|
442
359
|
}
|
|
443
360
|
/**
|
|
444
361
|
* Fetches pages with a specific type. Results are paginated.
|
|
@@ -452,7 +369,7 @@ var Client = class {
|
|
|
452
369
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytype}
|
|
453
370
|
*/
|
|
454
371
|
async getByType(documentType, params) {
|
|
455
|
-
return await this.get(
|
|
372
|
+
return await this.get(appendFilters(params, require_filter.filter.at("document.type", documentType)));
|
|
456
373
|
}
|
|
457
374
|
/**
|
|
458
375
|
* Fetches pages with a specific type. This method may make multiple network
|
|
@@ -467,7 +384,7 @@ var Client = class {
|
|
|
467
384
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytype}
|
|
468
385
|
*/
|
|
469
386
|
async getAllByType(documentType, params) {
|
|
470
|
-
return await this.dangerouslyGetAll(
|
|
387
|
+
return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.type", documentType)));
|
|
471
388
|
}
|
|
472
389
|
/**
|
|
473
390
|
* Fetches pages with a specific tag. Results are paginated.
|
|
@@ -481,7 +398,7 @@ var Client = class {
|
|
|
481
398
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbytag}
|
|
482
399
|
*/
|
|
483
400
|
async getByTag(tag, params) {
|
|
484
|
-
return await this.get(
|
|
401
|
+
return await this.get(appendFilters(params, require_filter.filter.any("document.tags", [tag])));
|
|
485
402
|
}
|
|
486
403
|
/**
|
|
487
404
|
* Fetches pages with a specific tag. This method may make multiple network
|
|
@@ -496,7 +413,7 @@ var Client = class {
|
|
|
496
413
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbytag}
|
|
497
414
|
*/
|
|
498
415
|
async getAllByTag(tag, params) {
|
|
499
|
-
return await this.dangerouslyGetAll(
|
|
416
|
+
return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.any("document.tags", [tag])));
|
|
500
417
|
}
|
|
501
418
|
/**
|
|
502
419
|
* Fetches pages with every tag from a list of tags. Results are paginated.
|
|
@@ -510,7 +427,7 @@ var Client = class {
|
|
|
510
427
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbyeverytag}
|
|
511
428
|
*/
|
|
512
429
|
async getByEveryTag(tags, params) {
|
|
513
|
-
return await this.get(
|
|
430
|
+
return await this.get(appendFilters(params, require_filter.filter.at("document.tags", tags)));
|
|
514
431
|
}
|
|
515
432
|
/**
|
|
516
433
|
* Fetches pages with every tag from a list of tags. This method may make
|
|
@@ -525,7 +442,7 @@ var Client = class {
|
|
|
525
442
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbyeverytag}
|
|
526
443
|
*/
|
|
527
444
|
async getAllByEveryTag(tags, params) {
|
|
528
|
-
return await this.dangerouslyGetAll(
|
|
445
|
+
return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.at("document.tags", tags)));
|
|
529
446
|
}
|
|
530
447
|
/**
|
|
531
448
|
* Fetches pages with at least one tag from a list of tags. Results are
|
|
@@ -540,7 +457,7 @@ var Client = class {
|
|
|
540
457
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getbysometags}
|
|
541
458
|
*/
|
|
542
459
|
async getBySomeTags(tags, params) {
|
|
543
|
-
return await this.get(
|
|
460
|
+
return await this.get(appendFilters(params, require_filter.filter.any("document.tags", tags)));
|
|
544
461
|
}
|
|
545
462
|
/**
|
|
546
463
|
* Fetches pages with at least one tag from a list of tags. This method may
|
|
@@ -555,7 +472,7 @@ var Client = class {
|
|
|
555
472
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getallbysometags}
|
|
556
473
|
*/
|
|
557
474
|
async getAllBySomeTags(tags, params) {
|
|
558
|
-
return await this.dangerouslyGetAll(
|
|
475
|
+
return await this.dangerouslyGetAll(appendFilters(params, require_filter.filter.any("document.tags", tags)));
|
|
559
476
|
}
|
|
560
477
|
/**
|
|
561
478
|
* Fetches metadata about the client's Prismic repository.
|
|
@@ -574,18 +491,13 @@ var Client = class {
|
|
|
574
491
|
const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
|
|
575
492
|
if (accessToken) url.searchParams.set("access_token", accessToken);
|
|
576
493
|
const response = await this.#request(url, params);
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
return this.#cachedRepository;
|
|
582
|
-
case 401: {
|
|
583
|
-
const json = await response.json();
|
|
584
|
-
throw new require_ForbiddenError.ForbiddenError(json.error, url.toString(), json);
|
|
585
|
-
}
|
|
586
|
-
case 404: throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
|
|
587
|
-
default: throw new require_PrismicError.PrismicError(void 0, url.toString(), await response.text());
|
|
494
|
+
if (response.ok) {
|
|
495
|
+
this.#cachedRepository = await response.json();
|
|
496
|
+
this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
497
|
+
return this.#cachedRepository;
|
|
588
498
|
}
|
|
499
|
+
if (response.status === 404) throw new require_errors.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
|
|
500
|
+
return await this.#throwContentAPIError(response, url.toString());
|
|
589
501
|
}
|
|
590
502
|
/**
|
|
591
503
|
* Fetches the repository's active refs.
|
|
@@ -613,7 +525,9 @@ var Client = class {
|
|
|
613
525
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbyid}
|
|
614
526
|
*/
|
|
615
527
|
async getRefByID(id, params) {
|
|
616
|
-
|
|
528
|
+
const ref = (await this.getRefs(params)).find((ref$1) => ref$1.id === id);
|
|
529
|
+
if (!ref) throw new require_errors.PrismicError(`Ref with ID "${id}" could not be found.`, void 0, void 0);
|
|
530
|
+
return ref;
|
|
617
531
|
}
|
|
618
532
|
/**
|
|
619
533
|
* Fetches a ref by its label. A release ref's label is its name shown in the
|
|
@@ -628,7 +542,9 @@ var Client = class {
|
|
|
628
542
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getrefbylabel}
|
|
629
543
|
*/
|
|
630
544
|
async getRefByLabel(label, params) {
|
|
631
|
-
|
|
545
|
+
const ref = (await this.getRefs(params)).find((ref$1) => ref$1.label === label);
|
|
546
|
+
if (!ref) throw new require_errors.PrismicError(`Ref with label "${label}" could not be found.`, void 0, void 0);
|
|
547
|
+
return ref;
|
|
632
548
|
}
|
|
633
549
|
/**
|
|
634
550
|
* Fetches the repository's master ref.
|
|
@@ -642,7 +558,9 @@ var Client = class {
|
|
|
642
558
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getmasterref}
|
|
643
559
|
*/
|
|
644
560
|
async getMasterRef(params) {
|
|
645
|
-
|
|
561
|
+
const ref = (await this.getRefs(params)).find((ref$1) => ref$1.isMasterRef);
|
|
562
|
+
if (!ref) throw new require_errors.PrismicError("Master ref could not be found.", void 0, void 0);
|
|
563
|
+
return ref;
|
|
646
564
|
}
|
|
647
565
|
/**
|
|
648
566
|
* Fetches the repository's active releases.
|
|
@@ -670,7 +588,9 @@ var Client = class {
|
|
|
670
588
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebyid}
|
|
671
589
|
*/
|
|
672
590
|
async getReleaseByID(id, params) {
|
|
673
|
-
|
|
591
|
+
const release = (await this.getReleases(params)).find((ref) => ref.id === id);
|
|
592
|
+
if (!release) throw new require_errors.PrismicError(`Release with ID "${id}" could not be found.`, void 0, void 0);
|
|
593
|
+
return release;
|
|
674
594
|
}
|
|
675
595
|
/**
|
|
676
596
|
* Fetches a release by its label. A release ref's label is its name shown in
|
|
@@ -685,7 +605,9 @@ var Client = class {
|
|
|
685
605
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getreleasebylabel}
|
|
686
606
|
*/
|
|
687
607
|
async getReleaseByLabel(label, params) {
|
|
688
|
-
|
|
608
|
+
const release = (await this.getReleases(params)).find((ref) => ref.label === label);
|
|
609
|
+
if (!release) throw new require_errors.PrismicError(`Release with label "${label}" could not be found.`, void 0, void 0);
|
|
610
|
+
return release;
|
|
689
611
|
}
|
|
690
612
|
/**
|
|
691
613
|
* Fetches the repository's page tags.
|
|
@@ -723,7 +645,7 @@ var Client = class {
|
|
|
723
645
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
|
|
724
646
|
*/
|
|
725
647
|
async buildQueryURL({ signal, fetchOptions,...params } = {}) {
|
|
726
|
-
const ref = params.ref || await this
|
|
648
|
+
const ref = params.ref || await this.#getResolvedRef({
|
|
727
649
|
accessToken: params.accessToken,
|
|
728
650
|
signal,
|
|
729
651
|
fetchOptions
|
|
@@ -764,13 +686,13 @@ var Client = class {
|
|
|
764
686
|
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
765
687
|
documentID = documentID || searchParams.get("documentId");
|
|
766
688
|
previewToken = previewToken || searchParams.get("token");
|
|
767
|
-
} else if (this
|
|
768
|
-
if ("query" in this
|
|
769
|
-
var _this$
|
|
770
|
-
documentID = documentID || ((_this$
|
|
771
|
-
previewToken = previewToken || ((_this$
|
|
772
|
-
} else if ("url" in this
|
|
773
|
-
const searchParams = new URL(this.
|
|
689
|
+
} else if (this.#autoPreviewsRequest) {
|
|
690
|
+
if ("query" in this.#autoPreviewsRequest) {
|
|
691
|
+
var _this$autoPreviewsReq, _this$autoPreviewsReq2;
|
|
692
|
+
documentID = documentID || ((_this$autoPreviewsReq = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq === void 0 ? void 0 : _this$autoPreviewsReq.documentId);
|
|
693
|
+
previewToken = previewToken || ((_this$autoPreviewsReq2 = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq2 === void 0 ? void 0 : _this$autoPreviewsReq2.token);
|
|
694
|
+
} else if ("url" in this.#autoPreviewsRequest && this.#autoPreviewsRequest.url) {
|
|
695
|
+
const searchParams = new URL(this.#autoPreviewsRequest.url, "missing-host://").searchParams;
|
|
774
696
|
documentID = documentID || searchParams.get("documentId");
|
|
775
697
|
previewToken = previewToken || searchParams.get("token");
|
|
776
698
|
}
|
|
@@ -799,7 +721,7 @@ var Client = class {
|
|
|
799
721
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
|
|
800
722
|
*/
|
|
801
723
|
queryLatestContent() {
|
|
802
|
-
this
|
|
724
|
+
this.#getRef = void 0;
|
|
803
725
|
}
|
|
804
726
|
/**
|
|
805
727
|
* Configures the client to query content from a release with a specific ID.
|
|
@@ -812,11 +734,9 @@ var Client = class {
|
|
|
812
734
|
*
|
|
813
735
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
|
|
814
736
|
*/
|
|
815
|
-
queryContentFromReleaseByID(
|
|
816
|
-
this
|
|
817
|
-
|
|
818
|
-
mode: RefStateMode.ReleaseID,
|
|
819
|
-
releaseID
|
|
737
|
+
queryContentFromReleaseByID(id) {
|
|
738
|
+
this.#getRef = async (params) => {
|
|
739
|
+
return (await this.getReleaseByID(id, params)).ref;
|
|
820
740
|
};
|
|
821
741
|
}
|
|
822
742
|
/**
|
|
@@ -831,11 +751,9 @@ var Client = class {
|
|
|
831
751
|
*
|
|
832
752
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
|
|
833
753
|
*/
|
|
834
|
-
queryContentFromReleaseByLabel(
|
|
835
|
-
this
|
|
836
|
-
|
|
837
|
-
mode: RefStateMode.ReleaseLabel,
|
|
838
|
-
releaseLabel
|
|
754
|
+
queryContentFromReleaseByLabel(label) {
|
|
755
|
+
this.#getRef = async (params) => {
|
|
756
|
+
return (await this.getReleaseByLabel(label, params)).ref;
|
|
839
757
|
};
|
|
840
758
|
}
|
|
841
759
|
/**
|
|
@@ -850,11 +768,7 @@ var Client = class {
|
|
|
850
768
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
|
|
851
769
|
*/
|
|
852
770
|
queryContentFromRef(ref) {
|
|
853
|
-
this
|
|
854
|
-
...this.refState,
|
|
855
|
-
mode: RefStateMode.Manual,
|
|
856
|
-
ref
|
|
857
|
-
};
|
|
771
|
+
this.#getRef = typeof ref === "string" ? () => ref : ref;
|
|
858
772
|
}
|
|
859
773
|
/**
|
|
860
774
|
* A preconfigured `fetch()` function for Prismic's GraphQL API that can be
|
|
@@ -881,20 +795,21 @@ var Client = class {
|
|
|
881
795
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#graphqlfetch}
|
|
882
796
|
*/
|
|
883
797
|
async graphQLFetch(input, init) {
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
"Prismic-ref": ref,
|
|
888
|
-
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
889
|
-
...init ? init.headers : {}
|
|
798
|
+
const params = {
|
|
799
|
+
accessToken: this.accessToken,
|
|
800
|
+
fetchOptions: this.fetchOptions
|
|
890
801
|
};
|
|
891
|
-
|
|
802
|
+
const repository = await this.getRepository(params);
|
|
803
|
+
const ref = await this.#getResolvedRef(params);
|
|
892
804
|
const headers = {};
|
|
893
|
-
|
|
894
|
-
|
|
805
|
+
headers["prismic-ref"] = ref;
|
|
806
|
+
if (this.accessToken) headers["authorization"] = `Token ${this.accessToken}`;
|
|
807
|
+
if (repository.integrationFieldsRef) headers["prismic-integration-field-ref"] = repository.integrationFieldsRef;
|
|
808
|
+
for (const [key, value] of Object.entries((init === null || init === void 0 ? void 0 : init.headers) ?? {})) headers[key.toLowerCase()] = value;
|
|
809
|
+
const url = new URL(typeof input === "string" ? input : input.url);
|
|
810
|
+
const query = (url.searchParams.get("query") ?? "").replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
|
|
811
|
+
url.searchParams.set("query", query);
|
|
895
812
|
url.searchParams.set("ref", ref);
|
|
896
|
-
const query = url.searchParams.get("query");
|
|
897
|
-
if (query) url.searchParams.set("query", require_minifyGraphQLQuery.minifyGraphQLQuery(query));
|
|
898
813
|
return await this.fetchFn(url.toString(), {
|
|
899
814
|
...init,
|
|
900
815
|
headers
|
|
@@ -905,7 +820,7 @@ var Client = class {
|
|
|
905
820
|
* method may make a network request to fetch a ref or resolve the user's ref
|
|
906
821
|
* thunk.
|
|
907
822
|
*
|
|
908
|
-
* If auto previews are enabled, the preview ref takes priority
|
|
823
|
+
* If auto previews are enabled, the preview ref takes priority.
|
|
909
824
|
*
|
|
910
825
|
* The following strategies are used depending on the client's state:
|
|
911
826
|
*
|
|
@@ -920,110 +835,76 @@ var Client = class {
|
|
|
920
835
|
* release is fetched.
|
|
921
836
|
* - If the user called `queryContentFromRef`: Use the provided ref. Fall back
|
|
922
837
|
* to the master ref if the ref is not a string.
|
|
923
|
-
*
|
|
924
|
-
* @returns The ref to use during a query.
|
|
925
838
|
*/
|
|
926
|
-
async
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if ((_this$refState$httpRe3 = this.refState.httpRequest) === null || _this$refState$httpRe3 === void 0 ? void 0 : _this$refState$httpRe3.headers) {
|
|
932
|
-
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
933
|
-
else if ("cookie" in this.refState.httpRequest.headers) cookieJar = this.refState.httpRequest.headers.cookie;
|
|
934
|
-
} else if ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) cookieJar = globalThis.document.cookie;
|
|
935
|
-
if (cookieJar) previewRef = require_getPreviewCookie.getPreviewCookie(cookieJar);
|
|
839
|
+
async #getResolvedRef(params) {
|
|
840
|
+
var _this$getRef;
|
|
841
|
+
if (this.#autoPreviews) {
|
|
842
|
+
var _this$autoPreviewsReq3, _globalThis$document;
|
|
843
|
+
const previewRef = require_getPreviewCookie.getPreviewCookie((((_this$autoPreviewsReq3 = this.#autoPreviewsRequest) === null || _this$autoPreviewsReq3 === void 0 ? void 0 : _this$autoPreviewsReq3.headers) ? "get" in this.#autoPreviewsRequest.headers ? this.#autoPreviewsRequest.headers.get("cookie") : this.#autoPreviewsRequest.headers.cookie : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) ?? "");
|
|
936
844
|
if (previewRef) return previewRef;
|
|
937
845
|
}
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
else if (refModeType === RefStateMode.ReleaseLabel) return require_findRefByLabel.findRefByLabel(repository.refs, this.refState.releaseLabel).ref;
|
|
942
|
-
else if (refModeType === RefStateMode.Manual) {
|
|
943
|
-
const res = await require_castThunk.castThunk(this.refState.ref)();
|
|
944
|
-
if (typeof res === "string") return res;
|
|
945
|
-
}
|
|
946
|
-
return require_findMasterRef.findMasterRef(repository.refs).ref;
|
|
846
|
+
const ref = await ((_this$getRef = this.#getRef) === null || _this$getRef === void 0 ? void 0 : _this$getRef.call(this, params));
|
|
847
|
+
if (ref) return ref;
|
|
848
|
+
return (await this.getMasterRef(params)).ref;
|
|
947
849
|
}
|
|
948
850
|
/**
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
* method to include in thrown errors.
|
|
952
|
-
*
|
|
953
|
-
* This method retries requests that throw `RefNotFoundError` or
|
|
954
|
-
* `RefExpiredError`. It contains special logic to retry with the latest
|
|
955
|
-
* master ref, provided in the API's error message.
|
|
956
|
-
*
|
|
957
|
-
* @typeParam TDocument - Type of Prismic documents returned.
|
|
958
|
-
*
|
|
959
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
960
|
-
*
|
|
961
|
-
* @returns An object containing the paginated response containing the result
|
|
962
|
-
* of the query and the URL used to make the API request.
|
|
851
|
+
* Performs a low-level Content API request with the given parameters.
|
|
852
|
+
* Automatically retries if an invalid ref is used.
|
|
963
853
|
*/
|
|
964
|
-
async
|
|
854
|
+
async #internalGet(params, attempt = 1) {
|
|
965
855
|
const url = await this.buildQueryURL(params);
|
|
856
|
+
const response = await this.#request(new URL(url), params);
|
|
857
|
+
if (response.ok) return response;
|
|
966
858
|
try {
|
|
967
|
-
|
|
968
|
-
switch (response.status) {
|
|
969
|
-
case 200: try {
|
|
970
|
-
return {
|
|
971
|
-
data: await response.clone().json(),
|
|
972
|
-
url
|
|
973
|
-
};
|
|
974
|
-
} catch {
|
|
975
|
-
throw new require_PrismicError.PrismicError(void 0, url, await response.text());
|
|
976
|
-
}
|
|
977
|
-
case 400: {
|
|
978
|
-
const json = await response.json();
|
|
979
|
-
throw new require_ParsingError.ParsingError(json.message, url, json);
|
|
980
|
-
}
|
|
981
|
-
case 401: {
|
|
982
|
-
const json = await response.json();
|
|
983
|
-
throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
|
|
984
|
-
}
|
|
985
|
-
case 404: {
|
|
986
|
-
const json = await response.json();
|
|
987
|
-
switch (json.type) {
|
|
988
|
-
case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
|
|
989
|
-
case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
|
|
990
|
-
default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
case 410: {
|
|
994
|
-
const json = await response.json();
|
|
995
|
-
throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
|
|
996
|
-
}
|
|
997
|
-
default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
|
|
998
|
-
}
|
|
859
|
+
return await this.#throwContentAPIError(response, url);
|
|
999
860
|
} catch (error) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
861
|
+
if ((error instanceof require_errors.RefNotFoundError || error instanceof require_errors.RefExpiredError) && attempt < MAX_INVALID_REF_RETRY_ATTEMPTS) {
|
|
862
|
+
var _error$message$match;
|
|
863
|
+
if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
|
|
864
|
+
const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
|
|
865
|
+
if (!masterRef) throw error;
|
|
866
|
+
require_throttledWarn.throttledWarn(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_errors.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`);
|
|
867
|
+
return await this.#internalGet({
|
|
868
|
+
...params,
|
|
869
|
+
ref: masterRef
|
|
870
|
+
}, attempt + 1);
|
|
871
|
+
}
|
|
872
|
+
throw error;
|
|
1010
873
|
}
|
|
1011
874
|
}
|
|
1012
875
|
/**
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
* @param url - The URL to request.
|
|
1017
|
-
* @param params - Fetch options.
|
|
1018
|
-
*
|
|
1019
|
-
* @returns The response from the fetch request.
|
|
876
|
+
* Throws an error based on a Content API response. Only call in known-errored
|
|
877
|
+
* states.
|
|
1020
878
|
*/
|
|
1021
|
-
async #
|
|
1022
|
-
|
|
879
|
+
async #throwContentAPIError(response, url) {
|
|
880
|
+
switch (response.status) {
|
|
881
|
+
case 400: {
|
|
882
|
+
const json = await response.clone().json();
|
|
883
|
+
throw new require_errors.ParsingError(json.message, url, json);
|
|
884
|
+
}
|
|
885
|
+
case 401: {
|
|
886
|
+
const json = await response.clone().json();
|
|
887
|
+
throw new require_errors.ForbiddenError(json.message, url, json);
|
|
888
|
+
}
|
|
889
|
+
case 404: {
|
|
890
|
+
const json = await response.clone().json();
|
|
891
|
+
switch (json.type) {
|
|
892
|
+
case "api_notfound_error": throw new require_errors.RefNotFoundError(json.message, url, json);
|
|
893
|
+
case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_errors.PreviewTokenExpiredError(json.message, url, json);
|
|
894
|
+
default: throw new require_errors.NotFoundError(json.message, url, json);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
case 410: {
|
|
898
|
+
const json = await response.clone().json();
|
|
899
|
+
throw new require_errors.RefExpiredError(json.message, url, json);
|
|
900
|
+
}
|
|
901
|
+
default: throw new require_errors.PrismicError(void 0, url, await response.text());
|
|
902
|
+
}
|
|
1023
903
|
}
|
|
1024
|
-
|
|
904
|
+
/** Performs a low-level network request with the client's fetch options. */
|
|
905
|
+
async #request(url, params) {
|
|
1025
906
|
var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
|
|
1026
|
-
return {
|
|
907
|
+
return await require_request.request(url, {
|
|
1027
908
|
...this.fetchOptions,
|
|
1028
909
|
...params === null || params === void 0 ? void 0 : params.fetchOptions,
|
|
1029
910
|
headers: {
|
|
@@ -1031,9 +912,16 @@ var Client = class {
|
|
|
1031
912
|
...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
|
|
1032
913
|
},
|
|
1033
914
|
signal: (params === null || params === void 0 || (_params$fetchOptions2 = params.fetchOptions) === null || _params$fetchOptions2 === void 0 ? void 0 : _params$fetchOptions2.signal) || (params === null || params === void 0 ? void 0 : params.signal) || ((_this$fetchOptions2 = this.fetchOptions) === null || _this$fetchOptions2 === void 0 ? void 0 : _this$fetchOptions2.signal)
|
|
1034
|
-
};
|
|
915
|
+
}, this.fetchFn);
|
|
1035
916
|
}
|
|
1036
917
|
};
|
|
918
|
+
/** Appends filters to a params object. */
|
|
919
|
+
function appendFilters(params = {}, ...filters) {
|
|
920
|
+
return {
|
|
921
|
+
...params,
|
|
922
|
+
filters: [...params.filters ?? [], ...filters]
|
|
923
|
+
};
|
|
924
|
+
}
|
|
1037
925
|
|
|
1038
926
|
//#endregion
|
|
1039
927
|
exports.Client = Client;
|