@fedify/fedify 1.2.0-dev.464 → 1.2.0-dev.466

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,6 @@
1
1
  import { getLogger } from "@logtape/logtape";
2
2
  import { parse } from "../deps/jsr.io/@std/semver/1.0.3/mod.js";
3
3
  const logger = getLogger(["fedify", "nodeinfo", "client"]);
4
- /**
5
- * Fetches a NodeInfo document from the given URL.
6
- * @param url The base URL of the server. If `options.direct` is turned off
7
- * (default), the NodeInfo document will be fetched from
8
- * the `.well-known` location of this URL (hence the only origin
9
- * of the URL is used). If `options.direct` is turned on,
10
- * the NodeInfo document will be fetched from the given URL.
11
- * @param options Options for fetching the NodeInfo document.
12
- * @returns The NodeInfo document if it could be fetched successfully.
13
- * Otherwise, `null` is returned.
14
- * @since 1.2.0
15
- */
16
4
  export async function getNodeInfo(url, options = {}) {
17
5
  try {
18
6
  let nodeInfoUrl = url;
@@ -25,7 +13,7 @@ export async function getNodeInfo(url, options = {}) {
25
13
  status: wellKnownResponse.status,
26
14
  statusText: wellKnownResponse.statusText,
27
15
  });
28
- return null;
16
+ return undefined;
29
17
  }
30
18
  const wellKnownRd = await wellKnownResponse.json();
31
19
  const link = wellKnownRd?.links?.find((link) => link != null &&
@@ -36,7 +24,7 @@ export async function getNodeInfo(url, options = {}) {
36
24
  link.href != null);
37
25
  if (link == null) {
38
26
  logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", { url: wellKnownUrl.href, resourceDescriptor: wellKnownRd });
39
- return null;
27
+ return undefined;
40
28
  }
41
29
  nodeInfoUrl = link.href;
42
30
  }
@@ -47,17 +35,21 @@ export async function getNodeInfo(url, options = {}) {
47
35
  status: response.status,
48
36
  statusText: response.statusText,
49
37
  });
50
- return null;
38
+ return undefined;
51
39
  }
52
40
  const data = await response.json();
53
- return parseNodeInfo(data, options);
41
+ if (options.parse === "none")
42
+ return data;
43
+ return parseNodeInfo(data, {
44
+ tryBestEffort: options.parse === "best-effort",
45
+ }) ?? undefined;
54
46
  }
55
47
  catch (error) {
56
48
  logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
57
49
  url: url.toString(),
58
50
  error,
59
51
  });
60
- return null;
52
+ return undefined;
61
53
  }
62
54
  }
63
55
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.2.0-dev.464+133bc111",
3
+ "version": "1.2.0-dev.466+c9309d76",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
- import type { InboundService, NodeInfo, OutboundService, Protocol, Services, Software, Usage } from "./types.js";
2
+ import type { InboundService, JsonValue, NodeInfo, OutboundService, Protocol, Services, Software, Usage } from "./types.js";
3
3
  /**
4
4
  * Options for {@link getNodeInfo} function.
5
5
  * @since 1.2.0
6
6
  */
7
- export interface GetNodeInfoOptions extends ParseNodeInfoOptions {
7
+ export interface GetNodeInfoOptions {
8
8
  /**
9
9
  * Whether to directly fetch the NodeInfo document from the given URL.
10
10
  * Otherwise, the NodeInfo document will be fetched from the `.well-known`
@@ -13,6 +13,17 @@ export interface GetNodeInfoOptions extends ParseNodeInfoOptions {
13
13
  * Turned off by default.
14
14
  */
15
15
  direct?: boolean;
16
+ /**
17
+ * How strictly to parse the NodeInfo document.
18
+ *
19
+ * - `"strict"`: Parse the NodeInfo document strictly. If the document is
20
+ * invalid, `undefined` is returned. This is the default.
21
+ * - `"best-effort"`: Try to parse the NodeInfo document even if it is
22
+ * invalid.
23
+ * - `"none"`: Do not parse the NodeInfo document. The function will return
24
+ * the raw JSON value.
25
+ */
26
+ parse?: "strict" | "best-effort" | "none";
16
27
  }
17
28
  /**
18
29
  * Fetches a NodeInfo document from the given URL.
@@ -23,10 +34,27 @@ export interface GetNodeInfoOptions extends ParseNodeInfoOptions {
23
34
  * the NodeInfo document will be fetched from the given URL.
24
35
  * @param options Options for fetching the NodeInfo document.
25
36
  * @returns The NodeInfo document if it could be fetched successfully.
26
- * Otherwise, `null` is returned.
37
+ * Otherwise, `undefined` is returned.
38
+ * @since 1.2.0
39
+ */
40
+ export declare function getNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
41
+ parse?: "strict" | "best-effort";
42
+ }): Promise<NodeInfo | undefined>;
43
+ /**
44
+ * Fetches a NodeInfo document from the given URL.
45
+ * @param url The base URL of the server. If `options.direct` is turned off
46
+ * (default), the NodeInfo document will be fetched from
47
+ * the `.well-known` location of this URL (hence the only origin
48
+ * of the URL is used). If `options.direct` is turned on,
49
+ * the NodeInfo document will be fetched from the given URL.
50
+ * @param options Options for fetching the NodeInfo document.
51
+ * @returns The NodeInfo document if it could be fetched successfully.
52
+ * Otherwise, `undefined` is returned.
27
53
  * @since 1.2.0
28
54
  */
29
- export declare function getNodeInfo(url: URL | string, options?: GetNodeInfoOptions): Promise<NodeInfo | null>;
55
+ export declare function getNodeInfo(url: URL | string, options: GetNodeInfoOptions & {
56
+ parse: "none";
57
+ }): Promise<JsonValue | undefined>;
30
58
  /**
31
59
  * Options for {@link parseNodeInfo} function.
32
60
  * @since 1.2.0
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/nodeinfo/client.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EACV,cAAc,EAEd,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,KAAK,EACN,MAAM,YAAY,CAAC;AAIpB;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC9D;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,GAAG,GAAG,MAAM,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAqD1B;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH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