@riao/iam 3.0.0 → 3.1.0

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.
@@ -0,0 +1,58 @@
1
+ import { DatabaseRecordId } from '@riao/dbal';
2
+ import { Auth, Principal } from '../auth';
3
+ export interface AuthorizationContext<TPrincipal extends Principal = Principal> {
4
+ principal: TPrincipal;
5
+ resource?: string | Record<string, unknown>;
6
+ action: string;
7
+ metadata?: Record<string, unknown>;
8
+ }
9
+ export interface AuthorizationResult {
10
+ allowed: boolean;
11
+ reason?: string;
12
+ }
13
+ export interface GrantPermissionOptions {
14
+ principalId: DatabaseRecordId;
15
+ action: string;
16
+ resource?: string;
17
+ metadata?: Record<string, unknown>;
18
+ }
19
+ export interface RevokePermissionOptions {
20
+ principalId: DatabaseRecordId;
21
+ action: string;
22
+ resource?: string;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ export declare abstract class Authorization<TPrincipal extends Principal> extends Auth<TPrincipal> {
26
+ /**
27
+ * Evaluate authorization for a given context
28
+ * @param context The authorization context containing principal,
29
+ * resource, action, and optional metadata
30
+ * @returns Authorization result with allowed status and optional reason
31
+ */
32
+ abstract evaluate(context: AuthorizationContext<TPrincipal>): Promise<AuthorizationResult>;
33
+ /**
34
+ * Check if a principal is authorized for a specific action on a resource
35
+ * @param context The authorization context
36
+ * @returns True if authorized, false otherwise
37
+ */
38
+ isAuthorized(context: AuthorizationContext<TPrincipal>): Promise<boolean>;
39
+ /**
40
+ * Check if a principal has permission for an action
41
+ * Subclasses should override this for specific authorization models
42
+ * @param context The authorization context
43
+ * @returns Authorization result
44
+ */
45
+ protected checkPermission(context: AuthorizationContext<TPrincipal>): Promise<AuthorizationResult>;
46
+ /**
47
+ * Grant a permission to a principal
48
+ * Subclasses should implement this based on their model
49
+ * @param options The grant permission options
50
+ */
51
+ abstract grantPermission(options: GrantPermissionOptions): Promise<void>;
52
+ /**
53
+ * Revoke a permission from a principal
54
+ * Subclasses should implement this based on their model
55
+ * @param options The revoke permission options
56
+ */
57
+ abstract revokePermission(options: RevokePermissionOptions): Promise<void>;
58
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Authorization = void 0;
4
+ const auth_1 = require("../auth");
5
+ class Authorization extends auth_1.Auth {
6
+ /**
7
+ * Check if a principal is authorized for a specific action on a resource
8
+ * @param context The authorization context
9
+ * @returns True if authorized, false otherwise
10
+ */
11
+ async isAuthorized(context) {
12
+ const result = await this.evaluate(context);
13
+ return result.allowed;
14
+ }
15
+ /**
16
+ * Check if a principal has permission for an action
17
+ * Subclasses should override this for specific authorization models
18
+ * @param context The authorization context
19
+ * @returns Authorization result
20
+ */
21
+ async checkPermission(
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
+ context) {
24
+ // Default implementation returns false
25
+ return {
26
+ allowed: false,
27
+ reason: 'No authorization model configured',
28
+ };
29
+ }
30
+ }
31
+ exports.Authorization = Authorization;
32
+ //# sourceMappingURL=authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/authorization/authorization.ts"],"names":[],"mappings":";;;AACA,kCAA0C;AA8B1C,MAAsB,aAEpB,SAAQ,WAAgB;IAWzB;;;;OAIG;IACI,KAAK,CAAC,YAAY,CACxB,OAAyC;QAEzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,OAAO,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,eAAe;IAC9B,6DAA6D;IAC7D,OAAyC;QAEzC,uCAAuC;QACvC,OAAO;YACN,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,mCAAmC;SAC3C,CAAC;IACH,CAAC;CAmBD;AA3DD,sCA2DC"}
@@ -0,0 +1 @@
1
+ export { Authorization, AuthorizationContext, AuthorizationResult, GrantPermissionOptions, RevokePermissionOptions, } from './authorization';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Authorization = void 0;
4
+ var authorization_1 = require("./authorization");
5
+ Object.defineProperty(exports, "Authorization", { enumerable: true, get: function () { return authorization_1.Authorization; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorization/index.ts"],"names":[],"mappings":";;;AAAA,iDAMyB;AALxB,8GAAA,aAAa,OAAA"}
package/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { encrypt, decrypt, Encryptor, Decryptor } from './crypto';
2
2
  export { KeyPairGenerator } from './keypair';
3
3
  export * from './auth';
4
4
  export * from './authentication';
5
+ export * from './authorization';
package/index.js CHANGED
@@ -11,4 +11,5 @@ var keypair_1 = require("./keypair");
11
11
  Object.defineProperty(exports, "KeyPairGenerator", { enumerable: true, get: function () { return keypair_1.KeyPairGenerator; } });
12
12
  tslib_1.__exportStar(require("./auth"), exports);
13
13
  tslib_1.__exportStar(require("./authentication"), exports);
14
+ tslib_1.__exportStar(require("./authorization"), exports);
14
15
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAAkE;AAAzD,iGAAA,OAAO,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,mGAAA,SAAS,OAAA;AAC/C,qCAA6C;AAApC,2GAAA,gBAAgB,OAAA;AAEzB,iDAAuB;AACvB,2DAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAAkE;AAAzD,iGAAA,OAAO,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,mGAAA,SAAS,OAAA;AAC/C,qCAA6C;AAApC,2GAAA,gBAAgB,OAAA;AAEzB,iDAAuB;AACvB,2DAAiC;AACjC,0DAAgC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riao/iam",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Identity Access Management for Riao",
5
5
  "typescript-template": {
6
6
  "base": "1.0.1",