@fonoster/apiserver 0.30.0 → 0.31.1

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 (159) hide show
  1. package/dist/applications/buildService.d.ts +1 -1
  2. package/dist/applications/buildService.js +4 -3
  3. package/dist/applications/createCreateApplication.js +6 -3
  4. package/dist/applications/createCreateTestToken.d.ts +3 -1
  5. package/dist/applications/createCreateTestToken.js +18 -13
  6. package/dist/applications/createGetFnUtil.d.ts +1 -1
  7. package/dist/applications/createUpdateApplication.js +6 -4
  8. package/dist/applications/evalKeys.d.ts +7 -1
  9. package/dist/applications/evalKeys.js +9 -3
  10. package/dist/applications/session/appModel.d.ts +28 -4
  11. package/dist/applications/session/appModel.js +74 -35
  12. package/dist/billing/buildService.d.ts +24 -0
  13. package/dist/billing/buildService.js +116 -0
  14. package/dist/{migration/cli.js → bin/usage.js} +46 -22
  15. package/dist/calls/buildService.d.ts +1 -20
  16. package/dist/calls/buildService.js +50 -10
  17. package/dist/calls/createCall.d.ts +16 -2
  18. package/dist/calls/createCall.js +29 -6
  19. package/dist/calls/createCallPublisher.d.ts +6 -4
  20. package/dist/calls/createCallPublisher.js +6 -5
  21. package/dist/calls/createTrackCall.d.ts +16 -13
  22. package/dist/calls/createTrackCall.js +78 -55
  23. package/dist/calls/getCall.d.ts +3 -3
  24. package/dist/calls/getCall.js +2 -3
  25. package/dist/calls/listCalls.d.ts +4 -4
  26. package/dist/calls/listCalls.js +2 -3
  27. package/dist/calls/types.d.ts +2 -1
  28. package/dist/capabilities/createGetCapabilities.d.ts +3 -0
  29. package/dist/capabilities/createGetCapabilities.js +2 -1
  30. package/dist/config/index.js +1 -3
  31. package/dist/config/schema.d.ts +106 -102
  32. package/dist/config/schema.js +39 -47
  33. package/dist/core/applyCatalog.d.ts +3 -3
  34. package/dist/core/applyCatalog.js +5 -4
  35. package/dist/core/regionHooks.d.ts +1 -0
  36. package/dist/core/runServices.js +25 -4
  37. package/dist/core/services.d.ts +25 -1
  38. package/dist/core/services.js +35 -11
  39. package/dist/core/testTokenConfig.js +2 -2
  40. package/dist/core/upsertRoomrPeer.d.ts +6 -0
  41. package/dist/core/{upsertMediaNodePeer.js → upsertRoomrPeer.js} +9 -9
  42. package/dist/envs.d.ts +30 -16
  43. package/dist/envs.js +49 -31
  44. package/dist/index.js +23 -22
  45. package/dist/outbound/createNodeDirectory.d.ts +35 -13
  46. package/dist/outbound/createNodeDirectory.js +54 -20
  47. package/dist/outbound/index.d.ts +1 -0
  48. package/dist/outbound/index.js +1 -0
  49. package/dist/outbound/placeOutboundCall.d.ts +53 -13
  50. package/dist/outbound/placeOutboundCall.js +135 -88
  51. package/dist/outbound/placementSweep.d.ts +56 -0
  52. package/dist/outbound/placementSweep.js +127 -0
  53. package/dist/outbound/runOutboundCalls.d.ts +18 -14
  54. package/dist/outbound/runOutboundCalls.js +46 -34
  55. package/dist/providers/createProvidersHandlers.d.ts +1 -10
  56. package/dist/providers/createProvidersHandlers.js +20 -25
  57. package/dist/providers/index.d.ts +2 -2
  58. package/dist/providers/index.js +2 -2
  59. package/dist/providers/registryUsage.d.ts +2 -2
  60. package/dist/providers/registryUsage.js +5 -5
  61. package/dist/records/createIndexRecord.d.ts +26 -3
  62. package/dist/records/createIndexRecord.js +37 -10
  63. package/dist/records/createRecordsRouter.js +4 -2
  64. package/dist/records/createSearchRecords.d.ts +4 -3
  65. package/dist/records/createSearchRecords.js +9 -21
  66. package/dist/records/maintenance.d.ts +1 -1
  67. package/dist/records/maintenance.js +1 -1
  68. package/dist/records/runCallRecords.d.ts +2 -0
  69. package/dist/records/runCallRecords.js +1 -1
  70. package/dist/records/types.d.ts +2 -0
  71. package/dist/regions/configSync.d.ts +5 -5
  72. package/dist/regions/configSync.js +9 -9
  73. package/dist/regions/createRegionsRouter.d.ts +6 -6
  74. package/dist/regions/createRegionsRouter.js +5 -5
  75. package/dist/regions/link.js +1 -1
  76. package/dist/regions/runRegions.d.ts +2 -0
  77. package/dist/regions/runRegions.js +4 -0
  78. package/dist/regions/service.js +4 -4
  79. package/dist/regions/sources.d.ts +1 -1
  80. package/dist/regions/sources.js +4 -4
  81. package/dist/regions/status.js +5 -4
  82. package/dist/regions/types.d.ts +2 -2
  83. package/dist/usage/buildService.d.ts +16 -0
  84. package/dist/{calls/influxdb.js → usage/buildService.js} +16 -9
  85. package/dist/{events/createPerCallCache.d.ts → usage/createGetUsage.d.ts} +7 -7
  86. package/dist/usage/createGetUsage.js +118 -0
  87. package/dist/usage/ingestUsage.d.ts +7 -0
  88. package/dist/usage/ingestUsage.js +87 -0
  89. package/dist/usage/publishRecordedUsage.d.ts +52 -0
  90. package/dist/usage/publishRecordedUsage.js +103 -0
  91. package/dist/usage/publishUsage.d.ts +29 -0
  92. package/dist/usage/publishUsage.js +50 -0
  93. package/dist/usage/rebuildUsage.d.ts +48 -0
  94. package/dist/usage/rebuildUsage.js +104 -0
  95. package/dist/usage/runUsageConsumer.d.ts +22 -0
  96. package/dist/usage/runUsageConsumer.js +78 -0
  97. package/dist/usage/snapshotStorage.d.ts +14 -0
  98. package/dist/usage/snapshotStorage.js +95 -0
  99. package/dist/usage/types.d.ts +36 -0
  100. package/dist/voice/stt/types.js +1 -1
  101. package/dist/webhooks/lostCalls.d.ts +35 -12
  102. package/dist/webhooks/lostCalls.js +86 -48
  103. package/dist/webhooks/nodeCallEvents.d.ts +73 -0
  104. package/dist/webhooks/nodeCallEvents.js +177 -0
  105. package/dist/webhooks/runWebhookFanout.d.ts +10 -4
  106. package/dist/webhooks/runWebhookFanout.js +41 -39
  107. package/package.json +17 -19
  108. package/dist/applications/migration/PrismaApplicationStore.d.ts +0 -55
  109. package/dist/applications/migration/PrismaApplicationStore.js +0 -92
  110. package/dist/applications/migration/convertLegacyApplication.d.ts +0 -11
  111. package/dist/applications/migration/convertLegacyApplication.js +0 -112
  112. package/dist/applications/migration/index.d.ts +0 -22
  113. package/dist/applications/migration/index.js +0 -38
  114. package/dist/applications/migration/migrateApplications.d.ts +0 -43
  115. package/dist/applications/migration/migrateApplications.js +0 -87
  116. package/dist/applications/migration/types.d.ts +0 -92
  117. package/dist/applications/migration/types.js +0 -20
  118. package/dist/calls/createFetchCalls.d.ts +0 -22
  119. package/dist/calls/createFetchCalls.js +0 -88
  120. package/dist/calls/createFetchSingleCall.d.ts +0 -22
  121. package/dist/calls/createFetchSingleCall.js +0 -54
  122. package/dist/calls/influxdb.d.ts +0 -2
  123. package/dist/core/upsertMediaNodePeer.d.ts +0 -6
  124. package/dist/events/callRefs.d.ts +0 -29
  125. package/dist/events/callRefs.js +0 -103
  126. package/dist/events/createCdrWriter.d.ts +0 -25
  127. package/dist/events/createCdrWriter.js +0 -95
  128. package/dist/events/createInfluxDbPub.d.ts +0 -10
  129. package/dist/events/createInfluxDbPub.js +0 -46
  130. package/dist/events/createPerCallCache.js +0 -46
  131. package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
  132. package/dist/events/mapCallDirectionToEnum.js +0 -37
  133. package/dist/events/nats.d.ts +0 -44
  134. package/dist/events/nats.js +0 -93
  135. package/dist/events/transformEvent.d.ts +0 -4
  136. package/dist/events/transformEvent.js +0 -87
  137. package/dist/events/types.d.ts +0 -26
  138. package/dist/migration/argv.d.ts +0 -22
  139. package/dist/migration/argv.js +0 -42
  140. package/dist/migration/catalogMapping.d.ts +0 -30
  141. package/dist/migration/catalogMapping.js +0 -53
  142. package/dist/migration/index.d.ts +0 -27
  143. package/dist/migration/index.js +0 -43
  144. package/dist/migration/migrateAssistants.d.ts +0 -8
  145. package/dist/migration/migrateAssistants.js +0 -169
  146. package/dist/migration/migrateCredentials.d.ts +0 -4
  147. package/dist/migration/migrateCredentials.js +0 -107
  148. package/dist/migration/migrateIntegrations.d.ts +0 -32
  149. package/dist/migration/migrateIntegrations.js +0 -136
  150. package/dist/migration/migrateLegacy.d.ts +0 -41
  151. package/dist/migration/migrateLegacy.js +0 -76
  152. package/dist/migration/providerKeys.d.ts +0 -14
  153. package/dist/migration/providerKeys.js +0 -61
  154. package/dist/migration/seedCatalog.d.ts +0 -2
  155. package/dist/migration/seedCatalog.js +0 -160
  156. package/dist/migration/types.d.ts +0 -42
  157. package/dist/migration/types.js +0 -31
  158. /package/dist/{migration/cli.d.ts → bin/usage.d.ts} +0 -0
  159. /package/dist/{events → usage}/types.js +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SHARED_VALUE_PATHS = exports.MOVED_KEYS = exports.fonosterConfigSchema = exports.featuresSchema = void 0;
3
+ exports.SHARED_VALUE_PATHS = exports.fonosterConfigSchema = exports.featuresSchema = void 0;
4
4
  /**
5
5
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -26,7 +26,13 @@ const zod_1 = require("zod");
26
26
  const featuresSchema = zod_1.z
27
27
  .object({
28
28
  auth: identity_1.authFeaturesSchema,
29
- billing: zod_1.z.object({ enabled: zod_1.z.boolean().default(false) }).default({}),
29
+ billing: zod_1.z
30
+ .object({
31
+ enabled: zod_1.z.boolean().default(false),
32
+ /** The billing service's Billing API (host:port); defaults to authz.host:50073. */
33
+ address: zod_1.z.string().min(1).optional()
34
+ })
35
+ .default({}),
30
36
  costs: zod_1.z
31
37
  .object({ display: zod_1.z.enum(["none", "usage", "prices"]).default("usage") })
32
38
  .default({}),
@@ -40,6 +46,14 @@ const featuresSchema = zod_1.z
40
46
  .default({}),
41
47
  recordings: zod_1.z.object({ store: zod_1.z.boolean().default(false) }).default({})
42
48
  })
49
+ .default({}),
50
+ /**
51
+ * SIP names (trunk inbound URIs, domains): "domain" requires one DNS label
52
+ * under `sip.<domain>` (carriers and phones reach a wildcard `*.sip.<domain>`);
53
+ * "any" accepts any host or IP, for installs reached by address.
54
+ */
55
+ sip: zod_1.z
56
+ .object({ names: zod_1.z.enum(["domain", "any"]).default("domain") })
43
57
  .default({})
44
58
  })
45
59
  .default({});
@@ -64,14 +78,13 @@ const recordStoreSchema = zod_1.z.union([
64
78
  })
65
79
  ]);
66
80
  /**
67
- * Call records (add-call-record): the index, the records API, retention, and ListCalls from the
68
- * index instead of InfluxDB. `stores` are the record stores the API reads from (the regions' and
81
+ * Call records (add-call-record): the index, the records API (ListCalls and GetCall read the
82
+ * index), and retention. `stores` are the record stores the API reads from (the regions' and
69
83
  * any workspace buckets), matched by the location in each index entry.
70
84
  */
71
85
  const callRecordsSchema = zod_1.z
72
86
  .object({
73
87
  enabled: zod_1.z.boolean().default(true),
74
- listCallsFromIndex: zod_1.z.boolean().default(true),
75
88
  stores: zod_1.z.array(recordStoreSchema).default([]),
76
89
  retentionIntervalMinutes: zod_1.z.number().int().positive().default(60),
77
90
  maintenanceTimeoutMs: zod_1.z.number().int().positive().default(30000)
@@ -79,7 +92,7 @@ const callRecordsSchema = zod_1.z
79
92
  .default({});
80
93
  /**
81
94
  * Session apps (voice-session G2): the hosted Autopilot that Autopilot apps point at, and the
82
- * secret the gateway signs their sessions with (the hosted Autopilot verifies one secret for every
95
+ * secret AppBridge signs their sessions with (the hosted Autopilot verifies one secret for every
83
96
  * Autopilot app). Without `signingSecret` each Autopilot app gets its own random secret.
84
97
  */
85
98
  const sessionAppsSchema = zod_1.z
@@ -95,26 +108,23 @@ const sessionAppsSchema = zod_1.z
95
108
  allowedDestinations: zod_1.z.array(zod_1.z.string().min(1)).optional()
96
109
  })
97
110
  .default({});
98
- /**
99
- * Provider registry (add-provider-registry 4.1): the platform credentials (credentialRef names)
100
- * the gateways have. When set, the catalog only lists providers with one of them or with the
101
- * workspace's own key.
102
- */
103
- const registrySchema = zod_1.z
104
- .object({
105
- platformCredentials: zod_1.z.array(zod_1.z.string().min(1)).optional()
106
- })
107
- .default({});
108
111
  /**
109
112
  * The provider catalog file (add-self-host-installer D7): applied to the registry tables on
110
113
  * every start with `fonoster-registry apply --store database` semantics. Listed entries are added
111
114
  * or updated; entries not in the file (operator-added) are kept. Absent: nothing is applied.
115
+ *
116
+ * `files` are applied after `file`, in order (a stack's own catalogs, such as the fakes'
117
+ * mods/conformance/fakes.catalog.yaml in dev and test stacks).
112
118
  */
113
- const catalogSchema = zod_1.z.object({ file: zod_1.z.string().min(1) }).optional();
119
+ const catalogSchema = zod_1.z
120
+ .object({
121
+ file: zod_1.z.string().min(1),
122
+ files: zod_1.z.array(zod_1.z.string().min(1)).optional()
123
+ })
124
+ .optional();
114
125
  /**
115
- * Assistant evaluations (EvaluateIntelligence): platform model keys by credentialRef, used when a
126
+ * Agent evaluations (EvaluateIntelligence): platform model keys by credentialRef, used when a
116
127
  * workspace has no key of its own for the provider. Values take `secret://` references (D8).
117
- * `fonoster-migrate-legacy --integrations` writes them from the retired integrations.json.
118
128
  */
119
129
  const evaluationsSchema = zod_1.z
120
130
  .object({ credentials: zod_1.z.record(zod_1.z.string().min(1)).default({}) })
@@ -247,14 +257,19 @@ const fonosterConfigSchema = zod_1.z
247
257
  .object({
248
258
  apiEndpoint: zod_1.z.string().default("routr:51907"),
249
259
  /**
250
- * The peer Go media nodes register under (least-sessions, add-media-node 4.1). Without a
260
+ * host:port of Routr's SIP listener: API-originated calls are dialed through it
261
+ * (CreateCall's to.proxy), as the roomr peer below (to.auth).
262
+ */
263
+ sipProxy: zod_1.z.string().default("routr:5060"),
264
+ /**
265
+ * The peer Go Roomr nodes register under (least-sessions, add-roomr 4.1). Without a
251
266
  * password the apiserver does not create it.
252
267
  */
253
- mediaNodePeer: zod_1.z
268
+ roomrPeer: zod_1.z
254
269
  .object({
255
- aor: zod_1.z.string().default("sip:medianode@default"),
256
- name: zod_1.z.string().default("Media Nodes"),
257
- username: zod_1.z.string().default("medianode"),
270
+ aor: zod_1.z.string().default("sip:roomr@default"),
271
+ name: zod_1.z.string().default("Roomr nodes"),
272
+ username: zod_1.z.string().default("roomr"),
258
273
  password: zod_1.z.string().optional()
259
274
  })
260
275
  .default({})
@@ -267,13 +282,6 @@ const fonosterConfigSchema = zod_1.z
267
282
  user: zod_1.z.string().min(1).optional(),
268
283
  password: zod_1.z.string().min(1).optional()
269
284
  }),
270
- influxdb: zod_1.z.object({
271
- url: zod_1.z.string().min(1),
272
- org: zod_1.z.string().min(1),
273
- username: zod_1.z.string().min(1),
274
- password: zod_1.z.string().min(1),
275
- token: zod_1.z.string().min(1)
276
- }),
277
285
  evaluations: evaluationsSchema,
278
286
  templatesDir: zod_1.z.string().optional(),
279
287
  twilio: identity_1.twilioSchema.optional(),
@@ -281,7 +289,6 @@ const fonosterConfigSchema = zod_1.z
281
289
  callRecords: callRecordsSchema,
282
290
  apps: sessionAppsSchema,
283
291
  webhooks: webhooksSchema,
284
- registry: registrySchema,
285
292
  catalog: catalogSchema,
286
293
  regions: regionsSchema
287
294
  })
@@ -348,18 +355,3 @@ exports.fonosterConfigSchema = fonosterConfigSchema;
348
355
  */
349
356
  const SHARED_VALUE_PATHS = ["*"];
350
357
  exports.SHARED_VALUE_PATHS = SHARED_VALUE_PATHS;
351
- /** Keys people may carry over from identity.json or older drafts. */
352
- const MOVED_KEYS = {
353
- encryptionKey: "encryption.key",
354
- defaultUser: "identity.owner",
355
- invite: "identity.invites",
356
- issuer: "identity.issuer",
357
- audience: "identity.audience",
358
- keys: "identity.keys",
359
- tokens: "identity.tokens",
360
- oauth2: "identity.oauth2",
361
- "smtp.auth": "smtp.user and smtp.password",
362
- owner: "identity.owner",
363
- integrationsFile: "evaluations.credentials (run fonoster-migrate-legacy --integrations once)"
364
- };
365
- exports.MOVED_KEYS = MOVED_KEYS;
@@ -4,7 +4,7 @@
4
4
  * updated; entries not in the file are kept. Equal entries write nothing, so a restart with the
5
5
  * same file changes no rows. Returns the change lines (["no changes"] when there are none).
6
6
  */
7
- declare function applyCatalog(file: string, prisma: any, options?: {
8
- testMode?: boolean;
9
- }): Promise<string[]>;
7
+ declare function applyCatalog(file: string, prisma: any,
8
+ /** The config key that names the file, for errors and the audit log. */
9
+ key?: string): Promise<string[]>;
10
10
  export { applyCatalog };
@@ -72,20 +72,21 @@ const common_1 = require("@fonoster/common");
72
72
  function applyCatalog(file_1, prisma_1) {
73
73
  return __awaiter(this, arguments, void 0, function* (file,
74
74
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- prisma, options = {}) {
75
+ prisma,
76
+ /** The config key that names the file, for errors and the audit log. */
77
+ key = "catalog.file") {
76
78
  let content;
77
79
  try {
78
80
  content = fs.readFileSync(file, "utf8");
79
81
  }
80
82
  catch (e) {
81
- throw new Error(`catalog.file ${file} could not be read: ${e.message}`);
83
+ throw new Error(`${key} ${file} could not be read: ${e.message}`);
82
84
  }
83
85
  const store = yield common_1.Registry.PrismaRegistryStore.open(prisma);
84
86
  const registry = new common_1.Registry.Registry({
85
87
  store,
86
88
  actor: "apiserver",
87
- testMode: options.testMode,
88
- commandLine: `apiserver catalog.file ${file}`
89
+ commandLine: `apiserver ${key} ${file}`
89
90
  });
90
91
  const lines = registry.apply(content);
91
92
  yield store.flush();
@@ -4,6 +4,7 @@ export declare const workspaceRegionHooks: {
4
4
  defaultRegion: string;
5
5
  attach(r: import("../regions/runRegions").RegionsRuntime): void;
6
6
  attachDirectory(d: import("../regions/types").WorkspaceDirectory): void;
7
+ directory(): import("../regions/types").WorkspaceDirectory | undefined;
7
8
  resolveRegion(ownerRef: string, requested?: string): Promise<{
8
9
  region: any;
9
10
  }>;
@@ -76,6 +76,10 @@ const providers_1 = require("../providers");
76
76
  const records_1 = require("../records");
77
77
  const regions_1 = require("../regions");
78
78
  const session_1 = require("../session");
79
+ const publishRecordedUsage_1 = require("../usage/publishRecordedUsage");
80
+ const publishUsage_1 = require("../usage/publishUsage");
81
+ const runUsageConsumer_1 = require("../usage/runUsageConsumer");
82
+ const snapshotStorage_1 = require("../usage/snapshotStorage");
79
83
  const runWebhookFanout_1 = require("../webhooks/runWebhookFanout");
80
84
  const allowList_1 = require("./allowList");
81
85
  const db_1 = require("./db");
@@ -125,7 +129,8 @@ function runServices() {
125
129
  handlers,
126
130
  callFeatures: (0, config_1.getConfig)().features.calls
127
131
  }),
128
- rootDomain: () => envs_1.DOMAIN
132
+ // Workspace domains are <label>.sip.<domain>; a region rewrites them to its own.
133
+ rootDomain: () => envs_1.SIP_ROOT
129
134
  });
130
135
  regionHooks_1.workspaceRegionHooks.attach(regions);
131
136
  // Load the remaining services; writes to synced resources notify the config sync
@@ -140,7 +145,8 @@ function runServices() {
140
145
  },
141
146
  db: db_1.prisma,
142
147
  relay: { regionOf: regions.regionOf, client: regions.relay },
143
- onConfigChange: regions.onConfigChange
148
+ onConfigChange: regions.onConfigChange,
149
+ usage: { directory: () => regionHooks_1.workspaceRegionHooks.directory() }
144
150
  });
145
151
  // The dashboard's cookie session (M4): refresh token in an httpOnly cookie on its origin
146
152
  const session = {
@@ -154,13 +160,28 @@ function runServices() {
154
160
  port: envs_1.HTTP_BRIDGE_PORT,
155
161
  routers: [...records.routers, ...regions.routers, session]
156
162
  });
157
- // Bus consumers: webhook fan-out (LO-B1) and the gateways' catalog use (LO-B11)
163
+ // Bus consumers: webhook fan-out (LO-B1) and the AppBridge replicas' catalog use (LO-B11)
158
164
  const bus = yield (0, nats_1.connect)(Object.assign(Object.assign({}, envs_1.NATS), { maxReconnectAttempts: -1 }));
159
165
  (0, providers_1.subscribeRegistryUsage)(bus, db_1.prisma);
166
+ (0, publishUsage_1.attachUsagePublisher)(bus);
167
+ yield (0, runUsageConsumer_1.runUsageConsumer)({
168
+ nc: bus,
169
+ db: db_1.prisma,
170
+ directory: () => regionHooks_1.workspaceRegionHooks.directory()
171
+ });
172
+ if (envs_1.BILLING_ENABLED)
173
+ yield (0, publishRecordedUsage_1.runRecordedUsagePublisher)({
174
+ nc: bus,
175
+ db: db_1.prisma
176
+ });
177
+ (0, snapshotStorage_1.runStorageSnapshots)({
178
+ db: db_1.prisma,
179
+ directory: () => regionHooks_1.workspaceRegionHooks.directory()
180
+ });
160
181
  if (envs_1.WEBHOOKS.fanout) {
161
182
  yield (0, runWebhookFanout_1.runWebhookFanout)(Object.assign(Object.assign({}, envs_1.WEBHOOKS), { enabled: true, allowInsecureUrls: envs_1.SESSION_APPS.allowInsecureWebhooks }), { nc: bus, db: db_1.prisma });
162
183
  }
163
- // CreateCall: places API-originated calls on the media nodes (cleanbreak CB-B2)
184
+ // CreateCall: places API-originated calls on the Roomr nodes (cleanbreak CB-B2)
164
185
  yield (0, outbound_1.runOutboundCalls)({ natsUrl: envs_1.NATS_CONNECTION });
165
186
  server.bindAsync(envs_1.APISERVER_BIND_ADDR, credentials, () => __awaiter(this, void 0, void 0, function* () {
166
187
  healthImpl.setStatus("", common_1.GRPC_SERVING_STATUS);
@@ -381,5 +381,29 @@ declare const services: Promise<[{
381
381
  request: unknown;
382
382
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
383
383
  };
384
- }]>;
384
+ }, {
385
+ definition: {
386
+ serviceName: string;
387
+ pckg: string;
388
+ version: string;
389
+ proto: string;
390
+ };
391
+ handlers: {
392
+ getUsage: (call: {
393
+ request: unknown;
394
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
395
+ };
396
+ }, ...{
397
+ definition: {
398
+ serviceName: string;
399
+ pckg: string;
400
+ version: string;
401
+ proto: string;
402
+ };
403
+ handlers: {
404
+ [k: string]: (call: {
405
+ request: Record<string, unknown>;
406
+ }, callback: (error: import("@grpc/grpc-js").ServiceError | null | Partial<import("@grpc/grpc-js").ServiceError>, response?: unknown) => void) => void;
407
+ };
408
+ }[]]>;
385
409
  export default services;
@@ -1,4 +1,13 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  /**
4
13
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
@@ -21,13 +30,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
30
  const identity_1 = require("@fonoster/identity");
22
31
  const sipnet_1 = require("@fonoster/sipnet");
23
32
  const applications_1 = require("../applications");
33
+ const buildService_1 = require("../billing/buildService");
24
34
  const calls_1 = require("../calls");
25
- const influxdb_1 = require("../calls/influxdb");
26
35
  const capabilities_1 = require("../capabilities");
27
36
  const config_1 = require("../config");
28
37
  const envs_1 = require("../envs");
29
38
  const providers_1 = require("../providers");
30
39
  const secrets_1 = require("../secrets");
40
+ const buildService_2 = require("../usage/buildService");
31
41
  const utils_1 = require("../utils");
32
42
  const webhooks_1 = require("../webhooks");
33
43
  const db_1 = require("./db");
@@ -35,25 +45,36 @@ const identityConfig_1 = require("./identityConfig");
35
45
  const regionHooks_1 = require("./regionHooks");
36
46
  const routrConfig_1 = require("./routrConfig");
37
47
  const testTokenConfig_1 = require("./testTokenConfig");
38
- const applicationsService = (0, applications_1.buildApplicationsService)(db_1.prisma, testTokenConfig_1.testTokenConfig);
48
+ // A browser test call records who placed it (#1060): the signed-in user's email.
49
+ const identityDb = (0, identity_1.createPrismaClient)(identityConfig_1.identityConfig.dbUrl, identityConfig_1.identityConfig.encryptionKey);
50
+ const applicationsService = (0, applications_1.buildApplicationsService)(db_1.prisma, testTokenConfig_1.testTokenConfig, undefined, (userRef) => __awaiter(void 0, void 0, void 0, function* () {
51
+ var _a;
52
+ return (_a = (yield identityDb.user.findUnique({
53
+ where: { ref: userRef },
54
+ select: { email: true }
55
+ }))) === null || _a === void 0 ? void 0 : _a.email;
56
+ }));
39
57
  const secretsService = (0, secrets_1.buildSecretsService)(db_1.prisma);
40
- const callsService = (0, calls_1.buildCallsService)(influxdb_1.influxdb);
58
+ const callsService = (0, calls_1.buildCallsService)();
41
59
  const identityService = (0, identity_1.buildIdentityService)(Object.assign(Object.assign({}, identityConfig_1.identityConfig), { regions: regionHooks_1.workspaceRegionHooks }));
42
60
  const agentsService = (0, sipnet_1.buildAgentsService)(routrConfig_1.routrConfig);
43
- const domainsService = (0, sipnet_1.buildDomainsService)(routrConfig_1.routrConfig);
61
+ const domainsService = (0, sipnet_1.buildDomainsService)(routrConfig_1.routrConfig, {
62
+ namesRoot: envs_1.DOMAIN_NAMES_ROOT
63
+ });
44
64
  const credentialsService = (0, sipnet_1.buildCredentialsService)(routrConfig_1.routrConfig);
45
- const trunksService = (0, sipnet_1.buildTrunksService)(routrConfig_1.routrConfig);
46
- // App-linked numbers point at the media-node peer (Asterisk is retired, cleanbreak CB-B3).
65
+ const trunksService = (0, sipnet_1.buildTrunksService)(routrConfig_1.routrConfig, {
66
+ namesRoot: envs_1.TRUNK_NAMES_ROOT
67
+ });
68
+ // App-linked numbers point at the roomr peer (Asterisk is retired, cleanbreak CB-B3).
47
69
  const numberRouting = (0, sipnet_1.createNumberRouting)({
48
- mediaNodeAor: envs_1.ROUTR_MEDIA_NODE_PEER.aor
70
+ roomrNodeAor: envs_1.ROUTR_ROOMR_PEER.aor
49
71
  });
50
72
  const numbersService = (0, sipnet_1.buildNumbersService)(routrConfig_1.routrConfig, (0, utils_1.createCheckNumberPreconditions)(db_1.prisma), numberRouting);
51
73
  const aclsService = (0, sipnet_1.buildAclsService)(routrConfig_1.routrConfig);
52
74
  const capabilitiesService = (0, capabilities_1.buildCapabilitiesService)((0, config_1.getConfig)());
53
75
  const webhooksService = (0, webhooks_1.buildWebhooksService)(db_1.prisma);
54
- const providersService = (0, providers_1.buildProvidersService)(db_1.prisma, {
55
- platformCredentials: envs_1.REGISTRY.platformCredentials
56
- });
76
+ const providersService = (0, providers_1.buildProvidersService)(db_1.prisma);
77
+ const usageService = (0, buildService_2.buildService)(db_1.prisma);
57
78
  const services = Promise.all([
58
79
  applicationsService,
59
80
  secretsService,
@@ -67,6 +88,9 @@ const services = Promise.all([
67
88
  domainsService,
68
89
  capabilitiesService,
69
90
  webhooksService,
70
- providersService
91
+ providersService,
92
+ usageService,
93
+ // Billing (Fonoster Cloud): only when it is on (add-billing-service 6.1).
94
+ ...(envs_1.BILLING_ENABLED ? [(0, buildService_1.buildService)(envs_1.BILLING_ADDRESS)] : [])
71
95
  ]);
72
96
  exports.default = services;
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.testTokenConfig = void 0;
4
4
  const config_1 = require("../config");
5
5
  const envs_1 = require("../envs");
6
- // Browser test calls reach the media nodes' Peer; the browser names the agent with X-App-Ref
6
+ // Browser test calls reach the Roomr nodes' Peer; the browser names the agent with X-App-Ref
7
7
  // (add-talk-in-browser D1).
8
8
  const testTokenConfig = {
9
9
  username: "internal",
10
10
  domain: "internal",
11
11
  displayName: "Test Call Agent",
12
- targetAor: (0, config_1.getConfig)().routr.mediaNodePeer.aor,
12
+ targetAor: (0, config_1.getConfig)().routr.roomrPeer.aor,
13
13
  signalingServer: envs_1.APISERVER_SIGNALING_SERVER
14
14
  };
15
15
  exports.testTokenConfig = testTokenConfig;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The peer Go Roomr nodes register under: least-sessions over `X-Session-Count`, any number of
3
+ * nodes (add-roomr 4.1). Created only when `routr.roomrPeer.password` is set.
4
+ */
5
+ declare function upsertRoomrPeer(attempt?: number, delayMs?: number): Promise<void>;
6
+ export { upsertRoomrPeer };
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.upsertMediaNodePeer = upsertMediaNodePeer;
15
+ exports.upsertRoomrPeer = upsertRoomrPeer;
16
16
  /**
17
17
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
18
18
  * http://github.com/fonoster/fonoster
@@ -40,12 +40,12 @@ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filen
40
40
  const RETRY_DELAY_MS = 5000;
41
41
  const MAX_ATTEMPTS = 60;
42
42
  /**
43
- * The peer Go media nodes register under: least-sessions over `X-Session-Count`, any number of
44
- * nodes (add-media-node 4.1). Created only when `routr.mediaNodePeer.password` is set.
43
+ * The peer Go Roomr nodes register under: least-sessions over `X-Session-Count`, any number of
44
+ * nodes (add-roomr 4.1). Created only when `routr.roomrPeer.password` is set.
45
45
  */
46
- function upsertMediaNodePeer() {
46
+ function upsertRoomrPeer() {
47
47
  return __awaiter(this, arguments, void 0, function* (attempt = 1, delayMs = RETRY_DELAY_MS) {
48
- const { aor, name, username, password } = envs_1.ROUTR_MEDIA_NODE_PEER;
48
+ const { aor, name, username, password } = envs_1.ROUTR_ROOMR_PEER;
49
49
  if (!password)
50
50
  return;
51
51
  const peers = new sdk_1.default.Peers(routrConfig_1.routrConfig);
@@ -68,19 +68,19 @@ function upsertMediaNodePeer() {
68
68
  });
69
69
  peer.credentialsRef = creds.ref;
70
70
  yield peers.updatePeer(peer);
71
- logger.info("media-node peer created", { peerRef: peer.ref, aor });
71
+ logger.info("roomr peer created", { peerRef: peer.ref, aor });
72
72
  }
73
73
  catch (err) {
74
74
  const error = err;
75
75
  if (error.message.includes("already exist")) {
76
- logger.info("media-node peer already exists");
76
+ logger.info("roomr peer already exists");
77
77
  return;
78
78
  }
79
79
  if (error.message.includes("Cannot connect") && attempt < MAX_ATTEMPTS) {
80
80
  yield new Promise((resolve) => setTimeout(resolve, delayMs));
81
- return upsertMediaNodePeer(attempt + 1, delayMs);
81
+ return upsertRoomrPeer(attempt + 1, delayMs);
82
82
  }
83
- logger.error(`error creating the media-node peer: ${error.message}`, {
83
+ logger.error(`error creating the roomr peer: ${error.message}`, {
84
84
  code: error.code
85
85
  });
86
86
  }
package/dist/envs.d.ts CHANGED
@@ -4,15 +4,22 @@ export declare const APISERVER_SIGNALING_SERVER: string;
4
4
  export declare const APP_URL: string;
5
5
  export declare const CALLS_CREATE_SUBJECT = "calls.create";
6
6
  /**
7
- * A call's status events, keyed by the call (TrackCall on any replica subscribes to them all):
8
- * TRYING and FAILED from the control plane that places the call, and the media node's
9
- * call.progress, call.answered and room.ended for the call's room.
7
+ * The control plane's own status of a call it places (TRYING, the node that took it, FAILED),
8
+ * keyed by the call, so TrackCall on any replica sees it.
10
9
  */
11
10
  export declare const callEventsSubject: (ref: string) => string;
12
- /** Every call's status events (TrackCall's subscription). */
11
+ /** Every call's control-plane status (TrackCall's subscription). */
13
12
  export declare const CALL_EVENTS_WILDCARD = "calls.*.events";
14
- /** Every media node's heartbeat and node.down (TrackCall ends the calls of a lost node). */
15
- export declare const NODE_HEARTBEAT_WILDCARD = "media.*.heartbeat";
13
+ /**
14
+ * A call's events from its Roomr node (media-control "Events on NATS are keyed by call"):
15
+ * call.started, call.ringing, call.answered, call.ended and the call's participant and operation
16
+ * events, each with node_ref, seq and metadata.
17
+ */
18
+ export declare const mediaCallEventsSubject: (ref: string) => string;
19
+ /** Every call's media events (TrackCall's subscription; room events are roomr.events.room.*). */
20
+ export declare const MEDIA_CALL_EVENTS_WILDCARD = "roomr.events.*";
21
+ /** Every Roomr node's heartbeat and node.down (TrackCall ends the calls of a lost node). */
22
+ export declare const NODE_HEARTBEAT_WILDCARD = "roomr.nodes.*.heartbeat";
16
23
  export declare const CLOAK_ENCRYPTION_KEY: string;
17
24
  export declare const DATABASE_URL: string;
18
25
  export declare const DEFAULT_NATS_QUEUE_GROUP = "apiserver";
@@ -33,15 +40,14 @@ export declare const IDENTITY_WORKSPACE_INVITE_FAIL_URL: string;
33
40
  export declare const IDENTITY_WORKSPACE_INVITE_EXPIRATION: string;
34
41
  export declare const IDENTITY_WORKSPACE_INVITE_URL: string;
35
42
  export declare const IDENTITY_DATABASE_URL: string;
43
+ /** Billing is on (Cloud): stored usage is published for the billing service (add-billing-service D2). */
44
+ export declare const BILLING_ENABLED: boolean;
45
+ /** Where the Billing API is served (the billing service). */
46
+ export declare const BILLING_ADDRESS: string;
36
47
  export declare const AUTHZ_SERVICE_ENABLED: boolean;
37
48
  export declare const AUTHZ_SERVICE_HOST: string;
38
49
  export declare const AUTHZ_SERVICE_PORT: number;
39
50
  export declare const AUTHZ_SERVICE_METHODS: string[];
40
- export declare const INFLUXDB_ORG: string;
41
- export declare const INFLUXDB_PASSWORD: string;
42
- export declare const INFLUXDB_TOKEN: string;
43
- export declare const INFLUXDB_URL: string;
44
- export declare const INFLUXDB_USERNAME: string;
45
51
  export declare const EVALUATIONS: {
46
52
  credentials?: Record<string, string>;
47
53
  };
@@ -63,12 +69,14 @@ export declare const OWNER_EMAIL: string;
63
69
  export declare const OWNER_NAME: string;
64
70
  export declare const OWNER_PASSWORD: string;
65
71
  export declare const ROUTR_API_ENDPOINT: string;
66
- export declare const ROUTR_MEDIA_NODE_PEER: {
72
+ export declare const ROUTR_ROOMR_PEER: {
67
73
  name?: string;
68
74
  aor?: string;
69
75
  username?: string;
70
76
  password?: string;
71
77
  };
78
+ /** Routr's SIP address: API-originated calls are dialed through it (Roomr CreateCall). */
79
+ export declare const ROUTR_SIP_PROXY: string;
72
80
  export declare const SMTP_AUTH_PASS: string;
73
81
  export declare const SMTP_AUTH_USER: string;
74
82
  export declare const SMTP_HOST: string;
@@ -81,7 +89,6 @@ export declare const TWILIO_AUTH_TOKEN: string;
81
89
  export declare const TWILIO_PHONE_NUMBER: string;
82
90
  export declare const CALL_RECORDS: {
83
91
  enabled?: boolean;
84
- listCallsFromIndex?: boolean;
85
92
  stores?: ({
86
93
  dir?: string;
87
94
  } | {
@@ -111,9 +118,6 @@ export declare const WEBHOOKS: {
111
118
  intervalMs?: number;
112
119
  refreshMs?: number;
113
120
  };
114
- export declare const REGISTRY: {
115
- platformCredentials?: string[];
116
- };
117
121
  export declare const REGIONS: {
118
122
  public?: {
119
123
  id?: string;
@@ -159,3 +163,13 @@ export declare const REGIONS: {
159
163
  configDebounceMs?: number;
160
164
  };
161
165
  export declare const DOMAIN: string;
166
+ /**
167
+ * The install's SIP roots, split as Twilio does: carriers reach trunks at
168
+ * `<label>.pstn.<domain>`, phones register on domains at `<label>.sip.<domain>`.
169
+ */
170
+ export declare const PSTN_ROOT: string;
171
+ export declare const SIP_ROOT: string;
172
+ /** Where trunk inbound URIs must live, or undefined when features.sip.names is "any". */
173
+ export declare const TRUNK_NAMES_ROOT: string;
174
+ /** Where domains must live, or undefined when features.sip.names is "any". */
175
+ export declare const DOMAIN_NAMES_ROOT: string;