@shipstatic/types 0.9.3 → 0.9.4

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.d.ts CHANGED
@@ -317,9 +317,9 @@ export declare const ErrorType: {
317
317
  readonly Business: "business_logic_error";
318
318
  /** API server error (500) */
319
319
  readonly Api: "internal_server_error";
320
- /** Network/connection error */
320
+ /** Network/connection error. Client-side only — set by HTTP clients on fetch failure; never produced server-side. */
321
321
  readonly Network: "network_error";
322
- /** Operation was cancelled */
322
+ /** Operation was cancelled. Client-side only — set on `AbortSignal` abort; never produced server-side. */
323
323
  readonly Cancelled: "operation_cancelled";
324
324
  /** File operation error */
325
325
  readonly File: "file_error";
package/dist/index.js CHANGED
@@ -71,9 +71,9 @@ export const ErrorType = {
71
71
  Business: 'business_logic_error',
72
72
  /** API server error (500) */
73
73
  Api: 'internal_server_error',
74
- /** Network/connection error */
74
+ /** Network/connection error. Client-side only — set by HTTP clients on fetch failure; never produced server-side. */
75
75
  Network: 'network_error',
76
- /** Operation was cancelled */
76
+ /** Operation was cancelled. Client-side only — set on `AbortSignal` abort; never produced server-side. */
77
77
  Cancelled: 'operation_cancelled',
78
78
  /** File operation error */
79
79
  File: 'file_error',
@@ -91,12 +91,16 @@ const ERROR_CATEGORIES = {
91
91
  auth: new Set([ErrorType.Authentication]),
92
92
  };
93
93
  /**
94
- * Lookup set of known wire-format error type strings. Used by
95
- * `ShipError.fromHttpResponse` to validate the body's `error` field before
96
- * trusting it as an `ErrorType`. Defensive against malformed/unknown values
97
- * that could otherwise leak into the typed `ShipError.type` field.
94
+ * Lookup set of error types that legitimately appear on the wire — i.e.
95
+ * server-thrown types. Used by `ShipError.fromHttpResponse` to validate the
96
+ * body's `error` field before trusting it as the `ShipError.type`.
97
+ *
98
+ * Excludes `Network` and `Cancelled`, which are client-side-only by design:
99
+ * they originate on the client (fetch failure, abort) and should never be
100
+ * reconstructed from a server response, even if a misbehaving server were
101
+ * to send them. A defensive omission, not a theoretical concern.
98
102
  */
99
- const KNOWN_ERROR_TYPES = new Set(Object.values(ErrorType));
103
+ const SERVER_PRODUCIBLE_ERROR_TYPES = new Set(Object.values(ErrorType).filter(t => t !== ErrorType.Network && t !== ErrorType.Cancelled));
100
104
  /**
101
105
  * Simple unified error class for both API and SDK
102
106
  */
@@ -155,7 +159,7 @@ export class ShipError extends Error {
155
159
  else if (typeof obj.error === 'string')
156
160
  message = obj.error;
157
161
  details = obj.details;
158
- if (typeof obj.error === 'string' && KNOWN_ERROR_TYPES.has(obj.error)) {
162
+ if (typeof obj.error === 'string' && SERVER_PRODUCIBLE_ERROR_TYPES.has(obj.error)) {
159
163
  bodyType = obj.error;
160
164
  }
161
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "Shared types for ShipStatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -362,9 +362,9 @@ export const ErrorType = {
362
362
  Business: 'business_logic_error',
363
363
  /** API server error (500) */
364
364
  Api: 'internal_server_error',
365
- /** Network/connection error */
365
+ /** Network/connection error. Client-side only — set by HTTP clients on fetch failure; never produced server-side. */
366
366
  Network: 'network_error',
367
- /** Operation was cancelled */
367
+ /** Operation was cancelled. Client-side only — set on `AbortSignal` abort; never produced server-side. */
368
368
  Cancelled: 'operation_cancelled',
369
369
  /** File operation error */
370
370
  File: 'file_error',
@@ -386,12 +386,20 @@ const ERROR_CATEGORIES = {
386
386
  } as const;
387
387
 
388
388
  /**
389
- * Lookup set of known wire-format error type strings. Used by
390
- * `ShipError.fromHttpResponse` to validate the body's `error` field before
391
- * trusting it as an `ErrorType`. Defensive against malformed/unknown values
392
- * that could otherwise leak into the typed `ShipError.type` field.
389
+ * Lookup set of error types that legitimately appear on the wire — i.e.
390
+ * server-thrown types. Used by `ShipError.fromHttpResponse` to validate the
391
+ * body's `error` field before trusting it as the `ShipError.type`.
392
+ *
393
+ * Excludes `Network` and `Cancelled`, which are client-side-only by design:
394
+ * they originate on the client (fetch failure, abort) and should never be
395
+ * reconstructed from a server response, even if a misbehaving server were
396
+ * to send them. A defensive omission, not a theoretical concern.
393
397
  */
394
- const KNOWN_ERROR_TYPES = new Set<string>(Object.values(ErrorType));
398
+ const SERVER_PRODUCIBLE_ERROR_TYPES = new Set<string>(
399
+ Object.values(ErrorType).filter(
400
+ t => t !== ErrorType.Network && t !== ErrorType.Cancelled,
401
+ ),
402
+ );
395
403
 
396
404
  /**
397
405
  * Standard error response format used everywhere
@@ -469,7 +477,7 @@ export class ShipError extends Error {
469
477
  if (typeof obj.message === 'string') message = obj.message;
470
478
  else if (typeof obj.error === 'string') message = obj.error;
471
479
  details = obj.details;
472
- if (typeof obj.error === 'string' && KNOWN_ERROR_TYPES.has(obj.error)) {
480
+ if (typeof obj.error === 'string' && SERVER_PRODUCIBLE_ERROR_TYPES.has(obj.error)) {
473
481
  bodyType = obj.error as ErrorType;
474
482
  }
475
483
  }