@prismicio/e2e-tests-utils 1.19.0 → 1.20.0-pr.40.f652adb

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.
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","names":[],"sources":["../../src/managers/repository.ts"],"sourcesContent":["import { expect } from \"@playwright/test\"\nimport type { DynamicCustomTypeModel, SharedSliceModel } from \"@prismicio/types-internal\"\nimport type { AxiosResponse } from \"axios\"\n\nimport type { AssetApiClient } from \"../clients/assetApi\"\nimport type { AuthenticationApiClient } from \"../clients/authenticationApi\"\nimport { ContentApiClient } from \"../clients/contentApi\"\nimport type {\n\tCoreApiClient,\n\tCoreApiDocumentCreationPayload,\n\tCoreApiDocumentCreationResponse,\n\tCoreApiDocumentData,\n\tCoreApiDocumentsPayload,\n\tCoreApiDocumentsResponse,\n\tRelease,\n} from \"../clients/coreApi\"\nimport type { CustomTypesApiClient } from \"../clients/customTypesApi\"\nimport type { IntegrationFieldsClient } from \"../clients/integrationFields\"\nimport type { ManageV2Client } from \"../clients/manageV2\"\nimport type { MigrationApiClient } from \"../clients/migrationApi\"\nimport type { WroomClient } from \"../clients/wroom\"\nimport type { IntegrationFieldConfig } from \"../types\"\nimport { logHttpResponse, logger } from \"../utils/log\"\nimport { getRepositoryUrl } from \"../utils/urls\"\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly coreApiClient: CoreApiClient,\n\t\tprivate readonly authApiClient: AuthenticationApiClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesApiClient,\n\t\tprivate readonly migrationApiClient: MigrationApiClient | undefined,\n\t\tprivate readonly assetApiClient: AssetApiClient,\n\t\tprivate readonly manageV2Client: ManageV2Client,\n\t\tprivate readonly integrationFieldsClient: IntegrationFieldsClient | undefined,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tconst hasLangConfig = config.defaultLocale || config.locales || config.customLocale\n\t\tif (hasLangConfig) {\n\t\t\tconst languages = await this.coreApiClient.getLanguages()\n\t\t\tlet updateDefaultLocaleAtTheEnd = false\n\t\t\t// if no locale exists on repo, the master locale needs to be set first\n\t\t\tif (config.defaultLocale) {\n\t\t\t\tconst master = languages.find(({ is_master }) => is_master === true)\n\t\t\t\tif (!master) {\n\t\t\t\t\tawait this.setDefaultLocale(config.defaultLocale, \"create\")\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\t// update the master lang at the end, after it is created.\n\t\t\t\t\tupdateDefaultLocaleAtTheEnd = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\t// No need to add default locale and already existing languages\n\t\t\t\tconst localesToAdd = config.locales.filter(\n\t\t\t\t\t(id) => !languages.some((language) => language.id === id),\n\t\t\t\t)\n\t\t\t\tif (localesToAdd.length > 0) {\n\t\t\t\t\tawait this.createLocales(localesToAdd)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.customLocale) {\n\t\t\t\tif (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {\n\t\t\t\t\tawait this.createCustomLocale(config.customLocale)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.defaultLocale && updateDefaultLocaleAtTheEnd) {\n\t\t\t\tawait this.setDefaultLocale(config.defaultLocale, \"update\")\n\t\t\t}\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices)\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes)\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview)\n\t\t}\n\n\t\tif (config.simulatorURL) {\n\t\t\tawait this.setSimulatorURL(config.simulatorURL)\n\t\t}\n\n\t\tif (config.rolePerLocal) {\n\t\t\tawait this.toggleRolePerLocal(true)\n\t\t}\n\n\t\tif (config.customRoles) {\n\t\t\tawait this.toggleCustomRoles(true)\n\t\t}\n\n\t\tif (config.integrationFields) {\n\t\t\tawait this.toggleIntegrationFields(true)\n\t\t\tawait this.setupIntegrationFields(config.integrationFields)\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 url. Uses Playwright\n\t * for requests so if your project uses Playwright too, any network request will be present in\n\t * Playwright test reports.\n\t */\n\tgetContentApiClient(config?: { version?: \"v1\" | \"v2\"; accessToken?: string }): ContentApiClient {\n\t\treturn new ContentApiClient(this.getBaseCdnURL(), config)\n\t}\n\n\t/**\n\t * @returns An instance of the Migration api client, see\n\t * https://prismic.io/docs/migration-api-technical-reference\n\t */\n\tgetMigrationApiClient(): MigrationApiClient {\n\t\tif (!this.migrationApiClient) {\n\t\t\tthrow \"No client found for the migration api. Did you provide a migration api url in the configuration?\"\n\t\t}\n\n\t\treturn this.migrationApiClient\n\t}\n\n\t/**\n\t * @returns An instance of the Asset api client, see\n\t * https://prismic.io/docs/asset-api-technical-reference\n\t */\n\tgetAssetApiClient(): AssetApiClient {\n\t\treturn this.assetApiClient\n\t}\n\n\t/** @returns The Wroom commit hash deployed on the current repository */\n\tasync getDeployedVersion(): Promise<string | undefined> {\n\t\tconst response = await this.wroomClient.get(\n\t\t\tthis.name,\n\t\t\t\"underground/834b34f16f451e00f268dd5c8c81d16e3c020275\",\n\t\t)\n\n\t\t// Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute\n\t\treturn response.data.version\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if the locales already\n\t * exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\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(this.name, \"app/settings/multilanguages\", {\n\t\t\tlanguages: locales,\n\t\t})\n\n\t\tconst { data, status } = response\n\t\tconst success =\n\t\t\tstatus === 200 || (status === 400 && (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 the locales already\n\t * exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\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 || (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 * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t)\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`)\n\t\tprofiler.done({ message: `locale '${locale}' deleted` })\n\t}\n\n\t/**\n\t * Create or update the default (master) locale for a repository in Wroom, the locale needs to\n\t * exist in the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t * @param endpoint - \"createMasterLang\" to create it, \"defineAsMaster\" to update it.\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string, action: \"create\" | \"update\"): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst endpoint = {\n\t\t\tcreate: \"createMasterLang\",\n\t\t\tupdate: \"defineAsMaster\",\n\t\t}\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/${endpoint[action]}`,\n\t\t)\n\n\t\tconst { data, status } = response\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"))\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`)\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` })\n\t}\n\n\t/**\n\t * Retrieves documents.\n\t *\n\t * @param args - Configure which documents are retrieved.\n\t * @returns A paginated set of documents.\n\t */\n\tasync getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse> {\n\t\treturn this.coreApiClient.getDocuments(args)\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\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 * Retrieves the migration release.\n\t *\n\t * @returns The migration relese metadata.\n\t */\n\tasync getMigrationRelease(): Promise<Release> {\n\t\tconst releases = await this.coreApiClient.getReleases()\n\t\tconst migrationRelease = releases.find((release) => release.migration)\n\t\tif (!migrationRelease) {\n\t\t\tthrow new Error(`The repository does not have a migration release`)\n\t\t}\n\n\t\treturn migrationRelease\n\t}\n\n\t/**\n\t * Publishes a release.\n\t *\n\t * @param id - The ID of the release.\n\t * @returns A Promise that resolves when the release is published and a new master ref is\n\t * available.\n\t */\n\tasync publishRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst contentApi = this.getContentApiClient()\n\t\tconst masterRef = await contentApi.getMasterRef()\n\t\tawait this.coreApiClient.publishRelease(id)\n\t\tawait expect\n\t\t\t.poll(async () => contentApi.getMasterRef(), {\n\t\t\t\ttimeout: 10_000,\n\t\t\t\tmessage: \"Waiting for new master ref to be available\",\n\t\t\t})\n\t\t\t.not.toBe(masterRef)\n\n\t\tprofiler.done({\n\t\t\tmessage: `release '${id}' published and new master ref available`,\n\t\t})\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\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(this.name, `app/releases/${id}/delete`, {})\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(this.name, `previews/new`, data)\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 * Set the simulator URL (table of slices) for a repository.\n\t *\n\t * @param data - The simulator URL to set.\n\t */\n\tasync setSimulatorURL(simulatorURL: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst repository = await this.coreApiClient.getRepository()\n\t\tawait this.coreApiClient.updateRepository({\n\t\t\t...repository,\n\t\t\tsimulator_url: simulatorURL,\n\t\t})\n\n\t\tprofiler.done({\n\t\t\tmessage: `simulator preview '${simulatorURL}' created`,\n\t\t})\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(this.name, `previews/delete/${id}`, {})\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id ${id}`)\n\t\tprofiler.done({ message: `preview '${id}' deleted` })\n\t}\n\n\t/**\n\t * Create a webhook.\n\t *\n\t * @returns A Promise that resolves with the webhook id.\n\t */\n\tasync createWebhook(\n\t\tname: string,\n\t\turl: string,\n\t\tsecret: string,\n\t\ttriggers: {\n\t\t\tdocumentsPublished?: boolean\n\t\t\tdocumentsUnpublished?: boolean\n\t\t\treleasesCreated?: boolean\n\t\t\treleasesUpdated?: boolean\n\t\t\ttagsCreated?: boolean\n\t\t\ttagsDeleted?: boolean\n\t\t},\n\t\tactive: boolean,\n\t): Promise<string> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/settings/webhooks/create\", {\n\t\t\tname,\n\t\t\turl,\n\t\t\tsecret,\n\t\t\tactive: active ? \"on\" : \"off\",\n\t\t\t...triggers,\n\t\t})\n\t\tthis.failIfNot200(response, `Could not create webhook ${name}`)\n\t\tprofiler.done({ message: `webhook '${name}' created` })\n\n\t\treturn response.data.created\n\t}\n\n\t/**\n\t * Deletes a webhook.\n\t *\n\t * @param id - The webhook ID.\n\t */\n\tasync deleteWebhook(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/webhooks/${id}/delete`,\n\t\t\t{},\n\t\t)\n\n\t\tthis.failIfNot200(response, `Could not delete webhook with id ${id}`)\n\t\tprofiler.done({ message: `webhook '${id}' deleted` })\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes\n\t */\n\tasync createCustomTypes(customTypes: DynamicCustomTypeModel[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes)\n\t}\n\n\tasync deleteCustomType(customTypeId: string): Promise<void> {\n\t\tawait this.customTypesApiClient.deleteCustomType(customTypeId)\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: SharedSliceModel[]): 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 api is fully private\n\t * 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[]> = await this.wroomClient.get(\n\t\t\tthis.name,\n\t\t\t\"settings/security/contentapi\",\n\t\t)\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> = await this.wroomClient.post(\n\t\t\t\tthis.name,\n\t\t\t\t\"settings/security/oauthapp\",\n\t\t\t\t{\n\t\t\t\t\tapp_name: appName,\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tthis.failIfNot200(response, `Could not create content api app ${appName}`)\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(this.name, \"settings/security/authorizations\", {\n\t\t\t\tapp: app.id,\n\t\t\t\tscope: tokenScope,\n\t\t\t})\n\t\t\tthis.failIfNot200(\n\t\t\t\tresponse,\n\t\t\t\t`Could not create content api access token for app ${appName} with scope ${tokenScope}`,\n\t\t\t)\n\t\t\ttokenInfo = response.data\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `content api access token for app '${appName}' created`,\n\t\t})\n\n\t\tif (!tokenInfo?.token) {\n\t\t\tthrow `Could not create content api access token for app ${appName} with scope ${tokenScope}`\n\t\t}\n\n\t\treturn tokenInfo.token\n\t}\n\n\t/** Create a permanent access token to authenticate to Prismic public apis. */\n\tasync createPermanentAccessToken(): Promise<string> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst token = await this.authApiClient.getMachine2MachineToken(this.name)\n\n\t\tprofiler.done({\n\t\t\tmessage: `machine2machine token created`,\n\t\t})\n\n\t\treturn token\n\t}\n\n\t/**\n\t * Toggle the Role per Locale workflow\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleRolePerLocal(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.manageV2Client.toggleRolePerLocal({\n\t\t\trepository: this.name,\n\t\t\tenabled: enabled,\n\t\t})\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not ${enabled ? \"enable\" : \"disable\"} Role per local for ${this.name}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Role per local ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t})\n\t}\n\n\t/**\n\t * Toggle the Custom Roles workflow\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleCustomRoles(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.manageV2Client.toggleCustomRoles({\n\t\t\trepository: this.name,\n\t\t\tenabled: enabled,\n\t\t})\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not ${enabled ? \"enable\" : \"disable\"} Custom Roles for ${this.name}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Custom Roles ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t})\n\t}\n\n\t/**\n\t * Toggle the Integration Fields feature\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleIntegrationFields(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.manageV2Client.toggleIntegrationFields({\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\"} Integration Fields for ${this.name}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Integration Fields ${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 && JSON.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(response, `Could not remove the user ${email} from the repository`)\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, either a string for\n\t * basic workflow or an object such as `{ \"lang_id\": \"Writer\" }`\n\t *\n\t * Example of roles are\n\t *\n\t * - Administrator\n\t * - Writer\n\t * - Contributor\n\t * - Manager (publisher)\n\t */\n\tasync updateUserRole(email: string, role: string | Record<string, string>): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response =\n\t\t\ttypeof role === \"string\"\n\t\t\t\t? await this.wroomClient.updateRole(this.name, email, role)\n\t\t\t\t: await this.wroomClient.updateRolePerLocal(this.name, email, role)\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not update the ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} of the user ${email}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Updated User's ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} for user ${email}`,\n\t\t})\n\t}\n\n\t/**\n\t * Creates a document using the core api. If the Core api format is too specific, use the\n\t * migration api client to create a document with the MigrationApiClient. See the\n\t * `getMigrationApiClient()` method.\n\t *\n\t * @example\n\t * \tTo create a document by converting it from the Page Builder to\n\t * \tCore api format\n\t *\n\t * \t```js\n\t * \timport { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';\n\t *\n\t * \tconst document = {\n\t * \ttitle: 'A new document',\n\t * \tcustom_type_id: 'home-page',\n\t * \tlocale: 'en-gb',\n\t * \tintegration_field_ids: [],\n\t * \ttags: [],\n\t * \tdata: DocumentLegacy.encode({\n\t * \tuid: {\n\t * \t__TYPE__: UIDContentType,\n\t * \tvalue: 'home-page',\n\t * \t},\n\t * \t})\n\t * \t}\n\t * \tawait repository.createDocument(document, 'published');\n\t * \t* ```\n\t * \t```\n\t *\n\t * \t@returns\n\t *\n\t * \t@param document - in the core api format.\n\t *\n\t * \t@param status - status of the document, if published, the function will\n\t * \twait for a new content api master ref to be created\n\t */\n\tasync createDocument(\n\t\tdocument: CoreApiDocumentCreationPayload,\n\t\tstatus: \"draft\" | \"published\",\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst profiler = logger.startTimer()\n\t\tconst result = await this.coreApiClient.createDraft(document)\n\n\t\tlet message = `Document created with id '${result.id}'`\n\t\tif (status === \"published\") {\n\t\t\tconst contentApi = this.getContentApiClient()\n\t\t\tconst masterRef = await contentApi.getMasterRef()\n\t\t\tawait this.coreApiClient.publishDraft(result.id)\n\t\t\tawait expect\n\t\t\t\t.poll(async () => contentApi.getMasterRef(), {\n\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t\tmessage: \"Waiting for new master ref to be available\",\n\t\t\t\t})\n\t\t\t\t.not.toBe(masterRef)\n\t\t\tmessage += \", status 'published' and new master ref available\"\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage,\n\t\t})\n\n\t\treturn result\n\t}\n\n\t/**\n\t * Retrieves data for a specific document version.\n\t *\n\t * @param versionId - The document's version ID.\n\t * @returns The document's version data.\n\t */\n\tasync getDocumentData(versionId: string): Promise<CoreApiDocumentData> {\n\t\treturn await this.coreApiClient.getDocumentData(versionId)\n\t}\n\n\tasync setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tif (!this.integrationFieldsClient) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Integration Fields client not found. Did you provide a integration fields api url in the configuration?\",\n\t\t\t)\n\t\t}\n\n\t\tawait this.integrationFieldsClient.setupIntegrationFields(integrationFields)\n\t\tprofiler.done({\n\t\t\tmessage: `Integration Fields setup`,\n\t\t})\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale\n\tlocales?: string[]\n\tdefaultLocale?: string\n\tslices?: SharedSliceModel[]\n\tcustomTypes?: DynamicCustomTypeModel[]\n\tpreview?: Preview\n\tsimulatorURL?: string\n\trolePerLocal?: boolean\n\tcustomRoles?: boolean\n\tintegrationFields?: IntegrationFieldConfig[]\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"],"mappings":";;;;;;AA0BA,IAAa,oBAAb,MAA+B;CAEpB;CACQ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CATlB,YACC,MACA,eACA,eACA,aACA,sBACA,oBACA,gBACA,gBACA,yBACC;EATQ,KAAA,OAAA;EACQ,KAAA,gBAAA;EACA,KAAA,gBAAA;EACA,KAAA,cAAA;EACA,KAAA,uBAAA;EACA,KAAA,qBAAA;EACA,KAAA,iBAAA;EACA,KAAA,i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names":[],"sources":["../../src/managers/repository.ts"],"sourcesContent":["import { expect } from \"@playwright/test\"\nimport type { DynamicCustomTypeModel, SharedSliceModel } from \"@prismicio/types-internal\"\nimport type { AxiosResponse } from \"axios\"\n\nimport type { AssetApiClient } from \"../clients/assetApi\"\nimport type { AuthenticationApiClient } from \"../clients/authenticationApi\"\nimport { ContentApiClient } from \"../clients/contentApi\"\nimport type {\n\tCoreApiClient,\n\tCoreApiDocumentCreationPayload,\n\tCoreApiDocumentCreationResponse,\n\tCoreApiDocumentData,\n\tCoreApiDocumentsPayload,\n\tCoreApiDocumentsResponse,\n\tCoreApiDocumentUpdatePayload,\n\tRelease,\n} from \"../clients/coreApi\"\nimport type { CustomTypesApiClient } from \"../clients/customTypesApi\"\nimport type { IntegrationFieldsClient } from \"../clients/integrationFields\"\nimport type { ManageV2Client } from \"../clients/manageV2\"\nimport type { MigrationApiClient } from \"../clients/migrationApi\"\nimport type { WroomClient } from \"../clients/wroom\"\nimport type { IntegrationFieldConfig } from \"../types\"\nimport { logHttpResponse, logger } from \"../utils/log\"\nimport { getRepositoryUrl } from \"../utils/urls\"\n\n/** Utility to manage test data for a Prismic repository */\nexport class RepositoryManager {\n\tconstructor(\n\t\treadonly name: string,\n\t\tprivate readonly coreApiClient: CoreApiClient,\n\t\tprivate readonly authApiClient: AuthenticationApiClient,\n\t\tprivate readonly wroomClient: WroomClient,\n\t\tprivate readonly customTypesApiClient: CustomTypesApiClient,\n\t\tprivate readonly migrationApiClient: MigrationApiClient | undefined,\n\t\tprivate readonly assetApiClient: AssetApiClient,\n\t\tprivate readonly manageV2Client: ManageV2Client,\n\t\tprivate readonly integrationFieldsClient: IntegrationFieldsClient | undefined,\n\t) {}\n\n\tasync configure(config: RepositoryConfig): Promise<void> {\n\t\tconst hasLangConfig = config.defaultLocale || config.locales || config.customLocale\n\t\tif (hasLangConfig) {\n\t\t\tconst languages = await this.coreApiClient.getLanguages()\n\t\t\tlet updateDefaultLocaleAtTheEnd = false\n\t\t\t// if no locale exists on repo, the master locale needs to be set first\n\t\t\tif (config.defaultLocale) {\n\t\t\t\tconst master = languages.find(({ is_master }) => is_master === true)\n\t\t\t\tif (!master) {\n\t\t\t\t\tawait this.setDefaultLocale(config.defaultLocale, \"create\")\n\t\t\t\t} else if (master.id !== config.defaultLocale) {\n\t\t\t\t\t// update the master lang at the end, after it is created.\n\t\t\t\t\tupdateDefaultLocaleAtTheEnd = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.locales) {\n\t\t\t\t// No need to add default locale and already existing languages\n\t\t\t\tconst localesToAdd = config.locales.filter(\n\t\t\t\t\t(id) => !languages.some((language) => language.id === id),\n\t\t\t\t)\n\t\t\t\tif (localesToAdd.length > 0) {\n\t\t\t\t\tawait this.createLocales(localesToAdd)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.customLocale) {\n\t\t\t\tif (!languages.find(({ id }) => id === config.customLocale?.lang.id)) {\n\t\t\t\t\tawait this.createCustomLocale(config.customLocale)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (config.defaultLocale && updateDefaultLocaleAtTheEnd) {\n\t\t\t\tawait this.setDefaultLocale(config.defaultLocale, \"update\")\n\t\t\t}\n\t\t}\n\n\t\tif (config.slices) {\n\t\t\tawait this.createSlices(config.slices)\n\t\t}\n\n\t\tif (config.customTypes) {\n\t\t\tawait this.createCustomTypes(config.customTypes)\n\t\t}\n\n\t\tif (config.preview) {\n\t\t\tawait this.createPreview(config.preview)\n\t\t}\n\n\t\tif (config.simulatorURL) {\n\t\t\tawait this.setSimulatorURL(config.simulatorURL)\n\t\t}\n\n\t\tif (config.rolePerLocal) {\n\t\t\tawait this.toggleRolePerLocal(true)\n\t\t}\n\n\t\tif (config.customRoles) {\n\t\t\tawait this.toggleCustomRoles(true)\n\t\t}\n\n\t\tif (config.integrationFields) {\n\t\t\tawait this.toggleIntegrationFields(true)\n\t\t\tawait this.setupIntegrationFields(config.integrationFields)\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 url. Uses Playwright\n\t * for requests so if your project uses Playwright too, any network request will be present in\n\t * Playwright test reports.\n\t */\n\tgetContentApiClient(config?: { version?: \"v1\" | \"v2\"; accessToken?: string }): ContentApiClient {\n\t\treturn new ContentApiClient(this.getBaseCdnURL(), config)\n\t}\n\n\t/**\n\t * @returns An instance of the Migration api client, see\n\t * https://prismic.io/docs/migration-api-technical-reference\n\t */\n\tgetMigrationApiClient(): MigrationApiClient {\n\t\tif (!this.migrationApiClient) {\n\t\t\tthrow \"No client found for the migration api. Did you provide a migration api url in the configuration?\"\n\t\t}\n\n\t\treturn this.migrationApiClient\n\t}\n\n\t/**\n\t * @returns An instance of the Asset api client, see\n\t * https://prismic.io/docs/asset-api-technical-reference\n\t */\n\tgetAssetApiClient(): AssetApiClient {\n\t\treturn this.assetApiClient\n\t}\n\n\t/** @returns The Wroom commit hash deployed on the current repository */\n\tasync getDeployedVersion(): Promise<string | undefined> {\n\t\tconst response = await this.wroomClient.get(\n\t\t\tthis.name,\n\t\t\t\"underground/834b34f16f451e00f268dd5c8c81d16e3c020275\",\n\t\t)\n\n\t\t// Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute\n\t\treturn response.data.version\n\t}\n\n\t/**\n\t * Set additional standard locales for a repository in Wroom, does not fail if the locales already\n\t * exist.\n\t *\n\t * @param locales - An array of all locales to be added to the repository.\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(this.name, \"app/settings/multilanguages\", {\n\t\t\tlanguages: locales,\n\t\t})\n\n\t\tconst { data, status } = response\n\t\tconst success =\n\t\t\tstatus === 200 || (status === 400 && (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 the locales already\n\t * exist.\n\t *\n\t * @param locale - The locale to be added to the repository.\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 || (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 * @throws Error if deleting the locale fails.\n\t */\n\tasync deleteLocale(locale: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/multilanguages/${locale}/delete`,\n\t\t)\n\t\tthis.failIfNot200(response, `Could not delete locale ${locale}`)\n\t\tprofiler.done({ message: `locale '${locale}' deleted` })\n\t}\n\n\t/**\n\t * Create or update the default (master) locale for a repository in Wroom, the locale needs to\n\t * exist in the repository.\n\t *\n\t * @param locale - The locale to be set as the default.\n\t * @param endpoint - \"createMasterLang\" to create it, \"defineAsMaster\" to update it.\n\t * @throws Error if setting the default locale fails.\n\t */\n\tasync setDefaultLocale(locale: string, action: \"create\" | \"update\"): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst endpoint = {\n\t\t\tcreate: \"createMasterLang\",\n\t\t\tupdate: \"defineAsMaster\",\n\t\t}\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`/app/settings/multilanguages/${locale}/${endpoint[action]}`,\n\t\t)\n\n\t\tconst { data, status } = response\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t// returns 400 if master lang is already set\n\t\t\t\tJSON.stringify(data).includes(\"Unable to set as master language\"))\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not set default locale to ${locale}`)\n\t\t}\n\t\tprofiler.done({ message: `default locale set to '${locale}'` })\n\t}\n\n\t/**\n\t * Retrieves documents.\n\t *\n\t * @param args - Configure which documents are retrieved.\n\t * @returns A paginated set of documents.\n\t */\n\tasync getDocuments(args: CoreApiDocumentsPayload): Promise<CoreApiDocumentsResponse> {\n\t\treturn this.coreApiClient.getDocuments(args)\n\t}\n\n\t/**\n\t * Creates a release.\n\t *\n\t * @param label - The label for the release.\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 * Retrieves the migration release.\n\t *\n\t * @returns The migration relese metadata.\n\t */\n\tasync getMigrationRelease(): Promise<Release> {\n\t\tconst releases = await this.coreApiClient.getReleases()\n\t\tconst migrationRelease = releases.find((release) => release.migration)\n\t\tif (!migrationRelease) {\n\t\t\tthrow new Error(`The repository does not have a migration release`)\n\t\t}\n\n\t\treturn migrationRelease\n\t}\n\n\t/**\n\t * Publishes a release.\n\t *\n\t * @param id - The ID of the release.\n\t * @returns A Promise that resolves when the release is published and a new master ref is\n\t * available.\n\t */\n\tasync publishRelease(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst contentApi = this.getContentApiClient()\n\t\tconst masterRef = await contentApi.getMasterRef()\n\t\tawait this.coreApiClient.publishRelease(id)\n\t\tawait this.waitForNewMasterRef(contentApi, masterRef)\n\n\t\tprofiler.done({\n\t\t\tmessage: `release '${id}' published and new master ref available`,\n\t\t})\n\t}\n\n\t/**\n\t * Deletes a repository release.\n\t *\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(this.name, `app/releases/${id}/delete`, {})\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(this.name, `previews/new`, data)\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 * Set the simulator URL (table of slices) for a repository.\n\t *\n\t * @param data - The simulator URL to set.\n\t */\n\tasync setSimulatorURL(simulatorURL: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst repository = await this.coreApiClient.getRepository()\n\t\tawait this.coreApiClient.updateRepository({\n\t\t\t...repository,\n\t\t\tsimulator_url: simulatorURL,\n\t\t})\n\n\t\tprofiler.done({\n\t\t\tmessage: `simulator preview '${simulatorURL}' created`,\n\t\t})\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(this.name, `previews/delete/${id}`, {})\n\n\t\tthis.failIfNot200(response, `Could not delete preview with id ${id}`)\n\t\tprofiler.done({ message: `preview '${id}' deleted` })\n\t}\n\n\t/**\n\t * Create a webhook.\n\t *\n\t * @returns A Promise that resolves with the webhook id.\n\t */\n\tasync createWebhook(\n\t\tname: string,\n\t\turl: string,\n\t\tsecret: string,\n\t\ttriggers: {\n\t\t\tdocumentsPublished?: boolean\n\t\t\tdocumentsUnpublished?: boolean\n\t\t\treleasesCreated?: boolean\n\t\t\treleasesUpdated?: boolean\n\t\t\ttagsCreated?: boolean\n\t\t\ttagsDeleted?: boolean\n\t\t},\n\t\tactive: boolean,\n\t): Promise<string> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.wroomClient.post(this.name, \"app/settings/webhooks/create\", {\n\t\t\tname,\n\t\t\turl,\n\t\t\tsecret,\n\t\t\tactive: active ? \"on\" : \"off\",\n\t\t\t...triggers,\n\t\t})\n\t\tthis.failIfNot200(response, `Could not create webhook ${name}`)\n\t\tprofiler.done({ message: `webhook '${name}' created` })\n\n\t\treturn response.data.created\n\t}\n\n\t/**\n\t * Deletes a webhook.\n\t *\n\t * @param id - The webhook ID.\n\t */\n\tasync deleteWebhook(id: string): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.name,\n\t\t\t`app/settings/webhooks/${id}/delete`,\n\t\t\t{},\n\t\t)\n\n\t\tthis.failIfNot200(response, `Could not delete webhook with id ${id}`)\n\t\tprofiler.done({ message: `webhook '${id}' deleted` })\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes\n\t */\n\tasync createCustomTypes(customTypes: DynamicCustomTypeModel[]): Promise<void> {\n\t\tawait this.customTypesApiClient.createCustomTypes(customTypes)\n\t}\n\n\tasync deleteCustomType(customTypeId: string): Promise<void> {\n\t\tawait this.customTypesApiClient.deleteCustomType(customTypeId)\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: SharedSliceModel[]): 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 api is fully private\n\t * 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[]> = await this.wroomClient.get(\n\t\t\tthis.name,\n\t\t\t\"settings/security/contentapi\",\n\t\t)\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> = await this.wroomClient.post(\n\t\t\t\tthis.name,\n\t\t\t\t\"settings/security/oauthapp\",\n\t\t\t\t{\n\t\t\t\t\tapp_name: appName,\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tthis.failIfNot200(response, `Could not create content api app ${appName}`)\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(this.name, \"settings/security/authorizations\", {\n\t\t\t\tapp: app.id,\n\t\t\t\tscope: tokenScope,\n\t\t\t})\n\t\t\tthis.failIfNot200(\n\t\t\t\tresponse,\n\t\t\t\t`Could not create content api access token for app ${appName} with scope ${tokenScope}`,\n\t\t\t)\n\t\t\ttokenInfo = response.data\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `content api access token for app '${appName}' created`,\n\t\t})\n\n\t\tif (!tokenInfo?.token) {\n\t\t\tthrow `Could not create content api access token for app ${appName} with scope ${tokenScope}`\n\t\t}\n\n\t\treturn tokenInfo.token\n\t}\n\n\t/** Create a permanent access token to authenticate to Prismic public apis. */\n\tasync createPermanentAccessToken(): Promise<string> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst token = await this.authApiClient.getMachine2MachineToken(this.name)\n\n\t\tprofiler.done({\n\t\t\tmessage: `machine2machine token created`,\n\t\t})\n\n\t\treturn token\n\t}\n\n\t/**\n\t * Toggle the Role per Locale workflow\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleRolePerLocal(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.manageV2Client.toggleRolePerLocal({\n\t\t\trepository: this.name,\n\t\t\tenabled: enabled,\n\t\t})\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not ${enabled ? \"enable\" : \"disable\"} Role per local for ${this.name}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Role per local ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t})\n\t}\n\n\t/**\n\t * Toggle the Custom Roles workflow\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleCustomRoles(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.manageV2Client.toggleCustomRoles({\n\t\t\trepository: this.name,\n\t\t\tenabled: enabled,\n\t\t})\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not ${enabled ? \"enable\" : \"disable\"} Custom Roles for ${this.name}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Custom Roles ${enabled ? \"enabled\" : \"disabled\"}`,\n\t\t})\n\t}\n\n\t/**\n\t * Toggle the Integration Fields feature\n\t *\n\t * @param enabled - The feature new status\n\t */\n\tasync toggleIntegrationFields(enabled: boolean): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response = await this.manageV2Client.toggleIntegrationFields({\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\"} Integration Fields for ${this.name}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Integration Fields ${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 && JSON.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(response, `Could not remove the user ${email} from the repository`)\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, either a string for\n\t * basic workflow or an object such as `{ \"lang_id\": \"Writer\" }`\n\t *\n\t * Example of roles are\n\t *\n\t * - Administrator\n\t * - Writer\n\t * - Contributor\n\t * - Manager (publisher)\n\t */\n\tasync updateUserRole(email: string, role: string | Record<string, string>): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tconst response =\n\t\t\ttypeof role === \"string\"\n\t\t\t\t? await this.wroomClient.updateRole(this.name, email, role)\n\t\t\t\t: await this.wroomClient.updateRolePerLocal(this.name, email, role)\n\n\t\tthis.failIfNot200(\n\t\t\tresponse,\n\t\t\t`Could not update the ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} of the user ${email}`,\n\t\t)\n\t\tprofiler.done({\n\t\t\tmessage: `Updated User's ${\n\t\t\t\ttypeof role === \"string\" ? \"role\" : \"rolePerLocal\"\n\t\t\t} for user ${email}`,\n\t\t})\n\t}\n\n\t/**\n\t * Creates a document using the core api. If the Core api format is too specific, use the\n\t * migration api client to create a document with the MigrationApiClient. See the\n\t * `getMigrationApiClient()` method.\n\t *\n\t * @example\n\t * \tTo create a document by converting it from the Page Builder to\n\t * \tCore api format\n\t *\n\t * \t```js\n\t * \timport { DocumentLegacy, UIDContentType } from '@prismicio/types-internal/lib/content';\n\t *\n\t * \tconst document = {\n\t * \ttitle: 'A new document',\n\t * \tcustom_type_id: 'home-page',\n\t * \tlocale: 'en-gb',\n\t * \tintegration_field_ids: [],\n\t * \ttags: [],\n\t * \tdata: DocumentLegacy.encode({\n\t * \tuid: {\n\t * \t__TYPE__: UIDContentType,\n\t * \tvalue: 'home-page',\n\t * \t},\n\t * \t})\n\t * \t}\n\t * \tawait repository.createDocument(document, 'published');\n\t * \t* ```\n\t * \t```\n\t *\n\t * \t@returns\n\t *\n\t * \t@param document - in the core api format.\n\t *\n\t * \t@param status - status of the document, if published, the function will\n\t * \twait for a new content api master ref to be created\n\t */\n\tasync createDocument(\n\t\tdocument: CoreApiDocumentCreationPayload,\n\t\tstatus: \"draft\" | \"published\",\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst profiler = logger.startTimer()\n\t\tconst result = await this.coreApiClient.createDraft(document)\n\n\t\tlet message = `Document created with id '${result.id}'`\n\t\tif (status === \"published\") {\n\t\t\tconst contentApi = this.getContentApiClient()\n\t\t\tconst masterRef = await contentApi.getMasterRef()\n\t\t\tawait this.coreApiClient.publishDraft(result.id)\n\t\t\tawait this.waitForNewMasterRef(contentApi, 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\t/**\n\t * Updates an existing document using the core api by creating a new draft version on top of the\n\t * given base version. If the status is published, the function will, unless disabled, wait for a\n\t * new content api master ref to be created.\n\t *\n\t * @param documentId - The id of the document to update.\n\t * @param data - The new version payload in the core api format.\n\t * @param baseVersionId - The id of the version the draft is created from.\n\t * @param status - Status of the new version, if published, the function will wait for a new\n\t * content api master ref to be created.\n\t * @param options - Additional options.\n\t * @param options.skipMasterRefWait - When publishing, skip waiting for a new content api master\n\t * ref to be available (default false). Set to true to return without waiting for the\n\t * projection.\n\t * @returns The updated document, including the new version's id. When publishing, the document is\n\t * retrieved again after publication so that the returned versions reflect the published state.\n\t */\n\tasync updateDocument(\n\t\tdocumentId: string,\n\t\tdata: CoreApiDocumentUpdatePayload,\n\t\tbaseVersionId: string,\n\t\tstatus: \"draft\" | \"published\",\n\t\toptions: { skipMasterRefWait?: boolean } = {},\n\t): Promise<CoreApiDocumentCreationResponse> {\n\t\tconst { skipMasterRefWait = false } = options\n\t\tconst profiler = logger.startTimer()\n\t\tconst draft = await this.coreApiClient.updateDraft(documentId, data, baseVersionId)\n\n\t\tif (status === \"draft\") {\n\t\t\tprofiler.done({ message: `Document '${documentId}' updated` })\n\n\t\t\treturn draft\n\t\t}\n\n\t\tlet message = `Document '${documentId}' updated, status 'published'`\n\t\tif (skipMasterRefWait) {\n\t\t\tawait this.coreApiClient.publishDraft(documentId)\n\t\t} else {\n\t\t\tconst contentApi = this.getContentApiClient()\n\t\t\tconst masterRef = await contentApi.getMasterRef()\n\t\t\tawait this.coreApiClient.publishDraft(documentId)\n\t\t\tawait this.waitForNewMasterRef(contentApi, masterRef)\n\t\t\tmessage += \" and new master ref available\"\n\t\t}\n\n\t\tconst { results } = await this.coreApiClient.getDocuments({\n\t\t\tdocumentIds: [documentId],\n\t\t\tlimit: 1,\n\t\t})\n\t\tconst publishedDocument = results[0]\n\t\tif (!publishedDocument) {\n\t\t\tthrow new Error(`Could not retrieve document '${documentId}' after publication`)\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage,\n\t\t})\n\n\t\treturn publishedDocument\n\t}\n\n\t/**\n\t * Unpublishes (archives) a live document using the core api. Unless disabled, waits for a new\n\t * content api master ref to be available.\n\t *\n\t * @param documentId - The id of the document to unpublish.\n\t * @param options - Additional options.\n\t * @param options.skipMasterRefWait - Skip waiting for a new content api master ref to be\n\t * available (default false). Set to true to return without waiting for the projection.\n\t */\n\tasync unpublishDocument(\n\t\tdocumentId: string,\n\t\toptions: { skipMasterRefWait?: boolean } = {},\n\t): Promise<void> {\n\t\tconst { skipMasterRefWait = false } = options\n\t\tconst profiler = logger.startTimer()\n\n\t\tif (skipMasterRefWait) {\n\t\t\tawait this.coreApiClient.unpublishDocument(documentId)\n\t\t\tprofiler.done({ message: `Document '${documentId}' unpublished` })\n\n\t\t\treturn\n\t\t}\n\n\t\tconst contentApi = this.getContentApiClient()\n\t\tconst masterRef = await contentApi.getMasterRef()\n\t\tawait this.coreApiClient.unpublishDocument(documentId)\n\t\tawait this.waitForNewMasterRef(contentApi, masterRef)\n\n\t\tprofiler.done({\n\t\t\tmessage: `Document '${documentId}' unpublished and new master ref available`,\n\t\t})\n\t}\n\n\t/**\n\t * Retrieves data for a specific document version.\n\t *\n\t * @param versionId - The document's version ID.\n\t * @returns The document's version data.\n\t */\n\tasync getDocumentData(versionId: string): Promise<CoreApiDocumentData> {\n\t\treturn await this.coreApiClient.getDocumentData(versionId)\n\t}\n\n\tasync setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {\n\t\tconst profiler = logger.startTimer()\n\n\t\tif (!this.integrationFieldsClient) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Integration Fields client not found. Did you provide a integration fields api url in the configuration?\",\n\t\t\t)\n\t\t}\n\n\t\tawait this.integrationFieldsClient.setupIntegrationFields(integrationFields)\n\t\tprofiler.done({\n\t\t\tmessage: `Integration Fields setup`,\n\t\t})\n\t}\n\n\tprivate async waitForNewMasterRef(\n\t\tcontentApi: ContentApiClient,\n\t\tpreviousMasterRef: string,\n\t): Promise<void> {\n\t\tawait expect\n\t\t\t.poll(async () => contentApi.getMasterRef(), {\n\t\t\t\ttimeout: 10_000,\n\t\t\t\tmessage: \"Waiting for new master ref to be available\",\n\t\t\t})\n\t\t\t.not.toBe(previousMasterRef)\n\t}\n}\n\nexport type RepositoryConfig = {\n\tcustomLocale?: CustomLocale\n\tlocales?: string[]\n\tdefaultLocale?: string\n\tslices?: SharedSliceModel[]\n\tcustomTypes?: DynamicCustomTypeModel[]\n\tpreview?: Preview\n\tsimulatorURL?: string\n\trolePerLocal?: boolean\n\tcustomRoles?: boolean\n\tintegrationFields?: IntegrationFieldConfig[]\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"],"mappings":";;;;;;AA2BA,IAAa,oBAAb,MAA+B;CAEpB;CACQ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CATlB,YACC,MACA,eACA,eACA,aACA,sBACA,oBACA,gBACA,gBACA,yBACC;EATQ,KAAA,OAAA;EACQ,KAAA,gBAAA;EACA,KAAA,gBAAA;EACA,KAAA,cAAA;EACA,KAAA,uBAAA;EACA,KAAA,qBAAA;EACA,KAAA,iBAAA;EACA,KAAA,iBAAA;EACA,KAAA,0BAAA;CACf;CAEH,MAAM,UAAU,QAAyC;EAExD,IADsB,OAAO,iBAAiB,OAAO,WAAW,OAAO,cACpD;GAClB,MAAM,YAAY,MAAM,KAAK,cAAc,aAAa;GACxD,IAAI,8BAA8B;GAElC,IAAI,OAAO,eAAe;IACzB,MAAM,SAAS,UAAU,MAAM,EAAE,gBAAgB,cAAc,IAAI;IACnE,IAAI,CAAC,QACJ,MAAM,KAAK,iBAAiB,OAAO,eAAe,QAAQ;SACpD,IAAI,OAAO,OAAO,OAAO,eAE/B,8BAA8B;GAEhC;GAEA,IAAI,OAAO,SAAS;IAEnB,MAAM,eAAe,OAAO,QAAQ,QAClC,OAAO,CAAC,UAAU,MAAM,aAAa,SAAS,OAAO,EAAE,CACzD;IACA,IAAI,aAAa,SAAS,GACzB,MAAM,KAAK,cAAc,YAAY;GAEvC;GAEA,IAAI,OAAO;QACN,CAAC,UAAU,MAAM,EAAE,SAAS,OAAO,OAAO,cAAc,KAAK,EAAE,GAClE,MAAM,KA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,KAAK,cAAc,kBAAkB,UAAU;EACrD,MAAM,KAAK,oBAAoB,YAAY,SAAS;EAEpD,SAAS,KAAK,EACb,SAAS,aAAa,WAAW,4CAClC,CAAC;CACF;;;;;;;CAQA,MAAM,gBAAgB,WAAiD;EACtE,OAAO,MAAM,KAAK,cAAc,gBAAgB,SAAS;CAC1D;CAEA,MAAM,uBAAuB,mBAA4D;EACxF,MAAM,WAAW,OAAO,WAAW;EAEnC,IAAI,CAAC,KAAK,yBACT,MAAM,IAAI,MACT,yGACD;EAGD,MAAM,KAAK,wBAAwB,uBAAuB,iBAAiB;EAC3E,SAAS,KAAK,EACb,SAAS,2BACV,CAAC;CACF;CAEA,MAAc,oBACb,YACA,mBACgB;EAChB,MAAM,OACJ,KAAK,YAAY,WAAW,aAAa,GAAG;GAC5C,SAAS;GACT,SAAS;EACV,CAAC,CAAC,CACD,IAAI,KAAK,iBAAiB;CAC7B;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "1.19.0",
3
+ "version": "1.20.0-pr.40.f652adb",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "prismic",
@@ -129,7 +129,9 @@ export class ContentApiClient extends AuthenticatedApiClient {
129
129
  headers?: Record<string, string>,
130
130
  ): Promise<APIResponse> {
131
131
  const context = await this.getContext()
132
- const securityParams = this.accessToken ? { access_token: this.accessToken } : {} as Record<string, never>
132
+ const securityParams = this.accessToken
133
+ ? { access_token: this.accessToken }
134
+ : ({} as Record<string, never>)
133
135
 
134
136
  return context.get(path, {
135
137
  params: { ...securityParams, ...params },
@@ -25,6 +25,12 @@ export type CoreApiDocumentCreationPayload = {
25
25
  tags: string[]
26
26
  }
27
27
 
28
+ export type CoreApiDocumentUpdatePayload = {
29
+ data: Record<string, unknown>
30
+ integration_field_ids: string[]
31
+ tags: string[]
32
+ }
33
+
28
34
  export type CoreApiRepository = Record<string, unknown> & {
29
35
  simulator_url?: string
30
36
  }
@@ -62,6 +68,7 @@ export type CoreApiDocumentsPayload = {
62
68
  limit?: number
63
69
  statuses?: string[]
64
70
  groupLangIds?: string[]
71
+ documentIds?: string[]
65
72
  }
66
73
 
67
74
  export type CoreApiDocumentsResponse = {
@@ -147,6 +154,33 @@ export class CoreApiClient extends AuthenticatedApiClient {
147
154
  return result.json()
148
155
  }
149
156
 
157
+ /**
158
+ * Creates a new draft version of an existing document, on top of the given base version.
159
+ *
160
+ * @param documentId - The id of the document to update.
161
+ * @param data - The new version payload in the core api format.
162
+ * @param baseVersionId - The id of the version the draft is created from.
163
+ * @returns The updated document, including the new version's id.
164
+ */
165
+ async updateDraft(
166
+ documentId: string,
167
+ data: CoreApiDocumentUpdatePayload,
168
+ baseVersionId: string,
169
+ ): Promise<CoreApiDocumentCreationResponse> {
170
+ const context = await this.getContext()
171
+ const result = await context.put(`core/documents/${documentId}/draft`, {
172
+ params: { base_version_id: baseVersionId },
173
+ data,
174
+ })
175
+
176
+ if (200 !== result.status()) {
177
+ await logPlaywrightApiResponse(result)
178
+ throw new Error(`Could not update draft for document with id ${documentId}`)
179
+ }
180
+
181
+ return result.json()
182
+ }
183
+
150
184
  async publishDraft(documentId: string): Promise<void> {
151
185
  const context = await this.getContext()
152
186
  const result = await context.patch(`core/documents/${documentId}/draft`, {
@@ -161,6 +195,25 @@ export class CoreApiClient extends AuthenticatedApiClient {
161
195
  }
162
196
  }
163
197
 
198
+ /**
199
+ * Unpublishes (archives) a live document.
200
+ *
201
+ * @param documentId - The id of the document to unpublish.
202
+ */
203
+ async unpublishDocument(documentId: string): Promise<void> {
204
+ const context = await this.getContext()
205
+ const result = await context.patch(`core/documents/${documentId}/live`, {
206
+ data: {
207
+ status: "archived",
208
+ },
209
+ })
210
+
211
+ if (204 !== result.status()) {
212
+ await logPlaywrightApiResponse(result)
213
+ throw new Error(`Could not unpublish document with id ${documentId}`)
214
+ }
215
+ }
216
+
164
217
  /**
165
218
  * Retrieves documents.
166
219
  *
@@ -38,7 +38,9 @@ export class CustomTypesApiClient extends AuthenticatedApiClient {
38
38
  })
39
39
  }
40
40
 
41
- private async getRemoteItems(endpoint: ItemTypePath): Promise<DynamicCustomTypeModel[] | SharedSliceModel[]> {
41
+ private async getRemoteItems(
42
+ endpoint: ItemTypePath,
43
+ ): Promise<DynamicCustomTypeModel[] | SharedSliceModel[]> {
42
44
  const context = await this.getContext()
43
45
  const result = await context.get(endpoint)
44
46
 
@@ -12,6 +12,7 @@ import type {
12
12
  CoreApiDocumentData,
13
13
  CoreApiDocumentsPayload,
14
14
  CoreApiDocumentsResponse,
15
+ CoreApiDocumentUpdatePayload,
15
16
  Release,
16
17
  } from "../clients/coreApi"
17
18
  import type { CustomTypesApiClient } from "../clients/customTypesApi"
@@ -319,12 +320,7 @@ export class RepositoryManager {
319
320
  const contentApi = this.getContentApiClient()
320
321
  const masterRef = await contentApi.getMasterRef()
321
322
  await this.coreApiClient.publishRelease(id)
322
- await expect
323
- .poll(async () => contentApi.getMasterRef(), {
324
- timeout: 10_000,
325
- message: "Waiting for new master ref to be available",
326
- })
327
- .not.toBe(masterRef)
323
+ await this.waitForNewMasterRef(contentApi, masterRef)
328
324
 
329
325
  profiler.done({
330
326
  message: `release '${id}' published and new master ref available`,
@@ -762,12 +758,7 @@ export class RepositoryManager {
762
758
  const contentApi = this.getContentApiClient()
763
759
  const masterRef = await contentApi.getMasterRef()
764
760
  await this.coreApiClient.publishDraft(result.id)
765
- await expect
766
- .poll(async () => contentApi.getMasterRef(), {
767
- timeout: 10_000,
768
- message: "Waiting for new master ref to be available",
769
- })
770
- .not.toBe(masterRef)
761
+ await this.waitForNewMasterRef(contentApi, masterRef)
771
762
  message += ", status 'published' and new master ref available"
772
763
  }
773
764
  profiler.done({
@@ -777,6 +768,100 @@ export class RepositoryManager {
777
768
  return result
778
769
  }
779
770
 
771
+ /**
772
+ * Updates an existing document using the core api by creating a new draft version on top of the
773
+ * given base version. If the status is published, the function will, unless disabled, wait for a
774
+ * new content api master ref to be created.
775
+ *
776
+ * @param documentId - The id of the document to update.
777
+ * @param data - The new version payload in the core api format.
778
+ * @param baseVersionId - The id of the version the draft is created from.
779
+ * @param status - Status of the new version, if published, the function will wait for a new
780
+ * content api master ref to be created.
781
+ * @param options - Additional options.
782
+ * @param options.skipMasterRefWait - When publishing, skip waiting for a new content api master
783
+ * ref to be available (default false). Set to true to return without waiting for the
784
+ * projection.
785
+ * @returns The updated document, including the new version's id. When publishing, the document is
786
+ * retrieved again after publication so that the returned versions reflect the published state.
787
+ */
788
+ async updateDocument(
789
+ documentId: string,
790
+ data: CoreApiDocumentUpdatePayload,
791
+ baseVersionId: string,
792
+ status: "draft" | "published",
793
+ options: { skipMasterRefWait?: boolean } = {},
794
+ ): Promise<CoreApiDocumentCreationResponse> {
795
+ const { skipMasterRefWait = false } = options
796
+ const profiler = logger.startTimer()
797
+ const draft = await this.coreApiClient.updateDraft(documentId, data, baseVersionId)
798
+
799
+ if (status === "draft") {
800
+ profiler.done({ message: `Document '${documentId}' updated` })
801
+
802
+ return draft
803
+ }
804
+
805
+ let message = `Document '${documentId}' updated, status 'published'`
806
+ if (skipMasterRefWait) {
807
+ await this.coreApiClient.publishDraft(documentId)
808
+ } else {
809
+ const contentApi = this.getContentApiClient()
810
+ const masterRef = await contentApi.getMasterRef()
811
+ await this.coreApiClient.publishDraft(documentId)
812
+ await this.waitForNewMasterRef(contentApi, masterRef)
813
+ message += " and new master ref available"
814
+ }
815
+
816
+ const { results } = await this.coreApiClient.getDocuments({
817
+ documentIds: [documentId],
818
+ limit: 1,
819
+ })
820
+ const publishedDocument = results[0]
821
+ if (!publishedDocument) {
822
+ throw new Error(`Could not retrieve document '${documentId}' after publication`)
823
+ }
824
+
825
+ profiler.done({
826
+ message,
827
+ })
828
+
829
+ return publishedDocument
830
+ }
831
+
832
+ /**
833
+ * Unpublishes (archives) a live document using the core api. Unless disabled, waits for a new
834
+ * content api master ref to be available.
835
+ *
836
+ * @param documentId - The id of the document to unpublish.
837
+ * @param options - Additional options.
838
+ * @param options.skipMasterRefWait - Skip waiting for a new content api master ref to be
839
+ * available (default false). Set to true to return without waiting for the projection.
840
+ */
841
+ async unpublishDocument(
842
+ documentId: string,
843
+ options: { skipMasterRefWait?: boolean } = {},
844
+ ): Promise<void> {
845
+ const { skipMasterRefWait = false } = options
846
+ const profiler = logger.startTimer()
847
+
848
+ if (skipMasterRefWait) {
849
+ await this.coreApiClient.unpublishDocument(documentId)
850
+ profiler.done({ message: `Document '${documentId}' unpublished` })
851
+
852
+ return
853
+ }
854
+
855
+ const contentApi = this.getContentApiClient()
856
+ const masterRef = await contentApi.getMasterRef()
857
+ await this.coreApiClient.unpublishDocument(documentId)
858
+ await this.waitForNewMasterRef(contentApi, masterRef)
859
+
860
+ profiler.done({
861
+ message: `Document '${documentId}' unpublished and new master ref available`,
862
+ })
863
+ }
864
+
780
865
  /**
781
866
  * Retrieves data for a specific document version.
782
867
  *
@@ -801,6 +886,18 @@ export class RepositoryManager {
801
886
  message: `Integration Fields setup`,
802
887
  })
803
888
  }
889
+
890
+ private async waitForNewMasterRef(
891
+ contentApi: ContentApiClient,
892
+ previousMasterRef: string,
893
+ ): Promise<void> {
894
+ await expect
895
+ .poll(async () => contentApi.getMasterRef(), {
896
+ timeout: 10_000,
897
+ message: "Waiting for new master ref to be available",
898
+ })
899
+ .not.toBe(previousMasterRef)
900
+ }
804
901
  }
805
902
 
806
903
  export type RepositoryConfig = {