@rockster/core 0.0.4 → 0.1.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.
Files changed (318) hide show
  1. package/access/access.module.js +3 -7
  2. package/access/access.module.js.map +1 -1
  3. package/access/constants.d.ts +2 -0
  4. package/access/constants.js +6 -0
  5. package/access/constants.js.map +1 -0
  6. package/access/controllers/controllers.d.ts +2 -1
  7. package/access/controllers/controllers.js +3 -1
  8. package/access/controllers/controllers.js.map +1 -1
  9. package/access/controllers/scope-access-profile.controller.d.ts +17 -0
  10. package/access/controllers/scope-access-profile.controller.js +111 -0
  11. package/access/controllers/scope-access-profile.controller.js.map +1 -0
  12. package/access/controllers/scope-group-user.controller.d.ts +11 -4
  13. package/access/controllers/scope-group-user.controller.js +57 -9
  14. package/access/controllers/scope-group-user.controller.js.map +1 -1
  15. package/access/controllers/scope-group.controller.d.ts +8 -5
  16. package/access/controllers/scope-group.controller.js +66 -12
  17. package/access/controllers/scope-group.controller.js.map +1 -1
  18. package/access/controllers/scope-owner.controller.d.ts +3 -2
  19. package/access/controllers/scope-owner.controller.js +18 -4
  20. package/access/controllers/scope-owner.controller.js.map +1 -1
  21. package/access/controllers/scope-user.controller.d.ts +2 -2
  22. package/access/controllers/scope-user.controller.js +19 -5
  23. package/access/controllers/scope-user.controller.js.map +1 -1
  24. package/access/decorators/context-params.decorator.d.ts +2 -0
  25. package/access/decorators/context-params.decorator.js +13 -0
  26. package/access/decorators/context-params.decorator.js.map +1 -0
  27. package/access/decorators/index.d.ts +2 -0
  28. package/access/decorators/index.js +19 -0
  29. package/access/decorators/index.js.map +1 -0
  30. package/access/decorators/scope-context-id-resolver.decorator.d.ts +10 -0
  31. package/access/decorators/scope-context-id-resolver.decorator.js +22 -0
  32. package/access/decorators/scope-context-id-resolver.decorator.js.map +1 -0
  33. package/access/entities/entities.d.ts +3 -1
  34. package/access/entities/entities.js +4 -0
  35. package/access/entities/entities.js.map +1 -1
  36. package/access/entities/index.d.ts +2 -0
  37. package/access/entities/index.js +2 -0
  38. package/access/entities/index.js.map +1 -1
  39. package/access/entities/scope-access-profile-key.d.ts +6 -0
  40. package/access/entities/scope-access-profile-key.js +40 -0
  41. package/access/entities/scope-access-profile-key.js.map +1 -0
  42. package/access/entities/scope-access-profile.d.ts +6 -0
  43. package/access/entities/scope-access-profile.js +37 -0
  44. package/access/entities/scope-access-profile.js.map +1 -0
  45. package/access/entities/scope-group.d.ts +3 -0
  46. package/access/entities/scope-group.js +16 -0
  47. package/access/entities/scope-group.js.map +1 -1
  48. package/access/functions/assert-context-admin-access.d.ts +15 -0
  49. package/access/functions/assert-context-admin-access.js +62 -0
  50. package/access/functions/assert-context-admin-access.js.map +1 -0
  51. package/access/functions/assert-master-or-owner.d.ts +9 -0
  52. package/access/functions/assert-master-or-owner.js +40 -0
  53. package/access/functions/assert-master-or-owner.js.map +1 -0
  54. package/access/functions/assert-scope-action-access.d.ts +32 -0
  55. package/access/functions/assert-scope-action-access.js +189 -0
  56. package/access/functions/assert-scope-action-access.js.map +1 -0
  57. package/access/functions/build-scope-resolver-initial-data.d.ts +4 -0
  58. package/access/functions/build-scope-resolver-initial-data.js +17 -0
  59. package/access/functions/build-scope-resolver-initial-data.js.map +1 -0
  60. package/access/functions/describe-action-scope.d.ts +9 -0
  61. package/access/functions/describe-action-scope.js +27 -0
  62. package/access/functions/describe-action-scope.js.map +1 -0
  63. package/access/functions/index.d.ts +5 -0
  64. package/access/functions/index.js +5 -0
  65. package/access/functions/index.js.map +1 -1
  66. package/access/functions/init-scope-service-executors.d.ts +3 -0
  67. package/access/functions/init-scope-service-executors.js +38 -0
  68. package/access/functions/init-scope-service-executors.js.map +1 -0
  69. package/access/functions/normalize-scope-keys.d.ts +4 -0
  70. package/access/functions/normalize-scope-keys.js +17 -0
  71. package/access/functions/normalize-scope-keys.js.map +1 -0
  72. package/access/functions/register-scope.d.ts +16 -5
  73. package/access/functions/register-scope.js +57 -45
  74. package/access/functions/register-scope.js.map +1 -1
  75. package/access/functions/resolve-scope-context-id.d.ts +9 -0
  76. package/access/functions/resolve-scope-context-id.js +71 -0
  77. package/access/functions/resolve-scope-context-id.js.map +1 -0
  78. package/access/functions/warn-if-public.d.ts +12 -0
  79. package/access/functions/warn-if-public.js +20 -0
  80. package/access/functions/warn-if-public.js.map +1 -0
  81. package/access/index.d.ts +2 -0
  82. package/access/index.js +2 -0
  83. package/access/index.js.map +1 -1
  84. package/access/interfaces/index.d.ts +1 -0
  85. package/access/interfaces/index.js +1 -0
  86. package/access/interfaces/index.js.map +1 -1
  87. package/access/interfaces/resolve-scope-context-id.d.ts +21 -0
  88. package/access/interfaces/resolve-scope-context-id.js +3 -0
  89. package/access/interfaces/resolve-scope-context-id.js.map +1 -0
  90. package/access/interfaces/scope-service-registry.d.ts +16 -1
  91. package/access/interfaces/scope-service.d.ts +6 -7
  92. package/access/models/scope-access-profile-keys-update.d.ts +5 -0
  93. package/access/models/scope-access-profile-keys-update.js +27 -0
  94. package/access/models/scope-access-profile-keys-update.js.map +1 -0
  95. package/access/models/scope-group-apply-access-profile.d.ts +6 -0
  96. package/access/models/scope-group-apply-access-profile.js +32 -0
  97. package/access/models/scope-group-apply-access-profile.js.map +1 -0
  98. package/access/models/scope-user-mapped.d.ts +1 -0
  99. package/access/models/scope-user-mapped.js +6 -0
  100. package/access/models/scope-user-mapped.js.map +1 -1
  101. package/access/models/scope-user.js +4 -2
  102. package/access/models/scope-user.js.map +1 -1
  103. package/access/queries/scope-access-profile.query.d.ts +1 -0
  104. package/access/queries/scope-access-profile.query.js +10 -0
  105. package/access/queries/scope-access-profile.query.js.map +1 -0
  106. package/access/queries/scope-group.query.js +9 -2
  107. package/access/queries/scope-group.query.js.map +1 -1
  108. package/access/services/index.d.ts +1 -0
  109. package/access/services/index.js +1 -0
  110. package/access/services/index.js.map +1 -1
  111. package/access/services/scope-access-profile.service.d.ts +13 -0
  112. package/access/services/scope-access-profile.service.js +75 -0
  113. package/access/services/scope-access-profile.service.js.map +1 -0
  114. package/access/services/scope-access.service.js +4 -2
  115. package/access/services/scope-access.service.js.map +1 -1
  116. package/access/services/scope-group-user.service.js +2 -2
  117. package/access/services/scope-group-user.service.js.map +1 -1
  118. package/access/services/scope-group.service.d.ts +10 -0
  119. package/access/services/scope-group.service.js +38 -1
  120. package/access/services/scope-group.service.js.map +1 -1
  121. package/access/services/scope-owner.service.d.ts +3 -0
  122. package/access/services/scope-owner.service.js +26 -1
  123. package/access/services/scope-owner.service.js.map +1 -1
  124. package/command/services/post-action-builder.js +19 -17
  125. package/command/services/post-action-builder.js.map +1 -1
  126. package/command/services/remove-action-builder.js +30 -22
  127. package/command/services/remove-action-builder.js.map +1 -1
  128. package/controllers/interfaces/controller-property.d.ts +7 -1
  129. package/controllers/services/default-action-builder.js +12 -30
  130. package/controllers/services/default-action-builder.js.map +1 -1
  131. package/controllers/services/restful-action-builder.js +25 -1
  132. package/controllers/services/restful-action-builder.js.map +1 -1
  133. package/core/contexts/request-context.d.ts +5 -0
  134. package/core/contexts/request-context.js +6 -0
  135. package/core/contexts/request-context.js.map +1 -0
  136. package/core/core.controller.js +6 -1
  137. package/core/core.controller.js.map +1 -1
  138. package/core/interfaces/action-docs.d.ts +15 -0
  139. package/core/interfaces/request-context.d.ts +5 -0
  140. package/core/services/request-router.js +2 -1
  141. package/core/services/request-router.js.map +1 -1
  142. package/database/database.controller.d.ts +1 -3
  143. package/database/database.controller.js +1 -5
  144. package/database/database.controller.js.map +1 -1
  145. package/database/decorators/protect-entity.decorator.d.ts +1 -0
  146. package/database/decorators/protect-entity.decorator.js +2 -3
  147. package/database/decorators/protect-entity.decorator.js.map +1 -1
  148. package/database/decorators/protected-entity.decorator.d.ts +1 -0
  149. package/database/decorators/protected-entity.decorator.js +2 -16
  150. package/database/decorators/protected-entity.decorator.js.map +1 -1
  151. package/database/functions/inject-repository-handle.js +4 -3
  152. package/database/functions/inject-repository-handle.js.map +1 -1
  153. package/database/interfaces/entity-object.d.ts +0 -6
  154. package/database/interfaces/index.d.ts +0 -1
  155. package/database/interfaces/index.js +0 -1
  156. package/database/interfaces/index.js.map +1 -1
  157. package/database/interfaces/repository.d.ts +8 -8
  158. package/docs/docs.module.js +3 -1
  159. package/docs/docs.module.js.map +1 -1
  160. package/docs/migrations/1747584000000-CreateDocsTables.d.ts +5 -0
  161. package/docs/migrations/1747584000000-CreateDocsTables.js +90 -0
  162. package/docs/migrations/1747584000000-CreateDocsTables.js.map +1 -0
  163. package/docs/migrations/migrations.d.ts +2 -0
  164. package/docs/migrations/migrations.js +8 -0
  165. package/docs/migrations/migrations.js.map +1 -0
  166. package/global.d.ts +2 -0
  167. package/global.js +1 -0
  168. package/global.js.map +1 -1
  169. package/index.d.ts +2 -1
  170. package/index.js +2 -1
  171. package/index.js.map +1 -1
  172. package/jobs/jobs.controller.d.ts +2 -0
  173. package/jobs/jobs.controller.js +20 -16
  174. package/jobs/jobs.controller.js.map +1 -1
  175. package/package.json +70 -70
  176. package/query/functions/add-join.js +2 -13
  177. package/query/functions/add-join.js.map +1 -1
  178. package/query/functions/create-query-builder.js +0 -10
  179. package/query/functions/create-query-builder.js.map +1 -1
  180. package/query/functions/execute-query.js +34 -0
  181. package/query/functions/execute-query.js.map +1 -1
  182. package/query/functions/load-properties.js +73 -5
  183. package/query/functions/load-properties.js.map +1 -1
  184. package/query/services/query-action-builder.js +12 -18
  185. package/query/services/query-action-builder.js.map +1 -1
  186. package/remote-logs/dtos/index.d.ts +2 -0
  187. package/remote-logs/dtos/index.js +19 -0
  188. package/remote-logs/dtos/index.js.map +1 -0
  189. package/remote-logs/dtos/remote-log-hooks.dto.d.ts +72 -0
  190. package/remote-logs/dtos/remote-log-hooks.dto.js +280 -0
  191. package/remote-logs/dtos/remote-log-hooks.dto.js.map +1 -0
  192. package/remote-logs/dtos/remote-log-search.dto.d.ts +34 -0
  193. package/remote-logs/dtos/remote-log-search.dto.js +146 -0
  194. package/remote-logs/dtos/remote-log-search.dto.js.map +1 -0
  195. package/remote-logs/environment.d.ts +4 -0
  196. package/remote-logs/environment.js +5 -0
  197. package/remote-logs/environment.js.map +1 -0
  198. package/remote-logs/index.d.ts +3 -0
  199. package/remote-logs/index.js +20 -0
  200. package/remote-logs/index.js.map +1 -0
  201. package/remote-logs/interfaces/index.d.ts +1 -0
  202. package/remote-logs/interfaces/index.js +18 -0
  203. package/remote-logs/interfaces/index.js.map +1 -0
  204. package/remote-logs/interfaces/remote-logs-module-options.d.ts +8 -0
  205. package/remote-logs/interfaces/remote-logs-module-options.js +3 -0
  206. package/remote-logs/interfaces/remote-logs-module-options.js.map +1 -0
  207. package/remote-logs/remote-logs-hooks.controller.d.ts +60 -0
  208. package/remote-logs/remote-logs-hooks.controller.js +331 -0
  209. package/remote-logs/remote-logs-hooks.controller.js.map +1 -0
  210. package/remote-logs/remote-logs.controller.d.ts +8 -0
  211. package/remote-logs/remote-logs.controller.js +41 -0
  212. package/remote-logs/remote-logs.controller.js.map +1 -0
  213. package/remote-logs/remote-logs.module.d.ts +12 -0
  214. package/remote-logs/remote-logs.module.js +107 -0
  215. package/remote-logs/remote-logs.module.js.map +1 -0
  216. package/remote-logs/services/opensearch.service.d.ts +13 -0
  217. package/remote-logs/services/opensearch.service.js +167 -0
  218. package/remote-logs/services/opensearch.service.js.map +1 -0
  219. package/security/auth.controller.js +4 -4
  220. package/security/auth.controller.js.map +1 -1
  221. package/security/functions/add-protected.d.ts +2 -2
  222. package/security/functions/add-protected.js +8 -5
  223. package/security/functions/add-protected.js.map +1 -1
  224. package/security/functions/create-authentication-interceptor.d.ts +44 -0
  225. package/security/functions/create-authentication-interceptor.js +114 -0
  226. package/security/functions/create-authentication-interceptor.js.map +1 -0
  227. package/security/functions/find-auth-context.d.ts +1 -2
  228. package/security/functions/find-auth-context.js +6 -11
  229. package/security/functions/find-auth-context.js.map +1 -1
  230. package/security/index.d.ts +1 -0
  231. package/security/index.js +1 -0
  232. package/security/index.js.map +1 -1
  233. package/security/interfaces/authorization-schema.d.ts +3 -1
  234. package/security/services/authorization.service.d.ts +5 -3
  235. package/security/services/authorization.service.js +56 -37
  236. package/security/services/authorization.service.js.map +1 -1
  237. package/storage/services/routes.service.js +1 -1
  238. package/storage/services/routes.service.js.map +1 -1
  239. package/tasks/constants.d.ts +3 -0
  240. package/tasks/constants.js +2 -1
  241. package/tasks/constants.js.map +1 -1
  242. package/tasks/controllers/task.controller.d.ts +3 -2
  243. package/tasks/controllers/task.controller.js +11 -40
  244. package/tasks/controllers/task.controller.js.map +1 -1
  245. package/tasks/decorators/index.d.ts +1 -0
  246. package/tasks/decorators/index.js +1 -0
  247. package/tasks/decorators/index.js.map +1 -1
  248. package/tasks/decorators/task-payload.decorator.d.ts +1 -0
  249. package/tasks/decorators/task-payload.decorator.js +12 -0
  250. package/tasks/decorators/task-payload.decorator.js.map +1 -0
  251. package/tasks/decorators/task.decorator.js +3 -0
  252. package/tasks/decorators/task.decorator.js.map +1 -1
  253. package/tasks/functions/compile-all-task-post-hooks.d.ts +1 -0
  254. package/tasks/functions/compile-all-task-post-hooks.js +27 -0
  255. package/tasks/functions/compile-all-task-post-hooks.js.map +1 -0
  256. package/tasks/functions/compile-task-hook-handle.d.ts +6 -0
  257. package/tasks/functions/compile-task-hook-handle.js +67 -0
  258. package/tasks/functions/compile-task-hook-handle.js.map +1 -0
  259. package/tasks/functions/create-task-hook.d.ts +9 -0
  260. package/tasks/functions/create-task-hook.js +13 -0
  261. package/tasks/functions/create-task-hook.js.map +1 -0
  262. package/tasks/functions/create-task-message-post.js +2 -0
  263. package/tasks/functions/create-task-message-post.js.map +1 -1
  264. package/tasks/functions/register-task-post-hook-interceptors.d.ts +3 -0
  265. package/tasks/functions/register-task-post-hook-interceptors.js +86 -0
  266. package/tasks/functions/register-task-post-hook-interceptors.js.map +1 -0
  267. package/tasks/functions/run-task-post-hooks.d.ts +11 -0
  268. package/tasks/functions/run-task-post-hooks.js +18 -0
  269. package/tasks/functions/run-task-post-hooks.js.map +1 -0
  270. package/tasks/functions/task-message-operations.d.ts +18 -0
  271. package/tasks/functions/task-message-operations.js +100 -0
  272. package/tasks/functions/task-message-operations.js.map +1 -0
  273. package/tasks/functions/validate-task-payload.d.ts +2 -0
  274. package/tasks/functions/validate-task-payload.js +19 -0
  275. package/tasks/functions/validate-task-payload.js.map +1 -0
  276. package/tasks/hook-constants.d.ts +2 -0
  277. package/tasks/hook-constants.js +6 -0
  278. package/tasks/hook-constants.js.map +1 -0
  279. package/tasks/index.d.ts +3 -0
  280. package/tasks/index.js +3 -0
  281. package/tasks/index.js.map +1 -1
  282. package/tasks/interfaces/compiled-task-post-hooks.d.ts +17 -0
  283. package/tasks/interfaces/compiled-task-post-hooks.js +3 -0
  284. package/tasks/interfaces/compiled-task-post-hooks.js.map +1 -0
  285. package/tasks/interfaces/index.d.ts +3 -0
  286. package/tasks/interfaces/index.js +3 -0
  287. package/tasks/interfaces/index.js.map +1 -1
  288. package/tasks/interfaces/task-hook.d.ts +16 -0
  289. package/tasks/interfaces/task-hook.js +8 -0
  290. package/tasks/interfaces/task-hook.js.map +1 -0
  291. package/tasks/interfaces/task-object.d.ts +4 -0
  292. package/tasks/interfaces/task-post-hook.d.ts +2 -0
  293. package/{database/interfaces/protector.js → tasks/interfaces/task-post-hook.js} +1 -1
  294. package/tasks/interfaces/task-post-hook.js.map +1 -0
  295. package/tasks/interfaces/task-settings.d.ts +5 -0
  296. package/tasks/services/task-runner.service.d.ts +24 -3
  297. package/tasks/services/task-runner.service.js +66 -28
  298. package/tasks/services/task-runner.service.js.map +1 -1
  299. package/translations/controllers/translation.controller.d.ts +3 -1
  300. package/translations/controllers/translation.controller.js +17 -3
  301. package/translations/controllers/translation.controller.js.map +1 -1
  302. package/translations/services/translations.service.d.ts +1 -0
  303. package/translations/services/translations.service.js +25 -6
  304. package/translations/services/translations.service.js.map +1 -1
  305. package/translations/services/translator.service.d.ts +1 -0
  306. package/translations/services/translator.service.js +6 -0
  307. package/translations/services/translator.service.js.map +1 -1
  308. package/database/functions/use-protector.d.ts +0 -2
  309. package/database/functions/use-protector.js +0 -11
  310. package/database/functions/use-protector.js.map +0 -1
  311. package/database/interfaces/protector.d.ts +0 -51
  312. package/database/interfaces/protector.js.map +0 -1
  313. package/database/services/protect-builder.d.ts +0 -60
  314. package/database/services/protect-builder.js +0 -524
  315. package/database/services/protect-builder.js.map +0 -1
  316. package/security/functions/add-protect.d.ts +0 -2
  317. package/security/functions/add-protect.js +0 -11
  318. package/security/functions/add-protect.js.map +0 -1
@@ -0,0 +1,167 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OpenSearchService = void 0;
10
+ const class_injector_1 = require("@rockster/class-injector");
11
+ const environment_1 = require("../environment");
12
+ const CONNECT_TIMEOUT_MS = 10000;
13
+ let OpenSearchService = class OpenSearchService {
14
+ getAuthHeader() {
15
+ const { username, password } = environment_1.environment.options;
16
+ return `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
17
+ }
18
+ getIndexName(suffix) {
19
+ const config = environment_1.environment.options;
20
+ if (!config) {
21
+ throw new Error('RemoteLogsModule is not initialized');
22
+ }
23
+ if (!suffix) {
24
+ return config.index;
25
+ }
26
+ return `${config.index}${suffix.startsWith('-') ? suffix : `-${suffix}`}`;
27
+ }
28
+ async request(path, init = {}) {
29
+ const config = environment_1.environment.options;
30
+ if (!config) {
31
+ throw new Error('RemoteLogsModule is not initialized');
32
+ }
33
+ const url = `${config.url}${path.startsWith('/') ? path : `/${path}`}`;
34
+ return fetch(url, {
35
+ ...init,
36
+ headers: {
37
+ Authorization: this.getAuthHeader(),
38
+ 'Content-Type': 'application/json',
39
+ ...(init.headers ?? {}),
40
+ },
41
+ signal: init.signal ?? AbortSignal.timeout(CONNECT_TIMEOUT_MS),
42
+ });
43
+ }
44
+ async search(payload) {
45
+ const index = this.getIndexName();
46
+ const response = await this.request(`/${index}/_search`, {
47
+ method: 'POST',
48
+ body: JSON.stringify(payload),
49
+ });
50
+ if (!response.ok) {
51
+ const text = await response.text().catch(() => '');
52
+ throw new Error(`OpenSearch search failed (${response.status}): ${text.slice(0, 500)}`);
53
+ }
54
+ return await response.json();
55
+ }
56
+ async searchIndex(suffix, payload) {
57
+ await this.ensureIndex(suffix);
58
+ const index = this.getIndexName(suffix);
59
+ const response = await this.request(`/${index}/_search`, {
60
+ method: 'POST',
61
+ body: JSON.stringify(payload),
62
+ });
63
+ if (!response.ok) {
64
+ const text = await response.text().catch(() => '');
65
+ throw new Error(`OpenSearch search failed (${response.status}): ${text.slice(0, 500)}`);
66
+ }
67
+ return await response.json();
68
+ }
69
+ async indexDocument(suffix, id, document) {
70
+ await this.ensureIndex(suffix);
71
+ const index = this.getIndexName(suffix);
72
+ const response = await this.request(`/${index}/_doc/${encodeURIComponent(id)}`, {
73
+ method: 'PUT',
74
+ body: JSON.stringify(document),
75
+ });
76
+ if (!response.ok) {
77
+ const text = await response.text().catch(() => '');
78
+ throw new Error(`OpenSearch index failed (${response.status}): ${text.slice(0, 500)}`);
79
+ }
80
+ }
81
+ async updateDocument(suffix, id, document) {
82
+ await this.ensureIndex(suffix);
83
+ const index = this.getIndexName(suffix);
84
+ const response = await this.request(`/${index}/_update/${encodeURIComponent(id)}`, {
85
+ method: 'POST',
86
+ body: JSON.stringify({ doc: document }),
87
+ });
88
+ if (!response.ok) {
89
+ const text = await response.text().catch(() => '');
90
+ throw new Error(`OpenSearch update failed (${response.status}): ${text.slice(0, 500)}`);
91
+ }
92
+ }
93
+ async getDocument(suffix, id) {
94
+ await this.ensureIndex(suffix);
95
+ const index = this.getIndexName(suffix);
96
+ const response = await this.request(`/${index}/_doc/${encodeURIComponent(id)}`, {
97
+ method: 'GET',
98
+ });
99
+ if (response.status === 404) {
100
+ return null;
101
+ }
102
+ if (!response.ok) {
103
+ const text = await response.text().catch(() => '');
104
+ throw new Error(`OpenSearch get failed (${response.status}): ${text.slice(0, 500)}`);
105
+ }
106
+ const payload = await response.json();
107
+ return payload._source ?? null;
108
+ }
109
+ async deleteDocument(suffix, id) {
110
+ const index = this.getIndexName(suffix);
111
+ const response = await this.request(`/${index}/_doc/${encodeURIComponent(id)}`, {
112
+ method: 'DELETE',
113
+ });
114
+ if (!response.ok && response.status !== 404) {
115
+ const text = await response.text().catch(() => '');
116
+ throw new Error(`OpenSearch delete failed (${response.status}): ${text.slice(0, 500)}`);
117
+ }
118
+ }
119
+ async ensureIndex(suffix) {
120
+ const index = this.getIndexName(suffix);
121
+ const response = await this.request(`/${index}`, { method: 'HEAD' });
122
+ if (response.ok) {
123
+ return;
124
+ }
125
+ if (response.status !== 404) {
126
+ return;
127
+ }
128
+ const mappings = suffix === 'apps'
129
+ ? {
130
+ properties: {
131
+ appId: { type: 'keyword' },
132
+ date: { type: 'date' },
133
+ },
134
+ }
135
+ : suffix === 'settings' || suffix === 'hooks' || suffix === 'events'
136
+ ? {
137
+ properties: {
138
+ appId: { type: 'keyword' },
139
+ hookId: { type: 'keyword' },
140
+ date: { type: 'date' },
141
+ firedAt: { type: 'date' },
142
+ enabled: { type: 'boolean' },
143
+ url: { type: 'keyword' },
144
+ clearInterval: { type: 'keyword' },
145
+ logLevel: { type: 'keyword' },
146
+ name: { type: 'keyword' },
147
+ displayName: { type: 'keyword' },
148
+ read: { type: 'boolean' },
149
+ readBy: { type: 'keyword' },
150
+ },
151
+ }
152
+ : undefined;
153
+ const createResponse = await this.request(`/${index}`, {
154
+ method: 'PUT',
155
+ body: JSON.stringify(mappings ? { mappings } : {}),
156
+ });
157
+ if (!createResponse.ok) {
158
+ const text = await createResponse.text().catch(() => '');
159
+ throw new Error(`OpenSearch ensureIndex failed (${createResponse.status}): ${text.slice(0, 500)}`);
160
+ }
161
+ }
162
+ };
163
+ exports.OpenSearchService = OpenSearchService;
164
+ exports.OpenSearchService = OpenSearchService = __decorate([
165
+ (0, class_injector_1.Injectable)()
166
+ ], OpenSearchService);
167
+ //# sourceMappingURL=opensearch.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opensearch.service.js","sourceRoot":"./","sources":["remote-logs/services/opensearch.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6DAAsD;AAKtD,gDAA6C;AAE7C,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAG1B,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEjB,aAAa;QACpB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,yBAAW,CAAC,OAAQ,CAAC;QACpD,OAAO,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC/E,CAAC;IAES,YAAY,CAAC,MAAe;QACnC,MAAM,MAAM,GAAG,yBAAW,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC,KAAK,CAAC;QACvB,CAAC;QACD,OAAO,GAAG,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,EAAE,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,OAAoB,EAAE;QACzD,MAAM,MAAM,GAAG,yBAAW,CAAC,OAAO,CAAC;QACnC,IA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,EAAE,EAAE;YACpD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpD,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACzD,MAAM,IAAI,KAAK,CACZ,kCAAkC,cAAc,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CACnF,CAAC;QACL,CAAC;IACJ,CAAC;CACH,CAAA;AA3MY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,2BAAU,GAAE;GACA,iBAAiB,CA2M7B"}
@@ -33,13 +33,13 @@ let AuthController = class AuthController {
33
33
  .contexts;
34
34
  for (const preSchemaContext of env_1.env.preSchema.contexts) {
35
35
  const context = contexts
36
- .find((context) => {
37
- return context.protector() === preSchemaContext.protector();
36
+ .find((registered) => {
37
+ return registered.name.toLowerCase() === preSchemaContext.name.toLowerCase();
38
38
  });
39
39
  if (!context) {
40
- this.logger.throw(new Error(`AuthContext not found for {${preSchemaContext.protector().name}}`));
40
+ this.logger.throw(new Error(`AuthContext not found for {${preSchemaContext.name}}`));
41
41
  }
42
- for (const key of preSchemaContext.keys) {
42
+ for (const key of preSchemaContext.keys ?? []) {
43
43
  context
44
44
  .keys
45
45
  .pushIfNotExists(key, (source, target) => {
@@ -1 +1 @@
1
- {"version":3,"file":"auth.controller.js","sourceRoot":"./","sources":["security/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6DAGkC;AAClC,6CAA0C;AAC1C,+BAA4B;AAE5B,kEAA8D;AAC9D,sCAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAc;IAApB;QAEM,W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Callback } from "../../common";
2
1
  import { IAuthorizationKey } from "../interfaces/authorization-schema";
3
- export declare const addProtected: (protector: GetTypeCallback, keys: IAuthorizationKey[]) => void;
2
+ /** Registers authorization keys for a scope context name (legacy security schema). */
3
+ export declare const addProtected: (contextName: string, keys?: IAuthorizationKey[]) => void;
@@ -2,17 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProtected = void 0;
4
4
  const env_1 = require("../env");
5
- const addProtected = (protector, keys) => {
5
+ /** Registers authorization keys for a scope context name (legacy security schema). */
6
+ const addProtected = (contextName, keys = []) => {
6
7
  let context = env_1.env
7
8
  .preSchema
8
9
  .contexts
9
- .find((context) => {
10
- return context.protector() === protector();
10
+ .find((entry) => {
11
+ return entry.name.toLowerCase() === contextName.toLowerCase();
11
12
  });
12
13
  if (!context) {
13
14
  context = {
14
- protector: protector,
15
- keys: keys || []
15
+ name: contextName,
16
+ keys: keys || [],
17
+ ownerKey: { name: "owner" },
18
+ adminKey: { name: "admin" },
16
19
  };
17
20
  env_1.env.preSchema.contexts.push(context);
18
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"add-protected.js","sourceRoot":"./","sources":["security/functions/add-protected.ts"],"names":[],"mappings":";;;AACA,gCAA4B;AAMrB,MAAM,YAAY,GAAG,CACzB,SAA0B,EAC1B,IAAyB,EAC1B,EAAE;IACD,IAAI,OAAO,GAAG,SAAG;SACb,SAAS;SACT,QAAQ;SACR,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACf,OAAO,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;IACN,IAAI,CAAC,OAAO,EAAE,CAAC;QACZ,OAAO,GAAG;YACP,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,IAAI,IAAI,EAAE;SACO,CAAC;QAC3B,SAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;SAAM,CAAC;QACL,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9B,CAAC;AACJ,CAAC,CAAA;AAnBY,QAAA,YAAY,gBAmBxB"}
1
+ {"version":3,"file":"add-protected.js","sourceRoot":"./","sources":["security/functions/add-protected.ts"],"names":[],"mappings":";;;AAAA,gCAA6B;AAG7B,sFAAsF;AAC/E,MAAM,YAAY,GAAG,CACzB,WAAmB,EACnB,OAA4B,EAAE,EAC/B,EAAE;IACD,IAAI,OAAO,GAAG,SAAG;SACb,SAAS;SACT,QAAQ;SACR,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;IACjE,CAAC,CAAC,CAAC;IAEN,IAAI,CAAC,OAAO,EAAE,CAAC;QACZ,OAAO,GAAG;YACP,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;YAC3B,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;SACJ,CAAC;QAC3B,SAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;SAAM,CAAC;QACL,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9B,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,YAAY,gBAsBvB"}
@@ -0,0 +1,44 @@
1
+ import { Instantiable } from "@rockster/common";
2
+ import { IAuthController } from "../interfaces/auth-controller";
3
+ /** Config for {@link createAuthenticationInterceptor}. */
4
+ export type AuthenticationInterceptorConfig = {
5
+ /** Unique name (registry key) — also the name you give your decorator. */
6
+ name: string;
7
+ /** Lazy ref to the auth service (implements {@link IAuthController}). */
8
+ service: () => Instantiable<IAuthController>;
9
+ /** Human description surfaced in the generated docs/SDK. */
10
+ description?: string;
11
+ /** Pipeline phase(s) to run on. Defaults to `onBeforeExecute`. */
12
+ filters?: string[];
13
+ };
14
+ /**
15
+ * Builds a **named** authentication decorator in the `createInterceptor` style,
16
+ * so each integration can name and document its own (e.g. `@ServiceApiAuth()`).
17
+ *
18
+ * The produced decorator marks the endpoint as `public` (it opts out of the
19
+ * default auth service) **and** `authenticated` (it runs a special auth
20
+ * strategy). That suppresses the standing `[PUBLIC]` warning and lets the docs
21
+ * present a custom auth requirement instead of "no auth".
22
+ *
23
+ * The interceptor runs the configured service (lazy `() => Service`, same
24
+ * `IAuthController` shape as the default `AuthController`) and, on success, sets
25
+ * `context.session` / `req.session`; it throws `UnauthorizedError` otherwise.
26
+ *
27
+ * Usage:
28
+ * ```ts
29
+ * export const ServiceApiAuth = createAuthenticationInterceptor({
30
+ * name: "ServiceApiAuth",
31
+ * service: () => ServiceApiKeyAuthService,
32
+ * description: "Autentica via API key de serviço (header X-Api-Key).",
33
+ * });
34
+ *
35
+ * @ServiceApiAuth()
36
+ * @Get("/things")
37
+ * async list() { ... }
38
+ * ```
39
+ *
40
+ * Note: it authenticates in the execute phase. To combine special auth with
41
+ * scope keys on the **same** endpoint, the auth must run before scope
42
+ * assertion — refine the `filters` when that case first appears.
43
+ */
44
+ export declare function createAuthenticationInterceptor<TParams = void>(config: AuthenticationInterceptorConfig): (params?: TParams) => PropertyDecorator;
@@ -0,0 +1,114 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createAuthenticationInterceptor = createAuthenticationInterceptor;
10
+ const class_injector_1 = require("@rockster/class-injector");
11
+ const common_1 = require("@rockster/common");
12
+ const core_1 = require("../../core");
13
+ /** Auth services are singletons — instantiate each once. */
14
+ const instanceCache = new Map();
15
+ async function resolveAuthService(ServiceRef) {
16
+ const ServiceClass = ServiceRef();
17
+ let instance = instanceCache.get(ServiceClass);
18
+ if (!instance) {
19
+ instance = (await (0, class_injector_1.createInstance)(ServiceClass));
20
+ instanceCache.set(ServiceClass, instance);
21
+ }
22
+ return instance;
23
+ }
24
+ let AuthenticationInterceptor = class AuthenticationInterceptor {
25
+ async intercept(args) {
26
+ const config = args.params?.__config;
27
+ if (!config) {
28
+ throw new common_1.UnauthorizedError();
29
+ }
30
+ const request = args.req ?? args.context?.httpRequest;
31
+ const service = await resolveAuthService(config.service);
32
+ if (request?.isWs && service.wsInterceptor) {
33
+ const connection = await service.wsInterceptor(request);
34
+ if (!connection) {
35
+ throw new common_1.UnauthorizedError();
36
+ }
37
+ if (args.context) {
38
+ args.context.session = connection;
39
+ args.context.isAuthenticated = true;
40
+ }
41
+ if (args.req) {
42
+ args.req.session = connection;
43
+ }
44
+ return;
45
+ }
46
+ if (!request) {
47
+ throw new common_1.UnauthorizedError();
48
+ }
49
+ const session = await service.httpInterceptor(request);
50
+ if (!session) {
51
+ throw new common_1.UnauthorizedError();
52
+ }
53
+ if (args.context) {
54
+ args.context.session = session;
55
+ args.context.isAuthenticated = true;
56
+ }
57
+ if (args.req) {
58
+ args.req.session = session;
59
+ }
60
+ }
61
+ };
62
+ AuthenticationInterceptor = __decorate([
63
+ (0, class_injector_1.Injectable)()
64
+ ], AuthenticationInterceptor);
65
+ /**
66
+ * Builds a **named** authentication decorator in the `createInterceptor` style,
67
+ * so each integration can name and document its own (e.g. `@ServiceApiAuth()`).
68
+ *
69
+ * The produced decorator marks the endpoint as `public` (it opts out of the
70
+ * default auth service) **and** `authenticated` (it runs a special auth
71
+ * strategy). That suppresses the standing `[PUBLIC]` warning and lets the docs
72
+ * present a custom auth requirement instead of "no auth".
73
+ *
74
+ * The interceptor runs the configured service (lazy `() => Service`, same
75
+ * `IAuthController` shape as the default `AuthController`) and, on success, sets
76
+ * `context.session` / `req.session`; it throws `UnauthorizedError` otherwise.
77
+ *
78
+ * Usage:
79
+ * ```ts
80
+ * export const ServiceApiAuth = createAuthenticationInterceptor({
81
+ * name: "ServiceApiAuth",
82
+ * service: () => ServiceApiKeyAuthService,
83
+ * description: "Autentica via API key de serviço (header X-Api-Key).",
84
+ * });
85
+ *
86
+ * @ServiceApiAuth()
87
+ * @Get("/things")
88
+ * async list() { ... }
89
+ * ```
90
+ *
91
+ * Note: it authenticates in the execute phase. To combine special auth with
92
+ * scope keys on the **same** endpoint, the auth must run before scope
93
+ * assertion — refine the `filters` when that case first appears.
94
+ */
95
+ function createAuthenticationInterceptor(config) {
96
+ return core_1.createInterceptor.custom({
97
+ name: config.name,
98
+ filters: config.filters ?? [core_1.commonInterceptor.onBeforeExecute],
99
+ executor: AuthenticationInterceptor,
100
+ }, (decorator, interceptor) => {
101
+ return (params) => {
102
+ return (target, propertyKey) => {
103
+ const property = core.storage.createProperty(target, propertyKey);
104
+ property.public = true;
105
+ property.authenticated = true;
106
+ decorator(interceptor, {
107
+ __config: config,
108
+ params,
109
+ })(target, propertyKey);
110
+ };
111
+ };
112
+ });
113
+ }
114
+ //# sourceMappingURL=create-authentication-interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-authentication-interceptor.js","sourceRoot":"./","sources":["security/functions/create-authentication-interceptor.ts"],"names":[],"mappings":";;;;;;;;AAqHA,0EA2BC;AAhJD,6DAAsE;AACtE,6CAAmE;AACnE,qCAKoB;AAoBpB,4DAA4D;AAC5D,MAAM,aAAa,GAAG,IAAI,GAAG,EAAiC,CAAC;AAE/D,KAAK,UAAU,kBAAkB,CAC9B,UAA+C;IAE/C,MAAM,YAAY,GAAG,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BAChB,MAAM;iBACiB,CAAC,CAAC,MAAM,EAAE,WAAqB,CAAC,CAAC;YAC9D,CAAC,CAAC;QACL,CAAC,CAAC;IACL,CAAC,CACH,CAAC;AACL,CAAC"}
@@ -1,3 +1,2 @@
1
- import { Instantiable } from "@rockster/common";
2
1
  import { IAuthorizationContext } from "../interfaces/authorization-schema";
3
- export declare const findAuthContext: (nameOrTarget: string | Instantiable) => IAuthorizationContext;
2
+ export declare const findAuthContext: (contextName: string) => IAuthorizationContext;
@@ -3,21 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findAuthContext = void 0;
4
4
  const common_1 = require("@rockster/common");
5
5
  const env_1 = require("../env");
6
- const findAuthContext = (nameOrTarget) => {
7
- const check = typeof nameOrTarget === 'string'
8
- ? (source) => {
9
- return source.name.toLowerCase() === nameOrTarget.toLowerCase();
10
- }
11
- : (source) => {
12
- return source.protector() === nameOrTarget;
13
- };
6
+ const findAuthContext = (contextName) => {
14
7
  const authContext = env_1.env
15
8
  .schema
16
- .contexts
17
- .find(check);
9
+ ?.contexts
10
+ ?.find((source) => {
11
+ return source.name.toLowerCase() === contextName.toLowerCase();
12
+ });
18
13
  if (!authContext) {
19
14
  throw new common_1.NotFoundError({
20
- message: `AuthContext [${[nameOrTarget]}] not found`
15
+ message: `AuthContext [${contextName}] not found`,
21
16
  });
22
17
  }
23
18
  return authContext;
@@ -1 +1 @@
1
- {"version":3,"file":"find-auth-context.js","sourceRoot":"./","sources":["security/functions/find-auth-context.ts"],"names":[],"mappings":";;;AAAA,6CAG0B;AAC1B,gCAA6B;AAGtB,MAAM,eAAe,GAAG,CAAC,YAAmC,EAAE,EAAE;IACpE,MAAM,KAAK,GAAG,OAAO,YAAY,KAAK,QAAQ;QAC3C,CAAC,CAAC,CAAC,MAA6B,EAAE,EAAE;YACjC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,CAAC;QACnE,CAAC;QACD,CAAC,CAAC,CAAC,MAA6B,EAAE,EAAE;YACjC,OAAO,MAAM,CAAC,SAAS,EAAE,KAAK,YAAY,CAAA;QAC7C,CAAC,CAAA;IACJ,MAAM,WAAW,GAAG,SAAG;SACnB,MAAM;SACN,QAAQ;SACR,IAAI,CAAC,KAAK,CAAC,CAAC;IAChB,IAAI,CAAC,WAAW,EAAE,CAAC;QAChB,MAAM,IAAI,sBAAa,CAAC;YACrB,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,aAAa;SACtD,CAAC,CAAC;IACN,CAAC;IACD,OAAO,WAAW,CAAC;AACtB,CAAC,CAAA;AAlBY,QAAA,eAAe,mBAkB3B"}
1
+ {"version":3,"file":"find-auth-context.js","sourceRoot":"./","sources":["security/functions/find-auth-context.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AACjD,gCAA6B;AAGtB,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAyB,EAAE;IAC3E,MAAM,WAAW,GAAG,SAAG;SACnB,MAAM;QACP,EAAE,QAAQ;QACV,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;IAClE,CAAC,CAAC,CAAC;IAEN,IAAI,CAAC,WAAW,EAAE,CAAC;QAChB,MAAM,IAAI,sBAAa,CAAC;YACrB,OAAO,EAAE,gBAAgB,WAAW,aAAa;SACnD,CAAC,CAAC;IACN,CAAC;IAED,OAAO,WAAW,CAAC;AACtB,CAAC,CAAC;AAfW,QAAA,eAAe,mBAe1B"}
@@ -1,3 +1,4 @@
1
1
  export * from './interfaces';
2
2
  export * from './functions/is-auth-enabled';
3
+ export * from './functions/create-authentication-interceptor';
3
4
  export * from './interceptors';
package/security/index.js CHANGED
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./interfaces"), exports);
18
18
  __exportStar(require("./functions/is-auth-enabled"), exports);
19
+ __exportStar(require("./functions/create-authentication-interceptor"), exports);
19
20
  __exportStar(require("./interceptors"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"./","sources":["security/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8DAA4C;AAC5C,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"./","sources":["security/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8DAA4C;AAC5C,gFAA8D;AAC9D,iDAA+B"}
@@ -4,13 +4,15 @@ export interface IAuthorizationKey {
4
4
  description?: string;
5
5
  iconUrl?: string;
6
6
  group?: string;
7
+ /** @deprecated Protector module removed; kept for schema compatibility. */
7
8
  protector?: GetTypeCallback;
8
9
  }
9
10
  export interface IAuthorizationContext {
10
11
  name: string;
11
12
  description?: string;
12
13
  iconUrl?: string;
13
- protector: GetTypeCallback;
14
+ /** @deprecated Protector module removed; kept for schema compatibility. */
15
+ protector?: GetTypeCallback;
14
16
  keys?: IAuthorizationKey[];
15
17
  ownerKey: IAuthorizationKey;
16
18
  adminKey: IAuthorizationKey;
@@ -3,9 +3,11 @@ import { AuthContextData } from "../models/auth-context-data";
3
3
  import { GetUserPermissionsPayload } from "../models/get-user-permissions-payload";
4
4
  import { SetUserPermissionsPayload } from "../models/set-user-permissions-payload";
5
5
  export declare class AuthorizationService {
6
- getUserPermissions(payload: GetUserPermissionsPayload, userId: string, entityManager: EntityManager): Promise<{
6
+ getUserPermissions(payload: GetUserPermissionsPayload, _userId: string, _entityManager: EntityManager): Promise<{
7
7
  accessKeys: string[];
8
8
  }>;
9
- changeUserPermissions(payload: SetUserPermissionsPayload, userId: string, entityManager: EntityManager): Promise<void>;
10
- getAuthContextConfig(payload: AuthContextData, userId: string, entityManager: EntityManager): Promise<import("..").IAuthorizationContext>;
9
+ changeUserPermissions(payload: SetUserPermissionsPayload, userId: string, _entityManager: EntityManager): Promise<void>;
10
+ getAuthContextConfig(payload: AuthContextData, userId: string, _entityManager: EntityManager): Promise<import("..").IAuthorizationContext>;
11
+ protected assertCanManageContext(contextName: string, userId: string, contextId: string): Promise<void>;
12
+ protected assertScopeAccessService(): void;
11
13
  }
@@ -8,51 +8,70 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AuthorizationService = void 0;
10
10
  const class_injector_1 = require("@rockster/class-injector");
11
- const use_protector_1 = require("../../database/functions/use-protector");
11
+ const common_1 = require("@rockster/common");
12
+ const env_1 = require("../../access/env");
13
+ const get_is_owner_1 = require("../../access/functions/get-is-owner");
14
+ const get_user_keys_1 = require("../../access/functions/get-user-keys");
15
+ const normalize_scope_keys_1 = require("../../access/functions/normalize-scope-keys");
12
16
  const find_auth_context_1 = require("../functions/find-auth-context");
13
17
  let AuthorizationService = class AuthorizationService {
14
- async getUserPermissions(payload, userId, entityManager) {
15
- const authContext = (0, find_auth_context_1.findAuthContext)(payload.context);
16
- const target = authContext.protector();
17
- const protector = (0, use_protector_1.useProtector)(target);
18
- const accessKeys = await protector.getUserPermissions({
19
- context: authContext.name,
20
- contextId: payload.contextId,
21
- targetUserId: payload.userId,
22
- userId: userId,
23
- entityManager: entityManager
24
- });
18
+ async getUserPermissions(payload, _userId, _entityManager) {
19
+ this.assertScopeAccessService();
20
+ const accessKeys = payload.contextId
21
+ ? await env_1.env.scopeAccessService.getKeysWithCtx(payload.contextId, payload.userId)
22
+ : await env_1.env.scopeAccessService.getAllUserKeys(payload.userId);
25
23
  return { accessKeys };
26
24
  }
27
- async changeUserPermissions(payload, userId, entityManager) {
28
- const authContext = (0, find_auth_context_1.findAuthContext)(payload.context);
29
- const target = authContext.protector();
30
- const protector = (0, use_protector_1.useProtector)(target);
31
- await protector.setUserPermissions({
32
- context: authContext.name,
33
- contextId: payload.contextId,
34
- targetUserId: payload.userId,
35
- userId: userId,
36
- entityManager: entityManager,
37
- accessKeys: payload.accessKeys
38
- });
25
+ async changeUserPermissions(payload, userId, _entityManager) {
26
+ this.assertScopeAccessService();
27
+ if (!payload.contextId?.trim()) {
28
+ throw new common_1.ForbiddenError({
29
+ message: "contextId is required",
30
+ });
31
+ }
32
+ await this.assertCanManageContext(payload.context, userId, payload.contextId);
33
+ await env_1.env.scopeAccessService.updateKeys("user", payload.context, payload.contextId, payload.userId, (0, normalize_scope_keys_1.normalizeScopeKeys)(payload.accessKeys));
39
34
  }
40
- async getAuthContextConfig(payload, userId, entityManager) {
35
+ async getAuthContextConfig(payload, userId, _entityManager) {
41
36
  const authContext = (0, find_auth_context_1.findAuthContext)(payload.context);
42
- const protector = (0, use_protector_1.useProtector)(authContext.protector());
43
- const canReadKeys = [
44
- authContext.adminKey.name,
45
- authContext.ownerKey.name
46
- ];
47
- await protector.isAuthorized({
48
- keys: canReadKeys,
49
- userId: userId,
50
- context: payload.context,
51
- contextId: payload.contextId,
52
- entityManager
53
- });
37
+ if (payload.contextId) {
38
+ await this.assertCanManageContext(payload.context, userId, payload.contextId);
39
+ }
54
40
  return authContext;
55
41
  }
42
+ async assertCanManageContext(contextName, userId, contextId) {
43
+ const isOwner = await (0, get_is_owner_1.getIsOwner)(contextName, userId, contextId);
44
+ if (isOwner) {
45
+ return;
46
+ }
47
+ let authContext;
48
+ try {
49
+ authContext = (0, find_auth_context_1.findAuthContext)(contextName);
50
+ }
51
+ catch (error) {
52
+ if (error instanceof common_1.NotFoundError) {
53
+ throw new common_1.ForbiddenError({
54
+ message: "Action require permissions to execute",
55
+ });
56
+ }
57
+ throw error;
58
+ }
59
+ const userKeys = await (0, get_user_keys_1.getUserKeys)(userId, contextId);
60
+ const privilegedKeys = [
61
+ authContext.ownerKey?.name,
62
+ authContext.adminKey?.name,
63
+ ].filter((key) => Boolean(key));
64
+ if (!privilegedKeys.some((key) => userKeys.includes(key))) {
65
+ throw new common_1.ForbiddenError({
66
+ message: "Action require permissions to execute",
67
+ });
68
+ }
69
+ }
70
+ assertScopeAccessService() {
71
+ if (!env_1.env.scopeAccessService) {
72
+ throw new Error("ScopeAccessService is not initialized");
73
+ }
74
+ }
56
75
  };
57
76
  exports.AuthorizationService = AuthorizationService;
58
77
  exports.AuthorizationService = AuthorizationService = __decorate([