@deepgram/sdk 5.0.0-beta.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -1472
- package/dist/browser/index.global.js +288 -192
- package/dist/cjs/BaseClient.js +3 -3
- package/dist/cjs/CustomClient.js +90 -107
- package/dist/cjs/api/resources/agent/exports.d.ts +3 -0
- package/dist/cjs/api/resources/agent/exports.js +22 -0
- package/dist/cjs/api/resources/agent/resources/v1/client/Client.d.ts +6 -0
- package/dist/cjs/api/resources/agent/resources/v1/client/Client.js +8 -3
- package/dist/cjs/api/resources/agent/resources/v1/client/Socket.d.ts +3 -2
- package/dist/cjs/api/resources/agent/resources/v1/client/Socket.js +4 -0
- package/dist/cjs/api/resources/agent/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/agent/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/agent/resources/v1/resources/settings/exports.d.ts +3 -0
- package/dist/cjs/api/resources/agent/resources/v1/resources/settings/exports.js +22 -0
- package/dist/cjs/api/resources/agent/resources/v1/resources/settings/resources/think/exports.d.ts +3 -0
- package/dist/cjs/api/resources/agent/resources/v1/resources/settings/resources/think/exports.js +22 -0
- package/dist/cjs/api/resources/agent/resources/v1/resources/settings/resources/think/resources/models/exports.d.ts +2 -0
- package/dist/cjs/api/resources/agent/resources/v1/resources/settings/resources/think/resources/models/exports.js +21 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1ReceiveFunctionCallResponse.d.ts +1 -1
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SendFunctionCallResponse.d.ts +1 -1
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1Settings.d.ts +21 -51
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.ts +5 -5
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1ThinkUpdated.d.ts +4 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1ThinkUpdated.js +3 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateSpeak.d.ts +2 -11
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateThink.d.ts +9 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateThink.js +3 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/index.d.ts +2 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/index.js +2 -0
- package/dist/cjs/api/resources/auth/exports.d.ts +3 -0
- package/dist/cjs/api/resources/auth/exports.js +22 -0
- package/dist/cjs/api/resources/auth/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/auth/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/auth/resources/v1/resources/tokens/exports.d.ts +2 -0
- package/dist/cjs/api/resources/auth/resources/v1/resources/tokens/exports.js +21 -0
- package/dist/cjs/api/resources/listen/exports.d.ts +3 -0
- package/dist/cjs/api/resources/listen/exports.js +22 -0
- package/dist/cjs/api/resources/listen/resources/v1/client/Client.d.ts +35 -28
- package/dist/cjs/api/resources/listen/resources/v1/client/Client.js +40 -30
- package/dist/cjs/api/resources/listen/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/listen/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/listen/resources/v1/resources/media/client/requests/MediaTranscribeRequestOctetStream.d.ts +0 -3
- package/dist/cjs/api/resources/listen/resources/v1/resources/media/exports.d.ts +2 -0
- package/dist/cjs/api/resources/listen/resources/v1/resources/media/exports.js +21 -0
- package/dist/cjs/api/resources/listen/resources/v1/types/ListenV1Results.d.ts +8 -8
- package/dist/cjs/api/resources/listen/resources/v2/client/Client.d.ts +16 -9
- package/dist/cjs/api/resources/listen/resources/v2/client/Client.js +29 -11
- package/dist/cjs/api/resources/listen/resources/v2/client/Socket.d.ts +3 -2
- package/dist/cjs/api/resources/listen/resources/v2/client/Socket.js +4 -0
- package/dist/cjs/api/resources/listen/resources/v2/exports.d.ts +2 -0
- package/dist/cjs/api/resources/listen/resources/v2/exports.js +21 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2Configure.d.ts +22 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2Configure.js +3 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2ConfigureFailure.d.ts +12 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2ConfigureFailure.js +3 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2ConfigureSuccess.d.ts +30 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2ConfigureSuccess.js +3 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/index.d.ts +3 -0
- package/dist/cjs/api/resources/listen/resources/v2/types/index.js +3 -0
- package/dist/cjs/api/resources/manage/exports.d.ts +3 -0
- package/dist/cjs/api/resources/manage/exports.js +22 -0
- package/dist/cjs/api/resources/manage/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/manage/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/models/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/models/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/exports.d.ts +3 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/exports.js +22 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/exports.d.ts +3 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/exports.js +22 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/balances/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/balances/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/breakdown/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/breakdown/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/fields/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/fields/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/purchases/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/purchases/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/keys/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/keys/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/members/exports.d.ts +3 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/members/exports.js +22 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/members/resources/invites/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/members/resources/invites/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/members/resources/scopes/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/members/resources/scopes/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/models/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/models/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/requests/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/requests/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/client/Client.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/client/Client.js +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/exports.d.ts +3 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/exports.js +22 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/breakdown/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/breakdown/exports.js +21 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/fields/exports.d.ts +2 -0
- package/dist/cjs/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/fields/exports.js +21 -0
- package/dist/cjs/api/resources/read/exports.d.ts +3 -0
- package/dist/cjs/api/resources/read/exports.js +22 -0
- package/dist/cjs/api/resources/read/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/read/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/read/resources/v1/resources/text/exports.d.ts +2 -0
- package/dist/cjs/api/resources/read/resources/v1/resources/text/exports.js +21 -0
- package/dist/cjs/api/resources/selfHosted/exports.d.ts +3 -0
- package/dist/cjs/api/resources/selfHosted/exports.js +22 -0
- package/dist/cjs/api/resources/selfHosted/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/selfHosted/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/selfHosted/resources/v1/resources/distributionCredentials/exports.d.ts +2 -0
- package/dist/cjs/api/resources/selfHosted/resources/v1/resources/distributionCredentials/exports.js +21 -0
- package/dist/cjs/api/resources/speak/exports.d.ts +3 -0
- package/dist/cjs/api/resources/speak/exports.js +22 -0
- package/dist/cjs/api/resources/speak/resources/v1/client/Client.d.ts +11 -4
- package/dist/cjs/api/resources/speak/resources/v1/client/Client.js +13 -7
- package/dist/cjs/api/resources/speak/resources/v1/exports.d.ts +3 -0
- package/dist/cjs/api/resources/speak/resources/v1/exports.js +22 -0
- package/dist/cjs/api/resources/speak/resources/v1/resources/audio/client/Client.d.ts +1 -0
- package/dist/cjs/api/resources/speak/resources/v1/resources/audio/client/Client.js +1 -0
- package/dist/cjs/api/resources/speak/resources/v1/resources/audio/exports.d.ts +2 -0
- package/dist/cjs/api/resources/speak/resources/v1/resources/audio/exports.js +21 -0
- package/dist/cjs/api/resources/speak/resources/v1/types/SpeakV1Metadata.d.ts +4 -2
- package/dist/cjs/api/types/Anthropic.d.ts +2 -2
- package/dist/cjs/api/types/AwsBedrockThinkProvider.d.ts +7 -7
- package/dist/cjs/api/types/AwsPollySpeakProvider.d.ts +2 -2
- package/dist/cjs/api/types/BillingBreakdownV1Response.d.ts +6 -6
- package/dist/cjs/api/types/Cartesia.d.ts +2 -2
- package/dist/cjs/api/types/CreateKeyV1Response.d.ts +6 -6
- package/dist/cjs/api/types/CreateProjectDistributionCredentialsV1Response.d.ts +1 -1
- package/dist/cjs/api/types/CreateProjectInviteV1Response.d.ts +1 -1
- package/dist/cjs/api/types/Deepgram.d.ts +1 -1
- package/dist/cjs/api/types/DeleteProjectInviteV1Response.d.ts +1 -1
- package/dist/cjs/api/types/DeleteProjectKeyV1Response.d.ts +1 -1
- package/dist/cjs/api/types/DeleteProjectMemberV1Response.d.ts +1 -1
- package/dist/cjs/api/types/DeleteProjectV1Response.d.ts +1 -1
- package/dist/cjs/api/types/ElevenLabsSpeakProvider.d.ts +3 -3
- package/dist/cjs/api/types/ErrorResponseLegacyError.d.ts +3 -3
- package/dist/cjs/api/types/ErrorResponseModernError.d.ts +4 -4
- package/dist/cjs/api/types/GetProjectBalanceV1Response.d.ts +4 -4
- package/dist/cjs/api/types/GetProjectDistributionCredentialsV1Response.d.ts +1 -1
- package/dist/cjs/api/types/GetProjectKeyV1Response.d.ts +13 -13
- package/dist/cjs/api/types/GetProjectRequestV1Response.d.ts +1 -1
- package/dist/cjs/api/types/GetProjectV1Response.d.ts +3 -3
- package/dist/cjs/api/types/Google.d.ts +2 -2
- package/dist/cjs/api/types/GrantV1Response.d.ts +1 -1
- package/dist/cjs/api/types/Groq.d.ts +2 -2
- package/dist/cjs/api/types/LeaveProjectV1Response.d.ts +1 -1
- package/dist/cjs/api/types/ListBillingFieldsV1Response.d.ts +4 -4
- package/dist/cjs/api/types/ListModelsV1Response.d.ts +2 -2
- package/dist/cjs/api/types/ListModelsV1ResponseSttModels.d.ts +9 -9
- package/dist/cjs/api/types/ListModelsV1ResponseTtsModels.d.ts +14 -14
- package/dist/cjs/api/types/ListProjectBalancesV1Response.d.ts +5 -5
- package/dist/cjs/api/types/ListProjectDistributionCredentialsV1Response.d.ts +2 -2
- package/dist/cjs/api/types/ListProjectInvitesV1Response.d.ts +3 -3
- package/dist/cjs/api/types/ListProjectKeysV1Response.d.ts +9 -9
- package/dist/cjs/api/types/ListProjectMemberScopesV1Response.d.ts +1 -1
- package/dist/cjs/api/types/ListProjectMembersV1Response.d.ts +3 -3
- package/dist/cjs/api/types/ListProjectPurchasesV1Response.d.ts +7 -7
- package/dist/cjs/api/types/ListProjectRequestsV1Response.d.ts +3 -3
- package/dist/cjs/api/types/ListProjectsV1Response.d.ts +3 -3
- package/dist/cjs/api/types/ListenV1ResponseMetadata.d.ts +18 -18
- package/dist/cjs/api/types/ListenV1ResponseResults.d.ts +5 -5
- package/dist/cjs/api/types/ListenV1ResponseResultsChannelsItem.d.ts +43 -43
- package/dist/cjs/api/types/ListenV1ResponseResultsSummary.d.ts +2 -2
- package/dist/cjs/api/types/ListenV1ResponseResultsUtterancesItem.d.ts +15 -15
- package/dist/cjs/api/types/OpenAiSpeakProvider.d.ts +27 -0
- package/dist/cjs/api/types/OpenAiSpeakProvider.js +21 -0
- package/dist/cjs/api/types/OpenAiThinkProvider.d.ts +23 -0
- package/dist/cjs/api/types/OpenAiThinkProvider.js +18 -0
- package/dist/cjs/api/types/ProjectRequestResponse.d.ts +9 -9
- package/dist/cjs/api/types/ReadV1ResponseMetadata.d.ts +20 -20
- package/dist/cjs/api/types/ReadV1ResponseResults.d.ts +4 -4
- package/dist/cjs/api/types/ReadV1ResponseResultsSummary.d.ts +3 -3
- package/dist/cjs/api/types/SharedIntents.d.ts +9 -9
- package/dist/cjs/api/types/SharedSentiments.d.ts +9 -9
- package/dist/cjs/api/types/SharedTopics.d.ts +9 -9
- package/dist/cjs/api/types/SpeakSettingsV1.d.ts +3 -3
- package/dist/cjs/api/types/SpeakSettingsV1Provider.d.ts +1 -1
- package/dist/cjs/api/types/ThinkSettingsV1.d.ts +15 -15
- package/dist/cjs/api/types/ThinkSettingsV1Provider.d.ts +19 -0
- package/dist/cjs/api/types/ThinkSettingsV1Provider.js +3 -0
- package/dist/cjs/api/types/UpdateProjectMemberScopesV1Response.d.ts +1 -1
- package/dist/cjs/api/types/UpdateProjectV1Response.d.ts +1 -1
- package/dist/cjs/api/types/UsageBreakdownV1Response.d.ts +9 -9
- package/dist/cjs/api/types/UsageFieldsV1Response.d.ts +8 -8
- package/dist/cjs/api/types/UsageV1Response.d.ts +5 -5
- package/dist/cjs/api/types/index.d.ts +3 -1
- package/dist/cjs/api/types/index.js +3 -1
- package/dist/cjs/core/fetcher/Fetcher.js +8 -2
- package/dist/cjs/core/fetcher/makeRequest.d.ts +6 -1
- package/dist/cjs/core/fetcher/makeRequest.js +30 -9
- package/dist/cjs/core/runtime/runtime.js +8 -7
- package/dist/cjs/core/websocket/ws.d.ts +4 -1
- package/dist/cjs/core/websocket/ws.js +32 -2
- package/dist/cjs/environments.d.ts +3 -3
- package/dist/cjs/environments.js +2 -2
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/middleware/adapters/express.d.ts +103 -0
- package/dist/cjs/middleware/adapters/express.js +141 -0
- package/dist/cjs/middleware/adapters/fastify.d.ts +32 -0
- package/dist/cjs/middleware/adapters/fastify.js +194 -0
- package/dist/cjs/middleware/adapters/http.d.ts +153 -0
- package/dist/cjs/middleware/adapters/http.js +192 -0
- package/dist/cjs/middleware/core/ProxyHandler.d.ts +35 -0
- package/dist/cjs/middleware/core/ProxyHandler.js +225 -0
- package/dist/cjs/middleware/core/TokenManager.d.ts +29 -0
- package/dist/cjs/middleware/core/TokenManager.js +110 -0
- package/dist/cjs/middleware/core/WebSocketProxy.d.ts +32 -0
- package/dist/cjs/middleware/core/WebSocketProxy.js +169 -0
- package/dist/cjs/middleware/core/jwt.d.ts +71 -0
- package/dist/cjs/middleware/core/jwt.js +136 -0
- package/dist/cjs/middleware/core/types.d.ts +37 -0
- package/dist/cjs/middleware/core/types.js +2 -0
- package/dist/cjs/middleware/index.d.ts +55 -0
- package/dist/cjs/middleware/index.js +75 -0
- package/dist/cjs/tests/manual/test-custom-baseurl.js +124 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +3 -3
- package/dist/esm/CustomClient.mjs +90 -107
- package/dist/esm/api/resources/agent/exports.d.mts +3 -0
- package/dist/esm/api/resources/agent/exports.mjs +4 -0
- package/dist/esm/api/resources/agent/resources/v1/client/Client.d.mts +6 -0
- package/dist/esm/api/resources/agent/resources/v1/client/Client.mjs +8 -3
- package/dist/esm/api/resources/agent/resources/v1/client/Socket.d.mts +3 -2
- package/dist/esm/api/resources/agent/resources/v1/client/Socket.mjs +4 -0
- package/dist/esm/api/resources/agent/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/agent/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/agent/resources/v1/resources/settings/exports.d.mts +3 -0
- package/dist/esm/api/resources/agent/resources/v1/resources/settings/exports.mjs +4 -0
- package/dist/esm/api/resources/agent/resources/v1/resources/settings/resources/think/exports.d.mts +3 -0
- package/dist/esm/api/resources/agent/resources/v1/resources/settings/resources/think/exports.mjs +4 -0
- package/dist/esm/api/resources/agent/resources/v1/resources/settings/resources/think/resources/models/exports.d.mts +2 -0
- package/dist/esm/api/resources/agent/resources/v1/resources/settings/resources/think/resources/models/exports.mjs +3 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1ReceiveFunctionCallResponse.d.mts +1 -1
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SendFunctionCallResponse.d.mts +1 -1
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1Settings.d.mts +21 -51
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.mts +5 -5
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1ThinkUpdated.d.mts +4 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1ThinkUpdated.mjs +2 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateSpeak.d.mts +2 -11
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateThink.d.mts +9 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateThink.mjs +2 -0
- package/dist/esm/api/resources/agent/resources/v1/types/index.d.mts +2 -0
- package/dist/esm/api/resources/agent/resources/v1/types/index.mjs +2 -0
- package/dist/esm/api/resources/auth/exports.d.mts +3 -0
- package/dist/esm/api/resources/auth/exports.mjs +4 -0
- package/dist/esm/api/resources/auth/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/auth/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/auth/resources/v1/resources/tokens/exports.d.mts +2 -0
- package/dist/esm/api/resources/auth/resources/v1/resources/tokens/exports.mjs +3 -0
- package/dist/esm/api/resources/listen/exports.d.mts +3 -0
- package/dist/esm/api/resources/listen/exports.mjs +4 -0
- package/dist/esm/api/resources/listen/resources/v1/client/Client.d.mts +35 -28
- package/dist/esm/api/resources/listen/resources/v1/client/Client.mjs +40 -30
- package/dist/esm/api/resources/listen/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/listen/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/listen/resources/v1/resources/media/client/requests/MediaTranscribeRequestOctetStream.d.mts +0 -3
- package/dist/esm/api/resources/listen/resources/v1/resources/media/exports.d.mts +2 -0
- package/dist/esm/api/resources/listen/resources/v1/resources/media/exports.mjs +3 -0
- package/dist/esm/api/resources/listen/resources/v1/types/ListenV1Results.d.mts +8 -8
- package/dist/esm/api/resources/listen/resources/v2/client/Client.d.mts +16 -9
- package/dist/esm/api/resources/listen/resources/v2/client/Client.mjs +29 -11
- package/dist/esm/api/resources/listen/resources/v2/client/Socket.d.mts +3 -2
- package/dist/esm/api/resources/listen/resources/v2/client/Socket.mjs +4 -0
- package/dist/esm/api/resources/listen/resources/v2/exports.d.mts +2 -0
- package/dist/esm/api/resources/listen/resources/v2/exports.mjs +3 -0
- package/dist/esm/api/resources/listen/resources/v2/types/ListenV2Configure.d.mts +22 -0
- package/dist/esm/api/resources/listen/resources/v2/types/ListenV2Configure.mjs +2 -0
- package/dist/esm/api/resources/listen/resources/v2/types/ListenV2ConfigureFailure.d.mts +12 -0
- package/dist/esm/api/resources/listen/resources/v2/types/ListenV2ConfigureFailure.mjs +2 -0
- package/dist/esm/api/resources/listen/resources/v2/types/ListenV2ConfigureSuccess.d.mts +30 -0
- package/dist/esm/api/resources/listen/resources/v2/types/ListenV2ConfigureSuccess.mjs +2 -0
- package/dist/esm/api/resources/listen/resources/v2/types/index.d.mts +3 -0
- package/dist/esm/api/resources/listen/resources/v2/types/index.mjs +3 -0
- package/dist/esm/api/resources/manage/exports.d.mts +3 -0
- package/dist/esm/api/resources/manage/exports.mjs +4 -0
- package/dist/esm/api/resources/manage/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/manage/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/models/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/models/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/exports.d.mts +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/exports.mjs +4 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/exports.d.mts +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/exports.mjs +4 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/balances/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/balances/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/breakdown/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/breakdown/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/fields/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/fields/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/purchases/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/billing/resources/purchases/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/keys/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/keys/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/members/exports.d.mts +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/members/exports.mjs +4 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/members/resources/invites/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/members/resources/invites/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/members/resources/scopes/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/members/resources/scopes/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/models/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/models/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/requests/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/requests/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/client/Client.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/client/Client.mjs +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/exports.d.mts +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/exports.mjs +4 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/breakdown/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/breakdown/exports.mjs +3 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/fields/exports.d.mts +2 -0
- package/dist/esm/api/resources/manage/resources/v1/resources/projects/resources/usage/resources/fields/exports.mjs +3 -0
- package/dist/esm/api/resources/read/exports.d.mts +3 -0
- package/dist/esm/api/resources/read/exports.mjs +4 -0
- package/dist/esm/api/resources/read/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/read/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/read/resources/v1/resources/text/exports.d.mts +2 -0
- package/dist/esm/api/resources/read/resources/v1/resources/text/exports.mjs +3 -0
- package/dist/esm/api/resources/selfHosted/exports.d.mts +3 -0
- package/dist/esm/api/resources/selfHosted/exports.mjs +4 -0
- package/dist/esm/api/resources/selfHosted/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/selfHosted/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/selfHosted/resources/v1/resources/distributionCredentials/exports.d.mts +2 -0
- package/dist/esm/api/resources/selfHosted/resources/v1/resources/distributionCredentials/exports.mjs +3 -0
- package/dist/esm/api/resources/speak/exports.d.mts +3 -0
- package/dist/esm/api/resources/speak/exports.mjs +4 -0
- package/dist/esm/api/resources/speak/resources/v1/client/Client.d.mts +11 -4
- package/dist/esm/api/resources/speak/resources/v1/client/Client.mjs +13 -7
- package/dist/esm/api/resources/speak/resources/v1/exports.d.mts +3 -0
- package/dist/esm/api/resources/speak/resources/v1/exports.mjs +4 -0
- package/dist/esm/api/resources/speak/resources/v1/resources/audio/client/Client.d.mts +1 -0
- package/dist/esm/api/resources/speak/resources/v1/resources/audio/client/Client.mjs +1 -0
- package/dist/esm/api/resources/speak/resources/v1/resources/audio/exports.d.mts +2 -0
- package/dist/esm/api/resources/speak/resources/v1/resources/audio/exports.mjs +3 -0
- package/dist/esm/api/resources/speak/resources/v1/types/SpeakV1Metadata.d.mts +4 -2
- package/dist/esm/api/types/Anthropic.d.mts +2 -2
- package/dist/esm/api/types/AwsBedrockThinkProvider.d.mts +7 -7
- package/dist/esm/api/types/AwsPollySpeakProvider.d.mts +2 -2
- package/dist/esm/api/types/BillingBreakdownV1Response.d.mts +6 -6
- package/dist/esm/api/types/Cartesia.d.mts +2 -2
- package/dist/esm/api/types/CreateKeyV1Response.d.mts +6 -6
- package/dist/esm/api/types/CreateProjectDistributionCredentialsV1Response.d.mts +1 -1
- package/dist/esm/api/types/CreateProjectInviteV1Response.d.mts +1 -1
- package/dist/esm/api/types/Deepgram.d.mts +1 -1
- package/dist/esm/api/types/DeleteProjectInviteV1Response.d.mts +1 -1
- package/dist/esm/api/types/DeleteProjectKeyV1Response.d.mts +1 -1
- package/dist/esm/api/types/DeleteProjectMemberV1Response.d.mts +1 -1
- package/dist/esm/api/types/DeleteProjectV1Response.d.mts +1 -1
- package/dist/esm/api/types/ElevenLabsSpeakProvider.d.mts +3 -3
- package/dist/esm/api/types/ErrorResponseLegacyError.d.mts +3 -3
- package/dist/esm/api/types/ErrorResponseModernError.d.mts +4 -4
- package/dist/esm/api/types/GetProjectBalanceV1Response.d.mts +4 -4
- package/dist/esm/api/types/GetProjectDistributionCredentialsV1Response.d.mts +1 -1
- package/dist/esm/api/types/GetProjectKeyV1Response.d.mts +13 -13
- package/dist/esm/api/types/GetProjectRequestV1Response.d.mts +1 -1
- package/dist/esm/api/types/GetProjectV1Response.d.mts +3 -3
- package/dist/esm/api/types/Google.d.mts +2 -2
- package/dist/esm/api/types/GrantV1Response.d.mts +1 -1
- package/dist/esm/api/types/Groq.d.mts +2 -2
- package/dist/esm/api/types/LeaveProjectV1Response.d.mts +1 -1
- package/dist/esm/api/types/ListBillingFieldsV1Response.d.mts +4 -4
- package/dist/esm/api/types/ListModelsV1Response.d.mts +2 -2
- package/dist/esm/api/types/ListModelsV1ResponseSttModels.d.mts +9 -9
- package/dist/esm/api/types/ListModelsV1ResponseTtsModels.d.mts +14 -14
- package/dist/esm/api/types/ListProjectBalancesV1Response.d.mts +5 -5
- package/dist/esm/api/types/ListProjectDistributionCredentialsV1Response.d.mts +2 -2
- package/dist/esm/api/types/ListProjectInvitesV1Response.d.mts +3 -3
- package/dist/esm/api/types/ListProjectKeysV1Response.d.mts +9 -9
- package/dist/esm/api/types/ListProjectMemberScopesV1Response.d.mts +1 -1
- package/dist/esm/api/types/ListProjectMembersV1Response.d.mts +3 -3
- package/dist/esm/api/types/ListProjectPurchasesV1Response.d.mts +7 -7
- package/dist/esm/api/types/ListProjectRequestsV1Response.d.mts +3 -3
- package/dist/esm/api/types/ListProjectsV1Response.d.mts +3 -3
- package/dist/esm/api/types/ListenV1ResponseMetadata.d.mts +18 -18
- package/dist/esm/api/types/ListenV1ResponseResults.d.mts +5 -5
- package/dist/esm/api/types/ListenV1ResponseResultsChannelsItem.d.mts +43 -43
- package/dist/esm/api/types/ListenV1ResponseResultsSummary.d.mts +2 -2
- package/dist/esm/api/types/ListenV1ResponseResultsUtterancesItem.d.mts +15 -15
- package/dist/esm/api/types/OpenAiSpeakProvider.d.mts +27 -0
- package/dist/esm/api/types/OpenAiSpeakProvider.mjs +18 -0
- package/dist/esm/api/types/OpenAiThinkProvider.d.mts +23 -0
- package/dist/esm/api/types/OpenAiThinkProvider.mjs +15 -0
- package/dist/esm/api/types/ProjectRequestResponse.d.mts +9 -9
- package/dist/esm/api/types/ReadV1ResponseMetadata.d.mts +20 -20
- package/dist/esm/api/types/ReadV1ResponseResults.d.mts +4 -4
- package/dist/esm/api/types/ReadV1ResponseResultsSummary.d.mts +3 -3
- package/dist/esm/api/types/SharedIntents.d.mts +9 -9
- package/dist/esm/api/types/SharedSentiments.d.mts +9 -9
- package/dist/esm/api/types/SharedTopics.d.mts +9 -9
- package/dist/esm/api/types/SpeakSettingsV1.d.mts +3 -3
- package/dist/esm/api/types/SpeakSettingsV1Provider.d.mts +1 -1
- package/dist/esm/api/types/ThinkSettingsV1.d.mts +15 -15
- package/dist/esm/api/types/ThinkSettingsV1Provider.d.mts +19 -0
- package/dist/esm/api/types/ThinkSettingsV1Provider.mjs +2 -0
- package/dist/esm/api/types/UpdateProjectMemberScopesV1Response.d.mts +1 -1
- package/dist/esm/api/types/UpdateProjectV1Response.d.mts +1 -1
- package/dist/esm/api/types/UsageBreakdownV1Response.d.mts +9 -9
- package/dist/esm/api/types/UsageFieldsV1Response.d.mts +8 -8
- package/dist/esm/api/types/UsageV1Response.d.mts +5 -5
- package/dist/esm/api/types/index.d.mts +3 -1
- package/dist/esm/api/types/index.mjs +3 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +8 -2
- package/dist/esm/core/fetcher/makeRequest.d.mts +6 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +28 -9
- package/dist/esm/core/runtime/runtime.mjs +8 -7
- package/dist/esm/core/websocket/ws.d.mts +4 -1
- package/dist/esm/core/websocket/ws.mjs +32 -2
- package/dist/esm/environments.d.mts +3 -3
- package/dist/esm/environments.mjs +2 -2
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/middleware/adapters/express.d.mts +103 -0
- package/dist/esm/middleware/adapters/express.mjs +136 -0
- package/dist/esm/middleware/adapters/fastify.d.mts +32 -0
- package/dist/esm/middleware/adapters/fastify.mjs +157 -0
- package/dist/esm/middleware/adapters/http.d.mts +153 -0
- package/dist/esm/middleware/adapters/http.mjs +187 -0
- package/dist/esm/middleware/core/ProxyHandler.d.mts +35 -0
- package/dist/esm/middleware/core/ProxyHandler.mjs +218 -0
- package/dist/esm/middleware/core/TokenManager.d.mts +29 -0
- package/dist/esm/middleware/core/TokenManager.mjs +106 -0
- package/dist/esm/middleware/core/WebSocketProxy.d.mts +32 -0
- package/dist/esm/middleware/core/WebSocketProxy.mjs +162 -0
- package/dist/esm/middleware/core/jwt.d.mts +71 -0
- package/dist/esm/middleware/core/jwt.mjs +99 -0
- package/dist/esm/middleware/core/types.d.mts +37 -0
- package/dist/esm/middleware/core/types.mjs +1 -0
- package/dist/esm/middleware/index.d.mts +55 -0
- package/dist/esm/middleware/index.mjs +59 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +433 -4
- package/reference.md +1 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProxyHandler = void 0;
|
|
16
|
+
const node_https_1 = __importDefault(require("node:https"));
|
|
17
|
+
const node_url_1 = require("node:url");
|
|
18
|
+
const jwt_js_1 = require("./jwt.js");
|
|
19
|
+
/**
|
|
20
|
+
* Handles HTTP/REST request proxying to Deepgram API
|
|
21
|
+
*/
|
|
22
|
+
class ProxyHandler {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
this.apiKey = options.apiKey;
|
|
26
|
+
this.baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : "https://api.deepgram.com";
|
|
27
|
+
this.tokenMode = (_b = options.tokenMode) !== null && _b !== void 0 ? _b : "deepgram";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Handle incoming HTTP request and proxy to Deepgram
|
|
31
|
+
*/
|
|
32
|
+
handleRequest(req, res) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
try {
|
|
35
|
+
// Handle CORS preflight
|
|
36
|
+
if (req.method === "OPTIONS") {
|
|
37
|
+
this.handleCorsPreflightRequest(req, res);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Forward request to Deepgram
|
|
41
|
+
yield this.forwardToDeepgram(req, res);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.handleError(error, res);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Forward request to Deepgram API
|
|
50
|
+
*/
|
|
51
|
+
forwardToDeepgram(req, res) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
var _a;
|
|
54
|
+
console.log(`[ProxyHandler] Starting forward to Deepgram`);
|
|
55
|
+
console.log(`[ProxyHandler] Original URL: ${req.url}`);
|
|
56
|
+
// Strip /api/deepgram prefix if present
|
|
57
|
+
const cleanUrl = ((_a = req.url) !== null && _a !== void 0 ? _a : "/").replace(/^\/api\/deepgram/, "");
|
|
58
|
+
console.log(`[ProxyHandler] Clean URL: ${cleanUrl}`);
|
|
59
|
+
// Build Deepgram URL
|
|
60
|
+
const targetUrl = new node_url_1.URL(cleanUrl, this.baseUrl);
|
|
61
|
+
console.log(`[ProxyHandler] Target URL: ${targetUrl.toString()}`);
|
|
62
|
+
// Prepare headers (may verify JWT)
|
|
63
|
+
const headers = yield this.prepareHeaders(req);
|
|
64
|
+
console.log(`[ProxyHandler] Request headers prepared`);
|
|
65
|
+
// Create request to Deepgram
|
|
66
|
+
const options = {
|
|
67
|
+
method: req.method,
|
|
68
|
+
headers,
|
|
69
|
+
};
|
|
70
|
+
console.log(`[ProxyHandler] Creating ${req.method} request to Deepgram...`);
|
|
71
|
+
console.log(`[ProxyHandler] Headers being SENT to Deepgram:`, JSON.stringify(headers, null, 2));
|
|
72
|
+
const deepgramReq = node_https_1.default.request(targetUrl, options, (deepgramRes) => {
|
|
73
|
+
var _a;
|
|
74
|
+
console.log(`[ProxyHandler] Received response from Deepgram: ${deepgramRes.statusCode}`);
|
|
75
|
+
console.log(`[ProxyHandler] Response headers from Deepgram:`, JSON.stringify(deepgramRes.headers, null, 2));
|
|
76
|
+
// Don't set headers if they were already sent
|
|
77
|
+
if (res.headersSent) {
|
|
78
|
+
console.log(`[ProxyHandler] Headers already sent, skipping`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Build response headers with CORS
|
|
82
|
+
const responseHeaders = Object.assign(Object.assign({}, deepgramRes.headers), { "access-control-allow-origin": "*", "access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS", "access-control-allow-headers": "Authorization, Content-Type, x-fern-language, x-fern-sdk-name, x-fern-sdk-version, x-deepgram-session-id", "access-control-max-age": "3600" });
|
|
83
|
+
// Forward status and headers
|
|
84
|
+
console.log(`[ProxyHandler] Writing response headers`);
|
|
85
|
+
res.writeHead((_a = deepgramRes.statusCode) !== null && _a !== void 0 ? _a : 200, responseHeaders);
|
|
86
|
+
// Stream response body
|
|
87
|
+
console.log(`[ProxyHandler] Piping response body to client`);
|
|
88
|
+
deepgramRes.pipe(res);
|
|
89
|
+
deepgramRes.on('end', () => {
|
|
90
|
+
console.log(`[ProxyHandler] Response stream ended`);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
// Handle request errors
|
|
94
|
+
deepgramReq.on("error", (error) => {
|
|
95
|
+
console.error(`[ProxyHandler] Request error:`, error);
|
|
96
|
+
this.handleError(error, res);
|
|
97
|
+
});
|
|
98
|
+
// Check if request stream is readable
|
|
99
|
+
console.log(`[ProxyHandler] Request stream readable: ${req.readable}`);
|
|
100
|
+
console.log(`[ProxyHandler] Request stream readableEnded: ${req.readableEnded}`);
|
|
101
|
+
console.log(`[ProxyHandler] Request method: ${req.method}`);
|
|
102
|
+
// For POST/PUT requests, manually read and forward the body
|
|
103
|
+
if (req.method === 'POST' || req.method === 'PUT' || req.method === 'PATCH') {
|
|
104
|
+
console.log(`[ProxyHandler] Reading request body for ${req.method} request...`);
|
|
105
|
+
const chunks = [];
|
|
106
|
+
req.on('data', (chunk) => {
|
|
107
|
+
console.log(`[ProxyHandler] Received request chunk: ${chunk.length} bytes`);
|
|
108
|
+
chunks.push(chunk);
|
|
109
|
+
});
|
|
110
|
+
req.on('end', () => {
|
|
111
|
+
const body = Buffer.concat(chunks);
|
|
112
|
+
console.log(`[ProxyHandler] Request body complete: ${body.length} bytes total`);
|
|
113
|
+
console.log(`[ProxyHandler] Request body content: ${body.toString()}`);
|
|
114
|
+
deepgramReq.write(body);
|
|
115
|
+
deepgramReq.end();
|
|
116
|
+
console.log(`[ProxyHandler] Request sent to Deepgram`);
|
|
117
|
+
});
|
|
118
|
+
req.on('error', (err) => {
|
|
119
|
+
console.error(`[ProxyHandler] Request stream error:`, err);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// For GET requests, just end immediately
|
|
124
|
+
console.log(`[ProxyHandler] No body expected for ${req.method} request`);
|
|
125
|
+
deepgramReq.end();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Prepare headers for Deepgram request
|
|
131
|
+
*/
|
|
132
|
+
prepareHeaders(req) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const headers = {};
|
|
135
|
+
// Copy relevant headers
|
|
136
|
+
const allowedHeaders = [
|
|
137
|
+
"content-type",
|
|
138
|
+
"content-length",
|
|
139
|
+
"accept",
|
|
140
|
+
"user-agent",
|
|
141
|
+
"x-fern-language",
|
|
142
|
+
"x-fern-sdk-name",
|
|
143
|
+
"x-fern-sdk-version",
|
|
144
|
+
"x-fern-runtime",
|
|
145
|
+
"x-fern-runtime-version",
|
|
146
|
+
"x-deepgram-session-id",
|
|
147
|
+
];
|
|
148
|
+
for (const header of allowedHeaders) {
|
|
149
|
+
const value = req.headers[header];
|
|
150
|
+
if (value) {
|
|
151
|
+
headers[header] = Array.isArray(value) ? value[0] : value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Authentication logic:
|
|
155
|
+
// 1. If client sends dummy key "Token Dummy key for SDK proxying" -> use server API key
|
|
156
|
+
// 2. If tokenMode is "jwt" and client sends Bearer token -> verify JWT and use server API key
|
|
157
|
+
// 3. If tokenMode is "deepgram" and client sends Token -> forward it (Deepgram temp token)
|
|
158
|
+
// 4. If client sends no auth header -> use server API key
|
|
159
|
+
const clientAuth = req.headers.authorization;
|
|
160
|
+
const isDummyKey = clientAuth === "Token Dummy key for SDK proxying";
|
|
161
|
+
if (clientAuth && !isDummyKey) {
|
|
162
|
+
// Check if it's a JWT Bearer token
|
|
163
|
+
if (this.tokenMode === "jwt" && clientAuth.startsWith("Bearer ")) {
|
|
164
|
+
const token = clientAuth.replace("Bearer ", "");
|
|
165
|
+
console.log(`[ProxyHandler] Client provided JWT token, verifying...`);
|
|
166
|
+
try {
|
|
167
|
+
yield (0, jwt_js_1.verifyProxyToken)(token, this.apiKey);
|
|
168
|
+
console.log(`[ProxyHandler] JWT verified successfully, using server API key`);
|
|
169
|
+
headers.authorization = `Token ${this.apiKey}`;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
console.error(`[ProxyHandler] JWT verification failed:`, error);
|
|
173
|
+
throw new Error("Invalid or expired token");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
console.log(`[ProxyHandler] Client provided authorization header, forwarding to Deepgram`);
|
|
178
|
+
headers.authorization = clientAuth;
|
|
179
|
+
console.log(`[ProxyHandler] Authorization header: ${headers.authorization.substring(0, 30)}...`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
if (isDummyKey) {
|
|
184
|
+
console.log(`[ProxyHandler] Client sent dummy key, using server API key`);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
console.log(`[ProxyHandler] No client auth, using server API key`);
|
|
188
|
+
}
|
|
189
|
+
headers.authorization = `Token ${this.apiKey}`;
|
|
190
|
+
console.log(`[ProxyHandler] Authorization header: ${headers.authorization.substring(0, 30)}...`);
|
|
191
|
+
}
|
|
192
|
+
return headers;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Add CORS headers to response
|
|
197
|
+
*/
|
|
198
|
+
addCorsHeaders(res) {
|
|
199
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
200
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
201
|
+
res.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, x-fern-language, x-fern-sdk-name, x-fern-sdk-version, x-fern-runtime, x-fern-runtime-version, x-deepgram-session-id");
|
|
202
|
+
res.setHeader("Access-Control-Max-Age", "3600");
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Handle CORS preflight requests
|
|
206
|
+
*/
|
|
207
|
+
handleCorsPreflightRequest(req, res) {
|
|
208
|
+
this.addCorsHeaders(res);
|
|
209
|
+
res.writeHead(204);
|
|
210
|
+
res.end();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Handle errors and send appropriate response
|
|
214
|
+
*/
|
|
215
|
+
handleError(error, res) {
|
|
216
|
+
console.error("ProxyHandler error:", error);
|
|
217
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
218
|
+
this.addCorsHeaders(res);
|
|
219
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
220
|
+
res.end(JSON.stringify({
|
|
221
|
+
error: message,
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.ProxyHandler = ProxyHandler;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { MiddlewareOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Manages temporary token generation for client authentication
|
|
5
|
+
*/
|
|
6
|
+
export declare class TokenManager {
|
|
7
|
+
private readonly client;
|
|
8
|
+
private readonly apiKey;
|
|
9
|
+
private readonly tokenMode;
|
|
10
|
+
private readonly defaultExpiration;
|
|
11
|
+
constructor(options: MiddlewareOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Generate a temporary access token
|
|
14
|
+
* Uses either Deepgram's native token API or JWT signing based on tokenMode
|
|
15
|
+
*/
|
|
16
|
+
generateToken(ttlSeconds: number): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Handle token generation request from client
|
|
19
|
+
*/
|
|
20
|
+
handleTokenRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Parse JSON request body
|
|
23
|
+
*/
|
|
24
|
+
private parseBody;
|
|
25
|
+
/**
|
|
26
|
+
* Handle errors and send appropriate response
|
|
27
|
+
*/
|
|
28
|
+
private handleError;
|
|
29
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TokenManager = void 0;
|
|
13
|
+
const CustomClient_js_1 = require("../../CustomClient.js");
|
|
14
|
+
const jwt_js_1 = require("./jwt.js");
|
|
15
|
+
/**
|
|
16
|
+
* Manages temporary token generation for client authentication
|
|
17
|
+
*/
|
|
18
|
+
class TokenManager {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
this.client = new CustomClient_js_1.CustomDeepgramClient({ apiKey: options.apiKey });
|
|
22
|
+
this.apiKey = options.apiKey;
|
|
23
|
+
this.tokenMode = (_a = options.tokenMode) !== null && _a !== void 0 ? _a : "deepgram";
|
|
24
|
+
this.defaultExpiration = (_b = options.defaultTokenExpiration) !== null && _b !== void 0 ? _b : 3600;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generate a temporary access token
|
|
28
|
+
* Uses either Deepgram's native token API or JWT signing based on tokenMode
|
|
29
|
+
*/
|
|
30
|
+
generateToken(ttlSeconds) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (this.tokenMode === "jwt") {
|
|
33
|
+
return (0, jwt_js_1.createProxyToken)(this.apiKey, { ttl: ttlSeconds });
|
|
34
|
+
}
|
|
35
|
+
const response = yield this.client.auth.v1.tokens.grant({
|
|
36
|
+
ttl_seconds: ttlSeconds,
|
|
37
|
+
});
|
|
38
|
+
return response.access_token;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Handle token generation request from client
|
|
43
|
+
*/
|
|
44
|
+
handleTokenRequest(req, res) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _a;
|
|
47
|
+
try {
|
|
48
|
+
// Parse request body
|
|
49
|
+
const body = yield this.parseBody(req);
|
|
50
|
+
const tokenRequest = body;
|
|
51
|
+
// Generate token with requested or default TTL
|
|
52
|
+
const ttlSeconds = (_a = tokenRequest.ttlSeconds) !== null && _a !== void 0 ? _a : this.defaultExpiration;
|
|
53
|
+
const token = yield this.generateToken(ttlSeconds);
|
|
54
|
+
// Send response
|
|
55
|
+
const response = {
|
|
56
|
+
token,
|
|
57
|
+
expiresIn: ttlSeconds,
|
|
58
|
+
};
|
|
59
|
+
res.writeHead(200, {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
"Access-Control-Allow-Origin": "*",
|
|
62
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
63
|
+
"Access-Control-Allow-Headers": "Content-Type",
|
|
64
|
+
});
|
|
65
|
+
res.end(JSON.stringify(response));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.handleError(error, res);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Parse JSON request body
|
|
74
|
+
*/
|
|
75
|
+
parseBody(req) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
let body = "";
|
|
79
|
+
req.on("data", (chunk) => {
|
|
80
|
+
body += chunk.toString();
|
|
81
|
+
});
|
|
82
|
+
req.on("end", () => {
|
|
83
|
+
try {
|
|
84
|
+
resolve(body ? JSON.parse(body) : {});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
reject(new Error("Invalid JSON in request body"));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
req.on("error", reject);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Handle errors and send appropriate response
|
|
96
|
+
*/
|
|
97
|
+
handleError(error, res) {
|
|
98
|
+
console.error("TokenManager error:", error);
|
|
99
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
100
|
+
const statusCode = message.includes("Invalid JSON") ? 400 : 500;
|
|
101
|
+
res.writeHead(statusCode, {
|
|
102
|
+
"Content-Type": "application/json",
|
|
103
|
+
"Access-Control-Allow-Origin": "*",
|
|
104
|
+
});
|
|
105
|
+
res.end(JSON.stringify({
|
|
106
|
+
error: message,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.TokenManager = TokenManager;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import type { Duplex } from "node:stream";
|
|
3
|
+
import type { MiddlewareOptions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Handles WebSocket proxying to Deepgram API
|
|
6
|
+
*/
|
|
7
|
+
export declare class WebSocketProxy {
|
|
8
|
+
private readonly apiKey;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
private readonly tokenMode;
|
|
11
|
+
constructor(options: MiddlewareOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Handle WebSocket upgrade request
|
|
14
|
+
*/
|
|
15
|
+
handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): void;
|
|
16
|
+
/**
|
|
17
|
+
* Async version of handleUpgrade to support JWT verification
|
|
18
|
+
*/
|
|
19
|
+
private handleUpgradeAsync;
|
|
20
|
+
/**
|
|
21
|
+
* Build WebSocket URL for Deepgram
|
|
22
|
+
*/
|
|
23
|
+
private buildWebSocketUrl;
|
|
24
|
+
/**
|
|
25
|
+
* Prepare headers for Deepgram WebSocket connection
|
|
26
|
+
*/
|
|
27
|
+
private prepareHeaders;
|
|
28
|
+
/**
|
|
29
|
+
* Forward WebSocket messages bidirectionally
|
|
30
|
+
*/
|
|
31
|
+
private forwardMessages;
|
|
32
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WebSocketProxy = void 0;
|
|
16
|
+
const node_url_1 = require("node:url");
|
|
17
|
+
const ws_1 = __importDefault(require("ws"));
|
|
18
|
+
const jwt_js_1 = require("./jwt.js");
|
|
19
|
+
/**
|
|
20
|
+
* Handles WebSocket proxying to Deepgram API
|
|
21
|
+
*/
|
|
22
|
+
class WebSocketProxy {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
this.apiKey = options.apiKey;
|
|
26
|
+
this.tokenMode = (_a = options.tokenMode) !== null && _a !== void 0 ? _a : "deepgram";
|
|
27
|
+
// Convert HTTP(S) base URL to WebSocket URL
|
|
28
|
+
this.baseUrl = ((_b = options.baseUrl) !== null && _b !== void 0 ? _b : "https://api.deepgram.com")
|
|
29
|
+
.replace(/^https:/, "wss:")
|
|
30
|
+
.replace(/^http:/, "ws:");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handle WebSocket upgrade request
|
|
34
|
+
*/
|
|
35
|
+
handleUpgrade(req, socket, head) {
|
|
36
|
+
this.handleUpgradeAsync(req, socket, head).catch((error) => {
|
|
37
|
+
console.error("WebSocket upgrade error:", error);
|
|
38
|
+
socket.destroy();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Async version of handleUpgrade to support JWT verification
|
|
43
|
+
*/
|
|
44
|
+
handleUpgradeAsync(req, socket, head) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
// Build Deepgram WebSocket URL
|
|
48
|
+
const targetUrl = this.buildWebSocketUrl(req);
|
|
49
|
+
// Prepare headers (may verify JWT)
|
|
50
|
+
const headers = yield this.prepareHeaders(req);
|
|
51
|
+
// Connect to Deepgram WebSocket
|
|
52
|
+
const deepgramSocket = new ws_1.default(targetUrl, { headers });
|
|
53
|
+
// Handle connection open
|
|
54
|
+
deepgramSocket.on("open", () => {
|
|
55
|
+
// Complete the client upgrade
|
|
56
|
+
socket.write("HTTP/1.1 101 Switching Protocols\r\n" +
|
|
57
|
+
"Upgrade: websocket\r\n" +
|
|
58
|
+
"Connection: Upgrade\r\n" +
|
|
59
|
+
"\r\n");
|
|
60
|
+
// Create client WebSocket
|
|
61
|
+
const clientSocket = new ws_1.default(null, null);
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- WebSocket internals
|
|
63
|
+
clientSocket.setSocket(socket, head, { maxPayload: 100 * 1024 * 1024 });
|
|
64
|
+
// Forward messages bidirectionally
|
|
65
|
+
this.forwardMessages(clientSocket, deepgramSocket);
|
|
66
|
+
});
|
|
67
|
+
// Handle connection errors
|
|
68
|
+
deepgramSocket.on("error", (error) => {
|
|
69
|
+
console.error("WebSocket proxy error (Deepgram):", error);
|
|
70
|
+
socket.destroy();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error("WebSocket upgrade error:", error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build WebSocket URL for Deepgram
|
|
81
|
+
*/
|
|
82
|
+
buildWebSocketUrl(req) {
|
|
83
|
+
var _a;
|
|
84
|
+
// Strip /api/deepgram prefix if present
|
|
85
|
+
const cleanUrl = ((_a = req.url) !== null && _a !== void 0 ? _a : "/").replace(/^\/api\/deepgram/, "");
|
|
86
|
+
const url = new node_url_1.URL(cleanUrl, this.baseUrl);
|
|
87
|
+
return url.toString();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Prepare headers for Deepgram WebSocket connection
|
|
91
|
+
*/
|
|
92
|
+
prepareHeaders(req) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const headers = {};
|
|
95
|
+
// Copy relevant headers
|
|
96
|
+
const allowedHeaders = [
|
|
97
|
+
"user-agent",
|
|
98
|
+
"x-fern-language",
|
|
99
|
+
"x-fern-sdk-name",
|
|
100
|
+
"x-fern-sdk-version",
|
|
101
|
+
"x-deepgram-session-id",
|
|
102
|
+
];
|
|
103
|
+
for (const header of allowedHeaders) {
|
|
104
|
+
const value = req.headers[header];
|
|
105
|
+
if (value) {
|
|
106
|
+
headers[header] = Array.isArray(value) ? value[0] : value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Authentication logic (similar to ProxyHandler)
|
|
110
|
+
const clientAuth = req.headers.authorization;
|
|
111
|
+
if (clientAuth && this.tokenMode === "jwt" && clientAuth.startsWith("Bearer ")) {
|
|
112
|
+
const token = clientAuth.replace("Bearer ", "");
|
|
113
|
+
console.log(`[WebSocketProxy] Client provided JWT token, verifying...`);
|
|
114
|
+
try {
|
|
115
|
+
yield (0, jwt_js_1.verifyProxyToken)(token, this.apiKey);
|
|
116
|
+
console.log(`[WebSocketProxy] JWT verified successfully, using server API key`);
|
|
117
|
+
headers.authorization = `Token ${this.apiKey}`;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error(`[WebSocketProxy] JWT verification failed:`, error);
|
|
121
|
+
throw new Error("Invalid or expired token");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Use server API key
|
|
126
|
+
headers.authorization = `Token ${this.apiKey}`;
|
|
127
|
+
}
|
|
128
|
+
return headers;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Forward WebSocket messages bidirectionally
|
|
133
|
+
*/
|
|
134
|
+
forwardMessages(clientSocket, deepgramSocket) {
|
|
135
|
+
// Forward client messages to Deepgram
|
|
136
|
+
clientSocket.on("message", (data, isBinary) => {
|
|
137
|
+
if (deepgramSocket.readyState === ws_1.default.OPEN) {
|
|
138
|
+
deepgramSocket.send(data, { binary: isBinary });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// Forward Deepgram messages to client
|
|
142
|
+
deepgramSocket.on("message", (data, isBinary) => {
|
|
143
|
+
if (clientSocket.readyState === ws_1.default.OPEN) {
|
|
144
|
+
clientSocket.send(data, { binary: isBinary });
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
// Handle closures
|
|
148
|
+
clientSocket.on("close", (code, reason) => {
|
|
149
|
+
if (deepgramSocket.readyState === ws_1.default.OPEN) {
|
|
150
|
+
deepgramSocket.close(code, reason);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
deepgramSocket.on("close", (code, reason) => {
|
|
154
|
+
if (clientSocket.readyState === ws_1.default.OPEN) {
|
|
155
|
+
clientSocket.close(code, reason);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
// Handle errors
|
|
159
|
+
clientSocket.on("error", (error) => {
|
|
160
|
+
console.error("WebSocket error (client):", error);
|
|
161
|
+
deepgramSocket.close();
|
|
162
|
+
});
|
|
163
|
+
deepgramSocket.on("error", (error) => {
|
|
164
|
+
console.error("WebSocket error (Deepgram):", error);
|
|
165
|
+
clientSocket.close();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.WebSocketProxy = WebSocketProxy;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a proxy token
|
|
3
|
+
*/
|
|
4
|
+
export interface ProxyTokenOptions {
|
|
5
|
+
/** Optional user or session identifier */
|
|
6
|
+
identity?: string;
|
|
7
|
+
/** Token time-to-live (e.g., "1h", "30m", 3600). Defaults to "1h" */
|
|
8
|
+
ttl?: string | number;
|
|
9
|
+
/** Optional scopes/permissions for the token */
|
|
10
|
+
scopes?: string[];
|
|
11
|
+
/** Optional custom metadata to include in token */
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Decoded proxy token payload
|
|
16
|
+
*/
|
|
17
|
+
export interface ProxyTokenPayload {
|
|
18
|
+
/** Issuer - the project ID extracted from API key */
|
|
19
|
+
iss: string;
|
|
20
|
+
/** Subject - optional user/session identifier */
|
|
21
|
+
sub?: string;
|
|
22
|
+
/** Issued at timestamp */
|
|
23
|
+
iat: number;
|
|
24
|
+
/** Expiration timestamp */
|
|
25
|
+
exp: number;
|
|
26
|
+
/** Not before timestamp */
|
|
27
|
+
nbf: number;
|
|
28
|
+
/** Optional scopes/permissions */
|
|
29
|
+
scopes?: string[];
|
|
30
|
+
/** Optional custom metadata */
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a proxy token signed with the Deepgram API key.
|
|
35
|
+
* This token should be generated on the backend and sent to browser clients.
|
|
36
|
+
* The browser uses this token to connect to the proxy middleware.
|
|
37
|
+
*
|
|
38
|
+
* @param apiKey - Deepgram API key (used as signing secret)
|
|
39
|
+
* @param options - Token configuration options
|
|
40
|
+
* @returns JWT token string
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const token = await createProxyToken(process.env.DEEPGRAM_API_KEY, {
|
|
45
|
+
* identity: 'user-123',
|
|
46
|
+
* ttl: '1h',
|
|
47
|
+
* scopes: ['listen', 'speak']
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function createProxyToken(apiKey: string, options?: ProxyTokenOptions): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Verifies a proxy token and returns the decoded payload.
|
|
54
|
+
* This should be called by the proxy middleware to validate tokens from clients.
|
|
55
|
+
*
|
|
56
|
+
* @param token - JWT token to verify
|
|
57
|
+
* @param apiKey - Deepgram API key (used to verify signature)
|
|
58
|
+
* @returns Decoded token payload
|
|
59
|
+
* @throws Error if token is invalid, expired, or signature doesn't match
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* try {
|
|
64
|
+
* const payload = await verifyProxyToken(token, process.env.DEEPGRAM_API_KEY);
|
|
65
|
+
* console.log('Valid token for user:', payload.sub);
|
|
66
|
+
* } catch (error) {
|
|
67
|
+
* console.error('Invalid token:', error);
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function verifyProxyToken(token: string, apiKey: string): Promise<ProxyTokenPayload>;
|