@webpieces/core-util 0.4.750 → 0.4.751

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 (47) hide show
  1. package/README.md +6 -0
  2. package/package.json +9 -1
  3. package/src/errors/ApiError.d.ts +70 -0
  4. package/src/errors/ApiError.js +106 -0
  5. package/src/errors/ApiError.js.map +1 -0
  6. package/src/errors/ApiErrorCodec.d.ts +25 -0
  7. package/src/errors/ApiErrorCodec.js +184 -0
  8. package/src/errors/ApiErrorCodec.js.map +1 -0
  9. package/src/errors/index.d.ts +2 -0
  10. package/src/errors/index.js +23 -0
  11. package/src/errors/index.js.map +1 -0
  12. package/src/http/HttpErrorStatus.d.ts +5 -0
  13. package/src/http/HttpErrorStatus.js +38 -0
  14. package/src/http/HttpErrorStatus.js.map +1 -0
  15. package/src/http/LogApiCall.d.ts +1 -1
  16. package/src/http/LogApiCall.js +7 -2
  17. package/src/http/LogApiCall.js.map +1 -1
  18. package/src/http/WebpiecesDefaultFailureClassifier.d.ts +4 -4
  19. package/src/http/WebpiecesDefaultFailureClassifier.js +11 -11
  20. package/src/http/WebpiecesDefaultFailureClassifier.js.map +1 -1
  21. package/src/http/decorators.d.ts +1 -1
  22. package/src/http/decorators.js +1 -1
  23. package/src/http/decorators.js.map +1 -1
  24. package/src/http/errors.d.ts +35 -158
  25. package/src/http/errors.js +65 -235
  26. package/src/http/errors.js.map +1 -1
  27. package/src/index.d.ts +8 -6
  28. package/src/index.js +20 -2
  29. package/src/index.js.map +1 -1
  30. package/src/ipc/IpcCompileAssertions.d.ts +4 -0
  31. package/src/ipc/IpcCompileAssertions.js +39 -0
  32. package/src/ipc/IpcCompileAssertions.js.map +1 -0
  33. package/src/ipc/IpcConnection.d.ts +50 -0
  34. package/src/ipc/IpcConnection.js +187 -0
  35. package/src/ipc/IpcConnection.js.map +1 -0
  36. package/src/ipc/IpcContract.d.ts +32 -0
  37. package/src/ipc/IpcContract.js +65 -0
  38. package/src/ipc/IpcContract.js.map +1 -0
  39. package/src/ipc/IpcLogging.d.ts +11 -0
  40. package/src/ipc/IpcLogging.js +13 -0
  41. package/src/ipc/IpcLogging.js.map +1 -0
  42. package/src/ipc/IpcProtocol.d.ts +37 -0
  43. package/src/ipc/IpcProtocol.js +103 -0
  44. package/src/ipc/IpcProtocol.js.map +1 -0
  45. package/src/ipc/index.d.ts +14 -0
  46. package/src/ipc/index.js +31 -0
  47. package/src/ipc/index.js.map +1 -0
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Utility functions for WebPieces applications. Works in both browser and Node.js environments.
4
4
 
5
+ ## Portable API errors and IPC
6
+
7
+ React Native consumers use `@webpieces/core-util/errors` for canonical semantic errors (`UserError`, `NotFoundError`, and the other API categories) and `@webpieces/core-util/ipc` for shared contracts and connection types. These two subpaths are checked with public declaration fixtures, Metro Android/iOS bundles, and Hermes compilation; the broad root barrel is not certified for React Native.
8
+
9
+ Use `@webpieces/ipc-client` and `@webpieces/ipc-server` for generated clients and typed receivers. HTTP preserves status 266 for `UserError`: monitoring succeeds, while generated clients throw it for GUI display. Old Http-prefixed names are deprecated aliases; neutral errors use standard `cause` and have no HTTP `.code`. See [the migration and verification guide](https://github.com/deanhiller/webpieces-ts/blob/main/docs/portable-ipc-and-errors.md).
10
+
5
11
  ## Installation
6
12
 
7
13
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/core-util",
3
- "version": "0.4.750",
3
+ "version": "0.4.751",
4
4
  "description": "Utility functions for WebPieces - works in browser and Node.js",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -9,6 +9,14 @@
9
9
  ".": {
10
10
  "types": "./src/index.d.ts",
11
11
  "default": "./src/index.js"
12
+ },
13
+ "./errors": {
14
+ "types": "./src/errors/index.d.ts",
15
+ "default": "./src/errors/index.js"
16
+ },
17
+ "./ipc": {
18
+ "types": "./src/ipc/index.d.ts",
19
+ "default": "./src/ipc/index.js"
12
20
  }
13
21
  },
14
22
  "keywords": [
@@ -0,0 +1,70 @@
1
+ /** Portable semantic failures. HTTP status mapping belongs to the HTTP adapter. */
2
+ export declare class ApiError extends Error {
3
+ readonly kind: string;
4
+ subType?: string;
5
+ constructor(message: string, cause?: Error);
6
+ }
7
+ /** NotFound failure, independent of transport. */
8
+ export declare class NotFoundError extends ApiError {
9
+ readonly kind: string;
10
+ }
11
+ /** BadGateway failure, independent of transport. */
12
+ export declare class BadGatewayError extends ApiError {
13
+ readonly kind: string;
14
+ }
15
+ /** ServiceUnavailable failure, independent of transport. */
16
+ export declare class ServiceUnavailableError extends ApiError {
17
+ readonly kind: string;
18
+ }
19
+ /** GatewayTimeout failure, independent of transport. */
20
+ export declare class GatewayTimeoutError extends ApiError {
21
+ readonly kind: string;
22
+ }
23
+ /** Internal failure, independent of transport. */
24
+ export declare class InternalError extends ApiError {
25
+ readonly kind: string;
26
+ }
27
+ /** TooManyRequests failure, independent of transport. */
28
+ export declare class TooManyRequestsError extends ApiError {
29
+ readonly kind: string;
30
+ }
31
+ /** Forbidden failure, independent of transport. */
32
+ export declare class ForbiddenError extends ApiError {
33
+ readonly kind: string;
34
+ }
35
+ /** RequestTimeout failure, independent of transport. */
36
+ export declare class RequestTimeoutError extends ApiError {
37
+ readonly kind: string;
38
+ }
39
+ /** Offline failure, independent of transport. */
40
+ export declare class OfflineError extends ApiError {
41
+ readonly kind: string;
42
+ }
43
+ /** The API endpoint is missing, distinct from an absent domain entity. */
44
+ export declare class EndpointNotFoundError extends NotFoundError {
45
+ readonly kind: string;
46
+ }
47
+ /** Expected user mistake: successful protocol/monitoring outcome; GUI catches this error. */
48
+ export declare class UserError extends ApiError {
49
+ errorCode?: string | undefined;
50
+ readonly kind: string;
51
+ constructor(message: string, errorCode?: string | undefined, cause?: Error);
52
+ }
53
+ /** Invalid caller input with optional human-safe field feedback. */
54
+ export declare class BadRequestError extends ApiError {
55
+ field?: string | undefined;
56
+ guiMessage?: string | undefined;
57
+ readonly kind: string;
58
+ constructor(message: string, field?: string | undefined, guiMessage?: string | undefined, cause?: Error);
59
+ }
60
+ /** Authentication failure with a contract-defined reason. */
61
+ export declare class UnauthorizedError extends ApiError {
62
+ readonly kind: string;
63
+ constructor(message: string, subType?: string, cause?: Error);
64
+ }
65
+ /** Dependency failure with bounded retry advice. */
66
+ export declare class VendorError extends ApiError {
67
+ waitSeconds: number;
68
+ readonly kind: string;
69
+ constructor(message: string, waitSeconds?: number, cause?: Error);
70
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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;
4
+ /** Portable semantic failures. HTTP status mapping belongs to the HTTP adapter. */
5
+ class ApiError extends Error {
6
+ kind = 'internal';
7
+ subType;
8
+ constructor(message, cause) {
9
+ super(message, { cause });
10
+ this.name = new.target.name;
11
+ }
12
+ }
13
+ exports.ApiError = ApiError;
14
+ /** NotFound failure, independent of transport. */
15
+ class NotFoundError extends ApiError {
16
+ kind = 'not-found';
17
+ }
18
+ exports.NotFoundError = NotFoundError;
19
+ /** BadGateway failure, independent of transport. */
20
+ class BadGatewayError extends ApiError {
21
+ kind = 'bad-gateway';
22
+ }
23
+ exports.BadGatewayError = BadGatewayError;
24
+ /** ServiceUnavailable failure, independent of transport. */
25
+ class ServiceUnavailableError extends ApiError {
26
+ kind = 'service-unavailable';
27
+ }
28
+ exports.ServiceUnavailableError = ServiceUnavailableError;
29
+ /** GatewayTimeout failure, independent of transport. */
30
+ class GatewayTimeoutError extends ApiError {
31
+ kind = 'gateway-timeout';
32
+ }
33
+ exports.GatewayTimeoutError = GatewayTimeoutError;
34
+ /** Internal failure, independent of transport. */
35
+ class InternalError extends ApiError {
36
+ kind = 'internal';
37
+ }
38
+ exports.InternalError = InternalError;
39
+ /** TooManyRequests failure, independent of transport. */
40
+ class TooManyRequestsError extends ApiError {
41
+ kind = 'too-many-requests';
42
+ }
43
+ exports.TooManyRequestsError = TooManyRequestsError;
44
+ /** Forbidden failure, independent of transport. */
45
+ class ForbiddenError extends ApiError {
46
+ kind = 'forbidden';
47
+ }
48
+ exports.ForbiddenError = ForbiddenError;
49
+ /** RequestTimeout failure, independent of transport. */
50
+ class RequestTimeoutError extends ApiError {
51
+ kind = 'request-timeout';
52
+ }
53
+ exports.RequestTimeoutError = RequestTimeoutError;
54
+ /** Offline failure, independent of transport. */
55
+ class OfflineError extends ApiError {
56
+ kind = 'offline';
57
+ }
58
+ exports.OfflineError = OfflineError;
59
+ /** The API endpoint is missing, distinct from an absent domain entity. */
60
+ class EndpointNotFoundError extends NotFoundError {
61
+ kind = 'endpoint-not-found';
62
+ }
63
+ exports.EndpointNotFoundError = EndpointNotFoundError;
64
+ /** Expected user mistake: successful protocol/monitoring outcome; GUI catches this error. */
65
+ class UserError extends ApiError {
66
+ errorCode;
67
+ kind = 'user';
68
+ constructor(message, errorCode, cause) {
69
+ super(message, cause);
70
+ this.errorCode = errorCode;
71
+ this.subType = 'USER_ERROR';
72
+ }
73
+ }
74
+ exports.UserError = UserError;
75
+ /** Invalid caller input with optional human-safe field feedback. */
76
+ class BadRequestError extends ApiError {
77
+ field;
78
+ guiMessage;
79
+ kind = 'bad-request';
80
+ constructor(message, field, guiMessage, cause) {
81
+ super(message, cause);
82
+ this.field = field;
83
+ this.guiMessage = guiMessage;
84
+ }
85
+ }
86
+ exports.BadRequestError = BadRequestError;
87
+ /** Authentication failure with a contract-defined reason. */
88
+ class UnauthorizedError extends ApiError {
89
+ kind = 'unauthorized';
90
+ constructor(message, subType, cause) {
91
+ super(message, cause);
92
+ this.subType = subType;
93
+ }
94
+ }
95
+ exports.UnauthorizedError = UnauthorizedError;
96
+ /** Dependency failure with bounded retry advice. */
97
+ class VendorError extends ApiError {
98
+ waitSeconds;
99
+ kind = 'vendor';
100
+ constructor(message, waitSeconds = 30, cause) {
101
+ super(message, cause);
102
+ this.waitSeconds = waitSeconds;
103
+ }
104
+ }
105
+ exports.VendorError = VendorError;
106
+ //# sourceMappingURL=ApiError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiError.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/errors/ApiError.ts"],"names":[],"mappings":";;;AAAA,mFAAmF;AACnF,MAAa,QAAS,SAAQ,KAAK;IACtB,IAAI,GAAW,UAAU,CAAC;IAC5B,OAAO,CAAU;IACxB,YAAY,OAAe,EAAE,KAAa;QACtC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAChC,CAAC;CACJ;AAPD,4BAOC;AAED,kDAAkD;AAClD,MAAa,aAAc,SAAQ,QAAQ;IAAqB,IAAI,GAAW,WAAW,CAAC;CAAE;AAA7F,sCAA6F;AAE7F,oDAAoD;AACpD,MAAa,eAAgB,SAAQ,QAAQ;IAAqB,IAAI,GAAW,aAAa,CAAC;CAAE;AAAjG,0CAAiG;AAEjG,4DAA4D;AAC5D,MAAa,uBAAwB,SAAQ,QAAQ;IAAqB,IAAI,GAAW,qBAAqB,CAAC;CAAE;AAAjH,0DAAiH;AAEjH,wDAAwD;AACxD,MAAa,mBAAoB,SAAQ,QAAQ;IAAqB,IAAI,GAAW,iBAAiB,CAAC;CAAE;AAAzG,kDAAyG;AAEzG,kDAAkD;AAClD,MAAa,aAAc,SAAQ,QAAQ;IAAqB,IAAI,GAAW,UAAU,CAAC;CAAE;AAA5F,sCAA4F;AAE5F,yDAAyD;AACzD,MAAa,oBAAqB,SAAQ,QAAQ;IAAqB,IAAI,GAAW,mBAAmB,CAAC;CAAE;AAA5G,oDAA4G;AAE5G,mDAAm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WAAY,SAAQ,QAAQ;IAED;IADlB,IAAI,GAAW,QAAQ,CAAC;IAC1C,YAAY,OAAe,EAAS,cAAc,EAAE,EAAE,KAAa;QAC/D,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QADU,gBAAW,GAAX,WAAW,CAAK;IAEpD,CAAC;CACJ;AALD,kCAKC","sourcesContent":["/** Portable semantic failures. HTTP status mapping belongs to the HTTP adapter. */\nexport class ApiError extends Error {\n readonly kind: string = 'internal';\n public subType?: string;\n constructor(message: string, cause?: Error) {\n super(message, { cause });\n this.name = new.target.name;\n }\n}\n\n/** NotFound failure, independent of transport. */\nexport class NotFoundError extends ApiError { override readonly kind: string = 'not-found'; }\n\n/** BadGateway failure, independent of transport. */\nexport class BadGatewayError extends ApiError { override readonly kind: string = 'bad-gateway'; }\n\n/** ServiceUnavailable failure, independent of transport. */\nexport class ServiceUnavailableError extends ApiError { override readonly kind: string = 'service-unavailable'; }\n\n/** GatewayTimeout failure, independent of transport. */\nexport class GatewayTimeoutError extends ApiError { override readonly kind: string = 'gateway-timeout'; }\n\n/** Internal failure, independent of transport. */\nexport class InternalError extends ApiError { override readonly kind: string = 'internal'; }\n\n/** TooManyRequests failure, independent of transport. */\nexport class TooManyRequestsError extends ApiError { override readonly kind: string = 'too-many-requests'; }\n\n/** Forbidden failure, independent of transport. */\nexport class ForbiddenError extends ApiError { override readonly kind: string = 'forbidden'; }\n\n/** RequestTimeout failure, independent of transport. */\nexport class RequestTimeoutError extends ApiError { override readonly kind: string = 'request-timeout'; }\n\n/** Offline failure, independent of transport. */\nexport class OfflineError extends ApiError { override readonly kind: string = 'offline'; }\n\n/** The API endpoint is missing, distinct from an absent domain entity. */\nexport class EndpointNotFoundError extends NotFoundError { override readonly kind: string = 'endpoint-not-found'; }\n/** Expected user mistake: successful protocol/monitoring outcome; GUI catches this error. */\nexport class UserError extends ApiError {\n override readonly kind: string = 'user';\n constructor(message: string, public errorCode?: string, cause?: Error) {\n super(message, cause);\n this.subType = 'USER_ERROR';\n }\n}\n/** Invalid caller input with optional human-safe field feedback. */\nexport class BadRequestError extends ApiError {\n override readonly kind: string = 'bad-request';\n constructor(message: string, public field?: string, public guiMessage?: string, cause?: Error) {\n super(message, cause);\n }\n}\n/** Authentication failure with a contract-defined reason. */\nexport class UnauthorizedError extends ApiError {\n override readonly kind: string = 'unauthorized';\n constructor(message: string, subType?: string, cause?: Error) {\n super(message, cause);\n this.subType = subType;\n }\n}\n/** Dependency failure with bounded retry advice. */\nexport class VendorError extends ApiError {\n override readonly kind: string = 'vendor';\n constructor(message: string, public waitSeconds = 30, cause?: Error) {\n super(message, cause);\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import { ApiError } from './ApiError';
2
+ /** Allowlisted error envelope shared by non-HTTP transports. Contains only bounded semantic causes, never stacks or arbitrary properties. */
3
+ export declare class ApiErrorPayload {
4
+ kind: string;
5
+ message: string;
6
+ cause?: ApiErrorPayload;
7
+ subType?: string;
8
+ field?: string;
9
+ guiAlertMessage?: string;
10
+ errorCode?: string;
11
+ waitSeconds?: number;
12
+ constructor(kind: string, message: string);
13
+ }
14
+ /** Bounded, safe, transport-neutral encoding. Unrecognized types become generic internal failures. */
15
+ export declare class ApiErrorCodec {
16
+ static encode(error: unknown): ApiErrorPayload;
17
+ private static encodeDepth;
18
+ static decode(value: unknown): ApiError;
19
+ private static decodeDepth;
20
+ private static decodeOne;
21
+ private static kind;
22
+ private static text;
23
+ private static wait;
24
+ private static message;
25
+ }
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiErrorCodec = exports.ApiErrorPayload = void 0;
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. */
6
+ class ApiErrorPayload {
7
+ kind;
8
+ message;
9
+ cause;
10
+ subType;
11
+ field;
12
+ guiAlertMessage;
13
+ errorCode;
14
+ waitSeconds;
15
+ constructor(kind, message) {
16
+ this.kind = kind;
17
+ this.message = message;
18
+ }
19
+ }
20
+ exports.ApiErrorPayload = ApiErrorPayload;
21
+ /** Bounded, safe, transport-neutral encoding. Unrecognized types become generic internal failures. */
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
24
+ static encode(error) {
25
+ return this.encodeDepth(error, 0);
26
+ }
27
+ // webpieces-disable no-function-outside-class -- recursive bounded wire codec; webpieces-disable no-any-unknown -- thrown causes require runtime narrowing
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));
31
+ if (error instanceof ApiError_1.ApiError)
32
+ payload.subType = this.text(error.subType);
33
+ if (error instanceof ApiError_1.UserError)
34
+ payload.errorCode = this.text(error.errorCode);
35
+ if (error instanceof ApiError_1.BadRequestError) {
36
+ payload.field = this.text(error.field);
37
+ payload.guiAlertMessage = this.text(error.guiMessage);
38
+ }
39
+ if (error instanceof ApiError_1.VendorError)
40
+ payload.waitSeconds = this.wait(error.waitSeconds);
41
+ if (error instanceof Error && depth < 3) {
42
+ const cause = Object.getOwnPropertyDescriptor(error, 'cause')?.value;
43
+ if (cause instanceof Error)
44
+ payload.cause = this.encodeDepth(cause, depth + 1);
45
+ }
46
+ return payload;
47
+ }
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
+ static decode(value) {
50
+ return this.decodeDepth(value, 0);
51
+ }
52
+ // webpieces-disable no-function-outside-class -- recursive bounded wire codec; webpieces-disable no-any-unknown -- remote causes remain untrusted until validated
53
+ static decodeDepth(value, depth) {
54
+ const error = this.decodeOne(value);
55
+ if (typeof value === 'object' && value !== null && depth < 3) {
56
+ const cause = Object.getOwnPropertyDescriptor(value, 'cause')?.value;
57
+ if (typeof cause === 'object' && cause !== null) {
58
+ // webpieces-disable no-anonymous-object-literals -- standard property descriptor keeps Error.cause non-enumerable
59
+ Object.defineProperty(error, 'cause', {
60
+ value: this.decodeDepth(cause, depth + 1),
61
+ configurable: true,
62
+ writable: true,
63
+ });
64
+ }
65
+ }
66
+ return error;
67
+ }
68
+ // webpieces-disable no-function-outside-class -- allowlisted wire codec; webpieces-disable no-any-unknown -- JSON transport input must be validated before use
69
+ static decodeOne(value) {
70
+ if (typeof value !== 'object' || value === null)
71
+ return new ApiError_1.InternalError('Internal Error');
72
+ // webpieces-disable no-any-unknown -- own wire fields remain untrusted until narrowed
73
+ const field = (key) => Object.getOwnPropertyDescriptor(value, key)?.value;
74
+ const kind = field('kind');
75
+ const message = this.text(field('message')) ?? this.message(kind);
76
+ switch (kind) {
77
+ case 'user':
78
+ return new ApiError_1.UserError(message, this.text(field('errorCode')));
79
+ case 'bad-request':
80
+ return new ApiError_1.BadRequestError(message, this.text(field('field')), this.text(field('guiAlertMessage')));
81
+ case 'unauthorized':
82
+ return new ApiError_1.UnauthorizedError(message, this.text(field('subType')));
83
+ case 'forbidden':
84
+ return new ApiError_1.ForbiddenError(message);
85
+ case 'not-found':
86
+ return new ApiError_1.NotFoundError(message);
87
+ case 'endpoint-not-found':
88
+ return new ApiError_1.EndpointNotFoundError(message);
89
+ 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);
105
+ default:
106
+ return new ApiError_1.InternalError('Internal Error');
107
+ }
108
+ }
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';
138
+ }
139
+ // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire fields need runtime string checks
140
+ static text(value) {
141
+ return typeof value === 'string' ? value.slice(0, 4096) : undefined;
142
+ }
143
+ // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire fields need runtime finite number checks
144
+ static wait(value) {
145
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0
146
+ ? Math.min(value, 86400)
147
+ : undefined;
148
+ }
149
+ // webpieces-disable no-function-outside-class -- helper of stateless codec; webpieces-disable no-any-unknown -- wire discriminator must be allowlisted before selection
150
+ static message(kind) {
151
+ switch (kind) {
152
+ case 'user':
153
+ return 'User Error';
154
+ case 'bad-request':
155
+ return 'Bad Request';
156
+ case 'unauthorized':
157
+ return 'Unauthorized';
158
+ case 'forbidden':
159
+ return 'Forbidden';
160
+ case 'not-found':
161
+ return 'Not Found';
162
+ case 'endpoint-not-found':
163
+ return 'Endpoint Not Found';
164
+ case 'request-timeout':
165
+ 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':
171
+ return 'Service Unavailable';
172
+ case 'gateway-timeout':
173
+ return 'Gateway Timeout';
174
+ case 'vendor':
175
+ return 'Vendor Error';
176
+ case 'offline':
177
+ return 'Offline';
178
+ default:
179
+ return 'Internal Error';
180
+ }
181
+ }
182
+ }
183
+ exports.ApiErrorCodec = ApiErrorCodec;
184
+ //# sourceMappingURL=ApiErrorCodec.js.map
@@ -0,0 +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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AAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;YACpE,CAAC,CAAC,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"]}
@@ -0,0 +1,2 @@
1
+ export { ApiError, NotFoundError, BadGatewayError, ServiceUnavailableError, GatewayTimeoutError, InternalError, TooManyRequestsError, ForbiddenError, RequestTimeoutError, OfflineError, EndpointNotFoundError, UserError, BadRequestError, UnauthorizedError, VendorError, } from './ApiError';
2
+ export { ApiErrorCodec, ApiErrorPayload } from './ApiErrorCodec';
@@ -0,0 +1,23 @@
1
+ "use strict";
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;
4
+ var ApiError_1 = require("./ApiError");
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; } });
20
+ var ApiErrorCodec_1 = require("./ApiErrorCodec");
21
+ Object.defineProperty(exports, "ApiErrorCodec", { enumerable: true, get: function () { return ApiErrorCodec_1.ApiErrorCodec; } });
22
+ Object.defineProperty(exports, "ApiErrorPayload", { enumerable: true, get: function () { return ApiErrorCodec_1.ApiErrorPayload; } });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,5 @@
1
+ import { ApiError } from '../errors/ApiError';
2
+ /** HTTP-only adapter: semantic errors themselves have no protocol status property. */
3
+ export declare class HttpErrorStatus {
4
+ static code(error: ApiError): number;
5
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpErrorStatus = void 0;
4
+ const ApiError_1 = require("../errors/ApiError");
5
+ const errors_1 = require("./errors");
6
+ /** HTTP-only adapter: semantic errors themselves have no protocol status property. */
7
+ class HttpErrorStatus {
8
+ // webpieces-disable no-function-outside-class -- stateless mapping shared by HTTP adapters
9
+ static code(error) {
10
+ if (error instanceof errors_1.HttpError)
11
+ return error.code;
12
+ if (error instanceof ApiError_1.UserError)
13
+ return 266;
14
+ if (error instanceof ApiError_1.BadRequestError)
15
+ return 400;
16
+ if (error instanceof ApiError_1.UnauthorizedError)
17
+ return 401;
18
+ if (error instanceof ApiError_1.ForbiddenError)
19
+ return 403;
20
+ if (error instanceof ApiError_1.NotFoundError)
21
+ return 404;
22
+ if (error instanceof ApiError_1.RequestTimeoutError)
23
+ return 408;
24
+ if (error instanceof ApiError_1.TooManyRequestsError)
25
+ return 429;
26
+ if (error instanceof ApiError_1.BadGatewayError)
27
+ return 502;
28
+ if (error instanceof ApiError_1.ServiceUnavailableError)
29
+ return 503;
30
+ if (error instanceof ApiError_1.GatewayTimeoutError)
31
+ return 504;
32
+ if (error instanceof ApiError_1.VendorError)
33
+ return 598;
34
+ return 500;
35
+ }
36
+ }
37
+ exports.HttpErrorStatus = HttpErrorStatus;
38
+ //# sourceMappingURL=HttpErrorStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpErrorStatus.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/HttpErrorStatus.ts"],"names":[],"mappings":";;;AAAA,iDAI4B;AAC5B,qCAAqC;AAErC,sFAAsF;AACtF,MAAa,eAAe;IACxB,2FAA2F;IAC3F,MAAM,CAAC,IAAI,CAAC,KAAe;QACvB,IAAI,KAAK,YAAY,kBAAS;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC;QAClD,IAAI,KAAK,YAAY,oBAAS;YAAE,OAAO,GAAG,CAAC;QAC3C,IAAI,KAAK,YAAY,0BAAe;YAAE,OAAO,GAAG,CAAC;QACjD,IAAI,KAAK,YAAY,4BAAiB;YAAE,OAAO,GAAG,CAAC;QACnD,IAAI,KAAK,YAAY,yBAAc;YAAE,OAAO,GAAG,CAAC;QAChD,IAAI,KAAK,YAAY,wBAAa;YAAE,OAAO,GAAG,CAAC;QAC/C,IAAI,KAAK,YAAY,8BAAmB;YAAE,OAAO,GAAG,CAAC;QACrD,IAAI,KAAK,YAAY,+BAAoB;YAAE,OAAO,GAAG,CAAC;QACtD,IAAI,KAAK,YAAY,0BAAe;YAAE,OAAO,GAAG,CAAC;QACjD,IAAI,KAAK,YAAY,kCAAuB;YAAE,OAAO,GAAG,CAAC;QACzD,IAAI,KAAK,YAAY,8BAAmB;YAAE,OAAO,GAAG,CAAC;QACrD,IAAI,KAAK,YAAY,sBAAW;YAAE,OAAO,GAAG,CAAC;QAC7C,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAjBD,0CAiBC","sourcesContent":["import {\n ApiError, UserError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError,\n RequestTimeoutError, TooManyRequestsError, BadGatewayError, ServiceUnavailableError,\n GatewayTimeoutError, VendorError,\n} from '../errors/ApiError';\nimport { HttpError } from './errors';\n\n/** HTTP-only adapter: semantic errors themselves have no protocol status property. */\nexport class HttpErrorStatus {\n // webpieces-disable no-function-outside-class -- stateless mapping shared by HTTP adapters\n static code(error: ApiError): number {\n if (error instanceof HttpError) return error.code;\n if (error instanceof UserError) return 266;\n if (error instanceof BadRequestError) return 400;\n if (error instanceof UnauthorizedError) return 401;\n if (error instanceof ForbiddenError) return 403;\n if (error instanceof NotFoundError) return 404;\n if (error instanceof RequestTimeoutError) return 408;\n if (error instanceof TooManyRequestsError) return 429;\n if (error instanceof BadGatewayError) return 502;\n if (error instanceof ServiceUnavailableError) return 503;\n if (error instanceof GatewayTimeoutError) return 504;\n if (error instanceof VendorError) return 598;\n return 500;\n }\n}\n"]}
@@ -73,7 +73,7 @@ export declare class LogApiCallImpl {
73
73
  */
74
74
  private logFailure;
75
75
  /**
76
- * UTF-8 byte size of an already-serialized body. TextEncoder, not Buffer: LogApiCall runs in the
76
+ * UTF-8 byte size without platform-specific encoding globals: LogApiCall runs in the
77
77
  * browser bundle. Undefined in, undefined out — a `Promise<void>` method has no body to measure,
78
78
  * and a 0 there would be a lie (JSON.stringify(undefined) returns undefined, not '').
79
79
  */
@@ -156,7 +156,7 @@ class LogApiCallImpl {
156
156
  : log.error(`[API-${side}-resp-FAIL] ${id} errorType=${errorType} error=${error.message}`));
157
157
  }
158
158
  /**
159
- * UTF-8 byte size of an already-serialized body. TextEncoder, not Buffer: LogApiCall runs in the
159
+ * UTF-8 byte size without platform-specific encoding globals: LogApiCall runs in the
160
160
  * browser bundle. Undefined in, undefined out — a `Promise<void>` method has no body to measure,
161
161
  * and a 0 there would be a lie (JSON.stringify(undefined) returns undefined, not '').
162
162
  */
@@ -164,7 +164,12 @@ class LogApiCallImpl {
164
164
  if (serialized === undefined) {
165
165
  return undefined;
166
166
  }
167
- return new TextEncoder().encode(serialized).length;
167
+ let bytes = 0;
168
+ for (const character of serialized) {
169
+ const code = character.codePointAt(0);
170
+ bytes += code <= 0x7f ? 1 : code <= 0x7ff ? 2 : code <= 0xffff ? 3 : 4;
171
+ }
172
+ return bytes;
168
173
  }
169
174
  /**
170
175
  * Is this error a NON-failure for HEALTH/METRICS — the process working CORRECTLY (log OTHER, api