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 CHANGED
@@ -89,12 +89,16 @@ function extract(body) {
89
89
  detail: fault
90
90
  };
91
91
  const inv = b.Error;
92
- if (inv?.ErrorDescription)
93
- return { message: inv.ErrorDescription, code: inv.ErrorCode, detail: b };
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.Error ?? f.title ?? f.Description ?? f.detail ?? "error";
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
- countrycode: a.Countrycode,
791
- houseNr: a.HouseNr,
792
- houseNrExt: a.HouseNrExt,
805
+ countryCode: a.Countrycode,
806
+ houseNumber: a.HouseNr,
807
+ houseNumberExtension: a.HouseNrExt,
793
808
  remark: a.Remark,
794
809
  street: a.Street,
795
- zipcode: a.Zipcode
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({ TimeframeTimeframe: pnlArray(timeframeTimeframeSchema) }).optional().transform((t) => t?.TimeframeTimeframe ?? [])
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