streamby-core 0.24.14 → 0.24.16
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,18 @@ 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
|
+
description: rawData?.description,
|
|
54
|
+
};
|
|
79
55
|
}
|
|
80
56
|
else if (exportMetadata.type === 'externalApi') {
|
|
81
57
|
const ProjectModel = (0, manager_1.getModel)('projects', 'nosql');
|
|
@@ -83,11 +59,48 @@ function exportRouter(config) {
|
|
|
83
59
|
if (!currentProject) {
|
|
84
60
|
return res.status(404).json({ message: 'Project not found.' });
|
|
85
61
|
}
|
|
86
|
-
|
|
62
|
+
let headers = {};
|
|
63
|
+
if (exportMetadata.credentialId) {
|
|
64
|
+
if (!(0, encryption_1.isEncryptionKeySet)()) {
|
|
65
|
+
throw new Error('Encryption key is not set. Cannot use encrypted credentials.');
|
|
66
|
+
}
|
|
67
|
+
const credential = project.credentials?.find((cred) => cred.id === exportMetadata.credentialId);
|
|
68
|
+
if (credential) {
|
|
69
|
+
const decryptedValue = (0, encryption_1.decrypt)(credential.encryptedValue);
|
|
70
|
+
const authPrefix = exportMetadata.prefix ? `${exportMetadata.prefix} ` : '';
|
|
71
|
+
headers = {
|
|
72
|
+
'Authorization': `${authPrefix}${decryptedValue}`,
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const externalApiData = await fetch(exportMetadata.apiUrl, { headers });
|
|
78
|
+
const rawData = await externalApiData.json();
|
|
79
|
+
data = {
|
|
80
|
+
json: rawData || {},
|
|
81
|
+
name: exportMetadata.name,
|
|
82
|
+
createdAt: exportMetadata.createdAt,
|
|
83
|
+
updatedAt: exportMetadata.updatedAt,
|
|
84
|
+
type: exportMetadata.type,
|
|
85
|
+
apiUrl: exportMetadata.apiUrl,
|
|
86
|
+
prefix: exportMetadata.prefix,
|
|
87
|
+
collectionName: exportMetadata.collectionName,
|
|
88
|
+
description: exportMetadata?.description,
|
|
89
|
+
};
|
|
87
90
|
}
|
|
88
91
|
else {
|
|
89
92
|
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportId) });
|
|
90
|
-
data =
|
|
93
|
+
data = {
|
|
94
|
+
json: rawData?.json,
|
|
95
|
+
name: rawData?.name,
|
|
96
|
+
method: rawData?.method,
|
|
97
|
+
createdAt: rawData?.createdAt,
|
|
98
|
+
updatedAt: rawData?.updatedAt,
|
|
99
|
+
collectionName: rawData?.collectionName,
|
|
100
|
+
type: exportMetadata.type,
|
|
101
|
+
credentialId: exportMetadata.credentialId,
|
|
102
|
+
description: rawData?.description,
|
|
103
|
+
};
|
|
91
104
|
}
|
|
92
105
|
}
|
|
93
106
|
else if (project.dbType === 'sql') {
|
|
@@ -120,7 +133,7 @@ function exportRouter(config) {
|
|
|
120
133
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
121
134
|
}
|
|
122
135
|
const projectId = req.params.id;
|
|
123
|
-
const { name, description, collectionName, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
136
|
+
const { name, description, fields, collectionName, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
124
137
|
if (!name || !collectionName) {
|
|
125
138
|
return res.status(400).json({ message: 'Missing export name or collectionName' });
|
|
126
139
|
}
|
|
@@ -136,7 +149,7 @@ function exportRouter(config) {
|
|
|
136
149
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
137
150
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
138
151
|
}
|
|
139
|
-
const result = await (0, export_1.createExport)(config, projectId,
|
|
152
|
+
const result = await (0, export_1.createExport)(config, projectId, description, fields, name, jsonData, project.dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix);
|
|
140
153
|
res.status(201).json({ data: result, message: result.message });
|
|
141
154
|
}
|
|
142
155
|
catch (err) {
|
|
@@ -150,7 +163,7 @@ function exportRouter(config) {
|
|
|
150
163
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
151
164
|
}
|
|
152
165
|
const { id: projectId, export_id: exportId } = req.params;
|
|
153
|
-
const { name, collectionName, description, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
166
|
+
const { name, collectionName, description, fields, jsonData, isPrivate, allowedOrigin, exportType, apiUrl, credentialId, prefix } = req.body;
|
|
154
167
|
if (!name || !collectionName) {
|
|
155
168
|
return res.status(400).json({ message: 'Missing name or collectionName' });
|
|
156
169
|
}
|
|
@@ -166,7 +179,7 @@ function exportRouter(config) {
|
|
|
166
179
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
167
180
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
168
181
|
}
|
|
169
|
-
const result = await (0, export_1.updateExport)(config, projectId, exportId, name, collectionName, jsonData, project.dbType, exportType
|
|
182
|
+
const result = await (0, export_1.updateExport)(config, projectId, exportId, description, fields, name, collectionName, jsonData, project.dbType, exportType, isPrivate, allowedOrigin, apiUrl, credentialId, prefix);
|
|
170
183
|
res.status(200).json({ data: result, message: result.message });
|
|
171
184
|
}
|
|
172
185
|
catch (err) {
|
|
@@ -239,7 +252,7 @@ function exportRouter(config) {
|
|
|
239
252
|
let data;
|
|
240
253
|
if (project.dbType === 'nosql') {
|
|
241
254
|
const db = connection.client.db();
|
|
242
|
-
if (exportMetadata.type === '
|
|
255
|
+
if (exportMetadata.type === 'json') {
|
|
243
256
|
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
244
257
|
data = rawData ? rawData.json : null;
|
|
245
258
|
}
|
|
@@ -261,7 +274,6 @@ function exportRouter(config) {
|
|
|
261
274
|
};
|
|
262
275
|
}
|
|
263
276
|
try {
|
|
264
|
-
const fetch = (await Promise.resolve().then(() => __importStar(require('node-fetch')))).default;
|
|
265
277
|
const response = await fetch(exportMetadata.apiUrl, { headers });
|
|
266
278
|
if (!response.ok) {
|
|
267
279
|
throw new Error(`Failed to fetch from external API: ${response.statusText}`);
|
|
@@ -271,6 +283,14 @@ function exportRouter(config) {
|
|
|
271
283
|
catch (error) {
|
|
272
284
|
throw new Error(`Error fetching from external API: ${error.message}`);
|
|
273
285
|
}
|
|
286
|
+
if (exportMetadata.fields && exportMetadata.fields.length > 0) {
|
|
287
|
+
data = data.map((item) => {
|
|
288
|
+
return exportMetadata.fields.reduce((filtered, field) => {
|
|
289
|
+
filtered[field.name] = item[field.name];
|
|
290
|
+
return filtered;
|
|
291
|
+
}, {});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
274
294
|
}
|
|
275
295
|
}
|
|
276
296
|
else if (project.dbType === 'sql') {
|
|
@@ -280,7 +300,7 @@ function exportRouter(config) {
|
|
|
280
300
|
if (!data) {
|
|
281
301
|
return res.status(404).json({ message: 'Export data not found' });
|
|
282
302
|
}
|
|
283
|
-
res.json(data);
|
|
303
|
+
res.json(data);
|
|
284
304
|
}
|
|
285
305
|
catch (err) {
|
|
286
306
|
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