@riao/iam 3.0.0 → 3.2.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.
package/auth/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { Auth } from './auth';
1
+ export { Auth, AuthOptions } from './auth';
2
2
  export { Principal } from './principal';
package/auth/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAAlC,4FAAA,IAAI,OAAA"}
@@ -0,0 +1,59 @@
1
+ import { DatabaseRecordId } from '@riao/dbal';
2
+ import { Auth, AuthOptions, Principal } from '../auth';
3
+ export type AuthorizationOptions = AuthOptions;
4
+ export interface AuthorizationContext<TPrincipal extends Principal = Principal> {
5
+ principal: TPrincipal;
6
+ resource?: string | Record<string, unknown>;
7
+ action: string;
8
+ metadata?: Record<string, unknown>;
9
+ }
10
+ export interface AuthorizationResult {
11
+ allowed: boolean;
12
+ reason?: string;
13
+ }
14
+ export interface GrantPermissionOptions {
15
+ principalId: DatabaseRecordId;
16
+ action: string;
17
+ resource?: string;
18
+ metadata?: Record<string, unknown>;
19
+ }
20
+ export interface RevokePermissionOptions {
21
+ principalId: DatabaseRecordId;
22
+ action: string;
23
+ resource?: string;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ export declare abstract class Authorization<TPrincipal extends Principal> extends Auth<TPrincipal> {
27
+ /**
28
+ * Evaluate authorization for a given context
29
+ * @param context The authorization context containing principal,
30
+ * resource, action, and optional metadata
31
+ * @returns Authorization result with allowed status and optional reason
32
+ */
33
+ abstract evaluate(context: AuthorizationContext<TPrincipal>): Promise<AuthorizationResult>;
34
+ /**
35
+ * Check if a principal is authorized for a specific action on a resource
36
+ * @param context The authorization context
37
+ * @returns True if authorized, false otherwise
38
+ */
39
+ isAuthorized(context: AuthorizationContext<TPrincipal>): Promise<boolean>;
40
+ /**
41
+ * Check if a principal has permission for an action
42
+ * Subclasses should override this for specific authorization models
43
+ * @param context The authorization context
44
+ * @returns Authorization result
45
+ */
46
+ protected checkPermission(context: AuthorizationContext<TPrincipal>): Promise<AuthorizationResult>;
47
+ /**
48
+ * Grant a permission to a principal
49
+ * Subclasses should implement this based on their model
50
+ * @param options The grant permission options
51
+ */
52
+ abstract grantPermission(options: GrantPermissionOptions): Promise<void>;
53
+ /**
54
+ * Revoke a permission from a principal
55
+ * Subclasses should implement this based on their model
56
+ * @param options The revoke permission options
57
+ */
58
+ abstract revokePermission(options: RevokePermissionOptions): Promise<void>;
59
+ }
@@ -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,kCAAuD;AAgCvD,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, AuthorizationOptions, 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,iDAOyB;AANxB,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.2.0",
4
4
  "description": "Identity Access Management for Riao",
5
5
  "typescript-template": {
6
6
  "base": "1.0.1",