@faremeter/rides 0.16.0 → 0.17.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/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/internal.d.ts +28 -1
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +41 -11
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +2 -0
- package/dist/src/solana.d.ts +1 -1
- package/dist/src/solana.d.ts.map +1 -1
- package/dist/src/solana.js +8 -6
- package/dist/src/types.d.ts +6 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Rides Package
|
|
3
|
+
* @sidebarTitle Rides
|
|
4
|
+
* @description High-level payer interface for multi-chain x402 payments
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
1
7
|
export { payer, createPayer } from "./internal.js";
|
|
8
|
+
export type { WalletAdapter } from "./types.js";
|
|
2
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/src/index.js
CHANGED
package/dist/src/internal.d.ts
CHANGED
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
import { type WrapOpts } from "@faremeter/fetch";
|
|
2
|
-
import { type KnownNetwork, type KnownAsset } from "./types.js";
|
|
2
|
+
import { type KnownNetwork, type KnownAsset, type WalletAdapter } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for creating a payer instance.
|
|
5
|
+
*/
|
|
3
6
|
export interface CreatePayerArgs {
|
|
7
|
+
/** Networks to enable for payments. Defaults to all known networks. */
|
|
4
8
|
networks?: KnownNetwork[];
|
|
9
|
+
/** Assets to enable for payments. Defaults to all known assets. */
|
|
5
10
|
assets?: KnownAsset[];
|
|
11
|
+
/** Custom fetch function to wrap. Defaults to globalThis.fetch. */
|
|
6
12
|
fetch?: typeof globalThis.fetch;
|
|
13
|
+
/** Additional options for fetch wrapping and balance checks. */
|
|
7
14
|
options?: {
|
|
15
|
+
/** Options passed to the fetch wrapper. */
|
|
8
16
|
fetch?: WrapOpts;
|
|
17
|
+
/** If true, skips balance validation before payment attempts. */
|
|
9
18
|
disableBalanceChecks?: boolean;
|
|
10
19
|
};
|
|
11
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a payer instance that manages wallets and payment-enabled fetch.
|
|
23
|
+
*
|
|
24
|
+
* The payer automatically handles x402 payment flows by wrapping fetch with
|
|
25
|
+
* payment capabilities. Wallets must be added via addLocalWallet before
|
|
26
|
+
* making paid requests.
|
|
27
|
+
*
|
|
28
|
+
* @param args - Optional configuration for networks, assets, and fetch behavior
|
|
29
|
+
* @returns A payer object with addLocalWallet and fetch methods
|
|
30
|
+
*/
|
|
12
31
|
export declare function createPayer(args?: CreatePayerArgs): {
|
|
32
|
+
addWalletAdapter: (adapter: WalletAdapter) => void;
|
|
13
33
|
addLocalWallet: (input: unknown) => Promise<void>;
|
|
14
34
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
15
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Default payer instance with all networks and assets enabled.
|
|
38
|
+
*
|
|
39
|
+
* Use addLocalWallet to attach wallet credentials before making requests
|
|
40
|
+
* with the fetch method.
|
|
41
|
+
*/
|
|
16
42
|
export declare const payer: {
|
|
43
|
+
addWalletAdapter: (adapter: WalletAdapter) => void;
|
|
17
44
|
addLocalWallet: (input: unknown) => Promise<void>;
|
|
18
45
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
19
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,QAAQ,EAEd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,UAAU,EAGf,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAMjB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,mEAAmE;IACnE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,gEAAgE;IAChE,OAAO,CAAC,EAAE;QACR,2CAA2C;QAC3C,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjB,iEAAiE;QACjE,oBAAoB,CAAC,EAAE,OAAO,CAAC;KAChC,CAAC;CACH;AAQD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,eAAe;gCAoFb,aAAa;4BAUhB,OAAO;mBA2B5B,WAAW,GAAG,GAAG,SACjB,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC;EAKvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK;gCApDmB,aAAa;4BAUhB,OAAO;mBA2B5B,WAAW,GAAG,GAAG,SACjB,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC;CAaU,CAAC"}
|
package/dist/src/internal.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import { x402PaymentId } from "@faremeter/types/x402";
|
|
2
1
|
import {} from "@faremeter/types/client";
|
|
3
2
|
import { wrap as wrapFetch, chooseFirstAvailable, } from "@faremeter/fetch";
|
|
4
|
-
import {} from "@faremeter/types/client";
|
|
5
3
|
import { KnownNetworks, KnownAssets, } from "./types.js";
|
|
4
|
+
import { logger } from "./logger.js";
|
|
6
5
|
import * as solana from "./solana.js";
|
|
7
6
|
import * as evm from "./evm.js";
|
|
8
7
|
function idKey({ network, scheme, asset }) {
|
|
9
8
|
return `${network}\0${scheme}\0${asset}`;
|
|
10
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a payer instance that manages wallets and payment-enabled fetch.
|
|
12
|
+
*
|
|
13
|
+
* The payer automatically handles x402 payment flows by wrapping fetch with
|
|
14
|
+
* payment capabilities. Wallets must be added via addLocalWallet before
|
|
15
|
+
* making paid requests.
|
|
16
|
+
*
|
|
17
|
+
* @param args - Optional configuration for networks, assets, and fetch behavior
|
|
18
|
+
* @returns A payer object with addLocalWallet and fetch methods
|
|
19
|
+
*/
|
|
11
20
|
export function createPayer(args) {
|
|
12
21
|
const { networks = KnownNetworks, assets = KnownAssets, fetch = globalThis.fetch, } = args ?? {};
|
|
13
22
|
const paymentHandlers = [];
|
|
@@ -32,11 +41,17 @@ export function createPayer(args) {
|
|
|
32
41
|
if (getBalance === undefined) {
|
|
33
42
|
continue;
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
let balance;
|
|
45
|
+
try {
|
|
46
|
+
balance = await getBalance();
|
|
47
|
+
}
|
|
48
|
+
catch (cause) {
|
|
49
|
+
logger.warning(`failed to check balance on ${req.network} for ${req.scheme}, skipping`, { cause });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
36
52
|
// XXX - We need to do a better job of understanding decimals here.
|
|
37
|
-
if (balance.amount < BigInt(req.
|
|
38
|
-
|
|
39
|
-
console.log(`Not paying with ${balance.name} on ${req.network} using the ${req.scheme} scheme: balance is ${balance.amount} which is less than ${req.maxAmountRequired}`);
|
|
53
|
+
if (balance.amount < BigInt(req.amount)) {
|
|
54
|
+
logger.info(`Not paying with ${balance.name} on ${req.network} using the ${req.scheme} scheme: balance is ${balance.amount} which is less than ${req.amount}`);
|
|
40
55
|
continue;
|
|
41
56
|
}
|
|
42
57
|
viableOptions.push(e);
|
|
@@ -54,12 +69,24 @@ export function createPayer(args) {
|
|
|
54
69
|
});
|
|
55
70
|
};
|
|
56
71
|
let _fetch;
|
|
72
|
+
/**
|
|
73
|
+
* Registers a wallet adapter directly, bypassing the plugin system.
|
|
74
|
+
*
|
|
75
|
+
* @param adapter - The wallet adapter to register
|
|
76
|
+
*/
|
|
77
|
+
const addWalletAdapter = (adapter) => {
|
|
78
|
+
_fetch = undefined;
|
|
79
|
+
paymentHandlers.push(adapter.paymentHandler);
|
|
80
|
+
for (const id of adapter.x402Id) {
|
|
81
|
+
balanceLookup.set(idKey(id), adapter.getBalance);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
57
84
|
return {
|
|
85
|
+
addWalletAdapter,
|
|
58
86
|
addLocalWallet: async (input) => {
|
|
59
87
|
if (input === undefined) {
|
|
60
88
|
throw new Error("undefined is not a valid local wallet");
|
|
61
89
|
}
|
|
62
|
-
_fetch = undefined;
|
|
63
90
|
const newWallets = [];
|
|
64
91
|
for (const adapter of adapters) {
|
|
65
92
|
const res = await adapter.addLocalWallet(input);
|
|
@@ -71,11 +98,8 @@ export function createPayer(args) {
|
|
|
71
98
|
if (newWallets.length === 0) {
|
|
72
99
|
throw new Error("couldn't find any way to use provided local wallet information");
|
|
73
100
|
}
|
|
74
|
-
paymentHandlers.push(...newWallets.map((x) => x.paymentHandler));
|
|
75
101
|
for (const wallet of newWallets) {
|
|
76
|
-
|
|
77
|
-
balanceLookup.set(idKey(id), wallet.getBalance);
|
|
78
|
-
}
|
|
102
|
+
addWalletAdapter(wallet);
|
|
79
103
|
}
|
|
80
104
|
},
|
|
81
105
|
fetch: async (input, init) => {
|
|
@@ -84,4 +108,10 @@ export function createPayer(args) {
|
|
|
84
108
|
},
|
|
85
109
|
};
|
|
86
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Default payer instance with all networks and assets enabled.
|
|
113
|
+
*
|
|
114
|
+
* Use addLocalWallet to attach wallet credentials before making requests
|
|
115
|
+
* with the fetch method.
|
|
116
|
+
*/
|
|
87
117
|
export const payer = createPayer();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,kCAA0C,CAAC"}
|
package/dist/src/solana.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type WalletAdapter } from "./types.js";
|
|
2
2
|
import { Keypair } from "@solana/web3.js";
|
|
3
3
|
export declare function findNetworkMintCombinations(networks: readonly string[], assets: readonly string[]): {
|
|
4
|
-
cluster: "testnet" | "
|
|
4
|
+
cluster: "testnet" | "mainnet-beta" | "devnet";
|
|
5
5
|
mints: {
|
|
6
6
|
address: string;
|
|
7
7
|
name: "USDC";
|
package/dist/src/solana.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/solana.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,OAAO,EAAa,OAAO,EAA6B,MAAM,iBAAiB,CAAC;AAWhF,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,EAAE,SAAS,MAAM,EAAE;;;;;;IA2B1B;AAED,eAAO,MAAM,YAAY,8IAKvB,CAAC;AAEH,wBAAsB,SAAS,CAAC,KAAK,EAAE,OAAO,gCAe7C;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB;4BAQtB,OAAO;
|
|
1
|
+
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/solana.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,OAAO,EAAa,OAAO,EAA6B,MAAM,iBAAiB,CAAC;AAWhF,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,EAAE,SAAS,MAAM,EAAE;;;;;;IA2B1B;AAED,eAAO,MAAM,YAAY,8IAKvB,CAAC;AAEH,wBAAsB,SAAS,CAAC,KAAK,EAAE,OAAO,gCAe7C;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB;4BAQtB,OAAO;cA0DxC"}
|
package/dist/src/solana.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { match } from "arktype";
|
|
2
|
-
import {
|
|
2
|
+
import { clusterToCAIP2, lookupKnownSPLToken, } from "@faremeter/info/solana";
|
|
3
3
|
import { createLocalWallet } from "@faremeter/wallet-solana";
|
|
4
4
|
import { exact } from "@faremeter/payment-solana";
|
|
5
5
|
import {} from "./types.js";
|
|
@@ -73,11 +73,13 @@ export function createAdapter(opts) {
|
|
|
73
73
|
const connection = new Connection(clusterApiUrl(cluster), "confirmed");
|
|
74
74
|
const wallet = await createLocalWallet(cluster, privateKey);
|
|
75
75
|
res.push({
|
|
76
|
-
x402Id:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
x402Id: [
|
|
77
|
+
{
|
|
78
|
+
scheme: "exact",
|
|
79
|
+
asset: mint.address,
|
|
80
|
+
network: clusterToCAIP2(cluster).caip2,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
81
83
|
paymentHandler: exact.createPaymentHandler(wallet, new PublicKey(mint.address), connection),
|
|
82
84
|
getBalance: async () => {
|
|
83
85
|
let balance = await getTokenBalance({
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { x402PaymentId } from "@faremeter/types/x402";
|
|
2
1
|
import { type PaymentHandler } from "@faremeter/types/client";
|
|
3
2
|
export declare const KnownNetworks: readonly ["base", "base-sepolia", "monad", "monad-testnet", "polygon", "polygon-amoy", "solana", "solana-devnet"];
|
|
4
3
|
export type KnownNetwork = (typeof KnownNetworks)[number];
|
|
@@ -10,8 +9,13 @@ export type Balance = {
|
|
|
10
9
|
decimals: number;
|
|
11
10
|
};
|
|
12
11
|
export type GetBalance = () => Promise<Balance>;
|
|
12
|
+
export type PaymentIdV2 = {
|
|
13
|
+
scheme: string;
|
|
14
|
+
network: string;
|
|
15
|
+
asset: string;
|
|
16
|
+
};
|
|
13
17
|
export interface WalletAdapter {
|
|
14
|
-
x402Id:
|
|
18
|
+
x402Id: PaymentIdV2[];
|
|
15
19
|
paymentHandler: PaymentHandler;
|
|
16
20
|
getBalance: GetBalance;
|
|
17
21
|
}
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D,eAAO,MAAM,aAAa,mHAShB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,eAAO,MAAM,WAAW,mBAAoB,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,CAAC;CACrE"}
|
package/dist/src/types.js
CHANGED