@prismicio/e2e-tests-utils 1.4.2-alpha.0 → 1.5.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  };
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  const test = require("@playwright/test");
10
+ const urls = require("../utils/urls.cjs");
10
11
  class AuthenticatedApiClient {
11
12
  constructor(baseURL, token, headers) {
12
13
  __publicField(this, "baseURL");
@@ -25,7 +26,7 @@ class AuthenticatedApiClient {
25
26
  if (!this._context) {
26
27
  const token = typeof this.token === "string" ? this.token : await this.token();
27
28
  this._context = await test.request.newContext({
28
- baseURL: this.baseURL,
29
+ baseURL: urls.appendTrailingSlash(this.baseURL),
29
30
  extraHTTPHeaders: {
30
31
  Authorization: `Bearer ${token}`,
31
32
  ...this.headers
@@ -1 +1 @@
1
- {"version":3,"file":"apiClient.cjs","sources":["../../../src/clients/apiClient.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\n/**\n * The authentication token. Can be a string or a function that returns a\n * promise resolving to the token.\n */\nexport type AuthServerToken = string | (() => Promise<string>);\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication\n * server. This class takes care or creating the Playwright context with the\n * necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios\n * which has the advantage of tracing all the network details in the Playwright\n * reports making test failures investigation easier for projects that use\n * Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/**\n\t * Returns a Playwright ApiRequestContext instance with the necessary\n\t * authorization headers.\n\t */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token =\n\t\t\t\ttypeof this.token === \"string\" ? this.token : await this.token();\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n}\n"],"names":["request"],"mappings":";;;;;;;;;MAkBsB,uBAAsB;AAAA,EAG3C,YACkB,SACA,OACA,SAA+C;AAF/C;AACA;AACA;AALV;AAGU,SAAO,UAAP;AACA,SAAK,QAAL;AACA,SAAO,UAAP;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,aAAU;AACrB,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,QACL,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK;AAErD,WAAA,WAAW,MAAMA,KAAA,QAAQ,WAAW;AAAA,QACxC,SAAS,KAAK;AAAA,QACd,kBAAkB;AAAA,UACjB,eAAe,UAAU,KAAK;AAAA,UAC9B,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AACA;;"}
1
+ {"version":3,"file":"apiClient.cjs","sources":["../../../src/clients/apiClient.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { appendTrailingSlash } from \"../utils/urls\";\n\n/**\n * The authentication token. Can be a string or a function that returns a\n * promise resolving to the token.\n */\nexport type AuthServerToken = string | (() => Promise<string>);\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication\n * server. This class takes care or creating the Playwright context with the\n * necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios\n * which has the advantage of tracing all the network details in the Playwright\n * reports making test failures investigation easier for projects that use\n * Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/**\n\t * Returns a Playwright ApiRequestContext instance with the necessary\n\t * authorization headers.\n\t */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token =\n\t\t\t\ttypeof this.token === \"string\" ? this.token : await this.token();\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n}\n"],"names":["request","appendTrailingSlash"],"mappings":";;;;;;;;;;MAoBsB,uBAAsB;AAAA,EAG3C,YACkB,SACA,OACA,SAA+C;AAF/C;AACA;AACA;AALV;AAGU,SAAO,UAAP;AACA,SAAK,QAAL;AACA,SAAO,UAAP;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,aAAU;AACrB,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,QACL,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK;AAErD,WAAA,WAAW,MAAMA,KAAA,QAAQ,WAAW;AAAA,QACxC,SAASC,KAAAA,oBAAoB,KAAK,OAAO;AAAA,QACzC,kBAAkB;AAAA,UACjB,eAAe,UAAU,KAAK;AAAA,UAC9B,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AACA;;"}
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { request } from "@playwright/test";
8
+ import { appendTrailingSlash } from "../utils/urls.js";
8
9
  class AuthenticatedApiClient {
9
10
  constructor(baseURL, token, headers) {
10
11
  __publicField(this, "baseURL");
@@ -23,7 +24,7 @@ class AuthenticatedApiClient {
23
24
  if (!this._context) {
24
25
  const token = typeof this.token === "string" ? this.token : await this.token();
25
26
  this._context = await request.newContext({
26
- baseURL: this.baseURL,
27
+ baseURL: appendTrailingSlash(this.baseURL),
27
28
  extraHTTPHeaders: {
28
29
  Authorization: `Bearer ${token}`,
29
30
  ...this.headers
@@ -1 +1 @@
1
- {"version":3,"file":"apiClient.js","sources":["../../../src/clients/apiClient.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\n/**\n * The authentication token. Can be a string or a function that returns a\n * promise resolving to the token.\n */\nexport type AuthServerToken = string | (() => Promise<string>);\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication\n * server. This class takes care or creating the Playwright context with the\n * necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios\n * which has the advantage of tracing all the network details in the Playwright\n * reports making test failures investigation easier for projects that use\n * Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/**\n\t * Returns a Playwright ApiRequestContext instance with the necessary\n\t * authorization headers.\n\t */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token =\n\t\t\t\ttypeof this.token === \"string\" ? this.token : await this.token();\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;MAkBsB,uBAAsB;AAAA,EAG3C,YACkB,SACA,OACA,SAA+C;AAF/C;AACA;AACA;AALV;AAGU,SAAO,UAAP;AACA,SAAK,QAAL;AACA,SAAO,UAAP;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,aAAU;AACrB,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,QACL,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK;AAErD,WAAA,WAAW,MAAM,QAAQ,WAAW;AAAA,QACxC,SAAS,KAAK;AAAA,QACd,kBAAkB;AAAA,UACjB,eAAe,UAAU,KAAK;AAAA,UAC9B,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AACA;"}
1
+ {"version":3,"file":"apiClient.js","sources":["../../../src/clients/apiClient.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { appendTrailingSlash } from \"../utils/urls\";\n\n/**\n * The authentication token. Can be a string or a function that returns a\n * promise resolving to the token.\n */\nexport type AuthServerToken = string | (() => Promise<string>);\n\n/**\n * Abstract class for Prismic api clients that use the Prismic authentication\n * server. This class takes care or creating the Playwright context with the\n * necessary authorization headers.\n *\n * This class performs requests with Playwright instead of a library like Axios\n * which has the advantage of tracing all the network details in the Playwright\n * reports making test failures investigation easier for projects that use\n * Playwright.\n */\nexport abstract class AuthenticatedApiClient {\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly token: AuthServerToken,\n\t\tprivate readonly headers?: { [key: string]: string } | undefined,\n\t) {}\n\n\t/**\n\t * Returns a Playwright ApiRequestContext instance with the necessary\n\t * authorization headers.\n\t */\n\tprotected async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tconst token =\n\t\t\t\ttypeof this.token === \"string\" ? this.token : await this.token();\n\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t\textraHTTPHeaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t...this.headers,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;MAoBsB,uBAAsB;AAAA,EAG3C,YACkB,SACA,OACA,SAA+C;AAF/C;AACA;AACA;AALV;AAGU,SAAO,UAAP;AACA,SAAK,QAAL;AACA,SAAO,UAAP;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM,aAAU;AACrB,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,QACL,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,MAAM,KAAK;AAErD,WAAA,WAAW,MAAM,QAAQ,WAAW;AAAA,QACxC,SAAS,oBAAoB,KAAK,OAAO;AAAA,QACzC,kBAAkB;AAAA,UACjB,eAAe,UAAU,KAAK;AAAA,UAC9B,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACb;AACA;"}
@@ -386,10 +386,9 @@ class RepositoryManager {
386
386
  });
387
387
  }
388
388
  /**
389
- * Creates a document using the migration api, see
390
- * https://prismic.io/docs/migration-api-technical-reference
389
+ * Creates a document using the core api
391
390
  *
392
- * @param document - in the migration api format
391
+ * @param document - in the core api format
393
392
  * @param status - status of the document, if published, the function will
394
393
  * wait for a new content api master ref to be created
395
394
  *
@@ -1 +1 @@
1
- {"version":3,"file":"repository.cjs","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\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\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 * 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 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 migration api, see\n\t * https://prismic.io/docs/migration-api-technical-reference\n\t *\n\t * @param document - in the migration api format\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\t * @returns\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":["logger","getRepositoryUrl","ContentApiClient","logHttpResponse","contentApi","expect"],"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,O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{"version":3,"file":"repository.cjs","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\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\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 * 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 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\n\t *\n\t * @param document - in the core api format\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\t * @returns\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":["logger","getRepositoryUrl","ContentApiClient","logHttpResponse","contentApi","expect"],"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;AAEvD,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;AAC9CA,cAAAA,OAAO,KACN,oCAAoC,OAAO,EAAE,2BAA2B,OAAO,aAAa,GAAG;AAAA,QAEjG;AAAA,MACD;AAEA,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,QACtC;AAAA,MACD;AAEA,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,QAClD;AAAA,MACD;AAAA,IACD;AAEA,QAAI,OAAO,QAAQ;AACZ,YAAA,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c,YAAY,QAAQ;AAExD,QAAA,UAAU,6BAA6B,OAAO,EAAE;AACpD,QAAI,WAAW,aAAa;AACrB,YAAAI,cAAa,KAAK;AAClB,YAAA,YAAY,MAAMA,YAAW;AACnC,YAAM,KAAK,cAAc,aAAa,OAAO,EAAE;AAC/C,YAAMC,KACJ,OAAA,KAAK,YAAYD,YAAW,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;;"}
@@ -165,10 +165,9 @@ export declare class RepositoryManager {
165
165
  */
166
166
  updateUserRole(email: string, role: string | Record<string, string>): Promise<void>;
167
167
  /**
168
- * Creates a document using the migration api, see
169
- * https://prismic.io/docs/migration-api-technical-reference
168
+ * Creates a document using the core api
170
169
  *
171
- * @param document - in the migration api format
170
+ * @param document - in the core api format
172
171
  * @param status - status of the document, if published, the function will
173
172
  * wait for a new content api master ref to be created
174
173
  *
@@ -384,10 +384,9 @@ class RepositoryManager {
384
384
  });
385
385
  }
386
386
  /**
387
- * Creates a document using the migration api, see
388
- * https://prismic.io/docs/migration-api-technical-reference
387
+ * Creates a document using the core api
389
388
  *
390
- * @param document - in the migration api format
389
+ * @param document - in the core api format
391
390
  * @param status - status of the document, if published, the function will
392
391
  * wait for a new content api master ref to be created
393
392
  *
@@ -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\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\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 * 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 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 migration api, see\n\t * https://prismic.io/docs/migration-api-technical-reference\n\t *\n\t * @param document - in the migration api format\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\t * @returns\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,S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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 { 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\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\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 * 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 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\n\t *\n\t * @param document - in the core api format\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\t * @returns\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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nC,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;"}
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const getRepositoryUrl = (baseUrl, repository) => {
3
+ function getRepositoryUrl(baseUrl, repository) {
4
4
  const url = new URL(baseUrl);
5
5
  url.hostname = `${repository}.${url.hostname}`;
6
6
  return url.toString();
7
- };
7
+ }
8
+ function appendTrailingSlash(url) {
9
+ if (!url.endsWith("/")) {
10
+ return url + "/";
11
+ }
12
+ return url;
13
+ }
14
+ exports.appendTrailingSlash = appendTrailingSlash;
8
15
  exports.getRepositoryUrl = getRepositoryUrl;
9
16
  //# sourceMappingURL=urls.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"urls.cjs","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport const getRepositoryUrl = (\n\tbaseUrl: string,\n\trepository: string,\n): string => {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n};\n"],"names":[],"mappings":";;AAQa,MAAA,mBAAmB,CAC/B,SACA,eACW;AACL,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI;AACZ;;"}
1
+ {"version":3,"file":"urls.cjs","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport function getRepositoryUrl(baseUrl: string, repository: string): string {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n}\n\n/**\n * Prevent issues when building urls using `URL` that contain sub path without\n * trailing slashes.\n *\n * @returns the original url with a trailing slash, if needed.\n */\nexport function appendTrailingSlash(url: string): string {\n\tif (!url.endsWith(\"/\")) {\n\t\treturn url + \"/\";\n\t}\n\n\treturn url;\n}\n"],"names":[],"mappings":";;AAQgB,SAAA,iBAAiB,SAAiB,YAAkB;AAC7D,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI;AACZ;AAQM,SAAU,oBAAoB,KAAW;AAC9C,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACvB,WAAO,MAAM;AAAA,EACd;AAEO,SAAA;AACR;;;"}
@@ -6,4 +6,11 @@
6
6
  *
7
7
  * @returns the repository url like https://my-repo.prismic.io
8
8
  */
9
- export declare const getRepositoryUrl: (baseUrl: string, repository: string) => string;
9
+ export declare function getRepositoryUrl(baseUrl: string, repository: string): string;
10
+ /**
11
+ * Prevent issues when building urls using `URL` that contain sub path without
12
+ * trailing slashes.
13
+ *
14
+ * @returns the original url with a trailing slash, if needed.
15
+ */
16
+ export declare function appendTrailingSlash(url: string): string;
@@ -1,9 +1,16 @@
1
- const getRepositoryUrl = (baseUrl, repository) => {
1
+ function getRepositoryUrl(baseUrl, repository) {
2
2
  const url = new URL(baseUrl);
3
3
  url.hostname = `${repository}.${url.hostname}`;
4
4
  return url.toString();
5
- };
5
+ }
6
+ function appendTrailingSlash(url) {
7
+ if (!url.endsWith("/")) {
8
+ return url + "/";
9
+ }
10
+ return url;
11
+ }
6
12
  export {
13
+ appendTrailingSlash,
7
14
  getRepositoryUrl
8
15
  };
9
16
  //# sourceMappingURL=urls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"urls.js","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport const getRepositoryUrl = (\n\tbaseUrl: string,\n\trepository: string,\n): string => {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n};\n"],"names":[],"mappings":"AAQa,MAAA,mBAAmB,CAC/B,SACA,eACW;AACL,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI;AACZ;"}
1
+ {"version":3,"file":"urls.js","sources":["../../../src/utils/urls.ts"],"sourcesContent":["/**\n * Build a repository base url from the prismic base url\n *\n * @param baseUrl - prismic base url like prismic.io\n * @param repository - the repository name\n *\n * @returns the repository url like https://my-repo.prismic.io\n */\nexport function getRepositoryUrl(baseUrl: string, repository: string): string {\n\tconst url = new URL(baseUrl);\n\turl.hostname = `${repository}.${url.hostname}`;\n\n\treturn url.toString();\n}\n\n/**\n * Prevent issues when building urls using `URL` that contain sub path without\n * trailing slashes.\n *\n * @returns the original url with a trailing slash, if needed.\n */\nexport function appendTrailingSlash(url: string): string {\n\tif (!url.endsWith(\"/\")) {\n\t\treturn url + \"/\";\n\t}\n\n\treturn url;\n}\n"],"names":[],"mappings":"AAQgB,SAAA,iBAAiB,SAAiB,YAAkB;AAC7D,QAAA,MAAM,IAAI,IAAI,OAAO;AAC3B,MAAI,WAAW,GAAG,UAAU,IAAI,IAAI,QAAQ;AAE5C,SAAO,IAAI;AACZ;AAQM,SAAU,oBAAoB,KAAW;AAC9C,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACvB,WAAO,MAAM;AAAA,EACd;AAEO,SAAA;AACR;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "1.4.2-alpha.0",
3
+ "version": "1.5.1-alpha.0",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -54,14 +54,19 @@
54
54
  "test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
55
55
  },
56
56
  "dependencies": {
57
- "@prismicio/types-internal": "^2.3.1",
58
57
  "axios": "^1.6.2",
59
58
  "jsonwebtoken": "^9.0.2",
60
59
  "lodash.isequal": "^4.5.0",
61
60
  "winston": "^3.11.0"
62
61
  },
63
62
  "peerDependencies": {
64
- "@playwright/test": ">= 1.16"
63
+ "@playwright/test": ">= 1.16",
64
+ "@prismicio/types-internal": "^2.3.1"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "@prismicio/types-internal": {
68
+ "optional": true
69
+ }
65
70
  },
66
71
  "devDependencies": {
67
72
  "@size-limit/preset-small-lib": "^11.0.1",
@@ -1,5 +1,7 @@
1
1
  import { APIRequestContext, request } from "@playwright/test";
2
2
 
3
+ import { appendTrailingSlash } from "../utils/urls";
4
+
3
5
  /**
4
6
  * The authentication token. Can be a string or a function that returns a
5
7
  * promise resolving to the token.
@@ -35,7 +37,7 @@ export abstract class AuthenticatedApiClient {
35
37
  typeof this.token === "string" ? this.token : await this.token();
36
38
 
37
39
  this._context = await request.newContext({
38
- baseURL: this.baseURL,
40
+ baseURL: appendTrailingSlash(this.baseURL),
39
41
  extraHTTPHeaders: {
40
42
  Authorization: `Bearer ${token}`,
41
43
  ...this.headers,
@@ -549,10 +549,9 @@ export class RepositoryManager {
549
549
  }
550
550
 
551
551
  /**
552
- * Creates a document using the migration api, see
553
- * https://prismic.io/docs/migration-api-technical-reference
552
+ * Creates a document using the core api
554
553
  *
555
- * @param document - in the migration api format
554
+ * @param document - in the core api format
556
555
  * @param status - status of the document, if published, the function will
557
556
  * wait for a new content api master ref to be created
558
557
  *
package/src/utils/urls.ts CHANGED
@@ -6,12 +6,23 @@
6
6
  *
7
7
  * @returns the repository url like https://my-repo.prismic.io
8
8
  */
9
- export const getRepositoryUrl = (
10
- baseUrl: string,
11
- repository: string,
12
- ): string => {
9
+ export function getRepositoryUrl(baseUrl: string, repository: string): string {
13
10
  const url = new URL(baseUrl);
14
11
  url.hostname = `${repository}.${url.hostname}`;
15
12
 
16
13
  return url.toString();
17
- };
14
+ }
15
+
16
+ /**
17
+ * Prevent issues when building urls using `URL` that contain sub path without
18
+ * trailing slashes.
19
+ *
20
+ * @returns the original url with a trailing slash, if needed.
21
+ */
22
+ export function appendTrailingSlash(url: string): string {
23
+ if (!url.endsWith("/")) {
24
+ return url + "/";
25
+ }
26
+
27
+ return url;
28
+ }