@prismicio/client 6.4.3 → 6.6.0
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/index.cjs +32 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +85 -29
- package/dist/index.js +32 -14
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/client.ts +135 -61
- package/src/index.ts +1 -1
- package/src/lib/getCookie.ts +4 -4
- package/src/predicate.ts +4 -2
- package/src/types.ts +62 -6
package/dist/index.cjs
CHANGED
|
@@ -155,7 +155,7 @@ const parse = (cookieString) => {
|
|
|
155
155
|
return result;
|
|
156
156
|
};
|
|
157
157
|
const getAll = (cookieStore) => parse(cookieStore);
|
|
158
|
-
const getCookie = (name,
|
|
158
|
+
const getCookie = (name, cookieJar) => getAll(cookieJar)[name];
|
|
159
159
|
|
|
160
160
|
const minifyGraphQLQuery = (query) => {
|
|
161
161
|
return query.replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
|
|
@@ -248,7 +248,7 @@ const GET_ALL_QUERY_DELAY = 500;
|
|
|
248
248
|
const typePredicate = (documentType) => predicate.at("document.type", documentType);
|
|
249
249
|
const everyTagPredicate = (tags) => predicate.at("document.tags", castArray(tags));
|
|
250
250
|
const someTagsPredicate = (tags) => predicate.any("document.tags", castArray(tags));
|
|
251
|
-
const createClient = (
|
|
251
|
+
const createClient = (repositoryNameOrEndpoint, options) => new Client(repositoryNameOrEndpoint, options);
|
|
252
252
|
class Client {
|
|
253
253
|
constructor(repositoryNameOrEndpoint, options = {}) {
|
|
254
254
|
this.refState = {
|
|
@@ -421,7 +421,11 @@ class Client {
|
|
|
421
421
|
async getTags(params) {
|
|
422
422
|
try {
|
|
423
423
|
const tagsForm = await this.getCachedRepositoryForm("tags", params);
|
|
424
|
-
|
|
424
|
+
const url = new URL(tagsForm.action);
|
|
425
|
+
if (this.accessToken) {
|
|
426
|
+
url.searchParams.set("access_token", this.accessToken);
|
|
427
|
+
}
|
|
428
|
+
return await this.fetch(url.toString(), params);
|
|
425
429
|
} catch (e) {
|
|
426
430
|
const repository = await this.getRepository(params);
|
|
427
431
|
return repository.tags;
|
|
@@ -443,16 +447,22 @@ class Client {
|
|
|
443
447
|
});
|
|
444
448
|
}
|
|
445
449
|
async resolvePreviewURL(args) {
|
|
446
|
-
var _a;
|
|
450
|
+
var _a, _b;
|
|
447
451
|
let documentID = args.documentID;
|
|
448
452
|
let previewToken = args.previewToken;
|
|
449
453
|
if (typeof globalThis.location !== "undefined") {
|
|
450
454
|
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
451
|
-
documentID = documentID || searchParams.get("documentId")
|
|
452
|
-
previewToken = previewToken || searchParams.get("token")
|
|
453
|
-
} else if (
|
|
454
|
-
|
|
455
|
-
|
|
455
|
+
documentID = documentID || searchParams.get("documentId");
|
|
456
|
+
previewToken = previewToken || searchParams.get("token");
|
|
457
|
+
} else if (this.refState.httpRequest) {
|
|
458
|
+
if ("query" in this.refState.httpRequest) {
|
|
459
|
+
documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
|
|
460
|
+
previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
|
|
461
|
+
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
462
|
+
const searchParams = new URL(this.refState.httpRequest.url).searchParams;
|
|
463
|
+
documentID = documentID || searchParams.get("documentId");
|
|
464
|
+
previewToken = previewToken || searchParams.get("token");
|
|
465
|
+
}
|
|
456
466
|
}
|
|
457
467
|
if (documentID != null && previewToken != null) {
|
|
458
468
|
const document = await this.getByID(documentID, {
|
|
@@ -533,13 +543,21 @@ class Client {
|
|
|
533
543
|
return form;
|
|
534
544
|
}
|
|
535
545
|
async getResolvedRefString(params) {
|
|
536
|
-
var _a, _b
|
|
546
|
+
var _a, _b;
|
|
537
547
|
if (this.refState.autoPreviewsEnabled) {
|
|
538
|
-
let previewRef
|
|
548
|
+
let previewRef;
|
|
549
|
+
let cookieJar;
|
|
539
550
|
if ((_a = globalThis.document) == null ? void 0 : _a.cookie) {
|
|
540
|
-
|
|
541
|
-
} else if ((
|
|
542
|
-
|
|
551
|
+
cookieJar = globalThis.document.cookie;
|
|
552
|
+
} else if ((_b = this.refState.httpRequest) == null ? void 0 : _b.headers) {
|
|
553
|
+
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
554
|
+
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
555
|
+
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
556
|
+
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (cookieJar) {
|
|
560
|
+
previewRef = getCookie(preview, cookieJar);
|
|
543
561
|
}
|
|
544
562
|
if (previewRef) {
|
|
545
563
|
return previewRef;
|