@fonoster/apiserver 0.7.5 → 0.7.9
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/applications/deleteApplication.js +1 -1
- package/dist/applications/getApplication.js +2 -2
- package/dist/applications/listApplications.d.ts +1 -1
- package/dist/applications/listApplications.js +1 -1
- package/dist/applications/updateApplication.js +4 -4
- package/dist/applications/utils/getApplicationValidationSchema.d.ts +1 -1
- package/dist/applications/utils/getApplicationValidationSchema.js +2 -2
- package/dist/calls/buildService.d.ts +2 -4
- package/dist/calls/createCall.d.ts +1 -1
- package/dist/calls/createCall.js +1 -8
- package/dist/calls/getCall.d.ts +1 -1
- package/dist/calls/getCall.js +1 -5
- package/dist/calls/listCalls.d.ts +1 -1
- package/dist/calls/listCalls.js +1 -2
- package/dist/calls/makeTrackCall.d.ts +2 -11
- package/dist/calls/makeTrackCall.js +2 -5
- package/dist/core/seed.js +5 -5
- package/dist/core/services.d.ts +20 -22
- package/dist/secrets/createSecret.d.ts +1 -1
- package/dist/secrets/createSecret.js +1 -1
- package/dist/secrets/deleteSecret.js +2 -2
- package/dist/secrets/getSecret.js +2 -2
- package/dist/secrets/listSecrets.d.ts +1 -1
- package/dist/secrets/listSecrets.js +1 -1
- package/dist/secrets/updateSecret.js +2 -1
- package/dist/utils/withErrorHandlingAndValidationAndAccess.d.ts +5 -0
- package/dist/utils/withErrorHandlingAndValidationAndAccess.js +30 -0
- package/dist/voice/VoiceClientImpl.js +0 -4
- package/dist/voice/handlers/gather/Gather.js +5 -2
- package/dist/voice/handlers/utils/withErrorHandling.js +0 -1
- package/dist/voice/stt/SpeechToTextFactory.js +1 -1
- package/dist/voice/tts/TextToSpeechFactory.js +1 -1
- package/package.json +8 -8
|
@@ -41,5 +41,5 @@ function deleteApplication(prisma) {
|
|
|
41
41
|
yield prisma.application.delete({ where: { ref } });
|
|
42
42
|
return { ref };
|
|
43
43
|
});
|
|
44
|
-
return (0, common_1.
|
|
44
|
+
return (0, common_1.withErrorHandlingAndValidation)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)), common_1.Validators.baseApiObjectSchema);
|
|
45
45
|
}
|
|
@@ -29,10 +29,10 @@ exports.getApplication = getApplication;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
34
|
const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
|
|
35
|
+
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
36
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
37
37
|
function getApplication(prisma) {
|
|
38
38
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
@@ -42,5 +42,5 @@ function getApplication(prisma) {
|
|
|
42
42
|
const result = yield getFn(ref);
|
|
43
43
|
return result ? (0, applicationWithEncodedStruct_1.applicationWithEncodedStruct)(result) : null;
|
|
44
44
|
});
|
|
45
|
-
return (0,
|
|
45
|
+
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.baseApiObjectSchema);
|
|
46
46
|
}
|
|
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
|
|
|
2
2
|
import { Prisma } from "../core/db";
|
|
3
3
|
declare function listApplications(prisma: Prisma): (call: {
|
|
4
4
|
request: unknown;
|
|
5
|
-
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { listApplications };
|
|
@@ -60,5 +60,5 @@ function listApplications(prisma) {
|
|
|
60
60
|
nextPageToken: (_a = result[result.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
|
-
return (0, common_1.
|
|
63
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listRequestSchema);
|
|
64
64
|
}
|
|
@@ -38,14 +38,14 @@ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filen
|
|
|
38
38
|
function updateApplication(prisma) {
|
|
39
39
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
40
40
|
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const {
|
|
41
|
+
const { request } = call;
|
|
42
|
+
const { type, ref: applicationRef } = request;
|
|
42
43
|
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
43
|
-
(0, validOrThrow_1.validOrThrow)(
|
|
44
|
+
(0, validOrThrow_1.validOrThrow)(request);
|
|
44
45
|
logger.verbose("call to updateApplication", {
|
|
45
46
|
accessKeyId,
|
|
46
47
|
type
|
|
47
48
|
});
|
|
48
|
-
// TODO: Revisit to see if needs optimization
|
|
49
49
|
yield prisma.$transaction([
|
|
50
50
|
prisma.textToSpeech.deleteMany({
|
|
51
51
|
where: {
|
|
@@ -67,7 +67,7 @@ function updateApplication(prisma) {
|
|
|
67
67
|
ref: applicationRef,
|
|
68
68
|
accessKeyId
|
|
69
69
|
},
|
|
70
|
-
data: (0, convertToApplicationData_1.convertToApplicationData)(
|
|
70
|
+
data: (0, convertToApplicationData_1.convertToApplicationData)(request)
|
|
71
71
|
})
|
|
72
72
|
]);
|
|
73
73
|
return { ref: applicationRef };
|
|
@@ -7,7 +7,7 @@ declare function getApplicationValidationSchema(request: {
|
|
|
7
7
|
type: z.ZodNativeEnum<{
|
|
8
8
|
EXTERNAL: "EXTERNAL";
|
|
9
9
|
}>;
|
|
10
|
-
endpoint: z.ZodEffects<z.
|
|
10
|
+
endpoint: z.ZodEffects<z.ZodOptional<z.ZodString>, string, string>;
|
|
11
11
|
textToSpeech: z.ZodUndefined | z.ZodObject<{
|
|
12
12
|
productRef: z.ZodString;
|
|
13
13
|
config: any;
|
|
@@ -27,7 +27,7 @@ const Google_1 = require("../../voice/stt/Google");
|
|
|
27
27
|
const Azure_1 = require("../../voice/tts/Azure");
|
|
28
28
|
const Deepgram_2 = require("../../voice/tts/Deepgram");
|
|
29
29
|
const Google_2 = require("../../voice/tts/Google");
|
|
30
|
-
|
|
30
|
+
const MAX_NAME_MESSAGE = "Name must contain at most 255 characters";
|
|
31
31
|
const validators = {
|
|
32
32
|
ttsConfigValidators: {
|
|
33
33
|
"tts.google": Google_2.Google.getConfigValidationSchema,
|
|
@@ -51,7 +51,7 @@ const validators = {
|
|
|
51
51
|
function getApplicationValidationSchema(request) {
|
|
52
52
|
const { ttsEngineName, sttEngineName } = request;
|
|
53
53
|
return zod_1.z.object({
|
|
54
|
-
name: zod_1.z.string(),
|
|
54
|
+
name: zod_1.z.string().max(255, MAX_NAME_MESSAGE),
|
|
55
55
|
type: zod_1.z.nativeEnum(client_1.ApplicationType),
|
|
56
56
|
endpoint: common_1.hostOrHostPortSchema,
|
|
57
57
|
textToSpeech: ttsEngineName
|
|
@@ -17,10 +17,8 @@ declare function buildService(influxdb: InfluxDBClient): Promise<{
|
|
|
17
17
|
request: unknown;
|
|
18
18
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
19
19
|
trackCall: (call: {
|
|
20
|
-
request:
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
}) => void;
|
|
20
|
+
request: unknown;
|
|
21
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
24
22
|
};
|
|
25
23
|
}>;
|
|
26
24
|
export { buildService };
|
|
@@ -3,5 +3,5 @@ import { CallPublisher } from "./types";
|
|
|
3
3
|
import { Prisma } from "../core/db";
|
|
4
4
|
declare function createCall(prisma: Prisma, publisher: CallPublisher): (call: {
|
|
5
5
|
request: unknown;
|
|
6
|
-
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
7
|
export { createCall };
|
package/dist/calls/createCall.js
CHANGED
|
@@ -32,15 +32,8 @@ const common_1 = require("@fonoster/common");
|
|
|
32
32
|
const identity_1 = require("@fonoster/identity");
|
|
33
33
|
const logger_1 = require("@fonoster/logger");
|
|
34
34
|
const uuid_1 = require("uuid");
|
|
35
|
-
const zod_1 = require("zod");
|
|
36
35
|
const notFoundError_1 = require("../core/notFoundError");
|
|
37
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
|
-
const createCallRequestSchema = zod_1.z.object({
|
|
39
|
-
from: zod_1.z.string(),
|
|
40
|
-
to: zod_1.z.string(),
|
|
41
|
-
appRef: zod_1.z.string(),
|
|
42
|
-
timeout: zod_1.z.number().optional()
|
|
43
|
-
});
|
|
44
37
|
function createCall(prisma, publisher) {
|
|
45
38
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
46
39
|
const { request } = call;
|
|
@@ -64,5 +57,5 @@ function createCall(prisma, publisher) {
|
|
|
64
57
|
});
|
|
65
58
|
callback(null, { ref });
|
|
66
59
|
});
|
|
67
|
-
return (0, common_1.
|
|
60
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.createCallRequestSchema);
|
|
68
61
|
}
|
package/dist/calls/getCall.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
|
|
|
2
2
|
import { InfluxDBClient } from "./types";
|
|
3
3
|
declare function getCall(influx: InfluxDBClient): (call: {
|
|
4
4
|
request: unknown;
|
|
5
|
-
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { getCall };
|
package/dist/calls/getCall.js
CHANGED
|
@@ -31,13 +31,9 @@ exports.getCall = getCall;
|
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const identity_1 = require("@fonoster/identity");
|
|
33
33
|
const logger_1 = require("@fonoster/logger");
|
|
34
|
-
const zod_1 = require("zod");
|
|
35
34
|
const createFetchSingleCall_1 = require("./createFetchSingleCall");
|
|
36
35
|
const notFoundError_1 = require("../core/notFoundError");
|
|
37
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
|
-
const getCallRequestSchema = zod_1.z.object({
|
|
39
|
-
ref: zod_1.z.string({ message: "Invalid call reference" })
|
|
40
|
-
});
|
|
41
37
|
function getCall(influx) {
|
|
42
38
|
const fetchSingleCall = (0, createFetchSingleCall_1.createFetchSingleCall)(influx);
|
|
43
39
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -50,5 +46,5 @@ function getCall(influx) {
|
|
|
50
46
|
}
|
|
51
47
|
callback(null, response);
|
|
52
48
|
});
|
|
53
|
-
return (0, common_1.
|
|
49
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.getCallRequestSchema);
|
|
54
50
|
}
|
|
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
|
|
|
2
2
|
import { InfluxDBClient } from "./types";
|
|
3
3
|
declare function listCalls(influx: InfluxDBClient): (call: {
|
|
4
4
|
request: unknown;
|
|
5
|
-
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { listCalls };
|
package/dist/calls/listCalls.js
CHANGED
|
@@ -29,7 +29,6 @@ exports.listCalls = listCalls;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const listCallsRequestSchema_1 = require("@fonoster/common/src/validators/listCallsRequestSchema");
|
|
33
32
|
const identity_1 = require("@fonoster/identity");
|
|
34
33
|
const logger_1 = require("@fonoster/logger");
|
|
35
34
|
const createFetchCalls_1 = require("./createFetchCalls");
|
|
@@ -43,5 +42,5 @@ function listCalls(influx) {
|
|
|
43
42
|
const result = yield fetchCalls(accessKeyId, request);
|
|
44
43
|
callback(null, result);
|
|
45
44
|
});
|
|
46
|
-
return (0, common_1.
|
|
45
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listCallsRequestSchema);
|
|
47
46
|
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { NatsConnection } from "nats";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
declare const trackCallRequestSchema: z.ZodObject<{
|
|
4
|
-
ref: z.ZodString;
|
|
5
|
-
}, "strip", z.ZodTypeAny, {
|
|
6
|
-
ref?: string;
|
|
7
|
-
}, {
|
|
8
|
-
ref?: string;
|
|
9
|
-
}>;
|
|
10
|
-
type TrackCallRequest = z.infer<typeof trackCallRequestSchema>;
|
|
11
2
|
declare function makeTrackCall(nc: NatsConnection): (call: {
|
|
12
|
-
request:
|
|
13
|
-
}) => void
|
|
3
|
+
request: unknown;
|
|
4
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
14
5
|
export { makeTrackCall };
|
|
@@ -21,7 +21,6 @@ exports.makeTrackCall = makeTrackCall;
|
|
|
21
21
|
*/
|
|
22
22
|
const common_1 = require("@fonoster/common");
|
|
23
23
|
const logger_1 = require("@fonoster/logger");
|
|
24
|
-
const zod_1 = require("zod");
|
|
25
24
|
const envs_1 = require("../envs");
|
|
26
25
|
const FINAL_STATUSES = [
|
|
27
26
|
common_1.DialStatus.BUSY,
|
|
@@ -29,9 +28,6 @@ const FINAL_STATUSES = [
|
|
|
29
28
|
common_1.DialStatus.NOANSWER
|
|
30
29
|
];
|
|
31
30
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
32
|
-
const trackCallRequestSchema = zod_1.z.object({
|
|
33
|
-
ref: zod_1.z.string()
|
|
34
|
-
});
|
|
35
31
|
function makeTrackCall(nc) {
|
|
36
32
|
const trackingCallsMap = new Map();
|
|
37
33
|
const subscription = nc.subscribe(envs_1.CALLS_TRACK_CALL_SUBJECT);
|
|
@@ -57,10 +53,11 @@ function makeTrackCall(nc) {
|
|
|
57
53
|
stream.write({ ref, status });
|
|
58
54
|
}
|
|
59
55
|
};
|
|
60
|
-
|
|
56
|
+
const fn = (call) => {
|
|
61
57
|
const stream = call;
|
|
62
58
|
const { ref } = call.request;
|
|
63
59
|
logger.verbose("call to trackCall", { ref });
|
|
64
60
|
trackingCallsMap.set(ref, stream);
|
|
65
61
|
};
|
|
62
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
|
|
66
63
|
}
|
package/dist/core/seed.js
CHANGED
|
@@ -74,13 +74,13 @@ function main() {
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
yield prisma.product.upsert({
|
|
77
|
-
where: { ref: "
|
|
77
|
+
where: { ref: "llm.openai" },
|
|
78
78
|
update: {},
|
|
79
79
|
create: {
|
|
80
|
-
ref: "
|
|
81
|
-
name: "
|
|
82
|
-
vendor: "
|
|
83
|
-
type: "
|
|
80
|
+
ref: "llm.openai",
|
|
81
|
+
name: "OpenAI Language Model",
|
|
82
|
+
vendor: "OPENAI",
|
|
83
|
+
type: "ASSISTANT"
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
});
|
package/dist/core/services.d.ts
CHANGED
|
@@ -64,10 +64,8 @@ declare const services: Promise<[{
|
|
|
64
64
|
request: unknown;
|
|
65
65
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
66
66
|
trackCall: (call: {
|
|
67
|
-
request:
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
}) => void;
|
|
67
|
+
request: unknown;
|
|
68
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
71
69
|
};
|
|
72
70
|
}, {
|
|
73
71
|
definition: {
|
|
@@ -147,8 +145,8 @@ declare const services: Promise<[{
|
|
|
147
145
|
};
|
|
148
146
|
handlers: {
|
|
149
147
|
createAgent: (call: {
|
|
150
|
-
request:
|
|
151
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
148
|
+
request: unknown;
|
|
149
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
152
150
|
updateAgent: (call: {
|
|
153
151
|
request: unknown;
|
|
154
152
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
@@ -171,8 +169,8 @@ declare const services: Promise<[{
|
|
|
171
169
|
};
|
|
172
170
|
handlers: {
|
|
173
171
|
createCredentials: (call: {
|
|
174
|
-
request:
|
|
175
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
172
|
+
request: unknown;
|
|
173
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
176
174
|
updateCredentials: (call: {
|
|
177
175
|
request: unknown;
|
|
178
176
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
@@ -195,8 +193,8 @@ declare const services: Promise<[{
|
|
|
195
193
|
};
|
|
196
194
|
handlers: {
|
|
197
195
|
createAcl: (call: {
|
|
198
|
-
request:
|
|
199
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
196
|
+
request: unknown;
|
|
197
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
200
198
|
updateAcl: (call: {
|
|
201
199
|
request: unknown;
|
|
202
200
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
@@ -219,17 +217,17 @@ declare const services: Promise<[{
|
|
|
219
217
|
};
|
|
220
218
|
handlers: {
|
|
221
219
|
createNumber: (call: {
|
|
222
|
-
request:
|
|
223
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
220
|
+
request: unknown;
|
|
221
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
224
222
|
updateNumber: (call: {
|
|
225
|
-
request:
|
|
226
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
223
|
+
request: unknown;
|
|
224
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
227
225
|
getNumber: (call: {
|
|
228
|
-
request:
|
|
229
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
226
|
+
request: unknown;
|
|
227
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
230
228
|
listNumbers: (call: {
|
|
231
|
-
request:
|
|
232
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
229
|
+
request: unknown;
|
|
230
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
233
231
|
deleteNumber: (call: {
|
|
234
232
|
request: unknown;
|
|
235
233
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
@@ -243,8 +241,8 @@ declare const services: Promise<[{
|
|
|
243
241
|
};
|
|
244
242
|
handlers: {
|
|
245
243
|
createTrunk: (call: {
|
|
246
|
-
request:
|
|
247
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
244
|
+
request: unknown;
|
|
245
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
248
246
|
updateTrunk: (call: {
|
|
249
247
|
request: unknown;
|
|
250
248
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
@@ -267,8 +265,8 @@ declare const services: Promise<[{
|
|
|
267
265
|
};
|
|
268
266
|
handlers: {
|
|
269
267
|
createDomain: (call: {
|
|
270
|
-
request:
|
|
271
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
268
|
+
request: unknown;
|
|
269
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
272
270
|
updateDomain: (call: {
|
|
273
271
|
request: unknown;
|
|
274
272
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
|
|
|
2
2
|
import { Prisma } from "../core/db";
|
|
3
3
|
declare function createSecret(prisma: Prisma): (call: {
|
|
4
4
|
request: unknown;
|
|
5
|
-
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { createSecret };
|
|
@@ -29,9 +29,9 @@ exports.deleteSecret = deleteSecret;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
34
|
+
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
35
35
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
36
|
function deleteSecret(prisma) {
|
|
37
37
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
@@ -41,5 +41,5 @@ function deleteSecret(prisma) {
|
|
|
41
41
|
yield prisma.secret.delete({ where: { ref } });
|
|
42
42
|
return { ref };
|
|
43
43
|
});
|
|
44
|
-
return (0,
|
|
44
|
+
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.baseApiObjectSchema);
|
|
45
45
|
}
|
|
@@ -29,9 +29,9 @@ exports.getSecret = getSecret;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
34
|
+
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
35
35
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
36
|
function getSecret(prisma) {
|
|
37
37
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
@@ -40,5 +40,5 @@ function getSecret(prisma) {
|
|
|
40
40
|
logger.verbose("call to getSecret", { ref });
|
|
41
41
|
return yield getFn(ref);
|
|
42
42
|
});
|
|
43
|
-
return (0,
|
|
43
|
+
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.baseApiObjectSchema);
|
|
44
44
|
}
|
|
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
|
|
|
2
2
|
import { Prisma } from "../core/db";
|
|
3
3
|
declare function listSecrets(prisma: Prisma): (call: {
|
|
4
4
|
request: unknown;
|
|
5
|
-
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { listSecrets };
|
|
@@ -53,5 +53,5 @@ function listSecrets(prisma) {
|
|
|
53
53
|
nextPageToken: (_a = result[result.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
return (0, common_1.
|
|
56
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listRequestSchema);
|
|
57
57
|
}
|
|
@@ -32,6 +32,7 @@ const common_1 = require("@fonoster/common");
|
|
|
32
32
|
const identity_1 = require("@fonoster/identity");
|
|
33
33
|
const logger_1 = require("@fonoster/logger");
|
|
34
34
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
|
+
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
35
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
37
|
function updateSecret(prisma) {
|
|
37
38
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
@@ -50,5 +51,5 @@ function updateSecret(prisma) {
|
|
|
50
51
|
});
|
|
51
52
|
return { ref: call.request.ref };
|
|
52
53
|
});
|
|
53
|
-
return (0,
|
|
54
|
+
return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.listRequestSchema);
|
|
54
55
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare function withErrorHandlingAndValidationAndAccess<T, A>(handler: (call: T) => Promise<A>, getFn: (ref: string) => Promise<unknown>, schema: z.ZodSchema): (call: {
|
|
3
|
+
request: unknown;
|
|
4
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
+
export { withErrorHandlingAndValidationAndAccess };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withErrorHandlingAndValidationAndAccess = withErrorHandlingAndValidationAndAccess;
|
|
4
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (C) 2024 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 common_1 = require("@fonoster/common");
|
|
24
|
+
const identity_1 = require("@fonoster/identity");
|
|
25
|
+
function withErrorHandlingAndValidationAndAccess(handler, getFn, schema) {
|
|
26
|
+
// Start by applying access logic, then validation, and finally error handling
|
|
27
|
+
const withAccessHandler = (0, identity_1.withAccess)(handler, getFn);
|
|
28
|
+
const withValidationHandler = (0, common_1.withValidation)(withAccessHandler, schema);
|
|
29
|
+
return (0, common_1.withErrorHandling)(withValidationHandler);
|
|
30
|
+
}
|
|
@@ -139,10 +139,6 @@ class VoiceClientImpl {
|
|
|
139
139
|
bridge.addChannel({ channel: [snoopChannel.id, channel.id] });
|
|
140
140
|
}));
|
|
141
141
|
channel.once("ChannelLeftBridge", () => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
// TODO: Evaluate a better way to handle this
|
|
143
|
-
// We should keep track of the channels and bridges and destroy them
|
|
144
|
-
// even if the apiserver crashes. Otherwise we risk having a lot of
|
|
145
|
-
// unused channels and bridges.
|
|
146
142
|
try {
|
|
147
143
|
yield bridge.destroy();
|
|
148
144
|
}
|
|
@@ -36,8 +36,11 @@ const withErrorHandling_1 = require("../utils/withErrorHandling");
|
|
|
36
36
|
const gatherRequestSchema = zod_1.z.object({
|
|
37
37
|
source: zod_1.z.optional(zod_1.z.nativeEnum(common_1.GatherSource)),
|
|
38
38
|
maxDigits: zod_1.z.number().optional().nullable(),
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
finishOnKey: zod_1.z
|
|
40
|
+
.string()
|
|
41
|
+
.regex(/^[0-9*#]$/) // Ensure it's a valid DTMF character
|
|
42
|
+
.max(1)
|
|
43
|
+
.optional()
|
|
41
44
|
});
|
|
42
45
|
function gatherHandler(voiceClient) {
|
|
43
46
|
return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -14,7 +14,6 @@ const logger_1 = require("@fonoster/logger");
|
|
|
14
14
|
const zod_1 = require("zod");
|
|
15
15
|
const zod_validation_error_1 = require("zod-validation-error");
|
|
16
16
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
17
|
-
// TODO: Send error to the client and to the log system
|
|
18
17
|
function withErrorHandling(fn) {
|
|
19
18
|
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
20
19
|
try {
|
|
@@ -25,7 +25,7 @@ const Google_1 = require("./Google");
|
|
|
25
25
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
26
26
|
class SpeechToTextFactory {
|
|
27
27
|
static registerEngine(name, ctor) {
|
|
28
|
-
logger.
|
|
28
|
+
logger.verbose("registering stt engine", { name });
|
|
29
29
|
this.engines.set(name, ctor);
|
|
30
30
|
}
|
|
31
31
|
static getEngine(engineName, config) {
|
|
@@ -26,7 +26,7 @@ const Google_1 = require("./Google");
|
|
|
26
26
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
27
27
|
class TextToSpeechFactory {
|
|
28
28
|
static registerEngine(name, ctor) {
|
|
29
|
-
logger.
|
|
29
|
+
logger.verbose("registering tts engine", { name });
|
|
30
30
|
this.engines.set(name, ctor);
|
|
31
31
|
}
|
|
32
32
|
static getEngine(engineName, config) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "APIServer for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@deepgram/sdk": "^3.5.1",
|
|
24
|
-
"@fonoster/common": "^0.7.
|
|
25
|
-
"@fonoster/identity": "^0.7.
|
|
26
|
-
"@fonoster/logger": "^0.7.
|
|
27
|
-
"@fonoster/sipnet": "^0.7.
|
|
28
|
-
"@fonoster/streams": "^0.7.
|
|
29
|
-
"@fonoster/types": "^0.7.
|
|
24
|
+
"@fonoster/common": "^0.7.9",
|
|
25
|
+
"@fonoster/identity": "^0.7.9",
|
|
26
|
+
"@fonoster/logger": "^0.7.9",
|
|
27
|
+
"@fonoster/sipnet": "^0.7.9",
|
|
28
|
+
"@fonoster/streams": "^0.7.9",
|
|
29
|
+
"@fonoster/types": "^0.7.9",
|
|
30
30
|
"@google-cloud/speech": "^6.6.0",
|
|
31
31
|
"@google-cloud/text-to-speech": "^5.3.0",
|
|
32
32
|
"@grpc/grpc-js": "~1.10.6",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"@types/uuid": "^9.0.8",
|
|
72
72
|
"@types/validator": "^13.12.0"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "3b16a5ed87b84d03534bb20de4d59d5bbb51a742"
|
|
75
75
|
}
|