@lssm/lib.error 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217072406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/appError.js CHANGED
@@ -1 +1,20 @@
1
- var e=class extends Error{constructor(e,t,n){super(t),this.code=e,this.details=n,Object.setPrototypeOf(this,new.target.prototype),this.name=`AppError`}};function t(t){return t instanceof e}export{e as AppError,t as isAppError};
1
+ //#region src/appError.ts
2
+ /**
3
+ * Generic application error with code and optional details.
4
+ */
5
+ var AppError = class extends Error {
6
+ constructor(code, message, details) {
7
+ super(message);
8
+ this.code = code;
9
+ this.details = details;
10
+ Object.setPrototypeOf(this, new.target.prototype);
11
+ this.name = "AppError";
12
+ }
13
+ };
14
+ /** Type guard to detect AppError */
15
+ function isAppError(err) {
16
+ return err instanceof AppError;
17
+ }
18
+
19
+ //#endregion
20
+ export { AppError, isAppError };
package/dist/codes.js CHANGED
@@ -1 +1,22 @@
1
- let e=function(e){return e.UNAUTHENTICATED=`UNAUTHENTICATED`,e.FORBIDDEN=`FORBIDDEN`,e.NOT_FOUND=`NOT_FOUND`,e.INVALID_INPUT=`INVALID_INPUT`,e.CONFLICT=`CONFLICT`,e.RATE_LIMITED=`RATE_LIMITED`,e.SERVER_ERROR=`SERVER_ERROR`,e.POLICY_DENIED=`POLICY_DENIED`,e}({});function t(t){return Object.values(e).includes(t)}export{e as ErrorCode,t as isKnownErrorCode};
1
+ //#region src/codes.ts
2
+ /**
3
+ * Centralised error codes used across services.
4
+ * Extend this enum to add more domain-specific codes.
5
+ */
6
+ let ErrorCode = /* @__PURE__ */ function(ErrorCode$1) {
7
+ ErrorCode$1["UNAUTHENTICATED"] = "UNAUTHENTICATED";
8
+ ErrorCode$1["FORBIDDEN"] = "FORBIDDEN";
9
+ ErrorCode$1["NOT_FOUND"] = "NOT_FOUND";
10
+ ErrorCode$1["INVALID_INPUT"] = "INVALID_INPUT";
11
+ ErrorCode$1["CONFLICT"] = "CONFLICT";
12
+ ErrorCode$1["RATE_LIMITED"] = "RATE_LIMITED";
13
+ ErrorCode$1["SERVER_ERROR"] = "SERVER_ERROR";
14
+ ErrorCode$1["POLICY_DENIED"] = "POLICY_DENIED";
15
+ return ErrorCode$1;
16
+ }({});
17
+ function isKnownErrorCode(code) {
18
+ return Object.values(ErrorCode).includes(code);
19
+ }
20
+
21
+ //#endregion
22
+ export { ErrorCode, isKnownErrorCode };
package/dist/http.js CHANGED
@@ -1 +1,24 @@
1
- import{ErrorCode as e}from"./codes.js";function t(t){switch(t){case e.UNAUTHENTICATED:return 401;case e.FORBIDDEN:case e.POLICY_DENIED:return 403;case e.NOT_FOUND:return 404;case e.INVALID_INPUT:return 400;case e.CONFLICT:return 409;case e.RATE_LIMITED:return 429;default:return 500}}export{t as httpStatus};
1
+ import { ErrorCode } from "./codes.js";
2
+
3
+ //#region src/http.ts
4
+ /**
5
+ * Map known error codes to HTTP status codes.
6
+ */
7
+ function httpStatus(code) {
8
+ switch (code) {
9
+ case ErrorCode.UNAUTHENTICATED: return 401;
10
+ case ErrorCode.FORBIDDEN:
11
+ case ErrorCode.POLICY_DENIED: return 403;
12
+ case ErrorCode.NOT_FOUND: return 404;
13
+ case ErrorCode.INVALID_INPUT: return 400;
14
+ case ErrorCode.CONFLICT: return 409;
15
+ case ErrorCode.RATE_LIMITED: return 429;
16
+ default: return 500;
17
+ }
18
+ }
19
+ /**
20
+ * Convert AppError or unknown error into a Problem JSON response body and status code.
21
+ */
22
+
23
+ //#endregion
24
+ export { httpStatus };
package/dist/index.js CHANGED
@@ -1 +1,5 @@
1
- import{ErrorCode as e,isKnownErrorCode as t}from"./codes.js";import{AppError as n,isAppError as r}from"./appError.js";import{httpStatus as i}from"./http.js";export{n as AppError,e as ErrorCode,i as httpStatus,r as isAppError,t as isKnownErrorCode};
1
+ import { ErrorCode, isKnownErrorCode } from "./codes.js";
2
+ import { AppError, isAppError } from "./appError.js";
3
+ import { httpStatus } from "./http.js";
4
+
5
+ export { AppError, ErrorCode, httpStatus, isAppError, isKnownErrorCode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lssm/lib.error",
3
- "version": "0.0.0-canary-20251217063201",
3
+ "version": "0.0.0-canary-20251217072406",
4
4
  "scripts": {
5
5
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
6
6
  "publish:pkg:canary": "bun publish:pkg --tag canary",
@@ -14,7 +14,8 @@
14
14
  "lint:check": "eslint src"
15
15
  },
16
16
  "devDependencies": {
17
- "@lssm/tool.typescript": "0.0.0-canary-20251217063201",
17
+ "@lssm/tool.tsdown": "0.0.0-canary-20251217072406",
18
+ "@lssm/tool.typescript": "0.0.0-canary-20251217072406",
18
19
  "tsdown": "^0.17.4",
19
20
  "typescript": "^5.9.3"
20
21
  },