@fonoster/apiserver 0.59.0 → 0.62.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/buildService.d.ts +5 -3
- package/dist/billing/buildService.js +12 -8
- package/dist/calls/createCall.js +3 -1
- package/dist/calls/getCall.js +1 -1
- package/dist/core/notFoundError.d.ts +12 -1
- package/dist/core/notFoundError.js +9 -4
- package/dist/core/services.d.ts +1 -1
- package/dist/providers/createProvidersHandlers.js +4 -3
- package/dist/webhooks/createWebhooksHandlers.js +3 -4
- package/package.json +11 -11
|
@@ -6,9 +6,11 @@ import * as grpc from "@grpc/grpc-js";
|
|
|
6
6
|
export declare function ownerOfCall(call: unknown): string | undefined;
|
|
7
7
|
/**
|
|
8
8
|
* The Billing API for the dashboard (billing.proto), when billing is on: each call is passed to
|
|
9
|
-
* the billing service with owner_ref set from the caller, never from the request.
|
|
9
|
+
* the billing service with owner_ref set from the caller, never from the request. GetCallsStatus
|
|
10
|
+
* is for anyone in the workspace (the authorization interceptor checks the role) and gets
|
|
11
|
+
* access_key_id from the call.
|
|
10
12
|
*/
|
|
11
|
-
declare function buildService(address: string, ownerOf?: typeof ownerOfCall): {
|
|
13
|
+
declare function buildService(address: string, ownerOf?: typeof ownerOfCall, accessKeyIdOf?: (call: unknown) => string | undefined): {
|
|
12
14
|
definition: {
|
|
13
15
|
serviceName: string;
|
|
14
16
|
pckg: string;
|
|
@@ -16,7 +18,7 @@ declare function buildService(address: string, ownerOf?: typeof ownerOfCall): {
|
|
|
16
18
|
proto: string;
|
|
17
19
|
};
|
|
18
20
|
handlers: {
|
|
19
|
-
|
|
21
|
+
getCallsStatus: (call: {
|
|
20
22
|
request: Record<string, unknown>;
|
|
21
23
|
}, callback: (error: grpc.ServiceError | null | Partial<grpc.ServiceError>, response?: unknown) => void) => void;
|
|
22
24
|
};
|
|
@@ -85,10 +85,17 @@ function ownerOfCall(call) {
|
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* The Billing API for the dashboard (billing.proto), when billing is on: each call is passed to
|
|
88
|
-
* the billing service with owner_ref set from the caller, never from the request.
|
|
88
|
+
* the billing service with owner_ref set from the caller, never from the request. GetCallsStatus
|
|
89
|
+
* is for anyone in the workspace (the authorization interceptor checks the role) and gets
|
|
90
|
+
* access_key_id from the call.
|
|
89
91
|
*/
|
|
90
|
-
function buildService(address, ownerOf = ownerOfCall) {
|
|
92
|
+
function buildService(address, ownerOf = ownerOfCall, accessKeyIdOf = (call) => (0, common_1.getAccessKeyIdFromCall)(call)) {
|
|
91
93
|
const client = new (grpc.makeGenericClientConstructor(definition(), "Billing", {}))(address, grpc.credentials.createInsecure());
|
|
94
|
+
const send = (method, request, callback) => client[method](request, (error, response) => {
|
|
95
|
+
if (error)
|
|
96
|
+
logger.verbose("billing call refused", { method, code: error.code });
|
|
97
|
+
callback(error ? { code: error.code, message: error.details } : null, response);
|
|
98
|
+
});
|
|
92
99
|
const forward = (method) => (call, callback) => {
|
|
93
100
|
const ownerRef = ownerOf(call);
|
|
94
101
|
if (!ownerRef) {
|
|
@@ -98,12 +105,9 @@ function buildService(address, ownerOf = ownerOfCall) {
|
|
|
98
105
|
});
|
|
99
106
|
return;
|
|
100
107
|
}
|
|
101
|
-
|
|
102
|
-
if (error)
|
|
103
|
-
logger.verbose("billing call refused", { method, code: error.code });
|
|
104
|
-
callback(error ? { code: error.code, message: error.details } : null, response);
|
|
105
|
-
});
|
|
108
|
+
send(method, Object.assign(Object.assign({}, call.request), { ownerRef }), callback);
|
|
106
109
|
};
|
|
110
|
+
const getCallsStatus = (call, callback) => send("getCallsStatus", Object.assign(Object.assign({}, call.request), { accessKeyId: accessKeyIdOf(call) }), callback);
|
|
107
111
|
return {
|
|
108
112
|
definition: {
|
|
109
113
|
serviceName: "Billing",
|
|
@@ -111,6 +115,6 @@ function buildService(address, ownerOf = ownerOfCall) {
|
|
|
111
115
|
version: "v1beta2",
|
|
112
116
|
proto: "billing.proto"
|
|
113
117
|
},
|
|
114
|
-
handlers: Object.fromEntries(METHODS.map((m) => [m, forward(m)]))
|
|
118
|
+
handlers: Object.assign(Object.assign({}, Object.fromEntries(METHODS.map((m) => [m, forward(m)]))), { getCallsStatus })
|
|
115
119
|
};
|
|
116
120
|
}
|
package/dist/calls/createCall.js
CHANGED
|
@@ -50,7 +50,9 @@ function createCall(prisma, publisher, isWorkspaceNumber, admitCall) {
|
|
|
50
50
|
where: { ref: appRef, accessKeyId }
|
|
51
51
|
});
|
|
52
52
|
if (!app) {
|
|
53
|
-
throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found
|
|
53
|
+
throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found`, {
|
|
54
|
+
public: true
|
|
55
|
+
});
|
|
54
56
|
}
|
|
55
57
|
// `from` picks the trunk the call leaves by (X-Dod-Number), so it must be one of the
|
|
56
58
|
// workspace's own Numbers; another workspace's number is reported like an unknown one.
|
package/dist/calls/getCall.js
CHANGED
|
@@ -40,7 +40,7 @@ function getCall(fetchSingleCall) {
|
|
|
40
40
|
logger.verbose("call to getCall", { accessKeyId, ref });
|
|
41
41
|
const response = yield fetchSingleCall(accessKeyId, ref);
|
|
42
42
|
if (!response) {
|
|
43
|
-
throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}
|
|
43
|
+
throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`, { public: true });
|
|
44
44
|
}
|
|
45
45
|
callback(null, response);
|
|
46
46
|
});
|
|
@@ -17,7 +17,18 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { status } from "@grpc/grpc-js";
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A NOT_FOUND error. The caller gets "The requested resource was not found" unless the error
|
|
22
|
+
* is marked public, in which case the caller gets `message` as written.
|
|
23
|
+
*
|
|
24
|
+
* Mark an error public only when it comes from a lookup that filters by the caller's
|
|
25
|
+
* accessKeyId. Never mark the error of a `withAccess` getFn: an unknown ref and another
|
|
26
|
+
* workspace's ref must answer the same message, or callers could probe other workspaces' refs.
|
|
27
|
+
*/
|
|
28
|
+
declare const notFoundError: (message: string, options?: {
|
|
29
|
+
public?: boolean;
|
|
30
|
+
}) => {
|
|
31
|
+
public?: boolean;
|
|
21
32
|
code: status;
|
|
22
33
|
message: string;
|
|
23
34
|
};
|
|
@@ -20,8 +20,13 @@ exports.notFoundError = void 0;
|
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
22
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A NOT_FOUND error. The caller gets "The requested resource was not found" unless the error
|
|
25
|
+
* is marked public, in which case the caller gets `message` as written.
|
|
26
|
+
*
|
|
27
|
+
* Mark an error public only when it comes from a lookup that filters by the caller's
|
|
28
|
+
* accessKeyId. Never mark the error of a `withAccess` getFn: an unknown ref and another
|
|
29
|
+
* workspace's ref must answer the same message, or callers could probe other workspaces' refs.
|
|
30
|
+
*/
|
|
31
|
+
const notFoundError = (message, options) => (Object.assign({ code: grpc_js_1.status.NOT_FOUND, message }, ((options === null || options === void 0 ? void 0 : options.public) ? { public: true } : {})));
|
|
27
32
|
exports.notFoundError = notFoundError;
|
package/dist/core/services.d.ts
CHANGED
|
@@ -410,7 +410,7 @@ declare const services: Promise<[{
|
|
|
410
410
|
proto: string;
|
|
411
411
|
};
|
|
412
412
|
handlers: {
|
|
413
|
-
|
|
413
|
+
getCallsStatus: (call: {
|
|
414
414
|
request: Record<string, unknown>;
|
|
415
415
|
}, callback: (error: import("@grpc/grpc-js").ServiceError | null | Partial<import("@grpc/grpc-js").ServiceError>, response?: unknown) => void) => void;
|
|
416
416
|
};
|
|
@@ -31,11 +31,10 @@ exports.createProvidersHandlers = createProvidersHandlers;
|
|
|
31
31
|
*/
|
|
32
32
|
const common_1 = require("@fonoster/common");
|
|
33
33
|
const logger_1 = require("@fonoster/logger");
|
|
34
|
+
const notFoundError_1 = require("../core/notFoundError");
|
|
34
35
|
const registryUsage_1 = require("./registryUsage");
|
|
35
36
|
const INVALID_ARGUMENT = 3;
|
|
36
|
-
const NOT_FOUND = 5;
|
|
37
37
|
const invalid = (message) => ({ code: INVALID_ARGUMENT, message });
|
|
38
|
-
const notFound = (message) => ({ code: NOT_FOUND, message });
|
|
39
38
|
const seconds = (d) => (d ? Math.floor(d.getTime() / 1000) : 0);
|
|
40
39
|
/** The Secret name a provider key is stored under. */
|
|
41
40
|
const providerKeySecretName = (providerId) => `provider-key/${providerId}`;
|
|
@@ -203,7 +202,9 @@ function createProvidersHandlers(db) {
|
|
|
203
202
|
where: { accessKeyId_providerId: { accessKeyId, providerId } }
|
|
204
203
|
});
|
|
205
204
|
if (!existing)
|
|
206
|
-
throw
|
|
205
|
+
throw (0, notFoundError_1.notFoundError)(`no key for provider ${providerId}`, {
|
|
206
|
+
public: true
|
|
207
|
+
});
|
|
207
208
|
yield db.secret.delete({ where: { ref: existing.secretRef } });
|
|
208
209
|
callback(null, { providerId });
|
|
209
210
|
});
|
|
@@ -31,11 +31,10 @@ exports.createWebhooksHandlers = createWebhooksHandlers;
|
|
|
31
31
|
const crypto_1 = require("crypto");
|
|
32
32
|
const common_1 = require("@fonoster/common");
|
|
33
33
|
const logger_1 = require("@fonoster/logger");
|
|
34
|
+
const notFoundError_1 = require("../core/notFoundError");
|
|
34
35
|
const ROTATION_WINDOW_MS = 24 * 3600 * 1000;
|
|
35
36
|
const INVALID_ARGUMENT = 3;
|
|
36
|
-
const NOT_FOUND = 5;
|
|
37
37
|
const invalid = (message) => ({ code: INVALID_ARGUMENT, message });
|
|
38
|
-
const notFound = (message) => ({ code: NOT_FOUND, message });
|
|
39
38
|
const seconds = (d) => (d ? Math.floor(d.getTime() / 1000) : 0);
|
|
40
39
|
const hint = (secret) => `…${secret.slice(-4)}`;
|
|
41
40
|
function toWebhook(row) {
|
|
@@ -99,7 +98,7 @@ function createWebhooksHandlers(db, config = {}) {
|
|
|
99
98
|
where: { ref, accessKeyId }
|
|
100
99
|
});
|
|
101
100
|
if (!row)
|
|
102
|
-
throw
|
|
101
|
+
throw (0, notFoundError_1.notFoundError)(`webhook not found: ${ref}`, { public: true });
|
|
103
102
|
return row;
|
|
104
103
|
});
|
|
105
104
|
const createWebhook = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -188,7 +187,7 @@ function createWebhooksHandlers(db, config = {}) {
|
|
|
188
187
|
where: { ref, accessKeyId }
|
|
189
188
|
});
|
|
190
189
|
if (!row)
|
|
191
|
-
throw
|
|
190
|
+
throw (0, notFoundError_1.notFoundError)(`delivery not found: ${ref}`, { public: true });
|
|
192
191
|
return row;
|
|
193
192
|
});
|
|
194
193
|
/** One delivery of the caller's workspace, with the event it sends. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.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.62.0",
|
|
27
|
+
"@fonoster/autopilot": "^0.62.0",
|
|
28
|
+
"@fonoster/callrecord": "^0.62.0",
|
|
29
|
+
"@fonoster/common": "^0.62.0",
|
|
30
|
+
"@fonoster/identity": "^0.62.0",
|
|
31
|
+
"@fonoster/logger": "^0.62.0",
|
|
32
|
+
"@fonoster/sipnet": "^0.62.0",
|
|
33
|
+
"@fonoster/types": "^0.62.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.62.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": "2fe4ba952809d7f460f57089cf8cee34dd053baf",
|
|
72
72
|
"prisma": {
|
|
73
73
|
"seed": "tsx src/core/seed.ts"
|
|
74
74
|
}
|