@kizenapps/packager 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1,821 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ AUTOMATION_SCRIPT_FILE: () => AUTOMATION_SCRIPT_FILE,
34
+ AUTOMATION_STEPS_DIRECTORY_NAME: () => AUTOMATION_STEPS_DIRECTORY_NAME,
35
+ BROWSER_ROUTE_SCRIPTS_DIRECTORY_NAME: () => BROWSER_ROUTE_SCRIPTS_DIRECTORY_NAME,
36
+ CALENDAR_SOURCES_DIRECTORY_NAME: () => CALENDAR_SOURCES_DIRECTORY_NAME,
37
+ CALLBACK_SCRIPT_FILE: () => CALLBACK_SCRIPT_FILE,
38
+ CONFIG_FILE_NAME: () => CONFIG_FILE_NAME,
39
+ DATA_ADORNMENTS_DIRECTORY_NAME: () => DATA_ADORNMENTS_DIRECTORY_NAME,
40
+ EVENT_SCRIPTS_DIRECTORY_NAME: () => EVENT_SCRIPTS_DIRECTORY_NAME,
41
+ FLOATING_FRAMES_DIRECTORY_NAME: () => FLOATING_FRAMES_DIRECTORY_NAME,
42
+ JS_ACTIONS_DIRECTORY_NAME: () => JS_ACTIONS_DIRECTORY_NAME,
43
+ KZN_FILE_NAME: () => KZN_FILE_NAME,
44
+ MAIN_SCRIPT_FILE: () => MAIN_SCRIPT_FILE,
45
+ MANIFEST_FILE_NAME: () => MANIFEST_FILE_NAME,
46
+ MESSAGE_SCRIPT_FILE: () => MESSAGE_SCRIPT_FILE,
47
+ OBJECT_SETTINGS_ITEMS_DIRECTORY_NAME: () => OBJECT_SETTINGS_ITEMS_DIRECTORY_NAME,
48
+ RELEASE_NOTES_EXTENSION: () => RELEASE_NOTES_EXTENSION,
49
+ ROUTABLE_PAGES_DIRECTORY_NAME: () => ROUTABLE_PAGES_DIRECTORY_NAME,
50
+ SCRIPT_EXTENSION: () => SCRIPT_EXTENSION,
51
+ SETUP_ASSISTANT_DIRECTORY_NAME: () => SETUP_ASSISTANT_DIRECTORY_NAME,
52
+ STYLES_FILE_NAME: () => STYLES_FILE_NAME,
53
+ THUMBNAIL_FILE_NAMES: () => THUMBNAIL_FILE_NAMES,
54
+ TOOLBAR_ITEMS_DIRECTORY_NAME: () => TOOLBAR_ITEMS_DIRECTORY_NAME,
55
+ USER_SETUP_ASSISTANT_DIRECTORY_NAME: () => USER_SETUP_ASSISTANT_DIRECTORY_NAME,
56
+ getAdornmentIcon: () => getAdornmentIcon,
57
+ getMinimizedConfig: () => getMinimizedConfig,
58
+ imagetoUint8Array: () => imagetoUint8Array,
59
+ maybeParseConfig: () => maybeParseConfig,
60
+ minifyFiles: () => minifyFiles,
61
+ packagePlugin: () => packagePlugin,
62
+ parseManifestFromFiles: () => parseManifestFromFiles,
63
+ sanitizeToAPIName: () => sanitizeToAPIName,
64
+ scriptRuntimeToApiName: () => scriptRuntimeToApiName,
65
+ thumbnailImageExtensions: () => thumbnailImageExtensions,
66
+ transformDeployablePlugin: () => transformDeployablePlugin,
67
+ triggerImageExtensions: () => triggerImageExtensions,
68
+ zipToUint8Array: () => zipToUint8Array
69
+ });
70
+ module.exports = __toCommonJS(index_exports);
71
+
72
+ // src/lib/minify.ts
73
+ var minifyFile = async (file) => {
74
+ if (file.path.endsWith(".js")) {
75
+ if (!file.content) {
76
+ return "";
77
+ }
78
+ const { minify } = await import("@node-minify/core");
79
+ const { uglifyJs } = await import("@node-minify/uglify-js");
80
+ const result = await minify({
81
+ compressor: uglifyJs,
82
+ content: file.content,
83
+ options: {
84
+ mangle: true,
85
+ parse: {
86
+ bare_returns: true
87
+ }
88
+ }
89
+ });
90
+ return result;
91
+ }
92
+ return file.content;
93
+ };
94
+ var minifyFiles = async (files) => {
95
+ return Promise.all(
96
+ files.map(async (file) => {
97
+ const minified = await minifyFile(file);
98
+ return { ...file, minified };
99
+ })
100
+ );
101
+ };
102
+
103
+ // src/lib/apiNames.ts
104
+ var sanitizeToAPIName = (name) => {
105
+ return name.toLowerCase().replace(/[^a-z0-9\-\s]/g, "").replace(/\s+/g, "_");
106
+ };
107
+ var scriptRuntimeToApiName = (runtime) => {
108
+ const result = runtime.replace(/\s+/g, "-").replace(/\./g, "-");
109
+ return result;
110
+ };
111
+
112
+ // src/lib/image.ts
113
+ var imagetoUint8Array = (base64Image) => {
114
+ const byteCharacters = atob(base64Image);
115
+ const byteNumbers = new Array(byteCharacters.length);
116
+ for (let i = 0; i < byteCharacters.length; i++) {
117
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
118
+ }
119
+ return new Uint8Array(byteNumbers);
120
+ };
121
+ var zipToUint8Array = (zip) => {
122
+ return Uint8Array.from(zip);
123
+ };
124
+
125
+ // src/lib/structure.ts
126
+ var thumbnailImageExtensions = ["png"];
127
+ var triggerImageExtensions = [...thumbnailImageExtensions, "svg"];
128
+ var EVENT_SCRIPTS_DIRECTORY_NAME = "eventScripts";
129
+ var FLOATING_FRAMES_DIRECTORY_NAME = "floatingFrames";
130
+ var DATA_ADORNMENTS_DIRECTORY_NAME = "dataAdornments";
131
+ var TOOLBAR_ITEMS_DIRECTORY_NAME = "toolbarItems";
132
+ var ROUTABLE_PAGES_DIRECTORY_NAME = "pages";
133
+ var BROWSER_ROUTE_SCRIPTS_DIRECTORY_NAME = "routeScripts";
134
+ var JS_ACTIONS_DIRECTORY_NAME = "actions";
135
+ var OBJECT_SETTINGS_ITEMS_DIRECTORY_NAME = "objectSettingsItems";
136
+ var AUTOMATION_STEPS_DIRECTORY_NAME = "automationSteps";
137
+ var SETUP_ASSISTANT_DIRECTORY_NAME = "setupAssistant";
138
+ var USER_SETUP_ASSISTANT_DIRECTORY_NAME = "userSetupAssistant";
139
+ var CALENDAR_SOURCES_DIRECTORY_NAME = "calendarSources";
140
+ var THUMBNAIL_FILE_NAMES = thumbnailImageExtensions.map(
141
+ (ext) => `thumbnail.${ext}`
142
+ );
143
+ var RELEASE_NOTES_EXTENSION = "md";
144
+ var SCRIPT_EXTENSION = "js";
145
+ var MAIN_SCRIPT_FILE = `script.${SCRIPT_EXTENSION}`;
146
+ var MESSAGE_SCRIPT_FILE = `message.${SCRIPT_EXTENSION}`;
147
+ var CALLBACK_SCRIPT_FILE = `callback.${SCRIPT_EXTENSION}`;
148
+ var AUTOMATION_SCRIPT_FILE = `script.py`;
149
+ var CONFIG_FILE_NAME = "config.json";
150
+ var STYLES_FILE_NAME = "styles.css";
151
+ var MANIFEST_FILE_NAME = "kizen.json";
152
+ var KZN_FILE_NAME = "import.kzn";
153
+ var maybeParseConfig = (content, path) => {
154
+ if (!content) {
155
+ throw new Error(`No content provided for config file: ${path}`);
156
+ }
157
+ try {
158
+ return JSON.parse(content);
159
+ } catch {
160
+ throw new Error(`Failed to parse config content: ${path}`);
161
+ }
162
+ };
163
+ var getMinimizedConfig = (config, entry, splitPath, consideredFiles) => {
164
+ const result = config["minimized_config"] ?? {};
165
+ if (result["customIconFile"]) {
166
+ let basePath = splitPath.slice(0, -1).join("/");
167
+ if (entry.endsWith("/")) {
168
+ basePath = `${entry}${basePath}`;
169
+ } else {
170
+ basePath = `${entry}/${basePath}`;
171
+ }
172
+ const filePath = `${basePath}/${result["customIconFile"]}`;
173
+ const file = consideredFiles.find((f) => f.path === filePath);
174
+ if (file?.base64Image) {
175
+ let extension = filePath.split(".").pop()?.toLowerCase();
176
+ if (extension === "svg") {
177
+ extension = "svg+xml";
178
+ }
179
+ result["customIcon"] = `data:image/${extension};base64,${file.base64Image}`;
180
+ }
181
+ }
182
+ return result;
183
+ };
184
+ var getAdornmentIcon = (config, entry, splitPath, consideredFiles) => {
185
+ if (config["customIconFile"]) {
186
+ let basePath = splitPath.slice(0, -1).join("/");
187
+ if (entry.endsWith("/")) {
188
+ basePath = `${entry}${basePath}`;
189
+ } else {
190
+ basePath = `${entry}/${basePath}`;
191
+ }
192
+ const filePath = `${basePath}/${config["customIconFile"]}`;
193
+ const file = consideredFiles.find((f) => f.path === filePath);
194
+ if (file?.base64Image) {
195
+ let extension = filePath.split(".").pop()?.toLowerCase();
196
+ if (extension === "svg") {
197
+ extension = "svg+xml";
198
+ }
199
+ return `data:image/${extension};base64,${file.base64Image}`;
200
+ }
201
+ }
202
+ return "";
203
+ };
204
+
205
+ // src/lib/package.ts
206
+ var replacementVar = "__kizen_state";
207
+ var prepend = "const __kizen_utils = {};\n";
208
+ var convertToSelfInvokingFunction = (fn, variable, args = {}, prependCode = "") => {
209
+ const functionString = fn.replace(/\n$/, "").replace(/;$/, "");
210
+ const inner = `(${functionString})({ state: {{${variable}}}, args: ${JSON.stringify(args)}, utils: __kizen_utils })`;
211
+ const full = `(function() { ${prependCode}
212
+ return ${inner}; })()`;
213
+ return full;
214
+ };
215
+ var mapFields = (fields, scriptsByKey) => {
216
+ return fields.map((field) => {
217
+ if (field["type"] === "container" && field["fields"] && Array.isArray(field["fields"])) {
218
+ return {
219
+ ...field,
220
+ fields: mapFields(
221
+ field["fields"],
222
+ scriptsByKey
223
+ )
224
+ };
225
+ }
226
+ const fieldKey = field["key"];
227
+ const scripts = scriptsByKey[fieldKey];
228
+ if (scripts) {
229
+ const result = { ...field };
230
+ for (const fnName of [
231
+ "getFetchUrl",
232
+ "optionMapper",
233
+ "getHeaders",
234
+ "getBody",
235
+ "getContextUrl"
236
+ ]) {
237
+ const fn = scripts[fnName];
238
+ if (fn) {
239
+ result[fnName] = convertToSelfInvokingFunction(
240
+ fn,
241
+ replacementVar,
242
+ {},
243
+ prepend
244
+ );
245
+ }
246
+ }
247
+ return result;
248
+ }
249
+ return field;
250
+ });
251
+ };
252
+ var processSetupAssistantFromFiles = (assistantConfig, scripts) => {
253
+ if (!assistantConfig) {
254
+ return void 0;
255
+ }
256
+ const scriptsByKey = scripts.reduce(
257
+ (acc, script) => {
258
+ if (!acc[script.key]) {
259
+ acc[script.key] = {};
260
+ }
261
+ acc[script.key][script.type] = script.content;
262
+ return acc;
263
+ },
264
+ {}
265
+ );
266
+ const newConfig = { ...assistantConfig };
267
+ if (newConfig["fields"] && Array.isArray(newConfig["fields"])) {
268
+ newConfig["fields"] = mapFields(
269
+ newConfig["fields"],
270
+ scriptsByKey
271
+ );
272
+ }
273
+ return newConfig;
274
+ };
275
+ var processOnePluginFromManifest = (manifest, files) => {
276
+ const entry = manifest.entry;
277
+ const releaseNotesDirectory = manifest.release_notes_directory;
278
+ const apiName = manifest.api_name;
279
+ const consideredFiles = files.filter(
280
+ (f) => f.path !== MANIFEST_FILE_NAME && f.path.startsWith(entry)
281
+ );
282
+ const releaseNotesFiles = releaseNotesDirectory ? files.filter((f) => f.path.startsWith(releaseNotesDirectory)) : [];
283
+ const { version } = manifest;
284
+ const releaseNotes = releaseNotesFiles.find(
285
+ (file) => file.path.endsWith(`${version}.${RELEASE_NOTES_EXTENSION}`)
286
+ );
287
+ const floatingFrames = {};
288
+ const dataAdornments = {};
289
+ const toolbarItems = {};
290
+ const routablePages = {};
291
+ const routeScripts = {};
292
+ const jsActions = {};
293
+ const objectSettingsItems = {};
294
+ const automationSteps = {};
295
+ const calendarSources = {};
296
+ let thumbnail = null;
297
+ let kznFile = null;
298
+ let hasBlockingCondition = false;
299
+ const requiredConfigFiles = {};
300
+ let setupAssistantJSON = null;
301
+ const setupAssistantFunctions = [];
302
+ let userSetupAssistantJSON = null;
303
+ const userSetupAssistantFunctions = [];
304
+ for (const file of consideredFiles) {
305
+ let strippedPath = file.path.replace(entry, "");
306
+ strippedPath = strippedPath.startsWith("/") ? strippedPath.substring(1) : strippedPath;
307
+ const splitPath = strippedPath.split("/");
308
+ if (splitPath[0] === SETUP_ASSISTANT_DIRECTORY_NAME) {
309
+ if (splitPath[1] === "assistant.json") {
310
+ setupAssistantJSON = maybeParseConfig(file.content, file.path);
311
+ } else {
312
+ const assistantKey = splitPath[1];
313
+ if (assistantKey && splitPath[2]?.endsWith(`.${SCRIPT_EXTENSION}`)) {
314
+ setupAssistantFunctions.push({
315
+ key: assistantKey,
316
+ type: splitPath[2].replace(`.${SCRIPT_EXTENSION}`, ""),
317
+ content: file.content
318
+ });
319
+ }
320
+ }
321
+ } else if (splitPath[0] === USER_SETUP_ASSISTANT_DIRECTORY_NAME) {
322
+ if (splitPath[1] === "assistant.json") {
323
+ userSetupAssistantJSON = maybeParseConfig(file.content, file.path);
324
+ } else {
325
+ const assistantKey = splitPath[1];
326
+ if (assistantKey && splitPath[2]?.endsWith(`.${SCRIPT_EXTENSION}`)) {
327
+ userSetupAssistantFunctions.push({
328
+ key: assistantKey,
329
+ type: splitPath[2].replace(`.${SCRIPT_EXTENSION}`, ""),
330
+ content: file.content
331
+ });
332
+ }
333
+ }
334
+ } else if (splitPath[0] === FLOATING_FRAMES_DIRECTORY_NAME) {
335
+ const floatingFrameName = splitPath[1];
336
+ if (!floatingFrameName) continue;
337
+ if (!floatingFrames[floatingFrameName]) {
338
+ requiredConfigFiles[`frame:${floatingFrameName}`] = true;
339
+ floatingFrames[floatingFrameName] = {
340
+ name: "",
341
+ api_name: "",
342
+ title: "",
343
+ type: "script",
344
+ css: "",
345
+ event_scripts: {},
346
+ default_position: "bottom-right",
347
+ header_color: "",
348
+ header_text_color: "",
349
+ height: 0,
350
+ width: 0,
351
+ ignore: [],
352
+ match: [],
353
+ message_handler: "",
354
+ minimized_style: "circle",
355
+ minimized_config: {},
356
+ script: "",
357
+ html: "",
358
+ when: ""
359
+ };
360
+ }
361
+ const frame = floatingFrames[floatingFrameName];
362
+ if (splitPath[2] === EVENT_SCRIPTS_DIRECTORY_NAME) {
363
+ if (splitPath[3]?.endsWith(`.${SCRIPT_EXTENSION}`)) {
364
+ const functionName = splitPath[3].replace(`.${SCRIPT_EXTENSION}`, "");
365
+ frame.event_scripts[functionName] = file.minified;
366
+ }
367
+ } else if (splitPath[2] === CONFIG_FILE_NAME) {
368
+ requiredConfigFiles[`frame:${floatingFrameName}`] = false;
369
+ const config = maybeParseConfig(file.content, file.path);
370
+ frame.name = config["name"] || "";
371
+ frame.api_name = config["api_name"] || sanitizeToAPIName(floatingFrameName);
372
+ frame.title = config["title"] || "";
373
+ frame.default_position = config["default_position"] || "bottom-right";
374
+ frame.header_color = config["header_color"] || "";
375
+ frame.header_text_color = config["header_text_color"] || "";
376
+ frame.height = config["height"] || 0;
377
+ frame.width = config["width"] || 0;
378
+ frame.ignore = config["ignore"] || [];
379
+ frame.match = config["match"] || [];
380
+ frame.html = config["html"] || "";
381
+ frame.minimized_style = config["minimized_style"] || "circle";
382
+ frame.minimized_config = getMinimizedConfig(
383
+ config,
384
+ entry,
385
+ splitPath,
386
+ consideredFiles
387
+ );
388
+ frame.when = config["when"] || "";
389
+ } else if (splitPath[2] === MESSAGE_SCRIPT_FILE) {
390
+ frame.message_handler = file.minified;
391
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
392
+ frame.script = file.minified;
393
+ } else if (splitPath[2] === STYLES_FILE_NAME) {
394
+ frame.css = file.minified;
395
+ }
396
+ } else if (splitPath[0] === DATA_ADORNMENTS_DIRECTORY_NAME) {
397
+ const dataAdornmentName = splitPath[1];
398
+ if (!dataAdornmentName) continue;
399
+ if (!dataAdornments[dataAdornmentName]) {
400
+ requiredConfigFiles[`dataAdornment:${dataAdornmentName}`] = true;
401
+ dataAdornments[dataAdornmentName] = {
402
+ config: { icon: "", color: "", tooltip: "" },
403
+ field_type: "phonenumber",
404
+ script: "",
405
+ when: ""
406
+ };
407
+ }
408
+ const adornment = dataAdornments[dataAdornmentName];
409
+ if (splitPath[2] === CONFIG_FILE_NAME) {
410
+ requiredConfigFiles[`dataAdornment:${dataAdornmentName}`] = false;
411
+ const config = maybeParseConfig(file.content, file.path);
412
+ adornment.config.icon = config["icon"] || "";
413
+ adornment.config.color = config["color"] || "";
414
+ adornment.config.tooltip = config["tooltip"] || "";
415
+ adornment.config.customIcon = getAdornmentIcon(
416
+ config,
417
+ entry,
418
+ splitPath,
419
+ consideredFiles
420
+ );
421
+ adornment.field_type = config["field_type"] || "phonenumber";
422
+ adornment.when = config["when"] || "";
423
+ if (config["when"]) hasBlockingCondition = true;
424
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
425
+ adornment.script = file.minified;
426
+ }
427
+ } else if (splitPath[0] === TOOLBAR_ITEMS_DIRECTORY_NAME) {
428
+ const toolbarItemName = splitPath[1];
429
+ if (!toolbarItemName) continue;
430
+ if (!toolbarItems[toolbarItemName]) {
431
+ requiredConfigFiles[`toolbarItem:${toolbarItemName}`] = true;
432
+ toolbarItems[toolbarItemName] = {
433
+ api_name: "",
434
+ label: "",
435
+ icon: "",
436
+ color: "",
437
+ script: "",
438
+ when: ""
439
+ };
440
+ }
441
+ const item = toolbarItems[toolbarItemName];
442
+ if (splitPath[2] === CONFIG_FILE_NAME) {
443
+ requiredConfigFiles[`toolbarItem:${toolbarItemName}`] = false;
444
+ const config = maybeParseConfig(file.content, file.path);
445
+ item.api_name = config["api_name"] || sanitizeToAPIName(toolbarItemName);
446
+ item.label = config["label"] || "";
447
+ item.icon = config["icon"] || "";
448
+ item.color = config["color"] || "";
449
+ item.when = config["when"] || "";
450
+ if (config["when"]) hasBlockingCondition = true;
451
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
452
+ item.script = file.minified;
453
+ }
454
+ } else if (splitPath[0] === ROUTABLE_PAGES_DIRECTORY_NAME) {
455
+ const pageName = splitPath[1];
456
+ if (!pageName) continue;
457
+ if (!routablePages[pageName]) {
458
+ requiredConfigFiles[`page:${pageName}`] = true;
459
+ routablePages[pageName] = {
460
+ name: pageName,
461
+ api_name: "",
462
+ event_scripts: {},
463
+ script: "",
464
+ callback: "",
465
+ css: "",
466
+ is_toolbar_item: false,
467
+ toolbar_color: "",
468
+ toolbar_icon: "",
469
+ type: "script",
470
+ html: "",
471
+ iframe_url: ""
472
+ };
473
+ }
474
+ const page = routablePages[pageName];
475
+ if (splitPath[2] === EVENT_SCRIPTS_DIRECTORY_NAME) {
476
+ if (splitPath[3]?.endsWith(SCRIPT_EXTENSION)) {
477
+ const functionName = splitPath[3].replace(`.${SCRIPT_EXTENSION}`, "");
478
+ page.event_scripts[functionName] = file.minified;
479
+ }
480
+ } else if (splitPath[2] === CONFIG_FILE_NAME) {
481
+ requiredConfigFiles[`page:${pageName}`] = false;
482
+ const config = maybeParseConfig(file.content, file.path);
483
+ page.api_name = config["api_name"] || sanitizeToAPIName(pageName);
484
+ page.name = config["name"] || pageName;
485
+ page.is_toolbar_item = config["is_toolbar_item"] || false;
486
+ page.toolbar_color = config["toolbar_color"] || "";
487
+ page.toolbar_icon = config["toolbar_icon"] || "";
488
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
489
+ page.script = file.minified;
490
+ } else if (splitPath[2] === CALLBACK_SCRIPT_FILE) {
491
+ page.callback = file.minified;
492
+ } else if (splitPath[2] === STYLES_FILE_NAME) {
493
+ page.css = file.minified;
494
+ }
495
+ } else if (splitPath[0] === AUTOMATION_STEPS_DIRECTORY_NAME) {
496
+ const stepName = splitPath[1];
497
+ if (!stepName) continue;
498
+ if (!automationSteps[stepName]) {
499
+ requiredConfigFiles[`automationStep:${stepName}`] = true;
500
+ automationSteps[stepName] = {
501
+ name: "",
502
+ action_step_api_name: "",
503
+ overall_description: "",
504
+ action_description: "",
505
+ action_type: "",
506
+ script_runtime: scriptRuntimeToApiName("python 3.12"),
507
+ secrets: [],
508
+ inputs: [],
509
+ outputs: [],
510
+ script: "",
511
+ when: ""
512
+ };
513
+ }
514
+ const step = automationSteps[stepName];
515
+ if (splitPath[2] === CONFIG_FILE_NAME) {
516
+ requiredConfigFiles[`automationStep:${stepName}`] = false;
517
+ const config = maybeParseConfig(file.content, file.path);
518
+ step.name = config["name"] || stepName;
519
+ step.action_step_api_name = config["api_name"] || sanitizeToAPIName(stepName);
520
+ step.overall_description = config["plugin_description"] || "";
521
+ step.action_description = config["action_description"] || "";
522
+ step.action_type = config["action_type"] || "";
523
+ step.secrets = config["secrets"] || [];
524
+ step.inputs = config["inputs"] || [];
525
+ step.outputs = config["outputs"] || [];
526
+ step.script_runtime = scriptRuntimeToApiName(
527
+ config["runtime"] || "python 3.12"
528
+ );
529
+ step.when = config["when"] || "";
530
+ if (config["when"]) hasBlockingCondition = true;
531
+ } else if (splitPath[2] === AUTOMATION_SCRIPT_FILE) {
532
+ step.script = file.content;
533
+ }
534
+ } else if (splitPath[0] === BROWSER_ROUTE_SCRIPTS_DIRECTORY_NAME) {
535
+ const routeName = splitPath[1];
536
+ if (!routeName) continue;
537
+ if (!routeScripts[routeName]) {
538
+ requiredConfigFiles[`route:${routeName}`] = true;
539
+ routeScripts[routeName] = {
540
+ script: "",
541
+ api_name: "",
542
+ hint_object_name: "",
543
+ routes: [],
544
+ name: routeName
545
+ };
546
+ }
547
+ const route = routeScripts[routeName];
548
+ if (splitPath[2] === CONFIG_FILE_NAME) {
549
+ requiredConfigFiles[`route:${routeName}`] = false;
550
+ const config = maybeParseConfig(file.content, file.path);
551
+ route.api_name = config["api_name"] || sanitizeToAPIName(routeName);
552
+ route.hint_object_name = config["hint_object_name"] || "";
553
+ route.routes = config["routes"] || [];
554
+ route.name = config["name"] || routeName;
555
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
556
+ route.script = file.minified;
557
+ }
558
+ } else if (splitPath[0] === JS_ACTIONS_DIRECTORY_NAME) {
559
+ const actionName = splitPath[1];
560
+ if (!actionName) continue;
561
+ if (!jsActions[actionName]) {
562
+ requiredConfigFiles[`action:${actionName}`] = true;
563
+ jsActions[actionName] = {
564
+ script: "",
565
+ name: "",
566
+ hint_object_name: "",
567
+ api_name: ""
568
+ };
569
+ }
570
+ const action = jsActions[actionName];
571
+ if (splitPath[2] === CONFIG_FILE_NAME) {
572
+ requiredConfigFiles[`action:${actionName}`] = false;
573
+ const config = maybeParseConfig(file.content, file.path);
574
+ action.name = config["name"] || actionName;
575
+ action.hint_object_name = config["hint_object_name"] || "";
576
+ action.api_name = config["api_name"] || sanitizeToAPIName(actionName);
577
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
578
+ action.script = file.minified;
579
+ }
580
+ } else if (splitPath[0] === OBJECT_SETTINGS_ITEMS_DIRECTORY_NAME) {
581
+ const itemName = splitPath[1];
582
+ if (!itemName) continue;
583
+ if (!objectSettingsItems[itemName]) {
584
+ requiredConfigFiles[`objectSettingsItem:${itemName}`] = true;
585
+ objectSettingsItems[itemName] = {
586
+ api_name: "",
587
+ label: "",
588
+ script: "",
589
+ when: ""
590
+ };
591
+ }
592
+ const settingsItem = objectSettingsItems[itemName];
593
+ if (splitPath[2] === CONFIG_FILE_NAME) {
594
+ requiredConfigFiles[`objectSettingsItem:${itemName}`] = false;
595
+ const config = maybeParseConfig(file.content, file.path);
596
+ settingsItem.api_name = config["api_name"] || sanitizeToAPIName(itemName);
597
+ settingsItem.label = config["label"] || "";
598
+ settingsItem.when = config["when"] || "";
599
+ } else if (splitPath[2] === MAIN_SCRIPT_FILE) {
600
+ settingsItem.script = file.minified;
601
+ }
602
+ } else if (splitPath[0] === CALENDAR_SOURCES_DIRECTORY_NAME) {
603
+ const itemName = splitPath[1];
604
+ if (!itemName) continue;
605
+ if (!calendarSources[itemName]) {
606
+ requiredConfigFiles[`calendarSource:${itemName}`] = true;
607
+ calendarSources[itemName] = {
608
+ api_name: "",
609
+ name: "",
610
+ calendars_script: "",
611
+ events_script: "",
612
+ when: ""
613
+ };
614
+ }
615
+ const cal = calendarSources[itemName];
616
+ if (splitPath[2] === CONFIG_FILE_NAME) {
617
+ requiredConfigFiles[`calendarSource:${itemName}`] = false;
618
+ const config = maybeParseConfig(file.content, file.path);
619
+ cal.api_name = config["api_name"] || sanitizeToAPIName(itemName);
620
+ cal.name = config["name"] || "";
621
+ cal.when = config["when"] || "";
622
+ if (config["when"]) hasBlockingCondition = true;
623
+ } else if (splitPath[2] === "calendars.js") {
624
+ cal.calendars_script = file.minified;
625
+ } else if (splitPath[2] === "events.js") {
626
+ cal.events_script = file.minified;
627
+ }
628
+ } else if (splitPath[0] === KZN_FILE_NAME) {
629
+ if (!file.binaryData) {
630
+ throw new Error(
631
+ `KZN file ${file.path} does not contain binary data. Cannot proceed.`
632
+ );
633
+ }
634
+ if (kznFile) {
635
+ throw new Error(
636
+ `Multiple KZN files found for plugin ${apiName}. Only one is allowed.`
637
+ );
638
+ }
639
+ kznFile = zipToUint8Array(file.binaryData);
640
+ } else if (THUMBNAIL_FILE_NAMES.includes(splitPath[0] ?? "")) {
641
+ if (file.base64Image) {
642
+ if (thumbnail) {
643
+ throw new Error(
644
+ `Multiple thumbnail files found for plugin ${apiName}. Only one is allowed.`
645
+ );
646
+ }
647
+ thumbnail = imagetoUint8Array(file.base64Image);
648
+ }
649
+ }
650
+ }
651
+ const requiredFileKeys = Object.keys(requiredConfigFiles).filter(
652
+ (key) => requiredConfigFiles[key] === true
653
+ );
654
+ if (requiredFileKeys.length > 0) {
655
+ throw new Error(
656
+ `The following required files are missing for plugin ${apiName}: ${requiredFileKeys.join(" config.json, ")} config.json. Please ensure these files are present in the repository.`
657
+ );
658
+ }
659
+ const setupAssistantContent = processSetupAssistantFromFiles(
660
+ setupAssistantJSON,
661
+ setupAssistantFunctions
662
+ );
663
+ const userSetupAssistantContent = processSetupAssistantFromFiles(
664
+ userSetupAssistantJSON,
665
+ userSetupAssistantFunctions
666
+ );
667
+ const updatedManifest = {
668
+ ...manifest,
669
+ block_loading_for_setup: hasBlockingCondition
670
+ };
671
+ const resolvedSetupAssistant = manifest.setup_assistant ?? setupAssistantContent;
672
+ if (resolvedSetupAssistant !== void 0) {
673
+ updatedManifest.setup_assistant = resolvedSetupAssistant;
674
+ }
675
+ const resolvedUserSetupAssistant = manifest.user_setup_assistant ?? userSetupAssistantContent;
676
+ if (resolvedUserSetupAssistant !== void 0) {
677
+ updatedManifest.user_setup_assistant = resolvedUserSetupAssistant;
678
+ }
679
+ return {
680
+ [apiName]: {
681
+ manifest: updatedManifest,
682
+ thumbnail,
683
+ floatingFrames,
684
+ dataAdornments,
685
+ toolbarItems,
686
+ routablePages,
687
+ actions: jsActions,
688
+ routeScripts,
689
+ releaseNotes: releaseNotes?.content,
690
+ objectSettingsMenuItems: objectSettingsItems,
691
+ calendarSources,
692
+ automationSteps,
693
+ kznFile
694
+ }
695
+ };
696
+ };
697
+ var packagePlugin = (files, manifests) => {
698
+ const manifestArray = Array.isArray(manifests) ? manifests : [manifests];
699
+ return manifestArray.reduce((acc, manifest) => {
700
+ return { ...acc, ...processOnePluginFromManifest(manifest, files) };
701
+ }, {});
702
+ };
703
+ var parseManifestFromFiles = (files) => {
704
+ const manifestFile = files.find((f) => f.path === MANIFEST_FILE_NAME);
705
+ if (!manifestFile) {
706
+ throw new Error("Missing kizen.json at the root of the plugin directory.");
707
+ }
708
+ try {
709
+ return JSON.parse(manifestFile.content);
710
+ } catch {
711
+ throw new Error("kizen.json could not be parsed.");
712
+ }
713
+ };
714
+
715
+ // src/lib/transform.ts
716
+ var formatBaseConfig = (packagedPlugin) => {
717
+ const assistantConfig = packagedPlugin.manifest.setup_assistant;
718
+ const actionsByApiName = Object.values(packagedPlugin.actions).reduce(
719
+ (acc, action) => {
720
+ acc[action.api_name] = action;
721
+ return acc;
722
+ },
723
+ {}
724
+ );
725
+ const userAssistantConfig = packagedPlugin.manifest.user_setup_assistant;
726
+ return {
727
+ ...packagedPlugin.manifest.base_config,
728
+ setup_assistant: assistantConfig ? {
729
+ ...assistantConfig,
730
+ actions: (assistantConfig.actions ?? []).map((apiName) => {
731
+ const action = actionsByApiName[apiName];
732
+ if (!action) {
733
+ throw new Error(
734
+ `Action with API name ${apiName} not found in packaged plugin for setup assistant. Allowed actions: ${Object.keys(actionsByApiName).join(", ")}`
735
+ );
736
+ }
737
+ return action;
738
+ })
739
+ } : void 0,
740
+ user_setup_assistant: userAssistantConfig,
741
+ block_loading_for_setup: packagedPlugin.manifest.block_loading_for_setup
742
+ };
743
+ };
744
+ var transformDeployablePlugin = (packagedPlugin) => {
745
+ const {
746
+ manifest,
747
+ floatingFrames,
748
+ dataAdornments,
749
+ routablePages,
750
+ toolbarItems,
751
+ actions,
752
+ routeScripts,
753
+ thumbnail,
754
+ releaseNotes,
755
+ objectSettingsMenuItems,
756
+ automationSteps,
757
+ calendarSources,
758
+ kznFile
759
+ } = packagedPlugin;
760
+ return {
761
+ ...manifest,
762
+ api_name: manifest.api_name,
763
+ artifacts: {
764
+ data_adornments: Object.values(dataAdornments),
765
+ floating_frames: Object.values(floatingFrames),
766
+ routable_pages: Object.values(routablePages),
767
+ toolbar_items: Object.values(toolbarItems),
768
+ js_action_templates: Object.values(actions),
769
+ route_scripts: Object.values(routeScripts),
770
+ object_settings_menu_items: Object.values(objectSettingsMenuItems),
771
+ automation_action_configs: Object.values(automationSteps),
772
+ calendar_sources: Object.values(calendarSources)
773
+ },
774
+ thumbnail,
775
+ kznFile,
776
+ releaseNotes,
777
+ base_config: formatBaseConfig(packagedPlugin),
778
+ setup_assistant: void 0,
779
+ services: manifest.services ?? []
780
+ };
781
+ };
782
+ // Annotate the CommonJS export names for ESM import in node:
783
+ 0 && (module.exports = {
784
+ AUTOMATION_SCRIPT_FILE,
785
+ AUTOMATION_STEPS_DIRECTORY_NAME,
786
+ BROWSER_ROUTE_SCRIPTS_DIRECTORY_NAME,
787
+ CALENDAR_SOURCES_DIRECTORY_NAME,
788
+ CALLBACK_SCRIPT_FILE,
789
+ CONFIG_FILE_NAME,
790
+ DATA_ADORNMENTS_DIRECTORY_NAME,
791
+ EVENT_SCRIPTS_DIRECTORY_NAME,
792
+ FLOATING_FRAMES_DIRECTORY_NAME,
793
+ JS_ACTIONS_DIRECTORY_NAME,
794
+ KZN_FILE_NAME,
795
+ MAIN_SCRIPT_FILE,
796
+ MANIFEST_FILE_NAME,
797
+ MESSAGE_SCRIPT_FILE,
798
+ OBJECT_SETTINGS_ITEMS_DIRECTORY_NAME,
799
+ RELEASE_NOTES_EXTENSION,
800
+ ROUTABLE_PAGES_DIRECTORY_NAME,
801
+ SCRIPT_EXTENSION,
802
+ SETUP_ASSISTANT_DIRECTORY_NAME,
803
+ STYLES_FILE_NAME,
804
+ THUMBNAIL_FILE_NAMES,
805
+ TOOLBAR_ITEMS_DIRECTORY_NAME,
806
+ USER_SETUP_ASSISTANT_DIRECTORY_NAME,
807
+ getAdornmentIcon,
808
+ getMinimizedConfig,
809
+ imagetoUint8Array,
810
+ maybeParseConfig,
811
+ minifyFiles,
812
+ packagePlugin,
813
+ parseManifestFromFiles,
814
+ sanitizeToAPIName,
815
+ scriptRuntimeToApiName,
816
+ thumbnailImageExtensions,
817
+ transformDeployablePlugin,
818
+ triggerImageExtensions,
819
+ zipToUint8Array
820
+ });
821
+ //# sourceMappingURL=index.cjs.map