streamby-core 0.29.2 → 0.29.4

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.
@@ -102,6 +102,44 @@ function connectionRouter(config) {
102
102
  res.status(500).json({ message: 'Failed to add API connection', details: err.message });
103
103
  }
104
104
  });
105
+ // Update an API connection (name, url, method, prefix, credentialId, description)
106
+ router.patch('/projects/:id/connections/api/:connectionId', async (req, res) => {
107
+ try {
108
+ const auth = req.auth;
109
+ if (auth.role !== 'admin' && auth.role !== 'editor') {
110
+ return res.status(403).json({ message: 'Permission denied' });
111
+ }
112
+ const { id: projectId, connectionId } = req.params;
113
+ const { name, apiUrl, method, description, credentialId, prefix } = req.body;
114
+ if (method && !VALID_METHODS.includes(method)) {
115
+ return res.status(400).json({ message: `method must be one of: ${VALID_METHODS.join(', ')}` });
116
+ }
117
+ const project = await Project.findOne({ _id: projectId });
118
+ if (!project)
119
+ return res.status(404).json({ message: 'Project not found' });
120
+ if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
121
+ return res.status(403).json({ message: 'Unauthorized project access' });
122
+ }
123
+ if (credentialId) {
124
+ const credExists = project.credentials?.some((c) => c.id === credentialId);
125
+ if (!credExists) {
126
+ return res.status(400).json({ message: 'Credential not found in project' });
127
+ }
128
+ }
129
+ const updated = await (0, apiConnection_1.updateApiConnection)(config, projectId, connectionId, {
130
+ ...(name !== undefined && { name }),
131
+ ...(apiUrl !== undefined && { apiUrl }),
132
+ ...(method !== undefined && { method }),
133
+ ...(description !== undefined && { description }),
134
+ ...(prefix !== undefined && { prefix }),
135
+ ...(credentialId !== undefined && { credentialId }),
136
+ });
137
+ return res.status(200).json({ data: updated });
138
+ }
139
+ catch (err) {
140
+ res.status(500).json({ message: 'Failed to update API connection', details: err.message });
141
+ }
142
+ });
105
143
  // Execute the request represented by an API connection
106
144
  router.get('/projects/:id/get-connection/:connectionId', async (req, res) => {
107
145
  try {
@@ -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) {
@@ -7,4 +7,12 @@ export declare function addApiConnection(config: StreamByConfig, projectId: stri
7
7
  description?: string;
8
8
  credentialId?: string;
9
9
  }): Promise<ApiConnection>;
10
+ export declare function updateApiConnection(config: StreamByConfig, projectId: string, connectionId: string, data: {
11
+ name?: string;
12
+ apiUrl?: string;
13
+ method?: ApiConnectionMethod;
14
+ prefix?: string;
15
+ description?: string;
16
+ credentialId?: string;
17
+ }): Promise<ApiConnection>;
10
18
  export declare function deleteApiConnection(config: StreamByConfig, projectId: string, connectionId: string): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addApiConnection = addApiConnection;
4
+ exports.updateApiConnection = updateApiConnection;
4
5
  exports.deleteApiConnection = deleteApiConnection;
5
6
  const mongodb_1 = require("mongodb");
6
7
  const manager_1 = require("../models/manager");
@@ -27,6 +28,30 @@ async function addApiConnection(config, projectId, data) {
27
28
  }
28
29
  return connection;
29
30
  }
31
+ async function updateApiConnection(config, projectId, connectionId, data) {
32
+ const ProjectModel = (0, manager_1.getModel)('projects');
33
+ const project = await ProjectModel.findOne({ _id: projectId });
34
+ if (!project)
35
+ throw new Error('Project not found.');
36
+ const connections = project.apiConnections ?? [];
37
+ const index = connections.findIndex((c) => c.id === connectionId);
38
+ if (index === -1)
39
+ throw new Error('API connection not found.');
40
+ const updated = {
41
+ ...connections[index],
42
+ ...(data.name !== undefined && { name: data.name }),
43
+ ...(data.apiUrl !== undefined && { apiUrl: data.apiUrl }),
44
+ ...(data.method !== undefined && { method: data.method }),
45
+ ...(data.prefix !== undefined && { prefix: data.prefix }),
46
+ ...(data.description !== undefined && { description: data.description }),
47
+ ...(data.credentialId !== undefined && { credentialId: data.credentialId }),
48
+ };
49
+ connections[index] = updated;
50
+ const result = await ProjectModel.update({ _id: projectId }, { $set: { apiConnections: connections } });
51
+ if (!result)
52
+ throw new Error('Failed to update API connection.');
53
+ return updated;
54
+ }
30
55
  async function deleteApiConnection(config, projectId, connectionId) {
31
56
  const ProjectModel = (0, manager_1.getModel)('projects');
32
57
  const project = await ProjectModel.findOne({ _id: projectId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.29.2",
3
+ "version": "0.29.4",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",