Skip to content

Commit

Permalink
BREAKING(npm): publish 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard committed Dec 1, 2023
1 parent 64b920b commit a1448e4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 50 deletions.
42 changes: 12 additions & 30 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import createClient from 'openapi-fetch'
import { paths } from './third_party/schema'

type Client = ReturnType<typeof createClient<paths>>

export class Vultr {
#client

delete: Client['DELETE']
get: Client['GET']
patch: Client['PATCH']
post: Client['POST']
put: Client['PUT']

constructor(options: {
token: string
}) {
this.#client = createClient<paths>({
baseUrl: 'https://api.vultr.com/v2',
headers: {
Authorization: `Bearer ${options.token}`
}
})

this.delete = this.#client.DELETE
this.get = this.#client.GET
this.patch = this.#client.PATCH
this.post = this.#client.POST
this.put = this.#client.PUT
}
import createOpenAPIClient from 'openapi-fetch'
import { paths } from './third_party/v2'

export type Client = ReturnType<typeof createOpenAPIClient<paths>>

export function createClient({ token }: { token: string }) {
return createOpenAPIClient<paths>({
baseUrl: 'https://api.vultr.com/v2',
headers: {
Authorization: `Bearer ${token}`
}
})
}
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@boywithkeyboard/vultr.js",
"version": "1.0.0",
"name": "openapi-vultr",
"version": "2.0.0",
"author": "Samuel Kopp (https://samuelkopp.de)",
"license": "Apache-2.0",
"description": "A type-safe JavaScript SDK for Vultr.",
"description": "An OpenAPI client for Vultr's API written in TypeScript.",
"funding": "https://github.com/sponsors/boywithkeyboard",
"repository": "github:boywithkeyboard/vultr.js",
"repository": "github:boywithkeyboard/openapi-vultr",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand All @@ -24,6 +24,16 @@
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
}
},
"./v2": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
}
}
},
"scripts": {
Expand Down
19 changes: 4 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
## vultr.js

> [!NOTE]
> vultr.js is merely a preconfigured instance of [openapi-fetch](https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-fetch), based on the official OpenAPI schema by Vultr.
## openapi-vultr

### Setup

#### Deno

```ts
import { Vultr } from 'https://esm.sh/@boywithkeyboard/vultr.js'
```

#### Node.js

```bash
npm i @boywithkeyboard/vultr.js
npm i openapi-vultr
```

```ts
import { Vultr } from '@boywithkeyboard/vultr.js'
import { createClient } from 'openapi-vultr/v2'
```

### Usage

```ts
const client = new Vultr({
const client = new createClient({
token: '...'
})
```
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"incremental": true
},
"include": [
"./index.ts"
"index.ts"
],
"exclude": [
"dist",
Expand Down

0 comments on commit a1448e4

Please sign in to comment.