@fonoster/apiserver 0.49.0 → 0.50.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.
@@ -24,8 +24,8 @@ export declare const sessionAppInputSchema: z.ZodObject<{
24
24
  }>>;
25
25
  url: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
26
26
  protocol: z.ZodPreprocess<z.ZodOptional<z.ZodEnum<{
27
- twilio: "twilio";
28
27
  fonoster: "fonoster";
28
+ twilio: "twilio";
29
29
  }>>, unknown>;
30
30
  speech: z.ZodPreprocess<z.ZodPrefault<z.ZodObject<{
31
31
  voice: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
@@ -93,7 +93,7 @@ export declare function toAppColumns(db: AppsDb, request: Record<string, unknown
93
93
  type: "STREAM" | "AUTOPILOT";
94
94
  endpoint: string;
95
95
  url: string;
96
- protocol: "twilio" | "fonoster";
96
+ protocol: "fonoster" | "twilio";
97
97
  speechVoice: string;
98
98
  speechLanguage: string;
99
99
  speechSttModel: string;
@@ -16,6 +16,19 @@ declare const featuresSchema: z.ZodPrefault<z.ZodObject<{
16
16
  enabled: z.ZodDefault<z.ZodBoolean>;
17
17
  address: z.ZodOptional<z.ZodString>;
18
18
  }, z.core.$strip>>;
19
+ ops: z.ZodPrefault<z.ZodObject<{
20
+ enabled: z.ZodDefault<z.ZodBoolean>;
21
+ secret: z.ZodOptional<z.ZodString>;
22
+ interop: z.ZodPrefault<z.ZodObject<{
23
+ intervalMinutes: z.ZodDefault<z.ZodNumber>;
24
+ }, z.core.$strip>>;
25
+ databases: z.ZodPrefault<z.ZodObject<{
26
+ fonoster: z.ZodOptional<z.ZodString>;
27
+ identity: z.ZodOptional<z.ZodString>;
28
+ routr: z.ZodOptional<z.ZodString>;
29
+ billing: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strip>>;
31
+ }, z.core.$strip>>;
19
32
  costs: z.ZodPrefault<z.ZodObject<{
20
33
  display: z.ZodDefault<z.ZodEnum<{
21
34
  none: "none";
@@ -112,6 +125,19 @@ declare const fonosterConfigSchema: z.ZodObject<{
112
125
  enabled: z.ZodDefault<z.ZodBoolean>;
113
126
  address: z.ZodOptional<z.ZodString>;
114
127
  }, z.core.$strip>>;
128
+ ops: z.ZodPrefault<z.ZodObject<{
129
+ enabled: z.ZodDefault<z.ZodBoolean>;
130
+ secret: z.ZodOptional<z.ZodString>;
131
+ interop: z.ZodPrefault<z.ZodObject<{
132
+ intervalMinutes: z.ZodDefault<z.ZodNumber>;
133
+ }, z.core.$strip>>;
134
+ databases: z.ZodPrefault<z.ZodObject<{
135
+ fonoster: z.ZodOptional<z.ZodString>;
136
+ identity: z.ZodOptional<z.ZodString>;
137
+ routr: z.ZodOptional<z.ZodString>;
138
+ billing: z.ZodOptional<z.ZodString>;
139
+ }, z.core.$strip>>;
140
+ }, z.core.$strip>>;
115
141
  costs: z.ZodPrefault<z.ZodObject<{
116
142
  display: z.ZodDefault<z.ZodEnum<{
117
143
  none: "none";
@@ -33,6 +33,28 @@ const featuresSchema = zod_1.z
33
33
  address: zod_1.z.string().min(1).optional()
34
34
  })
35
35
  .prefault({}),
36
+ /** Fonoster's own ops API (mods/ops): off by default, not for self-hosters. */
37
+ ops: zod_1.z
38
+ .object({
39
+ enabled: zod_1.z.boolean().default(false),
40
+ /** The bearer of /api/ops; required when enabled: s + openssl rand -hex 16. */
41
+ secret: zod_1.z.string().optional(),
42
+ interop: zod_1.z
43
+ .object({
44
+ intervalMinutes: zod_1.z.number().int().positive().default(5)
45
+ })
46
+ .prefault({}),
47
+ /** Read-only database URLs; all required when enabled. */
48
+ databases: zod_1.z
49
+ .object({
50
+ fonoster: zod_1.z.string().min(1).optional(),
51
+ identity: zod_1.z.string().min(1).optional(),
52
+ routr: zod_1.z.string().min(1).optional(),
53
+ billing: zod_1.z.string().min(1).optional()
54
+ })
55
+ .prefault({})
56
+ })
57
+ .prefault({}),
36
58
  costs: zod_1.z
37
59
  .object({ display: zod_1.z.enum(["none", "usage", "prices"]).default("usage") })
38
60
  .prefault({}),
@@ -293,7 +315,7 @@ const fonosterConfigSchema = zod_1.z
293
315
  regions: regionsSchema
294
316
  })
295
317
  .superRefine((config, ctx) => {
296
- var _a, _b;
318
+ var _a, _b, _c;
297
319
  if (config.authz.enabled && !config.authz.host) {
298
320
  ctx.addIssue({
299
321
  code: "custom",
@@ -308,8 +330,25 @@ const fonosterConfigSchema = zod_1.z
308
330
  message: "required when features.billing.enabled is true"
309
331
  });
310
332
  }
333
+ const { ops } = config.features;
334
+ if (ops.enabled) {
335
+ if (!/^s[0-9a-f]{32}$/.test((_a = ops.secret) !== null && _a !== void 0 ? _a : "")) {
336
+ ctx.addIssue({
337
+ code: "custom",
338
+ path: ["features", "ops", "secret"],
339
+ message: "required when features.ops.enabled is true: s followed by 32 lowercase hex digits"
340
+ });
341
+ }
342
+ ["fonoster", "identity", "routr", "billing"]
343
+ .filter((key) => !ops.databases[key])
344
+ .forEach((key) => ctx.addIssue({
345
+ code: "custom",
346
+ path: ["features", "ops", "databases", key],
347
+ message: "required when features.ops.enabled is true"
348
+ }));
349
+ }
311
350
  if (config.features.auth.methods.includes("github") &&
312
- !((_a = config.identity.oauth2) === null || _a === void 0 ? void 0 : _a.github)) {
351
+ !((_b = config.identity.oauth2) === null || _b === void 0 ? void 0 : _b.github)) {
313
352
  ctx.addIssue({
314
353
  code: "custom",
315
354
  path: ["identity", "oauth2", "github"],
@@ -318,7 +357,7 @@ const fonosterConfigSchema = zod_1.z
318
357
  }
319
358
  // PR-17: the default public region's id is always `default`.
320
359
  const publicRegions = config.regions.public;
321
- const dflt = (_b = publicRegions.find((r) => r.default)) !== null && _b !== void 0 ? _b : publicRegions[0];
360
+ const dflt = (_c = publicRegions.find((r) => r.default)) !== null && _c !== void 0 ? _c : publicRegions[0];
322
361
  if (dflt && dflt.id !== "default") {
323
362
  ctx.addIssue({
324
363
  code: "custom",
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import type { FonosterConfig } from "../config/schema";
20
+ import type { Router } from "express";
21
+ /**
22
+ * Fonoster's own ops API, under `features.ops`. @fonoster/ops is private and only a devDependency
23
+ * here: it is imported only when on, or the published @fonoster/apiserver would crash at start.
24
+ */
25
+ export declare function loadOps(config: FonosterConfig["features"]["ops"]): Promise<{
26
+ routers: {
27
+ path: string;
28
+ router: Router;
29
+ }[];
30
+ start(): void;
31
+ }>;
@@ -0,0 +1,70 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.loadOps = loadOps;
46
+ /**
47
+ * Fonoster's own ops API, under `features.ops`. @fonoster/ops is private and only a devDependency
48
+ * here: it is imported only when on, or the published @fonoster/apiserver would crash at start.
49
+ */
50
+ function loadOps(config) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ if (!config.enabled)
53
+ return { routers: [], start() { } };
54
+ const { createOps } = yield Promise.resolve().then(() => __importStar(require("@fonoster/ops")));
55
+ const ops = createOps({
56
+ secret: config.secret,
57
+ intervalMinutes: config.interop.intervalMinutes,
58
+ databases: {
59
+ fonoster: config.databases.fonoster,
60
+ identity: config.databases.identity,
61
+ routr: config.databases.routr,
62
+ billing: config.databases.billing
63
+ }
64
+ });
65
+ return {
66
+ routers: [{ path: "/api/ops", router: ops.router }],
67
+ start: ops.start
68
+ };
69
+ });
70
+ }
@@ -85,6 +85,7 @@ const allowList_1 = require("./allowList");
85
85
  const db_1 = require("./db");
86
86
  const httpBridge_1 = require("./httpBridge");
87
87
  const identityConfig_1 = require("./identityConfig");
88
+ const loadOps_1 = require("./loadOps");
88
89
  const loadServices_1 = __importDefault(require("./loadServices"));
89
90
  const regionHooks_1 = require("./regionHooks");
90
91
  const routrConfig_1 = require("./routrConfig");
@@ -158,10 +159,13 @@ function runServices() {
158
159
  secureCookie: envs_1.APP_URL.startsWith("https:")
159
160
  })
160
161
  };
162
+ const ops = yield (0, loadOps_1.loadOps)((0, config_1.getConfig)().features.ops);
161
163
  (0, httpBridge_1.httpBridge)(identityConfig_1.identityConfig, {
162
164
  port: envs_1.HTTP_BRIDGE_PORT,
163
- routers: [...records.routers, ...regions.routers, session]
165
+ routers: [...ops.routers, ...records.routers, ...regions.routers, session]
164
166
  });
167
+ // Not awaited: a first scan over every retained trace can't delay gRPC or the healthcheck.
168
+ ops.start();
165
169
  // Bus consumers: webhook fan-out (LO-B1) and the AppBridge replicas' catalog use (LO-B11)
166
170
  const bus = yield (0, nats_1.connect)(Object.assign(Object.assign({}, envs_1.NATS), { maxReconnectAttempts: -1 }));
167
171
  (0, providers_1.subscribeRegistryUsage)(bus, db_1.prisma);
@@ -3,9 +3,9 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
3
3
  extended: {
4
4
  accessKeyId: string;
5
5
  };
6
+ secret: string;
6
7
  accessKeyId: string;
7
8
  name: string;
8
- secret: string;
9
9
  ref: string;
10
10
  createdAt: Date;
11
11
  updatedAt: Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -23,14 +23,14 @@
23
23
  "fonoster-owner": "./dist/bin/owner.js"
24
24
  },
25
25
  "dependencies": {
26
- "@fonoster/authz": "^0.49.0",
27
- "@fonoster/autopilot": "^0.49.0",
28
- "@fonoster/callrecord": "^0.49.0",
29
- "@fonoster/common": "^0.49.0",
30
- "@fonoster/identity": "^0.49.0",
31
- "@fonoster/logger": "^0.49.0",
32
- "@fonoster/sipnet": "^0.49.0",
33
- "@fonoster/types": "^0.49.0",
26
+ "@fonoster/authz": "^0.50.0",
27
+ "@fonoster/autopilot": "^0.50.0",
28
+ "@fonoster/callrecord": "^0.50.0",
29
+ "@fonoster/common": "^0.50.0",
30
+ "@fonoster/identity": "^0.50.0",
31
+ "@fonoster/logger": "^0.50.0",
32
+ "@fonoster/sipnet": "^0.50.0",
33
+ "@fonoster/types": "^0.50.0",
34
34
  "@grpc/grpc-js": "~1.14.6",
35
35
  "@prisma/client": "^6.19.1",
36
36
  "@routr/common": "^2.24.0",
@@ -62,12 +62,13 @@
62
62
  "url": "https://github.com/fonoster/fonoster/issues"
63
63
  },
64
64
  "devDependencies": {
65
+ "@fonoster/ops": "^0.50.0",
65
66
  "@types/express": "^5.0.6",
66
67
  "@types/jsonwebtoken": "^9.0.10",
67
68
  "@types/uuid": "^10.0.0",
68
69
  "@types/validator": "^13.15.10"
69
70
  },
70
- "gitHead": "0be7f93e5ed55175a8d50c72d09ebecbb264ebc7",
71
+ "gitHead": "75d5debf2e3a113cc2275312a17cadaf7986a73a",
71
72
  "prisma": {
72
73
  "seed": "tsx src/core/seed.ts"
73
74
  }