Skip to content

Commit

Permalink
Fixed issue with key deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljolley committed May 4, 2021
1 parent 4119e09 commit 66a299c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

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

---

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deepgram Node.js SDK

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](CODE_OF_CONDUCT.md)
![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)

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

// BCP-47 language tag that hints at the primary spoken language.
// Defaults to en-US
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deepgram/sdk",
"version": "0.5.0",
"version": "0.6.0",
"description": "An SDK for the Deepgram automated speech recognition platform",
"main": "out/deepgram.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions sample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function main() {
console.log(err);
});

let key;
let key = 'Xwr5JGdWhUciiNLZ';
deepgram.keys.create('test')
.then((result) => {
key = result.key
Expand All @@ -32,7 +32,7 @@ function main() {
})
.catch((err) => {
console.log(err);
})
});
}

})
Expand Down
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ export class Deepgram {
);
},

delete: async (
credentials: string,
apiUrl: string,
key: string
): Promise<void> => {
delete: async (key: string): Promise<void> => {
return await Keys.delete(
this._credentials,
this.options.apiUrl || "",
Expand Down
14 changes: 11 additions & 3 deletions src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const Keys = {
const _requestOptions = (
credentials: string,
apiUrl: string,
method: string
method: string,
payload?: unknown
): RequestOptions => {
return {
host: apiUrl,
Expand All @@ -36,6 +37,11 @@ const _requestOptions = (
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${credentials}`,
"Content-Length": payload
? typeof payload === "string"
? Buffer.byteLength(payload)
: Buffer.byteLength(JSON.stringify(payload))
: undefined,
},
};
};
Expand All @@ -46,7 +52,7 @@ function _request<T>(
apiUrl: string,
payload?: unknown
): Promise<T> {
const requestOptions = _requestOptions(credentials, apiUrl, method);
const requestOptions = _requestOptions(credentials, apiUrl, method, payload);
return new Promise((resolve, reject) => {
try {
const httpRequest = request(requestOptions, (dgRes) => {
Expand Down Expand Up @@ -74,7 +80,9 @@ function _request<T>(
});

if (payload) {
httpRequest.write(payload);
httpRequest.write(
typeof payload === "string" ? payload : JSON.stringify(payload)
);
}

httpRequest.end();
Expand Down

0 comments on commit 66a299c

Please sign in to comment.