@medialane/sdk 0.86.0 → 0.88.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
@@ -80,6 +80,22 @@ function resolveFeeConfig(raw) {
80
80
  };
81
81
  }
82
82
 
83
+ // src/fee/app-config.ts
84
+ var DEFAULT_BPS = 100;
85
+ function bps(raw) {
86
+ if (!raw) return DEFAULT_BPS;
87
+ const n = Number(raw);
88
+ return Number.isFinite(n) ? n : DEFAULT_BPS;
89
+ }
90
+ function resolveAppFeeConfig(env = {}) {
91
+ return resolveFeeConfig({
92
+ enabled: env.NEXT_PUBLIC_FEE_ENABLED !== "false",
93
+ fundAddress: env.NEXT_PUBLIC_FEE_FUND_ADDRESS || void 0,
94
+ marketplaceBps: bps(env.NEXT_PUBLIC_FEE_MARKETPLACE_BPS),
95
+ launchpadBps: bps(env.NEXT_PUBLIC_FEE_LAUNCHPAD_BPS)
96
+ });
97
+ }
98
+
83
99
  // src/config.ts
84
100
  var MedialaneConfigSchema = zod.z.object({
85
101
  chain: zod.z.enum(CHAINS).default(DEFAULT_CHAIN),
@@ -1320,28 +1336,28 @@ function isSameOrigin(req) {
1320
1336
  }
1321
1337
  }
1322
1338
 
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 });
1339
+ // src/server/backend-proxy.ts
1340
+ function proxyError(code, message, status) {
1341
+ return Response.json({ jsonrpc: "2.0", error: { code, message }, id: null }, { status });
1326
1342
  }
1327
- function createRpcProxyHandler(config) {
1343
+ function createBackendProxyHandler(config) {
1328
1344
  const doFetch = config.fetchImpl ?? fetch;
1329
- const endpoint = `${config.backendUrl.replace(/\/$/, "")}/v1/rpc`;
1330
- return async function handleRpcProxy(req) {
1345
+ const endpoint = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
1346
+ return async function handleBackendProxy(req) {
1331
1347
  if (!isSameOrigin(req)) {
1332
- return rpcError(-32600, "Cross-origin requests are not allowed", 403);
1348
+ return proxyError(-32600, "Cross-origin requests are not allowed", 403);
1333
1349
  }
1334
1350
  if (!config.checkRateLimit(requestIp(req))) {
1335
- return rpcError(-32005, "Too many requests", 429);
1351
+ return proxyError(-32005, "Too many requests", 429);
1336
1352
  }
1337
1353
  if (!config.apiKey) {
1338
- return rpcError(-32003, "No API key configured \u2014 RPC call not forwarded", 402);
1354
+ return proxyError(-32003, "No API key configured \u2014 request not forwarded", 402);
1339
1355
  }
1340
1356
  let body;
1341
1357
  try {
1342
1358
  body = await req.json();
1343
1359
  } catch {
1344
- return rpcError(-32700, "Parse error");
1360
+ return proxyError(-32700, "Parse error", 400);
1345
1361
  }
1346
1362
  try {
1347
1363
  const upstream = await doFetch(endpoint, {
@@ -1355,11 +1371,16 @@ function createRpcProxyHandler(config) {
1355
1371
  headers: { "Content-Type": "application/json" }
1356
1372
  });
1357
1373
  } catch {
1358
- return rpcError(-32603, "RPC backend unreachable");
1374
+ return proxyError(-32603, "Backend unreachable", 502);
1359
1375
  }
1360
1376
  };
1361
1377
  }
1362
1378
 
1379
+ // src/server/rpc-proxy.ts
1380
+ function createRpcProxyHandler(config) {
1381
+ return createBackendProxyHandler({ ...config, path: "/v1/rpc" });
1382
+ }
1383
+
1363
1384
  // src/metadata.ts
1364
1385
  var RESERVED_TRAITS = /* @__PURE__ */ new Set([
1365
1386
  "Creator",
@@ -1414,6 +1435,19 @@ function buildAssetMetadata(input) {
1414
1435
  };
1415
1436
  }
1416
1437
 
1438
+ // src/remix-policy.ts
1439
+ function getDerivativesTerm(attributes) {
1440
+ const v = (Array.isArray(attributes) ? attributes : []).find(
1441
+ (a) => a.trait_type === "Derivatives"
1442
+ )?.value;
1443
+ return v === "Allowed" || v === "Not Allowed" ? v : null;
1444
+ }
1445
+ function resolveRemixPolicy(input) {
1446
+ const canRemixDirect = input.viewerIsParentOwner || !input.parentNoDerivatives;
1447
+ const showDealOption = input.dealAvailable && !input.viewerIsParentOwner;
1448
+ return { ...input, canRemixDirect, showDealOption };
1449
+ }
1450
+
1417
1451
  // src/utils/ipfs-gateway.ts
1418
1452
  var CID_PATH_PATTERN = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[a-z2-7]{58,})(\/[\w.\-/]*)?$/;
1419
1453
  function isValidIpfsCidPath(cidPath) {
@@ -1490,12 +1524,14 @@ exports.chainFromSlug = chainFromSlug;
1490
1524
  exports.chainSlug = chainSlug;
1491
1525
  exports.coinHref = coinHref;
1492
1526
  exports.collectionHref = collectionHref;
1527
+ exports.createBackendProxyHandler = createBackendProxyHandler;
1493
1528
  exports.createFailoverFetch = createFailoverFetch;
1494
1529
  exports.createRateLimiter = createRateLimiter;
1495
1530
  exports.createRpcProxyHandler = createRpcProxyHandler;
1496
1531
  exports.encodeU256 = encodeU256;
1497
1532
  exports.formatAmount = formatAmount;
1498
1533
  exports.getCoordinates = getCoordinates;
1534
+ exports.getDerivativesTerm = getDerivativesTerm;
1499
1535
  exports.getListableTokens = getListableTokens;
1500
1536
  exports.getService = getService;
1501
1537
  exports.getServicesByCapability = getServicesByCapability;
@@ -1512,8 +1548,10 @@ exports.normalizeAddress = normalizeAddress;
1512
1548
  exports.normalizeHash = normalizeHash;
1513
1549
  exports.parseAmount = parseAmount;
1514
1550
  exports.requestIp = requestIp;
1551
+ exports.resolveAppFeeConfig = resolveAppFeeConfig;
1515
1552
  exports.resolveConfig = resolveConfig;
1516
1553
  exports.resolveFeeConfig = resolveFeeConfig;
1554
+ exports.resolveRemixPolicy = resolveRemixPolicy;
1517
1555
  exports.resolveSafeImageContentType = resolveSafeImageContentType;
1518
1556
  exports.shortenAddress = shortenAddress;
1519
1557
  exports.stringifyBigInts = stringifyBigInts;