streamby-core 0.28.5 → 0.28.6

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.
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runRenderJob = runRenderJob;
4
+ exports.runFormatConvertJob = runFormatConvertJob;
5
+ exports.runLodJob = runLodJob;
6
+ exports.resolveAssetDependencyGraph = resolveAssetDependencyGraph;
7
+ const connectionManager_1 = require("../adapters/database/connectionManager");
8
+ const jobQueue_1 = require("./jobQueue");
9
+ function getNosqlDb() {
10
+ const ids = (0, connectionManager_1.getConnectedIds)().filter(id => (0, connectionManager_1.getConnection)(id).type === 'nosql');
11
+ if (!ids.length)
12
+ return null;
13
+ return (0, connectionManager_1.getConnection)(ids[0]).client.db();
14
+ }
15
+ async function runRenderJob(jobId, fileId, projectId, options) {
16
+ (0, jobQueue_1.updateJob)(jobId, { status: 'processing', stage: 'resolving', progress: 10, assetId: fileId });
17
+ try {
18
+ const db = getNosqlDb();
19
+ if (!db)
20
+ throw new Error('Storage database not available');
21
+ const fileDoc = await db.collection('storage_files').findOne({ fileId, projectId });
22
+ if (!fileDoc)
23
+ throw new Error(`File ${fileId} not found`);
24
+ (0, jobQueue_1.updateJob)(jobId, { stage: 'queued-farm', progress: 20 });
25
+ // Store pending render task — picked up by the host render farm worker
26
+ await db.collection('media_metadata').updateOne({ assetId: fileId, projectId }, {
27
+ $set: {
28
+ assetId: fileId,
29
+ projectId,
30
+ pendingRender: {
31
+ renderer: options.renderer ?? 'blender',
32
+ renderFarmConnectionId: options.renderFarmConnectionId,
33
+ frameRange: options.frameRange ?? '1-1',
34
+ resolution: options.resolution ?? '1920x1080',
35
+ samples: options.samples ?? 128,
36
+ outputFormat: options.outputFormat ?? 'png',
37
+ requestedAt: new Date(),
38
+ },
39
+ customTags: {},
40
+ extractedAt: new Date(),
41
+ },
42
+ }, { upsert: true });
43
+ (0, jobQueue_1.updateJob)(jobId, { stage: 'pending-worker', progress: 30 });
44
+ }
45
+ catch (err) {
46
+ (0, jobQueue_1.failJob)(jobId, err.message);
47
+ }
48
+ }
49
+ async function runFormatConvertJob(jobId, fileId, projectId, options) {
50
+ (0, jobQueue_1.updateJob)(jobId, { status: 'processing', stage: 'resolving', progress: 10, assetId: fileId });
51
+ try {
52
+ const db = getNosqlDb();
53
+ if (!db)
54
+ throw new Error('Storage database not available');
55
+ const fileDoc = await db.collection('storage_files').findOne({ fileId, projectId });
56
+ if (!fileDoc)
57
+ throw new Error(`File ${fileId} not found`);
58
+ (0, jobQueue_1.updateJob)(jobId, { stage: 'queued-convert', progress: 25 });
59
+ await db.collection('media_metadata').updateOne({ assetId: fileId, projectId }, {
60
+ $set: {
61
+ assetId: fileId,
62
+ projectId,
63
+ pendingFormatConvert: {
64
+ inputFormat: options.inputFormat ?? 'fbx',
65
+ outputFormat: options.outputFormat ?? 'glb',
66
+ applyTransforms: options.applyTransforms ?? true,
67
+ embedTextures: options.embedTextures ?? true,
68
+ requestedAt: new Date(),
69
+ },
70
+ customTags: {},
71
+ extractedAt: new Date(),
72
+ },
73
+ }, { upsert: true });
74
+ (0, jobQueue_1.updateJob)(jobId, { stage: 'pending-worker', progress: 35 });
75
+ }
76
+ catch (err) {
77
+ (0, jobQueue_1.failJob)(jobId, err.message);
78
+ }
79
+ }
80
+ async function runLodJob(jobId, fileId, projectId, options) {
81
+ (0, jobQueue_1.updateJob)(jobId, { status: 'processing', stage: 'resolving', progress: 10, assetId: fileId });
82
+ try {
83
+ const db = getNosqlDb();
84
+ if (!db)
85
+ throw new Error('Storage database not available');
86
+ const fileDoc = await db.collection('storage_files').findOne({ fileId, projectId });
87
+ if (!fileDoc)
88
+ throw new Error(`File ${fileId} not found`);
89
+ (0, jobQueue_1.updateJob)(jobId, { stage: 'queued-lod', progress: 25 });
90
+ await db.collection('media_metadata').updateOne({ assetId: fileId, projectId }, {
91
+ $set: {
92
+ assetId: fileId,
93
+ projectId,
94
+ pendingLod: {
95
+ levels: options.levels ?? 3,
96
+ reductionRatios: options.reductionRatios ?? [0.5, 0.25, 0.1],
97
+ algorithm: options.algorithm ?? 'quadric',
98
+ outputFormat: options.outputFormat ?? 'glb',
99
+ requestedAt: new Date(),
100
+ },
101
+ customTags: {},
102
+ extractedAt: new Date(),
103
+ },
104
+ }, { upsert: true });
105
+ (0, jobQueue_1.updateJob)(jobId, { stage: 'pending-worker', progress: 30 });
106
+ }
107
+ catch (err) {
108
+ (0, jobQueue_1.failJob)(jobId, err.message);
109
+ }
110
+ }
111
+ async function resolveAssetDependencyGraph(projectId, rootAssetId, maxDepth = 5) {
112
+ const db = getNosqlDb();
113
+ if (!db)
114
+ return { nodes: [], edges: [] };
115
+ const filesCol = db.collection('storage_files');
116
+ const visited = new Set();
117
+ const nodes = [];
118
+ const edges = [];
119
+ async function walk(assetId, depth) {
120
+ if (depth > maxDepth || visited.has(assetId))
121
+ return;
122
+ visited.add(assetId);
123
+ const file = await filesCol.findOne({ fileId: assetId, projectId });
124
+ nodes.push({
125
+ assetId,
126
+ type: file?.contentType ?? 'unknown',
127
+ resolved: !!file,
128
+ });
129
+ // Dependencies are stored as a `dependencies` array on the file document
130
+ const deps = file?.dependencies ?? [];
131
+ for (const depId of deps) {
132
+ edges.push({ from: assetId, to: depId, relationship: 'depends-on' });
133
+ await walk(depId, depth + 1);
134
+ }
135
+ }
136
+ await walk(rootAssetId, 0);
137
+ await db.collection('asset_dependency_graphs').updateOne({ rootAssetId, projectId }, { $set: { rootAssetId, projectId, nodes, edges, resolvedAt: new Date() } }, { upsert: true });
138
+ return { nodes, edges };
139
+ }
@@ -186,4 +186,192 @@ export interface Export {
186
186
  useConnections?: boolean;
187
187
  useCredentials?: boolean;
188
188
  storageDbId?: string;
189
+ deliverableType?: 'api' | 'video-stream' | 'game-build' | 'asset-bundle' | 'app-binary';
190
+ deliverableVersion?: string;
191
+ deliverableTargets?: DeliveryTarget[];
192
+ publishedAt?: Date;
193
+ publishedBy?: string;
194
+ cdnUrl?: string;
195
+ }
196
+ export type DistributionTarget = 'cdnPush' | 'hlsStream' | 'steam' | 'appStoreConnect' | 'googlePlay' | 'itchIo' | 'customWebhook';
197
+ export type DeliveryStatus = 'pending' | 'publishing' | 'published' | 'failed';
198
+ export interface DeliveryTarget {
199
+ connectionId: string;
200
+ target: DistributionTarget;
201
+ channel?: string;
202
+ publishedAt?: Date;
203
+ publishedBy?: string;
204
+ receipt?: Record<string, string>;
205
+ status: DeliveryStatus;
206
+ }
207
+ export interface DistributionConnection {
208
+ id: string;
209
+ name: string;
210
+ target: DistributionTarget;
211
+ credentialId?: string;
212
+ projectId: string;
213
+ config: Record<string, string>;
214
+ createdAt: Date;
215
+ description?: string;
216
+ }
217
+ export interface QcCheck {
218
+ name: string;
219
+ passed: boolean;
220
+ value: string | number;
221
+ threshold: string | number;
222
+ message?: string;
223
+ }
224
+ export interface QcReportRecord {
225
+ assetId: string;
226
+ projectId: string;
227
+ checks: QcCheck[];
228
+ overallPassed: boolean;
229
+ generatedAt: Date;
230
+ }
231
+ export type JobType = 'ingest' | 'transcode' | 'caption' | 'thumbnail' | 'render' | 'format-convert' | 'lod' | 'distribute' | 'qc' | 'transcription' | 'upscale' | 'generate-asset';
232
+ export type AiProvider = 'openai' | 'deepgram' | 'assemblyai' | 'stabilityai' | 'meshy' | 'elevenlabs' | 'custom';
233
+ export interface PipelineSuggestion {
234
+ rationale: string;
235
+ nodesToAdd: {
236
+ type: string;
237
+ label: string;
238
+ position: {
239
+ x: number;
240
+ y: number;
241
+ };
242
+ }[];
243
+ edgesToAdd: {
244
+ source: string;
245
+ sourceHandle: string;
246
+ target: string;
247
+ targetHandle: string;
248
+ }[];
249
+ }
250
+ export type RenderFarmProvider = 'flamenco' | 'deadline' | 'rebusfarm' | 'sheepit' | 'custom';
251
+ export interface RenderFarmConnection {
252
+ id: string;
253
+ name: string;
254
+ provider: RenderFarmProvider;
255
+ apiUrl: string;
256
+ credentialId?: string;
257
+ projectId: string;
258
+ createdAt: Date;
259
+ description?: string;
260
+ }
261
+ export interface LodLevel {
262
+ level: number;
263
+ ratio: number;
264
+ storageFileId: string;
265
+ polyCount?: number;
266
+ fileSize?: number;
267
+ }
268
+ export interface LodManifestRecord {
269
+ assetId: string;
270
+ projectId: string;
271
+ levels: LodLevel[];
272
+ generatedAt: Date;
273
+ }
274
+ export interface AssetDependencyGraphRecord {
275
+ rootAssetId: string;
276
+ projectId: string;
277
+ nodes: {
278
+ assetId: string;
279
+ type: string;
280
+ resolved: boolean;
281
+ }[];
282
+ edges: {
283
+ from: string;
284
+ to: string;
285
+ relationship: string;
286
+ }[];
287
+ resolvedAt: Date;
288
+ }
289
+ export type ReviewStatus = 'open' | 'approved' | 'rejected' | 'expired';
290
+ export type ReviewDecision = 'approve' | 'reject';
291
+ export interface ReviewApproval {
292
+ userId: string;
293
+ username: string;
294
+ decision: ReviewDecision;
295
+ comment?: string;
296
+ at: Date;
297
+ }
298
+ export interface ReviewSessionRecord {
299
+ id: string;
300
+ projectId: string;
301
+ assetId: string;
302
+ assetVersionId: string;
303
+ status: ReviewStatus;
304
+ requiredApprovers: number;
305
+ approvals: ReviewApproval[];
306
+ deadline?: Date;
307
+ createdAt: Date;
308
+ updatedAt: Date;
309
+ }
310
+ export type AnnotationType = 'timecoded' | 'spatial' | 'region';
311
+ export interface AnnotationRecord {
312
+ id: string;
313
+ assetId: string;
314
+ assetVersionId: string;
315
+ projectId: string;
316
+ authorId: string;
317
+ authorUsername: string;
318
+ type: AnnotationType;
319
+ timecode?: string;
320
+ position3d?: {
321
+ x: number;
322
+ y: number;
323
+ z: number;
324
+ };
325
+ regionRect?: {
326
+ x: number;
327
+ y: number;
328
+ width: number;
329
+ height: number;
330
+ };
331
+ text: string;
332
+ resolved: boolean;
333
+ resolvedBy?: string;
334
+ createdAt: Date;
335
+ }
336
+ export type JobStatus = 'pending' | 'processing' | 'completed' | 'failed';
337
+ export interface JobRecord {
338
+ jobId: string;
339
+ jobType: JobType;
340
+ userId: string;
341
+ projectId: string;
342
+ assetId?: string;
343
+ status: JobStatus;
344
+ stage: string;
345
+ progress: number;
346
+ payload: Record<string, any>;
347
+ error?: string;
348
+ createdAt: Date;
349
+ updatedAt: Date;
350
+ }
351
+ export interface AssetMetadataRecord {
352
+ assetId: string;
353
+ projectId: string;
354
+ duration?: number;
355
+ width?: number;
356
+ height?: number;
357
+ frameRate?: number;
358
+ colorSpace?: string;
359
+ codec?: string;
360
+ bitrate?: number;
361
+ channels?: number;
362
+ sampleRate?: number;
363
+ customTags: Record<string, string>;
364
+ extractedAt: Date;
365
+ }
366
+ export interface AssetVersionRecord {
367
+ versionId: string;
368
+ assetId: string;
369
+ projectId: string;
370
+ version: number;
371
+ label?: string;
372
+ storageKey: string;
373
+ size: number;
374
+ createdBy: string;
375
+ changeNote?: string;
376
+ createdAt: Date;
189
377
  }
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "streamby-core",
3
- "version": "0.28.5",
4
- "description": "StreamBy middleware framework for media storage management",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "dist"
9
- ],
10
- "scripts": {
11
- "build": "tsc",
12
- "test": "vitest",
13
- "dev": "ts-node-dev --respawn --clear dev.ts",
14
- "prepublishOnly": "npm run build"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/GwerhDev/StreamBy-Package.git"
19
- },
20
- "keywords": [
21
- "streamby",
22
- "middleware",
23
- "upload",
24
- "storage",
25
- "s3",
26
- "express",
27
- "typescript"
28
- ],
29
- "author": "TerminalCore Labs",
30
- "license": "MIT",
31
- "dependencies": {
32
- "@aws-sdk/client-s3": "^3.528.0",
33
- "@aws-sdk/s3-request-presigner": "^3.787.0",
34
- "@prisma/client": "^6.12.0",
35
- "bcrypt": "^5.1.1",
36
- "dotenv": "^16.5.0",
37
- "express": "^4.0.0",
38
- "mongodb": "^6.17.0",
39
- "mongoose": "^8.13.2",
40
- "node-fetch": "^3.0.0",
41
- "pg": "^8.16.3",
42
- "prisma": "^6.12.0",
43
- "ws": "^8.20.0"
44
- },
45
- "devDependencies": {
46
- "@types/bcrypt": "^5.0.2",
47
- "@types/cors": "^2.8.18",
48
- "@types/express": "^4.17.17",
49
- "@types/mongodb": "^4.0.7",
50
- "@types/node": "^22.15.21",
51
- "@types/pg": "^8.15.4",
52
- "@types/supertest": "^6.0.3",
53
- "@types/ws": "^8.18.1",
54
- "cors": "^2.8.5",
55
- "supertest": "^7.1.4",
56
- "ts-node-dev": "^2.0.0",
57
- "typescript": "^5.8.3",
58
- "vitest": "^3.1.1"
59
- },
60
- "peerDependencies": {
61
- "express": "^4.0.0"
62
- }
63
- }
1
+ {
2
+ "name": "streamby-core",
3
+ "version": "0.28.6",
4
+ "description": "StreamBy middleware framework for media storage management",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "vitest",
13
+ "dev": "ts-node-dev --respawn --clear dev.ts",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/GwerhDev/StreamBy-Package.git"
19
+ },
20
+ "keywords": [
21
+ "streamby",
22
+ "middleware",
23
+ "upload",
24
+ "storage",
25
+ "s3",
26
+ "express",
27
+ "typescript"
28
+ ],
29
+ "author": "TerminalCore Labs",
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "@aws-sdk/client-s3": "^3.528.0",
33
+ "@aws-sdk/s3-request-presigner": "^3.787.0",
34
+ "@prisma/client": "^6.12.0",
35
+ "bcrypt": "^5.1.1",
36
+ "dotenv": "^16.5.0",
37
+ "express": "^4.0.0",
38
+ "mongodb": "^6.17.0",
39
+ "mongoose": "^8.13.2",
40
+ "node-fetch": "^3.0.0",
41
+ "pg": "^8.16.3",
42
+ "prisma": "^6.12.0",
43
+ "ws": "^8.20.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/bcrypt": "^5.0.2",
47
+ "@types/cors": "^2.8.18",
48
+ "@types/express": "^4.17.17",
49
+ "@types/mongodb": "^4.0.7",
50
+ "@types/node": "^22.15.21",
51
+ "@types/pg": "^8.15.4",
52
+ "@types/supertest": "^6.0.3",
53
+ "@types/ws": "^8.18.1",
54
+ "cors": "^2.8.5",
55
+ "supertest": "^7.1.4",
56
+ "ts-node-dev": "^2.0.0",
57
+ "typescript": "^5.8.3",
58
+ "vitest": "^3.1.1"
59
+ },
60
+ "peerDependencies": {
61
+ "express": "^4.0.0"
62
+ }
63
+ }
@@ -1,3 +0,0 @@
1
- export declare function encrypt(text: string, secretKey: string): string;
2
- export declare function decrypt(text: string, secretKey: string): string;
3
- export declare function hash(text: string): string;
@@ -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
- }