@fonoster/common 0.5.5 → 0.6.1-alpha.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/LICENSE +2 -2
- package/README.md +3 -0
- package/dist/GrpcError.d.ts +5 -0
- package/dist/{speech/plugin.js → GrpcError.js} +8 -12
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +6 -0
- package/dist/errors/PrismaErrorEnum.d.ts +6 -0
- package/dist/{envs.js → errors/PrismaErrorEnum.js} +8 -6
- package/dist/errors/handleError.d.ts +6 -0
- package/dist/errors/handleError.js +86 -0
- package/dist/errors/handleZodError.d.ts +4 -0
- package/dist/errors/handleZodError.js +41 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +38 -0
- package/dist/errors/types.d.ts +5 -0
- package/dist/grpcStatusMap.d.ts +4 -0
- package/dist/grpcStatusMap.js +27 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +41 -14
- package/dist/notifications/compileTemplate.d.ts +6 -0
- package/dist/{env_is_set.js → notifications/compileTemplate.js} +12 -14
- package/dist/notifications/createEmailSender.d.ts +17 -0
- package/dist/notifications/createEmailSender.js +55 -0
- package/dist/notifications/index.d.ts +2 -0
- package/dist/notifications/index.js +36 -0
- package/dist/protos/acls.proto +119 -0
- package/dist/protos/agents.proto +155 -0
- package/dist/protos/applications.proto +154 -0
- package/dist/protos/calls.proto +164 -0
- package/dist/protos/credentials.proto +119 -0
- package/dist/protos/domains.proto +127 -0
- package/dist/protos/identity.proto +286 -0
- package/dist/protos/numbers.proto +152 -0
- package/dist/protos/secrets.proto +113 -0
- package/dist/protos/trunks.proto +164 -0
- package/dist/protos/voice.proto +421 -0
- package/dist/tts/AzureVoices.d.ts +523 -0
- package/dist/tts/AzureVoices.js +3622 -0
- package/dist/tts/GoogleVoices.d.ts +475 -0
- package/dist/tts/GoogleVoices.js +3284 -0
- package/dist/tts/index.d.ts +3 -0
- package/dist/tts/index.js +37 -0
- package/dist/tts/types.d.ts +164 -0
- package/dist/tts/types.js +186 -0
- package/dist/types/applications.d.ts +57 -0
- package/dist/types/applications.js +7 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +35 -0
- package/dist/types.d.ts +8 -6
- package/dist/utils/assertEnvsAreSet.d.ts +7 -0
- package/dist/utils/assertEnvsAreSet.js +37 -0
- package/dist/utils/assertFileExists.d.ts +5 -0
- package/dist/utils/assertFileExists.js +38 -0
- package/dist/utils/createInterceptingCall.d.ts +7 -0
- package/dist/utils/createInterceptingCall.js +9 -0
- package/dist/utils/createService.d.ts +9 -0
- package/dist/{service_runner.js → utils/createService.js} +15 -40
- package/dist/utils/datesMapper.d.ts +9 -0
- package/dist/utils/datesMapper.js +8 -0
- package/dist/utils/getServerCredentials.d.ts +10 -0
- package/dist/{trust_util.js → utils/getServerCredentials.js} +33 -37
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +42 -0
- package/dist/utils/toCamelCase.d.ts +2 -0
- package/dist/utils/toCamelCase.js +27 -0
- package/dist/utils/toPascalCase.d.ts +2 -0
- package/dist/utils/toPascalCase.js +29 -0
- package/dist/voice/Dial.d.ts +23 -0
- package/dist/voice/Dial.js +19 -0
- package/dist/voice/Gather.d.ts +18 -0
- package/dist/voice/Gather.js +9 -0
- package/dist/voice/Mute.d.ts +13 -0
- package/dist/voice/Mute.js +9 -0
- package/dist/voice/Play.d.ts +12 -0
- package/dist/voice/Play.js +2 -0
- package/dist/voice/PlayDtmf.d.ts +5 -0
- package/dist/voice/PlayDtmf.js +2 -0
- package/dist/voice/PlaybackControl.d.ts +13 -0
- package/dist/voice/PlaybackControl.js +11 -0
- package/dist/voice/Record.d.ts +18 -0
- package/dist/voice/Record.js +7 -0
- package/dist/voice/Say.d.ts +15 -0
- package/dist/voice/Say.js +2 -0
- package/dist/voice/Stream.d.ts +41 -0
- package/dist/voice/Stream.js +39 -0
- package/dist/voice/Verb.d.ts +9 -0
- package/dist/{healthcheck.js → voice/Verb.js} +2 -5
- package/dist/voice/index.d.ts +11 -0
- package/dist/voice/index.js +45 -0
- package/dist/voice/voice.d.ts +101 -0
- package/dist/voice/voice.js +44 -0
- package/package.json +29 -25
- package/dist/api_client.d.ts +0 -27
- package/dist/api_client.js +0 -110
- package/dist/env_is_set.d.ts +0 -1
- package/dist/envs.d.ts +0 -4
- package/dist/healthcheck.d.ts +0 -2
- package/dist/service_runner.d.ts +0 -13
- package/dist/speech/plugin.d.ts +0 -6
- package/dist/speech/types.d.ts +0 -17
- package/dist/trust_util.d.ts +0 -4
- /package/dist/{speech → errors}/types.js +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Fonoster Inc
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<a href="https://gitpod.io/#https://github.com/fonoster/fonoster"> <img src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod" alt="Contribute with Gitpod" />
|
|
2
|
+
|
|
3
|
+
This module is part of the \[Fonoster\](https://fonoster.com) project. 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).a](../apiserver/README.md)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GrpcError = void 0;
|
|
4
4
|
/*
|
|
5
|
-
* Copyright (C)
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
7
7
|
*
|
|
8
8
|
* This file is part of Fonoster
|
|
@@ -19,15 +19,11 @@ exports.Plugin = void 0;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
class
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
this.type = type;
|
|
28
|
-
}
|
|
29
|
-
getType() {
|
|
30
|
-
return this.type;
|
|
22
|
+
class GrpcError extends Error {
|
|
23
|
+
constructor(code, message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.code = code;
|
|
26
|
+
Object.setPrototypeOf(this, GrpcError.prototype);
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
|
-
exports.
|
|
29
|
+
exports.GrpcError = GrpcError;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STASIS_APP_NAME = exports.GRPC_NOT_SERVING_STATUS = exports.GRPC_SERVING_STATUS = void 0;
|
|
4
|
+
exports.GRPC_SERVING_STATUS = "SERVING";
|
|
5
|
+
exports.GRPC_NOT_SERVING_STATUS = "NOT_SERVING";
|
|
6
|
+
exports.STASIS_APP_NAME = "mediacontroller";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PrismaErrorEnum = void 0;
|
|
4
4
|
/*
|
|
5
|
-
* Copyright (C)
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
7
7
|
*
|
|
8
8
|
* This file is part of Fonoster
|
|
@@ -19,7 +19,9 @@ exports.GRPC_ALLOW_INSECURE = exports.APISERVER_ACCESS_KEY_SECRET = exports.APIS
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
var PrismaErrorEnum;
|
|
23
|
+
(function (PrismaErrorEnum) {
|
|
24
|
+
PrismaErrorEnum["RECORD_ALREADY_EXISTS"] = "P2002";
|
|
25
|
+
PrismaErrorEnum["RECORD_NOT_FOUND"] = "P2025";
|
|
26
|
+
PrismaErrorEnum["FAILED_PRECONDITION"] = "P2003";
|
|
27
|
+
})(PrismaErrorEnum || (exports.PrismaErrorEnum = PrismaErrorEnum = {}));
|
|
@@ -0,0 +1,86 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.handleError = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster/fonoster
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Fonoster
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License");
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
const logger_1 = require("@fonoster/logger");
|
|
46
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
47
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
48
|
+
const zod_1 = require("zod");
|
|
49
|
+
const handleZodError_1 = require("./handleZodError");
|
|
50
|
+
const PrismaErrorEnum_1 = require("./PrismaErrorEnum");
|
|
51
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
52
|
+
function handleError(error, callback) {
|
|
53
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
54
|
+
(0, handleZodError_1.handleZodError)(error, callback);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const { code, message } = error;
|
|
58
|
+
const logAndCallback = (errorCode, errorMessage, logMessage) => {
|
|
59
|
+
logger.error(logMessage, { message: errorMessage });
|
|
60
|
+
callback({ code: errorCode, message: errorMessage });
|
|
61
|
+
};
|
|
62
|
+
switch (code) {
|
|
63
|
+
case PrismaErrorEnum_1.PrismaErrorEnum.RECORD_ALREADY_EXISTS:
|
|
64
|
+
case grpc.status.ALREADY_EXISTS:
|
|
65
|
+
logAndCallback(grpc_js_1.status.ALREADY_EXISTS, message || "Duplicated resource", "duplicated entity error");
|
|
66
|
+
break;
|
|
67
|
+
case PrismaErrorEnum_1.PrismaErrorEnum.RECORD_NOT_FOUND:
|
|
68
|
+
case grpc.status.NOT_FOUND:
|
|
69
|
+
logAndCallback(grpc_js_1.status.NOT_FOUND, message || "The requested resource was not found", "not found error");
|
|
70
|
+
break;
|
|
71
|
+
case PrismaErrorEnum_1.PrismaErrorEnum.FAILED_PRECONDITION:
|
|
72
|
+
case grpc.status.FAILED_PRECONDITION:
|
|
73
|
+
logAndCallback(grpc_js_1.status.FAILED_PRECONDITION, message || "Failed precondition error (e.g., missing dependency)", "failed precondition error");
|
|
74
|
+
break;
|
|
75
|
+
case grpc.status.PERMISSION_DENIED:
|
|
76
|
+
logAndCallback(grpc_js_1.status.PERMISSION_DENIED, message || "Permission denied", "permission denied error");
|
|
77
|
+
break;
|
|
78
|
+
case grpc.status.UNAUTHENTICATED:
|
|
79
|
+
logAndCallback(grpc_js_1.status.UNAUTHENTICATED, message || "Unauthenticated", "unauthenticated error");
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
logger.error("unknown error:", error);
|
|
83
|
+
callback({ code: grpc_js_1.status.UNKNOWN, message: message || "Unknown error" });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.handleError = handleError;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleZodError = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const logger_1 = require("@fonoster/logger");
|
|
23
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
24
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
|
25
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
26
|
+
function handleZodError(error, callback) {
|
|
27
|
+
if ((error === null || error === void 0 ? void 0 : error.issues[0].code) === "custom") {
|
|
28
|
+
const message = error === null || error === void 0 ? void 0 : error.issues[0].message;
|
|
29
|
+
logger.error("custom validation error", { message });
|
|
30
|
+
callback({ code: grpc_js_1.status.INVALID_ARGUMENT, message });
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const validationError = (0, zod_validation_error_1.fromError)(error);
|
|
34
|
+
logger.error("validation error", { message: validationError.toString() });
|
|
35
|
+
callback({
|
|
36
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
37
|
+
message: validationError.toString()
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.handleZodError = handleZodError;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Fonoster
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the MIT License (the "License");
|
|
24
|
+
* you may not use this file except in compliance with
|
|
25
|
+
* the License. You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* https://opensource.org/licenses/MIT
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./handleError"), exports);
|
|
36
|
+
__exportStar(require("./PrismaErrorEnum"), exports);
|
|
37
|
+
__exportStar(require("./handleZodError"), exports);
|
|
38
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statusMap = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const constants_1 = require("./constants");
|
|
23
|
+
const statusMap = {
|
|
24
|
+
// By convention, the empty string represents the entire server
|
|
25
|
+
"": constants_1.GRPC_NOT_SERVING_STATUS
|
|
26
|
+
};
|
|
27
|
+
exports.statusMap = statusMap;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
1
|
+
export * from "./utils";
|
|
2
|
+
export * from "./notifications";
|
|
3
|
+
export * from "./errors";
|
|
4
|
+
export * from "./constants";
|
|
5
|
+
export * from "./grpcStatusMap";
|
|
6
|
+
export * from "./voice";
|
|
7
|
+
export * from "./tts";
|
|
8
|
+
export * from "./types/";
|
|
9
|
+
export * from "./types";
|
|
10
|
+
export * from "./GrpcError";
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Fonoster
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the MIT License (the "License");
|
|
24
|
+
* you may not use this file except in compliance with
|
|
25
|
+
* the License. You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* https://opensource.org/licenses/MIT
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./utils"), exports);
|
|
36
|
+
__exportStar(require("./notifications"), exports);
|
|
37
|
+
__exportStar(require("./errors"), exports);
|
|
38
|
+
__exportStar(require("./constants"), exports);
|
|
39
|
+
__exportStar(require("./grpcStatusMap"), exports);
|
|
40
|
+
__exportStar(require("./voice"), exports);
|
|
41
|
+
__exportStar(require("./tts"), exports);
|
|
42
|
+
__exportStar(require("./types/"), exports);
|
|
43
|
+
__exportStar(require("./types"), exports);
|
|
44
|
+
__exportStar(require("./GrpcError"), exports);
|
|
@@ -3,8 +3,9 @@ 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.compileTemplate = void 0;
|
|
6
7
|
/*
|
|
7
|
-
* Copyright (C)
|
|
8
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
8
9
|
* http://github.com/fonoster/fonoster
|
|
9
10
|
*
|
|
10
11
|
* This file is part of Fonoster
|
|
@@ -21,18 +22,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
22
|
* See the License for the specific language governing permissions and
|
|
22
23
|
* limitations under the License.
|
|
23
24
|
*/
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value.env.forEach(function (variable) {
|
|
31
|
-
if (!(variable in process.env)) {
|
|
32
|
-
logger_1.default.error(`The environment variable ${variable} is required but was not found`);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
25
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
27
|
+
function compileTemplate(params) {
|
|
28
|
+
const { filePath, data } = params;
|
|
29
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
30
|
+
throw new Error(`Template file not found: ${filePath}`);
|
|
36
31
|
}
|
|
32
|
+
const source = fs_1.default.readFileSync(filePath, "utf-8").toString();
|
|
33
|
+
const template = handlebars_1.default.compile(source);
|
|
34
|
+
return template(data);
|
|
37
35
|
}
|
|
38
|
-
exports.
|
|
36
|
+
exports.compileTemplate = compileTemplate;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type EmailSenderConfig = {
|
|
2
|
+
sender: string;
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
secure: boolean;
|
|
6
|
+
auth: {
|
|
7
|
+
user: string;
|
|
8
|
+
pass: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type EmailParams = {
|
|
12
|
+
to: string;
|
|
13
|
+
subject: string;
|
|
14
|
+
html: string;
|
|
15
|
+
};
|
|
16
|
+
declare function createEmailSender(config: EmailSenderConfig): (params: EmailParams) => Promise<void>;
|
|
17
|
+
export { createEmailSender, EmailSenderConfig, EmailParams };
|
|
@@ -0,0 +1,55 @@
|
|
|
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.createEmailSender = void 0;
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (C) 2024 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 logger_1 = require("@fonoster/logger");
|
|
32
|
+
const nodemailer_1 = require("nodemailer");
|
|
33
|
+
const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
|
|
34
|
+
function createEmailSender(config) {
|
|
35
|
+
const { sender, host, port, secure, auth } = config;
|
|
36
|
+
const transporter = (0, nodemailer_1.createTransport)({
|
|
37
|
+
host,
|
|
38
|
+
port,
|
|
39
|
+
secure,
|
|
40
|
+
auth
|
|
41
|
+
});
|
|
42
|
+
return function sendEmail(params) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const { to, subject, html } = params;
|
|
45
|
+
const info = yield transporter.sendMail({
|
|
46
|
+
from: sender,
|
|
47
|
+
to,
|
|
48
|
+
subject,
|
|
49
|
+
html
|
|
50
|
+
});
|
|
51
|
+
logger.verbose(`message sent: ${info.messageId}`);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.createEmailSender = createEmailSender;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Fonoster
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the MIT License (the "License");
|
|
24
|
+
* you may not use this file except in compliance with
|
|
25
|
+
* the License. You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* https://opensource.org/licenses/MIT
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./compileTemplate"), exports);
|
|
36
|
+
__exportStar(require("./createEmailSender"), exports);
|