@medialane/sdk 0.98.0 → 0.99.1

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.d.cts CHANGED
@@ -432,6 +432,16 @@ interface BackendProxyConfig {
432
432
  apiKey: string | undefined;
433
433
  checkRateLimit: (ip: string) => boolean;
434
434
  fetchImpl?: typeof fetch;
435
+ /**
436
+ * Forwards a cookie the app already sets (e.g. its own account-session
437
+ * cookie) as a header, so the backend can attribute cost to the calling
438
+ * end-user instead of only the app's shared API key. Purely additive —
439
+ * omitted when the cookie isn't present, never blocks the request.
440
+ */
441
+ forwardCookie?: {
442
+ name: string;
443
+ header: string;
444
+ };
435
445
  }
436
446
  declare function createBackendProxyHandler(config: BackendProxyConfig): (req: Request) => Promise<Response>;
437
447
 
package/dist/index.d.ts CHANGED
@@ -432,6 +432,16 @@ interface BackendProxyConfig {
432
432
  apiKey: string | undefined;
433
433
  checkRateLimit: (ip: string) => boolean;
434
434
  fetchImpl?: typeof fetch;
435
+ /**
436
+ * Forwards a cookie the app already sets (e.g. its own account-session
437
+ * cookie) as a header, so the backend can attribute cost to the calling
438
+ * end-user instead of only the app's shared API key. Purely additive —
439
+ * omitted when the cookie isn't present, never blocks the request.
440
+ */
441
+ forwardCookie?: {
442
+ name: string;
443
+ header: string;
444
+ };
435
445
  }
436
446
  declare function createBackendProxyHandler(config: BackendProxyConfig): (req: Request) => Promise<Response>;
437
447
 
package/dist/index.js CHANGED
@@ -1362,6 +1362,16 @@ function isSameOrigin(req) {
1362
1362
  function proxyError(code, message, status) {
1363
1363
  return Response.json({ jsonrpc: "2.0", error: { code, message }, id: null }, { status });
1364
1364
  }
1365
+ function readCookie(req, name) {
1366
+ const raw = req.headers.get("cookie");
1367
+ if (!raw) return null;
1368
+ for (const part of raw.split(";")) {
1369
+ const eq = part.indexOf("=");
1370
+ if (eq === -1) continue;
1371
+ if (part.slice(0, eq).trim() === name) return part.slice(eq + 1).trim();
1372
+ }
1373
+ return null;
1374
+ }
1365
1375
  function createBackendProxyHandler(config) {
1366
1376
  const doFetch = config.fetchImpl ?? fetch;
1367
1377
  const endpoint2 = `${config.backendUrl.replace(/\/$/, "")}/${config.path.replace(/^\//, "")}`;
@@ -1381,10 +1391,15 @@ function createBackendProxyHandler(config) {
1381
1391
  } catch {
1382
1392
  return proxyError(-32700, "Parse error", 400);
1383
1393
  }
1394
+ const headers2 = { "Content-Type": "application/json", "x-api-key": config.apiKey };
1395
+ if (config.forwardCookie) {
1396
+ const value = readCookie(req, config.forwardCookie.name);
1397
+ if (value) headers2[config.forwardCookie.header] = value;
1398
+ }
1384
1399
  try {
1385
1400
  const upstream = await doFetch(endpoint2, {
1386
1401
  method: "POST",
1387
- headers: { "Content-Type": "application/json", "x-api-key": config.apiKey },
1402
+ headers: headers2,
1388
1403
  body: JSON.stringify(body)
1389
1404
  });
1390
1405
  const text = await upstream.text();