@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
@@ -1,41 +0,0 @@
1
- /**
2
- * Builds the GraphQL schema exactly as src/server.ts assembles it (generated
3
- * resolvers minus server-only models, residual surface stripped) and reports
4
- * anything of a server-only model that survives.
5
- *
6
- * The generated TypeGraphQL resolvers rely on `emitDecoratorMetadata`, which
7
- * vitest's esbuild transform does not emit, so this runs out of process under
8
- * ts-node (see src/middleware/__tests__/ts-node-harness.ts). Output is printed
9
- * between `<<<RESULTS>>>` and `<<<END>>>`.
10
- */
11
- import 'reflect-metadata';
12
- import { buildSchema } from 'type-graphql';
13
- import { printSchema } from 'graphql';
14
- import { resolvers } from '../../generated/typegraphql-prisma/index.mjs';
15
- import { BrokerageAccountCredentialStatusResolver, OptionsGreeksHistoryCustomResolver, TradingSettingsResolver, } from '../../resolvers/custom/index.mjs';
16
- import { isServerOnlyTypeName, withoutServerOnlyResolvers, withoutServerOnlySchemaSurface, } from '../server-only-models.mjs';
17
- async function main() {
18
- const schema = withoutServerOnlySchemaSurface(await buildSchema({
19
- resolvers: [
20
- ...withoutServerOnlyResolvers(resolvers),
21
- OptionsGreeksHistoryCustomResolver,
22
- TradingSettingsResolver,
23
- BrokerageAccountCredentialStatusResolver,
24
- ],
25
- validate: false,
26
- }));
27
- const sdl = printSchema(schema);
28
- const tradeCount = schema.getType('TradeCount');
29
- const report = {
30
- serverOnlyTypes: Object.keys(schema.getTypeMap()).filter(isServerOnlyTypeName),
31
- sdlMentions: (sdl.match(/restatement/gi) ?? []).length,
32
- hasTrade: schema.getType('Trade') !== undefined,
33
- tradeCountFields: tradeCount ? Object.keys(tradeCount.getFields()) : [],
34
- };
35
- process.stdout.write(`<<<RESULTS>>>${JSON.stringify(report)}<<<END>>>\n`);
36
- }
37
- main().catch((error) => {
38
- process.stderr.write(`harness failed: ${String(error)}\n`);
39
- process.exit(1);
40
- });
41
- //# sourceMappingURL=server-only-surface.harness.js.map
@@ -1,144 +0,0 @@
1
- /**
2
- * Out-of-process harness for `audit-log-write-redaction.test.ts`.
3
- *
4
- * Answers one question for every way an `AuditLog` row can be written: what
5
- * reaches Prisma's query engine? It runs each write through the server's own
6
- * Prisma client — the singleton `src/prismaClient.ts` builds, with every guard
7
- * that module applies — and through an unextended client, and records the
8
- * arguments each would hand the engine. A terminal capture extension, applied
9
- * last so it runs after every production extension, records them and returns
10
- * a synthetic row instead of executing: no database is ever contacted, and the
11
- * datasource URL points at a closed local port so an accidental execution
12
- * fails rather than writes.
13
- *
14
- * The write paths it drives:
15
- *
16
- * - every generated `AuditLog` write mutation, through the GENERATED resolver
17
- * served by a real ApolloServer with the mutation-authorization guard
18
- * installed as `server.ts` installs it, across the principal/mode matrix
19
- * (so "who can reach this resolver" is observed, not assumed);
20
- * - the audit plugin (`createAuditLogPlugin`) auditing another model's
21
- * mutation, and the TradingPolicy audit trail (`writeAttemptRow`);
22
- * - direct `prisma.auditLog` writes, including the operations no GraphQL
23
- * field exposes (`updateManyAndReturn`, `createMany` with a single row);
24
- * - the exact payload shapes the engine and platform write today, which must
25
- * reach the engine byte-identical through the guarded client;
26
- * - the acceptance matrix: every credential shape (named column,
27
- * variable-named, nested JSON, inline GraphQL arguments) on every generated
28
- * write, both as a credential model's write the audit plugin records and as
29
- * a direct write through a generated AuditLog mutation, plus credentials
30
- * nested in a relation write and credential-free writes of credential
31
- * models;
32
- * - the client `reconnectPrisma()` installs after a failed heartbeat.
33
- *
34
- * The generated TypeGraphQL resolvers need `emitDecoratorMetadata`, which
35
- * vitest's esbuild transform does not emit, hence ts-node. Run directly:
36
- * npx ts-node --transpile-only src/middleware/__tests__/audit-log-write-redaction.harness.ts
37
- */
38
- import 'reflect-metadata';
39
- import type { MutationAuthMode } from '../../auth/mutation-authorization';
40
- import type { BackendPrincipal } from '../../auth/token-verifier';
41
- export declare const API_KEY = "PKAUDITHARNESSKEY0000000";
42
- export declare const API_SECRET = "audit-harness-secret-that-must-never-persist";
43
- export declare const OAUTH_TOKEN = "audit-harness-oauth-refresh-token";
44
- /** `changedFields` as an AlpacaAccount key rotation records it: the defect's own shape. */
45
- export declare const CREDENTIAL_CHANGED_FIELDS: {
46
- where: {
47
- id: string;
48
- };
49
- data: {
50
- APIKey: {
51
- set: string;
52
- };
53
- APISecret: {
54
- set: string;
55
- };
56
- label: {
57
- set: string;
58
- };
59
- };
60
- };
61
- /** `metadata` carrying an OAuth token next to ordinary context. */
62
- export declare const CREDENTIAL_METADATA: {
63
- source: string;
64
- refresh_token: string;
65
- note: string;
66
- };
67
- declare const PRINCIPALS: Record<string, BackendPrincipal | null>;
68
- /** Each generated AuditLog write mutation, carrying credentials in every row it writes. */
69
- export declare const WRITE_MUTATIONS: Record<string, {
70
- query: string;
71
- variables: Record<string, unknown>;
72
- }>;
73
- /** The principal / mode combinations each write mutation is driven under. */
74
- export declare const AUTH_MATRIX: Array<{
75
- principal: keyof typeof PRINCIPALS;
76
- mode: MutationAuthMode;
77
- }>;
78
- /**
79
- * The payloads the engine and platform write today, as they arrive at
80
- * `/graphql` (the `data` variable of `createOneAuditLog`). None carries a
81
- * credential, so the guarded client must hand each to the engine unchanged.
82
- */
83
- export declare const CONSUMER_PAYLOADS: Record<string, Record<string, unknown>>;
84
- /** A value in the form it was handed to the engine, with Prisma's non-JSON values tagged. */
85
- type Described = null | boolean | number | string | Described[] | {
86
- [key: string]: Described;
87
- };
88
- /** One operation as the engine would have received it. */
89
- export interface Captured {
90
- model: string;
91
- operation: string;
92
- /** The operation's arguments, described. */
93
- args: Described;
94
- /** `JSON.stringify(args)`: the byte-level form compared for identity. */
95
- bytes: string;
96
- }
97
- /** What one scenario produced through each client. */
98
- export interface ScenarioResult {
99
- /** HTTP status of the GraphQL response; 0 for a direct write. */
100
- status: number;
101
- codes: string[];
102
- errors: string[];
103
- /** Operations that reached the engine through the server's guarded client. */
104
- production: Captured[];
105
- /** The same scenario through an unextended client: what nothing redacts. */
106
- unguarded: Captured[];
107
- }
108
- /** How a credential reaches the operation. */
109
- export type CredentialShape = 'named-column' | 'variable-named' | 'nested-json' | 'graphql-args';
110
- export declare const CREDENTIAL_SHAPES: readonly CredentialShape[];
111
- /**
112
- * Credential-free writes of credential models, sent as the generated client
113
- * sends them (each variable named after its argument). Main's recorder stored
114
- * the variables map; these rows must be byte-identical to that.
115
- */
116
- export declare const CREDENTIAL_FREE_WRITES: Record<string, {
117
- query: string;
118
- variables: Record<string, unknown>;
119
- operationType: 'CREATE' | 'UPDATE' | 'DELETE';
120
- }>;
121
- /** One matrix case: what the write must store, and what it did through each client. */
122
- export interface MatrixCase {
123
- path: 'plugin' | 'direct';
124
- field: string;
125
- shape: CredentialShape | 'nested-relation';
126
- /** The model the audited write targets (plugin), or AuditLog (direct). */
127
- model: string;
128
- /** The Prisma operation the field's resolver runs. */
129
- operation: string;
130
- /** Plugin: the audit type the row is recorded under. */
131
- auditType?: 'CREATE' | 'UPDATE';
132
- /** Plugin: the stored `changedFields`; direct: the stored rows. */
133
- expected: unknown;
134
- query: string;
135
- result: ScenarioResult;
136
- }
137
- /** A credential-free write, with what the test needs to rebuild main's row for it. */
138
- export interface CredentialFreeCase {
139
- variables: Record<string, unknown>;
140
- operationType: 'CREATE' | 'UPDATE' | 'DELETE';
141
- result: ScenarioResult;
142
- }
143
- export {};
144
- //# sourceMappingURL=audit-log-write-redaction.harness.d.ts.map