@slicemachine/manager 0.24.16-beta.2 → 0.24.16-beta.4
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/managers/customTypes/CustomTypesManager.cjs +113 -38
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.d.ts +202 -75
- package/dist/managers/customTypes/CustomTypesManager.js +113 -38
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/package.json +3 -3
- package/src/managers/customTypes/CustomTypesManager.ts +253 -70
@@ -87,11 +87,11 @@ class CustomTypesManager extends BaseManager.BaseManager {
|
|
87
87
|
*/
|
88
88
|
async updateContentRelationships(args) {
|
89
89
|
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
90
|
-
const { model } = args;
|
91
|
-
|
92
|
-
|
93
|
-
previousPath = [
|
94
|
-
newPath = [
|
90
|
+
const { model, previousPath: previousFieldPath, newPath: newFieldPath } = args;
|
91
|
+
if (previousFieldPath.join(".") !== newFieldPath.join(".")) {
|
92
|
+
const { id: ctId } = model;
|
93
|
+
const previousPath = [ctId, ...previousFieldPath];
|
94
|
+
const newPath = [ctId, ...newFieldPath];
|
95
95
|
const crUpdates = [];
|
96
96
|
const customTypes = await this.readAllCustomTypes();
|
97
97
|
updateCustomTypeContentRelationships({
|
@@ -329,54 +329,113 @@ const InferSliceResponse = index.default.object({
|
|
329
329
|
langSmithUrl: index.default.string().url().optional()
|
330
330
|
});
|
331
331
|
function updateCRCustomType(args) {
|
332
|
-
const
|
333
|
-
const
|
334
|
-
if (!
|
335
|
-
throw new Error(
|
332
|
+
const previousPath = getPathIds(args.previousPath);
|
333
|
+
const newPath = getPathIds(args.newPath);
|
334
|
+
if (!previousPath.customTypeId || !newPath.customTypeId) {
|
335
|
+
throw new Error(`Could not find a customtype id in previousPath (${args.previousPath.join(".")}) and/or newPath (${args.newPath.join(".")}), which should not be possible.`);
|
336
336
|
}
|
337
|
-
if (!
|
338
|
-
throw new Error(
|
337
|
+
if (!previousPath.fieldId || !newPath.fieldId) {
|
338
|
+
throw new Error(`Could not find a field id in previousPath (${args.previousPath.join(".")}) and/or newPath (${args.newPath.join(".")}), which should not be possible.`);
|
339
339
|
}
|
340
340
|
const customType = shallowCloneIfObject(args.customType);
|
341
|
-
if (typeof customType === "string"
|
341
|
+
if (typeof customType === "string") {
|
342
342
|
return customType;
|
343
343
|
}
|
344
|
-
const matchedCustomTypeId = customType.id ===
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
344
|
+
const matchedCustomTypeId = customType.id === previousPath.customTypeId;
|
345
|
+
return {
|
346
|
+
...customType,
|
347
|
+
fields: customType.fields.map((fieldArg) => {
|
348
|
+
const customTypeField = shallowCloneIfObject(fieldArg);
|
349
|
+
if (typeof customTypeField === "string") {
|
350
|
+
if (matchedCustomTypeId && customTypeField === previousPath.fieldId && customTypeField !== newPath.fieldId) {
|
351
|
+
return newPath.fieldId;
|
352
|
+
}
|
353
|
+
return customTypeField;
|
350
354
|
}
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
customTypeField
|
355
|
+
if (matchedCustomTypeId && customTypeField.id === previousPath.fieldId && customTypeField.id !== newPath.fieldId) {
|
356
|
+
customTypeField.id = newPath.fieldId;
|
357
|
+
}
|
358
|
+
if ("fields" in customTypeField) {
|
359
|
+
if (!previousPath.groupId && !newPath.groupId && customTypeField.id === previousPath.fieldId && customTypeField.id !== newPath.fieldId) {
|
360
|
+
return newPath.fieldId;
|
361
|
+
}
|
362
|
+
const matchedGroupId = customTypeField.id === previousPath.groupId;
|
363
|
+
if (previousPath.groupId && newPath.groupId && matchedGroupId && customTypeField.id !== newPath.groupId) {
|
364
|
+
customTypeField.id = newPath.groupId;
|
365
|
+
}
|
366
|
+
return {
|
367
|
+
...customTypeField,
|
368
|
+
fields: customTypeField.fields.map((groupFieldArg) => {
|
369
|
+
const groupField = shallowCloneIfObject(groupFieldArg);
|
370
|
+
if (typeof groupField === "string") {
|
371
|
+
if (matchedGroupId && groupField === previousPath.fieldId && groupField !== newPath.fieldId) {
|
372
|
+
return newPath.fieldId;
|
373
|
+
}
|
374
|
+
return groupField;
|
375
|
+
}
|
376
|
+
return {
|
377
|
+
...groupField,
|
378
|
+
fields: updateContentRelationshipFields({
|
379
|
+
customtypes: groupField.customtypes,
|
380
|
+
previousPath,
|
381
|
+
newPath
|
382
|
+
})
|
383
|
+
};
|
384
|
+
})
|
385
|
+
};
|
386
|
+
}
|
387
|
+
return {
|
388
|
+
...customTypeField,
|
389
|
+
customtypes: updateContentRelationshipFields({
|
390
|
+
customtypes: customTypeField.customtypes,
|
391
|
+
previousPath,
|
392
|
+
newPath
|
393
|
+
})
|
394
|
+
};
|
395
|
+
})
|
396
|
+
};
|
397
|
+
}
|
398
|
+
function updateContentRelationshipFields(args) {
|
399
|
+
const { customtypes: customtypes2, previousPath, newPath } = args;
|
400
|
+
return customtypes2.map((nestedCtArg) => {
|
401
|
+
const nestedCt = shallowCloneIfObject(nestedCtArg);
|
402
|
+
if (typeof nestedCt === "string" || // Since we are entering a new custom type, if the previous id
|
403
|
+
// doesn't match, we can return early, because it's not the
|
404
|
+
// custom type we are looking for.
|
405
|
+
nestedCt.id !== previousPath.customTypeId) {
|
406
|
+
return nestedCt;
|
355
407
|
}
|
356
408
|
return {
|
357
|
-
...
|
358
|
-
|
359
|
-
const
|
360
|
-
if (typeof
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
return
|
409
|
+
...nestedCt,
|
410
|
+
fields: nestedCt.fields.map((nestedCtFieldArg) => {
|
411
|
+
const nestedCtField = shallowCloneIfObject(nestedCtFieldArg);
|
412
|
+
if (typeof nestedCtField === "string") {
|
413
|
+
if (nestedCtField === previousPath.fieldId && nestedCtField !== newPath.fieldId) {
|
414
|
+
return newPath.fieldId;
|
415
|
+
}
|
416
|
+
return nestedCtField;
|
417
|
+
}
|
418
|
+
if (nestedCtField.id === previousPath.fieldId && nestedCtField.id !== newPath.fieldId) {
|
419
|
+
nestedCtField.id = newPath.fieldId;
|
420
|
+
}
|
421
|
+
if (!previousPath.groupId || !newPath.groupId || nestedCtField.id !== previousPath.groupId) {
|
422
|
+
return nestedCtField;
|
423
|
+
}
|
424
|
+
if (nestedCtField.id !== newPath.groupId) {
|
425
|
+
nestedCtField.id = newPath.groupId;
|
365
426
|
}
|
366
427
|
return {
|
367
|
-
...
|
368
|
-
fields:
|
369
|
-
|
370
|
-
|
371
|
-
return newFieldId;
|
428
|
+
...nestedCtField,
|
429
|
+
fields: nestedCtField.fields.map((nestedCtGroupFieldId) => {
|
430
|
+
if (nestedCtGroupFieldId === previousPath.fieldId && nestedCtGroupFieldId !== newPath.fieldId) {
|
431
|
+
return newPath.fieldId;
|
372
432
|
}
|
373
|
-
return
|
433
|
+
return nestedCtGroupFieldId;
|
374
434
|
})
|
375
435
|
};
|
376
436
|
})
|
377
437
|
};
|
378
438
|
});
|
379
|
-
return { ...customType, fields: newFields };
|
380
439
|
}
|
381
440
|
function updateFieldContentRelationships(args) {
|
382
441
|
var _a, _b;
|
@@ -414,7 +473,7 @@ function updateSharedSliceContentRelationships(args) {
|
|
414
473
|
const { models, previousPath, newPath, onUpdate } = args;
|
415
474
|
for (const { model: slice } of models) {
|
416
475
|
const updateSlice = customtypes.traverseSharedSlice({
|
417
|
-
path: [
|
476
|
+
path: [],
|
418
477
|
slice,
|
419
478
|
onField: ({ field }) => {
|
420
479
|
return updateFieldContentRelationships({
|
@@ -429,6 +488,22 @@ function updateSharedSliceContentRelationships(args) {
|
|
429
488
|
}
|
430
489
|
}
|
431
490
|
}
|
491
|
+
function getPathIds(path) {
|
492
|
+
if (path.length < 2) {
|
493
|
+
throw new Error(`Unexpected path length ${path.length}. Expected at least 2 segments (got: ${path.join(".")}).`);
|
494
|
+
}
|
495
|
+
const [customTypeId, groupOrFieldId, fieldId] = path;
|
496
|
+
return {
|
497
|
+
customTypeId,
|
498
|
+
/**
|
499
|
+
* Id of a changed group. If it's defined, it means that a group or a field
|
500
|
+
* inside a group had its API ID renamed. It's defined when the path has a
|
501
|
+
* third element (e.g. `["customtypeA", "groupA", "fieldA"]`).
|
502
|
+
*/
|
503
|
+
groupId: fieldId ? groupOrFieldId : void 0,
|
504
|
+
fieldId: fieldId || groupOrFieldId
|
505
|
+
};
|
506
|
+
}
|
432
507
|
function isEqualModel(modelA, modelB) {
|
433
508
|
return JSON.stringify(modelA) === JSON.stringify(modelB);
|
434
509
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomTypesManager.cjs","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\tGroup,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\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\ntype CustomTypesMachineManagerUpdateCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypeFieldIdChangedMeta = {\n\tpreviousPath: string[];\n\tnewPath: string[];\n};\n\ntype CrCustomType =\n\t| string\n\t| { id: string; fields?: readonly CrCustomTypeNestedCr[] };\ntype CrCustomTypeNestedCr =\n\t| string\n\t| { id: string; customtypes: readonly CrCustomTypeFieldLeaf[] };\ntype CrCustomTypeFieldLeaf =\n\t| string\n\t| { id: string; fields?: readonly string[] };\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\t/**\n\t * Update the Content Relationship API IDs for all existing custom types and\n\t * slices. The change is determined by properties inside the `updateMeta`\n\t * property.\n\t */\n\tprivate async updateContentRelationships(\n\t\targs: { model: CustomType } & CustomTypeFieldIdChangedMeta,\n\t): Promise<\n\t\tOnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>> & {\n\t\t\trollback?: () => Promise<void>;\n\t\t}\n\t> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model } = args;\n\t\tlet { newPath, previousPath } = args;\n\n\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\tconst crUpdates: {\n\t\t\t\tupdatePromise: Promise<{ errors: HookError[] }>;\n\t\t\t\trollback: () => void;\n\t\t\t}[] = [];\n\n\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t// any custom type and update them to use the new one.\n\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\tupdateCustomTypeContentRelationships({\n\t\t\t\tmodels: customTypes.models,\n\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\"custom-type:update\",\n\t\t\t\t\t\t\t{ model: updatedModel },\n\t\t\t\t\t\t),\n\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\t\tmodel: previousModel,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tpreviousPath,\n\t\t\t\tnewPath,\n\t\t\t});\n\n\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\tfor (const library of libraries) {\n\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t});\n\n\t\t\t\tupdateSharedSliceContentRelationships({\n\t\t\t\t\tmodels: slices.models,\n\t\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\t\"slice:update\",\n\t\t\t\t\t\t\t\t{ libraryID: library.libraryID, model: updatedModel },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\t\tmodel: previousModel,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Process all the Content Relationship updates at once.\n\t\t\tconst crUpdatesResult = await Promise.all(\n\t\t\t\tcrUpdates.map((update) => update.updatePromise),\n\t\t\t);\n\n\t\t\tif (crUpdatesResult.some((result) => result.errors.length > 0)) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: crUpdatesResult.flatMap((result) => result.errors),\n\t\t\t\t\trollback: async () => {\n\t\t\t\t\t\tawait Promise.all(crUpdates.map((update) => update.rollback()));\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<CustomTypesMachineManagerUpdateCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\t\tconst { model } = args;\n\t\tconst { fieldIdChanged } = args.updateMeta ?? {};\n\n\t\tlet previousCustomType: CustomType | undefined;\n\n\t\tif (fieldIdChanged) {\n\t\t\tconst customTypeRead = await this.readCustomType({ id: model.id });\n\n\t\t\tif (customTypeRead.errors.length > 0) {\n\t\t\t\treturn { errors: customTypeRead.errors };\n\t\t\t}\n\t\t\tif (!customTypeRead.model) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`readCustomType succeeded reading custom type ${model.id} but model is undefined.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpreviousCustomType = customTypeRead.model;\n\t\t}\n\n\t\tconst customTypeUpdateResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\t{ model },\n\t\t);\n\n\t\tif (customTypeUpdateResult.errors.length > 0) {\n\t\t\treturn { errors: customTypeUpdateResult.errors };\n\t\t}\n\n\t\tif (previousCustomType && fieldIdChanged) {\n\t\t\tconst crUpdateResult = await this.updateContentRelationships({\n\t\t\t\t...fieldIdChanged,\n\t\t\t\tmodel: previousCustomType,\n\t\t\t});\n\n\t\t\tif (crUpdateResult.errors.length > 0) {\n\t\t\t\t// put the previous custom type back\n\t\t\t\tawait this.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\tmodel: previousCustomType,\n\t\t\t\t});\n\t\t\t\t// revert the content relationships updates\n\t\t\t\tawait crUpdateResult.rollback?.();\n\n\t\t\t\treturn { errors: crUpdateResult.errors };\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\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\tlangSmithUrl: z.string().url().optional(),\n});\n\nfunction updateCRCustomType(\n\targs: { customType: CrCustomType } & CustomTypeFieldIdChangedMeta,\n): CrCustomType {\n\tconst [previousCustomTypeId, previousFieldId] = args.previousPath;\n\tconst [newCustomTypeId, newFieldId] = args.newPath;\n\n\tif (!previousCustomTypeId || !newCustomTypeId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a customtype id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tif (!previousFieldId || !newFieldId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a field id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tconst customType = shallowCloneIfObject(args.customType);\n\n\tif (typeof customType === \"string\" || !customType.fields) {\n\t\treturn customType;\n\t}\n\n\tconst matchedCustomTypeId = customType.id === previousCustomTypeId;\n\n\tconst newFields = customType.fields.map((fieldArg) => {\n\t\tconst customTypeField = shallowCloneIfObject(fieldArg);\n\n\t\tif (typeof customTypeField === \"string\") {\n\t\t\tif (\n\t\t\t\tmatchedCustomTypeId &&\n\t\t\t\tcustomTypeField === previousFieldId &&\n\t\t\t\tcustomTypeField !== newFieldId\n\t\t\t) {\n\t\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t\t// so we update it new one. The field is a string, so return the new\n\t\t\t\t// id.\n\t\t\t\treturn newFieldId;\n\t\t\t}\n\n\t\t\treturn customTypeField;\n\t\t}\n\n\t\tif (\n\t\t\tmatchedCustomTypeId &&\n\t\t\tcustomTypeField.id === previousFieldId &&\n\t\t\tcustomTypeField.id !== newFieldId\n\t\t) {\n\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t// so we update it new one.\n\t\t\t// Since field is not a string, we don't exit, as we might have\n\t\t\t// something to update further down in customtypes.\n\t\t\tcustomTypeField.id = newFieldId;\n\t\t}\n\n\t\treturn {\n\t\t\t...customTypeField,\n\t\t\tcustomtypes: customTypeField.customtypes.map((customTypeArg) => {\n\t\t\t\tconst nestedCustomType = shallowCloneIfObject(customTypeArg);\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof nestedCustomType === \"string\" ||\n\t\t\t\t\t!nestedCustomType.fields ||\n\t\t\t\t\t// Since we are on the last level, if we don't start matching right\n\t\t\t\t\t// at the custom type id, we can return exit early because it's not\n\t\t\t\t\t// a match.\n\t\t\t\t\tnestedCustomType.id !== previousCustomTypeId\n\t\t\t\t) {\n\t\t\t\t\treturn nestedCustomType;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...nestedCustomType,\n\t\t\t\t\tfields: nestedCustomType.fields.map((fieldArg) => {\n\t\t\t\t\t\tconst nestedCustomTypeField = shallowCloneIfObject(fieldArg);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnestedCustomTypeField === previousFieldId &&\n\t\t\t\t\t\t\tnestedCustomTypeField !== newFieldId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Matches the previous id, so we update it and return because\n\t\t\t\t\t\t\t// it's the last level.\n\t\t\t\t\t\t\treturn newFieldId;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nestedCustomTypeField;\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n\n\treturn { ...customType, fields: newFields };\n}\n\n/**\n * Update the Content Relationship API IDs of a single field. The change is\n * determined by the `previousPath` and `newPath` properties.\n */\nfunction updateFieldContentRelationships<\n\tT extends UID | NestableWidget | Group | NestedGroup,\n>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\tconst { field, ...updateMeta } = args;\n\tif (\n\t\tfield.type !== \"Link\" ||\n\t\tfield.config?.select !== \"document\" ||\n\t\t!field.config?.customtypes\n\t) {\n\t\t// not a content relationship field\n\t\treturn field;\n\t}\n\n\tconst newCustomTypes = field.config.customtypes.map((customType) => {\n\t\treturn updateCRCustomType({ customType, ...updateMeta });\n\t});\n\n\treturn {\n\t\t...field,\n\t\tconfig: { ...field.config, customtypes: newCustomTypes },\n\t};\n}\n\nexport function updateCustomTypeContentRelationships(\n\targs: {\n\t\tmodels: { model: CustomType }[];\n\t\tonUpdate: (model: { previousModel: CustomType; model: CustomType }) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: customType } of models) {\n\t\tconst updatedCustomType = traverseCustomType({\n\t\t\tcustomType,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(customType, updatedCustomType)) {\n\t\t\tonUpdate({ model: updatedCustomType, previousModel: customType });\n\t\t}\n\t}\n}\n\nexport function updateSharedSliceContentRelationships(\n\targs: {\n\t\tmodels: { model: SharedSlice }[];\n\t\tonUpdate: (model: {\n\t\t\tpreviousModel: SharedSlice;\n\t\t\tmodel: SharedSlice;\n\t\t}) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: slice } of models) {\n\t\tconst updateSlice = traverseSharedSlice({\n\t\t\tpath: [\".\"],\n\t\t\tslice,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(slice, updateSlice)) {\n\t\t\tonUpdate({ model: updateSlice, previousModel: slice });\n\t\t}\n\t}\n}\n\nfunction isEqualModel<T extends CustomType | SharedSlice>(\n\tmodelA: T,\n\tmodelB: T,\n): boolean {\n\treturn JSON.stringify(modelA) === JSON.stringify(modelB);\n}\n\nfunction shallowCloneIfObject<T>(value: T): T {\n\tif (typeof value === \"object\") {\n\t\treturn { ...value };\n\t}\n\n\treturn value;\n}\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","_a","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice","fieldArg","traverseCustomType","traverseSharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6GM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1BC,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,KAAKA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB,QAAAF;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/CD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,QAAAC,QAAA,IAAW,MAAM,KAAK,sBAAqB;AACxD,QAAI,SAAS,CAAC,GAAG,IAAI,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UAAU,MAAM;AACxD;AAEA,SAAS,qBAAwB,OAAQ;AACpC,MAAA,OAAO,UAAU,UAAU;AACvB,WAAA,EAAE,GAAG;EACb;AAEO,SAAA;AACR;;;;"}
|
1
|
+
{"version":3,"file":"CustomTypesManager.cjs","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\tGroup,\n\tLinkConfig,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\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\n/** `[field]` or `[group, field]` – path **inside** the Custom Type */\ntype PathWithoutCustomType = [string] | [string, string];\n\ntype SliceMachineManagerUpdateCustomTypeFieldIdChanged = {\n\t/**\n\t * Previous path of the changed field, excluding the custom type id. Can be\n\t * used to identify the field that had an API ID rename (e.g. [\"fieldA\"] or\n\t * [\"groupA\", \"fieldA\"])\n\t */\n\tpreviousPath: PathWithoutCustomType;\n\t/**\n\t * New path of the changed field, excluding the custom type id. Can be used to\n\t * identify the field that had an API ID rename (e.g. [\"fieldB\"] or [\"groupA\",\n\t * \"fieldB\"])\n\t */\n\tnewPath: PathWithoutCustomType;\n};\n\ntype SliceMachineManagerUpdateCustomTypeArgs = CustomTypeUpdateHookData & {\n\tupdateMeta?: {\n\t\tfieldIdChanged?: SliceMachineManagerUpdateCustomTypeFieldIdChanged;\n\t};\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesMachineManagerUpdateCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\n/** `[ct, field]` or `[ct, group, field]` – path **with** Custom Type ID */\ntype PathWithCustomType = [string, string] | [string, string, string];\n\ntype CustomTypeFieldIdChangedMeta = {\n\tpreviousPath: PathWithCustomType;\n\tnewPath: PathWithCustomType;\n};\n\ntype LinkCustomType = NonNullable<LinkConfig[\"customtypes\"]>[number];\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\t/**\n\t * Update the Content Relationship API IDs for all existing custom types and\n\t * slices. The change is determined by properties inside the `updateMeta`\n\t * property.\n\t */\n\tprivate async updateContentRelationships(\n\t\targs: {\n\t\t\tmodel: CustomType;\n\t\t} & SliceMachineManagerUpdateCustomTypeFieldIdChanged,\n\t): Promise<\n\t\tOnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>> & {\n\t\t\trollback?: () => Promise<void>;\n\t\t}\n\t> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst {\n\t\t\tmodel,\n\t\t\tpreviousPath: previousFieldPath,\n\t\t\tnewPath: newFieldPath,\n\t\t} = args;\n\n\t\tif (previousFieldPath.join(\".\") !== newFieldPath.join(\".\")) {\n\t\t\tconst { id: ctId } = model;\n\t\t\tconst previousPath: PathWithCustomType = [ctId, ...previousFieldPath];\n\t\t\tconst newPath: PathWithCustomType = [ctId, ...newFieldPath];\n\n\t\t\tconst crUpdates: {\n\t\t\t\tupdatePromise: Promise<{ errors: HookError[] }>;\n\t\t\t\trollback: () => void;\n\t\t\t}[] = [];\n\n\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t// any custom type and update them to use the new one.\n\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\tupdateCustomTypeContentRelationships({\n\t\t\t\tmodels: customTypes.models,\n\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\"custom-type:update\",\n\t\t\t\t\t\t\t{ model: updatedModel },\n\t\t\t\t\t\t),\n\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\t\tmodel: previousModel,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tpreviousPath,\n\t\t\t\tnewPath,\n\t\t\t});\n\n\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\tfor (const library of libraries) {\n\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t});\n\n\t\t\t\tupdateSharedSliceContentRelationships({\n\t\t\t\t\tmodels: slices.models,\n\t\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\t\"slice:update\",\n\t\t\t\t\t\t\t\t{ libraryID: library.libraryID, model: updatedModel },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\t\tmodel: previousModel,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Process all the Content Relationship updates at once.\n\t\t\tconst crUpdatesResult = await Promise.all(\n\t\t\t\tcrUpdates.map((update) => update.updatePromise),\n\t\t\t);\n\n\t\t\tif (crUpdatesResult.some((result) => result.errors.length > 0)) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: crUpdatesResult.flatMap((result) => result.errors),\n\t\t\t\t\trollback: async () => {\n\t\t\t\t\t\tawait Promise.all(crUpdates.map((update) => update.rollback()));\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\n\t}\n\n\tasync updateCustomType(\n\t\targs: SliceMachineManagerUpdateCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerUpdateCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\t\tconst { model } = args;\n\t\tconst { fieldIdChanged } = args.updateMeta ?? {};\n\n\t\tlet previousCustomType: CustomType | undefined;\n\n\t\tif (fieldIdChanged) {\n\t\t\tconst customTypeRead = await this.readCustomType({ id: model.id });\n\n\t\t\tif (customTypeRead.errors.length > 0) {\n\t\t\t\treturn { errors: customTypeRead.errors };\n\t\t\t}\n\t\t\tif (!customTypeRead.model) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`readCustomType succeeded reading custom type ${model.id} but model is undefined.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpreviousCustomType = customTypeRead.model;\n\t\t}\n\n\t\tconst customTypeUpdateResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\t{ model },\n\t\t);\n\n\t\tif (customTypeUpdateResult.errors.length > 0) {\n\t\t\treturn { errors: customTypeUpdateResult.errors };\n\t\t}\n\n\t\tif (previousCustomType && fieldIdChanged) {\n\t\t\tconst crUpdateResult = await this.updateContentRelationships({\n\t\t\t\t...fieldIdChanged,\n\t\t\t\tmodel: previousCustomType,\n\t\t\t});\n\n\t\t\tif (crUpdateResult.errors.length > 0) {\n\t\t\t\t// put the previous custom type back\n\t\t\t\tawait this.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\tmodel: previousCustomType,\n\t\t\t\t});\n\t\t\t\t// revert the content relationships updates\n\t\t\t\tawait crUpdateResult.rollback?.();\n\n\t\t\t\treturn { errors: crUpdateResult.errors };\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\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\tlangSmithUrl: z.string().url().optional(),\n});\n\nfunction updateCRCustomType(\n\targs: { customType: LinkCustomType } & CustomTypeFieldIdChangedMeta,\n): LinkCustomType {\n\tconst previousPath = getPathIds(args.previousPath);\n\tconst newPath = getPathIds(args.newPath);\n\n\tif (!previousPath.customTypeId || !newPath.customTypeId) {\n\t\tthrow new Error(\n\t\t\t`Could not find a customtype id in previousPath (${args.previousPath.join(\n\t\t\t\t\".\",\n\t\t\t)}) and/or newPath (${args.newPath.join(\n\t\t\t\t\".\",\n\t\t\t)}), which should not be possible.`,\n\t\t);\n\t}\n\n\tif (!previousPath.fieldId || !newPath.fieldId) {\n\t\tthrow new Error(\n\t\t\t`Could not find a field id in previousPath (${args.previousPath.join(\n\t\t\t\t\".\",\n\t\t\t)}) and/or newPath (${args.newPath.join(\n\t\t\t\t\".\",\n\t\t\t)}), which should not be possible.`,\n\t\t);\n\t}\n\n\tconst customType = shallowCloneIfObject(args.customType);\n\n\tif (typeof customType === \"string\") {\n\t\t// Legacy format support, we don't have anything to update here.\n\t\treturn customType;\n\t}\n\n\tconst matchedCustomTypeId = customType.id === previousPath.customTypeId;\n\n\treturn {\n\t\t...customType,\n\t\tfields: customType.fields.map((fieldArg) => {\n\t\t\tconst customTypeField = shallowCloneIfObject(fieldArg);\n\n\t\t\t// Regular field\n\t\t\tif (typeof customTypeField === \"string\") {\n\t\t\t\tif (\n\t\t\t\t\tmatchedCustomTypeId &&\n\t\t\t\t\tcustomTypeField === previousPath.fieldId &&\n\t\t\t\t\tcustomTypeField !== newPath.fieldId\n\t\t\t\t) {\n\t\t\t\t\t// The id of the field has changed.\n\t\t\t\t\treturn newPath.fieldId;\n\t\t\t\t}\n\n\t\t\t\treturn customTypeField;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tmatchedCustomTypeId &&\n\t\t\t\tcustomTypeField.id === previousPath.fieldId &&\n\t\t\t\tcustomTypeField.id !== newPath.fieldId\n\t\t\t) {\n\t\t\t\t// The id of the field has changed. We don't exit return because there\n\t\t\t\t// might be other fields further down in nested custom types or groups\n\t\t\t\t// that need to be updated.\n\t\t\t\tcustomTypeField.id = newPath.fieldId;\n\t\t\t}\n\n\t\t\t// Group field\n\t\t\tif (\"fields\" in customTypeField) {\n\t\t\t\tif (\n\t\t\t\t\t!previousPath.groupId &&\n\t\t\t\t\t!newPath.groupId &&\n\t\t\t\t\tcustomTypeField.id === previousPath.fieldId &&\n\t\t\t\t\tcustomTypeField.id !== newPath.fieldId\n\t\t\t\t) {\n\t\t\t\t\t// Only the id of the group has changed. Group id is not defined, so\n\t\t\t\t\t// we can return early.\n\t\t\t\t\treturn newPath.fieldId;\n\t\t\t\t}\n\n\t\t\t\tconst matchedGroupId = customTypeField.id === previousPath.groupId;\n\n\t\t\t\tif (\n\t\t\t\t\tpreviousPath.groupId &&\n\t\t\t\t\tnewPath.groupId &&\n\t\t\t\t\tmatchedGroupId &&\n\t\t\t\t\tcustomTypeField.id !== newPath.groupId\n\t\t\t\t) {\n\t\t\t\t\t// The id of the group field has changed, so we update it. We don't\n\t\t\t\t\t// return because there are group fields that may need to be updated.\n\t\t\t\t\tcustomTypeField.id = newPath.groupId;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...customTypeField,\n\t\t\t\t\tfields: customTypeField.fields.map((groupFieldArg) => {\n\t\t\t\t\t\tconst groupField = shallowCloneIfObject(groupFieldArg);\n\n\t\t\t\t\t\t// Regular field inside a group field\n\t\t\t\t\t\tif (typeof groupField === \"string\") {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tmatchedGroupId &&\n\t\t\t\t\t\t\t\tgroupField === previousPath.fieldId &&\n\t\t\t\t\t\t\t\tgroupField !== newPath.fieldId\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// The id of the field inside the group has changed.\n\t\t\t\t\t\t\t\treturn newPath.fieldId;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn groupField;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Content relationship field inside a group field\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...groupField,\n\t\t\t\t\t\t\tfields: updateContentRelationshipFields({\n\t\t\t\t\t\t\t\tcustomtypes: groupField.customtypes,\n\t\t\t\t\t\t\t\tpreviousPath,\n\t\t\t\t\t\t\t\tnewPath,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Content relationship field\n\t\t\treturn {\n\t\t\t\t...customTypeField,\n\t\t\t\tcustomtypes: updateContentRelationshipFields({\n\t\t\t\t\tcustomtypes: customTypeField.customtypes,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t}),\n\t\t\t};\n\t\t}),\n\t};\n}\n\nfunction updateContentRelationshipFields(args: {\n\tcustomtypes: readonly (\n\t\t| string\n\t\t| {\n\t\t\t\tid: string;\n\t\t\t\tfields: readonly (string | { id: string; fields: readonly string[] })[];\n\t\t }\n\t)[];\n\tpreviousPath: CrUpdatePathIds;\n\tnewPath: CrUpdatePathIds;\n}) {\n\tconst { customtypes, previousPath, newPath } = args;\n\n\treturn customtypes.map((nestedCtArg) => {\n\t\tconst nestedCt = shallowCloneIfObject(nestedCtArg);\n\n\t\tif (\n\t\t\ttypeof nestedCt === \"string\" ||\n\t\t\t// Since we are entering a new custom type, if the previous id\n\t\t\t// doesn't match, we can return early, because it's not the\n\t\t\t// custom type we are looking for.\n\t\t\tnestedCt.id !== previousPath.customTypeId\n\t\t) {\n\t\t\treturn nestedCt;\n\t\t}\n\n\t\treturn {\n\t\t\t...nestedCt,\n\t\t\tfields: nestedCt.fields.map((nestedCtFieldArg) => {\n\t\t\t\tconst nestedCtField = shallowCloneIfObject(nestedCtFieldArg);\n\n\t\t\t\t// Regular field\n\t\t\t\tif (typeof nestedCtField === \"string\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\tnestedCtField === previousPath.fieldId &&\n\t\t\t\t\t\tnestedCtField !== newPath.fieldId\n\t\t\t\t\t) {\n\t\t\t\t\t\t// The id of the field has changed.\n\t\t\t\t\t\treturn newPath.fieldId;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn nestedCtField;\n\t\t\t\t}\n\n\t\t\t\t// Group field\n\n\t\t\t\tif (\n\t\t\t\t\tnestedCtField.id === previousPath.fieldId &&\n\t\t\t\t\tnestedCtField.id !== newPath.fieldId\n\t\t\t\t) {\n\t\t\t\t\t// The id of the field has changed.\n\t\t\t\t\tnestedCtField.id = newPath.fieldId;\n\t\t\t\t}\n\n\t\t\t\t// Further down the path, the field can only be a group field. So if we have\n\t\t\t\t// no group id defined, no need to continue.\n\t\t\t\tif (\n\t\t\t\t\t!previousPath.groupId ||\n\t\t\t\t\t!newPath.groupId ||\n\t\t\t\t\tnestedCtField.id !== previousPath.groupId\n\t\t\t\t) {\n\t\t\t\t\treturn nestedCtField;\n\t\t\t\t}\n\n\t\t\t\tif (nestedCtField.id !== newPath.groupId) {\n\t\t\t\t\t// The id of the group has changed.\n\t\t\t\t\tnestedCtField.id = newPath.groupId;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...nestedCtField,\n\t\t\t\t\tfields: nestedCtField.fields.map((nestedCtGroupFieldId) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnestedCtGroupFieldId === previousPath.fieldId &&\n\t\t\t\t\t\t\tnestedCtGroupFieldId !== newPath.fieldId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// The id of the field inside the group has changed.\n\t\t\t\t\t\t\treturn newPath.fieldId;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nestedCtGroupFieldId;\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n}\n\n/**\n * Update the Content Relationship API IDs of a single field. The change is\n * determined by the `previousPath` and `newPath` properties.\n */\nfunction updateFieldContentRelationships<\n\tT extends UID | NestableWidget | Group | NestedGroup,\n>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\tconst { field, ...updateMeta } = args;\n\tif (\n\t\tfield.type !== \"Link\" ||\n\t\tfield.config?.select !== \"document\" ||\n\t\t!field.config?.customtypes\n\t) {\n\t\t// not a content relationship field\n\t\treturn field;\n\t}\n\n\tconst newCustomTypes = field.config.customtypes.map((customType) => {\n\t\treturn updateCRCustomType({ customType, ...updateMeta });\n\t});\n\n\treturn {\n\t\t...field,\n\t\tconfig: { ...field.config, customtypes: newCustomTypes },\n\t};\n}\n\nexport function updateCustomTypeContentRelationships(\n\targs: {\n\t\tmodels: { model: CustomType }[];\n\t\tonUpdate: (model: { previousModel: CustomType; model: CustomType }) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: customType } of models) {\n\t\tconst updatedCustomType = traverseCustomType({\n\t\t\tcustomType,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(customType, updatedCustomType)) {\n\t\t\tonUpdate({ model: updatedCustomType, previousModel: customType });\n\t\t}\n\t}\n}\n\nexport function updateSharedSliceContentRelationships(\n\targs: {\n\t\tmodels: { model: SharedSlice }[];\n\t\tonUpdate: (model: {\n\t\t\tpreviousModel: SharedSlice;\n\t\t\tmodel: SharedSlice;\n\t\t}) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: slice } of models) {\n\t\tconst updateSlice = traverseSharedSlice({\n\t\t\tpath: [],\n\t\t\tslice,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(slice, updateSlice)) {\n\t\t\tonUpdate({ model: updateSlice, previousModel: slice });\n\t\t}\n\t}\n}\n\ninterface CrUpdatePathIds {\n\tcustomTypeId: string;\n\tgroupId: string | undefined;\n\tfieldId: string;\n}\n\nfunction getPathIds(path: PathWithCustomType): CrUpdatePathIds {\n\tif (path.length < 2) {\n\t\tthrow new Error(\n\t\t\t`Unexpected path length ${\n\t\t\t\tpath.length\n\t\t\t}. Expected at least 2 segments (got: ${path.join(\".\")}).`,\n\t\t);\n\t}\n\n\tconst [customTypeId, groupOrFieldId, fieldId] = path;\n\n\treturn {\n\t\tcustomTypeId,\n\t\t/**\n\t\t * Id of a changed group. If it's defined, it means that a group or a field\n\t\t * inside a group had its API ID renamed. It's defined when the path has a\n\t\t * third element (e.g. `[\"customtypeA\", \"groupA\", \"fieldA\"]`).\n\t\t */\n\t\tgroupId: fieldId ? groupOrFieldId : undefined,\n\t\tfieldId: fieldId || groupOrFieldId,\n\t};\n}\n\nfunction isEqualModel<T extends CustomType | SharedSlice>(\n\tmodelA: T,\n\tmodelB: T,\n): boolean {\n\treturn JSON.stringify(modelA) === JSON.stringify(modelB);\n}\n\nfunction shallowCloneIfObject<T>(value: T): T {\n\tif (typeof value === \"object\") {\n\t\treturn { ...value };\n\t}\n\n\treturn value;\n}\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","_a","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice","customtypes","traverseCustomType","traverseSharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiIM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1BC,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,KAAKA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB,QAAAF;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/CD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,QAAAC,QAAA,IAAW,MAAM,KAAK,sBAAqB;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