@medialane/sdk 0.87.0 → 0.89.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),
@@ -280,15 +296,15 @@ var ApiClient = class {
280
296
  }
281
297
  async request(path, init, opts) {
282
298
  const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
283
- const headers = { ...this.baseHeaders };
299
+ const headers2 = { ...this.baseHeaders };
284
300
  if (!(init?.body instanceof FormData)) {
285
- headers["Content-Type"] = "application/json";
301
+ headers2["Content-Type"] = "application/json";
286
302
  }
287
303
  const allowed = (status) => opts?.allow404 === true && status === 404 || opts?.allow403 === true && status === 403;
288
304
  const res = await withRetry(async () => {
289
305
  const response = await fetch(url, {
290
306
  ...init,
291
- headers: { ...headers, ...init?.headers }
307
+ headers: { ...headers2, ...init?.headers }
292
308
  });
293
309
  if (!response.ok && !allowed(response.status)) {
294
310
  const text = await response.text().catch(() => response.statusText);
@@ -1326,7 +1342,7 @@ function proxyError(code, message, status) {
1326
1342
  }
1327
1343
  function createBackendProxyHandler(config) {
1328
1344
  const doFetch = config.fetchImpl ?? fetch;
1329
- const endpoint = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
1345
+ const endpoint2 = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
1330
1346
  return async function handleBackendProxy(req) {
1331
1347
  if (!isSameOrigin(req)) {
1332
1348
  return proxyError(-32600, "Cross-origin requests are not allowed", 403);
@@ -1344,7 +1360,7 @@ function createBackendProxyHandler(config) {
1344
1360
  return proxyError(-32700, "Parse error", 400);
1345
1361
  }
1346
1362
  try {
1347
- const upstream = await doFetch(endpoint, {
1363
+ const upstream = await doFetch(endpoint2, {
1348
1364
  method: "POST",
1349
1365
  headers: { "Content-Type": "application/json", "x-api-key": config.apiKey },
1350
1366
  body: JSON.stringify(body)
@@ -1365,6 +1381,55 @@ function createRpcProxyHandler(config) {
1365
1381
  return createBackendProxyHandler({ ...config, path: "/v1/rpc" });
1366
1382
  }
1367
1383
 
1384
+ // src/server/backend-metadata.ts
1385
+ function endpoint(config, path) {
1386
+ return `${config.backendUrl.replace(/\/$/, "")}/v1/metadata/${path}`;
1387
+ }
1388
+ function headers(config, extra) {
1389
+ return { "x-api-key": config.apiKey, ...extra };
1390
+ }
1391
+ async function uploadJsonToBackend(config, json) {
1392
+ const res = await (config.fetchImpl ?? fetch)(endpoint(config, "upload"), {
1393
+ method: "POST",
1394
+ headers: headers(config, { "Content-Type": "application/json" }),
1395
+ body: JSON.stringify(json)
1396
+ });
1397
+ const data = await res.json().catch(() => ({}));
1398
+ if (!res.ok || !data.data) throw new Error(data.error ?? "Metadata upload failed");
1399
+ return { cid: data.data.cid, uri: data.data.url };
1400
+ }
1401
+ async function uploadFileToBackend(config, file) {
1402
+ const form = new FormData();
1403
+ form.append("file", file, file.name);
1404
+ const res = await (config.fetchImpl ?? fetch)(endpoint(config, "upload-file"), {
1405
+ method: "POST",
1406
+ headers: headers(config),
1407
+ body: form
1408
+ });
1409
+ const data = await res.json().catch(() => ({}));
1410
+ if (!res.ok || !data.data) throw new Error(data.error ?? "File upload failed");
1411
+ return { cid: data.data.cid, uri: data.data.url };
1412
+ }
1413
+ async function uploadDirectoryToBackend(config, files) {
1414
+ const res = await (config.fetchImpl ?? fetch)(endpoint(config, "upload-directory"), {
1415
+ method: "POST",
1416
+ headers: headers(config, { "Content-Type": "application/json" }),
1417
+ body: JSON.stringify({ files })
1418
+ });
1419
+ const data = await res.json().catch(() => ({}));
1420
+ if (!res.ok || !data.data) throw new Error(data.error ?? "Directory pin failed");
1421
+ return data.data;
1422
+ }
1423
+ async function getBackendSignedUrl(config, kind = "image") {
1424
+ const res = await (config.fetchImpl ?? fetch)(`${endpoint(config, "signed-url")}?kind=${kind}`, {
1425
+ method: "GET",
1426
+ headers: headers(config)
1427
+ });
1428
+ const data = await res.json().catch(() => ({}));
1429
+ if (!res.ok || !data.data) throw new Error(data.error ?? "Failed to create upload URL");
1430
+ return data.data.url;
1431
+ }
1432
+
1368
1433
  // src/metadata.ts
1369
1434
  var RESERVED_TRAITS = /* @__PURE__ */ new Set([
1370
1435
  "Creator",
@@ -1419,6 +1484,19 @@ function buildAssetMetadata(input) {
1419
1484
  };
1420
1485
  }
1421
1486
 
1487
+ // src/remix-policy.ts
1488
+ function getDerivativesTerm(attributes) {
1489
+ const v = (Array.isArray(attributes) ? attributes : []).find(
1490
+ (a) => a.trait_type === "Derivatives"
1491
+ )?.value;
1492
+ return v === "Allowed" || v === "Not Allowed" ? v : null;
1493
+ }
1494
+ function resolveRemixPolicy(input) {
1495
+ const canRemixDirect = input.viewerIsParentOwner || !input.parentNoDerivatives;
1496
+ const showDealOption = input.dealAvailable && !input.viewerIsParentOwner;
1497
+ return { ...input, canRemixDirect, showDealOption };
1498
+ }
1499
+
1422
1500
  // src/utils/ipfs-gateway.ts
1423
1501
  var CID_PATH_PATTERN = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[a-z2-7]{58,})(\/[\w.\-/]*)?$/;
1424
1502
  function isValidIpfsCidPath(cidPath) {
@@ -1501,7 +1579,9 @@ exports.createRateLimiter = createRateLimiter;
1501
1579
  exports.createRpcProxyHandler = createRpcProxyHandler;
1502
1580
  exports.encodeU256 = encodeU256;
1503
1581
  exports.formatAmount = formatAmount;
1582
+ exports.getBackendSignedUrl = getBackendSignedUrl;
1504
1583
  exports.getCoordinates = getCoordinates;
1584
+ exports.getDerivativesTerm = getDerivativesTerm;
1505
1585
  exports.getListableTokens = getListableTokens;
1506
1586
  exports.getService = getService;
1507
1587
  exports.getServicesByCapability = getServicesByCapability;
@@ -1518,11 +1598,16 @@ exports.normalizeAddress = normalizeAddress;
1518
1598
  exports.normalizeHash = normalizeHash;
1519
1599
  exports.parseAmount = parseAmount;
1520
1600
  exports.requestIp = requestIp;
1601
+ exports.resolveAppFeeConfig = resolveAppFeeConfig;
1521
1602
  exports.resolveConfig = resolveConfig;
1522
1603
  exports.resolveFeeConfig = resolveFeeConfig;
1604
+ exports.resolveRemixPolicy = resolveRemixPolicy;
1523
1605
  exports.resolveSafeImageContentType = resolveSafeImageContentType;
1524
1606
  exports.shortenAddress = shortenAddress;
1525
1607
  exports.stringifyBigInts = stringifyBigInts;
1526
1608
  exports.u256ToBigInt = u256ToBigInt;
1609
+ exports.uploadDirectoryToBackend = uploadDirectoryToBackend;
1610
+ exports.uploadFileToBackend = uploadFileToBackend;
1611
+ exports.uploadJsonToBackend = uploadJsonToBackend;
1527
1612
  //# sourceMappingURL=index.cjs.map
1528
1613
  //# sourceMappingURL=index.cjs.map