n8n-nodes-get-variables 0.1.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/credentials/N8nApi.credentials.ts +24 -0
- package/dist/credentials/N8nApi.credentials.d.ts +6 -0
- package/dist/credentials/N8nApi.credentials.js +29 -0
- package/dist/credentials/N8nApi.credentials.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/GetVariables/GetVariables.node.d.ts +11 -0
- package/dist/nodes/GetVariables/GetVariables.node.js +115 -0
- package/dist/nodes/GetVariables/GetVariables.node.js.map +1 -0
- package/index.ts +2 -0
- package/nodes/GetVariables/GetVariables.node.ts +128 -0
- package/package.json +34 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ICredentialType, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
|
|
3
|
+
export class N8nApi implements ICredentialType {
|
|
4
|
+
name = 'n8nApi';
|
|
5
|
+
displayName = 'n8n API';
|
|
6
|
+
properties: INodeProperties[] = [
|
|
7
|
+
{
|
|
8
|
+
displayName: 'Base URL',
|
|
9
|
+
name: 'baseUrl',
|
|
10
|
+
type: 'string',
|
|
11
|
+
default: 'http://localhost:5678',
|
|
12
|
+
placeholder: 'https://your-n8n-instance.com',
|
|
13
|
+
description: 'The base URL of your n8n instance (no trailing slash)',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
displayName: 'API Key',
|
|
17
|
+
name: 'apiKey',
|
|
18
|
+
type: 'string',
|
|
19
|
+
typeOptions: { password: true },
|
|
20
|
+
default: '',
|
|
21
|
+
description: 'Your n8n API key (Settings → API → Create API Key)',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.N8nApi = void 0;
|
|
4
|
+
class N8nApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'n8nApi';
|
|
7
|
+
this.displayName = 'n8n API';
|
|
8
|
+
this.properties = [
|
|
9
|
+
{
|
|
10
|
+
displayName: 'Base URL',
|
|
11
|
+
name: 'baseUrl',
|
|
12
|
+
type: 'string',
|
|
13
|
+
default: 'http://localhost:5678',
|
|
14
|
+
placeholder: 'https://your-n8n-instance.com',
|
|
15
|
+
description: 'The base URL of your n8n instance (no trailing slash)',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
displayName: 'API Key',
|
|
19
|
+
name: 'apiKey',
|
|
20
|
+
type: 'string',
|
|
21
|
+
typeOptions: { password: true },
|
|
22
|
+
default: '',
|
|
23
|
+
description: 'Your n8n API key (Settings → API → Create API Key)',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.N8nApi = N8nApi;
|
|
29
|
+
//# sourceMappingURL=N8nApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"N8nApi.credentials.js","sourceRoot":"","sources":["../../credentials/N8nApi.credentials.ts"],"names":[],"mappings":";;;AAEA,MAAa,MAAM;IAAnB;QACE,SAAI,GAAG,QAAQ,CAAC;QAChB,gBAAW,GAAG,SAAS,CAAC;QACxB,eAAU,GAAsB;YAC9B;gBACE,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,uBAAuB;gBAChC,WAAW,EAAE,+BAA+B;gBAC5C,WAAW,EAAE,uDAAuD;aACrE;YACD;gBACE,WAAW,EAAE,SAAS;gBACtB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,oDAAoD;aAClE;SACF,CAAC;IACJ,CAAC;CAAA;AArBD,wBAqBC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.N8nApi = exports.GetVariables = void 0;
|
|
4
|
+
var GetVariables_node_1 = require("./nodes/GetVariables/GetVariables.node");
|
|
5
|
+
Object.defineProperty(exports, "GetVariables", { enumerable: true, get: function () { return GetVariables_node_1.GetVariables; } });
|
|
6
|
+
var N8nApi_credentials_1 = require("./credentials/N8nApi.credentials");
|
|
7
|
+
Object.defineProperty(exports, "N8nApi", { enumerable: true, get: function () { return N8nApi_credentials_1.N8nApi; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,4EAAsE;AAA7D,iHAAA,YAAY,OAAA;AACrB,uEAA0D;AAAjD,4GAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IExecuteFunctions, ILoadOptionsFunctions, INodeExecutionData, INodePropertyOptions, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class GetVariables implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
methods: {
|
|
5
|
+
loadOptions: {
|
|
6
|
+
getDataTables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
7
|
+
getVariableKeys(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetVariables = void 0;
|
|
4
|
+
class GetVariables {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.description = {
|
|
7
|
+
displayName: 'Get Variables',
|
|
8
|
+
name: 'getVariables',
|
|
9
|
+
icon: 'fa:key',
|
|
10
|
+
group: ['transform'],
|
|
11
|
+
version: 1,
|
|
12
|
+
description: 'Fetch variables from an n8n DataTable and return them as a key-value object',
|
|
13
|
+
defaults: { name: 'Get Variables' },
|
|
14
|
+
inputs: [],
|
|
15
|
+
outputs: ['main'],
|
|
16
|
+
credentials: [
|
|
17
|
+
{
|
|
18
|
+
name: 'n8nApi',
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
properties: [
|
|
23
|
+
{
|
|
24
|
+
displayName: 'DataTable',
|
|
25
|
+
name: 'dataTableId',
|
|
26
|
+
type: 'options',
|
|
27
|
+
typeOptions: {
|
|
28
|
+
loadOptionsMethod: 'getDataTables',
|
|
29
|
+
},
|
|
30
|
+
default: '',
|
|
31
|
+
required: true,
|
|
32
|
+
description: 'The DataTable to fetch variables from',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
displayName: 'Variable Keys',
|
|
36
|
+
name: 'variableKeys',
|
|
37
|
+
type: 'multiOptions',
|
|
38
|
+
typeOptions: {
|
|
39
|
+
loadOptionsMethod: 'getVariableKeys',
|
|
40
|
+
loadOptionsDependsOn: ['dataTableId'],
|
|
41
|
+
},
|
|
42
|
+
default: [],
|
|
43
|
+
description: 'Which variable_key values to include. Leave empty to return all.',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
this.methods = {
|
|
48
|
+
loadOptions: {
|
|
49
|
+
async getDataTables() {
|
|
50
|
+
var _a;
|
|
51
|
+
const credentials = await this.getCredentials('n8nApi');
|
|
52
|
+
const baseUrl = credentials.baseUrl.replace(/\/$/, '');
|
|
53
|
+
const apiKey = credentials.apiKey;
|
|
54
|
+
const response = await this.helpers.httpRequest({
|
|
55
|
+
method: 'GET',
|
|
56
|
+
url: `${baseUrl}/api/v1/datatables`,
|
|
57
|
+
headers: { 'X-N8N-API-KEY': apiKey },
|
|
58
|
+
});
|
|
59
|
+
const tables = (_a = response.data) !== null && _a !== void 0 ? _a : response;
|
|
60
|
+
return tables.map((t) => ({
|
|
61
|
+
name: t.name,
|
|
62
|
+
value: t.id,
|
|
63
|
+
}));
|
|
64
|
+
},
|
|
65
|
+
async getVariableKeys() {
|
|
66
|
+
var _a;
|
|
67
|
+
const credentials = await this.getCredentials('n8nApi');
|
|
68
|
+
const baseUrl = credentials.baseUrl.replace(/\/$/, '');
|
|
69
|
+
const apiKey = credentials.apiKey;
|
|
70
|
+
const tableId = this.getCurrentNodeParameter('dataTableId');
|
|
71
|
+
if (!tableId)
|
|
72
|
+
return [];
|
|
73
|
+
const response = await this.helpers.httpRequest({
|
|
74
|
+
method: 'GET',
|
|
75
|
+
url: `${baseUrl}/api/v1/datatables/${tableId}/rows`,
|
|
76
|
+
headers: { 'X-N8N-API-KEY': apiKey },
|
|
77
|
+
});
|
|
78
|
+
const rows = (_a = response.data) !== null && _a !== void 0 ? _a : response;
|
|
79
|
+
const keys = [
|
|
80
|
+
...new Set(rows
|
|
81
|
+
.map((r) => r.variable_key)
|
|
82
|
+
.filter(Boolean)),
|
|
83
|
+
];
|
|
84
|
+
return keys.map((key) => ({ name: key, value: key }));
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async execute() {
|
|
90
|
+
var _a;
|
|
91
|
+
const credentials = await this.getCredentials('n8nApi');
|
|
92
|
+
const baseUrl = credentials.baseUrl.replace(/\/$/, '');
|
|
93
|
+
const apiKey = credentials.apiKey;
|
|
94
|
+
const tableId = this.getNodeParameter('dataTableId', 0);
|
|
95
|
+
const selectedKeys = this.getNodeParameter('variableKeys', 0);
|
|
96
|
+
const response = await this.helpers.httpRequest({
|
|
97
|
+
method: 'GET',
|
|
98
|
+
url: `${baseUrl}/api/v1/datatables/${tableId}/rows`,
|
|
99
|
+
headers: { 'X-N8N-API-KEY': apiKey },
|
|
100
|
+
});
|
|
101
|
+
const rows = (_a = response.data) !== null && _a !== void 0 ? _a : response;
|
|
102
|
+
const keyValuePairs = rows.reduce((acc, row) => {
|
|
103
|
+
const key = row.variable_key;
|
|
104
|
+
if (!key)
|
|
105
|
+
return acc;
|
|
106
|
+
if (selectedKeys.length === 0 || selectedKeys.includes(key)) {
|
|
107
|
+
acc[key] = row.variable_value;
|
|
108
|
+
}
|
|
109
|
+
return acc;
|
|
110
|
+
}, {});
|
|
111
|
+
return [[{ json: keyValuePairs }]];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.GetVariables = GetVariables;
|
|
115
|
+
//# sourceMappingURL=GetVariables.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetVariables.node.js","sourceRoot":"","sources":["../../../nodes/GetVariables/GetVariables.node.ts"],"names":[],"mappings":";;;AAUA,MAAa,YAAY;IAAzB;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,eAAe;YAC5B,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,CAAC,WAAW,CAAC;YACpB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,6EAA6E;YAC1F,QAAQ,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;YACnC,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,WAAW,EAAE;gBACX;oBACE,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;iBACf;aACF;YACD,UAAU,EAAE;gBACV;oBACE,WAAW,EAAE,WAAW;oBACxB,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE;wBACX,iBAAiB,EAAE,eAAe;qBACnC;oBACD,OAAO,EAAE,EAAE;oBACX,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,uCAAuC;iBACrD;gBACD;oBACE,WAAW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C;YAC9C,MAAM,EAAE,KAAK;YACb,GAAG,EAAE,GAAG,OAAO,sBAAsB,OAAO,OAAO;YACnD,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE;SACrC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAkB,MAAA,QAAQ,CAAC,IAAI,mCAAI,QAAQ,CAAC;QAEtD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAC7C,MAAM,GAAG,GAAG,GAAG,CAAC,YAAsB,CAAC;YACvC,IAAI,CAAC,GAAG;gBAAE,OAAO,GAAG,CAAC;YACrB,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC5D,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,cAAwB,CAAC;YAC1C,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAiB,CAAC,CAAC;QAEtB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;CACF;AArHD,oCAqHC"}
|
package/index.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IDataObject,
|
|
3
|
+
IExecuteFunctions,
|
|
4
|
+
ILoadOptionsFunctions,
|
|
5
|
+
INodeExecutionData,
|
|
6
|
+
INodePropertyOptions,
|
|
7
|
+
INodeType,
|
|
8
|
+
INodeTypeDescription,
|
|
9
|
+
} from 'n8n-workflow';
|
|
10
|
+
|
|
11
|
+
export class GetVariables implements INodeType {
|
|
12
|
+
description: INodeTypeDescription = {
|
|
13
|
+
displayName: 'Get Variables',
|
|
14
|
+
name: 'getVariables',
|
|
15
|
+
icon: 'fa:key',
|
|
16
|
+
group: ['transform'],
|
|
17
|
+
version: 1,
|
|
18
|
+
description: 'Fetch variables from an n8n DataTable and return them as a key-value object',
|
|
19
|
+
defaults: { name: 'Get Variables' },
|
|
20
|
+
inputs: [],
|
|
21
|
+
outputs: ['main'],
|
|
22
|
+
credentials: [
|
|
23
|
+
{
|
|
24
|
+
name: 'n8nApi',
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
properties: [
|
|
29
|
+
{
|
|
30
|
+
displayName: 'DataTable',
|
|
31
|
+
name: 'dataTableId',
|
|
32
|
+
type: 'options',
|
|
33
|
+
typeOptions: {
|
|
34
|
+
loadOptionsMethod: 'getDataTables',
|
|
35
|
+
},
|
|
36
|
+
default: '',
|
|
37
|
+
required: true,
|
|
38
|
+
description: 'The DataTable to fetch variables from',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
displayName: 'Variable Keys',
|
|
42
|
+
name: 'variableKeys',
|
|
43
|
+
type: 'multiOptions',
|
|
44
|
+
typeOptions: {
|
|
45
|
+
loadOptionsMethod: 'getVariableKeys',
|
|
46
|
+
loadOptionsDependsOn: ['dataTableId'],
|
|
47
|
+
},
|
|
48
|
+
default: [],
|
|
49
|
+
description: 'Which variable_key values to include. Leave empty to return all.',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
methods = {
|
|
55
|
+
loadOptions: {
|
|
56
|
+
async getDataTables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
57
|
+
const credentials = await this.getCredentials('n8nApi');
|
|
58
|
+
const baseUrl = (credentials.baseUrl as string).replace(/\/$/, '');
|
|
59
|
+
const apiKey = credentials.apiKey as string;
|
|
60
|
+
|
|
61
|
+
const response = await this.helpers.httpRequest({
|
|
62
|
+
method: 'GET',
|
|
63
|
+
url: `${baseUrl}/api/v1/datatables`,
|
|
64
|
+
headers: { 'X-N8N-API-KEY': apiKey },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const tables: IDataObject[] = response.data ?? response;
|
|
68
|
+
return tables.map((t) => ({
|
|
69
|
+
name: t.name as string,
|
|
70
|
+
value: t.id as string,
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
async getVariableKeys(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
75
|
+
const credentials = await this.getCredentials('n8nApi');
|
|
76
|
+
const baseUrl = (credentials.baseUrl as string).replace(/\/$/, '');
|
|
77
|
+
const apiKey = credentials.apiKey as string;
|
|
78
|
+
const tableId = this.getCurrentNodeParameter('dataTableId') as string;
|
|
79
|
+
|
|
80
|
+
if (!tableId) return [];
|
|
81
|
+
|
|
82
|
+
const response = await this.helpers.httpRequest({
|
|
83
|
+
method: 'GET',
|
|
84
|
+
url: `${baseUrl}/api/v1/datatables/${tableId}/rows`,
|
|
85
|
+
headers: { 'X-N8N-API-KEY': apiKey },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const rows: IDataObject[] = response.data ?? response;
|
|
89
|
+
const keys = [
|
|
90
|
+
...new Set(
|
|
91
|
+
rows
|
|
92
|
+
.map((r) => r.variable_key as string)
|
|
93
|
+
.filter(Boolean),
|
|
94
|
+
),
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
return keys.map((key) => ({ name: key, value: key }));
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
103
|
+
const credentials = await this.getCredentials('n8nApi');
|
|
104
|
+
const baseUrl = (credentials.baseUrl as string).replace(/\/$/, '');
|
|
105
|
+
const apiKey = credentials.apiKey as string;
|
|
106
|
+
const tableId = this.getNodeParameter('dataTableId', 0) as string;
|
|
107
|
+
const selectedKeys = this.getNodeParameter('variableKeys', 0) as string[];
|
|
108
|
+
|
|
109
|
+
const response = await this.helpers.httpRequest({
|
|
110
|
+
method: 'GET',
|
|
111
|
+
url: `${baseUrl}/api/v1/datatables/${tableId}/rows`,
|
|
112
|
+
headers: { 'X-N8N-API-KEY': apiKey },
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const rows: IDataObject[] = response.data ?? response;
|
|
116
|
+
|
|
117
|
+
const keyValuePairs = rows.reduce((acc, row) => {
|
|
118
|
+
const key = row.variable_key as string;
|
|
119
|
+
if (!key) return acc;
|
|
120
|
+
if (selectedKeys.length === 0 || selectedKeys.includes(key)) {
|
|
121
|
+
acc[key] = row.variable_value as string;
|
|
122
|
+
}
|
|
123
|
+
return acc;
|
|
124
|
+
}, {} as IDataObject);
|
|
125
|
+
|
|
126
|
+
return [[{ json: keyValuePairs }]];
|
|
127
|
+
}
|
|
128
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "n8n-nodes-get-variables",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "n8n community node — collapses DataTable rows into a single key-value object",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"n8n-community-node-package"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"lint": "eslint nodes --ext .ts",
|
|
14
|
+
"lintfix": "eslint nodes --ext .ts --fix",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"n8n": {
|
|
18
|
+
"n8nNodesApiVersion": 1,
|
|
19
|
+
"credentials": [
|
|
20
|
+
"dist/credentials/N8nApi.credentials.js"
|
|
21
|
+
],
|
|
22
|
+
"nodes": [
|
|
23
|
+
"dist/nodes/GetVariables/GetVariables.node.js"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^18.16.16",
|
|
28
|
+
"n8n-workflow": "*",
|
|
29
|
+
"typescript": "^5.1.3"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"n8n-workflow": "*"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2019",
|
|
4
|
+
"lib": ["ES2019"],
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"typeRoots": ["./node_modules/@types"],
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"nodes/**/*.ts",
|
|
16
|
+
"credentials/**/*.ts",
|
|
17
|
+
"index.ts"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"node_modules",
|
|
21
|
+
"dist"
|
|
22
|
+
]
|
|
23
|
+
}
|