@fonoster/common 0.26.0 → 0.30.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 (176) hide show
  1. package/dist/assistants/index.d.ts +2 -6
  2. package/dist/assistants/index.js +2 -6
  3. package/dist/assistants/sessionAssistantSchema.d.ts +741 -0
  4. package/dist/assistants/sessionAssistantSchema.js +112 -0
  5. package/dist/assistants/testCasesSchema.d.ts +4 -4
  6. package/dist/{voice/Dial.d.ts → calls/index.d.ts} +16 -13
  7. package/dist/calls/index.js +44 -0
  8. package/dist/cellsecrets/index.d.ts +91 -0
  9. package/dist/cellsecrets/index.js +299 -0
  10. package/dist/config/cli/check.d.ts +6 -0
  11. package/dist/config/cli/check.js +202 -0
  12. package/dist/config/cli/envFile.d.ts +23 -0
  13. package/dist/config/cli/envFile.js +81 -0
  14. package/dist/config/cli/exposure.d.ts +10 -0
  15. package/dist/config/cli/exposure.js +93 -0
  16. package/dist/config/cli/index.d.ts +2 -0
  17. package/dist/{identity/tokenHasAccessKeyId.js → config/cli/index.js} +7 -8
  18. package/dist/config/cli/info.d.ts +6 -0
  19. package/dist/config/cli/info.js +62 -0
  20. package/dist/config/cli/init.d.ts +9 -0
  21. package/dist/config/cli/init.js +152 -0
  22. package/dist/config/cli/main.d.ts +11 -0
  23. package/dist/config/cli/main.js +155 -0
  24. package/dist/config/cli/render.d.ts +44 -0
  25. package/dist/config/cli/render.js +129 -0
  26. package/dist/config/cli/secrets.d.ts +21 -0
  27. package/dist/config/cli/secrets.js +117 -0
  28. package/dist/{utils/findIntegrationsCredentials.d.ts → config/cli/types.d.ts} +6 -5
  29. package/dist/config/cli/types.js +7 -0
  30. package/dist/config/configHints.d.ts +39 -0
  31. package/dist/config/configHints.js +61 -0
  32. package/dist/{voice → config}/index.d.ts +12 -13
  33. package/dist/config/index.js +46 -0
  34. package/dist/config/integrationsSchema.d.ts +32 -0
  35. package/dist/config/integrationsSchema.js +56 -0
  36. package/dist/config/interpolateEnv.d.ts +34 -0
  37. package/dist/config/interpolateEnv.js +70 -0
  38. package/dist/config/loadServiceConfig.d.ts +33 -0
  39. package/dist/config/loadServiceConfig.js +121 -0
  40. package/dist/config/logsSchema.d.ts +76 -0
  41. package/dist/config/logsSchema.js +49 -0
  42. package/dist/config/natsConnection.d.ts +53 -0
  43. package/dist/config/natsConnection.js +58 -0
  44. package/dist/config/parseConfigFile.d.ts +7 -0
  45. package/dist/config/parseConfigFile.js +60 -0
  46. package/dist/config/resolveConfigFile.d.ts +17 -0
  47. package/dist/config/resolveConfigFile.js +54 -0
  48. package/dist/config/resolveSecretRefs.d.ts +35 -0
  49. package/dist/config/resolveSecretRefs.js +129 -0
  50. package/dist/{assistants/audioFiltersSchema.d.ts → config/strictDeep.d.ts} +9 -12
  51. package/dist/config/strictDeep.js +58 -0
  52. package/dist/config/telemetrySchema.d.ts +39 -0
  53. package/dist/config/telemetrySchema.js +44 -0
  54. package/dist/config/toJsonSchema.d.ts +30 -0
  55. package/dist/config/toJsonSchema.js +161 -0
  56. package/dist/constants.d.ts +1 -4
  57. package/dist/constants.js +4 -5
  58. package/dist/envs.d.ts +2 -1
  59. package/dist/envs.js +13 -11
  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 +22 -6
  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 +11 -1
  74. package/dist/index.js +14 -2
  75. package/dist/net/assertPublicDestination.d.ts +52 -0
  76. package/dist/net/assertPublicDestination.js +342 -0
  77. package/dist/{voice/PlayDtmf.d.ts → net/index.d.ts} +1 -5
  78. package/dist/{voice → net}/index.js +1 -13
  79. package/dist/notifications/createSendEmail.js +3 -1
  80. package/dist/protos/applications.proto +124 -3
  81. package/dist/protos/authz.proto +23 -4
  82. package/dist/protos/capabilities.proto +94 -0
  83. package/dist/protos/identity.proto +26 -1
  84. package/dist/protos/providers.proto +135 -0
  85. package/dist/protos/webhooks.proto +140 -0
  86. package/dist/{voice/StopSay.d.ts → regions/hub/index.d.ts} +1 -6
  87. package/dist/regions/hub/index.js +35 -0
  88. package/dist/regions/hub/natsJwt.d.ts +63 -0
  89. package/dist/regions/hub/natsJwt.js +195 -0
  90. package/dist/registry/Registry.d.ts +79 -0
  91. package/dist/registry/Registry.js +418 -0
  92. package/dist/registry/cli.d.ts +20 -0
  93. package/dist/registry/cli.js +424 -0
  94. package/dist/{assistants/audioFiltersSchema.js → registry/features.d.ts} +13 -14
  95. package/dist/registry/features.js +36 -0
  96. package/dist/{assistants/LanguageModelProvider.d.ts → registry/index.d.ts} +6 -8
  97. package/dist/registry/index.js +40 -0
  98. package/dist/registry/prisma.d.ts +67 -0
  99. package/dist/registry/prisma.js +391 -0
  100. package/dist/registry/stores.d.ts +21 -0
  101. package/dist/{assistants/eventsHookSchema.js → registry/stores.js} +55 -18
  102. package/dist/registry/types.d.ts +98 -0
  103. package/dist/{voice/Say.d.ts → registry/types.js} +4 -10
  104. package/dist/registry/workspaceKeys.d.ts +41 -0
  105. package/dist/registry/workspaceKeys.js +64 -0
  106. package/dist/session/index.d.ts +19 -0
  107. package/dist/session/index.js +35 -0
  108. package/dist/session/schema.d.ts +1951 -0
  109. package/dist/session/schema.js +397 -0
  110. package/dist/sessions/index.d.ts +93 -0
  111. package/dist/sessions/index.js +194 -0
  112. package/dist/telemetry.d.ts +76 -0
  113. package/dist/telemetry.js +360 -0
  114. package/dist/types.d.ts +3 -5
  115. package/dist/utils/{findIntegrationsCredentials.js → WriteBehind.d.ts} +13 -10
  116. package/dist/utils/WriteBehind.js +64 -0
  117. package/dist/utils/index.d.ts +1 -1
  118. package/dist/utils/index.js +1 -1
  119. package/dist/{voice/Play.d.ts → utils/logUnhandledRejections.d.ts} +8 -12
  120. package/dist/utils/logUnhandledRejections.js +37 -0
  121. package/dist/validators/calls.d.ts +2 -2
  122. package/dist/validators/calls.js +5 -2
  123. package/dist/validators/identity.d.ts +37 -8
  124. package/dist/validators/identity.js +22 -3
  125. package/dist/validators/index.d.ts +1 -0
  126. package/dist/validators/index.js +1 -0
  127. package/dist/validators/sip.d.ts +40 -0
  128. package/dist/validators/sip.js +99 -0
  129. package/dist/validators/sipnet/credentials.d.ts +2 -2
  130. package/dist/validators/sipnet/domains.js +7 -7
  131. package/dist/validators/sipnet/trunks.d.ts +14 -14
  132. package/dist/validators/sipnet/trunks.js +4 -2
  133. package/dist/webhooks/Dispatcher.d.ts +87 -0
  134. package/dist/webhooks/Dispatcher.js +225 -0
  135. package/dist/webhooks/bus.d.ts +49 -0
  136. package/dist/webhooks/bus.js +170 -0
  137. package/dist/webhooks/events.d.ts +66 -0
  138. package/dist/webhooks/events.js +62 -0
  139. package/dist/webhooks/index.d.ts +23 -0
  140. package/dist/webhooks/index.js +39 -0
  141. package/dist/webhooks/prisma.d.ts +55 -0
  142. package/dist/webhooks/prisma.js +242 -0
  143. package/dist/webhooks/signing.d.ts +8 -0
  144. package/dist/webhooks/signing.js +53 -0
  145. package/package.json +25 -12
  146. package/schema/session.v1.json +791 -0
  147. package/dist/assistants/assistantSchema.d.ts +0 -739
  148. package/dist/assistants/assistantSchema.js +0 -37
  149. package/dist/assistants/conversationSettingsSchema.d.ts +0 -122
  150. package/dist/assistants/conversationSettingsSchema.js +0 -133
  151. package/dist/assistants/eventsHookSchema.d.ts +0 -38
  152. package/dist/assistants/languageModelConfigSchema.d.ts +0 -206
  153. package/dist/assistants/languageModelConfigSchema.js +0 -91
  154. package/dist/identity/tokenHasAccessKeyId.d.ts +0 -2
  155. package/dist/protos/voice.proto +0 -557
  156. package/dist/voice/Dial.js +0 -20
  157. package/dist/voice/Gather.d.ts +0 -37
  158. package/dist/voice/Gather.js +0 -9
  159. package/dist/voice/Mute.d.ts +0 -31
  160. package/dist/voice/Mute.js +0 -9
  161. package/dist/voice/Play.js +0 -2
  162. package/dist/voice/PlayDtmf.js +0 -2
  163. package/dist/voice/PlaybackControl.d.ts +0 -31
  164. package/dist/voice/PlaybackControl.js +0 -11
  165. package/dist/voice/Record.d.ts +0 -36
  166. package/dist/voice/Record.js +0 -7
  167. package/dist/voice/Say.js +0 -2
  168. package/dist/voice/StopSay.js +0 -2
  169. package/dist/voice/Stream.d.ts +0 -53
  170. package/dist/voice/Stream.js +0 -19
  171. package/dist/voice/StreamGather.d.ts +0 -34
  172. package/dist/voice/StreamGather.js +0 -9
  173. package/dist/voice/Verb.d.ts +0 -27
  174. package/dist/voice/Verb.js +0 -2
  175. package/dist/voice/voice.d.ts +0 -171
  176. package/dist/voice/voice.js +0 -65
@@ -56,6 +56,8 @@ service Identity {
56
56
  rpc ExchangeApiKey (ExchangeApiKeyRequest) returns (ExchangeApiKeyResponse) {}
57
57
  rpc ExchangeOauth2Code (ExchangeOauth2CodeRequest) returns (ExchangeOauth2CodeResponse) {}
58
58
  rpc ExchangeRefreshToken (ExchangeRefreshTokenRequest) returns (ExchangeRefreshTokenResponse) {}
59
+ // Trade an emailed sign-in code for tokens (passwordless sign-in)
60
+ rpc ExchangeVerificationCode (ExchangeVerificationCodeRequest) returns (ExchangeVerificationCodeResponse) {}
59
61
  rpc RevokeToken (RevokeTokenRequest) returns (RevokeTokenResponse) {}
60
62
 
61
63
  // Get the public key for verifying JWTs
@@ -78,14 +80,22 @@ message Workspace {
78
80
  int32 created_at = 5;
79
81
  int32 updated_at = 6;
80
82
  Owner owner = 7;
83
+ // A public region id (default, us-east-1) or a private region ref (rg_...). Immutable.
84
+ string region = 8;
81
85
  }
82
86
 
83
87
  message CreateWorkspaceRequest {
84
88
  string name = 1;
89
+ // A public region id, or one of the caller's private regions (id or rg_ ref). Empty means "default".
90
+ string region = 2;
85
91
  }
86
92
 
87
93
  message CreateWorkspaceResponse {
88
94
  string ref = 1;
95
+ string region = 2;
96
+ // Unused since PR-15 (regions are created at the user level, POST /api/regions); kept reserved.
97
+ string enrollment_token = 3;
98
+ string expires_at = 4;
89
99
  }
90
100
 
91
101
  message DeleteWorkspaceRequest {
@@ -113,6 +123,8 @@ message ListWorkspacesResponse {
113
123
  message UpdateWorkspaceRequest {
114
124
  string ref = 1;
115
125
  string name = 2;
126
+ // Accepted only when unchanged (the region is immutable).
127
+ string region = 3;
116
128
  }
117
129
 
118
130
  message UpdateWorkspaceResponse {
@@ -204,10 +216,12 @@ message User {
204
216
 
205
217
  message UpdateUserRequest {
206
218
  string ref = 1;
219
+ // A new password; current_password must be the account's password.
207
220
  string password = 2;
208
221
  string name = 3;
209
222
  string avatar = 4;
210
223
  string phone = 5;
224
+ string current_password = 6;
211
225
  }
212
226
 
213
227
  message UpdateUserResponse {
@@ -356,4 +370,15 @@ message RevokeTokenResponse {
356
370
  // Message with response with the public key
357
371
  message GetPublicKeyResponse {
358
372
  string public_key = 1;
359
- }
373
+ }
374
+
375
+ message ExchangeVerificationCodeRequest {
376
+ string email = 1;
377
+ string code = 2;
378
+ }
379
+
380
+ message ExchangeVerificationCodeResponse {
381
+ string id_token = 1;
382
+ string access_token = 2;
383
+ string refresh_token = 3;
384
+ }
@@ -0,0 +1,135 @@
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.providers.v1beta2;
22
+
23
+ // The provider catalog (read-only) and the workspace's own vendor keys (add-provider-registry)
24
+ service Providers {
25
+ // Catalog entries this workspace can use: providers, models and voices (not retired)
26
+ rpc ListCatalog(ListCatalogRequest) returns (ListCatalogResponse) {}
27
+ // Store or replace the workspace's key for a provider (kept in a write-only Secret)
28
+ rpc SetProviderKey(SetProviderKeyRequest) returns (ProviderKey) {}
29
+ // The workspace's provider keys (never the key itself)
30
+ rpc ListProviderKeys(ListProviderKeysRequest) returns (ListProviderKeysResponse) {}
31
+ // Remove the workspace's key for a provider (and its Secret)
32
+ rpc DeleteProviderKey(DeleteProviderKeyRequest) returns (DeleteProviderKeyResponse) {}
33
+ // Deprecated or retired items this workspace uses, with where they are used
34
+ rpc ListWarnings(ListWarningsRequest) returns (ListWarningsResponse) {}
35
+ }
36
+
37
+ message CatalogItem {
38
+ // Catalog id, e.g. deepgram/nova-3 or elevenlabs/rachel; a provider's id has no slash
39
+ string id = 1;
40
+ // provider, model or voice
41
+ string kind = 2;
42
+ // active or deprecated
43
+ string state = 3;
44
+ // The provider id (the item's own id for providers)
45
+ string provider_id = 4;
46
+ // Models: stt, tts or llm
47
+ string type = 5;
48
+ // Providers: capabilities (stt, tts, llm)
49
+ repeated string capabilities = 6;
50
+ // Models: languages; voices: their language
51
+ repeated string languages = 7;
52
+ // Models: features
53
+ repeated string features = 8;
54
+ // Voices: the models they work on
55
+ repeated string models = 9;
56
+ // Voices: gender, when known
57
+ string gender = 10;
58
+ // Deprecated items: the suggested replacement and the retirement date (YYYY-MM-DD)
59
+ string replacement = 11;
60
+ string retire_on = 12;
61
+ }
62
+
63
+ message ListCatalogRequest {
64
+ // Optional: provider, model or voice
65
+ string kind = 1;
66
+ // Optional: stt, tts or llm (models and providers)
67
+ string type = 2;
68
+ }
69
+
70
+ message ListCatalogResponse {
71
+ repeated CatalogItem items = 1;
72
+ }
73
+
74
+ message ProviderKey {
75
+ string ref = 1;
76
+ string provider_id = 2;
77
+ // The Secret holding the key
78
+ string secret_ref = 3;
79
+ int32 created_at = 4;
80
+ int32 updated_at = 5;
81
+ }
82
+
83
+ message SetProviderKeyRequest {
84
+ string provider_id = 1;
85
+ // The vendor key; write-only
86
+ string key = 2;
87
+ }
88
+
89
+ message ListProviderKeysRequest {}
90
+
91
+ message ListProviderKeysResponse {
92
+ repeated ProviderKey items = 1;
93
+ }
94
+
95
+ message DeleteProviderKeyRequest {
96
+ string provider_id = 1;
97
+ }
98
+
99
+ message DeleteProviderKeyResponse {
100
+ string provider_id = 1;
101
+ }
102
+
103
+ message WarningUse {
104
+ // app or assistant
105
+ string kind = 1;
106
+ string ref = 2;
107
+ string name = 3;
108
+ // The config field naming the item: voice, ttsModel, sttModel or llm
109
+ string field = 4;
110
+ // For a TTS model: the voice the config uses with it (e.g. the workspace's cloned voice)
111
+ string voice = 5;
112
+ }
113
+
114
+ message Warning {
115
+ string id = 1;
116
+ // provider, model or voice
117
+ string kind = 2;
118
+ // deprecated or retired
119
+ string state = 3;
120
+ string replacement = 4;
121
+ string retire_on = 5;
122
+ // Saved configs that reference the item
123
+ repeated WarningUse used_by = 6;
124
+ // Apps whose sessions used it in the last days, including ids no saved config names
125
+ repeated string runtime_apps = 7;
126
+ int32 runtime_sessions = 8;
127
+ // ISO 8601; empty without recent runtime use
128
+ string last_used_at = 9;
129
+ }
130
+
131
+ message ListWarningsRequest {}
132
+
133
+ message ListWarningsResponse {
134
+ repeated Warning items = 1;
135
+ }
@@ -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,9 +16,4 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { VerbRequest } from "./Verb";
20
- type StopSayRequest = VerbRequest;
21
- type StopSayResponse = {
22
- mediaSessionRef: string;
23
- };
24
- export { StopSayRequest, StopSayResponse };
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
+ }