@postfetch/core 0.2.3 → 0.3.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.
@@ -1,12 +1,51 @@
1
1
  import { type MediaItem, type PostfetchResult } from "./internal";
2
+ /** Options for {@link download}, {@link archive} and {@link toResponse}. */
2
3
  export type DownloadOptions = {
4
+ /** Custom `fetch` implementation. Defaults to the global `fetch`. */
3
5
  fetch?: typeof fetch;
4
6
  };
7
+ /** A zip archive produced by {@link archive}. */
5
8
  export type Archive = {
9
+ /** The zip bytes (store mode, built in-process). */
6
10
  bytes: Uint8Array;
11
+ /** Suggested download filename. */
7
12
  filename: string;
13
+ /** Always `"application/zip"`. */
8
14
  mime: "application/zip";
9
15
  };
16
+ /**
17
+ * Fetch a single media item, ready to stream or buffer. A plain item streams
18
+ * straight from its CDN; a muxed item (one with {@link MediaItem.audio}) is
19
+ * downloaded as two streams and merged in-process, so its body is buffered.
20
+ *
21
+ * @param item A {@link MediaItem} from a {@link PostfetchResult}.
22
+ * @param options See {@link DownloadOptions}.
23
+ * @returns The upstream `Response`, or a buffered `Response` of the merged file.
24
+ * @throws {PostfetchError} If the CDN responds with a non-OK status.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const result = await postfetch(url);
29
+ * await Bun.write(result.items[0].filename, await download(result.items[0]));
30
+ * ```
31
+ */
10
32
  export declare function download(item: MediaItem, options?: DownloadOptions): Promise<Response>;
33
+ /**
34
+ * Download every item of a result and zip them in-process (store mode).
35
+ *
36
+ * @param result A {@link PostfetchResult}.
37
+ * @param options See {@link DownloadOptions}.
38
+ * @returns The zip bytes and a suggested filename.
39
+ */
11
40
  export declare function archive(result: PostfetchResult, options?: DownloadOptions): Promise<Archive>;
41
+ /**
42
+ * Turn a result into a ready-to-serve `Response`: a single item is streamed as
43
+ * its file (or, when muxed, merged and buffered), multiple items become a zip.
44
+ * Sets `content-disposition` and the `x-media-*` headers. This is what the
45
+ * showcase server and templates return.
46
+ *
47
+ * @param result A {@link PostfetchResult}.
48
+ * @param options See {@link DownloadOptions}.
49
+ * @returns A `Response` a server or edge function can return directly.
50
+ */
12
51
  export declare function toResponse(result: PostfetchResult, options?: DownloadOptions): Promise<Response>;
package/dist/hls.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { Net } from "./internal";
2
+ export type HlsVariant = {
3
+ width: number;
4
+ height: number;
5
+ bandwidth: number;
6
+ url: string;
7
+ audioGroup: string | null;
8
+ };
9
+ export type HlsMaster = {
10
+ variants: HlsVariant[];
11
+ audio: Record<string, string>;
12
+ };
13
+ export declare function isMasterPlaylist(text: string): boolean;
14
+ export declare function parseMaster(text: string, baseUrl: string): HlsMaster;
15
+ export declare function assembleHls(net: Net, playlistUrl: string, headers: HeadersInit): Promise<Uint8Array>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,24 @@
1
+ /**
2
+ * Turn a public social post URL into its media.
3
+ *
4
+ * {@link postfetch} resolves Instagram, TikTok, YouTube, Facebook and X (Twitter)
5
+ * URLs to typed {@link MediaItem}s. Zero dependencies, only Web-standard APIs
6
+ * (`fetch`, `Response`, `URL`, `crypto`) — so it runs on Deno, Node, Bun,
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`.
10
+ *
11
+ * @example Resolve a reel and save the video
12
+ * ```ts
13
+ * import { postfetch, download } from "@postfetch/core";
14
+ *
15
+ * const result = await postfetch("https://www.instagram.com/reel/DZ0ixNxtvYq/");
16
+ * const [item] = result.items; // { kind: "video", url, headers, filename, ... }
17
+ * const response = await download(item);
18
+ * ```
19
+ *
20
+ * @module
21
+ */
1
22
  export { postfetch, detect, type PostfetchOptions } from "./postfetch";
2
23
  export { download, archive, toResponse, type Archive, type DownloadOptions } from "./download";
3
24
  export { PostfetchError } from "./internal";