@cyberismo/backend 0.0.11 → 0.0.12

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.
@@ -11,7 +11,7 @@
11
11
  name="msapplication-TileImage"
12
12
  content="/cropped-favicon-270x270.png"
13
13
  />
14
- <script type="module" crossorigin src="/assets/index-jhDO7xT5.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-D46PNX0J.js"></script>
15
15
  <link rel="stylesheet" crossorigin href="/assets/index-BngW8o1w.css">
16
16
  </head>
17
17
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyberismo/backend",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Express backend for Cyberismo",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [],
@@ -8,16 +8,14 @@
8
8
  "license": "AGPL-3.0",
9
9
  "dependencies": {
10
10
  "@asciidoctor/core": "^3.0.4",
11
- "@hono/node-server": "^1.14.1",
11
+ "@hono/node-server": "^1.19.1",
12
12
  "@hono/zod-validator": "^0.7.2",
13
- "dotenv": "^16.5.0",
14
- "hono": "^4.7.5",
15
- "mime-types": "^3.0.1",
16
- "zod": "^4.0.17",
17
- "@cyberismo/data-handler": "0.0.11"
13
+ "dotenv": "^17.2.2",
14
+ "hono": "^4.9.7",
15
+ "zod": "^4.1.5",
16
+ "@cyberismo/data-handler": "0.0.12"
18
17
  },
19
18
  "devDependencies": {
20
- "@types/mime-types": "^3.0.0",
21
19
  "@cyberismo/app": "0.0.2"
22
20
  },
23
21
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  import { Hono } from 'hono';
15
15
  import { isSSGContext } from '../../export.js';
16
16
  import * as templateService from './service.js';
17
- import { createTemplateSchema } from './schema.js';
17
+ import { createTemplateSchema, addTemplateCardSchema } from './schema.js';
18
18
  import { zValidator } from '../../middleware/zvalidator.js';
19
19
 
20
20
  const router = new Hono();
@@ -86,4 +86,51 @@ router.post('/', zValidator('json', createTemplateSchema), async (c) => {
86
86
  return c.json({ message: 'Template created successfully' });
87
87
  });
88
88
 
89
+ /**
90
+ * @swagger
91
+ * /api/templates/card:
92
+ * post:
93
+ * summary: Create a new template card
94
+ * description: Adds a new card to a template. New card will be created as a child of the parentKey, if parentKey value is defined.
95
+ * requestBody:
96
+ * required: true
97
+ * content:
98
+ * application/json:
99
+ * schema:
100
+ * type: object
101
+ * properties:
102
+ * template:
103
+ * type: string
104
+ * cardType:
105
+ * type: string
106
+ * parentKey:
107
+ * type: string
108
+ * count:
109
+ * type: number
110
+ * description: Number of cards to create
111
+ * required:
112
+ * - template
113
+ * - cardType
114
+ * responses:
115
+ * 200:
116
+ * description: Template card(s) created successfully
117
+ * 400:
118
+ * description: Invalid request body
119
+ * 500:
120
+ * description: Server error
121
+ */
122
+ router.post('/card', zValidator('json', addTemplateCardSchema), async (c) => {
123
+ const commands = c.get('commands');
124
+ const { template, cardType, parentKey, count } = c.req.valid('json');
125
+
126
+ const added = await templateService.addTemplateCard(
127
+ commands,
128
+ template,
129
+ cardType,
130
+ parentKey,
131
+ count,
132
+ );
133
+ return c.json({ cards: added });
134
+ });
135
+
89
136
  export default router;
@@ -17,3 +17,10 @@ import { identifierSchema } from '../../common/validationSchemas.js';
17
17
  export const createTemplateSchema = z.object({
18
18
  identifier: identifierSchema,
19
19
  });
20
+
21
+ export const addTemplateCardSchema = z.object({
22
+ template: z.string(),
23
+ cardType: z.string().min(1, 'cardType is required'),
24
+ parentKey: z.string().optional(),
25
+ count: z.number().int().positive().optional(),
26
+ });
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import type { CommandManager } from '@cyberismo/data-handler';
15
+ import { resourceName } from '@cyberismo/data-handler';
15
16
 
16
17
  export async function getTemplatesWithDetails(commands: CommandManager) {
17
18
  const response = await commands.showCmd.showTemplatesWithDetails();
@@ -27,3 +28,26 @@ export async function createTemplate(
27
28
  ) {
28
29
  await commands.createCmd.createTemplate(templateName, '');
29
30
  }
31
+
32
+ export async function addTemplateCard(
33
+ commands: CommandManager,
34
+ template: string,
35
+ cardType: string,
36
+ parentKey?: string,
37
+ count?: number,
38
+ ) {
39
+ const { identifier, type } = resourceName(template);
40
+ if (type !== 'templates') {
41
+ throw new Error('Invalid template resource');
42
+ }
43
+ const added = await commands.createCmd.addCards(
44
+ cardType,
45
+ identifier,
46
+ parentKey,
47
+ count,
48
+ );
49
+ if (!added || added.length === 0) {
50
+ throw new Error('No cards created');
51
+ }
52
+ return added;
53
+ }
package/src/main.ts CHANGED
@@ -18,7 +18,7 @@ import dotenv from 'dotenv';
18
18
  dotenv.config();
19
19
 
20
20
  if (process.argv.includes('--export')) {
21
- exportSite(process.env.npm_config_project_path || '');
21
+ await exportSite(process.env.npm_config_project_path || '');
22
22
  } else {
23
- startServer(process.env.npm_config_project_path || '');
23
+ await startServer(process.env.npm_config_project_path || '');
24
24
  }