streamby-core 0.29.1 → 0.29.3

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.
@@ -12,32 +12,49 @@ const encryption_1 = require("../../utils/encryption");
12
12
  const DEFAULT_NODE_SCHEMA = {
13
13
  nodes: [
14
14
  {
15
- id: 'client',
16
- type: 'clientNode',
15
+ id: 'request',
16
+ type: 'requestNode',
17
17
  position: { x: 0, y: 100 },
18
- data: { label: 'Client', subtitle: 'GET' },
18
+ data: { label: 'Request', subtitle: 'GET' },
19
19
  width: 148,
20
20
  height: 100,
21
21
  },
22
22
  {
23
23
  id: 'streamby',
24
24
  type: 'streambyNode',
25
- position: { x: 240, y: 100 },
25
+ position: { x: 280, y: 100 },
26
26
  data: { label: 'StreamBy', subtitle: 'Middleware' },
27
27
  width: 158,
28
28
  height: 100,
29
29
  },
30
+ {
31
+ id: 'response',
32
+ type: 'responseNode',
33
+ position: { x: 560, y: 100 },
34
+ data: { label: 'Response', subtitle: 'HTTP Response' },
35
+ width: 148,
36
+ height: 100,
37
+ },
30
38
  ],
31
39
  edges: [
32
40
  {
33
- id: 'e-client-streamby',
34
- source: 'client',
41
+ id: 'e-request-streamby',
42
+ source: 'request',
35
43
  sourceHandle: 'out-right',
36
44
  target: 'streamby',
37
45
  targetHandle: 'in-left',
38
46
  animated: true,
39
47
  style: { stroke: '#38B6FF', strokeWidth: 2 },
40
48
  },
49
+ {
50
+ id: 'e-streamby-response',
51
+ source: 'streamby',
52
+ sourceHandle: 'out-right',
53
+ target: 'response',
54
+ targetHandle: 'in-left',
55
+ animated: true,
56
+ style: { stroke: '#fbbf24', strokeWidth: 2 },
57
+ },
41
58
  ],
42
59
  };
43
60
  function exportRouter(config) {
@@ -9,6 +9,70 @@ const mongodb_1 = require("mongodb");
9
9
  function workflowRouter(config) {
10
10
  const router = (0, express_1.Router)();
11
11
  const Project = (0, manager_1.getModel)('projects');
12
+ // Single-workflow endpoints — each project has exactly one Architecture workflow
13
+ router.get('/projects/:id/workflow', async (req, res) => {
14
+ try {
15
+ const auth = await config.authProvider(req);
16
+ if (!auth?.userId)
17
+ return res.status(401).json({ message: 'Unauthorized' });
18
+ const project = await Project.findOne({ _id: req.params.id });
19
+ if (!project)
20
+ return res.status(404).json({ message: 'Project not found' });
21
+ if (!(0, auth_1.isProjectMember)(project, auth.userId))
22
+ return res.status(403).json({ message: 'Unauthorized access' });
23
+ const workflow = (project.workflows ?? [])[0] ?? null;
24
+ if (!workflow)
25
+ return res.status(404).json({ message: 'No workflow found for this project' });
26
+ res.json({ data: workflow, message: 'Workflow fetched successfully' });
27
+ }
28
+ catch (err) {
29
+ res.status(500).json({ message: 'Failed to fetch workflow', details: err.message });
30
+ }
31
+ });
32
+ router.patch('/projects/:id/workflow', async (req, res) => {
33
+ try {
34
+ const auth = await config.authProvider(req);
35
+ if (!auth?.userId)
36
+ return res.status(401).json({ message: 'Unauthorized' });
37
+ const projectId = req.params.id;
38
+ const project = await Project.findOne({ _id: projectId });
39
+ if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
40
+ return res.status(403).json({ message: 'Unauthorized project access' });
41
+ }
42
+ const existing = (project.workflows ?? [])[0];
43
+ if (!existing)
44
+ return res.status(404).json({ message: 'No workflow found for this project' });
45
+ const { name, description, status, nodeSchema } = req.body;
46
+ const updated = {
47
+ ...existing,
48
+ name: name ?? existing.name,
49
+ description: description ?? existing.description,
50
+ status: status ?? existing.status,
51
+ nodeSchema: nodeSchema !== undefined ? nodeSchema : existing.nodeSchema,
52
+ updatedAt: new Date(),
53
+ };
54
+ if (project.dbType === 'sql') {
55
+ const SqlProject = (0, manager_1.getModel)('projects', 'sql');
56
+ const updatedWorkflows = (project.workflows ?? []).map((w, i) => i === 0 ? updated : w);
57
+ await SqlProject.update({ _id: projectId }, { workflows: updatedWorkflows });
58
+ }
59
+ else {
60
+ await Project.update({ _id: new mongodb_1.ObjectId(projectId), 'workflows.id': existing.id }, {
61
+ $set: {
62
+ 'workflows.$.name': updated.name,
63
+ 'workflows.$.description': updated.description,
64
+ 'workflows.$.status': updated.status,
65
+ 'workflows.$.nodeSchema': updated.nodeSchema,
66
+ 'workflows.$.updatedAt': updated.updatedAt,
67
+ },
68
+ });
69
+ }
70
+ res.json({ data: updated, message: 'Workflow updated successfully' });
71
+ }
72
+ catch (err) {
73
+ res.status(500).json({ message: 'Failed to update workflow', details: err.message });
74
+ }
75
+ });
12
76
  router.get('/projects/:id/workflows', async (req, res) => {
13
77
  try {
14
78
  const auth = await config.authProvider(req);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.29.1",
3
+ "version": "0.29.3",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",