@piprail/sdk 1.5.1 → 1.6.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/CHANGELOG.md +12 -0
- package/README.md +3 -1
- package/dist/index.cjs +6 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ All notable changes to `@piprail/sdk` are documented here. The format
|
|
|
4
4
|
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the
|
|
5
5
|
versions follow [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.6.0] — 2026-06-05
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **`policy.tokens` accepts `'native'`** — a chain-agnostic alias that allows the chain's native coin
|
|
11
|
+
(ETH/BNB/TRX/XLM/…) by the same word the accept side already uses (`token: 'native'`), without naming
|
|
12
|
+
the per-chain ticker. It's matched on the asset (not the symbol), so it works on every family; symbol
|
|
13
|
+
matching is unchanged (the real ticker still works), and `'native'` only ever matches a genuinely
|
|
14
|
+
native asset — it never loosens a stablecoin allowlist. Closes a terminology gap where allowing native
|
|
15
|
+
payments previously required knowing the coin's symbol. `@piprail/mcp`'s `PIPRAIL_TOKENS` inherits this.
|
|
16
|
+
Additive + non-breaking (next release is a minor).
|
|
17
|
+
|
|
7
18
|
## [1.5.1] — 2026-06-04
|
|
8
19
|
|
|
9
20
|
**Cosmetic polish — docs & comments only, zero behavior change.** A repo-wide tidy pass so the
|
|
@@ -406,6 +417,7 @@ straight into your wallet. The API is small and self-contained.
|
|
|
406
417
|
to your wallet; PipRail never holds funds.
|
|
407
418
|
- `viem ^2.21` is a peer dependency. Node 20+ or a modern browser.
|
|
408
419
|
|
|
420
|
+
[1.6.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
409
421
|
[1.5.1]: https://www.npmjs.com/package/@piprail/sdk
|
|
410
422
|
[1.5.0]: https://www.npmjs.com/package/@piprail/sdk
|
|
411
423
|
[1.4.0]: https://www.npmjs.com/package/@piprail/sdk
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const client = new PipRailClient({
|
|
|
52
52
|
maxAmount: '0.10', // never pay more than $0.10 for one call
|
|
53
53
|
maxTotal: '5.00', // never spend more than $5 total (per token)
|
|
54
54
|
chains: ['base'], // only on Base
|
|
55
|
-
tokens: ['USDC'], // only in USDC
|
|
55
|
+
tokens: ['USDC'], // only in USDC (use 'native' to also allow the chain's coin)
|
|
56
56
|
hosts: ['*.example.com'], // only these hosts
|
|
57
57
|
},
|
|
58
58
|
onBeforePay: (q) => Number(q.amountFormatted) <= 0.05, // final say on each payment
|
|
@@ -75,6 +75,8 @@ client.spent() // → { count, byAsset: [{ symbol:'USDC', totalFormatted:'0.05',
|
|
|
75
75
|
|
|
76
76
|
**The budget can't be fooled.** `maxAmount`/`maxTotal` are enforced against the token's **true** decimals (the SDK's own, via the driver) — a server can't slip past a cap by understating the price, and an asset the SDK can't recognise is refused unless you set `allowUnknownTokens`. `quote()` even flags a `symbolMismatch` when a challenge's stated symbol disagrees with the real token.
|
|
77
77
|
|
|
78
|
+
**`policy.tokens` takes symbols *or* `'native'`.** List stablecoin symbols (`'USDC'`, `'USDT'`, …) and/or the chain-agnostic alias **`'native'`** to allow the chain's own coin (ETH/BNB/TRX/XLM/…) on any family — the same word the accept side uses (`token: 'native'`), so you never name per-chain tickers (the real ticker works too). It only ever matches a genuinely native asset, so it never loosens a stablecoin-only list. The MCP server's `PIPRAIL_TOKENS` is the same allowlist.
|
|
79
|
+
|
|
78
80
|
**Know the gas before you pay.** `client.estimateCost(url)` returns the quote **and** a `CostEstimate` — the network fee in the chain's **native coin** (you pay in USDC but burn ETH / SOL / TON / XLM / XRP / TRX on gas, a separate balance the agent must keep topped up). It's best-effort and labelled (`cost.basis`): a live-RPC read where cheap (`'estimated'` — EVM gas price, XRPL fee), a typical-cost constant otherwise (`'heuristic'`), and it never throws. Most valuable on **Tron**, where a USD₮ transfer can cost real TRX. So an agent can budget the *total* — payment **+** gas — before any funds move. Every driver implements it; the math is extracted per-chain and shaped uniformly by one shared `nativeCost()` helper.
|
|
79
81
|
|
|
80
82
|
### Plan before you pay — `planPayment()` (never fumble a payment)
|
package/dist/index.cjs
CHANGED
|
@@ -923,7 +923,12 @@ function evaluatePolicy(intent, policy, spentForAssetBase) {
|
|
|
923
923
|
}
|
|
924
924
|
if (policy.tokens) {
|
|
925
925
|
const sym = intent.recognized ? intent.symbol : void 0;
|
|
926
|
-
|
|
926
|
+
const isNative = intent.asset === "native";
|
|
927
|
+
const matches = policy.tokens.some((t) => {
|
|
928
|
+
if (isNative && t.toUpperCase() === "NATIVE") return true;
|
|
929
|
+
return sym ? t.toUpperCase() === sym.toUpperCase() : false;
|
|
930
|
+
});
|
|
931
|
+
if (!matches) {
|
|
927
932
|
return deny(
|
|
928
933
|
`token ${_nullishCoalesce(intent.symbol, () => ( intent.asset))} is not in the allowed set (policy.tokens).`
|
|
929
934
|
);
|
package/dist/index.d.cts
CHANGED
|
@@ -4014,8 +4014,11 @@ interface PaymentPolicy {
|
|
|
4014
4014
|
/** Allowlist of chains the agent may pay on. A 402 on any other chain is
|
|
4015
4015
|
* declined. Strings match the configured selector; objects match by id. */
|
|
4016
4016
|
chains?: ChainSelector[];
|
|
4017
|
-
/** Allowlist of token symbols (matched against the TRUE symbol).
|
|
4018
|
-
*
|
|
4017
|
+
/** Allowlist of token symbols (matched against the TRUE symbol). The special
|
|
4018
|
+
* value `'native'` is a chain-agnostic alias for the chain's native coin — it
|
|
4019
|
+
* matches the native asset on ANY family (ETH/BNB/TRX/XLM/…) without naming
|
|
4020
|
+
* the ticker, mirroring the merchant-side `token: 'native'`. An asset the SDK
|
|
4021
|
+
* can't recognise never satisfies this list. */
|
|
4019
4022
|
tokens?: string[];
|
|
4020
4023
|
/** Allowlist of hosts. Exact (`api.example.com`) or wildcard (`*.example.com`). */
|
|
4021
4024
|
hosts?: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -4014,8 +4014,11 @@ interface PaymentPolicy {
|
|
|
4014
4014
|
/** Allowlist of chains the agent may pay on. A 402 on any other chain is
|
|
4015
4015
|
* declined. Strings match the configured selector; objects match by id. */
|
|
4016
4016
|
chains?: ChainSelector[];
|
|
4017
|
-
/** Allowlist of token symbols (matched against the TRUE symbol).
|
|
4018
|
-
*
|
|
4017
|
+
/** Allowlist of token symbols (matched against the TRUE symbol). The special
|
|
4018
|
+
* value `'native'` is a chain-agnostic alias for the chain's native coin — it
|
|
4019
|
+
* matches the native asset on ANY family (ETH/BNB/TRX/XLM/…) without naming
|
|
4020
|
+
* the ticker, mirroring the merchant-side `token: 'native'`. An asset the SDK
|
|
4021
|
+
* can't recognise never satisfies this list. */
|
|
4019
4022
|
tokens?: string[];
|
|
4020
4023
|
/** Allowlist of hosts. Exact (`api.example.com`) or wildcard (`*.example.com`). */
|
|
4021
4024
|
hosts?: string[];
|
package/dist/index.js
CHANGED
|
@@ -923,7 +923,12 @@ function evaluatePolicy(intent, policy, spentForAssetBase) {
|
|
|
923
923
|
}
|
|
924
924
|
if (policy.tokens) {
|
|
925
925
|
const sym = intent.recognized ? intent.symbol : void 0;
|
|
926
|
-
|
|
926
|
+
const isNative = intent.asset === "native";
|
|
927
|
+
const matches = policy.tokens.some((t) => {
|
|
928
|
+
if (isNative && t.toUpperCase() === "NATIVE") return true;
|
|
929
|
+
return sym ? t.toUpperCase() === sym.toUpperCase() : false;
|
|
930
|
+
});
|
|
931
|
+
if (!matches) {
|
|
927
932
|
return deny(
|
|
928
933
|
`token ${intent.symbol ?? intent.asset} is not in the allowed set (policy.tokens).`
|
|
929
934
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@piprail/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Accept x402 crypto payments across 28 chains — every major EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Algorand, Stellar & XRPL — in a couple of lines. No backend, no database, no fee; payments settle straight to your wallet.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|