streamby-core 0.23.2 → 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.
@@ -107,6 +107,50 @@ 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.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
+ });
110
154
  router.get('/:projectId/public-export/:exportName', async (req, res) => {
111
155
  try {
112
156
  const { projectId, exportName } = req.params;
@@ -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, updateFilter, data);
260
+ const result = await nosql_1.nosqlAdapter.update(connection, this.tableName, filter, data);
261
261
  if (result)
262
262
  return result;
263
263
  }
@@ -7,4 +7,8 @@ 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>;
11
+ export declare function deleteExport(config: StreamByConfig, projectId: string, exportId: string, dbType: DatabaseType, collectionName: string): Promise<{
12
+ message: string;
13
+ }>;
10
14
  export {};
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExport = createExport;
4
4
  exports.createRawExport = createRawExport;
5
+ exports.updateRawExport = updateRawExport;
6
+ exports.deleteExport = deleteExport;
5
7
  const manager_1 = require("../models/manager");
6
8
  const mongodb_1 = require("mongodb");
7
9
  const connectionManager_1 = require("../adapters/database/connectionManager");
@@ -32,7 +34,7 @@ async function createExport(config, projectId, exportName, collectionName, field
32
34
  // Update the project with the new export reference
33
35
  // Assuming project metadata is always in NoSQL (MongoDB)
34
36
  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' } } });
37
+ 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
38
  return { ...result, message: 'Export created successfully' };
37
39
  }
38
40
  async function createRawExport(config, projectId, exportName, collectionName, jsonData, dbType) {
@@ -58,3 +60,50 @@ async function createRawExport(config, projectId, exportName, collectionName, js
58
60
  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
61
  return { ...result, message: 'Raw export created successfully' };
60
62
  }
63
+ async function updateRawExport(config, projectId, exportId, exportName, collectionName, jsonData, dbType) {
64
+ const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
65
+ config.databases?.find(db => db.type === dbType);
66
+ if (!targetDb) {
67
+ throw new Error(`Database connection not found for type ${dbType}`);
68
+ }
69
+ const connection = (0, connectionManager_1.getConnection)(targetDb.id);
70
+ let result;
71
+ if (dbType === 'nosql') {
72
+ const db = connection.client.db();
73
+ const updateData = {
74
+ json: jsonData,
75
+ name: exportName,
76
+ updatedAt: new Date()
77
+ };
78
+ await db.collection(collectionName).updateOne({ _id: new mongodb_1.ObjectId(exportId) }, { $set: updateData });
79
+ result = { collectionName, exportId };
80
+ }
81
+ else {
82
+ throw new Error('Unsupported database type for update');
83
+ }
84
+ const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
85
+ await NoSQLProject.update({
86
+ _id: new mongodb_1.ObjectId(projectId),
87
+ 'exports.id': { $in: [new mongodb_1.ObjectId(exportId), exportId] }
88
+ }, { $set: { 'exports.$.name': exportName, 'exports.$.collectionName': collectionName } });
89
+ console.log(result);
90
+ return { ...result, message: 'Raw export updated successfully' };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.23.2",
3
+ "version": "0.23.4",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",