@medialane/sdk 0.85.12 → 0.86.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 +25 -116
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +25 -116
- package/dist/index.js.map +1 -1
- package/dist/{services-B_7IX3dM.d.ts → services-BMVi2U8T.d.ts} +1 -1
- package/dist/{services-BN4c7iT1.d.cts → services-yppVbYf6.d.cts} +1 -1
- package/dist/starknet/index.cjs +3 -2
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +1 -1
- package/dist/starknet/index.d.ts +1 -1
- package/dist/starknet/index.js +3 -2
- package/dist/starknet/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -495,8 +495,9 @@ var ApiClient = class {
|
|
|
495
495
|
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
496
496
|
return this.get(`/v1/orders/counter-offers?${params}`);
|
|
497
497
|
}
|
|
498
|
-
getMetadataSignedUrl() {
|
|
499
|
-
|
|
498
|
+
getMetadataSignedUrl(kind) {
|
|
499
|
+
const params = kind ? `?kind=${kind}` : "";
|
|
500
|
+
return this.get(`/v1/metadata/signed-url${params}`);
|
|
500
501
|
}
|
|
501
502
|
uploadMetadata(metadata) {
|
|
502
503
|
return this.post("/v1/metadata/upload", metadata);
|
|
@@ -1307,48 +1308,7 @@ function requestIp(req) {
|
|
|
1307
1308
|
return req.headers.get("x-forwarded-for")?.split(",")[0].trim() ?? "unknown";
|
|
1308
1309
|
}
|
|
1309
1310
|
|
|
1310
|
-
// src/server/
|
|
1311
|
-
var DEFAULT_STARKNET_RPC_METHODS = [
|
|
1312
|
-
"starknet_call",
|
|
1313
|
-
"starknet_addInvokeTransaction",
|
|
1314
|
-
"starknet_getTransactionReceipt",
|
|
1315
|
-
"starknet_getTransactionStatus",
|
|
1316
|
-
"starknet_getTransactionByHash",
|
|
1317
|
-
"starknet_getTransaction",
|
|
1318
|
-
"starknet_getBlockWithReceipts",
|
|
1319
|
-
"starknet_estimateFee",
|
|
1320
|
-
"starknet_getNonce",
|
|
1321
|
-
"starknet_simulateTransactions",
|
|
1322
|
-
"starknet_specVersion",
|
|
1323
|
-
"starknet_chainId",
|
|
1324
|
-
"starknet_blockNumber",
|
|
1325
|
-
"starknet_blockHashAndNumber",
|
|
1326
|
-
"starknet_getClassAt",
|
|
1327
|
-
"starknet_getClass",
|
|
1328
|
-
"starknet_getClassHashAt",
|
|
1329
|
-
"starknet_getStorageAt",
|
|
1330
|
-
"starknet_getBlockWithTxHashes",
|
|
1331
|
-
"starknet_getBlockWithTxs",
|
|
1332
|
-
"starknet_getEvents"
|
|
1333
|
-
];
|
|
1334
|
-
function isAllowedMethod(body, allowed) {
|
|
1335
|
-
if (Array.isArray(body)) {
|
|
1336
|
-
return body.every((item) => isAllowedMethod(item, allowed));
|
|
1337
|
-
}
|
|
1338
|
-
if (body && typeof body === "object") {
|
|
1339
|
-
const method = body.method;
|
|
1340
|
-
return typeof method === "string" && allowed.has(method);
|
|
1341
|
-
}
|
|
1342
|
-
return false;
|
|
1343
|
-
}
|
|
1344
|
-
function extractMethod(body) {
|
|
1345
|
-
if (Array.isArray(body)) return "batch";
|
|
1346
|
-
if (body && typeof body === "object") {
|
|
1347
|
-
const method = body.method;
|
|
1348
|
-
if (typeof method === "string") return method;
|
|
1349
|
-
}
|
|
1350
|
-
return "unknown";
|
|
1351
|
-
}
|
|
1311
|
+
// src/server/origin.ts
|
|
1352
1312
|
function isSameOrigin(req) {
|
|
1353
1313
|
const origin = req.headers.get("origin");
|
|
1354
1314
|
if (!origin) return true;
|
|
@@ -1359,28 +1319,14 @@ function isSameOrigin(req) {
|
|
|
1359
1319
|
return false;
|
|
1360
1320
|
}
|
|
1361
1321
|
}
|
|
1322
|
+
|
|
1323
|
+
// src/server/rpc-proxy.ts
|
|
1362
1324
|
function rpcError(code, message, status = 200, id = null) {
|
|
1363
1325
|
return Response.json({ jsonrpc: "2.0", error: { code, message }, id }, { status });
|
|
1364
1326
|
}
|
|
1365
|
-
async function billRpcCall(backendUrl, apiKey, method) {
|
|
1366
|
-
if (!apiKey) {
|
|
1367
|
-
console.error("[rpc-proxy] no API key configured \u2014 refusing to bill/forward");
|
|
1368
|
-
return false;
|
|
1369
|
-
}
|
|
1370
|
-
try {
|
|
1371
|
-
const res = await fetch(`${backendUrl.replace(/\/$/, "")}/v1/rpc/meter`, {
|
|
1372
|
-
method: "POST",
|
|
1373
|
-
headers: { "Content-Type": "application/json", "x-api-key": apiKey },
|
|
1374
|
-
body: JSON.stringify({ method })
|
|
1375
|
-
});
|
|
1376
|
-
return res.ok;
|
|
1377
|
-
} catch (err) {
|
|
1378
|
-
console.error("[rpc-proxy] billing call failed", { err: err instanceof Error ? err.message : String(err) });
|
|
1379
|
-
return false;
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
1327
|
function createRpcProxyHandler(config) {
|
|
1383
|
-
const
|
|
1328
|
+
const doFetch = config.fetchImpl ?? fetch;
|
|
1329
|
+
const endpoint = `${config.backendUrl.replace(/\/$/, "")}/v1/rpc`;
|
|
1384
1330
|
return async function handleRpcProxy(req) {
|
|
1385
1331
|
if (!isSameOrigin(req)) {
|
|
1386
1332
|
return rpcError(-32600, "Cross-origin requests are not allowed", 403);
|
|
@@ -1388,66 +1334,29 @@ function createRpcProxyHandler(config) {
|
|
|
1388
1334
|
if (!config.checkRateLimit(requestIp(req))) {
|
|
1389
1335
|
return rpcError(-32005, "Too many requests", 429);
|
|
1390
1336
|
}
|
|
1337
|
+
if (!config.apiKey) {
|
|
1338
|
+
return rpcError(-32003, "No API key configured \u2014 RPC call not forwarded", 402);
|
|
1339
|
+
}
|
|
1391
1340
|
let body;
|
|
1392
1341
|
try {
|
|
1393
1342
|
body = await req.json();
|
|
1394
1343
|
} catch {
|
|
1395
1344
|
return rpcError(-32700, "Parse error");
|
|
1396
1345
|
}
|
|
1397
|
-
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
headers: { "Content-Type": "application/json" },
|
|
1411
|
-
body: JSON.stringify(body)
|
|
1412
|
-
});
|
|
1413
|
-
const text = await response.text();
|
|
1414
|
-
const upstream = rpcUrl.split("/")[2];
|
|
1415
|
-
if (!text) {
|
|
1416
|
-
lastError = `Upstream RPC returned empty body (HTTP ${response.status})`;
|
|
1417
|
-
console.warn("[rpc-proxy] upstream returned empty body", { status: response.status, upstream });
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
try {
|
|
1421
|
-
const data = JSON.parse(text);
|
|
1422
|
-
if (isTransientRpcError({ status: response.status, body: data })) {
|
|
1423
|
-
const errObj = data.error;
|
|
1424
|
-
lastError = `Upstream RPC returned transient JSON-RPC error: ${String(errObj?.message ?? "(no message)")}`;
|
|
1425
|
-
console.warn("[rpc-proxy] upstream returned transient JSON-RPC error", {
|
|
1426
|
-
upstream,
|
|
1427
|
-
code: errObj?.code,
|
|
1428
|
-
message: errObj?.message
|
|
1429
|
-
});
|
|
1430
|
-
continue;
|
|
1431
|
-
}
|
|
1432
|
-
return Response.json(data, { status: 200 });
|
|
1433
|
-
} catch {
|
|
1434
|
-
lastError = `Upstream RPC returned non-JSON (HTTP ${response.status})`;
|
|
1435
|
-
console.warn("[rpc-proxy] upstream returned non-JSON", {
|
|
1436
|
-
status: response.status,
|
|
1437
|
-
upstream,
|
|
1438
|
-
bodyPreview: text.slice(0, 200)
|
|
1439
|
-
});
|
|
1440
|
-
continue;
|
|
1441
|
-
}
|
|
1442
|
-
} catch (err) {
|
|
1443
|
-
lastError = `Upstream RPC unreachable: ${err instanceof Error ? err.message : "unknown error"}`;
|
|
1444
|
-
console.warn("[rpc-proxy] upstream fetch failed", {
|
|
1445
|
-
upstream: rpcUrl.split("/")[2],
|
|
1446
|
-
err: err instanceof Error ? err.message : String(err)
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1346
|
+
try {
|
|
1347
|
+
const upstream = await doFetch(endpoint, {
|
|
1348
|
+
method: "POST",
|
|
1349
|
+
headers: { "Content-Type": "application/json", "x-api-key": config.apiKey },
|
|
1350
|
+
body: JSON.stringify(body)
|
|
1351
|
+
});
|
|
1352
|
+
const text = await upstream.text();
|
|
1353
|
+
return new Response(text, {
|
|
1354
|
+
status: upstream.status,
|
|
1355
|
+
headers: { "Content-Type": "application/json" }
|
|
1356
|
+
});
|
|
1357
|
+
} catch {
|
|
1358
|
+
return rpcError(-32603, "RPC backend unreachable");
|
|
1449
1359
|
}
|
|
1450
|
-
return rpcError(-32603, lastError);
|
|
1451
1360
|
};
|
|
1452
1361
|
}
|
|
1453
1362
|
|
|
@@ -1535,7 +1444,6 @@ exports.ApiClient = ApiClient;
|
|
|
1535
1444
|
exports.CHAINS = CHAINS;
|
|
1536
1445
|
exports.DEFAULT_CHAIN = DEFAULT_CHAIN;
|
|
1537
1446
|
exports.DEFAULT_CURRENCY = DEFAULT_CURRENCY;
|
|
1538
|
-
exports.DEFAULT_STARKNET_RPC_METHODS = DEFAULT_STARKNET_RPC_METHODS;
|
|
1539
1447
|
exports.FeeConfigSchema = FeeConfigSchema;
|
|
1540
1448
|
exports.IPFS_SAFE_CONTENT_TYPE_PREFIXES = IPFS_SAFE_CONTENT_TYPE_PREFIXES;
|
|
1541
1449
|
exports.MAX_IPFS_GATEWAY_RESPONSE_BYTES = MAX_IPFS_GATEWAY_RESPONSE_BYTES;
|
|
@@ -1595,6 +1503,7 @@ exports.getStarknetCoordinates = getStarknetCoordinates;
|
|
|
1595
1503
|
exports.getTokenByAddress = getTokenByAddress;
|
|
1596
1504
|
exports.getTokenBySymbol = getTokenBySymbol;
|
|
1597
1505
|
exports.hasCapability = hasCapability;
|
|
1506
|
+
exports.isSameOrigin = isSameOrigin;
|
|
1598
1507
|
exports.isServiceId = isServiceId;
|
|
1599
1508
|
exports.isTransientRpcError = isTransientRpcError;
|
|
1600
1509
|
exports.isValidIpfsCidPath = isValidIpfsCidPath;
|