Unofficial Node Client for PubPub.
Warning This is not an official Client and is not supported by the PubPub team. Anything here may break at any time. Please use responsibly, don't spam the API, and don't blame me if you get banned.
If you use this in Node, you have to use Node 18 or higher in order to support native FormData.
You can use the Client with lower versions, but you won't be able to use the uploadFile
method.
pnpm add pubpub-client
# yarn add pubpub-client
# npm install pubpub-client
PubPub is a great platform for publishing academic work. However, the API is quite hidden and undocumented.
This Client is an attempt to make it easier to interact with the API.
Because there is no official API, this Client is built by reverse engineering the API calls made by the PubPub website.
This means that the Client is not guaranteed to work with future versions of PubPub.
Furthermore, the following is not possible to do with the Client or through the API in general:
While technically possible through the API, this is not possible through the Client. I think this would cause too much risk of accidentally deleting a community or creating too many superfluous communities.
The API does not support this.
Currently, the API does not (AFAIK) support a way to simply get a list of current collections or pagees.
The Client does support doing this through the hacks
methods.
Basically what these do is request the actual page instead of calling the API and parse the JSON data that is passed there.
This should be considered very unstable.
import { PubPub } from 'pubpub-client'
const communityUrl = 'https://demo.pubpub.org'
const communityId = '...'
const pubpub = new PubPub(communityId, communityUrl)
async function main() {
await PubPub.login('username', 'password')
const pubs = await pubpub.pub.getMany()
}
main()
The only difference between the usage the Client in Node and in the browser is during the use of the uploadFile
method.
In the browser, you must pass a File
or Blob
object as the first argument.
In Node, you can also pass a Buffer
object as the first argument.
See the documentation below for more detail.
TODO: setup typedoc
Contributions are very welcome!
If you find a bug or have a feature request, please open an issue.
git clone
pnpm install
pnpm run build
pnpm run test
pnpm run build
pnpm run publish
You can use the PubPub ID Finder to find the ID of a community, page, or collection.
While the SDK was designed to also be run in the browser, I realized that PubPub does not send CORS headers. This means that you can't use the SDK in the browser, sadly.
GPL-3.0+, Thomas F. K. Jorna