@kanjijs/common 0.2.0-beta.8 → 0.3.0-beta.1
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/constants.d.ts +71 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +14 -0
- package/package.json +9 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard Context Keys for Kanjijs Framework
|
|
3
|
+
*
|
|
4
|
+
* These keys are used to store and retrieve values from the Hono context
|
|
5
|
+
* in a standardized way across all Kanjijs packages.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { CONTEXT_KEYS } from "@kanjijs/common";
|
|
10
|
+
*
|
|
11
|
+
* // Set principal in auth middleware
|
|
12
|
+
* c.set(CONTEXT_KEYS.AUTH_PRINCIPAL, principal);
|
|
13
|
+
*
|
|
14
|
+
* // Read principal in authz middleware
|
|
15
|
+
* const principal = c.get(CONTEXT_KEYS.AUTH_PRINCIPAL);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const CONTEXT_KEYS: {
|
|
19
|
+
/**
|
|
20
|
+
* Authenticated user ID
|
|
21
|
+
* @example "user_123"
|
|
22
|
+
*/
|
|
23
|
+
readonly AUTH_USER: "kanji.auth.user";
|
|
24
|
+
/**
|
|
25
|
+
* Session ID
|
|
26
|
+
* @example "session_abc"
|
|
27
|
+
*/
|
|
28
|
+
readonly AUTH_SESSION: "kanji.auth.session";
|
|
29
|
+
/**
|
|
30
|
+
* User roles (array of strings)
|
|
31
|
+
* @example ["admin", "editor"]
|
|
32
|
+
*/
|
|
33
|
+
readonly AUTH_ROLES: "kanji.auth.roles";
|
|
34
|
+
/**
|
|
35
|
+
* User scopes/permissions (array of strings)
|
|
36
|
+
* @example ["posts:read", "posts:write"]
|
|
37
|
+
*/
|
|
38
|
+
readonly AUTH_SCOPES: "kanji.auth.scopes";
|
|
39
|
+
/**
|
|
40
|
+
* Normalized Principal object
|
|
41
|
+
* Contains userId, sessionId, roles, scopes, claims
|
|
42
|
+
* @see Principal from @kanjijs/security
|
|
43
|
+
*/
|
|
44
|
+
readonly AUTH_PRINCIPAL: "kanji.auth.principal";
|
|
45
|
+
/**
|
|
46
|
+
* Authorization decision cache (Map)
|
|
47
|
+
* Stores decisions per request to avoid re-evaluation
|
|
48
|
+
* @example Map<string, Decision>
|
|
49
|
+
*/
|
|
50
|
+
readonly AUTHZ_CACHE: "kanji.authz.cache";
|
|
51
|
+
/**
|
|
52
|
+
* Last authorization decision
|
|
53
|
+
* Useful for debugging and logging
|
|
54
|
+
* @see Decision from @kanjijs/security
|
|
55
|
+
*/
|
|
56
|
+
readonly AUTHZ_DECISION: "kanji.authz.decision";
|
|
57
|
+
/**
|
|
58
|
+
* Request ID for tracing
|
|
59
|
+
* @example "req_abc123"
|
|
60
|
+
*/
|
|
61
|
+
readonly REQUEST_ID: "kanji.requestId";
|
|
62
|
+
/**
|
|
63
|
+
* Validated request data (from contract validation)
|
|
64
|
+
* @example { body: {...}, query: {...} }
|
|
65
|
+
*/
|
|
66
|
+
readonly VALIDATED: "kanji.validated";
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Type-safe context key type
|
|
70
|
+
*/
|
|
71
|
+
export type ContextKey = (typeof CONTEXT_KEYS)[keyof typeof CONTEXT_KEYS];
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/constants.ts
|
|
3
|
+
var CONTEXT_KEYS = {
|
|
4
|
+
AUTH_USER: "kanji.auth.user",
|
|
5
|
+
AUTH_SESSION: "kanji.auth.session",
|
|
6
|
+
AUTH_ROLES: "kanji.auth.roles",
|
|
7
|
+
AUTH_SCOPES: "kanji.auth.scopes",
|
|
8
|
+
AUTH_PRINCIPAL: "kanji.auth.principal",
|
|
9
|
+
AUTHZ_CACHE: "kanji.authz.cache",
|
|
10
|
+
AUTHZ_DECISION: "kanji.authz.decision",
|
|
11
|
+
REQUEST_ID: "kanji.requestId",
|
|
12
|
+
VALIDATED: "kanji.validated"
|
|
13
|
+
};
|
|
14
|
+
|
|
2
15
|
// src/index.ts
|
|
3
16
|
var COMMON_VERSION = "0.2.0-beta.1";
|
|
4
17
|
export {
|
|
18
|
+
CONTEXT_KEYS,
|
|
5
19
|
COMMON_VERSION
|
|
6
20
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanjijs/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
"LICENSE"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "bun build src/index.ts --outdir dist --target bun"
|
|
13
|
+
"build": "bun build src/index.ts --outdir dist --target bun && bunx tsc --emitDeclarationOnly --declaration --outDir dist -p tsconfig.build.json"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@kanjijs/core": "^0.2.0-beta.56"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"bun-types": "latest",
|
|
20
|
+
"@kanjijs/core": "^0.2.0-beta.56"
|
|
14
21
|
}
|
|
15
22
|
}
|