@prismicio/e2e-tests-utils 1.1.0-alpha.1 → 1.1.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.
@@ -7,15 +7,17 @@ var __publicField = (obj, key, value) => {
7
7
  import { logger, logHttpResponse } from "../utils/log.js";
8
8
  import { getRepositoryUrl } from "../utils/urls.js";
9
9
  class RepositoryManager {
10
- constructor(name, coreApiClient, wroomClient, customTypesApiClient) {
10
+ constructor(name, coreApiClient, wroomClient, customTypesApiClient, manageV2Client) {
11
11
  __publicField(this, "name");
12
12
  __publicField(this, "coreApiClient");
13
13
  __publicField(this, "wroomClient");
14
14
  __publicField(this, "customTypesApiClient");
15
+ __publicField(this, "manageV2Client");
15
16
  this.name = name;
16
17
  this.coreApiClient = coreApiClient;
17
18
  this.wroomClient = wroomClient;
18
19
  this.customTypesApiClient = customTypesApiClient;
20
+ this.manageV2Client = manageV2Client;
19
21
  }
20
22
  async configure(config) {
21
23
  const hasLangConfig = config.defaultLocale || config.locales || config.customLocale;
@@ -53,6 +55,9 @@ class RepositoryManager {
53
55
  if (config.preview) {
54
56
  await this.createPreview(config.preview);
55
57
  }
58
+ if (config.rolePerLocal) {
59
+ await this.toggleRolePerLocal(true);
60
+ }
56
61
  }
57
62
  /** @returns the repository base url, like https://my-repo.prismic.io */
58
63
  getBaseURL() {
@@ -228,6 +233,95 @@ class RepositoryManager {
228
233
  });
229
234
  return response.data.wroom_auths[0].token;
230
235
  }
236
+ /**
237
+ * Toggle the Role per local feature
238
+ *
239
+ * @param enabled - The feature new status
240
+ */
241
+ async toggleRolePerLocal(enabled) {
242
+ const profiler = logger.startTimer();
243
+ const response = await this.manageV2Client.toggleRolePerLocal({
244
+ repository: this.name,
245
+ enabled
246
+ });
247
+ this.failIfNot200(response, `Could not ${enabled ? "enable" : "disable"} Role per local for ${this.name}`);
248
+ profiler.done({
249
+ message: `Role per local ${enabled ? "enabled" : "disabled"}`
250
+ });
251
+ }
252
+ /**
253
+ * Change the Repository Plan
254
+ *
255
+ * @param {string} newPlanId - The Id of the new Plan to apply
256
+ */
257
+ async changePlan(newPlanId) {
258
+ const profiler = logger.startTimer();
259
+ const response = await this.manageV2Client.changePlan({
260
+ repository: this.name,
261
+ newPlanId,
262
+ bypassManualBilling: true
263
+ // For now the library does not support Stripe features
264
+ });
265
+ this.failIfNot200(response, "Could not change the Repository Plan");
266
+ profiler.done({
267
+ message: `Repository Plan changed to ${newPlanId}`
268
+ });
269
+ }
270
+ /**
271
+ * Add a new user to the repository
272
+ *
273
+ * @param {string} email - The email of the user
274
+ */
275
+ async addUser(email) {
276
+ const profiler = logger.startTimer();
277
+ const response = await this.manageV2Client.addUserToRepository({
278
+ repository: this.name,
279
+ email
280
+ });
281
+ this.failIfNot200(response, "Could not add a new user to the repository");
282
+ profiler.done({
283
+ message: `User ${email} was added to the repository`
284
+ });
285
+ }
286
+ /**
287
+ * Remove a user from the repository
288
+ *
289
+ * @param {string} email - The email of the user
290
+ */
291
+ async removeUser(email) {
292
+ const profiler = logger.startTimer();
293
+ const response = await this.manageV2Client.removeUserFromRepository({
294
+ repository: this.name,
295
+ email
296
+ });
297
+ this.failIfNot200(response, `Could not remove the user ${email} from the repository`);
298
+ profiler.done({
299
+ message: `User ${email} was removed from the repository`
300
+ });
301
+ }
302
+ /**
303
+ * Update the role of a user in a repository
304
+ *
305
+ * @param {string} email - The email of the user
306
+ * @param {string | Record<string, string>} role - The new Role of the user,
307
+ * either a string for basic workflow or an object such as `{ "lang_id":
308
+ * "Writer" }`
309
+ *
310
+ * Example of roles are
311
+ *
312
+ * - Administrator
313
+ * - Writer
314
+ * - Contributor
315
+ * - Manager (publisher)
316
+ */
317
+ async updateUserRole(email, role) {
318
+ const profiler = logger.startTimer();
319
+ const response = typeof role === "string" ? await this.wroomClient.updateRole(this.name, email, role) : await this.wroomClient.updateRolePerLocal(this.name, email, role);
320
+ this.failIfNot200(response, `Could not update the ${typeof role === "string" ? "role" : "rolePerLocal"} of the user ${email}`);
321
+ profiler.done({
322
+ message: `Updated User's ${typeof role === "string" ? "role" : "rolePerLocal"} for user ${email}`
323
+ });
324
+ }
231
325
  }
232
326
  export {
233
327
  RepositoryManager
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport type { CoreClient } from \"../clients/coreApi\";\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly coreApiClient: CoreClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tconst hasLangConfig =\n\t\t\tconfig.defaultLocale || config.locales || config.customLocale;\n\t\tif (hasLangConfig) {\n\t\t\tconst languages = await this.coreApiClient.getLanguages();\n\n\t\t\t// default locale must be set first\n\t\t\tif (config.defaultLocale) {\n\t\t\t\tconst master = languages.find(({ is_master }) => is_master === true);\n\t\t\t\tif (!master) {\n\t\t\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`Master locale is already set to '${master.id}', cannot update it to '${config.defaultLocale}'`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\tconst localesToAdd = config.locales.filter(\n\t\t\t\t\t(id) => !languages.some((language) => language.id === id),\n\t\t\t\t);\n\t\t\t\tif (localesToAdd.length > 0) {\n\t\t\t\t\tawait this.createLocales(localesToAdd);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.customLocale) {\n\t\t\t\tif (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {\n\t\t\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\treturn getRepositoryUrl(this.wroomClient.getBaseURL(), this.name);\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `locales '${locales}' created` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && JSON.stringify(data).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/createMasterLang`,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`);\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id ${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n\n\t/**\n\t * Create a permanent access token along with an application name\n\t *\n\t * @param appName - mandatory authorized application name\n\t */\n\tasync createPermanentAccessToken(appName: string): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\t\ttype AuthorizedAppResponse = {\n\t\t\tname: string;\n\t\t\twroom_auths: { token: string }[];\n\t\t};\n\t\tconst existingApps: AxiosResponse<AuthorizedAppResponse[]> =\n\t\t\tawait this.wroomClient.get(this.name, \"settings/security/contentapi\");\n\n\t\tthis.failIfNot200(\n\t\t\texistingApps,\n\t\t\t`Could not get status of existing applications to generate a permanent token`,\n\t\t);\n\t\tconst existingApp = existingApps.data.find(({ name, wroom_auths }) => {\n\t\t\treturn name === appName && wroom_auths.length > 0;\n\t\t});\n\t\tif (existingApp) {\n\t\t\treturn existingApp.wroom_auths[0].token;\n\t\t}\n\t\tconst response: AxiosResponse<AuthorizedAppResponse> =\n\t\t\tawait this.wroomClient.post(this.name, \"settings/security/oauthapp\", {\n\t\t\t\tapp_name: appName,\n\t\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not create permanent access token for app name ${appName}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `permanent access token for app name '${appName}' created`,\n\t\t});\n\n\t\t// only return the generated token since there is no need to access more\n\t\treturn response.data.wroom_auths[0].token;\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":[],"mappings":";;;;;;;;MAca,kBAAiB;AAAA,EAC7B,YACU,MACQ,eACA,aACA,sBAAuC;AAH/C;AACQ;AACA;AACA;AAHR,SAAI,OAAJ;AACQ,SAAa,gBAAb;AACA,SAAW,cAAX;AACA,SAAoB,uBAApB;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,QAAwB;AACvC,UAAM,gBACL,OAAO,iBAAiB,OAAO,WAAW,OAAO;AAClD,QAAI,eAAe;AAClB,YAAM,YAAY,MAAM,KAAK,cAAc,aAAY;AAGvD,UAAI,OAAO,eAAe;AACnB,cAAA,SAAS,UAAU,KAAK,CAAC,EAAE,gBAAgB,cAAc,IAAI;AACnE,YAAI,CAAC,QAAQ;AACN,gBAAA,KAAK,iBAAiB,OAAO,aAAa;AAAA,QACtC,WAAA,OAAO,OAAO,OAAO,eAAe;AAC9C,iBAAO,KACN,oCAAoC,OAAO,EAAE,2BAA2B,OAAO,aAAa,GAAG;AAAA,QAEhG;AAAA,MACD;AAED,UAAI,OAAO,SAAS;AACnB,cAAM,eAAe,OAAO,QAAQ,OACnC,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC,aAAa,SAAS,OAAO,EAAE,CAAC;AAEtD,YAAA,aAAa,SAAS,GAAG;AACtB,gBAAA,KAAK,cAAc,YAAY;AAAA,QACrC;AAAA,MACD;AAED,UAAI,OAAO,cAAc;AACxB,YAAI,CAAC,UAAU,KAAK,CAAC,EAAE,GAAA;;AAAS,0BAAO,YAAO,iBAAP,mBAAqB,KAAK;AAAA,SAAE,GAAG;AAC/D,gBAAA,KAAK,mBAAmB,OAAO,YAAY;AAAA,QACjD;AAAA,MACD;AAAA,IACD;AAED,QAAI,OAAO,Q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E;AAExE,UAAA,cAAc,aAAa,KAAK,KAAK,CAAC,EAAE,MAAM,kBAAiB;AAC7D,aAAA,SAAS,WAAW,YAAY,SAAS;AAAA,IAAA,CAChD;AACD,QAAI,aAAa;AACT,aAAA,YAAY,YAAY,CAAC,EAAE;AAAA,IAClC;AACD,UAAM,WACL,MAAM,KAAK,YAAY,KAAK,KAAK,MAAM,8BAA8B;AAAA,MACpE,UAAU;AAAA,IAAA,CACV;AAEF,SAAK,aACJ,UACA,wDAAwD,OAAO,EAAE;AAElE,aAAS,KAAK;AAAA,MACb,SAAS,wCAAwC,OAAO;AAAA,IAAA,CACxD;AAGD,WAAO,SAAS,KAAK,YAAY,CAAC,EAAE;AAAA,EACrC;AACA;"}
1
+ {"version":3,"file":"repository.js","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport type { CoreClient } from \"../clients/coreApi\";\nimport { CustomTypesClient } from \"../clients/customTypesApi\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly coreApiClient: CoreClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesClient,\n\t\tprivate readonly manageV2Client: ManageV2Client,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tconst hasLangConfig =\n\t\t\tconfig.defaultLocale || config.locales || config.customLocale;\n\t\tif (hasLangConfig) {\n\t\t\tconst languages = await this.coreApiClient.getLanguages();\n\n\t\t\t// default locale must be set first\n\t\t\tif (config.defaultLocale) {\n\t\t\t\tconst master = languages.find(({ is_master }) => is_master === true);\n\t\t\t\tif (!master) {\n\t\t\t\t\tawait this.setDefaultLocale(config.defaultLocale);\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`Master locale is already set to '${master.id}', cannot update it to '${config.defaultLocale}'`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\tconst localesToAdd = config.locales.filter(\n\t\t\t\t\t(id) => !languages.some((language) => language.id === id),\n\t\t\t\t);\n\t\t\t\tif (localesToAdd.length > 0) {\n\t\t\t\t\tawait this.createLocales(localesToAdd);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.customLocale) {\n\t\t\t\tif (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {\n\t\t\t\t\tawait this.createCustomLocale(config.customLocale);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices);\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes);\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview);\n\t\t}\n\n\t\tif (config.rolePerLocal) {\n\t\t\tawait this.toggleRolePerLocal(true);\n\t\t}\n\t}\n\t/** @returns the repository base url, like https://my-repo.prismic.io */\n\tgetBaseURL(): string {\n\t\treturn getRepositoryUrl(this.wroomClient.getBaseURL(), this.name);\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\n\t *\n\t * @throws Error if setting the locales fails.\n\t */\n\tasync createLocales(locales: string[]): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages\",\n\t\t\t{ languages: locales },\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"already existing languages\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add locales ${locales.join(\", \")}`);\n\t\t}\n\t\tprofiler.done({ message: `locales '${locales}' created` });\n\t}\n\n\t/**\n\t * Set additional custom locale for a repository in Wroom, does not fail if\n\t * the locales already exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\n\t *\n\t * @throws Error if setting the locale fails.\n\t */\n\tasync createCustomLocale(locale: CustomLocale): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t\"app/settings/multilanguages/custom\",\n\t\t\tlocale,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && JSON.stringify(data).includes(\"code is already used\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create custom locale ${locale}`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `custom locale ${JSON.stringify(locale)} created`,\n\t\t});\n\t}\n\n\tprivate failIfNot200(response: AxiosResponse, msg: string) {\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(msg);\n\t\t}\n\t}\n\n\t/**\n\t * Delete a locale from a repository.\n\t *\n\t * @param locale - locale to remove from the repository configuration.\n\t *\n\t * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t);\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`);\n\t\tprofiler.done({ message: `locale '${locale}' deleted` });\n\t}\n\n\t/**\n\t * Set the default (master) locale for a repository in Wroom, the locale needs\n\t * to exist for the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/createMasterLang`,\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`);\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` });\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\n\t *\n\t * @returns A Promise that resolves when the release is created.\n\t */\n\tasync createRelease(label: string): Promise<{ id: string }> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/releases\", {\n\t\t\tlabel,\n\t\t});\n\t\tthis.failIfNot200(response, `Could not create release ${label}`);\n\t\tprofiler.done({ message: `release '${label}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\n\t * @param repository - The name of the repository.\n\t * @param id - The ID of the release to be deleted.\n\t */\n\tasync deleteRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/releases/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete release with id ${id}`);\n\t\tprofiler.done({ message: `release '${id}' deleted` });\n\t}\n\n\t/**\n\t * Creates a preview for a repository.\n\t *\n\t * @param data - The data for creating the preview.\n\t */\n\tasync createPreview(data: Preview): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/new`,\n\t\t\tdata,\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not create preview ${data.name}`);\n\t\tprofiler.done({ message: `preview '${data.name}' created` });\n\n\t\treturn response.data;\n\t}\n\n\t/**\n\t * Deletes a preview from a repository.\n\t *\n\t * @param id - The ID of the preview to be deleted.\n\t */\n\tasync deletePreview(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`previews/delete/${id}`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id ${id}`);\n\t\tprofiler.done({ message: `preview '${id}' deleted` });\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createSlices(slices);\n\t}\n\n\t/**\n\t * Create a permanent access token along with an application name\n\t *\n\t * @param appName - mandatory authorized application name\n\t */\n\tasync createPermanentAccessToken(appName: string): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\t\ttype AuthorizedAppResponse = {\n\t\t\tname: string;\n\t\t\twroom_auths: { token: string }[];\n\t\t};\n\t\tconst existingApps: AxiosResponse<AuthorizedAppResponse[]> =\n\t\t\tawait this.wroomClient.get(this.name, \"settings/security/contentapi\");\n\n\t\tthis.failIfNot200(\n\t\t\texistingApps,\n\t\t\t`Could not get status of existing applications to generate a permanent token`,\n\t\t);\n\t\tconst existingApp = existingApps.data.find(({ name, wroom_auths }) => {\n\t\t\treturn name === appName && wroom_auths.length > 0;\n\t\t});\n\t\tif (existingApp) {\n\t\t\treturn existingApp.wroom_auths[0].token;\n\t\t}\n\t\tconst response: AxiosResponse<AuthorizedAppResponse> =\n\t\t\tawait this.wroomClient.post(this.name, \"settings/security/oauthapp\", {\n\t\t\t\tapp_name: appName,\n\t\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not create permanent access token for app name ${appName}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `permanent access token for app name '${appName}' created`,\n\t\t});\n\n\t\t// only return the generated token since there is no need to access more\n\t\treturn response.data.wroom_auths[0].token;\n\t}\n\n\t/**\n\t * Toggle the Role per local feature\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleRolePerLocal(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.toggleRolePerLocal({\n\t\t\trepository: this.name,\n\t\t\tenabled: enabled,\n\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not ${enabled ? \"enable\" : \"disable\"} Role per local for ${\n\t\t\t\tthis.name\n\t\t\t}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `Role per local ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t});\n\t}\n\n\t/**\n\t * Change the Repository Plan\n\t *\n\t * @param {string} newPlanId - The Id of the new Plan to apply\n\t */\n\tasync changePlan(newPlanId: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.changePlan({\n\t\t\trepository: this.name,\n\t\t\tnewPlanId: newPlanId,\n\t\t\tbypassManualBilling: true, // For now the library does not support Stripe features\n\t\t});\n\n\t\tthis.failIfNot200(response, \"Could not change the Repository Plan\");\n\t\tprofiler.done({\n\t\t\tmessage: `Repository Plan changed to ${newPlanId}`,\n\t\t});\n\t}\n\n\t/**\n\t * Add a new user to the repository\n\t *\n\t * @param {string} email - The email of the user\n\t */\n\tasync addUser(email: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.addUserToRepository({\n\t\t\trepository: this.name,\n\t\t\temail: email,\n\t\t});\n\n\t\tthis.failIfNot200(response, \"Could not add a new user to the repository\");\n\t\tprofiler.done({\n\t\t\tmessage: `User ${email} was added to the repository`,\n\t\t});\n\t}\n\n\t/**\n\t * Remove a user from the repository\n\t *\n\t * @param {string} email - The email of the user\n\t */\n\tasync removeUser(email: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.removeUserFromRepository({\n\t\t\trepository: this.name,\n\t\t\temail: email,\n\t\t});\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not remove the user ${email} from the repository`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `User ${email} was removed from the repository`,\n\t\t});\n\t}\n\n\t/**\n\t * Update the role of a user in a repository\n\t *\n\t * @param {string} email - The email of the user\n\t * @param {string | Record<string, string>} role - The new Role of the user,\n\t * either a string for basic workflow or an object such as `{ \"lang_id\":\n\t * \"Writer\" }`\n\t *\n\t * Example of roles are\n\t *\n\t * - Administrator\n\t * - Writer\n\t * - Contributor\n\t * - Manager (publisher)\n\t */\n\tasync updateUserRole(\n\t\temail: string,\n\t\trole: string | Record<string, string>,\n\t): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response =\n\t\t\ttypeof role === \"string\"\n\t\t\t\t? await this.wroomClient.updateRole(this.name, email, role)\n\t\t\t\t: await this.wroomClient.updateRolePerLocal(this.name, email, role);\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not update the ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} of the user ${email}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `Updated User's ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} for user ${email}`,\n\t\t});\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale;\n\tlocales?: string[];\n\tdefaultLocale?: string;\n\tslices?: SharedSlice[];\n\tcustomTypes?: CustomType[];\n\tpreview?: Preview;\n\trolePerLocal?: boolean;\n};\n\nexport type Preview = {\n\tname: string;\n\twebsiteURL: string;\n\tresolverPath: string;\n};\n\nexport type CustomLocale = {\n\tlang: {\n\t\tlabel: string;\n\t\tid: string;\n\t\tuseStandardAnalyzer?: boolean;\n\t};\n\tregion: {\n\t\tlabel: string;\n\t\tid: string;\n\t};\n};\n"],"names":[],"mappings":";;;;;;;;MAea,kBAAiB;AAAA,EAC7B,YACU,MACQ,eACA,aACA,sBACA,gBAA8B;AAJtC;AACQ;AACA;AACA;AACA;AAJR,SAAI,OAAJ;AACQ,SAAa,gBAAb;AACA,SAAW,cAAX;AACA,SAAoB,uBAApB;AACA,SAAc,iBAAd;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,QAAwB;AACvC,UAAM,gBACL,OAAO,iBAAiB,OAAO,WAAW,OAAO;AAClD,QAAI,eAAe;AAClB,YAAM,YAAY,MAAM,KAAK,cAAc,aAAY;AAGvD,UAAI,OAAO,eAAe;AACnB,cAAA,SAAS,UAAU,KAAK,CAAC,EAAE,gBAAgB,cAAc,IAAI;AACnE,YAAI,CAAC,QAAQ;AACN,gBAAA,KAAK,iBAAiB,OAAO,aAAa;AAAA,QACtC,WAAA,OAAO,OAAO,OAAO,eAAe;AAC9C,iBAAO,KACN,oCAAoC,OAAO,EAAE,2BAA2B,OAAO,aAAa,GAAG;AAAA,QAEhG;AAAA,MACD;AAED,UAAI,OAAO,SAAS;AACnB,cAAM,eAAe,OAAO,QAAQ,OACnC,CAAC,OAAO,CAAC,UAAU,KAAK,CAAC,aAAa,SAAS,OAAO,EAAE,CAAC;AAEtD,YAAA,aAAa,SAAS,GAAG;AACtB,gBAAA,KAAK,cAAc,YAAY;AAAA,QACrC;AAAA,MACD;AAED,UAAI,OAAO,cAAc;AACxB,YAAI,CAAC,UAAU,KAAK,CAAC,EAAE,GAAA;;AAAS,0BAAO,YAAO,iBAAP,mBAAqB,KAAK;AAAA,SA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 baseURL: string;
4
+ /** Custom types api base url */
5
+ customTypesApi: string;
6
+ /** Auth service api base url */
7
+ authenticationApi: string;
8
+ };
9
+ export type AuthConfig = {
2
10
  email: string;
3
11
  password: string;
4
12
  };
13
+ export type ManageV2Config = {
14
+ secret: string;
15
+ audience: string;
16
+ };
17
+ export type SetupConfiguration = {
18
+ urlConfig: UrlConfig | string;
19
+ authConfig: AuthConfig;
20
+ manageV2Config?: ManageV2Config;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "1.1.0-alpha.1",
3
+ "version": "1.1.1",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -54,12 +54,14 @@
54
54
  "dependencies": {
55
55
  "@prismicio/types-internal": "^2.3.1",
56
56
  "axios": "^1.6.2",
57
+ "jsonwebtoken": "^9.0.2",
57
58
  "lodash.isequal": "^4.5.0",
58
59
  "winston": "^3.11.0"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@size-limit/preset-small-lib": "^11.0.1",
62
63
  "@trivago/prettier-plugin-sort-imports": "^4.2.0",
64
+ "@types/jsonwebtoken": "^9.0.6",
63
65
  "@types/lodash.isequal": "^4.5.8",
64
66
  "@types/node": "^20.9.2",
65
67
  "@typescript-eslint/eslint-plugin": "^6.8.0",
@@ -1,6 +1,6 @@
1
1
  import axios, { AxiosInstance } from "axios";
2
2
 
3
- import { Credentials } from "../types";
3
+ import { AuthConfig } from "../types";
4
4
 
5
5
  import { logHttpResponse, logger } from "../utils/log";
6
6
 
@@ -11,7 +11,7 @@ export type AuthenticationClient = {
11
11
  /** Client for interacting with the authentication service to manage tokens */
12
12
  export const createAuthenticationApiClient = (
13
13
  baseURL: string,
14
- auth: Credentials,
14
+ auth: AuthConfig,
15
15
  ): AuthenticationClient => {
16
16
  let authToken: string;
17
17
 
@@ -0,0 +1,178 @@
1
+ import axios, { AxiosInstance, AxiosResponse } from "axios";
2
+ import jwt from "jsonwebtoken";
3
+
4
+ import { ManageV2Config } from "../types";
5
+
6
+ import { extractCookie } from "../utils/cookies";
7
+
8
+ const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
9
+
10
+ /**
11
+ * Client for interacting with ManageV2 routes to perform operations on
12
+ * repositories.
13
+ */
14
+ export class ManageV2Client {
15
+ readonly client: AxiosInstance; // Not private to have it available on tests
16
+ private token: string | null = null;
17
+
18
+ /**
19
+ * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
20
+ * @param config - ManageV2 configuration variable to call ManageV2.
21
+ */
22
+ constructor(baseUrl: string, config?: ManageV2Config | undefined) {
23
+ this.token = config ? this.generateToken(config) : null;
24
+
25
+ this.client = axios.create({
26
+ baseURL: `${baseUrl}/manageroutes/`,
27
+ withCredentials: true,
28
+ validateStatus: () => true,
29
+ headers: {
30
+ "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
31
+ Authorization: `Bearer ${this.token}`,
32
+ },
33
+ });
34
+
35
+ // cookies are not forwarded automatically in a non-browser env
36
+ this.client.interceptors.response.use((response) => {
37
+ const cookies = response.headers["set-cookie"];
38
+ if (cookies && extractCookie(cookies, "SESSION")) {
39
+ this.client.defaults.headers["Cookie"] = cookies;
40
+ }
41
+
42
+ return response;
43
+ });
44
+ }
45
+
46
+ /**
47
+ * The function generates a JWT token using the provided configuration
48
+ * parameters.
49
+ *
50
+ * @param {ManageV2Config} config - The `config` parameter in the
51
+ * `generateToken` function is of type `ManageV2Config`. It contains the
52
+ * following properties:
53
+ *
54
+ * @returns A JSON Web Token (JWT) is being returned by the `generateToken`
55
+ * function. The token is signed using the provided `config.secret` with the
56
+ * HS256 algorithm and includes the specified audience and issuer values.
57
+ */
58
+ private generateToken(config: ManageV2Config): string {
59
+ return jwt.sign({}, config.secret, {
60
+ algorithm: "HS256",
61
+ audience: config.audience,
62
+ issuer: "prismic.io",
63
+ });
64
+ }
65
+
66
+ /**
67
+ * The function `assertTokenExist` checks if a token exists before executing a
68
+ * given function.
69
+ *
70
+ * @param f - The `assertTokenExist` function takes a function `f` as a
71
+ * parameter. This function `f` should accept a parameter of type
72
+ * `Parameters` and return a Promise that resolves to an AxiosResponse. The
73
+ * `assertTokenExist` function ensures that a token is not null before
74
+ * calling the provided
75
+ *
76
+ * @returns A function is being returned that takes a parameter of type
77
+ * Parameters and checks if the token is null. If the token is null, an
78
+ * error is thrown. Otherwise, the function f is called with the provided
79
+ * parameters.
80
+ */
81
+ private assertTokenExist<Parameters>(
82
+ f: (_: Parameters) => Promise<AxiosResponse>,
83
+ ) {
84
+ return (params: Parameters) => {
85
+ if (this.token === null) {
86
+ throw new Error(
87
+ "Undefined configuration for ManageV2 while trying to use it's routes",
88
+ );
89
+ } else {
90
+ return f(params);
91
+ }
92
+ };
93
+ }
94
+
95
+ getBaseURL(): string {
96
+ return this.client.getUri();
97
+ }
98
+
99
+ /**
100
+ * The function `toggleRolePerLocal` enable or disable the role per local
101
+ * feature
102
+ *
103
+ * @param repository - The Repository name
104
+ * @param enabled - The feature new status
105
+ */
106
+ toggleRolePerLocal = this.assertTokenExist(
107
+ (params: { repository: string; enabled: boolean }) => {
108
+ return this.client.post("/repository/toggleRolesPerLocale", {
109
+ domain: params.repository,
110
+ enabled: params.enabled,
111
+ author: ManageV2StaticAuthor,
112
+ });
113
+ },
114
+ );
115
+
116
+ /**
117
+ * The function `changePlan` changes the plan of a repository the database
118
+ *
119
+ * @param repository - The Repository name
120
+ * @param newPlanId - The new planId
121
+ * @param bypassManualBilling - Beware that using this will not verify that
122
+ * the database and Stripe are in sync
123
+ */
124
+ changePlan = this.assertTokenExist(
125
+ ({
126
+ repository,
127
+ newPlanId,
128
+ bypassManualBilling = false,
129
+ }: {
130
+ repository: string;
131
+ newPlanId: string;
132
+ bypassManualBilling?: boolean;
133
+ }) => {
134
+ return this.client.post(
135
+ `/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,
136
+ {
137
+ domain: repository,
138
+ newPlan: newPlanId,
139
+ author: ManageV2StaticAuthor,
140
+ },
141
+ );
142
+ },
143
+ );
144
+
145
+ /**
146
+ * The function `addUserToRepository` adds a user corresponding to the email
147
+ * to the given repository
148
+ *
149
+ * @param repository - The Repository name
150
+ * @param email - The user email
151
+ */
152
+ addUserToRepository = this.assertTokenExist(
153
+ ({ repository, email }: { repository: string; email: string }) => {
154
+ return this.client.post("/repository/addUser", {
155
+ domain: repository,
156
+ email: email,
157
+ author: ManageV2StaticAuthor,
158
+ });
159
+ },
160
+ );
161
+
162
+ /**
163
+ * The function `removeUserFromRepository` removes a user corresponding to the
164
+ * email from the given repository
165
+ *
166
+ * @param repository - The Repository name
167
+ * @param email - The user email
168
+ */
169
+ removeUserFromRepository = this.assertTokenExist(
170
+ ({ repository, email }: { repository: string; email: string }) => {
171
+ return this.client.post("/repository/removeUser", {
172
+ domain: repository,
173
+ email: email,
174
+ author: ManageV2StaticAuthor,
175
+ });
176
+ },
177
+ );
178
+ }
@@ -1,6 +1,6 @@
1
1
  import axios, { AxiosInstance, AxiosResponse } from "axios";
2
2
 
3
- import { Credentials } from "../types";
3
+ import { AuthConfig } from "../types";
4
4
 
5
5
  import { extractCookie } from "../utils/cookies";
6
6
  import { logHttpResponse, logger } from "../utils/log";
@@ -20,7 +20,7 @@ export class WroomClient {
20
20
  */
21
21
  constructor(
22
22
  baseURL: string,
23
- private readonly auth: Credentials,
23
+ private readonly auth: AuthConfig,
24
24
  ) {
25
25
  this.client = axios.create({
26
26
  baseURL,
@@ -84,6 +84,44 @@ export class WroomClient {
84
84
  return response;
85
85
  }
86
86
 
87
+ /**
88
+ * Update the role of a user in the repository
89
+ *
90
+ * @param {string} repository - The repository name
91
+ * @param {string} email - The email of the user
92
+ * @param {string} role - The new role to be given
93
+ *
94
+ * @returns The Axios Reponse
95
+ */
96
+ async updateRole(
97
+ repository: string,
98
+ email: string,
99
+ role: string,
100
+ ): Promise<AxiosResponse> {
101
+ const path = `/app/settings/users/profiles?email=${email}&profile=${role}`;
102
+
103
+ return this.post(repository, path);
104
+ }
105
+
106
+ /**
107
+ * Update the role of a user in the repository
108
+ *
109
+ * @param {string} repository - The repository name
110
+ * @param {string} email - The email of the user
111
+ * @param {string} rolePerLocal - The role per local object
112
+ *
113
+ * @returns The Axios Reponse
114
+ */
115
+ async updateRolePerLocal(
116
+ repository: string,
117
+ email: string,
118
+ rolePerLocal: Record<string, string>,
119
+ ): Promise<AxiosResponse> {
120
+ const path = `/app/settings/users/rolesperlocale?email=${email}`;
121
+
122
+ return this.post(repository, path, rolePerLocal);
123
+ }
124
+
87
125
  /**
88
126
  * Authenticate Wroom to call Wroom unofficial endpoints.
89
127
  *
@@ -1,4 +1,4 @@
1
- import { Credentials } from "../types";
1
+ import { SetupConfiguration, UrlConfig } from "../types";
2
2
 
3
3
  import {
4
4
  AuthenticationClient,
@@ -6,6 +6,7 @@ import {
6
6
  } from "../clients/authenticationApi";
7
7
  import { createCoreApiClient } from "../clients/coreApi";
8
8
  import { createCustomTypesApiClient } from "../clients/customTypesApi";
9
+ import { ManageV2Client } from "../clients/manageV2";
9
10
  import { WroomClient } from "../clients/wroom";
10
11
  import { EnvVariableManager } from "../utils/envVariableManager";
11
12
  import { logHttpResponse, logger } from "../utils/log";
@@ -18,30 +19,29 @@ import { RepositoryConfig, RepositoryManager } from "./repository";
18
19
  * Factory method to create a RepositoriesManager to manage repositories test
19
20
  * data.
20
21
  *
21
- * @param urlConfig - If provided as an object:
22
+ * @param configuration - Global object containing the different configurations
23
+ * required to setup the RepositoriesManager.
22
24
  *
23
- * - {@link UrlConfig.baseURL}: The Prismic base URL.
24
- * - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.
25
- * - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.
26
- *
27
- * If provided as a string: It is treated as the base URL for Prismic. Other
28
- * URLs (Custom Types API, Auth API) will be derived from it.
29
- * @param auth - The authentication credentials
25
+ * - {@link configuration.urlConfig}: Configuration around the API's URLs management.
26
+ * - {@link configuration.authConfig}: Configuration around the authentication of a user.
27
+ * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.
30
28
  *
31
29
  * @returns An instance of {@link RepositoriesManager} to manage test data.
32
30
  */
33
31
  export const createRepositoriesManager = (
34
- urlConfig: UrlConfig | string,
35
- auth: Credentials,
32
+ configuration: SetupConfiguration,
36
33
  ): RepositoriesManager => {
37
- return new RepositoriesManager(urlConfig, auth);
34
+ return new RepositoriesManager(configuration);
38
35
  };
39
36
 
40
37
  /** Utility object to manage Prismic test data */
41
38
  export class RepositoriesManager {
42
- private readonly urls: UrlConfig;
39
+ private readonly config: Omit<SetupConfiguration, "urlConfig"> & {
40
+ urlConfig: UrlConfig;
41
+ };
43
42
  private readonly wroomClient: WroomClient;
44
43
  private readonly authClient: AuthenticationClient;
44
+ private readonly manageV2Client: ManageV2Client;
45
45
  /**
46
46
  * helper to keep track of repositories across independent test phases (setup,
47
47
  * teardown)
@@ -51,22 +51,31 @@ export class RepositoriesManager {
51
51
  );
52
52
 
53
53
  /**
54
- * @param urlConfig - The base URL of the Wroom app.
54
+ * @param configuration - Global object containing the different configuration
55
+ * required to setup the different clients.
55
56
  * @param credentials - Authentication credentials (email and password)
56
57
  */
57
- constructor(
58
- urlConfig: UrlConfig | string,
59
- private readonly credentials: Credentials,
60
- ) {
61
- if (typeof urlConfig === "string") {
58
+ constructor(configuration: SetupConfiguration) {
59
+ this.config = {
60
+ ...configuration,
62
61
  // When a string is provided, treat it as the 'base' property
63
- urlConfig = this.inferUrls(urlConfig);
64
- }
65
- this.urls = urlConfig;
66
- this.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);
62
+ urlConfig:
63
+ typeof configuration.urlConfig === "string"
64
+ ? this.inferUrls(configuration.urlConfig)
65
+ : configuration.urlConfig,
66
+ };
67
+
68
+ this.wroomClient = new WroomClient(
69
+ this.config.urlConfig.baseURL,
70
+ this.config.authConfig,
71
+ );
67
72
  this.authClient = createAuthenticationApiClient(
68
- this.urls.authenticationApi,
69
- this.credentials,
73
+ this.config.urlConfig.authenticationApi,
74
+ this.config.authConfig,
75
+ );
76
+ this.manageV2Client = new ManageV2Client(
77
+ this.config.urlConfig.baseURL,
78
+ this.config.manageV2Config,
70
79
  );
71
80
  }
72
81
 
@@ -149,7 +158,7 @@ export class RepositoriesManager {
149
158
  const post = async () =>
150
159
  this.wroomClient.post(repository, "app/settings/delete", {
151
160
  confirm: repository,
152
- password: this.credentials.password,
161
+ password: this.config.authConfig.password,
153
162
  });
154
163
  const response = await post();
155
164
  if (response.status !== 200) {
@@ -183,11 +192,11 @@ export class RepositoriesManager {
183
192
  */
184
193
  getRepositoryManager(name: string): RepositoryManager {
185
194
  const customTypeClient = createCustomTypesApiClient(
186
- this.urls.customTypesApi,
195
+ this.config.urlConfig.customTypesApi,
187
196
  name,
188
197
  this.authClient,
189
198
  );
190
- const coreApiUrl = getRepositoryUrl(this.urls.baseURL, name);
199
+ const coreApiUrl = getRepositoryUrl(this.config.urlConfig.baseURL, name);
191
200
  const coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);
192
201
 
193
202
  return new RepositoryManager(
@@ -195,15 +204,7 @@ export class RepositoriesManager {
195
204
  coreApiClient,
196
205
  this.wroomClient,
197
206
  customTypeClient,
207
+ this.manageV2Client,
198
208
  );
199
209
  }
200
210
  }
201
-
202
- export type UrlConfig = {
203
- /** Prismic base url */
204
- baseURL: string;
205
- /** Custom types api base url */
206
- customTypesApi: string;
207
- /** Auth service api base url */
208
- authenticationApi: string;
209
- };