@rlajous/sdk-core 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/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/cjs/client-base.js +155 -0
- package/dist/cjs/client-base.js.map +1 -0
- package/dist/cjs/config.js +30 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/errors/authentication.js +35 -0
- package/dist/cjs/errors/authentication.js.map +1 -0
- package/dist/cjs/errors/base.js +76 -0
- package/dist/cjs/errors/base.js.map +1 -0
- package/dist/cjs/errors/index.js +16 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/network.js +45 -0
- package/dist/cjs/errors/network.js.map +1 -0
- package/dist/cjs/errors/not-found.js +38 -0
- package/dist/cjs/errors/not-found.js.map +1 -0
- package/dist/cjs/errors/rate-limit.js +53 -0
- package/dist/cjs/errors/rate-limit.js.map +1 -0
- package/dist/cjs/errors/validation.js +49 -0
- package/dist/cjs/errors/validation.js.map +1 -0
- package/dist/cjs/http/client.js +335 -0
- package/dist/cjs/http/client.js.map +1 -0
- package/dist/cjs/http/index.js +11 -0
- package/dist/cjs/http/index.js.map +1 -0
- package/dist/cjs/http/retry.js +43 -0
- package/dist/cjs/http/retry.js.map +1 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/chain.js +114 -0
- package/dist/cjs/types/chain.js.map +1 -0
- package/dist/cjs/types/common.js +49 -0
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/modules.js +64 -0
- package/dist/cjs/types/modules.js.map +1 -0
- package/dist/cjs/utils/address-validation.js +124 -0
- package/dist/cjs/utils/address-validation.js.map +1 -0
- package/dist/cjs/utils/index.js +14 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/esm/client-base.js +151 -0
- package/dist/esm/client-base.js.map +1 -0
- package/dist/esm/config.js +26 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/errors/authentication.js +31 -0
- package/dist/esm/errors/authentication.js.map +1 -0
- package/dist/esm/errors/base.js +72 -0
- package/dist/esm/errors/base.js.map +1 -0
- package/dist/esm/errors/index.js +7 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/errors/network.js +41 -0
- package/dist/esm/errors/network.js.map +1 -0
- package/dist/esm/errors/not-found.js +34 -0
- package/dist/esm/errors/not-found.js.map +1 -0
- package/dist/esm/errors/rate-limit.js +49 -0
- package/dist/esm/errors/rate-limit.js.map +1 -0
- package/dist/esm/errors/validation.js +45 -0
- package/dist/esm/errors/validation.js.map +1 -0
- package/dist/esm/http/client.js +331 -0
- package/dist/esm/http/client.js.map +1 -0
- package/dist/esm/http/index.js +3 -0
- package/dist/esm/http/index.js.map +1 -0
- package/dist/esm/http/retry.js +37 -0
- package/dist/esm/http/retry.js.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types/chain.js +109 -0
- package/dist/esm/types/chain.js.map +1 -0
- package/dist/esm/types/common.js +46 -0
- package/dist/esm/types/common.js.map +1 -0
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/modules.js +61 -0
- package/dist/esm/types/modules.js.map +1 -0
- package/dist/esm/utils/address-validation.js +113 -0
- package/dist/esm/utils/address-validation.js.map +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/types/client-base.d.ts +94 -0
- package/dist/types/client-base.d.ts.map +1 -0
- package/dist/types/config.d.ts +124 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/errors/authentication.d.ts +24 -0
- package/dist/types/errors/authentication.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +53 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +7 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/errors/network.d.ts +30 -0
- package/dist/types/errors/network.d.ts.map +1 -0
- package/dist/types/errors/not-found.d.ts +27 -0
- package/dist/types/errors/not-found.d.ts.map +1 -0
- package/dist/types/errors/rate-limit.d.ts +37 -0
- package/dist/types/errors/rate-limit.d.ts.map +1 -0
- package/dist/types/errors/validation.d.ts +34 -0
- package/dist/types/errors/validation.d.ts.map +1 -0
- package/dist/types/http/client.d.ts +147 -0
- package/dist/types/http/client.d.ts.map +1 -0
- package/dist/types/http/index.d.ts +3 -0
- package/dist/types/http/index.d.ts.map +1 -0
- package/dist/types/http/retry.d.ts +32 -0
- package/dist/types/http/retry.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/chain.d.ts +60 -0
- package/dist/types/types/chain.d.ts.map +1 -0
- package/dist/types/types/common.d.ts +251 -0
- package/dist/types/types/common.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/modules.d.ts +51 -0
- package/dist/types/types/modules.d.ts.map +1 -0
- package/dist/types/utils/address-validation.d.ts +50 -0
- package/dist/types/utils/address-validation.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Webacy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @rlajous/sdk-core
|
|
2
|
+
|
|
3
|
+
Core utilities and shared internals for Webacy SDK packages. This package is automatically installed as a dependency of `@rlajous/sdk-trading` and `@rlajous/sdk-threat`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This package is typically not installed directly. Instead, install one of the SDK packages:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @rlajous/sdk # Full SDK
|
|
11
|
+
npm install @rlajous/sdk-trading # Trading analysis only
|
|
12
|
+
npm install @rlajous/sdk-threat # Threat analysis only
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What's Included
|
|
16
|
+
|
|
17
|
+
### Chain Support
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { Chain, isEvmChain, CHAIN_IDS, CHAIN_NAMES } from '@rlajous/sdk-core';
|
|
21
|
+
|
|
22
|
+
// Check if a chain is EVM-compatible
|
|
23
|
+
if (isEvmChain(Chain.ETH)) {
|
|
24
|
+
console.log('Using EVM chain');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Get chain metadata
|
|
28
|
+
console.log(CHAIN_NAMES[Chain.SOL]); // "Solana"
|
|
29
|
+
console.log(CHAIN_IDS[Chain.ETH]); // 1
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Error Classes
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import {
|
|
36
|
+
WebacyError,
|
|
37
|
+
AuthenticationError,
|
|
38
|
+
RateLimitError,
|
|
39
|
+
ValidationError,
|
|
40
|
+
NotFoundError,
|
|
41
|
+
NetworkError,
|
|
42
|
+
} from '@rlajous/sdk-core';
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await client.addresses.analyze('0x...');
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error instanceof RateLimitError) {
|
|
48
|
+
console.log(`Retry after ${error.retryAfter} seconds`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Type Definitions
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import type {
|
|
57
|
+
RiskTag,
|
|
58
|
+
RiskModule,
|
|
59
|
+
RiskCategory,
|
|
60
|
+
TokenMetadata,
|
|
61
|
+
OwnershipDistribution,
|
|
62
|
+
} from '@rlajous/sdk-core';
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Address Validation
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import {
|
|
69
|
+
isValidAddress,
|
|
70
|
+
isValidEvmAddress,
|
|
71
|
+
isValidSolanaAddress,
|
|
72
|
+
} from '@rlajous/sdk-core';
|
|
73
|
+
|
|
74
|
+
isValidAddress('0x742d35Cc...', Chain.ETH); // true
|
|
75
|
+
isValidSolanaAddress('EPjFWdd5Aufq...'); // true
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Supported Chains
|
|
79
|
+
|
|
80
|
+
| Chain | Code | EVM |
|
|
81
|
+
|-------|------|-----|
|
|
82
|
+
| Ethereum | `eth` | Yes |
|
|
83
|
+
| Base | `base` | Yes |
|
|
84
|
+
| BSC | `bsc` | Yes |
|
|
85
|
+
| Polygon | `pol` | Yes |
|
|
86
|
+
| Arbitrum | `arb` | Yes |
|
|
87
|
+
| Optimism | `opt` | Yes |
|
|
88
|
+
| Solana | `sol` | No |
|
|
89
|
+
| TON | `ton` | No |
|
|
90
|
+
| Sui | `sui` | No |
|
|
91
|
+
| Stellar | `stellar` | No |
|
|
92
|
+
| Bitcoin | `btc` | No |
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const http_1 = require("./http");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
/**
|
|
8
|
+
* Base client class for Webacy SDK
|
|
9
|
+
*
|
|
10
|
+
* Provides shared functionality for all Webacy client implementations
|
|
11
|
+
* including HTTP client setup, authentication, and interceptors.
|
|
12
|
+
*/
|
|
13
|
+
class BaseClient {
|
|
14
|
+
httpClient;
|
|
15
|
+
config;
|
|
16
|
+
/**
|
|
17
|
+
* Default chain to use when chain is not specified in API calls
|
|
18
|
+
*/
|
|
19
|
+
defaultChain;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
if (!config.apiKey) {
|
|
22
|
+
throw new errors_1.AuthenticationError('API key is required');
|
|
23
|
+
}
|
|
24
|
+
this.config = {
|
|
25
|
+
...config,
|
|
26
|
+
baseUrl: config.baseUrl ?? config_1.DEFAULT_CONFIG.baseUrl,
|
|
27
|
+
apiVersion: config.apiVersion ?? config_1.DEFAULT_CONFIG.apiVersion,
|
|
28
|
+
timeout: config.timeout ?? config_1.DEFAULT_CONFIG.timeout,
|
|
29
|
+
};
|
|
30
|
+
this.defaultChain = config.defaultChain;
|
|
31
|
+
this.httpClient = new http_1.HttpClient({
|
|
32
|
+
baseUrl: (0, config_1.buildBaseUrl)(this.config),
|
|
33
|
+
timeout: this.config.timeout,
|
|
34
|
+
retry: config.retry,
|
|
35
|
+
debug: config.debug,
|
|
36
|
+
logger: config.logger,
|
|
37
|
+
headers: {
|
|
38
|
+
'x-api-key': config.apiKey,
|
|
39
|
+
...config.headers,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Add a request interceptor
|
|
45
|
+
*
|
|
46
|
+
* Request interceptors are called before each request is sent.
|
|
47
|
+
* Use them to modify requests, add headers, or log requests.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* client.addRequestInterceptor((url, config) => {
|
|
52
|
+
* console.log(`Making request to ${url}`);
|
|
53
|
+
* return config;
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
addRequestInterceptor(interceptor) {
|
|
58
|
+
this.httpClient.addRequestInterceptor(interceptor);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Add a response interceptor
|
|
62
|
+
*
|
|
63
|
+
* Response interceptors are called after each successful response.
|
|
64
|
+
* Use them to transform responses or log data.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* client.addResponseInterceptor((response) => {
|
|
69
|
+
* console.log(`Received ${response.status} response`);
|
|
70
|
+
* return response;
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
addResponseInterceptor(interceptor) {
|
|
75
|
+
this.httpClient.addResponseInterceptor(interceptor);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Add an error interceptor
|
|
79
|
+
*
|
|
80
|
+
* Error interceptors are called when a request fails.
|
|
81
|
+
* Use them to handle errors globally or transform error types.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* client.addErrorInterceptor((error) => {
|
|
86
|
+
* if (error instanceof RateLimitError) {
|
|
87
|
+
* console.warn('Rate limited, will retry...');
|
|
88
|
+
* }
|
|
89
|
+
* return error;
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
addErrorInterceptor(interceptor) {
|
|
94
|
+
this.httpClient.addErrorInterceptor(interceptor);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Make a GET request
|
|
98
|
+
*/
|
|
99
|
+
get(path, options) {
|
|
100
|
+
return this.httpClient.get(path, {
|
|
101
|
+
timeout: options?.timeout,
|
|
102
|
+
signal: options?.signal,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Make a POST request
|
|
107
|
+
*/
|
|
108
|
+
post(path, body, options) {
|
|
109
|
+
return this.httpClient.post(path, body, {
|
|
110
|
+
timeout: options?.timeout,
|
|
111
|
+
signal: options?.signal,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Make a PUT request
|
|
116
|
+
*/
|
|
117
|
+
put(path, body, options) {
|
|
118
|
+
return this.httpClient.put(path, body, {
|
|
119
|
+
timeout: options?.timeout,
|
|
120
|
+
signal: options?.signal,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Make a DELETE request
|
|
125
|
+
*/
|
|
126
|
+
delete(path, options) {
|
|
127
|
+
return this.httpClient.delete(path, {
|
|
128
|
+
timeout: options?.timeout,
|
|
129
|
+
signal: options?.signal,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Build query string from parameters
|
|
134
|
+
*/
|
|
135
|
+
buildQueryString(params) {
|
|
136
|
+
const searchParams = new URLSearchParams();
|
|
137
|
+
for (const [key, value] of Object.entries(params)) {
|
|
138
|
+
if (value === undefined || value === null) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(value)) {
|
|
142
|
+
for (const item of value) {
|
|
143
|
+
searchParams.append(key, String(item));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
searchParams.append(key, String(value));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const queryString = searchParams.toString();
|
|
151
|
+
return queryString ? `?${queryString}` : '';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.BaseClient = BaseClient;
|
|
155
|
+
//# sourceMappingURL=client-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-base.js","sourceRoot":"","sources":["../../src/client-base.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONFIG = exports.defaultLogger = void 0;
|
|
4
|
+
exports.buildBaseUrl = buildBaseUrl;
|
|
5
|
+
/**
|
|
6
|
+
* Default console logger implementation
|
|
7
|
+
*/
|
|
8
|
+
exports.defaultLogger = {
|
|
9
|
+
debug: (message, data) => console.debug(`[Webacy SDK] ${message}`, data ?? ''),
|
|
10
|
+
info: (message, data) => console.info(`[Webacy SDK] ${message}`, data ?? ''),
|
|
11
|
+
warn: (message, data) => console.warn(`[Webacy SDK] ${message}`, data ?? ''),
|
|
12
|
+
error: (message, data) => console.error(`[Webacy SDK] ${message}`, data ?? ''),
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Default API configuration
|
|
16
|
+
*/
|
|
17
|
+
exports.DEFAULT_CONFIG = {
|
|
18
|
+
baseUrl: 'https://api.webacy.com',
|
|
19
|
+
apiVersion: 'v2',
|
|
20
|
+
timeout: 30000,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Build the full base URL from configuration
|
|
24
|
+
*/
|
|
25
|
+
function buildBaseUrl(config) {
|
|
26
|
+
const baseUrl = config.baseUrl ?? exports.DEFAULT_CONFIG.baseUrl;
|
|
27
|
+
// API doesn't need /api/v2 prefix - endpoints are directly on base URL
|
|
28
|
+
return baseUrl.replace(/\/$/, '');
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AA6IA,oCAIC;AAhID;;GAEG;AACU,QAAA,aAAa,GAAW;IACnC,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IAC9E,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IAC5E,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IAC5E,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;CAC/E,CAAC;AAwGF;;GAEG;AACU,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,wBAAwB;IACjC,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,KAAK;CACN,CAAC;AAEX;;GAEG;AACH,SAAgB,YAAY,CAAC,MAA0B;IACrD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,sBAAc,CAAC,OAAO,CAAC;IACzD,uEAAuE;IACvE,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationError = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when API key is invalid or missing
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* try {
|
|
11
|
+
* await client.addresses.analyze(address, { chain: Chain.ETH });
|
|
12
|
+
* } catch (error) {
|
|
13
|
+
* if (error instanceof AuthenticationError) {
|
|
14
|
+
* console.error('Authentication failed:', error.message);
|
|
15
|
+
* console.error('Suggestion:', error.getRecoverySuggestion());
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
class AuthenticationError extends base_1.WebacyError {
|
|
21
|
+
constructor(message = 'Invalid or missing API key', options = {}) {
|
|
22
|
+
super(message, {
|
|
23
|
+
status: 401,
|
|
24
|
+
code: 'AUTHENTICATION_ERROR',
|
|
25
|
+
requestId: options.requestId,
|
|
26
|
+
endpoint: options.endpoint,
|
|
27
|
+
});
|
|
28
|
+
this.name = 'AuthenticationError';
|
|
29
|
+
}
|
|
30
|
+
getRecoverySuggestion() {
|
|
31
|
+
return 'Verify your API key is correct and has not expired. You can get a new API key from the Webacy dashboard at https://webacy.com';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.AuthenticationError = AuthenticationError;
|
|
35
|
+
//# sourceMappingURL=authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../../src/errors/authentication.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAErC;;;;;;;;;;;;;;GAcG;AACH,MAAa,mBAAoB,SAAQ,kBAAW;IAClD,YACE,OAAO,GAAG,4BAA4B,EACtC,UAAqD,EAAE;QAEvD,KAAK,CAAC,OAAO,EAAE;YACb,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,sBAAsB;YAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;IAEQ,qBAAqB;QAC5B,OAAO,+HAA+H,CAAC;IACzI,CAAC;CACF;AAjBD,kDAiBC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebacyError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for all Webacy SDK errors
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* try {
|
|
10
|
+
* await client.addresses.analyze(address, { chain: Chain.ETH });
|
|
11
|
+
* } catch (error) {
|
|
12
|
+
* if (error instanceof WebacyError) {
|
|
13
|
+
* console.error(`Error: ${error.message}`);
|
|
14
|
+
* console.error(`Code: ${error.code}`);
|
|
15
|
+
* if (error.endpoint) {
|
|
16
|
+
* console.error(`Endpoint: ${error.endpoint}`);
|
|
17
|
+
* }
|
|
18
|
+
* if (error.requestId) {
|
|
19
|
+
* console.error(`Request ID: ${error.requestId} (include this when contacting support)`);
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
class WebacyError extends Error {
|
|
26
|
+
/** HTTP status code if applicable */
|
|
27
|
+
status;
|
|
28
|
+
/** Error code for programmatic handling */
|
|
29
|
+
code;
|
|
30
|
+
/** Original error if wrapped */
|
|
31
|
+
cause;
|
|
32
|
+
/** Request ID for support inquiries */
|
|
33
|
+
requestId;
|
|
34
|
+
/** API endpoint that failed (for debugging) */
|
|
35
|
+
endpoint;
|
|
36
|
+
constructor(message, options) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'WebacyError';
|
|
39
|
+
this.status = options.status;
|
|
40
|
+
this.code = options.code;
|
|
41
|
+
this.cause = options.cause;
|
|
42
|
+
this.requestId = options.requestId;
|
|
43
|
+
this.endpoint = options.endpoint;
|
|
44
|
+
// Maintain proper stack trace
|
|
45
|
+
if (Error.captureStackTrace) {
|
|
46
|
+
Error.captureStackTrace(this, this.constructor);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if this error is retryable
|
|
51
|
+
*/
|
|
52
|
+
isRetryable() {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert to JSON for logging
|
|
57
|
+
*/
|
|
58
|
+
toJSON() {
|
|
59
|
+
return {
|
|
60
|
+
name: this.name,
|
|
61
|
+
message: this.message,
|
|
62
|
+
code: this.code,
|
|
63
|
+
status: this.status,
|
|
64
|
+
requestId: this.requestId,
|
|
65
|
+
endpoint: this.endpoint,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a user-friendly description of how to resolve this error
|
|
70
|
+
*/
|
|
71
|
+
getRecoverySuggestion() {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.WebacyError = WebacyError;
|
|
76
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/errors/base.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,WAAY,SAAQ,KAAK;IACpC,qCAAqC;IACrB,MAAM,CAAU;IAEhC,2CAA2C;IAC3B,IAAI,CAAS;IAE7B,gCAAgC;IAChB,KAAK,CAAS;IAE9B,uCAAuC;IACvB,SAAS,CAAU;IAEnC,+CAA+C;IAC/B,QAAQ,CAAU;IAElC,YACE,OAAe,EACf,OAMC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAEjC,8BAA8B;QAC9B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,qBAAqB;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAnED,kCAmEC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetworkError = exports.NotFoundError = exports.ValidationError = exports.RateLimitError = exports.AuthenticationError = exports.WebacyError = void 0;
|
|
4
|
+
var base_1 = require("./base");
|
|
5
|
+
Object.defineProperty(exports, "WebacyError", { enumerable: true, get: function () { return base_1.WebacyError; } });
|
|
6
|
+
var authentication_1 = require("./authentication");
|
|
7
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return authentication_1.AuthenticationError; } });
|
|
8
|
+
var rate_limit_1 = require("./rate-limit");
|
|
9
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return rate_limit_1.RateLimitError; } });
|
|
10
|
+
var validation_1 = require("./validation");
|
|
11
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validation_1.ValidationError; } });
|
|
12
|
+
var not_found_1 = require("./not-found");
|
|
13
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return not_found_1.NotFoundError; } });
|
|
14
|
+
var network_1 = require("./network");
|
|
15
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return network_1.NetworkError; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,+BAAqC;AAA5B,mGAAA,WAAW,OAAA;AACpB,mDAAuD;AAA9C,qHAAA,mBAAmB,OAAA;AAC5B,2CAA8C;AAArC,4GAAA,cAAc,OAAA;AACvB,2CAA+C;AAAtC,6GAAA,eAAe,OAAA;AACxB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AACtB,qCAAyC;AAAhC,uGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetworkError = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when a network error occurs
|
|
7
|
+
*
|
|
8
|
+
* This includes timeouts, connection failures, and other transport-level errors.
|
|
9
|
+
* The SDK automatically retries network errors with exponential backoff.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* try {
|
|
14
|
+
* await client.addresses.analyze(address, { chain: Chain.ETH });
|
|
15
|
+
* } catch (error) {
|
|
16
|
+
* if (error instanceof NetworkError) {
|
|
17
|
+
* console.error('Network error:', error.message);
|
|
18
|
+
* if (error.cause) {
|
|
19
|
+
* console.error('Cause:', error.cause.message);
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
class NetworkError extends base_1.WebacyError {
|
|
26
|
+
constructor(message = 'Network request failed', options = {}) {
|
|
27
|
+
super(message, {
|
|
28
|
+
code: 'NETWORK_ERROR',
|
|
29
|
+
cause: options.cause,
|
|
30
|
+
endpoint: options.endpoint,
|
|
31
|
+
});
|
|
32
|
+
this.name = 'NetworkError';
|
|
33
|
+
}
|
|
34
|
+
isRetryable() {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
getRecoverySuggestion() {
|
|
38
|
+
if (this.message.includes('timed out')) {
|
|
39
|
+
return 'The request timed out. Try increasing the timeout option or check your network connection.';
|
|
40
|
+
}
|
|
41
|
+
return 'Check your network connection and try again. If the problem persists, the Webacy API may be temporarily unavailable.';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.NetworkError = NetworkError;
|
|
45
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../src/errors/network.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,YAAa,SAAQ,kBAAW;IAC3C,YACE,OAAO,GAAG,wBAAwB,EAClC,UAAgD,EAAE;QAElD,KAAK,CAAC,OAAO,EAAE;YACb,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;IAEQ,WAAW;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAEQ,qBAAqB;QAC5B,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACvC,OAAO,4FAA4F,CAAC;QACtG,CAAC;QACD,OAAO,sHAAsH,CAAC;IAChI,CAAC;CACF;AAvBD,oCAuBC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when a resource is not found
|
|
7
|
+
*
|
|
8
|
+
* This typically means the address or resource doesn't exist on the specified chain,
|
|
9
|
+
* or hasn't been indexed yet.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* try {
|
|
14
|
+
* await client.addresses.analyze(address, { chain: Chain.ETH });
|
|
15
|
+
* } catch (error) {
|
|
16
|
+
* if (error instanceof NotFoundError) {
|
|
17
|
+
* console.error('Resource not found:', error.message);
|
|
18
|
+
* // The address may not exist or may not have any activity
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class NotFoundError extends base_1.WebacyError {
|
|
24
|
+
constructor(message = 'Resource not found', options = {}) {
|
|
25
|
+
super(message, {
|
|
26
|
+
status: 404,
|
|
27
|
+
code: 'NOT_FOUND_ERROR',
|
|
28
|
+
requestId: options.requestId,
|
|
29
|
+
endpoint: options.endpoint,
|
|
30
|
+
});
|
|
31
|
+
this.name = 'NotFoundError';
|
|
32
|
+
}
|
|
33
|
+
getRecoverySuggestion() {
|
|
34
|
+
return 'Verify the address exists and has activity on the specified chain. For new addresses, data may take a few minutes to become available.';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.NotFoundError = NotFoundError;
|
|
38
|
+
//# sourceMappingURL=not-found.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found.js","sourceRoot":"","sources":["../../../src/errors/not-found.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAErC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,aAAc,SAAQ,kBAAW;IAC5C,YACE,OAAO,GAAG,oBAAoB,EAC9B,UAAqD,EAAE;QAEvD,KAAK,CAAC,OAAO,EAAE;YACb,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,iBAAiB;YACvB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;IAEQ,qBAAqB;QAC5B,OAAO,wIAAwI,CAAC;IAClJ,CAAC;CACF;AAjBD,sCAiBC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitError = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when rate limit is exceeded
|
|
7
|
+
*
|
|
8
|
+
* The SDK automatically retries rate-limited requests with exponential backoff.
|
|
9
|
+
* If you're seeing this error frequently, consider reducing request frequency
|
|
10
|
+
* or upgrading your API plan.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* try {
|
|
15
|
+
* await client.addresses.analyze(address, { chain: Chain.ETH });
|
|
16
|
+
* } catch (error) {
|
|
17
|
+
* if (error instanceof RateLimitError) {
|
|
18
|
+
* console.error('Rate limited:', error.message);
|
|
19
|
+
* if (error.retryAfter) {
|
|
20
|
+
* console.log(`Retry after ${error.retryAfter} seconds`);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
class RateLimitError extends base_1.WebacyError {
|
|
27
|
+
/** When the rate limit resets (Unix timestamp) */
|
|
28
|
+
resetAt;
|
|
29
|
+
/** Number of seconds until reset */
|
|
30
|
+
retryAfter;
|
|
31
|
+
constructor(message = 'Rate limit exceeded', options = {}) {
|
|
32
|
+
super(message, {
|
|
33
|
+
status: 429,
|
|
34
|
+
code: 'RATE_LIMIT_ERROR',
|
|
35
|
+
requestId: options.requestId,
|
|
36
|
+
endpoint: options.endpoint,
|
|
37
|
+
});
|
|
38
|
+
this.name = 'RateLimitError';
|
|
39
|
+
this.resetAt = options.resetAt;
|
|
40
|
+
this.retryAfter = options.retryAfter;
|
|
41
|
+
}
|
|
42
|
+
isRetryable() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
getRecoverySuggestion() {
|
|
46
|
+
if (this.retryAfter) {
|
|
47
|
+
return `Wait ${this.retryAfter} seconds before retrying. Consider implementing request throttling or upgrading your API plan for higher limits.`;
|
|
48
|
+
}
|
|
49
|
+
return 'Wait a moment before retrying. Consider implementing request throttling or upgrading your API plan for higher limits.';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.RateLimitError = RateLimitError;
|
|
53
|
+
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../../src/errors/rate-limit.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,cAAe,SAAQ,kBAAW;IAC7C,kDAAkD;IAClC,OAAO,CAAU;IAEjC,oCAAoC;IACpB,UAAU,CAAU;IAEpC,YACE,OAAO,GAAG,qBAAqB,EAC/B,UAA4F,EAAE;QAE9F,KAAK,CAAC,OAAO,EAAE;YACb,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,kBAAkB;YACxB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACvC,CAAC;IAEQ,WAAW;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAEQ,qBAAqB;QAC5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO,QAAQ,IAAI,CAAC,UAAU,kHAAkH,CAAC;QACnJ,CAAC;QACD,OAAO,uHAAuH,CAAC;IACjI,CAAC;CACF;AAhCD,wCAgCC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when request validation fails
|
|
7
|
+
*
|
|
8
|
+
* This error occurs when the provided input doesn't meet the API requirements.
|
|
9
|
+
* Common causes include invalid addresses, unsupported chains, or missing parameters.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* try {
|
|
14
|
+
* await client.addresses.analyze(address, { chain: Chain.ETH });
|
|
15
|
+
* } catch (error) {
|
|
16
|
+
* if (error instanceof ValidationError) {
|
|
17
|
+
* console.error('Validation failed:', error.message);
|
|
18
|
+
* if (error.errors) {
|
|
19
|
+
* for (const [field, messages] of Object.entries(error.errors)) {
|
|
20
|
+
* console.error(` ${field}: ${messages.join(', ')}`);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
class ValidationError extends base_1.WebacyError {
|
|
28
|
+
/** Field-level validation errors */
|
|
29
|
+
errors;
|
|
30
|
+
constructor(message = 'Validation failed', options = {}) {
|
|
31
|
+
super(message, {
|
|
32
|
+
status: 400,
|
|
33
|
+
code: 'VALIDATION_ERROR',
|
|
34
|
+
requestId: options.requestId,
|
|
35
|
+
endpoint: options.endpoint,
|
|
36
|
+
});
|
|
37
|
+
this.name = 'ValidationError';
|
|
38
|
+
this.errors = options.errors;
|
|
39
|
+
}
|
|
40
|
+
getRecoverySuggestion() {
|
|
41
|
+
if (this.errors && Object.keys(this.errors).length > 0) {
|
|
42
|
+
const fields = Object.keys(this.errors).join(', ');
|
|
43
|
+
return `Check the following fields: ${fields}. Ensure address formats match the specified blockchain and all required parameters are provided.`;
|
|
44
|
+
}
|
|
45
|
+
return 'Check your input parameters. Ensure address formats match the specified blockchain (e.g., 0x... for EVM chains, base58 for Solana).';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ValidationError = ValidationError;
|
|
49
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/errors/validation.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,eAAgB,SAAQ,kBAAW;IAC9C,oCAAoC;IACpB,MAAM,CAA4B;IAElD,YACE,OAAO,GAAG,mBAAmB,EAC7B,UAAwF,EAAE;QAE1F,KAAK,CAAC,OAAO,EAAE;YACb,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,kBAAkB;YACxB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAEQ,qBAAqB;QAC5B,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnD,OAAO,+BAA+B,MAAM,mGAAmG,CAAC;QAClJ,CAAC;QACD,OAAO,qIAAqI,CAAC;IAC/I,CAAC;CACF;AAzBD,0CAyBC"}
|