streamby-core 0.3.0 โ 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -114
- package/dist/middleware/createRouter.js +15 -1
- package/dist/services/project.d.ts +15 -0
- package/dist/services/project.js +26 -0
- package/dist/types/index.d.ts +10 -1
- package/package.json +45 -45
package/README.md
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
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
|
-
## ๐ฃ Roadmap
|
|
93
|
-
|
|
94
|
-
- [ ] Support for Google Cloud Storage
|
|
95
|
-
- [ ] CLI tool for uploading files
|
|
96
|
-
- [ ] Role-based access control middleware
|
|
97
|
-
- [ ] Plugin system for extended routes
|
|
98
|
-
- [ ] Streaming support (HLS, audio, etc.)
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## ๐งโ๐ป Maintained by
|
|
103
|
-
|
|
104
|
-
**TerminalCore Labs** โ part of [Nhexa Entertainment](https://nhexa.cl)
|
|
105
|
-
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
106
|
-
|
|
107
|
-
Visit us [here](https://terminalcore.cl)
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## ๐ License
|
|
112
|
-
|
|
113
|
-
[MIT](./LICENSE)
|
|
114
|
-
|
|
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
|
+
## ๐ฃ Roadmap
|
|
93
|
+
|
|
94
|
+
- [ ] Support for Google Cloud Storage
|
|
95
|
+
- [ ] CLI tool for uploading files
|
|
96
|
+
- [ ] Role-based access control middleware
|
|
97
|
+
- [ ] Plugin system for extended routes
|
|
98
|
+
- [ ] Streaming support (HLS, audio, etc.)
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## ๐งโ๐ป Maintained by
|
|
103
|
+
|
|
104
|
+
**TerminalCore Labs** โ part of [Nhexa Entertainment](https://nhexa.cl)
|
|
105
|
+
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
106
|
+
|
|
107
|
+
Visit us [here](https://terminalcore.cl)
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## ๐ License
|
|
112
|
+
|
|
113
|
+
[MIT](./LICENSE)
|
|
114
|
+
|
|
@@ -7,6 +7,7 @@ exports.createStreamByRouter = createStreamByRouter;
|
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
8
|
const s3_1 = require("../adapters/s3");
|
|
9
9
|
const file_1 = require("../services/file");
|
|
10
|
+
const project_1 = require("../services/project");
|
|
10
11
|
function createStreamByRouter(config) {
|
|
11
12
|
const router = express_1.default.Router();
|
|
12
13
|
const adapter = config.adapter || (() => {
|
|
@@ -61,12 +62,25 @@ function createStreamByRouter(config) {
|
|
|
61
62
|
if (!projectId || !auth.projects.includes(projectId)) {
|
|
62
63
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
63
64
|
}
|
|
64
|
-
const project = await config.projectProvider(projectId);
|
|
65
|
+
const project = await config.projectProvider.getById(projectId);
|
|
65
66
|
res.json({ project });
|
|
66
67
|
}
|
|
67
68
|
catch (err) {
|
|
68
69
|
res.status(404).json({ error: 'Project not found', details: err });
|
|
69
70
|
}
|
|
70
71
|
});
|
|
72
|
+
router.post('/projects', async (req, res) => {
|
|
73
|
+
try {
|
|
74
|
+
const auth = await config.authProvider(req);
|
|
75
|
+
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
76
|
+
return res.status(403).json({ error: 'Permission denied' });
|
|
77
|
+
}
|
|
78
|
+
const created = await (0, project_1.createProjectService)(req, config.projectProvider);
|
|
79
|
+
res.status(201).json(created);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
res.status(500).json({ error: 'Failed to create project', details: err.message });
|
|
83
|
+
}
|
|
84
|
+
});
|
|
71
85
|
return router;
|
|
72
86
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import { ProjectProvider } from '../types';
|
|
3
|
+
export declare function createProjectService(req: Request, projectProvider: ProjectProvider): Promise<{
|
|
4
|
+
success: boolean;
|
|
5
|
+
project: {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string | undefined;
|
|
9
|
+
settings: {
|
|
10
|
+
allowUpload?: boolean;
|
|
11
|
+
allowSharing?: boolean;
|
|
12
|
+
} | undefined;
|
|
13
|
+
rootFolders: import("../types").FolderNode[];
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProjectService = createProjectService;
|
|
4
|
+
async function createProjectService(req, projectProvider) {
|
|
5
|
+
const { name, description } = req.body;
|
|
6
|
+
if (!name) {
|
|
7
|
+
throw new Error('Project name is required');
|
|
8
|
+
}
|
|
9
|
+
const newProject = await projectProvider.create({
|
|
10
|
+
name,
|
|
11
|
+
description: description || '',
|
|
12
|
+
rootFolders: [],
|
|
13
|
+
allowUpload: true,
|
|
14
|
+
allowSharing: false
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
success: true,
|
|
18
|
+
project: {
|
|
19
|
+
id: newProject.id,
|
|
20
|
+
name: newProject.name,
|
|
21
|
+
description: newProject.description,
|
|
22
|
+
settings: newProject.settings,
|
|
23
|
+
rootFolders: newProject.rootFolders || [],
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -39,4 +39,13 @@ export interface AuthContext {
|
|
|
39
39
|
role: 'viewer' | 'editor' | 'admin';
|
|
40
40
|
}
|
|
41
41
|
export type AuthProvider = (req: Request) => Promise<AuthContext>;
|
|
42
|
-
export
|
|
42
|
+
export interface ProjectProvider {
|
|
43
|
+
getById(projectId: string): Promise<ProjectInfo>;
|
|
44
|
+
create(data: {
|
|
45
|
+
name: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
allowUpload?: boolean;
|
|
48
|
+
allowSharing?: boolean;
|
|
49
|
+
rootFolders?: FolderNode[];
|
|
50
|
+
}): Promise<ProjectInfo>;
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "streamby-core",
|
|
3
|
-
"version": "0.
|
|
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": "tsc --watch",
|
|
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
|
-
"express": "^4.0.0"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/express": "^4.17.17",
|
|
37
|
-
"@types/supertest": "^6.0.3",
|
|
38
|
-
"supertest": "^7.1.0",
|
|
39
|
-
"typescript": "^5.8.3",
|
|
40
|
-
"vitest": "^3.1.1"
|
|
41
|
-
},
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"express": "^4.0.0"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "streamby-core",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "StreamBy middleware framework for media storage management",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"dev": "tsc --watch",
|
|
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
|
+
"express": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/express": "^4.17.17",
|
|
37
|
+
"@types/supertest": "^6.0.3",
|
|
38
|
+
"supertest": "^7.1.0",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"vitest": "^3.1.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"express": "^4.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|