@fonoster/apiserver 0.55.0 → 0.57.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.
- package/dist/billing/createCloseAccount.d.ts +6 -0
- package/dist/billing/createCloseAccount.js +73 -0
- package/dist/core/routrConfig.d.ts +7 -2
- package/dist/core/routrConfig.js +9 -2
- package/dist/core/runServices.js +12 -0
- package/dist/core/services.d.ts +1 -1
- package/dist/core/services.js +4 -1
- package/dist/records/createWorkspaceSipResources.d.ts +23 -0
- package/dist/records/createWorkspaceSipResources.js +53 -0
- package/dist/records/index.d.ts +1 -0
- package/dist/records/index.js +1 -0
- package/dist/records/maintenance.d.ts +14 -1
- package/dist/records/maintenance.js +108 -1
- package/dist/records/runCallRecords.d.ts +10 -4
- package/dist/records/runCallRecords.js +11 -3
- package/dist/records/types.d.ts +32 -0
- package/dist/regions/service.js +3 -1
- package/dist/regions/types.d.ts +11 -0
- package/dist/regions/types.js +3 -2
- package/dist/regions/withConfigChangeHook.js +1 -1
- package/dist/secrets/access.d.ts +16 -0
- package/dist/secrets/access.js +56 -0
- package/dist/secrets/deleteSecret.js +4 -0
- package/dist/secrets/getSecret.js +6 -1
- package/dist/secrets/listSecrets.js +6 -2
- package/dist/secrets/updateSecret.js +6 -5
- package/dist/workspaces/workspaceDeleted.d.ts +10 -0
- package/dist/workspaces/workspaceDeleted.js +61 -0
- package/package.json +11 -11
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing's CloseAccount for Identity's DeleteUser (Fonoster Cloud, #1376). Internal: the apiserver
|
|
3
|
+
* never serves it. Rejects with `{ code, message }`, the gRPC status and billing's message.
|
|
4
|
+
*/
|
|
5
|
+
declare function createCloseAccount(address: string): (ownerRef: string) => Promise<void>;
|
|
6
|
+
export { createCloseAccount };
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createCloseAccount = createCloseAccount;
|
|
37
|
+
/**
|
|
38
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
39
|
+
* http://github.com/fonoster/fonoster
|
|
40
|
+
*
|
|
41
|
+
* This file is part of Fonoster
|
|
42
|
+
*
|
|
43
|
+
* Licensed under the MIT License (the "License");
|
|
44
|
+
* you may not use this file except in compliance with
|
|
45
|
+
* the License. You may obtain a copy of the License at
|
|
46
|
+
*
|
|
47
|
+
* https://opensource.org/licenses/MIT
|
|
48
|
+
*
|
|
49
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
50
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
51
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
52
|
+
* See the License for the specific language governing permissions and
|
|
53
|
+
* limitations under the License.
|
|
54
|
+
*/
|
|
55
|
+
const common_1 = require("@fonoster/common");
|
|
56
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
57
|
+
/** How long Identity's DeleteUser waits for billing before refusing (#1376). */
|
|
58
|
+
const DEADLINE_MS = 10000;
|
|
59
|
+
/**
|
|
60
|
+
* Billing's CloseAccount for Identity's DeleteUser (Fonoster Cloud, #1376). Internal: the apiserver
|
|
61
|
+
* never serves it. Rejects with `{ code, message }`, the gRPC status and billing's message.
|
|
62
|
+
*/
|
|
63
|
+
function createCloseAccount(address) {
|
|
64
|
+
const client = new (grpc.makeGenericClientConstructor((0, common_1.createServiceDefinition)({
|
|
65
|
+
serviceName: "Billing",
|
|
66
|
+
pckg: "billing",
|
|
67
|
+
proto: "billing.proto",
|
|
68
|
+
version: "v1beta2"
|
|
69
|
+
}), "Billing", {}))(address, grpc.credentials.createInsecure());
|
|
70
|
+
return (ownerRef) => new Promise((resolve, reject) => client.closeAccount({ ownerRef }, { deadline: Date.now() + DEADLINE_MS }, (error) => error
|
|
71
|
+
? reject({ code: error.code, message: error.details })
|
|
72
|
+
: resolve()));
|
|
73
|
+
}
|
|
@@ -2,6 +2,11 @@ declare const routrConfig: {
|
|
|
2
2
|
endpoint: string;
|
|
3
3
|
insecure: boolean;
|
|
4
4
|
};
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The apiserver's one client for Routr's Numbers (CreateCall's check, the records' trunks, a
|
|
7
|
+
* deleted workspace's numbers).
|
|
8
|
+
*/
|
|
6
9
|
declare const routrNumbers: () => import("@routr/sdk/dist/numbers").default;
|
|
7
|
-
|
|
10
|
+
/** The apiserver's one client for Routr's Trunks (a deleted workspace's trunks). */
|
|
11
|
+
declare const routrTrunks: () => import("@routr/sdk/dist/trunks").default;
|
|
12
|
+
export { routrConfig, routrNumbers, routrTrunks };
|
package/dist/core/routrConfig.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.routrNumbers = exports.routrConfig = void 0;
|
|
6
|
+
exports.routrTrunks = exports.routrNumbers = exports.routrConfig = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
9
9
|
* http://github.com/fonoster/fonoster
|
|
@@ -30,6 +30,13 @@ const routrConfig = {
|
|
|
30
30
|
};
|
|
31
31
|
exports.routrConfig = routrConfig;
|
|
32
32
|
let numbers;
|
|
33
|
-
|
|
33
|
+
let trunks;
|
|
34
|
+
/**
|
|
35
|
+
* The apiserver's one client for Routr's Numbers (CreateCall's check, the records' trunks, a
|
|
36
|
+
* deleted workspace's numbers).
|
|
37
|
+
*/
|
|
34
38
|
const routrNumbers = () => (numbers !== null && numbers !== void 0 ? numbers : (numbers = new sdk_1.default.Numbers(routrConfig)));
|
|
35
39
|
exports.routrNumbers = routrNumbers;
|
|
40
|
+
/** The apiserver's one client for Routr's Trunks (a deleted workspace's trunks). */
|
|
41
|
+
const routrTrunks = () => (trunks !== null && trunks !== void 0 ? trunks : (trunks = new sdk_1.default.Trunks(routrConfig)));
|
|
42
|
+
exports.routrTrunks = routrTrunks;
|
package/dist/core/runServices.js
CHANGED
|
@@ -81,6 +81,7 @@ const publishUsage_1 = require("../usage/publishUsage");
|
|
|
81
81
|
const runUsageConsumer_1 = require("../usage/runUsageConsumer");
|
|
82
82
|
const snapshotStorage_1 = require("../usage/snapshotStorage");
|
|
83
83
|
const runWebhookFanout_1 = require("../webhooks/runWebhookFanout");
|
|
84
|
+
const workspaceDeleted_1 = require("../workspaces/workspaceDeleted");
|
|
84
85
|
const allowList_1 = require("./allowList");
|
|
85
86
|
const db_1 = require("./db");
|
|
86
87
|
const httpBridge_1 = require("./httpBridge");
|
|
@@ -149,6 +150,15 @@ function runServices() {
|
|
|
149
150
|
relay: { regionOf: regions.regionOf, client: regions.relay },
|
|
150
151
|
onConfigChange: regions.onConfigChange,
|
|
151
152
|
usage: { directory: () => regionHooks_1.workspaceRegionHooks.directory() },
|
|
153
|
+
// Never service.directory: its empty stand-in answers "no workspace" for every key.
|
|
154
|
+
workspaces: () => regionHooks_1.workspaceRegionHooks.directory(),
|
|
155
|
+
// A deleted workspace's numbers and trunks: listed through sipnet's handlers, which filter
|
|
156
|
+
// by workspace, and deleted on Routr itself (the gRPC delete handlers need a caller's token).
|
|
157
|
+
sip: (0, records_1.createWorkspaceSipResources)({
|
|
158
|
+
handlers,
|
|
159
|
+
numbers: (0, routrConfig_1.routrNumbers)(),
|
|
160
|
+
trunks: (0, routrConfig_1.routrTrunks)()
|
|
161
|
+
}),
|
|
152
162
|
trunkOf: (0, records_1.createTrunkOfNumber)((0, routrConfig_1.routrNumbers)())
|
|
153
163
|
});
|
|
154
164
|
// The dashboard's cookie session (M4): refresh token in an httpOnly cookie on its origin
|
|
@@ -169,6 +179,8 @@ function runServices() {
|
|
|
169
179
|
// Bus consumers: webhook fan-out (LO-B1) and the AppBridge replicas' catalog use (LO-B11)
|
|
170
180
|
const bus = yield (0, nats_1.connect)(Object.assign(Object.assign({}, envs_1.NATS), { maxReconnectAttempts: -1 }));
|
|
171
181
|
(0, providers_1.subscribeRegistryUsage)(bus, db_1.prisma);
|
|
182
|
+
// AppBridge asks whether an inbound call's workspace was deleted (#1318).
|
|
183
|
+
(0, workspaceDeleted_1.subscribeWorkspaceDeleted)(bus, () => regionHooks_1.workspaceRegionHooks.directory());
|
|
172
184
|
(0, publishUsage_1.attachUsagePublisher)(bus);
|
|
173
185
|
yield (0, runUsageConsumer_1.runUsageConsumer)({
|
|
174
186
|
nc: bus,
|
package/dist/core/services.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ declare const services: Promise<[{
|
|
|
143
143
|
listApiKeys: (call: {
|
|
144
144
|
request: unknown;
|
|
145
145
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
146
|
-
|
|
146
|
+
rotateApiKey: (call: {
|
|
147
147
|
request: unknown;
|
|
148
148
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
149
149
|
exchangeApiKey: (call: {
|
package/dist/core/services.js
CHANGED
|
@@ -31,6 +31,7 @@ const identity_1 = require("@fonoster/identity");
|
|
|
31
31
|
const sipnet_1 = require("@fonoster/sipnet");
|
|
32
32
|
const applications_1 = require("../applications");
|
|
33
33
|
const buildService_1 = require("../billing/buildService");
|
|
34
|
+
const createCloseAccount_1 = require("../billing/createCloseAccount");
|
|
34
35
|
const calls_1 = require("../calls");
|
|
35
36
|
const capabilities_1 = require("../capabilities");
|
|
36
37
|
const config_1 = require("../config");
|
|
@@ -56,7 +57,9 @@ const applicationsService = (0, applications_1.buildApplicationsService)(db_1.pr
|
|
|
56
57
|
}));
|
|
57
58
|
const secretsService = (0, secrets_1.buildSecretsService)(db_1.prisma);
|
|
58
59
|
const callsService = (0, calls_1.buildCallsService)();
|
|
59
|
-
const identityService = (0, identity_1.buildIdentityService)(Object.assign(Object.assign({}, identityConfig_1.identityConfig), { regions: regionHooks_1.workspaceRegionHooks })
|
|
60
|
+
const identityService = (0, identity_1.buildIdentityService)(Object.assign(Object.assign(Object.assign({}, identityConfig_1.identityConfig), { regions: regionHooks_1.workspaceRegionHooks }), (envs_1.BILLING_ENABLED
|
|
61
|
+
? { billing: { closeAccount: (0, createCloseAccount_1.createCloseAccount)(envs_1.BILLING_ADDRESS) } }
|
|
62
|
+
: {})));
|
|
60
63
|
const agentsService = (0, sipnet_1.buildAgentsService)(routrConfig_1.routrConfig);
|
|
61
64
|
const domainsService = (0, sipnet_1.buildDomainsService)(routrConfig_1.routrConfig, {
|
|
62
65
|
namesRoot: envs_1.DOMAIN_NAMES_ROOT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { listAll } from "../regions/sources";
|
|
2
|
+
import { WorkspaceSipResources } from "./types";
|
|
3
|
+
type ListHandler = Parameters<typeof listAll>[0];
|
|
4
|
+
/**
|
|
5
|
+
* A deleted workspace's numbers and trunks, for `runWorkspaceErasure` (#1321). They are listed
|
|
6
|
+
* through the sipnet list handlers, which keep only the items whose `extended.accessKeyId` is the
|
|
7
|
+
* workspace's, so another workspace's resource is never deleted. They are deleted with the Routr
|
|
8
|
+
* SDK, because the gRPC delete handlers need a caller in the workspace and a deleted one has none.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createWorkspaceSipResources(deps: {
|
|
11
|
+
/** The loaded services' handlers, by method name. */
|
|
12
|
+
handlers: {
|
|
13
|
+
listNumbers?: ListHandler;
|
|
14
|
+
listTrunks?: ListHandler;
|
|
15
|
+
};
|
|
16
|
+
numbers: {
|
|
17
|
+
deleteNumber(ref: string): Promise<unknown>;
|
|
18
|
+
};
|
|
19
|
+
trunks: {
|
|
20
|
+
deleteTrunk(ref: string): Promise<unknown>;
|
|
21
|
+
};
|
|
22
|
+
}): WorkspaceSipResources;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createWorkspaceSipResources = createWorkspaceSipResources;
|
|
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 grpc_js_1 = require("@grpc/grpc-js");
|
|
32
|
+
const sources_1 = require("../regions/sources");
|
|
33
|
+
const refs = (items) => items.map((item) => item.ref);
|
|
34
|
+
/** Routr no longer has it (an earlier run, or one of Routr's own cascades): that is deleted. */
|
|
35
|
+
const unlessGone = (e) => {
|
|
36
|
+
if ((e === null || e === void 0 ? void 0 : e.code) !== grpc_js_1.status.NOT_FOUND)
|
|
37
|
+
throw e;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A deleted workspace's numbers and trunks, for `runWorkspaceErasure` (#1321). They are listed
|
|
41
|
+
* through the sipnet list handlers, which keep only the items whose `extended.accessKeyId` is the
|
|
42
|
+
* workspace's, so another workspace's resource is never deleted. They are deleted with the Routr
|
|
43
|
+
* SDK, because the gRPC delete handlers need a caller in the workspace and a deleted one has none.
|
|
44
|
+
*/
|
|
45
|
+
function createWorkspaceSipResources(deps) {
|
|
46
|
+
const { handlers, numbers, trunks } = deps;
|
|
47
|
+
return {
|
|
48
|
+
numbers: (accessKeyId) => __awaiter(this, void 0, void 0, function* () { return refs(yield (0, sources_1.listAll)(handlers.listNumbers, accessKeyId)); }),
|
|
49
|
+
trunks: (accessKeyId) => __awaiter(this, void 0, void 0, function* () { return refs(yield (0, sources_1.listAll)(handlers.listTrunks, accessKeyId)); }),
|
|
50
|
+
deleteNumber: (ref) => numbers.deleteNumber(ref).then(() => undefined, unlessGone),
|
|
51
|
+
deleteTrunk: (ref) => trunks.deleteTrunk(ref).then(() => undefined, unlessGone)
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/records/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from "./createIndexRecord";
|
|
|
20
20
|
export * from "./createRecordsRouter";
|
|
21
21
|
export * from "./createSearchRecords";
|
|
22
22
|
export * from "./createTrunkOfNumber";
|
|
23
|
+
export * from "./createWorkspaceSipResources";
|
|
23
24
|
export * from "./maintenance";
|
|
24
25
|
export * from "./runCallRecords";
|
|
25
26
|
export * from "./stores";
|
package/dist/records/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __exportStar(require("./createIndexRecord"), exports);
|
|
|
36
36
|
__exportStar(require("./createRecordsRouter"), exports);
|
|
37
37
|
__exportStar(require("./createSearchRecords"), exports);
|
|
38
38
|
__exportStar(require("./createTrunkOfNumber"), exports);
|
|
39
|
+
__exportStar(require("./createWorkspaceSipResources"), exports);
|
|
39
40
|
__exportStar(require("./maintenance"), exports);
|
|
40
41
|
__exportStar(require("./runCallRecords"), exports);
|
|
41
42
|
__exportStar(require("./stores"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NatsConnection } from "nats";
|
|
2
|
-
import {
|
|
2
|
+
import { WorkspaceDirectory } from "../regions/types";
|
|
3
|
+
import { AuditEntry, MaintenanceClient, RecordsDb, WorkspaceErasureDb, WorkspaceSipResources } from "./types";
|
|
3
4
|
/**
|
|
4
5
|
* Retention and erasure run in the record's region (it holds the files and the signing key);
|
|
5
6
|
* the control plane asks over NATS (`callrecord.<region>.maintenance`, served by the AppBridge replicas).
|
|
@@ -31,3 +32,15 @@ export declare function runRetention(db: RecordsDb, maintenance: MaintenanceClie
|
|
|
31
32
|
callRef: string;
|
|
32
33
|
part: string;
|
|
33
34
|
}[]>;
|
|
35
|
+
/** Days a deleted workspace's call records are kept before they are erased (#1318). */
|
|
36
|
+
export declare const WORKSPACE_ERASURE_GRACE_DAYS = 30;
|
|
37
|
+
/**
|
|
38
|
+
* Acts on Identity's deletion records. First, for every deleted workspace and with no grace, it
|
|
39
|
+
* deletes the workspace's applications, secrets, webhooks, numbers and trunks (#1321). Then it
|
|
40
|
+
* erases the call records of workspaces deleted more than 30 days ago (#1318). Only a deletion
|
|
41
|
+
* record starts either, never a workspace merely missing from the directory, and a workspace
|
|
42
|
+
* whose key exists again (an operator restore) keeps everything. Records in a private region
|
|
43
|
+
* stay. A workspace or a record that fails is retried on the next run; a failing directory ends
|
|
44
|
+
* the run.
|
|
45
|
+
*/
|
|
46
|
+
export declare function runWorkspaceErasure(db: WorkspaceErasureDb, maintenance: MaintenanceClient, directory: WorkspaceDirectory | undefined, now: Date, sip: WorkspaceSipResources): Promise<string[]>;
|
|
@@ -9,11 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RecordMaintenanceError = void 0;
|
|
12
|
+
exports.WORKSPACE_ERASURE_GRACE_DAYS = exports.RecordMaintenanceError = void 0;
|
|
13
13
|
exports.natsMaintenanceClient = natsMaintenanceClient;
|
|
14
14
|
exports.writeAudit = writeAudit;
|
|
15
15
|
exports.createRecordMaintenance = createRecordMaintenance;
|
|
16
16
|
exports.runRetention = runRetention;
|
|
17
|
+
exports.runWorkspaceErasure = runWorkspaceErasure;
|
|
17
18
|
/**
|
|
18
19
|
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
19
20
|
* http://github.com/fonoster/fonoster
|
|
@@ -35,6 +36,7 @@ exports.runRetention = runRetention;
|
|
|
35
36
|
const callrecord_1 = require("@fonoster/callrecord");
|
|
36
37
|
const logger_1 = require("@fonoster/logger");
|
|
37
38
|
const nats_1 = require("nats");
|
|
39
|
+
const types_1 = require("../regions/types");
|
|
38
40
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
39
41
|
const sc = (0, nats_1.StringCodec)();
|
|
40
42
|
/**
|
|
@@ -164,3 +166,108 @@ function runRetention(db_1, maintenance_1) {
|
|
|
164
166
|
return done;
|
|
165
167
|
});
|
|
166
168
|
}
|
|
169
|
+
/** Days a deleted workspace's call records are kept before they are erased (#1318). */
|
|
170
|
+
exports.WORKSPACE_ERASURE_GRACE_DAYS = 30;
|
|
171
|
+
/**
|
|
172
|
+
* Deletes what a deleted workspace left outside its call records (#1321): its applications (their
|
|
173
|
+
* vendor credentials cascade), webhook endpoints and deliveries, and secrets (its provider keys
|
|
174
|
+
* cascade) in this database, then its numbers and its trunks in Routr. In that order, stopping at
|
|
175
|
+
* the first failure, so its secrets never go while an application remains, nor its trunks before
|
|
176
|
+
* its numbers. Every delete is safe to repeat: the next run finishes what this one couldn't.
|
|
177
|
+
*/
|
|
178
|
+
function deleteWorkspaceData(db, sip, accessKeyId) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
try {
|
|
181
|
+
const where = { accessKeyId };
|
|
182
|
+
const applications = yield db.application.deleteMany({ where });
|
|
183
|
+
const webhookEndpoints = yield db.webhookEndpoint.deleteMany({ where });
|
|
184
|
+
const webhookDeliveries = yield db.webhookDelivery.deleteMany({ where });
|
|
185
|
+
const secrets = yield db.secret.deleteMany({ where });
|
|
186
|
+
const numbers = yield sip.numbers(accessKeyId);
|
|
187
|
+
for (const ref of numbers)
|
|
188
|
+
yield sip.deleteNumber(ref);
|
|
189
|
+
const trunks = yield sip.trunks(accessKeyId);
|
|
190
|
+
for (const ref of trunks)
|
|
191
|
+
yield sip.deleteTrunk(ref);
|
|
192
|
+
const removed = {
|
|
193
|
+
applications: applications.count,
|
|
194
|
+
webhookEndpoints: webhookEndpoints.count,
|
|
195
|
+
webhookDeliveries: webhookDeliveries.count,
|
|
196
|
+
secrets: secrets.count,
|
|
197
|
+
numbers: numbers.length,
|
|
198
|
+
trunks: trunks.length
|
|
199
|
+
};
|
|
200
|
+
// Every run comes back here for every deleted workspace; most find nothing left.
|
|
201
|
+
if (Object.values(removed).some((count) => count > 0))
|
|
202
|
+
logger.info(`deleted the data of deleted workspace ${accessKeyId}`, {
|
|
203
|
+
removed
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
logger.warn(`deleting the data of deleted workspace ${accessKeyId} failed: ${e.message}`);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Acts on Identity's deletion records. First, for every deleted workspace and with no grace, it
|
|
213
|
+
* deletes the workspace's applications, secrets, webhooks, numbers and trunks (#1321). Then it
|
|
214
|
+
* erases the call records of workspaces deleted more than 30 days ago (#1318). Only a deletion
|
|
215
|
+
* record starts either, never a workspace merely missing from the directory, and a workspace
|
|
216
|
+
* whose key exists again (an operator restore) keeps everything. Records in a private region
|
|
217
|
+
* stay. A workspace or a record that fails is retried on the next run; a failing directory ends
|
|
218
|
+
* the run.
|
|
219
|
+
*/
|
|
220
|
+
function runWorkspaceErasure(db_1, maintenance_1, directory_1) {
|
|
221
|
+
return __awaiter(this, arguments, void 0, function* (db, maintenance, directory, now = new Date(), sip) {
|
|
222
|
+
const done = [];
|
|
223
|
+
if (!directory)
|
|
224
|
+
return done;
|
|
225
|
+
const maintain = createRecordMaintenance(db, maintenance);
|
|
226
|
+
const cutoff = now.getTime() - exports.WORKSPACE_ERASURE_GRACE_DAYS * 24 * 3600 * 1000;
|
|
227
|
+
try {
|
|
228
|
+
const deletions = yield directory.deleted();
|
|
229
|
+
// Before any record: a slow or failing region below can't hold these deletes back.
|
|
230
|
+
for (const { accessKeyId } of deletions) {
|
|
231
|
+
if (yield directory.workspace(accessKeyId))
|
|
232
|
+
continue;
|
|
233
|
+
yield deleteWorkspaceData(db, sip, accessKeyId);
|
|
234
|
+
}
|
|
235
|
+
for (const { accessKeyId, deletedAt } of deletions) {
|
|
236
|
+
if (deletedAt.getTime() >= cutoff)
|
|
237
|
+
continue;
|
|
238
|
+
// Right before its records: the workspace may have been recreated with the same key.
|
|
239
|
+
if (yield directory.workspace(accessKeyId))
|
|
240
|
+
continue;
|
|
241
|
+
const rows = yield db.callRecord.findMany({
|
|
242
|
+
where: {
|
|
243
|
+
accessKeyId,
|
|
244
|
+
erasedAt: null,
|
|
245
|
+
NOT: { region: { startsWith: types_1.PRIVATE_REGION_PREFIX } }
|
|
246
|
+
},
|
|
247
|
+
take: 500
|
|
248
|
+
});
|
|
249
|
+
for (const row of rows) {
|
|
250
|
+
try {
|
|
251
|
+
yield maintain({
|
|
252
|
+
op: "erase",
|
|
253
|
+
callRef: row.callRef,
|
|
254
|
+
accessKeyId,
|
|
255
|
+
reason: "workspace deleted",
|
|
256
|
+
actor: "system:workspace-deleted"
|
|
257
|
+
});
|
|
258
|
+
done.push(row.callRef);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
if (e.code === "gone")
|
|
262
|
+
continue;
|
|
263
|
+
logger.warn(`erasing ${row.callRef} of deleted workspace ${accessKeyId} failed: ${e.message}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
logger.warn(`workspace erasure stopped: could not read Identity's workspaces: ${e.message}`);
|
|
270
|
+
}
|
|
271
|
+
return done;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
import { ObjectStoreConfig } from "@fonoster/callrecord";
|
|
20
20
|
import { NatsTarget } from "@fonoster/common";
|
|
21
21
|
import { Router } from "express";
|
|
22
|
+
import { WorkspaceDirectory } from "../regions/types";
|
|
22
23
|
import { IndexUsageDeps } from "./createIndexRecord";
|
|
23
24
|
import { RecordsRouterDeps } from "./createRecordsRouter";
|
|
24
25
|
import { TrunkOfNumber } from "./createTrunkOfNumber";
|
|
25
|
-
import {
|
|
26
|
+
import { WorkspaceErasureDb, WorkspaceSipResources } from "./types";
|
|
26
27
|
export type CallRecordsConfig = {
|
|
27
28
|
enabled: boolean;
|
|
28
29
|
stores: ObjectStoreConfig[];
|
|
@@ -30,19 +31,24 @@ export type CallRecordsConfig = {
|
|
|
30
31
|
maintenanceTimeoutMs: number;
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
33
|
-
* Starts the control plane's side of call records: the index consumer, the retention job
|
|
34
|
-
* records API router (mounted on the HTTP
|
|
34
|
+
* Starts the control plane's side of call records: the index consumer, the retention job (with the
|
|
35
|
+
* erasure of deleted workspaces' data and records) and the records API router (mounted on the HTTP
|
|
36
|
+
* bridge at /api/records).
|
|
35
37
|
*/
|
|
36
38
|
export declare function runCallRecords(config: CallRecordsConfig, deps: {
|
|
37
39
|
natsUrl: NatsTarget;
|
|
38
40
|
identityPublicKey: string;
|
|
39
41
|
identityTokenOptions?: RecordsRouterDeps["identityTokenOptions"];
|
|
40
|
-
db:
|
|
42
|
+
db: WorkspaceErasureDb;
|
|
41
43
|
relay?: RecordsRouterDeps["relay"];
|
|
42
44
|
onConfigChange?: (accessKeyId: string) => void;
|
|
43
45
|
usage?: IndexUsageDeps;
|
|
44
46
|
/** Names the trunk of a call's Number when its record is indexed. */
|
|
45
47
|
trunkOf?: TrunkOfNumber;
|
|
48
|
+
/** Identity's workspaces once attached: deleted workspaces' records are erased (#1318). */
|
|
49
|
+
workspaces?: () => WorkspaceDirectory | undefined;
|
|
50
|
+
/** Routr's numbers and trunks: a deleted workspace's are deleted (#1321). */
|
|
51
|
+
sip: WorkspaceSipResources;
|
|
46
52
|
}): Promise<{
|
|
47
53
|
routers: {
|
|
48
54
|
path: string;
|
|
@@ -19,8 +19,9 @@ const maintenance_1 = require("./maintenance");
|
|
|
19
19
|
const stores_1 = require("./stores");
|
|
20
20
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
21
21
|
/**
|
|
22
|
-
* Starts the control plane's side of call records: the index consumer, the retention job
|
|
23
|
-
* records API router (mounted on the HTTP
|
|
22
|
+
* Starts the control plane's side of call records: the index consumer, the retention job (with the
|
|
23
|
+
* erasure of deleted workspaces' data and records) and the records API router (mounted on the HTTP
|
|
24
|
+
* bridge at /api/records).
|
|
24
25
|
*/
|
|
25
26
|
function runCallRecords(config, deps) {
|
|
26
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,7 +36,14 @@ function runCallRecords(config, deps) {
|
|
|
35
36
|
const retention = setInterval(() => void (0, maintenance_1.runRetention)(deps.db, maintenance)
|
|
36
37
|
.then((done) => done.length &&
|
|
37
38
|
logger.info(`retention deleted ${done.length} record parts`))
|
|
38
|
-
.catch((e) => logger.error(`retention failed: ${e.message}`))
|
|
39
|
+
.catch((e) => logger.error(`retention failed: ${e.message}`))
|
|
40
|
+
.then(() => {
|
|
41
|
+
var _a;
|
|
42
|
+
return (0, maintenance_1.runWorkspaceErasure)(deps.db, maintenance, (_a = deps.workspaces) === null || _a === void 0 ? void 0 : _a.call(deps), undefined, deps.sip);
|
|
43
|
+
})
|
|
44
|
+
.then((erased) => erased.length &&
|
|
45
|
+
logger.info(`erased ${erased.length} call records of deleted workspaces`))
|
|
46
|
+
.catch((e) => logger.error(`workspace erasure failed: ${e.message}`)), config.retentionIntervalMinutes * 60000);
|
|
39
47
|
retention.unref();
|
|
40
48
|
const router = (0, createRecordsRouter_1.createRecordsRouter)({
|
|
41
49
|
db: deps.db,
|
package/dist/records/types.d.ts
CHANGED
|
@@ -85,6 +85,38 @@ export interface RecordsDb {
|
|
|
85
85
|
deleteMany(args: Record<string, unknown>): Promise<unknown>;
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
+
type DeleteByWorkspace = {
|
|
89
|
+
deleteMany(args: {
|
|
90
|
+
where: {
|
|
91
|
+
accessKeyId: string;
|
|
92
|
+
};
|
|
93
|
+
}): Promise<{
|
|
94
|
+
count: number;
|
|
95
|
+
}>;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* What the erasure of deleted workspaces uses of the Prisma client (#1321): the records' slice,
|
|
99
|
+
* and the tables that hold a workspace's applications, secrets and webhooks.
|
|
100
|
+
*/
|
|
101
|
+
export type WorkspaceErasureDb = RecordsDb & {
|
|
102
|
+
/** Their tts_services, stt_services and intelligence_services rows cascade. */
|
|
103
|
+
application: DeleteByWorkspace;
|
|
104
|
+
/** Their workspace_provider_keys rows cascade. */
|
|
105
|
+
secret: DeleteByWorkspace;
|
|
106
|
+
webhookEndpoint: DeleteByWorkspace;
|
|
107
|
+
webhookDelivery: DeleteByWorkspace;
|
|
108
|
+
};
|
|
109
|
+
/** A workspace's numbers and trunks in Routr, for the erasure of deleted workspaces (#1321). */
|
|
110
|
+
export type WorkspaceSipResources = {
|
|
111
|
+
/** The refs of the numbers whose `extended.accessKeyId` is the workspace's. */
|
|
112
|
+
numbers(accessKeyId: string): Promise<string[]>;
|
|
113
|
+
/** The refs of the trunks whose `extended.accessKeyId` is the workspace's. */
|
|
114
|
+
trunks(accessKeyId: string): Promise<string[]>;
|
|
115
|
+
/** Resolves when the number is deleted, or was already gone. */
|
|
116
|
+
deleteNumber(ref: string): Promise<void>;
|
|
117
|
+
/** Resolves when the trunk is deleted, or was already gone. */
|
|
118
|
+
deleteTrunk(ref: string): Promise<void>;
|
|
119
|
+
};
|
|
88
120
|
/** Sends retention and erasure requests to the region that holds the record. */
|
|
89
121
|
export type MaintenanceClient = (region: string, request: {
|
|
90
122
|
op: "delete_parts" | "erase";
|
package/dist/regions/service.js
CHANGED
|
@@ -57,7 +57,9 @@ function newRegionRef() {
|
|
|
57
57
|
/** Directory used until Identity attaches the real one (no workspaces). */
|
|
58
58
|
const EMPTY_DIRECTORY = {
|
|
59
59
|
workspace: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
|
|
60
|
-
inRegion: () => __awaiter(void 0, void 0, void 0, function* () { return []; })
|
|
60
|
+
inRegion: () => __awaiter(void 0, void 0, void 0, function* () { return []; }),
|
|
61
|
+
deleted: () => __awaiter(void 0, void 0, void 0, function* () { return []; }),
|
|
62
|
+
isDeleted: () => __awaiter(void 0, void 0, void 0, function* () { return false; })
|
|
61
63
|
};
|
|
62
64
|
const isUniqueViolation = (e) => (e === null || e === void 0 ? void 0 : e.code) === "P2002" ||
|
|
63
65
|
/unique constraint/i.test(String(e === null || e === void 0 ? void 0 : e.message));
|
package/dist/regions/types.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare const REGION_AUDIENCE = "fonoster.region.v1";
|
|
|
22
22
|
export declare const PRIVATE_REGION = "private";
|
|
23
23
|
/** A private region ref: `rg_` + lowercase base32. */
|
|
24
24
|
export declare const REGION_REF: RegExp;
|
|
25
|
+
export declare const PRIVATE_REGION_PREFIX = "rg_";
|
|
25
26
|
export declare const isPrivateRegionRef: (region?: string | null) => boolean;
|
|
26
27
|
export declare const subjects: (ref: string) => {
|
|
27
28
|
all: string;
|
|
@@ -112,6 +113,16 @@ export type WorkspaceDirectory = {
|
|
|
112
113
|
workspace(accessKeyId: string): Promise<WorkspaceInfo | undefined>;
|
|
113
114
|
/** Workspaces whose `region` is this key (a public id or a private ref). */
|
|
114
115
|
inRegion(regionKey: string): Promise<WorkspaceInfo[]>;
|
|
116
|
+
/** Every deleted workspace with when it was deleted; rejects when Identity's database fails. */
|
|
117
|
+
deleted(): Promise<{
|
|
118
|
+
accessKeyId: string;
|
|
119
|
+
deletedAt: Date;
|
|
120
|
+
}[]>;
|
|
121
|
+
/**
|
|
122
|
+
* Whether a workspace was deleted: it has a deletion record and no workspace with its key exists
|
|
123
|
+
* again. Rejects when Identity's database fails.
|
|
124
|
+
*/
|
|
125
|
+
isDeleted(accessKeyId: string): Promise<boolean>;
|
|
115
126
|
};
|
|
116
127
|
/** The Prisma client, narrowed to what the regions code uses (tests pass a real one). */
|
|
117
128
|
export type RegionsDb = any;
|
package/dist/regions/types.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegionError = exports.regionKey = exports.subjects = exports.isPrivateRegionRef = exports.REGION_REF = exports.PRIVATE_REGION = exports.REGION_AUDIENCE = void 0;
|
|
3
|
+
exports.RegionError = exports.regionKey = exports.subjects = exports.isPrivateRegionRef = exports.PRIVATE_REGION_PREFIX = exports.REGION_REF = exports.PRIVATE_REGION = exports.REGION_AUDIENCE = void 0;
|
|
4
4
|
/** Wire names of the private region contract (openspec/changes/archive/2026-10-17-add-private-regions/contract.md). */
|
|
5
5
|
exports.REGION_AUDIENCE = "fonoster.region.v1";
|
|
6
6
|
exports.PRIVATE_REGION = "private";
|
|
7
7
|
/** A private region ref: `rg_` + lowercase base32. */
|
|
8
8
|
exports.REGION_REF = /^rg_[a-z2-7]{8,32}$/;
|
|
9
|
-
|
|
9
|
+
exports.PRIVATE_REGION_PREFIX = "rg_";
|
|
10
|
+
const isPrivateRegionRef = (region) => !!region && region.startsWith(exports.PRIVATE_REGION_PREFIX);
|
|
10
11
|
exports.isPrivateRegionRef = isPrivateRegionRef;
|
|
11
12
|
const subjects = (ref) => ({
|
|
12
13
|
all: `region.${ref}.>`,
|
|
@@ -13,7 +13,7 @@ exports.SYNCED_SERVICES = [
|
|
|
13
13
|
"Credentials",
|
|
14
14
|
"Webhooks"
|
|
15
15
|
];
|
|
16
|
-
const WRITE = /^(create|update|delete|rotate|
|
|
16
|
+
const WRITE = /^(create|update|delete|rotate|resend)/;
|
|
17
17
|
/**
|
|
18
18
|
* Wraps the write handlers of the synced services so a successful write marks the workspace's
|
|
19
19
|
* config changed (the config sync publishes a new version for private workspaces).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { status } from "@grpc/grpc-js";
|
|
2
|
+
declare const isVendorKey: (name?: string | null) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* True when the call is made with an API key's token. API keys get access key ids starting with
|
|
5
|
+
* "AP"; people signed in get "US".
|
|
6
|
+
*/
|
|
7
|
+
declare function isApiKeyCall(call: unknown): boolean;
|
|
8
|
+
/** A Secret as anyone but an API key reading an app secret sees it: no value. */
|
|
9
|
+
declare function withoutValue<T extends {
|
|
10
|
+
secret?: unknown;
|
|
11
|
+
}>(secret: T): T;
|
|
12
|
+
declare const vendorKeyError: () => {
|
|
13
|
+
code: status;
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
export { isApiKeyCall, isVendorKey, vendorKeyError, withoutValue };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vendorKeyError = exports.isVendorKey = void 0;
|
|
4
|
+
exports.isApiKeyCall = isApiKeyCall;
|
|
5
|
+
exports.withoutValue = withoutValue;
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Fonoster
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
const common_1 = require("@fonoster/common");
|
|
25
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
26
|
+
const createProvidersHandlers_1 = require("../providers/createProvidersHandlers");
|
|
27
|
+
/** Secrets whose name starts with this are vendor keys, managed through the Providers API. */
|
|
28
|
+
const VENDOR_KEY_PREFIX = (0, createProvidersHandlers_1.providerKeySecretName)("");
|
|
29
|
+
const isVendorKey = (name) => typeof name === "string" && name.startsWith(VENDOR_KEY_PREFIX);
|
|
30
|
+
exports.isVendorKey = isVendorKey;
|
|
31
|
+
/**
|
|
32
|
+
* True when the call is made with an API key's token. API keys get access key ids starting with
|
|
33
|
+
* "AP"; people signed in get "US".
|
|
34
|
+
*/
|
|
35
|
+
function isApiKeyCall(call) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const token = (0, common_1.getTokenFromCall)(call);
|
|
38
|
+
if (!token)
|
|
39
|
+
return false;
|
|
40
|
+
try {
|
|
41
|
+
const decoded = (0, common_1.decodeToken)(token);
|
|
42
|
+
return (_b = (_a = decoded.accessKeyId) === null || _a === void 0 ? void 0 : _a.startsWith("AP")) !== null && _b !== void 0 ? _b : false;
|
|
43
|
+
}
|
|
44
|
+
catch (_c) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** A Secret as anyone but an API key reading an app secret sees it: no value. */
|
|
49
|
+
function withoutValue(secret) {
|
|
50
|
+
return Object.assign(Object.assign({}, secret), { secret: "" });
|
|
51
|
+
}
|
|
52
|
+
const vendorKeyError = () => ({
|
|
53
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
54
|
+
message: "This is a vendor key. Manage it with fonoster providers:keys:set or Vendor keys in the dashboard"
|
|
55
|
+
});
|
|
56
|
+
exports.vendorKeyError = vendorKeyError;
|
|
@@ -31,6 +31,7 @@ exports.deleteSecret = deleteSecret;
|
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
33
|
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
34
|
+
const access_1 = require("./access");
|
|
34
35
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
37
|
function deleteSecret(prisma) {
|
|
@@ -38,6 +39,9 @@ function deleteSecret(prisma) {
|
|
|
38
39
|
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
39
40
|
const { ref } = call.request;
|
|
40
41
|
logger.verbose("call to deleteSecret", { ref });
|
|
42
|
+
if ((0, access_1.isVendorKey)((yield getFn(ref)).name)) {
|
|
43
|
+
throw (0, access_1.vendorKeyError)();
|
|
44
|
+
}
|
|
41
45
|
yield prisma.secret.delete({ where: { ref } });
|
|
42
46
|
return { ref };
|
|
43
47
|
});
|
|
@@ -31,6 +31,7 @@ exports.getSecret = getSecret;
|
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
33
|
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
34
|
+
const access_1 = require("./access");
|
|
34
35
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
37
|
function getSecret(prisma) {
|
|
@@ -38,7 +39,11 @@ function getSecret(prisma) {
|
|
|
38
39
|
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
39
40
|
const { ref } = call.request;
|
|
40
41
|
logger.verbose("call to getSecret", { ref });
|
|
41
|
-
|
|
42
|
+
const secret = yield getFn(ref);
|
|
43
|
+
// Only apps, through an API key, read a value, and never a vendor key's.
|
|
44
|
+
return (0, access_1.isApiKeyCall)(call) && !(0, access_1.isVendorKey)(secret.name)
|
|
45
|
+
? secret
|
|
46
|
+
: (0, access_1.withoutValue)(secret);
|
|
42
47
|
});
|
|
43
48
|
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.emptySchema);
|
|
44
49
|
}
|
|
@@ -30,13 +30,14 @@ exports.listSecrets = listSecrets;
|
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
|
+
const access_1 = require("./access");
|
|
33
34
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
34
35
|
function listSecrets(prisma) {
|
|
35
36
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
36
37
|
var _a;
|
|
37
38
|
const { pageSize, pageToken } = call.request;
|
|
38
39
|
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
39
|
-
logger.verbose("call to
|
|
40
|
+
logger.verbose("call to listSecrets", {
|
|
40
41
|
accessKeyId,
|
|
41
42
|
pageSize,
|
|
42
43
|
pageToken
|
|
@@ -46,7 +47,10 @@ function listSecrets(prisma) {
|
|
|
46
47
|
take: pageSize,
|
|
47
48
|
skip: pageToken ? 1 : 0,
|
|
48
49
|
cursor: pageToken ? { ref: pageToken } : undefined
|
|
49
|
-
}))
|
|
50
|
+
}))
|
|
51
|
+
.map(common_1.datesMapper)
|
|
52
|
+
// A list never carries values; an app reads one with getSecret.
|
|
53
|
+
.map(access_1.withoutValue);
|
|
50
54
|
callback(null, {
|
|
51
55
|
items: result,
|
|
52
56
|
nextPageToken: result.length < pageSize ? "" : (_a = result[result.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
|
|
@@ -31,6 +31,7 @@ exports.updateSecret = updateSecret;
|
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
33
|
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
34
|
+
const access_1 = require("./access");
|
|
34
35
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
37
|
function updateSecret(prisma) {
|
|
@@ -41,14 +42,14 @@ function updateSecret(prisma) {
|
|
|
41
42
|
logger.verbose("call to updateSecret", {
|
|
42
43
|
accessKeyId
|
|
43
44
|
});
|
|
45
|
+
if ((0, access_1.isVendorKey)((yield getFn(call.request.ref)).name)) {
|
|
46
|
+
throw (0, access_1.vendorKeyError)();
|
|
47
|
+
}
|
|
44
48
|
yield prisma.secret.update({
|
|
45
49
|
where: { ref: call.request.ref },
|
|
46
|
-
data: {
|
|
47
|
-
name,
|
|
48
|
-
secret
|
|
49
|
-
}
|
|
50
|
+
data: Object.assign(Object.assign({}, (name ? { name } : {})), (secret ? { secret } : {}))
|
|
50
51
|
});
|
|
51
52
|
return { ref: call.request.ref };
|
|
52
53
|
});
|
|
53
|
-
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.
|
|
54
|
+
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.updateSecretRequestSchema);
|
|
54
55
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NatsConnection } from "nats";
|
|
2
|
+
import { WorkspaceDirectory } from "../regions/types";
|
|
3
|
+
/** AppBridge asks here whether an inbound call's workspace was deleted (#1318). */
|
|
4
|
+
export declare const WORKSPACE_DELETED_SUBJECT = "workspaces.deleted";
|
|
5
|
+
/**
|
|
6
|
+
* Answers `workspaces.deleted` from Identity's deletion records: `{deleted}`, or `{error}` when
|
|
7
|
+
* the directory isn't attached or its database fails (AppBridge then admits the call). Uncached,
|
|
8
|
+
* so a call right after a delete is refused. It only answers yes or no: nothing here erases.
|
|
9
|
+
*/
|
|
10
|
+
export declare function subscribeWorkspaceDeleted(nc: NatsConnection, directory: () => WorkspaceDirectory | undefined): () => void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WORKSPACE_DELETED_SUBJECT = void 0;
|
|
4
|
+
exports.subscribeWorkspaceDeleted = subscribeWorkspaceDeleted;
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
7
|
+
* http://github.com/fonoster/fonoster
|
|
8
|
+
*
|
|
9
|
+
* This file is part of Fonoster
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the MIT License (the "License");
|
|
12
|
+
* you may not use this file except in compliance with
|
|
13
|
+
* the License. You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* https://opensource.org/licenses/MIT
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
const logger_1 = require("@fonoster/logger");
|
|
24
|
+
const nats_1 = require("nats");
|
|
25
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
26
|
+
const sc = (0, nats_1.StringCodec)();
|
|
27
|
+
/** AppBridge asks here whether an inbound call's workspace was deleted (#1318). */
|
|
28
|
+
exports.WORKSPACE_DELETED_SUBJECT = "workspaces.deleted";
|
|
29
|
+
/**
|
|
30
|
+
* Answers `workspaces.deleted` from Identity's deletion records: `{deleted}`, or `{error}` when
|
|
31
|
+
* the directory isn't attached or its database fails (AppBridge then admits the call). Uncached,
|
|
32
|
+
* so a call right after a delete is refused. It only answers yes or no: nothing here erases.
|
|
33
|
+
*/
|
|
34
|
+
function subscribeWorkspaceDeleted(nc, directory) {
|
|
35
|
+
const reply = (msg, body) => msg.respond(sc.encode(JSON.stringify(body)));
|
|
36
|
+
const sub = nc.subscribe(exports.WORKSPACE_DELETED_SUBJECT, {
|
|
37
|
+
queue: "apiserver",
|
|
38
|
+
callback: (err, msg) => {
|
|
39
|
+
var _a;
|
|
40
|
+
if (err)
|
|
41
|
+
return;
|
|
42
|
+
let accessKeyId;
|
|
43
|
+
try {
|
|
44
|
+
accessKeyId = (_a = JSON.parse(sc.decode(msg.data))) === null || _a === void 0 ? void 0 : _a.accessKeyId;
|
|
45
|
+
}
|
|
46
|
+
catch (_b) {
|
|
47
|
+
// answered below as not deleted
|
|
48
|
+
}
|
|
49
|
+
if (typeof accessKeyId !== "string" || !accessKeyId)
|
|
50
|
+
return void reply(msg, { deleted: false });
|
|
51
|
+
const d = directory();
|
|
52
|
+
if (!d)
|
|
53
|
+
return void reply(msg, { error: "directory unavailable" });
|
|
54
|
+
d.isDeleted(accessKeyId).then((deleted) => reply(msg, { deleted }), (e) => {
|
|
55
|
+
logger.warn(`workspaces.deleted: could not read deletion records: ${e.message}`);
|
|
56
|
+
reply(msg, { error: "directory unavailable" });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return () => sub.unsubscribe();
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.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.
|
|
27
|
-
"@fonoster/autopilot": "^0.
|
|
28
|
-
"@fonoster/callrecord": "^0.
|
|
29
|
-
"@fonoster/common": "^0.
|
|
30
|
-
"@fonoster/identity": "^0.
|
|
31
|
-
"@fonoster/logger": "^0.
|
|
32
|
-
"@fonoster/sipnet": "^0.
|
|
33
|
-
"@fonoster/types": "^0.
|
|
26
|
+
"@fonoster/authz": "^0.57.0",
|
|
27
|
+
"@fonoster/autopilot": "^0.57.0",
|
|
28
|
+
"@fonoster/callrecord": "^0.57.0",
|
|
29
|
+
"@fonoster/common": "^0.57.0",
|
|
30
|
+
"@fonoster/identity": "^0.57.0",
|
|
31
|
+
"@fonoster/logger": "^0.57.0",
|
|
32
|
+
"@fonoster/sipnet": "^0.57.0",
|
|
33
|
+
"@fonoster/types": "^0.57.0",
|
|
34
34
|
"@grpc/grpc-js": "~1.14.6",
|
|
35
35
|
"@prisma/client": "^6.19.1",
|
|
36
36
|
"@routr/common": "^2.24.0",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@fonoster/ops": "^0.
|
|
65
|
+
"@fonoster/ops": "^0.57.0",
|
|
66
66
|
"@types/express": "^5.0.6",
|
|
67
67
|
"@types/jsonwebtoken": "^9.0.10",
|
|
68
68
|
"@types/uuid": "^10.0.0",
|
|
69
69
|
"@types/validator": "^13.15.10"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "68e8138df7e82c705f70d1f7293530959f3c9d3c",
|
|
72
72
|
"prisma": {
|
|
73
73
|
"seed": "tsx src/core/seed.ts"
|
|
74
74
|
}
|