@routr/registry 2.0.5-alpha.23 → 2.0.6-alpha.1

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/request.js CHANGED
@@ -34,10 +34,10 @@ let cseq = 1;
34
34
  * @return {RegistrationRequest}
35
35
  */
36
36
  function createRegistrationRequest(params) {
37
- var _a;
37
+ var _a, _b, _c, _d, _e;
38
38
  const credentials = params.auth
39
39
  ? {
40
- name: "X-Gateway-Auth",
40
+ name: common_1.CommonTypes.ExtraHeader.GATEWAY_AUTH,
41
41
  value: Buffer.from(`${params.auth.username}:${params.auth.secret}`).toString("base64")
42
42
  }
43
43
  : undefined;
@@ -49,9 +49,9 @@ function createRegistrationRequest(params) {
49
49
  user: params.user,
50
50
  message: {
51
51
  extensions: [
52
- ...(((_a = params.methods) === null || _a === void 0 ? void 0 : _a.map((value) => {
52
+ ...((_b = (_a = params.methods) === null || _a === void 0 ? void 0 : _a.map((value) => {
53
53
  return { name: "Allow", value };
54
- })) || []),
54
+ })) !== null && _b !== void 0 ? _b : []),
55
55
  {
56
56
  name: "CSeq",
57
57
  value: `${cseq++} ${common_1.Method.REGISTER}`
@@ -59,7 +59,7 @@ function createRegistrationRequest(params) {
59
59
  {
60
60
  name: "User-Agent",
61
61
  // TODO: Take from central location (commons?)
62
- value: params.userAgent || "Routr Connect v2"
62
+ value: (_c = params.userAgent) !== null && _c !== void 0 ? _c : "Routr Connect v2"
63
63
  },
64
64
  // TODO: Q. Should this be in the registry configuration?
65
65
  {
@@ -122,10 +122,10 @@ function createRegistrationRequest(params) {
122
122
  contentLength: 0
123
123
  },
124
124
  expires: {
125
- expires: params.expires || types_1.DEFAULT_EXPIRES
125
+ expires: (_d = params.expires) !== null && _d !== void 0 ? _d : types_1.DEFAULT_EXPIRES
126
126
  },
127
127
  maxForwards: {
128
- maxForwards: params.maxForwards || types_1.DEFAULT_MAX_FORWARDS
128
+ maxForwards: (_e = params.maxForwards) !== null && _e !== void 0 ? _e : types_1.DEFAULT_MAX_FORWARDS
129
129
  },
130
130
  requestUri: {
131
131
  user: params.user,
@@ -135,7 +135,7 @@ function createRegistrationRequest(params) {
135
135
  methodParam: common_1.Method.REGISTER,
136
136
  secure: params.secure
137
137
  },
138
- messageType: "requestUri"
138
+ messageType: common_1.CommonTypes.MessageType.REQUEST
139
139
  }
140
140
  };
141
141
  }
package/dist/service.js CHANGED
@@ -47,8 +47,9 @@ const DEFAULT_REGISTRATION_INTERVAL = 60;
47
47
  * @param {RegistryConfig} config
48
48
  */
49
49
  function registryService(config) {
50
+ var _a;
50
51
  logger.info("starting registry service");
51
- const registerInterval = config.registerInterval || DEFAULT_REGISTRATION_INTERVAL;
52
+ const registerInterval = (_a = config.registerInterval) !== null && _a !== void 0 ? _a : DEFAULT_REGISTRATION_INTERVAL;
52
53
  const store = (0, utils_1.buildStore)(config);
53
54
  // Creates internval to send registration request every X seconds
54
55
  setInterval(() => __awaiter(this, void 0, void 0, function* () {
@@ -73,7 +74,7 @@ function registryService(config) {
73
74
  }));
74
75
  const results = yield Promise.allSettled(registryInvocations);
75
76
  results === null || results === void 0 ? void 0 : results.forEach((result) => __awaiter(this, void 0, void 0, function* () {
76
- var _a, _b;
77
+ var _b, _c, _d, _e;
77
78
  logger.verbose("processing registration result", { result });
78
79
  if (result.status === "rejected") {
79
80
  logger.error("request rejected", result.reason);
@@ -85,9 +86,7 @@ function registryService(config) {
85
86
  }
86
87
  const message = result.value.message;
87
88
  // Makes sure we send register before the last register expires
88
- const retentionTime = (((_a = message.contact) === null || _a === void 0 ? void 0 : _a.expires) ||
89
- ((_b = message.expires) === null || _b === void 0 ? void 0 : _b.expires) ||
90
- types_1.DEFAULT_EXPIRES) - registerInterval;
89
+ const retentionTime = ((_e = (_c = (_b = message.contact) === null || _b === void 0 ? void 0 : _b.expires) !== null && _c !== void 0 ? _c : (_d = message.expires) === null || _d === void 0 ? void 0 : _d.expires) !== null && _e !== void 0 ? _e : types_1.DEFAULT_EXPIRES) - registerInterval;
91
90
  // TODO: Refactor to use ResponseType instead of string
92
91
  const status = message.responseType.toString() == "OK"
93
92
  ? types_1.RegistrationEntryStatus.REGISTERED
package/dist/utils.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -36,12 +13,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
13
  };
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
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
+ */
39
34
  const common_1 = require("@routr/common");
35
+ const common_2 = require("@routr/common");
40
36
  const memory_store_1 = __importDefault(require("./memory_store"));
41
37
  const redis_store_1 = __importDefault(require("./redis_store"));
42
38
  const types_1 = require("./types");
43
- const protobufUtil = __importStar(require("pb-util"));
44
- const jsonFromStruct = protobufUtil.struct.decode;
45
39
  // eslint-disable-next-line require-jsdoc
46
40
  function getUnregisteredTrunks(store) {
47
41
  return (trunks) => __awaiter(this, void 0, void 0, function* () {
@@ -56,8 +50,8 @@ exports.getUnregisteredTrunks = getUnregisteredTrunks;
56
50
  function findTrunks(dataAPI) {
57
51
  return __awaiter(this, void 0, void 0, function* () {
58
52
  return yield dataAPI.findBy({
59
- kind: common_1.CommonConnect.KIND.TRUNK,
60
- criteria: common_1.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER,
53
+ kind: common_2.CommonConnect.KIND.TRUNK,
54
+ criteria: common_2.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER,
61
55
  parameters: {}
62
56
  });
63
57
  });
@@ -96,26 +90,26 @@ const buildStore = (config) => {
96
90
  };
97
91
  exports.buildStore = buildStore;
98
92
  const convertResourceToTrunk = (dataAPI, resource) => __awaiter(void 0, void 0, void 0, function* () {
99
- var _a, _b, _c, _d;
93
+ var _a, _b, _c, _d, _e, _f;
100
94
  const metadata = resource.metadata;
101
- const trunkSpec = jsonFromStruct(resource.spec);
95
+ const trunkSpec = resource.spec;
102
96
  const uri = (_b = (_a = trunkSpec.outbound) === null || _a === void 0 ? void 0 : _a.uris[0]) === null || _b === void 0 ? void 0 : _b.uri;
103
97
  // WARNING: Perhaps we should bring this on a single API call
104
- const credentials = yield dataAPI.get((_c = trunkSpec.outbound) === null || _c === void 0 ? void 0 : _c.credentialsRef);
105
- const credSpec = jsonFromStruct(credentials.spec);
106
- const usernameAndPassword = credSpec.credentials;
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;
107
100
  return {
108
101
  ref: resource.metadata.ref,
109
102
  name: resource.metadata.name,
110
103
  region: metadata.region,
111
104
  host: uri.host,
112
- port: uri.port || 5060,
105
+ port: (_d = uri.port) !== null && _d !== void 0 ? _d : 5060,
113
106
  user: uri.user,
114
107
  credentials: {
115
- username: usernameAndPassword.username,
116
- secret: usernameAndPassword.password
108
+ username: usernameAndPassword === null || usernameAndPassword === void 0 ? void 0 : usernameAndPassword.username,
109
+ secret: usernameAndPassword === null || usernameAndPassword === void 0 ? void 0 : usernameAndPassword.password
117
110
  },
118
- transport: (((_d = uri.transport) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || "TCP")
111
+ // Q. Why default to TCP?
112
+ transport: ((_f = (_e = uri.transport) === null || _e === void 0 ? void 0 : _e.toUpperCase()) !== null && _f !== void 0 ? _f : common_1.Transport.TCP)
119
113
  };
120
114
  });
121
115
  exports.convertResourceToTrunk = convertResourceToTrunk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/registry",
3
- "version": "2.0.5-alpha.23",
3
+ "version": "2.0.6-alpha.1",
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.5-alpha.23",
38
- "@routr/processor": "^2.0.5-alpha.23",
37
+ "@routr/common": "^2.0.6-alpha.1",
38
+ "@routr/processor": "^2.0.6-alpha.1",
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": "318a9433328b89e7c50d0826ecff715ceb6f66dc"
55
+ "gitHead": "389513636bbac9ab7ffbe14f1b8ecdb5bb93bad4"
56
56
  }