@sidedrawer/sdk
v0.0.15
Published
SideDrawer SDK
Downloads
266
Keywords
Readme
SideDrawer JavaScript SDK
SDK for the SideDrawer API
Installation
To install the SDK, use:
npm install -S @sidedrawer/sdk
Example
Import SDK
import { SideDrawer } from "@sidedrawer/sdk";
const { SideDrawer } = require("@sidedrawer/sdk");
<script type="text/javascript" src="/dist/index.browser.js"></script>
Create an instance of the SDK:
const sd = new SideDrawer({
accessToken: '...'
}); // you can target a different environment, using { baseUrl: 'https://...' }
Then you can use the different modules to communicate with our APIs. Examples:
Search Records
const sd = new SideDrawer({
accessToken: '...'
});
const records = await sd.records.search({
sidedrawerId: '...',
displayInactive: false,
locale: 'en-US'
});
Upload File to Record
const sd = new SideDrawer({
accessToken: '...'
});
const controller = new AbortController();
const file = document.querySelector('#file-input').files[0];
const progressSubscriber$ = new rxjs.Subject<number>();
progressSubscriber$.subscribe((progressPercentage: number) => {
console.log(`Upload progress: ${progressPercentage}`);
});
await sd.files.upload({
// params
sidedrawerId: "...",
recordId: "...",
file, // Blob or ArrayBuffer
fileName: "...",
uploadTitle: "...",
fileType: "...",
fileExtension: "..",
metadata: {
testKey: "test value",
},
externalKeys: [
{ key: "test", value: "test" }
],
progressSubscriber$,
// options
signal: controller.signal,
maxRetries: 2,
maxConcurrency: 4,
});
Download File from a Record
Browser:
const file: Blob = await sd.files.download({
sidedrawerId: "...",
recordId: "...",
fileNameWithExtension: "...",
});
const file: Blob = await sd.files.download({
sidedrawerId: "...",
recordId: "...",
fileToken: "...",
progressSubscriber$: {
next: (progressPercentage: number) => {
console.log(`Download progress: ${progressPercentage}`);
}
}
});
NodeJs
const file: ArrayBuffer = await sd.files.download({
sidedrawerId: "...",
recordId: "...",
fileNameWithExtension: "...",
});
Create an instance of single SDK module:
import { Context, Records } from "@sidedrawer/sdk";
const context = new Context({
accessToken: '...'
});
const records = new Records(context);
or
const { SideDrawer } = require("@sidedrawer/sdk");
const context = new SideDrawer.Context({
accessToken: '...'
});
const records = new SideDrawer.Records(context);