@adaptic/backend-legacy 0.0.44 → 0.0.45
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/Allocation.cjs +19 -0
- package/esm/Allocation.d.ts.map +1 -1
- package/esm/Allocation.js.map +1 -1
- package/esm/Allocation.mjs +19 -0
- package/esm/config/jwtConfig.d.ts +16 -0
- package/esm/config/jwtConfig.d.ts.map +1 -0
- package/esm/config/jwtConfig.js.map +1 -0
- package/esm/config/jwtConfig.mjs +47 -0
- package/esm/generated/typegraphql-prisma/models/Trade.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/models/Trade.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/models/Trade.js.map +1 -1
- package/esm/generated/typegraphql-prisma/models/Trade.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.mjs +2 -2
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.mjs +1 -1
- package/esm/getToken.d.ts.map +1 -1
- package/esm/getToken.js.map +1 -1
- package/esm/getToken.mjs +2 -1
- package/esm/middleware/auth.d.ts.map +1 -1
- package/esm/middleware/auth.js.map +1 -1
- package/esm/middleware/auth.mjs +8 -8
- package/esm/middleware/graphql-validation-plugin.d.ts +37 -0
- package/esm/middleware/graphql-validation-plugin.d.ts.map +1 -0
- package/esm/middleware/graphql-validation-plugin.js.map +1 -0
- package/esm/middleware/graphql-validation-plugin.mjs +163 -0
- package/esm/middleware/index.d.ts +12 -0
- package/esm/middleware/index.d.ts.map +1 -0
- package/esm/middleware/index.js.map +1 -0
- package/esm/middleware/index.mjs +16 -0
- package/esm/middleware/input-validator.d.ts +63 -0
- package/esm/middleware/input-validator.d.ts.map +1 -0
- package/esm/middleware/input-validator.js.map +1 -0
- package/esm/middleware/input-validator.mjs +210 -0
- package/esm/middleware/rate-limiter.d.ts +12 -0
- package/esm/middleware/rate-limiter.d.ts.map +1 -0
- package/esm/middleware/rate-limiter.js.map +1 -0
- package/esm/middleware/rate-limiter.mjs +68 -0
- package/esm/middleware/types.d.ts +87 -0
- package/esm/middleware/types.d.ts.map +1 -0
- package/esm/middleware/types.js.map +1 -0
- package/esm/middleware/types.mjs +13 -0
- package/esm/middleware/validation-examples.d.ts +76 -0
- package/esm/middleware/validation-examples.d.ts.map +1 -0
- package/esm/middleware/validation-examples.js.map +1 -0
- package/esm/middleware/validation-examples.mjs +373 -0
- package/esm/plugins/error-sanitizer.d.ts +37 -0
- package/esm/plugins/error-sanitizer.d.ts.map +1 -0
- package/esm/plugins/error-sanitizer.js.map +1 -0
- package/esm/plugins/error-sanitizer.mjs +184 -0
- package/esm/plugins/index.d.ts +8 -0
- package/esm/plugins/index.d.ts.map +1 -0
- package/esm/plugins/index.js.map +1 -0
- package/esm/plugins/index.mjs +8 -0
- package/esm/plugins/integration-example.d.ts +53 -0
- package/esm/plugins/integration-example.d.ts.map +1 -0
- package/esm/plugins/integration-example.js.map +1 -0
- package/esm/plugins/integration-example.mjs +88 -0
- package/esm/plugins/query-depth-limiter.d.ts +47 -0
- package/esm/plugins/query-depth-limiter.d.ts.map +1 -0
- package/esm/plugins/query-depth-limiter.js.map +1 -0
- package/esm/plugins/query-depth-limiter.mjs +146 -0
- package/esm/validators/allocation-validator.d.ts +32 -0
- package/esm/validators/allocation-validator.d.ts.map +1 -0
- package/esm/validators/allocation-validator.js.map +1 -0
- package/esm/validators/allocation-validator.mjs +80 -0
- package/generated/typegraphql-prisma/models/Trade.cjs +1 -1
- package/generated/typegraphql-prisma/models/Trade.d.ts +1 -1
- package/generated/typegraphql-prisma/models/Trade.d.ts.map +1 -1
- package/generated/typegraphql-prisma/models/Trade.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.cjs +2 -2
- package/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/User/args/CreateOneUserArgs.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateManyInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeCreateWithoutActionsInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeScalarWhereWithAggregatesInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateManyMutationInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeUpdateWithoutActionsInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/TradeWhereUniqueInput.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTrade.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeGroupBy.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMaxAggregate.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/outputs/TradeMinAggregate.js.map +1 -1
- package/getToken.cjs +2 -1
- package/package.json +1 -1
- package/server.cjs +35 -17
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for validation middleware
|
|
3
|
+
*/
|
|
4
|
+
import { GraphQLError } from 'graphql';
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if an error is a ValidationError
|
|
7
|
+
*/
|
|
8
|
+
export function isValidationError(error) {
|
|
9
|
+
return (error instanceof GraphQLError &&
|
|
10
|
+
error.extensions?.code === 'BAD_USER_INPUT' &&
|
|
11
|
+
'validationErrors' in (error.extensions || {}));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-examples.d.ts","sourceRoot":"","sources":["../../../src/middleware/validation-examples.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,cACM,wBAAwB;IAE5B,WAAW,EAAG,MAAM,CAAC;IAGrB,UAAU,EAAG,MAAM,CAAC;IAGpB,SAAS,EAAG,MAAM,CAAC;IAGnB,aAAa,EAAG,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,cACM,uBAAuB;IAE3B,kBAAkB,EAAG,MAAM,CAAC;IAG5B,mBAAmB,EAAG,MAAM,CAAC;IAG7B,eAAe,EAAG,MAAM,CAAC;IAGzB,QAAQ,EAAG,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,qBACa,0BAA0B;IACrC;;OAEG;IAEG,yBAAyB,CACH,KAAK,EAAE,wBAAwB,GACxD,OAAO,CAAC,OAAO,CAAC;IAwBnB;;OAEG;IAEG,wBAAwB,CACF,KAAK,EAAE,uBAAuB,GACvD,OAAO,CAAC,OAAO,CAAC;IA6BnB;;OAEG;IAEG,WAAW,CACc,QAAQ,EAAE,MAAM,EACX,aAAa,EAAE,OAAO,GACvD,OAAO,CAAC,OAAO,CAAC;IAmBnB;;OAEG;IAEG,oBAAoB,CACK,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClD,OAAO,CAAC,OAAO,CAAC;IA8BnB;;OAEG;IAEG,oBAAoB,CACa,gBAAgB,EAAE,MAAM,EAC1B,cAAc,EAAE,MAAM,GACxD,OAAO,CAAC,OAAO,CAAC;IAUnB;;OAEG;IAEG,qBAAqB,CAEzB,WAAW,EAAE,wBAAwB,EAAE,GACtC,OAAO,CAAC,OAAO,CAAC;CA+BpB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;IACH,MAAM,CAAC,8BAA8B,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,IAAI;IAcP;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAgBlE;;OAEG;IACH,MAAM,CAAC,cAAc,CACnB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,IAAI;CAoDR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-examples.js","sourceRoot":"","sources":["../../../src/middleware/validation-examples.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;;;;;;;;;;;;AAEH,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEtB,cAAc,EACd,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AAEH,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAE5B,WAAW,CAAU;IAGrB,UAAU,CAAU;IAGpB,SAAS,CAAU;IAGnB,aAAa,CAAU;CACxB,CAAA;AAVC;IADC,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;;6DACtB;AAGrB;IADC,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;;4DACvB;AAGpB;IADC,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;;2DACxB;AAGnB;IADC,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;+DACT;AAXnB,wBAAwB;IAD7B,WAA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ACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,GAAG,EAAE;gBACH,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;oBACd,MAAM,IAAI,eAAe,CAAC,eAAe,EAAE;wBACzC;4BACE,KAAK,EAAE,OAAO;4BACd,KAAK,EAAE,KAAK;4BACZ,OAAO,EAAE,4BAA4B;4BACrC,UAAU,EAAE,SAAS;yBACtB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,GAAG,EAAE;gBACH,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;oBACd,MAAM,IAAI,eAAe,CAAC,eAAe,EAAE;wBACzC;4BACE,KAAK,EAAE,OAAO;4BACd,KAAK,EAAE,KAAK;4BACZ,OAAO,EAAE,gCAAgC;4BACzC,UAAU,EAAE,SAAS;yBACtB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,GAAG,EAAE;gBACH,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;oBACb,MAAM,IAAI,eAAe,CAAC,cAAc,EAAE;wBACxC;4BACE,KAAK,EAAE,MAAM;4BACb,KAAK,EAAE,IAAI;4BACX,OAAO,EAAE,2BAA2B;4BACpC,UAAU,EAAE,SAAS;yBACtB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,373 @@
|
|
|
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
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
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;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
};
|
|
13
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
17
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
18
|
+
};
|
|
19
|
+
import * as TypeGraphQL from 'type-graphql';
|
|
20
|
+
import { validatePercentage, validatePositiveNumber, validateFields, ValidationError, } from './input-validator.mjs';
|
|
21
|
+
/**
|
|
22
|
+
* Example: Portfolio allocation input with validation
|
|
23
|
+
*/
|
|
24
|
+
let PortfolioAllocationInput = class PortfolioAllocationInput {
|
|
25
|
+
equitiesPct;
|
|
26
|
+
optionsPct;
|
|
27
|
+
cryptoPct;
|
|
28
|
+
portfolioName;
|
|
29
|
+
};
|
|
30
|
+
__decorate([
|
|
31
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], PortfolioAllocationInput.prototype, "equitiesPct", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
36
|
+
__metadata("design:type", Number)
|
|
37
|
+
], PortfolioAllocationInput.prototype, "optionsPct", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], PortfolioAllocationInput.prototype, "cryptoPct", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
TypeGraphQL.Field(() => String),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], PortfolioAllocationInput.prototype, "portfolioName", void 0);
|
|
46
|
+
PortfolioAllocationInput = __decorate([
|
|
47
|
+
TypeGraphQL.InputType()
|
|
48
|
+
], PortfolioAllocationInput);
|
|
49
|
+
/**
|
|
50
|
+
* Example: Trade configuration input with validation
|
|
51
|
+
*/
|
|
52
|
+
let TradeConfigurationInput = class TradeConfigurationInput {
|
|
53
|
+
tradeAllocationPct;
|
|
54
|
+
minPercentageChange;
|
|
55
|
+
volumeThreshold;
|
|
56
|
+
quantity;
|
|
57
|
+
};
|
|
58
|
+
__decorate([
|
|
59
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
60
|
+
__metadata("design:type", Number)
|
|
61
|
+
], TradeConfigurationInput.prototype, "tradeAllocationPct", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
64
|
+
__metadata("design:type", Number)
|
|
65
|
+
], TradeConfigurationInput.prototype, "minPercentageChange", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
68
|
+
__metadata("design:type", Number)
|
|
69
|
+
], TradeConfigurationInput.prototype, "volumeThreshold", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
TypeGraphQL.Field(() => TypeGraphQL.Int),
|
|
72
|
+
__metadata("design:type", Number)
|
|
73
|
+
], TradeConfigurationInput.prototype, "quantity", void 0);
|
|
74
|
+
TradeConfigurationInput = __decorate([
|
|
75
|
+
TypeGraphQL.InputType()
|
|
76
|
+
], TradeConfigurationInput);
|
|
77
|
+
/**
|
|
78
|
+
* Example resolver demonstrating manual validation in custom resolvers
|
|
79
|
+
*
|
|
80
|
+
* Note: With the validation plugin enabled, these validations happen
|
|
81
|
+
* automatically. This example shows how to add ADDITIONAL custom validation
|
|
82
|
+
* logic beyond the automatic pattern-based validation.
|
|
83
|
+
*/
|
|
84
|
+
let ValidationExamplesResolver = class ValidationExamplesResolver {
|
|
85
|
+
/**
|
|
86
|
+
* Example 1: Basic field validation in a mutation
|
|
87
|
+
*/
|
|
88
|
+
async updatePortfolioAllocation(input) {
|
|
89
|
+
// The validation plugin will automatically validate:
|
|
90
|
+
// - equitiesPct (0-100)
|
|
91
|
+
// - optionsPct (0-100)
|
|
92
|
+
// - cryptoPct (0-100)
|
|
93
|
+
// - portfolioName (non-empty)
|
|
94
|
+
// Add custom business logic validation
|
|
95
|
+
const totalAllocation = input.equitiesPct + input.optionsPct + input.cryptoPct;
|
|
96
|
+
if (totalAllocation !== 100) {
|
|
97
|
+
throw new ValidationError('Total allocation must equal 100%', [
|
|
98
|
+
{
|
|
99
|
+
field: 'totalAllocation',
|
|
100
|
+
value: totalAllocation,
|
|
101
|
+
message: 'Sum of equitiesPct, optionsPct, and cryptoPct must equal 100',
|
|
102
|
+
constraint: 'sum',
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
// Resolver implementation...
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Example 2: Batch validation using validateFields
|
|
111
|
+
*/
|
|
112
|
+
async updateTradeConfiguration(input) {
|
|
113
|
+
// The validation plugin handles basic validation automatically.
|
|
114
|
+
// Use validateFields for additional custom validations.
|
|
115
|
+
try {
|
|
116
|
+
validateFields([
|
|
117
|
+
// Custom validation: minPercentageChange should be less than tradeAllocationPct
|
|
118
|
+
() => {
|
|
119
|
+
if (input.minPercentageChange >= input.tradeAllocationPct) {
|
|
120
|
+
throw new ValidationError('Invalid configuration', [
|
|
121
|
+
{
|
|
122
|
+
field: 'minPercentageChange',
|
|
123
|
+
value: input.minPercentageChange,
|
|
124
|
+
message: 'Must be less than tradeAllocationPct',
|
|
125
|
+
constraint: 'comparison',
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
// ValidationError is automatically formatted by Apollo Server
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
// Resolver implementation...
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Example 3: Conditional validation based on business logic
|
|
141
|
+
*/
|
|
142
|
+
async createTrade(quantity, isPremiumUser) {
|
|
143
|
+
// Basic validation happens automatically via plugin
|
|
144
|
+
// Add conditional validation based on user type
|
|
145
|
+
if (!isPremiumUser && quantity > 1000) {
|
|
146
|
+
throw new ValidationError('Quantity limit exceeded', [
|
|
147
|
+
{
|
|
148
|
+
field: 'quantity',
|
|
149
|
+
value: quantity,
|
|
150
|
+
message: 'Non-premium users are limited to 1000 units per trade',
|
|
151
|
+
constraint: 'userLimit',
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
}
|
|
155
|
+
// Resolver implementation...
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Example 4: Validating related fields together
|
|
160
|
+
*/
|
|
161
|
+
async setTradingThresholds(minPrice, maxPrice, targetPrice) {
|
|
162
|
+
// Automatic validation ensures all are positive numbers
|
|
163
|
+
// Custom validation for related fields
|
|
164
|
+
if (minPrice >= maxPrice) {
|
|
165
|
+
throw new ValidationError('Invalid price range', [
|
|
166
|
+
{
|
|
167
|
+
field: 'minPrice',
|
|
168
|
+
value: minPrice,
|
|
169
|
+
message: 'minPrice must be less than maxPrice',
|
|
170
|
+
constraint: 'range',
|
|
171
|
+
},
|
|
172
|
+
]);
|
|
173
|
+
}
|
|
174
|
+
if (targetPrice < minPrice || targetPrice > maxPrice) {
|
|
175
|
+
throw new ValidationError('Invalid target price', [
|
|
176
|
+
{
|
|
177
|
+
field: 'targetPrice',
|
|
178
|
+
value: targetPrice,
|
|
179
|
+
message: 'targetPrice must be between minPrice and maxPrice',
|
|
180
|
+
constraint: 'range',
|
|
181
|
+
},
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
// Resolver implementation...
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Example 5: Using manual validation for non-standard field names
|
|
189
|
+
*/
|
|
190
|
+
async updateCustomSettings(customAllocation, customQuantity) {
|
|
191
|
+
// These field names don't match the automatic validation patterns,
|
|
192
|
+
// so we validate manually
|
|
193
|
+
validatePercentage(customAllocation, 'customAllocation');
|
|
194
|
+
validatePositiveNumber(customQuantity, 'customQuantity');
|
|
195
|
+
// Resolver implementation...
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Example 6: Accumulating multiple validation errors
|
|
200
|
+
*/
|
|
201
|
+
async bulkUpdateAllocations(allocations) {
|
|
202
|
+
// Validate each allocation
|
|
203
|
+
// The plugin validates each item's fields automatically
|
|
204
|
+
// Add custom cross-item validation
|
|
205
|
+
const totalItems = allocations.length;
|
|
206
|
+
if (totalItems === 0) {
|
|
207
|
+
throw new ValidationError('Empty allocations array', [
|
|
208
|
+
{
|
|
209
|
+
field: 'allocations',
|
|
210
|
+
value: totalItems,
|
|
211
|
+
message: 'Must provide at least one allocation',
|
|
212
|
+
constraint: 'notEmpty',
|
|
213
|
+
},
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
if (totalItems > 100) {
|
|
217
|
+
throw new ValidationError('Too many allocations', [
|
|
218
|
+
{
|
|
219
|
+
field: 'allocations',
|
|
220
|
+
value: totalItems,
|
|
221
|
+
message: 'Maximum 100 allocations per request',
|
|
222
|
+
constraint: 'maxLength',
|
|
223
|
+
},
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
// Resolver implementation...
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
__decorate([
|
|
231
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
232
|
+
__param(0, TypeGraphQL.Arg('input')),
|
|
233
|
+
__metadata("design:type", Function),
|
|
234
|
+
__metadata("design:paramtypes", [PortfolioAllocationInput]),
|
|
235
|
+
__metadata("design:returntype", Promise)
|
|
236
|
+
], ValidationExamplesResolver.prototype, "updatePortfolioAllocation", null);
|
|
237
|
+
__decorate([
|
|
238
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
239
|
+
__param(0, TypeGraphQL.Arg('input')),
|
|
240
|
+
__metadata("design:type", Function),
|
|
241
|
+
__metadata("design:paramtypes", [TradeConfigurationInput]),
|
|
242
|
+
__metadata("design:returntype", Promise)
|
|
243
|
+
], ValidationExamplesResolver.prototype, "updateTradeConfiguration", null);
|
|
244
|
+
__decorate([
|
|
245
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
246
|
+
__param(0, TypeGraphQL.Arg('quantity')),
|
|
247
|
+
__param(1, TypeGraphQL.Arg('isPremiumUser')),
|
|
248
|
+
__metadata("design:type", Function),
|
|
249
|
+
__metadata("design:paramtypes", [Number, Boolean]),
|
|
250
|
+
__metadata("design:returntype", Promise)
|
|
251
|
+
], ValidationExamplesResolver.prototype, "createTrade", null);
|
|
252
|
+
__decorate([
|
|
253
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
254
|
+
__param(0, TypeGraphQL.Arg('minPrice')),
|
|
255
|
+
__param(1, TypeGraphQL.Arg('maxPrice')),
|
|
256
|
+
__param(2, TypeGraphQL.Arg('targetPrice')),
|
|
257
|
+
__metadata("design:type", Function),
|
|
258
|
+
__metadata("design:paramtypes", [Number, Number, Number]),
|
|
259
|
+
__metadata("design:returntype", Promise)
|
|
260
|
+
], ValidationExamplesResolver.prototype, "setTradingThresholds", null);
|
|
261
|
+
__decorate([
|
|
262
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
263
|
+
__param(0, TypeGraphQL.Arg('customAllocation')),
|
|
264
|
+
__param(1, TypeGraphQL.Arg('customQuantity')),
|
|
265
|
+
__metadata("design:type", Function),
|
|
266
|
+
__metadata("design:paramtypes", [Number, Number]),
|
|
267
|
+
__metadata("design:returntype", Promise)
|
|
268
|
+
], ValidationExamplesResolver.prototype, "updateCustomSettings", null);
|
|
269
|
+
__decorate([
|
|
270
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
271
|
+
__param(0, TypeGraphQL.Arg('allocations', () => [PortfolioAllocationInput])),
|
|
272
|
+
__metadata("design:type", Function),
|
|
273
|
+
__metadata("design:paramtypes", [Array]),
|
|
274
|
+
__metadata("design:returntype", Promise)
|
|
275
|
+
], ValidationExamplesResolver.prototype, "bulkUpdateAllocations", null);
|
|
276
|
+
ValidationExamplesResolver = __decorate([
|
|
277
|
+
TypeGraphQL.Resolver()
|
|
278
|
+
], ValidationExamplesResolver);
|
|
279
|
+
export { ValidationExamplesResolver };
|
|
280
|
+
/**
|
|
281
|
+
* Example: Reusable validation functions for complex business rules
|
|
282
|
+
*/
|
|
283
|
+
export class CustomValidators {
|
|
284
|
+
/**
|
|
285
|
+
* Validates that portfolio allocations sum to 100%
|
|
286
|
+
*/
|
|
287
|
+
static validatePortfolioAllocationSum(equities, options, crypto) {
|
|
288
|
+
const total = equities + options + crypto;
|
|
289
|
+
if (Math.abs(total - 100) > 0.01) { // Allow small floating point errors
|
|
290
|
+
throw new ValidationError('Invalid portfolio allocation', [
|
|
291
|
+
{
|
|
292
|
+
field: 'totalAllocation',
|
|
293
|
+
value: total,
|
|
294
|
+
message: 'Total allocation must equal 100%',
|
|
295
|
+
constraint: 'sum',
|
|
296
|
+
},
|
|
297
|
+
]);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Validates that a price is within acceptable market bounds
|
|
302
|
+
*/
|
|
303
|
+
static validateMarketPrice(price, fieldName) {
|
|
304
|
+
validatePositiveNumber(price, fieldName);
|
|
305
|
+
// Additional market-specific validation
|
|
306
|
+
if (price > 1000000) {
|
|
307
|
+
throw new ValidationError('Price exceeds maximum', [
|
|
308
|
+
{
|
|
309
|
+
field: fieldName,
|
|
310
|
+
value: price,
|
|
311
|
+
message: 'Price cannot exceed $1,000,000',
|
|
312
|
+
constraint: 'maximum',
|
|
313
|
+
},
|
|
314
|
+
]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Validates Greeks values are within expected ranges
|
|
319
|
+
*/
|
|
320
|
+
static validateGreeks(delta, gamma, theta, vega) {
|
|
321
|
+
validateFields([
|
|
322
|
+
() => {
|
|
323
|
+
if (delta < -1 || delta > 1) {
|
|
324
|
+
throw new ValidationError('Invalid delta', [
|
|
325
|
+
{
|
|
326
|
+
field: 'delta',
|
|
327
|
+
value: delta,
|
|
328
|
+
message: 'Delta must be between -1 and 1',
|
|
329
|
+
constraint: 'range',
|
|
330
|
+
},
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
() => {
|
|
335
|
+
if (gamma < 0) {
|
|
336
|
+
throw new ValidationError('Invalid gamma', [
|
|
337
|
+
{
|
|
338
|
+
field: 'gamma',
|
|
339
|
+
value: gamma,
|
|
340
|
+
message: 'Gamma must be non-negative',
|
|
341
|
+
constraint: 'minimum',
|
|
342
|
+
},
|
|
343
|
+
]);
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
() => {
|
|
347
|
+
if (theta > 0) {
|
|
348
|
+
throw new ValidationError('Invalid theta', [
|
|
349
|
+
{
|
|
350
|
+
field: 'theta',
|
|
351
|
+
value: theta,
|
|
352
|
+
message: 'Theta must be negative or zero',
|
|
353
|
+
constraint: 'maximum',
|
|
354
|
+
},
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
() => {
|
|
359
|
+
if (vega < 0) {
|
|
360
|
+
throw new ValidationError('Invalid vega', [
|
|
361
|
+
{
|
|
362
|
+
field: 'vega',
|
|
363
|
+
value: vega,
|
|
364
|
+
message: 'Vega must be non-negative',
|
|
365
|
+
constraint: 'minimum',
|
|
366
|
+
},
|
|
367
|
+
]);
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
]);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
//# sourceMappingURL=validation-examples.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Sanitizer for Apollo Server
|
|
3
|
+
*
|
|
4
|
+
* This module provides error formatting that:
|
|
5
|
+
* - Sanitizes internal errors in production
|
|
6
|
+
* - Preserves validation errors (safe to show)
|
|
7
|
+
* - Logs full error details server-side
|
|
8
|
+
* - Includes request IDs for debugging
|
|
9
|
+
*
|
|
10
|
+
* Integration:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createErrorSanitizer } from './plugins/error-sanitizer';
|
|
14
|
+
*
|
|
15
|
+
* const server = new ApolloServer({
|
|
16
|
+
* schema,
|
|
17
|
+
* formatError: createErrorSanitizer(),
|
|
18
|
+
* // ... other options
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Configuration:
|
|
23
|
+
* - Automatically detects NODE_ENV for production vs development mode
|
|
24
|
+
* - In production: sanitizes internal errors, keeps validation errors
|
|
25
|
+
* - In development: shows full error details
|
|
26
|
+
*/
|
|
27
|
+
import { GraphQLFormattedError } from 'graphql';
|
|
28
|
+
/**
|
|
29
|
+
* Creates an error formatter function for Apollo Server
|
|
30
|
+
*/
|
|
31
|
+
export declare function createErrorSanitizer(): (formattedError: GraphQLFormattedError, error: unknown) => GraphQLFormattedError;
|
|
32
|
+
/**
|
|
33
|
+
* Alternative: Export a pre-configured formatter
|
|
34
|
+
* Use this if you don't need to customize the behavior
|
|
35
|
+
*/
|
|
36
|
+
export declare const formatError: (formattedError: GraphQLFormattedError, error: unknown) => GraphQLFormattedError;
|
|
37
|
+
//# sourceMappingURL=error-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-sanitizer.d.ts","sourceRoot":"","sources":["../../../src/plugins/error-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAgB,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAqJ9D;;GAEG;AACH,wBAAgB,o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