@prismicio/e2e-tests-utils 1.2.0 → 1.3.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.
@@ -65,6 +65,34 @@ 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 params = new URLSearchParams({ email, profile: role });
79
+ const path = `/app/settings/users/profiles?${params.toString()}`;
80
+ return this.post(repository, path);
81
+ }
82
+ /**
83
+ * Update the role of a user in the repository
84
+ *
85
+ * @param {string} repository - The repository name
86
+ * @param {string} email - The email of the user
87
+ * @param {string} rolePerLocal - The role per local object
88
+ *
89
+ * @returns The Axios Reponse
90
+ */
91
+ async updateRolePerLocal(repository, email, rolePerLocal) {
92
+ const params = new URLSearchParams({ email });
93
+ const path = `/app/settings/users/rolesperlocale?${params.toString()}`;
94
+ return this.post(repository, path, rolePerLocal);
95
+ }
68
96
  /**
69
97
  * Authenticate Wroom to call Wroom unofficial endpoints.
70
98
  *
@@ -1 +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\";\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,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,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,YAAA,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,YAAA,iBAAiB,KAAK,UAAU;AAAA,IACtC;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;"}
1
+ {"version":3,"file":"wroom.js","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { AuthConfig } 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: AuthConfig,\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 * Update the role of a user in the repository\n\t *\n\t * @param {string} repository - The repository name\n\t * @param {string} email - The email of the user\n\t * @param {string} role - The new role to be given\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRole(\n\t\trepository: string,\n\t\temail: string,\n\t\trole: string,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email, profile: role });\n\t\tconst path = `/app/settings/users/profiles?${params.toString()}`;\n\n\t\treturn this.post(repository, path);\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param {string} repository - The repository name\n\t * @param {string} email - The email of the user\n\t * @param {string} rolePerLocal - The role per local object\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRolePerLocal(\n\t\trepository: string,\n\t\temail: string,\n\t\trolePerLocal: Record<string, string>,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email });\n\t\tconst path = `/app/settings/users/rolesperlocale?${params.toString()}`;\n\n\t\treturn this.post(repository, path, rolePerLocal);\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,EAQvB,YACC,SACiB,MAAgB;AAAhB;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;AAA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AAU;AAEpE,WAAO,KAAK,KAAK,YAAY,MAAM,YAAY;AAAA,EAChD;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;"}
@@ -9,37 +9,40 @@ 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");
12
13
  const wroom = require("../clients/wroom.cjs");
13
14
  const envVariableManager = require("../utils/envVariableManager.cjs");
14
15
  const log = require("../utils/log.cjs");
15
16
  const random = require("../utils/random.cjs");
16
17
  const urls = require("../utils/urls.cjs");
17
18
  const repository = require("./repository.cjs");
18
- const createRepositoriesManager = (urlConfig, auth) => {
19
- return new RepositoriesManager(urlConfig, auth);
19
+ const createRepositoriesManager = (configuration) => {
20
+ return new RepositoriesManager(configuration);
20
21
  };
21
22
  class RepositoriesManager {
22
23
  /**
23
- * @param urlConfig - The base URL of the Wroom app.
24
+ * @param configuration - Global object containing the different configuration
25
+ * required to setup the different clients.
24
26
  * @param credentials - Authentication credentials (email and password)
25
27
  */
26
- constructor(urlConfig, credentials) {
27
- __publicField(this, "credentials");
28
- __publicField(this, "urls");
28
+ constructor(configuration) {
29
+ __publicField(this, "config");
29
30
  __publicField(this, "wroomClient");
30
31
  __publicField(this, "authClient");
32
+ __publicField(this, "manageV2Client");
31
33
  /**
32
34
  * helper to keep track of repositories across independent test phases (setup,
33
35
  * teardown)
34
36
  */
35
37
  __publicField(this, "repositories", new envVariableManager.EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
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);
38
+ this.config = {
39
+ ...configuration,
40
+ // When a string is provided, treat it as the 'base' property
41
+ urlConfig: typeof configuration.urlConfig === "string" ? this.inferUrls(configuration.urlConfig) : configuration.urlConfig
42
+ };
43
+ this.wroomClient = new wroom.WroomClient(this.config.urlConfig.baseURL, this.config.authConfig);
44
+ this.authClient = authenticationApi.createAuthenticationApiClient(this.config.urlConfig.authenticationApi, this.config.authConfig);
45
+ this.manageV2Client = new manageV2.ManageV2Client(this.config.urlConfig.baseURL, this.config.manageV2Config);
43
46
  }
44
47
  /**
45
48
  * If the baseURL is prismic.io, assume the other services have the format
@@ -101,7 +104,7 @@ class RepositoriesManager {
101
104
  const profiler = log.logger.startTimer();
102
105
  const post = async () => this.wroomClient.post(repository2, "app/settings/delete", {
103
106
  confirm: repository2,
104
- password: this.credentials.password
107
+ password: this.config.authConfig.password
105
108
  });
106
109
  const response = await post();
107
110
  if (response.status !== 200) {
@@ -130,10 +133,10 @@ class RepositoriesManager {
130
133
  * @param name - The name of the repository.
131
134
  */
132
135
  getRepositoryManager(name) {
133
- const customTypeClient = customTypesApi.createCustomTypesApiClient(this.urls.customTypesApi, name, this.authClient);
134
- const coreApiUrl = urls.getRepositoryUrl(this.urls.baseURL, name);
136
+ const customTypeClient = customTypesApi.createCustomTypesApiClient(this.config.urlConfig.customTypesApi, name, this.authClient);
137
+ const coreApiUrl = urls.getRepositoryUrl(this.config.urlConfig.baseURL, name);
135
138
  const coreApiClient = coreApi.createCoreApiClient(coreApiUrl, this.authClient);
136
- return new repository.RepositoryManager(name, coreApiClient, this.wroomClient, customTypeClient);
139
+ return new repository.RepositoryManager(name, coreApiClient, this.authClient, this.wroomClient, customTypeClient, this.manageV2Client);
137
140
  }
138
141
  }
139
142
  exports.RepositoriesManager = RepositoriesManager;
@@ -1 +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 { 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,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,gBAA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;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
+ {"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { SetupConfiguration, UrlConfig } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCoreApiClient } from \"../clients/coreApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { ManageV2Client } from \"../clients/manageV2\";\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 configuration - Global object containing the different configurations\n * required to setup the RepositoriesManager.\n *\n * - {@link configuration.urlConfig}: Configuration around the API's URLs management.\n * - {@link configuration.authConfig}: Configuration around the authentication of a user.\n * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\tconfiguration: SetupConfiguration,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(configuration);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly config: Omit<SetupConfiguration, \"urlConfig\"> & {\n\t\turlConfig: UrlConfig;\n\t};\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\tprivate readonly manageV2Client: ManageV2Client;\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 configuration - Global object containing the different configuration\n\t * required to setup the different clients.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(configuration: SetupConfiguration) {\n\t\tthis.config = {\n\t\t\t...configuration,\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig:\n\t\t\t\ttypeof configuration.urlConfig === \"string\"\n\t\t\t\t\t? this.inferUrls(configuration.urlConfig)\n\t\t\t\t\t: configuration.urlConfig,\n\t\t};\n\n\t\tthis.wroomClient = new WroomClient(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.config.urlConfig.authenticationApi,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.manageV2Client = new ManageV2Client(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.manageV2Config,\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.config.authConfig.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.config.urlConfig.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(this.config.urlConfig.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.authClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t\tthis.manageV2Client,\n\t\t);\n\t}\n}\n"],"names":["EnvVariableManager","WroomClient","createAuthenticationApiClient","ManageV2Client","logger","randomString","logHttpResponse","repository","createCustomTypesApiClient","getRepositoryUrl","createCoreApiClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,kBACwB;AACjB,SAAA,IAAI,oBAAoB,aAAa;AAC7C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB/B,YAAY,eAAiC;AAnB5B;AAGA;AACA;AACA;AAKA;AAAA;AAAA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AAc;AAAA,EAErB;AACA;;;"}
@@ -1,38 +1,36 @@
1
- import { Credentials } from "../types";
1
+ import { SetupConfiguration } 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 urlConfig - If provided as an object:
7
+ * @param configuration - Global object containing the different configurations
8
+ * required to setup the RepositoriesManager.
8
9
  *
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
10
+ * - {@link configuration.urlConfig}: Configuration around the API's URLs management.
11
+ * - {@link configuration.authConfig}: Configuration around the authentication of a user.
12
+ * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.
16
13
  *
17
14
  * @returns An instance of {@link RepositoriesManager} to manage test data.
18
15
  */
19
- export declare const createRepositoriesManager: (urlConfig: UrlConfig | string, auth: Credentials) => RepositoriesManager;
16
+ export declare const createRepositoriesManager: (configuration: SetupConfiguration) => RepositoriesManager;
20
17
  /** Utility object to manage Prismic test data */
21
18
  export declare class RepositoriesManager {
22
- private readonly credentials;
23
- private readonly urls;
19
+ private readonly config;
24
20
  private readonly wroomClient;
25
21
  private readonly authClient;
22
+ private readonly manageV2Client;
26
23
  /**
27
24
  * helper to keep track of repositories across independent test phases (setup,
28
25
  * teardown)
29
26
  */
30
27
  private readonly repositories;
31
28
  /**
32
- * @param urlConfig - The base URL of the Wroom app.
29
+ * @param configuration - Global object containing the different configuration
30
+ * required to setup the different clients.
33
31
  * @param credentials - Authentication credentials (email and password)
34
32
  */
35
- constructor(urlConfig: UrlConfig | string, credentials: Credentials);
33
+ constructor(configuration: SetupConfiguration);
36
34
  /**
37
35
  * If the baseURL is prismic.io, assume the other services have the format
38
36
  * <name>.prismic.io
@@ -74,11 +72,3 @@ export declare class RepositoriesManager {
74
72
  */
75
73
  getRepositoryManager(name: string): RepositoryManager;
76
74
  }
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,37 +7,40 @@ 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";
10
11
  import { WroomClient } from "../clients/wroom.js";
11
12
  import { EnvVariableManager } from "../utils/envVariableManager.js";
12
13
  import { logger, logHttpResponse } from "../utils/log.js";
13
14
  import { randomString } from "../utils/random.js";
14
15
  import { getRepositoryUrl } from "../utils/urls.js";
15
16
  import { RepositoryManager } from "./repository.js";
16
- const createRepositoriesManager = (urlConfig, auth) => {
17
- return new RepositoriesManager(urlConfig, auth);
17
+ const createRepositoriesManager = (configuration) => {
18
+ return new RepositoriesManager(configuration);
18
19
  };
19
20
  class RepositoriesManager {
20
21
  /**
21
- * @param urlConfig - The base URL of the Wroom app.
22
+ * @param configuration - Global object containing the different configuration
23
+ * required to setup the different clients.
22
24
  * @param credentials - Authentication credentials (email and password)
23
25
  */
24
- constructor(urlConfig, credentials) {
25
- __publicField(this, "credentials");
26
- __publicField(this, "urls");
26
+ constructor(configuration) {
27
+ __publicField(this, "config");
27
28
  __publicField(this, "wroomClient");
28
29
  __publicField(this, "authClient");
30
+ __publicField(this, "manageV2Client");
29
31
  /**
30
32
  * helper to keep track of repositories across independent test phases (setup,
31
33
  * teardown)
32
34
  */
33
35
  __publicField(this, "repositories", new EnvVariableManager("_PRISMIC_E2E_TESTS_REPOS"));
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);
36
+ this.config = {
37
+ ...configuration,
38
+ // When a string is provided, treat it as the 'base' property
39
+ urlConfig: typeof configuration.urlConfig === "string" ? this.inferUrls(configuration.urlConfig) : configuration.urlConfig
40
+ };
41
+ this.wroomClient = new WroomClient(this.config.urlConfig.baseURL, this.config.authConfig);
42
+ this.authClient = createAuthenticationApiClient(this.config.urlConfig.authenticationApi, this.config.authConfig);
43
+ this.manageV2Client = new ManageV2Client(this.config.urlConfig.baseURL, this.config.manageV2Config);
41
44
  }
42
45
  /**
43
46
  * If the baseURL is prismic.io, assume the other services have the format
@@ -99,7 +102,7 @@ class RepositoriesManager {
99
102
  const profiler = logger.startTimer();
100
103
  const post = async () => this.wroomClient.post(repository, "app/settings/delete", {
101
104
  confirm: repository,
102
- password: this.credentials.password
105
+ password: this.config.authConfig.password
103
106
  });
104
107
  const response = await post();
105
108
  if (response.status !== 200) {
@@ -128,10 +131,10 @@ class RepositoriesManager {
128
131
  * @param name - The name of the repository.
129
132
  */
130
133
  getRepositoryManager(name) {
131
- const customTypeClient = createCustomTypesApiClient(this.urls.customTypesApi, name, this.authClient);
132
- const coreApiUrl = getRepositoryUrl(this.urls.baseURL, name);
134
+ const customTypeClient = createCustomTypesApiClient(this.config.urlConfig.customTypesApi, name, this.authClient);
135
+ const coreApiUrl = getRepositoryUrl(this.config.urlConfig.baseURL, name);
133
136
  const coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);
134
- return new RepositoryManager(name, coreApiClient, this.wroomClient, customTypeClient);
137
+ return new RepositoryManager(name, coreApiClient, this.authClient, this.wroomClient, customTypeClient, this.manageV2Client);
135
138
  }
136
139
  }
137
140
  export {
@@ -1 +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 { 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,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,gCACA;AAAA,MACC,QAAQ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,oBAAoB,YAAY,KAAK,UAAU;AAErE,WAAO,IAAI,kBACV,MACA,eACA,KAAK,aACL,gBAAgB;AAAA,EAElB;AACA;"}
1
+ {"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { SetupConfiguration, UrlConfig } from \"../types\";\n\nimport {\n\tAuthenticationClient,\n\tcreateAuthenticationApiClient,\n} from \"../clients/authenticationApi\";\nimport { createCoreApiClient } from \"../clients/coreApi\";\nimport { createCustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { ManageV2Client } from \"../clients/manageV2\";\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 configuration - Global object containing the different configurations\n * required to setup the RepositoriesManager.\n *\n * - {@link configuration.urlConfig}: Configuration around the API's URLs management.\n * - {@link configuration.authConfig}: Configuration around the authentication of a user.\n * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\tconfiguration: SetupConfiguration,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(configuration);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly config: Omit<SetupConfiguration, \"urlConfig\"> & {\n\t\turlConfig: UrlConfig;\n\t};\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationClient;\n\tprivate readonly manageV2Client: ManageV2Client;\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 configuration - Global object containing the different configuration\n\t * required to setup the different clients.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(configuration: SetupConfiguration) {\n\t\tthis.config = {\n\t\t\t...configuration,\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig:\n\t\t\t\ttypeof configuration.urlConfig === \"string\"\n\t\t\t\t\t? this.inferUrls(configuration.urlConfig)\n\t\t\t\t\t: configuration.urlConfig,\n\t\t};\n\n\t\tthis.wroomClient = new WroomClient(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.authClient = createAuthenticationApiClient(\n\t\t\tthis.config.urlConfig.authenticationApi,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.manageV2Client = new ManageV2Client(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.manageV2Config,\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.config.authConfig.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.config.urlConfig.customTypesApi,\n\t\t\tname,\n\t\t\tthis.authClient,\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(this.config.urlConfig.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.authClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t\tthis.manageV2Client,\n\t\t);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,kBACwB;AACjB,SAAA,IAAI,oBAAoB,aAAa;AAC7C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB/B,YAAY,eAAiC;AAnB5B;AAGA;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAS1B,SAAK,SAAS;AAAA,MACb,GAAG;AAAA;AAAA,MAEH,WACC,OAAO,cAAc,cAAc,WAChC,KAAK,UAAU,cAAc,SAAS,IACtC,cAAc;AAAA,IAAA;AAGd,SAAA,cAAc,IAAI,YACtB,KAAK,OAAO,UAAU,SACtB,KAAK,OAAO,UAAU;AAElB,SAAA,aAAa,8BACjB,KAAK,OAAO,UAAU,mBACtB,KAAK,OAAO,UAAU;AAElB,SAAA,iBAAiB,IAAI,eACzB,KAAK,OAAO,UAAU,SACtB,KAAK,OAAO,cAAc;AAAA,EAE5B;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,W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AA,IACD;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;AAC1B,UAAA,mBAAmB,2BACxB,KAAK,OAAO,UAAU,gBACtB,MACA,KAAK,UAAU;AAEhB,UAAM,aAAa,iBAAiB,KAAK,OAAO,UAAU,SAAS,IAAI;AACvE,UAAM,gBAAgB,oBAAoB,YAAY,KAAK,UAAU;AAE9D,WAAA,IAAI,kBACV,MACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,KAAK,cAAc;AAAA,EAErB;AACA;"}
@@ -9,15 +9,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  const log = require("../utils/log.cjs");
10
10
  const urls = require("../utils/urls.cjs");
11
11
  class RepositoryManager {
12
- constructor(name, coreApiClient, wroomClient, customTypesApiClient) {
12
+ constructor(name, coreApiClient, authApiClient, wroomClient, customTypesApiClient, manageV2Client) {
13
13
  __publicField(this, "name");
14
14
  __publicField(this, "coreApiClient");
15
+ __publicField(this, "authApiClient");
15
16
  __publicField(this, "wroomClient");
16
17
  __publicField(this, "customTypesApiClient");
18
+ __publicField(this, "manageV2Client");
17
19
  this.name = name;
18
20
  this.coreApiClient = coreApiClient;
21
+ this.authApiClient = authApiClient;
19
22
  this.wroomClient = wroomClient;
20
23
  this.customTypesApiClient = customTypesApiClient;
24
+ this.manageV2Client = manageV2Client;
21
25
  }
22
26
  async configure(config) {
23
27
  const hasLangConfig = config.defaultLocale || config.locales || config.customLocale;
@@ -55,6 +59,9 @@ class RepositoryManager {
55
59
  if (config.preview) {
56
60
  await this.createPreview(config.preview);
57
61
  }
62
+ if (config.rolePerLocal) {
63
+ await this.toggleRolePerLocal(true);
64
+ }
58
65
  }
59
66
  /** @returns the repository base url, like https://my-repo.prismic.io */
60
67
  getBaseURL() {
@@ -190,35 +197,6 @@ class RepositoryManager {
190
197
  this.failIfNot200(response, `Could not delete preview with id ${id}`);
191
198
  profiler.done({ message: `preview '${id}' deleted` });
192
199
  }
193
- /**
194
- * Create a webhook.
195
- *
196
- * @returns A Promise that resolves with the webhook id.
197
- */
198
- async createWebhook(name, url, secret, triggers, active) {
199
- const profiler = log.logger.startTimer();
200
- const response = await this.wroomClient.post(this.name, "app/settings/webhooks/create", {
201
- name,
202
- url,
203
- secret,
204
- active: active ? "on" : "off",
205
- ...triggers
206
- });
207
- this.failIfNot200(response, `Could not create webhook ${name}`);
208
- profiler.done({ message: `webhook '${name}' created` });
209
- return response.data.created;
210
- }
211
- /**
212
- * Deletes a webhook.
213
- *
214
- * @param id - The webhook ID.
215
- */
216
- async deleteWebhook(id) {
217
- const profiler = log.logger.startTimer();
218
- const response = await this.wroomClient.post(this.name, `app/settings/webhooks/${id}/delete`, {});
219
- this.failIfNot200(response, `Could not delete webhook with id ${id}`);
220
- profiler.done({ message: `webhook '${id}' deleted` });
221
- }
222
200
  /**
223
201
  * Create Custom Types using the Custom types api.
224
202
  *
@@ -236,28 +214,145 @@ class RepositoryManager {
236
214
  await this.customTypesApiClient.createSlices(slices);
237
215
  }
238
216
  /**
239
- * Create a permanent access token along with an application name
217
+ * Create an access token to query private items of the Content api.
240
218
  *
241
219
  * @param appName - mandatory authorized application name
220
+ * @param tokenScope - access token scope. Use "master" to when your content
221
+ * api is fully private or "master+releases" to access private releases
242
222
  */
243
- async createPermanentAccessToken(appName) {
223
+ async createContentAPIToken(appName, tokenScope = "master") {
244
224
  const profiler = log.logger.startTimer();
245
225
  const existingApps = await this.wroomClient.get(this.name, "settings/security/contentapi");
246
- this.failIfNot200(existingApps, `Could not get status of existing applications to generate a permanent token`);
247
- const existingApp = existingApps.data.find(({ name, wroom_auths }) => {
226
+ this.failIfNot200(existingApps, `Could not get status of existing applications to generate a content api token`);
227
+ let app = existingApps.data.find(({ name, wroom_auths }) => {
248
228
  return name === appName && wroom_auths.length > 0;
249
229
  });
250
- if (existingApp) {
251
- return existingApp.wroom_auths[0].token;
230
+ if (!app) {
231
+ const response = await this.wroomClient.post(this.name, "settings/security/oauthapp", {
232
+ app_name: appName
233
+ });
234
+ this.failIfNot200(response, `Could not create content api app ${appName}`);
235
+ app = response.data;
236
+ }
237
+ let tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope);
238
+ if (!tokenInfo) {
239
+ const response = await this.wroomClient.post(this.name, "settings/security/authorizations", {
240
+ app: app.id,
241
+ scope: tokenScope
242
+ });
243
+ this.failIfNot200(response, `Could not create content api access token for app ${appName} with scope ${tokenScope}`);
244
+ tokenInfo = response.data;
245
+ }
246
+ profiler.done({
247
+ message: `content api access token for app '${appName}' created`
248
+ });
249
+ if (!(tokenInfo == null ? void 0 : tokenInfo.token)) {
250
+ throw `Could not create content api access token for app ${appName} with scope ${tokenScope}`;
251
+ }
252
+ return tokenInfo.token;
253
+ }
254
+ /** Create a permanent access token to authenticate to Prismic public apis. */
255
+ async createPermanentAccessToken() {
256
+ const profiler = log.logger.startTimer();
257
+ const token = await this.authApiClient.getMachine2MachineToken(this.name);
258
+ profiler.done({
259
+ message: `machine2machine token created`
260
+ });
261
+ return token;
262
+ }
263
+ /**
264
+ * Toggle the Role per local feature
265
+ *
266
+ * @param enabled - The feature new status
267
+ */
268
+ async toggleRolePerLocal(enabled) {
269
+ const profiler = log.logger.startTimer();
270
+ const response = await this.manageV2Client.toggleRolePerLocal({
271
+ repository: this.name,
272
+ enabled
273
+ });
274
+ this.failIfNot200(response, `Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`);
275
+ profiler.done({
276
+ message: `Role per local ${enabled ? "enabled" : "disabled"}`
277
+ });
278
+ }
279
+ /**
280
+ * Change the Repository Plan
281
+ *
282
+ * @param {string} newPlanId - The Id of the new Plan to apply
283
+ */
284
+ async changePlan(newPlanId) {
285
+ const profiler = log.logger.startTimer();
286
+ const response = await this.manageV2Client.changePlan({
287
+ repository: this.name,
288
+ newPlanId,
289
+ bypassManualBilling: true
290
+ // For now the library does not support Stripe features
291
+ });
292
+ this.failIfNot200(response, "Could not change the Repository Plan");
293
+ profiler.done({
294
+ message: `Repository Plan changed to ${newPlanId}`
295
+ });
296
+ }
297
+ /**
298
+ * Add a new user to the repository
299
+ *
300
+ * @param {string} email - The email of the user
301
+ */
302
+ async addUser(email) {
303
+ const profiler = log.logger.startTimer();
304
+ const response = await this.manageV2Client.addUserToRepository({
305
+ repository: this.name,
306
+ email
307
+ });
308
+ const { data, status } = response;
309
+ const success = status === 200 || status === 409 && JSON.stringify(data).includes("already a member of the repo");
310
+ if (!success) {
311
+ log.logHttpResponse(response);
312
+ throw new Error(`Could not add a new user ${email} to the repository`);
252
313
  }
253
- const response = await this.wroomClient.post(this.name, "settings/security/oauthapp", {
254
- app_name: appName
314
+ profiler.done({
315
+ message: `User ${email} was added to the repository`
255
316
  });
256
- this.failIfNot200(response, `Could not create permanent access token for app name ${appName}`);
317
+ }
318
+ /**
319
+ * Remove a user from the repository
320
+ *
321
+ * @param {string} email - The email of the user
322
+ */
323
+ async removeUser(email) {
324
+ const profiler = log.logger.startTimer();
325
+ const response = await this.manageV2Client.removeUserFromRepository({
326
+ repository: this.name,
327
+ email
328
+ });
329
+ this.failIfNot200(response, `Could not remove the user ${email} from the repository`);
330
+ profiler.done({
331
+ message: `User ${email} was removed from the repository`
332
+ });
333
+ }
334
+ /**
335
+ * Update the role of a user in a repository
336
+ *
337
+ * @param {string} email - The email of the user
338
+ * @param {string | Record<string, string>} role - The new Role of the user,
339
+ * either a string for basic workflow or an object such as `{ "lang_id":
340
+ * "Writer" }`
341
+ *
342
+ * Example of roles are
343
+ *
344
+ * - Administrator
345
+ * - Writer
346
+ * - Contributor
347
+ * - Manager (publisher)
348
+ */
349
+ async updateUserRole(email, role) {
350
+ const profiler = log.logger.startTimer();
351
+ const response = typeof role === "string" ? await this.wroomClient.updateRole(this.name, email, role) : await this.wroomClient.updateRolePerLocal(this.name, email, role);
352
+ this.failIfNot200(response, `Could not update the ${typeof role === "string" ? "role" : "rolePerLocal"} of the user ${email}`);
257
353
  profiler.done({
258
- message: `permanent access token for app name '${appName}' created`
354
+ message: `Updated User's ${typeof role === "string" ? "role" : "rolePerLocal"} for user ${email}`
259
355
  });
260
- return response.data.wroom_auths[0].token;
261
356
  }
262
357
  }
263
358
  exports.RepositoryManager = RepositoryManager;