├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .nvmrc ├── .prettierignore ├── .prettierrc ├── .vscode ├── extensions.json └── settings.json ├── LICENSE ├── README.md ├── jest.config.ts ├── jest.preset.js ├── migrations.json ├── nx.json ├── package.json ├── packages ├── .gitkeep └── digitalocean-js │ ├── .eslintrc.json │ ├── README.md │ ├── jest.config.ts │ ├── package.json │ ├── project.json │ ├── src │ ├── index.ts │ ├── lib │ │ ├── axios-instance.ts │ │ ├── conf │ │ │ └── environment.ts │ │ ├── digitalocean.spec.ts │ │ ├── digitalocean.ts │ │ ├── models │ │ │ ├── account.ts │ │ │ ├── action.ts │ │ │ ├── backup.ts │ │ │ ├── balance.ts │ │ │ ├── billing-history.ts │ │ │ ├── block-storage.ts │ │ │ ├── cdn.ts │ │ │ ├── certificate.ts │ │ │ ├── domain-record.ts │ │ │ ├── domain.ts │ │ │ ├── droplet.ts │ │ │ ├── firewall.ts │ │ │ ├── floating-ip.ts │ │ │ ├── image.ts │ │ │ ├── index.ts │ │ │ ├── kernel.ts │ │ │ ├── kubernetes-cluster.ts │ │ │ ├── load-balancer.ts │ │ │ ├── network.ts │ │ │ ├── networks.ts │ │ │ ├── project.ts │ │ │ ├── region.ts │ │ │ ├── size.ts │ │ │ ├── snapshot.ts │ │ │ ├── ssh-key.ts │ │ │ └── tag.ts │ │ └── services │ │ │ ├── account │ │ │ ├── account.service.spec.ts │ │ │ └── account.service.ts │ │ │ ├── actions │ │ │ ├── actions.service.spec.ts │ │ │ └── actions.service.ts │ │ │ ├── billing-history │ │ │ ├── billing-history.service.spec.ts │ │ │ └── billing-history.service.ts │ │ │ ├── block-storage │ │ │ ├── block-storage-actions.service.ts │ │ │ └── block-storage.service.ts │ │ │ ├── cdn │ │ │ ├── cdn.service.spec.ts │ │ │ └── cdn.service.ts │ │ │ ├── certificate │ │ │ └── certificate.service.ts │ │ │ ├── domain │ │ │ ├── domain-record.service.ts │ │ │ └── domain.service.ts │ │ │ ├── droplet │ │ │ ├── droplet-actions.service.ts │ │ │ └── droplet.service.ts │ │ │ ├── firewall │ │ │ └── firewall.service.ts │ │ │ ├── floating-ip │ │ │ ├── floating-ip-actions.service.ts │ │ │ └── floating-ip.service.ts │ │ │ ├── image │ │ │ ├── image-actions.service.ts │ │ │ └── image.service.ts │ │ │ ├── index.ts │ │ │ ├── kubernetes │ │ │ └── kubernetes.service.ts │ │ │ ├── load-balancer │ │ │ └── load-balancer.service.ts │ │ │ ├── project │ │ │ ├── project.service.spec.ts │ │ │ └── project.service.ts │ │ │ ├── region │ │ │ └── region.service.ts │ │ │ ├── size │ │ │ └── size.service.ts │ │ │ ├── snapshot │ │ │ └── snapshot.service.ts │ │ │ ├── ssh │ │ │ └── ssh.service.ts │ │ │ └── tag │ │ │ └── tag.service.ts │ └── test │ │ ├── errors.ts │ │ ├── fixtures │ │ ├── accounts.fixture.ts │ │ ├── actions.fixture.ts │ │ ├── balance.fixture.ts │ │ ├── billing-history.fixture.ts │ │ ├── block-storage.fixture.ts │ │ ├── cdn.fixture.ts │ │ ├── error.fixture.ts │ │ └── projects.fixture.ts │ │ ├── index.ts │ │ └── models.ts │ ├── tsconfig.json │ ├── tsconfig.lib.json │ └── tsconfig.spec.json ├── tools └── tsconfig.tools.json ├── tsconfig.base.json ├── typedoc.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "ignorePatterns": ["**/*", "**/node_modules/**/*"], 4 | "plugins": ["@nx"], 5 | "overrides": [ 6 | { 7 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], 8 | "excludedFiles": ["**/node_modules/**/*"], 9 | "rules": { 10 | "@nx/enforce-module-boundaries": [ 11 | "error", 12 | { 13 | "enforceBuildableLibDependency": true, 14 | "allow": [], 15 | "depConstraints": [ 16 | { 17 | "sourceTag": "*", 18 | "onlyDependOnLibsWithTags": ["*"] 19 | } 20 | ] 21 | } 22 | ], 23 | "@typescript-eslint/no-non-null-assertion": "off" 24 | } 25 | }, 26 | { 27 | "files": ["*.ts", "*.tsx"], 28 | "excludedFiles": ["**/node_modules/**/*"], 29 | "extends": ["plugin:@nx/typescript"], 30 | "rules": { 31 | "@typescript-eslint/no-extra-semi": "error", 32 | "no-extra-semi": "off" 33 | } 34 | }, 35 | { 36 | "files": ["*.js", "*.jsx"], 37 | "excludedFiles": ["**/node_modules/**/*"], 38 | "extends": ["plugin:@nx/javascript"], 39 | "rules": { 40 | "@typescript-eslint/no-extra-semi": "error", 41 | "no-extra-semi": "off" 42 | } 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **I'm submitting a ...** 2 | [ ] bug report 3 | [ ] feature request 4 | [ ] question about the decisions made in the repository 5 | [ ] question about how to use this project 6 | 7 | * **Summary** 8 | 9 | 10 | 11 | * **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) 2 | 3 | 4 | 5 | * **What is the current behavior?** (You can also link to an open issue here) 6 | 7 | 8 | 9 | * **What is the new behavior (if this is a feature change)?** 10 | 11 | 12 | 13 | * **Other information**: 14 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the main branch 8 | push: 9 | branches: [ main ] 10 | pull_request: 11 | branches: [ main ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | - uses: actions/checkout@v1 26 | 27 | - run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc) 28 | id: nvm 29 | 30 | - uses: actions/setup-node@v2 31 | with: 32 | node-version: ${{ steps.nvm.outputs.NODE_VERSION }} 33 | 34 | - name: Install dependencies 35 | run: yarn install 36 | 37 | - name: Lint 38 | run: yarn nx lint digitalocean-js 39 | 40 | - name: Tests 41 | run: yarn nx test digitalocean-js 42 | 43 | - name: Build 44 | run: yarn nx build digitalocean-js 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | 41 | .nx/cache 42 | .nx/workspace-data -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Add files here to ignore them from prettier formatting 2 | 3 | /dist 4 | /coverage 5 | 6 | /.nx/cache 7 | /.nx/workspace-data -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSpacing": true, 4 | "printWidth": 80, 5 | "semi": true, 6 | "singleQuote": true, 7 | "tabWidth": 2, 8 | "trailingComma": "none", 9 | "useTabs": false 10 | } 11 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "nrwl.angular-console", 4 | "esbenp.prettier-vscode", 5 | "dbaeumer.vscode-eslint", 6 | "firsttris.vscode-jest-runner" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib", 3 | "editor.formatOnSave": true, 4 | "editor.defaultFormatter": "esbenp.prettier-vscode", 5 | "editor.codeActionsOnSave": { 6 | "source.organizeImports": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 John Woodruff 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![digitalocean-js](https://user-images.githubusercontent.com/5883616/126348407-dd1e694d-64a9-402e-b8df-f59e67686014.png) 2 | 3 | # DigitalOcean JS 4 | 5 | [![CI](https://github.com/johnbwoodruff/digitalocean-js/actions/workflows/main.yml/badge.svg)](https://github.com/johnbwoodruff/digitalocean-js/actions/workflows/main.yml) [![npm](https://img.shields.io/npm/dm/digitalocean-js.svg)](https://www.npmjs.com/package/digitalocean-js) [![npm](https://img.shields.io/npm/dt/digitalocean-js.svg)](https://www.npmjs.com/package/digitalocean-js) [![npm](https://img.shields.io/npm/v/digitalocean-js.svg)](https://www.npmjs.com/package/digitalocean-js) 6 | 7 | JavaScript library for the DigitalOcean API. For use in Node or the browser. 8 | 9 | ## Goals 10 | 11 | This library was built with a few goals in mind: 12 | 13 | - Be able to use in a Node or Browser environment with no difference in usage. 14 | - Use Promises instead of callbacks so clients can make use of `async`/`await`. 15 | - Be built in TypeScript so consumers of the library can benefit from excellent intellisense with the TypeScript definitions. 16 | - Provide solid documentation including examples for usage. 17 | 18 | ## Usage 19 | 20 | To use the library, install from the npm repository. 21 | 22 | ```shell 23 | $ npm install --save digitalocean-js 24 | # Alternatively install with yarn 25 | $ yarn add digitalocean-js 26 | ``` 27 | 28 | Simply import the client and initialize it with your API token: 29 | 30 | ```js 31 | import { DigitalOcean } from 'digitalocean-js'; 32 | 33 | const client = new DigitalOcean('my-api-token'); 34 | ``` 35 | 36 | To see all the services available, check out the [documentation](https://johnbwoodruff.github.io/digitalocean-js/). 37 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | const { getJestProjects } = require('@nx/jest'); 2 | 3 | export default { 4 | projects: getJestProjects() 5 | }; 6 | -------------------------------------------------------------------------------- /jest.preset.js: -------------------------------------------------------------------------------- 1 | const nxPreset = require('@nx/jest/preset').default; 2 | 3 | module.exports = { 4 | ...nxPreset 5 | }; 6 | -------------------------------------------------------------------------------- /migrations.json: -------------------------------------------------------------------------------- 1 | { 2 | "migrations": [ 3 | { 4 | "cli": "nx", 5 | "version": "18.0.0-beta.2", 6 | "description": "Updates nx.json to disabled adding plugins when generating projects in an existing Nx workspace", 7 | "implementation": "./src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces", 8 | "x-repair-skip": true, 9 | "package": "nx", 10 | "name": "18.0.0-disable-adding-plugins-for-existing-workspaces" 11 | }, 12 | { 13 | "version": "18.1.0-beta.3", 14 | "description": "Moves affected.defaultBase to defaultBase in `nx.json`", 15 | "implementation": "./src/migrations/update-17-2-0/move-default-base", 16 | "package": "nx", 17 | "name": "move-default-base-to-nx-json-root" 18 | }, 19 | { 20 | "cli": "nx", 21 | "version": "19.2.0-beta.2", 22 | "description": "Updates the default workspace data directory to .nx/workspace-data", 23 | "implementation": "./src/migrations/update-19-2-0/move-workspace-data-directory", 24 | "package": "nx", 25 | "name": "19-2-0-move-graph-cache-directory" 26 | }, 27 | { 28 | "cli": "nx", 29 | "version": "19.2.2-beta.0", 30 | "description": "Updates the nx wrapper.", 31 | "implementation": "./src/migrations/update-17-3-0/update-nxw", 32 | "package": "nx", 33 | "name": "19-2-2-update-nx-wrapper" 34 | }, 35 | { 36 | "version": "19.2.4-beta.0", 37 | "description": "Set project name in nx.json explicitly", 38 | "implementation": "./src/migrations/update-19-2-4/set-project-name", 39 | "x-repair-skip": true, 40 | "package": "nx", 41 | "name": "19-2-4-set-project-name" 42 | }, 43 | { 44 | "cli": "nx", 45 | "version": "19.1.0-beta.6", 46 | "description": "Migrate no-extra-semi rules into user config, out of nx extendable configs", 47 | "implementation": "./src/migrations/update-19-1-0-migrate-no-extra-semi/migrate-no-extra-semi", 48 | "package": "@nx/eslint-plugin", 49 | "name": "update-19-1-0-rename-no-extra-semi" 50 | } 51 | ] 52 | } -------------------------------------------------------------------------------- /nx.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "nx/presets/core.json", 3 | "$schema": "./node_modules/nx/schemas/nx-schema.json", 4 | "namedInputs": { 5 | "default": ["{projectRoot}/**/*", "sharedGlobals"], 6 | "sharedGlobals": [], 7 | "production": [ 8 | "default", 9 | "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)", 10 | "!{projectRoot}/tsconfig.spec.json", 11 | "!{projectRoot}/jest.config.[jt]s", 12 | "!{projectRoot}/.eslintrc.json", 13 | "!{projectRoot}/src/test-setup.[jt]s" 14 | ] 15 | }, 16 | "targetDefaults": { 17 | "build": { 18 | "dependsOn": ["^build"], 19 | "inputs": ["production", "^production"], 20 | "cache": true 21 | }, 22 | "@nx/jest:jest": { 23 | "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"], 24 | "cache": true, 25 | "options": { 26 | "passWithNoTests": true 27 | }, 28 | "configurations": { 29 | "ci": { 30 | "ci": true, 31 | "codeCoverage": true 32 | } 33 | } 34 | }, 35 | "@nx/eslint:lint": { 36 | "inputs": ["default", "{workspaceRoot}/.eslintrc.json"], 37 | "cache": true 38 | } 39 | }, 40 | "pluginsConfig": { 41 | "@nx/js": { 42 | "analyzeSourceFiles": true 43 | } 44 | }, 45 | "useInferencePlugins": false, 46 | "defaultBase": "main" 47 | } 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "digitalocean-js-source", 3 | "version": "2.1.2", 4 | "description": "JavaScript library for the DigitalOcean API", 5 | "private": false, 6 | "repository": "https://github.com/johnbwoodruff/digitalocean-js", 7 | "license": "MIT", 8 | "author": { 9 | "name": "John Woodruff", 10 | "email": "johnwoodruff91@gmail.com" 11 | }, 12 | "keywords": [ 13 | "digitalocean", 14 | "api", 15 | "droplet", 16 | "droplets", 17 | "client", 18 | "typescript" 19 | ], 20 | "scripts": {}, 21 | "dependencies": { 22 | "axios": "^1.1.3", 23 | "tslib": "^2.3.0" 24 | }, 25 | "devDependencies": { 26 | "@types/jest": "29.4.4", 27 | "@types/node": "18.19.9", 28 | "@typescript-eslint/eslint-plugin": "7.9.0", 29 | "@typescript-eslint/parser": "7.9.0", 30 | "axios-mock-adapter": "^1.21.2", 31 | "eslint": "8.57.0", 32 | "eslint-config-prettier": "9.1.0", 33 | "gh-pages": "^4.0.0", 34 | "jest": "29.4.3", 35 | "jest-environment-jsdom": "29.4.3", 36 | "nock": "^13.2.9", 37 | "nx": "19.4.2", 38 | "prettier": "2.7.1", 39 | "ts-jest": "29.1.5", 40 | "ts-node": "10.9.1", 41 | "typedoc": "^0.23.17", 42 | "typescript": "5.4.5", 43 | "@nx/workspace": "19.4.2", 44 | "@nx/js": "19.4.2", 45 | "@nx/eslint-plugin": "19.4.2", 46 | "@nx/jest": "19.4.2", 47 | "@nx/eslint": "19.4.2" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnbwoodruff/digitalocean-js/7d944d351d6efe63db80bcba0e229e7f0eae5c32/packages/.gitkeep -------------------------------------------------------------------------------- /packages/digitalocean-js/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../../.eslintrc.json" 4 | ], 5 | "ignorePatterns": [ 6 | "!**/*", 7 | "node_modules/**/*" 8 | ], 9 | "overrides": [ 10 | { 11 | "files": [ 12 | "*.ts", 13 | "*.tsx", 14 | "*.js", 15 | "*.jsx" 16 | ], 17 | "excludedFiles": [ 18 | "node_modules/**/*" 19 | ], 20 | "rules": { 21 | "@typescript-eslint/no-non-null-assertion": "off", 22 | "@typescript-eslint/no-explicit-any": "off" 23 | } 24 | }, 25 | { 26 | "files": [ 27 | "*.ts", 28 | "*.tsx" 29 | ], 30 | "excludedFiles": [ 31 | "node_modules/**/*" 32 | ], 33 | "rules": {} 34 | }, 35 | { 36 | "files": [ 37 | "*.js", 38 | "*.jsx" 39 | ], 40 | "excludedFiles": [ 41 | "node_modules/**/*" 42 | ], 43 | "rules": {} 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /packages/digitalocean-js/README.md: -------------------------------------------------------------------------------- 1 | ![digitalocean-js](https://user-images.githubusercontent.com/5883616/126348407-dd1e694d-64a9-402e-b8df-f59e67686014.png) 2 | 3 | # DigitalOcean JS 4 | 5 | [![CI](https://github.com/johnbwoodruff/digitalocean-js/actions/workflows/main.yml/badge.svg)](https://github.com/johnbwoodruff/digitalocean-js/actions/workflows/main.yml) [![npm](https://img.shields.io/npm/dm/digitalocean-js.svg)](https://www.npmjs.com/package/digitalocean-js) [![npm](https://img.shields.io/npm/dt/digitalocean-js.svg)](https://www.npmjs.com/package/digitalocean-js) [![npm](https://img.shields.io/npm/v/digitalocean-js.svg)](https://www.npmjs.com/package/digitalocean-js) 6 | 7 | JavaScript library for the DigitalOcean API. For use in Node or the browser. 8 | 9 | ## Goals 10 | 11 | This library was built with a few goals in mind: 12 | 13 | - Be able to use in a Node or Browser environment with no difference in usage. 14 | - Use Promises instead of callbacks so clients can make use of `async`/`await`. 15 | - Be built in TypeScript so consumers of the library can benefit from excellent intellisense with the TypeScript definitions. 16 | - Provide solid documentation including examples for usage. 17 | 18 | ## Usage 19 | 20 | To use the library, install from the npm repository. 21 | 22 | ```shell 23 | $ npm install --save digitalocean-js 24 | # Alternatively install with yarn 25 | $ yarn add digitalocean-js 26 | ``` 27 | 28 | Simply import the client and initialize it with your API token: 29 | 30 | ```js 31 | import { DigitalOcean } from 'digitalocean-js'; 32 | 33 | const client = new DigitalOcean('my-api-token'); 34 | ``` 35 | 36 | To see all the services available, check out the [documentation](https://johnbwoodruff.github.io/digitalocean-js/). 37 | -------------------------------------------------------------------------------- /packages/digitalocean-js/jest.config.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | export default { 3 | displayName: 'digitalocean-js', 4 | preset: '../../jest.preset.js', 5 | globals: {}, 6 | transform: { 7 | '^.+\\.[tj]s$': [ 8 | 'ts-jest', 9 | { 10 | tsconfig: '/tsconfig.spec.json' 11 | } 12 | ] 13 | }, 14 | moduleFileExtensions: ['ts', 'js', 'html'], 15 | coverageDirectory: '../../coverage/packages/digitalocean-js' 16 | }; 17 | -------------------------------------------------------------------------------- /packages/digitalocean-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "digitalocean-js", 3 | "version": "2.1.2", 4 | "description": "JavaScript library for the DigitalOcean API", 5 | "private": false, 6 | "repository": "https://github.com/johnbwoodruff/digitalocean-js", 7 | "license": "MIT", 8 | "author": { 9 | "name": "John Woodruff", 10 | "email": "johnwoodruff91@gmail.com" 11 | }, 12 | "keywords": [ 13 | "digitalocean", 14 | "api", 15 | "droplet", 16 | "droplets", 17 | "client", 18 | "typescript" 19 | ], 20 | "dependencies": { 21 | "axios": "^0.24.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/digitalocean-js/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "digitalocean-js", 3 | "$schema": "../../node_modules/nx/schemas/project-schema.json", 4 | "sourceRoot": "packages/digitalocean-js/src", 5 | "projectType": "library", 6 | "targets": { 7 | "build": { 8 | "executor": "@nx/js:tsc", 9 | "outputs": ["{options.outputPath}"], 10 | "options": { 11 | "outputPath": "dist/packages/digitalocean-js", 12 | "main": "packages/digitalocean-js/src/index.ts", 13 | "tsConfig": "packages/digitalocean-js/tsconfig.lib.json", 14 | "assets": ["packages/digitalocean-js/*.md"] 15 | } 16 | }, 17 | "lint": { 18 | "executor": "@nx/eslint:lint", 19 | "outputs": ["{options.outputFile}"] 20 | }, 21 | "test": { 22 | "executor": "@nx/jest:jest", 23 | "outputs": ["{workspaceRoot}/coverage/packages/digitalocean-js"], 24 | "options": { 25 | "jestConfig": "packages/digitalocean-js/jest.config.ts" 26 | } 27 | }, 28 | "publish": { 29 | "executor": "nx:run-commands", 30 | "outputs": [], 31 | "options": { 32 | "command": "npm publish --tag=latest --access public", 33 | "cwd": "dist/packages/digitalocean-js" 34 | } 35 | }, 36 | "publish:beta": { 37 | "executor": "nx:run-commands", 38 | "outputs": [], 39 | "options": { 40 | "command": "npm publish --tag=beta --access public", 41 | "cwd": "dist/packages/digitalocean-js" 42 | } 43 | }, 44 | "docs": { 45 | "executor": "nx:run-commands", 46 | "outputs": [], 47 | "options": { 48 | "commands": [ 49 | "typedoc --options typedoc.json", 50 | "gh-pages -d dist/docs/digitalocean-js" 51 | ], 52 | "parallel": false 53 | } 54 | } 55 | }, 56 | "tags": [] 57 | } 58 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './lib/digitalocean'; 2 | export * from './lib/models/index'; 3 | export * from './lib/services/index'; 4 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/axios-instance.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | /** 4 | * Internal axios instance for configs local to library 5 | * 6 | * @ignore 7 | */ 8 | export const instance = axios.create(); 9 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/conf/environment.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Base URL for DigitalOcean API v2 3 | * 4 | * @ignore 5 | */ 6 | export const API_BASE_URL = 'https://api.digitalocean.com/v2'; 7 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/digitalocean.spec.ts: -------------------------------------------------------------------------------- 1 | import { DigitalOcean } from './digitalocean'; 2 | 3 | describe('DigitalOcean Client', () => { 4 | let client: DigitalOcean; 5 | 6 | beforeEach(() => { 7 | client = new DigitalOcean('abc123'); 8 | }); 9 | 10 | it('should exist', () => { 11 | expect(client).toBeDefined(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/digitalocean.ts: -------------------------------------------------------------------------------- 1 | import { instance } from './axios-instance'; 2 | import { API_BASE_URL } from './conf/environment'; 3 | import { AccountService } from './services/account/account.service'; 4 | import { ActionService } from './services/actions/actions.service'; 5 | import { BillingHistoryService } from './services/billing-history/billing-history.service'; 6 | import { BlockStorageActionService } from './services/block-storage/block-storage-actions.service'; 7 | import { BlockStorageService } from './services/block-storage/block-storage.service'; 8 | import { CdnService } from './services/cdn/cdn.service'; 9 | import { CertificateService } from './services/certificate/certificate.service'; 10 | import { DomainRecordService } from './services/domain/domain-record.service'; 11 | import { DomainService } from './services/domain/domain.service'; 12 | import { DropletActionService } from './services/droplet/droplet-actions.service'; 13 | import { DropletService } from './services/droplet/droplet.service'; 14 | import { FirewallService } from './services/firewall/firewall.service'; 15 | import { FloatingIPActionService } from './services/floating-ip/floating-ip-actions.service'; 16 | import { FloatingIPService } from './services/floating-ip/floating-ip.service'; 17 | import { ImageActionService } from './services/image/image-actions.service'; 18 | import { ImageService } from './services/image/image.service'; 19 | import { KubernetesService } from './services/kubernetes/kubernetes.service'; 20 | import { LoadBalancerService } from './services/load-balancer/load-balancer.service'; 21 | import { ProjectService } from './services/project/project.service'; 22 | import { RegionService } from './services/region/region.service'; 23 | import { SizeService } from './services/size/size.service'; 24 | import { SnapshotService } from './services/snapshot/snapshot.service'; 25 | import { SshService } from './services/ssh/ssh.service'; 26 | import { TagService } from './services/tag/tag.service'; 27 | 28 | export class DigitalOcean { 29 | public account: AccountService; 30 | public actions: ActionService; 31 | public billingHistory: BillingHistoryService; 32 | public blockStorage: BlockStorageService; 33 | public blockStorageActions: BlockStorageActionService; 34 | public cdn: CdnService; 35 | public certificates: CertificateService; 36 | public domains: DomainService; 37 | public domainRecords: DomainRecordService; 38 | public droplets: DropletService; 39 | public dropletActions: DropletActionService; 40 | public firewalls: FirewallService; 41 | public floatingIPs: FloatingIPService; 42 | public floatingIPActions: FloatingIPActionService; 43 | public images: ImageService; 44 | public imageActions: ImageActionService; 45 | public kubernetes: KubernetesService; 46 | public loadBalancers: LoadBalancerService; 47 | public projects: ProjectService; 48 | public regions: RegionService; 49 | public sizes: SizeService; 50 | public snapshots: SnapshotService; 51 | public ssh: SshService; 52 | public tags: TagService; 53 | 54 | constructor(private token: string, url = API_BASE_URL) { 55 | instance.defaults.headers.common['Authorization'] = `Bearer ${this.token}`; 56 | instance.defaults.headers.common['Content-Type'] = `application/json`; 57 | instance.defaults.baseURL = url; 58 | 59 | this.account = new AccountService(); 60 | this.actions = new ActionService(); 61 | this.billingHistory = new BillingHistoryService(); 62 | this.blockStorage = new BlockStorageService(); 63 | this.blockStorageActions = new BlockStorageActionService(); 64 | this.cdn = new CdnService(); 65 | this.certificates = new CertificateService(); 66 | this.domains = new DomainService(); 67 | this.domainRecords = new DomainRecordService(); 68 | this.droplets = new DropletService(); 69 | this.dropletActions = new DropletActionService(); 70 | this.firewalls = new FirewallService(); 71 | this.floatingIPs = new FloatingIPService(); 72 | this.floatingIPActions = new FloatingIPActionService(); 73 | this.images = new ImageService(); 74 | this.imageActions = new ImageActionService(); 75 | this.kubernetes = new KubernetesService(); 76 | this.loadBalancers = new LoadBalancerService(); 77 | this.projects = new ProjectService(); 78 | this.regions = new RegionService(); 79 | this.sizes = new SizeService(); 80 | this.snapshots = new SnapshotService(); 81 | this.ssh = new SshService(); 82 | this.tags = new TagService(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/account.ts: -------------------------------------------------------------------------------- 1 | export interface Account { 2 | droplet_limit: number; 3 | floating_ip_limit: number; 4 | email: string; 5 | uuid: string; 6 | email_verified: boolean; 7 | status: string; 8 | status_message: string; 9 | } 10 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/action.ts: -------------------------------------------------------------------------------- 1 | import { Region } from './region'; 2 | 3 | export interface Action { 4 | id: number; 5 | status: string; 6 | type: string; 7 | started_at: string; 8 | completed_at: string; 9 | resource_id: number; 10 | resource_type: string; 11 | region?: Region | string | null; 12 | region_slug?: string | null; 13 | } 14 | 15 | export type ActionType = 'attach' | 'detach' | 'resize'; 16 | 17 | export interface ActionRequest { 18 | type: ActionType; 19 | region: string; 20 | droplet_id?: number; 21 | size_gigabytes?: number; 22 | volume_name?: string; 23 | } 24 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/backup.ts: -------------------------------------------------------------------------------- 1 | export interface Backup { 2 | id: number; 3 | name: string; 4 | type: string; 5 | distribution: string; 6 | slug: string | null; 7 | public: boolean; 8 | regions: string[]; 9 | min_disk_size: number; 10 | created_at: string; 11 | } 12 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/balance.ts: -------------------------------------------------------------------------------- 1 | export interface Balance { 2 | month_to_date_balance: string; 3 | account_balance: string; 4 | month_to_date_usage: string; 5 | generated_at: string; 6 | } 7 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/billing-history.ts: -------------------------------------------------------------------------------- 1 | export interface BillingHistory { 2 | description: string; 3 | amount: string; 4 | invoice_id?: string; 5 | invoice_uuid?: string; 6 | date: string; 7 | type: string; 8 | } 9 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/block-storage.ts: -------------------------------------------------------------------------------- 1 | import { Region } from './region'; 2 | 3 | export interface BlockStorage { 4 | id: string; 5 | region: Region; 6 | droplet_ids: number[]; 7 | name: string; 8 | description: string; 9 | size_gigabytes: number; 10 | filesystem_type: string; 11 | filesystem_label: string; 12 | created_at: string; 13 | tags: string[]; 14 | } 15 | 16 | export interface BlockStorageRequest { 17 | size_gigabytes: number; 18 | name: string; 19 | description?: string; 20 | region?: string; 21 | snapshot_id?: string; 22 | } 23 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/cdn.ts: -------------------------------------------------------------------------------- 1 | export interface CdnEndpoint { 2 | id: string; 3 | origin: string; 4 | endpoint: string; 5 | created_at: string; 6 | ttl: number; 7 | certificate_id?: string; 8 | custom_domain?: string; 9 | } 10 | 11 | export interface CdnEndpointRequest { 12 | origin?: string; 13 | ttl?: number; 14 | } 15 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/certificate.ts: -------------------------------------------------------------------------------- 1 | export type CertificateType = 'custom' | 'lets_encrypt'; 2 | 3 | export interface Certificate { 4 | id: string; 5 | name: string; 6 | not_after: string; 7 | sha1_fingerprint: string; 8 | created_at: string; 9 | dns_names: string[]; 10 | state: string; 11 | type: CertificateType; 12 | } 13 | 14 | export interface CertificateRequest { 15 | name: string; 16 | private_key: string; 17 | leaf_certificate: string; 18 | certificate_chain?: string; 19 | dns_names: string[]; 20 | type: CertificateType; 21 | } 22 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/domain-record.ts: -------------------------------------------------------------------------------- 1 | export interface DomainRecord { 2 | id: number; 3 | type: string; 4 | name: string; 5 | data: string; 6 | prority?: number | null; 7 | port?: number | null; 8 | ttl: number; 9 | weight: number | null; 10 | } 11 | 12 | export type DomainRecordTypes = 13 | | 'A' 14 | | 'AAAA' 15 | | 'CNAME' 16 | | 'MX' 17 | | 'TXT' 18 | | 'NS' 19 | | 'SRV'; 20 | 21 | export interface DomainRecordRequest { 22 | id?: number; 23 | type?: DomainRecordTypes; 24 | name?: string; 25 | data?: string; 26 | priority?: number | null; 27 | port?: number | null; 28 | ttl?: number; 29 | weight?: number | null; 30 | } 31 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/domain.ts: -------------------------------------------------------------------------------- 1 | export interface Domain { 2 | name: string; 3 | ttl: number; 4 | zone_file: string; 5 | } 6 | 7 | export interface DomainRequest { 8 | name: string; 9 | ip_address: string; 10 | } 11 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/droplet.ts: -------------------------------------------------------------------------------- 1 | import { Image } from './image'; 2 | import { Kernel } from './kernel'; 3 | import { Networks } from './networks'; 4 | import { Region } from './region'; 5 | import { Size } from './size'; 6 | 7 | export interface Droplet { 8 | id: number; 9 | name: string; 10 | memory: number; 11 | vcpus: number; 12 | disk: number; 13 | locked: boolean; 14 | created_at: string; 15 | status: string; 16 | backup_ids: string[]; 17 | snapshot_ids: string[]; 18 | features: string[]; 19 | region: Region; 20 | image: Image | null; 21 | size: Size | null; 22 | size_slug: string; 23 | networks: Networks | null; 24 | kernel: Kernel | null; 25 | next_backup_window: unknown; 26 | tags: string[]; 27 | volume_ids: string[]; 28 | } 29 | 30 | export interface DropletRequest { 31 | name?: string; 32 | names?: string[]; 33 | region: string; 34 | size: string; 35 | image: number | string; 36 | ssh_keys?: unknown[]; 37 | backups?: boolean; 38 | ipv6?: boolean; 39 | private_networking?: boolean; 40 | user_data?: string; 41 | monitoring?: boolean; 42 | volumes?: unknown[]; 43 | tags?: string[]; 44 | } 45 | 46 | export interface DropletActionRequest { 47 | type: string; 48 | image?: string | number; 49 | disk?: boolean; 50 | size?: string; 51 | name?: string; 52 | kernel?: number; 53 | } 54 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/firewall.ts: -------------------------------------------------------------------------------- 1 | export interface Firewall { 2 | id?: string; 3 | status?: string; 4 | created_at?: string; 5 | pending_changes?: FirewallChange[]; 6 | name: string; 7 | inbound_rules: FirewallInboundRule[]; 8 | outbound_rules: FirewallOutboundRule[]; 9 | droplet_ids: number[]; 10 | tags: string[]; 11 | } 12 | 13 | export interface FirewallChange { 14 | droplet_id: string; 15 | removing: string; 16 | status: string; 17 | } 18 | 19 | export interface FirewallInboundRule { 20 | protocol: string; 21 | ports: string; 22 | sources: FirewallSourceDestination; 23 | } 24 | 25 | export interface FirewallOutboundRule { 26 | protocol: string; 27 | ports: string; 28 | destinations: FirewallSourceDestination; 29 | } 30 | 31 | export interface FirewallSourceDestination { 32 | addresses: string[]; 33 | droplet_ids: number[]; 34 | load_balancer_uids: string[]; 35 | tags: string[]; 36 | } 37 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/floating-ip.ts: -------------------------------------------------------------------------------- 1 | import { Droplet } from './droplet'; 2 | import { Region } from './region'; 3 | 4 | export interface FloatingIP { 5 | ip: string; 6 | region: Region; 7 | droplet: Droplet; 8 | } 9 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/image.ts: -------------------------------------------------------------------------------- 1 | export interface Image { 2 | id: number; 3 | name: string; 4 | type: string; 5 | distribution: string; 6 | slug: string | null; 7 | public: boolean; 8 | regions: string[]; 9 | min_disk_size: number; 10 | size_gigabytes: number; 11 | created_at: string; 12 | description: string; 13 | } 14 | 15 | export interface ImageActionRequest { 16 | type: string; 17 | region?: string; 18 | } 19 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './account'; 2 | export * from './action'; 3 | export * from './backup'; 4 | export * from './balance'; 5 | export * from './billing-history'; 6 | export * from './block-storage'; 7 | export * from './cdn'; 8 | export * from './certificate'; 9 | export * from './domain'; 10 | export * from './domain-record'; 11 | export * from './droplet'; 12 | export * from './firewall'; 13 | export * from './floating-ip'; 14 | export * from './image'; 15 | export * from './kernel'; 16 | export * from './kubernetes-cluster'; 17 | export * from './load-balancer'; 18 | export * from './network'; 19 | export * from './networks'; 20 | export * from './project'; 21 | export * from './region'; 22 | export * from './size'; 23 | export * from './snapshot'; 24 | export * from './ssh-key'; 25 | export * from './tag'; 26 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/kernel.ts: -------------------------------------------------------------------------------- 1 | export interface Kernel { 2 | id: number; 3 | name: string; 4 | version: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/kubernetes-cluster.ts: -------------------------------------------------------------------------------- 1 | export interface KubernetesCluster { 2 | id: string; 3 | name: string; 4 | endpoint: string; 5 | region: string; 6 | version: string; 7 | auto_upgrade: boolean; 8 | ipv4: string; 9 | cluster_subnet: string; 10 | service_subnet: string; 11 | tags: string[]; 12 | maintenance_policy: KubernetesClusterMaintenancePolicy; 13 | node_pools: KubernetesWorkerNodePool[]; 14 | created_at: string; 15 | updated_at: string; 16 | status: KubernetesClusterState; 17 | } 18 | 19 | export interface KubernetesClusterMaintenancePolicy { 20 | start_time: string; 21 | duration?: string; 22 | day: string; 23 | } 24 | 25 | export interface KubernetesWorkerNodePool { 26 | id?: string; 27 | size: string; 28 | name: string; 29 | count: number; 30 | tags?: string[]; 31 | auto_scale?: boolean; 32 | nodes?: KubernetesWorkerNode; 33 | min_nodes?: string; 34 | max_nodes?: string; 35 | } 36 | 37 | export interface KubernetesWorkerNode { 38 | id?: string; 39 | name: string; 40 | status?: KubernetesClusterState; 41 | created_at?: string; 42 | updated_at?: string; 43 | } 44 | 45 | export interface KubernetesClusterState { 46 | state: 'running' | 'provisioning' | 'errored'; 47 | } 48 | 49 | export interface KubernetesClusterRequest { 50 | name: string; 51 | region: string; 52 | version: string; 53 | auto_upgrade?: boolean; 54 | tags?: string[]; 55 | maintenance_policy?: KubernetesClusterMaintenancePolicy; 56 | node_pools: KubernetesWorkerNodePool; 57 | } 58 | 59 | export interface KubernetesVersion { 60 | slug: string; 61 | kubernetes_version: string; 62 | } 63 | 64 | export interface KubernetesRegion { 65 | name: string; 66 | slug: string; 67 | } 68 | 69 | export interface KubernetesSize { 70 | name: string; 71 | slug: string; 72 | } 73 | 74 | export interface KubernetesOptions { 75 | regions: KubernetesRegion[]; 76 | versions: KubernetesVersion[]; 77 | sizes: KubernetesSize[]; 78 | } 79 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/load-balancer.ts: -------------------------------------------------------------------------------- 1 | import { Region } from './region'; 2 | 3 | export interface LoadBalancer { 4 | id: string; 5 | name: string; 6 | ip: string; 7 | algorithm: 'round_robin' | 'least_connections'; 8 | status: 'new' | 'active' | 'errored'; 9 | created_at: string; 10 | forwarding_rules: ForwardingRule[]; 11 | health_check: HealthCheck; 12 | sticky_sessions: StickySession; 13 | region: string | Region; 14 | tag: string; 15 | droplet_ids: number[]; 16 | redirect_http_to_https: boolean; 17 | } 18 | 19 | export interface ForwardingRule { 20 | entry_protocol: 'http' | 'https' | 'http2' | 'tcp'; 21 | entry_port: number; 22 | target_protocol: 'http' | 'https' | 'http2' | 'tcp'; 23 | target_port: number; 24 | certificate_id: string; 25 | tls_passthrough: boolean; 26 | } 27 | 28 | export interface HealthCheck { 29 | protocol: 'http' | 'tcp'; 30 | port: number; 31 | path: string; 32 | check_interval_seconds: number; 33 | response_timeout_seconds: number; 34 | unhealthy_threshold: number; 35 | healthy_threshold: number; 36 | } 37 | 38 | export interface StickySession { 39 | type: 'cookies' | 'none'; 40 | cookie_name: string; 41 | cookie_ttl_seconds: string; 42 | } 43 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/network.ts: -------------------------------------------------------------------------------- 1 | export interface Network { 2 | ip_address: string; 3 | netmask: string; 4 | gateway: string; 5 | type: string; 6 | } 7 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/networks.ts: -------------------------------------------------------------------------------- 1 | import { Network } from './network'; 2 | 3 | export interface Networks { 4 | v4: Network[]; 5 | v6: Network[]; 6 | } 7 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/project.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Various project purpose strings in enum form 3 | * 4 | * You can use as follows: 5 | * 6 | * ```js 7 | * import { ProjectPurpose } from 'digitalocean-js; 8 | * 9 | * console.log(ProjectPurpose.Website); // Prints "Website or blog" 10 | * ``` 11 | */ 12 | export enum ProjectPurpose { 13 | Trying = 'Just trying out DigitalOcean', 14 | Educational = 'Class project / Educational purposes', 15 | Website = 'Website or blog', 16 | WebApp = 'Web Application', 17 | Api = 'Service or API', 18 | Mobile = 'Mobile Application', 19 | MachineLearning = 'Machine learning / AI / Data processing', 20 | IoT = 'IoT', 21 | DevTooling = 'Operational / Developer tooling' 22 | } 23 | 24 | export type ProjectEnvironment = 'Development' | 'Staging' | 'Production'; 25 | 26 | export interface Project { 27 | id?: string; 28 | owner_uuid?: string; 29 | owner_id?: number; 30 | name?: string; 31 | description?: string; 32 | purpose?: string; 33 | environment?: ProjectEnvironment; 34 | is_default?: boolean; 35 | created_at?: string; 36 | updated_at?: string; 37 | } 38 | 39 | export type ProjectResourceStatus = 40 | | 'ok' 41 | | 'not_found' 42 | | 'assigned' 43 | | 'already_assigned' 44 | | 'service_down'; 45 | 46 | export interface ProjectResource { 47 | urn: string; 48 | assigned_at: string; 49 | links: string; 50 | status: ProjectResourceStatus; 51 | } 52 | 53 | /** 54 | * The structure of a parsed Project Resource URN 55 | */ 56 | export interface ProjectResourceParsedUrn { 57 | id: string; 58 | type: string; 59 | } 60 | 61 | /** 62 | * Defines the resource type keys 63 | */ 64 | export enum RESOURCE_TYPE { 65 | DATABASE = 'dbaas', 66 | DOMAIN = 'domain', 67 | DROPLET = 'droplet', 68 | FLOATING_IP = 'floatingip', 69 | KUBERNETES_CLUSTER = 'kubernetes', 70 | LOAD_BALANCER = 'loadbalancer', 71 | SPACE = 'space', 72 | VOLUME = 'volume' 73 | } 74 | 75 | /** 76 | * Defines the resource prefixes for various resource types 77 | */ 78 | export enum RESOURCE_PREFIX { 79 | DATABASE = 'do:dbaas:', 80 | DOMAIN = 'do:domain:', 81 | DROPLET = 'do:droplet:', 82 | FLOATING_IP = 'do:floatingip:', 83 | KUBERNETES_CLUSTER = 'do:kubernetes:', 84 | LOAD_BALANCER = 'do:loadbalancer:', 85 | SPACE = 'do:space:', 86 | VOLUME = 'do:volume:' 87 | } 88 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/region.ts: -------------------------------------------------------------------------------- 1 | export interface Region { 2 | slug: string; 3 | name: string; 4 | sizes: string[]; 5 | available: boolean; 6 | features: string[]; 7 | } 8 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/size.ts: -------------------------------------------------------------------------------- 1 | export interface Size { 2 | slug: string; 3 | available: boolean; 4 | transfer: number; 5 | price_monthly: number; 6 | price_hourly: number; 7 | memory: number; 8 | vcpus: number; 9 | disk: number; 10 | regions: string[]; 11 | description: string; 12 | } 13 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/snapshot.ts: -------------------------------------------------------------------------------- 1 | export interface Snapshot { 2 | id: string; 3 | name: string; 4 | created_at: string; 5 | regions: string[]; 6 | resource_id: string; 7 | resource_type: string; 8 | min_disk_size: number; 9 | size_gigabytes: number; 10 | } 11 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/ssh-key.ts: -------------------------------------------------------------------------------- 1 | export interface SshKey { 2 | id?: number; 3 | fingerprint?: string; 4 | public_key: string; 5 | name: string; 6 | } 7 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/models/tag.ts: -------------------------------------------------------------------------------- 1 | import { Droplet } from './droplet'; 2 | 3 | export interface Tag { 4 | name: string; 5 | resources?: { 6 | droplets?: { 7 | count?: number; 8 | last_tagged?: Droplet; 9 | }; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/account/account.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError } from 'axios'; 2 | import MockAdapter from 'axios-mock-adapter'; 3 | 4 | import { getErrorResponse, getSingleAccount } from '../../../test'; 5 | import { instance } from '../../axios-instance'; 6 | import { DigitalOcean } from '../../digitalocean'; 7 | 8 | const mock = new MockAdapter(instance, { onNoMatch: 'throwException' }); 9 | const client = new DigitalOcean('abc123'); 10 | 11 | describe('Account Service', () => { 12 | it('should exist', () => { 13 | expect(client.account).toBeDefined(); 14 | }); 15 | 16 | describe('getUserInformation', () => { 17 | it('should resolve correctly', async () => { 18 | const account = getSingleAccount(); 19 | mock.onGet('/account').reply(200, { account }); 20 | 21 | const user = await client.account.getUserInformation(); 22 | expect(user).toEqual(account); 23 | }); 24 | 25 | it('should reject on failure', async () => { 26 | const error = getErrorResponse(); 27 | mock.onGet('/account').reply(400, error); 28 | 29 | try { 30 | await client.account.getUserInformation(); 31 | } catch (e) { 32 | expect((e as AxiosError).response?.data).toEqual(error); 33 | } 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/account/account.service.ts: -------------------------------------------------------------------------------- 1 | import { instance } from '../../axios-instance'; 2 | 3 | import { Account } from '../../models'; 4 | 5 | export class AccountService { 6 | /** 7 | * Get the account information associated with the provided credentials 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const account = await client.account.getUserInformation(); 15 | * ``` 16 | */ 17 | public async getUserInformation(): Promise { 18 | return instance.get('/account').then(response => response.data.account); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/actions/actions.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError } from 'axios'; 2 | import MockAdapter from 'axios-mock-adapter'; 3 | 4 | import { getActions, getErrorResponse, getSingleAction } from '../../../test'; 5 | import { instance } from '../../axios-instance'; 6 | import { DigitalOcean } from '../../digitalocean'; 7 | 8 | const mock = new MockAdapter(instance, { onNoMatch: 'throwException' }); 9 | const client = new DigitalOcean('abc123'); 10 | 11 | describe('Actions Service', () => { 12 | it('should exist', () => { 13 | expect(client.actions).toBeDefined(); 14 | }); 15 | 16 | describe('getAllActions', () => { 17 | it('should resolve correctly', async () => { 18 | const actions = getActions(); 19 | mock 20 | .onGet('/actions', { params: { page: 1, per_page: 25 } }) 21 | .reply(200, { actions }); 22 | 23 | const allActions = await client.actions.getAllActions(); 24 | expect(allActions.length).toEqual(2); 25 | }); 26 | 27 | it('should resolve correctly with passed pagination', async () => { 28 | const actions = getActions(); 29 | mock 30 | .onGet('/actions', { params: { page: 2, per_page: 50 } }) 31 | .reply(200, { actions }); 32 | 33 | const allActions = await client.actions.getAllActions(50, 2); 34 | expect(allActions.length).toEqual(2); 35 | }); 36 | 37 | it('should reject on failure', async () => { 38 | const error = getErrorResponse(); 39 | mock.onGet('/actions').reply(400, error); 40 | 41 | try { 42 | await client.actions.getAllActions(); 43 | } catch (e) { 44 | expect((e as AxiosError).response?.data).toEqual(error); 45 | } 46 | }); 47 | }); 48 | 49 | describe('getExistingAction', () => { 50 | it('should resolve correctly', async () => { 51 | const action = getSingleAction(); 52 | mock.onGet(`/actions/${action.id}`).reply(200, { action }); 53 | 54 | const singleAction = await client.actions.getExistingAction(action.id); 55 | expect(singleAction).toEqual(action); 56 | }); 57 | 58 | it('should reject on failure', async () => { 59 | const action = getSingleAction(); 60 | const error = getErrorResponse(); 61 | mock.onGet(`/actions/${action.id}`).reply(400, error); 62 | 63 | try { 64 | await client.actions.getExistingAction(action.id); 65 | } catch (e) { 66 | expect((e as AxiosError).response?.data).toEqual(error); 67 | } 68 | }); 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/actions/actions.service.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class ActionService { 6 | /** 7 | * List all of the actions that have been executed on the current account. 8 | * Limited to 25 actions per page unless otherwise specified. 9 | * 10 | * ### Example 11 | * ```js 12 | * import { DigitalOcean } from 'digitalocean-js'; 13 | * 14 | * const client = new DigitalOcean('your-api-key'); 15 | * const actions = await client.actions.getAllActions(); 16 | * // Paginate actions, 10 per page, starting on page 1 17 | * actions = await client.actions.getAllActions(10, 1); 18 | * ``` 19 | */ 20 | public getAllActions(perPage?: number, page?: number): Promise { 21 | page = page ? page : 1; 22 | perPage = perPage ? perPage : 25; 23 | return instance 24 | .get('/actions', { 25 | params: { 26 | page, 27 | per_page: perPage 28 | } 29 | }) 30 | .then(response => response.data.actions); 31 | } 32 | 33 | /** 34 | * Get an existing account action based on the provided ID 35 | * 36 | * ### Example 37 | * ```js 38 | * import { DigitalOcean } from 'digitalocean-js'; 39 | * 40 | * const client = new DigitalOcean('your-api-key'); 41 | * const action = await client.actions.getExistingAction('specific-action-id'); 42 | * ``` 43 | */ 44 | public getExistingAction(id: number): Promise { 45 | return instance 46 | .get(`/actions/${id}`) 47 | .then(response => response.data.action); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/billing-history/billing-history.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError } from 'axios'; 2 | import MockAdapter from 'axios-mock-adapter'; 3 | 4 | import { getBalance, getBillingHistory, getErrorResponse } from '../../../test'; 5 | import { instance } from '../../axios-instance'; 6 | import { DigitalOcean } from '../../digitalocean'; 7 | 8 | const mock = new MockAdapter(instance, { onNoMatch: 'throwException' }); 9 | const client = new DigitalOcean('abc123'); 10 | 11 | describe('Billing History Service', () => { 12 | it('should exist', () => { 13 | expect(client.billingHistory).toBeDefined(); 14 | }); 15 | 16 | describe('getMyBalance', () => { 17 | it('should resolve correctly', async () => { 18 | const balance = getBalance(); 19 | mock.onGet('/customers/my/balance').reply(200, balance); 20 | 21 | const myBalance = await client.billingHistory.getMyBalance(); 22 | expect(myBalance).toEqual(balance); 23 | }); 24 | 25 | it('should reject on failure', async () => { 26 | const error = getErrorResponse(); 27 | mock.onGet('/customers/my/balance').reply(400, error); 28 | 29 | try { 30 | await client.billingHistory.getMyBalance(); 31 | } catch (e) { 32 | expect((e as AxiosError).response?.data).toEqual(error); 33 | } 34 | }); 35 | }); 36 | 37 | describe('getMyBillingHistory', () => { 38 | it('should resolve correctly', async () => { 39 | const billingHistory = getBillingHistory(); 40 | mock 41 | .onGet('/customers/my/billing_history') 42 | .reply(200, { billing_history: billingHistory }); 43 | 44 | const myBillingHistory = 45 | await client.billingHistory.getMyBillingHistory(); 46 | expect(myBillingHistory).toEqual(billingHistory); 47 | }); 48 | 49 | it('should reject on failure', async () => { 50 | const error = getErrorResponse(); 51 | mock.onGet('/customers/my/billing_history').reply(400, error); 52 | 53 | try { 54 | await client.billingHistory.getMyBillingHistory(); 55 | } catch (e) { 56 | expect((e as AxiosError).response?.data).toEqual(error); 57 | } 58 | }); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/billing-history/billing-history.service.ts: -------------------------------------------------------------------------------- 1 | import { Balance, BillingHistory } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class BillingHistoryService { 6 | /** 7 | * Retrieve the balances on a customer's account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const balance = await client.billingHistory.getMyBalance(); 15 | * ``` 16 | */ 17 | public getMyBalance(): Promise { 18 | return instance 19 | .get('/customers/my/balance') 20 | .then(response => response.data); 21 | } 22 | 23 | /** 24 | * Retrieve a list of all billing history entries 25 | * 26 | * ### Example 27 | * ```js 28 | * import { DigitalOcean } from 'digitalocean-js'; 29 | * 30 | * const client = new DigitalOcean('your-api-key'); 31 | * const billingHistory = await client.billingHistory.getMyBillingHistory(); 32 | * ``` 33 | */ 34 | public getMyBillingHistory(): Promise { 35 | return instance 36 | .get('/customers/my/billing_history') 37 | .then(response => response.data.billing_history); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/block-storage/block-storage-actions.service.ts: -------------------------------------------------------------------------------- 1 | import { Action, ActionRequest } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class BlockStorageActionService { 6 | /** 7 | * Attach a Block Storage volume to a droplet 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const request = { 15 | * type: 'attach', 16 | * droplet_id: 11612190, 17 | * region: 'nyc1' 18 | * } 19 | * const action = await client.blockStorageActions 20 | * .attachVolumeToDroplet('volume-id', request); 21 | * ``` 22 | */ 23 | public attachVolumeToDroplet( 24 | volumeId: string, 25 | actionRequest: ActionRequest 26 | ): Promise { 27 | if (!this.attachActionIsValid(actionRequest)) { 28 | throw new Error('Required fields missing from Action Object'); 29 | } 30 | return instance 31 | .post(`/volumes/${volumeId}/actions`, actionRequest) 32 | .then(response => response.data.action); 33 | } 34 | 35 | /** 36 | * Attach a Block Storage volume to a droplet using the volume name 37 | * 38 | * ### Example 39 | * ```js 40 | * import { DigitalOcean } from 'digitalocean-js'; 41 | * 42 | * const client = new DigitalOcean('your-api-key'); 43 | * const request = { 44 | * type: 'attach', 45 | * volume_name: 'example', 46 | * region: 'nyc1', 47 | * droplet_id: 116121901 48 | * } 49 | * const action = await client.blockStorageActions 50 | * .attachVolumeToDropletByName(request); 51 | * ``` 52 | */ 53 | public attachVolumeToDropletByName( 54 | actionRequest: ActionRequest 55 | ): Promise { 56 | if (!this.attachActionByNameIsValid(actionRequest)) { 57 | throw new Error('Required fields missing from Action Object'); 58 | } 59 | return instance 60 | .post(`/volumes/actions`, actionRequest) 61 | .then(response => response.data.action); 62 | } 63 | 64 | /** 65 | * Detach a Block Storage volume from a droplet 66 | * 67 | * ### Example 68 | * ```js 69 | * import { DigitalOcean } from 'digitalocean-js'; 70 | * 71 | * const client = new DigitalOcean('your-api-key'); 72 | * const request = { 73 | * type: 'detach', 74 | * droplet_id: 11612190, 75 | * region: 'nyc1' 76 | * } 77 | * const action = await client.blockStorageActions 78 | * .detachVolumeFromDroplet('volume-id', request); 79 | * ``` 80 | */ 81 | public detachVolumeFromDroplet( 82 | volumeId: string, 83 | actionRequest: ActionRequest 84 | ): Promise { 85 | if (!this.attachActionIsValid(actionRequest)) { 86 | throw new Error('Required fields missing from Action Object'); 87 | } 88 | return instance 89 | .post(`/volumes/${volumeId}/actions`, actionRequest) 90 | .then(response => response.data.action); 91 | } 92 | 93 | /** 94 | * Detach a Block Storage volume from a droplet using the volume name 95 | * 96 | * ### Example 97 | * ```js 98 | * import { DigitalOcean } from 'digitalocean-js'; 99 | * 100 | * const client = new DigitalOcean('your-api-key'); 101 | * const request = { 102 | * type: 'detach', 103 | * volume_name: 'example', 104 | * region: 'nyc1', 105 | * droplet_id: 116121901 106 | * } 107 | * const action = await client.blockStorageActions 108 | * .detachVolumeFromDropletByName(request); 109 | * ``` 110 | */ 111 | public detachVolumeFromDropletByName( 112 | actionRequest: ActionRequest 113 | ): Promise { 114 | if (!this.attachActionByNameIsValid(actionRequest)) { 115 | throw new Error('Required fields missing from Action Object'); 116 | } 117 | return instance 118 | .post(`/volumes/actions`, actionRequest) 119 | .then(response => response.data.action); 120 | } 121 | 122 | /** 123 | * Resize a Block Storage volume 124 | * 125 | * ### Example 126 | * ```js 127 | * import { DigitalOcean } from 'digitalocean-js'; 128 | * 129 | * const client = new DigitalOcean('your-api-key'); 130 | * const request = { 131 | * type: 'resize', 132 | * size_gigabytes: 100, 133 | * region: 'nyc1' 134 | * } 135 | * const action = await client.blockStorageActions 136 | * .resizeVolume('volume-id', request); 137 | * ``` 138 | */ 139 | public resizeVolume( 140 | volumeId: string, 141 | actionRequest: ActionRequest 142 | ): Promise { 143 | if (!this.resizeActionIsValid(actionRequest)) { 144 | throw new Error('Required fields missing from Action Object'); 145 | } 146 | return instance 147 | .post(`/volumes/${volumeId}/actions`, actionRequest) 148 | .then(response => response.data.action); 149 | } 150 | 151 | /** 152 | * List all actions that have been executed on the specified volume. 153 | * Limited to 25 actions per page unless otherwise specified. 154 | * 155 | * ### Example 156 | * ```js 157 | * import { DigitalOcean } from 'digitalocean-js'; 158 | * 159 | * const client = new DigitalOcean('your-api-key'); 160 | * const actions = await client.blockStorageActions.getAllVolumeActions('volume-id'); 161 | * // Paginate actions, 10 per page, starting on page 1 162 | * actions = await client.blockStorageActions 163 | * .getAllVolumeActions('volume-id', 10, 1); 164 | * ``` 165 | */ 166 | public getAllVolumeActions( 167 | volumeId: string, 168 | perPage?: number, 169 | page?: number 170 | ): Promise { 171 | page = page ? page : 1; 172 | perPage = perPage ? perPage : 25; 173 | return instance 174 | .get(`/volumes/${volumeId}/actions`, { 175 | params: { 176 | page, 177 | per_page: perPage 178 | } 179 | }) 180 | .then(response => response.data.actions); 181 | } 182 | 183 | /** 184 | * Get an existing volume action based on the provided ID 185 | * 186 | * ### Example 187 | * ```js 188 | * import { DigitalOcean } from 'digitalocean-js'; 189 | * 190 | * const client = new DigitalOcean('your-api-key'); 191 | * const action = await client.blockStorageActions 192 | * .getExistingVolumeAction('volume-id', 'action-id'); 193 | * ``` 194 | */ 195 | public getExistingVolumeAction( 196 | volumeId: string, 197 | actionId: number 198 | ): Promise { 199 | return instance 200 | .get(`/volumes/${volumeId}/actions/${actionId}`) 201 | .then(response => response.data.action); 202 | } 203 | 204 | ////////// Validation Methods ////////// 205 | private attachActionIsValid(action: ActionRequest): boolean { 206 | if (!action.type || !action.droplet_id) { 207 | return false; 208 | } 209 | return true; 210 | } 211 | 212 | private attachActionByNameIsValid(action: ActionRequest): boolean { 213 | if (!this.attachActionIsValid(action) || !action.volume_name) { 214 | return false; 215 | } 216 | return true; 217 | } 218 | 219 | private resizeActionIsValid(action: ActionRequest): boolean { 220 | if (!action.type || !action.size_gigabytes) { 221 | return false; 222 | } 223 | return true; 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/block-storage/block-storage.service.ts: -------------------------------------------------------------------------------- 1 | import { BlockStorage, BlockStorageRequest, Snapshot } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class BlockStorageService { 6 | /** 7 | * List all of the Block Storage volumes available on your account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const volumes = await client.blockStorage.getAllBlockStorage(); 15 | * ``` 16 | */ 17 | public getAllBlockStorage(): Promise { 18 | return instance.get(`/volumes`).then(response => response.data.volumes); 19 | } 20 | 21 | /** 22 | * Create a new Block Storage volume 23 | * 24 | * ### Example 25 | * ```js 26 | * import { DigitalOcean } from 'digitalocean-js'; 27 | * 28 | * const client = new DigitalOcean('your-api-key'); 29 | * const request = { 30 | * size_gigabytes: 10, 31 | * name: 'example', 32 | * description: 'Block store for examples', 33 | * region: 'nyc1' 34 | * }; 35 | * const volume = await client.blockStorage.createBlockStorage(request); 36 | * ``` 37 | */ 38 | public createBlockStorage( 39 | volume: BlockStorageRequest 40 | ): Promise { 41 | if (!this.volumeIsValid(volume)) { 42 | throw new Error('Required fields missing from Block Storage Object'); 43 | } 44 | return instance 45 | .post(`/volumes`, volume) 46 | .then(response => response.data.volume); 47 | } 48 | 49 | /** 50 | * Get a single Block Storage volume by ID 51 | * 52 | * ### Example 53 | * ```js 54 | * import { DigitalOcean } from 'digitalocean-js'; 55 | * 56 | * const client = new DigitalOcean('your-api-key'); 57 | * const volume = await client.blockStorage.getBlockStorageById('volume-id'); 58 | * ``` 59 | */ 60 | public getBlockStorageById(id: string): Promise { 61 | return instance 62 | .get(`/volumes/${id}`) 63 | .then(response => response.data.volume); 64 | } 65 | 66 | /** 67 | * Get Block Storage volumes by name and region 68 | * 69 | * ### Example 70 | * ```js 71 | * import { DigitalOcean } from 'digitalocean-js'; 72 | * 73 | * const client = new DigitalOcean('your-api-key'); 74 | * const volume = await client.blockStorage 75 | * .getBlockStorageByName('volume-name', 'nyc1'); 76 | * ``` 77 | */ 78 | public getBlockStorageByName( 79 | name: string, 80 | regionSlug: string 81 | ): Promise { 82 | return instance 83 | .get(`/volumes`, { params: { name, region: regionSlug } }) 84 | .then(response => response.data.volumes); 85 | } 86 | 87 | /** 88 | * Get snapshots that have been created from a Block Storage volume 89 | * 90 | * ### Example 91 | * ```js 92 | * import { DigitalOcean } from 'digitalocean-js'; 93 | * 94 | * const client = new DigitalOcean('your-api-key'); 95 | * const snapshots = await client.blockStorage 96 | * .getSnapshotsForVolume('volume-id'); 97 | * ``` 98 | */ 99 | public getSnapshotsForVolume(id: string): Promise { 100 | return instance 101 | .get(`/volumes/${id}/snapshots`) 102 | .then(response => response.data.snapshots); 103 | } 104 | 105 | /** 106 | * Create a snapshot from a Block Storage volume 107 | * 108 | * ### Example 109 | * ```js 110 | * import { DigitalOcean } from 'digitalocean-js'; 111 | * 112 | * const client = new DigitalOcean('your-api-key'); 113 | * const snapshot = await client.blockStorage 114 | * .createSnapshotFromVolume('volume-id', 'my-new-snapshot'); 115 | * ``` 116 | */ 117 | public createSnapshotFromVolume(id: string, name: string): Promise { 118 | return instance 119 | .post(`/volumes/${id}/snapshots`, { name }) 120 | .then(response => response.data.snapshot); 121 | } 122 | 123 | /** 124 | * Delete a Block Storage volume by ID 125 | * 126 | * ### Example 127 | * ```js 128 | * import { DigitalOcean } from 'digitalocean-js'; 129 | * 130 | * const client = new DigitalOcean('your-api-key'); 131 | * await client.blockStorage.deleteBlockStorageById('volume-id'); 132 | * ``` 133 | */ 134 | public deleteBlockStorageById(id: string): Promise { 135 | return instance.delete(`/volumes/${id}`); 136 | } 137 | 138 | /** 139 | * Delete a Block Storage volume by name and region 140 | * 141 | * ### Example 142 | * ```js 143 | * import { DigitalOcean } from 'digitalocean-js'; 144 | * 145 | * const client = new DigitalOcean('your-api-key'); 146 | * await client.blockStorage.deleteBlockStorageByName('volume-name', 'nyc1'); 147 | * ``` 148 | */ 149 | public deleteBlockStorageByName( 150 | name: string, 151 | regionSlug: string 152 | ): Promise { 153 | return instance.delete(`/volumes`, { 154 | params: { name, region: regionSlug } 155 | }); 156 | } 157 | 158 | ////////// Validation Methods ////////// 159 | private volumeIsValid(vol: BlockStorageRequest): boolean { 160 | if (!vol.size_gigabytes || !vol.name) { 161 | return false; 162 | } 163 | return true; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/cdn/cdn.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError } from 'axios'; 2 | import MockAdapter from 'axios-mock-adapter'; 3 | 4 | import { 5 | getCdnEndpoints, 6 | getErrorResponse, 7 | getSingleCdnEndpoint 8 | } from '../../../test'; 9 | import { instance } from '../../axios-instance'; 10 | import { DigitalOcean } from '../../digitalocean'; 11 | import { CdnEndpointRequest } from '../../models'; 12 | 13 | const mock = new MockAdapter(instance, { onNoMatch: 'throwException' }); 14 | const client = new DigitalOcean('abc123'); 15 | 16 | describe('CDN Service', () => { 17 | it('should exist', () => { 18 | expect(client.cdn).toBeDefined(); 19 | }); 20 | 21 | describe('getAllEndpoints', () => { 22 | it('should resolve correctly', async () => { 23 | const endpoints = getCdnEndpoints(); 24 | mock.onGet('/cdn/endpoints').reply(200, { endpoints }); 25 | 26 | const allEndpoints = await client.cdn.getAllEndpoints(); 27 | expect(allEndpoints).toEqual(endpoints); 28 | }); 29 | 30 | it('should reject on failure', async () => { 31 | const error = getErrorResponse(); 32 | mock.onGet('/cdn/endpoints').reply(400, error); 33 | 34 | try { 35 | await client.cdn.getAllEndpoints(); 36 | } catch (e) { 37 | expect((e as AxiosError).response?.data).toEqual(error); 38 | } 39 | }); 40 | }); 41 | 42 | describe('getExistingEndpoint', () => { 43 | it('should resolve correctly', async () => { 44 | const endpoint = getSingleCdnEndpoint(); 45 | mock.onGet(`/cdn/endpoints/${endpoint.id}`).reply(200, { endpoint }); 46 | 47 | const singleEndpoint = await client.cdn.getExistingEndpoint(endpoint.id); 48 | expect(singleEndpoint).toEqual(endpoint); 49 | }); 50 | 51 | it('should reject on failure', async () => { 52 | const error = getErrorResponse(); 53 | mock.onGet('/cdn/endpoints/bad-id').reply(400, error); 54 | 55 | try { 56 | await client.cdn.getExistingEndpoint('bad-id'); 57 | } catch (e) { 58 | expect((e as AxiosError).response?.data).toEqual(error); 59 | } 60 | }); 61 | }); 62 | 63 | describe('createEndpoint', () => { 64 | it('should resolve correctly', async () => { 65 | const endpoint = getSingleCdnEndpoint(); 66 | const createRequest: CdnEndpointRequest = { 67 | origin: endpoint.origin, 68 | ttl: 3600 69 | }; 70 | mock.onPost(`/cdn/endpoints`, createRequest).reply(200, { endpoint }); 71 | 72 | const singleEndpoint = await client.cdn.createEndpoint(createRequest); 73 | expect(singleEndpoint).toEqual(endpoint); 74 | }); 75 | 76 | it('should throw an error if request fails validation', async () => { 77 | const badRequest: CdnEndpointRequest = { 78 | ttl: 3600 79 | }; 80 | 81 | try { 82 | await client.cdn.createEndpoint(badRequest); 83 | } catch (e) { 84 | expect((e as Error).message).toEqual( 85 | 'Required fields missing from Endpoint Object' 86 | ); 87 | } 88 | }); 89 | 90 | it('should reject on failure', async () => { 91 | const error = getErrorResponse(); 92 | const badRequest: CdnEndpointRequest = { 93 | origin: 'not-an-origin', 94 | ttl: -3600 95 | }; 96 | mock.onPost(`/cdn/endpoints`, badRequest).reply(400, error); 97 | 98 | try { 99 | await client.cdn.createEndpoint(badRequest); 100 | } catch (e) { 101 | expect((e as AxiosError).response?.data).toEqual(error); 102 | } 103 | }); 104 | }); 105 | 106 | describe('updateEndpoint', () => { 107 | it('should resolve correctly', async () => { 108 | const endpoint = { ...getSingleCdnEndpoint(), ttl: 86400 }; 109 | mock 110 | .onPut(`/cdn/endpoints/${endpoint.id}`, { ttl: 86400 }) 111 | .reply(200, { endpoint }); 112 | 113 | const singleEndpoint = await client.cdn.updateEndpoint( 114 | endpoint.id, 115 | 86400 116 | ); 117 | expect(singleEndpoint).toEqual(endpoint); 118 | }); 119 | 120 | it('should reject on failure', async () => { 121 | const error = getErrorResponse(); 122 | mock.onPut(`/cdn/endpoints/bad-id`, { ttl: -3600 }).reply(400, error); 123 | 124 | try { 125 | await client.cdn.updateEndpoint('bad-id', -3600); 126 | } catch (e) { 127 | expect((e as AxiosError).response?.data).toEqual(error); 128 | } 129 | }); 130 | }); 131 | 132 | describe('deleteEndpoint', () => { 133 | it('should resolve correctly', async () => { 134 | const endpoint = getSingleCdnEndpoint(); 135 | mock.onDelete(`/cdn/endpoints/${endpoint.id}`).reply(200); 136 | 137 | try { 138 | await client.cdn.deleteEndpoint(endpoint.id); 139 | } catch (e) { 140 | fail('delete should have resolved correctly'); 141 | } 142 | }); 143 | 144 | it('should reject on failure', async () => { 145 | const error = getErrorResponse(); 146 | mock.onDelete(`/cdn/endpoints/bad-id`).reply(400, error); 147 | 148 | try { 149 | await client.cdn.deleteEndpoint('bad-id'); 150 | } catch (e) { 151 | expect((e as AxiosError).response?.data).toEqual(error); 152 | } 153 | }); 154 | }); 155 | 156 | describe('purgeEndpointCache', () => { 157 | it('should resolve correctly', async () => { 158 | const endpoint = getSingleCdnEndpoint(); 159 | const files = ['test-file-1.jpg', 'test-file-2.jpg']; 160 | mock 161 | .onDelete(`/cdn/endpoints/${endpoint.id}/cache`, { files }) 162 | .reply(200); 163 | 164 | try { 165 | await client.cdn.purgeEndpointCache(endpoint.id, files); 166 | } catch (e) { 167 | fail('purge cache should have resolved correctly'); 168 | } 169 | }); 170 | 171 | it('should reject on failure', async () => { 172 | const error = getErrorResponse(); 173 | const files = ['bad-file-1.jpg', 'bad-file-2.jpg']; 174 | mock.onDelete(`/cdn/endpoints/bad-id/cache`, { files }).reply(400, error); 175 | 176 | try { 177 | await client.cdn.purgeEndpointCache('bad-id', files); 178 | } catch (e) { 179 | expect((e as AxiosError).response?.data).toEqual(error); 180 | } 181 | }); 182 | }); 183 | }); 184 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/cdn/cdn.service.ts: -------------------------------------------------------------------------------- 1 | import { CdnEndpoint, CdnEndpointRequest } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class CdnService { 6 | /** 7 | * List all of the CDN endpoints available on your account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const endpoints = await client.cdn.getAllEndpoints(); 15 | * ``` 16 | */ 17 | public getAllEndpoints(): Promise { 18 | return instance 19 | .get(`/cdn/endpoints`) 20 | .then(response => response.data.endpoints); 21 | } 22 | 23 | /** 24 | * Get an existing CDN endpoint 25 | * 26 | * ### Example 27 | * ```js 28 | * import { DigitalOcean } from 'digitalocean-js'; 29 | * 30 | * const client = new DigitalOcean('your-api-key'); 31 | * const endpoint = await client.cdn.getExistingEndpoint('endpoint-id'); 32 | * ``` 33 | */ 34 | public getExistingEndpoint(id: string): Promise { 35 | return instance 36 | .get(`/cdn/endpoints/${id}`) 37 | .then(response => response.data.endpoint); 38 | } 39 | 40 | /** 41 | * Create a new CDN endpoint 42 | * 43 | * ### Example 44 | * ```js 45 | * import { DigitalOcean } from 'digitalocean-js'; 46 | * 47 | * const client = new DigitalOcean('your-api-key'); 48 | * const request = { 49 | * "origin": "static-images.nyc3.digitaloceanspaces.com", 50 | * "ttl": 3600 51 | * }; 52 | * const endpoint = await client.cdn.createEndpoint(request); 53 | * ``` 54 | */ 55 | public createEndpoint(endpoint: CdnEndpointRequest): Promise { 56 | if (!this.endpointIsValid(endpoint)) { 57 | throw new Error('Required fields missing from Endpoint Object'); 58 | } 59 | return instance 60 | .post(`/cdn/endpoints`, endpoint) 61 | .then(response => response.data.endpoint); 62 | } 63 | 64 | /** 65 | * Update the ttl of an existing CDN endpoint 66 | * 67 | * ### Example 68 | * ```js 69 | * import { DigitalOcean } from 'digitalocean-js'; 70 | * 71 | * const client = new DigitalOcean('your-api-key'); 72 | * const endpoint = await client.cdn.updateEndpoint('endpoint-id', 1800); 73 | * ``` 74 | */ 75 | public updateEndpoint(id: string, ttl: number): Promise { 76 | return instance 77 | .put(`/cdn/endpoints/${id}`, { ttl }) 78 | .then(response => response.data.endpoint); 79 | } 80 | 81 | /** 82 | * Delete an existing CDN endpoint 83 | * 84 | * ### Example 85 | * ```js 86 | * import { DigitalOcean } from 'digitalocean-js'; 87 | * 88 | * const client = new DigitalOcean('your-api-key'); 89 | * const endpoint = await client.cdn.deleteEndpoint('endpoint-id'); 90 | * ``` 91 | */ 92 | public deleteEndpoint(id: string): Promise { 93 | return instance.delete(`/cdn/endpoints/${id}`); 94 | } 95 | 96 | /** 97 | * Purge cached content from a CDN endpoint 98 | * 99 | * ### Example 100 | * ```js 101 | * import { DigitalOcean } from 'digitalocean-js'; 102 | * 103 | * const client = new DigitalOcean('your-api-key'); 104 | * const files = [ 105 | * 'assets/img/hero.png', 106 | * 'assets/css/*' 107 | * ]; 108 | * const endpoint = await client.cdn.purgeEndpointCache('endpoint-id', files); 109 | * ``` 110 | */ 111 | public purgeEndpointCache(id: string, files: string[]): Promise { 112 | return instance.delete(`/cdn/endpoints/${id}/cache`, { 113 | data: { files } 114 | }); 115 | } 116 | 117 | ////////// Validation Methods ////////// 118 | private endpointIsValid(end: CdnEndpointRequest): boolean { 119 | if (!end.origin) { 120 | return false; 121 | } 122 | return true; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/certificate/certificate.service.ts: -------------------------------------------------------------------------------- 1 | import { Certificate, CertificateRequest } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class CertificateService { 6 | /** 7 | * Upload a new SSL Certificate 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const request = { 15 | * name: 'web-cert-01', 16 | * private_key: '-----BEGIN PRIVATE KEY-----...', 17 | * leaf_certificate: '-----BEGIN CERTIFICATE-----...', 18 | * certificate_chain: '-----BEGIN CERTIFICATE-----...' 19 | * }; 20 | * const cert = await client.certificates.createCertificate(request); 21 | * ``` 22 | */ 23 | public createCertificate( 24 | certificateRequest: CertificateRequest 25 | ): Promise { 26 | return instance 27 | .post(`/certificates`, certificateRequest) 28 | .then(response => response.data.certificate); 29 | } 30 | 31 | /** 32 | * Get information about an existing SSL Certificate 33 | * 34 | * ### Example 35 | * ```js 36 | * import { DigitalOcean } from 'digitalocean-js'; 37 | * 38 | * const client = new DigitalOcean('your-api-key'); 39 | * const cert = await client.certificates.getExistingCertificate('cert-id'); 40 | * ``` 41 | */ 42 | public getExistingCertificate(certificateId: string): Promise { 43 | return instance 44 | .get(`/certificates/${certificateId}`) 45 | .then(response => response.data.certificate); 46 | } 47 | 48 | /** 49 | * Get information about all SSL Certificates on your account 50 | * 51 | * ### Example 52 | * ```js 53 | * import { DigitalOcean } from 'digitalocean-js'; 54 | * 55 | * const client = new DigitalOcean('your-api-key'); 56 | * const certs = await client.certificates.getAllCertificates(); 57 | * ``` 58 | */ 59 | public getAllCertificates(): Promise { 60 | return instance 61 | .get(`/certificates`) 62 | .then(response => response.data.certificates); 63 | } 64 | 65 | /** 66 | * Delete a specific SSL Certificate from the provided ID 67 | * 68 | * ### Example 69 | * ```js 70 | * import { DigitalOcean } from 'digitalocean-js'; 71 | * 72 | * const client = new DigitalOcean('your-api-key'); 73 | * await client.certificates.deleteCertificate('cert-id'); 74 | * ``` 75 | */ 76 | public deleteCertificate(certificateId: string): Promise { 77 | return instance.delete(`/certificates/${certificateId}`); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/domain/domain-record.service.ts: -------------------------------------------------------------------------------- 1 | import { DomainRecord, DomainRecordRequest } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class DomainRecordService { 6 | /** 7 | * Get all records configured for a domain 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const records = await client.domainRecords.getAllDomainRecords('example.com'); 15 | * ``` 16 | */ 17 | public getAllDomainRecords(domainName: string): Promise { 18 | return instance 19 | .get(`/domains/${domainName}/records`) 20 | .then(response => response.data.domain_records); 21 | } 22 | 23 | /** 24 | * Create a new record for a domain 25 | * 26 | * ### Example 27 | * ```js 28 | * import { DigitalOcean } from 'digitalocean-js'; 29 | * 30 | * const client = new DigitalOcean('your-api-key'); 31 | * const request = { 32 | * type: 'A', 33 | * name: 'www', 34 | * data: '162.10.66.0', 35 | * priority: null, 36 | * port: null, 37 | * ttl: 1800, 38 | * weight: null, 39 | * flags: null, 40 | * tag: null 41 | * }; 42 | * const record = await client.domainRecords 43 | * .createDomainRecord('example.com', request); 44 | * ``` 45 | */ 46 | public createDomainRecord( 47 | domainName: string, 48 | domainRequest: DomainRecordRequest 49 | ): Promise { 50 | return instance 51 | .post(`/domains/${domainName}/records`, domainRequest) 52 | .then(response => response.data.domain_record); 53 | } 54 | 55 | /** 56 | * Get a specific existing domain record 57 | * 58 | * ### Example 59 | * ```js 60 | * import { DigitalOcean } from 'digitalocean-js'; 61 | * 62 | * const client = new DigitalOcean('your-api-key'); 63 | * const record = await client.domainRecords 64 | * .getExistingDomainRecord('example.com', 'record-id'); 65 | * ``` 66 | */ 67 | public getExistingDomainRecord( 68 | domainName: string, 69 | recordId: number 70 | ): Promise { 71 | return instance 72 | .get(`/domains/${domainName}/records/${recordId}`) 73 | .then(response => response.data.domain_record); 74 | } 75 | 76 | /** 77 | * Update an existing domain record 78 | * 79 | * ### Example 80 | * ```js 81 | * import { DigitalOcean } from 'digitalocean-js'; 82 | * 83 | * const client = new DigitalOcean('your-api-key'); 84 | * const request = { 85 | * // Any valid domain record attribute can be changed 86 | * name: 'blog' 87 | * }; 88 | * const record = await client.domainRecords 89 | * .updateDomainRecord('example.com', 'record-id', request); 90 | * ``` 91 | */ 92 | public updateDomainRecord( 93 | domainName: string, 94 | recordId: number, 95 | domainRequest: DomainRecordRequest 96 | ): Promise { 97 | return instance 98 | .put(`/domains/${domainName}/records/${recordId}`, domainRequest) 99 | .then(response => response.data.domain_record); 100 | } 101 | 102 | /** 103 | * Delete a record for a domain 104 | * 105 | * ### Example 106 | * ```js 107 | * import { DigitalOcean } from 'digitalocean-js'; 108 | * 109 | * const client = new DigitalOcean('your-api-key'); 110 | * await client.domainRecords.deleteDomainRecord('example.com', 'record-id'); 111 | * ``` 112 | */ 113 | public deleteDomainRecord( 114 | domainName: string, 115 | recordId: number 116 | ): Promise { 117 | return instance.delete(`/domains/${domainName}/records/${recordId}`); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/domain/domain.service.ts: -------------------------------------------------------------------------------- 1 | import { Domain, DomainRequest } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class DomainService { 6 | /** 7 | * Get a list of all the domains on your account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const domains = await client.domains.getAllDomains(); 15 | * ``` 16 | */ 17 | public getAllDomains(): Promise { 18 | return instance.get(`/domains`).then(response => response.data.domains); 19 | } 20 | 21 | /** 22 | * Create a new domain on your account 23 | * 24 | * ### Example 25 | * ```js 26 | * import { DigitalOcean } from 'digitalocean-js'; 27 | * 28 | * const client = new DigitalOcean('your-api-key'); 29 | * const request = { 30 | * name: 'example.com', 31 | * ip_address: '1.2.3.4' 32 | * }; 33 | * const domain = await client.domains.createDomain(request); 34 | * ``` 35 | */ 36 | public createDomain(domainRequest: DomainRequest): Promise { 37 | return instance 38 | .post(`/domains`, domainRequest) 39 | .then(response => response.data.domain); 40 | } 41 | 42 | /** 43 | * Get information about a specific domain 44 | * 45 | * ### Example 46 | * ```js 47 | * import { DigitalOcean } from 'digitalocean-js'; 48 | * 49 | * const client = new DigitalOcean('your-api-key'); 50 | * const domain = await client.domains.getExistingDomain('example.com'); 51 | * ``` 52 | */ 53 | public getExistingDomain(domainName: string): Promise { 54 | return instance 55 | .get(`/domains/${domainName}`) 56 | .then(response => response.data.domain); 57 | } 58 | 59 | /** 60 | * Delete a specific domain from your account 61 | * 62 | * ### Example 63 | * ```js 64 | * import { DigitalOcean } from 'digitalocean-js'; 65 | * 66 | * const client = new DigitalOcean('your-api-key'); 67 | * await client.domains.deleteDomain('example.com'); 68 | * ``` 69 | */ 70 | public deleteDomain(domainName: string): Promise { 71 | return instance.delete(`/domains/${domainName}`); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/droplet/droplet-actions.service.ts: -------------------------------------------------------------------------------- 1 | import { Action, DropletActionRequest } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class DropletActionService { 6 | /** 7 | * Enable backups on an existing droplet 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const action = await client.dropletActions.enableBackupsForDroplet('droplet-id'); 15 | * ``` 16 | */ 17 | public enableBackupsForDroplet(dropletId: number): Promise { 18 | const actionRequest: DropletActionRequest = { 19 | type: 'enable_backups' 20 | }; 21 | return instance 22 | .post(`/droplets/${dropletId}/actions`, actionRequest) 23 | .then(response => response.data.action); 24 | } 25 | 26 | /** 27 | * Disable backups on an existing droplet 28 | * 29 | * ### Example 30 | * ```js 31 | * import { DigitalOcean } from 'digitalocean-js'; 32 | * 33 | * const client = new DigitalOcean('your-api-key'); 34 | * const action = await client.dropletActions.disableBackupsForDroplet('droplet-id'); 35 | * ``` 36 | */ 37 | public disableBackupsForDroplet(dropletId: number): Promise { 38 | const actionRequest: DropletActionRequest = { 39 | type: 'disable_backups' 40 | }; 41 | return instance 42 | .post(`/droplets/${dropletId}/actions`, actionRequest) 43 | .then(response => response.data.action); 44 | } 45 | 46 | /** 47 | * Reboot a droplet 48 | * 49 | * ### Example 50 | * ```js 51 | * import { DigitalOcean } from 'digitalocean-js'; 52 | * 53 | * const client = new DigitalOcean('your-api-key'); 54 | * const action = await client.dropletActions.rebootDroplet('droplet-id'); 55 | * ``` 56 | */ 57 | public rebootDroplet(dropletId: number): Promise { 58 | const actionRequest: DropletActionRequest = { 59 | type: 'reboot' 60 | }; 61 | return instance 62 | .post(`/droplets/${dropletId}/actions`, actionRequest) 63 | .then(response => response.data.action); 64 | } 65 | 66 | /** 67 | * Power cycle a droplet (power off then on) 68 | * 69 | * ### Example 70 | * ```js 71 | * import { DigitalOcean } from 'digitalocean-js'; 72 | * 73 | * const client = new DigitalOcean('your-api-key'); 74 | * const action = await client.dropletActions.powerCycleDroplet('droplet-id'); 75 | * ``` 76 | */ 77 | public powerCycleDroplet(dropletId: number): Promise { 78 | const actionRequest: DropletActionRequest = { 79 | type: 'power_cycle' 80 | }; 81 | return instance 82 | .post(`/droplets/${dropletId}/actions`, actionRequest) 83 | .then(response => response.data.action); 84 | } 85 | 86 | /** 87 | * Shutdown a droplet 88 | * 89 | * ### Example 90 | * ```js 91 | * import { DigitalOcean } from 'digitalocean-js'; 92 | * 93 | * const client = new DigitalOcean('your-api-key'); 94 | * const action = await client.dropletActions.shutdownDroplet('droplet-id'); 95 | * ``` 96 | */ 97 | public shutdownDroplet(dropletId: number): Promise { 98 | const actionRequest: DropletActionRequest = { 99 | type: 'shutdown' 100 | }; 101 | return instance 102 | .post(`/droplets/${dropletId}/actions`, actionRequest) 103 | .then(response => response.data.action); 104 | } 105 | 106 | /** 107 | * Power off a droplet 108 | * 109 | * ### Example 110 | * ```js 111 | * import { DigitalOcean } from 'digitalocean-js'; 112 | * 113 | * const client = new DigitalOcean('your-api-key'); 114 | * const action = await client.dropletActions.powerOffDroplet('droplet-id'); 115 | * ``` 116 | */ 117 | public powerOffDroplet(dropletId: number): Promise { 118 | const actionRequest: DropletActionRequest = { 119 | type: 'power_off' 120 | }; 121 | return instance 122 | .post(`/droplets/${dropletId}/actions`, actionRequest) 123 | .then(response => response.data.action); 124 | } 125 | 126 | /** 127 | * Power on a droplet 128 | * 129 | * ### Example 130 | * ```js 131 | * import { DigitalOcean } from 'digitalocean-js'; 132 | * 133 | * const client = new DigitalOcean('your-api-key'); 134 | * const action = await client.dropletActions.powerOnDroplet('droplet-id'); 135 | * ``` 136 | */ 137 | public powerOnDroplet(dropletId: number): Promise { 138 | const actionRequest: DropletActionRequest = { 139 | type: 'power_on' 140 | }; 141 | return instance 142 | .post(`/droplets/${dropletId}/actions`, actionRequest) 143 | .then(response => response.data.action); 144 | } 145 | 146 | /** 147 | * Restore a droplet using a backup image 148 | * 149 | * ### Example 150 | * ```js 151 | * import { DigitalOcean } from 'digitalocean-js'; 152 | * 153 | * const client = new DigitalOcean('your-api-key'); 154 | * const action = await client.dropletActions.restoreDroplet('droplet-id', 12389723); 155 | * ``` 156 | */ 157 | public restoreDroplet( 158 | dropletId: number, 159 | image: string | number 160 | ): Promise { 161 | const actionRequest: DropletActionRequest = { 162 | image, 163 | type: 'restore' 164 | }; 165 | return instance 166 | .post(`/droplets/${dropletId}/actions`, actionRequest) 167 | .then(response => response.data.action); 168 | } 169 | 170 | /** 171 | * Reset the password for a droplet 172 | * 173 | * ### Example 174 | * ```js 175 | * import { DigitalOcean } from 'digitalocean-js'; 176 | * 177 | * const client = new DigitalOcean('your-api-key'); 178 | * const action = await client.dropletActions.passwordResetDroplet('droplet-id'); 179 | * ``` 180 | */ 181 | public passwordResetDroplet(dropletId: number): Promise { 182 | const actionRequest: DropletActionRequest = { 183 | type: 'password_reset' 184 | }; 185 | return instance 186 | .post(`/droplets/${dropletId}/actions`, actionRequest) 187 | .then(response => response.data.action); 188 | } 189 | 190 | /** 191 | * Resize a droplet 192 | * 193 | * ### Example 194 | * ```js 195 | * import { DigitalOcean } from 'digitalocean-js'; 196 | * 197 | * const client = new DigitalOcean('your-api-key'); 198 | * const action = await client.dropletActions 199 | * .resizeDroplet('droplet-id', true, '1gb'); 200 | * ``` 201 | */ 202 | public resizeDroplet( 203 | dropletId: number, 204 | resizeDisk: boolean, 205 | size: string 206 | ): Promise { 207 | const actionRequest: DropletActionRequest = { 208 | disk: resizeDisk, 209 | size, 210 | type: 'resize' 211 | }; 212 | return instance 213 | .post(`/droplets/${dropletId}/actions`, actionRequest) 214 | .then(response => response.data.action); 215 | } 216 | 217 | /** 218 | * Rebuild a droplet 219 | * 220 | * ### Example 221 | * ```js 222 | * import { DigitalOcean } from 'digitalocean-js'; 223 | * 224 | * const client = new DigitalOcean('your-api-key'); 225 | * const action = await client.dropletActions 226 | * .rebuildDroplet('droplet-id', 'ubuntu-16-04-x64'); 227 | * ``` 228 | */ 229 | public rebuildDroplet( 230 | dropletId: number, 231 | image: string | number 232 | ): Promise { 233 | const actionRequest: DropletActionRequest = { 234 | image, 235 | type: 'rebuild' 236 | }; 237 | return instance 238 | .post(`/droplets/${dropletId}/actions`, actionRequest) 239 | .then(response => response.data.action); 240 | } 241 | 242 | /** 243 | * Rename a droplet 244 | * 245 | * ### Example 246 | * ```js 247 | * import { DigitalOcean } from 'digitalocean-js'; 248 | * 249 | * const client = new DigitalOcean('your-api-key'); 250 | * const action = await client.dropletActions 251 | * .renameDroplet('droplet-id', 'nifty-new-name'); 252 | * ``` 253 | */ 254 | public renameDroplet(dropletId: number, name: string): Promise { 255 | const actionRequest: DropletActionRequest = { 256 | name, 257 | type: 'rename' 258 | }; 259 | return instance 260 | .post(`/droplets/${dropletId}/actions`, actionRequest) 261 | .then(response => response.data.action); 262 | } 263 | 264 | /** 265 | * Change the kernel of a droplet 266 | * 267 | * ### Example 268 | * ```js 269 | * import { DigitalOcean } from 'digitalocean-js'; 270 | * 271 | * const client = new DigitalOcean('your-api-key'); 272 | * const action = await client.dropletActions 273 | * .renameDroplet('droplet-id', 991); 274 | * ``` 275 | */ 276 | public changeDropletKernel( 277 | dropletId: number, 278 | kernelId: number 279 | ): Promise { 280 | const actionRequest: DropletActionRequest = { 281 | kernel: kernelId, 282 | type: 'change_kernel' 283 | }; 284 | return instance 285 | .post(`/droplets/${dropletId}/actions`, actionRequest) 286 | .then(response => response.data.action); 287 | } 288 | 289 | /** 290 | * Enable IPv6 networking on an existing droplet 291 | * 292 | * ### Example 293 | * ```js 294 | * import { DigitalOcean } from 'digitalocean-js'; 295 | * 296 | * const client = new DigitalOcean('your-api-key'); 297 | * const action = await client.dropletActions.enableIPv6('droplet-id'); 298 | * ``` 299 | */ 300 | public enableIPv6(dropletId: number): Promise { 301 | const actionRequest: DropletActionRequest = { 302 | type: 'enable_ipv6' 303 | }; 304 | return instance 305 | .post(`/droplets/${dropletId}/actions`, actionRequest) 306 | .then(response => response.data.action); 307 | } 308 | 309 | /** 310 | * Enable private networking on an existing droplet 311 | * 312 | * ### Example 313 | * ```js 314 | * import { DigitalOcean } from 'digitalocean-js'; 315 | * 316 | * const client = new DigitalOcean('your-api-key'); 317 | * const action = await client.dropletActions.enablePrivateNetworking('droplet-id'); 318 | * ``` 319 | */ 320 | public enablePrivateNetworking(dropletId: number): Promise { 321 | const actionRequest: DropletActionRequest = { 322 | type: 'enable_private_networking' 323 | }; 324 | return instance 325 | .post(`/droplets/${dropletId}/actions`, actionRequest) 326 | .then(response => response.data.action); 327 | } 328 | 329 | /** 330 | * Take a snapshot of a droplet 331 | * 332 | * ### Example 333 | * ```js 334 | * import { DigitalOcean } from 'digitalocean-js'; 335 | * 336 | * const client = new DigitalOcean('your-api-key'); 337 | * const action = await client.dropletActions 338 | * .snapshotDroplet('droplet-id', 'Nifty New Snapshot'); 339 | * ``` 340 | */ 341 | public snapshotDroplet(dropletId: number, name: string): Promise { 342 | const actionRequest: DropletActionRequest = { 343 | name, 344 | type: 'snapshot' 345 | }; 346 | return instance 347 | .post(`/droplets/${dropletId}/actions`, actionRequest) 348 | .then(response => response.data.action); 349 | } 350 | 351 | // TODO: Implement the bulk action method, Acting on Tagged Droplets 352 | 353 | /** 354 | * Get a specific droplet action 355 | * 356 | * ### Example 357 | * ```js 358 | * import { DigitalOcean } from 'digitalocean-js'; 359 | * 360 | * const client = new DigitalOcean('your-api-key'); 361 | * const action = await client.dropletActions 362 | * .getExistingDropletAction('droplet-id', 'action-id'); 363 | * ``` 364 | */ 365 | public getExistingDropletAction( 366 | dropletId: number, 367 | actionId: number 368 | ): Promise { 369 | return instance 370 | .get(`/droplets/${dropletId}/actions/${actionId}`) 371 | .then(response => response.data.action); 372 | } 373 | } 374 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/droplet/droplet.service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Action, 3 | Backup, 4 | Droplet, 5 | DropletRequest, 6 | Kernel, 7 | Snapshot 8 | } from '../../models'; 9 | 10 | import { instance } from '../../axios-instance'; 11 | 12 | export class DropletService { 13 | /** 14 | * Create a new droplet 15 | * 16 | * ### Example 17 | * ```js 18 | * import { DigitalOcean } from 'digitalocean-js'; 19 | * 20 | * const client = new DigitalOcean('your-api-key'); 21 | * const request = { 22 | * name: 'example.com', 23 | * region: 'nyc3', 24 | * size: 's-1vcpu-1gb', 25 | * image: 'ubuntu-16-04-x64', 26 | * ssh_keys: null, 27 | * backups: false, 28 | * ipv6: true, 29 | * user_data: null, 30 | * private_networking: null, 31 | * volumes: null, 32 | * tags: [ 33 | * 'web' 34 | * ] 35 | * }; 36 | * const droplet = await client.droplets.createNewDroplet(request); 37 | * ``` 38 | */ 39 | public createNewDroplet(dropletRequest: DropletRequest): Promise { 40 | return instance 41 | .post(`/droplets`, dropletRequest) 42 | .then(response => response.data.droplet); 43 | } 44 | 45 | /** 46 | * Create multiple droplets with the same specs but different names 47 | * 48 | * ### Example 49 | * ```js 50 | * import { DigitalOcean } from 'digitalocean-js'; 51 | * 52 | * const client = new DigitalOcean('your-api-key'); 53 | * const request = { 54 | * names: [ 55 | * 'sub-01.example.com', 56 | * 'sub-02.example.com' 57 | * ], 58 | * region: 'nyc3', 59 | * size: 's-1vcpu-1gb', 60 | * image: 'ubuntu-16-04-x64', 61 | * ssh_keys: null, 62 | * backups: false, 63 | * ipv6: true, 64 | * user_data: null, 65 | * private_networking: null, 66 | * tags: [ 67 | * 'web' 68 | * ] 69 | * }; 70 | * const droplets = await client.droplets.createMultipleDroplets(request); 71 | * ``` 72 | */ 73 | public createMultipleDroplets( 74 | dropletsRequest: DropletRequest 75 | ): Promise { 76 | return instance 77 | .post(`/droplets`, dropletsRequest) 78 | .then(response => response.data.droplets); 79 | } 80 | 81 | /** 82 | * Get a specific existing droplet by ID 83 | * 84 | * ### Example 85 | * ```js 86 | * import { DigitalOcean } from 'digitalocean-js'; 87 | * 88 | * const client = new DigitalOcean('your-api-key'); 89 | * const droplet = await client.droplets.getExistingDroplet('droplet-id'); 90 | * ``` 91 | */ 92 | public getExistingDroplet(dropletId: number): Promise { 93 | return instance 94 | .get(`/droplets/${dropletId}`) 95 | .then(response => response.data.droplet); 96 | } 97 | 98 | /** 99 | * Get all droplets on the account 100 | * 101 | * ### Example 102 | * ```js 103 | * import { DigitalOcean } from 'digitalocean-js'; 104 | * 105 | * const client = new DigitalOcean('your-api-key'); 106 | * const droplets = await client.droplets.getAllDroplets(); 107 | * ``` 108 | */ 109 | public getAllDroplets(): Promise { 110 | return instance.get(`/droplets`).then(response => response.data.droplets); 111 | } 112 | 113 | /** 114 | * Get all droplets on the account that has a given tag 115 | * 116 | * ### Example 117 | * ```js 118 | * import { DigitalOcean } from 'digitalocean-js'; 119 | * 120 | * const client = new DigitalOcean('your-api-key'); 121 | * const droplets = await client.droplets.getDropletsByTag('tag-name'); 122 | * ``` 123 | */ 124 | public getDropletsByTag(tag: string): Promise { 125 | return instance 126 | .get(`/droplets`, { params: { tag_name: tag } }) 127 | .then(response => response.data.droplets); 128 | } 129 | 130 | /** 131 | * Retrieve a list of all kernels available to a Droplet 132 | * 133 | * ### Example 134 | * ```js 135 | * import { DigitalOcean } from 'digitalocean-js'; 136 | * 137 | * const client = new DigitalOcean('your-api-key'); 138 | * const kernels = await client.droplets.getAvailableKernelsForDroplet('droplet-id'); 139 | * ``` 140 | */ 141 | public getAvailableKernelsForDroplet(dropletId: number): Promise { 142 | return instance 143 | .get(`/droplets/${dropletId}/kernels`) 144 | .then(response => response.data.kernels); 145 | } 146 | 147 | /** 148 | * Retrieve the snapshots that have been created from a Droplet 149 | * 150 | * ### Example 151 | * ```js 152 | * import { DigitalOcean } from 'digitalocean-js'; 153 | * 154 | * const client = new DigitalOcean('your-api-key'); 155 | * const snapshots = await client.droplets.getSnapshotsForDroplet('droplet-id'); 156 | * ``` 157 | */ 158 | public getSnapshotsForDroplet(dropletId: number): Promise { 159 | return instance 160 | .get(`/droplets/${dropletId}/snapshots`) 161 | .then(response => response.data.snapshots); 162 | } 163 | 164 | /** 165 | * Retrieve any backups associated with a Droplet 166 | * 167 | * ### Example 168 | * ```js 169 | * import { DigitalOcean } from 'digitalocean-js'; 170 | * 171 | * const client = new DigitalOcean('your-api-key'); 172 | * const backups = await client.droplets.getBackupsForDroplet('droplet-id'); 173 | * ``` 174 | */ 175 | public getBackupsForDroplet(dropletId: number): Promise { 176 | return instance 177 | .get(`/droplets/${dropletId}/backups`) 178 | .then(response => response.data.backups); 179 | } 180 | 181 | /** 182 | * Retrieve all actions that have been executed on a Droplet 183 | * 184 | * ### Example 185 | * ```js 186 | * import { DigitalOcean } from 'digitalocean-js'; 187 | * 188 | * const client = new DigitalOcean('your-api-key'); 189 | * const actions = await client.droplets.getDropletActions('droplet-id'); 190 | * ``` 191 | */ 192 | public getDropletActions(dropletId: number): Promise { 193 | return instance 194 | .get(`/droplets/${dropletId}/actions`) 195 | .then(response => response.data.actions); 196 | } 197 | 198 | /** 199 | * Delete a specific droplet by ID 200 | * 201 | * ### Example 202 | * ```js 203 | * import { DigitalOcean } from 'digitalocean-js'; 204 | * 205 | * const client = new DigitalOcean('your-api-key'); 206 | * await client.droplets.deleteDroplet('droplet-id'); 207 | * ``` 208 | */ 209 | public deleteDroplet(dropletId: number): Promise { 210 | return instance.delete(`/droplets/${dropletId}`); 211 | } 212 | 213 | /** 214 | * Delete Droplets by a tag 215 | * 216 | * ### Example 217 | * ```js 218 | * import { DigitalOcean } from 'digitalocean-js'; 219 | * 220 | * const client = new DigitalOcean('your-api-key'); 221 | * await client.droplets.deleteDropletsByTag('tag'); 222 | * ``` 223 | */ 224 | public deleteDropletsByTag(tag: string): Promise { 225 | return instance.delete(`/droplets`, { params: { tag_name: tag } }); 226 | } 227 | 228 | /** 229 | * Retrieve a list of Droplets that are running on the same physical server 230 | * 231 | * ### Example 232 | * ```js 233 | * import { DigitalOcean } from 'digitalocean-js'; 234 | * 235 | * const client = new DigitalOcean('your-api-key'); 236 | * const droplets = await client.droplets.getNeighborsForDroplet('droplet-id'); 237 | * ``` 238 | */ 239 | public getNeighborsForDroplet(dropletId: number): Promise { 240 | return instance 241 | .delete(`/droplets/${dropletId}/neighbors`) 242 | .then(response => response.data.droplets); 243 | } 244 | 245 | /** 246 | * Retrieve a list of any Droplets that are running on the same physical hardware 247 | * 248 | * ### Example 249 | * ```js 250 | * import { DigitalOcean } from 'digitalocean-js'; 251 | * 252 | * const client = new DigitalOcean('your-api-key'); 253 | * const droplets = await client.droplets.getDropletNeighbors(); 254 | * ``` 255 | */ 256 | public getDropletNeighbors(): Promise { 257 | return instance 258 | .delete(`/reports/droplet_neighbors`) 259 | .then(response => response.data.neighbors); 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/firewall/firewall.service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Firewall, 3 | FirewallInboundRule, 4 | FirewallOutboundRule 5 | } from '../../models'; 6 | 7 | import { instance } from '../../axios-instance'; 8 | 9 | export class FirewallService { 10 | /** 11 | * Create a new Cloud Firewall 12 | * 13 | * ### Example 14 | * ```js 15 | * import { DigitalOcean } from 'digitalocean-js'; 16 | * 17 | * const client = new DigitalOcean('your-api-key'); 18 | * const newFirewall = { 19 | * "name": "firewall", 20 | * "inbound_rules": [ 21 | * { 22 | * "protocol": "tcp", 23 | * "ports": "80", 24 | * "sources": { 25 | * "load_balancer_uids": [ 26 | * "4de7ac8b-495b-4884-9a69-1050c6793cd6" 27 | * ] 28 | * } 29 | * }, 30 | * { 31 | * "protocol": "tcp", 32 | * "ports": 22, 33 | * "sources": { 34 | * "tags": [ 35 | * "gateway" 36 | * ], 37 | * "addresses": [ 38 | * "18.0.0.0/8" 39 | * ] 40 | * } 41 | * } 42 | * ], 43 | * "outbound_rules": [ 44 | * { 45 | * "protocol": "tcp", 46 | * "ports": "80", 47 | * "destinations": { 48 | * "addresses": [ 49 | * "0.0.0.0/0", 50 | * "::/0" 51 | * ] 52 | * } 53 | * } 54 | * ], 55 | * "droplet_ids": [ 56 | * 8043964 57 | * ], 58 | * "tags": null 59 | * }; 60 | * const firewall = await client.firewalls.createFirewall(newFirewall); 61 | * ``` 62 | */ 63 | public createFirewall(firewall: Firewall): Promise { 64 | return instance 65 | .post(`/firewalls`, firewall) 66 | .then(response => response.data.firewall); 67 | } 68 | 69 | /** 70 | * Show information about an existing Cloud Firewall 71 | * 72 | * ### Example 73 | * ```js 74 | * import { DigitalOcean } from 'digitalocean-js'; 75 | * 76 | * const client = new DigitalOcean('your-api-key'); 77 | * const firewall = await client.firewalls.getExistingFirewall('firewall-id'); 78 | * ``` 79 | */ 80 | public getExistingFirewall(firewallId: string): Promise { 81 | return instance 82 | .get(`/firewalls/${firewallId}`) 83 | .then(response => response.data.firewall); 84 | } 85 | 86 | /** 87 | * List all of the Cloud Firewalls available on your account 88 | * 89 | * ### Example 90 | * ```js 91 | * import { DigitalOcean } from 'digitalocean-js'; 92 | * 93 | * const client = new DigitalOcean('your-api-key'); 94 | * const firewall = await client.firewalls.getAllFirewalls(); 95 | * ``` 96 | */ 97 | public getAllFirewalls(): Promise { 98 | return instance.get(`/firewalls`).then(response => response.data.firewalls); 99 | } 100 | 101 | /** 102 | * Update the configuration of an existing Cloud Firewall 103 | * 104 | * **NOTE: Any attributes that are not provided will be reset to their default values.** 105 | * 106 | * ### Example 107 | * ```js 108 | * import { DigitalOcean } from 'digitalocean-js'; 109 | * 110 | * const client = new DigitalOcean('your-api-key'); 111 | * const updatedFirewall = { 112 | * "name": "firewall", 113 | * "inbound_rules": [ 114 | * { 115 | * "protocol": "tcp", 116 | * "ports": "8080", 117 | * "sources": { 118 | * "load_balancer_uids": [ 119 | * "4de7ac8b-495b-4884-9a69-1050c6793cd6" 120 | * ] 121 | * } 122 | * }, 123 | * { 124 | * "protocol": "tcp", 125 | * "ports": 22, 126 | * "sources": { 127 | * "tags": [ 128 | * "gateway" 129 | * ], 130 | * "addresses": [ 131 | * "18.0.0.0/8" 132 | * ] 133 | * } 134 | * } 135 | * ], 136 | * "outbound_rules": [ 137 | * { 138 | * "protocol": "tcp", 139 | * "ports": "8080", 140 | * "destinations": { 141 | * "addresses": [ 142 | * "0.0.0.0/0", 143 | * "::/0" 144 | * ] 145 | * } 146 | * } 147 | * ], 148 | * "droplet_ids": [ 149 | * 8043964 150 | * ], 151 | * "tags": [ 152 | * "frontend" 153 | * ] 154 | * }; 155 | * const firewall = await client.firewalls.updateFirewall(updatedFirewall); 156 | * ``` 157 | */ 158 | public updateFirewall(firewall: Firewall): Promise { 159 | return instance 160 | .put(`/firewalls/${firewall.id}`, firewall) 161 | .then(response => response.data.firewall); 162 | } 163 | 164 | /** 165 | * Delete a Cloud Firewall 166 | * 167 | * ### Example 168 | * ```js 169 | * import { DigitalOcean } from 'digitalocean-js'; 170 | * 171 | * const client = new DigitalOcean('your-api-key'); 172 | * await client.firewalls.deleteFirewall('firewall-id'); 173 | * ``` 174 | */ 175 | public deleteFirewall(firewallId: string): Promise { 176 | return instance.delete(`/firewalls/${firewallId}`); 177 | } 178 | 179 | /** 180 | * Assign Droplets to a Cloud Firewall 181 | * 182 | * ### Example 183 | * ```js 184 | * import { DigitalOcean } from 'digitalocean-js'; 185 | * 186 | * const client = new DigitalOcean('your-api-key'); 187 | * const dropletIds = [ 188 | * 'droplet-id-1', 189 | * 'droplet-id-2' 190 | * ]; 191 | * await client.firewalls.addDropletsToFirewall('firewall-id', dropletIds); 192 | * ``` 193 | */ 194 | public addDropletsToFirewall( 195 | firewallId: string, 196 | dropletIds: number[] 197 | ): Promise { 198 | const request = { 199 | droplet_ids: dropletIds 200 | }; 201 | return instance.post(`/firewalls/${firewallId}/droplets`, request); 202 | } 203 | 204 | /** 205 | * Remove Droplets from a Cloud Firewall 206 | * 207 | * ### Example 208 | * ```js 209 | * import { DigitalOcean } from 'digitalocean-js'; 210 | * 211 | * const client = new DigitalOcean('your-api-key'); 212 | * const dropletIds = [ 213 | * 'droplet-id-1', 214 | * 'droplet-id-2' 215 | * ]; 216 | * await client.firewalls.removeDropletsFromFirewall('firewall-id', dropletIds); 217 | * ``` 218 | */ 219 | public removeDropletsFromFirewall( 220 | firewallId: string, 221 | dropletIds: number[] 222 | ): Promise { 223 | const request = { 224 | droplet_ids: dropletIds 225 | }; 226 | return instance.delete(`/firewalls/${firewallId}/droplets`, { 227 | data: request 228 | }); 229 | } 230 | 231 | /** 232 | * Assign a Tag representing a group of Droplets to a Cloud Firewall 233 | * 234 | * ### Example 235 | * ```js 236 | * import { DigitalOcean } from 'digitalocean-js'; 237 | * 238 | * const client = new DigitalOcean('your-api-key'); 239 | * const tags = [ 240 | * 'my-tag-1', 241 | * 'my-tag-2' 242 | * ]; 243 | * await client.firewalls.addTagsToFirewall('firewall-id', tags); 244 | * ``` 245 | */ 246 | public addTagsToFirewall(firewallId: string, tags: string[]): Promise { 247 | const request = { 248 | tags 249 | }; 250 | return instance.post(`/firewalls/${firewallId}/tags`, request); 251 | } 252 | 253 | /** 254 | * Remove a Tag representing a group of Droplets from a Cloud Firewall 255 | * 256 | * ### Example 257 | * ```js 258 | * import { DigitalOcean } from 'digitalocean-js'; 259 | * 260 | * const client = new DigitalOcean('your-api-key'); 261 | * const tags = [ 262 | * 'my-tag-1', 263 | * 'my-tag-2' 264 | * ]; 265 | * await client.firewalls.removeTagsFromFirewall('firewall-id', tags); 266 | * ``` 267 | */ 268 | public removeTagsFromFirewall( 269 | firewallId: string, 270 | tags: string[] 271 | ): Promise { 272 | const request = { 273 | tags 274 | }; 275 | return instance.delete(`/firewalls/${firewallId}/tags`, { 276 | data: request 277 | }); 278 | } 279 | 280 | /** 281 | * Add additional access rules to a Cloud Firewall 282 | * 283 | * ### Example 284 | * ```js 285 | * import { DigitalOcean } from 'digitalocean-js'; 286 | * 287 | * const client = new DigitalOcean('your-api-key'); 288 | * const inboundRules = [ 289 | * { 290 | * "protocol": "tcp", 291 | * "ports": "3306", 292 | * "sources": { 293 | * "droplet_ids": [ 294 | * 49696269 295 | * ] 296 | * } 297 | * } 298 | * ]; 299 | * outboundRules = [ 300 | * { 301 | * "protocol": "tcp", 302 | * "ports": "3306", 303 | * "destinations": { 304 | * "droplet_ids": [ 305 | * 49696269 306 | * ] 307 | * } 308 | * } 309 | * ]; 310 | * await client.firewalls.addRulesToFirewall('firewall-id', inboundRules, outboundRules); 311 | * ``` 312 | */ 313 | public addRulesToFirewall( 314 | firewallId: string, 315 | inboundRules: FirewallInboundRule[], 316 | outboundRules: FirewallOutboundRule[] 317 | ): Promise { 318 | const request = { 319 | inbound_rules: inboundRules, 320 | outbound_rules: outboundRules 321 | }; 322 | return instance.post(`/firewalls/${firewallId}/rules`, request); 323 | } 324 | 325 | /** 326 | * Remove access rules from a Cloud Firewall 327 | * 328 | * ### Example 329 | * ```js 330 | * import { DigitalOcean } from 'digitalocean-js'; 331 | * 332 | * const client = new DigitalOcean('your-api-key'); 333 | * const inboundRules = [ 334 | * { 335 | * "protocol": "tcp", 336 | * "ports": "3306", 337 | * "sources": { 338 | * "droplet_ids": [ 339 | * 49696269 340 | * ] 341 | * } 342 | * } 343 | * ]; 344 | * outboundRules = [ 345 | * { 346 | * "protocol": "tcp", 347 | * "ports": "3306", 348 | * "destinations": { 349 | * "droplet_ids": [ 350 | * 49696269 351 | * ] 352 | * } 353 | * } 354 | * ]; 355 | * await client.firewalls.removeRulesFromFirewall('firewall-id', inboundRules, outboundRules); 356 | * ``` 357 | */ 358 | public removeRulesFromFirewall( 359 | firewallId: string, 360 | inboundRules: FirewallInboundRule[], 361 | outboundRules: FirewallOutboundRule[] 362 | ): Promise { 363 | const request = { 364 | inbound_rules: inboundRules, 365 | outbound_rules: outboundRules 366 | }; 367 | return instance.delete(`/firewalls/${firewallId}/rules`, { 368 | data: request 369 | }); 370 | } 371 | } 372 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/floating-ip/floating-ip-actions.service.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class FloatingIPActionService { 6 | /** 7 | * Assign an existing Floating IP to a Droplet 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const action = await client.floatingIPActions 15 | * .assignFloatingIPToDroplet('1.2.3.4', 'droplet-id'); 16 | * ``` 17 | */ 18 | public assignFloatingIPToDroplet( 19 | floatingIPAddress: string, 20 | dropletId: string 21 | ): Promise { 22 | const request = { 23 | droplet_id: dropletId, 24 | type: 'assign' 25 | }; 26 | return instance 27 | .post(`/floating_ips/${floatingIPAddress}/actions`, request) 28 | .then(response => response.data.action); 29 | } 30 | 31 | /** 32 | * Unassign an existing Floating IP 33 | * 34 | * ### Example 35 | * ```js 36 | * import { DigitalOcean } from 'digitalocean-js'; 37 | * 38 | * const client = new DigitalOcean('your-api-key'); 39 | * const action = await client.floatingIPActions 40 | * .unassignFloatingIP('1.2.3.4'); 41 | * ``` 42 | */ 43 | public unassignFloatingIP(floatingIPAddress: string): Promise { 44 | const request = { 45 | type: 'unassign' 46 | }; 47 | return instance 48 | .post(`/floating_ips/${floatingIPAddress}/actions`, request) 49 | .then(response => response.data.action); 50 | } 51 | 52 | /** 53 | * Retrieve all actions that have been executed on a Floating IP 54 | * 55 | * ### Example 56 | * ```js 57 | * import { DigitalOcean } from 'digitalocean-js'; 58 | * 59 | * const client = new DigitalOcean('your-api-key'); 60 | * const actions = await client.floatingIPActions 61 | * .getAllFloatingIPActions('1.2.3.4'); 62 | * ``` 63 | */ 64 | public getAllFloatingIPActions(floatingIPAddress: string): Promise { 65 | return instance 66 | .get(`/floating_ips/${floatingIPAddress}/actions`) 67 | .then(response => response.data.actions); 68 | } 69 | 70 | /** 71 | * Retrieve the status of a Floating IP action 72 | * 73 | * ### Example 74 | * ```js 75 | * import { DigitalOcean } from 'digitalocean-js'; 76 | * 77 | * const client = new DigitalOcean('your-api-key'); 78 | * const action = await client.floatingIPActions 79 | * .getExistingFloatingIPAction('1.2.3.4', 'action-id'); 80 | * ``` 81 | */ 82 | public getExistingFloatingIPAction( 83 | floatingIPAddress: string, 84 | actionId: string 85 | ): Promise { 86 | return instance 87 | .get(`/floating_ips/${floatingIPAddress}/actions/${actionId}`) 88 | .then(response => response.data.action); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/floating-ip/floating-ip.service.ts: -------------------------------------------------------------------------------- 1 | import { FloatingIP } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class FloatingIPService { 6 | /** 7 | * List all of the Floating IPs available on your account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const floatingIPs = await client.floatingIPs.getAllFloatingIPs(); 15 | * ``` 16 | */ 17 | public getAllFloatingIPs(): Promise { 18 | return instance 19 | .get(`/floating_ips`) 20 | .then(response => response.data.floating_ips); 21 | } 22 | 23 | /** 24 | * Create a new Floating IP assigned to a Droplet 25 | * 26 | * ### Example 27 | * ```js 28 | * import { DigitalOcean } from 'digitalocean-js'; 29 | * 30 | * const client = new DigitalOcean('your-api-key'); 31 | * const floatingIP = 32 | * await client.floatingIPs.createFloatingIPForDroplet('droplet-id'); 33 | * ``` 34 | */ 35 | public createFloatingIPForDroplet(dropletId: string): Promise { 36 | const request = { droplet_id: dropletId }; 37 | return instance 38 | .post(`/floating_ips`, request) 39 | .then(response => response.data.floating_ip); 40 | } 41 | 42 | /** 43 | * Create a Floating IP reserved to a Region 44 | * 45 | * ### Example 46 | * ```js 47 | * import { DigitalOcean } from 'digitalocean-js'; 48 | * 49 | * const client = new DigitalOcean('your-api-key'); 50 | * const floatingIP = 51 | * await client.floatingIPs.createFloatingIPForRegion('nyc3'); 52 | * ``` 53 | */ 54 | public createFloatingIPForRegion(region: string): Promise { 55 | return instance 56 | .post(`/floating_ips`, { region }) 57 | .then(response => response.data.floating_ip); 58 | } 59 | 60 | /** 61 | * Show information about an existing Floating IP 62 | * 63 | * ### Example 64 | * ```js 65 | * import { DigitalOcean } from 'digitalocean-js'; 66 | * 67 | * const client = new DigitalOcean('your-api-key'); 68 | * const floatingIP = 69 | * await client.floatingIPs.getExistingFloatingIP('1.2.3.4'); 70 | * ``` 71 | */ 72 | public getExistingFloatingIP(floatingIPAddress: string): Promise { 73 | return instance 74 | .get(`/floating_ips/${floatingIPAddress}`) 75 | .then(response => response.data.floating_ip); 76 | } 77 | 78 | /** 79 | * Delete an existing Floating IP and remove it from your account 80 | * 81 | * ### Example 82 | * ```js 83 | * import { DigitalOcean } from 'digitalocean-js'; 84 | * 85 | * const client = new DigitalOcean('your-api-key'); 86 | * await client.floatingIPs.deleteFloatingIP('1.2.3.4'); 87 | * ``` 88 | */ 89 | public deleteFloatingIP(floatingIPAddress: string): Promise { 90 | return instance.delete(`/floating_ips/${floatingIPAddress}`); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/image/image-actions.service.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class ImageActionService { 6 | /** 7 | * Transfer an image to another region 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const action = await client.imageActions.transferImage('image-id', 'nyc1'); 15 | * ``` 16 | */ 17 | public transferImage(imageId: number, region: string): Promise { 18 | const request = { 19 | region, 20 | type: 'transfer' 21 | }; 22 | return instance 23 | .post(`/images/${imageId}/actions`, request) 24 | .then(response => response.data.action); 25 | } 26 | 27 | /** 28 | * Convert an image (a backup for example) to a snapshot 29 | * 30 | * ### Example 31 | * ```js 32 | * import { DigitalOcean } from 'digitalocean-js'; 33 | * 34 | * const client = new DigitalOcean('your-api-key'); 35 | * const action = await client.imageActions.convertImageToSnapshot('image-id'); 36 | * ``` 37 | */ 38 | public convertImageToSnapshot(imageId: number): Promise { 39 | const request = { 40 | type: 'convert' 41 | }; 42 | return instance 43 | .post(`/images/${imageId}/actions`, request) 44 | .then(response => response.data.action); 45 | } 46 | 47 | /** 48 | * Retrieve the status of an image action 49 | * 50 | * ### Example 51 | * ```js 52 | * import { DigitalOcean } from 'digitalocean-js'; 53 | * 54 | * const client = new DigitalOcean('your-api-key'); 55 | * const action = await client.imageActions.getExistingImageAction('image-id', 'action-id'); 56 | * ``` 57 | */ 58 | public getExistingImageAction( 59 | imageId: number, 60 | actionId: number 61 | ): Promise { 62 | return instance 63 | .get(`/images/${imageId}/actions/${actionId}`) 64 | .then(response => response.data.action); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/image/image.service.ts: -------------------------------------------------------------------------------- 1 | import { Action, Image } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class ImageService { 6 | /** 7 | * Get all images on account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const images = await client.images.getAllImages(); 15 | * ``` 16 | */ 17 | public getAllImages(perPage?: number, page?: number): Promise { 18 | page = page ? page : 1; 19 | perPage = perPage ? perPage : 25; 20 | return instance 21 | .get(`/images`, { params: { page, per_page: perPage } }) 22 | .then(response => response.data.images); 23 | } 24 | 25 | /** 26 | * Get all distribution images 27 | * 28 | * ### Example 29 | * ```js 30 | * import { DigitalOcean } from 'digitalocean-js'; 31 | * 32 | * const client = new DigitalOcean('your-api-key'); 33 | * const images = await client.images.getAllDistributionImages(); 34 | * // Paginate images, 10 per page, starting on page 1 35 | * images = await client.images.getAllDistributionImages(10, 1); 36 | * ``` 37 | */ 38 | public getAllDistributionImages( 39 | perPage?: number, 40 | page?: number 41 | ): Promise { 42 | page = page ? page : 1; 43 | perPage = perPage ? perPage : 25; 44 | return instance 45 | .get(`/images`, { 46 | params: { type: 'distribution', page, per_page: perPage } 47 | }) 48 | .then(response => response.data.images); 49 | } 50 | 51 | /** 52 | * Get all application images 53 | * 54 | * ### Example 55 | * ```js 56 | * import { DigitalOcean } from 'digitalocean-js'; 57 | * 58 | * const client = new DigitalOcean('your-api-key'); 59 | * const images = await client.images.getAllApplicationImages(); 60 | * // Paginate application images, 10 per page, starting on page 1 61 | * images = await client.images.getAllApplicationImages(10, 1); 62 | * ``` 63 | */ 64 | public getAllApplicationImages( 65 | perPage?: number, 66 | page?: number 67 | ): Promise { 68 | page = page ? page : 1; 69 | perPage = perPage ? perPage : 25; 70 | return instance 71 | .get(`/images`, { 72 | params: { type: 'application', page, per_page: perPage } 73 | }) 74 | .then(response => response.data.images); 75 | } 76 | 77 | /** 78 | * Get the private images of a user 79 | * 80 | * ### Example 81 | * ```js 82 | * import { DigitalOcean } from 'digitalocean-js'; 83 | * 84 | * const client = new DigitalOcean('your-api-key'); 85 | * const images = await client.images.getUserImages(); 86 | * // Paginate user images, 10 per page, starting on page 1 87 | * images = await client.images.getUserImages(10, 1); 88 | * ``` 89 | */ 90 | public getUserImages(perPage?: number, page?: number): Promise { 91 | page = page ? page : 1; 92 | perPage = perPage ? perPage : 25; 93 | return instance 94 | .get(`/images`, { 95 | params: { private: true, page, per_page: perPage } 96 | }) 97 | .then(response => response.data.images); 98 | } 99 | 100 | /** 101 | * Get all actions that have been executed on an image 102 | * 103 | * ### Example 104 | * ```js 105 | * import { DigitalOcean } from 'digitalocean-js'; 106 | * 107 | * const client = new DigitalOcean('your-api-key'); 108 | * const actions = await client.images.getImageActions('image-id'); 109 | * ``` 110 | */ 111 | public getImageActions(imageId: number): Promise { 112 | return instance 113 | .get(`/images/${imageId}/actions`) 114 | .then(response => response.data.actions); 115 | } 116 | 117 | /** 118 | * Get information about an image 119 | * 120 | * ### Example 121 | * ```js 122 | * import { DigitalOcean } from 'digitalocean-js'; 123 | * 124 | * const client = new DigitalOcean('your-api-key'); 125 | * const image = await client.images.getExistingImage('image-id'); 126 | * ``` 127 | */ 128 | public getExistingImage(imageId: number): Promise { 129 | return instance 130 | .get(`/images/${imageId}`) 131 | .then(response => response.data.image); 132 | } 133 | 134 | /** 135 | * Get information about an image by image slug 136 | * 137 | * ### Example 138 | * ```js 139 | * import { DigitalOcean } from 'digitalocean-js'; 140 | * 141 | * const client = new DigitalOcean('your-api-key'); 142 | * const image = await client.images.getExistingImageBySlug('image-slug'); 143 | * ``` 144 | */ 145 | public getExistingImageBySlug(imageSlug: string): Promise { 146 | return instance 147 | .get(`/images/${imageSlug}`) 148 | .then(response => response.data.image); 149 | } 150 | 151 | /** 152 | * Update an image name 153 | * 154 | * ### Example 155 | * ```js 156 | * import { DigitalOcean } from 'digitalocean-js'; 157 | * 158 | * const client = new DigitalOcean('your-api-key'); 159 | * const image = await client.images.updateImageName('image-id', 'New Image Name'); 160 | * ``` 161 | */ 162 | public updateImageName(imageId: number, name: string): Promise { 163 | return instance 164 | .put(`/images/${imageId}`, { name }) 165 | .then(response => response.data.image); 166 | } 167 | 168 | /** 169 | * Delete an image 170 | * 171 | * ### Example 172 | * ```js 173 | * import { DigitalOcean } from 'digitalocean-js'; 174 | * 175 | * const client = new DigitalOcean('your-api-key'); 176 | * await client.images.deleteImage('image-id'); 177 | * ``` 178 | */ 179 | public deleteImage(imageId: number): Promise { 180 | return instance.delete(`/images/${imageId}`); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/index.ts: -------------------------------------------------------------------------------- 1 | export type { AccountService } from './account/account.service'; 2 | export type { ActionService } from './actions/actions.service'; 3 | export type { BillingHistoryService } from './billing-history/billing-history.service'; 4 | export type { BlockStorageActionService } from './block-storage/block-storage-actions.service'; 5 | export type { BlockStorageService } from './block-storage/block-storage.service'; 6 | export type { CdnService } from './cdn/cdn.service'; 7 | export type { CertificateService } from './certificate/certificate.service'; 8 | export type { DomainRecordService } from './domain/domain-record.service'; 9 | export type { DomainService } from './domain/domain.service'; 10 | export type { DropletActionService } from './droplet/droplet-actions.service'; 11 | export type { DropletService } from './droplet/droplet.service'; 12 | export type { FirewallService } from './firewall/firewall.service'; 13 | export type { FloatingIPActionService } from './floating-ip/floating-ip-actions.service'; 14 | export type { FloatingIPService } from './floating-ip/floating-ip.service'; 15 | export type { ImageActionService } from './image/image-actions.service'; 16 | export type { ImageService } from './image/image.service'; 17 | export type { KubernetesService } from './kubernetes/kubernetes.service'; 18 | export type { LoadBalancerService } from './load-balancer/load-balancer.service'; 19 | export type { ProjectService } from './project/project.service'; 20 | export type { RegionService } from './region/region.service'; 21 | export type { SizeService } from './size/size.service'; 22 | export type { 23 | SnapshotService, 24 | SnapshotType 25 | } from './snapshot/snapshot.service'; 26 | export type { SshService } from './ssh/ssh.service'; 27 | export type { TagService } from './tag/tag.service'; 28 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/kubernetes/kubernetes.service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | KubernetesCluster, 3 | KubernetesClusterRequest, 4 | KubernetesOptions, 5 | KubernetesVersion, 6 | KubernetesWorkerNodePool 7 | } from '../../models'; 8 | 9 | import { instance } from '../../axios-instance'; 10 | 11 | export class KubernetesService { 12 | /** 13 | * Create a new kubernetes cluster 14 | * 15 | * ### Example 16 | * ```js 17 | * import { DigitalOcean } from 'digitalocean-js'; 18 | * 19 | * const client = new DigitalOcean('your-api-key'); 20 | * const request = { 21 | * "name": "prod-cluster-01", 22 | * "region": "nyc1", 23 | * "version": "1.14.1-do.4", 24 | * "tags": [ 25 | * "production", 26 | * "web-team" 27 | * ], 28 | * "node_pools": [ 29 | * { 30 | * "size": "s-1vcpu-2gb", 31 | * "count": 3, 32 | * "name": "frontend-pool", 33 | * "tags": [ 34 | * "frontend" 35 | * ] 36 | * }, 37 | * { 38 | * "size": "c-4", 39 | * "count": 2, 40 | * "name": "backend-pool" 41 | * } 42 | * ] 43 | * }; 44 | * const cluster = await client.kubernetes.createCluster(request); 45 | * ``` 46 | */ 47 | public createCluster( 48 | cluster: KubernetesClusterRequest 49 | ): Promise { 50 | return instance 51 | .post(`/kubernetes/clusters`, cluster) 52 | .then(response => response.data.kubernetes_cluster); 53 | } 54 | 55 | /** 56 | * Get a specific existing kubernetes cluster by ID 57 | * 58 | * ### Example 59 | * ```js 60 | * import { DigitalOcean } from 'digitalocean-js'; 61 | * 62 | * const client = new DigitalOcean('your-api-key'); 63 | * const cluster = await client.kubernetes.getCluster('cluster-id'); 64 | * ``` 65 | */ 66 | public getCluster(clusterId: string): Promise { 67 | return instance 68 | .get(`/kubernetes/clusters/${clusterId}`) 69 | .then(response => response.data.kubernetes_cluster); 70 | } 71 | 72 | /** 73 | * Get all existing kubernetes clusters 74 | * 75 | * ### Example 76 | * ```js 77 | * import { DigitalOcean } from 'digitalocean-js'; 78 | * 79 | * const client = new DigitalOcean('your-api-key'); 80 | * const clusters = await client.kubernetes.getAllClusters(); 81 | * ``` 82 | */ 83 | public getAllClusters(): Promise { 84 | return instance 85 | .get(`/kubernetes/clusters`) 86 | .then(response => response.data.kubernetes_clusters); 87 | } 88 | 89 | /** 90 | * Update an existing kubernetes cluster 91 | * 92 | * ### Example 93 | * ```js 94 | * import { DigitalOcean } from 'digitalocean-js'; 95 | * 96 | * const client = new DigitalOcean('your-api-key'); 97 | * const request = { 98 | * "name": "stage-cluster-01", 99 | * "tags": [ 100 | * "staging", 101 | * "web-team" 102 | * ] 103 | * }; 104 | * const cluster = await client.kubernetes.updateCluster('cluster-id', request); 105 | * ``` 106 | */ 107 | public updateCluster( 108 | clusterId: string, 109 | cluster: KubernetesCluster 110 | ): Promise { 111 | return instance 112 | .put(`/kubernetes/clusters/${clusterId}`, cluster) 113 | .then(response => response.data.kubernetes_cluster); 114 | } 115 | 116 | /** 117 | * Get available upgrades for an existing kubernetes cluster 118 | * 119 | * ### Example 120 | * ```js 121 | * import { DigitalOcean } from 'digitalocean-js'; 122 | * 123 | * const client = new DigitalOcean('your-api-key'); 124 | * const upgrades = await client.kubernetes.getAvailableUpgradesForCluster('cluster-id'); 125 | * ``` 126 | */ 127 | public getAvailableUpgradesForCluster( 128 | clusterId: string 129 | ): Promise { 130 | return instance 131 | .get(`/kubernetes/clusters/${clusterId}/upgrades`) 132 | .then(response => response.data.available_upgrade_versions); 133 | } 134 | 135 | /** 136 | * Upgrade the version of an existing kubernetes cluster 137 | * 138 | * ### Example 139 | * ```js 140 | * import { DigitalOcean } from 'digitalocean-js'; 141 | * 142 | * const client = new DigitalOcean('your-api-key'); 143 | * await client.kubernetes.upgradeExistingCluster('cluster-id', "1.12.3-do.1"); 144 | * ``` 145 | */ 146 | public upgradeExistingCluster( 147 | clusterId: string, 148 | version: string 149 | ): Promise { 150 | return instance.post(`/kubernetes/clusters/${clusterId}/upgrade`, { 151 | version 152 | }); 153 | } 154 | 155 | /** 156 | * Delete an existing kubernetes cluster 157 | * 158 | * ### Example 159 | * ```js 160 | * import { DigitalOcean } from 'digitalocean-js'; 161 | * 162 | * const client = new DigitalOcean('your-api-key'); 163 | * await client.kubernetes.deleteCluster('cluster-id'); 164 | * ``` 165 | */ 166 | public deleteCluster(clusterId: string): Promise { 167 | return instance.delete(`/kubernetes/clusters/${clusterId}`); 168 | } 169 | 170 | /** 171 | * Get the contents of the kubeconfig yaml file for use with a Kubernetes cluster 172 | * 173 | * ### Example 174 | * ```js 175 | * import { DigitalOcean } from 'digitalocean-js'; 176 | * 177 | * const client = new DigitalOcean('your-api-key'); 178 | * const kubeconfig = await client.kubernetes.getClusterKubeconfig('cluster-id'); 179 | * ``` 180 | */ 181 | public getClusterKubeconfig(clusterId: string): Promise { 182 | return instance 183 | .get(`/kubernetes/clusters/${clusterId}/kubeconfig`) 184 | .then(response => response.data); 185 | } 186 | 187 | /** 188 | * Get an existing node pool on a kubernetes cluster 189 | * 190 | * ### Example 191 | * ```js 192 | * import { DigitalOcean } from 'digitalocean-js'; 193 | * 194 | * const client = new DigitalOcean('your-api-key'); 195 | * const nodePool = await client.kubernetes.getExistingNodePoolForCluster('cluster-id', 'pool-id'); 196 | * ``` 197 | */ 198 | public getExistingNodePoolForCluster( 199 | clusterId: string, 200 | poolId: string 201 | ): Promise { 202 | return instance 203 | .get(`/kubernetes/clusters/${clusterId}/node_pools/${poolId}`) 204 | .then(response => response.data.node_pool); 205 | } 206 | 207 | /** 208 | * Get all existing node pools on a kubernetes cluster 209 | * 210 | * ### Example 211 | * ```js 212 | * import { DigitalOcean } from 'digitalocean-js'; 213 | * 214 | * const client = new DigitalOcean('your-api-key'); 215 | * const nodePools = await client.kubernetes.getAllNodePoolsForCluster('cluster-id'); 216 | * ``` 217 | */ 218 | public getAllNodePoolsForCluster( 219 | clusterId: string 220 | ): Promise { 221 | return instance 222 | .get(`/kubernetes/clusters/${clusterId}/node_pools`) 223 | .then(response => response.data.node_pools); 224 | } 225 | 226 | /** 227 | * Add a node pool to a kubernetes cluster 228 | * 229 | * ### Example 230 | * ```js 231 | * import { DigitalOcean } from 'digitalocean-js'; 232 | * 233 | * const client = new DigitalOcean('your-api-key'); 234 | * const request = { 235 | * "size": "s-2vcpu-4gb", 236 | * "count": 1, 237 | * "name": "pool-02", 238 | * "tags": [ 239 | * "web" 240 | * ] 241 | * }; 242 | * const nodePool = await client.kubernetes.addNodePoolToCluster('cluster-id', request); 243 | * ``` 244 | */ 245 | public addNodePoolToCluster( 246 | clusterId: string, 247 | nodePool: KubernetesWorkerNodePool 248 | ): Promise { 249 | return instance 250 | .post(`/kubernetes/clusters/${clusterId}/node_pools`, nodePool) 251 | .then(response => response.data.node_pool); 252 | } 253 | 254 | /** 255 | * Update an existing node pool in a kubernetes cluster 256 | * 257 | * ### Example 258 | * ```js 259 | * import { DigitalOcean } from 'digitalocean-js'; 260 | * 261 | * const client = new DigitalOcean('your-api-key'); 262 | * const request = { 263 | * "name": "frontend", 264 | * "count": 1, 265 | * "tags": [ 266 | * "frontend" 267 | * ] 268 | * }; 269 | * const nodePool = await client.kubernetes.updateNodePoolForCluster('cluster-id', 'pool-id', request); 270 | * ``` 271 | */ 272 | public updateNodePoolForCluster( 273 | clusterId: string, 274 | nodePoolId: string, 275 | nodePool: KubernetesWorkerNodePool 276 | ): Promise { 277 | return instance 278 | .post( 279 | `/kubernetes/clusters/${clusterId}/node_pools/${nodePoolId}`, 280 | nodePool 281 | ) 282 | .then(response => response.data.node_pool); 283 | } 284 | 285 | /** 286 | * Delete an existing node pool from a kubernetes cluster 287 | * 288 | * ### Example 289 | * ```js 290 | * import { DigitalOcean } from 'digitalocean-js'; 291 | * 292 | * const client = new DigitalOcean('your-api-key'); 293 | * await client.kubernetes.deleteNodePoolFromCluster('cluster-id', 'pool-id'); 294 | * ``` 295 | */ 296 | public deleteNodePoolFromCluster( 297 | clusterId: string, 298 | nodePoolId: string 299 | ): Promise { 300 | return instance.delete( 301 | `/kubernetes/clusters/${clusterId}/node_pools/${nodePoolId}` 302 | ); 303 | } 304 | 305 | /** 306 | * Delete an existing node from a node pool in a kubernetes cluster. 307 | * Optionally specify to skip node draining or to replace with a new node after deletion. 308 | * 309 | * ### Example 310 | * ```js 311 | * import { DigitalOcean } from 'digitalocean-js'; 312 | * 313 | * const client = new DigitalOcean('your-api-key'); 314 | * await client.kubernetes.deleteNodeFromNodePoolForCluster('cluster-id', 'pool-id', 'node-id', false, false); 315 | * ``` 316 | */ 317 | public deleteNodeFromNodePoolForCluster( 318 | clusterId: string, 319 | nodePoolId: string, 320 | nodeId: string, 321 | skipDrain?: boolean, 322 | replace?: boolean 323 | ): Promise { 324 | const skipParam = skipDrain ? 1 : 0; 325 | const replaceParam = replace ? 1 : 0; 326 | return instance.delete( 327 | `/kubernetes/clusters/${clusterId}/node_pools/${nodePoolId}/nodes/${nodeId}`, 328 | { params: { skip_drain: skipParam, replace: replaceParam } } 329 | ); 330 | } 331 | 332 | /** 333 | * Get available Kubernetes versions, regions that support Kubernetes, and the available node sizes. 334 | * 335 | * ### Example 336 | * ```js 337 | * import { DigitalOcean } from 'digitalocean-js'; 338 | * 339 | * const client = new DigitalOcean('your-api-key'); 340 | * const options = await client.kubernetes.getKubernetesOptions(); 341 | * ``` 342 | */ 343 | public getKubernetesOptions(): Promise { 344 | return instance 345 | .get(`/kubernetes/options`) 346 | .then(response => response.data.options); 347 | } 348 | } 349 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/load-balancer/load-balancer.service.ts: -------------------------------------------------------------------------------- 1 | import { ForwardingRule, HealthCheck, LoadBalancer } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class LoadBalancerService { 6 | /** 7 | * Create a new Load Balancer 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * 15 | * const lb = { 16 | * "name": "example-lb-01", 17 | * "region": "nyc3", 18 | * "forwarding_rules": [ 19 | * { 20 | * "entry_protocol": "http", 21 | * "entry_port": 80, 22 | * "target_protocol": "http", 23 | * "target_port": 80, 24 | * "certificate_id": "", 25 | * "tls_passthrough": false 26 | * }, 27 | * { 28 | * "entry_protocol": "https", 29 | * "entry_port": 444, 30 | * "target_protocol": "https", 31 | * "target_port": 443, 32 | * "tls_passthrough": true 33 | * } 34 | * ], 35 | * "health_check": { 36 | * "protocol": "http", 37 | * "port": 80, 38 | * "path": "/", 39 | * "check_interval_seconds": 10, 40 | * "response_timeout_seconds": 5, 41 | * "healthy_threshold": 5, 42 | * "unhealthy_threshold": 3 43 | * }, 44 | * "sticky_sessions": { 45 | * "type": "none" 46 | * }, 47 | * "droplet_ids": [ 48 | * 3164444, 49 | * 3164445 50 | * ] 51 | * }; 52 | * 53 | * const loadBalancer = await client.loadBalancers.createLoadBalancer(lb); 54 | * ``` 55 | */ 56 | public createLoadBalancer(loadBalancer: LoadBalancer): Promise { 57 | if (!this.loadBalancerIsValid(loadBalancer)) { 58 | throw new Error('Required fields missing from Load Balancer Object'); 59 | } 60 | loadBalancer.forwarding_rules.forEach(rule => { 61 | if (!this.forwardingRuleIsValid(rule)) { 62 | throw new Error('Required fields missing from Forwarding Rule Object'); 63 | } 64 | }); 65 | if (loadBalancer.health_check) { 66 | if (!this.healthCheckIsValid(loadBalancer.health_check)) { 67 | throw new Error('Required fields missing from Health Check Object'); 68 | } 69 | } 70 | return instance 71 | .post(`/load_balancers`, loadBalancer) 72 | .then(response => response.data.load_balancer); 73 | } 74 | 75 | /** 76 | * Get an existing Load Balancer 77 | * 78 | * ### Example 79 | * ```js 80 | * import { DigitalOcean } from 'digitalocean-js'; 81 | * 82 | * const client = new DigitalOcean('your-api-key'); 83 | * const loadBalancer = await client.loadBalancers.getExistingLoadBalancer('load-balancer-id'); 84 | * ``` 85 | */ 86 | public getExistingLoadBalancer(id: string): Promise { 87 | return instance 88 | .get(`/load_balancers/${id}`) 89 | .then(response => response.data.load_balancer); 90 | } 91 | 92 | /** 93 | * Get all existing Load Balancers 94 | * 95 | * ### Example 96 | * ```js 97 | * import { DigitalOcean } from 'digitalocean-js'; 98 | * 99 | * const client = new DigitalOcean('your-api-key'); 100 | * const loadBalancers = await client.loadBalancers.getAllLoadBalancers(); 101 | * ``` 102 | */ 103 | public getAllLoadBalancers(): Promise { 104 | return instance 105 | .get(`/load_balancers`) 106 | .then(response => response.data.load_balancers); 107 | } 108 | 109 | /** 110 | * Update an existing Load Balancer 111 | * 112 | * ### Example 113 | * ```js 114 | * import { DigitalOcean } from 'digitalocean-js'; 115 | * 116 | * const client = new DigitalOcean('your-api-key'); 117 | * 118 | * const lb = { 119 | * "name": "example-lb-01", 120 | * "region": "nyc3", 121 | * "algorithm": "least_connections", 122 | * "forwarding_rules": [ 123 | * { 124 | * "entry_protocol": "http", 125 | * "entry_port": 80, 126 | * "target_protocol": "http", 127 | * "target_port": 80 128 | * }, 129 | * { 130 | * "entry_protocol": "https", 131 | * "entry_port": 444, 132 | * "target_protocol": "https", 133 | * "target_port": 443, 134 | * "tls_passthrough": true 135 | * } 136 | * ], 137 | * "health_check": { 138 | * "protocol": "http", 139 | * "port": 80, 140 | * "path": "/", 141 | * "check_interval_seconds": 10, 142 | * "response_timeout_seconds": 5, 143 | * "healthy_threshold": 5, 144 | * "unhealthy_threshold": 3 145 | * }, 146 | * "sticky_sessions": { 147 | * "type": "cookies", 148 | * "cookie_name": "DO_LB", 149 | * "cookie_ttl_seconds": 300 150 | * }, 151 | * "droplet_ids": [ 152 | * 3164444, 153 | * 3164445 154 | * ] 155 | * }; 156 | * 157 | * const loadBalancer = await client.loadBalancers.updateLoadBalancer(lb); 158 | * ``` 159 | */ 160 | public updateLoadBalancer(loadBalancer: LoadBalancer): Promise { 161 | if (!this.loadBalancerIsValid(loadBalancer)) { 162 | throw new Error('Required fields missing from Load Balancer Object'); 163 | } 164 | loadBalancer.forwarding_rules.forEach(rule => { 165 | if (!this.forwardingRuleIsValid(rule)) { 166 | throw new Error('Required fields missing from Forwarding Rule Object'); 167 | } 168 | }); 169 | if (loadBalancer.health_check) { 170 | if (!this.healthCheckIsValid(loadBalancer.health_check)) { 171 | throw new Error('Required fields missing from Health Check Object'); 172 | } 173 | } 174 | return instance 175 | .put(`/load_balancers/${loadBalancer.id}`, loadBalancer) 176 | .then(response => response.data.load_balancer); 177 | } 178 | 179 | /** 180 | * Delete an existing Load Balancer 181 | * 182 | * ### Example 183 | * ```js 184 | * import { DigitalOcean } from 'digitalocean-js'; 185 | * 186 | * const client = new DigitalOcean('your-api-key'); 187 | * await client.loadBalancers.deleteLoadBalancer('load-balancer-id'); 188 | * ``` 189 | */ 190 | public deleteLoadBalancer(id: string): Promise { 191 | return instance.delete(`/load_balancers/${id}`); 192 | } 193 | 194 | /** 195 | * Add droplets to a Load Balancer 196 | * 197 | * ### Example 198 | * ```js 199 | * import { DigitalOcean } from 'digitalocean-js'; 200 | * 201 | * const client = new DigitalOcean('your-api-key'); 202 | * const dropletIds = [ 203 | * 'droplet-id-1', 204 | * 'droplet-id-2', 205 | * 'droplet-id-3', 206 | * ]; 207 | * await client.loadBalancers.addDropletsToLoadBalancer(dropletIds); 208 | * ``` 209 | */ 210 | public addDropletsToLoadBalancer( 211 | id: string, 212 | dropletIds: number[] 213 | ): Promise { 214 | return instance.post(`/load_balancers/${id}`, { 215 | droplet_ids: dropletIds 216 | }); 217 | } 218 | 219 | /** 220 | * Remove droplets from a Load Balancer 221 | * 222 | * ### Example 223 | * ```js 224 | * import { DigitalOcean } from 'digitalocean-js'; 225 | * 226 | * const client = new DigitalOcean('your-api-key'); 227 | * const dropletIds = [ 228 | * 'droplet-id-1', 229 | * 'droplet-id-2', 230 | * 'droplet-id-3', 231 | * ]; 232 | * await client.loadBalancers.removeDropletsFromLoadBalancer('load-balancer-id', dropletIds); 233 | * ``` 234 | */ 235 | public removeDropletsFromLoadBalancer( 236 | id: string, 237 | dropletIds: number[] 238 | ): Promise { 239 | return instance.delete(`/load_balancers/${id}`, { 240 | data: { droplet_ids: dropletIds } 241 | }); 242 | } 243 | 244 | /** 245 | * Add forwarding rules to an existing Load Balancer 246 | * 247 | * ### Example 248 | * ```js 249 | * import { DigitalOcean } from 'digitalocean-js'; 250 | * 251 | * const client = new DigitalOcean('your-api-key'); 252 | * const rules = [ 253 | * { 254 | * "entry_protocol": "tcp", 255 | * "entry_port": 3306, 256 | * "target_protocol": "tcp", 257 | * "target_port": 3306 258 | * } 259 | * ]; 260 | * await client.loadBalancers 261 | * .addForwardingRulesToLoadBalancer('load-balancer-id', rules); 262 | * ``` 263 | */ 264 | public addForwardingRulesToLoadBalancer( 265 | id: string, 266 | rules: ForwardingRule[] 267 | ): Promise { 268 | rules.forEach(rule => { 269 | if (!this.forwardingRuleIsValid(rule)) { 270 | throw new Error('Required fields missing from Forwarding Rule Object'); 271 | } 272 | }); 273 | return instance.post(`/load_balancers/${id}/forwarding_rules`, { 274 | forwarding_rules: rules 275 | }); 276 | } 277 | 278 | /** 279 | * Remove forwarding rules from an existing Load Balancer 280 | * 281 | * ### Example 282 | * ```js 283 | * import { DigitalOcean } from 'digitalocean-js'; 284 | * 285 | * const client = new DigitalOcean('your-api-key'); 286 | * const rules = [ 287 | * { 288 | * "entry_protocol": "tcp", 289 | * "entry_port": 3306, 290 | * "target_protocol": "tcp", 291 | * "target_port": 3306 292 | * } 293 | * ]; 294 | * await client.loadBalancers 295 | * .removeForwardingRulesFromLoadBalancer('load-balancer-id', rules); 296 | * ``` 297 | */ 298 | public removeForwardingRulesFromLoadBalancer( 299 | id: string, 300 | rules: ForwardingRule[] 301 | ): Promise { 302 | rules.forEach(rule => { 303 | if (!this.forwardingRuleIsValid(rule)) { 304 | throw new Error('Required fields missing from Forwarding Rule Object'); 305 | } 306 | }); 307 | return instance.delete(`/load_balancers/${id}/forwarding_rules`, { 308 | data: { forwarding_rules: rules } 309 | }); 310 | } 311 | 312 | ////////// Validation Methods ////////// 313 | private loadBalancerIsValid(lb: LoadBalancer): boolean { 314 | if ( 315 | !lb.name || 316 | !lb.region || 317 | !lb.forwarding_rules || 318 | lb.forwarding_rules.length === 0 319 | ) { 320 | return false; 321 | } 322 | return true; 323 | } 324 | 325 | private forwardingRuleIsValid(rule: ForwardingRule): boolean { 326 | if ( 327 | !rule.entry_protocol || 328 | !rule.entry_port || 329 | !rule.target_protocol || 330 | !rule.target_port 331 | ) { 332 | return false; 333 | } 334 | return true; 335 | } 336 | 337 | private healthCheckIsValid(check: HealthCheck): boolean { 338 | if (!check.protocol || !check.port) { 339 | return false; 340 | } 341 | return true; 342 | } 343 | } 344 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/project/project.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError } from 'axios'; 2 | import MockAdapter from 'axios-mock-adapter'; 3 | 4 | import { getErrorResponse, getProjects, getSingleProject } from '../../../test'; 5 | import { instance } from '../../axios-instance'; 6 | import { DigitalOcean } from '../../digitalocean'; 7 | import { RESOURCE_TYPE } from '../../models'; 8 | 9 | const mock = new MockAdapter(instance, { onNoMatch: 'throwException' }); 10 | const client = new DigitalOcean('abc123'); 11 | 12 | describe('Project Service', () => { 13 | describe('getAllProjects', () => { 14 | it('should resolve correctly', async () => { 15 | const projects = getProjects(); 16 | mock.onGet('/projects').reply(200, { projects }); 17 | 18 | const allProjects = await client.projects.getAllProjects(); 19 | expect(allProjects).toEqual(projects); 20 | }); 21 | 22 | it('should reject on failure', async () => { 23 | const error = getErrorResponse(); 24 | mock.onGet('/projects').reply(400, error); 25 | 26 | try { 27 | await client.projects.getAllProjects(); 28 | } catch (e) { 29 | expect((e as AxiosError).response?.data).toEqual(error); 30 | } 31 | }); 32 | }); 33 | 34 | describe('getExistingProject', () => { 35 | it('should resolve correctly', async () => { 36 | const project = getSingleProject(); 37 | mock.onGet(`/projects/${project.id}`).reply(200, { project }); 38 | 39 | const singleProject = await client.projects.getExistingProject( 40 | project.id! 41 | ); 42 | expect(singleProject).toEqual(project); 43 | }); 44 | 45 | it('should reject on failure', async () => { 46 | const error = getErrorResponse(); 47 | mock.onGet('/projects/bad-id').reply(400, error); 48 | 49 | try { 50 | await client.projects.getExistingProject('bad-id'); 51 | } catch (e) { 52 | expect((e as AxiosError).response?.data).toEqual(error); 53 | } 54 | }); 55 | }); 56 | 57 | describe('parseProjectResourceUrn', () => { 58 | it('should successfully parse valid urn', () => { 59 | expect( 60 | client.projects.parseProjectResourceUrn('do:droplet:123456') 61 | ).toEqual({ 62 | id: '123456', 63 | type: RESOURCE_TYPE.DROPLET 64 | }); 65 | }); 66 | 67 | it('should throw error on bad urn', () => { 68 | expect(() => 69 | client.projects.parseProjectResourceUrn('this-is-not-a-urn') 70 | ).toThrowError( 71 | `URN expected in the format of 'do:resource_type:resource_id'` 72 | ); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/project/project.service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Project, 3 | ProjectPurpose, 4 | ProjectResource, 5 | ProjectResourceParsedUrn 6 | } from '../../models'; 7 | 8 | import { instance } from '../../axios-instance'; 9 | 10 | export class ProjectService { 11 | /** 12 | * Get all projects on your account 13 | * 14 | * ### Example 15 | * ```js 16 | * import { DigitalOcean } from 'digitalocean-js'; 17 | * 18 | * const client = new DigitalOcean('your-api-key'); 19 | * const projects = await client.projects.getAllProjects(); 20 | * ``` 21 | */ 22 | public getAllProjects(): Promise { 23 | return instance.get(`/projects`).then(response => response.data.projects); 24 | } 25 | 26 | /** 27 | * Get an existing project 28 | * 29 | * ### Example 30 | * ```js 31 | * import { DigitalOcean } from 'digitalocean-js'; 32 | * 33 | * const client = new DigitalOcean('your-api-key'); 34 | * const project = await client.projects.getExistingProject('project-id'); 35 | * ``` 36 | */ 37 | public getExistingProject(id: string): Promise { 38 | return instance 39 | .get(`/projects/${id}`) 40 | .then(response => response.data.project); 41 | } 42 | 43 | /** 44 | * Get the default project 45 | * 46 | * ### Example 47 | * ```js 48 | * import { DigitalOcean } from 'digitalocean-js'; 49 | * 50 | * const client = new DigitalOcean('your-api-key'); 51 | * const project = await client.projects.getDefaultProject(); 52 | * ``` 53 | */ 54 | public getDefaultProject(): Promise { 55 | return this.getExistingProject('default'); 56 | } 57 | 58 | /** 59 | * Create a new project 60 | * 61 | * ### Example 62 | * ```js 63 | * import { DigitalOcean } from 'digitalocean-js'; 64 | * 65 | * const client = new DigitalOcean('your-api-key'); 66 | * const request = { 67 | * "name": "my-web-api", 68 | * "description": "My website API", 69 | * "purpose": "Service or API", 70 | * "environment": "Production" 71 | * }; 72 | * const project = await client.projects.createProject(request); 73 | * ``` 74 | */ 75 | public createProject(project: Project): Promise { 76 | if (!this.createProjectIsValid(project)) { 77 | throw new Error('Required fields missing from the Project Object'); 78 | } 79 | if (!this.purposeIsValid(project.purpose)) { 80 | throw new Error( 81 | 'Project purpose is not one of the allowed values. Use a proper purpose value.' 82 | ); 83 | } 84 | return instance 85 | .post(`/projects`, project) 86 | .then(response => response.data.project); 87 | } 88 | 89 | /** 90 | * Update an existing project 91 | * 92 | * ### Example 93 | * ```js 94 | * import { DigitalOcean } from 'digitalocean-js'; 95 | * 96 | * const client = new DigitalOcean('your-api-key'); 97 | * const request = { 98 | * "name": "my-web-api", 99 | * "description": "My website API", 100 | * "purpose": "Service or API", 101 | * "environment": "Staging", 102 | * "is_default": false 103 | * }; 104 | * const project = await client.projects.updateProject('project-id', request); 105 | * ``` 106 | */ 107 | public updateProject(id: string, project: Project): Promise { 108 | if (!this.projectIsValid(project)) { 109 | throw new Error('Required fields missing from the Project Object'); 110 | } 111 | if (!this.purposeIsValid(project.purpose)) { 112 | throw new Error( 113 | 'Project purpose is not one of the allowed values. Use a proper purpose value.' 114 | ); 115 | } 116 | return instance 117 | .put(`/projects/${id}`, project) 118 | .then(response => response.data.project); 119 | } 120 | 121 | /** 122 | * Update the default project 123 | * 124 | * ### Example 125 | * ```js 126 | * import { DigitalOcean } from 'digitalocean-js'; 127 | * 128 | * const client = new DigitalOcean('your-api-key'); 129 | * const request = { 130 | * "name": "my-web-api", 131 | * "description": "My website API", 132 | * "purpose": "Service or API", 133 | * "environment": "Staging", 134 | * "is_default": true 135 | * }; 136 | * const project = await client.projects.updateDefaultProject(request); 137 | * ``` 138 | */ 139 | public updateDefaultProject(project: Project): Promise { 140 | return this.updateProject('default', project); 141 | } 142 | 143 | /** 144 | * Delete an existing project 145 | * 146 | * ### Example 147 | * ```js 148 | * import { DigitalOcean } from 'digitalocean-js'; 149 | * 150 | * const client = new DigitalOcean('your-api-key'); 151 | * await client.projects.deleteProject('project-id'); 152 | * ``` 153 | */ 154 | public async deleteProject(id: string): Promise { 155 | return instance.delete(`/projects/${id}`); 156 | } 157 | 158 | /** 159 | * Get all resources attached to a specific project 160 | * 161 | * ### Example 162 | * ```js 163 | * import { DigitalOcean } from 'digitalocean-js'; 164 | * 165 | * const client = new DigitalOcean('your-api-key'); 166 | * const resources = await client.projects.getProjectResources('project-id'); 167 | * ``` 168 | */ 169 | public getProjectResources(id: string): Promise { 170 | return instance 171 | .get(`/projects/${id}/resources`) 172 | .then(response => response.data.resources); 173 | } 174 | 175 | /** 176 | * Get all resources attached to the default project 177 | * 178 | * ### Example 179 | * ```js 180 | * import { DigitalOcean } from 'digitalocean-js'; 181 | * 182 | * const client = new DigitalOcean('your-api-key'); 183 | * const resources = await client.projects.getDefaultProjectResources(); 184 | * ``` 185 | */ 186 | public getDefaultProjectResources(): Promise { 187 | return this.getProjectResources('default'); 188 | } 189 | 190 | /** 191 | * Assign resources to an existing project 192 | * 193 | * ### Example 194 | * ```js 195 | * import { DigitalOcean, RESOURCE_PREFIX } from 'digitalocean-js'; 196 | * 197 | * const client = new DigitalOcean('your-api-key'); 198 | * const dropletId = 1; 199 | * const ip = '192.168.99.100'; 200 | * // Build resource urns using RESOURCE_PREFIX constant provided. 201 | * const resources = [ 202 | * `${RESOURCE_PREFIX.DROPLET}${dropletId}`, // 'do:droplet:1' 203 | * `${RESOURCE_PREFIX.FLOATING_IP}${ip}` // 'do:floatingip:192.168.99.100' 204 | * ]; 205 | * const resources = await client.projects 206 | * .assignResourcesToProject('project-id', resources); 207 | * ``` 208 | */ 209 | public assignResourcesToProject( 210 | id: string, 211 | resources: string[] 212 | ): Promise { 213 | return instance 214 | .post(`/projects/${id}/resources`, { resources }) 215 | .then(response => response.data.resources); 216 | } 217 | 218 | /** 219 | * Assign resources to the default project 220 | * 221 | * ### Example 222 | * ```js 223 | * import { DigitalOcean, RESOURCE_PREFIX } from 'digitalocean-js'; 224 | * 225 | * const client = new DigitalOcean('your-api-key'); 226 | * const dropletId = 1; 227 | * const ip = '192.168.99.100'; 228 | * // Build resource urns using RESOURCE_PREFIX constant provided. 229 | * const resources = [ 230 | * `${RESOURCE_PREFIX.DROPLET}${dropletId}`, // 'do:droplet:1' 231 | * `${RESOURCE_PREFIX.FLOATING_IP}${ip}` // 'do:floatingip:192.168.99.100' 232 | * ]; 233 | * const resources = await client.projects 234 | * .assignResourcesToDefaultProject(resources); 235 | * ``` 236 | */ 237 | public assignResourcesToDefaultProject( 238 | resources: string[] 239 | ): Promise { 240 | return this.assignResourcesToProject('default', resources); 241 | } 242 | 243 | /** 244 | * Parses a Project Resource URN into its various parts 245 | * 246 | * ### Example 247 | * ```js 248 | * import { DigitalOcean } from 'digitalocean-js'; 249 | * 250 | * const client = new DigitalOcean('your-api-key'); 251 | * const urn = 'do:droplet:4126873'; 252 | * const resource = await client.projects 253 | * .parseProjectResourceUrn(urn); 254 | * ``` 255 | */ 256 | public parseProjectResourceUrn(urn: string): ProjectResourceParsedUrn { 257 | const parts = urn.split(':'); 258 | if (parts[0] !== 'do' || parts.length !== 3) { 259 | throw new Error( 260 | `URN expected in the format of 'do:resource_type:resource_id'` 261 | ); 262 | } 263 | return { 264 | id: parts[2], 265 | type: parts[1] 266 | }; 267 | } 268 | 269 | ////////// Validation Methods ////////// 270 | private projectIsValid(project: Project): boolean { 271 | if (!project.name || !project.description || !project.purpose) { 272 | return false; 273 | } 274 | return true; 275 | } 276 | 277 | private createProjectIsValid(project: Project): boolean { 278 | if (!project.name || !project.purpose) { 279 | return false; 280 | } 281 | return true; 282 | } 283 | 284 | private purposeIsValid(purpose?: string): boolean { 285 | if (!purpose) { 286 | return false; 287 | } 288 | if (!Object.values(ProjectPurpose as object).includes(purpose)) { 289 | // Purpose doesn't correspond to allowed values. Check if Other. 290 | if (purpose.substring(0, 7) !== 'Other: ') { 291 | return false; 292 | } 293 | } 294 | return true; 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/region/region.service.ts: -------------------------------------------------------------------------------- 1 | import { Region } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class RegionService { 6 | /** 7 | * Get all regions 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const regions = await client.regions.getAllRegions(); 15 | * ``` 16 | */ 17 | public getAllRegions(): Promise { 18 | return instance.get(`/regions`).then(response => response.data.regions); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/size/size.service.ts: -------------------------------------------------------------------------------- 1 | import { Size } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class SizeService { 6 | /** 7 | * Get all sizes 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const sizes = await client.sizes.getAllSizes(); 15 | * ``` 16 | */ 17 | public getAllSizes(perPage?: number, page?: number): Promise { 18 | page = page ? page : 1; 19 | perPage = perPage ? perPage : 25; 20 | return instance 21 | .get(`/sizes`, { params: { page, per_page: perPage } }) 22 | .then(response => response.data.sizes); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/snapshot/snapshot.service.ts: -------------------------------------------------------------------------------- 1 | import { Snapshot } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export type SnapshotType = 'all' | 'droplet' | 'volume'; 6 | 7 | export class SnapshotService { 8 | /** 9 | * Get all snapshots on the account. 10 | * Optionally provide a resource type to filter snapshots. 11 | * 12 | * ### Example 13 | * ```js 14 | * import { DigitalOcean } from 'digitalocean-js'; 15 | * 16 | * const client = new DigitalOcean('your-api-key'); 17 | * // Get all snapshots 18 | * const snapshots = await client.snapshots.getSnapshots(); 19 | * // Get all droplet snapshots 20 | * snapshots = await client.snapshots.getSnapshots('droplet'); 21 | * // Get all volume snapshots 22 | * snapshots = await client.snapshots.getSnapshots('volume'); 23 | * ``` 24 | */ 25 | public getSnapshots(resourceType?: SnapshotType): Promise { 26 | const params: any = {}; 27 | if (resourceType && resourceType !== 'all') { 28 | params['resource_type'] = resourceType; 29 | } 30 | return instance 31 | .get(`/snapshots`, { params }) 32 | .then(response => response.data.snapshots); 33 | } 34 | 35 | /** 36 | * Get a specific existing snapshot by ID 37 | * 38 | * ### Example 39 | * ```js 40 | * import { DigitalOcean } from 'digitalocean-js'; 41 | * 42 | * const client = new DigitalOcean('your-api-key'); 43 | * const snapshot = await client.snapshots.getSnapshotById('snapshot-id'); 44 | * ``` 45 | */ 46 | public getSnapshotById(snapshotId: string): Promise { 47 | return instance 48 | .get(`/snapshots/${snapshotId}`) 49 | .then(response => response.data.snapshot); 50 | } 51 | 52 | /** 53 | * Delete a specific snapshot by ID 54 | * 55 | * ### Example 56 | * ```js 57 | * import { DigitalOcean } from 'digitalocean-js'; 58 | * 59 | * const client = new DigitalOcean('your-api-key'); 60 | * await client.snapshots.deleteSnapshot('snapshot-id'); 61 | * ``` 62 | */ 63 | public deleteSnapshot(snapshotId: string): Promise { 64 | return instance.delete(`/snapshots/${snapshotId}`); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/ssh/ssh.service.ts: -------------------------------------------------------------------------------- 1 | import { SshKey } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class SshService { 6 | /** 7 | * Get all ssh keys on account 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const keys = await client.ssh.getAllKeys(); 15 | * ``` 16 | */ 17 | public getAllKeys(): Promise { 18 | return instance 19 | .get(`/account/keys`) 20 | .then(response => response.data.ssh_keys); 21 | } 22 | 23 | /** 24 | * Create new ssh key 25 | * 26 | * ### Example 27 | * ```js 28 | * import { DigitalOcean } from 'digitalocean-js'; 29 | * 30 | * const client = new DigitalOcean('your-api-key'); 31 | * const request = { 32 | * name: 'My SSH Public Key', 33 | * public_key: 'ssh-rsa abcdef.... example' 34 | * }; 35 | * const key = await client.ssh.createNewKey(request); 36 | * ``` 37 | */ 38 | public createNewKey(key: SshKey): Promise { 39 | return instance 40 | .post(`/account/keys`, key) 41 | .then(response => response.data.ssh_key); 42 | } 43 | 44 | /** 45 | * Get existing ssh key from id 46 | * 47 | * ### Example 48 | * ```js 49 | * import { DigitalOcean } from 'digitalocean-js'; 50 | * 51 | * const client = new DigitalOcean('your-api-key'); 52 | * const key = await client.ssh.getExistingKey('id-or-fingerprint'); 53 | * ``` 54 | */ 55 | public getExistingKey(idOrFingerprint: string): Promise { 56 | return instance 57 | .get(`/account/keys/${idOrFingerprint}`) 58 | .then(response => response.data.ssh_key); 59 | } 60 | 61 | /** 62 | * Update ssh key 63 | * 64 | * ### Example 65 | * ```js 66 | * import { DigitalOcean } from 'digitalocean-js'; 67 | * 68 | * const client = new DigitalOcean('your-api-key'); 69 | * const request = { 70 | * name: 'Renamed SSH Key' 71 | * }; 72 | * const key = await client.ssh.updateKey('id-or-fingerprint', request); 73 | * ``` 74 | */ 75 | public updateKey(idOrFingerprint: string, key: SshKey): Promise { 76 | return instance 77 | .put(`/account/keys/${idOrFingerprint}`, key) 78 | .then(response => response.data.ssh_key); 79 | } 80 | 81 | /** 82 | * Delete ssh key 83 | * 84 | * ### Example 85 | * ```js 86 | * import { DigitalOcean } from 'digitalocean-js'; 87 | * 88 | * const client = new DigitalOcean('your-api-key'); 89 | * await client.ssh.deleteKey('id-or-fingerprint'); 90 | * ``` 91 | */ 92 | public deleteKey(idOrFingerprint: string): Promise { 93 | return instance.delete(`/account/keys/${idOrFingerprint}`); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/lib/services/tag/tag.service.ts: -------------------------------------------------------------------------------- 1 | import { Tag } from '../../models'; 2 | 3 | import { instance } from '../../axios-instance'; 4 | 5 | export class TagService { 6 | /** 7 | * Create new tag 8 | * 9 | * ### Example 10 | * ```js 11 | * import { DigitalOcean } from 'digitalocean-js'; 12 | * 13 | * const client = new DigitalOcean('your-api-key'); 14 | * const tag = await client.tags.createTag('new-tag'); 15 | * ``` 16 | */ 17 | public createTag(name: string): Promise { 18 | return instance.post(`/tags`, { name }).then(response => response.data.tag); 19 | } 20 | 21 | /** 22 | * Get all tags on the account 23 | * 24 | * ### Example 25 | * ```js 26 | * import { DigitalOcean } from 'digitalocean-js'; 27 | * 28 | * const client = new DigitalOcean('your-api-key'); 29 | * const tags = await client.tags.getTags(); 30 | * ``` 31 | */ 32 | public getTags(): Promise { 33 | return instance.get(`/tags`).then(response => response.data.tags); 34 | } 35 | 36 | /** 37 | * Get a specific existing tag by name 38 | * 39 | * ### Example 40 | * ```js 41 | * import { DigitalOcean } from 'digitalocean-js'; 42 | * 43 | * const client = new DigitalOcean('your-api-key'); 44 | * const tag = await client.tags.getTagByName('tag-name'); 45 | * ``` 46 | */ 47 | public getTagByName(tagName: string): Promise { 48 | return instance.get(`/tags/${tagName}`).then(response => response.data.tag); 49 | } 50 | 51 | /** 52 | * Add tag to specified resources 53 | * 54 | * ### Example 55 | * ```js 56 | * import { DigitalOcean } from 'digitalocean-js'; 57 | * 58 | * const client = new DigitalOcean('your-api-key'); 59 | * const resources = [ 60 | * 'droplet-id-1', 61 | * 'droplet-id-2', 62 | * 'droplet-id-3' 63 | * ]; 64 | * await client.tags.tagResources('tag-name', resources); 65 | * ``` 66 | */ 67 | public tagResources(tagName: string, resourceIds: string[]): Promise { 68 | const resources = resourceIds.map(id => { 69 | return { 70 | resource_id: id, 71 | resource_type: 'droplet' 72 | }; 73 | }); 74 | return instance.post(`/tags/${tagName}/resources`, { resources }); 75 | } 76 | 77 | /** 78 | * Remove tag from specified resources 79 | * 80 | * ### Example 81 | * ```js 82 | * import { DigitalOcean } from 'digitalocean-js'; 83 | * 84 | * const client = new DigitalOcean('your-api-key'); 85 | * const resources = [ 86 | * 'droplet-id-1', 87 | * 'droplet-id-2', 88 | * 'droplet-id-3' 89 | * ]; 90 | * await client.tags.removeTagFromResources('tag-name', resources); 91 | * ``` 92 | */ 93 | public removeTagFromResources( 94 | tagName: string, 95 | resourceIds: string[] 96 | ): Promise { 97 | const resources = resourceIds.map(id => { 98 | return { 99 | resource_id: id, 100 | resource_type: 'droplet' 101 | }; 102 | }); 103 | return instance.delete(`/tags/${tagName}/resources`, { 104 | data: { resources } 105 | }); 106 | } 107 | 108 | /** 109 | * Delete a tag by tag name 110 | * 111 | * ### Example 112 | * ```js 113 | * import { DigitalOcean } from 'digitalocean-js'; 114 | * 115 | * const client = new DigitalOcean('your-api-key'); 116 | * await client.tags.deleteTag('tag-name'); 117 | * ``` 118 | */ 119 | public deleteTag(tagName: string): Promise { 120 | return instance.delete(`/tags/${tagName}`); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/errors.ts: -------------------------------------------------------------------------------- 1 | import { ERROR_RESPONSE } from './fixtures/error.fixture'; 2 | 3 | export const getErrorResponse = () => ERROR_RESPONSE; 4 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/accounts.fixture.ts: -------------------------------------------------------------------------------- 1 | import { Account } from '../../index'; 2 | 3 | export const ACCOUNTS: Account[] = [ 4 | { 5 | droplet_limit: 25, 6 | floating_ip_limit: 5, 7 | email: 'sammy@digitalocean.com', 8 | uuid: 'uuid-1', 9 | email_verified: true, 10 | status: 'active', 11 | status_message: '' 12 | }, 13 | { 14 | droplet_limit: 30, 15 | floating_ip_limit: 10, 16 | email: 'testy@mctesterson.com', 17 | uuid: 'uuid-2', 18 | email_verified: true, 19 | status: 'active', 20 | status_message: '' 21 | } 22 | ]; 23 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/actions.fixture.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '../../index'; 2 | 3 | export const ACTIONS: Action[] = [ 4 | { 5 | id: 1, 6 | status: 'completed', 7 | type: 'create', 8 | started_at: '2020-11-14T16:29:21Z', 9 | completed_at: '2020-11-14T16:30:06Z', 10 | resource_id: 3164444, 11 | resource_type: 'droplet', 12 | region: { 13 | name: 'New York 3', 14 | slug: 'nyc3', 15 | features: [], 16 | available: true, 17 | sizes: [] 18 | }, 19 | region_slug: 'string' 20 | }, 21 | { 22 | id: 2, 23 | status: 'completed', 24 | type: 'create', 25 | started_at: '2020-11-14T16:29:21Z', 26 | completed_at: '2020-11-14T16:30:06Z', 27 | resource_id: 3164444, 28 | resource_type: 'droplet', 29 | region: { 30 | name: 'New York 3', 31 | slug: 'nyc3', 32 | features: [], 33 | available: true, 34 | sizes: [] 35 | }, 36 | region_slug: 'string' 37 | } 38 | ]; 39 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/balance.fixture.ts: -------------------------------------------------------------------------------- 1 | import { Balance } from '../../index'; 2 | 3 | export const BALANCE: Balance = { 4 | month_to_date_balance: '23.44', 5 | account_balance: '12.23', 6 | month_to_date_usage: '11.21', 7 | generated_at: '2019-07-09T15:01:12Z' 8 | }; 9 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/billing-history.fixture.ts: -------------------------------------------------------------------------------- 1 | import { BillingHistory } from '../../index'; 2 | 3 | export const BILLING_HISTORY: BillingHistory[] = [ 4 | { 5 | description: 'Invoice for May 2018', 6 | amount: '12.34', 7 | invoice_id: '123', 8 | invoice_uuid: 'example-uuid', 9 | date: '2018-06-01T08:44:38Z', 10 | type: 'Invoice' 11 | }, 12 | { 13 | description: 'Payment (MC 2018)', 14 | amount: '-12.34', 15 | date: '2018-06-02T08:44:38Z', 16 | type: 'Payment' 17 | } 18 | ]; 19 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/block-storage.fixture.ts: -------------------------------------------------------------------------------- 1 | import { BlockStorage } from '../../index'; 2 | 3 | export const BLOCK_STORAGE_VOLUMES: BlockStorage[] = [ 4 | { 5 | id: '506f78a4-e098-11e5-ad9f-000f53306ae1', 6 | region: { 7 | name: 'New York 1', 8 | slug: 'nyc1', 9 | sizes: [], 10 | features: [], 11 | available: true 12 | }, 13 | droplet_ids: [], 14 | name: 'example', 15 | description: 'Block store for examples', 16 | size_gigabytes: 10, 17 | created_at: '2016-03-02T17:00:49Z', 18 | filesystem_type: 'ext4', 19 | filesystem_label: 'example', 20 | tags: [] 21 | }, 22 | { 23 | id: '506f78a4-e098-11e5-ad9f-000f53305eb2', 24 | region: { 25 | name: 'New York 1', 26 | slug: 'nyc1', 27 | sizes: [], 28 | features: [], 29 | available: true 30 | }, 31 | droplet_ids: [], 32 | name: 'example', 33 | description: 'Block store for examples', 34 | size_gigabytes: 10, 35 | created_at: '2016-03-02T17:01:49Z', 36 | filesystem_type: 'ext4', 37 | filesystem_label: 'example', 38 | tags: [] 39 | } 40 | ]; 41 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/cdn.fixture.ts: -------------------------------------------------------------------------------- 1 | import { CdnEndpoint } from '../../index'; 2 | 3 | export const CDN_ENDPOINTS: CdnEndpoint[] = [ 4 | { 5 | id: '19f06b6a-3ace-4315-b086-499a0e521b76', 6 | origin: 'static-images.nyc3.digitaloceanspaces.com', 7 | endpoint: 'static-images.nyc3.cdn.digitaloceanspaces.com', 8 | created_at: '2018-07-19T15:04:16Z', 9 | certificate_id: '892071a0-bb95-49bc-8021-3afd67a210bf', 10 | custom_domain: 'static.example.com', 11 | ttl: 3600 12 | }, 13 | { 14 | id: 'a84dd587-17e7-4124-86bd-cbcf433042a2', 15 | origin: 'static-images.nyc3.digitaloceanspaces.com', 16 | endpoint: 'static-images.nyc3.cdn.digitaloceanspaces.com', 17 | created_at: '2018-07-19T15:04:16Z', 18 | certificate_id: '892071a0-bb95-49bc-8021-3afd67a210bf', 19 | custom_domain: 'static.example.com', 20 | ttl: 3600 21 | } 22 | ]; 23 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/error.fixture.ts: -------------------------------------------------------------------------------- 1 | export const ERROR_RESPONSE = { 2 | id: 'forbidden', 3 | message: 'You do not have access for the attempted action.' 4 | }; 5 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/fixtures/projects.fixture.ts: -------------------------------------------------------------------------------- 1 | import { Project } from '../../index'; 2 | 3 | export const PROJECTS: Project[] = [ 4 | { 5 | id: '4e1bfbc3-dc3e-41f2-a18f-1b4d7ba71679', 6 | owner_uuid: '99525febec065ca37b2ffe4f852fd2b2581895e7', 7 | owner_id: 258992, 8 | name: 'my-web-api', 9 | description: 'My website API', 10 | purpose: 'Service or API', 11 | environment: 'Production', 12 | is_default: false, 13 | created_at: '2018-09-27T20:10:35Z', 14 | updated_at: '2018-09-27T20:10:35Z' 15 | }, 16 | { 17 | id: 'addb4547-6bab-419a-8542-76263a033cf6', 18 | owner_uuid: '99525febec065ca37b2ffe4f852fd2b2581895e7', 19 | owner_id: 258992, 20 | name: 'Default', 21 | description: 'Default project', 22 | purpose: 'Just trying out DigitalOcean', 23 | environment: 'Development', 24 | is_default: true, 25 | created_at: '2017-10-19T21:44:20Z', 26 | updated_at: '2019-11-05T18:50:03Z' 27 | } 28 | ]; 29 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/index.ts: -------------------------------------------------------------------------------- 1 | export * from './errors'; 2 | export * from './models'; 3 | -------------------------------------------------------------------------------- /packages/digitalocean-js/src/test/models.ts: -------------------------------------------------------------------------------- 1 | import { ACCOUNTS } from './fixtures/accounts.fixture'; 2 | import { ACTIONS } from './fixtures/actions.fixture'; 3 | import { BALANCE } from './fixtures/balance.fixture'; 4 | import { BILLING_HISTORY } from './fixtures/billing-history.fixture'; 5 | import { BLOCK_STORAGE_VOLUMES } from './fixtures/block-storage.fixture'; 6 | import { CDN_ENDPOINTS } from './fixtures/cdn.fixture'; 7 | import { PROJECTS } from './fixtures/projects.fixture'; 8 | 9 | // Accounts 10 | export const getAccounts = () => ACCOUNTS; 11 | export const getSingleAccount = () => ACCOUNTS[0]; 12 | 13 | // Actions 14 | export const getActions = () => ACTIONS; 15 | export const getSingleAction = () => ACTIONS[0]; 16 | 17 | // Billing History 18 | export const getBillingHistory = () => BILLING_HISTORY; 19 | export const getSingleBillingHistoryItem = () => BILLING_HISTORY[0]; 20 | export const getBalance = () => BALANCE; 21 | 22 | // Block Storage 23 | export const getBlockStorageVolumes = () => BLOCK_STORAGE_VOLUMES; 24 | export const getSingleBlockStorageVolume = () => BLOCK_STORAGE_VOLUMES[0]; 25 | 26 | // CDN 27 | export const getCdnEndpoints = () => CDN_ENDPOINTS; 28 | export const getSingleCdnEndpoint = () => CDN_ENDPOINTS[0]; 29 | 30 | // Projects 31 | export const getProjects = () => PROJECTS; 32 | export const getSingleProject = () => PROJECTS[0]; 33 | -------------------------------------------------------------------------------- /packages/digitalocean-js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "forceConsistentCasingInFileNames": true, 6 | "strict": true, 7 | "noImplicitOverride": true, 8 | "noPropertyAccessFromIndexSignature": true, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true 11 | }, 12 | "files": [], 13 | "include": [], 14 | "references": [ 15 | { 16 | "path": "./tsconfig.lib.json" 17 | }, 18 | { 19 | "path": "./tsconfig.spec.json" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/digitalocean-js/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "declaration": true, 6 | "types": [] 7 | }, 8 | "include": [ 9 | "**/*.ts" 10 | ], 11 | "exclude": [ 12 | "**/*.spec.ts", 13 | "jest.config.ts", 14 | "./src/test/**/*" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/digitalocean-js/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "module": "commonjs", 6 | "types": ["jest", "node"] 7 | }, 8 | "include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts", "jest.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /tools/tsconfig.tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "../dist/out-tsc/tools", 5 | "rootDir": ".", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": ["node"], 9 | "importHelpers": false 10 | }, 11 | "include": ["**/*.ts"] 12 | } 13 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "allowSyntheticDefaultImports": true, 11 | "esModuleInterop": true, 12 | "importHelpers": true, 13 | "target": "es2017", 14 | "module": "esnext", 15 | "lib": ["es2017", "dom"], 16 | "skipLibCheck": true, 17 | "skipDefaultLibCheck": true, 18 | "baseUrl": ".", 19 | "paths": { 20 | "@digitalocean-js/digitalocean-js": [ 21 | "packages/digitalocean-js/src/index.ts" 22 | ] 23 | } 24 | }, 25 | "exclude": ["node_modules", "tmp"] 26 | } 27 | -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "entryPoints": [ 3 | "packages/digitalocean-js/src/index.ts" 4 | ], 5 | "tsconfig": "packages/digitalocean-js/tsconfig.json", 6 | "exclude": [ 7 | "**/*.spec.ts", 8 | "**/test/**/*" 9 | ], 10 | "readme": "./README.md", 11 | "excludePrivate": true, 12 | "out": "dist/docs/digitalocean-js", 13 | "gaID": "G-479J4KXVE4" 14 | } 15 | --------------------------------------------------------------------------------