@prismicio/e2e-tests-utils 1.3.2 → 1.4.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/README.md +16 -9
- package/dist/clients/apiClient.cjs +39 -0
- package/dist/clients/apiClient.cjs.map +1 -0
- package/dist/clients/apiClient.d.ts +30 -0
- package/dist/clients/apiClient.js +39 -0
- package/dist/clients/apiClient.js.map +1 -0
- package/dist/clients/authenticationApi.cjs +54 -34
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.ts +13 -5
- package/dist/clients/authenticationApi.js +55 -35
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +12 -48
- package/dist/clients/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.d.ts +5 -6
- package/dist/clients/contentApi.js +12 -48
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +36 -31
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +21 -3
- package/dist/clients/coreApi.js +37 -32
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +48 -42
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.d.ts +34 -6
- package/dist/clients/customTypesApi.js +49 -43
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/migrationApi.cjs +30 -29
- package/dist/clients/migrationApi.cjs.map +1 -1
- package/dist/clients/migrationApi.d.ts +25 -5
- package/dist/clients/migrationApi.js +31 -30
- package/dist/clients/migrationApi.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/managers/repositories.cjs +19 -9
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.ts +2 -2
- package/dist/managers/repositories.js +23 -13
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +5 -0
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +6 -4
- package/dist/managers/repository.js +5 -0
- package/dist/managers/repository.js.map +1 -1
- package/dist/utils/log.cjs +4 -0
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.d.ts +2 -0
- package/dist/utils/log.js +4 -0
- package/dist/utils/log.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/apiClient.ts +48 -0
- package/src/clients/authenticationApi.ts +52 -50
- package/src/clients/contentApi.ts +18 -24
- package/src/clients/coreApi.ts +36 -42
- package/src/clients/customTypesApi.ts +34 -59
- package/src/clients/migrationApi.ts +33 -45
- package/src/managers/repositories.ts +26 -20
- package/src/managers/repository.ts +17 -7
- package/src/utils/log.ts +11 -0
|
@@ -4,31 +4,8 @@ var __publicField = (obj, key, value) => {
|
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
throw TypeError("Cannot " + msg);
|
|
10
|
-
};
|
|
11
|
-
var __privateGet = (obj, member, getter) => {
|
|
12
|
-
__accessCheck(obj, member, "read from private field");
|
|
13
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
14
|
-
};
|
|
15
|
-
var __privateAdd = (obj, member, value) => {
|
|
16
|
-
if (member.has(obj))
|
|
17
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
18
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
-
};
|
|
20
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
21
|
-
__accessCheck(obj, member, "write to private field");
|
|
22
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
23
|
-
return value;
|
|
24
|
-
};
|
|
25
|
-
var __privateMethod = (obj, member, method) => {
|
|
26
|
-
__accessCheck(obj, member, "access private method");
|
|
27
|
-
return method;
|
|
28
|
-
};
|
|
29
|
-
var _version, _accessToken, _context, context_fn;
|
|
30
|
-
import { request } from "@playwright/test";
|
|
31
|
-
class ContentApiClient {
|
|
7
|
+
import { AuthenticatedApiClient } from "./apiClient.js";
|
|
8
|
+
class ContentApiClient extends AuthenticatedApiClient {
|
|
32
9
|
/**
|
|
33
10
|
* @example To instantiate the class:
|
|
34
11
|
*
|
|
@@ -47,18 +24,16 @@ class ContentApiClient {
|
|
|
47
24
|
* https://prismic.io/docs/access-token
|
|
48
25
|
*/
|
|
49
26
|
constructor(baseURL, config = {}) {
|
|
50
|
-
|
|
51
|
-
__publicField(this, "
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
__privateSet(this, _version, config.version || "v2");
|
|
56
|
-
__privateSet(this, _accessToken, config.accessToken);
|
|
27
|
+
super(baseURL, "");
|
|
28
|
+
__publicField(this, "version");
|
|
29
|
+
__publicField(this, "accessToken");
|
|
30
|
+
this.version = config.version || "v2";
|
|
31
|
+
this.accessToken = config.accessToken;
|
|
57
32
|
}
|
|
58
33
|
async get(path, params, headers) {
|
|
59
|
-
const context = await
|
|
34
|
+
const context = await this.getContext();
|
|
60
35
|
const securityParams = {
|
|
61
|
-
...
|
|
36
|
+
...this.accessToken ? { access_token: this.accessToken } : {}
|
|
62
37
|
};
|
|
63
38
|
return context.get(path, {
|
|
64
39
|
params: { ...securityParams, ...params },
|
|
@@ -71,10 +46,10 @@ class ContentApiClient {
|
|
|
71
46
|
}
|
|
72
47
|
/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
|
|
73
48
|
async graphql(ref, query) {
|
|
74
|
-
return this.getAsJson("
|
|
49
|
+
return this.getAsJson("graphql", { query }, { "Prismic-ref": ref });
|
|
75
50
|
}
|
|
76
51
|
async getRefs() {
|
|
77
|
-
const data = await this.getAsJson(
|
|
52
|
+
const data = await this.getAsJson(`api/${this.version}`);
|
|
78
53
|
return data.refs;
|
|
79
54
|
}
|
|
80
55
|
async getMasterRef() {
|
|
@@ -99,7 +74,7 @@ class ContentApiClient {
|
|
|
99
74
|
if (!ref) {
|
|
100
75
|
ref = await this.getMasterRef();
|
|
101
76
|
}
|
|
102
|
-
return this.getAsJson(
|
|
77
|
+
return this.getAsJson(`api/${this.version}/documents/search`, {
|
|
103
78
|
...filters,
|
|
104
79
|
ref
|
|
105
80
|
});
|
|
@@ -124,17 +99,6 @@ class ContentApiClient {
|
|
|
124
99
|
}
|
|
125
100
|
}
|
|
126
101
|
}
|
|
127
|
-
_version = new WeakMap();
|
|
128
|
-
_accessToken = new WeakMap();
|
|
129
|
-
_context = new WeakSet();
|
|
130
|
-
context_fn = function() {
|
|
131
|
-
return request.newContext({
|
|
132
|
-
baseURL: this.baseURL,
|
|
133
|
-
// reset any Authorization header set globally with Playwright
|
|
134
|
-
// didn't find a way to delete it
|
|
135
|
-
extraHTTPHeaders: { Authorization: "" }
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
102
|
export {
|
|
139
103
|
ContentApiClient
|
|
140
104
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentApi.js","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse
|
|
1
|
+
{"version":3,"file":"contentApi.js","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse } from \"@playwright/test\";\n\nimport { AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface ContentApiError {\n\ttype: string;\n\tmessage: string;\n}\nexport interface ContentApiSearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: ContentApiDocument[];\n}\n\nexport interface ContentApiDocument {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface ContentApiGraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface ContentApiRef {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\ninterface ContentApiRepoConfigResponse {\n\trefs: ContentApiRef[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\ntype SearchQueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient extends AuthenticatedApiClient {\n\tprivate version: ApiVersions;\n\tprivate accessToken: string | undefined;\n\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new ContentApiClient(\"https://my-repo.cdn.prismic.io\", {\n\t * \tversion: \"v2\",\n\t * \taccessToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\t// Use an empty string as auth header in case it is already set globally in the project Playwright config file.\n\t\t// This is because the api returns an error whenever an auth header is present in the content api request.\n\t\tsuper(baseURL, \"\");\n\t\tthis.version = config.version || \"v2\";\n\t\tthis.accessToken = config.accessToken;\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst securityParams = {\n\t\t\t...(this.accessToken ? { access_token: this.accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(\n\t\tref: string,\n\t\tquery: string,\n\t): Promise<ContentApiGraphQLResponse> {\n\t\treturn this.getAsJson<ContentApiGraphQLResponse>(\n\t\t\t\"graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<ContentApiRef[]> {\n\t\tconst data = await this.getAsJson<ContentApiRepoConfigResponse>(\n\t\t\t`api/${this.version}`,\n\t\t);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<ContentApiSearchResponse>(\n\t\t\t`api/${this.version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiSearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiDocument | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;AAuFM,MAAO,yBAAyB,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB3D,YACC,SACA,SAA0D,IAAE;AAI5D,UAAM,SAAS,EAAE;AA1BV;AACA;AA0BF,SAAA,UAAU,OAAO,WAAW;AACjC,SAAK,cAAc,OAAO;AAAA,EAC3B;AAAA,EAEA,MAAM,IACL,MACA,QACA,SAAgC;AAE1B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,iBAAiB;AAAA,MACtB,GAAI,KAAK,cAAc,EAAE,cAAc,KAAK,YAAA,IAAgB;;AAGtD,WAAA,QAAQ,IAAI,MAAM;AAAA,MACxB,QAAQ,EAAE,GAAG,gBAAgB,GAAG,OAAQ;AAAA,MACxC;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEA,MAAM,UACL,KACA,QACA,SAAgC;AAEhC,UAAM,WAAW,MAAM,KAAK,IAAI,KAAK,QAAQ,OAAO;AAEpD,WAAO,SAAS;EACjB;AAAA;AAAA,EAGA,MAAM,QACL,KACA,OAAa;AAEN,WAAA,KAAK,UACX,WACA,EAAE,SACF,EAAE,eAAe,IAAA,CAAK;AAAA,EAExB;AAAA,EAEA,MAAM,UAAO;AACZ,UAAM,OAAO,MAAM,KAAK,UACvB,OAAO,KAAK,OAAO,EAAE;AAGtB,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,eAAY;AACX,UAAA,OAAO,MAAM,KAAK;AAElB,UAAA,YAAY,KAAK,KAAK,CAAC,EAAE,kBAAkB,gBAAgB,IAAI;AACrE,QAAI,CAAC,WAAW;AACT,YAAA;AAAA,IACP;AAEA,WAAO,UAAU;AAAA,EAClB;AAAA,EAEA,MAAM,kBAAkB,WAAiB;AAClC,UAAA,OAAO,MAAM,KAAK;AAClB,UAAA,UAAU,KAAK,KAAK,CAAC,EAAE,SAAS,OAAO,SAAS;AACtD,QAAI,CAAC,SAAS;AACb,YAAM,4BAA4B,SAAS;AAAA,IAC5C;AAEA,WAAO,QAAQ;AAAA,EAChB;AAAA;AAAA,EAGA,MAAM,OAAO,SAA2B;AACvC,QAAI,MAAM,mCAAS;AACnB,QAAI,CAAC,KAAK;AACH,YAAA,MAAM,KAAK;IAClB;AAEA,WAAO,KAAK,UACX,OAAO,KAAK,OAAO,qBACnB;AAAA,MACC,GAAG;AAAA,MACH;AAAA,IAAA,CACA;AAAA,EAEH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WACL,IACA,SAA2B;AAEpB,WAAA,KAAK,OAAO,EAAE,GAAG,SAAS,GAAG,sBAAsB,EAAE,OAAA,CAAQ;AAAA,EACrE;AAAA;AAAA,EAGA,MAAM,gBACL,IACA,SAA2B;AAE3B,UAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO;AAC9C,YAAQ,KAAK,cAAc;AAAA,MAC1B,KAAK;AACJ;AAAA,MACD,KAAK;AACG,eAAA,KAAK,QAAQ,CAAC;AAAA,MACtB;AACC,cAAM,IAAI,MAAM,gDAAgD,EAAE,EAAE;AAAA,IACtE;AAAA,EACD;AACA;"}
|
package/dist/clients/coreApi.cjs
CHANGED
|
@@ -1,44 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const axios = require("axios");
|
|
4
3
|
const log = require("../utils/log.cjs");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const apiClient = require("./apiClient.cjs");
|
|
5
|
+
class CoreApiClient extends apiClient.AuthenticatedApiClient {
|
|
6
|
+
/**
|
|
7
|
+
* @example To instantiate the class:
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* new CoreApiClient("https://my-repo.prismic.io", {
|
|
11
|
+
* authToken: "my-secret-token",
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param baseURL - the api base URL like https://my-repo.prismic.io
|
|
16
|
+
* @param config - Optional configuration
|
|
17
|
+
*
|
|
18
|
+
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
19
|
+
* function to fetch it when it's needed.
|
|
20
|
+
*/
|
|
21
|
+
constructor(baseURL, config) {
|
|
22
|
+
super(baseURL, config);
|
|
23
|
+
}
|
|
24
|
+
async getLanguages() {
|
|
20
25
|
const profiler = log.logger.startTimer();
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const context = await this.getContext();
|
|
27
|
+
const result = await context.get("core/repository");
|
|
28
|
+
if (200 !== result.status() || !(await result.json()).languages) {
|
|
29
|
+
await log.logPlaywrightApiResponse(result);
|
|
24
30
|
throw new Error("Could not get languages from the core api.");
|
|
25
31
|
}
|
|
26
32
|
profiler.done({ message: "retrieved languages configuration" });
|
|
27
|
-
return result.
|
|
33
|
+
return (await result.json()).languages;
|
|
28
34
|
}
|
|
29
|
-
async
|
|
30
|
-
const
|
|
31
|
-
|
|
35
|
+
async publishDraft(documentId) {
|
|
36
|
+
const context = await this.getContext();
|
|
37
|
+
const result = await context.patch(`core/documents/${documentId}/draft`, {
|
|
38
|
+
data: {
|
|
39
|
+
status: "published"
|
|
40
|
+
}
|
|
32
41
|
});
|
|
33
|
-
if (204 !== result.status) {
|
|
34
|
-
log.
|
|
42
|
+
if (204 !== result.status()) {
|
|
43
|
+
await log.logPlaywrightApiResponse(result);
|
|
35
44
|
throw new Error(`Could not publish document with id ${documentId}`);
|
|
36
45
|
}
|
|
37
46
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
publishDraft
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
exports.createCoreApiClient = createCoreApiClient;
|
|
47
|
+
}
|
|
48
|
+
exports.CoreApiClient = CoreApiClient;
|
|
44
49
|
//# sourceMappingURL=coreApi.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreApi.cjs","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"coreApi.cjs","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype Language = {\n\tid: string;\n\tname: string;\n\tis_master: boolean;\n};\n\nexport type CoreClient = {\n\tgetLanguages(): Promise<Language[]>;\n\tpublishDraft(documentId: string): Promise<void>;\n};\n\nexport class CoreApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new CoreApiClient(\"https://my-repo.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.authToken}: Api token generated from the auth service or a\n\t * function to fetch it when it's needed.\n\t */\n\tconstructor(baseURL: string, config: AuthServerToken) {\n\t\tsuper(baseURL, config);\n\t}\n\n\tasync getLanguages(): Promise<Language[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"core/repository\");\n\n\t\tif (200 !== result.status() || !(await result.json()).languages) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get languages from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved languages configuration\" });\n\n\t\treturn (await result.json()).languages;\n\t}\n\n\tasync publishDraft(documentId: string): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.patch(`core/documents/${documentId}/draft`, {\n\t\t\tdata: {\n\t\t\t\tstatus: \"published\",\n\t\t\t},\n\t\t});\n\n\t\tif (204 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not publish document with id ${documentId}`);\n\t\t}\n\t}\n}\n"],"names":["AuthenticatedApiClient","logger","logPlaywrightApiResponse"],"mappings":";;;;AAeM,MAAO,sBAAsBA,UAAAA,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBxD,YAAY,SAAiB,QAAuB;AACnD,UAAM,SAAS,MAAM;AAAA,EACtB;AAAA,EAEA,MAAM,eAAY;AACX,UAAA,WAAWC,WAAO;AAClB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,iBAAiB;AAE9C,QAAA,QAAQ,OAAO,OAAM,KAAM,EAAE,MAAM,OAAO,KAAI,GAAI,WAAW;AAChE,YAAMC,IAAAA,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,4CAA4C;AAAA,IAC7D;AAEA,aAAS,KAAK,EAAE,SAAS,oCAAqC,CAAA;AAEtD,YAAA,MAAM,OAAO,KAAA,GAAQ;AAAA,EAC9B;AAAA,EAEA,MAAM,aAAa,YAAkB;AAC9B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,MAAM,kBAAkB,UAAU,UAAU;AAAA,MACxE,MAAM;AAAA,QACL,QAAQ;AAAA,MACR;AAAA,IAAA,CACD;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAMA,IAAAA,yBAAyB,MAAM;AACrC,YAAM,IAAI,MAAM,sCAAsC,UAAU,EAAE;AAAA,IACnE;AAAA,EACD;AACA;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
|
|
2
2
|
type Language = {
|
|
3
3
|
id: string;
|
|
4
4
|
name: string;
|
|
@@ -8,6 +8,24 @@ export type CoreClient = {
|
|
|
8
8
|
getLanguages(): Promise<Language[]>;
|
|
9
9
|
publishDraft(documentId: string): Promise<void>;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export declare class CoreApiClient extends AuthenticatedApiClient {
|
|
12
|
+
/**
|
|
13
|
+
* @example To instantiate the class:
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* new CoreApiClient("https://my-repo.prismic.io", {
|
|
17
|
+
* authToken: "my-secret-token",
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param baseURL - the api base URL like https://my-repo.prismic.io
|
|
22
|
+
* @param config - Optional configuration
|
|
23
|
+
*
|
|
24
|
+
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
25
|
+
* function to fetch it when it's needed.
|
|
26
|
+
*/
|
|
27
|
+
constructor(baseURL: string, config: AuthServerToken);
|
|
28
|
+
getLanguages(): Promise<Language[]>;
|
|
29
|
+
publishDraft(documentId: string): Promise<void>;
|
|
30
|
+
}
|
|
13
31
|
export {};
|
package/dist/clients/coreApi.js
CHANGED
|
@@ -1,44 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { logger, logPlaywrightApiResponse } from "../utils/log.js";
|
|
2
|
+
import { AuthenticatedApiClient } from "./apiClient.js";
|
|
3
|
+
class CoreApiClient extends AuthenticatedApiClient {
|
|
4
|
+
/**
|
|
5
|
+
* @example To instantiate the class:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* new CoreApiClient("https://my-repo.prismic.io", {
|
|
9
|
+
* authToken: "my-secret-token",
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param baseURL - the api base URL like https://my-repo.prismic.io
|
|
14
|
+
* @param config - Optional configuration
|
|
15
|
+
*
|
|
16
|
+
* - {@link config.authToken}: Api token generated from the auth service or a
|
|
17
|
+
* function to fetch it when it's needed.
|
|
18
|
+
*/
|
|
19
|
+
constructor(baseURL, config) {
|
|
20
|
+
super(baseURL, config);
|
|
21
|
+
}
|
|
22
|
+
async getLanguages() {
|
|
18
23
|
const profiler = logger.startTimer();
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
const context = await this.getContext();
|
|
25
|
+
const result = await context.get("core/repository");
|
|
26
|
+
if (200 !== result.status() || !(await result.json()).languages) {
|
|
27
|
+
await logPlaywrightApiResponse(result);
|
|
22
28
|
throw new Error("Could not get languages from the core api.");
|
|
23
29
|
}
|
|
24
30
|
profiler.done({ message: "retrieved languages configuration" });
|
|
25
|
-
return result.
|
|
31
|
+
return (await result.json()).languages;
|
|
26
32
|
}
|
|
27
|
-
async
|
|
28
|
-
const
|
|
29
|
-
|
|
33
|
+
async publishDraft(documentId) {
|
|
34
|
+
const context = await this.getContext();
|
|
35
|
+
const result = await context.patch(`core/documents/${documentId}/draft`, {
|
|
36
|
+
data: {
|
|
37
|
+
status: "published"
|
|
38
|
+
}
|
|
30
39
|
});
|
|
31
|
-
if (204 !== result.status) {
|
|
32
|
-
|
|
40
|
+
if (204 !== result.status()) {
|
|
41
|
+
await logPlaywrightApiResponse(result);
|
|
33
42
|
throw new Error(`Could not publish document with id ${documentId}`);
|
|
34
43
|
}
|
|
35
44
|
}
|
|
36
|
-
|
|
37
|
-
getLanguages,
|
|
38
|
-
publishDraft
|
|
39
|
-
};
|
|
40
|
-
};
|
|
45
|
+
}
|
|
41
46
|
export {
|
|
42
|
-
|
|
47
|
+
CoreApiClient
|
|
43
48
|
};
|
|
44
49
|
//# sourceMappingURL=coreApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreApi.js","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"coreApi.js","sources":["../../../src/clients/coreApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype Language = {\n\tid: string;\n\tname: string;\n\tis_master: boolean;\n};\n\nexport type CoreClient = {\n\tgetLanguages(): Promise<Language[]>;\n\tpublishDraft(documentId: string): Promise<void>;\n};\n\nexport class CoreApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new CoreApiClient(\"https://my-repo.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.authToken}: Api token generated from the auth service or a\n\t * function to fetch it when it's needed.\n\t */\n\tconstructor(baseURL: string, config: AuthServerToken) {\n\t\tsuper(baseURL, config);\n\t}\n\n\tasync getLanguages(): Promise<Language[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"core/repository\");\n\n\t\tif (200 !== result.status() || !(await result.json()).languages) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get languages from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved languages configuration\" });\n\n\t\treturn (await result.json()).languages;\n\t}\n\n\tasync publishDraft(documentId: string): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.patch(`core/documents/${documentId}/draft`, {\n\t\t\tdata: {\n\t\t\t\tstatus: \"published\",\n\t\t\t},\n\t\t});\n\n\t\tif (204 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not publish document with id ${documentId}`);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAeM,MAAO,sBAAsB,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBxD,YAAY,SAAiB,QAAuB;AACnD,UAAM,SAAS,MAAM;AAAA,EACtB;AAAA,EAEA,MAAM,eAAY;AACX,UAAA,WAAW,OAAO;AAClB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,iBAAiB;AAE9C,QAAA,QAAQ,OAAO,OAAM,KAAM,EAAE,MAAM,OAAO,KAAI,GAAI,WAAW;AAChE,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,4CAA4C;AAAA,IAC7D;AAEA,aAAS,KAAK,EAAE,SAAS,oCAAqC,CAAA;AAEtD,YAAA,MAAM,OAAO,KAAA,GAAQ;AAAA,EAC9B;AAAA,EAEA,MAAM,aAAa,YAAkB;AAC9B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,MAAM,kBAAkB,UAAU,UAAU;AAAA,MACxE,MAAM;AAAA,QACL,QAAQ;AAAA,MACR;AAAA,IAAA,CACD;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AACrC,YAAM,IAAI,MAAM,sCAAsC,UAAU,EAAE;AAAA,IACnE;AAAA,EACD;AACA;"}
|
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const axios = require("axios");
|
|
4
3
|
const isEqual = require("lodash.isequal");
|
|
5
4
|
const log = require("../utils/log.cjs");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
async function upsert(endpoint, operation, data) {
|
|
5
|
+
const apiClient = require("./apiClient.cjs");
|
|
6
|
+
class CustomTypesApiClient extends apiClient.AuthenticatedApiClient {
|
|
7
|
+
constructor(baseURL, config) {
|
|
8
|
+
super(baseURL, config.authToken, { repository: config.repository });
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create or update a custom type or slice.
|
|
12
|
+
*
|
|
13
|
+
* @param endpoint - - The API endpoint for custom types or slices
|
|
14
|
+
* ('customtypes' or 'slices').
|
|
15
|
+
* @param data - - The data representing the custom type or slice.
|
|
16
|
+
*
|
|
17
|
+
* @throws Error if the item status cannot be retrieved or the item cannot be
|
|
18
|
+
* created/updated.
|
|
19
|
+
*/
|
|
20
|
+
async upsert(endpoint, operation, data) {
|
|
24
21
|
const profiler = log.logger.startTimer();
|
|
25
22
|
const path = `${endpoint}/${operation}`;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const context = await this.getContext();
|
|
24
|
+
const result = await context.post(path, { data });
|
|
25
|
+
if (!result.ok()) {
|
|
26
|
+
log.logPlaywrightApiResponse(result);
|
|
29
27
|
throw new Error(`Could not ${operation} item`);
|
|
30
28
|
}
|
|
31
29
|
profiler.done({
|
|
32
30
|
message: `called customtypes api /${path} for item with id '${data.id}'`
|
|
33
31
|
});
|
|
34
32
|
}
|
|
35
|
-
async
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
async getRemoteItems(endpoint) {
|
|
34
|
+
const context = await this.getContext();
|
|
35
|
+
const result = await context.get(endpoint);
|
|
36
|
+
if (!result.ok()) {
|
|
37
|
+
log.logPlaywrightApiResponse(result);
|
|
39
38
|
throw new Error("Could not get items status from the Custom Type api.");
|
|
40
39
|
}
|
|
41
|
-
return result.
|
|
40
|
+
return result.json();
|
|
42
41
|
}
|
|
43
|
-
async
|
|
42
|
+
async getDifference(remoteItems, local) {
|
|
44
43
|
const remoteItem = remoteItems.find((remote) => remote.id === local.id);
|
|
45
44
|
if (!remoteItem) {
|
|
46
45
|
return "insert";
|
|
@@ -50,23 +49,30 @@ const createCustomTypesApiClient = (baseURL, repository, authClient) => {
|
|
|
50
49
|
}
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
/** Create items only if they have changed compared to their remote status */
|
|
53
|
+
async upsertIfChanged(itemType, localItems = []) {
|
|
54
|
+
const remoteItems = await this.getRemoteItems(itemType);
|
|
55
55
|
await Promise.all(localItems.map(async (localItem) => {
|
|
56
|
-
const operation = await getDifference(remoteItems, localItem);
|
|
57
|
-
return operation && upsert(itemType, operation, localItem);
|
|
56
|
+
const operation = await this.getDifference(remoteItems, localItem);
|
|
57
|
+
return operation && this.upsert(itemType, operation, localItem);
|
|
58
58
|
}));
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Create Custom Types using the Custom types api.
|
|
62
|
+
*
|
|
63
|
+
* @param customTypes -
|
|
64
|
+
*/
|
|
65
|
+
async createCustomTypes(customTypes = []) {
|
|
66
|
+
await this.upsertIfChanged("customtypes", customTypes);
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Create slices using the Custom types api.
|
|
70
|
+
*
|
|
71
|
+
* @param slices -
|
|
72
|
+
*/
|
|
73
|
+
async createSlices(slices = []) {
|
|
74
|
+
await this.upsertIfChanged("slices", slices);
|
|
65
75
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
createSlices
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
exports.createCustomTypesApiClient = createCustomTypesApiClient;
|
|
76
|
+
}
|
|
77
|
+
exports.CustomTypesApiClient = CustomTypesApiClient;
|
|
72
78
|
//# sourceMappingURL=customTypesApi.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\n\t}\n}\n"],"names":["AuthenticatedApiClient","logger","logPlaywrightApiResponse"],"mappings":";;;;;AAmBM,MAAO,6BAA6BA,UAAAA,uBAAsB;AAAA,EAC/D,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,MAAM,OACb,UACA,WACA,MAAc;AAER,UAAA,WAAWC,WAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,MAAM,EAAE,MAAM;AAC5C,QAAA,CAAC,OAAO,MAAM;AACjBC,UAAA,yBAAyB,MAAM;AAC/B,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAAA,EAEQ,MAAM,eACb,UAAsB;AAEhB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AAErC,QAAA,CAAC,OAAO,MAAM;AACjBA,UAAA,yBAAyB,MAAM;AACzB,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,WAAO,OAAO;EACf;AAAA,EAEQ,MAAM,cACb,aACA,OAAe;AAET,UAAA,aAAa,YAAY,KAC9B,CAAC,WAAqC,OAAO,OAAO,MAAM,EAAE;AAE7D,QAAI,CAAC,YAAY;AACT,aAAA;AAAA,IACR;AACA,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AACzB,aAAA;AAAA,IACR;AAEA;AAAA,EACD;AAAA;AAAA,EAGQ,MAAM,gBACb,UACA,aAAyB,IAAE;AAE3B,UAAM,cAAc,MAAM,KAAK,eAAe,QAAQ;AACtD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,KAAK,cAAc,aAAa,SAAS;AAEjE,aAAO,aAAa,KAAK,OAAO,UAAU,WAAW,SAAS;AAAA,IAC9D,CAAA,CAAC;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,cAA4B,IAAE;AAC/C,UAAA,KAAK,gBAAgB,eAAe,WAAW;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,SAAwB,IAAE;AACtC,UAAA,KAAK,gBAAgB,UAAU,MAAM;AAAA,EAC5C;AACA;;"}
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
import {
|
|
3
|
-
export type CustomTypesClient = {
|
|
4
|
-
createCustomTypes(customTypes: CustomType[]): Promise<void>;
|
|
5
|
-
createSlices(slices: SharedSlice[]): Promise<void>;
|
|
6
|
-
};
|
|
2
|
+
import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
|
|
7
3
|
/**
|
|
8
4
|
* Client for interacting with the Custom Types API to create/update custom
|
|
9
5
|
* types and slices.
|
|
10
6
|
*/
|
|
11
|
-
export declare
|
|
7
|
+
export declare class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
8
|
+
constructor(baseURL: string, config: {
|
|
9
|
+
authToken: AuthServerToken;
|
|
10
|
+
repository: string;
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Create or update a custom type or slice.
|
|
14
|
+
*
|
|
15
|
+
* @param endpoint - - The API endpoint for custom types or slices
|
|
16
|
+
* ('customtypes' or 'slices').
|
|
17
|
+
* @param data - - The data representing the custom type or slice.
|
|
18
|
+
*
|
|
19
|
+
* @throws Error if the item status cannot be retrieved or the item cannot be
|
|
20
|
+
* created/updated.
|
|
21
|
+
*/
|
|
22
|
+
private upsert;
|
|
23
|
+
private getRemoteItems;
|
|
24
|
+
private getDifference;
|
|
25
|
+
/** Create items only if they have changed compared to their remote status */
|
|
26
|
+
private upsertIfChanged;
|
|
27
|
+
/**
|
|
28
|
+
* Create Custom Types using the Custom types api.
|
|
29
|
+
*
|
|
30
|
+
* @param customTypes -
|
|
31
|
+
*/
|
|
32
|
+
createCustomTypes(customTypes?: CustomType[]): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Create slices using the Custom types api.
|
|
35
|
+
*
|
|
36
|
+
* @param slices -
|
|
37
|
+
*/
|
|
38
|
+
createSlices(slices?: SharedSlice[]): Promise<void>;
|
|
39
|
+
}
|