@open-kingdom/shared-backend-util-rbac 0.0.2-18 → 0.0.2-21

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/README.md CHANGED
@@ -19,6 +19,24 @@ providers: [
19
19
  ];
20
20
  ```
21
21
 
22
+ ### External identity (embedded hosts)
23
+
24
+ The identity contract every OpenKingdom controller relies on is just
25
+ `req.user: { id: number; email?: string }` (`AuthenticatedUser` / `AuthenticatedRequest`,
26
+ exported here). Hosts with their own auth perimeter register NO OpenKingdom guards and stamp
27
+ that shape from their own middleware:
28
+
29
+ ```typescript
30
+ app.use((req, res, next) => {
31
+ req.user = { id: localUserId, email }; // verified by the host's own auth
32
+ next();
33
+ });
34
+ ```
35
+
36
+ `@RequirePermission` decorators are inert without `PermissionGuard`. A host that wants the
37
+ guard's RBAC enforcement keeps it and binds `ROLE_RESOLVER` to its own `RoleResolver`
38
+ implementation instead of `UserRolesService`.
39
+
22
40
  ## Usage
23
41
 
24
42
  ```typescript
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { Public, IS_PUBLIC_KEY } from './lib/decorators/public.decorator.js';
3
3
  export { PermissionGuard } from './lib/guards/permission.guard.js';
4
4
  export { ROLE_RESOLVER } from './lib/role-resolver.js';
5
5
  export type { RoleResolver } from './lib/role-resolver.js';
6
+ export type { AuthenticatedUser, AuthenticatedRequest, } from './lib/authenticated-request.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EACV,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The canonical identity contract between hosts and OpenKingdom backend
3
+ * packages.
4
+ *
5
+ * Every OpenKingdom controller that needs the caller reads `req.user.id`
6
+ * (record ownership) — nothing more. In the standard stack, `JwtAuthGuard`
7
+ * populates `req.user` and `PermissionGuard` decorates it with
8
+ * `role`/`permissions`. In EMBEDDED mode, the host registers neither guard and
9
+ * instead stamps this shape from its own auth middleware:
10
+ *
11
+ * ```ts
12
+ * app.use((req, res, next) => {
13
+ * req.user = { id: localUserId, email }; // resolved by the host's perimeter
14
+ * next();
15
+ * });
16
+ * ```
17
+ *
18
+ * Hosts that keep `PermissionGuard` supply their own `ROLE_RESOLVER` instead.
19
+ */
20
+ export interface AuthenticatedUser {
21
+ id: number;
22
+ email?: string;
23
+ role?: string | null;
24
+ permissions?: string[];
25
+ }
26
+ export interface AuthenticatedRequest {
27
+ user?: AuthenticatedUser;
28
+ }
29
+ //# sourceMappingURL=authenticated-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-request.d.ts","sourceRoot":"","sources":["../../src/lib/authenticated-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-kingdom/shared-backend-util-rbac",
3
- "version": "0.0.2-18",
3
+ "version": "0.0.2-21",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },