streamby-core 0.24.14 → 0.24.17
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.
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.exportRouter = exportRouter;
|
|
37
4
|
const express_1 = require("express");
|
|
@@ -73,9 +40,19 @@ function exportRouter(config) {
|
|
|
73
40
|
let data;
|
|
74
41
|
if (project.dbType === 'nosql') {
|
|
75
42
|
const db = connection.client.db();
|
|
76
|
-
if (exportMetadata.type === '
|
|
43
|
+
if (exportMetadata.type === 'json') {
|
|
77
44
|
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportId) });
|
|
78
|
-
data =
|
|
45
|
+
data = {
|
|
46
|
+
json: rawData?.json,
|
|
47
|
+
name: rawData?.name,
|
|
48
|
+
method: rawData?.method,
|
|
49
|
+
collectionName: rawData?.collectionName,
|
|
50
|
+
createdAt: rawData?.createdAt,
|
|
51
|
+
updatedAt: rawData?.updatedAt,
|
|
52
|
+
type: exportMetadata.type,
|
|
53
|
+
fields: exportMetadata.fields,
|
|
54
|
+
description: rawData?.description,
|
|
55
|
+
};
|
|
79
56
|
}
|
|
80
57
|
else if (exportMetadata.type === 'externalApi') {
|
|
81
58
|
const ProjectModel = (0, manager_1.getModel)('projects', 'nosql');
|
|
@@ -83,11 +60,60 @@ function exportRouter(config) {
|
|
|
83
60
|
if (!currentProject) {
|
|
84
61
|
return res.status(404).json({ message: 'Project not found.' });
|
|
85
62
|
}
|
|
86
|
-
|
|
63
|
+
let headers = {};
|
|
64
|
+
if (exportMetadata.credentialId) {
|
|
65
|
+
if (!(0, encryption_1.isEncryptionKeySet)()) {
|
|
66
|
+
throw new Error('Encryption key is not set. Cannot use encrypted credentials.');
|
|
67
|
+
}
|
|
68
|
+
const credential = project.credentials?.find((cred) => cred.id === exportMetadata.credentialId);
|
|
69
|
+
if (credential) {
|
|
70
|
+
const decryptedValue = (0, encryption_1.decrypt)(credential.encryptedValue);
|
|
71
|
+
const authPrefix = exportMetadata.prefix ? `${exportMetadata.prefix} ` : '';
|
|
72
|
+
headers = {
|
|
73
|
+
'Authorization': `${authPrefix}${decryptedValue}`,
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const externalApiData = await fetch(exportMetadata.apiUrl, { headers });
|
|
79
|
+
const apiResponse = await externalApiData.json();
|
|
80
|
+
let rawData;
|
|
81
|
+
if (exportMetadata.fields && exportMetadata.fields.length > 0) {
|
|
82
|
+
rawData = apiResponse.map((item) => {
|
|
83
|
+
return exportMetadata.fields.reduce((filtered, field) => {
|
|
84
|
+
filtered[field.name] = item[field.name];
|
|
85
|
+
return filtered;
|
|
86
|
+
}, {});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
data = {
|
|
90
|
+
apiResponse: apiResponse,
|
|
91
|
+
json: rawData || {},
|
|
92
|
+
name: exportMetadata.name,
|
|
93
|
+
createdAt: exportMetadata.createdAt,
|
|
94
|
+
updatedAt: exportMetadata.updatedAt,
|
|
95
|
+
type: exportMetadata.type,
|
|
96
|
+
apiUrl: exportMetadata.apiUrl,
|
|
97
|
+
prefix: exportMetadata.prefix,
|
|
98
|
+
collectionName: exportMetadata.collectionName,
|
|
99
|
+
fields: exportMetadata.fields,
|
|
100
|
+
description: exportMetadata?.description,
|
|
101
|
+
};
|
|
87
102
|
}
|
|
88
103
|
else {
|
|
89
104
|
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportId) });
|
|
90
|
-
data =
|
|
105
|
+
data = {
|
|
106
|
+
json: rawData?.json,
|
|
107
|
+
name: rawData?.name,
|
|
108
|
+
method: rawData?.method,
|
|
109
|
+
createdAt: rawData?.createdAt,
|
|
110
|
+
updatedAt: rawData?.updatedAt,
|
|
111
|
+
collectionName: rawData?.collectionName,
|
|
112
|
+
type: exportMetadata.type,
|
|
113
|
+
credentialId: exportMetadata.credentialId,
|
|
114
|
+
description: rawData?.description,
|
|
115
|
+
fields: exportMetadata.fields,
|
|
116
|
+
};
|
|
91
117
|
}
|
|
92
118
|
}
|
|
93
119
|
else if (project.dbType === 'sql') {
|
|
@@ -120,7 +146,7 @@ function exportRouter(config) {
|
|
|
120
146
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
121
147
|
}
|
|
122
148
|
const projectId = req.params.id;
|
|
123
|
-
const { name, description, collectionName, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
149
|
+
const { name, description, fields, collectionName, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
124
150
|
if (!name || !collectionName) {
|
|
125
151
|
return res.status(400).json({ message: 'Missing export name or collectionName' });
|
|
126
152
|
}
|
|
@@ -136,7 +162,7 @@ function exportRouter(config) {
|
|
|
136
162
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
137
163
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
138
164
|
}
|
|
139
|
-
const result = await (0, export_1.createExport)(config, projectId,
|
|
165
|
+
const result = await (0, export_1.createExport)(config, projectId, description, fields, name, jsonData, project.dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix);
|
|
140
166
|
res.status(201).json({ data: result, message: result.message });
|
|
141
167
|
}
|
|
142
168
|
catch (err) {
|
|
@@ -150,7 +176,7 @@ function exportRouter(config) {
|
|
|
150
176
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
151
177
|
}
|
|
152
178
|
const { id: projectId, export_id: exportId } = req.params;
|
|
153
|
-
const { name, collectionName, description, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
179
|
+
const { name, collectionName, description, fields, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
154
180
|
if (!name || !collectionName) {
|
|
155
181
|
return res.status(400).json({ message: 'Missing name or collectionName' });
|
|
156
182
|
}
|
|
@@ -166,7 +192,7 @@ function exportRouter(config) {
|
|
|
166
192
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
167
193
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
168
194
|
}
|
|
169
|
-
const result = await (0, export_1.updateExport)(config, projectId, exportId, name, collectionName, jsonData, project.dbType, exportType
|
|
195
|
+
const result = await (0, export_1.updateExport)(config, projectId, exportId, description, fields, name, collectionName, jsonData, project.dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix);
|
|
170
196
|
res.status(200).json({ data: result, message: result.message });
|
|
171
197
|
}
|
|
172
198
|
catch (err) {
|
|
@@ -239,7 +265,7 @@ function exportRouter(config) {
|
|
|
239
265
|
let data;
|
|
240
266
|
if (project.dbType === 'nosql') {
|
|
241
267
|
const db = connection.client.db();
|
|
242
|
-
if (exportMetadata.type === '
|
|
268
|
+
if (exportMetadata.type === 'json') {
|
|
243
269
|
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
244
270
|
data = rawData ? rawData.json : null;
|
|
245
271
|
}
|
|
@@ -261,7 +287,6 @@ function exportRouter(config) {
|
|
|
261
287
|
};
|
|
262
288
|
}
|
|
263
289
|
try {
|
|
264
|
-
const fetch = (await Promise.resolve().then(() => __importStar(require('node-fetch')))).default;
|
|
265
290
|
const response = await fetch(exportMetadata.apiUrl, { headers });
|
|
266
291
|
if (!response.ok) {
|
|
267
292
|
throw new Error(`Failed to fetch from external API: ${response.statusText}`);
|
|
@@ -271,6 +296,14 @@ function exportRouter(config) {
|
|
|
271
296
|
catch (error) {
|
|
272
297
|
throw new Error(`Error fetching from external API: ${error.message}`);
|
|
273
298
|
}
|
|
299
|
+
if (exportMetadata.fields && exportMetadata.fields.length > 0) {
|
|
300
|
+
data = data.map((item) => {
|
|
301
|
+
return exportMetadata.fields.reduce((filtered, field) => {
|
|
302
|
+
filtered[field.name] = item[field.name];
|
|
303
|
+
return filtered;
|
|
304
|
+
}, {});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
274
307
|
}
|
|
275
308
|
}
|
|
276
309
|
else if (project.dbType === 'sql') {
|
|
@@ -280,7 +313,7 @@ function exportRouter(config) {
|
|
|
280
313
|
if (!data) {
|
|
281
314
|
return res.status(404).json({ message: 'Export data not found' });
|
|
282
315
|
}
|
|
283
|
-
res.json(data);
|
|
316
|
+
res.json(data);
|
|
284
317
|
}
|
|
285
318
|
catch (err) {
|
|
286
319
|
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DatabaseType, StreamByConfig } from '../types';
|
|
1
|
+
import { FieldDefinition, DatabaseType, StreamByConfig } from '../types';
|
|
2
2
|
interface CreateExportResult {
|
|
3
3
|
exportId: string;
|
|
4
4
|
collectionName: string;
|
|
5
5
|
message: string;
|
|
6
6
|
}
|
|
7
|
-
export declare function createExport(config: StreamByConfig, projectId: string,
|
|
8
|
-
export declare function updateExport(config: StreamByConfig, projectId: string, exportId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType, exportType: '
|
|
7
|
+
export declare function createExport(config: StreamByConfig, projectId: string, description: string, fields: FieldDefinition[], exportName: string, jsonData: any, dbType: DatabaseType, exportType: 'json' | 'externalApi', isPrivate?: boolean, allowedOrigin?: string[], apiUrl?: string, credentialId?: string, prefix?: string): Promise<CreateExportResult>;
|
|
8
|
+
export declare function updateExport(config: StreamByConfig, projectId: string, exportId: string, description: string, fields: FieldDefinition[], exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType, exportType: 'json' | 'externalApi', isPrivate?: boolean, allowedOrigin?: string[], apiUrl?: string, credentialId?: string, prefix?: string): Promise<CreateExportResult>;
|
|
9
9
|
export declare function deleteExport(config: StreamByConfig, projectId: string, exportId: string, dbType: DatabaseType, collectionName: string): Promise<{
|
|
10
10
|
message: string;
|
|
11
11
|
}>;
|
package/dist/services/export.js
CHANGED
|
@@ -9,7 +9,7 @@ const connectionManager_1 = require("../adapters/database/connectionManager");
|
|
|
9
9
|
const nosql_1 = require("../adapters/database/nosql");
|
|
10
10
|
const sql_1 = require("../adapters/database/sql");
|
|
11
11
|
const encryption_1 = require("../utils/encryption");
|
|
12
|
-
async function createExport(config, projectId,
|
|
12
|
+
async function createExport(config, projectId, description, fields, exportName, jsonData, dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix) {
|
|
13
13
|
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
14
14
|
config.databases?.find(db => db.type === dbType);
|
|
15
15
|
if (!targetDb) {
|
|
@@ -57,10 +57,10 @@ async function createExport(config, projectId, exportName, collectionName, jsonD
|
|
|
57
57
|
// Update the project with the new export reference
|
|
58
58
|
// Assuming project metadata is always in NoSQL (MongoDB)
|
|
59
59
|
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
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: exportType, method: 'GET', private: isPrivate, allowedOrigin: allowedOrigin, apiUrl: apiUrl, credentialId: credentialId, prefix: prefix } } });
|
|
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: exportType, method: 'GET', private: isPrivate, allowedOrigin: allowedOrigin, apiUrl: apiUrl, credentialId: credentialId, prefix: prefix, description: description, fields: fields } } });
|
|
61
61
|
return { ...result, message: `${exportType} export created successfully` };
|
|
62
62
|
}
|
|
63
|
-
async function updateExport(config, projectId, exportId, exportName, collectionName, jsonData, dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix) {
|
|
63
|
+
async function updateExport(config, projectId, exportId, description, fields, exportName, collectionName, jsonData, dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix) {
|
|
64
64
|
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
65
65
|
config.databases?.find(db => db.type === dbType);
|
|
66
66
|
if (!targetDb) {
|
|
@@ -81,14 +81,14 @@ async function updateExport(config, projectId, exportId, exportName, collectionN
|
|
|
81
81
|
const db = connection.client.db();
|
|
82
82
|
const updateData = {
|
|
83
83
|
json: jsonData,
|
|
84
|
-
|
|
84
|
+
description: description,
|
|
85
|
+
fields: fields,
|
|
85
86
|
updatedAt: new Date(),
|
|
86
87
|
apiUrl: apiUrl,
|
|
87
88
|
credentialId: credentialId,
|
|
88
89
|
prefix: prefix,
|
|
89
90
|
};
|
|
90
91
|
await db.collection(collectionName).updateOne({ _id: new mongodb_1.ObjectId(exportId) }, { $set: updateData });
|
|
91
|
-
result = { collectionName, exportId };
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
throw new Error('Unsupported database type for externalApi export update');
|
|
@@ -98,11 +98,13 @@ async function updateExport(config, projectId, exportId, exportName, collectionN
|
|
|
98
98
|
const db = connection.client.db();
|
|
99
99
|
const updateData = {
|
|
100
100
|
json: jsonData,
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
description: description,
|
|
102
|
+
fields: fields,
|
|
103
|
+
apiUrl: apiUrl,
|
|
104
|
+
credentialId: credentialId,
|
|
105
|
+
prefix: prefix,
|
|
103
106
|
};
|
|
104
107
|
await db.collection(collectionName).updateOne({ _id: new mongodb_1.ObjectId(exportId) }, { $set: updateData });
|
|
105
|
-
result = { collectionName, exportId };
|
|
106
108
|
}
|
|
107
109
|
else {
|
|
108
110
|
throw new Error('Unsupported database type for update');
|
|
@@ -111,7 +113,8 @@ async function updateExport(config, projectId, exportId, exportName, collectionN
|
|
|
111
113
|
await NoSQLProject.update({
|
|
112
114
|
_id: new mongodb_1.ObjectId(projectId),
|
|
113
115
|
'exports.id': { $in: [new mongodb_1.ObjectId(exportId), exportId] }
|
|
114
|
-
}, { $set: { 'exports.$.name': exportName, 'exports.$.collectionName': collectionName, 'exports.$.private': isPrivate, 'exports.$.allowedOrigin': allowedOrigin, 'exports.$.apiUrl': apiUrl, 'exports.$.credentialId': credentialId, 'exports.$.prefix': prefix } });
|
|
116
|
+
}, { $set: { 'exports.$.name': exportName, 'exports.$.collectionName': collectionName, 'exports.$.private': isPrivate, 'exports.$.allowedOrigin': allowedOrigin, 'exports.$.apiUrl': apiUrl, 'exports.$.credentialId': credentialId, 'exports.$.prefix': prefix, 'exports.$.description': description, 'exports.$.fields': fields } });
|
|
117
|
+
result = { collectionName, exportId };
|
|
115
118
|
return { ...result, message: `${exportType} export updated successfully` };
|
|
116
119
|
}
|
|
117
120
|
async function deleteExport(config, projectId, exportId, dbType, collectionName) {
|
package/dist/types/index.d.ts
CHANGED