n8n-nodes-databar 0.2.0 → 0.2.1
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.
|
@@ -40,15 +40,16 @@ const n8n_workflow_1 = require("n8n-workflow");
|
|
|
40
40
|
* @throws NodeOperationError if task fails or times out
|
|
41
41
|
*/
|
|
42
42
|
async function pollTaskStatus(context, taskId, pollInterval, timeout) {
|
|
43
|
+
if (!taskId) {
|
|
44
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'No task ID returned by the API. The request may have failed — check that your parameters are correct and you have enough credits.');
|
|
45
|
+
}
|
|
43
46
|
const startTime = Date.now();
|
|
44
47
|
const pollIntervalMs = pollInterval * 1000;
|
|
45
48
|
const timeoutMs = timeout * 1000;
|
|
46
49
|
while (true) {
|
|
47
|
-
// Check if we've exceeded the timeout
|
|
48
50
|
if (Date.now() - startTime > timeoutMs) {
|
|
49
|
-
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Task ${taskId} timed out after ${timeout} seconds
|
|
51
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Task ${taskId} timed out after ${timeout} seconds. You can increase the timeout in Additional Options.`);
|
|
50
52
|
}
|
|
51
|
-
// Check task status
|
|
52
53
|
const response = await context.helpers.httpRequestWithAuthentication.call(context, 'databarApi', {
|
|
53
54
|
method: 'GET',
|
|
54
55
|
url: `https://api.databar.ai/v1/tasks/${taskId}`,
|
|
@@ -62,7 +63,9 @@ async function pollTaskStatus(context, taskId, pollInterval, timeout) {
|
|
|
62
63
|
const error = taskData.error || 'Task failed without error message';
|
|
63
64
|
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Task ${taskId} failed: ${error}`);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
if (status === 'gone') {
|
|
67
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Task ${taskId} data has expired. Results are only available for 1 hour after completion.`);
|
|
68
|
+
}
|
|
66
69
|
await (0, n8n_workflow_1.sleep)(pollIntervalMs);
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -141,9 +144,31 @@ class Databar {
|
|
|
141
144
|
description: 'Get information about your current account',
|
|
142
145
|
action: 'Get account info',
|
|
143
146
|
},
|
|
147
|
+
{
|
|
148
|
+
name: 'Get Task',
|
|
149
|
+
value: 'getTask',
|
|
150
|
+
description: 'Retrieve the status and results of a previously run enrichment or waterfall task',
|
|
151
|
+
action: 'Get task result',
|
|
152
|
+
},
|
|
144
153
|
],
|
|
145
154
|
default: 'getMe',
|
|
146
155
|
},
|
|
156
|
+
// Other: Get Task - Task ID
|
|
157
|
+
{
|
|
158
|
+
displayName: 'Task ID',
|
|
159
|
+
name: 'taskId',
|
|
160
|
+
type: 'string',
|
|
161
|
+
displayOptions: {
|
|
162
|
+
show: {
|
|
163
|
+
resource: ['user'],
|
|
164
|
+
operation: ['getTask'],
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
default: '',
|
|
168
|
+
required: true,
|
|
169
|
+
placeholder: 'e.g. 123e4567-e89b-12d3-a456-426614174000',
|
|
170
|
+
description: 'The task ID returned when you ran an enrichment or waterfall with "Wait for Completion" turned off. Results are only stored for 1 hour.',
|
|
171
|
+
},
|
|
147
172
|
// ====================================
|
|
148
173
|
// ENRICHMENT OPERATIONS
|
|
149
174
|
// ====================================
|
|
@@ -1229,6 +1254,20 @@ class Databar {
|
|
|
1229
1254
|
pairedItem: { item: i },
|
|
1230
1255
|
});
|
|
1231
1256
|
}
|
|
1257
|
+
else if (operation === 'getTask') {
|
|
1258
|
+
const taskId = this.getNodeParameter('taskId', i);
|
|
1259
|
+
if (!taskId) {
|
|
1260
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Please provide a task ID', { itemIndex: i });
|
|
1261
|
+
}
|
|
1262
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'databarApi', {
|
|
1263
|
+
method: 'GET',
|
|
1264
|
+
url: `https://api.databar.ai/v1/tasks/${taskId}`,
|
|
1265
|
+
});
|
|
1266
|
+
returnData.push({
|
|
1267
|
+
json: response,
|
|
1268
|
+
pairedItem: { item: i },
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1232
1271
|
}
|
|
1233
1272
|
// ====================================
|
|
1234
1273
|
// ENRICHMENT OPERATIONS
|
|
@@ -1243,18 +1282,27 @@ class Databar {
|
|
|
1243
1282
|
const waitForCompletion = this.getNodeParameter('waitForCompletion', i, true);
|
|
1244
1283
|
const paramsFields = this.getNodeParameter('paramsFields', i);
|
|
1245
1284
|
const params = paramsFields.value || {};
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1285
|
+
let taskResponse;
|
|
1286
|
+
try {
|
|
1287
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'databarApi', {
|
|
1288
|
+
method: 'POST',
|
|
1289
|
+
url: `https://api.databar.ai/v1/enrichments/${enrichmentId}/run`,
|
|
1290
|
+
body: { params },
|
|
1291
|
+
});
|
|
1292
|
+
taskResponse = response;
|
|
1293
|
+
}
|
|
1294
|
+
catch (error) {
|
|
1295
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1296
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to start enrichment: ${msg}`, { itemIndex: i });
|
|
1297
|
+
}
|
|
1298
|
+
if (taskResponse.detail) {
|
|
1299
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Enrichment API error: ${JSON.stringify(taskResponse.detail)}`, { itemIndex: i });
|
|
1300
|
+
}
|
|
1252
1301
|
if (waitForCompletion) {
|
|
1253
1302
|
const additionalOptions = this.getNodeParameter('additionalOptions', i, {});
|
|
1254
1303
|
const pollInterval = additionalOptions.pollInterval || 3;
|
|
1255
1304
|
const timeout = additionalOptions.timeout || 300;
|
|
1256
1305
|
const taskId = taskResponse.task_id;
|
|
1257
|
-
// Poll for completion
|
|
1258
1306
|
const completedTask = await pollTaskStatus(this, taskId, pollInterval, timeout);
|
|
1259
1307
|
returnData.push({
|
|
1260
1308
|
json: completedTask,
|