@prismicio/e2e-tests-utils 1.1.2 → 1.2.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/authenticationApi.cjs +1 -18
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.ts +2 -3
- package/dist/clients/authenticationApi.js +2 -19
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/wroom.cjs +0 -26
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.ts +2 -22
- package/dist/clients/wroom.js +0 -26
- package/dist/clients/wroom.js.map +1 -1
- package/dist/managers/repositories.cjs +17 -20
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.ts +22 -12
- package/dist/managers/repositories.js +17 -20
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +32 -108
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +22 -50
- package/dist/managers/repository.js +32 -108
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.ts +1 -18
- package/package.json +1 -3
- package/src/clients/authenticationApi.ts +3 -30
- package/src/clients/wroom.ts +2 -40
- package/src/managers/repositories.ts +37 -39
- package/src/managers/repository.ts +58 -148
- package/src/types.ts +1 -27
- package/dist/clients/manageV2.cjs +0 -145
- package/dist/clients/manageV2.cjs.map +0 -1
- package/dist/clients/manageV2.d.ts +0 -91
- package/dist/clients/manageV2.js +0 -145
- package/dist/clients/manageV2.js.map +0 -1
- package/src/clients/manageV2.ts +0 -178
|
@@ -28,25 +28,8 @@ const createAuthenticationApiClient = (baseURL, auth) => {
|
|
|
28
28
|
}
|
|
29
29
|
return authToken;
|
|
30
30
|
}
|
|
31
|
-
async function getMachine2MachineToken(repository) {
|
|
32
|
-
if (!authToken) {
|
|
33
|
-
authToken = await login();
|
|
34
|
-
}
|
|
35
|
-
const result = await client.get("machine2machine", {
|
|
36
|
-
headers: {
|
|
37
|
-
Authorization: `Bearer ${authToken}`,
|
|
38
|
-
repository
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (![200].includes(result.status) || !result.data.token) {
|
|
42
|
-
log.logHttpResponse(result);
|
|
43
|
-
throw new Error("Machine2Machine token generation failed, no token received.");
|
|
44
|
-
}
|
|
45
|
-
return result.data.token;
|
|
46
|
-
}
|
|
47
31
|
return {
|
|
48
|
-
getToken
|
|
49
|
-
getMachine2MachineToken
|
|
32
|
+
getToken
|
|
50
33
|
};
|
|
51
34
|
};
|
|
52
35
|
exports.createAuthenticationApiClient = createAuthenticationApiClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: Credentials,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"generated user token from auth service\" });\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken() {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAWa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAWA,WAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpDC,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK,EAAE,SAAS,yCAA0C,CAAA;AAEnE,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Credentials } from "../types";
|
|
2
2
|
export type AuthenticationClient = {
|
|
3
3
|
getToken: () => Promise<string>;
|
|
4
|
-
getMachine2MachineToken: (repository: string) => Promise<string>;
|
|
5
4
|
};
|
|
6
5
|
/** Client for interacting with the authentication service to manage tokens */
|
|
7
|
-
export declare const createAuthenticationApiClient: (baseURL: string, auth:
|
|
6
|
+
export declare const createAuthenticationApiClient: (baseURL: string, auth: Credentials) => AuthenticationClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import {
|
|
2
|
+
import { logger, logHttpResponse } from "../utils/log.js";
|
|
3
3
|
const createAuthenticationApiClient = (baseURL, auth) => {
|
|
4
4
|
let authToken;
|
|
5
5
|
const client = axios.create({
|
|
@@ -26,25 +26,8 @@ const createAuthenticationApiClient = (baseURL, auth) => {
|
|
|
26
26
|
}
|
|
27
27
|
return authToken;
|
|
28
28
|
}
|
|
29
|
-
async function getMachine2MachineToken(repository) {
|
|
30
|
-
if (!authToken) {
|
|
31
|
-
authToken = await login();
|
|
32
|
-
}
|
|
33
|
-
const result = await client.get("machine2machine", {
|
|
34
|
-
headers: {
|
|
35
|
-
Authorization: `Bearer ${authToken}`,
|
|
36
|
-
repository
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (![200].includes(result.status) || !result.data.token) {
|
|
40
|
-
logHttpResponse(result);
|
|
41
|
-
throw new Error("Machine2Machine token generation failed, no token received.");
|
|
42
|
-
}
|
|
43
|
-
return result.data.token;
|
|
44
|
-
}
|
|
45
29
|
return {
|
|
46
|
-
getToken
|
|
47
|
-
getMachine2MachineToken
|
|
30
|
+
getToken
|
|
48
31
|
};
|
|
49
32
|
};
|
|
50
33
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nexport type AuthenticationClient = {\n\tgetToken: () => Promise<string>;\n};\n\n/** Client for interacting with the authentication service to manage tokens */\nexport const createAuthenticationApiClient = (\n\tbaseURL: string,\n\tauth: Credentials,\n): AuthenticationClient => {\n\tlet authToken: string;\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\tasync function login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst result = await client.post(\"login\", {\n\t\t\temail: auth.email,\n\t\t\tpassword: auth.password,\n\t\t});\n\n\t\tif (!result.data || typeof result.data !== \"string\") {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({ message: \"generated user token from auth service\" });\n\n\t\treturn result.data;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync function getToken() {\n\t\tif (!authToken) {\n\t\t\tauthToken = await login();\n\t\t}\n\n\t\treturn authToken;\n\t}\n\n\treturn {\n\t\tgetToken,\n\t};\n};\n"],"names":[],"mappings":";;AAWa,MAAA,gCAAgC,CAC5C,SACA,SACyB;AACrB,MAAA;AAEE,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAED,iBAAe,QAAK;AACb,UAAA,WAAW,OAAO;AAExB,UAAM,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,MACzC,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK;AAAA,IAAA,CACf;AAED,QAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UAAU;AACpD,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,2CAA2C;AAAA,IAC3D;AAED,aAAS,KAAK,EAAE,SAAS,yCAA0C,CAAA;AAEnE,WAAO,OAAO;AAAA,EACf;AAGA,iBAAe,WAAQ;AACtB,QAAI,CAAC,WAAW;AACf,kBAAY,MAAM;IAClB;AAEM,WAAA;AAAA,EACR;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
|
package/dist/clients/wroom.cjs
CHANGED
|
@@ -67,32 +67,6 @@ class WroomClient {
|
|
|
67
67
|
});
|
|
68
68
|
return response;
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Update the role of a user in the repository
|
|
72
|
-
*
|
|
73
|
-
* @param {string} repository - The repository name
|
|
74
|
-
* @param {string} email - The email of the user
|
|
75
|
-
* @param {string} role - The new role to be given
|
|
76
|
-
*
|
|
77
|
-
* @returns The Axios Reponse
|
|
78
|
-
*/
|
|
79
|
-
async updateRole(repository, email, role) {
|
|
80
|
-
const path = `/app/settings/users/profiles?email=${email}&profile=${role}`;
|
|
81
|
-
return this.post(repository, path);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Update the role of a user in the repository
|
|
85
|
-
*
|
|
86
|
-
* @param {string} repository - The repository name
|
|
87
|
-
* @param {string} email - The email of the user
|
|
88
|
-
* @param {string} rolePerLocal - The role per local object
|
|
89
|
-
*
|
|
90
|
-
* @returns The Axios Reponse
|
|
91
|
-
*/
|
|
92
|
-
async updateRolePerLocal(repository, email, rolePerLocal) {
|
|
93
|
-
const path = `/app/settings/users/rolesperlocale?email=${email}`;
|
|
94
|
-
return this.post(repository, path, rolePerLocal);
|
|
95
|
-
}
|
|
96
70
|
/**
|
|
97
71
|
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
98
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wroom.cjs","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"wroom.cjs","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/**\n * Client for interacting with the Wroom service to perform operations on\n * repositories.\n */\nexport class WroomClient {\n\tprivate readonly client: AxiosInstance;\n\tprivate loggedIn = false;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param auth - Authentication credentials.\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tprivate readonly auth: Credentials,\n\t) {\n\t\tthis.client = axios.create({\n\t\t\tbaseURL,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\txsrfCookieName: \"X_XSRF\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/** authenticated GET request on the wroom backend */\n\tasync get(repository: string | null, path: string): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\n\t\treturn this.client.get(url);\n\t}\n\n\t/** authenticated POST request on the wroom backend */\n\tasync post(\n\t\trepository: string | null,\n\t\tpath: string,\n\t\tdata?: unknown,\n\t): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\t\tconst response = await this.client.post(url.toString(), data, {\n\t\t\tparams: {\n\t\t\t\t_: extractCookie(this.client.defaults.headers[\"Cookie\"], \"X_XSRF\"),\n\t\t\t},\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Authenticate Wroom to call Wroom unofficial endpoints.\n\t *\n\t * @throws Error if the login to Wroom fails.\n\t */\n\tprivate async login(): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst response = await this.client.post<string>(\"/authentication/signin\", {\n\t\t\temail: this.auth.email,\n\t\t\tpassword: this.auth.password,\n\t\t});\n\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\"Could not login to Prismic, check your credentials\");\n\t\t}\n\t\tthis.loggedIn = true;\n\t\tprofiler.done({ message: \"logged in to Prismic\" });\n\t}\n}\n"],"names":["cookies","extractCookie","getRepositoryUrl","logger","logHttpResponse"],"mappings":";;;;;;;;;;;;MAYa,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAQvB,YACC,SACiB,MAAiB;AAAjB;AATD;AACT,oCAAW;AAQD,SAAI,OAAJ;AAEZ,SAAA,SAAS,MAAM,OAAO;AAAA,MAC1B;AAAA,MACA,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,gBAAgB;AAAA,MAChB,SAAS;AAAA,QACR,cAAc;AAAA,MACd;AAAA,IAAA,CACD;AAGD,SAAK,OAAO,aAAa,SAAS,IAAI,CAAC,aAAY;AAC5C,YAAAA,YAAU,SAAS,QAAQ,YAAY;AAC7C,UAAIA,aAAWC,QAAAA,cAAcD,WAAS,SAAS,GAAG;AACjD,aAAK,OAAO,SAAS,QAAQ,QAAQ,IAAIA;AAAAA,MACzC;AAEM,aAAA;AAAA,IAAA,CACP;AAAA,EACF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAAA;AAAA,EAGA,MAAM,IAAI,YAA2B,MAAY;AAC5C,QAAA,CAAC,KAAK,UAAU;AACnB,YAAM,KAAK;IACX;AAEG,QAAA,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO,OAAA,CAAQ,EAAE;AAC9C,QAAI,YAAY;AACT,YAAAE,KAAA,iBAAiB,KAAK,UAAU;AAAA,IACtC;AAEM,WAAA,KAAK,OAAO,IAAI,GAAG;AAAA,EAC3B;AAAA;AAAA,EAGA,MAAM,KACL,YACA,MACA,MAAc;AAEV,QAAA,CAAC,KAAK,UAAU;AACnB,YAAM,KAAK;IACX;AAEG,QAAA,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO,OAAA,CAAQ,EAAE;AAC9C,QAAI,YAAY;AACT,YAAAA,KAAA,iBAAiB,KAAK,UAAU;AAAA,IACtC;AACK,UAAA,WAAW,MAAM,KAAK,OAAO,KAAK,IAAI,YAAY,MAAM;AAAA,MAC7D,QAAQ;AAAA,QACP,GAAGD,QAAAA,cAAc,KAAK,OAAO,SAAS,QAAQ,QAAQ,GAAG,QAAQ;AAAA,MACjE;AAAA,IAAA,CACD;AAEM,WAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,MAAM,QAAK;AACZ,UAAA,WAAWE,WAAO;AACxB,UAAM,WAAW,MAAM,KAAK,OAAO,KAAa,0BAA0B;AAAA,MACzE,OAAO,KAAK,KAAK;AAAA,MACjB,UAAU,KAAK,KAAK;AAAA,IAAA,CACpB;AAEG,QAAA,SAAS,WAAW,KAAK;AAC5BC,UAAA,gBAAgB,QAAQ;AAClB,YAAA,IAAI,MAAM,oDAAoD;AAAA,IACpE;AACD,SAAK,WAAW;AAChB,aAAS,KAAK,EAAE,SAAS,uBAAwB,CAAA;AAAA,EAClD;AACA;;"}
|
package/dist/clients/wroom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
|
-
import {
|
|
2
|
+
import { Credentials } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Client for interacting with the Wroom service to perform operations on
|
|
5
5
|
* repositories.
|
|
@@ -12,32 +12,12 @@ export declare class WroomClient {
|
|
|
12
12
|
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
13
13
|
* @param auth - Authentication credentials.
|
|
14
14
|
*/
|
|
15
|
-
constructor(baseURL: string, auth:
|
|
15
|
+
constructor(baseURL: string, auth: Credentials);
|
|
16
16
|
getBaseURL(): string;
|
|
17
17
|
/** authenticated GET request on the wroom backend */
|
|
18
18
|
get(repository: string | null, path: string): Promise<AxiosResponse>;
|
|
19
19
|
/** authenticated POST request on the wroom backend */
|
|
20
20
|
post(repository: string | null, path: string, data?: unknown): Promise<AxiosResponse>;
|
|
21
|
-
/**
|
|
22
|
-
* Update the role of a user in the repository
|
|
23
|
-
*
|
|
24
|
-
* @param {string} repository - The repository name
|
|
25
|
-
* @param {string} email - The email of the user
|
|
26
|
-
* @param {string} role - The new role to be given
|
|
27
|
-
*
|
|
28
|
-
* @returns The Axios Reponse
|
|
29
|
-
*/
|
|
30
|
-
updateRole(repository: string, email: string, role: string): Promise<AxiosResponse>;
|
|
31
|
-
/**
|
|
32
|
-
* Update the role of a user in the repository
|
|
33
|
-
*
|
|
34
|
-
* @param {string} repository - The repository name
|
|
35
|
-
* @param {string} email - The email of the user
|
|
36
|
-
* @param {string} rolePerLocal - The role per local object
|
|
37
|
-
*
|
|
38
|
-
* @returns The Axios Reponse
|
|
39
|
-
*/
|
|
40
|
-
updateRolePerLocal(repository: string, email: string, rolePerLocal: Record<string, string>): Promise<AxiosResponse>;
|
|
41
21
|
/**
|
|
42
22
|
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
43
23
|
*
|
package/dist/clients/wroom.js
CHANGED
|
@@ -65,32 +65,6 @@ class WroomClient {
|
|
|
65
65
|
});
|
|
66
66
|
return response;
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Update the role of a user in the repository
|
|
70
|
-
*
|
|
71
|
-
* @param {string} repository - The repository name
|
|
72
|
-
* @param {string} email - The email of the user
|
|
73
|
-
* @param {string} role - The new role to be given
|
|
74
|
-
*
|
|
75
|
-
* @returns The Axios Reponse
|
|
76
|
-
*/
|
|
77
|
-
async updateRole(repository, email, role) {
|
|
78
|
-
const path = `/app/settings/users/profiles?email=${email}&profile=${role}`;
|
|
79
|
-
return this.post(repository, path);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Update the role of a user in the repository
|
|
83
|
-
*
|
|
84
|
-
* @param {string} repository - The repository name
|
|
85
|
-
* @param {string} email - The email of the user
|
|
86
|
-
* @param {string} rolePerLocal - The role per local object
|
|
87
|
-
*
|
|
88
|
-
* @returns The Axios Reponse
|
|
89
|
-
*/
|
|
90
|
-
async updateRolePerLocal(repository, email, rolePerLocal) {
|
|
91
|
-
const path = `/app/settings/users/rolesperlocale?email=${email}`;
|
|
92
|
-
return this.post(repository, path, rolePerLocal);
|
|
93
|
-
}
|
|
94
68
|
/**
|
|
95
69
|
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
96
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wroom.js","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"wroom.js","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { Credentials } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/**\n * Client for interacting with the Wroom service to perform operations on\n * repositories.\n */\nexport class WroomClient {\n\tprivate readonly client: AxiosInstance;\n\tprivate loggedIn = false;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param auth - Authentication credentials.\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tprivate readonly auth: Credentials,\n\t) {\n\t\tthis.client = axios.create({\n\t\t\tbaseURL,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\txsrfCookieName: \"X_XSRF\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/** authenticated GET request on the wroom backend */\n\tasync get(repository: string | null, path: string): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\n\t\treturn this.client.get(url);\n\t}\n\n\t/** authenticated POST request on the wroom backend */\n\tasync post(\n\t\trepository: string | null,\n\t\tpath: string,\n\t\tdata?: unknown,\n\t): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\t\tconst response = await this.client.post(url.toString(), data, {\n\t\t\tparams: {\n\t\t\t\t_: extractCookie(this.client.defaults.headers[\"Cookie\"], \"X_XSRF\"),\n\t\t\t},\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Authenticate Wroom to call Wroom unofficial endpoints.\n\t *\n\t * @throws Error if the login to Wroom fails.\n\t */\n\tprivate async login(): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst response = await this.client.post<string>(\"/authentication/signin\", {\n\t\t\temail: this.auth.email,\n\t\t\tpassword: this.auth.password,\n\t\t});\n\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\"Could not login to Prismic, check your credentials\");\n\t\t}\n\t\tthis.loggedIn = true;\n\t\tprofiler.done({ message: \"logged in to Prismic\" });\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;MAYa,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA,E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AA;AAAA;AAAA;AAAA,EAOQ,MAAM,QAAK;AACZ,UAAA,WAAW,OAAO;AACxB,UAAM,WAAW,MAAM,KAAK,OAAO,KAAa,0BAA0B;AAAA,MACzE,OAAO,KAAK,KAAK;AAAA,MACjB,UAAU,KAAK,KAAK;AAAA,IAAA,CACpB;AAEG,QAAA,SAAS,WAAW,KAAK;AAC5B,sBAAgB,QAAQ;AAClB,YAAA,IAAI,MAAM,oDAAoD;AAAA,IACpE;AACD,SAAK,WAAW;AAChB,aAAS,KAAK,EAAE,SAAS,uBAAwB,CAAA;AAAA,EAClD;AACA;"}
|
|
@@ -9,40 +9,37 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
9
9
|
const authenticationApi = require("../clients/authenticationApi.cjs");
|
|
10
10
|
const coreApi = require("../clients/coreApi.cjs");
|
|
11
11
|
const customTypesApi = require("../clients/customTypesApi.cjs");
|
|
12
|
-
const manageV2 = require("../clients/manageV2.cjs");
|
|
13
12
|
const wroom = require("../clients/wroom.cjs");
|
|
14
13
|
const envVariableManager = require("../utils/envVariableManager.cjs");
|
|
15
14
|
const log = require("../utils/log.cjs");
|
|
16
15
|
const random = require("../utils/random.cjs");
|
|
17
16
|
const urls = require("../utils/urls.cjs");
|
|
18
17
|
const repository = require("./repository.cjs");
|
|
19
|
-
const createRepositoriesManager = (
|
|
20
|
-
return new RepositoriesManager(
|
|
18
|
+
const createRepositoriesManager = (urlConfig, auth) => {
|
|
19
|
+
return new RepositoriesManager(urlConfig, auth);
|
|
21
20
|
};
|
|
22
21
|
class RepositoriesManager {
|
|
23
22
|
/**
|
|
24
|
-
* @param
|
|
25
|
-
* required to setup the different clients.
|
|
23
|
+
* @param urlConfig - The base URL of the Wroom app.
|
|
26
24
|
* @param credentials - Authentication credentials (email and password)
|
|
27
25
|
*/
|
|
28
|
-
constructor(
|
|
29
|
-
__publicField(this, "
|
|
26
|
+
constructor(urlConfig, credentials) {
|
|
27
|
+
__publicField(this, "credentials");
|
|
28
|
+
__publicField(this, "urls");
|
|
30
29
|
__publicField(this, "wroomClient");
|
|
31
30
|
__publicField(this, "authClient");
|
|
32
|
-
__publicField(this, "manageV2Client");
|
|
33
31
|
/**
|
|
34
32
|
* helper to keep track of repositories across independent test phases (setup,
|
|
35
33
|
* teardown)
|
|
36
34
|
*/
|
|
37
35
|
__publicField(this, "repositories", new envVariableManager.EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.wroomClient = new wroom.WroomClient(this.
|
|
44
|
-
this.authClient = authenticationApi.createAuthenticationApiClient(this.
|
|
45
|
-
this.manageV2Client = new manageV2.ManageV2Client(this.config.urlConfig.baseURL, this.config.manageV2Config);
|
|
36
|
+
this.credentials = credentials;
|
|
37
|
+
if (typeof urlConfig === "string") {
|
|
38
|
+
urlConfig = this.inferUrls(urlConfig);
|
|
39
|
+
}
|
|
40
|
+
this.urls = urlConfig;
|
|
41
|
+
this.wroomClient = new wroom.WroomClient(this.urls.baseURL, this.credentials);
|
|
42
|
+
this.authClient = authenticationApi.createAuthenticationApiClient(this.urls.authenticationApi, this.credentials);
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
45
|
* If the baseURL is prismic.io, assume the other services have the format
|
|
@@ -104,7 +101,7 @@ class RepositoriesManager {
|
|
|
104
101
|
const profiler = log.logger.startTimer();
|
|
105
102
|
const post = async () => this.wroomClient.post(repository2, "app/settings/delete", {
|
|
106
103
|
confirm: repository2,
|
|
107
|
-
password: this.
|
|
104
|
+
password: this.credentials.password
|
|
108
105
|
});
|
|
109
106
|
const response = await post();
|
|
110
107
|
if (response.status !== 200) {
|
|
@@ -133,10 +130,10 @@ class RepositoriesManager {
|
|
|
133
130
|
* @param name - The name of the repository.
|
|
134
131
|
*/
|
|
135
132
|
getRepositoryManager(name) {
|
|
136
|
-
const customTypeClient = customTypesApi.createCustomTypesApiClient(this.
|
|
137
|
-
const coreApiUrl = urls.getRepositoryUrl(this.
|
|
133
|
+
const customTypeClient = customTypesApi.createCustomTypesApiClient(this.urls.customTypesApi, name, this.authClient);
|
|
134
|
+
const coreApiUrl = urls.getRepositoryUrl(this.urls.baseURL, name);
|
|
138
135
|
const coreApiClient = coreApi.createCoreApiClient(coreApiUrl, this.authClient);
|
|
139
|
-
return new repository.RepositoryManager(name, coreApiClient, this.
|
|
136
|
+
return new repository.RepositoryManager(name, coreApiClient, this.wroomClient, customTypeClient);
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
139
|
exports.RepositoriesManager = RepositoriesManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { Credentials } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCoreApiClient } from \"../clients/coreApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param urlConfig - If provided as an object:\n *\n * - {@link UrlConfig.baseURL}: The Prismic base URL.\n * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.\n * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.\n *\n * If provided as a string: It is treated as the base URL for Prismic. Other\n * URLs (Custom Types API, Auth API) will be derived from it.\n * @param auth - The authentication credentials\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\turlConfig: UrlConfig | string,\n\tauth: Credentials,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(urlConfig, auth);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly urls: UrlConfig;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param urlConfig - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turlConfig: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urlConfig === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig = this.inferUrls(urlConfig);\n\t\t}\n\t\tthis.urls = urlConfig;\n\t\tthis.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.urls.authenticationApi,\n\t\t\tthis.credentials,\n\t\t);\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"vue\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tprofiler.done({ message: `created repository '${repositoryName}'` });\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.credentials.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param name - The name of the repository.\n\t */\n\tgetRepositoryManager(name: string): RepositoryManager {\n\t\tconst customTypeClient = createCustomTypesApiClient(\n\t\t\tthis.urls.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(this.urls.baseURL, name);\n\t\tconst coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);\n\n\t\treturn new RepositoryManager(\n\t\t\tname,\n\t\t\tcoreApiClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t);\n\t}\n}\n\nexport type UrlConfig = {\n\t/** Prismic base url */\n\tbaseURL: string;\n\t/** Custom types api base url */\n\tcustomTypesApi: string;\n\t/** Auth service api base url */\n\tauthenticationApi: string;\n};\n"],"names":["EnvVariableManager","WroomClient","createAuthenticationApiClient","logger","randomString","logHttpResponse","repository","createCustomTypesApiClient","getRepositoryUrl","createCoreApiClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;;;AAgCa,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,WACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAIA,sCACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,cAAc,UAAU;AAEtB,kBAAA,KAAK,UAAU,SAAS;AAAA,IACpC;AACD,SAAK,OAAO;AACZ,SAAK,cAAc,IAAIC,kBAAY,KAAK,KAAK,SAAS,KAAK,WAAW;AACtE,SAAK,aAAaC,kBAAAA,8BACjB,KAA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ACxD,SAASA;AAAA,MACT,UAAU,KAAK,YAAY;AAAA,IAAA,CAC3B;AACI,UAAA,WAAW,MAAM;AACnB,QAAA,SAAS,WAAW,KAAK;AAGtB,YAAA,QAAQ,MAAM;AAChB,UAAA,MAAM,WAAW,KAAK;AACzBD,YAAA,gBAAgB,QAAQ;AACxB,cAAM,IAAI,MAAM,+BAA+BC,WAAU,EAAE;AAAA,MAC3D;AAAA,IACD;AACI,SAAA,aAAa,OAAOA,WAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuBA,WAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAWA,eAAc,cAAc;AAChC,YAAA,KAAK,iBAAiBA,WAAU;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqB,MAAY;AAChC,UAAM,mBAAmBC,eACxB,2BAAA,KAAK,KAAK,gBACV,MACA,KAAK,UAAU;AAEhB,UAAM,aAAaC,KAAAA,iBAAiB,KAAK,KAAK,SAAS,IAAI;AAC3D,UAAM,gBAAgBC,QAAA,oBAAoB,YAAY,KAAK,UAAU;AAErE,WAAO,IAAIC,WACV,kBAAA,MACA,eACA,KAAK,aACL,gBAAgB;AAAA,EAElB;AACA;;;"}
|
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Credentials } from "../types";
|
|
2
2
|
import { RepositoryConfig, RepositoryManager } from "./repository";
|
|
3
3
|
/**
|
|
4
4
|
* Factory method to create a RepositoriesManager to manage repositories test
|
|
5
5
|
* data.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* required to setup the RepositoriesManager.
|
|
7
|
+
* @param urlConfig - If provided as an object:
|
|
9
8
|
*
|
|
10
|
-
* - {@link
|
|
11
|
-
* - {@link
|
|
12
|
-
* - {@link
|
|
9
|
+
* - {@link UrlConfig.baseURL}: The Prismic base URL.
|
|
10
|
+
* - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.
|
|
11
|
+
* - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.
|
|
12
|
+
*
|
|
13
|
+
* If provided as a string: It is treated as the base URL for Prismic. Other
|
|
14
|
+
* URLs (Custom Types API, Auth API) will be derived from it.
|
|
15
|
+
* @param auth - The authentication credentials
|
|
13
16
|
*
|
|
14
17
|
* @returns An instance of {@link RepositoriesManager} to manage test data.
|
|
15
18
|
*/
|
|
16
|
-
export declare const createRepositoriesManager: (
|
|
19
|
+
export declare const createRepositoriesManager: (urlConfig: UrlConfig | string, auth: Credentials) => RepositoriesManager;
|
|
17
20
|
/** Utility object to manage Prismic test data */
|
|
18
21
|
export declare class RepositoriesManager {
|
|
19
|
-
private readonly
|
|
22
|
+
private readonly credentials;
|
|
23
|
+
private readonly urls;
|
|
20
24
|
private readonly wroomClient;
|
|
21
25
|
private readonly authClient;
|
|
22
|
-
private readonly manageV2Client;
|
|
23
26
|
/**
|
|
24
27
|
* helper to keep track of repositories across independent test phases (setup,
|
|
25
28
|
* teardown)
|
|
26
29
|
*/
|
|
27
30
|
private readonly repositories;
|
|
28
31
|
/**
|
|
29
|
-
* @param
|
|
30
|
-
* required to setup the different clients.
|
|
32
|
+
* @param urlConfig - The base URL of the Wroom app.
|
|
31
33
|
* @param credentials - Authentication credentials (email and password)
|
|
32
34
|
*/
|
|
33
|
-
constructor(
|
|
35
|
+
constructor(urlConfig: UrlConfig | string, credentials: Credentials);
|
|
34
36
|
/**
|
|
35
37
|
* If the baseURL is prismic.io, assume the other services have the format
|
|
36
38
|
* <name>.prismic.io
|
|
@@ -72,3 +74,11 @@ export declare class RepositoriesManager {
|
|
|
72
74
|
*/
|
|
73
75
|
getRepositoryManager(name: string): RepositoryManager;
|
|
74
76
|
}
|
|
77
|
+
export type UrlConfig = {
|
|
78
|
+
/** Prismic base url */
|
|
79
|
+
baseURL: string;
|
|
80
|
+
/** Custom types api base url */
|
|
81
|
+
customTypesApi: string;
|
|
82
|
+
/** Auth service api base url */
|
|
83
|
+
authenticationApi: string;
|
|
84
|
+
};
|
|
@@ -7,40 +7,37 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { createAuthenticationApiClient } from "../clients/authenticationApi.js";
|
|
8
8
|
import { createCoreApiClient } from "../clients/coreApi.js";
|
|
9
9
|
import { createCustomTypesApiClient } from "../clients/customTypesApi.js";
|
|
10
|
-
import { ManageV2Client } from "../clients/manageV2.js";
|
|
11
10
|
import { WroomClient } from "../clients/wroom.js";
|
|
12
11
|
import { EnvVariableManager } from "../utils/envVariableManager.js";
|
|
13
12
|
import { logger, logHttpResponse } from "../utils/log.js";
|
|
14
13
|
import { randomString } from "../utils/random.js";
|
|
15
14
|
import { getRepositoryUrl } from "../utils/urls.js";
|
|
16
15
|
import { RepositoryManager } from "./repository.js";
|
|
17
|
-
const createRepositoriesManager = (
|
|
18
|
-
return new RepositoriesManager(
|
|
16
|
+
const createRepositoriesManager = (urlConfig, auth) => {
|
|
17
|
+
return new RepositoriesManager(urlConfig, auth);
|
|
19
18
|
};
|
|
20
19
|
class RepositoriesManager {
|
|
21
20
|
/**
|
|
22
|
-
* @param
|
|
23
|
-
* required to setup the different clients.
|
|
21
|
+
* @param urlConfig - The base URL of the Wroom app.
|
|
24
22
|
* @param credentials - Authentication credentials (email and password)
|
|
25
23
|
*/
|
|
26
|
-
constructor(
|
|
27
|
-
__publicField(this, "
|
|
24
|
+
constructor(urlConfig, credentials) {
|
|
25
|
+
__publicField(this, "credentials");
|
|
26
|
+
__publicField(this, "urls");
|
|
28
27
|
__publicField(this, "wroomClient");
|
|
29
28
|
__publicField(this, "authClient");
|
|
30
|
-
__publicField(this, "manageV2Client");
|
|
31
29
|
/**
|
|
32
30
|
* helper to keep track of repositories across independent test phases (setup,
|
|
33
31
|
* teardown)
|
|
34
32
|
*/
|
|
35
33
|
__publicField(this, "repositories", new EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.wroomClient = new WroomClient(this.
|
|
42
|
-
this.authClient = createAuthenticationApiClient(this.
|
|
43
|
-
this.manageV2Client = new ManageV2Client(this.config.urlConfig.baseURL, this.config.manageV2Config);
|
|
34
|
+
this.credentials = credentials;
|
|
35
|
+
if (typeof urlConfig === "string") {
|
|
36
|
+
urlConfig = this.inferUrls(urlConfig);
|
|
37
|
+
}
|
|
38
|
+
this.urls = urlConfig;
|
|
39
|
+
this.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);
|
|
40
|
+
this.authClient = createAuthenticationApiClient(this.urls.authenticationApi, this.credentials);
|
|
44
41
|
}
|
|
45
42
|
/**
|
|
46
43
|
* If the baseURL is prismic.io, assume the other services have the format
|
|
@@ -102,7 +99,7 @@ class RepositoriesManager {
|
|
|
102
99
|
const profiler = logger.startTimer();
|
|
103
100
|
const post = async () => this.wroomClient.post(repository, "app/settings/delete", {
|
|
104
101
|
confirm: repository,
|
|
105
|
-
password: this.
|
|
102
|
+
password: this.credentials.password
|
|
106
103
|
});
|
|
107
104
|
const response = await post();
|
|
108
105
|
if (response.status !== 200) {
|
|
@@ -131,10 +128,10 @@ class RepositoriesManager {
|
|
|
131
128
|
* @param name - The name of the repository.
|
|
132
129
|
*/
|
|
133
130
|
getRepositoryManager(name) {
|
|
134
|
-
const customTypeClient = createCustomTypesApiClient(this.
|
|
135
|
-
const coreApiUrl = getRepositoryUrl(this.
|
|
131
|
+
const customTypeClient = createCustomTypesApiClient(this.urls.customTypesApi, name, this.authClient);
|
|
132
|
+
const coreApiUrl = getRepositoryUrl(this.urls.baseURL, name);
|
|
136
133
|
const coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);
|
|
137
|
-
return new RepositoryManager(name, coreApiClient, this.
|
|
134
|
+
return new RepositoryManager(name, coreApiClient, this.wroomClient, customTypeClient);
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
137
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { Credentials } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCoreApiClient } from \"../clients/coreApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param urlConfig - If provided as an object:\n *\n * - {@link UrlConfig.baseURL}: The Prismic base URL.\n * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.\n * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.\n *\n * If provided as a string: It is treated as the base URL for Prismic. Other\n * URLs (Custom Types API, Auth API) will be derived from it.\n * @param auth - The authentication credentials\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\turlConfig: UrlConfig | string,\n\tauth: Credentials,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(urlConfig, auth);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly urls: UrlConfig;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param urlConfig - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turlConfig: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urlConfig === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig = this.inferUrls(urlConfig);\n\t\t}\n\t\tthis.urls = urlConfig;\n\t\tthis.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.urls.authenticationApi,\n\t\t\tthis.credentials,\n\t\t);\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"vue\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tprofiler.done({ message: `created repository '${repositoryName}'` });\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.credentials.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param name - The name of the repository.\n\t */\n\tgetRepositoryManager(name: string): RepositoryManager {\n\t\tconst customTypeClient = createCustomTypesApiClient(\n\t\t\tthis.urls.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(this.urls.baseURL, name);\n\t\tconst coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);\n\n\t\treturn new RepositoryManager(\n\t\t\tname,\n\t\t\tcoreApiClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t);\n\t}\n}\n\nexport type UrlConfig = {\n\t/** Prismic base url */\n\tbaseURL: string;\n\t/** Custom types api base url */\n\tcustomTypesApi: string;\n\t/** Auth service api base url */\n\tauthenticationApi: string;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAgCa,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,WACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,cAAc,UAAU;AAEtB,kBAAA,KAAK,UAAU,SAAS;AAAA,IACpC;AACD,SAAK,OAAO;AACZ,SAAK,cAAc,IAAI,YAAY,KAAK,KAAK,SAAS,KAAK,WAAW;AACtE,SAAK,aAAa,8BACjB,KAAK,KAAK,mBACV,KAAK,WAAW;AAAA,EAElB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,UAAU,SAAe;AAC1B,UAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,UAAM,WAAW,IAAI,SAAS,MAAM,GAAG,EAAE;AAElC,WAAA;AAAA,MACN;AAAA,MACA,mBAAmB,GAAG,QAAQ,WAAW,IAAI,QAAQ;AAAA,MACrD,gBAAgB,GAAG,QAAQ,kBAAkB,IAAI,QAAQ;AAAA,IAAA;AAAA,EAE3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAe;AACb,WAAA,KAAK,WAAW;EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,iBACL,SAEuB,I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