n8n-nodes-base 0.220.2 → 0.222.0
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/build.tsbuildinfo +1 -1
- package/dist/credentials/Postgres.credentials.js +115 -0
- package/dist/credentials/Postgres.credentials.js.map +1 -1
- package/dist/credentials/SshPrivateKey.credentials.js +1 -0
- package/dist/credentials/SshPrivateKey.credentials.js.map +1 -1
- package/dist/credentials/TotpApi.credentials.d.ts +7 -0
- package/dist/credentials/TotpApi.credentials.js +33 -0
- package/dist/credentials/TotpApi.credentials.js.map +1 -0
- package/dist/known/credentials.json +8 -0
- package/dist/known/nodes.json +4 -0
- package/dist/nodes/ActionNetwork/GenericFunctions.d.ts +1 -1
- package/dist/nodes/Autopilot/GenericFunctions.js +2 -1
- package/dist/nodes/Autopilot/GenericFunctions.js.map +1 -1
- package/dist/nodes/Aws/Rekognition/GenericFunctions.js +2 -1
- package/dist/nodes/Aws/Rekognition/GenericFunctions.js.map +1 -1
- package/dist/nodes/Aws/S3/FileDescription.js +1 -1
- package/dist/nodes/Aws/S3/FileDescription.js.map +1 -1
- package/dist/nodes/Aws/S3/GenericFunctions.js +2 -1
- package/dist/nodes/Aws/S3/GenericFunctions.js.map +1 -1
- package/dist/nodes/ClickUp/GenericFunctions.js +2 -1
- package/dist/nodes/ClickUp/GenericFunctions.js.map +1 -1
- package/dist/nodes/Clockify/GenericFunctions.js +2 -1
- package/dist/nodes/Clockify/GenericFunctions.js.map +1 -1
- package/dist/nodes/CompareDatasets/CompareDatasets.node.js +42 -6
- package/dist/nodes/CompareDatasets/CompareDatasets.node.js.map +1 -1
- package/dist/nodes/CompareDatasets/GenericFunctions.js +60 -18
- package/dist/nodes/CompareDatasets/GenericFunctions.js.map +1 -1
- package/dist/nodes/CompareDatasets/test/node/workflow.compareDatasets.fuzzy.missing_keys.json +232 -0
- package/dist/nodes/CompareDatasets/test/node/workflow.compareDatasets.skipFields.json +897 -0
- package/dist/nodes/CrateDb/CrateDb.node.js +7 -7
- package/dist/nodes/CrateDb/CrateDb.node.js.map +1 -1
- package/dist/nodes/DateTime/DateTime.node.js +11 -1
- package/dist/nodes/DateTime/DateTime.node.js.map +1 -1
- package/dist/nodes/DateTime/test/node/workflow.luxonDateTime.json +165 -0
- package/dist/nodes/Filter/Filter.node.js +12 -5
- package/dist/nodes/Filter/Filter.node.js.map +1 -1
- package/dist/nodes/Github/SearchFunctions.js +1 -1
- package/dist/nodes/Github/SearchFunctions.js.map +1 -1
- package/dist/nodes/GoToWebinar/GenericFunctions.d.ts +1 -1
- package/dist/nodes/GoToWebinar/GenericFunctions.js +5 -4
- package/dist/nodes/GoToWebinar/GenericFunctions.js.map +1 -1
- package/dist/nodes/Google/Sheet/GoogleSheetsTrigger.utils.d.ts +7 -1
- package/dist/nodes/HelpScout/GenericFunctions.js +2 -1
- package/dist/nodes/HelpScout/GenericFunctions.js.map +1 -1
- package/dist/nodes/HtmlExtract/HtmlExtract.node.js +4 -2
- package/dist/nodes/HtmlExtract/HtmlExtract.node.js.map +1 -1
- package/dist/nodes/HtmlExtract/test/workflow.dotNotation.json +143 -0
- package/dist/nodes/HttpRequest/GenericFunctions.d.ts +9 -0
- package/dist/nodes/HttpRequest/GenericFunctions.js +18 -1
- package/dist/nodes/HttpRequest/GenericFunctions.js.map +1 -1
- package/dist/nodes/HttpRequest/HttpRequest.node.js +2 -1
- package/dist/nodes/HttpRequest/HttpRequest.node.js.map +1 -1
- package/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js +56 -6
- package/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js.map +1 -1
- package/dist/nodes/Hubspot/GenericFunctions.js +2 -1
- package/dist/nodes/Hubspot/GenericFunctions.js.map +1 -1
- package/dist/nodes/LinkedIn/GenericFunctions.js +16 -4
- package/dist/nodes/LinkedIn/GenericFunctions.js.map +1 -1
- package/dist/nodes/LinkedIn/LinkedIn.node.js +33 -77
- package/dist/nodes/LinkedIn/LinkedIn.node.js.map +1 -1
- package/dist/nodes/Microsoft/Teams/GenericFunctions.js +2 -1
- package/dist/nodes/Microsoft/Teams/GenericFunctions.js.map +1 -1
- package/dist/nodes/Notion/GenericFunctions.js +2 -1
- package/dist/nodes/Notion/GenericFunctions.js.map +1 -1
- package/dist/nodes/Orbit/GenericFunctions.js +2 -1
- package/dist/nodes/Orbit/GenericFunctions.js.map +1 -1
- package/dist/nodes/Postgres/Postgres.node.d.ts +3 -9
- package/dist/nodes/Postgres/Postgres.node.js +9 -319
- package/dist/nodes/Postgres/Postgres.node.js.map +1 -1
- package/dist/nodes/Postgres/v1/PostgresV1.node.d.ts +12 -0
- package/dist/nodes/Postgres/v1/PostgresV1.node.js +345 -0
- package/dist/nodes/Postgres/v1/PostgresV1.node.js.map +1 -0
- package/dist/nodes/Postgres/{Postgres.node.functions.js → v1/genericFunctions.js} +1 -1
- package/dist/nodes/Postgres/v1/genericFunctions.js.map +1 -0
- package/dist/nodes/Postgres/v2/PostgresV2.node.d.ts +13 -0
- package/dist/nodes/Postgres/v2/PostgresV2.node.js +20 -0
- package/dist/nodes/Postgres/v2/PostgresV2.node.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/common.descriptions.d.ts +7 -0
- package/dist/nodes/Postgres/v2/actions/common.descriptions.js +317 -0
- package/dist/nodes/Postgres/v2/actions/common.descriptions.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/Database.resource.d.ts +9 -0
- package/dist/nodes/Postgres/v2/actions/database/Database.resource.js +100 -0
- package/dist/nodes/Postgres/v2/actions/database/Database.resource.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/deleteTable.operation.d.ts +24 -0
- package/dist/nodes/Postgres/v2/actions/database/deleteTable.operation.js +110 -0
- package/dist/nodes/Postgres/v2/actions/database/deleteTable.operation.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/executeQuery.operation.d.ts +24 -0
- package/dist/nodes/Postgres/v2/actions/database/executeQuery.operation.js +60 -0
- package/dist/nodes/Postgres/v2/actions/database/executeQuery.operation.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/insert.operation.d.ts +24 -0
- package/dist/nodes/Postgres/v2/actions/database/insert.operation.js +129 -0
- package/dist/nodes/Postgres/v2/actions/database/insert.operation.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/select.operation.d.ts +24 -0
- package/dist/nodes/Postgres/v2/actions/database/select.operation.js +87 -0
- package/dist/nodes/Postgres/v2/actions/database/select.operation.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/update.operation.d.ts +24 -0
- package/dist/nodes/Postgres/v2/actions/database/update.operation.js +164 -0
- package/dist/nodes/Postgres/v2/actions/database/update.operation.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/database/upsert.operation.d.ts +24 -0
- package/dist/nodes/Postgres/v2/actions/database/upsert.operation.js +165 -0
- package/dist/nodes/Postgres/v2/actions/database/upsert.operation.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/node.type.d.ts +7 -0
- package/dist/nodes/Postgres/v2/actions/node.type.js +3 -0
- package/dist/nodes/Postgres/v2/actions/node.type.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/router.d.ts +2 -0
- package/dist/nodes/Postgres/v2/actions/router.js +65 -0
- package/dist/nodes/Postgres/v2/actions/router.js.map +1 -0
- package/dist/nodes/Postgres/v2/actions/versionDescription.d.ts +2 -0
- package/dist/nodes/Postgres/v2/actions/versionDescription.js +65 -0
- package/dist/nodes/Postgres/v2/actions/versionDescription.js.map +1 -0
- package/dist/nodes/Postgres/v2/helpers/interfaces.d.ts +37 -0
- package/dist/nodes/Postgres/v2/helpers/interfaces.js +3 -0
- package/dist/nodes/Postgres/v2/helpers/interfaces.js.map +1 -0
- package/dist/nodes/Postgres/v2/helpers/utils.d.ts +29 -0
- package/dist/nodes/Postgres/v2/helpers/utils.js +258 -0
- package/dist/nodes/Postgres/v2/helpers/utils.js.map +1 -0
- package/dist/nodes/Postgres/v2/methods/credentialTest.d.ts +2 -0
- package/dist/nodes/Postgres/v2/methods/credentialTest.js +47 -0
- package/dist/nodes/Postgres/v2/methods/credentialTest.js.map +1 -0
- package/dist/nodes/Postgres/v2/methods/index.d.ts +3 -0
- package/dist/nodes/Postgres/v2/methods/index.js +30 -0
- package/dist/nodes/Postgres/v2/methods/index.js.map +1 -0
- package/dist/nodes/Postgres/v2/methods/listSearch.d.ts +3 -0
- package/dist/nodes/Postgres/v2/methods/listSearch.js +42 -0
- package/dist/nodes/Postgres/v2/methods/listSearch.js.map +1 -0
- package/dist/nodes/Postgres/v2/methods/loadOptions.d.ts +4 -0
- package/dist/nodes/Postgres/v2/methods/loadOptions.js +40 -0
- package/dist/nodes/Postgres/v2/methods/loadOptions.js.map +1 -0
- package/dist/nodes/Postgres/v2/transport/index.d.ts +10 -0
- package/dist/nodes/Postgres/v2/transport/index.js +168 -0
- package/dist/nodes/Postgres/v2/transport/index.js.map +1 -0
- package/dist/nodes/QuestDb/QuestDb.node.js +3 -3
- package/dist/nodes/QuestDb/QuestDb.node.js.map +1 -1
- package/dist/nodes/Redis/Redis.node.js +35 -4
- package/dist/nodes/Redis/Redis.node.js.map +1 -1
- package/dist/nodes/S3/GenericFunctions.js +2 -1
- package/dist/nodes/S3/GenericFunctions.js.map +1 -1
- package/dist/nodes/Schedule/ScheduleTrigger.node.js +2 -2
- package/dist/nodes/Schedule/ScheduleTrigger.node.js.map +1 -1
- package/dist/nodes/SendGrid/GenericFunctions.js +2 -1
- package/dist/nodes/SendGrid/GenericFunctions.js.map +1 -1
- package/dist/nodes/SentryIo/GenericFunctions.js +2 -1
- package/dist/nodes/SentryIo/GenericFunctions.js.map +1 -1
- package/dist/nodes/ServiceNow/IncidentDescription.js +7 -0
- package/dist/nodes/ServiceNow/IncidentDescription.js.map +1 -1
- package/dist/nodes/Taiga/GenericFunctions.js +2 -1
- package/dist/nodes/Taiga/GenericFunctions.js.map +1 -1
- package/dist/nodes/TimescaleDb/TimescaleDb.node.js +4 -4
- package/dist/nodes/TimescaleDb/TimescaleDb.node.js.map +1 -1
- package/dist/nodes/Totp/Totp.node.d.ts +5 -0
- package/dist/nodes/Totp/Totp.node.js +157 -0
- package/dist/nodes/Totp/Totp.node.js.map +1 -0
- package/dist/nodes/Totp/Totp.node.json +16 -0
- package/dist/nodes/Totp/test/Totp.workflow.test.json +41 -0
- package/dist/nodes/Zendesk/GenericFunctions.js +2 -1
- package/dist/nodes/Zendesk/GenericFunctions.js.map +1 -1
- package/dist/types/credentials.json +3 -2
- package/dist/types/nodes.json +16 -13
- package/package.json +6 -3
- package/dist/nodes/Postgres/Postgres.node.functions.js.map +0 -1
- /package/dist/nodes/Postgres/{Postgres.node.functions.d.ts → v1/genericFunctions.d.ts} +0 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkItemAgainstSchema = exports.getTableSchema = exports.prepareItem = exports.replaceEmptyStringsByNulls = exports.configureQueryRunner = exports.addReturning = exports.addSortRules = exports.addWhereClauses = exports.parsePostgresError = exports.prepareErrorItem = exports.wrapData = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
function wrapData(data) {
|
|
6
|
+
if (!Array.isArray(data)) {
|
|
7
|
+
return [{ json: data }];
|
|
8
|
+
}
|
|
9
|
+
return data.map((item) => ({
|
|
10
|
+
json: item,
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
exports.wrapData = wrapData;
|
|
14
|
+
function prepareErrorItem(items, error, index) {
|
|
15
|
+
return {
|
|
16
|
+
json: { message: error.message, item: { ...items[index].json }, error: { ...error } },
|
|
17
|
+
pairedItem: { item: index },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.prepareErrorItem = prepareErrorItem;
|
|
21
|
+
function parsePostgresError(node, error, queries, itemIndex) {
|
|
22
|
+
var _a;
|
|
23
|
+
if (error.message.includes('syntax error at or near') && queries.length) {
|
|
24
|
+
try {
|
|
25
|
+
const snippet = error.message.match(/syntax error at or near "(.*)"/)[1];
|
|
26
|
+
const failedQureryIndex = queries.findIndex((query) => query.query.includes(snippet));
|
|
27
|
+
if (failedQureryIndex !== -1) {
|
|
28
|
+
if (!itemIndex) {
|
|
29
|
+
itemIndex = failedQureryIndex;
|
|
30
|
+
}
|
|
31
|
+
const failedQuery = queries[failedQureryIndex].query;
|
|
32
|
+
const lines = failedQuery.split('\n');
|
|
33
|
+
const lineIndex = lines.findIndex((line) => line.includes(snippet));
|
|
34
|
+
const errorMessage = `Syntax error at line ${lineIndex + 1} near "${snippet}"`;
|
|
35
|
+
error.message = errorMessage;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch { }
|
|
39
|
+
}
|
|
40
|
+
let message = error.message;
|
|
41
|
+
const errorDescription = error.description ? error.description : error.detail || error.hint;
|
|
42
|
+
let description = errorDescription;
|
|
43
|
+
if (!description && ((_a = queries[itemIndex || 0]) === null || _a === void 0 ? void 0 : _a.query)) {
|
|
44
|
+
description = `Failed query: ${queries[itemIndex || 0].query}`;
|
|
45
|
+
}
|
|
46
|
+
if (error.message.includes('ECONNREFUSED')) {
|
|
47
|
+
message = 'Connection refused';
|
|
48
|
+
try {
|
|
49
|
+
description = error.message.split('ECONNREFUSED ')[1].trim();
|
|
50
|
+
}
|
|
51
|
+
catch (e) { }
|
|
52
|
+
}
|
|
53
|
+
if (error.message.includes('ENOTFOUND')) {
|
|
54
|
+
message = 'Host not found';
|
|
55
|
+
try {
|
|
56
|
+
description = error.message.split('ENOTFOUND ')[1].trim();
|
|
57
|
+
}
|
|
58
|
+
catch (e) { }
|
|
59
|
+
}
|
|
60
|
+
if (error.message.includes('ETIMEDOUT')) {
|
|
61
|
+
message = 'Connection timed out';
|
|
62
|
+
try {
|
|
63
|
+
description = error.message.split('ETIMEDOUT ')[1].trim();
|
|
64
|
+
}
|
|
65
|
+
catch (e) { }
|
|
66
|
+
}
|
|
67
|
+
return new n8n_workflow_1.NodeOperationError(node, error, {
|
|
68
|
+
message,
|
|
69
|
+
description,
|
|
70
|
+
itemIndex,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.parsePostgresError = parsePostgresError;
|
|
74
|
+
function addWhereClauses(node, itemIndex, query, clauses, replacements, combineConditions) {
|
|
75
|
+
if (clauses.length === 0)
|
|
76
|
+
return [query, replacements];
|
|
77
|
+
let combineWith = 'AND';
|
|
78
|
+
if (combineConditions === 'OR') {
|
|
79
|
+
combineWith = 'OR';
|
|
80
|
+
}
|
|
81
|
+
let replacementIndex = replacements.length + 1;
|
|
82
|
+
let whereQuery = ' WHERE';
|
|
83
|
+
const values = [];
|
|
84
|
+
clauses.forEach((clause, index) => {
|
|
85
|
+
if (clause.condition === 'equal') {
|
|
86
|
+
clause.condition = '=';
|
|
87
|
+
}
|
|
88
|
+
if (['>', '<', '>=', '<='].includes(clause.condition)) {
|
|
89
|
+
const value = Number(clause.value);
|
|
90
|
+
if (Number.isNaN(value)) {
|
|
91
|
+
throw new n8n_workflow_1.NodeOperationError(node, `Operator in entry ${index + 1} of 'Select Rows' works with numbers, but value ${clause.value} is not a number`, {
|
|
92
|
+
itemIndex,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
clause.value = value;
|
|
96
|
+
}
|
|
97
|
+
const columnReplacement = `$${replacementIndex}:name`;
|
|
98
|
+
values.push(clause.column);
|
|
99
|
+
replacementIndex = replacementIndex + 1;
|
|
100
|
+
let valueReplacement = '';
|
|
101
|
+
if (clause.condition !== 'IS NULL') {
|
|
102
|
+
valueReplacement = ` $${replacementIndex}`;
|
|
103
|
+
values.push(clause.value);
|
|
104
|
+
replacementIndex = replacementIndex + 1;
|
|
105
|
+
}
|
|
106
|
+
const operator = index === clauses.length - 1 ? '' : ` ${combineWith}`;
|
|
107
|
+
whereQuery += ` ${columnReplacement} ${clause.condition}${valueReplacement}${operator}`;
|
|
108
|
+
});
|
|
109
|
+
return [`${query}${whereQuery}`, replacements.concat(...values)];
|
|
110
|
+
}
|
|
111
|
+
exports.addWhereClauses = addWhereClauses;
|
|
112
|
+
function addSortRules(query, rules, replacements) {
|
|
113
|
+
if (rules.length === 0)
|
|
114
|
+
return [query, replacements];
|
|
115
|
+
let replacementIndex = replacements.length + 1;
|
|
116
|
+
let orderByQuery = ' ORDER BY';
|
|
117
|
+
const values = [];
|
|
118
|
+
rules.forEach((rule, index) => {
|
|
119
|
+
const columnReplacement = `$${replacementIndex}:name`;
|
|
120
|
+
values.push(rule.column);
|
|
121
|
+
replacementIndex = replacementIndex + 1;
|
|
122
|
+
const endWith = index === rules.length - 1 ? '' : ',';
|
|
123
|
+
const sortDirection = rule.direction === 'DESC' ? 'DESC' : 'ASC';
|
|
124
|
+
orderByQuery += ` ${columnReplacement} ${sortDirection}${endWith}`;
|
|
125
|
+
});
|
|
126
|
+
return [`${query}${orderByQuery}`, replacements.concat(...values)];
|
|
127
|
+
}
|
|
128
|
+
exports.addSortRules = addSortRules;
|
|
129
|
+
function addReturning(query, outputColumns, replacements) {
|
|
130
|
+
if (outputColumns.includes('*'))
|
|
131
|
+
return [`${query} RETURNING *`, replacements];
|
|
132
|
+
const replacementIndex = replacements.length + 1;
|
|
133
|
+
return [`${query} RETURNING $${replacementIndex}:name`, [...replacements, outputColumns]];
|
|
134
|
+
}
|
|
135
|
+
exports.addReturning = addReturning;
|
|
136
|
+
const configureQueryRunner = (node, constructExecutionMetaData, continueOnFail, pgp, db) => async (queries, items, options) => {
|
|
137
|
+
let returnData = [];
|
|
138
|
+
const queryBatching = options.queryBatching || 'single';
|
|
139
|
+
if (queryBatching === 'single') {
|
|
140
|
+
try {
|
|
141
|
+
returnData = (await db.multi(pgp.helpers.concat(queries)))
|
|
142
|
+
.map((result, i) => {
|
|
143
|
+
return constructExecutionMetaData(wrapData(result), {
|
|
144
|
+
itemData: { item: i },
|
|
145
|
+
});
|
|
146
|
+
})
|
|
147
|
+
.flat();
|
|
148
|
+
returnData = returnData.length ? returnData : [{ json: { success: true } }];
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
const error = parsePostgresError(node, err, queries);
|
|
152
|
+
if (!continueOnFail)
|
|
153
|
+
throw error;
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
json: {
|
|
157
|
+
message: error.message,
|
|
158
|
+
error: { ...error },
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (queryBatching === 'transaction') {
|
|
165
|
+
returnData = await db.tx(async (transaction) => {
|
|
166
|
+
const result = [];
|
|
167
|
+
for (let i = 0; i < queries.length; i++) {
|
|
168
|
+
try {
|
|
169
|
+
const transactionResult = await transaction.any(queries[i].query, queries[i].values);
|
|
170
|
+
const executionData = constructExecutionMetaData(wrapData(transactionResult.length ? transactionResult : [{ success: true }]), { itemData: { item: i } });
|
|
171
|
+
result.push(...executionData);
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
const error = parsePostgresError(node, err, queries, i);
|
|
175
|
+
if (!continueOnFail)
|
|
176
|
+
throw error;
|
|
177
|
+
result.push(prepareErrorItem(items, error, i));
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (queryBatching === 'independently') {
|
|
185
|
+
returnData = await db.task(async (t) => {
|
|
186
|
+
const result = [];
|
|
187
|
+
for (let i = 0; i < queries.length; i++) {
|
|
188
|
+
try {
|
|
189
|
+
const transactionResult = await t.any(queries[i].query, queries[i].values);
|
|
190
|
+
const executionData = constructExecutionMetaData(wrapData(transactionResult.length ? transactionResult : [{ success: true }]), { itemData: { item: i } });
|
|
191
|
+
result.push(...executionData);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
const error = parsePostgresError(node, err, queries, i);
|
|
195
|
+
if (!continueOnFail)
|
|
196
|
+
throw error;
|
|
197
|
+
result.push(prepareErrorItem(items, error, i));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return returnData;
|
|
204
|
+
};
|
|
205
|
+
exports.configureQueryRunner = configureQueryRunner;
|
|
206
|
+
function replaceEmptyStringsByNulls(items, replace) {
|
|
207
|
+
if (!replace)
|
|
208
|
+
return items;
|
|
209
|
+
const returnData = items.map((item) => {
|
|
210
|
+
const newItem = { ...item };
|
|
211
|
+
const keys = Object.keys(newItem.json);
|
|
212
|
+
for (const key of keys) {
|
|
213
|
+
if (newItem.json[key] === '') {
|
|
214
|
+
newItem.json[key] = null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return newItem;
|
|
218
|
+
});
|
|
219
|
+
return returnData;
|
|
220
|
+
}
|
|
221
|
+
exports.replaceEmptyStringsByNulls = replaceEmptyStringsByNulls;
|
|
222
|
+
function prepareItem(values) {
|
|
223
|
+
const item = values.reduce((acc, { column, value }) => {
|
|
224
|
+
acc[column] = value;
|
|
225
|
+
return acc;
|
|
226
|
+
}, {});
|
|
227
|
+
return item;
|
|
228
|
+
}
|
|
229
|
+
exports.prepareItem = prepareItem;
|
|
230
|
+
async function getTableSchema(db, schema, table) {
|
|
231
|
+
const columns = await db.any('SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2', [schema, table]);
|
|
232
|
+
return columns;
|
|
233
|
+
}
|
|
234
|
+
exports.getTableSchema = getTableSchema;
|
|
235
|
+
function checkItemAgainstSchema(node, item, columnsInfo, index) {
|
|
236
|
+
var _a;
|
|
237
|
+
if (columnsInfo.length === 0)
|
|
238
|
+
return item;
|
|
239
|
+
const schema = columnsInfo.reduce((acc, { column_name, data_type, is_nullable }) => {
|
|
240
|
+
acc[column_name] = { type: data_type.toUpperCase(), nullable: is_nullable === 'YES' };
|
|
241
|
+
return acc;
|
|
242
|
+
}, {});
|
|
243
|
+
for (const key of Object.keys(item)) {
|
|
244
|
+
if (schema[key] === undefined) {
|
|
245
|
+
throw new n8n_workflow_1.NodeOperationError(node, `Column '${key}' does not exist in selected table`, {
|
|
246
|
+
itemIndex: index,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (item[key] === null && !((_a = schema[key]) === null || _a === void 0 ? void 0 : _a.nullable)) {
|
|
250
|
+
throw new n8n_workflow_1.NodeOperationError(node, `Column '${key}' is not nullable`, {
|
|
251
|
+
itemIndex: index,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return item;
|
|
256
|
+
}
|
|
257
|
+
exports.checkItemAgainstSchema = checkItemAgainstSchema;
|
|
258
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../nodes/Postgres/v2/helpers/utils.ts"],"names":[],"mappings":";;;AACA,+CAAkD;AAclD,SAAgB,QAAQ,CAAC,IAAiC;IACzD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACzB,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;KACxB;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,IAAI;KACV,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,4BAOC;AAED,SAAgB,gBAAgB,CAC/B,KAA2B,EAC3B,KAA+C,EAC/C,KAAa;IAEb,OAAO;QACN,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE;QACrF,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;KACL,CAAC;AACzB,CAAC;AATD,4CASC;AAED,SAAgB,kBAAk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gB,sBAAsB,CACrC,IAAW,EACX,IAAiB,EACjB,WAAyB,EACzB,KAAa;;IAEb,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,EAAE;QAClF,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,WAAW,KAAK,KAAK,EAAE,CAAC;QACtF,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAiB,CAAC,CAAC;IAEtB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACpC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAC9B,MAAM,IAAI,iCAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,oCAAoC,EAAE;gBACtF,SAAS,EAAE,KAAK;aAChB,CAAC,CAAC;SACH;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAA,MAAC,MAAM,CAAC,GAAG,CAAiB,0CAAE,QAAQ,CAAA,EAAE;YAClE,MAAM,IAAI,iCAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,mBAAmB,EAAE;gBACrE,SAAS,EAAE,KAAK;aAChB,CAAC,CAAC;SACH;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AA1BD,wDA0BC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postgresConnectionTest = void 0;
|
|
4
|
+
const transport_1 = require("../transport");
|
|
5
|
+
const ssh2_1 = require("ssh2");
|
|
6
|
+
async function postgresConnectionTest(credential) {
|
|
7
|
+
const credentials = credential.data;
|
|
8
|
+
let sshClientCreated = new ssh2_1.Client();
|
|
9
|
+
let pgpClientCreated;
|
|
10
|
+
try {
|
|
11
|
+
const { db, pgp, sshClient } = (await transport_1.Connections.getInstance(credentials, {}, true, sshClientCreated));
|
|
12
|
+
sshClientCreated = sshClient;
|
|
13
|
+
pgpClientCreated = pgp;
|
|
14
|
+
await db.connect();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
let message = error.message;
|
|
18
|
+
if (error.message.includes('ECONNREFUSED')) {
|
|
19
|
+
message = 'Connection refused';
|
|
20
|
+
}
|
|
21
|
+
if (error.message.includes('ENOTFOUND')) {
|
|
22
|
+
message = 'Host not found, please check your host name';
|
|
23
|
+
}
|
|
24
|
+
if (error.message.includes('ETIMEDOUT')) {
|
|
25
|
+
message = 'Connection timed out';
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
status: 'Error',
|
|
29
|
+
message,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
if (sshClientCreated) {
|
|
34
|
+
sshClientCreated.end();
|
|
35
|
+
}
|
|
36
|
+
if (pgpClientCreated) {
|
|
37
|
+
pgpClientCreated.end();
|
|
38
|
+
}
|
|
39
|
+
await transport_1.Connections.getInstance({}, {}, false, undefined, true);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: 'OK',
|
|
43
|
+
message: 'Connection successful!',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.postgresConnectionTest = postgresConnectionTest;
|
|
47
|
+
//# sourceMappingURL=credentialTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentialTest.js","sourceRoot":"","sources":["../../../../../nodes/Postgres/v2/methods/credentialTest.ts"],"names":[],"mappings":";;;AAOA,4CAA2C;AAE3C,+BAA8B;AAGvB,KAAK,UAAU,sBAAsB,CAE3C,UAAiC;IAEjC,MAAM,WAAW,GAAG,UAAU,CAAC,IAAmB,CAAC;IA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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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadOptions = exports.listSearch = exports.credentialTest = void 0;
|
|
27
|
+
exports.credentialTest = __importStar(require("./credentialTest"));
|
|
28
|
+
exports.listSearch = __importStar(require("./listSearch"));
|
|
29
|
+
exports.loadOptions = __importStar(require("./loadOptions"));
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../nodes/Postgres/v2/methods/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAAmD;AACnD,2DAA2C;AAC3C,6DAA6C"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ILoadOptionsFunctions, INodeListSearchResult } from 'n8n-workflow';
|
|
2
|
+
export declare function schemaSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult>;
|
|
3
|
+
export declare function tableSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableSearch = exports.schemaSearch = void 0;
|
|
4
|
+
const transport_1 = require("../transport");
|
|
5
|
+
async function schemaSearch() {
|
|
6
|
+
const credentials = await this.getCredentials('postgres');
|
|
7
|
+
const { db } = (await transport_1.Connections.getInstance(credentials));
|
|
8
|
+
try {
|
|
9
|
+
const response = await db.any('SELECT schema_name FROM information_schema.schemata');
|
|
10
|
+
return {
|
|
11
|
+
results: response.map((schema) => ({
|
|
12
|
+
name: schema.schema_name,
|
|
13
|
+
value: schema.schema_name,
|
|
14
|
+
})),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.schemaSearch = schemaSearch;
|
|
22
|
+
async function tableSearch() {
|
|
23
|
+
const credentials = await this.getCredentials('postgres');
|
|
24
|
+
const { db } = (await transport_1.Connections.getInstance(credentials));
|
|
25
|
+
const schema = this.getNodeParameter('schema', 0, {
|
|
26
|
+
extractValue: true,
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const response = await db.any('SELECT table_name FROM information_schema.tables WHERE table_schema=$1', [schema]);
|
|
30
|
+
return {
|
|
31
|
+
results: response.map((table) => ({
|
|
32
|
+
name: table.table_name,
|
|
33
|
+
value: table.table_name,
|
|
34
|
+
})),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.tableSearch = tableSearch;
|
|
42
|
+
//# sourceMappingURL=listSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listSearch.js","sourceRoot":"","sources":["../../../../../nodes/Postgres/v2/methods/listSearch.ts"],"names":[],"mappings":";;;AAEA,4CAA2C;AAEpC,KAAK,UAAU,YAAY;IACjC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAE1D,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,uBAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAoB,CAAC;IAE/E,IAAI;QACH,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;QAErF,OAAO;YACN,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBAClC,IAAI,EAAE,MAAM,CAAC,WAAqB;gBAClC,KAAK,EAAE,MAAM,CAAC,WAAqB;aACnC,CAAC,CAAC;SACH,CAAC;KACF;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,KAAK,CAAC;KACZ;AACF,CAAC;AAjBD,oCAiBC;AACM,KAAK,UAAU,WAAW;IAChC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAE1D,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,uBAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAoB,CAAC;IAE/E,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,EAAE;QACjD,YAAY,EAAE,IAAI;KAClB,CAAW,CAAC;IAEb,IAAI;QACH,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,CAC5B,wEAAwE,EACxE,CAAC,MAAM,CAAC,CACR,CAAC;QAEF,OAAO;YACN,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACjC,IAAI,EAAE,KAAK,CAAC,UAAoB;gBAChC,KAAK,EAAE,KAAK,CAAC,UAAoB;aACjC,CAAC,CAAC;SACH,CAAC;KACF;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,KAAK,CAAC;KACZ;AACF,CAAC;AAxBD,kCAwBC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
|
|
2
|
+
export declare function getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
3
|
+
export declare function getColumnsMultiOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
4
|
+
export declare function getColumnsWithoutColumnToMatchOn(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getColumnsWithoutColumnToMatchOn = exports.getColumnsMultiOptions = exports.getColumns = void 0;
|
|
4
|
+
const utils_1 = require("../helpers/utils");
|
|
5
|
+
const transport_1 = require("../transport");
|
|
6
|
+
async function getColumns() {
|
|
7
|
+
const credentials = await this.getCredentials('postgres');
|
|
8
|
+
const { db } = (await transport_1.Connections.getInstance(credentials));
|
|
9
|
+
const schema = this.getNodeParameter('schema', 0, {
|
|
10
|
+
extractValue: true,
|
|
11
|
+
});
|
|
12
|
+
const table = this.getNodeParameter('table', 0, {
|
|
13
|
+
extractValue: true,
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
const columns = await (0, utils_1.getTableSchema)(db, schema, table);
|
|
17
|
+
return columns.map((column) => ({
|
|
18
|
+
name: column.column_name,
|
|
19
|
+
value: column.column_name,
|
|
20
|
+
description: `Type: ${column.data_type.toUpperCase()}, Nullable: ${column.is_nullable}`,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.getColumns = getColumns;
|
|
28
|
+
async function getColumnsMultiOptions() {
|
|
29
|
+
const returnData = await getColumns.call(this);
|
|
30
|
+
const returnAll = { name: '*', value: '*', description: 'All columns' };
|
|
31
|
+
return [returnAll, ...returnData];
|
|
32
|
+
}
|
|
33
|
+
exports.getColumnsMultiOptions = getColumnsMultiOptions;
|
|
34
|
+
async function getColumnsWithoutColumnToMatchOn() {
|
|
35
|
+
const columnToMatchOn = this.getNodeParameter('columnToMatchOn');
|
|
36
|
+
const returnData = await getColumns.call(this);
|
|
37
|
+
return returnData.filter((column) => column.value !== columnToMatchOn);
|
|
38
|
+
}
|
|
39
|
+
exports.getColumnsWithoutColumnToMatchOn = getColumnsWithoutColumnToMatchOn;
|
|
40
|
+
//# sourceMappingURL=loadOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadOptions.js","sourceRoot":"","sources":["../../../../../nodes/Postgres/v2/methods/loadOptions.ts"],"names":[],"mappings":";;;AAEA,4CAAkD;AAClD,4CAA2C;AAEpC,KAAK,UAAU,UAAU;IAC/B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAE1D,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,uBAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAoB,CAAC;IAE/E,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,EAAE;QACjD,YAAY,EAAE,IAAI;KAClB,CAAW,CAAC;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE;QAC/C,YAAY,EAAE,IAAI;KAClB,CAAW,CAAC;IAEb,IAAI;QACH,MAAM,OAAO,GAAG,MAAM,IAAA,sBAAc,EAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAExD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAC/B,IAAI,EAAE,MAAM,CAAC,WAAW;YACxB,KAAK,EAAE,MAAM,CAAC,WAAW;YACzB,WAAW,EAAE,SAAS,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE,eAAe,MAAM,CAAC,WAAW,EAAE;SACvF,CAAC,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,KAAK,CAAC;KACZ;AACF,CAAC;AAxBD,gCAwBC;AAEM,KAAK,UAAU,sBAAsB;IAG3C,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC;IACxE,OAAO,CAAC,SAAS,EAAE,GAAG,UAAU,CAAC,CAAC;AACnC,CAAC;AAND,wDAMC;AAEM,KAAK,UAAU,gCAAgC;IAGrD,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAW,CAAC;IAC3E,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,eAAe,CAAC,CAAC;AACxE,CAAC;AAND,4EAMC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IDataObject } from 'n8n-workflow';
|
|
2
|
+
import { Client } from 'ssh2';
|
|
3
|
+
import type { PgpClient, PgpDatabase } from '../helpers/interfaces';
|
|
4
|
+
export declare const Connections: {
|
|
5
|
+
getInstance(credentials?: IDataObject, options?: IDataObject, reload?: boolean, createdSshClient?: Client, nulify?: boolean): Promise<{
|
|
6
|
+
db: PgpDatabase;
|
|
7
|
+
pgp: PgpClient;
|
|
8
|
+
sshClient?: Client | undefined;
|
|
9
|
+
} | null>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Connections = void 0;
|
|
7
|
+
const ssh2_1 = require("ssh2");
|
|
8
|
+
const net_1 = require("net");
|
|
9
|
+
const pg_promise_1 = __importDefault(require("pg-promise"));
|
|
10
|
+
const promises_1 = require("fs/promises");
|
|
11
|
+
const tmp_promise_1 = require("tmp-promise");
|
|
12
|
+
async function createSshConnectConfig(credentials) {
|
|
13
|
+
if (credentials.sshAuthenticateWith === 'password') {
|
|
14
|
+
return {
|
|
15
|
+
host: credentials.sshHost,
|
|
16
|
+
port: credentials.sshPort,
|
|
17
|
+
username: credentials.sshUser,
|
|
18
|
+
password: credentials.sshPassword,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const { path } = await (0, tmp_promise_1.file)({ prefix: 'n8n-ssh-' });
|
|
23
|
+
await (0, promises_1.writeFile)(path, credentials.privateKey);
|
|
24
|
+
const options = {
|
|
25
|
+
host: credentials.host,
|
|
26
|
+
username: credentials.username,
|
|
27
|
+
port: credentials.port,
|
|
28
|
+
privateKey: path,
|
|
29
|
+
};
|
|
30
|
+
if (credentials.passphrase) {
|
|
31
|
+
options.passphrase = credentials.passphrase;
|
|
32
|
+
}
|
|
33
|
+
return options;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function configurePostgres(credentials, options = {}, createdSshClient) {
|
|
37
|
+
const pgp = (0, pg_promise_1.default)();
|
|
38
|
+
if (options.largeNumbersOutput === 'numbers') {
|
|
39
|
+
pgp.pg.types.setTypeParser(20, (value) => {
|
|
40
|
+
return parseInt(value, 10);
|
|
41
|
+
});
|
|
42
|
+
pgp.pg.types.setTypeParser(1700, (value) => {
|
|
43
|
+
return parseFloat(value);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const dbConfig = {
|
|
47
|
+
host: credentials.host,
|
|
48
|
+
port: credentials.port,
|
|
49
|
+
database: credentials.database,
|
|
50
|
+
user: credentials.user,
|
|
51
|
+
password: credentials.password,
|
|
52
|
+
};
|
|
53
|
+
if (options.connectionTimeout) {
|
|
54
|
+
dbConfig.connectionTimeoutMillis = options.connectionTimeout * 1000;
|
|
55
|
+
}
|
|
56
|
+
if (credentials.allowUnauthorizedCerts === true) {
|
|
57
|
+
dbConfig.ssl = {
|
|
58
|
+
rejectUnauthorized: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
dbConfig.ssl = !['disable', undefined].includes(credentials.ssl);
|
|
63
|
+
dbConfig.sslmode = credentials.ssl || 'disable';
|
|
64
|
+
}
|
|
65
|
+
if (!credentials.sshTunnel) {
|
|
66
|
+
const db = pgp(dbConfig);
|
|
67
|
+
return { db, pgp };
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const sshClient = createdSshClient || new ssh2_1.Client();
|
|
71
|
+
const tunnelConfig = await createSshConnectConfig(credentials);
|
|
72
|
+
const localHost = '127.0.0.1';
|
|
73
|
+
const localPort = credentials.sshPostgresPort;
|
|
74
|
+
let proxy;
|
|
75
|
+
const db = await new Promise((resolve, reject) => {
|
|
76
|
+
let sshClientReady = false;
|
|
77
|
+
proxy = (0, net_1.createServer)((socket) => {
|
|
78
|
+
if (!sshClientReady)
|
|
79
|
+
return socket.destroy();
|
|
80
|
+
sshClient.forwardOut(socket.remoteAddress, socket.remotePort, credentials.host, credentials.port, (err, stream) => {
|
|
81
|
+
if (err)
|
|
82
|
+
reject(err);
|
|
83
|
+
socket.pipe(stream);
|
|
84
|
+
stream.pipe(socket);
|
|
85
|
+
});
|
|
86
|
+
}).listen(localPort, localHost);
|
|
87
|
+
proxy.on('error', (err) => {
|
|
88
|
+
reject(err);
|
|
89
|
+
});
|
|
90
|
+
sshClient.connect(tunnelConfig);
|
|
91
|
+
sshClient.on('ready', () => {
|
|
92
|
+
sshClientReady = true;
|
|
93
|
+
const updatedDbConfig = {
|
|
94
|
+
...dbConfig,
|
|
95
|
+
port: localPort,
|
|
96
|
+
host: localHost,
|
|
97
|
+
};
|
|
98
|
+
const dbConnection = pgp(updatedDbConfig);
|
|
99
|
+
resolve(dbConnection);
|
|
100
|
+
});
|
|
101
|
+
sshClient.on('error', (err) => {
|
|
102
|
+
reject(err);
|
|
103
|
+
});
|
|
104
|
+
sshClient.on('end', async () => {
|
|
105
|
+
if (tunnelConfig.privateKey) {
|
|
106
|
+
await (0, promises_1.rm)(tunnelConfig.privateKey, { force: true });
|
|
107
|
+
}
|
|
108
|
+
if (proxy)
|
|
109
|
+
proxy.close();
|
|
110
|
+
});
|
|
111
|
+
}).catch((err) => {
|
|
112
|
+
if (proxy)
|
|
113
|
+
proxy.close();
|
|
114
|
+
if (sshClient)
|
|
115
|
+
sshClient.end();
|
|
116
|
+
let message = err.message;
|
|
117
|
+
let description = err.description;
|
|
118
|
+
if (err.message.includes('ECONNREFUSED')) {
|
|
119
|
+
message = 'Connection refused';
|
|
120
|
+
try {
|
|
121
|
+
description = err.message.split('ECONNREFUSED ')[1].trim();
|
|
122
|
+
}
|
|
123
|
+
catch (e) { }
|
|
124
|
+
}
|
|
125
|
+
if (err.message.includes('ENOTFOUND')) {
|
|
126
|
+
message = 'Host not found';
|
|
127
|
+
try {
|
|
128
|
+
description = err.message.split('ENOTFOUND ')[1].trim();
|
|
129
|
+
}
|
|
130
|
+
catch (e) { }
|
|
131
|
+
}
|
|
132
|
+
if (err.message.includes('ETIMEDOUT')) {
|
|
133
|
+
message = 'Connection timed out';
|
|
134
|
+
try {
|
|
135
|
+
description = err.message.split('ETIMEDOUT ')[1].trim();
|
|
136
|
+
}
|
|
137
|
+
catch (e) { }
|
|
138
|
+
}
|
|
139
|
+
err.message = message;
|
|
140
|
+
err.description = description;
|
|
141
|
+
throw err;
|
|
142
|
+
});
|
|
143
|
+
return { db, pgp, sshClient };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.Connections = (function () {
|
|
147
|
+
let instance = null;
|
|
148
|
+
return {
|
|
149
|
+
async getInstance(credentials = {}, options = {}, reload = false, createdSshClient, nulify = false) {
|
|
150
|
+
if (nulify) {
|
|
151
|
+
instance = null;
|
|
152
|
+
return instance;
|
|
153
|
+
}
|
|
154
|
+
if (instance !== null && reload) {
|
|
155
|
+
if (instance.sshClient) {
|
|
156
|
+
instance.sshClient.end();
|
|
157
|
+
}
|
|
158
|
+
instance.pgp.end();
|
|
159
|
+
instance = null;
|
|
160
|
+
}
|
|
161
|
+
if (instance === null && Object.keys(credentials).length) {
|
|
162
|
+
instance = await configurePostgres(credentials, options, createdSshClient);
|
|
163
|
+
}
|
|
164
|
+
return instance;
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
})();
|
|
168
|
+
//# sourceMappingURL=index.js.map
|