@routr/registry 2.0.8-alpha.2 → 2.0.8-alpha.20

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.
@@ -46,29 +46,29 @@ exports.getConfig = void 0;
46
46
  * limitations under the License.
47
47
  */
48
48
  const types_1 = require("../types");
49
- const fs_1 = __importDefault(require("fs"));
50
49
  const schema_1 = require("./schema");
51
50
  const ajv_1 = __importDefault(require("ajv"));
52
51
  const E = __importStar(require("fp-ts/Either"));
53
52
  const errors_1 = require("../errors");
53
+ const common_1 = require("@routr/common");
54
54
  const ajv = new ajv_1.default();
55
55
  const validate = ajv.compile(schema_1.schema);
56
56
  const getConfig = (path) => {
57
57
  var _a, _b, _c;
58
- const c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
58
+ const c = common_1.Helper.readConfigFile(path);
59
59
  if (!validate(Object.assign({}, c))) {
60
60
  return E.left(new errors_1.InvalidSchemaConfiguration(JSON.stringify(validate.errors[0].message)));
61
61
  }
62
62
  const config = c.spec;
63
63
  if (!((_a = config === null || config === void 0 ? void 0 : config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
64
64
  config.cache = {
65
- provider: types_1.CACHE_PROVIDER.MEMORY
65
+ provider: types_1.CacheProvider.MEMORY
66
66
  };
67
67
  }
68
- if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CACHE_PROVIDER.REDIS &&
68
+ if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CacheProvider.REDIS &&
69
69
  !((_c = config === null || config === void 0 ? void 0 : config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
70
70
  config.cache = {
71
- provider: types_1.CACHE_PROVIDER.REDIS,
71
+ provider: types_1.CacheProvider.REDIS,
72
72
  parameters: "host=localhost,port=6379"
73
73
  };
74
74
  }
package/dist/request.js CHANGED
@@ -135,6 +135,8 @@ function createRegistrationRequest(params) {
135
135
  methodParam: common_1.Method.REGISTER,
136
136
  secure: params.secure
137
137
  },
138
+ via: [],
139
+ recordRoute: [],
138
140
  messageType: common_1.CommonTypes.MessageType.REQUEST
139
141
  }
140
142
  };
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/types.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Method, Transport } from "@routr/common";
2
2
  import { SIPMessage } from "@routr/common/src/types";
3
3
  export declare const DEFAULT_MAX_FORWARDS = 70;
4
4
  export declare const DEFAULT_EXPIRES = 600;
5
- export declare enum CACHE_PROVIDER {
5
+ export declare enum CacheProvider {
6
6
  MEMORY = "memory",
7
7
  REDIS = "redis"
8
8
  }
@@ -21,7 +21,7 @@ export interface RegistryConfig {
21
21
  registerInterval: number;
22
22
  methods: Method[];
23
23
  cache?: {
24
- provider: CACHE_PROVIDER;
24
+ provider: CacheProvider;
25
25
  parameters?: string;
26
26
  };
27
27
  }
package/dist/types.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RegistrationEntryStatus = exports.CACHE_PROVIDER = exports.DEFAULT_EXPIRES = exports.DEFAULT_MAX_FORWARDS = void 0;
3
+ exports.RegistrationEntryStatus = exports.CacheProvider = exports.DEFAULT_EXPIRES = exports.DEFAULT_MAX_FORWARDS = void 0;
4
4
  exports.DEFAULT_MAX_FORWARDS = 70;
5
5
  exports.DEFAULT_EXPIRES = 600;
6
- var CACHE_PROVIDER;
7
- (function (CACHE_PROVIDER) {
8
- CACHE_PROVIDER["MEMORY"] = "memory";
9
- CACHE_PROVIDER["REDIS"] = "redis";
10
- })(CACHE_PROVIDER = exports.CACHE_PROVIDER || (exports.CACHE_PROVIDER = {}));
6
+ var CacheProvider;
7
+ (function (CacheProvider) {
8
+ CacheProvider["MEMORY"] = "memory";
9
+ CacheProvider["REDIS"] = "redis";
10
+ })(CacheProvider = exports.CacheProvider || (exports.CacheProvider = {}));
11
11
  var RegistrationEntryStatus;
12
12
  (function (RegistrationEntryStatus) {
13
13
  RegistrationEntryStatus["REGISTERED"] = "registered";
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;
@@ -80,7 +59,7 @@ const configFromString = (params, allowedKeys) => {
80
59
  };
81
60
  exports.configFromString = configFromString;
82
61
  const buildStore = (config) => {
83
- if (config.cache.provider === types_1.CACHE_PROVIDER.REDIS) {
62
+ if (config.cache.provider === types_1.CacheProvider.REDIS) {
84
63
  const allowedParameters = ["host", "port", "username", "password", "secure"];
85
64
  return new redis_store_1.default((0, exports.configFromString)(config.cache.parameters, allowedParameters));
86
65
  }
@@ -89,39 +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, _d, _e, _f;
94
- const metadata = resource.metadata;
95
- const trunkSpec = resource.spec;
96
- const uri = (_b = (_a = trunkSpec.outbound) === null || _a === void 0 ? void 0 : _a.uris[0]) === null || _b === void 0 ? void 0 : _b.uri;
97
- // WARNING: Perhaps we should bring this on a single API call
98
- const cred = yield dataAPI.get((_c = trunkSpec.outbound) === null || _c === void 0 ? void 0 : _c.credentialsRef);
99
- const usernameAndPassword = cred === null || cred === void 0 ? void 0 : cred.spec.credentials;
100
- return {
101
- ref: resource.ref,
102
- name: resource.metadata.name,
103
- region: metadata.region,
104
- host: uri.host,
105
- port: (_d = uri.port) !== null && _d !== void 0 ? _d : 5060,
106
- user: uri.user,
107
- credentials: {
108
- username: usernameAndPassword === null || usernameAndPassword === void 0 ? void 0 : usernameAndPassword.username,
109
- secret: usernameAndPassword === null || usernameAndPassword === void 0 ? void 0 : usernameAndPassword.password
110
- },
111
- transport: (_f = (_e = uri.transport) === null || _e === void 0 ? void 0 : _e.toLowerCase()) !== null && _f !== void 0 ? _f : common_1.Transport.UDP
112
- };
113
- });
114
- exports.convertResourceToTrunk = convertResourceToTrunk;
115
71
  const registrationRequestInputFromTrunk = (trunk, config) => {
72
+ var _a, _b;
73
+ const uri = trunk.uris[0];
116
74
  return {
117
75
  trunkRef: trunk.ref,
118
- user: trunk.user,
119
- targetDomain: trunk.host,
120
- targetAddress: `${trunk.host}:${trunk.port}`,
76
+ user: uri.user,
77
+ targetDomain: uri.host,
78
+ targetAddress: `${uri.host}:${uri.port}`,
121
79
  // TODO: Find closest edgeport instead of [0]
122
80
  proxyAddress: config.edgePorts[0].address,
123
- transport: trunk.transport,
124
- 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
+ },
125
86
  methods: config.methods
126
87
  };
127
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/registry",
3
- "version": "2.0.8-alpha.2",
3
+ "version": "2.0.8-alpha.20",
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",
@@ -25,7 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@grpc/grpc-js": "^1.5.9",
28
+ "@grpc/grpc-js": "^1.8.4",
29
29
  "@opentelemetry/api": "^1.0.4",
30
30
  "@opentelemetry/exporter-jaeger": "^1.0.4",
31
31
  "@opentelemetry/instrumentation": "^0.27.0",
@@ -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.2",
38
- "@routr/processor": "^2.0.8-alpha.2",
37
+ "@routr/common": "^2.0.8-alpha.20",
38
+ "@routr/processor": "^2.0.8-alpha.20",
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": "28ab976b0ef8b5cd34e278ea6fda13c518d7d052"
55
+ "gitHead": "a22ee8342d03f5dfe46fddba89ffe3e6d0d5deb6"
56
56
  }