streamby-core 0.23.1 β 0.23.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 +206 -206
- package/dist/middleware/createRouter.js +2 -0
- package/dist/middleware/public.d.ts +2 -0
- package/dist/middleware/public.js +9 -0
- package/dist/middleware/routes/export.js +102 -0
- package/dist/models/Model.js +6 -6
- package/dist/services/auth.d.ts +1 -1
- package/dist/services/auth.js +3 -0
- package/dist/services/export.d.ts +1 -0
- package/dist/services/export.js +31 -1
- package/dist/utils/auth.d.ts +2 -1
- package/dist/utils/auth.js +4 -1
- package/package.json +60 -60
package/README.md
CHANGED
|
@@ -1,206 +1,206 @@
|
|
|
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
|
-
```ts
|
|
32
|
-
import express from 'express';
|
|
33
|
-
import { createStreamByRouter } from '@streamby/core';
|
|
34
|
-
|
|
35
|
-
const app = express();
|
|
36
|
-
|
|
37
|
-
app.use('/streamby', createStreamByRouter({
|
|
38
|
-
storageProvider: {
|
|
39
|
-
type: 's3',
|
|
40
|
-
config: {
|
|
41
|
-
bucket: 'your-bucket-name',
|
|
42
|
-
region: 'your-region',
|
|
43
|
-
accessKeyId: 'YOUR_AWS_KEY',
|
|
44
|
-
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
authProvider: async (req) => {
|
|
48
|
-
// extract token/cookie and validate
|
|
49
|
-
return {
|
|
50
|
-
userId: 'demo',
|
|
51
|
-
projects: ['demo-project'],
|
|
52
|
-
role: 'admin',
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
projectProvider: async (projectId) => {
|
|
56
|
-
// fetch project from your DB
|
|
57
|
-
return {
|
|
58
|
-
id: projectId,
|
|
59
|
-
name: 'Demo Project',
|
|
60
|
-
description: 'Demo for StreamBy integration',
|
|
61
|
-
rootFolders: [],
|
|
62
|
-
settings: { allowUpload: true }
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
app.listen(3000);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## π§ͺ Testing
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
npm run test
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## π Features
|
|
83
|
-
|
|
84
|
-
- π Multi-project access control
|
|
85
|
-
- π Project-aware file uploads & listings
|
|
86
|
-
- π§Ή Modular adapters per storage provider
|
|
87
|
-
- π§° Built-in testability with mock auth & storage
|
|
88
|
-
- β¨ Simple to extend for custom business logic
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## πΊοΈ API Endpoints
|
|
93
|
-
|
|
94
|
-
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
95
|
-
|
|
96
|
-
### `GET /streamby/projects`
|
|
97
|
-
|
|
98
|
-
Lists all projects accessible by the authenticated user.
|
|
99
|
-
|
|
100
|
-
**Query Parameters:**
|
|
101
|
-
- `archived`: (Optional) Filter projects by their archived status.
|
|
102
|
-
- `true`: Returns only archived projects.
|
|
103
|
-
- `false`: Returns only unarchived projects.
|
|
104
|
-
- (Omitted): Returns all projects (both archived and unarchived).
|
|
105
|
-
|
|
106
|
-
**Example Response:**
|
|
107
|
-
```json
|
|
108
|
-
{
|
|
109
|
-
"projects": [
|
|
110
|
-
{
|
|
111
|
-
"id": "project1_id",
|
|
112
|
-
"dbType": "nosql",
|
|
113
|
-
"name": "My NoSQL Project",
|
|
114
|
-
"image": "url_to_image",
|
|
115
|
-
"archived": false
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
"id": "project2_id",
|
|
119
|
-
"dbType": "sql",
|
|
120
|
-
"name": "My SQL Project",
|
|
121
|
-
"image": "url_to_image",
|
|
122
|
-
"archived": true
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### `PATCH /streamby/projects/:id/archive`
|
|
129
|
-
|
|
130
|
-
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
131
|
-
|
|
132
|
-
**Example Response:**
|
|
133
|
-
```json
|
|
134
|
-
{
|
|
135
|
-
"success": true,
|
|
136
|
-
"projects": [
|
|
137
|
-
{
|
|
138
|
-
"id": "project1_id",
|
|
139
|
-
"dbType": "nosql",
|
|
140
|
-
"name": "My NoSQL Project",
|
|
141
|
-
"image": "url_to_image",
|
|
142
|
-
"archived": true
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
"id": "project2_id",
|
|
146
|
-
"dbType": "sql",
|
|
147
|
-
"name": "My SQL Project",
|
|
148
|
-
"image": "url_to_image",
|
|
149
|
-
"archived": false
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### `PATCH /streamby/projects/:id/unarchive`
|
|
156
|
-
|
|
157
|
-
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
158
|
-
|
|
159
|
-
**Example Response:**
|
|
160
|
-
```json
|
|
161
|
-
{
|
|
162
|
-
"success": true,
|
|
163
|
-
"projects": [
|
|
164
|
-
{
|
|
165
|
-
"id": "project1_id",
|
|
166
|
-
"dbType": "nosql",
|
|
167
|
-
"name": "My NoSQL Project",
|
|
168
|
-
"image": "url_to_image",
|
|
169
|
-
"archived": false
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
"id": "project2_id",
|
|
173
|
-
"dbType": "sql",
|
|
174
|
-
"name": "My SQL Project",
|
|
175
|
-
"image": "url_to_image",
|
|
176
|
-
"archived": false
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## π£ Roadmap
|
|
185
|
-
|
|
186
|
-
- [ ] Support for Google Cloud Storage
|
|
187
|
-
- [ ] CLI tool for uploading files
|
|
188
|
-
- [ ] Role-based access control middleware
|
|
189
|
-
- [ ] Plugin system for extended routes
|
|
190
|
-
- [ ] Streaming support (HLS, audio, etc.)
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## π§βπ» Maintained by
|
|
195
|
-
|
|
196
|
-
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
197
|
-
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
198
|
-
|
|
199
|
-
Visit us [here](https://terminalcore.cl)
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
## π License
|
|
204
|
-
|
|
205
|
-
[MIT](./LICENSE)
|
|
206
|
-
|
|
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
|
+
```ts
|
|
32
|
+
import express from 'express';
|
|
33
|
+
import { createStreamByRouter } from '@streamby/core';
|
|
34
|
+
|
|
35
|
+
const app = express();
|
|
36
|
+
|
|
37
|
+
app.use('/streamby', createStreamByRouter({
|
|
38
|
+
storageProvider: {
|
|
39
|
+
type: 's3',
|
|
40
|
+
config: {
|
|
41
|
+
bucket: 'your-bucket-name',
|
|
42
|
+
region: 'your-region',
|
|
43
|
+
accessKeyId: 'YOUR_AWS_KEY',
|
|
44
|
+
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
authProvider: async (req) => {
|
|
48
|
+
// extract token/cookie and validate
|
|
49
|
+
return {
|
|
50
|
+
userId: 'demo',
|
|
51
|
+
projects: ['demo-project'],
|
|
52
|
+
role: 'admin',
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
projectProvider: async (projectId) => {
|
|
56
|
+
// fetch project from your DB
|
|
57
|
+
return {
|
|
58
|
+
id: projectId,
|
|
59
|
+
name: 'Demo Project',
|
|
60
|
+
description: 'Demo for StreamBy integration',
|
|
61
|
+
rootFolders: [],
|
|
62
|
+
settings: { allowUpload: true }
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
app.listen(3000);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## π§ͺ Testing
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm run test
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## π Features
|
|
83
|
+
|
|
84
|
+
- π Multi-project access control
|
|
85
|
+
- π Project-aware file uploads & listings
|
|
86
|
+
- π§Ή Modular adapters per storage provider
|
|
87
|
+
- π§° Built-in testability with mock auth & storage
|
|
88
|
+
- β¨ Simple to extend for custom business logic
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## πΊοΈ API Endpoints
|
|
93
|
+
|
|
94
|
+
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
95
|
+
|
|
96
|
+
### `GET /streamby/projects`
|
|
97
|
+
|
|
98
|
+
Lists all projects accessible by the authenticated user.
|
|
99
|
+
|
|
100
|
+
**Query Parameters:**
|
|
101
|
+
- `archived`: (Optional) Filter projects by their archived status.
|
|
102
|
+
- `true`: Returns only archived projects.
|
|
103
|
+
- `false`: Returns only unarchived projects.
|
|
104
|
+
- (Omitted): Returns all projects (both archived and unarchived).
|
|
105
|
+
|
|
106
|
+
**Example Response:**
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"projects": [
|
|
110
|
+
{
|
|
111
|
+
"id": "project1_id",
|
|
112
|
+
"dbType": "nosql",
|
|
113
|
+
"name": "My NoSQL Project",
|
|
114
|
+
"image": "url_to_image",
|
|
115
|
+
"archived": false
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "project2_id",
|
|
119
|
+
"dbType": "sql",
|
|
120
|
+
"name": "My SQL Project",
|
|
121
|
+
"image": "url_to_image",
|
|
122
|
+
"archived": true
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `PATCH /streamby/projects/:id/archive`
|
|
129
|
+
|
|
130
|
+
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
131
|
+
|
|
132
|
+
**Example Response:**
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"success": true,
|
|
136
|
+
"projects": [
|
|
137
|
+
{
|
|
138
|
+
"id": "project1_id",
|
|
139
|
+
"dbType": "nosql",
|
|
140
|
+
"name": "My NoSQL Project",
|
|
141
|
+
"image": "url_to_image",
|
|
142
|
+
"archived": true
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"id": "project2_id",
|
|
146
|
+
"dbType": "sql",
|
|
147
|
+
"name": "My SQL Project",
|
|
148
|
+
"image": "url_to_image",
|
|
149
|
+
"archived": false
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `PATCH /streamby/projects/:id/unarchive`
|
|
156
|
+
|
|
157
|
+
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
158
|
+
|
|
159
|
+
**Example Response:**
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"success": true,
|
|
163
|
+
"projects": [
|
|
164
|
+
{
|
|
165
|
+
"id": "project1_id",
|
|
166
|
+
"dbType": "nosql",
|
|
167
|
+
"name": "My NoSQL Project",
|
|
168
|
+
"image": "url_to_image",
|
|
169
|
+
"archived": false
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"id": "project2_id",
|
|
173
|
+
"dbType": "sql",
|
|
174
|
+
"name": "My SQL Project",
|
|
175
|
+
"image": "url_to_image",
|
|
176
|
+
"archived": false
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## π£ Roadmap
|
|
185
|
+
|
|
186
|
+
- [ ] Support for Google Cloud Storage
|
|
187
|
+
- [ ] CLI tool for uploading files
|
|
188
|
+
- [ ] Role-based access control middleware
|
|
189
|
+
- [ ] Plugin system for extended routes
|
|
190
|
+
- [ ] Streaming support (HLS, audio, etc.)
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## π§βπ» Maintained by
|
|
195
|
+
|
|
196
|
+
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
197
|
+
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
198
|
+
|
|
199
|
+
Visit us [here](https://terminalcore.cl)
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## π License
|
|
204
|
+
|
|
205
|
+
[MIT](./LICENSE)
|
|
206
|
+
|
|
@@ -13,6 +13,7 @@ const database_1 = require("./routes/database");
|
|
|
13
13
|
const storage_2 = require("./routes/storage");
|
|
14
14
|
const project_1 = require("./routes/project");
|
|
15
15
|
const export_1 = require("./routes/export");
|
|
16
|
+
const auth_2 = require("../services/auth");
|
|
16
17
|
function createStreamByRouter(config) {
|
|
17
18
|
const router = express_1.default.Router();
|
|
18
19
|
(0, connectionManager_1.initConnections)(config.databases || []);
|
|
@@ -26,6 +27,7 @@ function createStreamByRouter(config) {
|
|
|
26
27
|
(0, manager_1.registerModel)('users', [mainDb.id], 'users');
|
|
27
28
|
}
|
|
28
29
|
}
|
|
30
|
+
router.use((0, auth_2.authenticate)(config));
|
|
29
31
|
router.use((0, auth_1.authRouter)(config));
|
|
30
32
|
router.use((0, database_1.databaseRouter)(config));
|
|
31
33
|
router.use((0, storage_2.storageRouter)(config));
|
|
@@ -107,6 +107,108 @@ function exportRouter(config) {
|
|
|
107
107
|
res.status(500).json({ message: 'Failed to create raw export', details: err.message });
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
|
+
router.patch('/projects/:id/exports/raw/:export_id', async (req, res) => {
|
|
111
|
+
try {
|
|
112
|
+
const auth = await config.authProvider(req);
|
|
113
|
+
if (!auth || !auth.userId) {
|
|
114
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
115
|
+
}
|
|
116
|
+
const { id: projectId, export_id: exportId } = req.params;
|
|
117
|
+
const { name, collectionName, description, jsonData } = req.body;
|
|
118
|
+
if (!name || !collectionName || !jsonData) {
|
|
119
|
+
return res.status(400).json({ message: 'Missing name, collectionName, or jsonData' });
|
|
120
|
+
}
|
|
121
|
+
const project = await Project.findOne({ _id: projectId });
|
|
122
|
+
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
123
|
+
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
124
|
+
}
|
|
125
|
+
const result = await (0, export_1.updateRawExport)(config, projectId, exportId, name, collectionName, jsonData, project.dbType);
|
|
126
|
+
res.status(200).json({ data: result, message: result.message });
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
res.status(500).json({ message: 'Failed to update raw export', details: err.message });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
|
133
|
+
try {
|
|
134
|
+
const { projectId, exportName } = req.params;
|
|
135
|
+
const project = await Project.findOne({ _id: projectId });
|
|
136
|
+
if (!project) {
|
|
137
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
138
|
+
}
|
|
139
|
+
const exportMetadata = project.exports.find((e) => e.name === exportName);
|
|
140
|
+
if (!exportMetadata) {
|
|
141
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
142
|
+
}
|
|
143
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
144
|
+
if (!targetDb) {
|
|
145
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
146
|
+
}
|
|
147
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
148
|
+
let data;
|
|
149
|
+
if (project.dbType === 'nosql') {
|
|
150
|
+
const db = connection.client.db();
|
|
151
|
+
if (exportMetadata.type === 'raw') {
|
|
152
|
+
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
153
|
+
data = rawData ? rawData.json : null;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
data = await db.collection(exportMetadata.collectionName).find({ __metadata: { $exists: false } }).toArray();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (project.dbType === 'sql') {
|
|
160
|
+
// SQL implementation for public exports will go here
|
|
161
|
+
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
162
|
+
}
|
|
163
|
+
if (!data) {
|
|
164
|
+
return res.status(404).json({ message: 'Export data not found' });
|
|
165
|
+
}
|
|
166
|
+
res.json(data); // Return the raw data directly
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
|
173
|
+
try {
|
|
174
|
+
const { projectId, exportName } = req.params;
|
|
175
|
+
const project = await Project.findOne({ _id: projectId });
|
|
176
|
+
if (!project) {
|
|
177
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
178
|
+
}
|
|
179
|
+
const exportMetadata = project.exports.find((e) => e.name === exportName);
|
|
180
|
+
if (!exportMetadata) {
|
|
181
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
182
|
+
}
|
|
183
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
184
|
+
if (!targetDb) {
|
|
185
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
186
|
+
}
|
|
187
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
188
|
+
let data;
|
|
189
|
+
if (project.dbType === 'nosql') {
|
|
190
|
+
const db = connection.client.db();
|
|
191
|
+
if (exportMetadata.type === 'raw') {
|
|
192
|
+
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
193
|
+
data = rawData ? rawData.json : null;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
data = await db.collection(exportMetadata.collectionName).find({ __metadata: { $exists: false } }).toArray();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (project.dbType === 'sql') {
|
|
200
|
+
// SQL implementation for public exports will go here
|
|
201
|
+
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
202
|
+
}
|
|
203
|
+
if (!data) {
|
|
204
|
+
return res.status(404).json({ message: 'Export data not found' });
|
|
205
|
+
}
|
|
206
|
+
res.json(data); // Return the raw data directly
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
210
|
+
}
|
|
211
|
+
});
|
|
110
212
|
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
|
111
213
|
try {
|
|
112
214
|
const { projectId, exportName } = req.params;
|
package/dist/models/Model.js
CHANGED
|
@@ -34,11 +34,11 @@ class Model {
|
|
|
34
34
|
if (this.tableName === 'projects' && processedFilter.members && processedFilter.members.$elemMatch) {
|
|
35
35
|
// Handle members filter for SQL projects
|
|
36
36
|
const userId = processedFilter.members.$elemMatch.userId;
|
|
37
|
-
const query = `
|
|
38
|
-
SELECT p.*, pm."userId" as memberUserId, pm.archived as memberArchived
|
|
39
|
-
FROM "projects" p
|
|
40
|
-
JOIN "project_members" pm ON p.id = pm."projectId"
|
|
41
|
-
WHERE pm."userId" = $1
|
|
37
|
+
const query = `
|
|
38
|
+
SELECT p.*, pm."userId" as memberUserId, pm.archived as memberArchived
|
|
39
|
+
FROM "projects" p
|
|
40
|
+
JOIN "project_members" pm ON p.id = pm."projectId"
|
|
41
|
+
WHERE pm."userId" = $1
|
|
42
42
|
`;
|
|
43
43
|
const result = await connection.query(query, [userId]);
|
|
44
44
|
sqlResults = result.rows.map(row => ({
|
|
@@ -257,7 +257,7 @@ class Model {
|
|
|
257
257
|
return result;
|
|
258
258
|
}
|
|
259
259
|
else if (dbType === 'nosql') {
|
|
260
|
-
const result = await nosql_1.nosqlAdapter.update(connection, this.tableName,
|
|
260
|
+
const result = await nosql_1.nosqlAdapter.update(connection, this.tableName, filter, data);
|
|
261
261
|
if (result)
|
|
262
262
|
return result;
|
|
263
263
|
}
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Auth } from '../types';
|
|
2
2
|
import { Request, Response, NextFunction } from 'express';
|
|
3
3
|
import { StreamByConfig } from '../types';
|
|
4
|
-
export declare const authenticate: (config: StreamByConfig) => (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any
|
|
4
|
+
export declare const authenticate: (config: StreamByConfig) => (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
5
5
|
export declare function checkRole(auth: Auth, required: 'viewer' | 'editor' | 'admin'): void;
|
package/dist/services/auth.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.authenticate = void 0;
|
|
4
4
|
exports.checkRole = checkRole;
|
|
5
5
|
const authenticate = (config) => async (req, res, next) => {
|
|
6
|
+
if (req.path.includes('/public-export/')) {
|
|
7
|
+
return next();
|
|
8
|
+
}
|
|
6
9
|
try {
|
|
7
10
|
const auth = await config.authProvider(req);
|
|
8
11
|
if (!auth || !auth.userId || !auth.role) {
|
|
@@ -7,4 +7,5 @@ interface CreateExportResult {
|
|
|
7
7
|
import { StreamByConfig } from '../types';
|
|
8
8
|
export declare function createExport(config: StreamByConfig, projectId: string, exportName: string, collectionName: string, fields: FieldDefinition[], dbType: DatabaseType): Promise<CreateExportResult>;
|
|
9
9
|
export declare function createRawExport(config: StreamByConfig, projectId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
|
|
10
|
+
export declare function updateRawExport(config: StreamByConfig, projectId: string, exportId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
|
|
10
11
|
export {};
|
package/dist/services/export.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExport = createExport;
|
|
4
4
|
exports.createRawExport = createRawExport;
|
|
5
|
+
exports.updateRawExport = updateRawExport;
|
|
5
6
|
const manager_1 = require("../models/manager");
|
|
6
7
|
const mongodb_1 = require("mongodb");
|
|
7
8
|
const connectionManager_1 = require("../adapters/database/connectionManager");
|
|
@@ -32,7 +33,7 @@ async function createExport(config, projectId, exportName, collectionName, field
|
|
|
32
33
|
// Update the project with the new export reference
|
|
33
34
|
// Assuming project metadata is always in NoSQL (MongoDB)
|
|
34
35
|
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
35
|
-
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: result.exportId, collectionName: result.collectionName, type: 'structured', fields, method: 'GET' } } });
|
|
36
|
+
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: dbType === 'nosql' ? new mongodb_1.ObjectId(result.exportId) : result.exportId, name: exportName, collectionName: result.collectionName, type: 'structured', fields, method: 'GET' } } });
|
|
36
37
|
return { ...result, message: 'Export created successfully' };
|
|
37
38
|
}
|
|
38
39
|
async function createRawExport(config, projectId, exportName, collectionName, jsonData, dbType) {
|
|
@@ -58,3 +59,32 @@ async function createRawExport(config, projectId, exportName, collectionName, js
|
|
|
58
59
|
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: dbType === 'nosql' ? new mongodb_1.ObjectId(result.exportId) : result.exportId, name: exportName, collectionName: result.collectionName, type: 'raw', method: 'GET' } } });
|
|
59
60
|
return { ...result, message: 'Raw export created successfully' };
|
|
60
61
|
}
|
|
62
|
+
async function updateRawExport(config, projectId, exportId, exportName, collectionName, jsonData, dbType) {
|
|
63
|
+
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
64
|
+
config.databases?.find(db => db.type === dbType);
|
|
65
|
+
if (!targetDb) {
|
|
66
|
+
throw new Error(`Database connection not found for type ${dbType}`);
|
|
67
|
+
}
|
|
68
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
69
|
+
let result;
|
|
70
|
+
if (dbType === 'nosql') {
|
|
71
|
+
const db = connection.client.db();
|
|
72
|
+
const updateData = {
|
|
73
|
+
json: jsonData,
|
|
74
|
+
name: exportName,
|
|
75
|
+
updatedAt: new Date()
|
|
76
|
+
};
|
|
77
|
+
await db.collection(collectionName).updateOne({ _id: new mongodb_1.ObjectId(exportId) }, { $set: updateData });
|
|
78
|
+
result = { collectionName, exportId };
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error('Unsupported database type for update');
|
|
82
|
+
}
|
|
83
|
+
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
84
|
+
await NoSQLProject.update({
|
|
85
|
+
_id: new mongodb_1.ObjectId(projectId),
|
|
86
|
+
'exports.id': { $in: [new mongodb_1.ObjectId(exportId), exportId] }
|
|
87
|
+
}, { $set: { 'exports.$.name': exportName, 'exports.$.collectionName': collectionName } });
|
|
88
|
+
console.log(result);
|
|
89
|
+
return { ...result, message: 'Raw export updated successfully' };
|
|
90
|
+
}
|
package/dist/utils/auth.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ProjectInfo } from '../types';
|
|
2
|
+
export declare function isProjectMember(project: ProjectInfo, userId: string): boolean;
|
package/dist/utils/auth.js
CHANGED
|
@@ -2,5 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isProjectMember = isProjectMember;
|
|
4
4
|
function isProjectMember(project, userId) {
|
|
5
|
-
|
|
5
|
+
if (!project || !project.members) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return project.members.some(member => member.userId === userId);
|
|
6
9
|
}
|
package/package.json
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "streamby-core",
|
|
3
|
-
"version": "0.23.
|
|
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
|
-
},
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@types/bcrypt": "^5.0.2",
|
|
45
|
-
"@types/cors": "^2.8.18",
|
|
46
|
-
"@types/express": "^4.17.17",
|
|
47
|
-
"@types/mongodb": "^4.0.7",
|
|
48
|
-
"@types/node": "^22.15.21",
|
|
49
|
-
"@types/pg": "^8.15.4",
|
|
50
|
-
"@types/supertest": "^6.0.3",
|
|
51
|
-
"cors": "^2.8.5",
|
|
52
|
-
"supertest": "^7.1.4",
|
|
53
|
-
"ts-node-dev": "^2.0.0",
|
|
54
|
-
"typescript": "^5.8.3",
|
|
55
|
-
"vitest": "^3.1.1"
|
|
56
|
-
},
|
|
57
|
-
"peerDependencies": {
|
|
58
|
-
"express": "^4.0.0"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "streamby-core",
|
|
3
|
+
"version": "0.23.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
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bcrypt": "^5.0.2",
|
|
45
|
+
"@types/cors": "^2.8.18",
|
|
46
|
+
"@types/express": "^4.17.17",
|
|
47
|
+
"@types/mongodb": "^4.0.7",
|
|
48
|
+
"@types/node": "^22.15.21",
|
|
49
|
+
"@types/pg": "^8.15.4",
|
|
50
|
+
"@types/supertest": "^6.0.3",
|
|
51
|
+
"cors": "^2.8.5",
|
|
52
|
+
"supertest": "^7.1.4",
|
|
53
|
+
"ts-node-dev": "^2.0.0",
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"vitest": "^3.1.1"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"express": "^4.0.0"
|
|
59
|
+
}
|
|
60
|
+
}
|