streamby-core 0.26.5 β 0.26.7
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/README.md +283 -242
- package/dist/adapters/database/connectionManager.js +41 -41
- package/dist/adapters/database/sql.js +16 -16
- package/dist/middleware/createRouter.js +1 -1
- package/dist/middleware/routes/notification.js +14 -0
- package/dist/models/Model.js +5 -5
- package/dist/services/wsHub.d.ts +2 -2
- package/dist/services/wsHub.js +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +63 -63
- package/dist/utils/crypto.d.ts +0 -3
- package/dist/utils/crypto.js +0 -32
package/README.md
CHANGED
|
@@ -1,242 +1,283 @@
|
|
|
1
|
-
# @streamby/core
|
|
2
|
-
|
|
3
|
-
Middleware framework for building storage-agnostic media APIs.
|
|
4
|
-
Part of the [StreamBy](https://streamby.nhexa.cl) ecosystem by TerminalCore Labs.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## π What is it?
|
|
9
|
-
|
|
10
|
-
`@streamby/core` is a plug-and-play middleware for Express (or compatible frameworks) that enables file uploads, listings and **multi-project access** over services like:
|
|
11
|
-
|
|
12
|
-
- β
AWS S3
|
|
13
|
-
- β
Google Cloud Storage (soon)
|
|
14
|
-
- β
Cloudflare R2 (soon)
|
|
15
|
-
- β
Local/Personal servers (soon)
|
|
16
|
-
|
|
17
|
-
It's designed to be installed inside your existing API as a library β **no need to run a separate backend**.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## π¦ Installation
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @streamby/core
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
1
|
+
# @streamby/core
|
|
2
|
+
|
|
3
|
+
Middleware framework for building storage-agnostic media APIs.
|
|
4
|
+
Part of the [StreamBy](https://streamby.nhexa.cl) ecosystem by TerminalCore Labs.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## π What is it?
|
|
9
|
+
|
|
10
|
+
`@streamby/core` is a plug-and-play middleware for Express (or compatible frameworks) that enables file uploads, listings and **multi-project access** over services like:
|
|
11
|
+
|
|
12
|
+
- β
AWS S3
|
|
13
|
+
- β
Google Cloud Storage (soon)
|
|
14
|
+
- β
Cloudflare R2 (soon)
|
|
15
|
+
- β
Local/Personal servers (soon)
|
|
16
|
+
|
|
17
|
+
It's designed to be installed inside your existing API as a library β **no need to run a separate backend**.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## π¦ Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @streamby/core ws
|
|
25
|
+
npm install -D @types/ws
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## π§± Basic usage
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import http from 'http';
|
|
34
|
+
import express from 'express';
|
|
35
|
+
import { WebSocketServer } from 'ws';
|
|
36
|
+
import { createStreamByRouter } from '@streamby/core';
|
|
37
|
+
|
|
38
|
+
const app = express();
|
|
39
|
+
const server = http.createServer(app);
|
|
40
|
+
const wss = new WebSocketServer({ server, path: '/streamby/ws' });
|
|
41
|
+
|
|
42
|
+
app.use('/streamby', express.json(), createStreamByRouter({
|
|
43
|
+
authProvider: async (req) => {
|
|
44
|
+
// validate token/session and return user info
|
|
45
|
+
return { userId: 'user-id', username: 'username', role: 'admin' };
|
|
46
|
+
},
|
|
47
|
+
databases: [
|
|
48
|
+
{ id: 'mongo', type: 'nosql', connectionString: process.env.MONGO_URI! },
|
|
49
|
+
{ id: 'postgres', type: 'sql', connectionString: process.env.POSTGRES_URI!, main: true },
|
|
50
|
+
],
|
|
51
|
+
storageProviders: [
|
|
52
|
+
{
|
|
53
|
+
type: 's3',
|
|
54
|
+
config: {
|
|
55
|
+
bucket: process.env.AWS_BUCKET!,
|
|
56
|
+
region: process.env.AWS_REGION!,
|
|
57
|
+
accessKeyId: process.env.AWS_ACCESS_KEY!,
|
|
58
|
+
secretAccessKey: process.env.AWS_SECRET_KEY!,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
encrypt: process.env.STREAMBY_ENCRYPTION_KEY,
|
|
63
|
+
websocket: { server: wss },
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
server.listen(3000);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> **Important:** use `http.createServer(app)` and pass `server.listen()` instead of `app.listen()`.
|
|
70
|
+
> This is required so the `WebSocketServer` shares the same port as the HTTP server.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## ποΈ Database Schema Setup
|
|
75
|
+
|
|
76
|
+
`@streamby/core` requires a pre-configured database schema for its internal operations. It does not manage database connections directly; instead, it expects the host application to provide initialized connection instances. This ensures full control and flexibility for the host environment.
|
|
77
|
+
|
|
78
|
+
The library will only interact with the specified schema and will not touch other schemas in your database. The `reset` option is opt-in and will only drop and recreate the specified `streamby` schema if explicitly set to `true`.
|
|
79
|
+
|
|
80
|
+
### PostgreSQL Example
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Pool } from "pg";
|
|
84
|
+
import { setupStreambyPg } from "@streamby/core/pg/setup"; // Adjust path as per your package structure
|
|
85
|
+
|
|
86
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
87
|
+
|
|
88
|
+
// Call setupStreambyPg to ensure the schema and tables are created
|
|
89
|
+
// reset: false (default) ensures idempotency and no data loss
|
|
90
|
+
await setupStreambyPg({ pool, schema: "streamby", reset: false });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### MongoDB Example
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { MongoClient } from "mongodb";
|
|
97
|
+
import { setupStreambyMongo } from "@streamby/core/mongo/setup"; // Adjust path as per your package structure
|
|
98
|
+
|
|
99
|
+
const client = new MongoClient(process.env.MONGO_URL!);
|
|
100
|
+
|
|
101
|
+
// Connect the MongoDB client
|
|
102
|
+
await client.connect();
|
|
103
|
+
|
|
104
|
+
// Call setupStreambyMongo to ensure collections and indexes are created
|
|
105
|
+
await setupStreambyMongo({ client, dbName: "streamby" });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import express from 'express';
|
|
110
|
+
import { createStreamByRouter } from '@streamby/core';
|
|
111
|
+
|
|
112
|
+
const app = express();
|
|
113
|
+
|
|
114
|
+
app.use('/streamby', createStreamByRouter({
|
|
115
|
+
storageProvider: {
|
|
116
|
+
type: 's3',
|
|
117
|
+
config: {
|
|
118
|
+
bucket: 'your-bucket-name',
|
|
119
|
+
region: 'your-region',
|
|
120
|
+
accessKeyId: 'YOUR_AWS_KEY',
|
|
121
|
+
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
authProvider: async (req) => {
|
|
125
|
+
// extract token/cookie and validate
|
|
126
|
+
return {
|
|
127
|
+
userId: 'demo',
|
|
128
|
+
projects: ['demo-project'],
|
|
129
|
+
role: 'admin',
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
projectProvider: async (projectId) => {
|
|
133
|
+
// fetch project from your DB
|
|
134
|
+
return {
|
|
135
|
+
id: projectId,
|
|
136
|
+
name: 'Demo Project',
|
|
137
|
+
description: 'Demo for StreamBy integration',
|
|
138
|
+
rootFolders: [],
|
|
139
|
+
settings: { allowUpload: true }
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
app.listen(3000);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## π§ͺ Testing
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm run test
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## π Features
|
|
160
|
+
|
|
161
|
+
- π Multi-project access control
|
|
162
|
+
- π Project-aware file uploads & listings
|
|
163
|
+
- π§Ή Modular adapters per storage provider
|
|
164
|
+
- π§° Built-in testability with mock auth & storage
|
|
165
|
+
- β¨ Simple to extend for custom business logic
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## πΊοΈ API Endpoints
|
|
170
|
+
|
|
171
|
+
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
172
|
+
|
|
173
|
+
### `GET /streamby/projects`
|
|
174
|
+
|
|
175
|
+
Lists all projects accessible by the authenticated user.
|
|
176
|
+
|
|
177
|
+
**Query Parameters:**
|
|
178
|
+
- `archived`: (Optional) Filter projects by their archived status.
|
|
179
|
+
- `true`: Returns only archived projects.
|
|
180
|
+
- `false`: Returns only unarchived projects.
|
|
181
|
+
- (Omitted): Returns all projects (both archived and unarchived).
|
|
182
|
+
|
|
183
|
+
**Example Response:**
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"projects": [
|
|
187
|
+
{
|
|
188
|
+
"id": "project1_id",
|
|
189
|
+
"dbType": "nosql",
|
|
190
|
+
"name": "My NoSQL Project",
|
|
191
|
+
"image": "url_to_image",
|
|
192
|
+
"archived": false
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"id": "project2_id",
|
|
196
|
+
"dbType": "sql",
|
|
197
|
+
"name": "My SQL Project",
|
|
198
|
+
"image": "url_to_image",
|
|
199
|
+
"archived": true
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### `PATCH /streamby/projects/:id/archive`
|
|
206
|
+
|
|
207
|
+
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
208
|
+
|
|
209
|
+
**Example Response:**
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"success": true,
|
|
213
|
+
"projects": [
|
|
214
|
+
{
|
|
215
|
+
"id": "project1_id",
|
|
216
|
+
"dbType": "nosql",
|
|
217
|
+
"name": "My NoSQL Project",
|
|
218
|
+
"image": "url_to_image",
|
|
219
|
+
"archived": true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"id": "project2_id",
|
|
223
|
+
"dbType": "sql",
|
|
224
|
+
"name": "My SQL Project",
|
|
225
|
+
"image": "url_to_image",
|
|
226
|
+
"archived": false
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### `PATCH /streamby/projects/:id/unarchive`
|
|
233
|
+
|
|
234
|
+
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
235
|
+
|
|
236
|
+
**Example Response:**
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"success": true,
|
|
240
|
+
"projects": [
|
|
241
|
+
{
|
|
242
|
+
"id": "project1_id",
|
|
243
|
+
"dbType": "nosql",
|
|
244
|
+
"name": "My NoSQL Project",
|
|
245
|
+
"image": "url_to_image",
|
|
246
|
+
"archived": false
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"id": "project2_id",
|
|
250
|
+
"dbType": "sql",
|
|
251
|
+
"name": "My SQL Project",
|
|
252
|
+
"image": "url_to_image",
|
|
253
|
+
"archived": false
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## π£ Roadmap
|
|
262
|
+
|
|
263
|
+
- [ ] Support for Google Cloud Storage
|
|
264
|
+
- [ ] CLI tool for uploading files
|
|
265
|
+
- [ ] Role-based access control middleware
|
|
266
|
+
- [ ] Plugin system for extended routes
|
|
267
|
+
- [ ] Streaming support (HLS, audio, etc.)
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## π§βπ» Maintained by
|
|
272
|
+
|
|
273
|
+
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
274
|
+
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
275
|
+
|
|
276
|
+
Visit us [here](https://terminalcore.cl)
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## π License
|
|
281
|
+
|
|
282
|
+
[MIT](./LICENSE)
|
|
283
|
+
|
|
@@ -43,56 +43,56 @@ const getConnection = (id) => {
|
|
|
43
43
|
exports.getConnection = getConnection;
|
|
44
44
|
const ensureTablesExist = async (pool) => {
|
|
45
45
|
try {
|
|
46
|
-
await pool.query(`
|
|
47
|
-
CREATE SCHEMA IF NOT EXISTS streamby;
|
|
48
|
-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
49
|
-
CREATE TABLE IF NOT EXISTS streamby.projects (
|
|
50
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
51
|
-
name VARCHAR(255) NOT NULL,
|
|
52
|
-
description TEXT,
|
|
53
|
-
image TEXT,
|
|
54
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
55
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
56
|
-
);
|
|
46
|
+
await pool.query(`
|
|
47
|
+
CREATE SCHEMA IF NOT EXISTS streamby;
|
|
48
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
49
|
+
CREATE TABLE IF NOT EXISTS streamby.projects (
|
|
50
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
51
|
+
name VARCHAR(255) NOT NULL,
|
|
52
|
+
description TEXT,
|
|
53
|
+
image TEXT,
|
|
54
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
55
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
56
|
+
);
|
|
57
57
|
`);
|
|
58
58
|
console.log('β
"projects" table ensured to exist.');
|
|
59
59
|
// Ensure dbType column exists and is correctly configured
|
|
60
|
-
await pool.query(`
|
|
61
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbType" VARCHAR(50);
|
|
60
|
+
await pool.query(`
|
|
61
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbType" VARCHAR(50);
|
|
62
62
|
`);
|
|
63
|
-
await pool.query(`
|
|
64
|
-
UPDATE streamby.projects SET "dbType" = 'nosql' WHERE "dbType" IS NULL;
|
|
63
|
+
await pool.query(`
|
|
64
|
+
UPDATE streamby.projects SET "dbType" = 'nosql' WHERE "dbType" IS NULL;
|
|
65
65
|
`);
|
|
66
|
-
await pool.query(`
|
|
67
|
-
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET NOT NULL;
|
|
66
|
+
await pool.query(`
|
|
67
|
+
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET NOT NULL;
|
|
68
68
|
`);
|
|
69
|
-
await pool.query(`
|
|
70
|
-
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET DEFAULT 'nosql';
|
|
69
|
+
await pool.query(`
|
|
70
|
+
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET DEFAULT 'nosql';
|
|
71
71
|
`);
|
|
72
|
-
await pool.query(`
|
|
73
|
-
CREATE TABLE IF NOT EXISTS streamby.exports (
|
|
74
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
75
|
-
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
76
|
-
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
|
77
|
-
"filePath" TEXT,
|
|
78
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
79
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
80
|
-
);
|
|
72
|
+
await pool.query(`
|
|
73
|
+
CREATE TABLE IF NOT EXISTS streamby.exports (
|
|
74
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
75
|
+
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
76
|
+
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
|
77
|
+
"filePath" TEXT,
|
|
78
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
79
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
80
|
+
);
|
|
81
81
|
`);
|
|
82
82
|
console.log('β
"exports" table ensured to exist.');
|
|
83
|
-
await pool.query(`
|
|
84
|
-
CREATE TABLE IF NOT EXISTS streamby.project_members (
|
|
85
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
86
|
-
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
87
|
-
"userId" VARCHAR(255) NOT NULL,
|
|
88
|
-
role VARCHAR(255) NOT NULL DEFAULT 'member',
|
|
89
|
-
archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
90
|
-
"archivedBy" VARCHAR(255),
|
|
91
|
-
"archivedAt" TIMESTAMP WITH TIME ZONE,
|
|
92
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
93
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
94
|
-
UNIQUE ("projectId", "userId")
|
|
95
|
-
);
|
|
83
|
+
await pool.query(`
|
|
84
|
+
CREATE TABLE IF NOT EXISTS streamby.project_members (
|
|
85
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
86
|
+
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
87
|
+
"userId" VARCHAR(255) NOT NULL,
|
|
88
|
+
role VARCHAR(255) NOT NULL DEFAULT 'member',
|
|
89
|
+
archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
90
|
+
"archivedBy" VARCHAR(255),
|
|
91
|
+
"archivedAt" TIMESTAMP WITH TIME ZONE,
|
|
92
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
93
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
94
|
+
UNIQUE ("projectId", "userId")
|
|
95
|
+
);
|
|
96
96
|
`);
|
|
97
97
|
console.log('β
"project_members" table ensured to exist.');
|
|
98
98
|
}
|
|
@@ -6,13 +6,13 @@ const createSQLExportTable = async (connection, projectId, exportName, fields) =
|
|
|
6
6
|
const slug = exportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
7
7
|
const tableName = `export_${projectId}_${slug}`;
|
|
8
8
|
const columns = fields.map(field => `"${field.name}" ${field.type}`).join(',');
|
|
9
|
-
const createTableQuery = `
|
|
10
|
-
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
11
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
12
|
-
"projectId" UUID NOT NULL,
|
|
13
|
-
__metadata JSONB NOT NULL,
|
|
14
|
-
${columns ? `, ${columns}` : ''}
|
|
15
|
-
);
|
|
9
|
+
const createTableQuery = `
|
|
10
|
+
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
11
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
12
|
+
"projectId" UUID NOT NULL,
|
|
13
|
+
__metadata JSONB NOT NULL,
|
|
14
|
+
${columns ? `, ${columns}` : ''}
|
|
15
|
+
);
|
|
16
16
|
`;
|
|
17
17
|
await connection.query(createTableQuery);
|
|
18
18
|
console.log(`β
Table '${tableName}' created with metadata.`);
|
|
@@ -30,15 +30,15 @@ exports.createSQLExportTable = createSQLExportTable;
|
|
|
30
30
|
const createSQLRawExportTable = async (connection, projectId, exportName, nodeSchema) => {
|
|
31
31
|
const tableName = projectId;
|
|
32
32
|
const exportId = (0, crypto_1.randomUUID)();
|
|
33
|
-
const createTableQuery = `
|
|
34
|
-
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
35
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
36
|
-
node_schema JSONB,
|
|
37
|
-
name TEXT,
|
|
38
|
-
method TEXT,
|
|
39
|
-
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
40
|
-
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
41
|
-
);
|
|
33
|
+
const createTableQuery = `
|
|
34
|
+
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
35
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
36
|
+
node_schema JSONB,
|
|
37
|
+
name TEXT,
|
|
38
|
+
method TEXT,
|
|
39
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
40
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
41
|
+
);
|
|
42
42
|
`;
|
|
43
43
|
await connection.query(createTableQuery);
|
|
44
44
|
await connection.query(`INSERT INTO "${tableName}" (id, node_schema, name, method) VALUES ($1, $2, $3, $4)`, [exportId, nodeSchema ? JSON.stringify(nodeSchema) : null, exportName, 'GET']);
|
|
@@ -43,7 +43,7 @@ function createStreamByRouter(config) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
if (config.websocket?.server) {
|
|
46
|
-
(0, wsHub_1.initWsHub)(config.websocket.server, config
|
|
46
|
+
(0, wsHub_1.initWsHub)(config.websocket.server, config);
|
|
47
47
|
}
|
|
48
48
|
router.use((0, user_1.userRouter)(config));
|
|
49
49
|
router.use((0, auth_2.authRouter)(config));
|
|
@@ -46,6 +46,20 @@ function notificationRouter(config) {
|
|
|
46
46
|
res.status(500).json({ message: 'Failed to fetch notifications', details: err.message });
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
+
router.get('/notifications/:id', async (req, res) => {
|
|
50
|
+
try {
|
|
51
|
+
const auth = req.auth;
|
|
52
|
+
const { id } = req.params;
|
|
53
|
+
const notifications = (0, manager_1.getModel)('notifications', 'nosql');
|
|
54
|
+
const notification = await notifications.findOne({ _id: new mongodb_1.ObjectId(id), userId: auth.userId.toString() });
|
|
55
|
+
res.status(200).json({
|
|
56
|
+
data: notification,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
res.status(500).json({ message: 'Failed to fetch notifications', details: err.message });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
49
63
|
router.patch('/notifications/read-all', async (req, res) => {
|
|
50
64
|
try {
|
|
51
65
|
const auth = req.auth;
|
package/dist/models/Model.js
CHANGED
|
@@ -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.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.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 => ({
|
package/dist/services/wsHub.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WebSocketServer } from 'ws';
|
|
2
2
|
import { StreamByConfig } from '../types';
|
|
3
|
-
export declare function initWsHub(
|
|
3
|
+
export declare function initWsHub(wss: WebSocketServer, config: StreamByConfig): void;
|
|
4
4
|
export declare function emitToUser(userId: string, event: object): void;
|
package/dist/services/wsHub.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.initWsHub = initWsHub;
|
|
|
4
4
|
exports.emitToUser = emitToUser;
|
|
5
5
|
const ws_1 = require("ws");
|
|
6
6
|
const connections = new Map();
|
|
7
|
-
function initWsHub(
|
|
8
|
-
|
|
7
|
+
function initWsHub(wss, config) {
|
|
8
|
+
console.log('π’ WebSocket hub connected');
|
|
9
9
|
wss.on('connection', async (ws, req) => {
|
|
10
10
|
let userId = null;
|
|
11
11
|
try {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
+
import type { WebSocketServer } from 'ws';
|
|
2
3
|
export interface S3Config {
|
|
3
4
|
bucket: string;
|
|
4
5
|
region: string;
|
|
@@ -100,8 +101,7 @@ export interface StreamByConfig {
|
|
|
100
101
|
adapter?: StorageAdapter;
|
|
101
102
|
encrypt?: string;
|
|
102
103
|
websocket?: {
|
|
103
|
-
server:
|
|
104
|
-
path?: string;
|
|
104
|
+
server: WebSocketServer;
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
export interface Notification {
|
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "streamby-core",
|
|
3
|
-
"version": "0.26.
|
|
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.26.7",
|
|
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
|
+
}
|
package/dist/utils/crypto.d.ts
DELETED
package/dist/utils/crypto.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|