@adaptic/backend-legacy 0.0.1048 → 0.0.1050

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 (38) hide show
  1. package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +5 -0
  2. package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts.map +1 -1
  3. package/esm/middleware/__tests__/mutation-auth-guard.harness.js.map +1 -1
  4. package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +38 -8
  5. package/esm/middleware/credential-field-guard.d.ts +7 -1
  6. package/esm/middleware/credential-field-guard.d.ts.map +1 -1
  7. package/esm/middleware/credential-field-guard.js.map +1 -1
  8. package/esm/middleware/credential-field-guard.mjs +7 -2
  9. package/esm/middleware/mutation-auth-guard.d.ts +16 -0
  10. package/esm/middleware/mutation-auth-guard.d.ts.map +1 -1
  11. package/esm/middleware/mutation-auth-guard.js.map +1 -1
  12. package/esm/middleware/mutation-auth-guard.mjs +68 -0
  13. package/esm/resolvers/custom/AccountEquityCurveResolver.d.ts +32 -0
  14. package/esm/resolvers/custom/AccountEquityCurveResolver.d.ts.map +1 -0
  15. package/esm/resolvers/custom/AccountEquityCurveResolver.js.map +1 -0
  16. package/esm/resolvers/custom/AccountEquityCurveResolver.mjs +206 -0
  17. package/esm/resolvers/custom/account-audit-read.d.ts +182 -0
  18. package/esm/resolvers/custom/account-audit-read.d.ts.map +1 -0
  19. package/esm/resolvers/custom/account-audit-read.js.map +1 -0
  20. package/esm/resolvers/custom/account-audit-read.mjs +315 -0
  21. package/esm/resolvers/custom/index.d.ts +1 -0
  22. package/esm/resolvers/custom/index.d.ts.map +1 -1
  23. package/esm/resolvers/custom/index.js.map +1 -1
  24. package/esm/resolvers/custom/index.mjs +1 -0
  25. package/package.json +1 -1
  26. package/resolvers/custom/AccountEquityCurveResolver.cjs +233 -0
  27. package/resolvers/custom/AccountEquityCurveResolver.d.ts +32 -0
  28. package/resolvers/custom/AccountEquityCurveResolver.d.ts.map +1 -0
  29. package/resolvers/custom/AccountEquityCurveResolver.js.map +1 -0
  30. package/resolvers/custom/account-audit-read.cjs +333 -0
  31. package/resolvers/custom/account-audit-read.d.ts +182 -0
  32. package/resolvers/custom/account-audit-read.d.ts.map +1 -0
  33. package/resolvers/custom/account-audit-read.js.map +1 -0
  34. package/resolvers/custom/index.cjs +5 -1
  35. package/resolvers/custom/index.d.ts +1 -0
  36. package/resolvers/custom/index.d.ts.map +1 -1
  37. package/resolvers/custom/index.js.map +1 -1
  38. package/server.cjs +1 -0
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AuditReadRefused = exports.ALPACA_TIMEOUT_MS = exports.ACCOUNT_BUDGET_WINDOW_MS = exports.ACCOUNT_REQUEST_BUDGET = exports.MAX_AUDIT_TOKEN_CLOCK_SKEW_SEC = exports.MAX_AUDIT_TOKEN_LIFETIME_SEC = exports.MINIMUM_AUDIT_SECRET_LENGTH = exports.AUDIT_READ_AUDIENCE = exports.AUDIT_READ_ISSUER = exports.AUDIT_READ_TOKEN_HEADER = exports.AUDIT_READ_JWT_SECRET_ENV = exports.AUDIT_READ_OPERATORS_ENV = exports.AUDIT_SUBJECT_PREFIX = void 0;
7
+ exports.createAccountBudgets = createAccountBudgets;
8
+ exports.auditTokenFromHeaders = auditTokenFromHeaders;
9
+ exports.assertAuditRead = assertAuditRead;
10
+ exports.assertAccountIdShape = assertAccountIdShape;
11
+ exports.assertAccountReadable = assertAccountReadable;
12
+ exports.snapshotEquity = snapshotEquity;
13
+ exports.etDateOf = etDateOf;
14
+ exports.parseSessionDate = parseSessionDate;
15
+ exports.readEquityCurve = readEquityCurve;
16
+ /**
17
+ * Server-side audit read of an account's equity curve.
18
+ *
19
+ * The audit toolkit used to read an account's broker key and secret and call
20
+ * Alpaca itself, which meant issuing an audit principal handed out live broker
21
+ * credentials. This read moves the Alpaca call here: the caller names an
22
+ * account and receives the curve, and the key never leaves this process.
23
+ *
24
+ * Everything in this module is pure or takes its collaborators as arguments
25
+ * (`fetchImpl`, `nowMs`), so it is unit-testable without a database or network.
26
+ *
27
+ * @module resolvers/custom/account-audit-read
28
+ */
29
+ const graphql_1 = require("graphql");
30
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
31
+ const logger_1 = require("../../utils/logger.cjs");
32
+ /** `sub` prefix the audit toolkit mints (`adaptic-audit:<who>@<host>:<pid>`). */
33
+ exports.AUDIT_SUBJECT_PREFIX = 'adaptic-audit:';
34
+ /** Env var holding the comma-separated operators admitted to the audit-read role. */
35
+ exports.AUDIT_READ_OPERATORS_ENV = 'AUDIT_READ_OPERATORS';
36
+ /** Env var holding the HS256 secret that signs audit-read tokens, and nothing else. */
37
+ exports.AUDIT_READ_JWT_SECRET_ENV = 'AUDIT_READ_JWT_SECRET';
38
+ /**
39
+ * Request header the audit token travels in.
40
+ *
41
+ * Not `Authorization`: the shared verifier would refuse a token it cannot
42
+ * verify with HTTP 401 before any resolver ran, and teaching it this secret
43
+ * would make audit-read one more way to become a `server` principal. A
44
+ * separate header keeps the two trust roots apart.
45
+ */
46
+ exports.AUDIT_READ_TOKEN_HEADER = 'x-adaptic-audit-token';
47
+ /** Issuer every audit-read token must carry. */
48
+ exports.AUDIT_READ_ISSUER = 'adaptic-audit';
49
+ /** Audience every audit-read token must carry. */
50
+ exports.AUDIT_READ_AUDIENCE = 'adaptic-backend:audit-read';
51
+ /** Minimum length for the audit-read secret, in characters. */
52
+ exports.MINIMUM_AUDIT_SECRET_LENGTH = 32;
53
+ /** Largest lifetime (`exp - iat`) honoured on an audit-read token, and the longest it is accepted ahead of its `exp`, seconds. */
54
+ exports.MAX_AUDIT_TOKEN_LIFETIME_SEC = 300;
55
+ /** How far in the future an `iat` may sit before the token is refused, seconds. */
56
+ exports.MAX_AUDIT_TOKEN_CLOCK_SKEW_SEC = 60;
57
+ /** Upstream Alpaca requests allowed per account per window, shared by every operator reading it. */
58
+ exports.ACCOUNT_REQUEST_BUDGET = 40;
59
+ /** Length of the per-account budget window, ms. */
60
+ exports.ACCOUNT_BUDGET_WINDOW_MS = 60000;
61
+ /** Longest one Alpaca request may take before it is abandoned, ms. */
62
+ exports.ALPACA_TIMEOUT_MS = 10000;
63
+ const PAPER_TRADE_HOST = 'https://paper-api.alpaca.markets';
64
+ /**
65
+ * A sliding-window request budget per account.
66
+ *
67
+ * Audit reads spend the book's own trading key, so the window is keyed on the
68
+ * account (the key being protected), not the operator: several operators on one
69
+ * book share one budget, and the engine's order traffic cannot be starved. State is
70
+ * in-process: with several backend instances the effective ceiling is the
71
+ * budget times the instance count, still bounded.
72
+ *
73
+ * @param limit - Requests allowed per window.
74
+ * @param windowMs - Window length.
75
+ * @param now - Clock, injectable for tests.
76
+ * @returns A function that returns the account's `RequestBudget`.
77
+ */
78
+ function createAccountBudgets(limit = exports.ACCOUNT_REQUEST_BUDGET, windowMs = exports.ACCOUNT_BUDGET_WINDOW_MS, now = Date.now) {
79
+ const spent = new Map();
80
+ return (accountId) => (n = 1) => {
81
+ var _a;
82
+ const t = now();
83
+ const live = ((_a = spent.get(accountId)) !== null && _a !== void 0 ? _a : []).filter((at) => at > t - windowMs);
84
+ if (live.length + n > limit) {
85
+ spent.set(accountId, live);
86
+ throw new graphql_1.GraphQLError('Audit read rate budget exhausted; retry shortly', {
87
+ extensions: { code: 'RATE_LIMITED', retryAfterMs: windowMs },
88
+ });
89
+ }
90
+ for (let i = 0; i < n; i++)
91
+ live.push(t);
92
+ spent.set(accountId, live);
93
+ };
94
+ }
95
+ /**
96
+ * The audit-read token from a request's headers, or null when absent.
97
+ *
98
+ * A repeated header arrives as an array and is refused rather than guessed at.
99
+ */
100
+ function auditTokenFromHeaders(headers) {
101
+ const raw = headers === null || headers === void 0 ? void 0 : headers[exports.AUDIT_READ_TOKEN_HEADER];
102
+ if (typeof raw !== 'string')
103
+ return null;
104
+ const token = raw.trim();
105
+ return token.length > 0 ? token : null;
106
+ }
107
+ /**
108
+ * The audit-read role, enforced in the resolver.
109
+ *
110
+ * Fail-closed, and independent of the request's principal. A `server`
111
+ * principal otherwise bypasses every role gate and `@Authorized()` is
112
+ * shadow-first, so neither can carry this; and any holder of the shared
113
+ * service secret can mint a `server` principal with whatever `sub` it likes.
114
+ * So the caller must present a token signed with `AUDIT_READ_JWT_SECRET`, a
115
+ * secret with no other use, bound to this issuer and audience, short-lived,
116
+ * whose `sub` is `adaptic-audit:<who>@…` with `<who>` in
117
+ * `AUDIT_READ_OPERATORS`. A token signed with any other secret is refused
118
+ * whatever its `sub` says. An unset secret or an empty list admits nobody.
119
+ *
120
+ * @param token - The raw audit-read token, or null/undefined when absent.
121
+ * @param env - Environment to read the secret and operator list from.
122
+ * @param nowSec - Current time, seconds since the epoch.
123
+ * @returns The operator the read is attributed to.
124
+ * @throws {GraphQLError} `UNAUTHENTICATED` without a token, `FORBIDDEN` otherwise.
125
+ */
126
+ function assertAuditRead(token, env = process.env, nowSec = Math.floor(Date.now() / 1000)) {
127
+ var _a, _b;
128
+ if (!token) {
129
+ throw new graphql_1.GraphQLError('Authentication required', { extensions: { code: 'UNAUTHENTICATED' } });
130
+ }
131
+ const forbidden = () => {
132
+ throw new graphql_1.GraphQLError('audit-read role required', { extensions: { code: 'FORBIDDEN' } });
133
+ };
134
+ const secret = ((_a = env[exports.AUDIT_READ_JWT_SECRET_ENV]) !== null && _a !== void 0 ? _a : '').trim();
135
+ if (secret.length < exports.MINIMUM_AUDIT_SECRET_LENGTH) {
136
+ if (secret.length > 0) {
137
+ logger_1.logger.error(`[audit-read] ${exports.AUDIT_READ_JWT_SECRET_ENV} is shorter than ${exports.MINIMUM_AUDIT_SECRET_LENGTH} characters; audit reads are disabled.`);
138
+ }
139
+ return forbidden();
140
+ }
141
+ // Equal to any other trust root collapses the separation this secret exists for.
142
+ const others = [
143
+ env.BACKEND_SERVICE_JWT_SECRET,
144
+ env.BACKEND_SERVICE_JWT_SECRET_PREVIOUS,
145
+ env.JWT_SECRET,
146
+ env.NEXTAUTH_SECRET,
147
+ ].map((v) => (v !== null && v !== void 0 ? v : '').trim());
148
+ if (others.includes(secret)) {
149
+ logger_1.logger.error(`[audit-read] ${exports.AUDIT_READ_JWT_SECRET_ENV} equals another auth secret; audit reads are disabled until it is distinct.`);
150
+ return forbidden();
151
+ }
152
+ let payload;
153
+ try {
154
+ const verified = jsonwebtoken_1.default.verify(token, secret, {
155
+ algorithms: ['HS256'],
156
+ issuer: exports.AUDIT_READ_ISSUER,
157
+ audience: exports.AUDIT_READ_AUDIENCE,
158
+ clockTimestamp: nowSec,
159
+ });
160
+ if (typeof verified === 'string')
161
+ return forbidden();
162
+ payload = verified;
163
+ }
164
+ catch (_c) {
165
+ return forbidden();
166
+ }
167
+ const { iat, exp } = payload;
168
+ if (typeof iat !== 'number' || typeof exp !== 'number')
169
+ return forbidden();
170
+ // The ceiling holds on the token's own lifetime and on the time it is honoured:
171
+ // an `iat` skewed ahead would otherwise stretch acceptance past it.
172
+ if (exp - iat > exports.MAX_AUDIT_TOKEN_LIFETIME_SEC || exp - nowSec > exports.MAX_AUDIT_TOKEN_LIFETIME_SEC)
173
+ return forbidden();
174
+ if (iat > nowSec + exports.MAX_AUDIT_TOKEN_CLOCK_SKEW_SEC)
175
+ return forbidden();
176
+ const sub = typeof payload.sub === 'string' ? payload.sub : '';
177
+ if (!sub.startsWith(exports.AUDIT_SUBJECT_PREFIX))
178
+ return forbidden();
179
+ const who = sub.slice(exports.AUDIT_SUBJECT_PREFIX.length).split('@')[0].trim();
180
+ const allowed = ((_b = env[exports.AUDIT_READ_OPERATORS_ENV]) !== null && _b !== void 0 ? _b : '')
181
+ .split(',')
182
+ .map((s) => s.trim())
183
+ .filter((s) => s.length > 0);
184
+ if (who.length === 0 || !allowed.includes(who))
185
+ return forbidden();
186
+ return who;
187
+ }
188
+ /**
189
+ * A read refused after the audit token verified, so the operator is known.
190
+ *
191
+ * Token failures from `assertAuditRead` are plain `GraphQLError`s and leave no
192
+ * record: the caller is unattributed. This class marks the refusals that do get
193
+ * an AuditLog row, and carries the reason that goes on it.
194
+ */
195
+ class AuditReadRefused extends graphql_1.GraphQLError {
196
+ constructor(reason, message, code) {
197
+ super(message, { extensions: { code, reason } });
198
+ this.name = 'AuditReadRefused';
199
+ this.reason = reason;
200
+ }
201
+ }
202
+ exports.AuditReadRefused = AuditReadRefused;
203
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
204
+ /**
205
+ * Refuse an account id that cannot name a stored account.
206
+ *
207
+ * `AlpacaAccount.id` is a Postgres uuid, and Prisma throws on a non-uuid
208
+ * lookup, so a malformed id would otherwise surface as an internal error with
209
+ * no refusal recorded.
210
+ *
211
+ * @throws {AuditReadRefused} `ACCOUNT_NOT_FOUND` for anything but a uuid.
212
+ */
213
+ function assertAccountIdShape(accountId) {
214
+ if (!UUID_RE.test(accountId)) {
215
+ throw new AuditReadRefused('ACCOUNT_NOT_FOUND', 'Account not found', 'NOT_FOUND');
216
+ }
217
+ }
218
+ /** Audit reads are PAPER-only; a LIVE account is refused. */
219
+ function assertAccountReadable(account) {
220
+ if (account.type !== 'PAPER') {
221
+ throw new AuditReadRefused('ACCOUNT_NOT_PAPER', `Account ${account.id} is ${account.type}; audit reads are PAPER-only`, 'FORBIDDEN');
222
+ }
223
+ }
224
+ /**
225
+ * The snapshot's `equity` and `last_equity` as finite numbers.
226
+ *
227
+ * Alpaca sends both as decimal strings. A missing, empty or non-numeric value
228
+ * refuses the read rather than serving `NaN` (or `0`, which `Number('')` and
229
+ * `Number(null)` would give): either reads as a real figure to whoever audits it.
230
+ *
231
+ * @throws {AuditReadRefused} `SNAPSHOT_INCOMPLETE` naming the unusable fields.
232
+ */
233
+ function snapshotEquity(snap) {
234
+ const s = (snap !== null && snap !== void 0 ? snap : {});
235
+ const num = (v) => typeof v === 'number' || (typeof v === 'string' && v.trim() !== '') ? Number(v) : NaN;
236
+ const equity = num(s.equity);
237
+ const lastEquity = num(s.last_equity);
238
+ const bad = [
239
+ ...(Number.isFinite(equity) ? [] : ['equity']),
240
+ ...(Number.isFinite(lastEquity) ? [] : ['last_equity']),
241
+ ];
242
+ if (bad.length > 0) {
243
+ // Field names only: the vendor values are not echoed.
244
+ throw new AuditReadRefused('SNAPSHOT_INCOMPLETE', `Broker account snapshot has no finite ${bad.join(' or ')}`, 'BAD_GATEWAY');
245
+ }
246
+ return { equity, lastEquity };
247
+ }
248
+ /** The ET calendar date of an instant, YYYY-MM-DD. */
249
+ function etDateOf(ms) {
250
+ return new Intl.DateTimeFormat('en-CA', { timeZone: 'America/New_York' }).format(new Date(ms));
251
+ }
252
+ /**
253
+ * Validate a `YYYY-MM-DD` session date.
254
+ *
255
+ * @throws {GraphQLError} `BAD_USER_INPUT` for anything else, so nothing the
256
+ * caller sends is ever spliced into a URL unchecked.
257
+ */
258
+ function parseSessionDate(raw) {
259
+ if (raw == null || raw === '')
260
+ return null;
261
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(raw) || Number.isNaN(Date.parse(`${raw}T00:00:00Z`))) {
262
+ throw new graphql_1.GraphQLError('sessionDate must be YYYY-MM-DD', { extensions: { code: 'BAD_USER_INPUT' } });
263
+ }
264
+ return raw;
265
+ }
266
+ async function alpacaGet(account, fetchImpl, url, budget) {
267
+ budget();
268
+ const badGateway = (message, upstreamStatus) => {
269
+ // Status only: the vendor body can echo request detail.
270
+ throw new graphql_1.GraphQLError(message, { extensions: { code: 'BAD_GATEWAY', upstreamStatus } });
271
+ };
272
+ let res;
273
+ let text;
274
+ try {
275
+ res = await fetchImpl(url, {
276
+ headers: { 'APCA-API-KEY-ID': account.APIKey, 'APCA-API-SECRET-KEY': account.APISecret },
277
+ signal: AbortSignal.timeout(exports.ALPACA_TIMEOUT_MS),
278
+ });
279
+ text = await res.text();
280
+ }
281
+ catch (_a) {
282
+ return badGateway('Broker read failed (no response)');
283
+ }
284
+ if (!res.ok)
285
+ return badGateway(`Broker read failed (HTTP ${res.status})`, res.status);
286
+ if (!text)
287
+ return null;
288
+ try {
289
+ return JSON.parse(text);
290
+ }
291
+ catch (_b) {
292
+ return badGateway(`Broker read failed (unreadable response, HTTP ${res.status})`, res.status);
293
+ }
294
+ }
295
+ /**
296
+ * Read one session's 1-minute equity curve and the account snapshot.
297
+ *
298
+ * @param p.account - The stored account row (carries the key; not returned).
299
+ * @param p.sessionDate - Pin a past session, or null for today's ET date.
300
+ * @param p.fetchImpl - Injected HTTP client.
301
+ * @throws {AuditReadRefused} for a LIVE account or an incomplete snapshot.
302
+ */
303
+ async function readEquityCurve(p) {
304
+ var _a, _b, _c;
305
+ const { account, fetchImpl, budget } = p;
306
+ assertAccountReadable(account);
307
+ const base = PAPER_TRADE_HOST;
308
+ const sessionDate = (_a = p.sessionDate) !== null && _a !== void 0 ? _a : etDateOf(p.nowMs);
309
+ // Checked before the history call, so a refused read spends one request, not two.
310
+ const snap = snapshotEquity(await alpacaGet(account, fetchImpl, `${base}/v2/account`, budget));
311
+ const hist = (await alpacaGet(account, fetchImpl, `${base}/v2/account/portfolio/history?period=1D&timeframe=1Min&intraday_reporting=market_hours&pnl_reset=per_day` +
312
+ (p.sessionDate ? `&date_end=${p.sessionDate}` : ''), budget));
313
+ const ts = (_b = hist === null || hist === void 0 ? void 0 : hist.timestamp) !== null && _b !== void 0 ? _b : [];
314
+ const eq = (_c = hist === null || hist === void 0 ? void 0 : hist.equity) !== null && _c !== void 0 ? _c : [];
315
+ const points = [];
316
+ for (let i = 0; i < ts.length; i++) {
317
+ const equity = eq[i];
318
+ if (typeof equity === 'number' && Number.isFinite(equity))
319
+ points.push({ ms: ts[i] * 1000, equity });
320
+ }
321
+ const cfg = account.configuration;
322
+ return {
323
+ accountId: account.id,
324
+ accountType: account.type,
325
+ accountName: typeof (cfg === null || cfg === void 0 ? void 0 : cfg.name) === 'string' && cfg.name ? cfg.name : account.id,
326
+ sessionDate,
327
+ points,
328
+ lastEquity: snap.lastEquity,
329
+ equity: snap.equity,
330
+ source: 'alpaca-portfolio-history',
331
+ };
332
+ }
333
+ //# sourceMappingURL=account-audit-read.js.map
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Server-side audit read of an account's equity curve.
3
+ *
4
+ * The audit toolkit used to read an account's broker key and secret and call
5
+ * Alpaca itself, which meant issuing an audit principal handed out live broker
6
+ * credentials. This read moves the Alpaca call here: the caller names an
7
+ * account and receives the curve, and the key never leaves this process.
8
+ *
9
+ * Everything in this module is pure or takes its collaborators as arguments
10
+ * (`fetchImpl`, `nowMs`), so it is unit-testable without a database or network.
11
+ *
12
+ * @module resolvers/custom/account-audit-read
13
+ */
14
+ import { GraphQLError } from 'graphql';
15
+ /** `sub` prefix the audit toolkit mints (`adaptic-audit:<who>@<host>:<pid>`). */
16
+ export declare const AUDIT_SUBJECT_PREFIX = "adaptic-audit:";
17
+ /** Env var holding the comma-separated operators admitted to the audit-read role. */
18
+ export declare const AUDIT_READ_OPERATORS_ENV = "AUDIT_READ_OPERATORS";
19
+ /** Env var holding the HS256 secret that signs audit-read tokens, and nothing else. */
20
+ export declare const AUDIT_READ_JWT_SECRET_ENV = "AUDIT_READ_JWT_SECRET";
21
+ /**
22
+ * Request header the audit token travels in.
23
+ *
24
+ * Not `Authorization`: the shared verifier would refuse a token it cannot
25
+ * verify with HTTP 401 before any resolver ran, and teaching it this secret
26
+ * would make audit-read one more way to become a `server` principal. A
27
+ * separate header keeps the two trust roots apart.
28
+ */
29
+ export declare const AUDIT_READ_TOKEN_HEADER = "x-adaptic-audit-token";
30
+ /** Issuer every audit-read token must carry. */
31
+ export declare const AUDIT_READ_ISSUER = "adaptic-audit";
32
+ /** Audience every audit-read token must carry. */
33
+ export declare const AUDIT_READ_AUDIENCE = "adaptic-backend:audit-read";
34
+ /** Minimum length for the audit-read secret, in characters. */
35
+ export declare const MINIMUM_AUDIT_SECRET_LENGTH = 32;
36
+ /** Largest lifetime (`exp - iat`) honoured on an audit-read token, and the longest it is accepted ahead of its `exp`, seconds. */
37
+ export declare const MAX_AUDIT_TOKEN_LIFETIME_SEC = 300;
38
+ /** How far in the future an `iat` may sit before the token is refused, seconds. */
39
+ export declare const MAX_AUDIT_TOKEN_CLOCK_SKEW_SEC = 60;
40
+ /** Upstream Alpaca requests allowed per account per window, shared by every operator reading it. */
41
+ export declare const ACCOUNT_REQUEST_BUDGET = 40;
42
+ /** Length of the per-account budget window, ms. */
43
+ export declare const ACCOUNT_BUDGET_WINDOW_MS = 60000;
44
+ /** Longest one Alpaca request may take before it is abandoned, ms. */
45
+ export declare const ALPACA_TIMEOUT_MS = 10000;
46
+ /** The stored account fields a read needs. Never returned to the caller. */
47
+ export interface AuditAccountRow {
48
+ id: string;
49
+ type: 'PAPER' | 'LIVE';
50
+ APIKey: string;
51
+ APISecret: string;
52
+ configuration?: unknown;
53
+ }
54
+ /** A request to Alpaca with the stored key. */
55
+ export type AlpacaFetch = (url: string, init: {
56
+ headers: Record<string, string>;
57
+ signal?: AbortSignal;
58
+ }) => Promise<{
59
+ ok: boolean;
60
+ status: number;
61
+ text: () => Promise<string>;
62
+ }>;
63
+ /** Spends upstream requests against an account's budget; throws when it is exhausted. */
64
+ export type RequestBudget = (n?: number) => void;
65
+ /**
66
+ * A sliding-window request budget per account.
67
+ *
68
+ * Audit reads spend the book's own trading key, so the window is keyed on the
69
+ * account (the key being protected), not the operator: several operators on one
70
+ * book share one budget, and the engine's order traffic cannot be starved. State is
71
+ * in-process: with several backend instances the effective ceiling is the
72
+ * budget times the instance count, still bounded.
73
+ *
74
+ * @param limit - Requests allowed per window.
75
+ * @param windowMs - Window length.
76
+ * @param now - Clock, injectable for tests.
77
+ * @returns A function that returns the account's `RequestBudget`.
78
+ */
79
+ export declare function createAccountBudgets(limit?: number, windowMs?: number, now?: () => number): (accountId: string) => RequestBudget;
80
+ /**
81
+ * The audit-read token from a request's headers, or null when absent.
82
+ *
83
+ * A repeated header arrives as an array and is refused rather than guessed at.
84
+ */
85
+ export declare function auditTokenFromHeaders(headers: Record<string, string | string[] | undefined> | undefined): string | null;
86
+ /**
87
+ * The audit-read role, enforced in the resolver.
88
+ *
89
+ * Fail-closed, and independent of the request's principal. A `server`
90
+ * principal otherwise bypasses every role gate and `@Authorized()` is
91
+ * shadow-first, so neither can carry this; and any holder of the shared
92
+ * service secret can mint a `server` principal with whatever `sub` it likes.
93
+ * So the caller must present a token signed with `AUDIT_READ_JWT_SECRET`, a
94
+ * secret with no other use, bound to this issuer and audience, short-lived,
95
+ * whose `sub` is `adaptic-audit:<who>@…` with `<who>` in
96
+ * `AUDIT_READ_OPERATORS`. A token signed with any other secret is refused
97
+ * whatever its `sub` says. An unset secret or an empty list admits nobody.
98
+ *
99
+ * @param token - The raw audit-read token, or null/undefined when absent.
100
+ * @param env - Environment to read the secret and operator list from.
101
+ * @param nowSec - Current time, seconds since the epoch.
102
+ * @returns The operator the read is attributed to.
103
+ * @throws {GraphQLError} `UNAUTHENTICATED` without a token, `FORBIDDEN` otherwise.
104
+ */
105
+ export declare function assertAuditRead(token: string | null | undefined, env?: Record<string, string | undefined>, nowSec?: number): string;
106
+ /** Why a read was refused after its audit token verified. Recorded on the refusal's AuditLog row. */
107
+ export type AuditReadRefusalReason = 'ACCOUNT_NOT_FOUND' | 'ACCOUNT_NOT_PAPER' | 'SNAPSHOT_INCOMPLETE';
108
+ /**
109
+ * A read refused after the audit token verified, so the operator is known.
110
+ *
111
+ * Token failures from `assertAuditRead` are plain `GraphQLError`s and leave no
112
+ * record: the caller is unattributed. This class marks the refusals that do get
113
+ * an AuditLog row, and carries the reason that goes on it.
114
+ */
115
+ export declare class AuditReadRefused extends GraphQLError {
116
+ readonly reason: AuditReadRefusalReason;
117
+ constructor(reason: AuditReadRefusalReason, message: string, code: 'NOT_FOUND' | 'FORBIDDEN' | 'BAD_GATEWAY');
118
+ }
119
+ /**
120
+ * Refuse an account id that cannot name a stored account.
121
+ *
122
+ * `AlpacaAccount.id` is a Postgres uuid, and Prisma throws on a non-uuid
123
+ * lookup, so a malformed id would otherwise surface as an internal error with
124
+ * no refusal recorded.
125
+ *
126
+ * @throws {AuditReadRefused} `ACCOUNT_NOT_FOUND` for anything but a uuid.
127
+ */
128
+ export declare function assertAccountIdShape(accountId: string): void;
129
+ /** Audit reads are PAPER-only; a LIVE account is refused. */
130
+ export declare function assertAccountReadable(account: AuditAccountRow): void;
131
+ /**
132
+ * The snapshot's `equity` and `last_equity` as finite numbers.
133
+ *
134
+ * Alpaca sends both as decimal strings. A missing, empty or non-numeric value
135
+ * refuses the read rather than serving `NaN` (or `0`, which `Number('')` and
136
+ * `Number(null)` would give): either reads as a real figure to whoever audits it.
137
+ *
138
+ * @throws {AuditReadRefused} `SNAPSHOT_INCOMPLETE` naming the unusable fields.
139
+ */
140
+ export declare function snapshotEquity(snap: unknown): {
141
+ equity: number;
142
+ lastEquity: number;
143
+ };
144
+ /** The ET calendar date of an instant, YYYY-MM-DD. */
145
+ export declare function etDateOf(ms: number): string;
146
+ /**
147
+ * Validate a `YYYY-MM-DD` session date.
148
+ *
149
+ * @throws {GraphQLError} `BAD_USER_INPUT` for anything else, so nothing the
150
+ * caller sends is ever spliced into a URL unchecked.
151
+ */
152
+ export declare function parseSessionDate(raw: string | null | undefined): string | null;
153
+ /** The curve as returned to the caller. */
154
+ export interface EquityCurve {
155
+ accountId: string;
156
+ accountType: 'PAPER' | 'LIVE';
157
+ accountName: string;
158
+ sessionDate: string;
159
+ points: Array<{
160
+ ms: number;
161
+ equity: number;
162
+ }>;
163
+ lastEquity: number;
164
+ equity: number;
165
+ source: string;
166
+ }
167
+ /**
168
+ * Read one session's 1-minute equity curve and the account snapshot.
169
+ *
170
+ * @param p.account - The stored account row (carries the key; not returned).
171
+ * @param p.sessionDate - Pin a past session, or null for today's ET date.
172
+ * @param p.fetchImpl - Injected HTTP client.
173
+ * @throws {AuditReadRefused} for a LIVE account or an incomplete snapshot.
174
+ */
175
+ export declare function readEquityCurve(p: {
176
+ account: AuditAccountRow;
177
+ sessionDate: string | null;
178
+ nowMs: number;
179
+ fetchImpl: AlpacaFetch;
180
+ budget: RequestBudget;
181
+ }): Promise<EquityCurve>;
182
+ //# sourceMappingURL=account-audit-read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-audit-read.d.ts","sourceRoot":"","sources":["../../../src/resolvers/custom/account-audit-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAErD,qFAAqF;AACrF,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,uFAAuF;AACvF,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,0BAA0B,CAAC;AAE/D,gDAAgD;AAChD,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAEhE,+DAA+D;AAC/D,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C,kIAAkI;AAClI,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD,mFAAmF;AACnF,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAEjD,oGAAoG;AACpG,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,mDAAmD;AACnD,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,QAAS,CAAC;AAGxC,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;CACz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AAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACvG,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,aAAsD,CAAC;IAC3E,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,WAAW,EAAE,OAAO,CAAC,IAAI;QACzB,WAAW,EAAE,OAAO,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAA,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;QAC9E,WAAW;QACX,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,0BAA0B;KACnC,CAAC;AACJ,CAAC"}
@@ -5,7 +5,7 @@
5
5
  * with custom aggregation queries and business logic
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.FundTradingOverridesPayload = exports.OrgTradingDefaultsPayload = exports.TradingSettingsInput = exports.TradingSettings = exports.TradingSettingsResolver = exports.OptionsGreeksHistorySystemSummary = exports.hasStoredApiCredentials = exports.BrokerageAccountCredentialStatusResolver = exports.OptionsGreeksHistoryCustomResolver = void 0;
8
+ exports.EquityCurvePoint = exports.AccountEquityCurve = exports.AccountEquityCurveResolver = exports.FundTradingOverridesPayload = exports.OrgTradingDefaultsPayload = exports.TradingSettingsInput = exports.TradingSettings = exports.TradingSettingsResolver = exports.OptionsGreeksHistorySystemSummary = exports.hasStoredApiCredentials = exports.BrokerageAccountCredentialStatusResolver = exports.OptionsGreeksHistoryCustomResolver = void 0;
9
9
  var OptionsGreeksHistoryCustomResolver_1 = require("./OptionsGreeksHistoryCustomResolver.cjs");
10
10
  Object.defineProperty(exports, "OptionsGreeksHistoryCustomResolver", { enumerable: true, get: function () { return OptionsGreeksHistoryCustomResolver_1.OptionsGreeksHistoryCustomResolver; } });
11
11
  var BrokerageAccountCredentialStatusResolver_1 = require("./BrokerageAccountCredentialStatusResolver.cjs");
@@ -19,4 +19,8 @@ Object.defineProperty(exports, "TradingSettings", { enumerable: true, get: funct
19
19
  Object.defineProperty(exports, "TradingSettingsInput", { enumerable: true, get: function () { return TradingSettingsResolver_1.TradingSettingsInput; } });
20
20
  Object.defineProperty(exports, "OrgTradingDefaultsPayload", { enumerable: true, get: function () { return TradingSettingsResolver_1.OrgTradingDefaultsPayload; } });
21
21
  Object.defineProperty(exports, "FundTradingOverridesPayload", { enumerable: true, get: function () { return TradingSettingsResolver_1.FundTradingOverridesPayload; } });
22
+ var AccountEquityCurveResolver_1 = require("./AccountEquityCurveResolver.cjs");
23
+ Object.defineProperty(exports, "AccountEquityCurveResolver", { enumerable: true, get: function () { return AccountEquityCurveResolver_1.AccountEquityCurveResolver; } });
24
+ Object.defineProperty(exports, "AccountEquityCurve", { enumerable: true, get: function () { return AccountEquityCurveResolver_1.AccountEquityCurve; } });
25
+ Object.defineProperty(exports, "EquityCurvePoint", { enumerable: true, get: function () { return AccountEquityCurveResolver_1.EquityCurvePoint; } });
22
26
  //# sourceMappingURL=index.js.map
@@ -7,4 +7,5 @@ export { OptionsGreeksHistoryCustomResolver } from './OptionsGreeksHistoryCustom
7
7
  export { BrokerageAccountCredentialStatusResolver, hasStoredApiCredentials, } from './BrokerageAccountCredentialStatusResolver';
8
8
  export { OptionsGreeksHistorySystemSummary } from './OptionsGreeksHistorySystemSummary';
9
9
  export { TradingSettingsResolver, TradingSettings, TradingSettingsInput, OrgTradingDefaultsPayload, FundTradingOverridesPayload, } from './TradingSettingsResolver';
10
+ export { AccountEquityCurveResolver, AccountEquityCurve, EquityCurvePoint, } from './AccountEquityCurveResolver';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/resolvers/custom/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,wCAAwC,EACxC,uBAAuB,GACxB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/resolvers/custom/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,wCAAwC,EACxC,uBAAuB,GACxB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/resolvers/custom/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,2FAA0F;AAAjF,wJAAA,kCAAkC,OAAA;AAC3C,uGAGoD;AAFlD,oKAAA,wCAAwC,OAAA;AACxC,mJAAA,uBAAuB,OAAA;AAEzB,yFAAwF;AAA/E,sJAAA,iCAAiC,OAAA;AAC1C,qEAMmC;AALjC,kIAAA,uBAAuB,OAAA;AACvB,0HAAA,eAAe,OAAA;AACf,+HAAA,oBAAoB,OAAA;AACpB,oIAAA,yBAAyB,OAAA;AACzB,sIAAA,2BAA2B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/resolvers/custom/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,2FAA0F;AAAjF,wJAAA,kCAAkC,OAAA;AAC3C,uGAGoD;AAFlD,oKAAA,wCAAwC,OAAA;AACxC,mJAAA,uBAAuB,OAAA;AAEzB,yFAAwF;AAA/E,sJAAA,iCAAiC,OAAA;AAC1C,qEAMmC;AALjC,kIAAA,uBAAuB,OAAA;AACvB,0HAAA,eAAe,OAAA;AACf,+HAAA,oBAAoB,OAAA;AACpB,oIAAA,yBAAyB,OAAA;AACzB,sIAAA,2BAA2B,OAAA;AAE7B,2EAIsC;AAHpC,wIAAA,0BAA0B,OAAA;AAC1B,gIAAA,kBAAkB,OAAA;AAClB,8HAAA,gBAAgB,OAAA"}
package/server.cjs CHANGED
@@ -151,6 +151,7 @@ const startServer = async () => {
151
151
  custom_1.OptionsGreeksHistoryCustomResolver,
152
152
  custom_1.TradingSettingsResolver,
153
153
  custom_1.BrokerageAccountCredentialStatusResolver,
154
+ custom_1.AccountEquityCurveResolver,
154
155
  ],
155
156
  validate: false,
156
157
  // Row-level tenancy scoping (SP2-G7 / SOC2). Applies ONLY to user-scoped