@prismicio/e2e-tests-utils 1.0.0-alpha.1
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/LICENSE +202 -0
- package/README.md +128 -0
- package/dist/clients/authenticationApi.cjs +36 -0
- package/dist/clients/authenticationApi.cjs.map +1 -0
- package/dist/clients/authenticationApi.d.ts +6 -0
- package/dist/clients/authenticationApi.js +36 -0
- package/dist/clients/authenticationApi.js.map +1 -0
- package/dist/clients/customTypesApi.cjs +71 -0
- package/dist/clients/customTypesApi.cjs.map +1 -0
- package/dist/clients/customTypesApi.d.ts +11 -0
- package/dist/clients/customTypesApi.js +71 -0
- package/dist/clients/customTypesApi.js.map +1 -0
- package/dist/clients/wroom.cjs +78 -0
- package/dist/clients/wroom.cjs.map +1 -0
- package/dist/clients/wroom.d.ts +25 -0
- package/dist/clients/wroom.js +78 -0
- package/dist/clients/wroom.js.map +1 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/repositories.cjs +130 -0
- package/dist/managers/repositories.cjs.map +1 -0
- package/dist/managers/repositories.d.ts +84 -0
- package/dist/managers/repositories.js +130 -0
- package/dist/managers/repositories.js.map +1 -0
- package/dist/managers/repository.cjs +187 -0
- package/dist/managers/repository.cjs.map +1 -0
- package/dist/managers/repository.d.ts +114 -0
- package/dist/managers/repository.js +187 -0
- package/dist/managers/repository.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/utils/cookies.cjs +20 -0
- package/dist/utils/cookies.cjs.map +1 -0
- package/dist/utils/cookies.d.ts +8 -0
- package/dist/utils/cookies.js +20 -0
- package/dist/utils/cookies.js.map +1 -0
- package/dist/utils/envVariableManager.cjs +36 -0
- package/dist/utils/envVariableManager.cjs.map +1 -0
- package/dist/utils/envVariableManager.d.ts +16 -0
- package/dist/utils/envVariableManager.js +36 -0
- package/dist/utils/envVariableManager.js.map +1 -0
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.d.ts +3 -0
- package/dist/utils/log.js +25 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/random.cjs +9 -0
- package/dist/utils/random.cjs.map +1 -0
- package/dist/utils/random.d.ts +8 -0
- package/dist/utils/random.js +9 -0
- package/dist/utils/random.js.map +1 -0
- package/package.json +88 -0
- package/src/clients/authenticationApi.ts +53 -0
- package/src/clients/customTypesApi.ts +145 -0
- package/src/clients/wroom.ts +91 -0
- package/src/index.ts +3 -0
- package/src/managers/repositories.ts +194 -0
- package/src/managers/repository.ts +277 -0
- package/src/types.ts +1 -0
- package/src/utils/cookies.ts +30 -0
- package/src/utils/envVariableManager.ts +35 -0
- package/src/utils/log.ts +26 -0
- package/src/utils/random.ts +14 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
const axios = require("axios");
|
|
10
|
+
const cookies = require("../utils/cookies.cjs");
|
|
11
|
+
const log = require("../utils/log.cjs");
|
|
12
|
+
class WroomClient {
|
|
13
|
+
/**
|
|
14
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
15
|
+
* @param auth - Authentication credentials.
|
|
16
|
+
*/
|
|
17
|
+
constructor(baseURL, auth) {
|
|
18
|
+
__publicField(this, "auth");
|
|
19
|
+
__publicField(this, "client");
|
|
20
|
+
__publicField(this, "loggedIn", false);
|
|
21
|
+
this.auth = auth;
|
|
22
|
+
this.client = axios.create({
|
|
23
|
+
baseURL,
|
|
24
|
+
withCredentials: true,
|
|
25
|
+
validateStatus: () => true,
|
|
26
|
+
xsrfCookieName: "X_XSRF",
|
|
27
|
+
headers: {
|
|
28
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.client.interceptors.response.use((response) => {
|
|
32
|
+
const cookies$1 = response.headers["set-cookie"];
|
|
33
|
+
if (cookies$1 && cookies.extractCookie(cookies$1, "SESSION")) {
|
|
34
|
+
this.client.defaults.headers["Cookie"] = cookies$1;
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getBaseURL() {
|
|
40
|
+
return this.client.getUri();
|
|
41
|
+
}
|
|
42
|
+
/** authenticated POST request on the wroom backend */
|
|
43
|
+
async post(repository, path, data) {
|
|
44
|
+
if (!this.loggedIn) {
|
|
45
|
+
await this.login();
|
|
46
|
+
}
|
|
47
|
+
const url = new URL(path, this.client.getUri());
|
|
48
|
+
if (repository) {
|
|
49
|
+
url.hostname = `${repository}.${url.hostname}`;
|
|
50
|
+
}
|
|
51
|
+
const response = await this.client.post(url.toString(), data, {
|
|
52
|
+
params: {
|
|
53
|
+
_: cookies.extractCookie(this.client.defaults.headers["Cookie"], "X_XSRF")
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
60
|
+
*
|
|
61
|
+
* @throws Error if the login to Wroom fails.
|
|
62
|
+
*/
|
|
63
|
+
async login() {
|
|
64
|
+
const profiler = log.logger.startTimer();
|
|
65
|
+
const response = await this.client.post("/authentication/signin", {
|
|
66
|
+
email: this.auth.email,
|
|
67
|
+
password: this.auth.password
|
|
68
|
+
});
|
|
69
|
+
if (response.status !== 200) {
|
|
70
|
+
log.logHttpResponse(response);
|
|
71
|
+
throw new Error("Could not login to Prismic, check your credentials");
|
|
72
|
+
}
|
|
73
|
+
this.loggedIn = true;
|
|
74
|
+
profiler.done({ message: "logged in to Prismic" });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.WroomClient = WroomClient;
|
|
78
|
+
//# sourceMappingURL=wroom.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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\";\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 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\tconst url = new URL(path, this.client.getUri());\n\t\tif (repository) {\n\t\t\turl.hostname = `${repository}.${url.hostname}`;\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","logger","logHttpResponse"],"mappings":";;;;;;;;;;;MAWa,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,KACL,YACA,MACA,MAAc;AAEV,QAAA,CAAC,KAAK,UAAU;AACnB,YAAM,KAAK;IACX;AAED,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO,QAAQ;AAC9C,QAAI,YAAY;AACf,UAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAAA,IAC5C;AACK,UAAA,WAAW,MAAM,KAAK,OAAO,KAAK,IAAI,YAAY,MAAM;AAAA,MAC7D,QAAQ;AAAA,QACP,GAAGC,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,WAAWC,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;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { Credentials } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Client for interacting with the Wroom service to perform operations on
|
|
5
|
+
* repositories.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WroomClient {
|
|
8
|
+
private readonly auth;
|
|
9
|
+
private readonly client;
|
|
10
|
+
private loggedIn;
|
|
11
|
+
/**
|
|
12
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
13
|
+
* @param auth - Authentication credentials.
|
|
14
|
+
*/
|
|
15
|
+
constructor(baseURL: string, auth: Credentials);
|
|
16
|
+
getBaseURL(): string;
|
|
17
|
+
/** authenticated POST request on the wroom backend */
|
|
18
|
+
post(repository: string | null, path: string, data?: unknown): Promise<AxiosResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
21
|
+
*
|
|
22
|
+
* @throws Error if the login to Wroom fails.
|
|
23
|
+
*/
|
|
24
|
+
private login;
|
|
25
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import axios from "axios";
|
|
8
|
+
import { extractCookie } from "../utils/cookies.js";
|
|
9
|
+
import { logger, logHttpResponse } from "../utils/log.js";
|
|
10
|
+
class WroomClient {
|
|
11
|
+
/**
|
|
12
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
13
|
+
* @param auth - Authentication credentials.
|
|
14
|
+
*/
|
|
15
|
+
constructor(baseURL, auth) {
|
|
16
|
+
__publicField(this, "auth");
|
|
17
|
+
__publicField(this, "client");
|
|
18
|
+
__publicField(this, "loggedIn", false);
|
|
19
|
+
this.auth = auth;
|
|
20
|
+
this.client = axios.create({
|
|
21
|
+
baseURL,
|
|
22
|
+
withCredentials: true,
|
|
23
|
+
validateStatus: () => true,
|
|
24
|
+
xsrfCookieName: "X_XSRF",
|
|
25
|
+
headers: {
|
|
26
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
this.client.interceptors.response.use((response) => {
|
|
30
|
+
const cookies = response.headers["set-cookie"];
|
|
31
|
+
if (cookies && extractCookie(cookies, "SESSION")) {
|
|
32
|
+
this.client.defaults.headers["Cookie"] = cookies;
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getBaseURL() {
|
|
38
|
+
return this.client.getUri();
|
|
39
|
+
}
|
|
40
|
+
/** authenticated POST request on the wroom backend */
|
|
41
|
+
async post(repository, path, data) {
|
|
42
|
+
if (!this.loggedIn) {
|
|
43
|
+
await this.login();
|
|
44
|
+
}
|
|
45
|
+
const url = new URL(path, this.client.getUri());
|
|
46
|
+
if (repository) {
|
|
47
|
+
url.hostname = `${repository}.${url.hostname}`;
|
|
48
|
+
}
|
|
49
|
+
const response = await this.client.post(url.toString(), data, {
|
|
50
|
+
params: {
|
|
51
|
+
_: extractCookie(this.client.defaults.headers["Cookie"], "X_XSRF")
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
58
|
+
*
|
|
59
|
+
* @throws Error if the login to Wroom fails.
|
|
60
|
+
*/
|
|
61
|
+
async login() {
|
|
62
|
+
const profiler = logger.startTimer();
|
|
63
|
+
const response = await this.client.post("/authentication/signin", {
|
|
64
|
+
email: this.auth.email,
|
|
65
|
+
password: this.auth.password
|
|
66
|
+
});
|
|
67
|
+
if (response.status !== 200) {
|
|
68
|
+
logHttpResponse(response);
|
|
69
|
+
throw new Error("Could not login to Prismic, check your credentials");
|
|
70
|
+
}
|
|
71
|
+
this.loggedIn = true;
|
|
72
|
+
profiler.done({ message: "logged in to Prismic" });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
WroomClient
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=wroom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\";\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 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\tconst url = new URL(path, this.client.getUri());\n\t\tif (repository) {\n\t\t\turl.hostname = `${repository}.${url.hostname}`;\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":";;;;;;;;;MAWa,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,YAAA,UAAU,SAAS,QAAQ,YAAY;AAC7C,UAAI,WAAW,cAAc,SAAS,SAAS,GAAG;AACjD,aAAK,OAAO,SAAS,QAAQ,QAAQ,IAAI;AAAA,MACzC;AAEM,aAAA;AAAA,IAAA,CACP;AAAA,EACF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAAA;AAAA,EAGA,MAAM,KACL,YACA,MACA,MAAc;AAEV,QAAA,CAAC,KAAK,UAAU;AACnB,YAAM,KAAK;IACX;AAED,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO,QAAQ;AAC9C,QAAI,YAAY;AACf,UAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAAA,IAC5C;AACK,UAAA,WAAW,MAAM,KAAK,OAAO,KAAK,IAAI,YAAY,MAAM;AAAA,MAC7D,QAAQ;AAAA,QACP,GAAG,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,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;"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const repositories = require("./managers/repositories.cjs");
|
|
4
|
+
const repository = require("./managers/repository.cjs");
|
|
5
|
+
exports.RepositoriesManager = repositories.RepositoriesManager;
|
|
6
|
+
exports.createRepositoriesManager = repositories.createRepositoriesManager;
|
|
7
|
+
exports.RepositoryManager = repository.RepositoryManager;
|
|
8
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RepositoriesManager, createRepositoriesManager } from "./managers/repositories.js";
|
|
2
|
+
import { RepositoryManager } from "./managers/repository.js";
|
|
3
|
+
export {
|
|
4
|
+
RepositoriesManager,
|
|
5
|
+
RepositoryManager,
|
|
6
|
+
createRepositoriesManager
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
const authenticationApi = require("../clients/authenticationApi.cjs");
|
|
10
|
+
const customTypesApi = require("../clients/customTypesApi.cjs");
|
|
11
|
+
const wroom = require("../clients/wroom.cjs");
|
|
12
|
+
const envVariableManager = require("../utils/envVariableManager.cjs");
|
|
13
|
+
const log = require("../utils/log.cjs");
|
|
14
|
+
const random = require("../utils/random.cjs");
|
|
15
|
+
const repository = require("./repository.cjs");
|
|
16
|
+
const createRepositoriesManager = (urlConfig, auth) => {
|
|
17
|
+
return new RepositoriesManager(urlConfig, auth);
|
|
18
|
+
};
|
|
19
|
+
class RepositoriesManager {
|
|
20
|
+
/**
|
|
21
|
+
* @param prismicUrl - The base URL of the Wroom app.
|
|
22
|
+
* @param credentials - Authentication credentials (email and password)
|
|
23
|
+
*/
|
|
24
|
+
constructor(urls, credentials) {
|
|
25
|
+
__publicField(this, "credentials");
|
|
26
|
+
__publicField(this, "urls");
|
|
27
|
+
__publicField(this, "wroomClient");
|
|
28
|
+
__publicField(this, "authClient");
|
|
29
|
+
/**
|
|
30
|
+
* helper to keep track of repositories across independent test phases (setup,
|
|
31
|
+
* teardown)
|
|
32
|
+
*/
|
|
33
|
+
__publicField(this, "repositories", new envVariableManager.EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
|
|
34
|
+
this.credentials = credentials;
|
|
35
|
+
if (typeof urls === "string") {
|
|
36
|
+
urls = this.inferUrls(urls);
|
|
37
|
+
}
|
|
38
|
+
this.urls = urls;
|
|
39
|
+
this.wroomClient = new wroom.WroomClient(this.urls.baseURL, this.credentials);
|
|
40
|
+
this.authClient = authenticationApi.createAuthenticationApiClient(this.urls.authenticationApi, this.credentials);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* If the baseURL is prismic.io, assume the other services have the format
|
|
44
|
+
* <name>.prismic.io
|
|
45
|
+
*/
|
|
46
|
+
inferUrls(baseURL) {
|
|
47
|
+
const url = new URL(baseURL);
|
|
48
|
+
const protocol = url.protocol.slice(0, -1);
|
|
49
|
+
return {
|
|
50
|
+
baseURL,
|
|
51
|
+
authenticationApi: `${protocol}://auth.${url.hostname}`,
|
|
52
|
+
customTypesApi: `${protocol}://customtypes.${url.hostname}`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate a user token from the authentication service.
|
|
57
|
+
*
|
|
58
|
+
* @returns a JWT token
|
|
59
|
+
*/
|
|
60
|
+
async getUserApiToken() {
|
|
61
|
+
return this.authClient.getToken();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a new repository in Wroom.
|
|
65
|
+
*
|
|
66
|
+
* @param repositoryName - The name of the repository.
|
|
67
|
+
*
|
|
68
|
+
* @throws Error if the repository creation fails.
|
|
69
|
+
*/
|
|
70
|
+
async createRepository(config = {}) {
|
|
71
|
+
const profiler = log.logger.startTimer();
|
|
72
|
+
const { prefix = "e2e-tests" } = config;
|
|
73
|
+
const repositoryName = `${prefix}-${random.randomString()}`;
|
|
74
|
+
const response = await this.wroomClient.post(null, "/authentication/newrepository", {
|
|
75
|
+
domain: repositoryName,
|
|
76
|
+
framework: "next",
|
|
77
|
+
plan: "personal",
|
|
78
|
+
isAnnual: "false",
|
|
79
|
+
role: "developer"
|
|
80
|
+
});
|
|
81
|
+
if (response.status !== 200) {
|
|
82
|
+
log.logHttpResponse(response);
|
|
83
|
+
throw new Error(`Could not create repository ${repositoryName}`);
|
|
84
|
+
}
|
|
85
|
+
this.repositories.add(repositoryName);
|
|
86
|
+
profiler.done({ message: `created repository '${repositoryName}'` });
|
|
87
|
+
const repository2 = this.getRepositoryManager(repositoryName);
|
|
88
|
+
await repository2.configure(config);
|
|
89
|
+
return repository2;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Delete a repository from Wroom.
|
|
93
|
+
*
|
|
94
|
+
* @param repository - The name of the repository.
|
|
95
|
+
*
|
|
96
|
+
* @throws Error if the repository deletion fails.
|
|
97
|
+
*/
|
|
98
|
+
async deleteRepository(repository2) {
|
|
99
|
+
const profiler = log.logger.startTimer();
|
|
100
|
+
const response = await this.wroomClient.post(repository2, "./app/settings/delete", { confirm: repository2, password: this.credentials.password });
|
|
101
|
+
if (response.status !== 200) {
|
|
102
|
+
log.logHttpResponse(response);
|
|
103
|
+
throw new Error(`Could not delete repository ${repository2}`);
|
|
104
|
+
}
|
|
105
|
+
this.repositories.remove(repository2);
|
|
106
|
+
profiler.done({ message: `deleted repository '${repository2}'` });
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Cleanup test data. For example, it deletes repositories created using
|
|
110
|
+
* createRepository()
|
|
111
|
+
*/
|
|
112
|
+
async tearDown() {
|
|
113
|
+
const repositories = this.repositories.getAll();
|
|
114
|
+
for (const repository2 of repositories) {
|
|
115
|
+
await this.deleteRepository(repository2);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Return a repository utilities object for a repository.
|
|
120
|
+
*
|
|
121
|
+
* @param name - The name of the repository.
|
|
122
|
+
*/
|
|
123
|
+
getRepositoryManager(name) {
|
|
124
|
+
const customTypeClient = customTypesApi.createCustomTypesApiClient(this.urls.customTypesApi, name, this.authClient);
|
|
125
|
+
return new repository.RepositoryManager(name, this.wroomClient, customTypeClient);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.RepositoriesManager = RepositoriesManager;
|
|
129
|
+
exports.createRepositoriesManager = createRepositoriesManager;
|
|
130
|
+
//# sourceMappingURL=repositories.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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 { 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\";\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 prismicUrl - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turls: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urls === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turls = this.inferUrls(urls);\n\t\t}\n\t\tthis.urls = urls;\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: \"next\",\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 response = await this.wroomClient.post(\n\t\t\trepository,\n\t\t\t\"./app/settings/delete\",\n\t\t\t{ confirm: repository, password: this.credentials.password },\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not delete repository ${repository}`);\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\n\t\treturn new RepositoryManager(name, this.wroomClient, customTypeClient);\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","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,MACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAIA,sCACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,SAAS,UAAU;AAEtB,aAAA,KAAK,UAAU,IAAI;AAAA,IAC1B;AACD,SAAK,OAAO;AACZ,SAAK,cAAc,IAAIC,kBAAY,KAAK,KAAK,SAAS,KAAK,WAAW;AACtE,SAAK,aAAaC,kBAAAA,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,IAAE;AAEnB,UAAA,WAAWC,WAAO;AAElB,UAAA,EAAE,SAAS,YAAgB,IAAA;AACjC,UAAM,iBAAiB,GAAG,MAAM,IAAIC,OAAAA,aAAc,CAAA;AAElD,UAAM,WAAW,MAAM,KAAK,YAAY,KACvC,MACA,iCACA;AAAA,MACC,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,MACV,MAAM;AAAA,IAAA,CACN;AAEE,QAAA,SAAS,WAAW,KAAK;AAC5BC,UAAA,gBAAgB,QAAQ;AACxB,YAAM,IAAI,MAAM,+BAA+B,cAAc,EAAE;AAAA,IAC/D;AACI,SAAA,aAAa,IAAI,cAAc;AAEpC,aAAS,KAAK,EAAE,SAAS,uBAAuB,cAAc,KAAK;AAE7D,UAAAC,cAAa,KAAK,qBAAqB,cAAc;AACrD,UAAAA,YAAW,UAAU,MAAM;AAE1B,WAAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,iBAAiBA,aAAkB;AAClC,UAAA,WAAWH,WAAO;AAExB,UAAM,WAAW,MAAM,KAAK,YAAY,KACvCG,aACA,yBACA,EAAE,SAASA,aAAY,UAAU,KAAK,YAAY,SAAU,CAAA;AAEzD,QAAA,SAAS,WAAW,KAAK;AAC5BD,UAAA,gBAAgB,QAAQ;AACxB,YAAM,IAAI,MAAM,+BAA+BC,WAAU,EAAE;AAAA,IAC3D;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;AAGhB,WAAO,IAAIC,WAAA,kBAAkB,MAAM,KAAK,aAAa,gBAAgB;AAAA,EACtE;AACA;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Credentials } from "../types";
|
|
2
|
+
import { RepositoryConfig, RepositoryManager } from "./repository";
|
|
3
|
+
/**
|
|
4
|
+
* Factory method to create a RepositoriesManager to manage repositories test
|
|
5
|
+
* data.
|
|
6
|
+
*
|
|
7
|
+
* @param urlConfig - If provided as an object:
|
|
8
|
+
*
|
|
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
|
|
16
|
+
*
|
|
17
|
+
* @returns An instance of {@link RepositoriesManager} to manage test data.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createRepositoriesManager: (urlConfig: UrlConfig | string, auth: Credentials) => RepositoriesManager;
|
|
20
|
+
/** Utility object to manage Prismic test data */
|
|
21
|
+
export declare class RepositoriesManager {
|
|
22
|
+
private readonly credentials;
|
|
23
|
+
private readonly urls;
|
|
24
|
+
private readonly wroomClient;
|
|
25
|
+
private readonly authClient;
|
|
26
|
+
/**
|
|
27
|
+
* helper to keep track of repositories across independent test phases (setup,
|
|
28
|
+
* teardown)
|
|
29
|
+
*/
|
|
30
|
+
private readonly repositories;
|
|
31
|
+
/**
|
|
32
|
+
* @param prismicUrl - The base URL of the Wroom app.
|
|
33
|
+
* @param credentials - Authentication credentials (email and password)
|
|
34
|
+
*/
|
|
35
|
+
constructor(urls: UrlConfig | string, credentials: Credentials);
|
|
36
|
+
/**
|
|
37
|
+
* If the baseURL is prismic.io, assume the other services have the format
|
|
38
|
+
* <name>.prismic.io
|
|
39
|
+
*/
|
|
40
|
+
private inferUrls;
|
|
41
|
+
/**
|
|
42
|
+
* Generate a user token from the authentication service.
|
|
43
|
+
*
|
|
44
|
+
* @returns a JWT token
|
|
45
|
+
*/
|
|
46
|
+
getUserApiToken(): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Create a new repository in Wroom.
|
|
49
|
+
*
|
|
50
|
+
* @param repositoryName - The name of the repository.
|
|
51
|
+
*
|
|
52
|
+
* @throws Error if the repository creation fails.
|
|
53
|
+
*/
|
|
54
|
+
createRepository(config?: {
|
|
55
|
+
prefix?: string;
|
|
56
|
+
} & RepositoryConfig): Promise<RepositoryManager>;
|
|
57
|
+
/**
|
|
58
|
+
* Delete a repository from Wroom.
|
|
59
|
+
*
|
|
60
|
+
* @param repository - The name of the repository.
|
|
61
|
+
*
|
|
62
|
+
* @throws Error if the repository deletion fails.
|
|
63
|
+
*/
|
|
64
|
+
deleteRepository(repository: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Cleanup test data. For example, it deletes repositories created using
|
|
67
|
+
* createRepository()
|
|
68
|
+
*/
|
|
69
|
+
tearDown(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Return a repository utilities object for a repository.
|
|
72
|
+
*
|
|
73
|
+
* @param name - The name of the repository.
|
|
74
|
+
*/
|
|
75
|
+
getRepositoryManager(name: string): RepositoryManager;
|
|
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
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { createAuthenticationApiClient } from "../clients/authenticationApi.js";
|
|
8
|
+
import { createCustomTypesApiClient } from "../clients/customTypesApi.js";
|
|
9
|
+
import { WroomClient } from "../clients/wroom.js";
|
|
10
|
+
import { EnvVariableManager } from "../utils/envVariableManager.js";
|
|
11
|
+
import { logger, logHttpResponse } from "../utils/log.js";
|
|
12
|
+
import { randomString } from "../utils/random.js";
|
|
13
|
+
import { RepositoryManager } from "./repository.js";
|
|
14
|
+
const createRepositoriesManager = (urlConfig, auth) => {
|
|
15
|
+
return new RepositoriesManager(urlConfig, auth);
|
|
16
|
+
};
|
|
17
|
+
class RepositoriesManager {
|
|
18
|
+
/**
|
|
19
|
+
* @param prismicUrl - The base URL of the Wroom app.
|
|
20
|
+
* @param credentials - Authentication credentials (email and password)
|
|
21
|
+
*/
|
|
22
|
+
constructor(urls, credentials) {
|
|
23
|
+
__publicField(this, "credentials");
|
|
24
|
+
__publicField(this, "urls");
|
|
25
|
+
__publicField(this, "wroomClient");
|
|
26
|
+
__publicField(this, "authClient");
|
|
27
|
+
/**
|
|
28
|
+
* helper to keep track of repositories across independent test phases (setup,
|
|
29
|
+
* teardown)
|
|
30
|
+
*/
|
|
31
|
+
__publicField(this, "repositories", new EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
|
|
32
|
+
this.credentials = credentials;
|
|
33
|
+
if (typeof urls === "string") {
|
|
34
|
+
urls = this.inferUrls(urls);
|
|
35
|
+
}
|
|
36
|
+
this.urls = urls;
|
|
37
|
+
this.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);
|
|
38
|
+
this.authClient = createAuthenticationApiClient(this.urls.authenticationApi, this.credentials);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* If the baseURL is prismic.io, assume the other services have the format
|
|
42
|
+
* <name>.prismic.io
|
|
43
|
+
*/
|
|
44
|
+
inferUrls(baseURL) {
|
|
45
|
+
const url = new URL(baseURL);
|
|
46
|
+
const protocol = url.protocol.slice(0, -1);
|
|
47
|
+
return {
|
|
48
|
+
baseURL,
|
|
49
|
+
authenticationApi: `${protocol}://auth.${url.hostname}`,
|
|
50
|
+
customTypesApi: `${protocol}://customtypes.${url.hostname}`
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generate a user token from the authentication service.
|
|
55
|
+
*
|
|
56
|
+
* @returns a JWT token
|
|
57
|
+
*/
|
|
58
|
+
async getUserApiToken() {
|
|
59
|
+
return this.authClient.getToken();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a new repository in Wroom.
|
|
63
|
+
*
|
|
64
|
+
* @param repositoryName - The name of the repository.
|
|
65
|
+
*
|
|
66
|
+
* @throws Error if the repository creation fails.
|
|
67
|
+
*/
|
|
68
|
+
async createRepository(config = {}) {
|
|
69
|
+
const profiler = logger.startTimer();
|
|
70
|
+
const { prefix = "e2e-tests" } = config;
|
|
71
|
+
const repositoryName = `${prefix}-${randomString()}`;
|
|
72
|
+
const response = await this.wroomClient.post(null, "/authentication/newrepository", {
|
|
73
|
+
domain: repositoryName,
|
|
74
|
+
framework: "next",
|
|
75
|
+
plan: "personal",
|
|
76
|
+
isAnnual: "false",
|
|
77
|
+
role: "developer"
|
|
78
|
+
});
|
|
79
|
+
if (response.status !== 200) {
|
|
80
|
+
logHttpResponse(response);
|
|
81
|
+
throw new Error(`Could not create repository ${repositoryName}`);
|
|
82
|
+
}
|
|
83
|
+
this.repositories.add(repositoryName);
|
|
84
|
+
profiler.done({ message: `created repository '${repositoryName}'` });
|
|
85
|
+
const repository = this.getRepositoryManager(repositoryName);
|
|
86
|
+
await repository.configure(config);
|
|
87
|
+
return repository;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete a repository from Wroom.
|
|
91
|
+
*
|
|
92
|
+
* @param repository - The name of the repository.
|
|
93
|
+
*
|
|
94
|
+
* @throws Error if the repository deletion fails.
|
|
95
|
+
*/
|
|
96
|
+
async deleteRepository(repository) {
|
|
97
|
+
const profiler = logger.startTimer();
|
|
98
|
+
const response = await this.wroomClient.post(repository, "./app/settings/delete", { confirm: repository, password: this.credentials.password });
|
|
99
|
+
if (response.status !== 200) {
|
|
100
|
+
logHttpResponse(response);
|
|
101
|
+
throw new Error(`Could not delete repository ${repository}`);
|
|
102
|
+
}
|
|
103
|
+
this.repositories.remove(repository);
|
|
104
|
+
profiler.done({ message: `deleted repository '${repository}'` });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Cleanup test data. For example, it deletes repositories created using
|
|
108
|
+
* createRepository()
|
|
109
|
+
*/
|
|
110
|
+
async tearDown() {
|
|
111
|
+
const repositories = this.repositories.getAll();
|
|
112
|
+
for (const repository of repositories) {
|
|
113
|
+
await this.deleteRepository(repository);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Return a repository utilities object for a repository.
|
|
118
|
+
*
|
|
119
|
+
* @param name - The name of the repository.
|
|
120
|
+
*/
|
|
121
|
+
getRepositoryManager(name) {
|
|
122
|
+
const customTypeClient = createCustomTypesApiClient(this.urls.customTypesApi, name, this.authClient);
|
|
123
|
+
return new RepositoryManager(name, this.wroomClient, customTypeClient);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export {
|
|
127
|
+
RepositoriesManager,
|
|
128
|
+
createRepositoriesManager
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=repositories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 { 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\";\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 prismicUrl - The base URL of the Wroom app.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(\n\t\turls: UrlConfig | string,\n\t\tprivate readonly credentials: Credentials,\n\t) {\n\t\tif (typeof urls === \"string\") {\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turls = this.inferUrls(urls);\n\t\t}\n\t\tthis.urls = urls;\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: \"next\",\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 response = await this.wroomClient.post(\n\t\t\trepository,\n\t\t\t\"./app/settings/delete\",\n\t\t\t{ confirm: repository, password: this.credentials.password },\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not delete repository ${repository}`);\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\n\t\treturn new RepositoryManager(name, this.wroomClient, customTypeClient);\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":";;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,WACA,SACwB;AACjB,SAAA,IAAI,oBAAoB,WAAW,IAAI;AAC/C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB/B,YACC,MACiB,aAAwB;AAAxB;AAjBD;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAST,SAAW,cAAX;AAEb,QAAA,OAAO,SAAS,UAAU;AAEtB,aAAA,KAAK,UAAU,IAAI;AAAA,IAC1B;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,IAAE;AAEnB,UAAA,WAAW,OAAO;AAElB,UAAA,EAAE,SAAS,YAAgB,IAAA;AACjC,UAAM,iBAAiB,GAAG,MAAM,IAAI,aAAc,CAAA;AAElD,UAAM,WAAW,MAAM,KAAK,YAAY,KACvC,MACA,iCACA;AAAA,MACC,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,MACV,MAAM;AAAA,IAAA,CACN;AAEE,QAAA,SAAS,WAAW,KAAK;AAC5B,sBAAgB,QAAQ;AACxB,YAAM,IAAI,MAAM,+BAA+B,cAAc,EAAE;AAAA,IAC/D;AACI,SAAA,aAAa,IAAI,cAAc;AAEpC,aAAS,KAAK,EAAE,SAAS,uBAAuB,cAAc,KAAK;AAE7D,UAAA,aAAa,KAAK,qBAAqB,cAAc;AACrD,UAAA,WAAW,UAAU,MAAM;AAE1B,WAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,iBAAiB,YAAkB;AAClC,UAAA,WAAW,OAAO;AAExB,UAAM,WAAW,MAAM,KAAK,YAAY,KACvC,YACA,yBACA,EAAE,SAAS,YAAY,UAAU,KAAK,YAAY,SAAU,CAAA;AAEzD,QAAA,SAAS,WAAW,KAAK;AAC5B,sBAAgB,QAAQ;AACxB,YAAM,IAAI,MAAM,+BAA+B,UAAU,EAAE;AAAA,IAC3D;AACI,SAAA,aAAa,OAAO,UAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuB,UAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAW,cAAc,cAAc;AAChC,YAAA,KAAK,iBAAiB,UAAU;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqB,MAAY;AAChC,UAAM,mBAAmB,2BACxB,KAAK,KAAK,gBACV,MACA,KAAK,UAAU;AAGhB,WAAO,IAAI,kBAAkB,MAAM,KAAK,aAAa,gBAAgB;AAAA,EACtE;AACA;"}
|