@marcohefti/request-network-api-client 0.5.5 → 0.5.7

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Request Network API Client (TypeScript)
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@marcohefti/request-network-api-client.svg)](https://www.npmjs.com/package/@marcohefti/request-network-api-client)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js CI](https://github.com/marcohefti/request-network-api-client-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/marcohefti/request-network-api-client-ts/actions/workflows/ci.yml)
6
+
3
7
  TypeScript client for the Request Network hosted REST API. Provides typed, ergonomic helpers for requests, payouts, payer/compliance, client IDs, currencies, and payments, with runtime validation and webhook utilities built in.
4
8
 
5
9
  **Note**: This targets the hosted REST API, not the protocol SDK. See [SCOPE.md](docs/SCOPE.md) for when to use which.
@@ -57,15 +61,6 @@ try {
57
61
  }
58
62
  ```
59
63
 
60
- **From environment variables**:
61
-
62
- ```ts
63
- import { createRequestClientFromEnv } from '@marcohefti/request-network-api-client';
64
-
65
- const client = createRequestClientFromEnv();
66
- // Reads: REQUEST_API_URL, REQUEST_API_KEY, REQUEST_CLIENT_ID
67
- ```
68
-
69
64
  ## Documentation
70
65
 
71
66
  - **[Quick Start](docs/QUICK-START.md)** - Installation, environment setup, common recipes
@@ -96,23 +91,138 @@ See [CHANGELOG.md](CHANGELOG.md) for release history.
96
91
 
97
92
  ## Troubleshooting
98
93
 
99
- **API Key Issues**
100
- - Ensure `REQUEST_API_KEY` is set and has necessary permissions
94
+ ### Common Issues
95
+
96
+ #### API Key Problems
97
+
98
+ **Error: 401 Unauthorized**
99
+ - Ensure `REQUEST_API_KEY` is set correctly in your environment
100
+ - Verify your API key is active in the Request API Portal
101
101
  - Test with a simple call: `await client.currencies.list({ network: 'sepolia' })`
102
+ - Check for extra whitespace or quotes in your environment variable
103
+
104
+ ```bash
105
+ # Verify your API key is set
106
+ echo $REQUEST_API_KEY
107
+
108
+ # Test with a simple command
109
+ node -e "import('@marcohefti/request-network-api-client').then(m => m.createRequestClient({apiKey: process.env.REQUEST_API_KEY}).currencies.list()).then(console.log)"
110
+ ```
111
+
112
+ #### CORS Errors (Browser)
113
+
114
+ **Error: CORS policy blocks request**
115
+ - Ensure you're using a Client ID, not an API key (API keys are server-only)
116
+ - Verify your domain is in the `allowedDomains` list for your Client ID
117
+ - Check the domain matches exactly (including protocol and port)
118
+ - For localhost development, use `http://localhost:3000` format
119
+
120
+ ```typescript
121
+ // ❌ Wrong - Using API key in browser
122
+ const client = createRequestClient({
123
+ apiKey: 'rk_live_...' // This will fail with CORS
124
+ });
125
+
126
+ // ✅ Correct - Using Client ID in browser
127
+ const client = createRequestClient({
128
+ clientId: 'client_live_...'
129
+ });
130
+ ```
131
+
132
+ #### Module Not Found Errors
133
+
134
+ **Error: Cannot find module '@marcohefti/request-network-api-client'**
135
+ - Run `pnpm install` or `npm install`
136
+ - Clear node_modules and reinstall: `rm -rf node_modules && pnpm install`
137
+ - Check package.json includes the dependency
138
+ - For local development, run `pnpm build` in the package directory
102
139
 
103
- **Runtime Validation Errors**
140
+ **Error: Cannot find module '@marcohefti/request-network-api-client/requests'**
141
+ - Ensure you're using the correct import path
142
+ - Check package.json `exports` field matches your import
143
+ - Update to the latest version: `pnpm update @marcohefti/request-network-api-client`
144
+
145
+ #### Type Errors
146
+
147
+ **Error: Property does not exist on type**
148
+ - Ensure you're using the latest version of the client
149
+ - Run `pnpm update @marcohefti/request-network-api-client`
150
+ - Check your TypeScript version is >= 5.0
151
+ - Clear TypeScript cache: `rm -rf node_modules/.cache`
152
+
153
+ #### Runtime Validation Errors
154
+
155
+ **Error: ValidationError - Response validation failed**
104
156
  - The API response didn't match the expected schema
105
- - Check you're using the latest client version
157
+ - This usually means the API has changed or there's a bug
158
+ - Update to the latest client version: `pnpm update @marcohefti/request-network-api-client`
106
159
  - Temporarily disable validation to debug: `runtimeValidation: false`
160
+ - Report the issue with the full error message
161
+
162
+ ```typescript
163
+ // Debug validation errors
164
+ const client = createRequestClient({
165
+ apiKey: process.env.REQUEST_API_KEY,
166
+ runtimeValidation: false, // Temporarily disable
167
+ });
168
+ ```
169
+
170
+ #### Timeout Issues
171
+
172
+ **Error: Request timeout / AbortError**
173
+ - Increase timeout for slow operations: `{ timeoutMs: 30_000 }`
174
+ - Check your network connection
175
+ - Verify the API is accessible: `curl https://api.request.network/v2/currencies`
176
+ - Try with a different network/endpoint
177
+
178
+ ```typescript
179
+ // Increase timeout for slow endpoints
180
+ await client.requests.create(
181
+ { /* ... */ },
182
+ { timeoutMs: 30_000 } // 30 seconds
183
+ );
184
+ ```
107
185
 
108
- **Timeout Issues**
109
- - Set custom timeout: `await client.currencies.list({ network: 'sepolia' }, { timeoutMs: 10_000 })`
186
+ #### Rate Limiting (429)
110
187
 
111
- **Rate Limiting (429)**
188
+ **Error: Rate limit exceeded**
112
189
  - The client auto-retries with exponential backoff
113
- - Override retry policy: `meta: { retry: { maxAttempts: 5 } }`
190
+ - Check `err.retryAfterMs` for when to retry
191
+ - Reduce request frequency in your application
192
+ - Consider caching responses for repeated queries
193
+
194
+ ```typescript
195
+ try {
196
+ await client.currencies.list();
197
+ } catch (err) {
198
+ if (isRequestApiError(err) && err.status === 429) {
199
+ console.log(`Rate limited. Retry after ${err.retryAfterMs}ms`);
200
+ // Client will automatically retry
201
+ }
202
+ }
203
+ ```
204
+
205
+ #### Network/Connection Errors
206
+
207
+ **Error: fetch failed / ECONNREFUSED**
208
+ - Check your internet connection
209
+ - Verify API endpoint is accessible
210
+ - Check for proxy/firewall blocking requests
211
+ - Try setting a custom base URL: `baseUrl: 'https://api.request.network'`
212
+
213
+ ### Getting Help
214
+
215
+ If you're still stuck:
114
216
 
115
- See [HTTP-AND-ERRORS.md](docs/HTTP-AND-ERRORS.md) for detailed error handling patterns.
217
+ 1. Check the [examples](examples/) directory for working code
218
+ 2. Review [HTTP-AND-ERRORS.md](docs/HTTP-AND-ERRORS.md) for detailed error handling
219
+ 3. Search [existing issues](https://github.com/marcohefti/request-network-api-client-ts/issues)
220
+ 4. Create a new issue with:
221
+ - Client version (`@marcohefti/request-network-api-client@x.x.x`)
222
+ - Node.js version (`node --version`)
223
+ - Minimal code sample that reproduces the issue
224
+ - Full error message and stack trace
225
+ - Request ID from error (if available)
116
226
 
117
227
  ## Support & Security
118
228
 
package/dist/cjs/index.js CHANGED
@@ -2310,13 +2310,6 @@ function createRequestClient(options) {
2310
2310
  pay: createPayApi(http)
2311
2311
  };
2312
2312
  }
2313
- function createRequestClientFromEnv(options) {
2314
- const env = options?.env ?? process.env;
2315
- const baseUrl = env.REQUEST_API_URL ?? env.REQUEST_SDK_BASE_URL;
2316
- const apiKey = env.REQUEST_API_KEY ?? env.REQUEST_SDK_API_KEY;
2317
- const clientId = env.REQUEST_CLIENT_ID ?? env.REQUEST_SDK_CLIENT_ID;
2318
- return createRequestClient({ baseUrl, apiKey, clientId });
2319
- }
2320
2313
 
2321
2314
  // src/core/config/request-environment.config.ts
2322
2315
  var RequestEnvironment = {
@@ -3443,7 +3436,6 @@ exports.clientIds = client_ids_exports;
3443
3436
  exports.computeRetryDelay = computeRetryDelay;
3444
3437
  exports.createHttpClient = createHttpClient;
3445
3438
  exports.createRequestClient = createRequestClient;
3446
- exports.createRequestClientFromEnv = createRequestClientFromEnv;
3447
3439
  exports.currencies = currencies_exports;
3448
3440
  exports.currenciesV1 = v1_exports;
3449
3441
  exports.isRequestApiError = isRequestApiError;