@routr/registry 2.0.8-alpha.13 → 2.0.8-alpha.15

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/sender.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { ServiceUnavailableError } from "@routr/common";
1
+ import { CommonErrors as CE } from "@routr/common";
2
2
  import { RegistrationRequest, SendMessageResponse } from "./types";
3
- export declare const sendRegisterMessage: (requesterAddr: string) => (request: RegistrationRequest) => Promise<ServiceUnavailableError | SendMessageResponse>;
3
+ export declare const sendRegisterMessage: (requesterAddr: string) => (request: RegistrationRequest) => Promise<CE.ServiceUnavailableError | SendMessageResponse>;
package/dist/sender.js CHANGED
@@ -42,16 +42,15 @@ exports.sendRegisterMessage = void 0;
42
42
  * See the License for the specific language governing permissions and
43
43
  * limitations under the License.
44
44
  */
45
- const grpc = __importStar(require("@grpc/grpc-js"));
46
45
  const common_1 = require("@routr/common");
47
- const common_2 = require("@routr/common");
46
+ const grpc = __importStar(require("@grpc/grpc-js"));
48
47
  const sendRegisterMessage = (requesterAddr) => {
49
48
  return (request) => {
50
- const client = new common_2.CommonRequester.REQUESTER_PROTO.v2draft1.Requester(requesterAddr, grpc.credentials.createInsecure());
49
+ const client = new common_1.CommonRequester.REQUESTER_PROTO.v2draft1.Requester(requesterAddr, grpc.credentials.createInsecure());
51
50
  return new Promise((resolve, reject) => {
52
51
  client.sendMessage(request, (err, response) => {
53
52
  if ((err === null || err === void 0 ? void 0 : err.code) === 14) {
54
- return reject(new common_1.ServiceUnavailableError(requesterAddr));
53
+ return reject(new common_1.CommonErrors.ServiceUnavailableError(requesterAddr));
55
54
  }
56
55
  else if (err) {
57
56
  return reject(err);
package/dist/service.js CHANGED
@@ -36,7 +36,6 @@ const types_1 = require("./types");
36
36
  const utils_1 = require("./utils");
37
37
  const common_1 = require("@routr/common");
38
38
  const logger_1 = require("@fonoster/logger");
39
- const common_2 = require("@routr/common");
40
39
  const logger = (0, logger_1.getLogger)({ service: "registry", filePath: __filename });
41
40
  const DEFAULT_REGISTRATION_INTERVAL = 60;
42
41
  // TODO:
@@ -49,15 +48,15 @@ const DEFAULT_REGISTRATION_INTERVAL = 60;
49
48
  function registryService(config) {
50
49
  var _a;
51
50
  logger.info("starting registry service");
52
- const registerInterval = (_a = config.registerInterval) !== null && _a !== void 0 ? _a : DEFAULT_REGISTRATION_INTERVAL;
53
51
  const store = (0, utils_1.buildStore)(config);
52
+ const dataAPI = common_1.CommonConnect.apiClient({ apiAddr: config.apiAddr });
53
+ const registerInterval = (_a = config.registerInterval) !== null && _a !== void 0 ? _a : DEFAULT_REGISTRATION_INTERVAL;
54
54
  // Creates internval to send registration request every X seconds
55
55
  setInterval(() => __awaiter(this, void 0, void 0, function* () {
56
56
  logger.verbose("starting registration process");
57
- let resources = [];
58
- const dataAPI = common_1.CommonConnect.dataAPI(config.apiAddr);
57
+ let trunks = [];
59
58
  try {
60
- resources = yield (0, utils_1.findTrunks)(dataAPI);
59
+ trunks = yield (0, utils_1.findTrunks)(dataAPI);
61
60
  }
62
61
  catch (err) {
63
62
  logger.error("failed to retrieve trunks from API", err);
@@ -65,10 +64,10 @@ function registryService(config) {
65
64
  }
66
65
  // Create a list of trunks in the Store
67
66
  const trunksInStore = (yield store.list()).map((r) => r.trunkRef);
68
- const registryInvocations = resources
69
- .filter((resources) => !trunksInStore.includes(resources.ref))
70
- .map((resource) => __awaiter(this, void 0, void 0, function* () {
71
- const registrationRequestInput = (0, utils_1.registrationRequestInputFromTrunk)(yield (0, utils_1.convertResourceToTrunk)(dataAPI, resource), config);
67
+ const registryInvocations = trunks
68
+ .filter((trunk) => !trunksInStore.includes(trunk.ref))
69
+ .map((trunk) => __awaiter(this, void 0, void 0, function* () {
70
+ const registrationRequestInput = (0, utils_1.registrationRequestInputFromTrunk)(trunk, config);
72
71
  const request = (0, request_1.default)(registrationRequestInput);
73
72
  return (0, sender_1.sendRegisterMessage)(config.requesterAddr)(request);
74
73
  }));
@@ -80,7 +79,7 @@ function registryService(config) {
80
79
  logger.error("request rejected", result.reason);
81
80
  return;
82
81
  }
83
- if (result.value instanceof common_2.ServiceUnavailableError) {
82
+ if (result.value instanceof common_1.CommonErrors.ServiceUnavailableError) {
84
83
  logger.error("service unavailable", result.value);
85
84
  return;
86
85
  }
package/dist/utils.d.ts CHANGED
@@ -1,20 +1,18 @@
1
- import { Transport } from "@routr/common";
2
1
  import { CommonConnect as CC } from "@routr/common";
3
2
  import MemoryStore from "./memory_store";
4
3
  import RedisStore from "./redis_store";
5
4
  import { IRegistryStore, RegistryConfig, Trunk } from "./types";
6
5
  export declare function getUnregisteredTrunks(store: IRegistryStore): (trunks: Trunk[]) => Promise<Trunk[]>;
7
- export declare function findTrunks(dataAPI: CC.DataAPI): Promise<CC.Resource[]>;
6
+ export declare function findTrunks(apiClient: CC.APIClient): Promise<CC.Trunk[]>;
8
7
  export declare const configFromString: (params: string, allowedKeys: string[]) => Record<string, string | boolean>;
9
8
  export declare const buildStore: (config: RegistryConfig) => MemoryStore | RedisStore;
10
- export declare const convertResourceToTrunk: (dataAPI: CC.DataAPI, resource: CC.Resource) => Promise<Trunk>;
11
- export declare const registrationRequestInputFromTrunk: (trunk: Trunk, config: RegistryConfig) => {
9
+ export declare const registrationRequestInputFromTrunk: (trunk: CC.Trunk, config: RegistryConfig) => {
12
10
  trunkRef: string;
13
11
  user: string;
14
12
  targetDomain: string;
15
13
  targetAddress: string;
16
14
  proxyAddress: string;
17
- transport: Transport;
15
+ transport: import("@routr/common").Transport;
18
16
  auth: {
19
17
  username: string;
20
18
  secret: string;
package/dist/utils.js CHANGED
@@ -12,27 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.registrationRequestInputFromTrunk = exports.convertResourceToTrunk = exports.buildStore = exports.configFromString = exports.findTrunks = exports.getUnregisteredTrunks = void 0;
16
- /*
17
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
18
- * http://github.com/fonoster
19
- *
20
- * This file is part of Routr.
21
- *
22
- * Licensed under the MIT License (the "License");
23
- * you may not use this file except in compliance with
24
- * the License. You may obtain a copy of the License at
25
- *
26
- * https://opensource.org/licenses/MIT
27
- *
28
- * Unless required by applicable law or agreed to in writing, software
29
- * distributed under the License is distributed on an "AS IS" BASIS,
30
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
- * See the License for the specific language governing permissions and
32
- * limitations under the License.
33
- */
34
- const common_1 = require("@routr/common");
35
- const common_2 = require("@routr/common");
15
+ exports.registrationRequestInputFromTrunk = exports.buildStore = exports.configFromString = exports.findTrunks = exports.getUnregisteredTrunks = void 0;
36
16
  const memory_store_1 = __importDefault(require("./memory_store"));
37
17
  const redis_store_1 = __importDefault(require("./redis_store"));
38
18
  const types_1 = require("./types");
@@ -47,13 +27,12 @@ function getUnregisteredTrunks(store) {
47
27
  }
48
28
  exports.getUnregisteredTrunks = getUnregisteredTrunks;
49
29
  // eslint-disable-next-line require-jsdoc
50
- function findTrunks(dataAPI) {
30
+ function findTrunks(apiClient) {
51
31
  return __awaiter(this, void 0, void 0, function* () {
52
- return yield dataAPI.findBy({
53
- kind: common_2.CommonConnect.Kind.TRUNK,
54
- criteria: common_2.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER,
55
- parameters: {}
56
- });
32
+ return (yield apiClient.trunks.findBy({
33
+ fieldName: "sendRegister",
34
+ fieldValue: "true"
35
+ })).items;
57
36
  });
58
37
  }
59
38
  exports.findTrunks = findTrunks;
@@ -89,42 +68,21 @@ const buildStore = (config) => {
89
68
  }
90
69
  };
91
70
  exports.buildStore = buildStore;
92
- const convertResourceToTrunk = (dataAPI, resource) => __awaiter(void 0, void 0, void 0, function* () {
93
- var _a, _b, _c;
94
- const metadata = resource.metadata;
95
- const trunkSpec = resource.spec;
96
- if (!trunkSpec.outbound) {
97
- throw new Error(`trunk ${resource.ref} has no outbound settings`);
98
- }
99
- const uri = trunkSpec.outbound.uris[0].uri;
100
- // WARNING: Perhaps we should bring this on a single API call
101
- const cred = yield dataAPI.get(trunkSpec.outbound.credentialsRef);
102
- const usernameAndPassword = cred === null || cred === void 0 ? void 0 : cred.spec.credentials;
103
- return {
104
- ref: resource.ref,
105
- name: resource.metadata.name,
106
- region: metadata.region,
107
- host: uri.host,
108
- port: (_a = uri.port) !== null && _a !== void 0 ? _a : 5060,
109
- user: uri.user,
110
- credentials: {
111
- username: usernameAndPassword === null || usernameAndPassword === void 0 ? void 0 : usernameAndPassword.username,
112
- secret: usernameAndPassword === null || usernameAndPassword === void 0 ? void 0 : usernameAndPassword.password
113
- },
114
- transport: (_c = (_b = uri.transport) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : common_1.Transport.UDP
115
- };
116
- });
117
- exports.convertResourceToTrunk = convertResourceToTrunk;
118
71
  const registrationRequestInputFromTrunk = (trunk, config) => {
72
+ var _a, _b;
73
+ const uri = trunk.uris[0];
119
74
  return {
120
75
  trunkRef: trunk.ref,
121
- user: trunk.user,
122
- targetDomain: trunk.host,
123
- targetAddress: `${trunk.host}:${trunk.port}`,
76
+ user: uri.user,
77
+ targetDomain: uri.host,
78
+ targetAddress: `${uri.host}:${uri.port}`,
124
79
  // TODO: Find closest edgeport instead of [0]
125
80
  proxyAddress: config.edgePorts[0].address,
126
- transport: trunk.transport,
127
- auth: trunk.credentials,
81
+ transport: uri.transport,
82
+ auth: {
83
+ username: (_a = trunk.outboundCredentials) === null || _a === void 0 ? void 0 : _a.username,
84
+ secret: (_b = trunk.outboundCredentials) === null || _b === void 0 ? void 0 : _b.password
85
+ },
128
86
  methods: config.methods
129
87
  };
130
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/registry",
3
- "version": "2.0.8-alpha.13",
3
+ "version": "2.0.8-alpha.15",
4
4
  "description": "Sends trunks registrations and maintains their bindings",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -34,8 +34,8 @@
34
34
  "@opentelemetry/sdk-trace-base": "^1.0.4",
35
35
  "@opentelemetry/sdk-trace-node": "^1.0.4",
36
36
  "@opentelemetry/semantic-conventions": "^1.0.4",
37
- "@routr/common": "^2.0.8-alpha.13",
38
- "@routr/processor": "^2.0.8-alpha.13",
37
+ "@routr/common": "^2.0.8-alpha.15",
38
+ "@routr/processor": "^2.0.8-alpha.15",
39
39
  "ajv": "^6.12.6",
40
40
  "fp-ts": "^2.11.8",
41
41
  "pb-util": "^1.0.3",
@@ -52,5 +52,5 @@
52
52
  "devDependencies": {
53
53
  "@types/uniqid": "^5.3.2"
54
54
  },
55
- "gitHead": "d866d6c03c5ea7e8fc3ee074804005df3a5be42f"
55
+ "gitHead": "713d176551252a157b5a7693ef8dba4e3e798dea"
56
56
  }