@webpieces/core-util 0.4.761 → 0.4.763

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.
Files changed (56) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/errors/ApiError.d.ts +43 -49
  4. package/src/errors/ApiError.js +54 -59
  5. package/src/errors/ApiError.js.map +1 -1
  6. package/src/errors/ApiErrorCodec.d.ts +11 -6
  7. package/src/errors/ApiErrorCodec.js +93 -87
  8. package/src/errors/ApiErrorCodec.js.map +1 -1
  9. package/src/errors/AuthErrorSubtypes.d.ts +9 -0
  10. package/src/errors/AuthErrorSubtypes.js +13 -0
  11. package/src/errors/AuthErrorSubtypes.js.map +1 -0
  12. package/src/errors/index.d.ts +3 -1
  13. package/src/errors/index.js +24 -15
  14. package/src/errors/index.js.map +1 -1
  15. package/src/http/{TimeoutError.d.ts → ApiCallTimeoutError.d.ts} +1 -1
  16. package/src/http/{TimeoutError.js → ApiCallTimeoutError.js} +5 -5
  17. package/src/http/ApiCallTimeoutError.js.map +1 -0
  18. package/src/http/{HttpErrorStatus.d.ts → ApiErrorHttpStatus.d.ts} +2 -1
  19. package/src/http/ApiErrorHttpStatus.js +43 -0
  20. package/src/http/ApiErrorHttpStatus.js.map +1 -0
  21. package/src/http/CallDeadline.js +2 -2
  22. package/src/http/CallDeadline.js.map +1 -1
  23. package/src/http/ErrorTranslators.d.ts +5 -3
  24. package/src/http/ErrorTranslators.js.map +1 -1
  25. package/src/http/HttpResponseDto.d.ts +1 -1
  26. package/src/http/HttpResponseDto.js +2 -2
  27. package/src/http/HttpResponseDto.js.map +1 -1
  28. package/src/http/WebpiecesDefaultFailureClassifier.d.ts +6 -6
  29. package/src/http/WebpiecesDefaultFailureClassifier.js +12 -12
  30. package/src/http/WebpiecesDefaultFailureClassifier.js.map +1 -1
  31. package/src/http/decorators.d.ts +1 -1
  32. package/src/http/decorators.js +1 -1
  33. package/src/http/decorators.js.map +1 -1
  34. package/src/http/networkReject.d.ts +2 -2
  35. package/src/http/networkReject.js +5 -5
  36. package/src/http/networkReject.js.map +1 -1
  37. package/src/index.d.ts +5 -4
  38. package/src/index.js +23 -38
  39. package/src/index.js.map +1 -1
  40. package/src/ipc/IpcConnection.js +14 -14
  41. package/src/ipc/IpcConnection.js.map +1 -1
  42. package/src/ipc/IpcDecorators.js +9 -9
  43. package/src/ipc/IpcDecorators.js.map +1 -1
  44. package/src/ipc/IpcIdentity.js +1 -1
  45. package/src/ipc/IpcIdentity.js.map +1 -1
  46. package/src/ipc/IpcProtocol.js +5 -5
  47. package/src/ipc/IpcProtocol.js.map +1 -1
  48. package/src/ipc/index.d.ts +1 -1
  49. package/src/ipc/index.js +3 -3
  50. package/src/ipc/index.js.map +1 -1
  51. package/src/http/HttpErrorStatus.js +0 -38
  52. package/src/http/HttpErrorStatus.js.map +0 -1
  53. package/src/http/TimeoutError.js.map +0 -1
  54. package/src/http/errors.d.ts +0 -56
  55. package/src/http/errors.js +0 -95
  56. package/src/http/errors.js.map +0 -1
@@ -2,42 +2,43 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiErrorCodec = exports.ApiErrorPayload = void 0;
4
4
  const ApiError_1 = require("./ApiError");
5
- /** Allowlisted error envelope shared by non-HTTP transports. Contains only bounded semantic causes, never stacks or arbitrary properties. */
5
+ /** Allowlisted transport-neutral envelope. It never contains stacks or arbitrary properties. */
6
6
  class ApiErrorPayload {
7
7
  kind;
8
8
  message;
9
9
  cause;
10
10
  subType;
11
11
  field;
12
- guiAlertMessage;
12
+ callerMessage;
13
13
  errorCode;
14
- waitSeconds;
15
- constructor(kind, message) {
14
+ retryAfterSeconds;
15
+ constructor(kind = 'implementation', message = 'Internal Error') {
16
16
  this.kind = kind;
17
17
  this.message = message;
18
18
  }
19
19
  }
20
20
  exports.ApiErrorPayload = ApiErrorPayload;
21
- /** Bounded, safe, transport-neutral encoding. Unrecognized types become generic internal failures. */
21
+ /** Bounded safe codec shared by HTTP, IPC, and other remote adapters. */
22
22
  class ApiErrorCodec {
23
- // webpieces-disable no-function-outside-class -- stateless public codec shared by transport adapters; webpieces-disable no-any-unknown -- thrown values are untrusted until narrowed by the codec
23
+ // webpieces-disable no-function-outside-class -- stateless public transport codec; webpieces-disable no-any-unknown -- thrown values are untrusted until narrowed
24
24
  static encode(error) {
25
25
  return this.encodeDepth(error, 0);
26
26
  }
27
- // webpieces-disable no-function-outside-class -- recursive bounded wire codec; webpieces-disable no-any-unknown -- thrown causes require runtime narrowing
27
+ // webpieces-disable no-function-outside-class -- recursive bounded transport codec; webpieces-disable no-any-unknown -- thrown causes require narrowing
28
28
  static encodeDepth(error, depth) {
29
- const kind = this.kind(error);
30
- const payload = new ApiErrorPayload(kind, error instanceof ApiError_1.UserError ? error.message.slice(0, 4096) : this.message(kind));
29
+ const kind = error instanceof ApiError_1.ApiError ? error.kind : 'implementation';
30
+ const payload = new ApiErrorPayload(kind, this.publicMessage(error, kind));
31
31
  if (error instanceof ApiError_1.ApiError)
32
32
  payload.subType = this.text(error.subType);
33
- if (error instanceof ApiError_1.UserError)
33
+ if (error instanceof ApiError_1.ApiEndUserError)
34
34
  payload.errorCode = this.text(error.errorCode);
35
- if (error instanceof ApiError_1.BadRequestError) {
35
+ if (error instanceof ApiError_1.ApiBadRequestError) {
36
36
  payload.field = this.text(error.field);
37
- payload.guiAlertMessage = this.text(error.guiMessage);
37
+ payload.callerMessage = this.text(error.callerMessage);
38
+ }
39
+ if (error instanceof ApiError_1.ApiDependencyBackoffError) {
40
+ payload.retryAfterSeconds = this.wait(error.retryAfterSeconds);
38
41
  }
39
- if (error instanceof ApiError_1.VendorError)
40
- payload.waitSeconds = this.wait(error.waitSeconds);
41
42
  if (error instanceof Error && depth < 3) {
42
43
  const cause = Object.getOwnPropertyDescriptor(error, 'cause')?.value;
43
44
  if (cause instanceof Error)
@@ -45,17 +46,26 @@ class ApiErrorCodec {
45
46
  }
46
47
  return payload;
47
48
  }
48
- // webpieces-disable no-function-outside-class -- stateless public codec shared by transport adapters; webpieces-disable no-any-unknown -- JSON transport input must be validated before use
49
+ /** Decode a value received from another process. Implementation failures are marked remote. */
50
+ // webpieces-disable no-function-outside-class -- stateless public transport codec; webpieces-disable no-any-unknown -- wire values require validation
49
51
  static decode(value) {
50
52
  return this.decodeDepth(value, 0);
51
53
  }
52
- // webpieces-disable no-function-outside-class -- recursive bounded wire codec; webpieces-disable no-any-unknown -- remote causes remain untrusted until validated
54
+ /** Whether a body carries a recognized Webpieces semantic discriminator. */
55
+ // webpieces-disable no-function-outside-class -- stateless wire discriminator check; webpieces-disable no-any-unknown -- wire values require validation
56
+ static isPayload(value) {
57
+ if (typeof value !== 'object' || value === null)
58
+ return false;
59
+ const kind = Object.getOwnPropertyDescriptor(value, 'kind')?.value;
60
+ return typeof kind === 'string' && this.kinds.has(kind);
61
+ }
62
+ // webpieces-disable no-function-outside-class -- recursive bounded transport codec; webpieces-disable no-any-unknown -- remote causes require validation
53
63
  static decodeDepth(value, depth) {
54
64
  const error = this.decodeOne(value);
55
65
  if (typeof value === 'object' && value !== null && depth < 3) {
56
66
  const cause = Object.getOwnPropertyDescriptor(value, 'cause')?.value;
57
67
  if (typeof cause === 'object' && cause !== null) {
58
- // webpieces-disable no-anonymous-object-literals -- standard property descriptor keeps Error.cause non-enumerable
68
+ // webpieces-disable no-anonymous-object-literals -- standard descriptor preserves Error.cause semantics
59
69
  Object.defineProperty(error, 'cause', {
60
70
  value: this.decodeDepth(cause, depth + 1),
61
71
  configurable: true,
@@ -65,92 +75,72 @@ class ApiErrorCodec {
65
75
  }
66
76
  return error;
67
77
  }
68
- // webpieces-disable no-function-outside-class -- allowlisted wire codec; webpieces-disable no-any-unknown -- JSON transport input must be validated before use
78
+ // webpieces-disable no-function-outside-class -- allowlisted wire codec; webpieces-disable no-any-unknown -- wire fields require validation
69
79
  static decodeOne(value) {
70
80
  if (typeof value !== 'object' || value === null)
71
- return new ApiError_1.InternalError('Internal Error');
81
+ return this.remoteImplementationError();
72
82
  // webpieces-disable no-any-unknown -- own wire fields remain untrusted until narrowed
73
83
  const field = (key) => Object.getOwnPropertyDescriptor(value, key)?.value;
74
84
  const kind = field('kind');
75
85
  const message = this.text(field('message')) ?? this.message(kind);
76
86
  switch (kind) {
77
- case 'user':
78
- return new ApiError_1.UserError(message, this.text(field('errorCode')));
87
+ case 'end-user':
88
+ return new ApiError_1.ApiEndUserError(message, this.text(field('errorCode')));
79
89
  case 'bad-request':
80
- return new ApiError_1.BadRequestError(message, this.text(field('field')), this.text(field('guiAlertMessage')));
90
+ return new ApiError_1.ApiBadRequestError(message, this.text(field('field')), this.text(field('callerMessage')));
81
91
  case 'unauthorized':
82
- return new ApiError_1.UnauthorizedError(message, this.text(field('subType')));
92
+ return new ApiError_1.ApiUnauthorizedError(message, this.text(field('subType')));
83
93
  case 'forbidden':
84
- return new ApiError_1.ForbiddenError(message);
94
+ return new ApiError_1.ApiForbiddenError(message);
85
95
  case 'not-found':
86
- return new ApiError_1.NotFoundError(message);
96
+ return new ApiError_1.ApiNotFoundError(message);
87
97
  case 'endpoint-not-found':
88
- return new ApiError_1.EndpointNotFoundError(message);
98
+ return new ApiError_1.ApiEndpointNotFoundError(message);
89
99
  case 'request-timeout':
90
- return new ApiError_1.RequestTimeoutError(message);
91
- case 'too-many-requests':
92
- return new ApiError_1.TooManyRequestsError(message);
93
- case 'bad-gateway':
94
- return new ApiError_1.BadGatewayError(message);
95
- case 'service-unavailable':
96
- return new ApiError_1.ServiceUnavailableError(message);
97
- case 'gateway-timeout':
98
- return new ApiError_1.GatewayTimeoutError(message);
99
- case 'vendor':
100
- return new ApiError_1.VendorError(message, this.wait(field('waitSeconds')));
101
- case 'offline':
102
- return new ApiError_1.OfflineError(message);
103
- case 'internal':
104
- return new ApiError_1.InternalError(message);
100
+ return new ApiError_1.ApiRequestTimeoutError(message);
101
+ case 'rate-limited':
102
+ return new ApiError_1.ApiRateLimitedError(message);
103
+ case 'dependency':
104
+ return new ApiError_1.ApiDependencyError(message);
105
+ case 'unavailable':
106
+ return new ApiError_1.ApiUnavailableError(message);
107
+ case 'dependency-timeout':
108
+ return new ApiError_1.ApiDependencyTimeoutError(message);
109
+ case 'dependency-backoff':
110
+ return new ApiError_1.ApiDependencyBackoffError(message, this.wait(field('retryAfterSeconds')));
111
+ case 'connection':
112
+ return new ApiError_1.ApiConnectionError(message);
113
+ case 'implementation':
114
+ return new ApiError_1.ApiImplementationError(message, undefined, true);
105
115
  default:
106
- return new ApiError_1.InternalError('Internal Error');
116
+ return this.remoteImplementationError();
107
117
  }
108
118
  }
109
- // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- thrown values need instanceof narrowing before encoding
110
- static kind(error) {
111
- if (error instanceof ApiError_1.UserError)
112
- return 'user';
113
- if (error instanceof ApiError_1.BadRequestError)
114
- return 'bad-request';
115
- if (error instanceof ApiError_1.UnauthorizedError)
116
- return 'unauthorized';
117
- if (error instanceof ApiError_1.ForbiddenError)
118
- return 'forbidden';
119
- if (error instanceof ApiError_1.EndpointNotFoundError)
120
- return 'endpoint-not-found';
121
- if (error instanceof ApiError_1.NotFoundError)
122
- return 'not-found';
123
- if (error instanceof ApiError_1.RequestTimeoutError)
124
- return 'request-timeout';
125
- if (error instanceof ApiError_1.TooManyRequestsError)
126
- return 'too-many-requests';
127
- if (error instanceof ApiError_1.BadGatewayError)
128
- return 'bad-gateway';
129
- if (error instanceof ApiError_1.ServiceUnavailableError)
130
- return 'service-unavailable';
131
- if (error instanceof ApiError_1.GatewayTimeoutError)
132
- return 'gateway-timeout';
133
- if (error instanceof ApiError_1.VendorError)
134
- return 'vendor';
135
- if (error instanceof ApiError_1.OfflineError)
136
- return 'offline';
137
- return 'internal';
119
+ // webpieces-disable no-function-outside-class -- concrete normalization for malformed remote errors
120
+ static remoteImplementationError() {
121
+ return new ApiError_1.ApiImplementationError('Internal Error', undefined, true);
122
+ }
123
+ // webpieces-disable no-function-outside-class -- caller-safe message selection; webpieces-disable no-any-unknown -- thrown values require narrowing
124
+ static publicMessage(error, kind) {
125
+ if (error instanceof ApiError_1.ApiEndUserError)
126
+ return error.message.slice(0, 4096);
127
+ return this.message(kind);
138
128
  }
139
- // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire fields need runtime string checks
129
+ // webpieces-disable no-function-outside-class -- wire string bound; webpieces-disable no-any-unknown -- wire values require validation
140
130
  static text(value) {
141
131
  return typeof value === 'string' ? value.slice(0, 4096) : undefined;
142
132
  }
143
- // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire fields need runtime finite number checks
133
+ // webpieces-disable no-function-outside-class -- wire number bound; webpieces-disable no-any-unknown -- wire values require validation
144
134
  static wait(value) {
145
135
  return typeof value === 'number' && Number.isFinite(value) && value >= 0
146
136
  ? Math.min(value, 86400)
147
137
  : undefined;
148
138
  }
149
- // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire discriminator must be allowlisted before selection
139
+ // webpieces-disable no-function-outside-class -- allowlisted generic messages; webpieces-disable no-any-unknown -- discriminator is validated by switch
150
140
  static message(kind) {
151
141
  switch (kind) {
152
- case 'user':
153
- return 'User Error';
142
+ case 'end-user':
143
+ return 'End User Error';
154
144
  case 'bad-request':
155
145
  return 'Bad Request';
156
146
  case 'unauthorized':
@@ -163,22 +153,38 @@ class ApiErrorCodec {
163
153
  return 'Endpoint Not Found';
164
154
  case 'request-timeout':
165
155
  return 'Request Timeout';
166
- case 'too-many-requests':
167
- return 'Too Many Requests';
168
- case 'bad-gateway':
169
- return 'Bad Gateway';
170
- case 'service-unavailable':
156
+ case 'rate-limited':
157
+ return 'Rate Limited';
158
+ case 'dependency':
159
+ return 'Dependency Error';
160
+ case 'unavailable':
171
161
  return 'Service Unavailable';
172
- case 'gateway-timeout':
173
- return 'Gateway Timeout';
174
- case 'vendor':
175
- return 'Vendor Error';
176
- case 'offline':
177
- return 'Offline';
162
+ case 'dependency-timeout':
163
+ return 'Dependency Timeout';
164
+ case 'dependency-backoff':
165
+ return 'Dependency Unavailable';
166
+ case 'connection':
167
+ return 'Connection Error';
178
168
  default:
179
169
  return 'Internal Error';
180
170
  }
181
171
  }
172
+ static kinds = new Set([
173
+ 'end-user',
174
+ 'bad-request',
175
+ 'unauthorized',
176
+ 'forbidden',
177
+ 'not-found',
178
+ 'endpoint-not-found',
179
+ 'request-timeout',
180
+ 'rate-limited',
181
+ 'implementation',
182
+ 'dependency',
183
+ 'unavailable',
184
+ 'dependency-timeout',
185
+ 'dependency-backoff',
186
+ 'connection',
187
+ ]);
182
188
  }
183
189
  exports.ApiErrorCodec = ApiErrorCodec;
184
190
  //# sourceMappingURL=ApiErrorCodec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApiErrorCodec.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/errors/ApiErrorCodec.ts"],"names":[],"mappings":";;;AAAA,yCAgBoB;AAEpB,6IAA6I;AAC7I,MAAa,eAAe;IAQb;IACA;IARJ,KAAK,CAAmB;IACxB,OAAO,CAAU;IACjB,KAAK,CAAU;IACf,eAAe,CAAU;IACzB,SAAS,CAAU;IACnB,WAAW,CAAU;IAC5B,YACW,IAAY,EACZ,OAAe;QADf,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;IACvB,CAAC;CACP;AAXD,0CAWC;AAED,sGAAsG;AACtG,MAAa,aAAa;IACtB,kMAAkM;IAClM,MAAM,CAAC,MAAM,CAAC,KAAc;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,2JAA2J;IACnJ,MAAM,CAAC,WAAW,CAAC,KAAc,EAAE,KAAa;QACpD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,eAAe,CAC/B,IAAI,EACJ,KAAK,YAAY,oBAAS,CA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IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC;YACxB,CAAC,CAAC,SAAS,CAAC;IACpB,CAAC;IACD,wKAAwK;IAChK,MAAM,CAAC,OAAO,CAAC,IAAa;QAChC,QAAQ,IAAI,EAAE,CAAC;YACX,KAAK,MAAM;gBACP,OAAO,YAAY,CAAC;YACxB,KAAK,aAAa;gBACd,OAAO,aAAa,CAAC;YACzB,KAAK,cAAc;gBACf,OAAO,cAAc,CAAC;YAC1B,KAAK,WAAW;gBACZ,OAAO,WAAW,CAAC;YACvB,KAAK,WAAW;gBACZ,OAAO,WAAW,CAAC;YACvB,KAAK,oBAAoB;gBACrB,OAAO,oBAAoB,CAAC;YAChC,KAAK,iBAAiB;gBAClB,OAAO,iBAAiB,CAAC;YAC7B,KAAK,mBAAmB;gBACpB,OAAO,mBAAmB,CAAC;YAC/B,KAAK,aAAa;gBACd,OAAO,aAAa,CAAC;YACzB,KAAK,qBAAqB;gBACtB,OAAO,qBAAqB,CAAC;YACjC,KAAK,iBAAiB;gBAClB,OAAO,iBAAiB,CAAC;YAC7B,KAAK,QAAQ;gBACT,OAAO,cAAc,CAAC;YAC1B,KAAK,SAAS;gBACV,OAAO,SAAS,CAAC;YACrB;gBACI,OAAO,gBAAgB,CAAC;QAChC,CAAC;IACL,CAAC;CACJ;AA1JD,sCA0JC","sourcesContent":["import {\n ApiError,\n BadRequestError,\n UserError,\n UnauthorizedError,\n ForbiddenError,\n NotFoundError,\n EndpointNotFoundError,\n RequestTimeoutError,\n TooManyRequestsError,\n InternalError,\n BadGatewayError,\n ServiceUnavailableError,\n GatewayTimeoutError,\n VendorError,\n OfflineError,\n} from './ApiError';\n\n/** Allowlisted error envelope shared by non-HTTP transports. Contains only bounded semantic causes, never stacks or arbitrary properties. */\nexport class ApiErrorPayload {\n public cause?: ApiErrorPayload;\n public subType?: string;\n public field?: string;\n public guiAlertMessage?: string;\n public errorCode?: string;\n public waitSeconds?: number;\n constructor(\n public kind: string,\n public message: string,\n ) {}\n}\n\n/** Bounded, safe, transport-neutral encoding. Unrecognized types become generic internal failures. */\nexport class ApiErrorCodec {\n // webpieces-disable no-function-outside-class -- stateless public codec shared by transport adapters; webpieces-disable no-any-unknown -- thrown values are untrusted until narrowed by the codec\n static encode(error: unknown): ApiErrorPayload {\n return this.encodeDepth(error, 0);\n }\n\n // webpieces-disable no-function-outside-class -- recursive bounded wire codec; webpieces-disable no-any-unknown -- thrown causes require runtime narrowing\n private static encodeDepth(error: unknown, depth: number): ApiErrorPayload {\n const kind = this.kind(error);\n const payload = new ApiErrorPayload(\n kind,\n error instanceof UserError ? error.message.slice(0, 4096) : this.message(kind),\n );\n if (error instanceof ApiError) payload.subType = this.text(error.subType);\n if (error instanceof UserError) payload.errorCode = this.text(error.errorCode);\n if (error instanceof BadRequestError) {\n payload.field = this.text(error.field);\n payload.guiAlertMessage = this.text(error.guiMessage);\n }\n if (error instanceof VendorError) payload.waitSeconds = this.wait(error.waitSeconds);\n if (error instanceof Error && depth < 3) {\n const cause = Object.getOwnPropertyDescriptor(error, 'cause')?.value;\n if (cause instanceof Error) payload.cause = this.encodeDepth(cause, depth + 1);\n }\n return payload;\n }\n\n // webpieces-disable no-function-outside-class -- stateless public codec shared by transport adapters; webpieces-disable no-any-unknown -- JSON transport input must be validated before use\n static decode(value: unknown): ApiError {\n return this.decodeDepth(value, 0);\n }\n\n // webpieces-disable no-function-outside-class -- recursive bounded wire codec; webpieces-disable no-any-unknown -- remote causes remain untrusted until validated\n private static decodeDepth(value: unknown, depth: number): ApiError {\n const error = this.decodeOne(value);\n if (typeof value === 'object' && value !== null && depth < 3) {\n const cause = Object.getOwnPropertyDescriptor(value, 'cause')?.value;\n if (typeof cause === 'object' && cause !== null) {\n // webpieces-disable no-anonymous-object-literals -- standard property descriptor keeps Error.cause non-enumerable\n Object.defineProperty(error, 'cause', {\n value: this.decodeDepth(cause, depth + 1),\n configurable: true,\n writable: true,\n });\n }\n }\n return error;\n }\n\n // webpieces-disable no-function-outside-class -- allowlisted wire codec; webpieces-disable no-any-unknown -- JSON transport input must be validated before use\n private static decodeOne(value: unknown): ApiError {\n if (typeof value !== 'object' || value === null) return new InternalError('Internal Error');\n // webpieces-disable no-any-unknown -- own wire fields remain untrusted until narrowed\n const field = (key: string): unknown => Object.getOwnPropertyDescriptor(value, key)?.value;\n const kind = field('kind');\n const message = this.text(field('message')) ?? this.message(kind);\n switch (kind) {\n case 'user':\n return new UserError(message, this.text(field('errorCode')));\n case 'bad-request':\n return new BadRequestError(\n message,\n this.text(field('field')),\n this.text(field('guiAlertMessage')),\n );\n case 'unauthorized':\n return new UnauthorizedError(message, this.text(field('subType')));\n case 'forbidden':\n return new ForbiddenError(message);\n case 'not-found':\n return new NotFoundError(message);\n case 'endpoint-not-found':\n return new EndpointNotFoundError(message);\n case 'request-timeout':\n return new RequestTimeoutError(message);\n case 'too-many-requests':\n return new TooManyRequestsError(message);\n case 'bad-gateway':\n return new BadGatewayError(message);\n case 'service-unavailable':\n return new ServiceUnavailableError(message);\n case 'gateway-timeout':\n return new GatewayTimeoutError(message);\n case 'vendor':\n return new VendorError(message, this.wait(field('waitSeconds')));\n case 'offline':\n return new OfflineError(message);\n case 'internal':\n return new InternalError(message);\n default:\n return new InternalError('Internal Error');\n }\n }\n\n // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- thrown values need instanceof narrowing before encoding\n private static kind(error: unknown): string {\n if (error instanceof UserError) return 'user';\n if (error instanceof BadRequestError) return 'bad-request';\n if (error instanceof UnauthorizedError) return 'unauthorized';\n if (error instanceof ForbiddenError) return 'forbidden';\n if (error instanceof EndpointNotFoundError) return 'endpoint-not-found';\n if (error instanceof NotFoundError) return 'not-found';\n if (error instanceof RequestTimeoutError) return 'request-timeout';\n if (error instanceof TooManyRequestsError) return 'too-many-requests';\n if (error instanceof BadGatewayError) return 'bad-gateway';\n if (error instanceof ServiceUnavailableError) return 'service-unavailable';\n if (error instanceof GatewayTimeoutError) return 'gateway-timeout';\n if (error instanceof VendorError) return 'vendor';\n if (error instanceof OfflineError) return 'offline';\n return 'internal';\n }\n // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire fields need runtime string checks\n private static text(value: unknown): string | undefined {\n return typeof value === 'string' ? value.slice(0, 4096) : undefined;\n }\n // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire fields need runtime finite number checks\n private static wait(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n ? Math.min(value, 86400)\n : undefined;\n }\n // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire discriminator must be allowlisted before selection\n private static message(kind: unknown): string {\n switch (kind) {\n case 'user':\n return 'User Error';\n case 'bad-request':\n return 'Bad Request';\n case 'unauthorized':\n return 'Unauthorized';\n case 'forbidden':\n return 'Forbidden';\n case 'not-found':\n return 'Not Found';\n case 'endpoint-not-found':\n return 'Endpoint Not Found';\n case 'request-timeout':\n return 'Request Timeout';\n case 'too-many-requests':\n return 'Too Many Requests';\n case 'bad-gateway':\n return 'Bad Gateway';\n case 'service-unavailable':\n return 'Service Unavailable';\n case 'gateway-timeout':\n return 'Gateway Timeout';\n case 'vendor':\n return 'Vendor Error';\n case 'offline':\n return 'Offline';\n default:\n return 'Internal Error';\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ApiErrorCodec.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/errors/ApiErrorCodec.ts"],"names":[],"mappings":";;;AAAA,yCAiBoB;AAEpB,gGAAgG;AAChG,MAAa,eAAe;IASb;IACA;IATJ,KAAK,CAAmB;IACxB,OAAO,CAAU;IACjB,KAAK,CAAU;IACf,aAAa,CAAU;IACvB,SAAS,CAAU;IACnB,iBAAiB,CAAU;IAElC,YACW,OAAe,gBAAgB,EAC/B,UAAkB,gBAAgB;QADlC,SAAI,GAAJ,IAAI,CAA2B;QAC/B,YAAO,GAAP,OAAO,CAA2B;IAC1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BAAoB;QACpB,iBAAiB;QACjB,cAAc;QACd,gBAAgB;QAChB,YAAY;QACZ,aAAa;QACb,oBAAoB;QACpB,oBAAoB;QACpB,YAAY;KACf,CAAC,CAAC;;AAjLP,sCAkLC","sourcesContent":["import {\n ApiBadRequestError,\n ApiConnectionError,\n ApiDependencyBackoffError,\n ApiDependencyError,\n ApiDependencyTimeoutError,\n ApiEndpointNotFoundError,\n ApiEndUserError,\n ApiError,\n ApiErrorKind,\n ApiForbiddenError,\n ApiImplementationError,\n ApiNotFoundError,\n ApiRateLimitedError,\n ApiRequestTimeoutError,\n ApiUnauthorizedError,\n ApiUnavailableError,\n} from './ApiError';\n\n/** Allowlisted transport-neutral envelope. It never contains stacks or arbitrary properties. */\nexport class ApiErrorPayload {\n public cause?: ApiErrorPayload;\n public subType?: string;\n public field?: string;\n public callerMessage?: string;\n public errorCode?: string;\n public retryAfterSeconds?: number;\n\n constructor(\n public kind: string = 'implementation',\n public message: string = 'Internal Error',\n ) {}\n}\n\n/** Bounded safe codec shared by HTTP, IPC, and other remote adapters. */\nexport class ApiErrorCodec {\n // webpieces-disable no-function-outside-class -- stateless public transport codec; webpieces-disable no-any-unknown -- thrown values are untrusted until narrowed\n static encode(error: unknown): ApiErrorPayload {\n return this.encodeDepth(error, 0);\n }\n\n // webpieces-disable no-function-outside-class -- recursive bounded transport codec; webpieces-disable no-any-unknown -- thrown causes require narrowing\n private static encodeDepth(error: unknown, depth: number): ApiErrorPayload {\n const kind = error instanceof ApiError ? error.kind : 'implementation';\n const payload = new ApiErrorPayload(kind, this.publicMessage(error, kind));\n if (error instanceof ApiError) payload.subType = this.text(error.subType);\n if (error instanceof ApiEndUserError) payload.errorCode = this.text(error.errorCode);\n if (error instanceof ApiBadRequestError) {\n payload.field = this.text(error.field);\n payload.callerMessage = this.text(error.callerMessage);\n }\n if (error instanceof ApiDependencyBackoffError) {\n payload.retryAfterSeconds = this.wait(error.retryAfterSeconds);\n }\n if (error instanceof Error && depth < 3) {\n const cause = Object.getOwnPropertyDescriptor(error, 'cause')?.value;\n if (cause instanceof Error) payload.cause = this.encodeDepth(cause, depth + 1);\n }\n return payload;\n }\n\n /** Decode a value received from another process. Implementation failures are marked remote. */\n // webpieces-disable no-function-outside-class -- stateless public transport codec; webpieces-disable no-any-unknown -- wire values require validation\n static decode(value: unknown): ApiError {\n return this.decodeDepth(value, 0);\n }\n\n /** Whether a body carries a recognized Webpieces semantic discriminator. */\n // webpieces-disable no-function-outside-class -- stateless wire discriminator check; webpieces-disable no-any-unknown -- wire values require validation\n static isPayload(value: unknown): boolean {\n if (typeof value !== 'object' || value === null) return false;\n const kind = Object.getOwnPropertyDescriptor(value, 'kind')?.value;\n return typeof kind === 'string' && this.kinds.has(kind as ApiErrorKind);\n }\n\n // webpieces-disable no-function-outside-class -- recursive bounded transport codec; webpieces-disable no-any-unknown -- remote causes require validation\n private static decodeDepth(value: unknown, depth: number): ApiError {\n const error = this.decodeOne(value);\n if (typeof value === 'object' && value !== null && depth < 3) {\n const cause = Object.getOwnPropertyDescriptor(value, 'cause')?.value;\n if (typeof cause === 'object' && cause !== null) {\n // webpieces-disable no-anonymous-object-literals -- standard descriptor preserves Error.cause semantics\n Object.defineProperty(error, 'cause', {\n value: this.decodeDepth(cause, depth + 1),\n configurable: true,\n writable: true,\n });\n }\n }\n return error;\n }\n\n // webpieces-disable no-function-outside-class -- allowlisted wire codec; webpieces-disable no-any-unknown -- wire fields require validation\n private static decodeOne(value: unknown): ApiError {\n if (typeof value !== 'object' || value === null) return this.remoteImplementationError();\n // webpieces-disable no-any-unknown -- own wire fields remain untrusted until narrowed\n const field = (key: string): unknown => Object.getOwnPropertyDescriptor(value, key)?.value;\n const kind = field('kind');\n const message = this.text(field('message')) ?? this.message(kind);\n switch (kind) {\n case 'end-user':\n return new ApiEndUserError(message, this.text(field('errorCode')));\n case 'bad-request':\n return new ApiBadRequestError(\n message,\n this.text(field('field')),\n this.text(field('callerMessage')),\n );\n case 'unauthorized':\n return new ApiUnauthorizedError(message, this.text(field('subType')));\n case 'forbidden':\n return new ApiForbiddenError(message);\n case 'not-found':\n return new ApiNotFoundError(message);\n case 'endpoint-not-found':\n return new ApiEndpointNotFoundError(message);\n case 'request-timeout':\n return new ApiRequestTimeoutError(message);\n case 'rate-limited':\n return new ApiRateLimitedError(message);\n case 'dependency':\n return new ApiDependencyError(message);\n case 'unavailable':\n return new ApiUnavailableError(message);\n case 'dependency-timeout':\n return new ApiDependencyTimeoutError(message);\n case 'dependency-backoff':\n return new ApiDependencyBackoffError(\n message,\n this.wait(field('retryAfterSeconds')),\n );\n case 'connection':\n return new ApiConnectionError(message);\n case 'implementation':\n return new ApiImplementationError(message, undefined, true);\n default:\n return this.remoteImplementationError();\n }\n }\n\n // webpieces-disable no-function-outside-class -- concrete normalization for malformed remote errors\n private static remoteImplementationError(): ApiImplementationError {\n return new ApiImplementationError('Internal Error', undefined, true);\n }\n\n // webpieces-disable no-function-outside-class -- caller-safe message selection; webpieces-disable no-any-unknown -- thrown values require narrowing\n private static publicMessage(error: unknown, kind: ApiErrorKind): string {\n if (error instanceof ApiEndUserError) return error.message.slice(0, 4096);\n return this.message(kind);\n }\n\n // webpieces-disable no-function-outside-class -- wire string bound; webpieces-disable no-any-unknown -- wire values require validation\n private static text(value: unknown): string | undefined {\n return typeof value === 'string' ? value.slice(0, 4096) : undefined;\n }\n\n // webpieces-disable no-function-outside-class -- wire number bound; webpieces-disable no-any-unknown -- wire values require validation\n private static wait(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n ? Math.min(value, 86400)\n : undefined;\n }\n\n // webpieces-disable no-function-outside-class -- allowlisted generic messages; webpieces-disable no-any-unknown -- discriminator is validated by switch\n private static message(kind: unknown): string {\n switch (kind) {\n case 'end-user':\n return 'End User Error';\n case 'bad-request':\n return 'Bad Request';\n case 'unauthorized':\n return 'Unauthorized';\n case 'forbidden':\n return 'Forbidden';\n case 'not-found':\n return 'Not Found';\n case 'endpoint-not-found':\n return 'Endpoint Not Found';\n case 'request-timeout':\n return 'Request Timeout';\n case 'rate-limited':\n return 'Rate Limited';\n case 'dependency':\n return 'Dependency Error';\n case 'unavailable':\n return 'Service Unavailable';\n case 'dependency-timeout':\n return 'Dependency Timeout';\n case 'dependency-backoff':\n return 'Dependency Unavailable';\n case 'connection':\n return 'Connection Error';\n default:\n return 'Internal Error';\n }\n }\n\n private static readonly kinds: ReadonlySet<ApiErrorKind> = new Set<ApiErrorKind>([\n 'end-user',\n 'bad-request',\n 'unauthorized',\n 'forbidden',\n 'not-found',\n 'endpoint-not-found',\n 'request-timeout',\n 'rate-limited',\n 'implementation',\n 'dependency',\n 'unavailable',\n 'dependency-timeout',\n 'dependency-backoff',\n 'connection',\n ]);\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /** Stable application contract values carried by ApiUnauthorizedError.subType. */
2
+ export declare const ENTITY_NOT_FOUND = "EntityNotFoundError";
3
+ export declare const WRONG_LOGIN_TYPE = "wrongLoginType";
4
+ export declare const WRONG_LOGIN = "wronglogin";
5
+ export declare const NOT_APPROVED = "notapproved";
6
+ export declare const EMAIL_NOT_CONFIRMED = "email_not_confirmed";
7
+ export declare const WRONG_DOMAIN = "wrongdomain";
8
+ export declare const WRONG_COMPANY = "wrongcompany";
9
+ export declare const NO_REG_CODE = "noregcode";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NO_REG_CODE = exports.WRONG_COMPANY = exports.WRONG_DOMAIN = exports.EMAIL_NOT_CONFIRMED = exports.NOT_APPROVED = exports.WRONG_LOGIN = exports.WRONG_LOGIN_TYPE = exports.ENTITY_NOT_FOUND = void 0;
4
+ /** Stable application contract values carried by ApiUnauthorizedError.subType. */
5
+ exports.ENTITY_NOT_FOUND = 'EntityNotFoundError';
6
+ exports.WRONG_LOGIN_TYPE = 'wrongLoginType';
7
+ exports.WRONG_LOGIN = 'wronglogin';
8
+ exports.NOT_APPROVED = 'notapproved';
9
+ exports.EMAIL_NOT_CONFIRMED = 'email_not_confirmed';
10
+ exports.WRONG_DOMAIN = 'wrongdomain';
11
+ exports.WRONG_COMPANY = 'wrongcompany';
12
+ exports.NO_REG_CODE = 'noregcode';
13
+ //# sourceMappingURL=AuthErrorSubtypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthErrorSubtypes.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/errors/AuthErrorSubtypes.ts"],"names":[],"mappings":";;;AAAA,kFAAkF;AACrE,QAAA,gBAAgB,GAAG,qBAAqB,CAAC;AACzC,QAAA,gBAAgB,GAAG,gBAAgB,CAAC;AACpC,QAAA,WAAW,GAAG,YAAY,CAAC;AAC3B,QAAA,YAAY,GAAG,aAAa,CAAC;AAC7B,QAAA,mBAAmB,GAAG,qBAAqB,CAAC;AAC5C,QAAA,YAAY,GAAG,aAAa,CAAC;AAC7B,QAAA,aAAa,GAAG,cAAc,CAAC;AAC/B,QAAA,WAAW,GAAG,WAAW,CAAC","sourcesContent":["/** Stable application contract values carried by ApiUnauthorizedError.subType. */\nexport const ENTITY_NOT_FOUND = 'EntityNotFoundError';\nexport const WRONG_LOGIN_TYPE = 'wrongLoginType';\nexport const WRONG_LOGIN = 'wronglogin';\nexport const NOT_APPROVED = 'notapproved';\nexport const EMAIL_NOT_CONFIRMED = 'email_not_confirmed';\nexport const WRONG_DOMAIN = 'wrongdomain';\nexport const WRONG_COMPANY = 'wrongcompany';\nexport const NO_REG_CODE = 'noregcode';\n"]}
@@ -1,2 +1,4 @@
1
- export { ApiError, NotFoundError, BadGatewayError, ServiceUnavailableError, GatewayTimeoutError, InternalError, TooManyRequestsError, ForbiddenError, RequestTimeoutError, OfflineError, EndpointNotFoundError, UserError, BadRequestError, UnauthorizedError, VendorError, } from './ApiError';
1
+ export { ApiError, ApiNotFoundError, ApiDependencyError, ApiUnavailableError, ApiDependencyTimeoutError, ApiImplementationError, ApiRateLimitedError, ApiForbiddenError, ApiRequestTimeoutError, ApiConnectionError, ApiEndpointNotFoundError, ApiEndUserError, ApiBadRequestError, ApiUnauthorizedError, ApiDependencyBackoffError, } from './ApiError';
2
+ export type { ApiErrorKind } from './ApiError';
2
3
  export { ApiErrorCodec, ApiErrorPayload } from './ApiErrorCodec';
4
+ export { ENTITY_NOT_FOUND, WRONG_LOGIN_TYPE, WRONG_LOGIN, NOT_APPROVED, EMAIL_NOT_CONFIRMED, WRONG_DOMAIN, WRONG_COMPANY, NO_REG_CODE, } from './AuthErrorSubtypes';
@@ -1,23 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiErrorPayload = exports.ApiErrorCodec = exports.VendorError = exports.UnauthorizedError = exports.BadRequestError = exports.UserError = exports.EndpointNotFoundError = exports.OfflineError = exports.RequestTimeoutError = exports.ForbiddenError = exports.TooManyRequestsError = exports.InternalError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotFoundError = exports.ApiError = void 0;
3
+ exports.NO_REG_CODE = exports.WRONG_COMPANY = exports.WRONG_DOMAIN = exports.EMAIL_NOT_CONFIRMED = exports.NOT_APPROVED = exports.WRONG_LOGIN = exports.WRONG_LOGIN_TYPE = exports.ENTITY_NOT_FOUND = exports.ApiErrorPayload = exports.ApiErrorCodec = exports.ApiDependencyBackoffError = exports.ApiUnauthorizedError = exports.ApiBadRequestError = exports.ApiEndUserError = exports.ApiEndpointNotFoundError = exports.ApiConnectionError = exports.ApiRequestTimeoutError = exports.ApiForbiddenError = exports.ApiRateLimitedError = exports.ApiImplementationError = exports.ApiDependencyTimeoutError = exports.ApiUnavailableError = exports.ApiDependencyError = exports.ApiNotFoundError = exports.ApiError = void 0;
4
4
  var ApiError_1 = require("./ApiError");
5
5
  Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return ApiError_1.ApiError; } });
6
- Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return ApiError_1.NotFoundError; } });
7
- Object.defineProperty(exports, "BadGatewayError", { enumerable: true, get: function () { return ApiError_1.BadGatewayError; } });
8
- Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return ApiError_1.ServiceUnavailableError; } });
9
- Object.defineProperty(exports, "GatewayTimeoutError", { enumerable: true, get: function () { return ApiError_1.GatewayTimeoutError; } });
10
- Object.defineProperty(exports, "InternalError", { enumerable: true, get: function () { return ApiError_1.InternalError; } });
11
- Object.defineProperty(exports, "TooManyRequestsError", { enumerable: true, get: function () { return ApiError_1.TooManyRequestsError; } });
12
- Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return ApiError_1.ForbiddenError; } });
13
- Object.defineProperty(exports, "RequestTimeoutError", { enumerable: true, get: function () { return ApiError_1.RequestTimeoutError; } });
14
- Object.defineProperty(exports, "OfflineError", { enumerable: true, get: function () { return ApiError_1.OfflineError; } });
15
- Object.defineProperty(exports, "EndpointNotFoundError", { enumerable: true, get: function () { return ApiError_1.EndpointNotFoundError; } });
16
- Object.defineProperty(exports, "UserError", { enumerable: true, get: function () { return ApiError_1.UserError; } });
17
- Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return ApiError_1.BadRequestError; } });
18
- Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return ApiError_1.UnauthorizedError; } });
19
- Object.defineProperty(exports, "VendorError", { enumerable: true, get: function () { return ApiError_1.VendorError; } });
6
+ Object.defineProperty(exports, "ApiNotFoundError", { enumerable: true, get: function () { return ApiError_1.ApiNotFoundError; } });
7
+ Object.defineProperty(exports, "ApiDependencyError", { enumerable: true, get: function () { return ApiError_1.ApiDependencyError; } });
8
+ Object.defineProperty(exports, "ApiUnavailableError", { enumerable: true, get: function () { return ApiError_1.ApiUnavailableError; } });
9
+ Object.defineProperty(exports, "ApiDependencyTimeoutError", { enumerable: true, get: function () { return ApiError_1.ApiDependencyTimeoutError; } });
10
+ Object.defineProperty(exports, "ApiImplementationError", { enumerable: true, get: function () { return ApiError_1.ApiImplementationError; } });
11
+ Object.defineProperty(exports, "ApiRateLimitedError", { enumerable: true, get: function () { return ApiError_1.ApiRateLimitedError; } });
12
+ Object.defineProperty(exports, "ApiForbiddenError", { enumerable: true, get: function () { return ApiError_1.ApiForbiddenError; } });
13
+ Object.defineProperty(exports, "ApiRequestTimeoutError", { enumerable: true, get: function () { return ApiError_1.ApiRequestTimeoutError; } });
14
+ Object.defineProperty(exports, "ApiConnectionError", { enumerable: true, get: function () { return ApiError_1.ApiConnectionError; } });
15
+ Object.defineProperty(exports, "ApiEndpointNotFoundError", { enumerable: true, get: function () { return ApiError_1.ApiEndpointNotFoundError; } });
16
+ Object.defineProperty(exports, "ApiEndUserError", { enumerable: true, get: function () { return ApiError_1.ApiEndUserError; } });
17
+ Object.defineProperty(exports, "ApiBadRequestError", { enumerable: true, get: function () { return ApiError_1.ApiBadRequestError; } });
18
+ Object.defineProperty(exports, "ApiUnauthorizedError", { enumerable: true, get: function () { return ApiError_1.ApiUnauthorizedError; } });
19
+ Object.defineProperty(exports, "ApiDependencyBackoffError", { enumerable: true, get: function () { return ApiError_1.ApiDependencyBackoffError; } });
20
20
  var ApiErrorCodec_1 = require("./ApiErrorCodec");
21
21
  Object.defineProperty(exports, "ApiErrorCodec", { enumerable: true, get: function () { return ApiErrorCodec_1.ApiErrorCodec; } });
22
22
  Object.defineProperty(exports, "ApiErrorPayload", { enumerable: true, get: function () { return ApiErrorCodec_1.ApiErrorPayload; } });
23
+ var AuthErrorSubtypes_1 = require("./AuthErrorSubtypes");
24
+ Object.defineProperty(exports, "ENTITY_NOT_FOUND", { enumerable: true, get: function () { return AuthErrorSubtypes_1.ENTITY_NOT_FOUND; } });
25
+ Object.defineProperty(exports, "WRONG_LOGIN_TYPE", { enumerable: true, get: function () { return AuthErrorSubtypes_1.WRONG_LOGIN_TYPE; } });
26
+ Object.defineProperty(exports, "WRONG_LOGIN", { enumerable: true, get: function () { return AuthErrorSubtypes_1.WRONG_LOGIN; } });
27
+ Object.defineProperty(exports, "NOT_APPROVED", { enumerable: true, get: function () { return AuthErrorSubtypes_1.NOT_APPROVED; } });
28
+ Object.defineProperty(exports, "EMAIL_NOT_CONFIRMED", { enumerable: true, get: function () { return AuthErrorSubtypes_1.EMAIL_NOT_CONFIRMED; } });
29
+ Object.defineProperty(exports, "WRONG_DOMAIN", { enumerable: true, get: function () { return AuthErrorSubtypes_1.WRONG_DOMAIN; } });
30
+ Object.defineProperty(exports, "WRONG_COMPANY", { enumerable: true, get: function () { return AuthErrorSubtypes_1.WRONG_COMPANY; } });
31
+ Object.defineProperty(exports, "NO_REG_CODE", { enumerable: true, get: function () { return AuthErrorSubtypes_1.NO_REG_CODE; } });
23
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/errors/index.ts"],"names":[],"mappings":";;;AAAA,uCAgBoB;AAfhB,oGAAA,QAAQ,OAAA;AACR,yGAAA,aAAa,OAAA;AACb,2GAAA,eAAe,OAAA;AACf,mHAAA,uBAAuB,OAAA;AACvB,+GAAA,mBAAmB,OAAA;AACnB,yGAAA,aAAa,OAAA;AACb,gHAAA,oBAAoB,OAAA;AACpB,0GAAA,cAAc,OAAA;AACd,+GAAA,mBAAmB,OAAA;AACnB,wGAAA,YAAY,OAAA;AACZ,iHAAA,qBAAqB,OAAA;AACrB,qGAAA,SAAS,OAAA;AACT,2GAAA,eAAe,OAAA;AACf,6GAAA,iBAAiB,OAAA;AACjB,uGAAA,WAAW,OAAA;AAEf,iDAAiE;AAAxD,8GAAA,aAAa,OAAA;AAAE,gHAAA,eAAe,OAAA","sourcesContent":["export {\n ApiError,\n NotFoundError,\n BadGatewayError,\n ServiceUnavailableError,\n GatewayTimeoutError,\n InternalError,\n TooManyRequestsError,\n ForbiddenError,\n RequestTimeoutError,\n OfflineError,\n EndpointNotFoundError,\n UserError,\n BadRequestError,\n UnauthorizedError,\n VendorError,\n} from './ApiError';\nexport { ApiErrorCodec, ApiErrorPayload } from './ApiErrorCodec';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/errors/index.ts"],"names":[],"mappings":";;;AAAA,uCAgBoB;AAfhB,oGAAA,QAAQ,OAAA;AACR,4GAAA,gBAAgB,OAAA;AAChB,8GAAA,kBAAkB,OAAA;AAClB,+GAAA,mBAAmB,OAAA;AACnB,qHAAA,yBAAyB,OAAA;AACzB,kHAAA,sBAAsB,OAAA;AACtB,+GAAA,mBAAmB,OAAA;AACnB,6GAAA,iBAAiB,OAAA;AACjB,kHAAA,sBAAsB,OAAA;AACtB,8GAAA,kBAAkB,OAAA;AAClB,oHAAA,wBAAwB,OAAA;AACxB,2GAAA,eAAe,OAAA;AACf,8GAAA,kBAAkB,OAAA;AAClB,gHAAA,oBAAoB,OAAA;AACpB,qHAAA,yBAAyB,OAAA;AAG7B,iDAAiE;AAAxD,8GAAA,aAAa,OAAA;AAAE,gHAAA,eAAe,OAAA;AACvC,yDAS6B;AARzB,qHAAA,gBAAgB,OAAA;AAChB,qHAAA,gBAAgB,OAAA;AAChB,gHAAA,WAAW,OAAA;AACX,iHAAA,YAAY,OAAA;AACZ,wHAAA,mBAAmB,OAAA;AACnB,iHAAA,YAAY,OAAA;AACZ,kHAAA,aAAa,OAAA;AACb,gHAAA,WAAW,OAAA","sourcesContent":["export {\n ApiError,\n ApiNotFoundError,\n ApiDependencyError,\n ApiUnavailableError,\n ApiDependencyTimeoutError,\n ApiImplementationError,\n ApiRateLimitedError,\n ApiForbiddenError,\n ApiRequestTimeoutError,\n ApiConnectionError,\n ApiEndpointNotFoundError,\n ApiEndUserError,\n ApiBadRequestError,\n ApiUnauthorizedError,\n ApiDependencyBackoffError,\n} from './ApiError';\nexport type { ApiErrorKind } from './ApiError';\nexport { ApiErrorCodec, ApiErrorPayload } from './ApiErrorCodec';\nexport {\n ENTITY_NOT_FOUND,\n WRONG_LOGIN_TYPE,\n WRONG_LOGIN,\n NOT_APPROVED,\n EMAIL_NOT_CONFIRMED,\n WRONG_DOMAIN,\n WRONG_COMPANY,\n NO_REG_CODE,\n} from './AuthErrorSubtypes';\n"]}
@@ -1,6 +1,6 @@
1
1
  import { CallContext } from './CallStrategy';
2
2
  /** Stopped waiting; this does not prove the remote operation did not run. */
3
- export declare class TimeoutError extends Error {
3
+ export declare class ApiCallTimeoutError extends Error {
4
4
  readonly timeoutMs: number;
5
5
  readonly context: CallContext;
6
6
  constructor(timeoutMs: number, context: CallContext);
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeoutError = void 0;
3
+ exports.ApiCallTimeoutError = void 0;
4
4
  /** Stopped waiting; this does not prove the remote operation did not run. */
5
- class TimeoutError extends Error {
5
+ class ApiCallTimeoutError extends Error {
6
6
  timeoutMs;
7
7
  context;
8
8
  constructor(timeoutMs, context) {
9
9
  super(`${context.apiName}.${context.methodName} timed out after ${timeoutMs}ms`);
10
10
  this.timeoutMs = timeoutMs;
11
11
  this.context = context;
12
- this.name = 'TimeoutError';
12
+ this.name = 'ApiCallTimeoutError';
13
13
  }
14
14
  }
15
- exports.TimeoutError = TimeoutError;
16
- //# sourceMappingURL=TimeoutError.js.map
15
+ exports.ApiCallTimeoutError = ApiCallTimeoutError;
16
+ //# sourceMappingURL=ApiCallTimeoutError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiCallTimeoutError.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/ApiCallTimeoutError.ts"],"names":[],"mappings":";;;AAEA,6EAA6E;AAC7E,MAAa,mBAAoB,SAAQ,KAAK;IAEtB;IACA;IAFpB,YACoB,SAAiB,EACjB,OAAoB;QAEpC,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,oBAAoB,SAAS,IAAI,CAAC,CAAC;QAHjE,cAAS,GAAT,SAAS,CAAQ;QACjB,YAAO,GAAP,OAAO,CAAa;QAGpC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ;AARD,kDAQC","sourcesContent":["import { CallContext } from './CallStrategy';\n\n/** Stopped waiting; this does not prove the remote operation did not run. */\nexport class ApiCallTimeoutError extends Error {\n constructor(\n public readonly timeoutMs: number,\n public readonly context: CallContext,\n ) {\n super(`${context.apiName}.${context.methodName} timed out after ${timeoutMs}ms`);\n this.name = 'ApiCallTimeoutError';\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { ApiError } from '../errors/ApiError';
2
2
  /** HTTP-only adapter: semantic errors themselves have no protocol status property. */
3
- export declare class HttpErrorStatus {
3
+ export declare class ApiErrorHttpStatus {
4
+ static hasCode(error: ApiError): boolean;
4
5
  static code(error: ApiError): number;
5
6
  }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiErrorHttpStatus = void 0;
4
+ /** HTTP-only adapter: semantic errors themselves have no protocol status property. */
5
+ class ApiErrorHttpStatus {
6
+ // webpieces-disable no-function-outside-class -- stateless mapping predicate
7
+ static hasCode(error) {
8
+ return error.kind !== 'connection';
9
+ }
10
+ // webpieces-disable no-function-outside-class -- stateless mapping shared by HTTP adapters
11
+ static code(error) {
12
+ switch (error.kind) {
13
+ case 'end-user':
14
+ return 266;
15
+ case 'bad-request':
16
+ return 400;
17
+ case 'unauthorized':
18
+ return 401;
19
+ case 'forbidden':
20
+ return 403;
21
+ case 'not-found':
22
+ case 'endpoint-not-found':
23
+ return 404;
24
+ case 'request-timeout':
25
+ return 408;
26
+ case 'rate-limited':
27
+ return 429;
28
+ case 'implementation':
29
+ return 500;
30
+ case 'dependency':
31
+ return 502;
32
+ case 'unavailable':
33
+ case 'dependency-backoff':
34
+ return 503;
35
+ case 'dependency-timeout':
36
+ return 504;
37
+ case 'connection':
38
+ throw new Error('ApiConnectionError has no HTTP status; normalize it at the server boundary');
39
+ }
40
+ }
41
+ }
42
+ exports.ApiErrorHttpStatus = ApiErrorHttpStatus;
43
+ //# sourceMappingURL=ApiErrorHttpStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiErrorHttpStatus.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/ApiErrorHttpStatus.ts"],"names":[],"mappings":";;;AAEA,sFAAsF;AACtF,MAAa,kBAAkB;IAC3B,6EAA6E;IAC7E,MAAM,CAAC,OAAO,CAAC,KAAe;QAC1B,OAAO,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;IACvC,CAAC;IAED,2FAA2F;IAC3F,MAAM,CAAC,IAAI,CAAC,KAAe;QACvB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACjB,KAAK,UAAU;gBACX,OAAO,GAAG,CAAC;YACf,KAAK,aAAa;gBACd,OAAO,GAAG,CAAC;YACf,KAAK,cAAc;gBACf,OAAO,GAAG,CAAC;YACf,KAAK,WAAW;gBACZ,OAAO,GAAG,CAAC;YACf,KAAK,WAAW,CAAC;YACjB,KAAK,oBAAoB;gBACrB,OAAO,GAAG,CAAC;YACf,KAAK,iBAAiB;gBAClB,OAAO,GAAG,CAAC;YACf,KAAK,cAAc;gBACf,OAAO,GAAG,CAAC;YACf,KAAK,gBAAgB;gBACjB,OAAO,GAAG,CAAC;YACf,KAAK,YAAY;gBACb,OAAO,GAAG,CAAC;YACf,KAAK,aAAa,CAAC;YACnB,KAAK,oBAAoB;gBACrB,OAAO,GAAG,CAAC;YACf,KAAK,oBAAoB;gBACrB,OAAO,GAAG,CAAC;YACf,KAAK,YAAY;gBACb,MAAM,IAAI,KAAK,CACX,4EAA4E,CAC/E,CAAC;QACV,CAAC;IACL,CAAC;CACJ;AAvCD,gDAuCC","sourcesContent":["import { ApiError } from '../errors/ApiError';\n\n/** HTTP-only adapter: semantic errors themselves have no protocol status property. */\nexport class ApiErrorHttpStatus {\n // webpieces-disable no-function-outside-class -- stateless mapping predicate\n static hasCode(error: ApiError): boolean {\n return error.kind !== 'connection';\n }\n\n // webpieces-disable no-function-outside-class -- stateless mapping shared by HTTP adapters\n static code(error: ApiError): number {\n switch (error.kind) {\n case 'end-user':\n return 266;\n case 'bad-request':\n return 400;\n case 'unauthorized':\n return 401;\n case 'forbidden':\n return 403;\n case 'not-found':\n case 'endpoint-not-found':\n return 404;\n case 'request-timeout':\n return 408;\n case 'rate-limited':\n return 429;\n case 'implementation':\n return 500;\n case 'dependency':\n return 502;\n case 'unavailable':\n case 'dependency-backoff':\n return 503;\n case 'dependency-timeout':\n return 504;\n case 'connection':\n throw new Error(\n 'ApiConnectionError has no HTTP status; normalize it at the server boundary',\n );\n }\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CallDeadline = void 0;
4
- const TimeoutError_1 = require("./TimeoutError");
4
+ const ApiCallTimeoutError_1 = require("./ApiCallTimeoutError");
5
5
  /** Transport deadline. The race bounds even transports that ignore cancellation. */
6
6
  class CallDeadline {
7
7
  /**
@@ -22,7 +22,7 @@ class CallDeadline {
22
22
  let timer;
23
23
  const expired = new Promise((_resolve, reject) => {
24
24
  timer = setTimeout(() => {
25
- const error = new TimeoutError_1.TimeoutError(timeoutMs, context);
25
+ const error = new ApiCallTimeoutError_1.ApiCallTimeoutError(timeoutMs, context);
26
26
  CallDeadline.failures.set(controller.signal, error);
27
27
  reject(error);
28
28
  controller.abort(error);
@@ -1 +1 @@
1
- {"version":3,"file":"CallDeadline.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/CallDeadline.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAE9C,oFAAoF;AACpF,MAAa,YAAY;IACrB;;;OAGG;IACK,MAAM,CAAU,QAAQ,GAAG,IAAI,OAAO,EAAsB,CAAC;IAErE,4EAA4E;IAC5E,MAAM,CAAC,QAAQ,CAAC,SAAiB;QAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,S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M,CAAC;YACjC,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAClE,CAAC;IACN,CAAC;;AArDL,oCAsDC","sourcesContent":["import { CallContext } from './CallStrategy';\nimport { TimeoutError } from './TimeoutError';\n\n/** Transport deadline. The race bounds even transports that ignore cancellation. */\nexport class CallDeadline {\n /**\n * AbortController.abort(reason) is not portable: React Native's abort-controller 3 signal has\n * neither `reason` nor `throwIfAborted`. Keep the typed failure beside the signal instead.\n */\n private static readonly failures = new WeakMap<AbortSignal, Error>();\n\n // webpieces-disable no-function-outside-class -- stateless transport helper\n static validate(timeoutMs: number): void {\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2_147_483_647) {\n throw new RangeError('timeoutMs must be positive, finite, and at most 2147483647');\n }\n }\n\n // webpieces-disable no-function-outside-class -- stateless transport helper\n static async run<T>(\n timeoutMs: number,\n context: CallContext,\n work: (signal: AbortSignal) => Promise<T>,\n ): Promise<T> {\n CallDeadline.validate(timeoutMs);\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const expired = new Promise<never>(\n (_resolve: (value: never) => void, reject: (error: Error) => void) => {\n timer = setTimeout(() => {\n const error = new TimeoutError(timeoutMs, context);\n CallDeadline.failures.set(controller.signal, error);\n reject(error);\n controller.abort(error);\n }, timeoutMs);\n },\n );\n // webpieces-disable no-unmanaged-exceptions -- release the timer on every settlement\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return await Promise.race([\n expired,\n Promise.resolve().then(() => work(controller.signal)),\n ]);\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** Throw the exact deadline failure without relying on optional AbortSignal extensions. */\n // webpieces-disable no-function-outside-class -- portable transport helper\n static throwIfAborted(signal: AbortSignal): void {\n if (!signal.aborted) return;\n throw (\n CallDeadline.failures.get(signal) ??\n new Error('The operation was aborted before it could complete')\n );\n }\n}\n"]}
1
+ {"version":3,"file":"CallDeadline.js","sourceRoot":"","sources":["../../../../../../packages/core/core-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AAC,MAAM,CAAC,CAAC;aACxD,CAAC,CAAC;QACP,CAAC;gBAAS,CAAC;YACP,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;IACL,CAAC;IAED,2FAA2F;IAC3F,2EAA2E;IAC3E,MAAM,CAAC,cAAc,CAAC,MAAmB;QACrC,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO;QAC5B,MAAM,CACF,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;YACjC,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAClE,CAAC;IACN,CAAC;;AArDL,oCAsDC","sourcesContent":["import { CallContext } from './CallStrategy';\nimport { ApiCallTimeoutError } from './ApiCallTimeoutError';\n\n/** Transport deadline. The race bounds even transports that ignore cancellation. */\nexport class CallDeadline {\n /**\n * AbortController.abort(reason) is not portable: React Native's abort-controller 3 signal has\n * neither `reason` nor `throwIfAborted`. Keep the typed failure beside the signal instead.\n */\n private static readonly failures = new WeakMap<AbortSignal, Error>();\n\n // webpieces-disable no-function-outside-class -- stateless transport helper\n static validate(timeoutMs: number): void {\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2_147_483_647) {\n throw new RangeError('timeoutMs must be positive, finite, and at most 2147483647');\n }\n }\n\n // webpieces-disable no-function-outside-class -- stateless transport helper\n static async run<T>(\n timeoutMs: number,\n context: CallContext,\n work: (signal: AbortSignal) => Promise<T>,\n ): Promise<T> {\n CallDeadline.validate(timeoutMs);\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const expired = new Promise<never>(\n (_resolve: (value: never) => void, reject: (error: Error) => void) => {\n timer = setTimeout(() => {\n const error = new ApiCallTimeoutError(timeoutMs, context);\n CallDeadline.failures.set(controller.signal, error);\n reject(error);\n controller.abort(error);\n }, timeoutMs);\n },\n );\n // webpieces-disable no-unmanaged-exceptions -- release the timer on every settlement\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return await Promise.race([\n expired,\n Promise.resolve().then(() => work(controller.signal)),\n ]);\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** Throw the exact deadline failure without relying on optional AbortSignal extensions. */\n // webpieces-disable no-function-outside-class -- portable transport helper\n static throwIfAborted(signal: AbortSignal): void {\n if (!signal.aborted) return;\n throw (\n CallDeadline.failures.get(signal) ??\n new Error('The operation was aborted before it could complete')\n );\n }\n}\n"]}