@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,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ownerOfCall = ownerOfCall;
|
|
37
|
+
exports.buildService = buildService;
|
|
38
|
+
/**
|
|
39
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
40
|
+
* http://github.com/fonoster/fonoster
|
|
41
|
+
*
|
|
42
|
+
* This file is part of Fonoster
|
|
43
|
+
*
|
|
44
|
+
* Licensed under the MIT License (the "License");
|
|
45
|
+
* you may not use this file except in compliance with
|
|
46
|
+
* the License. You may obtain a copy of the License at
|
|
47
|
+
*
|
|
48
|
+
* https://opensource.org/licenses/MIT
|
|
49
|
+
*
|
|
50
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
51
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
52
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
53
|
+
* See the License for the specific language governing permissions and
|
|
54
|
+
* limitations under the License.
|
|
55
|
+
*/
|
|
56
|
+
const common_1 = require("@fonoster/common");
|
|
57
|
+
const logger_1 = require("@fonoster/logger");
|
|
58
|
+
const types_1 = require("@fonoster/types");
|
|
59
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
60
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
61
|
+
const METHODS = [
|
|
62
|
+
"getBilling",
|
|
63
|
+
"updateAutoRecharge",
|
|
64
|
+
"createTopUp",
|
|
65
|
+
"subscribe",
|
|
66
|
+
"createPortalSession"
|
|
67
|
+
];
|
|
68
|
+
const definition = () => (0, common_1.createServiceDefinition)({
|
|
69
|
+
serviceName: "Billing",
|
|
70
|
+
pckg: "billing",
|
|
71
|
+
proto: "billing.proto",
|
|
72
|
+
version: "v1beta2"
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* The owner whose billing a call reads or changes: the caller, who must own the workspace the call
|
|
76
|
+
* is made in (add-billing-service 6.1). Undefined otherwise.
|
|
77
|
+
*/
|
|
78
|
+
function ownerOfCall(call) {
|
|
79
|
+
var _a;
|
|
80
|
+
const grpcCall = call;
|
|
81
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(grpcCall);
|
|
82
|
+
const token = (0, common_1.decodeToken)((0, common_1.getTokenFromCall)(grpcCall));
|
|
83
|
+
const owns = ((_a = token.access) !== null && _a !== void 0 ? _a : []).some((a) => a.accessKeyId === accessKeyId && a.role === types_1.Role.WORKSPACE_OWNER);
|
|
84
|
+
return owns ? token.sub : undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The Billing API for the dashboard (billing.proto), when billing is on: each call is passed to
|
|
88
|
+
* the billing service with owner_ref set from the caller, never from the request.
|
|
89
|
+
*/
|
|
90
|
+
function buildService(address, ownerOf = ownerOfCall) {
|
|
91
|
+
const client = new (grpc.makeGenericClientConstructor(definition(), "Billing", {}))(address, grpc.credentials.createInsecure());
|
|
92
|
+
const forward = (method) => (call, callback) => {
|
|
93
|
+
const ownerRef = ownerOf(call);
|
|
94
|
+
if (!ownerRef) {
|
|
95
|
+
callback({
|
|
96
|
+
code: grpc.status.PERMISSION_DENIED,
|
|
97
|
+
message: "Only the workspace owner manages billing"
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
client[method](Object.assign(Object.assign({}, call.request), { ownerRef }), (error, response) => {
|
|
102
|
+
if (error)
|
|
103
|
+
logger.verbose("billing call refused", { method, code: error.code });
|
|
104
|
+
callback(error ? { code: error.code, message: error.details } : null, response);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
definition: {
|
|
109
|
+
serviceName: "Billing",
|
|
110
|
+
pckg: "billing",
|
|
111
|
+
version: "v1beta2",
|
|
112
|
+
proto: "billing.proto"
|
|
113
|
+
},
|
|
114
|
+
handlers: Object.fromEntries(METHODS.map((m) => [m, forward(m)]))
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
/**
|
|
46
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
47
|
+
* http://github.com/fonoster/fonoster
|
|
48
|
+
*
|
|
49
|
+
* This file is part of Fonoster
|
|
50
|
+
*
|
|
51
|
+
* Licensed under the MIT License (the "License");
|
|
52
|
+
* you may not use this file except in compliance with
|
|
53
|
+
* the License. You may obtain a copy of the License at
|
|
54
|
+
*
|
|
55
|
+
* https://opensource.org/licenses/MIT
|
|
56
|
+
*
|
|
57
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
58
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
59
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
60
|
+
* See the License for the specific language governing permissions and
|
|
61
|
+
* limitations under the License.
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Container entrypoint: waits for Postgres, applies migrations, seeds, then
|
|
65
|
+
* starts the API server. Everything comes from fonoster.yaml; Prisma's CLI
|
|
66
|
+
* still reads its URL from an environment variable, so the URL is passed only
|
|
67
|
+
* to those child processes.
|
|
68
|
+
*
|
|
69
|
+
* node dist/bin/entrypoint.js [--config /opt/fonoster/fonoster.yaml]
|
|
70
|
+
* [--migrations-root /service]
|
|
71
|
+
* [--migrate-only | --skip-migrations]
|
|
72
|
+
*
|
|
73
|
+
* --migrate-only applies the migrations and the seed, then exits (the Helm migrations Job);
|
|
74
|
+
* --skip-migrations waits until `prisma migrate status` reports both schemas up to date (the
|
|
75
|
+
* Job applies them), then serves (replicas behind that Job).
|
|
76
|
+
*/
|
|
77
|
+
const child_process_1 = require("child_process");
|
|
78
|
+
const net_1 = require("net");
|
|
79
|
+
const path_1 = require("path");
|
|
80
|
+
const config_1 = require("../config");
|
|
81
|
+
const argv = process.argv;
|
|
82
|
+
const flag = (name, fallback) => {
|
|
83
|
+
const i = argv.indexOf(name);
|
|
84
|
+
return i >= 0 && argv[i + 1] ? argv[i + 1] : fallback;
|
|
85
|
+
};
|
|
86
|
+
const migrationsRoot = flag("--migrations-root", "/service");
|
|
87
|
+
const migrateOnly = argv.includes("--migrate-only");
|
|
88
|
+
const skipMigrations = argv.includes("--skip-migrations");
|
|
89
|
+
const WAIT_TIMEOUT_MS = 30000;
|
|
90
|
+
const MIGRATIONS_WAIT_MS = 15 * 60000;
|
|
91
|
+
function waitForTcp(host, port, timeoutMs) {
|
|
92
|
+
const deadline = Date.now() + timeoutMs;
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
const attempt = () => {
|
|
95
|
+
const socket = (0, net_1.createConnection)({ host, port });
|
|
96
|
+
socket.once("connect", () => {
|
|
97
|
+
socket.end();
|
|
98
|
+
resolve();
|
|
99
|
+
});
|
|
100
|
+
socket.once("error", () => {
|
|
101
|
+
socket.destroy();
|
|
102
|
+
if (Date.now() > deadline) {
|
|
103
|
+
reject(new Error(`database at ${host}:${port} not reachable after ${timeoutMs / 1000}s`));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
setTimeout(attempt, 1000);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
attempt();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function run(step, command, args, cwd, env) {
|
|
114
|
+
const result = (0, child_process_1.spawnSync)(command, args, {
|
|
115
|
+
cwd,
|
|
116
|
+
stdio: "inherit",
|
|
117
|
+
env: Object.assign(Object.assign({}, process.env), env)
|
|
118
|
+
});
|
|
119
|
+
if (result.status !== 0) {
|
|
120
|
+
throw new Error(`${step} failed (exit code ${result.status})`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Polls `prisma migrate status` (exit 0 = up to date) for both schemas. */
|
|
124
|
+
function waitForMigrations(coreUrl, identityUrl) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const deadline = Date.now() + MIGRATIONS_WAIT_MS;
|
|
127
|
+
const upToDate = () => [
|
|
128
|
+
["core", { APISERVER_DATABASE_URL: coreUrl }],
|
|
129
|
+
["identity", { APISERVER_IDENTITY_DATABASE_URL: identityUrl }]
|
|
130
|
+
].every(([dir, env]) => (0, child_process_1.spawnSync)("npx", ["prisma", "migrate", "status"], {
|
|
131
|
+
cwd: (0, path_1.join)(migrationsRoot, dir),
|
|
132
|
+
stdio: "ignore",
|
|
133
|
+
env: Object.assign(Object.assign({}, process.env), env)
|
|
134
|
+
}).status === 0);
|
|
135
|
+
while (!upToDate()) {
|
|
136
|
+
if (Date.now() > deadline)
|
|
137
|
+
throw new Error(`migrations not applied after ${MIGRATIONS_WAIT_MS / 1000}s (is the migrations Job running?)`);
|
|
138
|
+
console.log("waiting for the migrations Job");
|
|
139
|
+
yield new Promise((r) => setTimeout(r, 5000));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function main() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
// Validates fonoster.yaml (and reads the keys) before touching the database.
|
|
146
|
+
const config = (0, config_1.getConfig)();
|
|
147
|
+
const identity = (0, config_1.getIdentityConfig)();
|
|
148
|
+
if (skipMigrations) {
|
|
149
|
+
yield waitForMigrations(config.database.url, identity.dbUrl);
|
|
150
|
+
yield Promise.resolve().then(() => __importStar(require("../index")));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const db = new URL(config.database.url);
|
|
154
|
+
yield waitForTcp(db.hostname, Number(db.port || 5432), WAIT_TIMEOUT_MS);
|
|
155
|
+
run("core migrations", "npx", ["prisma", "migrate", "deploy"], (0, path_1.join)(migrationsRoot, "core"), {
|
|
156
|
+
APISERVER_DATABASE_URL: config.database.url
|
|
157
|
+
});
|
|
158
|
+
run("identity migrations", "npx", ["prisma", "migrate", "deploy"], (0, path_1.join)(migrationsRoot, "identity"), {
|
|
159
|
+
APISERVER_IDENTITY_DATABASE_URL: identity.dbUrl
|
|
160
|
+
});
|
|
161
|
+
// From source (the dev container runs this file with tsx) the seed is a .ts file and needs
|
|
162
|
+
// the same loader flags; in the image, dist/core/seed.js and no flags.
|
|
163
|
+
run("seed", process.execPath, [
|
|
164
|
+
...process.execArgv,
|
|
165
|
+
(0, path_1.join)(__dirname, "..", "core", `seed${(0, path_1.extname)(__filename)}`)
|
|
166
|
+
], process.cwd(), {
|
|
167
|
+
APISERVER_DATABASE_URL: config.database.url
|
|
168
|
+
});
|
|
169
|
+
if (migrateOnly) {
|
|
170
|
+
console.log("migrations and seed applied");
|
|
171
|
+
process.exit(0);
|
|
172
|
+
}
|
|
173
|
+
yield Promise.resolve().then(() => __importStar(require("../index")));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
main().catch((error) => {
|
|
177
|
+
// The logger isn't configured yet if the config itself is invalid.
|
|
178
|
+
console.error(`apiserver failed to start: ${error.message}`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
});
|
|
@@ -32,8 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var _a;
|
|
35
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
+
exports.checkHealth = checkHealth;
|
|
37
38
|
/**
|
|
38
39
|
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
39
40
|
* http://github.com/fonoster/fonoster
|
|
@@ -52,12 +53,26 @@ exports.VoiceServiceClientConstructor = void 0;
|
|
|
52
53
|
* See the License for the specific language governing permissions and
|
|
53
54
|
* limitations under the License.
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Container healthcheck: exits 0 when the API server answers the standard gRPC health check
|
|
58
|
+
* (grpc.health.v1) with SERVING, 1 otherwise. The server binds only after the entrypoint has
|
|
59
|
+
* applied the migrations and loaded the services, so a healthy apiserver has its tables.
|
|
60
|
+
*
|
|
61
|
+
* node /work/mods/apiserver/dist/bin/healthcheck.js [host:port] (default 127.0.0.1:50051)
|
|
62
|
+
*/
|
|
56
63
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
const grpc_health_check_1 = require("grpc-health-check");
|
|
65
|
+
const TIMEOUT_MS = 2000;
|
|
66
|
+
function checkHealth(address, timeoutMs = TIMEOUT_MS) {
|
|
67
|
+
const Health = grpc.makeGenericClientConstructor(grpc_health_check_1.service, "Health");
|
|
68
|
+
const client = new Health(address, grpc.credentials.createInsecure());
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
client.Check({ service: "" }, { deadline: Date.now() + timeoutMs }, (error, res) => {
|
|
71
|
+
client.close();
|
|
72
|
+
resolve(!error && (res === null || res === void 0 ? void 0 : res.status) === "SERVING");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (require.main === module) {
|
|
77
|
+
checkHealth((_a = process.argv[2]) !== null && _a !== void 0 ? _a : "127.0.0.1:50051").then((ok) => process.exit(ok ? 0 : 1));
|
|
78
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const crypto_1 = require("crypto");
|
|
23
|
+
const fs_1 = require("fs");
|
|
24
|
+
const path_1 = require("path");
|
|
25
|
+
const natsJwt_1 = require("../regions/natsJwt");
|
|
26
|
+
/**
|
|
27
|
+
* fonoster-region-hub-setup <dir> [--leaf-tls <cert> <key>]
|
|
28
|
+
*
|
|
29
|
+
* Generates, once, what private regions need on the control plane side (RG-B2):
|
|
30
|
+
* <dir>/region-hub.conf the hub's NATS config (operator mode, leaf listener)
|
|
31
|
+
* <dir>/keys/region-signing.pem the ES256 region-signing key (enrollment tokens)
|
|
32
|
+
* <dir>/keys/region-hub/*.seed|.creds the operator and REGIONS account seeds and the control
|
|
33
|
+
* plane's REGIONS and system users
|
|
34
|
+
* Existing files are left alone. Keep the seeds secret: they mint region credentials.
|
|
35
|
+
*/
|
|
36
|
+
function main(argv) {
|
|
37
|
+
const dir = argv[0];
|
|
38
|
+
if (!dir) {
|
|
39
|
+
process.stderr.write("usage: fonoster-region-hub-setup <dir> [--leaf-tls <cert> <key>]\n");
|
|
40
|
+
process.exit(2);
|
|
41
|
+
}
|
|
42
|
+
const tlsAt = argv.indexOf("--leaf-tls");
|
|
43
|
+
const leafTls = tlsAt >= 0
|
|
44
|
+
? { certFile: argv[tlsAt + 1], keyFile: argv[tlsAt + 2] }
|
|
45
|
+
: undefined;
|
|
46
|
+
const hubDir = (0, path_1.join)(dir, "keys", "region-hub");
|
|
47
|
+
(0, fs_1.mkdirSync)(hubDir, { recursive: true });
|
|
48
|
+
const signing = (0, path_1.join)(dir, "keys", "region-signing.pem");
|
|
49
|
+
if (!(0, fs_1.existsSync)(signing)) {
|
|
50
|
+
const { privateKey } = (0, crypto_1.generateKeyPairSync)("ec", { namedCurve: "P-256" });
|
|
51
|
+
(0, fs_1.writeFileSync)(signing, privateKey.export({ type: "pkcs8", format: "pem" }), {
|
|
52
|
+
mode: 0o600
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const conf = (0, path_1.join)(dir, "region-hub.conf");
|
|
56
|
+
if (!(0, fs_1.existsSync)(conf)) {
|
|
57
|
+
const hub = (0, natsJwt_1.generateRegionHub)({ leafTls });
|
|
58
|
+
const secret = { mode: 0o600 };
|
|
59
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(hubDir, "operator.seed"), hub.operatorSeed, secret);
|
|
60
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(hubDir, "account.seed"), hub.accountSeed, secret);
|
|
61
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(hubDir, "control-plane.creds"), hub.controlPlaneCreds, secret);
|
|
62
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(hubDir, "system.creds"), hub.systemCreds, secret);
|
|
63
|
+
(0, fs_1.writeFileSync)(conf, hub.conf);
|
|
64
|
+
}
|
|
65
|
+
process.stdout.write(`region hub material in ${dir}\n`);
|
|
66
|
+
}
|
|
67
|
+
main(process.argv.slice(2));
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
/**
|
|
47
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
48
|
+
* http://github.com/fonoster/fonoster
|
|
49
|
+
*
|
|
50
|
+
* This file is part of Fonoster
|
|
51
|
+
*
|
|
52
|
+
* Licensed under the MIT License (the "License");
|
|
53
|
+
* you may not use this file except in compliance with
|
|
54
|
+
* the License. You may obtain a copy of the License at
|
|
55
|
+
*
|
|
56
|
+
* https://opensource.org/licenses/MIT
|
|
57
|
+
*
|
|
58
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
59
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
60
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
61
|
+
* See the License for the specific language governing permissions and
|
|
62
|
+
* limitations under the License.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* fonoster-usage: maintenance for the usage ledger (add-usage-metering D7).
|
|
66
|
+
*
|
|
67
|
+
* fonoster-usage rebuild --from <YYYY-MM-DD> --to <YYYY-MM-DD> [--from-records]
|
|
68
|
+
*
|
|
69
|
+
* rebuild recomputes usage_daily for the days from usage_events. With --from-records it first
|
|
70
|
+
* re-reads the sealed call records of those days and stores usage that never reached the ledger.
|
|
71
|
+
*/
|
|
72
|
+
const identity_1 = require("@fonoster/identity");
|
|
73
|
+
const identityConfig_1 = require("../core/identityConfig");
|
|
74
|
+
const envs_1 = require("../envs");
|
|
75
|
+
const stores_1 = require("../records/stores");
|
|
76
|
+
const rebuildUsage_1 = require("../usage/rebuildUsage");
|
|
77
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
78
|
+
const USAGE = "usage: fonoster-usage rebuild --from <YYYY-MM-DD> --to <YYYY-MM-DD> [--from-records]";
|
|
79
|
+
function option(args, name) {
|
|
80
|
+
const i = args.indexOf(name);
|
|
81
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
82
|
+
}
|
|
83
|
+
function main(args) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const from = option(args, "--from");
|
|
86
|
+
const to = option(args, "--to");
|
|
87
|
+
if (args[0] !== "rebuild" ||
|
|
88
|
+
!from ||
|
|
89
|
+
!to ||
|
|
90
|
+
!DAY.test(from) ||
|
|
91
|
+
!DAY.test(to) ||
|
|
92
|
+
from > to) {
|
|
93
|
+
console.error(USAGE);
|
|
94
|
+
return 2;
|
|
95
|
+
}
|
|
96
|
+
const { prisma } = yield Promise.resolve().then(() => __importStar(require("../core/db")));
|
|
97
|
+
const db = prisma;
|
|
98
|
+
if (args.includes("--from-records")) {
|
|
99
|
+
const identity = (0, identity_1.createPrismaClient)(identityConfig_1.identityConfig.dbUrl, identityConfig_1.identityConfig.encryptionKey);
|
|
100
|
+
const recovered = yield (0, rebuildUsage_1.recoverUsageFromRecords)({
|
|
101
|
+
db,
|
|
102
|
+
directory: (0, identity_1.createWorkspaceDirectory)(identity),
|
|
103
|
+
storeFor: (0, stores_1.createStoreResolver)(envs_1.CALL_RECORDS.stores),
|
|
104
|
+
fromDay: from,
|
|
105
|
+
toDay: to
|
|
106
|
+
});
|
|
107
|
+
console.log(`recovered ${recovered} usage lines from records`);
|
|
108
|
+
yield identity.$disconnect();
|
|
109
|
+
}
|
|
110
|
+
const totals = yield (0, rebuildUsage_1.rebuildUsageDaily)(db, from, to);
|
|
111
|
+
console.log(`rebuilt ${totals} daily totals for ${from}..${to}`);
|
|
112
|
+
yield prisma.$disconnect();
|
|
113
|
+
return 0;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
main(process.argv.slice(2)).then((code) => process.exit(code), (e) => {
|
|
117
|
+
console.error(e.message);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|
|
@@ -1,23 +1,4 @@
|
|
|
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 { InfluxDBClient } from "@fonoster/common";
|
|
20
|
-
declare function buildService(influxdb: InfluxDBClient): Promise<{
|
|
1
|
+
declare function buildService(): Promise<{
|
|
21
2
|
definition: {
|
|
22
3
|
serviceName: string;
|
|
23
4
|
pckg: string;
|
|
@@ -8,20 +8,72 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.buildService = buildService;
|
|
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 authz_1 = require("@fonoster/authz");
|
|
35
|
+
const logger_1 = require("@fonoster/logger");
|
|
36
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
13
37
|
const nats_1 = require("nats");
|
|
14
38
|
const db_1 = require("../core/db");
|
|
39
|
+
const routrConfig_1 = require("../core/routrConfig");
|
|
15
40
|
const envs_1 = require("../envs");
|
|
41
|
+
const records_1 = require("../records");
|
|
16
42
|
const createCall_1 = require("./createCall");
|
|
17
43
|
const createCallPublisher_1 = require("./createCallPublisher");
|
|
44
|
+
const createIsWorkspaceNumber_1 = require("./createIsWorkspaceNumber");
|
|
18
45
|
const createTrackCall_1 = require("./createTrackCall");
|
|
19
46
|
const getCall_1 = require("./getCall");
|
|
20
47
|
const listCalls_1 = require("./listCalls");
|
|
21
|
-
|
|
48
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
49
|
+
/** An answer slower than this admits the call (add-billing-service D7). */
|
|
50
|
+
const ADMISSION_TIMEOUT_MS = 500;
|
|
51
|
+
/** Outbound admission from the authorization service, when it is enabled. */
|
|
52
|
+
function authzAdmission() {
|
|
53
|
+
if (!envs_1.AUTHZ_SERVICE_ENABLED)
|
|
54
|
+
return undefined;
|
|
55
|
+
const client = new authz_1.AuthzClient(`${envs_1.AUTHZ_SERVICE_HOST}:${envs_1.AUTHZ_SERVICE_PORT}`);
|
|
56
|
+
return (request) => client
|
|
57
|
+
.checkSession({
|
|
58
|
+
accessKeyId: request.accessKeyId,
|
|
59
|
+
appRef: request.appRef,
|
|
60
|
+
callRef: request.callRef,
|
|
61
|
+
callerNumber: request.from,
|
|
62
|
+
ingressNumber: request.to,
|
|
63
|
+
callDirection: "TO_PSTN"
|
|
64
|
+
}, ADMISSION_TIMEOUT_MS)
|
|
65
|
+
.catch((e) => {
|
|
66
|
+
logger.warn("call admitted without an answer from authorization", {
|
|
67
|
+
callRef: request.callRef,
|
|
68
|
+
error: e.message
|
|
69
|
+
});
|
|
70
|
+
return { authorized: true };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function buildService() {
|
|
22
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const callPublisher = yield (0, createCallPublisher_1.createCallPublisher)(envs_1.
|
|
24
|
-
const nc = yield (0, nats_1.connect)({
|
|
75
|
+
const callPublisher = yield (0, createCallPublisher_1.createCallPublisher)(envs_1.NATS_CONNECTION);
|
|
76
|
+
const nc = yield (0, nats_1.connect)(Object.assign(Object.assign({}, envs_1.NATS), { maxReconnectAttempts: -1 }));
|
|
25
77
|
return {
|
|
26
78
|
definition: {
|
|
27
79
|
serviceName: "Calls",
|
|
@@ -30,9 +82,10 @@ function buildService(influxdb) {
|
|
|
30
82
|
proto: "calls.proto"
|
|
31
83
|
},
|
|
32
84
|
handlers: {
|
|
33
|
-
createCall: (0, createCall_1.createCall)(db_1.prisma, callPublisher),
|
|
34
|
-
|
|
35
|
-
|
|
85
|
+
createCall: (0, createCall_1.createCall)(db_1.prisma, callPublisher, (0, createIsWorkspaceNumber_1.createIsWorkspaceNumber)(new sdk_1.default.Numbers(routrConfig_1.routrConfig)), authzAdmission()),
|
|
86
|
+
// Call history from the call-record index (add-call-record 7.1).
|
|
87
|
+
listCalls: (0, listCalls_1.listCalls)((0, records_1.createFetchCallsFromIndex)(db_1.prisma)),
|
|
88
|
+
getCall: (0, getCall_1.getCall)((0, records_1.createFetchSingleCallFromIndex)(db_1.prisma)),
|
|
36
89
|
trackCall: (0, createTrackCall_1.createTrackCall)(nc)
|
|
37
90
|
}
|
|
38
91
|
};
|