@medialane/sdk 0.86.0 → 0.87.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/index.cjs CHANGED
@@ -1320,28 +1320,28 @@ function isSameOrigin(req) {
1320
1320
  }
1321
1321
  }
1322
1322
 
1323
- // src/server/rpc-proxy.ts
1324
- function rpcError(code, message, status = 200, id = null) {
1325
- return Response.json({ jsonrpc: "2.0", error: { code, message }, id }, { status });
1323
+ // src/server/backend-proxy.ts
1324
+ function proxyError(code, message, status) {
1325
+ return Response.json({ jsonrpc: "2.0", error: { code, message }, id: null }, { status });
1326
1326
  }
1327
- function createRpcProxyHandler(config) {
1327
+ function createBackendProxyHandler(config) {
1328
1328
  const doFetch = config.fetchImpl ?? fetch;
1329
- const endpoint = `${config.backendUrl.replace(/\/$/, "")}/v1/rpc`;
1330
- return async function handleRpcProxy(req) {
1329
+ const endpoint = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
1330
+ return async function handleBackendProxy(req) {
1331
1331
  if (!isSameOrigin(req)) {
1332
- return rpcError(-32600, "Cross-origin requests are not allowed", 403);
1332
+ return proxyError(-32600, "Cross-origin requests are not allowed", 403);
1333
1333
  }
1334
1334
  if (!config.checkRateLimit(requestIp(req))) {
1335
- return rpcError(-32005, "Too many requests", 429);
1335
+ return proxyError(-32005, "Too many requests", 429);
1336
1336
  }
1337
1337
  if (!config.apiKey) {
1338
- return rpcError(-32003, "No API key configured \u2014 RPC call not forwarded", 402);
1338
+ return proxyError(-32003, "No API key configured \u2014 request not forwarded", 402);
1339
1339
  }
1340
1340
  let body;
1341
1341
  try {
1342
1342
  body = await req.json();
1343
1343
  } catch {
1344
- return rpcError(-32700, "Parse error");
1344
+ return proxyError(-32700, "Parse error", 400);
1345
1345
  }
1346
1346
  try {
1347
1347
  const upstream = await doFetch(endpoint, {
@@ -1355,11 +1355,16 @@ function createRpcProxyHandler(config) {
1355
1355
  headers: { "Content-Type": "application/json" }
1356
1356
  });
1357
1357
  } catch {
1358
- return rpcError(-32603, "RPC backend unreachable");
1358
+ return proxyError(-32603, "Backend unreachable", 502);
1359
1359
  }
1360
1360
  };
1361
1361
  }
1362
1362
 
1363
+ // src/server/rpc-proxy.ts
1364
+ function createRpcProxyHandler(config) {
1365
+ return createBackendProxyHandler({ ...config, path: "/v1/rpc" });
1366
+ }
1367
+
1363
1368
  // src/metadata.ts
1364
1369
  var RESERVED_TRAITS = /* @__PURE__ */ new Set([
1365
1370
  "Creator",
@@ -1490,6 +1495,7 @@ exports.chainFromSlug = chainFromSlug;
1490
1495
  exports.chainSlug = chainSlug;
1491
1496
  exports.coinHref = coinHref;
1492
1497
  exports.collectionHref = collectionHref;
1498
+ exports.createBackendProxyHandler = createBackendProxyHandler;
1493
1499
  exports.createFailoverFetch = createFailoverFetch;
1494
1500
  exports.createRateLimiter = createRateLimiter;
1495
1501
  exports.createRpcProxyHandler = createRpcProxyHandler;