@routr/edgeport 2.0.8-alpha.9 → 2.0.9

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.
@@ -21,8 +21,15 @@ const assertNoDuplicatedProto = (transports) => {
21
21
  exports.assertNoDuplicatedProto = assertNoDuplicatedProto;
22
22
  // The only protocol that can accept the same port twice are udp and tcp
23
23
  const assertNoDuplicatedPort = (transports) => {
24
- const duplicateCondition = (t1, t2) => t1.port === t2.port && t1.protocol !== "udp" && t1.protocol !== "tcp";
25
- if (transports.some((t1) => transports.filter((t2) => duplicateCondition(t1, t2)).length > 1)) {
24
+ const duplicateCondition = (t1, t2) => t1.port === t2.port && t1.protocol !== "UDP" && t1.protocol !== "TCP";
25
+ if (transports
26
+ .map((t) => {
27
+ return {
28
+ port: t.port,
29
+ protocol: t.protocol.toUpperCase()
30
+ };
31
+ })
32
+ .some((t1) => transports.filter((t2) => duplicateCondition(t1, t2)).length > 1)) {
26
33
  throw new Error("found the same port on more that one entry at .spec.transport");
27
34
  }
28
35
  };
@@ -1,2 +1,16 @@
1
+ import { JsonObject } from "pb-util/build";
1
2
  export declare const readFile: (path: string) => string;
2
- export declare const writeFile: (path: string, text: string) => void;
3
+ export declare const exists: (path: string) => any;
4
+ export declare const isFile: (path: string) => any;
5
+ /**
6
+ * Reads a file and returns a JSON object or throws an error.
7
+ * The file must be a valid JSON, YAML, or TOML file.
8
+ *
9
+ * @param {string} path - The path to the file.
10
+ * @return {object} The JSON object.
11
+ * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
12
+ * @throws {Error} If the file does not exist.
13
+ * @throws {Error} If the file is not readable.
14
+ * @throws {Error} If the file is empty.
15
+ */
16
+ export declare const readConfigFile: (path: string) => JsonObject;
package/dist/config/fs.js CHANGED
@@ -1,8 +1,31 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeFile = exports.readFile = void 0;
4
- const BufferedWriter = Java.type("java.io.BufferedWriter");
5
- const FileWriter = Java.type("java.io.FileWriter");
26
+ exports.readConfigFile = exports.isFile = exports.exists = exports.readFile = void 0;
27
+ const yaml = __importStar(require("js-yaml"));
28
+ const toml = __importStar(require("toml"));
6
29
  const JFile = Java.type("java.io.File");
7
30
  const Files = Java.type("java.nio.file.Files");
8
31
  const Paths = Java.type("java.nio.file.Paths");
@@ -15,10 +38,44 @@ const readFile = (path) => {
15
38
  return data.join("\n").trim();
16
39
  };
17
40
  exports.readFile = readFile;
18
- const writeFile = (path, text) => {
19
- const file = new JFile(path);
20
- const out = new BufferedWriter(new FileWriter(file));
21
- out.write(text);
22
- out.close();
41
+ const exists = (path) => new JFile(path).exists();
42
+ exports.exists = exists;
43
+ const isFile = (path) => new JFile(path).isFile();
44
+ exports.isFile = isFile;
45
+ /**
46
+ * Reads a file and returns a JSON object or throws an error.
47
+ * The file must be a valid JSON, YAML, or TOML file.
48
+ *
49
+ * @param {string} path - The path to the file.
50
+ * @return {object} The JSON object.
51
+ * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
52
+ * @throws {Error} If the file does not exist.
53
+ * @throws {Error} If the file is not readable.
54
+ * @throws {Error} If the file is empty.
55
+ */
56
+ const readConfigFile = (path) => {
57
+ if (!(0, exports.exists)(path) || !(0, exports.isFile)(path)) {
58
+ throw new Error(`config file ${path} does not exist`);
59
+ }
60
+ const content = (0, exports.readFile)(path);
61
+ try {
62
+ return yaml.load(content);
63
+ }
64
+ catch (e) {
65
+ // Ignore
66
+ }
67
+ // Experimental TOML support
68
+ try {
69
+ return toml.parse(content);
70
+ }
71
+ catch (e) {
72
+ // Ignore
73
+ }
74
+ try {
75
+ return JSON.parse(content);
76
+ }
77
+ catch (e) {
78
+ throw new Error("file is not a valid JSON or YAML file");
79
+ }
23
80
  };
24
- exports.writeFile = writeFile;
81
+ exports.readConfigFile = readConfigFile;
@@ -28,14 +28,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getConfig = exports.validateConfig = exports.readFile = void 0;
30
30
  const E = __importStar(require("fp-ts/Either"));
31
- const F = __importStar(require("./fs"));
31
+ const ajv_1 = __importDefault(require("ajv"));
32
32
  const function_1 = require("fp-ts/function");
33
33
  const schema_1 = require("./schema");
34
- const ajv_1 = __importDefault(require("ajv"));
34
+ const fs_1 = require("./fs");
35
35
  const ajv = new ajv_1.default();
36
36
  const validate = ajv.compile(schema_1.schema);
37
- // Reads a file a returns as a string
38
- const readFile = (path) => E.tryCatch(() => F.readFile(path), E.toError);
37
+ // TODO: Fix this unnecessary conversion to string
38
+ const readFile = (path) => E.tryCatch(() => JSON.stringify((0, fs_1.readConfigFile)(path)), E.toError);
39
39
  exports.readFile = readFile;
40
40
  // Validate Json with Ajv
41
41
  const validateConfig = (j) => E.tryCatch(() => {
@@ -11,20 +11,19 @@ export declare const schema: {
11
11
  apiVersion: {
12
12
  enum: string[];
13
13
  };
14
+ ref: {
15
+ description: string;
16
+ type: string;
17
+ };
14
18
  metadata: {
15
19
  description: string;
16
20
  type: string;
17
21
  properties: {
18
- ref: {
19
- description: string;
20
- type: string;
21
- };
22
22
  region: {
23
23
  description: string;
24
24
  type: string;
25
25
  };
26
26
  };
27
- required: string[];
28
27
  };
29
28
  spec: {
30
29
  description: string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schema = void 0;
4
4
  /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
@@ -30,22 +30,21 @@ exports.schema = {
30
30
  type: "string"
31
31
  },
32
32
  apiVersion: {
33
- enum: ["v2draft1", "v2.0", "v2"]
33
+ enum: ["v2beta1", "v2"]
34
+ },
35
+ ref: {
36
+ description: "EdgePort reference",
37
+ type: "string"
34
38
  },
35
39
  metadata: {
36
40
  description: "Resource metadata",
37
41
  type: "object",
38
42
  properties: {
39
- ref: {
40
- description: "EdgePort reference",
41
- type: "string"
42
- },
43
43
  region: {
44
44
  description: "Optional region where the EdgePort is operating",
45
45
  type: "string"
46
46
  }
47
- },
48
- required: ["ref"]
47
+ }
49
48
  },
50
49
  spec: {
51
50
  description: "Operation spec for the EdgePort",
@@ -117,5 +116,5 @@ exports.schema = {
117
116
  required: ["methods", "transport", "processor"]
118
117
  }
119
118
  },
120
- required: ["kind", "metadata", "spec", "apiVersion"]
119
+ required: ["kind", "ref", "spec", "apiVersion"]
121
120
  };
@@ -9,7 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  */
10
10
  function createSipProvider(sipStack, listeningPoints) {
11
11
  const sipProvider = sipStack.createSipProvider(listeningPoints[0]);
12
- listeningPoints === null || listeningPoints === void 0 ? void 0 : listeningPoints.filter((_, index) => index > 0).forEach((lp1) => {
12
+ listeningPoints
13
+ .filter((_, index) => index > 0)
14
+ .forEach((lp1) => {
13
15
  sipProvider.addListeningPoint(lp1);
14
16
  });
15
17
  return sipProvider;
package/dist/tracer.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = void 0;
7
7
  /*
8
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/edgeport",
3
- "version": "2.0.8-alpha.9",
3
+ "version": "2.0.9",
4
4
  "description": "SIP endpoint at the edge of the network",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -29,7 +29,11 @@
29
29
  "url": "https://github.com/fonoster/routr/issues"
30
30
  },
31
31
  "dependencies": {
32
- "fp-ts": "^2.11.8"
32
+ "@routr/common": "^2.0.9",
33
+ "ajv": "^6.12.6",
34
+ "fp-ts": "^2.11.8",
35
+ "js-yaml": "^4.1.0",
36
+ "toml": "^3.0.0"
33
37
  },
34
- "gitHead": "9ebb361db74fad2b3891fc9add683ddfde2efdff"
38
+ "gitHead": "62eb05f0b3bfa05d84c9ce4b4644de5fb5453295"
35
39
  }