@0xmonaco/types 0.0.0-develop-20260120180031

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 (134) hide show
  1. package/README.md +391 -0
  2. package/dist/api/index.d.ts +19 -0
  3. package/dist/api/index.d.ts.map +1 -0
  4. package/dist/api/index.js +8 -0
  5. package/dist/api/index.js.map +1 -0
  6. package/dist/applications/index.d.ts +24 -0
  7. package/dist/applications/index.d.ts.map +1 -0
  8. package/dist/applications/index.js +7 -0
  9. package/dist/applications/index.js.map +1 -0
  10. package/dist/applications/responses.d.ts +21 -0
  11. package/dist/applications/responses.d.ts.map +1 -0
  12. package/dist/applications/responses.js +7 -0
  13. package/dist/applications/responses.js.map +1 -0
  14. package/dist/auth/index.d.ts +76 -0
  15. package/dist/auth/index.d.ts.map +1 -0
  16. package/dist/auth/index.js +8 -0
  17. package/dist/auth/index.js.map +1 -0
  18. package/dist/auth/responses.d.ts +68 -0
  19. package/dist/auth/responses.d.ts.map +1 -0
  20. package/dist/auth/responses.js +7 -0
  21. package/dist/auth/responses.js.map +1 -0
  22. package/dist/contracts/balances.d.ts +44 -0
  23. package/dist/contracts/balances.d.ts.map +1 -0
  24. package/dist/contracts/balances.js +7 -0
  25. package/dist/contracts/balances.js.map +1 -0
  26. package/dist/contracts/index.d.ts +28 -0
  27. package/dist/contracts/index.d.ts.map +1 -0
  28. package/dist/contracts/index.js +7 -0
  29. package/dist/contracts/index.js.map +1 -0
  30. package/dist/fees/index.d.ts +40 -0
  31. package/dist/fees/index.d.ts.map +1 -0
  32. package/dist/fees/index.js +7 -0
  33. package/dist/fees/index.js.map +1 -0
  34. package/dist/fees/responses.d.ts +47 -0
  35. package/dist/fees/responses.d.ts.map +1 -0
  36. package/dist/fees/responses.js +62 -0
  37. package/dist/fees/responses.js.map +1 -0
  38. package/dist/index.d.ts +19 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +20 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/market/index.d.ts +224 -0
  43. package/dist/market/index.d.ts.map +1 -0
  44. package/dist/market/index.js +7 -0
  45. package/dist/market/index.js.map +1 -0
  46. package/dist/profile/index.d.ts +228 -0
  47. package/dist/profile/index.d.ts.map +1 -0
  48. package/dist/profile/index.js +7 -0
  49. package/dist/profile/index.js.map +1 -0
  50. package/dist/sdk/index.d.ts +122 -0
  51. package/dist/sdk/index.d.ts.map +1 -0
  52. package/dist/sdk/index.js +2 -0
  53. package/dist/sdk/index.js.map +1 -0
  54. package/dist/sdk/network.d.ts +31 -0
  55. package/dist/sdk/network.d.ts.map +1 -0
  56. package/dist/sdk/network.js +7 -0
  57. package/dist/sdk/network.js.map +1 -0
  58. package/dist/trading/index.d.ts +88 -0
  59. package/dist/trading/index.d.ts.map +1 -0
  60. package/dist/trading/index.js +7 -0
  61. package/dist/trading/index.js.map +1 -0
  62. package/dist/trading/orders.d.ts +108 -0
  63. package/dist/trading/orders.d.ts.map +1 -0
  64. package/dist/trading/orders.js +7 -0
  65. package/dist/trading/orders.js.map +1 -0
  66. package/dist/trading/responses.d.ts +130 -0
  67. package/dist/trading/responses.d.ts.map +1 -0
  68. package/dist/trading/responses.js +7 -0
  69. package/dist/trading/responses.js.map +1 -0
  70. package/dist/validation/common.d.ts +181 -0
  71. package/dist/validation/common.d.ts.map +1 -0
  72. package/dist/validation/common.js +196 -0
  73. package/dist/validation/common.js.map +1 -0
  74. package/dist/validation/index.d.ts +20 -0
  75. package/dist/validation/index.d.ts.map +1 -0
  76. package/dist/validation/index.js +22 -0
  77. package/dist/validation/index.js.map +1 -0
  78. package/dist/validation/market.d.ts +215 -0
  79. package/dist/validation/market.d.ts.map +1 -0
  80. package/dist/validation/market.js +226 -0
  81. package/dist/validation/market.js.map +1 -0
  82. package/dist/validation/trading.d.ts +148 -0
  83. package/dist/validation/trading.d.ts.map +1 -0
  84. package/dist/validation/trading.js +139 -0
  85. package/dist/validation/trading.js.map +1 -0
  86. package/dist/validation/vault.d.ts +62 -0
  87. package/dist/validation/vault.d.ts.map +1 -0
  88. package/dist/validation/vault.js +75 -0
  89. package/dist/validation/vault.js.map +1 -0
  90. package/dist/vault/index.d.ts +64 -0
  91. package/dist/vault/index.d.ts.map +1 -0
  92. package/dist/vault/index.js +7 -0
  93. package/dist/vault/index.js.map +1 -0
  94. package/dist/vault/responses.d.ts +34 -0
  95. package/dist/vault/responses.d.ts.map +1 -0
  96. package/dist/vault/responses.js +7 -0
  97. package/dist/vault/responses.js.map +1 -0
  98. package/dist/websocket/base.d.ts +32 -0
  99. package/dist/websocket/base.d.ts.map +1 -0
  100. package/dist/websocket/base.js +7 -0
  101. package/dist/websocket/base.js.map +1 -0
  102. package/dist/websocket/clients/orderbook-client.d.ts +15 -0
  103. package/dist/websocket/clients/orderbook-client.d.ts.map +1 -0
  104. package/dist/websocket/clients/orderbook-client.js +5 -0
  105. package/dist/websocket/clients/orderbook-client.js.map +1 -0
  106. package/dist/websocket/events/index.d.ts +6 -0
  107. package/dist/websocket/events/index.d.ts.map +1 -0
  108. package/dist/websocket/events/index.js +6 -0
  109. package/dist/websocket/events/index.js.map +1 -0
  110. package/dist/websocket/events/movement-events.d.ts +53 -0
  111. package/dist/websocket/events/movement-events.d.ts.map +1 -0
  112. package/dist/websocket/events/movement-events.js +8 -0
  113. package/dist/websocket/events/movement-events.js.map +1 -0
  114. package/dist/websocket/events/ohlcv-events.d.ts +32 -0
  115. package/dist/websocket/events/ohlcv-events.d.ts.map +1 -0
  116. package/dist/websocket/events/ohlcv-events.js +7 -0
  117. package/dist/websocket/events/ohlcv-events.js.map +1 -0
  118. package/dist/websocket/events/orderbook-events.d.ts +73 -0
  119. package/dist/websocket/events/orderbook-events.d.ts.map +1 -0
  120. package/dist/websocket/events/orderbook-events.js +7 -0
  121. package/dist/websocket/events/orderbook-events.js.map +1 -0
  122. package/dist/websocket/events/orders-events.d.ts +285 -0
  123. package/dist/websocket/events/orders-events.d.ts.map +1 -0
  124. package/dist/websocket/events/orders-events.js +2 -0
  125. package/dist/websocket/events/orders-events.js.map +1 -0
  126. package/dist/websocket/events/trade-events.d.ts +35 -0
  127. package/dist/websocket/events/trade-events.d.ts.map +1 -0
  128. package/dist/websocket/events/trade-events.js +7 -0
  129. package/dist/websocket/events/trade-events.js.map +1 -0
  130. package/dist/websocket/index.d.ts +9 -0
  131. package/dist/websocket/index.d.ts.map +1 -0
  132. package/dist/websocket/index.js +9 -0
  133. package/dist/websocket/index.js.map +1 -0
  134. package/package.json +31 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orders.js","sourceRoot":"","sources":["../../src/trading/orders.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Trading Response Types
3
+ *
4
+ * Response types for trading operations.
5
+ */
6
+ import type { Order, OrderStatus } from "./orders";
7
+ /**
8
+ * Match result information for order execution.
9
+ * Contains detailed information about trades, fills, and execution quality.
10
+ *
11
+ * @remarks
12
+ * This structure is returned after an order is processed by the matching engine,
13
+ * providing details about how the order was executed, including fills, slippage,
14
+ * and final order status.
15
+ */
16
+ export interface MatchResult {
17
+ /** Number of trades executed during matching */
18
+ trades_count: number;
19
+ /** Total quantity filled across all trades (in base currency) */
20
+ total_filled: string;
21
+ /** Remaining unfilled quantity after immediate matches (in base currency) */
22
+ remaining_quantity: string;
23
+ /** Average fill price across all trades (null if no fills occurred) */
24
+ average_fill_price: string | null;
25
+ /** Final order status after matching (e.g., FILLED, PARTIALLY_FILLED, etc.) */
26
+ status: OrderStatus;
27
+ /** Actual slippage experienced in basis points (positive = worse price, null if no fills) */
28
+ actual_slippage_bps: number | null;
29
+ /** Maximum slippage allowed when order was submitted in basis points (null if not set) */
30
+ max_slippage_bps: number | null;
31
+ /** Price range across executed trades (null if no fills) */
32
+ execution_price_range: {
33
+ /** Best (most favorable) execution price achieved */
34
+ best_price: string;
35
+ /** Worst (least favorable) execution price achieved */
36
+ worst_price: string;
37
+ } | null;
38
+ }
39
+ /**
40
+ * Response from creating an order.
41
+ *
42
+ * @remarks
43
+ * Contains the order ID, operation status, and optional match result
44
+ * with details about immediate fills that occurred during order placement.
45
+ */
46
+ export interface CreateOrderResponse {
47
+ /** Created order identifier (UUID) */
48
+ order_id: string;
49
+ /** Operation status (SUCCESS or FAILED) */
50
+ status: "SUCCESS" | "FAILED";
51
+ /** Operation message describing the result (e.g., "Order processed with 2 trades") */
52
+ message: string;
53
+ /** Match result information if order was processed by matching engine */
54
+ match_result?: MatchResult;
55
+ }
56
+ /**
57
+ * Response from cancelling an order.
58
+ */
59
+ export interface CancelOrderResponse {
60
+ /** Order identifier */
61
+ order_id: string;
62
+ /** Cancellation status */
63
+ status: "SUCCESS" | "FAILED";
64
+ /** Optional response message */
65
+ message?: string;
66
+ }
67
+ /**
68
+ * Response from replacing an order.
69
+ */
70
+ export interface ReplaceOrderResponse {
71
+ /** New order identifier (after replacement) */
72
+ order_id: string;
73
+ /** Replace operation status */
74
+ status: "SUCCESS" | "FAILED";
75
+ /** Operation message */
76
+ message: string;
77
+ /** Fields that were updated */
78
+ updated_fields: UpdatedFields;
79
+ /** Original order identifier that was replaced */
80
+ original_order_id?: string;
81
+ /** Match result information for the new order */
82
+ match_result?: MatchResult;
83
+ }
84
+ /**
85
+ * Fields that were updated in the replace operation
86
+ */
87
+ export interface UpdatedFields {
88
+ /** Updated price (if changed) */
89
+ price?: string;
90
+ /** Updated quantity (if changed) */
91
+ quantity?: string;
92
+ }
93
+ /**
94
+ * Query parameters for getting paginated orders
95
+ */
96
+ export interface GetPaginatedOrdersParams {
97
+ /** Filter by order status */
98
+ status?: OrderStatus;
99
+ /** Filter by trading pair */
100
+ trading_pair?: string;
101
+ /** Page number for pagination (default: 1) */
102
+ page?: number;
103
+ /** Number of orders per page (default: 10, max: 100) */
104
+ page_size?: number;
105
+ }
106
+ /**
107
+ * Response from getting paginated orders
108
+ */
109
+ export interface GetPaginatedOrdersResponse {
110
+ /** Array of orders */
111
+ orders: Order[];
112
+ /** Total number of orders matching the query */
113
+ total: number;
114
+ /** Current page number */
115
+ page: number;
116
+ /** Number of orders per page */
117
+ page_size: number;
118
+ /** Total number of pages */
119
+ total_pages: number;
120
+ }
121
+ /**
122
+ * Response from getting a single order by ID
123
+ */
124
+ export interface GetOrderResponse {
125
+ /** Order data */
126
+ order: Order;
127
+ /** Request status */
128
+ status: "SUCCESS" | "FAILED";
129
+ }
130
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/trading/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,+EAA+E;IAC/E,MAAM,EAAE,WAAW,CAAC;IACpB,6FAA6F;IAC7F,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,0FAA0F;IAC1F,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,4DAA4D;IAC5D,qBAAqB,EAAE;QACrB,qDAAqD;QACrD,UAAU,EAAE,MAAM,CAAC;QACnB,uDAAuD;QACvD,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,IAAI,CAAC;CACV;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,cAAc,EAAE,aAAa,CAAC;IAC9B,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iDAAiD;IACjD,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,6BAA6B;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,6BAA6B;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,sBAAsB;IACtB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,qBAAqB;IACrB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC9B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Trading Response Types
3
+ *
4
+ * Response types for trading operations.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/trading/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Common Validation Utilities
3
+ *
4
+ * Shared utilities for runtime validation across all SDK modules.
5
+ * These utilities work with any Zod schema and provide consistent
6
+ * error handling throughout the SDK.
7
+ */
8
+ import type { z } from "zod";
9
+ /**
10
+ * Validation error class for user-friendly error messages.
11
+ *
12
+ * Wraps Zod validation errors to provide better error formatting and
13
+ * structured error access for API consumers. This error is thrown when
14
+ * validation fails on any SDK parameters.
15
+ *
16
+ * **Features:**
17
+ * - Human-readable error message with field paths
18
+ * - Access to raw Zod issues for detailed error handling
19
+ * - Structured error object via `getErrors()` method
20
+ *
21
+ * **Example Usage:**
22
+ * ```typescript
23
+ * import { validate, PlaceLimitOrderSchema } from '@0xmonaco/types';
24
+ *
25
+ * try {
26
+ * const validated = validate(PlaceLimitOrderSchema, {
27
+ * tradingPairId: "invalid-uuid",
28
+ * side: "BUY",
29
+ * quantity: "-10", // Invalid: negative
30
+ * price: "100"
31
+ * });
32
+ * } catch (error) {
33
+ * if (error instanceof ValidationError) {
34
+ * // Human-readable message
35
+ * console.log(error.message);
36
+ * // "Validation failed:
37
+ * // - tradingPairId: Invalid uuid
38
+ * // - quantity: Number must be greater than 0"
39
+ *
40
+ * // Structured errors for form validation
41
+ * const errors = error.getErrors();
42
+ * console.log(errors);
43
+ * // {
44
+ * // "tradingPairId": "Invalid uuid",
45
+ * // "quantity": "Number must be greater than 0"
46
+ * // }
47
+ *
48
+ * // Raw Zod issues for advanced handling
49
+ * console.log(error.issues);
50
+ * // [{ path: ["tradingPairId"], message: "Invalid uuid", ... }, ...]
51
+ * }
52
+ * }
53
+ * ```
54
+ *
55
+ * @see {@link validate} - Helper function that throws ValidationError
56
+ */
57
+ export declare class ValidationError extends Error {
58
+ /**
59
+ * Array of Zod validation issues containing detailed error information.
60
+ * Each issue includes the field path, error code, and message.
61
+ */
62
+ readonly issues: z.ZodIssue[];
63
+ /**
64
+ * Creates a new ValidationError from a Zod validation error.
65
+ *
66
+ * Automatically formats all validation issues into a human-readable
67
+ * message and stores the raw issues for programmatic access.
68
+ *
69
+ * @param zodError - The Zod validation error to wrap
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const result = schema.safeParse(data);
74
+ * if (!result.success) {
75
+ * throw new ValidationError(result.error);
76
+ * }
77
+ * ```
78
+ */
79
+ constructor(zodError: z.ZodError);
80
+ /**
81
+ * Get validation errors as a structured object for easy field-level error display.
82
+ *
83
+ * Converts the array of Zod issues into a simple key-value object where
84
+ * keys are field paths (dot-notation) and values are error messages.
85
+ * Root-level errors (no path) are stored under the "root" key.
86
+ *
87
+ * **Use Cases:**
88
+ * - Form validation (map errors to input fields)
89
+ * - API error responses (structured JSON)
90
+ * - Error aggregation and reporting
91
+ *
92
+ * @returns Object mapping field paths to error messages
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Single field error
97
+ * error.getErrors();
98
+ * // { "price": "Number must be greater than 0" }
99
+ *
100
+ * // Multiple field errors
101
+ * error.getErrors();
102
+ * // {
103
+ * // "tradingPairId": "Invalid uuid",
104
+ * // "quantity": "Required",
105
+ * // "options.timeInForce": "Invalid enum value"
106
+ * // }
107
+ *
108
+ * // Root-level error (no specific field)
109
+ * error.getErrors();
110
+ * // { "root": "At least one field is required" }
111
+ *
112
+ * // Use in React form
113
+ * const errors = validationError.getErrors();
114
+ * <input error={errors.price} />
115
+ * ```
116
+ */
117
+ getErrors(): Record<string, string>;
118
+ }
119
+ /**
120
+ * Validates data against a Zod schema and throws user-friendly errors on failure.
121
+ *
122
+ * This is a convenience wrapper around Zod's `safeParse` that automatically
123
+ * throws a {@link ValidationError} with formatted error messages when validation fails.
124
+ *
125
+ * **When to Use:**
126
+ * - Validating user input before API calls
127
+ * - Runtime type checking for dynamic data
128
+ * - Ensuring data integrity before processing
129
+ *
130
+ * **Error Handling:**
131
+ * On validation failure, throws {@link ValidationError} which provides:
132
+ * - Human-readable error message
133
+ * - Structured errors via `getErrors()`
134
+ * - Raw Zod issues for advanced handling
135
+ *
136
+ * @template T - The expected type after validation
137
+ * @param schema - Zod schema to validate against
138
+ * @param data - Data to validate (unknown type for safety)
139
+ * @returns Validated and typed data
140
+ * @throws {@link ValidationError} When validation fails
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * import { validate, PlaceLimitOrderSchema } from '@0xmonaco/types';
145
+ *
146
+ * // Basic validation
147
+ * try {
148
+ * const validatedOrder = validate(PlaceLimitOrderSchema, userInput);
149
+ * // validatedOrder is now typed and guaranteed valid
150
+ * await sdk.trading.placeLimitOrder(...validatedOrder);
151
+ * } catch (error) {
152
+ * if (error instanceof ValidationError) {
153
+ * // Show user-friendly errors
154
+ * console.error(error.message);
155
+ * const fieldErrors = error.getErrors();
156
+ * // Display errors next to form fields
157
+ * }
158
+ * }
159
+ *
160
+ * // With custom error handling
161
+ * function safeValidate<T>(schema: z.ZodSchema<T>, data: unknown) {
162
+ * try {
163
+ * return { success: true, data: validate(schema, data) };
164
+ * } catch (error) {
165
+ * if (error instanceof ValidationError) {
166
+ * return { success: false, errors: error.getErrors() };
167
+ * }
168
+ * throw error; // Re-throw unexpected errors
169
+ * }
170
+ * }
171
+ *
172
+ * const result = safeValidate(PlaceLimitOrderSchema, input);
173
+ * if (result.success) {
174
+ * // Use result.data
175
+ * } else {
176
+ * // Handle result.errors
177
+ * }
178
+ * ```
179
+ */
180
+ export declare function validate<T>(schema: z.ZodSchema<T>, data: unknown): T;
181
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/validation/common.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC;;;OAGG;IACH,SAAgB,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAErC;;;;;;;;;;;;;;;OAeG;gBACS,QAAQ,EAAE,CAAC,CAAC,QAAQ;IAWhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAQpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,CAAC,CAQpE"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Common Validation Utilities
3
+ *
4
+ * Shared utilities for runtime validation across all SDK modules.
5
+ * These utilities work with any Zod schema and provide consistent
6
+ * error handling throughout the SDK.
7
+ */
8
+ /**
9
+ * Validation error class for user-friendly error messages.
10
+ *
11
+ * Wraps Zod validation errors to provide better error formatting and
12
+ * structured error access for API consumers. This error is thrown when
13
+ * validation fails on any SDK parameters.
14
+ *
15
+ * **Features:**
16
+ * - Human-readable error message with field paths
17
+ * - Access to raw Zod issues for detailed error handling
18
+ * - Structured error object via `getErrors()` method
19
+ *
20
+ * **Example Usage:**
21
+ * ```typescript
22
+ * import { validate, PlaceLimitOrderSchema } from '@0xmonaco/types';
23
+ *
24
+ * try {
25
+ * const validated = validate(PlaceLimitOrderSchema, {
26
+ * tradingPairId: "invalid-uuid",
27
+ * side: "BUY",
28
+ * quantity: "-10", // Invalid: negative
29
+ * price: "100"
30
+ * });
31
+ * } catch (error) {
32
+ * if (error instanceof ValidationError) {
33
+ * // Human-readable message
34
+ * console.log(error.message);
35
+ * // "Validation failed:
36
+ * // - tradingPairId: Invalid uuid
37
+ * // - quantity: Number must be greater than 0"
38
+ *
39
+ * // Structured errors for form validation
40
+ * const errors = error.getErrors();
41
+ * console.log(errors);
42
+ * // {
43
+ * // "tradingPairId": "Invalid uuid",
44
+ * // "quantity": "Number must be greater than 0"
45
+ * // }
46
+ *
47
+ * // Raw Zod issues for advanced handling
48
+ * console.log(error.issues);
49
+ * // [{ path: ["tradingPairId"], message: "Invalid uuid", ... }, ...]
50
+ * }
51
+ * }
52
+ * ```
53
+ *
54
+ * @see {@link validate} - Helper function that throws ValidationError
55
+ */
56
+ export class ValidationError extends Error {
57
+ /**
58
+ * Creates a new ValidationError from a Zod validation error.
59
+ *
60
+ * Automatically formats all validation issues into a human-readable
61
+ * message and stores the raw issues for programmatic access.
62
+ *
63
+ * @param zodError - The Zod validation error to wrap
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const result = schema.safeParse(data);
68
+ * if (!result.success) {
69
+ * throw new ValidationError(result.error);
70
+ * }
71
+ * ```
72
+ */
73
+ constructor(zodError) {
74
+ const messages = zodError.issues.map((issue) => {
75
+ const path = issue.path.join(".");
76
+ return `${path ? `${path}: ` : ""}${issue.message}`;
77
+ });
78
+ super(`Validation failed:\n - ${messages.join("\n - ")}`);
79
+ this.name = "ValidationError";
80
+ this.issues = zodError.issues;
81
+ }
82
+ /**
83
+ * Get validation errors as a structured object for easy field-level error display.
84
+ *
85
+ * Converts the array of Zod issues into a simple key-value object where
86
+ * keys are field paths (dot-notation) and values are error messages.
87
+ * Root-level errors (no path) are stored under the "root" key.
88
+ *
89
+ * **Use Cases:**
90
+ * - Form validation (map errors to input fields)
91
+ * - API error responses (structured JSON)
92
+ * - Error aggregation and reporting
93
+ *
94
+ * @returns Object mapping field paths to error messages
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Single field error
99
+ * error.getErrors();
100
+ * // { "price": "Number must be greater than 0" }
101
+ *
102
+ * // Multiple field errors
103
+ * error.getErrors();
104
+ * // {
105
+ * // "tradingPairId": "Invalid uuid",
106
+ * // "quantity": "Required",
107
+ * // "options.timeInForce": "Invalid enum value"
108
+ * // }
109
+ *
110
+ * // Root-level error (no specific field)
111
+ * error.getErrors();
112
+ * // { "root": "At least one field is required" }
113
+ *
114
+ * // Use in React form
115
+ * const errors = validationError.getErrors();
116
+ * <input error={errors.price} />
117
+ * ```
118
+ */
119
+ getErrors() {
120
+ const errors = {};
121
+ for (const issue of this.issues) {
122
+ const path = issue.path.join(".");
123
+ errors[path || "root"] = issue.message;
124
+ }
125
+ return errors;
126
+ }
127
+ }
128
+ /**
129
+ * Validates data against a Zod schema and throws user-friendly errors on failure.
130
+ *
131
+ * This is a convenience wrapper around Zod's `safeParse` that automatically
132
+ * throws a {@link ValidationError} with formatted error messages when validation fails.
133
+ *
134
+ * **When to Use:**
135
+ * - Validating user input before API calls
136
+ * - Runtime type checking for dynamic data
137
+ * - Ensuring data integrity before processing
138
+ *
139
+ * **Error Handling:**
140
+ * On validation failure, throws {@link ValidationError} which provides:
141
+ * - Human-readable error message
142
+ * - Structured errors via `getErrors()`
143
+ * - Raw Zod issues for advanced handling
144
+ *
145
+ * @template T - The expected type after validation
146
+ * @param schema - Zod schema to validate against
147
+ * @param data - Data to validate (unknown type for safety)
148
+ * @returns Validated and typed data
149
+ * @throws {@link ValidationError} When validation fails
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * import { validate, PlaceLimitOrderSchema } from '@0xmonaco/types';
154
+ *
155
+ * // Basic validation
156
+ * try {
157
+ * const validatedOrder = validate(PlaceLimitOrderSchema, userInput);
158
+ * // validatedOrder is now typed and guaranteed valid
159
+ * await sdk.trading.placeLimitOrder(...validatedOrder);
160
+ * } catch (error) {
161
+ * if (error instanceof ValidationError) {
162
+ * // Show user-friendly errors
163
+ * console.error(error.message);
164
+ * const fieldErrors = error.getErrors();
165
+ * // Display errors next to form fields
166
+ * }
167
+ * }
168
+ *
169
+ * // With custom error handling
170
+ * function safeValidate<T>(schema: z.ZodSchema<T>, data: unknown) {
171
+ * try {
172
+ * return { success: true, data: validate(schema, data) };
173
+ * } catch (error) {
174
+ * if (error instanceof ValidationError) {
175
+ * return { success: false, errors: error.getErrors() };
176
+ * }
177
+ * throw error; // Re-throw unexpected errors
178
+ * }
179
+ * }
180
+ *
181
+ * const result = safeValidate(PlaceLimitOrderSchema, input);
182
+ * if (result.success) {
183
+ * // Use result.data
184
+ * } else {
185
+ * // Handle result.errors
186
+ * }
187
+ * ```
188
+ */
189
+ export function validate(schema, data) {
190
+ const result = schema.safeParse(data);
191
+ if (!result.success) {
192
+ throw new ValidationError(result.error);
193
+ }
194
+ return result.data;
195
+ }
196
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/validation/common.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAOxC;;;;;;;;;;;;;;;OAeG;IACH,YAAY,QAAoB;QAC9B,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC7C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,2BAA2B,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,SAAS;QACP,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;QACzC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,UAAU,QAAQ,CAAI,MAAsB,EAAE,IAAa;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAEtC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Validation Schemas
3
+ *
4
+ * Runtime validation using Zod for all SDK inputs.
5
+ * Catches errors before making API calls.
6
+ *
7
+ * **Shared Utilities:**
8
+ * - {@link ValidationError} - User-friendly validation error class
9
+ * - {@link validate} - Helper function for schema validation
10
+ *
11
+ * **Schema Modules:**
12
+ * - Trading schemas (orders, trading pairs)
13
+ * - Vault schemas (deposits, withdrawals)
14
+ * - Market schemas (trading pairs, candlesticks)
15
+ */
16
+ export * from "./common.js";
17
+ export * from "./market.js";
18
+ export * from "./trading.js";
19
+ export * from "./vault.js";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,cAAc,aAAa,CAAC;AAE5B,cAAc,aAAa,CAAC;AAE5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validation Schemas
3
+ *
4
+ * Runtime validation using Zod for all SDK inputs.
5
+ * Catches errors before making API calls.
6
+ *
7
+ * **Shared Utilities:**
8
+ * - {@link ValidationError} - User-friendly validation error class
9
+ * - {@link validate} - Helper function for schema validation
10
+ *
11
+ * **Schema Modules:**
12
+ * - Trading schemas (orders, trading pairs)
13
+ * - Vault schemas (deposits, withdrawals)
14
+ * - Market schemas (trading pairs, candlesticks)
15
+ */
16
+ // Export validation utilities
17
+ export * from "./common.js";
18
+ export * from "./market.js";
19
+ // Export module-specific schemas
20
+ export * from "./trading.js";
21
+ export * from "./vault.js";
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,8BAA8B;AAC9B,cAAc,aAAa,CAAC;AAE5B,cAAc,aAAa,CAAC;AAC5B,iCAAiC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}