@absolutejs/voice 0.0.22-beta.272 → 0.0.22-beta.273

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
@@ -159,11 +159,13 @@ export type { VoiceS3ReviewStoreClient, VoiceS3ReviewStoreFile, VoiceS3ReviewSto
159
159
  export type { VoiceSQLiteRuntimeStorage, VoiceSQLiteStoreOptions } from './sqliteStore';
160
160
  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';
161
161
  export { createTwilioMediaStreamBridge, createTwilioVoiceRoutes, createTwilioVoiceResponse, decodeTwilioMulawBase64, encodeTwilioMulawBase64, transcodePCMToTwilioOutboundPayload, transcodeTwilioInboundPayloadToPCM16 } from './telephony/twilio';
162
+ export { createVoiceTelephonyWebhookSecurityPreset } from './telephony/security';
162
163
  export { evaluateVoiceTelephonyContract } from './telephony/contract';
163
164
  export { createMemoryVoiceTelnyxWebhookEventStore, createTelnyxMediaStreamBridge, createTelnyxVoiceResponse, createTelnyxVoiceRoutes, createVoicePostgresTelnyxWebhookEventStore, createVoiceRedisTelnyxWebhookEventStore, createVoiceSQLiteTelnyxWebhookEventStore, createVoiceTelnyxWebhookVerifier, verifyVoiceTelnyxWebhookSignature } from './telephony/telnyx';
164
165
  export { createMemoryVoicePlivoWebhookNonceStore, createPlivoMediaStreamBridge, createPlivoVoiceResponse, createPlivoVoiceRoutes, createVoicePostgresPlivoWebhookNonceStore, createVoicePlivoWebhookVerifier, createVoiceRedisPlivoWebhookNonceStore, createVoiceSQLitePlivoWebhookNonceStore, signVoicePlivoWebhook, verifyVoicePlivoWebhookSignature } from './telephony/plivo';
165
166
  export { createVoiceTelephonyCarrierMatrix, createVoiceTelephonyCarrierMatrixRoutes, renderVoiceTelephonyCarrierMatrixHTML } from './telephony/matrix';
166
167
  export type { TwilioInboundMessage, TwilioMediaStreamBridge, TwilioMediaStreamBridgeOptions, TwilioMediaStreamSocket, TwilioOutboundClearMessage, TwilioOutboundMarkMessage, TwilioOutboundMediaMessage, TwilioOutboundMessage, TwilioVoiceRouteParameters, TwilioVoiceResponseOptions, TwilioVoiceSmokeCheck, TwilioVoiceSmokeOptions, TwilioVoiceSmokeReport, TwilioVoiceSetupOptions, TwilioVoiceSetupStatus, TwilioVoiceRoutesOptions } from './telephony/twilio';
168
+ export type { VoiceTelephonyWebhookSecurityOptions, VoiceTelephonyWebhookSecurityPreset, VoiceTelephonyWebhookSecurityStorePreset } from './telephony/security';
167
169
  export type { VoiceTelephonyContractIssue, VoiceTelephonyContractOptions, VoiceTelephonyContractReport, VoiceTelephonyContractRequirement, VoiceTelephonyProvider, VoiceTelephonySetupStatus, VoiceTelephonySmokeCheck, VoiceTelephonySmokeReport } from './telephony/contract';
168
170
  export type { TelnyxInboundMessage, TelnyxMediaPayload, TelnyxMediaStreamBridge, TelnyxMediaStreamBridgeOptions, TelnyxMediaStreamSocket, TelnyxOutboundClearMessage, TelnyxOutboundMarkMessage, TelnyxOutboundMediaMessage, TelnyxOutboundMessage, TelnyxVoiceResponseOptions, TelnyxVoiceRoutesOptions, TelnyxVoiceSetupOptions, TelnyxVoiceSetupStatus, TelnyxVoiceSmokeCheck, TelnyxVoiceSmokeOptions, TelnyxVoiceSmokeReport, VoicePostgresTelnyxWebhookEventStoreOptions, VoiceRedisTelnyxWebhookEventClient, VoiceRedisTelnyxWebhookEventStoreOptions, VoiceSQLiteTelnyxWebhookEventStoreOptions, VoiceTelnyxWebhookEventStore, VoiceTelnyxWebhookEventStoreOptions, VoiceTelnyxWebhookVerifierOptions } from './telephony/telnyx';
169
171
  export type { PlivoInboundMessage, PlivoMediaStreamBridge, PlivoMediaStreamBridgeOptions, PlivoMediaStreamSocket, PlivoOutboundCheckpointMessage, PlivoOutboundClearAudioMessage, PlivoOutboundMessage, PlivoOutboundPlayAudioMessage, PlivoVoiceResponseOptions, PlivoVoiceRoutesOptions, PlivoVoiceSetupOptions, PlivoVoiceSetupStatus, PlivoVoiceSmokeCheck, PlivoVoiceSmokeOptions, PlivoVoiceSmokeReport, VoicePostgresPlivoWebhookNonceStoreOptions, VoicePlivoWebhookNonceStore, VoicePlivoWebhookNonceStoreOptions, VoicePlivoWebhookVerifierOptions, VoiceRedisPlivoWebhookNonceClient, VoiceRedisPlivoWebhookNonceStoreOptions, VoiceSQLitePlivoWebhookNonceStoreOptions } from './telephony/plivo';
package/dist/index.js CHANGED
@@ -31664,6 +31664,139 @@ var createVoiceSTTRoutingCorrectionHandler = (mode = "generic") => {
31664
31664
  }
31665
31665
  return createPhraseHintCorrectionHandler();
31666
31666
  };
31667
+ // src/telephony/security.ts
31668
+ var resolveVerificationUrl2 = (option, input) => typeof option === "function" ? option(input) : option ?? input.request.url;
31669
+ var createStores = (options) => {
31670
+ const ttlSeconds = options.ttlSeconds;
31671
+ const store = options.store ?? { kind: "memory" };
31672
+ if (store.kind === "sqlite") {
31673
+ return {
31674
+ idempotency: options.twilio?.idempotencyStore ?? createVoiceSQLiteTelephonyWebhookIdempotencyStore({
31675
+ path: store.path,
31676
+ tableName: "voice_twilio_webhook_idempotency",
31677
+ tablePrefix: store.tablePrefix
31678
+ }),
31679
+ plivo: options.plivo?.nonceStore ?? createVoiceSQLitePlivoWebhookNonceStore({
31680
+ path: store.path,
31681
+ tableName: "voice_plivo_webhook_nonces",
31682
+ tablePrefix: store.tablePrefix,
31683
+ ttlSeconds
31684
+ }),
31685
+ telnyx: options.telnyx?.eventStore ?? createVoiceSQLiteTelnyxWebhookEventStore({
31686
+ path: store.path,
31687
+ tableName: "voice_telnyx_webhook_events",
31688
+ tablePrefix: store.tablePrefix,
31689
+ ttlSeconds
31690
+ })
31691
+ };
31692
+ }
31693
+ if (store.kind === "postgres") {
31694
+ return {
31695
+ idempotency: options.twilio?.idempotencyStore ?? createVoicePostgresTelephonyWebhookIdempotencyStore({
31696
+ connectionString: store.connectionString,
31697
+ schemaName: store.schemaName,
31698
+ sql: store.sql,
31699
+ tableName: "voice_twilio_webhook_idempotency",
31700
+ tablePrefix: store.tablePrefix
31701
+ }),
31702
+ plivo: options.plivo?.nonceStore ?? createVoicePostgresPlivoWebhookNonceStore({
31703
+ connectionString: store.connectionString,
31704
+ schemaName: store.schemaName,
31705
+ sql: store.sql,
31706
+ tableName: "voice_plivo_webhook_nonces",
31707
+ tablePrefix: store.tablePrefix,
31708
+ ttlSeconds
31709
+ }),
31710
+ telnyx: options.telnyx?.eventStore ?? createVoicePostgresTelnyxWebhookEventStore({
31711
+ connectionString: store.connectionString,
31712
+ schemaName: store.schemaName,
31713
+ sql: store.sql,
31714
+ tableName: "voice_telnyx_webhook_events",
31715
+ tablePrefix: store.tablePrefix,
31716
+ ttlSeconds
31717
+ })
31718
+ };
31719
+ }
31720
+ if (store.kind === "redis") {
31721
+ const keyPrefix = store.keyPrefix?.trim() || "voice:webhook-security";
31722
+ return {
31723
+ idempotency: options.twilio?.idempotencyStore ?? createVoiceRedisTelephonyWebhookIdempotencyStore({
31724
+ client: store.idempotencyClient,
31725
+ keyPrefix: `${keyPrefix}:twilio:idempotency`,
31726
+ ttlSeconds,
31727
+ url: store.url
31728
+ }),
31729
+ plivo: options.plivo?.nonceStore ?? createVoiceRedisPlivoWebhookNonceStore({
31730
+ client: store.plivoClient,
31731
+ keyPrefix: `${keyPrefix}:plivo:nonce`,
31732
+ ttlSeconds,
31733
+ url: store.url
31734
+ }),
31735
+ telnyx: options.telnyx?.eventStore ?? createVoiceRedisTelnyxWebhookEventStore({
31736
+ client: store.telnyxClient,
31737
+ keyPrefix: `${keyPrefix}:telnyx:event`,
31738
+ ttlSeconds,
31739
+ url: store.url
31740
+ })
31741
+ };
31742
+ }
31743
+ return {
31744
+ idempotency: options.twilio?.idempotencyStore ?? createMemoryVoiceTelephonyWebhookIdempotencyStore(),
31745
+ plivo: options.plivo?.nonceStore ?? createMemoryVoicePlivoWebhookNonceStore(),
31746
+ telnyx: options.telnyx?.eventStore ?? createMemoryVoiceTelnyxWebhookEventStore()
31747
+ };
31748
+ };
31749
+ var createVoiceTelephonyWebhookSecurityPreset = (options = {}) => {
31750
+ const stores = createStores(options);
31751
+ const twilioVerificationUrl = options.twilio?.verificationUrl;
31752
+ const plivoVerify = createVoicePlivoWebhookVerifier({
31753
+ authToken: options.plivo?.authToken,
31754
+ nonceStore: stores.plivo,
31755
+ verificationUrl: options.plivo?.verificationUrl
31756
+ });
31757
+ const telnyxVerify = createVoiceTelnyxWebhookVerifier({
31758
+ eventStore: stores.telnyx,
31759
+ publicKey: options.telnyx?.publicKey,
31760
+ toleranceSeconds: options.telnyx?.toleranceSeconds
31761
+ });
31762
+ const twilioVerify = async (input) => verifyVoiceTwilioWebhookSignature({
31763
+ authToken: options.twilio?.authToken,
31764
+ body: input.body,
31765
+ headers: input.headers,
31766
+ url: resolveVerificationUrl2(twilioVerificationUrl, {
31767
+ query: input.query,
31768
+ request: input.request
31769
+ })
31770
+ });
31771
+ return {
31772
+ plivo: {
31773
+ authToken: options.plivo?.authToken,
31774
+ nonceStore: stores.plivo,
31775
+ verify: plivoVerify
31776
+ },
31777
+ telnyx: {
31778
+ eventStore: stores.telnyx,
31779
+ publicKey: options.telnyx?.publicKey,
31780
+ toleranceSeconds: options.telnyx?.toleranceSeconds,
31781
+ verify: telnyxVerify
31782
+ },
31783
+ twilio: {
31784
+ idempotency: {
31785
+ enabled: true,
31786
+ store: stores.idempotency
31787
+ },
31788
+ requireVerification: true,
31789
+ signingSecret: options.twilio?.authToken,
31790
+ verificationUrl: twilioVerificationUrl,
31791
+ verify: twilioVerify
31792
+ },
31793
+ verify: {
31794
+ plivo: plivoVerify,
31795
+ telnyx: telnyxVerify,
31796
+ twilio: twilioVerify
31797
+ }
31798
+ };
31799
+ };
31667
31800
  // src/telephony/response.ts
31668
31801
  var normalizeWhitespace = (value) => value.replace(/\s+/g, " ").trim();
31669
31802
  var DEFAULT_MAX_WORDS = 12;
@@ -31974,6 +32107,7 @@ export {
31974
32107
  createVoiceToolContract,
31975
32108
  createVoiceTelnyxWebhookVerifier,
31976
32109
  createVoiceTelnyxCampaignDialer,
32110
+ createVoiceTelephonyWebhookSecurityPreset,
31977
32111
  createVoiceTelephonyWebhookRoutes,
31978
32112
  createVoiceTelephonyWebhookHandler,
31979
32113
  createVoiceTelephonyOutcomePolicy,
@@ -0,0 +1,95 @@
1
+ import { type VoiceTelephonyWebhookIdempotencyStore, type VoiceTelephonyWebhookVerificationResult } from '../telephonyOutcome';
2
+ import { type VoicePostgresClient } from '../postgresStore';
3
+ import { type VoiceRedisTelephonyWebhookIdempotencyClient } from '../queue';
4
+ import { type VoicePlivoWebhookNonceStore, type VoiceRedisPlivoWebhookNonceClient } from './plivo';
5
+ import { type VoiceRedisTelnyxWebhookEventClient, type VoiceTelnyxWebhookEventStore } from './telnyx';
6
+ export type VoiceTelephonyWebhookSecurityStorePreset = {
7
+ kind?: 'memory';
8
+ } | {
9
+ kind: 'sqlite';
10
+ path: string;
11
+ tablePrefix?: string;
12
+ } | {
13
+ connectionString?: string;
14
+ kind: 'postgres';
15
+ schemaName?: string;
16
+ sql?: VoicePostgresClient;
17
+ tablePrefix?: string;
18
+ } | {
19
+ idempotencyClient?: VoiceRedisTelephonyWebhookIdempotencyClient;
20
+ keyPrefix?: string;
21
+ kind: 'redis';
22
+ plivoClient?: VoiceRedisPlivoWebhookNonceClient;
23
+ telnyxClient?: VoiceRedisTelnyxWebhookEventClient;
24
+ url?: string;
25
+ };
26
+ export type VoiceTelephonyWebhookSecurityOptions<TResult = unknown> = {
27
+ plivo?: {
28
+ authToken?: string;
29
+ nonceStore?: VoicePlivoWebhookNonceStore;
30
+ verificationUrl?: string | ((input: {
31
+ query: Record<string, unknown>;
32
+ request: Request;
33
+ }) => string);
34
+ };
35
+ store?: VoiceTelephonyWebhookSecurityStorePreset;
36
+ telnyx?: {
37
+ eventStore?: VoiceTelnyxWebhookEventStore;
38
+ publicKey?: string;
39
+ toleranceSeconds?: number;
40
+ };
41
+ ttlSeconds?: number;
42
+ twilio?: {
43
+ authToken?: string;
44
+ idempotencyStore?: VoiceTelephonyWebhookIdempotencyStore<TResult>;
45
+ verificationUrl?: string | ((input: {
46
+ query: Record<string, unknown>;
47
+ request: Request;
48
+ }) => string);
49
+ };
50
+ };
51
+ export type VoiceTelephonyWebhookSecurityPreset<TResult = unknown> = {
52
+ plivo: {
53
+ authToken?: string;
54
+ nonceStore: VoicePlivoWebhookNonceStore;
55
+ verify: (input: {
56
+ body: unknown;
57
+ headers: Headers;
58
+ query: Record<string, unknown>;
59
+ request: Request;
60
+ }) => Promise<VoiceTelephonyWebhookVerificationResult>;
61
+ };
62
+ telnyx: {
63
+ eventStore: VoiceTelnyxWebhookEventStore;
64
+ publicKey?: string;
65
+ toleranceSeconds?: number;
66
+ verify: (input: {
67
+ headers: Headers;
68
+ rawBody: string;
69
+ }) => Promise<VoiceTelephonyWebhookVerificationResult>;
70
+ };
71
+ twilio: {
72
+ idempotency: {
73
+ enabled: true;
74
+ store: VoiceTelephonyWebhookIdempotencyStore<TResult>;
75
+ };
76
+ requireVerification: true;
77
+ signingSecret?: string;
78
+ verificationUrl?: string | ((input: {
79
+ query: Record<string, unknown>;
80
+ request: Request;
81
+ }) => string);
82
+ verify: (input: {
83
+ body: unknown;
84
+ headers: Headers;
85
+ query: Record<string, unknown>;
86
+ request: Request;
87
+ }) => Promise<VoiceTelephonyWebhookVerificationResult>;
88
+ };
89
+ verify: {
90
+ plivo: VoiceTelephonyWebhookSecurityPreset<TResult>['plivo']['verify'];
91
+ telnyx: VoiceTelephonyWebhookSecurityPreset<TResult>['telnyx']['verify'];
92
+ twilio: VoiceTelephonyWebhookSecurityPreset<TResult>['twilio']['verify'];
93
+ };
94
+ };
95
+ export declare const createVoiceTelephonyWebhookSecurityPreset: <TResult = unknown>(options?: VoiceTelephonyWebhookSecurityOptions<TResult>) => VoiceTelephonyWebhookSecurityPreset<TResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.272",
3
+ "version": "0.0.22-beta.273",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",