@fonoster/common 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 (209) hide show
  1. package/dist/{voice/PlayDtmf.d.ts → agents/index.d.ts} +3 -5
  2. package/dist/{assistants → agents}/index.js +2 -6
  3. package/dist/agents/sessionAgentSchema.d.ts +755 -0
  4. package/dist/agents/sessionAgentSchema.js +117 -0
  5. package/dist/{voice/Dial.d.ts → calls/index.d.ts} +16 -13
  6. package/dist/calls/index.js +44 -0
  7. package/dist/cellsecrets/index.d.ts +91 -0
  8. package/dist/cellsecrets/index.js +299 -0
  9. package/dist/config/cli/check.d.ts +6 -0
  10. package/dist/config/cli/check.js +202 -0
  11. package/dist/config/cli/envFile.d.ts +23 -0
  12. package/dist/config/cli/envFile.js +81 -0
  13. package/dist/config/cli/exposure.d.ts +10 -0
  14. package/dist/config/cli/exposure.js +93 -0
  15. package/dist/config/cli/index.d.ts +2 -0
  16. package/dist/{identity/tokenHasAccessKeyId.js → config/cli/index.js} +7 -8
  17. package/dist/config/cli/info.d.ts +6 -0
  18. package/dist/config/cli/info.js +62 -0
  19. package/dist/config/cli/init.d.ts +9 -0
  20. package/dist/config/cli/init.js +152 -0
  21. package/dist/config/cli/main.d.ts +11 -0
  22. package/dist/config/cli/main.js +155 -0
  23. package/dist/config/cli/render.d.ts +44 -0
  24. package/dist/config/cli/render.js +129 -0
  25. package/dist/config/cli/secrets.d.ts +21 -0
  26. package/dist/config/cli/secrets.js +117 -0
  27. package/dist/config/cli/types.d.ts +24 -0
  28. package/dist/config/cli/types.js +7 -0
  29. package/dist/{assistants/index.d.ts → config/configHints.d.ts} +8 -7
  30. package/dist/config/configHints.js +47 -0
  31. package/dist/{voice → config}/index.d.ts +11 -13
  32. package/dist/{voice → config}/index.js +11 -13
  33. package/dist/config/interpolateEnv.d.ts +34 -0
  34. package/dist/config/interpolateEnv.js +70 -0
  35. package/dist/config/loadServiceConfig.d.ts +28 -0
  36. package/dist/config/loadServiceConfig.js +112 -0
  37. package/dist/config/logsSchema.d.ts +76 -0
  38. package/dist/config/logsSchema.js +49 -0
  39. package/dist/config/natsConnection.d.ts +53 -0
  40. package/dist/config/natsConnection.js +58 -0
  41. package/dist/config/parseConfigFile.d.ts +7 -0
  42. package/dist/config/parseConfigFile.js +60 -0
  43. package/dist/config/resolveConfigFile.d.ts +17 -0
  44. package/dist/config/resolveConfigFile.js +54 -0
  45. package/dist/config/resolveSecretRefs.d.ts +35 -0
  46. package/dist/config/resolveSecretRefs.js +129 -0
  47. package/dist/{assistants/audioFiltersSchema.d.ts → config/strictDeep.d.ts} +9 -12
  48. package/dist/config/strictDeep.js +58 -0
  49. package/dist/config/telemetrySchema.d.ts +39 -0
  50. package/dist/config/telemetrySchema.js +44 -0
  51. package/dist/config/toJsonSchema.d.ts +30 -0
  52. package/dist/config/toJsonSchema.js +161 -0
  53. package/dist/constants.d.ts +1 -6
  54. package/dist/constants.js +4 -7
  55. package/dist/envs.d.ts +2 -1
  56. package/dist/envs.js +13 -11
  57. package/dist/errors/handleZodError.js +3 -1
  58. package/dist/filters/index.d.ts +70 -0
  59. package/dist/filters/index.js +101 -0
  60. package/dist/identity/createAuthInterceptor.d.ts +9 -2
  61. package/dist/identity/createAuthInterceptor.js +36 -30
  62. package/dist/identity/hasAccess.d.ts +9 -3
  63. package/dist/identity/hasAccess.js +32 -8
  64. package/dist/identity/index.d.ts +1 -0
  65. package/dist/identity/index.js +1 -0
  66. package/dist/identity/isValidToken.d.ts +12 -2
  67. package/dist/identity/isValidToken.js +25 -9
  68. package/dist/identity/roles.js +33 -7
  69. package/dist/identity/types.d.ts +6 -1
  70. package/dist/identity/types.js +1 -0
  71. package/dist/{assistants/LanguageModelProvider.js → identity/verifyAccessToken.d.ts} +10 -11
  72. package/dist/identity/verifyAccessToken.js +44 -0
  73. package/dist/index.d.ts +15 -2
  74. package/dist/index.js +18 -3
  75. package/dist/net/assertPublicDestination.d.ts +52 -0
  76. package/dist/net/assertPublicDestination.js +342 -0
  77. package/dist/{voice/StopSay.d.ts → net/index.d.ts} +1 -6
  78. package/dist/net/index.js +35 -0
  79. package/dist/notifications/createSendEmail.js +3 -1
  80. package/dist/protos/applications.proto +138 -3
  81. package/dist/protos/authz.proto +26 -4
  82. package/dist/protos/billing.proto +92 -0
  83. package/dist/protos/calls.proto +4 -0
  84. package/dist/protos/capabilities.proto +102 -0
  85. package/dist/protos/identity.proto +26 -1
  86. package/dist/protos/providers.proto +139 -0
  87. package/dist/protos/roomr.proto +146 -0
  88. package/dist/protos/session.proto +194 -0
  89. package/dist/protos/usage.proto +59 -0
  90. package/dist/protos/webhooks.proto +140 -0
  91. package/dist/{utils/types.d.ts → regions/hub/index.d.ts} +1 -5
  92. package/dist/regions/hub/index.js +35 -0
  93. package/dist/regions/hub/natsJwt.d.ts +63 -0
  94. package/dist/regions/hub/natsJwt.js +195 -0
  95. package/dist/registry/Registry.d.ts +87 -0
  96. package/dist/registry/Registry.js +432 -0
  97. package/dist/registry/cli.d.ts +20 -0
  98. package/dist/registry/cli.js +436 -0
  99. package/dist/registry/features.d.ts +31 -0
  100. package/dist/registry/features.js +38 -0
  101. package/dist/registry/index.d.ts +24 -0
  102. package/dist/registry/index.js +40 -0
  103. package/dist/registry/prisma.d.ts +67 -0
  104. package/dist/registry/prisma.js +399 -0
  105. package/dist/registry/stores.d.ts +21 -0
  106. package/dist/{assistants/languageModelConfigSchema.js → registry/stores.js} +55 -38
  107. package/dist/registry/types.d.ts +110 -0
  108. package/dist/{assistants/LanguageModelProvider.d.ts → registry/types.js} +6 -8
  109. package/dist/registry/workspaceKeys.d.ts +41 -0
  110. package/dist/registry/workspaceKeys.js +64 -0
  111. package/dist/roomr/health.d.ts +9 -0
  112. package/dist/{assistants/eventsHookSchema.js → roomr/health.js} +22 -18
  113. package/dist/roomr/index.d.ts +75 -0
  114. package/dist/roomr/index.js +146 -0
  115. package/dist/roomr/session.d.ts +133 -0
  116. package/dist/roomr/session.js +132 -0
  117. package/dist/session/index.d.ts +19 -0
  118. package/dist/session/index.js +35 -0
  119. package/dist/session/schema.d.ts +2140 -0
  120. package/dist/session/schema.js +448 -0
  121. package/dist/sessions/index.d.ts +96 -0
  122. package/dist/sessions/index.js +197 -0
  123. package/dist/telemetry.d.ts +76 -0
  124. package/dist/telemetry.js +360 -0
  125. package/dist/types.d.ts +3 -5
  126. package/dist/{voice/Gather.d.ts → usage/CallUsage.d.ts} +19 -18
  127. package/dist/usage/CallUsage.js +76 -0
  128. package/dist/usage/index.d.ts +22 -0
  129. package/dist/usage/index.js +38 -0
  130. package/dist/usage/meters.d.ts +113 -0
  131. package/dist/usage/meters.js +90 -0
  132. package/dist/usage/types.d.ts +159 -0
  133. package/dist/usage/types.js +84 -0
  134. package/dist/usage/usageId.d.ts +6 -0
  135. package/dist/usage/usageId.js +45 -0
  136. package/dist/utils/{findIntegrationsCredentials.js → WriteBehind.d.ts} +13 -10
  137. package/dist/utils/WriteBehind.js +64 -0
  138. package/dist/utils/index.d.ts +1 -3
  139. package/dist/utils/index.js +1 -3
  140. package/dist/utils/{createFetchSingleCallByCallId.d.ts → logUnhandledRejections.d.ts} +8 -4
  141. package/dist/{assistants/audioFiltersSchema.js → utils/logUnhandledRejections.js} +17 -12
  142. package/dist/utils/withErrorHandling.js +1 -1
  143. package/dist/validators/calls.d.ts +3 -0
  144. package/dist/validators/calls.js +12 -2
  145. package/dist/validators/identity.d.ts +37 -8
  146. package/dist/validators/identity.js +22 -3
  147. package/dist/validators/index.d.ts +1 -0
  148. package/dist/validators/index.js +1 -0
  149. package/dist/validators/sip.d.ts +40 -0
  150. package/dist/validators/sip.js +99 -0
  151. package/dist/validators/sipnet/credentials.d.ts +2 -2
  152. package/dist/validators/sipnet/domains.js +7 -7
  153. package/dist/validators/sipnet/trunks.d.ts +14 -14
  154. package/dist/validators/sipnet/trunks.js +4 -2
  155. package/dist/webhooks/Dispatcher.d.ts +87 -0
  156. package/dist/webhooks/Dispatcher.js +225 -0
  157. package/dist/webhooks/bus.d.ts +68 -0
  158. package/dist/webhooks/bus.js +178 -0
  159. package/dist/webhooks/events.d.ts +66 -0
  160. package/dist/webhooks/events.js +62 -0
  161. package/dist/webhooks/index.d.ts +23 -0
  162. package/dist/webhooks/index.js +39 -0
  163. package/dist/webhooks/prisma.d.ts +55 -0
  164. package/dist/webhooks/prisma.js +242 -0
  165. package/dist/webhooks/signing.d.ts +8 -0
  166. package/dist/webhooks/signing.js +53 -0
  167. package/package.json +25 -11
  168. package/schema/session.v1.json +871 -0
  169. package/dist/assistants/assistantSchema.d.ts +0 -739
  170. package/dist/assistants/assistantSchema.js +0 -37
  171. package/dist/assistants/conversationSettingsSchema.d.ts +0 -122
  172. package/dist/assistants/conversationSettingsSchema.js +0 -133
  173. package/dist/assistants/eventsHookSchema.d.ts +0 -38
  174. package/dist/assistants/languageModelConfigSchema.d.ts +0 -206
  175. package/dist/identity/tokenHasAccessKeyId.d.ts +0 -2
  176. package/dist/protos/voice.proto +0 -557
  177. package/dist/utils/createFetchSingleCallByCallId.js +0 -33
  178. package/dist/utils/findIntegrationsCredentials.d.ts +0 -23
  179. package/dist/utils/types.js +0 -2
  180. package/dist/voice/Dial.js +0 -20
  181. package/dist/voice/Gather.js +0 -9
  182. package/dist/voice/Mute.d.ts +0 -31
  183. package/dist/voice/Mute.js +0 -9
  184. package/dist/voice/Play.d.ts +0 -30
  185. package/dist/voice/Play.js +0 -2
  186. package/dist/voice/PlayDtmf.js +0 -2
  187. package/dist/voice/PlaybackControl.d.ts +0 -31
  188. package/dist/voice/PlaybackControl.js +0 -11
  189. package/dist/voice/Record.d.ts +0 -36
  190. package/dist/voice/Record.js +0 -7
  191. package/dist/voice/Say.d.ts +0 -28
  192. package/dist/voice/Say.js +0 -2
  193. package/dist/voice/StopSay.js +0 -2
  194. package/dist/voice/Stream.d.ts +0 -53
  195. package/dist/voice/Stream.js +0 -19
  196. package/dist/voice/StreamGather.d.ts +0 -34
  197. package/dist/voice/StreamGather.js +0 -9
  198. package/dist/voice/Verb.d.ts +0 -27
  199. package/dist/voice/Verb.js +0 -2
  200. package/dist/voice/voice.d.ts +0 -171
  201. package/dist/voice/voice.js +0 -65
  202. package/dist/{assistants → agents}/testCasesSchema.d.ts +4 -4
  203. /package/dist/{assistants → agents}/testCasesSchema.js +0 -0
  204. /package/dist/{assistants → agents}/tools/index.d.ts +0 -0
  205. /package/dist/{assistants → agents}/tools/index.js +0 -0
  206. /package/dist/{assistants → agents}/tools/propertySchema.d.ts +0 -0
  207. /package/dist/{assistants → agents}/tools/propertySchema.js +0 -0
  208. /package/dist/{assistants → agents}/tools/toolSchema.d.ts +0 -0
  209. /package/dist/{assistants → agents}/tools/toolSchema.js +0 -0
@@ -0,0 +1,194 @@
1
+ // Session: the per-call control stream the Roomr node opens to the session endpoint (in Fonoster,
2
+ // AppBridge behind a Kubernetes Service). The node is the client: one new connection per call,
3
+ // `Start` first, then commands from the app and events from the node, in order. Audio never
4
+ // travels here; it is RTP between the two MediaEndpoints.
5
+ // Spec: openspec/changes/redesign-roomr/specs/media-control ("Each call opens one control stream
6
+ // to the session endpoint", "App audio is RTP negotiated on the control stream", "Transfer modes",
7
+ // "Hold silences the app and plays hold audio", "Listeners fork audio by track", "Endings carry a
8
+ // reason", "The app sends DTMF on the caller's leg"). Messages only grow: add fields, never
9
+ // renumber or reuse them, and receivers ignore fields they do not know.
10
+ //
11
+ // Regenerate the Go code with go/roomr/api/generate.sh.
12
+ syntax = "proto3";
13
+
14
+ package session.v1;
15
+
16
+ option go_package = "github.com/fonoster/roomr/api/session/v1;sessionv1";
17
+
18
+ service Session {
19
+ rpc Connect(stream NodeMessage) returns (stream AppMessage);
20
+ }
21
+
22
+ // An RTP endpoint: `codec` is "L16/16000" on app legs; `srtp_key` (SDES, base64) when encrypted.
23
+ message MediaEndpoint {
24
+ string ip = 1;
25
+ uint32 port = 2;
26
+ string codec = 3;
27
+ string srtp_key = 4;
28
+ }
29
+
30
+ message SipAuth {
31
+ string username = 1;
32
+ string password = 2;
33
+ }
34
+
35
+ // A SIP destination: `proxy` carries the transport in its URI (sip:host:port;transport=tcp).
36
+ message SipTarget {
37
+ string uri = 1;
38
+ string proxy = 2;
39
+ map<string, string> headers = 3;
40
+ SipAuth auth = 4;
41
+ }
42
+
43
+ // ---- node to app
44
+
45
+ message NodeMessage {
46
+ oneof msg {
47
+ Start start = 1;
48
+ Dtmf dtmf = 2;
49
+ Event event = 3;
50
+ }
51
+ }
52
+
53
+ message Start {
54
+ enum Direction {
55
+ INBOUND = 0;
56
+ OUTBOUND = 1;
57
+ }
58
+ string call_ref = 1;
59
+ Direction direction = 2;
60
+ string from = 3;
61
+ string to = 4;
62
+ // Every INVITE header, as received (inbound) or as sent (outbound).
63
+ map<string, string> headers = 5;
64
+ // Opaque to the node: CreateCall's metadata, passed through untouched.
65
+ map<string, string> metadata = 6;
66
+ string room_ref = 7;
67
+ // The node's RTP endpoint for this call's app leg.
68
+ MediaEndpoint media = 8;
69
+ string node_ref = 9;
70
+ }
71
+
72
+ message Dtmf {
73
+ string digit = 1;
74
+ // rfc4733, sip_info or inband
75
+ string source = 2;
76
+ }
77
+
78
+ message Event {
79
+ // 3 was operation_done (Play and Record left the node).
80
+ reserved 3;
81
+ reserved "operation_done";
82
+ oneof event {
83
+ ParticipantJoined participant_joined = 1;
84
+ ParticipantLeft participant_left = 2;
85
+ TransferResult transfer_result = 4;
86
+ Ended ended = 5;
87
+ }
88
+ }
89
+
90
+ message ParticipantJoined {
91
+ string participant_ref = 1;
92
+ uint32 track_id = 2;
93
+ }
94
+
95
+ message ParticipantLeft {
96
+ string participant_ref = 1;
97
+ string cause = 2;
98
+ }
99
+
100
+ message TransferResult {
101
+ // completed, referred or failed
102
+ string status = 1;
103
+ string cause = 2;
104
+ uint32 sip_status = 3;
105
+ }
106
+
107
+ // The call ended: `cause` is one of caller_hangup, callee_hangup, busy, no_answer, rejected,
108
+ // media_timeout, node_error, max_duration, removed, app_gone; `sip_status` when SIP gave one.
109
+ message Ended {
110
+ string cause = 1;
111
+ uint32 sip_status = 2;
112
+ }
113
+
114
+ // ---- app to node
115
+
116
+ message AppMessage {
117
+ // 4, 5 and 13 were play, stop and record: the node is the SIP and media edge, not an app server
118
+ // (an app plays its own audio on its RTP leg; recording is a listener).
119
+ reserved 4, 5, 13;
120
+ reserved "play", "stop", "record";
121
+ oneof msg {
122
+ Answer answer = 1;
123
+ Ready ready = 2;
124
+ Reject reject = 3;
125
+ Transfer transfer = 6;
126
+ TransferComplete transfer_complete = 7;
127
+ Hold hold = 8;
128
+ Resume resume = 9;
129
+ SendDtmf send_dtmf = 10;
130
+ AddListener add_listener = 11;
131
+ RemoveListener remove_listener = 12;
132
+ Hangup hangup = 14;
133
+ }
134
+ }
135
+
136
+ // Inbound: the app takes the call; the node answers 200 OK.
137
+ message Answer {
138
+ MediaEndpoint media = 1;
139
+ // Lowers the node's maximum call duration for this call (0: the node's).
140
+ uint32 max_duration_s = 2;
141
+ }
142
+
143
+ // Outbound: the app is ready for the answered call.
144
+ message Ready {
145
+ MediaEndpoint media = 1;
146
+ }
147
+
148
+ // Inbound: the app refuses the call with this SIP status (4xx to 6xx).
149
+ message Reject {
150
+ uint32 sip_status = 1;
151
+ string reason = 2;
152
+ }
153
+
154
+ message Transfer {
155
+ SipTarget to = 1;
156
+ // cold, warm or refer
157
+ string mode = 2;
158
+ // Warm: music for the caller while the new party is dialed.
159
+ string music = 3;
160
+ uint32 ring_timeout_s = 4;
161
+ }
162
+
163
+ message TransferComplete {}
164
+
165
+ message Hold {
166
+ string music = 1;
167
+ }
168
+
169
+ message Resume {}
170
+
171
+ // RFC 4733 events on the caller's leg, in order.
172
+ message SendDtmf {
173
+ // 0-9, *, #, A-D.
174
+ string digits = 1;
175
+ }
176
+
177
+ message ListenTrack {
178
+ uint32 track_id = 1;
179
+ MediaEndpoint rtp = 2;
180
+ }
181
+
182
+ message AddListener {
183
+ string listener_ref = 1;
184
+ repeated ListenTrack listen = 2;
185
+ }
186
+
187
+ message RemoveListener {
188
+ string listener_ref = 1;
189
+ }
190
+
191
+ message Hangup {
192
+ uint32 sip_status = 1;
193
+ string reason = 2;
194
+ }
@@ -0,0 +1,59 @@
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
+ syntax = "proto3";
20
+
21
+ package fonoster.usage.v1beta2;
22
+
23
+ // What the workspace consumed: quantities only, never money (usage-metering spec).
24
+ service Usage {
25
+ // Gets usage totals for a range of days, grouped as requested
26
+ rpc GetUsage (GetUsageRequest) returns (GetUsageResponse) {}
27
+ }
28
+
29
+ message GetUsageRequest {
30
+ // First day of the range, YYYY-MM-DD (UTC), inclusive
31
+ string from_day = 1;
32
+ // Last day of the range, YYYY-MM-DD (UTC), inclusive
33
+ string to_day = 2;
34
+ // Dimensions to group by: day | workspace | meter | provider | model | key_source | origin.
35
+ // Totals are always split by meter, so meter is implied.
36
+ repeated string group_by = 3;
37
+ // Owners only: every workspace the caller owns, instead of the caller's workspace
38
+ bool all_owned = 4;
39
+ }
40
+
41
+ message UsageRow {
42
+ // Set only for the dimensions requested in group_by
43
+ string day = 1;
44
+ string workspace_ref = 2;
45
+ string meter = 3;
46
+ // second | character | token | count | byte
47
+ string unit = 4;
48
+ string provider = 5;
49
+ string model = 6;
50
+ // platform | workspace; empty for meters that call no vendor
51
+ string key_source = 7;
52
+ // call | browser_test | eval | api
53
+ string origin = 8;
54
+ double quantity = 9;
55
+ }
56
+
57
+ message GetUsageResponse {
58
+ repeated UsageRow rows = 1;
59
+ }
@@ -0,0 +1,140 @@
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
+ syntax = "proto3";
20
+
21
+ package fonoster.webhooks.v1beta2;
22
+
23
+ // Workspace webhooks (add-workspace-webhooks): endpoints, secret rotation and the delivery log
24
+ service Webhooks {
25
+ // Create an endpoint; the response carries its signing secret (shown once)
26
+ rpc CreateWebhook(CreateWebhookRequest) returns (CreateWebhookResponse) {}
27
+ // List the workspace's endpoints
28
+ rpc ListWebhooks(ListWebhooksRequest) returns (ListWebhooksResponse) {}
29
+ // Get one endpoint
30
+ rpc GetWebhook(GetWebhookRequest) returns (Webhook) {}
31
+ // Change an endpoint's URL or events
32
+ rpc UpdateWebhook(UpdateWebhookRequest) returns (UpdateWebhookResponse) {}
33
+ // Delete an endpoint
34
+ rpc DeleteWebhook(DeleteWebhookRequest) returns (DeleteWebhookResponse) {}
35
+ // New signing secret; the previous one keeps verifying for 24 hours
36
+ rpc RotateWebhookSecret(RotateWebhookSecretRequest) returns (RotateWebhookSecretResponse) {}
37
+ // The delivery log, newest first
38
+ rpc ListWebhookDeliveries(ListWebhookDeliveriesRequest) returns (ListWebhookDeliveriesResponse) {}
39
+ // Send a delivery again now (same event id, fresh signature)
40
+ rpc ResendWebhookDelivery(ResendWebhookDeliveryRequest) returns (WebhookDelivery) {}
41
+ }
42
+
43
+ message Webhook {
44
+ string ref = 1;
45
+ string url = 2;
46
+ // Subscribed event types, e.g. call.ended
47
+ repeated string events = 3;
48
+ // The last characters of the current secret
49
+ string secret_hint = 4;
50
+ // Seconds since the epoch until which the previous secret still verifies (0: none)
51
+ int32 previous_secret_until = 5;
52
+ int32 created_at = 6;
53
+ int32 updated_at = 7;
54
+ }
55
+
56
+ message CreateWebhookRequest {
57
+ string url = 1;
58
+ repeated string events = 2;
59
+ }
60
+
61
+ message CreateWebhookResponse {
62
+ string ref = 1;
63
+ // Shown only here and on rotation
64
+ string secret = 2;
65
+ }
66
+
67
+ message ListWebhooksRequest {
68
+ int32 page_size = 1;
69
+ string page_token = 2;
70
+ }
71
+
72
+ message ListWebhooksResponse {
73
+ repeated Webhook items = 1;
74
+ string next_page_token = 2;
75
+ }
76
+
77
+ message GetWebhookRequest {
78
+ string ref = 1;
79
+ }
80
+
81
+ message UpdateWebhookRequest {
82
+ string ref = 1;
83
+ // Empty keeps the URL
84
+ string url = 2;
85
+ // Empty keeps the events
86
+ repeated string events = 3;
87
+ }
88
+
89
+ message UpdateWebhookResponse {
90
+ string ref = 1;
91
+ }
92
+
93
+ message DeleteWebhookRequest {
94
+ string ref = 1;
95
+ }
96
+
97
+ message DeleteWebhookResponse {
98
+ string ref = 1;
99
+ }
100
+
101
+ message RotateWebhookSecretRequest {
102
+ string ref = 1;
103
+ }
104
+
105
+ message RotateWebhookSecretResponse {
106
+ string ref = 1;
107
+ string secret = 2;
108
+ // Seconds since the epoch until which the previous secret still verifies
109
+ int32 previous_secret_until = 3;
110
+ }
111
+
112
+ message WebhookDelivery {
113
+ string ref = 1;
114
+ string webhook_ref = 2;
115
+ string event_id = 3;
116
+ string event_type = 4;
117
+ // pending, succeeded or failed
118
+ string status = 5;
119
+ int32 attempts = 6;
120
+ // HTTP status of the last attempt (0: no response)
121
+ int32 last_status = 7;
122
+ int32 last_attempt_at = 8;
123
+ int32 next_attempt_at = 9;
124
+ int32 created_at = 10;
125
+ }
126
+
127
+ message ListWebhookDeliveriesRequest {
128
+ // Optional: one endpoint's deliveries
129
+ string webhook_ref = 1;
130
+ // At most this many (default 50, up to 200)
131
+ int32 page_size = 2;
132
+ }
133
+
134
+ message ListWebhookDeliveriesResponse {
135
+ repeated WebhookDelivery items = 1;
136
+ }
137
+
138
+ message ResendWebhookDeliveryRequest {
139
+ string ref = 1;
140
+ }
@@ -16,8 +16,4 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { ParameterizedQuery } from "@influxdata/influxdb-client";
20
- type InfluxDBClient = {
21
- collectRows(query: ParameterizedQuery): Promise<unknown[]>;
22
- };
23
- export { InfluxDBClient };
19
+ export * from "./natsJwt";
@@ -0,0 +1,35 @@
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("./natsJwt"), exports);
@@ -0,0 +1,63 @@
1
+ import { createAccount, createOperator, createUser, KeyPair } from "nkeys.js";
2
+ export type NatsClaims = {
3
+ jti?: string;
4
+ iat: number;
5
+ iss: string;
6
+ name?: string;
7
+ sub: string;
8
+ exp?: number;
9
+ nats: Record<string, unknown>;
10
+ };
11
+ /** Signs claims with an nkey pair (operator signs accounts, accounts sign users). */
12
+ export declare function encodeNatsJwt(claims: NatsClaims, signer: KeyPair): string;
13
+ /** The claims of a NATS JWT (no verification; for tests and diagnostics). */
14
+ export declare function decodeNatsJwt(jwt: string): NatsClaims;
15
+ export declare function operatorJwt(operator: KeyPair, systemAccount: string): string;
16
+ /**
17
+ * An account JWT. `revocations` maps user public keys to the unix time before which their JWTs
18
+ * are revoked; re-publishing the account with a new entry disconnects that user.
19
+ */
20
+ export declare function accountJwt(operator: KeyPair, account: string, name: string, revocations?: Record<string, number>, extra?: Record<string, unknown>): string;
21
+ export type UserPermissions = {
22
+ pub: string[];
23
+ sub: string[];
24
+ };
25
+ export declare function userJwt(account: KeyPair, user: string, name: string, permissions?: UserPermissions): string;
26
+ /** A NATS credentials file (the user JWT and its seed), as `nsc` writes it. */
27
+ export declare function formatCreds(jwt: string, seed: string): string;
28
+ /** Issues a fresh user (new nkey) under an account and returns its credentials file. */
29
+ export declare function issueUserCreds(account: KeyPair, name: string, permissions?: UserPermissions): {
30
+ publicKey: string;
31
+ jwt: string;
32
+ creds: string;
33
+ };
34
+ export declare const seedOf: (kp: KeyPair) => string;
35
+ export declare const keyPairFromSeed: (seed: string) => KeyPair;
36
+ export declare const REGIONS_ACCOUNT_NAME = "REGIONS";
37
+ /** Claims of the REGIONS account; the hub preloads it and the control plane re-signs it. */
38
+ export declare function regionsAccountJwt(operator: KeyPair, account: string, revocations?: Record<string, number>): string;
39
+ /**
40
+ * Everything a region hub needs, generated once by `fonoster-region-hub-setup`:
41
+ * the hub's nats.conf, the control plane's seeds and two credentials files (the control plane's
42
+ * REGIONS user, unrestricted, and a system-account user to push account updates).
43
+ */
44
+ export declare function generateRegionHub(options: {
45
+ clientPort?: number;
46
+ leafPort?: number;
47
+ httpPort?: number;
48
+ /** TLS for the leaf listener (production); omitted only for local stacks. */
49
+ leafTls?: {
50
+ certFile: string;
51
+ keyFile: string;
52
+ };
53
+ resolverDir?: string;
54
+ }): {
55
+ conf: string;
56
+ operatorSeed: string;
57
+ accountSeed: string;
58
+ accountPublicKey: string;
59
+ systemAccountPublicKey: string;
60
+ controlPlaneCreds: string;
61
+ systemCreds: string;
62
+ };
63
+ export { createAccount, createOperator, createUser, KeyPair };
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUser = exports.createOperator = exports.createAccount = exports.REGIONS_ACCOUNT_NAME = exports.keyPairFromSeed = exports.seedOf = void 0;
4
+ exports.encodeNatsJwt = encodeNatsJwt;
5
+ exports.decodeNatsJwt = decodeNatsJwt;
6
+ exports.operatorJwt = operatorJwt;
7
+ exports.accountJwt = accountJwt;
8
+ exports.userJwt = userJwt;
9
+ exports.formatCreds = formatCreds;
10
+ exports.issueUserCreds = issueUserCreds;
11
+ exports.regionsAccountJwt = regionsAccountJwt;
12
+ exports.generateRegionHub = generateRegionHub;
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 crypto_1 = require("crypto");
32
+ const nkeys_js_1 = require("nkeys.js");
33
+ Object.defineProperty(exports, "createAccount", { enumerable: true, get: function () { return nkeys_js_1.createAccount; } });
34
+ Object.defineProperty(exports, "createOperator", { enumerable: true, get: function () { return nkeys_js_1.createOperator; } });
35
+ Object.defineProperty(exports, "createUser", { enumerable: true, get: function () { return nkeys_js_1.createUser; } });
36
+ /**
37
+ * Minimal NATS decentralized-auth JWTs (v2), enough for the region hub (RG-B2): an operator, the
38
+ * system account, the REGIONS account (with its user revocations) and per-region users whose
39
+ * permissions are `region.<ref>.>` only. Same encoding as nats-io/jwt: header
40
+ * `{"typ":"JWT","alg":"ed25519-nkey"}`, base64url parts, `jti` = base32(sha512/256(claims)).
41
+ */
42
+ const HEADER = { typ: "JWT", alg: "ed25519-nkey" };
43
+ const B32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
44
+ const b64url = (buf) => Buffer.from(buf).toString("base64url");
45
+ function base32(buf) {
46
+ let bits = 0;
47
+ let value = 0;
48
+ let out = "";
49
+ for (const byte of buf) {
50
+ value = (value << 8) | byte;
51
+ bits += 8;
52
+ while (bits >= 5) {
53
+ out += B32[(value >>> (bits - 5)) & 31];
54
+ bits -= 5;
55
+ }
56
+ }
57
+ if (bits > 0)
58
+ out += B32[(value << (5 - bits)) & 31];
59
+ return out;
60
+ }
61
+ /** Signs claims with an nkey pair (operator signs accounts, accounts sign users). */
62
+ function encodeNatsJwt(claims, signer) {
63
+ const body = Object.assign(Object.assign({}, claims), { jti: "" });
64
+ body.jti = base32((0, crypto_1.createHash)("sha512-256").update(JSON.stringify(body)).digest());
65
+ const head = b64url(Buffer.from(JSON.stringify(HEADER)));
66
+ const payload = b64url(Buffer.from(JSON.stringify(body)));
67
+ const sig = signer.sign(Buffer.from(`${head}.${payload}`));
68
+ return `${head}.${payload}.${b64url(sig)}`;
69
+ }
70
+ /** The claims of a NATS JWT (no verification; for tests and diagnostics). */
71
+ function decodeNatsJwt(jwt) {
72
+ return JSON.parse(Buffer.from(jwt.split(".")[1], "base64url").toString());
73
+ }
74
+ const now = () => Math.floor(Date.now() / 1000);
75
+ const pub = (kp) => kp.getPublicKey();
76
+ const NO_LIMITS = { subs: -1, data: -1, payload: -1 };
77
+ function operatorJwt(operator, systemAccount) {
78
+ return encodeNatsJwt({
79
+ iat: now(),
80
+ iss: pub(operator),
81
+ sub: pub(operator),
82
+ name: "fonoster-regions",
83
+ nats: { system_account: systemAccount, type: "operator", version: 2 }
84
+ }, operator);
85
+ }
86
+ /**
87
+ * An account JWT. `revocations` maps user public keys to the unix time before which their JWTs
88
+ * are revoked; re-publishing the account with a new entry disconnects that user.
89
+ */
90
+ function accountJwt(operator, account, name, revocations = {}, extra = {}) {
91
+ return encodeNatsJwt({
92
+ iat: now(),
93
+ iss: pub(operator),
94
+ sub: account,
95
+ name,
96
+ nats: Object.assign(Object.assign(Object.assign({ limits: Object.assign(Object.assign({}, NO_LIMITS), { imports: -1, exports: -1, wildcards: true, conn: -1, leaf: -1 }), default_permissions: { pub: {}, sub: {} } }, (Object.keys(revocations).length ? { revocations } : {})), extra), { type: "account", version: 2 })
97
+ }, operator);
98
+ }
99
+ function userJwt(account, user, name, permissions) {
100
+ return encodeNatsJwt({
101
+ iat: now(),
102
+ iss: pub(account),
103
+ sub: user,
104
+ name,
105
+ nats: Object.assign(Object.assign(Object.assign({}, (permissions
106
+ ? {
107
+ pub: { allow: permissions.pub },
108
+ sub: { allow: permissions.sub }
109
+ }
110
+ : { pub: {}, sub: {} })), NO_LIMITS), { type: "user", version: 2 })
111
+ }, account);
112
+ }
113
+ /** A NATS credentials file (the user JWT and its seed), as `nsc` writes it. */
114
+ function formatCreds(jwt, seed) {
115
+ return `-----BEGIN NATS USER JWT-----
116
+ ${jwt}
117
+ ------END NATS USER JWT------
118
+
119
+ ************************* IMPORTANT *************************
120
+ NKEY Seed printed below can be used to sign and prove identity.
121
+ NKEYs are sensitive and should be treated as secrets.
122
+
123
+ -----BEGIN USER NKEY SEED-----
124
+ ${seed}
125
+ ------END USER NKEY SEED------
126
+
127
+ *************************************************************
128
+ `;
129
+ }
130
+ /** Issues a fresh user (new nkey) under an account and returns its credentials file. */
131
+ function issueUserCreds(account, name, permissions) {
132
+ const user = (0, nkeys_js_1.createUser)();
133
+ const jwt = userJwt(account, pub(user), name, permissions);
134
+ return {
135
+ publicKey: pub(user),
136
+ jwt,
137
+ creds: formatCreds(jwt, Buffer.from(user.getSeed()).toString())
138
+ };
139
+ }
140
+ const seedOf = (kp) => Buffer.from(kp.getSeed()).toString();
141
+ exports.seedOf = seedOf;
142
+ const keyPairFromSeed = (seed) => (0, nkeys_js_1.fromSeed)(Buffer.from(seed.trim()));
143
+ exports.keyPairFromSeed = keyPairFromSeed;
144
+ exports.REGIONS_ACCOUNT_NAME = "REGIONS";
145
+ /** Claims of the REGIONS account; the hub preloads it and the control plane re-signs it. */
146
+ function regionsAccountJwt(operator, account, revocations = {}) {
147
+ return accountJwt(operator, account, exports.REGIONS_ACCOUNT_NAME, revocations);
148
+ }
149
+ /**
150
+ * Everything a region hub needs, generated once by `fonoster-region-hub-setup`:
151
+ * the hub's nats.conf, the control plane's seeds and two credentials files (the control plane's
152
+ * REGIONS user, unrestricted, and a system-account user to push account updates).
153
+ */
154
+ function generateRegionHub(options) {
155
+ var _a, _b, _c, _d;
156
+ const operator = (0, nkeys_js_1.createOperator)();
157
+ const sys = (0, nkeys_js_1.createAccount)();
158
+ const regions = (0, nkeys_js_1.createAccount)();
159
+ const opJwt = operatorJwt(operator, pub(sys));
160
+ const sysJwt = accountJwt(operator, pub(sys), "SYS");
161
+ const regJwt = regionsAccountJwt(operator, pub(regions));
162
+ const cpUser = issueUserCreds(regions, "control-plane");
163
+ const sysUser = issueUserCreds(sys, "control-plane-sys");
164
+ const leafTls = options.leafTls
165
+ ? `\n tls { cert_file: "${options.leafTls.certFile}", key_file: "${options.leafTls.keyFile}" }`
166
+ : "";
167
+ const conf = `# Region hub (add-private-regions, RG-B2): cells link here over an outbound leaf node.
168
+ # Generated by fonoster-region-hub-setup; operator mode, accounts pushed by the control plane.
169
+ port: ${(_a = options.clientPort) !== null && _a !== void 0 ? _a : 4222}
170
+ http_port: ${(_b = options.httpPort) !== null && _b !== void 0 ? _b : 8222}
171
+ operator: ${opJwt}
172
+ system_account: ${pub(sys)}
173
+ resolver: {
174
+ type: full
175
+ dir: "${(_c = options.resolverDir) !== null && _c !== void 0 ? _c : "/data/jwt"}"
176
+ allow_delete: false
177
+ }
178
+ resolver_preload: {
179
+ ${pub(sys)}: ${sysJwt}
180
+ ${pub(regions)}: ${regJwt}
181
+ }
182
+ leafnodes {
183
+ port: ${(_d = options.leafPort) !== null && _d !== void 0 ? _d : 7422}${leafTls}
184
+ }
185
+ `;
186
+ return {
187
+ conf,
188
+ operatorSeed: (0, exports.seedOf)(operator),
189
+ accountSeed: (0, exports.seedOf)(regions),
190
+ accountPublicKey: pub(regions),
191
+ systemAccountPublicKey: pub(sys),
192
+ controlPlaneCreds: cpUser.creds,
193
+ systemCreds: sysUser.creds
194
+ };
195
+ }