@weftlabs/sdk 0.25.0 → 0.26.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/server.js CHANGED
@@ -193,10 +193,10 @@ async function getFeeInfo(config, cacheConfig) {
193
193
  }
194
194
 
195
195
  // src/facilitator/middleware/express.ts
196
- var import_server2 = require("@x402/core/server");
196
+ var import_server3 = require("@x402/core/server");
197
197
 
198
198
  // package.json
199
- var version = "0.25.0";
199
+ var version = "0.26.0";
200
200
 
201
201
  // src/facilitator/middleware/product.ts
202
202
  var PRODUCT_TYPES = ["api", "agent", "mcp"];
@@ -784,6 +784,7 @@ function resumePaymentResult(resourceServer, resumed, context) {
784
784
  }
785
785
 
786
786
  // src/facilitator/middleware/settlement.ts
787
+ var import_server2 = require("@x402/core/server");
787
788
  var import_http2 = require("@x402/core/http");
788
789
  var CORE_FACILITATOR_UNAVAILABLE = /^Facilitator settle failed \(503\):(?: |$)/;
789
790
  function isFacilitatorUnavailable(errorReason) {
@@ -826,10 +827,21 @@ function serializeResponseBody(response) {
826
827
  }
827
828
  return typeof response.body === "string" ? response.body : String(response.body ?? "");
828
829
  }
830
+ var WeftHTTPResourceServer = class extends import_server2.x402HTTPResourceServer {
831
+ processSettlement(...args) {
832
+ const request = args[3]?.request;
833
+ const method = request?.method ?? request?.adapter.getMethod();
834
+ if (method) {
835
+ const payload = { ...args[0], httpMethod: method.toUpperCase() };
836
+ args[0] = payload;
837
+ }
838
+ return super.processSettlement(...args);
839
+ }
840
+ };
829
841
 
830
842
  // src/facilitator/middleware/express.ts
831
843
  var UNSAFE_FAILURE_HEADERS = /* @__PURE__ */ new Set([
832
- import_server2.SETTLEMENT_OVERRIDES_HEADER.toLowerCase(),
844
+ import_server3.SETTLEMENT_OVERRIDES_HEADER.toLowerCase(),
833
845
  "location",
834
846
  "set-cookie"
835
847
  ]);
@@ -933,9 +945,9 @@ async function sendCoreResponse(res, response) {
933
945
  }
934
946
  function sendFacilitatorUnavailable(res) {
935
947
  res.removeHeader("payment-response");
936
- res.removeHeader(import_server2.SETTLEMENT_OVERRIDES_HEADER);
948
+ res.removeHeader(import_server3.SETTLEMENT_OVERRIDES_HEADER);
937
949
  res.setHeader("retry-after", "1");
938
- res.setHeader("cache-control", (0, import_server2.withPrivateCacheControl)(null));
950
+ res.setHeader("cache-control", (0, import_server3.withPrivateCacheControl)(null));
939
951
  res.status(503).json({ error: "facilitator_unavailable" });
940
952
  }
941
953
  function weftPaymentMiddleware(routes, config) {
@@ -943,14 +955,14 @@ function weftPaymentMiddleware(routes, config) {
943
955
  config?.facilitator,
944
956
  buildFacilitatorAuthHeaders("express", config?.apiKey, config ?? {})
945
957
  );
946
- const resourceServer = new import_server2.x402ResourceServer(facilitatorClient);
958
+ const resourceServer = new import_server3.x402ResourceServer(facilitatorClient);
947
959
  registerDynamicExtensions(resourceServer, routes);
948
960
  if (config?.schemes) {
949
961
  config.schemes.forEach(({ network, server: schemeServer }) => {
950
962
  resourceServer.register(network, schemeServer);
951
963
  });
952
964
  }
953
- const httpServer = new import_server2.x402HTTPResourceServer(
965
+ const httpServer = new WeftHTTPResourceServer(
954
966
  resourceServer,
955
967
  applyProductIdentity(routes, config ?? {})
956
968
  );
@@ -1226,11 +1238,11 @@ function weftPaymentMiddleware(routes, config) {
1226
1238
  const cacheControl = res.getHeaders()["cache-control"];
1227
1239
  res.setHeader(
1228
1240
  "cache-control",
1229
- (0, import_server2.withPrivateCacheControl)(
1241
+ (0, import_server3.withPrivateCacheControl)(
1230
1242
  Array.isArray(cacheControl) ? cacheControl.join(",") : cacheControl === void 0 ? null : String(cacheControl)
1231
1243
  )
1232
1244
  );
1233
- res.removeHeader(import_server2.SETTLEMENT_OVERRIDES_HEADER);
1245
+ res.removeHeader(import_server3.SETTLEMENT_OVERRIDES_HEADER);
1234
1246
  } catch (error) {
1235
1247
  bufferedCalls = [];
1236
1248
  restoreHeaders(res, headersBeforeHandler);
@@ -1251,7 +1263,7 @@ function weftPaymentMiddleware(routes, config) {
1251
1263
  }
1252
1264
 
1253
1265
  // src/facilitator/middleware/hono.ts
1254
- var import_server3 = require("@x402/core/server");
1266
+ var import_server4 = require("@x402/core/server");
1255
1267
  var FACILITATOR_SYNC_RETRY_FLOOR_MS2 = 3e4;
1256
1268
  var HonoAdapter = class {
1257
1269
  constructor(c) {
@@ -1303,13 +1315,13 @@ function toHeaderRecord2(headers) {
1303
1315
  return record;
1304
1316
  }
1305
1317
  function withResponseHeaders(response, additions) {
1306
- if ((!additions || Object.keys(additions).length === 0) && !response.headers.has(import_server3.SETTLEMENT_OVERRIDES_HEADER))
1318
+ if ((!additions || Object.keys(additions).length === 0) && !response.headers.has(import_server4.SETTLEMENT_OVERRIDES_HEADER))
1307
1319
  return response;
1308
1320
  const headers = new Headers(response.headers);
1309
1321
  Object.entries(additions ?? {}).forEach(([key, value]) => {
1310
1322
  headers.set(key, value);
1311
1323
  });
1312
- headers.delete(import_server3.SETTLEMENT_OVERRIDES_HEADER);
1324
+ headers.delete(import_server4.SETTLEMENT_OVERRIDES_HEADER);
1313
1325
  return new Response(response.body, {
1314
1326
  status: response.status,
1315
1327
  statusText: response.statusText,
@@ -1321,10 +1333,10 @@ function withSuccessfulSettlementHeaders(response, additions) {
1321
1333
  Object.entries(additions).forEach(([key, value]) => {
1322
1334
  headers.set(key, value);
1323
1335
  });
1324
- headers.delete(import_server3.SETTLEMENT_OVERRIDES_HEADER);
1336
+ headers.delete(import_server4.SETTLEMENT_OVERRIDES_HEADER);
1325
1337
  headers.set(
1326
1338
  "cache-control",
1327
- (0, import_server3.withPrivateCacheControl)(headers.get("cache-control"))
1339
+ (0, import_server4.withPrivateCacheControl)(headers.get("cache-control"))
1328
1340
  );
1329
1341
  return new Response(response.body, {
1330
1342
  status: response.status,
@@ -1346,7 +1358,7 @@ function failureResponse(body, status, headers) {
1346
1358
  function facilitatorUnavailableResponse() {
1347
1359
  return failureResponse({ error: "facilitator_unavailable" }, 503, {
1348
1360
  "retry-after": "1",
1349
- "cache-control": (0, import_server3.withPrivateCacheControl)(null),
1361
+ "cache-control": (0, import_server4.withPrivateCacheControl)(null),
1350
1362
  "content-type": "application/json; charset=UTF-8"
1351
1363
  });
1352
1364
  }
@@ -1361,14 +1373,14 @@ function weftPaymentMiddlewareHono(routes, config) {
1361
1373
  config?.facilitator,
1362
1374
  buildFacilitatorAuthHeaders("hono", config?.apiKey, config ?? {})
1363
1375
  );
1364
- const resourceServer = new import_server3.x402ResourceServer(facilitatorClient);
1376
+ const resourceServer = new import_server4.x402ResourceServer(facilitatorClient);
1365
1377
  registerDynamicExtensions(resourceServer, routes);
1366
1378
  if (config?.schemes) {
1367
1379
  config.schemes.forEach(({ network, server: schemeServer }) => {
1368
1380
  resourceServer.register(network, schemeServer);
1369
1381
  });
1370
1382
  }
1371
- const httpServer = new import_server3.x402HTTPResourceServer(
1383
+ const httpServer = new WeftHTTPResourceServer(
1372
1384
  resourceServer,
1373
1385
  applyProductIdentity(routes, config ?? {})
1374
1386
  );