Client Library

Process workspace data by using Pine's API client.

This library is only intended for use on the frontend. Use the @pinecards/server library to communicate with Pine on the backend.

Pine's client library provides an easy way to interact with the Pine API from within a frontend extension.

To get started, you'll need to install the library in your project with your preferred package manager:

npm install @pinecards/client

The PineSDKClient uses IPC messages under the hood to securely communicate with Pine. To create the connection, it's thus necessary to call connectSDKClient as soon as possible in the global scope of your application:

import { connectSDKClient } from "@pinecards/client";
 
const client = connectSDKClient({ debug: false }) 

The cards, decks, and fields namespaces follow a similar signature to server library, while namespaces like routes , storage, and context are available exclusively through the client library.

Cards

The cards namespace provides methods for interacting with card data.

Data can be queried using read and list, as expanded on in queries.

const card = await client.cards.read({ where: { id: "..." } });
const { data: cards } = await client.cards.list({ where: { limit: 100 } });

Data can be mutated using create, update, and delete, as expanded on in mutations.

const createdCard = await client.cards.create({
  data: { title: [], body: [] },
});

const updatedCard = await client.cards.update({
  where: { id: "..." },
  data: { title: [], body: [] },
});

await client.cards.delete({ where: { id: "..." } });

Data can be subscribed to by using the on handler:

These methods will throw an error if you do not have the required card permissions.

The cards namespace also supports the following sub-namespaces:

  • associations: create, update, and delete card associations (comments, etc...).

  • connections: create, update, and delete card connections (links, backlinks, etc...).

  • embeddings: read and list local AI card embeddings.

Decks

The decks namespace provides methods for interacting with deck data.

Data can be queried using read and list, as expanded on in queries.

Data can be mutated using create, update, and delete, as expanded on in mutations.

Data can be subscribed to by using the on handler:

These methods will throw an error if you do not have the required deck permissions.

The decks namespace also supports the following sub-namespaces:

  • associations: create, update, and delete deck associations (comments, etc...).

  • connections: create, update, and delete deck connections (links, backlinks, etc...).

  • embeddings: read and list local AI deck embeddings.

Fields

The fields namespace provides methods for interacting with a workspace's configured preferences. This will return an object/dictionary data structure with the appropriate field type matching the corresponding value type:

Field type
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:

Routes

The routes namespace allows you to listen to route changes, as well as navigate users to specific routes.

Storage

The storage namespace provides methods for storing data in IndexedDB.

To minimize security risks, both the key and value arguments must be strings. It's recommended to serialize your inputs to strings (e.g. using JSON.stringify()) if you wish to store more complex objects:

Context

The context namespace provides utilities for accessing information such as theme data or manipulating the optional badge that appears next to the integration icon in the sidebar.

Last updated