postnl-client 0.1.0 → 0.2.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/dist/index.cjs +23 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -94
- package/dist/index.d.ts +91 -94
- package/dist/index.js +24 -12
- package/dist/index.js.map +1 -1
- package/package.json +14 -3
package/dist/index.cjs
CHANGED
|
@@ -89,12 +89,16 @@ function extract(body) {
|
|
|
89
89
|
detail: fault
|
|
90
90
|
};
|
|
91
91
|
const inv = b.Error;
|
|
92
|
-
if (inv
|
|
93
|
-
return {
|
|
92
|
+
if (inv && (inv.ErrorMessage || inv.ErrorDescription || inv.ErrorCode))
|
|
93
|
+
return {
|
|
94
|
+
message: inv.ErrorMessage ?? inv.ErrorDescription ?? "error",
|
|
95
|
+
code: inv.ErrorCode,
|
|
96
|
+
detail: b
|
|
97
|
+
};
|
|
94
98
|
const list = b.errors ?? b.Errors;
|
|
95
99
|
if (Array.isArray(list) && list.length) {
|
|
96
100
|
const f = list[0];
|
|
97
|
-
const msg = f.ErrorMsg ?? f.
|
|
101
|
+
const msg = f.ErrorMsg ?? f.Description ?? f.Error ?? f.title ?? f.detail ?? "error";
|
|
98
102
|
const code = f.ErrorNumber ?? f.Code ?? f.status;
|
|
99
103
|
return { message: String(msg), code: code != null ? String(code) : void 0, detail: list };
|
|
100
104
|
}
|
|
@@ -118,6 +122,15 @@ function parseError(status, body, headers) {
|
|
|
118
122
|
if (status === 400) return new PostNLBadRequestError(status, message, code, detail, body);
|
|
119
123
|
return new PostNLApiError(status, message, code, detail, body);
|
|
120
124
|
}
|
|
125
|
+
function inlineApiError(body) {
|
|
126
|
+
const b = body;
|
|
127
|
+
const err = b && typeof b === "object" ? b.Error : void 0;
|
|
128
|
+
if (err && typeof err === "object" && err.ErrorCode != null) {
|
|
129
|
+
const { message, code, detail } = extract(body);
|
|
130
|
+
return new PostNLApiError(200, message, code, detail, body);
|
|
131
|
+
}
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
121
134
|
|
|
122
135
|
// src/core/http.ts
|
|
123
136
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -286,6 +299,8 @@ var BaseResource = class {
|
|
|
286
299
|
query: args.query,
|
|
287
300
|
body: ep.method === "GET" ? void 0 : body
|
|
288
301
|
});
|
|
302
|
+
const inline = inlineApiError(raw);
|
|
303
|
+
if (inline) throw inline;
|
|
289
304
|
const out = args.responseSchema.safeParse(raw);
|
|
290
305
|
if (!out.success) throw new PostNLValidationError("invalid response", out.error.issues);
|
|
291
306
|
return out.data;
|
|
@@ -787,12 +802,12 @@ var addressSchema = zod.z.object({
|
|
|
787
802
|
}).transform(
|
|
788
803
|
(a) => stripUndefined({
|
|
789
804
|
city: a.City,
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
805
|
+
countryCode: a.Countrycode,
|
|
806
|
+
houseNumber: a.HouseNr,
|
|
807
|
+
houseNumberExtension: a.HouseNrExt,
|
|
793
808
|
remark: a.Remark,
|
|
794
809
|
street: a.Street,
|
|
795
|
-
|
|
810
|
+
postalCode: a.Zipcode
|
|
796
811
|
})
|
|
797
812
|
);
|
|
798
813
|
var day2 = pnlStringWrapped(zod.z.string()).optional();
|
|
@@ -1570,7 +1585,7 @@ var timeframeTimeframeSchema = zod.z.object({
|
|
|
1570
1585
|
);
|
|
1571
1586
|
var timeframeSchema2 = zod.z.object({
|
|
1572
1587
|
Date: pnlDateField,
|
|
1573
|
-
Timeframes: zod.z.object({
|
|
1588
|
+
Timeframes: zod.z.object({ TimeframeTimeFrame: pnlArray(timeframeTimeframeSchema) }).optional().transform((t) => t?.TimeframeTimeFrame ?? [])
|
|
1574
1589
|
}).transform((t) => ({
|
|
1575
1590
|
...stripUndefined({ date: t.Date }),
|
|
1576
1591
|
timeframes: t.Timeframes
|
|
@@ -1945,9 +1960,6 @@ var ProductCode = {
|
|
|
1945
1960
|
easyReturn: "4910"
|
|
1946
1961
|
};
|
|
1947
1962
|
|
|
1948
|
-
// src/index.ts
|
|
1949
|
-
var version = "0.1.0";
|
|
1950
|
-
|
|
1951
1963
|
exports.AddressResource = AddressResource;
|
|
1952
1964
|
exports.AddressType = AddressType;
|
|
1953
1965
|
exports.AssociatedDocumentType = AssociatedDocumentType;
|
|
@@ -2010,8 +2022,6 @@ exports.TimeframeResource = TimeframeResource;
|
|
|
2010
2022
|
exports.TrackingResource = TrackingResource;
|
|
2011
2023
|
exports.decodeBase64 = decodeBase64;
|
|
2012
2024
|
exports.labelContentType = labelContentType;
|
|
2013
|
-
exports.parseError = parseError;
|
|
2014
2025
|
exports.toDecodedLabel = toDecodedLabel;
|
|
2015
|
-
exports.version = version;
|
|
2016
2026
|
//# sourceMappingURL=index.cjs.map
|
|
2017
2027
|
//# sourceMappingURL=index.cjs.map
|