telnyx 6.41.0 → 6.42.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/CHANGELOG.md +41 -0
- package/client.d.mts +2 -2
- package/client.d.mts.map +1 -1
- package/client.d.ts +2 -2
- package/client.d.ts.map +1 -1
- package/client.js +11 -0
- package/client.js.map +1 -1
- package/client.mjs +11 -0
- package/client.mjs.map +1 -1
- package/core/EventEmitter.d.mts +11 -0
- package/core/EventEmitter.d.mts.map +1 -1
- package/core/EventEmitter.d.ts +11 -0
- package/core/EventEmitter.d.ts.map +1 -1
- package/core/EventEmitter.js +15 -1
- package/core/EventEmitter.js.map +1 -1
- package/core/EventEmitter.mjs +13 -0
- package/core/EventEmitter.mjs.map +1 -1
- package/core/pagination.d.mts.map +1 -1
- package/core/pagination.d.ts.map +1 -1
- package/internal/detect-platform.js +1 -1
- package/internal/detect-platform.js.map +1 -1
- package/internal/detect-platform.mjs +1 -1
- package/internal/detect-platform.mjs.map +1 -1
- package/internal/types.d.mts +6 -6
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +6 -6
- package/internal/types.d.ts.map +1 -1
- package/internal/utils/env.js +2 -2
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +2 -2
- package/internal/utils/env.mjs.map +1 -1
- package/internal/ws-adapter-browser.d.mts +34 -0
- package/internal/ws-adapter-browser.d.mts.map +1 -0
- package/internal/ws-adapter-browser.d.ts +34 -0
- package/internal/ws-adapter-browser.d.ts.map +1 -0
- package/internal/ws-adapter-browser.js +88 -0
- package/internal/ws-adapter-browser.js.map +1 -0
- package/internal/ws-adapter-browser.mjs +84 -0
- package/internal/ws-adapter-browser.mjs.map +1 -0
- package/internal/ws-adapter-node.d.mts +27 -0
- package/internal/ws-adapter-node.d.mts.map +1 -0
- package/internal/ws-adapter-node.d.ts +27 -0
- package/internal/ws-adapter-node.d.ts.map +1 -0
- package/internal/ws-adapter-node.js +90 -0
- package/internal/ws-adapter-node.js.map +1 -0
- package/internal/ws-adapter-node.mjs +86 -0
- package/internal/ws-adapter-node.mjs.map +1 -0
- package/internal/ws-adapter.d.mts +24 -0
- package/internal/ws-adapter.d.mts.map +1 -0
- package/internal/ws-adapter.d.ts +24 -0
- package/internal/ws-adapter.d.ts.map +1 -0
- package/internal/ws-adapter.js +11 -0
- package/internal/ws-adapter.js.map +1 -0
- package/internal/ws-adapter.mjs +8 -0
- package/internal/ws-adapter.mjs.map +1 -0
- package/internal/ws.d.mts +80 -0
- package/internal/ws.d.mts.map +1 -0
- package/internal/ws.d.ts +80 -0
- package/internal/ws.d.ts.map +1 -0
- package/internal/ws.js +153 -0
- package/internal/ws.js.map +1 -0
- package/internal/ws.mjs +147 -0
- package/internal/ws.mjs.map +1 -0
- package/lib/text-to-speech-ws-base.d.mts +106 -0
- package/lib/text-to-speech-ws-base.d.mts.map +1 -0
- package/lib/text-to-speech-ws-base.d.ts +106 -0
- package/lib/text-to-speech-ws-base.d.ts.map +1 -0
- package/lib/text-to-speech-ws-base.js +475 -0
- package/lib/text-to-speech-ws-base.js.map +1 -0
- package/lib/text-to-speech-ws-base.mjs +471 -0
- package/lib/text-to-speech-ws-base.mjs.map +1 -0
- package/lib/text-to-speech-ws-internal.d.mts +71 -0
- package/lib/text-to-speech-ws-internal.d.mts.map +1 -0
- package/lib/text-to-speech-ws-internal.d.ts +71 -0
- package/lib/text-to-speech-ws-internal.d.ts.map +1 -0
- package/lib/text-to-speech-ws-internal.js +47 -0
- package/lib/text-to-speech-ws-internal.js.map +1 -0
- package/lib/text-to-speech-ws-internal.mjs +41 -0
- package/lib/text-to-speech-ws-internal.mjs.map +1 -0
- package/lib/text-to-speech-ws.d.mts +13 -0
- package/lib/text-to-speech-ws.d.mts.map +1 -0
- package/lib/text-to-speech-ws.d.ts +13 -0
- package/lib/text-to-speech-ws.d.ts.map +1 -0
- package/lib/text-to-speech-ws.js +30 -0
- package/lib/text-to-speech-ws.js.map +1 -0
- package/lib/text-to-speech-ws.mjs +25 -0
- package/lib/text-to-speech-ws.mjs.map +1 -0
- package/lib/webhooks.d.mts +6 -0
- package/lib/webhooks.d.mts.map +1 -1
- package/lib/webhooks.d.ts +6 -0
- package/lib/webhooks.d.ts.map +1 -1
- package/lib/webhooks.js +16 -0
- package/lib/webhooks.js.map +1 -1
- package/lib/webhooks.mjs +14 -0
- package/lib/webhooks.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/ai/assistants/assistants.d.mts +901 -51
- package/resources/ai/assistants/assistants.d.mts.map +1 -1
- package/resources/ai/assistants/assistants.d.ts +901 -51
- package/resources/ai/assistants/assistants.d.ts.map +1 -1
- package/resources/ai/assistants/assistants.js +0 -1
- package/resources/ai/assistants/assistants.js.map +1 -1
- package/resources/ai/assistants/assistants.mjs +0 -1
- package/resources/ai/assistants/assistants.mjs.map +1 -1
- package/resources/ai/assistants/versions.d.mts +563 -25
- package/resources/ai/assistants/versions.d.mts.map +1 -1
- package/resources/ai/assistants/versions.d.ts +563 -25
- package/resources/ai/assistants/versions.d.ts.map +1 -1
- package/resources/ai/conversations/conversations.d.mts +2 -2
- package/resources/ai/conversations/conversations.d.mts.map +1 -1
- package/resources/ai/conversations/conversations.d.ts +2 -2
- package/resources/ai/conversations/conversations.d.ts.map +1 -1
- package/resources/ai/conversations/conversations.js.map +1 -1
- package/resources/ai/conversations/conversations.mjs +1 -1
- package/resources/ai/conversations/conversations.mjs.map +1 -1
- package/resources/ai/conversations/index.d.mts +1 -1
- package/resources/ai/conversations/index.d.mts.map +1 -1
- package/resources/ai/conversations/index.d.ts +1 -1
- package/resources/ai/conversations/index.d.ts.map +1 -1
- package/resources/ai/conversations/index.js.map +1 -1
- package/resources/ai/conversations/index.mjs +1 -1
- package/resources/ai/conversations/index.mjs.map +1 -1
- package/resources/ai/conversations/messages.d.mts +46 -48
- package/resources/ai/conversations/messages.d.mts.map +1 -1
- package/resources/ai/conversations/messages.d.ts +46 -48
- package/resources/ai/conversations/messages.d.ts.map +1 -1
- package/resources/ai/conversations/messages.js +9 -6
- package/resources/ai/conversations/messages.js.map +1 -1
- package/resources/ai/conversations/messages.mjs +9 -6
- package/resources/ai/conversations/messages.mjs.map +1 -1
- package/resources/calls/actions.d.mts +114 -6
- package/resources/calls/actions.d.mts.map +1 -1
- package/resources/calls/actions.d.ts +114 -6
- package/resources/calls/actions.d.ts.map +1 -1
- package/resources/calls/actions.js +4 -0
- package/resources/calls/actions.js.map +1 -1
- package/resources/calls/actions.mjs +4 -0
- package/resources/calls/actions.mjs.map +1 -1
- package/resources/calls/calls.d.mts +168 -8
- package/resources/calls/calls.d.mts.map +1 -1
- package/resources/calls/calls.d.ts +168 -8
- package/resources/calls/calls.d.ts.map +1 -1
- package/resources/calls/calls.js +4 -0
- package/resources/calls/calls.js.map +1 -1
- package/resources/calls/calls.mjs +4 -0
- package/resources/calls/calls.mjs.map +1 -1
- package/resources/index.d.mts +2 -3
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +2 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +2 -7
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -2
- package/resources/index.mjs.map +1 -1
- package/resources/inexplicit-number-orders.d.mts.map +1 -1
- package/resources/inexplicit-number-orders.d.ts.map +1 -1
- package/resources/messages/messages.d.mts +4 -0
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +4 -0
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/networks/networks.d.mts.map +1 -1
- package/resources/networks/networks.d.ts.map +1 -1
- package/resources/networks/networks.js.map +1 -1
- package/resources/networks/networks.mjs.map +1 -1
- package/resources/session-analysis/session-analysis.d.mts +3 -13
- package/resources/session-analysis/session-analysis.d.mts.map +1 -1
- package/resources/session-analysis/session-analysis.d.ts +3 -13
- package/resources/session-analysis/session-analysis.d.ts.map +1 -1
- package/resources/session-analysis/session-analysis.js.map +1 -1
- package/resources/session-analysis/session-analysis.mjs.map +1 -1
- package/resources/texml/accounts/calls/calls.d.mts +45 -0
- package/resources/texml/accounts/calls/calls.d.mts.map +1 -1
- package/resources/texml/accounts/calls/calls.d.ts +45 -0
- package/resources/texml/accounts/calls/calls.d.ts.map +1 -1
- package/resources/texml/accounts/calls/calls.js.map +1 -1
- package/resources/texml/accounts/calls/calls.mjs.map +1 -1
- package/resources/text-to-speech/index.d.mts +2 -1
- package/resources/text-to-speech/index.d.mts.map +1 -1
- package/resources/text-to-speech/index.d.ts +2 -1
- package/resources/text-to-speech/index.d.ts.map +1 -1
- package/resources/text-to-speech/index.js.map +1 -1
- package/resources/text-to-speech/index.mjs.map +1 -1
- package/resources/text-to-speech/internal-base.d.mts +1 -48
- package/resources/text-to-speech/internal-base.d.mts.map +1 -1
- package/resources/text-to-speech/internal-base.d.ts +1 -48
- package/resources/text-to-speech/internal-base.d.ts.map +1 -1
- package/resources/text-to-speech/internal-base.js +5 -48
- package/resources/text-to-speech/internal-base.js.map +1 -1
- package/resources/text-to-speech/internal-base.mjs +1 -44
- package/resources/text-to-speech/internal-base.mjs.map +1 -1
- package/resources/text-to-speech/text-to-speech.d.mts +28 -3
- package/resources/text-to-speech/text-to-speech.d.mts.map +1 -1
- package/resources/text-to-speech/text-to-speech.d.ts +28 -3
- package/resources/text-to-speech/text-to-speech.d.ts.map +1 -1
- package/resources/text-to-speech/text-to-speech.js +1 -1
- package/resources/text-to-speech/text-to-speech.mjs +1 -1
- package/resources/text-to-speech/ws-base.d.mts +2 -0
- package/resources/text-to-speech/ws-base.d.mts.map +1 -0
- package/resources/text-to-speech/ws-base.d.ts +2 -0
- package/resources/text-to-speech/ws-base.d.ts.map +1 -0
- package/resources/text-to-speech/ws-base.js +7 -0
- package/resources/text-to-speech/ws-base.js.map +1 -0
- package/resources/text-to-speech/ws-base.mjs +3 -0
- package/resources/text-to-speech/ws-base.mjs.map +1 -0
- package/resources/text-to-speech/ws.d.mts +2 -41
- package/resources/text-to-speech/ws.d.mts.map +1 -1
- package/resources/text-to-speech/ws.d.ts +2 -41
- package/resources/text-to-speech/ws.d.ts.map +1 -1
- package/resources/text-to-speech/ws.js +2 -182
- package/resources/text-to-speech/ws.js.map +1 -1
- package/resources/text-to-speech/ws.mjs +1 -180
- package/resources/text-to-speech/ws.mjs.map +1 -1
- package/resources/verify-profiles.d.mts +97 -121
- package/resources/verify-profiles.d.mts.map +1 -1
- package/resources/verify-profiles.d.ts +97 -121
- package/resources/verify-profiles.d.ts.map +1 -1
- package/resources/virtual-cross-connects.d.mts.map +1 -1
- package/resources/virtual-cross-connects.d.ts.map +1 -1
- package/resources/webhooks.d.mts +642 -7
- package/resources/webhooks.d.mts.map +1 -1
- package/resources/webhooks.d.ts +642 -7
- package/resources/webhooks.d.ts.map +1 -1
- package/resources/webhooks.js +4 -10
- package/resources/webhooks.js.map +1 -1
- package/resources/webhooks.mjs +5 -11
- package/resources/webhooks.mjs.map +1 -1
- package/resources/whatsapp/phone-numbers/profile/profile.d.mts +5 -0
- package/resources/whatsapp/phone-numbers/profile/profile.d.mts.map +1 -1
- package/resources/whatsapp/phone-numbers/profile/profile.d.ts +5 -0
- package/resources/whatsapp/phone-numbers/profile/profile.d.ts.map +1 -1
- package/resources/whatsapp/phone-numbers/profile/profile.js.map +1 -1
- package/resources/whatsapp/phone-numbers/profile/profile.mjs.map +1 -1
- package/resources/wireguard-interfaces.d.mts.map +1 -1
- package/resources/wireguard-interfaces.d.ts.map +1 -1
- package/src/client.ts +22 -0
- package/src/core/EventEmitter.ts +16 -0
- package/src/core/pagination.ts +3 -3
- package/src/internal/detect-platform.ts +1 -1
- package/src/internal/types.ts +6 -8
- package/src/internal/utils/env.ts +2 -2
- package/src/internal/ws-adapter-browser.ts +123 -0
- package/src/internal/ws-adapter-node.ts +105 -0
- package/src/internal/ws-adapter.ts +30 -0
- package/src/internal/ws.ts +193 -0
- package/src/lib/text-to-speech-ws-base.ts +618 -0
- package/src/lib/text-to-speech-ws-internal.ts +111 -0
- package/src/lib/text-to-speech-ws.ts +40 -0
- package/src/lib/webhooks.ts +27 -0
- package/src/resources/ai/assistants/assistants.ts +1025 -51
- package/src/resources/ai/assistants/versions.ts +639 -25
- package/src/resources/ai/conversations/conversations.ts +12 -2
- package/src/resources/ai/conversations/index.ts +6 -1
- package/src/resources/ai/conversations/messages.ts +67 -54
- package/src/resources/calls/actions.ts +184 -4
- package/src/resources/calls/calls.ts +191 -4
- package/src/resources/index.ts +6 -12
- package/src/resources/inexplicit-number-orders.ts +2 -1
- package/src/resources/messages/messages.ts +5 -0
- package/src/resources/networks/networks.ts +2 -1
- package/src/resources/session-analysis/session-analysis.ts +3 -16
- package/src/resources/texml/accounts/calls/calls.ts +54 -0
- package/src/resources/text-to-speech/index.ts +2 -1
- package/src/resources/text-to-speech/internal-base.ts +6 -95
- package/src/resources/text-to-speech/text-to-speech.ts +33 -3
- package/src/resources/text-to-speech/ws-base.ts +7 -0
- package/src/resources/text-to-speech/ws.ts +2 -201
- package/src/resources/verify-profiles.ts +109 -142
- package/src/resources/virtual-cross-connects.ts +2 -1
- package/src/resources/webhooks.ts +886 -45
- package/src/resources/whatsapp/phone-numbers/profile/profile.ts +7 -0
- package/src/resources/wireguard-interfaces.ts +2 -1
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as TextToSpeechAPI from '../resources/text-to-speech/text-to-speech';
|
|
2
|
+
import { Telnyx } from '../client';
|
|
3
|
+
import { EventEmitter } from '../core/EventEmitter';
|
|
4
|
+
import { TelnyxError } from '../core/error';
|
|
5
|
+
|
|
6
|
+
import type { RawWebSocketData, ReconnectingEvent, UnsentMessage } from '../internal/ws';
|
|
7
|
+
|
|
8
|
+
export type TextToSpeechStreamMessage =
|
|
9
|
+
| { type: 'connecting' | 'open' | 'closing' }
|
|
10
|
+
| {
|
|
11
|
+
type: 'close';
|
|
12
|
+
code: number;
|
|
13
|
+
reason: string;
|
|
14
|
+
unsent: UnsentMessage<TextToSpeechAPI.StreamClientEvent>[];
|
|
15
|
+
}
|
|
16
|
+
| { type: 'reconnecting'; reconnect: ReconnectingEvent }
|
|
17
|
+
| { type: 'reconnected' }
|
|
18
|
+
| { type: 'message'; message: TextToSpeechAPI.StreamServerEvent }
|
|
19
|
+
| { type: 'raw'; data: RawWebSocketData }
|
|
20
|
+
| { type: 'error'; error: WebSocketError };
|
|
21
|
+
|
|
22
|
+
export class WebSocketError extends TelnyxError {
|
|
23
|
+
/**
|
|
24
|
+
* The error data that the API sent back in an error event.
|
|
25
|
+
*/
|
|
26
|
+
error?: TextToSpeechAPI.StreamServerEvent.ErrorFrame | undefined;
|
|
27
|
+
|
|
28
|
+
constructor(message: string, event: TextToSpeechAPI.StreamServerEvent.ErrorFrame | null) {
|
|
29
|
+
super(message);
|
|
30
|
+
|
|
31
|
+
this.error = event ?? undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
36
|
+
|
|
37
|
+
type WebSocketEvents = Simplify<
|
|
38
|
+
{
|
|
39
|
+
event: (event: TextToSpeechAPI.StreamServerEvent) => void;
|
|
40
|
+
raw: (data: RawWebSocketData) => void;
|
|
41
|
+
error: (error: WebSocketError) => void;
|
|
42
|
+
close: (code: number, reason: string, unsent: UnsentMessage<TextToSpeechAPI.StreamClientEvent>[]) => void;
|
|
43
|
+
reconnecting: (event: ReconnectingEvent) => void;
|
|
44
|
+
reconnected: () => void;
|
|
45
|
+
} & {
|
|
46
|
+
[EventType in Exclude<NonNullable<TextToSpeechAPI.StreamServerEvent['type']>, 'error'>]: (
|
|
47
|
+
event: Extract<TextToSpeechAPI.StreamServerEvent, { type?: EventType }>,
|
|
48
|
+
) => unknown;
|
|
49
|
+
}
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
export abstract class TextToSpeechEmitter extends EventEmitter<WebSocketEvents> {
|
|
53
|
+
/**
|
|
54
|
+
* Send an event to the API.
|
|
55
|
+
*/
|
|
56
|
+
abstract send(event: TextToSpeechAPI.StreamClientEvent): void;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Send raw data over the WebSocket without JSON serialization.
|
|
60
|
+
*/
|
|
61
|
+
abstract sendRaw(data: RawWebSocketData): void;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Close the WebSocket connection.
|
|
65
|
+
*/
|
|
66
|
+
abstract close(props?: { code: number; reason: string }): void;
|
|
67
|
+
|
|
68
|
+
protected _onError(event: null, message: string, cause: any): void;
|
|
69
|
+
protected _onError(event: TextToSpeechAPI.StreamServerEvent.ErrorFrame, message?: string | undefined): void;
|
|
70
|
+
protected _onError(
|
|
71
|
+
event: TextToSpeechAPI.StreamServerEvent.ErrorFrame | null,
|
|
72
|
+
message?: string | undefined,
|
|
73
|
+
cause?: any,
|
|
74
|
+
): void {
|
|
75
|
+
message = message ?? safeJSONStringify(event) ?? 'unknown error';
|
|
76
|
+
|
|
77
|
+
if (!this._hasListener('error')) {
|
|
78
|
+
const error = new WebSocketError(
|
|
79
|
+
message +
|
|
80
|
+
`\n\nTo resolve these unhandled rejection errors you should bind an \`error\` callback, e.g. \`ws.on('error', (error) => ...)\` `,
|
|
81
|
+
event,
|
|
82
|
+
);
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
error.cause = cause;
|
|
85
|
+
Promise.reject(error);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const error = new WebSocketError(message, event);
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
error.cause = cause;
|
|
92
|
+
|
|
93
|
+
this._emit('error', error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function buildURL(client: Telnyx, parameters: Record<string, unknown>): URL {
|
|
98
|
+
const { ...query } = parameters;
|
|
99
|
+
const endpoint = '/text-to-speech/speech';
|
|
100
|
+
const url = new URL(client.buildURL(endpoint, query, undefined));
|
|
101
|
+
url.protocol = url.protocol === 'http:' || url.protocol === 'ws:' ? 'ws:' : 'wss:';
|
|
102
|
+
return url;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function safeJSONStringify(value: unknown): string | null {
|
|
106
|
+
try {
|
|
107
|
+
return JSON.stringify(value);
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as WS from 'ws';
|
|
2
|
+
import { NodeWebSocket } from '../internal/ws-adapter-node';
|
|
3
|
+
import { TextToSpeechWSBase, type TextToSpeechWSBaseOptions } from './text-to-speech-ws-base';
|
|
4
|
+
import { Telnyx } from '../client';
|
|
5
|
+
|
|
6
|
+
export type { TextToSpeechWSReconnectOptions } from './text-to-speech-ws-base';
|
|
7
|
+
|
|
8
|
+
export interface TextToSpeechWSClientOptions extends WS.ClientOptions, TextToSpeechWSBaseOptions {}
|
|
9
|
+
|
|
10
|
+
export class TextToSpeechWS extends TextToSpeechWSBase<NodeWebSocket> {
|
|
11
|
+
private _wsOptions: WS.ClientOptions | null | undefined;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
client: Telnyx,
|
|
15
|
+
parameters?: Record<string, unknown> | undefined,
|
|
16
|
+
options?: TextToSpeechWSClientOptions | null | undefined,
|
|
17
|
+
) {
|
|
18
|
+
if (!WS?.WebSocket) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'TextToSpeechWS from "telnyx/resources/text-to-speech/ws" requires the "ws" package but it could not be loaded.',
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { reconnect, maxQueueSize, ...wsOptions } = options ?? {};
|
|
25
|
+
super(client, parameters, { reconnect, maxQueueSize });
|
|
26
|
+
this._wsOptions = wsOptions;
|
|
27
|
+
this._connectInitial();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected _createSocket(url: URL, authHeaders: Record<string, string>): NodeWebSocket {
|
|
31
|
+
const ws = new WS.WebSocket(url, {
|
|
32
|
+
...this._wsOptions,
|
|
33
|
+
headers: {
|
|
34
|
+
...authHeaders,
|
|
35
|
+
...this._wsOptions?.headers,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return new NodeWebSocket(ws);
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/lib/webhooks.ts
CHANGED
|
@@ -30,6 +30,33 @@ export class TelnyxWebhookVerificationError extends TelnyxError {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export interface WebhookUnwrapOptions {
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
key?: string | Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function unsafeUnwrapWebhook<T>(body: string): T {
|
|
39
|
+
return JSON.parse(body) as T;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function unwrapWebhook<T>(
|
|
43
|
+
body: string,
|
|
44
|
+
options: WebhookUnwrapOptions | undefined,
|
|
45
|
+
clientPublicKey: string | null,
|
|
46
|
+
): Promise<T> {
|
|
47
|
+
if (options?.headers) {
|
|
48
|
+
const key = options.key || clientPublicKey;
|
|
49
|
+
if (!key) {
|
|
50
|
+
throw new TelnyxWebhookVerificationError('No public key provided for webhook verification');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const webhook = new TelnyxWebhook(key);
|
|
54
|
+
await webhook.verify(body, options.headers);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return unsafeUnwrapWebhook<T>(body);
|
|
58
|
+
}
|
|
59
|
+
|
|
33
60
|
// Type for the SubtleCrypto interface we need
|
|
34
61
|
// Using unknown for key type to avoid CryptoKey dependency
|
|
35
62
|
interface SubtleCryptoLike {
|