@postfetch/core 0.5.2 → 0.7.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/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # @postfetch/core
2
2
 
3
- Zero-dependency typed core that turns Instagram, TikTok and YouTube post URLs into media files. Part of [postfetch](https://github.com/chelokot/postfetch).
3
+ Zero-dependency typed core that turns Facebook, Instagram, LinkedIn, Pinterest, Reddit, SoundCloud, TikTok, X and YouTube post URLs into media files. Part of [postfetch](https://github.com/chelokot/postfetch).
4
4
 
5
5
  ```ts
6
- import { postfetch, download, archive, toResponse, PostfetchError } from "@postfetch/core";
6
+ import { postfetch, download, downloadBlob, archive, toResponse, PostfetchError } from "@postfetch/core";
7
7
 
8
8
  const result = await postfetch("https://vt.tiktok.com/ZSxpHvCUM/");
9
9
  for (const item of result.items) {
@@ -11,9 +11,13 @@ for (const item of result.items) {
11
11
  }
12
12
  ```
13
13
 
14
- `postfetch(url, options?)` detects the platform and resolves its media into a typed `PostfetchResult` (URLs plus the headers needed to fetch them). It performs no side effects beyond the lookup — `download`, `archive` and `toResponse` turn the result into bytes or an HTTP `Response`.
14
+ `postfetch(url, options?)` detects the platform and resolves its media into a typed `PostfetchResult` (URLs plus the headers needed to fetch them). It performs no side effects beyond the lookup — `download`, `downloadBlob`, `archive` and `toResponse` materialize the result.
15
15
 
16
- - `PostfetchOptions` — `{ fetch?: typeof fetch; preferredWidth?: number }`. Inject `fetch` to unit-test resolvers offline.
16
+ `downloadBlob(url, headers?, options?)` materializes an already-resolved media URL for
17
+ clients that need an uploadable `Blob`. Pass the resolved item's headers for
18
+ protected CDN URLs: `downloadBlob(item.url, item.headers)`.
19
+
20
+ - `PostfetchOptions` — `{ fetch?: typeof fetch; preferredWidth?: number; tryMaxBytes?: number }`. `tryMaxBytes` is a soft byte cap: when the normal media is larger, a smaller available rendition is returned; if its size cannot be discovered or no smaller rendition is available, the normal result is kept. Inject `fetch` to unit-test resolvers offline.
17
21
  - Every request rotates a consistent browser/app fingerprint, so a fixed user-agent never gets the whole fleet blocked.
18
22
  - No runtime dependencies, no `ffmpeg` / `yt-dlp`, no cookies.
19
23
 
@@ -30,6 +30,26 @@ export type Archive = {
30
30
  * ```
31
31
  */
32
32
  export declare function download(item: MediaItem, options?: DownloadOptions): Promise<Response>;
33
+ /**
34
+ * Download an already-resolved media URL as a Blob.
35
+ *
36
+ * This is useful for consumers that need to upload media themselves instead of
37
+ * passing its URL to a third party. When the resolved {@link MediaItem} carries
38
+ * required CDN headers, pass them as the second argument.
39
+ *
40
+ * @param url A direct media URL returned by a resolver.
41
+ * @param headers Headers required by the resolved media URL.
42
+ * @param options Fetch options.
43
+ * @returns The downloaded media as a Blob.
44
+ *
45
+ * @example Upload a video with FormData
46
+ * ```ts
47
+ * const [media] = (await postfetch(sourceUrl)).items;
48
+ * const blob = await downloadBlob(media.url, media.headers);
49
+ * form.append("video", blob, media.filename);
50
+ * ```
51
+ */
52
+ export declare function downloadBlob(url: string, headers?: HeadersInit, options?: DownloadOptions): Promise<Blob>;
33
53
  /**
34
54
  * Download every item of a result and zip them in-process (store mode).
35
55
  *
@@ -4,8 +4,12 @@ export type BrowserFingerprint = {
4
4
  secChUaPlatform: string;
5
5
  userAgent: string;
6
6
  };
7
+ export type NavigationHeaders = Record<string, string> & {
8
+ "user-agent": string;
9
+ };
7
10
  export declare function browserFingerprint(): BrowserFingerprint;
8
- export declare function navigationHeaders(): Record<string, string>;
11
+ export declare function navigationHeaders(): NavigationHeaders;
9
12
  export declare function browserUserAgent(): string;
10
13
  export declare function firefoxUserAgent(): string;
14
+ export declare function firefoxNavigationHeaders(userAgent?: string): NavigationHeaders;
11
15
  export declare function instagramAppUserAgent(): string;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Turn a public social post URL into its media.
3
3
  *
4
- * {@link postfetch} resolves Instagram, TikTok, YouTube, Facebook and X (Twitter)
4
+ * {@link postfetch} resolves Instagram, LinkedIn, TikTok, YouTube, Facebook and X (Twitter)
5
5
  * URLs to typed {@link MediaItem}s. Zero dependencies, only Web-standard APIs
6
6
  * (`fetch`, `Response`, `URL`, `crypto`) — so it runs on Deno, Node, Bun,
7
7
  * Cloudflare Workers and browsers alike. It only resolves the media; the
8
- * {@link download}, {@link archive} and {@link toResponse} helpers turn a result
9
- * into bytes or a `Response`.
8
+ * {@link download}, {@link downloadBlob}, {@link archive} and {@link toResponse}
9
+ * helpers turn a result into bytes, a `Blob`, or a `Response`.
10
10
  *
11
11
  * @example Resolve a reel and save the video
12
12
  * ```ts
@@ -20,6 +20,6 @@
20
20
  * @module
21
21
  */
22
22
  export { postfetch, detect, type PostfetchOptions } from "./postfetch";
23
- export { download, archive, toResponse, type Archive, type DownloadOptions } from "./download";
23
+ export { download, downloadBlob, archive, toResponse, type Archive, type DownloadOptions, } from "./download";
24
24
  export { PostfetchError } from "./internal";
25
- export type { InstagramExtra, MediaItem, MediaKind, PinterestExtra, Platform, PlatformResult, PostAuthor, PostfetchReason, PostfetchResult, PostMetadata, RedditExtra, SoundcloudExtra, TiktokExtra, TwitterExtra, YoutubeExtra, } from "./internal";
25
+ export type { InstagramExtra, MediaItem, MediaKind, PinterestExtra, Platform, PlatformResult, PostAuthor, PostfetchReason, PostfetchResult, PostMetadata, RedditExtra, SoundcloudExtra, TiktokExtra, TwitterExtra, TwitterQuotedTweet, YoutubeExtra, } from "./internal";