@prismicio/e2e-tests-utils 1.1.0 → 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,6 +7,7 @@ import {
7
7
 
8
8
  import type { CoreClient } from "../clients/coreApi";
9
9
  import { CustomTypesClient } from "../clients/customTypesApi";
10
+ import { ManageV2Client } from "../clients/manageV2";
10
11
  import { WroomClient } from "../clients/wroom";
11
12
  import { logHttpResponse, logger } from "../utils/log";
12
13
  import { getRepositoryUrl } from "../utils/urls";
@@ -18,6 +19,7 @@ export class RepositoryManager {
18
19
  private readonly coreApiClient: CoreClient,
19
20
  private readonly wroomClient: WroomClient,
20
21
  private readonly customTypesApiClient: CustomTypesClient,
22
+ private readonly manageV2Client: ManageV2Client,
21
23
  ) {}
22
24
 
23
25
  async configure(config: RepositoryConfig): Promise<void> {
@@ -65,6 +67,10 @@ export class RepositoryManager {
65
67
  if (config.preview) {
66
68
  await this.createPreview(config.preview);
67
69
  }
70
+
71
+ if (config.rolePerLocal) {
72
+ await this.toggleRolePerLocal(true);
73
+ }
68
74
  }
69
75
  /** @returns the repository base url, like https://my-repo.prismic.io */
70
76
  getBaseURL(): string {
@@ -318,6 +324,130 @@ export class RepositoryManager {
318
324
  // only return the generated token since there is no need to access more
319
325
  return response.data.wroom_auths[0].token;
320
326
  }
327
+
328
+ /**
329
+ * Toggle the Role per local feature
330
+ *
331
+ * @param enabled - The feature new status
332
+ */
333
+ async toggleRolePerLocal(enabled: boolean): Promise<void> {
334
+ const profiler = logger.startTimer();
335
+
336
+ const response = await this.manageV2Client.toggleRolePerLocal({
337
+ repository: this.name,
338
+ enabled: enabled,
339
+ });
340
+
341
+ this.failIfNot200(
342
+ response,
343
+ `Could not ${enabled ? "enable" : "disable"} Role per local for ${
344
+ this.name
345
+ }`,
346
+ );
347
+ profiler.done({
348
+ message: `Role per local ${enabled ? "enabled" : "disabled"}`,
349
+ });
350
+ }
351
+
352
+ /**
353
+ * Change the Repository Plan
354
+ *
355
+ * @param {string} newPlanId - The Id of the new Plan to apply
356
+ */
357
+ async changePlan(newPlanId: string): Promise<void> {
358
+ const profiler = logger.startTimer();
359
+
360
+ const response = await this.manageV2Client.changePlan({
361
+ repository: this.name,
362
+ newPlanId: newPlanId,
363
+ bypassManualBilling: true, // For now the library does not support Stripe features
364
+ });
365
+
366
+ this.failIfNot200(response, "Could not change the Repository Plan");
367
+ profiler.done({
368
+ message: `Repository Plan changed to ${newPlanId}`,
369
+ });
370
+ }
371
+
372
+ /**
373
+ * Add a new user to the repository
374
+ *
375
+ * @param {string} email - The email of the user
376
+ */
377
+ async addUser(email: string): Promise<void> {
378
+ const profiler = logger.startTimer();
379
+
380
+ const response = await this.manageV2Client.addUserToRepository({
381
+ repository: this.name,
382
+ email: email,
383
+ });
384
+
385
+ this.failIfNot200(response, "Could not add a new user to the repository");
386
+ profiler.done({
387
+ message: `User ${email} was added to the repository`,
388
+ });
389
+ }
390
+
391
+ /**
392
+ * Remove a user from the repository
393
+ *
394
+ * @param {string} email - The email of the user
395
+ */
396
+ async removeUser(email: string): Promise<void> {
397
+ const profiler = logger.startTimer();
398
+
399
+ const response = await this.manageV2Client.removeUserFromRepository({
400
+ repository: this.name,
401
+ email: email,
402
+ });
403
+
404
+ this.failIfNot200(
405
+ response,
406
+ `Could not remove the user ${email} from the repository`,
407
+ );
408
+ profiler.done({
409
+ message: `User ${email} was removed from the repository`,
410
+ });
411
+ }
412
+
413
+ /**
414
+ * Update the role of a user in a repository
415
+ *
416
+ * @param {string} email - The email of the user
417
+ * @param {string | Record<string, string>} role - The new Role of the user,
418
+ * either a string for basic workflow or an object such as `{ "lang_id":
419
+ * "Writer" }`
420
+ *
421
+ * Example of roles are
422
+ *
423
+ * - Administrator
424
+ * - Writer
425
+ * - Contributor
426
+ * - Manager (publisher)
427
+ */
428
+ async updateUserRole(
429
+ email: string,
430
+ role: string | Record<string, string>,
431
+ ): Promise<void> {
432
+ const profiler = logger.startTimer();
433
+
434
+ const response =
435
+ typeof role === "string"
436
+ ? await this.wroomClient.updateRole(this.name, email, role)
437
+ : await this.wroomClient.updateRolePerLocal(this.name, email, role);
438
+
439
+ this.failIfNot200(
440
+ response,
441
+ `Could not update the ${
442
+ typeof role === "string" ? "role" : "rolePerLocal"
443
+ } of the user ${email}`,
444
+ );
445
+ profiler.done({
446
+ message: `Updated User's ${
447
+ typeof role === "string" ? "role" : "rolePerLocal"
448
+ } for user ${email}`,
449
+ });
450
+ }
321
451
  }
322
452
 
323
453
  export type RepositoryConfig = {
@@ -327,6 +457,7 @@ export type RepositoryConfig = {
327
457
  slices?: SharedSlice[];
328
458
  customTypes?: CustomType[];
329
459
  preview?: Preview;
460
+ rolePerLocal?: boolean;
330
461
  };
331
462
 
332
463
  export type Preview = {
package/src/types.ts CHANGED
@@ -1 +1,27 @@
1
- export type Credentials = { email: string; password: string };
1
+ export type UrlConfig = {
2
+ /** Prismic base url */
3
+ baseURL: string;
4
+ /** Custom types api base url */
5
+ customTypesApi: string;
6
+ /** Auth service api base url */
7
+ authenticationApi: string;
8
+ };
9
+
10
+ export type AuthConfig = {
11
+ email: string;
12
+ password: string;
13
+ };
14
+
15
+ export type ManageV2Config = {
16
+ secret: string;
17
+ audience: string;
18
+ };
19
+
20
+ // Global configuration Object
21
+ export type SetupConfiguration = {
22
+ // If provided as a string: It is treated as the base URL for Prismic. Other
23
+ // URLs (Custom Types API, Auth API) will be derived from it.
24
+ urlConfig: UrlConfig | string;
25
+ authConfig: AuthConfig;
26
+ manageV2Config?: ManageV2Config;
27
+ };