@coinbase-sample/prime-sdk-ts 0.6.2 → 0.6.4

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 (77) hide show
  1. package/README.md +207 -67
  2. package/dist/addressBooks/index.js +2 -2
  3. package/dist/allocations/index.js +3 -3
  4. package/dist/client-manual.js +84 -0
  5. package/dist/client-modular.js +57 -0
  6. package/dist/client-only.js +31 -0
  7. package/dist/{client.js → clients/client.js} +12 -2
  8. package/dist/clients/clientWithServices.js +323 -0
  9. package/dist/{types/client.d.ts → clients/clientWithServicesTypes.js} +3 -6
  10. package/dist/clients/index.js +28 -0
  11. package/dist/clients/types.js +2 -0
  12. package/dist/constants.js +1 -1
  13. package/dist/futures/index.js +4 -4
  14. package/dist/index.js +27 -18
  15. package/dist/model/enumPrefixes.js +330 -0
  16. package/dist/onchainAddressBook/index.js +4 -4
  17. package/dist/orders/index.js +6 -6
  18. package/dist/paymentMethods/index.js +2 -1
  19. package/dist/services.js +75 -0
  20. package/dist/shared/dynamicEnumValidation.js +184 -0
  21. package/dist/shared/dynamicEnumValidation.old.js +746 -0
  22. package/dist/shared/enumHelpers.js +219 -0
  23. package/dist/shared/enumRegistry.js +153 -0
  24. package/dist/shared/enumValidationCore.js +194 -0
  25. package/dist/shared/enumValidators.js +115 -0
  26. package/dist/shared/envUtils.js +66 -0
  27. package/dist/shared/fieldMapping.js +242 -0
  28. package/dist/shared/serviceContext.js +157 -0
  29. package/dist/staking/index.js +5 -5
  30. package/dist/transactions/index.js +5 -5
  31. package/dist/types/activities/index.d.ts +2 -3
  32. package/dist/types/addressBooks/index.d.ts +2 -3
  33. package/dist/types/allocations/index.d.ts +2 -3
  34. package/dist/types/assets/index.d.ts +2 -3
  35. package/dist/types/balances/index.d.ts +2 -3
  36. package/dist/types/balances/types.d.ts +1 -1
  37. package/dist/types/client-manual.d.ts +58 -0
  38. package/dist/types/client-modular.d.ts +39 -0
  39. package/dist/types/client-only.d.ts +18 -0
  40. package/dist/types/clients/client.d.ts +27 -0
  41. package/dist/types/clients/clientWithServices.d.ts +229 -0
  42. package/dist/types/clients/clientWithServicesTypes.d.ts +115 -0
  43. package/dist/types/clients/index.d.ts +19 -0
  44. package/dist/types/clients/types.d.ts +48 -0
  45. package/dist/types/commission/index.d.ts +2 -3
  46. package/dist/types/constants.d.ts +1 -1
  47. package/dist/types/financing/index.d.ts +2 -3
  48. package/dist/types/futures/index.d.ts +2 -3
  49. package/dist/types/index.d.ts +2 -1
  50. package/dist/types/invoices/index.d.ts +2 -3
  51. package/dist/types/model/enumPrefixes.d.ts +206 -0
  52. package/dist/types/onchainAddressBook/index.d.ts +2 -3
  53. package/dist/types/orders/index.d.ts +2 -3
  54. package/dist/types/paymentMethods/index.d.ts +2 -3
  55. package/dist/types/paymentMethods/types.d.ts +1 -0
  56. package/dist/types/portfolios/index.d.ts +2 -3
  57. package/dist/types/positions/index.d.ts +2 -3
  58. package/dist/types/products/index.d.ts +2 -3
  59. package/dist/types/services.d.ts +39 -0
  60. package/dist/types/shared/dynamicEnumValidation.d.ts +48 -0
  61. package/dist/types/shared/dynamicEnumValidation.old.d.ts +143 -0
  62. package/dist/types/shared/enumHelpers.d.ts +135 -0
  63. package/dist/types/shared/enumRegistry.d.ts +74 -0
  64. package/dist/types/shared/enumValidationCore.d.ts +68 -0
  65. package/dist/types/shared/enumValidators.d.ts +117 -0
  66. package/dist/types/shared/envUtils.d.ts +36 -0
  67. package/dist/types/shared/fieldMapping.d.ts +35 -0
  68. package/dist/types/shared/paginatedResponse.d.ts +3 -4
  69. package/dist/types/shared/serviceContext.d.ts +46 -0
  70. package/dist/types/staking/index.d.ts +2 -3
  71. package/dist/types/transactions/index.d.ts +2 -3
  72. package/dist/types/types.d.ts +37 -0
  73. package/dist/types/users/index.d.ts +2 -3
  74. package/dist/types/wallets/index.d.ts +2 -3
  75. package/dist/types.js +39 -0
  76. package/dist/wallets/index.js +3 -3
  77. package/package.json +33 -2
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
+ ```
@@ -36,7 +36,7 @@ exports.AddressBooksService = void 0;
36
36
  * See the License for the specific language governing permissions and
37
37
  * limitations under the License.
38
38
  */
39
- const core_ts_1 = require("@coinbase-sample/core-ts");
39
+ const clients_1 = require("../clients");
40
40
  const paginatedResponse_1 = require("../shared/paginatedResponse");
41
41
  class AddressBooksService {
42
42
  constructor(client) {
@@ -62,7 +62,7 @@ class AddressBooksService {
62
62
  const response = yield this.client.request({
63
63
  url: `portfolios/${request.portfolioId}/address_book`,
64
64
  bodyParams,
65
- method: core_ts_1.Method.POST,
65
+ method: clients_1.Method.POST,
66
66
  callOptions: options,
67
67
  });
68
68
  return response.data;
@@ -36,7 +36,7 @@ exports.AllocationService = void 0;
36
36
  * See the License for the specific language governing permissions and
37
37
  * limitations under the License.
38
38
  */
39
- const core_ts_1 = require("@coinbase-sample/core-ts");
39
+ const clients_1 = require("../clients");
40
40
  const paginatedResponse_1 = require("../shared/paginatedResponse");
41
41
  class AllocationService {
42
42
  constructor(client) {
@@ -47,7 +47,7 @@ class AllocationService {
47
47
  const response = yield this.client.request({
48
48
  url: `allocations`,
49
49
  bodyParams: request,
50
- method: core_ts_1.Method.POST,
50
+ method: clients_1.Method.POST,
51
51
  callOptions: options,
52
52
  });
53
53
  return response.data;
@@ -58,7 +58,7 @@ class AllocationService {
58
58
  const response = yield this.client.request({
59
59
  url: `allocations/net`,
60
60
  bodyParams: request,
61
- method: core_ts_1.Method.POST,
61
+ method: clients_1.Method.POST,
62
62
  callOptions: options,
63
63
  });
64
64
  return response.data;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025-present Coinbase Global, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.WalletsService = exports.UsersService = exports.TransactionsService = exports.StakingService = exports.ProductsService = exports.PositionsService = exports.PortfoliosService = exports.PaymentMethodsService = exports.OrdersService = exports.OnchainAddressBookService = exports.InvoicesService = exports.FuturesService = exports.FinancingService = exports.CommissionService = exports.BalancesService = exports.AssetsService = exports.AllocationService = exports.AddressBooksService = exports.ActivitiesService = exports.createCredentialsFromEnv = exports.CoinbasePrimeCredentials = exports.CoinbaseError = exports.CoinbaseClientException = exports.Method = exports.CoinbaseClient = exports.CoinbasePrimeClient = void 0;
33
+ // Manual client entry point - for users who prefer manual service instantiation
34
+ // with comprehensive type exports and full control over service lifecycle
35
+ var clients_1 = require("./clients");
36
+ Object.defineProperty(exports, "CoinbasePrimeClient", { enumerable: true, get: function () { return clients_1.CoinbasePrimeClient; } });
37
+ Object.defineProperty(exports, "CoinbaseClient", { enumerable: true, get: function () { return clients_1.CoinbaseClient; } });
38
+ Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return clients_1.Method; } });
39
+ Object.defineProperty(exports, "CoinbaseClientException", { enumerable: true, get: function () { return clients_1.CoinbaseClientException; } });
40
+ Object.defineProperty(exports, "CoinbaseError", { enumerable: true, get: function () { return clients_1.CoinbaseError; } });
41
+ var credentials_1 = require("./credentials");
42
+ Object.defineProperty(exports, "CoinbasePrimeCredentials", { enumerable: true, get: function () { return credentials_1.CoinbasePrimeCredentials; } });
43
+ var envUtils_1 = require("./shared/envUtils");
44
+ Object.defineProperty(exports, "createCredentialsFromEnv", { enumerable: true, get: function () { return envUtils_1.createCredentialsFromEnv; } });
45
+ // Export all individual services for manual instantiation
46
+ var activities_1 = require("./activities");
47
+ Object.defineProperty(exports, "ActivitiesService", { enumerable: true, get: function () { return activities_1.ActivitiesService; } });
48
+ var addressBooks_1 = require("./addressBooks");
49
+ Object.defineProperty(exports, "AddressBooksService", { enumerable: true, get: function () { return addressBooks_1.AddressBooksService; } });
50
+ var allocations_1 = require("./allocations");
51
+ Object.defineProperty(exports, "AllocationService", { enumerable: true, get: function () { return allocations_1.AllocationService; } });
52
+ var assets_1 = require("./assets");
53
+ Object.defineProperty(exports, "AssetsService", { enumerable: true, get: function () { return assets_1.AssetsService; } });
54
+ var balances_1 = require("./balances");
55
+ Object.defineProperty(exports, "BalancesService", { enumerable: true, get: function () { return balances_1.BalancesService; } });
56
+ var commission_1 = require("./commission");
57
+ Object.defineProperty(exports, "CommissionService", { enumerable: true, get: function () { return commission_1.CommissionService; } });
58
+ var financing_1 = require("./financing");
59
+ Object.defineProperty(exports, "FinancingService", { enumerable: true, get: function () { return financing_1.FinancingService; } });
60
+ var futures_1 = require("./futures");
61
+ Object.defineProperty(exports, "FuturesService", { enumerable: true, get: function () { return futures_1.FuturesService; } });
62
+ var invoices_1 = require("./invoices");
63
+ Object.defineProperty(exports, "InvoicesService", { enumerable: true, get: function () { return invoices_1.InvoicesService; } });
64
+ var onchainAddressBook_1 = require("./onchainAddressBook");
65
+ Object.defineProperty(exports, "OnchainAddressBookService", { enumerable: true, get: function () { return onchainAddressBook_1.OnchainAddressBookService; } });
66
+ var orders_1 = require("./orders");
67
+ Object.defineProperty(exports, "OrdersService", { enumerable: true, get: function () { return orders_1.OrdersService; } });
68
+ var paymentMethods_1 = require("./paymentMethods");
69
+ Object.defineProperty(exports, "PaymentMethodsService", { enumerable: true, get: function () { return paymentMethods_1.PaymentMethodsService; } });
70
+ var portfolios_1 = require("./portfolios");
71
+ Object.defineProperty(exports, "PortfoliosService", { enumerable: true, get: function () { return portfolios_1.PortfoliosService; } });
72
+ var positions_1 = require("./positions");
73
+ Object.defineProperty(exports, "PositionsService", { enumerable: true, get: function () { return positions_1.PositionsService; } });
74
+ var products_1 = require("./products");
75
+ Object.defineProperty(exports, "ProductsService", { enumerable: true, get: function () { return products_1.ProductsService; } });
76
+ var staking_1 = require("./staking");
77
+ Object.defineProperty(exports, "StakingService", { enumerable: true, get: function () { return staking_1.StakingService; } });
78
+ var transactions_1 = require("./transactions");
79
+ Object.defineProperty(exports, "TransactionsService", { enumerable: true, get: function () { return transactions_1.TransactionsService; } });
80
+ var users_1 = require("./users");
81
+ Object.defineProperty(exports, "UsersService", { enumerable: true, get: function () { return users_1.UsersService; } });
82
+ var wallets_1 = require("./wallets");
83
+ Object.defineProperty(exports, "WalletsService", { enumerable: true, get: function () { return wallets_1.WalletsService; } });
84
+ __exportStar(require("./model/enums/"), exports);
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025-present Coinbase Global, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.createCredentialsFromEnv = exports.CoinbasePrimeCredentials = exports.CoinbaseError = exports.CoinbaseClientException = exports.Method = exports.CoinbaseClient = exports.CoinbasePrimeClientWithServices = void 0;
33
+ // Modular client entry point - for users who want optimized bundle sizes
34
+ // with lazy-loaded services and modular type imports
35
+ var clients_1 = require("./clients");
36
+ Object.defineProperty(exports, "CoinbasePrimeClientWithServices", { enumerable: true, get: function () { return clients_1.CoinbasePrimeClientWithServices; } });
37
+ Object.defineProperty(exports, "CoinbaseClient", { enumerable: true, get: function () { return clients_1.CoinbaseClient; } });
38
+ Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return clients_1.Method; } });
39
+ Object.defineProperty(exports, "CoinbaseClientException", { enumerable: true, get: function () { return clients_1.CoinbaseClientException; } });
40
+ Object.defineProperty(exports, "CoinbaseError", { enumerable: true, get: function () { return clients_1.CoinbaseError; } });
41
+ var credentials_1 = require("./credentials");
42
+ Object.defineProperty(exports, "CoinbasePrimeCredentials", { enumerable: true, get: function () { return credentials_1.CoinbasePrimeCredentials; } });
43
+ var envUtils_1 = require("./shared/envUtils");
44
+ Object.defineProperty(exports, "createCredentialsFromEnv", { enumerable: true, get: function () { return envUtils_1.createCredentialsFromEnv; } });
45
+ __exportStar(require("./model/enums/"), exports);
46
+ // NOTE: Service-specific request/response types are NOT exported here.
47
+ // For optimal tree-shaking, import them from their dedicated modules:
48
+ //
49
+ // import type { CreateOrderRequest } from '@coinbase-sample/prime-sdk-ts/orders';
50
+ // import type { ListWalletsRequest } from '@coinbase-sample/prime-sdk-ts/wallets';
51
+ // import type { GetActivityRequest } from '@coinbase-sample/prime-sdk-ts/activities';
52
+ //
53
+ // Or import all service types at once:
54
+ // import type * from '@coinbase-sample/prime-sdk-ts/types';
55
+ //
56
+ // This design ensures the modular client bundle stays minimal while
57
+ // still providing access to all service interfaces for TypeScript support.
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025-present Coinbase Global, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createCredentialsFromEnv = exports.CoinbasePrimeCredentials = exports.CoinbaseError = exports.CoinbaseClientException = exports.Method = exports.CoinbaseClient = exports.CoinbasePrimeClientWithServices = exports.CoinbasePrimeClient = void 0;
19
+ // Client-only entry point - for ultra-minimal bundles when using services separately
20
+ // Perfect for services-only approach where you want the smallest possible client bundle
21
+ var clients_1 = require("./clients");
22
+ Object.defineProperty(exports, "CoinbasePrimeClient", { enumerable: true, get: function () { return clients_1.CoinbasePrimeClient; } });
23
+ Object.defineProperty(exports, "CoinbasePrimeClientWithServices", { enumerable: true, get: function () { return clients_1.CoinbasePrimeClientWithServices; } });
24
+ Object.defineProperty(exports, "CoinbaseClient", { enumerable: true, get: function () { return clients_1.CoinbaseClient; } });
25
+ Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return clients_1.Method; } });
26
+ Object.defineProperty(exports, "CoinbaseClientException", { enumerable: true, get: function () { return clients_1.CoinbaseClientException; } });
27
+ Object.defineProperty(exports, "CoinbaseError", { enumerable: true, get: function () { return clients_1.CoinbaseError; } });
28
+ var credentials_1 = require("./credentials");
29
+ Object.defineProperty(exports, "CoinbasePrimeCredentials", { enumerable: true, get: function () { return credentials_1.CoinbasePrimeCredentials; } });
30
+ var envUtils_1 = require("./shared/envUtils");
31
+ Object.defineProperty(exports, "createCredentialsFromEnv", { enumerable: true, get: function () { return envUtils_1.createCredentialsFromEnv; } });
@@ -17,8 +17,9 @@ exports.CoinbasePrimeClient = void 0;
17
17
  * limitations under the License.
18
18
  */
19
19
  const core_ts_1 = require("@coinbase-sample/core-ts");
20
- const constants_1 = require("./constants");
21
- const toCamelCase_1 = require("./shared/toCamelCase");
20
+ const constants_1 = require("../constants");
21
+ const toCamelCase_1 = require("../shared/toCamelCase");
22
+ const envUtils_1 = require("../shared/envUtils");
22
23
  class CoinbasePrimeClient extends core_ts_1.CoinbaseClient {
23
24
  constructor(credentials, apiBasePath, options) {
24
25
  const defaultClientOptions = Object.assign({ defaultLimit: constants_1.DEFAULT_PAGINATION_LIMIT, maxPages: constants_1.DEFAULT_MAX_PAGES, maxItems: constants_1.DEFAULT_MAX_ITEMS }, options);
@@ -32,5 +33,14 @@ class CoinbasePrimeClient extends core_ts_1.CoinbaseClient {
32
33
  return Object.assign(Object.assign({}, response), { data: (0, toCamelCase_1.toCamelCase)(response.data) });
33
34
  });
34
35
  }
36
+ /**
37
+ * Create a client from environment variables
38
+ * Requires PRIME_CREDENTIALS environment variable with JSON containing:
39
+ * { "AccessKey": "...", "SecretKey": "...", "Passphrase": "..." }
40
+ */
41
+ static fromEnv(apiBaseUrl, options) {
42
+ const credentials = (0, envUtils_1.createCredentialsFromEnv)();
43
+ return new CoinbasePrimeClient(credentials, apiBaseUrl, options);
44
+ }
35
45
  }
36
46
  exports.CoinbasePrimeClient = CoinbasePrimeClient;