@faremeter/rides 0.17.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 +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/internal.d.ts +3 -1
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +24 -8
- 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/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;;;;;GAKG;AACH,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/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
3
|
/**
|
|
4
4
|
* Configuration options for creating a payer instance.
|
|
5
5
|
*/
|
|
@@ -29,6 +29,7 @@ export interface CreatePayerArgs {
|
|
|
29
29
|
* @returns A payer object with addLocalWallet and fetch methods
|
|
30
30
|
*/
|
|
31
31
|
export declare function createPayer(args?: CreatePayerArgs): {
|
|
32
|
+
addWalletAdapter: (adapter: WalletAdapter) => void;
|
|
32
33
|
addLocalWallet: (input: unknown) => Promise<void>;
|
|
33
34
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
34
35
|
};
|
|
@@ -39,6 +40,7 @@ export declare function createPayer(args?: CreatePayerArgs): {
|
|
|
39
40
|
* with the fetch method.
|
|
40
41
|
*/
|
|
41
42
|
export declare const payer: {
|
|
43
|
+
addWalletAdapter: (adapter: WalletAdapter) => void;
|
|
42
44
|
addLocalWallet: (input: unknown) => Promise<void>;
|
|
43
45
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
44
46
|
};
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import {} from "@faremeter/types/client";
|
|
2
2
|
import { wrap as wrapFetch, chooseFirstAvailable, } from "@faremeter/fetch";
|
|
3
3
|
import { KnownNetworks, KnownAssets, } from "./types.js";
|
|
4
|
+
import { logger } from "./logger.js";
|
|
4
5
|
import * as solana from "./solana.js";
|
|
5
6
|
import * as evm from "./evm.js";
|
|
6
7
|
function idKey({ network, scheme, asset }) {
|
|
@@ -40,11 +41,17 @@ export function createPayer(args) {
|
|
|
40
41
|
if (getBalance === undefined) {
|
|
41
42
|
continue;
|
|
42
43
|
}
|
|
43
|
-
|
|
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
|
+
}
|
|
44
52
|
// XXX - We need to do a better job of understanding decimals here.
|
|
45
53
|
if (balance.amount < BigInt(req.amount)) {
|
|
46
|
-
|
|
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}`);
|
|
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}`);
|
|
48
55
|
continue;
|
|
49
56
|
}
|
|
50
57
|
viableOptions.push(e);
|
|
@@ -62,12 +69,24 @@ export function createPayer(args) {
|
|
|
62
69
|
});
|
|
63
70
|
};
|
|
64
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
|
+
};
|
|
65
84
|
return {
|
|
85
|
+
addWalletAdapter,
|
|
66
86
|
addLocalWallet: async (input) => {
|
|
67
87
|
if (input === undefined) {
|
|
68
88
|
throw new Error("undefined is not a valid local wallet");
|
|
69
89
|
}
|
|
70
|
-
_fetch = undefined;
|
|
71
90
|
const newWallets = [];
|
|
72
91
|
for (const adapter of adapters) {
|
|
73
92
|
const res = await adapter.addLocalWallet(input);
|
|
@@ -79,11 +98,8 @@ export function createPayer(args) {
|
|
|
79
98
|
if (newWallets.length === 0) {
|
|
80
99
|
throw new Error("couldn't find any way to use provided local wallet information");
|
|
81
100
|
}
|
|
82
|
-
paymentHandlers.push(...newWallets.map((x) => x.paymentHandler));
|
|
83
101
|
for (const wallet of newWallets) {
|
|
84
|
-
|
|
85
|
-
balanceLookup.set(idKey(id), wallet.getBalance);
|
|
86
|
-
}
|
|
102
|
+
addWalletAdapter(wallet);
|
|
87
103
|
}
|
|
88
104
|
},
|
|
89
105
|
fetch: async (input, init) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,kCAA0C,CAAC"}
|