@routr/common 2.15.0 → 2.15.3

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/helper.d.ts CHANGED
@@ -16,11 +16,11 @@ export declare const deepCopy: <T>(source: T) => T;
16
16
  export declare const getListeningPoint: (listeningPoints: NetInterface[], transport: Transport) => NetInterface;
17
17
  /**
18
18
  * Reads a file and returns a JSON object or throws an error.
19
- * The file must be a valid JSON, YAML, or TOML file.
19
+ * The file must be a valid JSON or YAML file.
20
20
  *
21
21
  * @param {string} path - The path to the file.
22
22
  * @return {object} The JSON object.
23
- * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
23
+ * @throws {Error} If the file is not a valid JSON or YAML file.
24
24
  * @throws {Error} If the file does not exist.
25
25
  * @throws {Error} If the file is not readable.
26
26
  * @throws {Error} If the file is empty.
package/dist/helper.js CHANGED
@@ -56,7 +56,6 @@ exports.toPascalCase = exports.readConfigFile = exports.getListeningPoint = expo
56
56
  * limitations under the License.
57
57
  */
58
58
  const yaml = __importStar(require("js-yaml"));
59
- const toml = __importStar(require("toml"));
60
59
  const fs_1 = __importDefault(require("fs"));
61
60
  const types_1 = require("./types");
62
61
  /**
@@ -105,11 +104,11 @@ const getListeningPoint = (listeningPoints, transport) => {
105
104
  exports.getListeningPoint = getListeningPoint;
106
105
  /**
107
106
  * Reads a file and returns a JSON object or throws an error.
108
- * The file must be a valid JSON, YAML, or TOML file.
107
+ * The file must be a valid JSON or YAML file.
109
108
  *
110
109
  * @param {string} path - The path to the file.
111
110
  * @return {object} The JSON object.
112
- * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
111
+ * @throws {Error} If the file is not a valid JSON or YAML file.
113
112
  * @throws {Error} If the file does not exist.
114
113
  * @throws {Error} If the file is not readable.
115
114
  * @throws {Error} If the file is empty.
@@ -125,13 +124,6 @@ const readConfigFile = (path) => {
125
124
  catch (e) {
126
125
  // Ignore
127
126
  }
128
- // Experimental TOML support
129
- try {
130
- return toml.parse(content);
131
- }
132
- catch (e) {
133
- // Ignore
134
- }
135
127
  try {
136
128
  return JSON.parse(content);
137
129
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import createService, { getObjectProto, LOCATION_OBJECT_PROTO, PROCESSOR_OBJECT_PROTO } from "./service";
1
+ import createService, { getObjectProto, GRPC_SERVING_STATUS, statusMap, LOCATION_OBJECT_PROTO, PROCESSOR_OBJECT_PROTO } from "./service";
2
2
  import { HeaderModifier, MessageRequest, MessageResponse, Method, NetInterface, ObjectProto, ProcessorConfig, Route, ServiceInfo, Transport } from "./types";
3
- export { createService, getObjectProto, HeaderModifier, Route, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
3
+ export { createService, getObjectProto, HeaderModifier, Route, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO, GRPC_SERVING_STATUS, statusMap };
4
4
  export * as Auth from "./auth";
5
5
  export * as Redis from "./redis";
6
6
  export * as Helper from "./helper";
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Verifier = exports.Environment = exports.ConnectSchemas = exports.CommonErrors = exports.CommonTypes = exports.CommonResponse = exports.CommonRequester = exports.CommonConnect = exports.Assertions = exports.Tracer = exports.IpUtils = exports.Helper = exports.Redis = exports.Auth = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.getObjectProto = exports.createService = void 0;
36
+ exports.Verifier = exports.Environment = exports.ConnectSchemas = exports.CommonErrors = exports.CommonTypes = exports.CommonResponse = exports.CommonRequester = exports.CommonConnect = exports.Assertions = exports.Tracer = exports.IpUtils = exports.Helper = exports.Redis = exports.Auth = exports.statusMap = exports.GRPC_SERVING_STATUS = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.getObjectProto = exports.createService = void 0;
37
37
  /*
38
38
  * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
39
39
  * http://github.com/fonoster/routr
@@ -55,6 +55,8 @@ exports.Verifier = exports.Environment = exports.ConnectSchemas = exports.Common
55
55
  const service_1 = __importStar(require("./service"));
56
56
  exports.createService = service_1.default;
57
57
  Object.defineProperty(exports, "getObjectProto", { enumerable: true, get: function () { return service_1.getObjectProto; } });
58
+ Object.defineProperty(exports, "GRPC_SERVING_STATUS", { enumerable: true, get: function () { return service_1.GRPC_SERVING_STATUS; } });
59
+ Object.defineProperty(exports, "statusMap", { enumerable: true, get: function () { return service_1.statusMap; } });
58
60
  Object.defineProperty(exports, "LOCATION_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.LOCATION_OBJECT_PROTO; } });
59
61
  Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.PROCESSOR_OBJECT_PROTO; } });
60
62
  const types_1 = require("./types");
package/dist/service.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { ObjectProto, ServiceInfo } from "./types";
2
2
  import { ServiceDefinitionNotFoundError } from "./errors";
3
+ import { ServingStatusMap } from "grpc-health-check";
4
+ export declare const GRPC_SERVING_STATUS = "SERVING";
5
+ export declare const statusMap: ServingStatusMap;
3
6
  export declare const protoLoadOptions: {
4
7
  keepCase: boolean;
5
8
  longs: StringConstructor;
package/dist/service.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.protoLoadOptions = void 0;
36
+ exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.protoLoadOptions = exports.statusMap = exports.GRPC_SERVING_STATUS = void 0;
37
37
  exports.getObjectProto = getObjectProto;
38
38
  exports.default = createService;
39
39
  /*
@@ -59,8 +59,10 @@ const protoLoader = __importStar(require("@grpc/proto-loader"));
59
59
  const errors_1 = require("./errors");
60
60
  const logger_1 = require("@fonoster/logger");
61
61
  const grpc_health_check_1 = require("grpc-health-check");
62
- const common_1 = require("@fonoster/common");
63
62
  const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
63
+ exports.GRPC_SERVING_STATUS = "SERVING";
64
+ // By convention, the empty string represents the entire server
65
+ exports.statusMap = { "": "NOT_SERVING" };
64
66
  exports.protoLoadOptions = {
65
67
  keepCase: false,
66
68
  longs: String,
@@ -103,7 +105,7 @@ function getObjectProto(objectProto) {
103
105
  */
104
106
  function createService(serviceInfo) {
105
107
  const cb = () => {
106
- healthImpl.setStatus("", common_1.GRPC_SERVING_STATUS);
108
+ healthImpl.setStatus("", exports.GRPC_SERVING_STATUS);
107
109
  logger.info("starting routr service", {
108
110
  name: serviceInfo.name,
109
111
  bindAddr: serviceInfo.bindAddr
@@ -112,7 +114,7 @@ function createService(serviceInfo) {
112
114
  const credentials = grpc.ServerCredentials.createInsecure();
113
115
  const server = new grpc.Server();
114
116
  server.addService(serviceInfo.service, serviceInfo.handlers);
115
- const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
117
+ const healthImpl = new grpc_health_check_1.HealthImplementation(exports.statusMap);
116
118
  // Add the health check service to the server
117
119
  healthImpl.addToServer(server);
118
120
  server.bindAsync(serviceInfo.bindAddr, credentials, cb);
package/dist/tracer.d.ts CHANGED
@@ -1,7 +1,20 @@
1
+ import { Tracer } from "@opentelemetry/api";
1
2
  /**
2
- * This function registers the instrumentations for the service.
3
+ * Whether tracing is on: an OTLP endpoint is configured and the SDK is not disabled.
3
4
  *
4
- * @param {string} serviceName - The name of the service.
5
+ * @param {NodeJS.ProcessEnv} env - The environment to read.
6
+ * @return {boolean} True when spans should be exported.
7
+ */
8
+ export declare function tracingEnabled(env?: NodeJS.ProcessEnv): boolean;
9
+ /**
10
+ * Starts tracing for the service, exporting spans over OTLP/HTTP to the endpoint in the
11
+ * standard OTEL_EXPORTER_OTLP_* variables. Without one it registers nothing and returns a
12
+ * no-op tracer. Call it before anything loads @grpc/grpc-js, so the gRPC instrumentation
13
+ * can propagate the W3C trace context between services. Only the first call in a process
14
+ * starts tracing (Routr One loads several services).
15
+ *
16
+ * @param {string} serviceName - The service's name, unless OTEL_SERVICE_NAME is set.
17
+ * @param {NodeJS.ProcessEnv} env - The environment to read.
5
18
  * @return {Tracer} The tracer object.
6
19
  */
7
- export declare function init(serviceName: string): import("@opentelemetry/api").Tracer;
20
+ export declare function init(serviceName: string, env?: NodeJS.ProcessEnv): Tracer;
package/dist/tracer.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tracingEnabled = tracingEnabled;
6
7
  exports.init = init;
7
8
  /*
8
9
  * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
@@ -24,26 +25,59 @@ exports.init = init;
24
25
  */
25
26
  const api_1 = __importDefault(require("@opentelemetry/api"));
26
27
  const instrumentation_1 = require("@opentelemetry/instrumentation");
28
+ const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
27
29
  const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
30
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
28
31
  const resources_1 = require("@opentelemetry/resources");
29
32
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
30
- const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
31
- const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
32
- const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
33
+ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
34
+ /**
35
+ * Whether tracing is on: an OTLP endpoint is configured and the SDK is not disabled.
36
+ *
37
+ * @param {NodeJS.ProcessEnv} env - The environment to read.
38
+ * @return {boolean} True when spans should be exported.
39
+ */
40
+ function tracingEnabled(env = process.env) {
41
+ if (env.OTEL_SDK_DISABLED === "true")
42
+ return false;
43
+ return !!(env.OTEL_EXPORTER_OTLP_ENDPOINT || env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT);
44
+ }
45
+ /**
46
+ * The traces endpoint, as the OTLP exporter would derive it from process.env.
47
+ *
48
+ * @param {NodeJS.ProcessEnv} env - The environment to read.
49
+ * @return {string} The URL spans are posted to.
50
+ */
51
+ function tracesUrl(env) {
52
+ var _a;
53
+ if (env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
54
+ return env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
55
+ return `${(_a = env.OTEL_EXPORTER_OTLP_ENDPOINT) === null || _a === void 0 ? void 0 : _a.replace(/\/$/, "")}/v1/traces`;
56
+ }
57
+ let started = false;
33
58
  /**
34
- * This function registers the instrumentations for the service.
59
+ * Starts tracing for the service, exporting spans over OTLP/HTTP to the endpoint in the
60
+ * standard OTEL_EXPORTER_OTLP_* variables. Without one it registers nothing and returns a
61
+ * no-op tracer. Call it before anything loads @grpc/grpc-js, so the gRPC instrumentation
62
+ * can propagate the W3C trace context between services. Only the first call in a process
63
+ * starts tracing (Routr One loads several services).
35
64
  *
36
- * @param {string} serviceName - The name of the service.
65
+ * @param {string} serviceName - The service's name, unless OTEL_SERVICE_NAME is set.
66
+ * @param {NodeJS.ProcessEnv} env - The environment to read.
37
67
  * @return {Tracer} The tracer object.
38
68
  */
39
- function init(serviceName) {
69
+ function init(serviceName, env = process.env) {
70
+ if (started || !tracingEnabled(env))
71
+ return api_1.default.trace.getTracer("routr-tracer");
72
+ started = true;
40
73
  const provider = new sdk_trace_node_1.NodeTracerProvider({
41
- resource: new resources_1.Resource({
42
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
43
- })
74
+ resource: (0, resources_1.resourceFromAttributes)({
75
+ [semantic_conventions_1.ATTR_SERVICE_NAME]: env.OTEL_SERVICE_NAME || serviceName
76
+ }),
77
+ spanProcessors: [
78
+ new sdk_trace_base_1.BatchSpanProcessor(new exporter_trace_otlp_http_1.OTLPTraceExporter({ url: tracesUrl(env) }))
79
+ ]
44
80
  });
45
- const exporter = new exporter_jaeger_1.JaegerExporter();
46
- provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
47
81
  provider.register();
48
82
  (0, instrumentation_1.registerInstrumentations)({
49
83
  instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/common",
3
- "version": "2.15.0",
3
+ "version": "2.15.3",
4
4
  "description": "Common package",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -13,18 +13,17 @@
13
13
  "postbuild": "cp -a src/protos dist/protos && cp -a src/connect/protos dist/connect/protos"
14
14
  },
15
15
  "dependencies": {
16
- "@fonoster/common": "0.6.0",
17
16
  "@fonoster/logger": "0.6.0",
18
- "@grpc/grpc-js": "~1.10.1",
17
+ "@grpc/grpc-js": "~1.14.6",
19
18
  "@grpc/proto-loader": "~0.7.10",
20
- "@opentelemetry/api": "^1.0.4",
21
- "@opentelemetry/exporter-jaeger": "^1.0.4",
22
- "@opentelemetry/instrumentation": "^0.27.0",
23
- "@opentelemetry/instrumentation-grpc": "^0.27.0",
24
- "@opentelemetry/resources": "^1.0.4",
25
- "@opentelemetry/sdk-trace-base": "^1.0.4",
26
- "@opentelemetry/sdk-trace-node": "^1.0.4",
27
- "@opentelemetry/semantic-conventions": "^1.0.4",
19
+ "@opentelemetry/api": "^1.9.0",
20
+ "@opentelemetry/exporter-trace-otlp-http": "^0.223.0",
21
+ "@opentelemetry/instrumentation": "^0.223.0",
22
+ "@opentelemetry/instrumentation-grpc": "^0.223.0",
23
+ "@opentelemetry/resources": "^2.12.0",
24
+ "@opentelemetry/sdk-trace-base": "^2.12.0",
25
+ "@opentelemetry/sdk-trace-node": "^2.12.0",
26
+ "@opentelemetry/semantic-conventions": "^1.43.0",
28
27
  "ajv": "^6.12.6",
29
28
  "fp-ts": "^2.11.8",
30
29
  "grpc-health-check": "^2.1.0",
@@ -32,7 +31,6 @@
32
31
  "js-yaml": "^4.1.1",
33
32
  "pb-util": "^1.0.3",
34
33
  "phone": "^3.1.68",
35
- "toml": "^3.0.0",
36
34
  "validator": "^13.15.26"
37
35
  },
38
36
  "directories": {
@@ -55,5 +53,5 @@
55
53
  "devDependencies": {
56
54
  "@types/js-yaml": "^4.0.5"
57
55
  },
58
- "gitHead": "4cfe8529e9325b7a2f32aff615cf3db65c71cf29"
56
+ "gitHead": "30e73f1331f115b2dd9d02cdfdcf931dbeede36b"
59
57
  }