@tstdl/base 0.93.87 → 0.93.90

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 (314) hide show
  1. package/ai/genkit/helpers.d.ts +3 -1
  2. package/ai/genkit/helpers.js +3 -3
  3. package/api/server/gateway.d.ts +3 -0
  4. package/api/server/gateway.js +15 -4
  5. package/api/server/middlewares/catch-error.middleware.js +2 -4
  6. package/api/server/middlewares/cors.middleware.js +2 -3
  7. package/api/server/middlewares/csrf.middleware.d.ts +41 -0
  8. package/api/server/middlewares/csrf.middleware.js +108 -0
  9. package/api/server/middlewares/index.d.ts +1 -0
  10. package/api/server/middlewares/index.js +1 -0
  11. package/api/server/module.d.ts +8 -2
  12. package/api/server/module.js +14 -8
  13. package/api/server/tests/csrf.middleware.test.js +91 -0
  14. package/audit/drizzle/{0000_bored_stick.sql → 0000_lumpy_thunderball.sql} +3 -3
  15. package/audit/drizzle/meta/0000_snapshot.json +4 -4
  16. package/audit/drizzle/meta/_journal.json +2 -9
  17. package/audit/module.d.ts +4 -1
  18. package/audit/module.js +3 -2
  19. package/audit/schemas.d.ts +1 -1
  20. package/audit/types.d.ts +1 -1
  21. package/audit/types.js +1 -1
  22. package/authentication/client/authentication.service.d.ts +14 -1
  23. package/authentication/client/authentication.service.js +82 -23
  24. package/authentication/client/http-client.middleware.d.ts +6 -0
  25. package/authentication/client/http-client.middleware.js +36 -0
  26. package/authentication/client/module.js +8 -2
  27. package/authentication/models/service-account.model.d.ts +2 -2
  28. package/authentication/models/service-account.model.js +10 -5
  29. package/authentication/models/subject.model.d.ts +20 -5
  30. package/authentication/models/subject.model.js +34 -29
  31. package/authentication/models/system-account.model.d.ts +3 -2
  32. package/authentication/models/system-account.model.js +11 -5
  33. package/authentication/models/user.model.d.ts +2 -11
  34. package/authentication/models/user.model.js +5 -16
  35. package/authentication/server/authentication-api-request-token.provider.d.ts +0 -2
  36. package/authentication/server/authentication-api-request-token.provider.js +3 -11
  37. package/authentication/server/authentication.api-controller.d.ts +1 -2
  38. package/authentication/server/authentication.api-controller.js +8 -9
  39. package/authentication/server/authentication.audit.d.ts +3 -2
  40. package/authentication/server/authentication.service.d.ts +27 -1
  41. package/authentication/server/authentication.service.js +67 -18
  42. package/authentication/server/drizzle/{0000_normal_paper_doll.sql → 0000_soft_tag.sql} +25 -32
  43. package/authentication/server/drizzle/meta/0000_snapshot.json +180 -205
  44. package/authentication/server/drizzle/meta/_journal.json +2 -2
  45. package/authentication/server/helper.js +9 -2
  46. package/authentication/server/module.d.ts +4 -1
  47. package/authentication/server/module.js +9 -5
  48. package/authentication/server/schemas.d.ts +2 -1
  49. package/authentication/server/schemas.js +2 -2
  50. package/authentication/server/subject.service.d.ts +17 -11
  51. package/authentication/server/subject.service.js +86 -84
  52. package/authentication/tests/authentication-ancillary.service.test.d.ts +1 -0
  53. package/authentication/tests/authentication-ancillary.service.test.js +13 -0
  54. package/authentication/tests/authentication-secret-requirements.validator.test.d.ts +1 -0
  55. package/authentication/tests/authentication-secret-requirements.validator.test.js +29 -0
  56. package/authentication/tests/authentication.api-controller.test.d.ts +1 -0
  57. package/authentication/tests/authentication.api-controller.test.js +88 -0
  58. package/authentication/tests/authentication.api-request-token.provider.test.d.ts +1 -0
  59. package/authentication/tests/authentication.api-request-token.provider.test.js +48 -0
  60. package/authentication/tests/authentication.client-middleware.test.d.ts +1 -0
  61. package/authentication/tests/authentication.client-middleware.test.js +23 -0
  62. package/authentication/tests/authentication.client-service.test.d.ts +1 -0
  63. package/authentication/tests/authentication.client-service.test.js +70 -0
  64. package/authentication/tests/authentication.service.test.d.ts +1 -0
  65. package/authentication/tests/authentication.service.test.js +186 -0
  66. package/authentication/tests/authentication.test-ancillary-service.d.ts +9 -0
  67. package/authentication/tests/authentication.test-ancillary-service.js +27 -0
  68. package/authentication/tests/helper.test.d.ts +1 -0
  69. package/authentication/tests/helper.test.js +107 -0
  70. package/authentication/tests/secret-requirements.error.test.d.ts +1 -0
  71. package/authentication/tests/secret-requirements.error.test.js +14 -0
  72. package/authentication/tests/subject.service.test.d.ts +1 -0
  73. package/authentication/tests/subject.service.test.js +140 -0
  74. package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +1 -1
  75. package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
  76. package/circuit-breaker/postgres/module.d.ts +7 -1
  77. package/circuit-breaker/postgres/module.js +8 -6
  78. package/circuit-breaker/tests/circuit-breaker.test.js +2 -22
  79. package/document-management/api/document-management.api.js +2 -6
  80. package/document-management/server/services/document-validation.service.js +6 -5
  81. package/document-management/server/services/document-workflow.service.js +5 -5
  82. package/document-management/service-models/document-folders.view-model.d.ts +5 -2
  83. package/document-management/service-models/document-folders.view-model.js +42 -9
  84. package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
  85. package/examples/document-management/main.js +4 -4
  86. package/http/client/adapters/undici.adapter.d.ts +7 -5
  87. package/http/client/adapters/undici.adapter.js +13 -10
  88. package/http/client/module.d.ts +3 -1
  89. package/http/client/module.js +8 -9
  90. package/http/server/http-server.d.ts +2 -0
  91. package/http/server/node/module.d.ts +6 -2
  92. package/http/server/node/module.js +6 -4
  93. package/http/server/node/node-http-server.d.ts +2 -0
  94. package/http/server/node/node-http-server.js +7 -0
  95. package/http/types.d.ts +1 -1
  96. package/key-value-store/postgres/module.d.ts +7 -1
  97. package/key-value-store/postgres/module.js +7 -3
  98. package/lock/postgres/lock.js +0 -1
  99. package/lock/postgres/module.d.ts +7 -1
  100. package/lock/postgres/module.js +9 -5
  101. package/logger/formatter.d.ts +2 -0
  102. package/logger/formatters/json.js +2 -2
  103. package/logger/formatters/pretty-print.js +8 -10
  104. package/logger/logger.d.ts +1 -1
  105. package/logger/logger.js +15 -12
  106. package/message-bus/local/module.d.ts +5 -2
  107. package/message-bus/local/module.js +5 -4
  108. package/module/module.d.ts +2 -1
  109. package/module/module.js +3 -0
  110. package/module/modules/web-server.module.d.ts +11 -6
  111. package/module/modules/web-server.module.js +15 -10
  112. package/orm/decorators.d.ts +24 -1
  113. package/orm/decorators.js +40 -4
  114. package/orm/query/base.d.ts +17 -17
  115. package/orm/query/base.js +1 -1
  116. package/orm/repository.types.d.ts +45 -1
  117. package/orm/schemas/tsvector.js +1 -1
  118. package/orm/server/drizzle/schema-converter.d.ts +3 -1
  119. package/orm/server/drizzle/schema-converter.js +120 -14
  120. package/orm/server/index.d.ts +1 -0
  121. package/orm/server/index.js +1 -0
  122. package/orm/server/module.d.ts +4 -2
  123. package/orm/server/module.js +6 -5
  124. package/orm/server/query-converter.d.ts +6 -3
  125. package/orm/server/query-converter.js +32 -20
  126. package/orm/server/repository-config.d.ts +8 -0
  127. package/orm/server/repository-config.js +8 -0
  128. package/orm/server/repository.d.ts +117 -43
  129. package/orm/server/repository.js +757 -253
  130. package/orm/server/transaction.d.ts +4 -2
  131. package/orm/server/transaction.js +14 -5
  132. package/orm/server/transactional.d.ts +6 -2
  133. package/orm/server/transactional.js +39 -9
  134. package/orm/server/types.d.ts +2 -0
  135. package/orm/sqls/case-when.d.ts +3 -3
  136. package/orm/sqls/case-when.js +2 -2
  137. package/orm/sqls/sqls.d.ts +31 -5
  138. package/orm/sqls/sqls.js +69 -6
  139. package/orm/tests/data-types.test.d.ts +1 -0
  140. package/orm/tests/data-types.test.js +39 -0
  141. package/orm/tests/decorators.test.d.ts +1 -0
  142. package/orm/tests/decorators.test.js +77 -0
  143. package/orm/tests/encryption.test.d.ts +1 -0
  144. package/orm/tests/encryption.test.js +34 -0
  145. package/orm/tests/query-complex.test.d.ts +1 -0
  146. package/orm/tests/query-complex.test.js +203 -0
  147. package/orm/tests/query-converter-complex.test.d.ts +1 -0
  148. package/orm/tests/query-converter-complex.test.js +126 -0
  149. package/orm/tests/query-converter.test.d.ts +1 -0
  150. package/orm/tests/query-converter.test.js +123 -0
  151. package/orm/tests/repository-advanced.test.d.ts +1 -0
  152. package/orm/tests/repository-advanced.test.js +232 -0
  153. package/orm/tests/repository-attributes.test.d.ts +1 -0
  154. package/orm/tests/repository-attributes.test.js +99 -0
  155. package/orm/tests/repository-comprehensive.test.d.ts +1 -0
  156. package/orm/tests/repository-comprehensive.test.js +187 -0
  157. package/orm/tests/repository-coverage.test.d.ts +1 -0
  158. package/orm/tests/repository-coverage.test.js +303 -0
  159. package/orm/tests/repository-cti-complex.test.d.ts +1 -0
  160. package/orm/tests/repository-cti-complex.test.js +170 -0
  161. package/orm/tests/repository-cti-embedded.test.d.ts +1 -0
  162. package/orm/tests/repository-cti-embedded.test.js +188 -0
  163. package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
  164. package/orm/tests/repository-cti-extensive.test.js +308 -0
  165. package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
  166. package/orm/tests/repository-cti-mapping.test.js +121 -0
  167. package/orm/tests/repository-cti-search.test.d.ts +1 -0
  168. package/orm/tests/repository-cti-search.test.js +152 -0
  169. package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
  170. package/orm/tests/repository-cti-soft-delete.test.js +115 -0
  171. package/orm/tests/repository-cti-transactions.test.d.ts +1 -0
  172. package/orm/tests/repository-cti-transactions.test.js +126 -0
  173. package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
  174. package/orm/tests/repository-cti-upsert-many.test.js +127 -0
  175. package/orm/tests/repository-cti.test.d.ts +1 -0
  176. package/orm/tests/repository-cti.test.js +456 -0
  177. package/orm/tests/repository-edge-cases.test.d.ts +1 -0
  178. package/orm/tests/repository-edge-cases.test.js +216 -0
  179. package/orm/tests/repository-expiration.test.d.ts +1 -0
  180. package/orm/tests/repository-expiration.test.js +153 -0
  181. package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
  182. package/orm/tests/repository-extra-coverage.test.js +546 -0
  183. package/orm/tests/repository-mapping.test.d.ts +1 -0
  184. package/orm/tests/repository-mapping.test.js +71 -0
  185. package/orm/tests/repository-regression.test.d.ts +1 -0
  186. package/orm/tests/repository-regression.test.js +330 -0
  187. package/orm/tests/repository-search-coverage.test.d.ts +1 -0
  188. package/orm/tests/repository-search-coverage.test.js +129 -0
  189. package/orm/tests/repository-search.test.d.ts +1 -0
  190. package/orm/tests/repository-search.test.js +116 -0
  191. package/orm/tests/repository-soft-delete.test.d.ts +1 -0
  192. package/orm/tests/repository-soft-delete.test.js +143 -0
  193. package/orm/tests/repository-transactions-nested.test.d.ts +1 -0
  194. package/orm/tests/repository-transactions-nested.test.js +202 -0
  195. package/orm/tests/repository-types.test.d.ts +1 -0
  196. package/orm/tests/repository-types.test.js +218 -0
  197. package/orm/tests/schema-converter.test.d.ts +1 -0
  198. package/orm/tests/schema-converter.test.js +81 -0
  199. package/orm/tests/schema-generation.test.d.ts +1 -0
  200. package/orm/tests/schema-generation.test.js +127 -0
  201. package/orm/tests/sql-helpers.test.d.ts +1 -0
  202. package/orm/tests/sql-helpers.test.js +67 -0
  203. package/orm/tests/transaction-safety.test.d.ts +1 -0
  204. package/orm/tests/transaction-safety.test.js +81 -0
  205. package/orm/tests/transactional.test.d.ts +1 -0
  206. package/orm/tests/transactional.test.js +224 -0
  207. package/orm/tests/utils.test.d.ts +1 -0
  208. package/orm/tests/utils.test.js +70 -0
  209. package/orm/utils.d.ts +7 -0
  210. package/orm/utils.js +26 -6
  211. package/package.json +12 -7
  212. package/pool/pool.js +1 -1
  213. package/rate-limit/index.d.ts +2 -0
  214. package/rate-limit/index.js +2 -0
  215. package/rate-limit/postgres/drizzle/0000_watery_rage.sql +7 -0
  216. package/{queue → rate-limit}/postgres/drizzle/meta/0000_snapshot.json +14 -39
  217. package/rate-limit/postgres/drizzle/meta/_journal.json +13 -0
  218. package/{queue → rate-limit}/postgres/drizzle.config.js +1 -1
  219. package/rate-limit/postgres/index.d.ts +4 -0
  220. package/rate-limit/postgres/index.js +4 -0
  221. package/rate-limit/postgres/module.d.ts +12 -0
  222. package/rate-limit/postgres/module.js +28 -0
  223. package/rate-limit/postgres/postgres-rate-limiter.d.ts +9 -0
  224. package/rate-limit/postgres/postgres-rate-limiter.js +56 -0
  225. package/rate-limit/postgres/rate-limit.model.d.ts +8 -0
  226. package/rate-limit/postgres/rate-limit.model.js +35 -0
  227. package/rate-limit/postgres/rate-limiter.provider.d.ts +6 -0
  228. package/rate-limit/postgres/rate-limiter.provider.js +21 -0
  229. package/rate-limit/postgres/schemas.d.ts +3 -0
  230. package/rate-limit/postgres/schemas.js +4 -0
  231. package/rate-limit/provider.d.ts +9 -0
  232. package/rate-limit/provider.js +2 -0
  233. package/rate-limit/rate-limiter.d.ts +35 -0
  234. package/rate-limit/rate-limiter.js +3 -0
  235. package/rate-limit/tests/postgres-rate-limiter.test.d.ts +1 -0
  236. package/rate-limit/tests/postgres-rate-limiter.test.js +92 -0
  237. package/signals/implementation/configure.d.ts +3 -0
  238. package/signals/implementation/configure.js +3 -0
  239. package/sse/data-stream-source.d.ts +1 -1
  240. package/sse/data-stream-source.js +6 -6
  241. package/task-queue/enqueue-batch.d.ts +17 -0
  242. package/task-queue/enqueue-batch.js +24 -0
  243. package/{queue → task-queue}/index.d.ts +1 -1
  244. package/{queue → task-queue}/index.js +1 -1
  245. package/task-queue/postgres/drizzle/0000_thin_black_panther.sql +74 -0
  246. package/task-queue/postgres/drizzle/meta/0000_snapshot.json +592 -0
  247. package/task-queue/postgres/drizzle/meta/_journal.json +13 -0
  248. package/task-queue/postgres/drizzle.config.d.ts +2 -0
  249. package/task-queue/postgres/drizzle.config.js +11 -0
  250. package/task-queue/postgres/index.d.ts +4 -0
  251. package/task-queue/postgres/index.js +4 -0
  252. package/task-queue/postgres/module.d.ts +12 -0
  253. package/task-queue/postgres/module.js +28 -0
  254. package/task-queue/postgres/schemas.d.ts +16 -0
  255. package/task-queue/postgres/schemas.js +8 -0
  256. package/task-queue/postgres/task-queue.d.ts +83 -0
  257. package/task-queue/postgres/task-queue.js +1054 -0
  258. package/task-queue/postgres/task-queue.provider.d.ts +7 -0
  259. package/{queue/postgres/queue.provider.js → task-queue/postgres/task-queue.provider.js} +8 -8
  260. package/task-queue/postgres/task.model.d.ts +39 -0
  261. package/task-queue/postgres/task.model.js +178 -0
  262. package/{queue → task-queue}/provider.d.ts +3 -3
  263. package/task-queue/provider.js +2 -0
  264. package/{queue → task-queue}/task-context.d.ts +7 -7
  265. package/{queue → task-queue}/task-context.js +8 -8
  266. package/{queue/queue.d.ts → task-queue/task-queue.d.ts} +128 -59
  267. package/task-queue/task-queue.js +200 -0
  268. package/task-queue/tests/complex.test.d.ts +1 -0
  269. package/task-queue/tests/complex.test.js +299 -0
  270. package/task-queue/tests/dependencies.test.d.ts +1 -0
  271. package/task-queue/tests/dependencies.test.js +174 -0
  272. package/task-queue/tests/queue.test.d.ts +1 -0
  273. package/task-queue/tests/queue.test.js +334 -0
  274. package/task-queue/tests/worker.test.d.ts +1 -0
  275. package/task-queue/tests/worker.test.js +163 -0
  276. package/test1.js +1 -1
  277. package/test4.js +2 -2
  278. package/unit-test/index.d.ts +1 -0
  279. package/unit-test/index.js +1 -0
  280. package/unit-test/integration-setup.d.ts +55 -0
  281. package/unit-test/integration-setup.js +182 -0
  282. package/utils/patterns.d.ts +3 -0
  283. package/utils/patterns.js +6 -1
  284. package/audit/drizzle/0001_previous_network.sql +0 -2
  285. package/audit/drizzle/meta/0001_snapshot.json +0 -195
  286. package/queue/enqueue-batch.d.ts +0 -17
  287. package/queue/enqueue-batch.js +0 -18
  288. package/queue/postgres/drizzle/0000_zippy_moondragon.sql +0 -11
  289. package/queue/postgres/drizzle/0001_certain_wild_pack.sql +0 -2
  290. package/queue/postgres/drizzle/0002_dear_meggan.sql +0 -2
  291. package/queue/postgres/drizzle/0003_tricky_venom.sql +0 -30
  292. package/queue/postgres/drizzle/meta/0001_snapshot.json +0 -103
  293. package/queue/postgres/drizzle/meta/0002_snapshot.json +0 -90
  294. package/queue/postgres/drizzle/meta/0003_snapshot.json +0 -288
  295. package/queue/postgres/drizzle/meta/_journal.json +0 -34
  296. package/queue/postgres/index.d.ts +0 -4
  297. package/queue/postgres/index.js +0 -4
  298. package/queue/postgres/module.d.ts +0 -9
  299. package/queue/postgres/module.js +0 -29
  300. package/queue/postgres/queue.d.ts +0 -60
  301. package/queue/postgres/queue.js +0 -681
  302. package/queue/postgres/queue.provider.d.ts +0 -7
  303. package/queue/postgres/schemas.d.ts +0 -14
  304. package/queue/postgres/schemas.js +0 -6
  305. package/queue/postgres/task.model.d.ts +0 -24
  306. package/queue/postgres/task.model.js +0 -115
  307. package/queue/provider.js +0 -2
  308. package/queue/queue.js +0 -131
  309. package/queue/tests/queue.test.js +0 -623
  310. package/test3.d.ts +0 -1
  311. package/test3.js +0 -47
  312. /package/{queue/tests/queue.test.d.ts → api/server/tests/csrf.middleware.test.d.ts} +0 -0
  313. /package/circuit-breaker/postgres/drizzle/{0000_hard_shocker.sql → 0000_cooing_korath.sql} +0 -0
  314. /package/{queue → rate-limit}/postgres/drizzle.config.d.ts +0 -0
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { Subject, filter, firstValueFrom, race, timer } from 'rxjs';
11
- import { CancellationToken } from '../../cancellation/token.js';
11
+ import { CancellationSignal, CancellationToken } from '../../cancellation/token.js';
12
12
  import { isNode } from '../../environment.js';
13
13
  import { BadRequestError } from '../../errors/bad-request.error.js';
14
14
  import { ForbiddenError } from '../../errors/forbidden.error.js';
@@ -28,6 +28,9 @@ import { assertDefinedPass, isDefined, isNullOrUndefined, isUndefined } from '..
28
28
  import { millisecondsPerSecond } from '../../utils/units.js';
29
29
  import { AUTHENTICATION_API_CLIENT, INITIAL_AUTHENTICATION_DATA } from './tokens.js';
30
30
  const tokenStorageKey = 'AuthenticationService:token';
31
+ const rawTokenStorageKey = 'AuthenticationService:raw-token';
32
+ const rawRefreshTokenStorageKey = 'AuthenticationService:raw-refresh-token';
33
+ const rawImpersonatorRefreshTokenStorageKey = 'AuthenticationService:raw-impersonator-refresh-token';
31
34
  const authenticationDataStorageKey = 'AuthenticationService:authentication-data';
32
35
  const impersonatorAuthenticationDataStorageKey = 'AuthenticationService:impersonator-authentication-data';
33
36
  const tokenUpdateBusName = 'AuthenticationService:tokenUpdate';
@@ -67,8 +70,9 @@ let AuthenticationClientService = class AuthenticationClientService {
67
70
  forceRefreshToken = new CancellationToken();
68
71
  lock = inject(Lock, refreshLockResource);
69
72
  logger = inject(Logger, 'AuthenticationService');
70
- disposeToken = new CancellationToken();
73
+ disposeToken = inject(CancellationSignal).createChild();
71
74
  clockOffset = 0;
75
+ refreshLoopPromise;
72
76
  /**
73
77
  * Observable for authentication errors.
74
78
  * Emits when a refresh fails.
@@ -76,6 +80,12 @@ let AuthenticationClientService = class AuthenticationClientService {
76
80
  error$ = this.errorSubject.asObservable();
77
81
  /** Current token */
78
82
  token = signal(undefined);
83
+ /** Current raw token */
84
+ rawToken = signal(undefined);
85
+ /** Current raw refresh token */
86
+ rawRefreshToken = signal(undefined);
87
+ /** Current raw impersonator refresh token */
88
+ rawImpersonatorRefreshToken = signal(undefined);
79
89
  /** Whether the user is logged in */
80
90
  isLoggedIn = computed(() => isDefined(this.token()));
81
91
  /** Current session id */
@@ -168,7 +178,7 @@ let AuthenticationClientService = class AuthenticationClientService {
168
178
  initialize() {
169
179
  this.loadToken();
170
180
  this.tokenUpdateBus.messages$.subscribe((token) => this.token.set(token));
171
- void this.refreshLoop();
181
+ this.refreshLoopPromise = this.refreshLoop();
172
182
  }
173
183
  /** @internal */
174
184
  async [Symbol.asyncDispose]() {
@@ -180,6 +190,7 @@ let AuthenticationClientService = class AuthenticationClientService {
180
190
  */
181
191
  async dispose() {
182
192
  this.disposeToken.set();
193
+ await this.refreshLoopPromise;
183
194
  this.errorSubject.complete();
184
195
  await this.loggedOutBus.dispose();
185
196
  await this.tokenUpdateBus.dispose();
@@ -331,8 +342,33 @@ let AuthenticationClientService = class AuthenticationClientService {
331
342
  async checkSecret(secret) {
332
343
  return await this.client.checkSecret({ secret });
333
344
  }
345
+ /**
346
+ * Update raw tokens.
347
+ * @param token Raw token
348
+ * @param refreshToken Raw refresh token
349
+ * @param impersonatorRefreshToken Raw impersonator refresh token
350
+ */
351
+ updateRawTokens(token, refreshToken, impersonatorRefreshToken) {
352
+ if (isDefined(token)) {
353
+ this.rawToken.set(token);
354
+ }
355
+ if (isDefined(refreshToken)) {
356
+ this.rawRefreshToken.set(refreshToken);
357
+ }
358
+ if (isDefined(impersonatorRefreshToken)) {
359
+ this.rawImpersonatorRefreshToken.set(impersonatorRefreshToken);
360
+ }
361
+ if (isDefined(token) || isDefined(refreshToken) || isDefined(impersonatorRefreshToken)) {
362
+ this.saveToken(this.token(), this.rawToken(), this.rawRefreshToken(), this.rawImpersonatorRefreshToken());
363
+ }
364
+ }
334
365
  setNewToken(token) {
335
- this.saveToken(token);
366
+ if (isUndefined(token)) {
367
+ this.rawToken.set(undefined);
368
+ this.rawRefreshToken.set(undefined);
369
+ this.rawImpersonatorRefreshToken.set(undefined);
370
+ }
371
+ this.saveToken(token, this.rawToken(), this.rawRefreshToken(), this.rawImpersonatorRefreshToken());
336
372
  this.token.set(token);
337
373
  this.tokenUpdateBus.publishAndForget(token);
338
374
  }
@@ -342,30 +378,44 @@ let AuthenticationClientService = class AuthenticationClientService {
342
378
  }
343
379
  while (this.disposeToken.isUnset) {
344
380
  try {
345
- // Use a non-blocking lock to ensure only one tab/instance runs the refresh logic at a time.
346
- await this.lock.tryUse(undefined, async () => await this.refreshLoopIteration());
347
- // Calculate delay until the next refresh check.
348
- // The buffer ensures we refresh *before* the token actually expires.
381
+ const token = this.token();
382
+ if (isUndefined(token)) {
383
+ // Wait for login, dispose, or forced refresh
384
+ await firstValueFrom(race([this.definedToken$, this.disposeToken, this.forceRefreshToken]));
385
+ continue;
386
+ }
387
+ const now = this.estimatedServerTimestampSeconds();
388
+ const needsRefresh = this.forceRefreshToken.isSet || (now >= (token.exp - refreshBufferSeconds));
389
+ if (needsRefresh) {
390
+ // Only take the lock when we actually intend to refresh.
391
+ // Using tryUse(undefined, ...) ensures we try once and don't block if another instance is already refreshing.
392
+ await this.lock.tryUse(undefined, async () => {
393
+ // Re-check conditions inside the lock to avoid redundant refreshes if another instance just did it.
394
+ const currentToken = this.token();
395
+ const currentNow = this.estimatedServerTimestampSeconds();
396
+ const stillNeedsRefresh = isDefined(currentToken) && (this.forceRefreshToken.isSet || (currentNow >= (currentToken.exp - refreshBufferSeconds)));
397
+ if (stillNeedsRefresh) {
398
+ this.forceRefreshToken.unset();
399
+ await this.refresh();
400
+ }
401
+ });
402
+ }
349
403
  const delay = ((this.token()?.exp ?? 0) - this.estimatedServerTimestampSeconds() - refreshBufferSeconds) * millisecondsPerSecond;
350
- await firstValueFrom(race([timer(delay), this.disposeToken, this.forceRefreshToken]));
404
+ // Ensure delay is at least 0 to avoid tight loop, or wait longer if not logged in.
405
+ // If not logged in after refresh attempt (e.g. session invalidated), we wait for login.
406
+ if (isUndefined(this.token()) || (delay < 0)) {
407
+ await firstValueFrom(race([this.definedToken$, this.disposeToken, this.forceRefreshToken, timer(5000)]));
408
+ }
409
+ else {
410
+ await firstValueFrom(race([timer(delay), this.disposeToken, this.forceRefreshToken]));
411
+ }
351
412
  }
352
- catch {
413
+ catch (error) {
414
+ this.logger.error(error);
353
415
  await firstValueFrom(race([timer(5000), this.disposeToken, this.forceRefreshToken]));
354
416
  }
355
417
  }
356
418
  }
357
- async refreshLoopIteration() {
358
- // Wait for a token to be available or for the service to be disposed.
359
- const token = await firstValueFrom(race([this.definedToken$, this.disposeToken]));
360
- if (isUndefined(token)) {
361
- return;
362
- }
363
- const needsRefresh = this.estimatedServerTimestampSeconds() >= (token.exp - refreshBufferSeconds);
364
- if (this.forceRefreshToken.isSet || needsRefresh) {
365
- this.forceRefreshToken.unset();
366
- await this.refresh(); // Errors are caught by the outer loop
367
- }
368
- }
369
419
  async handleRefreshError(error) {
370
420
  this.logger.error(error);
371
421
  this.errorSubject.next(error);
@@ -386,12 +436,21 @@ let AuthenticationClientService = class AuthenticationClientService {
386
436
  this.clockOffset = 0;
387
437
  }
388
438
  }
389
- saveToken(token) {
439
+ saveToken(token, rawToken, rawRefreshToken, rawImpersonatorRefreshToken) {
390
440
  this.writeToStorage(tokenStorageKey, token);
441
+ this.writeToStorage(rawTokenStorageKey, rawToken);
442
+ this.writeToStorage(rawRefreshTokenStorageKey, rawRefreshToken);
443
+ this.writeToStorage(rawImpersonatorRefreshTokenStorageKey, rawImpersonatorRefreshToken);
391
444
  }
392
445
  loadToken() {
393
446
  const token = this.readFromStorage(tokenStorageKey);
447
+ const rawToken = this.readFromStorage(rawTokenStorageKey);
448
+ const rawRefreshToken = this.readFromStorage(rawRefreshTokenStorageKey);
449
+ const rawImpersonatorRefreshToken = this.readFromStorage(rawImpersonatorRefreshTokenStorageKey);
394
450
  this.token.set(token);
451
+ this.rawToken.set(rawToken);
452
+ this.rawRefreshToken.set(rawRefreshToken);
453
+ this.rawImpersonatorRefreshToken.set(rawImpersonatorRefreshToken);
395
454
  }
396
455
  readFromStorage(key) {
397
456
  try {
@@ -7,3 +7,9 @@ import type { AuthenticationClientService } from './authentication.service.js';
7
7
  * @returns A http client middleware.
8
8
  */
9
9
  export declare function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider: ValueOrAsyncProvider<AuthenticationClientService>): HttpClientMiddleware;
10
+ /**
11
+ * A http client middleware that adds authentication tokens to outgoing requests and extracts them from incoming responses.
12
+ * @param authenticationServiceOrProvider The authentication service or a provider for it.
13
+ * @returns A http client middleware.
14
+ */
15
+ export declare function authenticationMiddleware(authenticationServiceOrProvider: ValueOrAsyncProvider<AuthenticationClientService>): HttpClientMiddleware;
@@ -1,4 +1,5 @@
1
1
  import { firstValueFrom, timeout } from 'rxjs';
2
+ import { isDefined } from '../../utils/type-guards.js';
2
3
  import { cacheValueOrAsyncProvider } from '../../utils/value-or-provider.js';
3
4
  import { dontWaitForValidToken } from '../authentication.api.js';
4
5
  /**
@@ -20,3 +21,38 @@ export function waitForAuthenticationCredentialsMiddleware(authenticationService
20
21
  }
21
22
  return waitForAuthenticationCredentialsMiddleware;
22
23
  }
24
+ /**
25
+ * A http client middleware that adds authentication tokens to outgoing requests and extracts them from incoming responses.
26
+ * @param authenticationServiceOrProvider The authentication service or a provider for it.
27
+ * @returns A http client middleware.
28
+ */
29
+ export function authenticationMiddleware(authenticationServiceOrProvider) {
30
+ const getAuthenticationService = cacheValueOrAsyncProvider(authenticationServiceOrProvider);
31
+ async function authenticationMiddleware(context, next) {
32
+ const { request } = context;
33
+ const authenticationService = await getAuthenticationService();
34
+ const rawToken = authenticationService.rawToken();
35
+ const rawRefreshToken = authenticationService.rawRefreshToken();
36
+ const rawImpersonatorRefreshToken = authenticationService.rawImpersonatorRefreshToken();
37
+ if (isDefined(rawToken)) {
38
+ request.headers.setIfMissing('Authorization', rawToken);
39
+ }
40
+ if (isDefined(rawRefreshToken)) {
41
+ request.headers.setIfMissing('X-Refresh-Token', rawRefreshToken);
42
+ }
43
+ if (isDefined(rawImpersonatorRefreshToken)) {
44
+ request.headers.setIfMissing('X-Impersonator-Refresh-Token', rawImpersonatorRefreshToken);
45
+ }
46
+ await next();
47
+ if (isDefined(context.response)) {
48
+ const { response } = context;
49
+ const responseToken = response.headers.tryGetSingle('X-Authorization');
50
+ const responseRefreshToken = response.headers.tryGetSingle('X-Refresh-Token');
51
+ const responseImpersonatorRefreshToken = response.headers.tryGetSingle('X-Impersonator-Refresh-Token');
52
+ if (isDefined(responseToken) || isDefined(responseRefreshToken) || isDefined(responseImpersonatorRefreshToken)) {
53
+ authenticationService.updateRawTokens(responseToken, responseRefreshToken, responseImpersonatorRefreshToken);
54
+ }
55
+ }
56
+ }
57
+ return authenticationMiddleware;
58
+ }
@@ -3,7 +3,7 @@ import { getCurrentInjector } from '../../injector/inject.js';
3
3
  import { Injector } from '../../injector/injector.js';
4
4
  import { isDefined } from '../../utils/type-guards.js';
5
5
  import { AuthenticationClientService } from './authentication.service.js';
6
- import { waitForAuthenticationCredentialsMiddleware } from './http-client.middleware.js';
6
+ import { authenticationMiddleware, waitForAuthenticationCredentialsMiddleware } from './http-client.middleware.js';
7
7
  import { AUTHENTICATION_API_CLIENT, INITIAL_AUTHENTICATION_DATA } from './tokens.js';
8
8
  /**
9
9
  * Configures authentication client services.
@@ -17,12 +17,18 @@ export function configureAuthenticationClient(config, injector = getCurrentInjec
17
17
  if (isDefined(config.initialAuthenticationData)) {
18
18
  (injector ?? Injector).register(INITIAL_AUTHENTICATION_DATA, { useValue: config.initialAuthenticationData });
19
19
  }
20
- if (isDefined(config.registerMiddleware)) {
20
+ if (config.registerMiddleware == true) {
21
21
  (injector ?? Injector).register(HTTP_CLIENT_MIDDLEWARE, {
22
22
  useFactory(_, context) {
23
23
  const authenticationService = context.resolve(AuthenticationClientService, undefined, { forwardRef: true, forwardRefTypeHint: 'object' });
24
24
  return waitForAuthenticationCredentialsMiddleware(authenticationService);
25
25
  },
26
26
  }, { multi: true });
27
+ (injector ?? Injector).register(HTTP_CLIENT_MIDDLEWARE, {
28
+ useFactory(_, context) {
29
+ const authenticationService = context.resolve(AuthenticationClientService, undefined, { forwardRef: true, forwardRefTypeHint: 'object' });
30
+ return authenticationMiddleware(authenticationService);
31
+ },
32
+ }, { multi: true });
27
33
  }
28
34
  }
@@ -1,6 +1,6 @@
1
- import { TenantEntity } from '../../orm/entity.js';
2
1
  import { Subject } from './subject.model.js';
3
- export declare class ServiceAccount extends TenantEntity {
2
+ export declare class ServiceAccount extends Subject {
3
+ displayName: string;
4
4
  description: string;
5
5
  /** Who owns this service account? If null, it is a tenant-wide service account. */
6
6
  parent: Subject | null;
@@ -7,15 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { TenantEntity } from '../../orm/entity.js';
11
- import { Table, TenantReference, UuidProperty } from '../../orm/index.js';
10
+ import { ChildEntity, Table, TenantReference, UuidProperty } from '../../orm/index.js';
12
11
  import { StringProperty } from '../../schema/index.js';
13
- import { Subject } from './subject.model.js';
14
- let ServiceAccount = class ServiceAccount extends TenantEntity {
12
+ import { Subject, SubjectType } from './subject.model.js';
13
+ let ServiceAccount = class ServiceAccount extends Subject {
14
+ displayName;
15
15
  description;
16
16
  /** Who owns this service account? If null, it is a tenant-wide service account. */
17
17
  parent;
18
18
  };
19
+ __decorate([
20
+ StringProperty(),
21
+ __metadata("design:type", String)
22
+ ], ServiceAccount.prototype, "displayName", void 0);
19
23
  __decorate([
20
24
  StringProperty(),
21
25
  __metadata("design:type", String)
@@ -26,6 +30,7 @@ __decorate([
26
30
  __metadata("design:type", Object)
27
31
  ], ServiceAccount.prototype, "parent", void 0);
28
32
  ServiceAccount = __decorate([
29
- Table('service_account', { schema: 'authentication' })
33
+ Table('service_account', { schema: 'authentication' }),
34
+ ChildEntity(SubjectType.ServiceAccount)
30
35
  ], ServiceAccount);
31
36
  export { ServiceAccount };
@@ -1,16 +1,31 @@
1
1
  import { type EnumType } from '../../enumeration/enumeration.js';
2
2
  import { TenantEntity } from '../../orm/entity.js';
3
- import { type Uuid } from '../../orm/index.js';
3
+ import type { Timestamp } from '../../orm/types.js';
4
4
  export declare const SubjectType: {
5
5
  readonly System: "system";
6
6
  readonly User: "user";
7
7
  readonly ServiceAccount: "service-account";
8
8
  };
9
9
  export type SubjectType = EnumType<typeof SubjectType>;
10
+ /**
11
+ * Status of a subject.
12
+ */
13
+ export declare const SubjectStatus: {
14
+ /** Subject is active and can perform actions. */
15
+ readonly Active: "active";
16
+ /** Subject is inactive and cannot perform actions. Usually set by the user or a default state. */
17
+ readonly Inactive: "inactive";
18
+ /** Subject is suspended and cannot perform actions. Usually set by an administrator for security or policy reasons. */
19
+ readonly Suspended: "suspended";
20
+ /** Subject is pending approval from an administrator. */
21
+ readonly PendingApproval: "pending-approval";
22
+ /** Subject has been invited but has not yet accepted or completed setup. */
23
+ readonly Invited: "invited";
24
+ };
25
+ export type SubjectStatus = EnumType<typeof SubjectStatus>;
10
26
  export declare class Subject extends TenantEntity {
11
27
  type: SubjectType;
12
- displayName: string;
13
- systemAccountId: Uuid | null;
14
- userId: Uuid | null;
15
- serviceAccountId: Uuid | null;
28
+ status: SubjectStatus;
29
+ lastActivityTimestamp: Timestamp | null;
16
30
  }
31
+ export declare function getSubjectDisplayName(subject: Subject): string;
@@ -8,54 +8,59 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { defineEnum } from '../../enumeration/enumeration.js';
11
+ import { formatPersonName } from '../../formats/formats.js';
11
12
  import { TenantEntity } from '../../orm/entity.js';
12
- import { Check, exclusiveNotNull, Table, TenantReference, Unique, UuidProperty } from '../../orm/index.js';
13
- import { Enumeration, StringProperty } from '../../schema/index.js';
14
- import { ServiceAccount } from './service-account.model.js';
15
- import { SystemAccount } from './system-account.model.js';
16
- import { User } from './user.model.js';
13
+ import { Inheritance, Table, Unique } from '../../orm/index.js';
14
+ import { TimestampProperty } from '../../orm/schemas/timestamp.js';
15
+ import { Enumeration } from '../../schema/index.js';
16
+ import { match } from 'ts-pattern';
17
17
  export const SubjectType = defineEnum('SubjectType', {
18
18
  System: 'system',
19
19
  User: 'user',
20
20
  ServiceAccount: 'service-account',
21
21
  });
22
+ /**
23
+ * Status of a subject.
24
+ */
25
+ export const SubjectStatus = defineEnum('SubjectStatus', {
26
+ /** Subject is active and can perform actions. */
27
+ Active: 'active',
28
+ /** Subject is inactive and cannot perform actions. Usually set by the user or a default state. */
29
+ Inactive: 'inactive',
30
+ /** Subject is suspended and cannot perform actions. Usually set by an administrator for security or policy reasons. */
31
+ Suspended: 'suspended',
32
+ /** Subject is pending approval from an administrator. */
33
+ PendingApproval: 'pending-approval',
34
+ /** Subject has been invited but has not yet accepted or completed setup. */
35
+ Invited: 'invited',
36
+ });
22
37
  let Subject = class Subject extends TenantEntity {
23
38
  type;
24
- displayName;
25
- systemAccountId;
26
- userId;
27
- serviceAccountId;
39
+ status;
40
+ lastActivityTimestamp;
28
41
  };
29
42
  __decorate([
30
43
  Enumeration(SubjectType),
31
44
  __metadata("design:type", String)
32
45
  ], Subject.prototype, "type", void 0);
33
46
  __decorate([
34
- StringProperty(),
47
+ Enumeration(SubjectStatus),
35
48
  __metadata("design:type", String)
36
- ], Subject.prototype, "displayName", void 0);
37
- __decorate([
38
- TenantReference(() => SystemAccount),
39
- UuidProperty({ nullable: true }),
40
- __metadata("design:type", Object)
41
- ], Subject.prototype, "systemAccountId", void 0);
42
- __decorate([
43
- TenantReference(() => User),
44
- UuidProperty({ nullable: true }),
45
- __metadata("design:type", Object)
46
- ], Subject.prototype, "userId", void 0);
49
+ ], Subject.prototype, "status", void 0);
47
50
  __decorate([
48
- TenantReference(() => ServiceAccount),
49
- UuidProperty({ nullable: true }),
51
+ TimestampProperty({ nullable: true }),
50
52
  __metadata("design:type", Object)
51
- ], Subject.prototype, "serviceAccountId", void 0);
53
+ ], Subject.prototype, "lastActivityTimestamp", void 0);
52
54
  Subject = __decorate([
53
55
  Table('subject', { schema: 'authentication' }),
56
+ Inheritance({ strategy: 'joined', discriminatorColumn: 'type' }),
54
57
  Unique(['id']) // for external systems that might not support composite identities
55
- ,
56
- Unique(['tenantId', 'systemAccountId']),
57
- Unique(['tenantId', 'userId']),
58
- Unique(['tenantId', 'serviceAccountId']),
59
- Check('authentication_subject_reference_check', (table) => exclusiveNotNull(table.systemAccountId, table.userId, table.serviceAccountId))
60
58
  ], Subject);
61
59
  export { Subject };
60
+ export function getSubjectDisplayName(subject) {
61
+ return match(subject.type)
62
+ .with(SubjectType.User, () => formatPersonName(subject))
63
+ .with(SubjectType.System, () => subject.displayName)
64
+ .with(SubjectType.ServiceAccount, () => subject.displayName)
65
+ .exhaustive();
66
+ }
@@ -1,5 +1,6 @@
1
- import { TenantEntity } from '../../orm/entity.js';
2
- export declare class SystemAccount extends TenantEntity {
1
+ import { Subject } from './subject.model.js';
2
+ export declare class SystemAccount extends Subject {
3
3
  /** Programmatic name: 'cleanup-task', 'ai-agent' */
4
4
  identifier: string;
5
+ displayName: string;
5
6
  }
@@ -7,19 +7,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { TenantEntity } from '../../orm/entity.js';
11
- import { Table, Unique } from '../../orm/index.js';
10
+ import { ChildEntity, Table, Unique } from '../../orm/index.js';
12
11
  import { StringProperty } from '../../schema/index.js';
13
- let SystemAccount = class SystemAccount extends TenantEntity {
12
+ import { Subject, SubjectType } from './subject.model.js';
13
+ let SystemAccount = class SystemAccount extends Subject {
14
14
  /** Programmatic name: 'cleanup-task', 'ai-agent' */
15
15
  identifier;
16
+ displayName;
16
17
  };
17
18
  __decorate([
18
- Unique(),
19
19
  StringProperty(),
20
20
  __metadata("design:type", String)
21
21
  ], SystemAccount.prototype, "identifier", void 0);
22
+ __decorate([
23
+ StringProperty(),
24
+ __metadata("design:type", String)
25
+ ], SystemAccount.prototype, "displayName", void 0);
22
26
  SystemAccount = __decorate([
23
- Table('system_account', { schema: 'authentication' })
27
+ Table('system_account', { schema: 'authentication' }),
28
+ ChildEntity(SubjectType.System),
29
+ Unique(['tenantId', 'identifier'])
24
30
  ], SystemAccount);
25
31
  export { SystemAccount };
@@ -1,14 +1,5 @@
1
- import { type EnumType } from '../../enumeration/enumeration.js';
2
- import { TenantEntity } from '../../orm/entity.js';
3
- export declare const UserStatus: {
4
- readonly Active: "active";
5
- readonly Suspended: "suspended";
6
- readonly PendingApproval: "pending-approval";
7
- readonly Invited: "invited";
8
- };
9
- export type UserStatus = EnumType<typeof UserStatus>;
10
- export declare class User extends TenantEntity {
11
- status: UserStatus;
1
+ import { Subject } from './subject.model.js';
2
+ export declare class User extends Subject {
12
3
  email: string;
13
4
  firstName: string;
14
5
  lastName: string;
@@ -7,27 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { defineEnum } from '../../enumeration/enumeration.js';
11
- import { TenantEntity } from '../../orm/entity.js';
12
- import { Table, Unique } from '../../orm/index.js';
13
- import { Enumeration, StringProperty } from '../../schema/index.js';
10
+ import { ChildEntity, Table, Unique } from '../../orm/index.js';
11
+ import { StringProperty } from '../../schema/index.js';
14
12
  import { mailPattern } from '../../utils/patterns.js';
15
- export const UserStatus = defineEnum('UserStatus', {
16
- Active: 'active',
17
- Suspended: 'suspended',
18
- PendingApproval: 'pending-approval',
19
- Invited: 'invited',
20
- });
21
- let User = class User extends TenantEntity {
22
- status;
13
+ import { Subject, SubjectType } from './subject.model.js';
14
+ let User = class User extends Subject {
23
15
  email;
24
16
  firstName;
25
17
  lastName;
26
18
  };
27
- __decorate([
28
- Enumeration(UserStatus),
29
- __metadata("design:type", String)
30
- ], User.prototype, "status", void 0);
31
19
  __decorate([
32
20
  StringProperty({ pattern: mailPattern }),
33
21
  __metadata("design:type", String)
@@ -42,6 +30,7 @@ __decorate([
42
30
  ], User.prototype, "lastName", void 0);
43
31
  User = __decorate([
44
32
  Table('user', { schema: 'authentication' }),
33
+ ChildEntity(SubjectType.User),
45
34
  Unique(['tenantId', 'email'])
46
35
  ], User);
47
36
  export { User };
@@ -1,11 +1,9 @@
1
1
  import type { ApiRequestData } from '../../api/index.js';
2
2
  import { ApiRequestTokenProvider } from '../../api/server/api-request-token.provider.js';
3
- import { AuthenticationService } from './authentication.service.js';
4
3
  /**
5
4
  * Provides the info for an API request from the authorization header.
6
5
  */
7
6
  export declare class AuthenticationApiRequestTokenProvider extends ApiRequestTokenProvider {
8
7
  private readonly authenticationService;
9
- constructor(authenticationService: AuthenticationService);
10
8
  tryGetToken<T>(data: ApiRequestData): Promise<T | null>;
11
9
  }
@@ -4,11 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  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;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
7
  import { ApiRequestTokenProvider } from '../../api/server/api-request-token.provider.js';
11
- import { Singleton } from '../../injector/decorators.js';
8
+ import { inject, Singleton } from '../../injector/index.js';
12
9
  import { isUndefined } from '../../utils/type-guards.js';
13
10
  import { AuthenticationService } from './authentication.service.js';
14
11
  import { tryGetAuthorizationTokenStringFromRequest } from './helper.js';
@@ -16,11 +13,7 @@ import { tryGetAuthorizationTokenStringFromRequest } from './helper.js';
16
13
  * Provides the info for an API request from the authorization header.
17
14
  */
18
15
  let AuthenticationApiRequestTokenProvider = class AuthenticationApiRequestTokenProvider extends ApiRequestTokenProvider {
19
- authenticationService;
20
- constructor(authenticationService) {
21
- super();
22
- this.authenticationService = authenticationService;
23
- }
16
+ authenticationService = inject(AuthenticationService);
24
17
  async tryGetToken(data) {
25
18
  const tokenString = tryGetAuthorizationTokenStringFromRequest(data.request);
26
19
  if (isUndefined(tokenString)) {
@@ -30,7 +23,6 @@ let AuthenticationApiRequestTokenProvider = class AuthenticationApiRequestTokenP
30
23
  }
31
24
  };
32
25
  AuthenticationApiRequestTokenProvider = __decorate([
33
- Singleton(),
34
- __metadata("design:paramtypes", [AuthenticationService])
26
+ Singleton()
35
27
  ], AuthenticationApiRequestTokenProvider);
36
28
  export { AuthenticationApiRequestTokenProvider };
@@ -13,8 +13,7 @@ import { AuthenticationService } from './authentication.service.js';
13
13
  * @template AdditionalInitSecretResetData Type of additional secret reset data
14
14
  */
15
15
  export declare class AuthenticationApiController<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData = void> implements ApiController<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>> {
16
- readonly authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
17
- constructor(authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>);
16
+ protected readonly authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
18
17
  /**
19
18
  * Get a token for a subject and secret.
20
19
  * @param parameters The parameters for the request.
@@ -4,11 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  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;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
7
  import { apiController } from '../../api/server/index.js';
11
8
  import { HttpServerResponse } from '../../http/server/index.js';
9
+ import { inject } from '../../injector/index.js';
12
10
  import { currentTimestampSeconds } from '../../utils/date-time.js';
13
11
  import { assertDefinedPass, isDefined } from '../../utils/type-guards.js';
14
12
  import { authenticationApiDefinition, getAuthenticationApiDefinition } from '../authentication.api.js';
@@ -24,10 +22,7 @@ const deleteCookie = { value: '', ...cookieBaseOptions, maxAge: -1 };
24
22
  * @template AdditionalInitSecretResetData Type of additional secret reset data
25
23
  */
26
24
  let AuthenticationApiController = class AuthenticationApiController {
27
- authenticationService;
28
- constructor(authenticationService) {
29
- this.authenticationService = authenticationService;
30
- }
25
+ authenticationService = inject((AuthenticationService));
31
26
  /**
32
27
  * Get a token for a subject and secret.
33
28
  * @param parameters The parameters for the request.
@@ -146,6 +141,10 @@ let AuthenticationApiController = class AuthenticationApiController {
146
141
  getTokenResponse({ token, jsonToken, refreshToken, omitImpersonatorRefreshToken, impersonatorRefreshToken, impersonatorRefreshTokenExpiration }) {
147
142
  const result = jsonToken.payload;
148
143
  const options = {
144
+ headers: {
145
+ 'X-Authorization': `Bearer ${token}`,
146
+ 'X-Refresh-Token': `Bearer ${refreshToken}`,
147
+ },
149
148
  cookies: {
150
149
  authorization: {
151
150
  value: `Bearer ${token}`,
@@ -163,6 +162,7 @@ let AuthenticationApiController = class AuthenticationApiController {
163
162
  },
164
163
  };
165
164
  if (isDefined(impersonatorRefreshToken)) {
165
+ options.headers['X-Impersonator-Refresh-Token'] = `Bearer ${impersonatorRefreshToken}`;
166
166
  options.cookies['impersonatorRefreshToken'] = {
167
167
  value: `Bearer ${impersonatorRefreshToken}`,
168
168
  ...cookieBaseOptions,
@@ -176,8 +176,7 @@ let AuthenticationApiController = class AuthenticationApiController {
176
176
  }
177
177
  };
178
178
  AuthenticationApiController = __decorate([
179
- apiController(authenticationApiDefinition),
180
- __metadata("design:paramtypes", [AuthenticationService])
179
+ apiController(authenticationApiDefinition)
181
180
  ], AuthenticationApiController);
182
181
  export { AuthenticationApiController };
183
182
  /**