@api-engineering-digitalocean/dots
v1.0.0
Published
TypeScript client generator based on DigitalOcean's OpenAPI specification.
Downloads
14
Maintainers
Readme
dots
dots is the official DigitalOcean Typescript Client based on the DO OpenAPIv3 specification.
Getting Started
Prerequisites
- NodeJS 18 or above
- TypeScript 5 or above
- A DigitalOcean account with an active subscription. Along with a DigitalOcean token with proper permissions to manage DigitalOcean resources.
Installation
To install the dependencies for this repository, use the following command:
- Clone this repo. The client is not published anywhere currently.
- Install the dependencies for this repository. Run this command at the root of the repo:
npm installQuick Start
Authenticating
dots must be initialized with createDigitalOceanClient(). A DigitalOcean token is required. This token can be passed in via DigitalOceanApiKeyAuthenticationProvider(), an example below:
const authProvider = new DigitalOceanApiKeyAuthenticationProvider(token!);
// Create request adapter using the fetch-based implementation
const adapter = new FetchRequestAdapter(authProvider);
// Create the API client
const client = createDigitalOceanClient(adapter);Managing DigitalOcean Resources via dots
Find below a working example of creating a DigitalOcean volume via dots:
import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";
import { createDigitalOceanClient } from "../src/dots/digitalOceanClient.js";
import { DigitalOceanApiKeyAuthenticationProvider } from '../src/dots/DigitalOceanApiKeyAuthenticationProvider.js';
import {Volumes_ext4} from "../src/dots/models/index.js";
const token = process.env.DIGITALOCEAN_TOKEN;
if (!token) {
throw new Error("DIGITALOCEAN_TOKEN not set");
}
const authProvider = new DigitalOceanApiKeyAuthenticationProvider(token!);
// Create request adapter using the fetch-based implementation
const adapter = new FetchRequestAdapter(authProvider);
// Create the API client
const client = createDigitalOceanClient(adapter);
async function main(): Promise<void> {
try {
const volumeReq: Volumes_ext4 = {
sizeGigabytes: 10,
name: `test-volume`,
description: "Block storage testing",
region: "nyc3",
filesystemType: "ext4",
};
const resp = await client.v2.volumes.post(volumeReq);
if (resp && resp.volume) {
const volume = resp.volume;
console.log(`Created volume ${volume.name} <ID: ${volume.id}>`);
} else {
throw new Error("Failed to create volume or volume is undefined");
}
console.log("Done!");
} catch (err) {
console.error(err);
}
}
main();Running the above code snippet with tsc && node index.js would output the following:
Created volume test-volume <ID: 751d0c09-1613-11f0-8aa5-0a58ac147241>
Done!More working examples can be found in dots/examples.
