@naturalpay/sdk 0.0.2
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 +290 -0
- package/dist/index.cjs +968 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +703 -0
- package/dist/index.d.ts +703 -0
- package/dist/index.js +947 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/cli.cjs +1096 -0
- package/dist/mcp/cli.cjs.map +1 -0
- package/dist/mcp/cli.d.cts +1 -0
- package/dist/mcp/cli.d.ts +1 -0
- package/dist/mcp/cli.js +1094 -0
- package/dist/mcp/cli.js.map +1 -0
- package/dist/mcp/index.cjs +1046 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +19 -0
- package/dist/mcp/index.d.ts +19 -0
- package/dist/mcp/index.js +1044 -0
- package/dist/mcp/index.js.map +1 -0
- package/package.json +86 -0
package/README.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# Natural Payments TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript/Node.js SDK for Natural Payments - AI agent payment infrastructure.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install naturalpay
|
|
9
|
+
# or
|
|
10
|
+
pnpm add naturalpay
|
|
11
|
+
# or
|
|
12
|
+
yarn add naturalpay
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { NaturalClient } from '@naturalpay/sdk';
|
|
19
|
+
|
|
20
|
+
const client = new NaturalClient({
|
|
21
|
+
apiKey: process.env.NATURAL_API_KEY, // or pass directly
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Create a payment
|
|
25
|
+
const payment = await client.payments.create({
|
|
26
|
+
recipientEmail: 'alice@example.com',
|
|
27
|
+
amount: 50.00,
|
|
28
|
+
currency: 'USD',
|
|
29
|
+
memo: 'Payment for consulting',
|
|
30
|
+
agentId: 'agent_123',
|
|
31
|
+
customerPartyId: 'party_456',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(`Payment created: ${payment.transferId}`);
|
|
35
|
+
|
|
36
|
+
// Check balance
|
|
37
|
+
const balance = await client.wallet.balance();
|
|
38
|
+
console.log(`Available: $${balance.balances[0]?.available.amountDollars}`);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
### Environment Variables
|
|
44
|
+
|
|
45
|
+
- `NATURAL_API_KEY` - Your API key (starts with `pk_sandbox_` or `pk_live_`)
|
|
46
|
+
- `NATURAL_SERVER_URL` - API base URL (default: `https://api.natural.co`)
|
|
47
|
+
|
|
48
|
+
### Client Options
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const client = new NaturalClient({
|
|
52
|
+
apiKey: 'pk_sandbox_xxx', // API key
|
|
53
|
+
baseUrl: 'https://api.natural.co', // Custom base URL
|
|
54
|
+
timeout: 30000, // Request timeout in ms
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Resources
|
|
59
|
+
|
|
60
|
+
### Payments
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// Create a payment
|
|
64
|
+
const payment = await client.payments.create({
|
|
65
|
+
recipientEmail: 'alice@example.com',
|
|
66
|
+
// or recipientPhone: '+1234567890',
|
|
67
|
+
amount: 100.00,
|
|
68
|
+
currency: 'USD',
|
|
69
|
+
memo: 'Payment description',
|
|
70
|
+
agentId: 'agent_123',
|
|
71
|
+
customerPartyId: 'party_456',
|
|
72
|
+
instanceId: 'instance_789', // optional, for audit grouping
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Get payment status
|
|
76
|
+
const status = await client.payments.retrieve('transfer_id');
|
|
77
|
+
|
|
78
|
+
// Cancel a pending payment
|
|
79
|
+
const result = await client.payments.cancel('transfer_id');
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Wallet
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// Get account balance
|
|
86
|
+
const balance = await client.wallet.balance();
|
|
87
|
+
|
|
88
|
+
// Deposit funds (sandbox only)
|
|
89
|
+
const deposit = await client.wallet.deposit({
|
|
90
|
+
amount: 1000,
|
|
91
|
+
currency: 'USD',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Withdraw funds
|
|
95
|
+
const withdrawal = await client.wallet.withdraw({
|
|
96
|
+
amount: 500,
|
|
97
|
+
bankAccountId: 'bank_account_id',
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Transactions
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { TransactionTypeFilter } from '@naturalpay/sdk';
|
|
105
|
+
|
|
106
|
+
// List all transactions
|
|
107
|
+
const transactions = await client.transactions.list({
|
|
108
|
+
limit: 100,
|
|
109
|
+
customerFilter: '_self', // or customer agent_id
|
|
110
|
+
agentId: 'agent_123',
|
|
111
|
+
customerPartyId: 'party_456',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// List only transfers
|
|
115
|
+
const transfers = await client.transactions.list({
|
|
116
|
+
type: TransactionTypeFilter.TRANSFER,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// List only payments
|
|
120
|
+
const payments = await client.transactions.list({
|
|
121
|
+
type: TransactionTypeFilter.PAYMENT,
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Agents
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// List agents
|
|
129
|
+
const agents = await client.agents.list({
|
|
130
|
+
status: 'ACTIVE',
|
|
131
|
+
limit: 50,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Create an agent
|
|
135
|
+
const agent = await client.agents.create({
|
|
136
|
+
name: 'Shopping Assistant',
|
|
137
|
+
partyId: 'party_123',
|
|
138
|
+
description: 'Handles shopping tasks',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Update an agent
|
|
142
|
+
const updated = await client.agents.update('agent_id', {
|
|
143
|
+
name: 'Updated Name',
|
|
144
|
+
status: 'REVOKED',
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Delete an agent
|
|
148
|
+
await client.agents.delete('agent_id');
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Delegations
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// List delegations
|
|
155
|
+
const delegations = await client.delegations.list({
|
|
156
|
+
status: 'ACTIVE',
|
|
157
|
+
limit: 50,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Get delegation details
|
|
161
|
+
const delegation = await client.delegations.retrieve('delegation_id');
|
|
162
|
+
|
|
163
|
+
// Create a delegation
|
|
164
|
+
const newDelegation = await client.delegations.create({
|
|
165
|
+
targetPartyId: 'party_123',
|
|
166
|
+
permissions: ['payment:create', 'balance:read'],
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Update delegation
|
|
170
|
+
const updatedDelegation = await client.delegations.update('delegation_id', {
|
|
171
|
+
status: 'REVOKED',
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Customers
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// List customers
|
|
179
|
+
const customers = await client.customers.list({
|
|
180
|
+
limit: 50,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Get customer details
|
|
184
|
+
const customer = await client.customers.retrieve('customer_party_id');
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## MCP Server
|
|
188
|
+
|
|
189
|
+
The SDK includes an MCP (Model Context Protocol) server for AI agent integration.
|
|
190
|
+
|
|
191
|
+
### CLI Usage
|
|
192
|
+
|
|
193
|
+
Use `npx` to run the CLI without global installation:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Show help
|
|
197
|
+
npx naturalpay --help
|
|
198
|
+
|
|
199
|
+
# Start MCP server with stdio transport
|
|
200
|
+
npx naturalpay mcp serve
|
|
201
|
+
|
|
202
|
+
# Start with HTTP transport
|
|
203
|
+
npx naturalpay mcp serve --transport http --port 8080
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
> **Note:** We recommend `npx` over global installation to avoid conflicts if you also use the Python SDK (`uvx naturalpay` or `python -m naturalpay`).
|
|
207
|
+
|
|
208
|
+
### Programmatic Usage
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { createServer } from 'naturalpay/mcp';
|
|
212
|
+
|
|
213
|
+
const server = createServer('pk_sandbox_xxx');
|
|
214
|
+
|
|
215
|
+
// Start with stdio
|
|
216
|
+
server.start({ transportType: 'stdio' });
|
|
217
|
+
|
|
218
|
+
// Or start with HTTP
|
|
219
|
+
server.start({
|
|
220
|
+
transportType: 'httpStream',
|
|
221
|
+
httpStream: { port: 8080 },
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Available MCP Tools
|
|
226
|
+
|
|
227
|
+
| Tool | Description |
|
|
228
|
+
|------|-------------|
|
|
229
|
+
| `create_payment` | Create a payment to a recipient |
|
|
230
|
+
| `get_payment_status` | Check payment status by transfer ID |
|
|
231
|
+
| `cancel_payment` | Cancel a pending payment |
|
|
232
|
+
| `get_account_balance` | Get current wallet balance |
|
|
233
|
+
| `list_transactions` | List recent transactions |
|
|
234
|
+
| `list_agents` | List agents for the partner |
|
|
235
|
+
|
|
236
|
+
## Error Handling
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import {
|
|
240
|
+
NaturalError,
|
|
241
|
+
AuthenticationError,
|
|
242
|
+
InvalidRequestError,
|
|
243
|
+
PaymentError,
|
|
244
|
+
InsufficientFundsError,
|
|
245
|
+
RecipientNotFoundError,
|
|
246
|
+
RateLimitError,
|
|
247
|
+
ServerError,
|
|
248
|
+
} from '@naturalpay/sdk';
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
await client.payments.create({ ... });
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (error instanceof AuthenticationError) {
|
|
254
|
+
// Handle authentication issues (401)
|
|
255
|
+
} else if (error instanceof InsufficientFundsError) {
|
|
256
|
+
// Handle insufficient balance
|
|
257
|
+
} else if (error instanceof RecipientNotFoundError) {
|
|
258
|
+
// Handle invalid recipient
|
|
259
|
+
} else if (error instanceof RateLimitError) {
|
|
260
|
+
// Handle rate limiting (429)
|
|
261
|
+
console.log(`Retry after: ${error.retryAfter}s`);
|
|
262
|
+
} else if (error instanceof ServerError) {
|
|
263
|
+
// Handle server errors (5xx)
|
|
264
|
+
} else if (error instanceof NaturalError) {
|
|
265
|
+
// Handle other API errors
|
|
266
|
+
console.log(`Error: ${error.message}, Code: ${error.code}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## TypeScript Support
|
|
272
|
+
|
|
273
|
+
This SDK is written in TypeScript and provides full type definitions:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import type {
|
|
277
|
+
Payment,
|
|
278
|
+
PaymentCreateParams,
|
|
279
|
+
AccountBalance,
|
|
280
|
+
Transaction,
|
|
281
|
+
TransactionTypeFilter,
|
|
282
|
+
Agent,
|
|
283
|
+
Delegation,
|
|
284
|
+
Customer,
|
|
285
|
+
} from '@naturalpay/sdk';
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT
|