@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
|
@@ -29,19 +29,17 @@ describe('validation', () => {
|
|
|
29
29
|
expect((0, validation_1.isValidUUID)('123e4567-e89b-12d3-a456')).toBe(false);
|
|
30
30
|
expect((0, validation_1.isValidUUID)('123e4567e89b12d3a456426614174000')).toBe(false);
|
|
31
31
|
expect((0, validation_1.isValidUUID)('')).toBe(false);
|
|
32
|
-
expect((0, validation_1.isValidUUID)('12345678-1234-1234-1234-12345678901g')).toBe(false);
|
|
32
|
+
expect((0, validation_1.isValidUUID)('12345678-1234-1234-1234-12345678901g')).toBe(false);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
|
-
describe('
|
|
36
|
-
let validator;
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
validator = (0, validation_1.createValidator)();
|
|
39
|
-
});
|
|
35
|
+
describe('PropertyValidator', () => {
|
|
40
36
|
it('should start with no errors', () => {
|
|
37
|
+
const validator = (0, validation_1.validate)({});
|
|
41
38
|
expect(validator.hasErrors()).toBe(false);
|
|
42
39
|
expect(validator.getErrors()).toEqual([]);
|
|
43
40
|
});
|
|
44
41
|
it('should accumulate errors', () => {
|
|
42
|
+
const validator = (0, validation_1.validate)({});
|
|
45
43
|
validator.addError('field1', 'is required');
|
|
46
44
|
validator.addError('field2', 'must be a valid UUID', 'invalid-value');
|
|
47
45
|
expect(validator.hasErrors()).toBe(true);
|
|
@@ -57,146 +55,208 @@ describe('validation', () => {
|
|
|
57
55
|
});
|
|
58
56
|
});
|
|
59
57
|
it('should throw with formatted error message when there are errors', () => {
|
|
58
|
+
const validator = (0, validation_1.validate)({});
|
|
60
59
|
validator.addError('portfolioId', 'must be a valid UUID', 'bad-id');
|
|
61
60
|
validator.addError('orderId', 'is required');
|
|
62
|
-
expect(() => validator.
|
|
63
|
-
expect(() => validator.
|
|
61
|
+
expect(() => validator.check()).toThrow(errors_1.CoinbasePrimeClientException);
|
|
62
|
+
expect(() => validator.check()).toThrow(/Request validation failed:\n - portfolioId: must be a valid UUID \(received: 'bad-id'\)\n - orderId: is required/);
|
|
64
63
|
});
|
|
65
64
|
it('should not throw when there are no errors', () => {
|
|
66
|
-
|
|
65
|
+
const validator = (0, validation_1.validate)({});
|
|
66
|
+
expect(() => validator.check()).not.toThrow();
|
|
67
67
|
});
|
|
68
68
|
it('should include custom context message', () => {
|
|
69
|
+
const validator = (0, validation_1.validate)({});
|
|
69
70
|
validator.addError('field1', 'is invalid');
|
|
70
|
-
expect(() => validator.
|
|
71
|
+
expect(() => validator.check('Custom operation failed')).toThrow(/Custom operation failed:/);
|
|
71
72
|
});
|
|
72
73
|
});
|
|
73
|
-
describe('
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
(0, validation_1.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
it('should
|
|
93
|
-
|
|
94
|
-
expect(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
expect(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
74
|
+
describe('requiredUUID', () => {
|
|
75
|
+
it('should not throw for valid UUID', () => {
|
|
76
|
+
const request = { testId: '123e4567-e89b-12d3-a456-426614174000' };
|
|
77
|
+
expect(() => (0, validation_1.validate)(request)
|
|
78
|
+
.requiredUUID((r) => r.testId)
|
|
79
|
+
.check()).not.toThrow();
|
|
80
|
+
});
|
|
81
|
+
it('should throw for undefined', () => {
|
|
82
|
+
const request = { testId: undefined };
|
|
83
|
+
expect(() => (0, validation_1.validate)(request)
|
|
84
|
+
.requiredUUID((r) => r.testId)
|
|
85
|
+
.check()).toThrow(/required/);
|
|
86
|
+
});
|
|
87
|
+
it('should throw for null', () => {
|
|
88
|
+
const request = { testId: null };
|
|
89
|
+
expect(() => (0, validation_1.validate)(request)
|
|
90
|
+
.requiredUUID((r) => r.testId)
|
|
91
|
+
.check()).toThrow(/required/);
|
|
92
|
+
});
|
|
93
|
+
it('should throw for empty string', () => {
|
|
94
|
+
const request = { testId: '' };
|
|
95
|
+
expect(() => (0, validation_1.validate)(request)
|
|
96
|
+
.requiredUUID((r) => r.testId)
|
|
97
|
+
.check()).toThrow(/required/);
|
|
98
|
+
});
|
|
99
|
+
it('should throw for whitespace-only string', () => {
|
|
100
|
+
const request = { testId: ' ' };
|
|
101
|
+
expect(() => (0, validation_1.validate)(request)
|
|
102
|
+
.requiredUUID((r) => r.testId)
|
|
103
|
+
.check()).toThrow(/whitespace/);
|
|
104
|
+
});
|
|
105
|
+
it('should throw for invalid UUID format', () => {
|
|
106
|
+
const request = { testId: 'not-a-uuid' };
|
|
107
|
+
expect(() => (0, validation_1.validate)(request)
|
|
108
|
+
.requiredUUID((r) => r.testId)
|
|
109
|
+
.check()).toThrow(/valid UUID/);
|
|
106
110
|
});
|
|
107
111
|
});
|
|
108
|
-
describe('
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
it('should not
|
|
122
|
-
|
|
123
|
-
expect(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
describe('optionalUUID', () => {
|
|
113
|
+
it('should not throw for valid UUID', () => {
|
|
114
|
+
const request = { testId: '123e4567-e89b-12d3-a456-426614174000' };
|
|
115
|
+
expect(() => (0, validation_1.validate)(request)
|
|
116
|
+
.optionalUUID((r) => r.testId)
|
|
117
|
+
.check()).not.toThrow();
|
|
118
|
+
});
|
|
119
|
+
it('should not throw for undefined', () => {
|
|
120
|
+
const request = { testId: undefined };
|
|
121
|
+
expect(() => (0, validation_1.validate)(request)
|
|
122
|
+
.optionalUUID((r) => r.testId)
|
|
123
|
+
.check()).not.toThrow();
|
|
124
|
+
});
|
|
125
|
+
it('should not throw for null', () => {
|
|
126
|
+
const request = { testId: null };
|
|
127
|
+
expect(() => (0, validation_1.validate)(request)
|
|
128
|
+
.optionalUUID((r) => r.testId)
|
|
129
|
+
.check()).not.toThrow();
|
|
130
|
+
});
|
|
131
|
+
it('should not throw for empty string', () => {
|
|
132
|
+
const request = { testId: '' };
|
|
133
|
+
expect(() => (0, validation_1.validate)(request)
|
|
134
|
+
.optionalUUID((r) => r.testId)
|
|
135
|
+
.check()).not.toThrow();
|
|
136
|
+
});
|
|
137
|
+
it('should throw for invalid UUID format', () => {
|
|
138
|
+
const request = { testId: 'not-a-uuid' };
|
|
139
|
+
expect(() => (0, validation_1.validate)(request)
|
|
140
|
+
.optionalUUID((r) => r.testId)
|
|
141
|
+
.check()).toThrow(/valid UUID/);
|
|
133
142
|
});
|
|
134
143
|
});
|
|
135
|
-
describe('
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
(0, validation_1.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
it('should
|
|
155
|
-
|
|
156
|
-
expect(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
expect(
|
|
144
|
+
describe('requiredString', () => {
|
|
145
|
+
it('should not throw for valid string', () => {
|
|
146
|
+
const request = { testField: 'valid-string' };
|
|
147
|
+
expect(() => (0, validation_1.validate)(request)
|
|
148
|
+
.requiredString((r) => r.testField)
|
|
149
|
+
.check()).not.toThrow();
|
|
150
|
+
});
|
|
151
|
+
it('should throw for undefined', () => {
|
|
152
|
+
const request = { testField: undefined };
|
|
153
|
+
expect(() => (0, validation_1.validate)(request)
|
|
154
|
+
.requiredString((r) => r.testField)
|
|
155
|
+
.check()).toThrow(/required/);
|
|
156
|
+
});
|
|
157
|
+
it('should throw for null', () => {
|
|
158
|
+
const request = { testField: null };
|
|
159
|
+
expect(() => (0, validation_1.validate)(request)
|
|
160
|
+
.requiredString((r) => r.testField)
|
|
161
|
+
.check()).toThrow(/required/);
|
|
162
|
+
});
|
|
163
|
+
it('should throw for empty string', () => {
|
|
164
|
+
const request = { testField: '' };
|
|
165
|
+
expect(() => (0, validation_1.validate)(request)
|
|
166
|
+
.requiredString((r) => r.testField)
|
|
167
|
+
.check()).toThrow(/required/);
|
|
168
|
+
});
|
|
169
|
+
it('should throw for whitespace-only string', () => {
|
|
170
|
+
const request = { testField: ' ' };
|
|
171
|
+
expect(() => (0, validation_1.validate)(request)
|
|
172
|
+
.requiredString((r) => r.testField)
|
|
173
|
+
.check()).toThrow(/whitespace/);
|
|
163
174
|
});
|
|
164
175
|
});
|
|
165
|
-
describe('
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
describe('optionalString', () => {
|
|
177
|
+
it('should not throw for valid string', () => {
|
|
178
|
+
const request = { testField: 'valid-string' };
|
|
179
|
+
expect(() => (0, validation_1.validate)(request)
|
|
180
|
+
.optionalString((r) => r.testField)
|
|
181
|
+
.check()).not.toThrow();
|
|
182
|
+
});
|
|
183
|
+
it('should not throw for undefined', () => {
|
|
184
|
+
const request = { testField: undefined };
|
|
185
|
+
expect(() => (0, validation_1.validate)(request)
|
|
186
|
+
.optionalString((r) => r.testField)
|
|
187
|
+
.check()).not.toThrow();
|
|
188
|
+
});
|
|
189
|
+
it('should not throw for null', () => {
|
|
190
|
+
const request = { testField: null };
|
|
191
|
+
expect(() => (0, validation_1.validate)(request)
|
|
192
|
+
.optionalString((r) => r.testField)
|
|
193
|
+
.check()).not.toThrow();
|
|
194
|
+
});
|
|
195
|
+
it('should throw for whitespace-only when not empty', () => {
|
|
196
|
+
const request = { testField: ' ' };
|
|
197
|
+
expect(() => (0, validation_1.validate)(request)
|
|
198
|
+
.optionalString((r) => r.testField)
|
|
199
|
+
.check()).toThrow(/whitespace/);
|
|
177
200
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
201
|
+
});
|
|
202
|
+
describe('requiredArray', () => {
|
|
203
|
+
it('should not throw for valid array', () => {
|
|
204
|
+
const request = { items: ['a', 'b', 'c'] };
|
|
205
|
+
expect(() => (0, validation_1.validate)(request)
|
|
206
|
+
.requiredArray((r) => r.items)
|
|
207
|
+
.check()).not.toThrow();
|
|
208
|
+
});
|
|
209
|
+
it('should throw for undefined', () => {
|
|
210
|
+
const request = { items: undefined };
|
|
211
|
+
expect(() => (0, validation_1.validate)(request)
|
|
212
|
+
.requiredArray((r) => r.items)
|
|
213
|
+
.check()).toThrow(/required/);
|
|
214
|
+
});
|
|
215
|
+
it('should throw for empty array', () => {
|
|
216
|
+
const request = { items: [] };
|
|
217
|
+
expect(() => (0, validation_1.validate)(request)
|
|
218
|
+
.requiredArray((r) => r.items)
|
|
219
|
+
.check()).toThrow(/empty array/);
|
|
181
220
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
221
|
+
});
|
|
222
|
+
describe('requiredBoolean', () => {
|
|
223
|
+
it('should not throw for true', () => {
|
|
224
|
+
const request = { flag: true };
|
|
225
|
+
expect(() => (0, validation_1.validate)(request)
|
|
226
|
+
.requiredBoolean((r) => r.flag)
|
|
227
|
+
.check()).not.toThrow();
|
|
228
|
+
});
|
|
229
|
+
it('should not throw for false', () => {
|
|
230
|
+
const request = { flag: false };
|
|
231
|
+
expect(() => (0, validation_1.validate)(request)
|
|
232
|
+
.requiredBoolean((r) => r.flag)
|
|
233
|
+
.check()).not.toThrow();
|
|
234
|
+
});
|
|
235
|
+
it('should throw for undefined', () => {
|
|
236
|
+
const request = { flag: undefined };
|
|
237
|
+
expect(() => (0, validation_1.validate)(request)
|
|
238
|
+
.requiredBoolean((r) => r.flag)
|
|
239
|
+
.check()).toThrow(/required/);
|
|
186
240
|
});
|
|
187
241
|
});
|
|
188
242
|
describe('multiple field validation', () => {
|
|
189
243
|
it('should collect all validation errors before throwing', () => {
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
expect(
|
|
196
|
-
|
|
197
|
-
|
|
244
|
+
const request = {
|
|
245
|
+
portfolioId: undefined,
|
|
246
|
+
orderId: 'invalid-uuid',
|
|
247
|
+
productId: '',
|
|
248
|
+
};
|
|
249
|
+
expect(() => (0, validation_1.validate)(request)
|
|
250
|
+
.requiredUUID((r) => r.portfolioId)
|
|
251
|
+
.requiredUUID((r) => r.orderId)
|
|
252
|
+
.requiredString((r) => r.productId)
|
|
253
|
+
.check('getOrder request validation failed')).toThrow(errors_1.CoinbasePrimeClientException);
|
|
198
254
|
try {
|
|
199
|
-
|
|
255
|
+
(0, validation_1.validate)(request)
|
|
256
|
+
.requiredUUID((r) => r.portfolioId)
|
|
257
|
+
.requiredUUID((r) => r.orderId)
|
|
258
|
+
.requiredString((r) => r.productId)
|
|
259
|
+
.check('getOrder request validation failed');
|
|
200
260
|
}
|
|
201
261
|
catch (error) {
|
|
202
262
|
if (error instanceof errors_1.CoinbasePrimeClientException) {
|