@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,391 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.regionView = regionView;
|
|
16
|
+
exports.configuredView = configuredView;
|
|
17
|
+
exports.summary = summary;
|
|
18
|
+
exports.offeredPublicRegions = offeredPublicRegions;
|
|
19
|
+
exports.createRegionsRouter = createRegionsRouter;
|
|
20
|
+
/**
|
|
21
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
22
|
+
* http://github.com/fonoster/fonoster
|
|
23
|
+
*
|
|
24
|
+
* This file is part of Fonoster
|
|
25
|
+
*
|
|
26
|
+
* Licensed under the MIT License (the "License");
|
|
27
|
+
* you may not use this file except in compliance with
|
|
28
|
+
* the License. You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* https://opensource.org/licenses/MIT
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
*/
|
|
38
|
+
const crypto_1 = require("crypto");
|
|
39
|
+
const logger_1 = require("@fonoster/logger");
|
|
40
|
+
const express_1 = __importDefault(require("express"));
|
|
41
|
+
const httpAuth_1 = require("./httpAuth");
|
|
42
|
+
const types_1 = require("./types");
|
|
43
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
44
|
+
function workspaceDomains(row, bound, configSync) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const out = new Map();
|
|
48
|
+
if (!bound.length)
|
|
49
|
+
return out;
|
|
50
|
+
const snap = yield configSync.snapshot(row).catch(() => undefined);
|
|
51
|
+
for (const w of bound)
|
|
52
|
+
out.set(w.accessKeyId, (_b = (_a = snap === null || snap === void 0 ? void 0 : snap.workspaces[w.accessKeyId]) === null || _a === void 0 ? void 0 : _a.domain) !== null && _b !== void 0 ? _b : null);
|
|
53
|
+
return out;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** The region view (contract §0 `Region`; the dashboard's shape). */
|
|
57
|
+
function regionView(row_1, service_1) {
|
|
58
|
+
return __awaiter(this, arguments, void 0, function* (row, service, options = {}) {
|
|
59
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
60
|
+
const s = service.statusOf(row);
|
|
61
|
+
const c = ((_a = row.components) !== null && _a !== void 0 ? _a : {});
|
|
62
|
+
const { configSync } = options;
|
|
63
|
+
const needed = configSync
|
|
64
|
+
? (yield configSync.secretsNeeded(row, (_b = options.workspace) === null || _b === void 0 ? void 0 : _b.accessKeyId))
|
|
65
|
+
.secrets
|
|
66
|
+
: [];
|
|
67
|
+
const set = new Set((_c = row.secretsSet) !== null && _c !== void 0 ? _c : []);
|
|
68
|
+
const bound = options.showWorkspaces ? yield service.workspaces(row) : [];
|
|
69
|
+
const forDomains = options.workspace ? [options.workspace] : bound;
|
|
70
|
+
const domains = configSync
|
|
71
|
+
? yield workspaceDomains(row, forDomains, configSync)
|
|
72
|
+
: new Map();
|
|
73
|
+
const endpoints = row.endpoints
|
|
74
|
+
? Object.assign(Object.assign({}, row.endpoints), { sipDomain: (_d = row.sipDomain) !== null && _d !== void 0 ? _d : undefined }) : row.sipDomain
|
|
75
|
+
? {
|
|
76
|
+
sip: [],
|
|
77
|
+
signalingAddresses: [],
|
|
78
|
+
mediaAddresses: [],
|
|
79
|
+
sipDomain: row.sipDomain
|
|
80
|
+
}
|
|
81
|
+
: undefined;
|
|
82
|
+
const lastSeenAt = (_e = row.lastHeartbeatAt) === null || _e === void 0 ? void 0 : _e.toISOString();
|
|
83
|
+
const minutesThisMonth = row.kind === "private"
|
|
84
|
+
? yield service
|
|
85
|
+
.minutesThisMonth(row, (_f = options.workspace) === null || _f === void 0 ? void 0 : _f.accessKeyId)
|
|
86
|
+
.catch(() => undefined)
|
|
87
|
+
: undefined;
|
|
88
|
+
return {
|
|
89
|
+
ref: row.ref,
|
|
90
|
+
id: row.id,
|
|
91
|
+
kind: row.kind,
|
|
92
|
+
name: row.displayName || row.id,
|
|
93
|
+
displayName: row.displayName || row.id,
|
|
94
|
+
default: !!options.isDefault,
|
|
95
|
+
sipDomain: (_g = row.sipDomain) !== null && _g !== void 0 ? _g : undefined,
|
|
96
|
+
ownerRef: (_h = row.ownerRef) !== null && _h !== void 0 ? _h : undefined,
|
|
97
|
+
published: row.kind === "public" ? row.published : undefined,
|
|
98
|
+
status: s.status,
|
|
99
|
+
state: s.status,
|
|
100
|
+
reason: s.reason,
|
|
101
|
+
unsupportedReason: s.status === "unsupported" ? s.reason : undefined,
|
|
102
|
+
requiredVersion: s.requiredVersion,
|
|
103
|
+
version: (_j = row.version) !== null && _j !== void 0 ? _j : undefined,
|
|
104
|
+
lastHeartbeatAt: lastSeenAt,
|
|
105
|
+
lastSeenAt,
|
|
106
|
+
enrolledAt: (_k = row.enrolledAt) === null || _k === void 0 ? void 0 : _k.toISOString(),
|
|
107
|
+
components: {
|
|
108
|
+
roomrNodes: (_l = c.roomrNodes) !== null && _l !== void 0 ? _l : 0,
|
|
109
|
+
appbridges: (_m = c.appbridges) !== null && _m !== void 0 ? _m : 0,
|
|
110
|
+
autopilot: (_o = c.autopilot) !== null && _o !== void 0 ? _o : false
|
|
111
|
+
},
|
|
112
|
+
roomrNodes: (_p = c.roomrNodes) !== null && _p !== void 0 ? _p : 0,
|
|
113
|
+
appbridges: (_q = c.appbridges) !== null && _q !== void 0 ? _q : 0,
|
|
114
|
+
activeCalls: row.activeCalls,
|
|
115
|
+
configVersion: row.configVersion,
|
|
116
|
+
reportedConfigVersion: row.reportedConfig,
|
|
117
|
+
workspaces: options.showWorkspaces
|
|
118
|
+
? bound.map((w) => {
|
|
119
|
+
var _a;
|
|
120
|
+
return ({
|
|
121
|
+
ref: w.ref,
|
|
122
|
+
accessKeyId: w.accessKeyId,
|
|
123
|
+
name: w.name,
|
|
124
|
+
domain: (_a = domains.get(w.accessKeyId)) !== null && _a !== void 0 ? _a : undefined
|
|
125
|
+
});
|
|
126
|
+
})
|
|
127
|
+
: undefined,
|
|
128
|
+
workspaceDomain: options.workspace
|
|
129
|
+
? ((_r = domains.get(options.workspace.accessKeyId)) !== null && _r !== void 0 ? _r : undefined)
|
|
130
|
+
: undefined,
|
|
131
|
+
secretsNeeded: needed.map((n) => n.name),
|
|
132
|
+
secretsSet: [...set].sort(),
|
|
133
|
+
secrets: needed.map((n) => ({
|
|
134
|
+
name: n.name,
|
|
135
|
+
usedBy: n.usedBy,
|
|
136
|
+
set: set.has(n.name)
|
|
137
|
+
})),
|
|
138
|
+
endpoints,
|
|
139
|
+
monthlyFeeCents: row.kind === "private" ? ((_s = options.monthlyFeeCents) !== null && _s !== void 0 ? _s : null) : null,
|
|
140
|
+
/** Usage shown with the fee, not billed (PR-11). */
|
|
141
|
+
minutesThisMonth
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** A configured public region's view (always connected; contract §0, §4). */
|
|
146
|
+
function configuredView(r) {
|
|
147
|
+
return {
|
|
148
|
+
ref: r.id,
|
|
149
|
+
id: r.id,
|
|
150
|
+
kind: "public",
|
|
151
|
+
name: r.name,
|
|
152
|
+
displayName: r.name,
|
|
153
|
+
default: !!r.default,
|
|
154
|
+
status: "connected",
|
|
155
|
+
state: "connected",
|
|
156
|
+
components: { roomrNodes: 0, appbridges: 0, autopilot: false },
|
|
157
|
+
secretsNeeded: [],
|
|
158
|
+
secretsSet: [],
|
|
159
|
+
secrets: [],
|
|
160
|
+
endpoints: r.endpoints,
|
|
161
|
+
monthlyFeeCents: null
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const OFFERED = ["connected", "degraded"];
|
|
165
|
+
function summary(row, service, isDefault = false, workspaces) {
|
|
166
|
+
var _a;
|
|
167
|
+
const status = service.statusOf(row).status;
|
|
168
|
+
return Object.assign(Object.assign({ ref: row.ref, id: row.id, name: row.displayName || row.id, displayName: row.displayName || row.id, kind: row.kind, default: isDefault, status, state: status, sipDomain: (_a = row.sipDomain) !== null && _a !== void 0 ? _a : undefined }, (workspaces !== undefined ? { workspaces } : {})), (row.kind === "public" ? { published: row.published } : {}));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The public regions a new workspace can pick (PR-19, contract §0): configured ones (the fallback;
|
|
172
|
+
* always offered) and enrolled rows that are published and connected. A row with a configured id
|
|
173
|
+
* replaces the configured entry while it is offered.
|
|
174
|
+
*/
|
|
175
|
+
function offeredPublicRegions(service, configured) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
const rows = yield service.listPublicRows();
|
|
178
|
+
const offered = rows.filter((r) => r.published && OFFERED.includes(service.statusOf(r).status));
|
|
179
|
+
const out = [];
|
|
180
|
+
for (const c of configured) {
|
|
181
|
+
const row = offered.find((r) => r.id === c.id);
|
|
182
|
+
out.push(row
|
|
183
|
+
? summary(row, service, !!c.default)
|
|
184
|
+
: {
|
|
185
|
+
id: c.id,
|
|
186
|
+
name: c.name,
|
|
187
|
+
displayName: c.name,
|
|
188
|
+
kind: "public",
|
|
189
|
+
default: !!c.default,
|
|
190
|
+
status: "connected",
|
|
191
|
+
state: "connected"
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
for (const row of offered)
|
|
195
|
+
if (!configured.some((c) => c.id === row.id))
|
|
196
|
+
out.push(summary(row, service, false));
|
|
197
|
+
return out;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const sha = (v) => (0, crypto_1.createHash)("sha256").update(v).digest();
|
|
201
|
+
/**
|
|
202
|
+
* Regions over HTTP (on the HTTP bridge; contract §0):
|
|
203
|
+
*
|
|
204
|
+
* GET /.well-known/region-keys.json region-signing public keys (JWK Set)
|
|
205
|
+
* POST /api/regions/enroll a region's enrollment (§2; the token is the auth)
|
|
206
|
+
* GET /api/regions offered public regions + the caller's private ones
|
|
207
|
+
* POST /api/regions create a private region (user)
|
|
208
|
+
* GET /api/regions/current the workspace's region (any member)
|
|
209
|
+
* GET /api/regions/:region one region (owner, or a public one)
|
|
210
|
+
* PATCH /api/regions/:region display name (owner)
|
|
211
|
+
* POST /api/regions/:region/token re-issue an enrollment token (owner)
|
|
212
|
+
* POST /api/regions/:region/disconnect revoke the cell (owner)
|
|
213
|
+
* DELETE /api/regions/:region delete (owner; refused while in use)
|
|
214
|
+
* /api/admin/regions… public regions (operator key only, PR-19)
|
|
215
|
+
*/
|
|
216
|
+
function createRegionsRouter(deps) {
|
|
217
|
+
var _a;
|
|
218
|
+
const { service } = deps;
|
|
219
|
+
const router = express_1.default.Router();
|
|
220
|
+
const tokenOptions = (_a = deps.identityTokenOptions) !== null && _a !== void 0 ? _a : {};
|
|
221
|
+
const workspaceAuth = (0, httpAuth_1.createHttpAuth)(deps.identityPublicKey, tokenOptions);
|
|
222
|
+
const userAuth = (0, httpAuth_1.createUserAuth)(deps.identityPublicKey, tokenOptions);
|
|
223
|
+
const maybeUser = (0, httpAuth_1.optionalUser)(deps.identityPublicKey, tokenOptions);
|
|
224
|
+
const caller = (res) => res.locals.caller;
|
|
225
|
+
const user = (res) => res.locals.user;
|
|
226
|
+
const json = express_1.default.json({ limit: "64kb" });
|
|
227
|
+
const handle = (fn) => (req, res) => fn(req, res).catch((e) => {
|
|
228
|
+
if (e instanceof types_1.RegionError)
|
|
229
|
+
return res
|
|
230
|
+
.status(e.status)
|
|
231
|
+
.json({ error: e.code, message: e.message });
|
|
232
|
+
logger.error(`regions API: ${e.message}`);
|
|
233
|
+
res.status(500).json({ error: "internal" });
|
|
234
|
+
});
|
|
235
|
+
const defaultId = () => { var _a, _b; return (_b = ((_a = deps.publicRegions.find((p) => p.default)) !== null && _a !== void 0 ? _a : deps.publicRegions[0])) === null || _b === void 0 ? void 0 : _b.id; };
|
|
236
|
+
const view = (row, extra = {}) => {
|
|
237
|
+
var _a;
|
|
238
|
+
return regionView(row, service, Object.assign({ configSync: deps.configSync, monthlyFeeCents: (_a = deps.monthlyFeeCents) !== null && _a !== void 0 ? _a : null, isDefault: row.kind === "public" && row.id === defaultId() }, extra));
|
|
239
|
+
};
|
|
240
|
+
router.get("/.well-known/region-keys.json", (_req, res) => {
|
|
241
|
+
res.setHeader("cache-control", "public, max-age=300");
|
|
242
|
+
res.json(deps.signer ? deps.signer.jwks() : { keys: [] });
|
|
243
|
+
});
|
|
244
|
+
router.post("/api/regions/enroll", json, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
var _a;
|
|
246
|
+
res.json(yield service.enroll((_a = req.body) !== null && _a !== void 0 ? _a : {}));
|
|
247
|
+
})));
|
|
248
|
+
// ---- Admin API: the operator key only (PR-19) ------------------------------------------
|
|
249
|
+
const operator = (req, res) => {
|
|
250
|
+
var _a;
|
|
251
|
+
if (!deps.operatorKey) {
|
|
252
|
+
res.status(404).json({ error: "not_found" });
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
const given = String((_a = req.headers["x-operator-key"]) !== null && _a !== void 0 ? _a : "");
|
|
256
|
+
if (!given || !(0, crypto_1.timingSafeEqual)(sha(given), sha(deps.operatorKey))) {
|
|
257
|
+
res.status(401).json({
|
|
258
|
+
error: "operator_key_invalid",
|
|
259
|
+
message: "the region admin API needs the operator key (x-operator-key)"
|
|
260
|
+
});
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
return true;
|
|
264
|
+
};
|
|
265
|
+
const adminRow = (req) => __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
const row = yield service.anyRow(String(req.params.region));
|
|
267
|
+
if (!row)
|
|
268
|
+
throw new types_1.RegionError(404, "region_not_found", "no such region");
|
|
269
|
+
return row;
|
|
270
|
+
});
|
|
271
|
+
router.get("/api/admin/regions", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
if (!operator(req, res))
|
|
273
|
+
return;
|
|
274
|
+
const rows = yield service.listAll();
|
|
275
|
+
const items = [];
|
|
276
|
+
for (const row of rows)
|
|
277
|
+
items.push(Object.assign(Object.assign({}, (yield view(row))), { workspaceCount: (yield service.workspaces(row)).length }));
|
|
278
|
+
for (const c of deps.publicRegions)
|
|
279
|
+
if (!rows.some((r) => r.kind === "public" && r.id === c.id))
|
|
280
|
+
items.push(Object.assign(Object.assign({}, configuredView(c)), { configured: true }));
|
|
281
|
+
res.json({ items });
|
|
282
|
+
})));
|
|
283
|
+
router.post("/api/admin/regions", json, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
var _a, _b;
|
|
285
|
+
if (!operator(req, res))
|
|
286
|
+
return;
|
|
287
|
+
const b = (_a = req.body) !== null && _a !== void 0 ? _a : {};
|
|
288
|
+
res.status(201).json(yield service.createPublicRegion({
|
|
289
|
+
id: b.id,
|
|
290
|
+
displayName: (_b = b.displayName) !== null && _b !== void 0 ? _b : b.name,
|
|
291
|
+
sipDomain: b.sipDomain,
|
|
292
|
+
endpoints: b.endpoints
|
|
293
|
+
}));
|
|
294
|
+
})));
|
|
295
|
+
router.post("/api/admin/regions/:region/token", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
if (!operator(req, res))
|
|
297
|
+
return;
|
|
298
|
+
res.json(yield service.reissueToken(yield adminRow(req)));
|
|
299
|
+
})));
|
|
300
|
+
router.post("/api/admin/regions/:region/publish", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
301
|
+
if (!operator(req, res))
|
|
302
|
+
return;
|
|
303
|
+
const row = yield service.publish(yield adminRow(req));
|
|
304
|
+
logger.info(`public region ${row.id} published`);
|
|
305
|
+
res.json(yield view(row));
|
|
306
|
+
})));
|
|
307
|
+
router.post("/api/admin/regions/:region/revoke", handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
308
|
+
if (!operator(req, res))
|
|
309
|
+
return;
|
|
310
|
+
const row = yield service.revoke(yield adminRow(req));
|
|
311
|
+
logger.info(`public region ${row.id} revoked`);
|
|
312
|
+
res.json(yield view(row));
|
|
313
|
+
})));
|
|
314
|
+
// ---- User API -----------------------------------------------------------------------------
|
|
315
|
+
router.get("/api/regions", maybeUser, handle((_req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
316
|
+
const items = yield offeredPublicRegions(service, deps.publicRegions);
|
|
317
|
+
const u = res.locals.user;
|
|
318
|
+
if (u)
|
|
319
|
+
for (const row of yield service.listOwned(u.userRef))
|
|
320
|
+
items.push(summary(row, service, false, (yield service.workspaces(row)).length));
|
|
321
|
+
res.json({ items });
|
|
322
|
+
})));
|
|
323
|
+
router.post("/api/regions", userAuth, json, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
var _a, _b;
|
|
325
|
+
const b = (_a = req.body) !== null && _a !== void 0 ? _a : {};
|
|
326
|
+
res.status(201).json(yield service.createRegion(user(res).userRef, {
|
|
327
|
+
id: b.id,
|
|
328
|
+
displayName: (_b = b.displayName) !== null && _b !== void 0 ? _b : b.name,
|
|
329
|
+
sipDomain: b.sipDomain
|
|
330
|
+
}));
|
|
331
|
+
})));
|
|
332
|
+
router.get("/api/regions/current", workspaceAuth, handle((_req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
333
|
+
var _a, _b, _c, _d;
|
|
334
|
+
const accessKeyId = caller(res).accessKeyId;
|
|
335
|
+
const ws = yield service.directory.workspace(accessKeyId);
|
|
336
|
+
const key = (_b = (_a = ws === null || ws === void 0 ? void 0 : ws.region) !== null && _a !== void 0 ? _a : defaultId()) !== null && _b !== void 0 ? _b : "default";
|
|
337
|
+
const row = yield service.regionByKey(key);
|
|
338
|
+
if (row && ws)
|
|
339
|
+
return res.json(yield view(row, { workspace: ws }));
|
|
340
|
+
const configured = (_d = (_c = deps.publicRegions.find((p) => p.id === key)) !== null && _c !== void 0 ? _c : deps.publicRegions.find((p) => p.default)) !== null && _d !== void 0 ? _d : deps.publicRegions[0];
|
|
341
|
+
res.json(configuredView(configured));
|
|
342
|
+
})));
|
|
343
|
+
/** The caller's private region; for reads, also a public region. */
|
|
344
|
+
const regionFor = (req, res, write) => __awaiter(this, void 0, void 0, function* () {
|
|
345
|
+
const idOrRef = String(req.params.region);
|
|
346
|
+
try {
|
|
347
|
+
return yield service.owned(user(res).userRef, idOrRef);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
if (write)
|
|
351
|
+
throw e;
|
|
352
|
+
const row = yield service.publicRow(idOrRef);
|
|
353
|
+
if (row)
|
|
354
|
+
return row;
|
|
355
|
+
throw e;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
router.get("/api/regions/:region", userAuth, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
359
|
+
const idOrRef = String(req.params.region);
|
|
360
|
+
let row;
|
|
361
|
+
try {
|
|
362
|
+
row = yield regionFor(req, res, false);
|
|
363
|
+
}
|
|
364
|
+
catch (e) {
|
|
365
|
+
const c = deps.publicRegions.find((p) => p.id === idOrRef);
|
|
366
|
+
if (c)
|
|
367
|
+
return res.json(configuredView(c));
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
370
|
+
res.json(yield view(row, { showWorkspaces: row.kind === "private" }));
|
|
371
|
+
})));
|
|
372
|
+
router.patch("/api/regions/:region", userAuth, json, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
373
|
+
var _a, _b, _c;
|
|
374
|
+
const row = yield regionFor(req, res, true);
|
|
375
|
+
const updated = yield service.updateDisplayName(row, (_b = (_a = req.body) === null || _a === void 0 ? void 0 : _a.displayName) !== null && _b !== void 0 ? _b : (_c = req.body) === null || _c === void 0 ? void 0 : _c.name);
|
|
376
|
+
res.json(yield view(updated, { showWorkspaces: true }));
|
|
377
|
+
})));
|
|
378
|
+
router.post("/api/regions/:region/token", userAuth, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
379
|
+
res.json(yield service.reissueToken(yield regionFor(req, res, true)));
|
|
380
|
+
})));
|
|
381
|
+
router.post("/api/regions/:region/disconnect", userAuth, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
yield service.disconnect(yield regionFor(req, res, true));
|
|
383
|
+
res.json({ status: "waiting" });
|
|
384
|
+
})));
|
|
385
|
+
router.delete("/api/regions/:region", userAuth, handle((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
386
|
+
const row = yield regionFor(req, res, true);
|
|
387
|
+
yield service.deleteRegion(row);
|
|
388
|
+
res.json({ ref: row.ref });
|
|
389
|
+
})));
|
|
390
|
+
return router;
|
|
391
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const SIP_TRANSPORTS: readonly ["udp", "tcp", "tls", "ws", "wss"];
|
|
2
|
+
export type SipTransport = (typeof SIP_TRANSPORTS)[number];
|
|
3
|
+
/** A region's connection details (contract §3 `region.R.endpoints`, §3a). */
|
|
4
|
+
export type RegionEndpoints = {
|
|
5
|
+
sip: {
|
|
6
|
+
host: string;
|
|
7
|
+
port: number;
|
|
8
|
+
transport: SipTransport;
|
|
9
|
+
}[];
|
|
10
|
+
signalingAddresses: string[];
|
|
11
|
+
mediaAddresses: string[];
|
|
12
|
+
rtpPorts?: {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
};
|
|
16
|
+
updatedAt?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Validates and cleans what a cell (or the config) reports: unknown transports, bad hosts and
|
|
20
|
+
* ports are dropped; undefined when nothing usable is left.
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeEndpoints(body: unknown): RegionEndpoints | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* `endpointsHash` (contract §3, RE-B2), the region agent's algorithm (RC-B16): the first 16 hex
|
|
25
|
+
* characters of the sha256 of
|
|
26
|
+
* `{"sip":[[host,port,transport]…],"signalingAddresses":[…],"mediaAddresses":[…],"rtpPorts":[min,max]|null}`
|
|
27
|
+
* in the order the cell sent them; `updatedAt` left out.
|
|
28
|
+
*/
|
|
29
|
+
export declare function endpointsHash(e: {
|
|
30
|
+
sip?: {
|
|
31
|
+
host: unknown;
|
|
32
|
+
port: unknown;
|
|
33
|
+
transport: unknown;
|
|
34
|
+
}[];
|
|
35
|
+
signalingAddresses?: unknown[];
|
|
36
|
+
mediaAddresses?: unknown[];
|
|
37
|
+
rtpPorts?: {
|
|
38
|
+
min: unknown;
|
|
39
|
+
max: unknown;
|
|
40
|
+
} | null;
|
|
41
|
+
}): string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIP_TRANSPORTS = void 0;
|
|
4
|
+
exports.normalizeEndpoints = normalizeEndpoints;
|
|
5
|
+
exports.endpointsHash = endpointsHash;
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Fonoster
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
const crypto_1 = require("crypto");
|
|
25
|
+
exports.SIP_TRANSPORTS = ["udp", "tcp", "tls", "ws", "wss"];
|
|
26
|
+
const HOST = /^[A-Za-z0-9.:\-[\]]{1,253}$/;
|
|
27
|
+
const port = (v) => {
|
|
28
|
+
const n = Number(v);
|
|
29
|
+
return Number.isInteger(n) && n > 0 && n < 65536 ? n : undefined;
|
|
30
|
+
};
|
|
31
|
+
const addresses = (v) => Array.isArray(v)
|
|
32
|
+
? [
|
|
33
|
+
...new Set(v.map((a) => String(a).trim()).filter((a) => a && HOST.test(a)))
|
|
34
|
+
].slice(0, 32)
|
|
35
|
+
: [];
|
|
36
|
+
/**
|
|
37
|
+
* Validates and cleans what a cell (or the config) reports: unknown transports, bad hosts and
|
|
38
|
+
* ports are dropped; undefined when nothing usable is left.
|
|
39
|
+
*/
|
|
40
|
+
function normalizeEndpoints(body) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!body || typeof body !== "object")
|
|
43
|
+
return undefined;
|
|
44
|
+
const b = body;
|
|
45
|
+
const sip = (Array.isArray(b.sip) ? b.sip : [])
|
|
46
|
+
.map((e) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const r = (e !== null && e !== void 0 ? e : {});
|
|
49
|
+
const host = String((_a = r.host) !== null && _a !== void 0 ? _a : "").trim();
|
|
50
|
+
const transport = String((_b = r.transport) !== null && _b !== void 0 ? _b : "udp").toLowerCase();
|
|
51
|
+
const p = port(r.port);
|
|
52
|
+
if (!host || !HOST.test(host) || !p)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!exports.SIP_TRANSPORTS.includes(transport))
|
|
55
|
+
return undefined;
|
|
56
|
+
return { host, port: p, transport: transport };
|
|
57
|
+
})
|
|
58
|
+
.filter((e) => !!e)
|
|
59
|
+
.slice(0, 16);
|
|
60
|
+
const signalingAddresses = addresses(b.signalingAddresses);
|
|
61
|
+
const mediaAddresses = addresses(b.mediaAddresses);
|
|
62
|
+
const r = ((_a = b.rtpPorts) !== null && _a !== void 0 ? _a : {});
|
|
63
|
+
const min = port(r.min);
|
|
64
|
+
const max = port(r.max);
|
|
65
|
+
const rtpPorts = min && max && min <= max ? { min, max } : undefined;
|
|
66
|
+
if (!sip.length && !signalingAddresses.length && !mediaAddresses.length)
|
|
67
|
+
return undefined;
|
|
68
|
+
const updatedAt = typeof b.updatedAt === "string" && !isNaN(Date.parse(b.updatedAt))
|
|
69
|
+
? new Date(b.updatedAt).toISOString()
|
|
70
|
+
: undefined;
|
|
71
|
+
return Object.assign(Object.assign({ sip,
|
|
72
|
+
signalingAddresses,
|
|
73
|
+
mediaAddresses }, (rtpPorts ? { rtpPorts } : {})), (updatedAt ? { updatedAt } : {}));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `endpointsHash` (contract §3, RE-B2), the region agent's algorithm (RC-B16): the first 16 hex
|
|
77
|
+
* characters of the sha256 of
|
|
78
|
+
* `{"sip":[[host,port,transport]…],"signalingAddresses":[…],"mediaAddresses":[…],"rtpPorts":[min,max]|null}`
|
|
79
|
+
* in the order the cell sent them; `updatedAt` left out.
|
|
80
|
+
*/
|
|
81
|
+
function endpointsHash(e) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
const canonical = JSON.stringify({
|
|
84
|
+
sip: ((_a = e.sip) !== null && _a !== void 0 ? _a : []).map((s) => [s.host, s.port, s.transport]),
|
|
85
|
+
signalingAddresses: (_b = e.signalingAddresses) !== null && _b !== void 0 ? _b : [],
|
|
86
|
+
mediaAddresses: (_c = e.mediaAddresses) !== null && _c !== void 0 ? _c : [],
|
|
87
|
+
rtpPorts: e.rtpPorts ? [e.rtpPorts.min, e.rtpPorts.max] : null
|
|
88
|
+
});
|
|
89
|
+
return (0, crypto_1.createHash)("sha256").update(canonical).digest("hex").slice(0, 16);
|
|
90
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** The claims of an enrollment token (contract §1). */
|
|
2
|
+
export type EnrollmentClaims = {
|
|
3
|
+
iss: string;
|
|
4
|
+
aud: string;
|
|
5
|
+
sub: string;
|
|
6
|
+
/** Region id (PR-18). */
|
|
7
|
+
rid: string;
|
|
8
|
+
/** Region kind: public | private. */
|
|
9
|
+
knd: string;
|
|
10
|
+
cp: string;
|
|
11
|
+
leaf: string;
|
|
12
|
+
jti: string;
|
|
13
|
+
iat: number;
|
|
14
|
+
exp: number;
|
|
15
|
+
};
|
|
16
|
+
export declare class EnrollmentTokenError extends Error {
|
|
17
|
+
readonly code: "token_invalid" | "token_expired";
|
|
18
|
+
constructor(code: "token_invalid" | "token_expired");
|
|
19
|
+
}
|
|
20
|
+
export declare const ENROLLMENT_TOKEN_TTL_SECONDS: number;
|
|
21
|
+
/**
|
|
22
|
+
* The control plane's region-signing key (ES256, P-256): signs enrollment tokens, verifies them on
|
|
23
|
+
* enrollment and publishes its public key as a JWK Set at /.well-known/region-keys.json.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createRegionSigner(options: {
|
|
26
|
+
privateKeyPem: string;
|
|
27
|
+
kid?: string;
|
|
28
|
+
}): {
|
|
29
|
+
kid: string;
|
|
30
|
+
sign(claims: Omit<EnrollmentClaims, "aud" | "iat" | "exp">, ttl?: number): string;
|
|
31
|
+
/** The verified claims; throws EnrollmentTokenError. */
|
|
32
|
+
verify(token: string): EnrollmentClaims;
|
|
33
|
+
jwks(): {
|
|
34
|
+
keys: {
|
|
35
|
+
kid: string;
|
|
36
|
+
alg: string;
|
|
37
|
+
use: string;
|
|
38
|
+
}[];
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type RegionSigner = ReturnType<typeof createRegionSigner>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ENROLLMENT_TOKEN_TTL_SECONDS = exports.EnrollmentTokenError = void 0;
|
|
7
|
+
exports.createRegionSigner = createRegionSigner;
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
10
|
+
* http://github.com/fonoster/fonoster
|
|
11
|
+
*
|
|
12
|
+
* This file is part of Fonoster
|
|
13
|
+
*
|
|
14
|
+
* Licensed under the MIT License (the "License");
|
|
15
|
+
* you may not use this file except in compliance with
|
|
16
|
+
* the License. You may obtain a copy of the License at
|
|
17
|
+
*
|
|
18
|
+
* https://opensource.org/licenses/MIT
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
+
* See the License for the specific language governing permissions and
|
|
24
|
+
* limitations under the License.
|
|
25
|
+
*/
|
|
26
|
+
const crypto_1 = require("crypto");
|
|
27
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
28
|
+
const types_1 = require("./types");
|
|
29
|
+
class EnrollmentTokenError extends Error {
|
|
30
|
+
constructor(code) {
|
|
31
|
+
super(code);
|
|
32
|
+
this.code = code;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.EnrollmentTokenError = EnrollmentTokenError;
|
|
36
|
+
exports.ENROLLMENT_TOKEN_TTL_SECONDS = 24 * 60 * 60;
|
|
37
|
+
/** RFC 7638 thumbprint of an EC public JWK, the default `kid`. */
|
|
38
|
+
function thumbprint(key) {
|
|
39
|
+
const jwk = key.export({ format: "jwk" });
|
|
40
|
+
const canonical = JSON.stringify({
|
|
41
|
+
crv: jwk.crv,
|
|
42
|
+
kty: jwk.kty,
|
|
43
|
+
x: jwk.x,
|
|
44
|
+
y: jwk.y
|
|
45
|
+
});
|
|
46
|
+
return (0, crypto_1.createHash)("sha256").update(canonical).digest("base64url");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The control plane's region-signing key (ES256, P-256): signs enrollment tokens, verifies them on
|
|
50
|
+
* enrollment and publishes its public key as a JWK Set at /.well-known/region-keys.json.
|
|
51
|
+
*/
|
|
52
|
+
function createRegionSigner(options) {
|
|
53
|
+
var _a;
|
|
54
|
+
const privateKey = (0, crypto_1.createPrivateKey)(options.privateKeyPem);
|
|
55
|
+
const publicKey = (0, crypto_1.createPublicKey)(privateKey);
|
|
56
|
+
const jwk = publicKey.export({ format: "jwk" });
|
|
57
|
+
if (jwk.crv !== "P-256")
|
|
58
|
+
throw new Error("the region-signing key must be an EC P-256 key (ES256)");
|
|
59
|
+
const kid = (_a = options.kid) !== null && _a !== void 0 ? _a : thumbprint(publicKey);
|
|
60
|
+
return {
|
|
61
|
+
kid,
|
|
62
|
+
sign(claims, ttl = exports.ENROLLMENT_TOKEN_TTL_SECONDS) {
|
|
63
|
+
return jsonwebtoken_1.default.sign(Object.assign(Object.assign({}, claims), { aud: types_1.REGION_AUDIENCE }), privateKey, {
|
|
64
|
+
algorithm: "ES256",
|
|
65
|
+
keyid: kid,
|
|
66
|
+
expiresIn: ttl
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
/** The verified claims; throws EnrollmentTokenError. */
|
|
70
|
+
verify(token) {
|
|
71
|
+
try {
|
|
72
|
+
const claims = jsonwebtoken_1.default.verify(token, publicKey, {
|
|
73
|
+
algorithms: ["ES256"],
|
|
74
|
+
audience: types_1.REGION_AUDIENCE
|
|
75
|
+
});
|
|
76
|
+
if (!claims.sub || !claims.jti)
|
|
77
|
+
throw new EnrollmentTokenError("token_invalid");
|
|
78
|
+
return claims;
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
if (e instanceof EnrollmentTokenError)
|
|
82
|
+
throw e;
|
|
83
|
+
if (e.name === "TokenExpiredError")
|
|
84
|
+
throw new EnrollmentTokenError("token_expired");
|
|
85
|
+
throw new EnrollmentTokenError("token_invalid");
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
jwks() {
|
|
89
|
+
return {
|
|
90
|
+
keys: [Object.assign(Object.assign({}, jwk), { kid, alg: "ES256", use: "sig" })]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|