@slicemachine/manager 0.24.14-alpha.jp-update-cr-links.2 → 0.24.14-alpha.jp-update-cr-links.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 +4 -3
- package/dist/_virtual/index2.cjs.map +1 -1
- package/dist/_virtual/index2.js +4 -2
- package/dist/_virtual/index2.js.map +1 -1
- package/dist/_virtual/index3.cjs +3 -4
- package/dist/_virtual/index3.cjs.map +1 -1
- package/dist/_virtual/index3.js +2 -4
- package/dist/_virtual/index3.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs +15 -9
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.js +15 -9
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/package.json +2 -2
- package/src/managers/customTypes/CustomTypesManager.ts +28 -23
@@ -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/index2.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/index2.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/index3.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/index3.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,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=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,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=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,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=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,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=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":";"}
|
@@ -97,7 +97,7 @@ class CustomTypesManager extends BaseManager.BaseManager {
|
|
97
97
|
}
|
98
98
|
return customType;
|
99
99
|
}
|
100
|
-
if (customType.id
|
100
|
+
if (customType.id == previousId && customType.id !== newId) {
|
101
101
|
customType.id = newId;
|
102
102
|
}
|
103
103
|
if (customType.fields) {
|
@@ -174,6 +174,7 @@ class CustomTypesManager extends BaseManager.BaseManager {
|
|
174
174
|
const hookResult = await this.sliceMachinePluginRunner.callHook("custom-type:update", args);
|
175
175
|
const { model, updateMeta } = args;
|
176
176
|
if (updateMeta == null ? void 0 : updateMeta.fieldIdChanged) {
|
177
|
+
const crUpdatesPromises = [];
|
177
178
|
let { previousPath, newPath } = updateMeta.fieldIdChanged;
|
178
179
|
if (previousPath.join(".") !== newPath.join(".")) {
|
179
180
|
previousPath = [model.id, ...previousPath];
|
@@ -190,10 +191,9 @@ class CustomTypesManager extends BaseManager.BaseManager {
|
|
190
191
|
});
|
191
192
|
}
|
192
193
|
});
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
}
|
194
|
+
crUpdatesPromises.push(this.sliceMachinePluginRunner.callHook("custom-type:update", {
|
195
|
+
model: updatedCustomTypeModel
|
196
|
+
}));
|
197
197
|
}
|
198
198
|
const { libraries } = await this.slices.readAllSliceLibraries();
|
199
199
|
for (const library of libraries) {
|
@@ -212,12 +212,18 @@ class CustomTypesManager extends BaseManager.BaseManager {
|
|
212
212
|
});
|
213
213
|
}
|
214
214
|
});
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
}
|
215
|
+
crUpdatesPromises.push(this.sliceMachinePluginRunner.callHook("slice:update", {
|
216
|
+
libraryID: library.libraryID,
|
217
|
+
model: updatedSliceModel
|
218
|
+
}));
|
219
219
|
}
|
220
220
|
}
|
221
|
+
const crUpdatesResults = await Promise.all(crUpdatesPromises);
|
222
|
+
if (crUpdatesResults.some((result) => result.errors.length > 0)) {
|
223
|
+
return {
|
224
|
+
errors: crUpdatesResults.flatMap((result) => result.errors)
|
225
|
+
};
|
226
|
+
}
|
221
227
|
}
|
222
228
|
}
|
223
229
|
return { errors: hookResult.errors };
|
@@ -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\tLink,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypeUpdateMeta = {\n\tpreviousPath: string[];\n\tnewPath: string[];\n};\ntype CRCustomTypes = NonNullable<NonNullable<Link[\"config\"]>[\"customtypes\"]>;\ntype CRCustomType = NonNullable<CRCustomTypes>[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\tprivate updateCRCustomType(\n\t\targs: { customType: CRCustomType } & CustomTypeUpdateMeta,\n\t): CRCustomType {\n\t\tconst { customType: customTypeArg, previousPath, newPath } = args;\n\n\t\tlet customType = customTypeArg;\n\t\tif (typeof customTypeArg === \"object\") {\n\t\t\tcustomType = { ...customTypeArg };\n\t\t}\n\n\t\tconst [previousId] = previousPath;\n\t\tconst [newId] = newPath;\n\n\t\tif (!previousId || !newId) {\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (typeof customType === \"string\") {\n\t\t\tif (customType === previousId && customType !== newId) {\n\t\t\t\treturn newId; // update to new api id\n\t\t\t}\n\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (customType.id === previousId && customType.id !== newId) {\n\t\t\tcustomType.id = newId; // update to new api id\n\t\t}\n\n\t\tif (customType.fields) {\n\t\t\treturn {\n\t\t\t\t...customType,\n\t\t\t\tfields: customType.fields.map((field) => {\n\t\t\t\t\tconst previousId = previousPath[1];\n\t\t\t\t\tconst newId = newPath[1];\n\n\t\t\t\t\tif (!previousId || !newId) {\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (typeof field === \"string\") {\n\t\t\t\t\t\tif (field === previousId && field !== newId) {\n\t\t\t\t\t\t\treturn newId; // update to new api id\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field.id === previousId && field.id !== newId) {\n\t\t\t\t\t\tfield.id = newId; // update to new api id\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...field,\n\t\t\t\t\t\tcustomtypes: field.customtypes.map((customType) => {\n\t\t\t\t\t\t\treturn this.updateCRCustomType({\n\t\t\t\t\t\t\t\tcustomType,\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\t// TODO: Fix types. The second level customtypes are not typed\n\t\t\t\t\t\t\t\t// the same as the first level customtypes. Although it won't\n\t\t\t\t\t\t\t\t// matter at runtime.\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- -\n\t\t\t\t\t\t\t}) as any;\n\t\t\t\t\t\t}),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t};\n\t\t}\n\n\t\treturn { ...customType };\n\t}\n\n\t/**\n\t * Map over the custom types of a Content Relationship Link and update the API\n\t * IDs that were changed during the custom type update.\n\t */\n\tprivate updateCRCustomTypes(\n\t\targs: { customTypes: CRCustomTypes } & CustomTypeUpdateMeta,\n\t): CRCustomTypes {\n\t\tconst { customTypes, ...updateMeta } = args;\n\n\t\treturn customTypes.map((customType) => {\n\t\t\treturn this.updateCRCustomType({ customType, ...updateMeta });\n\t\t});\n\t}\n\n\t/**\n\t * Update the Content Relationship API IDs that were changed during the custom\n\t * type update. The change is determined by the `previousPath` and `newPath`\n\t * properties.\n\t */\n\tprivate updateFieldContentRelationships<\n\t\tT extends UID | NestableWidget | Group | NestedGroup,\n\t>(args: { field: T } & CustomTypeUpdateMeta): T {\n\t\tconst { field, ...updateMeta } = args;\n\t\tif (\n\t\t\tfield.type !== \"Link\" ||\n\t\t\tfield.config?.select !== \"document\" ||\n\t\t\t!field.config?.customtypes\n\t\t) {\n\t\t\treturn field; // not a content relationship field\n\t\t}\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tconfig: {\n\t\t\t\t...field.config,\n\t\t\t\tcustomtypes: this.updateCRCustomTypes({\n\t\t\t\t\t...updateMeta,\n\t\t\t\t\tcustomTypes: field.config.customtypes.slice(),\n\t\t\t\t}),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst { model, updateMeta } = args;\n\n\t\tif (updateMeta?.fieldIdChanged) {\n\t\t\tlet { previousPath, newPath } = updateMeta.fieldIdChanged;\n\n\t\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t\t// any custom type and update them to use the new one.\n\t\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\t\tfor (const customType of customTypes.models) {\n\t\t\t\t\tconst updatedCustomTypeModel = traverseCustomType({\n\t\t\t\t\t\tcustomType: customType.model,\n\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\tfield,\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\n\t\t\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\t\t\"custom-type:update\",\n\t\t\t\t\t\t{ model: updatedCustomTypeModel },\n\t\t\t\t\t);\n\n\t\t\t\t\tif (hookResult.errors.length > 0) {\n\t\t\t\t\t\treturn { errors: hookResult.errors };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\t\tfor (const library of libraries) {\n\t\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tfor (const slice of slices.models) {\n\t\t\t\t\t\tconst updatedSliceModel = traverseSharedSlice({\n\t\t\t\t\t\t\tpath: [\".\"],\n\t\t\t\t\t\t\tslice: slice.model,\n\t\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\tpreviousPath,\n\t\t\t\t\t\t\t\t\tnewPath,\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\n\t\t\t\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\t\t\t\"slice:update\",\n\t\t\t\t\t\t\t{ libraryID: library.libraryID, model: updatedSliceModel },\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (hookResult.errors.length > 0) {\n\t\t\t\t\t\t\treturn { errors: hookResult.errors };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: hookResult.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"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","previousId","newId","customType","traverseCustomType","hookResult","traverseSharedSlice","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGM,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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B,UAAM,WAAW,MAAMC,MAAAA,QAAM,IAAI,YAAY;AAAA,MAC5C,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,UAAU;AAAA,IAAA,CACjC;AAEG,QAAA,CAAC,SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqBG,cAAE,OAAO;AAAA,EACnC,OAAOA,MAAE,QAAA,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAASC,YAAAA,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAMD,MAAAA,QAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAOA,MAAAA,QAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAcA,MAAAA,QAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;;"}
|
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\tLink,\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\tSliceUpdateHookReturnType,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CRCustomTypes = NonNullable<NonNullable<Link[\"config\"]>[\"customtypes\"]>;\ntype CRCustomType = NonNullable<CRCustomTypes>[number];\ntype CustomTypeFieldIdChangedMeta = NonNullable<\n\tNonNullable<CustomTypeUpdateHookData[\"updateMeta\"]>[\"fieldIdChanged\"]\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\tprivate updateCRCustomType(\n\t\targs: { customType: CRCustomType } & CustomTypeFieldIdChangedMeta,\n\t): CRCustomType {\n\t\tconst { customType: customTypeArg, previousPath, newPath } = args;\n\n\t\tlet customType = customTypeArg;\n\t\tif (typeof customTypeArg === \"object\") {\n\t\t\tcustomType = { ...customTypeArg };\n\t\t}\n\n\t\tconst [previousId] = previousPath;\n\t\tconst [newId] = newPath;\n\n\t\tif (!previousId || !newId) {\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (typeof customType === \"string\") {\n\t\t\tif (customType === previousId && customType !== newId) {\n\t\t\t\treturn newId; // update to new api id\n\t\t\t}\n\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (customType.id == previousId && customType.id !== newId) {\n\t\t\tcustomType.id = newId; // update to new api id\n\t\t}\n\n\t\tif (customType.fields) {\n\t\t\treturn {\n\t\t\t\t...customType,\n\t\t\t\tfields: customType.fields.map((field) => {\n\t\t\t\t\tconst previousId = previousPath[1];\n\t\t\t\t\tconst newId = newPath[1];\n\n\t\t\t\t\tif (!previousId || !newId) {\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (typeof field === \"string\") {\n\t\t\t\t\t\tif (field === previousId && field !== newId) {\n\t\t\t\t\t\t\treturn newId; // update to new api id\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field.id === previousId && field.id !== newId) {\n\t\t\t\t\t\tfield.id = newId; // update to new api id\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...field,\n\t\t\t\t\t\tcustomtypes: field.customtypes.map((customType) => {\n\t\t\t\t\t\t\treturn this.updateCRCustomType({\n\t\t\t\t\t\t\t\tcustomType,\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\t// TODO: Fix types. The second level customtypes are not typed\n\t\t\t\t\t\t\t\t// the same as the first level customtypes. Although it won't\n\t\t\t\t\t\t\t\t// matter at runtime.\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- -\n\t\t\t\t\t\t\t}) as any;\n\t\t\t\t\t\t}),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t};\n\t\t}\n\n\t\treturn { ...customType };\n\t}\n\n\t/**\n\t * Map over the custom types of a Content Relationship Link and update the API\n\t * IDs that were changed during the custom type update.\n\t */\n\tprivate updateCRCustomTypes(\n\t\targs: { customTypes: CRCustomTypes } & CustomTypeFieldIdChangedMeta,\n\t): CRCustomTypes {\n\t\tconst { customTypes, ...updateMeta } = args;\n\n\t\treturn customTypes.map((customType) => {\n\t\t\treturn this.updateCRCustomType({ customType, ...updateMeta });\n\t\t});\n\t}\n\n\t/**\n\t * Update the Content Relationship API IDs that were changed during the custom\n\t * type update. The change is determined by the `previousPath` and `newPath`\n\t * properties.\n\t */\n\tprivate updateFieldContentRelationships<\n\t\tT extends UID | NestableWidget | Group | NestedGroup,\n\t>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\t\tconst { field, ...updateMeta } = args;\n\t\tif (\n\t\t\tfield.type !== \"Link\" ||\n\t\t\tfield.config?.select !== \"document\" ||\n\t\t\t!field.config?.customtypes\n\t\t) {\n\t\t\treturn field; // not a content relationship field\n\t\t}\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tconfig: {\n\t\t\t\t...field.config,\n\t\t\t\tcustomtypes: this.updateCRCustomTypes({\n\t\t\t\t\t...updateMeta,\n\t\t\t\t\tcustomTypes: field.config.customtypes.slice(),\n\t\t\t\t}),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst { model, updateMeta } = args;\n\n\t\tif (updateMeta?.fieldIdChanged) {\n\t\t\tconst crUpdatesPromises: Promise<{ errors: HookError[] }>[] = [];\n\n\t\t\tlet { previousPath, newPath } = updateMeta.fieldIdChanged;\n\n\t\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t\t// any custom type and update them to use the new one.\n\t\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\t\tfor (const customType of customTypes.models) {\n\t\t\t\t\tconst updatedCustomTypeModel = traverseCustomType({\n\t\t\t\t\t\tcustomType: customType.model,\n\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\tfield,\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\n\t\t\t\t\tcrUpdatesPromises.push(\n\t\t\t\t\t\tthis.sliceMachinePluginRunner.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\tmodel: updatedCustomTypeModel,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\t\tfor (const library of libraries) {\n\t\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tfor (const slice of slices.models) {\n\t\t\t\t\t\tconst updatedSliceModel = traverseSharedSlice({\n\t\t\t\t\t\t\tpath: [\".\"],\n\t\t\t\t\t\t\tslice: slice.model,\n\t\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\tpreviousPath,\n\t\t\t\t\t\t\t\t\tnewPath,\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\n\t\t\t\t\t\tcrUpdatesPromises.push(\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\tmodel: updatedSliceModel,\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\n\t\t\t\t// Process all the Content Relationship updates at once.\n\t\t\t\tconst crUpdatesResults = await Promise.all(crUpdatesPromises);\n\n\t\t\t\tif (crUpdatesResults.some((result) => result.errors.length > 0)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terrors: crUpdatesResults.flatMap((result) => result.errors),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: hookResult.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"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","previousId","newId","customType","traverseCustomType","traverseSharedSlice","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1BC,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,KAAKA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB,QAAAF;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/CD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,QAAAC,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IAAA,CACjC;AAEG,QAAA,CAAC,SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqBG,cAAE,OAAO;AAAA,EACnC,OAAOA,MAAE,QAAA,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAASC,YAAAA,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAMD,MAAAA,QAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAOA,MAAAA,QAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAcA,MAAAA,QAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;;"}
|
@@ -77,7 +77,7 @@ class CustomTypesManager extends BaseManager {
|
|
77
77
|
}
|
78
78
|
return customType;
|
79
79
|
}
|
80
|
-
if (customType.id
|
80
|
+
if (customType.id == previousId && customType.id !== newId) {
|
81
81
|
customType.id = newId;
|
82
82
|
}
|
83
83
|
if (customType.fields) {
|
@@ -154,6 +154,7 @@ class CustomTypesManager extends BaseManager {
|
|
154
154
|
const hookResult = await this.sliceMachinePluginRunner.callHook("custom-type:update", args);
|
155
155
|
const { model, updateMeta } = args;
|
156
156
|
if (updateMeta == null ? void 0 : updateMeta.fieldIdChanged) {
|
157
|
+
const crUpdatesPromises = [];
|
157
158
|
let { previousPath, newPath } = updateMeta.fieldIdChanged;
|
158
159
|
if (previousPath.join(".") !== newPath.join(".")) {
|
159
160
|
previousPath = [model.id, ...previousPath];
|
@@ -170,10 +171,9 @@ class CustomTypesManager extends BaseManager {
|
|
170
171
|
});
|
171
172
|
}
|
172
173
|
});
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
}
|
174
|
+
crUpdatesPromises.push(this.sliceMachinePluginRunner.callHook("custom-type:update", {
|
175
|
+
model: updatedCustomTypeModel
|
176
|
+
}));
|
177
177
|
}
|
178
178
|
const { libraries } = await this.slices.readAllSliceLibraries();
|
179
179
|
for (const library of libraries) {
|
@@ -192,12 +192,18 @@ class CustomTypesManager extends BaseManager {
|
|
192
192
|
});
|
193
193
|
}
|
194
194
|
});
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
}
|
195
|
+
crUpdatesPromises.push(this.sliceMachinePluginRunner.callHook("slice:update", {
|
196
|
+
libraryID: library.libraryID,
|
197
|
+
model: updatedSliceModel
|
198
|
+
}));
|
199
199
|
}
|
200
200
|
}
|
201
|
+
const crUpdatesResults = await Promise.all(crUpdatesPromises);
|
202
|
+
if (crUpdatesResults.some((result) => result.errors.length > 0)) {
|
203
|
+
return {
|
204
|
+
errors: crUpdatesResults.flatMap((result) => result.errors)
|
205
|
+
};
|
206
|
+
}
|
201
207
|
}
|
202
208
|
}
|
203
209
|
return { errors: hookResult.errors };
|
@@ -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\tLink,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypeUpdateMeta = {\n\tpreviousPath: string[];\n\tnewPath: string[];\n};\ntype CRCustomTypes = NonNullable<NonNullable<Link[\"config\"]>[\"customtypes\"]>;\ntype CRCustomType = NonNullable<CRCustomTypes>[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\tprivate updateCRCustomType(\n\t\targs: { customType: CRCustomType } & CustomTypeUpdateMeta,\n\t): CRCustomType {\n\t\tconst { customType: customTypeArg, previousPath, newPath } = args;\n\n\t\tlet customType = customTypeArg;\n\t\tif (typeof customTypeArg === \"object\") {\n\t\t\tcustomType = { ...customTypeArg };\n\t\t}\n\n\t\tconst [previousId] = previousPath;\n\t\tconst [newId] = newPath;\n\n\t\tif (!previousId || !newId) {\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (typeof customType === \"string\") {\n\t\t\tif (customType === previousId && customType !== newId) {\n\t\t\t\treturn newId; // update to new api id\n\t\t\t}\n\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (customType.id === previousId && customType.id !== newId) {\n\t\t\tcustomType.id = newId; // update to new api id\n\t\t}\n\n\t\tif (customType.fields) {\n\t\t\treturn {\n\t\t\t\t...customType,\n\t\t\t\tfields: customType.fields.map((field) => {\n\t\t\t\t\tconst previousId = previousPath[1];\n\t\t\t\t\tconst newId = newPath[1];\n\n\t\t\t\t\tif (!previousId || !newId) {\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (typeof field === \"string\") {\n\t\t\t\t\t\tif (field === previousId && field !== newId) {\n\t\t\t\t\t\t\treturn newId; // update to new api id\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field.id === previousId && field.id !== newId) {\n\t\t\t\t\t\tfield.id = newId; // update to new api id\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...field,\n\t\t\t\t\t\tcustomtypes: field.customtypes.map((customType) => {\n\t\t\t\t\t\t\treturn this.updateCRCustomType({\n\t\t\t\t\t\t\t\tcustomType,\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\t// TODO: Fix types. The second level customtypes are not typed\n\t\t\t\t\t\t\t\t// the same as the first level customtypes. Although it won't\n\t\t\t\t\t\t\t\t// matter at runtime.\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- -\n\t\t\t\t\t\t\t}) as any;\n\t\t\t\t\t\t}),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t};\n\t\t}\n\n\t\treturn { ...customType };\n\t}\n\n\t/**\n\t * Map over the custom types of a Content Relationship Link and update the API\n\t * IDs that were changed during the custom type update.\n\t */\n\tprivate updateCRCustomTypes(\n\t\targs: { customTypes: CRCustomTypes } & CustomTypeUpdateMeta,\n\t): CRCustomTypes {\n\t\tconst { customTypes, ...updateMeta } = args;\n\n\t\treturn customTypes.map((customType) => {\n\t\t\treturn this.updateCRCustomType({ customType, ...updateMeta });\n\t\t});\n\t}\n\n\t/**\n\t * Update the Content Relationship API IDs that were changed during the custom\n\t * type update. The change is determined by the `previousPath` and `newPath`\n\t * properties.\n\t */\n\tprivate updateFieldContentRelationships<\n\t\tT extends UID | NestableWidget | Group | NestedGroup,\n\t>(args: { field: T } & CustomTypeUpdateMeta): T {\n\t\tconst { field, ...updateMeta } = args;\n\t\tif (\n\t\t\tfield.type !== \"Link\" ||\n\t\t\tfield.config?.select !== \"document\" ||\n\t\t\t!field.config?.customtypes\n\t\t) {\n\t\t\treturn field; // not a content relationship field\n\t\t}\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tconfig: {\n\t\t\t\t...field.config,\n\t\t\t\tcustomtypes: this.updateCRCustomTypes({\n\t\t\t\t\t...updateMeta,\n\t\t\t\t\tcustomTypes: field.config.customtypes.slice(),\n\t\t\t\t}),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst { model, updateMeta } = args;\n\n\t\tif (updateMeta?.fieldIdChanged) {\n\t\t\tlet { previousPath, newPath } = updateMeta.fieldIdChanged;\n\n\t\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t\t// any custom type and update them to use the new one.\n\t\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\t\tfor (const customType of customTypes.models) {\n\t\t\t\t\tconst updatedCustomTypeModel = traverseCustomType({\n\t\t\t\t\t\tcustomType: customType.model,\n\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\tfield,\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\n\t\t\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\t\t\"custom-type:update\",\n\t\t\t\t\t\t{ model: updatedCustomTypeModel },\n\t\t\t\t\t);\n\n\t\t\t\t\tif (hookResult.errors.length > 0) {\n\t\t\t\t\t\treturn { errors: hookResult.errors };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\t\tfor (const library of libraries) {\n\t\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tfor (const slice of slices.models) {\n\t\t\t\t\t\tconst updatedSliceModel = traverseSharedSlice({\n\t\t\t\t\t\t\tpath: [\".\"],\n\t\t\t\t\t\t\tslice: slice.model,\n\t\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\tpreviousPath,\n\t\t\t\t\t\t\t\t\tnewPath,\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\n\t\t\t\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\t\t\t\"slice:update\",\n\t\t\t\t\t\t\t{ libraryID: library.libraryID, model: updatedSliceModel },\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (hookResult.errors.length > 0) {\n\t\t\t\t\t\t\treturn { errors: hookResult.errors };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: hookResult.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"],"names":["errors","previousId","newId","customType","hookResult"],"mappings":";;;;;;;;;;;AAkGM,MAAO,2BAA2B,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1B,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,OAAA,IAAW,iBACxB,EAAE,KAAK;AAAA,MACN,KAAK,EAAE,MAAM,EAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/C,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,OAAA,IAAW,MAAM,KAAK,sBAAqB;AACxD,QAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAG,MAAM;AAEtC,QAAI,KAAK;AACR,iBAAW,MAAM,KAAK;AACf,cAAA,EAAE,OAAO,QAAAA,YAAW,MAAM,KAAK,eAAe,EAAE,GAAA,CAAI;AAC1D,YAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAGA,OAAM;AAEtC,YAAI,UAAU,CAAC,QAAQ,KAAK,WAAW,MAAM,SAAS;AACrD,cAAI,OAAO,KAAK,EAAE,MAAO,CAAA;AAAA,QAC1B;AAAA,MACD;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,EAEA,MAAM,iBACL,MAA8B;AAE9B,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yB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IAAA,CACD;AAEM,WAAA,MAAM,OAAO;EACrB;AAAA,EAEA,MAAM,WAAW,EAChB,YAGA;AACA,UAAM,YAAY,MAAM,KAAK,KAAK,uBAAsB;AACxD,UAAM,UAAU;AAAA,MACf,eAAe,UAAU;AAAA,IAAA;AAG1B,UAAM,aAAa,MAAM,KAAK,QAAQ,0BAAyB;AACzD,UAAA,eAAe,IAAI,gBAAgB;AAAA,MACxC;AAAA,IAAA,CACA;AAED,UAAM,MAAM,IAAI,IAAI,kBAAkB,cAAc,iBAAiB;AACjE,QAAA,SAAS,aAAa;AAE1B,UAAM,WAAW,MAAM,MAAM,IAAI,YAAY;AAAA,MAC5C,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,UAAU;AAAA,IAAA,CACjC;AAEG,QAAA,CAAC,SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACnC,OAAO,EAAE,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAAS,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAM,EAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAO,EAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAc,EAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;"}
|
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\tLink,\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\tSliceUpdateHookReturnType,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CRCustomTypes = NonNullable<NonNullable<Link[\"config\"]>[\"customtypes\"]>;\ntype CRCustomType = NonNullable<CRCustomTypes>[number];\ntype CustomTypeFieldIdChangedMeta = NonNullable<\n\tNonNullable<CustomTypeUpdateHookData[\"updateMeta\"]>[\"fieldIdChanged\"]\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\tprivate updateCRCustomType(\n\t\targs: { customType: CRCustomType } & CustomTypeFieldIdChangedMeta,\n\t): CRCustomType {\n\t\tconst { customType: customTypeArg, previousPath, newPath } = args;\n\n\t\tlet customType = customTypeArg;\n\t\tif (typeof customTypeArg === \"object\") {\n\t\t\tcustomType = { ...customTypeArg };\n\t\t}\n\n\t\tconst [previousId] = previousPath;\n\t\tconst [newId] = newPath;\n\n\t\tif (!previousId || !newId) {\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (typeof customType === \"string\") {\n\t\t\tif (customType === previousId && customType !== newId) {\n\t\t\t\treturn newId; // update to new api id\n\t\t\t}\n\n\t\t\treturn customType;\n\t\t}\n\n\t\tif (customType.id == previousId && customType.id !== newId) {\n\t\t\tcustomType.id = newId; // update to new api id\n\t\t}\n\n\t\tif (customType.fields) {\n\t\t\treturn {\n\t\t\t\t...customType,\n\t\t\t\tfields: customType.fields.map((field) => {\n\t\t\t\t\tconst previousId = previousPath[1];\n\t\t\t\t\tconst newId = newPath[1];\n\n\t\t\t\t\tif (!previousId || !newId) {\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (typeof field === \"string\") {\n\t\t\t\t\t\tif (field === previousId && field !== newId) {\n\t\t\t\t\t\t\treturn newId; // update to new api id\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn field;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field.id === previousId && field.id !== newId) {\n\t\t\t\t\t\tfield.id = newId; // update to new api id\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...field,\n\t\t\t\t\t\tcustomtypes: field.customtypes.map((customType) => {\n\t\t\t\t\t\t\treturn this.updateCRCustomType({\n\t\t\t\t\t\t\t\tcustomType,\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\t// TODO: Fix types. The second level customtypes are not typed\n\t\t\t\t\t\t\t\t// the same as the first level customtypes. Although it won't\n\t\t\t\t\t\t\t\t// matter at runtime.\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- -\n\t\t\t\t\t\t\t}) as any;\n\t\t\t\t\t\t}),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t};\n\t\t}\n\n\t\treturn { ...customType };\n\t}\n\n\t/**\n\t * Map over the custom types of a Content Relationship Link and update the API\n\t * IDs that were changed during the custom type update.\n\t */\n\tprivate updateCRCustomTypes(\n\t\targs: { customTypes: CRCustomTypes } & CustomTypeFieldIdChangedMeta,\n\t): CRCustomTypes {\n\t\tconst { customTypes, ...updateMeta } = args;\n\n\t\treturn customTypes.map((customType) => {\n\t\t\treturn this.updateCRCustomType({ customType, ...updateMeta });\n\t\t});\n\t}\n\n\t/**\n\t * Update the Content Relationship API IDs that were changed during the custom\n\t * type update. The change is determined by the `previousPath` and `newPath`\n\t * properties.\n\t */\n\tprivate updateFieldContentRelationships<\n\t\tT extends UID | NestableWidget | Group | NestedGroup,\n\t>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\t\tconst { field, ...updateMeta } = args;\n\t\tif (\n\t\t\tfield.type !== \"Link\" ||\n\t\t\tfield.config?.select !== \"document\" ||\n\t\t\t!field.config?.customtypes\n\t\t) {\n\t\t\treturn field; // not a content relationship field\n\t\t}\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tconfig: {\n\t\t\t\t...field.config,\n\t\t\t\tcustomtypes: this.updateCRCustomTypes({\n\t\t\t\t\t...updateMeta,\n\t\t\t\t\tcustomTypes: field.config.customtypes.slice(),\n\t\t\t\t}),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst { model, updateMeta } = args;\n\n\t\tif (updateMeta?.fieldIdChanged) {\n\t\t\tconst crUpdatesPromises: Promise<{ errors: HookError[] }>[] = [];\n\n\t\t\tlet { previousPath, newPath } = updateMeta.fieldIdChanged;\n\n\t\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t\t// any custom type and update them to use the new one.\n\t\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\t\tfor (const customType of customTypes.models) {\n\t\t\t\t\tconst updatedCustomTypeModel = traverseCustomType({\n\t\t\t\t\t\tcustomType: customType.model,\n\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\tfield,\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\n\t\t\t\t\tcrUpdatesPromises.push(\n\t\t\t\t\t\tthis.sliceMachinePluginRunner.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\tmodel: updatedCustomTypeModel,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\t\tfor (const library of libraries) {\n\t\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tfor (const slice of slices.models) {\n\t\t\t\t\t\tconst updatedSliceModel = traverseSharedSlice({\n\t\t\t\t\t\t\tpath: [\".\"],\n\t\t\t\t\t\t\tslice: slice.model,\n\t\t\t\t\t\t\tonField: ({ field }) => {\n\t\t\t\t\t\t\t\treturn this.updateFieldContentRelationships({\n\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\tpreviousPath,\n\t\t\t\t\t\t\t\t\tnewPath,\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\n\t\t\t\t\t\tcrUpdatesPromises.push(\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\tmodel: updatedSliceModel,\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\n\t\t\t\t// Process all the Content Relationship updates at once.\n\t\t\t\tconst crUpdatesResults = await Promise.all(crUpdatesPromises);\n\n\t\t\t\tif (crUpdatesResults.some((result) => result.errors.length > 0)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terrors: crUpdatesResults.flatMap((result) => result.errors),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: hookResult.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"],"names":["errors","previousId","newId","customType"],"mappings":";;;;;;;;;;;AAiGM,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;AAEt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SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACnC,OAAO,EAAE,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAAS,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAM,EAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAO,EAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAc,EAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@slicemachine/manager",
|
3
|
-
"version": "0.24.14-alpha.jp-update-cr-links.
|
3
|
+
"version": "0.24.14-alpha.jp-update-cr-links.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.10.0-alpha.0",
|
72
72
|
"@segment/analytics-node": "^2.1.2",
|
73
|
-
"@slicemachine/plugin-kit": "0.4.76-alpha.jp-update-cr-links.
|
73
|
+
"@slicemachine/plugin-kit": "0.4.76-alpha.jp-update-cr-links.3",
|
74
74
|
"cookie": "^1.0.1",
|
75
75
|
"cors": "^2.8.5",
|
76
76
|
"execa": "^7.1.1",
|
@@ -20,6 +20,7 @@ import {
|
|
20
20
|
CustomTypeRenameHookData,
|
21
21
|
CustomTypeUpdateHook,
|
22
22
|
CustomTypeUpdateHookData,
|
23
|
+
SliceUpdateHookReturnType,
|
23
24
|
HookError,
|
24
25
|
} from "@slicemachine/plugin-kit";
|
25
26
|
import { z } from "zod";
|
@@ -89,13 +90,11 @@ type CustomTypesMachineManagerDeleteCustomTypeReturnType = {
|
|
89
90
|
errors: (DecodeError | HookError)[];
|
90
91
|
};
|
91
92
|
|
92
|
-
type CustomTypeUpdateMeta = {
|
93
|
-
previousPath: string[];
|
94
|
-
newPath: string[];
|
95
|
-
};
|
96
93
|
type CRCustomTypes = NonNullable<NonNullable<Link["config"]>["customtypes"]>;
|
97
94
|
type CRCustomType = NonNullable<CRCustomTypes>[number];
|
98
|
-
|
95
|
+
type CustomTypeFieldIdChangedMeta = NonNullable<
|
96
|
+
NonNullable<CustomTypeUpdateHookData["updateMeta"]>["fieldIdChanged"]
|
97
|
+
>;
|
99
98
|
export class CustomTypesManager extends BaseManager {
|
100
99
|
async readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {
|
101
100
|
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
@@ -182,7 +181,7 @@ export class CustomTypesManager extends BaseManager {
|
|
182
181
|
}
|
183
182
|
|
184
183
|
private updateCRCustomType(
|
185
|
-
args: { customType: CRCustomType } &
|
184
|
+
args: { customType: CRCustomType } & CustomTypeFieldIdChangedMeta,
|
186
185
|
): CRCustomType {
|
187
186
|
const { customType: customTypeArg, previousPath, newPath } = args;
|
188
187
|
|
@@ -206,7 +205,7 @@ export class CustomTypesManager extends BaseManager {
|
|
206
205
|
return customType;
|
207
206
|
}
|
208
207
|
|
209
|
-
if (customType.id
|
208
|
+
if (customType.id == previousId && customType.id !== newId) {
|
210
209
|
customType.id = newId; // update to new api id
|
211
210
|
}
|
212
211
|
|
@@ -259,7 +258,7 @@ export class CustomTypesManager extends BaseManager {
|
|
259
258
|
* IDs that were changed during the custom type update.
|
260
259
|
*/
|
261
260
|
private updateCRCustomTypes(
|
262
|
-
args: { customTypes: CRCustomTypes } &
|
261
|
+
args: { customTypes: CRCustomTypes } & CustomTypeFieldIdChangedMeta,
|
263
262
|
): CRCustomTypes {
|
264
263
|
const { customTypes, ...updateMeta } = args;
|
265
264
|
|
@@ -275,7 +274,7 @@ export class CustomTypesManager extends BaseManager {
|
|
275
274
|
*/
|
276
275
|
private updateFieldContentRelationships<
|
277
276
|
T extends UID | NestableWidget | Group | NestedGroup,
|
278
|
-
>(args: { field: T } &
|
277
|
+
>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {
|
279
278
|
const { field, ...updateMeta } = args;
|
280
279
|
if (
|
281
280
|
field.type !== "Link" ||
|
@@ -310,6 +309,8 @@ export class CustomTypesManager extends BaseManager {
|
|
310
309
|
const { model, updateMeta } = args;
|
311
310
|
|
312
311
|
if (updateMeta?.fieldIdChanged) {
|
312
|
+
const crUpdatesPromises: Promise<{ errors: HookError[] }>[] = [];
|
313
|
+
|
313
314
|
let { previousPath, newPath } = updateMeta.fieldIdChanged;
|
314
315
|
|
315
316
|
if (previousPath.join(".") !== newPath.join(".")) {
|
@@ -332,14 +333,11 @@ export class CustomTypesManager extends BaseManager {
|
|
332
333
|
},
|
333
334
|
});
|
334
335
|
|
335
|
-
|
336
|
-
"custom-type:update",
|
337
|
-
|
336
|
+
crUpdatesPromises.push(
|
337
|
+
this.sliceMachinePluginRunner.callHook("custom-type:update", {
|
338
|
+
model: updatedCustomTypeModel,
|
339
|
+
}),
|
338
340
|
);
|
339
|
-
|
340
|
-
if (hookResult.errors.length > 0) {
|
341
|
-
return { errors: hookResult.errors };
|
342
|
-
}
|
343
341
|
}
|
344
342
|
|
345
343
|
// Find existing slice with content relationships that link to the renamed
|
@@ -364,16 +362,23 @@ export class CustomTypesManager extends BaseManager {
|
|
364
362
|
},
|
365
363
|
});
|
366
364
|
|
367
|
-
|
368
|
-
"slice:update",
|
369
|
-
|
365
|
+
crUpdatesPromises.push(
|
366
|
+
this.sliceMachinePluginRunner.callHook("slice:update", {
|
367
|
+
libraryID: library.libraryID,
|
368
|
+
model: updatedSliceModel,
|
369
|
+
}),
|
370
370
|
);
|
371
|
-
|
372
|
-
if (hookResult.errors.length > 0) {
|
373
|
-
return { errors: hookResult.errors };
|
374
|
-
}
|
375
371
|
}
|
376
372
|
}
|
373
|
+
|
374
|
+
// Process all the Content Relationship updates at once.
|
375
|
+
const crUpdatesResults = await Promise.all(crUpdatesPromises);
|
376
|
+
|
377
|
+
if (crUpdatesResults.some((result) => result.errors.length > 0)) {
|
378
|
+
return {
|
379
|
+
errors: crUpdatesResults.flatMap((result) => result.errors),
|
380
|
+
};
|
381
|
+
}
|
377
382
|
}
|
378
383
|
}
|
379
384
|
|