-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64b920b
commit a1448e4
Showing
6 changed files
with
31 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
"incremental": true | ||
}, | ||
"include": [ | ||
"./index.ts" | ||
"index.ts" | ||
], | ||
"exclude": [ | ||
"dist", | ||
|