@deliverart/sdk-js-error-handler 2.48.0 → 3.0.0-dev.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/README.md CHANGED
@@ -479,3 +479,12 @@ try {
479
479
 
480
480
  MIT
481
481
 
482
+
483
+
484
+ ## Safe diagnostics
485
+
486
+ `ApiError` keeps its original `request`, `response`, `data`, `code`, `status` and message readable for typed consumers and form-state conversion. Transport objects, raw bodies and status/code fields are non-enumerable. Default Node inspection, string formatting and JSON serialization expose only an allowlisted diagnostic: stable classification, HTTP status/code, method and a pathname without query, fragment, origin or user information. The plugin captures that pathname from the actual request context. Validation field messages remain available programmatically and are not included in these diagnostics.
487
+
488
+ Do not log raw `error.request`, `error.response`, `error.data`, custom caller messages or arbitrary stack/exception serializers. This SDK behavior does not sanitize Next.js access logs, OAuth callback URLs logged elsewhere, or independent telemetry request contexts.
489
+
490
+ The focused built-artifact tests exercise ESM and CommonJS diagnostics, secret omission, actual response middleware and form-state compatibility. Build this package and its workspace dependencies first, then run `pnpm --filter @deliverart/sdk-js-error-handler test`. No test runner dependency is added: tests use Node's built-in runner.
package/dist/index.cjs CHANGED
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
6
9
  var __export = (target, all) => {
7
10
  for (var name in all)
8
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
16
19
  return to;
17
20
  };
18
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
19
26
 
20
27
  // src/index.ts
21
28
  var index_exports = {};
@@ -30,17 +37,55 @@ __export(index_exports, {
30
37
  module.exports = __toCommonJS(index_exports);
31
38
 
32
39
  // src/errors.ts
40
+ function safePath(value) {
41
+ if (!value || value.length > 8192) return void 0;
42
+ try {
43
+ const url = new URL(value, "https://sdk.invalid");
44
+ if (!["http:", "https:"].includes(url.protocol) || url.pathname.length > 1024) return void 0;
45
+ return url.pathname;
46
+ } catch {
47
+ return void 0;
48
+ }
49
+ }
50
+ var _path;
33
51
  var ApiError = class extends Error {
34
52
  constructor(message = "Unexpected API error", code, request, response, extra) {
35
53
  super(message);
36
54
  this.name = "ApiError";
55
+ __privateAdd(this, _path);
37
56
  this.code = code;
38
57
  this.request = request;
39
58
  this.response = response;
40
59
  this.status = extra?.status;
41
60
  this.data = extra?.data;
61
+ __privateSet(this, _path, safePath(extra?.path ?? response?.url));
62
+ for (const key of ["code", "request", "response", "data", "status"]) {
63
+ Object.defineProperty(this, key, { enumerable: false });
64
+ }
65
+ }
66
+ toJSON() {
67
+ const validation = this.data?.type === "VALIDATION_ERROR";
68
+ const status = typeof this.status === "number" && Number.isInteger(this.status) && this.status >= 100 && this.status <= 599 ? this.status : void 0;
69
+ const method = this.request?.method?.toUpperCase();
70
+ return {
71
+ name: "ApiError",
72
+ message: validation ? "Validation error" : "API request failed",
73
+ cause: validation ? "validation_error" : "http_error",
74
+ status,
75
+ code: typeof this.code === "string" && /^[1-5][0-9]{2}$/.test(this.code) ? this.code : void 0,
76
+ method: method && ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(method) ? method : void 0,
77
+ path: __privateGet(this, _path)
78
+ };
79
+ }
80
+ toString() {
81
+ const diagnostic = this.toJSON();
82
+ return `${diagnostic.name}: ${diagnostic.message}${diagnostic.status ? ` (${diagnostic.status})` : ""}`;
83
+ }
84
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
85
+ return this.toJSON();
42
86
  }
43
87
  };
88
+ _path = new WeakMap();
44
89
 
45
90
  // src/form-state.ts
46
91
  var FormStateError = class extends Error {
@@ -107,12 +152,14 @@ var ErrorHandlerPlugin = class {
107
152
  if (parsed.success) {
108
153
  throw new ApiError("Validation error", String(status), ctx.init, response, {
109
154
  status,
155
+ path: ctx.url.pathname,
110
156
  data: { type: "VALIDATION_ERROR", value: parsed.data }
111
157
  });
112
158
  }
113
159
  }
114
160
  throw new ApiError("Unknown error", String(status), ctx.init, response, {
115
161
  status,
162
+ path: ctx.url.pathname,
116
163
  data: { type: "UNKNOWN_ERROR", value: body }
117
164
  });
118
165
  });
package/dist/index.d.cts CHANGED
@@ -21,7 +21,17 @@ type ApiErrorData = {
21
21
  type: 'UNKNOWN_ERROR';
22
22
  value: unknown;
23
23
  };
24
+ interface ApiErrorDiagnostics {
25
+ name: 'ApiError';
26
+ message: 'Validation error' | 'API request failed';
27
+ cause: 'validation_error' | 'http_error';
28
+ status?: number;
29
+ code?: string;
30
+ method?: string;
31
+ path?: string;
32
+ }
24
33
  declare class ApiError extends Error {
34
+ #private;
25
35
  readonly name = "ApiError";
26
36
  readonly code?: string;
27
37
  readonly request?: RequestInit;
@@ -31,7 +41,10 @@ declare class ApiError extends Error {
31
41
  constructor(message?: string, code?: string, request?: RequestInit, response?: Response, extra?: {
32
42
  status?: number;
33
43
  data?: ApiErrorData;
44
+ path?: string;
34
45
  });
46
+ toJSON(): ApiErrorDiagnostics;
47
+ toString(): string;
35
48
  }
36
49
 
37
50
  type FormState<T> = {
@@ -58,4 +71,4 @@ declare class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
58
71
  setup(client: ApiClient): {};
59
72
  }
60
73
 
61
- export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type FormState, FormStateError, type ValidationErrorData, formStateErrorToThrowable, throwableToFormState, validationErrorDataSchema };
74
+ export { ApiError, type ApiErrorData, type ApiErrorDiagnostics, ErrorHandlerPlugin, type FormState, FormStateError, type ValidationErrorData, formStateErrorToThrowable, throwableToFormState, validationErrorDataSchema };
package/dist/index.d.ts CHANGED
@@ -21,7 +21,17 @@ type ApiErrorData = {
21
21
  type: 'UNKNOWN_ERROR';
22
22
  value: unknown;
23
23
  };
24
+ interface ApiErrorDiagnostics {
25
+ name: 'ApiError';
26
+ message: 'Validation error' | 'API request failed';
27
+ cause: 'validation_error' | 'http_error';
28
+ status?: number;
29
+ code?: string;
30
+ method?: string;
31
+ path?: string;
32
+ }
24
33
  declare class ApiError extends Error {
34
+ #private;
25
35
  readonly name = "ApiError";
26
36
  readonly code?: string;
27
37
  readonly request?: RequestInit;
@@ -31,7 +41,10 @@ declare class ApiError extends Error {
31
41
  constructor(message?: string, code?: string, request?: RequestInit, response?: Response, extra?: {
32
42
  status?: number;
33
43
  data?: ApiErrorData;
44
+ path?: string;
34
45
  });
46
+ toJSON(): ApiErrorDiagnostics;
47
+ toString(): string;
35
48
  }
36
49
 
37
50
  type FormState<T> = {
@@ -58,4 +71,4 @@ declare class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
58
71
  setup(client: ApiClient): {};
59
72
  }
60
73
 
61
- export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type FormState, FormStateError, type ValidationErrorData, formStateErrorToThrowable, throwableToFormState, validationErrorDataSchema };
74
+ export { ApiError, type ApiErrorData, type ApiErrorDiagnostics, ErrorHandlerPlugin, type FormState, FormStateError, type ValidationErrorData, formStateErrorToThrowable, throwableToFormState, validationErrorDataSchema };
package/dist/index.js CHANGED
@@ -1,15 +1,61 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+
1
9
  // src/errors.ts
10
+ function safePath(value) {
11
+ if (!value || value.length > 8192) return void 0;
12
+ try {
13
+ const url = new URL(value, "https://sdk.invalid");
14
+ if (!["http:", "https:"].includes(url.protocol) || url.pathname.length > 1024) return void 0;
15
+ return url.pathname;
16
+ } catch {
17
+ return void 0;
18
+ }
19
+ }
20
+ var _path;
2
21
  var ApiError = class extends Error {
3
22
  constructor(message = "Unexpected API error", code, request, response, extra) {
4
23
  super(message);
5
24
  this.name = "ApiError";
25
+ __privateAdd(this, _path);
6
26
  this.code = code;
7
27
  this.request = request;
8
28
  this.response = response;
9
29
  this.status = extra?.status;
10
30
  this.data = extra?.data;
31
+ __privateSet(this, _path, safePath(extra?.path ?? response?.url));
32
+ for (const key of ["code", "request", "response", "data", "status"]) {
33
+ Object.defineProperty(this, key, { enumerable: false });
34
+ }
35
+ }
36
+ toJSON() {
37
+ const validation = this.data?.type === "VALIDATION_ERROR";
38
+ const status = typeof this.status === "number" && Number.isInteger(this.status) && this.status >= 100 && this.status <= 599 ? this.status : void 0;
39
+ const method = this.request?.method?.toUpperCase();
40
+ return {
41
+ name: "ApiError",
42
+ message: validation ? "Validation error" : "API request failed",
43
+ cause: validation ? "validation_error" : "http_error",
44
+ status,
45
+ code: typeof this.code === "string" && /^[1-5][0-9]{2}$/.test(this.code) ? this.code : void 0,
46
+ method: method && ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(method) ? method : void 0,
47
+ path: __privateGet(this, _path)
48
+ };
49
+ }
50
+ toString() {
51
+ const diagnostic = this.toJSON();
52
+ return `${diagnostic.name}: ${diagnostic.message}${diagnostic.status ? ` (${diagnostic.status})` : ""}`;
53
+ }
54
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
55
+ return this.toJSON();
11
56
  }
12
57
  };
58
+ _path = new WeakMap();
13
59
 
14
60
  // src/form-state.ts
15
61
  var FormStateError = class extends Error {
@@ -76,12 +122,14 @@ var ErrorHandlerPlugin = class {
76
122
  if (parsed.success) {
77
123
  throw new ApiError("Validation error", String(status), ctx.init, response, {
78
124
  status,
125
+ path: ctx.url.pathname,
79
126
  data: { type: "VALIDATION_ERROR", value: parsed.data }
80
127
  });
81
128
  }
82
129
  }
83
130
  throw new ApiError("Unknown error", String(status), ctx.init, response, {
84
131
  status,
132
+ path: ctx.url.pathname,
85
133
  data: { type: "UNKNOWN_ERROR", value: body }
86
134
  });
87
135
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deliverart/sdk-js-error-handler",
3
3
  "description": "Error handling utilities for Deliverart SDK in JavaScript",
4
- "version": "2.48.0",
4
+ "version": "3.0.0-dev.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -18,8 +18,8 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "zod": "4.3.5",
22
- "@deliverart/sdk-js-core": "2.48.0"
21
+ "zod": "4.6.6",
22
+ "@deliverart/sdk-js-core": "3.0.0-dev.1"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"
@@ -27,6 +27,7 @@
27
27
  "scripts": {
28
28
  "build": "tsup src/index.ts --dts --format esm,cjs",
29
29
  "dev": "tsup src/index.ts --dts --watch",
30
- "clean": "rm -rf dist"
30
+ "clean": "rm -rf dist",
31
+ "test": "node --test tests/*.test.mjs"
31
32
  }
32
33
  }