@fonoster/common 0.4.8 → 0.4.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/api_client.js +10 -6
- package/dist/envs.d.ts +4 -0
- package/dist/envs.js +25 -0
- package/dist/healthcheck.js +1 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +5 -47
- package/dist/service_runner.js +5 -4
- package/dist/speech/plugin.js +2 -0
- package/dist/trust_util.js +2 -1
- package/package.json +5 -17
- package/dist/tracer.d.ts +0 -1
- package/dist/tracer.js +0 -65
package/dist/api_client.js
CHANGED
|
@@ -41,20 +41,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
41
41
|
* See the License for the specific language governing permissions and
|
|
42
42
|
* limitations under the License.
|
|
43
43
|
*/
|
|
44
|
-
const trust_util_1 = require("./trust_util");
|
|
45
44
|
const fs = __importStar(require("fs"));
|
|
46
45
|
const path = __importStar(require("path"));
|
|
46
|
+
const trust_util_1 = require("./trust_util");
|
|
47
47
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
48
|
-
const
|
|
49
|
-
|
|
48
|
+
const envs_1 = require("./envs");
|
|
49
|
+
const CONFIG_FILE = path.join(require("os").homedir(), ".fonoster", "config");
|
|
50
50
|
const configFileExit = () => fs.existsSync(CONFIG_FILE);
|
|
51
51
|
const getConfigFile = () => JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
|
|
52
52
|
const defaultOptions = {
|
|
53
|
-
endpoint:
|
|
54
|
-
accessKeyId:
|
|
55
|
-
accessKeySecret:
|
|
53
|
+
endpoint: envs_1.APISERVER_ENDPOINT || "api.fonoster.io",
|
|
54
|
+
accessKeyId: envs_1.APISERVER_ACCESS_KEY_ID,
|
|
55
|
+
accessKeySecret: envs_1.APISERVER_ACCESS_KEY_SECRET
|
|
56
56
|
};
|
|
57
57
|
class default_1 {
|
|
58
|
+
options;
|
|
59
|
+
metadata;
|
|
60
|
+
ServiceClient;
|
|
61
|
+
service;
|
|
58
62
|
/**
|
|
59
63
|
* Use the Options object to overwrite the service default configuration.
|
|
60
64
|
* @typedef {ClientOptions} Options
|
package/dist/envs.d.ts
ADDED
package/dist/envs.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GRPC_ALLOW_INSECURE = exports.APISERVER_ACCESS_KEY_SECRET = exports.APISERVER_ACCESS_KEY_ID = exports.APISERVER_ENDPOINT = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2023 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
|
+
exports.APISERVER_ENDPOINT = process.env.APISERVER_ENDPOINT || "api.fonoster.io";
|
|
23
|
+
exports.APISERVER_ACCESS_KEY_ID = process.env.APISERVER_ACCESS_KEY_ID;
|
|
24
|
+
exports.APISERVER_ACCESS_KEY_SECRET = process.env.APISERVER_ACCESS_KEY_SECRET;
|
|
25
|
+
exports.GRPC_ALLOW_INSECURE = process.env.GRPC_ALLOW_INSECURE || "false";
|
package/dist/healthcheck.js
CHANGED
|
@@ -20,7 +20,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
*/
|
|
21
21
|
/* eslint-disable require-jsdoc */
|
|
22
22
|
const grpc_health_check_1 = require("@fonoster/grpc-health-check");
|
|
23
|
-
|
|
24
|
-
const port = parseInt(process.env.SERVICE_PORT) || 50052;
|
|
25
|
-
const service = process.env.SERVICE_NAME || "";
|
|
26
|
-
exports.default = async () => (0, grpc_health_check_1.checker)(service, `${host}:${port}`);
|
|
23
|
+
exports.default = async () => (0, grpc_health_check_1.checker)("", `localhost:50052`);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import APIClient from "./api_client";
|
|
2
1
|
import { ClientOptions } from "./types";
|
|
3
2
|
import { getClientCredentials, getServerCredentials } from "./trust_util";
|
|
4
|
-
import healthcheck from "./healthcheck";
|
|
5
|
-
import runServices from "./service_runner";
|
|
6
3
|
import { Plugin } from "./speech/plugin";
|
|
7
4
|
import { SpeechProvider, SpeechTracker, SpeechResult, StreamSpeechResult } from "./speech/types";
|
|
8
|
-
|
|
5
|
+
import APIClient from "./api_client";
|
|
6
|
+
import healthcheck from "./healthcheck";
|
|
7
|
+
import runServices from "./service_runner";
|
|
9
8
|
export { APIClient, ClientOptions, Plugin, SpeechTracker, SpeechResult, SpeechProvider, StreamSpeechResult, getClientCredentials, getServerCredentials, runServices, healthcheck };
|
package/dist/index.js
CHANGED
|
@@ -1,59 +1,17 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.healthcheck = exports.runServices = exports.getServerCredentials = exports.getClientCredentials = exports.Plugin = exports.APIClient =
|
|
30
|
-
/*
|
|
31
|
-
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
32
|
-
* http://github.com/fonoster/fonoster
|
|
33
|
-
*
|
|
34
|
-
* This file is part of Fonoster
|
|
35
|
-
*
|
|
36
|
-
* Licensed under the MIT License (the "License");
|
|
37
|
-
* you may not use this file except in compliance with
|
|
38
|
-
* the License. You may obtain a copy of the License at
|
|
39
|
-
*
|
|
40
|
-
* https://opensource.org/licenses/MIT
|
|
41
|
-
*
|
|
42
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
43
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
44
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
45
|
-
* See the License for the specific language governing permissions and
|
|
46
|
-
* limitations under the License.
|
|
47
|
-
*/
|
|
48
|
-
const api_client_1 = __importDefault(require("./api_client"));
|
|
49
|
-
exports.APIClient = api_client_1.default;
|
|
6
|
+
exports.healthcheck = exports.runServices = exports.getServerCredentials = exports.getClientCredentials = exports.Plugin = exports.APIClient = void 0;
|
|
50
7
|
const trust_util_1 = require("./trust_util");
|
|
51
8
|
Object.defineProperty(exports, "getClientCredentials", { enumerable: true, get: function () { return trust_util_1.getClientCredentials; } });
|
|
52
9
|
Object.defineProperty(exports, "getServerCredentials", { enumerable: true, get: function () { return trust_util_1.getServerCredentials; } });
|
|
10
|
+
const plugin_1 = require("./speech/plugin");
|
|
11
|
+
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugin_1.Plugin; } });
|
|
12
|
+
const api_client_1 = __importDefault(require("./api_client"));
|
|
13
|
+
exports.APIClient = api_client_1.default;
|
|
53
14
|
const healthcheck_1 = __importDefault(require("./healthcheck"));
|
|
54
15
|
exports.healthcheck = healthcheck_1.default;
|
|
55
16
|
const service_runner_1 = __importDefault(require("./service_runner"));
|
|
56
17
|
exports.runServices = service_runner_1.default;
|
|
57
|
-
const plugin_1 = require("./speech/plugin");
|
|
58
|
-
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugin_1.Plugin; } });
|
|
59
|
-
exports.Tracer = __importStar(require("./tracer"));
|
package/dist/service_runner.js
CHANGED
|
@@ -52,14 +52,14 @@ const grpc_health_check_1 = require("@fonoster/grpc-health-check");
|
|
|
52
52
|
const logger_1 = require("@fonoster/logger");
|
|
53
53
|
const env_is_set_1 = __importDefault(require("./env_is_set"));
|
|
54
54
|
const interceptor = require("grpc-interceptors");
|
|
55
|
-
const
|
|
55
|
+
const BIND_ADDR = "0.0.0.0:50052";
|
|
56
56
|
const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
|
|
57
57
|
function run(srvInfList, middlewareList) {
|
|
58
58
|
const grpcServer = new grpc.Server();
|
|
59
59
|
// Wrapped server
|
|
60
60
|
const server = interceptor.serverProxy((0, grpc_health_check_1.useHealth)(grpcServer));
|
|
61
61
|
logger.info(`service runner`, {
|
|
62
|
-
|
|
62
|
+
bindAddr: BIND_ADDR,
|
|
63
63
|
apiVersion: srvInfList[0].version
|
|
64
64
|
});
|
|
65
65
|
middlewareList?.forEach((middleware) => {
|
|
@@ -69,13 +69,14 @@ function run(srvInfList, middlewareList) {
|
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
srvInfList.forEach((srvInf) => {
|
|
72
|
-
|
|
72
|
+
// TODO: Perhaps this method should be simplified now that we are using less services
|
|
73
|
+
(0, env_is_set_1.default)("apiserver");
|
|
73
74
|
server.addService(srvInf.service, srvInf.server);
|
|
74
75
|
logger.info(`service runner`, {
|
|
75
76
|
service: srvInf.name,
|
|
76
77
|
});
|
|
77
78
|
});
|
|
78
|
-
server.bindAsync(
|
|
79
|
+
server.bindAsync(BIND_ADDR, (0, trust_util_1.getServerCredentials)(), () => {
|
|
79
80
|
server.start();
|
|
80
81
|
});
|
|
81
82
|
logger.info("service runner online");
|
package/dist/speech/plugin.js
CHANGED
package/dist/trust_util.js
CHANGED
|
@@ -51,6 +51,7 @@ const fs = __importStar(require("fs"));
|
|
|
51
51
|
const logger_1 = require("@fonoster/logger");
|
|
52
52
|
const path_1 = __importDefault(require("path"));
|
|
53
53
|
const atob_1 = __importDefault(require("atob"));
|
|
54
|
+
const envs_1 = require("./envs");
|
|
54
55
|
const prepCert = (cert) => Buffer.from((0, atob_1.default)(cert), "utf-8");
|
|
55
56
|
const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
|
|
56
57
|
let config = {};
|
|
@@ -78,7 +79,7 @@ const getServerCredentials = () => {
|
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
81
|
exports.getServerCredentials = getServerCredentials;
|
|
81
|
-
const getClientCredentials = () =>
|
|
82
|
+
const getClientCredentials = () => envs_1.GRPC_ALLOW_INSECURE === "true"
|
|
82
83
|
? grpc.credentials.createInsecure()
|
|
83
84
|
: grpc.credentials.createSsl();
|
|
84
85
|
exports.getClientCredentials = getClientCredentials;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/common",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "Common artifacts",
|
|
5
5
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,29 +26,17 @@
|
|
|
26
26
|
"build": "tsc -b tsconfig.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@fonoster/
|
|
30
|
-
"@fonoster/
|
|
31
|
-
"@fonoster/logger": "^0.4.7",
|
|
29
|
+
"@fonoster/grpc-health-check": "^3.1.6",
|
|
30
|
+
"@fonoster/logger": "^0.4.9",
|
|
32
31
|
"@grpc/grpc-js": "^1.8.4",
|
|
33
32
|
"@grpc/proto-loader": "^0.7.2",
|
|
34
|
-
"@opentelemetry/api": "^1.0.4",
|
|
35
|
-
"@opentelemetry/exporter-jaeger": "^1.0.1",
|
|
36
|
-
"@opentelemetry/exporter-zipkin": "^1.0.1",
|
|
37
|
-
"@opentelemetry/instrumentation": "^0.27.0",
|
|
38
|
-
"@opentelemetry/instrumentation-express": "^0.27.0",
|
|
39
|
-
"@opentelemetry/instrumentation-grpc": "^0.27.0",
|
|
40
|
-
"@opentelemetry/instrumentation-http": "^0.27.0",
|
|
41
|
-
"@opentelemetry/resources": "^1.0.4",
|
|
42
|
-
"@opentelemetry/sdk-metrics-base": "0.27.0",
|
|
43
|
-
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
44
|
-
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
45
|
-
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
46
33
|
"atob": "^2.1.2",
|
|
34
|
+
"axios": "^1.6.2",
|
|
47
35
|
"deepmerge": "^4.2.2",
|
|
48
36
|
"grpc-interceptors": "github:fonoster/node-grpc-interceptors"
|
|
49
37
|
},
|
|
50
38
|
"publishConfig": {
|
|
51
39
|
"access": "public"
|
|
52
40
|
},
|
|
53
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "c32b3a14cdffce2e7ef8fd6dc4dfaf237dff23a8"
|
|
54
42
|
}
|
package/dist/tracer.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const init: (serviceName: string) => import("@opentelemetry/api").Tracer;
|
package/dist/tracer.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.init = void 0;
|
|
7
|
-
/*
|
|
8
|
-
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
9
|
-
* http://github.com/fonoster/fonoster
|
|
10
|
-
*
|
|
11
|
-
* This file is part of Fonoster
|
|
12
|
-
*
|
|
13
|
-
* Licensed under the MIT License (the "License");
|
|
14
|
-
* you may not use this file except in compliance with
|
|
15
|
-
* the License. You may obtain a copy of the License at
|
|
16
|
-
*
|
|
17
|
-
* https://opensource.org/licenses/MIT
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
-
* See the License for the specific language governing permissions and
|
|
23
|
-
* limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
const api_1 = require("@opentelemetry/api");
|
|
26
|
-
api_1.diag.setLogger(new api_1.DiagConsoleLogger(), getLogLevel());
|
|
27
|
-
const api_2 = __importDefault(require("@opentelemetry/api"));
|
|
28
|
-
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
29
|
-
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
30
|
-
const resources_1 = require("@opentelemetry/resources");
|
|
31
|
-
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
32
|
-
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
33
|
-
const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
|
|
34
|
-
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
|
|
35
|
-
function getLogLevel() {
|
|
36
|
-
switch (process.env.LOGS_LEVEL?.toLowerCase()) {
|
|
37
|
-
case "debug":
|
|
38
|
-
return api_1.DiagLogLevel.DEBUG;
|
|
39
|
-
case "info":
|
|
40
|
-
return api_1.DiagLogLevel.INFO;
|
|
41
|
-
case "warn":
|
|
42
|
-
return api_1.DiagLogLevel.WARN;
|
|
43
|
-
case "error":
|
|
44
|
-
return api_1.DiagLogLevel.ERROR;
|
|
45
|
-
default:
|
|
46
|
-
return api_1.DiagLogLevel.NONE;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const init = (serviceName) => {
|
|
50
|
-
const provider = new sdk_trace_node_1.NodeTracerProvider({
|
|
51
|
-
resource: new resources_1.Resource({
|
|
52
|
-
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
|
|
53
|
-
})
|
|
54
|
-
});
|
|
55
|
-
const exporter = new exporter_jaeger_1.JaegerExporter({
|
|
56
|
-
endpoint: process.env.TRACING_ENDPOINT || "http://localhost:14268/api/traces"
|
|
57
|
-
});
|
|
58
|
-
provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
|
|
59
|
-
provider.register();
|
|
60
|
-
(0, instrumentation_1.registerInstrumentations)({
|
|
61
|
-
instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
|
|
62
|
-
});
|
|
63
|
-
return api_2.default.trace.getTracer("fonoster-tracer");
|
|
64
|
-
};
|
|
65
|
-
exports.init = init;
|