@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.
- package/dist/applications/buildService.d.ts +5 -1
- package/dist/applications/buildService.js +10 -7
- package/dist/applications/createCreateApplication.d.ts +6 -2
- package/dist/applications/createCreateApplication.js +24 -16
- package/dist/applications/createCreateTestToken.d.ts +3 -1
- package/dist/applications/createCreateTestToken.js +18 -13
- package/dist/applications/createGetApplication.js +2 -2
- package/dist/applications/createGetFnUtil.d.ts +22 -18
- package/dist/applications/createGetFnUtil.js +3 -5
- package/dist/applications/createListApplications.js +3 -4
- package/dist/applications/createRotateSigningSecret.d.ts +9 -0
- package/dist/{calls/createFetchSingleCall.js → applications/createRotateSigningSecret.js} +23 -20
- package/dist/applications/createUpdateApplication.d.ts +6 -2
- package/dist/applications/createUpdateApplication.js +35 -36
- package/dist/applications/evalKeys.d.ts +9 -0
- package/dist/{voice/handlers/dial/recordChannel.js → applications/evalKeys.js} +17 -12
- package/dist/applications/session/appModel.d.ts +225 -0
- package/dist/applications/session/appModel.js +331 -0
- package/dist/applications/types.d.ts +1 -27
- package/dist/billing/buildService.d.ts +24 -0
- package/dist/billing/buildService.js +116 -0
- package/dist/bin/entrypoint.d.ts +1 -0
- package/dist/bin/entrypoint.js +180 -0
- package/dist/bin/healthcheck.d.ts +2 -0
- package/dist/{voice/utils/VoiceServiceClientConstructor.js → bin/healthcheck.js} +24 -9
- package/dist/bin/regionHubSetup.d.ts +2 -0
- package/dist/bin/regionHubSetup.js +67 -0
- package/dist/bin/usage.d.ts +2 -0
- package/dist/bin/usage.js +119 -0
- package/dist/calls/buildService.d.ts +1 -20
- package/dist/calls/buildService.js +59 -6
- package/dist/calls/createCall.d.ts +17 -2
- package/dist/calls/createCall.js +64 -11
- package/dist/calls/createCallPublisher.d.ts +40 -2
- package/dist/calls/createCallPublisher.js +43 -9
- package/dist/calls/createIsWorkspaceNumber.d.ts +41 -0
- package/dist/calls/createIsWorkspaceNumber.js +39 -0
- package/dist/calls/createTrackCall.d.ts +55 -2
- package/dist/calls/createTrackCall.js +230 -16
- package/dist/calls/getCall.d.ts +4 -2
- package/dist/calls/getCall.js +2 -3
- package/dist/calls/listCalls.d.ts +4 -2
- package/dist/calls/listCalls.js +2 -3
- package/dist/calls/types.d.ts +11 -2
- package/dist/calls/types.js +10 -0
- package/dist/{core/buildWelcomeDemoService.d.ts → capabilities/buildService.d.ts} +8 -8
- package/dist/capabilities/buildService.js +17 -0
- package/dist/capabilities/createGetCapabilities.d.ts +78 -0
- package/dist/capabilities/createGetCapabilities.js +98 -0
- package/dist/{voice/handlers/utils → capabilities}/index.d.ts +2 -3
- package/dist/{voice/handlers/utils → capabilities}/index.js +4 -3
- package/dist/config/index.d.ts +23 -0
- package/dist/config/index.js +102 -0
- package/dist/config/schema.d.ts +1919 -0
- package/dist/config/schema.js +357 -0
- package/dist/core/allowList.js +2 -1
- package/dist/core/applyCatalog.d.ts +10 -0
- package/dist/{voice/client/GrpcClientHandler.js → core/applyCatalog.js} +45 -51
- package/dist/core/db.d.ts +3 -1
- package/dist/core/db.js +2 -1
- package/dist/core/durableConsumer.d.ts +41 -0
- package/dist/core/durableConsumer.js +104 -0
- package/dist/core/httpBridge.d.ts +24 -6
- package/dist/core/httpBridge.js +3 -25
- package/dist/core/identityConfig.d.ts +2 -35
- package/dist/core/identityConfig.js +3 -36
- package/dist/core/regionHooks.d.ts +15 -0
- package/dist/{calls/influxdb.js → core/regionHooks.js} +4 -8
- package/dist/core/runServices.js +98 -15
- package/dist/core/services.d.ts +96 -6
- package/dist/core/services.js +49 -10
- package/dist/{voice/errors/index.d.ts → core/telemetry.d.ts} +2 -2
- package/dist/core/telemetry.js +42 -0
- package/dist/{applications/utils/convertToApplicationData.d.ts → core/telemetryInterceptor.d.ts} +10 -4
- package/dist/core/telemetryInterceptor.js +57 -0
- package/dist/core/testTokenConfig.js +4 -1
- package/dist/core/upsertRoomrPeer.d.ts +6 -0
- package/dist/core/{upsertDefaultPeer.js → upsertRoomrPeer.js} +31 -30
- package/dist/envs.d.ts +136 -23
- package/dist/envs.js +108 -143
- package/dist/index.js +39 -21
- package/dist/outbound/createNodeDirectory.d.ts +86 -0
- package/dist/outbound/createNodeDirectory.js +140 -0
- package/dist/{voice/integrations → outbound}/index.d.ts +4 -1
- package/dist/{voice/errors → outbound}/index.js +4 -2
- package/dist/outbound/placeOutboundCall.d.ts +96 -0
- package/dist/outbound/placeOutboundCall.js +172 -0
- package/dist/outbound/placementSweep.d.ts +56 -0
- package/dist/outbound/placementSweep.js +127 -0
- package/dist/outbound/runOutboundCalls.d.ts +52 -0
- package/dist/outbound/runOutboundCalls.js +171 -0
- package/dist/providers/createProvidersHandlers.d.ts +39 -0
- package/dist/providers/createProvidersHandlers.js +229 -0
- package/dist/providers/index.d.ts +47 -0
- package/dist/{voice/client → providers}/index.js +15 -6
- package/dist/providers/registryUsage.d.ts +48 -0
- package/dist/providers/registryUsage.js +236 -0
- package/dist/records/createIndexRecord.d.ts +42 -0
- package/dist/records/createIndexRecord.js +185 -0
- package/dist/records/createRecordsRouter.d.ts +61 -0
- package/dist/records/createRecordsRouter.js +330 -0
- package/dist/records/createSearchRecords.d.ts +51 -0
- package/dist/records/createSearchRecords.js +134 -0
- package/dist/{voice/filters → records}/index.d.ts +6 -6
- package/dist/{voice/filters → records}/index.js +6 -6
- package/dist/records/maintenance.d.ts +33 -0
- package/dist/records/maintenance.js +166 -0
- package/dist/records/runCallRecords.d.ts +48 -0
- package/dist/records/runCallRecords.js +49 -0
- package/dist/{events/createPerCallCache.d.ts → records/stores.d.ts} +4 -7
- package/dist/{voice/handlers/utils/isDtmf.js → records/stores.js} +9 -3
- package/dist/records/types.d.ts +104 -0
- package/dist/regions/configSync.d.ts +130 -0
- package/dist/regions/configSync.js +316 -0
- package/dist/regions/createRegionsRouter.d.ts +151 -0
- package/dist/regions/createRegionsRouter.js +391 -0
- package/dist/regions/endpoints.d.ts +41 -0
- package/dist/regions/endpoints.js +90 -0
- package/dist/regions/enrollmentToken.d.ts +41 -0
- package/dist/regions/enrollmentToken.js +94 -0
- package/dist/regions/httpAuth.d.ts +39 -0
- package/dist/regions/httpAuth.js +78 -0
- package/dist/regions/ids.d.ts +15 -0
- package/dist/regions/ids.js +81 -0
- package/dist/{voice/client → regions}/index.d.ts +17 -6
- package/dist/regions/index.js +51 -0
- package/dist/regions/link.d.ts +17 -0
- package/dist/regions/link.js +170 -0
- package/dist/regions/natsAuth.d.ts +41 -0
- package/dist/regions/natsAuth.js +64 -0
- package/dist/regions/natsJwt.d.ts +23 -0
- package/dist/regions/natsJwt.js +26 -0
- package/dist/regions/relay.d.ts +45 -0
- package/dist/regions/relay.js +203 -0
- package/dist/regions/relayHttp.d.ts +7 -0
- package/dist/regions/relayHttp.js +107 -0
- package/dist/regions/relaySlots.d.ts +18 -0
- package/dist/regions/relaySlots.js +118 -0
- package/dist/regions/runRegions.d.ts +111 -0
- package/dist/regions/runRegions.js +235 -0
- package/dist/regions/service.d.ts +129 -0
- package/dist/regions/service.js +558 -0
- package/dist/regions/sources.d.ts +20 -0
- package/dist/regions/sources.js +191 -0
- package/dist/regions/status.d.ts +35 -0
- package/dist/regions/status.js +63 -0
- package/dist/regions/types.d.ts +123 -0
- package/dist/regions/types.js +41 -0
- package/dist/{voice/integrations/getSttConfig.d.ts → regions/withConfigChangeHook.d.ts} +13 -7
- package/dist/regions/withConfigChangeHook.js +44 -0
- package/dist/secrets/createGetFnUtil.d.ts +2 -2
- package/dist/session/createSessionRouter.d.ts +49 -0
- package/dist/session/createSessionRouter.js +206 -0
- package/dist/{voice/handlers/dial → session}/index.d.ts +1 -1
- package/dist/{voice/handlers/dial → session}/index.js +1 -1
- package/dist/usage/buildService.d.ts +16 -0
- package/dist/{voice/integrations/getTtsConfig.js → usage/buildService.js} +13 -7
- package/dist/{voice/tts/utils/convertUlawToPCM16.d.ts → usage/createGetUsage.d.ts} +7 -6
- package/dist/usage/createGetUsage.js +118 -0
- package/dist/usage/ingestUsage.d.ts +7 -0
- package/dist/usage/ingestUsage.js +87 -0
- package/dist/usage/publishRecordedUsage.d.ts +52 -0
- package/dist/usage/publishRecordedUsage.js +103 -0
- package/dist/{utils/createHandleDialEventsWithNats.d.ts → usage/publishUsage.d.ts} +10 -4
- package/dist/usage/publishUsage.js +50 -0
- package/dist/usage/rebuildUsage.d.ts +48 -0
- package/dist/usage/rebuildUsage.js +104 -0
- package/dist/usage/runUsageConsumer.d.ts +22 -0
- package/dist/usage/runUsageConsumer.js +78 -0
- package/dist/usage/snapshotStorage.d.ts +14 -0
- package/dist/usage/snapshotStorage.js +95 -0
- package/dist/{voice/integrations/getTtsConfig.d.ts → usage/types.d.ts} +17 -6
- package/dist/utils/createCheckNumberPreconditions.js +4 -0
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/voice/stt/Deepgram.d.ts +4 -57
- package/dist/voice/stt/Deepgram.js +15 -286
- package/dist/voice/stt/Google.d.ts +4 -15
- package/dist/voice/stt/Google.js +7 -103
- package/dist/voice/stt/types.d.ts +2 -38
- package/dist/voice/stt/types.js +25 -3
- package/dist/voice/tts/Azure.d.ts +4 -34
- package/dist/voice/tts/Azure.js +25 -105
- package/dist/voice/tts/Deepgram.d.ts +4 -38
- package/dist/voice/tts/Deepgram.js +25 -82
- package/dist/voice/tts/ElevenLabs.d.ts +4 -18
- package/dist/voice/tts/ElevenLabs.js +6 -97
- package/dist/voice/tts/Google.d.ts +4 -38
- package/dist/voice/tts/Google.js +25 -91
- package/dist/webhooks/createWebhooksHandlers.d.ts +37 -0
- package/dist/webhooks/createWebhooksHandlers.js +217 -0
- package/dist/webhooks/index.d.ts +37 -0
- package/dist/webhooks/index.js +51 -0
- package/dist/webhooks/lostCalls.d.ts +49 -0
- package/dist/webhooks/lostCalls.js +147 -0
- package/dist/webhooks/nodeCallEvents.d.ts +73 -0
- package/dist/webhooks/nodeCallEvents.js +177 -0
- package/dist/webhooks/runWebhookFanout.d.ts +44 -0
- package/dist/webhooks/runWebhookFanout.js +202 -0
- package/package.json +21 -31
- package/dist/applications/utils/applicationWithEncodedStruct.d.ts +0 -3
- package/dist/applications/utils/applicationWithEncodedStruct.js +0 -50
- package/dist/applications/utils/convertToApplicationData.js +0 -37
- package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +0 -786
- package/dist/applications/validation/assistantWithoutApiKeySchema.js +0 -35
- package/dist/applications/validation/createValidationSchema.d.ts +0 -1474
- package/dist/applications/validation/createValidationSchema.js +0 -67
- package/dist/applications/validation/prepareForValidation.d.ts +0 -21
- package/dist/applications/validation/prepareForValidation.js +0 -35
- package/dist/applications/validation/speechValidators.d.ts +0 -47
- package/dist/applications/validation/speechValidators.js +0 -50
- package/dist/applications/validation/validOrThrow.d.ts +0 -21
- package/dist/applications/validation/validOrThrow.js +0 -15
- package/dist/calls/createFetchCalls.d.ts +0 -22
- package/dist/calls/createFetchCalls.js +0 -88
- package/dist/calls/createFetchSingleCall.d.ts +0 -22
- package/dist/calls/influxdb.d.ts +0 -2
- package/dist/calls/runCallManager.d.ts +0 -8
- package/dist/calls/runCallManager.js +0 -75
- package/dist/core/buildWelcomeDemoService.js +0 -97
- package/dist/core/upsertDefaultPeer.d.ts +0 -2
- package/dist/events/amdResultCache.d.ts +0 -23
- package/dist/events/amdResultCache.js +0 -35
- package/dist/events/createInfluxDbPub.d.ts +0 -13
- package/dist/events/createInfluxDbPub.js +0 -89
- package/dist/events/createPerCallCache.js +0 -46
- package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
- package/dist/events/mapCallDirectionToEnum.js +0 -37
- package/dist/events/nats.d.ts +0 -10
- package/dist/events/nats.js +0 -82
- package/dist/events/transformEvent.d.ts +0 -2
- package/dist/events/transformEvent.js +0 -87
- package/dist/events/types.d.ts +0 -26
- package/dist/utils/createHandleDialEventsWithNats.js +0 -24
- package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +0 -23
- package/dist/utils/createHandleDialEventsWithVoiceClient.js +0 -27
- package/dist/utils/getIntegrationsFromFile.d.ts +0 -2
- package/dist/utils/getIntegrationsFromFile.js +0 -49
- package/dist/utils/mapDialStatus.d.ts +0 -21
- package/dist/utils/mapDialStatus.js +0 -38
- package/dist/voice/VoiceDispatcher.d.ts +0 -21
- package/dist/voice/VoiceDispatcher.js +0 -122
- package/dist/voice/amd/mapAsteriskAmd.d.ts +0 -38
- package/dist/voice/amd/mapAsteriskAmd.js +0 -68
- package/dist/voice/client/AudioSocketHandler.d.ts +0 -38
- package/dist/voice/client/AudioSocketHandler.js +0 -70
- package/dist/voice/client/AuthorizationHandler.d.ts +0 -13
- package/dist/voice/client/AuthorizationHandler.js +0 -78
- package/dist/voice/client/ExternalMediaHandler.d.ts +0 -32
- package/dist/voice/client/ExternalMediaHandler.js +0 -59
- package/dist/voice/client/GrpcClientHandler.d.ts +0 -36
- package/dist/voice/client/SpeechHandler.d.ts +0 -60
- package/dist/voice/client/SpeechHandler.js +0 -120
- package/dist/voice/client/VoiceClientImpl.d.ts +0 -79
- package/dist/voice/client/VoiceClientImpl.js +0 -198
- package/dist/voice/connectToAri.d.ts +0 -2
- package/dist/voice/connectToAri.js +0 -81
- package/dist/voice/createCreateVoiceClient.d.ts +0 -9
- package/dist/voice/createCreateVoiceClient.js +0 -97
- package/dist/voice/errors/ChannelVarNotFoundError.d.ts +0 -23
- package/dist/voice/errors/ChannelVarNotFoundError.js +0 -10
- package/dist/voice/errors/MethodNotImplementedError.d.ts +0 -22
- package/dist/voice/errors/MethodNotImplementedError.js +0 -27
- package/dist/voice/filters/AudioFilterFactory.d.ts +0 -35
- package/dist/voice/filters/AudioFilterFactory.js +0 -94
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +0 -64
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +0 -252
- package/dist/voice/filters/aiCoustics/types.d.ts +0 -45
- package/dist/voice/filters/aiCoustics/types.js +0 -29
- package/dist/voice/filters/createAudioFilterChain.d.ts +0 -9
- package/dist/voice/filters/createAudioFilterChain.js +0 -171
- package/dist/voice/filters/createAudioFilterSession.d.ts +0 -15
- package/dist/voice/filters/createAudioFilterSession.js +0 -114
- package/dist/voice/filters/pcm.d.ts +0 -21
- package/dist/voice/filters/pcm.js +0 -37
- package/dist/voice/filters/types.d.ts +0 -61
- package/dist/voice/filters/types.js +0 -26
- package/dist/voice/handlers/createAnswerHandler.d.ts +0 -23
- package/dist/voice/handlers/createAnswerHandler.js +0 -24
- package/dist/voice/handlers/createHangupHandler.d.ts +0 -23
- package/dist/voice/handlers/createHangupHandler.js +0 -28
- package/dist/voice/handlers/createMuteHandler.d.ts +0 -4
- package/dist/voice/handlers/createMuteHandler.js +0 -27
- package/dist/voice/handlers/createPlayDtmfHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlayDtmfHandler.js +0 -27
- package/dist/voice/handlers/createPlayHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlayHandler.js +0 -33
- package/dist/voice/handlers/createPlaybackControlHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlaybackControlHandler.js +0 -62
- package/dist/voice/handlers/createRecordHandler.d.ts +0 -4
- package/dist/voice/handlers/createRecordHandler.js +0 -58
- package/dist/voice/handlers/createSayHandler.d.ts +0 -4
- package/dist/voice/handlers/createSayHandler.js +0 -31
- package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +0 -11
- package/dist/voice/handlers/createSetAudioFiltersHandler.js +0 -74
- package/dist/voice/handlers/createStopSayHandler.d.ts +0 -3
- package/dist/voice/handlers/createStopSayHandler.js +0 -34
- package/dist/voice/handlers/createStreamGatherHandler.d.ts +0 -3
- package/dist/voice/handlers/createStreamGatherHandler.js +0 -74
- package/dist/voice/handlers/createStreamHandler.d.ts +0 -3
- package/dist/voice/handlers/createStreamHandler.js +0 -70
- package/dist/voice/handlers/createUnmuteHandler.d.ts +0 -4
- package/dist/voice/handlers/createUnmuteHandler.js +0 -27
- package/dist/voice/handlers/dial/createDialHandler.d.ts +0 -23
- package/dist/voice/handlers/dial/createDialHandler.js +0 -78
- package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +0 -24
- package/dist/voice/handlers/dial/handleChannelLeftBridge.js +0 -29
- package/dist/voice/handlers/dial/handleStasisEnd.d.ts +0 -21
- package/dist/voice/handlers/dial/handleStasisEnd.js +0 -19
- package/dist/voice/handlers/dial/handleStasisStart.d.ts +0 -27
- package/dist/voice/handlers/dial/handleStasisStart.js +0 -52
- package/dist/voice/handlers/dial/recordChannel.d.ts +0 -22
- package/dist/voice/handlers/gather/createGatherHandler.d.ts +0 -3
- package/dist/voice/handlers/gather/createGatherHandler.js +0 -86
- package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +0 -26
- package/dist/voice/handlers/gather/getTimeoutPromise.js +0 -18
- package/dist/voice/handlers/index.d.ts +0 -33
- package/dist/voice/handlers/index.js +0 -49
- package/dist/voice/handlers/utils/awaitForPlaybackFinished.d.ts +0 -21
- package/dist/voice/handlers/utils/awaitForPlaybackFinished.js +0 -25
- package/dist/voice/handlers/utils/awaitForRecordingFinished.d.ts +0 -5
- package/dist/voice/handlers/utils/awaitForRecordingFinished.js +0 -53
- package/dist/voice/handlers/utils/isDtmf.d.ts +0 -20
- package/dist/voice/handlers/utils/textChunksByClause.d.ts +0 -2
- package/dist/voice/handlers/utils/textChunksByClause.js +0 -41
- package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.d.ts +0 -2
- package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.js +0 -34
- package/dist/voice/handlers/utils/withErrorHandling.d.ts +0 -22
- package/dist/voice/handlers/utils/withErrorHandling.js +0 -38
- package/dist/voice/integrations/ApplicationNotFoundError.d.ts +0 -22
- package/dist/voice/integrations/ApplicationNotFoundError.js +0 -28
- package/dist/voice/integrations/createCreateContainer.d.ts +0 -4
- package/dist/voice/integrations/createCreateContainer.js +0 -76
- package/dist/voice/integrations/getSttConfig.js +0 -30
- package/dist/voice/integrations/index.js +0 -35
- package/dist/voice/integrations/types.d.ts +0 -29
- package/dist/voice/stt/AbstractSpeechToText.d.ts +0 -33
- package/dist/voice/stt/AbstractSpeechToText.js +0 -19
- package/dist/voice/stt/SpeechToTextFactory.d.ts +0 -9
- package/dist/voice/stt/SpeechToTextFactory.js +0 -43
- package/dist/voice/transcribeOnConnection.d.ts +0 -35
- package/dist/voice/transcribeOnConnection.js +0 -91
- package/dist/voice/tts/AbstractTextToSpeech.d.ts +0 -40
- package/dist/voice/tts/AbstractTextToSpeech.js +0 -50
- package/dist/voice/tts/TextToSpeechFactory.d.ts +0 -8
- package/dist/voice/tts/TextToSpeechFactory.js +0 -47
- package/dist/voice/tts/types.d.ts +0 -48
- package/dist/voice/tts/types.js +0 -2
- package/dist/voice/tts/utils/convertUlawToPCM16.js +0 -40
- package/dist/voice/tts/utils/createChunkedSynthesisStream.d.ts +0 -28
- package/dist/voice/tts/utils/createChunkedSynthesisStream.js +0 -78
- package/dist/voice/tts/utils/createErrorStream.d.ts +0 -21
- package/dist/voice/tts/utils/createErrorStream.js +0 -28
- package/dist/voice/tts/utils/index.d.ts +0 -23
- package/dist/voice/tts/utils/index.js +0 -39
- package/dist/voice/tts/utils/isSsml.d.ts +0 -20
- package/dist/voice/tts/utils/isSsml.js +0 -25
- package/dist/voice/tts/utils/streamToBuffer.d.ts +0 -20
- package/dist/voice/tts/utils/streamToBuffer.js +0 -60
- package/dist/voice/types/ari.d.ts +0 -43
- package/dist/voice/types/ari.js +0 -48
- package/dist/voice/types/index.d.ts +0 -20
- package/dist/voice/types/index.js +0 -36
- package/dist/voice/types/voice.d.ts +0 -67
- package/dist/voice/types/voice.js +0 -2
- package/dist/voice/utils/VoiceServiceClientConstructor.d.ts +0 -3
- package/dist/voice/utils/createExternalMediaConfig.d.ts +0 -12
- package/dist/voice/utils/createExternalMediaConfig.js +0 -37
- package/dist/voice/utils/createGetChannelVar.d.ts +0 -22
- package/dist/voice/utils/createGetChannelVar.js +0 -27
- package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +0 -22
- package/dist/voice/utils/createGetChannelVarWithoutThrow.js +0 -26
- package/dist/voice/utils/index.d.ts +0 -22
- package/dist/voice/utils/index.js +0 -38
- /package/dist/{events → records}/types.js +0 -0
- /package/dist/{voice/integrations → usage}/types.js +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
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.DEFAULT_RECORD_REGION = exports.NODE_EVENTS_QUEUE = void 0;
|
|
13
|
+
exports.natsFailedCallRecords = natsFailedCallRecords;
|
|
14
|
+
exports.failedCallEntries = failedCallEntries;
|
|
15
|
+
exports.createNodeCallEvents = createNodeCallEvents;
|
|
16
|
+
exports.subscribeNodeCallEvents = subscribeNodeCallEvents;
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Fonoster
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the MIT License (the "License");
|
|
24
|
+
* you may not use this file except in compliance with
|
|
25
|
+
* the License. You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* https://opensource.org/licenses/MIT
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
const common_1 = require("@fonoster/common");
|
|
36
|
+
const logger_1 = require("@fonoster/logger");
|
|
37
|
+
const nats_1 = require("nats");
|
|
38
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
39
|
+
const sc = (0, nats_1.StringCodec)();
|
|
40
|
+
/** One replica handles each node event (core NATS queue group). */
|
|
41
|
+
exports.NODE_EVENTS_QUEUE = "apiserver-roomr-events";
|
|
42
|
+
/** Where records go when the node reports no region (AppBridge's `callRecord.region` default). */
|
|
43
|
+
exports.DEFAULT_RECORD_REGION = "default";
|
|
44
|
+
/**
|
|
45
|
+
* Writes failed-call records through the region's record maintenance subject
|
|
46
|
+
* (`callrecord.<region>.maintenance`, op `failed_call`, served by the AppBridge replicas that hold
|
|
47
|
+
* the region's signing key): the control plane never holds it.
|
|
48
|
+
*/
|
|
49
|
+
function natsFailedCallRecords(nc, timeoutMs = 5000) {
|
|
50
|
+
return (record) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
var _a;
|
|
52
|
+
const region = record.region || exports.DEFAULT_RECORD_REGION;
|
|
53
|
+
const msg = yield nc.request(`callrecord.${region}.maintenance`, sc.encode(JSON.stringify({
|
|
54
|
+
op: "failed_call",
|
|
55
|
+
callRef: record.callRef,
|
|
56
|
+
workspaceRef: record.workspaceRef,
|
|
57
|
+
entries: record.entries,
|
|
58
|
+
reason: "unanswered outbound call",
|
|
59
|
+
actor: "control-plane"
|
|
60
|
+
})), { timeout: timeoutMs });
|
|
61
|
+
const reply = JSON.parse(sc.decode(msg.data));
|
|
62
|
+
if ((reply === null || reply === void 0 ? void 0 : reply.type) !== "ack")
|
|
63
|
+
throw new Error(`record not written: ${(_a = reply === null || reply === void 0 ? void 0 : reply.code) !== null && _a !== void 0 ? _a : "error"}`);
|
|
64
|
+
return reply;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** The minimal record's entries (as AppBridge wrote them for calls that never reached an app). */
|
|
68
|
+
function failedCallEntries(call, workspaceRef) {
|
|
69
|
+
const sip = call.sipStatus ? { sipStatus: call.sipStatus } : {};
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
type: "call.started",
|
|
73
|
+
direction: "outbound",
|
|
74
|
+
appRef: call.appRef,
|
|
75
|
+
workspaceRef,
|
|
76
|
+
from: call.from,
|
|
77
|
+
to: call.to
|
|
78
|
+
},
|
|
79
|
+
Object.assign({ type: "call.progress", status: call.reason }, sip),
|
|
80
|
+
Object.assign({ type: "call.failed", reason: call.reason }, sip)
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The control plane's reading of the Roomr nodes' call events (`roomr.events.<call_ref>`, one
|
|
85
|
+
* replica per event): what no AppBridge can report.
|
|
86
|
+
*
|
|
87
|
+
* - An outbound call the control plane placed (its `metadata.app_ref`) that ends unanswered
|
|
88
|
+
* (`call.ended` with `answered: false`: busy, no answer, rejected, node error, removed) reached
|
|
89
|
+
* no AppBridge: its minimal call record (call.started, call.progress, call.failed) is written
|
|
90
|
+
* (`records`) and `call.failed` goes to the fan-out (`intake`).
|
|
91
|
+
* - A call the node ended with cause `app_gone` lost its AppBridge: `lost` sends its `call.ended`
|
|
92
|
+
* (`appbridge-lost`) unless AppBridge ended the call itself.
|
|
93
|
+
*
|
|
94
|
+
* Events are best effort (media-control "Events are best effort while NATS is down"): one lost in
|
|
95
|
+
* an outage is never replayed; TrackCall's and the placement sweep's own sweeps close what it
|
|
96
|
+
* would have closed.
|
|
97
|
+
*/
|
|
98
|
+
function createNodeCallEvents(deps) {
|
|
99
|
+
return {
|
|
100
|
+
onEvent(subject, event) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a, _b, _c, _d, _e;
|
|
103
|
+
if ((event === null || event === void 0 ? void 0 : event.type) !== "call.ended")
|
|
104
|
+
return;
|
|
105
|
+
if (event.cause === "app_gone" && typeof event.call_ref === "string") {
|
|
106
|
+
yield ((_a = deps.lost) === null || _a === void 0 ? void 0 : _a.onAppGone(event.call_ref));
|
|
107
|
+
}
|
|
108
|
+
const call = common_1.Webhooks.unansweredOutboundCall(subject, event);
|
|
109
|
+
if (!call)
|
|
110
|
+
return;
|
|
111
|
+
const workspaceRef = (_c = (yield ((_b = deps.workspaceOfApp) === null || _b === void 0 ? void 0 : _b.call(deps, call.appRef).catch(() => undefined)))) !== null && _c !== void 0 ? _c : null;
|
|
112
|
+
yield Promise.all([
|
|
113
|
+
(_d = deps
|
|
114
|
+
.records) === null || _d === void 0 ? void 0 : _d.call(deps, {
|
|
115
|
+
callRef: call.callRef,
|
|
116
|
+
workspaceRef,
|
|
117
|
+
region: (_e = deps.regionOf) === null || _e === void 0 ? void 0 : _e.call(deps, call.nodeRef),
|
|
118
|
+
entries: failedCallEntries(call, workspaceRef)
|
|
119
|
+
}).catch((e) => logger.warn(`call ${call.callRef}: minimal record not written: ${e.message}`)),
|
|
120
|
+
deps.intake(common_1.Webhooks.unansweredCallFailed(call))
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Subscribes to the nodes' call events (one replica per event) and their heartbeats (each node's
|
|
128
|
+
* region); returns a stop function.
|
|
129
|
+
*/
|
|
130
|
+
function subscribeNodeCallEvents(nc, deps) {
|
|
131
|
+
const regions = new Map();
|
|
132
|
+
const handler = createNodeCallEvents(Object.assign(Object.assign({}, deps), { regionOf: (nodeRef) => regions.get(nodeRef) }));
|
|
133
|
+
const parse = (data) => {
|
|
134
|
+
try {
|
|
135
|
+
const v = JSON.parse(sc.decode(data));
|
|
136
|
+
return v && typeof v === "object"
|
|
137
|
+
? v
|
|
138
|
+
: undefined;
|
|
139
|
+
}
|
|
140
|
+
catch (_a) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const events = nc.subscribe(common_1.Webhooks.ROOMR_CALL_EVENTS_SUBJECT, {
|
|
145
|
+
queue: exports.NODE_EVENTS_QUEUE,
|
|
146
|
+
callback: (err, msg) => {
|
|
147
|
+
if (err)
|
|
148
|
+
return;
|
|
149
|
+
const event = parse(msg.data);
|
|
150
|
+
if (!event)
|
|
151
|
+
return;
|
|
152
|
+
handler
|
|
153
|
+
.onEvent(msg.subject, event)
|
|
154
|
+
.catch((e) => logger.warn(`node call event failed: ${e.message}`));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const beats = nc.subscribe("roomr.nodes.*.heartbeat", {
|
|
158
|
+
callback: (err, msg) => {
|
|
159
|
+
if (err)
|
|
160
|
+
return;
|
|
161
|
+
const beat = parse(msg.data);
|
|
162
|
+
if ((beat === null || beat === void 0 ? void 0 : beat.type) === "node.heartbeat" &&
|
|
163
|
+
typeof beat.node_ref === "string" &&
|
|
164
|
+
typeof beat.region === "string" &&
|
|
165
|
+
beat.region) {
|
|
166
|
+
// Bounded: nodes come and go (a new node_ref per start).
|
|
167
|
+
if (regions.size >= 1024 && !regions.has(beat.node_ref))
|
|
168
|
+
regions.clear();
|
|
169
|
+
regions.set(beat.node_ref, beat.region);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return () => {
|
|
174
|
+
events.unsubscribe();
|
|
175
|
+
beats.unsubscribe();
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { NatsConnection } from "nats";
|
|
2
|
+
/** The work queue that captures `webhooks.events` and its one durable consumer (ST-2). */
|
|
3
|
+
export declare const WEBHOOK_EVENTS_STREAM = "FONOSTER_WEBHOOKS";
|
|
4
|
+
export declare const WEBHOOK_EVENTS_DURABLE = "apiserver-webhooks";
|
|
5
|
+
export type WebhookFanoutConfig = {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** How often due deliveries (retries, adopted ones) are attempted. */
|
|
8
|
+
intervalMs: number;
|
|
9
|
+
/** How often the endpoint snapshot is reloaded (new or changed endpoints). */
|
|
10
|
+
refreshMs: number;
|
|
11
|
+
allowInsecureUrls?: boolean;
|
|
12
|
+
allowedDestinations?: string[];
|
|
13
|
+
/** How long a replica may hold an event before another one gets it (default 30 s). */
|
|
14
|
+
ackWaitMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* How long after a node's `app_gone` an AppBridge's own end of the call may still arrive before
|
|
17
|
+
* the control plane sends `call.ended` (appbridge-lost) (default 2 s; tests).
|
|
18
|
+
*/
|
|
19
|
+
appGoneGraceMs?: number;
|
|
20
|
+
/** Whether minimal records of unanswered outbound calls are written (default true). */
|
|
21
|
+
failedCallRecords?: boolean;
|
|
22
|
+
/** The session registry's bucket (default Sessions.SESSIONS_BUCKET; tests). */
|
|
23
|
+
sessionsBucket?: string;
|
|
24
|
+
};
|
|
25
|
+
/** The slice of the apiserver's Prisma client the fan-out uses (with field encryption). */
|
|
26
|
+
export type WebhookFanoutDb = any;
|
|
27
|
+
/**
|
|
28
|
+
* Event fan-out from the bus (add-workspace-webhooks 2.2, build log LO-B1, ST-2): consumes
|
|
29
|
+
* `webhooks.events` through a JetStream durable consumer (one replica per event), fills in the
|
|
30
|
+
* workspace from the app when a producer did not know it (and builds the events no AppBridge can
|
|
31
|
+
* send from the Roomr nodes' call events: call.failed of unanswered outbound calls and call.ended
|
|
32
|
+
* of calls whose AppBridge was lost), reloads that workspace's endpoints,
|
|
33
|
+
* stores one delivery per subscribed endpoint and only then acknowledges the event, attempts the
|
|
34
|
+
* new deliveries at once, and keeps retrying due deliveries (including ones adopted from replicas
|
|
35
|
+
* that died). An event redelivered after a replica died finds the deliveries it already made
|
|
36
|
+
* (their ids depend on the event and the endpoint), so it is delivered once.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runWebhookFanout(config: WebhookFanoutConfig, deps: {
|
|
39
|
+
nc: NatsConnection;
|
|
40
|
+
db: WebhookFanoutDb;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
stop(): Promise<void>;
|
|
43
|
+
runDue(): Promise<void>;
|
|
44
|
+
}>;
|
|
@@ -0,0 +1,202 @@
|
|
|
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.WEBHOOK_EVENTS_DURABLE = exports.WEBHOOK_EVENTS_STREAM = void 0;
|
|
13
|
+
exports.runWebhookFanout = runWebhookFanout;
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
16
|
+
* http://github.com/fonoster/fonoster
|
|
17
|
+
*
|
|
18
|
+
* This file is part of Fonoster
|
|
19
|
+
*
|
|
20
|
+
* Licensed under the MIT License (the "License");
|
|
21
|
+
* you may not use this file except in compliance with
|
|
22
|
+
* the License. You may obtain a copy of the License at
|
|
23
|
+
*
|
|
24
|
+
* https://opensource.org/licenses/MIT
|
|
25
|
+
*
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
* See the License for the specific language governing permissions and
|
|
30
|
+
* limitations under the License.
|
|
31
|
+
*/
|
|
32
|
+
const common_1 = require("@fonoster/common");
|
|
33
|
+
const logger_1 = require("@fonoster/logger");
|
|
34
|
+
const durableConsumer_1 = require("../core/durableConsumer");
|
|
35
|
+
const lostCalls_1 = require("./lostCalls");
|
|
36
|
+
const nodeCallEvents_1 = require("./nodeCallEvents");
|
|
37
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
|
+
/** The work queue that captures `webhooks.events` and its one durable consumer (ST-2). */
|
|
39
|
+
exports.WEBHOOK_EVENTS_STREAM = "FONOSTER_WEBHOOKS";
|
|
40
|
+
exports.WEBHOOK_EVENTS_DURABLE = "apiserver-webhooks";
|
|
41
|
+
/**
|
|
42
|
+
* Event fan-out from the bus (add-workspace-webhooks 2.2, build log LO-B1, ST-2): consumes
|
|
43
|
+
* `webhooks.events` through a JetStream durable consumer (one replica per event), fills in the
|
|
44
|
+
* workspace from the app when a producer did not know it (and builds the events no AppBridge can
|
|
45
|
+
* send from the Roomr nodes' call events: call.failed of unanswered outbound calls and call.ended
|
|
46
|
+
* of calls whose AppBridge was lost), reloads that workspace's endpoints,
|
|
47
|
+
* stores one delivery per subscribed endpoint and only then acknowledges the event, attempts the
|
|
48
|
+
* new deliveries at once, and keeps retrying due deliveries (including ones adopted from replicas
|
|
49
|
+
* that died). An event redelivered after a replica died finds the deliveries it already made
|
|
50
|
+
* (their ids depend on the event and the endpoint), so it is delivered once.
|
|
51
|
+
*/
|
|
52
|
+
function runWebhookFanout(config, deps) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const store = yield common_1.Webhooks.PrismaWebhookStore.open(deps.db, {
|
|
55
|
+
adoptOverdue: true
|
|
56
|
+
});
|
|
57
|
+
const dispatcher = new common_1.Webhooks.WebhookDispatcher({
|
|
58
|
+
store,
|
|
59
|
+
allowInsecureUrls: config.allowInsecureUrls,
|
|
60
|
+
allowedDestinations: config.allowedDestinations
|
|
61
|
+
});
|
|
62
|
+
let running;
|
|
63
|
+
const runDue = () => {
|
|
64
|
+
running !== null && running !== void 0 ? running : (running = (() => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
yield dispatcher.runDue();
|
|
67
|
+
yield store.flush();
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
logger.warn(`webhook delivery failed: ${e.message}`);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
running = undefined;
|
|
74
|
+
}
|
|
75
|
+
}))());
|
|
76
|
+
return running;
|
|
77
|
+
};
|
|
78
|
+
const apps = new Map();
|
|
79
|
+
const workspaceOfApp = (appRef) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a;
|
|
81
|
+
const hit = apps.get(appRef);
|
|
82
|
+
if (hit && Date.now() - hit.at < 60000)
|
|
83
|
+
return hit.workspace;
|
|
84
|
+
const app = yield deps.db.application.findUnique({
|
|
85
|
+
where: { ref: appRef },
|
|
86
|
+
select: { accessKeyId: true }
|
|
87
|
+
});
|
|
88
|
+
apps.set(appRef, { at: Date.now(), workspace: app === null || app === void 0 ? void 0 : app.accessKeyId });
|
|
89
|
+
return (_a = app === null || app === void 0 ? void 0 : app.accessKeyId) !== null && _a !== void 0 ? _a : undefined;
|
|
90
|
+
});
|
|
91
|
+
/** One event: resolves when its deliveries are stored. */
|
|
92
|
+
const intakeEvent = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const resolved = yield common_1.Webhooks.resolveWorkspace(event, workspaceOfApp);
|
|
94
|
+
if (!resolved)
|
|
95
|
+
return;
|
|
96
|
+
yield store.refreshEndpoints(resolved.workspaceRef);
|
|
97
|
+
const created = yield store.insertDeliveries(dispatcher.plan(resolved));
|
|
98
|
+
if (created.length)
|
|
99
|
+
void runDue();
|
|
100
|
+
});
|
|
101
|
+
/** One bus event: resolves when its deliveries are stored (then the event is acknowledged). */
|
|
102
|
+
const intake = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const event = common_1.Webhooks.parseBusEvent(data);
|
|
104
|
+
if (event)
|
|
105
|
+
yield intakeEvent(event);
|
|
106
|
+
});
|
|
107
|
+
// What no AppBridge can report, from the nodes' call events (one replica per event; the
|
|
108
|
+
// events' ids depend on the call, so each endpoint gets one delivery): call.failed (and the
|
|
109
|
+
// minimal record) of unanswered outbound calls, call.ended (appbridge-lost) of calls whose
|
|
110
|
+
// AppBridge died.
|
|
111
|
+
const lost = yield watchLostCalls(config, deps.nc, (event) => intakeEvent(event).catch((e) => logger.warn(`lost call fan-out failed: ${e.message}`)));
|
|
112
|
+
const stopNodeEvents = (0, nodeCallEvents_1.subscribeNodeCallEvents)(deps.nc, {
|
|
113
|
+
lost: lost === null || lost === void 0 ? void 0 : lost.calls,
|
|
114
|
+
intake: (event) => intakeEvent(event).catch((e) => logger.warn(`node call event fan-out failed: ${e.message}`)),
|
|
115
|
+
records: config.failedCallRecords === false
|
|
116
|
+
? undefined
|
|
117
|
+
: (0, nodeCallEvents_1.natsFailedCallRecords)(deps.nc),
|
|
118
|
+
workspaceOfApp
|
|
119
|
+
});
|
|
120
|
+
let unsubscribe;
|
|
121
|
+
try {
|
|
122
|
+
unsubscribe = yield (0, durableConsumer_1.consumeDurable)(deps.nc, {
|
|
123
|
+
stream: exports.WEBHOOK_EVENTS_STREAM,
|
|
124
|
+
subject: common_1.Webhooks.WEBHOOK_EVENTS_SUBJECT,
|
|
125
|
+
durable: exports.WEBHOOK_EVENTS_DURABLE,
|
|
126
|
+
ackWaitMs: config.ackWaitMs
|
|
127
|
+
}, intake, (e) => logger.warn(`webhook fan-out failed: ${e.message}`));
|
|
128
|
+
logger.info("webhooks: fan-out from webhooks.events (JetStream) is on");
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
// No JetStream, or the NATS user may not use the stream: one replica per event still, but an
|
|
132
|
+
// event in flight when a replica dies is lost.
|
|
133
|
+
logger.warn(`webhooks: JetStream consumer unavailable (${e.message}); falling back to a core NATS queue group`);
|
|
134
|
+
const sub = deps.nc.subscribe(common_1.Webhooks.WEBHOOK_EVENTS_SUBJECT, {
|
|
135
|
+
queue: "apiserver-webhooks",
|
|
136
|
+
callback: (err, msg) => {
|
|
137
|
+
if (err)
|
|
138
|
+
return;
|
|
139
|
+
intake(msg.data).catch((e2) => logger.warn(`webhook fan-out failed: ${e2.message}`));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
unsubscribe = () => sub.unsubscribe();
|
|
143
|
+
}
|
|
144
|
+
const timers = [
|
|
145
|
+
setInterval(() => void runDue(), config.intervalMs),
|
|
146
|
+
setInterval(() => store
|
|
147
|
+
.refresh()
|
|
148
|
+
.catch((e) => logger.warn(`webhook refresh failed: ${e.message}`)), config.refreshMs)
|
|
149
|
+
];
|
|
150
|
+
timers.forEach((t) => t.unref());
|
|
151
|
+
return {
|
|
152
|
+
runDue,
|
|
153
|
+
stop() {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
stopNodeEvents();
|
|
156
|
+
lost === null || lost === void 0 ? void 0 : lost.stop();
|
|
157
|
+
yield unsubscribe();
|
|
158
|
+
timers.forEach(clearInterval);
|
|
159
|
+
yield running;
|
|
160
|
+
yield store.flush().catch(() => undefined);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Follows the session registry's `calls.*` entries (AppBridge's) for the calls whose AppBridge
|
|
168
|
+
* dies: the node's `app_gone` then sends their call.ended. Undefined without the registry.
|
|
169
|
+
*/
|
|
170
|
+
function watchLostCalls(config, nc, emit) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const calls = (0, lostCalls_1.createLostCalls)({
|
|
173
|
+
emit: (event) => {
|
|
174
|
+
logger.warn(`call ${event.data.callRef}: its AppBridge is gone; call.ended (appbridge-lost)`);
|
|
175
|
+
return emit(event);
|
|
176
|
+
},
|
|
177
|
+
graceMs: config.appGoneGraceMs
|
|
178
|
+
});
|
|
179
|
+
let stopWatch;
|
|
180
|
+
try {
|
|
181
|
+
const kv = yield Promise.race([
|
|
182
|
+
common_1.Sessions.openSessions(nc, { bucket: config.sessionsBucket }),
|
|
183
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timed out")), 5000).unref())
|
|
184
|
+
]);
|
|
185
|
+
stopWatch = yield common_1.Sessions.watchSessions(kv, "calls", calls.onEntry);
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
logger.warn(`session registry unavailable; calls of lost AppBridge replicas get no call.ended: ${e.message}`);
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
const timer = setInterval(() => calls.forget(), 60000);
|
|
192
|
+
timer.unref();
|
|
193
|
+
return {
|
|
194
|
+
calls,
|
|
195
|
+
stop() {
|
|
196
|
+
clearInterval(timer);
|
|
197
|
+
stopWatch();
|
|
198
|
+
calls.stop();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "APIServer for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -12,48 +12,39 @@
|
|
|
12
12
|
"test": "test"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
15
|
+
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo && npm run generate:prisma",
|
|
16
16
|
"build": "tsc -b tsconfig.json",
|
|
17
|
-
"
|
|
18
|
-
"start:dev": "nodemon --exec tsx --watch src src/index.ts"
|
|
17
|
+
"generate:prisma": "prisma generate --schema schema.prisma"
|
|
19
18
|
},
|
|
20
19
|
"bin": {
|
|
21
|
-
"fonoster": "./dist/index.js"
|
|
20
|
+
"fonoster": "./dist/index.js",
|
|
21
|
+
"fonoster-region-hub-setup": "./dist/bin/regionHubSetup.js",
|
|
22
|
+
"fonoster-usage": "./dist/bin/usage.js"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@fonoster/
|
|
26
|
-
"@fonoster/
|
|
27
|
-
"@fonoster/common": "^0.
|
|
28
|
-
"@fonoster/identity": "^0.
|
|
29
|
-
"@fonoster/logger": "^0.
|
|
30
|
-
"@fonoster/sipnet": "^0.
|
|
31
|
-
"@fonoster/
|
|
32
|
-
"@
|
|
33
|
-
"@google-cloud/speech": "^6.6.0",
|
|
34
|
-
"@google-cloud/text-to-speech": "^5.3.0",
|
|
35
|
-
"@grpc/grpc-js": "~1.10.11",
|
|
36
|
-
"@influxdata/influxdb-client": "^1.33.2",
|
|
25
|
+
"@fonoster/authz": "^0.31.0",
|
|
26
|
+
"@fonoster/autopilot": "^0.31.0",
|
|
27
|
+
"@fonoster/callrecord": "^0.31.0",
|
|
28
|
+
"@fonoster/common": "^0.31.0",
|
|
29
|
+
"@fonoster/identity": "^0.31.0",
|
|
30
|
+
"@fonoster/logger": "^0.31.0",
|
|
31
|
+
"@fonoster/sipnet": "^0.31.0",
|
|
32
|
+
"@fonoster/types": "^0.31.0",
|
|
33
|
+
"@grpc/grpc-js": "~1.14.6",
|
|
37
34
|
"@prisma/client": "^6.19.1",
|
|
38
|
-
"@routr/common": "^2.
|
|
39
|
-
"@routr/sdk": "^2.
|
|
40
|
-
"ari-client": "^2.2.0",
|
|
41
|
-
"dotenv": "^16.6.1",
|
|
42
|
-
"elevenlabs": "^1.50.2",
|
|
35
|
+
"@routr/common": "^2.19.0",
|
|
36
|
+
"@routr/sdk": "^2.19.0",
|
|
43
37
|
"express": "^5.0.1",
|
|
44
38
|
"grpc-health-check": "^2.0.1",
|
|
45
39
|
"jsonwebtoken": "^9.0.2",
|
|
46
40
|
"jwt-decode": "^4.0.0",
|
|
47
|
-
"microsoft-cognitiveservices-speech-sdk": "^1.47.0",
|
|
48
41
|
"nanoid": "^3.3.11",
|
|
49
42
|
"nats": "^2.25.0",
|
|
43
|
+
"nkeys.js": "^1.1.0",
|
|
50
44
|
"pb-util": "^1.0.3",
|
|
51
|
-
"pick-port": "^2.2.0",
|
|
52
45
|
"prisma-field-encryption": "^1.6.0",
|
|
53
46
|
"uuid": "^11.0.3",
|
|
54
47
|
"validator": "^13.12.0",
|
|
55
|
-
"wait-port": "^1.1.0",
|
|
56
|
-
"wavefile": "^11.0.0",
|
|
57
48
|
"zod": "^3.23.8"
|
|
58
49
|
},
|
|
59
50
|
"files": [
|
|
@@ -70,14 +61,13 @@
|
|
|
70
61
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
71
62
|
},
|
|
72
63
|
"devDependencies": {
|
|
73
|
-
"@types/ari-client": "^2.2.12",
|
|
74
64
|
"@types/express": "^5.0.6",
|
|
75
65
|
"@types/jsonwebtoken": "^9.0.10",
|
|
76
66
|
"@types/uuid": "^10.0.0",
|
|
77
67
|
"@types/validator": "^13.15.10"
|
|
78
68
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
-
"
|
|
81
|
-
"
|
|
69
|
+
"gitHead": "f0a5102dddeea0f70f659234108805bc10690f2e",
|
|
70
|
+
"prisma": {
|
|
71
|
+
"seed": "tsx src/core/seed.ts"
|
|
82
72
|
}
|
|
83
73
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applicationWithEncodedStruct = applicationWithEncodedStruct;
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
6
|
-
* http://github.com/fonoster/fonoster
|
|
7
|
-
*
|
|
8
|
-
* This file is part of Fonoster
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the MIT License (the "License");
|
|
11
|
-
* you may not use this file except in compliance with
|
|
12
|
-
* the License. You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* https://opensource.org/licenses/MIT
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
const common_1 = require("@fonoster/common");
|
|
23
|
-
const common_2 = require("@fonoster/common");
|
|
24
|
-
const client_1 = require("@prisma/client");
|
|
25
|
-
const pb_util_1 = require("pb-util");
|
|
26
|
-
function applicationWithEncodedStruct(application) {
|
|
27
|
-
const encodeConfig = (property) => {
|
|
28
|
-
return (property === null || property === void 0 ? void 0 : property.config) ? pb_util_1.struct.encode(property.config) : null;
|
|
29
|
-
};
|
|
30
|
-
const result = Object.assign({}, application);
|
|
31
|
-
// Hide the default endpoint value for AUTOPILOT applications
|
|
32
|
-
if (application.type === client_1.ApplicationType.AUTOPILOT &&
|
|
33
|
-
application.endpoint === common_2.AUTOPILOT_SPECIAL_LOCAL_ADDRESS) {
|
|
34
|
-
result.endpoint = "";
|
|
35
|
-
}
|
|
36
|
-
if (application.textToSpeech) {
|
|
37
|
-
delete application.textToSpeech.credentials;
|
|
38
|
-
result.textToSpeech = Object.assign(Object.assign({}, application.textToSpeech), { config: encodeConfig(application.textToSpeech) });
|
|
39
|
-
}
|
|
40
|
-
if (application.speechToText) {
|
|
41
|
-
delete application.speechToText.credentials;
|
|
42
|
-
result.speechToText = Object.assign(Object.assign({}, application.speechToText), { config: encodeConfig(application.speechToText) });
|
|
43
|
-
}
|
|
44
|
-
if (application.intelligence) {
|
|
45
|
-
const intelligenceCopy = application.intelligence;
|
|
46
|
-
delete intelligenceCopy.credentials;
|
|
47
|
-
result.intelligence = Object.assign(Object.assign({}, intelligenceCopy), { config: encodeConfig(intelligenceCopy) });
|
|
48
|
-
}
|
|
49
|
-
return (0, common_1.datesMapper)(result);
|
|
50
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToApplicationData = convertToApplicationData;
|
|
4
|
-
const client_1 = require("@prisma/client");
|
|
5
|
-
const pb_util_1 = require("pb-util");
|
|
6
|
-
function convertToApplicationData(request) {
|
|
7
|
-
const type = request.type || client_1.ApplicationType.EXTERNAL;
|
|
8
|
-
const result = {
|
|
9
|
-
ref: request.ref, // Only for UpdateApplicationRequest
|
|
10
|
-
name: request.name,
|
|
11
|
-
type,
|
|
12
|
-
endpoint: request.endpoint
|
|
13
|
-
};
|
|
14
|
-
const createProperty = (property) => {
|
|
15
|
-
return property
|
|
16
|
-
? {
|
|
17
|
-
create: {
|
|
18
|
-
productRef: property.productRef,
|
|
19
|
-
credentials: property.credentials
|
|
20
|
-
? JSON.stringify(pb_util_1.struct.decode(property.credentials))
|
|
21
|
-
: undefined,
|
|
22
|
-
config: property.config ? pb_util_1.struct.decode(property.config) : null
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
: undefined;
|
|
26
|
-
};
|
|
27
|
-
if (request.textToSpeech) {
|
|
28
|
-
result.textToSpeech = createProperty(request.textToSpeech);
|
|
29
|
-
}
|
|
30
|
-
if (request.speechToText) {
|
|
31
|
-
result.speechToText = createProperty(request.speechToText);
|
|
32
|
-
}
|
|
33
|
-
if (request.intelligence) {
|
|
34
|
-
result.intelligence = createProperty(request.intelligence);
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
}
|