@chili-publish/studio-sdk 1.44.0 → 1.45.0
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/_bundles/main.js +2 -2
- package/_bundles/main.js.map +1 -1
- package/lib/src/controllers/BrandKitController.cjs.js +13 -64
- package/lib/src/controllers/BrandKitController.cjs.js.map +1 -1
- package/lib/src/controllers/BrandKitController.d.ts +22 -30
- package/lib/src/controllers/BrandKitController.es.js +13 -64
- package/lib/src/controllers/BrandKitController.es.js.map +1 -1
- package/lib/src/controllers/ComponentController.cjs.js.map +1 -1
- package/lib/src/controllers/ComponentController.d.ts +1 -1
- package/lib/src/controllers/ComponentController.es.js.map +1 -1
- package/lib/src/controllers/ConnectorController.cjs.js.map +1 -1
- package/lib/src/controllers/ConnectorController.d.ts +5 -5
- package/lib/src/controllers/ConnectorController.es.js.map +1 -1
- package/lib/src/exceptions/AsyncExceptions.cjs.js.map +1 -1
- package/lib/src/exceptions/AsyncExceptions.d.ts +1 -0
- package/lib/src/exceptions/AsyncExceptions.es.js.map +1 -1
- package/lib/src/exceptions/Helpers.cjs.js.map +1 -1
- package/lib/src/exceptions/Helpers.es.js.map +1 -1
- package/lib/src/index.cjs.js +3 -2
- package/lib/src/index.cjs.js.map +1 -1
- package/lib/src/index.d.ts +2 -1
- package/lib/src/index.es.js +2 -1
- package/lib/src/next/NextInitiator.cjs.js +0 -2
- package/lib/src/next/NextInitiator.cjs.js.map +1 -1
- package/lib/src/next/NextInitiator.d.ts +0 -2
- package/lib/src/next/NextInitiator.es.js +0 -2
- package/lib/src/next/NextInitiator.es.js.map +1 -1
- package/lib/src/next/index.d.ts +0 -1
- package/lib/src/sdk/editor-engine.json.cjs.js +1 -1
- package/lib/src/sdk/editor-engine.json.es.js +1 -1
- package/lib/src/sdk/package.json.cjs.js +1 -1
- package/lib/src/sdk/package.json.es.js +1 -1
- package/lib/src/sdk.cjs.js +116 -78
- package/lib/src/sdk.cjs.js.map +1 -1
- package/lib/src/sdk.d.ts +52 -34
- package/lib/src/sdk.es.js +116 -78
- package/lib/src/sdk.es.js.map +1 -1
- package/lib/src/types/BrandKitTypes.d.ts +70 -108
- package/lib/src/types/ColorStyleTypes.cjs.js +10 -0
- package/lib/src/types/ColorStyleTypes.cjs.js.map +1 -1
- package/lib/src/types/ColorStyleTypes.es.js +10 -0
- package/lib/src/types/ColorStyleTypes.es.js.map +1 -1
- package/lib/src/types/CommonTypes.cjs.js +1 -0
- package/lib/src/types/CommonTypes.cjs.js.map +1 -1
- package/lib/src/types/CommonTypes.d.ts +2 -1
- package/lib/src/types/CommonTypes.es.js +1 -0
- package/lib/src/types/CommonTypes.es.js.map +1 -1
- package/lib/src/types/ConnectorTypes.cjs.js +6 -2
- package/lib/src/types/ConnectorTypes.cjs.js.map +1 -1
- package/lib/src/types/ConnectorTypes.d.ts +10 -1
- package/lib/src/types/ConnectorTypes.es.js +6 -2
- package/lib/src/types/ConnectorTypes.es.js.map +1 -1
- package/lib/src/types/FrameTypes.cjs.js.map +1 -1
- package/lib/src/types/FrameTypes.d.ts +1 -4
- package/lib/src/types/FrameTypes.es.js.map +1 -1
- package/lib/src/types/MethodInvocationTypes.d.ts +27 -0
- package/lib/src/utils/EngineEventTrigger.cjs.js +4 -1
- package/lib/src/utils/EngineEventTrigger.cjs.js.map +1 -1
- package/lib/src/utils/EngineEventTrigger.d.ts +2 -1
- package/lib/src/utils/EngineEventTrigger.es.js +5 -2
- package/lib/src/utils/EngineEventTrigger.es.js.map +1 -1
- package/lib/src/utils/MethodInstrumentation.cjs.js +176 -0
- package/lib/src/utils/MethodInstrumentation.cjs.js.map +1 -0
- package/lib/src/utils/MethodInstrumentation.d.ts +10 -0
- package/lib/src/utils/MethodInstrumentation.es.js +176 -0
- package/lib/src/utils/MethodInstrumentation.es.js.map +1 -0
- package/lib/src/utils/SdkEvent.cjs.js +29 -0
- package/lib/src/utils/SdkEvent.cjs.js.map +1 -0
- package/lib/src/utils/SdkEvent.d.ts +13 -0
- package/lib/src/utils/SdkEvent.es.js +29 -0
- package/lib/src/utils/SdkEvent.es.js.map +1 -0
- package/lib/src/utils/SdkEvents.cjs.js +11 -0
- package/lib/src/utils/SdkEvents.cjs.js.map +1 -0
- package/lib/src/utils/SdkEvents.d.ts +19 -0
- package/lib/src/utils/SdkEvents.es.js +11 -0
- package/lib/src/utils/SdkEvents.es.js.map +1 -0
- package/package.json +1 -1
- package/lib/src/next/controllers/BrandKitController.cjs.js +0 -34
- package/lib/src/next/controllers/BrandKitController.cjs.js.map +0 -1
- package/lib/src/next/controllers/BrandKitController.d.ts +0 -24
- package/lib/src/next/controllers/BrandKitController.es.js +0 -34
- package/lib/src/next/controllers/BrandKitController.es.js.map +0 -1
- package/lib/src/next/types/BrandKitTypes.d.ts +0 -52
- package/lib/src/utils/BrandKitAdapter.cjs.js +0 -42
- package/lib/src/utils/BrandKitAdapter.cjs.js.map +0 -1
- package/lib/src/utils/BrandKitAdapter.d.ts +0 -9
- package/lib/src/utils/BrandKitAdapter.es.js +0 -42
- package/lib/src/utils/BrandKitAdapter.es.js.map +0 -1
|
@@ -8,7 +8,6 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
8
8
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
9
9
|
var _editorAPI;
|
|
10
10
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
11
|
-
const BrandKitAdapter = require("../utils/BrandKitAdapter.cjs.js");
|
|
12
11
|
const EditorResponseData = require("../utils/EditorResponseData.cjs.js");
|
|
13
12
|
class BrandKitController {
|
|
14
13
|
/**
|
|
@@ -41,16 +40,7 @@ class BrandKitController {
|
|
|
41
40
|
};
|
|
42
41
|
this.get = async () => {
|
|
43
42
|
const res = await __privateGet(this, _editorAPI);
|
|
44
|
-
|
|
45
|
-
const response = EditorResponseData.getEditorResponseData(result);
|
|
46
|
-
const engineData = response.parsedData;
|
|
47
|
-
if (engineData == null) {
|
|
48
|
-
throw new Error("Brand kit response has no data");
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
...response,
|
|
52
|
-
parsedData: BrandKitAdapter.engineBrandKitToStudioBrandKit(engineData)
|
|
53
|
-
};
|
|
43
|
+
return res.getBrandKit().then((result) => EditorResponseData.getEditorResponseData(result));
|
|
54
44
|
};
|
|
55
45
|
this.getAllMedia = async () => {
|
|
56
46
|
const res = await __privateGet(this, _editorAPI);
|
|
@@ -72,52 +62,13 @@ class BrandKitController {
|
|
|
72
62
|
const res = await __privateGet(this, _editorAPI);
|
|
73
63
|
return res.removeBrandKitMedia(name).then((result) => EditorResponseData.getEditorResponseData(result));
|
|
74
64
|
};
|
|
75
|
-
this.
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
const characterStyles = await this.characterStyleController.getAll();
|
|
83
|
-
const characterStylesList = characterStyles.parsedData || [];
|
|
84
|
-
const fonts = await this.fontController.getFontFamilies();
|
|
85
|
-
const fontsList = fonts.parsedData || [];
|
|
86
|
-
const media = await this.getAllMedia();
|
|
87
|
-
const mediaList = media.parsedData || [];
|
|
88
|
-
await this.undoManagerController.record("brandKit.remove", async (sdk2) => {
|
|
89
|
-
for (const color of colorsList) {
|
|
90
|
-
await sdk2.colorStyle.remove(color.id);
|
|
91
|
-
}
|
|
92
|
-
for (const gradient of gradientsList) {
|
|
93
|
-
await sdk2.gradientStyle.remove(gradient.id);
|
|
94
|
-
}
|
|
95
|
-
for (const style of paragraphStylesList) {
|
|
96
|
-
await sdk2.paragraphStyle.remove(style.id);
|
|
97
|
-
}
|
|
98
|
-
for (const style of characterStylesList) {
|
|
99
|
-
await sdk2.characterStyle.remove(style.id);
|
|
100
|
-
}
|
|
101
|
-
for (const font of fontsList) {
|
|
102
|
-
await sdk2.font.removeFontFamily(font.id);
|
|
103
|
-
}
|
|
104
|
-
for (const media2 of mediaList) {
|
|
105
|
-
await this.removeMedia(media2.name);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
this.set = async (studioBrandKit) => {
|
|
110
|
-
const res = await __privateGet(this, _editorAPI);
|
|
111
|
-
const result = await res.setBrandKit(JSON.stringify(studioBrandKit.brandKit));
|
|
112
|
-
const response = EditorResponseData.getEditorResponseData(result);
|
|
113
|
-
const engineData = response.parsedData;
|
|
114
|
-
if (engineData == null) {
|
|
115
|
-
throw new Error("Brand kit set response has no data");
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
...response,
|
|
119
|
-
parsedData: BrandKitAdapter.engineBrandKitToBrandKitInternal(engineData)
|
|
120
|
-
};
|
|
65
|
+
this.set = async (apiBrandKit) => {
|
|
66
|
+
const res = await __privateGet(this, _editorAPI);
|
|
67
|
+
return res.setBrandKit(JSON.stringify(apiBrandKit)).then((result) => EditorResponseData.getEditorResponseData(result));
|
|
68
|
+
};
|
|
69
|
+
this.sync = async (apiBrandKit) => {
|
|
70
|
+
const res = await __privateGet(this, _editorAPI);
|
|
71
|
+
return res.syncBrandKit(JSON.stringify(apiBrandKit)).then((result) => EditorResponseData.getEditorResponseData(result));
|
|
121
72
|
};
|
|
122
73
|
this.isAutoSync = async () => {
|
|
123
74
|
const res = await __privateGet(this, _editorAPI);
|
|
@@ -127,14 +78,12 @@ class BrandKitController {
|
|
|
127
78
|
const res = await __privateGet(this, _editorAPI);
|
|
128
79
|
return res.enableBrandKitAutoSync(enableAutoSync).then((result) => EditorResponseData.getEditorResponseData(result));
|
|
129
80
|
};
|
|
81
|
+
this.switchTheme = async (themeName) => {
|
|
82
|
+
const res = await __privateGet(this, _editorAPI);
|
|
83
|
+
return res.switchBrandKitTheme(themeName).then((result) => EditorResponseData.getEditorResponseData(result));
|
|
84
|
+
};
|
|
130
85
|
__privateSet(this, _editorAPI, editorAPI);
|
|
131
|
-
this.
|
|
132
|
-
this.gradientStyleController = sdk.gradientStyle;
|
|
133
|
-
this.fontController = sdk.font;
|
|
134
|
-
this.mediaController = sdk.mediaConnector;
|
|
135
|
-
this.paragraphStyleController = sdk.paragraphStyle;
|
|
136
|
-
this.characterStyleController = sdk.characterStyle;
|
|
137
|
-
this.undoManagerController = sdk.undoManager;
|
|
86
|
+
this.sdk = sdk;
|
|
138
87
|
}
|
|
139
88
|
}
|
|
140
89
|
_editorAPI = new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrandKitController.cjs.js","sources":["../../../src/controllers/BrandKitController.ts"],"sourcesContent":["import SDK from '..';\nimport {\n BrandKitMedia,\n EngineBrandKit,\n StudioBrandKit,\n} from '../types/BrandKitTypes';\nimport { EditorAPI, Id } from '../types/CommonTypes';\nimport { engineBrandKitToBrandKitInternal, engineBrandKitToStudioBrandKit } from '../utils/BrandKitAdapter';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\nimport { CharacterStyleController } from './CharacterStyleController';\nimport { ColorStyleController } from './ColorStyleController';\nimport { FontController } from './FontController';\nimport { GradientStyleController } from './GradientStyleController';\nimport { MediaConnectorController } from './MediaConnectorController';\nimport { ParagraphStyleController } from './ParagraphStyleController';\nimport { UndoManagerController } from './UndoManagerController';\n\n/**\n * The BrandKitController is responsible for all communication regarding Brand Kits.\n * Methods inside this controller can be called by `window.SDK.brandKit.{method-name}`\n */\n\nexport class BrandKitController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI, sdk: SDK) {\n this.#editorAPI = editorAPI;\n this.colorStyleController = sdk.colorStyle;\n this.gradientStyleController = sdk.gradientStyle;\n this.fontController = sdk.font;\n this.mediaController = sdk.mediaConnector;\n this.paragraphStyleController = sdk.paragraphStyle;\n this.characterStyleController = sdk.characterStyle;\n\n this.undoManagerController = sdk.undoManager;\n }\n\n private colorStyleController: ColorStyleController;\n\n private gradientStyleController: GradientStyleController;\n\n private fontController: FontController;\n\n private mediaController: MediaConnectorController;\n\n private paragraphStyleController: ParagraphStyleController;\n\n private characterStyleController: CharacterStyleController;\n\n private undoManagerController: UndoManagerController;\n\n /**\n * This method returns the current brand kit id.\n * @returns current brand kit id\n */\n getId = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitId().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit version.\n * @returns current brand kit version\n */\n getVersion = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitVersion().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit name.\n * @returns current brand kit name\n */\n getName = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitName().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method renames the brand kit.\n * @param newName - The new name for the brand kit\n * @returns\n */\n rename = async (newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKit(newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method updates both the brand kit id and version.\n * @param id - The new brand kit id\n * @param version - The new brand kit version\n * @returns\n */\n updateIdAndVersion = async (id: string, version: string) => {\n const res = await this.#editorAPI;\n return res.updateBrandKitIdAndVersion(id, version).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method returns the local brandkit\n * @returns brandkit with all assigned resources\n */\n get = async () => {\n const res = await this.#editorAPI;\n const result = await res.getBrandKit();\n const response = getEditorResponseData<EngineBrandKit>(result);\n const engineData = response.parsedData;\n if (engineData == null) {\n throw new Error('Brand kit response has no data');\n }\n return {\n ...response,\n parsedData: engineBrandKitToStudioBrandKit(engineData),\n };\n };\n\n /**\n * This method returns all media items in the brand kit\n * @returns list of media items in the brand kit\n */\n getAllMedia = async () => {\n const res = await this.#editorAPI;\n return res.getAllBrandKitMedia().then((result) => getEditorResponseData<BrandKitMedia[]>(result));\n };\n\n /**\n * This method adds a media item to the brand kit\n * @param name - The name of the media item\n * @param remoteConnectorId - The remote connector ID\n * @param assetId - The asset ID of the media item\n * @returns\n */\n addMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .addBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<Id>(result));\n };\n\n /**\n * This method updates an existing media item in the brand kit\n * @param name - The name of the media item to update\n * @param remoteConnectorId - The new remote connector ID\n * @param assetId - The new asset ID\n * @returns\n */\n updateMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .updateBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method renames an existing media item in the brand kit\n * @param name - The name of the media item to rename\n * @param newName - The new name for the media item\n * @returns\n */\n renameMedia = async (name: string, newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKitMedia(name, newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method removes a media item from the brand kit\n * @param name - The name of the media item to remove\n * @returns\n */\n removeMedia = async (name: string) => {\n const res = await this.#editorAPI;\n return res.removeBrandKitMedia(name).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method removes a brand kit and all related resources assigned to it\n * @returns\n */\n remove = async () => {\n const colors = await this.colorStyleController.getAll();\n const colorsList = colors.parsedData || [];\n\n const gradients = await this.gradientStyleController.getAll();\n const gradientsList = gradients.parsedData || [];\n\n const paragraphStyles = await this.paragraphStyleController.getAll();\n const paragraphStylesList = paragraphStyles.parsedData || [];\n\n const characterStyles = await this.characterStyleController.getAll();\n const characterStylesList = characterStyles.parsedData || [];\n\n const fonts = await this.fontController.getFontFamilies();\n const fontsList = fonts.parsedData || [];\n\n const media = await this.getAllMedia();\n const mediaList = media.parsedData || [];\n\n await this.undoManagerController.record('brandKit.remove', async (sdk) => {\n for (const color of colorsList) {\n await sdk.colorStyle.remove(color.id);\n }\n for (const gradient of gradientsList) {\n await sdk.gradientStyle.remove(gradient.id);\n }\n for (const style of paragraphStylesList) {\n await sdk.paragraphStyle.remove(style.id);\n }\n for (const style of characterStylesList) {\n await sdk.characterStyle.remove(style.id);\n }\n for (const font of fontsList) {\n await sdk.font.removeFontFamily(font.id);\n }\n for (const media of mediaList) {\n await this.removeMedia(media.name);\n }\n });\n };\n\n /**\n * @experimental This method updates a brand kit and all related resources assigned to it\n * @param studioBrandKit the content of the brand kit\n * @returns\n */\n set = async (studioBrandKit: StudioBrandKit) => {\n const res = await this.#editorAPI;\n const result = await res.setBrandKit(JSON.stringify(studioBrandKit.brandKit));\n const response = getEditorResponseData<EngineBrandKit>(result);\n const engineData = response.parsedData;\n if (engineData == null) {\n throw new Error('Brand kit set response has no data');\n }\n return {\n ...response,\n parsedData: engineBrandKitToBrandKitInternal(engineData),\n };\n };\n\n\n /**\n * This method returns the value indicating whether the brand kit auto-sync is enabled or not\n * It is up to the integrator to implement this auto-sync functionality, this method only is an indication if it should be done or not.\n \n * @returns boolean indicating sync status\n */\n isAutoSync = async () => {\n const res = await this.#editorAPI;\n return res.isBrandKitAutoSync().then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * This method enables or disables brand kit auto-sync\n * @param enableAutoSync boolean indicating auto-sync status\n * @returns boolean indicating the result of the operation\n */\n enableAutoSync = async (enableAutoSync: boolean) => {\n const res = await this.#editorAPI;\n return res.enableBrandKitAutoSync(enableAutoSync).then((result) => getEditorResponseData<boolean>(result));\n };\n}\n"],"names":["getEditorResponseData","engineBrandKitToStudioBrandKit","sdk","media","engineBrandKitToBrandKitInternal"],"mappings":";;;;;;;;;;;;AAsBO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAS5B,YAAY,WAAsB,KAAU;AAL5C;AAAA;AAAA;AAAA;AAmCA,SAAA,QAAQ,YAAY;AAChB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,gBAAgB,KAAK,CAAC,WAAWA,mBAAAA,sBAA8B,MAAM,CAAC;AAAA,IACrF;AAMA,SAAA,aAAa,YAAY;AACrB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,I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OJ;AAhPI;;"}
|
|
1
|
+
{"version":3,"file":"BrandKitController.cjs.js","sources":["../../../src/controllers/BrandKitController.ts"],"sourcesContent":["import SDK from '..';\nimport { BrandKitMedia, BrandKit, APIBrandKit } from '../types/BrandKitTypes';\nimport { EditorAPI, Id } from '../types/CommonTypes';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\n\n/**\n * The BrandKitController is responsible for all communication regarding Brand Kits.\n * Methods inside this controller can be called by `window.SDK.brandKit.{method-name}`\n */\n\nexport class BrandKitController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n private sdk: SDK;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI, sdk: SDK) {\n this.#editorAPI = editorAPI;\n this.sdk = sdk;\n }\n\n /**\n * This method returns the current brand kit id.\n * @returns current brand kit id\n */\n getId = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitId().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit version.\n * @returns current brand kit version\n */\n getVersion = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitVersion().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit name.\n * @returns current brand kit name\n */\n getName = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitName().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method renames the brand kit.\n * @param newName - The new name for the brand kit\n * @returns\n */\n rename = async (newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKit(newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method updates both the brand kit id and version.\n * @param id - The new brand kit id\n * @param version - The new brand kit version\n * @returns\n */\n updateIdAndVersion = async (id: string, version: string) => {\n const res = await this.#editorAPI;\n return res.updateBrandKitIdAndVersion(id, version).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method returns the local brand kit\n * @returns brand kit with all assigned resources\n */\n get = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKit().then((result) => getEditorResponseData<BrandKit>(result));\n };\n\n /**\n * This method returns all media items in the brand kit\n * @returns list of media items in the brand kit\n */\n getAllMedia = async () => {\n const res = await this.#editorAPI;\n return res.getAllBrandKitMedia().then((result) => getEditorResponseData<BrandKitMedia[]>(result));\n };\n\n /**\n * This method adds a media item to the brand kit\n * @param name - The name of the media item\n * @param remoteConnectorId - The remote connector ID\n * @param assetId - The asset ID of the media item\n * @returns\n */\n addMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .addBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<Id>(result));\n };\n\n /**\n * This method updates an existing media item in the brand kit\n * @param name - The name of the media item to update\n * @param remoteConnectorId - The new remote connector ID\n * @param assetId - The new asset ID\n * @returns\n */\n updateMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .updateBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method renames an existing media item in the brand kit\n * @param name - The name of the media item to rename\n * @param newName - The new name for the media item\n * @returns\n */\n renameMedia = async (name: string, newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKitMedia(name, newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method removes a media item from the brand kit\n * @param name - The name of the media item to remove\n * @returns\n */\n removeMedia = async (name: string) => {\n const res = await this.#editorAPI;\n return res.removeBrandKitMedia(name).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method replaces the full brand kit and all related resources assigned to it\n * @param apiBrandKit the brand kit from the environment api\n * @returns the local brand kit\n */\n set = async (apiBrandKit: APIBrandKit) => {\n const res = await this.#editorAPI;\n return res.setBrandKit(JSON.stringify(apiBrandKit)).then((result) => getEditorResponseData<BrandKit>(result));\n };\n\n /**\n * @experimental This method syncs brand kit items and structure in place without replacing the existing brand kit\n * @param apiBrandKit the brand kit from the environment api\n * @returns boolean indicating whether the brand kit changed after the sync attempt\n */\n sync = async (apiBrandKit: APIBrandKit) => {\n const res = await this.#editorAPI;\n return res.syncBrandKit(JSON.stringify(apiBrandKit)).then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * This method returns the value indicating whether the brand kit auto-sync is enabled or not\n * It is up to the integrator to implement this auto-sync functionality, this method only is an indication if it should be done or not.\n \n * @returns boolean indicating sync status\n */\n isAutoSync = async () => {\n const res = await this.#editorAPI;\n return res.isBrandKitAutoSync().then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * This method enables or disables brand kit auto-sync\n * @param enableAutoSync boolean indicating auto-sync status\n * @returns boolean indicating the result of the operation\n */\n enableAutoSync = async (enableAutoSync: boolean) => {\n const res = await this.#editorAPI;\n return res.enableBrandKitAutoSync(enableAutoSync).then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * Switches the active brand kit theme.\n * @param themeName - Theme name\n * @returns\n */\n switchTheme = async (themeName: string) => {\n const res = await this.#editorAPI;\n return res.switchBrandKitTheme(themeName).then((result) => getEditorResponseData<null>(result));\n };\n}\n"],"names":["getEditorResponseData"],"mappings":";;;;;;;;;;;AAUO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAc5B,YAAY,WAAsB,KAAU;AAV5C;AAAA;AAAA;AAAA;AAmBA,SAAA,QAAQ,YAAY;AAChB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,gBAAgB,KAAK,CAAC,WAAWA,mBAAAA,sBAA8B,MAAM,CAAC;AAAA,IACrF;AAMA,SAAA,aAAa,YAAY;AACrB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,qBAAqB,KAAK,CAAC,WAAWA,mBAAAA,sBAA8B,MAAM,CAAC;AAAA,IAC1F;AAMA,SAAA,UAAU,YAAY;AAClB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,kBAAkB,KAAK,CAAC,WAAWA,mBAAAA,sBAA8B,MAAM,CAAC;AAA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,oBAAoB,IAAI,EAAE,KAAK,CAAC,WAAWA,yCAA4B,MAAM,CAAC;AAAA,IAC7F;AAOA,SAAA,MAAM,OAAO,gBAA6B;AACtC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,YAAY,KAAK,UAAU,WAAW,CAAC,EAAE,KAAK,CAAC,WAAWA,mBAAAA,sBAAgC,MAAM,CAAC;AAAA,IAChH;AAOA,SAAA,OAAO,OAAO,gBAA6B;AACvC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,aAAa,KAAK,UAAU,WAAW,CAAC,EAAE,KAAK,CAAC,WAAWA,mBAAAA,sBAA+B,MAAM,CAAC;AAAA,IAChH;AAQA,SAAA,aAAa,YAAY;AACrB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,qBAAqB,KAAK,CAAC,WAAWA,mBAAAA,sBAA+B,MAAM,CAAC;AAAA,IAC3F;AAOA,SAAA,iBAAiB,OAAO,mBAA4B;AAChD,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,uBAAuB,cAAc,EAAE,KAAK,CAAC,WAAWA,yCAA+B,MAAM,CAAC;AAAA,IAC7G;AAOA,SAAA,cAAc,OAAO,cAAsB;AACvC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,oBAAoB,SAAS,EAAE,KAAK,CAAC,WAAWA,yCAA4B,MAAM,CAAC;AAAA,IAClG;AAxKI,uBAAK,YAAa;AAClB,SAAK,MAAM;AAAA,EACf;AAuKJ;AApLI;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as SDK } from '..';
|
|
2
|
-
import { BrandKitMedia,
|
|
2
|
+
import { BrandKitMedia, BrandKit, APIBrandKit } from '../types/BrandKitTypes';
|
|
3
3
|
import { EditorAPI, Id } from '../types/CommonTypes';
|
|
4
4
|
/**
|
|
5
5
|
* The BrandKitController is responsible for all communication regarding Brand Kits.
|
|
@@ -7,17 +7,14 @@ import { EditorAPI, Id } from '../types/CommonTypes';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class BrandKitController {
|
|
9
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
private sdk;
|
|
10
14
|
/**
|
|
11
15
|
* @ignore
|
|
12
16
|
*/
|
|
13
17
|
constructor(editorAPI: EditorAPI, sdk: SDK);
|
|
14
|
-
private colorStyleController;
|
|
15
|
-
private gradientStyleController;
|
|
16
|
-
private fontController;
|
|
17
|
-
private mediaController;
|
|
18
|
-
private paragraphStyleController;
|
|
19
|
-
private characterStyleController;
|
|
20
|
-
private undoManagerController;
|
|
21
18
|
/**
|
|
22
19
|
* This method returns the current brand kit id.
|
|
23
20
|
* @returns current brand kit id
|
|
@@ -47,16 +44,10 @@ export declare class BrandKitController {
|
|
|
47
44
|
*/
|
|
48
45
|
updateIdAndVersion: (id: string, version: string) => Promise<import('..').EditorResponse<null>>;
|
|
49
46
|
/**
|
|
50
|
-
* @experimental This method returns the local
|
|
51
|
-
* @returns
|
|
47
|
+
* @experimental This method returns the local brand kit
|
|
48
|
+
* @returns brand kit with all assigned resources
|
|
52
49
|
*/
|
|
53
|
-
get: () => Promise<
|
|
54
|
-
parsedData: StudioBrandKit;
|
|
55
|
-
success: boolean;
|
|
56
|
-
status: number;
|
|
57
|
-
data?: string | null;
|
|
58
|
-
error?: import('../types/CommonTypes').EditorResponseError | null;
|
|
59
|
-
}>;
|
|
50
|
+
get: () => Promise<import('..').EditorResponse<BrandKit>>;
|
|
60
51
|
/**
|
|
61
52
|
* This method returns all media items in the brand kit
|
|
62
53
|
* @returns list of media items in the brand kit
|
|
@@ -92,22 +83,17 @@ export declare class BrandKitController {
|
|
|
92
83
|
*/
|
|
93
84
|
removeMedia: (name: string) => Promise<import('..').EditorResponse<null>>;
|
|
94
85
|
/**
|
|
95
|
-
* @experimental This method
|
|
96
|
-
* @
|
|
86
|
+
* @experimental This method replaces the full brand kit and all related resources assigned to it
|
|
87
|
+
* @param apiBrandKit the brand kit from the environment api
|
|
88
|
+
* @returns the local brand kit
|
|
97
89
|
*/
|
|
98
|
-
|
|
90
|
+
set: (apiBrandKit: APIBrandKit) => Promise<import('..').EditorResponse<BrandKit>>;
|
|
99
91
|
/**
|
|
100
|
-
* @experimental This method
|
|
101
|
-
* @param
|
|
102
|
-
* @returns
|
|
92
|
+
* @experimental This method syncs brand kit items and structure in place without replacing the existing brand kit
|
|
93
|
+
* @param apiBrandKit the brand kit from the environment api
|
|
94
|
+
* @returns boolean indicating whether the brand kit changed after the sync attempt
|
|
103
95
|
*/
|
|
104
|
-
|
|
105
|
-
parsedData: import('../types/BrandKitTypes').BrandKitInternal;
|
|
106
|
-
success: boolean;
|
|
107
|
-
status: number;
|
|
108
|
-
data?: string | null;
|
|
109
|
-
error?: import('../types/CommonTypes').EditorResponseError | null;
|
|
110
|
-
}>;
|
|
96
|
+
sync: (apiBrandKit: APIBrandKit) => Promise<import('..').EditorResponse<boolean>>;
|
|
111
97
|
/**
|
|
112
98
|
* This method returns the value indicating whether the brand kit auto-sync is enabled or not
|
|
113
99
|
* It is up to the integrator to implement this auto-sync functionality, this method only is an indication if it should be done or not.
|
|
@@ -121,4 +107,10 @@ export declare class BrandKitController {
|
|
|
121
107
|
* @returns boolean indicating the result of the operation
|
|
122
108
|
*/
|
|
123
109
|
enableAutoSync: (enableAutoSync: boolean) => Promise<import('..').EditorResponse<boolean>>;
|
|
110
|
+
/**
|
|
111
|
+
* Switches the active brand kit theme.
|
|
112
|
+
* @param themeName - Theme name
|
|
113
|
+
* @returns
|
|
114
|
+
*/
|
|
115
|
+
switchTheme: (themeName: string) => Promise<import('..').EditorResponse<null>>;
|
|
124
116
|
}
|
|
@@ -6,7 +6,6 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
6
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
var _editorAPI;
|
|
9
|
-
import { engineBrandKitToStudioBrandKit, engineBrandKitToBrandKitInternal } from "../utils/BrandKitAdapter.es.js";
|
|
10
9
|
import { getEditorResponseData } from "../utils/EditorResponseData.es.js";
|
|
11
10
|
class BrandKitController {
|
|
12
11
|
/**
|
|
@@ -39,16 +38,7 @@ class BrandKitController {
|
|
|
39
38
|
};
|
|
40
39
|
this.get = async () => {
|
|
41
40
|
const res = await __privateGet(this, _editorAPI);
|
|
42
|
-
|
|
43
|
-
const response = getEditorResponseData(result);
|
|
44
|
-
const engineData = response.parsedData;
|
|
45
|
-
if (engineData == null) {
|
|
46
|
-
throw new Error("Brand kit response has no data");
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
...response,
|
|
50
|
-
parsedData: engineBrandKitToStudioBrandKit(engineData)
|
|
51
|
-
};
|
|
41
|
+
return res.getBrandKit().then((result) => getEditorResponseData(result));
|
|
52
42
|
};
|
|
53
43
|
this.getAllMedia = async () => {
|
|
54
44
|
const res = await __privateGet(this, _editorAPI);
|
|
@@ -70,52 +60,13 @@ class BrandKitController {
|
|
|
70
60
|
const res = await __privateGet(this, _editorAPI);
|
|
71
61
|
return res.removeBrandKitMedia(name).then((result) => getEditorResponseData(result));
|
|
72
62
|
};
|
|
73
|
-
this.
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
const characterStyles = await this.characterStyleController.getAll();
|
|
81
|
-
const characterStylesList = characterStyles.parsedData || [];
|
|
82
|
-
const fonts = await this.fontController.getFontFamilies();
|
|
83
|
-
const fontsList = fonts.parsedData || [];
|
|
84
|
-
const media = await this.getAllMedia();
|
|
85
|
-
const mediaList = media.parsedData || [];
|
|
86
|
-
await this.undoManagerController.record("brandKit.remove", async (sdk2) => {
|
|
87
|
-
for (const color of colorsList) {
|
|
88
|
-
await sdk2.colorStyle.remove(color.id);
|
|
89
|
-
}
|
|
90
|
-
for (const gradient of gradientsList) {
|
|
91
|
-
await sdk2.gradientStyle.remove(gradient.id);
|
|
92
|
-
}
|
|
93
|
-
for (const style of paragraphStylesList) {
|
|
94
|
-
await sdk2.paragraphStyle.remove(style.id);
|
|
95
|
-
}
|
|
96
|
-
for (const style of characterStylesList) {
|
|
97
|
-
await sdk2.characterStyle.remove(style.id);
|
|
98
|
-
}
|
|
99
|
-
for (const font of fontsList) {
|
|
100
|
-
await sdk2.font.removeFontFamily(font.id);
|
|
101
|
-
}
|
|
102
|
-
for (const media2 of mediaList) {
|
|
103
|
-
await this.removeMedia(media2.name);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
this.set = async (studioBrandKit) => {
|
|
108
|
-
const res = await __privateGet(this, _editorAPI);
|
|
109
|
-
const result = await res.setBrandKit(JSON.stringify(studioBrandKit.brandKit));
|
|
110
|
-
const response = getEditorResponseData(result);
|
|
111
|
-
const engineData = response.parsedData;
|
|
112
|
-
if (engineData == null) {
|
|
113
|
-
throw new Error("Brand kit set response has no data");
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
...response,
|
|
117
|
-
parsedData: engineBrandKitToBrandKitInternal(engineData)
|
|
118
|
-
};
|
|
63
|
+
this.set = async (apiBrandKit) => {
|
|
64
|
+
const res = await __privateGet(this, _editorAPI);
|
|
65
|
+
return res.setBrandKit(JSON.stringify(apiBrandKit)).then((result) => getEditorResponseData(result));
|
|
66
|
+
};
|
|
67
|
+
this.sync = async (apiBrandKit) => {
|
|
68
|
+
const res = await __privateGet(this, _editorAPI);
|
|
69
|
+
return res.syncBrandKit(JSON.stringify(apiBrandKit)).then((result) => getEditorResponseData(result));
|
|
119
70
|
};
|
|
120
71
|
this.isAutoSync = async () => {
|
|
121
72
|
const res = await __privateGet(this, _editorAPI);
|
|
@@ -125,14 +76,12 @@ class BrandKitController {
|
|
|
125
76
|
const res = await __privateGet(this, _editorAPI);
|
|
126
77
|
return res.enableBrandKitAutoSync(enableAutoSync).then((result) => getEditorResponseData(result));
|
|
127
78
|
};
|
|
79
|
+
this.switchTheme = async (themeName) => {
|
|
80
|
+
const res = await __privateGet(this, _editorAPI);
|
|
81
|
+
return res.switchBrandKitTheme(themeName).then((result) => getEditorResponseData(result));
|
|
82
|
+
};
|
|
128
83
|
__privateSet(this, _editorAPI, editorAPI);
|
|
129
|
-
this.
|
|
130
|
-
this.gradientStyleController = sdk.gradientStyle;
|
|
131
|
-
this.fontController = sdk.font;
|
|
132
|
-
this.mediaController = sdk.mediaConnector;
|
|
133
|
-
this.paragraphStyleController = sdk.paragraphStyle;
|
|
134
|
-
this.characterStyleController = sdk.characterStyle;
|
|
135
|
-
this.undoManagerController = sdk.undoManager;
|
|
84
|
+
this.sdk = sdk;
|
|
136
85
|
}
|
|
137
86
|
}
|
|
138
87
|
_editorAPI = new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrandKitController.es.js","sources":["../../../src/controllers/BrandKitController.ts"],"sourcesContent":["import SDK from '..';\nimport {\n BrandKitMedia,\n EngineBrandKit,\n StudioBrandKit,\n} from '../types/BrandKitTypes';\nimport { EditorAPI, Id } from '../types/CommonTypes';\nimport { engineBrandKitToBrandKitInternal, engineBrandKitToStudioBrandKit } from '../utils/BrandKitAdapter';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\nimport { CharacterStyleController } from './CharacterStyleController';\nimport { ColorStyleController } from './ColorStyleController';\nimport { FontController } from './FontController';\nimport { GradientStyleController } from './GradientStyleController';\nimport { MediaConnectorController } from './MediaConnectorController';\nimport { ParagraphStyleController } from './ParagraphStyleController';\nimport { UndoManagerController } from './UndoManagerController';\n\n/**\n * The BrandKitController is responsible for all communication regarding Brand Kits.\n * Methods inside this controller can be called by `window.SDK.brandKit.{method-name}`\n */\n\nexport class BrandKitController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI, sdk: SDK) {\n this.#editorAPI = editorAPI;\n this.colorStyleController = sdk.colorStyle;\n this.gradientStyleController = sdk.gradientStyle;\n this.fontController = sdk.font;\n this.mediaController = sdk.mediaConnector;\n this.paragraphStyleController = sdk.paragraphStyle;\n this.characterStyleController = sdk.characterStyle;\n\n this.undoManagerController = sdk.undoManager;\n }\n\n private colorStyleController: ColorStyleController;\n\n private gradientStyleController: GradientStyleController;\n\n private fontController: FontController;\n\n private mediaController: MediaConnectorController;\n\n private paragraphStyleController: ParagraphStyleController;\n\n private characterStyleController: CharacterStyleController;\n\n private undoManagerController: UndoManagerController;\n\n /**\n * This method returns the current brand kit id.\n * @returns current brand kit id\n */\n getId = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitId().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit version.\n * @returns current brand kit version\n */\n getVersion = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitVersion().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit name.\n * @returns current brand kit name\n */\n getName = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitName().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method renames the brand kit.\n * @param newName - The new name for the brand kit\n * @returns\n */\n rename = async (newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKit(newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method updates both the brand kit id and version.\n * @param id - The new brand kit id\n * @param version - The new brand kit version\n * @returns\n */\n updateIdAndVersion = async (id: string, version: string) => {\n const res = await this.#editorAPI;\n return res.updateBrandKitIdAndVersion(id, version).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method returns the local brandkit\n * @returns brandkit with all assigned resources\n */\n get = async () => {\n const res = await this.#editorAPI;\n const result = await res.getBrandKit();\n const response = getEditorResponseData<EngineBrandKit>(result);\n const engineData = response.parsedData;\n if (engineData == null) {\n throw new Error('Brand kit response has no data');\n }\n return {\n ...response,\n parsedData: engineBrandKitToStudioBrandKit(engineData),\n };\n };\n\n /**\n * This method returns all media items in the brand kit\n * @returns list of media items in the brand kit\n */\n getAllMedia = async () => {\n const res = await this.#editorAPI;\n return res.getAllBrandKitMedia().then((result) => getEditorResponseData<BrandKitMedia[]>(result));\n };\n\n /**\n * This method adds a media item to the brand kit\n * @param name - The name of the media item\n * @param remoteConnectorId - The remote connector ID\n * @param assetId - The asset ID of the media item\n * @returns\n */\n addMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .addBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<Id>(result));\n };\n\n /**\n * This method updates an existing media item in the brand kit\n * @param name - The name of the media item to update\n * @param remoteConnectorId - The new remote connector ID\n * @param assetId - The new asset ID\n * @returns\n */\n updateMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .updateBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method renames an existing media item in the brand kit\n * @param name - The name of the media item to rename\n * @param newName - The new name for the media item\n * @returns\n */\n renameMedia = async (name: string, newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKitMedia(name, newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method removes a media item from the brand kit\n * @param name - The name of the media item to remove\n * @returns\n */\n removeMedia = async (name: string) => {\n const res = await this.#editorAPI;\n return res.removeBrandKitMedia(name).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method removes a brand kit and all related resources assigned to it\n * @returns\n */\n remove = async () => {\n const colors = await this.colorStyleController.getAll();\n const colorsList = colors.parsedData || [];\n\n const gradients = await this.gradientStyleController.getAll();\n const gradientsList = gradients.parsedData || [];\n\n const paragraphStyles = await this.paragraphStyleController.getAll();\n const paragraphStylesList = paragraphStyles.parsedData || [];\n\n const characterStyles = await this.characterStyleController.getAll();\n const characterStylesList = characterStyles.parsedData || [];\n\n const fonts = await this.fontController.getFontFamilies();\n const fontsList = fonts.parsedData || [];\n\n const media = await this.getAllMedia();\n const mediaList = media.parsedData || [];\n\n await this.undoManagerController.record('brandKit.remove', async (sdk) => {\n for (const color of colorsList) {\n await sdk.colorStyle.remove(color.id);\n }\n for (const gradient of gradientsList) {\n await sdk.gradientStyle.remove(gradient.id);\n }\n for (const style of paragraphStylesList) {\n await sdk.paragraphStyle.remove(style.id);\n }\n for (const style of characterStylesList) {\n await sdk.characterStyle.remove(style.id);\n }\n for (const font of fontsList) {\n await sdk.font.removeFontFamily(font.id);\n }\n for (const media of mediaList) {\n await this.removeMedia(media.name);\n }\n });\n };\n\n /**\n * @experimental This method updates a brand kit and all related resources assigned to it\n * @param studioBrandKit the content of the brand kit\n * @returns\n */\n set = async (studioBrandKit: StudioBrandKit) => {\n const res = await this.#editorAPI;\n const result = await res.setBrandKit(JSON.stringify(studioBrandKit.brandKit));\n const response = getEditorResponseData<EngineBrandKit>(result);\n const engineData = response.parsedData;\n if (engineData == null) {\n throw new Error('Brand kit set response has no data');\n }\n return {\n ...response,\n parsedData: engineBrandKitToBrandKitInternal(engineData),\n };\n };\n\n\n /**\n * This method returns the value indicating whether the brand kit auto-sync is enabled or not\n * It is up to the integrator to implement this auto-sync functionality, this method only is an indication if it should be done or not.\n \n * @returns boolean indicating sync status\n */\n isAutoSync = async () => {\n const res = await this.#editorAPI;\n return res.isBrandKitAutoSync().then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * This method enables or disables brand kit auto-sync\n * @param enableAutoSync boolean indicating auto-sync status\n * @returns boolean indicating the result of the operation\n */\n enableAutoSync = async (enableAutoSync: boolean) => {\n const res = await this.#editorAPI;\n return res.enableBrandKitAutoSync(enableAutoSync).then((result) => getEditorResponseData<boolean>(result));\n };\n}\n"],"names":["sdk","media"],"mappings":";;;;;;;;;;AAsBO,MAAM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,IAAI;AAChC,SAAK,0BAA0B,IAAI;AACnC,SAAK,iBAAiB,IAAI;AAC1B,SAAK,kBAAkB,IAAI;AAC3B,SAAK,2BAA2B,IAAI;AACpC,SAAK,2BAA2B,IAAI;AAEpC,SAAK,wBAAwB,IAAI;AAAA,EACrC;AAiOJ;AAhPI;"}
|
|
1
|
+
{"version":3,"file":"BrandKitController.es.js","sources":["../../../src/controllers/BrandKitController.ts"],"sourcesContent":["import SDK from '..';\nimport { BrandKitMedia, BrandKit, APIBrandKit } from '../types/BrandKitTypes';\nimport { EditorAPI, Id } from '../types/CommonTypes';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\n\n/**\n * The BrandKitController is responsible for all communication regarding Brand Kits.\n * Methods inside this controller can be called by `window.SDK.brandKit.{method-name}`\n */\n\nexport class BrandKitController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n private sdk: SDK;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI, sdk: SDK) {\n this.#editorAPI = editorAPI;\n this.sdk = sdk;\n }\n\n /**\n * This method returns the current brand kit id.\n * @returns current brand kit id\n */\n getId = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitId().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit version.\n * @returns current brand kit version\n */\n getVersion = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitVersion().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method returns the current brand kit name.\n * @returns current brand kit name\n */\n getName = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKitName().then((result) => getEditorResponseData<string>(result));\n };\n\n /**\n * This method renames the brand kit.\n * @param newName - The new name for the brand kit\n * @returns\n */\n rename = async (newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKit(newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method updates both the brand kit id and version.\n * @param id - The new brand kit id\n * @param version - The new brand kit version\n * @returns\n */\n updateIdAndVersion = async (id: string, version: string) => {\n const res = await this.#editorAPI;\n return res.updateBrandKitIdAndVersion(id, version).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method returns the local brand kit\n * @returns brand kit with all assigned resources\n */\n get = async () => {\n const res = await this.#editorAPI;\n return res.getBrandKit().then((result) => getEditorResponseData<BrandKit>(result));\n };\n\n /**\n * This method returns all media items in the brand kit\n * @returns list of media items in the brand kit\n */\n getAllMedia = async () => {\n const res = await this.#editorAPI;\n return res.getAllBrandKitMedia().then((result) => getEditorResponseData<BrandKitMedia[]>(result));\n };\n\n /**\n * This method adds a media item to the brand kit\n * @param name - The name of the media item\n * @param remoteConnectorId - The remote connector ID\n * @param assetId - The asset ID of the media item\n * @returns\n */\n addMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .addBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<Id>(result));\n };\n\n /**\n * This method updates an existing media item in the brand kit\n * @param name - The name of the media item to update\n * @param remoteConnectorId - The new remote connector ID\n * @param assetId - The new asset ID\n * @returns\n */\n updateMedia = async (name: string, remoteConnectorId: Id, assetId: string) => {\n const res = await this.#editorAPI;\n return res\n .updateBrandKitMedia(name, remoteConnectorId, assetId)\n .then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method renames an existing media item in the brand kit\n * @param name - The name of the media item to rename\n * @param newName - The new name for the media item\n * @returns\n */\n renameMedia = async (name: string, newName: string) => {\n const res = await this.#editorAPI;\n return res.renameBrandKitMedia(name, newName).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method removes a media item from the brand kit\n * @param name - The name of the media item to remove\n * @returns\n */\n removeMedia = async (name: string) => {\n const res = await this.#editorAPI;\n return res.removeBrandKitMedia(name).then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * @experimental This method replaces the full brand kit and all related resources assigned to it\n * @param apiBrandKit the brand kit from the environment api\n * @returns the local brand kit\n */\n set = async (apiBrandKit: APIBrandKit) => {\n const res = await this.#editorAPI;\n return res.setBrandKit(JSON.stringify(apiBrandKit)).then((result) => getEditorResponseData<BrandKit>(result));\n };\n\n /**\n * @experimental This method syncs brand kit items and structure in place without replacing the existing brand kit\n * @param apiBrandKit the brand kit from the environment api\n * @returns boolean indicating whether the brand kit changed after the sync attempt\n */\n sync = async (apiBrandKit: APIBrandKit) => {\n const res = await this.#editorAPI;\n return res.syncBrandKit(JSON.stringify(apiBrandKit)).then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * This method returns the value indicating whether the brand kit auto-sync is enabled or not\n * It is up to the integrator to implement this auto-sync functionality, this method only is an indication if it should be done or not.\n \n * @returns boolean indicating sync status\n */\n isAutoSync = async () => {\n const res = await this.#editorAPI;\n return res.isBrandKitAutoSync().then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * This method enables or disables brand kit auto-sync\n * @param enableAutoSync boolean indicating auto-sync status\n * @returns boolean indicating the result of the operation\n */\n enableAutoSync = async (enableAutoSync: boolean) => {\n const res = await this.#editorAPI;\n return res.enableBrandKitAutoSync(enableAutoSync).then((result) => getEditorResponseData<boolean>(result));\n };\n\n /**\n * Switches the active brand kit theme.\n * @param themeName - Theme name\n * @returns\n */\n switchTheme = async (themeName: string) => {\n const res = await this.#editorAPI;\n return res.switchBrandKitTheme(themeName).then((result) => getEditorResponseData<null>(result));\n };\n}\n"],"names":[],"mappings":";;;;;;;;;AAUO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAc5B,YAAY,WAAsB,KAAU;AAV5C;AAAA;AAAA;AAAA;AAmBA,SAAA,QAAQ,YAAY;AAChB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,gBAAgB,KAAK,CAAC,WAAW,sBAA8B,MAAM,CAAC;AAAA,IACrF;AAMA,SAAA,aAAa,YAAY;AACrB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,qBAAqB,KAAK,CAAC,WAAW,sBAA8B,MAAM,CAA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CAAC;AAAA,IACtG;AAOA,SAAA,cAAc,OAAO,SAAiB;AAClC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,oBAAoB,IAAI,EAAE,KAAK,CAAC,WAAW,sBAA4B,MAAM,CAAC;AAAA,IAC7F;AAOA,SAAA,MAAM,OAAO,gBAA6B;AACtC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,YAAY,KAAK,UAAU,WAAW,CAAC,EAAE,KAAK,CAAC,WAAW,sBAAgC,MAAM,CAAC;AAAA,IAChH;AAOA,SAAA,OAAO,OAAO,gBAA6B;AACvC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,aAAa,KAAK,UAAU,WAAW,CAAC,EAAE,KAAK,CAAC,WAAW,sBAA+B,MAAM,CAAC;AAAA,IAChH;AAQA,SAAA,aAAa,YAAY;AACrB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,qBAAqB,KAAK,CAAC,WAAW,sBAA+B,MAAM,CAAC;AAAA,IAC3F;AAOA,SAAA,iBAAiB,OAAO,mBAA4B;AAChD,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,uBAAuB,cAAc,EAAE,KAAK,CAAC,WAAW,sBAA+B,MAAM,CAAC;AAAA,IAC7G;AAOA,SAAA,cAAc,OAAO,cAAsB;AACvC,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,oBAAoB,SAAS,EAAE,KAAK,CAAC,WAAW,sBAA4B,MAAM,CAAC;AAAA,IAClG;AAxKI,uBAAK,YAAa;AAClB,SAAK,MAAM;AAAA,EACf;AAuKJ;AApLI;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentController.cjs.js","sources":["../../../src/controllers/ComponentController.ts"],"sourcesContent":["import { EditorAPI, Id } from '../types/CommonTypes';\nimport { ComponentFitEnum } from '../types/FrameTypes';\nimport { Variable } from '../types/VariableTypes';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\n\n/**\n * @experimental This controller is experimental and may change without warning.\n * The ComponentController is responsible for all communication regarding Component frames.\n * Methods inside this controller can be called by `window.SDK.component.{method-name}`\n */\nexport class ComponentController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI) {\n this.#editorAPI = editorAPI;\n }\n\n /**\n * @experimental This method will link (or unlink) a variable from the template to the component frame\n * @param id the id of the componentFrame that needs to be updated.\n * @param target the id of the variable, inside the component, that will be linked (or unlinked) to the source variable.\n * @param source the id of the source variable from the template. If not provided, the variable will be unlinked.\n * @param sourceField the field of the data source variable.\n
|
|
1
|
+
{"version":3,"file":"ComponentController.cjs.js","sources":["../../../src/controllers/ComponentController.ts"],"sourcesContent":["import { EditorAPI, Id } from '../types/CommonTypes';\nimport { ComponentFitEnum } from '../types/FrameTypes';\nimport { Variable } from '../types/VariableTypes';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\n\n/**\n * @experimental This controller is experimental and may change without warning.\n * The ComponentController is responsible for all communication regarding Component frames.\n * Methods inside this controller can be called by `window.SDK.component.{method-name}`\n */\nexport class ComponentController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI) {\n this.#editorAPI = editorAPI;\n }\n\n /**\n * @experimental This method will link (or unlink) a variable from the template to the component frame\n * @param id the id of the componentFrame that needs to be updated.\n * @param target the id of the variable, inside the component, that will be linked (or unlinked) to the source variable.\n * @param source the id of the source variable from the template. If not provided, the variable will be unlinked.\n * @param sourceField the field of the data source variable.\n * @returns\n */\n linkVariable = async (frameId: Id, target: Id, source?: Id, sourceField?: string) => {\n const res = await this.#editorAPI;\n return res\n .linkComponentVariable(frameId, target, source, sourceField ?? null)\n .then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method returns the list of variables of a component frame.\n * @param id the id of the componentFrame.\n * @returns\n */\n getComponentVariables = async (frameId: Id) => {\n const res = await this.#editorAPI;\n return res.getComponentVariables(frameId).then((result) => getEditorResponseData<Variable[]>(result));\n };\n\n /**\n * This method sets the fit mode of a component frame.\n * @param frameId the id of the component frame.\n * @param fitMode the fit mode to set.\n * @returns\n */\n setFitMode = async (frameId: Id, fitMode: ComponentFitEnum) => {\n const res = await this.#editorAPI;\n return res.setComponentLayoutFit(frameId, fitMode).then((result) => getEditorResponseData<null>(result));\n };\n}\n"],"names":["getEditorResponseData"],"mappings":";;;;;;;;;;;AAUO,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAS7B,YAAY,WAAsB;AALlC;AAAA;AAAA;AAAA;AAiBA,SAAA,eAAe,OAAO,SAAa,QAAY,QAAa,gBAAyB;AACjF,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IACF,sBAAsB,SAAS,QAAQ,QAAQ,eAAe,IAAI,EAClE,KAAK,CAAC,WAAWA,mBAAAA,sBAA4B,MAAM,CAAC;AAAA,IAC7D;AAOA,SAAA,wBAAwB,OAAO,YAAgB;AAC3C,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,sBAAsB,OAAO,EAAE,KAAK,CAAC,WAAWA,yCAAkC,MAAM,CAAC;AAAA,IACxG;AAQA,SAAA,aAAa,OAAO,SAAa,YAA8B;AAC3D,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,sBAAsB,SAAS,OAAO,EAAE,KAAK,CAAC,WAAWA,yCAA4B,MAAM,CAAC;AAAA,IAC3G;AArCI,uBAAK,YAAa;AAAA,EACtB;AAqCJ;AA5CI;;"}
|
|
@@ -18,7 +18,7 @@ export declare class ComponentController {
|
|
|
18
18
|
* @param target the id of the variable, inside the component, that will be linked (or unlinked) to the source variable.
|
|
19
19
|
* @param source the id of the source variable from the template. If not provided, the variable will be unlinked.
|
|
20
20
|
* @param sourceField the field of the data source variable.
|
|
21
|
-
|
|
21
|
+
* @returns
|
|
22
22
|
*/
|
|
23
23
|
linkVariable: (frameId: Id, target: Id, source?: Id, sourceField?: string) => Promise<import('../types/CommonTypes').EditorResponse<null>>;
|
|
24
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentController.es.js","sources":["../../../src/controllers/ComponentController.ts"],"sourcesContent":["import { EditorAPI, Id } from '../types/CommonTypes';\nimport { ComponentFitEnum } from '../types/FrameTypes';\nimport { Variable } from '../types/VariableTypes';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\n\n/**\n * @experimental This controller is experimental and may change without warning.\n * The ComponentController is responsible for all communication regarding Component frames.\n * Methods inside this controller can be called by `window.SDK.component.{method-name}`\n */\nexport class ComponentController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI) {\n this.#editorAPI = editorAPI;\n }\n\n /**\n * @experimental This method will link (or unlink) a variable from the template to the component frame\n * @param id the id of the componentFrame that needs to be updated.\n * @param target the id of the variable, inside the component, that will be linked (or unlinked) to the source variable.\n * @param source the id of the source variable from the template. If not provided, the variable will be unlinked.\n * @param sourceField the field of the data source variable.\n
|
|
1
|
+
{"version":3,"file":"ComponentController.es.js","sources":["../../../src/controllers/ComponentController.ts"],"sourcesContent":["import { EditorAPI, Id } from '../types/CommonTypes';\nimport { ComponentFitEnum } from '../types/FrameTypes';\nimport { Variable } from '../types/VariableTypes';\nimport { getEditorResponseData } from '../utils/EditorResponseData';\n\n/**\n * @experimental This controller is experimental and may change without warning.\n * The ComponentController is responsible for all communication regarding Component frames.\n * Methods inside this controller can be called by `window.SDK.component.{method-name}`\n */\nexport class ComponentController {\n /**\n * @ignore\n */\n #editorAPI: EditorAPI;\n\n /**\n * @ignore\n */\n constructor(editorAPI: EditorAPI) {\n this.#editorAPI = editorAPI;\n }\n\n /**\n * @experimental This method will link (or unlink) a variable from the template to the component frame\n * @param id the id of the componentFrame that needs to be updated.\n * @param target the id of the variable, inside the component, that will be linked (or unlinked) to the source variable.\n * @param source the id of the source variable from the template. If not provided, the variable will be unlinked.\n * @param sourceField the field of the data source variable.\n * @returns\n */\n linkVariable = async (frameId: Id, target: Id, source?: Id, sourceField?: string) => {\n const res = await this.#editorAPI;\n return res\n .linkComponentVariable(frameId, target, source, sourceField ?? null)\n .then((result) => getEditorResponseData<null>(result));\n };\n\n /**\n * This method returns the list of variables of a component frame.\n * @param id the id of the componentFrame.\n * @returns\n */\n getComponentVariables = async (frameId: Id) => {\n const res = await this.#editorAPI;\n return res.getComponentVariables(frameId).then((result) => getEditorResponseData<Variable[]>(result));\n };\n\n /**\n * This method sets the fit mode of a component frame.\n * @param frameId the id of the component frame.\n * @param fitMode the fit mode to set.\n * @returns\n */\n setFitMode = async (frameId: Id, fitMode: ComponentFitEnum) => {\n const res = await this.#editorAPI;\n return res.setComponentLayoutFit(frameId, fitMode).then((result) => getEditorResponseData<null>(result));\n };\n}\n"],"names":[],"mappings":";;;;;;;;;AAUO,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAS7B,YAAY,WAAsB;AALlC;AAAA;AAAA;AAAA;AAiBA,SAAA,eAAe,OAAO,SAAa,QAAY,QAAa,gBAAyB;AACjF,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IACF,sBAAsB,SAAS,QAAQ,QAAQ,eAAe,IAAI,EAClE,KAAK,CAAC,WAAW,sBAA4B,MAAM,CAAC;AAAA,IAC7D;AAOA,SAAA,wBAAwB,OAAO,YAAgB;AAC3C,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,sBAAsB,OAAO,EAAE,KAAK,CAAC,WAAW,sBAAkC,MAAM,CAAC;AAAA,IACxG;AAQA,SAAA,aAAa,OAAO,SAAa,YAA8B;AAC3D,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IAAI,sBAAsB,SAAS,OAAO,EAAE,KAAK,CAAC,WAAW,sBAA4B,MAAM,CAAC;AAAA,IAC3G;AArCI,uBAAK,YAAa;AAAA,EACtB;AAqCJ;AA5CI;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectorController.cjs.js","sources":["../../../src/controllers/ConnectorController.ts"],"sourcesContent":["import { EditorAPI, EditorResponse, Id } from '../types/CommonTypes';\r\nimport {\r\n ConnectorInstance,\r\n ConnectorMappingDirection,\r\n ConnectorMappingType,\r\n ConnectorOptions,\r\n ConnectorRegistration,\r\n ConnectorState,\r\n ConnectorStateType,\r\n ConnectorToEngineMapping,\r\n ConnectorType,\r\n EngineToConnectorMapping,\r\n} from '../types/ConnectorTypes';\r\nimport { getEditorResponseData } from '../utils/EditorResponseData';\r\n\r\nimport * as Next from '../next/types/ConnectorTypes';\r\nimport { WellKnownConfigurationKeys } from '../types/ConfigurationTypes';\r\nimport { ConnectorCompatibilityTools } from '../utils/ConnectorCompatibilityTools';\r\n\r\n/**\r\n * The ConnectorController manages lifetime of all available connectors, regardless of the type, in the\r\n * document. Use it to add/remove connectors to a template, or set specific configuration.\r\n *\r\n * The way CHILI Studio handles different sources of resources is called 'Connectors'. A Connectors is an\r\n * implementation of a set of capabilities we need to interact with a certain external resource management system.\r\n * In essence a connector is the combination of a Javascript snippet and some metadata. The Javascript snippet\r\n * is loaded in the studio engine using a sandboxed Javascript execution engine (QuickJs). This allows us to\r\n * execute the media connector both on web using webassembly and on the server side during e.g. animation output\r\n * generation.\r\n * This controller is an interface to the running connector instance inside the studio engine. The engine will\r\n * automatically register the 'grafx-media' and 'grafx-font' connectors. Custom connectors need to be registered\r\n * manually.\r\n */\r\nexport class ConnectorController {\r\n /**\r\n * @ignore\r\n */\r\n #editorAPI: EditorAPI;\r\n #localConfig: Map<string, string>;\r\n #connectorCompatibilityTools: ConnectorCompatibilityTools;\r\n\r\n /**\r\n * @ignore\r\n */\r\n constructor(editorAPI: EditorAPI, localConfig: Map<string, string>) {\r\n this.#editorAPI = editorAPI;\r\n this.#localConfig = localConfig;\r\n this.#connectorCompatibilityTools = new ConnectorCompatibilityTools();\r\n }\r\n\r\n /**\r\n * Gets a connector by its id\r\n * @param id the id of the connector\r\n * @returns connector\r\n */\r\n getById = async (id: Id) => {\r\n // add backwards compatibility code\r\n const res = await this.#editorAPI;\r\n return res\r\n .getConnectorById(id)\r\n .then((result) => getEditorResponseData<Next.ConnectorInstance>(result))\r\n .then((resp) => {\r\n const update: EditorResponse<ConnectorInstance> = { ...resp, parsedData: null };\r\n if (resp.parsedData) {\r\n update.parsedData = this.#connectorCompatibilityTools.makeSingleConnectorBackwardsCompatible(\r\n resp.parsedData,\r\n this.#localConfig.get(WellKnownConfigurationKeys.GraFxStudioEnvironmentApiUrl),\r\n );\r\n }\r\n return update;\r\n });\r\n };\r\n\r\n /**\r\n * Gets all available connectors of a 'ConnectorType'\r\n * @param type type of connector you want to get\r\n * @returns list of all available connectors of a 'ConnectorType'\r\n */\r\n getAllByType = async (type: ConnectorType) => {\r\n // add backwards compatibility code\r\n const res = await this.#editorAPI;\r\n return res\r\n .getConnectors(type)\r\n .then((result) => getEditorResponseData<Next.ConnectorInstance[]>(result))\r\n .then((resp) => {\r\n const update: EditorResponse<ConnectorInstance[]> = { ...resp, parsedData: null };\r\n if (resp.parsedData) {\r\n update.parsedData = this.#connectorCompatibilityTools.makeMultipleConnectorsBackwardsCompatible(\r\n resp.parsedData,\r\n this.#localConfig.get(WellKnownConfigurationKeys.GraFxStudioEnvironmentApiUrl),\r\n );\r\n }\r\n return update;\r\n });\r\n };\r\n\r\n /**\r\n * Registers a new connector in the SDK. After successful registration, depending\r\n * on the connector type, the connector can be configured and used in the template\r\n * Remember to add custom authentication information after registering the connector\r\n * @param registration registration object containing all details about the connector\r\n * @returns the Id of the newly created connector, this Id should be used going forward.\r\n */\r\n register = async (registration: ConnectorRegistration) => {\r\n const res = await this.#editorAPI;\r\n\r\n const connectorRegistration =\r\n this.#connectorCompatibilityTools.makeConnectorSourceForwardsCompatible(registration);\r\n\r\n return res\r\n .registerConnector(JSON.stringify(connectorRegistration))\r\n .then((result) => getEditorResponseData<Id>(result));\r\n };\r\n\r\n /**\r\n * Unregisters a connector from the document.\r\n * @param id the id of the connector to unregister\r\n * @returns\r\n */\r\n unregister = async (id: Id) => {\r\n const res = await this.#editorAPI;\r\n return res.unregisterConnector(id).then((result) => getEditorResponseData<null>(result));\r\n };\r\n\r\n /**\r\n * Configures a registered connector. A configurator helper is passed as an argument\r\n * of the callback for you to setup your connector.\r\n * @param id the id of your registered connector\r\n * @param configurationCallback callback to setup the connector\r\n * @returns\r\n */\r\n configure = async (id: Id, configurationCallback: (configurator: ConnectorConfigurator) => Promise<void>) => {\r\n const res = await this.#editorAPI;\r\n // wait for connector to be ready\r\n await this.waitToBeReady(id);\r\n // execute callback\r\n await configurationCallback(new ConnectorConfigurator(id, res));\r\n // invalidate connector in engine\r\n return res.updateConnectorConfiguration(id).then((result) => getEditorResponseData<null>(result));\r\n };\r\n\r\n /**\r\n * Gets the current state a connector is in, to wait until a connector is ready to be used, use the 'waitToBeReady'\r\n * method in this controller.\r\n * @param id the id of your registered connector you want to make sure it is loaded\r\n * @returns connector state\r\n */\r\n getState = async (id: Id) => {\r\n const res = await this.#editorAPI;\r\n return res.getConnectorState(id).then((result) => getEditorResponseData<ConnectorState>(result));\r\n };\r\n\r\n /**\r\n * Gets the mapped data from connector.\r\n * @param id the id of your registered connector\r\n * @param direction the mapping direction\r\n * @returns mappings\r\n */\r\n async getMappings(\r\n id: string,\r\n direction: ConnectorMappingDirection.engineToConnector,\r\n ): Promise<EditorResponse<EngineToConnectorMapping[]>>;\r\n async getMappings(\r\n id: string,\r\n direction: ConnectorMappingDirection.connectorToEngine,\r\n ): Promise<EditorResponse<ConnectorToEngineMapping[]>>;\r\n async getMappings(id: string, direction?: undefined): Promise<EditorResponse<ConnectorMappingType[]>>;\r\n async getMappings(id: string, direction?: ConnectorMappingDirection) {\r\n const res = await this.#editorAPI;\r\n return res\r\n .getConnectorMappings(id)\r\n .then((result) => getEditorResponseData<ConnectorMappingType[]>(result))\r\n .then((result) =>\r\n !direction\r\n ? result\r\n : {\r\n ...result,\r\n parsedData: result.parsedData?.filter((cm) => cm.direction === direction),\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Gets the options from the connector.\r\n * @param id the id of your registered connector\r\n * @returns options\r\n */\r\n getOptions = async (id: string) => {\r\n const res = await this.#editorAPI;\r\n return res.getConnectorOptions(id).then((result) => getEditorResponseData<ConnectorOptions>(result));\r\n };\r\n\r\n /**\r\n * Connectors are loaded asynchronously in the editor engine, this causes some challenges while configuring them. To make sure\r\n * an action on the connector will be available, it's advised to await this method. After the Promise resolves we are sure\r\n * the connector is up and running. This is used internally by the configure method to ensure correct execution. It's especially\r\n * useful during startup of the SDK / right after the loadDocument call.\r\n * @param id the id of your registered connector you want to make sure it is loaded\r\n * @returns\r\n */\r\n waitToBeReady = async (id: Id, timeoutMilliseconds = 2000): Promise<EditorResponse<null>> => {\r\n // minimum timeout is 500ms\r\n let timeout = Math.max(timeoutMilliseconds, 500);\r\n\r\n // maximum timeout is 5000ms\r\n timeout = Math.min(timeout, 5000);\r\n\r\n const waitTime = 100;\r\n let retries = 0;\r\n\r\n try {\r\n // using while loop will prevent stack overflow issues when using recursion\r\n // wait for maximum 2 seconds to fail\r\n while (retries * waitTime < timeout) {\r\n const result = await this.getState(id);\r\n\r\n if (\r\n result.success &&\r\n result.parsedData &&\r\n (result.parsedData.type === ConnectorStateType.running ||\r\n result.parsedData.type === ConnectorStateType.ready)\r\n ) {\r\n return getEditorResponseData<null>(\r\n { data: null, success: true, error: undefined, status: 0, parsedData: undefined },\r\n false,\r\n );\r\n }\r\n\r\n await new Promise((resolve) => setTimeout(resolve, waitTime));\r\n retries++;\r\n }\r\n } catch (err) {\r\n return getEditorResponseData<null>(\r\n {\r\n data: null,\r\n success: false,\r\n error: `Error while getting connector state ${err}`,\r\n status: 50000,\r\n parsedData: undefined,\r\n },\r\n false,\r\n );\r\n }\r\n\r\n return getEditorResponseData<null>(\r\n {\r\n data: null,\r\n success: false,\r\n error: `Timed out waiting for connector`,\r\n status: 50000,\r\n parsedData: undefined,\r\n },\r\n false,\r\n );\r\n };\r\n\r\n /**\r\n * Updates the mappings for a given connector.\r\n * @param id the id of your registered connector\r\n * @param mappings An array of mapping objects\r\n * @returns\r\n */\r\n updateMappings = async (id: Id, mappings: ConnectorMappingType[]) => {\r\n return await this.configure(id, async (config) => {\r\n // Retrieve all existing mappings\r\n const { parsedData: existingMappings } = await this.getMappings(id);\r\n\r\n // Filter out old mappings that are being replaced with new ones\r\n const filteredMappings =\r\n existingMappings?.filter(\r\n (mapping) =>\r\n !mappings.some(\r\n (newMapping) =>\r\n newMapping.name === mapping.name && newMapping.direction === mapping.direction,\r\n ),\r\n ) ?? [];\r\n\r\n // Filter out new mappings that have empty `name` or `value`\r\n const validMappings = mappings.filter((i) => i.name !== '' && i.value !== '');\r\n\r\n // Merge valid new mappings with the filtered existing mappings\r\n const combinedMappings = [...filteredMappings, ...validMappings];\r\n\r\n // Update the configuration with the resulted mappings\r\n await config.setMappings(combinedMappings);\r\n });\r\n };\r\n\r\n /**\r\n * Sets the mappings for a given connector, replacing the existing mappings with the new ones.\r\n * @param id the id of your registered connector\r\n * @param mappings An array of mapping objects to set\r\n * @returns\r\n */\r\n applyMappings = async (id: Id, mappings: ConnectorMappingType[]) => {\r\n return await this.configure(id, async (config) => {\r\n const validMappings = mappings.filter((i) => i.name !== '' && i.value !== '');\r\n await config.setMappings(validMappings);\r\n });\r\n };\r\n\r\n /**\r\n * Sets HTTP headers on every local connector instance of the given type that uses the given remote (Environment API) connector id.\r\n * It's applicable as for already registered connectors as well as for future one with same remote connector id.\r\n *\r\n * @param remoteConnectorId unique id of the remote connector from the Environment API (grafx source)\r\n * @param headers HTTP headers to set on the connector\r\n * @returns EditorResponse with null on success; error if the engine call fails\r\n */\r\n setHttpHeaders = async (\r\n remoteConnectorId: string,\r\n headers: Record<string, string>,\r\n ): Promise<EditorResponse<null>> => {\r\n const res = await this.#editorAPI;\r\n return res\r\n .remoteConnectorAuthenticationSetHttpHeaders(remoteConnectorId, JSON.stringify(headers))\r\n .then((result) => getEditorResponseData<null>(result));\r\n };\r\n}\r\n\r\n/**\r\n * Helper to setup your connector\r\n */\r\nclass ConnectorConfigurator {\r\n /**\r\n * @ignore\r\n */\r\n #connectorId: Id;\r\n #res: EditorAPI;\r\n\r\n /**\r\n * @ignore\r\n */\r\n constructor(id: Id, res: EditorAPI) {\r\n this.#connectorId = id;\r\n this.#res = res;\r\n }\r\n\r\n /**\r\n * Allows to customize the context data a connector can work with. The options data\r\n * will be available using the context parameter in the connector implementation code.\r\n * @param options object containing key value data to pass to connector context\r\n * @returns\r\n */\r\n setOptions = async (options: ConnectorOptions) => {\r\n return this.#res\r\n .setConnectorOptions(this.#connectorId, JSON.stringify(options))\r\n .then((result) => getEditorResponseData<null>(result));\r\n };\r\n\r\n /**\r\n * Allows to map variables or strings to connector context data.\r\n * By defining the mappings, we can trigger re-download of assets (dynamic asset provider)\r\n * or populate filters for the query endpoint. The mapped data will be available using\r\n * the context parameter in the connector implementation code.\r\n *\r\n * For the variables the mapping should follow the format \"var.[variable id]\". e.g. var.6B29FC40-CA47-1067-B31D-00DD010662DA\r\n *\r\n * @param mappings collection of mappings to set to this connector\r\n * @returns\r\n */\r\n setMappings = async (mappings: ConnectorMappingType[]) => {\r\n const result = await this.#res.setConnectorMappings(\r\n this.#connectorId,\r\n mappings.map(function (m) {\r\n return JSON.stringify(m);\r\n }),\r\n );\r\n return getEditorResponseData<null>(result);\r\n };\r\n\r\n /**\r\n * This method sets the HTTP headers for the 'staticKey' authentication type.\r\n * These additional headers will be added to all connector http calls.\r\n * Can only be used after a connector has been registered. (if you are using a grafx connector no registration is needed)\r\n * @param headerName name of the header\r\n * @param headerValue value of the header\r\n * @returns\r\n */\r\n setHttpHeader = async (headerName: string, headerValue: string) => {\r\n return this.#res\r\n .connectorAuthenticationSetHttpHeader(this.#connectorId, headerName, headerValue)\r\n .then((result) => getEditorResponseData<null>(result));\r\n };\r\n}\r\n"],"names":["getEditorResponseData","WellKnownConfigurationKeys","ConnectorStateType","ConnectorCompat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;AAAA,IAC7D;AAjDI,uBAAK,cAAe;AACpB,uBAAK,MAAO;AAAA,EAChB;AAgDJ;AAzDI;AACA;;"}
|
|
1
|
+
{"version":3,"file":"ConnectorController.cjs.js","sources":["../../../src/controllers/ConnectorController.ts"],"sourcesContent":["import { EditorAPI, EditorResponse, Id } from '../types/CommonTypes';\r\nimport {\r\n ConnectorInstance,\r\n ConnectorMappingDirection,\r\n ConnectorMappingType,\r\n ConnectorOptions,\r\n ConnectorRegistration,\r\n ConnectorState,\r\n ConnectorStateType,\r\n ConnectorToEngineMapping,\r\n ConnectorType,\r\n EngineToConnectorMapping,\r\n} from '../types/ConnectorTypes';\r\nimport { getEditorResponseData } from '../utils/EditorResponseData';\r\n\r\nimport * as Next from '../next/types/ConnectorTypes';\r\nimport { WellKnownConfigurationKeys } from '../types/ConfigurationTypes';\r\nimport { ConnectorCompatibilityTools } from '../utils/ConnectorCompatibilityTools';\r\n\r\n/**\r\n * The ConnectorController manages lifetime of all available connectors, regardless of the type, in the\r\n * document. Use it to add/remove connectors to a template, or set specific configuration.\r\n *\r\n * The way CHILI Studio handles different sources of resources is called 'Connectors'. A Connectors is an\r\n * implementation of a set of capabilities we need to interact with a certain external resource management system.\r\n * In essence a connector is the combination of a Javascript snippet and some metadata. The Javascript snippet\r\n * is loaded in the studio engine using a sandboxed Javascript execution engine (QuickJs). This allows us to\r\n * execute the media connector both on web using webassembly and on the server side during e.g. animation output\r\n * generation.\r\n * This controller is an interface to the running connector instance inside the studio engine. The engine will\r\n * automatically register the 'grafx-media' and 'grafx-font' connectors. Custom connectors need to be registered\r\n * manually.\r\n */\r\nexport class ConnectorController {\r\n /**\r\n * @ignore\r\n */\r\n #editorAPI: EditorAPI;\r\n #localConfig: Map<string, string>;\r\n #connectorCompatibilityTools: ConnectorCompatibilityTools;\r\n\r\n /**\r\n * @ignore\r\n */\r\n constructor(editorAPI: EditorAPI, localConfig: Map<string, string>) {\r\n this.#editorAPI = editorAPI;\r\n this.#localConfig = localConfig;\r\n this.#connectorCompatibilityTools = new ConnectorCompatibilityTools();\r\n }\r\n\r\n /**\r\n * Gets a connector by its id\r\n * @param id the id of the connector\r\n * @returns connector\r\n */\r\n getById = async (id: Id) => {\r\n // add backwards compatibility code\r\n const res = await this.#editorAPI;\r\n return res\r\n .getConnectorById(id)\r\n .then((result) => getEditorResponseData<Next.ConnectorInstance>(result))\r\n .then((resp) => {\r\n const update: EditorResponse<ConnectorInstance> = { ...resp, parsedData: null };\r\n if (resp.parsedData) {\r\n update.parsedData = this.#connectorCompatibilityTools.makeSingleConnectorBackwardsCompatible(\r\n resp.parsedData,\r\n this.#localConfig.get(WellKnownConfigurationKeys.GraFxStudioEnvironmentApiUrl),\r\n );\r\n }\r\n return update;\r\n });\r\n };\r\n\r\n /**\r\n * Gets all available connectors of a 'ConnectorType'\r\n * @param type type of connector you want to get\r\n * @returns list of all available connectors of a 'ConnectorType'\r\n */\r\n getAllByType = async (type: ConnectorType) => {\r\n // add backwards compatibility code\r\n const res = await this.#editorAPI;\r\n return res\r\n .getConnectors(type)\r\n .then((result) => getEditorResponseData<Next.ConnectorInstance[]>(result))\r\n .then((resp) => {\r\n const update: EditorResponse<ConnectorInstance[]> = { ...resp, parsedData: null };\r\n if (resp.parsedData) {\r\n update.parsedData = this.#connectorCompatibilityTools.makeMultipleConnectorsBackwardsCompatible(\r\n resp.parsedData,\r\n this.#localConfig.get(WellKnownConfigurationKeys.GraFxStudioEnvironmentApiUrl),\r\n );\r\n }\r\n return update;\r\n });\r\n };\r\n\r\n /**\r\n * Registers a new connector in the SDK. After successful registration, depending\r\n * on the connector type, the connector can be configured and used in the template\r\n * Remember to add custom authentication information after registering the connector\r\n * @param registration registration object containing all details about the connector\r\n * @returns the Id of the newly created connector, this Id should be used going forward.\r\n */\r\n register = async (registration: ConnectorRegistration) => {\r\n const res = await this.#editorAPI;\r\n\r\n const connectorRegistration =\r\n this.#connectorCompatibilityTools.makeConnectorSourceForwardsCompatible(registration);\r\n\r\n return res\r\n .registerConnector(JSON.stringify(connectorRegistration))\r\n .then((result) => getEditorResponseData<Id>(result));\r\n };\r\n\r\n /**\r\n * Unregisters a connector from the document.\r\n * @param id the id of the connector to unregister\r\n * @returns\r\n */\r\n unregister = async (id: Id) => {\r\n const res = await this.#editorAPI;\r\n return res.unregisterConnector(id).then((result) => getEditorResponseData<null>(result));\r\n };\r\n\r\n /**\r\n * Configures a registered connector. A configurator helper is passed as an argument\r\n * of the callback for you to setup your connector.\r\n * @param id the id of your registered connector\r\n * @param configurationCallback callback to setup the connector\r\n * @returns\r\n */\r\n configure = async (id: Id, configurationCallback: (configurator: ConnectorConfigurator) => Promise<void>) => {\r\n const res = await this.#editorAPI;\r\n // wait for connector to be ready\r\n await this.waitToBeReady(id);\r\n // execute callback\r\n await configurationCallback(new ConnectorConfigurator(id, res));\r\n // invalidate connector in engine\r\n return res.updateConnectorConfiguration(id).then((result) => getEditorResponseData<null>(result));\r\n };\r\n\r\n /**\r\n * Gets the current state a connector is in, to wait until a connector is ready to be used, use the 'waitToBeReady'\r\n * method in this controller.\r\n * @param id the id of your registered connector you want to make sure it is loaded\r\n * @returns connector state\r\n */\r\n getState = async (id: Id) => {\r\n const res = await this.#editorAPI;\r\n return res.getConnectorState(id).then((result) => getEditorResponseData<ConnectorState>(result));\r\n };\r\n\r\n /**\r\n * Gets the mapped data from connector.\r\n * @param id the id of your registered connector\r\n * @param direction the mapping direction\r\n * @returns mappings\r\n */\r\n async getMappings(\r\n id: string,\r\n direction: ConnectorMappingDirection.engineToConnector,\r\n ): Promise<EditorResponse<EngineToConnectorMapping[]>>;\r\n async getMappings(\r\n id: string,\r\n direction: ConnectorMappingDirection.connectorToEngine,\r\n ): Promise<EditorResponse<ConnectorToEngineMapping[]>>;\r\n async getMappings(id: string, direction?: undefined): Promise<EditorResponse<ConnectorMappingType[]>>;\r\n async getMappings(id: string, direction?: ConnectorMappingDirection) {\r\n const res = await this.#editorAPI;\r\n return res\r\n .getConnectorMappings(id)\r\n .then((result) => getEditorResponseData<ConnectorMappingType[]>(result))\r\n .then((result) =>\r\n !direction\r\n ? result\r\n : {\r\n ...result,\r\n parsedData: result.parsedData?.filter((cm) => cm.direction === direction),\r\n },\r\n );\r\n }\r\n\r\n /**\r\n * Gets the options from the connector.\r\n * @param id the id of your registered connector\r\n * @returns options\r\n */\r\n getOptions = async (id: string) => {\r\n const res = await this.#editorAPI;\r\n return res.getConnectorOptions(id).then((result) => getEditorResponseData<ConnectorOptions>(result));\r\n };\r\n\r\n /**\r\n * Connectors are loaded asynchronously in the editor engine, this causes some challenges while configuring them. To make sure\r\n * an action on the connector will be available, it's advised to await this method. After the Promise resolves we are sure\r\n * the connector is up and running. This is used internally by the configure method to ensure correct execution. It's especially\r\n * useful during startup of the SDK / right after the loadDocument call.\r\n * @param id the id of your registered connector you want to make sure it is loaded\r\n * @returns\r\n */\r\n waitToBeReady = async (id: Id, timeoutMilliseconds = 2000): Promise<EditorResponse<null>> => {\r\n // minimum timeout is 500ms\r\n let timeout = Math.max(timeoutMilliseconds, 500);\r\n\r\n // maximum timeout is 5000ms\r\n timeout = Math.min(timeout, 5000);\r\n\r\n const waitTime = 100;\r\n let retries = 0;\r\n\r\n try {\r\n // using while loop will prevent stack overflow issues when using recursion\r\n // wait for maximum 2 seconds to fail\r\n while (retries * waitTime < timeout) {\r\n const result = await this.getState(id);\r\n\r\n if (\r\n result.success &&\r\n result.parsedData &&\r\n (result.parsedData.type === ConnectorStateType.running ||\r\n result.parsedData.type === ConnectorStateType.ready)\r\n ) {\r\n return getEditorResponseData<null>(\r\n { data: null, success: true, error: undefined, status: 0, parsedData: undefined },\r\n false,\r\n );\r\n }\r\n\r\n await new Promise((resolve) => setTimeout(resolve, waitTime));\r\n retries++;\r\n }\r\n } catch (err) {\r\n return getEditorResponseData<null>(\r\n {\r\n data: null,\r\n success: false,\r\n error: `Error while getting connector state ${err}`,\r\n status: 50000,\r\n parsedData: undefined,\r\n },\r\n false,\r\n );\r\n }\r\n\r\n return getEditorResponseData<null>(\r\n {\r\n data: null,\r\n success: false,\r\n error: `Timed out waiting for connector`,\r\n status: 50000,\r\n parsedData: undefined,\r\n },\r\n false,\r\n );\r\n };\r\n\r\n /**\r\n * Updates the mappings for a given connector.\r\n * @param id the id of your registered connector\r\n * @param mappings An array of mapping objects\r\n * @returns\r\n */\r\n updateMappings = async (id: Id, mappings: ConnectorMappingType[]) => {\r\n return await this.configure(id, async (config) => {\r\n // Retrieve all existing mappings\r\n const { parsedData: existingMappings } = await this.getMappings(id);\r\n\r\n // Filter out old mappings that are being replaced with new ones\r\n const filteredMappings =\r\n existingMappings?.filter(\r\n (mapping) =>\r\n !mappings.some(\r\n (newMapping) =>\r\n newMapping.name === mapping.name && newMapping.direction === mapping.direction,\r\n ),\r\n ) ?? [];\r\n\r\n // Filter out new mappings that have empty `name` or `value`\r\n const validMappings = mappings.filter((i) => i.name !== '' && i.value !== '');\r\n\r\n // Merge valid new mappings with the filtered existing mappings\r\n const combinedMappings = [...filteredMappings, ...validMappings];\r\n\r\n // Update the configuration with the resulted mappings\r\n await config.setMappings(combinedMappings);\r\n });\r\n };\r\n\r\n /**\r\n * Sets the mappings for a given connector, replacing the existing mappings with the new ones.\r\n * @param id the id of your registered connector\r\n * @param mappings An array of mapping objects to set\r\n * @returns\r\n */\r\n applyMappings = async (id: Id, mappings: ConnectorMappingType[]) => {\r\n return await this.configure(id, async (config) => {\r\n const validMappings = mappings.filter((i) => i.name !== '' && i.value !== '');\r\n await config.setMappings(validMappings);\r\n });\r\n };\r\n\r\n /**\r\n * Sets HTTP headers on every local connector instance of the given type that uses the given remote (Environment API) connector id.\r\n * It's applicable as for already registered connectors as well as for future one with same remote connector id.\r\n *\r\n * @param remoteConnectorId unique id of the remote connector from the Environment API (grafx source)\r\n * @param headers HTTP headers to set on the connector\r\n * @returns EditorResponse with null on success; error if the engine call fails\r\n */\r\n setHttpHeaders = async (\r\n remoteConnectorId: string,\r\n headers: Record<string, string>,\r\n ): Promise<EditorResponse<null>> => {\r\n const res = await this.#editorAPI;\r\n return res\r\n .remoteConnectorAuthenticationSetHttpHeaders(remoteConnectorId, JSON.stringify(headers))\r\n .then((result) => getEditorResponseData<null>(result));\r\n };\r\n}\r\n\r\n/**\r\n * Helper to setup your connector\r\n */\r\nclass ConnectorConfigurator {\r\n /**\r\n * @ignore\r\n */\r\n #connectorId: Id;\r\n #res: EditorAPI;\r\n\r\n /**\r\n * @ignore\r\n */\r\n constructor(id: Id, res: EditorAPI) {\r\n this.#connectorId = id;\r\n this.#res = res;\r\n }\r\n\r\n /**\r\n * Allows to customize the context data a connector can work with. The options data\r\n * will be available using the context parameter in the connector implementation code.\r\n * @param options object containing key value data to pass to connector context\r\n * @returns\r\n */\r\n setOptions = async (options: ConnectorOptions) => {\r\n return this.#res\r\n .setConnectorOptions(this.#connectorId, JSON.stringify(options))\r\n .then((result) => getEditorResponseData<null>(result));\r\n };\r\n\r\n /**\r\n * Allows to map variables or strings to connector context data.\r\n * By defining the mappings, we can trigger re-download of assets (dynamic asset provider)\r\n * or populate filters for the query endpoint. The mapped data will be available using\r\n * the context parameter in the connector implementation code.\r\n *\r\n * For the variables the mapping should follow the format \"var.[variable id]\". e.g. var.6B29FC40-CA47-1067-B31D-00DD010662DA\r\n *\r\n * @param mappings collection of mappings to set to this connector\r\n * @returns\r\n */\r\n setMappings = async (mappings: ConnectorMappingType[]) => {\r\n const result = await this.#res.setConnectorMappings(\r\n this.#connectorId,\r\n mappings.map(function (m) {\r\n return JSON.stringify(m);\r\n }),\r\n );\r\n return getEditorResponseData<null>(result);\r\n };\r\n\r\n /**\r\n * This method sets the HTTP headers for the 'staticKey' authentication type.\r\n * These additional headers will be added to all connector http calls.\r\n * Can only be used after a connector has been registered. (if you are using a grafx connector no registration is needed)\r\n * @param headerName name of the header\r\n * @param headerValue value of the header\r\n * @returns\r\n */\r\n setHttpHeader = async (headerName: string, headerValue: string) => {\r\n return this.#res\r\n .connectorAuthenticationSetHttpHeader(this.#connectorId, headerName, headerValue)\r\n .then((result) => getEditorResponseData<null>(result));\r\n };\r\n}\r\n"],"names":["getEditorResponseData","WellKnownConfigurationKeys","ConnectorStateType","ConnectorCompatibilityTools"],"mappings":";;;;;;;;;;;;;;AAiCO,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAW7B,YAAY,WAAsB,aAAkC;AAPpE;AAAA;AAAA;AAAA;AACA;AACA;AAgBA,SAAA,UAAU,OAAO,OAAW;AAExB,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IACF,iBAAiB,EAAE,EACnB,KAAK,CAAC,WAAWA,mBAAAA,sBAA8C,MAAM,CAAC,EACtE,KAAK,CAAC,SAAS;AACZ,cAAM,SAA4C,EAAE,GAAG,MAAM,YAAY,KAAA;AACzE,YAAI,KAAK,YAAY;AACjB,iBAAO,aAAa,mBAAK,8BAA6B;AAAA,YAClD,KAAK;AAAA,YACL,mBAAK,cAAa,IAAIC,mBAAAA,2BAA2B,4BAA4B;AAAA,UAAA;AAAA,QAErF;AACA,eAAO;AAAA,MACX,CAAC;AAAA,IACT;AAOA,SAAA,eAAe,OAAO,SAAwB;AAE1C,YAAM,MAAM,MAAM,mBAAK;AACvB,aAAO,IACF,cAAc,IAAI,EAClB,KAAK,CAAC,WAAWD,mBAAAA,sBAAgD,MAAM,CAAC,EACxE,KAAK,CAAC,SAAS;AACZ,cAAM,SAA8C,EAAE,GAAG,MAAM,YAAY,KAAA;AAC3E,YAAI,KAAK,YAAY;AACjB,iBAAO,aAAa,mBAAK,8BAA6B;AAAA,YAClD,KAAK;AAAA,YACL,mBAAK,cAAa,IAAIC,mBAAAA,2BAA2B,4BAA4B;AAAA,UAAA;AAAA,QAErF;AACA,eAAO;AAAA,MACX,CAAC;AAAA,IACT;AASA,SAAA,WAAW,OAAO,iBAAwC;AACtD,YAAM,MAAM,MAAM,mBAAK;AAEvB,YAAM,wBACF,mBAAK,8BAA6B,sCAAsC,YAAY;AAExF,aAAO,IACF,kBAAkB,KAAK,UAAU,qBAAqB,CAA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K,MACP,qCAAqC,mBAAK,eAAc,YAAY,WAAW,EAC/E,KAAK,CAAC,WAAWA,mBAAAA,sBAA4B,MAAM,CAAC;AAAA,IAC7D;AAjDI,uBAAK,cAAe;AACpB,uBAAK,MAAO;AAAA,EAChB;AAgDJ;AAzDI;AACA;;"}
|
|
@@ -93,11 +93,11 @@ export declare class ConnectorController {
|
|
|
93
93
|
*/
|
|
94
94
|
updateMappings: (id: Id, mappings: ConnectorMappingType[]) => Promise<EditorResponse<null>>;
|
|
95
95
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
* Sets the mappings for a given connector, replacing the existing mappings with the new ones.
|
|
97
|
+
* @param id the id of your registered connector
|
|
98
|
+
* @param mappings An array of mapping objects to set
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
101
|
applyMappings: (id: Id, mappings: ConnectorMappingType[]) => Promise<EditorResponse<null>>;
|
|
102
102
|
/**
|
|
103
103
|
* Sets HTTP headers on every local connector instance of the given type that uses the given remote (Environment API) connector id.
|