@bevel-software/platform-core-backend 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/core/create-core-server.d.ts.map +1 -1
  2. package/dist/core/create-core-server.js +13 -0
  3. package/dist/core/create-core-server.js.map +1 -1
  4. package/dist/core/create-core-services.d.ts.map +1 -1
  5. package/dist/core/create-core-services.js +35 -5
  6. package/dist/core/create-core-services.js.map +1 -1
  7. package/dist/core-config.d.ts +45 -1
  8. package/dist/core-config.d.ts.map +1 -1
  9. package/dist/core-config.js +66 -2
  10. package/dist/core-config.js.map +1 -1
  11. package/dist/modules/admin/admin-access.service.d.ts +17 -1
  12. package/dist/modules/admin/admin-access.service.d.ts.map +1 -1
  13. package/dist/modules/admin/admin-access.service.js +14 -1
  14. package/dist/modules/admin/admin-access.service.js.map +1 -1
  15. package/dist/modules/auth/account.routes.d.ts +17 -0
  16. package/dist/modules/auth/account.routes.d.ts.map +1 -0
  17. package/dist/modules/auth/account.routes.js +47 -0
  18. package/dist/modules/auth/account.routes.js.map +1 -0
  19. package/dist/modules/auth/auth.routes.d.ts +13 -7
  20. package/dist/modules/auth/auth.routes.d.ts.map +1 -1
  21. package/dist/modules/auth/auth.routes.js +51 -3
  22. package/dist/modules/auth/auth.routes.js.map +1 -1
  23. package/dist/modules/auth/auth.service.d.ts +44 -8
  24. package/dist/modules/auth/auth.service.d.ts.map +1 -1
  25. package/dist/modules/auth/auth.service.js +129 -32
  26. package/dist/modules/auth/auth.service.js.map +1 -1
  27. package/dist/modules/auth/oidc-auth-provider.d.ts +51 -0
  28. package/dist/modules/auth/oidc-auth-provider.d.ts.map +1 -0
  29. package/dist/modules/auth/oidc-auth-provider.js +189 -0
  30. package/dist/modules/auth/oidc-auth-provider.js.map +1 -0
  31. package/dist/modules/auth/password-hash.d.ts +12 -0
  32. package/dist/modules/auth/password-hash.d.ts.map +1 -0
  33. package/dist/modules/auth/password-hash.js +67 -0
  34. package/dist/modules/auth/password-hash.js.map +1 -0
  35. package/dist/modules/auth/rate-limit.d.ts +32 -0
  36. package/dist/modules/auth/rate-limit.d.ts.map +1 -0
  37. package/dist/modules/auth/rate-limit.js +49 -0
  38. package/dist/modules/auth/rate-limit.js.map +1 -0
  39. package/dist/modules/database/core-schema.d.ts +17 -0
  40. package/dist/modules/database/core-schema.d.ts.map +1 -1
  41. package/dist/modules/database/core-schema.js +6 -0
  42. package/dist/modules/database/core-schema.js.map +1 -1
  43. package/dist/modules/tool-auth/internal-token.service.d.ts +10 -0
  44. package/dist/modules/tool-auth/internal-token.service.d.ts.map +1 -1
  45. package/dist/modules/tool-auth/internal-token.service.js +12 -0
  46. package/dist/modules/tool-auth/internal-token.service.js.map +1 -1
  47. package/migrations/0001_user_password_hash.sql +4 -0
  48. package/migrations/meta/_journal.json +20 -13
  49. package/package.json +2 -2
  50. package/src/core/create-core-server.ts +352 -338
  51. package/src/core/create-core-services.ts +542 -501
  52. package/src/core-config.ts +65 -2
  53. package/src/modules/admin/admin-access.service.ts +10 -0
  54. package/src/modules/auth/__tests__/account.routes.test.ts +98 -0
  55. package/src/modules/auth/__tests__/auth.routes.test.ts +91 -0
  56. package/src/modules/auth/__tests__/auth.service.test.ts +217 -0
  57. package/src/modules/auth/__tests__/oidc-auth-provider.test.ts +174 -0
  58. package/src/modules/auth/__tests__/password-hash.test.ts +53 -0
  59. package/src/modules/auth/__tests__/rate-limit.test.ts +36 -0
  60. package/src/modules/auth/account.routes.ts +59 -0
  61. package/src/modules/auth/auth.routes.ts +68 -10
  62. package/src/modules/auth/auth.service.ts +151 -32
  63. package/src/modules/auth/oidc-auth-provider.ts +229 -0
  64. package/src/modules/auth/password-hash.ts +80 -0
  65. package/src/modules/auth/rate-limit.ts +45 -0
  66. package/src/modules/database/core-schema.ts +437 -431
  67. package/src/modules/tool-auth/__tests__/internal-token.service.test.ts +25 -1
  68. package/src/modules/tool-auth/internal-token.service.ts +13 -0
@@ -1,5 +1,8 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { InternalTokenService } from '../internal-token.service.js';
2
+ import {
3
+ InternalTokenService,
4
+ deriveInternalTokenSecret,
5
+ } from '../internal-token.service.js';
3
6
  import { createTokenVerifier } from '../tool-auth.middleware.js';
4
7
  import type { IExternalApiKeyService } from '../external-api-key.interface.js';
5
8
 
@@ -40,6 +43,27 @@ describe('InternalTokenService', () => {
40
43
  expect(svc.verify(token)).toBeNull();
41
44
  });
42
45
 
46
+ it('verifies a token minted by a SIBLING instance sharing the secret (CLI → server)', () => {
47
+ // The routine CLI and a second replica each build their own service graph;
48
+ // with the same configured secret their tokens must verify across
49
+ // instances — this is what makes the loopback tool surface reachable from
50
+ // a process other than the server itself.
51
+ const secret = deriveInternalTokenSecret('deployment-jwt-secret');
52
+ const cliSide = new InternalTokenService({ secret });
53
+ const serverSide = new InternalTokenService({ secret });
54
+ expect(serverSide.verify(cliSide.mint(claim))).toEqual(claim);
55
+ });
56
+
57
+ it('derives a stable, domain-separated internal secret from the JWT secret', () => {
58
+ const derived = deriveInternalTokenSecret('deployment-jwt-secret');
59
+ // Deterministic (same input → same key) …
60
+ expect(deriveInternalTokenSecret('deployment-jwt-secret')).toBe(derived);
61
+ // … but never the JWT secret itself, and different per input.
62
+ expect(derived).not.toBe('deployment-jwt-secret');
63
+ expect(deriveInternalTokenSecret('other-secret')).not.toBe(derived);
64
+ expect(derived).toMatch(/^[0-9a-f]{64}$/);
65
+ });
66
+
43
67
  it('rejects a connection-key-shaped bearer', () => {
44
68
  const svc = new InternalTokenService({ secret: 's' });
45
69
  expect(svc.verify('bevel_abc123')).toBeNull();
@@ -36,6 +36,19 @@ interface SignedPayload extends InternalTokenClaim {
36
36
 
37
37
  const DEFAULT_PREFIX = 'bevel-int_';
38
38
 
39
+ /**
40
+ * Derive the stable internal-token HMAC key from the deployment's JWT secret.
41
+ * Domain-separated (the constant label), so the two token systems never share
42
+ * key material and neither key reveals the other. A STABLE key — rather than
43
+ * the per-boot random default — is what lets a sibling process that shares the
44
+ * deployment env (the enterprise routine CLI, a second replica) mint tokens
45
+ * this server verifies; the composition root uses this whenever
46
+ * `INTERNAL_TOKEN_SECRET` is not set explicitly.
47
+ */
48
+ export function deriveInternalTokenSecret(jwtSecret: string): string {
49
+ return createHmac('sha256', jwtSecret).update('bevel-internal-token').digest('hex');
50
+ }
51
+
39
52
  function b64url(buf: Buffer): string {
40
53
  return buf.toString('base64url');
41
54
  }