@prismicio/e2e-tests-utils 1.12.0 → 1.14.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/clients/assetApi.cjs +16 -0
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.ts +21 -0
- package/dist/clients/assetApi.js +16 -0
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +67 -0
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +47 -0
- package/dist/clients/coreApi.js +67 -0
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/managers/repository.cjs +54 -1
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +32 -2
- package/dist/managers/repository.js +54 -1
- package/dist/managers/repository.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/assetApi.ts +34 -0
- package/src/clients/coreApi.ts +103 -0
- package/src/index.ts +2 -0
- package/src/managers/repository.ts +69 -1
|
@@ -43,6 +43,22 @@ class AssetApiClient extends apiClient.AuthenticatedApiClient {
|
|
|
43
43
|
}
|
|
44
44
|
return result.json();
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Searches for assets.
|
|
48
|
+
*
|
|
49
|
+
* @param params - Optional parameters to refine search results.
|
|
50
|
+
*
|
|
51
|
+
* @returns The API response containing assets.
|
|
52
|
+
*/
|
|
53
|
+
async search(params) {
|
|
54
|
+
const context = await this.getContext();
|
|
55
|
+
const result = await context.get("assets", { params });
|
|
56
|
+
if (200 !== result.status()) {
|
|
57
|
+
await log.logPlaywrightApiResponse(result);
|
|
58
|
+
throw new Error("Could not search the asset API.");
|
|
59
|
+
}
|
|
60
|
+
return result.json();
|
|
61
|
+
}
|
|
46
62
|
}
|
|
47
63
|
exports.AssetApiClient = AssetApiClient;
|
|
48
64
|
//# sourceMappingURL=assetApi.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetApi.cjs","sources":["../../../src/clients/assetApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface AssetApiCreatePayload {\n\tname: string;\n\tmimeType: string;\n\tbuffer: Buffer;\n}\n\nexport interface AssetApiCreateResponse {\n\tid: string;\n\turl: string;\n\tfilename: string;\n\tsize: number;\n\twidth: number;\n\theight: number;\n\tlast_modified: number;\n\tkind: string;\n\textension: string;\n\tcreated_at: number;\n\tuploader_id: string;\n\ttags: string[];\n}\n\nexport class AssetApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new AssetApiClient(\"https://asset-api.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * \trepository: \"my-repo-name\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - The API base URL, such as https://asset-api.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 * - {@link config.repository}: Repository name.\n\t */\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 * Uploads an asset file to the server.\n\t *\n\t * @param data - The payload containing the file and filename.\n\t *\n\t * @returns The API response containing asset information.\n\t *\n\t * @throws An error if the upload fails.\n\t */\n\tasync createAsset(\n\t\tdata: AssetApiCreatePayload,\n\t): Promise<AssetApiCreateResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.post(\"assets\", {\n\t\t\tmultipart: { file: data },\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not upload the asset with the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":["AuthenticatedApiClient","logPlaywrightApiResponse"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"assetApi.cjs","sources":["../../../src/clients/assetApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface AssetApiCreatePayload {\n\tname: string;\n\tmimeType: string;\n\tbuffer: Buffer;\n}\n\nexport interface AssetApiCreateResponse {\n\tid: string;\n\turl: string;\n\tfilename: string;\n\tsize: number;\n\twidth: number;\n\theight: number;\n\tlast_modified: number;\n\tkind: string;\n\textension: string;\n\tcreated_at: number;\n\tuploader_id: string;\n\ttags: string[];\n}\n\ntype AssetApiSearchParams = {\n\tkeyword?: string;\n\tlimit?: number;\n\tassetType?: string;\n\tcursor?: string;\n};\n\ninterface AssetApiSearchResponse {\n\titems: AssetApiCreateResponse[];\n\ttotal: number;\n\tcursor: string;\n\tis_opensearch_result: boolean;\n}\n\nexport class AssetApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new AssetApiClient(\"https://asset-api.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * \trepository: \"my-repo-name\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - The API base URL, such as https://asset-api.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 * - {@link config.repository}: Repository name.\n\t */\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 * Uploads an asset file to the server.\n\t *\n\t * @param data - The payload containing the file and filename.\n\t *\n\t * @returns The API response containing asset information.\n\t *\n\t * @throws An error if the upload fails.\n\t */\n\tasync createAsset(\n\t\tdata: AssetApiCreatePayload,\n\t): Promise<AssetApiCreateResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.post(\"assets\", {\n\t\t\tmultipart: { file: data },\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not upload the asset with the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\t/**\n\t * Searches for assets.\n\t *\n\t * @param params - Optional parameters to refine search results.\n\t *\n\t * @returns The API response containing assets.\n\t */\n\tasync search(params?: AssetApiSearchParams): Promise<AssetApiSearchResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.get(\"assets\", { params });\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not search the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":["AuthenticatedApiClient","logPlaywrightApiResponse"],"mappings":";;;;AAuCM,MAAO,uBAAuBA,UAAAA,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzD,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YACL,MAA2B;AAErB,UAAA,UAAU,MAAM,KAAK;AAE3B,UAAM,SAAS,MAAM,QAAQ,KAAK,UAAU;AAAA,MAC3C,WAAW,EAAE,MAAM,KAAM;AAAA,IAAA,CACzB;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAMC,IAAAA,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,gDAAgD;AAAA,IACjE;AAEA,WAAO,OAAO;EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OAAO,QAA6B;AACnC,UAAA,UAAU,MAAM,KAAK;AAE3B,UAAM,SAAS,MAAM,QAAQ,IAAI,UAAU,EAAE,QAAQ;AAEjD,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAMA,IAAAA,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,iCAAiC;AAAA,IAClD;AAEA,WAAO,OAAO;EACf;AACA;;"}
|
|
@@ -19,6 +19,18 @@ export interface AssetApiCreateResponse {
|
|
|
19
19
|
uploader_id: string;
|
|
20
20
|
tags: string[];
|
|
21
21
|
}
|
|
22
|
+
type AssetApiSearchParams = {
|
|
23
|
+
keyword?: string;
|
|
24
|
+
limit?: number;
|
|
25
|
+
assetType?: string;
|
|
26
|
+
cursor?: string;
|
|
27
|
+
};
|
|
28
|
+
interface AssetApiSearchResponse {
|
|
29
|
+
items: AssetApiCreateResponse[];
|
|
30
|
+
total: number;
|
|
31
|
+
cursor: string;
|
|
32
|
+
is_opensearch_result: boolean;
|
|
33
|
+
}
|
|
22
34
|
export declare class AssetApiClient extends AuthenticatedApiClient {
|
|
23
35
|
/**
|
|
24
36
|
* @example To instantiate the class:
|
|
@@ -51,4 +63,13 @@ export declare class AssetApiClient extends AuthenticatedApiClient {
|
|
|
51
63
|
* @throws An error if the upload fails.
|
|
52
64
|
*/
|
|
53
65
|
createAsset(data: AssetApiCreatePayload): Promise<AssetApiCreateResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Searches for assets.
|
|
68
|
+
*
|
|
69
|
+
* @param params - Optional parameters to refine search results.
|
|
70
|
+
*
|
|
71
|
+
* @returns The API response containing assets.
|
|
72
|
+
*/
|
|
73
|
+
search(params?: AssetApiSearchParams): Promise<AssetApiSearchResponse>;
|
|
54
74
|
}
|
|
75
|
+
export {};
|
package/dist/clients/assetApi.js
CHANGED
|
@@ -41,6 +41,22 @@ class AssetApiClient extends AuthenticatedApiClient {
|
|
|
41
41
|
}
|
|
42
42
|
return result.json();
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Searches for assets.
|
|
46
|
+
*
|
|
47
|
+
* @param params - Optional parameters to refine search results.
|
|
48
|
+
*
|
|
49
|
+
* @returns The API response containing assets.
|
|
50
|
+
*/
|
|
51
|
+
async search(params) {
|
|
52
|
+
const context = await this.getContext();
|
|
53
|
+
const result = await context.get("assets", { params });
|
|
54
|
+
if (200 !== result.status()) {
|
|
55
|
+
await logPlaywrightApiResponse(result);
|
|
56
|
+
throw new Error("Could not search the asset API.");
|
|
57
|
+
}
|
|
58
|
+
return result.json();
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
export {
|
|
46
62
|
AssetApiClient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetApi.js","sources":["../../../src/clients/assetApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface AssetApiCreatePayload {\n\tname: string;\n\tmimeType: string;\n\tbuffer: Buffer;\n}\n\nexport interface AssetApiCreateResponse {\n\tid: string;\n\turl: string;\n\tfilename: string;\n\tsize: number;\n\twidth: number;\n\theight: number;\n\tlast_modified: number;\n\tkind: string;\n\textension: string;\n\tcreated_at: number;\n\tuploader_id: string;\n\ttags: string[];\n}\n\nexport class AssetApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new AssetApiClient(\"https://asset-api.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * \trepository: \"my-repo-name\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - The API base URL, such as https://asset-api.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 * - {@link config.repository}: Repository name.\n\t */\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 * Uploads an asset file to the server.\n\t *\n\t * @param data - The payload containing the file and filename.\n\t *\n\t * @returns The API response containing asset information.\n\t *\n\t * @throws An error if the upload fails.\n\t */\n\tasync createAsset(\n\t\tdata: AssetApiCreatePayload,\n\t): Promise<AssetApiCreateResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.post(\"assets\", {\n\t\t\tmultipart: { file: data },\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not upload the asset with the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"assetApi.js","sources":["../../../src/clients/assetApi.ts"],"sourcesContent":["import { logPlaywrightApiResponse } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\nexport interface AssetApiCreatePayload {\n\tname: string;\n\tmimeType: string;\n\tbuffer: Buffer;\n}\n\nexport interface AssetApiCreateResponse {\n\tid: string;\n\turl: string;\n\tfilename: string;\n\tsize: number;\n\twidth: number;\n\theight: number;\n\tlast_modified: number;\n\tkind: string;\n\textension: string;\n\tcreated_at: number;\n\tuploader_id: string;\n\ttags: string[];\n}\n\ntype AssetApiSearchParams = {\n\tkeyword?: string;\n\tlimit?: number;\n\tassetType?: string;\n\tcursor?: string;\n};\n\ninterface AssetApiSearchResponse {\n\titems: AssetApiCreateResponse[];\n\ttotal: number;\n\tcursor: string;\n\tis_opensearch_result: boolean;\n}\n\nexport class AssetApiClient extends AuthenticatedApiClient {\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new AssetApiClient(\"https://asset-api.prismic.io\", {\n\t * \tauthToken: \"my-secret-token\",\n\t * \trepository: \"my-repo-name\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - The API base URL, such as https://asset-api.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 * - {@link config.repository}: Repository name.\n\t */\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 * Uploads an asset file to the server.\n\t *\n\t * @param data - The payload containing the file and filename.\n\t *\n\t * @returns The API response containing asset information.\n\t *\n\t * @throws An error if the upload fails.\n\t */\n\tasync createAsset(\n\t\tdata: AssetApiCreatePayload,\n\t): Promise<AssetApiCreateResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.post(\"assets\", {\n\t\t\tmultipart: { file: data },\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not upload the asset with the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\t/**\n\t * Searches for assets.\n\t *\n\t * @param params - Optional parameters to refine search results.\n\t *\n\t * @returns The API response containing assets.\n\t */\n\tasync search(params?: AssetApiSearchParams): Promise<AssetApiSearchResponse> {\n\t\tconst context = await this.getContext();\n\n\t\tconst result = await context.get(\"assets\", { params });\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not search the asset API.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":[],"mappings":";;AAuCM,MAAO,uBAAuB,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzD,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YACL,MAA2B;AAErB,UAAA,UAAU,MAAM,KAAK;AAE3B,UAAM,SAAS,MAAM,QAAQ,KAAK,UAAU;AAAA,MAC3C,WAAW,EAAE,MAAM,KAAM;AAAA,IAAA,CACzB;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,gDAAgD;AAAA,IACjE;AAEA,WAAO,OAAO;EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OAAO,QAA6B;AACnC,UAAA,UAAU,MAAM,KAAK;AAE3B,UAAM,SAAS,MAAM,QAAQ,IAAI,UAAU,EAAE,QAAQ;AAEjD,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,iCAAiC;AAAA,IAClD;AAEA,WAAO,OAAO;EACf;AACA;"}
|
package/dist/clients/coreApi.cjs
CHANGED
|
@@ -32,6 +32,24 @@ class CoreApiClient extends apiClient.AuthenticatedApiClient {
|
|
|
32
32
|
profiler.done({ message: "retrieved languages configuration" });
|
|
33
33
|
return (await result.json()).languages;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves all releases, including the migration release.
|
|
37
|
+
*
|
|
38
|
+
* @returns An array of release metadata.
|
|
39
|
+
*/
|
|
40
|
+
async getReleases() {
|
|
41
|
+
const profiler = log.logger.startTimer();
|
|
42
|
+
const context = await this.getContext();
|
|
43
|
+
const result = await context.get("core/releases", {
|
|
44
|
+
params: { include_migration_releases: true }
|
|
45
|
+
});
|
|
46
|
+
if (200 !== result.status() || !(await result.json()).results) {
|
|
47
|
+
await log.logPlaywrightApiResponse(result);
|
|
48
|
+
throw new Error("Could not get releases from the core api.");
|
|
49
|
+
}
|
|
50
|
+
profiler.done({ message: "retrieved releases" });
|
|
51
|
+
return (await result.json()).results;
|
|
52
|
+
}
|
|
35
53
|
async createDraft(data) {
|
|
36
54
|
const context = await this.getContext();
|
|
37
55
|
const result = await context.post("core/documents", {
|
|
@@ -55,6 +73,55 @@ class CoreApiClient extends apiClient.AuthenticatedApiClient {
|
|
|
55
73
|
throw new Error(`Could not publish document with id ${documentId}`);
|
|
56
74
|
}
|
|
57
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves documents.
|
|
78
|
+
*
|
|
79
|
+
* @param args - Configure which documents are retrieved.
|
|
80
|
+
*
|
|
81
|
+
* @returns A paginated set of documents.
|
|
82
|
+
*/
|
|
83
|
+
async getDocuments(args) {
|
|
84
|
+
const context = await this.getContext();
|
|
85
|
+
const result = await context.post("core/documents/search", {
|
|
86
|
+
data: args
|
|
87
|
+
});
|
|
88
|
+
if (200 !== result.status()) {
|
|
89
|
+
await log.logPlaywrightApiResponse(result);
|
|
90
|
+
throw new Error("Could not search documents");
|
|
91
|
+
}
|
|
92
|
+
return result.json();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Retrieves data for a specific document version.
|
|
96
|
+
*
|
|
97
|
+
* @param versionId - The document's version ID.
|
|
98
|
+
*
|
|
99
|
+
* @returns The document's version data.
|
|
100
|
+
*/
|
|
101
|
+
async getDocumentData(versionId) {
|
|
102
|
+
const context = await this.getContext();
|
|
103
|
+
const result = await context.get(`core/documents/data/${versionId}`);
|
|
104
|
+
if (200 !== result.status()) {
|
|
105
|
+
await log.logPlaywrightApiResponse(result);
|
|
106
|
+
throw new Error("Could not retrieve document data");
|
|
107
|
+
}
|
|
108
|
+
return result.json();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Publishes a release.
|
|
112
|
+
*
|
|
113
|
+
* @param id - The ID of the release.
|
|
114
|
+
*
|
|
115
|
+
* @returns A Promise that resolves when the release is published.
|
|
116
|
+
*/
|
|
117
|
+
async publishRelease(id) {
|
|
118
|
+
const context = await this.getContext();
|
|
119
|
+
const result = await context.post(`core/releases/${id}/publish`);
|
|
120
|
+
if (200 !== result.status()) {
|
|
121
|
+
await log.logPlaywrightApiResponse(result);
|
|
122
|
+
throw new Error("Could not publish release ${id}");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
58
125
|
}
|
|
59
126
|
exports.CoreApiClient = CoreApiClient;
|
|
60
127
|
//# sourceMappingURL=coreApi.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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 CoreApiDocumentCreationPayload = {\n\ttitle: string;\n\tlocale?: string;\n\tgroup_lang_id?: string;\n\trelease_id?: string;\n\tintegration_field_ids: string[];\n\tdata: Record<string, unknown>;\n\tcustom_type_id: string;\n\ttags: string[];\n};\n\nexport type CoreApiDocumentCreationResponse = {\n\tid: string;\n\tgroup_lang_id: string;\n\tcustom_type_id: string;\n\tlocale: string;\n\tlanguage: { id: string; name: string };\n\tfirst_publication_date: number | null;\n\tlast_publication_date: number | null;\n\ttitle: string;\n\tversions: {\n\t\tstatus: string;\n\t\tversion_id: string;\n\t\tauthor: {\n\t\t\tid: string;\n\t\t\tfirst_name: string | null;\n\t\t\tlast_name: string | null;\n\t\t\temail: string;\n\t\t};\n\t\trelease_id: string | null;\n\t\tlast_modified_date: number;\n\t\ttags: string[];\n\t\tcustom_type_label: string;\n\t\tpreview_summary?: string;\n\t\tpreview_image?: string;\n\t\tuid?: string;\n\t}[];\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 createDraft(\n\t\tdata: CoreApiDocumentCreationPayload,\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"core/documents\", {\n\t\t\tdata,\n\t\t});\n\n\t\tif (201 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not create draft document\");\n\t\t}\n\n\t\treturn result.json();\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":";;;;
|
|
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 Release = {\n\tid: string;\n\tlabel: string;\n\tmigration: boolean;\n};\n\nexport type CoreApiDocumentCreationPayload = {\n\ttitle: string;\n\tlocale?: string;\n\tgroup_lang_id?: string;\n\trelease_id?: string;\n\tintegration_field_ids: string[];\n\tdata: Record<string, unknown>;\n\tcustom_type_id: string;\n\ttags: string[];\n};\n\nexport type CoreApiDocumentCreationResponse = {\n\tid: string;\n\tgroup_lang_id: string;\n\tcustom_type_id: string;\n\tlocale: string;\n\tlanguage: { id: string; name: string };\n\tfirst_publication_date: number | null;\n\tlast_publication_date: number | null;\n\ttitle: string;\n\tversions: {\n\t\tstatus: string;\n\t\tversion_id: string;\n\t\tauthor: {\n\t\t\tid: string;\n\t\t\tfirst_name: string | null;\n\t\t\tlast_name: string | null;\n\t\t\temail: string;\n\t\t};\n\t\trelease_id: string | null;\n\t\tlast_modified_date: number;\n\t\ttags: string[];\n\t\tcustom_type_label: string;\n\t\tpreview_summary?: string;\n\t\tpreview_image?: string;\n\t\tuid?: string;\n\t}[];\n};\n\nexport type CoreApiDocumentsPayload = {\n\tlanguage?: string;\n\tlimit?: number;\n\tstatuses?: string[];\n\tgroupLangIds?: string[];\n};\n\nexport type CoreApiDocumentsResponse = {\n\ttotal: number;\n\tcursor: string;\n\tresults: CoreApiDocumentCreationResponse[];\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CoreApiDocumentData = Record<string, any>;\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\t/**\n\t * Retrieves all releases, including the migration release.\n\t *\n\t * @returns An array of release metadata.\n\t */\n\tasync getReleases(): Promise<Release[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"core/releases\", {\n\t\t\tparams: { include_migration_releases: true },\n\t\t});\n\n\t\tif (200 !== result.status() || !(await result.json()).results) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get releases from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved releases\" });\n\n\t\treturn (await result.json()).results;\n\t}\n\n\tasync createDraft(\n\t\tdata: CoreApiDocumentCreationPayload,\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"core/documents\", {\n\t\t\tdata,\n\t\t});\n\n\t\tif (201 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not create draft document\");\n\t\t}\n\n\t\treturn result.json();\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\t/**\n\t * Retrieves documents.\n\t *\n\t * @param args - Configure which documents are retrieved.\n\t *\n\t * @returns A paginated set of documents.\n\t */\n\tasync getDocuments(\n\t\targs: CoreApiDocumentsPayload,\n\t): Promise<CoreApiDocumentsResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"core/documents/search\", {\n\t\t\tdata: args,\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not search documents\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\t/**\n\t * Retrieves data for a specific document version.\n\t *\n\t * @param versionId - The document's version ID.\n\t *\n\t * @returns The document's version data.\n\t */\n\tasync getDocumentData(versionId: string): Promise<CoreApiDocumentData> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(`core/documents/data/${versionId}`);\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not retrieve document data\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\t/**\n\t * Publishes a release.\n\t *\n\t * @param id - The ID of the release.\n\t *\n\t * @returns A Promise that resolves when the release is published.\n\t */\n\tasync publishRelease(id: string): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(`core/releases/${id}/publish`);\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not publish release ${id}\");\n\t\t}\n\t}\n}\n"],"names":["AuthenticatedApiClient","logger","logPlaywrightApiResponse"],"mappings":"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"}
|
|
@@ -4,6 +4,11 @@ type Language = {
|
|
|
4
4
|
name: string;
|
|
5
5
|
is_master: boolean;
|
|
6
6
|
};
|
|
7
|
+
export type Release = {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
migration: boolean;
|
|
11
|
+
};
|
|
7
12
|
export type CoreApiDocumentCreationPayload = {
|
|
8
13
|
title: string;
|
|
9
14
|
locale?: string;
|
|
@@ -44,6 +49,18 @@ export type CoreApiDocumentCreationResponse = {
|
|
|
44
49
|
uid?: string;
|
|
45
50
|
}[];
|
|
46
51
|
};
|
|
52
|
+
export type CoreApiDocumentsPayload = {
|
|
53
|
+
language?: string;
|
|
54
|
+
limit?: number;
|
|
55
|
+
statuses?: string[];
|
|
56
|
+
groupLangIds?: string[];
|
|
57
|
+
};
|
|
58
|
+
export type CoreApiDocumentsResponse = {
|
|
59
|
+
total: number;
|
|
60
|
+
cursor: string;
|
|
61
|
+
results: CoreApiDocumentCreationResponse[];
|
|
62
|
+
};
|
|
63
|
+
export type CoreApiDocumentData = Record<string, any>;
|
|
47
64
|
export declare class CoreApiClient extends AuthenticatedApiClient {
|
|
48
65
|
/**
|
|
49
66
|
* @example To instantiate the class:
|
|
@@ -62,7 +79,37 @@ export declare class CoreApiClient extends AuthenticatedApiClient {
|
|
|
62
79
|
*/
|
|
63
80
|
constructor(baseURL: string, config: AuthServerToken);
|
|
64
81
|
getLanguages(): Promise<Language[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves all releases, including the migration release.
|
|
84
|
+
*
|
|
85
|
+
* @returns An array of release metadata.
|
|
86
|
+
*/
|
|
87
|
+
getReleases(): Promise<Release[]>;
|
|
65
88
|
createDraft(data: CoreApiDocumentCreationPayload): Promise<CoreApiDocumentCreationResponse>;
|
|
66
89
|
publishDraft(documentId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Retrieves documents.
|
|
92
|
+
*
|
|
93
|
+
* @param args - Configure which documents are retrieved.
|
|
94
|
+
*
|
|
95
|
+
* @returns A paginated set of documents.
|
|
96
|
+
*/
|
|
97
|
+
getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves data for a specific document version.
|
|
100
|
+
*
|
|
101
|
+
* @param versionId - The document's version ID.
|
|
102
|
+
*
|
|
103
|
+
* @returns The document's version data.
|
|
104
|
+
*/
|
|
105
|
+
getDocumentData(versionId: string): Promise<CoreApiDocumentData>;
|
|
106
|
+
/**
|
|
107
|
+
* Publishes a release.
|
|
108
|
+
*
|
|
109
|
+
* @param id - The ID of the release.
|
|
110
|
+
*
|
|
111
|
+
* @returns A Promise that resolves when the release is published.
|
|
112
|
+
*/
|
|
113
|
+
publishRelease(id: string): Promise<void>;
|
|
67
114
|
}
|
|
68
115
|
export {};
|
package/dist/clients/coreApi.js
CHANGED
|
@@ -30,6 +30,24 @@ class CoreApiClient extends AuthenticatedApiClient {
|
|
|
30
30
|
profiler.done({ message: "retrieved languages configuration" });
|
|
31
31
|
return (await result.json()).languages;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves all releases, including the migration release.
|
|
35
|
+
*
|
|
36
|
+
* @returns An array of release metadata.
|
|
37
|
+
*/
|
|
38
|
+
async getReleases() {
|
|
39
|
+
const profiler = logger.startTimer();
|
|
40
|
+
const context = await this.getContext();
|
|
41
|
+
const result = await context.get("core/releases", {
|
|
42
|
+
params: { include_migration_releases: true }
|
|
43
|
+
});
|
|
44
|
+
if (200 !== result.status() || !(await result.json()).results) {
|
|
45
|
+
await logPlaywrightApiResponse(result);
|
|
46
|
+
throw new Error("Could not get releases from the core api.");
|
|
47
|
+
}
|
|
48
|
+
profiler.done({ message: "retrieved releases" });
|
|
49
|
+
return (await result.json()).results;
|
|
50
|
+
}
|
|
33
51
|
async createDraft(data) {
|
|
34
52
|
const context = await this.getContext();
|
|
35
53
|
const result = await context.post("core/documents", {
|
|
@@ -53,6 +71,55 @@ class CoreApiClient extends AuthenticatedApiClient {
|
|
|
53
71
|
throw new Error(`Could not publish document with id ${documentId}`);
|
|
54
72
|
}
|
|
55
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves documents.
|
|
76
|
+
*
|
|
77
|
+
* @param args - Configure which documents are retrieved.
|
|
78
|
+
*
|
|
79
|
+
* @returns A paginated set of documents.
|
|
80
|
+
*/
|
|
81
|
+
async getDocuments(args) {
|
|
82
|
+
const context = await this.getContext();
|
|
83
|
+
const result = await context.post("core/documents/search", {
|
|
84
|
+
data: args
|
|
85
|
+
});
|
|
86
|
+
if (200 !== result.status()) {
|
|
87
|
+
await logPlaywrightApiResponse(result);
|
|
88
|
+
throw new Error("Could not search documents");
|
|
89
|
+
}
|
|
90
|
+
return result.json();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves data for a specific document version.
|
|
94
|
+
*
|
|
95
|
+
* @param versionId - The document's version ID.
|
|
96
|
+
*
|
|
97
|
+
* @returns The document's version data.
|
|
98
|
+
*/
|
|
99
|
+
async getDocumentData(versionId) {
|
|
100
|
+
const context = await this.getContext();
|
|
101
|
+
const result = await context.get(`core/documents/data/${versionId}`);
|
|
102
|
+
if (200 !== result.status()) {
|
|
103
|
+
await logPlaywrightApiResponse(result);
|
|
104
|
+
throw new Error("Could not retrieve document data");
|
|
105
|
+
}
|
|
106
|
+
return result.json();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Publishes a release.
|
|
110
|
+
*
|
|
111
|
+
* @param id - The ID of the release.
|
|
112
|
+
*
|
|
113
|
+
* @returns A Promise that resolves when the release is published.
|
|
114
|
+
*/
|
|
115
|
+
async publishRelease(id) {
|
|
116
|
+
const context = await this.getContext();
|
|
117
|
+
const result = await context.post(`core/releases/${id}/publish`);
|
|
118
|
+
if (200 !== result.status()) {
|
|
119
|
+
await logPlaywrightApiResponse(result);
|
|
120
|
+
throw new Error("Could not publish release ${id}");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
56
123
|
}
|
|
57
124
|
export {
|
|
58
125
|
CoreApiClient
|
|
@@ -1 +1 @@
|
|
|
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 CoreApiDocumentCreationPayload = {\n\ttitle: string;\n\tlocale?: string;\n\tgroup_lang_id?: string;\n\trelease_id?: string;\n\tintegration_field_ids: string[];\n\tdata: Record<string, unknown>;\n\tcustom_type_id: string;\n\ttags: string[];\n};\n\nexport type CoreApiDocumentCreationResponse = {\n\tid: string;\n\tgroup_lang_id: string;\n\tcustom_type_id: string;\n\tlocale: string;\n\tlanguage: { id: string; name: string };\n\tfirst_publication_date: number | null;\n\tlast_publication_date: number | null;\n\ttitle: string;\n\tversions: {\n\t\tstatus: string;\n\t\tversion_id: string;\n\t\tauthor: {\n\t\t\tid: string;\n\t\t\tfirst_name: string | null;\n\t\t\tlast_name: string | null;\n\t\t\temail: string;\n\t\t};\n\t\trelease_id: string | null;\n\t\tlast_modified_date: number;\n\t\ttags: string[];\n\t\tcustom_type_label: string;\n\t\tpreview_summary?: string;\n\t\tpreview_image?: string;\n\t\tuid?: string;\n\t}[];\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 createDraft(\n\t\tdata: CoreApiDocumentCreationPayload,\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"core/documents\", {\n\t\t\tdata,\n\t\t});\n\n\t\tif (201 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not create draft document\");\n\t\t}\n\n\t\treturn result.json();\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":";;
|
|
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 Release = {\n\tid: string;\n\tlabel: string;\n\tmigration: boolean;\n};\n\nexport type CoreApiDocumentCreationPayload = {\n\ttitle: string;\n\tlocale?: string;\n\tgroup_lang_id?: string;\n\trelease_id?: string;\n\tintegration_field_ids: string[];\n\tdata: Record<string, unknown>;\n\tcustom_type_id: string;\n\ttags: string[];\n};\n\nexport type CoreApiDocumentCreationResponse = {\n\tid: string;\n\tgroup_lang_id: string;\n\tcustom_type_id: string;\n\tlocale: string;\n\tlanguage: { id: string; name: string };\n\tfirst_publication_date: number | null;\n\tlast_publication_date: number | null;\n\ttitle: string;\n\tversions: {\n\t\tstatus: string;\n\t\tversion_id: string;\n\t\tauthor: {\n\t\t\tid: string;\n\t\t\tfirst_name: string | null;\n\t\t\tlast_name: string | null;\n\t\t\temail: string;\n\t\t};\n\t\trelease_id: string | null;\n\t\tlast_modified_date: number;\n\t\ttags: string[];\n\t\tcustom_type_label: string;\n\t\tpreview_summary?: string;\n\t\tpreview_image?: string;\n\t\tuid?: string;\n\t}[];\n};\n\nexport type CoreApiDocumentsPayload = {\n\tlanguage?: string;\n\tlimit?: number;\n\tstatuses?: string[];\n\tgroupLangIds?: string[];\n};\n\nexport type CoreApiDocumentsResponse = {\n\ttotal: number;\n\tcursor: string;\n\tresults: CoreApiDocumentCreationResponse[];\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CoreApiDocumentData = Record<string, any>;\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\t/**\n\t * Retrieves all releases, including the migration release.\n\t *\n\t * @returns An array of release metadata.\n\t */\n\tasync getReleases(): Promise<Release[]> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"core/releases\", {\n\t\t\tparams: { include_migration_releases: true },\n\t\t});\n\n\t\tif (200 !== result.status() || !(await result.json()).results) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get releases from the core api.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"retrieved releases\" });\n\n\t\treturn (await result.json()).results;\n\t}\n\n\tasync createDraft(\n\t\tdata: CoreApiDocumentCreationPayload,\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"core/documents\", {\n\t\t\tdata,\n\t\t});\n\n\t\tif (201 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not create draft document\");\n\t\t}\n\n\t\treturn result.json();\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\t/**\n\t * Retrieves documents.\n\t *\n\t * @param args - Configure which documents are retrieved.\n\t *\n\t * @returns A paginated set of documents.\n\t */\n\tasync getDocuments(\n\t\targs: CoreApiDocumentsPayload,\n\t): Promise<CoreApiDocumentsResponse> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"core/documents/search\", {\n\t\t\tdata: args,\n\t\t});\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not search documents\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\t/**\n\t * Retrieves data for a specific document version.\n\t *\n\t * @param versionId - The document's version ID.\n\t *\n\t * @returns The document's version data.\n\t */\n\tasync getDocumentData(versionId: string): Promise<CoreApiDocumentData> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(`core/documents/data/${versionId}`);\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not retrieve document data\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\t/**\n\t * Publishes a release.\n\t *\n\t * @param id - The ID of the release.\n\t *\n\t * @returns A Promise that resolves when the release is published.\n\t */\n\tasync publishRelease(id: string): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(`core/releases/${id}/publish`);\n\n\t\tif (200 !== result.status()) {\n\t\t\tawait logPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not publish release ${id}\");\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAuEM,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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAW;AACV,UAAA,WAAW,OAAO;AAClB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,iBAAiB;AAAA,MACjD,QAAQ,EAAE,4BAA4B,KAAM;AAAA,IAAA,CAC5C;AAEG,QAAA,QAAQ,OAAO,OAAM,KAAM,EAAE,MAAM,OAAO,KAAI,GAAI,SAAS;AAC9D,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,aAAS,KAAK,EAAE,SAAS,qBAAsB,CAAA;AAEvC,YAAA,MAAM,OAAO,KAAA,GAAQ;AAAA,EAC9B;AAAA,EAEA,MAAM,YACL,MAAoC;AAE9B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,kBAAkB;AAAA,MACnD;AAAA,IAAA,CACA;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,iCAAiC;AAAA,IAClD;AAEA,WAAO,OAAO;EACf;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,aACL,MAA6B;AAEvB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,yBAAyB;AAAA,MAC1D,MAAM;AAAA,IAAA,CACN;AAEG,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,4BAA4B;AAAA,IAC7C;AAEA,WAAO,OAAO;EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,gBAAgB,WAAiB;AAChC,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,uBAAuB,SAAS,EAAE;AAE/D,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,kCAAkC;AAAA,IACnD;AAEA,WAAO,OAAO;EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,eAAe,IAAU;AACxB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,iBAAiB,EAAE,UAAU;AAE3D,QAAA,QAAQ,OAAO,UAAU;AAC5B,YAAM,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,iCAAiC;AAAA,IAClD;AAAA,EACD;AACA;"}
|
package/dist/index.cjs
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const repositories = require("./managers/repositories.cjs");
|
|
4
4
|
const repository = require("./managers/repository.cjs");
|
|
5
|
+
const coreApi = require("./clients/coreApi.cjs");
|
|
5
6
|
const contentApi = require("./clients/contentApi.cjs");
|
|
7
|
+
const assetApi = require("./clients/assetApi.cjs");
|
|
6
8
|
const migrationApi = require("./clients/migrationApi.cjs");
|
|
7
9
|
exports.RepositoriesManager = repositories.RepositoriesManager;
|
|
8
10
|
exports.createRepositoriesManager = repositories.createRepositoriesManager;
|
|
9
11
|
exports.RepositoryManager = repository.RepositoryManager;
|
|
12
|
+
exports.CoreApiClient = coreApi.CoreApiClient;
|
|
10
13
|
exports.ContentApiClient = contentApi.ContentApiClient;
|
|
14
|
+
exports.AssetApiClient = assetApi.AssetApiClient;
|
|
11
15
|
exports.MigrationApiClient = migrationApi.MigrationApiClient;
|
|
12
16
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { RepositoriesManager, createRepositoriesManager } from "./managers/repositories.js";
|
|
2
2
|
import { RepositoryManager } from "./managers/repository.js";
|
|
3
|
+
import { CoreApiClient } from "./clients/coreApi.js";
|
|
3
4
|
import { ContentApiClient } from "./clients/contentApi.js";
|
|
5
|
+
import { AssetApiClient } from "./clients/assetApi.js";
|
|
4
6
|
import { MigrationApiClient } from "./clients/migrationApi.js";
|
|
5
7
|
export {
|
|
8
|
+
AssetApiClient,
|
|
6
9
|
ContentApiClient,
|
|
10
|
+
CoreApiClient,
|
|
7
11
|
MigrationApiClient,
|
|
8
12
|
RepositoriesManager,
|
|
9
13
|
RepositoryManager,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -205,6 +205,16 @@ class RepositoryManager {
|
|
|
205
205
|
}
|
|
206
206
|
profiler.done({ message: `default locale set to '${locale}'` });
|
|
207
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Retrieves documents.
|
|
210
|
+
*
|
|
211
|
+
* @param args - Configure which documents are retrieved.
|
|
212
|
+
*
|
|
213
|
+
* @returns A paginated set of documents.
|
|
214
|
+
*/
|
|
215
|
+
async getDocuments(args) {
|
|
216
|
+
return this.coreApiClient.getDocuments(args);
|
|
217
|
+
}
|
|
208
218
|
/**
|
|
209
219
|
* Creates a release.
|
|
210
220
|
*
|
|
@@ -221,10 +231,43 @@ class RepositoryManager {
|
|
|
221
231
|
profiler.done({ message: `release '${label}' created` });
|
|
222
232
|
return response.data;
|
|
223
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Retrieves the migration release.
|
|
236
|
+
*
|
|
237
|
+
* @returns The migration relese metadata.
|
|
238
|
+
*/
|
|
239
|
+
async getMigrationRelease() {
|
|
240
|
+
const releases = await this.coreApiClient.getReleases();
|
|
241
|
+
const migrationRelease = releases.find((release) => release.migration);
|
|
242
|
+
if (!migrationRelease) {
|
|
243
|
+
throw new Error(`The repository does not have a migration release`);
|
|
244
|
+
}
|
|
245
|
+
return migrationRelease;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Publishes a release.
|
|
249
|
+
*
|
|
250
|
+
* @param id - The ID of the release.
|
|
251
|
+
*
|
|
252
|
+
* @returns A Promise that resolves when the release is published and a new
|
|
253
|
+
* master ref is available.
|
|
254
|
+
*/
|
|
255
|
+
async publishRelease(id) {
|
|
256
|
+
const profiler = log.logger.startTimer();
|
|
257
|
+
const contentApi2 = this.getContentApiClient();
|
|
258
|
+
const masterRef = await contentApi2.getMasterRef();
|
|
259
|
+
await this.coreApiClient.publishRelease(id);
|
|
260
|
+
await test.expect.poll(async () => contentApi2.getMasterRef(), {
|
|
261
|
+
timeout: 1e4,
|
|
262
|
+
message: "Waiting for new master ref to be available"
|
|
263
|
+
}).not.toBe(masterRef);
|
|
264
|
+
profiler.done({
|
|
265
|
+
message: `release '${id}' published and new master ref available`
|
|
266
|
+
});
|
|
267
|
+
}
|
|
224
268
|
/**
|
|
225
269
|
* Deletes a repository release.
|
|
226
270
|
*
|
|
227
|
-
* @param repository - The name of the repository.
|
|
228
271
|
* @param id - The ID of the release to be deleted.
|
|
229
272
|
*/
|
|
230
273
|
async deleteRelease(id) {
|
|
@@ -528,6 +571,16 @@ class RepositoryManager {
|
|
|
528
571
|
});
|
|
529
572
|
return result;
|
|
530
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Retrieves data for a specific document version.
|
|
576
|
+
*
|
|
577
|
+
* @param versionId - The document's version ID.
|
|
578
|
+
*
|
|
579
|
+
* @returns The document's version data.
|
|
580
|
+
*/
|
|
581
|
+
async getDocumentData(versionId) {
|
|
582
|
+
return await this.coreApiClient.getDocumentData(versionId);
|
|
583
|
+
}
|
|
531
584
|
async setupIntegrationFields(integrationFields) {
|
|
532
585
|
const profiler = log.logger.startTimer();
|
|
533
586
|
if (!this.integrationFieldsClient) {
|