@solution25/n8n-nodes-shopware 1.4.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.
Files changed (156) hide show
  1. package/README.md +80 -0
  2. package/dist/credentials/ShopwareOAuth2Api.credentials.d.ts +16 -0
  3. package/dist/credentials/ShopwareOAuth2Api.credentials.js +78 -0
  4. package/dist/credentials/ShopwareOAuth2Api.credentials.js.map +1 -0
  5. package/dist/nodes/Shopware/Shopware.node.d.ts +4 -0
  6. package/dist/nodes/Shopware/Shopware.node.js +23 -0
  7. package/dist/nodes/Shopware/Shopware.node.js.map +1 -0
  8. package/dist/nodes/Shopware/Shopware.node.json +18 -0
  9. package/dist/nodes/Shopware/test/v1/node/customer/getMany.test.d.ts +1 -0
  10. package/dist/nodes/Shopware/test/v1/node/customer/getMany.test.js +98 -0
  11. package/dist/nodes/Shopware/test/v1/node/customer/getMany.test.js.map +1 -0
  12. package/dist/nodes/Shopware/test/v1/node/helpers.d.ts +6 -0
  13. package/dist/nodes/Shopware/test/v1/node/helpers.js +44 -0
  14. package/dist/nodes/Shopware/test/v1/node/helpers.js.map +1 -0
  15. package/dist/nodes/Shopware/test/v1/node/order/getMany.test.d.ts +1 -0
  16. package/dist/nodes/Shopware/test/v1/node/order/getMany.test.js +111 -0
  17. package/dist/nodes/Shopware/test/v1/node/order/getMany.test.js.map +1 -0
  18. package/dist/nodes/Shopware/test/v1/node/product/getMany.test.d.ts +1 -0
  19. package/dist/nodes/Shopware/test/v1/node/product/getMany.test.js +96 -0
  20. package/dist/nodes/Shopware/test/v1/node/product/getMany.test.js.map +1 -0
  21. package/dist/nodes/Shopware/v1/ShopwareV1.node.d.ts +10 -0
  22. package/dist/nodes/Shopware/v1/ShopwareV1.node.js +23 -0
  23. package/dist/nodes/Shopware/v1/ShopwareV1.node.js.map +1 -0
  24. package/dist/nodes/Shopware/v1/actions/category/Category.resource.d.ts +8 -0
  25. package/dist/nodes/Shopware/v1/actions/category/Category.resource.js +98 -0
  26. package/dist/nodes/Shopware/v1/actions/category/Category.resource.js.map +1 -0
  27. package/dist/nodes/Shopware/v1/actions/category/create.operation.d.ts +27 -0
  28. package/dist/nodes/Shopware/v1/actions/category/create.operation.js +211 -0
  29. package/dist/nodes/Shopware/v1/actions/category/create.operation.js.map +1 -0
  30. package/dist/nodes/Shopware/v1/actions/category/deleteCategory.operation.d.ts +27 -0
  31. package/dist/nodes/Shopware/v1/actions/category/deleteCategory.operation.js +47 -0
  32. package/dist/nodes/Shopware/v1/actions/category/deleteCategory.operation.js.map +1 -0
  33. package/dist/nodes/Shopware/v1/actions/category/fields.d.ts +1 -0
  34. package/dist/nodes/Shopware/v1/actions/category/fields.js +21 -0
  35. package/dist/nodes/Shopware/v1/actions/category/fields.js.map +1 -0
  36. package/dist/nodes/Shopware/v1/actions/category/get.operation.d.ts +27 -0
  37. package/dist/nodes/Shopware/v1/actions/category/get.operation.js +77 -0
  38. package/dist/nodes/Shopware/v1/actions/category/get.operation.js.map +1 -0
  39. package/dist/nodes/Shopware/v1/actions/category/getMany.operation.d.ts +27 -0
  40. package/dist/nodes/Shopware/v1/actions/category/getMany.operation.js +164 -0
  41. package/dist/nodes/Shopware/v1/actions/category/getMany.operation.js.map +1 -0
  42. package/dist/nodes/Shopware/v1/actions/category/types.d.ts +19 -0
  43. package/dist/nodes/Shopware/v1/actions/category/types.js +3 -0
  44. package/dist/nodes/Shopware/v1/actions/category/types.js.map +1 -0
  45. package/dist/nodes/Shopware/v1/actions/category/update.operation.d.ts +27 -0
  46. package/dist/nodes/Shopware/v1/actions/category/update.operation.js +120 -0
  47. package/dist/nodes/Shopware/v1/actions/category/update.operation.js.map +1 -0
  48. package/dist/nodes/Shopware/v1/actions/customer/Customer.resource.d.ts +8 -0
  49. package/dist/nodes/Shopware/v1/actions/customer/Customer.resource.js +98 -0
  50. package/dist/nodes/Shopware/v1/actions/customer/Customer.resource.js.map +1 -0
  51. package/dist/nodes/Shopware/v1/actions/customer/create.operation.d.ts +27 -0
  52. package/dist/nodes/Shopware/v1/actions/customer/create.operation.js +301 -0
  53. package/dist/nodes/Shopware/v1/actions/customer/create.operation.js.map +1 -0
  54. package/dist/nodes/Shopware/v1/actions/customer/deleteCustomer.operation.d.ts +27 -0
  55. package/dist/nodes/Shopware/v1/actions/customer/deleteCustomer.operation.js +47 -0
  56. package/dist/nodes/Shopware/v1/actions/customer/deleteCustomer.operation.js.map +1 -0
  57. package/dist/nodes/Shopware/v1/actions/customer/fields.d.ts +4 -0
  58. package/dist/nodes/Shopware/v1/actions/customer/fields.js +30 -0
  59. package/dist/nodes/Shopware/v1/actions/customer/fields.js.map +1 -0
  60. package/dist/nodes/Shopware/v1/actions/customer/get.operation.d.ts +27 -0
  61. package/dist/nodes/Shopware/v1/actions/customer/get.operation.js +77 -0
  62. package/dist/nodes/Shopware/v1/actions/customer/get.operation.js.map +1 -0
  63. package/dist/nodes/Shopware/v1/actions/customer/getMany.operation.d.ts +27 -0
  64. package/dist/nodes/Shopware/v1/actions/customer/getMany.operation.js +319 -0
  65. package/dist/nodes/Shopware/v1/actions/customer/getMany.operation.js.map +1 -0
  66. package/dist/nodes/Shopware/v1/actions/customer/types.d.ts +54 -0
  67. package/dist/nodes/Shopware/v1/actions/customer/types.js +3 -0
  68. package/dist/nodes/Shopware/v1/actions/customer/types.js.map +1 -0
  69. package/dist/nodes/Shopware/v1/actions/customer/update.operation.d.ts +27 -0
  70. package/dist/nodes/Shopware/v1/actions/customer/update.operation.js +287 -0
  71. package/dist/nodes/Shopware/v1/actions/customer/update.operation.js.map +1 -0
  72. package/dist/nodes/Shopware/v1/actions/fields.d.ts +5 -0
  73. package/dist/nodes/Shopware/v1/actions/fields.js +26 -0
  74. package/dist/nodes/Shopware/v1/actions/fields.js.map +1 -0
  75. package/dist/nodes/Shopware/v1/actions/node.type.d.ts +9 -0
  76. package/dist/nodes/Shopware/v1/actions/node.type.js +3 -0
  77. package/dist/nodes/Shopware/v1/actions/node.type.js.map +1 -0
  78. package/dist/nodes/Shopware/v1/actions/order/Order.resource.d.ts +8 -0
  79. package/dist/nodes/Shopware/v1/actions/order/Order.resource.js +98 -0
  80. package/dist/nodes/Shopware/v1/actions/order/Order.resource.js.map +1 -0
  81. package/dist/nodes/Shopware/v1/actions/order/create.operation.d.ts +27 -0
  82. package/dist/nodes/Shopware/v1/actions/order/create.operation.js +861 -0
  83. package/dist/nodes/Shopware/v1/actions/order/create.operation.js.map +1 -0
  84. package/dist/nodes/Shopware/v1/actions/order/deleteOrder.operation.d.ts +27 -0
  85. package/dist/nodes/Shopware/v1/actions/order/deleteOrder.operation.js +47 -0
  86. package/dist/nodes/Shopware/v1/actions/order/deleteOrder.operation.js.map +1 -0
  87. package/dist/nodes/Shopware/v1/actions/order/fields.d.ts +2 -0
  88. package/dist/nodes/Shopware/v1/actions/order/fields.js +25 -0
  89. package/dist/nodes/Shopware/v1/actions/order/fields.js.map +1 -0
  90. package/dist/nodes/Shopware/v1/actions/order/get.operation.d.ts +27 -0
  91. package/dist/nodes/Shopware/v1/actions/order/get.operation.js +77 -0
  92. package/dist/nodes/Shopware/v1/actions/order/get.operation.js.map +1 -0
  93. package/dist/nodes/Shopware/v1/actions/order/getMany.operation.d.ts +27 -0
  94. package/dist/nodes/Shopware/v1/actions/order/getMany.operation.js +226 -0
  95. package/dist/nodes/Shopware/v1/actions/order/getMany.operation.js.map +1 -0
  96. package/dist/nodes/Shopware/v1/actions/order/types.d.ts +171 -0
  97. package/dist/nodes/Shopware/v1/actions/order/types.js +3 -0
  98. package/dist/nodes/Shopware/v1/actions/order/types.js.map +1 -0
  99. package/dist/nodes/Shopware/v1/actions/order/update.operation.d.ts +27 -0
  100. package/dist/nodes/Shopware/v1/actions/order/update.operation.js +723 -0
  101. package/dist/nodes/Shopware/v1/actions/order/update.operation.js.map +1 -0
  102. package/dist/nodes/Shopware/v1/actions/product/Product.resource.d.ts +8 -0
  103. package/dist/nodes/Shopware/v1/actions/product/Product.resource.js +98 -0
  104. package/dist/nodes/Shopware/v1/actions/product/Product.resource.js.map +1 -0
  105. package/dist/nodes/Shopware/v1/actions/product/create.operation.d.ts +27 -0
  106. package/dist/nodes/Shopware/v1/actions/product/create.operation.js +335 -0
  107. package/dist/nodes/Shopware/v1/actions/product/create.operation.js.map +1 -0
  108. package/dist/nodes/Shopware/v1/actions/product/deleteProduct.operation.d.ts +27 -0
  109. package/dist/nodes/Shopware/v1/actions/product/deleteProduct.operation.js +47 -0
  110. package/dist/nodes/Shopware/v1/actions/product/deleteProduct.operation.js.map +1 -0
  111. package/dist/nodes/Shopware/v1/actions/product/fields.d.ts +7 -0
  112. package/dist/nodes/Shopware/v1/actions/product/fields.js +33 -0
  113. package/dist/nodes/Shopware/v1/actions/product/fields.js.map +1 -0
  114. package/dist/nodes/Shopware/v1/actions/product/get.operation.d.ts +27 -0
  115. package/dist/nodes/Shopware/v1/actions/product/get.operation.js +77 -0
  116. package/dist/nodes/Shopware/v1/actions/product/get.operation.js.map +1 -0
  117. package/dist/nodes/Shopware/v1/actions/product/getMany.operation.d.ts +27 -0
  118. package/dist/nodes/Shopware/v1/actions/product/getMany.operation.js +319 -0
  119. package/dist/nodes/Shopware/v1/actions/product/getMany.operation.js.map +1 -0
  120. package/dist/nodes/Shopware/v1/actions/product/types.d.ts +66 -0
  121. package/dist/nodes/Shopware/v1/actions/product/types.js +3 -0
  122. package/dist/nodes/Shopware/v1/actions/product/types.js.map +1 -0
  123. package/dist/nodes/Shopware/v1/actions/product/update.operation.d.ts +27 -0
  124. package/dist/nodes/Shopware/v1/actions/product/update.operation.js +287 -0
  125. package/dist/nodes/Shopware/v1/actions/product/update.operation.js.map +1 -0
  126. package/dist/nodes/Shopware/v1/actions/router.d.ts +2 -0
  127. package/dist/nodes/Shopware/v1/actions/router.js +78 -0
  128. package/dist/nodes/Shopware/v1/actions/router.js.map +1 -0
  129. package/dist/nodes/Shopware/v1/actions/types.d.ts +97 -0
  130. package/dist/nodes/Shopware/v1/actions/types.js +3 -0
  131. package/dist/nodes/Shopware/v1/actions/types.js.map +1 -0
  132. package/dist/nodes/Shopware/v1/actions/versionDescription.d.ts +2 -0
  133. package/dist/nodes/Shopware/v1/actions/versionDescription.js +93 -0
  134. package/dist/nodes/Shopware/v1/actions/versionDescription.js.map +1 -0
  135. package/dist/nodes/Shopware/v1/helpers/handlers.d.ts +14 -0
  136. package/dist/nodes/Shopware/v1/helpers/handlers.js +261 -0
  137. package/dist/nodes/Shopware/v1/helpers/handlers.js.map +1 -0
  138. package/dist/nodes/Shopware/v1/helpers/interfaces.d.ts +1 -0
  139. package/dist/nodes/Shopware/v1/helpers/interfaces.js +3 -0
  140. package/dist/nodes/Shopware/v1/helpers/interfaces.js.map +1 -0
  141. package/dist/nodes/Shopware/v1/helpers/utils.d.ts +16 -0
  142. package/dist/nodes/Shopware/v1/helpers/utils.js +354 -0
  143. package/dist/nodes/Shopware/v1/helpers/utils.js.map +1 -0
  144. package/dist/nodes/Shopware/v1/methods/index.d.ts +1 -0
  145. package/dist/nodes/Shopware/v1/methods/index.js +38 -0
  146. package/dist/nodes/Shopware/v1/methods/index.js.map +1 -0
  147. package/dist/nodes/Shopware/v1/methods/loadOptions.d.ts +18 -0
  148. package/dist/nodes/Shopware/v1/methods/loadOptions.js +143 -0
  149. package/dist/nodes/Shopware/v1/methods/loadOptions.js.map +1 -0
  150. package/dist/nodes/Shopware/v1/transport/index.d.ts +2 -0
  151. package/dist/nodes/Shopware/v1/transport/index.js +25 -0
  152. package/dist/nodes/Shopware/v1/transport/index.js.map +1 -0
  153. package/dist/package.json +63 -0
  154. package/dist/shopware.png +0 -0
  155. package/dist/tsconfig.tsbuildinfo +1 -0
  156. package/package.json +63 -0
@@ -0,0 +1,723 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.description = void 0;
4
+ exports.execute = execute;
5
+ const n8n_workflow_1 = require("n8n-workflow");
6
+ const transport_1 = require("../../transport");
7
+ const fields_1 = require("./fields");
8
+ const utils_1 = require("../../helpers/utils");
9
+ const properties = [
10
+ {
11
+ displayName: 'Order ID',
12
+ name: 'id',
13
+ type: 'string',
14
+ default: '',
15
+ placeholder: 'e.g. 2a88d9b59d474...',
16
+ required: true,
17
+ description: 'ID of the order to update. You can find the ID in the URL when viewing the order in Shopware Admin (e.g. https://your-domain.com/admin#/sw/order/detail/<orderId>).',
18
+ },
19
+ {
20
+ displayName: 'Update Fields',
21
+ name: 'updateFields',
22
+ type: 'collection',
23
+ placeholder: 'Add Field',
24
+ default: {},
25
+ options: [
26
+ {
27
+ displayName: 'Billing Address',
28
+ name: 'billingAddressUi',
29
+ placeholder: 'Add Billing Address',
30
+ type: 'fixedCollection',
31
+ default: {},
32
+ typeOptions: {
33
+ multipleValues: false,
34
+ },
35
+ description: 'Add customer billing address',
36
+ options: [
37
+ {
38
+ name: 'billingAddressValues',
39
+ displayName: 'Billing Address',
40
+ values: [
41
+ {
42
+ displayName: 'Country',
43
+ name: 'country',
44
+ type: 'options',
45
+ typeOptions: {
46
+ loadOptionsMethod: 'getCountries',
47
+ },
48
+ required: true,
49
+ default: '',
50
+ description: 'Country of the billing address',
51
+ },
52
+ {
53
+ displayName: 'First Name',
54
+ name: 'firstName',
55
+ type: 'string',
56
+ required: true,
57
+ default: '',
58
+ description: 'Customer first name',
59
+ },
60
+ {
61
+ displayName: 'Last Name',
62
+ name: 'lastName',
63
+ type: 'string',
64
+ required: true,
65
+ default: '',
66
+ description: 'Customer last name',
67
+ },
68
+ {
69
+ displayName: 'City',
70
+ name: 'city',
71
+ type: 'string',
72
+ required: true,
73
+ default: '',
74
+ description: 'Billing address city',
75
+ },
76
+ {
77
+ displayName: 'Street',
78
+ name: 'street',
79
+ type: 'string',
80
+ required: true,
81
+ default: '',
82
+ description: 'Billing address street',
83
+ },
84
+ ],
85
+ },
86
+ ],
87
+ },
88
+ {
89
+ displayName: 'Deliveries',
90
+ name: 'deliveries',
91
+ placeholder: 'Add Delivery',
92
+ type: 'fixedCollection',
93
+ typeOptions: {
94
+ multipleValues: true,
95
+ },
96
+ description: 'Order deliveries',
97
+ default: {},
98
+ options: [
99
+ {
100
+ name: 'delivery',
101
+ displayName: 'Delivery',
102
+ values: [
103
+ {
104
+ displayName: 'Shipping Method',
105
+ name: 'shippingMethod',
106
+ type: 'options',
107
+ typeOptions: {
108
+ loadOptionsMethod: 'getShippingMethods',
109
+ },
110
+ required: true,
111
+ default: '',
112
+ description: 'Delivery shipping method',
113
+ },
114
+ {
115
+ displayName: 'State',
116
+ name: 'state',
117
+ type: 'options',
118
+ typeOptions: {
119
+ loadOptionsMethod: 'getDeliveryStates',
120
+ },
121
+ required: true,
122
+ default: '',
123
+ description: 'State of the delivery (e.g. Shipped)',
124
+ },
125
+ {
126
+ displayName: 'Use Customer Shipping Address',
127
+ name: 'customerShippingAddress',
128
+ type: 'boolean',
129
+ default: true,
130
+ description: 'Whether to use the customer shipping address',
131
+ },
132
+ {
133
+ displayName: 'Address',
134
+ name: 'addressUi',
135
+ placeholder: 'Add Address',
136
+ type: 'fixedCollection',
137
+ default: {},
138
+ typeOptions: {
139
+ multipleValues: false,
140
+ },
141
+ displayOptions: {
142
+ show: {
143
+ customerShippingAddress: [false],
144
+ },
145
+ },
146
+ description: 'Add delivery shipping address',
147
+ options: [
148
+ {
149
+ name: 'addressValues',
150
+ displayName: 'Address',
151
+ values: [
152
+ {
153
+ displayName: 'Country',
154
+ name: 'country',
155
+ type: 'options',
156
+ typeOptions: {
157
+ loadOptionsMethod: 'getCountries',
158
+ },
159
+ required: true,
160
+ default: '',
161
+ description: 'Country of the shippng address',
162
+ },
163
+ {
164
+ displayName: 'First Name',
165
+ name: 'firstName',
166
+ type: 'string',
167
+ required: true,
168
+ default: '',
169
+ description: 'Customer first name',
170
+ },
171
+ {
172
+ displayName: 'Last Name',
173
+ name: 'lastName',
174
+ type: 'string',
175
+ required: true,
176
+ default: '',
177
+ description: 'Customer last name',
178
+ },
179
+ {
180
+ displayName: 'City',
181
+ name: 'city',
182
+ type: 'string',
183
+ required: true,
184
+ default: '',
185
+ description: 'Shipping address city',
186
+ },
187
+ {
188
+ displayName: 'Street',
189
+ name: 'street',
190
+ type: 'string',
191
+ required: true,
192
+ default: '',
193
+ description: 'Shipping address street',
194
+ },
195
+ ],
196
+ },
197
+ ],
198
+ },
199
+ ],
200
+ },
201
+ ],
202
+ },
203
+ {
204
+ displayName: 'Line Items',
205
+ name: 'lineItems',
206
+ placeholder: 'Add Line Item',
207
+ type: 'fixedCollection',
208
+ typeOptions: {
209
+ multipleValues: true,
210
+ },
211
+ description: 'Order line items',
212
+ default: {},
213
+ options: [
214
+ {
215
+ name: 'lineItem',
216
+ displayName: 'Line Item',
217
+ values: [
218
+ {
219
+ displayName: 'Product Number',
220
+ name: 'productNumber',
221
+ type: 'string',
222
+ required: true,
223
+ default: '',
224
+ placeholder: 'e.g. P10001',
225
+ description: 'Line item product number',
226
+ },
227
+ {
228
+ displayName: 'Quantity',
229
+ name: 'quantity',
230
+ type: 'number',
231
+ typeOptions: {
232
+ maxValue: 999000000,
233
+ minValue: 0,
234
+ },
235
+ required: true,
236
+ default: 1,
237
+ placeholder: 'e.g. 5',
238
+ description: 'Line item quantity',
239
+ },
240
+ ],
241
+ },
242
+ ],
243
+ },
244
+ {
245
+ displayName: 'Shipping Address',
246
+ name: 'shippingAddressUi',
247
+ placeholder: 'Add Shipping Address',
248
+ type: 'fixedCollection',
249
+ default: {},
250
+ typeOptions: {
251
+ multipleValues: false,
252
+ },
253
+ description: 'Add customer shipping address',
254
+ options: [
255
+ {
256
+ name: 'shippingAddressValues',
257
+ displayName: 'Shipping Address',
258
+ values: [
259
+ {
260
+ displayName: 'Country',
261
+ name: 'country',
262
+ type: 'options',
263
+ typeOptions: {
264
+ loadOptionsMethod: 'getCountries',
265
+ },
266
+ required: true,
267
+ default: '',
268
+ description: 'Country of the shipping address',
269
+ },
270
+ {
271
+ displayName: 'First Name',
272
+ name: 'firstName',
273
+ type: 'string',
274
+ required: true,
275
+ default: '',
276
+ description: 'Customer first name',
277
+ },
278
+ {
279
+ displayName: 'Last Name',
280
+ name: 'lastName',
281
+ type: 'string',
282
+ required: true,
283
+ default: '',
284
+ description: 'Customer last name',
285
+ },
286
+ {
287
+ displayName: 'City',
288
+ name: 'city',
289
+ type: 'string',
290
+ required: true,
291
+ default: '',
292
+ description: 'Shipping address city',
293
+ },
294
+ {
295
+ displayName: 'Street',
296
+ name: 'street',
297
+ type: 'string',
298
+ required: true,
299
+ default: '',
300
+ description: 'Shipping address street',
301
+ },
302
+ ],
303
+ },
304
+ ],
305
+ },
306
+ {
307
+ displayName: 'State',
308
+ name: 'state',
309
+ type: 'options',
310
+ options: [
311
+ {
312
+ name: 'Cancel',
313
+ value: 'cancel',
314
+ },
315
+ {
316
+ name: 'Complete',
317
+ value: 'complete',
318
+ },
319
+ {
320
+ name: 'None',
321
+ value: '',
322
+ },
323
+ {
324
+ name: 'Process',
325
+ value: 'process',
326
+ },
327
+ {
328
+ name: 'Reopen',
329
+ value: 'reopen',
330
+ },
331
+ ],
332
+ default: '',
333
+ description: 'Choose the order state from the list',
334
+ },
335
+ {
336
+ displayName: 'Transactions',
337
+ name: 'transactions',
338
+ placeholder: 'Add Transaction',
339
+ type: 'fixedCollection',
340
+ typeOptions: {
341
+ multipleValues: true,
342
+ },
343
+ description: 'Order transactions',
344
+ default: {},
345
+ options: [
346
+ {
347
+ name: 'transaction',
348
+ displayName: 'Transaction',
349
+ values: [
350
+ {
351
+ displayName: 'Payment Method',
352
+ name: 'paymentMethod',
353
+ type: 'options',
354
+ typeOptions: {
355
+ loadOptionsMethod: 'getPaymentMethods',
356
+ },
357
+ required: true,
358
+ default: '',
359
+ description: 'Transaction payment method',
360
+ },
361
+ {
362
+ displayName: 'State',
363
+ name: 'state',
364
+ type: 'options',
365
+ typeOptions: {
366
+ loadOptionsMethod: 'getTransactionStates',
367
+ },
368
+ required: true,
369
+ default: '',
370
+ description: 'State of the transaction (e.g. Paid)',
371
+ },
372
+ ],
373
+ },
374
+ ],
375
+ },
376
+ ],
377
+ },
378
+ ];
379
+ const displayOptions = {
380
+ show: {
381
+ resource: ['order'],
382
+ operation: ['update'],
383
+ },
384
+ };
385
+ exports.description = (0, n8n_workflow_1.updateDisplayOptions)(displayOptions, properties);
386
+ async function execute(items) {
387
+ var _a, _b, _c, _d, _e;
388
+ const returnData = [];
389
+ for (let i = 0; i < items.length; i++) {
390
+ try {
391
+ const id = this.getNodeParameter('id', i);
392
+ const searchPrevOrderBody = {
393
+ filter: [{ type: 'equals', field: 'id', value: id }],
394
+ associations: {
395
+ currency: {},
396
+ },
397
+ };
398
+ const prevOrder = (await transport_1.apiRequest.call(this, 'POST', `/search/order`, searchPrevOrderBody)).data[0];
399
+ if (!prevOrder) {
400
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Order does not exist', {
401
+ description: 'There is no order with id ' + id,
402
+ itemIndex: i,
403
+ });
404
+ }
405
+ const { state: orderState, ...updateFields } = this.getNodeParameter('updateFields', i);
406
+ const { currency: currencyData, shippingCosts: shippingData, orderCustomer: prevOrderCustomer, ...previousOrderData } = prevOrder;
407
+ const customerData = {};
408
+ const customerBillingAddress = (_a = updateFields.billingAddressUi) === null || _a === void 0 ? void 0 : _a.billingAddressValues;
409
+ const customerShippingAddress = (_b = updateFields.shippingAddressUi) === null || _b === void 0 ? void 0 : _b.shippingAddressValues;
410
+ if (customerBillingAddress) {
411
+ const prePaymentStates = await utils_1.getPrePaymentOrderStates.call(this);
412
+ if (prePaymentStates.includes(previousOrderData.stateId)) {
413
+ customerData.billingAddress = {
414
+ id: (0, utils_1.uuidv7)(),
415
+ countryId: customerBillingAddress.country,
416
+ firstName: customerBillingAddress.firstName,
417
+ lastName: customerBillingAddress.lastName,
418
+ city: customerBillingAddress.city,
419
+ street: customerBillingAddress.street,
420
+ };
421
+ }
422
+ }
423
+ if (customerShippingAddress) {
424
+ customerData.shippingAddress = {
425
+ id: (0, utils_1.uuidv7)(),
426
+ countryId: customerShippingAddress.country,
427
+ firstName: customerShippingAddress.firstName,
428
+ lastName: customerShippingAddress.lastName,
429
+ city: customerShippingAddress.city,
430
+ street: customerShippingAddress.street,
431
+ };
432
+ }
433
+ const nodeLineItems = (_c = updateFields.lineItems) === null || _c === void 0 ? void 0 : _c.lineItem;
434
+ let transactions = [];
435
+ const nodeTransactions = (_d = updateFields.transactions) === null || _d === void 0 ? void 0 : _d.transaction;
436
+ let lineItems = [];
437
+ let price = null;
438
+ if (nodeLineItems) {
439
+ lineItems = await Promise.all(nodeLineItems.map(async (lineItem) => {
440
+ const { identifier, productId, label, states, unitPrice, taxRate } = await utils_1.getLineItemData.call(this, lineItem.productNumber, currencyData.id, i);
441
+ const quantity = lineItem.quantity;
442
+ const totalPrice = unitPrice * quantity;
443
+ const tax = totalPrice * (taxRate / 100);
444
+ const taxPrice = totalPrice + tax;
445
+ const price = {
446
+ unitPrice,
447
+ totalPrice,
448
+ quantity,
449
+ calculatedTaxes: [
450
+ {
451
+ tax,
452
+ taxRate,
453
+ price: taxPrice,
454
+ },
455
+ ],
456
+ taxRules: [
457
+ {
458
+ taxRate,
459
+ percentage: 100,
460
+ },
461
+ ],
462
+ };
463
+ return {
464
+ identifier,
465
+ productId,
466
+ quantity,
467
+ label,
468
+ states,
469
+ price,
470
+ };
471
+ }));
472
+ const defaultTaxRate = await utils_1.getDefaultTaxRate.call(this);
473
+ const totalPrice = lineItems.reduce((acc, item) => acc + item.price.totalPrice, 0) +
474
+ previousOrderData.amountNet;
475
+ const orderTax = totalPrice * (defaultTaxRate / 100);
476
+ const taxPrice = totalPrice + orderTax;
477
+ const quantity = lineItems.reduce((acc, item) => acc + item.quantity, 0);
478
+ price = {
479
+ netPrice: totalPrice,
480
+ totalPrice: taxPrice,
481
+ calculatedTaxes: [
482
+ {
483
+ tax: orderTax,
484
+ taxRate: defaultTaxRate,
485
+ price: taxPrice,
486
+ },
487
+ ],
488
+ taxRules: [
489
+ {
490
+ taxRate: defaultTaxRate,
491
+ percentage: 100,
492
+ },
493
+ ],
494
+ positionPrice: totalPrice,
495
+ rawTotal: totalPrice,
496
+ taxStatus: 'gross',
497
+ };
498
+ if (nodeTransactions && nodeTransactions.length > 0) {
499
+ transactions = nodeTransactions.map((transaction) => {
500
+ const amount = {
501
+ unitPrice: totalPrice,
502
+ totalPrice: taxPrice,
503
+ quantity: quantity,
504
+ calculatedTaxes: [
505
+ {
506
+ tax: orderTax,
507
+ taxRate: defaultTaxRate,
508
+ price: taxPrice,
509
+ },
510
+ ],
511
+ taxRules: [
512
+ {
513
+ taxRate: defaultTaxRate,
514
+ percentage: 100,
515
+ },
516
+ ],
517
+ };
518
+ return {
519
+ paymentMethodId: transaction.paymentMethod,
520
+ stateId: transaction.state,
521
+ amount,
522
+ };
523
+ });
524
+ }
525
+ }
526
+ if (!nodeLineItems && nodeTransactions) {
527
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Missing line items for transaction', {
528
+ description: 'Line items are required for order transactions',
529
+ itemIndex: i,
530
+ });
531
+ }
532
+ const addresses = [];
533
+ if (customerShippingAddress && customerData.shippingAddress) {
534
+ addresses.push({
535
+ id: customerData.shippingAddress.id,
536
+ countryId: customerData.shippingAddress.countryId,
537
+ firstName: customerData.shippingAddress.firstName,
538
+ lastName: customerData.shippingAddress.lastName,
539
+ city: customerData.shippingAddress.city,
540
+ street: customerData.shippingAddress.street,
541
+ });
542
+ }
543
+ let deliveries = [];
544
+ const nodeDeliveries = (_e = updateFields.deliveries) === null || _e === void 0 ? void 0 : _e.delivery;
545
+ let shippingCosts = null;
546
+ if (nodeDeliveries && nodeDeliveries.length > 0) {
547
+ deliveries = await Promise.all(nodeDeliveries.map(async (delivery) => {
548
+ let shippingOrderAddressId;
549
+ if (delivery.customerShippingAddress) {
550
+ if (addresses.length > 0) {
551
+ shippingOrderAddressId = addresses[0].id;
552
+ }
553
+ else {
554
+ shippingOrderAddressId = (await utils_1.getCustomerByNumber.call(this, prevOrderCustomer.customerNumber, i)).defaultShippingAddressId;
555
+ }
556
+ }
557
+ else {
558
+ const address = delivery.addressUi.addressValues;
559
+ if (!address) {
560
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Missing shipping address', {
561
+ description: 'A shipping address must be provided for the selected delivery if not using the customer one',
562
+ itemIndex: i,
563
+ });
564
+ }
565
+ for (const key in address) {
566
+ if (address[key] === '') {
567
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Missing required value for shipping address', {
568
+ description: `Shipping address ${key} must be a valid value.`,
569
+ itemIndex: i,
570
+ });
571
+ }
572
+ }
573
+ shippingOrderAddressId = (0, utils_1.uuidv7)();
574
+ addresses.push({
575
+ id: shippingOrderAddressId,
576
+ countryId: address.country,
577
+ firstName: address.firstName,
578
+ lastName: address.lastName,
579
+ city: address.city,
580
+ street: address.street,
581
+ });
582
+ }
583
+ const { ['unitPrice']: shippingPrice, ['taxRate']: shippingTaxRate } = await utils_1.getShippingMethodData.call(this, delivery.shippingMethod, currencyData.id);
584
+ const deliveryTime = await utils_1.getShippingDeliveryTime.call(this, delivery.shippingMethod);
585
+ const shippingTax = shippingPrice * (shippingTaxRate / 100);
586
+ const shippingTaxPrice = shippingPrice + shippingTax;
587
+ const shippingCosts = {
588
+ unitPrice: shippingPrice,
589
+ totalPrice: shippingPrice,
590
+ quantity: 1,
591
+ calculatedTaxes: [
592
+ {
593
+ tax: shippingTax,
594
+ taxRate: shippingTaxRate,
595
+ price: shippingTaxPrice,
596
+ },
597
+ ],
598
+ taxRules: [
599
+ {
600
+ taxRate: shippingTaxRate,
601
+ percentage: 100,
602
+ },
603
+ ],
604
+ };
605
+ const shippingDateEarliest = new Date();
606
+ const shippingDateLatest = new Date();
607
+ switch (deliveryTime.unit) {
608
+ case 'hour':
609
+ shippingDateEarliest.setHours(shippingDateEarliest.getHours() + deliveryTime.min);
610
+ shippingDateLatest.setHours(shippingDateLatest.getHours() + deliveryTime.max);
611
+ break;
612
+ case 'day':
613
+ shippingDateEarliest.setDate(shippingDateEarliest.getDate() + deliveryTime.min);
614
+ shippingDateLatest.setDate(shippingDateLatest.getDate() + deliveryTime.max);
615
+ break;
616
+ case 'week':
617
+ shippingDateEarliest.setDate(shippingDateEarliest.getDate() + deliveryTime.min * 7);
618
+ shippingDateLatest.setDate(shippingDateLatest.getDate() + deliveryTime.max * 7);
619
+ break;
620
+ }
621
+ return {
622
+ shippingOrderAddressId,
623
+ shippingMethodId: delivery.shippingMethod,
624
+ stateId: delivery.state,
625
+ shippingDateEarliest,
626
+ shippingDateLatest,
627
+ shippingCosts,
628
+ };
629
+ }));
630
+ const deliveriesUnitPrice = deliveries.reduce((acc, delivery) => acc + delivery.shippingCosts.unitPrice, 0) +
631
+ shippingData.unitPrice;
632
+ const deliveriesTax = deliveries.reduce((acc, delivery) => acc + delivery.shippingCosts.calculatedTaxes[0].tax, 0) + shippingData.calculatedTaxes[0].tax;
633
+ const deliveriesTaxRate = deliveries[0].shippingCosts.taxRules[0].taxRate;
634
+ const deliveriesTaxPrice = deliveriesUnitPrice + deliveriesTax;
635
+ shippingCosts = {
636
+ unitPrice: deliveriesUnitPrice,
637
+ totalPrice: deliveriesUnitPrice,
638
+ quantity: 1,
639
+ calculatedTaxes: [
640
+ {
641
+ tax: deliveriesTax,
642
+ taxRate: deliveriesTaxRate,
643
+ price: deliveriesTaxPrice,
644
+ },
645
+ ],
646
+ taxRules: [
647
+ {
648
+ taxRate: deliveriesTaxRate,
649
+ percentage: 100,
650
+ },
651
+ ],
652
+ };
653
+ }
654
+ let serializedBillingAddress = null;
655
+ if (customerData.billingAddress) {
656
+ serializedBillingAddress = {
657
+ id: customerData.billingAddress.id,
658
+ countryId: customerData.billingAddress.countryId,
659
+ firstName: customerData.billingAddress.firstName,
660
+ lastName: customerData.billingAddress.lastName,
661
+ city: customerData.billingAddress.city,
662
+ street: customerData.billingAddress.street,
663
+ };
664
+ }
665
+ const updateBody = {
666
+ billingAddressId: customerData.billingAddress ? customerData.billingAddress.id : null,
667
+ billingAddress: serializedBillingAddress,
668
+ lineItems,
669
+ price,
670
+ shippingCosts,
671
+ transactions,
672
+ deliveries,
673
+ addresses,
674
+ };
675
+ const searchBody = {
676
+ fields: fields_1.orderFields,
677
+ includes: {
678
+ order: fields_1.orderFields,
679
+ },
680
+ filter: [{ type: 'equals', field: 'id', value: id }],
681
+ };
682
+ for (const key in updateBody) {
683
+ const typedKey = key;
684
+ if (Array.isArray(updateBody[typedKey]) &&
685
+ updateBody[typedKey].length === 0) {
686
+ delete updateBody[typedKey];
687
+ }
688
+ else if (updateBody[typedKey] === '' || updateBody[typedKey] === null) {
689
+ delete updateBody[typedKey];
690
+ }
691
+ }
692
+ if (orderState) {
693
+ await transport_1.apiRequest.call(this, 'POST', `/_action/order/${previousOrderData.id}/state/${orderState}`);
694
+ }
695
+ if (orderState === '') {
696
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid order state', {
697
+ description: 'Please specify a valid order state from the list',
698
+ itemIndex: i,
699
+ });
700
+ }
701
+ if (Object.keys(updateFields).length !== 0) {
702
+ await transport_1.apiRequest.call(this, 'PATCH', `/order/${id}`, updateBody);
703
+ }
704
+ const response = await transport_1.apiRequest.call(this, 'POST', `/search/order`, searchBody);
705
+ const executionData = this.helpers.constructExecutionMetaData((0, utils_1.wrapData)(response.data), {
706
+ itemData: { item: i },
707
+ });
708
+ returnData.push(...executionData);
709
+ }
710
+ catch (error) {
711
+ if (this.continueOnFail()) {
712
+ returnData.push({ json: { error: error.message } });
713
+ continue;
714
+ }
715
+ if (error instanceof n8n_workflow_1.NodeOperationError) {
716
+ throw error;
717
+ }
718
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
719
+ }
720
+ }
721
+ return returnData;
722
+ }
723
+ //# sourceMappingURL=update.operation.js.map