@medialane/sdk 0.88.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 +58 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +55 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -296,15 +296,15 @@ var ApiClient = class {
|
|
|
296
296
|
}
|
|
297
297
|
async request(path, init, opts) {
|
|
298
298
|
const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
|
|
299
|
-
const
|
|
299
|
+
const headers2 = { ...this.baseHeaders };
|
|
300
300
|
if (!(init?.body instanceof FormData)) {
|
|
301
|
-
|
|
301
|
+
headers2["Content-Type"] = "application/json";
|
|
302
302
|
}
|
|
303
303
|
const allowed = (status) => opts?.allow404 === true && status === 404 || opts?.allow403 === true && status === 403;
|
|
304
304
|
const res = await withRetry(async () => {
|
|
305
305
|
const response = await fetch(url, {
|
|
306
306
|
...init,
|
|
307
|
-
headers: { ...
|
|
307
|
+
headers: { ...headers2, ...init?.headers }
|
|
308
308
|
});
|
|
309
309
|
if (!response.ok && !allowed(response.status)) {
|
|
310
310
|
const text = await response.text().catch(() => response.statusText);
|
|
@@ -1342,7 +1342,7 @@ function proxyError(code, message, status) {
|
|
|
1342
1342
|
}
|
|
1343
1343
|
function createBackendProxyHandler(config) {
|
|
1344
1344
|
const doFetch = config.fetchImpl ?? fetch;
|
|
1345
|
-
const
|
|
1345
|
+
const endpoint2 = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
|
|
1346
1346
|
return async function handleBackendProxy(req) {
|
|
1347
1347
|
if (!isSameOrigin(req)) {
|
|
1348
1348
|
return proxyError(-32600, "Cross-origin requests are not allowed", 403);
|
|
@@ -1360,7 +1360,7 @@ function createBackendProxyHandler(config) {
|
|
|
1360
1360
|
return proxyError(-32700, "Parse error", 400);
|
|
1361
1361
|
}
|
|
1362
1362
|
try {
|
|
1363
|
-
const upstream = await doFetch(
|
|
1363
|
+
const upstream = await doFetch(endpoint2, {
|
|
1364
1364
|
method: "POST",
|
|
1365
1365
|
headers: { "Content-Type": "application/json", "x-api-key": config.apiKey },
|
|
1366
1366
|
body: JSON.stringify(body)
|
|
@@ -1381,6 +1381,55 @@ function createRpcProxyHandler(config) {
|
|
|
1381
1381
|
return createBackendProxyHandler({ ...config, path: "/v1/rpc" });
|
|
1382
1382
|
}
|
|
1383
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
|
+
|
|
1384
1433
|
// src/metadata.ts
|
|
1385
1434
|
var RESERVED_TRAITS = /* @__PURE__ */ new Set([
|
|
1386
1435
|
"Creator",
|
|
@@ -1530,6 +1579,7 @@ exports.createRateLimiter = createRateLimiter;
|
|
|
1530
1579
|
exports.createRpcProxyHandler = createRpcProxyHandler;
|
|
1531
1580
|
exports.encodeU256 = encodeU256;
|
|
1532
1581
|
exports.formatAmount = formatAmount;
|
|
1582
|
+
exports.getBackendSignedUrl = getBackendSignedUrl;
|
|
1533
1583
|
exports.getCoordinates = getCoordinates;
|
|
1534
1584
|
exports.getDerivativesTerm = getDerivativesTerm;
|
|
1535
1585
|
exports.getListableTokens = getListableTokens;
|
|
@@ -1556,5 +1606,8 @@ exports.resolveSafeImageContentType = resolveSafeImageContentType;
|
|
|
1556
1606
|
exports.shortenAddress = shortenAddress;
|
|
1557
1607
|
exports.stringifyBigInts = stringifyBigInts;
|
|
1558
1608
|
exports.u256ToBigInt = u256ToBigInt;
|
|
1609
|
+
exports.uploadDirectoryToBackend = uploadDirectoryToBackend;
|
|
1610
|
+
exports.uploadFileToBackend = uploadFileToBackend;
|
|
1611
|
+
exports.uploadJsonToBackend = uploadJsonToBackend;
|
|
1559
1612
|
//# sourceMappingURL=index.cjs.map
|
|
1560
1613
|
//# sourceMappingURL=index.cjs.map
|