@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.
Files changed (376) hide show
  1. package/dist/applications/buildService.d.ts +5 -1
  2. package/dist/applications/buildService.js +10 -7
  3. package/dist/applications/createCreateApplication.d.ts +6 -2
  4. package/dist/applications/createCreateApplication.js +24 -16
  5. package/dist/applications/createCreateTestToken.d.ts +3 -1
  6. package/dist/applications/createCreateTestToken.js +18 -13
  7. package/dist/applications/createGetApplication.js +2 -2
  8. package/dist/applications/createGetFnUtil.d.ts +22 -18
  9. package/dist/applications/createGetFnUtil.js +3 -5
  10. package/dist/applications/createListApplications.js +3 -4
  11. package/dist/applications/createRotateSigningSecret.d.ts +9 -0
  12. package/dist/{calls/createFetchSingleCall.js → applications/createRotateSigningSecret.js} +23 -20
  13. package/dist/applications/createUpdateApplication.d.ts +6 -2
  14. package/dist/applications/createUpdateApplication.js +35 -36
  15. package/dist/applications/evalKeys.d.ts +9 -0
  16. package/dist/{voice/handlers/dial/recordChannel.js → applications/evalKeys.js} +17 -12
  17. package/dist/applications/session/appModel.d.ts +225 -0
  18. package/dist/applications/session/appModel.js +331 -0
  19. package/dist/applications/types.d.ts +1 -27
  20. package/dist/billing/buildService.d.ts +24 -0
  21. package/dist/billing/buildService.js +116 -0
  22. package/dist/bin/entrypoint.d.ts +1 -0
  23. package/dist/bin/entrypoint.js +180 -0
  24. package/dist/bin/healthcheck.d.ts +2 -0
  25. package/dist/{voice/utils/VoiceServiceClientConstructor.js → bin/healthcheck.js} +24 -9
  26. package/dist/bin/regionHubSetup.d.ts +2 -0
  27. package/dist/bin/regionHubSetup.js +67 -0
  28. package/dist/bin/usage.d.ts +2 -0
  29. package/dist/bin/usage.js +119 -0
  30. package/dist/calls/buildService.d.ts +1 -20
  31. package/dist/calls/buildService.js +59 -6
  32. package/dist/calls/createCall.d.ts +17 -2
  33. package/dist/calls/createCall.js +64 -11
  34. package/dist/calls/createCallPublisher.d.ts +40 -2
  35. package/dist/calls/createCallPublisher.js +43 -9
  36. package/dist/calls/createIsWorkspaceNumber.d.ts +41 -0
  37. package/dist/calls/createIsWorkspaceNumber.js +39 -0
  38. package/dist/calls/createTrackCall.d.ts +55 -2
  39. package/dist/calls/createTrackCall.js +230 -16
  40. package/dist/calls/getCall.d.ts +4 -2
  41. package/dist/calls/getCall.js +2 -3
  42. package/dist/calls/listCalls.d.ts +4 -2
  43. package/dist/calls/listCalls.js +2 -3
  44. package/dist/calls/types.d.ts +11 -2
  45. package/dist/calls/types.js +10 -0
  46. package/dist/{core/buildWelcomeDemoService.d.ts → capabilities/buildService.d.ts} +8 -8
  47. package/dist/capabilities/buildService.js +17 -0
  48. package/dist/capabilities/createGetCapabilities.d.ts +78 -0
  49. package/dist/capabilities/createGetCapabilities.js +98 -0
  50. package/dist/{voice/handlers/utils → capabilities}/index.d.ts +2 -3
  51. package/dist/{voice/handlers/utils → capabilities}/index.js +4 -3
  52. package/dist/config/index.d.ts +23 -0
  53. package/dist/config/index.js +102 -0
  54. package/dist/config/schema.d.ts +1919 -0
  55. package/dist/config/schema.js +357 -0
  56. package/dist/core/allowList.js +2 -1
  57. package/dist/core/applyCatalog.d.ts +10 -0
  58. package/dist/{voice/client/GrpcClientHandler.js → core/applyCatalog.js} +45 -51
  59. package/dist/core/db.d.ts +3 -1
  60. package/dist/core/db.js +2 -1
  61. package/dist/core/durableConsumer.d.ts +41 -0
  62. package/dist/core/durableConsumer.js +104 -0
  63. package/dist/core/httpBridge.d.ts +24 -6
  64. package/dist/core/httpBridge.js +3 -25
  65. package/dist/core/identityConfig.d.ts +2 -35
  66. package/dist/core/identityConfig.js +3 -36
  67. package/dist/core/regionHooks.d.ts +15 -0
  68. package/dist/{calls/influxdb.js → core/regionHooks.js} +4 -8
  69. package/dist/core/runServices.js +98 -15
  70. package/dist/core/services.d.ts +96 -6
  71. package/dist/core/services.js +49 -10
  72. package/dist/{voice/errors/index.d.ts → core/telemetry.d.ts} +2 -2
  73. package/dist/core/telemetry.js +42 -0
  74. package/dist/{applications/utils/convertToApplicationData.d.ts → core/telemetryInterceptor.d.ts} +10 -4
  75. package/dist/core/telemetryInterceptor.js +57 -0
  76. package/dist/core/testTokenConfig.js +4 -1
  77. package/dist/core/upsertRoomrPeer.d.ts +6 -0
  78. package/dist/core/{upsertDefaultPeer.js → upsertRoomrPeer.js} +31 -30
  79. package/dist/envs.d.ts +136 -23
  80. package/dist/envs.js +108 -143
  81. package/dist/index.js +39 -21
  82. package/dist/outbound/createNodeDirectory.d.ts +86 -0
  83. package/dist/outbound/createNodeDirectory.js +140 -0
  84. package/dist/{voice/integrations → outbound}/index.d.ts +4 -1
  85. package/dist/{voice/errors → outbound}/index.js +4 -2
  86. package/dist/outbound/placeOutboundCall.d.ts +96 -0
  87. package/dist/outbound/placeOutboundCall.js +172 -0
  88. package/dist/outbound/placementSweep.d.ts +56 -0
  89. package/dist/outbound/placementSweep.js +127 -0
  90. package/dist/outbound/runOutboundCalls.d.ts +52 -0
  91. package/dist/outbound/runOutboundCalls.js +171 -0
  92. package/dist/providers/createProvidersHandlers.d.ts +39 -0
  93. package/dist/providers/createProvidersHandlers.js +229 -0
  94. package/dist/providers/index.d.ts +47 -0
  95. package/dist/{voice/client → providers}/index.js +15 -6
  96. package/dist/providers/registryUsage.d.ts +48 -0
  97. package/dist/providers/registryUsage.js +236 -0
  98. package/dist/records/createIndexRecord.d.ts +42 -0
  99. package/dist/records/createIndexRecord.js +185 -0
  100. package/dist/records/createRecordsRouter.d.ts +61 -0
  101. package/dist/records/createRecordsRouter.js +330 -0
  102. package/dist/records/createSearchRecords.d.ts +51 -0
  103. package/dist/records/createSearchRecords.js +134 -0
  104. package/dist/{voice/filters → records}/index.d.ts +6 -6
  105. package/dist/{voice/filters → records}/index.js +6 -6
  106. package/dist/records/maintenance.d.ts +33 -0
  107. package/dist/records/maintenance.js +166 -0
  108. package/dist/records/runCallRecords.d.ts +48 -0
  109. package/dist/records/runCallRecords.js +49 -0
  110. package/dist/{events/createPerCallCache.d.ts → records/stores.d.ts} +4 -7
  111. package/dist/{voice/handlers/utils/isDtmf.js → records/stores.js} +9 -3
  112. package/dist/records/types.d.ts +104 -0
  113. package/dist/regions/configSync.d.ts +130 -0
  114. package/dist/regions/configSync.js +316 -0
  115. package/dist/regions/createRegionsRouter.d.ts +151 -0
  116. package/dist/regions/createRegionsRouter.js +391 -0
  117. package/dist/regions/endpoints.d.ts +41 -0
  118. package/dist/regions/endpoints.js +90 -0
  119. package/dist/regions/enrollmentToken.d.ts +41 -0
  120. package/dist/regions/enrollmentToken.js +94 -0
  121. package/dist/regions/httpAuth.d.ts +39 -0
  122. package/dist/regions/httpAuth.js +78 -0
  123. package/dist/regions/ids.d.ts +15 -0
  124. package/dist/regions/ids.js +81 -0
  125. package/dist/{voice/client → regions}/index.d.ts +17 -6
  126. package/dist/regions/index.js +51 -0
  127. package/dist/regions/link.d.ts +17 -0
  128. package/dist/regions/link.js +170 -0
  129. package/dist/regions/natsAuth.d.ts +41 -0
  130. package/dist/regions/natsAuth.js +64 -0
  131. package/dist/regions/natsJwt.d.ts +23 -0
  132. package/dist/regions/natsJwt.js +26 -0
  133. package/dist/regions/relay.d.ts +45 -0
  134. package/dist/regions/relay.js +203 -0
  135. package/dist/regions/relayHttp.d.ts +7 -0
  136. package/dist/regions/relayHttp.js +107 -0
  137. package/dist/regions/relaySlots.d.ts +18 -0
  138. package/dist/regions/relaySlots.js +118 -0
  139. package/dist/regions/runRegions.d.ts +111 -0
  140. package/dist/regions/runRegions.js +235 -0
  141. package/dist/regions/service.d.ts +129 -0
  142. package/dist/regions/service.js +558 -0
  143. package/dist/regions/sources.d.ts +20 -0
  144. package/dist/regions/sources.js +191 -0
  145. package/dist/regions/status.d.ts +35 -0
  146. package/dist/regions/status.js +63 -0
  147. package/dist/regions/types.d.ts +123 -0
  148. package/dist/regions/types.js +41 -0
  149. package/dist/{voice/integrations/getSttConfig.d.ts → regions/withConfigChangeHook.d.ts} +13 -7
  150. package/dist/regions/withConfigChangeHook.js +44 -0
  151. package/dist/secrets/createGetFnUtil.d.ts +2 -2
  152. package/dist/session/createSessionRouter.d.ts +49 -0
  153. package/dist/session/createSessionRouter.js +206 -0
  154. package/dist/{voice/handlers/dial → session}/index.d.ts +1 -1
  155. package/dist/{voice/handlers/dial → session}/index.js +1 -1
  156. package/dist/usage/buildService.d.ts +16 -0
  157. package/dist/{voice/integrations/getTtsConfig.js → usage/buildService.js} +13 -7
  158. package/dist/{voice/tts/utils/convertUlawToPCM16.d.ts → usage/createGetUsage.d.ts} +7 -6
  159. package/dist/usage/createGetUsage.js +118 -0
  160. package/dist/usage/ingestUsage.d.ts +7 -0
  161. package/dist/usage/ingestUsage.js +87 -0
  162. package/dist/usage/publishRecordedUsage.d.ts +52 -0
  163. package/dist/usage/publishRecordedUsage.js +103 -0
  164. package/dist/{utils/createHandleDialEventsWithNats.d.ts → usage/publishUsage.d.ts} +10 -4
  165. package/dist/usage/publishUsage.js +50 -0
  166. package/dist/usage/rebuildUsage.d.ts +48 -0
  167. package/dist/usage/rebuildUsage.js +104 -0
  168. package/dist/usage/runUsageConsumer.d.ts +22 -0
  169. package/dist/usage/runUsageConsumer.js +78 -0
  170. package/dist/usage/snapshotStorage.d.ts +14 -0
  171. package/dist/usage/snapshotStorage.js +95 -0
  172. package/dist/{voice/integrations/getTtsConfig.d.ts → usage/types.d.ts} +17 -6
  173. package/dist/utils/createCheckNumberPreconditions.js +4 -0
  174. package/dist/utils/index.d.ts +0 -2
  175. package/dist/utils/index.js +0 -2
  176. package/dist/voice/stt/Deepgram.d.ts +4 -57
  177. package/dist/voice/stt/Deepgram.js +15 -286
  178. package/dist/voice/stt/Google.d.ts +4 -15
  179. package/dist/voice/stt/Google.js +7 -103
  180. package/dist/voice/stt/types.d.ts +2 -38
  181. package/dist/voice/stt/types.js +25 -3
  182. package/dist/voice/tts/Azure.d.ts +4 -34
  183. package/dist/voice/tts/Azure.js +25 -105
  184. package/dist/voice/tts/Deepgram.d.ts +4 -38
  185. package/dist/voice/tts/Deepgram.js +25 -82
  186. package/dist/voice/tts/ElevenLabs.d.ts +4 -18
  187. package/dist/voice/tts/ElevenLabs.js +6 -97
  188. package/dist/voice/tts/Google.d.ts +4 -38
  189. package/dist/voice/tts/Google.js +25 -91
  190. package/dist/webhooks/createWebhooksHandlers.d.ts +37 -0
  191. package/dist/webhooks/createWebhooksHandlers.js +217 -0
  192. package/dist/webhooks/index.d.ts +37 -0
  193. package/dist/webhooks/index.js +51 -0
  194. package/dist/webhooks/lostCalls.d.ts +49 -0
  195. package/dist/webhooks/lostCalls.js +147 -0
  196. package/dist/webhooks/nodeCallEvents.d.ts +73 -0
  197. package/dist/webhooks/nodeCallEvents.js +177 -0
  198. package/dist/webhooks/runWebhookFanout.d.ts +44 -0
  199. package/dist/webhooks/runWebhookFanout.js +202 -0
  200. package/package.json +21 -31
  201. package/dist/applications/utils/applicationWithEncodedStruct.d.ts +0 -3
  202. package/dist/applications/utils/applicationWithEncodedStruct.js +0 -50
  203. package/dist/applications/utils/convertToApplicationData.js +0 -37
  204. package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +0 -786
  205. package/dist/applications/validation/assistantWithoutApiKeySchema.js +0 -35
  206. package/dist/applications/validation/createValidationSchema.d.ts +0 -1474
  207. package/dist/applications/validation/createValidationSchema.js +0 -67
  208. package/dist/applications/validation/prepareForValidation.d.ts +0 -21
  209. package/dist/applications/validation/prepareForValidation.js +0 -35
  210. package/dist/applications/validation/speechValidators.d.ts +0 -47
  211. package/dist/applications/validation/speechValidators.js +0 -50
  212. package/dist/applications/validation/validOrThrow.d.ts +0 -21
  213. package/dist/applications/validation/validOrThrow.js +0 -15
  214. package/dist/calls/createFetchCalls.d.ts +0 -22
  215. package/dist/calls/createFetchCalls.js +0 -88
  216. package/dist/calls/createFetchSingleCall.d.ts +0 -22
  217. package/dist/calls/influxdb.d.ts +0 -2
  218. package/dist/calls/runCallManager.d.ts +0 -8
  219. package/dist/calls/runCallManager.js +0 -75
  220. package/dist/core/buildWelcomeDemoService.js +0 -97
  221. package/dist/core/upsertDefaultPeer.d.ts +0 -2
  222. package/dist/events/amdResultCache.d.ts +0 -23
  223. package/dist/events/amdResultCache.js +0 -35
  224. package/dist/events/createInfluxDbPub.d.ts +0 -13
  225. package/dist/events/createInfluxDbPub.js +0 -89
  226. package/dist/events/createPerCallCache.js +0 -46
  227. package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
  228. package/dist/events/mapCallDirectionToEnum.js +0 -37
  229. package/dist/events/nats.d.ts +0 -10
  230. package/dist/events/nats.js +0 -82
  231. package/dist/events/transformEvent.d.ts +0 -2
  232. package/dist/events/transformEvent.js +0 -87
  233. package/dist/events/types.d.ts +0 -26
  234. package/dist/utils/createHandleDialEventsWithNats.js +0 -24
  235. package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +0 -23
  236. package/dist/utils/createHandleDialEventsWithVoiceClient.js +0 -27
  237. package/dist/utils/getIntegrationsFromFile.d.ts +0 -2
  238. package/dist/utils/getIntegrationsFromFile.js +0 -49
  239. package/dist/utils/mapDialStatus.d.ts +0 -21
  240. package/dist/utils/mapDialStatus.js +0 -38
  241. package/dist/voice/VoiceDispatcher.d.ts +0 -21
  242. package/dist/voice/VoiceDispatcher.js +0 -122
  243. package/dist/voice/amd/mapAsteriskAmd.d.ts +0 -38
  244. package/dist/voice/amd/mapAsteriskAmd.js +0 -68
  245. package/dist/voice/client/AudioSocketHandler.d.ts +0 -38
  246. package/dist/voice/client/AudioSocketHandler.js +0 -70
  247. package/dist/voice/client/AuthorizationHandler.d.ts +0 -13
  248. package/dist/voice/client/AuthorizationHandler.js +0 -78
  249. package/dist/voice/client/ExternalMediaHandler.d.ts +0 -32
  250. package/dist/voice/client/ExternalMediaHandler.js +0 -59
  251. package/dist/voice/client/GrpcClientHandler.d.ts +0 -36
  252. package/dist/voice/client/SpeechHandler.d.ts +0 -60
  253. package/dist/voice/client/SpeechHandler.js +0 -120
  254. package/dist/voice/client/VoiceClientImpl.d.ts +0 -79
  255. package/dist/voice/client/VoiceClientImpl.js +0 -198
  256. package/dist/voice/connectToAri.d.ts +0 -2
  257. package/dist/voice/connectToAri.js +0 -81
  258. package/dist/voice/createCreateVoiceClient.d.ts +0 -9
  259. package/dist/voice/createCreateVoiceClient.js +0 -97
  260. package/dist/voice/errors/ChannelVarNotFoundError.d.ts +0 -23
  261. package/dist/voice/errors/ChannelVarNotFoundError.js +0 -10
  262. package/dist/voice/errors/MethodNotImplementedError.d.ts +0 -22
  263. package/dist/voice/errors/MethodNotImplementedError.js +0 -27
  264. package/dist/voice/filters/AudioFilterFactory.d.ts +0 -35
  265. package/dist/voice/filters/AudioFilterFactory.js +0 -94
  266. package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +0 -64
  267. package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +0 -252
  268. package/dist/voice/filters/aiCoustics/types.d.ts +0 -45
  269. package/dist/voice/filters/aiCoustics/types.js +0 -29
  270. package/dist/voice/filters/createAudioFilterChain.d.ts +0 -9
  271. package/dist/voice/filters/createAudioFilterChain.js +0 -171
  272. package/dist/voice/filters/createAudioFilterSession.d.ts +0 -15
  273. package/dist/voice/filters/createAudioFilterSession.js +0 -114
  274. package/dist/voice/filters/pcm.d.ts +0 -21
  275. package/dist/voice/filters/pcm.js +0 -37
  276. package/dist/voice/filters/types.d.ts +0 -61
  277. package/dist/voice/filters/types.js +0 -26
  278. package/dist/voice/handlers/createAnswerHandler.d.ts +0 -23
  279. package/dist/voice/handlers/createAnswerHandler.js +0 -24
  280. package/dist/voice/handlers/createHangupHandler.d.ts +0 -23
  281. package/dist/voice/handlers/createHangupHandler.js +0 -28
  282. package/dist/voice/handlers/createMuteHandler.d.ts +0 -4
  283. package/dist/voice/handlers/createMuteHandler.js +0 -27
  284. package/dist/voice/handlers/createPlayDtmfHandler.d.ts +0 -4
  285. package/dist/voice/handlers/createPlayDtmfHandler.js +0 -27
  286. package/dist/voice/handlers/createPlayHandler.d.ts +0 -4
  287. package/dist/voice/handlers/createPlayHandler.js +0 -33
  288. package/dist/voice/handlers/createPlaybackControlHandler.d.ts +0 -4
  289. package/dist/voice/handlers/createPlaybackControlHandler.js +0 -62
  290. package/dist/voice/handlers/createRecordHandler.d.ts +0 -4
  291. package/dist/voice/handlers/createRecordHandler.js +0 -58
  292. package/dist/voice/handlers/createSayHandler.d.ts +0 -4
  293. package/dist/voice/handlers/createSayHandler.js +0 -31
  294. package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +0 -11
  295. package/dist/voice/handlers/createSetAudioFiltersHandler.js +0 -74
  296. package/dist/voice/handlers/createStopSayHandler.d.ts +0 -3
  297. package/dist/voice/handlers/createStopSayHandler.js +0 -34
  298. package/dist/voice/handlers/createStreamGatherHandler.d.ts +0 -3
  299. package/dist/voice/handlers/createStreamGatherHandler.js +0 -74
  300. package/dist/voice/handlers/createStreamHandler.d.ts +0 -3
  301. package/dist/voice/handlers/createStreamHandler.js +0 -70
  302. package/dist/voice/handlers/createUnmuteHandler.d.ts +0 -4
  303. package/dist/voice/handlers/createUnmuteHandler.js +0 -27
  304. package/dist/voice/handlers/dial/createDialHandler.d.ts +0 -23
  305. package/dist/voice/handlers/dial/createDialHandler.js +0 -78
  306. package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +0 -24
  307. package/dist/voice/handlers/dial/handleChannelLeftBridge.js +0 -29
  308. package/dist/voice/handlers/dial/handleStasisEnd.d.ts +0 -21
  309. package/dist/voice/handlers/dial/handleStasisEnd.js +0 -19
  310. package/dist/voice/handlers/dial/handleStasisStart.d.ts +0 -27
  311. package/dist/voice/handlers/dial/handleStasisStart.js +0 -52
  312. package/dist/voice/handlers/dial/recordChannel.d.ts +0 -22
  313. package/dist/voice/handlers/gather/createGatherHandler.d.ts +0 -3
  314. package/dist/voice/handlers/gather/createGatherHandler.js +0 -86
  315. package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +0 -26
  316. package/dist/voice/handlers/gather/getTimeoutPromise.js +0 -18
  317. package/dist/voice/handlers/index.d.ts +0 -33
  318. package/dist/voice/handlers/index.js +0 -49
  319. package/dist/voice/handlers/utils/awaitForPlaybackFinished.d.ts +0 -21
  320. package/dist/voice/handlers/utils/awaitForPlaybackFinished.js +0 -25
  321. package/dist/voice/handlers/utils/awaitForRecordingFinished.d.ts +0 -5
  322. package/dist/voice/handlers/utils/awaitForRecordingFinished.js +0 -53
  323. package/dist/voice/handlers/utils/isDtmf.d.ts +0 -20
  324. package/dist/voice/handlers/utils/textChunksByClause.d.ts +0 -2
  325. package/dist/voice/handlers/utils/textChunksByClause.js +0 -41
  326. package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.d.ts +0 -2
  327. package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.js +0 -34
  328. package/dist/voice/handlers/utils/withErrorHandling.d.ts +0 -22
  329. package/dist/voice/handlers/utils/withErrorHandling.js +0 -38
  330. package/dist/voice/integrations/ApplicationNotFoundError.d.ts +0 -22
  331. package/dist/voice/integrations/ApplicationNotFoundError.js +0 -28
  332. package/dist/voice/integrations/createCreateContainer.d.ts +0 -4
  333. package/dist/voice/integrations/createCreateContainer.js +0 -76
  334. package/dist/voice/integrations/getSttConfig.js +0 -30
  335. package/dist/voice/integrations/index.js +0 -35
  336. package/dist/voice/integrations/types.d.ts +0 -29
  337. package/dist/voice/stt/AbstractSpeechToText.d.ts +0 -33
  338. package/dist/voice/stt/AbstractSpeechToText.js +0 -19
  339. package/dist/voice/stt/SpeechToTextFactory.d.ts +0 -9
  340. package/dist/voice/stt/SpeechToTextFactory.js +0 -43
  341. package/dist/voice/transcribeOnConnection.d.ts +0 -35
  342. package/dist/voice/transcribeOnConnection.js +0 -91
  343. package/dist/voice/tts/AbstractTextToSpeech.d.ts +0 -40
  344. package/dist/voice/tts/AbstractTextToSpeech.js +0 -50
  345. package/dist/voice/tts/TextToSpeechFactory.d.ts +0 -8
  346. package/dist/voice/tts/TextToSpeechFactory.js +0 -47
  347. package/dist/voice/tts/types.d.ts +0 -48
  348. package/dist/voice/tts/types.js +0 -2
  349. package/dist/voice/tts/utils/convertUlawToPCM16.js +0 -40
  350. package/dist/voice/tts/utils/createChunkedSynthesisStream.d.ts +0 -28
  351. package/dist/voice/tts/utils/createChunkedSynthesisStream.js +0 -78
  352. package/dist/voice/tts/utils/createErrorStream.d.ts +0 -21
  353. package/dist/voice/tts/utils/createErrorStream.js +0 -28
  354. package/dist/voice/tts/utils/index.d.ts +0 -23
  355. package/dist/voice/tts/utils/index.js +0 -39
  356. package/dist/voice/tts/utils/isSsml.d.ts +0 -20
  357. package/dist/voice/tts/utils/isSsml.js +0 -25
  358. package/dist/voice/tts/utils/streamToBuffer.d.ts +0 -20
  359. package/dist/voice/tts/utils/streamToBuffer.js +0 -60
  360. package/dist/voice/types/ari.d.ts +0 -43
  361. package/dist/voice/types/ari.js +0 -48
  362. package/dist/voice/types/index.d.ts +0 -20
  363. package/dist/voice/types/index.js +0 -36
  364. package/dist/voice/types/voice.d.ts +0 -67
  365. package/dist/voice/types/voice.js +0 -2
  366. package/dist/voice/utils/VoiceServiceClientConstructor.d.ts +0 -3
  367. package/dist/voice/utils/createExternalMediaConfig.d.ts +0 -12
  368. package/dist/voice/utils/createExternalMediaConfig.js +0 -37
  369. package/dist/voice/utils/createGetChannelVar.d.ts +0 -22
  370. package/dist/voice/utils/createGetChannelVar.js +0 -27
  371. package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +0 -22
  372. package/dist/voice/utils/createGetChannelVarWithoutThrow.js +0 -26
  373. package/dist/voice/utils/index.d.ts +0 -22
  374. package/dist/voice/utils/index.js +0 -38
  375. /package/dist/{events → records}/types.js +0 -0
  376. /package/dist/{voice/integrations → usage}/types.js +0 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { TokenVerifyOptions } from "@fonoster/common";
20
+ import { NextFunction, Request, Response } from "express";
21
+ export type Caller = {
22
+ accessKeyId: string;
23
+ role: string;
24
+ actor: string;
25
+ };
26
+ /** A signed-in user (regions belong to users, PR-14). */
27
+ export type UserCaller = {
28
+ userRef: string;
29
+ };
30
+ export declare const ADMIN_ROLES: string[];
31
+ /**
32
+ * Bearer access token + `x-accesskey-id` (same rules as the records API). With
33
+ * `tokenOptions`, the token's issuer and audience must match too.
34
+ */
35
+ export declare function createHttpAuth(identityPublicKey: string, tokenOptions?: TokenVerifyOptions): (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>>;
36
+ /** A user-level call: a valid Bearer access token; its `sub` is the user (no workspace). */
37
+ export declare function createUserAuth(identityPublicKey: string, tokenOptions?: TokenVerifyOptions): (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>>;
38
+ /** Sets `res.locals.user` when a valid token is present; never refuses. */
39
+ export declare function optionalUser(identityPublicKey: string, tokenOptions?: TokenVerifyOptions): (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ADMIN_ROLES = void 0;
4
+ exports.createHttpAuth = createHttpAuth;
5
+ exports.createUserAuth = createUserAuth;
6
+ exports.optionalUser = optionalUser;
7
+ /**
8
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/fonoster
10
+ *
11
+ * This file is part of Fonoster
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const common_1 = require("@fonoster/common");
26
+ exports.ADMIN_ROLES = ["WORKSPACE_OWNER", "WORKSPACE_ADMIN"];
27
+ const bearer = (req) => {
28
+ var _a;
29
+ const header = (_a = req.headers.authorization) !== null && _a !== void 0 ? _a : "";
30
+ return header.startsWith("Bearer ") ? header.slice(7) : "";
31
+ };
32
+ /**
33
+ * Bearer access token + `x-accesskey-id` (same rules as the records API). With
34
+ * `tokenOptions`, the token's issuer and audience must match too.
35
+ */
36
+ function createHttpAuth(identityPublicKey, tokenOptions = {}) {
37
+ return (req, res, next) => {
38
+ var _a, _b, _c, _d, _e;
39
+ const token = bearer(req);
40
+ const accessKeyId = String((_b = (_a = req.headers["x-accesskey-id"]) !== null && _a !== void 0 ? _a : req.headers["accesskeyid"]) !== null && _b !== void 0 ? _b : "");
41
+ // Access tokens only: id, refresh and invite tokens are refused here.
42
+ const decoded = (0, common_1.verifyAccessToken)(token, identityPublicKey, tokenOptions);
43
+ if (!decoded)
44
+ return res.status(401).json({ error: "unauthenticated" });
45
+ const access = (_c = decoded.access) === null || _c === void 0 ? void 0 : _c.find((a) => a.accessKeyId === accessKeyId);
46
+ if (!accessKeyId || !access)
47
+ return res.status(403).json({ error: "permission_denied" });
48
+ res.locals.caller = {
49
+ accessKeyId,
50
+ role: access.role,
51
+ actor: (_e = (_d = decoded.sub) !== null && _d !== void 0 ? _d : decoded.accessKeyId) !== null && _e !== void 0 ? _e : "unknown"
52
+ };
53
+ next();
54
+ };
55
+ }
56
+ const userOf = (token, identityPublicKey, tokenOptions) => {
57
+ const decoded = (0, common_1.verifyAccessToken)(token, identityPublicKey, tokenOptions);
58
+ return (decoded === null || decoded === void 0 ? void 0 : decoded.sub) ? { userRef: decoded.sub } : undefined;
59
+ };
60
+ /** A user-level call: a valid Bearer access token; its `sub` is the user (no workspace). */
61
+ function createUserAuth(identityPublicKey, tokenOptions = {}) {
62
+ return (req, res, next) => {
63
+ const user = userOf(bearer(req), identityPublicKey, tokenOptions);
64
+ if (!user)
65
+ return res.status(401).json({ error: "unauthenticated" });
66
+ res.locals.user = user;
67
+ next();
68
+ };
69
+ }
70
+ /** Sets `res.locals.user` when a valid token is present; never refuses. */
71
+ function optionalUser(identityPublicKey, tokenOptions = {}) {
72
+ return (req, res, next) => {
73
+ const user = userOf(bearer(req), identityPublicKey, tokenOptions);
74
+ if (user)
75
+ res.locals.user = user;
76
+ next();
77
+ };
78
+ }
@@ -0,0 +1,15 @@
1
+ export declare const REGION_ID: RegExp;
2
+ export declare const GEO_PREFIXES: string[];
3
+ /** Words the HTTP routes use (`/api/regions/current`, …); never region ids. */
4
+ export declare const ROUTE_WORDS: string[];
5
+ export declare const PUBLIC_REGION_ID: RegExp;
6
+ export declare const DEFAULT_REGION_ID = "default";
7
+ /** A private region id: the format, not `default`, no public geo prefix, no route word. */
8
+ export declare function checkPrivateRegionId(id: unknown): string;
9
+ /** A public region id: `default` or `<geo>-<area>-<n>` (us-east-1). */
10
+ export declare function checkPublicRegionId(id: unknown): string;
11
+ export declare function checkDisplayName(name: unknown): string;
12
+ /** True for a lowercase FQDN: 2+ labels, alphabetic TLD, ≤ 253 characters, no wildcard. */
13
+ export declare function isFqdn(value: string): boolean;
14
+ /** A region's SIP domain (PR-16), lowercased; required unless `optional`. */
15
+ export declare function checkSipDomain(value: unknown, optional?: boolean): string | undefined;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_REGION_ID = exports.PUBLIC_REGION_ID = exports.ROUTE_WORDS = exports.GEO_PREFIXES = exports.REGION_ID = void 0;
4
+ exports.checkPrivateRegionId = checkPrivateRegionId;
5
+ exports.checkPublicRegionId = checkPublicRegionId;
6
+ exports.checkDisplayName = checkDisplayName;
7
+ exports.isFqdn = isFqdn;
8
+ exports.checkSipDomain = checkSipDomain;
9
+ /**
10
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
11
+ * http://github.com/fonoster/fonoster
12
+ *
13
+ * This file is part of Fonoster
14
+ *
15
+ * Licensed under the MIT License (the "License");
16
+ * you may not use this file except in compliance with
17
+ * the License. You may obtain a copy of the License at
18
+ *
19
+ * https://opensource.org/licenses/MIT
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ const types_1 = require("./types");
28
+ // Region ids, display names and SIP domains (add-private-regions PR-16, PR-18).
29
+ exports.REGION_ID = /^[a-z][a-z0-9-]{2,31}$/;
30
+ exports.GEO_PREFIXES = ["us-", "eu-", "sa-", "ap-", "af-", "me-"];
31
+ /** Words the HTTP routes use (`/api/regions/current`, …); never region ids. */
32
+ exports.ROUTE_WORDS = ["current", "enroll", "admin"];
33
+ exports.PUBLIC_REGION_ID = /^(us|eu|sa|ap|af|me)-[a-z]+-\d+$/;
34
+ exports.DEFAULT_REGION_ID = "default";
35
+ /** A private region id: the format, not `default`, no public geo prefix, no route word. */
36
+ function checkPrivateRegionId(id) {
37
+ if (typeof id !== "string" || !exports.REGION_ID.test(id))
38
+ throw new types_1.RegionError(400, "region_id_invalid", "the id must be 3-32 lowercase letters, digits or hyphens and start with a letter");
39
+ if (id === exports.DEFAULT_REGION_ID ||
40
+ exports.ROUTE_WORDS.includes(id) ||
41
+ exports.GEO_PREFIXES.some((p) => id.startsWith(p)))
42
+ throw new types_1.RegionError(400, "region_id_reserved", `"${id}" is reserved: \`default\` and the public prefixes ${exports.GEO_PREFIXES.join(", ")} are for public regions`);
43
+ return id;
44
+ }
45
+ /** A public region id: `default` or `<geo>-<area>-<n>` (us-east-1). */
46
+ function checkPublicRegionId(id) {
47
+ if (typeof id !== "string" ||
48
+ !exports.REGION_ID.test(id) ||
49
+ !(id === exports.DEFAULT_REGION_ID || exports.PUBLIC_REGION_ID.test(id)))
50
+ throw new types_1.RegionError(400, "region_id_invalid", "a public region id is `default` or <geo>-<area>-<n> (e.g. us-east-1)");
51
+ return id;
52
+ }
53
+ function checkDisplayName(name) {
54
+ const v = typeof name === "string" ? name.trim() : "";
55
+ if (!v || v.length > 120)
56
+ throw new types_1.RegionError(400, "display_name_invalid", "the display name must be 1-120 characters");
57
+ return v;
58
+ }
59
+ const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
60
+ /** True for a lowercase FQDN: 2+ labels, alphabetic TLD, ≤ 253 characters, no wildcard. */
61
+ function isFqdn(value) {
62
+ if (!value || value.length > 253)
63
+ return false;
64
+ const labels = value.split(".");
65
+ if (labels.length < 2)
66
+ return false;
67
+ if (!labels.every((l) => LABEL.test(l)))
68
+ return false;
69
+ return /^[a-z]{2,63}$/.test(labels[labels.length - 1]);
70
+ }
71
+ /** A region's SIP domain (PR-16), lowercased; required unless `optional`. */
72
+ function checkSipDomain(value, optional = false) {
73
+ if (optional && (value === undefined || value === null || value === ""))
74
+ return undefined;
75
+ const v = typeof value === "string"
76
+ ? value.trim().toLowerCase().replace(/\.$/, "")
77
+ : "";
78
+ if (!isFqdn(v))
79
+ throw new types_1.RegionError(400, "sip_domain_invalid", "the SIP domain must be a fully qualified domain name you control (e.g. sip.acme.com); point wildcard DNS (*.sip.acme.com) at the region");
80
+ return v;
81
+ }
@@ -16,9 +16,20 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- export * from "./VoiceClientImpl";
20
- export * from "./AudioSocketHandler";
21
- export * from "./ExternalMediaHandler";
22
- export * from "./AuthorizationHandler";
23
- export * from "./GrpcClientHandler";
24
- export * from "./SpeechHandler";
19
+ export * from "./configSync";
20
+ export * from "./createRegionsRouter";
21
+ export * from "./endpoints";
22
+ export * from "./ids";
23
+ export * from "./enrollmentToken";
24
+ export * from "./link";
25
+ export * from "./natsAuth";
26
+ export * from "./natsJwt";
27
+ export * from "./relay";
28
+ export * from "./relaySlots";
29
+ export * from "./relayHttp";
30
+ export * from "./runRegions";
31
+ export * from "./service";
32
+ export * from "./sources";
33
+ export * from "./status";
34
+ export * from "./types";
35
+ export * from "./withConfigChangeHook";
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./configSync"), exports);
36
+ __exportStar(require("./createRegionsRouter"), exports);
37
+ __exportStar(require("./endpoints"), exports);
38
+ __exportStar(require("./ids"), exports);
39
+ __exportStar(require("./enrollmentToken"), exports);
40
+ __exportStar(require("./link"), exports);
41
+ __exportStar(require("./natsAuth"), exports);
42
+ __exportStar(require("./natsJwt"), exports);
43
+ __exportStar(require("./relay"), exports);
44
+ __exportStar(require("./relaySlots"), exports);
45
+ __exportStar(require("./relayHttp"), exports);
46
+ __exportStar(require("./runRegions"), exports);
47
+ __exportStar(require("./service"), exports);
48
+ __exportStar(require("./sources"), exports);
49
+ __exportStar(require("./status"), exports);
50
+ __exportStar(require("./types"), exports);
51
+ __exportStar(require("./withConfigChangeHook"), exports);
@@ -0,0 +1,17 @@
1
+ import { NatsConnection } from "nats";
2
+ import { ConfigSync } from "./configSync";
3
+ import { RegionService } from "./service";
4
+ import { RegionsDb } from "./types";
5
+ /** A workspace's key for a provider (workspace_provider_keys → encrypted Secret), uncached. */
6
+ export declare function workspaceKey(db: RegionsDb, accessKeyId: string, providerId: string): Promise<string | undefined>;
7
+ /**
8
+ * The control plane's side of the link (contract §3), subscribed on the region hub: heartbeats,
9
+ * config requests, index entries and usage. The hub only lets a cell publish under its own
10
+ * `region.<ref>.>`, so the subject's ref is the sender's identity.
11
+ */
12
+ export declare function startRegionLink(deps: {
13
+ nc: NatsConnection;
14
+ db: RegionsDb;
15
+ service: RegionService;
16
+ configSync: ConfigSync;
17
+ }): () => void;
@@ -0,0 +1,170 @@
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.workspaceKey = workspaceKey;
13
+ exports.startRegionLink = startRegionLink;
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 logger_1 = require("@fonoster/logger");
33
+ const nats_1 = require("nats");
34
+ const createIndexRecord_1 = require("../records/createIndexRecord");
35
+ const types_1 = require("./types");
36
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
+ const sc = (0, nats_1.StringCodec)();
38
+ const QUEUE = "apiserver-regions";
39
+ /** A workspace's key for a provider (workspace_provider_keys → encrypted Secret), uncached. */
40
+ function workspaceKey(db, accessKeyId, providerId) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const binding = yield db.workspaceProviderKey.findUnique({
43
+ where: { accessKeyId_providerId: { accessKeyId, providerId } }
44
+ });
45
+ if (!binding)
46
+ return undefined;
47
+ const secret = yield db.secret.findUnique({
48
+ where: { ref: binding.secretRef }
49
+ });
50
+ return (secret === null || secret === void 0 ? void 0 : secret.secret) || undefined;
51
+ });
52
+ }
53
+ /**
54
+ * The control plane's side of the link (contract §3), subscribed on the region hub: heartbeats,
55
+ * config requests, index entries and usage. The hub only lets a cell publish under its own
56
+ * `region.<ref>.>`, so the subject's ref is the sender's identity.
57
+ */
58
+ function startRegionLink(deps) {
59
+ const { nc, db, service, configSync } = deps;
60
+ const index = (0, createIndexRecord_1.createIndexRecord)(db, { directory: () => service.directory });
61
+ const enrolled = (msg) => __awaiter(this, void 0, void 0, function* () {
62
+ const ref = msg.subject.split(".")[1];
63
+ if (!types_1.REGION_REF.test(ref))
64
+ return undefined;
65
+ const row = yield service.byRef(ref);
66
+ return (row === null || row === void 0 ? void 0 : row.state) === "enrolled" ? row : undefined;
67
+ });
68
+ const parse = (msg) => {
69
+ try {
70
+ return JSON.parse(sc.decode(msg.data));
71
+ }
72
+ catch (_a) {
73
+ return undefined;
74
+ }
75
+ };
76
+ const on = (subject, fn) => nc.subscribe(subject, {
77
+ queue: QUEUE,
78
+ callback: (err, msg) => {
79
+ if (err)
80
+ return;
81
+ const body = parse(msg);
82
+ if (!body)
83
+ return;
84
+ void enrolled(msg)
85
+ .then((row) => (row ? fn(msg, row, body) : undefined))
86
+ .catch((e) => logger.error(`${msg.subject}: ${e.message}`));
87
+ }
88
+ });
89
+ const subs = [
90
+ on("region.*.heartbeat", (_msg, row, body) => __awaiter(this, void 0, void 0, function* () {
91
+ const updated = yield service.heartbeat(row.ref, body);
92
+ if (!updated)
93
+ return;
94
+ if (service.needsEndpoints(updated, body))
95
+ nc.publish((0, types_1.subjects)(row.ref).endpointsRequest, sc.encode(JSON.stringify({ type: "region.endpoints.request" })));
96
+ yield configSync.afterHeartbeat(updated);
97
+ })),
98
+ on("region.*.endpoints", (_msg, row, body) => __awaiter(this, void 0, void 0, function* () {
99
+ if (body.type !== undefined && body.type !== "region.endpoints")
100
+ return;
101
+ yield service.reportEndpoints(row.ref, body);
102
+ })),
103
+ on("region.*.config.request", (msg, row, body) => __awaiter(this, void 0, void 0, function* () {
104
+ var _a;
105
+ const answer = yield configSync.answer(row, Number((_a = body.haveVersion) !== null && _a !== void 0 ? _a : 0));
106
+ if (msg.reply)
107
+ msg.respond(sc.encode(JSON.stringify(answer)));
108
+ })),
109
+ on("region.*.index", (_msg, row, body) => __awaiter(this, void 0, void 0, function* () {
110
+ var _a;
111
+ // The entry must name a workspace bound to this region (contract §5, PR-14).
112
+ const ws = (_a = body.workspaceRef) !== null && _a !== void 0 ? _a : body.accessKeyId;
113
+ if (!body.callRef)
114
+ return;
115
+ if (!(yield service.serves(row, ws))) {
116
+ logger.warn(`region ${row.ref}: index entry ${String(body.callRef)} names a workspace the region does not serve; dropped`);
117
+ return;
118
+ }
119
+ const entry = Object.assign(Object.assign({}, body), { workspaceRef: String(ws), region: row.ref });
120
+ yield index(entry);
121
+ })),
122
+ on("region.*.usage", (_msg, row, body) => __awaiter(this, void 0, void 0, function* () {
123
+ var _a;
124
+ const minutes = Number(body.minutes);
125
+ const period = String((_a = body.period) !== null && _a !== void 0 ? _a : "").slice(0, 16);
126
+ if (!period || !Number.isFinite(minutes))
127
+ return;
128
+ const accessKeyId = body.workspaceRef;
129
+ if (!(yield service.serves(row, accessKeyId)))
130
+ return;
131
+ yield db.regionUsage.upsert({
132
+ where: {
133
+ regionRef_accessKeyId_period: {
134
+ regionRef: row.ref,
135
+ accessKeyId,
136
+ period
137
+ }
138
+ },
139
+ create: { regionRef: row.ref, accessKeyId, period, minutes },
140
+ update: { minutes }
141
+ });
142
+ })),
143
+ on("region.*.secrets.get", (msg, row, body) => __awaiter(this, void 0, void 0, function* () {
144
+ // PR-20: a public region asks for a workspace's bring-your-own key, per call. The value is
145
+ // only ever in this reply: never cached, stored or logged.
146
+ if (!msg.reply)
147
+ return;
148
+ const reply = (m) => {
149
+ msg.respond(sc.encode(JSON.stringify(m)));
150
+ };
151
+ const workspaceRef = body.workspaceRef;
152
+ const provider = body.provider;
153
+ if (typeof provider !== "string" || !provider)
154
+ return reply({ type: "region.secrets.error", code: "bad_request" });
155
+ if (row.kind !== "public")
156
+ return reply({ type: "region.secrets.error", code: "not_public" });
157
+ if (!(yield service.serves(row, workspaceRef)))
158
+ return reply({
159
+ type: "region.secrets.error",
160
+ code: "workspace_not_in_region"
161
+ });
162
+ const value = yield workspaceKey(db, String(workspaceRef), provider);
163
+ reply(value
164
+ ? { type: "region.secrets.value", workspaceRef, provider, value }
165
+ : { type: "region.secrets.none", workspaceRef, provider });
166
+ }))
167
+ ];
168
+ logger.info("region link: heartbeat, endpoints, config, index, usage and secrets consumers on");
169
+ return () => subs.forEach((s) => s.unsubscribe());
170
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { NatsConnection } from "nats";
20
+ /**
21
+ * Issues and revokes the cells' NATS users on the region hub (RG-B2). Users are signed by the
22
+ * REGIONS account key and allowed `region.<ref>.>` only; revoking re-signs the REGIONS account
23
+ * with the user in `revocations` and pushes it over the system account, which disconnects it.
24
+ */
25
+ export declare function createRegionNatsAuth(options: {
26
+ operatorSeed: string;
27
+ accountSeed: string;
28
+ /** A connection as a system-account user of the hub; needed to revoke. */
29
+ system?: NatsConnection;
30
+ timeoutMs?: number;
31
+ }): {
32
+ accountPublicKey: string;
33
+ issue(regionRef: string): {
34
+ publicKey: string;
35
+ jwt: string;
36
+ creds: string;
37
+ };
38
+ /** Pushes the REGIONS account with every revoked user (public key → revoked-before time). */
39
+ pushRevocations(revocations: Record<string, number>): Promise<void>;
40
+ };
41
+ export type RegionNatsAuth = ReturnType<typeof createRegionNatsAuth>;
@@ -0,0 +1,64 @@
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.createRegionNatsAuth = createRegionNatsAuth;
13
+ /**
14
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const nats_1 = require("nats");
32
+ const natsJwt_1 = require("./natsJwt");
33
+ const types_1 = require("./types");
34
+ const sc = (0, nats_1.StringCodec)();
35
+ /**
36
+ * Issues and revokes the cells' NATS users on the region hub (RG-B2). Users are signed by the
37
+ * REGIONS account key and allowed `region.<ref>.>` only; revoking re-signs the REGIONS account
38
+ * with the user in `revocations` and pushes it over the system account, which disconnects it.
39
+ */
40
+ function createRegionNatsAuth(options) {
41
+ const operator = (0, natsJwt_1.keyPairFromSeed)(options.operatorSeed);
42
+ const account = (0, natsJwt_1.keyPairFromSeed)(options.accountSeed);
43
+ const accountPublicKey = account.getPublicKey();
44
+ return {
45
+ accountPublicKey,
46
+ issue(regionRef) {
47
+ const scope = (0, types_1.subjects)(regionRef).all;
48
+ return (0, natsJwt_1.issueUserCreds)(account, regionRef, { pub: [scope], sub: [scope] });
49
+ },
50
+ /** Pushes the REGIONS account with every revoked user (public key → revoked-before time). */
51
+ pushRevocations(revocations) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ var _a, _b, _c, _d, _e;
54
+ if (!options.system)
55
+ throw new Error("region hub: no system connection to push revocations");
56
+ const jwt = (0, natsJwt_1.regionsAccountJwt)(operator, accountPublicKey, revocations);
57
+ const reply = yield options.system.request("$SYS.REQ.CLAIMS.UPDATE", sc.encode(jwt), { timeout: (_a = options.timeoutMs) !== null && _a !== void 0 ? _a : 5000 });
58
+ const body = JSON.parse(sc.decode(reply.data));
59
+ if (body.error || (((_b = body.data) === null || _b === void 0 ? void 0 : _b.code) && body.data.code !== 200))
60
+ throw new Error(`region hub refused the account update: ${(_d = (_c = body.error) === null || _c === void 0 ? void 0 : _c.description) !== null && _d !== void 0 ? _d : (_e = body.data) === null || _e === void 0 ? void 0 : _e.message}`);
61
+ });
62
+ }
63
+ };
64
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { RegionHub } from "@fonoster/common";
20
+ export declare const encodeNatsJwt: typeof RegionHub.encodeNatsJwt, decodeNatsJwt: typeof RegionHub.decodeNatsJwt, operatorJwt: typeof RegionHub.operatorJwt, accountJwt: typeof RegionHub.accountJwt, userJwt: typeof RegionHub.userJwt, formatCreds: typeof RegionHub.formatCreds, issueUserCreds: typeof RegionHub.issueUserCreds, seedOf: (kp: RegionHub.KeyPair) => string, keyPairFromSeed: (seed: string) => RegionHub.KeyPair, REGIONS_ACCOUNT_NAME: string, regionsAccountJwt: typeof RegionHub.regionsAccountJwt, generateRegionHub: typeof RegionHub.generateRegionHub, createAccount: typeof RegionHub.createAccount, createOperator: typeof RegionHub.createOperator, createUser: typeof RegionHub.createUser;
21
+ export type NatsClaims = RegionHub.NatsClaims;
22
+ export type UserPermissions = RegionHub.UserPermissions;
23
+ export type KeyPair = RegionHub.KeyPair;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUser = exports.createOperator = exports.createAccount = exports.generateRegionHub = exports.regionsAccountJwt = exports.REGIONS_ACCOUNT_NAME = exports.keyPairFromSeed = exports.seedOf = exports.issueUserCreds = exports.formatCreds = exports.userJwt = exports.accountJwt = exports.operatorJwt = exports.decodeNatsJwt = exports.encodeNatsJwt = void 0;
4
+ /**
5
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const common_1 = require("@fonoster/common");
23
+ // The NATS JWT helpers and generateRegionHub live in @fonoster/common (regions/hub) so the
24
+ // self-host setup utility (fonoster-config init) can generate the region hub without the
25
+ // apiserver. Re-exported here so existing imports keep working.
26
+ exports.encodeNatsJwt = common_1.RegionHub.encodeNatsJwt, exports.decodeNatsJwt = common_1.RegionHub.decodeNatsJwt, exports.operatorJwt = common_1.RegionHub.operatorJwt, exports.accountJwt = common_1.RegionHub.accountJwt, exports.userJwt = common_1.RegionHub.userJwt, exports.formatCreds = common_1.RegionHub.formatCreds, exports.issueUserCreds = common_1.RegionHub.issueUserCreds, exports.seedOf = common_1.RegionHub.seedOf, exports.keyPairFromSeed = common_1.RegionHub.keyPairFromSeed, exports.REGIONS_ACCOUNT_NAME = common_1.RegionHub.REGIONS_ACCOUNT_NAME, exports.regionsAccountJwt = common_1.RegionHub.regionsAccountJwt, exports.generateRegionHub = common_1.RegionHub.generateRegionHub, exports.createAccount = common_1.RegionHub.createAccount, exports.createOperator = common_1.RegionHub.createOperator, exports.createUser = common_1.RegionHub.createUser;