@routr/common 2.13.20 → 2.15.2
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/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/dist/response.d.ts +14 -0
- package/dist/response.js +21 -1
- package/dist/service.d.ts +3 -0
- package/dist/service.js +6 -4
- package/dist/tracer.d.ts +16 -3
- package/dist/tracer.js +45 -11
- package/package.json +12 -13
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/response.d.ts
CHANGED
|
@@ -38,3 +38,17 @@ export declare const createForbiddenResponse: (metadata?: Record<string, string>
|
|
|
38
38
|
reasonPhrase: string;
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
+
export declare const createBadRequestResponse: (reasonPhrase?: string, metadata?: Record<string, string>) => {
|
|
42
|
+
metadata: Record<string, string>;
|
|
43
|
+
message: {
|
|
44
|
+
responseType: ResponseType;
|
|
45
|
+
reasonPhrase: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export declare const createNotFoundResponse: (reasonPhrase?: string, metadata?: Record<string, string>) => {
|
|
49
|
+
metadata: Record<string, string>;
|
|
50
|
+
message: {
|
|
51
|
+
responseType: ResponseType;
|
|
52
|
+
reasonPhrase: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
package/dist/response.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createForbiddenResponse = exports.createServerInternalErrorResponse = exports.createUnauthorizedResponseWithoutChallenge = exports.createUnauthorizedResponse = void 0;
|
|
3
|
+
exports.createNotFoundResponse = exports.createBadRequestResponse = exports.createForbiddenResponse = exports.createServerInternalErrorResponse = exports.createUnauthorizedResponseWithoutChallenge = exports.createUnauthorizedResponse = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/routr
|
|
@@ -69,3 +69,23 @@ const createForbiddenResponse = (metadata) => {
|
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
exports.createForbiddenResponse = createForbiddenResponse;
|
|
72
|
+
const createBadRequestResponse = (reasonPhrase = "Bad Request", metadata) => {
|
|
73
|
+
return {
|
|
74
|
+
metadata,
|
|
75
|
+
message: {
|
|
76
|
+
responseType: types_1.ResponseType.BAD_REQUEST,
|
|
77
|
+
reasonPhrase
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
exports.createBadRequestResponse = createBadRequestResponse;
|
|
82
|
+
const createNotFoundResponse = (reasonPhrase = "Not Found", metadata) => {
|
|
83
|
+
return {
|
|
84
|
+
metadata,
|
|
85
|
+
message: {
|
|
86
|
+
responseType: types_1.ResponseType.NOT_FOUND,
|
|
87
|
+
reasonPhrase
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.createNotFoundResponse = createNotFoundResponse;
|
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("",
|
|
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(
|
|
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
|
-
*
|
|
3
|
+
* Whether tracing is on: an OTLP endpoint is configured and the SDK is not disabled.
|
|
3
4
|
*
|
|
4
|
-
* @param {
|
|
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):
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
*
|
|
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
|
|
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:
|
|
42
|
-
[semantic_conventions_1.
|
|
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.
|
|
3
|
+
"version": "2.15.2",
|
|
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.
|
|
17
|
+
"@grpc/grpc-js": "~1.14.6",
|
|
19
18
|
"@grpc/proto-loader": "~0.7.10",
|
|
20
|
-
"@opentelemetry/api": "^1.0
|
|
21
|
-
"@opentelemetry/exporter-
|
|
22
|
-
"@opentelemetry/instrumentation": "^0.
|
|
23
|
-
"@opentelemetry/instrumentation-grpc": "^0.
|
|
24
|
-
"@opentelemetry/resources": "^
|
|
25
|
-
"@opentelemetry/sdk-trace-base": "^
|
|
26
|
-
"@opentelemetry/sdk-trace-node": "^
|
|
27
|
-
"@opentelemetry/semantic-conventions": "^1.0
|
|
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,7 @@
|
|
|
32
31
|
"js-yaml": "^4.1.1",
|
|
33
32
|
"pb-util": "^1.0.3",
|
|
34
33
|
"phone": "^3.1.68",
|
|
35
|
-
"toml": "^
|
|
34
|
+
"toml": "^5.0.1",
|
|
36
35
|
"validator": "^13.15.26"
|
|
37
36
|
},
|
|
38
37
|
"directories": {
|
|
@@ -55,5 +54,5 @@
|
|
|
55
54
|
"devDependencies": {
|
|
56
55
|
"@types/js-yaml": "^4.0.5"
|
|
57
56
|
},
|
|
58
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "012332304537f623d017dffdf4911910fb27c0e0"
|
|
59
58
|
}
|