streamby-core 0.23.3 β†’ 0.23.4

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 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
+
@@ -129,6 +129,28 @@ function exportRouter(config) {
129
129
  res.status(500).json({ message: 'Failed to update raw export', details: err.message });
130
130
  }
131
131
  });
132
+ router.delete('/projects/:id/exports/:export_id', async (req, res) => {
133
+ try {
134
+ const auth = await config.authProvider(req);
135
+ if (!auth || !auth.userId) {
136
+ return res.status(401).json({ message: 'Unauthorized' });
137
+ }
138
+ const { id: projectId, export_id: exportId } = req.params;
139
+ const project = await Project.findOne({ _id: projectId });
140
+ if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
141
+ return res.status(403).json({ message: 'Unauthorized project access' });
142
+ }
143
+ const exportMetadata = project.exports.find((e) => e.id.toString() === exportId);
144
+ if (!exportMetadata) {
145
+ return res.status(404).json({ message: 'Export not found in this project' });
146
+ }
147
+ await (0, export_1.deleteExport)(config, projectId, exportId, project.dbType, exportMetadata.collectionName);
148
+ res.status(200).json({ message: 'Export deleted successfully' });
149
+ }
150
+ catch (err) {
151
+ res.status(500).json({ message: 'Failed to delete export', details: err.message });
152
+ }
153
+ });
132
154
  router.get('/:projectId/public-export/:exportName', async (req, res) => {
133
155
  try {
134
156
  const { projectId, exportName } = req.params;
@@ -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 => ({
@@ -8,4 +8,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
10
  export declare function updateRawExport(config: StreamByConfig, projectId: string, exportId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
11
+ export declare function deleteExport(config: StreamByConfig, projectId: string, exportId: string, dbType: DatabaseType, collectionName: string): Promise<{
12
+ message: string;
13
+ }>;
11
14
  export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExport = createExport;
4
4
  exports.createRawExport = createRawExport;
5
5
  exports.updateRawExport = updateRawExport;
6
+ exports.deleteExport = deleteExport;
6
7
  const manager_1 = require("../models/manager");
7
8
  const mongodb_1 = require("mongodb");
8
9
  const connectionManager_1 = require("../adapters/database/connectionManager");
@@ -88,3 +89,21 @@ async function updateRawExport(config, projectId, exportId, exportName, collecti
88
89
  console.log(result);
89
90
  return { ...result, message: 'Raw export updated successfully' };
90
91
  }
92
+ async function deleteExport(config, projectId, exportId, dbType, collectionName) {
93
+ const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
94
+ config.databases?.find(db => db.type === dbType);
95
+ if (!targetDb) {
96
+ throw new Error(`Database connection not found for type ${dbType}`);
97
+ }
98
+ const connection = (0, connectionManager_1.getConnection)(targetDb.id);
99
+ if (dbType === 'nosql') {
100
+ const db = connection.client.db();
101
+ await db.collection(collectionName).deleteOne({ _id: new mongodb_1.ObjectId(exportId) });
102
+ }
103
+ else {
104
+ throw new Error('Unsupported database type for delete');
105
+ }
106
+ const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
107
+ await NoSQLProject.update({ _id: new mongodb_1.ObjectId(projectId) }, { $pull: { exports: { id: new mongodb_1.ObjectId(exportId) } } });
108
+ return { message: 'Export deleted successfully' };
109
+ }
package/package.json CHANGED
@@ -1,60 +1,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
- }
1
+ {
2
+ "name": "streamby-core",
3
+ "version": "0.23.4",
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
+ }