@medialane/sdk 0.131.0 → 0.132.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 +0 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -11
- package/dist/index.d.ts +1 -11
- package/dist/index.js +1 -66
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1506,41 +1506,6 @@ function createFailoverFetch(urls, options = {}) {
|
|
|
1506
1506
|
return failover;
|
|
1507
1507
|
}
|
|
1508
1508
|
|
|
1509
|
-
// src/server/rate-limit.ts
|
|
1510
|
-
function createRateLimiter(windowMs, max) {
|
|
1511
|
-
const counts = /* @__PURE__ */ new Map();
|
|
1512
|
-
let nextSweepAt = Date.now() + windowMs;
|
|
1513
|
-
return function checkRateLimit(key) {
|
|
1514
|
-
const now = Date.now();
|
|
1515
|
-
if (now >= nextSweepAt) {
|
|
1516
|
-
for (const [k, entry2] of counts) {
|
|
1517
|
-
if (now >= entry2.resetAt) counts.delete(k);
|
|
1518
|
-
}
|
|
1519
|
-
nextSweepAt = now + windowMs;
|
|
1520
|
-
}
|
|
1521
|
-
const entry = counts.get(key);
|
|
1522
|
-
if (!entry || now >= entry.resetAt) {
|
|
1523
|
-
counts.set(key, { count: 1, resetAt: now + windowMs });
|
|
1524
|
-
return true;
|
|
1525
|
-
}
|
|
1526
|
-
if (entry.count >= max) return false;
|
|
1527
|
-
entry.count += 1;
|
|
1528
|
-
return true;
|
|
1529
|
-
};
|
|
1530
|
-
}
|
|
1531
|
-
var TRUSTED_APP_IP_HEADER = "x-medialane-client-ip";
|
|
1532
|
-
function requestIp(req) {
|
|
1533
|
-
const fromEdge = req.headers.get("x-vercel-forwarded-for")?.split(",")[0]?.trim();
|
|
1534
|
-
if (fromEdge) return fromEdge;
|
|
1535
|
-
const forwarded = req.headers.get("x-forwarded-for");
|
|
1536
|
-
if (forwarded) {
|
|
1537
|
-
const hops = forwarded.split(",").map((hop) => hop.trim()).filter(Boolean);
|
|
1538
|
-
const nearest = hops[hops.length - 1];
|
|
1539
|
-
if (nearest) return nearest;
|
|
1540
|
-
}
|
|
1541
|
-
return "unknown";
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
1509
|
// src/server/origin.ts
|
|
1545
1510
|
function isSameOrigin(req) {
|
|
1546
1511
|
const origin = req.headers.get("origin");
|
|
@@ -1574,9 +1539,6 @@ function createBackendProxyHandler(config) {
|
|
|
1574
1539
|
if (!isSameOrigin(req)) {
|
|
1575
1540
|
return proxyError(-32600, "Cross-origin requests are not allowed", 403);
|
|
1576
1541
|
}
|
|
1577
|
-
if (!config.checkRateLimit(requestIp(req))) {
|
|
1578
|
-
return proxyError(-32005, "Too many requests", 429);
|
|
1579
|
-
}
|
|
1580
1542
|
if (!config.apiKey) {
|
|
1581
1543
|
return proxyError(-32003, "No API key configured \u2014 request not forwarded", 402);
|
|
1582
1544
|
}
|
|
@@ -1834,9 +1796,6 @@ function createImageProxyHandler(config) {
|
|
|
1834
1796
|
return res;
|
|
1835
1797
|
}
|
|
1836
1798
|
return async function handleImageProxy(req) {
|
|
1837
|
-
if (!config.checkRateLimit(requestIp(req))) {
|
|
1838
|
-
return jsonError("Too many requests", 429);
|
|
1839
|
-
}
|
|
1840
1799
|
const raw = new URL(req.url).searchParams.get("url");
|
|
1841
1800
|
if (!raw) return jsonError("Missing url", 400);
|
|
1842
1801
|
const validated = validateUrl(raw);
|
|
@@ -1918,30 +1877,6 @@ async function getBackendSignedUrl(config, kind = "image") {
|
|
|
1918
1877
|
if (!res.ok || !data.data) throw new Error(data.error ?? "Failed to create upload URL");
|
|
1919
1878
|
return data.data.url;
|
|
1920
1879
|
}
|
|
1921
|
-
|
|
1922
|
-
// src/server/trusted-client-ip.ts
|
|
1923
|
-
var SPOOFABLE_FORWARDING_HEADERS = [
|
|
1924
|
-
"x-forwarded-for",
|
|
1925
|
-
"x-real-ip",
|
|
1926
|
-
"x-client-ip",
|
|
1927
|
-
"true-client-ip",
|
|
1928
|
-
"cf-connecting-ip",
|
|
1929
|
-
TRUSTED_APP_IP_HEADER
|
|
1930
|
-
];
|
|
1931
|
-
function isSpoofableForwardingHeader(name) {
|
|
1932
|
-
return SPOOFABLE_FORWARDING_HEADERS.includes(name.toLowerCase());
|
|
1933
|
-
}
|
|
1934
|
-
function trustedClientIp(req) {
|
|
1935
|
-
const vercel = req.headers.get("x-vercel-forwarded-for")?.split(",")[0]?.trim();
|
|
1936
|
-
if (vercel) return vercel;
|
|
1937
|
-
const forwarded = req.headers.get("x-forwarded-for");
|
|
1938
|
-
if (forwarded) {
|
|
1939
|
-
const hops = forwarded.split(",").map((hop) => hop.trim()).filter(Boolean);
|
|
1940
|
-
const nearest = hops[hops.length - 1];
|
|
1941
|
-
if (nearest) return nearest;
|
|
1942
|
-
}
|
|
1943
|
-
return "unknown";
|
|
1944
|
-
}
|
|
1945
1880
|
var IDENTITY_PREFIX = "siws_";
|
|
1946
1881
|
var ACCOUNT_SESSION_PREFIX = "account_session_";
|
|
1947
1882
|
var IDENTITY_DOMAIN = "siws-identity-v1";
|
|
@@ -2172,7 +2107,6 @@ exports.STARKNET_POP_COLLECTION_CLASS_HASH = STARKNET_POP_COLLECTION_CLASS_HASH;
|
|
|
2172
2107
|
exports.STARKNET_POP_FACTORY_CONTRACT = STARKNET_POP_FACTORY_CONTRACT;
|
|
2173
2108
|
exports.SUPPORTED_TOKENS = SUPPORTED_TOKENS;
|
|
2174
2109
|
exports.SUPPORTED_URL_CHAINS = SUPPORTED_URL_CHAINS;
|
|
2175
|
-
exports.TRUSTED_APP_IP_HEADER = TRUSTED_APP_IP_HEADER;
|
|
2176
2110
|
exports.UserFacingError = UserFacingError;
|
|
2177
2111
|
exports.assetHref = assetHref;
|
|
2178
2112
|
exports.buildAssetMetadata = buildAssetMetadata;
|
|
@@ -2183,7 +2117,6 @@ exports.collectionHref = collectionHref;
|
|
|
2183
2117
|
exports.createBackendProxyHandler = createBackendProxyHandler;
|
|
2184
2118
|
exports.createFailoverFetch = createFailoverFetch;
|
|
2185
2119
|
exports.createImageProxyHandler = createImageProxyHandler;
|
|
2186
|
-
exports.createRateLimiter = createRateLimiter;
|
|
2187
2120
|
exports.createRpcProxyHandler = createRpcProxyHandler;
|
|
2188
2121
|
exports.encodeU256 = encodeU256;
|
|
2189
2122
|
exports.formatAmount = formatAmount;
|
|
@@ -2202,7 +2135,6 @@ exports.isPrivateHost = isPrivateHost;
|
|
|
2202
2135
|
exports.isPrivateOrInsecureUrl = isPrivateOrInsecureUrl;
|
|
2203
2136
|
exports.isSameOrigin = isSameOrigin;
|
|
2204
2137
|
exports.isServiceId = isServiceId;
|
|
2205
|
-
exports.isSpoofableForwardingHeader = isSpoofableForwardingHeader;
|
|
2206
2138
|
exports.isTransientRpcError = isTransientRpcError;
|
|
2207
2139
|
exports.isValidIpfsCidPath = isValidIpfsCidPath;
|
|
2208
2140
|
exports.issueAccountSessionToken = issueAccountSessionToken;
|
|
@@ -2212,7 +2144,6 @@ exports.normalizeAddress = normalizeAddress;
|
|
|
2212
2144
|
exports.normalizeHash = normalizeHash;
|
|
2213
2145
|
exports.parseAmount = parseAmount;
|
|
2214
2146
|
exports.readBodyWithCap = readBodyWithCap;
|
|
2215
|
-
exports.requestIp = requestIp;
|
|
2216
2147
|
exports.resolveAppFeeConfig = resolveAppFeeConfig;
|
|
2217
2148
|
exports.resolveConfig = resolveConfig;
|
|
2218
2149
|
exports.resolveFeeConfig = resolveFeeConfig;
|
|
@@ -2220,7 +2151,6 @@ exports.resolveRemixPolicy = resolveRemixPolicy;
|
|
|
2220
2151
|
exports.resolveSafeImageContentType = resolveSafeImageContentType;
|
|
2221
2152
|
exports.shortenAddress = shortenAddress;
|
|
2222
2153
|
exports.stringifyBigInts = stringifyBigInts;
|
|
2223
|
-
exports.trustedClientIp = trustedClientIp;
|
|
2224
2154
|
exports.u256ToBigInt = u256ToBigInt;
|
|
2225
2155
|
exports.uploadDirectoryToBackend = uploadDirectoryToBackend;
|
|
2226
2156
|
exports.uploadFileToBackend = uploadFileToBackend;
|