postnl-client 0.1.0 → 0.1.1
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 +18 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/package.json +14 -3
package/dist/index.cjs
CHANGED
|
@@ -89,8 +89,12 @@ 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];
|
|
@@ -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;
|
|
@@ -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
|
|
@@ -2010,7 +2025,6 @@ exports.TimeframeResource = TimeframeResource;
|
|
|
2010
2025
|
exports.TrackingResource = TrackingResource;
|
|
2011
2026
|
exports.decodeBase64 = decodeBase64;
|
|
2012
2027
|
exports.labelContentType = labelContentType;
|
|
2013
|
-
exports.parseError = parseError;
|
|
2014
2028
|
exports.toDecodedLabel = toDecodedLabel;
|
|
2015
2029
|
exports.version = version;
|
|
2016
2030
|
//# sourceMappingURL=index.cjs.map
|