@fonoster/common 0.2.12

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Fonoster Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,27 @@
1
+ import { ClientOptions } from "./types";
2
+ import { Metadata } from "@grpc/grpc-js";
3
+ export default class {
4
+ options: ClientOptions;
5
+ metadata: Metadata;
6
+ ServiceClient: any;
7
+ service: any;
8
+ /**
9
+ * Use the Options object to overwrite the service default configuration.
10
+ * @typedef {ClientOptions} Options
11
+ * @property {string} endpoint - The endpoint URI to send requests to.
12
+ * The endpoint should be a string like '{serviceHost}:{servicePort}'.
13
+ * @property {string} accessKeyId - your Fonos access key ID.
14
+ * @property {string} accessKeySecret - your Fonos secret access key.
15
+ * @property {string} bucket - The bucket to upload apps and media files.
16
+ */
17
+ /**
18
+ * Constructs a service object.
19
+ *
20
+ * @param {Options} options - Overwrite for the service's defaults configuration.
21
+ */
22
+ constructor(ServiceClient: any, options: ClientOptions);
23
+ init(): void;
24
+ getOptions(): ClientOptions;
25
+ getService(): any;
26
+ getMeta(): Metadata;
27
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ /*
23
+ * Copyright (C) 2021 by Fonoster Inc (https://fonoster.com)
24
+ * http://github.com/fonoster/fonoster
25
+ *
26
+ * This file is part of Fonoster
27
+ *
28
+ * Licensed under the MIT License (the "License");
29
+ * you may not use this file except in compliance with
30
+ * the License. You may obtain a copy of the License at
31
+ *
32
+ * https://opensource.org/licenses/MIT
33
+ *
34
+ * Unless required by applicable law or agreed to in writing, software
35
+ * distributed under the License is distributed on an "AS IS" BASIS,
36
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ * See the License for the specific language governing permissions and
38
+ * limitations under the License.
39
+ */
40
+ const trust_util_1 = require("./trust_util");
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const grpc_js_1 = require("@grpc/grpc-js");
44
+ const CONFIG_FILE = process.env.API_CONFIG_FILE ||
45
+ path.join(require("os").homedir(), ".fonoster", "config");
46
+ const configFileExit = () => fs.existsSync(CONFIG_FILE);
47
+ const getConfigFile = () => JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
48
+ const defaultOptions = {
49
+ endpoint: process.env.APISERVER_ENDPOINT || "api.fonoster.io",
50
+ accessKeyId: process.env.ACCESS_KEY_ID,
51
+ accessKeySecret: process.env.ACCESS_KEY_SECRET
52
+ };
53
+ class default_1 {
54
+ /**
55
+ * Use the Options object to overwrite the service default configuration.
56
+ * @typedef {ClientOptions} Options
57
+ * @property {string} endpoint - The endpoint URI to send requests to.
58
+ * The endpoint should be a string like '{serviceHost}:{servicePort}'.
59
+ * @property {string} accessKeyId - your Fonos access key ID.
60
+ * @property {string} accessKeySecret - your Fonos secret access key.
61
+ * @property {string} bucket - The bucket to upload apps and media files.
62
+ */
63
+ /**
64
+ * Constructs a service object.
65
+ *
66
+ * @param {Options} options - Overwrite for the service's defaults configuration.
67
+ */
68
+ constructor(ServiceClient, options) {
69
+ this.ServiceClient = ServiceClient;
70
+ this.options = options;
71
+ }
72
+ init() {
73
+ try {
74
+ if (!this.options && configFileExit()) {
75
+ this.options = getConfigFile();
76
+ }
77
+ }
78
+ catch (err) {
79
+ throw new Error(`Malformed config file found at: ${CONFIG_FILE}`);
80
+ }
81
+ if (!this.options) {
82
+ this.options = defaultOptions;
83
+ }
84
+ if (!this.options.accessKeyId || !this.options.accessKeySecret) {
85
+ throw new Error("Not valid credentials found");
86
+ }
87
+ this.metadata = new grpc_js_1.Metadata();
88
+ this.metadata.add("access_key_id", this.options.accessKeyId);
89
+ this.metadata.add("access_key_secret", this.options.accessKeySecret);
90
+ this.service = new this.ServiceClient(this.options.endpoint || defaultOptions.endpoint, trust_util_1.getClientCredentials());
91
+ }
92
+ getOptions() {
93
+ return this.options;
94
+ }
95
+ getService() {
96
+ return this.service;
97
+ }
98
+ getMeta() {
99
+ return this.metadata;
100
+ }
101
+ }
102
+ exports.default = default_1;
@@ -0,0 +1 @@
1
+ export default function assertEnvIsSet(name: string): void;
@@ -0,0 +1,20 @@
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
+ const logger_1 = __importDefault(require("@fonoster/logger"));
7
+ function assertEnvIsSet(name) {
8
+ const register = require(process.env.SERVICES_ENVS ||
9
+ "/home/fonoster/service_envs.json");
10
+ const services = register.filter((service) => service.module === name);
11
+ for (let value of services) {
12
+ value.env.forEach(function (variable) {
13
+ if (!(variable in process.env)) {
14
+ logger_1.default.error(`The environment variable ${variable} is required but was not found`);
15
+ process.exit(1);
16
+ }
17
+ });
18
+ }
19
+ }
20
+ exports.default = assertEnvIsSet;
@@ -0,0 +1 @@
1
+ export default function (): void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ /*
26
+ * Copyright (C) 2021 by Fonoster Inc (https://fonoster.com)
27
+ * http://github.com/fonoster/fonoster
28
+ *
29
+ * This file is part of Fonoster
30
+ *
31
+ * Licensed under the MIT License (the "License");
32
+ * you may not use this file except in compliance with
33
+ * the License. You may obtain a copy of the License at
34
+ *
35
+ * https://opensource.org/licenses/MIT
36
+ *
37
+ * Unless required by applicable law or agreed to in writing, software
38
+ * distributed under the License is distributed on an "AS IS" BASIS,
39
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ * See the License for the specific language governing permissions and
41
+ * limitations under the License.
42
+ */
43
+ /* eslint-disable require-jsdoc */
44
+ const logger_1 = __importDefault(require("@fonoster/logger"));
45
+ const grpc = __importStar(require("@grpc/grpc-js"));
46
+ const grpc_ts_health_check_1 = require("grpc-ts-health-check");
47
+ const host = process.env.SERVICE_ADDRESS || "localhost";
48
+ const port = parseInt(process.env.SERVICE_PORT) || 50052;
49
+ const service = process.env.SERVICE_NAME || "";
50
+ function default_1() {
51
+ const healthClient = new grpc_ts_health_check_1.HealthClient(`${host}:${port}`, grpc.credentials.createInsecure());
52
+ const request = new grpc_ts_health_check_1.HealthCheckRequest();
53
+ request.setService(service);
54
+ healthClient.check(request, (error, response) => {
55
+ if (error) {
56
+ logger_1.default.error(`@fonoster/common healthcheck fialed: ${error}`, error);
57
+ process.exit(1);
58
+ }
59
+ else {
60
+ logger_1.default.verbose(`@fonoster/common healthcheck success [status: ${response.getStatus()}]`);
61
+ process.exit(0);
62
+ }
63
+ });
64
+ }
65
+ exports.default = default_1;
@@ -0,0 +1,8 @@
1
+ import APIClient from "./api_client";
2
+ import WebAPIClient from "./web_client";
3
+ import { ClientOptions, WebClientOptions } from "./types";
4
+ import { getClientCredentials, getServerCredentials } from "./trust_util";
5
+ import runServices from "./service_runner";
6
+ import { Plugin } from "./speech/plugin";
7
+ import { SpeechProvider, SpeechTracker, SpeechResult, StreamSpeechResult } from "./speech/types";
8
+ export { APIClient, WebAPIClient, WebClientOptions, ClientOptions, Plugin, SpeechTracker, SpeechResult, SpeechProvider, StreamSpeechResult, getClientCredentials, getServerCredentials, runServices };
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
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.runServices = exports.getServerCredentials = exports.getClientCredentials = exports.Plugin = exports.WebAPIClient = exports.APIClient = void 0;
7
+ /*
8
+ * Copyright (C) 2021 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_client_1 = __importDefault(require("./api_client"));
26
+ exports.APIClient = api_client_1.default;
27
+ const web_client_1 = __importDefault(require("./web_client"));
28
+ exports.WebAPIClient = web_client_1.default;
29
+ const trust_util_1 = require("./trust_util");
30
+ Object.defineProperty(exports, "getClientCredentials", { enumerable: true, get: function () { return trust_util_1.getClientCredentials; } });
31
+ Object.defineProperty(exports, "getServerCredentials", { enumerable: true, get: function () { return trust_util_1.getServerCredentials; } });
32
+ //import healthcheck from "./healthcheck";
33
+ const service_runner_1 = __importDefault(require("./service_runner"));
34
+ exports.runServices = service_runner_1.default;
35
+ const plugin_1 = require("./speech/plugin");
36
+ Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugin_1.Plugin; } });
@@ -0,0 +1,13 @@
1
+ interface ServiceInf {
2
+ name: string;
3
+ version: string;
4
+ service: any;
5
+ server: any;
6
+ }
7
+ interface Middleware {
8
+ name: string;
9
+ description?: string;
10
+ middlewareObj: any;
11
+ }
12
+ export default function run(srvInfList: ServiceInf[], middlewareList?: Middleware[]): void;
13
+ export {};
@@ -0,0 +1,53 @@
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
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
7
+ /* eslint-disable require-jsdoc */
8
+ /*
9
+ * Copyright (C) 2021 by Fonoster Inc (https://fonoster.com)
10
+ * http://github.com/fonoster/fonoster
11
+ *
12
+ * This file is part of Fonoster
13
+ *
14
+ * Licensed under the MIT License (the "License");
15
+ * you may not use this file except in compliance with
16
+ * the License. You may obtain a copy of the License at
17
+ *
18
+ * https://opensource.org/licenses/MIT
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ const logger_1 = __importDefault(require("@fonoster/logger"));
27
+ const env_is_set_1 = __importDefault(require("./env_is_set"));
28
+ const grpc = require("@grpc/grpc-js");
29
+ const trust_util_1 = require("./trust_util");
30
+ const interceptor = require("@speedymonster/grpc-interceptors");
31
+ const ENDPOINT = process.env.BINDADDR || "0.0.0.0:50052";
32
+ function run(srvInfList, middlewareList) {
33
+ const grpcServer = new grpc.Server();
34
+ // Wrapped server
35
+ const server = interceptor.serverProxy(grpcServer);
36
+ logger_1.default.info(`@fonoster/common service runner [starting @ ${ENDPOINT}, api = ${srvInfList[0].version}]`);
37
+ if (middlewareList) {
38
+ middlewareList.forEach((middleware) => {
39
+ server.use(middleware.middlewareObj);
40
+ logger_1.default.info(`@fonoster/common service runner [added ${middleware.name} middleware]`);
41
+ });
42
+ }
43
+ srvInfList.forEach((srvInf) => {
44
+ env_is_set_1.default(srvInf.name);
45
+ server.addService(srvInf.service, srvInf.server);
46
+ logger_1.default.info(`@fonoster/common service runner [added ${srvInf.name} service]`);
47
+ });
48
+ server.bindAsync(ENDPOINT, trust_util_1.getServerCredentials(), () => {
49
+ server.start();
50
+ });
51
+ logger_1.default.info("@fonoster/common service runner [runner is online]");
52
+ }
53
+ exports.default = run;
@@ -0,0 +1,6 @@
1
+ export declare abstract class Plugin {
2
+ type: string;
3
+ name: string;
4
+ constructor(type: string, name: string);
5
+ getType(): string;
6
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Plugin = void 0;
4
+ /*
5
+ * Copyright (C) 2021 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
+ class Plugin {
23
+ constructor(type, name) {
24
+ this.name = name;
25
+ this.type = type;
26
+ }
27
+ getType() {
28
+ return this.type;
29
+ }
30
+ }
31
+ exports.Plugin = Plugin;
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import { Stream } from "stream";
3
+ export interface SpeechProvider {
4
+ createSpeechTracker(options: unknown): SpeechTracker;
5
+ }
6
+ export interface SpeechTracker {
7
+ transcribe(stream: Stream): Promise<SpeechResult>;
8
+ streamTranscribe(stream: Stream): StreamSpeechResult;
9
+ }
10
+ export interface SpeechResult {
11
+ transcript: string;
12
+ isFinal: boolean;
13
+ }
14
+ export interface StreamSpeechResult {
15
+ on(events: string, callback: Function): void;
16
+ close: Function;
17
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ declare const getServerCredentials: () => any;
2
+ declare const getClientCredentials: () => any;
3
+ export { getClientCredentials, getServerCredentials };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.getServerCredentials = exports.getClientCredentials = void 0;
26
+ /*
27
+ * Copyright (C) 2021 by Fonoster Inc (https://fonoster.com)
28
+ * http://github.com/fonoster/fonoster
29
+ *
30
+ * This file is part of Fonoster
31
+ *
32
+ * Licensed under the MIT License (the "License");
33
+ * you may not use this file except in compliance with
34
+ * the License. You may obtain a copy of the License at
35
+ *
36
+ * https://opensource.org/licenses/MIT
37
+ *
38
+ * Unless required by applicable law or agreed to in writing, software
39
+ * distributed under the License is distributed on an "AS IS" BASIS,
40
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41
+ * See the License for the specific language governing permissions and
42
+ * limitations under the License.
43
+ */
44
+ const logger_1 = __importDefault(require("@fonoster/logger"));
45
+ const path_1 = __importDefault(require("path"));
46
+ const os = __importStar(require("os"));
47
+ const fs = __importStar(require("fs"));
48
+ const atob_1 = __importDefault(require("atob"));
49
+ const grpc = require("@grpc/grpc-js");
50
+ const prepCert = (cert) => Buffer.from(atob_1.default(cert), "utf-8");
51
+ let config = {};
52
+ try {
53
+ config = JSON.parse(fs
54
+ .readFileSync(path_1.default.join(os.homedir(), ".fonoster", "config"))
55
+ .toString("utf-8"));
56
+ }
57
+ catch (e) {
58
+ logger_1.default.verbose("@fonoster/common no config found");
59
+ }
60
+ const getServerCredentials = () => {
61
+ try {
62
+ return grpc.ServerCredentials.createSsl(prepCert(config.caCertificate), [
63
+ {
64
+ cert_chain: prepCert(config.serverCertificate),
65
+ private_key: prepCert(config.serverKey)
66
+ }
67
+ ], true);
68
+ }
69
+ catch (e) {
70
+ logger_1.default.warn("@fonoster/common trust util [unable to load security certificates]");
71
+ logger_1.default.warn("@fonoster/common trust util [starting server in insecure mode]");
72
+ return grpc.ServerCredentials.createInsecure();
73
+ }
74
+ };
75
+ exports.getServerCredentials = getServerCredentials;
76
+ const getClientCredentials = () => process.env.ALLOW_INSECURE === "true"
77
+ ? grpc.credentials.createInsecure()
78
+ : grpc.credentials.createSsl();
79
+ exports.getClientCredentials = getClientCredentials;
@@ -0,0 +1,12 @@
1
+ export interface ClientOptions {
2
+ endpoint?: string;
3
+ bucket?: string;
4
+ accessKeyId?: string;
5
+ accessKeySecret?: string;
6
+ }
7
+ export interface WebClientOptions {
8
+ endpoint?: string;
9
+ bucket?: string;
10
+ accessKeyId: string;
11
+ accessKeySecret: string;
12
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
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 Fonos access key ID.
11
+ * @property {string} accessKeySecret - your Fonos 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
+ }
@@ -0,0 +1,53 @@
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 Fonos access key ID.
11
+ * @property {string} accessKeySecret - your Fonos 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;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@fonoster/common",
3
+ "version": "0.2.12",
4
+ "description": "Common artifacts",
5
+ "author": "Pedro Sanders <psanders@fonoster.com>",
6
+ "homepage": "https://github.com/fonoster/fonos#readme",
7
+ "license": "MIT",
8
+ "main": "dist/index",
9
+ "types": "dist/index",
10
+ "scripts": {
11
+ "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
12
+ "build": "tsc -b tsconfig.json"
13
+ },
14
+ "directories": {
15
+ "src": "src",
16
+ "test": "test"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/fonoster/fonostergit"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/fonoster/fonoster/issues"
30
+ },
31
+ "dependencies": {
32
+ "@fonoster/certs": "^0.2.12",
33
+ "@fonoster/logger": "^0.2.12",
34
+ "@grpc/grpc-js": "^1.3.6",
35
+ "@speedymonster/grpc-interceptors": "^0.2.5",
36
+ "atob": "^2.1.2",
37
+ "deepmerge": "^4.2.2"
38
+ },
39
+ "gitHead": "b91b98924d61304f6175be48fe5762e36db24a02"
40
+ }