@zeroxsolutions/server 0.3.2 → 0.3.3
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/CHANGELOG.md +11 -0
- package/dist/error-handler.d.ts +2 -2
- package/dist/error-handler.d.ts.map +1 -1
- package/dist/error-handler.js +17 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/permission-refused.d.ts +13 -0
- package/dist/permission-refused.d.ts.map +1 -0
- package/dist/permission-refused.js +16 -0
- package/dist/unauthenticated.d.ts +11 -0
- package/dist/unauthenticated.d.ts.map +1 -0
- package/dist/unauthenticated.js +13 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# @zeroxsolutions/server@0.3.3 (2026-09-18)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **server:** answer a guard's refusal from the one error handler ([d4ae306](https://github.com/zeroxsolutions/zeroxsolutions/commit/d4ae306))
|
|
6
|
+
|
|
7
|
+
### ❤️ Thank You
|
|
8
|
+
|
|
9
|
+
- Claude Opus 5 (1M context)
|
|
10
|
+
- Lương Văn Tú
|
|
11
|
+
|
|
1
12
|
## 0.3.2 (2026-09-18)
|
|
2
13
|
|
|
3
14
|
This was a version bump only for @zeroxsolutions/server to align it with other projects, there were no code changes.
|
package/dist/error-handler.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export interface ErrorHandlerOptions extends SurfaceVocabulary {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The one central `onError` a transport installs, rendering every failure as one `application/vnd.api+json`
|
|
19
|
-
* `errors[]` document. It asks, in order: `resolve`, then a
|
|
20
|
-
* {@link JsonApiError} as thrown, then the HTTP status alone.
|
|
19
|
+
* `errors[]` document. It asks, in order: `resolve`, then a guard's own refusal, then a request the validation
|
|
20
|
+
* hook rejected, then a {@link JsonApiError} as thrown, then the HTTP status alone.
|
|
21
21
|
*
|
|
22
22
|
* Every answer is written to the log before it goes out, at the level its status class decides: a 5xx at error,
|
|
23
23
|
* because this side went wrong, anything else at warn, because the request was refused. Without the line, a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAGlD,OAAO,EAOL,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAGlD,OAAO,EAOL,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAqCjE,iGAAiG;AACjG,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D;;;;OAIG;IACH,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,uGAAuG;IACvG,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,KAAK,aAAa,GAAG,SAAS,CAAC;IAChE,0GAA0G;IAC1G,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACvD;AA2BD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAiC7E"}
|
package/dist/error-handler.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getLogger } from '@logtape/logtape';
|
|
2
2
|
import { HTTPException } from 'hono/http-exception';
|
|
3
3
|
import { BASE_ERROR_CODES, JsonApiError, JSON_API_MEDIA_TYPE, toErrorDocument, toErrorObject, } from '@zeroxsolutions/response';
|
|
4
|
+
import { PermissionRefused } from './permission-refused.js';
|
|
4
5
|
import { RequestInvalid } from './request-invalid.js';
|
|
6
|
+
import { Unauthenticated } from './unauthenticated.js';
|
|
5
7
|
// The `code` and `title` each HTTP status is answered with, from the first entry the base registry gives it.
|
|
6
8
|
const META_BY_STATUS = new Map();
|
|
7
9
|
for (const [name, meta] of Object.entries(BASE_ERROR_CODES)) {
|
|
@@ -22,13 +24,21 @@ function errorObjectByStatus(err, status, namespace) {
|
|
|
22
24
|
...(detail && detail !== meta.title ? { detail } : {}),
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
|
-
// Asks each step of the dispatch in turn: `resolve`, a request the validation hook rejected, a
|
|
26
|
-
// thrown, the HTTP status alone.
|
|
27
|
+
// Asks each step of the dispatch in turn: `resolve`, a guard's refusal, a request the validation hook rejected, a
|
|
28
|
+
// `JsonApiError` as thrown, the HTTP status alone.
|
|
27
29
|
function claimError(err, c, options) {
|
|
28
30
|
const resolved = options.resolve?.(err, c);
|
|
29
31
|
if (resolved) {
|
|
30
32
|
return { claimedBy: 'resolve', resolved };
|
|
31
33
|
}
|
|
34
|
+
if (err instanceof Unauthenticated) {
|
|
35
|
+
const error = { status: '401', code: `${options.namespace}.unauthenticated`, title: 'Unauthenticated' };
|
|
36
|
+
return { claimedBy: 'auth', resolved: { status: 401, errors: [error] } };
|
|
37
|
+
}
|
|
38
|
+
if (err instanceof PermissionRefused) {
|
|
39
|
+
const error = { status: '403', code: `${options.namespace}.forbidden`, title: 'Forbidden' };
|
|
40
|
+
return { claimedBy: 'auth', resolved: { status: 403, errors: [error] }, logged: { permissions: err.permissions } };
|
|
41
|
+
}
|
|
32
42
|
if (err instanceof RequestInvalid) {
|
|
33
43
|
return { claimedBy: 'validation', resolved: { status: err.status, errors: err.errors } };
|
|
34
44
|
}
|
|
@@ -40,8 +50,8 @@ function claimError(err, c, options) {
|
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
* The one central `onError` a transport installs, rendering every failure as one `application/vnd.api+json`
|
|
43
|
-
* `errors[]` document. It asks, in order: `resolve`, then a
|
|
44
|
-
* {@link JsonApiError} as thrown, then the HTTP status alone.
|
|
53
|
+
* `errors[]` document. It asks, in order: `resolve`, then a guard's own refusal, then a request the validation
|
|
54
|
+
* hook rejected, then a {@link JsonApiError} as thrown, then the HTTP status alone.
|
|
45
55
|
*
|
|
46
56
|
* Every answer is written to the log before it goes out, at the level its status class decides: a 5xx at error,
|
|
47
57
|
* because this side went wrong, anything else at warn, because the request was refused. Without the line, a
|
|
@@ -52,8 +62,10 @@ export function createErrorHandler(options) {
|
|
|
52
62
|
return (err, c) => {
|
|
53
63
|
const requestId = options.requestId?.(c);
|
|
54
64
|
const stamp = (e) => (requestId && !e.id ? { ...e, id: requestId } : e);
|
|
55
|
-
const { claimedBy, resolved } = claimError(err, c, options);
|
|
65
|
+
const { claimedBy, resolved, logged } = claimError(err, c, options);
|
|
56
66
|
const line = {
|
|
67
|
+
// First, so a step's own facts can never take the place of the ones every line carries.
|
|
68
|
+
...logged,
|
|
57
69
|
// Undefined where a transport never mounted `requestId()` - minting one here is a second id for one request.
|
|
58
70
|
requestId: requestId ?? c.get('requestId'),
|
|
59
71
|
method: c.req.method,
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,7 @@ export { createEnvironment, type EnvironmentOptions } from './environment.js';
|
|
|
5
5
|
export type { SurfaceVocabulary } from './surface-vocabulary.js';
|
|
6
6
|
export { jsonApiContentNegotiation } from './content-negotiation.js';
|
|
7
7
|
export { createErrorHandler, type ErrorHandlerOptions } from './error-handler.js';
|
|
8
|
+
export { PermissionRefused } from './permission-refused.js';
|
|
9
|
+
export { Unauthenticated } from './unauthenticated.js';
|
|
8
10
|
export { createValidationHook } from './validation-hook.js';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,6 @@
|
|
|
4
4
|
export { createEnvironment } from './environment.js';
|
|
5
5
|
export { jsonApiContentNegotiation } from './content-negotiation.js';
|
|
6
6
|
export { createErrorHandler } from './error-handler.js';
|
|
7
|
+
export { PermissionRefused } from './permission-refused.js';
|
|
8
|
+
export { Unauthenticated } from './unauthenticated.js';
|
|
7
9
|
export { createValidationHook } from './validation-hook.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A caller who is authenticated and may not perform what the route requires, thrown by the authorization
|
|
3
|
+
* guard so the app's one `onError` renders and logs it.
|
|
4
|
+
*
|
|
5
|
+
* `permissions` is what the route asked for, never who asked: the log needs it to say which guard refused,
|
|
6
|
+
* and the answer withholds it, because a 403 naming the resource draws the permission map for the caller
|
|
7
|
+
* who just failed it.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PermissionRefused extends Error {
|
|
10
|
+
readonly permissions: Readonly<Record<string, readonly string[]>>;
|
|
11
|
+
constructor(permissions: Readonly<Record<string, readonly string[]>>);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=permission-refused.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-refused.d.ts","sourceRoot":"","sources":["../src/permission-refused.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC9B,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;gBAAxD,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;CAI9E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A caller who is authenticated and may not perform what the route requires, thrown by the authorization
|
|
3
|
+
* guard so the app's one `onError` renders and logs it.
|
|
4
|
+
*
|
|
5
|
+
* `permissions` is what the route asked for, never who asked: the log needs it to say which guard refused,
|
|
6
|
+
* and the answer withholds it, because a 403 naming the resource draws the permission map for the caller
|
|
7
|
+
* who just failed it.
|
|
8
|
+
*/
|
|
9
|
+
export class PermissionRefused extends Error {
|
|
10
|
+
permissions;
|
|
11
|
+
constructor(permissions) {
|
|
12
|
+
super('The caller may not perform every action this route requires');
|
|
13
|
+
this.permissions = permissions;
|
|
14
|
+
this.name = 'PermissionRefused';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request that resolved no caller, thrown by whatever guard establishes identity so the app's one
|
|
3
|
+
* `onError` renders and logs it.
|
|
4
|
+
*
|
|
5
|
+
* A guard that answers the request itself writes a second spelling of 401 per surface, and the two drift:
|
|
6
|
+
* one says `unauthenticated`, the next says `unauthorized`, for the same refusal.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Unauthenticated extends Error {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unauthenticated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticated.d.ts","sourceRoot":"","sources":["../src/unauthenticated.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,SAAgD;CAIpE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request that resolved no caller, thrown by whatever guard establishes identity so the app's one
|
|
3
|
+
* `onError` renders and logs it.
|
|
4
|
+
*
|
|
5
|
+
* A guard that answers the request itself writes a second spelling of 401 per surface, and the two drift:
|
|
6
|
+
* one says `unauthenticated`, the next says `unauthorized`, for the same refusal.
|
|
7
|
+
*/
|
|
8
|
+
export class Unauthenticated extends Error {
|
|
9
|
+
constructor(message = 'The request carries no authenticated caller') {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'Unauthenticated';
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroxsolutions/server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"tslib": "^2.3.0",
|
|
24
|
-
"@zeroxsolutions/
|
|
25
|
-
"@zeroxsolutions/
|
|
24
|
+
"@zeroxsolutions/jsonapi": "0.11.1",
|
|
25
|
+
"@zeroxsolutions/response": "0.12.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@hono/zod-openapi": "^1.0.0",
|