New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@deepgram/sdk

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deepgram/sdk - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

14

CHANGELOG.md

@@ -12,2 +12,13 @@ # Changelog

## [1.0.3]
### Added
- In addition to a Url and Buffer, `trascricription.preRecorded` now accepts a
ReadStream as a source of the file to transcribe.
### Updated
- Removed a console log that occurred when an HTTP request ended
## [1.0.2]

@@ -100,3 +111,4 @@

[unreleased]: https://github.com/deepgram/node-sdk/compare/1.0.2...HEAD
[unreleased]: https://github.com/deepgram/node-sdk/compare/1.0.3...HEAD
[1.0.3]: https://github.com/deepgram/node-sdk/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/deepgram/node-sdk/compare/1.0.0...1.0.2

@@ -103,0 +115,0 @@ [1.0.0]: https://github.com/deepgram/node-sdk/compare/0.6.5...1.0.0

3

dist/httpRequest.d.ts
/// <reference types="node" />
export declare function _request<T>(method: string, api_key: string, apiUrl: string, path: string, payload?: string | Buffer, options?: Object): Promise<T>;
import { ReadStream } from "fs";
export declare function _request<T>(method: string, api_key: string, apiUrl: string, path: string, payload?: string | Buffer | ReadStream, options?: Object): Promise<T>;

@@ -15,2 +15,3 @@ "use strict";

exports._request = void 0;
var fs_1 = require("fs");
var https_1 = require("https");

@@ -21,2 +22,6 @@ var userAgent_1 = require("./userAgent");

override_options) {
var additionalHeaders = {};
if (payload && !(payload instanceof fs_1.ReadStream)) {
additionalHeaders["Content-Length"] = Buffer.byteLength(payload);
}
var options = {

@@ -26,12 +31,4 @@ host: apiUrl,

method: method,
headers: {
"User-Agent": userAgent_1.userAgent(),
"Content-Type": "application/json",
Authorization: "token " + api_key,
"Content-Length": payload ? Buffer.byteLength(payload) : undefined,
},
headers: __assign({ "User-Agent": userAgent_1.userAgent(), "Content-Type": "application/json", Authorization: "token " + api_key }, additionalHeaders),
};
if (payload === undefined) {
delete options.headers["Content-Length"];
}
var headers = options.headers;

@@ -49,3 +46,3 @@ if (override_options && override_options.headers) {

try {
var httpRequest = https_1.request(requestOptions, function (dgRes) {
var httpRequest_1 = https_1.request(requestOptions, function (dgRes) {
var dgResContent = "";

@@ -58,3 +55,2 @@ dgRes.on("data", function (chunk) {

try {
console.log("content: " + dgResContent);
dgResponse = JSON.parse(dgResContent);

@@ -74,9 +70,21 @@ }

});
httpRequest.on("error", function (err) {
httpRequest_1.on("error", function (err) {
reject("DG: " + err);
});
if (payload) {
httpRequest.write(payload);
if (payload instanceof fs_1.ReadStream) {
payload.pipe(httpRequest_1);
payload.on("finish", function () {
httpRequest_1.end();
});
}
else {
// It's a buffer
httpRequest_1.write(payload);
httpRequest_1.end();
}
}
httpRequest.end();
else {
httpRequest_1.end();
}
}

@@ -83,0 +91,0 @@ catch (err) {

@@ -61,2 +61,12 @@ "use strict";

}
function isBufferSource(providedSource) {
if (providedSource.buffer)
return true;
return false;
}
function isReadStreamSource(providedSource) {
if (providedSource.stream)
return true;
return false;
}
/**

@@ -69,3 +79,3 @@ * Transcribes audio from a file or buffer

var preRecordedTranscription = function (apiKey, apiUrl, source, options) { return __awaiter(void 0, void 0, void 0, function () {
var transcriptionOptions;
var transcriptionOptions, body, requestOptions;
return __generator(this, function (_a) {

@@ -77,11 +87,23 @@ switch (_a.label) {

(source.mimetype === undefined || source.mimetype.length === 0)) {
throw new Error("DG: Mimetype must be provided if the source is a Buffer");
throw new Error("DG: Mimetype must be provided if the source is a Buffer or a ReadStream");
}
return [4 /*yield*/, httpRequest_1._request("POST", apiKey, apiUrl, "/v1/listen?" + querystring_1.default.stringify(transcriptionOptions), isUrlSource(source) ? JSON.stringify(source) : source.buffer, isUrlSource(source)
? undefined
: {
headers: {
"Content-Type": source.mimetype,
},
})];
if (isUrlSource(source)) {
body = JSON.stringify(source);
}
else if (isBufferSource(source)) {
body = source.buffer;
}
else if (isReadStreamSource(source)) {
body = source.stream;
}
else {
throw new Error("Unknown TranscriptionSource type");
}
requestOptions = {};
if (!isUrlSource(source)) {
requestOptions.headers = {
"Content-Type": source.mimetype,
};
}
return [4 /*yield*/, httpRequest_1._request("POST", apiKey, apiUrl, "/v1/listen?" + querystring_1.default.stringify(transcriptionOptions), body, requestOptions)];
case 1: return [2 /*return*/, _a.sent()];

@@ -88,0 +110,0 @@ }

/// <reference types="node" />
export declare type TranscriptionSource = UrlSource | BufferSource;
import { ReadStream } from "fs";
export declare type TranscriptionSource = UrlSource | BufferSource | ReadStreamSource;
export declare type ReadStreamSource = {
stream: ReadStream;
mimetype: string;
};
export declare type UrlSource = {

@@ -4,0 +9,0 @@ url: string;

{
"name": "@deepgram/sdk",
"version": "1.0.2",
"version": "1.0.3",
"description": "An SDK for the Deepgram automated speech recognition platform",

@@ -10,4 +10,4 @@ "main": "dist/index.js",

"coverage": "nyc npm run test",
"lint": "eslint ./src --ext .ts && prettier --config .prettierrc src/**/*.ts --write",
"test": "mocha -r ts-node/register tests/**/*test.ts --insect",
"lint": "eslint ./src --ext .ts && prettier --config .prettierrc src/*.ts src/**/*.ts --write",
"test": "mocha -r ts-node/register tests/*test.ts tests/**/*test.ts --insect",
"watch": "nodemon -e ts --watch src --exec \"npm run build\""

@@ -14,0 +14,0 @@ },

# Deepgram Node.js SDK
![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/sdk) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-rounded)](CODE_OF_CONDUCT.md)
[![CI](https://github.com/deepgram/node-sdk/actions/workflows/CI.yml/badge.svg)](https://github.com/deepgram/node-sdk/actions/workflows/CI.yml) [![npm (scoped)](https://img.shields.io/npm/v/@deepgram/sdk)](https://www.npmjs.com/package/@deepgram/sdk) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-rounded)](CODE_OF_CONDUCT.md)

@@ -8,2 +8,4 @@ Official Node.js SDK for [Deepgram](https://www.deepgram.com/)'s automated

> This SDK only supports the new beta Deepgram API.
To access the API you will need a Deepgram account. Sign up for free at

@@ -33,6 +35,3 @@ [signup][signup].

const deepgram = new Deepgram({
apiKey: DEEPGRAM_API_KEY,
apiUrl: CUSTOM_API_URL, // Optionally used for on-premises customers
});
const deepgram = new Deepgram(DEEPGRAM_API_KEY);
```

@@ -59,5 +58,8 @@

// Sending a ReadStream
const streamSource = { stream: fs.createReadStream("/path/to/file"), mimetype: MIMETYPE_OF_FILE };
// Both fileSource or bufferSource could be provided as the source parameter
const response = await deepgram.transcription.preRecorded(
fileSource | bufferSource,
fileSource | bufferSource | streamSource,
{

@@ -64,0 +66,0 @@ punctuate: true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc