1.0.0
06/05/2024 18:33:31
The Context SDK provides a powerful and flexible way to interact with Context, enabling developers to manage domains and documents programmatically. With this SDK, you can create, modify, and manage domains and their associated documents using Context's API.
To start using the Context SDK in your TypeScript project, install it via npm:
$ npm install @contextprotocol/sdk
This section walks you through setting up a basic connection and performing common operations with the Context SDK. Setting Up Your Connection First, import the SDK and create an instance of the Context object using your API key:
import { Context } from '@contextprotocol/sdk';
const ctx = new Context();
To initialize the SDK, you need to provide the api key:
await ctx.init({ apiKey });
Retrieving info for your domain:
const yourDomain = await ctx.domain();
To get information about a domain:
const domain = await ctx.domain("domain_name");
domain.name;
domain.nameHash;
domain.createdAt;
domain.updatedAt;
Retrieve all documents within a domain or a specific document:
const document = await domain.document("document_path"); // Get a specific document
const documentInVersionXYZ = await domain.document("document_path?v=X.Y.Z"); // Get a specific version of a document
Retriving the document data:
document.data;
Retrieving a document version list:
const documentVersions = await document.versions();
Get a specific version of a document:
const documentVersion = await document.version("X.Y.Z");
document.path
document.versionNumber
document.data
document.createdAt
document.updatedAt
Steps to create a new document under a domain:
const data: any = YOUR_AWESOME_JSON_DATA;
const templates: string[] = ["template_path"]; // Optional
const newDocument = await domain.createDocument("document_path", data, templates);
Adding a template to a document:
await document.addTemplate("template_path");
Creating a template:
const myDataType = `interface User{
name: string;
age: number;
}`;
const schema = generateJsonSchema(dataName, myDataType);
const template = await domain.createTemplate("template_path", schema);
Retrieving all Domain Information
const allDomainsInfo = await ctx.public.domains();
const allDomainsInfo = await ctx.public.domains({offset: 1, limit: 10});
Retrieving all documents from public API
const allDocuments = await ctx.public.documents();
const allDocuments = await ctx.public.documents({offset: 1, limit: 10, name: "document_name", domain: "domain_name"});
For more detailed information on the Context SDK, please refer to the official documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
Key | Value |
---|---|
readme | https://arweave.net/VcQyZPMY_QXp_QA4xi9dBj9xd6vLAd-BkZMkMVTsaqQ |
Size: 237.00 bytes
Last update: 06/05/2024 18:33:31
Tx: