streamby-core 0.29.3 → 0.29.5
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.
|
@@ -36,7 +36,24 @@ function createStreamByRouter(config) {
|
|
|
36
36
|
const router = express_1.default.Router();
|
|
37
37
|
if (config.encrypt)
|
|
38
38
|
(0, encryption_1.setEncryptionKey)(config.encrypt);
|
|
39
|
-
|
|
39
|
+
// Establish DB connections asynchronously (Postgres/Mongo + schema migrations).
|
|
40
|
+
// Until they're ready, HOLD incoming requests instead of letting them through —
|
|
41
|
+
// route handlers resolve projects/exports (e.g. the /menu-list export) against a
|
|
42
|
+
// live connection, so hitting them before startup finishes would 404. This gate
|
|
43
|
+
// makes the client's fetch wait for StreamBy's instances to come up.
|
|
44
|
+
let ready = false;
|
|
45
|
+
const readyPromise = (0, connectionManager_1.initConnections)(config.databases || [])
|
|
46
|
+
.catch((err) => {
|
|
47
|
+
console.error('❌ StreamBy: failed to initialize database connections:', err);
|
|
48
|
+
})
|
|
49
|
+
.finally(() => {
|
|
50
|
+
ready = true;
|
|
51
|
+
});
|
|
52
|
+
router.use((_req, _res, next) => {
|
|
53
|
+
if (ready)
|
|
54
|
+
return next();
|
|
55
|
+
readyPromise.then(() => next());
|
|
56
|
+
});
|
|
40
57
|
const adapter = config.adapter || (0, storage_1.createStorageProvider)(config.storageProviders);
|
|
41
58
|
if (config.databases) {
|
|
42
59
|
const allDbIds = config.databases.map(db => db.id);
|
|
@@ -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 {
|
|
@@ -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 });
|