n8n-nodes-ship24 1.0.2
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/LICENSE.md +19 -0
- package/README.md +241 -0
- package/dist/credentials/Ship24Api.credentials.d.ts +15 -0
- package/dist/credentials/Ship24Api.credentials.js +31 -0
- package/dist/credentials/Ship24Api.credentials.js.map +1 -0
- package/dist/credentials/ship24.svg +11 -0
- package/dist/docs/images/bulk-mode.png +0 -0
- package/dist/docs/images/create-operation.png +0 -0
- package/dist/docs/images/create-tracker-get-results.png +0 -0
- package/dist/docs/images/credentials-setup.png +0 -0
- package/dist/docs/images/get-results-by-trackerId.png +0 -0
- package/dist/docs/images/node-overview.png +0 -0
- package/dist/docs/images/update-tracker.png +0 -0
- package/dist/docs/images/utility-call.png +0 -0
- package/dist/nodes/Ship24/Ship24.node.d.ts +5 -0
- package/dist/nodes/Ship24/Ship24.node.js +904 -0
- package/dist/nodes/Ship24/Ship24.node.js.map +1 -0
- package/dist/nodes/Ship24/ship24.svg +11 -0
- package/dist/transport/ship24ApiRequest.d.ts +2 -0
- package/dist/transport/ship24ApiRequest.js +33 -0
- package/dist/transport/ship24ApiRequest.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Ship24 = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const ship24ApiRequest_1 = require("../../transport/ship24ApiRequest");
|
|
6
|
+
function isRecord(v) {
|
|
7
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
8
|
+
}
|
|
9
|
+
function getRecord(v) {
|
|
10
|
+
return isRecord(v) ? v : undefined;
|
|
11
|
+
}
|
|
12
|
+
function getNestedRecord(root, ...path) {
|
|
13
|
+
let cur = root;
|
|
14
|
+
for (const key of path) {
|
|
15
|
+
const rec = getRecord(cur);
|
|
16
|
+
if (!rec)
|
|
17
|
+
return undefined;
|
|
18
|
+
cur = rec[key];
|
|
19
|
+
}
|
|
20
|
+
return getRecord(cur);
|
|
21
|
+
}
|
|
22
|
+
function getNestedString(root, ...path) {
|
|
23
|
+
let cur = root;
|
|
24
|
+
for (const key of path) {
|
|
25
|
+
const rec = getRecord(cur);
|
|
26
|
+
if (!rec)
|
|
27
|
+
return undefined;
|
|
28
|
+
cur = rec[key];
|
|
29
|
+
}
|
|
30
|
+
return typeof cur === 'string' ? cur : undefined;
|
|
31
|
+
}
|
|
32
|
+
function toSafeJsonValue(v) {
|
|
33
|
+
if (v === null)
|
|
34
|
+
return null;
|
|
35
|
+
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean')
|
|
36
|
+
return v;
|
|
37
|
+
try {
|
|
38
|
+
return JSON.stringify(v);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return String(v);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function formatShip24HttpError(error, ctx = {}) {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
|
|
46
|
+
const err = getRecord(error);
|
|
47
|
+
const rawStatusCode = (_p = (_l = (_h = (_f = (_e = (_c = (_a = err === null || err === void 0 ? void 0 : err.statusCode) !== null && _a !== void 0 ? _a : (_b = getNestedRecord(err === null || err === void 0 ? void 0 : err.response)) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : (_d = getNestedRecord(err === null || err === void 0 ? void 0 : err.response)) === null || _d === void 0 ? void 0 : _d.statusCode) !== null && _e !== void 0 ? _e : err === null || err === void 0 ? void 0 : err.httpCode) !== null && _f !== void 0 ? _f : (_g = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _g === void 0 ? void 0 : _g.statusCode) !== null && _h !== void 0 ? _h : (_k = getNestedRecord((_j = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _j === void 0 ? void 0 : _j.response)) === null || _k === void 0 ? void 0 : _k.status) !== null && _l !== void 0 ? _l : (_o = getNestedRecord((_m = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _m === void 0 ? void 0 : _m.response)) === null || _o === void 0 ? void 0 : _o.statusCode) !== null && _p !== void 0 ? _p : (_q = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _q === void 0 ? void 0 : _q.httpCode;
|
|
48
|
+
const statusCode = typeof rawStatusCode === 'string'
|
|
49
|
+
? Number.parseInt(rawStatusCode, 10)
|
|
50
|
+
: typeof rawStatusCode === 'number'
|
|
51
|
+
? rawStatusCode
|
|
52
|
+
: undefined;
|
|
53
|
+
const statusText = (_r = getNestedString(err === null || err === void 0 ? void 0 : err.response, 'statusText')) !== null && _r !== void 0 ? _r : (statusCode ? `HTTP ${statusCode}` : undefined);
|
|
54
|
+
const responseBody = (_5 = (_3 = (_0 = (_x = (_w = (_v = (_t = (_s = getNestedRecord(err === null || err === void 0 ? void 0 : err.response)) === null || _s === void 0 ? void 0 : _s.body) !== null && _t !== void 0 ? _t : (_u = getNestedRecord(err === null || err === void 0 ? void 0 : err.response)) === null || _u === void 0 ? void 0 : _u.data) !== null && _v !== void 0 ? _v : err === null || err === void 0 ? void 0 : err.body) !== null && _w !== void 0 ? _w : err === null || err === void 0 ? void 0 : err.data) !== null && _x !== void 0 ? _x : (_z = getNestedRecord((_y = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _y === void 0 ? void 0 : _y.response)) === null || _z === void 0 ? void 0 : _z.body) !== null && _0 !== void 0 ? _0 : (_2 = getNestedRecord((_1 = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _1 === void 0 ? void 0 : _1.response)) === null || _2 === void 0 ? void 0 : _2.data) !== null && _3 !== void 0 ? _3 : (_4 = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _4 === void 0 ? void 0 : _4.body) !== null && _5 !== void 0 ? _5 : (_6 = getNestedRecord(err === null || err === void 0 ? void 0 : err.cause)) === null || _6 === void 0 ? void 0 : _6.data;
|
|
55
|
+
let ship24Message;
|
|
56
|
+
if (isRecord(responseBody)) {
|
|
57
|
+
const msg = responseBody.message;
|
|
58
|
+
const errMsg = responseBody.error;
|
|
59
|
+
const title = responseBody.title;
|
|
60
|
+
ship24Message =
|
|
61
|
+
(_8 = (_7 = (typeof msg === 'string' ? msg : undefined)) !== null && _7 !== void 0 ? _7 : (typeof errMsg === 'string' ? errMsg : undefined)) !== null && _8 !== void 0 ? _8 : (typeof title === 'string' ? title : undefined);
|
|
62
|
+
}
|
|
63
|
+
else if (typeof responseBody === 'string' && responseBody.trim() !== '') {
|
|
64
|
+
ship24Message = responseBody.trim();
|
|
65
|
+
}
|
|
66
|
+
const itemPrefix = typeof ctx.itemIndex === 'number' ? `Item ${ctx.itemIndex + 1}: ` : '';
|
|
67
|
+
if (statusCode === 401) {
|
|
68
|
+
return {
|
|
69
|
+
message: `${itemPrefix}Ship24 API request failed (401). Check your API key credentials.`,
|
|
70
|
+
description: ship24Message ? `Ship24 response: ${ship24Message}` : undefined,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (statusCode === 404) {
|
|
74
|
+
let message = `${itemPrefix}Ship24 API request failed (404). The requested resource was not found.`;
|
|
75
|
+
if (ctx.resource === 'tracker' && ctx.operation === 'getResultsByTrackerId') {
|
|
76
|
+
message = `${itemPrefix}Ship24 API request failed (404). No results found for this tracker ID (or it is not available yet).`;
|
|
77
|
+
}
|
|
78
|
+
else if (ctx.resource === 'tracker' && ctx.operation === 'getResultsByTrackingNumber') {
|
|
79
|
+
message = `${itemPrefix}Ship24 API request failed (404). No results found for this tracking number (or it is not available yet).`;
|
|
80
|
+
}
|
|
81
|
+
else if (ctx.resource === 'utility' && ctx.operation === 'apiCall') {
|
|
82
|
+
message = `${itemPrefix}Ship24 API request failed (404). The API path may be incorrect.`;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
message,
|
|
86
|
+
description: ship24Message ? `Ship24 response: ${ship24Message}` : undefined,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (statusCode === 429) {
|
|
90
|
+
return {
|
|
91
|
+
message: `${itemPrefix}Ship24 API request failed (429). Rate limit exceeded. Try again later or reduce request frequency.`,
|
|
92
|
+
description: ship24Message ? `Ship24 response: ${ship24Message}` : undefined,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const baseMessage = ship24Message
|
|
96
|
+
? `${itemPrefix}Ship24 API request failed (${statusText !== null && statusText !== void 0 ? statusText : 'error'}): ${ship24Message}`
|
|
97
|
+
: `${itemPrefix}Ship24 API request failed (${statusText !== null && statusText !== void 0 ? statusText : 'error'}).`;
|
|
98
|
+
let description;
|
|
99
|
+
if (responseBody !== undefined) {
|
|
100
|
+
try {
|
|
101
|
+
description = `Ship24 response body:\n${typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody, null, 2)}`;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
description = 'Ship24 response body was present but could not be stringified.';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { message: baseMessage, description };
|
|
108
|
+
}
|
|
109
|
+
function chunkArray(arr, size) {
|
|
110
|
+
const out = [];
|
|
111
|
+
for (let i = 0; i < arr.length; i += size)
|
|
112
|
+
out.push(arr.slice(i, i + size));
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
function normaliseTrackingNumber(v) {
|
|
116
|
+
if (typeof v !== 'string')
|
|
117
|
+
return '';
|
|
118
|
+
return v.trim();
|
|
119
|
+
}
|
|
120
|
+
function parseCourierCodes(input) {
|
|
121
|
+
if (typeof input !== 'string')
|
|
122
|
+
return undefined;
|
|
123
|
+
const trimmed = input.trim();
|
|
124
|
+
if (!trimmed)
|
|
125
|
+
return undefined;
|
|
126
|
+
const parts = trimmed
|
|
127
|
+
.split(',')
|
|
128
|
+
.map((p) => p.trim())
|
|
129
|
+
.filter(Boolean);
|
|
130
|
+
return parts.length ? parts : undefined;
|
|
131
|
+
}
|
|
132
|
+
function getFixedCollectionValues(collection) {
|
|
133
|
+
if (!collection || typeof collection !== 'object')
|
|
134
|
+
return undefined;
|
|
135
|
+
const values = collection.values;
|
|
136
|
+
if (values && typeof values === 'object')
|
|
137
|
+
return values;
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
function isUuid(v) {
|
|
141
|
+
if (typeof v !== 'string')
|
|
142
|
+
return false;
|
|
143
|
+
const s = v.trim();
|
|
144
|
+
const uuidV4ish = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
145
|
+
return uuidV4ish.test(s);
|
|
146
|
+
}
|
|
147
|
+
function buildCreatePayload(trackingNumber, additionalFields) {
|
|
148
|
+
const body = { trackingNumber };
|
|
149
|
+
const af = additionalFields !== null && additionalFields !== void 0 ? additionalFields : {};
|
|
150
|
+
const setIfString = (key) => {
|
|
151
|
+
const v = af[key];
|
|
152
|
+
if (typeof v === 'string' && v.trim() !== '')
|
|
153
|
+
body[key] = v.trim();
|
|
154
|
+
};
|
|
155
|
+
setIfString('clientTrackerId');
|
|
156
|
+
setIfString('courierName');
|
|
157
|
+
setIfString('destinationCountryCode');
|
|
158
|
+
setIfString('destinationPostCode');
|
|
159
|
+
setIfString('orderNumber');
|
|
160
|
+
setIfString('originCountryCode');
|
|
161
|
+
setIfString('shipmentReference');
|
|
162
|
+
setIfString('trackingUrl');
|
|
163
|
+
if (typeof af.shippingDate === 'string' && af.shippingDate.trim() !== '') {
|
|
164
|
+
body.shippingDate = af.shippingDate.trim();
|
|
165
|
+
}
|
|
166
|
+
if (typeof af.courierCode === 'string') {
|
|
167
|
+
const codes = parseCourierCodes(af.courierCode);
|
|
168
|
+
if (codes)
|
|
169
|
+
body.courierCode = codes;
|
|
170
|
+
}
|
|
171
|
+
const recipient = getFixedCollectionValues(af.recipient);
|
|
172
|
+
if (recipient) {
|
|
173
|
+
const email = recipient.email;
|
|
174
|
+
if (typeof email === 'string' && email.trim() !== '') {
|
|
175
|
+
body.recipient = { email: email.trim() };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const settings = getFixedCollectionValues(af.settings);
|
|
179
|
+
if (settings) {
|
|
180
|
+
const restrict = settings.restrictTrackingToCourierCode;
|
|
181
|
+
if (typeof restrict === 'boolean') {
|
|
182
|
+
body.settings = { restrictTrackingToCourierCode: restrict };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return body;
|
|
186
|
+
}
|
|
187
|
+
function bulkFirstErrorMessage(errors) {
|
|
188
|
+
if (!Array.isArray(errors) || errors.length === 0)
|
|
189
|
+
return {};
|
|
190
|
+
const first = errors[0];
|
|
191
|
+
if (!isRecord(first))
|
|
192
|
+
return {};
|
|
193
|
+
const code = typeof first.code === 'string' ? first.code : undefined;
|
|
194
|
+
const message = typeof first.message === 'string' ? first.message : undefined;
|
|
195
|
+
return { code, message };
|
|
196
|
+
}
|
|
197
|
+
function toBulkResponseShape(response) {
|
|
198
|
+
const rec = getRecord(response);
|
|
199
|
+
if (!rec)
|
|
200
|
+
return {};
|
|
201
|
+
return {
|
|
202
|
+
status: rec.status,
|
|
203
|
+
summary: rec.summary,
|
|
204
|
+
data: rec.data,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function toBulkItems(response) {
|
|
208
|
+
const rec = getRecord(response);
|
|
209
|
+
if (!rec)
|
|
210
|
+
return [];
|
|
211
|
+
const data = rec.data;
|
|
212
|
+
if (!Array.isArray(data))
|
|
213
|
+
return [];
|
|
214
|
+
const out = [];
|
|
215
|
+
for (const item of data) {
|
|
216
|
+
if (!isRecord(item))
|
|
217
|
+
continue;
|
|
218
|
+
out.push({
|
|
219
|
+
itemStatus: typeof item.itemStatus === 'string' ? item.itemStatus : undefined,
|
|
220
|
+
errors: item.errors,
|
|
221
|
+
inputData: item.inputData,
|
|
222
|
+
tracker: item.tracker,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
function getInputTrackingNumberFromBulkItem(item) {
|
|
228
|
+
const inputDataRec = getRecord(item.inputData);
|
|
229
|
+
const tn = inputDataRec === null || inputDataRec === void 0 ? void 0 : inputDataRec.trackingNumber;
|
|
230
|
+
return normaliseTrackingNumber(tn);
|
|
231
|
+
}
|
|
232
|
+
function getTrackerIdFromCreateResponse(created) {
|
|
233
|
+
var _a;
|
|
234
|
+
return ((_a = getNestedString(created, 'data', 'tracker', 'trackerId')) !== null && _a !== void 0 ? _a : getNestedString(created, 'tracker', 'trackerId'));
|
|
235
|
+
}
|
|
236
|
+
function isHttpMethod(v) {
|
|
237
|
+
return v === 'DELETE' || v === 'GET' || v === 'PATCH' || v === 'POST' || v === 'PUT';
|
|
238
|
+
}
|
|
239
|
+
class Ship24 {
|
|
240
|
+
constructor() {
|
|
241
|
+
this.description = {
|
|
242
|
+
displayName: 'Ship24',
|
|
243
|
+
name: 'ship24',
|
|
244
|
+
icon: 'file:ship24.svg',
|
|
245
|
+
group: ['input'],
|
|
246
|
+
version: 1,
|
|
247
|
+
description: 'Automate shipment tracking using the Ship24 API',
|
|
248
|
+
defaults: { name: 'Ship24' },
|
|
249
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
250
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
251
|
+
credentials: [{ name: 'ship24Api', required: true }],
|
|
252
|
+
properties: [
|
|
253
|
+
{
|
|
254
|
+
displayName: 'Generate or view your Ship24 API key in the dashboard: https://dashboard.ship24.com/integrations/api-keys',
|
|
255
|
+
name: 'ship24DashboardNotice',
|
|
256
|
+
type: 'notice',
|
|
257
|
+
default: '',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
displayName: 'Resource',
|
|
261
|
+
name: 'resource',
|
|
262
|
+
type: 'options',
|
|
263
|
+
noDataExpression: true,
|
|
264
|
+
options: [
|
|
265
|
+
{ name: 'Tracker', value: 'tracker' },
|
|
266
|
+
{ name: 'Utility', value: 'utility' },
|
|
267
|
+
],
|
|
268
|
+
default: 'tracker',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
displayName: 'Operation',
|
|
272
|
+
name: 'operation',
|
|
273
|
+
type: 'options',
|
|
274
|
+
noDataExpression: true,
|
|
275
|
+
options: [
|
|
276
|
+
{ name: 'Create', value: 'create', action: 'Create a tracker' },
|
|
277
|
+
{
|
|
278
|
+
name: 'Create and Get Results',
|
|
279
|
+
value: 'createAndGetResults',
|
|
280
|
+
action: 'Create and get results',
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: 'Get Results By Tracker ID',
|
|
284
|
+
value: 'getResultsByTrackerId',
|
|
285
|
+
action: 'Get results by tracker ID',
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: 'Get Results By Tracking Number',
|
|
289
|
+
value: 'getResultsByTrackingNumber',
|
|
290
|
+
action: 'Get results by tracking number',
|
|
291
|
+
},
|
|
292
|
+
{ name: 'Update', value: 'update', action: 'Update a tracker' },
|
|
293
|
+
],
|
|
294
|
+
displayOptions: { show: { resource: ['tracker'] } },
|
|
295
|
+
default: 'create',
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
displayName: 'Operation',
|
|
299
|
+
name: 'utilityOperation',
|
|
300
|
+
type: 'options',
|
|
301
|
+
noDataExpression: true,
|
|
302
|
+
options: [{ name: 'Make an API Call', value: 'apiCall' }],
|
|
303
|
+
displayOptions: { show: { resource: ['utility'] } },
|
|
304
|
+
default: 'apiCall',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
displayName: 'Create Method',
|
|
308
|
+
name: 'createMethod',
|
|
309
|
+
type: 'options',
|
|
310
|
+
default: 'single',
|
|
311
|
+
options: [
|
|
312
|
+
{ name: 'Single (Per Item)', value: 'single' },
|
|
313
|
+
{ name: 'Bulk (Up to 100 per Request)', value: 'bulk' },
|
|
314
|
+
],
|
|
315
|
+
description: 'When using Bulk, the node batches input items (max 100 tracking numbers per API request) and returns one output item per input item',
|
|
316
|
+
displayOptions: { show: { resource: ['tracker'], operation: ['create'] } },
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
displayName: 'Tracking Number',
|
|
320
|
+
name: 'trackingNumber',
|
|
321
|
+
type: 'string',
|
|
322
|
+
required: true,
|
|
323
|
+
default: '',
|
|
324
|
+
placeholder: '07284069305508',
|
|
325
|
+
description: 'The shipment tracking number',
|
|
326
|
+
displayOptions: {
|
|
327
|
+
show: {
|
|
328
|
+
resource: ['tracker'],
|
|
329
|
+
operation: ['create', 'createAndGetResults', 'getResultsByTrackingNumber'],
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
displayName: 'Additional Fields',
|
|
335
|
+
name: 'additionalFields',
|
|
336
|
+
type: 'collection',
|
|
337
|
+
default: {},
|
|
338
|
+
placeholder: 'Add Field',
|
|
339
|
+
description: 'Optional fields for creating a tracker',
|
|
340
|
+
displayOptions: {
|
|
341
|
+
show: {
|
|
342
|
+
resource: ['tracker'],
|
|
343
|
+
operation: ['create', 'createAndGetResults'],
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
options: [
|
|
347
|
+
{
|
|
348
|
+
displayName: 'Client Tracker ID',
|
|
349
|
+
name: 'clientTrackerId',
|
|
350
|
+
type: 'string',
|
|
351
|
+
default: '',
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
displayName: 'Courier Code',
|
|
355
|
+
name: 'courierCode',
|
|
356
|
+
type: 'string',
|
|
357
|
+
default: '',
|
|
358
|
+
placeholder: 'mobly or mobly,usps',
|
|
359
|
+
description: 'Comma-separated courier codes (supports expressions and mapping)',
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
displayName: 'Courier Name',
|
|
363
|
+
name: 'courierName',
|
|
364
|
+
type: 'string',
|
|
365
|
+
default: '',
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
displayName: 'Destination Country Code',
|
|
369
|
+
name: 'destinationCountryCode',
|
|
370
|
+
type: 'string',
|
|
371
|
+
default: '',
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
displayName: 'Destination Post Code',
|
|
375
|
+
name: 'destinationPostCode',
|
|
376
|
+
type: 'string',
|
|
377
|
+
default: '',
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
displayName: 'Order Number',
|
|
381
|
+
name: 'orderNumber',
|
|
382
|
+
type: 'string',
|
|
383
|
+
default: '',
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
displayName: 'Origin Country Code',
|
|
387
|
+
name: 'originCountryCode',
|
|
388
|
+
type: 'string',
|
|
389
|
+
default: '',
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
displayName: 'Recipient',
|
|
393
|
+
name: 'recipient',
|
|
394
|
+
type: 'fixedCollection',
|
|
395
|
+
default: {},
|
|
396
|
+
options: [
|
|
397
|
+
{
|
|
398
|
+
displayName: 'Recipient',
|
|
399
|
+
name: 'values',
|
|
400
|
+
values: [
|
|
401
|
+
{
|
|
402
|
+
displayName: 'Email',
|
|
403
|
+
name: 'email',
|
|
404
|
+
type: 'string',
|
|
405
|
+
default: '',
|
|
406
|
+
placeholder: 'name@email.com',
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
displayName: 'Settings',
|
|
414
|
+
name: 'settings',
|
|
415
|
+
type: 'fixedCollection',
|
|
416
|
+
default: {},
|
|
417
|
+
options: [
|
|
418
|
+
{
|
|
419
|
+
displayName: 'Settings',
|
|
420
|
+
name: 'values',
|
|
421
|
+
values: [
|
|
422
|
+
{
|
|
423
|
+
displayName: 'Restrict Tracking To Courier Code',
|
|
424
|
+
name: 'restrictTrackingToCourierCode',
|
|
425
|
+
type: 'boolean',
|
|
426
|
+
default: false,
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
},
|
|
430
|
+
],
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
displayName: 'Shipment Reference',
|
|
434
|
+
name: 'shipmentReference',
|
|
435
|
+
type: 'string',
|
|
436
|
+
default: '',
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
displayName: 'Shipping Date',
|
|
440
|
+
name: 'shippingDate',
|
|
441
|
+
type: 'string',
|
|
442
|
+
default: '',
|
|
443
|
+
placeholder: '2021-03-01T11:09:00.000Z',
|
|
444
|
+
description: 'ISO date-time string (UTC)',
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
displayName: 'Tracking URL',
|
|
448
|
+
name: 'trackingUrl',
|
|
449
|
+
type: 'string',
|
|
450
|
+
default: '',
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
displayName: 'Tracker ID',
|
|
456
|
+
name: 'trackerId',
|
|
457
|
+
type: 'string',
|
|
458
|
+
required: true,
|
|
459
|
+
default: '',
|
|
460
|
+
placeholder: 'a6e6c40c-e012-4832-9636-e73ffda82517',
|
|
461
|
+
description: 'The Ship24 tracker ID (UUID)',
|
|
462
|
+
displayOptions: {
|
|
463
|
+
show: {
|
|
464
|
+
resource: ['tracker'],
|
|
465
|
+
operation: ['getResultsByTrackerId', 'update'],
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
displayName: 'Is Subscribed',
|
|
471
|
+
name: 'isSubscribed',
|
|
472
|
+
type: 'boolean',
|
|
473
|
+
default: true,
|
|
474
|
+
description: 'Whether the tracker is subscribed for updates',
|
|
475
|
+
displayOptions: {
|
|
476
|
+
show: {
|
|
477
|
+
resource: ['tracker'],
|
|
478
|
+
operation: ['update'],
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
displayName: 'Origin Country Code',
|
|
484
|
+
name: 'originCountryCode',
|
|
485
|
+
type: 'string',
|
|
486
|
+
default: '',
|
|
487
|
+
placeholder: 'CN',
|
|
488
|
+
description: 'Two-letter country code (ISO 3166-1 alpha-2)',
|
|
489
|
+
displayOptions: {
|
|
490
|
+
show: {
|
|
491
|
+
resource: ['tracker'],
|
|
492
|
+
operation: ['update'],
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
displayName: 'Destination Country Code',
|
|
498
|
+
name: 'destinationCountryCode',
|
|
499
|
+
type: 'string',
|
|
500
|
+
default: '',
|
|
501
|
+
placeholder: 'US',
|
|
502
|
+
description: 'Two-letter country code (ISO 3166-1 alpha-2)',
|
|
503
|
+
displayOptions: {
|
|
504
|
+
show: {
|
|
505
|
+
resource: ['tracker'],
|
|
506
|
+
operation: ['update'],
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
displayName: 'Destination Post Code',
|
|
512
|
+
name: 'destinationPostCode',
|
|
513
|
+
type: 'string',
|
|
514
|
+
default: '',
|
|
515
|
+
placeholder: '94901',
|
|
516
|
+
displayOptions: {
|
|
517
|
+
show: {
|
|
518
|
+
resource: ['tracker'],
|
|
519
|
+
operation: ['update'],
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
displayName: 'Shipping Date',
|
|
525
|
+
name: 'shippingDate',
|
|
526
|
+
type: 'string',
|
|
527
|
+
default: '',
|
|
528
|
+
placeholder: '2021-03-01T11:09:00.000Z',
|
|
529
|
+
description: 'Shipping date in ISO format (UTC recommended)',
|
|
530
|
+
displayOptions: {
|
|
531
|
+
show: {
|
|
532
|
+
resource: ['tracker'],
|
|
533
|
+
operation: ['update'],
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
displayName: 'Courier Code',
|
|
539
|
+
name: 'courierCode',
|
|
540
|
+
type: 'string',
|
|
541
|
+
default: '',
|
|
542
|
+
placeholder: 'us-post',
|
|
543
|
+
description: 'Comma-separated courier codes (e.g. "us-post,dhl")',
|
|
544
|
+
displayOptions: {
|
|
545
|
+
show: {
|
|
546
|
+
resource: ['tracker'],
|
|
547
|
+
operation: ['update'],
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
displayName: 'Method',
|
|
553
|
+
name: 'method',
|
|
554
|
+
type: 'options',
|
|
555
|
+
options: [
|
|
556
|
+
{ name: 'DELETE', value: 'DELETE' },
|
|
557
|
+
{ name: 'GET', value: 'GET' },
|
|
558
|
+
{ name: 'PATCH', value: 'PATCH' },
|
|
559
|
+
{ name: 'POST', value: 'POST' },
|
|
560
|
+
{ name: 'PUT', value: 'PUT' },
|
|
561
|
+
],
|
|
562
|
+
displayOptions: { show: { resource: ['utility'] } },
|
|
563
|
+
default: 'GET',
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
displayName: 'Path',
|
|
567
|
+
name: 'path',
|
|
568
|
+
type: 'string',
|
|
569
|
+
required: true,
|
|
570
|
+
default: '',
|
|
571
|
+
placeholder: '/trackers',
|
|
572
|
+
description: 'Relative Ship24 API path',
|
|
573
|
+
displayOptions: { show: { resource: ['utility'] } },
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
displayName: 'Query Parameters',
|
|
577
|
+
name: 'query',
|
|
578
|
+
type: 'json',
|
|
579
|
+
default: '{}',
|
|
580
|
+
displayOptions: { show: { resource: ['utility'] } },
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
displayName: 'Body',
|
|
584
|
+
name: 'body',
|
|
585
|
+
type: 'json',
|
|
586
|
+
default: '{}',
|
|
587
|
+
displayOptions: { show: { resource: ['utility'] } },
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
usableAsTool: true,
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
async execute() {
|
|
594
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
595
|
+
const items = this.getInputData();
|
|
596
|
+
const returnData = [];
|
|
597
|
+
const pushItemError = (error, ctx) => {
|
|
598
|
+
const formatted = formatShip24HttpError(error, ctx);
|
|
599
|
+
if (this.continueOnFail()) {
|
|
600
|
+
returnData.push({
|
|
601
|
+
json: {
|
|
602
|
+
success: false,
|
|
603
|
+
error: {
|
|
604
|
+
message: formatted.message,
|
|
605
|
+
description: formatted.description,
|
|
606
|
+
},
|
|
607
|
+
context: {
|
|
608
|
+
resource: ctx.resource,
|
|
609
|
+
operation: ctx.operation,
|
|
610
|
+
trackingNumber: ctx.trackingNumber,
|
|
611
|
+
trackerId: ctx.trackerId,
|
|
612
|
+
path: ctx.path,
|
|
613
|
+
itemIndex: ctx.itemIndex,
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), formatted.message, formatted.description ? { description: formatted.description } : undefined);
|
|
620
|
+
};
|
|
621
|
+
const canBulkCreateAllItems = (() => {
|
|
622
|
+
if (items.length === 0)
|
|
623
|
+
return false;
|
|
624
|
+
try {
|
|
625
|
+
for (let i = 0; i < items.length; i++) {
|
|
626
|
+
const r = this.getNodeParameter('resource', i);
|
|
627
|
+
if (r !== 'tracker')
|
|
628
|
+
return false;
|
|
629
|
+
const op = this.getNodeParameter('operation', i);
|
|
630
|
+
if (op !== 'create')
|
|
631
|
+
return false;
|
|
632
|
+
const m = this.getNodeParameter('createMethod', i) || 'single';
|
|
633
|
+
if (m !== 'bulk')
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
catch {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
})();
|
|
642
|
+
if (canBulkCreateAllItems) {
|
|
643
|
+
const indexed = items.map((_, i) => {
|
|
644
|
+
const trackingNumber = normaliseTrackingNumber(this.getNodeParameter('trackingNumber', i));
|
|
645
|
+
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
646
|
+
return { i, trackingNumber, additionalFields };
|
|
647
|
+
});
|
|
648
|
+
const chunks = chunkArray(indexed, 100);
|
|
649
|
+
const outputs = new Array(items.length);
|
|
650
|
+
for (const chunk of chunks) {
|
|
651
|
+
const bulkBody = chunk.map((x) => buildCreatePayload(x.trackingNumber, x.additionalFields));
|
|
652
|
+
try {
|
|
653
|
+
const response = await ship24ApiRequest_1.ship24ApiRequest.call(this, 'POST', '/trackers/bulk', bulkBody);
|
|
654
|
+
const bulkShape = toBulkResponseShape(response);
|
|
655
|
+
const bulkMeta = {
|
|
656
|
+
status: toSafeJsonValue(bulkShape.status),
|
|
657
|
+
summary: toSafeJsonValue(bulkShape.summary),
|
|
658
|
+
};
|
|
659
|
+
const dataItems = toBulkItems(response);
|
|
660
|
+
const map = new Map();
|
|
661
|
+
for (const d of dataItems) {
|
|
662
|
+
const tn = getInputTrackingNumberFromBulkItem(d);
|
|
663
|
+
if (!tn)
|
|
664
|
+
continue;
|
|
665
|
+
if (!map.has(tn))
|
|
666
|
+
map.set(tn, []);
|
|
667
|
+
map.get(tn).push(d);
|
|
668
|
+
}
|
|
669
|
+
for (const input of chunk) {
|
|
670
|
+
const tn = input.trackingNumber;
|
|
671
|
+
const queue = map.get(tn);
|
|
672
|
+
const itemResult = queue === null || queue === void 0 ? void 0 : queue.shift();
|
|
673
|
+
if (!itemResult) {
|
|
674
|
+
outputs[input.i] = {
|
|
675
|
+
success: false,
|
|
676
|
+
trackingNumber: tn,
|
|
677
|
+
error: {
|
|
678
|
+
type: 'mapping_error',
|
|
679
|
+
message: 'No result returned for this tracking number in the bulk response.',
|
|
680
|
+
},
|
|
681
|
+
_bulk: bulkMeta,
|
|
682
|
+
};
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
const itemStatus = itemResult.itemStatus;
|
|
686
|
+
if (itemStatus === 'error') {
|
|
687
|
+
const firstErr = bulkFirstErrorMessage(itemResult.errors);
|
|
688
|
+
outputs[input.i] = {
|
|
689
|
+
success: false,
|
|
690
|
+
trackingNumber: tn,
|
|
691
|
+
itemStatus,
|
|
692
|
+
error: {
|
|
693
|
+
type: 'item_error',
|
|
694
|
+
code: firstErr.code,
|
|
695
|
+
message: (_a = firstErr.message) !== null && _a !== void 0 ? _a : 'An error occurred for this tracking number.',
|
|
696
|
+
},
|
|
697
|
+
errors: (_b = itemResult.errors) !== null && _b !== void 0 ? _b : null,
|
|
698
|
+
inputData: (_c = itemResult.inputData) !== null && _c !== void 0 ? _c : null,
|
|
699
|
+
tracker: (_d = itemResult.tracker) !== null && _d !== void 0 ? _d : null,
|
|
700
|
+
_bulk: bulkMeta,
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
outputs[input.i] = {
|
|
705
|
+
success: true,
|
|
706
|
+
trackingNumber: tn,
|
|
707
|
+
itemStatus,
|
|
708
|
+
tracker: (_e = itemResult.tracker) !== null && _e !== void 0 ? _e : null,
|
|
709
|
+
inputData: (_f = itemResult.inputData) !== null && _f !== void 0 ? _f : null,
|
|
710
|
+
errors: (_g = itemResult.errors) !== null && _g !== void 0 ? _g : null,
|
|
711
|
+
_bulk: bulkMeta,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
catch (error) {
|
|
717
|
+
const formatted = formatShip24HttpError(error, {
|
|
718
|
+
resource: 'tracker',
|
|
719
|
+
operation: 'create',
|
|
720
|
+
});
|
|
721
|
+
if (!this.continueOnFail()) {
|
|
722
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), formatted.message, formatted.description ? { description: formatted.description } : undefined);
|
|
723
|
+
}
|
|
724
|
+
for (const x of chunk) {
|
|
725
|
+
outputs[x.i] = {
|
|
726
|
+
success: false,
|
|
727
|
+
trackingNumber: x.trackingNumber,
|
|
728
|
+
error: {
|
|
729
|
+
type: 'request_error',
|
|
730
|
+
message: formatted.message,
|
|
731
|
+
description: formatted.description,
|
|
732
|
+
},
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
for (let i = 0; i < outputs.length; i++) {
|
|
738
|
+
returnData.push({
|
|
739
|
+
json: (_h = outputs[i]) !== null && _h !== void 0 ? _h : {
|
|
740
|
+
success: false,
|
|
741
|
+
error: { type: 'unknown', message: 'No output generated for this item.' },
|
|
742
|
+
},
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
return [returnData];
|
|
746
|
+
}
|
|
747
|
+
for (let i = 0; i < items.length; i++) {
|
|
748
|
+
const resource = this.getNodeParameter('resource', i);
|
|
749
|
+
if (resource === 'tracker') {
|
|
750
|
+
const operation = this.getNodeParameter('operation', i);
|
|
751
|
+
if (operation === 'create') {
|
|
752
|
+
const trackingNumber = normaliseTrackingNumber(this.getNodeParameter('trackingNumber', i));
|
|
753
|
+
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
754
|
+
const body = buildCreatePayload(trackingNumber, additionalFields);
|
|
755
|
+
try {
|
|
756
|
+
const response = await ship24ApiRequest_1.ship24ApiRequest.call(this, 'POST', '/trackers', body);
|
|
757
|
+
returnData.push({ json: response });
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
pushItemError(error, { resource, operation, trackingNumber, itemIndex: i });
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (operation === 'createAndGetResults') {
|
|
766
|
+
const trackingNumber = normaliseTrackingNumber(this.getNodeParameter('trackingNumber', i));
|
|
767
|
+
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
768
|
+
const body = buildCreatePayload(trackingNumber, additionalFields);
|
|
769
|
+
try {
|
|
770
|
+
const created = (await ship24ApiRequest_1.ship24ApiRequest.call(this, 'POST', '/trackers', body));
|
|
771
|
+
const trackerId = getTrackerIdFromCreateResponse(created);
|
|
772
|
+
if (!trackerId || typeof trackerId !== 'string') {
|
|
773
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Create succeeded but trackerId was not found in the response.');
|
|
774
|
+
}
|
|
775
|
+
const results = (await ship24ApiRequest_1.ship24ApiRequest.call(this, 'GET', `/trackers/${encodeURIComponent(trackerId)}/results`));
|
|
776
|
+
const out = {
|
|
777
|
+
created: created,
|
|
778
|
+
results: results,
|
|
779
|
+
};
|
|
780
|
+
returnData.push({ json: out });
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
catch (error) {
|
|
784
|
+
pushItemError(error, { resource, operation, trackingNumber, itemIndex: i });
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (operation === 'update') {
|
|
789
|
+
const trackerId = this.getNodeParameter('trackerId', i);
|
|
790
|
+
if (!isUuid(trackerId)) {
|
|
791
|
+
pushItemError(new n8n_workflow_1.NodeOperationError(this.getNode(), 'Tracker ID must be a valid UUID.'), {
|
|
792
|
+
resource,
|
|
793
|
+
operation,
|
|
794
|
+
trackerId,
|
|
795
|
+
itemIndex: i,
|
|
796
|
+
});
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
const body = {};
|
|
800
|
+
body.isSubscribed = this.getNodeParameter('isSubscribed', i);
|
|
801
|
+
const originCountryCode = this.getNodeParameter('originCountryCode', i, '');
|
|
802
|
+
if (typeof originCountryCode === 'string' && originCountryCode.trim() !== '') {
|
|
803
|
+
body.originCountryCode = originCountryCode.trim();
|
|
804
|
+
}
|
|
805
|
+
const destinationCountryCode = this.getNodeParameter('destinationCountryCode', i, '');
|
|
806
|
+
if (typeof destinationCountryCode === 'string' && destinationCountryCode.trim() !== '') {
|
|
807
|
+
body.destinationCountryCode = destinationCountryCode.trim();
|
|
808
|
+
}
|
|
809
|
+
const destinationPostCode = this.getNodeParameter('destinationPostCode', i, '');
|
|
810
|
+
if (typeof destinationPostCode === 'string' && destinationPostCode.trim() !== '') {
|
|
811
|
+
body.destinationPostCode = destinationPostCode.trim();
|
|
812
|
+
}
|
|
813
|
+
const shippingDate = this.getNodeParameter('shippingDate', i, '');
|
|
814
|
+
if (typeof shippingDate === 'string' && shippingDate.trim() !== '') {
|
|
815
|
+
body.shippingDate = shippingDate.trim();
|
|
816
|
+
}
|
|
817
|
+
const courierCodeRaw = this.getNodeParameter('courierCode', i, '');
|
|
818
|
+
if (typeof courierCodeRaw === 'string' && courierCodeRaw.trim() !== '') {
|
|
819
|
+
const codes = parseCourierCodes(courierCodeRaw);
|
|
820
|
+
if (codes)
|
|
821
|
+
body.courierCode = codes;
|
|
822
|
+
}
|
|
823
|
+
try {
|
|
824
|
+
const response = await ship24ApiRequest_1.ship24ApiRequest.call(this, 'PATCH', `/trackers/${encodeURIComponent(trackerId)}`, body);
|
|
825
|
+
returnData.push({ json: response });
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
pushItemError(error, { resource, operation, trackerId, itemIndex: i });
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (operation === 'getResultsByTrackingNumber') {
|
|
834
|
+
const trackingNumber = normaliseTrackingNumber(this.getNodeParameter('trackingNumber', i));
|
|
835
|
+
try {
|
|
836
|
+
const response = await ship24ApiRequest_1.ship24ApiRequest.call(this, 'GET', `/trackers/search/${encodeURIComponent(trackingNumber)}/results`);
|
|
837
|
+
returnData.push({ json: response });
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
catch (error) {
|
|
841
|
+
pushItemError(error, { resource, operation, trackingNumber, itemIndex: i });
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (operation === 'getResultsByTrackerId') {
|
|
846
|
+
const trackerId = this.getNodeParameter('trackerId', i);
|
|
847
|
+
if (!isUuid(trackerId)) {
|
|
848
|
+
pushItemError(new n8n_workflow_1.NodeOperationError(this.getNode(), 'Tracker ID must be a valid UUID.'), {
|
|
849
|
+
resource,
|
|
850
|
+
operation,
|
|
851
|
+
trackerId,
|
|
852
|
+
itemIndex: i,
|
|
853
|
+
});
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
try {
|
|
857
|
+
const response = await ship24ApiRequest_1.ship24ApiRequest.call(this, 'GET', `/trackers/${encodeURIComponent(trackerId)}/results`);
|
|
858
|
+
returnData.push({ json: response });
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
catch (error) {
|
|
862
|
+
pushItemError(error, { resource, operation, trackerId, itemIndex: i });
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
pushItemError(new Error('The selected operation is not implemented.'), {
|
|
867
|
+
resource,
|
|
868
|
+
operation,
|
|
869
|
+
itemIndex: i,
|
|
870
|
+
});
|
|
871
|
+
continue;
|
|
872
|
+
}
|
|
873
|
+
if (resource === 'utility') {
|
|
874
|
+
const operation = this.getNodeParameter('utilityOperation', i) || 'apiCall';
|
|
875
|
+
try {
|
|
876
|
+
const methodRaw = this.getNodeParameter('method', i);
|
|
877
|
+
const method = isHttpMethod(methodRaw) ? methodRaw : 'GET';
|
|
878
|
+
const path = this.getNodeParameter('path', i);
|
|
879
|
+
const query = this.getNodeParameter('query', i);
|
|
880
|
+
const body = this.getNodeParameter('body', i);
|
|
881
|
+
const response = await ship24ApiRequest_1.ship24ApiRequest.call(this, method, path, body, query);
|
|
882
|
+
returnData.push({ json: response });
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
catch (error) {
|
|
886
|
+
pushItemError(error, {
|
|
887
|
+
resource,
|
|
888
|
+
operation,
|
|
889
|
+
path: this.getNodeParameter('path', i),
|
|
890
|
+
itemIndex: i,
|
|
891
|
+
});
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
pushItemError(new Error('The selected resource is not implemented.'), {
|
|
896
|
+
resource,
|
|
897
|
+
itemIndex: i,
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
return [returnData];
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
exports.Ship24 = Ship24;
|
|
904
|
+
//# sourceMappingURL=Ship24.node.js.map
|