Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

The package accepts a public post URL and returns a normalized MediaResult. Paths are relative to packages/core. The public entry points are exported from src/index.ts.

Request path

resolve(url, options)
  -> route(url)
  -> platform extractor
  -> http_get/http_post
  -> global fetch
  -> MediaResult

src/resolve.ts selects an extractor through src/router.ts. The router removes a leading www. and matches the hostname. Pinterest also accepts subdomains. An unmatched hostname produces PlatformNotSupportedError.

The extractor parses the platform response into the common types in src/types.ts. src/http.ts supplies default request headers, applies the per-request timeout, and turns failed HTTP responses into NetworkError.

Source map

PathResponsibility
src/index.tsPublic functions, types, and error exports.
src/resolve.tsResolves one post through the router.
src/router.tsMaps supported hostnames to extractors.
src/http.tsGET and POST wrappers around fetch.
src/errors.tsPublic error classes.
src/types.tsPublic result, media, and Instagram listing types.
src/extractors/*.tsPlatform-specific URL parsing, requests, and response mapping.
scripts/eval.tsPrints fixture results for local inspection.
tests/fixtures.tsPost and account inputs used by replay tests and eval.
tests/support/transport.tsReplays or records HTTP responses for tests.
tests/replay/Behavioral tests for extractors, Instagram listing, and recording.

Instagram listing

src/extractors/instagram-posts.ts uses the Instagram extractor’s shared media lookup for detail: true. It validates the username before the first request, returns pages of up to 12 posts, and uses the returned cursor for later pages.

src/extractors/instagram-session.ts holds the signed-in path. It reads the request tokens and the viewer from the signed-in home page, builds the cookie and same-origin headers, and reads a post from the v1 media API. The listing and the post extractor switch to it when the options carry a sessionid cookie.

Build boundary

bunup.config.ts builds src/index.ts into dist/index.js and dist/index.d.ts. The package publishes dist, readme.md, and LICENSE, as declared in package.json.