@coinbase/cdp-sdk 0.0.0 → 1.0.0
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/README.md +165 -0
- package/dist/accounts/evm/toEvmServerAccount.d.ts +19 -0
- package/dist/accounts/evm/toEvmServerAccount.js +42 -0
- package/dist/accounts/evm/toEvmSmartAccount.d.ts +24 -0
- package/dist/accounts/evm/toEvmSmartAccount.js +24 -0
- package/dist/accounts/types.d.ts +45 -0
- package/dist/accounts/types.js +2 -0
- package/dist/actions/evm/sendUserOperation.d.ts +95 -0
- package/dist/actions/evm/sendUserOperation.js +87 -0
- package/dist/actions/evm/waitForUserOperation.d.ts +63 -0
- package/dist/actions/evm/waitForUserOperation.js +60 -0
- package/dist/analytics.d.ts +30 -0
- package/dist/analytics.js +89 -0
- package/dist/auth/errors.d.ts +45 -0
- package/dist/auth/errors.js +62 -0
- package/dist/auth/hooks/axios/index.d.ts +1 -0
- package/dist/auth/hooks/axios/index.js +17 -0
- package/dist/auth/hooks/axios/withAuth.d.ts +37 -0
- package/dist/auth/hooks/axios/withAuth.js +73 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +43 -0
- package/dist/auth/utils/http.d.ts +60 -0
- package/dist/auth/utils/http.js +72 -0
- package/dist/auth/utils/index.d.ts +2 -0
- package/dist/auth/utils/index.js +18 -0
- package/dist/auth/utils/jwt.d.ts +88 -0
- package/dist/auth/utils/jwt.js +235 -0
- package/dist/client/cdp.d.ts +43 -0
- package/dist/client/cdp.js +40 -0
- package/dist/client/evm/evm.d.ts +387 -0
- package/dist/client/evm/evm.js +520 -0
- package/dist/client/evm/evm.types.d.ts +254 -0
- package/dist/client/evm/evm.types.js +2 -0
- package/dist/client/evm/index.d.ts +1 -0
- package/dist/client/evm/index.js +5 -0
- package/dist/client/solana/index.d.ts +1 -0
- package/dist/client/solana/index.js +5 -0
- package/dist/client/solana/solana.d.ts +168 -0
- package/dist/client/solana/solana.js +207 -0
- package/dist/client/solana/solana.types.d.ts +94 -0
- package/dist/client/solana/solana.types.js +2 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +7 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/openapi-client/cdpApiClient.d.ts +50 -0
- package/dist/openapi-client/cdpApiClient.js +146 -0
- package/dist/openapi-client/errors.d.ts +53 -0
- package/dist/openapi-client/errors.js +70 -0
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +345 -0
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +54 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +62 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +85 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +17 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +113 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +48 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +66 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +15 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +99 -0
- package/dist/openapi-client/generated/faucets/faucets.d.ts +48 -0
- package/dist/openapi-client/generated/faucets/faucets.js +51 -0
- package/dist/openapi-client/generated/faucets/faucets.msw.d.ts +7 -0
- package/dist/openapi-client/generated/faucets/faucets.msw.js +43 -0
- package/dist/openapi-client/generated/index.msw.d.ts +4 -0
- package/dist/openapi-client/generated/index.msw.js +20 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.d.ts +61 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.js +79 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +15 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.js +99 -0
- package/dist/openapi-client/index.d.ts +55 -0
- package/dist/openapi-client/index.js +65 -0
- package/dist/types/calls.d.ts +13 -0
- package/dist/types/calls.js +4 -0
- package/dist/types/contract.d.ts +30 -0
- package/dist/types/contract.js +4 -0
- package/dist/types/misc.d.ts +3 -0
- package/dist/types/misc.js +3 -0
- package/dist/types/multicall.d.ts +9 -0
- package/dist/types/multicall.js +2 -0
- package/dist/types/utils.d.ts +196 -0
- package/dist/types/utils.js +4 -0
- package/dist/utils/wait.d.ts +28 -0
- package/dist/utils/wait.js +34 -0
- package/package.json +72 -5
- package/index.js +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { OpenApiSolanaMethods, SolanaAccount as OpenAPISolanaAccount } from "../../openapi-client";
|
|
2
|
+
/**
|
|
3
|
+
* The SolanaClient type, where all OpenApiSolanaMethods methods are wrapped.
|
|
4
|
+
*/
|
|
5
|
+
export type SolanaClientInterface = Omit<typeof OpenApiSolanaMethods, "createSolanaAccount" | "getSolanaAccount" | "getSolanaAccountByName" | "listSolanaAccounts" | "requestSolanaFaucet" | "signSolanaMessage" | "signSolanaTransaction"> & {
|
|
6
|
+
createAccount: (options: CreateAccountOptions) => Promise<Account>;
|
|
7
|
+
getAccount: (options: GetAccountOptions) => Promise<Account>;
|
|
8
|
+
listAccounts: (options: ListAccountsOptions) => Promise<ListAccountsResult>;
|
|
9
|
+
requestFaucet: (options: RequestFaucetOptions) => Promise<SignatureResult>;
|
|
10
|
+
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
11
|
+
signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A Solana account.
|
|
15
|
+
*/
|
|
16
|
+
export type Account = OpenAPISolanaAccount;
|
|
17
|
+
/**
|
|
18
|
+
* Options for creating a Solana account.
|
|
19
|
+
*/
|
|
20
|
+
export interface CreateAccountOptions {
|
|
21
|
+
/** The name of the account. */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** The idempotency key. */
|
|
24
|
+
idempotencyKey?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for getting a Solana account.
|
|
28
|
+
*/
|
|
29
|
+
export interface GetAccountOptions {
|
|
30
|
+
/** The address of the account. */
|
|
31
|
+
address?: string;
|
|
32
|
+
/** The name of the account. */
|
|
33
|
+
name?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for listing Solana accounts.
|
|
37
|
+
*/
|
|
38
|
+
export interface ListAccountsOptions {
|
|
39
|
+
/** The page size. */
|
|
40
|
+
pageSize?: number;
|
|
41
|
+
/** The page token. */
|
|
42
|
+
pageToken?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The result of listing Solana accounts.
|
|
46
|
+
*/
|
|
47
|
+
export interface ListAccountsResult {
|
|
48
|
+
/** The accounts. */
|
|
49
|
+
accounts: Account[];
|
|
50
|
+
/**
|
|
51
|
+
* The token for the next page of accounts, if any.
|
|
52
|
+
*/
|
|
53
|
+
nextPageToken?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Options for requesting funds from a Solana faucet.
|
|
57
|
+
*/
|
|
58
|
+
export interface RequestFaucetOptions {
|
|
59
|
+
/** The address of the account. */
|
|
60
|
+
address: string;
|
|
61
|
+
/** The token to request funds for. */
|
|
62
|
+
token: "sol" | "usdc";
|
|
63
|
+
/** The idempotency key. */
|
|
64
|
+
idempotencyKey?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for signing a Solana message.
|
|
68
|
+
*/
|
|
69
|
+
export interface SignMessageOptions {
|
|
70
|
+
/** The address of the account. */
|
|
71
|
+
address: string;
|
|
72
|
+
/** The message to sign. */
|
|
73
|
+
message: string;
|
|
74
|
+
/** The idempotency key. */
|
|
75
|
+
idempotencyKey?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Options for signing a Solana transaction.
|
|
79
|
+
*/
|
|
80
|
+
export interface SignTransactionOptions {
|
|
81
|
+
/** The address of the account. */
|
|
82
|
+
address: string;
|
|
83
|
+
/** The base64 encoded transaction to sign. */
|
|
84
|
+
transaction: string;
|
|
85
|
+
/** The idempotency key. */
|
|
86
|
+
idempotencyKey?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A Solana signature result.
|
|
90
|
+
*/
|
|
91
|
+
export interface SignatureResult {
|
|
92
|
+
/** The signature. */
|
|
93
|
+
signature: string;
|
|
94
|
+
}
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeoutError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TimeoutError is thrown when an operation times out.
|
|
6
|
+
*/
|
|
7
|
+
class TimeoutError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Initializes a new TimeoutError instance.
|
|
10
|
+
*
|
|
11
|
+
* @param message - The error message.
|
|
12
|
+
*/
|
|
13
|
+
constructor(message = "Timeout Error") {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "TimeoutError";
|
|
16
|
+
if (Error.captureStackTrace) {
|
|
17
|
+
Error.captureStackTrace(this, TimeoutError);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TimeoutError = TimeoutError;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CdpClient = void 0;
|
|
4
|
+
require("./analytics");
|
|
5
|
+
var cdp_1 = require("./client/cdp");
|
|
6
|
+
Object.defineProperty(exports, "CdpClient", { enumerable: true, get: function () { return cdp_1.CdpClient; } });
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* The options for the CDP API.
|
|
4
|
+
*/
|
|
5
|
+
export type CdpOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* The API key ID or the legacy API key name.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* ID format: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
11
|
+
* Legacy name format: 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
12
|
+
*/
|
|
13
|
+
apiKeyId: string;
|
|
14
|
+
/**
|
|
15
|
+
* The API key secret, using the Ed25519 or legacy EC key format.
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
* Ed25519 key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=='
|
|
19
|
+
* EC key: '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n'
|
|
20
|
+
*/
|
|
21
|
+
apiKeySecret: string;
|
|
22
|
+
/** The Wallet Secret. Only needed if calling certain Wallet APIs. */
|
|
23
|
+
walletSecret?: string;
|
|
24
|
+
/** If true, logs API requests and responses to the console. */
|
|
25
|
+
debugging?: boolean;
|
|
26
|
+
/** The base path for the API. */
|
|
27
|
+
basePath?: string;
|
|
28
|
+
/** The source for the API request, used for analytics. Defaults to `typescript-client`. */
|
|
29
|
+
source?: string;
|
|
30
|
+
/** The version of the source for the API request, used for analytics. */
|
|
31
|
+
sourceVersion?: string;
|
|
32
|
+
/** Optional expiration time in seconds (defaults to 120) */
|
|
33
|
+
expiresIn?: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Configures the CDP client with the given options.
|
|
37
|
+
*
|
|
38
|
+
* @param {CdpOptions} options - The CDP options.
|
|
39
|
+
*/
|
|
40
|
+
export declare const configure: (options: CdpOptions) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Mutates the given Axios request configuration to add the CDP API key signature
|
|
43
|
+
* to the request headers.
|
|
44
|
+
*
|
|
45
|
+
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
46
|
+
* @param idempotencyKey - The idempotency key.
|
|
47
|
+
* @returns {Promise<T>} A promise that resolves to the response data.
|
|
48
|
+
* @throws {APIError} If the request fails.
|
|
49
|
+
*/
|
|
50
|
+
export declare const cdpApiClient: <T>(config: AxiosRequestConfig, idempotencyKey?: string) => Promise<T>;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.cdpApiClient = exports.configure = void 0;
|
|
37
|
+
const axios_1 = __importStar(require("axios"));
|
|
38
|
+
const axios_2 = require("../auth/hooks/axios");
|
|
39
|
+
const errors_1 = require("./errors");
|
|
40
|
+
const constants_1 = require("../constants");
|
|
41
|
+
let axiosInstance;
|
|
42
|
+
/**
|
|
43
|
+
* Configures the CDP client with the given options.
|
|
44
|
+
*
|
|
45
|
+
* @param {CdpOptions} options - The CDP options.
|
|
46
|
+
*/
|
|
47
|
+
const configure = (options) => {
|
|
48
|
+
axiosInstance = axios_1.default.create({
|
|
49
|
+
baseURL: options.basePath || "https://api.cdp.coinbase.com/platform",
|
|
50
|
+
});
|
|
51
|
+
axiosInstance = (0, axios_2.withAuth)(axiosInstance, {
|
|
52
|
+
apiKeyId: options.apiKeyId,
|
|
53
|
+
apiKeySecret: options.apiKeySecret,
|
|
54
|
+
source: options.source || "sdk-openapi-client",
|
|
55
|
+
sourceVersion: options.sourceVersion,
|
|
56
|
+
walletSecret: options.walletSecret,
|
|
57
|
+
expiresIn: options.expiresIn,
|
|
58
|
+
debug: options.debugging,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
exports.configure = configure;
|
|
62
|
+
/**
|
|
63
|
+
* Adds an idempotency key to request config if provided
|
|
64
|
+
*
|
|
65
|
+
* @param config - The Axios request configuration.
|
|
66
|
+
* @param idempotencyKey - The idempotency key.
|
|
67
|
+
* @returns The Axios request configuration with the idempotency key.
|
|
68
|
+
*/
|
|
69
|
+
const addIdempotencyKey = (config, idempotencyKey) => {
|
|
70
|
+
if (!idempotencyKey) {
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
...config,
|
|
75
|
+
headers: {
|
|
76
|
+
...(config.headers || {}),
|
|
77
|
+
"X-Idempotency-Key": idempotencyKey,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Mutates the given Axios request configuration to add the CDP API key signature
|
|
83
|
+
* to the request headers.
|
|
84
|
+
*
|
|
85
|
+
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
86
|
+
* @param idempotencyKey - The idempotency key.
|
|
87
|
+
* @returns {Promise<T>} A promise that resolves to the response data.
|
|
88
|
+
* @throws {APIError} If the request fails.
|
|
89
|
+
*/
|
|
90
|
+
const cdpApiClient = async (config, idempotencyKey) => {
|
|
91
|
+
validateCall(config);
|
|
92
|
+
// Add idempotency key to the request headers if provided
|
|
93
|
+
const configWithIdempotencyKey = addIdempotencyKey(config, idempotencyKey);
|
|
94
|
+
try {
|
|
95
|
+
const response = await axiosInstance(configWithIdempotencyKey);
|
|
96
|
+
return response.data;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
100
|
+
if ((0, errors_1.isOpenAPIError)(error.response.data)) {
|
|
101
|
+
throw new errors_1.APIError(error.response.status, error.response.data.errorType, error.response.data.errorMessage, error.response.data.correlationId, error.response.data.errorLink);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const statusCode = error.response.status;
|
|
105
|
+
switch (statusCode) {
|
|
106
|
+
case 401:
|
|
107
|
+
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.unauthorized, "Unauthorized.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}#unauthorized`);
|
|
108
|
+
case 404:
|
|
109
|
+
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.not_found, "API not found.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}#not_found`);
|
|
110
|
+
case 502:
|
|
111
|
+
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.bad_gateway, "Bad gateway.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
112
|
+
case 503:
|
|
113
|
+
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.service_unavailable, "Service unavailable. Please try again later.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
114
|
+
default:
|
|
115
|
+
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.unexpected_error, "An unexpected error occurred.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (axios_1.default.isAxiosError(error) && error.request) {
|
|
120
|
+
throw new errors_1.APIError(axios_1.HttpStatusCode.ServiceUnavailable, errors_1.HttpErrorType.service_unavailable, "Network error, unable to reach the service.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw new errors_1.APIError(axios_1.HttpStatusCode.InternalServerError, errors_1.HttpErrorType.unexpected_error, error instanceof Error
|
|
124
|
+
? error.message
|
|
125
|
+
: `An unexpected error occurred: ${JSON.stringify(error, Object.getOwnPropertyNames(error))}`, undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
exports.cdpApiClient = cdpApiClient;
|
|
130
|
+
/**
|
|
131
|
+
* Validates the call to the cdpApiClient.
|
|
132
|
+
*
|
|
133
|
+
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
134
|
+
* @throws {Error} If the call is not valid.
|
|
135
|
+
*/
|
|
136
|
+
const validateCall = (config) => {
|
|
137
|
+
if (!axiosInstance.getUri() || axiosInstance.getUri() === "") {
|
|
138
|
+
throw new Error("CDP client URI not configured. Call configure() first.");
|
|
139
|
+
}
|
|
140
|
+
if (!config.url || config.url === "") {
|
|
141
|
+
throw new Error("AxiosRequestConfig URL is empty. This should never happen.");
|
|
142
|
+
}
|
|
143
|
+
if (!config.method || config.method === "") {
|
|
144
|
+
throw new Error("AxiosRequestConfig method is empty. This should never happen.");
|
|
145
|
+
}
|
|
146
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Error as OpenAPIError, ErrorType as OpenAPIErrorType } from "./generated/coinbaseDeveloperPlatformAPIs.schemas";
|
|
2
|
+
export declare const HttpErrorType: {
|
|
3
|
+
readonly unexpected_error: "unexpected_error";
|
|
4
|
+
readonly unauthorized: "unauthorized";
|
|
5
|
+
readonly not_found: "not_found";
|
|
6
|
+
readonly bad_gateway: "bad_gateway";
|
|
7
|
+
readonly service_unavailable: "service_unavailable";
|
|
8
|
+
};
|
|
9
|
+
export type HttpErrorType = (typeof HttpErrorType)[keyof typeof HttpErrorType];
|
|
10
|
+
/**
|
|
11
|
+
* Extended error codes that include both OpenAPI errors and network errors
|
|
12
|
+
*/
|
|
13
|
+
export type APIErrorType = OpenAPIErrorType | HttpErrorType;
|
|
14
|
+
/**
|
|
15
|
+
* Extended API error that encompasses both OpenAPI errors and other API-related errors
|
|
16
|
+
*/
|
|
17
|
+
export declare class APIError extends Error {
|
|
18
|
+
statusCode: number;
|
|
19
|
+
errorType: APIErrorType;
|
|
20
|
+
errorMessage: string;
|
|
21
|
+
correlationId?: string;
|
|
22
|
+
errorLink?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Constructor for the APIError class
|
|
25
|
+
*
|
|
26
|
+
* @param statusCode - The HTTP status code
|
|
27
|
+
* @param errorType - The type of error
|
|
28
|
+
* @param errorMessage - The error message
|
|
29
|
+
* @param correlationId - The correlation ID
|
|
30
|
+
* @param errorLink - URL to documentation about this error
|
|
31
|
+
*/
|
|
32
|
+
constructor(statusCode: number, errorType: APIErrorType, errorMessage: string, correlationId?: string, errorLink?: string);
|
|
33
|
+
/**
|
|
34
|
+
* Convert the error to a JSON object, excluding undefined properties
|
|
35
|
+
*
|
|
36
|
+
* @returns The error as a JSON object
|
|
37
|
+
*/
|
|
38
|
+
toJSON(): {
|
|
39
|
+
errorLink?: string | undefined;
|
|
40
|
+
correlationId?: string | undefined;
|
|
41
|
+
name: string;
|
|
42
|
+
statusCode: number;
|
|
43
|
+
errorType: APIErrorType;
|
|
44
|
+
errorMessage: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Type guard to check if an object is an OpenAPIError
|
|
49
|
+
*
|
|
50
|
+
* @param obj - The object to check
|
|
51
|
+
* @returns True if the object is an OpenAPIError
|
|
52
|
+
*/
|
|
53
|
+
export declare function isOpenAPIError(obj: unknown): obj is OpenAPIError;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APIError = exports.HttpErrorType = void 0;
|
|
4
|
+
exports.isOpenAPIError = isOpenAPIError;
|
|
5
|
+
exports.HttpErrorType = {
|
|
6
|
+
unexpected_error: "unexpected_error",
|
|
7
|
+
unauthorized: "unauthorized",
|
|
8
|
+
not_found: "not_found",
|
|
9
|
+
bad_gateway: "bad_gateway",
|
|
10
|
+
service_unavailable: "service_unavailable",
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Extended API error that encompasses both OpenAPI errors and other API-related errors
|
|
14
|
+
*/
|
|
15
|
+
class APIError extends Error {
|
|
16
|
+
/**
|
|
17
|
+
* Constructor for the APIError class
|
|
18
|
+
*
|
|
19
|
+
* @param statusCode - The HTTP status code
|
|
20
|
+
* @param errorType - The type of error
|
|
21
|
+
* @param errorMessage - The error message
|
|
22
|
+
* @param correlationId - The correlation ID
|
|
23
|
+
* @param errorLink - URL to documentation about this error
|
|
24
|
+
*/
|
|
25
|
+
constructor(statusCode, errorType, errorMessage, correlationId, errorLink) {
|
|
26
|
+
super(errorMessage);
|
|
27
|
+
this.name = "APIError";
|
|
28
|
+
this.statusCode = statusCode;
|
|
29
|
+
this.errorType = errorType;
|
|
30
|
+
this.errorMessage = errorMessage;
|
|
31
|
+
// Only set correlationId if it's defined
|
|
32
|
+
if (correlationId !== undefined) {
|
|
33
|
+
this.correlationId = correlationId;
|
|
34
|
+
}
|
|
35
|
+
// Only set errorLink if it's defined
|
|
36
|
+
if (errorLink !== undefined) {
|
|
37
|
+
this.errorLink = errorLink;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Convert the error to a JSON object, excluding undefined properties
|
|
42
|
+
*
|
|
43
|
+
* @returns The error as a JSON object
|
|
44
|
+
*/
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
name: this.name,
|
|
48
|
+
statusCode: this.statusCode,
|
|
49
|
+
errorType: this.errorType,
|
|
50
|
+
errorMessage: this.errorMessage,
|
|
51
|
+
...(this.correlationId && { correlationId: this.correlationId }),
|
|
52
|
+
...(this.errorLink && { errorLink: this.errorLink }),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.APIError = APIError;
|
|
57
|
+
/**
|
|
58
|
+
* Type guard to check if an object is an OpenAPIError
|
|
59
|
+
*
|
|
60
|
+
* @param obj - The object to check
|
|
61
|
+
* @returns True if the object is an OpenAPIError
|
|
62
|
+
*/
|
|
63
|
+
function isOpenAPIError(obj) {
|
|
64
|
+
return (obj !== null &&
|
|
65
|
+
typeof obj === "object" &&
|
|
66
|
+
"errorType" in obj &&
|
|
67
|
+
typeof obj.errorType === "string" &&
|
|
68
|
+
"errorMessage" in obj &&
|
|
69
|
+
typeof obj.errorMessage === "string");
|
|
70
|
+
}
|