@slicemachine/manager 0.24.16-alpha.jp-cr-sync-groups.1 → 0.24.16-alpha.jp-cr-sync-groups.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/managers/customTypes/CustomTypesManager.cjs +7 -7
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.d.ts +19 -14
- package/dist/managers/customTypes/CustomTypesManager.js +7 -7
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/package.json +2 -2
- package/src/managers/customTypes/CustomTypesManager.ts +47 -26
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
const _commonjsHelpers = require("../../../../../../_virtual/_commonjsHelpers.cjs");
|
3
3
|
const client = require("../../../../../../_virtual/client2.cjs");
|
4
|
-
const index = require("../../../../../../_virtual/
|
4
|
+
const index = require("../../../../../../_virtual/index3.cjs");
|
5
5
|
const experimentCore_esm = require("../../../../../../_virtual/experiment-core.esm.cjs");
|
6
6
|
require("../assignment/assignment.cjs");
|
7
7
|
require("../assignment/assignment-filter.cjs");
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { commonjsGlobal } from "../../../../../../_virtual/_commonjsHelpers.js";
|
2
2
|
import { __exports as client } from "../../../../../../_virtual/client2.js";
|
3
|
-
import require$$0 from "../../../../../../_virtual/
|
3
|
+
import require$$0 from "../../../../../../_virtual/index3.js";
|
4
4
|
import require$$1 from "../../../../../../_virtual/experiment-core.esm.js";
|
5
5
|
import "../assignment/assignment.js";
|
6
6
|
import "../assignment/assignment-filter.js";
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
const _commonjsHelpers = require("../../_virtual/_commonjsHelpers.cjs");
|
3
|
-
const index = require("../../_virtual/
|
3
|
+
const index = require("../../_virtual/index2.cjs");
|
4
4
|
const require$$0 = require("child_process");
|
5
5
|
const parse$1 = require("./lib/parse.cjs");
|
6
6
|
const enoent$1 = require("./lib/enoent.cjs");
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { getDefaultExportFromCjs } from "../../_virtual/_commonjsHelpers.js";
|
2
|
-
import { __module as crossSpawn$1 } from "../../_virtual/
|
2
|
+
import { __module as crossSpawn$1 } from "../../_virtual/index2.js";
|
3
3
|
import require$$0 from "child_process";
|
4
4
|
import { p as parse_1 } from "./lib/parse.js";
|
5
5
|
import { e as enoent$1 } from "./lib/enoent.js";
|
package/dist/_virtual/index2.cjs
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
module.exports = require$$0;
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
var crossSpawn = { exports: {} };
|
4
|
+
exports.__module = crossSpawn;
|
6
5
|
//# sourceMappingURL=index2.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index2.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index2.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/dist/_virtual/index2.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
import * as index from './../_node_modules/@amplitude/analytics-node/lib/esm/index.js';
|
3
|
-
const require$$0 = /* @__PURE__ */ getAugmentedNamespace(index);
|
1
|
+
var crossSpawn = { exports: {} };
|
4
2
|
export {
|
5
|
-
|
3
|
+
crossSpawn as __module
|
6
4
|
};
|
7
5
|
//# sourceMappingURL=index2.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index2.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/_virtual/index3.cjs
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
const _commonjsHelpers = require("./_commonjsHelpers.cjs");
|
3
|
+
const index = require('./../_node_modules/@amplitude/analytics-node/lib/esm/index.cjs');
|
4
|
+
const require$$0 = /* @__PURE__ */ _commonjsHelpers.getAugmentedNamespace(index);
|
5
|
+
module.exports = require$$0;
|
5
6
|
//# sourceMappingURL=index3.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index3.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index3.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
package/dist/_virtual/index3.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
1
|
+
import { getAugmentedNamespace } from "./_commonjsHelpers.js";
|
2
|
+
import * as index from './../_node_modules/@amplitude/analytics-node/lib/esm/index.js';
|
3
|
+
const require$$0 = /* @__PURE__ */ getAugmentedNamespace(index);
|
2
4
|
export {
|
3
|
-
|
5
|
+
require$$0 as default
|
4
6
|
};
|
5
7
|
//# sourceMappingURL=index3.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index3.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index3.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
@@ -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({
|
@@ -332,10 +332,10 @@ function updateCRCustomType(args) {
|
|
332
332
|
const previousPath = getPathIds(args.previousPath);
|
333
333
|
const newPath = getPathIds(args.newPath);
|
334
334
|
if (!previousPath.customTypeId || !newPath.customTypeId) {
|
335
|
-
throw new Error(
|
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
337
|
if (!previousPath.fieldId || !newPath.fieldId) {
|
338
|
-
throw new Error(
|
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
341
|
if (typeof customType === "string") {
|
@@ -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\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\nexport type SliceMachineManagerUpdateCustomTypeArgs =\n\tCustomTypeUpdateHookData & {\n\t\tupdateMeta?: {\n\t\t\tfieldIdChanged?: {\n\t\t\t\t/**\n\t\t\t\t * Previous path of the changed field. Can be used to identify the field\n\t\t\t\t * that had an API ID rename (e.g. [\"page\", \"title\"])\n\t\t\t\t */\n\t\t\t\tpreviousPath: string[];\n\t\t\t\t/**\n\t\t\t\t * New path of the changed field. Can be used to identify the field that\n\t\t\t\t * had an API ID rename (e.g. [\"page\", \"title2\"])\n\t\t\t\t */\n\t\t\t\tnewPath: string[];\n\t\t\t};\n\t\t};\n\t};\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 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: { 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: 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 and/or newPath, 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 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\") {\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: CrUpdatePath;\n\tnewPath: CrUpdatePath;\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 CrUpdatePath {\n\tcustomTypeId: string;\n\tgroupId: string | undefined;\n\tfieldId: string;\n}\n\nfunction getPathIds(path: string[]): CrUpdatePath {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHM,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,UA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;AACtC,UAAM,cAAcC,YAAAA,oBAAoB;AAAA,MACvC,MAAM,CAAE;AAAA,MACR;AAAA,MACA,SAAS,CAAC,EAAE,YAAW;AACtB,eAAO,gCAAgC;AAAA,UACtC;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA,CACA;AAED,QAAI,CAAC,aAAa,OAAO,WAAW,GAAG;AACtC,eAAS,EAAE,OAAO,aAAa,eAAe,MAAO,CAAA;AAAA,IACtD;AAAA,EACD;AACD;AAQA,SAAS,WAAW,MAAc;AACjC,QAAM,CAAC,cAAc,gBAAgB,OAAO,IAAI;AAEzC,SAAA;AAAA,IACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,UAAU,iBAAiB;AAAA,IACpC,SAAS,WAAW;AAAA,EAAA;AAEtB;AAEA,SAAS,aACR,QACA,QAAS;AAET,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,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\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: [string] | [string, string];\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: [string] | [string, string];\n};\n\nexport type SliceMachineManagerUpdateCustomTypeArgs =\n\tCustomTypeUpdateHookData & {\n\t\tupdateMeta?: {\n\t\t\tfieldIdChanged?: SliceMachineManagerUpdateCustomTypeFieldIdChanged;\n\t\t};\n\t};\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/** Path of the changed field, including the custom type id. */\ntype CustomTypeUpdatePath = [string, string] | [string, string, string];\n\ntype CustomTypeFieldIdChangedMeta = {\n\tpreviousPath: CustomTypeUpdatePath;\n\tnewPath: CustomTypeUpdatePath;\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: CustomTypeUpdatePath = [ctId, ...previousFieldPath];\n\t\t\tconst newPath: CustomTypeUpdatePath = [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: CustomTypeUpdatePath): CrUpdatePathIds {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HM,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,iB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|
37
37
|
customTypeID: string;
|
38
38
|
mocksConfig: Record<string, unknown>;
|
39
39
|
};
|
40
|
+
type SliceMachineManagerUpdateCustomTypeFieldIdChanged = {
|
41
|
+
/**
|
42
|
+
* Previous path of the changed field, excluding the custom type id. Can be
|
43
|
+
* used to identify the field that had an API ID rename (e.g. ["fieldA"] or
|
44
|
+
* ["groupA", "fieldA"])
|
45
|
+
*/
|
46
|
+
previousPath: [string] | [string, string];
|
47
|
+
/**
|
48
|
+
* New path of the changed field, excluding the custom type id. Can be used to
|
49
|
+
* identify the field that had an API ID rename (e.g. ["fieldB"] or ["groupA",
|
50
|
+
* "fieldB"])
|
51
|
+
*/
|
52
|
+
newPath: [string] | [string, string];
|
53
|
+
};
|
40
54
|
export type SliceMachineManagerUpdateCustomTypeArgs = CustomTypeUpdateHookData & {
|
41
55
|
updateMeta?: {
|
42
|
-
fieldIdChanged?:
|
43
|
-
/**
|
44
|
-
* Previous path of the changed field. Can be used to identify the field
|
45
|
-
* that had an API ID rename (e.g. ["page", "title"])
|
46
|
-
*/
|
47
|
-
previousPath: string[];
|
48
|
-
/**
|
49
|
-
* New path of the changed field. Can be used to identify the field that
|
50
|
-
* had an API ID rename (e.g. ["page", "title2"])
|
51
|
-
*/
|
52
|
-
newPath: string[];
|
53
|
-
};
|
56
|
+
fieldIdChanged?: SliceMachineManagerUpdateCustomTypeFieldIdChanged;
|
54
57
|
};
|
55
58
|
};
|
56
59
|
type SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {
|
@@ -65,9 +68,11 @@ type CustomTypesMachineManagerDeleteCustomTypeReturnType = {
|
|
65
68
|
type CustomTypesMachineManagerUpdateCustomTypeReturnType = {
|
66
69
|
errors: (DecodeError | HookError)[];
|
67
70
|
};
|
71
|
+
/** Path of the changed field, including the custom type id. */
|
72
|
+
type CustomTypeUpdatePath = [string, string] | [string, string, string];
|
68
73
|
type CustomTypeFieldIdChangedMeta = {
|
69
|
-
previousPath:
|
70
|
-
newPath:
|
74
|
+
previousPath: CustomTypeUpdatePath;
|
75
|
+
newPath: CustomTypeUpdatePath;
|
71
76
|
};
|
72
77
|
export declare class CustomTypesManager extends BaseManager {
|
73
78
|
readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType>;
|
@@ -67,11 +67,11 @@ class CustomTypesManager extends BaseManager {
|
|
67
67
|
*/
|
68
68
|
async updateContentRelationships(args) {
|
69
69
|
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
70
|
-
const { model } = args;
|
71
|
-
|
72
|
-
|
73
|
-
previousPath = [
|
74
|
-
newPath = [
|
70
|
+
const { model, previousPath: previousFieldPath, newPath: newFieldPath } = args;
|
71
|
+
if (previousFieldPath.join(".") !== newFieldPath.join(".")) {
|
72
|
+
const { id: ctId } = model;
|
73
|
+
const previousPath = [ctId, ...previousFieldPath];
|
74
|
+
const newPath = [ctId, ...newFieldPath];
|
75
75
|
const crUpdates = [];
|
76
76
|
const customTypes = await this.readAllCustomTypes();
|
77
77
|
updateCustomTypeContentRelationships({
|
@@ -312,10 +312,10 @@ function updateCRCustomType(args) {
|
|
312
312
|
const previousPath = getPathIds(args.previousPath);
|
313
313
|
const newPath = getPathIds(args.newPath);
|
314
314
|
if (!previousPath.customTypeId || !newPath.customTypeId) {
|
315
|
-
throw new Error(
|
315
|
+
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.`);
|
316
316
|
}
|
317
317
|
if (!previousPath.fieldId || !newPath.fieldId) {
|
318
|
-
throw new Error(
|
318
|
+
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.`);
|
319
319
|
}
|
320
320
|
const customType = shallowCloneIfObject(args.customType);
|
321
321
|
if (typeof customType === "string") {
|
@@ -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 {\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\nexport type SliceMachineManagerUpdateCustomTypeArgs =\n\tCustomTypeUpdateHookData & {\n\t\tupdateMeta?: {\n\t\t\tfieldIdChanged?: {\n\t\t\t\t/**\n\t\t\t\t * Previous path of the changed field. Can be used to identify the field\n\t\t\t\t * that had an API ID rename (e.g. [\"page\", \"title\"])\n\t\t\t\t */\n\t\t\t\tpreviousPath: string[];\n\t\t\t\t/**\n\t\t\t\t * New path of the changed field. Can be used to identify the field that\n\t\t\t\t * had an API ID rename (e.g. [\"page\", \"title2\"])\n\t\t\t\t */\n\t\t\t\tnewPath: string[];\n\t\t\t};\n\t\t};\n\t};\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 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: { 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: 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 and/or newPath, 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 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\") {\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: CrUpdatePath;\n\tnewPath: CrUpdatePath;\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 CrUpdatePath {\n\tcustomTypeId: string;\n\tgroupId: string | undefined;\n\tfieldId: string;\n}\n\nfunction getPathIds(path: string[]): CrUpdatePath {\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":["errors","_a"],"mappings":";;;;;;;;;;;AAwHM,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;AA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;AAED,QAAI,CAAC,aAAa,OAAO,WAAW,GAAG;AACtC,eAAS,EAAE,OAAO,aAAa,eAAe,MAAO,CAAA;AAAA,IACtD;AAAA,EACD;AACD;AAQA,SAAS,WAAW,MAAc;AACjC,QAAM,CAAC,cAAc,gBAAgB,OAAO,IAAI;AAEzC,SAAA;AAAA,IACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,UAAU,iBAAiB;AAAA,IACpC,SAAS,WAAW;AAAA,EAAA;AAEtB;AAEA,SAAS,aACR,QACA,QAAS;AAET,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,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.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\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\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: [string] | [string, string];\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: [string] | [string, string];\n};\n\nexport type SliceMachineManagerUpdateCustomTypeArgs =\n\tCustomTypeUpdateHookData & {\n\t\tupdateMeta?: {\n\t\t\tfieldIdChanged?: SliceMachineManagerUpdateCustomTypeFieldIdChanged;\n\t\t};\n\t};\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/** Path of the changed field, including the custom type id. */\ntype CustomTypeUpdatePath = [string, string] | [string, string, string];\n\ntype CustomTypeFieldIdChangedMeta = {\n\tpreviousPath: CustomTypeUpdatePath;\n\tnewPath: CustomTypeUpdatePath;\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: CustomTypeUpdatePath = [ctId, ...previousFieldPath];\n\t\t\tconst newPath: CustomTypeUpdatePath = [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: CustomTypeUpdatePath): CrUpdatePathIds {\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":["errors","_a"],"mappings":";;;;;;;;;;;AA+HM,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,S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A;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA,CACA;AAED,QAAI,CAAC,aAAa,OAAO,WAAW,GAAG;AACtC,eAAS,EAAE,OAAO,aAAa,eAAe,MAAO,CAAA;AAAA,IACtD;AAAA,EACD;AACD;AAQA,SAAS,WAAW,MAA0B;AAC7C,QAAM,CAAC,cAAc,gBAAgB,OAAO,IAAI;AAEzC,SAAA;AAAA,IACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,UAAU,iBAAiB;AAAA,IACpC,SAAS,WAAW;AAAA,EAAA;AAEtB;AAEA,SAAS,aACR,QACA,QAAS;AAET,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,UAAU,MAAM;AACxD;AAEA,SAAS,qBAAwB,OAAQ;AACpC,MAAA,OAAO,UAAU,UAAU;AACvB,WAAA,EAAE,GAAG;EACb;AAEO,SAAA;AACR;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@slicemachine/manager",
|
3
|
-
"version": "0.24.16-alpha.jp-cr-sync-groups.
|
3
|
+
"version": "0.24.16-alpha.jp-cr-sync-groups.3",
|
4
4
|
"description": "Manage all aspects of a Slice Machine project.",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -70,7 +70,7 @@
|
|
70
70
|
"@prismicio/mocks": "2.13.0",
|
71
71
|
"@prismicio/types-internal": "3.11.0",
|
72
72
|
"@segment/analytics-node": "^2.1.2",
|
73
|
-
"@slicemachine/plugin-kit": "0.4.78-alpha.jp-cr-sync-groups.
|
73
|
+
"@slicemachine/plugin-kit": "0.4.78-alpha.jp-cr-sync-groups.3",
|
74
74
|
"cookie": "^1.0.1",
|
75
75
|
"cors": "^2.8.5",
|
76
76
|
"execa": "^7.1.1",
|
@@ -77,21 +77,25 @@ type SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {
|
|
77
77
|
mocksConfig: Record<string, unknown>;
|
78
78
|
};
|
79
79
|
|
80
|
+
type SliceMachineManagerUpdateCustomTypeFieldIdChanged = {
|
81
|
+
/**
|
82
|
+
* Previous path of the changed field, excluding the custom type id. Can be
|
83
|
+
* used to identify the field that had an API ID rename (e.g. ["fieldA"] or
|
84
|
+
* ["groupA", "fieldA"])
|
85
|
+
*/
|
86
|
+
previousPath: [string] | [string, string];
|
87
|
+
/**
|
88
|
+
* New path of the changed field, excluding the custom type id. Can be used to
|
89
|
+
* identify the field that had an API ID rename (e.g. ["fieldB"] or ["groupA",
|
90
|
+
* "fieldB"])
|
91
|
+
*/
|
92
|
+
newPath: [string] | [string, string];
|
93
|
+
};
|
94
|
+
|
80
95
|
export type SliceMachineManagerUpdateCustomTypeArgs =
|
81
96
|
CustomTypeUpdateHookData & {
|
82
97
|
updateMeta?: {
|
83
|
-
fieldIdChanged?:
|
84
|
-
/**
|
85
|
-
* Previous path of the changed field. Can be used to identify the field
|
86
|
-
* that had an API ID rename (e.g. ["page", "title"])
|
87
|
-
*/
|
88
|
-
previousPath: string[];
|
89
|
-
/**
|
90
|
-
* New path of the changed field. Can be used to identify the field that
|
91
|
-
* had an API ID rename (e.g. ["page", "title2"])
|
92
|
-
*/
|
93
|
-
newPath: string[];
|
94
|
-
};
|
98
|
+
fieldIdChanged?: SliceMachineManagerUpdateCustomTypeFieldIdChanged;
|
95
99
|
};
|
96
100
|
};
|
97
101
|
|
@@ -111,9 +115,12 @@ type CustomTypesMachineManagerUpdateCustomTypeReturnType = {
|
|
111
115
|
errors: (DecodeError | HookError)[];
|
112
116
|
};
|
113
117
|
|
118
|
+
/** Path of the changed field, including the custom type id. */
|
119
|
+
type CustomTypeUpdatePath = [string, string] | [string, string, string];
|
120
|
+
|
114
121
|
type CustomTypeFieldIdChangedMeta = {
|
115
|
-
previousPath:
|
116
|
-
newPath:
|
122
|
+
previousPath: CustomTypeUpdatePath;
|
123
|
+
newPath: CustomTypeUpdatePath;
|
117
124
|
};
|
118
125
|
|
119
126
|
type LinkCustomType = NonNullable<LinkConfig["customtypes"]>[number];
|
@@ -209,7 +216,9 @@ export class CustomTypesManager extends BaseManager {
|
|
209
216
|
* property.
|
210
217
|
*/
|
211
218
|
private async updateContentRelationships(
|
212
|
-
args: {
|
219
|
+
args: {
|
220
|
+
model: CustomType;
|
221
|
+
} & SliceMachineManagerUpdateCustomTypeFieldIdChanged,
|
213
222
|
): Promise<
|
214
223
|
OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>> & {
|
215
224
|
rollback?: () => Promise<void>;
|
@@ -217,12 +226,16 @@ export class CustomTypesManager extends BaseManager {
|
|
217
226
|
> {
|
218
227
|
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
219
228
|
|
220
|
-
const {
|
221
|
-
|
229
|
+
const {
|
230
|
+
model,
|
231
|
+
previousPath: previousFieldPath,
|
232
|
+
newPath: newFieldPath,
|
233
|
+
} = args;
|
222
234
|
|
223
|
-
if (
|
224
|
-
|
225
|
-
|
235
|
+
if (previousFieldPath.join(".") !== newFieldPath.join(".")) {
|
236
|
+
const { id: ctId } = model;
|
237
|
+
const previousPath: CustomTypeUpdatePath = [ctId, ...previousFieldPath];
|
238
|
+
const newPath: CustomTypeUpdatePath = [ctId, ...newFieldPath];
|
226
239
|
|
227
240
|
const crUpdates: {
|
228
241
|
updatePromise: Promise<{ errors: HookError[] }>;
|
@@ -578,13 +591,21 @@ function updateCRCustomType(
|
|
578
591
|
|
579
592
|
if (!previousPath.customTypeId || !newPath.customTypeId) {
|
580
593
|
throw new Error(
|
581
|
-
|
594
|
+
`Could not find a customtype id in previousPath (${args.previousPath.join(
|
595
|
+
".",
|
596
|
+
)}) and/or newPath (${args.newPath.join(
|
597
|
+
".",
|
598
|
+
)}), which should not be possible.`,
|
582
599
|
);
|
583
600
|
}
|
584
601
|
|
585
602
|
if (!previousPath.fieldId || !newPath.fieldId) {
|
586
603
|
throw new Error(
|
587
|
-
|
604
|
+
`Could not find a field id in previousPath (${args.previousPath.join(
|
605
|
+
".",
|
606
|
+
)}) and/or newPath (${args.newPath.join(
|
607
|
+
".",
|
608
|
+
)}), which should not be possible.`,
|
588
609
|
);
|
589
610
|
}
|
590
611
|
|
@@ -706,8 +727,8 @@ function updateContentRelationshipFields(args: {
|
|
706
727
|
fields: readonly (string | { id: string; fields: readonly string[] })[];
|
707
728
|
}
|
708
729
|
)[];
|
709
|
-
previousPath:
|
710
|
-
newPath:
|
730
|
+
previousPath: CrUpdatePathIds;
|
731
|
+
newPath: CrUpdatePathIds;
|
711
732
|
}) {
|
712
733
|
const { customtypes, previousPath, newPath } = args;
|
713
734
|
|
@@ -869,13 +890,13 @@ export function updateSharedSliceContentRelationships(
|
|
869
890
|
}
|
870
891
|
}
|
871
892
|
|
872
|
-
interface
|
893
|
+
interface CrUpdatePathIds {
|
873
894
|
customTypeId: string;
|
874
895
|
groupId: string | undefined;
|
875
896
|
fieldId: string;
|
876
897
|
}
|
877
898
|
|
878
|
-
function getPathIds(path:
|
899
|
+
function getPathIds(path: CustomTypeUpdatePath): CrUpdatePathIds {
|
879
900
|
const [customTypeId, groupOrFieldId, fieldId] = path;
|
880
901
|
|
881
902
|
return {
|