postnl-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +206 -0
- package/dist/index.cjs +2017 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12752 -0
- package/dist/index.d.ts +12752 -0
- package/dist/index.js +1951 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2017 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/config.ts
|
|
6
|
+
var BASE_URLS = {
|
|
7
|
+
production: "https://api.postnl.nl",
|
|
8
|
+
sandbox: "https://api-sandbox.postnl.nl"
|
|
9
|
+
};
|
|
10
|
+
var DEFAULT_RETRY = {
|
|
11
|
+
maxRetries: 3,
|
|
12
|
+
backoffFactor: 2,
|
|
13
|
+
retryStatuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
14
|
+
retryMethods: ["GET", "PUT"]
|
|
15
|
+
};
|
|
16
|
+
function resolveConfig(opts) {
|
|
17
|
+
if (!opts?.apiKey) throw new Error("postnl-client: apiKey is required");
|
|
18
|
+
const environment = opts.environment ?? "production";
|
|
19
|
+
const f = opts.fetch ?? globalThis.fetch;
|
|
20
|
+
if (!f) throw new Error("postnl-client: no fetch available; pass options.fetch");
|
|
21
|
+
return {
|
|
22
|
+
apiKey: opts.apiKey,
|
|
23
|
+
environment,
|
|
24
|
+
baseUrl: BASE_URLS[environment],
|
|
25
|
+
fetch: f,
|
|
26
|
+
timeoutMs: opts.timeoutMs ?? 6e4,
|
|
27
|
+
retry: { ...DEFAULT_RETRY, ...opts.retry },
|
|
28
|
+
hooks: opts.hooks ?? {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/core/errors.ts
|
|
33
|
+
var PostNLError = class extends Error {
|
|
34
|
+
};
|
|
35
|
+
var PostNLValidationError = class extends PostNLError {
|
|
36
|
+
constructor(message, issues) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.issues = issues;
|
|
39
|
+
this.name = "PostNLValidationError";
|
|
40
|
+
}
|
|
41
|
+
issues;
|
|
42
|
+
};
|
|
43
|
+
var PostNLTimeoutError = class extends PostNLError {
|
|
44
|
+
constructor(timeoutMs) {
|
|
45
|
+
super(`postnl request timed out after ${timeoutMs}ms`);
|
|
46
|
+
this.timeoutMs = timeoutMs;
|
|
47
|
+
this.name = "PostNLTimeoutError";
|
|
48
|
+
}
|
|
49
|
+
timeoutMs;
|
|
50
|
+
};
|
|
51
|
+
var PostNLApiError = class extends PostNLError {
|
|
52
|
+
constructor(status, message, code, detail, raw) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.status = status;
|
|
55
|
+
this.code = code;
|
|
56
|
+
this.detail = detail;
|
|
57
|
+
this.raw = raw;
|
|
58
|
+
this.name = "PostNLApiError";
|
|
59
|
+
}
|
|
60
|
+
status;
|
|
61
|
+
code;
|
|
62
|
+
detail;
|
|
63
|
+
raw;
|
|
64
|
+
};
|
|
65
|
+
var PostNLAuthError = class extends PostNLApiError {
|
|
66
|
+
name = "PostNLAuthError";
|
|
67
|
+
};
|
|
68
|
+
var PostNLRateLimitError = class extends PostNLApiError {
|
|
69
|
+
retryAfter;
|
|
70
|
+
name = "PostNLRateLimitError";
|
|
71
|
+
};
|
|
72
|
+
var PostNLMethodNotAllowedError = class extends PostNLApiError {
|
|
73
|
+
name = "PostNLMethodNotAllowedError";
|
|
74
|
+
};
|
|
75
|
+
var PostNLBadRequestError = class extends PostNLApiError {
|
|
76
|
+
name = "PostNLBadRequestError";
|
|
77
|
+
};
|
|
78
|
+
var PostNLServerError = class extends PostNLApiError {
|
|
79
|
+
name = "PostNLServerError";
|
|
80
|
+
};
|
|
81
|
+
function extract(body) {
|
|
82
|
+
const b = body;
|
|
83
|
+
if (b && typeof b === "object") {
|
|
84
|
+
const fault = b.fault;
|
|
85
|
+
if (fault)
|
|
86
|
+
return {
|
|
87
|
+
message: fault.faultstring ?? "fault",
|
|
88
|
+
code: fault.detail?.errorcode,
|
|
89
|
+
detail: fault
|
|
90
|
+
};
|
|
91
|
+
const inv = b.Error;
|
|
92
|
+
if (inv?.ErrorDescription)
|
|
93
|
+
return { message: inv.ErrorDescription, code: inv.ErrorCode, detail: b };
|
|
94
|
+
const list = b.errors ?? b.Errors;
|
|
95
|
+
if (Array.isArray(list) && list.length) {
|
|
96
|
+
const f = list[0];
|
|
97
|
+
const msg = f.ErrorMsg ?? f.Error ?? f.title ?? f.Description ?? f.detail ?? "error";
|
|
98
|
+
const code = f.ErrorNumber ?? f.Code ?? f.status;
|
|
99
|
+
return { message: String(msg), code: code != null ? String(code) : void 0, detail: list };
|
|
100
|
+
}
|
|
101
|
+
if (typeof b.title === "string")
|
|
102
|
+
return { message: b.title, code: b.type, detail: b };
|
|
103
|
+
if (typeof b.message === "string") return { message: b.message, detail: b };
|
|
104
|
+
}
|
|
105
|
+
return { message: `postnl request failed (${typeof body})`, detail: body };
|
|
106
|
+
}
|
|
107
|
+
function parseError(status, body, headers) {
|
|
108
|
+
const { message, code, detail } = extract(body);
|
|
109
|
+
if (status === 401) return new PostNLAuthError(status, message, code, detail, body);
|
|
110
|
+
if (status === 429) {
|
|
111
|
+
const err = new PostNLRateLimitError(status, message, code, detail, body);
|
|
112
|
+
const ra = Number(headers?.["retry-after"]);
|
|
113
|
+
if (Number.isFinite(ra)) err.retryAfter = ra;
|
|
114
|
+
return err;
|
|
115
|
+
}
|
|
116
|
+
if (status === 405) return new PostNLMethodNotAllowedError(status, message, code, detail, body);
|
|
117
|
+
if (status >= 500) return new PostNLServerError(status, message, code, detail, body);
|
|
118
|
+
if (status === 400) return new PostNLBadRequestError(status, message, code, detail, body);
|
|
119
|
+
return new PostNLApiError(status, message, code, detail, body);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/core/http.ts
|
|
123
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
124
|
+
var Transport = class {
|
|
125
|
+
constructor(cfg) {
|
|
126
|
+
this.cfg = cfg;
|
|
127
|
+
}
|
|
128
|
+
cfg;
|
|
129
|
+
buildUrl(args) {
|
|
130
|
+
let path = args.path;
|
|
131
|
+
for (const [k, v] of Object.entries(args.pathParams ?? {})) {
|
|
132
|
+
path = path.replace(`{${k}}`, encodeURIComponent(v));
|
|
133
|
+
}
|
|
134
|
+
const url = new URL(this.cfg.baseUrl + path);
|
|
135
|
+
for (const [k, v] of Object.entries(args.query ?? {})) {
|
|
136
|
+
if (v === void 0) continue;
|
|
137
|
+
if (Array.isArray(v)) for (const item of v) url.searchParams.append(k, String(item));
|
|
138
|
+
else url.searchParams.append(k, String(v));
|
|
139
|
+
}
|
|
140
|
+
return url.toString();
|
|
141
|
+
}
|
|
142
|
+
async send(args) {
|
|
143
|
+
const url = this.buildUrl(args);
|
|
144
|
+
const headers = { apikey: this.cfg.apiKey, accept: "application/json" };
|
|
145
|
+
if (args.body !== void 0) headers["content-type"] = "application/json";
|
|
146
|
+
const ctx = {
|
|
147
|
+
family: args.family,
|
|
148
|
+
method: args.method,
|
|
149
|
+
url,
|
|
150
|
+
headers,
|
|
151
|
+
body: args.body
|
|
152
|
+
};
|
|
153
|
+
await this.cfg.hooks.onRequest?.(ctx);
|
|
154
|
+
const canRetry = this.cfg.retry.retryMethods.includes(args.method);
|
|
155
|
+
let attempt = 0;
|
|
156
|
+
while (true) {
|
|
157
|
+
const controller = new AbortController();
|
|
158
|
+
let timedOut = false;
|
|
159
|
+
const timer = setTimeout(() => {
|
|
160
|
+
timedOut = true;
|
|
161
|
+
controller.abort();
|
|
162
|
+
}, this.cfg.timeoutMs);
|
|
163
|
+
try {
|
|
164
|
+
const res = await this.cfg.fetch(url, {
|
|
165
|
+
method: args.method,
|
|
166
|
+
headers,
|
|
167
|
+
body: args.body !== void 0 ? JSON.stringify(args.body) : void 0,
|
|
168
|
+
signal: controller.signal
|
|
169
|
+
});
|
|
170
|
+
clearTimeout(timer);
|
|
171
|
+
const text = await res.text();
|
|
172
|
+
const headerObj = Object.fromEntries(res.headers.entries());
|
|
173
|
+
let body;
|
|
174
|
+
try {
|
|
175
|
+
body = text ? JSON.parse(text) : void 0;
|
|
176
|
+
} catch {
|
|
177
|
+
if (!res.ok) {
|
|
178
|
+
const err3 = parseError(res.status, text, headerObj);
|
|
179
|
+
await this.cfg.hooks.onError?.(err3);
|
|
180
|
+
throw err3;
|
|
181
|
+
}
|
|
182
|
+
const err2 = new PostNLApiError(
|
|
183
|
+
res.status,
|
|
184
|
+
"invalid json response",
|
|
185
|
+
void 0,
|
|
186
|
+
void 0,
|
|
187
|
+
text
|
|
188
|
+
);
|
|
189
|
+
await this.cfg.hooks.onError?.(err2);
|
|
190
|
+
throw err2;
|
|
191
|
+
}
|
|
192
|
+
if (res.ok) {
|
|
193
|
+
await this.cfg.hooks.onResponse?.({ request: ctx, status: res.status, body });
|
|
194
|
+
return body;
|
|
195
|
+
}
|
|
196
|
+
if (canRetry && this.cfg.retry.retryStatuses.includes(res.status) && attempt < this.cfg.retry.maxRetries) {
|
|
197
|
+
attempt++;
|
|
198
|
+
await sleep(this.retryDelay(attempt, res.status, headerObj));
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const err = parseError(res.status, body, headerObj);
|
|
202
|
+
await this.cfg.hooks.onError?.(err);
|
|
203
|
+
throw err;
|
|
204
|
+
} catch (e2) {
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
if (e2 instanceof PostNLApiError) throw e2;
|
|
207
|
+
if (canRetry && this.isRetryable(e2) && attempt < this.cfg.retry.maxRetries) {
|
|
208
|
+
attempt++;
|
|
209
|
+
await sleep(this.cfg.retry.backoffFactor * 2 ** (attempt - 1) * 100);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const surfaced = timedOut ? new PostNLTimeoutError(this.cfg.timeoutMs) : e2;
|
|
213
|
+
await this.cfg.hooks.onError?.(surfaced);
|
|
214
|
+
throw surfaced;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
retryDelay(attempt, status, headers) {
|
|
219
|
+
if (status === 429) {
|
|
220
|
+
const ra = Number(headers["retry-after"]);
|
|
221
|
+
if (Number.isFinite(ra)) return ra * 1e3;
|
|
222
|
+
}
|
|
223
|
+
return this.cfg.retry.backoffFactor * 2 ** (attempt - 1) * 100;
|
|
224
|
+
}
|
|
225
|
+
// only retry genuine network failures: our timeout abort, or a fetch
|
|
226
|
+
// network-level TypeError. bad-url/bad-init TypeErrors should not retry.
|
|
227
|
+
isRetryable(e2) {
|
|
228
|
+
if (e2?.name === "AbortError") return true;
|
|
229
|
+
if (!(e2 instanceof TypeError)) return false;
|
|
230
|
+
const msg = `${e2.message} ${String(e2.cause ?? "")}`.toLowerCase();
|
|
231
|
+
return /fetch|network|connect|econn|enotfound|socket|timeout|terminated/.test(msg);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/core/endpoints.ts
|
|
236
|
+
var e = (family, method, path) => ({
|
|
237
|
+
family,
|
|
238
|
+
method,
|
|
239
|
+
path
|
|
240
|
+
});
|
|
241
|
+
var ENDPOINTS = {
|
|
242
|
+
barcodeV4: e("v4", "POST", "/shipment/delivery/v4/barcode"),
|
|
243
|
+
shippingCreate: e("v4", "POST", "/shipment/delivery/v4/labelconfirm"),
|
|
244
|
+
shippingLabelV4: e("v4", "POST", "/shipment/delivery/v4/label"),
|
|
245
|
+
shippingConfirmV4: e("v4", "POST", "/shipment/delivery/v4/confirm"),
|
|
246
|
+
returnGenerate: e("v4", "POST", "/shipment/delivery/v4/return/generate"),
|
|
247
|
+
barcodeLegacy: e("legacy", "GET", "/shipment/v1_1/barcode"),
|
|
248
|
+
shippingLabelLegacy: e("legacy", "POST", "/shipment/v2_2/label"),
|
|
249
|
+
shippingConfirmLegacy: e("legacy", "POST", "/shipment/v2/confirm"),
|
|
250
|
+
trackingByBarcode: e("legacy", "GET", "/shipment/v2/status/barcode/{barcode}"),
|
|
251
|
+
trackingByReference: e("legacy", "GET", "/shipment/v2/status/reference/{referenceId}"),
|
|
252
|
+
trackingSignature: e("legacy", "GET", "/shipment/v2/status/signature/{barcode}"),
|
|
253
|
+
trackingUpdated: e("legacy", "GET", "/shipment/v2/status/{customernumber}/updatedshipments"),
|
|
254
|
+
deliveryDateCalculate: e("legacy", "GET", "/shipment/v2_2/calculate/date/delivery"),
|
|
255
|
+
deliveryDateSent: e("legacy", "GET", "/shipment/v2_2/calculate/date/shipping"),
|
|
256
|
+
timeframeGet: e("legacy", "GET", "/shipment/v2_1/calculate/timeframes"),
|
|
257
|
+
locationNearest: e("legacy", "GET", "/shipment/v2_1/locations/nearest"),
|
|
258
|
+
locationNearestByGeocode: e("legacy", "GET", "/shipment/v2_1/locations/nearest/geocode"),
|
|
259
|
+
locationArea: e("legacy", "GET", "/shipment/v2_1/locations/area"),
|
|
260
|
+
locationLookup: e("legacy", "GET", "/shipment/v2_1/locations/lookup"),
|
|
261
|
+
checkoutGet: e("legacy", "POST", "/shipment/v1/checkout"),
|
|
262
|
+
addressCheck: e("legacy", "GET", "/shipment/checkout/v1/postalcodecheck")
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/core/base-resource.ts
|
|
266
|
+
var BaseResource = class {
|
|
267
|
+
constructor(transport) {
|
|
268
|
+
this.transport = transport;
|
|
269
|
+
}
|
|
270
|
+
transport;
|
|
271
|
+
async call(args) {
|
|
272
|
+
const ep = ENDPOINTS[args.operation];
|
|
273
|
+
let body;
|
|
274
|
+
if (args.requestSchema && args.input !== void 0) {
|
|
275
|
+
const parsed = args.requestSchema.safeParse(args.input);
|
|
276
|
+
if (!parsed.success) throw new PostNLValidationError("invalid request", parsed.error.issues);
|
|
277
|
+
body = parsed.data;
|
|
278
|
+
} else {
|
|
279
|
+
body = args.input;
|
|
280
|
+
}
|
|
281
|
+
const raw = await this.transport.send({
|
|
282
|
+
family: ep.family,
|
|
283
|
+
method: ep.method,
|
|
284
|
+
path: ep.path,
|
|
285
|
+
pathParams: args.pathParams,
|
|
286
|
+
query: args.query,
|
|
287
|
+
body: ep.method === "GET" ? void 0 : body
|
|
288
|
+
});
|
|
289
|
+
const out = args.responseSchema.safeParse(raw);
|
|
290
|
+
if (!out.success) throw new PostNLValidationError("invalid response", out.error.issues);
|
|
291
|
+
return out.data;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
function pnlArray(inner) {
|
|
295
|
+
return zod.z.preprocess((v) => {
|
|
296
|
+
if (v == null) return [];
|
|
297
|
+
if (Array.isArray(v)) return v;
|
|
298
|
+
if (typeof v === "object" && v !== null && "string" in v) {
|
|
299
|
+
const wrapped = v.string;
|
|
300
|
+
return Array.isArray(wrapped) ? wrapped : [wrapped];
|
|
301
|
+
}
|
|
302
|
+
return [v];
|
|
303
|
+
}, zod.z.array(inner));
|
|
304
|
+
}
|
|
305
|
+
function pnlStringWrapped(inner) {
|
|
306
|
+
return zod.z.preprocess((v) => {
|
|
307
|
+
if (v != null && typeof v === "object" && "string" in v) {
|
|
308
|
+
return v.string;
|
|
309
|
+
}
|
|
310
|
+
return v;
|
|
311
|
+
}, inner);
|
|
312
|
+
}
|
|
313
|
+
function pnlNum() {
|
|
314
|
+
return zod.z.preprocess(
|
|
315
|
+
(v) => typeof v === "string" && v.trim() !== "" ? Number(v) : v,
|
|
316
|
+
zod.z.number()
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/core/codec/object.ts
|
|
321
|
+
var stripUndefined = (obj) => {
|
|
322
|
+
const out = {};
|
|
323
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
324
|
+
if (v !== void 0) out[k] = v;
|
|
325
|
+
}
|
|
326
|
+
return out;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/resources/address/schema.ts
|
|
330
|
+
var postalcodeCheckAddressSchema = zod.z.object({
|
|
331
|
+
city: zod.z.string().optional(),
|
|
332
|
+
postalCode: zod.z.string().optional(),
|
|
333
|
+
streetName: zod.z.string().optional(),
|
|
334
|
+
houseNumber: pnlNum().optional(),
|
|
335
|
+
houseNumberAddition: zod.z.string().optional(),
|
|
336
|
+
formattedAddress: pnlArray(zod.z.string()).optional()
|
|
337
|
+
}).transform(
|
|
338
|
+
(a) => stripUndefined({
|
|
339
|
+
city: a.city,
|
|
340
|
+
postalCode: a.postalCode,
|
|
341
|
+
streetName: a.streetName,
|
|
342
|
+
houseNumber: a.houseNumber,
|
|
343
|
+
houseNumberAddition: a.houseNumberAddition,
|
|
344
|
+
formattedAddress: a.formattedAddress?.length ? a.formattedAddress : void 0
|
|
345
|
+
})
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
// src/resources/address/index.ts
|
|
349
|
+
var AddressResource = class extends BaseResource {
|
|
350
|
+
constructor(transport, environment) {
|
|
351
|
+
super(transport);
|
|
352
|
+
this.environment = environment;
|
|
353
|
+
}
|
|
354
|
+
environment;
|
|
355
|
+
// GET /shipment/checkout/v1/postalcodecheck
|
|
356
|
+
check(input) {
|
|
357
|
+
if (this.environment === "sandbox") {
|
|
358
|
+
return Promise.reject(
|
|
359
|
+
new PostNLError("address.check is production-only and not available on sandbox")
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
return this.call({
|
|
363
|
+
operation: "addressCheck",
|
|
364
|
+
query: {
|
|
365
|
+
postalcode: input.postalCode,
|
|
366
|
+
housenumber: String(input.houseNumber),
|
|
367
|
+
housenumberaddition: input.houseNumberAddition
|
|
368
|
+
},
|
|
369
|
+
responseSchema: postalcodeCheckAddressSchema
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var responseSchema = zod.z.object({ Barcode: zod.z.string() }).transform((r) => ({ barcode: r.Barcode }));
|
|
374
|
+
var BarcodeLegacyResource = class extends BaseResource {
|
|
375
|
+
generate(input) {
|
|
376
|
+
return this.call({
|
|
377
|
+
operation: "barcodeLegacy",
|
|
378
|
+
query: {
|
|
379
|
+
CustomerCode: input.customerCode,
|
|
380
|
+
CustomerNumber: input.customerNumber,
|
|
381
|
+
Type: input.type,
|
|
382
|
+
Serie: input.serie,
|
|
383
|
+
Range: input.range
|
|
384
|
+
},
|
|
385
|
+
responseSchema
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var barcodeV4RequestSchema = zod.z.object({
|
|
390
|
+
customerNumber: zod.z.string(),
|
|
391
|
+
customerCode: zod.z.string(),
|
|
392
|
+
serieStart: zod.z.string().default("000000000"),
|
|
393
|
+
serieEnd: zod.z.string().default("999999999"),
|
|
394
|
+
numberOfBarcodes: zod.z.number().int().min(1).default(1)
|
|
395
|
+
});
|
|
396
|
+
var barcodeV4ResponseSchema = zod.z.object({
|
|
397
|
+
barcodes: zod.z.array(zod.z.string()).default([])
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// src/resources/barcode/index.ts
|
|
401
|
+
var BarcodeResource = class extends BaseResource {
|
|
402
|
+
// legacy barcode generation (GET /shipment/v1_1/barcode)
|
|
403
|
+
legacy = new BarcodeLegacyResource(this.transport);
|
|
404
|
+
// v4 server-side barcode generation
|
|
405
|
+
generate(input) {
|
|
406
|
+
return this.call({
|
|
407
|
+
operation: "barcodeV4",
|
|
408
|
+
input,
|
|
409
|
+
requestSchema: barcodeV4RequestSchema,
|
|
410
|
+
responseSchema: barcodeV4ResponseSchema
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// src/core/codec/dates.ts
|
|
416
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
417
|
+
var num = (v) => Number(v ?? 0);
|
|
418
|
+
var ISO = /^\d{4}-\d{2}-\d{2}$/;
|
|
419
|
+
var NL_DATE = /^\d{2}-\d{2}-\d{4}$/;
|
|
420
|
+
var NL_DATETIME = /^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}$/;
|
|
421
|
+
function parsePnlDate(input) {
|
|
422
|
+
const trimmed = input.trim();
|
|
423
|
+
const [datePart = "", timePart] = trimmed.split(" ");
|
|
424
|
+
let y;
|
|
425
|
+
let mo;
|
|
426
|
+
let d;
|
|
427
|
+
if (ISO.test(trimmed)) {
|
|
428
|
+
const [yy, mm, dd] = datePart.split("-");
|
|
429
|
+
y = num(yy);
|
|
430
|
+
mo = num(mm);
|
|
431
|
+
d = num(dd);
|
|
432
|
+
} else if (NL_DATE.test(trimmed) || NL_DATETIME.test(trimmed)) {
|
|
433
|
+
const [dd, mm, yy] = datePart.split("-");
|
|
434
|
+
y = num(yy);
|
|
435
|
+
mo = num(mm);
|
|
436
|
+
d = num(dd);
|
|
437
|
+
} else {
|
|
438
|
+
throw new Error(`invalid postnl date: ${input}`);
|
|
439
|
+
}
|
|
440
|
+
const [hh, mi, ss] = (timePart ?? "00:00:00").split(":");
|
|
441
|
+
return new Date(y, mo - 1, d, num(hh), num(mi), num(ss));
|
|
442
|
+
}
|
|
443
|
+
function formatDate(date, kind) {
|
|
444
|
+
const d = `${pad(date.getDate())}-${pad(date.getMonth() + 1)}-${date.getFullYear()}`;
|
|
445
|
+
if (kind === "date") return d;
|
|
446
|
+
return `${d} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
447
|
+
}
|
|
448
|
+
function formatIsoDate(date) {
|
|
449
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
450
|
+
}
|
|
451
|
+
var pnlDateField = zod.z.string().optional().transform((v) => v == null ? void 0 : parsePnlDate(v));
|
|
452
|
+
var sustainabilitySchema = zod.z.object({ Code: zod.z.string().optional(), Description: zod.z.string().optional() }).transform((s) => stripUndefined({ code: s.Code, description: s.Description }));
|
|
453
|
+
|
|
454
|
+
// src/resources/checkout/schema.ts
|
|
455
|
+
function toCheckoutRequestBody(input, orderDate) {
|
|
456
|
+
return stripUndefined({
|
|
457
|
+
OrderDate: orderDate,
|
|
458
|
+
CutOffTimes: input.cutOffTimes.map(
|
|
459
|
+
(c) => stripUndefined({ Day: c.day, Available: c.available, Type: c.type, Time: c.time })
|
|
460
|
+
),
|
|
461
|
+
Options: [...input.options],
|
|
462
|
+
Locations: input.locations,
|
|
463
|
+
Days: input.days,
|
|
464
|
+
Addresses: input.addresses.map(
|
|
465
|
+
(a) => stripUndefined({
|
|
466
|
+
AddressType: a.addressType,
|
|
467
|
+
HouseNr: a.houseNr,
|
|
468
|
+
Zipcode: a.zipcode,
|
|
469
|
+
Countrycode: a.countrycode,
|
|
470
|
+
Street: a.street,
|
|
471
|
+
HouseNrExt: a.houseNrExt,
|
|
472
|
+
City: a.city
|
|
473
|
+
})
|
|
474
|
+
),
|
|
475
|
+
ShippingDuration: input.shippingDuration,
|
|
476
|
+
HolidaySorting: input.holidaySorting
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
var timeframeSchema = zod.z.object({
|
|
480
|
+
From: zod.z.string().optional(),
|
|
481
|
+
To: zod.z.string().optional(),
|
|
482
|
+
Options: pnlArray(zod.z.string()),
|
|
483
|
+
ShippingDate: pnlDateField,
|
|
484
|
+
Sustainability: sustainabilitySchema.optional()
|
|
485
|
+
}).transform(
|
|
486
|
+
(t) => stripUndefined({
|
|
487
|
+
from: t.From,
|
|
488
|
+
to: t.To,
|
|
489
|
+
options: t.Options.length ? t.Options : void 0,
|
|
490
|
+
shippingDate: t.ShippingDate,
|
|
491
|
+
sustainability: t.Sustainability
|
|
492
|
+
})
|
|
493
|
+
);
|
|
494
|
+
var deliveryOptionSchema = zod.z.object({
|
|
495
|
+
DeliveryDate: pnlDateField,
|
|
496
|
+
Timeframe: pnlArray(timeframeSchema)
|
|
497
|
+
}).transform((d) => ({
|
|
498
|
+
...stripUndefined({ deliveryDate: d.DeliveryDate }),
|
|
499
|
+
timeframe: d.Timeframe
|
|
500
|
+
}));
|
|
501
|
+
var pickupAddressSchema = zod.z.object({
|
|
502
|
+
Street: zod.z.string().optional(),
|
|
503
|
+
Zipcode: zod.z.string().optional(),
|
|
504
|
+
HouseNr: pnlNum().optional(),
|
|
505
|
+
HouseNrExt: zod.z.string().optional(),
|
|
506
|
+
Countrycode: zod.z.string().optional(),
|
|
507
|
+
CompanyName: zod.z.string().optional()
|
|
508
|
+
}).transform(
|
|
509
|
+
(a) => stripUndefined({
|
|
510
|
+
street: a.Street,
|
|
511
|
+
zipcode: a.Zipcode,
|
|
512
|
+
houseNr: a.HouseNr,
|
|
513
|
+
houseNrExt: a.HouseNrExt,
|
|
514
|
+
countrycode: a.Countrycode,
|
|
515
|
+
companyName: a.CompanyName
|
|
516
|
+
})
|
|
517
|
+
);
|
|
518
|
+
var openingHoursPerDaySchema = zod.z.object({ From: zod.z.string().optional(), To: zod.z.string().optional() }).transform((d) => stripUndefined({ from: d.From, to: d.To }));
|
|
519
|
+
var day = openingHoursPerDaySchema.optional();
|
|
520
|
+
var pickupOpeningHoursSchema = zod.z.object({
|
|
521
|
+
Monday: day,
|
|
522
|
+
Tuesday: day,
|
|
523
|
+
Wednesday: day,
|
|
524
|
+
Thursday: day,
|
|
525
|
+
Friday: day,
|
|
526
|
+
Saturday: day,
|
|
527
|
+
Sunday: day
|
|
528
|
+
}).transform(
|
|
529
|
+
(o) => stripUndefined({
|
|
530
|
+
monday: o.Monday,
|
|
531
|
+
tuesday: o.Tuesday,
|
|
532
|
+
wednesday: o.Wednesday,
|
|
533
|
+
thursday: o.Thursday,
|
|
534
|
+
friday: o.Friday,
|
|
535
|
+
saturday: o.Saturday,
|
|
536
|
+
sunday: o.Sunday
|
|
537
|
+
})
|
|
538
|
+
);
|
|
539
|
+
var checkoutLocationSchema = zod.z.object({
|
|
540
|
+
Address: pickupAddressSchema.optional(),
|
|
541
|
+
PickupTime: zod.z.string().optional(),
|
|
542
|
+
OpeningHours: pickupOpeningHoursSchema.optional(),
|
|
543
|
+
Distance: pnlNum().optional(),
|
|
544
|
+
LocationCode: zod.z.string().optional(),
|
|
545
|
+
PartnerID: zod.z.string().optional(),
|
|
546
|
+
Sustainability: sustainabilitySchema.optional()
|
|
547
|
+
}).transform(
|
|
548
|
+
(l) => stripUndefined({
|
|
549
|
+
address: l.Address,
|
|
550
|
+
pickupTime: l.PickupTime,
|
|
551
|
+
openingHours: l.OpeningHours,
|
|
552
|
+
distance: l.Distance,
|
|
553
|
+
locationCode: l.LocationCode,
|
|
554
|
+
partnerId: l.PartnerID,
|
|
555
|
+
sustainability: l.Sustainability
|
|
556
|
+
})
|
|
557
|
+
);
|
|
558
|
+
var pickupOptionSchema = zod.z.object({
|
|
559
|
+
PickupDate: pnlDateField,
|
|
560
|
+
ShippingDate: pnlDateField,
|
|
561
|
+
Option: zod.z.string().optional(),
|
|
562
|
+
Locations: pnlArray(checkoutLocationSchema)
|
|
563
|
+
}).transform((p) => ({
|
|
564
|
+
...stripUndefined({
|
|
565
|
+
pickupDate: p.PickupDate,
|
|
566
|
+
shippingDate: p.ShippingDate,
|
|
567
|
+
option: p.Option
|
|
568
|
+
}),
|
|
569
|
+
locations: p.Locations
|
|
570
|
+
}));
|
|
571
|
+
var warningSchema = zod.z.object({
|
|
572
|
+
DeliveryDate: pnlDateField,
|
|
573
|
+
Code: zod.z.string().optional(),
|
|
574
|
+
Description: zod.z.string().optional(),
|
|
575
|
+
Options: zod.z.string().optional()
|
|
576
|
+
}).transform(
|
|
577
|
+
(w) => stripUndefined({
|
|
578
|
+
deliveryDate: w.DeliveryDate,
|
|
579
|
+
code: w.Code,
|
|
580
|
+
description: w.Description,
|
|
581
|
+
options: w.Options
|
|
582
|
+
})
|
|
583
|
+
);
|
|
584
|
+
var checkoutResponseSchema = zod.z.object({
|
|
585
|
+
DeliveryOptions: pnlArray(deliveryOptionSchema),
|
|
586
|
+
PickupOptions: pnlArray(pickupOptionSchema),
|
|
587
|
+
Warnings: pnlArray(warningSchema)
|
|
588
|
+
}).transform((r) => ({
|
|
589
|
+
deliveryOptions: r.DeliveryOptions,
|
|
590
|
+
pickupOptions: r.PickupOptions,
|
|
591
|
+
warnings: r.Warnings
|
|
592
|
+
}));
|
|
593
|
+
|
|
594
|
+
// src/resources/checkout/index.ts
|
|
595
|
+
var asDateTime = (v) => v instanceof Date ? formatDate(v, "datetime") : v;
|
|
596
|
+
var CheckoutResource = class extends BaseResource {
|
|
597
|
+
// POST /shipment/v1/checkout
|
|
598
|
+
get(input) {
|
|
599
|
+
return this.call({
|
|
600
|
+
operation: "checkoutGet",
|
|
601
|
+
input: toCheckoutRequestBody(input, asDateTime(input.orderDate)),
|
|
602
|
+
responseSchema: checkoutResponseSchema
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
var deliveryDateResponseSchema = zod.z.object({
|
|
607
|
+
DeliveryDate: pnlDateField,
|
|
608
|
+
Options: pnlArray(zod.z.string()),
|
|
609
|
+
Sustainability: sustainabilitySchema.optional()
|
|
610
|
+
}).transform(
|
|
611
|
+
(r) => stripUndefined({
|
|
612
|
+
deliveryDate: r.DeliveryDate,
|
|
613
|
+
options: r.Options.length ? r.Options : void 0,
|
|
614
|
+
sustainability: r.Sustainability
|
|
615
|
+
})
|
|
616
|
+
);
|
|
617
|
+
var sentDateResponseSchema = zod.z.object({
|
|
618
|
+
SentDate: pnlDateField,
|
|
619
|
+
Options: pnlArray(zod.z.string())
|
|
620
|
+
}).transform(
|
|
621
|
+
(r) => stripUndefined({
|
|
622
|
+
sentDate: r.SentDate,
|
|
623
|
+
options: r.Options.length ? r.Options : void 0
|
|
624
|
+
})
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
// src/resources/delivery-date/index.ts
|
|
628
|
+
var WEEKDAYS = [
|
|
629
|
+
"Monday",
|
|
630
|
+
"Tuesday",
|
|
631
|
+
"Wednesday",
|
|
632
|
+
"Thursday",
|
|
633
|
+
"Friday",
|
|
634
|
+
"Saturday",
|
|
635
|
+
"Sunday"
|
|
636
|
+
];
|
|
637
|
+
var asDateTime2 = (v) => v instanceof Date ? formatDate(v, "datetime") : v;
|
|
638
|
+
var asDate = (v) => v instanceof Date ? formatDate(v, "date") : v;
|
|
639
|
+
var DeliveryDateResource = class extends BaseResource {
|
|
640
|
+
// GET /shipment/v2_2/calculate/date/delivery
|
|
641
|
+
calculate(input) {
|
|
642
|
+
const query = {
|
|
643
|
+
ShippingDate: asDateTime2(input.shippingDate),
|
|
644
|
+
ShippingDuration: input.shippingDuration,
|
|
645
|
+
CutOffTime: input.cutOffTime,
|
|
646
|
+
PostalCode: input.postalCode,
|
|
647
|
+
CountryCode: input.countryCode,
|
|
648
|
+
Options: input.options.join(","),
|
|
649
|
+
OriginCountryCode: input.originCountryCode ?? "NL",
|
|
650
|
+
City: input.city,
|
|
651
|
+
Street: input.street,
|
|
652
|
+
HouseNumber: input.houseNumber,
|
|
653
|
+
HouseNrExt: input.houseNrExt
|
|
654
|
+
};
|
|
655
|
+
for (const day3 of WEEKDAYS) {
|
|
656
|
+
query[`CutOffTime${day3}`] = input[`cutOffTime${day3}`];
|
|
657
|
+
query[`Available${day3}`] = input[`available${day3}`];
|
|
658
|
+
}
|
|
659
|
+
return this.call({
|
|
660
|
+
operation: "deliveryDateCalculate",
|
|
661
|
+
query,
|
|
662
|
+
responseSchema: deliveryDateResponseSchema
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
// GET /shipment/v2_2/calculate/date/shipping
|
|
666
|
+
sentDate(input) {
|
|
667
|
+
return this.call({
|
|
668
|
+
operation: "deliveryDateSent",
|
|
669
|
+
query: {
|
|
670
|
+
DeliveryDate: asDate(input.deliveryDate),
|
|
671
|
+
ShippingDuration: input.shippingDuration,
|
|
672
|
+
PostalCode: input.postalCode,
|
|
673
|
+
CountryCode: input.countryCode,
|
|
674
|
+
OriginCountryCode: input.originCountryCode ?? "NL",
|
|
675
|
+
City: input.city,
|
|
676
|
+
Street: input.street,
|
|
677
|
+
HouseNumber: input.houseNumber,
|
|
678
|
+
HouseNrExt: input.houseNrExt
|
|
679
|
+
},
|
|
680
|
+
responseSchema: sentDateResponseSchema
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
// src/constants/enums.ts
|
|
686
|
+
var BarcodeType = ["2S", "3S", "CC", "CP", "CD", "CF", "LA", "RI", "UE"];
|
|
687
|
+
var ShipmentTypeV4 = [
|
|
688
|
+
"parcel",
|
|
689
|
+
"letterbox",
|
|
690
|
+
"packet",
|
|
691
|
+
"parcelnonstandard",
|
|
692
|
+
"letter"
|
|
693
|
+
];
|
|
694
|
+
var ReturnShipmentTypeV4 = ["parcel", "letterbox", "packet", "parcelnonstandard"];
|
|
695
|
+
var ReceiverType = ["business", "consumer"];
|
|
696
|
+
var OutputType = ["zpl", "pdf", "gif", "jpg", "png"];
|
|
697
|
+
var ReturnOutputType = ["pdf", "gif", "jpg", "png"];
|
|
698
|
+
var PageOrientation = ["portrait", "landscape"];
|
|
699
|
+
var Resolution = [200, 300, 600];
|
|
700
|
+
var MergeType = ["singlepdf", "pdfa6toa4"];
|
|
701
|
+
var Positioning = ["topleft", "topright", "bottomleft", "bottomright"];
|
|
702
|
+
var PrintMethod = ["consumerPrint", "retailPrint"];
|
|
703
|
+
var LabelType = ["labelinthebox"];
|
|
704
|
+
var ReturnPeriod = [35, 100, 200, 365];
|
|
705
|
+
var ReturnPeriodV4 = [20, 35];
|
|
706
|
+
var Bundle = ["track_trace", "insured", "insured_plus"];
|
|
707
|
+
var Language = ["NL", "FR", "EN"];
|
|
708
|
+
var StatusLanguage = ["NL", "EN", "CN", "DE", "FR"];
|
|
709
|
+
var MinimalAgeCheck = ["16+", "18+"];
|
|
710
|
+
var DeliveryConfirmation = ["signature", "deliverycode"];
|
|
711
|
+
var GuaranteedBefore = ["10:00", "12:00", "17:00"];
|
|
712
|
+
var Duration = ["24hours", "non24hours"];
|
|
713
|
+
var ConsolidationMode = ["none", "bulk"];
|
|
714
|
+
var NetworkType = ["commercial", "postal"];
|
|
715
|
+
var AssociatedDocumentType = ["certificate", "invoice", "license"];
|
|
716
|
+
var CountryCode = ["NL", "BE"];
|
|
717
|
+
var OriginCountryCode = ["NL", "BE"];
|
|
718
|
+
var Currency = ["EUR", "GBP", "USD", "CNY"];
|
|
719
|
+
var LabellingCurrency = ["EUR", "USS"];
|
|
720
|
+
var AddressType = ["01", "02"];
|
|
721
|
+
var ShipmentTypeLegacy = [
|
|
722
|
+
"Gift",
|
|
723
|
+
"Documents",
|
|
724
|
+
"Commercial Goods",
|
|
725
|
+
"Commercial Sample",
|
|
726
|
+
"Returned Goods"
|
|
727
|
+
];
|
|
728
|
+
var DeliverydateOption = [
|
|
729
|
+
"Daytime",
|
|
730
|
+
"Evening",
|
|
731
|
+
"Morning",
|
|
732
|
+
"Noon",
|
|
733
|
+
"Sunday",
|
|
734
|
+
"Today",
|
|
735
|
+
"Afternoon"
|
|
736
|
+
];
|
|
737
|
+
var TimeframeOption = [
|
|
738
|
+
"Daytime",
|
|
739
|
+
"Today",
|
|
740
|
+
"Sameday",
|
|
741
|
+
"Evening",
|
|
742
|
+
"Morning",
|
|
743
|
+
"Noon",
|
|
744
|
+
"Sunday",
|
|
745
|
+
"Afternoon"
|
|
746
|
+
];
|
|
747
|
+
var CheckoutOption = [
|
|
748
|
+
"Daytime",
|
|
749
|
+
"Evening",
|
|
750
|
+
"Sunday",
|
|
751
|
+
"Sameday",
|
|
752
|
+
"Today",
|
|
753
|
+
"08:00-10:00",
|
|
754
|
+
"08:00-12:00",
|
|
755
|
+
"08:00-17:00",
|
|
756
|
+
"Pickup"
|
|
757
|
+
];
|
|
758
|
+
var CheckoutWarningOption = [
|
|
759
|
+
"Daytime",
|
|
760
|
+
"Evening",
|
|
761
|
+
"Sameday",
|
|
762
|
+
"Sunday",
|
|
763
|
+
"Today",
|
|
764
|
+
"08:00-10:00",
|
|
765
|
+
"08:00-12:00",
|
|
766
|
+
"08:00-17:00",
|
|
767
|
+
"08:00-09:00",
|
|
768
|
+
"Pickup"
|
|
769
|
+
];
|
|
770
|
+
var CheckoutCutOffDay = ["00", "01", "02", "03", "04", "05", "06", "07"];
|
|
771
|
+
var CheckoutCutOffType = ["Regular", "Sameday", "Today"];
|
|
772
|
+
var LocationDeliveryOption = ["PG", "PA", "PG_EX"];
|
|
773
|
+
var IGNORED_LOCATION_OPTIONS = ["RETA", "UL", "PU", "DO", "BW", "RT", "BWUL"];
|
|
774
|
+
var SustainabilityCode = ["00", "01", "02", "03"];
|
|
775
|
+
var Service = ["evening"];
|
|
776
|
+
|
|
777
|
+
// src/resources/location/schema.ts
|
|
778
|
+
var IGNORED = new Set(IGNORED_LOCATION_OPTIONS);
|
|
779
|
+
var addressSchema = zod.z.object({
|
|
780
|
+
City: zod.z.string().optional(),
|
|
781
|
+
Countrycode: zod.z.string().optional(),
|
|
782
|
+
HouseNr: pnlNum().optional(),
|
|
783
|
+
HouseNrExt: zod.z.string().optional(),
|
|
784
|
+
Remark: zod.z.string().optional(),
|
|
785
|
+
Street: zod.z.string().optional(),
|
|
786
|
+
Zipcode: zod.z.string().optional()
|
|
787
|
+
}).transform(
|
|
788
|
+
(a) => stripUndefined({
|
|
789
|
+
city: a.City,
|
|
790
|
+
countrycode: a.Countrycode,
|
|
791
|
+
houseNr: a.HouseNr,
|
|
792
|
+
houseNrExt: a.HouseNrExt,
|
|
793
|
+
remark: a.Remark,
|
|
794
|
+
street: a.Street,
|
|
795
|
+
zipcode: a.Zipcode
|
|
796
|
+
})
|
|
797
|
+
);
|
|
798
|
+
var day2 = pnlStringWrapped(zod.z.string()).optional();
|
|
799
|
+
var openingHoursSchema = zod.z.object({
|
|
800
|
+
Monday: day2,
|
|
801
|
+
Tuesday: day2,
|
|
802
|
+
Wednesday: day2,
|
|
803
|
+
Thursday: day2,
|
|
804
|
+
Friday: day2,
|
|
805
|
+
Saturday: day2,
|
|
806
|
+
Sunday: day2
|
|
807
|
+
}).transform(
|
|
808
|
+
(o) => stripUndefined({
|
|
809
|
+
monday: o.Monday,
|
|
810
|
+
tuesday: o.Tuesday,
|
|
811
|
+
wednesday: o.Wednesday,
|
|
812
|
+
thursday: o.Thursday,
|
|
813
|
+
friday: o.Friday,
|
|
814
|
+
saturday: o.Saturday,
|
|
815
|
+
sunday: o.Sunday
|
|
816
|
+
})
|
|
817
|
+
);
|
|
818
|
+
var locationSchema = zod.z.object({
|
|
819
|
+
Address: addressSchema.optional(),
|
|
820
|
+
DeliveryOptions: pnlArray(zod.z.string()),
|
|
821
|
+
Distance: pnlNum().optional(),
|
|
822
|
+
Latitude: pnlNum().optional(),
|
|
823
|
+
LocationCode: pnlNum().optional(),
|
|
824
|
+
Longitude: pnlNum().optional(),
|
|
825
|
+
Name: zod.z.string().optional(),
|
|
826
|
+
OpeningHours: openingHoursSchema.optional(),
|
|
827
|
+
Sustainability: sustainabilitySchema.optional(),
|
|
828
|
+
PartnerName: zod.z.string().optional(),
|
|
829
|
+
RetailNetworkID: zod.z.string().optional()
|
|
830
|
+
}).transform((l) => {
|
|
831
|
+
const deliveryOptions = l.DeliveryOptions.filter((o) => !IGNORED.has(o));
|
|
832
|
+
return stripUndefined({
|
|
833
|
+
address: l.Address,
|
|
834
|
+
deliveryOptions: deliveryOptions.length ? deliveryOptions : void 0,
|
|
835
|
+
distance: l.Distance,
|
|
836
|
+
latitude: l.Latitude,
|
|
837
|
+
locationCode: l.LocationCode,
|
|
838
|
+
longitude: l.Longitude,
|
|
839
|
+
name: l.Name,
|
|
840
|
+
openingHours: l.OpeningHours,
|
|
841
|
+
sustainability: l.Sustainability,
|
|
842
|
+
partnerName: l.PartnerName,
|
|
843
|
+
retailNetworkId: l.RetailNetworkID
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
var locationsResponseSchema = zod.z.object({
|
|
847
|
+
GetLocationsResult: zod.z.object({ ResponseLocation: pnlArray(locationSchema) }).optional().transform((r) => r?.ResponseLocation ?? [])
|
|
848
|
+
}).transform((r) => ({ locations: r.GetLocationsResult }));
|
|
849
|
+
var locationLookupResponseSchema = zod.z.object({
|
|
850
|
+
GetLocationsResult: zod.z.object({ ResponseLocation: locationSchema.optional() }).optional().transform((r) => r?.ResponseLocation)
|
|
851
|
+
}).transform((r) => stripUndefined({ location: r.GetLocationsResult }));
|
|
852
|
+
|
|
853
|
+
// src/resources/location/index.ts
|
|
854
|
+
var asDate2 = (v) => v instanceof Date ? formatDate(v, "date") : v;
|
|
855
|
+
var LocationResource = class extends BaseResource {
|
|
856
|
+
// GET /shipment/v2_1/locations/nearest
|
|
857
|
+
nearest(input) {
|
|
858
|
+
return this.call({
|
|
859
|
+
operation: "locationNearest",
|
|
860
|
+
query: {
|
|
861
|
+
CountryCode: input.countryCode,
|
|
862
|
+
PostalCode: input.postalCode,
|
|
863
|
+
City: input.city,
|
|
864
|
+
Street: input.street,
|
|
865
|
+
HouseNumber: input.houseNumber,
|
|
866
|
+
HouseNumberExtension: input.houseNumberExtension,
|
|
867
|
+
DeliveryDate: asDate2(input.deliveryDate),
|
|
868
|
+
OpeningTime: input.openingTime,
|
|
869
|
+
DeliveryOptions: input.deliveryOptions?.join(",")
|
|
870
|
+
},
|
|
871
|
+
responseSchema: locationsResponseSchema
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
// GET /shipment/v2_1/locations/nearest/geocode
|
|
875
|
+
nearestByGeocode(input) {
|
|
876
|
+
return this.call({
|
|
877
|
+
operation: "locationNearestByGeocode",
|
|
878
|
+
query: {
|
|
879
|
+
Latitude: input.latitude,
|
|
880
|
+
Longitude: input.longitude,
|
|
881
|
+
CountryCode: input.countryCode,
|
|
882
|
+
DeliveryDate: asDate2(input.deliveryDate),
|
|
883
|
+
OpeningTime: input.openingTime,
|
|
884
|
+
DeliveryOptions: input.deliveryOptions?.join(",")
|
|
885
|
+
},
|
|
886
|
+
responseSchema: locationsResponseSchema
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
// GET /shipment/v2_1/locations/area
|
|
890
|
+
area(input) {
|
|
891
|
+
return this.call({
|
|
892
|
+
operation: "locationArea",
|
|
893
|
+
query: {
|
|
894
|
+
LatitudeNorth: input.latitudeNorth,
|
|
895
|
+
LongitudeWest: input.longitudeWest,
|
|
896
|
+
LatitudeSouth: input.latitudeSouth,
|
|
897
|
+
LongitudeEast: input.longitudeEast,
|
|
898
|
+
CountryCode: input.countryCode,
|
|
899
|
+
DeliveryDate: asDate2(input.deliveryDate),
|
|
900
|
+
OpeningTime: input.openingTime,
|
|
901
|
+
DeliveryOptions: input.deliveryOptions?.join(",")
|
|
902
|
+
},
|
|
903
|
+
responseSchema: locationsResponseSchema
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
// GET /shipment/v2_1/locations/lookup
|
|
907
|
+
lookup(input) {
|
|
908
|
+
return this.call({
|
|
909
|
+
operation: "locationLookup",
|
|
910
|
+
query: { LocationCode: String(input.locationCode) },
|
|
911
|
+
responseSchema: locationLookupResponseSchema
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
// src/core/base64.ts
|
|
917
|
+
function decodeBase64(b64) {
|
|
918
|
+
const fromBase64 = Uint8Array.fromBase64;
|
|
919
|
+
if (fromBase64) return fromBase64(b64);
|
|
920
|
+
const bin = atob(b64);
|
|
921
|
+
const out = new Uint8Array(bin.length);
|
|
922
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
923
|
+
return out;
|
|
924
|
+
}
|
|
925
|
+
var CONTENT_TYPES = {
|
|
926
|
+
pdf: "application/pdf",
|
|
927
|
+
gif: "image/gif",
|
|
928
|
+
jpg: "image/jpeg",
|
|
929
|
+
jpeg: "image/jpeg",
|
|
930
|
+
png: "image/png",
|
|
931
|
+
zpl: "text/plain"
|
|
932
|
+
};
|
|
933
|
+
function labelContentType(outputType) {
|
|
934
|
+
return CONTENT_TYPES[outputType.toLowerCase()] ?? "application/octet-stream";
|
|
935
|
+
}
|
|
936
|
+
function toDecodedLabel(base64, outputType) {
|
|
937
|
+
return { base64, contentType: labelContentType(outputType), bytes: () => decodeBase64(base64) };
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// src/resources/shipping/schema.ts
|
|
941
|
+
var isoDate = zod.z.preprocess(
|
|
942
|
+
(v) => v instanceof Date ? Number.isNaN(v.getTime()) ? v : formatIsoDate(v) : v,
|
|
943
|
+
zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/)
|
|
944
|
+
);
|
|
945
|
+
var internationalAddressDataSchema = zod.z.object({
|
|
946
|
+
area: zod.z.string().optional(),
|
|
947
|
+
buildingName: zod.z.string().optional(),
|
|
948
|
+
doorCode: zod.z.string().optional(),
|
|
949
|
+
floor: zod.z.string().optional(),
|
|
950
|
+
region: zod.z.string().optional()
|
|
951
|
+
});
|
|
952
|
+
var addressV4Schema = zod.z.object({
|
|
953
|
+
countryIso: zod.z.string(),
|
|
954
|
+
city: zod.z.string().optional(),
|
|
955
|
+
companyName: zod.z.string().optional(),
|
|
956
|
+
departmentName: zod.z.string().optional(),
|
|
957
|
+
houseNumber: zod.z.string().optional(),
|
|
958
|
+
houseNumberAddition: zod.z.string().optional(),
|
|
959
|
+
postalCode: zod.z.string().optional(),
|
|
960
|
+
street: zod.z.string().optional(),
|
|
961
|
+
addressLine: zod.z.string().optional(),
|
|
962
|
+
internationalAddressData: internationalAddressDataSchema.optional()
|
|
963
|
+
});
|
|
964
|
+
var contactV4Schema = zod.z.object({
|
|
965
|
+
email: zod.z.string().optional(),
|
|
966
|
+
firstName: zod.z.string().optional(),
|
|
967
|
+
lastName: zod.z.string().optional(),
|
|
968
|
+
language: zod.z.enum(Language).optional(),
|
|
969
|
+
mobileNumber: zod.z.string().optional()
|
|
970
|
+
});
|
|
971
|
+
var receiverV4Schema = zod.z.object({
|
|
972
|
+
address: addressV4Schema,
|
|
973
|
+
contact: contactV4Schema.optional(),
|
|
974
|
+
type: zod.z.enum(ReceiverType).optional()
|
|
975
|
+
});
|
|
976
|
+
var senderV4Schema = zod.z.object({
|
|
977
|
+
customerNumber: zod.z.string(),
|
|
978
|
+
customerCode: zod.z.string(),
|
|
979
|
+
address: addressV4Schema,
|
|
980
|
+
contact: contactV4Schema.optional(),
|
|
981
|
+
undeliverableReturnAddress: addressV4Schema.optional()
|
|
982
|
+
});
|
|
983
|
+
var dimensionsSchema = zod.z.object({
|
|
984
|
+
length: zod.z.number().int().optional(),
|
|
985
|
+
width: zod.z.number().int().optional(),
|
|
986
|
+
height: zod.z.number().int().optional(),
|
|
987
|
+
volume: zod.z.number().int().optional(),
|
|
988
|
+
weight: zod.z.number().int().optional()
|
|
989
|
+
});
|
|
990
|
+
var customerReferencesSchema = zod.z.object({
|
|
991
|
+
shipmentReference: zod.z.string().optional(),
|
|
992
|
+
costCenter: zod.z.string().optional(),
|
|
993
|
+
returnReference: zod.z.string().optional()
|
|
994
|
+
});
|
|
995
|
+
var itemV4Schema = zod.z.object({
|
|
996
|
+
barcode: zod.z.string().optional(),
|
|
997
|
+
dimensions: dimensionsSchema.optional(),
|
|
998
|
+
customerReferences: customerReferencesSchema.optional()
|
|
999
|
+
});
|
|
1000
|
+
var labelSettingsSchema = zod.z.object({
|
|
1001
|
+
outputType: zod.z.enum(OutputType).optional(),
|
|
1002
|
+
pageOrientation: zod.z.enum(PageOrientation).default("portrait"),
|
|
1003
|
+
resolution: zod.z.union([zod.z.literal(200), zod.z.literal(300), zod.z.literal(600)]).default(200),
|
|
1004
|
+
mergeType: zod.z.enum(MergeType).optional(),
|
|
1005
|
+
positioning: zod.z.enum(Positioning).optional()
|
|
1006
|
+
});
|
|
1007
|
+
var deliveryWindowSchema = zod.z.object({
|
|
1008
|
+
service: zod.z.enum(Service).optional(),
|
|
1009
|
+
guaranteedBefore: zod.z.enum(GuaranteedBefore).optional(),
|
|
1010
|
+
duration: zod.z.enum(Duration).optional()
|
|
1011
|
+
});
|
|
1012
|
+
var servicesSchema = zod.z.object({
|
|
1013
|
+
insuredValue: zod.z.number().optional(),
|
|
1014
|
+
deliveryWindow: deliveryWindowSchema.optional(),
|
|
1015
|
+
statedAddressOnly: zod.z.boolean().optional(),
|
|
1016
|
+
returnWhenNotHome: zod.z.boolean().optional(),
|
|
1017
|
+
minimalAgeCheck: zod.z.enum(MinimalAgeCheck).optional(),
|
|
1018
|
+
deliveryConfirmation: zod.z.enum(DeliveryConfirmation).optional(),
|
|
1019
|
+
adrLq: zod.z.boolean().optional(),
|
|
1020
|
+
registered: zod.z.boolean().optional()
|
|
1021
|
+
});
|
|
1022
|
+
var contentSchema = zod.z.object({
|
|
1023
|
+
countryOfOrigin: zod.z.string(),
|
|
1024
|
+
description: zod.z.string(),
|
|
1025
|
+
quantity: zod.z.number().int(),
|
|
1026
|
+
value: zod.z.number(),
|
|
1027
|
+
weight: zod.z.number().int(),
|
|
1028
|
+
hsTariffNumber: zod.z.string().optional()
|
|
1029
|
+
});
|
|
1030
|
+
var associatedDocumentSchema = zod.z.object({
|
|
1031
|
+
type: zod.z.enum(AssociatedDocumentType),
|
|
1032
|
+
number: zod.z.string()
|
|
1033
|
+
});
|
|
1034
|
+
var customsV4Schema = zod.z.object({
|
|
1035
|
+
content: zod.z.array(contentSchema),
|
|
1036
|
+
transactionCode: zod.z.string(),
|
|
1037
|
+
currency: zod.z.string(),
|
|
1038
|
+
handleAsNonDeliverable: zod.z.boolean().optional(),
|
|
1039
|
+
associatedDocument: associatedDocumentSchema.optional(),
|
|
1040
|
+
senderIdentification: zod.z.string().optional(),
|
|
1041
|
+
receiverIdentification: zod.z.string().optional(),
|
|
1042
|
+
labelSignature: zod.z.boolean().optional()
|
|
1043
|
+
});
|
|
1044
|
+
var internationalShipmentDataV4Schema = zod.z.object({
|
|
1045
|
+
pudo: zod.z.boolean().optional(),
|
|
1046
|
+
customs: customsV4Schema.optional(),
|
|
1047
|
+
bundle: zod.z.enum(Bundle).optional()
|
|
1048
|
+
});
|
|
1049
|
+
var deliveryLocationV4Schema = zod.z.object({
|
|
1050
|
+
pickUpLocationId: zod.z.string().optional(),
|
|
1051
|
+
address: addressV4Schema.optional()
|
|
1052
|
+
});
|
|
1053
|
+
var returnOptionsV4Schema = zod.z.object({
|
|
1054
|
+
labelType: zod.z.string().optional(),
|
|
1055
|
+
returnPeriod: zod.z.union([zod.z.literal(35), zod.z.literal(100), zod.z.literal(200), zod.z.literal(365)]).optional(),
|
|
1056
|
+
returnAddress: addressV4Schema.optional(),
|
|
1057
|
+
returnBarcode: zod.z.string().optional()
|
|
1058
|
+
});
|
|
1059
|
+
var shipmentV4BaseShape = {
|
|
1060
|
+
receiver: receiverV4Schema,
|
|
1061
|
+
sender: senderV4Schema,
|
|
1062
|
+
shipmentType: zod.z.enum(ShipmentTypeV4),
|
|
1063
|
+
handOverDate: isoDate.optional(),
|
|
1064
|
+
deliveryLocation: deliveryLocationV4Schema.optional(),
|
|
1065
|
+
returnOptions: returnOptionsV4Schema.optional(),
|
|
1066
|
+
// should match items.length for multi-collo shipments
|
|
1067
|
+
itemCount: zod.z.number().int().default(1),
|
|
1068
|
+
items: zod.z.array(itemV4Schema).optional(),
|
|
1069
|
+
internationalShipmentData: internationalShipmentDataV4Schema.optional(),
|
|
1070
|
+
services: servicesSchema.optional()
|
|
1071
|
+
};
|
|
1072
|
+
var shipmentV4RequestSchema = zod.z.object({
|
|
1073
|
+
...shipmentV4BaseShape,
|
|
1074
|
+
labelSettings: labelSettingsSchema.optional()
|
|
1075
|
+
});
|
|
1076
|
+
var labellingV4RequestSchema = zod.z.object({
|
|
1077
|
+
...shipmentV4BaseShape,
|
|
1078
|
+
labelSettings: labelSettingsSchema.optional()
|
|
1079
|
+
});
|
|
1080
|
+
var confirmV4RequestSchema = zod.z.object(shipmentV4BaseShape);
|
|
1081
|
+
var labelResponseSchema = zod.z.object({
|
|
1082
|
+
label: zod.z.string().optional(),
|
|
1083
|
+
content: zod.z.string().optional(),
|
|
1084
|
+
outputType: zod.z.string().optional(),
|
|
1085
|
+
labelType: zod.z.string().optional()
|
|
1086
|
+
}).transform((l) => {
|
|
1087
|
+
const base64 = l.label ?? l.content ?? "";
|
|
1088
|
+
return {
|
|
1089
|
+
...toDecodedLabel(base64, l.outputType ?? ""),
|
|
1090
|
+
outputType: l.outputType,
|
|
1091
|
+
labelType: l.labelType
|
|
1092
|
+
};
|
|
1093
|
+
});
|
|
1094
|
+
var productServiceSchema = zod.z.object({
|
|
1095
|
+
productData: zod.z.string().optional(),
|
|
1096
|
+
// untyped in sdk (List[Any]); doc examples show objects
|
|
1097
|
+
services: zod.z.array(zod.z.record(zod.z.unknown())).optional(),
|
|
1098
|
+
bundles: zod.z.array(zod.z.record(zod.z.unknown())).optional()
|
|
1099
|
+
});
|
|
1100
|
+
var responseItemSchema = zod.z.object({
|
|
1101
|
+
shipmentReference: zod.z.string().optional(),
|
|
1102
|
+
returnReference: zod.z.string().optional(),
|
|
1103
|
+
barcode: zod.z.string().optional(),
|
|
1104
|
+
returnBarcode: zod.z.string().optional(),
|
|
1105
|
+
preannouncedProduct: zod.z.string().optional(),
|
|
1106
|
+
codingText: zod.z.string().optional(),
|
|
1107
|
+
productService: productServiceSchema.optional(),
|
|
1108
|
+
partnerBarcode: zod.z.string().optional(),
|
|
1109
|
+
partnerId: zod.z.string().optional(),
|
|
1110
|
+
labels: zod.z.array(labelResponseSchema).optional()
|
|
1111
|
+
});
|
|
1112
|
+
var shipmentPostResponseSchema = zod.z.object({
|
|
1113
|
+
items: zod.z.array(responseItemSchema).default([]),
|
|
1114
|
+
traceId: zod.z.string().optional(),
|
|
1115
|
+
warnings: zod.z.array(zod.z.string()).optional()
|
|
1116
|
+
});
|
|
1117
|
+
var returnCustomerSchema = zod.z.object({
|
|
1118
|
+
customerNumber: zod.z.string(),
|
|
1119
|
+
customerCode: zod.z.string(),
|
|
1120
|
+
address: addressV4Schema
|
|
1121
|
+
});
|
|
1122
|
+
var returnReceiverSchema = zod.z.object({
|
|
1123
|
+
customer: returnCustomerSchema.optional(),
|
|
1124
|
+
contact: contactV4Schema.optional()
|
|
1125
|
+
});
|
|
1126
|
+
var returnSenderSchema = zod.z.object({
|
|
1127
|
+
address: addressV4Schema,
|
|
1128
|
+
contact: contactV4Schema.optional()
|
|
1129
|
+
});
|
|
1130
|
+
var returnLabelSchema = zod.z.object({
|
|
1131
|
+
outputType: zod.z.enum(OutputType),
|
|
1132
|
+
printMethod: zod.z.enum(PrintMethod),
|
|
1133
|
+
pageOrientation: zod.z.enum(PageOrientation).optional(),
|
|
1134
|
+
resolution: zod.z.union([zod.z.literal(200), zod.z.literal(300), zod.z.literal(600)]).optional()
|
|
1135
|
+
});
|
|
1136
|
+
var returnDomesticSchema = zod.z.object({
|
|
1137
|
+
returnPeriod: zod.z.union([zod.z.literal(20), zod.z.literal(35)]).optional(),
|
|
1138
|
+
valuableReturn: zod.z.boolean().optional()
|
|
1139
|
+
});
|
|
1140
|
+
var returnInternationalSchema = zod.z.object({
|
|
1141
|
+
consolidationMode: zod.z.enum(ConsolidationMode).optional(),
|
|
1142
|
+
networkType: zod.z.enum(NetworkType).optional()
|
|
1143
|
+
});
|
|
1144
|
+
var returnCollectionServiceSchema = zod.z.object({
|
|
1145
|
+
timeWindow: isoDate.optional(),
|
|
1146
|
+
// should match items.length for multi-collo shipments
|
|
1147
|
+
itemCount: zod.z.number().int().default(1)
|
|
1148
|
+
});
|
|
1149
|
+
var returnOptionsSchema = zod.z.object({
|
|
1150
|
+
domestic: returnDomesticSchema.optional(),
|
|
1151
|
+
international: returnInternationalSchema.optional(),
|
|
1152
|
+
collectionService: returnCollectionServiceSchema.optional()
|
|
1153
|
+
});
|
|
1154
|
+
var returnItemSchema = zod.z.object({
|
|
1155
|
+
barcode: zod.z.string().optional(),
|
|
1156
|
+
dimensions: dimensionsSchema.optional(),
|
|
1157
|
+
customerReferences: customerReferencesSchema.optional()
|
|
1158
|
+
});
|
|
1159
|
+
var returnGenerateRequestSchema = zod.z.object({
|
|
1160
|
+
receiver: returnReceiverSchema,
|
|
1161
|
+
sender: returnSenderSchema,
|
|
1162
|
+
labelSettings: returnLabelSchema,
|
|
1163
|
+
shipmentType: zod.z.enum(ReturnShipmentTypeV4),
|
|
1164
|
+
returnOptions: returnOptionsSchema.optional(),
|
|
1165
|
+
items: zod.z.array(returnItemSchema).optional()
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
// src/resources/return/index.ts
|
|
1169
|
+
var ReturnResource = class extends BaseResource {
|
|
1170
|
+
// generate a return label
|
|
1171
|
+
generate(input) {
|
|
1172
|
+
return this.call({
|
|
1173
|
+
operation: "returnGenerate",
|
|
1174
|
+
input,
|
|
1175
|
+
requestSchema: returnGenerateRequestSchema,
|
|
1176
|
+
responseSchema: shipmentPostResponseSchema
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
var messageTimeStamp = zod.z.preprocess(
|
|
1181
|
+
(v) => v instanceof Date ? formatDate(v, "datetime") : v,
|
|
1182
|
+
zod.z.string()
|
|
1183
|
+
);
|
|
1184
|
+
var legacyAddressSchema = zod.z.object({
|
|
1185
|
+
addressType: zod.z.custom(),
|
|
1186
|
+
countrycode: zod.z.string(),
|
|
1187
|
+
area: zod.z.string().optional(),
|
|
1188
|
+
buildingname: zod.z.string().optional(),
|
|
1189
|
+
city: zod.z.string().optional(),
|
|
1190
|
+
companyName: zod.z.string().optional(),
|
|
1191
|
+
department: zod.z.string().optional(),
|
|
1192
|
+
doorcode: zod.z.string().optional(),
|
|
1193
|
+
firstName: zod.z.string().optional(),
|
|
1194
|
+
floor: zod.z.string().optional(),
|
|
1195
|
+
houseNr: zod.z.string().optional(),
|
|
1196
|
+
houseNrExt: zod.z.string().optional(),
|
|
1197
|
+
name: zod.z.string().optional(),
|
|
1198
|
+
region: zod.z.string().optional(),
|
|
1199
|
+
street: zod.z.string().optional(),
|
|
1200
|
+
streetHouseNrExt: zod.z.string().optional(),
|
|
1201
|
+
zipcode: zod.z.string().optional()
|
|
1202
|
+
}).transform(
|
|
1203
|
+
(a) => stripUndefined({
|
|
1204
|
+
AddressType: a.addressType,
|
|
1205
|
+
Countrycode: a.countrycode,
|
|
1206
|
+
Area: a.area,
|
|
1207
|
+
Buildingname: a.buildingname,
|
|
1208
|
+
City: a.city,
|
|
1209
|
+
CompanyName: a.companyName,
|
|
1210
|
+
Department: a.department,
|
|
1211
|
+
Doorcode: a.doorcode,
|
|
1212
|
+
FirstName: a.firstName,
|
|
1213
|
+
Floor: a.floor,
|
|
1214
|
+
HouseNr: a.houseNr,
|
|
1215
|
+
HouseNrExt: a.houseNrExt,
|
|
1216
|
+
Name: a.name,
|
|
1217
|
+
Region: a.region,
|
|
1218
|
+
Street: a.street,
|
|
1219
|
+
StreetHouseNrExt: a.streetHouseNrExt,
|
|
1220
|
+
Zipcode: a.zipcode
|
|
1221
|
+
})
|
|
1222
|
+
);
|
|
1223
|
+
var legacyContactSchema = zod.z.object({
|
|
1224
|
+
contactType: zod.z.string(),
|
|
1225
|
+
email: zod.z.string().optional(),
|
|
1226
|
+
smsNr: zod.z.string().optional(),
|
|
1227
|
+
telNr: zod.z.string().optional()
|
|
1228
|
+
}).transform(
|
|
1229
|
+
(c) => stripUndefined({
|
|
1230
|
+
ContactType: c.contactType,
|
|
1231
|
+
Email: c.email,
|
|
1232
|
+
SMSNr: c.smsNr,
|
|
1233
|
+
TelNr: c.telNr
|
|
1234
|
+
})
|
|
1235
|
+
);
|
|
1236
|
+
var legacyDimensionSchema = zod.z.object({
|
|
1237
|
+
weight: zod.z.number().int(),
|
|
1238
|
+
height: zod.z.number().int().optional(),
|
|
1239
|
+
length: zod.z.number().int().optional(),
|
|
1240
|
+
volume: zod.z.number().int().optional(),
|
|
1241
|
+
width: zod.z.number().int().optional()
|
|
1242
|
+
}).transform(
|
|
1243
|
+
(d) => stripUndefined({
|
|
1244
|
+
Weight: d.weight,
|
|
1245
|
+
Height: d.height,
|
|
1246
|
+
Length: d.length,
|
|
1247
|
+
Volume: d.volume,
|
|
1248
|
+
Width: d.width
|
|
1249
|
+
})
|
|
1250
|
+
);
|
|
1251
|
+
var legacyAmountSchema = zod.z.object({
|
|
1252
|
+
amountType: zod.z.string(),
|
|
1253
|
+
value: zod.z.number(),
|
|
1254
|
+
accountName: zod.z.string().optional(),
|
|
1255
|
+
bic: zod.z.string().optional(),
|
|
1256
|
+
currency: zod.z.custom().optional(),
|
|
1257
|
+
iban: zod.z.string().optional(),
|
|
1258
|
+
reference: zod.z.string().optional(),
|
|
1259
|
+
transactionNumber: zod.z.string().optional()
|
|
1260
|
+
}).transform(
|
|
1261
|
+
(a) => stripUndefined({
|
|
1262
|
+
AmountType: a.amountType,
|
|
1263
|
+
Value: a.value,
|
|
1264
|
+
AccountName: a.accountName,
|
|
1265
|
+
BIC: a.bic,
|
|
1266
|
+
Currency: a.currency,
|
|
1267
|
+
IBAN: a.iban,
|
|
1268
|
+
Reference: a.reference,
|
|
1269
|
+
TransactionNumber: a.transactionNumber
|
|
1270
|
+
})
|
|
1271
|
+
);
|
|
1272
|
+
var legacyGroupSchema = zod.z.object({
|
|
1273
|
+
groupType: zod.z.string(),
|
|
1274
|
+
mainBarcode: zod.z.string(),
|
|
1275
|
+
groupSequence: zod.z.number().int().optional(),
|
|
1276
|
+
groupCount: zod.z.number().int().optional()
|
|
1277
|
+
}).transform(
|
|
1278
|
+
(g) => stripUndefined({
|
|
1279
|
+
GroupType: g.groupType,
|
|
1280
|
+
MainBarcode: g.mainBarcode,
|
|
1281
|
+
GroupSequence: g.groupSequence,
|
|
1282
|
+
GroupCount: g.groupCount
|
|
1283
|
+
})
|
|
1284
|
+
);
|
|
1285
|
+
var legacyProductOptionSchema = zod.z.object({ characteristic: zod.z.string(), option: zod.z.string() }).transform((p) => ({ Characteristic: p.characteristic, Option: p.option }));
|
|
1286
|
+
var legacyCustomsContentSchema = zod.z.object({
|
|
1287
|
+
description: zod.z.string(),
|
|
1288
|
+
quantity: zod.z.number().int(),
|
|
1289
|
+
weight: zod.z.number().int(),
|
|
1290
|
+
value: zod.z.number(),
|
|
1291
|
+
hsTariffNr: zod.z.string().optional(),
|
|
1292
|
+
countryOfOrigin: zod.z.string().optional()
|
|
1293
|
+
}).transform(
|
|
1294
|
+
(c) => stripUndefined({
|
|
1295
|
+
Description: c.description,
|
|
1296
|
+
Quantity: c.quantity,
|
|
1297
|
+
Weight: c.weight,
|
|
1298
|
+
Value: c.value,
|
|
1299
|
+
HSTariffNr: c.hsTariffNr,
|
|
1300
|
+
CountryOfOrigin: c.countryOfOrigin
|
|
1301
|
+
})
|
|
1302
|
+
);
|
|
1303
|
+
var legacyCustomsSchema = zod.z.object({
|
|
1304
|
+
currency: zod.z.custom(),
|
|
1305
|
+
shipmentType: zod.z.custom(),
|
|
1306
|
+
content: zod.z.array(legacyCustomsContentSchema),
|
|
1307
|
+
certificate: zod.z.boolean().optional(),
|
|
1308
|
+
certificateNr: zod.z.string().optional(),
|
|
1309
|
+
license: zod.z.boolean().optional(),
|
|
1310
|
+
licenseNr: zod.z.string().optional(),
|
|
1311
|
+
invoice: zod.z.boolean().optional(),
|
|
1312
|
+
invoiceNr: zod.z.string().optional(),
|
|
1313
|
+
handleAsNonDeliverable: zod.z.boolean().optional(),
|
|
1314
|
+
trustedShipperId: zod.z.string().optional(),
|
|
1315
|
+
importerReferenceCode: zod.z.string().optional(),
|
|
1316
|
+
transactionCode: zod.z.string().optional(),
|
|
1317
|
+
transactionDescription: zod.z.string().optional()
|
|
1318
|
+
}).transform(
|
|
1319
|
+
(c) => stripUndefined({
|
|
1320
|
+
Currency: c.currency,
|
|
1321
|
+
ShipmentType: c.shipmentType,
|
|
1322
|
+
Content: c.content,
|
|
1323
|
+
Certificate: c.certificate,
|
|
1324
|
+
CertificateNr: c.certificateNr,
|
|
1325
|
+
License: c.license,
|
|
1326
|
+
LicenseNr: c.licenseNr,
|
|
1327
|
+
Invoice: c.invoice,
|
|
1328
|
+
InvoiceNr: c.invoiceNr,
|
|
1329
|
+
HandleAsNonDeliverable: c.handleAsNonDeliverable,
|
|
1330
|
+
TrustedShipperID: c.trustedShipperId,
|
|
1331
|
+
ImporterReferenceCode: c.importerReferenceCode,
|
|
1332
|
+
TransactionCode: c.transactionCode,
|
|
1333
|
+
TransactionDescription: c.transactionDescription
|
|
1334
|
+
})
|
|
1335
|
+
);
|
|
1336
|
+
var legacyExtraFieldSchema = zod.z.object({ key: zod.z.string().optional(), value: zod.z.string().optional() }).transform((e2) => stripUndefined({ Key: e2.key, Value: e2.value }));
|
|
1337
|
+
var legacyShipmentShape = {
|
|
1338
|
+
addresses: zod.z.array(legacyAddressSchema),
|
|
1339
|
+
barcode: zod.z.string(),
|
|
1340
|
+
dimension: legacyDimensionSchema,
|
|
1341
|
+
productCodeDelivery: zod.z.string(),
|
|
1342
|
+
amounts: zod.z.array(legacyAmountSchema).optional(),
|
|
1343
|
+
codingText: zod.z.string().optional(),
|
|
1344
|
+
collectionTimeStampStart: zod.z.string().optional(),
|
|
1345
|
+
collectionTimeStampEnd: zod.z.string().optional(),
|
|
1346
|
+
contacts: zod.z.array(legacyContactSchema).optional(),
|
|
1347
|
+
content: zod.z.string().optional(),
|
|
1348
|
+
costCenter: zod.z.string().optional(),
|
|
1349
|
+
customerOrderNumber: zod.z.string().optional(),
|
|
1350
|
+
customs: legacyCustomsSchema.optional(),
|
|
1351
|
+
deliveryAddress: zod.z.string().optional(),
|
|
1352
|
+
deliveryDate: zod.z.string().optional(),
|
|
1353
|
+
downPartnerBarcode: zod.z.string().optional(),
|
|
1354
|
+
downPartnerId: zod.z.string().optional(),
|
|
1355
|
+
downPartnerLocation: zod.z.string().optional(),
|
|
1356
|
+
groups: zod.z.array(legacyGroupSchema).optional(),
|
|
1357
|
+
hazardousMaterial: zod.z.string().optional(),
|
|
1358
|
+
productCodeCollect: zod.z.string().optional(),
|
|
1359
|
+
productOptions: zod.z.array(legacyProductOptionSchema).optional(),
|
|
1360
|
+
receiverDateOfBirth: zod.z.string().optional(),
|
|
1361
|
+
reference: zod.z.string().optional(),
|
|
1362
|
+
referenceCollect: zod.z.string().optional(),
|
|
1363
|
+
remark: zod.z.string().optional(),
|
|
1364
|
+
returnBarcode: zod.z.string().optional(),
|
|
1365
|
+
returnReference: zod.z.string().optional(),
|
|
1366
|
+
timeslotId: zod.z.string().optional()
|
|
1367
|
+
};
|
|
1368
|
+
var toWireShipment = (s) => stripUndefined({
|
|
1369
|
+
Addresses: s.addresses,
|
|
1370
|
+
Barcode: s.barcode,
|
|
1371
|
+
Dimension: s.dimension,
|
|
1372
|
+
ProductCodeDelivery: s.productCodeDelivery,
|
|
1373
|
+
Amounts: s.amounts,
|
|
1374
|
+
CodingText: s.codingText,
|
|
1375
|
+
CollectionTimeStampStart: s.collectionTimeStampStart,
|
|
1376
|
+
CollectionTimeStampEnd: s.collectionTimeStampEnd,
|
|
1377
|
+
Contacts: s.contacts,
|
|
1378
|
+
Content: s.content,
|
|
1379
|
+
CostCenter: s.costCenter,
|
|
1380
|
+
CustomerOrderNumber: s.customerOrderNumber,
|
|
1381
|
+
Customs: s.customs,
|
|
1382
|
+
DeliveryAddress: s.deliveryAddress,
|
|
1383
|
+
DeliveryDate: s.deliveryDate,
|
|
1384
|
+
DownPartnerBarcode: s.downPartnerBarcode,
|
|
1385
|
+
DownPartnerID: s.downPartnerId,
|
|
1386
|
+
DownPartnerLocation: s.downPartnerLocation,
|
|
1387
|
+
Groups: s.groups,
|
|
1388
|
+
HazardousMaterial: s.hazardousMaterial,
|
|
1389
|
+
ProductCodeCollect: s.productCodeCollect,
|
|
1390
|
+
ProductOptions: s.productOptions,
|
|
1391
|
+
ReceiverDateOfBirth: s.receiverDateOfBirth,
|
|
1392
|
+
Reference: s.reference,
|
|
1393
|
+
ReferenceCollect: s.referenceCollect,
|
|
1394
|
+
Remark: s.remark,
|
|
1395
|
+
ReturnBarcode: s.returnBarcode,
|
|
1396
|
+
ReturnReference: s.returnReference,
|
|
1397
|
+
TimeslotID: s.timeslotId
|
|
1398
|
+
});
|
|
1399
|
+
var legacyLabellingShipmentSchema = zod.z.object({ ...legacyShipmentShape, extraFields: zod.z.array(legacyExtraFieldSchema).optional() }).transform((s) => stripUndefined({ ...toWireShipment(s), ExtraFields: s.extraFields }));
|
|
1400
|
+
var legacyCustomerSchema = zod.z.object({
|
|
1401
|
+
customerCode: zod.z.string(),
|
|
1402
|
+
customerNumber: zod.z.string(),
|
|
1403
|
+
address: legacyAddressSchema.optional(),
|
|
1404
|
+
collectionLocation: zod.z.string().optional(),
|
|
1405
|
+
contactPerson: zod.z.string().optional(),
|
|
1406
|
+
email: zod.z.string().optional(),
|
|
1407
|
+
name: zod.z.string().optional()
|
|
1408
|
+
}).transform(
|
|
1409
|
+
(c) => stripUndefined({
|
|
1410
|
+
CustomerCode: c.customerCode,
|
|
1411
|
+
CustomerNumber: c.customerNumber,
|
|
1412
|
+
Address: c.address,
|
|
1413
|
+
CollectionLocation: c.collectionLocation,
|
|
1414
|
+
ContactPerson: c.contactPerson,
|
|
1415
|
+
Email: c.email,
|
|
1416
|
+
Name: c.name
|
|
1417
|
+
})
|
|
1418
|
+
);
|
|
1419
|
+
var legacyLabellingMessageSchema = zod.z.object({
|
|
1420
|
+
messageId: zod.z.string(),
|
|
1421
|
+
messageTimeStamp: messageTimeStamp.optional(),
|
|
1422
|
+
printertype: zod.z.string()
|
|
1423
|
+
}).transform(
|
|
1424
|
+
(m) => stripUndefined({
|
|
1425
|
+
MessageID: m.messageId,
|
|
1426
|
+
MessageTimeStamp: m.messageTimeStamp ?? formatDate(/* @__PURE__ */ new Date(), "datetime"),
|
|
1427
|
+
Printertype: m.printertype
|
|
1428
|
+
})
|
|
1429
|
+
);
|
|
1430
|
+
var labellingRequestSchema = zod.z.object({
|
|
1431
|
+
customer: legacyCustomerSchema,
|
|
1432
|
+
message: legacyLabellingMessageSchema,
|
|
1433
|
+
shipments: zod.z.array(legacyLabellingShipmentSchema),
|
|
1434
|
+
labelSignature: zod.z.boolean().optional()
|
|
1435
|
+
}).transform(
|
|
1436
|
+
(r) => stripUndefined({
|
|
1437
|
+
Customer: r.customer,
|
|
1438
|
+
Message: r.message,
|
|
1439
|
+
Shipments: r.shipments,
|
|
1440
|
+
LabelSignature: r.labelSignature
|
|
1441
|
+
})
|
|
1442
|
+
);
|
|
1443
|
+
var legacyConfirmingMessageSchema = zod.z.object({ messageId: zod.z.string(), messageTimeStamp: messageTimeStamp.optional() }).transform((m) => ({
|
|
1444
|
+
MessageID: m.messageId,
|
|
1445
|
+
MessageTimeStamp: m.messageTimeStamp ?? formatDate(/* @__PURE__ */ new Date(), "datetime")
|
|
1446
|
+
}));
|
|
1447
|
+
var legacyConfirmingShipmentSchema = zod.z.object(legacyShipmentShape).transform((s) => toWireShipment(s));
|
|
1448
|
+
var confirmingRequestSchema = zod.z.object({
|
|
1449
|
+
customer: legacyCustomerSchema,
|
|
1450
|
+
message: legacyConfirmingMessageSchema,
|
|
1451
|
+
shipments: zod.z.array(legacyConfirmingShipmentSchema)
|
|
1452
|
+
}).transform((r) => ({ Customer: r.customer, Message: r.message, Shipments: r.shipments }));
|
|
1453
|
+
var legacyLabelSchema = zod.z.object({
|
|
1454
|
+
Content: zod.z.string().optional(),
|
|
1455
|
+
Labeltype: zod.z.string().optional(),
|
|
1456
|
+
OutputType: zod.z.string().optional()
|
|
1457
|
+
}).transform((l) => {
|
|
1458
|
+
const format = l.OutputType ?? l.Labeltype ?? "";
|
|
1459
|
+
return {
|
|
1460
|
+
...toDecodedLabel(l.Content ?? "", format),
|
|
1461
|
+
labeltype: l.Labeltype,
|
|
1462
|
+
outputType: l.OutputType
|
|
1463
|
+
};
|
|
1464
|
+
});
|
|
1465
|
+
var warningSchema2 = zod.z.object({ Code: zod.z.string().optional(), Description: zod.z.string().optional() }).transform((w) => stripUndefined({ code: w.Code, description: w.Description }));
|
|
1466
|
+
var errorSchema = zod.z.unknown();
|
|
1467
|
+
var labellingResponseShipmentSchema = zod.z.object({
|
|
1468
|
+
ProductCodeDelivery: zod.z.string().optional(),
|
|
1469
|
+
Labels: pnlArray(legacyLabelSchema),
|
|
1470
|
+
Barcode: zod.z.string().optional(),
|
|
1471
|
+
Errors: pnlArray(errorSchema),
|
|
1472
|
+
Warnings: pnlArray(warningSchema2)
|
|
1473
|
+
}).transform((s) => ({
|
|
1474
|
+
labels: s.Labels,
|
|
1475
|
+
...stripUndefined({
|
|
1476
|
+
productCodeDelivery: s.ProductCodeDelivery,
|
|
1477
|
+
barcode: s.Barcode,
|
|
1478
|
+
errors: s.Errors.length ? s.Errors : void 0,
|
|
1479
|
+
warnings: s.Warnings.length ? s.Warnings : void 0
|
|
1480
|
+
})
|
|
1481
|
+
}));
|
|
1482
|
+
var legacyMergedLabelSchema = zod.z.object({ Barcodes: pnlArray(zod.z.string()), Labels: pnlArray(legacyLabelSchema) }).transform((m) => ({ barcodes: m.Barcodes, labels: m.Labels }));
|
|
1483
|
+
var labellingResponseSchema = zod.z.object({
|
|
1484
|
+
MergedLabels: pnlArray(legacyMergedLabelSchema),
|
|
1485
|
+
ResponseShipments: pnlArray(labellingResponseShipmentSchema)
|
|
1486
|
+
}).transform((r) => ({
|
|
1487
|
+
responseShipments: r.ResponseShipments,
|
|
1488
|
+
...r.MergedLabels.length ? { mergedLabels: r.MergedLabels } : {}
|
|
1489
|
+
}));
|
|
1490
|
+
var confirmingResponseShipmentSchema = zod.z.object({
|
|
1491
|
+
Barcode: zod.z.string().optional(),
|
|
1492
|
+
Errors: pnlArray(errorSchema),
|
|
1493
|
+
Warnings: pnlArray(warningSchema2)
|
|
1494
|
+
}).transform(
|
|
1495
|
+
(s) => stripUndefined({
|
|
1496
|
+
barcode: s.Barcode,
|
|
1497
|
+
errors: s.Errors.length ? s.Errors : void 0,
|
|
1498
|
+
warnings: s.Warnings.length ? s.Warnings : void 0
|
|
1499
|
+
})
|
|
1500
|
+
);
|
|
1501
|
+
var confirmingResponseSchema = zod.z.object({ ResponseShipments: pnlArray(confirmingResponseShipmentSchema) }).transform((r) => ({ responseShipments: r.ResponseShipments }));
|
|
1502
|
+
|
|
1503
|
+
// src/resources/shipping/legacy.ts
|
|
1504
|
+
var ShippingLegacyResource = class extends BaseResource {
|
|
1505
|
+
// POST /shipment/v2_2/label; confirm query param defaults true
|
|
1506
|
+
label(input, options) {
|
|
1507
|
+
return this.call({
|
|
1508
|
+
operation: "shippingLabelLegacy",
|
|
1509
|
+
query: { confirm: options?.confirm ?? true },
|
|
1510
|
+
input,
|
|
1511
|
+
requestSchema: labellingRequestSchema,
|
|
1512
|
+
responseSchema: labellingResponseSchema
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
// POST /shipment/v2/confirm
|
|
1516
|
+
confirm(input) {
|
|
1517
|
+
return this.call({
|
|
1518
|
+
operation: "shippingConfirmLegacy",
|
|
1519
|
+
input,
|
|
1520
|
+
requestSchema: confirmingRequestSchema,
|
|
1521
|
+
responseSchema: confirmingResponseSchema
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// src/resources/shipping/index.ts
|
|
1527
|
+
var ShippingResource = class extends BaseResource {
|
|
1528
|
+
// legacy label/confirm (POST /shipment/v2_2/label, /shipment/v2/confirm)
|
|
1529
|
+
legacy = new ShippingLegacyResource(this.transport);
|
|
1530
|
+
// create + confirm in one call (labelconfirm)
|
|
1531
|
+
create(input) {
|
|
1532
|
+
return this.call({
|
|
1533
|
+
operation: "shippingCreate",
|
|
1534
|
+
input,
|
|
1535
|
+
requestSchema: shipmentV4RequestSchema,
|
|
1536
|
+
responseSchema: shipmentPostResponseSchema
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
// generate label without confirming
|
|
1540
|
+
label(input) {
|
|
1541
|
+
return this.call({
|
|
1542
|
+
operation: "shippingLabelV4",
|
|
1543
|
+
input,
|
|
1544
|
+
requestSchema: labellingV4RequestSchema,
|
|
1545
|
+
responseSchema: shipmentPostResponseSchema
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
// confirm a previously created shipment
|
|
1549
|
+
confirm(input) {
|
|
1550
|
+
return this.call({
|
|
1551
|
+
operation: "shippingConfirmV4",
|
|
1552
|
+
input,
|
|
1553
|
+
requestSchema: confirmV4RequestSchema,
|
|
1554
|
+
responseSchema: shipmentPostResponseSchema
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
var timeframeTimeframeSchema = zod.z.object({
|
|
1559
|
+
From: zod.z.string().optional(),
|
|
1560
|
+
To: zod.z.string().optional(),
|
|
1561
|
+
Options: pnlArray(zod.z.string()),
|
|
1562
|
+
Sustainability: sustainabilitySchema.optional()
|
|
1563
|
+
}).transform(
|
|
1564
|
+
(t) => stripUndefined({
|
|
1565
|
+
from: t.From,
|
|
1566
|
+
to: t.To,
|
|
1567
|
+
options: t.Options.length ? t.Options : void 0,
|
|
1568
|
+
sustainability: t.Sustainability
|
|
1569
|
+
})
|
|
1570
|
+
);
|
|
1571
|
+
var timeframeSchema2 = zod.z.object({
|
|
1572
|
+
Date: pnlDateField,
|
|
1573
|
+
Timeframes: zod.z.object({ TimeframeTimeframe: pnlArray(timeframeTimeframeSchema) }).optional().transform((t) => t?.TimeframeTimeframe ?? [])
|
|
1574
|
+
}).transform((t) => ({
|
|
1575
|
+
...stripUndefined({ date: t.Date }),
|
|
1576
|
+
timeframes: t.Timeframes
|
|
1577
|
+
}));
|
|
1578
|
+
var reasonNoTimeframeSchema = zod.z.object({
|
|
1579
|
+
Code: zod.z.string().optional(),
|
|
1580
|
+
Date: pnlDateField,
|
|
1581
|
+
Description: zod.z.string().optional(),
|
|
1582
|
+
Options: pnlArray(zod.z.string()),
|
|
1583
|
+
Sustainability: sustainabilitySchema.optional()
|
|
1584
|
+
}).transform(
|
|
1585
|
+
(r) => stripUndefined({
|
|
1586
|
+
code: r.Code,
|
|
1587
|
+
date: r.Date,
|
|
1588
|
+
description: r.Description,
|
|
1589
|
+
options: r.Options.length ? r.Options : void 0,
|
|
1590
|
+
sustainability: r.Sustainability
|
|
1591
|
+
})
|
|
1592
|
+
);
|
|
1593
|
+
var timeframeResponseSchema = zod.z.object({
|
|
1594
|
+
Timeframes: zod.z.object({ Timeframe: pnlArray(timeframeSchema2) }).optional().transform((t) => t?.Timeframe ?? []),
|
|
1595
|
+
ReasonNoTimeframes: zod.z.object({ ReasonNoTimeframe: pnlArray(reasonNoTimeframeSchema) }).optional().transform((r) => r?.ReasonNoTimeframe ?? [])
|
|
1596
|
+
}).transform((r) => ({
|
|
1597
|
+
timeframes: r.Timeframes,
|
|
1598
|
+
reasonNoTimeframes: r.ReasonNoTimeframes
|
|
1599
|
+
}));
|
|
1600
|
+
|
|
1601
|
+
// src/resources/timeframe/index.ts
|
|
1602
|
+
var asDate3 = (v) => v instanceof Date ? formatDate(v, "date") : v;
|
|
1603
|
+
var TimeframeResource = class extends BaseResource {
|
|
1604
|
+
// GET /shipment/v2_1/calculate/timeframes
|
|
1605
|
+
get(input) {
|
|
1606
|
+
return this.call({
|
|
1607
|
+
operation: "timeframeGet",
|
|
1608
|
+
query: {
|
|
1609
|
+
AllowSundaySorting: input.allowSundaySorting,
|
|
1610
|
+
StartDate: asDate3(input.startDate),
|
|
1611
|
+
EndDate: asDate3(input.endDate),
|
|
1612
|
+
CountryCode: input.countryCode,
|
|
1613
|
+
PostalCode: input.postalCode,
|
|
1614
|
+
HouseNumber: input.houseNumber,
|
|
1615
|
+
Options: input.options.join(","),
|
|
1616
|
+
HouseNrExt: input.houseNrExt,
|
|
1617
|
+
City: input.city,
|
|
1618
|
+
Street: input.street
|
|
1619
|
+
},
|
|
1620
|
+
responseSchema: timeframeResponseSchema
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
var pnlDate = zod.z.string().nullish().transform((v) => {
|
|
1625
|
+
if (v == null) return void 0;
|
|
1626
|
+
try {
|
|
1627
|
+
return parsePnlDate(v);
|
|
1628
|
+
} catch {
|
|
1629
|
+
return v;
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
var customerSchema = zod.z.object({
|
|
1633
|
+
CustomerCode: zod.z.string().optional(),
|
|
1634
|
+
CustomerNumber: zod.z.string().optional(),
|
|
1635
|
+
Name: zod.z.string().optional()
|
|
1636
|
+
}).transform(
|
|
1637
|
+
(c) => stripUndefined({
|
|
1638
|
+
customerCode: c.CustomerCode,
|
|
1639
|
+
customerNumber: c.CustomerNumber,
|
|
1640
|
+
name: c.Name
|
|
1641
|
+
})
|
|
1642
|
+
);
|
|
1643
|
+
var dimensionSchema = zod.z.object({
|
|
1644
|
+
Weight: pnlNum().optional(),
|
|
1645
|
+
Height: pnlNum().optional(),
|
|
1646
|
+
Length: pnlNum().optional(),
|
|
1647
|
+
Width: pnlNum().optional(),
|
|
1648
|
+
Volume: pnlNum().optional()
|
|
1649
|
+
}).transform(
|
|
1650
|
+
(d) => stripUndefined({
|
|
1651
|
+
weight: d.Weight,
|
|
1652
|
+
height: d.Height,
|
|
1653
|
+
length: d.Length,
|
|
1654
|
+
width: d.Width,
|
|
1655
|
+
volume: d.Volume
|
|
1656
|
+
})
|
|
1657
|
+
);
|
|
1658
|
+
var amountSchema = zod.z.object({
|
|
1659
|
+
RemboursBedrag: zod.z.string().optional(),
|
|
1660
|
+
VerzekerdBedrag: zod.z.string().optional()
|
|
1661
|
+
}).transform(
|
|
1662
|
+
(a) => stripUndefined({ remboursBedrag: a.RemboursBedrag, verzekerdBedrag: a.VerzekerdBedrag })
|
|
1663
|
+
);
|
|
1664
|
+
var addressSchema2 = zod.z.object({
|
|
1665
|
+
FirstName: zod.z.string().optional(),
|
|
1666
|
+
LastName: zod.z.string().optional(),
|
|
1667
|
+
CompanyName: zod.z.string().optional(),
|
|
1668
|
+
DepartmentName: zod.z.string().optional(),
|
|
1669
|
+
CountryCode: zod.z.string().optional(),
|
|
1670
|
+
Zipcode: zod.z.string().optional(),
|
|
1671
|
+
Region: zod.z.string().optional(),
|
|
1672
|
+
District: zod.z.string().optional(),
|
|
1673
|
+
City: zod.z.string().optional(),
|
|
1674
|
+
Street: zod.z.string().optional(),
|
|
1675
|
+
HouseNumber: zod.z.string().optional(),
|
|
1676
|
+
HouseNumberSuffix: zod.z.string().optional(),
|
|
1677
|
+
Building: zod.z.string().optional(),
|
|
1678
|
+
Floor: zod.z.string().optional(),
|
|
1679
|
+
Remark: zod.z.string().optional()
|
|
1680
|
+
}).transform(
|
|
1681
|
+
(a) => stripUndefined({
|
|
1682
|
+
firstName: a.FirstName,
|
|
1683
|
+
lastName: a.LastName,
|
|
1684
|
+
companyName: a.CompanyName,
|
|
1685
|
+
departmentName: a.DepartmentName,
|
|
1686
|
+
countryCode: a.CountryCode,
|
|
1687
|
+
zipcode: a.Zipcode,
|
|
1688
|
+
region: a.Region,
|
|
1689
|
+
district: a.District,
|
|
1690
|
+
city: a.City,
|
|
1691
|
+
street: a.Street,
|
|
1692
|
+
houseNumber: a.HouseNumber,
|
|
1693
|
+
houseNumberSuffix: a.HouseNumberSuffix,
|
|
1694
|
+
building: a.Building,
|
|
1695
|
+
floor: a.Floor,
|
|
1696
|
+
remark: a.Remark
|
|
1697
|
+
})
|
|
1698
|
+
);
|
|
1699
|
+
var statusSchema = zod.z.object({
|
|
1700
|
+
TimeStamp: pnlDate,
|
|
1701
|
+
StatusCode: zod.z.string().optional(),
|
|
1702
|
+
StatusDescription: zod.z.string().optional(),
|
|
1703
|
+
PhaseCode: zod.z.string().optional(),
|
|
1704
|
+
PhaseDescription: zod.z.string().optional()
|
|
1705
|
+
}).transform(
|
|
1706
|
+
(s) => stripUndefined({
|
|
1707
|
+
timeStamp: s.TimeStamp,
|
|
1708
|
+
statusCode: s.StatusCode,
|
|
1709
|
+
statusDescription: s.StatusDescription,
|
|
1710
|
+
phaseCode: s.PhaseCode,
|
|
1711
|
+
phaseDescription: s.PhaseDescription
|
|
1712
|
+
})
|
|
1713
|
+
);
|
|
1714
|
+
var eventSchema = zod.z.object({
|
|
1715
|
+
Code: zod.z.string().optional(),
|
|
1716
|
+
Description: zod.z.string().optional(),
|
|
1717
|
+
DestinationLocationCode: zod.z.string().optional(),
|
|
1718
|
+
LocationCode: zod.z.string().optional(),
|
|
1719
|
+
RouteCode: zod.z.string().optional(),
|
|
1720
|
+
RouteNumber: zod.z.string().optional(),
|
|
1721
|
+
TimeStamp: pnlDate
|
|
1722
|
+
}).transform(
|
|
1723
|
+
(e2) => stripUndefined({
|
|
1724
|
+
code: e2.Code,
|
|
1725
|
+
description: e2.Description,
|
|
1726
|
+
destinationLocationCode: e2.DestinationLocationCode,
|
|
1727
|
+
locationCode: e2.LocationCode,
|
|
1728
|
+
routeCode: e2.RouteCode,
|
|
1729
|
+
routeNumber: e2.RouteNumber,
|
|
1730
|
+
timeStamp: e2.TimeStamp
|
|
1731
|
+
})
|
|
1732
|
+
);
|
|
1733
|
+
var expectationSchema = zod.z.object({ ETAFrom: pnlDate, ETATo: pnlDate }).transform((e2) => stripUndefined({ etaFrom: e2.ETAFrom, etaTo: e2.ETATo }));
|
|
1734
|
+
var productOptionsSchema = zod.z.object({
|
|
1735
|
+
ProductOption: zod.z.object({
|
|
1736
|
+
OptionCode: zod.z.string().optional(),
|
|
1737
|
+
CharacteristicCode: zod.z.string().optional()
|
|
1738
|
+
}).optional()
|
|
1739
|
+
}).transform(
|
|
1740
|
+
(p) => stripUndefined({
|
|
1741
|
+
optionCode: p.ProductOption?.OptionCode,
|
|
1742
|
+
characteristicCode: p.ProductOption?.CharacteristicCode
|
|
1743
|
+
})
|
|
1744
|
+
);
|
|
1745
|
+
var warningSchema3 = zod.z.object({ Message: zod.z.string().optional(), Code: zod.z.string().optional() }).transform((w) => stripUndefined({ message: w.Message, code: w.Code }));
|
|
1746
|
+
var baseShipmentSchema = zod.z.object({
|
|
1747
|
+
MainBarcode: zod.z.string().optional(),
|
|
1748
|
+
Barcode: zod.z.string().optional(),
|
|
1749
|
+
ShipmentAmount: pnlNum().optional(),
|
|
1750
|
+
ShipmentCounter: pnlNum().optional(),
|
|
1751
|
+
Customer: customerSchema.optional(),
|
|
1752
|
+
ProductCode: zod.z.string().optional(),
|
|
1753
|
+
ProductDescription: zod.z.string().optional(),
|
|
1754
|
+
Reference: zod.z.string().optional(),
|
|
1755
|
+
DeliveryDate: pnlDate,
|
|
1756
|
+
Dimension: dimensionSchema.optional(),
|
|
1757
|
+
Address: pnlArray(addressSchema2),
|
|
1758
|
+
ProductOptions: pnlArray(productOptionsSchema),
|
|
1759
|
+
Status: statusSchema.optional()
|
|
1760
|
+
});
|
|
1761
|
+
var toBaseShipment = (s) => stripUndefined({
|
|
1762
|
+
mainBarcode: s.MainBarcode,
|
|
1763
|
+
barcode: s.Barcode,
|
|
1764
|
+
shipmentAmount: s.ShipmentAmount,
|
|
1765
|
+
shipmentCounter: s.ShipmentCounter,
|
|
1766
|
+
customer: s.Customer,
|
|
1767
|
+
productCode: s.ProductCode,
|
|
1768
|
+
productDescription: s.ProductDescription,
|
|
1769
|
+
reference: s.Reference,
|
|
1770
|
+
deliveryDate: s.DeliveryDate,
|
|
1771
|
+
dimension: s.Dimension,
|
|
1772
|
+
addresses: s.Address.length ? s.Address : void 0,
|
|
1773
|
+
productOptions: s.ProductOptions.length ? s.ProductOptions : void 0,
|
|
1774
|
+
status: s.Status
|
|
1775
|
+
});
|
|
1776
|
+
var currentStatusShipmentSchema = baseShipmentSchema.transform((s) => toBaseShipment(s));
|
|
1777
|
+
var completeStatusShipmentSchema = baseShipmentSchema.extend({
|
|
1778
|
+
Amount: amountSchema.optional(),
|
|
1779
|
+
Event: pnlArray(eventSchema),
|
|
1780
|
+
Expectation: expectationSchema.optional(),
|
|
1781
|
+
OldStatus: pnlArray(statusSchema)
|
|
1782
|
+
}).transform(
|
|
1783
|
+
(s) => stripUndefined({
|
|
1784
|
+
...toBaseShipment(s),
|
|
1785
|
+
amount: s.Amount,
|
|
1786
|
+
events: s.Event.length ? s.Event : void 0,
|
|
1787
|
+
expectation: s.Expectation,
|
|
1788
|
+
oldStatuses: s.OldStatus.length ? s.OldStatus : void 0
|
|
1789
|
+
})
|
|
1790
|
+
);
|
|
1791
|
+
var shippingStatusResponseSchema = zod.z.object({
|
|
1792
|
+
CurrentStatus: zod.z.object({ Shipment: currentStatusShipmentSchema }).optional(),
|
|
1793
|
+
CompleteStatus: zod.z.object({ Shipment: completeStatusShipmentSchema }).optional(),
|
|
1794
|
+
Warnings: pnlArray(warningSchema3)
|
|
1795
|
+
}).transform((r) => ({
|
|
1796
|
+
...stripUndefined({
|
|
1797
|
+
currentStatus: r.CurrentStatus?.Shipment,
|
|
1798
|
+
completeStatus: r.CompleteStatus?.Shipment
|
|
1799
|
+
}),
|
|
1800
|
+
warnings: r.Warnings
|
|
1801
|
+
}));
|
|
1802
|
+
var signatureSchema = zod.z.object({
|
|
1803
|
+
Barcode: zod.z.string().optional(),
|
|
1804
|
+
SignatureDate: pnlDate,
|
|
1805
|
+
SignatureImage: zod.z.string().optional()
|
|
1806
|
+
}).transform(
|
|
1807
|
+
(s) => stripUndefined({
|
|
1808
|
+
barcode: s.Barcode,
|
|
1809
|
+
signatureDate: s.SignatureDate,
|
|
1810
|
+
signatureImage: s.SignatureImage ? toDecodedLabel(s.SignatureImage, "gif") : void 0
|
|
1811
|
+
})
|
|
1812
|
+
);
|
|
1813
|
+
var signatureResponseSchema = zod.z.object({
|
|
1814
|
+
Signature: signatureSchema.optional(),
|
|
1815
|
+
// signature Warnings is a single-object wrapper { Warning: {...} }; unwrap to a 1-element array
|
|
1816
|
+
Warnings: zod.z.object({ Warning: pnlArray(warningSchema3) }).optional().transform((w) => w?.Warning ?? [])
|
|
1817
|
+
}).transform((r) => ({
|
|
1818
|
+
...stripUndefined({ signature: r.Signature }),
|
|
1819
|
+
warnings: r.Warnings
|
|
1820
|
+
}));
|
|
1821
|
+
var updatedShipmentStatusSchema = zod.z.object({
|
|
1822
|
+
Timestamp: pnlDate,
|
|
1823
|
+
StatusCode: zod.z.string().optional(),
|
|
1824
|
+
StatusDescription: zod.z.string().optional(),
|
|
1825
|
+
PhaseCode: zod.z.string().optional(),
|
|
1826
|
+
PhaseDescription: zod.z.string().optional()
|
|
1827
|
+
}).transform(
|
|
1828
|
+
(s) => stripUndefined({
|
|
1829
|
+
timestamp: s.Timestamp,
|
|
1830
|
+
statusCode: s.StatusCode,
|
|
1831
|
+
statusDescription: s.StatusDescription,
|
|
1832
|
+
phaseCode: s.PhaseCode,
|
|
1833
|
+
phaseDescription: s.PhaseDescription
|
|
1834
|
+
})
|
|
1835
|
+
);
|
|
1836
|
+
var updatedShipmentSchema = zod.z.object({
|
|
1837
|
+
Barcode: zod.z.string().optional(),
|
|
1838
|
+
CreationDate: pnlDate,
|
|
1839
|
+
CustomerNumber: zod.z.string().optional(),
|
|
1840
|
+
CustomerCode: zod.z.string().optional(),
|
|
1841
|
+
Status: updatedShipmentStatusSchema.optional()
|
|
1842
|
+
}).transform(
|
|
1843
|
+
(s) => stripUndefined({
|
|
1844
|
+
barcode: s.Barcode,
|
|
1845
|
+
creationDate: s.CreationDate,
|
|
1846
|
+
customerNumber: s.CustomerNumber,
|
|
1847
|
+
customerCode: s.CustomerCode,
|
|
1848
|
+
status: s.Status
|
|
1849
|
+
})
|
|
1850
|
+
);
|
|
1851
|
+
var updatedShipmentsResponseSchema = pnlArray(updatedShipmentSchema);
|
|
1852
|
+
|
|
1853
|
+
// src/resources/tracking/index.ts
|
|
1854
|
+
var TrackingResource = class extends BaseResource {
|
|
1855
|
+
// GET /shipment/v2/status/barcode/{barcode}
|
|
1856
|
+
byBarcode(barcode, options) {
|
|
1857
|
+
return this.call({
|
|
1858
|
+
operation: "trackingByBarcode",
|
|
1859
|
+
pathParams: { barcode },
|
|
1860
|
+
query: {
|
|
1861
|
+
detail: options?.detail,
|
|
1862
|
+
language: options?.language,
|
|
1863
|
+
maxDays: options?.maxDays
|
|
1864
|
+
},
|
|
1865
|
+
responseSchema: shippingStatusResponseSchema
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
// GET /shipment/v2/status/reference/{referenceId}; customerCode + customerNumber required
|
|
1869
|
+
byReference(referenceId, options) {
|
|
1870
|
+
return this.call({
|
|
1871
|
+
operation: "trackingByReference",
|
|
1872
|
+
pathParams: { referenceId },
|
|
1873
|
+
query: {
|
|
1874
|
+
customerCode: options.customerCode,
|
|
1875
|
+
customerNumber: options.customerNumber,
|
|
1876
|
+
detail: options.detail,
|
|
1877
|
+
language: options.language,
|
|
1878
|
+
maxDays: options.maxDays
|
|
1879
|
+
},
|
|
1880
|
+
responseSchema: shippingStatusResponseSchema
|
|
1881
|
+
});
|
|
1882
|
+
}
|
|
1883
|
+
// GET /shipment/v2/status/signature/{barcode}
|
|
1884
|
+
signature(barcode) {
|
|
1885
|
+
return this.call({
|
|
1886
|
+
operation: "trackingSignature",
|
|
1887
|
+
pathParams: { barcode },
|
|
1888
|
+
responseSchema: signatureResponseSchema
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
// GET /shipment/v2/status/{customernumber}/updatedshipments; two repeated period params
|
|
1892
|
+
updated(customerNumber, options) {
|
|
1893
|
+
return this.call({
|
|
1894
|
+
operation: "trackingUpdated",
|
|
1895
|
+
pathParams: { customernumber: customerNumber },
|
|
1896
|
+
query: { period: options.period },
|
|
1897
|
+
responseSchema: updatedShipmentsResponseSchema
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1902
|
+
// src/client.ts
|
|
1903
|
+
var PostNLClient = class {
|
|
1904
|
+
transport;
|
|
1905
|
+
barcode;
|
|
1906
|
+
shipping;
|
|
1907
|
+
return;
|
|
1908
|
+
tracking;
|
|
1909
|
+
deliveryDate;
|
|
1910
|
+
timeframe;
|
|
1911
|
+
location;
|
|
1912
|
+
checkout;
|
|
1913
|
+
address;
|
|
1914
|
+
constructor(options) {
|
|
1915
|
+
const config = resolveConfig(options);
|
|
1916
|
+
this.transport = new Transport(config);
|
|
1917
|
+
this.barcode = new BarcodeResource(this.transport);
|
|
1918
|
+
this.shipping = new ShippingResource(this.transport);
|
|
1919
|
+
this.return = new ReturnResource(this.transport);
|
|
1920
|
+
this.tracking = new TrackingResource(this.transport);
|
|
1921
|
+
this.deliveryDate = new DeliveryDateResource(this.transport);
|
|
1922
|
+
this.timeframe = new TimeframeResource(this.transport);
|
|
1923
|
+
this.location = new LocationResource(this.transport);
|
|
1924
|
+
this.checkout = new CheckoutResource(this.transport);
|
|
1925
|
+
this.address = new AddressResource(this.transport, config.environment);
|
|
1926
|
+
}
|
|
1927
|
+
// low-level escape hatch for endpoints/params not yet covered
|
|
1928
|
+
async request(args) {
|
|
1929
|
+
const raw = await this.transport.send({
|
|
1930
|
+
family: args.family,
|
|
1931
|
+
method: args.method,
|
|
1932
|
+
path: args.path,
|
|
1933
|
+
pathParams: args.pathParams,
|
|
1934
|
+
query: args.query,
|
|
1935
|
+
body: args.body
|
|
1936
|
+
});
|
|
1937
|
+
return args.schema ? args.schema.parse(raw) : raw;
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
// src/constants/product.ts
|
|
1942
|
+
var ProductCode = {
|
|
1943
|
+
domesticParcel: "3085",
|
|
1944
|
+
domesticInsured: "3087",
|
|
1945
|
+
easyReturn: "4910"
|
|
1946
|
+
};
|
|
1947
|
+
|
|
1948
|
+
// src/index.ts
|
|
1949
|
+
var version = "0.1.0";
|
|
1950
|
+
|
|
1951
|
+
exports.AddressResource = AddressResource;
|
|
1952
|
+
exports.AddressType = AddressType;
|
|
1953
|
+
exports.AssociatedDocumentType = AssociatedDocumentType;
|
|
1954
|
+
exports.BarcodeResource = BarcodeResource;
|
|
1955
|
+
exports.BarcodeType = BarcodeType;
|
|
1956
|
+
exports.Bundle = Bundle;
|
|
1957
|
+
exports.CheckoutCutOffDay = CheckoutCutOffDay;
|
|
1958
|
+
exports.CheckoutCutOffType = CheckoutCutOffType;
|
|
1959
|
+
exports.CheckoutOption = CheckoutOption;
|
|
1960
|
+
exports.CheckoutResource = CheckoutResource;
|
|
1961
|
+
exports.CheckoutWarningOption = CheckoutWarningOption;
|
|
1962
|
+
exports.ConsolidationMode = ConsolidationMode;
|
|
1963
|
+
exports.CountryCode = CountryCode;
|
|
1964
|
+
exports.Currency = Currency;
|
|
1965
|
+
exports.DeliveryConfirmation = DeliveryConfirmation;
|
|
1966
|
+
exports.DeliveryDateResource = DeliveryDateResource;
|
|
1967
|
+
exports.DeliverydateOption = DeliverydateOption;
|
|
1968
|
+
exports.Duration = Duration;
|
|
1969
|
+
exports.GuaranteedBefore = GuaranteedBefore;
|
|
1970
|
+
exports.IGNORED_LOCATION_OPTIONS = IGNORED_LOCATION_OPTIONS;
|
|
1971
|
+
exports.LabelType = LabelType;
|
|
1972
|
+
exports.LabellingCurrency = LabellingCurrency;
|
|
1973
|
+
exports.Language = Language;
|
|
1974
|
+
exports.LocationDeliveryOption = LocationDeliveryOption;
|
|
1975
|
+
exports.LocationResource = LocationResource;
|
|
1976
|
+
exports.MergeType = MergeType;
|
|
1977
|
+
exports.MinimalAgeCheck = MinimalAgeCheck;
|
|
1978
|
+
exports.NetworkType = NetworkType;
|
|
1979
|
+
exports.OriginCountryCode = OriginCountryCode;
|
|
1980
|
+
exports.OutputType = OutputType;
|
|
1981
|
+
exports.PageOrientation = PageOrientation;
|
|
1982
|
+
exports.Positioning = Positioning;
|
|
1983
|
+
exports.PostNLApiError = PostNLApiError;
|
|
1984
|
+
exports.PostNLAuthError = PostNLAuthError;
|
|
1985
|
+
exports.PostNLBadRequestError = PostNLBadRequestError;
|
|
1986
|
+
exports.PostNLClient = PostNLClient;
|
|
1987
|
+
exports.PostNLError = PostNLError;
|
|
1988
|
+
exports.PostNLMethodNotAllowedError = PostNLMethodNotAllowedError;
|
|
1989
|
+
exports.PostNLRateLimitError = PostNLRateLimitError;
|
|
1990
|
+
exports.PostNLServerError = PostNLServerError;
|
|
1991
|
+
exports.PostNLTimeoutError = PostNLTimeoutError;
|
|
1992
|
+
exports.PostNLValidationError = PostNLValidationError;
|
|
1993
|
+
exports.PrintMethod = PrintMethod;
|
|
1994
|
+
exports.ProductCode = ProductCode;
|
|
1995
|
+
exports.ReceiverType = ReceiverType;
|
|
1996
|
+
exports.Resolution = Resolution;
|
|
1997
|
+
exports.ReturnOutputType = ReturnOutputType;
|
|
1998
|
+
exports.ReturnPeriod = ReturnPeriod;
|
|
1999
|
+
exports.ReturnPeriodV4 = ReturnPeriodV4;
|
|
2000
|
+
exports.ReturnResource = ReturnResource;
|
|
2001
|
+
exports.ReturnShipmentTypeV4 = ReturnShipmentTypeV4;
|
|
2002
|
+
exports.Service = Service;
|
|
2003
|
+
exports.ShipmentTypeLegacy = ShipmentTypeLegacy;
|
|
2004
|
+
exports.ShipmentTypeV4 = ShipmentTypeV4;
|
|
2005
|
+
exports.ShippingResource = ShippingResource;
|
|
2006
|
+
exports.StatusLanguage = StatusLanguage;
|
|
2007
|
+
exports.SustainabilityCode = SustainabilityCode;
|
|
2008
|
+
exports.TimeframeOption = TimeframeOption;
|
|
2009
|
+
exports.TimeframeResource = TimeframeResource;
|
|
2010
|
+
exports.TrackingResource = TrackingResource;
|
|
2011
|
+
exports.decodeBase64 = decodeBase64;
|
|
2012
|
+
exports.labelContentType = labelContentType;
|
|
2013
|
+
exports.parseError = parseError;
|
|
2014
|
+
exports.toDecodedLabel = toDecodedLabel;
|
|
2015
|
+
exports.version = version;
|
|
2016
|
+
//# sourceMappingURL=index.cjs.map
|
|
2017
|
+
//# sourceMappingURL=index.cjs.map
|