Typescript/Javascript library that provides basic API calls and utility functions that are useful to interact with ActivityPub-based Fediverse instances. It supports also related protocols and specifications such as Webfinger.
# Not yet published
$ yarn add @networld-to/fediverse-helper
See the following usage example to get started.
import FediverseAccount from '@networld-to/fediverse-helper';
const fediAccount = new FediverseAccount('@[email protected]');
console.log(fediProfile.getInstanceHost());
fediProfile.getAccountInfo(this.email).then((profile) => {
console.log(profile);
});
The FediverseAccount class accepts the fediverse handle as input parameter during the instantiation. Everything else is derived from it by making the right calls and parsing the right data.
Function | Params | Output | Caching |
---|---|---|---|
getInstanceHost | None | fediverseHost (String) | Not needed, local call |
getWebfingerInfo | forceFetch: boolean = false (optional) | webfingerInfo (Object) | Yes |
getInstanceInfo | forceFetch: boolean = false (optional) | instanceInfo (Object) | Yes |
getAccountInfo | forceFetch: boolean = false (optional) | accountInfo (Object) | Yes |
getOutboxPosts | None | posts ([Object]) | No |
The getHandleHost is an internal helper function that splits the fediverse handle into two parts and returns the hostname of it. For the instance host use the getInstanceHost function. The fediverse handle may only be an alias to the real instance.
# To run ./client/main.js after compiling the library (see ./dist output)
$ yarn run client @[email protected]
Alternatively run the steps manually.
# Make your changes in files under ./src/
$ yarn build
# see output under ./dist
# Change code under ./client/main.js and run it
$ node ./client/main.js @[email protected]