@spinajs/rbac-http-token 2.0.507

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.
Files changed (198) hide show
  1. package/README.md +152 -0
  2. package/lib/cjs/actions.d.ts +119 -0
  3. package/lib/cjs/actions.d.ts.map +1 -0
  4. package/lib/cjs/actions.js +257 -0
  5. package/lib/cjs/actions.js.map +1 -0
  6. package/lib/cjs/cli/CreateToken.d.ts +13 -0
  7. package/lib/cjs/cli/CreateToken.d.ts.map +1 -0
  8. package/lib/cjs/cli/CreateToken.js +56 -0
  9. package/lib/cjs/cli/CreateToken.js.map +1 -0
  10. package/lib/cjs/cli/DeleteExpiredTokens.d.ts +11 -0
  11. package/lib/cjs/cli/DeleteExpiredTokens.d.ts.map +1 -0
  12. package/lib/cjs/cli/DeleteExpiredTokens.js +39 -0
  13. package/lib/cjs/cli/DeleteExpiredTokens.js.map +1 -0
  14. package/lib/cjs/cli/DeleteToken.d.ts +7 -0
  15. package/lib/cjs/cli/DeleteToken.d.ts.map +1 -0
  16. package/lib/cjs/cli/DeleteToken.js +36 -0
  17. package/lib/cjs/cli/DeleteToken.js.map +1 -0
  18. package/lib/cjs/cli/GrantTokenRole.d.ts +7 -0
  19. package/lib/cjs/cli/GrantTokenRole.d.ts.map +1 -0
  20. package/lib/cjs/cli/GrantTokenRole.js +37 -0
  21. package/lib/cjs/cli/GrantTokenRole.js.map +1 -0
  22. package/lib/cjs/cli/RevokeTokenRole.d.ts +12 -0
  23. package/lib/cjs/cli/RevokeTokenRole.d.ts.map +1 -0
  24. package/lib/cjs/cli/RevokeTokenRole.js +42 -0
  25. package/lib/cjs/cli/RevokeTokenRole.js.map +1 -0
  26. package/lib/cjs/config/rbac-http-token.d.ts +71 -0
  27. package/lib/cjs/config/rbac-http-token.d.ts.map +1 -0
  28. package/lib/cjs/config/rbac-http-token.js +98 -0
  29. package/lib/cjs/config/rbac-http-token.js.map +1 -0
  30. package/lib/cjs/controllers/AccessTokenController.d.ts +139 -0
  31. package/lib/cjs/controllers/AccessTokenController.d.ts.map +1 -0
  32. package/lib/cjs/controllers/AccessTokenController.js +264 -0
  33. package/lib/cjs/controllers/AccessTokenController.js.map +1 -0
  34. package/lib/cjs/dto/create-token-dto.d.ts +34 -0
  35. package/lib/cjs/dto/create-token-dto.d.ts.map +1 -0
  36. package/lib/cjs/dto/create-token-dto.js +35 -0
  37. package/lib/cjs/dto/create-token-dto.js.map +1 -0
  38. package/lib/cjs/events/AccessTokenCreated.d.ts +4 -0
  39. package/lib/cjs/events/AccessTokenCreated.d.ts.map +1 -0
  40. package/lib/cjs/events/AccessTokenCreated.js +18 -0
  41. package/lib/cjs/events/AccessTokenCreated.js.map +1 -0
  42. package/lib/cjs/events/AccessTokenDeleted.d.ts +4 -0
  43. package/lib/cjs/events/AccessTokenDeleted.d.ts.map +1 -0
  44. package/lib/cjs/events/AccessTokenDeleted.js +18 -0
  45. package/lib/cjs/events/AccessTokenDeleted.js.map +1 -0
  46. package/lib/cjs/events/AccessTokenEvent.d.ts +10 -0
  47. package/lib/cjs/events/AccessTokenEvent.d.ts.map +1 -0
  48. package/lib/cjs/events/AccessTokenEvent.js +26 -0
  49. package/lib/cjs/events/AccessTokenEvent.js.map +1 -0
  50. package/lib/cjs/events/AccessTokenRoleGranted.d.ts +7 -0
  51. package/lib/cjs/events/AccessTokenRoleGranted.d.ts.map +1 -0
  52. package/lib/cjs/events/AccessTokenRoleGranted.js +27 -0
  53. package/lib/cjs/events/AccessTokenRoleGranted.js.map +1 -0
  54. package/lib/cjs/events/AccessTokenRoleRevoked.d.ts +7 -0
  55. package/lib/cjs/events/AccessTokenRoleRevoked.d.ts.map +1 -0
  56. package/lib/cjs/events/AccessTokenRoleRevoked.js +27 -0
  57. package/lib/cjs/events/AccessTokenRoleRevoked.js.map +1 -0
  58. package/lib/cjs/events/index.d.ts +6 -0
  59. package/lib/cjs/events/index.d.ts.map +1 -0
  60. package/lib/cjs/events/index.js +22 -0
  61. package/lib/cjs/events/index.js.map +1 -0
  62. package/lib/cjs/generator.d.ts +12 -0
  63. package/lib/cjs/generator.d.ts.map +1 -0
  64. package/lib/cjs/generator.js +42 -0
  65. package/lib/cjs/generator.js.map +1 -0
  66. package/lib/cjs/index.d.ts +20 -0
  67. package/lib/cjs/index.d.ts.map +1 -0
  68. package/lib/cjs/index.js +39 -0
  69. package/lib/cjs/index.js.map +1 -0
  70. package/lib/cjs/interfaces.d.ts +57 -0
  71. package/lib/cjs/interfaces.d.ts.map +1 -0
  72. package/lib/cjs/interfaces.js +11 -0
  73. package/lib/cjs/interfaces.js.map +1 -0
  74. package/lib/cjs/middlewares.d.ts +76 -0
  75. package/lib/cjs/middlewares.d.ts.map +1 -0
  76. package/lib/cjs/middlewares.js +181 -0
  77. package/lib/cjs/middlewares.js.map +1 -0
  78. package/lib/cjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.d.ts +6 -0
  79. package/lib/cjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.d.ts.map +1 -0
  80. package/lib/cjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.js +38 -0
  81. package/lib/cjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.js.map +1 -0
  82. package/lib/cjs/models/AccessToken.d.ts +55 -0
  83. package/lib/cjs/models/AccessToken.d.ts.map +1 -0
  84. package/lib/cjs/models/AccessToken.js +73 -0
  85. package/lib/cjs/models/AccessToken.js.map +1 -0
  86. package/lib/cjs/package.json +1 -0
  87. package/lib/cjs/policies/NoImpersonationPolicy.d.ts +28 -0
  88. package/lib/cjs/policies/NoImpersonationPolicy.d.ts.map +1 -0
  89. package/lib/cjs/policies/NoImpersonationPolicy.js +45 -0
  90. package/lib/cjs/policies/NoImpersonationPolicy.js.map +1 -0
  91. package/lib/cjs/policies/NoTokenAuthPolicy.d.ts +12 -0
  92. package/lib/cjs/policies/NoTokenAuthPolicy.d.ts.map +1 -0
  93. package/lib/cjs/policies/NoTokenAuthPolicy.js +24 -0
  94. package/lib/cjs/policies/NoTokenAuthPolicy.js.map +1 -0
  95. package/lib/cjs/policies/TokenPolicy.d.ts +49 -0
  96. package/lib/cjs/policies/TokenPolicy.d.ts.map +1 -0
  97. package/lib/cjs/policies/TokenPolicy.js +79 -0
  98. package/lib/cjs/policies/TokenPolicy.js.map +1 -0
  99. package/lib/mjs/actions.d.ts +119 -0
  100. package/lib/mjs/actions.d.ts.map +1 -0
  101. package/lib/mjs/actions.js +242 -0
  102. package/lib/mjs/actions.js.map +1 -0
  103. package/lib/mjs/cli/CreateToken.d.ts +13 -0
  104. package/lib/mjs/cli/CreateToken.d.ts.map +1 -0
  105. package/lib/mjs/cli/CreateToken.js +53 -0
  106. package/lib/mjs/cli/CreateToken.js.map +1 -0
  107. package/lib/mjs/cli/DeleteExpiredTokens.d.ts +11 -0
  108. package/lib/mjs/cli/DeleteExpiredTokens.d.ts.map +1 -0
  109. package/lib/mjs/cli/DeleteExpiredTokens.js +36 -0
  110. package/lib/mjs/cli/DeleteExpiredTokens.js.map +1 -0
  111. package/lib/mjs/cli/DeleteToken.d.ts +7 -0
  112. package/lib/mjs/cli/DeleteToken.d.ts.map +1 -0
  113. package/lib/mjs/cli/DeleteToken.js +33 -0
  114. package/lib/mjs/cli/DeleteToken.js.map +1 -0
  115. package/lib/mjs/cli/GrantTokenRole.d.ts +7 -0
  116. package/lib/mjs/cli/GrantTokenRole.d.ts.map +1 -0
  117. package/lib/mjs/cli/GrantTokenRole.js +34 -0
  118. package/lib/mjs/cli/GrantTokenRole.js.map +1 -0
  119. package/lib/mjs/cli/RevokeTokenRole.d.ts +12 -0
  120. package/lib/mjs/cli/RevokeTokenRole.d.ts.map +1 -0
  121. package/lib/mjs/cli/RevokeTokenRole.js +39 -0
  122. package/lib/mjs/cli/RevokeTokenRole.js.map +1 -0
  123. package/lib/mjs/config/rbac-http-token.d.ts +71 -0
  124. package/lib/mjs/config/rbac-http-token.d.ts.map +1 -0
  125. package/lib/mjs/config/rbac-http-token.js +96 -0
  126. package/lib/mjs/config/rbac-http-token.js.map +1 -0
  127. package/lib/mjs/controllers/AccessTokenController.d.ts +139 -0
  128. package/lib/mjs/controllers/AccessTokenController.d.ts.map +1 -0
  129. package/lib/mjs/controllers/AccessTokenController.js +261 -0
  130. package/lib/mjs/controllers/AccessTokenController.js.map +1 -0
  131. package/lib/mjs/dto/create-token-dto.d.ts +34 -0
  132. package/lib/mjs/dto/create-token-dto.d.ts.map +1 -0
  133. package/lib/mjs/dto/create-token-dto.js +32 -0
  134. package/lib/mjs/dto/create-token-dto.js.map +1 -0
  135. package/lib/mjs/events/AccessTokenCreated.d.ts +4 -0
  136. package/lib/mjs/events/AccessTokenCreated.d.ts.map +1 -0
  137. package/lib/mjs/events/AccessTokenCreated.js +15 -0
  138. package/lib/mjs/events/AccessTokenCreated.js.map +1 -0
  139. package/lib/mjs/events/AccessTokenDeleted.d.ts +4 -0
  140. package/lib/mjs/events/AccessTokenDeleted.d.ts.map +1 -0
  141. package/lib/mjs/events/AccessTokenDeleted.js +15 -0
  142. package/lib/mjs/events/AccessTokenDeleted.js.map +1 -0
  143. package/lib/mjs/events/AccessTokenEvent.d.ts +10 -0
  144. package/lib/mjs/events/AccessTokenEvent.d.ts.map +1 -0
  145. package/lib/mjs/events/AccessTokenEvent.js +23 -0
  146. package/lib/mjs/events/AccessTokenEvent.js.map +1 -0
  147. package/lib/mjs/events/AccessTokenRoleGranted.d.ts +7 -0
  148. package/lib/mjs/events/AccessTokenRoleGranted.d.ts.map +1 -0
  149. package/lib/mjs/events/AccessTokenRoleGranted.js +24 -0
  150. package/lib/mjs/events/AccessTokenRoleGranted.js.map +1 -0
  151. package/lib/mjs/events/AccessTokenRoleRevoked.d.ts +7 -0
  152. package/lib/mjs/events/AccessTokenRoleRevoked.d.ts.map +1 -0
  153. package/lib/mjs/events/AccessTokenRoleRevoked.js +24 -0
  154. package/lib/mjs/events/AccessTokenRoleRevoked.js.map +1 -0
  155. package/lib/mjs/events/index.d.ts +6 -0
  156. package/lib/mjs/events/index.d.ts.map +1 -0
  157. package/lib/mjs/events/index.js +6 -0
  158. package/lib/mjs/events/index.js.map +1 -0
  159. package/lib/mjs/generator.d.ts +12 -0
  160. package/lib/mjs/generator.d.ts.map +1 -0
  161. package/lib/mjs/generator.js +39 -0
  162. package/lib/mjs/generator.js.map +1 -0
  163. package/lib/mjs/index.d.ts +20 -0
  164. package/lib/mjs/index.d.ts.map +1 -0
  165. package/lib/mjs/index.js +23 -0
  166. package/lib/mjs/index.js.map +1 -0
  167. package/lib/mjs/interfaces.d.ts +57 -0
  168. package/lib/mjs/interfaces.d.ts.map +1 -0
  169. package/lib/mjs/interfaces.js +7 -0
  170. package/lib/mjs/interfaces.js.map +1 -0
  171. package/lib/mjs/middlewares.d.ts +76 -0
  172. package/lib/mjs/middlewares.d.ts.map +1 -0
  173. package/lib/mjs/middlewares.js +178 -0
  174. package/lib/mjs/middlewares.js.map +1 -0
  175. package/lib/mjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.d.ts +6 -0
  176. package/lib/mjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.d.ts.map +1 -0
  177. package/lib/mjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.js +35 -0
  178. package/lib/mjs/migrations/RbacHttpTokenInitial_2026_08_11_01_00_00.js.map +1 -0
  179. package/lib/mjs/models/AccessToken.d.ts +55 -0
  180. package/lib/mjs/models/AccessToken.d.ts.map +1 -0
  181. package/lib/mjs/models/AccessToken.js +70 -0
  182. package/lib/mjs/models/AccessToken.js.map +1 -0
  183. package/lib/mjs/package.json +1 -0
  184. package/lib/mjs/policies/NoImpersonationPolicy.d.ts +28 -0
  185. package/lib/mjs/policies/NoImpersonationPolicy.d.ts.map +1 -0
  186. package/lib/mjs/policies/NoImpersonationPolicy.js +41 -0
  187. package/lib/mjs/policies/NoImpersonationPolicy.js.map +1 -0
  188. package/lib/mjs/policies/NoTokenAuthPolicy.d.ts +12 -0
  189. package/lib/mjs/policies/NoTokenAuthPolicy.d.ts.map +1 -0
  190. package/lib/mjs/policies/NoTokenAuthPolicy.js +20 -0
  191. package/lib/mjs/policies/NoTokenAuthPolicy.js.map +1 -0
  192. package/lib/mjs/policies/TokenPolicy.d.ts +49 -0
  193. package/lib/mjs/policies/TokenPolicy.d.ts.map +1 -0
  194. package/lib/mjs/policies/TokenPolicy.js +75 -0
  195. package/lib/mjs/policies/TokenPolicy.js.map +1 -0
  196. package/lib/tsconfig.cjs.tsbuildinfo +1 -0
  197. package/lib/tsconfig.mjs.tsbuildinfo +1 -0
  198. package/package.json +78 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeleteExpiredTokens = void 0;
13
+ const log_1 = require("@spinajs/log");
14
+ const cli_1 = require("@spinajs/cli");
15
+ const actions_js_1 = require("../actions.js");
16
+ /**
17
+ * Intended for cyclic execution from a worker process
18
+ * ( eg. cron / task scheduler ) to keep the token table clean.
19
+ */
20
+ let DeleteExpiredTokens = class DeleteExpiredTokens extends cli_1.CliCommand {
21
+ async execute() {
22
+ try {
23
+ const count = await (0, actions_js_1.deleteExpiredTokens)();
24
+ this.Log.success(`Deleted ${count} expired token(s)`);
25
+ }
26
+ catch (e) {
27
+ this.Log.error(`Error while deleting expired tokens: ${e.message}`);
28
+ }
29
+ }
30
+ };
31
+ exports.DeleteExpiredTokens = DeleteExpiredTokens;
32
+ __decorate([
33
+ (0, log_1.Logger)('rbac-http-token'),
34
+ __metadata("design:type", log_1.Log)
35
+ ], DeleteExpiredTokens.prototype, "Log", void 0);
36
+ exports.DeleteExpiredTokens = DeleteExpiredTokens = __decorate([
37
+ (0, cli_1.Command)('rbac:token-delete-expired', 'Deletes all expired access tokens')
38
+ ], DeleteExpiredTokens);
39
+ //# sourceMappingURL=DeleteExpiredTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeleteExpiredTokens.js","sourceRoot":"","sources":["../../../src/cli/DeleteExpiredTokens.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA2C;AAC3C,sCAAmD;AAEnD,8CAAoD;AAEpD;;;GAGG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,gBAAU;IAI1C,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAA,gCAAmB,GAAE,CAAC;YAC1C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,mBAAmB,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,wCAAyC,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;CACF,CAAA;;AAVW;IADT,IAAA,YAAM,EAAC,iBAAiB,CAAC;8BACX,SAAG;gDAAC;8BAFR,mBAAmB;IAD/B,IAAA,aAAO,EAAC,2BAA2B,EAAE,mCAAmC,CAAC;GAC7D,mBAAmB,CAY/B"}
@@ -0,0 +1,7 @@
1
+ import { Log } from '@spinajs/log';
2
+ import { CliCommand } from '@spinajs/cli';
3
+ export declare class DeleteToken extends CliCommand {
4
+ protected Log: Log;
5
+ execute(uuid: string): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=DeleteToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeleteToken.d.ts","sourceRoot":"","sources":["../../../src/cli/DeleteToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAY,UAAU,EAAW,MAAM,cAAc,CAAC;AAI7D,qBAEa,WAAY,SAAQ,UAAU;IAEzC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhD;CACF"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeleteToken = void 0;
13
+ const log_1 = require("@spinajs/log");
14
+ const cli_1 = require("@spinajs/cli");
15
+ const actions_js_1 = require("../actions.js");
16
+ let DeleteToken = class DeleteToken extends cli_1.CliCommand {
17
+ async execute(uuid) {
18
+ try {
19
+ await (0, actions_js_1.deleteToken)(uuid);
20
+ this.Log.success(`Token ${uuid} deleted`);
21
+ }
22
+ catch (e) {
23
+ this.Log.error(`Error while deleting token ${uuid}: ${e.message}`);
24
+ }
25
+ }
26
+ };
27
+ exports.DeleteToken = DeleteToken;
28
+ __decorate([
29
+ (0, log_1.Logger)('rbac-http-token'),
30
+ __metadata("design:type", log_1.Log)
31
+ ], DeleteToken.prototype, "Log", void 0);
32
+ exports.DeleteToken = DeleteToken = __decorate([
33
+ (0, cli_1.Command)('rbac:token-delete', 'Deletes ( revokes ) an access token'),
34
+ (0, cli_1.Argument)('uuid', true, 'token uuid')
35
+ ], DeleteToken);
36
+ //# sourceMappingURL=DeleteToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeleteToken.js","sourceRoot":"","sources":["../../../src/cli/DeleteToken.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA2C;AAC3C,sCAA6D;AAE7D,8CAA4C;AAIrC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,gBAAU;IAIlC,KAAK,CAAC,OAAO,CAAC,IAAY;QAC/B,IAAI,CAAC;YACH,MAAM,IAAA,wBAAW,EAAC,IAAI,CAAC,CAAC;YACxB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,UAAU,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,8BAA8B,IAAI,KAAM,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;CACF,CAAA;;AAVW;IADT,IAAA,YAAM,EAAC,iBAAiB,CAAC;8BACX,SAAG;wCAAC;sBAFR,WAAW;IAFvB,IAAA,aAAO,EAAC,mBAAmB,EAAE,qCAAqC,CAAC;IACnE,IAAA,cAAQ,EAAC,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC;GACxB,WAAW,CAYvB"}
@@ -0,0 +1,7 @@
1
+ import { Log } from '@spinajs/log';
2
+ import { CliCommand } from '@spinajs/cli';
3
+ export declare class GrantTokenRole extends CliCommand {
4
+ protected Log: Log;
5
+ execute(uuid: string, role: string): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=GrantTokenRole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GrantTokenRole.d.ts","sourceRoot":"","sources":["../../../src/cli/GrantTokenRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAY,UAAU,EAAW,MAAM,cAAc,CAAC;AAI7D,qBAGa,cAAe,SAAQ,UAAU;IAE5C,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO9D;CACF"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GrantTokenRole = void 0;
13
+ const log_1 = require("@spinajs/log");
14
+ const cli_1 = require("@spinajs/cli");
15
+ const actions_js_1 = require("../actions.js");
16
+ let GrantTokenRole = class GrantTokenRole extends cli_1.CliCommand {
17
+ async execute(uuid, role) {
18
+ try {
19
+ await (0, actions_js_1.grantTokenRole)(uuid, role);
20
+ this.Log.success(`Role ${role} granted to token ${uuid}`);
21
+ }
22
+ catch (e) {
23
+ this.Log.error(`Error while granting role ${role} to token ${uuid}: ${e.message}`);
24
+ }
25
+ }
26
+ };
27
+ exports.GrantTokenRole = GrantTokenRole;
28
+ __decorate([
29
+ (0, log_1.Logger)('rbac-http-token'),
30
+ __metadata("design:type", log_1.Log)
31
+ ], GrantTokenRole.prototype, "Log", void 0);
32
+ exports.GrantTokenRole = GrantTokenRole = __decorate([
33
+ (0, cli_1.Command)('rbac:token-grant', 'Grants a role to an access token'),
34
+ (0, cli_1.Argument)('uuid', true, 'token uuid'),
35
+ (0, cli_1.Argument)('role', true, 'role to grant, must be held by token owner')
36
+ ], GrantTokenRole);
37
+ //# sourceMappingURL=GrantTokenRole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GrantTokenRole.js","sourceRoot":"","sources":["../../../src/cli/GrantTokenRole.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA2C;AAC3C,sCAA6D;AAE7D,8CAA+C;AAKxC,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,gBAAU;IAIrC,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,IAAY;QAC7C,IAAI,CAAC;YACH,MAAM,IAAA,2BAAc,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,qBAAqB,IAAI,EAAE,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,IAAI,aAAa,IAAI,KAAM,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAChG,CAAC;IACH,CAAC;CACF,CAAA;;AAVW;IADT,IAAA,YAAM,EAAC,iBAAiB,CAAC;8BACX,SAAG;2CAAC;yBAFR,cAAc;IAH1B,IAAA,aAAO,EAAC,kBAAkB,EAAE,kCAAkC,CAAC;IAC/D,IAAA,cAAQ,EAAC,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC;IACpC,IAAA,cAAQ,EAAC,MAAM,EAAE,IAAI,EAAE,4CAA4C,CAAC;GACxD,cAAc,CAY1B"}
@@ -0,0 +1,12 @@
1
+ import { Log } from '@spinajs/log';
2
+ import { CliCommand } from '@spinajs/cli';
3
+ export declare class RevokeTokenRole extends CliCommand {
4
+ protected Log: Log;
5
+ /**
6
+ * Refusals arrive as thrown errors ( eg. revoking a token's last role ) and
7
+ * are reported on the error channel like any other failure - the row is left
8
+ * exactly as it was.
9
+ */
10
+ execute(uuid: string, role: string): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=RevokeTokenRole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RevokeTokenRole.d.ts","sourceRoot":"","sources":["../../../src/cli/RevokeTokenRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAY,UAAU,EAAW,MAAM,cAAc,CAAC;AAI7D,qBAGa,eAAgB,SAAQ,UAAU;IAE7C,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEnB;;;;OAIG;IACU,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO9D;CACF"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RevokeTokenRole = void 0;
13
+ const log_1 = require("@spinajs/log");
14
+ const cli_1 = require("@spinajs/cli");
15
+ const actions_js_1 = require("../actions.js");
16
+ let RevokeTokenRole = class RevokeTokenRole extends cli_1.CliCommand {
17
+ /**
18
+ * Refusals arrive as thrown errors ( eg. revoking a token's last role ) and
19
+ * are reported on the error channel like any other failure - the row is left
20
+ * exactly as it was.
21
+ */
22
+ async execute(uuid, role) {
23
+ try {
24
+ await (0, actions_js_1.revokeTokenRole)(uuid, role);
25
+ this.Log.success(`Role ${role} revoked from token ${uuid}`);
26
+ }
27
+ catch (e) {
28
+ this.Log.error(`Error while revoking role ${role} from token ${uuid}: ${e.message}`);
29
+ }
30
+ }
31
+ };
32
+ exports.RevokeTokenRole = RevokeTokenRole;
33
+ __decorate([
34
+ (0, log_1.Logger)('rbac-http-token'),
35
+ __metadata("design:type", log_1.Log)
36
+ ], RevokeTokenRole.prototype, "Log", void 0);
37
+ exports.RevokeTokenRole = RevokeTokenRole = __decorate([
38
+ (0, cli_1.Command)('rbac:token-revoke', 'Revokes a role from an access token'),
39
+ (0, cli_1.Argument)('uuid', true, 'token uuid'),
40
+ (0, cli_1.Argument)('role', true, 'role to revoke')
41
+ ], RevokeTokenRole);
42
+ //# sourceMappingURL=RevokeTokenRole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RevokeTokenRole.js","sourceRoot":"","sources":["../../../src/cli/RevokeTokenRole.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA2C;AAC3C,sCAA6D;AAE7D,8CAAgD;AAKzC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,gBAAU;IAI7C;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,IAAY;QAC7C,IAAI,CAAC;YACH,MAAM,IAAA,4BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAClC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,uBAAuB,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,IAAI,eAAe,IAAI,KAAM,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAClG,CAAC;IACH,CAAC;CACF,CAAA;;AAfW;IADT,IAAA,YAAM,EAAC,iBAAiB,CAAC;8BACX,SAAG;4CAAC;0BAFR,eAAe;IAH3B,IAAA,aAAO,EAAC,mBAAmB,EAAE,qCAAqC,CAAC;IACnE,IAAA,cAAQ,EAAC,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC;IACpC,IAAA,cAAQ,EAAC,MAAM,EAAE,IAAI,EAAE,gBAAgB,CAAC;GAC5B,eAAe,CAiB3B"}
@@ -0,0 +1,71 @@
1
+ declare const rbacHttpToken: {
2
+ system: {
3
+ dirs: {
4
+ cli: string[];
5
+ controllers: string[];
6
+ };
7
+ };
8
+ queue: {
9
+ routing: {
10
+ AccessTokenCreated: {
11
+ connection: string;
12
+ };
13
+ AccessTokenDeleted: {
14
+ connection: string;
15
+ };
16
+ AccessTokenRoleGranted: {
17
+ connection: string;
18
+ };
19
+ AccessTokenRoleRevoked: {
20
+ connection: string;
21
+ };
22
+ };
23
+ };
24
+ rbac: {
25
+ token: {
26
+ /**
27
+ * Token generation algorithm. Swap for your own implementation of
28
+ * AccessTokenGenerationProvider registered under this name.
29
+ */
30
+ generation: {
31
+ service: string;
32
+ };
33
+ /**
34
+ * Stable plaintext prefix - lets secret scanners recognise leaked tokens.
35
+ */
36
+ prefix: string;
37
+ /**
38
+ * Random bytes per token ( 32 = 256 bit entropy ).
39
+ */
40
+ length: number;
41
+ /**
42
+ * Fallback header checked when no `Authorization: Bearer` is present.
43
+ */
44
+ headerName: string;
45
+ /**
46
+ * Seconds between LastUsedAt writes for a busy token.
47
+ */
48
+ lastUsedUpdateInterval: number;
49
+ };
50
+ grants: {
51
+ user: {
52
+ 'user.tokens': {
53
+ 'create:own': string[];
54
+ 'read:own': string[];
55
+ 'update:own': string[];
56
+ 'delete:own': string[];
57
+ };
58
+ };
59
+ 'admin.users': {
60
+ 'user.tokens': {
61
+ 'create:any': string[];
62
+ 'read:any': string[];
63
+ 'update:any': string[];
64
+ 'delete:any': string[];
65
+ };
66
+ };
67
+ };
68
+ };
69
+ };
70
+ export default rbacHttpToken;
71
+ //# sourceMappingURL=rbac-http-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rbac-http-token.d.ts","sourceRoot":"","sources":["../../../src/config/rbac-http-token.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,aAAa;IACjB,MAAM;QACJ,IAAI;YAIF,GAAG;YACH,WAAW;;;IAqBf,KAAK;QAKH,OAAO;YACL,kBAAkB;gBAAI,UAAU;;YAChC,kBAAkB;gBAAI,UAAU;;YAChC,sBAAsB;gBAAI,UAAU;;YACpC,sBAAsB;gBAAI,UAAU;;;;IAGxC,IAAI;QACF,KAAK;YACH;;;eAGG;YACH,UAAU;gBACR,OAAO;;YAGT;;eAEG;YACH,MAAM;YAEN;;eAEG;YACH,MAAM;YAEN;;eAEG;YACH,UAAU;YAEV;;eAEG;YACH,sBAAsB;;QAExB,MAAM;YACJ,IAAI;gBACF,aAAa;oBAAI,YAAY;oBAAS,UAAU;oBAAS,YAAY;oBAAS,YAAY;;;YAa5F,aAAa;gBACX,aAAa;oBAAI,YAAY;oBAAS,UAAU;oBAAS,YAAY;oBAAS,YAAY;;;;;CAIjG,CAAC;eAEa,aAAa"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ function dir(path) {
5
+ const inCommonJs = typeof module !== 'undefined';
6
+ return [
7
+ (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), 'node_modules', '@spinajs', 'rbac-http-token', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
8
+ // one up if we run from app or build folder
9
+ (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), '../', 'node_modules', '@spinajs', 'rbac-http-token', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
10
+ ];
11
+ }
12
+ const rbacHttpToken = {
13
+ system: {
14
+ dirs: {
15
+ // CLI commands and controllers are found by a filesystem scan
16
+ // ( `@ListFromFiles` ), so without these entries the shipped commands and
17
+ // the AccessToken controller are unreachable in a consuming app.
18
+ cli: [...dir('cli')],
19
+ controllers: [...dir('controllers')],
20
+ // `migrations` is DELIBERATELY not shipped here, and neither is `models`.
21
+ //
22
+ // Package configs merge into an app's config by ARRAY CONCAT, and
23
+ // `FilesystemMigrationSource` treats a non-empty `system.dirs.migrations`
24
+ // as "the operator configured the scan set": it then REPLACES the build
25
+ // layout defaults instead of adding to them, and turns a failed `.js`
26
+ // import from a warning into a throw ( `orm/src/migration-sources.ts`,
27
+ // and the docblock on `orm/src/config/orm.ts` which ships the key empty
28
+ // for exactly this reason ). A single line here would therefore silently
29
+ // switch off migration discovery in every application that installs this
30
+ // package. `RbacHttpTokenInitial_...` needs no scan anyway - it carries
31
+ // `@Migration`, is exported from the package index, and is picked up from
32
+ // the DI registry by `DiRegistryMigrationSource`. `@spinajs/rbac` ships
33
+ // `cli` only for the same reason.
34
+ //
35
+ // Nothing in the framework reads `system.dirs.models` - models register
36
+ // themselves through the `@Model` decorator when their file is imported.
37
+ },
38
+ },
39
+ queue: {
40
+ // All events emitted by this package go to the black hole connection
41
+ // declared by @spinajs/rbac ( `rbac-user-empty-queue` ). Without the
42
+ // routing they would fall back to the application's DEFAULT connection -
43
+ // a real broker - and every token operation would publish to it.
44
+ routing: {
45
+ AccessTokenCreated: { connection: 'rbac-user-empty-queue' },
46
+ AccessTokenDeleted: { connection: 'rbac-user-empty-queue' },
47
+ AccessTokenRoleGranted: { connection: 'rbac-user-empty-queue' },
48
+ AccessTokenRoleRevoked: { connection: 'rbac-user-empty-queue' },
49
+ },
50
+ },
51
+ rbac: {
52
+ token: {
53
+ /**
54
+ * Token generation algorithm. Swap for your own implementation of
55
+ * AccessTokenGenerationProvider registered under this name.
56
+ */
57
+ generation: {
58
+ service: 'SecureRandomTokenProvider',
59
+ },
60
+ /**
61
+ * Stable plaintext prefix - lets secret scanners recognise leaked tokens.
62
+ */
63
+ prefix: 'spt_',
64
+ /**
65
+ * Random bytes per token ( 32 = 256 bit entropy ).
66
+ */
67
+ length: 32,
68
+ /**
69
+ * Fallback header checked when no `Authorization: Bearer` is present.
70
+ */
71
+ headerName: 'x-api-key',
72
+ /**
73
+ * Seconds between LastUsedAt writes for a busy token.
74
+ */
75
+ lastUsedUpdateInterval: 60,
76
+ },
77
+ grants: {
78
+ user: {
79
+ 'user.tokens': { 'create:own': ['*'], 'read:own': ['*'], 'update:own': ['*'], 'delete:own': ['*'] },
80
+ },
81
+ // RESERVED - nothing shipped in this package enforces or consumes these.
82
+ //
83
+ // `AccessTokenController` is self-service by construction: every one of
84
+ // its routes declares an `*Own` permission and additionally constrains
85
+ // its query by the caller's id ( `own()` ), so an `*:any` grant changes
86
+ // nothing about what that controller lets through. The entry is here so
87
+ // the role's grant map is complete ahead of an admin-scope controller -
88
+ // "list / revoke the tokens of any user" is the obvious next addition -
89
+ // and so an application that writes such a controller itself finds the
90
+ // grants already declared under the resource name it must use.
91
+ 'admin.users': {
92
+ 'user.tokens': { 'create:any': ['*'], 'read:any': ['*'], 'update:any': ['*'], 'delete:any': ['*'] },
93
+ },
94
+ },
95
+ },
96
+ };
97
+ exports.default = rbacHttpToken;
98
+ //# sourceMappingURL=rbac-http-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rbac-http-token.js","sourceRoot":"","sources":["../../../src/config/rbac-http-token.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACjD,OAAO;QACL,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QAElK,4CAA4C;QAC5C,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;KAC1K,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAG;IACpB,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,8DAA8D;YAC9D,0EAA0E;YAC1E,iEAAiE;YACjE,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,WAAW,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;YAEpC,0EAA0E;YAC1E,EAAE;YACF,kEAAkE;YAClE,0EAA0E;YAC1E,wEAAwE;YACxE,sEAAsE;YACtE,uEAAuE;YACvE,wEAAwE;YACxE,yEAAyE;YACzE,yEAAyE;YACzE,wEAAwE;YACxE,0EAA0E;YAC1E,wEAAwE;YACxE,kCAAkC;YAClC,EAAE;YACF,wEAAwE;YACxE,yEAAyE;SAC1E;KACF;IACD,KAAK,EAAE;QACL,qEAAqE;QACrE,qEAAqE;QACrE,yEAAyE;QACzE,iEAAiE;QACjE,OAAO,EAAE;YACP,kBAAkB,EAAE,EAAE,UAAU,EAAE,uBAAuB,EAAE;YAC3D,kBAAkB,EAAE,EAAE,UAAU,EAAE,uBAAuB,EAAE;YAC3D,sBAAsB,EAAE,EAAE,UAAU,EAAE,uBAAuB,EAAE;YAC/D,sBAAsB,EAAE,EAAE,UAAU,EAAE,uBAAuB,EAAE;SAChE;KACF;IACD,IAAI,EAAE;QACJ,KAAK,EAAE;YACL;;;eAGG;YACH,UAAU,EAAE;gBACV,OAAO,EAAE,2BAA2B;aACrC;YAED;;eAEG;YACH,MAAM,EAAE,MAAM;YAEd;;eAEG;YACH,MAAM,EAAE,EAAE;YAEV;;eAEG;YACH,UAAU,EAAE,WAAW;YAEvB;;eAEG;YACH,sBAAsB,EAAE,EAAE;SAC3B;QACD,MAAM,EAAE;YACN,IAAI,EAAE;gBACJ,aAAa,EAAE,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE;aACpG;YAED,yEAAyE;YACzE,EAAE;YACF,wEAAwE;YACxE,uEAAuE;YACvE,wEAAwE;YACxE,wEAAwE;YACxE,wEAAwE;YACxE,wEAAwE;YACxE,uEAAuE;YACvE,+DAA+D;YAC/D,aAAa,EAAE;gBACb,aAAa,EAAE,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE;aACpG;SACF;KACF;CACF,CAAC;kBAEa,aAAa"}
@@ -0,0 +1,139 @@
1
+ import { BadRequestResponse, BaseController, NotFound, Ok } from '@spinajs/http';
2
+ import { User as UserModel } from '@spinajs/rbac';
3
+ import { AccessToken } from '../models/AccessToken.js';
4
+ import { CreateTokenDto } from '../dto/create-token-dto.js';
5
+ /**
6
+ * Self-service management of own access tokens.
7
+ *
8
+ * SELF-service in the strict sense: the caller must be the account owner,
9
+ * present in person. Two ways of acting *as* somebody are refused outright -
10
+ * an access token ( which must never mint another token ) and an impersonated
11
+ * session ( which must never mint a credential that outlives it ). Every query
12
+ * is additionally constrained by the calling user's id, so a foreign uuid is
13
+ * simply not found.
14
+ *
15
+ * WIRING - the decorator layout below is load bearing. The two guards share ONE
16
+ * `@Policy([...])` group so they are ANDed; splitting them into two `@Policy()`
17
+ * calls would OR them and each would become optional. And do NOT add a class
18
+ * level `@Policy(RbacPolicy)` alongside:
19
+ *
20
+ * `@spinajs/http` combines policies at three levels ( see `createPolicyGate` in
21
+ * `http/src/route-builder.ts` ): AND inside one `@Policy()` group, OR between
22
+ * the groups declared at one scope, AND between the controller scope and the
23
+ * route scope. `@Permission()` already pushes `RbacPolicy` as a group on the
24
+ * ROUTE ( `rbac-http/src/decorators.ts` ), so:
25
+ *
26
+ * - controller scope holds exactly ONE group,
27
+ * `[NoTokenAuthPolicy, NoImpersonationPolicy]`. A lone group cannot be ORed
28
+ * away, so both are a hard requirement of EVERY route on this controller,
29
+ * including any route added later.
30
+ * - route scope holds `[RbacPolicy]` from `@Permission`, which demands an
31
+ * authorized session AND the declared grant.
32
+ *
33
+ * Adding `@Policy(RbacPolicy)` at class level would make the controller scope
34
+ * `[NoTokenAuthPolicy, NoImpersonationPolicy] OR [RbacPolicy]`, and satisfying
35
+ * `RbacPolicy` alone would then discharge the whole scope - both invariants
36
+ * would rest on nothing but RbacPolicy's own session check, which does not look
37
+ * at impersonation at all.
38
+ *
39
+ * @tags AccessTokens
40
+ */
41
+ export declare class AccessTokenController extends BaseController {
42
+ /**
43
+ * List own access tokens
44
+ * Hashes are never returned - `Token` is `@Hidden()` on the model, so the
45
+ * dehydrated rows carry the uuid, label, roles and timestamps only.
46
+ * @security cookieAuth
47
+ * @response 200 Own tokens
48
+ * @response 401 Unauthorized - valid session required
49
+ * @response 403 Forbidden - access tokens cannot be used on this route
50
+ */
51
+ list(user: UserModel): Promise<Ok<unknown>>;
52
+ /**
53
+ * Create an access token
54
+ * The plaintext appears in this response only and cannot be retrieved again.
55
+ * Roles must be a subset of the caller's own roles.
56
+ * @security cookieAuth
57
+ * @response 200 Token created, `Plaintext` returned once
58
+ * @response 400 Requested roles are not held by the caller
59
+ * @response 401 Unauthorized - valid session required
60
+ * @response 403 Forbidden - access tokens cannot be used on this route
61
+ */
62
+ create(user: UserModel, dto: CreateTokenDto): Promise<Ok<unknown> | BadRequestResponse>;
63
+ /**
64
+ * Delete ( revoke ) an own token
65
+ * @security cookieAuth
66
+ * @param uuid Public identifier of the token
67
+ * @response 200 Token deleted
68
+ * @response 401 Unauthorized - valid session required
69
+ * @response 403 Forbidden - access tokens cannot be used on this route
70
+ * @response 404 No such token for this user
71
+ */
72
+ delete(user: UserModel, uuid: string): Promise<Ok | NotFound>;
73
+ /**
74
+ * Grant a role to an own token
75
+ * The role must be held by the caller - a token can never carry more than its
76
+ * owner does.
77
+ * @security cookieAuth
78
+ * @param uuid Public identifier of the token
79
+ * @param role Role name to grant
80
+ * @response 200 Updated token
81
+ * @response 400 Role is not held by the caller
82
+ * @response 401 Unauthorized - valid session required
83
+ * @response 403 Forbidden - access tokens cannot be used on this route
84
+ * @response 404 No such token for this user
85
+ */
86
+ grantRole(user: UserModel, uuid: string, role: string): Promise<Ok<unknown> | NotFound | BadRequestResponse>;
87
+ /**
88
+ * Revoke a role from an own token
89
+ * A token must keep at least one role; dropping the last one is refused with
90
+ * 400 - deleting the token is the way to revoke it entirely.
91
+ * @security cookieAuth
92
+ * @param uuid Public identifier of the token
93
+ * @param role Role name to revoke
94
+ * @response 200 Updated token
95
+ * @response 400 Cannot revoke the token's last role
96
+ * @response 401 Unauthorized - valid session required
97
+ * @response 403 Forbidden - access tokens cannot be used on this route
98
+ * @response 404 No such token for this user
99
+ */
100
+ revokeRole(user: UserModel, uuid: string, role: string): Promise<Ok<unknown> | NotFound | BadRequestResponse>;
101
+ /**
102
+ * Resolves a token by uuid WITHIN the caller's own tokens - the ownership
103
+ * boundary of this whole controller.
104
+ */
105
+ protected own(user: UserModel, uuid: string): Promise<AccessToken | undefined>;
106
+ /**
107
+ * Wire shape of one token: the dehydrated row, with timestamps as ISO
108
+ * instants and `Roles` put back as a real array.
109
+ *
110
+ * `dehydrate()` runs every column through its converter's `toDB` direction -
111
+ * the STORAGE encoding, which is not the API contract in two places:
112
+ *
113
+ * - `dateTimeFormat: 'iso'` is what turns `CreatedAt` / `ExpiresAt` /
114
+ * `LastUsedAt` into offset-carrying ISO strings. Without it the sql
115
+ * converter emits its driver format ( `"2026-08-11 10:00:00"` ), which
116
+ * names no offset at all, so a client has to guess the zone. Every other
117
+ * user-bearing response in the repo dehydrates with this option - see
118
+ * `rbac-http-user/src/controllers/UserController.ts` - and a plain
119
+ * `toJSON()` is exactly `dehydrate()` with the option missing.
120
+ * - `@Set()`'s converter joins the role list into `"user,admin"`. Left
121
+ * alone, `Roles` reaches clients as a string that only looks like a list,
122
+ * which no generated client parses back.
123
+ *
124
+ * `@Hidden()` columns ( `Token`, `Id` ) are dropped by `dehydrate` itself and
125
+ * `user_id` is skipped as the `User` relation's foreign key, so the hash still
126
+ * never leaves here.
127
+ */
128
+ protected toWire(token: AccessToken): Record<string, unknown>;
129
+ /**
130
+ * Turns the actions layer's role refusals into a 400.
131
+ *
132
+ * `ErrorCode` has no entry in the http error map, so an uncaught one leaves as
133
+ * a 500 - and "you asked for a role you do not have" / "a token must keep one
134
+ * role" are the caller's mistakes, not the server's. Anything else is rethrown
135
+ * untouched so a genuine failure still reaches the error handler.
136
+ */
137
+ protected roleError(err: unknown): BadRequestResponse;
138
+ }
139
+ //# sourceMappingURL=AccessTokenController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccessTokenController.d.ts","sourceRoot":"","sources":["../../../src/controllers/AccessTokenController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAA4B,QAAQ,EAAE,EAAE,EAA4B,MAAM,eAAe,CAAC;AACrI,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,eAAe,CAAC;AAKlD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAI5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAGa,qBAAsB,SAAQ,cAAc;IACvD;;;;;;;;OAQG;IAGU,IAAI,CAAS,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAG/D;IAED;;;;;;;;;OASG;IAGU,MAAM,CAAS,IAAI,EAAE,SAAS,EAAU,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,CASnH;IAED;;;;;;;;OAQG;IAGU,MAAM,CAAS,IAAI,EAAE,SAAS,EAAW,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC,CAQ1F;IAED;;;;;;;;;;;;OAYG;IAGU,SAAS,CAAS,IAAI,EAAE,SAAS,EAAW,IAAI,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,QAAQ,GAAG,kBAAkB,CAAC,CAYlJ;IAED;;;;;;;;;;;;OAYG;IAGU,UAAU,CAAS,IAAI,EAAE,SAAS,EAAW,IAAI,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,QAAQ,GAAG,kBAAkB,CAAC,CAYnJ;IAED;;;OAGG;IACH,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAE7E;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE5D;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CAMpD;CACF"}