@fonoster/common 0.4.6 → 0.4.8
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/index.d.ts +2 -3
- package/dist/index.js +1 -3
- package/dist/service_runner.js +13 -5
- package/dist/trust_util.d.ts +3 -2
- package/dist/trust_util.js +8 -7
- package/dist/types.d.ts +0 -6
- package/package.json +3 -3
- package/dist/web_client.d.ts +0 -21
- package/dist/web_client.js +0 -53
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import APIClient from "./api_client";
|
|
2
|
-
import
|
|
3
|
-
import { ClientOptions, WebClientOptions } from "./types";
|
|
2
|
+
import { ClientOptions } from "./types";
|
|
4
3
|
import { getClientCredentials, getServerCredentials } from "./trust_util";
|
|
5
4
|
import healthcheck from "./healthcheck";
|
|
6
5
|
import runServices from "./service_runner";
|
|
7
6
|
import { Plugin } from "./speech/plugin";
|
|
8
7
|
import { SpeechProvider, SpeechTracker, SpeechResult, StreamSpeechResult } from "./speech/types";
|
|
9
8
|
export * as Tracer from "./tracer";
|
|
10
|
-
export { APIClient,
|
|
9
|
+
export { APIClient, ClientOptions, Plugin, SpeechTracker, SpeechResult, SpeechProvider, StreamSpeechResult, getClientCredentials, getServerCredentials, runServices, healthcheck };
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.healthcheck = exports.runServices = exports.getServerCredentials = exports.getClientCredentials = exports.Plugin = exports.
|
|
29
|
+
exports.healthcheck = exports.runServices = exports.getServerCredentials = exports.getClientCredentials = exports.Plugin = exports.APIClient = exports.Tracer = void 0;
|
|
30
30
|
/*
|
|
31
31
|
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
32
32
|
* http://github.com/fonoster/fonoster
|
|
@@ -47,8 +47,6 @@ exports.healthcheck = exports.runServices = exports.getServerCredentials = expor
|
|
|
47
47
|
*/
|
|
48
48
|
const api_client_1 = __importDefault(require("./api_client"));
|
|
49
49
|
exports.APIClient = api_client_1.default;
|
|
50
|
-
const web_client_1 = __importDefault(require("./web_client"));
|
|
51
|
-
exports.WebAPIClient = web_client_1.default;
|
|
52
50
|
const trust_util_1 = require("./trust_util");
|
|
53
51
|
Object.defineProperty(exports, "getClientCredentials", { enumerable: true, get: function () { return trust_util_1.getClientCredentials; } });
|
|
54
52
|
Object.defineProperty(exports, "getServerCredentials", { enumerable: true, get: function () { return trust_util_1.getServerCredentials; } });
|
package/dist/service_runner.js
CHANGED
|
@@ -49,27 +49,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
49
49
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
50
50
|
const trust_util_1 = require("./trust_util");
|
|
51
51
|
const grpc_health_check_1 = require("@fonoster/grpc-health-check");
|
|
52
|
-
const logger_1 =
|
|
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
55
|
const ENDPOINT = process.env.BINDADDR || "0.0.0.0:50052";
|
|
56
|
+
const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
|
|
56
57
|
function run(srvInfList, middlewareList) {
|
|
57
58
|
const grpcServer = new grpc.Server();
|
|
58
59
|
// Wrapped server
|
|
59
60
|
const server = interceptor.serverProxy((0, grpc_health_check_1.useHealth)(grpcServer));
|
|
60
|
-
|
|
61
|
+
logger.info(`service runner`, {
|
|
62
|
+
endpoint: ENDPOINT,
|
|
63
|
+
apiVersion: srvInfList[0].version
|
|
64
|
+
});
|
|
61
65
|
middlewareList?.forEach((middleware) => {
|
|
62
66
|
server.use(middleware.middlewareObj);
|
|
63
|
-
|
|
67
|
+
logger.info(`service runner`, {
|
|
68
|
+
middleware: middleware.name,
|
|
69
|
+
});
|
|
64
70
|
});
|
|
65
71
|
srvInfList.forEach((srvInf) => {
|
|
66
72
|
(0, env_is_set_1.default)(srvInf.name);
|
|
67
73
|
server.addService(srvInf.service, srvInf.server);
|
|
68
|
-
|
|
74
|
+
logger.info(`service runner`, {
|
|
75
|
+
service: srvInf.name,
|
|
76
|
+
});
|
|
69
77
|
});
|
|
70
78
|
server.bindAsync(ENDPOINT, (0, trust_util_1.getServerCredentials)(), () => {
|
|
71
79
|
server.start();
|
|
72
80
|
});
|
|
73
|
-
|
|
81
|
+
logger.info("service runner online");
|
|
74
82
|
}
|
|
75
83
|
exports.default = run;
|
package/dist/trust_util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
declare const getServerCredentials: () => grpc.ServerCredentials;
|
|
3
|
+
declare const getClientCredentials: () => grpc.ChannelCredentials;
|
|
3
4
|
export { getClientCredentials, getServerCredentials };
|
package/dist/trust_util.js
CHANGED
|
@@ -45,13 +45,14 @@ exports.getServerCredentials = exports.getClientCredentials = void 0;
|
|
|
45
45
|
* See the License for the specific language governing permissions and
|
|
46
46
|
* limitations under the License.
|
|
47
47
|
*/
|
|
48
|
-
const
|
|
49
|
-
const path_1 = __importDefault(require("path"));
|
|
48
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
50
49
|
const os = __importStar(require("os"));
|
|
51
50
|
const fs = __importStar(require("fs"));
|
|
51
|
+
const logger_1 = require("@fonoster/logger");
|
|
52
|
+
const path_1 = __importDefault(require("path"));
|
|
52
53
|
const atob_1 = __importDefault(require("atob"));
|
|
53
|
-
const grpc = require("@grpc/grpc-js");
|
|
54
54
|
const prepCert = (cert) => Buffer.from((0, atob_1.default)(cert), "utf-8");
|
|
55
|
+
const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
|
|
55
56
|
let config = {};
|
|
56
57
|
try {
|
|
57
58
|
config = JSON.parse(fs
|
|
@@ -59,7 +60,7 @@ try {
|
|
|
59
60
|
.toString("utf-8"));
|
|
60
61
|
}
|
|
61
62
|
catch (e) {
|
|
62
|
-
|
|
63
|
+
logger.verbose("no config found at " + path_1.default.join(os.homedir(), ".fonoster", "config"));
|
|
63
64
|
}
|
|
64
65
|
const getServerCredentials = () => {
|
|
65
66
|
try {
|
|
@@ -71,13 +72,13 @@ const getServerCredentials = () => {
|
|
|
71
72
|
], true);
|
|
72
73
|
}
|
|
73
74
|
catch (e) {
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
logger.info("unable to load security certificates");
|
|
76
|
+
logger.info("starting server in insecure mode");
|
|
76
77
|
return grpc.ServerCredentials.createInsecure();
|
|
77
78
|
}
|
|
78
79
|
};
|
|
79
80
|
exports.getServerCredentials = getServerCredentials;
|
|
80
|
-
const getClientCredentials = () => process.env.
|
|
81
|
+
const getClientCredentials = () => process.env.GRPC_ALLOW_INSECURE === "true"
|
|
81
82
|
? grpc.credentials.createInsecure()
|
|
82
83
|
: grpc.credentials.createSsl();
|
|
83
84
|
exports.getClientCredentials = getClientCredentials;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/common",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "Common artifacts",
|
|
5
5
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@fonoster/certs": "^0.4.6",
|
|
30
30
|
"@fonoster/grpc-health-check": "^3.1.2",
|
|
31
|
-
"@fonoster/logger": "^0.4.
|
|
31
|
+
"@fonoster/logger": "^0.4.7",
|
|
32
32
|
"@grpc/grpc-js": "^1.8.4",
|
|
33
33
|
"@grpc/proto-loader": "^0.7.2",
|
|
34
34
|
"@opentelemetry/api": "^1.0.4",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "e594d9c289ce814090b8133d3efb03561cfa7598"
|
|
54
54
|
}
|
package/dist/web_client.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ClientOptions, WebClientOptions } from "./types";
|
|
2
|
-
export default class {
|
|
3
|
-
options: ClientOptions;
|
|
4
|
-
api: any;
|
|
5
|
-
/**
|
|
6
|
-
* Use the Options object to overwrite the service default configuration.
|
|
7
|
-
* @typedef {Object} Options
|
|
8
|
-
* @property {string} endpoint - The endpoint URI to send requests to.
|
|
9
|
-
* The endpoint should be a string like '{serviceHost}:{servicePort}'.
|
|
10
|
-
* @property {string} accessKeyId - your Fonoster access key ID.
|
|
11
|
-
* @property {string} accessKeySecret - your Fonoster secret access key.
|
|
12
|
-
* @property {string} bucket - The bucket to upload apps and media files.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Constructs a service object.
|
|
16
|
-
*
|
|
17
|
-
* @param {WebClientOptions} options - Overwrite for the service's defaults configuration.
|
|
18
|
-
*/
|
|
19
|
-
constructor(API: any, name: string, options: WebClientOptions);
|
|
20
|
-
run(method: string, request: unknown): Promise<unknown>;
|
|
21
|
-
}
|
package/dist/web_client.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const DEFAULT_ENDPOINT = "https://api.fonoster.io/api";
|
|
4
|
-
class default_1 {
|
|
5
|
-
/**
|
|
6
|
-
* Use the Options object to overwrite the service default configuration.
|
|
7
|
-
* @typedef {Object} Options
|
|
8
|
-
* @property {string} endpoint - The endpoint URI to send requests to.
|
|
9
|
-
* The endpoint should be a string like '{serviceHost}:{servicePort}'.
|
|
10
|
-
* @property {string} accessKeyId - your Fonoster access key ID.
|
|
11
|
-
* @property {string} accessKeySecret - your Fonoster secret access key.
|
|
12
|
-
* @property {string} bucket - The bucket to upload apps and media files.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Constructs a service object.
|
|
16
|
-
*
|
|
17
|
-
* @param {WebClientOptions} options - Overwrite for the service's defaults configuration.
|
|
18
|
-
*/
|
|
19
|
-
constructor(API, name, options) {
|
|
20
|
-
this.options = options;
|
|
21
|
-
if (!this.options.endpoint) {
|
|
22
|
-
this.options.endpoint = DEFAULT_ENDPOINT;
|
|
23
|
-
}
|
|
24
|
-
const config = new API.Configuration({
|
|
25
|
-
basePath: this.options.endpoint,
|
|
26
|
-
baseOptions: {
|
|
27
|
-
headers: {
|
|
28
|
-
access_key_id: this.options.accessKeyId,
|
|
29
|
-
access_key_secret: this.options.accessKeySecret
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
this.api = new API[name](config);
|
|
34
|
-
}
|
|
35
|
-
// eslint-disable-next-line require-jsdoc
|
|
36
|
-
async run(method, request) {
|
|
37
|
-
try {
|
|
38
|
-
return (await this.api[method](request));
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
if (e.response) {
|
|
42
|
-
throw e.response.data;
|
|
43
|
-
}
|
|
44
|
-
else if (e.request) {
|
|
45
|
-
// client never received a response, or request never left
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// anything else
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.default = default_1;
|