streamby-core 0.25.2 β 0.25.3
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 +242 -242
- package/dist/adapters/database/connectionManager.js +41 -41
- package/dist/adapters/database/sql.js +12 -12
- package/dist/middleware/createRouter.js +2 -0
- package/dist/middleware/routes/apiConnection.d.ts +3 -0
- package/dist/middleware/routes/apiConnection.js +100 -0
- package/dist/middleware/routes/project.js +1 -1
- package/dist/models/Model.js +5 -2
- package/dist/services/apiConnection.d.ts +10 -0
- package/dist/services/apiConnection.js +40 -0
- package/dist/types/index.d.ts +13 -0
- package/package.json +61 -61
- package/dist/utils/crypto.d.ts +0 -3
- package/dist/utils/crypto.js +0 -32
package/README.md
CHANGED
|
@@ -1,242 +1,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
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## π§± Basic usage
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## ποΈ Database Schema Setup
|
|
34
|
-
|
|
35
|
-
`@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.
|
|
36
|
-
|
|
37
|
-
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`.
|
|
38
|
-
|
|
39
|
-
### PostgreSQL Example
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { Pool } from "pg";
|
|
43
|
-
import { setupStreambyPg } from "@streamby/core/pg/setup"; // Adjust path as per your package structure
|
|
44
|
-
|
|
45
|
-
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
46
|
-
|
|
47
|
-
// Call setupStreambyPg to ensure the schema and tables are created
|
|
48
|
-
// reset: false (default) ensures idempotency and no data loss
|
|
49
|
-
await setupStreambyPg({ pool, schema: "streamby", reset: false });
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### MongoDB Example
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { MongoClient } from "mongodb";
|
|
56
|
-
import { setupStreambyMongo } from "@streamby/core/mongo/setup"; // Adjust path as per your package structure
|
|
57
|
-
|
|
58
|
-
const client = new MongoClient(process.env.MONGO_URL!);
|
|
59
|
-
|
|
60
|
-
// Connect the MongoDB client
|
|
61
|
-
await client.connect();
|
|
62
|
-
|
|
63
|
-
// Call setupStreambyMongo to ensure collections and indexes are created
|
|
64
|
-
await setupStreambyMongo({ client, dbName: "streamby" });
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import express from 'express';
|
|
69
|
-
import { createStreamByRouter } from '@streamby/core';
|
|
70
|
-
|
|
71
|
-
const app = express();
|
|
72
|
-
|
|
73
|
-
app.use('/streamby', createStreamByRouter({
|
|
74
|
-
storageProvider: {
|
|
75
|
-
type: 's3',
|
|
76
|
-
config: {
|
|
77
|
-
bucket: 'your-bucket-name',
|
|
78
|
-
region: 'your-region',
|
|
79
|
-
accessKeyId: 'YOUR_AWS_KEY',
|
|
80
|
-
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
authProvider: async (req) => {
|
|
84
|
-
// extract token/cookie and validate
|
|
85
|
-
return {
|
|
86
|
-
userId: 'demo',
|
|
87
|
-
projects: ['demo-project'],
|
|
88
|
-
role: 'admin',
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
projectProvider: async (projectId) => {
|
|
92
|
-
// fetch project from your DB
|
|
93
|
-
return {
|
|
94
|
-
id: projectId,
|
|
95
|
-
name: 'Demo Project',
|
|
96
|
-
description: 'Demo for StreamBy integration',
|
|
97
|
-
rootFolders: [],
|
|
98
|
-
settings: { allowUpload: true }
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
app.listen(3000);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
---
|
|
107
|
-
|
|
108
|
-
## π§ͺ Testing
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
npm run test
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## π Features
|
|
119
|
-
|
|
120
|
-
- π Multi-project access control
|
|
121
|
-
- π Project-aware file uploads & listings
|
|
122
|
-
- π§Ή Modular adapters per storage provider
|
|
123
|
-
- π§° Built-in testability with mock auth & storage
|
|
124
|
-
- β¨ Simple to extend for custom business logic
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## πΊοΈ API Endpoints
|
|
129
|
-
|
|
130
|
-
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
131
|
-
|
|
132
|
-
### `GET /streamby/projects`
|
|
133
|
-
|
|
134
|
-
Lists all projects accessible by the authenticated user.
|
|
135
|
-
|
|
136
|
-
**Query Parameters:**
|
|
137
|
-
- `archived`: (Optional) Filter projects by their archived status.
|
|
138
|
-
- `true`: Returns only archived projects.
|
|
139
|
-
- `false`: Returns only unarchived projects.
|
|
140
|
-
- (Omitted): Returns all projects (both archived and unarchived).
|
|
141
|
-
|
|
142
|
-
**Example Response:**
|
|
143
|
-
```json
|
|
144
|
-
{
|
|
145
|
-
"projects": [
|
|
146
|
-
{
|
|
147
|
-
"id": "project1_id",
|
|
148
|
-
"dbType": "nosql",
|
|
149
|
-
"name": "My NoSQL Project",
|
|
150
|
-
"image": "url_to_image",
|
|
151
|
-
"archived": false
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
"id": "project2_id",
|
|
155
|
-
"dbType": "sql",
|
|
156
|
-
"name": "My SQL Project",
|
|
157
|
-
"image": "url_to_image",
|
|
158
|
-
"archived": true
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### `PATCH /streamby/projects/:id/archive`
|
|
165
|
-
|
|
166
|
-
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
167
|
-
|
|
168
|
-
**Example Response:**
|
|
169
|
-
```json
|
|
170
|
-
{
|
|
171
|
-
"success": true,
|
|
172
|
-
"projects": [
|
|
173
|
-
{
|
|
174
|
-
"id": "project1_id",
|
|
175
|
-
"dbType": "nosql",
|
|
176
|
-
"name": "My NoSQL Project",
|
|
177
|
-
"image": "url_to_image",
|
|
178
|
-
"archived": true
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
"id": "project2_id",
|
|
182
|
-
"dbType": "sql",
|
|
183
|
-
"name": "My SQL Project",
|
|
184
|
-
"image": "url_to_image",
|
|
185
|
-
"archived": false
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### `PATCH /streamby/projects/:id/unarchive`
|
|
192
|
-
|
|
193
|
-
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
194
|
-
|
|
195
|
-
**Example Response:**
|
|
196
|
-
```json
|
|
197
|
-
{
|
|
198
|
-
"success": true,
|
|
199
|
-
"projects": [
|
|
200
|
-
{
|
|
201
|
-
"id": "project1_id",
|
|
202
|
-
"dbType": "nosql",
|
|
203
|
-
"name": "My NoSQL Project",
|
|
204
|
-
"image": "url_to_image",
|
|
205
|
-
"archived": false
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
"id": "project2_id",
|
|
209
|
-
"dbType": "sql",
|
|
210
|
-
"name": "My SQL Project",
|
|
211
|
-
"image": "url_to_image",
|
|
212
|
-
"archived": false
|
|
213
|
-
}
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
## π£ Roadmap
|
|
221
|
-
|
|
222
|
-
- [ ] Support for Google Cloud Storage
|
|
223
|
-
- [ ] CLI tool for uploading files
|
|
224
|
-
- [ ] Role-based access control middleware
|
|
225
|
-
- [ ] Plugin system for extended routes
|
|
226
|
-
- [ ] Streaming support (HLS, audio, etc.)
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
|
-
## π§βπ» Maintained by
|
|
231
|
-
|
|
232
|
-
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
233
|
-
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
234
|
-
|
|
235
|
-
Visit us [here](https://terminalcore.cl)
|
|
236
|
-
|
|
237
|
-
---
|
|
238
|
-
|
|
239
|
-
## π License
|
|
240
|
-
|
|
241
|
-
[MIT](./LICENSE)
|
|
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
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## π§± Basic usage
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## ποΈ Database Schema Setup
|
|
34
|
+
|
|
35
|
+
`@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.
|
|
36
|
+
|
|
37
|
+
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`.
|
|
38
|
+
|
|
39
|
+
### PostgreSQL Example
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { Pool } from "pg";
|
|
43
|
+
import { setupStreambyPg } from "@streamby/core/pg/setup"; // Adjust path as per your package structure
|
|
44
|
+
|
|
45
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
46
|
+
|
|
47
|
+
// Call setupStreambyPg to ensure the schema and tables are created
|
|
48
|
+
// reset: false (default) ensures idempotency and no data loss
|
|
49
|
+
await setupStreambyPg({ pool, schema: "streamby", reset: false });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### MongoDB Example
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { MongoClient } from "mongodb";
|
|
56
|
+
import { setupStreambyMongo } from "@streamby/core/mongo/setup"; // Adjust path as per your package structure
|
|
57
|
+
|
|
58
|
+
const client = new MongoClient(process.env.MONGO_URL!);
|
|
59
|
+
|
|
60
|
+
// Connect the MongoDB client
|
|
61
|
+
await client.connect();
|
|
62
|
+
|
|
63
|
+
// Call setupStreambyMongo to ensure collections and indexes are created
|
|
64
|
+
await setupStreambyMongo({ client, dbName: "streamby" });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import express from 'express';
|
|
69
|
+
import { createStreamByRouter } from '@streamby/core';
|
|
70
|
+
|
|
71
|
+
const app = express();
|
|
72
|
+
|
|
73
|
+
app.use('/streamby', createStreamByRouter({
|
|
74
|
+
storageProvider: {
|
|
75
|
+
type: 's3',
|
|
76
|
+
config: {
|
|
77
|
+
bucket: 'your-bucket-name',
|
|
78
|
+
region: 'your-region',
|
|
79
|
+
accessKeyId: 'YOUR_AWS_KEY',
|
|
80
|
+
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
authProvider: async (req) => {
|
|
84
|
+
// extract token/cookie and validate
|
|
85
|
+
return {
|
|
86
|
+
userId: 'demo',
|
|
87
|
+
projects: ['demo-project'],
|
|
88
|
+
role: 'admin',
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
projectProvider: async (projectId) => {
|
|
92
|
+
// fetch project from your DB
|
|
93
|
+
return {
|
|
94
|
+
id: projectId,
|
|
95
|
+
name: 'Demo Project',
|
|
96
|
+
description: 'Demo for StreamBy integration',
|
|
97
|
+
rootFolders: [],
|
|
98
|
+
settings: { allowUpload: true }
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
app.listen(3000);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## π§ͺ Testing
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm run test
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## π Features
|
|
119
|
+
|
|
120
|
+
- π Multi-project access control
|
|
121
|
+
- π Project-aware file uploads & listings
|
|
122
|
+
- π§Ή Modular adapters per storage provider
|
|
123
|
+
- π§° Built-in testability with mock auth & storage
|
|
124
|
+
- β¨ Simple to extend for custom business logic
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## πΊοΈ API Endpoints
|
|
129
|
+
|
|
130
|
+
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
131
|
+
|
|
132
|
+
### `GET /streamby/projects`
|
|
133
|
+
|
|
134
|
+
Lists all projects accessible by the authenticated user.
|
|
135
|
+
|
|
136
|
+
**Query Parameters:**
|
|
137
|
+
- `archived`: (Optional) Filter projects by their archived status.
|
|
138
|
+
- `true`: Returns only archived projects.
|
|
139
|
+
- `false`: Returns only unarchived projects.
|
|
140
|
+
- (Omitted): Returns all projects (both archived and unarchived).
|
|
141
|
+
|
|
142
|
+
**Example Response:**
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"projects": [
|
|
146
|
+
{
|
|
147
|
+
"id": "project1_id",
|
|
148
|
+
"dbType": "nosql",
|
|
149
|
+
"name": "My NoSQL Project",
|
|
150
|
+
"image": "url_to_image",
|
|
151
|
+
"archived": false
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"id": "project2_id",
|
|
155
|
+
"dbType": "sql",
|
|
156
|
+
"name": "My SQL Project",
|
|
157
|
+
"image": "url_to_image",
|
|
158
|
+
"archived": true
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `PATCH /streamby/projects/:id/archive`
|
|
165
|
+
|
|
166
|
+
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
167
|
+
|
|
168
|
+
**Example Response:**
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"success": true,
|
|
172
|
+
"projects": [
|
|
173
|
+
{
|
|
174
|
+
"id": "project1_id",
|
|
175
|
+
"dbType": "nosql",
|
|
176
|
+
"name": "My NoSQL Project",
|
|
177
|
+
"image": "url_to_image",
|
|
178
|
+
"archived": true
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"id": "project2_id",
|
|
182
|
+
"dbType": "sql",
|
|
183
|
+
"name": "My SQL Project",
|
|
184
|
+
"image": "url_to_image",
|
|
185
|
+
"archived": false
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### `PATCH /streamby/projects/:id/unarchive`
|
|
192
|
+
|
|
193
|
+
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
194
|
+
|
|
195
|
+
**Example Response:**
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"success": true,
|
|
199
|
+
"projects": [
|
|
200
|
+
{
|
|
201
|
+
"id": "project1_id",
|
|
202
|
+
"dbType": "nosql",
|
|
203
|
+
"name": "My NoSQL Project",
|
|
204
|
+
"image": "url_to_image",
|
|
205
|
+
"archived": false
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"id": "project2_id",
|
|
209
|
+
"dbType": "sql",
|
|
210
|
+
"name": "My SQL Project",
|
|
211
|
+
"image": "url_to_image",
|
|
212
|
+
"archived": false
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## π£ Roadmap
|
|
221
|
+
|
|
222
|
+
- [ ] Support for Google Cloud Storage
|
|
223
|
+
- [ ] CLI tool for uploading files
|
|
224
|
+
- [ ] Role-based access control middleware
|
|
225
|
+
- [ ] Plugin system for extended routes
|
|
226
|
+
- [ ] Streaming support (HLS, audio, etc.)
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## π§βπ» Maintained by
|
|
231
|
+
|
|
232
|
+
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
233
|
+
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
234
|
+
|
|
235
|
+
Visit us [here](https://terminalcore.cl)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## π License
|
|
240
|
+
|
|
241
|
+
[MIT](./LICENSE)
|
|
242
|
+
|
|
@@ -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
|
}
|
|
@@ -5,13 +5,13 @@ const createSQLExportTable = async (connection, projectId, exportName, fields) =
|
|
|
5
5
|
const slug = exportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
6
6
|
const tableName = `export_${projectId}_${slug}`;
|
|
7
7
|
const columns = fields.map(field => `"${field.name}" ${field.type}`).join(',');
|
|
8
|
-
const createTableQuery = `
|
|
9
|
-
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
10
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
11
|
-
"projectId" UUID NOT NULL,
|
|
12
|
-
__metadata JSONB NOT NULL,
|
|
13
|
-
${columns ? `, ${columns}` : ''}
|
|
14
|
-
);
|
|
8
|
+
const createTableQuery = `
|
|
9
|
+
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
10
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
11
|
+
"projectId" UUID NOT NULL,
|
|
12
|
+
__metadata JSONB NOT NULL,
|
|
13
|
+
${columns ? `, ${columns}` : ''}
|
|
14
|
+
);
|
|
15
15
|
`;
|
|
16
16
|
await connection.query(createTableQuery);
|
|
17
17
|
console.log(`β
Table '${tableName}' created with metadata.`);
|
|
@@ -29,11 +29,11 @@ exports.createSQLExportTable = createSQLExportTable;
|
|
|
29
29
|
const createSQLRawExportTable = async (connection, projectId, exportName, jsonData) => {
|
|
30
30
|
const slug = exportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
31
31
|
const tableName = `raw_export_${projectId}_${slug}`;
|
|
32
|
-
const createTableQuery = `
|
|
33
|
-
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
34
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
35
|
-
data JSONB NOT NULL
|
|
36
|
-
);
|
|
32
|
+
const createTableQuery = `
|
|
33
|
+
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
34
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
35
|
+
data JSONB NOT NULL
|
|
36
|
+
);
|
|
37
37
|
`;
|
|
38
38
|
await connection.query(createTableQuery);
|
|
39
39
|
console.log(`β
Raw table '${tableName}' created.`);
|
|
@@ -14,6 +14,7 @@ const storage_2 = require("./routes/storage");
|
|
|
14
14
|
const project_1 = require("./routes/project");
|
|
15
15
|
const export_1 = require("./routes/export");
|
|
16
16
|
const credential_1 = require("./routes/credential");
|
|
17
|
+
const apiConnection_1 = require("./routes/apiConnection");
|
|
17
18
|
const auth_2 = require("../services/auth");
|
|
18
19
|
const encryption_1 = require("../utils/encryption");
|
|
19
20
|
function createStreamByRouter(config) {
|
|
@@ -40,5 +41,6 @@ function createStreamByRouter(config) {
|
|
|
40
41
|
router.use((0, project_1.projectRouter)(config));
|
|
41
42
|
router.use((0, export_1.exportRouter)(config));
|
|
42
43
|
router.use((0, credential_1.credentialRouter)(config));
|
|
44
|
+
router.use((0, apiConnection_1.apiConnectionRouter)(config));
|
|
43
45
|
return router;
|
|
44
46
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiConnectionRouter = apiConnectionRouter;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const manager_1 = require("../../models/manager");
|
|
6
|
+
const auth_1 = require("../../utils/auth");
|
|
7
|
+
const apiConnection_1 = require("../../services/apiConnection");
|
|
8
|
+
const VALID_METHODS = ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'];
|
|
9
|
+
function apiConnectionRouter(config) {
|
|
10
|
+
const router = (0, express_1.Router)();
|
|
11
|
+
const Project = (0, manager_1.getModel)('projects');
|
|
12
|
+
// List API connections for a project
|
|
13
|
+
router.get('/projects/:id/api/connections', async (req, res) => {
|
|
14
|
+
try {
|
|
15
|
+
const auth = req.auth;
|
|
16
|
+
const projectId = req.params.id;
|
|
17
|
+
const project = await Project.findOne({ _id: projectId });
|
|
18
|
+
if (!project) {
|
|
19
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
20
|
+
}
|
|
21
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
22
|
+
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
23
|
+
}
|
|
24
|
+
return res.status(200).json({ data: project.apiConnections || [] });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
res.status(500).json({ message: 'Failed to fetch API connections', details: err.message });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
// Add a new API connection to a project
|
|
31
|
+
router.post('/projects/:id/api/connections', async (req, res) => {
|
|
32
|
+
try {
|
|
33
|
+
const auth = req.auth;
|
|
34
|
+
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
35
|
+
return res.status(403).json({ message: 'Permission denied' });
|
|
36
|
+
}
|
|
37
|
+
const projectId = req.params.id;
|
|
38
|
+
const { name, baseUrl, method, description, credentialId, prefix } = req.body;
|
|
39
|
+
if (!name || !baseUrl) {
|
|
40
|
+
return res.status(400).json({ message: 'name and baseUrl are required' });
|
|
41
|
+
}
|
|
42
|
+
if (!VALID_METHODS.includes(method)) {
|
|
43
|
+
return res.status(400).json({ message: `method must be one of: ${VALID_METHODS.join(', ')}` });
|
|
44
|
+
}
|
|
45
|
+
const project = await Project.findOne({ _id: projectId });
|
|
46
|
+
if (!project) {
|
|
47
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
48
|
+
}
|
|
49
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
50
|
+
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
51
|
+
}
|
|
52
|
+
if (credentialId) {
|
|
53
|
+
const credExists = project.credentials?.some((c) => c.id === credentialId);
|
|
54
|
+
if (!credExists) {
|
|
55
|
+
return res.status(400).json({ message: 'Credential not found in project' });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const connection = await (0, apiConnection_1.addApiConnection)(config, projectId, {
|
|
59
|
+
name,
|
|
60
|
+
baseUrl,
|
|
61
|
+
method,
|
|
62
|
+
prefix,
|
|
63
|
+
...(description !== undefined && { description }),
|
|
64
|
+
...(credentialId !== undefined && { credentialId }),
|
|
65
|
+
});
|
|
66
|
+
return res.status(201).json({ data: connection });
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
res.status(500).json({ message: 'Failed to add API connection', details: err.message });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// Delete an API connection from a project
|
|
73
|
+
router.delete('/projects/:id/api/connections/:connectionId', async (req, res) => {
|
|
74
|
+
try {
|
|
75
|
+
const auth = req.auth;
|
|
76
|
+
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
77
|
+
return res.status(403).json({ message: 'Permission denied' });
|
|
78
|
+
}
|
|
79
|
+
const projectId = req.params.id;
|
|
80
|
+
const { connectionId } = req.params;
|
|
81
|
+
const project = await Project.findOne({ _id: projectId });
|
|
82
|
+
if (!project) {
|
|
83
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
84
|
+
}
|
|
85
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
86
|
+
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
87
|
+
}
|
|
88
|
+
const exists = project.apiConnections?.some((c) => c.id === connectionId);
|
|
89
|
+
if (!exists) {
|
|
90
|
+
return res.status(404).json({ message: 'API connection not found' });
|
|
91
|
+
}
|
|
92
|
+
await (0, apiConnection_1.deleteApiConnection)(config, projectId, connectionId);
|
|
93
|
+
return res.status(200).json({ message: 'API connection deleted successfully.' });
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
res.status(500).json({ message: 'Failed to delete API connection', details: err.message });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return router;
|
|
100
|
+
}
|
|
@@ -96,7 +96,7 @@ function projectRouter(config) {
|
|
|
96
96
|
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
97
97
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
98
98
|
}
|
|
99
|
-
res.json({ project: { ...project, id: project._id || project.id, _id: undefined }, message: 'Project fetched successfully' });
|
|
99
|
+
res.json({ project: { ...project, id: project._id || project.id, _id: undefined, apiConnections: project.apiConnections || [] }, message: 'Project fetched successfully' });
|
|
100
100
|
}
|
|
101
101
|
catch (err) {
|
|
102
102
|
res.status(500).json({ message: 'Failed to fetch project', details: err.message });
|
package/dist/models/Model.js
CHANGED
|
@@ -20,6 +20,8 @@ class Model {
|
|
|
20
20
|
}
|
|
21
21
|
useDbType(dbType) {
|
|
22
22
|
const filteredConnectionIds = this.connectionIds.filter(id => {
|
|
23
|
+
if (!(0, connectionManager_1.getConnectedIds)().includes(id))
|
|
24
|
+
return false;
|
|
23
25
|
const connection = (0, connectionManager_1.getConnection)(id);
|
|
24
26
|
return connection.type === dbType;
|
|
25
27
|
});
|
|
@@ -198,8 +200,9 @@ class Model {
|
|
|
198
200
|
return null; // Project not found
|
|
199
201
|
}
|
|
200
202
|
const targetDbType = existingProject.dbType; // Get the actual dbType of the project
|
|
201
|
-
// Find the connection that matches the targetDbType
|
|
202
|
-
const
|
|
203
|
+
// Find the connection that matches the targetDbType (only among active connections)
|
|
204
|
+
const activeConnectionIds = this.connectionIds.filter(id => (0, connectionManager_1.getConnectedIds)().includes(id));
|
|
205
|
+
const clientEntry = activeConnectionIds
|
|
203
206
|
.map(id => (0, connectionManager_1.getConnection)(id))
|
|
204
207
|
.find(entry => entry.type === targetDbType);
|
|
205
208
|
if (!clientEntry) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StreamByConfig, ApiConnection, ApiConnectionMethod } from '../types';
|
|
2
|
+
export declare function addApiConnection(config: StreamByConfig, projectId: string, data: {
|
|
3
|
+
name: string;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
method: ApiConnectionMethod;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
credentialId?: string;
|
|
9
|
+
}): Promise<ApiConnection>;
|
|
10
|
+
export declare function deleteApiConnection(config: StreamByConfig, projectId: string, connectionId: string): Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addApiConnection = addApiConnection;
|
|
4
|
+
exports.deleteApiConnection = deleteApiConnection;
|
|
5
|
+
const mongodb_1 = require("mongodb");
|
|
6
|
+
const manager_1 = require("../models/manager");
|
|
7
|
+
async function addApiConnection(config, projectId, data) {
|
|
8
|
+
const ProjectModel = (0, manager_1.getModel)('projects');
|
|
9
|
+
const project = await ProjectModel.findOne({ _id: projectId });
|
|
10
|
+
if (!project) {
|
|
11
|
+
throw new Error('Project not found.');
|
|
12
|
+
}
|
|
13
|
+
const connection = {
|
|
14
|
+
id: new mongodb_1.ObjectId().toHexString(),
|
|
15
|
+
name: data.name,
|
|
16
|
+
prefix: data.prefix,
|
|
17
|
+
baseUrl: data.baseUrl,
|
|
18
|
+
method: data.method,
|
|
19
|
+
projectId,
|
|
20
|
+
createdAt: new Date(),
|
|
21
|
+
...(data.description !== undefined && { description: data.description }),
|
|
22
|
+
...(data.credentialId !== undefined && { credentialId: data.credentialId }),
|
|
23
|
+
};
|
|
24
|
+
const updatedProject = await ProjectModel.update({ _id: projectId }, { $push: { apiConnections: connection } });
|
|
25
|
+
if (!updatedProject) {
|
|
26
|
+
throw new Error('Failed to add API connection to project.');
|
|
27
|
+
}
|
|
28
|
+
return connection;
|
|
29
|
+
}
|
|
30
|
+
async function deleteApiConnection(config, projectId, connectionId) {
|
|
31
|
+
const ProjectModel = (0, manager_1.getModel)('projects');
|
|
32
|
+
const project = await ProjectModel.findOne({ _id: projectId });
|
|
33
|
+
if (!project) {
|
|
34
|
+
throw new Error('Project not found.');
|
|
35
|
+
}
|
|
36
|
+
const updatedProject = await ProjectModel.update({ _id: projectId }, { $pull: { apiConnections: { id: connectionId } } });
|
|
37
|
+
if (!updatedProject) {
|
|
38
|
+
throw new Error('Failed to delete API connection from project.');
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -57,12 +57,25 @@ export interface ProjectInfo {
|
|
|
57
57
|
allowSharing?: boolean;
|
|
58
58
|
};
|
|
59
59
|
credentials?: Credential[];
|
|
60
|
+
apiConnections?: ApiConnection[];
|
|
60
61
|
}
|
|
61
62
|
export interface Credential {
|
|
62
63
|
id: string;
|
|
63
64
|
key: string;
|
|
64
65
|
encryptedValue: string;
|
|
65
66
|
}
|
|
67
|
+
export type ApiConnectionMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
68
|
+
export interface ApiConnection {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
baseUrl: string;
|
|
72
|
+
method: ApiConnectionMethod;
|
|
73
|
+
projectId: string;
|
|
74
|
+
createdAt: Date;
|
|
75
|
+
prefix?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
credentialId?: string;
|
|
78
|
+
}
|
|
66
79
|
export interface ProjectListInfo {
|
|
67
80
|
id: string;
|
|
68
81
|
dbType: DatabaseType;
|
package/package.json
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "streamby-core",
|
|
3
|
-
"version": "0.25.
|
|
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
|
-
"pg": "^8.16.3",
|
|
41
|
-
"prisma": "^6.12.0",
|
|
42
|
-
"node-fetch": "^3.0.0"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@types/bcrypt": "^5.0.2",
|
|
46
|
-
"@types/cors": "^2.8.18",
|
|
47
|
-
"@types/express": "^4.17.17",
|
|
48
|
-
"@types/mongodb": "^4.0.7",
|
|
49
|
-
"@types/node": "^22.15.21",
|
|
50
|
-
"@types/pg": "^8.15.4",
|
|
51
|
-
"@types/supertest": "^6.0.3",
|
|
52
|
-
"cors": "^2.8.5",
|
|
53
|
-
"supertest": "^7.1.4",
|
|
54
|
-
"ts-node-dev": "^2.0.0",
|
|
55
|
-
"typescript": "^5.8.3",
|
|
56
|
-
"vitest": "^3.1.1"
|
|
57
|
-
},
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"express": "^4.0.0"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "streamby-core",
|
|
3
|
+
"version": "0.25.3",
|
|
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
|
+
"pg": "^8.16.3",
|
|
41
|
+
"prisma": "^6.12.0",
|
|
42
|
+
"node-fetch": "^3.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/bcrypt": "^5.0.2",
|
|
46
|
+
"@types/cors": "^2.8.18",
|
|
47
|
+
"@types/express": "^4.17.17",
|
|
48
|
+
"@types/mongodb": "^4.0.7",
|
|
49
|
+
"@types/node": "^22.15.21",
|
|
50
|
+
"@types/pg": "^8.15.4",
|
|
51
|
+
"@types/supertest": "^6.0.3",
|
|
52
|
+
"cors": "^2.8.5",
|
|
53
|
+
"supertest": "^7.1.4",
|
|
54
|
+
"ts-node-dev": "^2.0.0",
|
|
55
|
+
"typescript": "^5.8.3",
|
|
56
|
+
"vitest": "^3.1.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"express": "^4.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|
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
|
-
}
|