@coinbase-sample/prime-sdk-ts 0.8.0 → 0.8.1
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/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 +41 -0
- package/dist/transactions/index.js +42 -0
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/orders/types.d.ts +1 -1
- package/dist/types/shared/validation.d.ts +19 -107
- 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
package/dist/orders/index.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.OrdersService = void 0;
|
|
|
37
37
|
* limitations under the License.
|
|
38
38
|
*/
|
|
39
39
|
const clients_1 = require("../clients");
|
|
40
|
+
const validation_1 = require("../shared/validation");
|
|
40
41
|
const paginatedResponse_1 = require("../shared/paginatedResponse");
|
|
41
42
|
class OrdersService {
|
|
42
43
|
constructor(client) {
|
|
@@ -44,6 +45,10 @@ class OrdersService {
|
|
|
44
45
|
}
|
|
45
46
|
getOrder(request, options) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
(0, validation_1.validate)(request)
|
|
49
|
+
.requiredUUID((r) => r.portfolioId)
|
|
50
|
+
.requiredUUID((r) => r.orderId)
|
|
51
|
+
.check();
|
|
47
52
|
const response = yield this.client.request({
|
|
48
53
|
url: `portfolios/${request.portfolioId}/orders/${request.orderId}`,
|
|
49
54
|
callOptions: options,
|
|
@@ -53,6 +58,10 @@ class OrdersService {
|
|
|
53
58
|
}
|
|
54
59
|
getOrderEditHistory(request, options) {
|
|
55
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
(0, validation_1.validate)(request)
|
|
62
|
+
.requiredUUID((r) => r.portfolioId)
|
|
63
|
+
.requiredUUID((r) => r.orderId)
|
|
64
|
+
.check();
|
|
56
65
|
const response = yield this.client.request({
|
|
57
66
|
url: `portfolios/${request.portfolioId}/orders/${request.orderId}/edit_history`,
|
|
58
67
|
callOptions: options,
|
|
@@ -64,6 +73,9 @@ class OrdersService {
|
|
|
64
73
|
}
|
|
65
74
|
listPortfolioFills(request, options) {
|
|
66
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
(0, validation_1.validate)(request)
|
|
77
|
+
.requiredUUID((r) => r.portfolioId)
|
|
78
|
+
.check();
|
|
67
79
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
68
80
|
const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
|
|
69
81
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
|
@@ -78,6 +90,9 @@ class OrdersService {
|
|
|
78
90
|
}
|
|
79
91
|
listPortfolioOrders(request, options) {
|
|
80
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
(0, validation_1.validate)(request)
|
|
94
|
+
.requiredUUID((r) => r.portfolioId)
|
|
95
|
+
.check();
|
|
81
96
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
82
97
|
const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
|
|
83
98
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
|
@@ -92,6 +107,10 @@ class OrdersService {
|
|
|
92
107
|
}
|
|
93
108
|
listOrderFills(request, options) {
|
|
94
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
(0, validation_1.validate)(request)
|
|
111
|
+
.requiredUUID((r) => r.portfolioId)
|
|
112
|
+
.requiredUUID((r) => r.orderId)
|
|
113
|
+
.check();
|
|
95
114
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
96
115
|
const { limit, cursor, sortDirection, portfolioId, orderId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId", "orderId"]);
|
|
97
116
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
|
@@ -106,6 +125,9 @@ class OrdersService {
|
|
|
106
125
|
}
|
|
107
126
|
listOpenOrders(request, options) {
|
|
108
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
(0, validation_1.validate)(request)
|
|
129
|
+
.requiredUUID((r) => r.portfolioId)
|
|
130
|
+
.check();
|
|
109
131
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
110
132
|
const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
|
|
111
133
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
|
@@ -120,6 +142,12 @@ class OrdersService {
|
|
|
120
142
|
}
|
|
121
143
|
createOrderPreview(request, options) {
|
|
122
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
(0, validation_1.validate)(request)
|
|
146
|
+
.requiredUUID((r) => r.portfolioId)
|
|
147
|
+
.requiredString((r) => r.productId)
|
|
148
|
+
.requiredString((r) => r.side)
|
|
149
|
+
.requiredString((r) => r.type)
|
|
150
|
+
.check();
|
|
123
151
|
const response = yield this.client.request({
|
|
124
152
|
url: `portfolios/${request.portfolioId}/order_preview`,
|
|
125
153
|
method: clients_1.Method.POST,
|
|
@@ -131,6 +159,10 @@ class OrdersService {
|
|
|
131
159
|
}
|
|
132
160
|
cancelOrder(request, options) {
|
|
133
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
(0, validation_1.validate)(request)
|
|
163
|
+
.requiredUUID((r) => r.portfolioId)
|
|
164
|
+
.requiredUUID((r) => r.orderId)
|
|
165
|
+
.check();
|
|
134
166
|
const response = yield this.client.request({
|
|
135
167
|
url: `portfolios/${request.portfolioId}/orders/${request.orderId}/cancel`,
|
|
136
168
|
method: clients_1.Method.POST,
|
|
@@ -141,6 +173,13 @@ class OrdersService {
|
|
|
141
173
|
}
|
|
142
174
|
createOrder(request, options) {
|
|
143
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
(0, validation_1.validate)(request)
|
|
177
|
+
.requiredUUID((r) => r.portfolioId)
|
|
178
|
+
.requiredString((r) => r.productId)
|
|
179
|
+
.requiredString((r) => r.side)
|
|
180
|
+
.requiredUUID((r) => r.clientOrderId)
|
|
181
|
+
.requiredString((r) => r.type)
|
|
182
|
+
.check();
|
|
144
183
|
const response = yield this.client.request({
|
|
145
184
|
url: `portfolios/${request.portfolioId}/order`,
|
|
146
185
|
method: clients_1.Method.POST,
|
|
@@ -152,6 +191,13 @@ class OrdersService {
|
|
|
152
191
|
}
|
|
153
192
|
createQuote(request, options) {
|
|
154
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
(0, validation_1.validate)(request)
|
|
195
|
+
.requiredUUID((r) => r.portfolioId)
|
|
196
|
+
.requiredString((r) => r.productId)
|
|
197
|
+
.requiredString((r) => r.side)
|
|
198
|
+
.requiredUUID((r) => r.clientOrderId)
|
|
199
|
+
.requiredString((r) => r.type)
|
|
200
|
+
.check();
|
|
155
201
|
const response = yield this.client.request({
|
|
156
202
|
url: `portfolios/${request.portfolioId}/rfq`,
|
|
157
203
|
method: clients_1.Method.POST,
|
|
@@ -163,6 +209,13 @@ class OrdersService {
|
|
|
163
209
|
}
|
|
164
210
|
acceptQuote(request, options) {
|
|
165
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
(0, validation_1.validate)(request)
|
|
213
|
+
.requiredUUID((r) => r.portfolioId)
|
|
214
|
+
.requiredString((r) => r.productId)
|
|
215
|
+
.requiredString((r) => r.side)
|
|
216
|
+
.requiredUUID((r) => r.clientOrderId)
|
|
217
|
+
.requiredString((r) => r.quoteId)
|
|
218
|
+
.check();
|
|
166
219
|
const response = yield this.client.request({
|
|
167
220
|
url: `portfolios/${request.portfolioId}/accept_quote`,
|
|
168
221
|
method: clients_1.Method.POST,
|
|
@@ -174,6 +227,12 @@ class OrdersService {
|
|
|
174
227
|
}
|
|
175
228
|
editOrder(request, options) {
|
|
176
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
(0, validation_1.validate)(request)
|
|
231
|
+
.requiredUUID((r) => r.portfolioId)
|
|
232
|
+
.requiredUUID((r) => r.orderId)
|
|
233
|
+
.requiredUUID((r) => r.clientOrderId)
|
|
234
|
+
.requiredString((r) => r.origClientOrderId)
|
|
235
|
+
.check();
|
|
177
236
|
const { portfolioId, orderId } = request, bodyParams = __rest(request, ["portfolioId", "orderId"]);
|
|
178
237
|
const response = yield this.client.request({
|
|
179
238
|
url: `portfolios/${portfolioId}/orders/${orderId}/edit`,
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PaymentMethodsService = void 0;
|
|
13
|
+
const validation_1 = require("../shared/validation");
|
|
13
14
|
class PaymentMethodsService {
|
|
14
15
|
constructor(client) {
|
|
15
16
|
this.client = client;
|
|
@@ -17,6 +18,9 @@ class PaymentMethodsService {
|
|
|
17
18
|
// TODO: rename me to remove Entity in a minor version change
|
|
18
19
|
listEntityPaymentMethods(request, options) {
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
(0, validation_1.validate)(request)
|
|
22
|
+
.requiredUUID((r) => r.entityId)
|
|
23
|
+
.check();
|
|
20
24
|
const response = yield this.client.request({
|
|
21
25
|
url: `entities/${request.entityId}/payment-methods`,
|
|
22
26
|
callOptions: options,
|
|
@@ -26,6 +30,10 @@ class PaymentMethodsService {
|
|
|
26
30
|
}
|
|
27
31
|
getPaymentMethod(request, options) {
|
|
28
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
(0, validation_1.validate)(request)
|
|
34
|
+
.requiredUUID((r) => r.entityId)
|
|
35
|
+
.requiredUUID((r) => r.paymentMethodId)
|
|
36
|
+
.check();
|
|
29
37
|
const response = yield this.client.request({
|
|
30
38
|
url: `entities/${request.entityId}/payment-methods/${request.paymentMethodId}`,
|
|
31
39
|
callOptions: options,
|
package/dist/portfolios/index.js
CHANGED
|
@@ -10,12 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PortfoliosService = void 0;
|
|
13
|
+
const validation_1 = require("../shared/validation");
|
|
13
14
|
class PortfoliosService {
|
|
14
15
|
constructor(client) {
|
|
15
16
|
this.client = client;
|
|
16
17
|
}
|
|
17
18
|
getPortfolio(request, options) {
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
(0, validation_1.validate)(request)
|
|
21
|
+
.requiredUUID((r) => r.portfolioId)
|
|
22
|
+
.check();
|
|
19
23
|
const response = yield this.client.request({
|
|
20
24
|
url: `portfolios/${request.portfolioId}`,
|
|
21
25
|
callOptions: options,
|
|
@@ -25,6 +29,9 @@ class PortfoliosService {
|
|
|
25
29
|
}
|
|
26
30
|
getPortfolioCredit(request, options) {
|
|
27
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
(0, validation_1.validate)(request)
|
|
33
|
+
.requiredUUID((r) => r.portfolioId)
|
|
34
|
+
.check();
|
|
28
35
|
const response = yield this.client.request({
|
|
29
36
|
url: `portfolios/${request.portfolioId}/credit`,
|
|
30
37
|
callOptions: options,
|
|
@@ -34,6 +41,9 @@ class PortfoliosService {
|
|
|
34
41
|
}
|
|
35
42
|
getCounterpartyId(request, options) {
|
|
36
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
(0, validation_1.validate)(request)
|
|
45
|
+
.requiredUUID((r) => r.portfolioId)
|
|
46
|
+
.check();
|
|
37
47
|
const response = yield this.client.request({
|
|
38
48
|
url: `portfolios/${request.portfolioId}/counterparty`,
|
|
39
49
|
callOptions: options,
|
package/dist/positions/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.PositionsService = void 0;
|
|
24
|
+
const validation_1 = require("../shared/validation");
|
|
24
25
|
const paginatedResponse_1 = require("../shared/paginatedResponse");
|
|
25
26
|
class PositionsService {
|
|
26
27
|
constructor(client) {
|
|
@@ -28,6 +29,9 @@ class PositionsService {
|
|
|
28
29
|
}
|
|
29
30
|
listAggregateEntityPositions(request, options) {
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
(0, validation_1.validate)(request)
|
|
33
|
+
.requiredUUID((r) => r.entityId)
|
|
34
|
+
.check();
|
|
31
35
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
32
36
|
const { limit, cursor, sortDirection, entityId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "entityId"]);
|
|
33
37
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
|
@@ -42,6 +46,9 @@ class PositionsService {
|
|
|
42
46
|
}
|
|
43
47
|
listEntityPositions(request, options) {
|
|
44
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
(0, validation_1.validate)(request)
|
|
50
|
+
.requiredUUID((r) => r.entityId)
|
|
51
|
+
.check();
|
|
45
52
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
46
53
|
const { limit, cursor, sortDirection, entityId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "entityId"]);
|
|
47
54
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
package/dist/products/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.ProductsService = void 0;
|
|
24
|
+
const validation_1 = require("../shared/validation");
|
|
24
25
|
const paginatedResponse_1 = require("../shared/paginatedResponse");
|
|
25
26
|
class ProductsService {
|
|
26
27
|
constructor(client) {
|
|
@@ -28,6 +29,9 @@ class ProductsService {
|
|
|
28
29
|
}
|
|
29
30
|
listProducts(request, options) {
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
(0, validation_1.validate)(request)
|
|
33
|
+
.requiredUUID((r) => r.portfolioId)
|
|
34
|
+
.check();
|
|
31
35
|
const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
|
|
32
36
|
const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
|
|
33
37
|
const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
|
|
@@ -42,6 +46,13 @@ class ProductsService {
|
|
|
42
46
|
}
|
|
43
47
|
listProductCandles(request, options) {
|
|
44
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
(0, validation_1.validate)(request)
|
|
50
|
+
.requiredUUID((r) => r.portfolioId)
|
|
51
|
+
.requiredString((r) => r.productId)
|
|
52
|
+
.requiredString((r) => r.startTime)
|
|
53
|
+
.requiredString((r) => r.endTime)
|
|
54
|
+
.requiredString((r) => r.granularity)
|
|
55
|
+
.check();
|
|
45
56
|
const { portfolioId, productId, startTime, endTime, granularity } = request;
|
|
46
57
|
const response = yield this.client.request({
|
|
47
58
|
url: `portfolios/${portfolioId}/candles`,
|
|
@@ -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) {
|