@faremeter/facilitator 0.15.0 → 0.16.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/routes.d.ts.map +1 -1
- package/dist/src/routes.js +29 -32
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/src/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAKvE,KAAK,2BAA2B,GAAG;IACjC,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE;QACR,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAKvE,KAAK,2BAA2B,GAAG;IACjC,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE;QACR,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAoCF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,2BAA2B,8EAuQxE"}
|
package/dist/src/routes.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { getLogger } from "@
|
|
1
|
+
import { getLogger } from "@faremeter/logs";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import * as x from "@faremeter/types/x402";
|
|
4
4
|
import { isValidationError } from "@faremeter/types";
|
|
5
5
|
import {} from "@faremeter/types/x402";
|
|
6
6
|
import { allSettledWithTimeout } from "./promise.js";
|
|
7
|
-
const logger = getLogger(["faremeter", "facilitator"]);
|
|
7
|
+
const logger = await getLogger(["faremeter", "facilitator"]);
|
|
8
8
|
function summarizeRequirements({ scheme, network, asset, payTo, }) {
|
|
9
9
|
return {
|
|
10
10
|
scheme,
|
|
@@ -13,6 +13,21 @@ function summarizeRequirements({ scheme, network, asset, payTo, }) {
|
|
|
13
13
|
payTo,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
function processException(step, e, cb) {
|
|
17
|
+
let msg = undefined;
|
|
18
|
+
// XXX - We can do a better job of determining if it's a chain
|
|
19
|
+
// error, or some other issue.
|
|
20
|
+
if (e instanceof Error) {
|
|
21
|
+
msg = e.message;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
msg = `unknown error handling ${step}`;
|
|
25
|
+
}
|
|
26
|
+
logger.error(`Caught exception during ${step}`, {
|
|
27
|
+
exception: e,
|
|
28
|
+
});
|
|
29
|
+
return cb(msg);
|
|
30
|
+
}
|
|
16
31
|
export function createFacilitatorRoutes(args) {
|
|
17
32
|
const router = new Hono();
|
|
18
33
|
function sendVerifyError(c, status, msg) {
|
|
@@ -42,7 +57,7 @@ export function createFacilitatorRoutes(args) {
|
|
|
42
57
|
}
|
|
43
58
|
paymentPayload = decodedHeader;
|
|
44
59
|
}
|
|
45
|
-
logger.debug("starting verifyment attempt for request
|
|
60
|
+
logger.debug("starting verifyment attempt for request", x402Req);
|
|
46
61
|
for (const handler of args.handlers) {
|
|
47
62
|
let t;
|
|
48
63
|
if (handler.handleVerify === undefined) {
|
|
@@ -52,28 +67,19 @@ export function createFacilitatorRoutes(args) {
|
|
|
52
67
|
t = await handler.handleVerify(x402Req.paymentRequirements, paymentPayload);
|
|
53
68
|
}
|
|
54
69
|
catch (e) {
|
|
55
|
-
|
|
56
|
-
// XXX - We can do a better job of determining if it's a chain
|
|
57
|
-
// error, or some other issue.
|
|
58
|
-
if (e instanceof Error) {
|
|
59
|
-
msg = e.message;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
msg = "unknown error handling verifyment";
|
|
63
|
-
}
|
|
64
|
-
return sendVerifyError(c, 500, msg);
|
|
70
|
+
return processException("verify", e, (msg) => sendVerifyError(c, 500, msg));
|
|
65
71
|
}
|
|
66
72
|
if (t === null) {
|
|
67
73
|
continue;
|
|
68
74
|
}
|
|
69
|
-
logger.debug("facilitator handler agreed to verify and returned
|
|
70
|
-
logger.info(`${t.isValid ? "succeeded" : "failed"} verifying request
|
|
75
|
+
logger.debug("facilitator handler agreed to verify and returned", t);
|
|
76
|
+
logger.info(`${t.isValid ? "succeeded" : "failed"} verifying request`, {
|
|
71
77
|
...t,
|
|
72
78
|
requirements: summarizeRequirements(x402Req.paymentRequirements),
|
|
73
79
|
});
|
|
74
80
|
return c.json(t);
|
|
75
81
|
}
|
|
76
|
-
logger.warning("attempt to verify was made with no handler found, requirements summary was
|
|
82
|
+
logger.warning("attempt to verify was made with no handler found, requirements summary was", summarizeRequirements(x402Req.paymentRequirements));
|
|
77
83
|
return sendVerifyError(c, 400, "no matching payment handler found");
|
|
78
84
|
});
|
|
79
85
|
function sendSettleError(c, status, msg) {
|
|
@@ -105,36 +111,27 @@ export function createFacilitatorRoutes(args) {
|
|
|
105
111
|
}
|
|
106
112
|
paymentPayload = decodedHeader;
|
|
107
113
|
}
|
|
108
|
-
logger.debug("starting settlement attempt for request
|
|
114
|
+
logger.debug("starting settlement attempt for request", x402Req);
|
|
109
115
|
for (const handler of args.handlers) {
|
|
110
116
|
let t;
|
|
111
117
|
try {
|
|
112
118
|
t = await handler.handleSettle(x402Req.paymentRequirements, paymentPayload);
|
|
113
119
|
}
|
|
114
120
|
catch (e) {
|
|
115
|
-
|
|
116
|
-
// XXX - We can do a better job of determining if it's a chain
|
|
117
|
-
// error, or some other issue.
|
|
118
|
-
if (e instanceof Error) {
|
|
119
|
-
msg = e.message;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
msg = "unknown error handling settlement";
|
|
123
|
-
}
|
|
124
|
-
return sendSettleError(c, 500, msg);
|
|
121
|
+
return processException("settle", e, (msg) => sendSettleError(c, 500, msg));
|
|
125
122
|
}
|
|
126
123
|
if (t === null) {
|
|
127
124
|
continue;
|
|
128
125
|
}
|
|
129
|
-
logger.debug("facilitator handler accepted settlement and returned
|
|
130
|
-
logger.info(`${t.success ? "succeeded" : "failed"} settlement request
|
|
126
|
+
logger.debug("facilitator handler accepted settlement and returned", t);
|
|
127
|
+
logger.info(`${t.success ? "succeeded" : "failed"} settlement request`, {
|
|
131
128
|
requirements: summarizeRequirements(x402Req.paymentRequirements),
|
|
132
129
|
txHash: t.txHash,
|
|
133
130
|
});
|
|
134
131
|
return c.json(t);
|
|
135
132
|
}
|
|
136
133
|
sendSettleError(c, 400, "no matching payment handler found");
|
|
137
|
-
logger.warning("attempt to settle was made with no handler found, requirements summary was
|
|
134
|
+
logger.warning("attempt to settle was made with no handler found, requirements summary was", summarizeRequirements(x402Req.paymentRequirements));
|
|
138
135
|
});
|
|
139
136
|
router.post("/accepts", async (c) => {
|
|
140
137
|
const x402Req = x.x402PaymentRequiredResponse(await c.req.json());
|
|
@@ -158,7 +155,7 @@ export function createFacilitatorRoutes(args) {
|
|
|
158
155
|
logger.error(`failed to retrieve requirements from facilitator handler: ${message}`, x.reason);
|
|
159
156
|
}
|
|
160
157
|
});
|
|
161
|
-
logger.debug(`returning ${accepts.length} accepts
|
|
158
|
+
logger.debug(`returning ${accepts.length} accepts`, {
|
|
162
159
|
accepts: accepts.map(summarizeRequirements),
|
|
163
160
|
});
|
|
164
161
|
c.status(200);
|
|
@@ -185,7 +182,7 @@ export function createFacilitatorRoutes(args) {
|
|
|
185
182
|
logger.error(`failed to retrieve supported from facilitator handler: ${message}`, x.reason);
|
|
186
183
|
}
|
|
187
184
|
});
|
|
188
|
-
logger.debug(`returning ${kinds.length} kinds supported
|
|
185
|
+
logger.debug(`returning ${kinds.length} kinds supported`, {
|
|
189
186
|
kinds,
|
|
190
187
|
});
|
|
191
188
|
c.status(200);
|