@cyberismo/backend 0.0.8 → 0.0.10

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.
Files changed (152) hide show
  1. package/dist/app.js +22 -8
  2. package/dist/app.js.map +1 -1
  3. package/dist/common/validationSchemas.js +39 -0
  4. package/dist/common/validationSchemas.js.map +1 -0
  5. package/dist/domain/calculations/index.js +102 -0
  6. package/dist/domain/calculations/index.js.map +1 -0
  7. package/dist/domain/calculations/schema.js +24 -0
  8. package/dist/domain/calculations/schema.js.map +1 -0
  9. package/dist/domain/calculations/service.js +21 -0
  10. package/dist/domain/calculations/service.js.map +1 -0
  11. package/dist/domain/cardTypes/index.js +86 -0
  12. package/dist/domain/cardTypes/index.js.map +1 -0
  13. package/dist/domain/cardTypes/schema.js +19 -0
  14. package/dist/domain/cardTypes/schema.js.map +1 -0
  15. package/dist/domain/cardTypes/service.js +20 -0
  16. package/dist/domain/cardTypes/service.js.map +1 -0
  17. package/dist/{routes/cards.js → domain/cards/index.js} +52 -223
  18. package/dist/domain/cards/index.js.map +1 -0
  19. package/dist/domain/cards/lib.js +80 -0
  20. package/dist/domain/cards/lib.js.map +1 -0
  21. package/dist/domain/cards/service.js +178 -0
  22. package/dist/domain/cards/service.js.map +1 -0
  23. package/dist/domain/fieldTypes/index.js +87 -0
  24. package/dist/domain/fieldTypes/index.js.map +1 -0
  25. package/dist/domain/fieldTypes/schema.js +30 -0
  26. package/dist/domain/fieldTypes/schema.js.map +1 -0
  27. package/dist/domain/fieldTypes/service.js +24 -0
  28. package/dist/domain/fieldTypes/service.js.map +1 -0
  29. package/dist/domain/graphModels/index.js +50 -0
  30. package/dist/domain/graphModels/index.js.map +1 -0
  31. package/dist/domain/graphModels/schema.js +18 -0
  32. package/dist/domain/graphModels/schema.js.map +1 -0
  33. package/dist/domain/graphModels/service.js +16 -0
  34. package/dist/domain/graphModels/service.js.map +1 -0
  35. package/dist/domain/graphViews/index.js +50 -0
  36. package/dist/domain/graphViews/index.js.map +1 -0
  37. package/dist/domain/graphViews/schema.js +6 -0
  38. package/dist/domain/graphViews/schema.js.map +1 -0
  39. package/dist/domain/graphViews/service.js +16 -0
  40. package/dist/domain/graphViews/service.js.map +1 -0
  41. package/dist/domain/linkTypes/index.js +76 -0
  42. package/dist/domain/linkTypes/index.js.map +1 -0
  43. package/dist/domain/linkTypes/schema.js +18 -0
  44. package/dist/domain/linkTypes/schema.js.map +1 -0
  45. package/dist/domain/linkTypes/service.js +24 -0
  46. package/dist/domain/linkTypes/service.js.map +1 -0
  47. package/dist/domain/logicPrograms/index.js +25 -0
  48. package/dist/domain/logicPrograms/index.js.map +1 -0
  49. package/dist/domain/logicPrograms/service.js +9 -0
  50. package/dist/domain/logicPrograms/service.js.map +1 -0
  51. package/dist/domain/reports/index.js +50 -0
  52. package/dist/domain/reports/index.js.map +1 -0
  53. package/dist/domain/reports/schema.js +18 -0
  54. package/dist/domain/reports/schema.js.map +1 -0
  55. package/dist/domain/reports/service.js +16 -0
  56. package/dist/domain/reports/service.js.map +1 -0
  57. package/dist/domain/resources/index.js +128 -0
  58. package/dist/domain/resources/index.js.map +1 -0
  59. package/dist/domain/resources/schema.js +9 -0
  60. package/dist/domain/resources/schema.js.map +1 -0
  61. package/dist/domain/resources/service.js +258 -0
  62. package/dist/domain/resources/service.js.map +1 -0
  63. package/dist/domain/templates/index.js +81 -0
  64. package/dist/domain/templates/index.js.map +1 -0
  65. package/dist/domain/templates/schema.js +18 -0
  66. package/dist/domain/templates/schema.js.map +1 -0
  67. package/dist/domain/templates/service.js +23 -0
  68. package/dist/domain/templates/service.js.map +1 -0
  69. package/dist/domain/tree/index.js +44 -0
  70. package/dist/domain/tree/index.js.map +1 -0
  71. package/dist/domain/tree/service.js +17 -0
  72. package/dist/domain/tree/service.js.map +1 -0
  73. package/dist/domain/workflows/index.js +50 -0
  74. package/dist/domain/workflows/index.js.map +1 -0
  75. package/dist/domain/workflows/schema.js +18 -0
  76. package/dist/domain/workflows/schema.js.map +1 -0
  77. package/dist/domain/workflows/service.js +16 -0
  78. package/dist/domain/workflows/service.js.map +1 -0
  79. package/dist/export.js +3 -3
  80. package/dist/export.js.map +1 -1
  81. package/dist/middleware/zvalidator.js +8 -0
  82. package/dist/middleware/zvalidator.js.map +1 -0
  83. package/dist/public/THIRD-PARTY.txt +2452 -296
  84. package/dist/public/assets/index-jhDO7xT5.js +161493 -0
  85. package/dist/public/cropped-favicon-180x180.png +0 -0
  86. package/dist/public/cropped-favicon-192x192.png +0 -0
  87. package/dist/public/cropped-favicon-270x270.png +0 -0
  88. package/dist/public/cropped-favicon-32x32.png +0 -0
  89. package/dist/public/index.html +8 -1
  90. package/dist/types.js +14 -0
  91. package/dist/types.js.map +1 -0
  92. package/dist/utils.js +3 -1
  93. package/dist/utils.js.map +1 -1
  94. package/package.json +7 -3
  95. package/src/app.ts +22 -8
  96. package/src/common/validationSchemas.ts +46 -0
  97. package/src/domain/calculations/index.ts +121 -0
  98. package/src/domain/calculations/schema.ts +27 -0
  99. package/src/domain/calculations/service.ts +32 -0
  100. package/src/domain/cardTypes/index.ts +96 -0
  101. package/src/domain/cardTypes/schema.ts +19 -0
  102. package/src/domain/cardTypes/service.ts +28 -0
  103. package/src/{routes/cards.ts → domain/cards/index.ts} +82 -270
  104. package/src/domain/cards/lib.ts +103 -0
  105. package/src/domain/cards/service.ts +254 -0
  106. package/src/domain/fieldTypes/index.ts +97 -0
  107. package/src/domain/fieldTypes/schema.ts +30 -0
  108. package/src/domain/fieldTypes/service.ts +38 -0
  109. package/src/domain/graphModels/index.ts +54 -0
  110. package/src/domain/graphModels/schema.ts +18 -0
  111. package/src/domain/graphModels/service.ts +21 -0
  112. package/src/domain/graphViews/index.ts +53 -0
  113. package/src/domain/graphViews/schema.ts +6 -0
  114. package/src/domain/graphViews/service.ts +20 -0
  115. package/src/domain/linkTypes/index.ts +84 -0
  116. package/src/domain/linkTypes/schema.ts +19 -0
  117. package/src/domain/linkTypes/service.ts +34 -0
  118. package/src/domain/logicPrograms/index.ts +35 -0
  119. package/src/domain/logicPrograms/service.ts +25 -0
  120. package/src/domain/reports/index.ts +54 -0
  121. package/src/domain/reports/schema.ts +19 -0
  122. package/src/domain/reports/service.ts +21 -0
  123. package/src/domain/resources/index.ts +166 -0
  124. package/src/domain/resources/schema.ts +19 -0
  125. package/src/domain/resources/service.ts +436 -0
  126. package/src/domain/templates/index.ts +89 -0
  127. package/src/domain/templates/schema.ts +19 -0
  128. package/src/domain/templates/service.ts +29 -0
  129. package/src/domain/tree/index.ts +50 -0
  130. package/src/domain/tree/service.ts +22 -0
  131. package/src/domain/workflows/index.ts +54 -0
  132. package/src/domain/workflows/schema.ts +19 -0
  133. package/src/domain/workflows/service.ts +21 -0
  134. package/src/export.ts +9 -5
  135. package/src/middleware/commandManager.ts +1 -1
  136. package/src/middleware/zvalidator.ts +17 -0
  137. package/src/types.ts +20 -0
  138. package/src/utils.ts +4 -2
  139. package/dist/public/assets/index-D5kiRHuF.js +0 -111171
  140. package/dist/routes/cards.js.map +0 -1
  141. package/dist/routes/fieldTypes.js +0 -42
  142. package/dist/routes/fieldTypes.js.map +0 -1
  143. package/dist/routes/linkTypes.js +0 -42
  144. package/dist/routes/linkTypes.js.map +0 -1
  145. package/dist/routes/templates.js +0 -46
  146. package/dist/routes/templates.js.map +0 -1
  147. package/dist/routes/tree.js +0 -40
  148. package/dist/routes/tree.js.map +0 -1
  149. package/src/routes/fieldTypes.ts +0 -53
  150. package/src/routes/linkTypes.ts +0 -53
  151. package/src/routes/templates.ts +0 -52
  152. package/src/routes/tree.ts +0 -45
@@ -0,0 +1,436 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import type { ResourceContent } from '@cyberismo/data-handler/interfaces/resource-interfaces';
15
+ import type {
16
+ Card,
17
+ ResourceFolderType,
18
+ RemovableResourceTypes,
19
+ } from '@cyberismo/data-handler/interfaces/project-interfaces';
20
+ import {
21
+ type CommandManager,
22
+ isResourceFolderType,
23
+ moduleNameFromCardKey,
24
+ resourceName,
25
+ resourceNameToString,
26
+ } from '@cyberismo/data-handler';
27
+ import type { ResourceParams } from '../../common/validationSchemas.js';
28
+ import type { ValidateResourceParams } from './schema.js';
29
+
30
+ const resourceTypes: ResourceFolderType[] = [
31
+ 'calculations',
32
+ 'cardTypes',
33
+ 'fieldTypes',
34
+ 'graphModels',
35
+ 'graphViews',
36
+ 'linkTypes',
37
+ 'reports',
38
+ 'templates',
39
+ 'workflows',
40
+ ];
41
+
42
+ export async function buildResourceTree(commands: CommandManager) {
43
+ const project = await commands.showCmd.showProject();
44
+ const tree: unknown[] = [];
45
+ const allModuleResources: {
46
+ [prefix: string]: { [type: string]: unknown[] };
47
+ } = {};
48
+
49
+ // Process each resource type
50
+ for (const resourceType of resourceTypes) {
51
+ let rootResources: unknown[];
52
+ let moduleResources: { [prefix: string]: unknown[] };
53
+
54
+ if (resourceType === 'templates') {
55
+ ({ rootResources, moduleResources } = await processTemplates(
56
+ commands,
57
+ project.prefix,
58
+ ));
59
+ } else {
60
+ ({ rootResources, moduleResources } = await groupResourcesByPrefix(
61
+ commands,
62
+ resourceType,
63
+ project.prefix,
64
+ ));
65
+ }
66
+
67
+ // Add root level resources
68
+ if (rootResources.length > 0) {
69
+ tree.push({
70
+ id: resourceType,
71
+ type: 'resourceGroup',
72
+ name: resourceType,
73
+ children: rootResources,
74
+ });
75
+ }
76
+
77
+ // Collect module resources
78
+ Object.entries(moduleResources).forEach(([prefix, resources]) => {
79
+ if (!allModuleResources[prefix]) {
80
+ allModuleResources[prefix] = {};
81
+ }
82
+ allModuleResources[prefix][resourceType] = resources;
83
+ });
84
+ }
85
+
86
+ // Build modules section
87
+ if (Object.keys(allModuleResources).length > 0) {
88
+ const modules = Object.entries(allModuleResources).map(
89
+ ([prefix, resourcesByType]) => ({
90
+ id: `modules-${prefix}`,
91
+ type: 'module',
92
+ name: prefix,
93
+ children: Object.entries(resourcesByType).map(([type, resources]) => ({
94
+ id: `modules-${prefix}-${type}`,
95
+ type: 'resourceGroup',
96
+ name: type,
97
+ children: resources,
98
+ })),
99
+ }),
100
+ );
101
+
102
+ tree.push({
103
+ id: 'modules',
104
+ type: 'modulesGroup',
105
+ name: 'modules',
106
+ children: modules,
107
+ });
108
+ }
109
+
110
+ return tree;
111
+ }
112
+
113
+ // Helper function to parse resource prefix
114
+ function parseResourcePrefix(resource: string): {
115
+ prefix: string;
116
+ identifier: string;
117
+ } {
118
+ const parts = resource.split('/');
119
+ if (parts.length !== 3) {
120
+ throw new Error(`Invalid resource name: ${resource}`);
121
+ }
122
+ return {
123
+ prefix: parts[0],
124
+ identifier: parts[2],
125
+ };
126
+ }
127
+
128
+ // Helper function to create resource node with all data from showResource
129
+ // TODO: The types should be shared between backend and frontend
130
+ async function createResourceNode(
131
+ commands: CommandManager,
132
+ resourceType: ResourceFolderType,
133
+ name: string,
134
+ projectPrefix: string,
135
+ children?: unknown[],
136
+ ): Promise<{
137
+ id: string;
138
+ type: ResourceFolderType;
139
+ name: string;
140
+ data: ResourceContent | undefined;
141
+ children?: unknown[];
142
+ readOnly?: boolean;
143
+ }> {
144
+ const resourceData = await commands.showCmd.showResource(name);
145
+ const node: {
146
+ id: string;
147
+ type: ResourceFolderType;
148
+ name: string;
149
+ data: ResourceContent | undefined;
150
+ children?: unknown[];
151
+ readOnly?: boolean;
152
+ } = {
153
+ id: `${resourceType}-${name}`,
154
+ type: resourceType,
155
+ name: name,
156
+ data: resourceData,
157
+ readOnly: resourceName(name).prefix !== projectPrefix,
158
+ };
159
+
160
+ // Add file children for folder resources
161
+ if (isResourceFolderType(resourceType) && resourceType !== 'templates') {
162
+ try {
163
+ const fileNames = await commands.showCmd.showFileNames(
164
+ resourceName(name),
165
+ );
166
+ const fileNodes = fileNames.map((fileName: string) => ({
167
+ id: `${resourceType}-${name}-${fileName}`,
168
+ type: 'file',
169
+ name: `${name}/${fileName}`,
170
+ displayName: fileName,
171
+ readOnly: resourceName(name).prefix !== projectPrefix,
172
+ }));
173
+
174
+ node.children = children ? [...children, ...fileNodes] : fileNodes;
175
+ } catch (error) {
176
+ console.warn(`Failed to get file names for resource '${name}'`, error);
177
+ }
178
+ } else if (children) {
179
+ node.children = children;
180
+ }
181
+
182
+ return node;
183
+ }
184
+
185
+ // Helper function to recursively create card nodes with children
186
+ function createCardNode(
187
+ card: Card,
188
+ module: string,
189
+ projectPrefix: string,
190
+ ): unknown {
191
+ // Destructure to separate children from other card data
192
+ const { children, ...cardData } = card;
193
+
194
+ const cardNode: {
195
+ id: string;
196
+ type: string;
197
+ name: string;
198
+ data: Omit<Card, 'children'>;
199
+ children: unknown[];
200
+ readOnly: boolean;
201
+ } = {
202
+ id: `${card.key}`,
203
+ type: 'card',
204
+ name: `${module}/cards/${card.key}`,
205
+ data: cardData,
206
+ children: [],
207
+ readOnly: moduleNameFromCardKey(card.key) !== projectPrefix,
208
+ };
209
+
210
+ // Recursively process children if they exist
211
+ if (children && children.length > 0) {
212
+ cardNode.children = children.map((child) =>
213
+ createCardNode(child, module, projectPrefix),
214
+ );
215
+ }
216
+
217
+ return cardNode;
218
+ }
219
+
220
+ // Helper function to process templates using templateTree query
221
+ async function processTemplates(
222
+ commands: CommandManager,
223
+ projectPrefix: string,
224
+ ) {
225
+ const templates = await commands.showCmd.showResources('templates');
226
+ const templateTree = await commands.showCmd.showAllTemplateCards();
227
+
228
+ const rootTemplates: { [templateName: string]: unknown[] } = {};
229
+ const moduleTemplates: {
230
+ [prefix: string]: { [templateName: string]: unknown[] };
231
+ } = {};
232
+
233
+ for (const { name, cards } of templateTree) {
234
+ for (const card of cards) {
235
+ const { prefix } = parseResourcePrefix(name);
236
+ const cardNode = createCardNode(card, prefix, projectPrefix);
237
+
238
+ if (prefix === projectPrefix || !prefix) {
239
+ if (!rootTemplates[name]) {
240
+ templates.splice(templates.indexOf(name), 1);
241
+ rootTemplates[name] = [];
242
+ }
243
+ rootTemplates[name].push(cardNode);
244
+ } else {
245
+ if (!moduleTemplates[prefix]) {
246
+ moduleTemplates[prefix] = {};
247
+ }
248
+ if (!moduleTemplates[prefix][name]) {
249
+ templates.splice(templates.indexOf(name), 1);
250
+ moduleTemplates[prefix][name] = [];
251
+ }
252
+ moduleTemplates[prefix][name].push(cardNode);
253
+ }
254
+ }
255
+ }
256
+
257
+ const rootResources = await Promise.all(
258
+ Object.entries(rootTemplates).map(([templateName, cards]) =>
259
+ createResourceNode(
260
+ commands,
261
+ 'templates',
262
+ templateName,
263
+ projectPrefix,
264
+ cards,
265
+ ),
266
+ ),
267
+ );
268
+
269
+ const moduleResources: { [prefix: string]: unknown[] } = {};
270
+ for (const [prefix, templates] of Object.entries(moduleTemplates)) {
271
+ moduleResources[prefix] = await Promise.all(
272
+ Object.entries(templates).map(([templateName, cards]) =>
273
+ createResourceNode(
274
+ commands,
275
+ 'templates',
276
+ templateName,
277
+ projectPrefix,
278
+ cards,
279
+ ),
280
+ ),
281
+ );
282
+ }
283
+
284
+ // Add also templates that do not have any cards
285
+ for (const template of templates) {
286
+ const { prefix } = parseResourcePrefix(template);
287
+ if (prefix === projectPrefix) {
288
+ if (!rootResources.find((resource) => resource.name === template)) {
289
+ rootResources.push(
290
+ await createResourceNode(
291
+ commands,
292
+ 'templates',
293
+ template,
294
+ projectPrefix,
295
+ ),
296
+ );
297
+ }
298
+ } else {
299
+ if (!moduleResources[prefix]) {
300
+ moduleResources[prefix] = [];
301
+ }
302
+ if (
303
+ !moduleResources[prefix].find(
304
+ (resource) => (resource as { name: string }).name === template,
305
+ )
306
+ ) {
307
+ moduleResources[prefix].push(
308
+ await createResourceNode(
309
+ commands,
310
+ 'templates',
311
+ template,
312
+ projectPrefix,
313
+ ),
314
+ );
315
+ }
316
+ }
317
+ }
318
+
319
+ return { rootResources, moduleResources };
320
+ }
321
+
322
+ // Helper function to group regular resources by prefix
323
+ async function groupResourcesByPrefix(
324
+ commands: CommandManager,
325
+ resourceType: ResourceFolderType,
326
+ projectPrefix: string,
327
+ ) {
328
+ const resourceNames = await commands.showCmd.showResources(resourceType);
329
+ const resources = await Promise.all(
330
+ resourceNames.map((name: string) =>
331
+ createResourceNode(commands, resourceType, name, projectPrefix),
332
+ ),
333
+ );
334
+
335
+ const rootResources: unknown[] = [];
336
+ const moduleResources: { [prefix: string]: unknown[] } = {};
337
+
338
+ resources.forEach((resource) => {
339
+ const { prefix } = parseResourcePrefix(resource.name);
340
+ if (prefix === projectPrefix || !prefix) {
341
+ rootResources.push(resource);
342
+ } else {
343
+ if (!moduleResources[prefix]) {
344
+ moduleResources[prefix] = [];
345
+ }
346
+ moduleResources[prefix].push(resource);
347
+ }
348
+ });
349
+
350
+ return { rootResources, moduleResources };
351
+ }
352
+
353
+ /**
354
+ * Delete a resource.
355
+ * @param commands Command manager.
356
+ * @param resource Resource to delete.
357
+ */
358
+ export async function deleteResource(
359
+ commands: CommandManager,
360
+ resource: ResourceParams,
361
+ ) {
362
+ return commands.removeCmd.remove(
363
+ resource.type.substring(
364
+ 0,
365
+ resource.type.length - 1,
366
+ ) as RemovableResourceTypes,
367
+ resourceNameToString(resource),
368
+ );
369
+ }
370
+
371
+ /**
372
+ * Get the content of a file in a resource.
373
+ * @param commands Command manager.
374
+ * @param module Name of the module.
375
+ * @param type Name of the type.
376
+ * @param resource Name of the resource.
377
+ * @param fileName Name of the file.
378
+ * @returns The content of the file.
379
+ */
380
+ export async function getFileContent(
381
+ commands: CommandManager,
382
+ module: string,
383
+ type: string,
384
+ resource: string,
385
+ fileName: string,
386
+ ) {
387
+ return commands.showCmd.showFile(
388
+ resourceName(`${module}/${type}/${resource}`),
389
+ fileName,
390
+ );
391
+ }
392
+
393
+ /**
394
+ * Update a file of a folder resource. Cannot be used to create a new file.
395
+ * @param commands Command manager.
396
+ * @param module Name of the module.
397
+ * @param type Name of the type.
398
+ * @param resource Name of the resource.
399
+ * @param fileName Name of the file.
400
+ * @param changedContent The new content for the file.
401
+ * @returns The updated file content.
402
+ */
403
+ export async function updateFile(
404
+ commands: CommandManager,
405
+ module: string,
406
+ type: string,
407
+ resource: string,
408
+ fileName: string,
409
+ changedContent: string,
410
+ ) {
411
+ return commands.editCmd.editResourceContent(
412
+ resourceName(`${module}/${type}/${resource}`),
413
+ fileName,
414
+ changedContent,
415
+ );
416
+ }
417
+
418
+ /**
419
+ * Validate a single resource.
420
+ * @param commands Command manager.
421
+ * @param resource Resource to validate.
422
+ * @returns Validation result with errors and validity status.
423
+ */
424
+ export async function validateResource(
425
+ commands: CommandManager,
426
+ resource: ValidateResourceParams,
427
+ ) {
428
+ const errors = await commands.validateCmd.validateResource(
429
+ resource,
430
+ commands.project,
431
+ );
432
+
433
+ return {
434
+ errors: errors.split('\n\n').filter((error) => error !== ''),
435
+ };
436
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import { Hono } from 'hono';
15
+ import { isSSGContext } from '../../export.js';
16
+ import * as templateService from './service.js';
17
+ import { createTemplateSchema } from './schema.js';
18
+ import { zValidator } from '../../middleware/zvalidator.js';
19
+
20
+ const router = new Hono();
21
+
22
+ /**
23
+ * @swagger
24
+ * /api/templates:
25
+ * get:
26
+ * summary: Returns a list of all templates in the defined project.
27
+ * description: List of templates includes only the names of the templates in the project.
28
+ * responses:
29
+ * 200:
30
+ * description: Array containing the names of the project templates.
31
+ * 400:
32
+ * description: Error in reading project details.
33
+ * 500:
34
+ * description: project_path not set or other internal error
35
+ */
36
+ router.get('/', async (c) => {
37
+ // We do not need templates in ssg context
38
+ if (isSSGContext(c)) {
39
+ return c.json([]);
40
+ }
41
+ const commands = c.get('commands');
42
+
43
+ try {
44
+ const response = await templateService.getTemplatesWithDetails(commands);
45
+ return c.json(response);
46
+ } catch (error) {
47
+ return c.json(
48
+ {
49
+ error: `${error instanceof Error ? error.message : 'Unknown error'} from path ${c.get('projectPath')}`,
50
+ },
51
+ 500,
52
+ );
53
+ }
54
+ });
55
+
56
+ /**
57
+ * @swagger
58
+ * /api/templates:
59
+ * post:
60
+ * summary: Create a new template
61
+ * description: Creates a new template with the specified identifier
62
+ * requestBody:
63
+ * required: true
64
+ * content:
65
+ * application/json:
66
+ * schema:
67
+ * type: object
68
+ * properties:
69
+ * identifier:
70
+ * type: string
71
+ * required:
72
+ * - identifier
73
+ * responses:
74
+ * 200:
75
+ * description: Template created successfully
76
+ * 400:
77
+ * description: Invalid request body
78
+ * 500:
79
+ * description: Server error
80
+ */
81
+ router.post('/', zValidator('json', createTemplateSchema), async (c) => {
82
+ const commands = c.get('commands');
83
+ const { identifier } = c.req.valid('json');
84
+
85
+ await templateService.createTemplate(commands, identifier);
86
+ return c.json({ message: 'Template created successfully' });
87
+ });
88
+
89
+ export default router;
@@ -0,0 +1,19 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import { z } from 'zod';
15
+ import { identifierSchema } from '../../common/validationSchemas.js';
16
+
17
+ export const createTemplateSchema = z.object({
18
+ identifier: identifierSchema,
19
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import type { CommandManager } from '@cyberismo/data-handler';
15
+
16
+ export async function getTemplatesWithDetails(commands: CommandManager) {
17
+ const response = await commands.showCmd.showTemplatesWithDetails();
18
+ if (!response) {
19
+ throw new Error('No templates found');
20
+ }
21
+ return response;
22
+ }
23
+
24
+ export async function createTemplate(
25
+ commands: CommandManager,
26
+ templateName: string,
27
+ ) {
28
+ await commands.createCmd.createTemplate(templateName, '');
29
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import { Hono } from 'hono';
15
+ import * as treeService from './service.js';
16
+ import { isSSGContext } from '../../export.js';
17
+
18
+ const router = new Hono();
19
+
20
+ /**
21
+ * @swagger
22
+ * /api/tree:
23
+ * get:
24
+ * summary: Returns a card tree of all cards in the defined project.
25
+ * description: List of cards displayed in hierarchical format as a tree
26
+ * responses:
27
+ * 200:
28
+ * description: Object containing the project cards in tree format. See definitions.ts/Card for the structure.
29
+ * 400:
30
+ * description: Error in reading project details.
31
+ * 500:
32
+ * description: project_path not set or other internal error
33
+ */
34
+ router.get('/', async (c) => {
35
+ const commands = c.get('commands');
36
+
37
+ try {
38
+ const response = await treeService.getCardTree(commands, isSSGContext(c));
39
+ return c.json(response);
40
+ } catch (error) {
41
+ return c.json(
42
+ {
43
+ error: `${error instanceof Error ? error.message : 'Unknown error'} from path ${c.get('projectPath')}`,
44
+ },
45
+ 500,
46
+ );
47
+ }
48
+ });
49
+
50
+ export default router;
@@ -0,0 +1,22 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import type { CommandManager } from '@cyberismo/data-handler';
15
+
16
+ export async function getCardTree(commands: CommandManager, isSsg: boolean) {
17
+ await commands.calculateCmd.generate();
18
+ return commands.calculateCmd.runQuery(
19
+ 'tree',
20
+ isSsg ? 'exportedSite' : 'localApp',
21
+ );
22
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import { Hono } from 'hono';
15
+ import * as workflowService from './service.js';
16
+ import { createWorkflowSchema } from './schema.js';
17
+ import { zValidator } from '../../middleware/zvalidator.js';
18
+
19
+ const router = new Hono();
20
+
21
+ /**
22
+ * @swagger
23
+ * /api/workflows:
24
+ * post:
25
+ * summary: Create a new workflow
26
+ * description: Creates a new workflow with the specified identifier
27
+ * requestBody:
28
+ * required: true
29
+ * content:
30
+ * application/json:
31
+ * schema:
32
+ * type: object
33
+ * properties:
34
+ * identifier:
35
+ * type: string
36
+ * required:
37
+ * - identifier
38
+ * responses:
39
+ * 200:
40
+ * description: Workflow created successfully
41
+ * 400:
42
+ * description: Invalid request body
43
+ * 500:
44
+ * description: Server error
45
+ */
46
+ router.post('/', zValidator('json', createWorkflowSchema), async (c) => {
47
+ const commands = c.get('commands');
48
+ const { identifier } = c.req.valid('json');
49
+
50
+ await workflowService.createWorkflow(commands, identifier);
51
+ return c.json({ message: 'Workflow created successfully' });
52
+ });
53
+
54
+ export default router;