@fonoster/apiserver 0.27.0 → 0.31.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.
Files changed (376) hide show
  1. package/dist/applications/buildService.d.ts +5 -1
  2. package/dist/applications/buildService.js +10 -7
  3. package/dist/applications/createCreateApplication.d.ts +6 -2
  4. package/dist/applications/createCreateApplication.js +24 -16
  5. package/dist/applications/createCreateTestToken.d.ts +3 -1
  6. package/dist/applications/createCreateTestToken.js +18 -13
  7. package/dist/applications/createGetApplication.js +2 -2
  8. package/dist/applications/createGetFnUtil.d.ts +22 -18
  9. package/dist/applications/createGetFnUtil.js +3 -5
  10. package/dist/applications/createListApplications.js +3 -4
  11. package/dist/applications/createRotateSigningSecret.d.ts +9 -0
  12. package/dist/{calls/createFetchSingleCall.js → applications/createRotateSigningSecret.js} +23 -20
  13. package/dist/applications/createUpdateApplication.d.ts +6 -2
  14. package/dist/applications/createUpdateApplication.js +35 -36
  15. package/dist/applications/evalKeys.d.ts +9 -0
  16. package/dist/{voice/handlers/dial/recordChannel.js → applications/evalKeys.js} +17 -12
  17. package/dist/applications/session/appModel.d.ts +225 -0
  18. package/dist/applications/session/appModel.js +331 -0
  19. package/dist/applications/types.d.ts +1 -27
  20. package/dist/billing/buildService.d.ts +24 -0
  21. package/dist/billing/buildService.js +116 -0
  22. package/dist/bin/entrypoint.d.ts +1 -0
  23. package/dist/bin/entrypoint.js +180 -0
  24. package/dist/bin/healthcheck.d.ts +2 -0
  25. package/dist/{voice/utils/VoiceServiceClientConstructor.js → bin/healthcheck.js} +24 -9
  26. package/dist/bin/regionHubSetup.d.ts +2 -0
  27. package/dist/bin/regionHubSetup.js +67 -0
  28. package/dist/bin/usage.d.ts +2 -0
  29. package/dist/bin/usage.js +119 -0
  30. package/dist/calls/buildService.d.ts +1 -20
  31. package/dist/calls/buildService.js +59 -6
  32. package/dist/calls/createCall.d.ts +17 -2
  33. package/dist/calls/createCall.js +64 -11
  34. package/dist/calls/createCallPublisher.d.ts +40 -2
  35. package/dist/calls/createCallPublisher.js +43 -9
  36. package/dist/calls/createIsWorkspaceNumber.d.ts +41 -0
  37. package/dist/calls/createIsWorkspaceNumber.js +39 -0
  38. package/dist/calls/createTrackCall.d.ts +55 -2
  39. package/dist/calls/createTrackCall.js +230 -16
  40. package/dist/calls/getCall.d.ts +4 -2
  41. package/dist/calls/getCall.js +2 -3
  42. package/dist/calls/listCalls.d.ts +4 -2
  43. package/dist/calls/listCalls.js +2 -3
  44. package/dist/calls/types.d.ts +11 -2
  45. package/dist/calls/types.js +10 -0
  46. package/dist/{core/buildWelcomeDemoService.d.ts → capabilities/buildService.d.ts} +8 -8
  47. package/dist/capabilities/buildService.js +17 -0
  48. package/dist/capabilities/createGetCapabilities.d.ts +78 -0
  49. package/dist/capabilities/createGetCapabilities.js +98 -0
  50. package/dist/{voice/handlers/utils → capabilities}/index.d.ts +2 -3
  51. package/dist/{voice/handlers/utils → capabilities}/index.js +4 -3
  52. package/dist/config/index.d.ts +23 -0
  53. package/dist/config/index.js +102 -0
  54. package/dist/config/schema.d.ts +1919 -0
  55. package/dist/config/schema.js +357 -0
  56. package/dist/core/allowList.js +2 -1
  57. package/dist/core/applyCatalog.d.ts +10 -0
  58. package/dist/{voice/client/GrpcClientHandler.js → core/applyCatalog.js} +45 -51
  59. package/dist/core/db.d.ts +3 -1
  60. package/dist/core/db.js +2 -1
  61. package/dist/core/durableConsumer.d.ts +41 -0
  62. package/dist/core/durableConsumer.js +104 -0
  63. package/dist/core/httpBridge.d.ts +24 -6
  64. package/dist/core/httpBridge.js +3 -25
  65. package/dist/core/identityConfig.d.ts +2 -35
  66. package/dist/core/identityConfig.js +3 -36
  67. package/dist/core/regionHooks.d.ts +15 -0
  68. package/dist/{calls/influxdb.js → core/regionHooks.js} +4 -8
  69. package/dist/core/runServices.js +98 -15
  70. package/dist/core/services.d.ts +96 -6
  71. package/dist/core/services.js +49 -10
  72. package/dist/{voice/errors/index.d.ts → core/telemetry.d.ts} +2 -2
  73. package/dist/core/telemetry.js +42 -0
  74. package/dist/{applications/utils/convertToApplicationData.d.ts → core/telemetryInterceptor.d.ts} +10 -4
  75. package/dist/core/telemetryInterceptor.js +57 -0
  76. package/dist/core/testTokenConfig.js +4 -1
  77. package/dist/core/upsertRoomrPeer.d.ts +6 -0
  78. package/dist/core/{upsertDefaultPeer.js → upsertRoomrPeer.js} +31 -30
  79. package/dist/envs.d.ts +136 -23
  80. package/dist/envs.js +108 -143
  81. package/dist/index.js +39 -21
  82. package/dist/outbound/createNodeDirectory.d.ts +86 -0
  83. package/dist/outbound/createNodeDirectory.js +140 -0
  84. package/dist/{voice/integrations → outbound}/index.d.ts +4 -1
  85. package/dist/{voice/errors → outbound}/index.js +4 -2
  86. package/dist/outbound/placeOutboundCall.d.ts +96 -0
  87. package/dist/outbound/placeOutboundCall.js +172 -0
  88. package/dist/outbound/placementSweep.d.ts +56 -0
  89. package/dist/outbound/placementSweep.js +127 -0
  90. package/dist/outbound/runOutboundCalls.d.ts +52 -0
  91. package/dist/outbound/runOutboundCalls.js +171 -0
  92. package/dist/providers/createProvidersHandlers.d.ts +39 -0
  93. package/dist/providers/createProvidersHandlers.js +229 -0
  94. package/dist/providers/index.d.ts +47 -0
  95. package/dist/{voice/client → providers}/index.js +15 -6
  96. package/dist/providers/registryUsage.d.ts +48 -0
  97. package/dist/providers/registryUsage.js +236 -0
  98. package/dist/records/createIndexRecord.d.ts +42 -0
  99. package/dist/records/createIndexRecord.js +185 -0
  100. package/dist/records/createRecordsRouter.d.ts +61 -0
  101. package/dist/records/createRecordsRouter.js +330 -0
  102. package/dist/records/createSearchRecords.d.ts +51 -0
  103. package/dist/records/createSearchRecords.js +134 -0
  104. package/dist/{voice/filters → records}/index.d.ts +6 -6
  105. package/dist/{voice/filters → records}/index.js +6 -6
  106. package/dist/records/maintenance.d.ts +33 -0
  107. package/dist/records/maintenance.js +166 -0
  108. package/dist/records/runCallRecords.d.ts +48 -0
  109. package/dist/records/runCallRecords.js +49 -0
  110. package/dist/{events/createPerCallCache.d.ts → records/stores.d.ts} +4 -7
  111. package/dist/{voice/handlers/utils/isDtmf.js → records/stores.js} +9 -3
  112. package/dist/records/types.d.ts +104 -0
  113. package/dist/regions/configSync.d.ts +130 -0
  114. package/dist/regions/configSync.js +316 -0
  115. package/dist/regions/createRegionsRouter.d.ts +151 -0
  116. package/dist/regions/createRegionsRouter.js +391 -0
  117. package/dist/regions/endpoints.d.ts +41 -0
  118. package/dist/regions/endpoints.js +90 -0
  119. package/dist/regions/enrollmentToken.d.ts +41 -0
  120. package/dist/regions/enrollmentToken.js +94 -0
  121. package/dist/regions/httpAuth.d.ts +39 -0
  122. package/dist/regions/httpAuth.js +78 -0
  123. package/dist/regions/ids.d.ts +15 -0
  124. package/dist/regions/ids.js +81 -0
  125. package/dist/{voice/client → regions}/index.d.ts +17 -6
  126. package/dist/regions/index.js +51 -0
  127. package/dist/regions/link.d.ts +17 -0
  128. package/dist/regions/link.js +170 -0
  129. package/dist/regions/natsAuth.d.ts +41 -0
  130. package/dist/regions/natsAuth.js +64 -0
  131. package/dist/regions/natsJwt.d.ts +23 -0
  132. package/dist/regions/natsJwt.js +26 -0
  133. package/dist/regions/relay.d.ts +45 -0
  134. package/dist/regions/relay.js +203 -0
  135. package/dist/regions/relayHttp.d.ts +7 -0
  136. package/dist/regions/relayHttp.js +107 -0
  137. package/dist/regions/relaySlots.d.ts +18 -0
  138. package/dist/regions/relaySlots.js +118 -0
  139. package/dist/regions/runRegions.d.ts +111 -0
  140. package/dist/regions/runRegions.js +235 -0
  141. package/dist/regions/service.d.ts +129 -0
  142. package/dist/regions/service.js +558 -0
  143. package/dist/regions/sources.d.ts +20 -0
  144. package/dist/regions/sources.js +191 -0
  145. package/dist/regions/status.d.ts +35 -0
  146. package/dist/regions/status.js +63 -0
  147. package/dist/regions/types.d.ts +123 -0
  148. package/dist/regions/types.js +41 -0
  149. package/dist/{voice/integrations/getSttConfig.d.ts → regions/withConfigChangeHook.d.ts} +13 -7
  150. package/dist/regions/withConfigChangeHook.js +44 -0
  151. package/dist/secrets/createGetFnUtil.d.ts +2 -2
  152. package/dist/session/createSessionRouter.d.ts +49 -0
  153. package/dist/session/createSessionRouter.js +206 -0
  154. package/dist/{voice/handlers/dial → session}/index.d.ts +1 -1
  155. package/dist/{voice/handlers/dial → session}/index.js +1 -1
  156. package/dist/usage/buildService.d.ts +16 -0
  157. package/dist/{voice/integrations/getTtsConfig.js → usage/buildService.js} +13 -7
  158. package/dist/{voice/tts/utils/convertUlawToPCM16.d.ts → usage/createGetUsage.d.ts} +7 -6
  159. package/dist/usage/createGetUsage.js +118 -0
  160. package/dist/usage/ingestUsage.d.ts +7 -0
  161. package/dist/usage/ingestUsage.js +87 -0
  162. package/dist/usage/publishRecordedUsage.d.ts +52 -0
  163. package/dist/usage/publishRecordedUsage.js +103 -0
  164. package/dist/{utils/createHandleDialEventsWithNats.d.ts → usage/publishUsage.d.ts} +10 -4
  165. package/dist/usage/publishUsage.js +50 -0
  166. package/dist/usage/rebuildUsage.d.ts +48 -0
  167. package/dist/usage/rebuildUsage.js +104 -0
  168. package/dist/usage/runUsageConsumer.d.ts +22 -0
  169. package/dist/usage/runUsageConsumer.js +78 -0
  170. package/dist/usage/snapshotStorage.d.ts +14 -0
  171. package/dist/usage/snapshotStorage.js +95 -0
  172. package/dist/{voice/integrations/getTtsConfig.d.ts → usage/types.d.ts} +17 -6
  173. package/dist/utils/createCheckNumberPreconditions.js +4 -0
  174. package/dist/utils/index.d.ts +0 -2
  175. package/dist/utils/index.js +0 -2
  176. package/dist/voice/stt/Deepgram.d.ts +4 -57
  177. package/dist/voice/stt/Deepgram.js +15 -286
  178. package/dist/voice/stt/Google.d.ts +4 -15
  179. package/dist/voice/stt/Google.js +7 -103
  180. package/dist/voice/stt/types.d.ts +2 -38
  181. package/dist/voice/stt/types.js +25 -3
  182. package/dist/voice/tts/Azure.d.ts +4 -34
  183. package/dist/voice/tts/Azure.js +25 -105
  184. package/dist/voice/tts/Deepgram.d.ts +4 -38
  185. package/dist/voice/tts/Deepgram.js +25 -82
  186. package/dist/voice/tts/ElevenLabs.d.ts +4 -18
  187. package/dist/voice/tts/ElevenLabs.js +6 -97
  188. package/dist/voice/tts/Google.d.ts +4 -38
  189. package/dist/voice/tts/Google.js +25 -91
  190. package/dist/webhooks/createWebhooksHandlers.d.ts +37 -0
  191. package/dist/webhooks/createWebhooksHandlers.js +217 -0
  192. package/dist/webhooks/index.d.ts +37 -0
  193. package/dist/webhooks/index.js +51 -0
  194. package/dist/webhooks/lostCalls.d.ts +49 -0
  195. package/dist/webhooks/lostCalls.js +147 -0
  196. package/dist/webhooks/nodeCallEvents.d.ts +73 -0
  197. package/dist/webhooks/nodeCallEvents.js +177 -0
  198. package/dist/webhooks/runWebhookFanout.d.ts +44 -0
  199. package/dist/webhooks/runWebhookFanout.js +202 -0
  200. package/package.json +21 -31
  201. package/dist/applications/utils/applicationWithEncodedStruct.d.ts +0 -3
  202. package/dist/applications/utils/applicationWithEncodedStruct.js +0 -50
  203. package/dist/applications/utils/convertToApplicationData.js +0 -37
  204. package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +0 -786
  205. package/dist/applications/validation/assistantWithoutApiKeySchema.js +0 -35
  206. package/dist/applications/validation/createValidationSchema.d.ts +0 -1474
  207. package/dist/applications/validation/createValidationSchema.js +0 -67
  208. package/dist/applications/validation/prepareForValidation.d.ts +0 -21
  209. package/dist/applications/validation/prepareForValidation.js +0 -35
  210. package/dist/applications/validation/speechValidators.d.ts +0 -47
  211. package/dist/applications/validation/speechValidators.js +0 -50
  212. package/dist/applications/validation/validOrThrow.d.ts +0 -21
  213. package/dist/applications/validation/validOrThrow.js +0 -15
  214. package/dist/calls/createFetchCalls.d.ts +0 -22
  215. package/dist/calls/createFetchCalls.js +0 -88
  216. package/dist/calls/createFetchSingleCall.d.ts +0 -22
  217. package/dist/calls/influxdb.d.ts +0 -2
  218. package/dist/calls/runCallManager.d.ts +0 -8
  219. package/dist/calls/runCallManager.js +0 -75
  220. package/dist/core/buildWelcomeDemoService.js +0 -97
  221. package/dist/core/upsertDefaultPeer.d.ts +0 -2
  222. package/dist/events/amdResultCache.d.ts +0 -23
  223. package/dist/events/amdResultCache.js +0 -35
  224. package/dist/events/createInfluxDbPub.d.ts +0 -13
  225. package/dist/events/createInfluxDbPub.js +0 -89
  226. package/dist/events/createPerCallCache.js +0 -46
  227. package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
  228. package/dist/events/mapCallDirectionToEnum.js +0 -37
  229. package/dist/events/nats.d.ts +0 -10
  230. package/dist/events/nats.js +0 -82
  231. package/dist/events/transformEvent.d.ts +0 -2
  232. package/dist/events/transformEvent.js +0 -87
  233. package/dist/events/types.d.ts +0 -26
  234. package/dist/utils/createHandleDialEventsWithNats.js +0 -24
  235. package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +0 -23
  236. package/dist/utils/createHandleDialEventsWithVoiceClient.js +0 -27
  237. package/dist/utils/getIntegrationsFromFile.d.ts +0 -2
  238. package/dist/utils/getIntegrationsFromFile.js +0 -49
  239. package/dist/utils/mapDialStatus.d.ts +0 -21
  240. package/dist/utils/mapDialStatus.js +0 -38
  241. package/dist/voice/VoiceDispatcher.d.ts +0 -21
  242. package/dist/voice/VoiceDispatcher.js +0 -122
  243. package/dist/voice/amd/mapAsteriskAmd.d.ts +0 -38
  244. package/dist/voice/amd/mapAsteriskAmd.js +0 -68
  245. package/dist/voice/client/AudioSocketHandler.d.ts +0 -38
  246. package/dist/voice/client/AudioSocketHandler.js +0 -70
  247. package/dist/voice/client/AuthorizationHandler.d.ts +0 -13
  248. package/dist/voice/client/AuthorizationHandler.js +0 -78
  249. package/dist/voice/client/ExternalMediaHandler.d.ts +0 -32
  250. package/dist/voice/client/ExternalMediaHandler.js +0 -59
  251. package/dist/voice/client/GrpcClientHandler.d.ts +0 -36
  252. package/dist/voice/client/SpeechHandler.d.ts +0 -60
  253. package/dist/voice/client/SpeechHandler.js +0 -120
  254. package/dist/voice/client/VoiceClientImpl.d.ts +0 -79
  255. package/dist/voice/client/VoiceClientImpl.js +0 -198
  256. package/dist/voice/connectToAri.d.ts +0 -2
  257. package/dist/voice/connectToAri.js +0 -81
  258. package/dist/voice/createCreateVoiceClient.d.ts +0 -9
  259. package/dist/voice/createCreateVoiceClient.js +0 -97
  260. package/dist/voice/errors/ChannelVarNotFoundError.d.ts +0 -23
  261. package/dist/voice/errors/ChannelVarNotFoundError.js +0 -10
  262. package/dist/voice/errors/MethodNotImplementedError.d.ts +0 -22
  263. package/dist/voice/errors/MethodNotImplementedError.js +0 -27
  264. package/dist/voice/filters/AudioFilterFactory.d.ts +0 -35
  265. package/dist/voice/filters/AudioFilterFactory.js +0 -94
  266. package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +0 -64
  267. package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +0 -252
  268. package/dist/voice/filters/aiCoustics/types.d.ts +0 -45
  269. package/dist/voice/filters/aiCoustics/types.js +0 -29
  270. package/dist/voice/filters/createAudioFilterChain.d.ts +0 -9
  271. package/dist/voice/filters/createAudioFilterChain.js +0 -171
  272. package/dist/voice/filters/createAudioFilterSession.d.ts +0 -15
  273. package/dist/voice/filters/createAudioFilterSession.js +0 -114
  274. package/dist/voice/filters/pcm.d.ts +0 -21
  275. package/dist/voice/filters/pcm.js +0 -37
  276. package/dist/voice/filters/types.d.ts +0 -61
  277. package/dist/voice/filters/types.js +0 -26
  278. package/dist/voice/handlers/createAnswerHandler.d.ts +0 -23
  279. package/dist/voice/handlers/createAnswerHandler.js +0 -24
  280. package/dist/voice/handlers/createHangupHandler.d.ts +0 -23
  281. package/dist/voice/handlers/createHangupHandler.js +0 -28
  282. package/dist/voice/handlers/createMuteHandler.d.ts +0 -4
  283. package/dist/voice/handlers/createMuteHandler.js +0 -27
  284. package/dist/voice/handlers/createPlayDtmfHandler.d.ts +0 -4
  285. package/dist/voice/handlers/createPlayDtmfHandler.js +0 -27
  286. package/dist/voice/handlers/createPlayHandler.d.ts +0 -4
  287. package/dist/voice/handlers/createPlayHandler.js +0 -33
  288. package/dist/voice/handlers/createPlaybackControlHandler.d.ts +0 -4
  289. package/dist/voice/handlers/createPlaybackControlHandler.js +0 -62
  290. package/dist/voice/handlers/createRecordHandler.d.ts +0 -4
  291. package/dist/voice/handlers/createRecordHandler.js +0 -58
  292. package/dist/voice/handlers/createSayHandler.d.ts +0 -4
  293. package/dist/voice/handlers/createSayHandler.js +0 -31
  294. package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +0 -11
  295. package/dist/voice/handlers/createSetAudioFiltersHandler.js +0 -74
  296. package/dist/voice/handlers/createStopSayHandler.d.ts +0 -3
  297. package/dist/voice/handlers/createStopSayHandler.js +0 -34
  298. package/dist/voice/handlers/createStreamGatherHandler.d.ts +0 -3
  299. package/dist/voice/handlers/createStreamGatherHandler.js +0 -74
  300. package/dist/voice/handlers/createStreamHandler.d.ts +0 -3
  301. package/dist/voice/handlers/createStreamHandler.js +0 -70
  302. package/dist/voice/handlers/createUnmuteHandler.d.ts +0 -4
  303. package/dist/voice/handlers/createUnmuteHandler.js +0 -27
  304. package/dist/voice/handlers/dial/createDialHandler.d.ts +0 -23
  305. package/dist/voice/handlers/dial/createDialHandler.js +0 -78
  306. package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +0 -24
  307. package/dist/voice/handlers/dial/handleChannelLeftBridge.js +0 -29
  308. package/dist/voice/handlers/dial/handleStasisEnd.d.ts +0 -21
  309. package/dist/voice/handlers/dial/handleStasisEnd.js +0 -19
  310. package/dist/voice/handlers/dial/handleStasisStart.d.ts +0 -27
  311. package/dist/voice/handlers/dial/handleStasisStart.js +0 -52
  312. package/dist/voice/handlers/dial/recordChannel.d.ts +0 -22
  313. package/dist/voice/handlers/gather/createGatherHandler.d.ts +0 -3
  314. package/dist/voice/handlers/gather/createGatherHandler.js +0 -86
  315. package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +0 -26
  316. package/dist/voice/handlers/gather/getTimeoutPromise.js +0 -18
  317. package/dist/voice/handlers/index.d.ts +0 -33
  318. package/dist/voice/handlers/index.js +0 -49
  319. package/dist/voice/handlers/utils/awaitForPlaybackFinished.d.ts +0 -21
  320. package/dist/voice/handlers/utils/awaitForPlaybackFinished.js +0 -25
  321. package/dist/voice/handlers/utils/awaitForRecordingFinished.d.ts +0 -5
  322. package/dist/voice/handlers/utils/awaitForRecordingFinished.js +0 -53
  323. package/dist/voice/handlers/utils/isDtmf.d.ts +0 -20
  324. package/dist/voice/handlers/utils/textChunksByClause.d.ts +0 -2
  325. package/dist/voice/handlers/utils/textChunksByClause.js +0 -41
  326. package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.d.ts +0 -2
  327. package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.js +0 -34
  328. package/dist/voice/handlers/utils/withErrorHandling.d.ts +0 -22
  329. package/dist/voice/handlers/utils/withErrorHandling.js +0 -38
  330. package/dist/voice/integrations/ApplicationNotFoundError.d.ts +0 -22
  331. package/dist/voice/integrations/ApplicationNotFoundError.js +0 -28
  332. package/dist/voice/integrations/createCreateContainer.d.ts +0 -4
  333. package/dist/voice/integrations/createCreateContainer.js +0 -76
  334. package/dist/voice/integrations/getSttConfig.js +0 -30
  335. package/dist/voice/integrations/index.js +0 -35
  336. package/dist/voice/integrations/types.d.ts +0 -29
  337. package/dist/voice/stt/AbstractSpeechToText.d.ts +0 -33
  338. package/dist/voice/stt/AbstractSpeechToText.js +0 -19
  339. package/dist/voice/stt/SpeechToTextFactory.d.ts +0 -9
  340. package/dist/voice/stt/SpeechToTextFactory.js +0 -43
  341. package/dist/voice/transcribeOnConnection.d.ts +0 -35
  342. package/dist/voice/transcribeOnConnection.js +0 -91
  343. package/dist/voice/tts/AbstractTextToSpeech.d.ts +0 -40
  344. package/dist/voice/tts/AbstractTextToSpeech.js +0 -50
  345. package/dist/voice/tts/TextToSpeechFactory.d.ts +0 -8
  346. package/dist/voice/tts/TextToSpeechFactory.js +0 -47
  347. package/dist/voice/tts/types.d.ts +0 -48
  348. package/dist/voice/tts/types.js +0 -2
  349. package/dist/voice/tts/utils/convertUlawToPCM16.js +0 -40
  350. package/dist/voice/tts/utils/createChunkedSynthesisStream.d.ts +0 -28
  351. package/dist/voice/tts/utils/createChunkedSynthesisStream.js +0 -78
  352. package/dist/voice/tts/utils/createErrorStream.d.ts +0 -21
  353. package/dist/voice/tts/utils/createErrorStream.js +0 -28
  354. package/dist/voice/tts/utils/index.d.ts +0 -23
  355. package/dist/voice/tts/utils/index.js +0 -39
  356. package/dist/voice/tts/utils/isSsml.d.ts +0 -20
  357. package/dist/voice/tts/utils/isSsml.js +0 -25
  358. package/dist/voice/tts/utils/streamToBuffer.d.ts +0 -20
  359. package/dist/voice/tts/utils/streamToBuffer.js +0 -60
  360. package/dist/voice/types/ari.d.ts +0 -43
  361. package/dist/voice/types/ari.js +0 -48
  362. package/dist/voice/types/index.d.ts +0 -20
  363. package/dist/voice/types/index.js +0 -36
  364. package/dist/voice/types/voice.d.ts +0 -67
  365. package/dist/voice/types/voice.js +0 -2
  366. package/dist/voice/utils/VoiceServiceClientConstructor.d.ts +0 -3
  367. package/dist/voice/utils/createExternalMediaConfig.d.ts +0 -12
  368. package/dist/voice/utils/createExternalMediaConfig.js +0 -37
  369. package/dist/voice/utils/createGetChannelVar.d.ts +0 -22
  370. package/dist/voice/utils/createGetChannelVar.js +0 -27
  371. package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +0 -22
  372. package/dist/voice/utils/createGetChannelVarWithoutThrow.js +0 -26
  373. package/dist/voice/utils/index.d.ts +0 -22
  374. package/dist/voice/utils/index.js +0 -38
  375. /package/dist/{events → records}/types.js +0 -0
  376. /package/dist/{voice/integrations → usage}/types.js +0 -0
@@ -0,0 +1,217 @@
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.createWebhooksHandlers = createWebhooksHandlers;
13
+ /**
14
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const crypto_1 = require("crypto");
32
+ const common_1 = require("@fonoster/common");
33
+ const logger_1 = require("@fonoster/logger");
34
+ const ROTATION_WINDOW_MS = 24 * 3600 * 1000;
35
+ const INVALID_ARGUMENT = 3;
36
+ const NOT_FOUND = 5;
37
+ const invalid = (message) => ({ code: INVALID_ARGUMENT, message });
38
+ const notFound = (message) => ({ code: NOT_FOUND, message });
39
+ const seconds = (d) => (d ? Math.floor(d.getTime() / 1000) : 0);
40
+ const hint = (secret) => `…${secret.slice(-4)}`;
41
+ function toWebhook(row) {
42
+ return {
43
+ ref: row.ref,
44
+ url: row.url,
45
+ events: row.events,
46
+ secretHint: hint(row.secret),
47
+ previousSecretUntil: seconds(row.previousUntil),
48
+ createdAt: seconds(row.createdAt),
49
+ updatedAt: seconds(row.updatedAt)
50
+ };
51
+ }
52
+ function toDelivery(row) {
53
+ var _a;
54
+ return {
55
+ ref: row.ref,
56
+ webhookRef: row.endpointRef,
57
+ eventId: row.eventId,
58
+ eventType: row.eventType,
59
+ status: row.status,
60
+ attempts: row.attempts,
61
+ lastStatus: (_a = row.lastStatus) !== null && _a !== void 0 ? _a : 0,
62
+ lastAttemptAt: seconds(row.lastAttemptAt),
63
+ nextAttemptAt: row.status === "pending" ? seconds(row.nextAttemptAt) : 0,
64
+ createdAt: seconds(row.createdAt)
65
+ };
66
+ }
67
+ /** Checks the URL (HTTPS) and event types the same way the dispatcher does. */
68
+ function validated(input, config) {
69
+ var _a;
70
+ if (!input.url)
71
+ throw invalid("url is required");
72
+ if (!((_a = input.events) === null || _a === void 0 ? void 0 : _a.length))
73
+ throw invalid("events: choose at least one");
74
+ try {
75
+ const dispatcher = new common_1.Webhooks.WebhookDispatcher({
76
+ store: new common_1.Webhooks.MemoryWebhookStore(),
77
+ allowInsecureUrls: config.allowInsecureUrls,
78
+ allowedDestinations: config.allowedDestinations
79
+ });
80
+ return dispatcher.createEndpoint({
81
+ workspaceRef: "check",
82
+ url: input.url,
83
+ events: [...new Set(input.events)]
84
+ });
85
+ }
86
+ catch (e) {
87
+ throw invalid(e.message);
88
+ }
89
+ }
90
+ function createWebhooksHandlers(db, config = {}) {
91
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
92
+ const now = () => { var _a, _b; return (_b = (_a = config.now) === null || _a === void 0 ? void 0 : _a.call(config)) !== null && _b !== void 0 ? _b : Date.now(); };
93
+ const workspace = (call) => (0, common_1.getAccessKeyIdFromCall)(call);
94
+ const find = (ref, accessKeyId) => __awaiter(this, void 0, void 0, function* () {
95
+ if (!ref)
96
+ throw invalid("ref is required");
97
+ const row = yield db.webhookEndpoint.findFirst({
98
+ where: { ref, accessKeyId }
99
+ });
100
+ if (!row)
101
+ throw notFound(`webhook not found: ${ref}`);
102
+ return row;
103
+ });
104
+ const createWebhook = (call, callback) => __awaiter(this, void 0, void 0, function* () {
105
+ const accessKeyId = workspace(call);
106
+ const endpoint = validated(call.request, config);
107
+ yield db.webhookEndpoint.create({
108
+ data: {
109
+ ref: endpoint.id,
110
+ accessKeyId,
111
+ url: endpoint.url,
112
+ events: endpoint.events,
113
+ secret: endpoint.secret
114
+ }
115
+ });
116
+ logger.verbose("webhook created", { accessKeyId, ref: endpoint.id });
117
+ callback(null, { ref: endpoint.id, secret: endpoint.secret });
118
+ });
119
+ const listWebhooks = (call, callback) => __awaiter(this, void 0, void 0, function* () {
120
+ const accessKeyId = workspace(call);
121
+ const pageSize = Math.min(call.request.pageSize || 50, 200);
122
+ const pageToken = call.request.pageToken;
123
+ const rows = yield db.webhookEndpoint.findMany({
124
+ where: { accessKeyId },
125
+ orderBy: [{ createdAt: "desc" }, { ref: "asc" }],
126
+ take: pageSize,
127
+ skip: pageToken ? 1 : 0,
128
+ cursor: pageToken ? { ref: pageToken } : undefined
129
+ });
130
+ callback(null, {
131
+ items: rows.map(toWebhook),
132
+ nextPageToken: rows.length < pageSize ? "" : rows[rows.length - 1].ref
133
+ });
134
+ });
135
+ const getWebhook = (call, callback) => __awaiter(this, void 0, void 0, function* () {
136
+ callback(null, toWebhook(yield find(call.request.ref, workspace(call))));
137
+ });
138
+ const updateWebhook = (call, callback) => __awaiter(this, void 0, void 0, function* () {
139
+ var _a;
140
+ const accessKeyId = workspace(call);
141
+ const row = yield find(call.request.ref, accessKeyId);
142
+ const url = call.request.url || row.url;
143
+ const events = ((_a = call.request.events) === null || _a === void 0 ? void 0 : _a.length)
144
+ ? call.request.events
145
+ : row.events;
146
+ const checked = validated({ url, events }, config);
147
+ yield db.webhookEndpoint.update({
148
+ where: { ref: row.ref },
149
+ data: { url: checked.url, events: checked.events }
150
+ });
151
+ callback(null, { ref: row.ref });
152
+ });
153
+ const deleteWebhook = (call, callback) => __awaiter(this, void 0, void 0, function* () {
154
+ const row = yield find(call.request.ref, workspace(call));
155
+ // Deliveries stay in the log; pending ones fail when attempted (no endpoint).
156
+ yield db.webhookEndpoint.delete({ where: { ref: row.ref } });
157
+ callback(null, { ref: row.ref });
158
+ });
159
+ const rotateWebhookSecret = (call, callback) => __awaiter(this, void 0, void 0, function* () {
160
+ var _a;
161
+ const row = yield find(call.request.ref, workspace(call));
162
+ const secret = `whsec_${(0, crypto_1.randomBytes)(24).toString("base64url")}`;
163
+ const until = new Date(now() + ((_a = config.rotationWindowMs) !== null && _a !== void 0 ? _a : ROTATION_WINDOW_MS));
164
+ yield db.webhookEndpoint.update({
165
+ where: { ref: row.ref },
166
+ data: { secret, previousSecret: row.secret, previousUntil: until }
167
+ });
168
+ callback(null, {
169
+ ref: row.ref,
170
+ secret,
171
+ previousSecretUntil: seconds(until)
172
+ });
173
+ });
174
+ const listWebhookDeliveries = (call, callback) => __awaiter(this, void 0, void 0, function* () {
175
+ const accessKeyId = workspace(call);
176
+ const rows = yield db.webhookDelivery.findMany({
177
+ where: Object.assign({ accessKeyId }, (call.request.webhookRef
178
+ ? { endpointRef: call.request.webhookRef }
179
+ : {})),
180
+ orderBy: { createdAt: "desc" },
181
+ take: Math.min(call.request.pageSize || 50, 200)
182
+ });
183
+ callback(null, { items: rows.map(toDelivery) });
184
+ });
185
+ /** Sends again now with the original event id and a fresh signature (W6). */
186
+ const resendWebhookDelivery = (call, callback) => __awaiter(this, void 0, void 0, function* () {
187
+ const accessKeyId = workspace(call);
188
+ const { ref } = call.request;
189
+ const row = yield db.webhookDelivery.findFirst({
190
+ where: { ref, accessKeyId }
191
+ });
192
+ if (!row)
193
+ throw notFound(`delivery not found: ${ref}`);
194
+ const store = yield common_1.Webhooks.PrismaWebhookStore.open(db);
195
+ yield store.loadDeliveries({ id: ref, workspaceRef: accessKeyId }, 1);
196
+ const dispatcher = new common_1.Webhooks.WebhookDispatcher({
197
+ store,
198
+ allowInsecureUrls: config.allowInsecureUrls,
199
+ allowedDestinations: config.allowedDestinations,
200
+ now
201
+ });
202
+ yield dispatcher.resend(ref);
203
+ yield store.flush();
204
+ const updated = yield db.webhookDelivery.findUnique({ where: { ref } });
205
+ callback(null, toDelivery(updated));
206
+ });
207
+ return {
208
+ createWebhook: (0, common_1.withErrorHandling)(createWebhook),
209
+ listWebhooks: (0, common_1.withErrorHandling)(listWebhooks),
210
+ getWebhook: (0, common_1.withErrorHandling)(getWebhook),
211
+ updateWebhook: (0, common_1.withErrorHandling)(updateWebhook),
212
+ deleteWebhook: (0, common_1.withErrorHandling)(deleteWebhook),
213
+ rotateWebhookSecret: (0, common_1.withErrorHandling)(rotateWebhookSecret),
214
+ listWebhookDeliveries: (0, common_1.withErrorHandling)(listWebhookDeliveries),
215
+ resendWebhookDelivery: (0, common_1.withErrorHandling)(resendWebhookDelivery)
216
+ };
217
+ }
@@ -0,0 +1,37 @@
1
+ import { WebhooksDb } from "./createWebhooksHandlers";
2
+ declare function buildWebhooksService(db: WebhooksDb): {
3
+ definition: {
4
+ serviceName: string;
5
+ pckg: string;
6
+ version: string;
7
+ proto: string;
8
+ };
9
+ handlers: {
10
+ createWebhook: (call: {
11
+ request: unknown;
12
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
13
+ listWebhooks: (call: {
14
+ request: unknown;
15
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
16
+ getWebhook: (call: {
17
+ request: unknown;
18
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
19
+ updateWebhook: (call: {
20
+ request: unknown;
21
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
22
+ deleteWebhook: (call: {
23
+ request: unknown;
24
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
25
+ rotateWebhookSecret: (call: {
26
+ request: unknown;
27
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
28
+ listWebhookDeliveries: (call: {
29
+ request: unknown;
30
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
31
+ resendWebhookDelivery: (call: {
32
+ request: unknown;
33
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
34
+ };
35
+ };
36
+ export { buildWebhooksService };
37
+ export * from "./createWebhooksHandlers";
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.buildWebhooksService = buildWebhooksService;
18
+ /**
19
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
20
+ * http://github.com/fonoster/fonoster
21
+ *
22
+ * This file is part of Fonoster
23
+ *
24
+ * Licensed under the MIT License (the "License");
25
+ * you may not use this file except in compliance with
26
+ * the License. You may obtain a copy of the License at
27
+ *
28
+ * https://opensource.org/licenses/MIT
29
+ *
30
+ * Unless required by applicable law or agreed to in writing, software
31
+ * distributed under the License is distributed on an "AS IS" BASIS,
32
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+ * See the License for the specific language governing permissions and
34
+ * limitations under the License.
35
+ */
36
+ const envs_1 = require("../envs");
37
+ const createWebhooksHandlers_1 = require("./createWebhooksHandlers");
38
+ function buildWebhooksService(db) {
39
+ return {
40
+ definition: {
41
+ serviceName: "Webhooks",
42
+ pckg: "webhooks",
43
+ version: "v1beta2",
44
+ proto: "webhooks.proto"
45
+ },
46
+ handlers: (0, createWebhooksHandlers_1.createWebhooksHandlers)(db, {
47
+ allowInsecureUrls: envs_1.SESSION_APPS === null || envs_1.SESSION_APPS === void 0 ? void 0 : envs_1.SESSION_APPS.allowInsecureWebhooks
48
+ })
49
+ };
50
+ }
51
+ __exportStar(require("./createWebhooksHandlers"), exports);
@@ -0,0 +1,49 @@
1
+ import { Sessions, Webhooks } from "@fonoster/common";
2
+ /** `call.ended`'s `endReason` when AppBridge that owned the call died mid-call. */
3
+ export declare const APPBRIDGE_LOST_REASON = "appbridge-lost";
4
+ /**
5
+ * The `call.ended` the control plane sends for a call whose AppBridge is gone (the node ended it
6
+ * with cause `app_gone`). Its id depends on the call only, so every replica that detects the loss builds the same event and the fan-out
7
+ * stores one delivery per endpoint (delivery ids depend on the event id): delivered once.
8
+ */
9
+ export declare function lostCallEnded(call: Record<string, unknown>, lastSeenAt: number): Webhooks.WebhookEvent | undefined;
10
+ /** How long after the node's `app_gone` an AppBridge's own end of the call may still show up. */
11
+ export declare const APP_GONE_GRACE_MS = 2000;
12
+ /**
13
+ * How long a call entry is remembered after its last write: an AppBridge rewrites its entries
14
+ * every SESSIONS_REFRESH_MS, and the node reports `app_gone` well within this after its AppBridge
15
+ * stops (stream break at once, keepalive or media timeout within seconds).
16
+ */
17
+ export declare const LOST_CALL_FORGET_MS: number;
18
+ /**
19
+ * Calls whose AppBridge died mid-call (redesign-roomr 15.4, workspace-webhooks "AppBridge dies
20
+ * mid-call"). AppBridge writes `calls.<callRef>` (with the app and parties once the call reached
21
+ * an app) and deletes it when the call ends, right after it sent its own `call.ended`. When the
22
+ * Roomr node ends a call with cause `app_gone` (its control stream broke, or the app leg went
23
+ * silent), `onAppGone` waits `graceMs` for that delete and then, if the entry was not deleted (it
24
+ * is still there, or it expired with the AppBridge that kept it alive), `emit` gets the call's
25
+ * `call.ended` with `endReason` `appbridge-lost`. Its id depends on the call only, so the event is
26
+ * delivered once per endpoint across replicas; a call AppBridge ended itself gets none.
27
+ *
28
+ * Entries are remembered as this replica saw them on the registry watch (an entry that expires is
29
+ * not reported by the watch, so it stays here until `forgetMs` after its last write).
30
+ */
31
+ export declare function createLostCalls(deps: {
32
+ emit: (event: Webhooks.WebhookEvent) => unknown;
33
+ graceMs?: number;
34
+ forgetMs?: number;
35
+ now?: () => number;
36
+ }): {
37
+ onEntry: (e: Sessions.SessionEntry) => void;
38
+ /**
39
+ * The node ended `callRef` with cause `app_gone`: after `graceMs` (an AppBridge that ended the
40
+ * call itself deletes its entry by then) the call's `call.ended` (appbridge-lost) is sent.
41
+ * Resolves with the event, or undefined when there is none to send.
42
+ */
43
+ onAppGone(callRef: string): Promise<Webhooks.WebhookEvent | undefined>;
44
+ /** Drops what is remembered past `forgetMs` (also done as entries arrive). */
45
+ forget: () => void;
46
+ size: () => number;
47
+ stop(): void;
48
+ };
49
+ export type LostCalls = ReturnType<typeof createLostCalls>;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOST_CALL_FORGET_MS = exports.APP_GONE_GRACE_MS = exports.APPBRIDGE_LOST_REASON = void 0;
4
+ exports.lostCallEnded = lostCallEnded;
5
+ exports.createLostCalls = createLostCalls;
6
+ /**
7
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
8
+ * http://github.com/fonoster/fonoster
9
+ *
10
+ * This file is part of Fonoster
11
+ *
12
+ * Licensed under the MIT License (the "License");
13
+ * you may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at
15
+ *
16
+ * https://opensource.org/licenses/MIT
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const crypto_1 = require("crypto");
25
+ const common_1 = require("@fonoster/common");
26
+ /** `call.ended`'s `endReason` when AppBridge that owned the call died mid-call. */
27
+ exports.APPBRIDGE_LOST_REASON = "appbridge-lost";
28
+ /**
29
+ * The `call.ended` the control plane sends for a call whose AppBridge is gone (the node ended it
30
+ * with cause `app_gone`). Its id depends on the call only, so every replica that detects the loss builds the same event and the fan-out
31
+ * stores one delivery per endpoint (delivery ids depend on the event id): delivered once.
32
+ */
33
+ function lostCallEnded(call, lastSeenAt) {
34
+ const str = (v) => (typeof v === "string" ? v : "");
35
+ const callRef = str(call.callRef);
36
+ const appRef = str(call.appRef);
37
+ // Only a call that reached an app gets call.ended (voice-session).
38
+ if (!callRef || !appRef)
39
+ return undefined;
40
+ const startedAt = Date.parse(str(call.startedAt));
41
+ const event = common_1.Webhooks.callEnded("", {
42
+ callRef,
43
+ appRef,
44
+ from: str(call.from),
45
+ to: str(call.to),
46
+ direction: call.direction === "outbound" ? "outbound" : "inbound",
47
+ durationSeconds: Number.isFinite(startedAt)
48
+ ? Math.max(0, Math.round((lastSeenAt - startedAt) / 1000))
49
+ : 0,
50
+ endReason: exports.APPBRIDGE_LOST_REASON
51
+ });
52
+ const digest = (0, crypto_1.createHash)("sha256")
53
+ .update(`appbridge-lost\n${callRef}`)
54
+ .digest("hex")
55
+ .slice(0, 32);
56
+ return Object.assign(Object.assign({}, event), { id: `evt_lost_${digest}` });
57
+ }
58
+ /** How long after the node's `app_gone` an AppBridge's own end of the call may still show up. */
59
+ exports.APP_GONE_GRACE_MS = 2000;
60
+ /**
61
+ * How long a call entry is remembered after its last write: an AppBridge rewrites its entries
62
+ * every SESSIONS_REFRESH_MS, and the node reports `app_gone` well within this after its AppBridge
63
+ * stops (stream break at once, keepalive or media timeout within seconds).
64
+ */
65
+ exports.LOST_CALL_FORGET_MS = 5 * 60000;
66
+ /**
67
+ * Calls whose AppBridge died mid-call (redesign-roomr 15.4, workspace-webhooks "AppBridge dies
68
+ * mid-call"). AppBridge writes `calls.<callRef>` (with the app and parties once the call reached
69
+ * an app) and deletes it when the call ends, right after it sent its own `call.ended`. When the
70
+ * Roomr node ends a call with cause `app_gone` (its control stream broke, or the app leg went
71
+ * silent), `onAppGone` waits `graceMs` for that delete and then, if the entry was not deleted (it
72
+ * is still there, or it expired with the AppBridge that kept it alive), `emit` gets the call's
73
+ * `call.ended` with `endReason` `appbridge-lost`. Its id depends on the call only, so the event is
74
+ * delivered once per endpoint across replicas; a call AppBridge ended itself gets none.
75
+ *
76
+ * Entries are remembered as this replica saw them on the registry watch (an entry that expires is
77
+ * not reported by the watch, so it stays here until `forgetMs` after its last write).
78
+ */
79
+ function createLostCalls(deps) {
80
+ var _a, _b, _c;
81
+ const graceMs = (_a = deps.graceMs) !== null && _a !== void 0 ? _a : exports.APP_GONE_GRACE_MS;
82
+ const forgetMs = (_b = deps.forgetMs) !== null && _b !== void 0 ? _b : exports.LOST_CALL_FORGET_MS;
83
+ const now = (_c = deps.now) !== null && _c !== void 0 ? _c : Date.now;
84
+ const calls = new Map();
85
+ /** Calls already reported here (a repeated app_gone sends nothing more). */
86
+ const reported = new Map();
87
+ const timers = new Set();
88
+ const forget = () => {
89
+ const at = now();
90
+ for (const [id, c] of calls)
91
+ if (at - c.seenAt > forgetMs)
92
+ calls.delete(id);
93
+ for (const [id, t] of reported)
94
+ if (at - t > forgetMs)
95
+ reported.delete(id);
96
+ };
97
+ /** One `calls.*` registry entry (a put, or a delete when the call ended normally). */
98
+ const onEntry = (e) => {
99
+ if (e.kind !== "calls")
100
+ return;
101
+ if (e.value)
102
+ calls.set(e.id, { value: e.value, seenAt: now() });
103
+ else
104
+ calls.delete(e.id); // ended: its AppBridge sent call.ended
105
+ if (calls.size % 256 === 0)
106
+ forget();
107
+ };
108
+ /** Reports the call now if its entry is still known; returns its event. */
109
+ const report = (callRef) => {
110
+ const id = common_1.Sessions.sessionKey("calls", callRef).slice("calls.".length);
111
+ const c = calls.get(id);
112
+ if (!c || reported.has(id))
113
+ return undefined;
114
+ calls.delete(id);
115
+ reported.set(id, now());
116
+ const event = lostCallEnded(c.value, now());
117
+ if (event)
118
+ deps.emit(event);
119
+ return event;
120
+ };
121
+ return {
122
+ onEntry,
123
+ /**
124
+ * The node ended `callRef` with cause `app_gone`: after `graceMs` (an AppBridge that ended the
125
+ * call itself deletes its entry by then) the call's `call.ended` (appbridge-lost) is sent.
126
+ * Resolves with the event, or undefined when there is none to send.
127
+ */
128
+ onAppGone(callRef) {
129
+ if (graceMs <= 0)
130
+ return Promise.resolve(report(callRef));
131
+ return new Promise((resolve) => {
132
+ const t = setTimeout(() => {
133
+ timers.delete(t);
134
+ resolve(report(callRef));
135
+ }, graceMs);
136
+ timers.add(t);
137
+ });
138
+ },
139
+ /** Drops what is remembered past `forgetMs` (also done as entries arrive). */
140
+ forget,
141
+ size: () => calls.size,
142
+ stop() {
143
+ timers.forEach(clearTimeout);
144
+ timers.clear();
145
+ }
146
+ };
147
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { Webhooks } from "@fonoster/common";
20
+ import { NatsConnection } from "nats";
21
+ import { LostCalls } from "./lostCalls";
22
+ /** One replica handles each node event (core NATS queue group). */
23
+ export declare const NODE_EVENTS_QUEUE = "apiserver-roomr-events";
24
+ /** The minimal record of an unanswered outbound call, written where the region keeps records. */
25
+ export type FailedCallRecord = {
26
+ callRef: string;
27
+ workspaceRef: string | null;
28
+ /** The node's region (its heartbeat), where the record is written. */
29
+ region?: string;
30
+ entries: Record<string, unknown>[];
31
+ };
32
+ export type FailedCallRecords = (record: FailedCallRecord) => Promise<unknown>;
33
+ /** Where records go when the node reports no region (AppBridge's `callRecord.region` default). */
34
+ export declare const DEFAULT_RECORD_REGION = "default";
35
+ /**
36
+ * Writes failed-call records through the region's record maintenance subject
37
+ * (`callrecord.<region>.maintenance`, op `failed_call`, served by the AppBridge replicas that hold
38
+ * the region's signing key): the control plane never holds it.
39
+ */
40
+ export declare function natsFailedCallRecords(nc: NatsConnection, timeoutMs?: number): FailedCallRecords;
41
+ /** The minimal record's entries (as AppBridge wrote them for calls that never reached an app). */
42
+ export declare function failedCallEntries(call: Webhooks.UnansweredCall, workspaceRef: string | null): Record<string, unknown>[];
43
+ /**
44
+ * The control plane's reading of the Roomr nodes' call events (`roomr.events.<call_ref>`, one
45
+ * replica per event): what no AppBridge can report.
46
+ *
47
+ * - An outbound call the control plane placed (its `metadata.app_ref`) that ends unanswered
48
+ * (`call.ended` with `answered: false`: busy, no answer, rejected, node error, removed) reached
49
+ * no AppBridge: its minimal call record (call.started, call.progress, call.failed) is written
50
+ * (`records`) and `call.failed` goes to the fan-out (`intake`).
51
+ * - A call the node ended with cause `app_gone` lost its AppBridge: `lost` sends its `call.ended`
52
+ * (`appbridge-lost`) unless AppBridge ended the call itself.
53
+ *
54
+ * Events are best effort (media-control "Events are best effort while NATS is down"): one lost in
55
+ * an outage is never replayed; TrackCall's and the placement sweep's own sweeps close what it
56
+ * would have closed.
57
+ */
58
+ export declare function createNodeCallEvents(deps: {
59
+ lost?: LostCalls;
60
+ intake: (event: Webhooks.WebhookEvent) => Promise<unknown> | unknown;
61
+ records?: FailedCallRecords;
62
+ /** The workspace of an app (the record names it; the webhook resolves it itself). */
63
+ workspaceOfApp?: (appRef: string) => Promise<string | undefined>;
64
+ /** The region of a node from its heartbeats. */
65
+ regionOf?: (nodeRef: string) => string | undefined;
66
+ }): {
67
+ onEvent(subject: string, event: Record<string, unknown>): Promise<void>;
68
+ };
69
+ /**
70
+ * Subscribes to the nodes' call events (one replica per event) and their heartbeats (each node's
71
+ * region); returns a stop function.
72
+ */
73
+ export declare function subscribeNodeCallEvents(nc: NatsConnection, deps: Omit<Parameters<typeof createNodeCallEvents>[0], "regionOf">): () => void;