@medialane/sdk 0.97.0 → 0.99.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 +16 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1364,6 +1364,16 @@ function isSameOrigin(req) {
|
|
|
1364
1364
|
function proxyError(code, message, status) {
|
|
1365
1365
|
return Response.json({ jsonrpc: "2.0", error: { code, message }, id: null }, { status });
|
|
1366
1366
|
}
|
|
1367
|
+
function readCookie(req, name) {
|
|
1368
|
+
const raw = req.headers.get("cookie");
|
|
1369
|
+
if (!raw) return null;
|
|
1370
|
+
for (const part of raw.split(";")) {
|
|
1371
|
+
const eq = part.indexOf("=");
|
|
1372
|
+
if (eq === -1) continue;
|
|
1373
|
+
if (part.slice(0, eq).trim() === name) return part.slice(eq + 1).trim();
|
|
1374
|
+
}
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1367
1377
|
function createBackendProxyHandler(config) {
|
|
1368
1378
|
const doFetch = config.fetchImpl ?? fetch;
|
|
1369
1379
|
const endpoint2 = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
|
|
@@ -1383,10 +1393,15 @@ function createBackendProxyHandler(config) {
|
|
|
1383
1393
|
} catch {
|
|
1384
1394
|
return proxyError(-32700, "Parse error", 400);
|
|
1385
1395
|
}
|
|
1396
|
+
const headers2 = { "Content-Type": "application/json", "x-api-key": config.apiKey };
|
|
1397
|
+
if (config.forwardCookie) {
|
|
1398
|
+
const value = readCookie(req, config.forwardCookie.name);
|
|
1399
|
+
if (value) headers2[config.forwardCookie.header] = value;
|
|
1400
|
+
}
|
|
1386
1401
|
try {
|
|
1387
1402
|
const upstream = await doFetch(endpoint2, {
|
|
1388
1403
|
method: "POST",
|
|
1389
|
-
headers:
|
|
1404
|
+
headers: headers2,
|
|
1390
1405
|
body: JSON.stringify(body)
|
|
1391
1406
|
});
|
|
1392
1407
|
const text = await upstream.text();
|