@coinbase-sample/prime-sdk-ts 0.6.1 → 0.6.3

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 (64) hide show
  1. package/README.md +207 -67
  2. package/dist/activities/index.js +21 -39
  3. package/dist/addressBooks/index.js +18 -5
  4. package/dist/allocations/index.js +19 -18
  5. package/dist/balances/index.js +23 -17
  6. package/dist/client-manual.js +84 -0
  7. package/dist/client-modular.js +57 -0
  8. package/dist/client-only.js +31 -0
  9. package/dist/{client.js → clients/client.js} +12 -2
  10. package/dist/clients/clientWithServices.js +323 -0
  11. package/dist/{types/client.d.ts → clients/clientWithServicesTypes.js} +3 -6
  12. package/dist/clients/index.js +28 -0
  13. package/dist/clients/types.js +2 -0
  14. package/dist/constants.js +1 -1
  15. package/dist/financing/index.js +16 -3
  16. package/dist/futures/index.js +4 -4
  17. package/dist/index.js +27 -18
  18. package/dist/invoices/index.js +16 -12
  19. package/dist/onchainAddressBook/index.js +4 -4
  20. package/dist/orders/index.js +38 -58
  21. package/dist/positions/index.js +21 -6
  22. package/dist/products/index.js +16 -3
  23. package/dist/services.js +75 -0
  24. package/dist/shared/envUtils.js +66 -0
  25. package/dist/shared/paginatedResponse.js +3 -0
  26. package/dist/staking/index.js +5 -5
  27. package/dist/transactions/index.js +26 -17
  28. package/dist/types/activities/index.d.ts +2 -3
  29. package/dist/types/addressBooks/index.d.ts +2 -3
  30. package/dist/types/allocations/index.d.ts +2 -3
  31. package/dist/types/assets/index.d.ts +2 -3
  32. package/dist/types/balances/index.d.ts +2 -3
  33. package/dist/types/client-manual.d.ts +58 -0
  34. package/dist/types/client-modular.d.ts +39 -0
  35. package/dist/types/client-only.d.ts +18 -0
  36. package/dist/types/clients/client.d.ts +27 -0
  37. package/dist/types/clients/clientWithServices.d.ts +229 -0
  38. package/dist/types/clients/clientWithServicesTypes.d.ts +115 -0
  39. package/dist/types/clients/index.d.ts +19 -0
  40. package/dist/types/clients/types.d.ts +48 -0
  41. package/dist/types/commission/index.d.ts +2 -3
  42. package/dist/types/constants.d.ts +1 -1
  43. package/dist/types/financing/index.d.ts +2 -3
  44. package/dist/types/futures/index.d.ts +2 -3
  45. package/dist/types/index.d.ts +2 -1
  46. package/dist/types/invoices/index.d.ts +2 -3
  47. package/dist/types/onchainAddressBook/index.d.ts +2 -3
  48. package/dist/types/orders/index.d.ts +2 -3
  49. package/dist/types/paymentMethods/index.d.ts +2 -3
  50. package/dist/types/portfolios/index.d.ts +2 -3
  51. package/dist/types/positions/index.d.ts +2 -3
  52. package/dist/types/products/index.d.ts +2 -3
  53. package/dist/types/services.d.ts +39 -0
  54. package/dist/types/shared/envUtils.d.ts +36 -0
  55. package/dist/types/shared/paginatedResponse.d.ts +5 -4
  56. package/dist/types/staking/index.d.ts +2 -3
  57. package/dist/types/transactions/index.d.ts +2 -3
  58. package/dist/types/types.d.ts +37 -0
  59. package/dist/types/users/index.d.ts +2 -3
  60. package/dist/types/wallets/index.d.ts +2 -3
  61. package/dist/types.js +39 -0
  62. package/dist/users/index.js +21 -6
  63. package/dist/wallets/index.js +24 -12
  64. package/package.json +32 -1
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Coinbase Prime API TypeScript SDK
2
2
 
3
- ## Overview
3
+ [![npm version](https://badge.fury.io/js/%40coinbase-sample%2Fprime-sdk-ts.svg)](https://badge.fury.io/js/%40coinbase-sample%2Fprime-sdk-ts)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
5
 
5
- Welcome to the Coinbase Prime API TypeScript SDK. This TypeScript project was created to allow developers to easily plug into the [Coinbase Prime API](https://docs.cdp.coinbase.com/prime/docs/welcome).
6
+ ## Overview
6
7
 
7
- ---
8
+ Welcome to the Coinbase Prime API TypeScript SDK. This TypeScript project provides a comprehensive, type-safe interface to the [Coinbase Prime API](https://docs.cdp.coinbase.com/prime/docs/welcome) with multiple consumption patterns optimized for different use cases.
8
9
 
9
10
  ## License
10
11
 
@@ -12,109 +13,248 @@ The _Prime Typescript SDK_ sample library is free and open source and released u
12
13
 
13
14
  The application and code are only available for demonstration purposes.
14
15
 
15
- ## Pagination
16
+ ## 🚀 Quick Start
16
17
 
17
- When creating the client, you can now specify a maxItems and maxPages to help manage paginated responses.
18
+ ### Installation
18
19
 
19
- ```
20
- const client = new CoinbasePrimeClient(credentials, undefined, { maxPages: 5, maxItems: 1000 });
20
+ ```bash
21
+ npm install @coinbase-sample/prime-sdk-ts
21
22
  ```
22
23
 
23
- These values can also be added on a per paginated request, such as:
24
+ ### Basic Usage (Recommended)
24
25
 
25
- ```
26
- const client = new CoinbasePrimeClient(credentials);
26
+ The SDK provides a **modular client** with lazy-loaded services for the best developer experience:
27
+
28
+ ```typescript
29
+ import { CoinbasePrimeClientWithServices } from '@coinbase-sample/prime-sdk-ts';
27
30
 
28
- const service = new TransactionsService(client);
31
+ // Create client from environment variables
32
+ const client = CoinbasePrimeClientWithServices.fromEnv();
29
33
 
30
- service
31
- .listPortfolioTransactions(
32
- { portfolioId, limit: 100 },
33
- { maxPages: 20, maxItems: 1000 }
34
- )
34
+ // Access services directly - no manual instantiation needed!
35
+ const portfolios = await client.portfolios.listPortfolios();
36
+ const orders = await client.orders.listPortfolioOrders({ portfolioId: 'your-id' });
37
+ const wallets = await client.wallets.listWallets({ portfolioId: 'your-id' });
35
38
  ```
36
39
 
37
- ## Usage
40
+ ### Environment Setup
38
41
 
39
- Here are a few examples requests:
42
+ Copy `env.example` to `.env` and populate with your values:
40
43
 
41
- **[List Portfolios](https://docs.cdp.coinbase.com/prime/reference/primerestapi_getportfolios)**
44
+ ```bash
45
+ cp env.example .env
46
+ ```
47
+
48
+ Then edit `.env` with your actual credentials:
49
+ ```env
50
+ # API Credentials (JSON format)
51
+ PRIME_CREDENTIALS={"AccessKey":"your-access-key","SecretKey":"your-secret-key","Passphrase":"your-passphrase"}
42
52
 
53
+ # Required IDs
54
+ ENTITY_ID=your-entity-id
55
+ PORTFOLIO_ID=your-portfolio-id
56
+ WALLET_ID=your-wallet-id
43
57
  ```
44
- client
45
- .listPortfolios()
46
- .then((result) => {
47
- console.log(result);
48
- })
49
- .catch((error) => {
50
- console.error(error.message);
51
- });
58
+
59
+ ## 📚 Usage Examples
60
+
61
+ ### **List Portfolios**
62
+ ```typescript
63
+ const portfolios = await client.portfolios.listPortfolios();
64
+ console.log(portfolios.portfolios);
52
65
  ```
53
66
 
54
- **[Get Assets](https://docs.cdp.coinbase.com/prime/reference/primerestapi_getentityassets)**
67
+ ### **Get Assets**
68
+ ```typescript
69
+ const assets = await client.assets.listAssets({
70
+ entityId: portfolioId
71
+ });
72
+ console.log(assets.assets);
73
+ ```
55
74
 
75
+ ### **Create Order**
76
+ ```typescript
77
+ import { OrderSide, OrderType } from '@coinbase-sample/prime-sdk-ts';
78
+
79
+ const order = await client.orders.createOrder({
80
+ portfolioId: 'your-portfolio-id',
81
+ productId: 'BTC-USD',
82
+ side: OrderSide.BUY,
83
+ type: OrderType.MARKET,
84
+ baseQuantity: '0.001'
85
+ });
86
+ console.log(order.orderId);
56
87
  ```
57
- client
58
- .listAssets({entityId: "somePortfolioId"})
59
- .then((result) => {
60
- console.log(result);
61
- })
62
- .catch((error) => {
63
- console.error(error.message);
64
- });
88
+
89
+ See the example folder for more robust examples for many of the available services and endpoints.
90
+
91
+ ## 🔧 Configuration Options
92
+
93
+ ### Pagination Control
94
+
95
+ The SDK provides powerful pagination controls at both the client and request level:
96
+
97
+ ```typescript
98
+ const client = CoinbasePrimeClientWithServices.fromEnv(undefined, {
99
+ maxPages: 5, // Max pages to fetch automatically
100
+ maxItems: 1000, // Max total items across all pages
101
+ defaultLimit: 100 // Items per page
102
+ });
103
+
104
+ // Or per-request
105
+ const response = await client.transactions.listPortfolioTransactions(
106
+ { portfolioId, limit: 50 },
107
+ { maxPages: 10, maxItems: 500 }
108
+ );
65
109
  ```
66
110
 
67
- **[Create Order](https://docs.cdp.coinbase.com/prime/reference/primerestapi_createorder)**
111
+ ### Advanced Pagination Methods
68
112
 
69
- _$10 Market Buy on BTC-USD_
113
+ All paginated responses include powerful methods for manual pagination control:
70
114
 
115
+ ```typescript
116
+ // Get the first page
117
+ const firstPage = await client.transactions.listPortfolioTransactions({ portfolioId });
118
+
119
+ // Check if there are more pages
120
+ if (firstPage.hasNext()) {
121
+ console.log('More data available');
122
+ }
123
+
124
+ // Get the next page manually
125
+ const secondPage = await firstPage.next();
126
+
127
+ // Fetch ALL remaining pages and combine the data
128
+ const allTransactions = await firstPage.fetchAll(
129
+ undefined, // options
130
+ (page, totalItems) => console.log(`Fetched page ${page}, total items: ${totalItems}`)
131
+ );
132
+
133
+ // Example: Manual pagination loop
134
+ let currentPage = firstPage;
135
+ while (currentPage.hasNext()) {
136
+ console.log(`Processing ${currentPage.transactions.length} transactions`);
137
+ currentPage = await currentPage.next();
138
+ }
71
139
  ```
72
- client
73
- .createOrder({
74
- portfolioId: "somePortfolioId",
75
- productId: "BTC-USD",
76
- side: OrderSide.BUY,
77
- type: OrderType.Market,
78
- baseQuantity: "0.0001"
79
- })
80
- .then((result) => {
81
- console.log(result);
82
- })
83
- .catch((error) => {
84
- console.error(error.message);
85
- });
140
+
141
+ #### Pagination Methods
142
+
143
+ | Method | Description | Returns |
144
+ |--------|-------------|---------|
145
+ | **`hasNext()`** | Check if more pages are available | `boolean` |
146
+ | **`next()`** | Fetch the next page | `Promise<Response \| null>` |
147
+ | **`fetchAll()`** | Fetch all remaining pages and combine data | `Promise<DataArray[]>` |
148
+ | **`getNextCursor()`** | Get the next page cursor | `string \| undefined` |
149
+
150
+ ## 📦 Alternative Import Patterns
151
+
152
+ While the **modular client** (`CoinbasePrimeClientWithServices`) is recommended for most use cases, the SDK provides additional import patterns optimized for specific scenarios:
153
+
154
+ ### 🎯 For Bundle Size Optimization
155
+
156
+ #### **Manual Client** (`@coinbase-sample/prime-sdk-ts/manual`)
157
+ When you need full control over service instantiation:
158
+
159
+ ```typescript
160
+ import { CoinbasePrimeClient, OrdersService, WalletsService } from '@coinbase-sample/prime-sdk-ts/manual';
161
+
162
+ const client = CoinbasePrimeClient.fromEnv();
163
+ const orders = new OrdersService(client);
164
+ const wallets = new WalletsService(client);
165
+
166
+ // Only the services you import are included in your bundle
86
167
  ```
87
168
 
88
- ## Development Installation
169
+ #### **Ultra-Minimal Client** (`@coinbase-sample/prime-sdk-ts/client`)
170
+ For services-only patterns (97% smaller bundles):
89
171
 
90
- ```bash
91
- npm install
172
+ ```typescript
173
+ import { CoinbasePrimeClient } from '@coinbase-sample/prime-sdk-ts/client';
174
+ import { OrdersService } from '@coinbase-sample/prime-sdk-ts/services';
175
+
176
+ const client = CoinbasePrimeClient.fromEnv();
177
+ const orders = new OrdersService(client);
178
+ // Total bundle: ~3kb (perfect for microservices)
92
179
  ```
93
180
 
94
- ---
181
+ ### 📊 Bundle Size Comparison
95
182
 
96
- ## Build and Use
183
+ | Import Pattern | Bundle Size | Use Case |
184
+ |----------------|-------------|----------|
185
+ | **Modular Client** (recommended) | ~30kb | Best developer experience |
186
+ | **Manual Client** | ~90kb | Full control, all services available |
187
+ | **Services + Client** | ~6kb | Custom implementations |
188
+ | **Individual Service** | ~3kb | Microservices, Lambda functions |
97
189
 
98
- To build the project, run the following command:
190
+ ### 🎨 Type-Only Imports
99
191
 
100
- ```bash
101
- npm run build
192
+ For shared libraries or type definitions:
193
+
194
+ ```typescript
195
+ import type { CreateOrderRequest, OrderSide } from '@coinbase-sample/prime-sdk-ts/types';
196
+ // 0kb runtime - perfect for shared type libraries
102
197
  ```
103
198
 
104
- _Note: To avoid potential issues, do not forget to build your project again after making any changes to it._
199
+ ## 🤔 When to Use Which?
105
200
 
106
- After building the project, each `.ts` file will have its `.js` counterpart generated.
201
+ - **🏆 Modular Client**: Default choice - best DX, good performance
202
+ - **⚡ Manual Client**: Need all services, want explicit control
203
+ - **🎯 Services-Only**: Microservices, custom clients, minimal bundles
204
+ - **📦 Individual Services**: Lambda functions, single-purpose apps
205
+ - **📝 Types-Only**: Shared libraries, type definitions
107
206
 
108
- To run a file, use the following command:
207
+ ## 🛠️ Development
109
208
 
209
+ ### Installation
210
+ ```bash
211
+ git clone https://github.com/coinbase-samples/prime-sdk-ts.git
212
+ cd prime-sdk-ts
213
+ npm install
110
214
  ```
111
- node dist/{INSERT-FILENAME}.js
215
+
216
+ ### Build
217
+ ```bash
218
+ npm run build
112
219
  ```
113
220
 
114
- For example, a `main.ts` file would be run like:
221
+ ### Run Examples
222
+ The SDK includes comprehensive examples in the `example/` directory:
115
223
 
116
224
  ```bash
117
- node dist/main.js
225
+ # Set up environment (copy env.example to .env first)
226
+ cp env.example .env
227
+ # Edit .env with your actual entityId, portfolioId, and walletId
228
+
229
+ # Run examples
230
+ node example/listPortfolios.js
231
+ node example/createOrder.js
232
+ node example/listWallets.js TRADING
118
233
  ```
119
234
 
120
- ---
235
+ ## 🧪 TypeScript Support
236
+
237
+ The SDK is built with TypeScript and provides full type safety:
238
+
239
+ ```typescript
240
+ import {
241
+ CoinbasePrimeClientWithServices,
242
+ OrderSide,
243
+ OrderType,
244
+ CreateOrderRequest
245
+ } from '@coinbase-sample/prime-sdk-ts';
246
+
247
+ const client = CoinbasePrimeClientWithServices.fromEnv();
248
+
249
+ // Full IntelliSense and type checking
250
+ const request: CreateOrderRequest = {
251
+ portfolioId: 'your-id',
252
+ productId: 'BTC-USD',
253
+ side: OrderSide.BUY, // Enum with autocomplete
254
+ type: OrderType.MARKET,
255
+ baseQuantity: '0.001'
256
+ };
257
+
258
+ const order = await client.orders.createOrder(request);
259
+ // Response is fully typed - no manual type assertions needed
260
+ ```
@@ -23,6 +23,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
24
  });
25
25
  };
26
+ var __rest = (this && this.__rest) || function (s, e) {
27
+ var t = {};
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
29
+ t[p] = s[p];
30
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
31
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
32
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
33
+ t[p[i]] = s[p[i]];
34
+ }
35
+ return t;
36
+ };
26
37
  Object.defineProperty(exports, "__esModule", { value: true });
27
38
  exports.ActivitiesService = void 0;
28
39
  const paginatedResponse_1 = require("../shared/paginatedResponse");
@@ -50,28 +61,12 @@ class ActivitiesService {
50
61
  }
51
62
  listEntityActivities(request, options) {
52
63
  return __awaiter(this, void 0, void 0, function* () {
53
- let queryParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
54
- if (request.startTime) {
55
- queryParams.startTime = new Date(request.startTime).toISOString();
56
- }
57
- if (request.endTime) {
58
- queryParams.endTime = new Date(request.endTime).toISOString();
59
- }
60
- if (request.statuses) {
61
- queryParams.statuses = request.statuses;
62
- }
63
- if (request.categories) {
64
- queryParams.categories = request.categories;
65
- }
66
- if (request.symbols) {
67
- queryParams.symbols = request.symbols;
68
- }
69
- if (request.activityLevel) {
70
- queryParams.activityLevel = request.activityLevel;
71
- }
64
+ const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
65
+ const { limit, cursor, sortDirection, entityId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "entityId"]);
66
+ const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
72
67
  const response = yield this.client.request({
73
- url: `entities/${request.entityId}/activities`,
74
- queryParams,
68
+ url: `entities/${entityId}/activities`,
69
+ queryParams: finalQueryParams,
75
70
  callOptions: options,
76
71
  });
77
72
  const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);
@@ -80,25 +75,12 @@ class ActivitiesService {
80
75
  }
81
76
  listPortfolioActivities(request, options) {
82
77
  return __awaiter(this, void 0, void 0, function* () {
83
- const queryParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
84
- if (request.startTime) {
85
- queryParams.startTime = new Date(request.startTime).toISOString();
86
- }
87
- if (request.endTime) {
88
- queryParams.endTime = new Date(request.endTime).toISOString();
89
- }
90
- if (request.statuses) {
91
- queryParams.statuses = request.statuses;
92
- }
93
- if (request.categories) {
94
- queryParams.categories = request.categories;
95
- }
96
- if (request.symbols) {
97
- queryParams.symbols = request.symbols;
98
- }
78
+ const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
79
+ const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
80
+ const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
99
81
  const response = yield this.client.request({
100
- url: `portfolios/${request.portfolioId}/activities`,
101
- queryParams,
82
+ url: `portfolios/${portfolioId}/activities`,
83
+ queryParams: finalQueryParams,
102
84
  callOptions: options,
103
85
  });
104
86
  const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.AddressBooksService = void 0;
13
24
  /**
@@ -25,7 +36,7 @@ exports.AddressBooksService = void 0;
25
36
  * See the License for the specific language governing permissions and
26
37
  * limitations under the License.
27
38
  */
28
- const core_ts_1 = require("@coinbase-sample/core-ts");
39
+ const clients_1 = require("../clients");
29
40
  const paginatedResponse_1 = require("../shared/paginatedResponse");
30
41
  class AddressBooksService {
31
42
  constructor(client) {
@@ -33,10 +44,12 @@ class AddressBooksService {
33
44
  }
34
45
  listAddressBooks(request, options) {
35
46
  return __awaiter(this, void 0, void 0, function* () {
36
- const queryParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
47
+ const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
48
+ const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
49
+ const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
37
50
  const response = yield this.client.request({
38
- url: `portfolios/${request.portfolioId}/address_book`,
39
- queryParams,
51
+ url: `portfolios/${portfolioId}/address_book`,
52
+ queryParams: finalQueryParams,
40
53
  callOptions: options,
41
54
  });
42
55
  const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);
@@ -49,7 +62,7 @@ class AddressBooksService {
49
62
  const response = yield this.client.request({
50
63
  url: `portfolios/${request.portfolioId}/address_book`,
51
64
  bodyParams,
52
- method: core_ts_1.Method.POST,
65
+ method: clients_1.Method.POST,
53
66
  callOptions: options,
54
67
  });
55
68
  return response.data;
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.AllocationService = void 0;
13
24
  /**
@@ -25,7 +36,7 @@ exports.AllocationService = void 0;
25
36
  * See the License for the specific language governing permissions and
26
37
  * limitations under the License.
27
38
  */
28
- const core_ts_1 = require("@coinbase-sample/core-ts");
39
+ const clients_1 = require("../clients");
29
40
  const paginatedResponse_1 = require("../shared/paginatedResponse");
30
41
  class AllocationService {
31
42
  constructor(client) {
@@ -36,7 +47,7 @@ class AllocationService {
36
47
  const response = yield this.client.request({
37
48
  url: `allocations`,
38
49
  bodyParams: request,
39
- method: core_ts_1.Method.POST,
50
+ method: clients_1.Method.POST,
40
51
  callOptions: options,
41
52
  });
42
53
  return response.data;
@@ -47,7 +58,7 @@ class AllocationService {
47
58
  const response = yield this.client.request({
48
59
  url: `allocations/net`,
49
60
  bodyParams: request,
50
- method: core_ts_1.Method.POST,
61
+ method: clients_1.Method.POST,
51
62
  callOptions: options,
52
63
  });
53
64
  return response.data;
@@ -55,22 +66,12 @@ class AllocationService {
55
66
  }
56
67
  listPortfolioAllocations(request, options) {
57
68
  return __awaiter(this, void 0, void 0, function* () {
58
- let queryParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
59
- if (request.startDate) {
60
- queryParams.startDate = new Date(request.startDate).toISOString();
61
- }
62
- if (request.endDate) {
63
- queryParams.endDate = new Date(request.endDate).toISOString();
64
- }
65
- if (request.productIds) {
66
- queryParams.productIds = request.productIds;
67
- }
68
- if (request.orderSide) {
69
- queryParams.orderSide = request.orderSide;
70
- }
69
+ const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
70
+ const { limit, cursor, sortDirection, portfolioId } = request, queryParams = __rest(request, ["limit", "cursor", "sortDirection", "portfolioId"]);
71
+ const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
71
72
  const response = yield this.client.request({
72
- url: `portfolios/${request.portfolioId}/allocations`,
73
- queryParams,
73
+ url: `portfolios/${portfolioId}/allocations`,
74
+ queryParams: finalQueryParams,
74
75
  callOptions: options,
75
76
  });
76
77
  const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.BalancesService = void 0;
13
24
  const paginatedResponse_1 = require("../shared/paginatedResponse");
@@ -17,9 +28,9 @@ class BalancesService {
17
28
  }
18
29
  listPortfolioBalances(request, options) {
19
30
  return __awaiter(this, void 0, void 0, function* () {
20
- const queryParams = Object.assign(Object.assign({}, request), { portfolioId: undefined });
31
+ const { portfolioId } = request, queryParams = __rest(request, ["portfolioId"]);
21
32
  const response = yield this.client.request({
22
- url: `portfolios/${request.portfolioId}/balances`,
33
+ url: `portfolios/${portfolioId}/balances`,
23
34
  queryParams,
24
35
  callOptions: options,
25
36
  });
@@ -37,13 +48,12 @@ class BalancesService {
37
48
  }
38
49
  listOnchainWalletBalances(request, options) {
39
50
  return __awaiter(this, void 0, void 0, function* () {
40
- let queryParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
41
- if (request.visibilityStatuses) {
42
- queryParams.visibilityStatuses = request.visibilityStatuses;
43
- }
51
+ const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
52
+ const { limit, cursor, portfolioId, walletId } = request, queryParams = __rest(request, ["limit", "cursor", "portfolioId", "walletId"]);
53
+ const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
44
54
  const response = yield this.client.request({
45
- url: `portfolios/${request.portfolioId}/wallets/${request.walletId}/web3_balances`,
46
- queryParams,
55
+ url: `portfolios/${portfolioId}/wallets/${walletId}/web3_balances`,
56
+ queryParams: finalQueryParams,
47
57
  callOptions: options,
48
58
  });
49
59
  const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);
@@ -52,16 +62,12 @@ class BalancesService {
52
62
  }
53
63
  listEntityBalances(request, options) {
54
64
  return __awaiter(this, void 0, void 0, function* () {
55
- let queryParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
56
- if (request.symbols) {
57
- queryParams.symbols = request.symbols;
58
- }
59
- if (request.aggregationType) {
60
- queryParams.aggregationType = request.aggregationType;
61
- }
65
+ const paginationParams = (0, paginatedResponse_1.getQueryParams)(this.client, request);
66
+ const { limit, cursor, entityId } = request, queryParams = __rest(request, ["limit", "cursor", "entityId"]);
67
+ const finalQueryParams = Object.assign(Object.assign({}, paginationParams), queryParams);
62
68
  const response = yield this.client.request({
63
- url: `entities/${request.entityId}/balances`,
64
- queryParams,
69
+ url: `entities/${entityId}/balances`,
70
+ queryParams: finalQueryParams,
65
71
  callOptions: options,
66
72
  });
67
73
  const paginationOptions = (0, paginatedResponse_1.getDefaultPaginationOptions)(this.client, options);