TypeScript SDK
Ce contenu n’est pas encore disponible dans votre langue.
The TypeScript SDK provides a type-safe client for integrating with Subnoto’s API. It handles Oak tunnel encryption, HTTP signature authentication, and provides helper functions for common operations.
Installation
Section titled “Installation”npm install @subnoto/api-client# orpnpm add @subnoto/api-client# oryarn add @subnoto/api-clientQuick Start
Section titled “Quick Start”import { SubnotoClient } from "@subnoto/api-client";
const client = new SubnotoClient({ apiBaseUrl: "https://enclave.subnoto.com", accessKey: process.env.API_ACCESS_KEY, secretKey: process.env.API_SECRET_KEY, unattested: false});
// Use openapi-fetch syntaxconst { data, error } = await client.POST("/public/utils/whoami", { body: {} });console.log("User info:", data);
const { data: workspaces } = await client.POST("/public/workspace/list", { body: {} });console.log("Workspaces:", workspaces);Configuration
Section titled “Configuration”| Option | Type | Required | Description |
|---|---|---|---|
apiBaseUrl | string | Yes | API base URL |
accessKey | string | Yes | API access key |
secretKey | string | Yes | API secret key |
unattested | boolean | No | Use unattested mode (default: false) |
attesterKey | Buffer | No | Public key for attestation |
Common Use Cases
Section titled “Common Use Cases”List Workspaces
Section titled “List Workspaces”const { data, error } = await client.POST("/public/workspace/list", { body: {} });
if (error) { console.error("Failed to list workspaces:", error);} else { data.workspaces.forEach(workspace => { console.log(`Workspace: ${workspace.name} (${workspace.uuid})`); });}List Envelopes in a Workspace
Section titled “List Envelopes in a Workspace”const { data, error } = await client.POST("/public/envelope/list", { body: { workspaceUuid: "your-workspace-uuid", page: 1 }});
if (data) { data.envelopes.forEach(envelope => { console.log(`Envelope: ${envelope.title} - Status: ${envelope.status}`); });}Create an Envelope from Template
Section titled “Create an Envelope from Template”// Create envelope from a pre-configured template// Recipients must include labels that match the template's recipient labelsconst { data, error } = await client.POST("/public/envelope/create-from-template", { body: { workspaceUuid: "your-workspace-uuid", templateUuid: "your-template-uuid", recipients: [ { type: "manual", label: "customer", firstname: "John", lastname: "Doe" }, { type: "manual", label: "manager", firstname: "Jane", lastname: "Smith" } ] }});
if (data) { console.log(`Created envelope: ${data.envelopeUuid}`);}Send an Envelope
Section titled “Send an Envelope”const { error } = await client.POST("/public/envelope/send", { body: { workspaceUuid: "your-workspace-uuid", envelopeUuid: "your-envelope-uuid", customInvitationMessage: "Please review and sign this document." }});
if (!error) { console.log("Envelope sent successfully!");}List Templates
Section titled “List Templates”const { data, error } = await client.POST("/public/template/list", { body: { page: 1 }});
if (data) { data.templates.forEach(template => { console.log(`Template: ${template.name} (${template.uuid})`); });}List Contacts
Section titled “List Contacts”const { data, error } = await client.POST("/public/contact/list", { body: { workspaceUuid: "your-workspace-uuid" }});
if (data) { data.contacts.forEach(contact => { console.log(`Contact: ${contact.firstname} ${contact.lastname} (${contact.email})`); });}Full Workflow Examples
Section titled “Full Workflow Examples”Creating an Envelope from a Template
Section titled “Creating an Envelope from a Template”import { SubnotoClient } from "@subnoto/api-client";
async function createAndSendEnvelopeFromTemplate() { const client = new SubnotoClient({ apiBaseUrl: "https://enclave.subnoto.com", accessKey: process.env.API_ACCESS_KEY, secretKey: process.env.API_SECRET_KEY });
// 1. Get workspace const { data: workspaceData } = await client.POST("/public/workspace/list", { body: {} }); const workspaceUuid = workspaceData.workspaces[0].uuid;
// 2. Get template const { data: templateData } = await client.POST("/public/template/list", { body: { page: 1 } }); const templateUuid = templateData.templates[0].uuid;
// 3. Create envelope from template const { data: envelopeData } = await client.POST("/public/envelope/create-from-template", { body: { workspaceUuid, templateUuid, recipients: [ { type: "manual", label: "signer", firstname: "John", lastname: "Doe" } ] } });
// 4. Send the envelope await client.POST("/public/envelope/send", { body: { workspaceUuid, envelopeUuid: envelopeData.envelopeUuid, customInvitationMessage: "Please review and sign this document." } });
console.log(`Envelope ${envelopeData.envelopeUuid} created and sent!`);}
createAndSendEnvelopeFromTemplate().catch(console.error);Creating an Envelope with a Document Upload
Section titled “Creating an Envelope with a Document Upload”Upload documents to create envelopes. Supported file types: PDF (.pdf) and Word documents (.docx, .doc) - Word files are automatically converted to PDF. Maximum file size: 50 MB.
The SDK provides a helper method uploadDocument that simplifies document uploads by handling multipart/form-data automatically. This is the recommended approach.
import { SubnotoClient } from "@subnoto/api-client";import { readFileSync } from "fs";
async function createAndSendEnvelopeWithDocument() { const client = new SubnotoClient({ apiBaseUrl: "https://enclave.subnoto.com", accessKey: process.env.API_ACCESS_KEY, secretKey: process.env.API_SECRET_KEY });
// 1. Get workspace const { data: workspaceData } = await client.POST("/public/workspace/list", { body: {} }); const workspaceUuid = workspaceData.workspaces[0].uuid;
// 2. Upload document and create envelope using the helper method const pdfBuffer = readFileSync("path/to/document.pdf"); const result = await client.uploadDocument({ workspaceUuid, fileBuffer: pdfBuffer, envelopeTitle: "My Document" });
const { envelopeUuid, documentUuid } = result;
// 3. Add recipients await client.POST("/public/envelope/add-recipients", { body: { workspaceUuid, envelopeUuid, recipients: [ { type: "manual", firstname: "John", lastname: "Doe" } ] } });
// 4. Add signature blocks await client.POST("/public/envelope/add-blocks", { body: { workspaceUuid, envelopeUuid, documentUuid, blocks: [ { type: "signature", page: "1", x: 100, y: 200, } ] } });
// 5. Send the envelope await client.POST("/public/envelope/send", { body: { workspaceUuid, envelopeUuid, customInvitationMessage: "Please review and sign this document." } });
console.log(`Envelope ${envelopeUuid} created and sent!`);}
createAndSendEnvelopeWithDocument().catch(console.error);Alternative: Manual FormData Approach
Section titled “Alternative: Manual FormData Approach”If you need more control over the upload process, you can use the create-from-file endpoint directly with FormData. Steps 3-5 (add recipients, add blocks, send) remain the same as shown above.
Required dependency:
npm install form-data# orpnpm add form-dataimport { SubnotoClient } from "@subnoto/api-client";import FormData from "form-data";import { createReadStream } from "fs";
// ... (steps 1 and client setup same as above) ...
// 2. Upload document and create envelope using FormDataconst formData = new FormData();formData.append("workspaceUuid", workspaceUuid);formData.append("envelopeTitle", "My Document");formData.append("file", createReadStream("path/to/document.pdf"));
const { data: envelopeData, error: uploadError } = await client.POST("/public/envelope/create-from-file", { body: formData as any, headers: { ...formData.getHeaders() }});
if (uploadError) { throw new Error(`Failed to upload document: ${uploadError}`);}
const { envelopeUuid, documentUuid } = envelopeData;
// Continue with steps 3-5 as shown in the example aboveAttestation
Section titled “Attestation”The SDK supports attestation verification to ensure you’re communicating with a genuine Subnoto enclave:
const client = new SubnotoClient({ apiBaseUrl: "https://enclave.subnoto.com", accessKey: process.env.API_ACCESS_KEY, secretKey: process.env.API_SECRET_KEY, attesterKey: Buffer.from(process.env.ATTESTATION_PUBLIC_KEYS, "base64"), unattested: false // Enable attestation (default)});
// After making a request, check attestation statusconst attestationStatus = client.getAttestationStatus();console.log("Attestation status:", attestationStatus);
const attestationResults = client.getAttestationResults();console.log("Attestation results:", attestationResults);API Reference
Section titled “API Reference”The SDK uses openapi-fetch syntax for all API calls. All endpoints are type-safe and match the OpenAPI specification.
For complete API documentation, see the OpenAPI specifications.
Package
Section titled “Package”- NPM: @subnoto/api-client
- License: Apache-2.0