@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,558 @@
|
|
|
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.newRegionRef = newRegionRef;
|
|
13
|
+
exports.createRegionService = createRegionService;
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
16
|
+
* http://github.com/fonoster/fonoster
|
|
17
|
+
*
|
|
18
|
+
* This file is part of Fonoster
|
|
19
|
+
*
|
|
20
|
+
* Licensed under the MIT License (the "License");
|
|
21
|
+
* you may not use this file except in compliance with
|
|
22
|
+
* the License. You may obtain a copy of the License at
|
|
23
|
+
*
|
|
24
|
+
* https://opensource.org/licenses/MIT
|
|
25
|
+
*
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
* See the License for the specific language governing permissions and
|
|
30
|
+
* limitations under the License.
|
|
31
|
+
*/
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
const logger_1 = require("@fonoster/logger");
|
|
34
|
+
const endpoints_1 = require("./endpoints");
|
|
35
|
+
const enrollmentToken_1 = require("./enrollmentToken");
|
|
36
|
+
const ids_1 = require("./ids");
|
|
37
|
+
const status_1 = require("./status");
|
|
38
|
+
const types_1 = require("./types");
|
|
39
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
40
|
+
const B32 = "abcdefghijklmnopqrstuvwxyz234567";
|
|
41
|
+
/** `rg_` + 16 lowercase base32 characters (80 random bits). */
|
|
42
|
+
function newRegionRef() {
|
|
43
|
+
const bytes = (0, crypto_1.randomBytes)(10);
|
|
44
|
+
let bits = 0;
|
|
45
|
+
let value = 0;
|
|
46
|
+
let out = "";
|
|
47
|
+
for (const b of bytes) {
|
|
48
|
+
value = (value << 8) | b;
|
|
49
|
+
bits += 8;
|
|
50
|
+
while (bits >= 5) {
|
|
51
|
+
out += B32[(value >>> (bits - 5)) & 31];
|
|
52
|
+
bits -= 5;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return `rg_${out}`;
|
|
56
|
+
}
|
|
57
|
+
/** Directory used until Identity attaches the real one (no workspaces). */
|
|
58
|
+
const EMPTY_DIRECTORY = {
|
|
59
|
+
workspace: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
|
|
60
|
+
inRegion: () => __awaiter(void 0, void 0, void 0, function* () { return []; })
|
|
61
|
+
};
|
|
62
|
+
const isUniqueViolation = (e) => (e === null || e === void 0 ? void 0 : e.code) === "P2002" ||
|
|
63
|
+
/unique constraint/i.test(String(e === null || e === void 0 ? void 0 : e.message));
|
|
64
|
+
/**
|
|
65
|
+
* Regions on the control plane (PR-12..PR-21): user-owned private regions and operator-created
|
|
66
|
+
* public regions, one enrollment and credential mechanism for both, heartbeats and status, and
|
|
67
|
+
* which workspaces a region serves.
|
|
68
|
+
*/
|
|
69
|
+
function createRegionService(deps) {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
const { db, config } = deps;
|
|
72
|
+
const now = (_a = deps.now) !== null && _a !== void 0 ? _a : (() => new Date());
|
|
73
|
+
const publish = (_b = deps.publish) !== null && _b !== void 0 ? _b : (() => undefined);
|
|
74
|
+
let directory = (_c = deps.directory) !== null && _c !== void 0 ? _c : EMPTY_DIRECTORY;
|
|
75
|
+
const signer = () => {
|
|
76
|
+
if (!deps.signer)
|
|
77
|
+
throw new types_1.RegionError(503, "regions_unavailable", "regions are not configured on this control plane (regions.signingKey)");
|
|
78
|
+
return deps.signer;
|
|
79
|
+
};
|
|
80
|
+
const natsAuth = () => {
|
|
81
|
+
if (!deps.natsAuth)
|
|
82
|
+
throw new types_1.RegionError(503, "regions_unavailable", "the region hub is not configured on this control plane (regions.hub)");
|
|
83
|
+
return deps.natsAuth;
|
|
84
|
+
};
|
|
85
|
+
const notFound = () => new types_1.RegionError(404, "region_not_found", "no such region");
|
|
86
|
+
const issueToken = (row) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const jti = (0, crypto_1.randomUUID)();
|
|
88
|
+
const token = signer().sign({
|
|
89
|
+
iss: config.issuer,
|
|
90
|
+
sub: row.ref,
|
|
91
|
+
rid: row.id,
|
|
92
|
+
knd: row.kind,
|
|
93
|
+
cp: config.controlPlaneUrl,
|
|
94
|
+
leaf: config.leafUrl,
|
|
95
|
+
jti
|
|
96
|
+
});
|
|
97
|
+
const claims = signer().verify(token);
|
|
98
|
+
const expiresAt = new Date(claims.exp * 1000);
|
|
99
|
+
yield db.regionToken.create({
|
|
100
|
+
data: {
|
|
101
|
+
jti,
|
|
102
|
+
regionRef: row.ref,
|
|
103
|
+
issuedAt: new Date(claims.iat * 1000),
|
|
104
|
+
expiresAt
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
token,
|
|
109
|
+
enrollmentToken: token,
|
|
110
|
+
expiresAt: expiresAt.toISOString()
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
/** Revokes every live credential of a region and pushes the revocations to the hub. */
|
|
114
|
+
const revokeAll = (regionRef, reason) => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const live = yield db.regionCredential.findMany({
|
|
116
|
+
where: { regionRef, revokedAt: null }
|
|
117
|
+
});
|
|
118
|
+
if (!live.length)
|
|
119
|
+
return 0;
|
|
120
|
+
publish((0, types_1.subjects)(regionRef).revoked, { type: "region.revoked", reason });
|
|
121
|
+
yield db.regionCredential.updateMany({
|
|
122
|
+
where: { regionRef, revokedAt: null },
|
|
123
|
+
data: { revokedAt: now() }
|
|
124
|
+
});
|
|
125
|
+
yield pushRevocations();
|
|
126
|
+
return live.length;
|
|
127
|
+
});
|
|
128
|
+
const pushRevocations = () => __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const revoked = yield db.regionCredential.findMany({
|
|
130
|
+
where: { revokedAt: { not: null } },
|
|
131
|
+
select: { userPublicKey: true, revokedAt: true }
|
|
132
|
+
});
|
|
133
|
+
const map = {};
|
|
134
|
+
for (const r of revoked)
|
|
135
|
+
map[r.userPublicKey] = Math.ceil(r.revokedAt.getTime() / 1000);
|
|
136
|
+
yield natsAuth().pushRevocations(map);
|
|
137
|
+
});
|
|
138
|
+
const insert = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
try {
|
|
140
|
+
return (yield db.region.create({
|
|
141
|
+
data: Object.assign({ ref: newRegionRef(), state: "waiting" }, data)
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
if (isUniqueViolation(e))
|
|
146
|
+
throw new types_1.RegionError(409, "region_id_taken", `a region with id "${data.id}" already exists`);
|
|
147
|
+
throw e;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const byRef = (ref) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const row = yield db.region.findUnique({ where: { ref } });
|
|
152
|
+
return row && !row.deletedAt ? row : undefined;
|
|
153
|
+
});
|
|
154
|
+
/** The live public region row with this id (or ref). */
|
|
155
|
+
const publicRow = (idOrRef) => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
var _a;
|
|
157
|
+
if (types_1.REGION_REF.test(idOrRef)) {
|
|
158
|
+
const row = yield byRef(idOrRef);
|
|
159
|
+
return (row === null || row === void 0 ? void 0 : row.kind) === "public" ? row : undefined;
|
|
160
|
+
}
|
|
161
|
+
return ((_a = (yield db.region.findFirst({
|
|
162
|
+
where: { kind: "public", id: idOrRef, deletedAt: null }
|
|
163
|
+
}))) !== null && _a !== void 0 ? _a : undefined);
|
|
164
|
+
});
|
|
165
|
+
/** A live region by id or ref, for the admin API (ids name public regions). */
|
|
166
|
+
const anyRow = (idOrRef) => __awaiter(this, void 0, void 0, function* () { return types_1.REGION_REF.test(idOrRef) ? byRef(idOrRef) : publicRow(idOrRef); });
|
|
167
|
+
const workspaces = (row) => directory.inRegion((0, types_1.regionKey)(row));
|
|
168
|
+
const service = {
|
|
169
|
+
setDirectory(d) {
|
|
170
|
+
directory = d;
|
|
171
|
+
},
|
|
172
|
+
get directory() {
|
|
173
|
+
return directory;
|
|
174
|
+
},
|
|
175
|
+
/** A user creates a private region (PR-15, PR-16, PR-18); the first token is returned once. */
|
|
176
|
+
createRegion(ownerRef, input) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
var _a;
|
|
179
|
+
if (!ownerRef)
|
|
180
|
+
throw new types_1.RegionError(401, "unauthenticated", "a user is required");
|
|
181
|
+
const id = (0, ids_1.checkPrivateRegionId)(input.id);
|
|
182
|
+
const displayName = (0, ids_1.checkDisplayName)((_a = input.displayName) !== null && _a !== void 0 ? _a : id);
|
|
183
|
+
const sipDomain = (0, ids_1.checkSipDomain)(input.sipDomain);
|
|
184
|
+
signer();
|
|
185
|
+
const exists = yield db.region.findFirst({
|
|
186
|
+
where: { kind: "private", ownerRef, id, deletedAt: null }
|
|
187
|
+
});
|
|
188
|
+
if (exists)
|
|
189
|
+
throw new types_1.RegionError(409, "region_id_taken", `you already have a region with id "${id}"`);
|
|
190
|
+
const row = yield insert({
|
|
191
|
+
id,
|
|
192
|
+
kind: "private",
|
|
193
|
+
ownerRef,
|
|
194
|
+
displayName,
|
|
195
|
+
sipDomain
|
|
196
|
+
});
|
|
197
|
+
const token = yield issueToken(row);
|
|
198
|
+
logger.info(`private region ${row.ref} (${id}) created for ${ownerRef}`);
|
|
199
|
+
return Object.assign({ ref: row.ref, id: row.id }, token);
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
/** The operator creates a public region (PR-19); unpublished until `publish`. */
|
|
203
|
+
createPublicRegion(input) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
var _a;
|
|
206
|
+
const id = (0, ids_1.checkPublicRegionId)(input.id);
|
|
207
|
+
const displayName = (0, ids_1.checkDisplayName)((_a = input.displayName) !== null && _a !== void 0 ? _a : id);
|
|
208
|
+
const sipDomain = (0, ids_1.checkSipDomain)(input.sipDomain, true);
|
|
209
|
+
signer();
|
|
210
|
+
if (yield publicRow(id))
|
|
211
|
+
throw new types_1.RegionError(409, "region_id_taken", `public region "${id}" already exists`);
|
|
212
|
+
const endpoints = input.endpoints
|
|
213
|
+
? (0, endpoints_1.normalizeEndpoints)(input.endpoints)
|
|
214
|
+
: undefined;
|
|
215
|
+
const row = yield insert(Object.assign({ id, kind: "public", displayName, sipDomain: sipDomain !== null && sipDomain !== void 0 ? sipDomain : null }, (endpoints
|
|
216
|
+
? {
|
|
217
|
+
endpoints: Object.assign(Object.assign({}, endpoints), { updatedAt: now().toISOString() }),
|
|
218
|
+
endpointsAt: now()
|
|
219
|
+
}
|
|
220
|
+
: {})));
|
|
221
|
+
const token = yield issueToken(row);
|
|
222
|
+
logger.info(`public region ${row.ref} (${id}) created by the operator`);
|
|
223
|
+
return Object.assign({ ref: row.ref, id: row.id }, token);
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
/** The caller's private region by id or ref; 404 for anything else. */
|
|
227
|
+
owned(ownerRef, idOrRef) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const row = types_1.REGION_REF.test(idOrRef)
|
|
230
|
+
? yield byRef(idOrRef)
|
|
231
|
+
: yield db.region.findFirst({
|
|
232
|
+
where: { kind: "private", ownerRef, id: idOrRef, deletedAt: null }
|
|
233
|
+
});
|
|
234
|
+
if (!row || row.kind !== "private" || row.ownerRef !== ownerRef)
|
|
235
|
+
throw notFound();
|
|
236
|
+
return row;
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
listOwned(ownerRef) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
return db.region.findMany({
|
|
242
|
+
where: { kind: "private", ownerRef, deletedAt: null },
|
|
243
|
+
orderBy: { createdAt: "asc" }
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
listPublicRows() {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
return db.region.findMany({
|
|
250
|
+
where: { kind: "public", deletedAt: null },
|
|
251
|
+
orderBy: { createdAt: "asc" }
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
listAll() {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
return db.region.findMany({
|
|
258
|
+
where: { deletedAt: null },
|
|
259
|
+
orderBy: { createdAt: "asc" }
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
publicRow,
|
|
264
|
+
anyRow,
|
|
265
|
+
byRef,
|
|
266
|
+
workspaces,
|
|
267
|
+
updateDisplayName(row, displayName) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
return (yield db.region.update({
|
|
270
|
+
where: { ref: row.ref },
|
|
271
|
+
data: { displayName: (0, ids_1.checkDisplayName)(displayName) }
|
|
272
|
+
}));
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
/** A new enrollment token; the current cell keeps working until a cell enrolls with it. */
|
|
276
|
+
reissueToken(row) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
return issueToken(row);
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
/** Revokes the cell now and puts the region back in `waiting`. */
|
|
282
|
+
disconnect(row_1) {
|
|
283
|
+
return __awaiter(this, arguments, void 0, function* (row, reason = "disconnected") {
|
|
284
|
+
yield revokeAll(row.ref, reason);
|
|
285
|
+
const updated = (yield db.region.update({
|
|
286
|
+
where: { ref: row.ref },
|
|
287
|
+
data: {
|
|
288
|
+
state: "waiting",
|
|
289
|
+
cellPublicKey: null,
|
|
290
|
+
lastHeartbeatAt: null,
|
|
291
|
+
enrolledAt: null,
|
|
292
|
+
// The next cell's heartbeat then always asks for fresh endpoints.
|
|
293
|
+
endpointsHash: null
|
|
294
|
+
}
|
|
295
|
+
}));
|
|
296
|
+
logger.info(`region ${row.ref} disconnected (${reason})`);
|
|
297
|
+
return updated;
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
/** Deletes a region no workspace uses and revokes its cell (refused while in use). */
|
|
301
|
+
deleteRegion(row) {
|
|
302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
const using = yield workspaces(row);
|
|
304
|
+
if (using.length)
|
|
305
|
+
throw new types_1.RegionError(409, "region_in_use", `the region is used by ${using.length} workspace(s): ${using
|
|
306
|
+
.map((w) => w.name)
|
|
307
|
+
.join(", ")}`);
|
|
308
|
+
yield db.region.update({
|
|
309
|
+
where: { ref: row.ref },
|
|
310
|
+
data: { deletedAt: now(), state: "waiting", published: false }
|
|
311
|
+
});
|
|
312
|
+
yield revokeAll(row.ref, "region deleted").catch((e) => logger.error(`could not revoke region ${row.ref}: ${e.message}`));
|
|
313
|
+
logger.info(`region ${row.ref} (${row.id}) deleted`);
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
/** Public regions: offered in pickers while connected (PR-19). */
|
|
317
|
+
publish(row) {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
319
|
+
if (row.kind !== "public")
|
|
320
|
+
throw new types_1.RegionError(400, "not_public", "only public regions publish");
|
|
321
|
+
return (yield db.region.update({
|
|
322
|
+
where: { ref: row.ref },
|
|
323
|
+
data: { published: true }
|
|
324
|
+
}));
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
/** Public regions: withdrawn from pickers and the cell's credentials revoked. */
|
|
328
|
+
revoke(row) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
if (row.kind !== "public")
|
|
331
|
+
throw new types_1.RegionError(400, "not_public", "only public regions revoke");
|
|
332
|
+
yield db.region.update({
|
|
333
|
+
where: { ref: row.ref },
|
|
334
|
+
data: { published: false }
|
|
335
|
+
});
|
|
336
|
+
return service.disconnect(row, "revoked by the operator");
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
/** Exchanges a one-time token for cell credentials (contract §2). */
|
|
340
|
+
enroll(body) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
343
|
+
if (!(body === null || body === void 0 ? void 0 : body.token) || typeof body.token !== "string")
|
|
344
|
+
throw new types_1.RegionError(400, "token_invalid", "token is required");
|
|
345
|
+
let claims;
|
|
346
|
+
try {
|
|
347
|
+
claims = signer().verify(body.token);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
if (e instanceof enrollmentToken_1.EnrollmentTokenError)
|
|
351
|
+
throw new types_1.RegionError(e.code === "token_expired" ? 410 : 400, e.code);
|
|
352
|
+
throw e;
|
|
353
|
+
}
|
|
354
|
+
const publicKey = String((_a = body.publicKey) !== null && _a !== void 0 ? _a : "");
|
|
355
|
+
if (Buffer.from(publicKey, "base64url").length !== 32)
|
|
356
|
+
throw new types_1.RegionError(400, "bad_request", "publicKey must be the region's Ed25519 public key (32 bytes, base64url)");
|
|
357
|
+
const tokenRow = yield db.regionToken.findUnique({
|
|
358
|
+
where: { jti: claims.jti }
|
|
359
|
+
});
|
|
360
|
+
if (!tokenRow || tokenRow.regionRef !== claims.sub)
|
|
361
|
+
throw new types_1.RegionError(400, "token_invalid", "unknown token");
|
|
362
|
+
if (tokenRow.usedAt)
|
|
363
|
+
throw new types_1.RegionError(409, "token_used");
|
|
364
|
+
const row = yield db.region.findUnique({
|
|
365
|
+
where: { ref: claims.sub }
|
|
366
|
+
});
|
|
367
|
+
if (!row)
|
|
368
|
+
throw new types_1.RegionError(404, "region_not_found");
|
|
369
|
+
if (row.deletedAt)
|
|
370
|
+
throw new types_1.RegionError(409, "region_deleted");
|
|
371
|
+
natsAuth();
|
|
372
|
+
// Spend the token first: of two concurrent enrollments only one gets here.
|
|
373
|
+
const spent = yield db.regionToken.updateMany({
|
|
374
|
+
where: { jti: claims.jti, usedAt: null },
|
|
375
|
+
data: { usedAt: now() }
|
|
376
|
+
});
|
|
377
|
+
if (spent.count !== 1)
|
|
378
|
+
throw new types_1.RegionError(409, "token_used");
|
|
379
|
+
yield revokeAll(row.ref, "re-enrolled");
|
|
380
|
+
const user = natsAuth().issue(row.ref);
|
|
381
|
+
yield db.regionCredential.create({
|
|
382
|
+
data: {
|
|
383
|
+
userPublicKey: user.publicKey,
|
|
384
|
+
regionRef: row.ref,
|
|
385
|
+
issuedAt: now()
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
const components = {
|
|
389
|
+
roomrNodes: Number((_c = (_b = body.components) === null || _b === void 0 ? void 0 : _b.roomrNodes) !== null && _c !== void 0 ? _c : 0),
|
|
390
|
+
appbridges: Number((_e = (_d = body.components) === null || _d === void 0 ? void 0 : _d.appbridges) !== null && _e !== void 0 ? _e : 0),
|
|
391
|
+
autopilot: Boolean((_f = body.components) === null || _f === void 0 ? void 0 : _f.autopilot)
|
|
392
|
+
};
|
|
393
|
+
const updated = yield db.region.update({
|
|
394
|
+
where: { ref: row.ref },
|
|
395
|
+
data: {
|
|
396
|
+
state: "enrolled",
|
|
397
|
+
cellPublicKey: publicKey,
|
|
398
|
+
version: body.version ? String(body.version) : null,
|
|
399
|
+
components,
|
|
400
|
+
enrolledAt: now(),
|
|
401
|
+
lastHeartbeatAt: null,
|
|
402
|
+
reportedConfig: 0,
|
|
403
|
+
endpointsHash: null
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
const bound = yield workspaces(row).catch(() => []);
|
|
407
|
+
logger.info(`region ${row.ref} (${row.id}) enrolled (version ${(_g = body.version) !== null && _g !== void 0 ? _g : "?"}, ${bound.length} workspace(s))`);
|
|
408
|
+
return {
|
|
409
|
+
regionRef: row.ref,
|
|
410
|
+
regionId: row.id,
|
|
411
|
+
kind: row.kind,
|
|
412
|
+
sipDomain: (_h = row.sipDomain) !== null && _h !== void 0 ? _h : null,
|
|
413
|
+
workspaceRefs: bound.map((w) => w.accessKeyId),
|
|
414
|
+
leafUrl: claims.leaf,
|
|
415
|
+
credentials: user.creds,
|
|
416
|
+
subjects: (0, types_1.subjects)(row.ref).all,
|
|
417
|
+
configVersion: updated.configVersion
|
|
418
|
+
};
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
/** Records a heartbeat; returns the row, or undefined when the region is not enrolled. */
|
|
422
|
+
heartbeat(regionRef, hb) {
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
var _a, _b, _c, _d, _e;
|
|
425
|
+
const row = yield byRef(regionRef);
|
|
426
|
+
if (!row || row.state !== "enrolled")
|
|
427
|
+
return undefined;
|
|
428
|
+
const c = (_a = hb.components) !== null && _a !== void 0 ? _a : {};
|
|
429
|
+
return (yield db.region.update({
|
|
430
|
+
where: { ref: regionRef },
|
|
431
|
+
data: {
|
|
432
|
+
version: hb.version ? String(hb.version) : row.version,
|
|
433
|
+
components: {
|
|
434
|
+
roomrNodes: Number((_b = c.roomrNodes) !== null && _b !== void 0 ? _b : 0),
|
|
435
|
+
appbridges: Number((_c = c.appbridges) !== null && _c !== void 0 ? _c : 0),
|
|
436
|
+
autopilot: Boolean(c.autopilot)
|
|
437
|
+
},
|
|
438
|
+
activeCalls: Number((_d = hb.activeCalls) !== null && _d !== void 0 ? _d : 0),
|
|
439
|
+
secretsSet: Array.isArray(hb.secretsSet)
|
|
440
|
+
? hb.secretsSet.map(String)
|
|
441
|
+
: [],
|
|
442
|
+
reportedConfig: Number((_e = hb.configVersion) !== null && _e !== void 0 ? _e : 0),
|
|
443
|
+
lastHeartbeatAt: now()
|
|
444
|
+
}
|
|
445
|
+
}));
|
|
446
|
+
});
|
|
447
|
+
},
|
|
448
|
+
/** Stores the connection details a cell reported (contract §3); undefined when ignored. */
|
|
449
|
+
reportEndpoints(regionRef, body) {
|
|
450
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
451
|
+
const row = yield byRef(regionRef);
|
|
452
|
+
if (!row || row.state !== "enrolled")
|
|
453
|
+
return undefined;
|
|
454
|
+
const endpoints = (0, endpoints_1.normalizeEndpoints)(body);
|
|
455
|
+
if (!endpoints)
|
|
456
|
+
return undefined;
|
|
457
|
+
return (yield db.region.update({
|
|
458
|
+
where: { ref: regionRef },
|
|
459
|
+
data: {
|
|
460
|
+
endpoints: Object.assign(Object.assign({}, endpoints), { updatedAt: now().toISOString() }),
|
|
461
|
+
// Hash what the cell sent (as its heartbeats do), not the cleaned copy.
|
|
462
|
+
endpointsHash: (0, endpoints_1.endpointsHash)(body),
|
|
463
|
+
endpointsAt: now()
|
|
464
|
+
}
|
|
465
|
+
}));
|
|
466
|
+
});
|
|
467
|
+
},
|
|
468
|
+
/** Whether to ask the cell for its endpoints after this heartbeat (RE-B2). */
|
|
469
|
+
needsEndpoints(row, hb) {
|
|
470
|
+
if (typeof hb.endpointsHash === "string" && hb.endpointsHash)
|
|
471
|
+
return hb.endpointsHash !== row.endpointsHash;
|
|
472
|
+
return !row.endpoints;
|
|
473
|
+
},
|
|
474
|
+
statusOf(row) {
|
|
475
|
+
return (0, status_1.regionStatus)(row, {
|
|
476
|
+
now: now(),
|
|
477
|
+
currentVersion: config.currentVersion,
|
|
478
|
+
offlineAfterMs: config.offlineAfterMs
|
|
479
|
+
});
|
|
480
|
+
},
|
|
481
|
+
/** The region row a workspace is bound to; undefined for a configured public region. */
|
|
482
|
+
regionOfWorkspace(accessKeyId) {
|
|
483
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
const ws = yield directory.workspace(accessKeyId);
|
|
485
|
+
if (!ws)
|
|
486
|
+
return undefined;
|
|
487
|
+
return service.regionByKey(ws.region);
|
|
488
|
+
});
|
|
489
|
+
},
|
|
490
|
+
/** The row for a `Workspace.region` value (a private ref or a public id). */
|
|
491
|
+
regionByKey(key) {
|
|
492
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
493
|
+
if (!key)
|
|
494
|
+
return undefined;
|
|
495
|
+
return types_1.REGION_REF.test(key) ? byRef(key) : publicRow(key);
|
|
496
|
+
});
|
|
497
|
+
},
|
|
498
|
+
/**
|
|
499
|
+
* Minutes reported by a region this calendar month (UTC), for one workspace or all of them.
|
|
500
|
+
* Shown next to the flat fee, never billed (PR-11, AO-B5).
|
|
501
|
+
*/
|
|
502
|
+
minutesThisMonth(row, accessKeyId) {
|
|
503
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
504
|
+
const period = now().toISOString().slice(0, 7);
|
|
505
|
+
const rows = yield db.regionUsage.findMany({
|
|
506
|
+
where: Object.assign({ regionRef: row.ref, period }, (accessKeyId ? { accessKeyId } : {})),
|
|
507
|
+
select: { minutes: true }
|
|
508
|
+
});
|
|
509
|
+
return rows.reduce((sum, r) => sum + r.minutes, 0);
|
|
510
|
+
});
|
|
511
|
+
},
|
|
512
|
+
/** Whether a workspace is bound to this region (PR-14: the cloud checks every record). */
|
|
513
|
+
serves(row, accessKeyId) {
|
|
514
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
515
|
+
if (typeof accessKeyId !== "string" || !accessKeyId)
|
|
516
|
+
return false;
|
|
517
|
+
const ws = yield directory.workspace(accessKeyId);
|
|
518
|
+
return !!ws && ws.region === (0, types_1.regionKey)(row);
|
|
519
|
+
});
|
|
520
|
+
},
|
|
521
|
+
/**
|
|
522
|
+
* Migration from the old model (one workspace per private region): a private region without
|
|
523
|
+
* an owner gets its workspace's owner (RW-B3). Identity has its own database, so this runs at
|
|
524
|
+
* start instead of in SQL.
|
|
525
|
+
*/
|
|
526
|
+
migrateLegacyOwners() {
|
|
527
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
528
|
+
const rows = yield db.region.findMany({
|
|
529
|
+
where: { kind: "private", ownerRef: null, deletedAt: null }
|
|
530
|
+
});
|
|
531
|
+
let n = 0;
|
|
532
|
+
for (const row of rows) {
|
|
533
|
+
if (!row.accessKeyId)
|
|
534
|
+
continue;
|
|
535
|
+
const ws = yield directory.workspace(row.accessKeyId);
|
|
536
|
+
if (!ws)
|
|
537
|
+
continue;
|
|
538
|
+
try {
|
|
539
|
+
yield db.region.update({
|
|
540
|
+
where: { ref: row.ref },
|
|
541
|
+
data: { ownerRef: ws.ownerRef }
|
|
542
|
+
});
|
|
543
|
+
n++;
|
|
544
|
+
}
|
|
545
|
+
catch (e) {
|
|
546
|
+
logger.warn(`could not set the owner of region ${row.ref}: ${e.message}`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (n)
|
|
550
|
+
logger.info(`regions: ${n} legacy private region(s) got their owner`);
|
|
551
|
+
return n;
|
|
552
|
+
});
|
|
553
|
+
},
|
|
554
|
+
/** Re-pushes every revocation (on startup, so a restarted hub converges). */
|
|
555
|
+
pushRevocations
|
|
556
|
+
};
|
|
557
|
+
return service;
|
|
558
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SnapshotSources } from "./configSync";
|
|
2
|
+
import { RegionsDb } from "./types";
|
|
3
|
+
type Handler = (call: unknown, callback: (err: unknown, res?: {
|
|
4
|
+
items?: unknown[];
|
|
5
|
+
nextPageToken?: string;
|
|
6
|
+
}) => void) => unknown;
|
|
7
|
+
/** Every item of a workspace from a gRPC list handler (the sipnet services filter by workspace). */
|
|
8
|
+
export declare function listAll(handler: Handler | undefined, accessKeyId: string): Promise<unknown[]>;
|
|
9
|
+
/**
|
|
10
|
+
* The production snapshot sources: Prisma for apps, agents, webhooks, the catalog and the
|
|
11
|
+
* recording policy; the Routr-backed gRPC handlers for numbers and Routr resources.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createSnapshotSources(deps: {
|
|
14
|
+
db: RegionsDb;
|
|
15
|
+
/** The loaded services' handlers, by method name (listNumbers, listDomains, …). */
|
|
16
|
+
handlers: Record<string, Handler | undefined>;
|
|
17
|
+
/** Workspace-wide defaults (features.calls). */
|
|
18
|
+
callFeatures?: Record<string, unknown>;
|
|
19
|
+
}): SnapshotSources;
|
|
20
|
+
export {};
|