@fonoster/apiserver 0.7.4 → 0.7.5
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/README.md +2 -2
- package/dist/applications/buildService.d.ts +10 -12
- package/dist/applications/createApplication.d.ts +2 -3
- package/dist/applications/createApplication.js +13 -16
- package/dist/applications/createGetFnUtil.d.ts +3 -3
- package/dist/applications/deleteApplication.d.ts +2 -3
- package/dist/applications/deleteApplication.js +4 -2
- package/dist/applications/getApplication.d.ts +2 -3
- package/dist/applications/getApplication.js +4 -2
- package/dist/applications/listApplications.d.ts +2 -3
- package/dist/applications/listApplications.js +18 -22
- package/dist/applications/updateApplication.d.ts +2 -5
- package/dist/applications/updateApplication.js +4 -2
- package/dist/applications/utils/getApplicationValidationSchema.js +2 -2
- package/dist/calls/buildService.d.ts +6 -6
- package/dist/calls/createCall.d.ts +3 -4
- package/dist/calls/createCall.js +22 -27
- package/dist/calls/getCall.d.ts +3 -3
- package/dist/calls/getCall.js +10 -15
- package/dist/calls/listCalls.d.ts +3 -3
- package/dist/calls/listCalls.js +8 -12
- package/dist/calls/makeTrackCall.d.ts +2 -2
- package/dist/calls/makeTrackCall.js +1 -2
- package/dist/calls/types.d.ts +1 -1
- package/dist/calls/types.js +1 -1
- package/dist/core/db.d.ts +1 -1
- package/dist/core/services.d.ts +105 -146
- package/dist/envs.d.ts +33 -33
- package/dist/envs.js +40 -40
- package/dist/events/createInfluxDbPub.d.ts +1 -1
- package/dist/events/nats.js +0 -1
- package/dist/events/types.d.ts +1 -1
- package/dist/secrets/buildService.d.ts +10 -12
- package/dist/secrets/createSecret.d.ts +2 -3
- package/dist/secrets/createSecret.js +10 -14
- package/dist/secrets/deleteSecret.d.ts +2 -3
- package/dist/secrets/deleteSecret.js +4 -2
- package/dist/secrets/getSecret.d.ts +2 -3
- package/dist/secrets/getSecret.js +4 -2
- package/dist/secrets/listSecrets.d.ts +2 -3
- package/dist/secrets/listSecrets.js +12 -16
- package/dist/secrets/updateSecret.d.ts +2 -5
- package/dist/secrets/updateSecret.js +4 -2
- package/dist/voice/handlers/Say.js +0 -1
- package/dist/voice/handlers/Stream.js +0 -1
- package/dist/voice/handlers/StreamGather.js +0 -1
- package/dist/voice/handlers/gather/Gather.js +0 -1
- package/dist/voice/handlers/index.d.ts +5 -5
- package/dist/voice/handlers/index.js +5 -5
- package/dist/voice/integrations/types.d.ts +1 -1
- package/dist/voice/stt/Google.d.ts +1 -1
- package/dist/voice/stt/Google.js +1 -1
- package/dist/voice/stt/types.d.ts +6 -6
- package/dist/voice/tts/Google.d.ts +1 -1
- package/dist/voice/tts/Google.js +1 -1
- package/dist/voice/tts/types.d.ts +1 -1
- package/dist/voice/types/voice.d.ts +1 -1
- package/package.json +8 -8
- package/dist/applications/hostOrHostPortSchema.d.ts +0 -3
- package/dist/applications/hostOrHostPortSchema.js +0 -34
- package/dist/calls/ListCallsRequestSchema.d.ts +0 -25
- package/dist/calls/ListCallsRequestSchema.js +0 -54
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://discord.gg/4QWgSz4hTC)  
|
|
2
2
|
|
|
3
|
-
This module is part of the [Fonoster](https://fonoster.com)
|
|
3
|
+
This module is part of the [Fonoster](https://fonoster.com) open-source. By itself, it does not do much. It is intended to be used as a dependency for other modules. For more information about the project, please visit [https://github.com/fonoster/fonoster](https://github.com/fonoster/fonoster).
|
|
@@ -8,22 +8,20 @@ declare function buildService(prisma: Prisma): {
|
|
|
8
8
|
};
|
|
9
9
|
handlers: {
|
|
10
10
|
createApplication: (call: {
|
|
11
|
-
request:
|
|
12
|
-
}, callback: (error
|
|
11
|
+
request: unknown;
|
|
12
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
13
13
|
getApplication: (call: {
|
|
14
|
-
request:
|
|
15
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
14
|
+
request: unknown;
|
|
15
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
16
16
|
listApplications: (call: {
|
|
17
|
-
request:
|
|
18
|
-
}, callback: (error
|
|
17
|
+
request: unknown;
|
|
18
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
19
19
|
deleteApplication: (call: {
|
|
20
|
-
request:
|
|
21
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
20
|
+
request: unknown;
|
|
21
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
22
22
|
updateApplication: (call: {
|
|
23
|
-
request:
|
|
24
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
25
|
-
ref: string;
|
|
26
|
-
}) => void) => Promise<void>;
|
|
23
|
+
request: unknown;
|
|
24
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
27
25
|
};
|
|
28
26
|
};
|
|
29
27
|
export { buildService };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
-
import { BaseApiObject, CreateApplicationRequest } from "@fonoster/types";
|
|
3
2
|
import { Prisma } from "../core/db";
|
|
4
3
|
declare function createApplication(prisma: Prisma): (call: {
|
|
5
|
-
request:
|
|
6
|
-
}, callback: (error
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
6
|
export { createApplication };
|
|
@@ -35,22 +35,19 @@ const convertToApplicationData_1 = require("./utils/convertToApplicationData");
|
|
|
35
35
|
const validOrThrow_1 = require("./utils/validOrThrow");
|
|
36
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
37
37
|
function createApplication(prisma) {
|
|
38
|
-
|
|
39
|
-
const {
|
|
38
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { request } = call;
|
|
40
|
+
const { type } = request;
|
|
40
41
|
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return callback(null, { ref: result.ref });
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
(0, common_1.handleError)(error, callback);
|
|
54
|
-
}
|
|
42
|
+
logger.verbose("call to createApplication", {
|
|
43
|
+
accessKeyId,
|
|
44
|
+
type
|
|
45
|
+
});
|
|
46
|
+
(0, validOrThrow_1.validOrThrow)(request);
|
|
47
|
+
const result = yield prisma.application.create({
|
|
48
|
+
data: Object.assign(Object.assign({}, (0, convertToApplicationData_1.convertToApplicationData)(request)), { accessKeyId })
|
|
49
|
+
});
|
|
50
|
+
callback(null, { ref: result.ref });
|
|
55
51
|
});
|
|
52
|
+
return (0, common_1.withErrorHandling)(fn);
|
|
56
53
|
}
|
|
@@ -5,20 +5,20 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
|
|
|
5
5
|
};
|
|
6
6
|
textToSpeech: {
|
|
7
7
|
ref: string;
|
|
8
|
-
config: import("
|
|
8
|
+
config: import("@prisma/client/runtime/library").JsonValue;
|
|
9
9
|
applicationRef: string;
|
|
10
10
|
productRef: string;
|
|
11
11
|
};
|
|
12
12
|
speechToText: {
|
|
13
13
|
ref: string;
|
|
14
|
-
config: import("
|
|
14
|
+
config: import("@prisma/client/runtime/library").JsonValue;
|
|
15
15
|
applicationRef: string;
|
|
16
16
|
productRef: string;
|
|
17
17
|
};
|
|
18
18
|
intelligence: {
|
|
19
19
|
ref: string;
|
|
20
20
|
credentials: string;
|
|
21
|
-
config: import("
|
|
21
|
+
config: import("@prisma/client/runtime/library").JsonValue;
|
|
22
22
|
applicationRef: string;
|
|
23
23
|
productRef: string;
|
|
24
24
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BaseApiObject } from "@fonoster/types";
|
|
2
1
|
import { Prisma } from "../core/db";
|
|
3
2
|
declare function deleteApplication(prisma: Prisma): (call: {
|
|
4
|
-
request:
|
|
5
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
3
|
+
request: unknown;
|
|
4
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
5
|
export { deleteApplication };
|
|
@@ -28,16 +28,18 @@ exports.deleteApplication = deleteApplication;
|
|
|
28
28
|
* See the License for the specific language governing permissions and
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
|
+
const common_1 = require("@fonoster/common");
|
|
31
32
|
const identity_1 = require("@fonoster/identity");
|
|
32
33
|
const logger_1 = require("@fonoster/logger");
|
|
33
34
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
34
35
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
35
36
|
function deleteApplication(prisma) {
|
|
36
37
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
37
|
-
|
|
38
|
+
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
38
39
|
const { ref } = call.request;
|
|
39
40
|
logger.verbose("call to deleteApplication", { ref });
|
|
40
41
|
yield prisma.application.delete({ where: { ref } });
|
|
41
42
|
return { ref };
|
|
42
|
-
})
|
|
43
|
+
});
|
|
44
|
+
return (0, common_1.withErrorHandling)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)));
|
|
43
45
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Application, BaseApiObject } from "@fonoster/types";
|
|
2
1
|
import { Prisma } from "../core/db";
|
|
3
2
|
declare function getApplication(prisma: Prisma): (call: {
|
|
4
|
-
request:
|
|
5
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
3
|
+
request: unknown;
|
|
4
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
5
|
export { getApplication };
|
|
@@ -28,6 +28,7 @@ exports.getApplication = getApplication;
|
|
|
28
28
|
* See the License for the specific language governing permissions and
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
|
+
const common_1 = require("@fonoster/common");
|
|
31
32
|
const identity_1 = require("@fonoster/identity");
|
|
32
33
|
const logger_1 = require("@fonoster/logger");
|
|
33
34
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
@@ -35,10 +36,11 @@ const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedSt
|
|
|
35
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
37
|
function getApplication(prisma) {
|
|
37
38
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(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 getApplication", { ref });
|
|
41
42
|
const result = yield getFn(ref);
|
|
42
43
|
return result ? (0, applicationWithEncodedStruct_1.applicationWithEncodedStruct)(result) : null;
|
|
43
|
-
})
|
|
44
|
+
});
|
|
45
|
+
return (0, common_1.withErrorHandling)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)));
|
|
44
46
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
-
import { ListApplicationsRequest, ListApplicationsResponse } from "@fonoster/types";
|
|
3
2
|
import { Prisma } from "../core/db";
|
|
4
3
|
declare function listApplications(prisma: Prisma): (call: {
|
|
5
|
-
request:
|
|
6
|
-
}, callback: (error
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
6
|
export { listApplications };
|
|
@@ -34,7 +34,7 @@ const logger_1 = require("@fonoster/logger");
|
|
|
34
34
|
const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
|
|
35
35
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
36
36
|
function listApplications(prisma) {
|
|
37
|
-
|
|
37
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
var _a;
|
|
39
39
|
const { pageSize, pageToken } = call.request;
|
|
40
40
|
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
@@ -43,26 +43,22 @@ function listApplications(prisma) {
|
|
|
43
43
|
pageSize,
|
|
44
44
|
pageToken
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
(0, common_1.handleError)(error, callback);
|
|
66
|
-
}
|
|
46
|
+
const result = yield prisma.application.findMany({
|
|
47
|
+
where: { accessKeyId },
|
|
48
|
+
include: {
|
|
49
|
+
textToSpeech: true,
|
|
50
|
+
speechToText: true,
|
|
51
|
+
intelligence: true
|
|
52
|
+
},
|
|
53
|
+
take: pageSize,
|
|
54
|
+
skip: pageToken ? 1 : 0,
|
|
55
|
+
cursor: pageToken ? { ref: pageToken } : undefined
|
|
56
|
+
});
|
|
57
|
+
const items = result.map(applicationWithEncodedStruct_1.applicationWithEncodedStruct);
|
|
58
|
+
callback(null, {
|
|
59
|
+
items,
|
|
60
|
+
nextPageToken: (_a = result[result.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
|
|
61
|
+
});
|
|
67
62
|
});
|
|
63
|
+
return (0, common_1.withErrorHandling)(fn);
|
|
68
64
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { UpdateApplicationRequest } from "@fonoster/types";
|
|
2
1
|
import { Prisma } from "../core/db";
|
|
3
2
|
declare function updateApplication(prisma: Prisma): (call: {
|
|
4
|
-
request:
|
|
5
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
6
|
-
ref: string;
|
|
7
|
-
}) => void) => Promise<void>;
|
|
3
|
+
request: unknown;
|
|
4
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
8
5
|
export { updateApplication };
|
|
@@ -28,6 +28,7 @@ exports.updateApplication = updateApplication;
|
|
|
28
28
|
* See the License for the specific language governing permissions and
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
|
+
const common_1 = require("@fonoster/common");
|
|
31
32
|
const identity_1 = require("@fonoster/identity");
|
|
32
33
|
const logger_1 = require("@fonoster/logger");
|
|
33
34
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
@@ -36,7 +37,7 @@ const validOrThrow_1 = require("./utils/validOrThrow");
|
|
|
36
37
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
37
38
|
function updateApplication(prisma) {
|
|
38
39
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
39
|
-
|
|
40
|
+
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
40
41
|
const { type, ref: applicationRef } = call.request;
|
|
41
42
|
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
42
43
|
(0, validOrThrow_1.validOrThrow)(call.request);
|
|
@@ -70,5 +71,6 @@ function updateApplication(prisma) {
|
|
|
70
71
|
})
|
|
71
72
|
]);
|
|
72
73
|
return { ref: applicationRef };
|
|
73
|
-
})
|
|
74
|
+
});
|
|
75
|
+
return (0, common_1.withErrorHandling)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)));
|
|
74
76
|
}
|
|
@@ -19,6 +19,7 @@ exports.getApplicationValidationSchema = getApplicationValidationSchema;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
const common_1 = require("@fonoster/common");
|
|
22
23
|
const client_1 = require("@prisma/client");
|
|
23
24
|
const zod_1 = require("zod");
|
|
24
25
|
const Deepgram_1 = require("../../voice/stt/Deepgram");
|
|
@@ -26,7 +27,6 @@ const Google_1 = require("../../voice/stt/Google");
|
|
|
26
27
|
const Azure_1 = require("../../voice/tts/Azure");
|
|
27
28
|
const Deepgram_2 = require("../../voice/tts/Deepgram");
|
|
28
29
|
const Google_2 = require("../../voice/tts/Google");
|
|
29
|
-
const hostOrHostPortSchema_1 = require("../hostOrHostPortSchema");
|
|
30
30
|
// TODO: We need a way to add this values dynamically
|
|
31
31
|
const validators = {
|
|
32
32
|
ttsConfigValidators: {
|
|
@@ -53,7 +53,7 @@ function getApplicationValidationSchema(request) {
|
|
|
53
53
|
return zod_1.z.object({
|
|
54
54
|
name: zod_1.z.string(),
|
|
55
55
|
type: zod_1.z.nativeEnum(client_1.ApplicationType),
|
|
56
|
-
endpoint:
|
|
56
|
+
endpoint: common_1.hostOrHostPortSchema,
|
|
57
57
|
textToSpeech: ttsEngineName
|
|
58
58
|
? zod_1.z.object({
|
|
59
59
|
productRef: zod_1.z.string(),
|
|
@@ -8,14 +8,14 @@ declare function buildService(influxdb: InfluxDBClient): Promise<{
|
|
|
8
8
|
};
|
|
9
9
|
handlers: {
|
|
10
10
|
createCall: (call: {
|
|
11
|
-
request:
|
|
12
|
-
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?:
|
|
11
|
+
request: unknown;
|
|
12
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
13
13
|
listCalls: (call: {
|
|
14
|
-
request:
|
|
15
|
-
}, callback: (error
|
|
14
|
+
request: unknown;
|
|
15
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
16
16
|
getCall: (call: {
|
|
17
|
-
request:
|
|
18
|
-
}, callback: (error
|
|
17
|
+
request: unknown;
|
|
18
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
19
19
|
trackCall: (call: {
|
|
20
20
|
request: {
|
|
21
21
|
ref?: string;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CreateCallRequest } from "@fonoster/types";
|
|
1
|
+
import { GrpcErrorMessage } from "@fonoster/common";
|
|
3
2
|
import { CallPublisher } from "./types";
|
|
4
3
|
import { Prisma } from "../core/db";
|
|
5
4
|
declare function createCall(prisma: Prisma, publisher: CallPublisher): (call: {
|
|
6
|
-
request:
|
|
7
|
-
}, callback: (error?: GrpcErrorMessage, response?:
|
|
5
|
+
request: unknown;
|
|
6
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
8
7
|
export { createCall };
|
package/dist/calls/createCall.js
CHANGED
|
@@ -35,39 +35,34 @@ const uuid_1 = require("uuid");
|
|
|
35
35
|
const zod_1 = require("zod");
|
|
36
36
|
const notFoundError_1 = require("../core/notFoundError");
|
|
37
37
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
|
-
const
|
|
38
|
+
const createCallRequestSchema = zod_1.z.object({
|
|
39
39
|
from: zod_1.z.string(),
|
|
40
40
|
to: zod_1.z.string(),
|
|
41
41
|
appRef: zod_1.z.string(),
|
|
42
42
|
timeout: zod_1.z.number().optional()
|
|
43
43
|
});
|
|
44
44
|
function createCall(prisma, publisher) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found`);
|
|
57
|
-
}
|
|
58
|
-
// TODO: Must validate that the from number exists and is owned by the user
|
|
59
|
-
publisher.publishCall({
|
|
60
|
-
ref,
|
|
61
|
-
from,
|
|
62
|
-
to,
|
|
63
|
-
appRef,
|
|
64
|
-
accessKeyId,
|
|
65
|
-
timeout: timeout || 60
|
|
66
|
-
});
|
|
67
|
-
callback(null, { ref });
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
(0, common_1.handleError)(error, callback);
|
|
45
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const { request } = call;
|
|
47
|
+
const { from, to, appRef, timeout } = request;
|
|
48
|
+
const ref = (0, uuid_1.v4)();
|
|
49
|
+
logger.verbose("call to createCall", Object.assign(Object.assign({}, request), { ref }));
|
|
50
|
+
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
51
|
+
const app = yield prisma.application.findUnique({
|
|
52
|
+
where: { ref: appRef, accessKeyId }
|
|
53
|
+
});
|
|
54
|
+
if (!app) {
|
|
55
|
+
throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found`);
|
|
71
56
|
}
|
|
57
|
+
publisher.publishCall({
|
|
58
|
+
ref,
|
|
59
|
+
from,
|
|
60
|
+
to,
|
|
61
|
+
appRef,
|
|
62
|
+
accessKeyId,
|
|
63
|
+
timeout: timeout || 60
|
|
64
|
+
});
|
|
65
|
+
callback(null, { ref });
|
|
72
66
|
});
|
|
67
|
+
return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, createCallRequestSchema));
|
|
73
68
|
}
|
package/dist/calls/getCall.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
-
import {
|
|
2
|
+
import { InfluxDBClient } from "./types";
|
|
3
3
|
declare function getCall(influx: InfluxDBClient): (call: {
|
|
4
|
-
request:
|
|
5
|
-
}, callback: (error
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { getCall };
|
package/dist/calls/getCall.js
CHANGED
|
@@ -35,25 +35,20 @@ const zod_1 = require("zod");
|
|
|
35
35
|
const createFetchSingleCall_1 = require("./createFetchSingleCall");
|
|
36
36
|
const notFoundError_1 = require("../core/notFoundError");
|
|
37
37
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
|
-
const
|
|
38
|
+
const getCallRequestSchema = zod_1.z.object({
|
|
39
39
|
ref: zod_1.z.string({ message: "Invalid call reference" })
|
|
40
40
|
});
|
|
41
41
|
function getCall(influx) {
|
|
42
42
|
const fetchSingleCall = (0, createFetchSingleCall_1.createFetchSingleCall)(influx);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!response) {
|
|
51
|
-
throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`);
|
|
52
|
-
}
|
|
53
|
-
callback(null, response);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
(0, common_1.handleError)(error, callback);
|
|
43
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const { ref } = call.request;
|
|
45
|
+
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
46
|
+
logger.verbose("call to getCall", { accessKeyId, ref });
|
|
47
|
+
const response = yield fetchSingleCall(accessKeyId, ref);
|
|
48
|
+
if (!response) {
|
|
49
|
+
throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`);
|
|
57
50
|
}
|
|
51
|
+
callback(null, response);
|
|
58
52
|
});
|
|
53
|
+
return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, getCallRequestSchema));
|
|
59
54
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
-
import { InfluxDBClient
|
|
2
|
+
import { InfluxDBClient } from "./types";
|
|
3
3
|
declare function listCalls(influx: InfluxDBClient): (call: {
|
|
4
|
-
request:
|
|
5
|
-
}, callback: (error
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
6
|
export { listCalls };
|
package/dist/calls/listCalls.js
CHANGED
|
@@ -29,23 +29,19 @@ 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");
|
|
32
33
|
const identity_1 = require("@fonoster/identity");
|
|
33
34
|
const logger_1 = require("@fonoster/logger");
|
|
34
35
|
const createFetchCalls_1 = require("./createFetchCalls");
|
|
35
|
-
const ListCallsRequestSchema_1 = require("./ListCallsRequestSchema");
|
|
36
36
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
37
37
|
function listCalls(influx) {
|
|
38
38
|
const fetchCalls = (0, createFetchCalls_1.createFetchCalls)(influx);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
callback(null, result);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
(0, common_1.handleError)(error, callback);
|
|
49
|
-
}
|
|
39
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const { request } = call;
|
|
41
|
+
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
42
|
+
logger.verbose("call to listCalls", { request, accessKeyId });
|
|
43
|
+
const result = yield fetchCalls(accessKeyId, request);
|
|
44
|
+
callback(null, result);
|
|
50
45
|
});
|
|
46
|
+
return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, listCallsRequestSchema_1.listCallsRequestSchema));
|
|
51
47
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { NatsConnection } from "nats";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
declare const
|
|
3
|
+
declare const trackCallRequestSchema: z.ZodObject<{
|
|
4
4
|
ref: z.ZodString;
|
|
5
5
|
}, "strip", z.ZodTypeAny, {
|
|
6
6
|
ref?: string;
|
|
7
7
|
}, {
|
|
8
8
|
ref?: string;
|
|
9
9
|
}>;
|
|
10
|
-
type TrackCallRequest = z.infer<typeof
|
|
10
|
+
type TrackCallRequest = z.infer<typeof trackCallRequestSchema>;
|
|
11
11
|
declare function makeTrackCall(nc: NatsConnection): (call: {
|
|
12
12
|
request: TrackCallRequest;
|
|
13
13
|
}) => void;
|
|
@@ -24,13 +24,12 @@ const logger_1 = require("@fonoster/logger");
|
|
|
24
24
|
const zod_1 = require("zod");
|
|
25
25
|
const envs_1 = require("../envs");
|
|
26
26
|
const FINAL_STATUSES = [
|
|
27
|
-
common_1.DialStatus.ANSWER,
|
|
28
27
|
common_1.DialStatus.BUSY,
|
|
29
28
|
common_1.DialStatus.FAILED,
|
|
30
29
|
common_1.DialStatus.NOANSWER
|
|
31
30
|
];
|
|
32
31
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
33
|
-
const
|
|
32
|
+
const trackCallRequestSchema = zod_1.z.object({
|
|
34
33
|
ref: zod_1.z.string()
|
|
35
34
|
});
|
|
36
35
|
function makeTrackCall(nc) {
|
package/dist/calls/types.d.ts
CHANGED
|
@@ -59,4 +59,4 @@ type TrackCallSubscriber = {
|
|
|
59
59
|
on: (event: string, cb: (data: TrackCallResponse | Error) => void) => void;
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
|
-
export { CALL_DETAIL_RECORD_MEASUREMENT, CallDetailRecord,
|
|
62
|
+
export { CALL_DETAIL_RECORD_MEASUREMENT, CallDetailRecord, CallDirection, CallPublisher, CallStatus, CallStream, CallType, CreateCallRequest, GetCallRequest, InfluxDBClient, ListCallsRequest, ListCallsResponse, TrackCallResponse, TrackCallSubscriber };
|
package/dist/calls/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CallType = exports.CallStatus = exports.CallDirection = exports.CALL_DETAIL_RECORD_MEASUREMENT = void 0;
|
|
4
4
|
const types_1 = require("@fonoster/types");
|
|
5
5
|
Object.defineProperty(exports, "CallDirection", { enumerable: true, get: function () { return types_1.CallDirection; } });
|
|
6
6
|
Object.defineProperty(exports, "CallStatus", { enumerable: true, get: function () { return types_1.CallStatus; } });
|
package/dist/core/db.d.ts
CHANGED