streamby-core 0.23.1 → 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.
@@ -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));
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ export declare function publicRoute(req: Request, res: Response, next: NextFunction): void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publicRoute = publicRoute;
4
+ function publicRoute(req, res, next) {
5
+ if (req.path.includes('/public-export/')) {
6
+ return next();
7
+ }
8
+ return next();
9
+ }
@@ -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
  }
@@ -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>> | undefined>;
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;
@@ -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) {
@@ -1 +1,2 @@
1
- export declare function isProjectMember(project: any, userId: string): any;
1
+ import { ProjectInfo } from '../types';
2
+ export declare function isProjectMember(project: ProjectInfo, userId: string): boolean;
@@ -2,5 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isProjectMember = isProjectMember;
4
4
  function isProjectMember(project, userId) {
5
- return project.members?.some((m) => m.userId?.toString() === userId?.toString());
5
+ if (!project || !project.members) {
6
+ return false;
7
+ }
8
+ return project.members.some(member => member.userId === userId);
6
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.23.1",
3
+ "version": "0.23.2",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",