@webpieces/core-util 0.4.416 → 0.4.418
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/http/errors.d.ts +24 -0
- package/src/http/errors.js +35 -1
- package/src/http/errors.js.map +1 -1
- package/src/http/networkReject.d.ts +27 -0
- package/src/http/networkReject.js +100 -0
- package/src/http/networkReject.js.map +1 -0
- package/src/index.d.ts +2 -1
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
package/package.json
CHANGED
package/src/http/errors.d.ts
CHANGED
|
@@ -60,6 +60,15 @@ export declare class HttpBadRequestError extends HttpError {
|
|
|
60
60
|
export declare class HttpUnauthorizedError extends HttpError {
|
|
61
61
|
constructor(message: string, subType?: string, cause?: Error);
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* HttpTooManyRequestsError - 429 Too Many Requests.
|
|
65
|
+
*
|
|
66
|
+
* The one member of the HttpError ladder that never made it over from trytami. Without it, apps are
|
|
67
|
+
* forced back to `err.code === 429` — the exact untyped pattern this ladder exists to replace.
|
|
68
|
+
*/
|
|
69
|
+
export declare class HttpTooManyRequestsError extends HttpError {
|
|
70
|
+
constructor(message: string, cause?: Error);
|
|
71
|
+
}
|
|
63
72
|
/**
|
|
64
73
|
* HttpForbiddenError - 403 Forbidden.
|
|
65
74
|
*/
|
|
@@ -116,3 +125,18 @@ export declare class HttpUserError extends HttpError {
|
|
|
116
125
|
errorCode?: string;
|
|
117
126
|
constructor(message: string, errorCode?: string, cause?: Error);
|
|
118
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* OfflineError - the request never reached a server.
|
|
130
|
+
*
|
|
131
|
+
* Offline, DNS failure, connection refused, CORS preflight rejected: `fetch` itself rejected, so no
|
|
132
|
+
* Response — and therefore no HTTP status — ever existed. That is precisely why this extends `Error`
|
|
133
|
+
* and NOT `HttpError`: an `HttpError` carries a `code` and means "the server replied with a failure",
|
|
134
|
+
* a different situation a caller usually retries differently. Subclassing it would give this a bogus
|
|
135
|
+
* status and make it match `instanceof HttpError` ladders that must not catch a transport reject.
|
|
136
|
+
*
|
|
137
|
+
* The original failure (a raw `TypeError: Failed to fetch`, or undici's coded reject) is always
|
|
138
|
+
* preserved as `cause`, so a caller that wants the underlying detail can still reach it.
|
|
139
|
+
*/
|
|
140
|
+
export declare class OfflineError extends Error {
|
|
141
|
+
constructor(message: string, cause?: Error);
|
|
142
|
+
}
|
package/src/http/errors.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* These errors are used throughout the framework for consistent error handling.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.HttpUserError = exports.HttpVendorError = exports.HttpInternalServerError = exports.HttpGatewayTimeoutError = exports.HttpBadGatewayError = exports.HttpTimeoutError = exports.HttpForbiddenError = exports.HttpUnauthorizedError = exports.HttpBadRequestError = exports.EndpointNotFoundError = exports.HttpNotFoundError = 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.HttpError = exports.ProtocolError = void 0;
|
|
7
|
+
exports.OfflineError = exports.HttpUserError = exports.HttpVendorError = exports.HttpInternalServerError = exports.HttpGatewayTimeoutError = exports.HttpBadGatewayError = exports.HttpTimeoutError = exports.HttpForbiddenError = exports.HttpTooManyRequestsError = exports.HttpUnauthorizedError = exports.HttpBadRequestError = exports.EndpointNotFoundError = exports.HttpNotFoundError = 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.HttpError = exports.ProtocolError = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* ProtocolError - Data class for error response body.
|
|
10
10
|
* This is what gets serialized and sent to the client.
|
|
@@ -93,6 +93,20 @@ class HttpUnauthorizedError extends HttpError {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
exports.HttpUnauthorizedError = HttpUnauthorizedError;
|
|
96
|
+
/**
|
|
97
|
+
* HttpTooManyRequestsError - 429 Too Many Requests.
|
|
98
|
+
*
|
|
99
|
+
* The one member of the HttpError ladder that never made it over from trytami. Without it, apps are
|
|
100
|
+
* forced back to `err.code === 429` — the exact untyped pattern this ladder exists to replace.
|
|
101
|
+
*/
|
|
102
|
+
class HttpTooManyRequestsError extends HttpError {
|
|
103
|
+
constructor(message, cause) {
|
|
104
|
+
super(message, 429, undefined, cause);
|
|
105
|
+
this.name = 'TooManyRequests';
|
|
106
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.HttpTooManyRequestsError = HttpTooManyRequestsError;
|
|
96
110
|
/**
|
|
97
111
|
* HttpForbiddenError - 403 Forbidden.
|
|
98
112
|
*/
|
|
@@ -186,4 +200,24 @@ class HttpUserError extends HttpError {
|
|
|
186
200
|
}
|
|
187
201
|
}
|
|
188
202
|
exports.HttpUserError = HttpUserError;
|
|
203
|
+
/**
|
|
204
|
+
* OfflineError - the request never reached a server.
|
|
205
|
+
*
|
|
206
|
+
* Offline, DNS failure, connection refused, CORS preflight rejected: `fetch` itself rejected, so no
|
|
207
|
+
* Response — and therefore no HTTP status — ever existed. That is precisely why this extends `Error`
|
|
208
|
+
* and NOT `HttpError`: an `HttpError` carries a `code` and means "the server replied with a failure",
|
|
209
|
+
* a different situation a caller usually retries differently. Subclassing it would give this a bogus
|
|
210
|
+
* status and make it match `instanceof HttpError` ladders that must not catch a transport reject.
|
|
211
|
+
*
|
|
212
|
+
* The original failure (a raw `TypeError: Failed to fetch`, or undici's coded reject) is always
|
|
213
|
+
* preserved as `cause`, so a caller that wants the underlying detail can still reach it.
|
|
214
|
+
*/
|
|
215
|
+
class OfflineError extends Error {
|
|
216
|
+
constructor(message, cause) {
|
|
217
|
+
super(message, { cause });
|
|
218
|
+
this.name = 'OfflineError';
|
|
219
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.OfflineError = OfflineError;
|
|
189
223
|
//# sourceMappingURL=errors.js.map
|
package/src/http/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/errors.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,aAAa;IACf,OAAO,CAAU;IACjB,OAAO,CAAU;IACjB,KAAK,CAAU;IACf,WAAW,CAAU;IACrB,IAAI,CAAU;IACd,eAAe,CAAU;IACzB,SAAS,CAAU;CAC7B;AARD,sCAQC;AAED;;;GAGG;AACH,MAAa,SAAU,SAAQ,KAAK;IACzB,IAAI,CAAS;IACb,OAAO,CAAU;IACR,SAAS,CAAS;IAElC,YACI,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,KAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;CACJ;AAhBD,8BAgBC;AAED,0BAA0B;AACb,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;AAEv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ent error handling.\n */\n\n/**\n * ProtocolError - Data class for error response body.\n * This is what gets serialized and sent to the client.\n */\nexport class ProtocolError {\n public message?: string;\n public subType?: string;\n public field?: string;\n public waitSeconds?: number;\n public name?: string;\n public guiAlertMessage?: string;\n public errorCode?: string;\n}\n\n/**\n * HttpError - Base error class with HTTP status code.\n * All specific HTTP errors extend this class.\n */\nexport class HttpError extends Error {\n public code: number;\n public subType?: string;\n public readonly httpCause?: Error;\n\n constructor(\n message: string,\n code: number,\n subType?: string,\n cause?: Error,\n ) {\n super(message);\n this.code = code;\n this.subType = subType;\n this.httpCause = cause;\n }\n}\n\n// Error subtype constants\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\n/**\n * HttpNotFoundError - 404 Not Found.\n */\nexport class HttpNotFoundError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 404, undefined, cause);\n this.name = ENTITY_NOT_FOUND;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * EndpointNotFoundError - 404 for missing endpoints.\n */\nexport class EndpointNotFoundError extends HttpNotFoundError {\n constructor(message: string, cause?: Error) {\n super(message, cause);\n this.name = 'EndpointNotFoundError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpBadRequestError - 400 Bad Request.\n * Used for validation errors with optional field and GUI message.\n */\nexport class HttpBadRequestError extends HttpError {\n public field?: string;\n public guiMessage?: string;\n\n constructor(message: string, field?: string, guiMessage?: string, cause?: Error) {\n super(message, 400, undefined, cause);\n this.name = 'BadRequest';\n this.field = field;\n this.guiMessage = guiMessage;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpUnauthorizedError - 401 Unauthorized.\n */\nexport class HttpUnauthorizedError extends HttpError {\n constructor(message: string, subType?: string, cause?: Error) {\n super(message, 401, subType, cause);\n this.name = 'Unauthorized';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpForbiddenError - 403 Forbidden.\n */\nexport class HttpForbiddenError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 403, undefined, cause);\n this.name = 'Forbidden';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpTimeoutError - 408 Request Timeout.\n */\nexport class HttpTimeoutError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 408, undefined, cause);\n this.name = 'Timeout';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpBadGatewayError - 502 Bad Gateway.\n */\nexport class HttpBadGatewayError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 502, undefined, cause);\n this.name = 'HttpBadGatewayError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpGatewayTimeoutError - 504 Gateway Timeout.\n * SHOULD NOT BE USED SERVER SIDE SINCE ALBs will return 504 and it will not be translated\n * to json body 'ProtocolError'.\n */\nexport class HttpGatewayTimeoutError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 504, undefined, cause);\n this.name = 'HttpGatewayTimeoutError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpInternalServerError - 500 Internal Server Error.\n */\nexport class HttpInternalServerError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 500, undefined, cause);\n this.name = 'InternalServerError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpVendorError - 598 Vendor Error.\n * Custom status code for vendor/external service errors with retry hint.\n */\nexport class HttpVendorError extends HttpError {\n constructor(\n message: string,\n public waitSeconds = 30,\n cause?: Error,\n ) {\n super(message, 598, undefined, cause);\n this.name = 'VendorError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpUserError - User validation error with 2xx status code.\n *\n * Uses HTTP 266 (non-standard 2xx code) intentionally because:\n * 1. User validation errors are \"successful\" from server perspective - user just made a mistake\n * 2. Browser DevTools show 4xx/5xx codes in RED, which is confusing for user validation\n * 3. Allows error to propagate up the stack via throw without triggering error monitoring\n * 4. Avoids polluting logs with \"errors\" that are actually expected user behavior\n *\n * This is a deliberate design pattern - do NOT change to 4xx codes.\n * Examples: \"Email already exists\", \"Invalid password format\", \"Required field missing\"\n */\nexport class HttpUserError extends HttpError {\n public errorCode?: string;\n\n constructor(message: string, errorCode?: string, cause?: Error) {\n super(message, 266, 'USER_ERROR', cause);\n this.name = 'UserError';\n this.errorCode = errorCode;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/errors.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,aAAa;IACf,OAAO,CAAU;IACjB,OAAO,CAAU;IACjB,KAAK,CAAU;IACf,WAAW,CAAU;IACrB,IAAI,CAAU;IACd,eAAe,CAAU;IACzB,SAAS,CAAU;CAC7B;AARD,sCAQC;AAED;;;GAGG;AACH,MAAa,SAAU,SAAQ,KAAK;IACzB,IAAI,CAAS;IACb,OAAO,CAAU;IACR,SAAS,CAAS;IAElC,YACI,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,KAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;CACJ;AAhBD,8BAgBC;AAED,0BAA0B;AACb,QAAA,gBAAgB,GAAG,qBAAqB,CAAC;AACzC,QAAA,gBAAgB,GAAG,gBAAgB,CA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AAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACJ;AAVD,0CAUC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,aAAc,SAAQ,SAAS;IACjC,SAAS,CAAU;IAE1B,YAAY,OAAe,EAAE,SAAkB,EAAE,KAAa;QAC1D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACJ;AATD,sCASC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,YAAa,SAAQ,KAAK;IACnC,YAAY,OAAe,EAAE,KAAa;QACtC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACJ;AAND,oCAMC","sourcesContent":["/**\n * HTTP Error classes for webpieces-ts.\n * These errors are used throughout the framework for consistent error handling.\n */\n\n/**\n * ProtocolError - Data class for error response body.\n * This is what gets serialized and sent to the client.\n */\nexport class ProtocolError {\n public message?: string;\n public subType?: string;\n public field?: string;\n public waitSeconds?: number;\n public name?: string;\n public guiAlertMessage?: string;\n public errorCode?: string;\n}\n\n/**\n * HttpError - Base error class with HTTP status code.\n * All specific HTTP errors extend this class.\n */\nexport class HttpError extends Error {\n public code: number;\n public subType?: string;\n public readonly httpCause?: Error;\n\n constructor(\n message: string,\n code: number,\n subType?: string,\n cause?: Error,\n ) {\n super(message);\n this.code = code;\n this.subType = subType;\n this.httpCause = cause;\n }\n}\n\n// Error subtype constants\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\n/**\n * HttpNotFoundError - 404 Not Found.\n */\nexport class HttpNotFoundError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 404, undefined, cause);\n this.name = ENTITY_NOT_FOUND;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * EndpointNotFoundError - 404 for missing endpoints.\n */\nexport class EndpointNotFoundError extends HttpNotFoundError {\n constructor(message: string, cause?: Error) {\n super(message, cause);\n this.name = 'EndpointNotFoundError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpBadRequestError - 400 Bad Request.\n * Used for validation errors with optional field and GUI message.\n */\nexport class HttpBadRequestError extends HttpError {\n public field?: string;\n public guiMessage?: string;\n\n constructor(message: string, field?: string, guiMessage?: string, cause?: Error) {\n super(message, 400, undefined, cause);\n this.name = 'BadRequest';\n this.field = field;\n this.guiMessage = guiMessage;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpUnauthorizedError - 401 Unauthorized.\n */\nexport class HttpUnauthorizedError extends HttpError {\n constructor(message: string, subType?: string, cause?: Error) {\n super(message, 401, subType, cause);\n this.name = 'Unauthorized';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpTooManyRequestsError - 429 Too Many Requests.\n *\n * The one member of the HttpError ladder that never made it over from trytami. Without it, apps are\n * forced back to `err.code === 429` — the exact untyped pattern this ladder exists to replace.\n */\nexport class HttpTooManyRequestsError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 429, undefined, cause);\n this.name = 'TooManyRequests';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpForbiddenError - 403 Forbidden.\n */\nexport class HttpForbiddenError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 403, undefined, cause);\n this.name = 'Forbidden';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpTimeoutError - 408 Request Timeout.\n */\nexport class HttpTimeoutError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 408, undefined, cause);\n this.name = 'Timeout';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpBadGatewayError - 502 Bad Gateway.\n */\nexport class HttpBadGatewayError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 502, undefined, cause);\n this.name = 'HttpBadGatewayError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpGatewayTimeoutError - 504 Gateway Timeout.\n * SHOULD NOT BE USED SERVER SIDE SINCE ALBs will return 504 and it will not be translated\n * to json body 'ProtocolError'.\n */\nexport class HttpGatewayTimeoutError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 504, undefined, cause);\n this.name = 'HttpGatewayTimeoutError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpInternalServerError - 500 Internal Server Error.\n */\nexport class HttpInternalServerError extends HttpError {\n constructor(message: string, cause?: Error) {\n super(message, 500, undefined, cause);\n this.name = 'InternalServerError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpVendorError - 598 Vendor Error.\n * Custom status code for vendor/external service errors with retry hint.\n */\nexport class HttpVendorError extends HttpError {\n constructor(\n message: string,\n public waitSeconds = 30,\n cause?: Error,\n ) {\n super(message, 598, undefined, cause);\n this.name = 'VendorError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * HttpUserError - User validation error with 2xx status code.\n *\n * Uses HTTP 266 (non-standard 2xx code) intentionally because:\n * 1. User validation errors are \"successful\" from server perspective - user just made a mistake\n * 2. Browser DevTools show 4xx/5xx codes in RED, which is confusing for user validation\n * 3. Allows error to propagate up the stack via throw without triggering error monitoring\n * 4. Avoids polluting logs with \"errors\" that are actually expected user behavior\n *\n * This is a deliberate design pattern - do NOT change to 4xx codes.\n * Examples: \"Email already exists\", \"Invalid password format\", \"Required field missing\"\n */\nexport class HttpUserError extends HttpError {\n public errorCode?: string;\n\n constructor(message: string, errorCode?: string, cause?: Error) {\n super(message, 266, 'USER_ERROR', cause);\n this.name = 'UserError';\n this.errorCode = errorCode;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * OfflineError - the request never reached a server.\n *\n * Offline, DNS failure, connection refused, CORS preflight rejected: `fetch` itself rejected, so no\n * Response — and therefore no HTTP status — ever existed. That is precisely why this extends `Error`\n * and NOT `HttpError`: an `HttpError` carries a `code` and means \"the server replied with a failure\",\n * a different situation a caller usually retries differently. Subclassing it would give this a bogus\n * status and make it match `instanceof HttpError` ladders that must not catch a transport reject.\n *\n * The original failure (a raw `TypeError: Failed to fetch`, or undici's coded reject) is always\n * preserved as `cause`, so a caller that wants the underlying detail can still reach it.\n */\nexport class OfflineError extends Error {\n constructor(message: string, cause?: Error) {\n super(message, { cause });\n this.name = 'OfflineError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decides whether a thrown error is a transport reject and, if so, mints the typed {@link OfflineError}
|
|
3
|
+
* for it. Stateless and dependency-free, so a caller can `new` it directly on the browser fetch path
|
|
4
|
+
* (instance methods, not static — webpieces wires behaviour into injectable classes, and a static
|
|
5
|
+
* method is just a module-scope function wearing a class as a namespace).
|
|
6
|
+
*/
|
|
7
|
+
export declare class NetworkRejectClassifier {
|
|
8
|
+
/**
|
|
9
|
+
* Classify an error as a transport reject ("the request never reached a server").
|
|
10
|
+
*
|
|
11
|
+
* Node/undici system codes are checked first (a stable code beats text), then browser wordings.
|
|
12
|
+
*/
|
|
13
|
+
isNetworkRejectError(error: Error): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* If `error` is a transport reject, return an {@link OfflineError} that names `url` and preserves
|
|
16
|
+
* the original as `cause`. Otherwise return `error` UNTOUCHED — a genuine bug keeps its own type
|
|
17
|
+
* and stack, so a defect is never silently relabelled as "offline".
|
|
18
|
+
*/
|
|
19
|
+
toNetworkError(error: Error, url: string): Error;
|
|
20
|
+
/**
|
|
21
|
+
* True if this error (or any error up its `cause` chain, to {@link MAX_CAUSE_DEPTH}) carries a
|
|
22
|
+
* node/undici system code meaning the transport never delivered a response.
|
|
23
|
+
*/
|
|
24
|
+
private hasNodeSystemCode;
|
|
25
|
+
/** True if the error message contains any known browser transport-reject wording. */
|
|
26
|
+
private hasBrowserRejectMessage;
|
|
27
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetworkRejectClassifier = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Centralised classifier for transport rejects — the ONE place in the framework that decides
|
|
6
|
+
* "the request never reached a server" (offline, DNS, connection refused, CORS preflight).
|
|
7
|
+
*
|
|
8
|
+
* Browser-safe: zero node imports, no framework deps beyond {@link OfflineError}. It runs identically
|
|
9
|
+
* in an Angular bundle and on Cloud Run.
|
|
10
|
+
*
|
|
11
|
+
* WHY here and not in each app: the browser-wording list below is inherently incomplete and drifts as
|
|
12
|
+
* engines reword their messages. Kept in one module, an app never writes it, and a new wording is
|
|
13
|
+
* fixed exactly once — here — instead of in every consumer's copy of the same fragile string match.
|
|
14
|
+
*/
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
/**
|
|
17
|
+
* Node/undici system codes that mean the connection never established (or dropped mid-flight before
|
|
18
|
+
* any HTTP response). A real, stable code beats message text, so these are checked FIRST.
|
|
19
|
+
*/
|
|
20
|
+
const NODE_SYSTEM_CODES = new Set([
|
|
21
|
+
'ECONNREFUSED',
|
|
22
|
+
'ENOTFOUND',
|
|
23
|
+
'EAI_AGAIN',
|
|
24
|
+
'ECONNRESET',
|
|
25
|
+
'EPIPE',
|
|
26
|
+
'ETIMEDOUT',
|
|
27
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
28
|
+
'ENETUNREACH',
|
|
29
|
+
'EHOSTUNREACH',
|
|
30
|
+
]);
|
|
31
|
+
/**
|
|
32
|
+
* Browser `fetch` reject wordings. Substring tests, not equality: zone.js (Angular) may append the
|
|
33
|
+
* request hostname to the message. This list is expected to grow as engines/locales reword.
|
|
34
|
+
*/
|
|
35
|
+
const BROWSER_REJECT_MESSAGES = [
|
|
36
|
+
'Failed to fetch',
|
|
37
|
+
'NetworkError when attempting to fetch resource',
|
|
38
|
+
'Load failed',
|
|
39
|
+
'The network connection was lost',
|
|
40
|
+
'loading dynamically imported module',
|
|
41
|
+
'Network request failed',
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* undici's thrown `TypeError: fetch failed` carries the useful system code one or two `cause` levels
|
|
45
|
+
* down, so the code check MUST walk the chain — but a self-referential chain would spin forever, so
|
|
46
|
+
* the walk is depth-capped.
|
|
47
|
+
*/
|
|
48
|
+
const MAX_CAUSE_DEPTH = 5;
|
|
49
|
+
/**
|
|
50
|
+
* Decides whether a thrown error is a transport reject and, if so, mints the typed {@link OfflineError}
|
|
51
|
+
* for it. Stateless and dependency-free, so a caller can `new` it directly on the browser fetch path
|
|
52
|
+
* (instance methods, not static — webpieces wires behaviour into injectable classes, and a static
|
|
53
|
+
* method is just a module-scope function wearing a class as a namespace).
|
|
54
|
+
*/
|
|
55
|
+
class NetworkRejectClassifier {
|
|
56
|
+
/**
|
|
57
|
+
* Classify an error as a transport reject ("the request never reached a server").
|
|
58
|
+
*
|
|
59
|
+
* Node/undici system codes are checked first (a stable code beats text), then browser wordings.
|
|
60
|
+
*/
|
|
61
|
+
isNetworkRejectError(error) {
|
|
62
|
+
return this.hasNodeSystemCode(error) || this.hasBrowserRejectMessage(error);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* If `error` is a transport reject, return an {@link OfflineError} that names `url` and preserves
|
|
66
|
+
* the original as `cause`. Otherwise return `error` UNTOUCHED — a genuine bug keeps its own type
|
|
67
|
+
* and stack, so a defect is never silently relabelled as "offline".
|
|
68
|
+
*/
|
|
69
|
+
toNetworkError(error, url) {
|
|
70
|
+
if (this.isNetworkRejectError(error)) {
|
|
71
|
+
return new errors_1.OfflineError(`Request to ${url} never reached a server (offline / network reject)`, error);
|
|
72
|
+
}
|
|
73
|
+
return error;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* True if this error (or any error up its `cause` chain, to {@link MAX_CAUSE_DEPTH}) carries a
|
|
77
|
+
* node/undici system code meaning the transport never delivered a response.
|
|
78
|
+
*/
|
|
79
|
+
hasNodeSystemCode(error) {
|
|
80
|
+
let current = error;
|
|
81
|
+
for (let depth = 0; depth <= MAX_CAUSE_DEPTH && current !== undefined; depth += 1) {
|
|
82
|
+
const code = current.code;
|
|
83
|
+
if (code !== undefined && NODE_SYSTEM_CODES.has(code)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
// Error.cause is `unknown`; only an Error carries the message/code we can read next, so a
|
|
87
|
+
// non-Error cause (or none) ends the walk. undici's nested reject IS an Error, so this
|
|
88
|
+
// still reaches the ECONNREFUSED it hangs one level down.
|
|
89
|
+
current = current.cause instanceof Error ? current.cause : undefined;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
/** True if the error message contains any known browser transport-reject wording. */
|
|
94
|
+
hasBrowserRejectMessage(error) {
|
|
95
|
+
const message = error.message;
|
|
96
|
+
return BROWSER_REJECT_MESSAGES.some((wording) => message.includes(wording));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.NetworkRejectClassifier = NetworkRejectClassifier;
|
|
100
|
+
//# sourceMappingURL=networkReject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networkReject.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/http/networkReject.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,qCAAwC;AAWxC;;;GAGG;AACH,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACnD,cAAc;IACd,WAAW;IACX,WAAW;IACX,YAAY;IACZ,OAAO;IACP,WAAW;IACX,yBAAyB;IACzB,aAAa;IACb,cAAc;CACjB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,uBAAuB,GAAsB;IAC/C,iBAAiB;IACjB,gDAAgD;IAChD,aAAa;IACb,iCAAiC;IACjC,qCAAqC;IACrC,wBAAwB;CAC3B,CAAC;AAEF;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;GAKG;AACH,MAAa,uBAAuB;IAChC;;;;OAIG;IACH,oBAAoB,CAAC,KAAY;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,KAAY,EAAE,GAAW;QACpC,IAAI,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,IAAI,qBAAY,CAAC,cAAc,GAAG,oDAAoD,EAAE,KAAK,CAAC,CAAC;QAC1G,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;OAGG;IACK,iBAAiB,CAAC,KAAY;QAClC,IAAI,OAAO,GAAsB,KAAK,CAAC;QACvC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,eAAe,IAAI,OAAO,KAAK,SAAS,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAChF,MAAM,IAAI,GAAI,OAAuB,CAAC,IAAI,CAAC;YAC3C,IAAI,IAAI,KAAK,SAAS,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpD,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,0FAA0F;YAC1F,uFAAuF;YACvF,0DAA0D;YAC1D,OAAO,GAAG,OAAO,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QACzE,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,qFAAqF;IAC7E,uBAAuB,CAAC,KAAY;QACxC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,OAAO,uBAAuB,CAAC,IAAI,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACxF,CAAC;CACJ;AA9CD,0DA8CC","sourcesContent":["/**\n * Centralised classifier for transport rejects — the ONE place in the framework that decides\n * \"the request never reached a server\" (offline, DNS, connection refused, CORS preflight).\n *\n * Browser-safe: zero node imports, no framework deps beyond {@link OfflineError}. It runs identically\n * in an Angular bundle and on Cloud Run.\n *\n * WHY here and not in each app: the browser-wording list below is inherently incomplete and drifts as\n * engines reword their messages. Kept in one module, an app never writes it, and a new wording is\n * fixed exactly once — here — instead of in every consumer's copy of the same fragile string match.\n */\nimport { OfflineError } from './errors';\n\n/**\n * The error shape this classifier reads for the node/undici code. `Error.cause` (ES2022) is already\n * on the base type — typed `unknown` there — so we only add the optional `code`; a plain `Error`\n * narrows to this safely since we only ever READ the field.\n */\ninterface CausedError extends Error {\n code?: string;\n}\n\n/**\n * Node/undici system codes that mean the connection never established (or dropped mid-flight before\n * any HTTP response). A real, stable code beats message text, so these are checked FIRST.\n */\nconst NODE_SYSTEM_CODES: ReadonlySet<string> = new Set([\n 'ECONNREFUSED',\n 'ENOTFOUND',\n 'EAI_AGAIN',\n 'ECONNRESET',\n 'EPIPE',\n 'ETIMEDOUT',\n 'UND_ERR_CONNECT_TIMEOUT',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n]);\n\n/**\n * Browser `fetch` reject wordings. Substring tests, not equality: zone.js (Angular) may append the\n * request hostname to the message. This list is expected to grow as engines/locales reword.\n */\nconst BROWSER_REJECT_MESSAGES: readonly string[] = [\n 'Failed to fetch',\n 'NetworkError when attempting to fetch resource',\n 'Load failed',\n 'The network connection was lost',\n 'loading dynamically imported module',\n 'Network request failed',\n];\n\n/**\n * undici's thrown `TypeError: fetch failed` carries the useful system code one or two `cause` levels\n * down, so the code check MUST walk the chain — but a self-referential chain would spin forever, so\n * the walk is depth-capped.\n */\nconst MAX_CAUSE_DEPTH = 5;\n\n/**\n * Decides whether a thrown error is a transport reject and, if so, mints the typed {@link OfflineError}\n * for it. Stateless and dependency-free, so a caller can `new` it directly on the browser fetch path\n * (instance methods, not static — webpieces wires behaviour into injectable classes, and a static\n * method is just a module-scope function wearing a class as a namespace).\n */\nexport class NetworkRejectClassifier {\n /**\n * Classify an error as a transport reject (\"the request never reached a server\").\n *\n * Node/undici system codes are checked first (a stable code beats text), then browser wordings.\n */\n isNetworkRejectError(error: Error): boolean {\n return this.hasNodeSystemCode(error) || this.hasBrowserRejectMessage(error);\n }\n\n /**\n * If `error` is a transport reject, return an {@link OfflineError} that names `url` and preserves\n * the original as `cause`. Otherwise return `error` UNTOUCHED — a genuine bug keeps its own type\n * and stack, so a defect is never silently relabelled as \"offline\".\n */\n toNetworkError(error: Error, url: string): Error {\n if (this.isNetworkRejectError(error)) {\n return new OfflineError(`Request to ${url} never reached a server (offline / network reject)`, error);\n }\n return error;\n }\n\n /**\n * True if this error (or any error up its `cause` chain, to {@link MAX_CAUSE_DEPTH}) carries a\n * node/undici system code meaning the transport never delivered a response.\n */\n private hasNodeSystemCode(error: Error): boolean {\n let current: Error | undefined = error;\n for (let depth = 0; depth <= MAX_CAUSE_DEPTH && current !== undefined; depth += 1) {\n const code = (current as CausedError).code;\n if (code !== undefined && NODE_SYSTEM_CODES.has(code)) {\n return true;\n }\n // Error.cause is `unknown`; only an Error carries the message/code we can read next, so a\n // non-Error cause (or none) ends the walk. undici's nested reject IS an Error, so this\n // still reaches the ECONNREFUSED it hangs one level down.\n current = current.cause instanceof Error ? current.cause : undefined;\n }\n return false;\n }\n\n /** True if the error message contains any known browser transport-reject wording. */\n private hasBrowserRejectMessage(error: Error): boolean {\n const message = error.message;\n return BROWSER_REJECT_MESSAGES.some((wording: string) => message.includes(wording));\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -20,7 +20,8 @@ export { ApiPath, Endpoint, Authentication, AuthenticationConfig, Public, AuthJw
|
|
|
20
20
|
export type { AuthMode, ApiKind, JwtRequirement, EndpointOptions } from './http/decorators';
|
|
21
21
|
export { Secrets, SECRETS } from './http/Secrets';
|
|
22
22
|
export { ValidateImplementation } from './http/validators';
|
|
23
|
-
export { ProtocolError, HttpError, HttpNotFoundError, EndpointNotFoundError, HttpBadRequestError, HttpUnauthorizedError, HttpForbiddenError, HttpTimeoutError, HttpBadGatewayError, HttpGatewayTimeoutError, HttpInternalServerError, HttpVendorError, HttpUserError, ENTITY_NOT_FOUND, WRONG_LOGIN_TYPE, WRONG_LOGIN, NOT_APPROVED, EMAIL_NOT_CONFIRMED, WRONG_DOMAIN, WRONG_COMPANY, NO_REG_CODE, } from './http/errors';
|
|
23
|
+
export { ProtocolError, HttpError, HttpNotFoundError, EndpointNotFoundError, HttpBadRequestError, HttpUnauthorizedError, HttpForbiddenError, HttpTimeoutError, HttpBadGatewayError, HttpGatewayTimeoutError, HttpInternalServerError, HttpTooManyRequestsError, HttpVendorError, HttpUserError, OfflineError, ENTITY_NOT_FOUND, WRONG_LOGIN_TYPE, WRONG_LOGIN, NOT_APPROVED, EMAIL_NOT_CONFIRMED, WRONG_DOMAIN, WRONG_COMPANY, NO_REG_CODE, } from './http/errors';
|
|
24
|
+
export { NetworkRejectClassifier } from './http/networkReject';
|
|
24
25
|
export { InstantDto, DateDto, TimeDto, DateTimeDto, InstantUtil, DateUtil, TimeUtil, DateTimeUtil, } from './http/datetime';
|
|
25
26
|
export { HeaderRegistry } from './http/HeaderRegistry';
|
|
26
27
|
export { ClientRegistry } from './http/ClientRegistry';
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.HttpUnauthorizedError = exports.HttpBadRequestError = exports.EndpointNotFoundError = exports.HttpNotFoundError = exports.HttpError = exports.ProtocolError = exports.SECRETS = exports.Secrets = exports.METADATA_KEYS = exports.RouteMetadata = exports.AuthMeta = exports.validateNoConflictingDecorators = exports.getQueueName = exports.assertPubSubConventions = exports.assertApiKind = exports.getApiKind = exports.assertEveryEndpointHasAuthMode = exports.getAuthMode = exports.getAuthMeta = exports.isApiPath = exports.isFormPost = exports.getEndpointOptions = exports.getEndpoints = exports.getApiPath = exports.Queue = exports.PubSub = exports.Rpc = exports.AuthSharedSecret = exports.AuthOidc = exports.Auth = exports.AuthJwt = exports.Public = exports.AuthenticationConfig = exports.Authentication = exports.Endpoint = exports.ApiPath = exports.GCP_LOG_BUDGET_BYTES = exports.MAX_GCP_LOG_BYTES = exports.LogChunkInfo = exports.LogChunkerImpl = exports.LogChunker = exports.LogManager = exports.ConsoleLoggerFactory = exports.ConsoleLogger = exports.DESIGN_METADATA_KEYS = exports.isDocumentDesign = exports.DocumentDesign = exports.ContextTuple = exports.ContextKey = exports.toError = void 0;
|
|
12
|
-
exports.SerializedError = exports.SerializedMap = exports.RecordSerializer = exports.getDoNotRecordFields = exports.DoNotRecord = exports.RecordedTestCase = exports.RecordedError = exports.RecordedEndpoint = exports.RecorderKeys = exports.ApiCallContextHolder = exports.ApiMethodInfo = exports.LOG_API_CALL_LOGGER_NAME = exports.ApiCallLogNameImpl = exports.ApiCallLogName = exports.ApiCallInfo = exports.LogApiCallImpl = exports.LogApiCall = exports.ContextMgr = exports.WebpiecesCoreHeaders = exports.templateDeriver = exports.WEBPIECES_DEFAULT_FAILURE_CLASSIFIER = exports.WebpiecesDefaultFailureClassifier = exports.KeyedFailureClassifier = exports.ErrorWireForm = exports.ServiceInfo = exports.ClientRegistry = exports.HeaderRegistry = exports.DateTimeUtil = exports.TimeUtil = exports.DateUtil = exports.InstantUtil = 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.HttpUserError = exports.HttpVendorError = exports.HttpInternalServerError = exports.HttpGatewayTimeoutError = exports.HttpBadGatewayError = exports.HttpTimeoutError = exports.HttpForbiddenError = void 0;
|
|
12
|
+
exports.SerializedError = exports.SerializedMap = exports.RecordSerializer = exports.getDoNotRecordFields = exports.DoNotRecord = exports.RecordedTestCase = exports.RecordedError = exports.RecordedEndpoint = exports.RecorderKeys = exports.ApiCallContextHolder = exports.ApiMethodInfo = exports.LOG_API_CALL_LOGGER_NAME = exports.ApiCallLogNameImpl = exports.ApiCallLogName = exports.ApiCallInfo = exports.LogApiCallImpl = exports.LogApiCall = exports.ContextMgr = exports.WebpiecesCoreHeaders = exports.templateDeriver = exports.WEBPIECES_DEFAULT_FAILURE_CLASSIFIER = exports.WebpiecesDefaultFailureClassifier = exports.KeyedFailureClassifier = exports.ErrorWireForm = exports.ServiceInfo = exports.ClientRegistry = exports.HeaderRegistry = exports.DateTimeUtil = exports.TimeUtil = exports.DateUtil = exports.InstantUtil = exports.NetworkRejectClassifier = 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.OfflineError = exports.HttpUserError = exports.HttpVendorError = exports.HttpTooManyRequestsError = exports.HttpInternalServerError = exports.HttpGatewayTimeoutError = exports.HttpBadGatewayError = exports.HttpTimeoutError = exports.HttpForbiddenError = void 0;
|
|
13
13
|
var errorUtils_1 = require("./lib/errorUtils");
|
|
14
14
|
Object.defineProperty(exports, "toError", { enumerable: true, get: function () { return errorUtils_1.toError; } });
|
|
15
15
|
var ContextKey_1 = require("./ContextKey");
|
|
@@ -89,8 +89,10 @@ Object.defineProperty(exports, "HttpTimeoutError", { enumerable: true, get: func
|
|
|
89
89
|
Object.defineProperty(exports, "HttpBadGatewayError", { enumerable: true, get: function () { return errors_1.HttpBadGatewayError; } });
|
|
90
90
|
Object.defineProperty(exports, "HttpGatewayTimeoutError", { enumerable: true, get: function () { return errors_1.HttpGatewayTimeoutError; } });
|
|
91
91
|
Object.defineProperty(exports, "HttpInternalServerError", { enumerable: true, get: function () { return errors_1.HttpInternalServerError; } });
|
|
92
|
+
Object.defineProperty(exports, "HttpTooManyRequestsError", { enumerable: true, get: function () { return errors_1.HttpTooManyRequestsError; } });
|
|
92
93
|
Object.defineProperty(exports, "HttpVendorError", { enumerable: true, get: function () { return errors_1.HttpVendorError; } });
|
|
93
94
|
Object.defineProperty(exports, "HttpUserError", { enumerable: true, get: function () { return errors_1.HttpUserError; } });
|
|
95
|
+
Object.defineProperty(exports, "OfflineError", { enumerable: true, get: function () { return errors_1.OfflineError; } });
|
|
94
96
|
// Error subtype constants
|
|
95
97
|
Object.defineProperty(exports, "ENTITY_NOT_FOUND", { enumerable: true, get: function () { return errors_1.ENTITY_NOT_FOUND; } });
|
|
96
98
|
Object.defineProperty(exports, "WRONG_LOGIN_TYPE", { enumerable: true, get: function () { return errors_1.WRONG_LOGIN_TYPE; } });
|
|
@@ -100,6 +102,8 @@ Object.defineProperty(exports, "EMAIL_NOT_CONFIRMED", { enumerable: true, get: f
|
|
|
100
102
|
Object.defineProperty(exports, "WRONG_DOMAIN", { enumerable: true, get: function () { return errors_1.WRONG_DOMAIN; } });
|
|
101
103
|
Object.defineProperty(exports, "WRONG_COMPANY", { enumerable: true, get: function () { return errors_1.WRONG_COMPANY; } });
|
|
102
104
|
Object.defineProperty(exports, "NO_REG_CODE", { enumerable: true, get: function () { return errors_1.NO_REG_CODE; } });
|
|
105
|
+
var networkReject_1 = require("./http/networkReject");
|
|
106
|
+
Object.defineProperty(exports, "NetworkRejectClassifier", { enumerable: true, get: function () { return networkReject_1.NetworkRejectClassifier; } });
|
|
103
107
|
// Date/Time DTOs and Utilities (inspired by Java Time / JSR-310)
|
|
104
108
|
var datetime_1 = require("./http/datetime");
|
|
105
109
|
Object.defineProperty(exports, "InstantUtil", { enumerable: true, get: function () { return datetime_1.InstantUtil; } });
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-util/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;AAEH,+CAA2C;AAAlC,qGAAA,OAAO,OAAA;AAChB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAErB,+EAA+E;AAC/E,kFAAkF;AAClF,yCAAyC;AACzC,mDAA0F;AAAjF,gHAAA,cAAc,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAO/D,yDAAwD;AAA/C,8GAAA,aAAa,OAAA;AACtB,uEAAsE;AAA7D,4HAAA,oBAAoB,OAAA;AAC7B,mDAAkD;AAAzC,wGAAA,UAAU,OAAA;AACnB,mDAAyH;AAAhH,wGAAA,UAAU,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AAE1F,8DAA8D;AAC9D,sEAAsE;AACtE,sEAAsE;AACtE,uEAAuE;AACvE,kEAAkE;AAElE,4BAA4B;AAC5B,gDA+B2B;AA9BvB,qGAAA,OAAO,OAAA;AACP,sGAAA,QAAQ,OAAA;AACR,4GAAA,cAAc,OAAA;AACd,kHAAA,oBAAoB,OAAA;AACpB,mEAAmE;AACnE,oGAAA,MAAM,OAAA;AACN,qGAAA,OAAO,OAAA;AACP,kGAAA,IAAI,OAAA;AACJ,sGAAA,QAAQ,OAAA;AACR,8GAAA,gBAAgB,OAAA;AAChB,sDAAsD;AACtD,iGAAA,GAAG,OAAA;AACH,oGAAA,MAAM,OAAA;AACN,mGAAA,KAAK,OAAA;AACL,wGAAA,UAAU,OAAA;AACV,0GAAA,YAAY,OAAA;AACZ,gHAAA,kBAAkB,OAAA;AAClB,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,yGAAA,WAAW,OAAA;AACX,yGAAA,WAAW,OAAA;AACX,4HAAA,8BAA8B,OAAA;AAC9B,wGAAA,UAAU,OAAA;AACV,2GAAA,aAAa,OAAA;AACb,qHAAA,uBAAuB,OAAA;AACvB,0GAAA,YAAY,OAAA;AACZ,6HAAA,+BAA+B,OAAA;AAC/B,sGAAA,QAAQ,OAAA;AACR,2GAAA,aAAa,OAAA;AACb,2GAAA,aAAa,OAAA;AAGjB,4FAA4F;AAC5F,0CAAkD;AAAzC,kGAAA,OAAO,OAAA;AAAE,kGAAA,OAAO,OAAA;AAKzB,cAAc;AACd,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-util/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;AAEH,+CAA2C;AAAlC,qGAAA,OAAO,OAAA;AAChB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAErB,+EAA+E;AAC/E,kFAAkF;AAClF,yCAAyC;AACzC,mDAA0F;AAAjF,gHAAA,cAAc,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAO/D,yDAAwD;AAA/C,8GAAA,aAAa,OAAA;AACtB,uEAAsE;AAA7D,4HAAA,oBAAoB,OAAA;AAC7B,m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B,sGAAsG;AACtG,gDAA+D;AAAtD,wGAAA,UAAU,OAAA;AAAE,4GAAA,cAAc,OAAA;AAEnC,yFAAyF;AACzF,kGAAkG;AAClG,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AAEpB,oGAAoG;AACpG,wDAAqG;AAA5F,gHAAA,cAAc,OAAA;AAAE,oHAAA,kBAAkB,OAAA;AAAE,0HAAA,wBAAwB,OAAA;AACrE,sDAAqD;AAA5C,8GAAA,aAAa,OAAA;AAEtB,wDAA6D;AAApD,sHAAA,oBAAoB,OAAA;AAG7B,iFAAiF;AACjF,qEAAkF;AAAvD,gHAAA,YAAY,OAAA;AACvC,qEAAqG;AAA5F,oHAAA,gBAAgB,OAAA;AAAE,iHAAA,aAAa,OAAA;AAAE,oHAAA,gBAAgB,OAAA;AAC1D,2DAAgF;AAAvE,0GAAA,WAAW,OAAA;AAAE,mHAAA,oBAAoB,OAAA;AAC1C,qEAAoG;AAA3F,oHAAA,gBAAgB,OAAA;AAAE,iHAAA,aAAa,OAAA;AAAE,mHAAA,eAAe,OAAA","sourcesContent":["/**\n * @webpieces/core-util\n *\n * Utility functions for WebPieces applications.\n * This package works in both browser and Node.js environments.\n *\n * @packageDocumentation\n */\n\nexport { toError } from './lib/errorUtils';\nexport { ContextKey } from './ContextKey';\nexport { ContextTuple } from './ContextTuple';\n\n// @DocumentDesign — DI-design-root marker. Applies to ANY project kind (server\n// controllers AND library impl classes), so it lives here (browser + Node) rather\n// than in a server-only routing package.\nexport { DocumentDesign, isDocumentDesign, DESIGN_METADATA_KEYS } from './DocumentDesign';\n\n// Logging (merged from former @webpieces/wp-logging).\n// Pluggable logging interface + a browser-safe console default; apps plug in\n// bunyan/winston/pino/etc. via LogManager.setFactory(...). Browser + Node.\nexport type { Logger, LogLevel } from './logging/Logger';\nexport type { LoggerFactory } from './logging/LoggerFactory';\nexport { ConsoleLogger } from './logging/ConsoleLogger';\nexport { ConsoleLoggerFactory } from './logging/ConsoleLoggerFactory';\nexport { LogManager } from './logging/LogManager';\nexport { LogChunker, LogChunkerImpl, LogChunkInfo, MAX_GCP_LOG_BYTES, GCP_LOG_BUDGET_BYTES } from './logging/LogChunker';\n\n// HTTP API contract (merged from former @webpieces/http-api).\n// Shared HTTP API definition consumed by both client and server: REST\n// decorators, the HttpError hierarchy, datetime DTOs, platform-header\n// registry/readers, ValidateImplementation, and the test-case recorder\n// contract. Pure definitions — express-free, browser + Node safe.\n\n// API definition decorators\nexport {\n ApiPath,\n Endpoint,\n Authentication,\n AuthenticationConfig,\n // Auth mode decorators (clean service-to-service + user JWT model)\n Public,\n AuthJwt,\n Auth,\n AuthOidc,\n AuthSharedSecret,\n // API kind (RPC vs PubSub/Cloud Tasks) + queue naming\n Rpc,\n PubSub,\n Queue,\n getApiPath,\n getEndpoints,\n getEndpointOptions,\n isFormPost,\n isApiPath,\n getAuthMeta,\n getAuthMode,\n assertEveryEndpointHasAuthMode,\n getApiKind,\n assertApiKind,\n assertPubSubConventions,\n getQueueName,\n validateNoConflictingDecorators,\n AuthMeta,\n RouteMetadata,\n METADATA_KEYS,\n} from './http/decorators';\nexport type { AuthMode, ApiKind, JwtRequirement, EndpointOptions } from './http/decorators';\n// Client-side shared-secret store (the value THIS service sends per @AuthSharedSecret key).\nexport { Secrets, SECRETS } from './http/Secrets';\n\n// Type validators\nexport { ValidateImplementation } from './http/validators';\n\n// HTTP errors\nexport {\n ProtocolError,\n HttpError,\n HttpNotFoundError,\n EndpointNotFoundError,\n HttpBadRequestError,\n HttpUnauthorizedError,\n HttpForbiddenError,\n HttpTimeoutError,\n HttpBadGatewayError,\n HttpGatewayTimeoutError,\n HttpInternalServerError,\n HttpTooManyRequestsError,\n HttpVendorError,\n HttpUserError,\n OfflineError,\n // Error subtype constants\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 './http/errors';\n\nexport { NetworkRejectClassifier } from './http/networkReject';\n\n// Date/Time DTOs and Utilities (inspired by Java Time / JSR-310)\nexport {\n InstantDto,\n DateDto,\n TimeDto,\n DateTimeDto,\n InstantUtil,\n DateUtil,\n TimeUtil,\n DateTimeUtil,\n} from './http/datetime';\n\n// Context keys + registry (the global magic-context header system)\nexport { HeaderRegistry } from './http/HeaderRegistry';\nexport { ClientRegistry } from './http/ClientRegistry';\nexport type { ServiceUrlDeriver } from './http/ClientRegistry';\n\n// \"What service am I\" — set once at startup, read by the logging backends and by\n// RequestContextHeaders (to stamp requestIdSource on ids this service mints).\nexport { ServiceInfo } from './http/ServiceInfo';\n// Pluggable, bidirectional error translation (app exception <-> wire form). Registered on\n// ClientRegistry at startup; consulted before the built-in webpieces mapping on BOTH sides.\nexport { ErrorWireForm } from './http/ErrorTranslation';\nexport type { ErrorTranslation } from './http/ErrorTranslation';\n// Pluggable per-client failure classification (is a thrown API-call error a real failure or an\n// expected non-failure?). Registered on ClientRegistry at startup; consulted by LogApiCall.\nexport type { FailureClassifier } from './http/FailureClassifier';\nexport { KeyedFailureClassifier } from './http/FailureClassifier';\nexport {\n WebpiecesDefaultFailureClassifier,\n WEBPIECES_DEFAULT_FAILURE_CLASSIFIER,\n} from './http/WebpiecesDefaultFailureClassifier';\nexport { templateDeriver } from './http/templateDeriver';\nexport { WebpiecesCoreHeaders } from './http/WebpiecesCoreHeaders';\nexport { ContextReader } from './http/ContextReader';\n\n// BROWSER-ONLY outbound-header propagation (app-held store + registry -> outbound HTTP headers).\n// Only @webpieces/http-client-browser may name it; the server reads RequestContext directly via\n// RequestContextHeaders in the Node-only @webpieces/core-context.\nexport { ContextMgr } from './http/ContextMgr';\n\n// API-call logging helper (uses LogManager above). Singleton: use the LogApiCall constant, not `new`.\nexport { LogApiCall, LogApiCallImpl } from './http/LogApiCall';\n\n// The structured `api` tag + the context-writer seam LogApiCall stamps through. The Node\n// RequestContext-backed impl is installed by @webpieces/core-context; the browser gets the no-op.\nexport { ApiCallInfo } from './http/ApiCallInfo';\nexport type { ApiType, ApiResult } from './http/ApiCallInfo';\n// Console-render bridge: turns LogApiCall's [LogApiCall] bracket into [API.{side}.{phase}] locally.\nexport { ApiCallLogName, ApiCallLogNameImpl, LOG_API_CALL_LOGGER_NAME } from './http/ApiCallLogName';\nexport { ApiMethodInfo } from './http/ApiMethodInfo';\nexport type { ApiSide } from './http/ApiMethodInfo';\nexport { ApiCallContextHolder } from './http/ApiCallContext';\nexport type { ApiCallContext } from './http/ApiCallContext';\n\n// Test-case recording contract (impl lives in http-server; hooks in http-client)\nexport { TestCaseRecorder, RecorderKeys } from './http/recorder/TestCaseRecorder';\nexport { RecordedEndpoint, RecordedError, RecordedTestCase } from './http/recorder/RecordedEndpoint';\nexport { DoNotRecord, getDoNotRecordFields } from './http/recorder/DoNotRecord';\nexport { RecordSerializer, SerializedMap, SerializedError } from './http/recorder/RecordSerializer';\n"]}
|