@adaptic/backend-legacy 0.0.1037 → 0.0.1039

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 (101) hide show
  1. package/esm/auth/credential-fields.d.ts +19 -0
  2. package/esm/auth/credential-fields.d.ts.map +1 -0
  3. package/esm/auth/credential-fields.js.map +1 -0
  4. package/esm/auth/credential-fields.mjs +42 -0
  5. package/esm/auth/credential-redaction.d.ts +56 -0
  6. package/esm/auth/credential-redaction.d.ts.map +1 -0
  7. package/esm/auth/credential-redaction.js.map +1 -0
  8. package/esm/auth/credential-redaction.mjs +99 -0
  9. package/esm/auth/mutation-authorization.d.ts +206 -0
  10. package/esm/auth/mutation-authorization.d.ts.map +1 -0
  11. package/esm/auth/mutation-authorization.js.map +1 -0
  12. package/esm/auth/mutation-authorization.mjs +271 -0
  13. package/esm/auth/nested-write-inspector.d.ts +94 -0
  14. package/esm/auth/nested-write-inspector.d.ts.map +1 -0
  15. package/esm/auth/nested-write-inspector.js.map +1 -0
  16. package/esm/auth/nested-write-inspector.mjs +185 -0
  17. package/esm/auth/nested-write-policy.d.ts +95 -0
  18. package/esm/auth/nested-write-policy.d.ts.map +1 -0
  19. package/esm/auth/nested-write-policy.js.map +1 -0
  20. package/esm/auth/nested-write-policy.mjs +154 -0
  21. package/esm/auth/service-token.d.ts +11 -1
  22. package/esm/auth/service-token.d.ts.map +1 -1
  23. package/esm/auth/service-token.js.map +1 -1
  24. package/esm/auth/service-token.mjs +31 -5
  25. package/esm/auth/token-verifier.d.ts +9 -1
  26. package/esm/auth/token-verifier.d.ts.map +1 -1
  27. package/esm/auth/token-verifier.js.map +1 -1
  28. package/esm/auth/user-write-content.d.ts +41 -0
  29. package/esm/auth/user-write-content.d.ts.map +1 -0
  30. package/esm/auth/user-write-content.js.map +1 -0
  31. package/esm/auth/user-write-content.mjs +100 -0
  32. package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts +55 -0
  33. package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts.map +1 -0
  34. package/esm/middleware/__tests__/credential-field-coverage.harness.js.map +1 -0
  35. package/esm/middleware/__tests__/credential-field-coverage.harness.mjs +438 -0
  36. package/esm/middleware/__tests__/credential-field-guard.harness.d.ts +34 -0
  37. package/esm/middleware/__tests__/credential-field-guard.harness.d.ts.map +1 -0
  38. package/esm/middleware/__tests__/credential-field-guard.harness.js.map +1 -0
  39. package/esm/middleware/__tests__/credential-field-guard.harness.mjs +212 -0
  40. package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +49 -0
  41. package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts.map +1 -0
  42. package/esm/middleware/__tests__/mutation-auth-guard.harness.js.map +1 -0
  43. package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +402 -0
  44. package/esm/middleware/__tests__/ts-node-harness.d.ts +10 -0
  45. package/esm/middleware/__tests__/ts-node-harness.d.ts.map +1 -0
  46. package/esm/middleware/__tests__/ts-node-harness.js.map +1 -0
  47. package/esm/middleware/__tests__/ts-node-harness.mjs +71 -0
  48. package/esm/middleware/audit-logger.d.ts +18 -1
  49. package/esm/middleware/audit-logger.d.ts.map +1 -1
  50. package/esm/middleware/audit-logger.js.map +1 -1
  51. package/esm/middleware/audit-logger.mjs +36 -13
  52. package/esm/middleware/audit-payload-guard.d.ts +85 -0
  53. package/esm/middleware/audit-payload-guard.d.ts.map +1 -0
  54. package/esm/middleware/audit-payload-guard.js.map +1 -0
  55. package/esm/middleware/audit-payload-guard.mjs +97 -0
  56. package/esm/middleware/credential-field-guard.d.ts +160 -0
  57. package/esm/middleware/credential-field-guard.d.ts.map +1 -0
  58. package/esm/middleware/credential-field-guard.js.map +1 -0
  59. package/esm/middleware/credential-field-guard.mjs +479 -0
  60. package/esm/middleware/generated-type-names.d.ts +44 -0
  61. package/esm/middleware/generated-type-names.d.ts.map +1 -0
  62. package/esm/middleware/generated-type-names.js.map +1 -0
  63. package/esm/middleware/generated-type-names.mjs +73 -0
  64. package/esm/middleware/guard-log-throttle.d.ts +80 -0
  65. package/esm/middleware/guard-log-throttle.d.ts.map +1 -0
  66. package/esm/middleware/guard-log-throttle.js.map +1 -0
  67. package/esm/middleware/guard-log-throttle.mjs +87 -0
  68. package/esm/middleware/mutation-account-facts.d.ts +140 -0
  69. package/esm/middleware/mutation-account-facts.d.ts.map +1 -0
  70. package/esm/middleware/mutation-account-facts.js.map +1 -0
  71. package/esm/middleware/mutation-account-facts.mjs +212 -0
  72. package/esm/middleware/mutation-auth-guard.d.ts +82 -0
  73. package/esm/middleware/mutation-auth-guard.d.ts.map +1 -0
  74. package/esm/middleware/mutation-auth-guard.js.map +1 -0
  75. package/esm/middleware/mutation-auth-guard.mjs +425 -0
  76. package/esm/middleware/mutation-tenant-facts.d.ts +58 -0
  77. package/esm/middleware/mutation-tenant-facts.d.ts.map +1 -0
  78. package/esm/middleware/mutation-tenant-facts.js.map +1 -0
  79. package/esm/middleware/mutation-tenant-facts.mjs +75 -0
  80. package/esm/middleware/trading-policy-audit.d.ts +172 -0
  81. package/esm/middleware/trading-policy-audit.d.ts.map +1 -0
  82. package/esm/middleware/trading-policy-audit.js.map +1 -0
  83. package/esm/middleware/trading-policy-audit.mjs +309 -0
  84. package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts +22 -0
  85. package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts.map +1 -0
  86. package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.js.map +1 -0
  87. package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.mjs +63 -0
  88. package/esm/resolvers/custom/index.d.ts +1 -0
  89. package/esm/resolvers/custom/index.d.ts.map +1 -1
  90. package/esm/resolvers/custom/index.js.map +1 -1
  91. package/esm/resolvers/custom/index.mjs +1 -0
  92. package/package.json +1 -1
  93. package/resolvers/custom/BrokerageAccountCredentialStatusResolver.cjs +100 -0
  94. package/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts +22 -0
  95. package/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts.map +1 -0
  96. package/resolvers/custom/BrokerageAccountCredentialStatusResolver.js.map +1 -0
  97. package/resolvers/custom/index.cjs +4 -1
  98. package/resolvers/custom/index.d.ts +1 -0
  99. package/resolvers/custom/index.d.ts.map +1 -1
  100. package/resolvers/custom/index.js.map +1 -1
  101. package/server.cjs +40 -3
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
45
+ return function (target, key) { decorator(target, key, paramIndex); }
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.BrokerageAccountCredentialStatusResolver = void 0;
49
+ exports.hasStoredApiCredentials = hasStoredApiCredentials;
50
+ /**
51
+ * `BrokerageAccount.hasApiCredentials` — whether an account's broker API key
52
+ * and secret are both stored, without reading either one.
53
+ *
54
+ * The credential columns are readable only by a service principal (see
55
+ * `src/middleware/credential-field-guard.ts`), yet a client legitimately needs
56
+ * to show whether an account is configured. Selecting the secret to test it
57
+ * for emptiness would put the secret on the wire for a yes/no answer, so the
58
+ * answer is computed here, where the row is already in memory, and only the
59
+ * boolean leaves the server.
60
+ *
61
+ * @module resolvers/custom/BrokerageAccountCredentialStatusResolver
62
+ */
63
+ const TypeGraphQL = __importStar(require("type-graphql"));
64
+ const BrokerageAccount_1 = require("../../generated/typegraphql-prisma/models/BrokerageAccount.cjs");
65
+ /**
66
+ * True only when both credential columns hold a non-blank value.
67
+ *
68
+ * @param account - The parent row as the generated resolvers loaded it.
69
+ * @returns Whether the account can authenticate to its broker.
70
+ */
71
+ function hasStoredApiCredentials(account) {
72
+ const present = (value) => typeof value === 'string' && value.trim().length > 0;
73
+ return present(account.apiKey) && present(account.apiSecret);
74
+ }
75
+ /** Adds the computed `hasApiCredentials` field to `BrokerageAccount`. */
76
+ let BrokerageAccountCredentialStatusResolver = class BrokerageAccountCredentialStatusResolver {
77
+ /**
78
+ * Whether both the API key and secret are stored for this account.
79
+ *
80
+ * @param account - The parent `BrokerageAccount` row.
81
+ * @returns `true` when both credential columns are non-blank.
82
+ */
83
+ hasApiCredentials(account) {
84
+ return hasStoredApiCredentials(account);
85
+ }
86
+ };
87
+ exports.BrokerageAccountCredentialStatusResolver = BrokerageAccountCredentialStatusResolver;
88
+ __decorate([
89
+ TypeGraphQL.FieldResolver(() => Boolean, {
90
+ description: 'Whether both broker API credential columns are stored. Readable by any caller that can read the account; the credentials themselves are not.',
91
+ }),
92
+ __param(0, TypeGraphQL.Root()),
93
+ __metadata("design:type", Function),
94
+ __metadata("design:paramtypes", [BrokerageAccount_1.BrokerageAccount]),
95
+ __metadata("design:returntype", Boolean)
96
+ ], BrokerageAccountCredentialStatusResolver.prototype, "hasApiCredentials", null);
97
+ exports.BrokerageAccountCredentialStatusResolver = BrokerageAccountCredentialStatusResolver = __decorate([
98
+ TypeGraphQL.Resolver(() => BrokerageAccount_1.BrokerageAccount)
99
+ ], BrokerageAccountCredentialStatusResolver);
100
+ //# sourceMappingURL=BrokerageAccountCredentialStatusResolver.js.map
@@ -0,0 +1,22 @@
1
+ import { BrokerageAccount } from '../../generated/typegraphql-prisma/models/BrokerageAccount';
2
+ /** The two credential columns this resolver inspects on the parent row. */
3
+ type CredentialColumns = Pick<BrokerageAccount, 'apiKey' | 'apiSecret'>;
4
+ /**
5
+ * True only when both credential columns hold a non-blank value.
6
+ *
7
+ * @param account - The parent row as the generated resolvers loaded it.
8
+ * @returns Whether the account can authenticate to its broker.
9
+ */
10
+ export declare function hasStoredApiCredentials(account: CredentialColumns): boolean;
11
+ /** Adds the computed `hasApiCredentials` field to `BrokerageAccount`. */
12
+ export declare class BrokerageAccountCredentialStatusResolver {
13
+ /**
14
+ * Whether both the API key and secret are stored for this account.
15
+ *
16
+ * @param account - The parent `BrokerageAccount` row.
17
+ * @returns `true` when both credential columns are non-blank.
18
+ */
19
+ hasApiCredentials(account: BrokerageAccount): boolean;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=BrokerageAccountCredentialStatusResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrokerageAccountCredentialStatusResolver.d.ts","sourceRoot":"","sources":["../../../src/resolvers/custom/BrokerageAccountCredentialStatusResolver.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAC;AAE9F,2EAA2E;AAC3E,KAAK,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,WAAW,CAAC,CAAC;AAExE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAI3E;AAED,yEAAyE;AACzE,qBACa,wCAAwC;IACnD;;;;;OAKG;IAKH,iBAAiB,CAAqB,OAAO,EAAE,gBAAgB,GAAG,OAAO;CAG1E"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrokerageAccountCredentialStatusResolver.js","sourceRoot":"","sources":["../../../src/resolvers/custom/BrokerageAccountCredentialStatusResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,0DAIC;AA9BD;;;;;;;;;;;;GAYG;AACH,0DAA4C;AAE5C,iGAA8F;AAK9F;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,OAA0B;IAChE,MAAM,OAAO,GAAG,CAAC,KAAgC,EAAW,EAAE,CAC5D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IACvD,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAC/D,CAAC;AAED,yEAAyE;AAElE,IAAM,wCAAwC,GAA9C,MAAM,wCAAwC;IACnD;;;;;OAKG;IAKH,iBAAiB,CAAqB,OAAyB;QAC7D,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AAdY,4FAAwC;AAWnD;IAJC,WAAW,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACxC,WAAW,EACT,8IAA8I;KACjJ,CAAC;IACiB,WAAA,WAAW,CAAC,IAAI,EAAE,CAAA;;qCAAU,mCAAgB;;iFAE9D;mDAbU,wCAAwC;IADpD,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,mCAAgB,CAAC;GAChC,wCAAwC,CAcpD"}
@@ -5,9 +5,12 @@
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.OptionsGreeksHistoryCustomResolver = void 0;
8
+ 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
+ var BrokerageAccountCredentialStatusResolver_1 = require("./BrokerageAccountCredentialStatusResolver.cjs");
12
+ Object.defineProperty(exports, "BrokerageAccountCredentialStatusResolver", { enumerable: true, get: function () { return BrokerageAccountCredentialStatusResolver_1.BrokerageAccountCredentialStatusResolver; } });
13
+ Object.defineProperty(exports, "hasStoredApiCredentials", { enumerable: true, get: function () { return BrokerageAccountCredentialStatusResolver_1.hasStoredApiCredentials; } });
11
14
  var OptionsGreeksHistorySystemSummary_1 = require("./OptionsGreeksHistorySystemSummary.cjs");
12
15
  Object.defineProperty(exports, "OptionsGreeksHistorySystemSummary", { enumerable: true, get: function () { return OptionsGreeksHistorySystemSummary_1.OptionsGreeksHistorySystemSummary; } });
13
16
  var TradingSettingsResolver_1 = require("./TradingSettingsResolver.cjs");
@@ -4,6 +4,7 @@
4
4
  * with custom aggregation queries and business logic
5
5
  */
6
6
  export { OptionsGreeksHistoryCustomResolver } from './OptionsGreeksHistoryCustomResolver';
7
+ export { BrokerageAccountCredentialStatusResolver, hasStoredApiCredentials, } from './BrokerageAccountCredentialStatusResolver';
7
8
  export { OptionsGreeksHistorySystemSummary } from './OptionsGreeksHistorySystemSummary';
8
9
  export { TradingSettingsResolver, TradingSettings, TradingSettingsInput, OrgTradingDefaultsPayload, FundTradingOverridesPayload, } from './TradingSettingsResolver';
9
10
  //# 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,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"}
@@ -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,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"}
package/server.cjs CHANGED
@@ -62,6 +62,9 @@ const auth_1 = require("./middleware/auth.cjs");
62
62
  const rate_limiter_1 = require("./middleware/rate-limiter.cjs");
63
63
  const audit_logger_1 = require("./middleware/audit-logger.cjs");
64
64
  const tenancy_scoping_1 = require("./middleware/tenancy-scoping.cjs");
65
+ const credential_field_guard_1 = require("./middleware/credential-field-guard.cjs");
66
+ const mutation_auth_guard_1 = require("./middleware/mutation-auth-guard.cjs");
67
+ const trading_policy_audit_1 = require("./middleware/trading-policy-audit.cjs");
65
68
  const cortex_auth_checker_1 = require("./auth/cortex-auth-checker.cjs");
66
69
  const authorization_map_1 = require("./auth/authorization-map.cjs");
67
70
  const http_status_mapper_1 = require("./plugins/http-status-mapper.cjs");
@@ -143,13 +146,24 @@ const startServer = async () => {
143
146
  ...typegraphql_prisma_1.resolvers,
144
147
  custom_1.OptionsGreeksHistoryCustomResolver,
145
148
  custom_1.TradingSettingsResolver,
149
+ custom_1.BrokerageAccountCredentialStatusResolver,
146
150
  ],
147
151
  validate: false,
148
152
  // Row-level tenancy scoping (SP2-G7 / SOC2). Applies ONLY to user-scoped
149
153
  // principals on the tenancy + notification models; service/admin principals
150
154
  // and unauthenticated callers are bypassed in every mode. Gated by
151
155
  // `TENANCY_SCOPING_MODE` (default `shadow`).
152
- globalMiddlewares: [(0, tenancy_scoping_1.createTenancyScopingMiddleware)()],
156
+ //
157
+ // Credential-field guard: stored credentials (broker API keys, OAuth,
158
+ // session and invite tokens) resolve — and can be filtered, sorted or
159
+ // grouped on — only for a verified service principal. It runs FIRST so a
160
+ // credential predicate is refused before any other middleware or resolver
161
+ // touches the database. Gated by `CREDENTIAL_FIELD_GUARD_MODE` (default
162
+ // `enforce`); see src/middleware/credential-field-guard.ts.
163
+ globalMiddlewares: [
164
+ (0, credential_field_guard_1.createCredentialFieldGuardMiddleware)(),
165
+ (0, tenancy_scoping_1.createTenancyScopingMiddleware)(),
166
+ ],
153
167
  // Resolver-level authorization (CORTEX-P0-001). Invoked for the
154
168
  // `@Authorized()`-decorated fields applied by applyCortexAuthorizationMap
155
169
  // above. SHADOW-FIRST: while `CORTEX_AUTHCHECKER_ENFORCE` is OFF (default),
@@ -157,6 +171,20 @@ const startServer = async () => {
157
171
  // byte-identical live behaviour until enforcement is flipped on.
158
172
  authChecker: cortex_auth_checker_1.cortexAuthChecker,
159
173
  });
174
+ // Mutation authorization: every mutation is admitted only for a principal
175
+ // authorised to write that model — the engine's service principal and admins
176
+ // everywhere, a user only on an account, row or tenant it owns — and every
177
+ // TradingPolicy write leaves an attributed audit row. Installed on the built
178
+ // schema's Mutation fields (not as a global middleware, which would tax every
179
+ // read field), so it covers generated and custom mutations alike on both the
180
+ // HTTP and WebSocket transports. Gated by `MUTATION_AUTH_MODE` (unset =
181
+ // `shadow`) and the per-model escalation `MUTATION_AUTH_ENFORCE_MODELS`; see
182
+ // src/middleware/mutation-auth-guard.ts and
183
+ // docs/security/2026-09-24-mutation-authorization-runbook.md.
184
+ const guardedMutations = (0, mutation_auth_guard_1.installMutationAuthGuard)(schema);
185
+ logger_1.logger.info('[mutation-auth] guard installed on every root Mutation field', {
186
+ guardedMutations,
187
+ });
160
188
  const app = (0, express_1.default)();
161
189
  const httpServer = (0, http_1.createServer)(app);
162
190
  // Trust the load-balancer proxy chain so `req.ip` resolves the CLIENT address
@@ -303,7 +331,10 @@ const startServer = async () => {
303
331
  },
304
332
  credentials: true,
305
333
  methods: ['GET', 'POST', 'OPTIONS'],
306
- allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-ID'],
334
+ // X-Adaptic-Change-Reason is the stated reason recorded on every
335
+ // TradingPolicy audit row (src/middleware/trading-policy-audit.ts); a
336
+ // browser caller can only send it if preflight allows it.
337
+ allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-ID', 'X-Adaptic-Change-Reason'],
307
338
  maxAge: 86400, // 24h preflight cache
308
339
  };
309
340
  app.use('/graphql', (0, cors_1.default)(corsOptions),
@@ -443,12 +474,18 @@ const startServer = async () => {
443
474
  userAgent: wsIdentity.userAgent,
444
475
  authHeaderPresent: authHeader.length > 0,
445
476
  });
446
- return { prisma: global.prisma, user: null, principal: null };
477
+ return {
478
+ prisma: global.prisma,
479
+ req: (0, trading_policy_audit_1.wsActorRequest)(ctx.extra, ctx.connectionParams),
480
+ user: null,
481
+ principal: null,
482
+ };
447
483
  }
448
484
  case 'authenticated': {
449
485
  (0, graphql_auth_shadow_1.recordAuthContextOutcome)('ws', 'authenticated');
450
486
  return {
451
487
  prisma: global.prisma,
488
+ req: (0, trading_policy_audit_1.wsActorRequest)(ctx.extra, ctx.connectionParams),
452
489
  user: principalToUser(decision.principal),
453
490
  principal: decision.principal,
454
491
  };