@adaptic/backend 0.0.1057 → 0.0.1059

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 (114) hide show
  1. package/auth/authorization-map.cjs +306 -0
  2. package/auth/authorization-map.d.ts +143 -0
  3. package/auth/cortex-auth-checker.cjs +172 -0
  4. package/auth/cortex-auth-checker.d.ts +114 -0
  5. package/auth/credential-fields.cjs +51 -0
  6. package/auth/credential-fields.d.ts +19 -0
  7. package/auth/credential-redaction.cjs +134 -0
  8. package/auth/credential-redaction.d.ts +60 -0
  9. package/auth/graphql-auth-shadow.cjs +317 -0
  10. package/auth/graphql-auth-shadow.d.ts +194 -0
  11. package/auth/membership-write-authority.cjs +131 -0
  12. package/auth/membership-write-authority.d.ts +110 -0
  13. package/auth/mutation-authorization.cjs +376 -0
  14. package/auth/mutation-authorization.d.ts +261 -0
  15. package/auth/nested-write-inspector.cjs +189 -0
  16. package/auth/nested-write-inspector.d.ts +94 -0
  17. package/auth/nested-write-policy.cjs +189 -0
  18. package/auth/nested-write-policy.d.ts +99 -0
  19. package/auth/service-token.cjs +339 -0
  20. package/auth/service-token.d.ts +106 -0
  21. package/auth/tenancy-scope.cjs +736 -0
  22. package/auth/tenancy-scope.d.ts +347 -0
  23. package/auth/token-verifier.cjs +451 -0
  24. package/auth/token-verifier.d.ts +153 -0
  25. package/auth/totp.cjs +265 -0
  26. package/auth/totp.d.ts +111 -0
  27. package/auth/user-write-content.cjs +116 -0
  28. package/auth/user-write-content.d.ts +47 -0
  29. package/auth/ws-auth-context.cjs +75 -0
  30. package/auth/ws-auth-context.d.ts +69 -0
  31. package/config/jwtConfig.cjs +57 -0
  32. package/config/jwtConfig.d.ts +16 -0
  33. package/config/metrics.cjs +356 -0
  34. package/config/metrics.d.ts +128 -0
  35. package/config/persisted-queries.cjs +122 -0
  36. package/config/persisted-queries.d.ts +40 -0
  37. package/config/server-only-models.cjs +166 -0
  38. package/config/server-only-models.d.ts +89 -0
  39. package/config/tracing.d.ts +24 -0
  40. package/esm/auth/service-token.d.ts +12 -0
  41. package/esm/auth/service-token.mjs +27 -5
  42. package/esm/config/jwtConfig.mjs +5 -1
  43. package/generated/typegraphql-prisma/enhance.cjs +3 -3
  44. package/generated/typegraphql-prisma/index.cjs +6 -6
  45. package/generated/typegraphql-prisma/resolvers/crud/args.index.cjs +95 -95
  46. package/generated/typegraphql-prisma/resolvers/outputs/index.cjs +1 -1
  47. package/generated/typegraphql-prisma/resolvers/relations/args.index.cjs +32 -32
  48. package/middleware/audit-log-write-redaction.cjs +143 -0
  49. package/middleware/audit-log-write-redaction.d.ts +82 -0
  50. package/middleware/audit-logger.cjs +378 -0
  51. package/middleware/audit-logger.d.ts +158 -0
  52. package/middleware/audit-payload-guard.cjs +107 -0
  53. package/middleware/audit-payload-guard.d.ts +85 -0
  54. package/middleware/auth.cjs +66 -0
  55. package/middleware/auth.d.ts +41 -0
  56. package/middleware/credential-field-guard.cjs +514 -0
  57. package/middleware/credential-field-guard.d.ts +173 -0
  58. package/middleware/generated-type-names.cjs +77 -0
  59. package/middleware/generated-type-names.d.ts +44 -0
  60. package/middleware/graphql-validation-plugin.cjs +310 -0
  61. package/middleware/graphql-validation-plugin.d.ts +98 -0
  62. package/middleware/guard-log-throttle.cjs +89 -0
  63. package/middleware/guard-log-throttle.d.ts +80 -0
  64. package/middleware/index.cjs +57 -0
  65. package/middleware/index.d.ts +14 -0
  66. package/middleware/input-validator.cjs +220 -0
  67. package/middleware/input-validator.d.ts +63 -0
  68. package/middleware/mandate-version-validation.cjs +131 -0
  69. package/middleware/mandate-version-validation.d.ts +41 -0
  70. package/middleware/mutation-account-facts.cjs +223 -0
  71. package/middleware/mutation-account-facts.d.ts +143 -0
  72. package/middleware/mutation-auth-guard.cjs +536 -0
  73. package/middleware/mutation-auth-guard.d.ts +100 -0
  74. package/middleware/mutation-membership-facts.cjs +276 -0
  75. package/middleware/mutation-membership-facts.d.ts +133 -0
  76. package/middleware/mutation-tenant-facts.cjs +132 -0
  77. package/middleware/mutation-tenant-facts.d.ts +81 -0
  78. package/middleware/query-complexity.cjs +182 -0
  79. package/middleware/query-complexity.d.ts +56 -0
  80. package/middleware/rate-limiter.cjs +223 -0
  81. package/middleware/rate-limiter.d.ts +93 -0
  82. package/middleware/rate-tier.cjs +111 -0
  83. package/middleware/rate-tier.d.ts +56 -0
  84. package/middleware/soft-delete.cjs +175 -0
  85. package/middleware/soft-delete.d.ts +146 -0
  86. package/middleware/tenancy-scoping.cjs +229 -0
  87. package/middleware/tenancy-scoping.d.ts +67 -0
  88. package/middleware/trading-policy-audit.cjs +353 -0
  89. package/middleware/trading-policy-audit.d.ts +184 -0
  90. package/middleware/types.cjs +17 -0
  91. package/middleware/types.d.ts +87 -0
  92. package/middleware/validation-examples.cjs +398 -0
  93. package/middleware/validation-examples.d.ts +76 -0
  94. package/package.json +10 -2
  95. package/readers/index.cjs +15 -0
  96. package/readers/index.d.ts +10 -0
  97. package/readers/intraday-lane-prefs.cjs +76 -0
  98. package/readers/intraday-lane-prefs.d.ts +45 -0
  99. package/esm/config/__tests__/server-only-surface.harness.d.ts +0 -12
  100. package/esm/config/__tests__/server-only-surface.harness.mjs +0 -41
  101. package/esm/middleware/__tests__/audit-log-write-redaction.harness.d.ts +0 -144
  102. package/esm/middleware/__tests__/audit-log-write-redaction.harness.mjs +0 -920
  103. package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts +0 -55
  104. package/esm/middleware/__tests__/credential-field-coverage.harness.mjs +0 -440
  105. package/esm/middleware/__tests__/credential-field-guard.harness.d.ts +0 -34
  106. package/esm/middleware/__tests__/credential-field-guard.harness.mjs +0 -212
  107. package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +0 -56
  108. package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +0 -575
  109. package/esm/middleware/__tests__/rate-limit-test-utils.d.ts +0 -60
  110. package/esm/middleware/__tests__/rate-limit-test-utils.mjs +0 -85
  111. package/esm/middleware/__tests__/ts-node-harness.d.ts +0 -10
  112. package/esm/middleware/__tests__/ts-node-harness.mjs +0 -71
  113. package/health.cjs +0 -274
  114. package/server.cjs +0 -607
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Service-to-service principal minted from a dedicated HS256 secret.
3
+ *
4
+ * WHY THIS EXISTS AS A THIRD PATH RATHER THAN REUSING EITHER EXISTING ONE.
5
+ * `verifyBackendToken` already knows two ways to arrive at a non-user caller,
6
+ * and both are wrong for a long-lived internal service:
7
+ *
8
+ * - `SERVER_AUTH_TOKEN` is an exact string match against a static value. It
9
+ * never expires, carries no audience, names no caller, and cannot be
10
+ * rotated without a simultaneous restart of every holder. A copy taken
11
+ * from a log or a process listing is a permanent credential.
12
+ * - An app-issued JWT verifies against `jwtSecret` — the SAME secret that
13
+ * signs end-user sessions. A service credential keyed on it would make
14
+ * every holder of a user secret able to mint a service identity and vice
15
+ * versa, and it yields `kind: "user"`, which is then subject to
16
+ * per-user tenancy scoping that a service must not be subject to.
17
+ *
18
+ * So the service path is keyed on `BACKEND_SERVICE_JWT_SECRET`, a secret whose
19
+ * ONLY purpose is service identity. It is deliberately distinct from
20
+ * `JWT_SECRET` so that the blast radius of either one leaking stops at that
21
+ * one trust domain, and the verifier refuses to run if the two are ever set to
22
+ * the same value — a configuration that would silently collapse the
23
+ * separation this module exists to create.
24
+ *
25
+ * ABSENCE DISABLES THE PATH; IT NEVER WIDENS IT. With no secret provisioned
26
+ * `verifyServiceToken` returns `null` and the caller falls through to the
27
+ * existing paths, which reject. A service that cannot prove itself is refused,
28
+ * never admitted.
29
+ *
30
+ * @module auth/service-token
31
+ */
32
+ import { type BackendPrincipal } from './token-verifier';
33
+ /**
34
+ * Issuer every service credential must carry.
35
+ *
36
+ * Pinned rather than free-form so a token minted for some other HS256 system
37
+ * that happens to share the secret cannot be replayed here.
38
+ */
39
+ export declare const SERVICE_TOKEN_ISSUER = "adaptic-service";
40
+ /**
41
+ * Audience every service credential must carry.
42
+ *
43
+ * This backend is the only intended recipient. Binding the audience is what
44
+ * stops a credential minted for a sibling service from being replayed against
45
+ * the data tier.
46
+ */
47
+ export declare const SERVICE_TOKEN_AUDIENCE = "adaptic-backend";
48
+ /** Minimum length for the dedicated service secret, in characters. */
49
+ export declare const MINIMUM_SERVICE_SECRET_LENGTH = 32;
50
+ /**
51
+ * Largest lifetime this backend will honour on a service credential, seconds.
52
+ *
53
+ * A credential's own `exp` bounds the replay window on a leak, so a minter is
54
+ * free to choose a shorter one — but it may not choose a longer one and
55
+ * thereby re-create the non-expiring static bearer this path replaces. One
56
+ * hour is comfortably above the 15-minute lifetime the engine mints and far
57
+ * below "effectively permanent".
58
+ */
59
+ export declare const MAX_SERVICE_TOKEN_LIFETIME_SEC = 3600;
60
+ /**
61
+ * How far in the future, seconds, a credential's `iat` may sit before it is
62
+ * refused.
63
+ *
64
+ * The lifetime ceiling is measured from `iat`, so an `iat` the verifier does
65
+ * not bound would let a secret holder date a token years ahead and hold a
66
+ * credential valid until then. One minute absorbs ordinary clock drift between
67
+ * a minter and this host and nothing more.
68
+ */
69
+ export declare const MAX_SERVICE_TOKEN_CLOCK_SKEW_SEC = 60;
70
+ /**
71
+ * Which configured secret proved a credential's signature.
72
+ *
73
+ * `primary` is `BACKEND_SERVICE_JWT_SECRET`; `previous` is the optional
74
+ * `BACKEND_SERVICE_JWT_SECRET_PREVIOUS` that exists only for the length of a
75
+ * rotation.
76
+ */
77
+ export type ServiceKeySlot = 'primary' | 'previous';
78
+ /**
79
+ * Boot-time guard: refuse to start when a provisioned service secret (either
80
+ * slot) equals `JWT_SECRET`.
81
+ *
82
+ * `verifyServiceToken` already refuses per request, but that surfaces only as
83
+ * a stream of 401s on service calls after a deploy. Failing at boot puts the
84
+ * misconfiguration on the deploy, where it is caught before traffic. An
85
+ * unprovisioned service path is not an error — it is simply disabled.
86
+ *
87
+ * @throws {Error} When a service secret collides with the user-session secret.
88
+ */
89
+ export declare function assertServiceSecretsDistinctFromJwtSecret(): void;
90
+ /**
91
+ * Attempt to establish a service principal from a bearer token.
92
+ *
93
+ * Returns `null` — meaning "not a service credential, keep looking" — only
94
+ * when the path is unprovisioned or the signature does not belong to the
95
+ * service secret. Once a token IS proven to carry that signature, every
96
+ * subsequent problem with it (expiry, wrong audience, missing subject,
97
+ * over-long lifetime) throws, because at that point the caller's intent is
98
+ * unambiguous and falling through would report a misleading `bad_signature`
99
+ * for what is actually an expired or mis-scoped service token.
100
+ *
101
+ * @param token - Raw bearer token; assumed to be three dot-separated segments.
102
+ * @returns The verified service principal, or `null` to fall through.
103
+ * @throws {AuthError} When the token is ours but unacceptable.
104
+ */
105
+ export declare function verifyServiceToken(token: string, nowMs?: number): BackendPrincipal | null;
106
+ //# sourceMappingURL=service-token.d.ts.map