streamby-core 0.23.0 → 0.23.2
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.
- package/dist/middleware/createRouter.js +2 -0
- package/dist/middleware/public.d.ts +2 -0
- package/dist/middleware/public.js +9 -0
- package/dist/middleware/routes/export.js +80 -0
- package/dist/middleware/routes/project.js +4 -4
- package/dist/models/Model.js +5 -5
- package/dist/services/auth.d.ts +1 -1
- package/dist/services/auth.js +3 -0
- package/dist/utils/auth.d.ts +2 -1
- package/dist/utils/auth.js +4 -1
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ const database_1 = require("./routes/database");
|
|
|
13
13
|
const storage_2 = require("./routes/storage");
|
|
14
14
|
const project_1 = require("./routes/project");
|
|
15
15
|
const export_1 = require("./routes/export");
|
|
16
|
+
const auth_2 = require("../services/auth");
|
|
16
17
|
function createStreamByRouter(config) {
|
|
17
18
|
const router = express_1.default.Router();
|
|
18
19
|
(0, connectionManager_1.initConnections)(config.databases || []);
|
|
@@ -26,6 +27,7 @@ function createStreamByRouter(config) {
|
|
|
26
27
|
(0, manager_1.registerModel)('users', [mainDb.id], 'users');
|
|
27
28
|
}
|
|
28
29
|
}
|
|
30
|
+
router.use((0, auth_2.authenticate)(config));
|
|
29
31
|
router.use((0, auth_1.authRouter)(config));
|
|
30
32
|
router.use((0, database_1.databaseRouter)(config));
|
|
31
33
|
router.use((0, storage_2.storageRouter)(config));
|
|
@@ -147,5 +147,85 @@ function exportRouter(config) {
|
|
|
147
147
|
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
+
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
|
151
|
+
try {
|
|
152
|
+
const { projectId, exportName } = req.params;
|
|
153
|
+
const project = await Project.findOne({ _id: projectId });
|
|
154
|
+
if (!project) {
|
|
155
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
156
|
+
}
|
|
157
|
+
const exportMetadata = project.exports.find((e) => e.name === exportName);
|
|
158
|
+
if (!exportMetadata) {
|
|
159
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
160
|
+
}
|
|
161
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
162
|
+
if (!targetDb) {
|
|
163
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
164
|
+
}
|
|
165
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
166
|
+
let data;
|
|
167
|
+
if (project.dbType === 'nosql') {
|
|
168
|
+
const db = connection.client.db();
|
|
169
|
+
if (exportMetadata.type === 'raw') {
|
|
170
|
+
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
171
|
+
data = rawData ? rawData.json : null;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
data = await db.collection(exportMetadata.collectionName).find({ __metadata: { $exists: false } }).toArray();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (project.dbType === 'sql') {
|
|
178
|
+
// SQL implementation for public exports will go here
|
|
179
|
+
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
180
|
+
}
|
|
181
|
+
if (!data) {
|
|
182
|
+
return res.status(404).json({ message: 'Export data not found' });
|
|
183
|
+
}
|
|
184
|
+
res.json(data); // Return the raw data directly
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
|
191
|
+
try {
|
|
192
|
+
const { projectId, exportName } = req.params;
|
|
193
|
+
const project = await Project.findOne({ _id: projectId });
|
|
194
|
+
if (!project) {
|
|
195
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
196
|
+
}
|
|
197
|
+
const exportMetadata = project.exports.find((e) => e.name === exportName);
|
|
198
|
+
if (!exportMetadata) {
|
|
199
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
200
|
+
}
|
|
201
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
202
|
+
if (!targetDb) {
|
|
203
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
204
|
+
}
|
|
205
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
206
|
+
let data;
|
|
207
|
+
if (project.dbType === 'nosql') {
|
|
208
|
+
const db = connection.client.db();
|
|
209
|
+
if (exportMetadata.type === 'raw') {
|
|
210
|
+
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
211
|
+
data = rawData ? rawData.json : null;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
data = await db.collection(exportMetadata.collectionName).find({ __metadata: { $exists: false } }).toArray();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (project.dbType === 'sql') {
|
|
218
|
+
// SQL implementation for public exports will go here
|
|
219
|
+
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
220
|
+
}
|
|
221
|
+
if (!data) {
|
|
222
|
+
return res.status(404).json({ message: 'Export data not found' });
|
|
223
|
+
}
|
|
224
|
+
res.json(data); // Return the raw data directly
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
150
230
|
return router;
|
|
151
231
|
}
|
|
@@ -146,14 +146,14 @@ function projectRouter(config) {
|
|
|
146
146
|
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
147
147
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
148
148
|
}
|
|
149
|
-
await Project.delete({ _id: projectId });
|
|
149
|
+
await Project.useDbType(project.dbType).delete({ _id: projectId });
|
|
150
150
|
const allProjects = await Project.find({});
|
|
151
151
|
const projects = allProjects
|
|
152
|
-
.filter(
|
|
153
|
-
const isMember =
|
|
152
|
+
.filter(p => {
|
|
153
|
+
const isMember = p.members?.some((m) => m.userId?.toString() === auth.userId?.toString());
|
|
154
154
|
return isMember; // Only include projects where the user is a member
|
|
155
155
|
})
|
|
156
|
-
.map(
|
|
156
|
+
.map(p => mapProjectToResponseFormat(p, auth.userId));
|
|
157
157
|
res.status(200).json({ success: true, projects: projects, message: 'Project deleted successfully' });
|
|
158
158
|
}
|
|
159
159
|
catch (err) {
|
package/dist/models/Model.js
CHANGED
|
@@ -34,11 +34,11 @@ class Model {
|
|
|
34
34
|
if (this.tableName === 'projects' && processedFilter.members && processedFilter.members.$elemMatch) {
|
|
35
35
|
// Handle members filter for SQL projects
|
|
36
36
|
const userId = processedFilter.members.$elemMatch.userId;
|
|
37
|
-
const query = `
|
|
38
|
-
SELECT p.*, pm."userId" as memberUserId, pm.archived as memberArchived
|
|
39
|
-
FROM "projects" p
|
|
40
|
-
JOIN "project_members" pm ON p.id = pm."projectId"
|
|
41
|
-
WHERE pm."userId" = $1
|
|
37
|
+
const query = `
|
|
38
|
+
SELECT p.*, pm."userId" as memberUserId, pm.archived as memberArchived
|
|
39
|
+
FROM "projects" p
|
|
40
|
+
JOIN "project_members" pm ON p.id = pm."projectId"
|
|
41
|
+
WHERE pm."userId" = $1
|
|
42
42
|
`;
|
|
43
43
|
const result = await connection.query(query, [userId]);
|
|
44
44
|
sqlResults = result.rows.map(row => ({
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Auth } from '../types';
|
|
2
2
|
import { Request, Response, NextFunction } from 'express';
|
|
3
3
|
import { StreamByConfig } from '../types';
|
|
4
|
-
export declare const authenticate: (config: StreamByConfig) => (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any
|
|
4
|
+
export declare const authenticate: (config: StreamByConfig) => (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
5
5
|
export declare function checkRole(auth: Auth, required: 'viewer' | 'editor' | 'admin'): void;
|
package/dist/services/auth.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.authenticate = void 0;
|
|
4
4
|
exports.checkRole = checkRole;
|
|
5
5
|
const authenticate = (config) => async (req, res, next) => {
|
|
6
|
+
if (req.path.includes('/public-export/')) {
|
|
7
|
+
return next();
|
|
8
|
+
}
|
|
6
9
|
try {
|
|
7
10
|
const auth = await config.authProvider(req);
|
|
8
11
|
if (!auth || !auth.userId || !auth.role) {
|
package/dist/utils/auth.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ProjectInfo } from '../types';
|
|
2
|
+
export declare function isProjectMember(project: ProjectInfo, userId: string): boolean;
|
package/dist/utils/auth.js
CHANGED
|
@@ -2,5 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isProjectMember = isProjectMember;
|
|
4
4
|
function isProjectMember(project, userId) {
|
|
5
|
-
|
|
5
|
+
if (!project || !project.members) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return project.members.some(member => member.userId === userId);
|
|
6
9
|
}
|