@adaptic/backend 0.0.1057 → 0.0.1059
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/authorization-map.cjs +306 -0
- package/auth/authorization-map.d.ts +143 -0
- package/auth/cortex-auth-checker.cjs +172 -0
- package/auth/cortex-auth-checker.d.ts +114 -0
- package/auth/credential-fields.cjs +51 -0
- package/auth/credential-fields.d.ts +19 -0
- package/auth/credential-redaction.cjs +134 -0
- package/auth/credential-redaction.d.ts +60 -0
- package/auth/graphql-auth-shadow.cjs +317 -0
- package/auth/graphql-auth-shadow.d.ts +194 -0
- package/auth/membership-write-authority.cjs +131 -0
- package/auth/membership-write-authority.d.ts +110 -0
- package/auth/mutation-authorization.cjs +376 -0
- package/auth/mutation-authorization.d.ts +261 -0
- package/auth/nested-write-inspector.cjs +189 -0
- package/auth/nested-write-inspector.d.ts +94 -0
- package/auth/nested-write-policy.cjs +189 -0
- package/auth/nested-write-policy.d.ts +99 -0
- package/auth/service-token.cjs +339 -0
- package/auth/service-token.d.ts +106 -0
- package/auth/tenancy-scope.cjs +736 -0
- package/auth/tenancy-scope.d.ts +347 -0
- package/auth/token-verifier.cjs +451 -0
- package/auth/token-verifier.d.ts +153 -0
- package/auth/totp.cjs +265 -0
- package/auth/totp.d.ts +111 -0
- package/auth/user-write-content.cjs +116 -0
- package/auth/user-write-content.d.ts +47 -0
- package/auth/ws-auth-context.cjs +75 -0
- package/auth/ws-auth-context.d.ts +69 -0
- package/config/jwtConfig.cjs +57 -0
- package/config/jwtConfig.d.ts +16 -0
- package/config/metrics.cjs +356 -0
- package/config/metrics.d.ts +128 -0
- package/config/persisted-queries.cjs +122 -0
- package/config/persisted-queries.d.ts +40 -0
- package/config/server-only-models.cjs +166 -0
- package/config/server-only-models.d.ts +89 -0
- package/config/tracing.d.ts +24 -0
- package/esm/auth/service-token.d.ts +12 -0
- package/esm/auth/service-token.mjs +27 -5
- package/esm/config/jwtConfig.mjs +5 -1
- package/generated/typegraphql-prisma/enhance.cjs +3 -3
- package/generated/typegraphql-prisma/index.cjs +6 -6
- package/generated/typegraphql-prisma/resolvers/crud/args.index.cjs +95 -95
- package/generated/typegraphql-prisma/resolvers/outputs/index.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/relations/args.index.cjs +32 -32
- package/middleware/audit-log-write-redaction.cjs +143 -0
- package/middleware/audit-log-write-redaction.d.ts +82 -0
- package/middleware/audit-logger.cjs +378 -0
- package/middleware/audit-logger.d.ts +158 -0
- package/middleware/audit-payload-guard.cjs +107 -0
- package/middleware/audit-payload-guard.d.ts +85 -0
- package/middleware/auth.cjs +66 -0
- package/middleware/auth.d.ts +41 -0
- package/middleware/credential-field-guard.cjs +514 -0
- package/middleware/credential-field-guard.d.ts +173 -0
- package/middleware/generated-type-names.cjs +77 -0
- package/middleware/generated-type-names.d.ts +44 -0
- package/middleware/graphql-validation-plugin.cjs +310 -0
- package/middleware/graphql-validation-plugin.d.ts +98 -0
- package/middleware/guard-log-throttle.cjs +89 -0
- package/middleware/guard-log-throttle.d.ts +80 -0
- package/middleware/index.cjs +57 -0
- package/middleware/index.d.ts +14 -0
- package/middleware/input-validator.cjs +220 -0
- package/middleware/input-validator.d.ts +63 -0
- package/middleware/mandate-version-validation.cjs +131 -0
- package/middleware/mandate-version-validation.d.ts +41 -0
- package/middleware/mutation-account-facts.cjs +223 -0
- package/middleware/mutation-account-facts.d.ts +143 -0
- package/middleware/mutation-auth-guard.cjs +536 -0
- package/middleware/mutation-auth-guard.d.ts +100 -0
- package/middleware/mutation-membership-facts.cjs +276 -0
- package/middleware/mutation-membership-facts.d.ts +133 -0
- package/middleware/mutation-tenant-facts.cjs +132 -0
- package/middleware/mutation-tenant-facts.d.ts +81 -0
- package/middleware/query-complexity.cjs +182 -0
- package/middleware/query-complexity.d.ts +56 -0
- package/middleware/rate-limiter.cjs +223 -0
- package/middleware/rate-limiter.d.ts +93 -0
- package/middleware/rate-tier.cjs +111 -0
- package/middleware/rate-tier.d.ts +56 -0
- package/middleware/soft-delete.cjs +175 -0
- package/middleware/soft-delete.d.ts +146 -0
- package/middleware/tenancy-scoping.cjs +229 -0
- package/middleware/tenancy-scoping.d.ts +67 -0
- package/middleware/trading-policy-audit.cjs +353 -0
- package/middleware/trading-policy-audit.d.ts +184 -0
- package/middleware/types.cjs +17 -0
- package/middleware/types.d.ts +87 -0
- package/middleware/validation-examples.cjs +398 -0
- package/middleware/validation-examples.d.ts +76 -0
- package/package.json +10 -2
- package/readers/index.cjs +15 -0
- package/readers/index.d.ts +10 -0
- package/readers/intraday-lane-prefs.cjs +76 -0
- package/readers/intraday-lane-prefs.d.ts +45 -0
- package/esm/config/__tests__/server-only-surface.harness.d.ts +0 -12
- package/esm/config/__tests__/server-only-surface.harness.mjs +0 -41
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.d.ts +0 -144
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.mjs +0 -920
- package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts +0 -55
- package/esm/middleware/__tests__/credential-field-coverage.harness.mjs +0 -440
- package/esm/middleware/__tests__/credential-field-guard.harness.d.ts +0 -34
- package/esm/middleware/__tests__/credential-field-guard.harness.mjs +0 -212
- package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +0 -56
- package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +0 -575
- package/esm/middleware/__tests__/rate-limit-test-utils.d.ts +0 -60
- package/esm/middleware/__tests__/rate-limit-test-utils.mjs +0 -85
- package/esm/middleware/__tests__/ts-node-harness.d.ts +0 -10
- package/esm/middleware/__tests__/ts-node-harness.mjs +0 -71
- package/health.cjs +0 -274
- package/server.cjs +0 -607
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example usage of validation functions in custom resolvers
|
|
4
|
+
*
|
|
5
|
+
* This file demonstrates how to use the validation utilities
|
|
6
|
+
* in custom resolver implementations.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
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;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
};
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
48
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
49
|
+
};
|
|
50
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
51
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.CustomValidators = exports.ValidationExamplesResolver = void 0;
|
|
55
|
+
const TypeGraphQL = __importStar(require("type-graphql"));
|
|
56
|
+
const input_validator_1 = require("./input-validator.cjs");
|
|
57
|
+
/**
|
|
58
|
+
* Example: Portfolio allocation input with validation
|
|
59
|
+
*/
|
|
60
|
+
let PortfolioAllocationInput = class PortfolioAllocationInput {
|
|
61
|
+
};
|
|
62
|
+
__decorate([
|
|
63
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
64
|
+
__metadata("design:type", Number)
|
|
65
|
+
], PortfolioAllocationInput.prototype, "equitiesPct", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
68
|
+
__metadata("design:type", Number)
|
|
69
|
+
], PortfolioAllocationInput.prototype, "optionsPct", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
72
|
+
__metadata("design:type", Number)
|
|
73
|
+
], PortfolioAllocationInput.prototype, "cryptoPct", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
TypeGraphQL.Field(() => String),
|
|
76
|
+
__metadata("design:type", String)
|
|
77
|
+
], PortfolioAllocationInput.prototype, "portfolioName", void 0);
|
|
78
|
+
PortfolioAllocationInput = __decorate([
|
|
79
|
+
TypeGraphQL.InputType()
|
|
80
|
+
], PortfolioAllocationInput);
|
|
81
|
+
/**
|
|
82
|
+
* Example: Trade configuration input with validation
|
|
83
|
+
*/
|
|
84
|
+
let TradeConfigurationInput = class TradeConfigurationInput {
|
|
85
|
+
};
|
|
86
|
+
__decorate([
|
|
87
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
88
|
+
__metadata("design:type", Number)
|
|
89
|
+
], TradeConfigurationInput.prototype, "tradeAllocationPct", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
92
|
+
__metadata("design:type", Number)
|
|
93
|
+
], TradeConfigurationInput.prototype, "minPercentageChange", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
96
|
+
__metadata("design:type", Number)
|
|
97
|
+
], TradeConfigurationInput.prototype, "volumeThreshold", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
TypeGraphQL.Field(() => TypeGraphQL.Int),
|
|
100
|
+
__metadata("design:type", Number)
|
|
101
|
+
], TradeConfigurationInput.prototype, "quantity", void 0);
|
|
102
|
+
TradeConfigurationInput = __decorate([
|
|
103
|
+
TypeGraphQL.InputType()
|
|
104
|
+
], TradeConfigurationInput);
|
|
105
|
+
/**
|
|
106
|
+
* Example resolver demonstrating manual validation in custom resolvers
|
|
107
|
+
*
|
|
108
|
+
* Note: With the validation plugin enabled, these validations happen
|
|
109
|
+
* automatically. This example shows how to add ADDITIONAL custom validation
|
|
110
|
+
* logic beyond the automatic pattern-based validation.
|
|
111
|
+
*/
|
|
112
|
+
let ValidationExamplesResolver = class ValidationExamplesResolver {
|
|
113
|
+
/**
|
|
114
|
+
* Example 1: Basic field validation in a mutation
|
|
115
|
+
*/
|
|
116
|
+
async updatePortfolioAllocation(input) {
|
|
117
|
+
// The validation plugin will automatically validate:
|
|
118
|
+
// - equitiesPct (0-100)
|
|
119
|
+
// - optionsPct (0-100)
|
|
120
|
+
// - cryptoPct (0-100)
|
|
121
|
+
// - portfolioName (non-empty)
|
|
122
|
+
// Add custom business logic validation
|
|
123
|
+
const totalAllocation = input.equitiesPct + input.optionsPct + input.cryptoPct;
|
|
124
|
+
if (totalAllocation !== 100) {
|
|
125
|
+
throw new input_validator_1.ValidationError('Total allocation must equal 100%', [
|
|
126
|
+
{
|
|
127
|
+
field: 'totalAllocation',
|
|
128
|
+
value: totalAllocation,
|
|
129
|
+
message: 'Sum of equitiesPct, optionsPct, and cryptoPct must equal 100',
|
|
130
|
+
constraint: 'sum',
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
// Resolver implementation...
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Example 2: Batch validation using validateFields
|
|
139
|
+
*/
|
|
140
|
+
async updateTradeConfiguration(input) {
|
|
141
|
+
// The validation plugin handles basic validation automatically.
|
|
142
|
+
// Use validateFields for additional custom validations.
|
|
143
|
+
// ValidationError is automatically formatted by Apollo Server
|
|
144
|
+
(0, input_validator_1.validateFields)([
|
|
145
|
+
// Custom validation: minPercentageChange should be less than tradeAllocationPct
|
|
146
|
+
() => {
|
|
147
|
+
if (input.minPercentageChange >= input.tradeAllocationPct) {
|
|
148
|
+
throw new input_validator_1.ValidationError('Invalid configuration', [
|
|
149
|
+
{
|
|
150
|
+
field: 'minPercentageChange',
|
|
151
|
+
value: input.minPercentageChange,
|
|
152
|
+
message: 'Must be less than tradeAllocationPct',
|
|
153
|
+
constraint: 'comparison',
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
]);
|
|
159
|
+
// Resolver implementation...
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Example 3: Conditional validation based on business logic
|
|
164
|
+
*/
|
|
165
|
+
async createTrade(quantity, isPremiumUser) {
|
|
166
|
+
// Basic validation happens automatically via plugin
|
|
167
|
+
// Add conditional validation based on user type
|
|
168
|
+
if (!isPremiumUser && quantity > 1000) {
|
|
169
|
+
throw new input_validator_1.ValidationError('Quantity limit exceeded', [
|
|
170
|
+
{
|
|
171
|
+
field: 'quantity',
|
|
172
|
+
value: quantity,
|
|
173
|
+
message: 'Non-premium users are limited to 1000 units per trade',
|
|
174
|
+
constraint: 'userLimit',
|
|
175
|
+
},
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
// Resolver implementation...
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Example 4: Validating related fields together
|
|
183
|
+
*/
|
|
184
|
+
async setTradingThresholds(minPrice, maxPrice, targetPrice) {
|
|
185
|
+
// Automatic validation ensures all are positive numbers
|
|
186
|
+
// Custom validation for related fields
|
|
187
|
+
if (minPrice >= maxPrice) {
|
|
188
|
+
throw new input_validator_1.ValidationError('Invalid price range', [
|
|
189
|
+
{
|
|
190
|
+
field: 'minPrice',
|
|
191
|
+
value: minPrice,
|
|
192
|
+
message: 'minPrice must be less than maxPrice',
|
|
193
|
+
constraint: 'range',
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
if (targetPrice < minPrice || targetPrice > maxPrice) {
|
|
198
|
+
throw new input_validator_1.ValidationError('Invalid target price', [
|
|
199
|
+
{
|
|
200
|
+
field: 'targetPrice',
|
|
201
|
+
value: targetPrice,
|
|
202
|
+
message: 'targetPrice must be between minPrice and maxPrice',
|
|
203
|
+
constraint: 'range',
|
|
204
|
+
},
|
|
205
|
+
]);
|
|
206
|
+
}
|
|
207
|
+
// Resolver implementation...
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Example 5: Using manual validation for non-standard field names
|
|
212
|
+
*/
|
|
213
|
+
async updateCustomSettings(customAllocation, customQuantity) {
|
|
214
|
+
// These field names don't match the automatic validation patterns,
|
|
215
|
+
// so we validate manually
|
|
216
|
+
(0, input_validator_1.validatePercentage)(customAllocation, 'customAllocation');
|
|
217
|
+
(0, input_validator_1.validatePositiveNumber)(customQuantity, 'customQuantity');
|
|
218
|
+
// Resolver implementation...
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Example 6: Accumulating multiple validation errors
|
|
223
|
+
*/
|
|
224
|
+
async bulkUpdateAllocations(allocations) {
|
|
225
|
+
// Validate each allocation
|
|
226
|
+
// The plugin validates each item's fields automatically
|
|
227
|
+
// Add custom cross-item validation
|
|
228
|
+
const totalItems = allocations.length;
|
|
229
|
+
if (totalItems === 0) {
|
|
230
|
+
throw new input_validator_1.ValidationError('Empty allocations array', [
|
|
231
|
+
{
|
|
232
|
+
field: 'allocations',
|
|
233
|
+
value: totalItems,
|
|
234
|
+
message: 'Must provide at least one allocation',
|
|
235
|
+
constraint: 'notEmpty',
|
|
236
|
+
},
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
if (totalItems > 100) {
|
|
240
|
+
throw new input_validator_1.ValidationError('Too many allocations', [
|
|
241
|
+
{
|
|
242
|
+
field: 'allocations',
|
|
243
|
+
value: totalItems,
|
|
244
|
+
message: 'Maximum 100 allocations per request',
|
|
245
|
+
constraint: 'maxLength',
|
|
246
|
+
},
|
|
247
|
+
]);
|
|
248
|
+
}
|
|
249
|
+
// Resolver implementation...
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
exports.ValidationExamplesResolver = ValidationExamplesResolver;
|
|
254
|
+
__decorate([
|
|
255
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
256
|
+
__param(0, TypeGraphQL.Arg('input')),
|
|
257
|
+
__metadata("design:type", Function),
|
|
258
|
+
__metadata("design:paramtypes", [PortfolioAllocationInput]),
|
|
259
|
+
__metadata("design:returntype", Promise)
|
|
260
|
+
], ValidationExamplesResolver.prototype, "updatePortfolioAllocation", null);
|
|
261
|
+
__decorate([
|
|
262
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
263
|
+
__param(0, TypeGraphQL.Arg('input')),
|
|
264
|
+
__metadata("design:type", Function),
|
|
265
|
+
__metadata("design:paramtypes", [TradeConfigurationInput]),
|
|
266
|
+
__metadata("design:returntype", Promise)
|
|
267
|
+
], ValidationExamplesResolver.prototype, "updateTradeConfiguration", null);
|
|
268
|
+
__decorate([
|
|
269
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
270
|
+
__param(0, TypeGraphQL.Arg('quantity')),
|
|
271
|
+
__param(1, TypeGraphQL.Arg('isPremiumUser')),
|
|
272
|
+
__metadata("design:type", Function),
|
|
273
|
+
__metadata("design:paramtypes", [Number, Boolean]),
|
|
274
|
+
__metadata("design:returntype", Promise)
|
|
275
|
+
], ValidationExamplesResolver.prototype, "createTrade", null);
|
|
276
|
+
__decorate([
|
|
277
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
278
|
+
__param(0, TypeGraphQL.Arg('minPrice')),
|
|
279
|
+
__param(1, TypeGraphQL.Arg('maxPrice')),
|
|
280
|
+
__param(2, TypeGraphQL.Arg('targetPrice')),
|
|
281
|
+
__metadata("design:type", Function),
|
|
282
|
+
__metadata("design:paramtypes", [Number, Number, Number]),
|
|
283
|
+
__metadata("design:returntype", Promise)
|
|
284
|
+
], ValidationExamplesResolver.prototype, "setTradingThresholds", null);
|
|
285
|
+
__decorate([
|
|
286
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
287
|
+
__param(0, TypeGraphQL.Arg('customAllocation')),
|
|
288
|
+
__param(1, TypeGraphQL.Arg('customQuantity')),
|
|
289
|
+
__metadata("design:type", Function),
|
|
290
|
+
__metadata("design:paramtypes", [Number, Number]),
|
|
291
|
+
__metadata("design:returntype", Promise)
|
|
292
|
+
], ValidationExamplesResolver.prototype, "updateCustomSettings", null);
|
|
293
|
+
__decorate([
|
|
294
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
295
|
+
__param(0, TypeGraphQL.Arg('allocations', () => [PortfolioAllocationInput])),
|
|
296
|
+
__metadata("design:type", Function),
|
|
297
|
+
__metadata("design:paramtypes", [Array]),
|
|
298
|
+
__metadata("design:returntype", Promise)
|
|
299
|
+
], ValidationExamplesResolver.prototype, "bulkUpdateAllocations", null);
|
|
300
|
+
exports.ValidationExamplesResolver = ValidationExamplesResolver = __decorate([
|
|
301
|
+
TypeGraphQL.Resolver()
|
|
302
|
+
], ValidationExamplesResolver);
|
|
303
|
+
/**
|
|
304
|
+
* Example: Reusable validation functions for complex business rules
|
|
305
|
+
*/
|
|
306
|
+
class CustomValidators {
|
|
307
|
+
/**
|
|
308
|
+
* Validates that portfolio allocations sum to 100%
|
|
309
|
+
*/
|
|
310
|
+
static validatePortfolioAllocationSum(equities, options, crypto) {
|
|
311
|
+
const total = equities + options + crypto;
|
|
312
|
+
if (Math.abs(total - 100) > 0.01) {
|
|
313
|
+
// Allow small floating point errors
|
|
314
|
+
throw new input_validator_1.ValidationError('Invalid portfolio allocation', [
|
|
315
|
+
{
|
|
316
|
+
field: 'totalAllocation',
|
|
317
|
+
value: total,
|
|
318
|
+
message: 'Total allocation must equal 100%',
|
|
319
|
+
constraint: 'sum',
|
|
320
|
+
},
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Validates that a price is within acceptable market bounds
|
|
326
|
+
*/
|
|
327
|
+
static validateMarketPrice(price, fieldName) {
|
|
328
|
+
(0, input_validator_1.validatePositiveNumber)(price, fieldName);
|
|
329
|
+
// Additional market-specific validation
|
|
330
|
+
if (price > 1000000) {
|
|
331
|
+
throw new input_validator_1.ValidationError('Price exceeds maximum', [
|
|
332
|
+
{
|
|
333
|
+
field: fieldName,
|
|
334
|
+
value: price,
|
|
335
|
+
message: 'Price cannot exceed $1,000,000',
|
|
336
|
+
constraint: 'maximum',
|
|
337
|
+
},
|
|
338
|
+
]);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Validates Greeks values are within expected ranges
|
|
343
|
+
*/
|
|
344
|
+
static validateGreeks(delta, gamma, theta, vega) {
|
|
345
|
+
(0, input_validator_1.validateFields)([
|
|
346
|
+
() => {
|
|
347
|
+
if (delta < -1 || delta > 1) {
|
|
348
|
+
throw new input_validator_1.ValidationError('Invalid delta', [
|
|
349
|
+
{
|
|
350
|
+
field: 'delta',
|
|
351
|
+
value: delta,
|
|
352
|
+
message: 'Delta must be between -1 and 1',
|
|
353
|
+
constraint: 'range',
|
|
354
|
+
},
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
() => {
|
|
359
|
+
if (gamma < 0) {
|
|
360
|
+
throw new input_validator_1.ValidationError('Invalid gamma', [
|
|
361
|
+
{
|
|
362
|
+
field: 'gamma',
|
|
363
|
+
value: gamma,
|
|
364
|
+
message: 'Gamma must be non-negative',
|
|
365
|
+
constraint: 'minimum',
|
|
366
|
+
},
|
|
367
|
+
]);
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
() => {
|
|
371
|
+
if (theta > 0) {
|
|
372
|
+
throw new input_validator_1.ValidationError('Invalid theta', [
|
|
373
|
+
{
|
|
374
|
+
field: 'theta',
|
|
375
|
+
value: theta,
|
|
376
|
+
message: 'Theta must be negative or zero',
|
|
377
|
+
constraint: 'maximum',
|
|
378
|
+
},
|
|
379
|
+
]);
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
() => {
|
|
383
|
+
if (vega < 0) {
|
|
384
|
+
throw new input_validator_1.ValidationError('Invalid vega', [
|
|
385
|
+
{
|
|
386
|
+
field: 'vega',
|
|
387
|
+
value: vega,
|
|
388
|
+
message: 'Vega must be non-negative',
|
|
389
|
+
constraint: 'minimum',
|
|
390
|
+
},
|
|
391
|
+
]);
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
]);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
exports.CustomValidators = CustomValidators;
|
|
398
|
+
//# sourceMappingURL=validation-examples.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example usage of validation functions in custom resolvers
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to use the validation utilities
|
|
5
|
+
* in custom resolver implementations.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Example: Portfolio allocation input with validation
|
|
9
|
+
*/
|
|
10
|
+
declare class PortfolioAllocationInput {
|
|
11
|
+
equitiesPct: number;
|
|
12
|
+
optionsPct: number;
|
|
13
|
+
cryptoPct: number;
|
|
14
|
+
portfolioName: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Example: Trade configuration input with validation
|
|
18
|
+
*/
|
|
19
|
+
declare class TradeConfigurationInput {
|
|
20
|
+
tradeAllocationPct: number;
|
|
21
|
+
minPercentageChange: number;
|
|
22
|
+
volumeThreshold: number;
|
|
23
|
+
quantity: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Example resolver demonstrating manual validation in custom resolvers
|
|
27
|
+
*
|
|
28
|
+
* Note: With the validation plugin enabled, these validations happen
|
|
29
|
+
* automatically. This example shows how to add ADDITIONAL custom validation
|
|
30
|
+
* logic beyond the automatic pattern-based validation.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ValidationExamplesResolver {
|
|
33
|
+
/**
|
|
34
|
+
* Example 1: Basic field validation in a mutation
|
|
35
|
+
*/
|
|
36
|
+
updatePortfolioAllocation(input: PortfolioAllocationInput): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Example 2: Batch validation using validateFields
|
|
39
|
+
*/
|
|
40
|
+
updateTradeConfiguration(input: TradeConfigurationInput): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Example 3: Conditional validation based on business logic
|
|
43
|
+
*/
|
|
44
|
+
createTrade(quantity: number, isPremiumUser: boolean): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Example 4: Validating related fields together
|
|
47
|
+
*/
|
|
48
|
+
setTradingThresholds(minPrice: number, maxPrice: number, targetPrice: number): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Example 5: Using manual validation for non-standard field names
|
|
51
|
+
*/
|
|
52
|
+
updateCustomSettings(customAllocation: number, customQuantity: number): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Example 6: Accumulating multiple validation errors
|
|
55
|
+
*/
|
|
56
|
+
bulkUpdateAllocations(allocations: PortfolioAllocationInput[]): Promise<boolean>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Example: Reusable validation functions for complex business rules
|
|
60
|
+
*/
|
|
61
|
+
export declare class CustomValidators {
|
|
62
|
+
/**
|
|
63
|
+
* Validates that portfolio allocations sum to 100%
|
|
64
|
+
*/
|
|
65
|
+
static validatePortfolioAllocationSum(equities: number, options: number, crypto: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Validates that a price is within acceptable market bounds
|
|
68
|
+
*/
|
|
69
|
+
static validateMarketPrice(price: number, fieldName: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Validates Greeks values are within expected ranges
|
|
72
|
+
*/
|
|
73
|
+
static validateGreeks(delta: number, gamma: number, theta: number, vega: number): void;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=validation-examples.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptic/backend",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1059",
|
|
4
4
|
"description": "Backend executable CRUD functions with dynamic variables construction, and type definitions for the Adaptic AI platform.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -22,12 +22,20 @@
|
|
|
22
22
|
"resolvers/",
|
|
23
23
|
"utils/",
|
|
24
24
|
"validators/",
|
|
25
|
+
"auth/",
|
|
26
|
+
"readers/",
|
|
27
|
+
"config/",
|
|
28
|
+
"middleware/",
|
|
25
29
|
"*.d.ts",
|
|
26
30
|
"*.js",
|
|
27
31
|
"*.cjs",
|
|
28
32
|
"*.mjs",
|
|
29
33
|
"*.ts",
|
|
30
|
-
"!**/*.map"
|
|
34
|
+
"!**/*.map",
|
|
35
|
+
"!**/__tests__/**",
|
|
36
|
+
"!/server.cjs",
|
|
37
|
+
"!/health.cjs",
|
|
38
|
+
"!/config/tracing.cjs"
|
|
31
39
|
],
|
|
32
40
|
"peerDependencies": {
|
|
33
41
|
"@apollo/client": "^3.11.0",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INTRADAY_LANE_PREFS_SELECTION = exports.readIntradayLanePrefs = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Narrow, hand-written reads of fields that the generated selection sets
|
|
6
|
+
* deliberately leave out (`GQL.SKIP`). Each read selects only its own field and
|
|
7
|
+
* the row's identity, so it fails alone and cannot take a generated read down
|
|
8
|
+
* with it.
|
|
9
|
+
*
|
|
10
|
+
* @module readers
|
|
11
|
+
*/
|
|
12
|
+
var intraday_lane_prefs_1 = require("./intraday-lane-prefs.cjs");
|
|
13
|
+
Object.defineProperty(exports, "readIntradayLanePrefs", { enumerable: true, get: function () { return intraday_lane_prefs_1.readIntradayLanePrefs; } });
|
|
14
|
+
Object.defineProperty(exports, "INTRADAY_LANE_PREFS_SELECTION", { enumerable: true, get: function () { return intraday_lane_prefs_1.INTRADAY_LANE_PREFS_SELECTION; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow, hand-written reads of fields that the generated selection sets
|
|
3
|
+
* deliberately leave out (`GQL.SKIP`). Each read selects only its own field and
|
|
4
|
+
* the row's identity, so it fails alone and cannot take a generated read down
|
|
5
|
+
* with it.
|
|
6
|
+
*
|
|
7
|
+
* @module readers
|
|
8
|
+
*/
|
|
9
|
+
export { readIntradayLanePrefs, INTRADAY_LANE_PREFS_SELECTION, type IntradayLanePrefsRow, } from './intraday-lane-prefs';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INTRADAY_LANE_PREFS_SELECTION = void 0;
|
|
4
|
+
exports.readIntradayLanePrefs = readIntradayLanePrefs;
|
|
5
|
+
const client_1 = require("../client.cjs");
|
|
6
|
+
/** The fields this read selects, and nothing else. */
|
|
7
|
+
exports.INTRADAY_LANE_PREFS_SELECTION = 'id alpacaAccountId intradayLanePrefs';
|
|
8
|
+
/** The backend's error message when no TradingPolicy row matches. */
|
|
9
|
+
const NO_POLICY_MESSAGE = 'No TradingPolicy found';
|
|
10
|
+
/** The shape of the `getTradingPolicy` answer this read accepts. */
|
|
11
|
+
function rowOf(value) {
|
|
12
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
13
|
+
throw new Error('readIntradayLanePrefs: the backend answered with no policy object');
|
|
14
|
+
}
|
|
15
|
+
const record = value;
|
|
16
|
+
if (typeof record.id !== 'string' || typeof record.alpacaAccountId !== 'string') {
|
|
17
|
+
throw new Error('readIntradayLanePrefs: the policy answer has no id or alpacaAccountId');
|
|
18
|
+
}
|
|
19
|
+
if (!('intradayLanePrefs' in record) || record.intradayLanePrefs === undefined) {
|
|
20
|
+
throw new Error('readIntradayLanePrefs: the policy answer omits intradayLanePrefs');
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
policyId: record.id,
|
|
24
|
+
alpacaAccountId: record.alpacaAccountId,
|
|
25
|
+
intradayLanePrefs: record.intradayLanePrefs,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read one account's lane preferences.
|
|
30
|
+
*
|
|
31
|
+
* @param alpacaAccountId - The account whose TradingPolicy to read.
|
|
32
|
+
* @param globalClient - The backend client; the shared client when omitted.
|
|
33
|
+
* @returns The stored preferences, or `null` when the account has no
|
|
34
|
+
* TradingPolicy row.
|
|
35
|
+
* @throws When the backend fails, answers with errors (including a server
|
|
36
|
+
* whose schema predates the column), or answers without the field.
|
|
37
|
+
*/
|
|
38
|
+
async function readIntradayLanePrefs(alpacaAccountId, globalClient) {
|
|
39
|
+
var _a;
|
|
40
|
+
const [modules, client] = await Promise.all([
|
|
41
|
+
(0, client_1.getApolloModules)(),
|
|
42
|
+
globalClient ? Promise.resolve(globalClient) : (0, client_1.getApolloClient)(),
|
|
43
|
+
]);
|
|
44
|
+
const query = modules.gql `
|
|
45
|
+
query readIntradayLanePrefs($where: TradingPolicyWhereUniqueInput!) {
|
|
46
|
+
getTradingPolicy(where: $where) {
|
|
47
|
+
${exports.INTRADAY_LANE_PREFS_SELECTION}
|
|
48
|
+
}
|
|
49
|
+
}`;
|
|
50
|
+
let response;
|
|
51
|
+
try {
|
|
52
|
+
response = await client.query({
|
|
53
|
+
query,
|
|
54
|
+
variables: { where: { alpacaAccountId } },
|
|
55
|
+
fetchPolicy: 'network-only',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof Error && error.message === NO_POLICY_MESSAGE)
|
|
60
|
+
return null;
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (response.errors && response.errors.length > 0) {
|
|
64
|
+
if (response.errors[0].message === NO_POLICY_MESSAGE)
|
|
65
|
+
return null;
|
|
66
|
+
throw new Error(`readIntradayLanePrefs: ${response.errors[0].message}`);
|
|
67
|
+
}
|
|
68
|
+
const policy = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getTradingPolicy;
|
|
69
|
+
if (policy === null)
|
|
70
|
+
return null;
|
|
71
|
+
if (policy === undefined) {
|
|
72
|
+
throw new Error('readIntradayLanePrefs: the backend answered with no getTradingPolicy field');
|
|
73
|
+
}
|
|
74
|
+
return rowOf(policy);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=intraday-lane-prefs.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read of one account's multi-lane intraday preferences
|
|
3
|
+
* (`TradingPolicy.intradayLanePrefs`).
|
|
4
|
+
*
|
|
5
|
+
* The field is excluded from every generated selection set (`GQL.SKIP`). A
|
|
6
|
+
* GraphQL server whose schema predates the column rejects the WHOLE operation
|
|
7
|
+
* that selects it, and the generated TradingPolicy and AlpacaAccount selection
|
|
8
|
+
* sets carry the engine's order-chokepoint policy read and its broker-credential
|
|
9
|
+
* read. Leaving the field out of those reads keeps them working against a
|
|
10
|
+
* server whether or not the migration has run. This read is the only place the
|
|
11
|
+
* field is selected, so a server without the column fails this read alone.
|
|
12
|
+
*
|
|
13
|
+
* The read never turns a failure into a value. A transport or GraphQL error
|
|
14
|
+
* throws, and so does an answer that omits the field. Only a backend that
|
|
15
|
+
* answers "no policy row" yields `null`. The consumer (the engine's lane-arming
|
|
16
|
+
* resolver) maps every one of these outcomes to "lanes disarmed". It never
|
|
17
|
+
* blocks an exit, because the preferences govern entries only.
|
|
18
|
+
*
|
|
19
|
+
* @module readers/intraday-lane-prefs
|
|
20
|
+
*/
|
|
21
|
+
import type { TradingPolicy as TradingPolicyType } from '../generated/typegraphql-prisma/models/TradingPolicy';
|
|
22
|
+
import { type ApolloClientType, type NormalizedCacheObject } from '../client';
|
|
23
|
+
/** The fields this read selects, and nothing else. */
|
|
24
|
+
export declare const INTRADAY_LANE_PREFS_SELECTION = "id alpacaAccountId intradayLanePrefs";
|
|
25
|
+
/** One account's lane preferences, as stored. */
|
|
26
|
+
export interface IntradayLanePrefsRow {
|
|
27
|
+
/** The TradingPolicy row id. */
|
|
28
|
+
readonly policyId: string;
|
|
29
|
+
/** The account the policy governs. */
|
|
30
|
+
readonly alpacaAccountId: string;
|
|
31
|
+
/** The stored preferences; `null` when none are set (lanes disarmed). */
|
|
32
|
+
readonly intradayLanePrefs: Exclude<TradingPolicyType['intradayLanePrefs'], undefined>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Read one account's lane preferences.
|
|
36
|
+
*
|
|
37
|
+
* @param alpacaAccountId - The account whose TradingPolicy to read.
|
|
38
|
+
* @param globalClient - The backend client; the shared client when omitted.
|
|
39
|
+
* @returns The stored preferences, or `null` when the account has no
|
|
40
|
+
* TradingPolicy row.
|
|
41
|
+
* @throws When the backend fails, answers with errors (including a server
|
|
42
|
+
* whose schema predates the column), or answers without the field.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readIntradayLanePrefs(alpacaAccountId: string, globalClient?: ApolloClientType<NormalizedCacheObject>): Promise<IntradayLanePrefsRow | null>;
|
|
45
|
+
//# sourceMappingURL=intraday-lane-prefs.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds the GraphQL schema exactly as src/server.ts assembles it (generated
|
|
3
|
-
* resolvers minus server-only models, residual surface stripped) and reports
|
|
4
|
-
* anything of a server-only model that survives.
|
|
5
|
-
*
|
|
6
|
-
* The generated TypeGraphQL resolvers rely on `emitDecoratorMetadata`, which
|
|
7
|
-
* vitest's esbuild transform does not emit, so this runs out of process under
|
|
8
|
-
* ts-node (see src/middleware/__tests__/ts-node-harness.ts). Output is printed
|
|
9
|
-
* between `<<<RESULTS>>>` and `<<<END>>>`.
|
|
10
|
-
*/
|
|
11
|
-
import 'reflect-metadata';
|
|
12
|
-
//# sourceMappingURL=server-only-surface.harness.d.ts.map
|