@adaptic/backend-legacy 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
@@ -1,212 +0,0 @@
1
- /**
2
- * Out-of-process harness for `credential-field-guard.test.ts`.
3
- *
4
- * The generated TypeGraphQL resolvers rely on `emitDecoratorMetadata`, which
5
- * vitest's esbuild transform does not emit, so a schema built from them cannot
6
- * be constructed inside the vitest worker. This harness runs under ts-node
7
- * (which honours the repo tsconfig), builds a schema from the GENERATED
8
- * AlpacaAccount and User resolvers with the guard installed exactly as
9
- * `server.ts` installs it, executes every scenario, and prints one JSON
10
- * document the test asserts on.
11
- *
12
- * Run directly: npx ts-node --transpile-only src/middleware/__tests__/credential-field-guard.harness.ts
13
- */
14
- import 'reflect-metadata';
15
- import { buildSchema } from 'type-graphql';
16
- import { graphql } from 'graphql';
17
- import { AlpacaAccountCrudResolver } from '../../generated/typegraphql-prisma/resolvers/crud/AlpacaAccount/AlpacaAccountCrudResolver.mjs';
18
- import { UserCrudResolver } from '../../generated/typegraphql-prisma/resolvers/crud/User/UserCrudResolver.mjs';
19
- import { BrokerageAccountCrudResolver } from '../../generated/typegraphql-prisma/resolvers/crud/BrokerageAccount/BrokerageAccountCrudResolver.mjs';
20
- import { BrokerageAccountCredentialStatusResolver } from '../../resolvers/custom/BrokerageAccountCredentialStatusResolver.mjs';
21
- import { createCredentialFieldGuardMiddleware, credentialFieldAccessTotal, } from '../credential-field-guard.mjs';
22
- export const API_KEY = 'PKGUARDTESTKEYVALUE0000000';
23
- export const API_SECRET = 'guard-test-secret-value-that-must-never-leak';
24
- const ROW = { id: 'acct-1', type: 'LIVE', APIKey: API_KEY, APISecret: API_SECRET };
25
- const PRINCIPALS = {
26
- none: null,
27
- server: { kind: 'server' },
28
- user: { kind: 'user', sub: 'u-1', roles: ['user'] },
29
- admin: { kind: 'admin', sub: 'a-1', roles: ['admin'] },
30
- };
31
- const READ_KEYS = '{ alpacaAccounts { id APIKey APISecret } }';
32
- export const SCENARIOS = [
33
- { name: 'output/server', query: READ_KEYS, principal: 'server', mode: 'enforce' },
34
- { name: 'output/none', query: READ_KEYS, principal: 'none', mode: 'enforce' },
35
- { name: 'output/user', query: READ_KEYS, principal: 'user', mode: 'enforce' },
36
- { name: 'output/admin', query: READ_KEYS, principal: 'admin', mode: 'enforce' },
37
- {
38
- name: 'output/non-credential-none',
39
- query: '{ alpacaAccounts { id type } }',
40
- principal: 'none',
41
- mode: 'enforce',
42
- },
43
- {
44
- name: 'output/single-row-none',
45
- query: '{ alpacaAccount(where: { id: "acct-1" }) { id APISecret } }',
46
- principal: 'none',
47
- mode: 'enforce',
48
- },
49
- {
50
- name: 'aggregate-max/server',
51
- query: '{ aggregateAlpacaAccount { _max { APISecret } } }',
52
- principal: 'server',
53
- mode: 'enforce',
54
- },
55
- {
56
- name: 'aggregate-max/none',
57
- query: '{ aggregateAlpacaAccount { _max { APISecret } } }',
58
- principal: 'none',
59
- mode: 'enforce',
60
- },
61
- {
62
- name: 'aggregate-count/none',
63
- query: '{ aggregateAlpacaAccount { _count { APISecret } } }',
64
- principal: 'none',
65
- mode: 'enforce',
66
- },
67
- {
68
- name: 'arg/where-none',
69
- query: '{ alpacaAccounts(where: { APISecret: { startsWith: "g" } }) { id } }',
70
- principal: 'none',
71
- mode: 'enforce',
72
- },
73
- {
74
- name: 'arg/where-server',
75
- query: '{ alpacaAccounts(where: { APISecret: { startsWith: "g" } }) { id } }',
76
- principal: 'server',
77
- mode: 'enforce',
78
- },
79
- {
80
- name: 'arg/not-nested-none',
81
- query: '{ alpacaAccounts(where: { NOT: [{ APIKey: { equals: "x" } }] }) { id } }',
82
- principal: 'none',
83
- mode: 'enforce',
84
- },
85
- {
86
- name: 'arg/orderBy-none',
87
- query: '{ alpacaAccounts(orderBy: [{ APISecret: asc }]) { id } }',
88
- principal: 'none',
89
- mode: 'enforce',
90
- },
91
- {
92
- name: 'arg/distinct-none',
93
- query: '{ alpacaAccounts(distinct: [APIKey]) { id } }',
94
- principal: 'none',
95
- mode: 'enforce',
96
- },
97
- {
98
- name: 'arg/relation-filter-none',
99
- query: '{ users(where: { alpacaAccounts: { some: { APISecret: { startsWith: "g" } } } }) { id } }',
100
- principal: 'none',
101
- mode: 'enforce',
102
- },
103
- {
104
- name: 'arg/groupBy-none',
105
- query: '{ groupByAlpacaAccount(by: [APIKey]) { APIKey } }',
106
- principal: 'none',
107
- mode: 'enforce',
108
- },
109
- {
110
- name: 'arg/non-credential-filter-none',
111
- query: '{ alpacaAccounts(where: { id: { equals: "acct-1" } }) { id } }',
112
- principal: 'none',
113
- mode: 'enforce',
114
- },
115
- {
116
- name: 'brokerage/status-none',
117
- query: '{ brokerageAccounts { id hasApiCredentials } }',
118
- principal: 'none',
119
- mode: 'enforce',
120
- },
121
- {
122
- name: 'brokerage/key-none',
123
- query: '{ brokerageAccounts { id apiKey } }',
124
- principal: 'none',
125
- mode: 'enforce',
126
- },
127
- {
128
- name: 'brokerage/key-server',
129
- query: '{ brokerageAccounts { id apiKey } }',
130
- principal: 'server',
131
- mode: 'enforce',
132
- },
133
- { name: 'mode/shadow-none', query: READ_KEYS, principal: 'none', mode: 'shadow' },
134
- { name: 'mode/off-none', query: READ_KEYS, principal: 'none', mode: 'off' },
135
- ];
136
- async function counterSnapshot() {
137
- const metric = await credentialFieldAccessTotal.get();
138
- const out = {};
139
- for (const v of metric.values) {
140
- const key = `${v.labels.surface}|${v.labels.decision}|${v.labels.principal_kind}`;
141
- out[key] = (out[key] ?? 0) + v.value;
142
- }
143
- return out;
144
- }
145
- async function main() {
146
- let mode = 'enforce';
147
- let resolverCalls = 0;
148
- const count = (value) => {
149
- resolverCalls += 1;
150
- return Promise.resolve(value);
151
- };
152
- const prisma = {
153
- alpacaAccount: {
154
- findMany: () => count([ROW]),
155
- findUnique: () => count(ROW),
156
- groupBy: () => count([{ id: ROW.id, APIKey: API_KEY, _max: { APISecret: API_SECRET } }]),
157
- aggregate: () => count({ _max: { APISecret: API_SECRET }, _count: { APISecret: 1 } }),
158
- },
159
- user: { findMany: () => count([{ id: 'u-1' }]) },
160
- brokerageAccount: {
161
- findMany: () => count([
162
- { id: 'ba-1', apiKey: API_KEY, apiSecret: API_SECRET },
163
- { id: 'ba-2', apiKey: null, apiSecret: null },
164
- { id: 'ba-3', apiKey: API_KEY, apiSecret: ' ' },
165
- ]),
166
- },
167
- };
168
- const schema = await buildSchema({
169
- resolvers: [
170
- AlpacaAccountCrudResolver,
171
- UserCrudResolver,
172
- BrokerageAccountCrudResolver,
173
- BrokerageAccountCredentialStatusResolver,
174
- ],
175
- validate: false,
176
- globalMiddlewares: [createCredentialFieldGuardMiddleware({ modeProvider: () => mode })],
177
- });
178
- const results = {};
179
- for (const scenario of SCENARIOS) {
180
- mode = scenario.mode;
181
- resolverCalls = 0;
182
- const before = await counterSnapshot();
183
- const result = await graphql({
184
- schema,
185
- source: scenario.query,
186
- contextValue: {
187
- prisma,
188
- principal: PRINCIPALS[scenario.principal],
189
- req: { ip: '203.0.113.9', headers: { 'user-agent': 'guard-harness' } },
190
- },
191
- });
192
- const after = await counterSnapshot();
193
- const counterDelta = {};
194
- for (const [key, value] of Object.entries(after)) {
195
- const delta = value - (before[key] ?? 0);
196
- if (delta !== 0)
197
- counterDelta[key] = delta;
198
- }
199
- results[scenario.name] = {
200
- codes: (result.errors ?? []).map((e) => String(e.extensions?.code)),
201
- json: JSON.stringify(result),
202
- resolverCalls,
203
- counterDelta,
204
- };
205
- }
206
- process.stdout.write(`<<<RESULTS>>>${JSON.stringify(results)}<<<END>>>\n`);
207
- }
208
- main().catch((error) => {
209
- process.stderr.write(`harness failed: ${String(error)}\n`);
210
- process.exit(1);
211
- });
212
- //# sourceMappingURL=credential-field-guard.harness.js.map
@@ -1,56 +0,0 @@
1
- /**
2
- * Out-of-process harness for `mutation-auth-guard.test.ts`.
3
- *
4
- * The generated TypeGraphQL resolvers need `emitDecoratorMetadata`, which
5
- * vitest's esbuild transform does not emit, so a schema built from them cannot
6
- * be constructed inside the vitest worker. This harness runs under ts-node,
7
- * builds a schema from the GENERATED TradingPolicy, AlpacaAccount, User,
8
- * tenancy (Organization, OrgMembership, Fund, FundAssignment,
9
- * BrokerageAccount), AuditLog and Configuration resolvers with the guard
10
- * installed exactly as `server.ts` installs it
11
- * (`installMutationAuthGuard` on the built schema),
12
- * serves it through a real ApolloServer carrying the production HTTP-status
13
- * plugin (so a refusal's HTTP status is observed, not assumed), runs every
14
- * scenario against a recording fake Prisma client, and prints one JSON
15
- * document the test asserts on.
16
- *
17
- * Run directly:
18
- * npx ts-node --transpile-only src/middleware/__tests__/mutation-auth-guard.harness.ts
19
- */
20
- import 'reflect-metadata';
21
- import type { MutationAuthMode } from '../../auth/mutation-authorization';
22
- import type { BackendPrincipal } from '../../auth/token-verifier';
23
- import type { CredentialFieldGuardMode } from '../credential-field-guard';
24
- export declare const API_KEY = "PKMUTATIONGUARDKEY00000000";
25
- export declare const API_SECRET = "mutation-guard-secret-value-that-must-never-leak";
26
- declare const PRINCIPALS: Record<string, BackendPrincipal | null>;
27
- /** One harness scenario. */
28
- export interface Scenario {
29
- name: string;
30
- query: string;
31
- principal: keyof typeof PRINCIPALS;
32
- mode: MutationAuthMode;
33
- enforcedModels?: string[];
34
- auditDown?: boolean;
35
- /** The credential-field guard's mode; defaults to `enforce`, production's setting. */
36
- credentialMode?: CredentialFieldGuardMode;
37
- /** Make every OrgMembership and FundAssignment `findUnique` fail. */
38
- membershipReadsDown?: boolean;
39
- }
40
- export declare const SCENARIOS: Scenario[];
41
- /** What the harness reports per scenario. */
42
- export interface ScenarioResult {
43
- status: number;
44
- codes: string[];
45
- reasons: string[];
46
- json: string;
47
- writes: string[];
48
- /** Guard-side database reads (`delegate.method`), in order. */
49
- reads: string[];
50
- audit: Array<Record<string, unknown>>;
51
- counterDelta: Record<string, number>;
52
- auditFailureDelta: number;
53
- auditBypassDelta: number;
54
- }
55
- export {};
56
- //# sourceMappingURL=mutation-auth-guard.harness.d.ts.map