@slicemachine/manager 0.10.1-dev-slices-templates-feature.2 → 0.10.1-dev-next-release.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/managers/BaseManager.cjs +0 -3
- package/dist/managers/BaseManager.cjs.map +1 -1
- package/dist/managers/BaseManager.d.ts +0 -2
- package/dist/managers/BaseManager.js +0 -3
- package/dist/managers/BaseManager.js.map +1 -1
- package/dist/managers/SliceMachineManager.cjs +0 -3
- package/dist/managers/SliceMachineManager.cjs.map +1 -1
- package/dist/managers/SliceMachineManager.d.ts +0 -2
- package/dist/managers/SliceMachineManager.js +0 -3
- package/dist/managers/SliceMachineManager.js.map +1 -1
- package/dist/managers/createSliceMachineManagerMiddleware.cjs +0 -1
- package/dist/managers/createSliceMachineManagerMiddleware.cjs.map +1 -1
- package/dist/managers/createSliceMachineManagerMiddleware.js +0 -1
- package/dist/managers/createSliceMachineManagerMiddleware.js.map +1 -1
- package/dist/managers/telemetry/types.cjs.map +1 -1
- package/dist/managers/telemetry/types.d.ts +0 -1
- package/dist/managers/telemetry/types.js.map +1 -1
- package/package.json +6 -3
- package/src/managers/BaseManager.ts +0 -4
- package/src/managers/SliceMachineManager.ts +0 -3
- package/src/managers/createSliceMachineManagerMiddleware.ts +0 -1
- package/src/managers/telemetry/types.ts +1 -1
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.cjs +0 -138
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.cjs.map +0 -1
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.d.ts +0 -27
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.js +0 -121
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.js.map +0 -1
- package/src/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.ts +0 -195
|
@@ -55,9 +55,6 @@ class BaseManager {
|
|
|
55
55
|
get documentation() {
|
|
56
56
|
return this._sliceMachineManager.documentation;
|
|
57
57
|
}
|
|
58
|
-
get sliceTemplateLibrary() {
|
|
59
|
-
return this._sliceMachineManager.sliceTemplateLibrary;
|
|
60
|
-
}
|
|
61
58
|
get versions() {
|
|
62
59
|
return this._sliceMachineManager.versions;
|
|
63
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseManager.cjs","sources":["../../../src/managers/BaseManager.ts"],"sourcesContent":["import { SliceMachinePluginRunner } from \"@slicemachine/plugin-kit\";\nimport { PrismicAuthManager } from \"../auth/PrismicAuthManager\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\
|
|
1
|
+
{"version":3,"file":"BaseManager.cjs","sources":["../../../src/managers/BaseManager.ts"],"sourcesContent":["import { SliceMachinePluginRunner } from \"@slicemachine/plugin-kit\";\nimport { PrismicAuthManager } from \"../auth/PrismicAuthManager\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\n\nexport abstract class BaseManager {\n\tprivate _sliceMachineManager: SliceMachineManager;\n\n\tconstructor(sliceMachineManager: SliceMachineManager) {\n\t\tthis._sliceMachineManager = sliceMachineManager;\n\t}\n\n\tprotected get prismicAuthManager(): PrismicAuthManager {\n\t\treturn this._sliceMachineManager.getPrismicAuthManager();\n\t}\n\n\tprotected get sliceMachinePluginRunner():\n\t\t| SliceMachinePluginRunner\n\t\t| undefined {\n\t\treturn this._sliceMachineManager.getSliceMachinePluginRunner();\n\t}\n\n\tprotected set sliceMachinePluginRunner(\n\t\tsliceMachinePluginRunner: SliceMachinePluginRunner | undefined,\n\t) {\n\t\t// @ts-expect-error - _sliceMachinePluginRunner is private. We\n\t\t// are intentially ignoring its privacy to allow Manager\n\t\t// classes to access a shared plugin runner via protected\n\t\t// getters and setters.\n\t\tthis._sliceMachineManager._sliceMachinePluginRunner =\n\t\t\tsliceMachinePluginRunner;\n\t}\n\n\tprotected get cwd(): string {\n\t\treturn this._sliceMachineManager.cwd;\n\t}\n\n\t// Protected instance prevents circular intellisense\n\t// e.g. sliceMachineManager.user.user.user\n\tprotected get user(): UserManager {\n\t\treturn this._sliceMachineManager.user;\n\t}\n\tprotected get prismicRepository(): PrismicRepositoryManager {\n\t\treturn this._sliceMachineManager.prismicRepository;\n\t}\n\n\tprotected get plugins(): PluginsManager {\n\t\treturn this._sliceMachineManager.plugins;\n\t}\n\n\tprotected get project(): ProjectManager {\n\t\treturn this._sliceMachineManager.project;\n\t}\n\tprotected get customTypes(): CustomTypesManager {\n\t\treturn this._sliceMachineManager.customTypes;\n\t}\n\tprotected get slices(): SlicesManager {\n\t\treturn this._sliceMachineManager.slices;\n\t}\n\tprotected get snippets(): SnippetsManager {\n\t\treturn this._sliceMachineManager.snippets;\n\t}\n\tprotected get screenshots(): ScreenshotsManager {\n\t\treturn this._sliceMachineManager.screenshots;\n\t}\n\tprotected get simulator(): SimulatorManager {\n\t\treturn this._sliceMachineManager.simulator;\n\t}\n\tprotected get documentation(): DocumentationManager {\n\t\treturn this._sliceMachineManager.documentation;\n\t}\n\n\tprotected get versions(): VersionsManager {\n\t\treturn this._sliceMachineManager.versions;\n\t}\n\n\tprotected get telemetry(): TelemetryManager {\n\t\treturn this._sliceMachineManager.telemetry;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;MAqBsB,YAAW;AAAA,EAGhC,YAAY,qBAAwC;AAF5C;AAGP,SAAK,uBAAuB;AAAA,EAC7B;AAAA,EAEA,IAAc,qBAAkB;AACxB,WAAA,KAAK,qBAAqB;EAClC;AAAA,EAEA,IAAc,2BAAwB;AAG9B,WAAA,KAAK,qBAAqB;EAClC;AAAA,EAEA,IAAc,yBACb,0BAA8D;AAM9D,SAAK,qBAAqB,4BACzB;AAAA,EACF;AAAA,EAEA,IAAc,MAAG;AAChB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA;AAAA;AAAA,EAIA,IAAc,OAAI;AACjB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,oBAAiB;AAC9B,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,UAAO;AACpB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,UAAO;AACpB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,cAAW;AACxB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,SAAM;AACnB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,WAAQ;AACrB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,cAAW;AACxB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,YAAS;AACtB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,gBAAa;AAC1B,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,WAAQ;AACrB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,YAAS;AACtB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AACA;;"}
|
|
@@ -13,7 +13,6 @@ import { SimulatorManager } from "./simulator/SimulatorManager";
|
|
|
13
13
|
import { VersionsManager } from "./versions/VersionsManager";
|
|
14
14
|
import { TelemetryManager } from "./telemetry/TelemetryManager";
|
|
15
15
|
import { DocumentationManager } from "./documentation/DocumentationManager";
|
|
16
|
-
import { SliceTemplateLibraryManager } from "./sliceTemplateLibrary/SliceTemplateLibraryManager";
|
|
17
16
|
export declare abstract class BaseManager {
|
|
18
17
|
private _sliceMachineManager;
|
|
19
18
|
constructor(sliceMachineManager: SliceMachineManager);
|
|
@@ -31,7 +30,6 @@ export declare abstract class BaseManager {
|
|
|
31
30
|
protected get screenshots(): ScreenshotsManager;
|
|
32
31
|
protected get simulator(): SimulatorManager;
|
|
33
32
|
protected get documentation(): DocumentationManager;
|
|
34
|
-
protected get sliceTemplateLibrary(): SliceTemplateLibraryManager;
|
|
35
33
|
protected get versions(): VersionsManager;
|
|
36
34
|
protected get telemetry(): TelemetryManager;
|
|
37
35
|
}
|
|
@@ -53,9 +53,6 @@ class BaseManager {
|
|
|
53
53
|
get documentation() {
|
|
54
54
|
return this._sliceMachineManager.documentation;
|
|
55
55
|
}
|
|
56
|
-
get sliceTemplateLibrary() {
|
|
57
|
-
return this._sliceMachineManager.sliceTemplateLibrary;
|
|
58
|
-
}
|
|
59
56
|
get versions() {
|
|
60
57
|
return this._sliceMachineManager.versions;
|
|
61
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseManager.js","sources":["../../../src/managers/BaseManager.ts"],"sourcesContent":["import { SliceMachinePluginRunner } from \"@slicemachine/plugin-kit\";\nimport { PrismicAuthManager } from \"../auth/PrismicAuthManager\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\
|
|
1
|
+
{"version":3,"file":"BaseManager.js","sources":["../../../src/managers/BaseManager.ts"],"sourcesContent":["import { SliceMachinePluginRunner } from \"@slicemachine/plugin-kit\";\nimport { PrismicAuthManager } from \"../auth/PrismicAuthManager\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\n\nexport abstract class BaseManager {\n\tprivate _sliceMachineManager: SliceMachineManager;\n\n\tconstructor(sliceMachineManager: SliceMachineManager) {\n\t\tthis._sliceMachineManager = sliceMachineManager;\n\t}\n\n\tprotected get prismicAuthManager(): PrismicAuthManager {\n\t\treturn this._sliceMachineManager.getPrismicAuthManager();\n\t}\n\n\tprotected get sliceMachinePluginRunner():\n\t\t| SliceMachinePluginRunner\n\t\t| undefined {\n\t\treturn this._sliceMachineManager.getSliceMachinePluginRunner();\n\t}\n\n\tprotected set sliceMachinePluginRunner(\n\t\tsliceMachinePluginRunner: SliceMachinePluginRunner | undefined,\n\t) {\n\t\t// @ts-expect-error - _sliceMachinePluginRunner is private. We\n\t\t// are intentially ignoring its privacy to allow Manager\n\t\t// classes to access a shared plugin runner via protected\n\t\t// getters and setters.\n\t\tthis._sliceMachineManager._sliceMachinePluginRunner =\n\t\t\tsliceMachinePluginRunner;\n\t}\n\n\tprotected get cwd(): string {\n\t\treturn this._sliceMachineManager.cwd;\n\t}\n\n\t// Protected instance prevents circular intellisense\n\t// e.g. sliceMachineManager.user.user.user\n\tprotected get user(): UserManager {\n\t\treturn this._sliceMachineManager.user;\n\t}\n\tprotected get prismicRepository(): PrismicRepositoryManager {\n\t\treturn this._sliceMachineManager.prismicRepository;\n\t}\n\n\tprotected get plugins(): PluginsManager {\n\t\treturn this._sliceMachineManager.plugins;\n\t}\n\n\tprotected get project(): ProjectManager {\n\t\treturn this._sliceMachineManager.project;\n\t}\n\tprotected get customTypes(): CustomTypesManager {\n\t\treturn this._sliceMachineManager.customTypes;\n\t}\n\tprotected get slices(): SlicesManager {\n\t\treturn this._sliceMachineManager.slices;\n\t}\n\tprotected get snippets(): SnippetsManager {\n\t\treturn this._sliceMachineManager.snippets;\n\t}\n\tprotected get screenshots(): ScreenshotsManager {\n\t\treturn this._sliceMachineManager.screenshots;\n\t}\n\tprotected get simulator(): SimulatorManager {\n\t\treturn this._sliceMachineManager.simulator;\n\t}\n\tprotected get documentation(): DocumentationManager {\n\t\treturn this._sliceMachineManager.documentation;\n\t}\n\n\tprotected get versions(): VersionsManager {\n\t\treturn this._sliceMachineManager.versions;\n\t}\n\n\tprotected get telemetry(): TelemetryManager {\n\t\treturn this._sliceMachineManager.telemetry;\n\t}\n}\n"],"names":[],"mappings":";;;;;;MAqBsB,YAAW;AAAA,EAGhC,YAAY,qBAAwC;AAF5C;AAGP,SAAK,uBAAuB;AAAA,EAC7B;AAAA,EAEA,IAAc,qBAAkB;AACxB,WAAA,KAAK,qBAAqB;EAClC;AAAA,EAEA,IAAc,2BAAwB;AAG9B,WAAA,KAAK,qBAAqB;EAClC;AAAA,EAEA,IAAc,yBACb,0BAA8D;AAM9D,SAAK,qBAAqB,4BACzB;AAAA,EACF;AAAA,EAEA,IAAc,MAAG;AAChB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA;AAAA;AAAA,EAIA,IAAc,OAAI;AACjB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,oBAAiB;AAC9B,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,UAAO;AACpB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,UAAO;AACpB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,cAAW;AACxB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,SAAM;AACnB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,WAAQ;AACrB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,cAAW;AACxB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,YAAS;AACtB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EACA,IAAc,gBAAa;AAC1B,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,WAAQ;AACrB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AAAA,EAEA,IAAc,YAAS;AACtB,WAAO,KAAK,qBAAqB;AAAA,EAClC;AACA;"}
|
|
@@ -23,7 +23,6 @@ const VersionsManager = require("./versions/VersionsManager.cjs");
|
|
|
23
23
|
const TelemetryManager = require("./telemetry/TelemetryManager.cjs");
|
|
24
24
|
const buildPrismicRepositoryAPIEndpoint = require("../lib/buildPrismicRepositoryAPIEndpoint.cjs");
|
|
25
25
|
const DocumentationManager = require("./documentation/DocumentationManager.cjs");
|
|
26
|
-
const SliceTemplateLibraryManager = require("./sliceTemplateLibrary/SliceTemplateLibraryManager.cjs");
|
|
27
26
|
class SliceMachineManager {
|
|
28
27
|
constructor(args) {
|
|
29
28
|
__publicField(this, "_sliceMachinePluginRunner");
|
|
@@ -38,7 +37,6 @@ class SliceMachineManager {
|
|
|
38
37
|
__publicField(this, "slices");
|
|
39
38
|
__publicField(this, "snippets");
|
|
40
39
|
__publicField(this, "documentation");
|
|
41
|
-
__publicField(this, "sliceTemplateLibrary");
|
|
42
40
|
__publicField(this, "telemetry");
|
|
43
41
|
__publicField(this, "user");
|
|
44
42
|
__publicField(this, "versions");
|
|
@@ -55,7 +53,6 @@ class SliceMachineManager {
|
|
|
55
53
|
this.screenshots = new ScreenshotsManager.ScreenshotsManager(this);
|
|
56
54
|
this.simulator = new SimulatorManager.SimulatorManager(this);
|
|
57
55
|
this.documentation = new DocumentationManager.DocumentationManager(this);
|
|
58
|
-
this.sliceTemplateLibrary = new SliceTemplateLibraryManager.SliceTemplateLibraryManager(this);
|
|
59
56
|
this.versions = new VersionsManager.VersionsManager(this);
|
|
60
57
|
this.telemetry = new TelemetryManager.TelemetryManager(this);
|
|
61
58
|
this.cwd = (args == null ? void 0 : args.cwd) ?? process.cwd();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceMachineManager.cjs","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tForbiddenError,\n\tUnauthorizedError,\n} from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\nimport { SliceTemplateLibraryManager } from \"./sliceTemplateLibrary/SliceTemplateLibraryManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tsupportsSliceSimulator: boolean;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\tsliceTemplateLibrary: SliceTemplateLibraryManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\t\tthis.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Non-Prismic error\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof UnauthorizedError ||\n\t\t\t\t\t\t\terror instanceof ForbiddenError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\tsupportsSliceSimulator: this.simulator.supportsSliceSimulator(),\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\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\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["createPrismicAuthManager","UserManager","PrismicRepositoryManager","PluginsManager","ProjectManager","CustomTypesManager","SlicesManager","SnippetsManager","ScreenshotsManager","SimulatorManager","DocumentationManager","SliceTemplateLibraryManager","VersionsManager","TelemetryManager","API_ENDPOINTS","sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices","UnauthorizedError","ForbiddenError","buildPrismicRepositoryAPIEndpoint","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;MAqGa,oBAAmB;AAAA,EAqB/B,YAAY,MAAyC;AApB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsBA,yBAAAA;AAEtB,SAAA,OAAO,IAAIC,YAAA,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAIC,yBAAA,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAIC,eAAA,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAIC,eAAA,eAAe,IAAI;AACjC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAIC,cAAA,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AACnC,SAAA,cAAc,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AY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;;"}
|
|
1
|
+
{"version":3,"file":"SliceMachineManager.cjs","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tForbiddenError,\n\tUnauthorizedError,\n} from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tsupportsSliceSimulator: boolean;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Non-Prismic error\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof UnauthorizedError ||\n\t\t\t\t\t\t\terror instanceof ForbiddenError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\tsupportsSliceSimulator: this.simulator.supportsSliceSimulator(),\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\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\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["createPrismicAuthManager","UserManager","PrismicRepositoryManager","PluginsManager","ProjectManager","CustomTypesManager","SlicesManager","SnippetsManager","ScreenshotsManager","SimulatorManager","DocumentationManager","VersionsManager","TelemetryManager","API_ENDPOINTS","sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices","UnauthorizedError","ForbiddenError","buildPrismicRepositoryAPIEndpoint","createContentDigest"],"mappings":";;;;;;;;;;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AAA,CAAC;AAGH,yBAAW,KAAK;AAAA,gBACf,MAAM;AAAA,gBACN,MAAM,UAAU,QAAQ,OAAO,IAAI;AAAA,gBACnC,aAAa;AAAA,gBACb,UAAU;AAAA,gBACV,WAAW;AAAA,gBACX;AAAA,gBACA;AAAA,gBACA;AAAA,cAAA,CACA;AAAA,YACD;AAAA,UACD,CAAA,CAAC;AAGH,oBAAU,KAAK;AAAA,YACd,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,YACT;AAAA,YACA,MAAM;AAAA;AAAA,cAEL,cAAc;AAAA,cACd,cAAc;AAAA,cACd,UAAU;AAAA,YACV;AAAA,UAAA,CACD;AAAA,QACD;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAGD,WAAO,UAAU,KAAK,CAAC,UAAU,aAAY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;;"}
|
|
@@ -17,7 +17,6 @@ import { SimulatorManager } from "./simulator/SimulatorManager";
|
|
|
17
17
|
import { VersionsManager } from "./versions/VersionsManager";
|
|
18
18
|
import { TelemetryManager } from "./telemetry/TelemetryManager";
|
|
19
19
|
import { DocumentationManager } from "./documentation/DocumentationManager";
|
|
20
|
-
import { SliceTemplateLibraryManager } from "./sliceTemplateLibrary/SliceTemplateLibraryManager";
|
|
21
20
|
type SliceMachineManagerGetStateReturnType = {
|
|
22
21
|
env: {
|
|
23
22
|
shortId?: string;
|
|
@@ -83,7 +82,6 @@ export declare class SliceMachineManager {
|
|
|
83
82
|
slices: SlicesManager;
|
|
84
83
|
snippets: SnippetsManager;
|
|
85
84
|
documentation: DocumentationManager;
|
|
86
|
-
sliceTemplateLibrary: SliceTemplateLibraryManager;
|
|
87
85
|
telemetry: TelemetryManager;
|
|
88
86
|
user: UserManager;
|
|
89
87
|
versions: VersionsManager;
|
|
@@ -21,7 +21,6 @@ import { VersionsManager } from "./versions/VersionsManager.js";
|
|
|
21
21
|
import { TelemetryManager } from "./telemetry/TelemetryManager.js";
|
|
22
22
|
import { buildPrismicRepositoryAPIEndpoint } from "../lib/buildPrismicRepositoryAPIEndpoint.js";
|
|
23
23
|
import { DocumentationManager } from "./documentation/DocumentationManager.js";
|
|
24
|
-
import { SliceTemplateLibraryManager } from "./sliceTemplateLibrary/SliceTemplateLibraryManager.js";
|
|
25
24
|
class SliceMachineManager {
|
|
26
25
|
constructor(args) {
|
|
27
26
|
__publicField(this, "_sliceMachinePluginRunner");
|
|
@@ -36,7 +35,6 @@ class SliceMachineManager {
|
|
|
36
35
|
__publicField(this, "slices");
|
|
37
36
|
__publicField(this, "snippets");
|
|
38
37
|
__publicField(this, "documentation");
|
|
39
|
-
__publicField(this, "sliceTemplateLibrary");
|
|
40
38
|
__publicField(this, "telemetry");
|
|
41
39
|
__publicField(this, "user");
|
|
42
40
|
__publicField(this, "versions");
|
|
@@ -53,7 +51,6 @@ class SliceMachineManager {
|
|
|
53
51
|
this.screenshots = new ScreenshotsManager(this);
|
|
54
52
|
this.simulator = new SimulatorManager(this);
|
|
55
53
|
this.documentation = new DocumentationManager(this);
|
|
56
|
-
this.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);
|
|
57
54
|
this.versions = new VersionsManager(this);
|
|
58
55
|
this.telemetry = new TelemetryManager(this);
|
|
59
56
|
this.cwd = (args == null ? void 0 : args.cwd) ?? process.cwd();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceMachineManager.js","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tForbiddenError,\n\tUnauthorizedError,\n} from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\nimport { SliceTemplateLibraryManager } from \"./sliceTemplateLibrary/SliceTemplateLibraryManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tsupportsSliceSimulator: boolean;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\tsliceTemplateLibrary: SliceTemplateLibraryManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\t\tthis.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Non-Prismic error\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof UnauthorizedError ||\n\t\t\t\t\t\t\terror instanceof ForbiddenError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\tsupportsSliceSimulator: this.simulator.supportsSliceSimulator(),\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\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\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;MAqGa,oBAAmB;AAAA,EAqB/B,YAAY,MAAyC;AApB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsB;AAEtB,SAAA,OAAO,IAAI,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAI,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAI,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAI,eAAe,IAAI;AACjC,SAAA,cAAc,IAAI,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAI,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAI,gBAAgB,IAAI;AACnC,SAAA,cAAc,IAA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BACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;"}
|
|
1
|
+
{"version":3,"file":"SliceMachineManager.js","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tForbiddenError,\n\tUnauthorizedError,\n} from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tsupportsSliceSimulator: boolean;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Non-Prismic error\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof UnauthorizedError ||\n\t\t\t\t\t\t\terror instanceof ForbiddenError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\tsupportsSliceSimulator: this.simulator.supportsSliceSimulator(),\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\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\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;MAoGa,oBAAmB;AAAA,EAoB/B,YAAY,MAAyC;AAnB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsB;AAEtB,SAAA,OAAO,IAAI,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAI,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAI,eAAe,MAAM;AAAA,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D;AAAA,QACD;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAGD,WAAO,UAAU,KAAK,CAAC,UAAU,aAAY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;"}
|
|
@@ -22,7 +22,6 @@ const omitProcedures = defineOmits()([
|
|
|
22
22
|
"user._sliceMachineManager",
|
|
23
23
|
"versions._sliceMachineManager",
|
|
24
24
|
"documentation._sliceMachineManager",
|
|
25
|
-
"sliceTemplateLibrary._sliceMachineManager",
|
|
26
25
|
"getSliceMachinePluginRunner",
|
|
27
26
|
"getPrismicAuthManager",
|
|
28
27
|
"screenshots.browserContext"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSliceMachineManagerMiddleware.cjs","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"
|
|
1
|
+
{"version":3,"file":"createSliceMachineManagerMiddleware.cjs","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"getSliceMachinePluginRunner\",\n\t\"getPrismicAuthManager\",\n\t\"screenshots.browserContext\",\n]);\n\nexport type SliceMachineManagerMiddleware = RPCMiddleware<\n\tProceduresFromInstance<SliceMachineManager, (typeof omitProcedures)[number]>\n>;\n\nexport type SliceMachineManagerProcedures =\n\tExtractProcedures<SliceMachineManagerMiddleware>;\n\ntype GetSliceMachineManagerProceduresArgs = {\n\tsliceMachineManager: SliceMachineManager;\n};\n\nexport const getSliceMachineManagerProcedures = (\n\targs: GetSliceMachineManagerProceduresArgs,\n): SliceMachineManagerProcedures => {\n\treturn proceduresFromInstance(args.sliceMachineManager, {\n\t\tomit: omitProcedures,\n\t});\n};\n\nexport type CreateSliceMachineManagerMiddlewareArgs = {\n\tsliceMachineManager: SliceMachineManager;\n\tonError?: OnErrorEventHandler;\n};\n\nexport const createSliceMachineManagerMiddleware = (\n\targs: CreateSliceMachineManagerMiddlewareArgs,\n): SliceMachineManagerMiddleware => {\n\treturn createRPCMiddleware({\n\t\tprocedures: getSliceMachineManagerProcedures({\n\t\t\tsliceMachineManager: args.sliceMachineManager,\n\t\t}),\n\t\tonError: args.onError,\n\t});\n};\n"],"names":["proceduresFromInstance","createRPCMiddleware"],"mappings":";;;;AAYA,MAAM,cAAc,MAAW;AAG9B,SAAO,CACN,SAC8D;AACvD,WAAA;AAAA,EAAA;AAET;AAGA,MAAM,iBAAiB,cAAmC;AAAA,EACzD;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACA,CAAA;AAaY,MAAA,mCAAmC,CAC/C,SACkC;AAC3B,SAAAA,uBAAA,uBAAuB,KAAK,qBAAqB;AAAA,IACvD,MAAM;AAAA,EAAA,CACN;AACF;AAOa,MAAA,sCAAsC,CAClD,SACkC;AAClC,SAAOC,wCAAoB;AAAA,IAC1B,YAAY,iCAAiC;AAAA,MAC5C,qBAAqB,KAAK;AAAA,IAAA,CAC1B;AAAA,IACD,SAAS,KAAK;AAAA,EAAA,CACd;AACF;;;"}
|
|
@@ -20,7 +20,6 @@ const omitProcedures = defineOmits()([
|
|
|
20
20
|
"user._sliceMachineManager",
|
|
21
21
|
"versions._sliceMachineManager",
|
|
22
22
|
"documentation._sliceMachineManager",
|
|
23
|
-
"sliceTemplateLibrary._sliceMachineManager",
|
|
24
23
|
"getSliceMachinePluginRunner",
|
|
25
24
|
"getPrismicAuthManager",
|
|
26
25
|
"screenshots.browserContext"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSliceMachineManagerMiddleware.js","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"
|
|
1
|
+
{"version":3,"file":"createSliceMachineManagerMiddleware.js","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"getSliceMachinePluginRunner\",\n\t\"getPrismicAuthManager\",\n\t\"screenshots.browserContext\",\n]);\n\nexport type SliceMachineManagerMiddleware = RPCMiddleware<\n\tProceduresFromInstance<SliceMachineManager, (typeof omitProcedures)[number]>\n>;\n\nexport type SliceMachineManagerProcedures =\n\tExtractProcedures<SliceMachineManagerMiddleware>;\n\ntype GetSliceMachineManagerProceduresArgs = {\n\tsliceMachineManager: SliceMachineManager;\n};\n\nexport const getSliceMachineManagerProcedures = (\n\targs: GetSliceMachineManagerProceduresArgs,\n): SliceMachineManagerProcedures => {\n\treturn proceduresFromInstance(args.sliceMachineManager, {\n\t\tomit: omitProcedures,\n\t});\n};\n\nexport type CreateSliceMachineManagerMiddlewareArgs = {\n\tsliceMachineManager: SliceMachineManager;\n\tonError?: OnErrorEventHandler;\n};\n\nexport const createSliceMachineManagerMiddleware = (\n\targs: CreateSliceMachineManagerMiddlewareArgs,\n): SliceMachineManagerMiddleware => {\n\treturn createRPCMiddleware({\n\t\tprocedures: getSliceMachineManagerProcedures({\n\t\t\tsliceMachineManager: args.sliceMachineManager,\n\t\t}),\n\t\tonError: args.onError,\n\t});\n};\n"],"names":[],"mappings":";;AAYA,MAAM,cAAc,MAAW;AAG9B,SAAO,CACN,SAC8D;AACvD,WAAA;AAAA,EAAA;AAET;AAGA,MAAM,iBAAiB,cAAmC;AAAA,EACzD;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACA,CAAA;AAaY,MAAA,mCAAmC,CAC/C,SACkC;AAC3B,SAAA,uBAAuB,KAAK,qBAAqB;AAAA,IACvD,MAAM;AAAA,EAAA,CACN;AACF;AAOa,MAAA,sCAAsC,CAClD,SACkC;AAClC,SAAO,oBAAoB;AAAA,IAC1B,YAAY,iCAAiC;AAAA,MAC5C,qBAAqB,KAAK;AAAA,IAAA,CAC1B;AAAA,IACD,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{ rating: number; comment: string }\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{ rating: number; comment: string }\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string }\n>;\n\ntype ScreenshotTakenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.screenshotTaken,\n\t{\n\t\ttype: \"custom\" | \"automatic\";\n\t\tmethod: \"fromSimulator\" | \"upload\" | \"dragAndDrop\";\n\t}\n>;\n\ntype ChangesPushedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_pushed,\n\t{\n\t\tcustomTypesCreated: number;\n\t\tcustomTypesModified: number;\n\t\tcustomTypesDeleted: number;\n\t\tslicesCreated: number;\n\t\tslicesModified: number;\n\t\tslicesDeleted: number;\n\t\tmissingScreenshots: number;\n\t\ttotal: number;\n\t\tduration: number;\n\t\thasDeletedDocuments: boolean;\n\t}\n>;\n\ntype ChangesLimitReachSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_limitReach,\n\t{ limitType: LimitType }\n>;\n\ntype EditorWidgetUsedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.editor_widgetUsed,\n\t{ sliceId: string }\n>;\n\nexport type SegmentEvents =\n\t| CommandInitStartSegmentEvent\n\t| CommandInitIdentifySegmentEvent\n\t| CommandInitEndSegmentEvent\n\t| ReviewSegmentEvent\n\t| SliceSimulatorSetupSegmentEvent\n\t| SliceSimulatorOpenSegmentEvent\n\t| SliceSimulatorIsNotRunningSegmentEvent\n\t| PageViewSegmentEvent\n\t| OpenVideoTutorialsSegmentEvent\n\t| CustomTypeCreatedSegmentEvent\n\t| CustomTypeFieldAddedSegmentEvent\n\t| CustomTypeSliceZoneUpdatedSegmentEvent\n\t| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent\n\t| OpenPageSnippetSegmentEvent\n\t| CopyPageSnippetSegmentEvent;\n"],"names":[],"mappings":";;AAGO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;;AAKb,MAAM,wBAAwB;AAAA,EACpC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GAAG;AAAA,EAC1C,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,MAAM,GAAG;AAAA,EAC3B,CAAC,iBAAiB,oBAAoB,GAAG;AAAA,EACzC,CAAC,iBAAiB,mBAAmB,GAAG;AAAA,EACxC,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;AAAA,EACtC,CAAC,iBAAiB,iBAAiB,GAClC;AAAA,EACD,CAAC,iBAAiB,iBAAiB,GAClC;;;;"}
|
|
@@ -109,7 +109,6 @@ type SliceCreatedSegmentEvent = SegmentEvent<typeof SegmentEventType.slice_creat
|
|
|
109
109
|
id: string;
|
|
110
110
|
name: string;
|
|
111
111
|
library: string;
|
|
112
|
-
sliceTemplate?: string;
|
|
113
112
|
}>;
|
|
114
113
|
type ScreenshotTakenSegmentEvent = SegmentEvent<typeof SegmentEventType.screenshotTaken, {
|
|
115
114
|
type: "custom" | "automatic";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{ rating: number; comment: string }\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{ rating: number; comment: string }\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string }\n>;\n\ntype ScreenshotTakenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.screenshotTaken,\n\t{\n\t\ttype: \"custom\" | \"automatic\";\n\t\tmethod: \"fromSimulator\" | \"upload\" | \"dragAndDrop\";\n\t}\n>;\n\ntype ChangesPushedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_pushed,\n\t{\n\t\tcustomTypesCreated: number;\n\t\tcustomTypesModified: number;\n\t\tcustomTypesDeleted: number;\n\t\tslicesCreated: number;\n\t\tslicesModified: number;\n\t\tslicesDeleted: number;\n\t\tmissingScreenshots: number;\n\t\ttotal: number;\n\t\tduration: number;\n\t\thasDeletedDocuments: boolean;\n\t}\n>;\n\ntype ChangesLimitReachSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_limitReach,\n\t{ limitType: LimitType }\n>;\n\ntype EditorWidgetUsedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.editor_widgetUsed,\n\t{ sliceId: string }\n>;\n\nexport type SegmentEvents =\n\t| CommandInitStartSegmentEvent\n\t| CommandInitIdentifySegmentEvent\n\t| CommandInitEndSegmentEvent\n\t| ReviewSegmentEvent\n\t| SliceSimulatorSetupSegmentEvent\n\t| SliceSimulatorOpenSegmentEvent\n\t| SliceSimulatorIsNotRunningSegmentEvent\n\t| PageViewSegmentEvent\n\t| OpenVideoTutorialsSegmentEvent\n\t| CustomTypeCreatedSegmentEvent\n\t| CustomTypeFieldAddedSegmentEvent\n\t| CustomTypeSliceZoneUpdatedSegmentEvent\n\t| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent\n\t| OpenPageSnippetSegmentEvent\n\t| CopyPageSnippetSegmentEvent;\n"],"names":[],"mappings":"AAGO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;;AAKb,MAAM,wBAAwB;AAAA,EACpC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GAAG;AAAA,EAC1C,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,MAAM,GAAG;AAAA,EAC3B,CAAC,iBAAiB,oBAAoB,GAAG;AAAA,EACzC,CAAC,iBAAiB,mBAAmB,GAAG;AAAA,EACxC,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;AAAA,EACtC,CAAC,iBAAiB,iBAAiB,GAClC;AAAA,EACD,CAAC,iBAAiB,iBAAiB,GAClC;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/manager",
|
|
3
|
-
"version": "0.10.1-dev-
|
|
3
|
+
"version": "0.10.1-dev-next-release.5",
|
|
4
4
|
"description": "Manage all aspects of a Slice Machine project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,14 +13,17 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
16
17
|
"require": "./dist/index.cjs",
|
|
17
18
|
"import": "./dist/index.js"
|
|
18
19
|
},
|
|
19
20
|
"./client": {
|
|
21
|
+
"types": "./dist/client/index.d.js",
|
|
20
22
|
"require": "./dist/client.cjs",
|
|
21
23
|
"import": "./dist/client.js"
|
|
22
24
|
},
|
|
23
25
|
"./test": {
|
|
26
|
+
"types": "./dist/test/index.d.js",
|
|
24
27
|
"require": "./dist/test.cjs",
|
|
25
28
|
"import": "./dist/test.js"
|
|
26
29
|
},
|
|
@@ -65,7 +68,7 @@
|
|
|
65
68
|
"@prismicio/custom-types-client": "^1.2.0-alpha.0",
|
|
66
69
|
"@prismicio/mocks": "^2.0.0-alpha.2",
|
|
67
70
|
"@prismicio/types-internal": "^2.0.0",
|
|
68
|
-
"@slicemachine/plugin-kit": "^0.4.14-dev-
|
|
71
|
+
"@slicemachine/plugin-kit": "^0.4.14-dev-next-release.5",
|
|
69
72
|
"@wooorm/starry-night": "^1.6.0",
|
|
70
73
|
"analytics-node": "^6.2.0",
|
|
71
74
|
"cookie": "^0.5.0",
|
|
@@ -131,5 +134,5 @@
|
|
|
131
134
|
"engines": {
|
|
132
135
|
"node": ">=14.15.0"
|
|
133
136
|
},
|
|
134
|
-
"gitHead": "
|
|
137
|
+
"gitHead": "493a6d41d5a40c65dce1e1adfb1a8e38db999804"
|
|
135
138
|
}
|
|
@@ -18,7 +18,6 @@ import { SimulatorManager } from "./simulator/SimulatorManager";
|
|
|
18
18
|
import { VersionsManager } from "./versions/VersionsManager";
|
|
19
19
|
import { TelemetryManager } from "./telemetry/TelemetryManager";
|
|
20
20
|
import { DocumentationManager } from "./documentation/DocumentationManager";
|
|
21
|
-
import { SliceTemplateLibraryManager } from "./sliceTemplateLibrary/SliceTemplateLibraryManager";
|
|
22
21
|
|
|
23
22
|
export abstract class BaseManager {
|
|
24
23
|
private _sliceMachineManager: SliceMachineManager;
|
|
@@ -86,9 +85,6 @@ export abstract class BaseManager {
|
|
|
86
85
|
protected get documentation(): DocumentationManager {
|
|
87
86
|
return this._sliceMachineManager.documentation;
|
|
88
87
|
}
|
|
89
|
-
protected get sliceTemplateLibrary(): SliceTemplateLibraryManager {
|
|
90
|
-
return this._sliceMachineManager.sliceTemplateLibrary;
|
|
91
|
-
}
|
|
92
88
|
|
|
93
89
|
protected get versions(): VersionsManager {
|
|
94
90
|
return this._sliceMachineManager.versions;
|
|
@@ -40,7 +40,6 @@ import { VersionsManager } from "./versions/VersionsManager";
|
|
|
40
40
|
import { TelemetryManager } from "./telemetry/TelemetryManager";
|
|
41
41
|
import { buildPrismicRepositoryAPIEndpoint } from "../lib/buildPrismicRepositoryAPIEndpoint";
|
|
42
42
|
import { DocumentationManager } from "./documentation/DocumentationManager";
|
|
43
|
-
import { SliceTemplateLibraryManager } from "./sliceTemplateLibrary/SliceTemplateLibraryManager";
|
|
44
43
|
|
|
45
44
|
type SliceMachineManagerGetStateReturnType = {
|
|
46
45
|
env: {
|
|
@@ -115,7 +114,6 @@ export class SliceMachineManager {
|
|
|
115
114
|
slices: SlicesManager;
|
|
116
115
|
snippets: SnippetsManager;
|
|
117
116
|
documentation: DocumentationManager;
|
|
118
|
-
sliceTemplateLibrary: SliceTemplateLibraryManager;
|
|
119
117
|
telemetry: TelemetryManager;
|
|
120
118
|
user: UserManager;
|
|
121
119
|
versions: VersionsManager;
|
|
@@ -140,7 +138,6 @@ export class SliceMachineManager {
|
|
|
140
138
|
this.screenshots = new ScreenshotsManager(this);
|
|
141
139
|
this.simulator = new SimulatorManager(this);
|
|
142
140
|
this.documentation = new DocumentationManager(this);
|
|
143
|
-
this.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);
|
|
144
141
|
|
|
145
142
|
this.versions = new VersionsManager(this);
|
|
146
143
|
|
|
@@ -37,7 +37,6 @@ const omitProcedures = defineOmits<SliceMachineManager>()([
|
|
|
37
37
|
"user._sliceMachineManager",
|
|
38
38
|
"versions._sliceMachineManager",
|
|
39
39
|
"documentation._sliceMachineManager",
|
|
40
|
-
"sliceTemplateLibrary._sliceMachineManager",
|
|
41
40
|
"getSliceMachinePluginRunner",
|
|
42
41
|
"getPrismicAuthManager",
|
|
43
42
|
"screenshots.browserContext",
|
|
@@ -164,7 +164,7 @@ type CustomTypeSavedSegmentEvent = SegmentEvent<
|
|
|
164
164
|
|
|
165
165
|
type SliceCreatedSegmentEvent = SegmentEvent<
|
|
166
166
|
typeof SegmentEventType.slice_created,
|
|
167
|
-
{ id: string; name: string; library: string
|
|
167
|
+
{ id: string; name: string; library: string }
|
|
168
168
|
>;
|
|
169
169
|
|
|
170
170
|
type ScreenshotTakenSegmentEvent = SegmentEvent<
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const t = require("io-ts");
|
|
4
|
-
const BaseManager = require("../BaseManager.cjs");
|
|
5
|
-
const assertPluginsInitialized = require("../../lib/assertPluginsInitialized.cjs");
|
|
6
|
-
const decodeHookResult = require("../../lib/decodeHookResult.cjs");
|
|
7
|
-
const customtypes = require("@prismicio/types-internal/lib/customtypes");
|
|
8
|
-
const content = require("@prismicio/types-internal/lib/content");
|
|
9
|
-
function _interopNamespaceDefault(e) {
|
|
10
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
-
if (e) {
|
|
12
|
-
for (const k in e) {
|
|
13
|
-
if (k !== "default") {
|
|
14
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: () => e[k]
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
n.default = e;
|
|
23
|
-
return Object.freeze(n);
|
|
24
|
-
}
|
|
25
|
-
const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
|
|
26
|
-
const readHookCodec = t__namespace.type({
|
|
27
|
-
templates: t__namespace.array(t__namespace.type({
|
|
28
|
-
model: customtypes.SharedSlice,
|
|
29
|
-
createComponentContents: t__namespace.Function,
|
|
30
|
-
mocks: t__namespace.array(content.SharedSliceContent),
|
|
31
|
-
screenshots: t__namespace.record(t__namespace.string, t__namespace.any)
|
|
32
|
-
}))
|
|
33
|
-
});
|
|
34
|
-
class SliceTemplateLibraryManager extends BaseManager.BaseManager {
|
|
35
|
-
async readLibrary(args) {
|
|
36
|
-
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
37
|
-
const hookResult = await this.sliceMachinePluginRunner.callHook("slice-template-library:read", args);
|
|
38
|
-
const { data, errors } = decodeHookResult.decodeHookResult(readHookCodec, hookResult);
|
|
39
|
-
return {
|
|
40
|
-
templates: data.flat().flatMap((item) => item.templates.map((t2) => ({
|
|
41
|
-
model: t2.model,
|
|
42
|
-
screenshots: t2.screenshots
|
|
43
|
-
}))),
|
|
44
|
-
errors
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async createSlices(args) {
|
|
48
|
-
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
49
|
-
const hookReadResult = await this.sliceMachinePluginRunner.callHook("slice-template-library:read", args);
|
|
50
|
-
const { data: readData, errors: readErrors } = decodeHookResult.decodeHookResult(readHookCodec, hookReadResult);
|
|
51
|
-
const templates = readData.flat().flatMap((item) => item.templates);
|
|
52
|
-
if (readErrors.length > 0) {
|
|
53
|
-
return {
|
|
54
|
-
errors: readErrors
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const { models: allSlices, errors: readAllSlicesErrors } = await this.slices.readAllSlices();
|
|
58
|
-
if (readAllSlicesErrors.length > 0) {
|
|
59
|
-
return {
|
|
60
|
-
errors: readAllSlicesErrors
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
const existingIds = allSlices.map((slice) => slice.model.id);
|
|
64
|
-
const getNextAvailableSlice = (baseId) => {
|
|
65
|
-
let nextId = baseId;
|
|
66
|
-
let counter = 1;
|
|
67
|
-
while (existingIds.includes(nextId)) {
|
|
68
|
-
counter++;
|
|
69
|
-
nextId = `${baseId}_${counter}`;
|
|
70
|
-
}
|
|
71
|
-
existingIds.push(nextId);
|
|
72
|
-
return { id: nextId, counter };
|
|
73
|
-
};
|
|
74
|
-
const slicesToCreate = templates.map((template) => {
|
|
75
|
-
const { id, counter } = getNextAvailableSlice(template.model.id);
|
|
76
|
-
return {
|
|
77
|
-
...template,
|
|
78
|
-
model: {
|
|
79
|
-
...template.model,
|
|
80
|
-
id,
|
|
81
|
-
name: counter > 1 ? template.model.name + counter : template.model.name
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
const { libraries, errors: readAllSliceLibrariesErrors } = await this.slices.readAllSliceLibraries();
|
|
86
|
-
if (readAllSliceLibrariesErrors.length > 0) {
|
|
87
|
-
return {
|
|
88
|
-
errors: readAllSliceLibrariesErrors
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const targetLibrary = libraries[0];
|
|
92
|
-
const creationPromises = slicesToCreate.map((slice) => {
|
|
93
|
-
return this.slices.createSlice({
|
|
94
|
-
libraryID: targetLibrary.libraryID,
|
|
95
|
-
model: slice.model,
|
|
96
|
-
componentContents: slice.createComponentContents(slice.model)
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
const creationResults = await Promise.all(creationPromises);
|
|
100
|
-
const creationErrors = creationResults.flatMap((result) => result.errors);
|
|
101
|
-
if (creationErrors.length > 0) {
|
|
102
|
-
return {
|
|
103
|
-
errors: creationErrors
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
const mocksPromises = slicesToCreate.map((slice) => {
|
|
107
|
-
return this.slices.updateSliceMocks({
|
|
108
|
-
libraryID: targetLibrary.libraryID,
|
|
109
|
-
sliceID: slice.model.id,
|
|
110
|
-
mocks: slice.mocks
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
const mocksResults = await Promise.all(mocksPromises);
|
|
114
|
-
const sliceScreenshotsPromises = slicesToCreate.map((slice) => {
|
|
115
|
-
const screenshotPromises = Object.entries(slice.screenshots).map(([variationID, data]) => {
|
|
116
|
-
return this.slices.updateSliceScreenshot({
|
|
117
|
-
libraryID: targetLibrary.libraryID,
|
|
118
|
-
sliceID: slice.model.id,
|
|
119
|
-
variationID,
|
|
120
|
-
data
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
return Promise.all(screenshotPromises);
|
|
124
|
-
});
|
|
125
|
-
const sliceScreenshotsResults = await Promise.all(sliceScreenshotsPromises);
|
|
126
|
-
const mocksErrors = mocksResults.flatMap((result) => result.errors);
|
|
127
|
-
const screenshotErrors = sliceScreenshotsResults.flatMap((result) => result.flat().flatMap((r) => r.errors));
|
|
128
|
-
const sliceIDs = slicesToCreate.map((slice) => slice.model.id);
|
|
129
|
-
return {
|
|
130
|
-
errors: [...mocksErrors, ...screenshotErrors],
|
|
131
|
-
data: {
|
|
132
|
-
sliceIDs
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.SliceTemplateLibraryManager = SliceTemplateLibraryManager;
|
|
138
|
-
//# sourceMappingURL=SliceTemplateLibraryManager.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SliceTemplateLibraryManager.cjs","sources":["../../../../src/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { HookError } from \"@slicemachine/plugin-kit\";\nimport { BaseManager } from \"../BaseManager\";\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\n\ntype SliceTemplateLibraryManagerReadLibraryReturnType = {\n\ttemplates: {\n\t\tmodel: SharedSlice;\n\t\tscreenshots: Record<string, Buffer>;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceTemplateLibraryManagerCreateSlicesReturnType = {\n\tdata?: {\n\t\tsliceIDs: string[];\n\t};\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceTemplateLibraryReadLibraryData = {\n\ttemplateIDs?: string[];\n};\n\ntype SliceTemplateLibraryCreateSlicesData = SliceTemplateLibraryReadLibraryData;\n\nconst readHookCodec = t.type({\n\ttemplates: t.array(\n\t\tt.type({\n\t\t\tmodel: SharedSlice,\n\t\t\tcreateComponentContents: t.Function,\n\t\t\tmocks: t.array(SharedSliceContent),\n\t\t\tscreenshots: t.record(t.string, t.any),\n\t\t}),\n\t),\n});\n\nexport class SliceTemplateLibraryManager extends BaseManager {\n\tasync readLibrary(\n\t\targs: SliceTemplateLibraryReadLibraryData,\n\t): Promise<SliceTemplateLibraryManagerReadLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-template-library:read\",\n\t\t\targs,\n\t\t);\n\n\t\tconst { data, errors } = decodeHookResult(readHookCodec, hookResult);\n\n\t\treturn {\n\t\t\ttemplates: data.flat().flatMap((item) =>\n\t\t\t\titem.templates.map((t) => ({\n\t\t\t\t\tmodel: t.model,\n\t\t\t\t\tscreenshots: t.screenshots,\n\t\t\t\t})),\n\t\t\t),\n\t\t\terrors,\n\t\t};\n\t}\n\tasync createSlices(\n\t\targs: SliceTemplateLibraryCreateSlicesData,\n\t): Promise<SliceTemplateLibraryManagerCreateSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// Reading all available slice templates\n\t\tconst hookReadResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-template-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data: readData, errors: readErrors } = decodeHookResult(\n\t\t\treadHookCodec,\n\t\t\thookReadResult,\n\t\t);\n\t\tconst templates = readData.flat().flatMap((item) => item.templates);\n\t\tif (readErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: readErrors,\n\t\t\t};\n\t\t}\n\n\t\t// Extract all existing slice IDs into an array\n\t\tconst { models: allSlices, errors: readAllSlicesErrors } =\n\t\t\tawait this.slices.readAllSlices();\n\t\tif (readAllSlicesErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: readAllSlicesErrors,\n\t\t\t};\n\t\t}\n\t\tconst existingIds: string[] = allSlices.map((slice) => slice.model.id);\n\n\t\t// Create a function to get the next available ID based on the baseId\n\t\tconst getNextAvailableSlice = (baseId: string) => {\n\t\t\tlet nextId = baseId;\n\t\t\tlet counter = 1;\n\t\t\twhile (existingIds.includes(nextId)) {\n\t\t\t\tcounter++;\n\t\t\t\tnextId = `${baseId}_${counter}`;\n\t\t\t}\n\t\t\texistingIds.push(nextId);\n\n\t\t\treturn { id: nextId, counter };\n\t\t};\n\n\t\t// Extract the slices to create from the template ids given in args\n\t\tconst slicesToCreate = templates.map((template) => {\n\t\t\tconst { id, counter } = getNextAvailableSlice(template.model.id);\n\n\t\t\treturn {\n\t\t\t\t...template,\n\t\t\t\tmodel: {\n\t\t\t\t\t...template.model,\n\t\t\t\t\tid,\n\t\t\t\t\tname:\n\t\t\t\t\t\tcounter > 1 ? template.model.name + counter : template.model.name,\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\t// Get target library\n\t\t// Note: We only support adding template to the first library at the moment\n\t\tconst { libraries, errors: readAllSliceLibrariesErrors } =\n\t\t\tawait this.slices.readAllSliceLibraries();\n\t\tif (readAllSliceLibrariesErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: readAllSliceLibrariesErrors,\n\t\t\t};\n\t\t}\n\t\tconst targetLibrary = libraries[0];\n\n\t\t// Initiate the slice creation process for all slices\n\t\tconst creationPromises = slicesToCreate.map((slice) => {\n\t\t\treturn this.slices.createSlice({\n\t\t\t\tlibraryID: targetLibrary.libraryID,\n\t\t\t\tmodel: slice.model,\n\t\t\t\tcomponentContents: slice.createComponentContents(slice.model),\n\t\t\t});\n\t\t});\n\n\t\t// Wait for all slices to be created\n\t\tconst creationResults = await Promise.all(creationPromises);\n\t\t// Check for any errors in the creation results\n\t\tconst creationErrors = creationResults.flatMap((result) => result.errors);\n\t\tif (creationErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: creationErrors,\n\t\t\t};\n\t\t}\n\n\t\tconst mocksPromises = slicesToCreate.map((slice) => {\n\t\t\treturn this.slices.updateSliceMocks({\n\t\t\t\tlibraryID: targetLibrary.libraryID,\n\t\t\t\tsliceID: slice.model.id,\n\t\t\t\tmocks: slice.mocks,\n\t\t\t});\n\t\t});\n\n\t\tconst mocksResults = await Promise.all(mocksPromises);\n\n\t\tconst sliceScreenshotsPromises = slicesToCreate.map((slice) => {\n\t\t\tconst screenshotPromises = Object.entries(slice.screenshots).map(\n\t\t\t\t([variationID, data]) => {\n\t\t\t\t\treturn this.slices.updateSliceScreenshot({\n\t\t\t\t\t\tlibraryID: targetLibrary.libraryID,\n\t\t\t\t\t\tsliceID: slice.model.id,\n\t\t\t\t\t\tvariationID,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn Promise.all(screenshotPromises);\n\t\t});\n\n\t\tconst sliceScreenshotsResults = await Promise.all(sliceScreenshotsPromises);\n\t\tconst mocksErrors = mocksResults.flatMap((result) => result.errors);\n\t\tconst screenshotErrors = sliceScreenshotsResults.flatMap((result) =>\n\t\t\tresult.flat().flatMap((r) => r.errors),\n\t\t);\n\n\t\t// Extract the slice IDs from the creation results (assuming each result has an ID)\n\t\tconst sliceIDs = slicesToCreate.map((slice) => slice.model.id);\n\n\t\treturn {\n\t\t\terrors: [...mocksErrors, ...screenshotErrors],\n\t\t\tdata: {\n\t\t\t\tsliceIDs,\n\t\t\t},\n\t\t};\n\t}\n}\n"],"names":["t","SharedSlice","SharedSliceContent","BaseManager","assertPluginsInitialized","decodeHookResult"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,gBAAgBA,aAAE,KAAK;AAAA,EAC5B,WAAWA,aAAE,MACZA,aAAE,KAAK;AAAA,IACN,OAAOC,YAAA;AAAA,IACP,yBAAyBD,aAAE;AAAA,IAC3B,OAAOA,aAAE,MAAME,0BAAkB;AAAA,IACjC,aAAaF,aAAE,OAAOA,aAAE,QAAQA,aAAE,GAAG;AAAA,EAAA,CACrC,CAAC;AAEH,CAAA;AAEK,MAAO,oCAAoCG,YAAAA,YAAW;AAAA,EAC3D,MAAM,YACL,MAAyC;AAEzCC,sDAAyB,KAAK,wBAAwB;AAE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aAAA,QAAQ,IAAI,kBAAkB;AAAA,IAAA,CACrC;AAED,UAAM,0BAA0B,MAAM,QAAQ,IAAI,wBAAwB;AAC1E,UAAM,cAAc,aAAa,QAAQ,CAAC,WAAW,OAAO,MAAM;AAClE,UAAM,mBAAmB,wBAAwB,QAAQ,CAAC,WACzD,OAAO,KAAM,EAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AAIvC,UAAM,WAAW,eAAe,IAAI,CAAC,UAAU,MAAM,MAAM,EAAE;AAEtD,WAAA;AAAA,MACN,QAAQ,CAAC,GAAG,aAAa,GAAG,gBAAgB;AAAA,MAC5C,MAAM;AAAA,QACL;AAAA,MACA;AAAA,IAAA;AAAA,EAEH;AACA;;"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { HookError } from "@slicemachine/plugin-kit";
|
|
3
|
-
import { BaseManager } from "../BaseManager";
|
|
4
|
-
import { DecodeError } from "../../lib/DecodeError";
|
|
5
|
-
import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
6
|
-
type SliceTemplateLibraryManagerReadLibraryReturnType = {
|
|
7
|
-
templates: {
|
|
8
|
-
model: SharedSlice;
|
|
9
|
-
screenshots: Record<string, Buffer>;
|
|
10
|
-
}[];
|
|
11
|
-
errors: (DecodeError | HookError)[];
|
|
12
|
-
};
|
|
13
|
-
type SliceTemplateLibraryManagerCreateSlicesReturnType = {
|
|
14
|
-
data?: {
|
|
15
|
-
sliceIDs: string[];
|
|
16
|
-
};
|
|
17
|
-
errors: (DecodeError | HookError)[];
|
|
18
|
-
};
|
|
19
|
-
type SliceTemplateLibraryReadLibraryData = {
|
|
20
|
-
templateIDs?: string[];
|
|
21
|
-
};
|
|
22
|
-
type SliceTemplateLibraryCreateSlicesData = SliceTemplateLibraryReadLibraryData;
|
|
23
|
-
export declare class SliceTemplateLibraryManager extends BaseManager {
|
|
24
|
-
readLibrary(args: SliceTemplateLibraryReadLibraryData): Promise<SliceTemplateLibraryManagerReadLibraryReturnType>;
|
|
25
|
-
createSlices(args: SliceTemplateLibraryCreateSlicesData): Promise<SliceTemplateLibraryManagerCreateSlicesReturnType>;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
import { BaseManager } from "../BaseManager.js";
|
|
3
|
-
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized.js";
|
|
4
|
-
import { decodeHookResult } from "../../lib/decodeHookResult.js";
|
|
5
|
-
import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
6
|
-
import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
|
|
7
|
-
const readHookCodec = t.type({
|
|
8
|
-
templates: t.array(t.type({
|
|
9
|
-
model: SharedSlice,
|
|
10
|
-
createComponentContents: t.Function,
|
|
11
|
-
mocks: t.array(SharedSliceContent),
|
|
12
|
-
screenshots: t.record(t.string, t.any)
|
|
13
|
-
}))
|
|
14
|
-
});
|
|
15
|
-
class SliceTemplateLibraryManager extends BaseManager {
|
|
16
|
-
async readLibrary(args) {
|
|
17
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
18
|
-
const hookResult = await this.sliceMachinePluginRunner.callHook("slice-template-library:read", args);
|
|
19
|
-
const { data, errors } = decodeHookResult(readHookCodec, hookResult);
|
|
20
|
-
return {
|
|
21
|
-
templates: data.flat().flatMap((item) => item.templates.map((t2) => ({
|
|
22
|
-
model: t2.model,
|
|
23
|
-
screenshots: t2.screenshots
|
|
24
|
-
}))),
|
|
25
|
-
errors
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async createSlices(args) {
|
|
29
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
30
|
-
const hookReadResult = await this.sliceMachinePluginRunner.callHook("slice-template-library:read", args);
|
|
31
|
-
const { data: readData, errors: readErrors } = decodeHookResult(readHookCodec, hookReadResult);
|
|
32
|
-
const templates = readData.flat().flatMap((item) => item.templates);
|
|
33
|
-
if (readErrors.length > 0) {
|
|
34
|
-
return {
|
|
35
|
-
errors: readErrors
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const { models: allSlices, errors: readAllSlicesErrors } = await this.slices.readAllSlices();
|
|
39
|
-
if (readAllSlicesErrors.length > 0) {
|
|
40
|
-
return {
|
|
41
|
-
errors: readAllSlicesErrors
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const existingIds = allSlices.map((slice) => slice.model.id);
|
|
45
|
-
const getNextAvailableSlice = (baseId) => {
|
|
46
|
-
let nextId = baseId;
|
|
47
|
-
let counter = 1;
|
|
48
|
-
while (existingIds.includes(nextId)) {
|
|
49
|
-
counter++;
|
|
50
|
-
nextId = `${baseId}_${counter}`;
|
|
51
|
-
}
|
|
52
|
-
existingIds.push(nextId);
|
|
53
|
-
return { id: nextId, counter };
|
|
54
|
-
};
|
|
55
|
-
const slicesToCreate = templates.map((template) => {
|
|
56
|
-
const { id, counter } = getNextAvailableSlice(template.model.id);
|
|
57
|
-
return {
|
|
58
|
-
...template,
|
|
59
|
-
model: {
|
|
60
|
-
...template.model,
|
|
61
|
-
id,
|
|
62
|
-
name: counter > 1 ? template.model.name + counter : template.model.name
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
const { libraries, errors: readAllSliceLibrariesErrors } = await this.slices.readAllSliceLibraries();
|
|
67
|
-
if (readAllSliceLibrariesErrors.length > 0) {
|
|
68
|
-
return {
|
|
69
|
-
errors: readAllSliceLibrariesErrors
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const targetLibrary = libraries[0];
|
|
73
|
-
const creationPromises = slicesToCreate.map((slice) => {
|
|
74
|
-
return this.slices.createSlice({
|
|
75
|
-
libraryID: targetLibrary.libraryID,
|
|
76
|
-
model: slice.model,
|
|
77
|
-
componentContents: slice.createComponentContents(slice.model)
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
const creationResults = await Promise.all(creationPromises);
|
|
81
|
-
const creationErrors = creationResults.flatMap((result) => result.errors);
|
|
82
|
-
if (creationErrors.length > 0) {
|
|
83
|
-
return {
|
|
84
|
-
errors: creationErrors
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const mocksPromises = slicesToCreate.map((slice) => {
|
|
88
|
-
return this.slices.updateSliceMocks({
|
|
89
|
-
libraryID: targetLibrary.libraryID,
|
|
90
|
-
sliceID: slice.model.id,
|
|
91
|
-
mocks: slice.mocks
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
const mocksResults = await Promise.all(mocksPromises);
|
|
95
|
-
const sliceScreenshotsPromises = slicesToCreate.map((slice) => {
|
|
96
|
-
const screenshotPromises = Object.entries(slice.screenshots).map(([variationID, data]) => {
|
|
97
|
-
return this.slices.updateSliceScreenshot({
|
|
98
|
-
libraryID: targetLibrary.libraryID,
|
|
99
|
-
sliceID: slice.model.id,
|
|
100
|
-
variationID,
|
|
101
|
-
data
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
return Promise.all(screenshotPromises);
|
|
105
|
-
});
|
|
106
|
-
const sliceScreenshotsResults = await Promise.all(sliceScreenshotsPromises);
|
|
107
|
-
const mocksErrors = mocksResults.flatMap((result) => result.errors);
|
|
108
|
-
const screenshotErrors = sliceScreenshotsResults.flatMap((result) => result.flat().flatMap((r) => r.errors));
|
|
109
|
-
const sliceIDs = slicesToCreate.map((slice) => slice.model.id);
|
|
110
|
-
return {
|
|
111
|
-
errors: [...mocksErrors, ...screenshotErrors],
|
|
112
|
-
data: {
|
|
113
|
-
sliceIDs
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export {
|
|
119
|
-
SliceTemplateLibraryManager
|
|
120
|
-
};
|
|
121
|
-
//# sourceMappingURL=SliceTemplateLibraryManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SliceTemplateLibraryManager.js","sources":["../../../../src/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { HookError } from \"@slicemachine/plugin-kit\";\nimport { BaseManager } from \"../BaseManager\";\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\n\ntype SliceTemplateLibraryManagerReadLibraryReturnType = {\n\ttemplates: {\n\t\tmodel: SharedSlice;\n\t\tscreenshots: Record<string, Buffer>;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceTemplateLibraryManagerCreateSlicesReturnType = {\n\tdata?: {\n\t\tsliceIDs: string[];\n\t};\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceTemplateLibraryReadLibraryData = {\n\ttemplateIDs?: string[];\n};\n\ntype SliceTemplateLibraryCreateSlicesData = SliceTemplateLibraryReadLibraryData;\n\nconst readHookCodec = t.type({\n\ttemplates: t.array(\n\t\tt.type({\n\t\t\tmodel: SharedSlice,\n\t\t\tcreateComponentContents: t.Function,\n\t\t\tmocks: t.array(SharedSliceContent),\n\t\t\tscreenshots: t.record(t.string, t.any),\n\t\t}),\n\t),\n});\n\nexport class SliceTemplateLibraryManager extends BaseManager {\n\tasync readLibrary(\n\t\targs: SliceTemplateLibraryReadLibraryData,\n\t): Promise<SliceTemplateLibraryManagerReadLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-template-library:read\",\n\t\t\targs,\n\t\t);\n\n\t\tconst { data, errors } = decodeHookResult(readHookCodec, hookResult);\n\n\t\treturn {\n\t\t\ttemplates: data.flat().flatMap((item) =>\n\t\t\t\titem.templates.map((t) => ({\n\t\t\t\t\tmodel: t.model,\n\t\t\t\t\tscreenshots: t.screenshots,\n\t\t\t\t})),\n\t\t\t),\n\t\t\terrors,\n\t\t};\n\t}\n\tasync createSlices(\n\t\targs: SliceTemplateLibraryCreateSlicesData,\n\t): Promise<SliceTemplateLibraryManagerCreateSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// Reading all available slice templates\n\t\tconst hookReadResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-template-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data: readData, errors: readErrors } = decodeHookResult(\n\t\t\treadHookCodec,\n\t\t\thookReadResult,\n\t\t);\n\t\tconst templates = readData.flat().flatMap((item) => item.templates);\n\t\tif (readErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: readErrors,\n\t\t\t};\n\t\t}\n\n\t\t// Extract all existing slice IDs into an array\n\t\tconst { models: allSlices, errors: readAllSlicesErrors } =\n\t\t\tawait this.slices.readAllSlices();\n\t\tif (readAllSlicesErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: readAllSlicesErrors,\n\t\t\t};\n\t\t}\n\t\tconst existingIds: string[] = allSlices.map((slice) => slice.model.id);\n\n\t\t// Create a function to get the next available ID based on the baseId\n\t\tconst getNextAvailableSlice = (baseId: string) => {\n\t\t\tlet nextId = baseId;\n\t\t\tlet counter = 1;\n\t\t\twhile (existingIds.includes(nextId)) {\n\t\t\t\tcounter++;\n\t\t\t\tnextId = `${baseId}_${counter}`;\n\t\t\t}\n\t\t\texistingIds.push(nextId);\n\n\t\t\treturn { id: nextId, counter };\n\t\t};\n\n\t\t// Extract the slices to create from the template ids given in args\n\t\tconst slicesToCreate = templates.map((template) => {\n\t\t\tconst { id, counter } = getNextAvailableSlice(template.model.id);\n\n\t\t\treturn {\n\t\t\t\t...template,\n\t\t\t\tmodel: {\n\t\t\t\t\t...template.model,\n\t\t\t\t\tid,\n\t\t\t\t\tname:\n\t\t\t\t\t\tcounter > 1 ? template.model.name + counter : template.model.name,\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\t// Get target library\n\t\t// Note: We only support adding template to the first library at the moment\n\t\tconst { libraries, errors: readAllSliceLibrariesErrors } =\n\t\t\tawait this.slices.readAllSliceLibraries();\n\t\tif (readAllSliceLibrariesErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: readAllSliceLibrariesErrors,\n\t\t\t};\n\t\t}\n\t\tconst targetLibrary = libraries[0];\n\n\t\t// Initiate the slice creation process for all slices\n\t\tconst creationPromises = slicesToCreate.map((slice) => {\n\t\t\treturn this.slices.createSlice({\n\t\t\t\tlibraryID: targetLibrary.libraryID,\n\t\t\t\tmodel: slice.model,\n\t\t\t\tcomponentContents: slice.createComponentContents(slice.model),\n\t\t\t});\n\t\t});\n\n\t\t// Wait for all slices to be created\n\t\tconst creationResults = await Promise.all(creationPromises);\n\t\t// Check for any errors in the creation results\n\t\tconst creationErrors = creationResults.flatMap((result) => result.errors);\n\t\tif (creationErrors.length > 0) {\n\t\t\treturn {\n\t\t\t\terrors: creationErrors,\n\t\t\t};\n\t\t}\n\n\t\tconst mocksPromises = slicesToCreate.map((slice) => {\n\t\t\treturn this.slices.updateSliceMocks({\n\t\t\t\tlibraryID: targetLibrary.libraryID,\n\t\t\t\tsliceID: slice.model.id,\n\t\t\t\tmocks: slice.mocks,\n\t\t\t});\n\t\t});\n\n\t\tconst mocksResults = await Promise.all(mocksPromises);\n\n\t\tconst sliceScreenshotsPromises = slicesToCreate.map((slice) => {\n\t\t\tconst screenshotPromises = Object.entries(slice.screenshots).map(\n\t\t\t\t([variationID, data]) => {\n\t\t\t\t\treturn this.slices.updateSliceScreenshot({\n\t\t\t\t\t\tlibraryID: targetLibrary.libraryID,\n\t\t\t\t\t\tsliceID: slice.model.id,\n\t\t\t\t\t\tvariationID,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn Promise.all(screenshotPromises);\n\t\t});\n\n\t\tconst sliceScreenshotsResults = await Promise.all(sliceScreenshotsPromises);\n\t\tconst mocksErrors = mocksResults.flatMap((result) => result.errors);\n\t\tconst screenshotErrors = sliceScreenshotsResults.flatMap((result) =>\n\t\t\tresult.flat().flatMap((r) => r.errors),\n\t\t);\n\n\t\t// Extract the slice IDs from the creation results (assuming each result has an ID)\n\t\tconst sliceIDs = slicesToCreate.map((slice) => slice.model.id);\n\n\t\treturn {\n\t\t\terrors: [...mocksErrors, ...screenshotErrors],\n\t\t\tdata: {\n\t\t\t\tsliceIDs,\n\t\t\t},\n\t\t};\n\t}\n}\n"],"names":["t"],"mappings":";;;;;;AA8BA,MAAM,gBAAgB,EAAE,KAAK;AAAA,EAC5B,WAAW,EAAE,MACZ,EAAE,KAAK;AAAA,IACN,OAAO;AAAA,IACP,yBAAyB,EAAE;AAAA,IAC3B,OAAO,EAAE,MAAM,kBAAkB;AAAA,IACjC,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG;AAAA,EAAA,CACrC,CAAC;AAEH,CAAA;AAEK,MAAO,oCAAoC,YAAW;AAAA,EAC3D,MAAM,YACL,MAAyC;AAEzC,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,+BACA,IAAI;AAGL,UAAM,EAAE,MAAM,OAAA,IAAW,iBAAiB,eAAe,UAAU;AAE5D,WAAA;AAAA,MACN,WAAW,KAAK,KAAO,EAAA,QAAQ,CAAC,SAC/B,KAAK,UAAU,IAAI,CAACA,QAAO;AAAA,QAC1B,OAAOA,GAAE;AAAA,QACT,aAAaA,GAAE;AAAA,QACd,CAAC;AAAA,MAEJ;AAAA,IAAA;AAAA,EAEF;AAAA,EACA,MAAM,aACL,MAA0C;AAE1C,6BAAyB,KAAK,wBAAwB;AAGtD,UAAM,iBAAiB,MAAM,KAAK,yBAAyB,SAC1D,+BACA,IAAI;AAEC,UAAA,EAAE,MAAM,UAAU,QAAQ,eAA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from "io-ts";
|
|
2
|
-
import { HookError } from "@slicemachine/plugin-kit";
|
|
3
|
-
import { BaseManager } from "../BaseManager";
|
|
4
|
-
import { DecodeError } from "../../lib/DecodeError";
|
|
5
|
-
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
|
|
6
|
-
import { decodeHookResult } from "../../lib/decodeHookResult";
|
|
7
|
-
import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
8
|
-
import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
|
|
9
|
-
|
|
10
|
-
type SliceTemplateLibraryManagerReadLibraryReturnType = {
|
|
11
|
-
templates: {
|
|
12
|
-
model: SharedSlice;
|
|
13
|
-
screenshots: Record<string, Buffer>;
|
|
14
|
-
}[];
|
|
15
|
-
errors: (DecodeError | HookError)[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type SliceTemplateLibraryManagerCreateSlicesReturnType = {
|
|
19
|
-
data?: {
|
|
20
|
-
sliceIDs: string[];
|
|
21
|
-
};
|
|
22
|
-
errors: (DecodeError | HookError)[];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type SliceTemplateLibraryReadLibraryData = {
|
|
26
|
-
templateIDs?: string[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type SliceTemplateLibraryCreateSlicesData = SliceTemplateLibraryReadLibraryData;
|
|
30
|
-
|
|
31
|
-
const readHookCodec = t.type({
|
|
32
|
-
templates: t.array(
|
|
33
|
-
t.type({
|
|
34
|
-
model: SharedSlice,
|
|
35
|
-
createComponentContents: t.Function,
|
|
36
|
-
mocks: t.array(SharedSliceContent),
|
|
37
|
-
screenshots: t.record(t.string, t.any),
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export class SliceTemplateLibraryManager extends BaseManager {
|
|
43
|
-
async readLibrary(
|
|
44
|
-
args: SliceTemplateLibraryReadLibraryData,
|
|
45
|
-
): Promise<SliceTemplateLibraryManagerReadLibraryReturnType> {
|
|
46
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
47
|
-
|
|
48
|
-
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
49
|
-
"slice-template-library:read",
|
|
50
|
-
args,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const { data, errors } = decodeHookResult(readHookCodec, hookResult);
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
templates: data.flat().flatMap((item) =>
|
|
57
|
-
item.templates.map((t) => ({
|
|
58
|
-
model: t.model,
|
|
59
|
-
screenshots: t.screenshots,
|
|
60
|
-
})),
|
|
61
|
-
),
|
|
62
|
-
errors,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async createSlices(
|
|
66
|
-
args: SliceTemplateLibraryCreateSlicesData,
|
|
67
|
-
): Promise<SliceTemplateLibraryManagerCreateSlicesReturnType> {
|
|
68
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
69
|
-
|
|
70
|
-
// Reading all available slice templates
|
|
71
|
-
const hookReadResult = await this.sliceMachinePluginRunner.callHook(
|
|
72
|
-
"slice-template-library:read",
|
|
73
|
-
args,
|
|
74
|
-
);
|
|
75
|
-
const { data: readData, errors: readErrors } = decodeHookResult(
|
|
76
|
-
readHookCodec,
|
|
77
|
-
hookReadResult,
|
|
78
|
-
);
|
|
79
|
-
const templates = readData.flat().flatMap((item) => item.templates);
|
|
80
|
-
if (readErrors.length > 0) {
|
|
81
|
-
return {
|
|
82
|
-
errors: readErrors,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Extract all existing slice IDs into an array
|
|
87
|
-
const { models: allSlices, errors: readAllSlicesErrors } =
|
|
88
|
-
await this.slices.readAllSlices();
|
|
89
|
-
if (readAllSlicesErrors.length > 0) {
|
|
90
|
-
return {
|
|
91
|
-
errors: readAllSlicesErrors,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
const existingIds: string[] = allSlices.map((slice) => slice.model.id);
|
|
95
|
-
|
|
96
|
-
// Create a function to get the next available ID based on the baseId
|
|
97
|
-
const getNextAvailableSlice = (baseId: string) => {
|
|
98
|
-
let nextId = baseId;
|
|
99
|
-
let counter = 1;
|
|
100
|
-
while (existingIds.includes(nextId)) {
|
|
101
|
-
counter++;
|
|
102
|
-
nextId = `${baseId}_${counter}`;
|
|
103
|
-
}
|
|
104
|
-
existingIds.push(nextId);
|
|
105
|
-
|
|
106
|
-
return { id: nextId, counter };
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// Extract the slices to create from the template ids given in args
|
|
110
|
-
const slicesToCreate = templates.map((template) => {
|
|
111
|
-
const { id, counter } = getNextAvailableSlice(template.model.id);
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
...template,
|
|
115
|
-
model: {
|
|
116
|
-
...template.model,
|
|
117
|
-
id,
|
|
118
|
-
name:
|
|
119
|
-
counter > 1 ? template.model.name + counter : template.model.name,
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Get target library
|
|
125
|
-
// Note: We only support adding template to the first library at the moment
|
|
126
|
-
const { libraries, errors: readAllSliceLibrariesErrors } =
|
|
127
|
-
await this.slices.readAllSliceLibraries();
|
|
128
|
-
if (readAllSliceLibrariesErrors.length > 0) {
|
|
129
|
-
return {
|
|
130
|
-
errors: readAllSliceLibrariesErrors,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const targetLibrary = libraries[0];
|
|
134
|
-
|
|
135
|
-
// Initiate the slice creation process for all slices
|
|
136
|
-
const creationPromises = slicesToCreate.map((slice) => {
|
|
137
|
-
return this.slices.createSlice({
|
|
138
|
-
libraryID: targetLibrary.libraryID,
|
|
139
|
-
model: slice.model,
|
|
140
|
-
componentContents: slice.createComponentContents(slice.model),
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Wait for all slices to be created
|
|
145
|
-
const creationResults = await Promise.all(creationPromises);
|
|
146
|
-
// Check for any errors in the creation results
|
|
147
|
-
const creationErrors = creationResults.flatMap((result) => result.errors);
|
|
148
|
-
if (creationErrors.length > 0) {
|
|
149
|
-
return {
|
|
150
|
-
errors: creationErrors,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const mocksPromises = slicesToCreate.map((slice) => {
|
|
155
|
-
return this.slices.updateSliceMocks({
|
|
156
|
-
libraryID: targetLibrary.libraryID,
|
|
157
|
-
sliceID: slice.model.id,
|
|
158
|
-
mocks: slice.mocks,
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const mocksResults = await Promise.all(mocksPromises);
|
|
163
|
-
|
|
164
|
-
const sliceScreenshotsPromises = slicesToCreate.map((slice) => {
|
|
165
|
-
const screenshotPromises = Object.entries(slice.screenshots).map(
|
|
166
|
-
([variationID, data]) => {
|
|
167
|
-
return this.slices.updateSliceScreenshot({
|
|
168
|
-
libraryID: targetLibrary.libraryID,
|
|
169
|
-
sliceID: slice.model.id,
|
|
170
|
-
variationID,
|
|
171
|
-
data,
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
return Promise.all(screenshotPromises);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const sliceScreenshotsResults = await Promise.all(sliceScreenshotsPromises);
|
|
180
|
-
const mocksErrors = mocksResults.flatMap((result) => result.errors);
|
|
181
|
-
const screenshotErrors = sliceScreenshotsResults.flatMap((result) =>
|
|
182
|
-
result.flat().flatMap((r) => r.errors),
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
// Extract the slice IDs from the creation results (assuming each result has an ID)
|
|
186
|
-
const sliceIDs = slicesToCreate.map((slice) => slice.model.id);
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
errors: [...mocksErrors, ...screenshotErrors],
|
|
190
|
-
data: {
|
|
191
|
-
sliceIDs,
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|