@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,96 @@
|
|
|
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 { Roomr } from "@fonoster/common";
|
|
20
|
+
import { NodeDirectory } from "./createNodeDirectory";
|
|
21
|
+
/** The calls.create message the Calls service publishes (CreateCall). */
|
|
22
|
+
export type OutboundCallRequest = {
|
|
23
|
+
ref: string;
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
appRef: string;
|
|
27
|
+
accessKeyId: string;
|
|
28
|
+
timeout?: number;
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
/** The call's region: only nodes whose heartbeat names it are eligible (unset: any node). */
|
|
31
|
+
region?: string;
|
|
32
|
+
};
|
|
33
|
+
/** Where API-originated calls are dialed: the SIP proxy and the digest identity it challenges. */
|
|
34
|
+
export type OutboundTarget = {
|
|
35
|
+
/** host:port of the SIP proxy (Routr); the INVITE goes there. */
|
|
36
|
+
proxy: string;
|
|
37
|
+
auth?: Roomr.SipAuth;
|
|
38
|
+
};
|
|
39
|
+
/** Nodes tried for one call before it fails with no_capacity. */
|
|
40
|
+
export declare const MAX_PLACEMENT_ATTEMPTS = 3;
|
|
41
|
+
/**
|
|
42
|
+
* Attempts of CreateCall on the same node when the outcome is unknown (a timeout or a connection
|
|
43
|
+
* lost after sending): the same call_ref and parameters, so the node dedupes it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SAME_NODE_ATTEMPTS = 3;
|
|
46
|
+
/** The PlacementError code for "no node took the call" (CreateCall's RESOURCE_EXHAUSTED). */
|
|
47
|
+
export declare const NO_CAPACITY = "no_capacity";
|
|
48
|
+
export declare class PlacementError extends Error {
|
|
49
|
+
readonly code: string;
|
|
50
|
+
constructor(code: string, message: string);
|
|
51
|
+
}
|
|
52
|
+
/** The Request-URI for a callee: a SIP URI as given, a number at the proxy's host. */
|
|
53
|
+
export declare function calleeUri(to: string, proxy: string): string;
|
|
54
|
+
/** The Roomr `metadata` of an API-originated call (AppBridge reads it at answer, 4.8). */
|
|
55
|
+
export declare function outboundMetadata(call: OutboundCallRequest): {
|
|
56
|
+
app_metadata?: string;
|
|
57
|
+
app_ref: string;
|
|
58
|
+
from: string;
|
|
59
|
+
to: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The CreateCall request for an API-originated call: dialed through the SIP proxy with the
|
|
63
|
+
* pass-through headers it routes on (`X-DOD-Number`, the caller id, picks the trunk; From is the
|
|
64
|
+
* node's own identity), `to.auth` for the proxy's challenge, and the app in `metadata.app_ref`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createCallRequest(call: OutboundCallRequest, outbound: OutboundTarget): Roomr.CreateCallRequest;
|
|
67
|
+
/**
|
|
68
|
+
* Places an API-originated call (CreateCall) on a Roomr node over gRPC, at the heartbeat's
|
|
69
|
+
* `control_addr` (control-plane "Call creation picks the least-loaded Roomr node"):
|
|
70
|
+
*
|
|
71
|
+
* - `CreateCall` with the call's ref on the highest-scoring eligible node. The node dials the
|
|
72
|
+
* callee, creates the room on answer and opens the call's control stream to AppBridge, which
|
|
73
|
+
* finds the app in `metadata.app_ref`; a busy, unanswered or rejected call creates no room and
|
|
74
|
+
* ends with the node's `call.ended` (the control plane's minimal record and call.failed).
|
|
75
|
+
* - `RESOURCE_EXHAUSTED` or `UNAVAILABLE` sends the call to the next node, up to
|
|
76
|
+
* MAX_PLACEMENT_ATTEMPTS nodes, then `no_capacity` (synchronously: the API caller gets it).
|
|
77
|
+
* - A timeout or a lost connection is ambiguous (the INVITE may be out): CreateCall is repeated on
|
|
78
|
+
* the same node with the same call_ref and parameters (the node dedupes it), never on another;
|
|
79
|
+
* still no answer after SAME_NODE_ATTEMPTS fails the call, and EndCall is sent in case the node
|
|
80
|
+
* did take it.
|
|
81
|
+
*
|
|
82
|
+
* `onAttempt` is told each node before anything is sent to it (the session registry's
|
|
83
|
+
* `placements.<callRef>` entry, written before the RPC so a sweep can end the call if this
|
|
84
|
+
* replica dies mid-placement).
|
|
85
|
+
*/
|
|
86
|
+
export declare function placeOutboundCall(deps: {
|
|
87
|
+
roomr: Roomr.RoomrCalls;
|
|
88
|
+
nodes: NodeDirectory;
|
|
89
|
+
outbound: OutboundTarget;
|
|
90
|
+
}, call: OutboundCallRequest, hooks?: {
|
|
91
|
+
onAttempt?: (nodeId: string, controlAddr: string) => unknown;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
nodeId: string;
|
|
94
|
+
roomRef: string;
|
|
95
|
+
callRef: string;
|
|
96
|
+
}>;
|
|
@@ -0,0 +1,172 @@
|
|
|
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.PlacementError = exports.NO_CAPACITY = exports.SAME_NODE_ATTEMPTS = exports.MAX_PLACEMENT_ATTEMPTS = void 0;
|
|
13
|
+
exports.calleeUri = calleeUri;
|
|
14
|
+
exports.outboundMetadata = outboundMetadata;
|
|
15
|
+
exports.createCallRequest = createCallRequest;
|
|
16
|
+
exports.placeOutboundCall = placeOutboundCall;
|
|
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 grpc_js_1 = require("@grpc/grpc-js");
|
|
37
|
+
/** Nodes tried for one call before it fails with no_capacity. */
|
|
38
|
+
exports.MAX_PLACEMENT_ATTEMPTS = 3;
|
|
39
|
+
/**
|
|
40
|
+
* Attempts of CreateCall on the same node when the outcome is unknown (a timeout or a connection
|
|
41
|
+
* lost after sending): the same call_ref and parameters, so the node dedupes it.
|
|
42
|
+
*/
|
|
43
|
+
exports.SAME_NODE_ATTEMPTS = 3;
|
|
44
|
+
/** The PlacementError code for "no node took the call" (CreateCall's RESOURCE_EXHAUSTED). */
|
|
45
|
+
exports.NO_CAPACITY = "no_capacity";
|
|
46
|
+
class PlacementError extends Error {
|
|
47
|
+
constructor(code, message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.name = "PlacementError";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.PlacementError = PlacementError;
|
|
54
|
+
/**
|
|
55
|
+
* A node's refusal that sends the call to another node (control-plane "Call creation picks the
|
|
56
|
+
* least-loaded Roomr node"): the node is full (RESOURCE_EXHAUSTED) or not there (UNAVAILABLE).
|
|
57
|
+
*/
|
|
58
|
+
const isRefusal = (e) => e instanceof common_1.Roomr.RoomrError &&
|
|
59
|
+
(e.code === grpc_js_1.status.RESOURCE_EXHAUSTED || e.code === grpc_js_1.status.UNAVAILABLE);
|
|
60
|
+
/** An outcome the caller cannot know (the request may have been served): retry the same node. */
|
|
61
|
+
const isAmbiguous = (e) => !(e instanceof common_1.Roomr.RoomrError) ||
|
|
62
|
+
e.code === grpc_js_1.status.DEADLINE_EXCEEDED ||
|
|
63
|
+
e.code === grpc_js_1.status.CANCELLED ||
|
|
64
|
+
e.code === grpc_js_1.status.UNKNOWN;
|
|
65
|
+
/** The PlacementError for a failed RPC: the API maps these codes to its own status codes. */
|
|
66
|
+
function placementError(what, nodeId, e) {
|
|
67
|
+
var _a;
|
|
68
|
+
const code = e instanceof common_1.Roomr.RoomrError
|
|
69
|
+
? ((_a = {
|
|
70
|
+
[grpc_js_1.status.RESOURCE_EXHAUSTED]: exports.NO_CAPACITY,
|
|
71
|
+
[grpc_js_1.status.INVALID_ARGUMENT]: "invalid_argument",
|
|
72
|
+
[grpc_js_1.status.ALREADY_EXISTS]: "already_exists"
|
|
73
|
+
}[e.code]) !== null && _a !== void 0 ? _a : "unavailable")
|
|
74
|
+
: "unavailable";
|
|
75
|
+
return new PlacementError(code, `${what} failed on ${nodeId}: ${e.message}`);
|
|
76
|
+
}
|
|
77
|
+
/** Runs `rpc`, again on the same node while its outcome is ambiguous. */
|
|
78
|
+
function sameNode(rpc) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
for (let attempt = 1;; attempt++) {
|
|
81
|
+
try {
|
|
82
|
+
return yield rpc();
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if (attempt >= exports.SAME_NODE_ATTEMPTS || !isAmbiguous(e))
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** The Request-URI for a callee: a SIP URI as given, a number at the proxy's host. */
|
|
92
|
+
function calleeUri(to, proxy) {
|
|
93
|
+
if (/^sips?:/i.test(to))
|
|
94
|
+
return to;
|
|
95
|
+
const host = proxy.replace(/:\d+$/, "");
|
|
96
|
+
return `sip:${to}@${host}`;
|
|
97
|
+
}
|
|
98
|
+
/** The Roomr `metadata` of an API-originated call (AppBridge reads it at answer, 4.8). */
|
|
99
|
+
function outboundMetadata(call) {
|
|
100
|
+
return Object.assign({ app_ref: call.appRef, from: call.from, to: call.to }, (call.metadata && Object.keys(call.metadata).length
|
|
101
|
+
? { app_metadata: JSON.stringify(call.metadata) }
|
|
102
|
+
: {}));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The CreateCall request for an API-originated call: dialed through the SIP proxy with the
|
|
106
|
+
* pass-through headers it routes on (`X-DOD-Number`, the caller id, picks the trunk; From is the
|
|
107
|
+
* node's own identity), `to.auth` for the proxy's challenge, and the app in `metadata.app_ref`.
|
|
108
|
+
*/
|
|
109
|
+
function createCallRequest(call, outbound) {
|
|
110
|
+
return Object.assign(Object.assign({ callRef: call.ref, to: Object.assign({ uri: calleeUri(call.to, outbound.proxy), proxy: outbound.proxy, headers: {
|
|
111
|
+
"X-DOD-Number": call.from,
|
|
112
|
+
"X-Call-Ref": call.ref,
|
|
113
|
+
"X-Access-Key-Id": call.accessKeyId,
|
|
114
|
+
"X-Is-Api-Originated-Type": "true"
|
|
115
|
+
} }, (outbound.auth ? { auth: outbound.auth } : {})) }, (call.timeout ? { ringTimeoutS: call.timeout } : {})), { metadata: outboundMetadata(call) });
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Places an API-originated call (CreateCall) on a Roomr node over gRPC, at the heartbeat's
|
|
119
|
+
* `control_addr` (control-plane "Call creation picks the least-loaded Roomr node"):
|
|
120
|
+
*
|
|
121
|
+
* - `CreateCall` with the call's ref on the highest-scoring eligible node. The node dials the
|
|
122
|
+
* callee, creates the room on answer and opens the call's control stream to AppBridge, which
|
|
123
|
+
* finds the app in `metadata.app_ref`; a busy, unanswered or rejected call creates no room and
|
|
124
|
+
* ends with the node's `call.ended` (the control plane's minimal record and call.failed).
|
|
125
|
+
* - `RESOURCE_EXHAUSTED` or `UNAVAILABLE` sends the call to the next node, up to
|
|
126
|
+
* MAX_PLACEMENT_ATTEMPTS nodes, then `no_capacity` (synchronously: the API caller gets it).
|
|
127
|
+
* - A timeout or a lost connection is ambiguous (the INVITE may be out): CreateCall is repeated on
|
|
128
|
+
* the same node with the same call_ref and parameters (the node dedupes it), never on another;
|
|
129
|
+
* still no answer after SAME_NODE_ATTEMPTS fails the call, and EndCall is sent in case the node
|
|
130
|
+
* did take it.
|
|
131
|
+
*
|
|
132
|
+
* `onAttempt` is told each node before anything is sent to it (the session registry's
|
|
133
|
+
* `placements.<callRef>` entry, written before the RPC so a sweep can end the call if this
|
|
134
|
+
* replica dies mid-placement).
|
|
135
|
+
*/
|
|
136
|
+
function placeOutboundCall(deps_1, call_1) {
|
|
137
|
+
return __awaiter(this, arguments, void 0, function* (deps, call, hooks = {}) {
|
|
138
|
+
var _a;
|
|
139
|
+
const { roomr, nodes } = deps;
|
|
140
|
+
const request = createCallRequest(call, deps.outbound);
|
|
141
|
+
const tried = new Set();
|
|
142
|
+
while (tried.size < exports.MAX_PLACEMENT_ATTEMPTS) {
|
|
143
|
+
const nodeId = nodes.pick(tried, call.region);
|
|
144
|
+
if (!nodeId)
|
|
145
|
+
break;
|
|
146
|
+
tried.add(nodeId);
|
|
147
|
+
const addr = nodes.addressOf(nodeId);
|
|
148
|
+
yield ((_a = hooks.onAttempt) === null || _a === void 0 ? void 0 : _a.call(hooks, nodeId, addr));
|
|
149
|
+
try {
|
|
150
|
+
const placed = yield sameNode(() => roomr.createCall(addr, request));
|
|
151
|
+
nodes.placed(nodeId);
|
|
152
|
+
return { nodeId, roomRef: placed.roomRef, callRef: placed.callRef };
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
if (isRefusal(e)) {
|
|
156
|
+
nodes.refused(nodeId, e.code === grpc_js_1.status.UNAVAILABLE
|
|
157
|
+
? "unavailable"
|
|
158
|
+
: "at_capacity");
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// Anything else fails the call: only a refusal says the node did nothing. After an
|
|
162
|
+
// ambiguous outcome the node may hold the call; end it (the API caller gets an error).
|
|
163
|
+
if (isAmbiguous(e))
|
|
164
|
+
yield roomr.endCall(addr, { callRef: call.ref }).catch(() => undefined);
|
|
165
|
+
throw placementError("CreateCall", nodeId, e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
throw new PlacementError(exports.NO_CAPACITY, tried.size === 0
|
|
169
|
+
? "no Roomr node has room for the call"
|
|
170
|
+
: `no Roomr node took the call (tried ${[...tried].join(", ")})`);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { Roomr } from "@fonoster/common";
|
|
20
|
+
import type { KV } from "nats";
|
|
21
|
+
/**
|
|
22
|
+
* A placement entry older than this was left by a replica that died mid-placement: every step of
|
|
23
|
+
* a placement rewrites its entry well within it (CreateCall and its retries on one node).
|
|
24
|
+
*/
|
|
25
|
+
export declare const PLACEMENT_STALE_MS = 10000;
|
|
26
|
+
/**
|
|
27
|
+
* Placements in the session registry (control-plane "Outbound calls are registered before they
|
|
28
|
+
* are placed"): before CreateCall reaches a node, the placing replica writes
|
|
29
|
+
* `placements.<callRef>` = { callRef, nodeRef, controlAddr }, rewrites it when it moves to
|
|
30
|
+
* another node, and deletes it once CreateCall has answered (or the placement failed). Every
|
|
31
|
+
* replica follows the entries; one that sits unchanged for `staleMs` belongs to a replica that
|
|
32
|
+
* died mid-placement (its API caller got no answer, so the call must not go on). The sweep
|
|
33
|
+
* removes it, and reports the call FAILED (`failed`), when its node is down (no fresh heartbeat,
|
|
34
|
+
* or `node.down`) or answers `NOT_FOUND` for the call; a call the node does hold is ended
|
|
35
|
+
* (EndCall; its `call.ended` then follows on `roomr.events.<call_ref>`). Registry writes are best
|
|
36
|
+
* effort and never fail a placement. Nothing is replayed: a placement whose events were lost is
|
|
37
|
+
* closed by this sweep or by TrackCall's own node-down and maximum-duration sweeps.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPlacementSweep(deps: {
|
|
40
|
+
kv: KV;
|
|
41
|
+
roomr: Roomr.RoomrCalls;
|
|
42
|
+
/** Whether the node is live (fresh heartbeat); a down node's placements fail at once. */
|
|
43
|
+
nodeUp?: (nodeRef: string) => boolean;
|
|
44
|
+
/** The call never got placed: its record ends FAILED (TrackCall). */
|
|
45
|
+
failed?: (callRef: string) => unknown;
|
|
46
|
+
staleMs?: number;
|
|
47
|
+
now?: () => number;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
/** Writes (or rewrites) the call's entry before CreateCall reaches `nodeRef`. */
|
|
50
|
+
placing(callRef: string, nodeRef: string, controlAddr: string): Promise<void>;
|
|
51
|
+
/** The placement is over (placed or failed): its entry goes. */
|
|
52
|
+
placed(callRef: string): Promise<void>;
|
|
53
|
+
/** Ends the calls of stale entries now (tests; the timer runs it too). */
|
|
54
|
+
sweep: () => Promise<string[]>;
|
|
55
|
+
stop(): void;
|
|
56
|
+
}>;
|
|
@@ -0,0 +1,127 @@
|
|
|
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.PLACEMENT_STALE_MS = void 0;
|
|
13
|
+
exports.createPlacementSweep = createPlacementSweep;
|
|
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 grpc_js_1 = require("@grpc/grpc-js");
|
|
35
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
|
+
/**
|
|
37
|
+
* A placement entry older than this was left by a replica that died mid-placement: every step of
|
|
38
|
+
* a placement rewrites its entry well within it (CreateCall and its retries on one node).
|
|
39
|
+
*/
|
|
40
|
+
exports.PLACEMENT_STALE_MS = 10000;
|
|
41
|
+
/** How often each replica looks for stale placements. */
|
|
42
|
+
const SWEEP_EVERY_MS = 2000;
|
|
43
|
+
/**
|
|
44
|
+
* Placements in the session registry (control-plane "Outbound calls are registered before they
|
|
45
|
+
* are placed"): before CreateCall reaches a node, the placing replica writes
|
|
46
|
+
* `placements.<callRef>` = { callRef, nodeRef, controlAddr }, rewrites it when it moves to
|
|
47
|
+
* another node, and deletes it once CreateCall has answered (or the placement failed). Every
|
|
48
|
+
* replica follows the entries; one that sits unchanged for `staleMs` belongs to a replica that
|
|
49
|
+
* died mid-placement (its API caller got no answer, so the call must not go on). The sweep
|
|
50
|
+
* removes it, and reports the call FAILED (`failed`), when its node is down (no fresh heartbeat,
|
|
51
|
+
* or `node.down`) or answers `NOT_FOUND` for the call; a call the node does hold is ended
|
|
52
|
+
* (EndCall; its `call.ended` then follows on `roomr.events.<call_ref>`). Registry writes are best
|
|
53
|
+
* effort and never fail a placement. Nothing is replayed: a placement whose events were lost is
|
|
54
|
+
* closed by this sweep or by TrackCall's own node-down and maximum-duration sweeps.
|
|
55
|
+
*/
|
|
56
|
+
function createPlacementSweep(deps) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
const staleMs = (_a = deps.staleMs) !== null && _a !== void 0 ? _a : exports.PLACEMENT_STALE_MS;
|
|
60
|
+
const now = (_b = deps.now) !== null && _b !== void 0 ? _b : Date.now;
|
|
61
|
+
const seen = new Map();
|
|
62
|
+
const key = (ref) => common_1.Sessions.sessionKey("placements", ref);
|
|
63
|
+
const write = (ref, value) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
if (value)
|
|
66
|
+
yield deps.kv.put(key(ref), JSON.stringify(value));
|
|
67
|
+
else
|
|
68
|
+
yield deps.kv.delete(key(ref));
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
logger.warn(`placement entry ${ref} not written: ${e.message}`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const stopWatch = yield common_1.Sessions.watchSessions(deps.kv, "placements", (e) => {
|
|
75
|
+
if (e.value)
|
|
76
|
+
seen.set(e.id, { value: e.value, seenAt: now() });
|
|
77
|
+
else
|
|
78
|
+
seen.delete(e.id);
|
|
79
|
+
});
|
|
80
|
+
const sweep = () => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
var _a, _b, _c, _d, _e;
|
|
82
|
+
const at = now();
|
|
83
|
+
const ended = [];
|
|
84
|
+
for (const [id, p] of [...seen]) {
|
|
85
|
+
if (at - p.seenAt <= staleMs)
|
|
86
|
+
continue;
|
|
87
|
+
seen.delete(id);
|
|
88
|
+
const callRef = String((_a = p.value.callRef) !== null && _a !== void 0 ? _a : id);
|
|
89
|
+
const addr = String((_b = p.value.controlAddr) !== null && _b !== void 0 ? _b : "");
|
|
90
|
+
const nodeRef = String((_c = p.value.nodeRef) !== null && _c !== void 0 ? _c : "");
|
|
91
|
+
logger.warn(`outbound call ${callRef} was left mid-placement on ${nodeRef}; sweeping it`);
|
|
92
|
+
let notFound = !addr || ((_d = deps.nodeUp) === null || _d === void 0 ? void 0 : _d.call(deps, nodeRef)) === false;
|
|
93
|
+
if (!notFound) {
|
|
94
|
+
notFound = yield deps.roomr.endCall(addr, { callRef }).then(() => false, (e) => e instanceof common_1.Roomr.RoomrError && e.code === grpc_js_1.status.NOT_FOUND);
|
|
95
|
+
}
|
|
96
|
+
if (notFound)
|
|
97
|
+
yield ((_e = deps.failed) === null || _e === void 0 ? void 0 : _e.call(deps, callRef));
|
|
98
|
+
yield write(id);
|
|
99
|
+
ended.push(callRef);
|
|
100
|
+
}
|
|
101
|
+
return ended;
|
|
102
|
+
});
|
|
103
|
+
const timer = setInterval(() => void sweep(), SWEEP_EVERY_MS);
|
|
104
|
+
(_c = timer.unref) === null || _c === void 0 ? void 0 : _c.call(timer);
|
|
105
|
+
return {
|
|
106
|
+
/** Writes (or rewrites) the call's entry before CreateCall reaches `nodeRef`. */
|
|
107
|
+
placing(callRef, nodeRef, controlAddr) {
|
|
108
|
+
return write(callRef, {
|
|
109
|
+
callRef,
|
|
110
|
+
nodeRef,
|
|
111
|
+
controlAddr,
|
|
112
|
+
at: new Date().toISOString()
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
/** The placement is over (placed or failed): its entry goes. */
|
|
116
|
+
placed(callRef) {
|
|
117
|
+
return write(callRef);
|
|
118
|
+
},
|
|
119
|
+
/** Ends the calls of stale entries now (tests; the timer runs it too). */
|
|
120
|
+
sweep,
|
|
121
|
+
stop() {
|
|
122
|
+
clearInterval(timer);
|
|
123
|
+
stopWatch();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 { NatsTarget, Roomr } from "@fonoster/common";
|
|
20
|
+
import { NatsConnection } from "nats";
|
|
21
|
+
import { OutboundTarget } from "./placeOutboundCall";
|
|
22
|
+
/**
|
|
23
|
+
* The control plane's part of a call's status events for TrackCall: TRYING when placement starts,
|
|
24
|
+
* `{ref, node_ref}` once a node took CreateCall (TrackCall then follows that node's heartbeats), and FAILED when placement fails. Everything after that (call.ringing,
|
|
25
|
+
* call.answered, call.ended) comes from the Roomr node on `roomr.events.<ref>`, so the statuses
|
|
26
|
+
* keep flowing to every replica's TrackCall even if this replica dies.
|
|
27
|
+
*/
|
|
28
|
+
export declare function callTracker(nc: NatsConnection, ref: string): {
|
|
29
|
+
placed(nodeId: string): void;
|
|
30
|
+
failed(): void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Serves `calls.create` (a request from CreateCall) by placing each call on a Roomr node with
|
|
34
|
+
* Roomr's CreateCall over gRPC (placeOutboundCall); nodes come from their heartbeats on
|
|
35
|
+
* `roomr.nodes.<node_ref>.heartbeat`. The reply comes once the node accepted CreateCall (`{type: "ack",
|
|
36
|
+
* ref, nodeId}`), or with `{type: "error", code, message}` (`no_capacity` when no node took it),
|
|
37
|
+
* so CreateCall fails at once instead of TrackCall reporting FAILED later. While a call is being
|
|
38
|
+
* placed its `placements.<ref>` registry entry names the node; a replica that dies mid-placement
|
|
39
|
+
* leaves it behind and the sweep (every replica) ends the call. Returns a stop function.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runOutboundCalls(config: {
|
|
42
|
+
natsUrl?: NatsTarget;
|
|
43
|
+
/** The session registry's bucket (default Sessions.SESSIONS_BUCKET; tests). */
|
|
44
|
+
sessionsBucket?: string;
|
|
45
|
+
nc?: NatsConnection;
|
|
46
|
+
/** Roomr calls (default: a channel pool over plaintext gRPC). */
|
|
47
|
+
roomr?: Roomr.RoomrCalls;
|
|
48
|
+
/** Where calls are dialed (default: fonoster.yaml's routr). */
|
|
49
|
+
outbound?: OutboundTarget;
|
|
50
|
+
/** How long a placement entry may sit unchanged before the sweep ends its call (tests). */
|
|
51
|
+
placementStaleMs?: number;
|
|
52
|
+
}): Promise<() => Promise<void>>;
|