@paynodelabs/sdk-js 2.2.0 → 2.2.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 +2 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +24 -10
- package/dist/middleware/x402.js +2 -2
- package/dist/types/x402.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://docs.paynode.dev)
|
|
4
4
|
[](https://www.npmjs.com/package/@paynodelabs/sdk-js)
|
|
5
5
|
|
|
6
|
-
The official TypeScript/JavaScript SDK for the **PayNode Protocol (v2.2.
|
|
6
|
+
The official TypeScript/JavaScript SDK for the **PayNode Protocol (v2.2.1)**. PayNode is a stateless, non-custodial M2M payment gateway that standardizes the HTTP 402 "Payment Required" flow for AI Agents, with support for both on-chain receipts and off-chain signatures (EIP-3009).
|
|
7
7
|
|
|
8
8
|
## 📖 Read the Docs
|
|
9
9
|
|
|
@@ -33,7 +33,7 @@ async function main() {
|
|
|
33
33
|
main();
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
### Key Features (v2.2.
|
|
36
|
+
### Key Features (v2.2.1)
|
|
37
37
|
- **Zero-Wait Checkout**: API response speed drops from 5 seconds to **under 50ms** by using local signatures instead of waiting for on-chain inclusion.
|
|
38
38
|
- **Double-Spend Protection**:
|
|
39
39
|
- **L1 (Memory)**: High-speed local replay protection via `IdempotencyStore`.
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,eAAe,EAEhB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAID,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,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,EAAE,GAAG,CAAM,GAC9B,OAAO,CAAC,eAAe,CAAC;IA6CrB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBpH,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IA8BrJ,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAE,MAAa,EAAE,OAAO,GAAE,MAAY;;;;;;YAyChH,UAAU;CAYzB"}
|
package/dist/client.js
CHANGED
|
@@ -78,20 +78,28 @@ class PayNodeAgentClient {
|
|
|
78
78
|
const b64Required = response.headers.get('PAYMENT-REQUIRED') || response.headers.get('X-402-Required');
|
|
79
79
|
const orderId = response.headers.get('X-402-Order-Id');
|
|
80
80
|
let body = null;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
else if (b64Required) {
|
|
81
|
+
let headerBody = null;
|
|
82
|
+
if (b64Required) {
|
|
85
83
|
try {
|
|
86
84
|
const decoded = typeof globalThis.Buffer !== 'undefined'
|
|
87
85
|
? globalThis.Buffer.from(b64Required, 'base64').toString()
|
|
88
86
|
: atob(b64Required);
|
|
89
|
-
|
|
87
|
+
headerBody = JSON.parse(decoded);
|
|
90
88
|
}
|
|
91
89
|
catch (e) {
|
|
92
90
|
console.debug('⚠️ [PayNode-JS] Failed to parse PAYMENT-REQUIRED header:', e);
|
|
93
91
|
}
|
|
94
92
|
}
|
|
93
|
+
if (contentType && contentType.includes('application/json')) {
|
|
94
|
+
try {
|
|
95
|
+
body = await response.clone().json();
|
|
96
|
+
}
|
|
97
|
+
catch (e) { /* ignore */ }
|
|
98
|
+
}
|
|
99
|
+
// Robustness: Merge header info into body if body is missing critical bits
|
|
100
|
+
if (headerBody && (!body || !body.x402Version)) {
|
|
101
|
+
body = { ...body, ...headerBody };
|
|
102
|
+
}
|
|
95
103
|
if (body && body.x402Version === 2) {
|
|
96
104
|
console.log(`🚀 [PayNode-JS] x402 v2 detected. Handling autonomous payment...`);
|
|
97
105
|
if (orderId && !body.orderId)
|
|
@@ -148,7 +156,7 @@ class PayNodeAgentClient {
|
|
|
148
156
|
},
|
|
149
157
|
payload: authorization,
|
|
150
158
|
_paynode: {
|
|
151
|
-
version: "2.2.
|
|
159
|
+
version: "2.2.1",
|
|
152
160
|
type: 'eip3009',
|
|
153
161
|
orderId: orderId
|
|
154
162
|
}
|
|
@@ -192,7 +200,7 @@ class PayNodeAgentClient {
|
|
|
192
200
|
},
|
|
193
201
|
payload: { txHash },
|
|
194
202
|
_paynode: {
|
|
195
|
-
version: "2.2.
|
|
203
|
+
version: "2.2.1",
|
|
196
204
|
type: 'onchain',
|
|
197
205
|
orderId: orderId
|
|
198
206
|
}
|
|
@@ -220,9 +228,15 @@ class PayNodeAgentClient {
|
|
|
220
228
|
const settleHeader = retryResponse.headers.get('PAYMENT-RESPONSE') || retryResponse.headers.get('X-PAYMENT-RESPONSE');
|
|
221
229
|
if (settleHeader) {
|
|
222
230
|
try {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
let decoded;
|
|
232
|
+
if (settleHeader.trim().startsWith('{')) {
|
|
233
|
+
decoded = settleHeader;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
decoded = typeof globalThis.Buffer !== 'undefined'
|
|
237
|
+
? globalThis.Buffer.from(settleHeader, 'base64').toString()
|
|
238
|
+
: atob(settleHeader);
|
|
239
|
+
}
|
|
226
240
|
const settleData = JSON.parse(decoded);
|
|
227
241
|
if (settleData.success) {
|
|
228
242
|
console.log(`✅ [PayNode-JS] Settlement confirmed: ${settleData.transaction}`);
|
package/dist/middleware/x402.js
CHANGED
|
@@ -63,7 +63,7 @@ const x402Gate = (options) => {
|
|
|
63
63
|
inferredType = "onchain";
|
|
64
64
|
}
|
|
65
65
|
unifiedPayload = {
|
|
66
|
-
version: "2.2.
|
|
66
|
+
version: "2.2.1",
|
|
67
67
|
type: parsed._paynode?.type || inferredType,
|
|
68
68
|
orderId: internalOrderId,
|
|
69
69
|
router: parsed.accepted?.router,
|
|
@@ -71,7 +71,7 @@ const x402Gate = (options) => {
|
|
|
71
71
|
};
|
|
72
72
|
orderId = internalOrderId;
|
|
73
73
|
}
|
|
74
|
-
else if (parsed.version === "2.2.
|
|
74
|
+
else if (typeof parsed.version === 'string' && (parsed.version.startsWith("2.3") || parsed.version.startsWith("2.2"))) {
|
|
75
75
|
// Legacy PayNode format
|
|
76
76
|
unifiedPayload = parsed;
|
|
77
77
|
if (unifiedPayload?.orderId) {
|
package/dist/types/x402.d.ts
CHANGED