@pathmx/embed 0.7.0 → 0.7.2

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.
Files changed (3) hide show
  1. package/index.ts +2 -9
  2. package/metadata.ts +8 -0
  3. package/package.json +1 -1
package/index.ts CHANGED
@@ -2,6 +2,7 @@ import { parseDirectiveLabel, type Plugin } from "@pathmx/core"
2
2
  import { decodeHTML } from "entities"
3
3
  import { embedSource, type EmbedSource } from "./source.ts"
4
4
  import {
5
+ hostLookup,
5
6
  resolveWebLinkMetadata,
6
7
  type EmbedFetch,
7
8
  type EmbedLookup,
@@ -25,15 +26,7 @@ type AuthoredEmbed = Readonly<{
25
26
  /** Enhance deliberate @embed links, preserving their authored destination as fallback. */
26
27
  export function EmbedPlugin(options: EmbedPluginOptions = {}): Plugin {
27
28
  const fetcher = options.fetch ?? globalThis.fetch
28
- const lookup: EmbedLookup =
29
- options.lookup ??
30
- (async (hostname) => {
31
- if (typeof Bun === "undefined")
32
- throw new Error("Web metadata lookup needs a server environment.")
33
- return (await Bun.dns.lookup(hostname, { family: 0 })).map(
34
- (result) => result.address,
35
- )
36
- })
29
+ const lookup = options.lookup ?? hostLookup
37
30
  const metadata = new Map<string, Promise<WebLinkMetadata | undefined>>()
38
31
 
39
32
  return {
package/metadata.ts CHANGED
@@ -17,6 +17,14 @@ export type EmbedFetch = (
17
17
  ) => Promise<Response>
18
18
  export type EmbedLookup = (hostname: string) => Promise<readonly string[]>
19
19
 
20
+ /** The host's own resolver: the system resolver on Bun and Node, Cloudflare DNS in Workers. */
21
+ export const hostLookup: EmbedLookup = async (hostname) => {
22
+ const dns = await import("node:dns/promises")
23
+ return (await dns.lookup(hostname, { all: true })).map(
24
+ (result) => result.address,
25
+ )
26
+ }
27
+
20
28
  const MAX_REDIRECTS = 3
21
29
  const MAX_HTML_BYTES = 512 * 1024
22
30
  const TIMEOUT_MS = 5_000
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pathmx/embed",
3
3
  "description": "X posts, YouTube videos, and rich web link cards for PathMX.",
4
- "version": "0.7.0",
4
+ "version": "0.7.2",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "repository": {
7
7
  "type": "git",