monei-sdk 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 +351 -0
- package/dist/client/MoneiClient.d.ts +15 -0
- package/dist/client/MoneiClient.js +78 -0
- package/dist/errors/MoneiError.d.ts +17 -0
- package/dist/errors/MoneiError.js +36 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +48 -0
- package/dist/services/AgentService.d.ts +14 -0
- package/dist/services/AgentService.js +42 -0
- package/dist/services/BillService.d.ts +13 -0
- package/dist/services/BillService.js +30 -0
- package/dist/services/EvmService.d.ts +11 -0
- package/dist/services/EvmService.js +28 -0
- package/dist/services/ExchangeService.d.ts +16 -0
- package/dist/services/ExchangeService.js +43 -0
- package/dist/services/SolanaService.d.ts +12 -0
- package/dist/services/SolanaService.js +30 -0
- package/dist/services/TransactionService.d.ts +9 -0
- package/dist/services/TransactionService.js +18 -0
- package/dist/services/UserService.d.ts +8 -0
- package/dist/services/UserService.js +15 -0
- package/dist/services/WalletService.d.ts +15 -0
- package/dist/services/WalletService.js +41 -0
- package/dist/services/index.d.ts +8 -0
- package/dist/services/index.js +19 -0
- package/dist/types/agent.d.ts +42 -0
- package/dist/types/agent.js +2 -0
- package/dist/types/beneficiary.d.ts +0 -0
- package/dist/types/beneficiary.js +1 -0
- package/dist/types/bills.d.ts +118 -0
- package/dist/types/bills.js +2 -0
- package/dist/types/evm.d.ts +51 -0
- package/dist/types/evm.js +2 -0
- package/dist/types/exchange.d.ts +47 -0
- package/dist/types/exchange.js +2 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.js +24 -0
- package/dist/types/solana.d.ts +52 -0
- package/dist/types/solana.js +2 -0
- package/dist/types/transaction.d.ts +35 -0
- package/dist/types/transaction.js +2 -0
- package/dist/types/user.d.ts +29 -0
- package/dist/types/user.js +2 -0
- package/dist/types/wallet.d.ts +102 -0
- package/dist/types/wallet.js +2 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Mr. Monei Node.js SDK
|
|
2
|
+
|
|
3
|
+
The official Node.js SDK for Monei API - providing seamless integration with Monei's comprehensive financial services including wallets, crypto transactions, bill payments, and AI agent.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install monei-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import MoneiSDK from 'monei-sdk';
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
// Initialize SDK with API key
|
|
18
|
+
const sdk = new MoneiSDK({
|
|
19
|
+
apiKey: process.env.MONEI_API_KEY!
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// Get user info
|
|
24
|
+
const user = await sdk.user.getCurrentUser();
|
|
25
|
+
console.log(`Welcome ${user.data.firstName} ${user.data.lastName}!`);
|
|
26
|
+
|
|
27
|
+
// Get wallet balance
|
|
28
|
+
const wallet = await sdk.wallet.getWalletBalance();
|
|
29
|
+
console.log(`Naira Balance: ₦${wallet.nairaBalance.toLocaleString()}`);
|
|
30
|
+
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error('Error:', error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
main();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **User Management** - Profile, KYC verification, user updates
|
|
42
|
+
- **Wallet Operations** - Balance, funding, withdrawals, peer transfers, bank verification
|
|
43
|
+
- **EVM Wallets** - Ethereum, BSC, Polygon, Arbitrum support
|
|
44
|
+
- **Solana Wallets** - SOL and SPL token management
|
|
45
|
+
- **Bill Payments** - Airtime, data, electricity, cable TV
|
|
46
|
+
- **Crypto Exchange** - Token swaps on EVM and Solana
|
|
47
|
+
- **AI Agent** - Conversational banking assistant with streaming support
|
|
48
|
+
- **Transaction Management** - Transaction history and tracking
|
|
49
|
+
- **Beneficiary Management** - Bank, crypto, and peer beneficiaries
|
|
50
|
+
- **Full TypeScript Support** - Complete type definitions
|
|
51
|
+
|
|
52
|
+
## Basic Usage Examples
|
|
53
|
+
|
|
54
|
+
### 1. Wallet Operations
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import MoneiSDK from 'monei-sdk';
|
|
58
|
+
|
|
59
|
+
const sdk = new MoneiSDK({ apiKey: 'your-api-key' });
|
|
60
|
+
|
|
61
|
+
// Fund wallet
|
|
62
|
+
const fundResult = await sdk.wallet.fundWalletByNaira({
|
|
63
|
+
amount: 5000
|
|
64
|
+
});
|
|
65
|
+
console.log(`Funding link: ${fundResult.data.link}`);
|
|
66
|
+
|
|
67
|
+
// Peer transfer
|
|
68
|
+
await sdk.wallet.peerTransfer({
|
|
69
|
+
receiver: "user@example.com",
|
|
70
|
+
amount: 1000,
|
|
71
|
+
transactionPin: "123456"
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Get banks and verify account
|
|
75
|
+
const banks = await sdk.wallet.getBanks();
|
|
76
|
+
const account = await sdk.wallet.verifyBankAccount({
|
|
77
|
+
accountNumber: "1234567890",
|
|
78
|
+
bank: "058" // GTBank code
|
|
79
|
+
});
|
|
80
|
+
console.log(`Account Name: ${account.data.accountName}`);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 2. Crypto Operations - EVM
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// Get EVM portfolio
|
|
87
|
+
const portfolio = await sdk.evm.getPortfolio(56); // BSC
|
|
88
|
+
console.log(`Portfolio value: $${portfolio.data.totalPortfolioValueUSD}`);
|
|
89
|
+
|
|
90
|
+
// Get token balance
|
|
91
|
+
const balance = await sdk.evm.getTokenBalance(
|
|
92
|
+
'0x6B175474E89094C44Da98b954EedeAC495271d0F', // DAI
|
|
93
|
+
1 // Ethereum
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Send native token
|
|
97
|
+
const transferResult = await sdk.evm.sendNativeToken({
|
|
98
|
+
to: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
|
99
|
+
amount: "0.01",
|
|
100
|
+
chainId: 1 // Ethereum
|
|
101
|
+
});
|
|
102
|
+
console.log(`Transaction hash: ${transferResult.data.txHash}`);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 3. Crypto Operations - Solana
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Get Solana wallet address
|
|
109
|
+
const address = await sdk.solana.getWalletAddress();
|
|
110
|
+
console.log(`Wallet address: ${address.data.address}`);
|
|
111
|
+
|
|
112
|
+
// Get portfolio
|
|
113
|
+
const portfolio = await sdk.solana.getPortfolio('mainnet-beta');
|
|
114
|
+
console.log(`SOL Balance: ${portfolio.data.nativeBalance}`);
|
|
115
|
+
|
|
116
|
+
// Transfer SOL
|
|
117
|
+
const transferResult = await sdk.solana.sendNativeToken({
|
|
118
|
+
to: "5AH3qo1v1EZfT3QKQpSsx1F8W5JyGEVZPcD5DzkX1N1d",
|
|
119
|
+
amount: "1.5",
|
|
120
|
+
network: "mainnet-beta"
|
|
121
|
+
});
|
|
122
|
+
console.log(`Signature: ${transferResult.data.signature}`);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 4. Bill Payments
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Buy airtime
|
|
129
|
+
const airtimeResult = await sdk.bills.buyAirtime({
|
|
130
|
+
phoneNumber: "08012345678",
|
|
131
|
+
biller: "MTN",
|
|
132
|
+
amount: 500
|
|
133
|
+
});
|
|
134
|
+
console.log(`Airtime purchase successful! Reference: ${airtimeResult.data.reference}`);
|
|
135
|
+
|
|
136
|
+
// Buy electricity
|
|
137
|
+
const electricityResult = await sdk.bills.buyElectricity({
|
|
138
|
+
meterNumber: "04123456789",
|
|
139
|
+
amount: 2000,
|
|
140
|
+
disco: "IKEJA DISCO ELECTRICITY"
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Get bill history
|
|
144
|
+
const history = await sdk.bills.getBillHistory();
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 5. AI Agent
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// Get conversations
|
|
151
|
+
const conversations = await sdk.agent.getConversations();
|
|
152
|
+
|
|
153
|
+
// Initialize conversation
|
|
154
|
+
await sdk.agent.initializeConversation({
|
|
155
|
+
id: "conv_123"
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Chat with AI agent
|
|
159
|
+
const chatResponse = await sdk.agent.chat({
|
|
160
|
+
message: "What's my current account balance?",
|
|
161
|
+
conversationId: "conv_123"
|
|
162
|
+
});
|
|
163
|
+
console.log(`Agent: ${chatResponse.response}`);
|
|
164
|
+
|
|
165
|
+
// Get conversation messages
|
|
166
|
+
const messages = await sdk.agent.getConversationMessages("conv_123", 20);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 6. Crypto Exchange
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Get swap quote
|
|
173
|
+
const quote = await sdk.exchange.getNativeToTokenQuote({
|
|
174
|
+
amount: "0.1",
|
|
175
|
+
tokenOut: "0x6B175474E89094C44Da98b954EedeAC495271d0F", // DAI
|
|
176
|
+
chainId: 1
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Execute swap
|
|
180
|
+
const swapResult = await sdk.exchange.swapNativeToToken({
|
|
181
|
+
amount: "0.1",
|
|
182
|
+
tokenOut: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
|
183
|
+
chainId: 1
|
|
184
|
+
});
|
|
185
|
+
console.log(`Swap transaction: ${swapResult.data.txHash}`);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 7. Transaction Management
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// Get user transactions
|
|
192
|
+
const transactions = await sdk.transactions.getUserTransactions();
|
|
193
|
+
console.log(`Found ${transactions.data.length} transactions`);
|
|
194
|
+
|
|
195
|
+
// Get specific transaction
|
|
196
|
+
const transaction = await sdk.transactions.getTransactionById("txn_123");
|
|
197
|
+
console.log(`Amount: ${transaction.amount} ${transaction.currency}`);
|
|
198
|
+
|
|
199
|
+
// Get transaction by reference
|
|
200
|
+
const txByRef = await sdk.transactions.getTransactionByReference("ref_456");
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Advanced Usage
|
|
204
|
+
|
|
205
|
+
### Error Handling
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { MoneiError, AuthenticationError, ValidationError } from 'monei-sdk';
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await sdk.user.getCurrentUser();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (error instanceof AuthenticationError) {
|
|
214
|
+
console.log('Authentication failed - check your API key or bearer token');
|
|
215
|
+
} else if (error instanceof ValidationError) {
|
|
216
|
+
console.log('Invalid request parameters');
|
|
217
|
+
} else if (error instanceof MoneiError) {
|
|
218
|
+
console.log(`API Error: ${error.message} (Status: ${error.statusCode})`);
|
|
219
|
+
} else {
|
|
220
|
+
console.log('Unexpected error:', error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Using with Async/Await
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
async function comprehensiveExample() {
|
|
229
|
+
const sdk = new MoneiSDK({
|
|
230
|
+
apiKey: process.env.MONEI_API_KEY!,
|
|
231
|
+
baseUrl: 'https://api.monei.cc', // Optional
|
|
232
|
+
timeout: 30000 // Optional, default 30s
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
// Multiple operations
|
|
237
|
+
const [user, wallet, transactions] = await Promise.all([
|
|
238
|
+
sdk.user.getCurrentUser(),
|
|
239
|
+
sdk.wallet.getWalletBalance(),
|
|
240
|
+
sdk.transactions.getUserTransactions()
|
|
241
|
+
]);
|
|
242
|
+
|
|
243
|
+
console.log(`User: ${user.data.name}`);
|
|
244
|
+
console.log(`Balance: ₦${wallet.nairaBalance}`);
|
|
245
|
+
console.log(`Transaction count: ${transactions.data.length}`);
|
|
246
|
+
|
|
247
|
+
} catch(error) {
|
|
248
|
+
console.error('Error:', error);
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Environment Configuration
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// config/monei.ts
|
|
258
|
+
import MoneiSDK from 'monei-sdk';
|
|
259
|
+
|
|
260
|
+
export const moneiSDK = new MoneiSDK({
|
|
261
|
+
apiKey: process.env.MONEI_API_KEY!,
|
|
262
|
+
baseUrl: process.env.MONEI_BASE_URL || 'https://api.monei.cc',
|
|
263
|
+
timeout: parseInt(process.env.MONEI_TIMEOUT || '30000')
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## API Reference
|
|
269
|
+
|
|
270
|
+
### SDK Configuration
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
interface MoneiConfig {
|
|
274
|
+
apiKey: string; // Required: Your Monei API key
|
|
275
|
+
baseUrl?: string; // Optional: API base URL (default: https://api.monei.cc)
|
|
276
|
+
timeout?: number; // Optional: Request timeout in ms (default: 30000)
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Available Services
|
|
281
|
+
|
|
282
|
+
- `sdk.user` - User profile and management
|
|
283
|
+
- `sdk.wallet` - Wallet operations and banking
|
|
284
|
+
- `sdk.evm` - EVM blockchain operations
|
|
285
|
+
- `sdk.solana` - Solana blockchain operations
|
|
286
|
+
- `sdk.transactions` - Transaction history
|
|
287
|
+
- `sdk.agent` - AI agent conversations
|
|
288
|
+
- `sdk.bills` - Bill payments
|
|
289
|
+
- `sdk.exchange` - Crypto token swaps
|
|
290
|
+
|
|
291
|
+
## Authentication
|
|
292
|
+
|
|
293
|
+
Get your API key from the [Mr. Monei Dashboard](https://monei.cc).
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
// Recommended: Use environment variables
|
|
297
|
+
const sdk = new MoneiSDK({
|
|
298
|
+
apiKey: process.env.MONEI_API_KEY!
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Error Types
|
|
304
|
+
|
|
305
|
+
The SDK provides specific error types for better error handling:
|
|
306
|
+
|
|
307
|
+
- `MoneiError` - Base error class
|
|
308
|
+
- `AuthenticationError` - Authentication failures (401)
|
|
309
|
+
- `ValidationError` - Invalid request parameters (400)
|
|
310
|
+
- `NotFoundError` - Resource not found (404)
|
|
311
|
+
- `RateLimitError` - Rate limit exceeded (429)
|
|
312
|
+
|
|
313
|
+
## Common Chain IDs
|
|
314
|
+
|
|
315
|
+
| Chain | Chain ID | Network Name |
|
|
316
|
+
|-------|----------|--------------|
|
|
317
|
+
| Ethereum | 1 | Mainnet |
|
|
318
|
+
| BSC | 56 | Mainnet |
|
|
319
|
+
| Polygon | 137 | Mainnet |
|
|
320
|
+
| Arbitrum | 42161 | Mainnet |
|
|
321
|
+
| Optimism | 10 | Mainnet |
|
|
322
|
+
| Base | 8453 | Mainnet |
|
|
323
|
+
|
|
324
|
+
## Solana Networks
|
|
325
|
+
|
|
326
|
+
- `mainnet-beta` - Solana mainnet
|
|
327
|
+
- `devnet` - Solana development network
|
|
328
|
+
- `testnet` - Solana test network
|
|
329
|
+
|
|
330
|
+
## Getting Help
|
|
331
|
+
|
|
332
|
+
- **Documentation**: [Mr. Monei API Gateway Docs](https://goviral-ai-lab.gitbook.io/monei-api-gateway-docs/)
|
|
333
|
+
- **API Reference**: [Interactive API Docs](https://api.monei.cc/api-gateway-docs)
|
|
334
|
+
- **Support**: tech@monei.cc
|
|
335
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/monei/monei-nodejs-sdk/issues)
|
|
336
|
+
|
|
337
|
+
## Contributing
|
|
338
|
+
|
|
339
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
340
|
+
|
|
341
|
+
## License
|
|
342
|
+
|
|
343
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
344
|
+
|
|
345
|
+
## Changelog
|
|
346
|
+
|
|
347
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history and changes.
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
**Note**: This SDK is designed for server-side use only. Never expose your API keys in client-side code.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { MoneiConfig } from '../types';
|
|
3
|
+
export declare class MoneiClient {
|
|
4
|
+
private client;
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: MoneiConfig);
|
|
7
|
+
private setupInterceptors;
|
|
8
|
+
get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
9
|
+
post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
10
|
+
patch<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
11
|
+
delete<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
12
|
+
setApiKey(apiKey: string): void;
|
|
13
|
+
setBearerToken(token: string): void;
|
|
14
|
+
removeBearerToken(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MoneiClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const MoneiError_1 = require("../errors/MoneiError");
|
|
9
|
+
class MoneiClient {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = {
|
|
12
|
+
baseUrl: 'https://api.monei.cc',
|
|
13
|
+
timeout: 30000,
|
|
14
|
+
...config
|
|
15
|
+
};
|
|
16
|
+
this.client = axios_1.default.create({
|
|
17
|
+
baseURL: this.config.baseUrl,
|
|
18
|
+
timeout: this.config.timeout,
|
|
19
|
+
headers: {
|
|
20
|
+
'X-API-KEY': this.config.apiKey,
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
this.setupInterceptors();
|
|
25
|
+
}
|
|
26
|
+
setupInterceptors() {
|
|
27
|
+
this.client.interceptors.response.use((response) => response, (error) => {
|
|
28
|
+
if (error.response) {
|
|
29
|
+
const { status, data } = error.response;
|
|
30
|
+
switch (status) {
|
|
31
|
+
case 400:
|
|
32
|
+
throw new MoneiError_1.ValidationError(data?.message || 'Bad request');
|
|
33
|
+
case 401:
|
|
34
|
+
throw new MoneiError_1.AuthenticationError(data?.message || 'Unauthorized');
|
|
35
|
+
case 404:
|
|
36
|
+
throw new MoneiError_1.NotFoundError(data?.message || 'Not found');
|
|
37
|
+
case 429:
|
|
38
|
+
throw new MoneiError_1.RateLimitError(data?.message || 'Rate limit exceeded');
|
|
39
|
+
default:
|
|
40
|
+
throw new MoneiError_1.MoneiError(data?.message || 'Internal server error', status);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (error.request) {
|
|
44
|
+
throw new MoneiError_1.MoneiError('Network error: Unable to connect to API');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new MoneiError_1.MoneiError('Request configuration error');
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async get(url, config) {
|
|
52
|
+
const response = await this.client.get(url, config);
|
|
53
|
+
return response.data;
|
|
54
|
+
}
|
|
55
|
+
async post(url, data, config) {
|
|
56
|
+
const response = await this.client.post(url, data, config);
|
|
57
|
+
return response.data;
|
|
58
|
+
}
|
|
59
|
+
async patch(url, data, config) {
|
|
60
|
+
const response = await this.client.patch(url, data, config);
|
|
61
|
+
return response.data;
|
|
62
|
+
}
|
|
63
|
+
async delete(url, config) {
|
|
64
|
+
const response = await this.client.delete(url, config);
|
|
65
|
+
return response.data;
|
|
66
|
+
}
|
|
67
|
+
setApiKey(apiKey) {
|
|
68
|
+
this.config.apiKey = apiKey;
|
|
69
|
+
this.client.defaults.headers['X-API-KEY'] = apiKey;
|
|
70
|
+
}
|
|
71
|
+
setBearerToken(token) {
|
|
72
|
+
this.client.defaults.headers['Authorization'] = `Bearer ${token}`;
|
|
73
|
+
}
|
|
74
|
+
removeBearerToken() {
|
|
75
|
+
delete this.client.defaults.headers['Authorization'];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.MoneiClient = MoneiClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class MoneiError extends Error {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
code: string;
|
|
4
|
+
constructor(message: string, statusCode?: number, code?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class AuthenticationError extends MoneiError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class ValidationError extends MoneiError {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class NotFoundError extends MoneiError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class RateLimitError extends MoneiError {
|
|
16
|
+
constructor(message?: string);
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitError = exports.NotFoundError = exports.ValidationError = exports.AuthenticationError = exports.MoneiError = void 0;
|
|
4
|
+
class MoneiError extends Error {
|
|
5
|
+
constructor(message, statusCode = 500, code = 'INTERNAL_ERROR') {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'MoneiError';
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.MoneiError = MoneiError;
|
|
13
|
+
class AuthenticationError extends MoneiError {
|
|
14
|
+
constructor(message = 'Authentication failed') {
|
|
15
|
+
super(message, 401, 'AUTHENTICATION_ERROR');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AuthenticationError = AuthenticationError;
|
|
19
|
+
class ValidationError extends MoneiError {
|
|
20
|
+
constructor(message = 'Validation failed') {
|
|
21
|
+
super(message, 400, 'VALIDATION_ERROR');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ValidationError = ValidationError;
|
|
25
|
+
class NotFoundError extends MoneiError {
|
|
26
|
+
constructor(message = 'Resource not found') {
|
|
27
|
+
super(message, 404, 'NOT_FOUND_ERROR');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.NotFoundError = NotFoundError;
|
|
31
|
+
class RateLimitError extends MoneiError {
|
|
32
|
+
constructor(message = 'Rate limit exceeded') {
|
|
33
|
+
super(message, 429, 'RATE_LIMIT_ERROR');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.RateLimitError = RateLimitError;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MoneiConfig } from './types';
|
|
2
|
+
import { UserService, WalletService, EvmService, SolanaService, TransactionService, AgentService, BillService, ExchangeService } from './services';
|
|
3
|
+
export declare class MoneiSDK {
|
|
4
|
+
user: UserService;
|
|
5
|
+
wallet: WalletService;
|
|
6
|
+
evm: EvmService;
|
|
7
|
+
solana: SolanaService;
|
|
8
|
+
transactions: TransactionService;
|
|
9
|
+
agent: AgentService;
|
|
10
|
+
bills: BillService;
|
|
11
|
+
exchange: ExchangeService;
|
|
12
|
+
private client;
|
|
13
|
+
constructor(config: MoneiConfig);
|
|
14
|
+
setBearerToken(token: string): void;
|
|
15
|
+
removeBearerToken(): void;
|
|
16
|
+
setApiKey(apiKey: string): void;
|
|
17
|
+
}
|
|
18
|
+
export * from './types';
|
|
19
|
+
export * from './errors/MoneiError';
|
|
20
|
+
export default MoneiSDK;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.MoneiSDK = void 0;
|
|
18
|
+
const MoneiClient_1 = require("./client/MoneiClient");
|
|
19
|
+
const services_1 = require("./services");
|
|
20
|
+
class MoneiSDK {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.client = new MoneiClient_1.MoneiClient(config);
|
|
23
|
+
// Initialize all services
|
|
24
|
+
this.user = new services_1.UserService(this.client);
|
|
25
|
+
this.wallet = new services_1.WalletService(this.client);
|
|
26
|
+
this.evm = new services_1.EvmService(this.client);
|
|
27
|
+
this.solana = new services_1.SolanaService(this.client);
|
|
28
|
+
this.transactions = new services_1.TransactionService(this.client);
|
|
29
|
+
this.agent = new services_1.AgentService(this.client);
|
|
30
|
+
this.bills = new services_1.BillService(this.client);
|
|
31
|
+
this.exchange = new services_1.ExchangeService(this.client);
|
|
32
|
+
}
|
|
33
|
+
// Helper methods for authentication
|
|
34
|
+
setBearerToken(token) {
|
|
35
|
+
this.client.setBearerToken(token);
|
|
36
|
+
}
|
|
37
|
+
removeBearerToken() {
|
|
38
|
+
this.client.removeBearerToken();
|
|
39
|
+
}
|
|
40
|
+
setApiKey(apiKey) {
|
|
41
|
+
this.client.setApiKey(apiKey);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.MoneiSDK = MoneiSDK;
|
|
45
|
+
// Export all types
|
|
46
|
+
__exportStar(require("./types"), exports);
|
|
47
|
+
__exportStar(require("./errors/MoneiError"), exports);
|
|
48
|
+
exports.default = MoneiSDK;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MoneiClient } from '../client/MoneiClient';
|
|
2
|
+
import { ConversationListResponseDto, ConversationMessagesResponseDto, CreateConversationDto, PinConversationDto, AgentChatRequestDto, AgentChatResponseDto, AgentStreamRequestDto, GuestAgentRequestDto } from '../types';
|
|
3
|
+
export declare class AgentService {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: MoneiClient);
|
|
6
|
+
getConversations(): Promise<ConversationListResponseDto[]>;
|
|
7
|
+
getConversationMessages(conversationId: string, limit?: number): Promise<ConversationMessagesResponseDto[]>;
|
|
8
|
+
initializeConversation(conversationData: CreateConversationDto): Promise<any>;
|
|
9
|
+
chat(chatData: AgentChatRequestDto): Promise<AgentChatResponseDto>;
|
|
10
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
11
|
+
pinConversation(conversationId: string, pinData: PinConversationDto): Promise<void>;
|
|
12
|
+
streamChat(streamData: AgentStreamRequestDto): Promise<any>;
|
|
13
|
+
streamGuestChat(guestData: GuestAgentRequestDto): Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentService = void 0;
|
|
4
|
+
class AgentService {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async getConversations() {
|
|
9
|
+
return this.client.get('/api/v1/agent/conversations');
|
|
10
|
+
}
|
|
11
|
+
async getConversationMessages(conversationId, limit) {
|
|
12
|
+
const params = limit ? { limit } : undefined;
|
|
13
|
+
return this.client.get(`/api/v1/agent/conversations/${conversationId}/messages`, { params });
|
|
14
|
+
}
|
|
15
|
+
async initializeConversation(conversationData) {
|
|
16
|
+
return this.client.post('/api/v1/agent/conversations/init-conversation', conversationData);
|
|
17
|
+
}
|
|
18
|
+
async chat(chatData) {
|
|
19
|
+
return this.client.post('/api/v1/agent/conversations', chatData);
|
|
20
|
+
}
|
|
21
|
+
async deleteConversation(conversationId) {
|
|
22
|
+
await this.client.delete(`/api/v1/agent/conversations/${conversationId}`);
|
|
23
|
+
}
|
|
24
|
+
async pinConversation(conversationId, pinData) {
|
|
25
|
+
await this.client.patch(`/api/v1/agent/conversations/${conversationId}/pin`, pinData);
|
|
26
|
+
}
|
|
27
|
+
async streamChat(streamData) {
|
|
28
|
+
return this.client.post('/api/v1/agent/conversations/stream', streamData, {
|
|
29
|
+
headers: {
|
|
30
|
+
'Accept': 'text/event-stream'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async streamGuestChat(guestData) {
|
|
35
|
+
return this.client.post('/api/v1/guest-agent/stream', guestData, {
|
|
36
|
+
headers: {
|
|
37
|
+
'Accept': 'text/event-stream'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.AgentService = AgentService;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MoneiClient } from '../client/MoneiClient';
|
|
2
|
+
import { BillCategory, BillerItemsResponseDto, ValidateBillDto, AirtimePurchaseDto, DataPurchaseDto, ElectricityPaymentDto, CableTvPaymentDto, BillPaymentResponseDto, BillDto } from '../types';
|
|
3
|
+
export declare class BillService {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: MoneiClient);
|
|
6
|
+
getBillerItems(category: BillCategory, billerName: string): Promise<BillerItemsResponseDto>;
|
|
7
|
+
validateBill(validateData: ValidateBillDto): Promise<any>;
|
|
8
|
+
buyAirtime(airtimeData: AirtimePurchaseDto): Promise<BillPaymentResponseDto>;
|
|
9
|
+
buyMobileData(dataData: DataPurchaseDto): Promise<BillPaymentResponseDto>;
|
|
10
|
+
buyElectricity(electricityData: ElectricityPaymentDto): Promise<BillPaymentResponseDto>;
|
|
11
|
+
subscribeCableTv(cableData: CableTvPaymentDto): Promise<BillPaymentResponseDto>;
|
|
12
|
+
getBillHistory(): Promise<BillDto[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BillService = void 0;
|
|
4
|
+
class BillService {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async getBillerItems(category, billerName) {
|
|
9
|
+
return this.client.get(`/api/v1/bills/get-biller-items/${category}/${billerName}`);
|
|
10
|
+
}
|
|
11
|
+
async validateBill(validateData) {
|
|
12
|
+
return this.client.post('/api/v1/bills/validate', validateData);
|
|
13
|
+
}
|
|
14
|
+
async buyAirtime(airtimeData) {
|
|
15
|
+
return this.client.post('/api/v1/bills/buy-airtime', airtimeData);
|
|
16
|
+
}
|
|
17
|
+
async buyMobileData(dataData) {
|
|
18
|
+
return this.client.post('/api/v1/bills/buy-mobile-data', dataData);
|
|
19
|
+
}
|
|
20
|
+
async buyElectricity(electricityData) {
|
|
21
|
+
return this.client.post('/api/v1/bills/buy-electricity', electricityData);
|
|
22
|
+
}
|
|
23
|
+
async subscribeCableTv(cableData) {
|
|
24
|
+
return this.client.post('/api/v1/bills/subscribe-cable-tv', cableData);
|
|
25
|
+
}
|
|
26
|
+
async getBillHistory() {
|
|
27
|
+
return this.client.get('/api/v1/bills/history');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.BillService = BillService;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MoneiClient } from '../client/MoneiClient';
|
|
2
|
+
import { UserEvmPortfolioResponseDto, SendNativeTokenDto, SendNativeTokenResponseDto, SendTokenDto, SendTokenResponseDto, BalanceResponseDto } from '../types';
|
|
3
|
+
export declare class EvmService {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: MoneiClient);
|
|
6
|
+
getPortfolio(chainId: number): Promise<UserEvmPortfolioResponseDto>;
|
|
7
|
+
getNativeBalance(chainId: number): Promise<BalanceResponseDto>;
|
|
8
|
+
getTokenBalance(tokenAddress: string, chainId: number): Promise<BalanceResponseDto>;
|
|
9
|
+
sendNativeToken(sendData: SendNativeTokenDto): Promise<SendNativeTokenResponseDto>;
|
|
10
|
+
sendToken(sendData: SendTokenDto): Promise<SendTokenResponseDto>;
|
|
11
|
+
}
|