@medialane/sdk 0.187.0 → 0.189.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.d.cts CHANGED
@@ -718,6 +718,7 @@ interface ImageProxyConfig {
718
718
  resolveHostname: (hostname: string) => Promise<string[]>;
719
719
  fetchImpl?: typeof fetch;
720
720
  userAgent?: string;
721
+ backend?: Pick<AppGatewayConfig, "appId" | "backendUrl" | "apiKey" | "appSecret">;
721
722
  }
722
723
  interface CappedBody {
723
724
  ok: boolean;
package/dist/index.d.ts CHANGED
@@ -718,6 +718,7 @@ interface ImageProxyConfig {
718
718
  resolveHostname: (hostname: string) => Promise<string[]>;
719
719
  fetchImpl?: typeof fetch;
720
720
  userAgent?: string;
721
+ backend?: Pick<AppGatewayConfig, "appId" | "backendUrl" | "apiKey" | "appSecret">;
721
722
  }
722
723
  interface CappedBody {
723
724
  ok: boolean;
package/dist/index.js CHANGED
@@ -451,6 +451,15 @@ async function readBodyWithCap(res, maxBytes) {
451
451
  function createImageProxyHandler(config) {
452
452
  const doFetch = config.fetchImpl ?? fetch;
453
453
  const userAgent = config.userAgent ?? DEFAULT_USER_AGENT;
454
+ const backendOrigin = config.backend ? new URL(config.backend.backendUrl).origin : null;
455
+ function headersFor(url) {
456
+ const headers2 = { "User-Agent": userAgent };
457
+ if (!config.backend || url.origin !== backendOrigin) return headers2;
458
+ if (config.backend.apiKey) headers2["x-api-key"] = config.backend.apiKey;
459
+ headers2["x-app-id"] = config.backend.appId;
460
+ if (config.backend.appSecret) headers2["x-app-secret"] = config.backend.appSecret;
461
+ return headers2;
462
+ }
454
463
  async function resolvesToPrivateHost(hostname) {
455
464
  try {
456
465
  const addresses = await config.resolveHostname(hostname);
@@ -467,7 +476,7 @@ function createImageProxyHandler(config) {
467
476
  }
468
477
  const res = await doFetch(url.toString(), {
469
478
  redirect: "manual",
470
- headers: { "User-Agent": userAgent }
479
+ headers: headersFor(url)
471
480
  });
472
481
  if (res.status >= 300 && res.status < 400) {
473
482
  const location = res.headers.get("location");
@@ -619,7 +628,8 @@ var PUBLIC_ROUTES = {
619
628
  `sponsorship/proposals/${SEG}`,
620
629
  "sponsorship/licenses",
621
630
  `sponsorship/licenses/${SEG}`,
622
- "auth/email/exists"
631
+ "auth/email/exists",
632
+ `media/${SEG}/${SEG}/${SEG}/image`
623
633
  ].map((p) => new RegExp(`^${p}$`)),
624
634
  POST: [
625
635
  "auth/email/(request-code|verify-code|register-account|confirm)",