streamby-core 0.27.1 → 0.27.3
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.
|
@@ -267,7 +267,7 @@ function exportRouter(config) {
|
|
|
267
267
|
if (!project) {
|
|
268
268
|
return res.status(404).json({ message: 'Project not found' });
|
|
269
269
|
}
|
|
270
|
-
const exportMetadata = project.exports
|
|
270
|
+
const exportMetadata = project.exports?.find((e) => e.name?.toLowerCase().trim() === exportName.toLowerCase().trim());
|
|
271
271
|
if (!exportMetadata) {
|
|
272
272
|
return res.status(404).json({ message: 'Export not found in this project' });
|
|
273
273
|
}
|
|
@@ -318,64 +318,62 @@ function exportRouter(config) {
|
|
|
318
318
|
let data;
|
|
319
319
|
if (exportMetadata.nodeSchema) {
|
|
320
320
|
data = await (0, pipeline_1.executePipeline)(exportMetadata.nodeSchema, project, config);
|
|
321
|
+
return res.json(data ?? null);
|
|
321
322
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
// Legacy path: raw JSON or external API export
|
|
324
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
325
|
+
if (!targetDb) {
|
|
326
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
327
|
+
}
|
|
328
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
329
|
+
if (project.dbType === 'nosql') {
|
|
330
|
+
const db = connection.client.db();
|
|
331
|
+
const legacyCollection = exportMetadata.collectionName ?? projectId;
|
|
332
|
+
if (exportMetadata.type === 'json') {
|
|
333
|
+
const rawData = await db.collection(legacyCollection).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id.toString()) });
|
|
334
|
+
data = rawData ? rawData.json : null;
|
|
326
335
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
data = rawData ? rawData.json : null;
|
|
333
|
-
}
|
|
334
|
-
else if (exportMetadata.type === 'externalApi') {
|
|
335
|
-
let headers = {};
|
|
336
|
-
if (exportMetadata.credentialId) {
|
|
337
|
-
if (!(0, encryption_1.isEncryptionKeySet)()) {
|
|
338
|
-
throw new Error('Encryption key is not set. Cannot use encrypted credentials.');
|
|
339
|
-
}
|
|
340
|
-
const credential = project.credentials?.find((cred) => cred.id === exportMetadata.credentialId);
|
|
341
|
-
if (!credential) {
|
|
342
|
-
throw new Error(`Credential with ID ${exportMetadata.credentialId} not found.`);
|
|
343
|
-
}
|
|
344
|
-
const decryptedValue = (0, encryption_1.decrypt)(credential.encryptedValue);
|
|
345
|
-
const authPrefix = exportMetadata.prefix ? `${exportMetadata.prefix} ` : '';
|
|
346
|
-
headers = {
|
|
347
|
-
'Authorization': `${authPrefix}${decryptedValue}`,
|
|
348
|
-
'Content-Type': 'application/json',
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
try {
|
|
352
|
-
const response = await fetch(exportMetadata.apiUrl, { headers });
|
|
353
|
-
if (!response.ok) {
|
|
354
|
-
throw new Error(`Failed to fetch from external API: ${response.statusText}`);
|
|
355
|
-
}
|
|
356
|
-
data = await response.json();
|
|
336
|
+
else if (exportMetadata.type === 'externalApi') {
|
|
337
|
+
let headers = {};
|
|
338
|
+
if (exportMetadata.credentialId) {
|
|
339
|
+
if (!(0, encryption_1.isEncryptionKeySet)()) {
|
|
340
|
+
throw new Error('Encryption key is not set. Cannot use encrypted credentials.');
|
|
357
341
|
}
|
|
358
|
-
|
|
359
|
-
|
|
342
|
+
const credential = project.credentials?.find((cred) => cred.id === exportMetadata.credentialId);
|
|
343
|
+
if (!credential) {
|
|
344
|
+
throw new Error(`Credential with ID ${exportMetadata.credentialId} not found.`);
|
|
360
345
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
346
|
+
const decryptedValue = (0, encryption_1.decrypt)(credential.encryptedValue);
|
|
347
|
+
const authPrefix = exportMetadata.prefix ? `${exportMetadata.prefix} ` : '';
|
|
348
|
+
headers = {
|
|
349
|
+
'Authorization': `${authPrefix}${decryptedValue}`,
|
|
350
|
+
'Content-Type': 'application/json',
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
const response = await fetch(exportMetadata.apiUrl, { headers });
|
|
355
|
+
if (!response.ok) {
|
|
356
|
+
throw new Error(`Failed to fetch from external API: ${response.statusText}`);
|
|
368
357
|
}
|
|
358
|
+
data = await response.json();
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
throw new Error(`Error fetching from external API: ${error.message}`);
|
|
362
|
+
}
|
|
363
|
+
if (exportMetadata.fields && exportMetadata.fields.length > 0) {
|
|
364
|
+
data = data.map((item) => {
|
|
365
|
+
return exportMetadata.fields.reduce((filtered, field) => {
|
|
366
|
+
filtered[field.name] = item[field.name];
|
|
367
|
+
return filtered;
|
|
368
|
+
}, {});
|
|
369
|
+
});
|
|
369
370
|
}
|
|
370
371
|
}
|
|
371
|
-
else if (project.dbType === 'sql') {
|
|
372
|
-
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
373
|
-
}
|
|
374
|
-
} // end legacy else block
|
|
375
|
-
if (!data) {
|
|
376
|
-
return res.status(404).json({ message: 'Export data not found' });
|
|
377
372
|
}
|
|
378
|
-
|
|
373
|
+
else if (project.dbType === 'sql') {
|
|
374
|
+
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
375
|
+
}
|
|
376
|
+
res.json(data ?? null);
|
|
379
377
|
}
|
|
380
378
|
catch (err) {
|
|
381
379
|
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
package/dist/services/export.js
CHANGED
|
@@ -19,9 +19,11 @@ async function createExport(config, projectId, description, exportName, dbType,
|
|
|
19
19
|
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
20
20
|
const resolvedDbType = targetDb.type;
|
|
21
21
|
let exportId;
|
|
22
|
+
let collectionName;
|
|
22
23
|
if (resolvedDbType === 'nosql') {
|
|
23
24
|
const result = await (0, nosql_1.createNoSQLRawExportCollection)(connection.client, projectId, exportName, 'GET', nodeSchema);
|
|
24
25
|
exportId = result.exportId;
|
|
26
|
+
collectionName = result.collectionName;
|
|
25
27
|
}
|
|
26
28
|
else if (resolvedDbType === 'sql') {
|
|
27
29
|
const result = await (0, sql_1.createSQLRawExportTable)(connection.client, projectId, exportName, nodeSchema);
|
|
@@ -46,9 +48,13 @@ async function createExport(config, projectId, description, exportName, dbType,
|
|
|
46
48
|
useCredentials,
|
|
47
49
|
description,
|
|
48
50
|
storageDbId: targetDb.id,
|
|
51
|
+
collectionName,
|
|
49
52
|
};
|
|
50
53
|
const ProjectModel = isSqlProject ? (0, manager_1.getModel)('projects', 'sql') : (0, manager_1.getModel)('projects', 'nosql');
|
|
51
|
-
await ProjectModel.update({ _id: projectId }, { $push: { exports: exportEntry } });
|
|
54
|
+
const updated = await ProjectModel.update({ _id: projectId }, { $push: { exports: exportEntry } });
|
|
55
|
+
if (!updated) {
|
|
56
|
+
throw new Error(`Failed to save export entry to project ${projectId}. The project may not exist or the database update failed.`);
|
|
57
|
+
}
|
|
52
58
|
return { exportId, message: `${exportType} export created successfully` };
|
|
53
59
|
}
|
|
54
60
|
async function updateExport(config, projectId, exportId, description, exportName, dbType, exportType, isPrivate, allowedOrigin, devMode, devPorts, nodeSchema, useConnections, useCredentials) {
|