@slicemachine/manager 0.25.3-alpha.jp-align-radix-dependencies.1 → 0.25.3-alpha.jp-unauthorized-error.3

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.
@@ -207,7 +207,6 @@ class PrismicRepositoryManager extends BaseManager.BaseManager {
207
207
  }
208
208
  const modelWithScreenshots = await this.slices.updateSliceModelScreenshotsInPlace({
209
209
  libraryID: change.libraryID,
210
- variationImageUrlMap: change.variationImageUrlMap,
211
210
  model
212
211
  });
213
212
  return {
@@ -226,7 +225,6 @@ class PrismicRepositoryManager extends BaseManager.BaseManager {
226
225
  }
227
226
  const modelWithScreenshots = await this.slices.updateSliceModelScreenshotsInPlace({
228
227
  libraryID: change.libraryID,
229
- variationImageUrlMap: change.variationImageUrlMap,
230
228
  model
231
229
  });
232
230
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRepositoryManager.cjs","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { z } from \"zod\";\nimport fetch, { Response } from \"../../lib/fetch\";\nimport { fold } from \"fp-ts/Either\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decode } from \"../../lib/decode\";\nimport { serializeCookies } from \"../../lib/serializeCookies\";\n\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { REPOSITORY_NAME_VALIDATION } from \"../../constants/REPOSITORY_NAME_VALIDATION\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tPushBody,\n\tChangeTypes,\n\tClientError,\n\tPushChangesLimit,\n\tPushChangesLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tPushChangesRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n\tFrameworkWroomTelemetryID,\n\tStarterId,\n\tEnvironment,\n\tOnboardingState,\n} from \"./types\";\nimport { sortEnvironments } from \"./sortEnvironments\";\n\nconst DEFAULT_REPOSITORY_SETTINGS = {\n\tplan: \"personal\",\n\tisAnnual: \"false\",\n\trole: \"developer\",\n};\n\ntype PrismicRepositoryManagerCheckExistsArgs = {\n\tdomain: string;\n};\n\ntype PrismicRepositoryManagerCreateArgs = {\n\tdomain: string;\n\tframework: FrameworkWroomTelemetryID;\n\tstarterId?: StarterId;\n};\n\ntype PrismicRepositoryManagerDeleteArgs = {\n\tdomain: string;\n\tpassword: string;\n};\n\ntype PrismicRepositoryManagerPushDocumentsArgs = {\n\tdomain: string;\n\tsignature: string;\n\tdocuments: Record<string, unknown>; // TODO: Type unknown if possible(?)\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsArgs = {\n\t/**\n\t * If set to `true`, all environments are returned regardless of the user's\n\t * permission level.\n\t *\n\t * If set to `false`, only environments the user can access are returned.\n\t *\n\t * @defaultValue `false`\n\t */\n\tincludeAll?: boolean;\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsReturnType = {\n\tenvironments?: Environment[];\n};\n\nexport class PrismicRepositoryManager extends BaseManager {\n\t// TODO: Add methods for repository-specific actions. E.g. creating a\n\t// new repository.\n\n\tasync readAll(): Promise<PrismicRepository[]> {\n\t\tconst url = new URL(\"./repositories\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value: repositories, error } = decode(\n\t\t\t\tt.array(PrismicRepository),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to decode repositories: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn repositories;\n\t\t} else {\n\t\t\tconst text = await res.text();\n\t\t\tthrow new Error(`Failed to read repositories`, { cause: text });\n\t\t}\n\t}\n\n\t// Should this be in manager? It's one of the few sync method\n\t//\n\t// Reply from Angelo 2022-12-22: I think it should be in manager\n\t// because we shouldn't be exporting root-level utilities from this\n\t// package. If we want to make it more inline with the other methods,\n\t// we could simplify the API by changing its signature to the\n\t// following:\n\t//\n\t// ```ts\n\t// (repositoryName: string) => Promise<boolean>\n\t// ```\n\t//\n\t// This method would:\n\t//\n\t// 1. Fetch the list of repositories for the user using `readAll()`.\n\t// The list would be cached.\n\t// 2. Determine if the user has write access to the given repository.\n\t//\n\t// This version has the following benefits:\n\t//\n\t// - Does not expect the consumer to supply a repository object; it\n\t// only requires a repository name, which could be sourced from\n\t// anything (incl. the project's `slicemachine.config.json`).\n\t//\n\t// - Similarly, it does not expect the consumer to call `readAll()`\n\t// before calling this method.\n\t//\n\t// - Works for repositories that the user does not have access to. For\n\t// example, I could use it to check if I have access to \"qwerty\",\n\t// even if I am not added as a user. The purpose of the method is\n\t// still valid: do I have write access to a given repository?\n\thasWriteAccess(repository: PrismicRepository): boolean {\n\t\tswitch (repository.role) {\n\t\t\tcase PrismicRepositoryRole.SuperUser:\n\t\t\tcase PrismicRepositoryRole.Owner:\n\t\t\tcase PrismicRepositoryRole.Administrator:\n\t\t\t\treturn true;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync checkExists(\n\t\targs: PrismicRepositoryManagerCheckExistsArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t`./app/dashboard/repositories/${args.domain}/exists`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tskipAuthentication: true,\n\t\t});\n\n\t\tconst text = await res.text();\n\n\t\tif (res.ok) {\n\t\t\treturn text === \"false\"; // Endpoint returns `false` when repository exists\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to check repository existence for domain \\`${args.domain}\\``,\n\t\t\t\t{ cause: text },\n\t\t\t);\n\t\t}\n\t}\n\n\tasync create(args: PrismicRepositoryManagerCreateArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./authentication/newrepository?app=slicemachine\",\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\n\t\tconst body = {\n\t\t\t...DEFAULT_REPOSITORY_SETTINGS,\n\t\t\tdomain: args.domain,\n\t\t\t// These properties are optional in the API but needed for tracking\n\t\t\tframework: args.framework,\n\t\t\tstarterId: args.starterId,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.SliceMachine, // Custom User Agent is required\n\t\t});\n\t\tconst text = await res.text();\n\n\t\t// Endpoint returns repository name on success, that should be within the validation range\n\t\t// Even when there is an error, we get a 200 success and so we have to check the name thanks to that\n\t\tif (\n\t\t\t!res.ok ||\n\t\t\ttext.length < REPOSITORY_NAME_VALIDATION.Min ||\n\t\t\ttext.length > REPOSITORY_NAME_VALIDATION.Max\n\t\t) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: text,\n\t\t\t});\n\t\t}\n\t}\n\n\t// TODO: Delete this endpoint? It doesn't seem to be used (I might be wrong). - Angelo\n\tasync delete(args: PrismicRepositoryManagerDeleteArgs): Promise<void> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\n\n\t\tconst url = new URL(\n\t\t\t`./app/settings/delete?_=${cookies[\"X_XSRF\"]}`, // TODO: Maybe we want to throw early if the token is no available, or get the token another way\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tconfirm: args.domain,\n\t\t\tpassword: args.password,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`Failed to delete repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync pushDocuments(\n\t\targs: PrismicRepositoryManagerPushDocumentsArgs,\n\t): Promise<void> {\n\t\tconst url = new URL(\"./starter/documents\", API_ENDPOINTS.PrismicWroom);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tsignature: args.signature,\n\t\t\tdocuments: JSON.stringify(args.documents),\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tlet reason: string | null = null;\n\t\t\ttry {\n\t\t\t\treason = await res.text();\n\t\t\t} catch {\n\t\t\t\t// Noop\n\t\t\t}\n\n\t\t\t// Ideally the API should throw a 409 or something like that...\n\t\t\tif (reason === \"Repository should not contain documents\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, repository is not empty`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, ${res.status} ${res.statusText}`,\n\t\t\t\t{\n\t\t\t\t\tcause: reason,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushChanges(\n\t\targs: TransactionalMergeArgs,\n\t): Promise<TransactionalMergeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\ttry {\n\t\t\t// Update the AWS ACL before uploading screenshots as it might have expired\n\t\t\tawait this.screenshots.initS3ACL();\n\n\t\t\tconst allChanges: AllChangeTypes[] = await Promise.all(\n\t\t\t\targs.changes.map(async (change) => {\n\t\t\t\t\tif (change.type === \"Slice\") {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tvariationImageUrlMap: change.variationImageUrlMap,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_INSERT,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tvariationImageUrlMap: change.variationImageUrlMap,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_UPDATE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\tawait this.screenshots.deleteScreenshotFolder({\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_INSERT,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Compute the POST body\n\t\t\tconst requestBody: PushBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./push\", API_ENDPOINTS.SliceMachineV1),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: repositoryName,\n\t\t\t});\n\n\t\t\tswitch (response.status) {\n\t\t\t\tcase 202:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.SOFT,\n\t\t\t\t\t);\n\t\t\t\tcase 204:\n\t\t\t\t\treturn null;\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.HARD,\n\t\t\t\t\t);\n\t\t\t\tcase 400:\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tthrow new Error(text);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected status code ${response.status}`, {\n\t\t\t\t\t\tcause: await response.text(),\n\t\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\"An error happened while pushing your changes\");\n\t\t\tconsole.error(err);\n\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync fetchEnvironments(\n\t\targs?: PrismicRepositoryManagerFetchEnvironmentsArgs,\n\t): Promise<PrismicRepositoryManagerFetchEnvironmentsReturnType> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\n\t\t\tconst { value, error } = decode(\n\t\t\t\tt.union([\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tresults: t.array(Environment),\n\t\t\t\t\t}),\n\t\t\t\t\tt.type({\n\t\t\t\t\t\terror: t.literal(\"invalid_token\"),\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode environments: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\"results\" in value) {\n\t\t\t\tlet environments = value.results;\n\n\t\t\t\tif (!args?.includeAll) {\n\t\t\t\t\tconst profile = await this.user.getProfile();\n\n\t\t\t\t\tenvironments = environments.filter((environment) =>\n\t\t\t\t\t\tenvironment.users.some((user) => user.id === profile.shortId),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { environments: sortEnvironments(environments) };\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch environments.\");\n\t\t}\n\t}\n\n\tasync fetchOnboarding(): Promise<OnboardingState> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(OnboardingState, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch onboarding.\");\n\t\t}\n\t}\n\n\tasync toggleOnboardingStep(\n\t\tstepId: string,\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\n\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding step toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding step.\");\n\t\t}\n\t}\n\n\tasync completeOnboardingStep(\n\t\t...stepIds: string[]\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst currentState = await this.fetchOnboarding();\n\t\tconst incompleteSteps = stepIds.filter(\n\t\t\t(stepId) => !currentState.completedSteps.includes(stepId),\n\t\t);\n\n\t\tif (incompleteSteps.length > 0) {\n\t\t\t// TODO: Refactor when the API accepts multiple steps (DT-2389)\n\t\t\tfor await (const stepId of incompleteSteps) {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\t\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\t\t\tif (res.ok) {\n\t\t\t\t\tconst json = await res.json();\n\t\t\t\t\tconst { value, error } = decode(\n\t\t\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\t\t\tjson,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\t\t`Failed to decode onboarding step complete response: ${error.errors.join(\n\t\t\t\t\t\t\t\t\", \",\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tcurrentState.completedSteps = value.completedSteps;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch (res.status) {\n\t\t\t\t\tcase 400:\n\t\t\t\t\tcase 401:\n\t\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\t\tcase 403:\n\t\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\"Failed to complete onboarding step.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { completedSteps: currentState.completedSteps };\n\t}\n\n\tasync toggleOnboarding(): Promise<{ isDismissed: boolean }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding/toggle\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ isDismissed: z.boolean() }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding guide.\");\n\t\t}\n\t}\n\n\tasync setDefaultMasterLocale(): Promise<void> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./repository/locales\", API_ENDPOINTS.LocaleService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tid: \"en-us\",\n\t\t\t\tisMaster: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 400:\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(\"Failed to set main content language.\", {\n\t\t\t\t\t\tcause: text,\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: PushChangesLimitType,\n\t): PushChangesLimit | null {\n\t\treturn fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(\n\t\t\t() => {\n\t\t\t\tconst error: ClientError = {\n\t\t\t\t\tstatus: statusCode,\n\t\t\t\t\tmessage: `Unable to parse raw limit from ${JSON.stringify(\n\t\t\t\t\t\tpotentialLimit,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(rawLimit: PushChangesRawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(PushChangesRawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\" | \"PATCH\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t\tskipAuthentication?: boolean;\n\t}): Promise<Response> {\n\t\tlet cookies;\n\t\ttry {\n\t\t\tcookies = await this.user.getAuthenticationCookies();\n\t\t} catch (e) {\n\t\t\tif (!args.skipAuthentication) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tconst extraHeaders: Record<string, string> = {};\n\n\t\tif (args.body) {\n\t\t\textraHeaders[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\textraHeaders.repository = args.repository;\n\t\t}\n\n\t\treturn await fetch(args.url.toString(), {\n\t\t\tmethod: args.method,\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\t// Some endpoints rely on the authorization header...\n\n\t\t\t\t...(cookies !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\t\t\t\tCookie: serializeCookies(cookies),\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...extraHeaders,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["BaseManager","API_ENDPOINTS","decode","t","PrismicRepository","PrismicRepositoryRole","PrismicRepositoryUserAgent","REPOSITORY_NAME_VALIDATION","assertPluginsInitialized","UnauthenticatedError","ChangeTypes","PushChangesLimitType","Environment","UnexpectedDataError","sortEnvironments","UnauthorizedError","OnboardingState","z","fold","PushChangesRawLimit","fetch","serializeCookies","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,8BAA8B;AAAA,EACnC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;;AAwCD,MAAO,iCAAiCA,YAAAA,YAAW;AAAA;AAAA;AAAA,EAIxD,MAAM,UAAO;AACZ,UAAM,MAAM,IAAI,IAAI,kBAAkBC,4BAAc,WAAW;A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AAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAGR,GAAI,YAAY,SACb;AAAA,UACA,eAAe,UAAU,QAAQ,cAAc,CAAC;AAAA,UAChD,QAAQC,kCAAiB,OAAO;AAAA,QAAA,IAEhC;QACH,cAAc,KAAK,aAAaC,yBAAA;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;;"}
1
+ {"version":3,"file":"PrismicRepositoryManager.cjs","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { z } from \"zod\";\nimport fetch, { Response } from \"../../lib/fetch\";\nimport { fold } from \"fp-ts/Either\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decode } from \"../../lib/decode\";\nimport { serializeCookies } from \"../../lib/serializeCookies\";\n\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { REPOSITORY_NAME_VALIDATION } from \"../../constants/REPOSITORY_NAME_VALIDATION\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tPushBody,\n\tChangeTypes,\n\tClientError,\n\tPushChangesLimit,\n\tPushChangesLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tPushChangesRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n\tFrameworkWroomTelemetryID,\n\tStarterId,\n\tEnvironment,\n\tOnboardingState,\n} from \"./types\";\nimport { sortEnvironments } from \"./sortEnvironments\";\n\nconst DEFAULT_REPOSITORY_SETTINGS = {\n\tplan: \"personal\",\n\tisAnnual: \"false\",\n\trole: \"developer\",\n};\n\ntype PrismicRepositoryManagerCheckExistsArgs = {\n\tdomain: string;\n};\n\ntype PrismicRepositoryManagerCreateArgs = {\n\tdomain: string;\n\tframework: FrameworkWroomTelemetryID;\n\tstarterId?: StarterId;\n};\n\ntype PrismicRepositoryManagerDeleteArgs = {\n\tdomain: string;\n\tpassword: string;\n};\n\ntype PrismicRepositoryManagerPushDocumentsArgs = {\n\tdomain: string;\n\tsignature: string;\n\tdocuments: Record<string, unknown>; // TODO: Type unknown if possible(?)\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsArgs = {\n\t/**\n\t * If set to `true`, all environments are returned regardless of the user's\n\t * permission level.\n\t *\n\t * If set to `false`, only environments the user can access are returned.\n\t *\n\t * @defaultValue `false`\n\t */\n\tincludeAll?: boolean;\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsReturnType = {\n\tenvironments?: Environment[];\n};\n\nexport class PrismicRepositoryManager extends BaseManager {\n\t// TODO: Add methods for repository-specific actions. E.g. creating a\n\t// new repository.\n\n\tasync readAll(): Promise<PrismicRepository[]> {\n\t\tconst url = new URL(\"./repositories\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value: repositories, error } = decode(\n\t\t\t\tt.array(PrismicRepository),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to decode repositories: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn repositories;\n\t\t} else {\n\t\t\tconst text = await res.text();\n\t\t\tthrow new Error(`Failed to read repositories`, { cause: text });\n\t\t}\n\t}\n\n\t// Should this be in manager? It's one of the few sync method\n\t//\n\t// Reply from Angelo 2022-12-22: I think it should be in manager\n\t// because we shouldn't be exporting root-level utilities from this\n\t// package. If we want to make it more inline with the other methods,\n\t// we could simplify the API by changing its signature to the\n\t// following:\n\t//\n\t// ```ts\n\t// (repositoryName: string) => Promise<boolean>\n\t// ```\n\t//\n\t// This method would:\n\t//\n\t// 1. Fetch the list of repositories for the user using `readAll()`.\n\t// The list would be cached.\n\t// 2. Determine if the user has write access to the given repository.\n\t//\n\t// This version has the following benefits:\n\t//\n\t// - Does not expect the consumer to supply a repository object; it\n\t// only requires a repository name, which could be sourced from\n\t// anything (incl. the project's `slicemachine.config.json`).\n\t//\n\t// - Similarly, it does not expect the consumer to call `readAll()`\n\t// before calling this method.\n\t//\n\t// - Works for repositories that the user does not have access to. For\n\t// example, I could use it to check if I have access to \"qwerty\",\n\t// even if I am not added as a user. The purpose of the method is\n\t// still valid: do I have write access to a given repository?\n\thasWriteAccess(repository: PrismicRepository): boolean {\n\t\tswitch (repository.role) {\n\t\t\tcase PrismicRepositoryRole.SuperUser:\n\t\t\tcase PrismicRepositoryRole.Owner:\n\t\t\tcase PrismicRepositoryRole.Administrator:\n\t\t\t\treturn true;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync checkExists(\n\t\targs: PrismicRepositoryManagerCheckExistsArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t`./app/dashboard/repositories/${args.domain}/exists`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tskipAuthentication: true,\n\t\t});\n\n\t\tconst text = await res.text();\n\n\t\tif (res.ok) {\n\t\t\treturn text === \"false\"; // Endpoint returns `false` when repository exists\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to check repository existence for domain \\`${args.domain}\\``,\n\t\t\t\t{ cause: text },\n\t\t\t);\n\t\t}\n\t}\n\n\tasync create(args: PrismicRepositoryManagerCreateArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./authentication/newrepository?app=slicemachine\",\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\n\t\tconst body = {\n\t\t\t...DEFAULT_REPOSITORY_SETTINGS,\n\t\t\tdomain: args.domain,\n\t\t\t// These properties are optional in the API but needed for tracking\n\t\t\tframework: args.framework,\n\t\t\tstarterId: args.starterId,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.SliceMachine, // Custom User Agent is required\n\t\t});\n\t\tconst text = await res.text();\n\n\t\t// Endpoint returns repository name on success, that should be within the validation range\n\t\t// Even when there is an error, we get a 200 success and so we have to check the name thanks to that\n\t\tif (\n\t\t\t!res.ok ||\n\t\t\ttext.length < REPOSITORY_NAME_VALIDATION.Min ||\n\t\t\ttext.length > REPOSITORY_NAME_VALIDATION.Max\n\t\t) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: text,\n\t\t\t});\n\t\t}\n\t}\n\n\t// TODO: Delete this endpoint? It doesn't seem to be used (I might be wrong). - Angelo\n\tasync delete(args: PrismicRepositoryManagerDeleteArgs): Promise<void> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\n\n\t\tconst url = new URL(\n\t\t\t`./app/settings/delete?_=${cookies[\"X_XSRF\"]}`, // TODO: Maybe we want to throw early if the token is no available, or get the token another way\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tconfirm: args.domain,\n\t\t\tpassword: args.password,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`Failed to delete repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync pushDocuments(\n\t\targs: PrismicRepositoryManagerPushDocumentsArgs,\n\t): Promise<void> {\n\t\tconst url = new URL(\"./starter/documents\", API_ENDPOINTS.PrismicWroom);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tsignature: args.signature,\n\t\t\tdocuments: JSON.stringify(args.documents),\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tlet reason: string | null = null;\n\t\t\ttry {\n\t\t\t\treason = await res.text();\n\t\t\t} catch {\n\t\t\t\t// Noop\n\t\t\t}\n\n\t\t\t// Ideally the API should throw a 409 or something like that...\n\t\t\tif (reason === \"Repository should not contain documents\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, repository is not empty`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, ${res.status} ${res.statusText}`,\n\t\t\t\t{\n\t\t\t\t\tcause: reason,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushChanges(\n\t\targs: TransactionalMergeArgs,\n\t): Promise<TransactionalMergeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\ttry {\n\t\t\t// Update the AWS ACL before uploading screenshots as it might have expired\n\t\t\tawait this.screenshots.initS3ACL();\n\n\t\t\tconst allChanges: AllChangeTypes[] = await Promise.all(\n\t\t\t\targs.changes.map(async (change) => {\n\t\t\t\t\tif (change.type === \"Slice\") {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_INSERT,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_UPDATE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\tawait this.screenshots.deleteScreenshotFolder({\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_INSERT,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Compute the POST body\n\t\t\tconst requestBody: PushBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./push\", API_ENDPOINTS.SliceMachineV1),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: repositoryName,\n\t\t\t});\n\n\t\t\tswitch (response.status) {\n\t\t\t\tcase 202:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.SOFT,\n\t\t\t\t\t);\n\t\t\t\tcase 204:\n\t\t\t\t\treturn null;\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.HARD,\n\t\t\t\t\t);\n\t\t\t\tcase 400:\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tthrow new Error(text);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected status code ${response.status}`, {\n\t\t\t\t\t\tcause: await response.text(),\n\t\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\"An error happened while pushing your changes\");\n\t\t\tconsole.error(err);\n\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync fetchEnvironments(\n\t\targs?: PrismicRepositoryManagerFetchEnvironmentsArgs,\n\t): Promise<PrismicRepositoryManagerFetchEnvironmentsReturnType> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\n\t\t\tconst { value, error } = decode(\n\t\t\t\tt.union([\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tresults: t.array(Environment),\n\t\t\t\t\t}),\n\t\t\t\t\tt.type({\n\t\t\t\t\t\terror: t.literal(\"invalid_token\"),\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode environments: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\"results\" in value) {\n\t\t\t\tlet environments = value.results;\n\n\t\t\t\tif (!args?.includeAll) {\n\t\t\t\t\tconst profile = await this.user.getProfile();\n\n\t\t\t\t\tenvironments = environments.filter((environment) =>\n\t\t\t\t\t\tenvironment.users.some((user) => user.id === profile.shortId),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { environments: sortEnvironments(environments) };\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch environments.\");\n\t\t}\n\t}\n\n\tasync fetchOnboarding(): Promise<OnboardingState> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(OnboardingState, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch onboarding.\");\n\t\t}\n\t}\n\n\tasync toggleOnboardingStep(\n\t\tstepId: string,\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\n\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding step toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding step.\");\n\t\t}\n\t}\n\n\tasync completeOnboardingStep(\n\t\t...stepIds: string[]\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst currentState = await this.fetchOnboarding();\n\t\tconst incompleteSteps = stepIds.filter(\n\t\t\t(stepId) => !currentState.completedSteps.includes(stepId),\n\t\t);\n\n\t\tif (incompleteSteps.length > 0) {\n\t\t\t// TODO: Refactor when the API accepts multiple steps (DT-2389)\n\t\t\tfor await (const stepId of incompleteSteps) {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\t\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\t\t\tif (res.ok) {\n\t\t\t\t\tconst json = await res.json();\n\t\t\t\t\tconst { value, error } = decode(\n\t\t\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\t\t\tjson,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\t\t`Failed to decode onboarding step complete response: ${error.errors.join(\n\t\t\t\t\t\t\t\t\", \",\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tcurrentState.completedSteps = value.completedSteps;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch (res.status) {\n\t\t\t\t\tcase 400:\n\t\t\t\t\tcase 401:\n\t\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\t\tcase 403:\n\t\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\"Failed to complete onboarding step.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { completedSteps: currentState.completedSteps };\n\t}\n\n\tasync toggleOnboarding(): Promise<{ isDismissed: boolean }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding/toggle\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ isDismissed: z.boolean() }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding guide.\");\n\t\t}\n\t}\n\n\tasync setDefaultMasterLocale(): Promise<void> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./repository/locales\", API_ENDPOINTS.LocaleService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tid: \"en-us\",\n\t\t\t\tisMaster: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 400:\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(\"Failed to set main content language.\", {\n\t\t\t\t\t\tcause: text,\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: PushChangesLimitType,\n\t): PushChangesLimit | null {\n\t\treturn fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(\n\t\t\t() => {\n\t\t\t\tconst error: ClientError = {\n\t\t\t\t\tstatus: statusCode,\n\t\t\t\t\tmessage: `Unable to parse raw limit from ${JSON.stringify(\n\t\t\t\t\t\tpotentialLimit,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(rawLimit: PushChangesRawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(PushChangesRawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\" | \"PATCH\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t\tskipAuthentication?: boolean;\n\t}): Promise<Response> {\n\t\tlet cookies;\n\t\ttry {\n\t\t\tcookies = await this.user.getAuthenticationCookies();\n\t\t} catch (e) {\n\t\t\tif (!args.skipAuthentication) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tconst extraHeaders: Record<string, string> = {};\n\n\t\tif (args.body) {\n\t\t\textraHeaders[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\textraHeaders.repository = args.repository;\n\t\t}\n\n\t\treturn await fetch(args.url.toString(), {\n\t\t\tmethod: args.method,\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\t// Some endpoints rely on the authorization header...\n\n\t\t\t\t...(cookies !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\t\t\t\tCookie: serializeCookies(cookies),\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...extraHeaders,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["BaseManager","API_ENDPOINTS","decode","t","PrismicRepository","PrismicRepositoryRole","PrismicRepositoryUserAgent","REPOSITORY_NAME_VALIDATION","assertPluginsInitialized","UnauthenticatedError","ChangeTypes","PushChangesLimitType","Environment","UnexpectedDataError","sortEnvironments","UnauthorizedError","OnboardingState","z","fold","PushChangesRawLimit","fetch","serializeCookies","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,8BAA8B;AAAA,EACnC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;;AAwCD,MAAO,iCAAiCA,YAAAA,YAAW;AAAA;AAAA;AAAA,EAIxD,MAAM,UAAO;AACZ,UAAM,MAAM,IAAI,IAAI,kBAAkBC,4BAAc,WAAW;AAC/D,UAAM,MAAM,MAAM,KAAK,OAAO,EAAE,IAAK,CAAA;AAErC,QAAI,IAAI,IAAI;AACL,YAAA,OAAO,MAAM,IAAI;AACjB,YAAA,EAAE,OAAO,cAAc,UAAUC,OAAAA,OACtCC,aAAE,MAAMC,MAAAA,iBAAiB,GACzB,IAAI;AAGL,UAAI,OAAO;AACJ,cAAA,IAAI,MACT,kCAAkC,MAAM,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,MAE7D;AAEO,aAAA;AAAA,IAAA,OACD;AACA,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MAAM,+BAA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;AAAA,MACH;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,oBACP,gBACA,YACA,WAA+B;AAE/B,WAAOG,YACN,MAAK;AACJ,YAAM,QAAqB;AAAA,QAC1B,QAAQ;AAAA,QACR,SAAS,kCAAkC,KAAK,UAC/C,cAAc,CACd;AAAA,MAAA;AAEI,YAAA;AAAA,IACP,GACA,CAAC,aAAiC;AACjC,YAAM,QAAQ,EAAE,GAAG,UAAU,MAAM,UAAS;AAErC,aAAA;AAAA,IACP,CAAA,EACAC,MAAoB,oBAAA,OAAO,cAAc,CAAC;AAAA,EAC7C;AAAA,EAEQ,MAAM,OAAO,MAOpB;AACI,QAAA;AACA,QAAA;AACO,gBAAA,MAAM,KAAK,KAAK;aAClB,GAAG;AACP,UAAA,CAAC,KAAK,oBAAoB;AACvB,cAAA;AAAA,MACP;AAAA,IACD;AAEA,UAAM,eAAuC,CAAA;AAE7C,QAAI,KAAK,MAAM;AACd,mBAAa,cAAc,IAAI;AAAA,IAChC;AAEA,QAAI,KAAK,YAAY;AACpB,mBAAa,aAAa,KAAK;AAAA,IAChC;AAEA,WAAO,MAAMC,MAAAA,QAAM,KAAK,IAAI,YAAY;AAAA,MACvC,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAGR,GAAI,YAAY,SACb;AAAA,UACA,eAAe,UAAU,QAAQ,cAAc,CAAC;AAAA,UAChD,QAAQC,kCAAiB,OAAO;AAAA,QAAA,IAEhC;QACH,cAAc,KAAK,aAAaC,yBAAA;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;;"}
@@ -188,7 +188,6 @@ class PrismicRepositoryManager extends BaseManager {
188
188
  }
189
189
  const modelWithScreenshots = await this.slices.updateSliceModelScreenshotsInPlace({
190
190
  libraryID: change.libraryID,
191
- variationImageUrlMap: change.variationImageUrlMap,
192
191
  model
193
192
  });
194
193
  return {
@@ -207,7 +206,6 @@ class PrismicRepositoryManager extends BaseManager {
207
206
  }
208
207
  const modelWithScreenshots = await this.slices.updateSliceModelScreenshotsInPlace({
209
208
  libraryID: change.libraryID,
210
- variationImageUrlMap: change.variationImageUrlMap,
211
209
  model
212
210
  });
213
211
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRepositoryManager.js","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { z } from \"zod\";\nimport fetch, { Response } from \"../../lib/fetch\";\nimport { fold } from \"fp-ts/Either\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decode } from \"../../lib/decode\";\nimport { serializeCookies } from \"../../lib/serializeCookies\";\n\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { REPOSITORY_NAME_VALIDATION } from \"../../constants/REPOSITORY_NAME_VALIDATION\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tPushBody,\n\tChangeTypes,\n\tClientError,\n\tPushChangesLimit,\n\tPushChangesLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tPushChangesRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n\tFrameworkWroomTelemetryID,\n\tStarterId,\n\tEnvironment,\n\tOnboardingState,\n} from \"./types\";\nimport { sortEnvironments } from \"./sortEnvironments\";\n\nconst DEFAULT_REPOSITORY_SETTINGS = {\n\tplan: \"personal\",\n\tisAnnual: \"false\",\n\trole: \"developer\",\n};\n\ntype PrismicRepositoryManagerCheckExistsArgs = {\n\tdomain: string;\n};\n\ntype PrismicRepositoryManagerCreateArgs = {\n\tdomain: string;\n\tframework: FrameworkWroomTelemetryID;\n\tstarterId?: StarterId;\n};\n\ntype PrismicRepositoryManagerDeleteArgs = {\n\tdomain: string;\n\tpassword: string;\n};\n\ntype PrismicRepositoryManagerPushDocumentsArgs = {\n\tdomain: string;\n\tsignature: string;\n\tdocuments: Record<string, unknown>; // TODO: Type unknown if possible(?)\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsArgs = {\n\t/**\n\t * If set to `true`, all environments are returned regardless of the user's\n\t * permission level.\n\t *\n\t * If set to `false`, only environments the user can access are returned.\n\t *\n\t * @defaultValue `false`\n\t */\n\tincludeAll?: boolean;\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsReturnType = {\n\tenvironments?: Environment[];\n};\n\nexport class PrismicRepositoryManager extends BaseManager {\n\t// TODO: Add methods for repository-specific actions. E.g. creating a\n\t// new repository.\n\n\tasync readAll(): Promise<PrismicRepository[]> {\n\t\tconst url = new URL(\"./repositories\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value: repositories, error } = decode(\n\t\t\t\tt.array(PrismicRepository),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to decode repositories: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn repositories;\n\t\t} else {\n\t\t\tconst text = await res.text();\n\t\t\tthrow new Error(`Failed to read repositories`, { cause: text });\n\t\t}\n\t}\n\n\t// Should this be in manager? It's one of the few sync method\n\t//\n\t// Reply from Angelo 2022-12-22: I think it should be in manager\n\t// because we shouldn't be exporting root-level utilities from this\n\t// package. If we want to make it more inline with the other methods,\n\t// we could simplify the API by changing its signature to the\n\t// following:\n\t//\n\t// ```ts\n\t// (repositoryName: string) => Promise<boolean>\n\t// ```\n\t//\n\t// This method would:\n\t//\n\t// 1. Fetch the list of repositories for the user using `readAll()`.\n\t// The list would be cached.\n\t// 2. Determine if the user has write access to the given repository.\n\t//\n\t// This version has the following benefits:\n\t//\n\t// - Does not expect the consumer to supply a repository object; it\n\t// only requires a repository name, which could be sourced from\n\t// anything (incl. the project's `slicemachine.config.json`).\n\t//\n\t// - Similarly, it does not expect the consumer to call `readAll()`\n\t// before calling this method.\n\t//\n\t// - Works for repositories that the user does not have access to. For\n\t// example, I could use it to check if I have access to \"qwerty\",\n\t// even if I am not added as a user. The purpose of the method is\n\t// still valid: do I have write access to a given repository?\n\thasWriteAccess(repository: PrismicRepository): boolean {\n\t\tswitch (repository.role) {\n\t\t\tcase PrismicRepositoryRole.SuperUser:\n\t\t\tcase PrismicRepositoryRole.Owner:\n\t\t\tcase PrismicRepositoryRole.Administrator:\n\t\t\t\treturn true;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync checkExists(\n\t\targs: PrismicRepositoryManagerCheckExistsArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t`./app/dashboard/repositories/${args.domain}/exists`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tskipAuthentication: true,\n\t\t});\n\n\t\tconst text = await res.text();\n\n\t\tif (res.ok) {\n\t\t\treturn text === \"false\"; // Endpoint returns `false` when repository exists\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to check repository existence for domain \\`${args.domain}\\``,\n\t\t\t\t{ cause: text },\n\t\t\t);\n\t\t}\n\t}\n\n\tasync create(args: PrismicRepositoryManagerCreateArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./authentication/newrepository?app=slicemachine\",\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\n\t\tconst body = {\n\t\t\t...DEFAULT_REPOSITORY_SETTINGS,\n\t\t\tdomain: args.domain,\n\t\t\t// These properties are optional in the API but needed for tracking\n\t\t\tframework: args.framework,\n\t\t\tstarterId: args.starterId,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.SliceMachine, // Custom User Agent is required\n\t\t});\n\t\tconst text = await res.text();\n\n\t\t// Endpoint returns repository name on success, that should be within the validation range\n\t\t// Even when there is an error, we get a 200 success and so we have to check the name thanks to that\n\t\tif (\n\t\t\t!res.ok ||\n\t\t\ttext.length < REPOSITORY_NAME_VALIDATION.Min ||\n\t\t\ttext.length > REPOSITORY_NAME_VALIDATION.Max\n\t\t) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: text,\n\t\t\t});\n\t\t}\n\t}\n\n\t// TODO: Delete this endpoint? It doesn't seem to be used (I might be wrong). - Angelo\n\tasync delete(args: PrismicRepositoryManagerDeleteArgs): Promise<void> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\n\n\t\tconst url = new URL(\n\t\t\t`./app/settings/delete?_=${cookies[\"X_XSRF\"]}`, // TODO: Maybe we want to throw early if the token is no available, or get the token another way\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tconfirm: args.domain,\n\t\t\tpassword: args.password,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`Failed to delete repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync pushDocuments(\n\t\targs: PrismicRepositoryManagerPushDocumentsArgs,\n\t): Promise<void> {\n\t\tconst url = new URL(\"./starter/documents\", API_ENDPOINTS.PrismicWroom);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tsignature: args.signature,\n\t\t\tdocuments: JSON.stringify(args.documents),\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tlet reason: string | null = null;\n\t\t\ttry {\n\t\t\t\treason = await res.text();\n\t\t\t} catch {\n\t\t\t\t// Noop\n\t\t\t}\n\n\t\t\t// Ideally the API should throw a 409 or something like that...\n\t\t\tif (reason === \"Repository should not contain documents\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, repository is not empty`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, ${res.status} ${res.statusText}`,\n\t\t\t\t{\n\t\t\t\t\tcause: reason,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushChanges(\n\t\targs: TransactionalMergeArgs,\n\t): Promise<TransactionalMergeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\ttry {\n\t\t\t// Update the AWS ACL before uploading screenshots as it might have expired\n\t\t\tawait this.screenshots.initS3ACL();\n\n\t\t\tconst allChanges: AllChangeTypes[] = await Promise.all(\n\t\t\t\targs.changes.map(async (change) => {\n\t\t\t\t\tif (change.type === \"Slice\") {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tvariationImageUrlMap: change.variationImageUrlMap,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_INSERT,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tvariationImageUrlMap: change.variationImageUrlMap,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_UPDATE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\tawait this.screenshots.deleteScreenshotFolder({\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_INSERT,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Compute the POST body\n\t\t\tconst requestBody: PushBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./push\", API_ENDPOINTS.SliceMachineV1),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: repositoryName,\n\t\t\t});\n\n\t\t\tswitch (response.status) {\n\t\t\t\tcase 202:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.SOFT,\n\t\t\t\t\t);\n\t\t\t\tcase 204:\n\t\t\t\t\treturn null;\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.HARD,\n\t\t\t\t\t);\n\t\t\t\tcase 400:\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tthrow new Error(text);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected status code ${response.status}`, {\n\t\t\t\t\t\tcause: await response.text(),\n\t\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\"An error happened while pushing your changes\");\n\t\t\tconsole.error(err);\n\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync fetchEnvironments(\n\t\targs?: PrismicRepositoryManagerFetchEnvironmentsArgs,\n\t): Promise<PrismicRepositoryManagerFetchEnvironmentsReturnType> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\n\t\t\tconst { value, error } = decode(\n\t\t\t\tt.union([\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tresults: t.array(Environment),\n\t\t\t\t\t}),\n\t\t\t\t\tt.type({\n\t\t\t\t\t\terror: t.literal(\"invalid_token\"),\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode environments: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\"results\" in value) {\n\t\t\t\tlet environments = value.results;\n\n\t\t\t\tif (!args?.includeAll) {\n\t\t\t\t\tconst profile = await this.user.getProfile();\n\n\t\t\t\t\tenvironments = environments.filter((environment) =>\n\t\t\t\t\t\tenvironment.users.some((user) => user.id === profile.shortId),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { environments: sortEnvironments(environments) };\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch environments.\");\n\t\t}\n\t}\n\n\tasync fetchOnboarding(): Promise<OnboardingState> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(OnboardingState, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch onboarding.\");\n\t\t}\n\t}\n\n\tasync toggleOnboardingStep(\n\t\tstepId: string,\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\n\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding step toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding step.\");\n\t\t}\n\t}\n\n\tasync completeOnboardingStep(\n\t\t...stepIds: string[]\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst currentState = await this.fetchOnboarding();\n\t\tconst incompleteSteps = stepIds.filter(\n\t\t\t(stepId) => !currentState.completedSteps.includes(stepId),\n\t\t);\n\n\t\tif (incompleteSteps.length > 0) {\n\t\t\t// TODO: Refactor when the API accepts multiple steps (DT-2389)\n\t\t\tfor await (const stepId of incompleteSteps) {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\t\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\t\t\tif (res.ok) {\n\t\t\t\t\tconst json = await res.json();\n\t\t\t\t\tconst { value, error } = decode(\n\t\t\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\t\t\tjson,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\t\t`Failed to decode onboarding step complete response: ${error.errors.join(\n\t\t\t\t\t\t\t\t\", \",\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tcurrentState.completedSteps = value.completedSteps;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch (res.status) {\n\t\t\t\t\tcase 400:\n\t\t\t\t\tcase 401:\n\t\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\t\tcase 403:\n\t\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\"Failed to complete onboarding step.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { completedSteps: currentState.completedSteps };\n\t}\n\n\tasync toggleOnboarding(): Promise<{ isDismissed: boolean }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding/toggle\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ isDismissed: z.boolean() }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding guide.\");\n\t\t}\n\t}\n\n\tasync setDefaultMasterLocale(): Promise<void> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./repository/locales\", API_ENDPOINTS.LocaleService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tid: \"en-us\",\n\t\t\t\tisMaster: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 400:\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(\"Failed to set main content language.\", {\n\t\t\t\t\t\tcause: text,\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: PushChangesLimitType,\n\t): PushChangesLimit | null {\n\t\treturn fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(\n\t\t\t() => {\n\t\t\t\tconst error: ClientError = {\n\t\t\t\t\tstatus: statusCode,\n\t\t\t\t\tmessage: `Unable to parse raw limit from ${JSON.stringify(\n\t\t\t\t\t\tpotentialLimit,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(rawLimit: PushChangesRawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(PushChangesRawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\" | \"PATCH\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t\tskipAuthentication?: boolean;\n\t}): Promise<Response> {\n\t\tlet cookies;\n\t\ttry {\n\t\t\tcookies = await this.user.getAuthenticationCookies();\n\t\t} catch (e) {\n\t\t\tif (!args.skipAuthentication) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tconst extraHeaders: Record<string, string> = {};\n\n\t\tif (args.body) {\n\t\t\textraHeaders[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\textraHeaders.repository = args.repository;\n\t\t}\n\n\t\treturn await fetch(args.url.toString(), {\n\t\t\tmethod: args.method,\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\t// Some endpoints rely on the authorization header...\n\n\t\t\t\t...(cookies !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\t\t\t\tCookie: serializeCookies(cookies),\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...extraHeaders,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,8BAA8B;AAAA,EACnC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;;AAwCD,MAAO,iCAAiC,YAAW;AAAA;AAAA;AAAA,EAIxD,MAAM,UAAO;AACZ,UAAM,MAAM,IAAI,IAAI,kBAAkB,cAAc,WAAW;AAC/D,UAAM,MAAM,MAAM,KAAK,OAAO,EAAE,IAAK,CAAA;AAErC,QAAI,IAAI,IAAI;AACL,YAAA,OAAO,MAAM,IAAI;AACjB,YAAA,EAAE,OAAO,cAAc,UAAU,OACtC,EAAE,MAAM,iBAAiB,GACzB,IAAI;AAGL,UAAI,OAAO;AACJ,cAAA,IAAI,MACT,kCAAkC,MAAM,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,MAE7D;AAEO,aAAA;AAAA,IAAA,OACD;AACA,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM;AAAA,IAC/D;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiCA,eAAe,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KAAK,YAAY;AACpB,mBAAa,aAAa,KAAK;AAAA,IAChC;AAEA,WAAO,MAAM,MAAM,KAAK,IAAI,YAAY;AAAA,MACvC,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAGR,GAAI,YAAY,SACb;AAAA,UACA,eAAe,UAAU,QAAQ,cAAc,CAAC;AAAA,UAChD,QAAQ,iBAAiB,OAAO;AAAA,QAAA,IAEhC;QACH,cAAc,KAAK,aAAa;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;"}
1
+ {"version":3,"file":"PrismicRepositoryManager.js","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { z } from \"zod\";\nimport fetch, { Response } from \"../../lib/fetch\";\nimport { fold } from \"fp-ts/Either\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decode } from \"../../lib/decode\";\nimport { serializeCookies } from \"../../lib/serializeCookies\";\n\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { REPOSITORY_NAME_VALIDATION } from \"../../constants/REPOSITORY_NAME_VALIDATION\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tPushBody,\n\tChangeTypes,\n\tClientError,\n\tPushChangesLimit,\n\tPushChangesLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tPushChangesRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n\tFrameworkWroomTelemetryID,\n\tStarterId,\n\tEnvironment,\n\tOnboardingState,\n} from \"./types\";\nimport { sortEnvironments } from \"./sortEnvironments\";\n\nconst DEFAULT_REPOSITORY_SETTINGS = {\n\tplan: \"personal\",\n\tisAnnual: \"false\",\n\trole: \"developer\",\n};\n\ntype PrismicRepositoryManagerCheckExistsArgs = {\n\tdomain: string;\n};\n\ntype PrismicRepositoryManagerCreateArgs = {\n\tdomain: string;\n\tframework: FrameworkWroomTelemetryID;\n\tstarterId?: StarterId;\n};\n\ntype PrismicRepositoryManagerDeleteArgs = {\n\tdomain: string;\n\tpassword: string;\n};\n\ntype PrismicRepositoryManagerPushDocumentsArgs = {\n\tdomain: string;\n\tsignature: string;\n\tdocuments: Record<string, unknown>; // TODO: Type unknown if possible(?)\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsArgs = {\n\t/**\n\t * If set to `true`, all environments are returned regardless of the user's\n\t * permission level.\n\t *\n\t * If set to `false`, only environments the user can access are returned.\n\t *\n\t * @defaultValue `false`\n\t */\n\tincludeAll?: boolean;\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsReturnType = {\n\tenvironments?: Environment[];\n};\n\nexport class PrismicRepositoryManager extends BaseManager {\n\t// TODO: Add methods for repository-specific actions. E.g. creating a\n\t// new repository.\n\n\tasync readAll(): Promise<PrismicRepository[]> {\n\t\tconst url = new URL(\"./repositories\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value: repositories, error } = decode(\n\t\t\t\tt.array(PrismicRepository),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to decode repositories: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn repositories;\n\t\t} else {\n\t\t\tconst text = await res.text();\n\t\t\tthrow new Error(`Failed to read repositories`, { cause: text });\n\t\t}\n\t}\n\n\t// Should this be in manager? It's one of the few sync method\n\t//\n\t// Reply from Angelo 2022-12-22: I think it should be in manager\n\t// because we shouldn't be exporting root-level utilities from this\n\t// package. If we want to make it more inline with the other methods,\n\t// we could simplify the API by changing its signature to the\n\t// following:\n\t//\n\t// ```ts\n\t// (repositoryName: string) => Promise<boolean>\n\t// ```\n\t//\n\t// This method would:\n\t//\n\t// 1. Fetch the list of repositories for the user using `readAll()`.\n\t// The list would be cached.\n\t// 2. Determine if the user has write access to the given repository.\n\t//\n\t// This version has the following benefits:\n\t//\n\t// - Does not expect the consumer to supply a repository object; it\n\t// only requires a repository name, which could be sourced from\n\t// anything (incl. the project's `slicemachine.config.json`).\n\t//\n\t// - Similarly, it does not expect the consumer to call `readAll()`\n\t// before calling this method.\n\t//\n\t// - Works for repositories that the user does not have access to. For\n\t// example, I could use it to check if I have access to \"qwerty\",\n\t// even if I am not added as a user. The purpose of the method is\n\t// still valid: do I have write access to a given repository?\n\thasWriteAccess(repository: PrismicRepository): boolean {\n\t\tswitch (repository.role) {\n\t\t\tcase PrismicRepositoryRole.SuperUser:\n\t\t\tcase PrismicRepositoryRole.Owner:\n\t\t\tcase PrismicRepositoryRole.Administrator:\n\t\t\t\treturn true;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync checkExists(\n\t\targs: PrismicRepositoryManagerCheckExistsArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t`./app/dashboard/repositories/${args.domain}/exists`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tskipAuthentication: true,\n\t\t});\n\n\t\tconst text = await res.text();\n\n\t\tif (res.ok) {\n\t\t\treturn text === \"false\"; // Endpoint returns `false` when repository exists\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to check repository existence for domain \\`${args.domain}\\``,\n\t\t\t\t{ cause: text },\n\t\t\t);\n\t\t}\n\t}\n\n\tasync create(args: PrismicRepositoryManagerCreateArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./authentication/newrepository?app=slicemachine\",\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\n\t\tconst body = {\n\t\t\t...DEFAULT_REPOSITORY_SETTINGS,\n\t\t\tdomain: args.domain,\n\t\t\t// These properties are optional in the API but needed for tracking\n\t\t\tframework: args.framework,\n\t\t\tstarterId: args.starterId,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.SliceMachine, // Custom User Agent is required\n\t\t});\n\t\tconst text = await res.text();\n\n\t\t// Endpoint returns repository name on success, that should be within the validation range\n\t\t// Even when there is an error, we get a 200 success and so we have to check the name thanks to that\n\t\tif (\n\t\t\t!res.ok ||\n\t\t\ttext.length < REPOSITORY_NAME_VALIDATION.Min ||\n\t\t\ttext.length > REPOSITORY_NAME_VALIDATION.Max\n\t\t) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: text,\n\t\t\t});\n\t\t}\n\t}\n\n\t// TODO: Delete this endpoint? It doesn't seem to be used (I might be wrong). - Angelo\n\tasync delete(args: PrismicRepositoryManagerDeleteArgs): Promise<void> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\n\n\t\tconst url = new URL(\n\t\t\t`./app/settings/delete?_=${cookies[\"X_XSRF\"]}`, // TODO: Maybe we want to throw early if the token is no available, or get the token another way\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tconfirm: args.domain,\n\t\t\tpassword: args.password,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`Failed to delete repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync pushDocuments(\n\t\targs: PrismicRepositoryManagerPushDocumentsArgs,\n\t): Promise<void> {\n\t\tconst url = new URL(\"./starter/documents\", API_ENDPOINTS.PrismicWroom);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tsignature: args.signature,\n\t\t\tdocuments: JSON.stringify(args.documents),\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tlet reason: string | null = null;\n\t\t\ttry {\n\t\t\t\treason = await res.text();\n\t\t\t} catch {\n\t\t\t\t// Noop\n\t\t\t}\n\n\t\t\t// Ideally the API should throw a 409 or something like that...\n\t\t\tif (reason === \"Repository should not contain documents\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, repository is not empty`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, ${res.status} ${res.statusText}`,\n\t\t\t\t{\n\t\t\t\t\tcause: reason,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushChanges(\n\t\targs: TransactionalMergeArgs,\n\t): Promise<TransactionalMergeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\ttry {\n\t\t\t// Update the AWS ACL before uploading screenshots as it might have expired\n\t\t\tawait this.screenshots.initS3ACL();\n\n\t\t\tconst allChanges: AllChangeTypes[] = await Promise.all(\n\t\t\t\targs.changes.map(async (change) => {\n\t\t\t\t\tif (change.type === \"Slice\") {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_INSERT,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_UPDATE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\tawait this.screenshots.deleteScreenshotFolder({\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_INSERT,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Compute the POST body\n\t\t\tconst requestBody: PushBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./push\", API_ENDPOINTS.SliceMachineV1),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: repositoryName,\n\t\t\t});\n\n\t\t\tswitch (response.status) {\n\t\t\t\tcase 202:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.SOFT,\n\t\t\t\t\t);\n\t\t\t\tcase 204:\n\t\t\t\t\treturn null;\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.HARD,\n\t\t\t\t\t);\n\t\t\t\tcase 400:\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tthrow new Error(text);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected status code ${response.status}`, {\n\t\t\t\t\t\tcause: await response.text(),\n\t\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\"An error happened while pushing your changes\");\n\t\t\tconsole.error(err);\n\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync fetchEnvironments(\n\t\targs?: PrismicRepositoryManagerFetchEnvironmentsArgs,\n\t): Promise<PrismicRepositoryManagerFetchEnvironmentsReturnType> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\n\t\t\tconst { value, error } = decode(\n\t\t\t\tt.union([\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tresults: t.array(Environment),\n\t\t\t\t\t}),\n\t\t\t\t\tt.type({\n\t\t\t\t\t\terror: t.literal(\"invalid_token\"),\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode environments: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\"results\" in value) {\n\t\t\t\tlet environments = value.results;\n\n\t\t\t\tif (!args?.includeAll) {\n\t\t\t\t\tconst profile = await this.user.getProfile();\n\n\t\t\t\t\tenvironments = environments.filter((environment) =>\n\t\t\t\t\t\tenvironment.users.some((user) => user.id === profile.shortId),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { environments: sortEnvironments(environments) };\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch environments.\");\n\t\t}\n\t}\n\n\tasync fetchOnboarding(): Promise<OnboardingState> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(OnboardingState, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch onboarding.\");\n\t\t}\n\t}\n\n\tasync toggleOnboardingStep(\n\t\tstepId: string,\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\n\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding step toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding step.\");\n\t\t}\n\t}\n\n\tasync completeOnboardingStep(\n\t\t...stepIds: string[]\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst currentState = await this.fetchOnboarding();\n\t\tconst incompleteSteps = stepIds.filter(\n\t\t\t(stepId) => !currentState.completedSteps.includes(stepId),\n\t\t);\n\n\t\tif (incompleteSteps.length > 0) {\n\t\t\t// TODO: Refactor when the API accepts multiple steps (DT-2389)\n\t\t\tfor await (const stepId of incompleteSteps) {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\t\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\t\t\tif (res.ok) {\n\t\t\t\t\tconst json = await res.json();\n\t\t\t\t\tconst { value, error } = decode(\n\t\t\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\t\t\tjson,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\t\t`Failed to decode onboarding step complete response: ${error.errors.join(\n\t\t\t\t\t\t\t\t\", \",\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tcurrentState.completedSteps = value.completedSteps;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch (res.status) {\n\t\t\t\t\tcase 400:\n\t\t\t\t\tcase 401:\n\t\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\t\tcase 403:\n\t\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\"Failed to complete onboarding step.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { completedSteps: currentState.completedSteps };\n\t}\n\n\tasync toggleOnboarding(): Promise<{ isDismissed: boolean }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding/toggle\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ isDismissed: z.boolean() }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding guide.\");\n\t\t}\n\t}\n\n\tasync setDefaultMasterLocale(): Promise<void> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./repository/locales\", API_ENDPOINTS.LocaleService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tid: \"en-us\",\n\t\t\t\tisMaster: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 400:\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(\"Failed to set main content language.\", {\n\t\t\t\t\t\tcause: text,\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: PushChangesLimitType,\n\t): PushChangesLimit | null {\n\t\treturn fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(\n\t\t\t() => {\n\t\t\t\tconst error: ClientError = {\n\t\t\t\t\tstatus: statusCode,\n\t\t\t\t\tmessage: `Unable to parse raw limit from ${JSON.stringify(\n\t\t\t\t\t\tpotentialLimit,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(rawLimit: PushChangesRawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(PushChangesRawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\" | \"PATCH\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t\tskipAuthentication?: boolean;\n\t}): Promise<Response> {\n\t\tlet cookies;\n\t\ttry {\n\t\t\tcookies = await this.user.getAuthenticationCookies();\n\t\t} catch (e) {\n\t\t\tif (!args.skipAuthentication) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tconst extraHeaders: Record<string, string> = {};\n\n\t\tif (args.body) {\n\t\t\textraHeaders[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\textraHeaders.repository = args.repository;\n\t\t}\n\n\t\treturn await fetch(args.url.toString(), {\n\t\t\tmethod: args.method,\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\t// Some endpoints rely on the authorization header...\n\n\t\t\t\t...(cookies !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\t\t\t\tCookie: serializeCookies(cookies),\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...extraHeaders,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,8BAA8B;AAAA,EACnC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;;AAwCD,MAAO,iCAAiC,YAAW;AAAA;AAAA;AAAA,EAIxD,MAAM,UAAO;AACZ,UAAM,MAAM,IAAI,IAAI,kBAAkB,cAAc,WAAW;AAC/D,UAAM,MAAM,MAAM,KAAK,OAAO,EAAE,IAAK,CAAA;AAErC,QAAI,IAAI,IAAI;AACL,YAAA,OAAO,MAAM,IAAI;AACjB,YAAA,EAAE,OAAO,cAAc,UAAU,OACtC,EAAE,MAAM,iBAAiB,GACzB,IAAI;AAGL,UAAI,OAAO;AACJ,cAAA,IAAI,MACT,kCAAkC,MAAM,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,MAE7D;AAEO,aAAA;AAAA,IAAA,OACD;AACA,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM;AAAA,IAC/D;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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mBAAa,cAAc,IAAI;AAAA,IAChC;AAEA,QAAI,KAAK,YAAY;AACpB,mBAAa,aAAa,KAAK;AAAA,IAChC;AAEA,WAAO,MAAM,MAAM,KAAK,IAAI,YAAY;AAAA,MACvC,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAGR,GAAI,YAAY,SACb;AAAA,UACA,eAAe,UAAU,QAAQ,cAAc,CAAC;AAAA,UAChD,QAAQ,iBAAiB,OAAO;AAAA,QAAA,IAEhC;QACH,cAAc,KAAK,aAAa;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\nimport { z } from \"zod\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n\t/**\n\t * A map of variation IDs to remote screenshot URLs. These URLs are used to\n\t * detect if a screenshot has changed when comparing with local ones and to\n\t * push slices with the current screenshot. If a matching screenshot is not\n\t * found in this map, the current local screenshot is uploaded again.\n\t */\n\tvariationImageUrlMap: Record<string, string>;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = PushChangesLimit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n\nexport const Environment = t.type({\n\tkind: t.union([t.literal(\"prod\"), t.literal(\"stage\"), t.literal(\"dev\")]),\n\tname: t.string,\n\tdomain: t.string,\n\tusers: t.array(\n\t\tt.type({\n\t\t\tid: t.string,\n\t\t}),\n\t),\n});\nexport type Environment = t.TypeOf<typeof Environment>;\n\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["t","ChangeTypes","PushChangesLimitType","z"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;;AAKE,MAAA,oBAAoBA,aAAE,KAAK;AAAA,EACvC,QAAQA,aAAE;AAAA,EACV,MAAMA,aAAE;AAAA,EACR,MAAMA,aAAE,MAAM;AAAA,IACbA,aAAE,MAAM,qBAAqB;AAAA,IAC7BA,aAAE,OAAOA,aAAE,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AA,EACR;AAEO,SAAA;AACR,GACAA,MAAAA,QAAE,KAAK,CAAC,GAAG,iCAAiC,OAAO,CAAC,CAAC;AAKzC,MAAA,kBAAkBA,cAAE,OAAO;AAAA,EACvC,gBAAgBA,MAAAA,QAAE,MAAMA,MAAA,QAAE,QAAQ;AAAA,EAClC,aAAaA,cAAE,QAAS;AAAA,EACxB,SAASA,cAAE,OAAO;AAAA,IACjB,WAAW;AAAA,IACX,WAAWA,MAAA,QAAE,OAAQ,EAAC,SAAU;AAAA,EAAA,CAChC;AACD,CAAA;;;;;;;;;"}
1
+ {"version":3,"file":"types.cjs","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\nimport { z } from \"zod\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = PushChangesLimit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n\nexport const Environment = t.type({\n\tkind: t.union([t.literal(\"prod\"), t.literal(\"stage\"), t.literal(\"dev\")]),\n\tname: t.string,\n\tdomain: t.string,\n\tusers: t.array(\n\t\tt.type({\n\t\t\tid: t.string,\n\t\t}),\n\t),\n});\nexport type Environment = t.TypeOf<typeof Environment>;\n\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["t","ChangeTypes","PushChangesLimitType","z"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;;AAKE,MAAA,oBAAoBA,aAAE,KAAK;AAAA,EACvC,QAAQA,aAAE;AAAA,EACV,MAAMA,aAAE;AAAA,EACR,MAAMA,aAAE,MAAM;AAAA,IACbA,aAAE,MAAM,qBAAqB;AAAA,IAC7BA,aAAE,OAAOA,aAAE,QAAQA,aAAE,MAAM,qBAAqB,CAAC;AAAA,EAAA,CACjD;AACD,CAAA;AAGWC,QAAA,cAAA;AAAA,CAAZ,SAAYA,cAAW;AACtBA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACD,GAPYA,wBAAAA,QAAA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MAAA,QAAE,OAAQ,EAAC,SAAU;AAAA,EAAA,CAChC;AACD,CAAA;;;;;;;;;"}
@@ -115,13 +115,6 @@ type SliceChange = {
115
115
  type: "Slice";
116
116
  status: ChangeStatus;
117
117
  libraryID: string;
118
- /**
119
- * A map of variation IDs to remote screenshot URLs. These URLs are used to
120
- * detect if a screenshot has changed when comparing with local ones and to
121
- * push slices with the current screenshot. If a matching screenshot is not
122
- * found in this map, the current local screenshot is uploaded again.
123
- */
124
- variationImageUrlMap: Record<string, string>;
125
118
  };
126
119
  export type TransactionalMergeArgs = {
127
120
  confirmDeleteDocuments: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\nimport { z } from \"zod\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n\t/**\n\t * A map of variation IDs to remote screenshot URLs. These URLs are used to\n\t * detect if a screenshot has changed when comparing with local ones and to\n\t * push slices with the current screenshot. If a matching screenshot is not\n\t * found in this map, the current local screenshot is uploaded again.\n\t */\n\tvariationImageUrlMap: Record<string, string>;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = PushChangesLimit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n\nexport const Environment = t.type({\n\tkind: t.union([t.literal(\"prod\"), t.literal(\"stage\"), t.literal(\"dev\")]),\n\tname: t.string,\n\tdomain: t.string,\n\tusers: t.array(\n\t\tt.type({\n\t\t\tid: t.string,\n\t\t}),\n\t),\n});\nexport type Environment = t.TypeOf<typeof Environment>;\n\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["ChangeTypes","PushChangesLimitType"],"mappings":";;AAOO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;;AAKE,MAAA,oBAAoB,EAAE,KAAK;AAAA,EACvC,QAAQ,EAAE;AAAA,EACV,MAAM,EAAE;AAAA,EACR,MAAM,EAAE,MAAM;AAAA,IACb,EAAE,MAAM,qBAAqB;AAAA,IAC7B,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAAA,EAAA,CACjD;AACD,CAAA;AAGW,IAAA;AAAA,CAAZ,SAAYA,cAAW;AACtBA,eA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C,aAAa,EAAE,QAAS;AAAA,EACxB,SAAS,EAAE,OAAO;AAAA,IACjB,WAAW;AAAA,IACX,WAAW,EAAE,OAAQ,EAAC,SAAU;AAAA,EAAA,CAChC;AACD,CAAA;"}
1
+ {"version":3,"file":"types.js","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\nimport { z } from \"zod\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = PushChangesLimit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n\nexport const Environment = t.type({\n\tkind: t.union([t.literal(\"prod\"), t.literal(\"stage\"), t.literal(\"dev\")]),\n\tname: t.string,\n\tdomain: t.string,\n\tusers: t.array(\n\t\tt.type({\n\t\t\tid: t.string,\n\t\t}),\n\t),\n});\nexport type Environment = t.TypeOf<typeof Environment>;\n\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["ChangeTypes","PushChangesLimitType"],"mappings":";;AAOO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;;AAKE,MAAA,oBAAoB,EAAE,KAAK;AAAA,EACvC,QAAQ,EAAE;AAAA,EACV,MAAM,EAAE;AAAA,EACR,MAAM,EAAE,MAAM;AAAA,IACb,EAAE,MAAM,qBAAqB;AAAA,IAC7B,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAAA,EAAA,CACjD;AACD,CAAA;AAGW,IAAA;AAAA,CAAZ,SAAYA,cAAW;AACtBA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACD,GAPY,gBAAA,cAOX,CAAA,EAAA;AA6CY,MAAA,sBAAsB,EAAE,KAAK;AAAA,EACzC,SAAS,EAAE,KAAK;AAAA,IACf,aAAa,EAAE,MACd,EAAE,KAAK;AAAA,MACN,IAAI,EAAE;AAAA,MACN,mBAAmB,EAAE;AAAA,MACrB,KAAK,EAAE;AAAA,IAAA,CACP,CAAC;AAAA,EAAA,CAEH;AACD,CAAA;AAEW,IAAA;AAAA,CAAZ,SAAYC,uBAAoB;AAC/BA,wBAAA,MAAA,IAAA;AACAA,wBAAA,MAAA,IAAA;AACD,GAHY,yBAAA,uBAGX,CAAA,EAAA;AAwDY,MAAA,cAAc,EAAE,KAAK;AAAA,EACjC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,MAAM,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,EACvE,MAAM,EAAE;AAAA,EACR,QAAQ,EAAE;AAAA,EACV,OAAO,EAAE,MACR,EAAE,KAAK;AAAA,IACN,IAAI,EAAE;AAAA,EAAA,CACN,CAAC;AAEH,CAAA;AAGM,MAAM,kCAAkC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;;AAKD,SAAS,qBAAqB,OAAa;AACnC,SAAA,gCAAgC,SAAS,KAA2B;AAC5E;AAEO,MAAM,sBAAsB,EAAE,WACpC,CAAC,UAAS;AAGT,MAAI,OAAO,UAAU,YAAY,qBAAqB,KAAK,GAAG;AACtD,WAAA;AAAA,EACR;AAEO,SAAA;AACR,GACA,EAAE,KAAK,CAAC,GAAG,iCAAiC,OAAO,CAAC,CAAC;AAKzC,MAAA,kBAAkB,EAAE,OAAO;AAAA,EACvC,gBAAgB,EAAE,MAAM,EAAE,QAAQ;AAAA,EAClC,aAAa,EAAE,QAAS;AAAA,EACxB,SAAS,EAAE,OAAO;AAAA,IACjB,WAAW;AAAA,IACX,WAAW,EAAE,OAAQ,EAAC,SAAU;AAAA,EAAA,CAChC;AACD,CAAA;"}
@@ -413,11 +413,8 @@ class SlicesManager extends BaseManager.BaseManager {
413
413
  });
414
414
  if (model) {
415
415
  const modelWithScreenshots = await this.updateSliceModelScreenshotsInPlace({
416
- model,
417
416
  libraryID: args.libraryID,
418
- // We are pushing it for the first time here, no remote image URLs to
419
- // use during the update.
420
- variationImageUrlMap: {}
417
+ model
421
418
  });
422
419
  const authenticationToken = await this.user.getAuthenticationToken();
423
420
  const repositoryName = await this.project.getResolvedRepositoryName();
@@ -604,14 +601,9 @@ class SlicesManager extends BaseManager.BaseManager {
604
601
  imageUrl: DEFAULT_SLICE_SCREENSHOT_URL.DEFAULT_SLICE_SCREENSHOT_URL
605
602
  };
606
603
  }
607
- const remoteImageUrl = (_a = args.variationImageUrlMap) == null ? void 0 : _a[variation.id];
608
- const hasScreenshotChanged = !(remoteImageUrl == null ? void 0 : remoteImageUrl.includes(createContentDigest.createContentDigest(screenshot.data)));
604
+ const hasScreenshotChanged = !((_a = variation.imageUrl) == null ? void 0 : _a.includes(createContentDigest.createContentDigest(screenshot.data)));
609
605
  if (!hasScreenshotChanged) {
610
- return {
611
- ...variation,
612
- // Keep the existing remote screenshot URL if it exists.
613
- imageUrl: remoteImageUrl ?? variation.imageUrl
614
- };
606
+ return variation;
615
607
  }
616
608
  const keyPrefix = [
617
609
  repositoryName,
@@ -1 +1 @@
1
- {"version":3,"file":"SlicesManager.cjs","sources":["../../../../src/managers/slices/SlicesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport { SliceComparator } from \"@prismicio/types-internal/lib/customtypes/diff\";\nimport {\n\tCompositeSlice,\n\tLegacySlice,\n\tSharedSlice,\n\tVariation,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tHookError,\n\tSliceAssetUpdateHook,\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceLibraryReadHookData,\n\tSliceReadHookData,\n\tSliceRenameHook,\n\tSliceRenameHookData,\n\tSliceUpdateHook,\n} from \"@slicemachine/plugin-kit\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { bufferCodec } from \"../../lib/bufferCodec\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { mockSlice } from \"../../lib/mockSlice\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { DEFAULT_SLICE_SCREENSHOT_URL } from \"../../constants/DEFAULT_SLICE_SCREENSHOT_URL\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { UnauthenticatedError, UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype SlicesManagerReadSliceLibraryReturnType = {\n\tsliceIDs: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SlicesManagerReadAllSliceLibrariesReturnType = {\n\tlibraries: {\n\t\tlibraryID: string;\n\t\tsliceIDs: string[] | undefined;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryArgs = {\n\tlibraryID: string;\n};\n\ntype SliceMachineManagerUpdateSliceArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\tmocks?: SharedSliceContent[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\tmodels: { model: SharedSlice }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesReturnType = {\n\tmodels: {\n\t\tlibraryID: string;\n\t\tmodel: SharedSlice;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceReturnType = {\n\tmodel: SharedSlice | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tuserAgent?: string;\n};\n\nexport type SliceMachineManagerPushSliceReturnType = {\n\t/**\n\t * A record of Slice variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tscreenshotURLs: Record<string, string> | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceScreenshotReturnType = {\n\tdata: Buffer | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerUpdateSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tdata: Buffer;\n};\n\ntype SliceMachineManagerDeleteSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksReturnType = {\n\tmocks?: SharedSliceContent[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tmocks: SharedSliceContent[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype SlicesManagerUpsertHostedSliceScreenshotsArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\t/**\n\t * A map of variation IDs to remote screenshot URLs. These URLs are used to\n\t * detect if a screenshot has changed when comparing with local ones and to\n\t * push slices with the current screenshot. If a matching screenshot is not\n\t * found in this map, the current local screenshot is uploaded again.\n\t */\n\tvariationImageUrlMap: Record<string, string>;\n};\n\ntype SliceMachineManagerDeleteSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerDeleteSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerRenameSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\t/**\n\t * Current ID of the variation to rename.\n\t */\n\tvariationID: string;\n\tmodel: Variation;\n};\n\ntype SliceMachineManagerRenameSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerDeleteSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerDeleteSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {\n\tmodel: CompositeSlice | LegacySlice;\n\tsrc: {\n\t\tcustomTypeID: string;\n\t\ttabID: string;\n\t\tsliceZoneID: string;\n\t\tsliceID: string;\n\t};\n\tdest: {\n\t\tlibraryID: string;\n\t\tsliceID: string;\n\t\tvariationName: string;\n\t\tvariationID: string;\n\t};\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class SlicesManager extends BaseManager {\n\tasync readSliceLibrary(\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SlicesManagerReadSliceLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Should validation happen at the `callHook` level?\n\t\t// Including validation at the hook level would ensure\n\t\t// hook-based actions are validated.\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tsliceIDs: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tsliceIDs: data[0]?.sliceIDs ?? [],\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync readAllSliceLibraries(): Promise<SlicesManagerReadAllSliceLibrariesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SlicesManagerReadAllSliceLibrariesReturnType = {\n\t\t\tlibraries: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\tres.libraries.push({\n\t\t\t\tlibraryID,\n\t\t\t\tsliceIDs,\n\t\t\t});\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlicesForLibrary(\n\t\targs: SliceMachineManagerReadAllSlicesForLibraryArgs,\n\t): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\t\tres.errors.push(...errors);\n\n\t\tif (sliceIDs) {\n\t\t\tfor (const sliceID of sliceIDs) {\n\t\t\t\tconst { model, errors } = await this.readSlice({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t\tres.errors.push(...errors);\n\n\t\t\t\tif (model) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SliceMachineManagerReadAllSlicesReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { models, errors } = await this.readAllSlicesForLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors.push(...errors);\n\n\t\t\tfor (const model of models) {\n\t\t\t\tres.models.push({\n\t\t\t\t\tlibraryID,\n\t\t\t\t\tmodel: model.model,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createSlice(\n\t\targs: SliceCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:create\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: mockSlice({ model: args.model }),\n\t\t};\n\n\t\tconst { errors: updateSliceHookErrors } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceHookErrors],\n\t\t};\n\t}\n\n\tasync readSlice(\n\t\targs: SliceReadHookData,\n\t): Promise<SliceMachineManagerReadSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: SharedSlice,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors: errors.map((error) => {\n\t\t\t\terror.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;\n\n\t\t\t\treturn error;\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync updateSlice(\n\t\targs: SliceMachineManagerUpdateSliceArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { mocks: previousMocks } = await this.readSliceMocks({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst { model: previousModel } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updatedMocks = mockSlice({\n\t\t\tmodel: args.model,\n\t\t\tmocks: previousMocks,\n\t\t\tdiff: SliceComparator.compare(previousModel, args.model),\n\t\t});\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: updatedMocks,\n\t\t};\n\n\t\tconst { errors: updateSliceMocksHookResult } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceMocksHookResult],\n\t\t};\n\t}\n\n\tasync renameSlice(\n\t\targs: SliceRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSlice(\n\t\targs: SliceMachineManagerDeleteSliceArgs,\n\t): Promise<SliceMachineManagerDeleteSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst { errors: deleteSliceErrors } =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:delete\", {\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t});\n\n\t\t\t// Do not update custom types if slice deletion failed\n\t\t\tif (deleteSliceErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: deleteSliceErrors,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: updateCustomTypeErrors } =\n\t\t\t\tawait this._removeSliceFromCustomTypes(args.sliceID);\n\n\t\t\treturn {\n\t\t\t\terrors: updateCustomTypeErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync renameSliceVariation(\n\t\targs: SliceMachineManagerRenameSliceVariationArgs,\n\t): Promise<SliceMachineManagerRenameSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Remove when we support renaming variation ID, see: DT-1708\n\t\tif (args.variationID !== args.model.id) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Find and rename the variation\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.map((variation) => {\n\t\t\t\t\tif (variation.id === args.variationID) {\n\t\t\t\t\t\t// Matches the slice we want to rename\n\t\t\t\t\t\treturn args.model;\n\t\t\t\t\t} else if (variation.id === args.model.id) {\n\t\t\t\t\t\t// Matches any other slice that has the ID of the renamed variation and throw.\n\t\t\t\t\t\t// This should be validated on the frontend first for better UX, this is only backend validation.\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot rename variation \\`${args.variationID}\\` to \\`${args.model.id}\\`. A variation already exists with that ID in slice \\`${args.sliceID}\\` from library \\`${args.libraryID}\\`, try deleting it first or choose another variation ID to rename that slice.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn variation;\n\t\t\t\t}),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// If variation ID has changed, we need to rename assets accordingly\n\t\t\tconst assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];\n\t\t\tif (args.variationID !== args.model.id) {\n\t\t\t\t// Renaming screenshot\n\t\t\t\tconst { data: screenshot, errors: readSliceScreenshotErrors } =\n\t\t\t\t\tawait this.readSliceScreenshot({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceScreenshotErrors);\n\n\t\t\t\tif (screenshot) {\n\t\t\t\t\t// Delete old ID screenshot\n\t\t\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.deleteSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...deleteSliceScreenshotErrors);\n\n\t\t\t\t\t// Create new ID screenshot\n\t\t\t\t\tconst { errors: updateSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.model.id,\n\t\t\t\t\t\t\tdata: screenshot,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceScreenshotErrors);\n\t\t\t\t}\n\n\t\t\t\t// Renaming mocks\n\t\t\t\tconst { mocks, errors: readSliceMocksErrors } =\n\t\t\t\t\tawait this.readSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceMocksErrors);\n\n\t\t\t\tif (mocks?.length) {\n\t\t\t\t\tconst { errors: updateSliceMocksErrors } =\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tmocks: mocks.map((mock) => {\n\t\t\t\t\t\t\t\tif (mock.variation === args.variationID) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...mock,\n\t\t\t\t\t\t\t\t\t\tvariation: args.model.id,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn mock;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceMocksErrors);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync deleteSliceVariation(\n\t\targs: SliceMachineManagerDeleteSliceVariationArgs,\n\t): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Remove variation from model and update it\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.filter(\n\t\t\t\t\t(variation) => variation.id !== args.variationID,\n\t\t\t\t),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// Cleanup deleted variation screenshot\n\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\tawait this.deleteSliceScreenshot(args);\n\n\t\t\t// Cleanup deleted variation mocks\n\t\t\tconst { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(\n\t\t\t\t{\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t},\n\t\t\t);\n\t\t\tlet updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType[\"errors\"] =\n\t\t\t\t[];\n\t\t\tif (mocks?.length) {\n\t\t\t\tupdateSliceMocksErrors = (\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tmocks: mocks.filter((mock) => mock.variation !== args.variationID),\n\t\t\t\t\t})\n\t\t\t\t).errors;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors: [\n\t\t\t\t\t...deleteSliceScreenshotErrors,\n\t\t\t\t\t...readSliceMocksErrors,\n\t\t\t\t\t...updateSliceMocksErrors,\n\t\t\t\t],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync convertLegacySliceToSharedSlice(\n\t\targs: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,\n\t): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {\n\t\tconst errors: (DecodeError | HookError)[] = [];\n\n\t\tconst { model: maybeExistingSlice } = await this.readSlice({\n\t\t\tlibraryID: args.dest.libraryID,\n\t\t\tsliceID: args.dest.sliceID,\n\t\t});\n\n\t\tconst legacySliceAsVariation: Variation = {\n\t\t\tid: args.dest.variationID,\n\t\t\tname: args.dest.variationName,\n\t\t\tdescription: args.dest.variationName,\n\t\t\timageUrl: \"\",\n\t\t\tdocURL: \"\",\n\t\t\tversion: \"initial\",\n\t\t\tprimary: {},\n\t\t\titems: {},\n\t\t};\n\n\t\tswitch (args.model.type) {\n\t\t\tcase \"Slice\":\n\t\t\t\tlegacySliceAsVariation.primary = args.model[\"non-repeat\"];\n\t\t\t\tlegacySliceAsVariation.items = args.model.repeat;\n\t\t\t\tbreak;\n\n\t\t\tcase \"Group\":\n\t\t\t\tlegacySliceAsVariation.items = args.model.config?.fields ?? {};\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tlegacySliceAsVariation.primary = { [args.src.sliceID]: args.model };\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Convert as a slice variation, or merge against an existing slice variation\n\t\tif (maybeExistingSlice) {\n\t\t\tconst maybeVariation = maybeExistingSlice.variations.find(\n\t\t\t\t(variation) => variation.id === args.dest.variationID,\n\t\t\t);\n\n\t\t\t// If we're not merging against an existing slice variation, then we need to insert the new variation\n\t\t\tif (!maybeVariation) {\n\t\t\t\tmaybeExistingSlice.variations = [\n\t\t\t\t\t...maybeExistingSlice.variations,\n\t\t\t\t\tlegacySliceAsVariation,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tmaybeExistingSlice.legacyPaths ||= {};\n\t\t\tmaybeExistingSlice.legacyPaths[\n\t\t\t\t`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`\n\t\t\t] = args.dest.variationID;\n\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: maybeExistingSlice,\n\t\t\t});\n\t\t} else {\n\t\t\t// Convert to new shared slice\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: {\n\t\t\t\t\tid: args.dest.sliceID,\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t\tname: args.dest.sliceID,\n\t\t\t\t\tlegacyPaths: {\n\t\t\t\t\t\t[`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`]:\n\t\t\t\t\t\t\targs.dest.variationID,\n\t\t\t\t\t},\n\t\t\t\t\tvariations: [legacySliceAsVariation],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Update source custom type\n\t\tconst { model: customType, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readCustomType({\n\t\t\t\tid: args.src.customTypeID,\n\t\t\t});\n\t\terrors.push(...customTypeReadErrors);\n\n\t\tif (customType) {\n\t\t\tconst field = customType.json[args.src.tabID][args.src.sliceZoneID];\n\n\t\t\t// Convert legacy slice definition in slice zone to shared slice reference\n\t\t\tif (field.type === \"Slices\" && field.config?.choices) {\n\t\t\t\tdelete field.config.choices[args.src.sliceID];\n\t\t\t\tfield.config.choices[args.dest.sliceID] = {\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: customTypeUpdateErrors } =\n\t\t\t\tawait this.customTypes.updateCustomType({ model: customType });\n\t\t\terrors.push(...customTypeUpdateErrors);\n\t\t}\n\n\t\treturn { errors };\n\t}\n\n\t/**\n\t * @returns Record of variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tasync pushSlice(\n\t\targs: SliceMachineManagerPushSliceArgs,\n\t): Promise<SliceMachineManagerPushSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst modelWithScreenshots =\n\t\t\t\tawait this.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t// We are pushing it for the first time here, no remote image URLs to\n\t\t\t\t\t// use during the update.\n\t\t\t\t\tvariationImageUrlMap: {},\n\t\t\t\t});\n\n\t\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Slice already exists on the repository.\n\t\t\t\tawait client.getSharedSliceByID(args.sliceID);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateSharedSlice(modelWithScreenshots);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If the Slice doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertSharedSlice(modelWithScreenshots);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push Slices to this Prismic repository.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Pass the error through if it isn't the one we were expecting.\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst screenshotURLs: Record<string, string> = {};\n\t\t\tfor (const variation of modelWithScreenshots.variations) {\n\t\t\t\tscreenshotURLs[variation.id] = variation.imageUrl;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tscreenshotURLs,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tscreenshotURLs: undefined,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync readSliceScreenshot(\n\t\targs: SliceMachineManagerReadSliceScreenshotArgs,\n\t): Promise<SliceMachineManagerReadSliceScreenshotReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: bufferCodec,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tdata: data[0]?.data,\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync updateSliceScreenshot(\n\t\targs: SliceMachineManagerUpdateSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: `screenshot-${args.variationID}.png`,\n\t\t\t\t\tdata: args.data,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSliceScreenshot(\n\t\targs: SliceMachineManagerDeleteSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:delete\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readSliceMocks(\n\t\targs: SliceMachineManagerReadSliceMocksArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `mocks.json`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: t.array(SharedSliceContent),\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...hookResult,\n\t\t\t\t// Convert the asset data from a Buffer to JSON\n\t\t\t\t// to prepare it for validation.\n\t\t\t\tdata: hookResult.data.map((result) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tdata: JSON.parse(result.data.toString()),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocks: data[0]?.data,\n\t\t\t\terrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocks: [],\n\t\t\t\terrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync updateSliceMocks(\n\t\targs: SliceMachineManagerUpdateSliceMocksArgs,\n\t): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocks, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\t// TODO: Remove\n\tasync readSliceMocksConfig(\n\t\targs: SliceMachineManagerReadSliceMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync fetchRemoteSlices(): Promise<SharedSlice[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllSharedSlices();\n\t}\n\n\tasync updateSliceModelScreenshotsInPlace(\n\t\targs: SlicesManagerUpsertHostedSliceScreenshotsArgs,\n\t): Promise<SharedSlice> {\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst variations = await Promise.all(\n\t\t\targs.model.variations.map(async (variation) => {\n\t\t\t\tconst screenshot = await this.readSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.model.id,\n\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t});\n\n\t\t\t\t// If there's no screenshot, delete it by replacing it with the default screenshot\n\t\t\t\tif (!screenshot.data) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\timageUrl: DEFAULT_SLICE_SCREENSHOT_URL,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst remoteImageUrl = args.variationImageUrlMap?.[variation.id];\n\t\t\t\tconst hasScreenshotChanged = !remoteImageUrl?.includes(\n\t\t\t\t\tcreateContentDigest(screenshot.data),\n\t\t\t\t);\n\n\t\t\t\t// If screenshot hasn't changed, no need to upload it again, just use\n\t\t\t\t// the existing variation with the remote image URL if it exists.\n\t\t\t\tif (!hasScreenshotChanged) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\t// Keep the existing remote screenshot URL if it exists.\n\t\t\t\t\t\timageUrl: remoteImageUrl ?? variation.imageUrl,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst keyPrefix = [\n\t\t\t\t\trepositoryName,\n\t\t\t\t\t\"shared-slices\",\n\t\t\t\t\targs.model.id,\n\t\t\t\t\tvariation.id,\n\t\t\t\t].join(\"/\");\n\n\t\t\t\tconst uploadedScreenshot = await this.screenshots.uploadScreenshot({\n\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\tkeyPrefix,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\t...variation,\n\t\t\t\t\timageUrl: uploadedScreenshot.url,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\t...args.model,\n\t\t\tvariations,\n\t\t};\n\t}\n\n\tprivate async _removeSliceFromCustomTypes(sliceID: string) {\n\t\tconst { models, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readAllCustomTypes();\n\n\t\t// Successfully update all custom types or throw\n\t\tawait Promise.all(\n\t\t\tmodels.map(async (customType) => {\n\t\t\t\tconst updatedJsonModel = Object.entries(customType.model.json).reduce(\n\t\t\t\t\t(tabAccumulator, [tabKey, tab]) => {\n\t\t\t\t\t\tconst updatedTabFields = Object.entries(tab).reduce(\n\t\t\t\t\t\t\t(fieldAccumulator, [fieldKey, field]) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tfield.config === undefined ||\n\t\t\t\t\t\t\t\t\tfield.type !== \"Slices\" ||\n\t\t\t\t\t\t\t\t\tfield.config.choices === undefined\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn { ...fieldAccumulator, [fieldKey]: field };\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filteredChoices = Object.entries(\n\t\t\t\t\t\t\t\t\tfield.config.choices,\n\t\t\t\t\t\t\t\t).reduce((choiceAccumulator, [choiceKey, choice]) => {\n\t\t\t\t\t\t\t\t\tif (choiceKey === sliceID) {\n\t\t\t\t\t\t\t\t\t\treturn choiceAccumulator;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn { ...choiceAccumulator, [choiceKey]: choice };\n\t\t\t\t\t\t\t\t}, {});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...fieldAccumulator,\n\t\t\t\t\t\t\t\t\t[fieldKey]: {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tconfig: { ...field.config, choices: filteredChoices },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn { ...tabAccumulator, [tabKey]: updatedTabFields };\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t);\n\n\t\t\t\tawait this.customTypes.updateCustomType({\n\t\t\t\t\tmodel: { ...customType.model, json: updatedJsonModel },\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\n\t\treturn { errors: customTypeReadErrors };\n\t}\n}\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","mockSlice","SharedSlice","SliceComparator","UnauthenticatedError","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","bufferCodec","SharedSliceContent","DEFAULT_SLICE_SCREENSHOT_URL","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwNM,MAAO,sBAAsBA,YAAAA,YAAW;AAAA,EAC7C,MAAM,iBACL,MAA8B;;AAE9BC,sDAAyB,KAAK,wBAAwB;AAKtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,sBACA,IAAI;AAEL,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,IAAIA,aAAE;AAAA,MACN,UAAUA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CA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G,WAAW,OAAO,MAAM,iBAAkB;AAAA,MAAA,CACtD;AAAA,IACD,CAAA,CAAC;AAGI,WAAA,EAAE,QAAQ;EAClB;AACA;;"}
1
+ {"version":3,"file":"SlicesManager.cjs","sources":["../../../../src/managers/slices/SlicesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport { SliceComparator } from \"@prismicio/types-internal/lib/customtypes/diff\";\nimport {\n\tCompositeSlice,\n\tLegacySlice,\n\tSharedSlice,\n\tVariation,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tHookError,\n\tSliceAssetUpdateHook,\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceLibraryReadHookData,\n\tSliceReadHookData,\n\tSliceRenameHook,\n\tSliceRenameHookData,\n\tSliceUpdateHook,\n} from \"@slicemachine/plugin-kit\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { bufferCodec } from \"../../lib/bufferCodec\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { mockSlice } from \"../../lib/mockSlice\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { DEFAULT_SLICE_SCREENSHOT_URL } from \"../../constants/DEFAULT_SLICE_SCREENSHOT_URL\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { UnauthenticatedError, UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype SlicesManagerReadSliceLibraryReturnType = {\n\tsliceIDs: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SlicesManagerReadAllSliceLibrariesReturnType = {\n\tlibraries: {\n\t\tlibraryID: string;\n\t\tsliceIDs: string[] | undefined;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryArgs = {\n\tlibraryID: string;\n};\n\ntype SliceMachineManagerUpdateSliceArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\tmocks?: SharedSliceContent[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\tmodels: { model: SharedSlice }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesReturnType = {\n\tmodels: {\n\t\tlibraryID: string;\n\t\tmodel: SharedSlice;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceReturnType = {\n\tmodel: SharedSlice | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tuserAgent?: string;\n};\n\nexport type SliceMachineManagerPushSliceReturnType = {\n\t/**\n\t * A record of Slice variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tscreenshotURLs: Record<string, string> | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceScreenshotReturnType = {\n\tdata: Buffer | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerUpdateSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tdata: Buffer;\n};\n\ntype SliceMachineManagerDeleteSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksReturnType = {\n\tmocks?: SharedSliceContent[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tmocks: SharedSliceContent[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype SlicesManagerUpsertHostedSliceScrenshotsArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n};\n\ntype SliceMachineManagerDeleteSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerDeleteSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerRenameSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\t/**\n\t * Current ID of the variation to rename.\n\t */\n\tvariationID: string;\n\tmodel: Variation;\n};\n\ntype SliceMachineManagerRenameSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerDeleteSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerDeleteSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {\n\tmodel: CompositeSlice | LegacySlice;\n\tsrc: {\n\t\tcustomTypeID: string;\n\t\ttabID: string;\n\t\tsliceZoneID: string;\n\t\tsliceID: string;\n\t};\n\tdest: {\n\t\tlibraryID: string;\n\t\tsliceID: string;\n\t\tvariationName: string;\n\t\tvariationID: string;\n\t};\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class SlicesManager extends BaseManager {\n\tasync readSliceLibrary(\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SlicesManagerReadSliceLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Should validation happen at the `callHook` level?\n\t\t// Including validation at the hook level would ensure\n\t\t// hook-based actions are validated.\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tsliceIDs: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tsliceIDs: data[0]?.sliceIDs ?? [],\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync readAllSliceLibraries(): Promise<SlicesManagerReadAllSliceLibrariesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SlicesManagerReadAllSliceLibrariesReturnType = {\n\t\t\tlibraries: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\tres.libraries.push({\n\t\t\t\tlibraryID,\n\t\t\t\tsliceIDs,\n\t\t\t});\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlicesForLibrary(\n\t\targs: SliceMachineManagerReadAllSlicesForLibraryArgs,\n\t): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\t\tres.errors.push(...errors);\n\n\t\tif (sliceIDs) {\n\t\t\tfor (const sliceID of sliceIDs) {\n\t\t\t\tconst { model, errors } = await this.readSlice({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t\tres.errors.push(...errors);\n\n\t\t\t\tif (model) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SliceMachineManagerReadAllSlicesReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { models, errors } = await this.readAllSlicesForLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors.push(...errors);\n\n\t\t\tfor (const model of models) {\n\t\t\t\tres.models.push({\n\t\t\t\t\tlibraryID,\n\t\t\t\t\tmodel: model.model,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createSlice(\n\t\targs: SliceCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:create\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: mockSlice({ model: args.model }),\n\t\t};\n\n\t\tconst { errors: updateSliceHookErrors } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceHookErrors],\n\t\t};\n\t}\n\n\tasync readSlice(\n\t\targs: SliceReadHookData,\n\t): Promise<SliceMachineManagerReadSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: SharedSlice,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors: errors.map((error) => {\n\t\t\t\terror.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;\n\n\t\t\t\treturn error;\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync updateSlice(\n\t\targs: SliceMachineManagerUpdateSliceArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { mocks: previousMocks } = await this.readSliceMocks({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst { model: previousModel } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updatedMocks = mockSlice({\n\t\t\tmodel: args.model,\n\t\t\tmocks: previousMocks,\n\t\t\tdiff: SliceComparator.compare(previousModel, args.model),\n\t\t});\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: updatedMocks,\n\t\t};\n\n\t\tconst { errors: updateSliceMocksHookResult } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceMocksHookResult],\n\t\t};\n\t}\n\n\tasync renameSlice(\n\t\targs: SliceRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSlice(\n\t\targs: SliceMachineManagerDeleteSliceArgs,\n\t): Promise<SliceMachineManagerDeleteSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst { errors: deleteSliceErrors } =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:delete\", {\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t});\n\n\t\t\t// Do not update custom types if slice deletion failed\n\t\t\tif (deleteSliceErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: deleteSliceErrors,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: updateCustomTypeErrors } =\n\t\t\t\tawait this._removeSliceFromCustomTypes(args.sliceID);\n\n\t\t\treturn {\n\t\t\t\terrors: updateCustomTypeErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync renameSliceVariation(\n\t\targs: SliceMachineManagerRenameSliceVariationArgs,\n\t): Promise<SliceMachineManagerRenameSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Remove when we support renaming variation ID, see: DT-1708\n\t\tif (args.variationID !== args.model.id) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Find and rename the variation\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.map((variation) => {\n\t\t\t\t\tif (variation.id === args.variationID) {\n\t\t\t\t\t\t// Matches the slice we want to rename\n\t\t\t\t\t\treturn args.model;\n\t\t\t\t\t} else if (variation.id === args.model.id) {\n\t\t\t\t\t\t// Matches any other slice that has the ID of the renamed variation and throw.\n\t\t\t\t\t\t// This should be validated on the frontend first for better UX, this is only backend validation.\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot rename variation \\`${args.variationID}\\` to \\`${args.model.id}\\`. A variation already exists with that ID in slice \\`${args.sliceID}\\` from library \\`${args.libraryID}\\`, try deleting it first or choose another variation ID to rename that slice.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn variation;\n\t\t\t\t}),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// If variation ID has changed, we need to rename assets accordingly\n\t\t\tconst assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];\n\t\t\tif (args.variationID !== args.model.id) {\n\t\t\t\t// Renaming screenshot\n\t\t\t\tconst { data: screenshot, errors: readSliceScreenshotErrors } =\n\t\t\t\t\tawait this.readSliceScreenshot({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceScreenshotErrors);\n\n\t\t\t\tif (screenshot) {\n\t\t\t\t\t// Delete old ID screenshot\n\t\t\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.deleteSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...deleteSliceScreenshotErrors);\n\n\t\t\t\t\t// Create new ID screenshot\n\t\t\t\t\tconst { errors: updateSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.model.id,\n\t\t\t\t\t\t\tdata: screenshot,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceScreenshotErrors);\n\t\t\t\t}\n\n\t\t\t\t// Renaming mocks\n\t\t\t\tconst { mocks, errors: readSliceMocksErrors } =\n\t\t\t\t\tawait this.readSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceMocksErrors);\n\n\t\t\t\tif (mocks?.length) {\n\t\t\t\t\tconst { errors: updateSliceMocksErrors } =\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tmocks: mocks.map((mock) => {\n\t\t\t\t\t\t\t\tif (mock.variation === args.variationID) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...mock,\n\t\t\t\t\t\t\t\t\t\tvariation: args.model.id,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn mock;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceMocksErrors);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync deleteSliceVariation(\n\t\targs: SliceMachineManagerDeleteSliceVariationArgs,\n\t): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Remove variation from model and update it\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.filter(\n\t\t\t\t\t(variation) => variation.id !== args.variationID,\n\t\t\t\t),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// Cleanup deleted variation screenshot\n\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\tawait this.deleteSliceScreenshot(args);\n\n\t\t\t// Cleanup deleted variation mocks\n\t\t\tconst { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(\n\t\t\t\t{\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t},\n\t\t\t);\n\t\t\tlet updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType[\"errors\"] =\n\t\t\t\t[];\n\t\t\tif (mocks?.length) {\n\t\t\t\tupdateSliceMocksErrors = (\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tmocks: mocks.filter((mock) => mock.variation !== args.variationID),\n\t\t\t\t\t})\n\t\t\t\t).errors;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors: [\n\t\t\t\t\t...deleteSliceScreenshotErrors,\n\t\t\t\t\t...readSliceMocksErrors,\n\t\t\t\t\t...updateSliceMocksErrors,\n\t\t\t\t],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync convertLegacySliceToSharedSlice(\n\t\targs: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,\n\t): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {\n\t\tconst errors: (DecodeError | HookError)[] = [];\n\n\t\tconst { model: maybeExistingSlice } = await this.readSlice({\n\t\t\tlibraryID: args.dest.libraryID,\n\t\t\tsliceID: args.dest.sliceID,\n\t\t});\n\n\t\tconst legacySliceAsVariation: Variation = {\n\t\t\tid: args.dest.variationID,\n\t\t\tname: args.dest.variationName,\n\t\t\tdescription: args.dest.variationName,\n\t\t\timageUrl: \"\",\n\t\t\tdocURL: \"\",\n\t\t\tversion: \"initial\",\n\t\t\tprimary: {},\n\t\t\titems: {},\n\t\t};\n\n\t\tswitch (args.model.type) {\n\t\t\tcase \"Slice\":\n\t\t\t\tlegacySliceAsVariation.primary = args.model[\"non-repeat\"];\n\t\t\t\tlegacySliceAsVariation.items = args.model.repeat;\n\t\t\t\tbreak;\n\n\t\t\tcase \"Group\":\n\t\t\t\tlegacySliceAsVariation.items = args.model.config?.fields ?? {};\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tlegacySliceAsVariation.primary = { [args.src.sliceID]: args.model };\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Convert as a slice variation, or merge against an existing slice variation\n\t\tif (maybeExistingSlice) {\n\t\t\tconst maybeVariation = maybeExistingSlice.variations.find(\n\t\t\t\t(variation) => variation.id === args.dest.variationID,\n\t\t\t);\n\n\t\t\t// If we're not merging against an existing slice variation, then we need to insert the new variation\n\t\t\tif (!maybeVariation) {\n\t\t\t\tmaybeExistingSlice.variations = [\n\t\t\t\t\t...maybeExistingSlice.variations,\n\t\t\t\t\tlegacySliceAsVariation,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tmaybeExistingSlice.legacyPaths ||= {};\n\t\t\tmaybeExistingSlice.legacyPaths[\n\t\t\t\t`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`\n\t\t\t] = args.dest.variationID;\n\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: maybeExistingSlice,\n\t\t\t});\n\t\t} else {\n\t\t\t// Convert to new shared slice\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: {\n\t\t\t\t\tid: args.dest.sliceID,\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t\tname: args.dest.sliceID,\n\t\t\t\t\tlegacyPaths: {\n\t\t\t\t\t\t[`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`]:\n\t\t\t\t\t\t\targs.dest.variationID,\n\t\t\t\t\t},\n\t\t\t\t\tvariations: [legacySliceAsVariation],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Update source custom type\n\t\tconst { model: customType, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readCustomType({\n\t\t\t\tid: args.src.customTypeID,\n\t\t\t});\n\t\terrors.push(...customTypeReadErrors);\n\n\t\tif (customType) {\n\t\t\tconst field = customType.json[args.src.tabID][args.src.sliceZoneID];\n\n\t\t\t// Convert legacy slice definition in slice zone to shared slice reference\n\t\t\tif (field.type === \"Slices\" && field.config?.choices) {\n\t\t\t\tdelete field.config.choices[args.src.sliceID];\n\t\t\t\tfield.config.choices[args.dest.sliceID] = {\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: customTypeUpdateErrors } =\n\t\t\t\tawait this.customTypes.updateCustomType({ model: customType });\n\t\t\terrors.push(...customTypeUpdateErrors);\n\t\t}\n\n\t\treturn { errors };\n\t}\n\n\t/**\n\t * @returns Record of variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tasync pushSlice(\n\t\targs: SliceMachineManagerPushSliceArgs,\n\t): Promise<SliceMachineManagerPushSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst modelWithScreenshots =\n\t\t\t\tawait this.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel,\n\t\t\t\t});\n\n\t\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Slice already exists on the repository.\n\t\t\t\tawait client.getSharedSliceByID(args.sliceID);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateSharedSlice(modelWithScreenshots);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If the Slice doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertSharedSlice(modelWithScreenshots);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push Slices to this Prismic repository.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Pass the error through if it isn't the one we were expecting.\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst screenshotURLs: Record<string, string> = {};\n\t\t\tfor (const variation of modelWithScreenshots.variations) {\n\t\t\t\tscreenshotURLs[variation.id] = variation.imageUrl;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tscreenshotURLs,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tscreenshotURLs: undefined,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync readSliceScreenshot(\n\t\targs: SliceMachineManagerReadSliceScreenshotArgs,\n\t): Promise<SliceMachineManagerReadSliceScreenshotReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: bufferCodec,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tdata: data[0]?.data,\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync updateSliceScreenshot(\n\t\targs: SliceMachineManagerUpdateSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: `screenshot-${args.variationID}.png`,\n\t\t\t\t\tdata: args.data,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSliceScreenshot(\n\t\targs: SliceMachineManagerDeleteSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:delete\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readSliceMocks(\n\t\targs: SliceMachineManagerReadSliceMocksArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `mocks.json`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: t.array(SharedSliceContent),\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...hookResult,\n\t\t\t\t// Convert the asset data from a Buffer to JSON\n\t\t\t\t// to prepare it for validation.\n\t\t\t\tdata: hookResult.data.map((result) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tdata: JSON.parse(result.data.toString()),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocks: data[0]?.data,\n\t\t\t\terrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocks: [],\n\t\t\t\terrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync updateSliceMocks(\n\t\targs: SliceMachineManagerUpdateSliceMocksArgs,\n\t): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocks, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\t// TODO: Remove\n\tasync readSliceMocksConfig(\n\t\targs: SliceMachineManagerReadSliceMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync fetchRemoteSlices(): Promise<SharedSlice[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllSharedSlices();\n\t}\n\n\tasync updateSliceModelScreenshotsInPlace(\n\t\targs: SlicesManagerUpsertHostedSliceScrenshotsArgs,\n\t): Promise<SharedSlice> {\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst variations = await Promise.all(\n\t\t\targs.model.variations.map(async (variation) => {\n\t\t\t\tconst screenshot = await this.readSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.model.id,\n\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t});\n\n\t\t\t\t// If there's no screenshot, delete it by replacing it with the default screenshot\n\t\t\t\tif (!screenshot.data) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\timageUrl: DEFAULT_SLICE_SCREENSHOT_URL,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst hasScreenshotChanged = !variation.imageUrl?.includes(\n\t\t\t\t\tcreateContentDigest(screenshot.data),\n\t\t\t\t);\n\n\t\t\t\t// If screenshot hasn't changed, do nothing\n\t\t\t\tif (!hasScreenshotChanged) {\n\t\t\t\t\treturn variation;\n\t\t\t\t}\n\n\t\t\t\tconst keyPrefix = [\n\t\t\t\t\trepositoryName,\n\t\t\t\t\t\"shared-slices\",\n\t\t\t\t\targs.model.id,\n\t\t\t\t\tvariation.id,\n\t\t\t\t].join(\"/\");\n\n\t\t\t\tconst uploadedScreenshot = await this.screenshots.uploadScreenshot({\n\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\tkeyPrefix,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\t...variation,\n\t\t\t\t\timageUrl: uploadedScreenshot.url,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\t...args.model,\n\t\t\tvariations,\n\t\t};\n\t}\n\n\tprivate async _removeSliceFromCustomTypes(sliceID: string) {\n\t\tconst { models, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readAllCustomTypes();\n\n\t\t// Successfully update all custom types or throw\n\t\tawait Promise.all(\n\t\t\tmodels.map(async (customType) => {\n\t\t\t\tconst updatedJsonModel = Object.entries(customType.model.json).reduce(\n\t\t\t\t\t(tabAccumulator, [tabKey, tab]) => {\n\t\t\t\t\t\tconst updatedTabFields = Object.entries(tab).reduce(\n\t\t\t\t\t\t\t(fieldAccumulator, [fieldKey, field]) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tfield.config === undefined ||\n\t\t\t\t\t\t\t\t\tfield.type !== \"Slices\" ||\n\t\t\t\t\t\t\t\t\tfield.config.choices === undefined\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn { ...fieldAccumulator, [fieldKey]: field };\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filteredChoices = Object.entries(\n\t\t\t\t\t\t\t\t\tfield.config.choices,\n\t\t\t\t\t\t\t\t).reduce((choiceAccumulator, [choiceKey, choice]) => {\n\t\t\t\t\t\t\t\t\tif (choiceKey === sliceID) {\n\t\t\t\t\t\t\t\t\t\treturn choiceAccumulator;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn { ...choiceAccumulator, [choiceKey]: choice };\n\t\t\t\t\t\t\t\t}, {});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...fieldAccumulator,\n\t\t\t\t\t\t\t\t\t[fieldKey]: {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tconfig: { ...field.config, choices: filteredChoices },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn { ...tabAccumulator, [tabKey]: updatedTabFields };\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t);\n\n\t\t\t\tawait this.customTypes.updateCustomType({\n\t\t\t\t\tmodel: { ...customType.model, json: updatedJsonModel },\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\n\t\treturn { errors: customTypeReadErrors };\n\t}\n}\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","mockSlice","SharedSlice","SliceComparator","UnauthenticatedError","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","bufferCodec","SharedSliceContent","DEFAULT_SLICE_SCREENSHOT_URL","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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AEH,GACA,CAAE,CAAA;AAGH,eAAO,EAAE,GAAG,gBAAgB,CAAC,MAAM,GAAG,iBAAgB;AAAA,MACvD,GACA,CAAE,CAAA;AAGG,YAAA,KAAK,YAAY,iBAAiB;AAAA,QACvC,OAAO,EAAE,GAAG,WAAW,OAAO,MAAM,iBAAkB;AAAA,MAAA,CACtD;AAAA,IACD,CAAA,CAAC;AAGI,WAAA,EAAE,QAAQ;EAClB;AACA;;"}
@@ -98,16 +98,9 @@ type SliceMachineManagerUpdateSliceMocksArgs = {
98
98
  type SliceMachineManagerUpdateSliceMocksArgsReturnType = {
99
99
  errors: HookError[];
100
100
  };
101
- type SlicesManagerUpsertHostedSliceScreenshotsArgs = {
101
+ type SlicesManagerUpsertHostedSliceScrenshotsArgs = {
102
102
  libraryID: string;
103
103
  model: SharedSlice;
104
- /**
105
- * A map of variation IDs to remote screenshot URLs. These URLs are used to
106
- * detect if a screenshot has changed when comparing with local ones and to
107
- * push slices with the current screenshot. If a matching screenshot is not
108
- * found in this map, the current local screenshot is uploaded again.
109
- */
110
- variationImageUrlMap: Record<string, string>;
111
104
  };
112
105
  type SliceMachineManagerDeleteSliceArgs = {
113
106
  libraryID: string;
@@ -180,7 +173,7 @@ export declare class SlicesManager extends BaseManager {
180
173
  updateSliceMocks(args: SliceMachineManagerUpdateSliceMocksArgs): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType>;
181
174
  readSliceMocksConfig(args: SliceMachineManagerReadSliceMocksConfigArgs): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType>;
182
175
  fetchRemoteSlices(): Promise<SharedSlice[]>;
183
- updateSliceModelScreenshotsInPlace(args: SlicesManagerUpsertHostedSliceScreenshotsArgs): Promise<SharedSlice>;
176
+ updateSliceModelScreenshotsInPlace(args: SlicesManagerUpsertHostedSliceScrenshotsArgs): Promise<SharedSlice>;
184
177
  private _removeSliceFromCustomTypes;
185
178
  }
186
179
  export {};
@@ -393,11 +393,8 @@ class SlicesManager extends BaseManager {
393
393
  });
394
394
  if (model) {
395
395
  const modelWithScreenshots = await this.updateSliceModelScreenshotsInPlace({
396
- model,
397
396
  libraryID: args.libraryID,
398
- // We are pushing it for the first time here, no remote image URLs to
399
- // use during the update.
400
- variationImageUrlMap: {}
397
+ model
401
398
  });
402
399
  const authenticationToken = await this.user.getAuthenticationToken();
403
400
  const repositoryName = await this.project.getResolvedRepositoryName();
@@ -584,14 +581,9 @@ class SlicesManager extends BaseManager {
584
581
  imageUrl: DEFAULT_SLICE_SCREENSHOT_URL
585
582
  };
586
583
  }
587
- const remoteImageUrl = (_a = args.variationImageUrlMap) == null ? void 0 : _a[variation.id];
588
- const hasScreenshotChanged = !(remoteImageUrl == null ? void 0 : remoteImageUrl.includes(createContentDigest(screenshot.data)));
584
+ const hasScreenshotChanged = !((_a = variation.imageUrl) == null ? void 0 : _a.includes(createContentDigest(screenshot.data)));
589
585
  if (!hasScreenshotChanged) {
590
- return {
591
- ...variation,
592
- // Keep the existing remote screenshot URL if it exists.
593
- imageUrl: remoteImageUrl ?? variation.imageUrl
594
- };
586
+ return variation;
595
587
  }
596
588
  const keyPrefix = [
597
589
  repositoryName,
@@ -1 +1 @@
1
- {"version":3,"file":"SlicesManager.js","sources":["../../../../src/managers/slices/SlicesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport { SliceComparator } from \"@prismicio/types-internal/lib/customtypes/diff\";\nimport {\n\tCompositeSlice,\n\tLegacySlice,\n\tSharedSlice,\n\tVariation,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tHookError,\n\tSliceAssetUpdateHook,\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceLibraryReadHookData,\n\tSliceReadHookData,\n\tSliceRenameHook,\n\tSliceRenameHookData,\n\tSliceUpdateHook,\n} from \"@slicemachine/plugin-kit\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { bufferCodec } from \"../../lib/bufferCodec\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { mockSlice } from \"../../lib/mockSlice\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { DEFAULT_SLICE_SCREENSHOT_URL } from \"../../constants/DEFAULT_SLICE_SCREENSHOT_URL\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { UnauthenticatedError, UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype SlicesManagerReadSliceLibraryReturnType = {\n\tsliceIDs: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SlicesManagerReadAllSliceLibrariesReturnType = {\n\tlibraries: {\n\t\tlibraryID: string;\n\t\tsliceIDs: string[] | undefined;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryArgs = {\n\tlibraryID: string;\n};\n\ntype SliceMachineManagerUpdateSliceArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\tmocks?: SharedSliceContent[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\tmodels: { model: SharedSlice }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesReturnType = {\n\tmodels: {\n\t\tlibraryID: string;\n\t\tmodel: SharedSlice;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceReturnType = {\n\tmodel: SharedSlice | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tuserAgent?: string;\n};\n\nexport type SliceMachineManagerPushSliceReturnType = {\n\t/**\n\t * A record of Slice variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tscreenshotURLs: Record<string, string> | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceScreenshotReturnType = {\n\tdata: Buffer | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerUpdateSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tdata: Buffer;\n};\n\ntype SliceMachineManagerDeleteSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksReturnType = {\n\tmocks?: SharedSliceContent[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tmocks: SharedSliceContent[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype SlicesManagerUpsertHostedSliceScreenshotsArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\t/**\n\t * A map of variation IDs to remote screenshot URLs. These URLs are used to\n\t * detect if a screenshot has changed when comparing with local ones and to\n\t * push slices with the current screenshot. If a matching screenshot is not\n\t * found in this map, the current local screenshot is uploaded again.\n\t */\n\tvariationImageUrlMap: Record<string, string>;\n};\n\ntype SliceMachineManagerDeleteSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerDeleteSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerRenameSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\t/**\n\t * Current ID of the variation to rename.\n\t */\n\tvariationID: string;\n\tmodel: Variation;\n};\n\ntype SliceMachineManagerRenameSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerDeleteSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerDeleteSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {\n\tmodel: CompositeSlice | LegacySlice;\n\tsrc: {\n\t\tcustomTypeID: string;\n\t\ttabID: string;\n\t\tsliceZoneID: string;\n\t\tsliceID: string;\n\t};\n\tdest: {\n\t\tlibraryID: string;\n\t\tsliceID: string;\n\t\tvariationName: string;\n\t\tvariationID: string;\n\t};\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class SlicesManager extends BaseManager {\n\tasync readSliceLibrary(\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SlicesManagerReadSliceLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Should validation happen at the `callHook` level?\n\t\t// Including validation at the hook level would ensure\n\t\t// hook-based actions are validated.\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tsliceIDs: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tsliceIDs: data[0]?.sliceIDs ?? [],\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync readAllSliceLibraries(): Promise<SlicesManagerReadAllSliceLibrariesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SlicesManagerReadAllSliceLibrariesReturnType = {\n\t\t\tlibraries: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\tres.libraries.push({\n\t\t\t\tlibraryID,\n\t\t\t\tsliceIDs,\n\t\t\t});\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlicesForLibrary(\n\t\targs: SliceMachineManagerReadAllSlicesForLibraryArgs,\n\t): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\t\tres.errors.push(...errors);\n\n\t\tif (sliceIDs) {\n\t\t\tfor (const sliceID of sliceIDs) {\n\t\t\t\tconst { model, errors } = await this.readSlice({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t\tres.errors.push(...errors);\n\n\t\t\t\tif (model) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SliceMachineManagerReadAllSlicesReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { models, errors } = await this.readAllSlicesForLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors.push(...errors);\n\n\t\t\tfor (const model of models) {\n\t\t\t\tres.models.push({\n\t\t\t\t\tlibraryID,\n\t\t\t\t\tmodel: model.model,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createSlice(\n\t\targs: SliceCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:create\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: mockSlice({ model: args.model }),\n\t\t};\n\n\t\tconst { errors: updateSliceHookErrors } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceHookErrors],\n\t\t};\n\t}\n\n\tasync readSlice(\n\t\targs: SliceReadHookData,\n\t): Promise<SliceMachineManagerReadSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: SharedSlice,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors: errors.map((error) => {\n\t\t\t\terror.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;\n\n\t\t\t\treturn error;\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync updateSlice(\n\t\targs: SliceMachineManagerUpdateSliceArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { mocks: previousMocks } = await this.readSliceMocks({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst { model: previousModel } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updatedMocks = mockSlice({\n\t\t\tmodel: args.model,\n\t\t\tmocks: previousMocks,\n\t\t\tdiff: SliceComparator.compare(previousModel, args.model),\n\t\t});\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: updatedMocks,\n\t\t};\n\n\t\tconst { errors: updateSliceMocksHookResult } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceMocksHookResult],\n\t\t};\n\t}\n\n\tasync renameSlice(\n\t\targs: SliceRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSlice(\n\t\targs: SliceMachineManagerDeleteSliceArgs,\n\t): Promise<SliceMachineManagerDeleteSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst { errors: deleteSliceErrors } =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:delete\", {\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t});\n\n\t\t\t// Do not update custom types if slice deletion failed\n\t\t\tif (deleteSliceErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: deleteSliceErrors,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: updateCustomTypeErrors } =\n\t\t\t\tawait this._removeSliceFromCustomTypes(args.sliceID);\n\n\t\t\treturn {\n\t\t\t\terrors: updateCustomTypeErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync renameSliceVariation(\n\t\targs: SliceMachineManagerRenameSliceVariationArgs,\n\t): Promise<SliceMachineManagerRenameSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Remove when we support renaming variation ID, see: DT-1708\n\t\tif (args.variationID !== args.model.id) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Find and rename the variation\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.map((variation) => {\n\t\t\t\t\tif (variation.id === args.variationID) {\n\t\t\t\t\t\t// Matches the slice we want to rename\n\t\t\t\t\t\treturn args.model;\n\t\t\t\t\t} else if (variation.id === args.model.id) {\n\t\t\t\t\t\t// Matches any other slice that has the ID of the renamed variation and throw.\n\t\t\t\t\t\t// This should be validated on the frontend first for better UX, this is only backend validation.\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot rename variation \\`${args.variationID}\\` to \\`${args.model.id}\\`. A variation already exists with that ID in slice \\`${args.sliceID}\\` from library \\`${args.libraryID}\\`, try deleting it first or choose another variation ID to rename that slice.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn variation;\n\t\t\t\t}),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// If variation ID has changed, we need to rename assets accordingly\n\t\t\tconst assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];\n\t\t\tif (args.variationID !== args.model.id) {\n\t\t\t\t// Renaming screenshot\n\t\t\t\tconst { data: screenshot, errors: readSliceScreenshotErrors } =\n\t\t\t\t\tawait this.readSliceScreenshot({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceScreenshotErrors);\n\n\t\t\t\tif (screenshot) {\n\t\t\t\t\t// Delete old ID screenshot\n\t\t\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.deleteSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...deleteSliceScreenshotErrors);\n\n\t\t\t\t\t// Create new ID screenshot\n\t\t\t\t\tconst { errors: updateSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.model.id,\n\t\t\t\t\t\t\tdata: screenshot,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceScreenshotErrors);\n\t\t\t\t}\n\n\t\t\t\t// Renaming mocks\n\t\t\t\tconst { mocks, errors: readSliceMocksErrors } =\n\t\t\t\t\tawait this.readSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceMocksErrors);\n\n\t\t\t\tif (mocks?.length) {\n\t\t\t\t\tconst { errors: updateSliceMocksErrors } =\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tmocks: mocks.map((mock) => {\n\t\t\t\t\t\t\t\tif (mock.variation === args.variationID) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...mock,\n\t\t\t\t\t\t\t\t\t\tvariation: args.model.id,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn mock;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceMocksErrors);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync deleteSliceVariation(\n\t\targs: SliceMachineManagerDeleteSliceVariationArgs,\n\t): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Remove variation from model and update it\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.filter(\n\t\t\t\t\t(variation) => variation.id !== args.variationID,\n\t\t\t\t),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// Cleanup deleted variation screenshot\n\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\tawait this.deleteSliceScreenshot(args);\n\n\t\t\t// Cleanup deleted variation mocks\n\t\t\tconst { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(\n\t\t\t\t{\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t},\n\t\t\t);\n\t\t\tlet updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType[\"errors\"] =\n\t\t\t\t[];\n\t\t\tif (mocks?.length) {\n\t\t\t\tupdateSliceMocksErrors = (\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tmocks: mocks.filter((mock) => mock.variation !== args.variationID),\n\t\t\t\t\t})\n\t\t\t\t).errors;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors: [\n\t\t\t\t\t...deleteSliceScreenshotErrors,\n\t\t\t\t\t...readSliceMocksErrors,\n\t\t\t\t\t...updateSliceMocksErrors,\n\t\t\t\t],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync convertLegacySliceToSharedSlice(\n\t\targs: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,\n\t): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {\n\t\tconst errors: (DecodeError | HookError)[] = [];\n\n\t\tconst { model: maybeExistingSlice } = await this.readSlice({\n\t\t\tlibraryID: args.dest.libraryID,\n\t\t\tsliceID: args.dest.sliceID,\n\t\t});\n\n\t\tconst legacySliceAsVariation: Variation = {\n\t\t\tid: args.dest.variationID,\n\t\t\tname: args.dest.variationName,\n\t\t\tdescription: args.dest.variationName,\n\t\t\timageUrl: \"\",\n\t\t\tdocURL: \"\",\n\t\t\tversion: \"initial\",\n\t\t\tprimary: {},\n\t\t\titems: {},\n\t\t};\n\n\t\tswitch (args.model.type) {\n\t\t\tcase \"Slice\":\n\t\t\t\tlegacySliceAsVariation.primary = args.model[\"non-repeat\"];\n\t\t\t\tlegacySliceAsVariation.items = args.model.repeat;\n\t\t\t\tbreak;\n\n\t\t\tcase \"Group\":\n\t\t\t\tlegacySliceAsVariation.items = args.model.config?.fields ?? {};\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tlegacySliceAsVariation.primary = { [args.src.sliceID]: args.model };\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Convert as a slice variation, or merge against an existing slice variation\n\t\tif (maybeExistingSlice) {\n\t\t\tconst maybeVariation = maybeExistingSlice.variations.find(\n\t\t\t\t(variation) => variation.id === args.dest.variationID,\n\t\t\t);\n\n\t\t\t// If we're not merging against an existing slice variation, then we need to insert the new variation\n\t\t\tif (!maybeVariation) {\n\t\t\t\tmaybeExistingSlice.variations = [\n\t\t\t\t\t...maybeExistingSlice.variations,\n\t\t\t\t\tlegacySliceAsVariation,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tmaybeExistingSlice.legacyPaths ||= {};\n\t\t\tmaybeExistingSlice.legacyPaths[\n\t\t\t\t`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`\n\t\t\t] = args.dest.variationID;\n\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: maybeExistingSlice,\n\t\t\t});\n\t\t} else {\n\t\t\t// Convert to new shared slice\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: {\n\t\t\t\t\tid: args.dest.sliceID,\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t\tname: args.dest.sliceID,\n\t\t\t\t\tlegacyPaths: {\n\t\t\t\t\t\t[`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`]:\n\t\t\t\t\t\t\targs.dest.variationID,\n\t\t\t\t\t},\n\t\t\t\t\tvariations: [legacySliceAsVariation],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Update source custom type\n\t\tconst { model: customType, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readCustomType({\n\t\t\t\tid: args.src.customTypeID,\n\t\t\t});\n\t\terrors.push(...customTypeReadErrors);\n\n\t\tif (customType) {\n\t\t\tconst field = customType.json[args.src.tabID][args.src.sliceZoneID];\n\n\t\t\t// Convert legacy slice definition in slice zone to shared slice reference\n\t\t\tif (field.type === \"Slices\" && field.config?.choices) {\n\t\t\t\tdelete field.config.choices[args.src.sliceID];\n\t\t\t\tfield.config.choices[args.dest.sliceID] = {\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: customTypeUpdateErrors } =\n\t\t\t\tawait this.customTypes.updateCustomType({ model: customType });\n\t\t\terrors.push(...customTypeUpdateErrors);\n\t\t}\n\n\t\treturn { errors };\n\t}\n\n\t/**\n\t * @returns Record of variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tasync pushSlice(\n\t\targs: SliceMachineManagerPushSliceArgs,\n\t): Promise<SliceMachineManagerPushSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst modelWithScreenshots =\n\t\t\t\tawait this.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t// We are pushing it for the first time here, no remote image URLs to\n\t\t\t\t\t// use during the update.\n\t\t\t\t\tvariationImageUrlMap: {},\n\t\t\t\t});\n\n\t\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Slice already exists on the repository.\n\t\t\t\tawait client.getSharedSliceByID(args.sliceID);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateSharedSlice(modelWithScreenshots);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If the Slice doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertSharedSlice(modelWithScreenshots);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push Slices to this Prismic repository.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Pass the error through if it isn't the one we were expecting.\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst screenshotURLs: Record<string, string> = {};\n\t\t\tfor (const variation of modelWithScreenshots.variations) {\n\t\t\t\tscreenshotURLs[variation.id] = variation.imageUrl;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tscreenshotURLs,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tscreenshotURLs: undefined,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync readSliceScreenshot(\n\t\targs: SliceMachineManagerReadSliceScreenshotArgs,\n\t): Promise<SliceMachineManagerReadSliceScreenshotReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: bufferCodec,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tdata: data[0]?.data,\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync updateSliceScreenshot(\n\t\targs: SliceMachineManagerUpdateSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: `screenshot-${args.variationID}.png`,\n\t\t\t\t\tdata: args.data,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSliceScreenshot(\n\t\targs: SliceMachineManagerDeleteSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:delete\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readSliceMocks(\n\t\targs: SliceMachineManagerReadSliceMocksArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `mocks.json`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: t.array(SharedSliceContent),\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...hookResult,\n\t\t\t\t// Convert the asset data from a Buffer to JSON\n\t\t\t\t// to prepare it for validation.\n\t\t\t\tdata: hookResult.data.map((result) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tdata: JSON.parse(result.data.toString()),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocks: data[0]?.data,\n\t\t\t\terrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocks: [],\n\t\t\t\terrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync updateSliceMocks(\n\t\targs: SliceMachineManagerUpdateSliceMocksArgs,\n\t): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocks, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\t// TODO: Remove\n\tasync readSliceMocksConfig(\n\t\targs: SliceMachineManagerReadSliceMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync fetchRemoteSlices(): Promise<SharedSlice[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllSharedSlices();\n\t}\n\n\tasync updateSliceModelScreenshotsInPlace(\n\t\targs: SlicesManagerUpsertHostedSliceScreenshotsArgs,\n\t): Promise<SharedSlice> {\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst variations = await Promise.all(\n\t\t\targs.model.variations.map(async (variation) => {\n\t\t\t\tconst screenshot = await this.readSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.model.id,\n\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t});\n\n\t\t\t\t// If there's no screenshot, delete it by replacing it with the default screenshot\n\t\t\t\tif (!screenshot.data) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\timageUrl: DEFAULT_SLICE_SCREENSHOT_URL,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst remoteImageUrl = args.variationImageUrlMap?.[variation.id];\n\t\t\t\tconst hasScreenshotChanged = !remoteImageUrl?.includes(\n\t\t\t\t\tcreateContentDigest(screenshot.data),\n\t\t\t\t);\n\n\t\t\t\t// If screenshot hasn't changed, no need to upload it again, just use\n\t\t\t\t// the existing variation with the remote image URL if it exists.\n\t\t\t\tif (!hasScreenshotChanged) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\t// Keep the existing remote screenshot URL if it exists.\n\t\t\t\t\t\timageUrl: remoteImageUrl ?? variation.imageUrl,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst keyPrefix = [\n\t\t\t\t\trepositoryName,\n\t\t\t\t\t\"shared-slices\",\n\t\t\t\t\targs.model.id,\n\t\t\t\t\tvariation.id,\n\t\t\t\t].join(\"/\");\n\n\t\t\t\tconst uploadedScreenshot = await this.screenshots.uploadScreenshot({\n\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\tkeyPrefix,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\t...variation,\n\t\t\t\t\timageUrl: uploadedScreenshot.url,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\t...args.model,\n\t\t\tvariations,\n\t\t};\n\t}\n\n\tprivate async _removeSliceFromCustomTypes(sliceID: string) {\n\t\tconst { models, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readAllCustomTypes();\n\n\t\t// Successfully update all custom types or throw\n\t\tawait Promise.all(\n\t\t\tmodels.map(async (customType) => {\n\t\t\t\tconst updatedJsonModel = Object.entries(customType.model.json).reduce(\n\t\t\t\t\t(tabAccumulator, [tabKey, tab]) => {\n\t\t\t\t\t\tconst updatedTabFields = Object.entries(tab).reduce(\n\t\t\t\t\t\t\t(fieldAccumulator, [fieldKey, field]) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tfield.config === undefined ||\n\t\t\t\t\t\t\t\t\tfield.type !== \"Slices\" ||\n\t\t\t\t\t\t\t\t\tfield.config.choices === undefined\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn { ...fieldAccumulator, [fieldKey]: field };\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filteredChoices = Object.entries(\n\t\t\t\t\t\t\t\t\tfield.config.choices,\n\t\t\t\t\t\t\t\t).reduce((choiceAccumulator, [choiceKey, choice]) => {\n\t\t\t\t\t\t\t\t\tif (choiceKey === sliceID) {\n\t\t\t\t\t\t\t\t\t\treturn choiceAccumulator;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn { ...choiceAccumulator, [choiceKey]: choice };\n\t\t\t\t\t\t\t\t}, {});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...fieldAccumulator,\n\t\t\t\t\t\t\t\t\t[fieldKey]: {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tconfig: { ...field.config, choices: filteredChoices },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn { ...tabAccumulator, [tabKey]: updatedTabFields };\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t);\n\n\t\t\t\tawait this.customTypes.updateCustomType({\n\t\t\t\t\tmodel: { ...customType.model, json: updatedJsonModel },\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\n\t\treturn { errors: customTypeReadErrors };\n\t}\n}\n"],"names":["errors"],"mappings":";;;;;;;;;;;;;;;;AAwNM,MAAO,sBAAsB,YAAW;AAAA,EAC7C,MAAM,iBACL,MAA8B;;AAE9B,6BAAyB,KAAK,wBAAwB;AAKtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,sBACA,IAAI;AAEL,UAAM,EAAE,MAAM,OAAA,IAAW,iBACxB,EAAE,KAAK;AAAA,MACN,IAAI,EAAE;AAAA,MACN,UAAU,EAAE,MAAM,EAAE,MAAM;AAAA,IAAA,CAC1B,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,YAAU,UAAK,CAAC,MAAN,mB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AAM,IAAI,EAAE,OAC9D,CAAC,gBAAgB,CAAC,QAAQ,GAAG,MAAK;AAC3B,cAAA,mBAAmB,OAAO,QAAQ,GAAG,EAAE,OAC5C,CAAC,kBAAkB,CAAC,UAAU,KAAK,MAAK;AAEtC,cAAA,MAAM,WAAW,UACjB,MAAM,SAAS,YACf,MAAM,OAAO,YAAY,QACxB;AACD,mBAAO,EAAE,GAAG,kBAAkB,CAAC,QAAQ,GAAG,MAAK;AAAA,UAChD;AAEA,gBAAM,kBAAkB,OAAO,QAC9B,MAAM,OAAO,OAAO,EACnB,OAAO,CAAC,mBAAmB,CAAC,WAAW,MAAM,MAAK;AACnD,gBAAI,cAAc,SAAS;AACnB,qBAAA;AAAA,YACR;AAEA,mBAAO,EAAE,GAAG,mBAAmB,CAAC,SAAS,GAAG,OAAM;AAAA,UACnD,GAAG,CAAE,CAAA;AAEE,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,CAAC,QAAQ,GAAG;AAAA,cACX,GAAG;AAAA,cACH,QAAQ,EAAE,GAAG,MAAM,QAAQ,SAAS,gBAAiB;AAAA,YACrD;AAAA,UAAA;AAAA,QAEH,GACA,CAAE,CAAA;AAGH,eAAO,EAAE,GAAG,gBAAgB,CAAC,MAAM,GAAG,iBAAgB;AAAA,MACvD,GACA,CAAE,CAAA;AAGG,YAAA,KAAK,YAAY,iBAAiB;AAAA,QACvC,OAAO,EAAE,GAAG,WAAW,OAAO,MAAM,iBAAkB;AAAA,MAAA,CACtD;AAAA,IACD,CAAA,CAAC;AAGI,WAAA,EAAE,QAAQ;EAClB;AACA;"}
1
+ {"version":3,"file":"SlicesManager.js","sources":["../../../../src/managers/slices/SlicesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport { SliceComparator } from \"@prismicio/types-internal/lib/customtypes/diff\";\nimport {\n\tCompositeSlice,\n\tLegacySlice,\n\tSharedSlice,\n\tVariation,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tHookError,\n\tSliceAssetUpdateHook,\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceLibraryReadHookData,\n\tSliceReadHookData,\n\tSliceRenameHook,\n\tSliceRenameHookData,\n\tSliceUpdateHook,\n} from \"@slicemachine/plugin-kit\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { bufferCodec } from \"../../lib/bufferCodec\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { mockSlice } from \"../../lib/mockSlice\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { DEFAULT_SLICE_SCREENSHOT_URL } from \"../../constants/DEFAULT_SLICE_SCREENSHOT_URL\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { UnauthenticatedError, UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype SlicesManagerReadSliceLibraryReturnType = {\n\tsliceIDs: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SlicesManagerReadAllSliceLibrariesReturnType = {\n\tlibraries: {\n\t\tlibraryID: string;\n\t\tsliceIDs: string[] | undefined;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryArgs = {\n\tlibraryID: string;\n};\n\ntype SliceMachineManagerUpdateSliceArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\tmocks?: SharedSliceContent[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\tmodels: { model: SharedSlice }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesReturnType = {\n\tmodels: {\n\t\tlibraryID: string;\n\t\tmodel: SharedSlice;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceReturnType = {\n\tmodel: SharedSlice | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tuserAgent?: string;\n};\n\nexport type SliceMachineManagerPushSliceReturnType = {\n\t/**\n\t * A record of Slice variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tscreenshotURLs: Record<string, string> | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceScreenshotReturnType = {\n\tdata: Buffer | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerUpdateSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tdata: Buffer;\n};\n\ntype SliceMachineManagerDeleteSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksReturnType = {\n\tmocks?: SharedSliceContent[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tmocks: SharedSliceContent[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype SlicesManagerUpsertHostedSliceScrenshotsArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n};\n\ntype SliceMachineManagerDeleteSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerDeleteSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerRenameSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\t/**\n\t * Current ID of the variation to rename.\n\t */\n\tvariationID: string;\n\tmodel: Variation;\n};\n\ntype SliceMachineManagerRenameSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerDeleteSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerDeleteSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {\n\tmodel: CompositeSlice | LegacySlice;\n\tsrc: {\n\t\tcustomTypeID: string;\n\t\ttabID: string;\n\t\tsliceZoneID: string;\n\t\tsliceID: string;\n\t};\n\tdest: {\n\t\tlibraryID: string;\n\t\tsliceID: string;\n\t\tvariationName: string;\n\t\tvariationID: string;\n\t};\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class SlicesManager extends BaseManager {\n\tasync readSliceLibrary(\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SlicesManagerReadSliceLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Should validation happen at the `callHook` level?\n\t\t// Including validation at the hook level would ensure\n\t\t// hook-based actions are validated.\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tsliceIDs: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tsliceIDs: data[0]?.sliceIDs ?? [],\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync readAllSliceLibraries(): Promise<SlicesManagerReadAllSliceLibrariesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SlicesManagerReadAllSliceLibrariesReturnType = {\n\t\t\tlibraries: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\tres.libraries.push({\n\t\t\t\tlibraryID,\n\t\t\t\tsliceIDs,\n\t\t\t});\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlicesForLibrary(\n\t\targs: SliceMachineManagerReadAllSlicesForLibraryArgs,\n\t): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\t\tres.errors.push(...errors);\n\n\t\tif (sliceIDs) {\n\t\t\tfor (const sliceID of sliceIDs) {\n\t\t\t\tconst { model, errors } = await this.readSlice({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t\tres.errors.push(...errors);\n\n\t\t\t\tif (model) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SliceMachineManagerReadAllSlicesReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { models, errors } = await this.readAllSlicesForLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors.push(...errors);\n\n\t\t\tfor (const model of models) {\n\t\t\t\tres.models.push({\n\t\t\t\t\tlibraryID,\n\t\t\t\t\tmodel: model.model,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createSlice(\n\t\targs: SliceCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:create\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: mockSlice({ model: args.model }),\n\t\t};\n\n\t\tconst { errors: updateSliceHookErrors } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceHookErrors],\n\t\t};\n\t}\n\n\tasync readSlice(\n\t\targs: SliceReadHookData,\n\t): Promise<SliceMachineManagerReadSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: SharedSlice,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors: errors.map((error) => {\n\t\t\t\terror.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;\n\n\t\t\t\treturn error;\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync updateSlice(\n\t\targs: SliceMachineManagerUpdateSliceArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { mocks: previousMocks } = await this.readSliceMocks({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst { model: previousModel } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updatedMocks = mockSlice({\n\t\t\tmodel: args.model,\n\t\t\tmocks: previousMocks,\n\t\t\tdiff: SliceComparator.compare(previousModel, args.model),\n\t\t});\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: updatedMocks,\n\t\t};\n\n\t\tconst { errors: updateSliceMocksHookResult } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceMocksHookResult],\n\t\t};\n\t}\n\n\tasync renameSlice(\n\t\targs: SliceRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSlice(\n\t\targs: SliceMachineManagerDeleteSliceArgs,\n\t): Promise<SliceMachineManagerDeleteSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst { errors: deleteSliceErrors } =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:delete\", {\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t});\n\n\t\t\t// Do not update custom types if slice deletion failed\n\t\t\tif (deleteSliceErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: deleteSliceErrors,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: updateCustomTypeErrors } =\n\t\t\t\tawait this._removeSliceFromCustomTypes(args.sliceID);\n\n\t\t\treturn {\n\t\t\t\terrors: updateCustomTypeErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync renameSliceVariation(\n\t\targs: SliceMachineManagerRenameSliceVariationArgs,\n\t): Promise<SliceMachineManagerRenameSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Remove when we support renaming variation ID, see: DT-1708\n\t\tif (args.variationID !== args.model.id) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Find and rename the variation\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.map((variation) => {\n\t\t\t\t\tif (variation.id === args.variationID) {\n\t\t\t\t\t\t// Matches the slice we want to rename\n\t\t\t\t\t\treturn args.model;\n\t\t\t\t\t} else if (variation.id === args.model.id) {\n\t\t\t\t\t\t// Matches any other slice that has the ID of the renamed variation and throw.\n\t\t\t\t\t\t// This should be validated on the frontend first for better UX, this is only backend validation.\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot rename variation \\`${args.variationID}\\` to \\`${args.model.id}\\`. A variation already exists with that ID in slice \\`${args.sliceID}\\` from library \\`${args.libraryID}\\`, try deleting it first or choose another variation ID to rename that slice.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn variation;\n\t\t\t\t}),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// If variation ID has changed, we need to rename assets accordingly\n\t\t\tconst assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];\n\t\t\tif (args.variationID !== args.model.id) {\n\t\t\t\t// Renaming screenshot\n\t\t\t\tconst { data: screenshot, errors: readSliceScreenshotErrors } =\n\t\t\t\t\tawait this.readSliceScreenshot({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceScreenshotErrors);\n\n\t\t\t\tif (screenshot) {\n\t\t\t\t\t// Delete old ID screenshot\n\t\t\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.deleteSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...deleteSliceScreenshotErrors);\n\n\t\t\t\t\t// Create new ID screenshot\n\t\t\t\t\tconst { errors: updateSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.model.id,\n\t\t\t\t\t\t\tdata: screenshot,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceScreenshotErrors);\n\t\t\t\t}\n\n\t\t\t\t// Renaming mocks\n\t\t\t\tconst { mocks, errors: readSliceMocksErrors } =\n\t\t\t\t\tawait this.readSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceMocksErrors);\n\n\t\t\t\tif (mocks?.length) {\n\t\t\t\t\tconst { errors: updateSliceMocksErrors } =\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tmocks: mocks.map((mock) => {\n\t\t\t\t\t\t\t\tif (mock.variation === args.variationID) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...mock,\n\t\t\t\t\t\t\t\t\t\tvariation: args.model.id,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn mock;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceMocksErrors);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync deleteSliceVariation(\n\t\targs: SliceMachineManagerDeleteSliceVariationArgs,\n\t): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Remove variation from model and update it\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.filter(\n\t\t\t\t\t(variation) => variation.id !== args.variationID,\n\t\t\t\t),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// Cleanup deleted variation screenshot\n\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\tawait this.deleteSliceScreenshot(args);\n\n\t\t\t// Cleanup deleted variation mocks\n\t\t\tconst { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(\n\t\t\t\t{\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t},\n\t\t\t);\n\t\t\tlet updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType[\"errors\"] =\n\t\t\t\t[];\n\t\t\tif (mocks?.length) {\n\t\t\t\tupdateSliceMocksErrors = (\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tmocks: mocks.filter((mock) => mock.variation !== args.variationID),\n\t\t\t\t\t})\n\t\t\t\t).errors;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors: [\n\t\t\t\t\t...deleteSliceScreenshotErrors,\n\t\t\t\t\t...readSliceMocksErrors,\n\t\t\t\t\t...updateSliceMocksErrors,\n\t\t\t\t],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync convertLegacySliceToSharedSlice(\n\t\targs: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,\n\t): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {\n\t\tconst errors: (DecodeError | HookError)[] = [];\n\n\t\tconst { model: maybeExistingSlice } = await this.readSlice({\n\t\t\tlibraryID: args.dest.libraryID,\n\t\t\tsliceID: args.dest.sliceID,\n\t\t});\n\n\t\tconst legacySliceAsVariation: Variation = {\n\t\t\tid: args.dest.variationID,\n\t\t\tname: args.dest.variationName,\n\t\t\tdescription: args.dest.variationName,\n\t\t\timageUrl: \"\",\n\t\t\tdocURL: \"\",\n\t\t\tversion: \"initial\",\n\t\t\tprimary: {},\n\t\t\titems: {},\n\t\t};\n\n\t\tswitch (args.model.type) {\n\t\t\tcase \"Slice\":\n\t\t\t\tlegacySliceAsVariation.primary = args.model[\"non-repeat\"];\n\t\t\t\tlegacySliceAsVariation.items = args.model.repeat;\n\t\t\t\tbreak;\n\n\t\t\tcase \"Group\":\n\t\t\t\tlegacySliceAsVariation.items = args.model.config?.fields ?? {};\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tlegacySliceAsVariation.primary = { [args.src.sliceID]: args.model };\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Convert as a slice variation, or merge against an existing slice variation\n\t\tif (maybeExistingSlice) {\n\t\t\tconst maybeVariation = maybeExistingSlice.variations.find(\n\t\t\t\t(variation) => variation.id === args.dest.variationID,\n\t\t\t);\n\n\t\t\t// If we're not merging against an existing slice variation, then we need to insert the new variation\n\t\t\tif (!maybeVariation) {\n\t\t\t\tmaybeExistingSlice.variations = [\n\t\t\t\t\t...maybeExistingSlice.variations,\n\t\t\t\t\tlegacySliceAsVariation,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tmaybeExistingSlice.legacyPaths ||= {};\n\t\t\tmaybeExistingSlice.legacyPaths[\n\t\t\t\t`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`\n\t\t\t] = args.dest.variationID;\n\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: maybeExistingSlice,\n\t\t\t});\n\t\t} else {\n\t\t\t// Convert to new shared slice\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: {\n\t\t\t\t\tid: args.dest.sliceID,\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t\tname: args.dest.sliceID,\n\t\t\t\t\tlegacyPaths: {\n\t\t\t\t\t\t[`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`]:\n\t\t\t\t\t\t\targs.dest.variationID,\n\t\t\t\t\t},\n\t\t\t\t\tvariations: [legacySliceAsVariation],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Update source custom type\n\t\tconst { model: customType, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readCustomType({\n\t\t\t\tid: args.src.customTypeID,\n\t\t\t});\n\t\terrors.push(...customTypeReadErrors);\n\n\t\tif (customType) {\n\t\t\tconst field = customType.json[args.src.tabID][args.src.sliceZoneID];\n\n\t\t\t// Convert legacy slice definition in slice zone to shared slice reference\n\t\t\tif (field.type === \"Slices\" && field.config?.choices) {\n\t\t\t\tdelete field.config.choices[args.src.sliceID];\n\t\t\t\tfield.config.choices[args.dest.sliceID] = {\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: customTypeUpdateErrors } =\n\t\t\t\tawait this.customTypes.updateCustomType({ model: customType });\n\t\t\terrors.push(...customTypeUpdateErrors);\n\t\t}\n\n\t\treturn { errors };\n\t}\n\n\t/**\n\t * @returns Record of variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tasync pushSlice(\n\t\targs: SliceMachineManagerPushSliceArgs,\n\t): Promise<SliceMachineManagerPushSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst modelWithScreenshots =\n\t\t\t\tawait this.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel,\n\t\t\t\t});\n\n\t\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Slice already exists on the repository.\n\t\t\t\tawait client.getSharedSliceByID(args.sliceID);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateSharedSlice(modelWithScreenshots);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If the Slice doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertSharedSlice(modelWithScreenshots);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push Slices to this Prismic repository.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Pass the error through if it isn't the one we were expecting.\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst screenshotURLs: Record<string, string> = {};\n\t\t\tfor (const variation of modelWithScreenshots.variations) {\n\t\t\t\tscreenshotURLs[variation.id] = variation.imageUrl;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tscreenshotURLs,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tscreenshotURLs: undefined,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync readSliceScreenshot(\n\t\targs: SliceMachineManagerReadSliceScreenshotArgs,\n\t): Promise<SliceMachineManagerReadSliceScreenshotReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: bufferCodec,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tdata: data[0]?.data,\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync updateSliceScreenshot(\n\t\targs: SliceMachineManagerUpdateSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: `screenshot-${args.variationID}.png`,\n\t\t\t\t\tdata: args.data,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSliceScreenshot(\n\t\targs: SliceMachineManagerDeleteSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:delete\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readSliceMocks(\n\t\targs: SliceMachineManagerReadSliceMocksArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `mocks.json`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: t.array(SharedSliceContent),\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...hookResult,\n\t\t\t\t// Convert the asset data from a Buffer to JSON\n\t\t\t\t// to prepare it for validation.\n\t\t\t\tdata: hookResult.data.map((result) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tdata: JSON.parse(result.data.toString()),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocks: data[0]?.data,\n\t\t\t\terrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocks: [],\n\t\t\t\terrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync updateSliceMocks(\n\t\targs: SliceMachineManagerUpdateSliceMocksArgs,\n\t): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocks, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\t// TODO: Remove\n\tasync readSliceMocksConfig(\n\t\targs: SliceMachineManagerReadSliceMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync fetchRemoteSlices(): Promise<SharedSlice[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllSharedSlices();\n\t}\n\n\tasync updateSliceModelScreenshotsInPlace(\n\t\targs: SlicesManagerUpsertHostedSliceScrenshotsArgs,\n\t): Promise<SharedSlice> {\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst variations = await Promise.all(\n\t\t\targs.model.variations.map(async (variation) => {\n\t\t\t\tconst screenshot = await this.readSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.model.id,\n\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t});\n\n\t\t\t\t// If there's no screenshot, delete it by replacing it with the default screenshot\n\t\t\t\tif (!screenshot.data) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\timageUrl: DEFAULT_SLICE_SCREENSHOT_URL,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst hasScreenshotChanged = !variation.imageUrl?.includes(\n\t\t\t\t\tcreateContentDigest(screenshot.data),\n\t\t\t\t);\n\n\t\t\t\t// If screenshot hasn't changed, do nothing\n\t\t\t\tif (!hasScreenshotChanged) {\n\t\t\t\t\treturn variation;\n\t\t\t\t}\n\n\t\t\t\tconst keyPrefix = [\n\t\t\t\t\trepositoryName,\n\t\t\t\t\t\"shared-slices\",\n\t\t\t\t\targs.model.id,\n\t\t\t\t\tvariation.id,\n\t\t\t\t].join(\"/\");\n\n\t\t\t\tconst uploadedScreenshot = await this.screenshots.uploadScreenshot({\n\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\tkeyPrefix,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\t...variation,\n\t\t\t\t\timageUrl: uploadedScreenshot.url,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\t...args.model,\n\t\t\tvariations,\n\t\t};\n\t}\n\n\tprivate async _removeSliceFromCustomTypes(sliceID: string) {\n\t\tconst { models, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readAllCustomTypes();\n\n\t\t// Successfully update all custom types or throw\n\t\tawait Promise.all(\n\t\t\tmodels.map(async (customType) => {\n\t\t\t\tconst updatedJsonModel = Object.entries(customType.model.json).reduce(\n\t\t\t\t\t(tabAccumulator, [tabKey, tab]) => {\n\t\t\t\t\t\tconst updatedTabFields = Object.entries(tab).reduce(\n\t\t\t\t\t\t\t(fieldAccumulator, [fieldKey, field]) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tfield.config === undefined ||\n\t\t\t\t\t\t\t\t\tfield.type !== \"Slices\" ||\n\t\t\t\t\t\t\t\t\tfield.config.choices === undefined\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn { ...fieldAccumulator, [fieldKey]: field };\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filteredChoices = Object.entries(\n\t\t\t\t\t\t\t\t\tfield.config.choices,\n\t\t\t\t\t\t\t\t).reduce((choiceAccumulator, [choiceKey, choice]) => {\n\t\t\t\t\t\t\t\t\tif (choiceKey === sliceID) {\n\t\t\t\t\t\t\t\t\t\treturn choiceAccumulator;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn { ...choiceAccumulator, [choiceKey]: choice };\n\t\t\t\t\t\t\t\t}, {});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...fieldAccumulator,\n\t\t\t\t\t\t\t\t\t[fieldKey]: {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tconfig: { ...field.config, choices: filteredChoices },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn { ...tabAccumulator, [tabKey]: updatedTabFields };\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t);\n\n\t\t\t\tawait this.customTypes.updateCustomType({\n\t\t\t\t\tmodel: { ...customType.model, json: updatedJsonModel },\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\n\t\treturn { errors: customTypeReadErrors };\n\t}\n}\n"],"names":["errors"],"mappings":";;;;;;;;;;;;;;;;AAiNM,MAAO,sBAAsB,YAAW;AAAA,EAC7C,MAAM,iBACL,MAA8B;;AAE9B,6BAAyB,KAAK,wBAAwB;AAKtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,sBACA,IAAI;AAEL,UAAM,EAAE,MAAM,OAAA,IAAW,iBACxB,EAAE,KAAK;AAAA,MACN,IAAI,EAAE;AAAA,MACN,UAAU,EAAE,MAAM,EAAE,MAAM;AAAA,IAAA,CAC1B,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,YAAU,UAAK,CAAC,MAAN,mBAAS,aAAY,CAAE;AAAA,MACjC;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,wBAAqB;AAC1B,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAC7D,UAAA,aAAa,mBAAmB,aAAa;AAEnD,UAAM,MAAoD;AA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CAAC,mBAAmB,CAAC,WAAW,MAAM,MAAK;AACnD,gBAAI,cAAc,SAAS;AACnB,qBAAA;AAAA,YACR;AAEA,mBAAO,EAAE,GAAG,mBAAmB,CAAC,SAAS,GAAG,OAAM;AAAA,UACnD,GAAG,CAAE,CAAA;AAEE,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,CAAC,QAAQ,GAAG;AAAA,cACX,GAAG;AAAA,cACH,QAAQ,EAAE,GAAG,MAAM,QAAQ,SAAS,gBAAiB;AAAA,YACrD;AAAA,UAAA;AAAA,QAEH,GACA,CAAE,CAAA;AAGH,eAAO,EAAE,GAAG,gBAAgB,CAAC,MAAM,GAAG,iBAAgB;AAAA,MACvD,GACA,CAAE,CAAA;AAGG,YAAA,KAAK,YAAY,iBAAiB;AAAA,QACvC,OAAO,EAAE,GAAG,WAAW,OAAO,MAAM,iBAAkB;AAAA,MAAA,CACtD;AAAA,IACD,CAAA,CAAC;AAGI,WAAA,EAAE,QAAQ;EAClB;AACA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/manager",
3
- "version": "0.25.3-alpha.jp-align-radix-dependencies.1",
3
+ "version": "0.25.3-alpha.jp-unauthorized-error.3",
4
4
  "description": "Manage all aspects of a Slice Machine project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -70,7 +70,7 @@
70
70
  "@prismicio/mocks": "2.14.0",
71
71
  "@prismicio/types-internal": "3.11.2",
72
72
  "@segment/analytics-node": "^2.1.2",
73
- "@slicemachine/plugin-kit": "0.4.81-alpha.jp-align-radix-dependencies.1",
73
+ "@slicemachine/plugin-kit": "0.4.81-alpha.jp-unauthorized-error.3",
74
74
  "cookie": "^1.0.1",
75
75
  "cors": "^2.8.5",
76
76
  "execa": "^7.1.1",
@@ -319,7 +319,6 @@ export class PrismicRepositoryManager extends BaseManager {
319
319
  const modelWithScreenshots =
320
320
  await this.slices.updateSliceModelScreenshotsInPlace({
321
321
  libraryID: change.libraryID,
322
- variationImageUrlMap: change.variationImageUrlMap,
323
322
  model,
324
323
  });
325
324
 
@@ -342,7 +341,6 @@ export class PrismicRepositoryManager extends BaseManager {
342
341
  const modelWithScreenshots =
343
342
  await this.slices.updateSliceModelScreenshotsInPlace({
344
343
  libraryID: change.libraryID,
345
- variationImageUrlMap: change.variationImageUrlMap,
346
344
  model,
347
345
  });
348
346
 
@@ -124,13 +124,6 @@ type SliceChange = {
124
124
  type: "Slice";
125
125
  status: ChangeStatus;
126
126
  libraryID: string;
127
- /**
128
- * A map of variation IDs to remote screenshot URLs. These URLs are used to
129
- * detect if a screenshot has changed when comparing with local ones and to
130
- * push slices with the current screenshot. If a matching screenshot is not
131
- * found in this map, the current local screenshot is uploaded again.
132
- */
133
- variationImageUrlMap: Record<string, string>;
134
127
  };
135
128
 
136
129
  export type TransactionalMergeArgs = {
@@ -147,16 +147,9 @@ type SliceMachineManagerUpdateSliceMocksArgsReturnType = {
147
147
  errors: HookError[];
148
148
  };
149
149
 
150
- type SlicesManagerUpsertHostedSliceScreenshotsArgs = {
150
+ type SlicesManagerUpsertHostedSliceScrenshotsArgs = {
151
151
  libraryID: string;
152
152
  model: SharedSlice;
153
- /**
154
- * A map of variation IDs to remote screenshot URLs. These URLs are used to
155
- * detect if a screenshot has changed when comparing with local ones and to
156
- * push slices with the current screenshot. If a matching screenshot is not
157
- * found in this map, the current local screenshot is uploaded again.
158
- */
159
- variationImageUrlMap: Record<string, string>;
160
153
  };
161
154
 
162
155
  type SliceMachineManagerDeleteSliceArgs = {
@@ -766,11 +759,8 @@ export class SlicesManager extends BaseManager {
766
759
  if (model) {
767
760
  const modelWithScreenshots =
768
761
  await this.updateSliceModelScreenshotsInPlace({
769
- model,
770
762
  libraryID: args.libraryID,
771
- // We are pushing it for the first time here, no remote image URLs to
772
- // use during the update.
773
- variationImageUrlMap: {},
763
+ model,
774
764
  });
775
765
 
776
766
  const authenticationToken = await this.user.getAuthenticationToken();
@@ -1013,7 +1003,7 @@ export class SlicesManager extends BaseManager {
1013
1003
  }
1014
1004
 
1015
1005
  async updateSliceModelScreenshotsInPlace(
1016
- args: SlicesManagerUpsertHostedSliceScreenshotsArgs,
1006
+ args: SlicesManagerUpsertHostedSliceScrenshotsArgs,
1017
1007
  ): Promise<SharedSlice> {
1018
1008
  const repositoryName = await this.project.getResolvedRepositoryName();
1019
1009
 
@@ -1033,19 +1023,13 @@ export class SlicesManager extends BaseManager {
1033
1023
  };
1034
1024
  }
1035
1025
 
1036
- const remoteImageUrl = args.variationImageUrlMap?.[variation.id];
1037
- const hasScreenshotChanged = !remoteImageUrl?.includes(
1026
+ const hasScreenshotChanged = !variation.imageUrl?.includes(
1038
1027
  createContentDigest(screenshot.data),
1039
1028
  );
1040
1029
 
1041
- // If screenshot hasn't changed, no need to upload it again, just use
1042
- // the existing variation with the remote image URL if it exists.
1030
+ // If screenshot hasn't changed, do nothing
1043
1031
  if (!hasScreenshotChanged) {
1044
- return {
1045
- ...variation,
1046
- // Keep the existing remote screenshot URL if it exists.
1047
- imageUrl: remoteImageUrl ?? variation.imageUrl,
1048
- };
1032
+ return variation;
1049
1033
  }
1050
1034
 
1051
1035
  const keyPrefix = [