@coinbase-sample/prime-sdk-ts 0.8.0 → 0.8.2
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/dist/activities/index.js +14 -0
- package/dist/addressBooks/index.js +10 -0
- package/dist/allocations/index.js +12 -0
- package/dist/assets/index.js +4 -0
- package/dist/balances/index.js +15 -0
- package/dist/commission/index.js +4 -0
- package/dist/constants.js +1 -1
- package/dist/financing/index.js +52 -0
- package/dist/futures/index.js +33 -0
- package/dist/index.js +7 -1
- package/dist/invoices/index.js +4 -0
- package/dist/model/GetStakingStatusResponse.js +21 -0
- package/dist/model/StakingStatus.js +21 -0
- package/dist/model/SubmitDepositTravelRuleDataResponse.js +21 -0
- package/dist/model/TravelRuleData.js +21 -0
- package/dist/model/ValidatorStakingInfo.js +21 -0
- package/dist/model/enums/StakeType.js +28 -0
- package/dist/model/enums/index.js +4 -2
- package/dist/model/googleTypeDate.js +21 -0
- package/dist/model/requestToSubmitTravelRuleDataForAnExistingDepositTransaction.js +21 -0
- package/dist/onchainAddressBook/index.js +14 -0
- package/dist/orders/index.js +59 -0
- package/dist/paymentMethods/index.js +8 -0
- package/dist/portfolios/index.js +10 -0
- package/dist/positions/index.js +7 -0
- package/dist/products/index.js +11 -0
- package/dist/shared/__tests__/validation.test.js +184 -124
- package/dist/shared/validation.js +90 -260
- package/dist/staking/index.js +55 -0
- package/dist/transactions/index.js +58 -0
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/model/Balance.d.ts +4 -0
- package/dist/types/model/CreatePortfolioAddressBookEntryRequest.d.ts +0 -2
- package/dist/types/model/CreateWalletWithdrawalRequest.d.ts +2 -0
- package/dist/types/model/GetStakingStatusResponse.d.ts +42 -0
- package/dist/types/model/StakingStatus.d.ts +39 -0
- package/dist/types/model/SubmitDepositTravelRuleDataResponse.d.ts +22 -0
- package/dist/types/model/TravelRuleData.d.ts +37 -0
- package/dist/types/model/TravelRuleParty.d.ts +19 -4
- package/dist/types/model/ValidatorStakingInfo.d.ts +30 -0
- package/dist/types/model/enums/StakeType.d.ts +24 -0
- package/dist/types/model/enums/index.d.ts +1 -0
- package/dist/types/model/googleTypeDate.d.ts +36 -0
- package/dist/types/model/index.d.ts +7 -0
- package/dist/types/model/requestToSubmitTravelRuleDataForAnExistingDepositTransaction.d.ts +26 -0
- package/dist/types/orders/types.d.ts +1 -1
- package/dist/types/shared/validation.d.ts +19 -107
- package/dist/types/staking/index.d.ts +3 -1
- package/dist/types/staking/types.d.ts +6 -1
- package/dist/types/transactions/index.d.ts +3 -1
- package/dist/types/transactions/types.d.ts +6 -1
- package/dist/types/wallets/types.d.ts +1 -1
- package/dist/users/index.js +7 -0
- package/dist/wallets/index.js +27 -0
- package/package.json +6 -2
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PropertyValidator =
|
|
3
|
+
exports.PropertyValidator = void 0;
|
|
4
4
|
exports.isValidUUID = isValidUUID;
|
|
5
|
-
exports.validateRequiredUUID = validateRequiredUUID;
|
|
6
|
-
exports.validateOptionalUUID = validateOptionalUUID;
|
|
7
|
-
exports.validateRequiredString = validateRequiredString;
|
|
8
|
-
exports.validateOptionalString = validateOptionalString;
|
|
9
|
-
exports.createValidator = createValidator;
|
|
10
5
|
exports.validate = validate;
|
|
11
6
|
/**
|
|
12
7
|
* Copyright 2025-present Coinbase Global, Inc.
|
|
@@ -26,332 +21,169 @@ exports.validate = validate;
|
|
|
26
21
|
const errors_1 = require("../errors");
|
|
27
22
|
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
28
23
|
/**
|
|
29
|
-
*
|
|
24
|
+
* Validates that a string is a valid UUID v4 format
|
|
30
25
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
function isValidUUID(value) {
|
|
27
|
+
return UUID_REGEX.test(value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a validator with property accessor support for automatic field name inference.
|
|
31
|
+
*
|
|
32
|
+
* @param source - The source object containing the fields to validate
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* validate(request)
|
|
37
|
+
* .requiredUUID(r => r.portfolioId)
|
|
38
|
+
* .requiredUUID(r => r.orderId)
|
|
39
|
+
* .check();
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function validate(source) {
|
|
43
|
+
return new PropertyValidator(source);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validator with property accessor support for automatic field name inference.
|
|
47
|
+
* Uses Proxy to track property accesses and extract field names automatically.
|
|
48
|
+
*/
|
|
49
|
+
class PropertyValidator {
|
|
50
|
+
constructor(source) {
|
|
33
51
|
this.errors = [];
|
|
52
|
+
this.source = source;
|
|
34
53
|
}
|
|
35
54
|
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
addError(paramName, message, value) {
|
|
39
|
-
this.errors.push({ paramName, message, value });
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Check if there are any validation errors
|
|
43
|
-
*/
|
|
44
|
-
hasErrors() {
|
|
45
|
-
return this.errors.length > 0;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get all validation errors
|
|
49
|
-
*/
|
|
50
|
-
getErrors() {
|
|
51
|
-
return [...this.errors];
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Validates that a required UUID parameter is present and valid.
|
|
55
|
-
* Returns this for method chaining.
|
|
55
|
+
* Validates that a required UUID field is present and valid.
|
|
56
|
+
* Automatically extracts the field name from the property accessor.
|
|
56
57
|
*
|
|
57
58
|
* @example
|
|
58
59
|
* ```typescript
|
|
59
|
-
*
|
|
60
|
-
* .
|
|
61
|
-
* .validateRequiredUUID(request.orderId, 'orderId')
|
|
60
|
+
* validate(request)
|
|
61
|
+
* .requiredUUID(r => r.portfolioId)
|
|
62
62
|
* .check();
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
requiredUUID(accessor) {
|
|
66
|
+
const { propertyName, value } = this.extractProperty(accessor);
|
|
66
67
|
if (value === undefined || value === null || value === '') {
|
|
67
|
-
this.addError(
|
|
68
|
+
this.addError(propertyName, 'is required and cannot be empty', value);
|
|
68
69
|
return this;
|
|
69
70
|
}
|
|
70
71
|
const trimmedValue = typeof value === 'string' ? value.trim() : value;
|
|
71
72
|
if (trimmedValue === '') {
|
|
72
|
-
this.addError(
|
|
73
|
+
this.addError(propertyName, 'cannot be empty or whitespace only', value);
|
|
73
74
|
return this;
|
|
74
75
|
}
|
|
75
76
|
if (!isValidUUID(trimmedValue)) {
|
|
76
|
-
this.addError(
|
|
77
|
+
this.addError(propertyName, 'must be a valid UUID', value);
|
|
77
78
|
}
|
|
78
79
|
return this;
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
|
-
* Validates that an optional UUID
|
|
82
|
-
* Returns this for method chaining.
|
|
82
|
+
* Validates that an optional UUID field is valid if provided.
|
|
83
83
|
*/
|
|
84
|
-
|
|
84
|
+
optionalUUID(accessor) {
|
|
85
|
+
const { propertyName, value } = this.extractProperty(accessor);
|
|
85
86
|
if (value === undefined || value === null || value === '') {
|
|
86
|
-
return this;
|
|
87
|
+
return this;
|
|
87
88
|
}
|
|
88
89
|
const trimmedValue = typeof value === 'string' ? value.trim() : value;
|
|
89
90
|
if (trimmedValue !== '' && !isValidUUID(trimmedValue)) {
|
|
90
|
-
this.addError(
|
|
91
|
+
this.addError(propertyName, 'must be a valid UUID if provided', value);
|
|
91
92
|
}
|
|
92
93
|
return this;
|
|
93
94
|
}
|
|
94
95
|
/**
|
|
95
|
-
* Validates that a required string
|
|
96
|
-
* Returns this for method chaining.
|
|
96
|
+
* Validates that a required string field is present and not empty.
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
requiredString(accessor) {
|
|
99
|
+
const { propertyName, value } = this.extractProperty(accessor);
|
|
99
100
|
if (value === undefined || value === null || value === '') {
|
|
100
|
-
this.addError(
|
|
101
|
+
this.addError(propertyName, 'is required and cannot be empty', value);
|
|
101
102
|
return this;
|
|
102
103
|
}
|
|
103
104
|
const trimmedValue = typeof value === 'string' ? value.trim() : value;
|
|
104
105
|
if (trimmedValue === '') {
|
|
105
|
-
this.addError(
|
|
106
|
+
this.addError(propertyName, 'cannot be empty or whitespace only', value);
|
|
106
107
|
}
|
|
107
108
|
return this;
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
|
-
* Validates that an optional string
|
|
111
|
-
* Returns this for method chaining.
|
|
111
|
+
* Validates that an optional string field is not empty if provided.
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
optionalString(accessor) {
|
|
114
|
+
const { propertyName, value } = this.extractProperty(accessor);
|
|
114
115
|
if (value === undefined || value === null) {
|
|
115
|
-
return this;
|
|
116
|
+
return this;
|
|
116
117
|
}
|
|
117
118
|
if (typeof value === 'string') {
|
|
118
119
|
const trimmedValue = value.trim();
|
|
119
120
|
if (value !== '' && trimmedValue === '') {
|
|
120
|
-
this.addError(
|
|
121
|
+
this.addError(propertyName, 'cannot be whitespace only if provided', value);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
return this;
|
|
124
125
|
}
|
|
125
126
|
/**
|
|
126
|
-
*
|
|
127
|
-
* Automatically detects the calling method name if no context is provided.
|
|
128
|
-
*
|
|
129
|
-
* @param contextMessage - Optional context message. If not provided, attempts to detect method name.
|
|
130
|
-
* @throws {CoinbasePrimeClientException} if there are validation errors
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* const validator = createValidator();
|
|
135
|
-
* validateRequiredUUID(validator, request.id, 'id');
|
|
136
|
-
* validator.throwIfInvalid(); // Automatically detects calling method
|
|
137
|
-
* ```
|
|
127
|
+
* Validates that a required array field is present and not empty.
|
|
138
128
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const valueInfo = err.value !== undefined ? ` (received: '${err.value}')` : '';
|
|
144
|
-
return ` - ${err.paramName}: ${err.message}${valueInfo}`;
|
|
145
|
-
})
|
|
146
|
-
.join('\n');
|
|
147
|
-
const prefix = contextMessage || this.getCallerContext();
|
|
148
|
-
throw new errors_1.CoinbasePrimeClientException(`${prefix}:\n${errorDetails}`);
|
|
129
|
+
requiredArray(accessor) {
|
|
130
|
+
const { propertyName, value } = this.extractProperty(accessor);
|
|
131
|
+
if (value === undefined || value === null) {
|
|
132
|
+
this.addError(propertyName, 'is required', value);
|
|
149
133
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
* Alias for throwIfInvalid() - more natural for fluent/builder pattern.
|
|
153
|
-
* Throw an exception if there are validation errors.
|
|
154
|
-
*
|
|
155
|
-
* @param contextMessage - Optional context message. If not provided, attempts to detect method name.
|
|
156
|
-
* @throws {CoinbasePrimeClientException} if there are validation errors
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```typescript
|
|
160
|
-
* validator
|
|
161
|
-
* .validateRequiredUUID(request.portfolioId, 'portfolioId')
|
|
162
|
-
* .validateRequiredUUID(request.orderId, 'orderId')
|
|
163
|
-
* .check(); // ✅ Fluent pattern
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
check(contextMessage) {
|
|
167
|
-
this.throwIfInvalid(contextMessage);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Attempts to extract the calling method name from the stack trace.
|
|
171
|
-
* This provides automatic context for validation errors.
|
|
172
|
-
* Falls back to 'Request validation failed' if method name cannot be determined.
|
|
173
|
-
*/
|
|
174
|
-
getCallerContext() {
|
|
175
|
-
try {
|
|
176
|
-
const stack = new Error().stack;
|
|
177
|
-
if (stack) {
|
|
178
|
-
// Parse stack to find the calling method
|
|
179
|
-
const lines = stack.split('\n');
|
|
180
|
-
// Stack trace format:
|
|
181
|
-
// Line 0: Error
|
|
182
|
-
// Line 1: getCallerContext
|
|
183
|
-
// Line 2: throwIfInvalid
|
|
184
|
-
// Line 3: actual calling method (e.g., getOrder, listOnchainAddressBook)
|
|
185
|
-
const callerLine = lines[3];
|
|
186
|
-
// Try to match various stack trace formats
|
|
187
|
-
// Format: "at ClassName.methodName" or "at methodName" or "methodName@file.ts"
|
|
188
|
-
let match = callerLine.match(/at (?:\w+\.)?(\w+)/);
|
|
189
|
-
if (!match) {
|
|
190
|
-
// Try Firefox/Safari format: methodName@file.ts:line:col
|
|
191
|
-
match = callerLine.match(/^(\w+)@/);
|
|
192
|
-
}
|
|
193
|
-
if (match && match[1]) {
|
|
194
|
-
const methodName = match[1];
|
|
195
|
-
// Filter out common internal/utility method names
|
|
196
|
-
if (!['async', 'Function', 'Object'].includes(methodName)) {
|
|
197
|
-
return `${methodName} request validation failed`;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
134
|
+
else if (!Array.isArray(value)) {
|
|
135
|
+
this.addError(propertyName, 'must be an array', value);
|
|
201
136
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// This might happen in different JavaScript engines or minified code
|
|
137
|
+
else if (value.length === 0) {
|
|
138
|
+
this.addError(propertyName, 'must not be an empty array', value);
|
|
205
139
|
}
|
|
206
|
-
return 'Request validation failed';
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.ValidationResult = ValidationResult;
|
|
210
|
-
/**
|
|
211
|
-
* Validates that a string is a valid UUID v4 format
|
|
212
|
-
*/
|
|
213
|
-
function isValidUUID(value) {
|
|
214
|
-
return UUID_REGEX.test(value);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Validates that a required UUID parameter is present and valid
|
|
218
|
-
*/
|
|
219
|
-
function validateRequiredUUID(validator, value, paramName) {
|
|
220
|
-
if (value === undefined || value === null || value === '') {
|
|
221
|
-
validator.addError(paramName, 'is required and cannot be empty', value);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
const trimmedValue = typeof value === 'string' ? value.trim() : value;
|
|
225
|
-
if (trimmedValue === '') {
|
|
226
|
-
validator.addError(paramName, 'cannot be empty or whitespace only', value);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (!isValidUUID(trimmedValue)) {
|
|
230
|
-
validator.addError(paramName, 'must be a valid UUID', value);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Validates that an optional UUID parameter is valid if provided
|
|
235
|
-
*/
|
|
236
|
-
function validateOptionalUUID(validator, value, paramName) {
|
|
237
|
-
if (value === undefined || value === null || value === '') {
|
|
238
|
-
return; // Optional, so undefined/null/empty is valid
|
|
239
|
-
}
|
|
240
|
-
const trimmedValue = typeof value === 'string' ? value.trim() : value;
|
|
241
|
-
if (trimmedValue !== '' && !isValidUUID(trimmedValue)) {
|
|
242
|
-
validator.addError(paramName, 'must be a valid UUID if provided', value);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Validates that a required string parameter is present and not empty
|
|
247
|
-
*/
|
|
248
|
-
function validateRequiredString(validator, value, paramName) {
|
|
249
|
-
if (value === undefined || value === null || value === '') {
|
|
250
|
-
validator.addError(paramName, 'is required and cannot be empty', value);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const trimmedValue = typeof value === 'string' ? value.trim() : value;
|
|
254
|
-
if (trimmedValue === '') {
|
|
255
|
-
validator.addError(paramName, 'cannot be empty or whitespace only', value);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Validates that an optional string parameter is not empty if provided
|
|
260
|
-
*/
|
|
261
|
-
function validateOptionalString(validator, value, paramName) {
|
|
262
|
-
if (value === undefined || value === null) {
|
|
263
|
-
return; // Optional, so undefined/null is valid
|
|
264
|
-
}
|
|
265
|
-
if (typeof value === 'string') {
|
|
266
|
-
const trimmedValue = value.trim();
|
|
267
|
-
if (value !== '' && trimmedValue === '') {
|
|
268
|
-
validator.addError(paramName, 'cannot be whitespace only if provided', value);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Convenience function to create a new ValidationResult
|
|
274
|
-
*/
|
|
275
|
-
function createValidator() {
|
|
276
|
-
return new ValidationResult();
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Creates a validator with property accessor support for automatic field name inference.
|
|
280
|
-
*
|
|
281
|
-
* @param source - The source object containing the fields to validate
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```typescript
|
|
285
|
-
* validate(request)
|
|
286
|
-
* .requiredUUID(r => r.portfolioId)
|
|
287
|
-
* .requiredUUID(r => r.orderId)
|
|
288
|
-
* .check();
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
|
-
function validate(source) {
|
|
292
|
-
return new PropertyValidator(source);
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Validator with property accessor support for automatic field name inference.
|
|
296
|
-
* Uses Proxy to track property accesses and extract field names automatically.
|
|
297
|
-
*/
|
|
298
|
-
class PropertyValidator {
|
|
299
|
-
constructor(source) {
|
|
300
|
-
this.validator = new ValidationResult();
|
|
301
|
-
this.source = source;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Validates that a required UUID field is present and valid.
|
|
305
|
-
* Automatically extracts the field name from the property accessor.
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* ```typescript
|
|
309
|
-
* validate(request)
|
|
310
|
-
* .requiredUUID(r => r.portfolioId)
|
|
311
|
-
* .check();
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
requiredUUID(accessor) {
|
|
315
|
-
const { propertyName, value } = this.extractProperty(accessor);
|
|
316
|
-
this.validator.validateRequiredUUID(value, propertyName);
|
|
317
140
|
return this;
|
|
318
141
|
}
|
|
319
142
|
/**
|
|
320
|
-
* Validates that
|
|
143
|
+
* Validates that a required boolean field is present.
|
|
321
144
|
*/
|
|
322
|
-
|
|
145
|
+
requiredBoolean(accessor) {
|
|
323
146
|
const { propertyName, value } = this.extractProperty(accessor);
|
|
324
|
-
|
|
147
|
+
if (value === undefined || value === null) {
|
|
148
|
+
this.addError(propertyName, 'is required', value);
|
|
149
|
+
}
|
|
150
|
+
else if (typeof value !== 'boolean') {
|
|
151
|
+
this.addError(propertyName, 'must be a boolean', value);
|
|
152
|
+
}
|
|
325
153
|
return this;
|
|
326
154
|
}
|
|
327
155
|
/**
|
|
328
|
-
*
|
|
156
|
+
* Throws if there are validation errors.
|
|
329
157
|
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
158
|
+
check(contextMessage) {
|
|
159
|
+
if (this.errors.length > 0) {
|
|
160
|
+
const errorDetails = this.errors
|
|
161
|
+
.map((err) => {
|
|
162
|
+
const valueInfo = err.value !== undefined ? ` (received: '${err.value}')` : '';
|
|
163
|
+
return ` - ${err.paramName}: ${err.message}${valueInfo}`;
|
|
164
|
+
})
|
|
165
|
+
.join('\n');
|
|
166
|
+
const prefix = contextMessage || 'Request validation failed';
|
|
167
|
+
throw new errors_1.CoinbasePrimeClientException(`${prefix}:\n${errorDetails}`);
|
|
168
|
+
}
|
|
334
169
|
}
|
|
335
170
|
/**
|
|
336
|
-
*
|
|
171
|
+
* Add a validation error
|
|
337
172
|
*/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
this.validator.validateOptionalString(value, propertyName);
|
|
341
|
-
return this;
|
|
173
|
+
addError(paramName, message, value) {
|
|
174
|
+
this.errors.push({ paramName, message, value });
|
|
342
175
|
}
|
|
343
176
|
/**
|
|
344
|
-
*
|
|
345
|
-
* Automatically detects the calling method name.
|
|
177
|
+
* Check if there are any validation errors
|
|
346
178
|
*/
|
|
347
|
-
|
|
348
|
-
this.
|
|
179
|
+
hasErrors() {
|
|
180
|
+
return this.errors.length > 0;
|
|
349
181
|
}
|
|
350
182
|
/**
|
|
351
|
-
*
|
|
183
|
+
* Get all validation errors
|
|
352
184
|
*/
|
|
353
|
-
|
|
354
|
-
this.
|
|
185
|
+
getErrors() {
|
|
186
|
+
return [...this.errors];
|
|
355
187
|
}
|
|
356
188
|
/**
|
|
357
189
|
* Extracts the property name and value from a property accessor function.
|
|
@@ -359,7 +191,6 @@ class PropertyValidator {
|
|
|
359
191
|
*/
|
|
360
192
|
extractProperty(accessor) {
|
|
361
193
|
let accessedProperty;
|
|
362
|
-
// Create a Proxy that tracks property accesses
|
|
363
194
|
const proxy = new Proxy(this.source, {
|
|
364
195
|
get(target, prop) {
|
|
365
196
|
if (typeof prop === 'string') {
|
|
@@ -369,7 +200,6 @@ class PropertyValidator {
|
|
|
369
200
|
return undefined;
|
|
370
201
|
},
|
|
371
202
|
});
|
|
372
|
-
// Call the accessor to trigger the Proxy
|
|
373
203
|
const value = accessor(proxy);
|
|
374
204
|
if (!accessedProperty) {
|
|
375
205
|
throw new Error('Unable to extract property name. Ensure the accessor accesses a property directly (e.g., r => r.fieldName)');
|
package/dist/staking/index.js
CHANGED
|
@@ -27,12 +27,18 @@ exports.StakingService = void 0;
|
|
|
27
27
|
*/
|
|
28
28
|
const clients_1 = require("../clients");
|
|
29
29
|
const paginatedResponse_1 = require("../shared/paginatedResponse");
|
|
30
|
+
const validation_1 = require("../shared/validation");
|
|
30
31
|
class StakingService {
|
|
31
32
|
constructor(client) {
|
|
32
33
|
this.client = client;
|
|
33
34
|
}
|
|
34
35
|
createStake(request, options) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
(0, validation_1.validate)(request)
|
|
38
|
+
.requiredUUID((r) => r.portfolioId)
|
|
39
|
+
.requiredUUID((r) => r.walletId)
|
|
40
|
+
.requiredUUID((r) => r.idempotencyKey)
|
|
41
|
+
.check();
|
|
36
42
|
const bodyParams = Object.assign(Object.assign({}, request), { portfolioId: undefined, walletId: undefined });
|
|
37
43
|
const response = yield this.client.request({
|
|
38
44
|
url: `portfolios/${request.portfolioId}/wallets/${request.walletId}/staking/initiate`,
|
|
@@ -45,6 +51,11 @@ class StakingService {
|
|
|
45
51
|
}
|
|
46
52
|
createUnstake(request, options) {
|
|
47
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
(0, validation_1.validate)(request)
|
|
55
|
+
.requiredUUID((r) => r.portfolioId)
|
|
56
|
+
.requiredUUID((r) => r.walletId)
|
|
57
|
+
.requiredUUID((r) => r.idempotencyKey)
|
|
58
|
+
.check();
|
|
48
59
|
const bodyParams = Object.assign(Object.assign({}, request), { portfolioId: undefined, walletId: undefined });
|
|
49
60
|
const response = yield this.client.request({
|
|
50
61
|
url: `portfolios/${request.portfolioId}/wallets/${request.walletId}/staking/unstake`,
|
|
@@ -57,6 +68,12 @@ class StakingService {
|
|
|
57
68
|
}
|
|
58
69
|
createPortfolioStake(request, options) {
|
|
59
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
(0, validation_1.validate)(request)
|
|
72
|
+
.requiredUUID((r) => r.portfolioId)
|
|
73
|
+
.requiredUUID((r) => r.idempotencyKey)
|
|
74
|
+
.requiredString((r) => r.currencySymbol)
|
|
75
|
+
.requiredString((r) => r.amount)
|
|
76
|
+
.check();
|
|
60
77
|
const bodyParams = Object.assign(Object.assign({}, request), { portfolioId: undefined });
|
|
61
78
|
const response = yield this.client.request({
|
|
62
79
|
url: `portfolios/${request.portfolioId}/staking/initiate`,
|
|
@@ -69,6 +86,12 @@ class StakingService {
|
|
|
69
86
|
}
|
|
70
87
|
createPortfolioUnstake(request, options) {
|
|
71
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
(0, validation_1.validate)(request)
|
|
90
|
+
.requiredUUID((r) => r.portfolioId)
|
|
91
|
+
.requiredUUID((r) => r.idempotencyKey)
|
|
92
|
+
.requiredString((r) => r.currencySymbol)
|
|
93
|
+
.requiredString((r) => r.amount)
|
|
94
|
+
.check();
|
|
72
95
|
const bodyParams = Object.assign(Object.assign({}, request), { portfolioId: undefined });
|
|
73
96
|
const response = yield this.client.request({
|
|
74
97
|
url: `portfolios/${request.portfolioId}/staking/unstake`,
|
|
@@ -81,6 +104,10 @@ class StakingService {
|
|
|
81
104
|
}
|
|
82
105
|
queryTransactionValidators(request, options) {
|
|
83
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
(0, validation_1.validate)(request)
|
|
108
|
+
.requiredUUID((r) => r.portfolioId)
|
|
109
|
+
.requiredArray((r) => r.transactionIds)
|
|
110
|
+
.check();
|
|
84
111
|
const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);
|
|
85
112
|
const { transactionIds, cursor, limit, sortDirection } = request;
|
|
86
113
|
const bodyParams = {
|
|
@@ -101,6 +128,11 @@ class StakingService {
|
|
|
101
128
|
}
|
|
102
129
|
claimRewards(request, options) {
|
|
103
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
(0, validation_1.validate)(request)
|
|
132
|
+
.requiredUUID((r) => r.portfolioId)
|
|
133
|
+
.requiredUUID((r) => r.walletId)
|
|
134
|
+
.requiredUUID((r) => r.idempotencyKey)
|
|
135
|
+
.check();
|
|
104
136
|
const { idempotencyKey, inputs, portfolioId, walletId } = request;
|
|
105
137
|
const bodyParams = {
|
|
106
138
|
idempotencyKey,
|
|
@@ -117,6 +149,11 @@ class StakingService {
|
|
|
117
149
|
}
|
|
118
150
|
previewUnstake(request, options) {
|
|
119
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
(0, validation_1.validate)(request)
|
|
153
|
+
.requiredUUID((r) => r.portfolioId)
|
|
154
|
+
.requiredUUID((r) => r.walletId)
|
|
155
|
+
.requiredString((r) => r.amount)
|
|
156
|
+
.check();
|
|
120
157
|
const bodyParams = Object.assign(Object.assign({}, request), { portfolioId: undefined, walletId: undefined });
|
|
121
158
|
const response = yield this.client.request({
|
|
122
159
|
url: `portfolios/${request.portfolioId}/wallets/${request.walletId}/staking/unstake/preview`,
|
|
@@ -129,6 +166,10 @@ class StakingService {
|
|
|
129
166
|
}
|
|
130
167
|
getUnstakingStatus(request, options) {
|
|
131
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
(0, validation_1.validate)(request)
|
|
170
|
+
.requiredUUID((r) => r.portfolioId)
|
|
171
|
+
.requiredUUID((r) => r.walletId)
|
|
172
|
+
.check();
|
|
132
173
|
const { portfolioId, walletId } = request;
|
|
133
174
|
const response = yield this.client.request({
|
|
134
175
|
url: `portfolios/${portfolioId}/wallets/${walletId}/staking/unstake/status`,
|
|
@@ -137,5 +178,19 @@ class StakingService {
|
|
|
137
178
|
return response.data;
|
|
138
179
|
});
|
|
139
180
|
}
|
|
181
|
+
getStakingStatus(request, options) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
(0, validation_1.validate)(request)
|
|
184
|
+
.requiredUUID((r) => r.portfolioId)
|
|
185
|
+
.requiredUUID((r) => r.walletId)
|
|
186
|
+
.check();
|
|
187
|
+
const { portfolioId, walletId } = request;
|
|
188
|
+
const response = yield this.client.request({
|
|
189
|
+
url: `portfolios/${portfolioId}/wallets/${walletId}/staking/status`,
|
|
190
|
+
callOptions: options,
|
|
191
|
+
});
|
|
192
|
+
return response.data;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
140
195
|
}
|
|
141
196
|
exports.StakingService = StakingService;
|