@medialane/sdk 0.108.0 → 0.110.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
@@ -393,18 +393,6 @@ declare function hasCapability(id: string | null | undefined, cap: ServiceCapabi
393
393
 
394
394
  declare function normalizeAddress(chain: Chain, address: string): string;
395
395
  declare const canonicalHashBrand: unique symbol;
396
- /**
397
- * A felt hash in exactly one spelling: lowercase, zero-padded to 64 hex digits.
398
- *
399
- * Felts have many equal spellings — `0x0ab`, `0xAB` and `0xab` are the same
400
- * value on chain but three different strings. Anything that uses a hash as an
401
- * identity or uniqueness key must therefore compare canonical form, or the
402
- * same on-chain fact can be presented as several distinct records.
403
- *
404
- * Only `normalizeHash` can produce this type, so a function that demands a
405
- * `CanonicalHash` cannot be handed a raw caller-supplied string. It remains
406
- * assignable to `string`, so existing readers are unaffected.
407
- */
408
396
  type CanonicalHash = string & {
409
397
  readonly [canonicalHashBrand]: true;
410
398
  };
@@ -423,18 +411,6 @@ declare function u256ToBigInt(low: string, high: string): bigint;
423
411
  declare function encodeU256(n: bigint): [string, string];
424
412
 
425
413
  declare const PUBLIC_RPC_FALLBACKS: readonly string[];
426
- /**
427
- * Codes our own proxies emit to *refuse* a call on policy grounds: no API key,
428
- * insufficient credits, rate limited, wrong origin.
429
- *
430
- * These must never be treated as transient. They sit inside the JSON-RPC
431
- * reserved server-error range and carry messages like "Too many requests", so
432
- * every generic transient heuristic below would otherwise match them — and a
433
- * caller with a fallback list would quietly retry the same call against a
434
- * different upstream. That turns a refusal into a redirect: the harder the
435
- * meter says no, the faster traffic routes around it. A policy refusal is an
436
- * answer, not a failure; retrying it elsewhere is always wrong.
437
- */
438
414
  declare const POLICY_REFUSAL_CODES: readonly number[];
439
415
  declare function isPolicyRefusal(input: {
440
416
  body?: unknown;
@@ -452,18 +428,6 @@ interface FailoverFetchOptions {
452
428
  }) => void;
453
429
  }
454
430
  declare function createFailoverFetch(urls: string[], options?: FailoverFetchOptions): typeof fetch;
455
- /**
456
- * Hostnames and env-var names that reach a paid upstream directly.
457
- *
458
- * An app must never name one of these. Everything paid goes through the
459
- * backend, the only place a call can be authenticated, scoped, rate limited
460
- * and billed. An app that knows a node's address has a route around all four —
461
- * and since the address ships in the client bundle, so does every visitor.
462
- *
463
- * The list lives here, not in each app, because it is the part that drifts:
464
- * adding an upstream must protect every consumer at once. Each app keeps its
465
- * own small test that scans its source for these with its own file APIs.
466
- */
467
431
  declare const PAID_UPSTREAM_MARKERS: readonly string[];
468
432
 
469
433
  interface RpcProxyConfig {
@@ -480,12 +444,6 @@ interface BackendProxyConfig {
480
444
  apiKey: string | undefined;
481
445
  checkRateLimit: (ip: string) => boolean;
482
446
  fetchImpl?: typeof fetch;
483
- /**
484
- * Forwards a cookie the app already sets (e.g. its own account-session
485
- * cookie) as a header, so the backend can attribute cost to the calling
486
- * end-user instead of only the app's shared API key. Purely additive —
487
- * omitted when the cookie isn't present, never blocks the request.
488
- */
489
447
  forwardCookie?: {
490
448
  name: string;
491
449
  header: string;
@@ -497,12 +455,6 @@ declare const ALLOWED_IMAGE_CONTENT_TYPES: Set<string>;
497
455
  declare const MAX_IMAGE_REDIRECTS = 5;
498
456
  declare const MAX_IMAGE_PROXY_BYTES: number;
499
457
  declare function isPrivateHost(hostname: string): boolean;
500
- /**
501
- * Validates a URL before it is fetched server-side. `requireHttps` is on by
502
- * default; callers that legitimately accept plain http (a metadata URI already
503
- * committed on chain, say) opt out explicitly rather than the guard being
504
- * lenient for everyone.
505
- */
506
458
  declare function validateUrl(raw: string, options?: {
507
459
  requireHttps?: boolean;
508
460
  }): {
@@ -511,33 +463,10 @@ declare function validateUrl(raw: string, options?: {
511
463
  error: string;
512
464
  status: number;
513
465
  };
514
- /** Convenience for callers that only need a yes/no, mirroring the backend's prior helper. */
515
466
  declare function isPrivateOrInsecureUrl(raw: string, requireHttps?: boolean): boolean;
516
467
 
517
- /**
518
- * Proxies a remote image, which means fetching a URL an untrusted caller chose
519
- * — the classic SSRF shape. Guarded in four places, each of which has to hold:
520
- *
521
- * 1. the URL is https, credential-free and not a private host
522
- * 2. the hostname's *resolved* addresses are re-checked, since a public name
523
- * can resolve to a private address
524
- * 3. redirects are followed manually, re-validating each hop, because a
525
- * permitted host can redirect into the private range
526
- * 4. the response must be an allowed image type and is read under a byte cap
527
- *
528
- * This existed as a byte-identical copy in each app, so a fix to one would not
529
- * have reached the other. DNS resolution is injected rather than imported: it
530
- * is runtime-specific, and this package stays isomorphic.
531
- *
532
- * Note the remaining exposure: between resolving a hostname and fetching it,
533
- * the name could resolve differently (DNS rebinding). Closing that needs the
534
- * fetch pinned to the address already checked, which the platform fetch does
535
- * not expose. The content-type allowlist and byte cap bound what an attacker
536
- * gets if they win that race.
537
- */
538
468
  interface ImageProxyConfig {
539
469
  checkRateLimit: (ip: string) => boolean;
540
- /** Returns every address a hostname resolves to. Injected; see above. */
541
470
  resolveHostname: (hostname: string) => Promise<string[]>;
542
471
  fetchImpl?: typeof fetch;
543
472
  userAgent?: string;
@@ -548,7 +477,6 @@ interface CappedBody {
548
477
  error?: string;
549
478
  status?: number;
550
479
  }
551
- /** Reads a response body, refusing anything past `maxBytes` rather than buffering it. */
552
480
  declare function readBodyWithCap(res: Response, maxBytes: number): Promise<CappedBody>;
553
481
  declare function createImageProxyHandler(config: ImageProxyConfig): (req: Request) => Promise<Response>;
554
482
 
@@ -576,17 +504,6 @@ declare function createRateLimiter(windowMs: number, max: number): (key: string)
576
504
  declare const TRUSTED_APP_IP_HEADER = "x-medialane-client-ip";
577
505
  declare function requestIp(req: Request): string;
578
506
 
579
- /**
580
- * Same-origin guard for server routes. A missing `Origin` header is allowed,
581
- * because same-origin navigations and server-to-server calls do not send one;
582
- * a present `Origin` must match `Host`.
583
- *
584
- * Read that carefully before relying on it: this blocks cross-site *browser*
585
- * abuse, and nothing else. A non-browser client simply omits `Origin` and
586
- * passes. It is not a substitute for authentication, and on a route that
587
- * spends money or credits it must be paired with a rate limit and, where the
588
- * route touches a paid resource, real auth.
589
- */
590
507
  declare function isSameOrigin(req: Request): boolean;
591
508
 
592
509
  declare const IDENTITY_TTL_SECONDS = 86400;
package/dist/index.d.ts CHANGED
@@ -393,18 +393,6 @@ declare function hasCapability(id: string | null | undefined, cap: ServiceCapabi
393
393
 
394
394
  declare function normalizeAddress(chain: Chain, address: string): string;
395
395
  declare const canonicalHashBrand: unique symbol;
396
- /**
397
- * A felt hash in exactly one spelling: lowercase, zero-padded to 64 hex digits.
398
- *
399
- * Felts have many equal spellings — `0x0ab`, `0xAB` and `0xab` are the same
400
- * value on chain but three different strings. Anything that uses a hash as an
401
- * identity or uniqueness key must therefore compare canonical form, or the
402
- * same on-chain fact can be presented as several distinct records.
403
- *
404
- * Only `normalizeHash` can produce this type, so a function that demands a
405
- * `CanonicalHash` cannot be handed a raw caller-supplied string. It remains
406
- * assignable to `string`, so existing readers are unaffected.
407
- */
408
396
  type CanonicalHash = string & {
409
397
  readonly [canonicalHashBrand]: true;
410
398
  };
@@ -423,18 +411,6 @@ declare function u256ToBigInt(low: string, high: string): bigint;
423
411
  declare function encodeU256(n: bigint): [string, string];
424
412
 
425
413
  declare const PUBLIC_RPC_FALLBACKS: readonly string[];
426
- /**
427
- * Codes our own proxies emit to *refuse* a call on policy grounds: no API key,
428
- * insufficient credits, rate limited, wrong origin.
429
- *
430
- * These must never be treated as transient. They sit inside the JSON-RPC
431
- * reserved server-error range and carry messages like "Too many requests", so
432
- * every generic transient heuristic below would otherwise match them — and a
433
- * caller with a fallback list would quietly retry the same call against a
434
- * different upstream. That turns a refusal into a redirect: the harder the
435
- * meter says no, the faster traffic routes around it. A policy refusal is an
436
- * answer, not a failure; retrying it elsewhere is always wrong.
437
- */
438
414
  declare const POLICY_REFUSAL_CODES: readonly number[];
439
415
  declare function isPolicyRefusal(input: {
440
416
  body?: unknown;
@@ -452,18 +428,6 @@ interface FailoverFetchOptions {
452
428
  }) => void;
453
429
  }
454
430
  declare function createFailoverFetch(urls: string[], options?: FailoverFetchOptions): typeof fetch;
455
- /**
456
- * Hostnames and env-var names that reach a paid upstream directly.
457
- *
458
- * An app must never name one of these. Everything paid goes through the
459
- * backend, the only place a call can be authenticated, scoped, rate limited
460
- * and billed. An app that knows a node's address has a route around all four —
461
- * and since the address ships in the client bundle, so does every visitor.
462
- *
463
- * The list lives here, not in each app, because it is the part that drifts:
464
- * adding an upstream must protect every consumer at once. Each app keeps its
465
- * own small test that scans its source for these with its own file APIs.
466
- */
467
431
  declare const PAID_UPSTREAM_MARKERS: readonly string[];
468
432
 
469
433
  interface RpcProxyConfig {
@@ -480,12 +444,6 @@ interface BackendProxyConfig {
480
444
  apiKey: string | undefined;
481
445
  checkRateLimit: (ip: string) => boolean;
482
446
  fetchImpl?: typeof fetch;
483
- /**
484
- * Forwards a cookie the app already sets (e.g. its own account-session
485
- * cookie) as a header, so the backend can attribute cost to the calling
486
- * end-user instead of only the app's shared API key. Purely additive —
487
- * omitted when the cookie isn't present, never blocks the request.
488
- */
489
447
  forwardCookie?: {
490
448
  name: string;
491
449
  header: string;
@@ -497,12 +455,6 @@ declare const ALLOWED_IMAGE_CONTENT_TYPES: Set<string>;
497
455
  declare const MAX_IMAGE_REDIRECTS = 5;
498
456
  declare const MAX_IMAGE_PROXY_BYTES: number;
499
457
  declare function isPrivateHost(hostname: string): boolean;
500
- /**
501
- * Validates a URL before it is fetched server-side. `requireHttps` is on by
502
- * default; callers that legitimately accept plain http (a metadata URI already
503
- * committed on chain, say) opt out explicitly rather than the guard being
504
- * lenient for everyone.
505
- */
506
458
  declare function validateUrl(raw: string, options?: {
507
459
  requireHttps?: boolean;
508
460
  }): {
@@ -511,33 +463,10 @@ declare function validateUrl(raw: string, options?: {
511
463
  error: string;
512
464
  status: number;
513
465
  };
514
- /** Convenience for callers that only need a yes/no, mirroring the backend's prior helper. */
515
466
  declare function isPrivateOrInsecureUrl(raw: string, requireHttps?: boolean): boolean;
516
467
 
517
- /**
518
- * Proxies a remote image, which means fetching a URL an untrusted caller chose
519
- * — the classic SSRF shape. Guarded in four places, each of which has to hold:
520
- *
521
- * 1. the URL is https, credential-free and not a private host
522
- * 2. the hostname's *resolved* addresses are re-checked, since a public name
523
- * can resolve to a private address
524
- * 3. redirects are followed manually, re-validating each hop, because a
525
- * permitted host can redirect into the private range
526
- * 4. the response must be an allowed image type and is read under a byte cap
527
- *
528
- * This existed as a byte-identical copy in each app, so a fix to one would not
529
- * have reached the other. DNS resolution is injected rather than imported: it
530
- * is runtime-specific, and this package stays isomorphic.
531
- *
532
- * Note the remaining exposure: between resolving a hostname and fetching it,
533
- * the name could resolve differently (DNS rebinding). Closing that needs the
534
- * fetch pinned to the address already checked, which the platform fetch does
535
- * not expose. The content-type allowlist and byte cap bound what an attacker
536
- * gets if they win that race.
537
- */
538
468
  interface ImageProxyConfig {
539
469
  checkRateLimit: (ip: string) => boolean;
540
- /** Returns every address a hostname resolves to. Injected; see above. */
541
470
  resolveHostname: (hostname: string) => Promise<string[]>;
542
471
  fetchImpl?: typeof fetch;
543
472
  userAgent?: string;
@@ -548,7 +477,6 @@ interface CappedBody {
548
477
  error?: string;
549
478
  status?: number;
550
479
  }
551
- /** Reads a response body, refusing anything past `maxBytes` rather than buffering it. */
552
480
  declare function readBodyWithCap(res: Response, maxBytes: number): Promise<CappedBody>;
553
481
  declare function createImageProxyHandler(config: ImageProxyConfig): (req: Request) => Promise<Response>;
554
482
 
@@ -576,17 +504,6 @@ declare function createRateLimiter(windowMs: number, max: number): (key: string)
576
504
  declare const TRUSTED_APP_IP_HEADER = "x-medialane-client-ip";
577
505
  declare function requestIp(req: Request): string;
578
506
 
579
- /**
580
- * Same-origin guard for server routes. A missing `Origin` header is allowed,
581
- * because same-origin navigations and server-to-server calls do not send one;
582
- * a present `Origin` must match `Host`.
583
- *
584
- * Read that carefully before relying on it: this blocks cross-site *browser*
585
- * abuse, and nothing else. A non-browser client simply omits `Origin` and
586
- * passes. It is not a substitute for authentication, and on a route that
587
- * spends money or credits it must be paired with a rate limit and, where the
588
- * route touches a paid resource, real auth.
589
- */
590
507
  declare function isSameOrigin(req: Request): boolean;
591
508
 
592
509
  declare const IDENTITY_TTL_SECONDS = 86400;