@adaptic/backend-legacy 0.0.1045 → 0.0.1047
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.
- package/esm/auth/credential-redaction.d.ts +12 -8
- package/esm/auth/credential-redaction.d.ts.map +1 -1
- package/esm/auth/credential-redaction.js.map +1 -1
- package/esm/auth/credential-redaction.mjs +40 -10
- package/esm/generated/typegraphql-prisma/models/TradeAuditEvent.d.ts +2 -2
- package/esm/generated/typegraphql-prisma/models/TradeAuditEvent.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/models/TradeAuditEvent.js.map +1 -1
- package/esm/generated/typegraphql-prisma/models/TradeAuditEvent.mjs +4 -4
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.mjs +2 -2
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.mjs +2 -2
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.mjs +2 -2
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.mjs +2 -2
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.d.ts +144 -0
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.d.ts.map +1 -0
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.js.map +1 -0
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.mjs +920 -0
- package/esm/middleware/audit-log-write-redaction.d.ts +82 -0
- package/esm/middleware/audit-log-write-redaction.d.ts.map +1 -0
- package/esm/middleware/audit-log-write-redaction.js.map +1 -0
- package/esm/middleware/audit-log-write-redaction.mjs +138 -0
- package/esm/middleware/audit-logger.d.ts +80 -17
- package/esm/middleware/audit-logger.d.ts.map +1 -1
- package/esm/middleware/audit-logger.js.map +1 -1
- package/esm/middleware/audit-logger.mjs +182 -67
- package/esm/middleware/index.d.ts +1 -0
- package/esm/middleware/index.d.ts.map +1 -1
- package/esm/middleware/index.js.map +1 -1
- package/esm/middleware/index.mjs +3 -0
- package/esm/prismaClient.d.ts +22 -0
- package/esm/prismaClient.d.ts.map +1 -1
- package/esm/prismaClient.js.map +1 -1
- package/esm/prismaClient.mjs +27 -3
- package/generated/typegraphql-prisma/models/TradeAuditEvent.cjs +3 -3
- package/generated/typegraphql-prisma/models/TradeAuditEvent.d.ts +2 -2
- package/generated/typegraphql-prisma/models/TradeAuditEvent.d.ts.map +1 -1
- package/generated/typegraphql-prisma/models/TradeAuditEvent.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.cjs +2 -2
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.cjs +2 -2
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventCreateManyInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithAggregationInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventOrderByWithRelationInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventScalarWhereWithAggregatesInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventUpdateManyMutationInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeAuditEventWhereUniqueInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.cjs +2 -2
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradeAuditEvent.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.cjs +2 -2
- package/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeAuditEventGroupBy.js.map +1 -1
- package/package.json +1 -1
- package/prismaClient.cjs +28 -2
- package/prismaClient.d.ts +22 -0
|
@@ -0,0 +1,920 @@
|
|
|
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 { ApolloServer } from '@apollo/server';
|
|
40
|
+
import { Prisma, PrismaClient } from '@prisma/client';
|
|
41
|
+
import { buildSchema } from 'type-graphql';
|
|
42
|
+
import { AlpacaAccountCrudResolver } from '../../generated/typegraphql-prisma/resolvers/crud/AlpacaAccount/AlpacaAccountCrudResolver.mjs';
|
|
43
|
+
import { AuditLogCrudResolver } from '../../generated/typegraphql-prisma/resolvers/crud/AuditLog/AuditLogCrudResolver.mjs';
|
|
44
|
+
import { UserCrudResolver } from '../../generated/typegraphql-prisma/resolvers/crud/User/UserCrudResolver.mjs';
|
|
45
|
+
import { REDACTED } from '../../auth/credential-redaction.mjs';
|
|
46
|
+
import { createHttpStatusMapperPlugin } from '../../plugins/http-status-mapper.mjs';
|
|
47
|
+
import { createAuditLogPlugin } from '../audit-logger.mjs';
|
|
48
|
+
import { installMutationAuthGuard } from '../mutation-auth-guard.mjs';
|
|
49
|
+
import { writeAttemptRow } from '../trading-policy-audit.mjs';
|
|
50
|
+
/**
|
|
51
|
+
* A datasource no query can reach: a closed port on the loopback interface.
|
|
52
|
+
* Set before `prismaClient.ts` is loaded so the singleton it builds points
|
|
53
|
+
* here, whatever DATABASE_URL the parent environment carries.
|
|
54
|
+
*/
|
|
55
|
+
const UNREACHABLE_DATABASE_URL = 'postgresql://harness:harness@127.0.0.1:9/harness';
|
|
56
|
+
export const API_KEY = 'PKAUDITHARNESSKEY0000000';
|
|
57
|
+
export const API_SECRET = 'audit-harness-secret-that-must-never-persist';
|
|
58
|
+
export const OAUTH_TOKEN = 'audit-harness-oauth-refresh-token';
|
|
59
|
+
const U_USER = '11111111-1111-4111-8111-111111111111';
|
|
60
|
+
const AUDIT_ROW_ID = '99999999-9999-4999-8999-999999999999';
|
|
61
|
+
/** `changedFields` as an AlpacaAccount key rotation records it: the defect's own shape. */
|
|
62
|
+
export const CREDENTIAL_CHANGED_FIELDS = {
|
|
63
|
+
where: { id: 'acct-1' },
|
|
64
|
+
data: { APIKey: { set: API_KEY }, APISecret: { set: API_SECRET }, label: { set: 'rotated' } },
|
|
65
|
+
};
|
|
66
|
+
/** `metadata` carrying an OAuth token next to ordinary context. */
|
|
67
|
+
export const CREDENTIAL_METADATA = { source: 'harness', refresh_token: OAUTH_TOKEN, note: 'kept' };
|
|
68
|
+
/** A row whose two JSON columns both carry a credential. */
|
|
69
|
+
const CREDENTIAL_ROW = {
|
|
70
|
+
operationType: 'UPDATE',
|
|
71
|
+
modelName: 'AlpacaAccount',
|
|
72
|
+
recordId: 'acct-1',
|
|
73
|
+
changedFields: CREDENTIAL_CHANGED_FIELDS,
|
|
74
|
+
metadata: CREDENTIAL_METADATA,
|
|
75
|
+
};
|
|
76
|
+
/** A row with no credential anywhere, written alongside a credential row. */
|
|
77
|
+
const PLAIN_ROW = {
|
|
78
|
+
operationType: 'CREATE',
|
|
79
|
+
modelName: 'Order',
|
|
80
|
+
recordId: 'order-2',
|
|
81
|
+
changedFields: { status: 'cancel_requested' },
|
|
82
|
+
metadata: { source: 'harness' },
|
|
83
|
+
};
|
|
84
|
+
const PRINCIPALS = {
|
|
85
|
+
none: null,
|
|
86
|
+
server: { kind: 'server', sub: 'adaptic-engine:audit-harness' },
|
|
87
|
+
user: { kind: 'user', sub: U_USER, roles: ['user'] },
|
|
88
|
+
};
|
|
89
|
+
const CREATE_ONE = 'mutation CreateOne($data: AuditLogCreateInput!) { createOneAuditLog(data: $data) { id } }';
|
|
90
|
+
const CREATE_MANY = 'mutation CreateMany($data: [AuditLogCreateManyInput!]!) { createManyAuditLog(data: $data) { count } }';
|
|
91
|
+
const CREATE_MANY_AND_RETURN = 'mutation CreateManyAndReturn($data: [AuditLogCreateManyInput!]!) { createManyAndReturnAuditLog(data: $data) { id } }';
|
|
92
|
+
const UPDATE_ONE = 'mutation UpdateOne($where: AuditLogWhereUniqueInput!, $data: AuditLogUpdateInput!) { updateOneAuditLog(where: $where, data: $data) { id } }';
|
|
93
|
+
const UPDATE_MANY = 'mutation UpdateMany($where: AuditLogWhereInput, $data: AuditLogUpdateManyMutationInput!) { updateManyAuditLog(where: $where, data: $data) { count } }';
|
|
94
|
+
const UPSERT_ONE = 'mutation UpsertOne($where: AuditLogWhereUniqueInput!, $create: AuditLogCreateInput!, $update: AuditLogUpdateInput!) { upsertOneAuditLog(where: $where, create: $create, update: $update) { id } }';
|
|
95
|
+
const UPDATE_ACCOUNT_KEYS = 'mutation RotateKeys($where: AlpacaAccountWhereUniqueInput!, $data: AlpacaAccountUpdateInput!) { updateOneAlpacaAccount(where: $where, data: $data) { id } }';
|
|
96
|
+
/** Each generated AuditLog write mutation, carrying credentials in every row it writes. */
|
|
97
|
+
export const WRITE_MUTATIONS = {
|
|
98
|
+
createOneAuditLog: { query: CREATE_ONE, variables: { data: CREDENTIAL_ROW } },
|
|
99
|
+
createManyAuditLog: { query: CREATE_MANY, variables: { data: [CREDENTIAL_ROW, PLAIN_ROW] } },
|
|
100
|
+
createManyAndReturnAuditLog: { query: CREATE_MANY_AND_RETURN, variables: { data: [CREDENTIAL_ROW, PLAIN_ROW] } },
|
|
101
|
+
updateOneAuditLog: {
|
|
102
|
+
query: UPDATE_ONE,
|
|
103
|
+
variables: {
|
|
104
|
+
where: { id: AUDIT_ROW_ID },
|
|
105
|
+
data: { changedFields: CREDENTIAL_CHANGED_FIELDS, metadata: CREDENTIAL_METADATA },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
updateManyAuditLog: {
|
|
109
|
+
query: UPDATE_MANY,
|
|
110
|
+
variables: {
|
|
111
|
+
where: { modelName: { equals: 'AlpacaAccount' } },
|
|
112
|
+
data: { changedFields: CREDENTIAL_CHANGED_FIELDS, metadata: CREDENTIAL_METADATA },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
upsertOneAuditLog: {
|
|
116
|
+
query: UPSERT_ONE,
|
|
117
|
+
variables: {
|
|
118
|
+
where: { id: AUDIT_ROW_ID },
|
|
119
|
+
create: CREDENTIAL_ROW,
|
|
120
|
+
update: { changedFields: CREDENTIAL_CHANGED_FIELDS, metadata: CREDENTIAL_METADATA },
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
/** The principal / mode combinations each write mutation is driven under. */
|
|
125
|
+
export const AUTH_MATRIX = [
|
|
126
|
+
{ principal: 'none', mode: 'shadow' },
|
|
127
|
+
{ principal: 'none', mode: 'enforce' },
|
|
128
|
+
{ principal: 'user', mode: 'enforce' },
|
|
129
|
+
{ principal: 'server', mode: 'enforce' },
|
|
130
|
+
];
|
|
131
|
+
const ISO_NOW = '2026-09-26T16:00:00.000Z';
|
|
132
|
+
/**
|
|
133
|
+
* The payloads the engine and platform write today, as they arrive at
|
|
134
|
+
* `/graphql` (the `data` variable of `createOneAuditLog`). None carries a
|
|
135
|
+
* credential, so the guarded client must hand each to the engine unchanged.
|
|
136
|
+
*/
|
|
137
|
+
export const CONSUMER_PAYLOADS = {
|
|
138
|
+
// engine src/routes/order-cancel.routes.ts writeCancelAudit()
|
|
139
|
+
'engine/order-cancel': {
|
|
140
|
+
timestamp: ISO_NOW,
|
|
141
|
+
userId: null,
|
|
142
|
+
operationType: 'DELETE',
|
|
143
|
+
modelName: 'Order',
|
|
144
|
+
recordId: 'broker-order-1',
|
|
145
|
+
changedFields: { status: 'cancel_requested' },
|
|
146
|
+
operationName: 'order.cancel',
|
|
147
|
+
ipAddress: null,
|
|
148
|
+
metadata: { accountId: 'acct-1', source: 'engine.order-cancel-route' },
|
|
149
|
+
},
|
|
150
|
+
// engine src/services/fund/nav-strike-audit.ts, the strike row
|
|
151
|
+
'engine/nav-strike': {
|
|
152
|
+
timestamp: ISO_NOW,
|
|
153
|
+
userId: U_USER,
|
|
154
|
+
operationType: 'CREATE',
|
|
155
|
+
modelName: 'FundNavRecord',
|
|
156
|
+
recordId: 'nav-record-1',
|
|
157
|
+
operationName: 'fund.nav.strike',
|
|
158
|
+
changedFields: {
|
|
159
|
+
fundId: 'fund-1',
|
|
160
|
+
periodEnd: '2026-09-25T00:00:00.000Z',
|
|
161
|
+
periodType: 'DAILY',
|
|
162
|
+
valuationAt: ISO_NOW,
|
|
163
|
+
navPerShare: 101.25,
|
|
164
|
+
sharesOutstanding: 1000,
|
|
165
|
+
netAssetValue: 101250,
|
|
166
|
+
totalAssets: 101500,
|
|
167
|
+
totalLiabilities: 250,
|
|
168
|
+
previousNavPerShare: 100,
|
|
169
|
+
highWaterMarkNav: 101.25,
|
|
170
|
+
staleMarkCount: 0,
|
|
171
|
+
calculationMethod: 'MARK_TO_MARKET',
|
|
172
|
+
valuationInputs: {
|
|
173
|
+
accounts: [{ accountId: 'acct-1', equity: 101500, asOf: ISO_NOW, stale: false }],
|
|
174
|
+
holdingsCounted: 3,
|
|
175
|
+
maxMarkAgeMs: 60000,
|
|
176
|
+
},
|
|
177
|
+
executionCount: 1,
|
|
178
|
+
holdingsUpdated: 1,
|
|
179
|
+
},
|
|
180
|
+
ipAddress: null,
|
|
181
|
+
metadata: { idempotencyKey: 'strike-1', replayed: false, correlationId: null, source: 'engine.nav-strike' },
|
|
182
|
+
},
|
|
183
|
+
// engine src/services/fund/nav-strike-audit.ts, one executed movement
|
|
184
|
+
'engine/nav-execution': {
|
|
185
|
+
timestamp: ISO_NOW,
|
|
186
|
+
userId: U_USER,
|
|
187
|
+
operationType: 'UPDATE',
|
|
188
|
+
modelName: 'InvestorTransaction',
|
|
189
|
+
recordId: 'txn-1',
|
|
190
|
+
operationName: 'fund.nav.execute_transaction',
|
|
191
|
+
changedFields: {
|
|
192
|
+
status: 'COMPLETED',
|
|
193
|
+
executionNav: 101.25,
|
|
194
|
+
executedUnits: 9.876,
|
|
195
|
+
netAmount: 1000,
|
|
196
|
+
investorId: 'investor-1',
|
|
197
|
+
type: 'SUBSCRIPTION',
|
|
198
|
+
},
|
|
199
|
+
ipAddress: null,
|
|
200
|
+
metadata: { navRecordId: 'nav-record-1', fundId: 'fund-1', source: 'engine.nav-strike' },
|
|
201
|
+
},
|
|
202
|
+
// platform apps/web/lib/audit/audit-log.ts buildAuditLogInput(), as the broker-credentials route calls it
|
|
203
|
+
'platform/broker-credentials': {
|
|
204
|
+
userId: U_USER,
|
|
205
|
+
operationType: 'CREATE',
|
|
206
|
+
modelName: 'BrokerageAccount',
|
|
207
|
+
recordId: 'fund-1',
|
|
208
|
+
changedFields: { provider: 'ALPACA', accountType: 'PAPER', fundId: 'fund-1' },
|
|
209
|
+
operationName: 'broker_credentials.create',
|
|
210
|
+
ipAddress: '203.0.113.7',
|
|
211
|
+
metadata: {
|
|
212
|
+
outcome: 'success',
|
|
213
|
+
actorUserId: U_USER,
|
|
214
|
+
requestId: 'req-1',
|
|
215
|
+
statusCode: 200,
|
|
216
|
+
method: 'POST',
|
|
217
|
+
path: '/api/broker-credentials',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
// platform apps/web/lib/auth/auth-events.ts persistAuthEvent()
|
|
221
|
+
'platform/auth-event': {
|
|
222
|
+
userId: U_USER,
|
|
223
|
+
operationType: 'CREATE',
|
|
224
|
+
modelName: 'Session',
|
|
225
|
+
recordId: U_USER,
|
|
226
|
+
changedFields: {},
|
|
227
|
+
operationName: 'auth.login_success',
|
|
228
|
+
ipAddress: '203.0.113.7',
|
|
229
|
+
metadata: {
|
|
230
|
+
outcome: 'success',
|
|
231
|
+
actorUserId: U_USER,
|
|
232
|
+
eventType: 'LOGIN_SUCCESS',
|
|
233
|
+
email: 'someone@example.test',
|
|
234
|
+
userAgent: 'Mozilla/5.0',
|
|
235
|
+
provider: 'google',
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
// platform apps/web/lib/data-adapters/mutations.ts submitKycDecision()
|
|
239
|
+
'platform/kyc-decision': {
|
|
240
|
+
operationType: 'UPDATE',
|
|
241
|
+
modelName: 'Customer',
|
|
242
|
+
recordId: '42',
|
|
243
|
+
operationName: 'submitKycDecision',
|
|
244
|
+
userId: U_USER,
|
|
245
|
+
changedFields: { amlStatus: { after: 'CLEAR' }, lastKycUpdate: { after: ISO_NOW } },
|
|
246
|
+
metadata: { source: 'adaptic-os-client', kycDecision: 'approve', reason: 'documents verified' },
|
|
247
|
+
},
|
|
248
|
+
// platform apps/web/lib/notifications/dispatcher/process-event.ts writeAuditEntry()
|
|
249
|
+
'platform/notification-delivery': {
|
|
250
|
+
operationType: 'CREATE',
|
|
251
|
+
modelName: 'NotificationDelivery',
|
|
252
|
+
recordId: 'delivery-1',
|
|
253
|
+
changedFields: {
|
|
254
|
+
eventRowId: 'event-1',
|
|
255
|
+
catalogEventId: 'fund.nav.struck',
|
|
256
|
+
recipientUserId: U_USER,
|
|
257
|
+
channel: 'EMAIL',
|
|
258
|
+
templateId: 'fund.nav.struck',
|
|
259
|
+
templateVersion: '2026-09-01',
|
|
260
|
+
status: 'SENT',
|
|
261
|
+
},
|
|
262
|
+
operationName: 'notificationDispatch',
|
|
263
|
+
metadata: { source: 'engine', orgId: 'org-1', fundId: 'fund-1', audiencePolicy: 'fund-investors' },
|
|
264
|
+
},
|
|
265
|
+
// A nullable JSON column sent as null.
|
|
266
|
+
'nullable/metadata-null': {
|
|
267
|
+
operationType: 'CREATE',
|
|
268
|
+
modelName: 'Order',
|
|
269
|
+
recordId: 'order-3',
|
|
270
|
+
changedFields: { status: 'cancel_requested' },
|
|
271
|
+
metadata: null,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
function describeValue(value) {
|
|
275
|
+
if (value === undefined)
|
|
276
|
+
return { $undefined: true };
|
|
277
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
280
|
+
if (typeof value === 'bigint')
|
|
281
|
+
return { $bigint: value.toString() };
|
|
282
|
+
if (value === Prisma.DbNull)
|
|
283
|
+
return { $sentinel: 'DbNull' };
|
|
284
|
+
if (value === Prisma.JsonNull)
|
|
285
|
+
return { $sentinel: 'JsonNull' };
|
|
286
|
+
if (value === Prisma.AnyNull)
|
|
287
|
+
return { $sentinel: 'AnyNull' };
|
|
288
|
+
if (value instanceof Date)
|
|
289
|
+
return { $date: Number.isNaN(value.getTime()) ? 'invalid' : value.toISOString() };
|
|
290
|
+
if (Prisma.Decimal.isDecimal(value))
|
|
291
|
+
return { $decimal: value.toFixed() };
|
|
292
|
+
if (Array.isArray(value))
|
|
293
|
+
return value.map(describeValue);
|
|
294
|
+
if (typeof value === 'object') {
|
|
295
|
+
const out = {};
|
|
296
|
+
for (const [key, child] of Object.entries(value))
|
|
297
|
+
out[key] = describeValue(child);
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
return { $unserializable: typeof value };
|
|
301
|
+
}
|
|
302
|
+
function rowsIn(args) {
|
|
303
|
+
return Array.isArray(args.data) ? args.data.length : 1;
|
|
304
|
+
}
|
|
305
|
+
/** A plausible engine result, so resolvers and writers carry on as if the write ran. */
|
|
306
|
+
function syntheticResult(operation, args) {
|
|
307
|
+
switch (operation) {
|
|
308
|
+
case 'createMany':
|
|
309
|
+
case 'updateMany':
|
|
310
|
+
case 'deleteMany':
|
|
311
|
+
return { count: rowsIn(args) };
|
|
312
|
+
case 'createManyAndReturn':
|
|
313
|
+
case 'updateManyAndReturn':
|
|
314
|
+
return Array.from({ length: rowsIn(args) }, (_, index) => ({ id: `captured-${index + 1}` }));
|
|
315
|
+
case 'findMany':
|
|
316
|
+
return [];
|
|
317
|
+
case 'findUnique':
|
|
318
|
+
case 'findUniqueOrThrow':
|
|
319
|
+
case 'findFirst':
|
|
320
|
+
case 'findFirstOrThrow':
|
|
321
|
+
return null;
|
|
322
|
+
case 'count':
|
|
323
|
+
return 0;
|
|
324
|
+
default:
|
|
325
|
+
return { id: 'captured-row' };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Apply the terminal capture. Applied LAST, it runs after every extension the
|
|
330
|
+
* client already carries, so it sees exactly what the engine would; it never
|
|
331
|
+
* calls `query`, so nothing executes.
|
|
332
|
+
*/
|
|
333
|
+
function withEngineBoundaryCapture(client, sink) {
|
|
334
|
+
const extended = client.$extends({
|
|
335
|
+
name: 'engine-boundary-capture',
|
|
336
|
+
query: {
|
|
337
|
+
$allModels: {
|
|
338
|
+
$allOperations({ model, operation, args }) {
|
|
339
|
+
const described = describeValue(args);
|
|
340
|
+
sink.push({ model, operation, args: described, bytes: JSON.stringify(described) });
|
|
341
|
+
return Promise.resolve(syntheticResult(operation, (args ?? {})));
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
return extended;
|
|
347
|
+
}
|
|
348
|
+
async function runBoth(guarded, unguarded, run) {
|
|
349
|
+
const production = [];
|
|
350
|
+
const baseline = [];
|
|
351
|
+
const outcome = await run(withEngineBoundaryCapture(guarded, production));
|
|
352
|
+
await run(withEngineBoundaryCapture(unguarded, baseline));
|
|
353
|
+
return { ...outcome, production, unguarded: baseline };
|
|
354
|
+
}
|
|
355
|
+
function direct(write) {
|
|
356
|
+
return async (client) => {
|
|
357
|
+
try {
|
|
358
|
+
await write(client);
|
|
359
|
+
return { status: 0, codes: [], errors: [] };
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
return { status: 0, codes: ['THROWN'], errors: [error instanceof Error ? error.message : String(error)] };
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/** A TradingPolicy write whose requested change reaches an account's keys. */
|
|
367
|
+
const POLICY_ENTRY = {
|
|
368
|
+
mutation: 'updateOneTradingPolicy',
|
|
369
|
+
action: 'update',
|
|
370
|
+
nestedPaths: ['data.alpacaAccount'],
|
|
371
|
+
actor: { principalKind: 'server', sub: 'adaptic-engine:audit-harness', email: null, ip: null, userAgent: null, origin: null },
|
|
372
|
+
changeReason: null,
|
|
373
|
+
decision: 'allowed',
|
|
374
|
+
authorizationReason: 'service_principal',
|
|
375
|
+
effectiveMode: 'shadow',
|
|
376
|
+
graphqlOperationName: null,
|
|
377
|
+
requested: { data: { alpacaAccount: { update: { APIKey: { set: API_KEY }, APISecret: { set: API_SECRET } } } } },
|
|
378
|
+
policies: [],
|
|
379
|
+
};
|
|
380
|
+
// -----------------------------------------------------------------------------
|
|
381
|
+
// Acceptance matrix: every credential shape on every write
|
|
382
|
+
// -----------------------------------------------------------------------------
|
|
383
|
+
/** A credential value, and the variable that carries it when a shape passes credentials by variable. */
|
|
384
|
+
class Secret {
|
|
385
|
+
variable;
|
|
386
|
+
value;
|
|
387
|
+
constructor(variable, value) {
|
|
388
|
+
this.variable = variable;
|
|
389
|
+
this.value = value;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** The value of a credential column, whatever it holds: stored as the redaction placeholder. */
|
|
393
|
+
class Credential {
|
|
394
|
+
value;
|
|
395
|
+
constructor(value) {
|
|
396
|
+
this.value = value;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/** A JSON value passed as its own `JSON!` variable, as a client sends a JSON column. */
|
|
400
|
+
class JsonVariable {
|
|
401
|
+
variable;
|
|
402
|
+
value;
|
|
403
|
+
constructor(variable, value) {
|
|
404
|
+
this.variable = variable;
|
|
405
|
+
this.value = value;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/** An enum value, written bare in a GraphQL literal. */
|
|
409
|
+
class EnumValue {
|
|
410
|
+
name;
|
|
411
|
+
constructor(name) {
|
|
412
|
+
this.name = name;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const KEY = new Secret('k', API_KEY);
|
|
416
|
+
const SECRET = new Secret('s', API_SECRET);
|
|
417
|
+
const TOKEN = new Secret('t', OAUTH_TOKEN);
|
|
418
|
+
const ACCOUNT = 'acct-1';
|
|
419
|
+
const cred = (value) => new Credential(value);
|
|
420
|
+
export const CREDENTIAL_SHAPES = [
|
|
421
|
+
'named-column',
|
|
422
|
+
'variable-named',
|
|
423
|
+
'nested-json',
|
|
424
|
+
'graphql-args',
|
|
425
|
+
];
|
|
426
|
+
/** The value a template stands for, as a request variable carries it. */
|
|
427
|
+
function plain(value) {
|
|
428
|
+
if (value instanceof Credential || value instanceof JsonVariable)
|
|
429
|
+
return plain(value.value);
|
|
430
|
+
if (value instanceof Secret)
|
|
431
|
+
return value.value;
|
|
432
|
+
if (value instanceof EnumValue)
|
|
433
|
+
return value.name;
|
|
434
|
+
if (Array.isArray(value))
|
|
435
|
+
return value.map(plain);
|
|
436
|
+
if (value !== null && typeof value === 'object') {
|
|
437
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, plain(child)]));
|
|
438
|
+
}
|
|
439
|
+
return value;
|
|
440
|
+
}
|
|
441
|
+
/** What a correct audit row stores for a template: every credential column's value replaced. */
|
|
442
|
+
function stored(value) {
|
|
443
|
+
if (value instanceof Credential)
|
|
444
|
+
return REDACTED;
|
|
445
|
+
if (value instanceof JsonVariable)
|
|
446
|
+
return stored(value.value);
|
|
447
|
+
if (value instanceof Secret)
|
|
448
|
+
return value.value;
|
|
449
|
+
if (value instanceof EnumValue)
|
|
450
|
+
return value.name;
|
|
451
|
+
if (Array.isArray(value))
|
|
452
|
+
return value.map(stored);
|
|
453
|
+
if (value !== null && typeof value === 'object') {
|
|
454
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, stored(child)]));
|
|
455
|
+
}
|
|
456
|
+
return value;
|
|
457
|
+
}
|
|
458
|
+
/** The template as a GraphQL literal, credentials inline or as `$variable` references. */
|
|
459
|
+
function render(value, credentials) {
|
|
460
|
+
if (value instanceof Credential)
|
|
461
|
+
return render(value.value, credentials);
|
|
462
|
+
if (value instanceof Secret)
|
|
463
|
+
return credentials === 'inline' ? JSON.stringify(value.value) : `$${value.variable}`;
|
|
464
|
+
if (value instanceof JsonVariable)
|
|
465
|
+
return `$${value.variable}`;
|
|
466
|
+
if (value instanceof EnumValue)
|
|
467
|
+
return value.name;
|
|
468
|
+
if (value === null)
|
|
469
|
+
return 'null';
|
|
470
|
+
if (Array.isArray(value))
|
|
471
|
+
return `[${value.map((item) => render(item, credentials)).join(', ')}]`;
|
|
472
|
+
if (typeof value === 'object') {
|
|
473
|
+
const fields = Object.entries(value).map(([key, child]) => `${key}: ${render(child, credentials)}`);
|
|
474
|
+
return `{ ${fields.join(', ')} }`;
|
|
475
|
+
}
|
|
476
|
+
return JSON.stringify(value);
|
|
477
|
+
}
|
|
478
|
+
/** The variables a rendered template references: credentials (when passed by variable) and JSON values. */
|
|
479
|
+
function referencedVariables(value, credentials, found) {
|
|
480
|
+
if (value instanceof Credential)
|
|
481
|
+
return referencedVariables(value.value, credentials, found);
|
|
482
|
+
if (value instanceof JsonVariable) {
|
|
483
|
+
found.set(value.variable, { type: 'JSON!', value: plain(value.value) });
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (value instanceof Secret) {
|
|
487
|
+
if (credentials === 'variables')
|
|
488
|
+
found.set(value.variable, { type: 'String!', value: value.value });
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (Array.isArray(value)) {
|
|
492
|
+
for (const item of value)
|
|
493
|
+
referencedVariables(item, credentials, found);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (value !== null && typeof value === 'object' && !(value instanceof EnumValue)) {
|
|
497
|
+
for (const child of Object.values(value))
|
|
498
|
+
referencedVariables(child, credentials, found);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The operation that sends `spec` with its credentials in `shape`:
|
|
503
|
+
*
|
|
504
|
+
* - `named-column`: every argument is a variable named after the argument, so
|
|
505
|
+
* the credential sits under its column name in what the client sends (the
|
|
506
|
+
* generated client's own documents);
|
|
507
|
+
* - `variable-named`: each credential is its own scalar variable (`$k`, `$s`,
|
|
508
|
+
* `$t`), named by the operation rather than the schema;
|
|
509
|
+
* - `nested-json`: the spec carries a credential deep inside a JSON value, sent
|
|
510
|
+
* as a `JSON!` variable, with everything else inline;
|
|
511
|
+
* - `graphql-args`: every value, credentials included, is written inline.
|
|
512
|
+
*/
|
|
513
|
+
function operationFor(spec, shape) {
|
|
514
|
+
if (shape === 'named-column') {
|
|
515
|
+
const declarations = spec.args.map(([name, type]) => `$${name}: ${type}`).join(', ');
|
|
516
|
+
const passed = spec.args.map(([name]) => `${name}: $${name}`).join(', ');
|
|
517
|
+
return {
|
|
518
|
+
query: `mutation NamedColumn(${declarations}) { ${spec.field}(${passed}) ${spec.selection} }`,
|
|
519
|
+
variables: Object.fromEntries(spec.args.map(([name, , value]) => [name, plain(value)])),
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
const credentials = shape === 'variable-named' ? 'variables' : 'inline';
|
|
523
|
+
const found = new Map();
|
|
524
|
+
for (const [, , value] of spec.args)
|
|
525
|
+
referencedVariables(value, credentials, found);
|
|
526
|
+
const declarations = [...found].map(([name, { type }]) => `$${name}: ${type}`);
|
|
527
|
+
const passed = spec.args.map(([name, , value]) => `${name}: ${render(value, credentials)}`).join(', ');
|
|
528
|
+
return {
|
|
529
|
+
query: `mutation Shaped${declarations.length ? `(${declarations.join(', ')})` : ''} { ${spec.field}(${passed}) ${spec.selection} }`,
|
|
530
|
+
variables: Object.fromEntries([...found].map(([name, { value }]) => [name, value])),
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
/** The Prisma operation each generated field runs, and the audit type the plugin records it under. */
|
|
534
|
+
const FIELD_OPERATIONS = {
|
|
535
|
+
createOne: { operation: 'create', auditType: 'CREATE' },
|
|
536
|
+
createMany: { operation: 'createMany', auditType: 'CREATE' },
|
|
537
|
+
createManyAndReturn: { operation: 'createManyAndReturn', auditType: 'CREATE' },
|
|
538
|
+
updateOne: { operation: 'update', auditType: 'UPDATE' },
|
|
539
|
+
updateMany: { operation: 'updateMany', auditType: 'UPDATE' },
|
|
540
|
+
upsertOne: { operation: 'upsert', auditType: 'CREATE' },
|
|
541
|
+
};
|
|
542
|
+
/** A generated field split into its model, Prisma operation and audit type, longest prefix first. */
|
|
543
|
+
function fieldOperation(field) {
|
|
544
|
+
const prefix = Object.keys(FIELD_OPERATIONS)
|
|
545
|
+
.sort((a, b) => b.length - a.length)
|
|
546
|
+
.find((candidate) => field.startsWith(candidate));
|
|
547
|
+
if (!prefix)
|
|
548
|
+
throw new Error(`no operation for ${field}`);
|
|
549
|
+
return { model: field.slice(prefix.length), ...FIELD_OPERATIONS[prefix] };
|
|
550
|
+
}
|
|
551
|
+
/** The `changedFields` a correct audit plugin row stores for `spec`: its arguments under their schema paths. */
|
|
552
|
+
function expectedPluginChangedFields(spec) {
|
|
553
|
+
const args = Object.fromEntries(spec.args.map(([name, , value]) => [name, stored(value)]));
|
|
554
|
+
return fieldOperation(spec.field).auditType === 'CREATE'
|
|
555
|
+
? { input: args.data ?? args }
|
|
556
|
+
: { where: args.where ?? {}, data: args.data ?? {} };
|
|
557
|
+
}
|
|
558
|
+
/** The rows a correct direct AuditLog write stores for `spec`, in `data`, `create`, `update` order. */
|
|
559
|
+
function expectedDirectRows(spec) {
|
|
560
|
+
const args = new Map(spec.args.map(([name, , value]) => [name, stored(value)]));
|
|
561
|
+
return ['data', 'create', 'update'].flatMap((name) => {
|
|
562
|
+
const payload = args.get(name);
|
|
563
|
+
if (payload === undefined)
|
|
564
|
+
return [];
|
|
565
|
+
return Array.isArray(payload) ? payload : [payload];
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
// --- the credential model the audit plugin records: AlpacaAccount ----------
|
|
569
|
+
const ACCOUNT_CREATE = {
|
|
570
|
+
APIKey: cred(KEY),
|
|
571
|
+
APISecret: cred(SECRET),
|
|
572
|
+
tradeAllocationPct: 7,
|
|
573
|
+
user: { connect: { id: U_USER } },
|
|
574
|
+
};
|
|
575
|
+
const ACCOUNT_CREATE_MANY_ROW = {
|
|
576
|
+
APIKey: cred(KEY),
|
|
577
|
+
APISecret: cred(SECRET),
|
|
578
|
+
tradeAllocationPct: 7,
|
|
579
|
+
userId: U_USER,
|
|
580
|
+
};
|
|
581
|
+
const ACCOUNT_UPDATE = {
|
|
582
|
+
APIKey: cred({ set: KEY }),
|
|
583
|
+
APISecret: cred({ set: SECRET }),
|
|
584
|
+
tradeAllocationPct: { set: 7 },
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* The same row with a JSON column that carries a credential three levels
|
|
588
|
+
* down, next to values that must be kept, when the shape is `nested-json`.
|
|
589
|
+
*/
|
|
590
|
+
function withNestedJson(row, shape) {
|
|
591
|
+
if (shape !== 'nested-json')
|
|
592
|
+
return row;
|
|
593
|
+
return {
|
|
594
|
+
...row,
|
|
595
|
+
configuration: new JsonVariable('cfg', {
|
|
596
|
+
broker: { region: 'us-east', auth: { apiSecret: cred(SECRET) } },
|
|
597
|
+
note: 'kept',
|
|
598
|
+
}),
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
const ACCOUNT_WHERE_UNIQUE = { id: ACCOUNT };
|
|
602
|
+
const ACCOUNT_WHERE_MANY = { userId: { equals: U_USER } };
|
|
603
|
+
/** Each audited AlpacaAccount write, per shape. */
|
|
604
|
+
const PLUGIN_WRITES = {
|
|
605
|
+
createOneAlpacaAccount: (shape) => ({
|
|
606
|
+
field: 'createOneAlpacaAccount',
|
|
607
|
+
args: [['data', 'AlpacaAccountCreateInput!', withNestedJson(ACCOUNT_CREATE, shape)]],
|
|
608
|
+
selection: '{ id }',
|
|
609
|
+
}),
|
|
610
|
+
createManyAlpacaAccount: (shape) => ({
|
|
611
|
+
field: 'createManyAlpacaAccount',
|
|
612
|
+
args: [['data', '[AlpacaAccountCreateManyInput!]!', [withNestedJson(ACCOUNT_CREATE_MANY_ROW, shape)]]],
|
|
613
|
+
selection: '{ count }',
|
|
614
|
+
}),
|
|
615
|
+
createManyAndReturnAlpacaAccount: (shape) => ({
|
|
616
|
+
field: 'createManyAndReturnAlpacaAccount',
|
|
617
|
+
args: [['data', '[AlpacaAccountCreateManyInput!]!', [withNestedJson(ACCOUNT_CREATE_MANY_ROW, shape)]]],
|
|
618
|
+
selection: '{ id }',
|
|
619
|
+
}),
|
|
620
|
+
updateOneAlpacaAccount: (shape) => ({
|
|
621
|
+
field: 'updateOneAlpacaAccount',
|
|
622
|
+
args: [
|
|
623
|
+
['where', 'AlpacaAccountWhereUniqueInput!', ACCOUNT_WHERE_UNIQUE],
|
|
624
|
+
['data', 'AlpacaAccountUpdateInput!', withNestedJson(ACCOUNT_UPDATE, shape)],
|
|
625
|
+
],
|
|
626
|
+
selection: '{ id }',
|
|
627
|
+
}),
|
|
628
|
+
updateManyAlpacaAccount: (shape) => ({
|
|
629
|
+
field: 'updateManyAlpacaAccount',
|
|
630
|
+
args: [
|
|
631
|
+
['where', 'AlpacaAccountWhereInput', ACCOUNT_WHERE_MANY],
|
|
632
|
+
['data', 'AlpacaAccountUpdateManyMutationInput!', withNestedJson(ACCOUNT_UPDATE, shape)],
|
|
633
|
+
],
|
|
634
|
+
selection: '{ count }',
|
|
635
|
+
}),
|
|
636
|
+
upsertOneAlpacaAccount: (shape) => ({
|
|
637
|
+
field: 'upsertOneAlpacaAccount',
|
|
638
|
+
args: [
|
|
639
|
+
['where', 'AlpacaAccountWhereUniqueInput!', ACCOUNT_WHERE_UNIQUE],
|
|
640
|
+
['create', 'AlpacaAccountCreateInput!', withNestedJson(ACCOUNT_CREATE, shape)],
|
|
641
|
+
['update', 'AlpacaAccountUpdateInput!', withNestedJson(ACCOUNT_UPDATE, shape)],
|
|
642
|
+
],
|
|
643
|
+
selection: '{ id }',
|
|
644
|
+
}),
|
|
645
|
+
};
|
|
646
|
+
/** A credential nested in a relation write of a model that holds none on the row itself. */
|
|
647
|
+
const NESTED_RELATION_WRITES = {
|
|
648
|
+
createOneUser: {
|
|
649
|
+
field: 'createOneUser',
|
|
650
|
+
args: [['data', 'UserCreateInput!', { name: 'harness user', alpacaAccounts: { create: [{ APIKey: cred(KEY), APISecret: cred(SECRET) }] } }]],
|
|
651
|
+
selection: '{ id }',
|
|
652
|
+
},
|
|
653
|
+
updateOneUser: {
|
|
654
|
+
field: 'updateOneUser',
|
|
655
|
+
args: [
|
|
656
|
+
['where', 'UserWhereUniqueInput!', { id: U_USER }],
|
|
657
|
+
['data', 'UserUpdateInput!', { alpacaAccounts: { update: [{ where: { id: ACCOUNT }, data: { APIKey: cred({ set: KEY }), APISecret: cred({ set: SECRET }) } }] } }],
|
|
658
|
+
],
|
|
659
|
+
selection: '{ id }',
|
|
660
|
+
},
|
|
661
|
+
upsertOneUser: {
|
|
662
|
+
field: 'upsertOneUser',
|
|
663
|
+
args: [
|
|
664
|
+
['where', 'UserWhereUniqueInput!', { id: U_USER }],
|
|
665
|
+
['create', 'UserCreateInput!', { name: 'harness user', alpacaAccounts: { create: [{ APIKey: cred(KEY), APISecret: cred(SECRET) }] } }],
|
|
666
|
+
['update', 'UserUpdateInput!', { alpacaAccounts: { create: [{ APIKey: cred(KEY), APISecret: cred(SECRET) }] } }],
|
|
667
|
+
],
|
|
668
|
+
selection: '{ id }',
|
|
669
|
+
},
|
|
670
|
+
};
|
|
671
|
+
/**
|
|
672
|
+
* Credential-free writes of credential models, sent as the generated client
|
|
673
|
+
* sends them (each variable named after its argument). Main's recorder stored
|
|
674
|
+
* the variables map; these rows must be byte-identical to that.
|
|
675
|
+
*/
|
|
676
|
+
export const CREDENTIAL_FREE_WRITES = {
|
|
677
|
+
updateOneAlpacaAccount: {
|
|
678
|
+
query: 'mutation updateOneAlpacaAccount($data: AlpacaAccountUpdateInput!, $where: AlpacaAccountWhereUniqueInput!) { updateOneAlpacaAccount(data: $data, where: $where) { id } }',
|
|
679
|
+
variables: { where: { id: ACCOUNT }, data: { tradeAllocationPct: { set: 7 }, autoAllocation: { set: false } } },
|
|
680
|
+
operationType: 'UPDATE',
|
|
681
|
+
},
|
|
682
|
+
updateManyAlpacaAccount: {
|
|
683
|
+
query: 'mutation updateManyAlpacaAccount($data: AlpacaAccountUpdateManyMutationInput!, $where: AlpacaAccountWhereInput) { updateManyAlpacaAccount(data: $data, where: $where) { count } }',
|
|
684
|
+
variables: { where: { userId: { equals: U_USER } }, data: { realTime: { set: true } } },
|
|
685
|
+
operationType: 'UPDATE',
|
|
686
|
+
},
|
|
687
|
+
createOneUser: {
|
|
688
|
+
query: 'mutation createOneUser($data: UserCreateInput!) { createOneUser(data: $data) { id } }',
|
|
689
|
+
variables: { data: { name: 'harness user', bio: 'no credential here' } },
|
|
690
|
+
operationType: 'CREATE',
|
|
691
|
+
},
|
|
692
|
+
upsertOneUser: {
|
|
693
|
+
query: 'mutation upsertOneUser($where: UserWhereUniqueInput!, $create: UserCreateInput!, $update: UserUpdateInput!) { upsertOneUser(where: $where, create: $create, update: $update) { id } }',
|
|
694
|
+
variables: { where: { id: U_USER }, create: { name: 'harness user' }, update: { name: { set: 'renamed' } } },
|
|
695
|
+
operationType: 'CREATE',
|
|
696
|
+
},
|
|
697
|
+
deleteOneAlpacaAccount: {
|
|
698
|
+
query: 'mutation deleteOneAlpacaAccount($where: AlpacaAccountWhereUniqueInput!) { deleteOneAlpacaAccount(where: $where) { id } }',
|
|
699
|
+
variables: { where: { id: ACCOUNT } },
|
|
700
|
+
operationType: 'DELETE',
|
|
701
|
+
},
|
|
702
|
+
};
|
|
703
|
+
// --- direct writes through the generated AuditLog mutations ------------------
|
|
704
|
+
/** An audit row whose JSON columns carry credentials under their own names. */
|
|
705
|
+
const AUDIT_ROW = {
|
|
706
|
+
operationType: new EnumValue('UPDATE'),
|
|
707
|
+
modelName: 'AlpacaAccount',
|
|
708
|
+
recordId: ACCOUNT,
|
|
709
|
+
changedFields: { where: { id: ACCOUNT }, data: { APIKey: cred({ set: KEY }), APISecret: cred({ set: SECRET }), label: { set: 'rotated' } } },
|
|
710
|
+
metadata: { source: 'harness', refresh_token: cred(TOKEN), note: 'kept' },
|
|
711
|
+
};
|
|
712
|
+
/** An audit row whose JSON columns carry credentials deep inside, each sent as a JSON variable. */
|
|
713
|
+
const NESTED_AUDIT_ROW = {
|
|
714
|
+
operationType: new EnumValue('CREATE'),
|
|
715
|
+
modelName: 'User',
|
|
716
|
+
recordId: U_USER,
|
|
717
|
+
changedFields: new JsonVariable('cf', {
|
|
718
|
+
input: {
|
|
719
|
+
name: 'n',
|
|
720
|
+
accounts: { create: [{ provider: 'google', refresh_token: cred(TOKEN), access_token: cred(SECRET) }] },
|
|
721
|
+
alpacaAccounts: { create: [{ APIKey: cred(KEY), APISecret: cred(SECRET), configuration: { auth: { apiSecret: cred(SECRET) } } }] },
|
|
722
|
+
},
|
|
723
|
+
}),
|
|
724
|
+
metadata: new JsonVariable('md', { context: { session: { sessionToken: cred(TOKEN) }, linked: [{ provider: 'github', accessToken: cred(SECRET) }] }, note: 'kept' }),
|
|
725
|
+
};
|
|
726
|
+
/** A row with no credential, written beside a credential row. */
|
|
727
|
+
const PLAIN_AUDIT_ROW = {
|
|
728
|
+
operationType: new EnumValue('CREATE'),
|
|
729
|
+
modelName: 'Order',
|
|
730
|
+
recordId: 'order-2',
|
|
731
|
+
changedFields: { status: 'cancel_requested' },
|
|
732
|
+
metadata: { source: 'harness' },
|
|
733
|
+
};
|
|
734
|
+
const AUDIT_ROW_ID_WHERE = { id: AUDIT_ROW_ID };
|
|
735
|
+
/** The credential row for a shape: the nested-JSON shape writes the nested row. */
|
|
736
|
+
function auditRow(shape) {
|
|
737
|
+
return shape === 'nested-json' ? NESTED_AUDIT_ROW : AUDIT_ROW;
|
|
738
|
+
}
|
|
739
|
+
/** The JSON columns of a row: what an update writes. */
|
|
740
|
+
function jsonColumns(row) {
|
|
741
|
+
return { changedFields: row.changedFields, metadata: row.metadata };
|
|
742
|
+
}
|
|
743
|
+
/** Each generated AuditLog write, per shape. */
|
|
744
|
+
const DIRECT_WRITES = {
|
|
745
|
+
createOneAuditLog: (shape) => ({
|
|
746
|
+
field: 'createOneAuditLog',
|
|
747
|
+
args: [['data', 'AuditLogCreateInput!', auditRow(shape)]],
|
|
748
|
+
selection: '{ id }',
|
|
749
|
+
}),
|
|
750
|
+
createManyAuditLog: (shape) => ({
|
|
751
|
+
field: 'createManyAuditLog',
|
|
752
|
+
args: [['data', '[AuditLogCreateManyInput!]!', [auditRow(shape), PLAIN_AUDIT_ROW]]],
|
|
753
|
+
selection: '{ count }',
|
|
754
|
+
}),
|
|
755
|
+
createManyAndReturnAuditLog: (shape) => ({
|
|
756
|
+
field: 'createManyAndReturnAuditLog',
|
|
757
|
+
args: [['data', '[AuditLogCreateManyInput!]!', [auditRow(shape), PLAIN_AUDIT_ROW]]],
|
|
758
|
+
selection: '{ id }',
|
|
759
|
+
}),
|
|
760
|
+
updateOneAuditLog: (shape) => ({
|
|
761
|
+
field: 'updateOneAuditLog',
|
|
762
|
+
args: [
|
|
763
|
+
['where', 'AuditLogWhereUniqueInput!', AUDIT_ROW_ID_WHERE],
|
|
764
|
+
['data', 'AuditLogUpdateInput!', jsonColumns(auditRow(shape))],
|
|
765
|
+
],
|
|
766
|
+
selection: '{ id }',
|
|
767
|
+
}),
|
|
768
|
+
updateManyAuditLog: (shape) => ({
|
|
769
|
+
field: 'updateManyAuditLog',
|
|
770
|
+
args: [
|
|
771
|
+
['where', 'AuditLogWhereInput', { modelName: { equals: 'AlpacaAccount' } }],
|
|
772
|
+
['data', 'AuditLogUpdateManyMutationInput!', jsonColumns(auditRow(shape))],
|
|
773
|
+
],
|
|
774
|
+
selection: '{ count }',
|
|
775
|
+
}),
|
|
776
|
+
upsertOneAuditLog: (shape) => ({
|
|
777
|
+
field: 'upsertOneAuditLog',
|
|
778
|
+
args: [
|
|
779
|
+
['where', 'AuditLogWhereUniqueInput!', AUDIT_ROW_ID_WHERE],
|
|
780
|
+
['create', 'AuditLogCreateInput!', auditRow(shape)],
|
|
781
|
+
['update', 'AuditLogUpdateInput!', jsonColumns(auditRow(shape))],
|
|
782
|
+
],
|
|
783
|
+
selection: '{ id }',
|
|
784
|
+
}),
|
|
785
|
+
};
|
|
786
|
+
async function main() {
|
|
787
|
+
process.env.DATABASE_URL = UNREACHABLE_DATABASE_URL;
|
|
788
|
+
process.env.DIRECT_DATABASE_URL = UNREACHABLE_DATABASE_URL;
|
|
789
|
+
const prismaModule = (await import('../../prismaClient'));
|
|
790
|
+
const initialSingleton = global.prisma;
|
|
791
|
+
if (!initialSingleton)
|
|
792
|
+
throw new Error('prismaClient.ts did not install global.prisma');
|
|
793
|
+
const guarded = initialSingleton;
|
|
794
|
+
const unguarded = new PrismaClient({ datasourceUrl: UNREACHABLE_DATABASE_URL });
|
|
795
|
+
let mode = 'shadow';
|
|
796
|
+
const schema = await buildSchema({
|
|
797
|
+
resolvers: [AuditLogCrudResolver, AlpacaAccountCrudResolver, UserCrudResolver],
|
|
798
|
+
validate: false,
|
|
799
|
+
});
|
|
800
|
+
installMutationAuthGuard(schema, { modeProvider: () => mode, enforcedModelsProvider: () => new Set() });
|
|
801
|
+
const server = new ApolloServer({ schema, plugins: [createAuditLogPlugin(), createHttpStatusMapperPlugin()] });
|
|
802
|
+
await server.start();
|
|
803
|
+
const graphql = (query, variables, principal) => async (client) => {
|
|
804
|
+
const response = await server.executeOperation({ query, variables }, {
|
|
805
|
+
contextValue: {
|
|
806
|
+
prisma: client,
|
|
807
|
+
principal,
|
|
808
|
+
user: principal ? { sub: principal.kind === 'server' ? 'server' : principal.sub } : null,
|
|
809
|
+
req: { ip: '203.0.113.7', headers: { 'user-agent': 'audit-write-harness' } },
|
|
810
|
+
},
|
|
811
|
+
});
|
|
812
|
+
const body = response.body.kind === 'single' ? response.body.singleResult : null;
|
|
813
|
+
const errors = body?.errors ?? [];
|
|
814
|
+
return {
|
|
815
|
+
status: response.http.status ?? 200,
|
|
816
|
+
codes: errors.map((e) => String(e.extensions?.code)),
|
|
817
|
+
errors: errors.map((e) => e.message),
|
|
818
|
+
};
|
|
819
|
+
};
|
|
820
|
+
const results = {};
|
|
821
|
+
for (const [field, { query, variables }] of Object.entries(WRITE_MUTATIONS)) {
|
|
822
|
+
for (const { principal, mode: scenarioMode } of AUTH_MATRIX) {
|
|
823
|
+
mode = scenarioMode;
|
|
824
|
+
results[`gql/${field}/${principal}/${scenarioMode}`] = await runBoth(guarded, unguarded, graphql(query, variables, PRINCIPALS[principal]));
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
mode = 'enforce';
|
|
828
|
+
for (const [name, data] of Object.entries(CONSUMER_PAYLOADS)) {
|
|
829
|
+
results[`consumer/${name}`] = await runBoth(guarded, unguarded, graphql(CREATE_ONE, { data }, PRINCIPALS.server));
|
|
830
|
+
}
|
|
831
|
+
results['server/audit-plugin'] = await runBoth(guarded, unguarded, graphql(UPDATE_ACCOUNT_KEYS, { where: { id: 'acct-1' }, data: { APIKey: { set: API_KEY }, APISecret: { set: API_SECRET } } }, PRINCIPALS.server));
|
|
832
|
+
results['server/trading-policy-attempt'] = await runBoth(guarded, unguarded, direct((client) => writeAttemptRow(client, POLICY_ENTRY, 'pending')));
|
|
833
|
+
results['direct/create'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.create({ data: CREDENTIAL_ROW })));
|
|
834
|
+
results['direct/createMany-single-row'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.createMany({ data: CREDENTIAL_ROW })));
|
|
835
|
+
results['direct/updateManyAndReturn'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.updateManyAndReturn({
|
|
836
|
+
where: { modelName: 'AlpacaAccount' },
|
|
837
|
+
data: { changedFields: CREDENTIAL_CHANGED_FIELDS },
|
|
838
|
+
})));
|
|
839
|
+
results['direct/sentinels'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.create({
|
|
840
|
+
data: { operationType: 'CREATE', modelName: 'Order', recordId: 'order-4', changedFields: Prisma.JsonNull, metadata: Prisma.DbNull },
|
|
841
|
+
})));
|
|
842
|
+
results['direct/non-json-values'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.create({
|
|
843
|
+
data: {
|
|
844
|
+
operationType: 'CREATE',
|
|
845
|
+
modelName: 'Order',
|
|
846
|
+
recordId: 'order-5',
|
|
847
|
+
timestamp: new Date(ISO_NOW),
|
|
848
|
+
changedFields: { at: new Date(ISO_NOW), nested: [{ n: 1 }, null] },
|
|
849
|
+
},
|
|
850
|
+
})));
|
|
851
|
+
results['direct/read-filter'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.findFirst({ where: { metadata: { equals: { refresh_token: OAUTH_TOKEN } } } })));
|
|
852
|
+
results['direct/deleteMany'] = await runBoth(guarded, unguarded, direct((client) => client.auditLog.deleteMany({ where: { recordId: 'acct-1' } })));
|
|
853
|
+
// The acceptance matrix, as the engine's service principal sends it under enforce.
|
|
854
|
+
mode = 'enforce';
|
|
855
|
+
const matrix = [];
|
|
856
|
+
const runCase = async (path, shape, spec, sentAs) => {
|
|
857
|
+
const { model, operation, auditType } = fieldOperation(spec.field);
|
|
858
|
+
const { query, variables } = operationFor(spec, sentAs);
|
|
859
|
+
matrix.push({
|
|
860
|
+
path,
|
|
861
|
+
field: spec.field,
|
|
862
|
+
shape,
|
|
863
|
+
model,
|
|
864
|
+
operation,
|
|
865
|
+
auditType: path === 'plugin' ? auditType : undefined,
|
|
866
|
+
expected: path === 'plugin' ? expectedPluginChangedFields(spec) : expectedDirectRows(spec),
|
|
867
|
+
query,
|
|
868
|
+
result: await runBoth(guarded, unguarded, graphql(query, variables, PRINCIPALS.server)),
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
for (const build of Object.values(PLUGIN_WRITES)) {
|
|
872
|
+
for (const shape of CREDENTIAL_SHAPES)
|
|
873
|
+
await runCase('plugin', shape, build(shape), shape);
|
|
874
|
+
}
|
|
875
|
+
// A relation write's nested credentials, sent as the variables the old recorder stored raw.
|
|
876
|
+
for (const spec of Object.values(NESTED_RELATION_WRITES)) {
|
|
877
|
+
await runCase('plugin', 'nested-relation', spec, 'variable-named');
|
|
878
|
+
}
|
|
879
|
+
for (const build of Object.values(DIRECT_WRITES)) {
|
|
880
|
+
for (const shape of CREDENTIAL_SHAPES)
|
|
881
|
+
await runCase('direct', shape, build(shape), shape);
|
|
882
|
+
}
|
|
883
|
+
const credentialFree = {};
|
|
884
|
+
for (const [field, { query, variables, operationType }] of Object.entries(CREDENTIAL_FREE_WRITES)) {
|
|
885
|
+
credentialFree[field] = {
|
|
886
|
+
variables,
|
|
887
|
+
operationType,
|
|
888
|
+
result: await runBoth(guarded, unguarded, graphql(query, variables, PRINCIPALS.server)),
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
const reconnectPrisma = prismaModule.reconnectPrisma;
|
|
892
|
+
const reconnect = {
|
|
893
|
+
available: typeof reconnectPrisma === 'function',
|
|
894
|
+
replaced: false,
|
|
895
|
+
result: null,
|
|
896
|
+
};
|
|
897
|
+
if (typeof reconnectPrisma === 'function') {
|
|
898
|
+
await reconnectPrisma();
|
|
899
|
+
const reconnected = global.prisma;
|
|
900
|
+
reconnect.replaced = reconnected !== undefined && reconnected !== initialSingleton;
|
|
901
|
+
if (reconnected) {
|
|
902
|
+
reconnect.result = await runBoth(reconnected, unguarded, direct((client) => client.auditLog.create({ data: CREDENTIAL_ROW })));
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
await server.stop();
|
|
906
|
+
await unguarded.$disconnect();
|
|
907
|
+
await global.prisma?.$disconnect();
|
|
908
|
+
process.stdout.write(`<<<RESULTS>>>${JSON.stringify({
|
|
909
|
+
singletonIsDefaultExport: prismaModule.default === initialSingleton,
|
|
910
|
+
reconnect,
|
|
911
|
+
results,
|
|
912
|
+
matrix,
|
|
913
|
+
credentialFree,
|
|
914
|
+
})}<<<END>>>\n`);
|
|
915
|
+
}
|
|
916
|
+
main().catch((error) => {
|
|
917
|
+
process.stderr.write(`harness failed: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`);
|
|
918
|
+
process.exit(1);
|
|
919
|
+
});
|
|
920
|
+
//# sourceMappingURL=audit-log-write-redaction.harness.js.map
|