Skip to content

Commit 66a299c

Browse files
committed
Fixed issue with key deletion.
1 parent 4119e09 commit 66a299c

6 files changed

Lines changed: 19 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `transcribe` method will now return transcription results for both urls or buffers.
13+
- `keys` now provides `create`, `list`, and `delete` methods that allow managing of
14+
API keys.
1315

1416
---
1517

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Deepgram Node.js SDK
22

3-
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](CODE_OF_CONDUCT.md)
3+
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/deepgram/node-sdk/CI/main) ![npm (scoped)](https://img.shields.io/npm/v/deepgram/node-sdk) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-rounded)](CODE_OF_CONDUCT.md)
44

55
Node.js official SDK for [Deepgram](https://www.deepgram.com/)'s automated
66
speech recognition APIs.
@@ -55,7 +55,7 @@ const response = await deepgram.transcribe(URL_OR_BUFFER_OF_FILE, {
5555
```js
5656
{
5757
// AI model used to process submitted audio.
58-
model?: "general" | "phonecall" | "meeting" | <custom-id>,
58+
model?: "general" | "phonecall" | "meeting" | "<custom-id>",
5959

6060
// BCP-47 language tag that hints at the primary spoken language.
6161
// Defaults to en-US

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deepgram/sdk",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "An SDK for the Deepgram automated speech recognition platform",
55
"main": "out/deepgram.js",
66
"scripts": {

sample/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function main() {
2020
console.log(err);
2121
});
2222

23-
let key;
23+
let key = 'Xwr5JGdWhUciiNLZ';
2424
deepgram.keys.create('test')
2525
.then((result) => {
2626
key = result.key
@@ -32,7 +32,7 @@ function main() {
3232
})
3333
.catch((err) => {
3434
console.log(err);
35-
})
35+
});
3636
}
3737

3838
})

src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ export class Deepgram {
6666
);
6767
},
6868

69-
delete: async (
70-
credentials: string,
71-
apiUrl: string,
72-
key: string
73-
): Promise<void> => {
69+
delete: async (key: string): Promise<void> => {
7470
return await Keys.delete(
7571
this._credentials,
7672
this.options.apiUrl || "",

src/keys.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export const Keys = {
2727
const _requestOptions = (
2828
credentials: string,
2929
apiUrl: string,
30-
method: string
30+
method: string,
31+
payload?: unknown
3132
): RequestOptions => {
3233
return {
3334
host: apiUrl,
@@ -36,6 +37,11 @@ const _requestOptions = (
3637
headers: {
3738
"Content-Type": "application/json",
3839
Authorization: `Basic ${credentials}`,
40+
"Content-Length": payload
41+
? typeof payload === "string"
42+
? Buffer.byteLength(payload)
43+
: Buffer.byteLength(JSON.stringify(payload))
44+
: undefined,
3945
},
4046
};
4147
};
@@ -46,7 +52,7 @@ function _request<T>(
4652
apiUrl: string,
4753
payload?: unknown
4854
): Promise<T> {
49-
const requestOptions = _requestOptions(credentials, apiUrl, method);
55+
const requestOptions = _requestOptions(credentials, apiUrl, method, payload);
5056
return new Promise((resolve, reject) => {
5157
try {
5258
const httpRequest = request(requestOptions, (dgRes) => {
@@ -74,7 +80,9 @@ function _request<T>(
7480
});
7581

7682
if (payload) {
77-
httpRequest.write(payload);
83+
httpRequest.write(
84+
typeof payload === "string" ? payload : JSON.stringify(payload)
85+
);
7886
}
7987

8088
httpRequest.end();

0 commit comments

Comments
 (0)