@coinbase-sample/prime-sdk-ts 0.6.3 → 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.
package/dist/constants.js CHANGED
@@ -16,7 +16,7 @@ exports.DEFAULT_MAX_ITEMS = exports.DEFAULT_MAX_PAGES = exports.DEFAULT_PAGINATI
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- exports.VERSION = '0.6.3';
19
+ exports.VERSION = '0.6.4';
20
20
  exports.API_BASE_PATH = 'https://api.prime.coinbase.com/v1/';
21
21
  exports.USER_AGENT = 'coinbase-prime-ts/' + exports.VERSION;
22
22
  exports.CB_ACCESS_KEY_HEADER = 'X-CB-ACCESS-KEY';
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025-present Coinbase Global, Inc.
4
+ *
5
+ * This file is auto-generated during the type generation process.
6
+ * Do not edit manually - regenerate by running: npm run generate-types
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.ENUM_ANALYSIS = exports.GENERATED_ENUM_PREFIXES = void 0;
22
+ /**
23
+ * Auto-generated enum prefix patterns extracted from OpenAPI specification
24
+ * Total enums analyzed: 43
25
+ * Prefix patterns discovered: 77
26
+ */
27
+ exports.GENERATED_ENUM_PREFIXES = [
28
+ 'ACTION_',
29
+ 'ACTIVITY_CATEGORY_',
30
+ 'ACTIVITY_LEVEL_',
31
+ 'ACTIVITY_SECONDARY_',
32
+ 'ACTIVITY_STATUS_',
33
+ 'ACTIVITY_TYPE_',
34
+ 'ADDRESS_BOOK_',
35
+ 'ALLOCATION_STATUS_',
36
+ 'BALANCE_',
37
+ 'BENCHMARK_',
38
+ 'BILATERAL_',
39
+ 'BILLING_',
40
+ 'CHANGE_',
41
+ 'CLAIM_',
42
+ 'COINBASE_',
43
+ 'COMPLETE_',
44
+ 'CONCENTRATION_',
45
+ 'COUNTERPARTY_',
46
+ 'CRYPTO_',
47
+ 'DEPOSIT_',
48
+ 'DESTINATION_',
49
+ 'DESTINATION_PAYMENT_',
50
+ 'FCM_FUTURES_',
51
+ 'FCM_MARGIN_',
52
+ 'FCM_POSITION_',
53
+ 'FILL_OR_',
54
+ 'FULL_',
55
+ 'GOOD_UNTIL_',
56
+ 'HIERARCHY_TYPE_',
57
+ 'IMMEDIATE_OR_',
58
+ 'INTERNAL_',
59
+ 'INVOICE_STATE_',
60
+ 'INVOICE_TYPE_',
61
+ 'ITEM_',
62
+ 'ITEM_APPROVAL_',
63
+ 'LOAN_TYPE_',
64
+ 'MACRO_',
65
+ 'MARGIN_ADD_',
66
+ 'METHOD_',
67
+ 'MULTIPLE_',
68
+ 'NETWORK_FAMILY_',
69
+ 'NETWORK_TYPE_',
70
+ 'NO_SECONDARY_',
71
+ 'ONCHAIN_',
72
+ 'OTHER_',
73
+ 'OTHER_ACTIVITY_',
74
+ 'OTHER_TRANSACTION_',
75
+ 'PAYMENT_',
76
+ 'PORTFOLIO_',
77
+ 'POSITION_REFERENCE_',
78
+ 'PRIME_CUSTODY_',
79
+ 'PRODUCT_PERMISSION_',
80
+ 'PROXY_',
81
+ 'RATE_TYPE_',
82
+ 'REMOVE_AUTHORIZED_',
83
+ 'SHORT_',
84
+ 'SHORT_BIASED_',
85
+ 'SHORT_COLLATERAL_',
86
+ 'SINGLE_COIN_',
87
+ 'STAKE_ACCOUNT_',
88
+ 'STAKE_AUTHORIZE_',
89
+ 'STOP_',
90
+ 'SWEEP_',
91
+ 'TEAM_',
92
+ 'TOTAL_',
93
+ 'TRADE_',
94
+ 'TRADING_',
95
+ 'TRANSACTION_',
96
+ 'TRANSACTION_IMPORT_',
97
+ 'TRANSACTION_TYPE_',
98
+ 'UNIFIED_TOTAL_',
99
+ 'VAULT_',
100
+ 'VOTE_',
101
+ 'WALLET_TYPE_',
102
+ 'WALLET_VISIBILITY_',
103
+ 'WITHDRAWAL_',
104
+ 'WITHDRAW_',
105
+ ];
106
+ /**
107
+ * Detailed enum analysis for debugging and insights
108
+ */
109
+ exports.ENUM_ANALYSIS = {
110
+ totalEnums: 43,
111
+ discoveredPrefixes: 77,
112
+ prefixPatterns: exports.GENERATED_ENUM_PREFIXES,
113
+ enumDetails: [
114
+ {
115
+ name: 'CoinbaseCustodyApiActivityType',
116
+ valueCount: 29,
117
+ file: 'coinbaseCustodyApiActivityType.ts',
118
+ },
119
+ {
120
+ name: 'CoinbaseCustodyApiAddressBookType',
121
+ valueCount: 3,
122
+ file: 'coinbaseCustodyApiAddressBookType.ts',
123
+ },
124
+ {
125
+ name: 'CoinbasePublicRestApiAction',
126
+ valueCount: 5,
127
+ file: 'coinbasePublicRestApiAction.ts',
128
+ },
129
+ {
130
+ name: 'CoinbasePublicRestApiActivityCategory',
131
+ valueCount: 7,
132
+ file: 'coinbasePublicRestApiActivityCategory.ts',
133
+ },
134
+ {
135
+ name: 'CoinbasePublicRestApiActivityLevel',
136
+ valueCount: 3,
137
+ file: 'coinbasePublicRestApiActivityLevel.ts',
138
+ },
139
+ {
140
+ name: 'CoinbasePublicRestApiActivitySecondaryType',
141
+ valueCount: 7,
142
+ file: 'coinbasePublicRestApiActivitySecondaryType.ts',
143
+ },
144
+ {
145
+ name: 'CoinbasePublicRestApiActivityStatus',
146
+ valueCount: 7,
147
+ file: 'coinbasePublicRestApiActivityStatus.ts',
148
+ },
149
+ {
150
+ name: 'CoinbasePublicRestApiActivityType',
151
+ valueCount: 42,
152
+ file: 'coinbasePublicRestApiActivityType.ts',
153
+ },
154
+ {
155
+ name: 'CoinbasePublicRestApiAllocationSizeType',
156
+ valueCount: 3,
157
+ file: 'coinbasePublicRestApiAllocationSizeType.ts',
158
+ },
159
+ {
160
+ name: 'CoinbasePublicRestApiAllocationStatus',
161
+ valueCount: 5,
162
+ file: 'coinbasePublicRestApiAllocationStatus.ts',
163
+ },
164
+ {
165
+ name: 'CoinbasePublicRestApiAssetChangeType',
166
+ valueCount: 5,
167
+ file: 'coinbasePublicRestApiAssetChangeType.ts',
168
+ },
169
+ {
170
+ name: 'CoinbasePublicRestApiBenchmark',
171
+ valueCount: 5,
172
+ file: 'coinbasePublicRestApiBenchmark.ts',
173
+ },
174
+ {
175
+ name: 'CoinbasePublicRestApiDestinationType',
176
+ valueCount: 4,
177
+ file: 'coinbasePublicRestApiDestinationType.ts',
178
+ },
179
+ {
180
+ name: 'CoinbasePublicRestApiFcmFuturesSweepStatus',
181
+ valueCount: 5,
182
+ file: 'coinbasePublicRestApiFcmFuturesSweepStatus.ts',
183
+ },
184
+ {
185
+ name: 'CoinbasePublicRestApiFcmMarginCallState',
186
+ valueCount: 5,
187
+ file: 'coinbasePublicRestApiFcmMarginCallState.ts',
188
+ },
189
+ {
190
+ name: 'CoinbasePublicRestApiFcmMarginCallType',
191
+ valueCount: 3,
192
+ file: 'coinbasePublicRestApiFcmMarginCallType.ts',
193
+ },
194
+ {
195
+ name: 'CoinbasePublicRestApiFcmPositionSide',
196
+ valueCount: 3,
197
+ file: 'coinbasePublicRestApiFcmPositionSide.ts',
198
+ },
199
+ {
200
+ name: 'CoinbasePublicRestApiHierarchyType',
201
+ valueCount: 3,
202
+ file: 'coinbasePublicRestApiHierarchyType.ts',
203
+ },
204
+ {
205
+ name: 'CoinbasePublicRestApiInvoiceState',
206
+ valueCount: 5,
207
+ file: 'coinbasePublicRestApiInvoiceState.ts',
208
+ },
209
+ {
210
+ name: 'CoinbasePublicRestApiInvoiceType',
211
+ valueCount: 6,
212
+ file: 'coinbasePublicRestApiInvoiceType.ts',
213
+ },
214
+ {
215
+ name: 'CoinbasePublicRestApiLoanType',
216
+ valueCount: 6,
217
+ file: 'coinbasePublicRestApiLoanType.ts',
218
+ },
219
+ {
220
+ name: 'CoinbasePublicRestApiMarginAddOnType',
221
+ valueCount: 5,
222
+ file: 'coinbasePublicRestApiMarginAddOnType.ts',
223
+ },
224
+ {
225
+ name: 'CoinbasePublicRestApiNetworkFamily',
226
+ valueCount: 3,
227
+ file: 'coinbasePublicRestApiNetworkFamily.ts',
228
+ },
229
+ {
230
+ name: 'CoinbasePublicRestApiNetworkType',
231
+ valueCount: 3,
232
+ file: 'coinbasePublicRestApiNetworkType.ts',
233
+ },
234
+ {
235
+ name: 'CoinbasePublicRestApiOrderSide',
236
+ valueCount: 2,
237
+ file: 'coinbasePublicRestApiOrderSide.ts',
238
+ },
239
+ {
240
+ name: 'CoinbasePublicRestApiOrderStatus',
241
+ valueCount: 6,
242
+ file: 'coinbasePublicRestApiOrderStatus.ts',
243
+ },
244
+ {
245
+ name: 'CoinbasePublicRestApiOrderType',
246
+ valueCount: 7,
247
+ file: 'coinbasePublicRestApiOrderType.ts',
248
+ },
249
+ {
250
+ name: 'CoinbasePublicRestApiPaymentMethodType',
251
+ valueCount: 3,
252
+ file: 'coinbasePublicRestApiPaymentMethodType.ts',
253
+ },
254
+ {
255
+ name: 'CoinbasePublicRestApiPortfolioBalanceType',
256
+ valueCount: 5,
257
+ file: 'coinbasePublicRestApiPortfolioBalanceType.ts',
258
+ },
259
+ {
260
+ name: 'CoinbasePublicRestApiPositionReferenceType',
261
+ valueCount: 3,
262
+ file: 'coinbasePublicRestApiPositionReferenceType.ts',
263
+ },
264
+ {
265
+ name: 'CoinbasePublicRestApiProductPermissions',
266
+ valueCount: 3,
267
+ file: 'coinbasePublicRestApiProductPermissions.ts',
268
+ },
269
+ {
270
+ name: 'CoinbasePublicRestApiRateType',
271
+ valueCount: 5,
272
+ file: 'coinbasePublicRestApiRateType.ts',
273
+ },
274
+ {
275
+ name: 'CoinbasePublicRestApiSigningStatus',
276
+ valueCount: 2,
277
+ file: 'coinbasePublicRestApiSigningStatus.ts',
278
+ },
279
+ {
280
+ name: 'CoinbasePublicRestApiSortDirection',
281
+ valueCount: 2,
282
+ file: 'coinbasePublicRestApiSortDirection.ts',
283
+ },
284
+ {
285
+ name: 'CoinbasePublicRestApiTimeInForceType',
286
+ valueCount: 4,
287
+ file: 'coinbasePublicRestApiTimeInForceType.ts',
288
+ },
289
+ {
290
+ name: 'CoinbasePublicRestApiTransactionStatus',
291
+ valueCount: 21,
292
+ file: 'coinbasePublicRestApiTransactionStatus.ts',
293
+ },
294
+ {
295
+ name: 'CoinbasePublicRestApiTransactionType',
296
+ valueCount: 33,
297
+ file: 'coinbasePublicRestApiTransactionType.ts',
298
+ },
299
+ {
300
+ name: 'CoinbasePublicRestApiTransferLocationType',
301
+ valueCount: 6,
302
+ file: 'coinbasePublicRestApiTransferLocationType.ts',
303
+ },
304
+ {
305
+ name: 'CoinbasePublicRestApiUserRole',
306
+ valueCount: 9,
307
+ file: 'coinbasePublicRestApiUserRole.ts',
308
+ },
309
+ {
310
+ name: 'CoinbasePublicRestApiVisibilityStatus',
311
+ valueCount: 3,
312
+ file: 'coinbasePublicRestApiVisibilityStatus.ts',
313
+ },
314
+ {
315
+ name: 'CoinbasePublicRestApiWalletDepositInstructionType',
316
+ valueCount: 5,
317
+ file: 'coinbasePublicRestApiWalletDepositInstructionType.ts',
318
+ },
319
+ {
320
+ name: 'CoinbasePublicRestApiWalletType',
321
+ valueCount: 5,
322
+ file: 'coinbasePublicRestApiWalletType.ts',
323
+ },
324
+ {
325
+ name: 'CoinbasePublicRestApiWalletVisibility',
326
+ valueCount: 3,
327
+ file: 'coinbasePublicRestApiWalletVisibility.ts',
328
+ },
329
+ ],
330
+ };
@@ -14,6 +14,7 @@ class PaymentMethodsService {
14
14
  constructor(client) {
15
15
  this.client = client;
16
16
  }
17
+ // TODO: rename me to remove Entity in a minor version change
17
18
  listEntityPaymentMethods(request, options) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
19
20
  const response = yield this.client.request({
@@ -26,7 +27,7 @@ class PaymentMethodsService {
26
27
  getPaymentMethod(request, options) {
27
28
  return __awaiter(this, void 0, void 0, function* () {
28
29
  const response = yield this.client.request({
29
- url: `entities/${request.entityId}/payment-methods`,
30
+ url: `entities/${request.entityId}/payment-methods/${request.paymentMethodId}`,
30
31
  callOptions: options,
31
32
  });
32
33
  return response.data;
@@ -0,0 +1,184 @@
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.enumRegistry = exports.DynamicEnumValidationError = void 0;
19
+ exports.setDynamicValidationConfig = setDynamicValidationConfig;
20
+ exports.getDynamicValidationConfig = getDynamicValidationConfig;
21
+ exports.dynamicValidateRequest = dynamicValidateRequest;
22
+ exports.getEnumInfo = getEnumInfo;
23
+ /**
24
+ * Dynamic enum validation system that automatically discovers and validates
25
+ * enum fields in request objects without manual service-specific configuration.
26
+ *
27
+ * This approach is more scalable and maintainable than manual validation rules.
28
+ */
29
+ const enumRegistry_1 = require("./enumRegistry");
30
+ Object.defineProperty(exports, "enumRegistry", { enumerable: true, get: function () { return enumRegistry_1.enumRegistry; } });
31
+ const enumValidationCore_1 = require("./enumValidationCore");
32
+ Object.defineProperty(exports, "DynamicEnumValidationError", { enumerable: true, get: function () { return enumValidationCore_1.DynamicEnumValidationError; } });
33
+ // Default configuration
34
+ const defaultConfig = {
35
+ enabled: true,
36
+ strict: true,
37
+ autoNormalize: true,
38
+ logWarnings: true,
39
+ };
40
+ let currentConfig = Object.assign({}, defaultConfig);
41
+ // Cache for request type analysis to improve performance
42
+ const requestTypeCache = new Map();
43
+ /**
44
+ * Set global configuration for dynamic enum validation
45
+ */
46
+ function setDynamicValidationConfig(config) {
47
+ currentConfig = Object.assign(Object.assign({}, currentConfig), config);
48
+ }
49
+ /**
50
+ * Get current dynamic validation configuration
51
+ */
52
+ function getDynamicValidationConfig() {
53
+ return Object.assign({}, currentConfig);
54
+ }
55
+ /**
56
+ * Analyze request structure to identify enum fields
57
+ */
58
+ function analyzeRequestType(request, serviceName) {
59
+ // Use object structure and service name as cache key
60
+ const cacheKey = JSON.stringify({
61
+ structure: Object.keys(request || {})
62
+ .sort()
63
+ .reduce((acc, key) => {
64
+ acc[key] = typeof request[key];
65
+ return acc;
66
+ }, {}),
67
+ serviceName: serviceName || 'unknown',
68
+ });
69
+ // Return cached result if available
70
+ const cached = requestTypeCache.get(cacheKey);
71
+ if (cached) {
72
+ return cached;
73
+ }
74
+ const enumFields = [];
75
+ if (!request || typeof request !== 'object') {
76
+ return enumFields;
77
+ }
78
+ Object.entries(request).forEach(([fieldName, value]) => {
79
+ const fieldInfo = (0, enumValidationCore_1.analyzeField)(fieldName, value, serviceName);
80
+ if (fieldInfo) {
81
+ enumFields.push(fieldInfo);
82
+ }
83
+ });
84
+ // Cache the result
85
+ requestTypeCache.set(cacheKey, enumFields);
86
+ return enumFields;
87
+ }
88
+ /**
89
+ * Validate request object and normalize enum values
90
+ */
91
+ function validateRequestEnums(request, config = currentConfig) {
92
+ const validatedRequest = Object.assign({}, request);
93
+ const errors = [];
94
+ if (!config.enabled) {
95
+ return { validatedRequest, errors };
96
+ }
97
+ const enumFields = analyzeRequestType(request, config.serviceName);
98
+ enumFields.forEach((fieldInfo) => {
99
+ const { fieldName, enumName, isArray } = fieldInfo;
100
+ const fieldValue = request[fieldName];
101
+ if (fieldValue === undefined || fieldValue === null) {
102
+ return;
103
+ }
104
+ try {
105
+ const enumObject = enumRegistry_1.enumRegistry.getEnum(enumName);
106
+ if (!enumObject) {
107
+ errors.push(`${fieldName}: Enum ${enumName} not found`);
108
+ return;
109
+ }
110
+ if (isArray && Array.isArray(fieldValue)) {
111
+ // Handle array values
112
+ const validatedArray = [];
113
+ for (const item of fieldValue) {
114
+ if (typeof item === 'string') {
115
+ const validation = (0, enumValidationCore_1.validateEnumValue)(item, enumObject, enumName, fieldName, config);
116
+ if (validation.isValid && validation.normalizedValue) {
117
+ validatedArray.push(validation.normalizedValue);
118
+ }
119
+ else if (validation.error) {
120
+ if (config.strict) {
121
+ throw new enumValidationCore_1.DynamicEnumValidationError(fieldName, item, enumName, Object.values(enumObject), Object.keys(enumObject));
122
+ }
123
+ else {
124
+ if (config.logWarnings) {
125
+ console.warn(`[Prime SDK] Dynamic enum validation warning: ${validation.error}`);
126
+ }
127
+ validatedArray.push(item); // Keep original value
128
+ }
129
+ }
130
+ }
131
+ }
132
+ validatedRequest[fieldName] = validatedArray;
133
+ }
134
+ else if (typeof fieldValue === 'string') {
135
+ // Handle single string values
136
+ const validation = (0, enumValidationCore_1.validateEnumValue)(fieldValue, enumObject, enumName, fieldName, config);
137
+ if (validation.isValid && validation.normalizedValue) {
138
+ validatedRequest[fieldName] = validation.normalizedValue;
139
+ }
140
+ else if (validation.error) {
141
+ if (config.strict) {
142
+ throw new enumValidationCore_1.DynamicEnumValidationError(fieldName, fieldValue, enumName, Object.values(enumObject), Object.keys(enumObject));
143
+ }
144
+ else {
145
+ if (config.logWarnings) {
146
+ console.warn(`[Prime SDK] Dynamic enum validation warning: ${validation.error}`);
147
+ }
148
+ // Keep original value in non-strict mode
149
+ }
150
+ }
151
+ }
152
+ }
153
+ catch (error) {
154
+ if (error instanceof enumValidationCore_1.DynamicEnumValidationError) {
155
+ throw error; // Re-throw enum validation errors
156
+ }
157
+ errors.push(`${fieldName}: Unexpected validation error: ${error}`);
158
+ }
159
+ });
160
+ return { validatedRequest, errors };
161
+ }
162
+ /**
163
+ * Main API: Validate and normalize request with type-safe generics
164
+ */
165
+ function dynamicValidateRequest(request, config) {
166
+ const validationConfig = config
167
+ ? Object.assign(Object.assign({}, currentConfig), config) : currentConfig;
168
+ const result = validateRequestEnums(request, validationConfig);
169
+ if (result.errors.length > 0) {
170
+ throw new enumValidationCore_1.DynamicEnumValidationError('request', 'multiple fields', 'various', [], result.errors);
171
+ }
172
+ return result.validatedRequest;
173
+ }
174
+ /**
175
+ * Get information about discovered enums
176
+ */
177
+ function getEnumInfo() {
178
+ const stats = enumRegistry_1.enumRegistry.getStats();
179
+ return {
180
+ totalEnums: stats.totalEnums,
181
+ enumNames: enumRegistry_1.enumRegistry.getAllEnumNames(),
182
+ enumDetails: enumRegistry_1.enumRegistry.getEnumDetails(),
183
+ };
184
+ }