@faremeter/rides 0.16.0 → 0.17.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/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/internal.d.ts +25 -0
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +18 -4
- 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
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"}
|
package/dist/src/index.js
CHANGED
package/dist/src/internal.d.ts
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
import { type WrapOpts } from "@faremeter/fetch";
|
|
2
2
|
import { type KnownNetwork, type KnownAsset } 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): {
|
|
13
32
|
addLocalWallet: (input: unknown) => Promise<void>;
|
|
14
33
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
15
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Default payer instance with all networks and assets enabled.
|
|
37
|
+
*
|
|
38
|
+
* Use addLocalWallet to attach wallet credentials before making requests
|
|
39
|
+
* with the fetch method.
|
|
40
|
+
*/
|
|
16
41
|
export declare const payer: {
|
|
17
42
|
addLocalWallet: (input: unknown) => Promise<void>;
|
|
18
43
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
@@ -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,EAGhB,MAAM,SAAS,CAAC;AAKjB;;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;4BAuEhB,OAAO;mBAiC5B,WAAW,GAAG,GAAG,SACjB,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC;EAKvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK;4BAhDgB,OAAO;mBAiC5B,WAAW,GAAG,GAAG,SACjB,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC;CAaU,CAAC"}
|
package/dist/src/internal.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
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";
|
|
6
4
|
import * as solana from "./solana.js";
|
|
7
5
|
import * as evm from "./evm.js";
|
|
8
6
|
function idKey({ network, scheme, asset }) {
|
|
9
7
|
return `${network}\0${scheme}\0${asset}`;
|
|
10
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a payer instance that manages wallets and payment-enabled fetch.
|
|
11
|
+
*
|
|
12
|
+
* The payer automatically handles x402 payment flows by wrapping fetch with
|
|
13
|
+
* payment capabilities. Wallets must be added via addLocalWallet before
|
|
14
|
+
* making paid requests.
|
|
15
|
+
*
|
|
16
|
+
* @param args - Optional configuration for networks, assets, and fetch behavior
|
|
17
|
+
* @returns A payer object with addLocalWallet and fetch methods
|
|
18
|
+
*/
|
|
11
19
|
export function createPayer(args) {
|
|
12
20
|
const { networks = KnownNetworks, assets = KnownAssets, fetch = globalThis.fetch, } = args ?? {};
|
|
13
21
|
const paymentHandlers = [];
|
|
@@ -34,9 +42,9 @@ export function createPayer(args) {
|
|
|
34
42
|
}
|
|
35
43
|
const balance = await getBalance();
|
|
36
44
|
// XXX - We need to do a better job of understanding decimals here.
|
|
37
|
-
if (balance.amount < BigInt(req.
|
|
45
|
+
if (balance.amount < BigInt(req.amount)) {
|
|
38
46
|
// eslint-disable-next-line no-console
|
|
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.
|
|
47
|
+
console.log(`Not paying with ${balance.name} on ${req.network} using the ${req.scheme} scheme: balance is ${balance.amount} which is less than ${req.amount}`);
|
|
40
48
|
continue;
|
|
41
49
|
}
|
|
42
50
|
viableOptions.push(e);
|
|
@@ -84,4 +92,10 @@ export function createPayer(args) {
|
|
|
84
92
|
},
|
|
85
93
|
};
|
|
86
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Default payer instance with all networks and assets enabled.
|
|
97
|
+
*
|
|
98
|
+
* Use addLocalWallet to attach wallet credentials before making requests
|
|
99
|
+
* with the fetch method.
|
|
100
|
+
*/
|
|
87
101
|
export const payer = createPayer();
|
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