Unverified Commit aa5e275d authored by Hong Minhee's avatar Hong Minhee
Browse files

NodeInfo client

parent aa8dcdc7
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -8,12 +8,24 @@ Version 1.2.0

To be released.

 -  Added NodeInfo client functions.

     -  Added `getNodeInfo()` function.
     -  Added `GetNodeInfoOptions` interface.
     -  Added `parseNodeInfo()` function.
     -  Added `ParseNodeInfoOptions` interface.

 -  Re-exported Semantic Versioning-related types and functions:

     -  Added `SemVer` type.
     -  Added `formatSemVer()` function.
     -  Added `parseSemVer()` function.

 -  Added more log messages using the [LogTape] library.  Currently the below
    logger categories are used:

     -  `["fedify", "nodeinfo", "client"]`


Version 1.1.0
-------------
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ features:
- icon: ℹ️
  title: NodeInfo
  details: >-
    <a href="https://nodeinfo.diaspora.software/">NodeInfo</a> server
    <a href="https://nodeinfo.diaspora.software/">NodeInfo</a> server and client
  link: /manual/nodeinfo.md
- icon: 🧩
  title: Integration
+8 −0
Original line number Diff line number Diff line
@@ -161,6 +161,14 @@ The `["fedify", "federation", "queue"]` category is used for logging messages
related to the task queue.  When you are curious about the task queue, you can
check the log messages in this category with the `"debug"` level.

### `["fedify", "nodeinfo", "client"]`

*This category is available since Fedify 1.2.0.*

The `["fedify", "nodeinfo", "client"]` category is used for logging messages
related to the NodeInfo client.  When you are curious about the NodeInfo client,
you can check the log messages in this category with the `"error"` level.

### `["fedify", "runtime", "docloader"]`

*This category is available since Fedify 0.8.0.*
+41 −4
Original line number Diff line number Diff line
@@ -94,8 +94,10 @@ The `NodeInfo` interface is defined as follows:

`software.version`
:   *Required.*  The version of the server software.  This must be a valid
    [`SemVer`] object.  For your information, a Semantic Versioning string
    can be parsed into a [`SemVer`] object using [`parse()`] function.
    `SemVer` object.  For your information, a Semantic Versioning string
    can be parsed into a `SemVer` object using `parseSemVer()` function.
    In the other way around, you can render a `SemVer` object into a Semantic
    Versioning string using `formatSemVer()` function.

`software.repository`
:   The [`URL`] of the source code repository of the server software.
@@ -140,6 +142,41 @@ The `NodeInfo` interface is defined as follows:
    the server.  This `number` has to be an integer greater than or equal to
    zero.

[`SemVer`]: https://jsr.io/@std/semver/doc/~/SemVer
[`parse()`]: https://jsr.io/@std/semver/doc/~/parse
[`URL`]: https://developer.mozilla.org/en-US/docs/Web/API/URL


NodeInfo client
---------------

*This API is available since Fedify 1.2.0.*

You may want to fetch NodeInfo objects from other servers.  Fedify provides
a way to fetch NodeInfo objects with the `getNodeInfo()` function:

~~~~ typescript twoslash
import { type NodeInfo, getNodeInfo } from "@fedify/fedify";

const nodeInfo: NodeInfo | null = await getNodeInfo("https://example.com/");
if (nodeInfo != null) console.log(nodeInfo);
~~~~

The `getNodeInfo()` function returns a `NodeInfo` object if the server provides
a NodeInfo endpoint and the response is valid.  Otherwise, it returns `null`.

> [!TIP]
> Sometimes, a server may provide a slightly invalid NodeInfo object.  In such
> case, you can enforce parsing the object by passing `{ tryBestEffort: true }`
> option as the second argument to `getNodeInfo()` function:
>
> ~~~~ typescript twoslash
> import { type NodeInfo, getNodeInfo } from "@fedify/fedify";
>
> const nodeInfo: NodeInfo | null = await getNodeInfo("https://example.com/", {
>   tryBestEffort: true,
> });
>
> if (nodeInfo != null) console.log(nodeInfo);
> ~~~~
>
> However, it does not guarantee that parsing will always succeed.  It just
> tries to parse the object as much as possible.
+889 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading