Server Library
Process workspace data by using Pine's API client.
The @pinecards/server library provides an easy way to interact with the Pine API in a type-safe manner. To get started, you'll need to install the library in your project with your preferred package manager:
npm install @pinecards/serverYou can then import the PineClient class and construct it with your authorization token:
import { PineClient } from "@pinecards/server";
const client = new PineClient({ accessToken: "YOUR_TOKEN" });The PineClient uses tRPC under the hood to make network requests. As a result, this requires explicitly denoting whether a certain operation is a query or a mutation.
client.cards.list.query({ where: { limit: 500 } });Queries
Read queries are the simplest operations as they only require a valid idas part of their where argument:
const deck = await client.decks.read.query({ where: { id: "..." } });
const card = await client.cards.read.query({ where: { id: "..." } });List queries rely on cursor-based pagination and can thus optionally take a limit (min 1, max 500) and a cursor argument:
const response = await client.decks.list.query({ where: { limit: 500 } });
if (response.cursor) {
const { data } = await client.decks.list.query({
where: { cursor: response.cursor }
});
}
Mutations
Create mutations take data inputs that depend on the model that is being operated on:
Decks require a
titleargument that accepts an input array that conforms to Pine's inline text editor.Cards require a
titleandbodyargument that conforms to Pine's block text editor.Associations (comments, etc..) require a
bodyargument that conforms to Pine's block text editor and awhereargument for specifying the parent model to which the association should be added.Connections (links, backlinks, etc..) require a
bodyargument that conforms to Pine's block text editor and awhereargument for specifying the parent model to which the connection should be added.
Update mutations are similar, except they require a where argument and optional data:
Delete mutations only require a where argument:
Fields
The Fields API allows you to query a workspace's configured fields. This will return an object/dictionary data structure with the appropriate field type matching the corresponding value type:
text
string
number
number
switch
boolean
date
string
Fields that haven't been assigned a value will return a null value.
You can retrieve the value of a configured number field as follows:
Webhooks
Pine provides webhooks for Deck and Card events, allowing you to listen to any workspace changes that affect these models.
Webhook events are sent to a publicly accessible HTTPS URL via a HTTP POSTrequest. The POST request expects a HTTP 200 status code in response and will be retried only once if it fails to receive it.
The @pinecards/server library exports a PineWebhooks class for securely constructing a webhook payload. Here's a simple demonstration using the express library:
Under the hood, Pine verifies that the signature contained in req.headers["pine-signature"] matches the signature that is constructed from the raw body:
The event that is returned from the construct function contains the following fields:
id
The unique identifier for the webhook event.
action
The create, update, or delete action.
data
The Deck or Card data that changed.
webhookTimestamp
Timestamp of when the webhook was sent to help guard against replay attacks.
Last updated