@slicemachine/manager 0.24.8 → 0.24.9-alpha.lg-ai-slice-menu-update.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/client.cjs +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/client.js +1 -1
- package/dist/_node_modules/cross-spawn/index.cjs +1 -1
- package/dist/_node_modules/cross-spawn/index.js +1 -1
- package/dist/_virtual/index2.cjs +3 -4
- package/dist/_virtual/index2.cjs.map +1 -1
- package/dist/_virtual/index2.js +2 -4
- package/dist/_virtual/index2.js.map +1 -1
- package/dist/_virtual/index3.cjs +4 -3
- package/dist/_virtual/index3.cjs.map +1 -1
- package/dist/_virtual/index3.js +4 -2
- package/dist/_virtual/index3.js.map +1 -1
- package/dist/constants/API_ENDPOINTS.cjs +8 -4
- package/dist/constants/API_ENDPOINTS.cjs.map +1 -1
- package/dist/constants/API_ENDPOINTS.d.ts +1 -0
- package/dist/constants/API_ENDPOINTS.js +8 -4
- package/dist/constants/API_ENDPOINTS.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs +36 -0
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.d.ts +1434 -0
- package/dist/managers/customTypes/CustomTypesManager.js +37 -1
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs +35 -0
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.d.ts +3 -0
- package/dist/managers/slices/SlicesManager.js +35 -0
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/package.json +4 -3
- package/src/constants/API_ENDPOINTS.ts +8 -0
- package/src/managers/customTypes/CustomTypesManager.ts +55 -1
- package/src/managers/slices/SlicesManager.ts +46 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
import * as t from "io-ts";
|
2
2
|
import * as prismicCustomTypesClient from "@prismicio/custom-types-client";
|
3
|
-
import { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
3
|
+
import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
4
|
+
import z from './../../_node_modules/zod/lib/index.js';
|
4
5
|
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized.js";
|
5
6
|
import { decodeHookResult } from "../../lib/decodeHookResult.js";
|
6
7
|
import fetch from "../../lib/fetch.js";
|
@@ -173,7 +174,42 @@ class CustomTypesManager extends BaseManager {
|
|
173
174
|
});
|
174
175
|
return await client.getAllCustomTypes();
|
175
176
|
}
|
177
|
+
async inferSlice({ imageUrl }) {
|
178
|
+
const authToken = await this.user.getAuthenticationToken();
|
179
|
+
const headers = {
|
180
|
+
Authorization: `Bearer ${authToken}`
|
181
|
+
};
|
182
|
+
const repository = await this.project.getResolvedRepositoryName();
|
183
|
+
const searchParams = new URLSearchParams({
|
184
|
+
repository
|
185
|
+
});
|
186
|
+
const url = new URL("./slices/infer", API_ENDPOINTS.CustomTypeService);
|
187
|
+
url.search = searchParams.toString();
|
188
|
+
const response = await fetch(url.toString(), {
|
189
|
+
method: "POST",
|
190
|
+
headers,
|
191
|
+
body: JSON.stringify({ imageUrl })
|
192
|
+
});
|
193
|
+
if (!response.ok) {
|
194
|
+
throw new Error(`Failed to infer slice: ${response.statusText}`);
|
195
|
+
}
|
196
|
+
const json = await response.json();
|
197
|
+
return InferSliceResponse.parse(json);
|
198
|
+
}
|
176
199
|
}
|
200
|
+
const InferSliceResponse = z.object({
|
201
|
+
slice: z.custom().transform((value, ctx) => {
|
202
|
+
const result = SharedSlice.decode(value);
|
203
|
+
if (result._tag === "Right") {
|
204
|
+
return result.right;
|
205
|
+
}
|
206
|
+
ctx.addIssue({
|
207
|
+
code: z.ZodIssueCode.custom,
|
208
|
+
message: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`
|
209
|
+
});
|
210
|
+
return z.NEVER;
|
211
|
+
})
|
212
|
+
});
|
177
213
|
export {
|
178
214
|
CustomTypesManager
|
179
215
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomTypesManager.js","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { CustomType } from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\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 createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\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 readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\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,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\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 renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type: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 deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\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 Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\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 types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\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\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, 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\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\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.getAllCustomTypes();\n\t}\n}\n"],"names":["errors"],"mappings":";;;;;;;;;;AAgFM,MAAO,2BAA2B,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1B,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,OAAA,IAAW,iBACxB,EAAE,KAAK;AAAA,MACN,KAAK,EAAE,MAAM,EAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/C,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,OAAA,IAAW,MAAM,KAAK,sBAAqB;AACxD,QAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAG,MAAM;AAEtC,QAAI,KAAK;AACR,iBAA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nB,SAAS;AAAA,IAAA,CACT;AAEF,UAAM,QAAO,gBAAW,KAAK,CAAC,MAAjB,mBAAoB;AAIjC,QAAI,MAAM;AACF,aAAA;AAAA,QACN,aAAa,KAAK,MAAM,KAAK,UAAU;AAAA,QACvC,QAAQ,WAAW;AAAA,MAAA;AAAA,WAEd;AACC,aAAA;AAAA,QACN,aAAa;AAAA,QACb,QAAQ,WAAW;AAAA,MAAA;AAAA,IAErB;AAAA,EACD;AAAA;AAAA,EAGA,MAAM,4BACL,MAAwD;AAExD,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA;AAAA,MACC,cAAc,KAAK;AAAA,MACnB,OAAO;AAAA,QACN,IAAI;AAAA,QACJ,MAAM,OAAO,KAAK,KAAK,UAAU,KAAK,aAAa,MAAM,GAAI,CAAC;AAAA,MAC9D;AAAA,IAAA,CACD;AAGK,WAAA;AAAA,MACN,QAAQ,WAAW;AAAA,IAAA;AAAA,EAErB;AAAA,EAEA,MAAM,yBAAsB;AAC3B,UAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAClE,UAAM,iBAAiB,MAAM,KAAK,QAAQ,0BAAyB;AAE7D,UAAA,SAAS,yBAAyB,aAAa;AAAA,MACpD,UAAU,cAAc;AAAA,MACxB;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA,cAAc;AAAA,QACb,SAAS;AAAA,UACR,cAAc;AAAA,QACd;AAAA,MACD;AAAA,IAAA,CACD;AAEM,WAAA,MAAM,OAAO;EACrB;AACA;"}
|
1
|
+
{"version":3,"file":"CustomTypesManager.js","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\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 createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\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 readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\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,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\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 renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type: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 deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\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 Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\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 types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\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\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, 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\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\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.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n});\n"],"names":["errors"],"mappings":";;;;;;;;;;;AAoFM,MAAO,2BAA2B,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1B,6BAAyB,KAAK,wBAAwB;AAEtD,U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EAAE;AAAA,EAAA,CACT;AACD,CAAA;"}
|
@@ -127,6 +127,41 @@ class SlicesManager extends BaseManager.BaseManager {
|
|
127
127
|
errors: [...hookResult.errors, ...updateSliceHookErrors]
|
128
128
|
};
|
129
129
|
}
|
130
|
+
async addSlices(args) {
|
131
|
+
const { models } = args;
|
132
|
+
const existingSlices = await this.readAllSlices();
|
133
|
+
if (existingSlices.errors.length > 0) {
|
134
|
+
throw new Error("Failed to read existing slices.");
|
135
|
+
}
|
136
|
+
const existingSliceIds = new Set(existingSlices.models.map((slice) => slice.model.id));
|
137
|
+
const updatedModels = models.map((model) => {
|
138
|
+
let newId = model.id;
|
139
|
+
let counter = 2;
|
140
|
+
while (existingSliceIds.has(newId)) {
|
141
|
+
newId = `${model.id}${counter}`;
|
142
|
+
counter++;
|
143
|
+
}
|
144
|
+
existingSliceIds.add(newId);
|
145
|
+
return {
|
146
|
+
...model,
|
147
|
+
id: newId
|
148
|
+
};
|
149
|
+
});
|
150
|
+
const { libraries = [] } = await this.project.getSliceMachineConfig();
|
151
|
+
const library = libraries[0];
|
152
|
+
if (!library) {
|
153
|
+
throw new Error("No library found in Slice Machine config.");
|
154
|
+
}
|
155
|
+
for (const model of updatedModels) {
|
156
|
+
const { errors: errors2 } = await this.createSlice({
|
157
|
+
libraryID: library,
|
158
|
+
model
|
159
|
+
});
|
160
|
+
if (errors2.length) {
|
161
|
+
throw new Error(`Failed to create slice ${model.id}.`);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
130
165
|
async readSlice(args) {
|
131
166
|
var _a;
|
132
167
|
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
@@ -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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNM,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,MAAM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port * 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 addSlices(args: { models: SharedSlice[] }): Promise<void> {\n\t\tconst { models } = args;\n\n\t\t// fix duplicate slice ids\n\t\tconst existingSlices = await this.readAllSlices();\n\t\tif (existingSlices.errors.length > 0) {\n\t\t\tthrow new Error(\"Failed to read existing slices.\");\n\t\t}\n\t\tconst existingSliceIds = new Set(\n\t\t\texistingSlices.models.map((slice) => slice.model.id),\n\t\t);\n\t\tconst updatedModels = models.map((model) => {\n\t\t\tlet newId = model.id;\n\t\t\tlet counter = 2;\n\n\t\t\twhile (existingSliceIds.has(newId)) {\n\t\t\t\tnewId = `${model.id}${counter}`;\n\t\t\t\tcounter++;\n\t\t\t}\n\n\t\t\texistingSliceIds.add(newId);\n\n\t\t\treturn {\n\t\t\t\t...model,\n\t\t\t\tid: newId,\n\t\t\t};\n\t\t});\n\n\t\t// add slices to the first library\n\t\tconst { libraries = [] } = await this.project.getSliceMachineConfig();\n\t\tconst library = libraries[0];\n\t\tif (!library) {\n\t\t\tthrow new Error(\"No library found in Slice Machine config.\");\n\t\t}\n\n\t\tfor (const model of updatedModels) {\n\t\t\tconst { errors } = await this.createSlice({\n\t\t\t\tlibraryID: library,\n\t\t\t\tmodel,\n\t\t\t});\n\t\t\tif (errors.length) {\n\t\t\t\tthrow new Error(`Failed to create slice ${model.id}.`);\n\t\t\t}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNM,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,CAC1B,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,YAAU,UAAK,CAAC,MAAN,mBAAS,aAAY,CAAE;AAAA,MACjC,QAAAF;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,wBAAqB;AAC1BD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAC7D,UAAA,aAAa,mBAAmB,aAAa;AAEnD,UAA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,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;;"}
|
@@ -154,6 +154,9 @@ export declare class SlicesManager extends BaseManager {
|
|
154
154
|
readAllSlicesForLibrary(args: SliceMachineManagerReadAllSlicesForLibraryArgs): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType>;
|
155
155
|
readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType>;
|
156
156
|
createSlice(args: SliceCreateHookData): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>>;
|
157
|
+
addSlices(args: {
|
158
|
+
models: SharedSlice[];
|
159
|
+
}): Promise<void>;
|
157
160
|
readSlice(args: SliceReadHookData): Promise<SliceMachineManagerReadSliceReturnType>;
|
158
161
|
updateSlice(args: SliceMachineManagerUpdateSliceArgs): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>>;
|
159
162
|
renameSlice(args: SliceRenameHookData): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>>;
|
@@ -107,6 +107,41 @@ class SlicesManager extends BaseManager {
|
|
107
107
|
errors: [...hookResult.errors, ...updateSliceHookErrors]
|
108
108
|
};
|
109
109
|
}
|
110
|
+
async addSlices(args) {
|
111
|
+
const { models } = args;
|
112
|
+
const existingSlices = await this.readAllSlices();
|
113
|
+
if (existingSlices.errors.length > 0) {
|
114
|
+
throw new Error("Failed to read existing slices.");
|
115
|
+
}
|
116
|
+
const existingSliceIds = new Set(existingSlices.models.map((slice) => slice.model.id));
|
117
|
+
const updatedModels = models.map((model) => {
|
118
|
+
let newId = model.id;
|
119
|
+
let counter = 2;
|
120
|
+
while (existingSliceIds.has(newId)) {
|
121
|
+
newId = `${model.id}${counter}`;
|
122
|
+
counter++;
|
123
|
+
}
|
124
|
+
existingSliceIds.add(newId);
|
125
|
+
return {
|
126
|
+
...model,
|
127
|
+
id: newId
|
128
|
+
};
|
129
|
+
});
|
130
|
+
const { libraries = [] } = await this.project.getSliceMachineConfig();
|
131
|
+
const library = libraries[0];
|
132
|
+
if (!library) {
|
133
|
+
throw new Error("No library found in Slice Machine config.");
|
134
|
+
}
|
135
|
+
for (const model of updatedModels) {
|
136
|
+
const { errors } = await this.createSlice({
|
137
|
+
libraryID: library,
|
138
|
+
model
|
139
|
+
});
|
140
|
+
if (errors.length) {
|
141
|
+
throw new Error(`Failed to create slice ${model.id}.`);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
110
145
|
async readSlice(args) {
|
111
146
|
var _a;
|
112
147
|
assertPluginsInitialized(this.sliceMachinePluginRunner);
|