@prismicio/e2e-tests-utils 1.12.0-alpha.6 → 1.13.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/contentApi.cjs.map +1 -1
- package/dist/clients/contentApi.d.ts +7 -1
- package/dist/clients/contentApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +52 -0
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +39 -0
- package/dist/clients/coreApi.js +52 -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 +33 -0
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +23 -1
- package/dist/managers/repository.js +33 -0
- package/dist/managers/repository.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/assetApi.ts +34 -0
- package/src/clients/contentApi.ts +8 -1
- package/src/clients/coreApi.ts +86 -0
- package/src/index.ts +2 -0
- package/src/managers/repository.ts +43 -0
|
@@ -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;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentApi.cjs","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:
|
|
1
|
+
{"version":3,"file":"contentApi.cjs","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: ContentApiAlternateLanguage[];\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\tscheduledAt?: number | undefined;\n}\n\ninterface ContentApiAlternateLanguage {\n\tid: string;\n\ttype: string;\n\tlang: string;\n\tuid?: string;\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 Authorization header in case it is already set globally in the project Playwright config file.\n\t\t// This is because the content api returns an error in case it gets an non-empty invalid Authorization\n\t\t// even though it actually checks authorization from the access_token query parameter.\n\t\tsuper(baseURL, config.accessToken || \"\");\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":["AuthenticatedApiClient"],"mappings":";;;;;;;;;AA+FM,MAAO,yBAAyBA,UAAAA,uBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB3D,YACC,SACA,SAA0D,IAAE;AAKtD,UAAA,SAAS,OAAO,eAAe,EAAE;AA3BhC;AACA;AA2BF,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;;"}
|
|
@@ -26,7 +26,7 @@ export interface ContentApiDocument {
|
|
|
26
26
|
slugs: string[];
|
|
27
27
|
linked_documents: unknown[];
|
|
28
28
|
lang: string;
|
|
29
|
-
alternate_languages:
|
|
29
|
+
alternate_languages: ContentApiAlternateLanguage[];
|
|
30
30
|
data: Record<string, any>;
|
|
31
31
|
}
|
|
32
32
|
export interface ContentApiGraphQLResponse {
|
|
@@ -43,6 +43,12 @@ export interface ContentApiRef {
|
|
|
43
43
|
isMasterRef?: boolean;
|
|
44
44
|
scheduledAt?: number | undefined;
|
|
45
45
|
}
|
|
46
|
+
interface ContentApiAlternateLanguage {
|
|
47
|
+
id: string;
|
|
48
|
+
type: string;
|
|
49
|
+
lang: string;
|
|
50
|
+
uid?: string;
|
|
51
|
+
}
|
|
46
52
|
type SearchQueryParams = {
|
|
47
53
|
ref?: string;
|
|
48
54
|
query?: string;
|
|
@@ -1 +1 @@
|
|
|
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:
|
|
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: ContentApiAlternateLanguage[];\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\tscheduledAt?: number | undefined;\n}\n\ninterface ContentApiAlternateLanguage {\n\tid: string;\n\ttype: string;\n\tlang: string;\n\tuid?: string;\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 Authorization header in case it is already set globally in the project Playwright config file.\n\t\t// This is because the content api returns an error in case it gets an non-empty invalid Authorization\n\t\t// even though it actually checks authorization from the access_token query parameter.\n\t\tsuper(baseURL, config.accessToken || \"\");\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":";;;;;;;AA+FM,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;AAKtD,UAAA,SAAS,OAAO,eAAe,EAAE;AA3BhC;AACA;AA2BF,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
|
@@ -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,40 @@ 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
|
+
}
|
|
58
110
|
}
|
|
59
111
|
exports.CoreApiClient = CoreApiClient;
|
|
60
112
|
//# 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"],"names":["AuthenticatedApiClient","logger","logPlaywrightApiResponse"],"mappings":";;;;AAuEM,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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAW;AACV,UAAA,WAAWD,WAAO;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,YAAMC,IAAAA,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,YAAMA,IAAAA,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,YAAMA,IAAAA,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,YAAMA,IAAAA,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,YAAMA,IAAAA,yBAAyB,MAAM;AAC/B,YAAA,IAAI,MAAM,kCAAkC;AAAA,IACnD;AAEA,WAAO,OAAO;EACf;AACA;;"}
|
|
@@ -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,29 @@ 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>;
|
|
67
106
|
}
|
|
68
107
|
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,40 @@ 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
|
+
}
|
|
56
108
|
}
|
|
57
109
|
export {
|
|
58
110
|
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"],"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;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,6 +231,19 @@ 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
|
+
}
|
|
224
247
|
/**
|
|
225
248
|
* Deletes a repository release.
|
|
226
249
|
*
|
|
@@ -528,6 +551,16 @@ class RepositoryManager {
|
|
|
528
551
|
});
|
|
529
552
|
return result;
|
|
530
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Retrieves data for a specific document version.
|
|
556
|
+
*
|
|
557
|
+
* @param versionId - The document's version ID.
|
|
558
|
+
*
|
|
559
|
+
* @returns The document's version data.
|
|
560
|
+
*/
|
|
561
|
+
async getDocumentData(versionId) {
|
|
562
|
+
return await this.coreApiClient.getDocumentData(versionId);
|
|
563
|
+
}
|
|
531
564
|
async setupIntegrationFields(integrationFields) {
|
|
532
565
|
const profiler = log.logger.startTimer();
|
|
533
566
|
if (!this.integrationFieldsClient) {
|