streamby-core 0.26.0 → 0.26.2
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.
- package/dist/adapters/database/nosql.d.ts +1 -1
- package/dist/adapters/database/nosql.js +2 -4
- package/dist/adapters/database/sql.d.ts +1 -1
- package/dist/adapters/database/sql.js +2 -3
- package/dist/middleware/routes/connection.js +5 -5
- package/dist/middleware/routes/export.js +1 -1
- package/dist/services/apiConnection.d.ts +1 -1
- package/dist/services/apiConnection.js +1 -1
- package/dist/services/export.d.ts +1 -1
- package/dist/services/export.js +5 -7
- package/dist/services/pipeline.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ export declare const createNoSQLExportCollection: (connection: MongoClient, proj
|
|
|
5
5
|
collectionName: string;
|
|
6
6
|
exportId: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare const createNoSQLRawExportCollection: (connection: MongoClient, exportName: string, method: string, nodeSchema?: NodeSchema) => Promise<{
|
|
8
|
+
export declare const createNoSQLRawExportCollection: (connection: MongoClient, projectId: string, exportName: string, method: string, nodeSchema?: NodeSchema) => Promise<{
|
|
9
9
|
collectionName: string;
|
|
10
10
|
exportId: string;
|
|
11
11
|
}>;
|
|
@@ -33,12 +33,10 @@ const createNoSQLExportCollection = async (connection, projectId, exportName, fi
|
|
|
33
33
|
return { collectionName, exportId: collectionName };
|
|
34
34
|
};
|
|
35
35
|
exports.createNoSQLExportCollection = createNoSQLExportCollection;
|
|
36
|
-
const createNoSQLRawExportCollection = async (connection, exportName, method, nodeSchema) => {
|
|
36
|
+
const createNoSQLRawExportCollection = async (connection, projectId, exportName, method, nodeSchema) => {
|
|
37
37
|
const db = connection.db();
|
|
38
|
-
const
|
|
39
|
-
const collectionName = slug;
|
|
38
|
+
const collectionName = projectId;
|
|
40
39
|
const result = await db.collection(collectionName).insertOne({ nodeSchema, name: exportName, method, createdAt: new Date(), updatedAt: new Date() });
|
|
41
|
-
console.log(`✅ Raw collection '${collectionName}' created.`);
|
|
42
40
|
return { collectionName, exportId: result.insertedId.toHexString() };
|
|
43
41
|
};
|
|
44
42
|
exports.createNoSQLRawExportCollection = createNoSQLRawExportCollection;
|
|
@@ -4,7 +4,7 @@ export declare const createSQLExportTable: (connection: Pool, projectId: string,
|
|
|
4
4
|
collectionName: string;
|
|
5
5
|
exportId: string;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const createSQLRawExportTable: (connection: Pool, exportName: string, nodeSchema?: any) => Promise<{
|
|
7
|
+
export declare const createSQLRawExportTable: (connection: Pool, projectId: string, exportName: string, nodeSchema?: any) => Promise<{
|
|
8
8
|
collectionName: string;
|
|
9
9
|
exportId: string;
|
|
10
10
|
}>;
|
|
@@ -27,9 +27,8 @@ const createSQLExportTable = async (connection, projectId, exportName, fields) =
|
|
|
27
27
|
return { collectionName: tableName, exportId: tableName };
|
|
28
28
|
};
|
|
29
29
|
exports.createSQLExportTable = createSQLExportTable;
|
|
30
|
-
const createSQLRawExportTable = async (connection, exportName, nodeSchema) => {
|
|
31
|
-
const
|
|
32
|
-
const tableName = slug;
|
|
30
|
+
const createSQLRawExportTable = async (connection, projectId, exportName, nodeSchema) => {
|
|
31
|
+
const tableName = projectId;
|
|
33
32
|
const exportId = (0, crypto_1.randomUUID)();
|
|
34
33
|
const createTableQuery = `
|
|
35
34
|
CREATE TABLE IF NOT EXISTS "${tableName}" (
|
|
@@ -68,9 +68,9 @@ function apiConnectionRouter(config) {
|
|
|
68
68
|
return res.status(403).json({ message: 'Permission denied' });
|
|
69
69
|
}
|
|
70
70
|
const projectId = req.params.id;
|
|
71
|
-
const { name,
|
|
72
|
-
if (!name || !
|
|
73
|
-
return res.status(400).json({ message: 'name and
|
|
71
|
+
const { name, apiUrl, method, description, credentialId, prefix } = req.body;
|
|
72
|
+
if (!name || !apiUrl) {
|
|
73
|
+
return res.status(400).json({ message: 'name and apiUrl are required' });
|
|
74
74
|
}
|
|
75
75
|
if (!VALID_METHODS.includes(method)) {
|
|
76
76
|
return res.status(400).json({ message: `method must be one of: ${VALID_METHODS.join(', ')}` });
|
|
@@ -90,7 +90,7 @@ function apiConnectionRouter(config) {
|
|
|
90
90
|
}
|
|
91
91
|
const connection = await (0, apiConnection_1.addApiConnection)(config, projectId, {
|
|
92
92
|
name,
|
|
93
|
-
|
|
93
|
+
apiUrl,
|
|
94
94
|
method,
|
|
95
95
|
prefix,
|
|
96
96
|
...(description !== undefined && { description }),
|
|
@@ -132,7 +132,7 @@ function apiConnectionRouter(config) {
|
|
|
132
132
|
const prefix = apiConnection.prefix ? `${apiConnection.prefix} ` : '';
|
|
133
133
|
headers['Authorization'] = `${prefix}${decrypted}`;
|
|
134
134
|
}
|
|
135
|
-
const response = await fetch(apiConnection.
|
|
135
|
+
const response = await fetch(apiConnection.apiUrl, { method: apiConnection.method || 'GET', headers });
|
|
136
136
|
if (!response.ok) {
|
|
137
137
|
return res.status(response.status).json({ message: `External API error: ${response.statusText}` });
|
|
138
138
|
}
|
|
@@ -200,7 +200,7 @@ function exportRouter(config) {
|
|
|
200
200
|
if (!exportMetadata) {
|
|
201
201
|
return res.status(404).json({ message: 'Export not found' });
|
|
202
202
|
}
|
|
203
|
-
const result = await (0, export_1.updateExport)(config, projectId, exportId, description, name,
|
|
203
|
+
const result = await (0, export_1.updateExport)(config, projectId, exportId, description, name, project.dbType, exportType, isPrivate, allowedOrigin, nodeSchema, useConnections, useCredentials);
|
|
204
204
|
res.status(200).json({ data: result, message: result.message });
|
|
205
205
|
}
|
|
206
206
|
catch (err) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StreamByConfig, ApiConnection, ApiConnectionMethod } from '../types';
|
|
2
2
|
export declare function addApiConnection(config: StreamByConfig, projectId: string, data: {
|
|
3
3
|
name: string;
|
|
4
|
-
|
|
4
|
+
apiUrl: string;
|
|
5
5
|
method: ApiConnectionMethod;
|
|
6
6
|
prefix?: string;
|
|
7
7
|
description?: string;
|
|
@@ -14,7 +14,7 @@ async function addApiConnection(config, projectId, data) {
|
|
|
14
14
|
id: new mongodb_1.ObjectId().toHexString(),
|
|
15
15
|
name: data.name,
|
|
16
16
|
prefix: data.prefix,
|
|
17
|
-
|
|
17
|
+
apiUrl: data.apiUrl,
|
|
18
18
|
method: data.method,
|
|
19
19
|
projectId,
|
|
20
20
|
createdAt: new Date(),
|
|
@@ -4,7 +4,7 @@ interface ExportResult {
|
|
|
4
4
|
message: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function createExport(config: StreamByConfig, projectId: string, description: string, exportName: string, dbType: DatabaseType, exportType: 'json' | 'externalApi', isPrivate?: boolean, allowedOrigin?: string[], nodeSchema?: NodeSchema, useConnections?: boolean, useCredentials?: boolean): Promise<ExportResult>;
|
|
7
|
-
export declare function updateExport(config: StreamByConfig, projectId: string, exportId: string, description: string, exportName: string,
|
|
7
|
+
export declare function updateExport(config: StreamByConfig, projectId: string, exportId: string, description: string, exportName: string, dbType: DatabaseType, exportType: 'json' | 'externalApi', isPrivate?: boolean, allowedOrigin?: string[], nodeSchema?: NodeSchema, useConnections?: boolean, useCredentials?: boolean): Promise<ExportResult>;
|
|
8
8
|
export declare function deleteExport(config: StreamByConfig, projectId: string, exportId: string, dbType: DatabaseType, exportName: string): Promise<{
|
|
9
9
|
message: string;
|
|
10
10
|
}>;
|
package/dist/services/export.js
CHANGED
|
@@ -17,11 +17,11 @@ async function createExport(config, projectId, description, exportName, dbType,
|
|
|
17
17
|
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
18
18
|
let exportId;
|
|
19
19
|
if (dbType === 'nosql') {
|
|
20
|
-
const result = await (0, nosql_1.createNoSQLRawExportCollection)(connection.client, exportName, 'GET', nodeSchema);
|
|
20
|
+
const result = await (0, nosql_1.createNoSQLRawExportCollection)(connection.client, projectId, exportName, 'GET', nodeSchema);
|
|
21
21
|
exportId = result.exportId;
|
|
22
22
|
}
|
|
23
23
|
else if (dbType === 'sql') {
|
|
24
|
-
const result = await (0, sql_1.createSQLRawExportTable)(connection.client, exportName, nodeSchema);
|
|
24
|
+
const result = await (0, sql_1.createSQLRawExportTable)(connection.client, projectId, exportName, nodeSchema);
|
|
25
25
|
exportId = result.exportId;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
@@ -31,17 +31,16 @@ async function createExport(config, projectId, description, exportName, dbType,
|
|
|
31
31
|
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: new mongodb_1.ObjectId(exportId), name: exportName, type: exportType, method: 'GET', private: isPrivate, allowedOrigin, nodeSchema, useConnections, useCredentials, description } } });
|
|
32
32
|
return { exportId, message: `${exportType} export created successfully` };
|
|
33
33
|
}
|
|
34
|
-
async function updateExport(config, projectId, exportId, description, exportName,
|
|
34
|
+
async function updateExport(config, projectId, exportId, description, exportName, dbType, exportType, isPrivate, allowedOrigin, nodeSchema, useConnections, useCredentials) {
|
|
35
35
|
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
36
36
|
config.databases?.find(db => db.type === dbType);
|
|
37
37
|
if (!targetDb) {
|
|
38
38
|
throw new Error(`Database connection not found for type ${dbType}`);
|
|
39
39
|
}
|
|
40
40
|
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
41
|
-
const storedSlug = storedExportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
42
41
|
if (dbType === 'nosql') {
|
|
43
42
|
const db = connection.client.db();
|
|
44
|
-
await db.collection(
|
|
43
|
+
await db.collection(projectId).updateOne({ _id: new mongodb_1.ObjectId(exportId) }, { $set: { nodeSchema, description, updatedAt: new Date() } });
|
|
45
44
|
}
|
|
46
45
|
else {
|
|
47
46
|
throw new Error('Unsupported database type for update');
|
|
@@ -60,10 +59,9 @@ async function deleteExport(config, projectId, exportId, dbType, exportName) {
|
|
|
60
59
|
throw new Error(`Database connection not found for type ${dbType}`);
|
|
61
60
|
}
|
|
62
61
|
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
63
|
-
const slug = exportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
64
62
|
if (dbType === 'nosql') {
|
|
65
63
|
const db = connection.client.db();
|
|
66
|
-
await db.collection(
|
|
64
|
+
await db.collection(projectId).deleteOne({ _id: new mongodb_1.ObjectId(exportId) });
|
|
67
65
|
}
|
|
68
66
|
else {
|
|
69
67
|
throw new Error('Unsupported database type for delete');
|
|
@@ -53,7 +53,7 @@ async function executePipeline(nodeSchema, project, config) {
|
|
|
53
53
|
headers['Authorization'] = `${prefix}${decrypted}`;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const response = await fetch(apiConnection.
|
|
56
|
+
const response = await fetch(apiConnection.apiUrl, { method: apiConnection.method || 'GET', headers });
|
|
57
57
|
if (!response.ok)
|
|
58
58
|
throw new Error(`API connection fetch failed: ${response.statusText}`);
|
|
59
59
|
dataResults.push(await response.json());
|
package/dist/types/index.d.ts
CHANGED