streamby-core 0.21.0 → 0.21.1

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.
@@ -10,7 +10,6 @@ const presign_1 = require("../services/presign");
10
10
  const manager_1 = require("../models/manager");
11
11
  const storage_1 = require("../providers/storage");
12
12
  const connectionManager_1 = require("../adapters/database/connectionManager");
13
- const auth_1 = require("../services/auth");
14
13
  function isProjectMember(project, userId) {
15
14
  return project.members?.some((m) => m.userId?.toString() === userId?.toString());
16
15
  }
@@ -27,17 +26,24 @@ function createStreamByRouter(config) {
27
26
  const Export = (0, manager_1.getModel)('exports');
28
27
  router.get('/auth', async (req, res) => {
29
28
  try {
30
- const auth = await (0, auth_1.resolveAuth)(config, req);
31
- res.status(200).json({ logged: true, ...auth });
29
+ const auth = await config.authProvider(req);
30
+ if (!auth ||
31
+ !auth.userId ||
32
+ !auth.role) {
33
+ throw new Error('Invalid or missing authentication context');
34
+ }
35
+ return res.status(200).json({ logged: true, ...auth });
32
36
  }
33
37
  catch (err) {
34
- res.status(401).json({ logged: false });
38
+ return res.status(401).json({ logged: false });
35
39
  }
36
40
  });
37
41
  router.get('/databases', async (req, res) => {
38
42
  try {
39
43
  const auth = await config.authProvider(req);
40
- if (!auth) {
44
+ if (!auth ||
45
+ !auth.userId ||
46
+ !auth.role) {
41
47
  return res.status(401).json({ error: 'Unauthorized' });
42
48
  }
43
49
  const connectedDbIds = (0, connectionManager_1.getConnectedIds)();
@@ -53,6 +59,11 @@ function createStreamByRouter(config) {
53
59
  router.get('/upload-project-image-url/:id', async (req, res) => {
54
60
  try {
55
61
  const auth = await config.authProvider(req);
62
+ if (!auth ||
63
+ !auth.userId ||
64
+ !auth.role) {
65
+ return res.status(401).json({ error: 'Unauthorized' });
66
+ }
56
67
  if (auth.role !== 'admin' && auth.role !== 'editor') {
57
68
  return res.status(403).json({ error: 'Permission denied' });
58
69
  }
@@ -70,6 +81,11 @@ function createStreamByRouter(config) {
70
81
  router.delete('/delete-project-image-url/:id', async (req, res) => {
71
82
  try {
72
83
  const auth = await config.authProvider(req);
84
+ if (!auth ||
85
+ !auth.userId ||
86
+ !auth.role) {
87
+ return res.status(401).json({ error: 'Unauthorized' });
88
+ }
73
89
  if (auth.role !== 'admin' && auth.role !== 'editor') {
74
90
  return res.status(403).json({ error: 'Permission denied' });
75
91
  }
@@ -88,6 +104,11 @@ function createStreamByRouter(config) {
88
104
  router.get('/files', async (req, res) => {
89
105
  try {
90
106
  const auth = await config.authProvider(req);
107
+ if (!auth ||
108
+ !auth.userId ||
109
+ !auth.role) {
110
+ return res.status(401).json({ error: 'Unauthorized' });
111
+ }
91
112
  const projectId = (req.query.projectId || req.headers['x-project-id']);
92
113
  if (!projectId) {
93
114
  return res.status(403).json({ error: 'Unauthorized or missing projectId' });
@@ -102,6 +123,11 @@ function createStreamByRouter(config) {
102
123
  router.get('/projects', async (req, res) => {
103
124
  try {
104
125
  const auth = await config.authProvider(req);
126
+ if (!auth ||
127
+ !auth.userId ||
128
+ !auth.role) {
129
+ return res.status(401).json({ error: 'Unauthorized' });
130
+ }
105
131
  const archivedQuery = req.query.archived;
106
132
  const filterArchived = archivedQuery !== undefined ? String(archivedQuery).toLowerCase() === 'true' : undefined;
107
133
  const allProjects = await Project.find({}); // Fetch all projects
@@ -136,6 +162,11 @@ function createStreamByRouter(config) {
136
162
  router.post('/projects/create', async (req, res) => {
137
163
  try {
138
164
  const auth = await config.authProvider(req);
165
+ if (!auth ||
166
+ !auth.userId ||
167
+ !auth.role) {
168
+ return res.status(401).json({ error: 'Unauthorized' });
169
+ }
139
170
  if (auth.role !== 'admin' && auth.role !== 'editor') {
140
171
  return res.status(403).json({ error: 'Permission denied' });
141
172
  }
@@ -155,6 +186,11 @@ function createStreamByRouter(config) {
155
186
  router.get('/projects/:id', async (req, res) => {
156
187
  try {
157
188
  const auth = await config.authProvider(req);
189
+ if (!auth ||
190
+ !auth.userId ||
191
+ !auth.role) {
192
+ return res.status(401).json({ error: 'Unauthorized' });
193
+ }
158
194
  const projectId = req.params.id;
159
195
  const project = await Project.findOne({ _id: projectId });
160
196
  if (!project) {
@@ -172,6 +208,11 @@ function createStreamByRouter(config) {
172
208
  router.patch('/projects/:id', async (req, res) => {
173
209
  try {
174
210
  const auth = await config.authProvider(req);
211
+ if (!auth ||
212
+ !auth.userId ||
213
+ !auth.role) {
214
+ return res.status(401).json({ error: 'Unauthorized' });
215
+ }
175
216
  if (auth.role !== 'admin' && auth.role !== 'editor') {
176
217
  return res.status(403).json({ error: 'Permission denied' });
177
218
  }
@@ -200,6 +241,11 @@ function createStreamByRouter(config) {
200
241
  router.delete('/projects/:id', async (req, res) => {
201
242
  try {
202
243
  const auth = await config.authProvider(req);
244
+ if (!auth ||
245
+ !auth.userId ||
246
+ !auth.role) {
247
+ return res.status(401).json({ error: 'Unauthorized' });
248
+ }
203
249
  const projectId = req.params.id;
204
250
  const project = await Project.findOne({ _id: projectId });
205
251
  if (!project) {
@@ -218,6 +264,11 @@ function createStreamByRouter(config) {
218
264
  router.patch('/projects/:id/archive', async (req, res) => {
219
265
  try {
220
266
  const auth = await config.authProvider(req);
267
+ if (!auth ||
268
+ !auth.userId ||
269
+ !auth.role) {
270
+ return res.status(401).json({ error: 'Unauthorized' });
271
+ }
221
272
  const projectId = req.params.id;
222
273
  const project = await Project.findOne({ _id: projectId });
223
274
  if (!project || !isProjectMember(project, auth.userId)) {
@@ -246,6 +297,11 @@ function createStreamByRouter(config) {
246
297
  router.patch('/projects/:id/unarchive', async (req, res) => {
247
298
  try {
248
299
  const auth = await config.authProvider(req);
300
+ if (!auth ||
301
+ !auth.userId ||
302
+ !auth.role) {
303
+ return res.status(401).json({ error: 'Unauthorized' });
304
+ }
249
305
  const projectId = req.params.id;
250
306
  const project = await Project.findOne({ _id: projectId });
251
307
  if (!project || !isProjectMember(project, auth.userId)) {
@@ -274,6 +330,11 @@ function createStreamByRouter(config) {
274
330
  router.get('/projects/:id/exports/:export_id', async (req, res) => {
275
331
  try {
276
332
  const auth = await config.authProvider(req);
333
+ if (!auth ||
334
+ !auth.userId ||
335
+ !auth.role) {
336
+ return res.status(401).json({ error: 'Unauthorized' });
337
+ }
277
338
  const projectId = req.params.id;
278
339
  const exportId = req.params.export_id;
279
340
  const project = await Project.findOne({ _id: projectId });
@@ -293,6 +354,11 @@ function createStreamByRouter(config) {
293
354
  router.post('/projects/:id/exports', async (req, res) => {
294
355
  try {
295
356
  const auth = await config.authProvider(req);
357
+ if (!auth ||
358
+ !auth.userId ||
359
+ !auth.role) {
360
+ return res.status(401).json({ error: 'Unauthorized' });
361
+ }
296
362
  const projectId = req.params.id;
297
363
  const { name, description, collectionName } = req.body;
298
364
  if (!name || !collectionName) {
@@ -317,6 +383,11 @@ function createStreamByRouter(config) {
317
383
  router.get('/projects/:id/members', async (req, res) => {
318
384
  try {
319
385
  const auth = await config.authProvider(req);
386
+ if (!auth ||
387
+ !auth.userId ||
388
+ !auth.role) {
389
+ return res.status(401).json({ error: 'Unauthorized' });
390
+ }
320
391
  const projectId = req.params.id;
321
392
  const project = await Project.findOne({ _id: projectId });
322
393
  if (!project) {
@@ -1,4 +1,2 @@
1
- import { Request } from 'express';
2
- import { StreamByConfig, AuthContext } from '../types';
3
- export declare function resolveAuth(config: StreamByConfig, req: Request): Promise<AuthContext>;
1
+ import { AuthContext } from '../types';
4
2
  export declare function checkRole(auth: AuthContext, required: 'viewer' | 'editor' | 'admin'): void;
@@ -1,16 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveAuth = resolveAuth;
4
3
  exports.checkRole = checkRole;
5
- async function resolveAuth(config, req) {
6
- const auth = await config.authProvider(req);
7
- if (!auth ||
8
- !auth.userId ||
9
- !auth.role) {
10
- throw new Error('Invalid or missing authentication context');
11
- }
12
- return auth;
13
- }
14
4
  function checkRole(auth, required) {
15
5
  const roles = ['viewer', 'editor', 'admin'];
16
6
  const userIdx = roles.indexOf(auth.role);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",