@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,330 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UNREDACTED_ROLES = void 0;
|
|
16
|
+
exports.createRecordsRouter = createRecordsRouter;
|
|
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 callrecord_1 = require("@fonoster/callrecord");
|
|
36
|
+
const logger_1 = require("@fonoster/logger");
|
|
37
|
+
const express_1 = __importDefault(require("express"));
|
|
38
|
+
const httpAuth_1 = require("../regions/httpAuth");
|
|
39
|
+
const relayHttp_1 = require("../regions/relayHttp");
|
|
40
|
+
const createSearchRecords_1 = require("./createSearchRecords");
|
|
41
|
+
const maintenance_1 = require("./maintenance");
|
|
42
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
43
|
+
/** Roles that may read unredacted originals and delete or erase records (V5, V3). */
|
|
44
|
+
exports.UNREDACTED_ROLES = ["WORKSPACE_OWNER", "WORKSPACE_ADMIN"];
|
|
45
|
+
/**
|
|
46
|
+
* The records API (call-record "Records are available through the API and the dashboard",
|
|
47
|
+
* tasks 5.1 and 4.2), on the apiserver's HTTP port so recordings download as files:
|
|
48
|
+
*
|
|
49
|
+
* GET /api/records search: after, before, number, appRef, status
|
|
50
|
+
* GET /api/records/:callRef the record (redacted; ?original=true, ?version=n)
|
|
51
|
+
* GET /api/records/:callRef/recording the recording (WAV)
|
|
52
|
+
* GET /api/records/:callRef/audit deletions of this record (owner, admin)
|
|
53
|
+
* DELETE /api/records/:callRef erase the call (owner, admin)
|
|
54
|
+
* DELETE /api/records/:callRef/parts/:part delete one part (owner, admin)
|
|
55
|
+
* GET /api/records/retention the workspace's retention policies
|
|
56
|
+
* PUT /api/records/retention {part, days} sets one; days null removes it
|
|
57
|
+
*
|
|
58
|
+
* Every request carries `Authorization: Bearer <access token>` and the workspace in
|
|
59
|
+
* `x-accesskey-id`; only that workspace's records are visible.
|
|
60
|
+
*/
|
|
61
|
+
function createRecordsRouter(deps) {
|
|
62
|
+
var _a;
|
|
63
|
+
const router = express_1.default.Router();
|
|
64
|
+
const search = (0, createSearchRecords_1.createSearchRecords)(deps.db);
|
|
65
|
+
const maintain = (0, maintenance_1.createRecordMaintenance)(deps.db, deps.maintenance);
|
|
66
|
+
// Access tokens only (id, refresh and invite tokens are refused), from the configured issuer
|
|
67
|
+
// and for the configured audience; the same middleware guards /api/regions.
|
|
68
|
+
const auth = (0, httpAuth_1.createHttpAuth)(deps.identityPublicKey, (_a = deps.identityTokenOptions) !== null && _a !== void 0 ? _a : {});
|
|
69
|
+
const caller = (res) => res.locals.caller;
|
|
70
|
+
const privileged = (res) => exports.UNREDACTED_ROLES.includes(caller(res).role);
|
|
71
|
+
const handle = (fn) => (req, res) => fn(req, res).catch((e) => {
|
|
72
|
+
if (e instanceof maintenance_1.RecordMaintenanceError) {
|
|
73
|
+
const status = e.code === "not_found"
|
|
74
|
+
? 404
|
|
75
|
+
: e.code === "gone"
|
|
76
|
+
? 410
|
|
77
|
+
: e.code === "bad_request"
|
|
78
|
+
? 400
|
|
79
|
+
: 502;
|
|
80
|
+
return res.status(status).json({ error: e.code, message: e.message });
|
|
81
|
+
}
|
|
82
|
+
logger.error(`records API: ${e.message}`);
|
|
83
|
+
res.status(500).json({ error: "internal" });
|
|
84
|
+
});
|
|
85
|
+
router.use(express_1.default.json());
|
|
86
|
+
router.use(auth);
|
|
87
|
+
const view = (row) => {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
return ({
|
|
90
|
+
callRef: row.callRef,
|
|
91
|
+
appRef: row.appRef,
|
|
92
|
+
from: row.fromNumber,
|
|
93
|
+
to: row.toNumber,
|
|
94
|
+
direction: row.direction,
|
|
95
|
+
status: row.status,
|
|
96
|
+
endReason: row.endReason,
|
|
97
|
+
failureReason: row.failureReason,
|
|
98
|
+
sipStatus: row.sipStatus,
|
|
99
|
+
amdStatus: (_a = row.amdStatus) !== null && _a !== void 0 ? _a : null,
|
|
100
|
+
startedAt: row.startedAt.toISOString(),
|
|
101
|
+
endedAt: (_c = (_b = row.endedAt) === null || _b === void 0 ? void 0 : _b.toISOString()) !== null && _c !== void 0 ? _c : null,
|
|
102
|
+
durationSeconds: row.durationSeconds,
|
|
103
|
+
region: row.region,
|
|
104
|
+
version: row.version,
|
|
105
|
+
size: Number(row.size),
|
|
106
|
+
parts: row.parts
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
router.get("/", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const q = req.query;
|
|
111
|
+
const result = yield search(caller(res).accessKeyId, {
|
|
112
|
+
after: q.after,
|
|
113
|
+
before: q.before,
|
|
114
|
+
number: q.number,
|
|
115
|
+
appRef: q.appRef,
|
|
116
|
+
direction: q.direction,
|
|
117
|
+
status: q.status,
|
|
118
|
+
pageSize: q.pageSize ? Number(q.pageSize) : undefined,
|
|
119
|
+
pageToken: q.pageToken
|
|
120
|
+
});
|
|
121
|
+
res.json({
|
|
122
|
+
items: result.items.map(view),
|
|
123
|
+
nextPageToken: result.nextPageToken
|
|
124
|
+
});
|
|
125
|
+
})));
|
|
126
|
+
router.get("/retention", handle((_req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const policies = yield deps.db.callRecordRetention.findMany({
|
|
128
|
+
where: { accessKeyId: caller(res).accessKeyId }
|
|
129
|
+
});
|
|
130
|
+
res.json({
|
|
131
|
+
items: policies.map((p) => ({ part: p.part, days: p.days }))
|
|
132
|
+
});
|
|
133
|
+
})));
|
|
134
|
+
router.put("/retention", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
if (!privileged(res))
|
|
137
|
+
return res.status(403).json({ error: "permission_denied" });
|
|
138
|
+
const { part, days } = (_a = req.body) !== null && _a !== void 0 ? _a : {};
|
|
139
|
+
if (!callrecord_1.RECORD_PARTS.includes(part))
|
|
140
|
+
return res.status(400).json({
|
|
141
|
+
error: "bad_request",
|
|
142
|
+
message: `part must be one of ${callrecord_1.RECORD_PARTS.join(", ")}`
|
|
143
|
+
});
|
|
144
|
+
const accessKeyId = caller(res).accessKeyId;
|
|
145
|
+
if (days === null || days === undefined) {
|
|
146
|
+
yield deps.db.callRecordRetention.deleteMany({
|
|
147
|
+
where: { accessKeyId, part }
|
|
148
|
+
});
|
|
149
|
+
(_b = deps.onConfigChange) === null || _b === void 0 ? void 0 : _b.call(deps, accessKeyId);
|
|
150
|
+
return res.json({ part, days: null });
|
|
151
|
+
}
|
|
152
|
+
if (!Number.isInteger(days) || days < 1)
|
|
153
|
+
return res
|
|
154
|
+
.status(400)
|
|
155
|
+
.json({ error: "bad_request", message: "days must be ≥ 1" });
|
|
156
|
+
yield deps.db.callRecordRetention.upsert({
|
|
157
|
+
where: { accessKeyId_part: { accessKeyId, part } },
|
|
158
|
+
create: { accessKeyId, part, days },
|
|
159
|
+
update: { days }
|
|
160
|
+
});
|
|
161
|
+
(_c = deps.onConfigChange) === null || _c === void 0 ? void 0 : _c.call(deps, accessKeyId);
|
|
162
|
+
res.json({ part, days });
|
|
163
|
+
})));
|
|
164
|
+
/** The row of a record in the caller's workspace, or a 404 / 410 already sent. */
|
|
165
|
+
const rowOf = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const row = yield deps.db.callRecord.findUnique({
|
|
167
|
+
where: { callRef: String(req.params.callRef) }
|
|
168
|
+
});
|
|
169
|
+
if (!row || row.accessKeyId !== caller(res).accessKeyId) {
|
|
170
|
+
res.status(404).json({ error: "not_found" });
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
if (row.erasedAt) {
|
|
174
|
+
res.status(410).json({ error: "erased" });
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
return row;
|
|
178
|
+
});
|
|
179
|
+
/**
|
|
180
|
+
* For a private workspace: relays the content from its cell and returns true (the response is
|
|
181
|
+
* sent). Offline regions answer 503 `region_offline`.
|
|
182
|
+
*/
|
|
183
|
+
const relayed = (req, res, row, op, part) => __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
const regionRef = yield ((_a = deps.relay) === null || _a === void 0 ? void 0 : _a.regionOf(caller(res).accessKeyId));
|
|
186
|
+
// Only records indexed from that region live there (PR-14: same mechanism for public ones).
|
|
187
|
+
if (!regionRef || (row.region && row.region !== regionRef))
|
|
188
|
+
return false;
|
|
189
|
+
const original = req.query.original === "true";
|
|
190
|
+
if (original && !privileged(res)) {
|
|
191
|
+
res.status(403).json({
|
|
192
|
+
error: "permission_denied",
|
|
193
|
+
message: "the unredacted original needs the owner or admin role"
|
|
194
|
+
});
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
if (!((_b = deps.relay) === null || _b === void 0 ? void 0 : _b.client)) {
|
|
198
|
+
res.status(503).json({
|
|
199
|
+
error: "region_offline",
|
|
200
|
+
message: "the region link is not configured on this control plane"
|
|
201
|
+
});
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
yield (0, relayHttp_1.relayToResponse)(deps.relay.client, regionRef, {
|
|
205
|
+
userRef: caller(res).actor,
|
|
206
|
+
workspaceRef: caller(res).accessKeyId,
|
|
207
|
+
op,
|
|
208
|
+
callRef: row.callRef,
|
|
209
|
+
part,
|
|
210
|
+
original,
|
|
211
|
+
version: req.query.version ? Number(req.query.version) : undefined,
|
|
212
|
+
range: typeof req.headers.range === "string" ? req.headers.range : undefined
|
|
213
|
+
}, res, op === "record.part"
|
|
214
|
+
? { "content-disposition": `attachment; filename="${row.callRef}.wav"` }
|
|
215
|
+
: {});
|
|
216
|
+
return true;
|
|
217
|
+
});
|
|
218
|
+
/** The requested copy of a version: redacted by default, the original only when allowed. */
|
|
219
|
+
const copyOf = (req, res, row) => __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const original = req.query.original === "true";
|
|
221
|
+
if (original && !privileged(res)) {
|
|
222
|
+
res.status(403).json({
|
|
223
|
+
error: "permission_denied",
|
|
224
|
+
message: "the unredacted original needs the owner or admin role"
|
|
225
|
+
});
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
const store = deps.stores(row.location);
|
|
229
|
+
if (!store) {
|
|
230
|
+
res.status(503).json({ error: "store_unavailable" });
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const version = req.query.version ? Number(req.query.version) : undefined;
|
|
234
|
+
const stored = yield store.getVersion(row.callRef, version);
|
|
235
|
+
if (!stored) {
|
|
236
|
+
res.status(404).json({ error: "not_found" });
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
const signed = original
|
|
240
|
+
? stored.signed
|
|
241
|
+
: stored.redacted;
|
|
242
|
+
if (!signed) {
|
|
243
|
+
res.status(410).json({ error: "contents_deleted" });
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
return { store, stored, signed, original };
|
|
247
|
+
});
|
|
248
|
+
router.get("/:callRef", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
const row = yield rowOf(req, res);
|
|
250
|
+
if (!row)
|
|
251
|
+
return;
|
|
252
|
+
if (yield relayed(req, res, row, "record.get"))
|
|
253
|
+
return;
|
|
254
|
+
const copy = yield copyOf(req, res, row);
|
|
255
|
+
if (!copy)
|
|
256
|
+
return;
|
|
257
|
+
res.json(Object.assign(Object.assign({}, view(row)), { version: copy.stored.version, currentVersion: row.version, redacted: !copy.original, vcon: (0, callrecord_1.decodeVcon)(copy.signed), jws: copy.signed, parts: copy.stored.manifest.parts }));
|
|
258
|
+
})));
|
|
259
|
+
router.get("/:callRef/recording", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
260
|
+
var _a, _b;
|
|
261
|
+
const row = yield rowOf(req, res);
|
|
262
|
+
if (!row)
|
|
263
|
+
return;
|
|
264
|
+
if (yield relayed(req, res, row, "record.part", "recording"))
|
|
265
|
+
return;
|
|
266
|
+
const copy = yield copyOf(req, res, row);
|
|
267
|
+
if (!copy)
|
|
268
|
+
return;
|
|
269
|
+
const ref = (0, callrecord_1.decodeVcon)(copy.signed).dialog.find((d) => d.type === "recording" && d.url);
|
|
270
|
+
if (!ref) {
|
|
271
|
+
const inOriginal = !copy.original &&
|
|
272
|
+
copy.stored.signed &&
|
|
273
|
+
(0, callrecord_1.decodeVcon)(copy.stored.signed).dialog.some((d) => d.type === "recording" && d.url);
|
|
274
|
+
return inOriginal
|
|
275
|
+
? res.status(403).json({
|
|
276
|
+
error: "permission_denied",
|
|
277
|
+
message: "the recording is withheld from the redacted copy; it needs unredacted access"
|
|
278
|
+
})
|
|
279
|
+
: res.status(404).json({ error: "no_recording" });
|
|
280
|
+
}
|
|
281
|
+
const name = String(ref.url).replace(/^parts\//, "");
|
|
282
|
+
const data = yield copy.store.getPart(row.callRef, name);
|
|
283
|
+
if (!data)
|
|
284
|
+
return res.status(410).json({ error: "contents_deleted" });
|
|
285
|
+
res.setHeader("content-type", String((_a = ref.mimetype) !== null && _a !== void 0 ? _a : "audio/x-wav"));
|
|
286
|
+
res.setHeader("content-disposition", `attachment; filename="${row.callRef}.wav"`);
|
|
287
|
+
res.setHeader("x-content-hash", String((_b = ref.content_hash) !== null && _b !== void 0 ? _b : ""));
|
|
288
|
+
res.send(data);
|
|
289
|
+
})));
|
|
290
|
+
router.get("/:callRef/audit", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
if (!privileged(res))
|
|
292
|
+
return res.status(403).json({ error: "permission_denied" });
|
|
293
|
+
const items = yield deps.db.callRecordAudit.findMany({
|
|
294
|
+
where: {
|
|
295
|
+
callRef: String(req.params.callRef),
|
|
296
|
+
accessKeyId: caller(res).accessKeyId
|
|
297
|
+
},
|
|
298
|
+
orderBy: { at: "asc" }
|
|
299
|
+
});
|
|
300
|
+
res.json({ items });
|
|
301
|
+
})));
|
|
302
|
+
router.delete("/:callRef", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
var _a, _b;
|
|
304
|
+
if (!privileged(res))
|
|
305
|
+
return res.status(403).json({ error: "permission_denied" });
|
|
306
|
+
const result = yield maintain({
|
|
307
|
+
op: "erase",
|
|
308
|
+
callRef: String(req.params.callRef),
|
|
309
|
+
accessKeyId: caller(res).accessKeyId,
|
|
310
|
+
reason: String((_b = (_a = req.body) === null || _a === void 0 ? void 0 : _a.reason) !== null && _b !== void 0 ? _b : "erasure request"),
|
|
311
|
+
actor: caller(res).actor
|
|
312
|
+
});
|
|
313
|
+
res.json(result);
|
|
314
|
+
})));
|
|
315
|
+
router.delete("/:callRef/parts/:part", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
if (!privileged(res))
|
|
318
|
+
return res.status(403).json({ error: "permission_denied" });
|
|
319
|
+
const result = yield maintain({
|
|
320
|
+
op: "delete_parts",
|
|
321
|
+
callRef: String(req.params.callRef),
|
|
322
|
+
accessKeyId: caller(res).accessKeyId,
|
|
323
|
+
parts: [String(req.params.part)],
|
|
324
|
+
reason: String((_b = (_a = req.body) === null || _a === void 0 ? void 0 : _a.reason) !== null && _b !== void 0 ? _b : "deletion request"),
|
|
325
|
+
actor: caller(res).actor
|
|
326
|
+
});
|
|
327
|
+
res.json(result);
|
|
328
|
+
})));
|
|
329
|
+
return router;
|
|
330
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { CallDetailRecord, ListCallsRequest, ListCallsResponse } from "@fonoster/types";
|
|
20
|
+
import { CallRecordRow, RecordsDb } from "./types";
|
|
21
|
+
export type RecordSearch = {
|
|
22
|
+
after?: string;
|
|
23
|
+
before?: string;
|
|
24
|
+
/** Matches the caller or the callee. */
|
|
25
|
+
number?: string;
|
|
26
|
+
from?: string;
|
|
27
|
+
to?: string;
|
|
28
|
+
appRef?: string;
|
|
29
|
+
/** inbound, outbound or internal. */
|
|
30
|
+
direction?: string;
|
|
31
|
+
status?: string;
|
|
32
|
+
pageSize?: number;
|
|
33
|
+
/** The previous page's last startedAt (ms). */
|
|
34
|
+
pageToken?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Searches the index within one workspace (call-record "Fetch and search": time range, number,
|
|
38
|
+
* app, direction and status; records from other workspaces are never returned). Newest first.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createSearchRecords(db: RecordsDb): (accessKeyId: string, search: RecordSearch) => Promise<{
|
|
41
|
+
items: CallRecordRow[];
|
|
42
|
+
nextPageToken: string;
|
|
43
|
+
}>;
|
|
44
|
+
/** A call detail record (the existing Calls API shape) from an index row. */
|
|
45
|
+
export declare function toCallDetailRecord(row: CallRecordRow): CallDetailRecord;
|
|
46
|
+
/**
|
|
47
|
+
* ListCalls served from the call-record index (task 7.1).
|
|
48
|
+
*/
|
|
49
|
+
export declare function createFetchCallsFromIndex(db: RecordsDb): (accessKeyId: string, request: ListCallsRequest) => Promise<ListCallsResponse>;
|
|
50
|
+
/** GetCall from the index. */
|
|
51
|
+
export declare function createFetchSingleCallFromIndex(db: RecordsDb): (accessKeyId: string, ref: string) => Promise<CallDetailRecord>;
|
|
@@ -0,0 +1,134 @@
|
|
|
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.createSearchRecords = createSearchRecords;
|
|
13
|
+
exports.toCallDetailRecord = toCallDetailRecord;
|
|
14
|
+
exports.createFetchCallsFromIndex = createFetchCallsFromIndex;
|
|
15
|
+
exports.createFetchSingleCallFromIndex = createFetchSingleCallFromIndex;
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
18
|
+
* http://github.com/fonoster/fonoster
|
|
19
|
+
*
|
|
20
|
+
* This file is part of Fonoster
|
|
21
|
+
*
|
|
22
|
+
* Licensed under the MIT License (the "License");
|
|
23
|
+
* you may not use this file except in compliance with
|
|
24
|
+
* the License. You may obtain a copy of the License at
|
|
25
|
+
*
|
|
26
|
+
* https://opensource.org/licenses/MIT
|
|
27
|
+
*
|
|
28
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
30
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
31
|
+
* See the License for the specific language governing permissions and
|
|
32
|
+
* limitations under the License.
|
|
33
|
+
*/
|
|
34
|
+
const types_1 = require("@fonoster/types");
|
|
35
|
+
/**
|
|
36
|
+
* Searches the index within one workspace (call-record "Fetch and search": time range, number,
|
|
37
|
+
* app, direction and status; records from other workspaces are never returned). Newest first.
|
|
38
|
+
*/
|
|
39
|
+
function createSearchRecords(db) {
|
|
40
|
+
return (accessKeyId, search) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const startedAt = {};
|
|
42
|
+
if (search.after)
|
|
43
|
+
startedAt.gte = new Date(search.after);
|
|
44
|
+
if (search.before)
|
|
45
|
+
startedAt.lt = new Date(search.before);
|
|
46
|
+
if (search.pageToken) {
|
|
47
|
+
const token = new Date(Number(search.pageToken));
|
|
48
|
+
if (!startedAt.lt || token < startedAt.lt)
|
|
49
|
+
startedAt.lt = token;
|
|
50
|
+
}
|
|
51
|
+
const where = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ accessKeyId, erasedAt: null }, (Object.keys(startedAt).length ? { startedAt } : {})), (search.from ? { fromNumber: search.from } : {})), (search.to ? { toNumber: search.to } : {})), (search.appRef ? { appRef: search.appRef } : {})), (search.direction ? { direction: search.direction } : {})), (search.status ? { status: search.status } : {})), (search.number
|
|
52
|
+
? {
|
|
53
|
+
OR: [{ fromNumber: search.number }, { toNumber: search.number }]
|
|
54
|
+
}
|
|
55
|
+
: {}));
|
|
56
|
+
const pageSize = Math.min(Math.max(search.pageSize || 50, 1), 500);
|
|
57
|
+
const items = yield db.callRecord.findMany({
|
|
58
|
+
where,
|
|
59
|
+
orderBy: { startedAt: "desc" },
|
|
60
|
+
take: pageSize
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
items,
|
|
64
|
+
nextPageToken: items.length === pageSize
|
|
65
|
+
? String(items[items.length - 1].startedAt.getTime())
|
|
66
|
+
: ""
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const FAILURE_STATUS = {
|
|
71
|
+
busy: types_1.CallStatus.USER_BUSY,
|
|
72
|
+
no_answer: types_1.CallStatus.NO_ANSWER,
|
|
73
|
+
rejected: types_1.CallStatus.CALL_REJECTED,
|
|
74
|
+
no_app: types_1.CallStatus.NO_ROUTE_DESTINATION
|
|
75
|
+
};
|
|
76
|
+
/** A call detail record (the existing Calls API shape) from an index row. */
|
|
77
|
+
function toCallDetailRecord(row) {
|
|
78
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
79
|
+
const status = row.status === "failed"
|
|
80
|
+
? ((_b = FAILURE_STATUS[(_a = row.failureReason) !== null && _a !== void 0 ? _a : ""]) !== null && _b !== void 0 ? _b : types_1.CallStatus.SERVICE_UNAVAILABLE)
|
|
81
|
+
: types_1.CallStatus.NORMAL_CLEARING;
|
|
82
|
+
// The Calls API carries times as epoch seconds (int32 on the wire; the SDK multiplies by 1000).
|
|
83
|
+
return Object.assign({ ref: row.callRef, accessKeyId: (_c = row.accessKeyId) !== null && _c !== void 0 ? _c : "", callId: row.callRef, direction: row.direction === "outbound"
|
|
84
|
+
? types_1.CallDirection.TO_PSTN
|
|
85
|
+
: types_1.CallDirection.FROM_PSTN, type: row.direction === "outbound"
|
|
86
|
+
? types_1.CallType.API_ORIGINATED
|
|
87
|
+
: types_1.CallType.SIP_ORIGINATED, status, startedAt: Math.floor(row.startedAt.getTime() / 1000), endedAt: Math.floor(((_d = row.endedAt) !== null && _d !== void 0 ? _d : row.startedAt).getTime() / 1000), from: (_e = row.fromNumber) !== null && _e !== void 0 ? _e : "", to: (_f = row.toNumber) !== null && _f !== void 0 ? _f : "", duration: row.durationSeconds, appRef: (_g = row.appRef) !== null && _g !== void 0 ? _g : "" }, (row.amdStatus ? { amdStatus: row.amdStatus.toUpperCase() } : {}));
|
|
88
|
+
}
|
|
89
|
+
const STATUS_FILTER = {
|
|
90
|
+
[types_1.CallStatus.NORMAL_CLEARING]: { status: "completed" },
|
|
91
|
+
[types_1.CallStatus.USER_BUSY]: { status: "failed", failureReason: "busy" },
|
|
92
|
+
[types_1.CallStatus.NO_ANSWER]: { status: "failed", failureReason: "no_answer" }
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* ListCalls served from the call-record index (task 7.1).
|
|
96
|
+
*/
|
|
97
|
+
function createFetchCallsFromIndex(db) {
|
|
98
|
+
const search = createSearchRecords(db);
|
|
99
|
+
return (accessKeyId, request) => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const status = request.status
|
|
101
|
+
? STATUS_FILTER[request.status]
|
|
102
|
+
: undefined;
|
|
103
|
+
const result = yield search(accessKeyId, {
|
|
104
|
+
after: request.after,
|
|
105
|
+
before: request.before,
|
|
106
|
+
from: request.from,
|
|
107
|
+
to: request.to,
|
|
108
|
+
appRef: request.appRef,
|
|
109
|
+
status: status === null || status === void 0 ? void 0 : status.status,
|
|
110
|
+
pageSize: request.pageSize,
|
|
111
|
+
pageToken: request.pageToken
|
|
112
|
+
});
|
|
113
|
+
let items = result.items;
|
|
114
|
+
if (status === null || status === void 0 ? void 0 : status.failureReason)
|
|
115
|
+
items = items.filter((r) => r.failureReason === status.failureReason);
|
|
116
|
+
if (request.type)
|
|
117
|
+
items = items.filter((r) => (r.direction === "outbound"
|
|
118
|
+
? types_1.CallType.API_ORIGINATED
|
|
119
|
+
: types_1.CallType.SIP_ORIGINATED) === request.type);
|
|
120
|
+
return {
|
|
121
|
+
nextPageToken: result.nextPageToken,
|
|
122
|
+
items: items.map(toCallDetailRecord)
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** GetCall from the index. */
|
|
127
|
+
function createFetchSingleCallFromIndex(db) {
|
|
128
|
+
return (accessKeyId, ref) => __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const row = yield db.callRecord.findUnique({ where: { callRef: ref } });
|
|
130
|
+
if (!row || row.accessKeyId !== accessKeyId || row.erasedAt)
|
|
131
|
+
return null;
|
|
132
|
+
return toCallDetailRecord(row);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
export * from "./
|
|
20
|
-
export * from "./
|
|
21
|
-
export * from "./
|
|
22
|
-
export * from "./
|
|
23
|
-
export * from "./
|
|
24
|
-
export * from "./
|
|
19
|
+
export * from "./createIndexRecord";
|
|
20
|
+
export * from "./createRecordsRouter";
|
|
21
|
+
export * from "./createSearchRecords";
|
|
22
|
+
export * from "./maintenance";
|
|
23
|
+
export * from "./runCallRecords";
|
|
24
|
+
export * from "./stores";
|
|
25
25
|
export * from "./types";
|
|
@@ -32,10 +32,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./
|
|
39
|
-
__exportStar(require("./
|
|
40
|
-
__exportStar(require("./
|
|
35
|
+
__exportStar(require("./createIndexRecord"), exports);
|
|
36
|
+
__exportStar(require("./createRecordsRouter"), exports);
|
|
37
|
+
__exportStar(require("./createSearchRecords"), exports);
|
|
38
|
+
__exportStar(require("./maintenance"), exports);
|
|
39
|
+
__exportStar(require("./runCallRecords"), exports);
|
|
40
|
+
__exportStar(require("./stores"), exports);
|
|
41
41
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NatsConnection } from "nats";
|
|
2
|
+
import { AuditEntry, MaintenanceClient, RecordsDb } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Retention and erasure run in the record's region (it holds the files and the signing key);
|
|
5
|
+
* the control plane asks over NATS (`callrecord.<region>.maintenance`, served by the AppBridge replicas).
|
|
6
|
+
*/
|
|
7
|
+
export declare function natsMaintenanceClient(nc: NatsConnection, timeoutMs?: number): MaintenanceClient;
|
|
8
|
+
/** Writes audit entries (call-record: what was deleted, when, why and by whom). */
|
|
9
|
+
export declare function writeAudit(db: RecordsDb, audit: AuditEntry[]): Promise<void>;
|
|
10
|
+
export declare class RecordMaintenanceError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
constructor(code: string, message: string);
|
|
13
|
+
}
|
|
14
|
+
/** Deletes parts of a record or erases it, then audits and updates the index. */
|
|
15
|
+
export declare function createRecordMaintenance(db: RecordsDb, maintenance: MaintenanceClient): (request: {
|
|
16
|
+
op: "delete_parts" | "erase";
|
|
17
|
+
callRef: string;
|
|
18
|
+
accessKeyId: string;
|
|
19
|
+
parts?: string[];
|
|
20
|
+
reason: string;
|
|
21
|
+
actor: string;
|
|
22
|
+
}) => Promise<{
|
|
23
|
+
version: number;
|
|
24
|
+
audit: AuditEntry[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Applies every workspace's retention policies once (task 4.3): records older than a policy's
|
|
28
|
+
* days lose that part, with the policy named as the reason. Without a policy nothing is deleted.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runRetention(db: RecordsDb, maintenance: MaintenanceClient, now?: number): Promise<{
|
|
31
|
+
callRef: string;
|
|
32
|
+
part: string;
|
|
33
|
+
}[]>;
|