diff --git a/package.json b/package.json index 0b33a69..2a5c657 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "homepage": "https://github.com/deepgram-starters/node-text-intelligence#readme", "dependencies": { - "@deepgram/sdk": "4.11.3", + "@deepgram/sdk": "5.0.0-beta.4", "cors": "2.8.5", "dotenv": "17.2.3", "express": "5.2.1", @@ -52,4 +52,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 126ab99..60ac4cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@deepgram/sdk': - specifier: 4.11.3 - version: 4.11.3 + specifier: 5.0.0-beta.4 + version: 5.0.0-beta.4 cors: specifier: 2.8.5 version: 2.8.5 @@ -33,17 +33,10 @@ importers: packages: - '@deepgram/captions@1.2.0': - resolution: {integrity: sha512-8B1C/oTxTxyHlSFubAhNRgCbQ2SQ5wwvtlByn8sDYZvdDtdn/VE2yEPZ4BvUnrKWmsbTQY6/ooLV+9Ka2qmDSQ==} + '@deepgram/sdk@5.0.0-beta.4': + resolution: {integrity: sha512-i1Vb5h9W06UHlYVsGaOMIC4kQIil5z/SfzrsUQVUU0UYAuyf5QbcCgtdf+mkElb+aVYokP0Qt0avWYFTfVVmAw==} engines: {node: '>=18.0.0'} - '@deepgram/sdk@4.11.3': - resolution: {integrity: sha512-7NujHlAX6ciBeYAkxkhE7LCZWy0JK3nvFsV2VwVZIUiFR40ykhep5fxYd7ZovM+PbNyCoM8GKNMHu9MeQ5/wTQ==} - engines: {node: '>=18.0.0'} - - '@types/node@18.19.130': - resolution: {integrity: sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==} - accepts@2.0.0: resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==} engines: {node: '>= 0.6'} @@ -112,12 +105,6 @@ packages: resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==} engines: {node: '>= 0.10'} - cross-fetch@3.2.0: - resolution: {integrity: sha512-Q+xVJLoGOeIMXZmbUK4HYk+69cQH6LudR0Vu/pRm2YlU/hDV9CiS0gKUMaWY5f2NeUH9C1nV3bsTlCo0FsTV1Q==} - - dayjs@1.11.19: - resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==} - debug@4.4.3: resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} engines: {node: '>=6.0'} @@ -127,10 +114,6 @@ packages: supports-color: optional: true - deepmerge@4.3.1: - resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} - engines: {node: '>=0.10.0'} - depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -172,10 +155,6 @@ packages: resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} engines: {node: '>= 0.6'} - events@3.3.0: - resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} - engines: {node: '>=0.8.x'} - express@5.2.1: resolution: {integrity: sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==} engines: {node: '>= 18'} @@ -334,15 +313,6 @@ packages: resolution: {integrity: sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==} engines: {node: '>= 0.6'} - node-fetch@2.7.0: - resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - nodemon@3.1.10: resolution: {integrity: sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==} engines: {node: '>=10'} @@ -474,9 +444,6 @@ packages: resolution: {integrity: sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==} hasBin: true - tr46@0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - type-is@2.0.1: resolution: {integrity: sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==} engines: {node: '>= 0.6'} @@ -484,9 +451,6 @@ packages: undefsafe@2.0.5: resolution: {integrity: sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==} - undici-types@5.26.5: - resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} - unpipe@1.0.0: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} @@ -495,12 +459,6 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} - webidl-conversions@3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - - whatwg-url@5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - wrappy@1.0.2: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} @@ -518,27 +476,13 @@ packages: snapshots: - '@deepgram/captions@1.2.0': + '@deepgram/sdk@5.0.0-beta.4': dependencies: - dayjs: 1.11.19 - - '@deepgram/sdk@4.11.3': - dependencies: - '@deepgram/captions': 1.2.0 - '@types/node': 18.19.130 - cross-fetch: 3.2.0 - deepmerge: 4.3.1 - events: 3.3.0 ws: 8.18.3 transitivePeerDependencies: - bufferutil - - encoding - utf-8-validate - '@types/node@18.19.130': - dependencies: - undici-types: 5.26.5 - accepts@2.0.0: dependencies: mime-types: 3.0.2 @@ -617,22 +561,12 @@ snapshots: object-assign: 4.1.1 vary: 1.1.2 - cross-fetch@3.2.0: - dependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - - dayjs@1.11.19: {} - debug@4.4.3(supports-color@5.5.0): dependencies: ms: 2.1.3 optionalDependencies: supports-color: 5.5.0 - deepmerge@4.3.1: {} - depd@2.0.0: {} dotenv@17.2.3: {} @@ -663,8 +597,6 @@ snapshots: etag@1.8.1: {} - events@3.3.0: {} - express@5.2.1: dependencies: accepts: 2.0.0 @@ -852,10 +784,6 @@ snapshots: negotiator@1.0.0: {} - node-fetch@2.7.0: - dependencies: - whatwg-url: 5.0.0 - nodemon@3.1.10: dependencies: chokidar: 3.6.0 @@ -1006,8 +934,6 @@ snapshots: touch@3.1.1: {} - tr46@0.0.3: {} - type-is@2.0.1: dependencies: content-type: 1.0.5 @@ -1016,19 +942,10 @@ snapshots: undefsafe@2.0.5: {} - undici-types@5.26.5: {} - unpipe@1.0.0: {} vary@1.1.2: {} - webidl-conversions@3.0.1: {} - - whatwg-url@5.0.0: - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - wrappy@1.0.2: {} ws@8.18.3: {} diff --git a/server.js b/server.js index 081aab0..848632d 100644 --- a/server.js +++ b/server.js @@ -14,7 +14,7 @@ require("dotenv").config(); -const { createClient } = require("@deepgram/sdk"); +const { DeepgramClient } = require("@deepgram/sdk"); const cors = require("cors"); const crypto = require("crypto"); const express = require("express"); @@ -100,7 +100,7 @@ function loadApiKey() { const apiKey = loadApiKey(); // Initialize Deepgram client -const deepgram = createClient(apiKey); +const deepgram = new DeepgramClient({ apiKey }); // Initialize Express app const app = express(); @@ -269,21 +269,8 @@ app.post('/api/text-intelligence', requireSession, async (req, res) => { options.intents = true; } - // Call Deepgram API (SDK v4 returns { result, error }) - const { result, error } = await deepgram.read.analyzeText({ text: textContent }, options); - - // Handle SDK errors - if (error) { - console.error('Deepgram API Error:', error); - return res.status(400).json({ - error: { - type: "processing_error", - code: "INVALID_TEXT", - message: error.message || 'Failed to process text', - details: {} - } - }); - } + // Call Deepgram API (SDK v5 throws on error) + const result = await deepgram.read.v1.text.analyze({ ...options, body: { text: textContent } }); // Return full results object (includes all requested features) res.json({