streamby-core 0.28.6 → 0.29.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.
@@ -0,0 +1,3 @@
1
+ import { Router } from 'express';
2
+ import { StreamByConfig } from '../../types';
3
+ export declare function workflowRouter(config: StreamByConfig): Router;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workflowRouter = workflowRouter;
4
+ const express_1 = require("express");
5
+ const crypto_1 = require("crypto");
6
+ const manager_1 = require("../../models/manager");
7
+ const auth_1 = require("../../utils/auth");
8
+ const mongodb_1 = require("mongodb");
9
+ function workflowRouter(config) {
10
+ const router = (0, express_1.Router)();
11
+ const Project = (0, manager_1.getModel)('projects');
12
+ router.get('/projects/:id/workflows', async (req, res) => {
13
+ try {
14
+ const auth = await config.authProvider(req);
15
+ if (!auth?.userId)
16
+ return res.status(401).json({ message: 'Unauthorized' });
17
+ const project = await Project.findOne({ _id: req.params.id });
18
+ if (!project)
19
+ return res.status(404).json({ message: 'Project not found' });
20
+ if (!(0, auth_1.isProjectMember)(project, auth.userId))
21
+ return res.status(403).json({ message: 'Unauthorized access' });
22
+ res.json({ data: project.workflows ?? [], message: 'Workflows fetched successfully' });
23
+ }
24
+ catch (err) {
25
+ res.status(500).json({ message: 'Failed to fetch workflows', details: err.message });
26
+ }
27
+ });
28
+ router.get('/projects/:id/workflows/:workflow_id', async (req, res) => {
29
+ try {
30
+ const auth = await config.authProvider(req);
31
+ if (!auth?.userId)
32
+ return res.status(401).json({ message: 'Unauthorized' });
33
+ const project = await Project.findOne({ _id: req.params.id });
34
+ if (!project)
35
+ return res.status(404).json({ message: 'Project not found' });
36
+ if (!(0, auth_1.isProjectMember)(project, auth.userId))
37
+ return res.status(403).json({ message: 'Unauthorized access' });
38
+ const workflow = (project.workflows ?? []).find((w) => w.id === req.params.workflow_id);
39
+ if (!workflow)
40
+ return res.status(404).json({ message: 'Workflow not found' });
41
+ res.json({ data: workflow, message: 'Workflow fetched successfully' });
42
+ }
43
+ catch (err) {
44
+ res.status(500).json({ message: 'Failed to fetch workflow', details: err.message });
45
+ }
46
+ });
47
+ router.post('/projects/:id/workflows', async (req, res) => {
48
+ try {
49
+ const auth = await config.authProvider(req);
50
+ if (!auth?.userId)
51
+ return res.status(401).json({ message: 'Unauthorized' });
52
+ const projectId = req.params.id;
53
+ const project = await Project.findOne({ _id: projectId });
54
+ if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
55
+ return res.status(403).json({ message: 'Unauthorized project access' });
56
+ }
57
+ const { name, description } = req.body;
58
+ if (!name)
59
+ return res.status(400).json({ message: 'Missing workflow name' });
60
+ const now = new Date();
61
+ const workflow = {
62
+ id: (0, crypto_1.randomUUID)(),
63
+ name,
64
+ description: description ?? '',
65
+ status: 'draft',
66
+ projectId,
67
+ nodeSchema: null,
68
+ createdAt: now,
69
+ updatedAt: now,
70
+ };
71
+ if (project.dbType === 'sql') {
72
+ const SqlProject = (0, manager_1.getModel)('projects', 'sql');
73
+ const currentWorkflows = project.workflows ?? [];
74
+ await SqlProject.update({ _id: projectId }, { workflows: [...currentWorkflows, workflow] });
75
+ }
76
+ else {
77
+ await Project.update({ _id: new mongodb_1.ObjectId(projectId) }, { $push: { workflows: workflow } });
78
+ }
79
+ res.status(201).json({ data: workflow, message: 'Workflow created successfully' });
80
+ }
81
+ catch (err) {
82
+ res.status(500).json({ message: 'Failed to create workflow', details: err.message });
83
+ }
84
+ });
85
+ router.patch('/projects/:id/workflows/:workflow_id', async (req, res) => {
86
+ try {
87
+ const auth = await config.authProvider(req);
88
+ if (!auth?.userId)
89
+ return res.status(401).json({ message: 'Unauthorized' });
90
+ const { id: projectId, workflow_id: workflowId } = req.params;
91
+ const project = await Project.findOne({ _id: projectId });
92
+ if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
93
+ return res.status(403).json({ message: 'Unauthorized project access' });
94
+ }
95
+ const existing = (project.workflows ?? []).find((w) => w.id === workflowId);
96
+ if (!existing)
97
+ return res.status(404).json({ message: 'Workflow not found' });
98
+ const { name, description, status, nodeSchema } = req.body;
99
+ const updated = {
100
+ ...existing,
101
+ name: name ?? existing.name,
102
+ description: description ?? existing.description,
103
+ status: status ?? existing.status,
104
+ nodeSchema: nodeSchema !== undefined ? nodeSchema : existing.nodeSchema,
105
+ updatedAt: new Date(),
106
+ };
107
+ if (project.dbType === 'sql') {
108
+ const SqlProject = (0, manager_1.getModel)('projects', 'sql');
109
+ const updatedWorkflows = (project.workflows ?? []).map((w) => w.id === workflowId ? updated : w);
110
+ await SqlProject.update({ _id: projectId }, { workflows: updatedWorkflows });
111
+ }
112
+ else {
113
+ await Project.update({ _id: new mongodb_1.ObjectId(projectId), 'workflows.id': workflowId }, {
114
+ $set: {
115
+ 'workflows.$.name': updated.name,
116
+ 'workflows.$.description': updated.description,
117
+ 'workflows.$.status': updated.status,
118
+ 'workflows.$.nodeSchema': updated.nodeSchema,
119
+ 'workflows.$.updatedAt': updated.updatedAt,
120
+ },
121
+ });
122
+ }
123
+ res.json({ data: updated, message: 'Workflow updated successfully' });
124
+ }
125
+ catch (err) {
126
+ res.status(500).json({ message: 'Failed to update workflow', details: err.message });
127
+ }
128
+ });
129
+ router.delete('/projects/:id/workflows/:workflow_id', async (req, res) => {
130
+ try {
131
+ const auth = await config.authProvider(req);
132
+ if (!auth?.userId)
133
+ return res.status(401).json({ message: 'Unauthorized' });
134
+ const { id: projectId, workflow_id: workflowId } = req.params;
135
+ const project = await Project.findOne({ _id: projectId });
136
+ if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
137
+ return res.status(403).json({ message: 'Unauthorized project access' });
138
+ }
139
+ const existing = (project.workflows ?? []).find((w) => w.id === workflowId);
140
+ if (!existing)
141
+ return res.status(404).json({ message: 'Workflow not found' });
142
+ if (project.dbType === 'sql') {
143
+ const SqlProject = (0, manager_1.getModel)('projects', 'sql');
144
+ const updatedWorkflows = (project.workflows ?? []).filter((w) => w.id !== workflowId);
145
+ await SqlProject.update({ _id: projectId }, { workflows: updatedWorkflows });
146
+ }
147
+ else {
148
+ await Project.update({ _id: new mongodb_1.ObjectId(projectId) }, { $pull: { workflows: { id: workflowId } } });
149
+ }
150
+ res.json({ message: 'Workflow deleted successfully' });
151
+ }
152
+ catch (err) {
153
+ res.status(500).json({ message: 'Failed to delete workflow', details: err.message });
154
+ }
155
+ });
156
+ return router;
157
+ }
@@ -45,11 +45,11 @@ class Model {
45
45
  // Handle members filter for SQL projects
46
46
  const userId = processedFilter.members.$elemMatch.userId;
47
47
  const schema = this.schema || 'streamby'; // Default to 'streamby' if schema not provided
48
- const query = `
49
- SELECT p.*, pm."userId" as memberUserId, pm.role as memberRole, pm.status as memberStatus, pm.archived as memberArchived
50
- FROM "${schema}"."projects" p
51
- JOIN "${schema}"."project_members" pm ON p.id = pm."projectId"
52
- WHERE pm."userId" = $1
48
+ const query = `
49
+ SELECT p.*, pm."userId" as memberUserId, pm.role as memberRole, pm.status as memberStatus, pm.archived as memberArchived
50
+ FROM "${schema}"."projects" p
51
+ JOIN "${schema}"."project_members" pm ON p.id = pm."projectId"
52
+ WHERE pm."userId" = $1
53
53
  `;
54
54
  const result = await connection.query(query, [userId]);
55
55
  sqlResults = result.rows.map(row => ({
@@ -219,10 +219,10 @@ class Model {
219
219
  else {
220
220
  const matchKey = value.id !== undefined ? 'id' : Object.keys(value)[0];
221
221
  const matchVal = String(value[matchKey]);
222
- await connection.query(`UPDATE ${tbl} SET "${field}" = (
223
- SELECT COALESCE(jsonb_agg(elem), '[]'::jsonb)
224
- FROM jsonb_array_elements("${field}") elem
225
- WHERE elem->>'${matchKey}' != $1
222
+ await connection.query(`UPDATE ${tbl} SET "${field}" = (
223
+ SELECT COALESCE(jsonb_agg(elem), '[]'::jsonb)
224
+ FROM jsonb_array_elements("${field}") elem
225
+ WHERE elem->>'${matchKey}' != $1
226
226
  ) WHERE id = $2`, [matchVal, id]);
227
227
  }
228
228
  }
@@ -0,0 +1,3 @@
1
+ export declare function encrypt(text: string, secretKey: string): string;
2
+ export declare function decrypt(text: string, secretKey: string): string;
3
+ export declare function hash(text: string): string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encrypt = encrypt;
7
+ exports.decrypt = decrypt;
8
+ exports.hash = hash;
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ const ALGORITHM = 'aes-256-cbc';
11
+ const IV_LENGTH = 16;
12
+ function encrypt(text, secretKey) {
13
+ const iv = crypto_1.default.randomBytes(IV_LENGTH);
14
+ const key = crypto_1.default.createHash('sha256').update(String(secretKey)).digest('base64').substr(0, 32);
15
+ const cipher = crypto_1.default.createCipheriv(ALGORITHM, Buffer.from(key), iv);
16
+ let encrypted = cipher.update(text);
17
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
18
+ return iv.toString('hex') + ':' + encrypted.toString('hex');
19
+ }
20
+ function decrypt(text, secretKey) {
21
+ const textParts = text.split(':');
22
+ const iv = Buffer.from(textParts.shift(), 'hex');
23
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex');
24
+ const key = crypto_1.default.createHash('sha256').update(String(secretKey)).digest('base64').substr(0, 32);
25
+ const decipher = crypto_1.default.createDecipheriv(ALGORITHM, Buffer.from(key), iv);
26
+ let decrypted = decipher.update(encryptedText);
27
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
28
+ return decrypted.toString();
29
+ }
30
+ function hash(text) {
31
+ return crypto_1.default.createHash('sha256').update(text).digest('hex');
32
+ }
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "streamby-core",
3
- "version": "0.28.6",
4
- "description": "StreamBy middleware framework for media storage management",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "dist"
9
- ],
10
- "scripts": {
11
- "build": "tsc",
12
- "test": "vitest",
13
- "dev": "ts-node-dev --respawn --clear dev.ts",
14
- "prepublishOnly": "npm run build"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/GwerhDev/StreamBy-Package.git"
19
- },
20
- "keywords": [
21
- "streamby",
22
- "middleware",
23
- "upload",
24
- "storage",
25
- "s3",
26
- "express",
27
- "typescript"
28
- ],
29
- "author": "TerminalCore Labs",
30
- "license": "MIT",
31
- "dependencies": {
32
- "@aws-sdk/client-s3": "^3.528.0",
33
- "@aws-sdk/s3-request-presigner": "^3.787.0",
34
- "@prisma/client": "^6.12.0",
35
- "bcrypt": "^5.1.1",
36
- "dotenv": "^16.5.0",
37
- "express": "^4.0.0",
38
- "mongodb": "^6.17.0",
39
- "mongoose": "^8.13.2",
40
- "node-fetch": "^3.0.0",
41
- "pg": "^8.16.3",
42
- "prisma": "^6.12.0",
43
- "ws": "^8.20.0"
44
- },
45
- "devDependencies": {
46
- "@types/bcrypt": "^5.0.2",
47
- "@types/cors": "^2.8.18",
48
- "@types/express": "^4.17.17",
49
- "@types/mongodb": "^4.0.7",
50
- "@types/node": "^22.15.21",
51
- "@types/pg": "^8.15.4",
52
- "@types/supertest": "^6.0.3",
53
- "@types/ws": "^8.18.1",
54
- "cors": "^2.8.5",
55
- "supertest": "^7.1.4",
56
- "ts-node-dev": "^2.0.0",
57
- "typescript": "^5.8.3",
58
- "vitest": "^3.1.1"
59
- },
60
- "peerDependencies": {
61
- "express": "^4.0.0"
62
- }
63
- }
1
+ {
2
+ "name": "streamby-core",
3
+ "version": "0.29.1",
4
+ "description": "StreamBy middleware framework for media storage management",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "vitest",
13
+ "dev": "ts-node-dev --respawn --clear dev.ts",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/GwerhDev/StreamBy-Package.git"
19
+ },
20
+ "keywords": [
21
+ "streamby",
22
+ "middleware",
23
+ "upload",
24
+ "storage",
25
+ "s3",
26
+ "express",
27
+ "typescript"
28
+ ],
29
+ "author": "TerminalCore Labs",
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "@aws-sdk/client-s3": "^3.528.0",
33
+ "@aws-sdk/s3-request-presigner": "^3.787.0",
34
+ "@prisma/client": "^6.12.0",
35
+ "bcrypt": "^5.1.1",
36
+ "dotenv": "^16.5.0",
37
+ "express": "^4.0.0",
38
+ "mongodb": "^6.17.0",
39
+ "mongoose": "^8.13.2",
40
+ "node-fetch": "^3.0.0",
41
+ "pg": "^8.16.3",
42
+ "prisma": "^6.12.0",
43
+ "ws": "^8.20.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/bcrypt": "^5.0.2",
47
+ "@types/cors": "^2.8.18",
48
+ "@types/express": "^4.17.17",
49
+ "@types/mongodb": "^4.0.7",
50
+ "@types/node": "^22.15.21",
51
+ "@types/pg": "^8.15.4",
52
+ "@types/supertest": "^6.0.3",
53
+ "@types/ws": "^8.18.1",
54
+ "cors": "^2.8.5",
55
+ "supertest": "^7.1.4",
56
+ "ts-node-dev": "^2.0.0",
57
+ "typescript": "^5.8.3",
58
+ "vitest": "^3.1.1"
59
+ },
60
+ "peerDependencies": {
61
+ "express": "^4.0.0"
62
+ }
63
+ }