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