@fonoster/apiserver 0.4.10 → 0.4.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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
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
+ /*
7
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
8
+ * http://github.com/fonoster/fonoster
9
+ *
10
+ * This file is part of Fonoster
11
+ *
12
+ * Licensed under the MIT License (the "License");
13
+ * you may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at
15
+ *
16
+ * https://opensource.org/licenses/MIT
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const logger_1 = require("@fonoster/logger");
25
+ const envs_1 = require("./envs");
26
+ const btoa_1 = __importDefault(require("btoa"));
27
+ const express_1 = __importDefault(require("express"));
28
+ const http_proxy_1 = __importDefault(require("http-proxy"));
29
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
30
+ const PORT = 4000;
31
+ const proxy = http_proxy_1.default.createProxyServer({});
32
+ const app = (0, express_1.default)();
33
+ proxy.on("proxyReq", (proxyReq) => {
34
+ const encodedCredentials = (0, btoa_1.default)(`${envs_1.APISERVER_ASTERISK_ARI_USERNAME}:${envs_1.APISERVER_ASTERISK_ARI_SECRET}`);
35
+ proxyReq.setHeader("Authorization", `Basic ${encodedCredentials}`);
36
+ });
37
+ app.use("/ari", (req, res) => {
38
+ logger.verbose("proxying request to target server", {
39
+ targetServer: envs_1.APISERVER_ASTERISK_ARI_INTERNAL_URL,
40
+ url: req.url
41
+ });
42
+ proxy.web(req, res, { target: envs_1.APISERVER_ASTERISK_ARI_INTERNAL_URL });
43
+ });
44
+ app.listen(PORT, () => {
45
+ logger.info(`ARI proxy server is running on http://localhost:${PORT}`);
46
+ });
package/dist/envs.d.ts CHANGED
@@ -1 +1,6 @@
1
1
  export declare const APISERVER_JWT_PRIVATE_KEY: string;
2
+ export declare const APISERVER_ROUTR_DEFAULT_PEER_USERNAME: string;
3
+ export declare const APISERVER_ROUTR_DEFAULT_PEER_SECRET: string;
4
+ export declare const APISERVER_ASTERISK_ARI_INTERNAL_URL: string;
5
+ export declare const APISERVER_ASTERISK_ARI_USERNAME: string;
6
+ export declare const APISERVER_ASTERISK_ARI_SECRET: string;
package/dist/envs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APISERVER_JWT_PRIVATE_KEY = void 0;
3
+ exports.APISERVER_ASTERISK_ARI_SECRET = exports.APISERVER_ASTERISK_ARI_USERNAME = exports.APISERVER_ASTERISK_ARI_INTERNAL_URL = exports.APISERVER_ROUTR_DEFAULT_PEER_SECRET = exports.APISERVER_ROUTR_DEFAULT_PEER_USERNAME = exports.APISERVER_JWT_PRIVATE_KEY = void 0;
4
4
  /*
5
5
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -20,3 +20,8 @@ exports.APISERVER_JWT_PRIVATE_KEY = void 0;
20
20
  * limitations under the License.
21
21
  */
22
22
  exports.APISERVER_JWT_PRIVATE_KEY = process.env.APISERVER_JWT_PRIVATE_KEY;
23
+ exports.APISERVER_ROUTR_DEFAULT_PEER_USERNAME = process.env.APISERVER_ROUTR_DEFAULT_PEER_USERNAME;
24
+ exports.APISERVER_ROUTR_DEFAULT_PEER_SECRET = process.env.APISERVER_ROUTR_DEFAULT_PEER_SECRET;
25
+ exports.APISERVER_ASTERISK_ARI_INTERNAL_URL = process.env.APISERVER_ASTERISK_ARI_INTERNAL_URL;
26
+ exports.APISERVER_ASTERISK_ARI_USERNAME = process.env.APISERVER_ASTERISK_ARI_USERNAME;
27
+ exports.APISERVER_ASTERISK_ARI_SECRET = process.env.APISERVER_ASTERISK_ARI_SECRET;
package/dist/index.js CHANGED
@@ -1,5 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
3
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
28
  };
@@ -42,6 +65,9 @@ const auth_1 = require("@fonoster/auth");
42
65
  const agents_1 = require("@fonoster/agents");
43
66
  const common_1 = require("@fonoster/common");
44
67
  const envs_1 = require("./envs");
68
+ Promise.resolve().then(() => __importStar(require("./ari_proxy")));
69
+ Promise.resolve().then(() => __importStar(require("./upsert_peer")));
70
+ Promise.resolve().then(() => __importStar(require("@fonoster/dispatcher")));
45
71
  const services = [
46
72
  {
47
73
  name: "apps",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/fonoster
6
+ *
7
+ * This file is part of Fonoster
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const core_1 = require("@fonoster/core");
22
+ const logger_1 = require("@fonoster/logger");
23
+ const envs_1 = require("./envs");
24
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
25
+ async function upsertPeer(peerInfo) {
26
+ const redis = (0, core_1.getRedisConnection)();
27
+ logger.info(`upserting peer ${peerInfo.ref}`);
28
+ try {
29
+ await redis.sadd("peers", peerInfo.ref);
30
+ await redis.set(peerInfo.ref, buildPeer(peerInfo));
31
+ }
32
+ catch (err) {
33
+ logger.error(err);
34
+ process.exit(1);
35
+ }
36
+ return peerInfo.ref;
37
+ }
38
+ function buildPeer(peerInfo) {
39
+ const { ref, username, secret } = peerInfo;
40
+ const peerObj = {
41
+ apiVersion: "v1beta1",
42
+ kind: "Peer",
43
+ metadata: {
44
+ name: "Voice Media Server @ Default",
45
+ ref: ref,
46
+ createdOn: new Date().toISOString(),
47
+ modifiedOn: new Date().toISOString()
48
+ },
49
+ spec: {
50
+ device: "default",
51
+ credentials: {
52
+ username: username,
53
+ secret: secret
54
+ }
55
+ }
56
+ };
57
+ return JSON.stringify(peerObj);
58
+ }
59
+ upsertPeer({
60
+ ref: "default",
61
+ username: envs_1.APISERVER_ROUTR_DEFAULT_PEER_USERNAME,
62
+ secret: envs_1.APISERVER_ROUTR_DEFAULT_PEER_SECRET
63
+ }).catch(logger.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "Fonoster API Server",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -36,21 +36,27 @@
36
36
  "url": "https://github.com/fonoster/fonoster/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@fonoster/agents": "^0.4.10",
40
- "@fonoster/apps": "^0.4.10",
41
- "@fonoster/auth": "^0.4.10",
42
- "@fonoster/callmanager": "^0.4.10",
43
- "@fonoster/common": "^0.4.10",
44
- "@fonoster/domains": "^0.4.10",
45
- "@fonoster/limiter": "^0.4.10",
46
- "@fonoster/monitor": "^0.4.10",
47
- "@fonoster/numbers": "^0.4.10",
48
- "@fonoster/projects": "^0.4.10",
49
- "@fonoster/providers": "^0.4.10",
50
- "@fonoster/secrets": "^0.4.10",
51
- "@fonoster/storage": "^0.4.10",
52
- "@fonoster/users": "^0.4.10",
53
- "dotenv": "^8.2.0"
39
+ "@fonoster/agents": "^0.4.12",
40
+ "@fonoster/apps": "^0.4.12",
41
+ "@fonoster/auth": "^0.4.12",
42
+ "@fonoster/callmanager": "^0.4.12",
43
+ "@fonoster/common": "^0.4.12",
44
+ "@fonoster/dispatcher": "^0.4.12",
45
+ "@fonoster/domains": "^0.4.12",
46
+ "@fonoster/limiter": "^0.4.12",
47
+ "@fonoster/monitor": "^0.4.12",
48
+ "@fonoster/numbers": "^0.4.12",
49
+ "@fonoster/projects": "^0.4.12",
50
+ "@fonoster/providers": "^0.4.12",
51
+ "@fonoster/secrets": "^0.4.12",
52
+ "@fonoster/storage": "^0.4.12",
53
+ "@fonoster/users": "^0.4.12",
54
+ "dotenv": "^8.2.0",
55
+ "express": "^4.18.2",
56
+ "http-proxy": "^1.18.1"
54
57
  },
55
- "gitHead": "5803a7dc72afe7bf454896ae4c60c7565d27eb49"
58
+ "gitHead": "85d2c5384d83041dc22bd0362b2022a016a64bfb",
59
+ "devDependencies": {
60
+ "@types/http-proxy": "^1.17.14"
61
+ }
56
62
  }