@prismicio/e2e-tests-utils 2.0.0-alpha.0 → 2.0.0-alpha.10

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.
Files changed (43) hide show
  1. package/dist/clients/assetApi.cjs +48 -0
  2. package/dist/clients/assetApi.cjs.map +1 -0
  3. package/dist/clients/assetApi.d.ts +54 -0
  4. package/dist/clients/assetApi.js +48 -0
  5. package/dist/clients/assetApi.js.map +1 -0
  6. package/dist/clients/authenticationApi.cjs +3 -10
  7. package/dist/clients/authenticationApi.cjs.map +1 -1
  8. package/dist/clients/authenticationApi.js +3 -10
  9. package/dist/clients/authenticationApi.js.map +1 -1
  10. package/dist/clients/manageV2.cjs +19 -6
  11. package/dist/clients/manageV2.cjs.map +1 -1
  12. package/dist/clients/manageV2.d.ts +15 -5
  13. package/dist/clients/manageV2.js +19 -6
  14. package/dist/clients/manageV2.js.map +1 -1
  15. package/dist/clients/wroom.cjs +10 -16
  16. package/dist/clients/wroom.cjs.map +1 -1
  17. package/dist/clients/wroom.d.ts +6 -6
  18. package/dist/clients/wroom.js +10 -16
  19. package/dist/clients/wroom.js.map +1 -1
  20. package/dist/managers/repositories.cjs +10 -3
  21. package/dist/managers/repositories.cjs.map +1 -1
  22. package/dist/managers/repositories.js +10 -3
  23. package/dist/managers/repositories.js.map +1 -1
  24. package/dist/managers/repository.cjs +65 -9
  25. package/dist/managers/repository.cjs.map +1 -1
  26. package/dist/managers/repository.d.ts +41 -9
  27. package/dist/managers/repository.js +65 -9
  28. package/dist/managers/repository.js.map +1 -1
  29. package/dist/types.d.ts +3 -0
  30. package/dist/utils/authentication.cjs +38 -0
  31. package/dist/utils/authentication.cjs.map +1 -0
  32. package/dist/utils/authentication.d.ts +4 -0
  33. package/dist/utils/authentication.js +38 -0
  34. package/dist/utils/authentication.js.map +1 -0
  35. package/package.json +3 -2
  36. package/src/clients/assetApi.ts +76 -0
  37. package/src/clients/authenticationApi.ts +7 -10
  38. package/src/clients/manageV2.ts +22 -6
  39. package/src/clients/wroom.ts +14 -17
  40. package/src/managers/repositories.ts +17 -1
  41. package/src/managers/repository.ts +102 -8
  42. package/src/types.ts +3 -0
  43. package/src/utils/authentication.ts +58 -0
@@ -1,4 +1,5 @@
1
1
  import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
+ import { AssetApiClient } from "../clients/assetApi";
2
3
  import { AuthenticationApiClient } from "../clients/authenticationApi";
3
4
  import { ContentApiClient } from "../clients/contentApi";
4
5
  import { CoreApiClient, CoreApiDocumentCreationPayload, CoreApiDocumentCreationResponse } from "../clients/coreApi";
@@ -14,8 +15,9 @@ export declare class RepositoryManager {
14
15
  private readonly wroomClient;
15
16
  private readonly customTypesApiClient;
16
17
  private readonly migrationApiClient;
18
+ private readonly assetApiClient;
17
19
  private readonly manageV2Client;
18
- constructor(name: string, coreApiClient: CoreApiClient, authApiClient: AuthenticationApiClient, wroomClient: WroomClient, customTypesApiClient: CustomTypesApiClient, migrationApiClient: MigrationApiClient | undefined, manageV2Client: ManageV2Client);
20
+ constructor(name: string, coreApiClient: CoreApiClient, authApiClient: AuthenticationApiClient, wroomClient: WroomClient, customTypesApiClient: CustomTypesApiClient, migrationApiClient: MigrationApiClient | undefined, assetApiClient: AssetApiClient, manageV2Client: ManageV2Client);
19
21
  configure(config: RepositoryConfig): Promise<void>;
20
22
  /** @returns the repository base url, like https://my-repo.prismic.io */
21
23
  getBaseURL(): string;
@@ -35,6 +37,11 @@ export declare class RepositoryManager {
35
37
  * https://prismic.io/docs/migration-api-technical-reference
36
38
  */
37
39
  getMigrationApiClient(): MigrationApiClient;
40
+ /**
41
+ * @returns an instance of the Asset api client, see
42
+ * https://prismic.io/docs/asset-api-technical-reference
43
+ */
44
+ getAssetApiClient(): AssetApiClient;
38
45
  /** @returns the Wroom commit hash deployed on the current repository */
39
46
  getDeployedVersion(): Promise<string | undefined>;
40
47
  /**
@@ -104,6 +111,25 @@ export declare class RepositoryManager {
104
111
  * @param id - The ID of the preview to be deleted.
105
112
  */
106
113
  deletePreview(id: string): Promise<void>;
114
+ /**
115
+ * Create a webhook.
116
+ *
117
+ * @returns A Promise that resolves with the webhook id.
118
+ */
119
+ createWebhook(name: string, url: string, secret: string, triggers: {
120
+ documentsPublished?: boolean;
121
+ documentsUnpublished?: boolean;
122
+ releasesCreated?: boolean;
123
+ releasesUpdated?: boolean;
124
+ tagsCreated?: boolean;
125
+ tagsDeleted?: boolean;
126
+ }, active: boolean): Promise<string>;
127
+ /**
128
+ * Deletes a webhook.
129
+ *
130
+ * @param id - The webhook ID.
131
+ */
132
+ deleteWebhook(id: string): Promise<void>;
107
133
  /**
108
134
  * Create Custom Types using the Custom types api.
109
135
  *
@@ -127,36 +153,41 @@ export declare class RepositoryManager {
127
153
  /** Create a permanent access token to authenticate to Prismic public apis. */
128
154
  createPermanentAccessToken(): Promise<string>;
129
155
  /**
130
- * Toggle the Role per local feature
156
+ * Toggle the Role per Locale workflow
131
157
  *
132
158
  * @param enabled - The feature new status
133
159
  */
134
160
  toggleRolePerLocal(enabled: boolean): Promise<void>;
161
+ /**
162
+ * Toggle the Custom Roles workflow
163
+ *
164
+ * @param enabled - The feature new status
165
+ */
166
+ toggleCustomRoles(enabled: boolean): Promise<void>;
135
167
  /**
136
168
  * Change the Repository Plan
137
169
  *
138
- * @param {string} newPlanId - The Id of the new Plan to apply
170
+ * @param newPlanId - The Id of the new Plan to apply
139
171
  */
140
172
  changePlan(newPlanId: string): Promise<void>;
141
173
  /**
142
174
  * Add a new user to the repository
143
175
  *
144
- * @param {string} email - The email of the user
176
+ * @param email - The email of the user
145
177
  */
146
178
  addUser(email: string): Promise<void>;
147
179
  /**
148
180
  * Remove a user from the repository
149
181
  *
150
- * @param {string} email - The email of the user
182
+ * @param email - The email of the user
151
183
  */
152
184
  removeUser(email: string): Promise<void>;
153
185
  /**
154
186
  * Update the role of a user in a repository
155
187
  *
156
- * @param {string} email - The email of the user
157
- * @param {string | Record<string, string>} role - The new Role of the user,
158
- * either a string for basic workflow or an object such as `{ "lang_id":
159
- * "Writer" }`
188
+ * @param email - The email of the user
189
+ * @param role - The new Role of the user, either a string for basic workflow
190
+ * or an object such as `{ "lang_id": "Writer" }`
160
191
  *
161
192
  * Example of roles are
162
193
  *
@@ -211,6 +242,7 @@ export type RepositoryConfig = {
211
242
  customTypes?: CustomType[];
212
243
  preview?: Preview;
213
244
  rolePerLocal?: boolean;
245
+ customRoles?: boolean;
214
246
  };
215
247
  export type Preview = {
216
248
  name: string;
@@ -9,13 +9,14 @@ import { ContentApiClient } from "../clients/contentApi.js";
9
9
  import { logger, logHttpResponse } from "../utils/log.js";
10
10
  import { getRepositoryUrl } from "../utils/urls.js";
11
11
  class RepositoryManager {
12
- constructor(name, coreApiClient, authApiClient, wroomClient, customTypesApiClient, migrationApiClient, manageV2Client) {
12
+ constructor(name, coreApiClient, authApiClient, wroomClient, customTypesApiClient, migrationApiClient, assetApiClient, manageV2Client) {
13
13
  __publicField(this, "name");
14
14
  __publicField(this, "coreApiClient");
15
15
  __publicField(this, "authApiClient");
16
16
  __publicField(this, "wroomClient");
17
17
  __publicField(this, "customTypesApiClient");
18
18
  __publicField(this, "migrationApiClient");
19
+ __publicField(this, "assetApiClient");
19
20
  __publicField(this, "manageV2Client");
20
21
  this.name = name;
21
22
  this.coreApiClient = coreApiClient;
@@ -23,6 +24,7 @@ class RepositoryManager {
23
24
  this.wroomClient = wroomClient;
24
25
  this.customTypesApiClient = customTypesApiClient;
25
26
  this.migrationApiClient = migrationApiClient;
27
+ this.assetApiClient = assetApiClient;
26
28
  this.manageV2Client = manageV2Client;
27
29
  }
28
30
  async configure(config) {
@@ -68,6 +70,9 @@ class RepositoryManager {
68
70
  if (config.rolePerLocal) {
69
71
  await this.toggleRolePerLocal(true);
70
72
  }
73
+ if (config.customRoles) {
74
+ await this.toggleCustomRoles(true);
75
+ }
71
76
  }
72
77
  /** @returns the repository base url, like https://my-repo.prismic.io */
73
78
  getBaseURL() {
@@ -95,6 +100,13 @@ class RepositoryManager {
95
100
  }
96
101
  return this.migrationApiClient;
97
102
  }
103
+ /**
104
+ * @returns an instance of the Asset api client, see
105
+ * https://prismic.io/docs/asset-api-technical-reference
106
+ */
107
+ getAssetApiClient() {
108
+ return this.assetApiClient;
109
+ }
98
110
  /** @returns the Wroom commit hash deployed on the current repository */
99
111
  async getDeployedVersion() {
100
112
  const response = await this.wroomClient.get(this.name, "underground/834b34f16f451e00f268dd5c8c81d16e3c020275");
@@ -236,6 +248,35 @@ class RepositoryManager {
236
248
  this.failIfNot200(response, `Could not delete preview with id ${id}`);
237
249
  profiler.done({ message: `preview '${id}' deleted` });
238
250
  }
251
+ /**
252
+ * Create a webhook.
253
+ *
254
+ * @returns A Promise that resolves with the webhook id.
255
+ */
256
+ async createWebhook(name, url, secret, triggers, active) {
257
+ const profiler = logger.startTimer();
258
+ const response = await this.wroomClient.post(this.name, "app/settings/webhooks/create", {
259
+ name,
260
+ url,
261
+ secret,
262
+ active: active ? "on" : "off",
263
+ ...triggers
264
+ });
265
+ this.failIfNot200(response, `Could not create webhook ${name}`);
266
+ profiler.done({ message: `webhook '${name}' created` });
267
+ return response.data.created;
268
+ }
269
+ /**
270
+ * Deletes a webhook.
271
+ *
272
+ * @param id - The webhook ID.
273
+ */
274
+ async deleteWebhook(id) {
275
+ const profiler = logger.startTimer();
276
+ const response = await this.wroomClient.post(this.name, `app/settings/webhooks/${id}/delete`, {});
277
+ this.failIfNot200(response, `Could not delete webhook with id ${id}`);
278
+ profiler.done({ message: `webhook '${id}' deleted` });
279
+ }
239
280
  /**
240
281
  * Create Custom Types using the Custom types api.
241
282
  *
@@ -300,7 +341,7 @@ class RepositoryManager {
300
341
  return token;
301
342
  }
302
343
  /**
303
- * Toggle the Role per local feature
344
+ * Toggle the Role per Locale workflow
304
345
  *
305
346
  * @param enabled - The feature new status
306
347
  */
@@ -315,10 +356,26 @@ class RepositoryManager {
315
356
  message: `Role per local ${enabled ? "enabled" : "disabled"}`
316
357
  });
317
358
  }
359
+ /**
360
+ * Toggle the Custom Roles workflow
361
+ *
362
+ * @param enabled - The feature new status
363
+ */
364
+ async toggleCustomRoles(enabled) {
365
+ const profiler = logger.startTimer();
366
+ const response = await this.manageV2Client.toggleCustomRoles({
367
+ repository: this.name,
368
+ enabled
369
+ });
370
+ this.failIfNot200(response, `Could not ${enabled ? "enable" : "disable"} Custom Roles for ${this.name}`);
371
+ profiler.done({
372
+ message: `Custom Roles ${enabled ? "enabled" : "disabled"}`
373
+ });
374
+ }
318
375
  /**
319
376
  * Change the Repository Plan
320
377
  *
321
- * @param {string} newPlanId - The Id of the new Plan to apply
378
+ * @param newPlanId - The Id of the new Plan to apply
322
379
  */
323
380
  async changePlan(newPlanId) {
324
381
  const profiler = logger.startTimer();
@@ -336,7 +393,7 @@ class RepositoryManager {
336
393
  /**
337
394
  * Add a new user to the repository
338
395
  *
339
- * @param {string} email - The email of the user
396
+ * @param email - The email of the user
340
397
  */
341
398
  async addUser(email) {
342
399
  const profiler = logger.startTimer();
@@ -357,7 +414,7 @@ class RepositoryManager {
357
414
  /**
358
415
  * Remove a user from the repository
359
416
  *
360
- * @param {string} email - The email of the user
417
+ * @param email - The email of the user
361
418
  */
362
419
  async removeUser(email) {
363
420
  const profiler = logger.startTimer();
@@ -373,10 +430,9 @@ class RepositoryManager {
373
430
  /**
374
431
  * Update the role of a user in a repository
375
432
  *
376
- * @param {string} email - The email of the user
377
- * @param {string | Record<string, string>} role - The new Role of the user,
378
- * either a string for basic workflow or an object such as `{ "lang_id":
379
- * "Writer" }`
433
+ * @param email - The email of the user
434
+ * @param role - The new Role of the user, either a string for basic workflow
435
+ * or an object such as `{ "lang_id": "Writer" }`
380
436
  *
381
437
  * Example of roles are
382
438
  *
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { expect } from \"@playwright/test\";\nimport { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { AuthenticationApiClient } from \"../clients/authenticationApi\";\nimport { ContentApiClient } from \"../clients/contentApi\";\nimport {\n\tCoreApiClient,\n\tCoreApiDocumentCreationPayload,\n\tCoreApiDocumentCreationResponse,\n} from \"../clients/coreApi\";\nimport { CustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { MigrationApiClient } from \"../clients/migrationApi\";\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: CoreApiClient,\n\t\tprivate readonly authApiClient: AuthenticationApiClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesApiClient,\n\t\tprivate readonly migrationApiClient: MigrationApiClient | undefined,\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\t\t\tlet updateDefaultLocaleAtTheEnd = false;\n\t\t\t// if no locale exists on repo, the master locale needs to 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, \"create\");\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\t// update the master lang at the end, after it is created.\n\t\t\t\t\tupdateDefaultLocaleAtTheEnd = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\t// No need to add default locale and already existing languages\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\n\t\t\tif (config.defaultLocale && updateDefaultLocaleAtTheEnd) {\n\t\t\t\tawait this.setDefaultLocale(config.defaultLocale, \"update\");\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\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/** @returns the repository base cdn url, like https://my-repo.cdn.prismic.io */\n\tgetBaseCdnURL(): string {\n\t\treturn getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`);\n\t}\n\n\t/**\n\t * @returns a Content Type api client configured to target the repository CDN\n\t * url. Uses Playwright for requests so if your project uses Playwright too,\n\t * any network request will be present in Playwright test reports.\n\t */\n\tgetContentApiClient(config?: {\n\t\tversion?: \"v1\" | \"v2\";\n\t\taccessToken?: string;\n\t}): ContentApiClient {\n\t\treturn new ContentApiClient(this.getBaseCdnURL(), config);\n\t}\n\n\t/**\n\t * @returns an instance of the Migration api client, see\n\t * https://prismic.io/docs/migration-api-technical-reference\n\t */\n\tgetMigrationApiClient(): MigrationApiClient {\n\t\tif (!this.migrationApiClient) {\n\t\t\tthrow \"No client found for the migration api. Did you provide a migration api url in the configuration?\";\n\t\t}\n\n\t\treturn this.migrationApiClient;\n\t}\n\n\t/** @returns the Wroom commit hash deployed on the current repository */\n\tasync getDeployedVersion(): Promise<string | undefined> {\n\t\tconst response = await this.wroomClient.get(\n\t\t\tthis.name,\n\t\t\t\"underground/834b34f16f451e00f268dd5c8c81d16e3c020275\",\n\t\t);\n\n\t\t// Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute\n\t\treturn response.data.version;\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 * Create or update the default (master) locale for a repository in Wroom, the\n\t * locale needs to exist in the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t * @param endpoint - \"createMasterLang\" to create it, \"defineAsMaster\" to\n\t * update it.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(\n\t\tlocale: string,\n\t\taction: \"create\" | \"update\",\n\t): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst endpoint = {\n\t\t\tcreate: \"createMasterLang\",\n\t\t\tupdate: \"defineAsMaster\",\n\t\t};\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/${endpoint[action]}`,\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 an access token to query private items of the Content api.\n\t *\n\t * @param appName - mandatory authorized application name\n\t * @param tokenScope - access token scope. Use \"master\" to when your content\n\t * api is fully private or \"master+releases\" to access private releases\n\t */\n\tasync createContentAPIToken(\n\t\tappName: string,\n\t\ttokenScope: \"master\" | \"master+releases\" = \"master\",\n\t): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\t\ttype AuthorizedAppResponse = {\n\t\t\tid: string;\n\t\t\tname: string;\n\t\t\twroom_auths: { token: string; scope: \"master\" | \"master+releases\" }[];\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 content api token`,\n\t\t);\n\t\tlet app = existingApps.data.find(({ name, wroom_auths }) => {\n\t\t\treturn name === appName && wroom_auths.length > 0;\n\t\t});\n\n\t\tif (!app) {\n\t\t\tconst response: AxiosResponse<AuthorizedAppResponse> =\n\t\t\t\tawait this.wroomClient.post(this.name, \"settings/security/oauthapp\", {\n\t\t\t\t\tapp_name: appName,\n\t\t\t\t});\n\n\t\t\tthis.failIfNot200(\n\t\t\t\tresponse,\n\t\t\t\t`Could not create content api app ${appName}`,\n\t\t\t);\n\t\t\tapp = response.data;\n\t\t}\n\n\t\tlet tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope);\n\t\tif (!tokenInfo) {\n\t\t\tconst response = await this.wroomClient.post(\n\t\t\t\tthis.name,\n\t\t\t\t\"settings/security/authorizations\",\n\t\t\t\t{\n\t\t\t\t\tapp: app.id,\n\t\t\t\t\tscope: tokenScope,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis.failIfNot200(\n\t\t\t\tresponse,\n\t\t\t\t`Could not create content api access token for app ${appName} with scope ${tokenScope}`,\n\t\t\t);\n\t\t\ttokenInfo = response.data;\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `content api access token for app '${appName}' created`,\n\t\t});\n\n\t\tif (!tokenInfo?.token) {\n\t\t\tthrow `Could not create content api access token for app ${appName} with scope ${tokenScope}`;\n\t\t}\n\n\t\treturn tokenInfo.token;\n\t}\n\n\t/** Create a permanent access token to authenticate to Prismic public apis. */\n\tasync createPermanentAccessToken(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst token = await this.authApiClient.getMachine2MachineToken(this.name);\n\n\t\tprofiler.done({\n\t\t\tmessage: `machine2machine token created`,\n\t\t});\n\n\t\treturn 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\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 409 &&\n\t\t\t\tJSON.stringify(data).includes(\"already a member of the repo\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add a new user ${email} to the repository`);\n\t\t}\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\t/**\n\t * Creates a document using the core api. If the Core api format is too\n\t * specific, use the migration api client to create a document with the\n\t * MigrationApiClient. See the `getMigrationApiClient()` method.\n\t *\n\t * @example To create a document by converting it from the Page Builder to\n\t * Core api format\n\t *\n\t * ```js\n\t * import { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';\n\t *\n\t * const document = {\n\t * title: 'A new document',\n\t * custom_type_id: 'home-page',\n\t * locale: 'en-gb',\n\t * integration_field_ids: [],\n\t * tags: [],\n\t * data: DocumentLegacy.encode({\n\t * uid: {\n\t * __TYPE__: UIDContentType,\n\t * value: 'home-page',\n\t * },\n\t * })\n\t * }\n\t * await repository.createDocument(document, 'published');\n\t * \t * ```\n\t * ```\n\t *\n\t * @returns\n\t *\n\t * @param document - in the core api format.\n\t *\n\t * @param status - status of the document, if published, the function will\n\t * wait for a new content api master ref to be created\n\t */\n\tasync createDocument(\n\t\tdocument: CoreApiDocumentCreationPayload,\n\t\tstatus: \"draft\" | \"published\",\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst result = await this.coreApiClient.createDraft(document);\n\n\t\tlet message = `Document created with id '${result.id}'`;\n\t\tif (status === \"published\") {\n\t\t\tconst contentApi = this.getContentApiClient();\n\t\t\tconst masterRef = await contentApi.getMasterRef();\n\t\t\tawait this.coreApiClient.publishDraft(result.id);\n\t\t\tawait expect\n\t\t\t\t.poll(async () => contentApi.getMasterRef(), {\n\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t\tmessage: \"Waiting for new master ref to be available\",\n\t\t\t\t})\n\t\t\t\t.not.toBe(masterRef);\n\t\t\tmessage += \", status 'published' and new master ref available\";\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage,\n\t\t});\n\n\t\treturn result;\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":";;;;;;;;;;MAuBa,kBAAiB;AAAA,EAC7B,YACU,MACQ,eACA,eACA,aACA,sBACA,oBACA,gBAA8B;AANtC;AACQ;AACA;AACA;AACA;AACA;AACA;AANR,SAAI,OAAJ;AACQ,SAAa,gBAAb;AACA,SAAa,gBAAb;AACA,SAAW,cAAX;AACA,SAAoB,uBAApB;AACA,SAAkB,qBAAlB;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;AACvD,UAAI,8BAA8B;AAElC,UAAI,OAAO,eAAe;AACnB,cAAA,SAAS,UAAU,KAAK,CAAC,EAAE,gBAAgB,cAAc,IAAI;AACnE,YAAI,CAAC,QAAQ;AACZ,gBAAM,KAAK,iBAAiB,OAA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version":3,"file":"repository.js","sources":["../../../src/managers/repository.ts"],"sourcesContent":["import { expect } from \"@playwright/test\";\nimport { AxiosResponse } from \"axios\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { AssetApiClient } from \"../clients/assetApi\";\nimport { AuthenticationApiClient } from \"../clients/authenticationApi\";\nimport { ContentApiClient } from \"../clients/contentApi\";\nimport {\n\tCoreApiClient,\n\tCoreApiDocumentCreationPayload,\n\tCoreApiDocumentCreationResponse,\n} from \"../clients/coreApi\";\nimport { CustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { MigrationApiClient } from \"../clients/migrationApi\";\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: CoreApiClient,\n\t\tprivate readonly authApiClient: AuthenticationApiClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesApiClient,\n\t\tprivate readonly migrationApiClient: MigrationApiClient | undefined,\n\t\tprivate readonly assetApiClient: AssetApiClient,\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\t\t\tlet updateDefaultLocaleAtTheEnd = false;\n\t\t\t// if no locale exists on repo, the master locale needs to 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, \"create\");\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\t// update the master lang at the end, after it is created.\n\t\t\t\t\tupdateDefaultLocaleAtTheEnd = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\t// No need to add default locale and already existing languages\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\n\t\t\tif (config.defaultLocale && updateDefaultLocaleAtTheEnd) {\n\t\t\t\tawait this.setDefaultLocale(config.defaultLocale, \"update\");\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\n\t\tif (config.customRoles) {\n\t\t\tawait this.toggleCustomRoles(true);\n\t\t}\n\t}\n\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/** @returns the repository base cdn url, like https://my-repo.cdn.prismic.io */\n\tgetBaseCdnURL(): string {\n\t\treturn getRepositoryUrl(this.wroomClient.getBaseURL(), `${this.name}.cdn`);\n\t}\n\n\t/**\n\t * @returns a Content Type api client configured to target the repository CDN\n\t * url. Uses Playwright for requests so if your project uses Playwright too,\n\t * any network request will be present in Playwright test reports.\n\t */\n\tgetContentApiClient(config?: {\n\t\tversion?: \"v1\" | \"v2\";\n\t\taccessToken?: string;\n\t}): ContentApiClient {\n\t\treturn new ContentApiClient(this.getBaseCdnURL(), config);\n\t}\n\n\t/**\n\t * @returns an instance of the Migration api client, see\n\t * https://prismic.io/docs/migration-api-technical-reference\n\t */\n\tgetMigrationApiClient(): MigrationApiClient {\n\t\tif (!this.migrationApiClient) {\n\t\t\tthrow \"No client found for the migration api. Did you provide a migration api url in the configuration?\";\n\t\t}\n\n\t\treturn this.migrationApiClient;\n\t}\n\n\t/**\n\t * @returns an instance of the Asset api client, see\n\t * https://prismic.io/docs/asset-api-technical-reference\n\t */\n\tgetAssetApiClient(): AssetApiClient {\n\t\treturn this.assetApiClient;\n\t}\n\n\t/** @returns the Wroom commit hash deployed on the current repository */\n\tasync getDeployedVersion(): Promise<string | undefined> {\n\t\tconst response = await this.wroomClient.get(\n\t\t\tthis.name,\n\t\t\t\"underground/834b34f16f451e00f268dd5c8c81d16e3c020275\",\n\t\t);\n\n\t\t// Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute\n\t\treturn response.data.version;\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 * Create or update the default (master) locale for a repository in Wroom, the\n\t * locale needs to exist in the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t * @param endpoint - \"createMasterLang\" to create it, \"defineAsMaster\" to\n\t * update it.\n\t *\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(\n\t\tlocale: string,\n\t\taction: \"create\" | \"update\",\n\t): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst endpoint = {\n\t\t\tcreate: \"createMasterLang\",\n\t\t\tupdate: \"defineAsMaster\",\n\t\t};\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/${endpoint[action]}`,\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 a webhook.\n\t *\n\t * @returns A Promise that resolves with the webhook id.\n\t */\n\tasync createWebhook(\n\t\tname: string,\n\t\turl: string,\n\t\tsecret: string,\n\t\ttriggers: {\n\t\t\tdocumentsPublished?: boolean;\n\t\t\tdocumentsUnpublished?: boolean;\n\t\t\treleasesCreated?: boolean;\n\t\t\treleasesUpdated?: boolean;\n\t\t\ttagsCreated?: boolean;\n\t\t\ttagsDeleted?: boolean;\n\t\t},\n\t\tactive: boolean,\n\t): Promise<string> {\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/webhooks/create\",\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\turl,\n\t\t\t\tsecret,\n\t\t\t\tactive: active ? \"on\" : \"off\",\n\t\t\t\t...triggers,\n\t\t\t},\n\t\t);\n\t\tthis.failIfNot200(response, `Could not create webhook ${name}`);\n\t\tprofiler.done({ message: `webhook '${name}' created` });\n\n\t\treturn response.data.created;\n\t}\n\n\t/**\n\t * Deletes a webhook.\n\t *\n\t * @param id - The webhook ID.\n\t */\n\tasync deleteWebhook(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/settings/webhooks/${id}/delete`,\n\t\t\t{},\n\t\t);\n\n\t\tthis.failIfNot200(response, `Could not delete webhook with id ${id}`);\n\t\tprofiler.done({ message: `webhook '${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 an access token to query private items of the Content api.\n\t *\n\t * @param appName - mandatory authorized application name\n\t * @param tokenScope - access token scope. Use \"master\" to when your content\n\t * api is fully private or \"master+releases\" to access private releases\n\t */\n\tasync createContentAPIToken(\n\t\tappName: string,\n\t\ttokenScope: \"master\" | \"master+releases\" = \"master\",\n\t): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\t\ttype AuthorizedAppResponse = {\n\t\t\tid: string;\n\t\t\tname: string;\n\t\t\twroom_auths: { token: string; scope: \"master\" | \"master+releases\" }[];\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 content api token`,\n\t\t);\n\t\tlet app = existingApps.data.find(({ name, wroom_auths }) => {\n\t\t\treturn name === appName && wroom_auths.length > 0;\n\t\t});\n\n\t\tif (!app) {\n\t\t\tconst response: AxiosResponse<AuthorizedAppResponse> =\n\t\t\t\tawait this.wroomClient.post(this.name, \"settings/security/oauthapp\", {\n\t\t\t\t\tapp_name: appName,\n\t\t\t\t});\n\n\t\t\tthis.failIfNot200(\n\t\t\t\tresponse,\n\t\t\t\t`Could not create content api app ${appName}`,\n\t\t\t);\n\t\t\tapp = response.data;\n\t\t}\n\n\t\tlet tokenInfo = app.wroom_auths.find(({ scope }) => scope === tokenScope);\n\t\tif (!tokenInfo) {\n\t\t\tconst response = await this.wroomClient.post(\n\t\t\t\tthis.name,\n\t\t\t\t\"settings/security/authorizations\",\n\t\t\t\t{\n\t\t\t\t\tapp: app.id,\n\t\t\t\t\tscope: tokenScope,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis.failIfNot200(\n\t\t\t\tresponse,\n\t\t\t\t`Could not create content api access token for app ${appName} with scope ${tokenScope}`,\n\t\t\t);\n\t\t\ttokenInfo = response.data;\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `content api access token for app '${appName}' created`,\n\t\t});\n\n\t\tif (!tokenInfo?.token) {\n\t\t\tthrow `Could not create content api access token for app ${appName} with scope ${tokenScope}`;\n\t\t}\n\n\t\treturn tokenInfo.token;\n\t}\n\n\t/** Create a permanent access token to authenticate to Prismic public apis. */\n\tasync createPermanentAccessToken(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst token = await this.authApiClient.getMachine2MachineToken(this.name);\n\n\t\tprofiler.done({\n\t\t\tmessage: `machine2machine token created`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/**\n\t * Toggle the Role per Locale workflow\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 * Toggle the Custom Roles workflow\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleCustomRoles(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst response = await this.manageV2Client.toggleCustomRoles({\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\"} Custom Roles for ${\n\t\t\t\tthis.name\n\t\t\t}`,\n\t\t);\n\t\tprofiler.done({\n\t\t\tmessage: `Custom Roles ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t});\n\t}\n\n\t/**\n\t * Change the Repository Plan\n\t *\n\t * @param 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 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\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 409 &&\n\t\t\t\tJSON.stringify(data).includes(\"already a member of the repo\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add a new user ${email} to the repository`);\n\t\t}\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 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 email - The email of the user\n\t * @param role - The new Role of the user, either a string for basic workflow\n\t * or an object such as `{ \"lang_id\": \"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\t/**\n\t * Creates a document using the core api. If the Core api format is too\n\t * specific, use the migration api client to create a document with the\n\t * MigrationApiClient. See the `getMigrationApiClient()` method.\n\t *\n\t * @example To create a document by converting it from the Page Builder to\n\t * Core api format\n\t *\n\t * ```js\n\t * import { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';\n\t *\n\t * const document = {\n\t * title: 'A new document',\n\t * custom_type_id: 'home-page',\n\t * locale: 'en-gb',\n\t * integration_field_ids: [],\n\t * tags: [],\n\t * data: DocumentLegacy.encode({\n\t * uid: {\n\t * __TYPE__: UIDContentType,\n\t * value: 'home-page',\n\t * },\n\t * })\n\t * }\n\t * await repository.createDocument(document, 'published');\n\t * \t * ```\n\t * ```\n\t *\n\t * @returns\n\t *\n\t * @param document - in the core api format.\n\t *\n\t * @param status - status of the document, if published, the function will\n\t * wait for a new content api master ref to be created\n\t */\n\tasync createDocument(\n\t\tdocument: CoreApiDocumentCreationPayload,\n\t\tstatus: \"draft\" | \"published\",\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst result = await this.coreApiClient.createDraft(document);\n\n\t\tlet message = `Document created with id '${result.id}'`;\n\t\tif (status === \"published\") {\n\t\t\tconst contentApi = this.getContentApiClient();\n\t\t\tconst masterRef = await contentApi.getMasterRef();\n\t\t\tawait this.coreApiClient.publishDraft(result.id);\n\t\t\tawait expect\n\t\t\t\t.poll(async () => contentApi.getMasterRef(), {\n\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t\tmessage: \"Waiting for new master ref to be available\",\n\t\t\t\t})\n\t\t\t\t.not.toBe(masterRef);\n\t\t\tmessage += \", status 'published' and new master ref available\";\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage,\n\t\t});\n\n\t\treturn result;\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\tcustomRoles?: 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":";;;;;;;;;;MAwBa,kBAAiB;AAAA,EAC7B,YACU,MACQ,eACA,eACA,aACA,sBACA,oBAC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OAAO;AACxB,UAAM,SAAS,MAAM,KAAK,cAAc,YAAY,QAAQ;AAExD,QAAA,UAAU,6BAA6B,OAAO,EAAE;AACpD,QAAI,WAAW,aAAa;AACrB,YAAA,aAAa,KAAK;AAClB,YAAA,YAAY,MAAM,WAAW;AACnC,YAAM,KAAK,cAAc,aAAa,OAAO,EAAE;AAC/C,YAAM,OACJ,KAAK,YAAY,WAAW,gBAAgB;AAAA,QAC5C,SAAS;AAAA,QACT,SAAS;AAAA,MACT,CAAA,EACA,IAAI,KAAK,SAAS;AACT,iBAAA;AAAA,IACZ;AACA,aAAS,KAAK;AAAA,MACb;AAAA,IAAA,CACA;AAEM,WAAA;AAAA,EACR;AACA;"}
package/dist/types.d.ts CHANGED
@@ -7,6 +7,8 @@ export type UrlConfig = {
7
7
  authenticationApi: string;
8
8
  /** Prismic migration api base url */
9
9
  migrationApi?: string;
10
+ /** Asset api base url */
11
+ assetApi: string;
10
12
  };
11
13
  export type AuthConfig = {
12
14
  email: string;
@@ -21,4 +23,5 @@ export type SetupConfiguration = {
21
23
  authConfig: AuthConfig;
22
24
  manageV2Config?: ManageV2Config;
23
25
  cluster?: string;
26
+ environment?: string;
24
27
  };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const axios = require("axios");
4
+ const log = require("./log.cjs");
5
+ async function login(baseUrl, email, password) {
6
+ const profiler = log.logger.startTimer();
7
+ const payload = {
8
+ email,
9
+ password
10
+ };
11
+ const url = transformUrl(baseUrl, "auth.internal");
12
+ const response = await axios.post(`${url}/login-e2e`, payload, {
13
+ headers: {
14
+ "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
15
+ Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c"
16
+ }
17
+ });
18
+ if (response.status !== 200) {
19
+ log.logHttpResponse(response);
20
+ throw new Error("Could not obtain OAuth token, check your credentials");
21
+ }
22
+ profiler.done({ message: "logged in via OAuth" });
23
+ const token = response.data.token;
24
+ return { token, cookies: response.headers["set-cookie"] };
25
+ }
26
+ function transformUrl(baseUrl, subdomainPrefix) {
27
+ try {
28
+ const url = new URL(baseUrl);
29
+ const domainParts = url.hostname.split(".");
30
+ const mainDomain = domainParts.slice(-2).join(".");
31
+ const transformedHostname = `${subdomainPrefix}.${mainDomain}`;
32
+ return `${url.protocol}//${transformedHostname}`;
33
+ } catch (error) {
34
+ throw new Error(`Invalid URL: ${baseUrl}`);
35
+ }
36
+ }
37
+ exports.login = login;
38
+ //# sourceMappingURL=authentication.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.cjs","sources":["../../../src/utils/authentication.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport { logHttpResponse, logger } from \"./log\";\n\nexport async function login(\n\tbaseUrl: string,\n\temail: string,\n\tpassword: string,\n): Promise<{ token: string; cookies: string[] | undefined }> {\n\tconst profiler = logger.startTimer();\n\n\tconst payload = {\n\t\temail,\n\t\tpassword,\n\t};\n\n\tconst url = transformUrl(baseUrl, \"auth.internal\");\n\n\tconst response = await axios.post<{ token: string }>(\n\t\t`${url}/login-e2e`,\n\t\tpayload,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization:\n\t\t\t\t\t\"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c\",\n\t\t\t},\n\t\t},\n\t);\n\n\tif (response.status !== 200) {\n\t\tlogHttpResponse(response);\n\t\tthrow new Error(\"Could not obtain OAuth token, check your credentials\");\n\t}\n\n\tprofiler.done({ message: \"logged in via OAuth\" });\n\tconst token = response.data.token;\n\n\treturn { token, cookies: response.headers[\"set-cookie\"] };\n}\n\nfunction transformUrl(baseUrl: string, subdomainPrefix: string): string {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\tconst domainParts = url.hostname.split(\".\");\n\n\t\t// Ensure we retain only the main domain (e.g., \"platform-wroom.com\")\n\t\tconst mainDomain = domainParts.slice(-2).join(\".\"); // Keeps last two parts of domain\n\n\t\t// Construct the new hostname with the custom prefix\n\t\tconst transformedHostname = `${subdomainPrefix}.${mainDomain}`;\n\n\t\t// Construct and return the full URL with the new hostname\n\t\treturn `${url.protocol}//${transformedHostname}`;\n\t} catch (error) {\n\t\tthrow new Error(`Invalid URL: ${baseUrl}`);\n\t}\n}\n"],"names":["logger","logHttpResponse"],"mappings":";;;;AAIsB,eAAA,MACrB,SACA,OACA,UAAgB;AAEV,QAAA,WAAWA,WAAO;AAExB,QAAM,UAAU;AAAA,IACf;AAAA,IACA;AAAA,EAAA;AAGK,QAAA,MAAM,aAAa,SAAS,eAAe;AAEjD,QAAM,WAAW,MAAM,MAAM,KAC5B,GAAG,GAAG,cACN,SACA;AAAA,IACC,SAAS;AAAA,MACR,cAAc;AAAA,MACd,eACC;AAAA,IACD;AAAA,EAAA,CACD;AAGE,MAAA,SAAS,WAAW,KAAK;AAC5BC,QAAA,gBAAgB,QAAQ;AAClB,UAAA,IAAI,MAAM,sDAAsD;AAAA,EACvE;AAEA,WAAS,KAAK,EAAE,SAAS,sBAAuB,CAAA;AAC1C,QAAA,QAAQ,SAAS,KAAK;AAE5B,SAAO,EAAE,OAAO,SAAS,SAAS,QAAQ,YAAY;AACvD;AAEA,SAAS,aAAa,SAAiB,iBAAuB;AACzD,MAAA;AACG,UAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,UAAM,cAAc,IAAI,SAAS,MAAM,GAAG;AAG1C,UAAM,aAAa,YAAY,MAAM,EAAE,EAAE,KAAK,GAAG;AAGjD,UAAM,sBAAsB,GAAG,eAAe,IAAI,UAAU;AAG5D,WAAO,GAAG,IAAI,QAAQ,KAAK,mBAAmB;AAAA,WACtC,OAAO;AACf,UAAM,IAAI,MAAM,gBAAgB,OAAO,EAAE;AAAA,EAC1C;AACD;;"}
@@ -0,0 +1,4 @@
1
+ export declare function login(baseUrl: string, email: string, password: string): Promise<{
2
+ token: string;
3
+ cookies: string[] | undefined;
4
+ }>;
@@ -0,0 +1,38 @@
1
+ import axios from "axios";
2
+ import { logger, logHttpResponse } from "./log.js";
3
+ async function login(baseUrl, email, password) {
4
+ const profiler = logger.startTimer();
5
+ const payload = {
6
+ email,
7
+ password
8
+ };
9
+ const url = transformUrl(baseUrl, "auth.internal");
10
+ const response = await axios.post(`${url}/login-e2e`, payload, {
11
+ headers: {
12
+ "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
13
+ Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c"
14
+ }
15
+ });
16
+ if (response.status !== 200) {
17
+ logHttpResponse(response);
18
+ throw new Error("Could not obtain OAuth token, check your credentials");
19
+ }
20
+ profiler.done({ message: "logged in via OAuth" });
21
+ const token = response.data.token;
22
+ return { token, cookies: response.headers["set-cookie"] };
23
+ }
24
+ function transformUrl(baseUrl, subdomainPrefix) {
25
+ try {
26
+ const url = new URL(baseUrl);
27
+ const domainParts = url.hostname.split(".");
28
+ const mainDomain = domainParts.slice(-2).join(".");
29
+ const transformedHostname = `${subdomainPrefix}.${mainDomain}`;
30
+ return `${url.protocol}//${transformedHostname}`;
31
+ } catch (error) {
32
+ throw new Error(`Invalid URL: ${baseUrl}`);
33
+ }
34
+ }
35
+ export {
36
+ login
37
+ };
38
+ //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sources":["../../../src/utils/authentication.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport { logHttpResponse, logger } from \"./log\";\n\nexport async function login(\n\tbaseUrl: string,\n\temail: string,\n\tpassword: string,\n): Promise<{ token: string; cookies: string[] | undefined }> {\n\tconst profiler = logger.startTimer();\n\n\tconst payload = {\n\t\temail,\n\t\tpassword,\n\t};\n\n\tconst url = transformUrl(baseUrl, \"auth.internal\");\n\n\tconst response = await axios.post<{ token: string }>(\n\t\t`${url}/login-e2e`,\n\t\tpayload,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization:\n\t\t\t\t\t\"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NDE3ODQ5NDEsImF1ZCI6ImF1dGgwLWFjdGlvbnMiLCJpc3MiOiJwcmlzbWljLmlvIn0.1UPoVMXJSTWtsyNzK5XYftK_mW0ScVuXwCK69nsyf5c\",\n\t\t\t},\n\t\t},\n\t);\n\n\tif (response.status !== 200) {\n\t\tlogHttpResponse(response);\n\t\tthrow new Error(\"Could not obtain OAuth token, check your credentials\");\n\t}\n\n\tprofiler.done({ message: \"logged in via OAuth\" });\n\tconst token = response.data.token;\n\n\treturn { token, cookies: response.headers[\"set-cookie\"] };\n}\n\nfunction transformUrl(baseUrl: string, subdomainPrefix: string): string {\n\ttry {\n\t\tconst url = new URL(baseUrl);\n\t\tconst domainParts = url.hostname.split(\".\");\n\n\t\t// Ensure we retain only the main domain (e.g., \"platform-wroom.com\")\n\t\tconst mainDomain = domainParts.slice(-2).join(\".\"); // Keeps last two parts of domain\n\n\t\t// Construct the new hostname with the custom prefix\n\t\tconst transformedHostname = `${subdomainPrefix}.${mainDomain}`;\n\n\t\t// Construct and return the full URL with the new hostname\n\t\treturn `${url.protocol}//${transformedHostname}`;\n\t} catch (error) {\n\t\tthrow new Error(`Invalid URL: ${baseUrl}`);\n\t}\n}\n"],"names":[],"mappings":";;AAIsB,eAAA,MACrB,SACA,OACA,UAAgB;AAEV,QAAA,WAAW,OAAO;AAExB,QAAM,UAAU;AAAA,IACf;AAAA,IACA;AAAA,EAAA;AAGK,QAAA,MAAM,aAAa,SAAS,eAAe;AAEjD,QAAM,WAAW,MAAM,MAAM,KAC5B,GAAG,GAAG,cACN,SACA;AAAA,IACC,SAAS;AAAA,MACR,cAAc;AAAA,MACd,eACC;AAAA,IACD;AAAA,EAAA,CACD;AAGE,MAAA,SAAS,WAAW,KAAK;AAC5B,oBAAgB,QAAQ;AAClB,UAAA,IAAI,MAAM,sDAAsD;AAAA,EACvE;AAEA,WAAS,KAAK,EAAE,SAAS,sBAAuB,CAAA;AAC1C,QAAA,QAAQ,SAAS,KAAK;AAE5B,SAAO,EAAE,OAAO,SAAS,SAAS,QAAQ,YAAY;AACvD;AAEA,SAAS,aAAa,SAAiB,iBAAuB;AACzD,MAAA;AACG,UAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,UAAM,cAAc,IAAI,SAAS,MAAM,GAAG;AAG1C,UAAM,aAAa,YAAY,MAAM,EAAE,EAAE,KAAK,GAAG;AAGjD,UAAM,sBAAsB,GAAG,eAAe,IAAI,UAAU;AAG5D,WAAO,GAAG,IAAI,QAAQ,KAAK,mBAAmB;AAAA,WACtC,OAAO;AACf,UAAM,IAAI,MAAM,gBAAgB,OAAO,EAAE;AAAA,EAC1C;AACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.10",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -96,5 +96,6 @@
96
96
  },
97
97
  "publishConfig": {
98
98
  "access": "restricted"
99
- }
99
+ },
100
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
100
101
  }
@@ -0,0 +1,76 @@
1
+ import { logPlaywrightApiResponse } from "../utils/log";
2
+
3
+ import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
4
+
5
+ export interface AssetApiCreatePayload {
6
+ name: string;
7
+ mimeType: string;
8
+ buffer: Buffer;
9
+ }
10
+
11
+ export interface AssetApiCreateResponse {
12
+ id: string;
13
+ url: string;
14
+ filename: string;
15
+ size: number;
16
+ width: number;
17
+ height: number;
18
+ last_modified: number;
19
+ kind: string;
20
+ extension: string;
21
+ created_at: number;
22
+ uploader_id: string;
23
+ tags: string[];
24
+ }
25
+
26
+ export class AssetApiClient extends AuthenticatedApiClient {
27
+ /**
28
+ * @example To instantiate the class:
29
+ *
30
+ * ```js
31
+ * new AssetApiClient("https://asset-api.prismic.io", {
32
+ * authToken: "my-secret-token",
33
+ * repository: "my-repo-name",
34
+ * });
35
+ * ```
36
+ *
37
+ * @param baseURL - The API base URL, such as https://asset-api.prismic.io
38
+ * @param config - Optional configuration
39
+ *
40
+ * - {@link config.authToken}: API token generated from the auth service or a
41
+ * function to fetch it when it's needed.
42
+ * - {@link config.repository}: Repository name.
43
+ */
44
+ constructor(
45
+ baseURL: string,
46
+ config: { authToken: AuthServerToken; repository: string },
47
+ ) {
48
+ super(baseURL, config.authToken, { repository: config.repository });
49
+ }
50
+
51
+ /**
52
+ * Uploads an asset file to the server.
53
+ *
54
+ * @param data - The payload containing the file and filename.
55
+ *
56
+ * @returns The API response containing asset information.
57
+ *
58
+ * @throws An error if the upload fails.
59
+ */
60
+ async createAsset(
61
+ data: AssetApiCreatePayload,
62
+ ): Promise<AssetApiCreateResponse> {
63
+ const context = await this.getContext();
64
+
65
+ const result = await context.post("assets", {
66
+ multipart: { file: data },
67
+ });
68
+
69
+ if (200 !== result.status()) {
70
+ await logPlaywrightApiResponse(result);
71
+ throw new Error("Could not upload the asset with the asset API.");
72
+ }
73
+
74
+ return result.json();
75
+ }
76
+ }
@@ -2,6 +2,7 @@ import { APIRequestContext, request } from "@playwright/test";
2
2
 
3
3
  import { AuthConfig } from "../types";
4
4
 
5
+ import { login as authenticateWithLambda } from "../utils/authentication";
5
6
  import { logPlaywrightApiResponse, logger } from "../utils/log";
6
7
 
7
8
  /** Client for interacting with the authentication service to manage tokens */
@@ -27,17 +28,13 @@ export class AuthenticationApiClient {
27
28
  private async login(): Promise<string> {
28
29
  const profiler = logger.startTimer();
29
30
 
30
- const context = await this.getContext();
31
- const result = await context.post("login", {
32
- data: {
33
- email: this.auth.email,
34
- password: this.auth.password,
35
- },
36
- });
31
+ const { token } = await authenticateWithLambda(
32
+ this.baseURL,
33
+ this.auth.email,
34
+ this.auth.password,
35
+ );
37
36
 
38
- const token = await result.text();
39
- if (!result.ok() || !token) {
40
- logPlaywrightApiResponse(result);
37
+ if (!token) {
41
38
  throw new Error("Authentication failed, no token received.");
42
39
  }
43
40