@limetech/n8n-nodes-lime 0.2.9 → 0.3.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/.dockerignore +1 -0
- package/.github/workflows/lint.yml +21 -0
- package/.github/workflows/release.yml +82 -0
- package/.github/workflows/test-and-build.yml +47 -0
- package/.prettierignore +4 -0
- package/.prettierrc.mjs +1 -0
- package/.releaserc.json +34 -0
- package/CHANGELOG.md +74 -0
- package/Dockerfile +21 -0
- package/README.md +4 -0
- package/credentials/FortnoxApi.credentials.ts +61 -0
- package/credentials/LimeCrmApi.credentials.ts +60 -0
- package/docker-compose.yml +46 -0
- package/eslint.config.mjs +27 -0
- package/jest.config.js +11 -0
- package/nodes/fortnox/Fortnox.node.json +18 -0
- package/nodes/fortnox/Fortnox.node.ts +102 -0
- package/nodes/fortnox/FortnoxTrigger.node.json +18 -0
- package/nodes/fortnox/FortnoxTrigger.node.ts +196 -0
- package/nodes/fortnox/commons.ts +94 -0
- package/nodes/fortnox/fortnoxLogo.svg +15 -0
- package/nodes/fortnox/model.ts +25 -0
- package/nodes/fortnox/resources/customers/filterParameters.ts +47 -0
- package/nodes/fortnox/resources/customers/index.ts +57 -0
- package/nodes/fortnox/resources/customers/model.ts +107 -0
- package/nodes/fortnox/resources/customers/operations/create.operation.ts +303 -0
- package/nodes/fortnox/resources/customers/operations/delete.operation.ts +44 -0
- package/nodes/fortnox/resources/customers/operations/get.operation.ts +45 -0
- package/nodes/fortnox/resources/customers/operations/getAll.operation.ts +80 -0
- package/nodes/fortnox/resources/customers/operations/update.operation.ts +278 -0
- package/nodes/fortnox/resources/customers/sortParameters.ts +32 -0
- package/nodes/fortnox/resources/invoice/filterParameters.ts +88 -0
- package/nodes/fortnox/resources/invoice/index.ts +51 -0
- package/nodes/fortnox/resources/invoice/invoiceParameters.ts +214 -0
- package/nodes/fortnox/resources/invoice/model.ts +160 -0
- package/nodes/fortnox/resources/invoice/operations/create.operation.ts +72 -0
- package/nodes/fortnox/resources/invoice/operations/get.operation.ts +45 -0
- package/nodes/fortnox/resources/invoice/operations/getAll.operation.ts +101 -0
- package/nodes/fortnox/resources/invoice/operations/update.operation.ts +74 -0
- package/nodes/fortnox/transport/errorCodes.ts +62 -0
- package/nodes/fortnox/transport/index.ts +98 -0
- package/nodes/lime-crm/LimeCrm.node.json +18 -0
- package/nodes/lime-crm/LimeCrmNode.node.ts +135 -0
- package/nodes/lime-crm/LimeCrmTrigger.node.ts +263 -0
- package/nodes/lime-crm/assets/lime-crm.svg +1 -0
- package/nodes/lime-crm/commons/constants.ts +9 -0
- package/nodes/lime-crm/commons/index.ts +9 -0
- package/nodes/lime-crm/commons/limetype.ts +11 -0
- package/nodes/lime-crm/commons/task.ts +55 -0
- package/nodes/lime-crm/commons/webhook.ts +50 -0
- package/nodes/lime-crm/methods/getEntitiesForErpSystem.ts +11 -0
- package/nodes/lime-crm/methods/getLimeTypeProperties.ts +27 -0
- package/nodes/lime-crm/methods/getLimeTypes.ts +23 -0
- package/nodes/lime-crm/methods/index.ts +3 -0
- package/nodes/lime-crm/resources/erpConnector/index.ts +43 -0
- package/nodes/lime-crm/resources/erpConnector/operations/createOrUpdateObjects.operation.ts +69 -0
- package/nodes/lime-crm/resources/erpConnector/operations/transform.operation.ts +274 -0
- package/nodes/lime-crm/resources/erpConnector/transform.ts +49 -0
- package/nodes/lime-crm/resources/erpConnector/transformers/baseTransformer.ts +18 -0
- package/nodes/lime-crm/resources/erpConnector/transformers/fortnox.ts +201 -0
- package/nodes/lime-crm/resources/erpConnector/transformers/index.ts +1 -0
- package/nodes/lime-crm/resources/limeObject/index.ts +64 -0
- package/nodes/lime-crm/resources/limeObject/operations/create.operation.ts +152 -0
- package/nodes/lime-crm/resources/limeObject/operations/delete.operation.ts +55 -0
- package/nodes/lime-crm/resources/limeObject/operations/get.operation.ts +54 -0
- package/nodes/lime-crm/resources/limeObject/operations/search.operation.ts +99 -0
- package/nodes/lime-crm/resources/limeObject/operations/update.operation.ts +157 -0
- package/nodes/lime-crm/resources/limeType/index.ts +58 -0
- package/nodes/lime-crm/resources/limeType/operations/getProperties.operation.ts +42 -0
- package/nodes/lime-crm/resources/limeType/operations/getType.operation.ts +36 -0
- package/nodes/lime-crm/resources/limeType/operations/listTypes.operation.ts +18 -0
- package/nodes/lime-crm/transport/commons.ts +44 -0
- package/nodes/lime-crm/transport/erpConnector.ts +21 -0
- package/nodes/lime-crm/transport/index.ts +17 -0
- package/nodes/lime-crm/transport/limeobjects.ts +83 -0
- package/nodes/lime-crm/transport/limetypes.ts +68 -0
- package/nodes/lime-crm/transport/task.ts +32 -0
- package/nodes/lime-crm/transport/webhooks.ts +61 -0
- package/nodes/nodeResponse.ts +13 -0
- package/package.json +36 -16
- package/tests/fixtures/fortnox.ts +182 -0
- package/tests/transform.spec.ts +187 -0
- package/tsconfig.json +30 -0
- package/index.js +0 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
|
|
3
|
+
import { startCreateOrUpdateObjectsTask } from '../../../transport';
|
|
4
|
+
import { ERP_CONNECTOR_RESOURCE } from '../../../commons';
|
|
5
|
+
import { LimeCrmData } from '../transform';
|
|
6
|
+
import { waitForTaskCompletion } from '../../../commons/task';
|
|
7
|
+
|
|
8
|
+
export const description = {
|
|
9
|
+
name: 'Create Or Update Objects Task',
|
|
10
|
+
value: 'createOrUpdateObjects',
|
|
11
|
+
description: 'Sync data between ERP and Lime CRM',
|
|
12
|
+
action: 'Create or Update Objects',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const properties: INodeProperties[] = [
|
|
16
|
+
{
|
|
17
|
+
displayName: 'Data',
|
|
18
|
+
name: 'data',
|
|
19
|
+
type: 'json',
|
|
20
|
+
default: '',
|
|
21
|
+
description: 'Provide payload',
|
|
22
|
+
displayOptions: {
|
|
23
|
+
show: {
|
|
24
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
25
|
+
operation: ['createOrUpdateObjects'],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
displayName: 'Poll Interval',
|
|
31
|
+
name: 'pollInterval',
|
|
32
|
+
type: 'number',
|
|
33
|
+
default: 2,
|
|
34
|
+
description: 'Seconds between polls',
|
|
35
|
+
displayOptions: {
|
|
36
|
+
show: {
|
|
37
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
38
|
+
operation: ['createOrUpdateObjects'],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
displayName: 'Timeout',
|
|
44
|
+
name: 'timeout',
|
|
45
|
+
type: 'number',
|
|
46
|
+
default: 60,
|
|
47
|
+
description: 'Max total wait time in seconds',
|
|
48
|
+
displayOptions: {
|
|
49
|
+
show: {
|
|
50
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
51
|
+
operation: ['createOrUpdateObjects'],
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
export async function execute(this: IExecuteFunctions, i: number) {
|
|
58
|
+
const data = this.getNodeParameter('data', i) as LimeCrmData;
|
|
59
|
+
const pollInterval =
|
|
60
|
+
(this.getNodeParameter('pollInterval', i) as number) * 1000;
|
|
61
|
+
const timeout = (this.getNodeParameter('timeout', i) as number) * 1000;
|
|
62
|
+
|
|
63
|
+
const response = await startCreateOrUpdateObjectsTask(this, data);
|
|
64
|
+
|
|
65
|
+
if (!response.success) return response;
|
|
66
|
+
|
|
67
|
+
const taskId = response.data.id;
|
|
68
|
+
return await waitForTaskCompletion(this, taskId, pollInterval, timeout);
|
|
69
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IExecuteFunctions,
|
|
3
|
+
INodeProperties,
|
|
4
|
+
INodePropertyCollection,
|
|
5
|
+
} from 'n8n-workflow';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CustomLimeTypeNames,
|
|
9
|
+
Entity,
|
|
10
|
+
ErpData,
|
|
11
|
+
ErpSystem,
|
|
12
|
+
SearchParameters,
|
|
13
|
+
transform,
|
|
14
|
+
} from '../transform';
|
|
15
|
+
import { ERP_CONNECTOR_RESOURCE } from '../../../commons';
|
|
16
|
+
|
|
17
|
+
export const description = {
|
|
18
|
+
name: 'Transform ERP Data',
|
|
19
|
+
value: 'transformErpData',
|
|
20
|
+
description:
|
|
21
|
+
'Transform and map ERP data into the structure required by Lime CRM',
|
|
22
|
+
action: 'Transform',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type PropertyMappingItem = {
|
|
26
|
+
defaultPropertyName: string;
|
|
27
|
+
customPropertyName: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type Properties = {
|
|
31
|
+
properties: PropertyMappingItem[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type CustomPropertiesMapping = {
|
|
35
|
+
[key in Entity]: Properties;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const defaults: { [key in Entity]: string[] } = {
|
|
39
|
+
invoice: [
|
|
40
|
+
'invoice_number',
|
|
41
|
+
'company',
|
|
42
|
+
'customerid',
|
|
43
|
+
'customer_reference',
|
|
44
|
+
'coworker',
|
|
45
|
+
'invoice_type',
|
|
46
|
+
'invoice_date',
|
|
47
|
+
'invoice_expires',
|
|
48
|
+
'currency',
|
|
49
|
+
'conversionrate',
|
|
50
|
+
'invoice_sum',
|
|
51
|
+
'invoice_vat',
|
|
52
|
+
'invoice_total_sum',
|
|
53
|
+
'invoice_balance',
|
|
54
|
+
'paid',
|
|
55
|
+
'paid_date',
|
|
56
|
+
'invoice_shredded',
|
|
57
|
+
],
|
|
58
|
+
invoicerow: [
|
|
59
|
+
'company',
|
|
60
|
+
'invoice',
|
|
61
|
+
'item',
|
|
62
|
+
'description',
|
|
63
|
+
'units',
|
|
64
|
+
'row_margin',
|
|
65
|
+
'row_value',
|
|
66
|
+
'rowid',
|
|
67
|
+
],
|
|
68
|
+
company: ['erp_id'],
|
|
69
|
+
coworker: ['name'],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function getLimeTypesPropertiesMapping(): INodeProperties[] {
|
|
73
|
+
return Object.keys(defaults).map((key) => ({
|
|
74
|
+
displayName: key,
|
|
75
|
+
name: key,
|
|
76
|
+
type: 'fixedCollection',
|
|
77
|
+
typeOptions: {
|
|
78
|
+
multipleValues: true,
|
|
79
|
+
},
|
|
80
|
+
default: {},
|
|
81
|
+
options: getPropertiesMapping(key as Entity),
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getPropertiesMapping(limeType: Entity): INodePropertyCollection[] {
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
displayName: 'Properties',
|
|
89
|
+
name: 'properties',
|
|
90
|
+
values: [
|
|
91
|
+
{
|
|
92
|
+
displayName: 'Property',
|
|
93
|
+
name: 'defaultPropertyName',
|
|
94
|
+
type: 'options',
|
|
95
|
+
default: '',
|
|
96
|
+
description: 'Name of the property',
|
|
97
|
+
options: defaults[limeType]?.map((property) => ({
|
|
98
|
+
name: property,
|
|
99
|
+
value: property,
|
|
100
|
+
})),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
displayName: 'Custom Property Name',
|
|
104
|
+
name: 'customPropertyName',
|
|
105
|
+
type: 'string',
|
|
106
|
+
default: '',
|
|
107
|
+
description: 'Custom name of the property in your Lime CRM',
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const properties: INodeProperties[] = [
|
|
115
|
+
{
|
|
116
|
+
displayName: 'ERP System',
|
|
117
|
+
name: 'erpSystem',
|
|
118
|
+
type: 'options',
|
|
119
|
+
options: [
|
|
120
|
+
{
|
|
121
|
+
name: 'Fortnox',
|
|
122
|
+
value: 'fortnox',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
required: true,
|
|
126
|
+
default: '',
|
|
127
|
+
description: '',
|
|
128
|
+
displayOptions: {
|
|
129
|
+
show: {
|
|
130
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
131
|
+
operation: ['transformErpData'],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
displayName: 'Entity',
|
|
137
|
+
name: 'entity',
|
|
138
|
+
type: 'options',
|
|
139
|
+
typeOptions: {
|
|
140
|
+
loadOptionsMethod: 'getEntitiesForErpSystem',
|
|
141
|
+
loadOptionsDependsOn: ['erpSystem'],
|
|
142
|
+
},
|
|
143
|
+
required: true,
|
|
144
|
+
default: '',
|
|
145
|
+
description: 'Type of entity to sync',
|
|
146
|
+
displayOptions: {
|
|
147
|
+
show: {
|
|
148
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
149
|
+
operation: ['transformErpData'],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
displayName: 'Search Parameters',
|
|
155
|
+
name: 'searchParameters',
|
|
156
|
+
type: 'collection',
|
|
157
|
+
placeholder: 'Add search criteria',
|
|
158
|
+
default: {},
|
|
159
|
+
options: [
|
|
160
|
+
{
|
|
161
|
+
displayName: 'Search Property',
|
|
162
|
+
name: 'property',
|
|
163
|
+
type: 'string',
|
|
164
|
+
default: '',
|
|
165
|
+
description: 'Property to search the object by',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
displayName: 'Search Value',
|
|
169
|
+
name: 'value',
|
|
170
|
+
type: 'string',
|
|
171
|
+
default: '',
|
|
172
|
+
description: 'Value of the search property',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
displayName: 'Create',
|
|
176
|
+
name: 'create',
|
|
177
|
+
type: 'boolean',
|
|
178
|
+
default: true,
|
|
179
|
+
description: 'Whether to create a new object',
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
displayOptions: {
|
|
183
|
+
show: {
|
|
184
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
185
|
+
operation: ['transformErpData'],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
displayName: 'Custom Lime Type Name',
|
|
191
|
+
name: 'customLimeTypeNames',
|
|
192
|
+
type: 'collection',
|
|
193
|
+
default: {},
|
|
194
|
+
description: 'Optional custom name for the Lime CRM types.',
|
|
195
|
+
displayOptions: {
|
|
196
|
+
show: {
|
|
197
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
198
|
+
operation: ['transformErpData'],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
options: [
|
|
202
|
+
{
|
|
203
|
+
displayName: 'Invoice',
|
|
204
|
+
name: 'invoice',
|
|
205
|
+
type: 'string',
|
|
206
|
+
default: 'invoice',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
displayName: 'Invoice Row',
|
|
210
|
+
name: 'invoicerow',
|
|
211
|
+
type: 'string',
|
|
212
|
+
default: 'invoicerow',
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
displayName: 'Custom Properties Mapping',
|
|
218
|
+
name: 'customPropertiesMapping',
|
|
219
|
+
type: 'collection',
|
|
220
|
+
default: {},
|
|
221
|
+
displayOptions: {
|
|
222
|
+
show: {
|
|
223
|
+
resource: [ERP_CONNECTOR_RESOURCE],
|
|
224
|
+
operation: ['transformErpData'],
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
description: 'Select Lime Type',
|
|
228
|
+
options: getLimeTypesPropertiesMapping(),
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
export async function execute(this: IExecuteFunctions, i: number) {
|
|
233
|
+
const data = this.getInputData(i);
|
|
234
|
+
|
|
235
|
+
const erpSystem = this.getNodeParameter('erpSystem', i) as ErpSystem;
|
|
236
|
+
const entity = this.getNodeParameter('entity', i) as Entity;
|
|
237
|
+
const searchParameters = this.getNodeParameter(
|
|
238
|
+
'searchParameters',
|
|
239
|
+
i
|
|
240
|
+
) as SearchParameters;
|
|
241
|
+
const customLimeTypeNames = this.getNodeParameter(
|
|
242
|
+
'customLimeTypeNames',
|
|
243
|
+
i
|
|
244
|
+
) as CustomLimeTypeNames;
|
|
245
|
+
const customPropertiesMapping = this.getNodeParameter(
|
|
246
|
+
'customPropertiesMapping',
|
|
247
|
+
i
|
|
248
|
+
) as CustomPropertiesMapping;
|
|
249
|
+
|
|
250
|
+
const customPropertiesNames = Object.fromEntries(
|
|
251
|
+
Object.entries(customPropertiesMapping).map(
|
|
252
|
+
([limeType, { properties }]) => [
|
|
253
|
+
limeType,
|
|
254
|
+
Object.fromEntries(
|
|
255
|
+
properties.map(
|
|
256
|
+
({ defaultPropertyName, customPropertyName }) => [
|
|
257
|
+
defaultPropertyName,
|
|
258
|
+
customPropertyName,
|
|
259
|
+
]
|
|
260
|
+
)
|
|
261
|
+
),
|
|
262
|
+
]
|
|
263
|
+
)
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
return transform(
|
|
267
|
+
erpSystem,
|
|
268
|
+
entity,
|
|
269
|
+
data[0].json as ErpData,
|
|
270
|
+
searchParameters,
|
|
271
|
+
customLimeTypeNames,
|
|
272
|
+
customPropertiesNames
|
|
273
|
+
);
|
|
274
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FortnoxTransformer } from './transformers';
|
|
2
|
+
|
|
3
|
+
export type Entity = 'invoice' | 'invoicerow' | 'company' | 'coworker';
|
|
4
|
+
export type ErpSystem = 'fortnox';
|
|
5
|
+
export type ErpData = Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
export type CustomLimeTypeNames = Partial<Record<Entity, string>>;
|
|
8
|
+
|
|
9
|
+
export type CustomPropertiesNames = Partial<
|
|
10
|
+
Record<Entity, Record<string, string>>
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export type SearchParameters = {
|
|
14
|
+
property?: string;
|
|
15
|
+
value?: string | number | boolean;
|
|
16
|
+
create?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type LimeCrmObjectData = {
|
|
20
|
+
[key: string]:
|
|
21
|
+
| LimeCrmData
|
|
22
|
+
| SearchParameters
|
|
23
|
+
| string
|
|
24
|
+
| number
|
|
25
|
+
| boolean
|
|
26
|
+
| null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type LimeCrmData = LimeCrmObjectData[];
|
|
30
|
+
|
|
31
|
+
export function transform(
|
|
32
|
+
erpSystem: ErpSystem,
|
|
33
|
+
entity: Entity,
|
|
34
|
+
data: ErpData,
|
|
35
|
+
searchParameters: SearchParameters,
|
|
36
|
+
customLimeTypeNames?: CustomLimeTypeNames,
|
|
37
|
+
customPropertiesNames?: CustomPropertiesNames
|
|
38
|
+
): LimeCrmData {
|
|
39
|
+
if (erpSystem === 'fortnox') {
|
|
40
|
+
return new FortnoxTransformer().transform(
|
|
41
|
+
entity,
|
|
42
|
+
data,
|
|
43
|
+
searchParameters,
|
|
44
|
+
customLimeTypeNames,
|
|
45
|
+
customPropertiesNames
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`Unsupported ERP system: ${erpSystem}`);
|
|
49
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CustomLimeTypeNames,
|
|
3
|
+
CustomPropertiesNames,
|
|
4
|
+
Entity,
|
|
5
|
+
ErpData,
|
|
6
|
+
LimeCrmData,
|
|
7
|
+
SearchParameters,
|
|
8
|
+
} from '../transform';
|
|
9
|
+
|
|
10
|
+
export abstract class BaseTransformer {
|
|
11
|
+
abstract transform(
|
|
12
|
+
entity: Entity,
|
|
13
|
+
data: ErpData,
|
|
14
|
+
searchParameters: SearchParameters,
|
|
15
|
+
customLimeTypeNames?: CustomLimeTypeNames,
|
|
16
|
+
customPropertiesNames?: CustomPropertiesNames
|
|
17
|
+
): LimeCrmData;
|
|
18
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { BaseTransformer } from './baseTransformer';
|
|
2
|
+
import {
|
|
3
|
+
CustomLimeTypeNames,
|
|
4
|
+
CustomPropertiesNames,
|
|
5
|
+
Entity,
|
|
6
|
+
ErpData,
|
|
7
|
+
LimeCrmData,
|
|
8
|
+
LimeCrmObjectData,
|
|
9
|
+
SearchParameters,
|
|
10
|
+
} from '../transform';
|
|
11
|
+
|
|
12
|
+
export interface FortnoxInvoiceRowData extends ErpData {
|
|
13
|
+
ArticleNumber: string;
|
|
14
|
+
Description: string;
|
|
15
|
+
DeliveredQuantity: string;
|
|
16
|
+
ContributionPercent: string;
|
|
17
|
+
Total: number;
|
|
18
|
+
RowId: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface FortnoxInvoiceData extends ErpData {
|
|
22
|
+
DocumentNumber: string;
|
|
23
|
+
InvoiceType: string;
|
|
24
|
+
InvoiceDate: string;
|
|
25
|
+
DueDate: string;
|
|
26
|
+
Currency: string;
|
|
27
|
+
Net: number;
|
|
28
|
+
TotalVAT: number;
|
|
29
|
+
Total: number;
|
|
30
|
+
Balance: number;
|
|
31
|
+
FinalPayDate: string | null;
|
|
32
|
+
CustomerNumber: string;
|
|
33
|
+
YourReference: string;
|
|
34
|
+
OurReference: string;
|
|
35
|
+
InvoiceRows: FortnoxInvoiceRowData[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class FortnoxTransformer extends BaseTransformer {
|
|
39
|
+
readonly INVOICE_MAPPING: {
|
|
40
|
+
[key: string]: (
|
|
41
|
+
_data: FortnoxInvoiceData,
|
|
42
|
+
_customPropertiesNames?: CustomPropertiesNames
|
|
43
|
+
) => string | number | boolean | object | null;
|
|
44
|
+
} = {
|
|
45
|
+
invoice_number: (_data, _customPropertiesNames) =>
|
|
46
|
+
_data['DocumentNumber'],
|
|
47
|
+
invoice_type: (_data, _customPropertiesNames) => _data['InvoiceType'],
|
|
48
|
+
invoice_date: (_data, _customPropertiesNames) => _data['InvoiceDate'],
|
|
49
|
+
invoice_expires: (_data, _customPropertiesNames) => _data['DueDate'],
|
|
50
|
+
currency: (_data, _customPropertiesNames) => _data['Currency'],
|
|
51
|
+
invoice_sum: (_data, _customPropertiesNames) => _data['Net'],
|
|
52
|
+
invoice_vat: (_data, _customPropertiesNames) => _data['TotalVAT'],
|
|
53
|
+
invoice_total_sum: (_data, _customPropertiesNames) => _data['Total'],
|
|
54
|
+
invoice_balance: (_data, _customPropertiesNames) => _data['Balance'],
|
|
55
|
+
paid: (_data, _customPropertiesNames) => _data['Balance'] === 0,
|
|
56
|
+
paid_date: (_data, _customPropertiesNames) => _data['FinalPayDate'],
|
|
57
|
+
invoice_shredded: (_data, _customPropertiesNames) => false,
|
|
58
|
+
customerid: (_data, _customPropertiesNames) => _data['CustomerNumber'],
|
|
59
|
+
customer_reference: (_data, _customPropertiesNames) =>
|
|
60
|
+
_data['YourReference'],
|
|
61
|
+
company: (_data, _customPropertiesNames) => ({
|
|
62
|
+
_search: {
|
|
63
|
+
property:
|
|
64
|
+
_customPropertiesNames?.company?.['erp_id'] || 'erp_id',
|
|
65
|
+
value: _data['CustomerNumber'],
|
|
66
|
+
create: false,
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
coworker: (_data, _customPropertiesNames) => ({
|
|
70
|
+
_search: {
|
|
71
|
+
property: _customPropertiesNames?.coworker?.['name'] || 'name',
|
|
72
|
+
value: _data['OurReference'],
|
|
73
|
+
create: false,
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
readonly INVOICE_ROW_MAPPING: {
|
|
79
|
+
[key: string]: (
|
|
80
|
+
_data: FortnoxInvoiceRowData,
|
|
81
|
+
_customPropertiesNames?: CustomPropertiesNames
|
|
82
|
+
) => string | number | boolean | object;
|
|
83
|
+
} = {
|
|
84
|
+
company: (_data, _customPropertiesNames) => ({
|
|
85
|
+
_search: {
|
|
86
|
+
property:
|
|
87
|
+
_customPropertiesNames?.company?.['erp_id'] || 'erp_id',
|
|
88
|
+
value: _data['CustomerNumber'],
|
|
89
|
+
create: false,
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
invoice: (_data, _customPropertiesNames) => ({
|
|
93
|
+
_search: {
|
|
94
|
+
property:
|
|
95
|
+
_customPropertiesNames?.invoice?.['invoice_number'] ||
|
|
96
|
+
'invoice_number',
|
|
97
|
+
value: _data['DocumentNumber'],
|
|
98
|
+
create: false,
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
item: (_data, _customPropertiesNames) => _data['ArticleNumber'],
|
|
102
|
+
description: (_data, _customPropertiesNames) => _data['Description'],
|
|
103
|
+
units: (_data, _customPropertiesNames) => +_data['DeliveredQuantity'],
|
|
104
|
+
row_margin: (_data, _customPropertiesNames) =>
|
|
105
|
+
+_data['ContributionPercent'],
|
|
106
|
+
row_value: (_data, _customPropertiesNames) => +_data['Total'],
|
|
107
|
+
rowid: (_data, _customPropertiesNames) => _data['RowId'],
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
transform(
|
|
111
|
+
entity: Entity,
|
|
112
|
+
data: ErpData,
|
|
113
|
+
searchParameters: SearchParameters,
|
|
114
|
+
customLimeTypeNames?: CustomLimeTypeNames,
|
|
115
|
+
customPropertiesNames?: CustomPropertiesNames
|
|
116
|
+
): LimeCrmData {
|
|
117
|
+
if (entity === 'invoice') {
|
|
118
|
+
{
|
|
119
|
+
return this._transformInvoice(
|
|
120
|
+
data as FortnoxInvoiceData,
|
|
121
|
+
searchParameters,
|
|
122
|
+
customLimeTypeNames,
|
|
123
|
+
customPropertiesNames
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
{
|
|
128
|
+
throw new Error(`Unsupported entity type: ${entity}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected _transformInvoice(
|
|
134
|
+
data: FortnoxInvoiceData,
|
|
135
|
+
searchParameters: SearchParameters,
|
|
136
|
+
customLimeTypeNames?: CustomLimeTypeNames,
|
|
137
|
+
customPropertiesNames?: CustomPropertiesNames
|
|
138
|
+
): LimeCrmData {
|
|
139
|
+
const limeCrmData: LimeCrmData = [];
|
|
140
|
+
|
|
141
|
+
const invoice: LimeCrmObjectData = {
|
|
142
|
+
_limetype: customLimeTypeNames?.invoice || 'invoice',
|
|
143
|
+
_search: searchParameters,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
for (const [limeCrmKey, getLimeCrmValue] of Object.entries(
|
|
147
|
+
this.INVOICE_MAPPING
|
|
148
|
+
)) {
|
|
149
|
+
invoice[
|
|
150
|
+
customPropertiesNames?.invoice?.[limeCrmKey] || limeCrmKey
|
|
151
|
+
] = getLimeCrmValue(data, customPropertiesNames);
|
|
152
|
+
}
|
|
153
|
+
limeCrmData.push(invoice);
|
|
154
|
+
|
|
155
|
+
for (const invoiceRow of data['InvoiceRows']) {
|
|
156
|
+
invoiceRow['DocumentNumber'] = data['DocumentNumber'];
|
|
157
|
+
invoiceRow['CustomerNumber'] = data['CustomerNumber'];
|
|
158
|
+
limeCrmData.push(
|
|
159
|
+
...this._transformInvoiceRow(
|
|
160
|
+
invoiceRow,
|
|
161
|
+
{
|
|
162
|
+
property:
|
|
163
|
+
customPropertiesNames?.invoicerow?.['rowid'] ||
|
|
164
|
+
'rowid',
|
|
165
|
+
value: invoiceRow['RowId'],
|
|
166
|
+
create: true,
|
|
167
|
+
},
|
|
168
|
+
customLimeTypeNames,
|
|
169
|
+
customPropertiesNames
|
|
170
|
+
)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return limeCrmData;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
protected _transformInvoiceRow(
|
|
178
|
+
data: FortnoxInvoiceRowData,
|
|
179
|
+
searchParameters: SearchParameters,
|
|
180
|
+
customLimeTypeNames?: CustomLimeTypeNames,
|
|
181
|
+
customPropertiesNames?: CustomPropertiesNames
|
|
182
|
+
): LimeCrmData {
|
|
183
|
+
const limeCrmData: LimeCrmData = [];
|
|
184
|
+
|
|
185
|
+
const invoiceRow: LimeCrmObjectData = {
|
|
186
|
+
_limetype: customLimeTypeNames?.invoicerow || 'invoicerow',
|
|
187
|
+
_search: searchParameters,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
for (const [limeCrmKey, getLimeCrmValue] of Object.entries(
|
|
191
|
+
this.INVOICE_ROW_MAPPING
|
|
192
|
+
)) {
|
|
193
|
+
invoiceRow[
|
|
194
|
+
customPropertiesNames?.invoicerow?.[limeCrmKey] || limeCrmKey
|
|
195
|
+
] = getLimeCrmValue(data, customPropertiesNames);
|
|
196
|
+
}
|
|
197
|
+
limeCrmData.push(invoiceRow);
|
|
198
|
+
|
|
199
|
+
return limeCrmData;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FortnoxTransformer } from './fortnox';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IExecuteFunctions,
|
|
3
|
+
INodeProperties,
|
|
4
|
+
NodePropertyTypes,
|
|
5
|
+
} from 'n8n-workflow';
|
|
6
|
+
|
|
7
|
+
import * as create from './operations/create.operation';
|
|
8
|
+
import * as get from './operations/get.operation';
|
|
9
|
+
import * as update from './operations/update.operation';
|
|
10
|
+
import * as delete_ from './operations/delete.operation';
|
|
11
|
+
import * as search from './operations/search.operation';
|
|
12
|
+
|
|
13
|
+
import { LIMEOBJECT_RESOURCE } from '../../commons';
|
|
14
|
+
|
|
15
|
+
export const limeObjectFields: INodeProperties[] = [
|
|
16
|
+
{
|
|
17
|
+
displayName: 'Operation',
|
|
18
|
+
name: 'operation',
|
|
19
|
+
type: 'options' as NodePropertyTypes,
|
|
20
|
+
noDataExpression: true,
|
|
21
|
+
displayOptions: {
|
|
22
|
+
show: {
|
|
23
|
+
resource: [LIMEOBJECT_RESOURCE],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
options: [
|
|
27
|
+
create.description,
|
|
28
|
+
get.description,
|
|
29
|
+
update.description,
|
|
30
|
+
delete_.description,
|
|
31
|
+
search.description,
|
|
32
|
+
],
|
|
33
|
+
default: 'search',
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
...create.properties,
|
|
37
|
+
...get.properties,
|
|
38
|
+
...update.properties,
|
|
39
|
+
...delete_.properties,
|
|
40
|
+
...search.properties,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
export async function limeObjectOperations(
|
|
44
|
+
this: IExecuteFunctions,
|
|
45
|
+
{ operation, i }: { operation: string; i: number }
|
|
46
|
+
) {
|
|
47
|
+
if (operation === 'create') {
|
|
48
|
+
return await create.execute.call(this, i);
|
|
49
|
+
}
|
|
50
|
+
if (operation === 'get') {
|
|
51
|
+
return await get.execute.call(this, i);
|
|
52
|
+
}
|
|
53
|
+
if (operation === 'update') {
|
|
54
|
+
return await update.execute.call(this, i);
|
|
55
|
+
}
|
|
56
|
+
if (operation === 'delete') {
|
|
57
|
+
return await delete_.execute.call(this, i);
|
|
58
|
+
}
|
|
59
|
+
if (operation === 'search') {
|
|
60
|
+
return await search.execute.call(this, i);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return null;
|
|
64
|
+
}
|