@atproto-labs/handle-resolver-node 0.1.25 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atproto-labs/handle-resolver-node
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
8
+
9
+ - [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
10
+
11
+ Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
12
+
13
+ - [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c), [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9), [`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c), [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705)]:
18
+ - @atproto/did@0.4.0
19
+ - @atproto-labs/fetch-node@0.3.0
20
+ - @atproto-labs/handle-resolver@0.4.0
21
+
3
22
  ## 0.1.25
4
23
 
5
24
  ### Patch Changes
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AtprotoHandleResolverNode = void 0;
4
- const fetch_node_1 = require("@atproto-labs/fetch-node");
5
- const handle_resolver_1 = require("@atproto-labs/handle-resolver");
6
- const node_resolve_txt_factory_js_1 = require("./node-resolve-txt-factory.js");
7
- class AtprotoHandleResolverNode extends handle_resolver_1.AtprotoHandleResolver {
1
+ import { safeFetchWrap } from '@atproto-labs/fetch-node';
2
+ import { AtprotoHandleResolver, } from '@atproto-labs/handle-resolver';
3
+ import { nodeResolveTxtDefault, nodeResolveTxtFactory, } from './node-resolve-txt-factory.js';
4
+ export class AtprotoHandleResolverNode extends AtprotoHandleResolver {
8
5
  constructor({ fetch = globalThis.fetch, fallbackNameservers, } = {}) {
9
6
  super({
10
- fetch: (0, fetch_node_1.safeFetchWrap)({
7
+ fetch: safeFetchWrap({
11
8
  fetch,
12
9
  timeout: 3000, // 3 seconds
13
10
  ssrfProtection: true,
14
11
  responseMaxSize: 10 * 1048, // DID are max 2048 characters, 10kb for safety
15
12
  }),
16
- resolveTxt: node_resolve_txt_factory_js_1.nodeResolveTxtDefault,
13
+ resolveTxt: nodeResolveTxtDefault,
17
14
  resolveTxtFallback: fallbackNameservers?.length
18
- ? (0, node_resolve_txt_factory_js_1.nodeResolveTxtFactory)(fallbackNameservers)
15
+ ? nodeResolveTxtFactory(fallbackNameservers)
19
16
  : undefined,
20
17
  });
21
18
  }
22
19
  }
23
- exports.AtprotoHandleResolverNode = AtprotoHandleResolverNode;
24
20
  //# sourceMappingURL=atproto-handle-resolver-node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"atproto-handle-resolver-node.js","sourceRoot":"","sources":["../src/atproto-handle-resolver-node.ts"],"names":[],"mappings":";;;AAAA,yDAA+D;AAC/D,mEAGsC;AACtC,+EAGsC;AAoBtC,MAAa,yBACX,SAAQ,uCAAqB;IAG7B,YAAY,EACV,KAAK,GAAG,UAAU,CAAC,KAAK,EACxB,mBAAmB,MACiB,EAAE;QACtC,KAAK,CAAC;YACJ,KAAK,EAAE,IAAA,0BAAa,EAAC;gBACnB,KAAK;gBACL,OAAO,EAAE,IAAI,EAAE,YAAY;gBAC3B,cAAc,EAAE,IAAI;gBACpB,eAAe,EAAE,EAAE,GAAG,IAAI,EAAE,+CAA+C;aAC5E,CAAC;YACF,UAAU,EAAE,mDAAqB;YACjC,kBAAkB,EAAE,mBAAmB,EAAE,MAAM;gBAC7C,CAAC,CAAC,IAAA,mDAAqB,EAAC,mBAAmB,CAAC;gBAC5C,CAAC,CAAC,SAAS;SACd,CAAC,CAAA;IACJ,CAAC;CACF;AArBD,8DAqBC","sourcesContent":["import { Fetch, safeFetchWrap } from '@atproto-labs/fetch-node'\nimport {\n AtprotoHandleResolver,\n HandleResolver,\n} from '@atproto-labs/handle-resolver'\nimport {\n nodeResolveTxtDefault,\n nodeResolveTxtFactory,\n} from './node-resolve-txt-factory.js'\n\nexport type AtprotoHandleResolverNodeOptions = {\n /**\n * List of backup nameservers to use in case the primary ones fail. Will\n * default to no fallback nameservers.\n */\n fallbackNameservers?: string[]\n\n /**\n * Fetch function to use for HTTP requests. Allows customizing the request\n * behavior, e.g. adding headers, setting a timeout, mocking, etc. The\n * provided fetch function will be wrapped with a safeFetchWrap function that\n * adds SSRF protection.\n *\n * @default `globalThis.fetch`\n */\n fetch?: Fetch\n}\n\nexport class AtprotoHandleResolverNode\n extends AtprotoHandleResolver\n implements HandleResolver\n{\n constructor({\n fetch = globalThis.fetch,\n fallbackNameservers,\n }: AtprotoHandleResolverNodeOptions = {}) {\n super({\n fetch: safeFetchWrap({\n fetch,\n timeout: 3000, // 3 seconds\n ssrfProtection: true,\n responseMaxSize: 10 * 1048, // DID are max 2048 characters, 10kb for safety\n }),\n resolveTxt: nodeResolveTxtDefault,\n resolveTxtFallback: fallbackNameservers?.length\n ? nodeResolveTxtFactory(fallbackNameservers)\n : undefined,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"atproto-handle-resolver-node.js","sourceRoot":"","sources":["../src/atproto-handle-resolver-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EACL,qBAAqB,GAEtB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,+BAA+B,CAAA;AAoBtC,MAAM,OAAO,yBACX,SAAQ,qBAAqB;IAG7B,YAAY,EACV,KAAK,GAAG,UAAU,CAAC,KAAK,EACxB,mBAAmB,MACiB,EAAE;QACtC,KAAK,CAAC;YACJ,KAAK,EAAE,aAAa,CAAC;gBACnB,KAAK;gBACL,OAAO,EAAE,IAAI,EAAE,YAAY;gBAC3B,cAAc,EAAE,IAAI;gBACpB,eAAe,EAAE,EAAE,GAAG,IAAI,EAAE,+CAA+C;aAC5E,CAAC;YACF,UAAU,EAAE,qBAAqB;YACjC,kBAAkB,EAAE,mBAAmB,EAAE,MAAM;gBAC7C,CAAC,CAAC,qBAAqB,CAAC,mBAAmB,CAAC;gBAC5C,CAAC,CAAC,SAAS;SACd,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { Fetch, safeFetchWrap } from '@atproto-labs/fetch-node'\nimport {\n AtprotoHandleResolver,\n HandleResolver,\n} from '@atproto-labs/handle-resolver'\nimport {\n nodeResolveTxtDefault,\n nodeResolveTxtFactory,\n} from './node-resolve-txt-factory.js'\n\nexport type AtprotoHandleResolverNodeOptions = {\n /**\n * List of backup nameservers to use in case the primary ones fail. Will\n * default to no fallback nameservers.\n */\n fallbackNameservers?: string[]\n\n /**\n * Fetch function to use for HTTP requests. Allows customizing the request\n * behavior, e.g. adding headers, setting a timeout, mocking, etc. The\n * provided fetch function will be wrapped with a safeFetchWrap function that\n * adds SSRF protection.\n *\n * @default `globalThis.fetch`\n */\n fetch?: Fetch\n}\n\nexport class AtprotoHandleResolverNode\n extends AtprotoHandleResolver\n implements HandleResolver\n{\n constructor({\n fetch = globalThis.fetch,\n fallbackNameservers,\n }: AtprotoHandleResolverNodeOptions = {}) {\n super({\n fetch: safeFetchWrap({\n fetch,\n timeout: 3000, // 3 seconds\n ssrfProtection: true,\n responseMaxSize: 10 * 1048, // DID are max 2048 characters, 10kb for safety\n }),\n resolveTxt: nodeResolveTxtDefault,\n resolveTxtFallback: fallbackNameservers?.length\n ? nodeResolveTxtFactory(fallbackNameservers)\n : undefined,\n })\n }\n}\n"]}
package/dist/index.js CHANGED
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./atproto-handle-resolver-node.js"), exports);
1
+ export * from './atproto-handle-resolver-node.js';
18
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAiD","sourcesContent":["export * from './atproto-handle-resolver-node.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA","sourcesContent":["export * from './atproto-handle-resolver-node.js'\n"]}
@@ -1,12 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nodeResolveTxtDefault = void 0;
4
- exports.nodeResolveTxtFactory = nodeResolveTxtFactory;
5
- const promises_1 = require("node:dns/promises");
6
- const node_net_1 = require("node:net");
7
- const nodeResolveTxtDefault = (hostname) => (0, promises_1.resolveTxt)(hostname).then(groupChunks, handleError);
8
- exports.nodeResolveTxtDefault = nodeResolveTxtDefault;
9
- function nodeResolveTxtFactory(nameservers) {
1
+ import { Resolver, lookup, resolveTxt } from 'node:dns/promises';
2
+ import { isIP } from 'node:net';
3
+ export const nodeResolveTxtDefault = (hostname) => resolveTxt(hostname).then(groupChunks, handleError);
4
+ export function nodeResolveTxtFactory(nameservers) {
10
5
  // Optimization
11
6
  if (!nameservers.length)
12
7
  return async () => null;
@@ -16,9 +11,9 @@ function nodeResolveTxtFactory(nameservers) {
16
11
  if (port !== null && !/^\d+$/.test(port)) {
17
12
  throw new TypeError(`Invalid name server "${nameserver}"`);
18
13
  }
19
- return (0, node_net_1.isIP)(domain) === 4 || isBracedIPv6(domain)
14
+ return isIP(domain) === 4 || isBracedIPv6(domain)
20
15
  ? [nameserver] // No need to lookup
21
- : (0, promises_1.lookup)(domain, { all: true }).then((r) => r.map((a) => appendPort(a.address, port)),
16
+ : lookup(domain, { all: true }).then((r) => r.map((a) => appendPort(a.address, port)),
22
17
  // Let's just ignore failed nameservers resolution
23
18
  (_err) => []);
24
19
  })).then((results) => {
@@ -26,7 +21,7 @@ function nodeResolveTxtFactory(nameservers) {
26
21
  // No resolver if no valid IP
27
22
  if (!backupIps.length)
28
23
  return null;
29
- const resolver = new promises_1.Resolver();
24
+ const resolver = new Resolver();
30
25
  resolver.setServers(backupIps);
31
26
  return resolver;
32
27
  });
@@ -44,7 +39,7 @@ function nodeResolveTxtFactory(nameservers) {
44
39
  function isBracedIPv6(address) {
45
40
  return (address.startsWith('[') &&
46
41
  address.endsWith(']') &&
47
- (0, node_net_1.isIP)(address.slice(1, -1)) === 6);
42
+ isIP(address.slice(1, -1)) === 6);
48
43
  }
49
44
  function groupChunks(results) {
50
45
  return results.map((chunks) => chunks.join(''));
@@ -71,7 +66,7 @@ function handleError(err) {
71
66
  return null;
72
67
  }
73
68
  function appendPort(address, port) {
74
- switch ((0, node_net_1.isIP)(address)) {
69
+ switch (isIP(address)) {
75
70
  case 4:
76
71
  return port ? `${address}:${port}` : address;
77
72
  case 6:
@@ -1 +1 @@
1
- {"version":3,"file":"node-resolve-txt-factory.js","sourceRoot":"","sources":["../src/node-resolve-txt-factory.ts"],"names":[],"mappings":";;;AAOA,sDA0CC;AAjDD,gDAAgE;AAChE,uCAA+B;AAGxB,MAAM,qBAAqB,GAAe,CAAC,QAAQ,EAAE,EAAE,CAC5D,IAAA,qBAAU,EAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;AADxC,QAAA,qBAAqB,yBACmB;AAErD,SAAgB,qBAAqB,CAAC,WAAqB;IACzD,eAAe;IACf,IAAI,CAAC,WAAW,CAAC,MAAM;QAAE,OAAO,KAAK,IAAI,EAAE,CAAC,IAAI,CAAA;IAEhD,mEAAmE;IACnE,MAAM,eAAe,GAA6B,OAAO,CAAC,GAAG,CAC3D,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7B,MAAM,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QAEtD,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,SAAS,CAAC,wBAAwB,UAAU,GAAG,CAAC,CAAA;QAC5D,CAAC;QAED,OAAO,IAAA,eAAI,EAAC,MAAM,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC;YAC/C,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,oBAAoB;YACnC,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AC,KAAK,CAAC,CACjC,CAAA;AACH,CAAC;AAED,SAAS,WAAW,CAAC,OAAmB;IACtC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,WAAW,CAAC,GAAY;IAC/B,oDAAoD;IACpD,IAAI,GAAG,YAAY,SAAS;QAAE,MAAM,GAAG,CAAA;IAEvC,gDAAgD;IAChD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,WAAW;YAAE,OAAO,IAAI,CAAA;QAE5C,sCAAsC;QACtC,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,UAAU;YAAE,MAAM,GAAG,CAAA;QAEzC,yBAAyB;QACzB,4CAA4C;IAC9C,CAAC;IAED,6EAA6E;IAC7E,kEAAkE;IAElE,8EAA8E;IAC9E,8EAA8E;IAE9E,YAAY;IAEZ,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,IAAmB;IACtD,QAAQ,IAAA,eAAI,EAAC,OAAO,CAAC,EAAE,CAAC;QACtB,KAAK,CAAC;YACJ,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;QAC9C,KAAK,CAAC;YACJ,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAA;QACvD;YACE,MAAM,IAAI,SAAS,CAAC,uBAAuB,OAAO,GAAG,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC","sourcesContent":["import { Resolver, lookup, resolveTxt } from 'node:dns/promises'\nimport { isIP } from 'node:net'\nimport { ResolveTxt } from '@atproto-labs/handle-resolver'\n\nexport const nodeResolveTxtDefault: ResolveTxt = (hostname) =>\n resolveTxt(hostname).then(groupChunks, handleError)\n\nexport function nodeResolveTxtFactory(nameservers: string[]): ResolveTxt {\n // Optimization\n if (!nameservers.length) return async () => null\n\n // Build the resolver asynchronously (will be awaited on every use)\n const resolverPromise: Promise<Resolver | null> = Promise.all<string[]>(\n nameservers.map((nameserver) => {\n const [domain, port = null] = nameserver.split(':', 2)\n\n if (port !== null && !/^\\d+$/.test(port)) {\n throw new TypeError(`Invalid name server \"${nameserver}\"`)\n }\n\n return isIP(domain) === 4 || isBracedIPv6(domain)\n ? [nameserver] // No need to lookup\n : lookup(domain, { all: true }).then(\n (r) => r.map((a) => appendPort(a.address, port)),\n // Let's just ignore failed nameservers resolution\n (_err) => [],\n )\n }),\n ).then((results) => {\n const backupIps = results.flat(1)\n // No resolver if no valid IP\n if (!backupIps.length) return null\n\n const resolver = new Resolver()\n resolver.setServers(backupIps)\n return resolver\n })\n\n // Avoid uncaught promise rejection\n void resolverPromise.catch(() => {\n // Should never happen though...\n })\n\n return async (hostname) => {\n const resolver = await resolverPromise\n return resolver\n ? resolver.resolveTxt(hostname).then(groupChunks, handleError)\n : null\n }\n}\n\nfunction isBracedIPv6(address: string): boolean {\n return (\n address.startsWith('[') &&\n address.endsWith(']') &&\n isIP(address.slice(1, -1)) === 6\n )\n}\n\nfunction groupChunks(results: string[][]): string[] {\n return results.map((chunks) => chunks.join(''))\n}\n\nfunction handleError(err: unknown) {\n // Invalid argument type (e.g. hostname is a number)\n if (err instanceof TypeError) throw err\n\n // If the hostname does not resolve, return null\n if (err instanceof Error) {\n if (err['code'] === 'ENOTFOUND') return null\n\n // Hostname is not a valid domain name\n if (err['code'] === 'EBADNAME') throw err\n\n // DNS server unreachable\n // if (err['code'] === 'ETIMEOUT') throw err\n }\n\n // Historically, errors were not thrown here. A \"null\" value indicates to the\n // AtprotoHandleResolver that it should try the fallback resolver.\n\n // @TODO We might want to re-visit this to only apply when an unexpected error\n // occurs (by throwing here). For now, let's keep the same behavior as before.\n\n // throw err\n\n return null\n}\n\nfunction appendPort(address: string, port: string | null): string {\n switch (isIP(address)) {\n case 4:\n return port ? `${address}:${port}` : address\n case 6:\n return port ? `[${address}]:${port}` : `[${address}]`\n default:\n throw new TypeError(`Invalid IP address \"${address}\"`)\n }\n}\n"]}
1
+ {"version":3,"file":"node-resolve-txt-factory.js","sourceRoot":"","sources":["../src/node-resolve-txt-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAG/B,MAAM,CAAC,MAAM,qBAAqB,GAAe,CAAC,QAAQ,EAAE,EAAE,CAC5D,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;AAErD,MAAM,UAAU,qBAAqB,CAAC,WAAqB;IACzD,eAAe;IACf,IAAI,CAAC,WAAW,CAAC,MAAM;QAAE,OAAO,KAAK,IAAI,EAAE,CAAC,IAAI,CAAA;IAEhD,mEAAmE;IACnE,MAAM,eAAe,GAA6B,OAAO,CAAC,GAAG,CAC3D,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7B,MAAM,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QAEtD,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,SAAS,CAAC,wBAAwB,UAAU,GAAG,CAAC,CAAA;QAC5D,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC;YAC/C,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,oBAAoB;YACnC,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE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CAAC,OAAmB;IACtC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,WAAW,CAAC,GAAY;IAC/B,oDAAoD;IACpD,IAAI,GAAG,YAAY,SAAS;QAAE,MAAM,GAAG,CAAA;IAEvC,gDAAgD;IAChD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,WAAW;YAAE,OAAO,IAAI,CAAA;QAE5C,sCAAsC;QACtC,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,UAAU;YAAE,MAAM,GAAG,CAAA;QAEzC,yBAAyB;QACzB,4CAA4C;IAC9C,CAAC;IAED,6EAA6E;IAC7E,kEAAkE;IAElE,8EAA8E;IAC9E,8EAA8E;IAE9E,YAAY;IAEZ,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,IAAmB;IACtD,QAAQ,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACtB,KAAK,CAAC;YACJ,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;QAC9C,KAAK,CAAC;YACJ,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAA;QACvD;YACE,MAAM,IAAI,SAAS,CAAC,uBAAuB,OAAO,GAAG,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC","sourcesContent":["import { Resolver, lookup, resolveTxt } from 'node:dns/promises'\nimport { isIP } from 'node:net'\nimport { ResolveTxt } from '@atproto-labs/handle-resolver'\n\nexport const nodeResolveTxtDefault: ResolveTxt = (hostname) =>\n resolveTxt(hostname).then(groupChunks, handleError)\n\nexport function nodeResolveTxtFactory(nameservers: string[]): ResolveTxt {\n // Optimization\n if (!nameservers.length) return async () => null\n\n // Build the resolver asynchronously (will be awaited on every use)\n const resolverPromise: Promise<Resolver | null> = Promise.all<string[]>(\n nameservers.map((nameserver) => {\n const [domain, port = null] = nameserver.split(':', 2)\n\n if (port !== null && !/^\\d+$/.test(port)) {\n throw new TypeError(`Invalid name server \"${nameserver}\"`)\n }\n\n return isIP(domain) === 4 || isBracedIPv6(domain)\n ? [nameserver] // No need to lookup\n : lookup(domain, { all: true }).then(\n (r) => r.map((a) => appendPort(a.address, port)),\n // Let's just ignore failed nameservers resolution\n (_err) => [],\n )\n }),\n ).then((results) => {\n const backupIps = results.flat(1)\n // No resolver if no valid IP\n if (!backupIps.length) return null\n\n const resolver = new Resolver()\n resolver.setServers(backupIps)\n return resolver\n })\n\n // Avoid uncaught promise rejection\n void resolverPromise.catch(() => {\n // Should never happen though...\n })\n\n return async (hostname) => {\n const resolver = await resolverPromise\n return resolver\n ? resolver.resolveTxt(hostname).then(groupChunks, handleError)\n : null\n }\n}\n\nfunction isBracedIPv6(address: string): boolean {\n return (\n address.startsWith('[') &&\n address.endsWith(']') &&\n isIP(address.slice(1, -1)) === 6\n )\n}\n\nfunction groupChunks(results: string[][]): string[] {\n return results.map((chunks) => chunks.join(''))\n}\n\nfunction handleError(err: unknown) {\n // Invalid argument type (e.g. hostname is a number)\n if (err instanceof TypeError) throw err\n\n // If the hostname does not resolve, return null\n if (err instanceof Error) {\n if (err['code'] === 'ENOTFOUND') return null\n\n // Hostname is not a valid domain name\n if (err['code'] === 'EBADNAME') throw err\n\n // DNS server unreachable\n // if (err['code'] === 'ETIMEOUT') throw err\n }\n\n // Historically, errors were not thrown here. A \"null\" value indicates to the\n // AtprotoHandleResolver that it should try the fallback resolver.\n\n // @TODO We might want to re-visit this to only apply when an unexpected error\n // occurs (by throwing here). For now, let's keep the same behavior as before.\n\n // throw err\n\n return null\n}\n\nfunction appendPort(address: string, port: string | null): string {\n switch (isIP(address)) {\n case 4:\n return port ? `${address}:${port}` : address\n case 6:\n return port ? `[${address}]:${port}` : `[${address}]`\n default:\n throw new TypeError(`Invalid IP address \"${address}\"`)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto-labs/handle-resolver-node",
3
- "version": "0.1.25",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "description": "Node specific ATProto handle to DID resolver",
6
6
  "keywords": [
@@ -16,9 +16,7 @@
16
16
  "url": "https://github.com/bluesky-social/atproto",
17
17
  "directory": "packages/internal/handle-resolver-node"
18
18
  },
19
- "type": "commonjs",
20
- "main": "dist/index.js",
21
- "types": "dist/index.d.ts",
19
+ "type": "module",
22
20
  "exports": {
23
21
  ".": {
24
22
  "types": "./dist/index.d.ts",
@@ -26,15 +24,15 @@
26
24
  }
27
25
  },
28
26
  "engines": {
29
- "node": ">=18.7.0"
27
+ "node": ">=22"
30
28
  },
31
29
  "dependencies": {
32
- "@atproto-labs/fetch-node": "0.2.0",
33
- "@atproto-labs/handle-resolver": "0.3.6",
34
- "@atproto/did": "0.3.0"
30
+ "@atproto-labs/fetch-node": "^0.3.0",
31
+ "@atproto-labs/handle-resolver": "^0.4.0",
32
+ "@atproto/did": "^0.4.0"
35
33
  },
36
34
  "devDependencies": {
37
- "typescript": "^5.6.3"
35
+ "typescript": "^6.0.3"
38
36
  },
39
37
  "scripts": {
40
38
  "build": "tsc --build tsconfig.build.json"
@@ -1 +1 @@
1
- {"root":["./src/atproto-handle-resolver-node.ts","./src/index.ts","./src/node-resolve-txt-factory.ts"],"version":"5.8.2"}
1
+ {"root":["./src/atproto-handle-resolver-node.ts","./src/index.ts","./src/node-resolve-txt-factory.ts"],"version":"6.0.3"}