@absolutejs/voice 0.0.22-beta.76 → 0.0.22-beta.78

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/dist/index.d.ts CHANGED
@@ -81,7 +81,11 @@ export type { VoiceS3ReviewStoreClient, VoiceS3ReviewStoreFile, VoiceS3ReviewSto
81
81
  export type { VoiceSQLiteRuntimeStorage, VoiceSQLiteStoreOptions } from './sqliteStore';
82
82
  export type { StoredVoiceIntegrationEvent, StoredVoiceExternalObjectMap, StoredVoiceOpsTask, VoiceExternalObjectMap, VoiceExternalObjectMapStore, VoiceOpsTaskAgeBucket, VoiceOpsTaskAnalyticsOptions, VoiceOpsTaskAnalyticsSummary, VoiceOpsTaskAssignmentRule, VoiceOpsTaskAssignmentRuleCondition, VoiceOpsTaskAssignmentRules, VoiceOpsTaskAssigneeAnalytics, VoiceOpsDispositionTaskPolicies, VoiceOpsSLABreachPolicy, VoiceIntegrationDeliveryStatus, VoiceIntegrationEvent, VoiceIntegrationEventStore, VoiceIntegrationSinkDelivery, VoiceIntegrationEventType, VoiceIntegrationWebhookConfig, VoiceOpsTask, VoiceOpsTaskHistoryEntry, VoiceOpsTaskKind, VoiceOpsTaskPolicy, VoiceOpsTaskPriority, VoiceOpsTaskStatus, VoiceOpsTaskStore, VoiceOpsTaskSummary, VoiceOpsTaskWorkerAnalytics } from './ops';
83
83
  export { createTwilioMediaStreamBridge, createTwilioVoiceRoutes, createTwilioVoiceResponse, decodeTwilioMulawBase64, encodeTwilioMulawBase64, transcodePCMToTwilioOutboundPayload, transcodeTwilioInboundPayloadToPCM16 } from './telephony/twilio';
84
+ export { evaluateVoiceTelephonyContract } from './telephony/contract';
85
+ export { createTelnyxVoiceResponse, createTelnyxVoiceRoutes, verifyVoiceTelnyxWebhookSignature } from './telephony/telnyx';
84
86
  export type { TwilioInboundMessage, TwilioMediaStreamBridge, TwilioMediaStreamBridgeOptions, TwilioMediaStreamSocket, TwilioOutboundClearMessage, TwilioOutboundMarkMessage, TwilioOutboundMediaMessage, TwilioOutboundMessage, TwilioVoiceRouteParameters, TwilioVoiceResponseOptions, TwilioVoiceSmokeCheck, TwilioVoiceSmokeOptions, TwilioVoiceSmokeReport, TwilioVoiceSetupOptions, TwilioVoiceSetupStatus, TwilioVoiceRoutesOptions } from './telephony/twilio';
87
+ export type { VoiceTelephonyContractIssue, VoiceTelephonyContractOptions, VoiceTelephonyContractReport, VoiceTelephonyContractRequirement, VoiceTelephonyProvider, VoiceTelephonySetupStatus, VoiceTelephonySmokeCheck, VoiceTelephonySmokeReport } from './telephony/contract';
88
+ export type { TelnyxVoiceResponseOptions, TelnyxVoiceRoutesOptions, TelnyxVoiceSetupOptions, TelnyxVoiceSetupStatus, TelnyxVoiceSmokeCheck, TelnyxVoiceSmokeOptions, TelnyxVoiceSmokeReport } from './telephony/telnyx';
85
89
  export { shapeTelephonyAssistantText } from './telephony/response';
86
90
  export type { TelephonyResponseShapeMode, TelephonyResponseShapeOptions } from './telephony/response';
87
91
  export * from './types';
package/dist/index.js CHANGED
@@ -15904,6 +15904,372 @@ var createTwilioVoiceRoutes = (options) => {
15904
15904
  return report;
15905
15905
  });
15906
15906
  };
15907
+ // src/telephony/contract.ts
15908
+ var DEFAULT_REQUIREMENTS = [
15909
+ "stream-url",
15910
+ "wss-stream",
15911
+ "webhook-url",
15912
+ "signed-webhook",
15913
+ "smoke-pass"
15914
+ ];
15915
+ var hasFailingSmokeCheck = (smoke) => smoke?.checks.some((check) => check.status === "fail") ?? false;
15916
+ var evaluateVoiceTelephonyContract = (input) => {
15917
+ const requirements = input.options?.requirements ?? DEFAULT_REQUIREMENTS;
15918
+ const issues = [];
15919
+ const hasRequirement = (requirement) => requirements.includes(requirement);
15920
+ if (hasRequirement("stream-url") && !input.setup.urls.stream) {
15921
+ issues.push({
15922
+ message: "Missing media stream URL.",
15923
+ requirement: "stream-url",
15924
+ severity: "error"
15925
+ });
15926
+ }
15927
+ if (hasRequirement("wss-stream") && !input.setup.urls.stream.startsWith("wss://")) {
15928
+ issues.push({
15929
+ message: "Media stream URL must use wss://.",
15930
+ requirement: "wss-stream",
15931
+ severity: "error"
15932
+ });
15933
+ }
15934
+ if (hasRequirement("webhook-url") && !input.setup.urls.webhook) {
15935
+ issues.push({
15936
+ message: "Missing carrier webhook URL.",
15937
+ requirement: "webhook-url",
15938
+ severity: "error"
15939
+ });
15940
+ }
15941
+ if (hasRequirement("signed-webhook") && !input.setup.signing.configured) {
15942
+ issues.push({
15943
+ message: "Carrier webhook signature verification is not configured.",
15944
+ requirement: "signed-webhook",
15945
+ severity: "error"
15946
+ });
15947
+ }
15948
+ if (hasRequirement("smoke-pass")) {
15949
+ if (!input.smoke) {
15950
+ issues.push({
15951
+ message: "Missing telephony smoke test report.",
15952
+ requirement: "smoke-pass",
15953
+ severity: "error"
15954
+ });
15955
+ } else if (!input.smoke.pass || hasFailingSmokeCheck(input.smoke)) {
15956
+ issues.push({
15957
+ message: "Telephony smoke test did not pass.",
15958
+ requirement: "smoke-pass",
15959
+ severity: "error"
15960
+ });
15961
+ }
15962
+ }
15963
+ for (const warning of input.setup.warnings) {
15964
+ issues.push({
15965
+ message: warning,
15966
+ requirement: "stream-url",
15967
+ severity: "warning"
15968
+ });
15969
+ }
15970
+ for (const name of input.setup.missing) {
15971
+ issues.push({
15972
+ message: `${name} is missing.`,
15973
+ requirement: "webhook-url",
15974
+ severity: "error"
15975
+ });
15976
+ }
15977
+ return {
15978
+ issues,
15979
+ pass: issues.every((issue) => issue.severity !== "error"),
15980
+ provider: input.setup.provider,
15981
+ requirements,
15982
+ setup: input.setup,
15983
+ smoke: input.smoke
15984
+ };
15985
+ };
15986
+ // src/telephony/telnyx.ts
15987
+ import { Buffer as Buffer4 } from "buffer";
15988
+ import { Elysia as Elysia19 } from "elysia";
15989
+ var escapeXml3 = (value) => value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("'", "&apos;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
15990
+ var escapeHtml18 = (value) => value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
15991
+ var joinUrlPath2 = (origin, path) => `${origin.replace(/\/$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
15992
+ var resolveRequestOrigin2 = (request) => {
15993
+ const url = new URL(request.url);
15994
+ const forwardedHost = request.headers.get("x-forwarded-host");
15995
+ const forwardedProto = request.headers.get("x-forwarded-proto");
15996
+ const host = forwardedHost ?? request.headers.get("host") ?? url.host;
15997
+ const protocol = forwardedProto ?? url.protocol.replace(":", "");
15998
+ return `${protocol}://${host}`;
15999
+ };
16000
+ var extractTelnyxStreamUrl = (texml) => texml.match(/<Stream\b[^>]*\surl="([^"]+)"/i)?.[1]?.replaceAll("&amp;", "&");
16001
+ var createSmokeCheck2 = (name, status, message, details) => ({
16002
+ details,
16003
+ message,
16004
+ name,
16005
+ status
16006
+ });
16007
+ var resolveTelnyxStreamUrl = async (options, input) => {
16008
+ if (typeof options.texml?.streamUrl === "function") {
16009
+ return options.texml.streamUrl(input);
16010
+ }
16011
+ if (typeof options.texml?.streamUrl === "string") {
16012
+ return options.texml.streamUrl;
16013
+ }
16014
+ const origin = resolveRequestOrigin2(input.request);
16015
+ const wsOrigin = origin.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
16016
+ return `${wsOrigin}${input.streamPath}`;
16017
+ };
16018
+ var createTelnyxVoiceResponse = (options) => {
16019
+ const attributes = [
16020
+ `url="${escapeXml3(options.streamUrl)}"`,
16021
+ options.streamName ? `name="${escapeXml3(options.streamName)}"` : undefined,
16022
+ options.track ? `track="${escapeXml3(options.track)}"` : undefined,
16023
+ options.codec ? `codec="${escapeXml3(options.codec)}"` : undefined,
16024
+ options.bidirectionalMode ? `bidirectionalMode="${escapeXml3(options.bidirectionalMode)}"` : undefined,
16025
+ options.bidirectionalCodec ? `bidirectionalCodec="${escapeXml3(options.bidirectionalCodec)}"` : undefined
16026
+ ].filter((value) => Boolean(value)).join(" ");
16027
+ return `<?xml version="1.0" encoding="UTF-8"?><Response><Start><Stream ${attributes} /></Start></Response>`;
16028
+ };
16029
+ var decodeBase64 = (value) => Uint8Array.from(Buffer4.from(value, "base64"));
16030
+ var verifyVoiceTelnyxWebhookSignature = async (input) => {
16031
+ if (!input.publicKey) {
16032
+ return { ok: false, reason: "missing-secret" };
16033
+ }
16034
+ const signature = input.headers.get("telnyx-signature-ed25519");
16035
+ const timestamp = input.headers.get("telnyx-timestamp");
16036
+ if (!signature || !timestamp) {
16037
+ return { ok: false, reason: "missing-signature" };
16038
+ }
16039
+ const toleranceSeconds = input.toleranceSeconds ?? 300;
16040
+ const timestampNumber = Number(timestamp);
16041
+ if (Number.isFinite(timestampNumber) && Math.abs(Date.now() / 1000 - timestampNumber) > toleranceSeconds) {
16042
+ return { ok: false, reason: "invalid-signature" };
16043
+ }
16044
+ try {
16045
+ const key = await crypto.subtle.importKey("raw", decodeBase64(input.publicKey), "Ed25519", false, ["verify"]);
16046
+ const ok = await crypto.subtle.verify("Ed25519", key, decodeBase64(signature), new TextEncoder().encode(`${timestamp}|${input.body}`));
16047
+ return ok ? { ok: true } : { ok: false, reason: "invalid-signature" };
16048
+ } catch {
16049
+ return { ok: false, reason: "invalid-signature" };
16050
+ }
16051
+ };
16052
+ var buildTelnyxVoiceSetupStatus = async (options, input) => {
16053
+ const origin = resolveRequestOrigin2(input.request);
16054
+ const stream = await resolveTelnyxStreamUrl(options, input);
16055
+ const texml = joinUrlPath2(origin, input.texmlPath);
16056
+ const webhook = joinUrlPath2(origin, input.webhookPath);
16057
+ const missing = Object.entries(options.setup?.requiredEnv ?? {}).filter((entry) => !entry[1]).map(([name]) => name);
16058
+ const signingConfigured = Boolean(options.webhook?.publicKey || options.webhook?.verify);
16059
+ const warnings = [
16060
+ ...stream.startsWith("wss://") ? [] : ["Telnyx media streams should use wss:// in production."],
16061
+ ...signingConfigured ? [] : ["Webhook signature verification is not configured."]
16062
+ ];
16063
+ return {
16064
+ generatedAt: Date.now(),
16065
+ missing,
16066
+ provider: "telnyx",
16067
+ ready: missing.length === 0 && signingConfigured && warnings.length === 0,
16068
+ signing: {
16069
+ configured: signingConfigured,
16070
+ mode: options.webhook?.verify ? "custom" : options.webhook?.publicKey ? "provider-signature" : "none",
16071
+ verificationUrl: webhook
16072
+ },
16073
+ urls: {
16074
+ stream,
16075
+ texml,
16076
+ webhook
16077
+ },
16078
+ warnings
16079
+ };
16080
+ };
16081
+ var renderTelnyxSetupHTML = (status, title) => `<main style="font-family: ui-sans-serif, system-ui; max-width: 860px; margin: 40px auto; padding: 0 20px;">
16082
+ <p style="letter-spacing: .12em; text-transform: uppercase; color: #52606d;">Telnyx setup</p>
16083
+ <h1>${escapeHtml18(title)}</h1>
16084
+ <p><strong>Status:</strong> ${status.ready ? "Ready" : "Needs attention"}</p>
16085
+ <ul>
16086
+ <li><strong>TeXML:</strong> <code>${escapeHtml18(status.urls.texml)}</code></li>
16087
+ <li><strong>Media stream:</strong> <code>${escapeHtml18(status.urls.stream)}</code></li>
16088
+ <li><strong>Status webhook:</strong> <code>${escapeHtml18(status.urls.webhook)}</code></li>
16089
+ </ul>
16090
+ ${status.missing.length ? `<h2>Missing env</h2><ul>${status.missing.map((name) => `<li><code>${escapeHtml18(name)}</code></li>`).join("")}</ul>` : ""}
16091
+ ${status.warnings.length ? `<h2>Warnings</h2><ul>${status.warnings.map((warning) => `<li>${escapeHtml18(warning)}</li>`).join("")}</ul>` : ""}
16092
+ </main>`;
16093
+ var renderTelnyxSmokeHTML = (report, title) => `<main style="font-family: ui-sans-serif, system-ui; max-width: 860px; margin: 40px auto; padding: 0 20px;">
16094
+ <p style="letter-spacing: .12em; text-transform: uppercase; color: #52606d;">Telnyx smoke test</p>
16095
+ <h1>${escapeHtml18(title)}</h1>
16096
+ <p><strong>Status:</strong> ${report.pass ? "Pass" : "Fail"}</p>
16097
+ <ul>${report.checks.map((check) => `<li><strong>${escapeHtml18(check.name)}</strong>: ${escapeHtml18(check.status)}${check.message ? ` - ${escapeHtml18(check.message)}` : ""}</li>`).join("")}</ul>
16098
+ </main>`;
16099
+ var runTelnyxSmokeTest = async (input) => {
16100
+ const setup = await buildTelnyxVoiceSetupStatus(input.options, input);
16101
+ const checks = [];
16102
+ const texmlResponse = await input.app.handle(new Request(setup.urls.texml));
16103
+ const texml = await texmlResponse.text();
16104
+ const streamUrl = extractTelnyxStreamUrl(texml);
16105
+ checks.push(createSmokeCheck2("texml", texmlResponse.ok && Boolean(streamUrl) ? "pass" : "fail", streamUrl ? "TeXML includes a media stream URL." : 'TeXML is missing <Stream url="...">.', {
16106
+ status: texmlResponse.status,
16107
+ streamUrl
16108
+ }));
16109
+ checks.push(createSmokeCheck2("stream-url", streamUrl?.startsWith("wss://") ? "pass" : "fail", streamUrl?.startsWith("wss://") ? "Media stream URL uses wss://." : "Media stream URL should use wss:// for Telnyx.", {
16110
+ streamUrl
16111
+ }));
16112
+ const webhookBody = {
16113
+ data: {
16114
+ event_type: input.options.smoke?.eventType ?? "call.hangup",
16115
+ id: "telnyx-smoke-event",
16116
+ payload: {
16117
+ call_control_id: input.options.smoke?.callControlId ?? "telnyx-smoke-call",
16118
+ call_leg_id: input.options.smoke?.callLegId ?? "telnyx-smoke-leg",
16119
+ call_session_id: input.options.smoke?.sessionId ?? "telnyx-smoke-session",
16120
+ hangup_cause: "busy",
16121
+ sip_hangup_cause: 486
16122
+ },
16123
+ record_type: "event"
16124
+ }
16125
+ };
16126
+ const webhookResponse = await input.app.handle(new Request(setup.urls.webhook, {
16127
+ body: JSON.stringify(webhookBody),
16128
+ headers: {
16129
+ "content-type": "application/json"
16130
+ },
16131
+ method: "POST"
16132
+ }));
16133
+ const webhookText = await webhookResponse.text();
16134
+ const webhookPayload = (() => {
16135
+ try {
16136
+ return JSON.parse(webhookText);
16137
+ } catch {
16138
+ return webhookText;
16139
+ }
16140
+ })();
16141
+ checks.push(createSmokeCheck2("webhook", webhookResponse.ok ? "pass" : "fail", webhookResponse.ok ? "Synthetic Telnyx event was accepted." : "Synthetic Telnyx event failed.", {
16142
+ status: webhookResponse.status
16143
+ }));
16144
+ for (const warning of setup.warnings) {
16145
+ checks.push(createSmokeCheck2("setup-warning", "warn", warning));
16146
+ }
16147
+ for (const name of setup.missing) {
16148
+ checks.push(createSmokeCheck2("missing-env", "fail", `${name} is missing.`));
16149
+ }
16150
+ const baseReport = {
16151
+ checks,
16152
+ generatedAt: Date.now(),
16153
+ pass: checks.every((check) => check.status !== "fail"),
16154
+ provider: "telnyx",
16155
+ setup,
16156
+ texml: {
16157
+ status: texmlResponse.status,
16158
+ streamUrl
16159
+ },
16160
+ twiml: {
16161
+ status: texmlResponse.status,
16162
+ streamUrl
16163
+ },
16164
+ webhook: {
16165
+ body: webhookPayload,
16166
+ status: webhookResponse.status
16167
+ }
16168
+ };
16169
+ return {
16170
+ ...baseReport,
16171
+ contract: evaluateVoiceTelephonyContract({
16172
+ setup,
16173
+ smoke: baseReport
16174
+ })
16175
+ };
16176
+ };
16177
+ var createTelnyxVoiceRoutes = (options = {}) => {
16178
+ const streamPath = options.streamPath ?? "/api/voice/telnyx/stream";
16179
+ const texmlPath = options.texml?.path ?? "/api/voice/telnyx";
16180
+ const webhookPath = options.webhook?.path ?? "/api/voice/telnyx/webhook";
16181
+ const setupPath = options.setup?.path === false ? false : options.setup?.path ?? "/api/voice/telnyx/setup";
16182
+ const smokePath = options.smoke?.path === false ? false : options.smoke?.path ?? "/api/voice/telnyx/smoke";
16183
+ const webhookPolicy = options.webhook?.policy ?? options.outcomePolicy ?? createVoiceTelephonyOutcomePolicy();
16184
+ const verify = options.webhook?.verify ?? (options.webhook?.publicKey ? (input) => verifyVoiceTelnyxWebhookSignature({
16185
+ body: input.rawBody,
16186
+ headers: input.headers,
16187
+ publicKey: options.webhook?.publicKey,
16188
+ toleranceSeconds: options.webhook?.toleranceSeconds
16189
+ }) : undefined);
16190
+ const app = new Elysia19({
16191
+ name: options.name ?? "absolutejs-voice-telnyx"
16192
+ }).get(texmlPath, async ({ query, request }) => {
16193
+ const streamUrl = await resolveTelnyxStreamUrl(options, {
16194
+ query,
16195
+ request,
16196
+ streamPath
16197
+ });
16198
+ return new Response(createTelnyxVoiceResponse({
16199
+ ...options.texml?.response,
16200
+ streamUrl
16201
+ }), {
16202
+ headers: {
16203
+ "content-type": "text/xml; charset=utf-8"
16204
+ }
16205
+ });
16206
+ }).post(texmlPath, async ({ query, request }) => {
16207
+ const streamUrl = await resolveTelnyxStreamUrl(options, {
16208
+ query,
16209
+ request,
16210
+ streamPath
16211
+ });
16212
+ return new Response(createTelnyxVoiceResponse({
16213
+ ...options.texml?.response,
16214
+ streamUrl
16215
+ }), {
16216
+ headers: {
16217
+ "content-type": "text/xml; charset=utf-8"
16218
+ }
16219
+ });
16220
+ }).use(createVoiceTelephonyWebhookRoutes({
16221
+ ...options.webhook ?? {},
16222
+ context: options.context,
16223
+ path: webhookPath,
16224
+ policy: webhookPolicy,
16225
+ provider: "telnyx",
16226
+ requireVerification: Boolean(options.webhook?.publicKey),
16227
+ resolveSessionId: options.webhook?.resolveSessionId ?? (({ event }) => {
16228
+ const metadata = event.metadata;
16229
+ return typeof metadata?.call_session_id === "string" ? metadata.call_session_id : typeof metadata?.callSessionId === "string" ? metadata.callSessionId : typeof metadata?.call_control_id === "string" ? metadata.call_control_id : undefined;
16230
+ }),
16231
+ verify
16232
+ }));
16233
+ const withSetup = setupPath ? app.get(setupPath, async ({ query, request }) => {
16234
+ const status = await buildTelnyxVoiceSetupStatus(options, {
16235
+ query,
16236
+ request,
16237
+ streamPath,
16238
+ texmlPath,
16239
+ webhookPath
16240
+ });
16241
+ if (query.format === "html") {
16242
+ return new Response(renderTelnyxSetupHTML(status, options.setup?.title ?? "AbsoluteJS Telnyx Voice Setup"), {
16243
+ headers: {
16244
+ "content-type": "text/html; charset=utf-8"
16245
+ }
16246
+ });
16247
+ }
16248
+ return status;
16249
+ }) : app;
16250
+ if (!smokePath) {
16251
+ return withSetup;
16252
+ }
16253
+ return withSetup.get(smokePath, async ({ query, request }) => {
16254
+ const report = await runTelnyxSmokeTest({
16255
+ app,
16256
+ options,
16257
+ query,
16258
+ request,
16259
+ streamPath,
16260
+ texmlPath,
16261
+ webhookPath
16262
+ });
16263
+ if (query.format === "html") {
16264
+ return new Response(renderTelnyxSmokeHTML(report, options.smoke?.title ?? "AbsoluteJS Telnyx Voice Smoke Test"), {
16265
+ headers: {
16266
+ "content-type": "text/html; charset=utf-8"
16267
+ }
16268
+ });
16269
+ }
16270
+ return report;
16271
+ });
16272
+ };
15907
16273
  // src/telephony/response.ts
15908
16274
  var normalizeWhitespace = (value) => value.replace(/\s+/g, " ").trim();
15909
16275
  var DEFAULT_MAX_WORDS = 12;
@@ -15962,6 +16328,7 @@ export {
15962
16328
  voiceTelephonyOutcomeToRouteResult,
15963
16329
  voice,
15964
16330
  verifyVoiceTwilioWebhookSignature,
16331
+ verifyVoiceTelnyxWebhookSignature,
15965
16332
  verifyVoiceOpsWebhookSignature,
15966
16333
  validateVoiceWorkflowRouteResult,
15967
16334
  transcodeTwilioInboundPayloadToPCM16,
@@ -16046,6 +16413,7 @@ export {
16046
16413
  failVoiceOpsTask,
16047
16414
  exportVoiceTrace,
16048
16415
  evaluateVoiceTrace,
16416
+ evaluateVoiceTelephonyContract,
16049
16417
  evaluateVoiceQuality,
16050
16418
  encodeTwilioMulawBase64,
16051
16419
  deliverVoiceTraceEventsToSinks,
@@ -16202,6 +16570,8 @@ export {
16202
16570
  createTwilioVoiceRoutes,
16203
16571
  createTwilioVoiceResponse,
16204
16572
  createTwilioMediaStreamBridge,
16573
+ createTelnyxVoiceRoutes,
16574
+ createTelnyxVoiceResponse,
16205
16575
  createStoredVoiceOpsTask,
16206
16576
  createStoredVoiceIntegrationEvent,
16207
16577
  createStoredVoiceExternalObjectMap,
@@ -0,0 +1,61 @@
1
+ export type VoiceTelephonyProvider = 'generic' | 'plivo' | 'telnyx' | 'twilio';
2
+ export type VoiceTelephonySetupStatus<TProvider extends VoiceTelephonyProvider = VoiceTelephonyProvider> = {
3
+ generatedAt: number;
4
+ missing: string[];
5
+ provider: TProvider;
6
+ ready: boolean;
7
+ signing: {
8
+ configured: boolean;
9
+ mode: 'custom' | 'none' | 'provider-signature' | 'twilio-signature';
10
+ verificationUrl?: string;
11
+ };
12
+ urls: {
13
+ stream: string;
14
+ twiml?: string;
15
+ webhook: string;
16
+ };
17
+ warnings: string[];
18
+ };
19
+ export type VoiceTelephonySmokeCheck = {
20
+ details?: Record<string, unknown>;
21
+ message?: string;
22
+ name: string;
23
+ status: 'fail' | 'pass' | 'warn';
24
+ };
25
+ export type VoiceTelephonySmokeReport<TProvider extends VoiceTelephonyProvider = VoiceTelephonyProvider> = {
26
+ checks: VoiceTelephonySmokeCheck[];
27
+ generatedAt: number;
28
+ pass: boolean;
29
+ provider: TProvider;
30
+ setup: VoiceTelephonySetupStatus<TProvider>;
31
+ twiml?: {
32
+ status: number;
33
+ streamUrl?: string;
34
+ };
35
+ webhook?: {
36
+ body?: unknown;
37
+ status: number;
38
+ };
39
+ };
40
+ export type VoiceTelephonyContractRequirement = 'signed-webhook' | 'smoke-pass' | 'stream-url' | 'webhook-url' | 'wss-stream';
41
+ export type VoiceTelephonyContractIssue = {
42
+ requirement: VoiceTelephonyContractRequirement;
43
+ severity: 'error' | 'warning';
44
+ message: string;
45
+ };
46
+ export type VoiceTelephonyContractReport<TProvider extends VoiceTelephonyProvider = VoiceTelephonyProvider> = {
47
+ issues: VoiceTelephonyContractIssue[];
48
+ pass: boolean;
49
+ provider: TProvider;
50
+ requirements: VoiceTelephonyContractRequirement[];
51
+ setup: VoiceTelephonySetupStatus<TProvider>;
52
+ smoke?: VoiceTelephonySmokeReport<TProvider>;
53
+ };
54
+ export type VoiceTelephonyContractOptions = {
55
+ requirements?: VoiceTelephonyContractRequirement[];
56
+ };
57
+ export declare const evaluateVoiceTelephonyContract: <TProvider extends VoiceTelephonyProvider>(input: {
58
+ options?: VoiceTelephonyContractOptions;
59
+ setup: VoiceTelephonySetupStatus<TProvider>;
60
+ smoke?: VoiceTelephonySmokeReport<TProvider>;
61
+ }) => VoiceTelephonyContractReport<TProvider>;
@@ -0,0 +1,139 @@
1
+ import { Elysia } from 'elysia';
2
+ import { type VoiceTelephonyContractReport, type VoiceTelephonySetupStatus, type VoiceTelephonySmokeCheck, type VoiceTelephonySmokeReport } from './contract';
3
+ import { type VoiceTelephonyOutcomePolicy, type VoiceTelephonyWebhookRoutesOptions, type VoiceTelephonyWebhookVerificationResult } from '../telephonyOutcome';
4
+ import type { VoiceSessionRecord } from '../types';
5
+ export type TelnyxVoiceResponseOptions = {
6
+ bidirectionalCodec?: 'AMR-WB' | 'G722' | 'OPUS' | 'PCMA' | 'PCMU';
7
+ bidirectionalMode?: 'mp3' | 'rtp';
8
+ codec?: 'AMR-WB' | 'G722' | 'OPUS' | 'PCMA' | 'PCMU' | 'default';
9
+ streamName?: string;
10
+ streamUrl: string;
11
+ track?: 'both_tracks' | 'inbound_track' | 'outbound_track';
12
+ };
13
+ export type TelnyxVoiceSetupStatus = VoiceTelephonySetupStatus<'telnyx'> & {
14
+ urls: VoiceTelephonySetupStatus<'telnyx'>['urls'] & {
15
+ texml: string;
16
+ };
17
+ };
18
+ export type TelnyxVoiceSetupOptions = {
19
+ path?: false | string;
20
+ requiredEnv?: Record<string, string | undefined>;
21
+ title?: string;
22
+ };
23
+ export type TelnyxVoiceSmokeCheck = VoiceTelephonySmokeCheck;
24
+ export type TelnyxVoiceSmokeReport = VoiceTelephonySmokeReport<'telnyx'> & {
25
+ contract: VoiceTelephonyContractReport<'telnyx'>;
26
+ setup: TelnyxVoiceSetupStatus;
27
+ texml?: {
28
+ status: number;
29
+ streamUrl?: string;
30
+ };
31
+ };
32
+ export type TelnyxVoiceSmokeOptions = {
33
+ callControlId?: string;
34
+ callLegId?: string;
35
+ eventType?: string;
36
+ path?: false | string;
37
+ sessionId?: string;
38
+ title?: string;
39
+ };
40
+ export type TelnyxVoiceRoutesOptions<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = {
41
+ context?: TContext;
42
+ name?: string;
43
+ outcomePolicy?: VoiceTelephonyOutcomePolicy;
44
+ setup?: TelnyxVoiceSetupOptions;
45
+ smoke?: TelnyxVoiceSmokeOptions;
46
+ streamPath?: string;
47
+ texml?: {
48
+ path?: string;
49
+ response?: Omit<TelnyxVoiceResponseOptions, 'streamUrl'>;
50
+ streamUrl?: string | ((input: {
51
+ query: Record<string, unknown>;
52
+ request: Request;
53
+ streamPath: string;
54
+ }) => Promise<string> | string);
55
+ };
56
+ webhook?: Omit<VoiceTelephonyWebhookRoutesOptions<TContext, TSession, TResult>, 'context' | 'path' | 'policy' | 'provider'> & {
57
+ path?: string;
58
+ policy?: VoiceTelephonyOutcomePolicy;
59
+ publicKey?: string;
60
+ toleranceSeconds?: number;
61
+ };
62
+ };
63
+ export declare const createTelnyxVoiceResponse: (options: TelnyxVoiceResponseOptions) => string;
64
+ export declare const verifyVoiceTelnyxWebhookSignature: (input: {
65
+ body: string;
66
+ headers: Headers;
67
+ publicKey?: string;
68
+ toleranceSeconds?: number;
69
+ }) => Promise<VoiceTelephonyWebhookVerificationResult>;
70
+ export declare const createTelnyxVoiceRoutes: <TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown>(options?: TelnyxVoiceRoutesOptions<TContext, TSession, TResult>) => Elysia<"", {
71
+ decorator: {};
72
+ store: {};
73
+ derive: {};
74
+ resolve: {};
75
+ }, {
76
+ typebox: {};
77
+ error: {};
78
+ }, {
79
+ schema: {};
80
+ standaloneSchema: {};
81
+ macro: {};
82
+ macroFn: {};
83
+ parser: {};
84
+ response: {};
85
+ }, {
86
+ [x: string]: {
87
+ get: {
88
+ body: unknown;
89
+ params: {};
90
+ query: unknown;
91
+ headers: unknown;
92
+ response: {
93
+ 200: Response;
94
+ };
95
+ };
96
+ };
97
+ } & {
98
+ [x: string]: {
99
+ post: {
100
+ body: unknown;
101
+ params: {};
102
+ query: unknown;
103
+ headers: unknown;
104
+ response: {
105
+ 200: Response;
106
+ };
107
+ };
108
+ };
109
+ } & {
110
+ [x: string]: {
111
+ post: {
112
+ body: unknown;
113
+ params: {};
114
+ query: unknown;
115
+ headers: unknown;
116
+ response: {
117
+ 200: Response | import("..").VoiceTelephonyWebhookDecision<TResult>;
118
+ };
119
+ };
120
+ };
121
+ }, {
122
+ derive: {};
123
+ resolve: {};
124
+ schema: {};
125
+ standaloneSchema: {};
126
+ response: {};
127
+ }, {
128
+ derive: {};
129
+ resolve: {};
130
+ schema: {};
131
+ standaloneSchema: {};
132
+ response: {};
133
+ } & {
134
+ derive: {};
135
+ resolve: {};
136
+ schema: {};
137
+ standaloneSchema: {};
138
+ response: {};
139
+ }>;
@@ -1,4 +1,5 @@
1
1
  import { Elysia } from 'elysia';
2
+ import type { VoiceTelephonySetupStatus, VoiceTelephonySmokeCheck, VoiceTelephonySmokeReport } from './contract';
2
3
  import { type VoiceTelephonyOutcomePolicy, type VoiceTelephonyWebhookRoutesOptions } from '../telephonyOutcome';
3
4
  import { type VoiceCallReviewArtifact, type VoiceCallReviewConfig } from '../testing/review';
4
5
  import type { AudioFormat, VoiceLogger, VoicePluginConfig, VoiceSessionRecord, VoiceServerMessage } from '../types';
@@ -113,48 +114,19 @@ export type TwilioVoiceRouteParameters = Record<string, string | number | boolea
113
114
  query: Record<string, unknown>;
114
115
  request: Request;
115
116
  }) => Promise<Record<string, string | number | boolean | undefined>> | Record<string, string | number | boolean | undefined>);
116
- export type TwilioVoiceSetupStatus = {
117
- generatedAt: number;
118
- missing: string[];
119
- provider: 'twilio';
120
- ready: boolean;
121
- signing: {
122
- configured: boolean;
123
- mode: 'custom' | 'none' | 'twilio-signature';
124
- verificationUrl?: string;
125
- };
126
- urls: {
127
- stream: string;
117
+ export type TwilioVoiceSetupStatus = VoiceTelephonySetupStatus<'twilio'> & {
118
+ urls: VoiceTelephonySetupStatus<'twilio'>['urls'] & {
128
119
  twiml: string;
129
- webhook: string;
130
120
  };
131
- warnings: string[];
132
121
  };
133
122
  export type TwilioVoiceSetupOptions = {
134
123
  path?: false | string;
135
124
  requiredEnv?: Record<string, string | undefined>;
136
125
  title?: string;
137
126
  };
138
- export type TwilioVoiceSmokeCheck = {
139
- details?: Record<string, unknown>;
140
- message?: string;
141
- name: string;
142
- status: 'fail' | 'pass' | 'warn';
143
- };
144
- export type TwilioVoiceSmokeReport = {
145
- checks: TwilioVoiceSmokeCheck[];
146
- generatedAt: number;
147
- pass: boolean;
148
- provider: 'twilio';
127
+ export type TwilioVoiceSmokeCheck = VoiceTelephonySmokeCheck;
128
+ export type TwilioVoiceSmokeReport = VoiceTelephonySmokeReport<'twilio'> & {
149
129
  setup: TwilioVoiceSetupStatus;
150
- twiml?: {
151
- status: number;
152
- streamUrl?: string;
153
- };
154
- webhook?: {
155
- body?: unknown;
156
- status: number;
157
- };
158
130
  };
159
131
  export type TwilioVoiceSmokeOptions = {
160
132
  callSid?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.76",
3
+ "version": "0.0.22-beta.78",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",