@naturalpay/sdk 0.1.1
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 +261 -0
- package/dist/index.cjs +1229 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +676 -0
- package/dist/index.d.ts +676 -0
- package/dist/index.js +1208 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/cli.cjs +166 -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 +164 -0
- package/dist/mcp/cli.js.map +1 -0
- package/dist/mcp/index.cjs +8 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +9 -0
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.js +6 -0
- package/dist/mcp/index.js.map +1 -0
- package/package.json +87 -0
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
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/sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @naturalpay/sdk
|
|
11
|
+
# or
|
|
12
|
+
yarn add @naturalpay/sdk
|
|
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
|
+
agentId: 'agent_123',
|
|
27
|
+
instanceId: 'instance_456',
|
|
28
|
+
amount: 5000,
|
|
29
|
+
customerPartyId: 'party_456',
|
|
30
|
+
recipient: 'alice@example.com',
|
|
31
|
+
memo: 'Payment for consulting',
|
|
32
|
+
idempotencyKey: 'unique-key-for-this-payment',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(`Payment created: ${payment.transactionId}`);
|
|
36
|
+
|
|
37
|
+
// Check balance
|
|
38
|
+
const balance = await client.wallet.balance();
|
|
39
|
+
console.log(`Available: ${balance.available.amountMinor} minor units`);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
### Environment Variables
|
|
45
|
+
|
|
46
|
+
- `NATURAL_API_KEY` - Your API key (starts with `sk_ntl_sandbox_` or `sk_ntl_live_`)
|
|
47
|
+
- `NATURAL_SERVER_URL` - API base URL (default: `https://api.natural.co`)
|
|
48
|
+
|
|
49
|
+
### Client Options
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const client = new NaturalClient({
|
|
53
|
+
apiKey: 'sk_ntl_sandbox_xxx', // API key
|
|
54
|
+
baseUrl: 'https://api.natural.co', // Custom base URL
|
|
55
|
+
timeout: 30000, // Request timeout in ms
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Resources
|
|
60
|
+
|
|
61
|
+
### Payments
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Create a payment
|
|
65
|
+
const payment = await client.payments.create({
|
|
66
|
+
agentId: 'agent_123',
|
|
67
|
+
instanceId: 'instance_789', // required when agentId is provided
|
|
68
|
+
amount: 10000,
|
|
69
|
+
customerPartyId: 'party_456',
|
|
70
|
+
recipient: 'alice@example.com', // email, phone, or party ID (pty_xxx)
|
|
71
|
+
memo: 'Payment description',
|
|
72
|
+
idempotencyKey: 'unique-key-for-this-payment',
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Wallet
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// Get account balance
|
|
80
|
+
const balance = await client.wallet.balance();
|
|
81
|
+
|
|
82
|
+
// Withdraw funds
|
|
83
|
+
const withdrawal = await client.wallet.withdraw({
|
|
84
|
+
amount: 50000,
|
|
85
|
+
externalFundingSourceId: 'efs_xxx',
|
|
86
|
+
idempotencyKey: 'wd_unique_key',
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Transactions
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { TransactionTypeFilter } from '@naturalpay/sdk';
|
|
94
|
+
|
|
95
|
+
// List all transactions
|
|
96
|
+
const transactions = await client.transactions.list({
|
|
97
|
+
limit: 100,
|
|
98
|
+
agentId: 'agent_123',
|
|
99
|
+
instanceId: 'instance_789', // required when agentId is provided
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// List only transfers
|
|
103
|
+
const transfers = await client.transactions.list({
|
|
104
|
+
type: TransactionTypeFilter.TRANSFER,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// List only payments
|
|
108
|
+
const payments = await client.transactions.list({
|
|
109
|
+
type: TransactionTypeFilter.PAYMENT,
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Agents
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// List agents
|
|
117
|
+
const agents = await client.agents.list({
|
|
118
|
+
status: 'ACTIVE',
|
|
119
|
+
limit: 50,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Create an agent
|
|
123
|
+
const agent = await client.agents.create({
|
|
124
|
+
name: 'Shopping Assistant',
|
|
125
|
+
partyId: 'party_123',
|
|
126
|
+
description: 'Handles shopping tasks',
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Update an agent
|
|
130
|
+
const updated = await client.agents.update('agent_id', {
|
|
131
|
+
name: 'Updated Name',
|
|
132
|
+
status: 'REVOKED',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Delete an agent
|
|
136
|
+
await client.agents.delete('agent_id');
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Delegations
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
// List agent delegations
|
|
143
|
+
const delegations = await client.delegations.list({
|
|
144
|
+
limit: 50,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Get delegation details
|
|
148
|
+
const delegation = await client.delegations.get('adl_xxx');
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Customers
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// List customers who have delegated to you
|
|
155
|
+
const customers = await client.customers.list({
|
|
156
|
+
limit: 50,
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## MCP Server
|
|
161
|
+
|
|
162
|
+
The SDK includes an MCP (Model Context Protocol) server for AI agent integration.
|
|
163
|
+
|
|
164
|
+
### CLI Usage
|
|
165
|
+
|
|
166
|
+
Use `npx` to run the CLI without global installation:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Show help
|
|
170
|
+
npx @naturalpay/sdk --help
|
|
171
|
+
|
|
172
|
+
# Start MCP server with stdio transport
|
|
173
|
+
npx @naturalpay/sdk mcp serve
|
|
174
|
+
|
|
175
|
+
# With explicit options
|
|
176
|
+
npx @naturalpay/sdk mcp serve --api-key sk_ntl_sandbox_xxx --mcp-url https://mcp.natural.co
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
> **Note:** We recommend `npx` over global installation to avoid conflicts if you also use the Python SDK (`uvx naturalpay` or `python -m naturalpay`).
|
|
180
|
+
|
|
181
|
+
### Claude Desktop / Cursor Config
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"mcpServers": {
|
|
186
|
+
"natural": {
|
|
187
|
+
"command": "npx",
|
|
188
|
+
"args": ["@naturalpay/sdk", "mcp", "serve"],
|
|
189
|
+
"env": { "NATURAL_API_KEY": "sk_ntl_..." }
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Available MCP Tools
|
|
196
|
+
|
|
197
|
+
| Tool | Description |
|
|
198
|
+
|------|-------------|
|
|
199
|
+
| `create_payment` | Create a payment to a recipient |
|
|
200
|
+
| `get_payment_status` | Check payment status by transfer ID |
|
|
201
|
+
| `get_account_balance` | Get current wallet balance |
|
|
202
|
+
| `list_transactions` | List recent transactions |
|
|
203
|
+
| `list_agents` | List agents for the partner |
|
|
204
|
+
| `list_customers` | List customers who delegated to you |
|
|
205
|
+
|
|
206
|
+
## Error Handling
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import {
|
|
210
|
+
NaturalError,
|
|
211
|
+
AuthenticationError,
|
|
212
|
+
InvalidRequestError,
|
|
213
|
+
PaymentError,
|
|
214
|
+
InsufficientFundsError,
|
|
215
|
+
RecipientNotFoundError,
|
|
216
|
+
RateLimitError,
|
|
217
|
+
ServerError,
|
|
218
|
+
} from '@naturalpay/sdk';
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
await client.payments.create({ ... });
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (error instanceof AuthenticationError) {
|
|
224
|
+
// Handle authentication issues (401)
|
|
225
|
+
} else if (error instanceof InsufficientFundsError) {
|
|
226
|
+
// Handle insufficient balance
|
|
227
|
+
} else if (error instanceof RecipientNotFoundError) {
|
|
228
|
+
// Handle invalid recipient
|
|
229
|
+
} else if (error instanceof RateLimitError) {
|
|
230
|
+
// Handle rate limiting (429)
|
|
231
|
+
console.log(`Retry after: ${error.retryAfter}s`);
|
|
232
|
+
} else if (error instanceof ServerError) {
|
|
233
|
+
// Handle server errors (5xx)
|
|
234
|
+
} else if (error instanceof NaturalError) {
|
|
235
|
+
// Handle other API errors
|
|
236
|
+
console.log(`Error: ${error.message}, Code: ${error.code}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## TypeScript Support
|
|
242
|
+
|
|
243
|
+
This SDK is written in TypeScript and provides full type definitions:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import type {
|
|
247
|
+
PaymentCreateParams,
|
|
248
|
+
AccountBalance,
|
|
249
|
+
Transaction,
|
|
250
|
+
TransactionListResponse,
|
|
251
|
+
Agent,
|
|
252
|
+
AgentDelegation,
|
|
253
|
+
WithdrawResponse,
|
|
254
|
+
} from '@naturalpay/sdk';
|
|
255
|
+
|
|
256
|
+
import { TransactionTypeFilter } from '@naturalpay/sdk';
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|