@prismicio/client 6.7.1 → 6.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ForbiddenError.cjs +7 -0
- package/dist/ForbiddenError.cjs.map +1 -0
- package/dist/ForbiddenError.d.ts +11 -0
- package/dist/ForbiddenError.js +7 -0
- package/dist/ForbiddenError.js.map +1 -0
- package/dist/NotFoundError.cjs +7 -0
- package/dist/NotFoundError.cjs.map +1 -0
- package/dist/NotFoundError.d.ts +3 -0
- package/dist/NotFoundError.js +7 -0
- package/dist/NotFoundError.js.map +1 -0
- package/dist/ParsingError.cjs +7 -0
- package/dist/ParsingError.cjs.map +1 -0
- package/dist/ParsingError.d.ts +12 -0
- package/dist/ParsingError.js +7 -0
- package/dist/ParsingError.js.map +1 -0
- package/dist/PrismicError.cjs +19 -0
- package/dist/PrismicError.cjs.map +1 -0
- package/dist/PrismicError.d.ts +5 -0
- package/dist/PrismicError.js +19 -0
- package/dist/PrismicError.js.map +1 -0
- package/dist/buildQueryURL.cjs +40 -0
- package/dist/buildQueryURL.cjs.map +1 -0
- package/dist/buildQueryURL.d.ts +130 -0
- package/dist/buildQueryURL.js +40 -0
- package/dist/buildQueryURL.js.map +1 -0
- package/dist/client.cjs +436 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.ts +929 -0
- package/dist/client.js +419 -0
- package/dist/client.js.map +1 -0
- package/dist/cookie.cjs +5 -0
- package/dist/cookie.cjs.map +1 -0
- package/dist/cookie.d.ts +5 -0
- package/dist/cookie.js +5 -0
- package/dist/cookie.js.map +1 -0
- package/dist/getGraphQLEndpoint.cjs +13 -0
- package/dist/getGraphQLEndpoint.cjs.map +1 -0
- package/dist/getGraphQLEndpoint.d.ts +9 -0
- package/dist/getGraphQLEndpoint.js +13 -0
- package/dist/getGraphQLEndpoint.js.map +1 -0
- package/dist/getRepositoryEndpoint.cjs +13 -0
- package/dist/getRepositoryEndpoint.cjs.map +1 -0
- package/dist/getRepositoryEndpoint.d.ts +10 -0
- package/dist/getRepositoryEndpoint.js +13 -0
- package/dist/getRepositoryEndpoint.js.map +1 -0
- package/dist/getRepositoryName.cjs +12 -0
- package/dist/getRepositoryName.cjs.map +1 -0
- package/dist/getRepositoryName.d.ts +13 -0
- package/dist/getRepositoryName.js +12 -0
- package/dist/getRepositoryName.js.map +1 -0
- package/dist/index.cjs +32 -719
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +88 -1526
- package/dist/index.js +34 -679
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs +12 -0
- package/dist/isRepositoryEndpoint.cjs.map +1 -0
- package/dist/isRepositoryEndpoint.d.ts +10 -0
- package/dist/isRepositoryEndpoint.js +12 -0
- package/dist/isRepositoryEndpoint.js.map +1 -0
- package/dist/isRepositoryName.cjs +7 -0
- package/dist/isRepositoryName.cjs.map +1 -0
- package/dist/isRepositoryName.d.ts +9 -0
- package/dist/isRepositoryName.js +7 -0
- package/dist/isRepositoryName.js.map +1 -0
- package/dist/lib/appendPredicates.cjs +14 -0
- package/dist/lib/appendPredicates.cjs.map +1 -0
- package/dist/lib/appendPredicates.d.ts +18 -0
- package/dist/lib/appendPredicates.js +14 -0
- package/dist/lib/appendPredicates.js.map +1 -0
- package/dist/lib/castArray.cjs +5 -0
- package/dist/lib/castArray.cjs.map +1 -0
- package/dist/lib/castArray.d.ts +11 -0
- package/dist/lib/castArray.js +5 -0
- package/dist/lib/castArray.js.map +1 -0
- package/dist/lib/castThunk.cjs +5 -0
- package/dist/lib/castThunk.cjs.map +1 -0
- package/dist/lib/castThunk.d.ts +10 -0
- package/dist/lib/castThunk.js +5 -0
- package/dist/lib/castThunk.js.map +1 -0
- package/dist/lib/findMasterRef.cjs +8 -0
- package/dist/lib/findMasterRef.cjs.map +1 -0
- package/dist/lib/findMasterRef.d.ts +10 -0
- package/dist/lib/findMasterRef.js +8 -0
- package/dist/lib/findMasterRef.js.map +1 -0
- package/dist/lib/findRef.cjs +12 -0
- package/dist/lib/findRef.cjs.map +1 -0
- package/dist/lib/findRef.d.ts +13 -0
- package/dist/lib/findRef.js +12 -0
- package/dist/lib/findRef.js.map +1 -0
- package/dist/lib/findRefByID.cjs +8 -0
- package/dist/lib/findRefByID.cjs.map +1 -0
- package/dist/lib/findRefByID.d.ts +11 -0
- package/dist/lib/findRefByID.js +8 -0
- package/dist/lib/findRefByID.js.map +1 -0
- package/dist/lib/findRefByLabel.cjs +8 -0
- package/dist/lib/findRefByLabel.cjs.map +1 -0
- package/dist/lib/findRefByLabel.d.ts +11 -0
- package/dist/lib/findRefByLabel.js +8 -0
- package/dist/lib/findRefByLabel.js.map +1 -0
- package/dist/lib/getPreviewCookie.cjs +21 -0
- package/dist/lib/getPreviewCookie.cjs.map +1 -0
- package/dist/lib/getPreviewCookie.d.ts +9 -0
- package/dist/lib/getPreviewCookie.js +21 -0
- package/dist/lib/getPreviewCookie.js.map +1 -0
- package/dist/lib/minifyGraphQLQuery.cjs +7 -0
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
- package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
- package/dist/lib/minifyGraphQLQuery.js +7 -0
- package/dist/lib/minifyGraphQLQuery.js.map +1 -0
- package/dist/lib/orElseThrow.d.ts +11 -0
- package/dist/predicate.cjs +68 -0
- package/dist/predicate.cjs.map +1 -0
- package/dist/predicate.d.ts +209 -0
- package/dist/predicate.js +68 -0
- package/dist/predicate.js.map +1 -0
- package/dist/types.d.ts +156 -0
- package/package.json +21 -21
- package/src/buildQueryURL.ts +6 -3
- package/src/client.ts +71 -36
- package/src/cookie.ts +2 -1
- package/src/getRepositoryName.ts +4 -2
- package/src/isRepositoryEndpoint.ts +2 -1
- package/src/isRepositoryName.ts +2 -1
- package/src/lib/appendPredicates.ts +2 -1
- package/src/lib/getPreviewCookie.ts +2 -1
- package/src/predicate.ts +4 -2
- package/src/types.ts +3 -3
package/dist/client.js
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import * as prismicH from "@prismicio/helpers";
|
|
8
|
+
import { appendPredicates } from "./lib/appendPredicates.js";
|
|
9
|
+
import { castArray } from "./lib/castArray.js";
|
|
10
|
+
import { castThunk } from "./lib/castThunk.js";
|
|
11
|
+
import { findMasterRef } from "./lib/findMasterRef.js";
|
|
12
|
+
import { findRefByID } from "./lib/findRefByID.js";
|
|
13
|
+
import { findRefByLabel } from "./lib/findRefByLabel.js";
|
|
14
|
+
import { getPreviewCookie } from "./lib/getPreviewCookie.js";
|
|
15
|
+
import { minifyGraphQLQuery } from "./lib/minifyGraphQLQuery.js";
|
|
16
|
+
import { ForbiddenError } from "./ForbiddenError.js";
|
|
17
|
+
import { NotFoundError } from "./NotFoundError.js";
|
|
18
|
+
import { ParsingError } from "./ParsingError.js";
|
|
19
|
+
import { PrismicError } from "./PrismicError.js";
|
|
20
|
+
import { buildQueryURL } from "./buildQueryURL.js";
|
|
21
|
+
import { getRepositoryEndpoint } from "./getRepositoryEndpoint.js";
|
|
22
|
+
import { isRepositoryEndpoint } from "./isRepositoryEndpoint.js";
|
|
23
|
+
import { predicate } from "./predicate.js";
|
|
24
|
+
const MAX_PAGE_SIZE = 100;
|
|
25
|
+
const REPOSITORY_CACHE_TTL = 5e3;
|
|
26
|
+
const GET_ALL_QUERY_DELAY = 500;
|
|
27
|
+
var RefStateMode;
|
|
28
|
+
(function(RefStateMode2) {
|
|
29
|
+
RefStateMode2["Master"] = "Master";
|
|
30
|
+
RefStateMode2["ReleaseID"] = "ReleaseID";
|
|
31
|
+
RefStateMode2["ReleaseLabel"] = "ReleaseLabel";
|
|
32
|
+
RefStateMode2["Manual"] = "Manual";
|
|
33
|
+
})(RefStateMode || (RefStateMode = {}));
|
|
34
|
+
const typePredicate = (documentType) => predicate.at("document.type", documentType);
|
|
35
|
+
const everyTagPredicate = (tags) => predicate.at("document.tags", castArray(tags));
|
|
36
|
+
const someTagsPredicate = (tags) => predicate.any("document.tags", castArray(tags));
|
|
37
|
+
const createClient = (repositoryNameOrEndpoint, options) => new Client(repositoryNameOrEndpoint, options);
|
|
38
|
+
class Client {
|
|
39
|
+
constructor(repositoryNameOrEndpoint, options = {}) {
|
|
40
|
+
__publicField(this, "endpoint");
|
|
41
|
+
__publicField(this, "accessToken");
|
|
42
|
+
__publicField(this, "routes");
|
|
43
|
+
__publicField(this, "brokenRoute");
|
|
44
|
+
__publicField(this, "fetchFn");
|
|
45
|
+
__publicField(this, "defaultParams");
|
|
46
|
+
__publicField(this, "refState", {
|
|
47
|
+
mode: RefStateMode.Master,
|
|
48
|
+
autoPreviewsEnabled: true
|
|
49
|
+
});
|
|
50
|
+
__publicField(this, "cachedRepository");
|
|
51
|
+
__publicField(this, "cachedRepositoryExpiration", 0);
|
|
52
|
+
__publicField(this, "graphqlFetch", this.graphQLFetch.bind(this));
|
|
53
|
+
if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
|
|
54
|
+
if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)) {
|
|
55
|
+
throw new 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);
|
|
56
|
+
}
|
|
57
|
+
this.endpoint = repositoryNameOrEndpoint;
|
|
58
|
+
} else {
|
|
59
|
+
this.endpoint = getRepositoryEndpoint(repositoryNameOrEndpoint);
|
|
60
|
+
}
|
|
61
|
+
this.accessToken = options.accessToken;
|
|
62
|
+
this.routes = options.routes;
|
|
63
|
+
this.brokenRoute = options.brokenRoute;
|
|
64
|
+
this.defaultParams = options.defaultParams;
|
|
65
|
+
if (options.ref) {
|
|
66
|
+
this.queryContentFromRef(options.ref);
|
|
67
|
+
}
|
|
68
|
+
if (typeof options.fetch === "function") {
|
|
69
|
+
this.fetchFn = options.fetch;
|
|
70
|
+
} else if (typeof globalThis.fetch === "function") {
|
|
71
|
+
this.fetchFn = globalThis.fetch;
|
|
72
|
+
} else {
|
|
73
|
+
throw new 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);
|
|
74
|
+
}
|
|
75
|
+
if (this.fetchFn === globalThis.fetch) {
|
|
76
|
+
this.fetchFn = this.fetchFn.bind(globalThis);
|
|
77
|
+
}
|
|
78
|
+
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
79
|
+
}
|
|
80
|
+
enableAutoPreviews() {
|
|
81
|
+
this.refState.autoPreviewsEnabled = true;
|
|
82
|
+
}
|
|
83
|
+
enableAutoPreviewsFromReq(req) {
|
|
84
|
+
this.refState.httpRequest = req;
|
|
85
|
+
this.refState.autoPreviewsEnabled = true;
|
|
86
|
+
}
|
|
87
|
+
disableAutoPreviews() {
|
|
88
|
+
this.refState.autoPreviewsEnabled = false;
|
|
89
|
+
}
|
|
90
|
+
async query(predicates, params) {
|
|
91
|
+
const url = await this.buildQueryURL({ ...params, predicates });
|
|
92
|
+
return await this.fetch(url, params);
|
|
93
|
+
}
|
|
94
|
+
async get(params) {
|
|
95
|
+
const url = await this.buildQueryURL(params);
|
|
96
|
+
return await this.fetch(url, params);
|
|
97
|
+
}
|
|
98
|
+
async getFirst(params) {
|
|
99
|
+
var _a;
|
|
100
|
+
const actualParams = { ...params };
|
|
101
|
+
if (!(params && params.page) && !(params == null ? void 0 : params.pageSize)) {
|
|
102
|
+
actualParams.pageSize = ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) ?? 1;
|
|
103
|
+
}
|
|
104
|
+
const url = await this.buildQueryURL(actualParams);
|
|
105
|
+
const result = await this.fetch(url, params);
|
|
106
|
+
const firstResult = result.results[0];
|
|
107
|
+
if (firstResult) {
|
|
108
|
+
return firstResult;
|
|
109
|
+
}
|
|
110
|
+
throw new PrismicError("No documents were returned", url, void 0);
|
|
111
|
+
}
|
|
112
|
+
async dangerouslyGetAll(params = {}) {
|
|
113
|
+
var _a;
|
|
114
|
+
const { limit = Infinity, ...actualParams } = params;
|
|
115
|
+
const resolvedParams = {
|
|
116
|
+
...actualParams,
|
|
117
|
+
pageSize: Math.min(limit, actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE)
|
|
118
|
+
};
|
|
119
|
+
const documents = [];
|
|
120
|
+
let latestResult;
|
|
121
|
+
while ((!latestResult || latestResult.next_page) && documents.length < limit) {
|
|
122
|
+
const page = latestResult ? latestResult.page + 1 : void 0;
|
|
123
|
+
latestResult = await this.get({ ...resolvedParams, page });
|
|
124
|
+
documents.push(...latestResult.results);
|
|
125
|
+
if (latestResult.next_page) {
|
|
126
|
+
await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return documents.slice(0, limit);
|
|
130
|
+
}
|
|
131
|
+
async getByID(id, params) {
|
|
132
|
+
return await this.getFirst(appendPredicates(params, predicate.at("document.id", id)));
|
|
133
|
+
}
|
|
134
|
+
async getByIDs(ids, params) {
|
|
135
|
+
return await this.get(appendPredicates(params, predicate.in("document.id", ids)));
|
|
136
|
+
}
|
|
137
|
+
async getAllByIDs(ids, params) {
|
|
138
|
+
return await this.dangerouslyGetAll(appendPredicates(params, predicate.in("document.id", ids)));
|
|
139
|
+
}
|
|
140
|
+
async getByUID(documentType, uid, params) {
|
|
141
|
+
return await this.getFirst(appendPredicates(params, [
|
|
142
|
+
typePredicate(documentType),
|
|
143
|
+
predicate.at(`my.${documentType}.uid`, uid)
|
|
144
|
+
]));
|
|
145
|
+
}
|
|
146
|
+
async getByUIDs(documentType, uids, params) {
|
|
147
|
+
return await this.get(appendPredicates(params, [
|
|
148
|
+
typePredicate(documentType),
|
|
149
|
+
predicate.in(`my.${documentType}.uid`, uids)
|
|
150
|
+
]));
|
|
151
|
+
}
|
|
152
|
+
async getAllByUIDs(documentType, uids, params) {
|
|
153
|
+
return await this.dangerouslyGetAll(appendPredicates(params, [
|
|
154
|
+
typePredicate(documentType),
|
|
155
|
+
predicate.in(`my.${documentType}.uid`, uids)
|
|
156
|
+
]));
|
|
157
|
+
}
|
|
158
|
+
async getSingle(documentType, params) {
|
|
159
|
+
return await this.getFirst(appendPredicates(params, typePredicate(documentType)));
|
|
160
|
+
}
|
|
161
|
+
async getByType(documentType, params) {
|
|
162
|
+
return await this.get(appendPredicates(params, typePredicate(documentType)));
|
|
163
|
+
}
|
|
164
|
+
async getAllByType(documentType, params) {
|
|
165
|
+
return await this.dangerouslyGetAll(appendPredicates(params, typePredicate(documentType)));
|
|
166
|
+
}
|
|
167
|
+
async getByTag(tag, params) {
|
|
168
|
+
return await this.get(appendPredicates(params, someTagsPredicate(tag)));
|
|
169
|
+
}
|
|
170
|
+
async getAllByTag(tag, params) {
|
|
171
|
+
return await this.dangerouslyGetAll(appendPredicates(params, someTagsPredicate(tag)));
|
|
172
|
+
}
|
|
173
|
+
async getByEveryTag(tags, params) {
|
|
174
|
+
return await this.get(appendPredicates(params, everyTagPredicate(tags)));
|
|
175
|
+
}
|
|
176
|
+
async getAllByEveryTag(tags, params) {
|
|
177
|
+
return await this.dangerouslyGetAll(appendPredicates(params, everyTagPredicate(tags)));
|
|
178
|
+
}
|
|
179
|
+
async getBySomeTags(tags, params) {
|
|
180
|
+
return await this.get(appendPredicates(params, someTagsPredicate(tags)));
|
|
181
|
+
}
|
|
182
|
+
async getAllBySomeTags(tags, params) {
|
|
183
|
+
return await this.dangerouslyGetAll(appendPredicates(params, someTagsPredicate(tags)));
|
|
184
|
+
}
|
|
185
|
+
async getRepository(params) {
|
|
186
|
+
const url = new URL(this.endpoint);
|
|
187
|
+
if (this.accessToken) {
|
|
188
|
+
url.searchParams.set("access_token", this.accessToken);
|
|
189
|
+
}
|
|
190
|
+
return await this.fetch(url.toString(), params);
|
|
191
|
+
}
|
|
192
|
+
async getRefs(params) {
|
|
193
|
+
const repository = await this.getRepository(params);
|
|
194
|
+
return repository.refs;
|
|
195
|
+
}
|
|
196
|
+
async getRefByID(id, params) {
|
|
197
|
+
const refs = await this.getRefs(params);
|
|
198
|
+
return findRefByID(refs, id);
|
|
199
|
+
}
|
|
200
|
+
async getRefByLabel(label, params) {
|
|
201
|
+
const refs = await this.getRefs(params);
|
|
202
|
+
return findRefByLabel(refs, label);
|
|
203
|
+
}
|
|
204
|
+
async getMasterRef(params) {
|
|
205
|
+
const refs = await this.getRefs(params);
|
|
206
|
+
return findMasterRef(refs);
|
|
207
|
+
}
|
|
208
|
+
async getReleases(params) {
|
|
209
|
+
const refs = await this.getRefs(params);
|
|
210
|
+
return refs.filter((ref) => !ref.isMasterRef);
|
|
211
|
+
}
|
|
212
|
+
async getReleaseByID(id, params) {
|
|
213
|
+
const releases = await this.getReleases(params);
|
|
214
|
+
return findRefByID(releases, id);
|
|
215
|
+
}
|
|
216
|
+
async getReleaseByLabel(label, params) {
|
|
217
|
+
const releases = await this.getReleases(params);
|
|
218
|
+
return findRefByLabel(releases, label);
|
|
219
|
+
}
|
|
220
|
+
async getTags(params) {
|
|
221
|
+
try {
|
|
222
|
+
const tagsForm = await this.getCachedRepositoryForm("tags", params);
|
|
223
|
+
const url = new URL(tagsForm.action);
|
|
224
|
+
if (this.accessToken) {
|
|
225
|
+
url.searchParams.set("access_token", this.accessToken);
|
|
226
|
+
}
|
|
227
|
+
return await this.fetch(url.toString(), params);
|
|
228
|
+
} catch {
|
|
229
|
+
const repository = await this.getRepository(params);
|
|
230
|
+
return repository.tags;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async buildQueryURL({ signal, ...params } = {}) {
|
|
234
|
+
const ref = params.ref || await this.getResolvedRefString();
|
|
235
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal })).integrationFieldsRef || void 0;
|
|
236
|
+
return buildQueryURL(this.endpoint, {
|
|
237
|
+
...this.defaultParams,
|
|
238
|
+
...params,
|
|
239
|
+
ref,
|
|
240
|
+
integrationFieldsRef,
|
|
241
|
+
routes: params.routes || this.routes,
|
|
242
|
+
brokenRoute: params.brokenRoute || this.brokenRoute,
|
|
243
|
+
accessToken: params.accessToken || this.accessToken
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
async resolvePreviewURL(args) {
|
|
247
|
+
var _a, _b;
|
|
248
|
+
let documentID = args.documentID;
|
|
249
|
+
let previewToken = args.previewToken;
|
|
250
|
+
if (typeof globalThis.location !== "undefined") {
|
|
251
|
+
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
252
|
+
documentID = documentID || searchParams.get("documentId");
|
|
253
|
+
previewToken = previewToken || searchParams.get("token");
|
|
254
|
+
} else if (this.refState.httpRequest) {
|
|
255
|
+
if ("query" in this.refState.httpRequest) {
|
|
256
|
+
documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
|
|
257
|
+
previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
|
|
258
|
+
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
259
|
+
const searchParams = new URL(this.refState.httpRequest.url).searchParams;
|
|
260
|
+
documentID = documentID || searchParams.get("documentId");
|
|
261
|
+
previewToken = previewToken || searchParams.get("token");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (documentID != null && previewToken != null) {
|
|
265
|
+
const document = await this.getByID(documentID, {
|
|
266
|
+
signal: args.signal,
|
|
267
|
+
ref: previewToken,
|
|
268
|
+
lang: "*"
|
|
269
|
+
});
|
|
270
|
+
const url = prismicH.asLink(document, args.linkResolver);
|
|
271
|
+
if (typeof url === "string") {
|
|
272
|
+
return url;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return args.defaultURL;
|
|
276
|
+
}
|
|
277
|
+
queryLatestContent() {
|
|
278
|
+
this.refState.mode = RefStateMode.Master;
|
|
279
|
+
}
|
|
280
|
+
queryContentFromReleaseByID(releaseID) {
|
|
281
|
+
this.refState = {
|
|
282
|
+
...this.refState,
|
|
283
|
+
mode: RefStateMode.ReleaseID,
|
|
284
|
+
releaseID
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
queryContentFromReleaseByLabel(releaseLabel) {
|
|
288
|
+
this.refState = {
|
|
289
|
+
...this.refState,
|
|
290
|
+
mode: RefStateMode.ReleaseLabel,
|
|
291
|
+
releaseLabel
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
queryContentFromRef(ref) {
|
|
295
|
+
this.refState = {
|
|
296
|
+
...this.refState,
|
|
297
|
+
mode: RefStateMode.Manual,
|
|
298
|
+
ref
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
async graphQLFetch(input, init) {
|
|
302
|
+
const cachedRepository = await this.getCachedRepository();
|
|
303
|
+
const ref = await this.getResolvedRefString();
|
|
304
|
+
const unsanitizedHeaders = {
|
|
305
|
+
"Prismic-ref": ref,
|
|
306
|
+
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
307
|
+
...init ? init.headers : {}
|
|
308
|
+
};
|
|
309
|
+
if (cachedRepository.integrationFieldsRef) {
|
|
310
|
+
unsanitizedHeaders["Prismic-integration-field-ref"] = cachedRepository.integrationFieldsRef;
|
|
311
|
+
}
|
|
312
|
+
const headers = {};
|
|
313
|
+
for (const key in unsanitizedHeaders) {
|
|
314
|
+
if (unsanitizedHeaders[key]) {
|
|
315
|
+
headers[key.toLowerCase()] = unsanitizedHeaders[key];
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const url = new URL(
|
|
319
|
+
input
|
|
320
|
+
);
|
|
321
|
+
url.searchParams.set("ref", ref);
|
|
322
|
+
const query = url.searchParams.get("query");
|
|
323
|
+
if (query) {
|
|
324
|
+
url.searchParams.set(
|
|
325
|
+
"query",
|
|
326
|
+
minifyGraphQLQuery(query)
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
return await this.fetchFn(url.toString(), {
|
|
330
|
+
...init,
|
|
331
|
+
headers
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
async getCachedRepository(params) {
|
|
335
|
+
if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
|
|
336
|
+
this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
337
|
+
this.cachedRepository = await this.getRepository(params);
|
|
338
|
+
}
|
|
339
|
+
return this.cachedRepository;
|
|
340
|
+
}
|
|
341
|
+
async getCachedRepositoryForm(name, params) {
|
|
342
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
343
|
+
const form = cachedRepository.forms[name];
|
|
344
|
+
if (!form) {
|
|
345
|
+
throw new PrismicError(`Form with name "${name}" could not be found`, void 0, void 0);
|
|
346
|
+
}
|
|
347
|
+
return form;
|
|
348
|
+
}
|
|
349
|
+
async getResolvedRefString(params) {
|
|
350
|
+
var _a, _b;
|
|
351
|
+
if (this.refState.autoPreviewsEnabled) {
|
|
352
|
+
let previewRef;
|
|
353
|
+
let cookieJar;
|
|
354
|
+
if ((_a = this.refState.httpRequest) == null ? void 0 : _a.headers) {
|
|
355
|
+
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
356
|
+
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
357
|
+
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
358
|
+
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
359
|
+
}
|
|
360
|
+
} else if ((_b = globalThis.document) == null ? void 0 : _b.cookie) {
|
|
361
|
+
cookieJar = globalThis.document.cookie;
|
|
362
|
+
}
|
|
363
|
+
if (cookieJar) {
|
|
364
|
+
previewRef = getPreviewCookie(cookieJar);
|
|
365
|
+
}
|
|
366
|
+
if (previewRef) {
|
|
367
|
+
return previewRef;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
371
|
+
const refModeType = this.refState.mode;
|
|
372
|
+
if (refModeType === RefStateMode.ReleaseID) {
|
|
373
|
+
return findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
|
|
374
|
+
} else if (refModeType === RefStateMode.ReleaseLabel) {
|
|
375
|
+
return findRefByLabel(cachedRepository.refs, this.refState.releaseLabel).ref;
|
|
376
|
+
} else if (refModeType === RefStateMode.Manual) {
|
|
377
|
+
const res = await castThunk(this.refState.ref)();
|
|
378
|
+
if (typeof res === "string") {
|
|
379
|
+
return res;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return findMasterRef(cachedRepository.refs).ref;
|
|
383
|
+
}
|
|
384
|
+
async fetch(url, params = {}) {
|
|
385
|
+
const res = await this.fetchFn(url, {
|
|
386
|
+
signal: params.signal
|
|
387
|
+
});
|
|
388
|
+
let json;
|
|
389
|
+
try {
|
|
390
|
+
json = await res.json();
|
|
391
|
+
} catch {
|
|
392
|
+
if (res.status === 404) {
|
|
393
|
+
throw new NotFoundError(`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`, url, void 0);
|
|
394
|
+
} else {
|
|
395
|
+
throw new PrismicError(void 0, url, void 0);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
switch (res.status) {
|
|
399
|
+
case 200: {
|
|
400
|
+
return json;
|
|
401
|
+
}
|
|
402
|
+
case 400: {
|
|
403
|
+
throw new ParsingError(json.message, url, json);
|
|
404
|
+
}
|
|
405
|
+
case 401:
|
|
406
|
+
case 403: {
|
|
407
|
+
throw new ForbiddenError("error" in json ? json.error : json.message, url, json);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
throw new PrismicError(void 0, url, json);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
export {
|
|
414
|
+
Client,
|
|
415
|
+
GET_ALL_QUERY_DELAY,
|
|
416
|
+
REPOSITORY_CACHE_TTL,
|
|
417
|
+
createClient
|
|
418
|
+
};
|
|
419
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/client.ts"],"sourcesContent":["import * as prismicT from \"@prismicio/types\";\nimport * as prismicH from \"@prismicio/helpers\";\n\nimport { appendPredicates } from \"./lib/appendPredicates\";\nimport { castArray } from \"./lib/castArray\";\nimport { castThunk } from \"./lib/castThunk\";\nimport { findMasterRef } from \"./lib/findMasterRef\";\nimport { findRefByID } from \"./lib/findRefByID\";\nimport { findRefByLabel } from \"./lib/findRefByLabel\";\nimport { getPreviewCookie } from \"./lib/getPreviewCookie\";\nimport { minifyGraphQLQuery } from \"./lib/minifyGraphQLQuery\";\n\nimport {\n\tAbortSignalLike,\n\tFetchLike,\n\tHttpRequestLike,\n\tExtractDocumentType,\n} from \"./types\";\nimport { ForbiddenError } from \"./ForbiddenError\";\nimport { NotFoundError } from \"./NotFoundError\";\nimport { ParsingError } from \"./ParsingError\";\nimport { PrismicError } from \"./PrismicError\";\nimport { buildQueryURL, BuildQueryURLArgs } from \"./buildQueryURL\";\nimport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nimport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nimport { predicate } from \"./predicate\";\n\n/**\n * The largest page size allowed by the Prismic REST API V2. This value is used\n * to minimize the number of requests required to query content.\n */\nconst MAX_PAGE_SIZE = 100;\n\n/**\n * The number of milliseconds in which repository metadata is considered valid.\n * A ref can be invalidated quickly depending on how frequently content is\n * updated in the Prismic repository. As such, repository's metadata can only be\n * considered valid for a short amount of time.\n */\nexport const REPOSITORY_CACHE_TTL = 5000;\n\n/**\n * The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,\n * `getAllByType`, `getAllByTag`) will wait between individual page requests.\n *\n * This is done to ensure API performance is sustainable and reduces the chance\n * of a failed API request due to overloading.\n */\nexport const GET_ALL_QUERY_DELAY = 500;\n\n/**\n * Modes for client ref management.\n */\nenum RefStateMode {\n\t/**\n\t * Use the repository's master ref.\n\t */\n\tMaster = \"Master\",\n\n\t/**\n\t * Use a given Release identified by its ID.\n\t */\n\tReleaseID = \"ReleaseID\",\n\n\t/**\n\t * Use a given Release identified by its label.\n\t */\n\tReleaseLabel = \"ReleaseLabel\",\n\n\t/**\n\t * Use a given ref.\n\t */\n\tManual = \"Manual\",\n}\n\n/**\n * An object containing stateful information about a client's ref strategy.\n */\ntype RefState = {\n\t/**\n\t * Determines if automatic preview support is enabled.\n\t */\n\tautoPreviewsEnabled: boolean;\n\n\t/**\n\t * An optional HTTP server request object used during previews if automatic\n\t * previews are enabled.\n\t */\n\thttpRequest?: HttpRequestLike;\n} & (\n\t| {\n\t\t\tmode: RefStateMode.Master;\n\t }\n\t| {\n\t\t\tmode: RefStateMode.ReleaseID;\n\t\t\treleaseID: string;\n\t }\n\t| {\n\t\t\tmode: RefStateMode.ReleaseLabel;\n\t\t\treleaseLabel: string;\n\t }\n\t| {\n\t\t\tmode: RefStateMode.Manual;\n\t\t\tref: RefStringOrThunk;\n\t }\n);\n\n/**\n * A ref or a function that returns a ref. If a static ref is known, one can be\n * given. If the ref must be fetched on-demand, a function can be provided. This\n * function can optionally be asynchronous.\n */\ntype RefStringOrThunk =\n\t| string\n\t| (() => string | undefined | Promise<string | undefined>);\n\n/**\n * Configuration for clients that determine how content is queried.\n */\nexport type ClientConfig = {\n\t/**\n\t * The secure token for accessing the Prismic repository. This is only\n\t * required if the repository is set to private.\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * A string representing a version of the Prismic repository's content. This\n\t * may point to the latest version (called the \"master ref\"), or a preview\n\t * with draft content.\n\t */\n\tref?: RefStringOrThunk;\n\n\t/**\n\t * A list of Route Resolver objects that define how a document's `url` field\n\t * is resolved.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\troutes?: NonNullable<BuildQueryURLArgs[\"routes\"]>;\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken Link or Content Relationship fields. A broken\n\t * link is a Link or Content Relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\tbrokenRoute?: NonNullable<BuildQueryURLArgs[\"brokenRoute\"]>;\n\n\t/**\n\t * Default parameters that will be sent with each query. These parameters can\n\t * be overridden on each query if needed.\n\t */\n\tdefaultParams?: Omit<\n\t\tBuildQueryURLArgs,\n\t\t\"ref\" | \"integrationFieldsRef\" | \"accessToken\" | \"routes\" | \"brokenRoute\"\n\t>;\n\n\t/**\n\t * The function used to make network requests to the Prismic REST API. In\n\t * environments where a global `fetch` function does not exist, such as\n\t * Node.js, this function must be provided.\n\t */\n\tfetch?: FetchLike;\n};\n\n/**\n * Parameters for any client method that use `fetch()`. Only a subset of\n * `fetch()` parameters are exposed.\n */\ntype FetchParams = {\n\t/**\n\t * An `AbortSignal` provided by an `AbortController`. This allows the network\n\t * request to be cancelled if necessary.\n\t *\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n\t */\n\tsignal?: AbortSignalLike;\n};\n\n/**\n * Parameters specific to client methods that fetch all documents. These methods\n * start with `getAll` (for example, `getAllByType`).\n */\ntype GetAllParams = {\n\t/**\n\t * Limit the number of documents queried. If a number is not provided, there\n\t * will be no limit and all matching documents will be returned.\n\t */\n\tlimit?: number;\n};\n\n/**\n * Arguments to determine how the URL for a preview session is resolved.\n */\ntype ResolvePreviewArgs<LinkResolverReturnType> = {\n\t/**\n\t * A function that maps a Prismic document to a URL within your app.\n\t */\n\tlinkResolver?: prismicH.LinkResolverFunction<LinkResolverReturnType>;\n\n\t/**\n\t * A fallback URL if the Link Resolver does not return a value.\n\t */\n\tdefaultURL: string;\n\n\t/**\n\t * The preview token (also known as a ref) that will be used to query preview\n\t * content from the Prismic repository.\n\t */\n\tpreviewToken?: string;\n\n\t/**\n\t * The previewed document that will be used to determine the destination URL.\n\t */\n\tdocumentID?: string;\n};\n\n/**\n * Creates a predicate to filter content by document type.\n *\n * @param documentType - The document type to filter queried content.\n *\n * @returns A predicate that can be used in a Prismic REST API V2 request.\n */\nconst typePredicate = (documentType: string): string =>\n\tpredicate.at(\"document.type\", documentType);\n\n/**\n * Creates a predicate to filter content by document tags. All tags are required\n * on the document.\n *\n * @param tags - Document tags to filter queried content.\n *\n * @returns A predicate that can be used in a Prismic REST API V2 request.\n */\nconst everyTagPredicate = (tags: string | string[]): string =>\n\tpredicate.at(\"document.tags\", castArray(tags));\n\n/**\n * Creates a predicate to filter content by document tags. At least one matching\n * tag is required on the document.\n *\n * @param tags - Document tags to filter queried content.\n *\n * @returns A predicate that can be used in a Prismic REST API V2 request.\n */\nconst someTagsPredicate = (tags: string | string[]): string =>\n\tpredicate.any(\"document.tags\", castArray(tags));\n\n/**\n * Type definitions for the `createClient()` function. May be augmented by\n * third-party libraries.\n */\nexport interface CreateClient {\n\t<TDocuments extends prismicT.PrismicDocument>(\n\t\t...args: ConstructorParameters<typeof Client>\n\t): Client<TDocuments>;\n}\n\n/**\n * Creates a Prismic client that can be used to query a repository.\n *\n * @example\n *\n * ```ts\n * // With a repository name.\n * createClient(\"qwerty\");\n *\n * // Or with a full Prismic Rest API V2 endpoint.\n * createClient(\"https://qwerty.cdn.prismic.io/api/v2\");\n * ```\n *\n * @typeParam TDocuments - A map of Prismic document type IDs mapped to their\n * TypeScript type.\n * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest\n * API V2 endpoint for the repository.\n * @param options - Configuration that determines how content will be queried\n * from the Prismic repository.\n *\n * @returns A client that can query content from the repository.\n */\nexport const createClient: CreateClient = <\n\tTDocuments extends prismicT.PrismicDocument,\n>(\n\trepositoryNameOrEndpoint: string,\n\toptions?: ClientConfig,\n) => new Client<TDocuments>(repositoryNameOrEndpoint, options);\n\n/**\n * A client that allows querying content from a Prismic repository.\n *\n * If used in an environment where a global `fetch` function is unavailable,\n * such as Node.js, the `fetch` option must be provided as part of the `options`\n * parameter.\n *\n * @typeParam TDocuments - Document types that are registered for the Prismic\n * repository. Query methods will automatically be typed based on this type.\n */\nexport class Client<\n\tTDocuments extends prismicT.PrismicDocument = prismicT.PrismicDocument,\n> {\n\t/**\n\t * The Prismic REST API V2 endpoint for the repository (use\n\t * `prismic.getRepositoryEndpoint` for the default endpoint).\n\t */\n\tendpoint: string;\n\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * A list of Route Resolver objects that define how a document's `url` field\n\t * is resolved.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\troutes?: NonNullable<BuildQueryURLArgs[\"routes\"]>;\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken Link or Content Relationship fields. A broken\n\t * link is a Link or Content Relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\tbrokenRoute?: NonNullable<BuildQueryURLArgs[\"brokenRoute\"]>;\n\n\t/**\n\t * The function used to make network requests to the Prismic REST API. In\n\t * environments where a global `fetch` function does not exist, such as\n\t * Node.js, this function must be provided.\n\t */\n\tfetchFn: FetchLike;\n\n\t/**\n\t * Default parameters that will be sent with each query. These parameters can\n\t * be overridden on each query if needed.\n\t */\n\tdefaultParams?: Omit<\n\t\tBuildQueryURLArgs,\n\t\t\"ref\" | \"integrationFieldsRef\" | \"accessToken\" | \"routes\"\n\t>;\n\n\t/**\n\t * The client's ref mode state. This determines which ref is used during\n\t * queries.\n\t */\n\tprivate refState: RefState = {\n\t\tmode: RefStateMode.Master,\n\t\tautoPreviewsEnabled: true,\n\t};\n\n\t/**\n\t * Cached repository value.\n\t */\n\tprivate cachedRepository: prismicT.Repository | undefined;\n\n\t/**\n\t * Timestamp at which the cached repository data is considered stale.\n\t */\n\tprivate cachedRepositoryExpiration = 0;\n\n\t/**\n\t * Creates a Prismic client that can be used to query a repository.\n\t *\n\t * If used in an environment where a global `fetch` function is unavailable,\n\t * such as Node.js, the `fetch` option must be provided as part of the\n\t * `options` parameter.\n\t *\n\t * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest\n\t * API V2 endpoint for the repository.\n\t * @param options - Configuration that determines how content will be queried\n\t * from the Prismic repository.\n\t *\n\t * @returns A client that can query content from the repository.\n\t */\n\tconstructor(repositoryNameOrEndpoint: string, options: ClientConfig = {}) {\n\t\tif (isRepositoryEndpoint(repositoryNameOrEndpoint)) {\n\t\t\tif (\n\t\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\t\t/\\.prismic\\.io\\/(?!api\\/v2\\/?)/.test(repositoryNameOrEndpoint)\n\t\t\t) {\n\t\t\t\tthrow new PrismicError(\n\t\t\t\t\t\"@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.\",\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.endpoint = repositoryNameOrEndpoint;\n\t\t} else {\n\t\t\tthis.endpoint = getRepositoryEndpoint(repositoryNameOrEndpoint);\n\t\t}\n\n\t\tthis.accessToken = options.accessToken;\n\t\tthis.routes = options.routes;\n\t\tthis.brokenRoute = options.brokenRoute;\n\t\tthis.defaultParams = options.defaultParams;\n\n\t\tif (options.ref) {\n\t\t\tthis.queryContentFromRef(options.ref);\n\t\t}\n\n\t\tif (typeof options.fetch === \"function\") {\n\t\t\tthis.fetchFn = options.fetch;\n\t\t} else if (typeof globalThis.fetch === \"function\") {\n\t\t\tthis.fetchFn = globalThis.fetch as FetchLike;\n\t\t} else {\n\t\t\tthrow new PrismicError(\n\t\t\t\t\"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.\",\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t}\n\n\t\t// If the global fetch function is used, we must bind it to the global scope.\n\t\tif (this.fetchFn === globalThis.fetch) {\n\t\t\tthis.fetchFn = this.fetchFn.bind(globalThis);\n\t\t}\n\n\t\tthis.graphQLFetch = this.graphQLFetch.bind(this);\n\t}\n\n\t/**\n\t * Enables the client to automatically query content from a preview session if\n\t * one is active in browser environments. This is enabled by default in the\n\t * browser.\n\t *\n\t * For server environments, use `enableAutoPreviewsFromReq`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * client.enableAutoPreviews();\n\t * ```\n\t *\n\t * @see enableAutoPreviewsFromReq\n\t */\n\tenableAutoPreviews(): void {\n\t\tthis.refState.autoPreviewsEnabled = true;\n\t}\n\n\t/**\n\t * Enables the client to automatically query content from a preview session if\n\t * one is active in server environments. This is disabled by default on the\n\t * server.\n\t *\n\t * For browser environments, use `enableAutoPreviews`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // In an express app\n\t * app.get(\"/\", function (req, res) {\n\t * \tclient.enableAutoPreviewsFromReq(req);\n\t * });\n\t * ```\n\t *\n\t * @param req - An HTTP server request object containing the request's\n\t * cookies.\n\t */\n\tenableAutoPreviewsFromReq<R extends HttpRequestLike>(req: R): void {\n\t\tthis.refState.httpRequest = req;\n\t\tthis.refState.autoPreviewsEnabled = true;\n\t}\n\n\t/**\n\t * Disables the client from automatically querying content from a preview\n\t * session if one is active.\n\t *\n\t * Automatic preview content querying is enabled by default unless this method\n\t * is called.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * client.disableAutoPreviews();\n\t * ```\n\t */\n\tdisableAutoPreviews(): void {\n\t\tthis.refState.autoPreviewsEnabled = false;\n\t}\n\n\t/**\n\t * Queries content from the Prismic repository.\n\t *\n\t * @deprecated Use `get` instead.\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.query(\n\t * \tprismic.predicate.at(\"document.type\", \"page\"),\n\t * );\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param params - Parameters to filter, sort, and paginate results.\n\t *\n\t * @returns A paginated response containing the result of the query.\n\t */\n\tasync query<TDocument extends TDocuments>(\n\t\tpredicates: NonNullable<BuildQueryURLArgs[\"predicates\"]>,\n\t\tparams?: Partial<Omit<BuildQueryURLArgs, \"predicates\">> & FetchParams,\n\t): Promise<prismicT.Query<TDocument>> {\n\t\tconst url = await this.buildQueryURL({ ...params, predicates });\n\n\t\treturn await this.fetch<prismicT.Query<TDocument>>(url, params);\n\t}\n\n\t/**\n\t * Queries content from the Prismic repository.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.get();\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param params - Parameters to filter, sort, and paginate results.\n\t *\n\t * @returns A paginated response containing the result of the query.\n\t */\n\tasync get<TDocument extends TDocuments>(\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<TDocument>> {\n\t\tconst url = await this.buildQueryURL(params);\n\n\t\treturn await this.fetch<prismicT.Query<TDocument>>(url, params);\n\t}\n\n\t/**\n\t * Queries content from the Prismic repository and returns only the first\n\t * result, if any.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const document = await client.getFirst();\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of the Prismic document returned.\n\t * @param params - Parameters to filter, sort, and paginate results. @returns\n\t * The first result of the query, if any.\n\t */\n\tasync getFirst<TDocument extends TDocuments>(\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<TDocument> {\n\t\tconst actualParams = { ...params };\n\t\tif (!(params && params.page) && !params?.pageSize) {\n\t\t\tactualParams.pageSize = this.defaultParams?.pageSize ?? 1;\n\t\t}\n\t\tconst url = await this.buildQueryURL(actualParams);\n\t\tconst result = await this.fetch<prismicT.Query<TDocument>>(url, params);\n\n\t\tconst firstResult = result.results[0];\n\n\t\tif (firstResult) {\n\t\t\treturn firstResult;\n\t\t}\n\n\t\tthrow new PrismicError(\"No documents were returned\", url, undefined);\n\t}\n\n\t/**\n\t * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and\n\t * require more resources than other methods. Prefer using other methods that\n\t * filter by predicates such as `getAllByType`.\n\t *\n\t * Queries content from the Prismic repository and returns all matching\n\t * content. If no predicates are provided, all documents will be fetched.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.dangerouslyGetAll();\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param params - Parameters to filter, sort, and paginate results.\n\t *\n\t * @returns A list of documents matching the query.\n\t */\n\tasync dangerouslyGetAll<TDocument extends TDocuments>(\n\t\tparams: Partial<Omit<BuildQueryURLArgs, \"page\">> &\n\t\t\tGetAllParams &\n\t\t\tFetchParams = {},\n\t): Promise<TDocument[]> {\n\t\tconst { limit = Infinity, ...actualParams } = params;\n\t\tconst resolvedParams = {\n\t\t\t...actualParams,\n\t\t\tpageSize: Math.min(\n\t\t\t\tlimit,\n\t\t\t\tactualParams.pageSize || this.defaultParams?.pageSize || MAX_PAGE_SIZE,\n\t\t\t),\n\t\t};\n\n\t\tconst documents: TDocument[] = [];\n\t\tlet latestResult: prismicT.Query<TDocument> | undefined;\n\n\t\twhile (\n\t\t\t(!latestResult || latestResult.next_page) &&\n\t\t\tdocuments.length < limit\n\t\t) {\n\t\t\tconst page = latestResult ? latestResult.page + 1 : undefined;\n\n\t\t\tlatestResult = await this.get<TDocument>({ ...resolvedParams, page });\n\t\t\tdocuments.push(...latestResult.results);\n\n\t\t\tif (latestResult.next_page) {\n\t\t\t\tawait new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));\n\t\t\t}\n\t\t}\n\n\t\treturn documents.slice(0, limit);\n\t}\n\n\t/**\n\t * Queries a document from the Prismic repository with a specific ID.\n\t *\n\t * @remarks\n\t * A document's UID is different from its ID. An ID is automatically generated\n\t * for all documents and is made available on its `id` property. A UID is\n\t * provided in the Prismic editor and is unique among all documents of its\n\t * Custom Type.\n\t * @example\n\t *\n\t * ```ts\n\t * const document = await client.getByID(\"WW4bKScAAMAqmluX\");\n\t * ```\n\t *\n\t * @typeParam TDocument- Type of the Prismic document returned.\n\t * @param id - ID of the document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns The document with an ID matching the `id` parameter, if a matching\n\t * document exists.\n\t */\n\tasync getByID<TDocument extends TDocuments>(\n\t\tid: string,\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<TDocument> {\n\t\treturn await this.getFirst<TDocument>(\n\t\t\tappendPredicates(params, predicate.at(\"document.id\", id)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository with specific IDs.\n\t *\n\t * @remarks\n\t * A document's UID is different from its ID. An ID is automatically generated\n\t * for all documents and is made available on its `id` property. A UID is\n\t * provided in the Prismic editor and is unique among all documents of its\n\t * Custom Type.\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getByIDs([\n\t * \t\"WW4bKScAAMAqmluX\",\n\t * \t\"U1kTRgEAAC8A5ldS\",\n\t * ]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param ids - A list of document IDs.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A paginated response containing documents with IDs matching the\n\t * `ids` parameter.\n\t */\n\tasync getByIDs<TDocument extends TDocuments>(\n\t\tids: string[],\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<TDocument>> {\n\t\treturn await this.get<TDocument>(\n\t\t\tappendPredicates(params, predicate.in(\"document.id\", ids)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries all documents from the Prismic repository with specific IDs.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @remarks\n\t * A document's UID is different from its ID. An ID is automatically generated\n\t * for all documents and is made available on its `id` property. A UID is\n\t * provided in the Prismic editor and is unique among all documents of its\n\t * Custom Type.\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getAllByIDs([\n\t * \t\"WW4bKScAAMAqmluX\",\n\t * \t\"U1kTRgEAAC8A5ldS\",\n\t * ]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param ids - A list of document IDs.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A list of documents with IDs matching the `ids` parameter.\n\t */\n\tasync getAllByIDs<TDocument extends TDocuments>(\n\t\tids: string[],\n\t\tparams?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,\n\t): Promise<TDocument[]> {\n\t\treturn await this.dangerouslyGetAll<TDocument>(\n\t\t\tappendPredicates(params, predicate.in(\"document.id\", ids)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries a document from the Prismic repository with a specific UID and\n\t * Custom Type.\n\t *\n\t * @remarks\n\t * A document's UID is different from its ID. An ID is automatically generated\n\t * for all documents and is made available on its `id` property. A UID is\n\t * provided in the Prismic editor and is unique among all documents of its\n\t * Custom Type.\n\t * @example\n\t *\n\t * ```ts\n\t * const document = await client.getByUID(\"blog_post\", \"my-first-post\");\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of the Prismic document returned.\n\t * @param documentType - The API ID of the document's Custom Type.\n\t * @param uid - UID of the document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns The document with a UID matching the `uid` parameter, if a\n\t * matching document exists.\n\t */\n\tasync getByUID<\n\t\tTDocument extends TDocuments,\n\t\tTDocumentType extends TDocument[\"type\"] = TDocument[\"type\"],\n\t>(\n\t\tdocumentType: TDocumentType,\n\t\tuid: string,\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<ExtractDocumentType<TDocument, TDocumentType>> {\n\t\treturn await this.getFirst<ExtractDocumentType<TDocument, TDocumentType>>(\n\t\t\tappendPredicates(params, [\n\t\t\t\ttypePredicate(documentType),\n\t\t\t\tpredicate.at(`my.${documentType}.uid`, uid),\n\t\t\t]),\n\t\t);\n\t}\n\n\t/**\n\t * Queries document from the Prismic repository with specific UIDs and Custom\n\t * Type.\n\t *\n\t * @remarks\n\t * A document's UID is different from its ID. An ID is automatically generated\n\t * for all documents and is made available on its `id` property. A UID is\n\t * provided in the Prismic editor and is unique among all documents of its\n\t * Custom Type.\n\t * @example\n\t *\n\t * ```ts\n\t * const document = await client.getByUIDs(\"blog_post\", [\n\t * \t\"my-first-post\",\n\t * \t\"my-second-post\",\n\t * ]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of the Prismic document returned.\n\t * @param documentType - The API ID of the document's Custom Type.\n\t * @param uids - A list of document UIDs.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A paginated response containing documents with UIDs matching the\n\t * `uids` parameter.\n\t */\n\tasync getByUIDs<\n\t\tTDocument extends TDocuments,\n\t\tTDocumentType extends TDocument[\"type\"] = TDocument[\"type\"],\n\t>(\n\t\tdocumentType: TDocumentType,\n\t\tuids: string[],\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<ExtractDocumentType<TDocument, TDocumentType>>> {\n\t\treturn await this.get<ExtractDocumentType<TDocument, TDocumentType>>(\n\t\t\tappendPredicates(params, [\n\t\t\t\ttypePredicate(documentType),\n\t\t\t\tpredicate.in(`my.${documentType}.uid`, uids),\n\t\t\t]),\n\t\t);\n\t}\n\n\t/**\n\t * Queries all documents from the Prismic repository with specific UIDs and\n\t * Custom Type.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @remarks\n\t * A document's UID is different from its ID. An ID is automatically generated\n\t * for all documents and is made available on its `id` property. A UID is\n\t * provided in the Prismic editor and is unique among all documents of its\n\t * Custom Type.\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getAllByUIDs([\n\t * \t\"my-first-post\",\n\t * \t\"my-second-post\",\n\t * ]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param documentType - The API ID of the document's Custom Type.\n\t * @param uids - A list of document UIDs.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A list of documents with UIDs matching the `uids` parameter.\n\t */\n\tasync getAllByUIDs<\n\t\tTDocument extends TDocuments,\n\t\tTDocumentType extends TDocument[\"type\"] = TDocument[\"type\"],\n\t>(\n\t\tdocumentType: TDocumentType,\n\t\tuids: string[],\n\t\tparams?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,\n\t): Promise<ExtractDocumentType<TDocument, TDocumentType>[]> {\n\t\treturn await this.dangerouslyGetAll<\n\t\t\tExtractDocumentType<TDocument, TDocumentType>\n\t\t>(\n\t\t\tappendPredicates(params, [\n\t\t\t\ttypePredicate(documentType),\n\t\t\t\tpredicate.in(`my.${documentType}.uid`, uids),\n\t\t\t]),\n\t\t);\n\t}\n\n\t/**\n\t * Queries a singleton document from the Prismic repository for a specific\n\t * Custom Type.\n\t *\n\t * @remarks\n\t * A singleton document is one that is configured in Prismic to only allow one\n\t * instance. For example, a repository may be configured to contain just one\n\t * Settings document. This is in contrast to a repeatable Custom Type which\n\t * allows multiple instances of itself.\n\t * @example\n\t *\n\t * ```ts\n\t * const document = await client.getSingle(\"settings\");\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of the Prismic document returned.\n\t * @param documentType - The API ID of the singleton Custom Type.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns The singleton document for the Custom Type, if a matching document\n\t * exists.\n\t */\n\tasync getSingle<\n\t\tTDocument extends TDocuments,\n\t\tTDocumentType extends TDocument[\"type\"] = TDocument[\"type\"],\n\t>(\n\t\tdocumentType: TDocumentType,\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<ExtractDocumentType<TDocument, TDocumentType>> {\n\t\treturn await this.getFirst<ExtractDocumentType<TDocument, TDocumentType>>(\n\t\t\tappendPredicates(params, typePredicate(documentType)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository for a specific Custom Type.\n\t *\n\t * Use `getAllByType` instead if you need to query all documents for a\n\t * specific Custom Type.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getByType(\"blog_post\");\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param documentType - The API ID of the Custom Type.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A paginated response containing documents of the Custom Type.\n\t */\n\tasync getByType<\n\t\tTDocument extends TDocuments,\n\t\tTDocumentType extends TDocument[\"type\"] = TDocument[\"type\"],\n\t>(\n\t\tdocumentType: TDocumentType,\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<ExtractDocumentType<TDocument, TDocumentType>>> {\n\t\treturn await this.get<ExtractDocumentType<TDocument, TDocumentType>>(\n\t\t\tappendPredicates(params, typePredicate(documentType)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries all documents from the Prismic repository for a specific Custom\n\t * Type.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getByType(\"blog_post\");\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param documentType - The API ID of the Custom Type.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A list of all documents of the Custom Type.\n\t */\n\tasync getAllByType<\n\t\tTDocument extends TDocuments,\n\t\tTDocumentType extends TDocument[\"type\"] = TDocument[\"type\"],\n\t>(\n\t\tdocumentType: TDocumentType,\n\t\tparams?: Partial<Omit<BuildQueryURLArgs, \"page\">> &\n\t\t\tGetAllParams &\n\t\t\tFetchParams,\n\t): Promise<ExtractDocumentType<TDocument, TDocumentType>[]> {\n\t\treturn await this.dangerouslyGetAll<\n\t\t\tExtractDocumentType<TDocument, TDocumentType>\n\t\t>(appendPredicates(params, typePredicate(documentType)));\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository with a specific tag.\n\t *\n\t * Use `getAllByTag` instead if you need to query all documents with a\n\t * specific tag.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getByTag(\"food\");\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param tag - The tag that must be included on a document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A paginated response containing documents with the tag.\n\t */\n\tasync getByTag<TDocument extends TDocuments>(\n\t\ttag: string,\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<TDocument>> {\n\t\treturn await this.get<TDocument>(\n\t\t\tappendPredicates(params, someTagsPredicate(tag)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries all documents from the Prismic repository with a specific tag.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getAllByTag(\"food\");\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param tag - The tag that must be included on a document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A list of all documents with the tag.\n\t */\n\tasync getAllByTag<TDocument extends TDocuments>(\n\t\ttag: string,\n\t\tparams?: Partial<Omit<BuildQueryURLArgs, \"page\">> &\n\t\t\tGetAllParams &\n\t\t\tFetchParams,\n\t): Promise<TDocument[]> {\n\t\treturn await this.dangerouslyGetAll<TDocument>(\n\t\t\tappendPredicates(params, someTagsPredicate(tag)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository with specific tags. A\n\t * document must be tagged with all of the queried tags to be included.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getByEveryTag([\"food\", \"fruit\"]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param tags - A list of tags that must be included on a document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A paginated response containing documents with the tags.\n\t */\n\tasync getByEveryTag<TDocument extends TDocuments>(\n\t\ttags: string[],\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<TDocument>> {\n\t\treturn await this.get<TDocument>(\n\t\t\tappendPredicates(params, everyTagPredicate(tags)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository with specific tags. A\n\t * document must be tagged with all of the queried tags to be included.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getAllByEveryTag([\"food\", \"fruit\"]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param tags - A list of tags that must be included on a document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A list of all documents with the tags.\n\t */\n\tasync getAllByEveryTag<TDocument extends TDocuments>(\n\t\ttags: string[],\n\t\tparams?: Partial<Omit<BuildQueryURLArgs, \"page\">> &\n\t\t\tGetAllParams &\n\t\t\tFetchParams,\n\t): Promise<TDocument[]> {\n\t\treturn await this.dangerouslyGetAll<TDocument>(\n\t\t\tappendPredicates(params, everyTagPredicate(tags)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository with specific tags. A\n\t * document must be tagged with at least one of the queried tags to be\n\t * included.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getByEveryTag([\"food\", \"fruit\"]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param tags - A list of tags that must be included on a document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A paginated response containing documents with at least one of the\n\t * tags.\n\t */\n\tasync getBySomeTags<TDocument extends TDocuments>(\n\t\ttags: string[],\n\t\tparams?: Partial<BuildQueryURLArgs> & FetchParams,\n\t): Promise<prismicT.Query<TDocument>> {\n\t\treturn await this.get<TDocument>(\n\t\t\tappendPredicates(params, someTagsPredicate(tags)),\n\t\t);\n\t}\n\n\t/**\n\t * Queries documents from the Prismic repository with specific tags. A\n\t * document must be tagged with at least one of the queried tags to be\n\t * included.\n\t *\n\t * This method may make multiple network requests to query all matching\n\t * content.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const response = await client.getAllBySomeTags([\"food\", \"fruit\"]);\n\t * ```\n\t *\n\t * @typeParam TDocument - Type of Prismic documents returned.\n\t * @param tags - A list of tags that must be included on a document.\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A list of all documents with at least one of the tags.\n\t */\n\tasync getAllBySomeTags<TDocument extends TDocuments>(\n\t\ttags: string[],\n\t\tparams?: Partial<Omit<BuildQueryURLArgs, \"page\">> &\n\t\t\tGetAllParams &\n\t\t\tFetchParams,\n\t): Promise<TDocument[]> {\n\t\treturn await this.dangerouslyGetAll<TDocument>(\n\t\t\tappendPredicates(params, someTagsPredicate(tags)),\n\t\t);\n\t}\n\n\t/**\n\t * Returns metadata about the Prismic repository, such as its refs, releases,\n\t * and custom types.\n\t *\n\t * @returns Repository metadata.\n\t */\n\tasync getRepository(params?: FetchParams): Promise<prismicT.Repository> {\n\t\t// TODO: Restore when Authorization header support works in browsers with CORS.\n\t\t// return await this.fetch<prismicT.Repository>(this.endpoint);\n\n\t\tconst url = new URL(this.endpoint);\n\n\t\tif (this.accessToken) {\n\t\t\turl.searchParams.set(\"access_token\", this.accessToken);\n\t\t}\n\n\t\treturn await this.fetch<prismicT.Repository>(url.toString(), params);\n\t}\n\n\t/**\n\t * Returns a list of all refs for the Prismic repository.\n\t *\n\t * Refs are used to identify which version of the repository's content should\n\t * be queried. All repositories will have at least one ref pointing to the\n\t * latest published content called the \"master ref\".\n\t *\n\t * @returns A list of all refs for the Prismic repository.\n\t */\n\tasync getRefs(params?: FetchParams): Promise<prismicT.Ref[]> {\n\t\tconst repository = await this.getRepository(params);\n\n\t\treturn repository.refs;\n\t}\n\n\t/**\n\t * Returns a ref for the Prismic repository with a matching ID.\n\t *\n\t * @param id - ID of the ref.\n\t *\n\t * @returns The ref with a matching ID, if it exists.\n\t */\n\tasync getRefByID(id: string, params?: FetchParams): Promise<prismicT.Ref> {\n\t\tconst refs = await this.getRefs(params);\n\n\t\treturn findRefByID(refs, id);\n\t}\n\n\t/**\n\t * Returns a ref for the Prismic repository with a matching label.\n\t *\n\t * @param label - Label of the ref.\n\t *\n\t * @returns The ref with a matching label, if it exists.\n\t */\n\tasync getRefByLabel(\n\t\tlabel: string,\n\t\tparams?: FetchParams,\n\t): Promise<prismicT.Ref> {\n\t\tconst refs = await this.getRefs(params);\n\n\t\treturn findRefByLabel(refs, label);\n\t}\n\n\t/**\n\t * Returns the master ref for the Prismic repository. The master ref points to\n\t * the repository's latest published content.\n\t *\n\t * @returns The repository's master ref.\n\t */\n\tasync getMasterRef(params?: FetchParams): Promise<prismicT.Ref> {\n\t\tconst refs = await this.getRefs(params);\n\n\t\treturn findMasterRef(refs);\n\t}\n\n\t/**\n\t * Returns a list of all Releases for the Prismic repository. Releases are\n\t * used to group content changes before publishing.\n\t *\n\t * @returns A list of all Releases for the Prismic repository.\n\t */\n\tasync getReleases(params?: FetchParams): Promise<prismicT.Ref[]> {\n\t\tconst refs = await this.getRefs(params);\n\n\t\treturn refs.filter((ref) => !ref.isMasterRef);\n\t}\n\n\t/**\n\t * Returns a Release for the Prismic repository with a matching ID.\n\t *\n\t * @param id - ID of the Release.\n\t *\n\t * @returns The Release with a matching ID, if it exists.\n\t */\n\tasync getReleaseByID(\n\t\tid: string,\n\t\tparams?: FetchParams,\n\t): Promise<prismicT.Ref> {\n\t\tconst releases = await this.getReleases(params);\n\n\t\treturn findRefByID(releases, id);\n\t}\n\n\t/**\n\t * Returns a Release for the Prismic repository with a matching label.\n\t *\n\t * @param label - Label of the ref.\n\t *\n\t * @returns The ref with a matching label, if it exists.\n\t */\n\tasync getReleaseByLabel(\n\t\tlabel: string,\n\t\tparams?: FetchParams,\n\t): Promise<prismicT.Ref> {\n\t\tconst releases = await this.getReleases(params);\n\n\t\treturn findRefByLabel(releases, label);\n\t}\n\n\t/**\n\t * Returns a list of all tags used in the Prismic repository.\n\t *\n\t * @returns A list of all tags used in the repository.\n\t */\n\tasync getTags(params?: FetchParams): Promise<string[]> {\n\t\ttry {\n\t\t\tconst tagsForm = await this.getCachedRepositoryForm(\"tags\", params);\n\n\t\t\tconst url = new URL(tagsForm.action);\n\n\t\t\tif (this.accessToken) {\n\t\t\t\turl.searchParams.set(\"access_token\", this.accessToken);\n\t\t\t}\n\n\t\t\treturn await this.fetch<string[]>(url.toString(), params);\n\t\t} catch {\n\t\t\tconst repository = await this.getRepository(params);\n\n\t\t\treturn repository.tags;\n\t\t}\n\t}\n\n\t/**\n\t * Builds a URL used to query content from the Prismic repository.\n\t *\n\t * @param params - Parameters to filter, sort, and paginate the results.\n\t *\n\t * @returns A URL string that can be requested to query content.\n\t */\n\tasync buildQueryURL({\n\t\tsignal,\n\t\t...params\n\t}: Partial<BuildQueryURLArgs> & FetchParams = {}): Promise<string> {\n\t\tconst ref = params.ref || (await this.getResolvedRefString());\n\t\tconst integrationFieldsRef =\n\t\t\tparams.integrationFieldsRef ||\n\t\t\t(await this.getCachedRepository({ signal })).integrationFieldsRef ||\n\t\t\tundefined;\n\n\t\treturn buildQueryURL(this.endpoint, {\n\t\t\t...this.defaultParams,\n\t\t\t...params,\n\t\t\tref,\n\t\t\tintegrationFieldsRef,\n\t\t\troutes: params.routes || this.routes,\n\t\t\tbrokenRoute: params.brokenRoute || this.brokenRoute,\n\t\t\taccessToken: params.accessToken || this.accessToken,\n\t\t});\n\t}\n\n\t/**\n\t * Determines the URL for a previewed document during an active preview\n\t * session. The result of this method should be used to redirect the user to\n\t * the document's URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * \tconst url = client.resolvePreviewURL({\n\t * \tlinkResolver: (document) => `/${document.uid}`\n\t * \tdefaultURL: '/'\n\t * \t})\n\t * ```\n\t *\n\t * @param args - Arguments to configure the URL resolving.\n\t *\n\t * @returns The URL for the previewed document during an active preview\n\t * session. The user should be redirected to this URL.\n\t */\n\tasync resolvePreviewURL<LinkResolverReturnType>(\n\t\targs: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams,\n\t): Promise<string> {\n\t\tlet documentID: string | undefined | null = args.documentID;\n\t\tlet previewToken: string | undefined | null = args.previewToken;\n\n\t\tif (typeof globalThis.location !== \"undefined\") {\n\t\t\tconst searchParams = new URLSearchParams(globalThis.location.search);\n\n\t\t\tdocumentID = documentID || searchParams.get(\"documentId\");\n\t\t\tpreviewToken = previewToken || searchParams.get(\"token\");\n\t\t} else if (this.refState.httpRequest) {\n\t\t\tif (\"query\" in this.refState.httpRequest) {\n\t\t\t\tdocumentID =\n\t\t\t\t\tdocumentID || (this.refState.httpRequest.query?.documentId as string);\n\t\t\t\tpreviewToken =\n\t\t\t\t\tpreviewToken || (this.refState.httpRequest.query?.token as string);\n\t\t\t} else if (\n\t\t\t\t\"url\" in this.refState.httpRequest &&\n\t\t\t\tthis.refState.httpRequest.url\n\t\t\t) {\n\t\t\t\tconst searchParams = new URL(this.refState.httpRequest.url)\n\t\t\t\t\t.searchParams;\n\n\t\t\t\tdocumentID = documentID || searchParams.get(\"documentId\");\n\t\t\t\tpreviewToken = previewToken || searchParams.get(\"token\");\n\t\t\t}\n\t\t}\n\n\t\tif (documentID != null && previewToken != null) {\n\t\t\tconst document = await this.getByID(documentID, {\n\t\t\t\tsignal: args.signal,\n\t\t\t\tref: previewToken,\n\t\t\t\tlang: \"*\",\n\t\t\t});\n\n\t\t\tconst url = prismicH.asLink(document, args.linkResolver);\n\n\t\t\tif (typeof url === \"string\") {\n\t\t\t\treturn url;\n\t\t\t}\n\t\t}\n\n\t\treturn args.defaultURL;\n\t}\n\n\t/**\n\t * Configures the client to query the latest published content for all future\n\t * queries.\n\t *\n\t * If the `ref` parameter is provided during a query, it takes priority for\n\t * that query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * await client.queryLatestContent();\n\t * const document = await client.getByID(\"WW4bKScAAMAqmluX\");\n\t * ```\n\t */\n\tqueryLatestContent(): void {\n\t\tthis.refState.mode = RefStateMode.Master;\n\t}\n\n\t/**\n\t * Configures the client to query content from a specific Release identified\n\t * by its ID for all future queries.\n\t *\n\t * If the `ref` parameter is provided during a query, it takes priority for\n\t * that query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * await client.queryContentFromReleaseByID(\"YLB7OBAAACMA7Cpa\");\n\t * const document = await client.getByID(\"WW4bKScAAMAqmluX\");\n\t * ```\n\t *\n\t * @param releaseID - The ID of the Release.\n\t */\n\tqueryContentFromReleaseByID(releaseID: string): void {\n\t\tthis.refState = {\n\t\t\t...this.refState,\n\t\t\tmode: RefStateMode.ReleaseID,\n\t\t\treleaseID,\n\t\t};\n\t}\n\n\t/**\n\t * Configures the client to query content from a specific Release identified\n\t * by its label for all future queries.\n\t *\n\t * If the `ref` parameter is provided during a query, it takes priority for\n\t * that query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * await client.queryContentFromReleaseByLabel(\"My Release\");\n\t * const document = await client.getByID(\"WW4bKScAAMAqmluX\");\n\t * ```\n\t *\n\t * @param releaseLabel - The label of the Release.\n\t */\n\tqueryContentFromReleaseByLabel(releaseLabel: string): void {\n\t\tthis.refState = {\n\t\t\t...this.refState,\n\t\t\tmode: RefStateMode.ReleaseLabel,\n\t\t\treleaseLabel,\n\t\t};\n\t}\n\n\t/**\n\t * Configures the client to query content from a specific ref. The ref can be\n\t * provided as a string or a function.\n\t *\n\t * If a function is provided, the ref is fetched lazily before each query. The\n\t * function may also be asynchronous.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * await client.queryContentFromRef(\"my-ref\");\n\t * const document = await client.getByID(\"WW4bKScAAMAqmluX\");\n\t * ```\n\t *\n\t * @param ref - The ref or a function that returns the ref from which to query\n\t * content.\n\t */\n\tqueryContentFromRef(ref: RefStringOrThunk): void {\n\t\tthis.refState = {\n\t\t\t...this.refState,\n\t\t\tmode: RefStateMode.Manual,\n\t\t\tref,\n\t\t};\n\t}\n\n\t/**\n\t * @deprecated Renamed to `graphQLFetch()` (note the capitalization of \"QL\").\n\t */\n\t// TODO: Remove in v7\n\tgraphqlFetch = this.graphQLFetch.bind(this);\n\n\t/**\n\t * A `fetch()` function to be used with GraphQL clients configured for\n\t * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`\n\t * and Authorization headers. Queries will automatically be minified by\n\t * removing whitespace where possible.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const graphqlClient = new ApolloClient({\n\t * \tlink: new HttpLink({\n\t * \t\turi: prismic.getGraphQLEndpoint(repositoryName),\n\t * \t\t// Provide `client.graphqlFetch` as the fetch implementation.\n\t * \t\tfetch: client.graphqlFetch,\n\t * \t\t// Using GET is required.\n\t * \t\tuseGETForQueries: true,\n\t * \t}),\n\t * \tcache: new InMemoryCache(),\n\t * });\n\t * ```\n\t *\n\t * @param input - The `fetch()` `input` parameter. Only strings are supported.\n\t * @param init - The `fetch()` `init` parameter. Only plain objects are\n\t * supported.\n\t *\n\t * @returns The `fetch()` Response for the request.\n\t * @experimental\n\t */\n\tasync graphQLFetch(\n\t\tinput: RequestInfo,\n\t\tinit?: Omit<RequestInit, \"signal\"> & { signal?: AbortSignalLike },\n\t): Promise<Response> {\n\t\tconst cachedRepository = await this.getCachedRepository();\n\t\tconst ref = await this.getResolvedRefString();\n\n\t\tconst unsanitizedHeaders: Record<string, string> = {\n\t\t\t\"Prismic-ref\": ref,\n\t\t\tAuthorization: this.accessToken ? `Token ${this.accessToken}` : \"\",\n\t\t\t// Asserting `init.headers` is a Record since popular GraphQL\n\t\t\t// libraries pass this as a Record. Header objects as input\n\t\t\t// are unsupported.\n\t\t\t...(init ? (init.headers as Record<string, string>) : {}),\n\t\t};\n\n\t\tif (cachedRepository.integrationFieldsRef) {\n\t\t\tunsanitizedHeaders[\"Prismic-integration-field-ref\"] =\n\t\t\t\tcachedRepository.integrationFieldsRef;\n\t\t}\n\n\t\t// Normalize header keys to lowercase. This prevents header\n\t\t// conflicts between the Prismic client and the GraphQL\n\t\t// client.\n\t\tconst headers: Record<string, string> = {};\n\t\tfor (const key in unsanitizedHeaders) {\n\t\t\tif (unsanitizedHeaders[key]) {\n\t\t\t\theaders[key.toLowerCase()] =\n\t\t\t\t\tunsanitizedHeaders[key as keyof typeof unsanitizedHeaders];\n\t\t\t}\n\t\t}\n\n\t\tconst url = new URL(\n\t\t\t// Asserting `input` is a string since popular GraphQL\n\t\t\t// libraries pass this as a string. Request objects as\n\t\t\t// input are unsupported.\n\t\t\tinput as string,\n\t\t);\n\n\t\t// This prevents the request from being cached unnecessarily.\n\t\t// Without adding this `ref` param, re-running a query\n\t\t// could return a locally cached response, even if the\n\t\t// `ref` changed. This happens because the URL is\n\t\t// identical when the `ref` is not included. Caches may ignore\n\t\t// headers.\n\t\t//\n\t\t// The Prismic GraphQL API ignores the `ref` param.\n\t\turl.searchParams.set(\"ref\", ref);\n\n\t\tconst query = url.searchParams.get(\"query\");\n\t\tif (query) {\n\t\t\turl.searchParams.set(\n\t\t\t\t\"query\",\n\t\t\t\t// Compress the GraphQL query (if it exists) by\n\t\t\t\t// removing whitespace. This is done to\n\t\t\t\t// optimize the query size and avoid\n\t\t\t\t// hitting the upper limit of GET requests\n\t\t\t\t// (2048 characters).\n\t\t\t\tminifyGraphQLQuery(query),\n\t\t\t);\n\t\t}\n\n\t\treturn (await this.fetchFn(url.toString(), {\n\t\t\t...init,\n\t\t\theaders,\n\t\t})) as Response;\n\t}\n\n\t/**\n\t * Returns a cached version of `getRepository` with a TTL.\n\t *\n\t * @returns Cached repository metadata.\n\t */\n\tprivate async getCachedRepository(\n\t\tparams?: FetchParams,\n\t): Promise<prismicT.Repository> {\n\t\tif (\n\t\t\t!this.cachedRepository ||\n\t\t\tDate.now() >= this.cachedRepositoryExpiration\n\t\t) {\n\t\t\tthis.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;\n\t\t\tthis.cachedRepository = await this.getRepository(params);\n\t\t}\n\n\t\treturn this.cachedRepository;\n\t}\n\n\t/**\n\t * Returns a cached Prismic repository form. Forms are used to determine API\n\t * endpoints for types of repository data.\n\t *\n\t * @param name - Name of the form.\n\t *\n\t * @returns The repository form.\n\t * @throws If a matching form cannot be found.\n\t */\n\tprivate async getCachedRepositoryForm(\n\t\tname: string,\n\t\tparams?: FetchParams,\n\t): Promise<prismicT.Form> {\n\t\tconst cachedRepository = await this.getCachedRepository(params);\n\t\tconst form = cachedRepository.forms[name];\n\n\t\tif (!form) {\n\t\t\tthrow new PrismicError(\n\t\t\t\t`Form with name \"${name}\" could not be found`,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t}\n\n\t\treturn form;\n\t}\n\n\t/**\n\t * Returns the ref needed to query based on the client's current state. This\n\t * method may make a network request to fetch a ref or resolve the user's ref\n\t * thunk.\n\t *\n\t * If auto previews are enabled, the preview ref takes priority if available.\n\t *\n\t * The following strategies are used depending on the client's state:\n\t *\n\t * - If the user called `queryLatestContent`: Use the repository's master ref.\n\t * The ref is cached for 5 seconds. After 5 seconds, a new master ref is\n\t * fetched.\n\t * - If the user called `queryContentFromReleaseByID`: Use the release's ref.\n\t * The ref is cached for 5 seconds. After 5 seconds, a new ref for the\n\t * release is fetched.\n\t * - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.\n\t * The ref is cached for 5 seconds. After 5 seconds, a new ref for the\n\t * release is fetched.\n\t * - If the user called `queryContentFromRef`: Use the provided ref. Fall back\n\t * to the master ref if the ref is not a string.\n\t *\n\t * @returns The ref to use during a query.\n\t */\n\tprivate async getResolvedRefString(params?: FetchParams): Promise<string> {\n\t\tif (this.refState.autoPreviewsEnabled) {\n\t\t\tlet previewRef: string | undefined;\n\n\t\t\tlet cookieJar: string | null | undefined;\n\n\t\t\tif (this.refState.httpRequest?.headers) {\n\t\t\t\tif (\n\t\t\t\t\t\"get\" in this.refState.httpRequest.headers &&\n\t\t\t\t\ttypeof this.refState.httpRequest.headers.get === \"function\"\n\t\t\t\t) {\n\t\t\t\t\t// Web API Headers\n\t\t\t\t\tcookieJar = this.refState.httpRequest.headers.get(\"cookie\");\n\t\t\t\t} else if (\"cookie\" in this.refState.httpRequest.headers) {\n\t\t\t\t\t// Express-style headers\n\t\t\t\t\tcookieJar = this.refState.httpRequest.headers.cookie;\n\t\t\t\t}\n\t\t\t} else if (globalThis.document?.cookie) {\n\t\t\t\tcookieJar = globalThis.document.cookie;\n\t\t\t}\n\n\t\t\tif (cookieJar) {\n\t\t\t\tpreviewRef = getPreviewCookie(cookieJar);\n\t\t\t}\n\n\t\t\tif (previewRef) {\n\t\t\t\treturn previewRef;\n\t\t\t}\n\t\t}\n\n\t\tconst cachedRepository = await this.getCachedRepository(params);\n\n\t\tconst refModeType = this.refState.mode;\n\t\tif (refModeType === RefStateMode.ReleaseID) {\n\t\t\treturn findRefByID(cachedRepository.refs, this.refState.releaseID).ref;\n\t\t} else if (refModeType === RefStateMode.ReleaseLabel) {\n\t\t\treturn findRefByLabel(cachedRepository.refs, this.refState.releaseLabel)\n\t\t\t\t.ref;\n\t\t} else if (refModeType === RefStateMode.Manual) {\n\t\t\tconst res = await castThunk(this.refState.ref)();\n\n\t\t\tif (typeof res === \"string\") {\n\t\t\t\treturn res;\n\t\t\t}\n\t\t}\n\n\t\treturn findMasterRef(cachedRepository.refs).ref;\n\t}\n\n\t/**\n\t * Performs a network request using the configured `fetch` function. It\n\t * assumes all successful responses will have a JSON content type. It also\n\t * normalizes unsuccessful network requests.\n\t *\n\t * @typeParam T - The JSON response.\n\t * @param url - URL to the resource to fetch.\n\t * @param params - Prismic REST API parameters for the network request.\n\t *\n\t * @returns The JSON response from the network request.\n\t */\n\tprivate async fetch<T = unknown>(\n\t\turl: string,\n\t\t// TODO: Change to `params` when Authorization header support works in browsers with CORS.\n\t\t// _params?: Partial<BuildQueryURLArgs>,\n\t\tparams: FetchParams = {},\n\t): Promise<T> {\n\t\t// TODO: Restore when Authorization header support works in browsers with CORS.\n\t\t// const accessToken = (params && params.accessToken) || this.accessToken;\n\t\t// const options = accessToken\n\t\t// \t? { headers: { Authorization: `Token ${accessToken}` } }\n\t\t// \t: {};\n\n\t\tconst res = await this.fetchFn(url, {\n\t\t\tsignal: params.signal,\n\t\t});\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tlet json: any;\n\t\ttry {\n\t\t\t// We can assume Prismic REST API responses will have a `application/json`\n\t\t\t// Content Type. If not, this will throw, signaling an invalid response.\n\t\t\tjson = await res.json();\n\t\t} catch {\n\t\t\t// Not Found (this response has an empty body and throws on `.json()`)\n\t\t\t// - Incorrect repository name\n\t\t\tif (res.status === 404) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\t`Prismic repository not found. Check that \"${this.endpoint}\" is pointing to the correct repository.`,\n\t\t\t\t\turl,\n\t\t\t\t\tundefined,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new PrismicError(undefined, url, undefined);\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\t// Successful\n\t\t\tcase 200: {\n\t\t\t\treturn json;\n\t\t\t}\n\n\t\t\t// Bad Request\n\t\t\t// - Invalid predicate syntax\n\t\t\t// - Ref not provided (ignored)\n\t\t\tcase 400: {\n\t\t\t\tthrow new ParsingError(json.message, url, json);\n\t\t\t}\n\n\t\t\t// Unauthorized\n\t\t\t// - Missing access token for repository endpoint\n\t\t\t// - Incorrect access token for repository endpoint\n\t\t\tcase 401:\n\t\t\t// Forbidden\n\t\t\t// - Missing access token for query endpoint\n\t\t\t// - Incorrect access token for query endpoint\n\t\t\tcase 403: {\n\t\t\t\tthrow new Forbidden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D,KACA,MAAS;AAAA,MAAA,OAEJ;AACN,cAAM,IAAI,aAAa,QAAW,KAAK,MAAS;AAAA,MAChD;AAAA,IACD;AAED,YAAQ,IAAI,QAAQ;AAAA,MAEnB,KAAK,KAAK;AACF,eAAA;AAAA,MACP;AAAA,MAKD,KAAK,KAAK;AACT,cAAM,IAAI,aAAa,KAAK,SAAS,KAAK,IAAI;AAAA,MAC9C;AAAA,MAKD,KAAK;AAAA,MAIL,KAAK,KAAK;AACH,cAAA,IAAI,eACT,WAAW,OAAO,KAAK,QAAQ,KAAK,SACpC,KACA,IAAI;AAAA,MAEL;AAAA,IACD;AAED,UAAM,IAAI,aAAa,QAAW,KAAK,IAAI;AAAA,EAC5C;AACA;"}
|
package/dist/cookie.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.cjs","sources":["../../src/cookie.ts"],"sourcesContent":["/**\n * The well-known name of the cookie used to store a Prismic preview session's\n * ref.\n */\nexport const preview = \"io.prismic.preview\";\n"],"names":[],"mappings":";;AAIO,MAAM,UAAU;;"}
|
package/dist/cookie.d.ts
ADDED
package/dist/cookie.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sources":["../../src/cookie.ts"],"sourcesContent":["/**\n * The well-known name of the cookie used to store a Prismic preview session's\n * ref.\n */\nexport const preview = \"io.prismic.preview\";\n"],"names":[],"mappings":"AAIO,MAAM,UAAU;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const isRepositoryName = require("./isRepositoryName.cjs");
|
|
4
|
+
const PrismicError = require("./PrismicError.cjs");
|
|
5
|
+
const getGraphQLEndpoint = (repositoryName) => {
|
|
6
|
+
if (isRepositoryName.isRepositoryName(repositoryName)) {
|
|
7
|
+
return `https://${repositoryName}.cdn.prismic.io/graphql`;
|
|
8
|
+
} else {
|
|
9
|
+
throw new PrismicError.PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.getGraphQLEndpoint = getGraphQLEndpoint;
|
|
13
|
+
//# sourceMappingURL=getGraphQLEndpoint.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGraphQLEndpoint.cjs","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { isRepositoryName } from \"./isRepositoryName\";\nimport { PrismicError } from \"./PrismicError\";\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const;\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t);\n\t}\n};\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAWa,MAAA,qBAAqB,CACjC,mBACuD;AACnD,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW;AAAA,EAAA,OACZ;AACN,UAAM,IAAIC,aAAAA,aACT,iDAAiD,kBACjD,QACA,MAAS;AAAA,EAEV;AACF;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a repository's Prismic GraphQL endpoint.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam RepositoryName - Name of the Prismic repository.
|
|
5
|
+
* @param repositoryName - Name of the repository.
|
|
6
|
+
*
|
|
7
|
+
* @returns The repository's Prismic REST API V2 endpoint
|
|
8
|
+
*/
|
|
9
|
+
export declare const getGraphQLEndpoint: <RepositoryName extends string>(repositoryName: RepositoryName) => `https://${RepositoryName}.cdn.prismic.io/graphql`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isRepositoryName } from "./isRepositoryName.js";
|
|
2
|
+
import { PrismicError } from "./PrismicError.js";
|
|
3
|
+
const getGraphQLEndpoint = (repositoryName) => {
|
|
4
|
+
if (isRepositoryName(repositoryName)) {
|
|
5
|
+
return `https://${repositoryName}.cdn.prismic.io/graphql`;
|
|
6
|
+
} else {
|
|
7
|
+
throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
getGraphQLEndpoint
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=getGraphQLEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGraphQLEndpoint.js","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { isRepositoryName } from \"./isRepositoryName\";\nimport { PrismicError } from \"./PrismicError\";\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const;\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t);\n\t}\n};\n"],"names":[],"mappings":";;AAWa,MAAA,qBAAqB,CACjC,mBACuD;AACnD,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW;AAAA,EAAA,OACZ;AACN,UAAM,IAAI,aACT,iDAAiD,kBACjD,QACA,MAAS;AAAA,EAEV;AACF;"}
|