Dropthis Node SDK
Official Node.js SDK for Dropthis.
npm install @dropthis/sdk
Publish Anything
import { Dropthis } from "@dropthis/sdk";
const dropthis = new Dropthis({ apiKey: process.env.DROPTHIS_API_KEY });
const { data, error } = await dropthis.publish("./dist", {
title: "Generated launch page",
visibility: "unlisted",
});
if (error) {
console.error(error.message);
process.exit(1);
}
console.log(data.url);
Update A Drop
const created = await dropthis.publish("./dist", { title: "Launch" });
if (created.error) throw new Error(created.error.message);
const updated = await dropthis.update(created.data.id, "./dist", {
ifRevision: created.data.revision,
});
if (updated.error) throw new Error(updated.error.message);
const deployments = await dropthis.deployments.list(created.data.id);
Supported inputs:
- HTML strings
- Plain text strings
- HTTP(S) URLs
- Local files and folders, uploaded through staged signed URLs
- Explicit
content, files, sourceUrl, and sourceUrls objects
Large strings, binary inputs, local files, local folders, and explicit files are staged through /uploads, signed object-store PUT requests, upload completion, then a final upload_id publish request.
Error Handling
SDK methods return { data, error, headers }.
const result = await dropthis.drops.get("drop_123");
if (result.error) {
console.error(result.error.code, result.error.message);
}
Resources
dropthis.auth.requestEmailOtp({ email: "agent@example.com" });
dropthis.auth.verifyEmailOtp({ email: "agent@example.com", code: "123456" });
dropthis.apiKeys.create({ label: "CI" });
dropthis.drops.list({ limit: 20 });
dropthis.drops.get("drop_123");
dropthis.drops.update("drop_123", { title: "Updated" });
dropthis.drops.delete("drop_123");
dropthis.uploads.create({
schemaVersion: 1,
files: [{ path: "index.html", contentType: "text/html", sizeBytes: 12 }],
});
dropthis.uploads.get("upl_123");
dropthis.uploads.complete("upl_123", { files: {} });
dropthis.uploads.cancel("upl_123");
dropthis.deployments.list("drop_123");
dropthis.deployments.get("drop_123", "dep_123");
dropthis.account.get();