@routr/common 2.17.0 → 2.20.0

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.
Files changed (91) hide show
  1. package/dist/connect/config.d.ts +5 -1
  2. package/dist/connect/mappers/agent.js +1 -0
  3. package/dist/connect/mappers/domain.js +1 -0
  4. package/dist/connect/mappers/peer.js +1 -0
  5. package/dist/connect/mappers/trunk.js +1 -0
  6. package/dist/connect/protos/agents.proto +7 -0
  7. package/dist/connect/protos/domains.proto +7 -0
  8. package/dist/connect/protos/peers.proto +7 -0
  9. package/dist/connect/protos/trace.proto +28 -0
  10. package/dist/connect/protos/trunks.proto +7 -0
  11. package/dist/connect/schemas/agent.d.ts +10 -0
  12. package/dist/connect/schemas/agent.js +8 -0
  13. package/dist/connect/schemas/domain.d.ts +10 -0
  14. package/dist/connect/schemas/domain.js +8 -0
  15. package/dist/connect/schemas/peer.d.ts +10 -0
  16. package/dist/connect/schemas/peer.js +8 -0
  17. package/dist/connect/schemas/trunk.d.ts +10 -0
  18. package/dist/connect/schemas/trunk.js +8 -0
  19. package/dist/connect/types.d.ts +7 -0
  20. package/dist/errors.d.ts +14 -0
  21. package/dist/errors.js +19 -1
  22. package/dist/helper.js +2 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +2 -1
  25. package/dist/protos/processor.proto +4 -0
  26. package/dist/trace/compat.d.ts +37 -0
  27. package/dist/trace/compat.js +131 -0
  28. package/dist/trace/diff.d.ts +48 -0
  29. package/dist/trace/diff.js +152 -0
  30. package/dist/trace/index.d.ts +11 -0
  31. package/dist/trace/index.js +68 -0
  32. package/dist/trace/metadata.d.ts +28 -0
  33. package/dist/trace/metadata.js +75 -0
  34. package/dist/trace/normalize.d.ts +11 -0
  35. package/dist/trace/normalize.js +39 -0
  36. package/dist/trace/redact.d.ts +19 -0
  37. package/dist/trace/redact.js +52 -0
  38. package/dist/trace/rules/facts.d.ts +43 -0
  39. package/dist/trace/rules/facts.js +117 -0
  40. package/dist/trace/rules/index.d.ts +34 -0
  41. package/dist/trace/rules/index.js +153 -0
  42. package/dist/trace/rules/sip/ack-2xx.d.ts +2 -0
  43. package/dist/trace/rules/sip/ack-2xx.js +56 -0
  44. package/dist/trace/rules/sip/cancel-matches.d.ts +2 -0
  45. package/dist/trace/rules/sip/cancel-matches.js +46 -0
  46. package/dist/trace/rules/sip/credentials-stripped.d.ts +2 -0
  47. package/dist/trace/rules/sip/credentials-stripped.js +41 -0
  48. package/dist/trace/rules/sip/cseq-ack.d.ts +2 -0
  49. package/dist/trace/rules/sip/cseq-ack.js +40 -0
  50. package/dist/trace/rules/sip/cseq-monotonic.d.ts +2 -0
  51. package/dist/trace/rules/sip/cseq-monotonic.js +50 -0
  52. package/dist/trace/rules/sip/max-forwards.d.ts +2 -0
  53. package/dist/trace/rules/sip/max-forwards.js +47 -0
  54. package/dist/trace/rules/sip/private-address.d.ts +2 -0
  55. package/dist/trace/rules/sip/private-address.js +48 -0
  56. package/dist/trace/rules/sip/record-route-self.d.ts +2 -0
  57. package/dist/trace/rules/sip/record-route-self.js +46 -0
  58. package/dist/trace/rules/sip/register-ok.d.ts +2 -0
  59. package/dist/trace/rules/sip/register-ok.js +52 -0
  60. package/dist/trace/rules/sip/retransmission.d.ts +2 -0
  61. package/dist/trace/rules/sip/retransmission.js +47 -0
  62. package/dist/trace/rules/sip/route-self-removed.d.ts +2 -0
  63. package/dist/trace/rules/sip/route-self-removed.js +38 -0
  64. package/dist/trace/rules/sip/via.d.ts +2 -0
  65. package/dist/trace/rules/sip/via.js +50 -0
  66. package/dist/trace/rules/sip-connect/from-e164-or-anonymous.d.ts +2 -0
  67. package/dist/trace/rules/sip-connect/from-e164-or-anonymous.js +43 -0
  68. package/dist/trace/rules/sip-connect/pai-e164.d.ts +2 -0
  69. package/dist/trace/rules/sip-connect/pai-e164.js +44 -0
  70. package/dist/trace/rules/sip-connect/pai-single.d.ts +2 -0
  71. package/dist/trace/rules/sip-connect/pai-single.js +41 -0
  72. package/dist/trace/rules/sip-connect/privacy.d.ts +2 -0
  73. package/dist/trace/rules/sip-connect/privacy.js +50 -0
  74. package/dist/trace/rules/sip-connect/request-uri-e164.d.ts +2 -0
  75. package/dist/trace/rules/sip-connect/request-uri-e164.js +44 -0
  76. package/dist/trace/rules/sip-connect/scope.d.ts +11 -0
  77. package/dist/trace/rules/sip-connect/scope.js +19 -0
  78. package/dist/trace/rules/types.d.ts +34 -0
  79. package/dist/trace/rules/types.js +13 -0
  80. package/dist/trace/sanitize.d.ts +40 -0
  81. package/dist/trace/sanitize.js +85 -0
  82. package/dist/trace/schema.d.ts +338 -0
  83. package/dist/trace/schema.js +197 -0
  84. package/dist/trace/status.d.ts +15 -0
  85. package/dist/trace/status.js +102 -0
  86. package/dist/trace/types.d.ts +126 -0
  87. package/dist/trace/types.js +82 -0
  88. package/dist/trace/validate.d.ts +56 -0
  89. package/dist/trace/validate.js +140 -0
  90. package/dist/types.d.ts +2 -0
  91. package/package.json +2 -2
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CORPUS_FILE_NAME = void 0;
4
+ exports.parseManifest = parseManifest;
5
+ exports.compareLive = compareLive;
6
+ /*
7
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
8
+ * http://github.com/fonoster/routr
9
+ *
10
+ * This file is part of Routr.
11
+ *
12
+ * Licensed under the MIT License (the "License");
13
+ * you may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at
15
+ *
16
+ * https://opensource.org/licenses/MIT
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const types_1 = require("../types");
25
+ const diff_1 = require("./diff");
26
+ const normalize_1 = require("./normalize");
27
+ const status_1 = require("./status");
28
+ const types_2 = require("./types");
29
+ /*
30
+ * A known-good corpus: recordings committed to the repository and replayed
31
+ * through the live chain on every change, so a drift in what the chain
32
+ * answers to known traffic fails the build.
33
+ */
34
+ /** File name: <origin>_<flow>_<far-end>_<YYYYMMDD>.jsonl */
35
+ exports.CORPUS_FILE_NAME = /^[a-z0-9][a-z0-9-]*_[a-z0-9][a-z0-9.-]*_[a-z0-9][a-z0-9-]*_\d{8}\.jsonl$/;
36
+ /**
37
+ * Validates a parsed manifest (YAML or JSON) and fills the defaults.
38
+ *
39
+ * @param {unknown} input - The parsed manifest
40
+ * @return {CorpusManifest} A complete manifest
41
+ */
42
+ function parseManifest(input) {
43
+ const m = input;
44
+ if (!m || typeof m !== "object")
45
+ throw new Error("manifest is not an object");
46
+ if (typeof m.resources !== "string" || !m.resources) {
47
+ throw new Error("manifest needs a resources directory");
48
+ }
49
+ if (!Array.isArray(m.files))
50
+ throw new Error("manifest needs a files list");
51
+ const files = m.files.map((raw, i) => {
52
+ var _a, _b;
53
+ const e = raw;
54
+ if (!e || typeof e.file !== "string") {
55
+ throw new Error(`files[${i}] has no file name`);
56
+ }
57
+ if (!exports.CORPUS_FILE_NAME.test(e.file)) {
58
+ throw new Error(`${e.file} does not follow <origin>_<flow>_<far-end>_<YYYYMMDD>.jsonl`);
59
+ }
60
+ const profiles = Array.from(new Set([types_2.Profile.SIP, ...((_a = e.profiles) !== null && _a !== void 0 ? _a : [])]));
61
+ profiles.forEach((p) => {
62
+ if (!Object.values(types_2.Profile).includes(p)) {
63
+ throw new Error(`${e.file}: unknown profile ${p}`);
64
+ }
65
+ });
66
+ const findings = (_b = e.findings) !== null && _b !== void 0 ? _b : [];
67
+ if (!Array.isArray(findings) ||
68
+ findings.some((f) => typeof f !== "string")) {
69
+ throw new Error(`${e.file}: findings must be a list of rule ids`);
70
+ }
71
+ return Object.assign({ file: e.file, profiles, replay: e.replay !== false, findings: Array.from(new Set(findings)).sort() }, (e.note ? { note: e.note } : {}));
72
+ });
73
+ return { resources: m.resources, files };
74
+ }
75
+ const outcomeOf = (live) => {
76
+ var _a;
77
+ const isResponse = ((_a = live.message) === null || _a === void 0 ? void 0 : _a.messageType) === types_1.MessageType.RESPONSE;
78
+ const status = isResponse
79
+ ? (0, status_1.statusCodeOf)(live.message.responseType)
80
+ : undefined;
81
+ return isResponse
82
+ ? {
83
+ outcome: status !== undefined && status < 300
84
+ ? types_2.TraceOutcome.ANSWERED
85
+ : types_2.TraceOutcome.REJECTED,
86
+ status
87
+ }
88
+ : { outcome: types_2.TraceOutcome.FORWARDED };
89
+ };
90
+ /**
91
+ * Compares what the live chain answered with what the recording holds,
92
+ * after normalizing the values that differ between runs. Timing never
93
+ * counts.
94
+ *
95
+ * @param {TraceRecord} record - The recorded message
96
+ * @param {MessageRequest} live - What the chain returned for record.request
97
+ * @return {Drift | undefined} The drift, or undefined when they agree
98
+ */
99
+ function compareLive(record, live) {
100
+ var _a, _b, _c;
101
+ const recordedIsResponse = record.request.message.messageType === types_1.MessageType.RESPONSE;
102
+ if (!recordedIsResponse) {
103
+ const got = outcomeOf(live);
104
+ if (got.outcome !== record.outcome ||
105
+ ((_a = record.status) !== null && _a !== void 0 ? _a : got.status) !== got.status) {
106
+ return {
107
+ seq: record.seq,
108
+ reason: `recorded ${record.outcome}${record.status ? " " + record.status : ""}, live ${got.outcome}${got.status ? " " + got.status : ""}`
109
+ };
110
+ }
111
+ }
112
+ if (!((_b = record.response) === null || _b === void 0 ? void 0 : _b.message) || !live.message) {
113
+ return ((_c = record.response) === null || _c === void 0 ? void 0 : _c.message) || live.message
114
+ ? { seq: record.seq, reason: "one side has no outgoing message" }
115
+ : undefined;
116
+ }
117
+ const diff = (0, diff_1.diffMessages)((0, normalize_1.normalizeMessage)(record.response.message), (0, normalize_1.normalizeMessage)(live.message));
118
+ if ((0, diff_1.isEmptyDiff)(diff))
119
+ return undefined;
120
+ const changed = [
121
+ ...(diff.requestUri ? ["Request-URI"] : []),
122
+ ...Object.keys(diff.headers.changed),
123
+ ...Object.keys(diff.headers.added).map((h) => "+" + h),
124
+ ...Object.keys(diff.headers.removed).map((h) => "-" + h)
125
+ ];
126
+ return {
127
+ seq: record.seq,
128
+ reason: `outgoing message differs: ${changed.join(", ")}`,
129
+ diff
130
+ };
131
+ }
@@ -0,0 +1,48 @@
1
+ import { Address, SIPMessage, SipURI, Via } from "../types";
2
+ import { MessageDiff } from "./types";
3
+ /**
4
+ * Renders a SIP URI the way it appears on the wire.
5
+ *
6
+ * @param {SipURI} uri - Parsed URI
7
+ * @return {string} e.g. sip:+1555@sip.provider.net:5060;transport=udp;user=phone
8
+ */
9
+ export declare function formatUri(uri?: SipURI): string;
10
+ /**
11
+ * Renders a name-addr, e.g. "John" <sip:1001@sip.local>.
12
+ *
13
+ * @param {Address} address - Parsed address
14
+ * @return {string} The rendering
15
+ */
16
+ export declare function formatAddress(address?: Address): string;
17
+ /**
18
+ * Renders a Via header value.
19
+ *
20
+ * @param {Via} via - Parsed Via
21
+ * @return {string} e.g. SIP/2.0/UDP 10.0.0.1:5060;branch=z9hG4bK-1;rport
22
+ */
23
+ export declare function formatVia(via: Via): string;
24
+ /**
25
+ * Flattens a message into header name → values, rendered as on the wire.
26
+ * Multi-valued headers (Via, Route, Record-Route) keep one entry per line.
27
+ * The body is summarized by its media lines so SDP changes show up.
28
+ *
29
+ * @param {SIPMessage} message - Parsed message
30
+ * @return {Record<string, string[]>} Headers by canonical name
31
+ */
32
+ export declare function flattenHeaders(message: SIPMessage): Record<string, string[]>;
33
+ /**
34
+ * Computes what a component changed between the message it received and
35
+ * the one it returned.
36
+ *
37
+ * @param {SIPMessage} before - Message as it entered the component
38
+ * @param {SIPMessage} after - Message as it left the component
39
+ * @return {MessageDiff} Added, removed and changed headers
40
+ */
41
+ export declare function diffMessages(before: SIPMessage, after: SIPMessage): MessageDiff;
42
+ /**
43
+ * True when a diff carries no change at all.
44
+ *
45
+ * @param {MessageDiff} diff - A diff
46
+ * @return {boolean} Whether it is empty
47
+ */
48
+ export declare function isEmptyDiff(diff: MessageDiff): boolean;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatUri = formatUri;
4
+ exports.formatAddress = formatAddress;
5
+ exports.formatVia = formatVia;
6
+ exports.flattenHeaders = flattenHeaders;
7
+ exports.diffMessages = diffMessages;
8
+ exports.isEmptyDiff = isEmptyDiff;
9
+ /**
10
+ * Renders a SIP URI the way it appears on the wire.
11
+ *
12
+ * @param {SipURI} uri - Parsed URI
13
+ * @return {string} e.g. sip:+1555@sip.provider.net:5060;transport=udp;user=phone
14
+ */
15
+ function formatUri(uri) {
16
+ if (!uri)
17
+ return "";
18
+ const scheme = uri.secure ? "sips" : "sip";
19
+ const user = uri.user ? `${uri.user}@` : "";
20
+ const port = uri.port ? `:${uri.port}` : "";
21
+ const params = [
22
+ uri.transportParam ? `transport=${uri.transportParam.toLowerCase()}` : "",
23
+ uri.userParam ? `user=${uri.userParam}` : "",
24
+ uri.lrParam ? "lr" : "",
25
+ uri.methodParam ? `method=${uri.methodParam}` : ""
26
+ ]
27
+ .filter(Boolean)
28
+ .map((p) => `;${p}`)
29
+ .join("");
30
+ return `${scheme}:${user}${uri.host}${port}${params}`;
31
+ }
32
+ /**
33
+ * Renders a name-addr, e.g. "John" <sip:1001@sip.local>.
34
+ *
35
+ * @param {Address} address - Parsed address
36
+ * @return {string} The rendering
37
+ */
38
+ function formatAddress(address) {
39
+ if (!address)
40
+ return "";
41
+ const name = address.displayName ? `"${address.displayName}" ` : "";
42
+ return `${name}<${formatUri(address.uri)}>`;
43
+ }
44
+ /**
45
+ * Renders a Via header value.
46
+ *
47
+ * @param {Via} via - Parsed Via
48
+ * @return {string} e.g. SIP/2.0/UDP 10.0.0.1:5060;branch=z9hG4bK-1;rport
49
+ */
50
+ function formatVia(via) {
51
+ const params = [
52
+ via.branch ? `branch=${via.branch}` : "",
53
+ via.received ? `received=${via.received}` : "",
54
+ via.rPort ? `rport=${via.rPort}` : via.rPortFlag ? "rport" : ""
55
+ ]
56
+ .filter(Boolean)
57
+ .map((p) => `;${p}`)
58
+ .join("");
59
+ return `SIP/2.0/${via.transport} ${via.host}:${via.port}${params}`;
60
+ }
61
+ const withParams = (address, parameters) => formatAddress(address) +
62
+ Object.entries(parameters || {})
63
+ .map(([k, v]) => (v === "" ? `;${k}` : `;${k}=${v}`))
64
+ .join("");
65
+ /**
66
+ * Flattens a message into header name → values, rendered as on the wire.
67
+ * Multi-valued headers (Via, Route, Record-Route) keep one entry per line.
68
+ * The body is summarized by its media lines so SDP changes show up.
69
+ *
70
+ * @param {SIPMessage} message - Parsed message
71
+ * @return {Record<string, string[]>} Headers by canonical name
72
+ */
73
+ function flattenHeaders(message) {
74
+ var _a, _b;
75
+ const headers = {};
76
+ const put = (name, value) => {
77
+ if (value === undefined || value === null || value === "")
78
+ return;
79
+ headers[name] = (headers[name] || []).concat(String(value));
80
+ };
81
+ (message.via || []).forEach((via) => put("Via", formatVia(via)));
82
+ (message.route || []).forEach((r) => put("Route", withParams(r.address, r.parameters)));
83
+ (message.recordRoute || []).forEach((r) => put("Record-Route", withParams(r.address, r.parameters)));
84
+ if (message.from) {
85
+ put("From", withParams(message.from.address, Object.assign(Object.assign({}, (message.from.tag ? { tag: message.from.tag } : {})), message.from.parameters)));
86
+ }
87
+ if (message.to) {
88
+ put("To", withParams(message.to.address, Object.assign(Object.assign({}, (message.to.tag ? { tag: message.to.tag } : {})), message.to.parameters)));
89
+ }
90
+ if (message.contact)
91
+ put("Contact", formatAddress(message.contact.address));
92
+ put("Max-Forwards", (_a = message.maxForwards) === null || _a === void 0 ? void 0 : _a.maxForwards);
93
+ put("Expires", (_b = message.expires) === null || _b === void 0 ? void 0 : _b.expires);
94
+ if (message.authorization) {
95
+ put("Authorization", `Digest username="${message.authorization.username}", realm="${message.authorization.realm}"`);
96
+ }
97
+ if (message.wwwAuthenticate) {
98
+ put("WWW-Authenticate", `Digest realm="${message.wwwAuthenticate.realm}", nonce="${message.wwwAuthenticate.nonce}"`);
99
+ }
100
+ ;
101
+ (message.extensions || []).forEach((ext) => put(ext.name, ext.value));
102
+ const media = (message.body || "")
103
+ .split(/\r?\n/)
104
+ .filter((line) => /^(m|c)=/.test(line));
105
+ if (media.length)
106
+ put("Body", media.join(" "));
107
+ return headers;
108
+ }
109
+ const join = (values) => values.join(", ");
110
+ /**
111
+ * Computes what a component changed between the message it received and
112
+ * the one it returned.
113
+ *
114
+ * @param {SIPMessage} before - Message as it entered the component
115
+ * @param {SIPMessage} after - Message as it left the component
116
+ * @return {MessageDiff} Added, removed and changed headers
117
+ */
118
+ function diffMessages(before, after) {
119
+ const a = flattenHeaders(before);
120
+ const b = flattenHeaders(after);
121
+ const diff = { headers: { added: {}, removed: {}, changed: {} } };
122
+ Object.keys(b)
123
+ .filter((name) => !(name in a))
124
+ .forEach((name) => (diff.headers.added[name] = join(b[name])));
125
+ Object.keys(a)
126
+ .filter((name) => !(name in b))
127
+ .forEach((name) => (diff.headers.removed[name] = join(a[name])));
128
+ Object.keys(a)
129
+ .filter((name) => name in b && join(a[name]) !== join(b[name]))
130
+ .forEach((name) => (diff.headers.changed[name] = {
131
+ from: join(a[name]),
132
+ to: join(b[name])
133
+ }));
134
+ const uriBefore = formatUri(before.requestUri);
135
+ const uriAfter = formatUri(after.requestUri);
136
+ if (uriBefore && uriAfter && uriBefore !== uriAfter) {
137
+ diff.requestUri = { from: uriBefore, to: uriAfter };
138
+ }
139
+ return diff;
140
+ }
141
+ /**
142
+ * True when a diff carries no change at all.
143
+ *
144
+ * @param {MessageDiff} diff - A diff
145
+ * @return {boolean} Whether it is empty
146
+ */
147
+ function isEmptyDiff(diff) {
148
+ return (!diff.requestUri &&
149
+ Object.keys(diff.headers.added).length === 0 &&
150
+ Object.keys(diff.headers.removed).length === 0 &&
151
+ Object.keys(diff.headers.changed).length === 0);
152
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./types";
2
+ export * from "./schema";
3
+ export * from "./validate";
4
+ export * from "./redact";
5
+ export * from "./diff";
6
+ export * from "./status";
7
+ export * from "./metadata";
8
+ export * from "./normalize";
9
+ export * from "./compat";
10
+ export * from "./sanitize";
11
+ export * as Rules from "./rules";
@@ -0,0 +1,68 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Rules = void 0;
40
+ /*
41
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
42
+ * http://github.com/fonoster/routr
43
+ *
44
+ * This file is part of Routr.
45
+ *
46
+ * Licensed under the MIT License (the "License");
47
+ * you may not use this file except in compliance with
48
+ * the License. You may obtain a copy of the License at
49
+ *
50
+ * https://opensource.org/licenses/MIT
51
+ *
52
+ * Unless required by applicable law or agreed to in writing, software
53
+ * distributed under the License is distributed on an "AS IS" BASIS,
54
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55
+ * See the License for the specific language governing permissions and
56
+ * limitations under the License.
57
+ */
58
+ __exportStar(require("./types"), exports);
59
+ __exportStar(require("./schema"), exports);
60
+ __exportStar(require("./validate"), exports);
61
+ __exportStar(require("./redact"), exports);
62
+ __exportStar(require("./diff"), exports);
63
+ __exportStar(require("./status"), exports);
64
+ __exportStar(require("./metadata"), exports);
65
+ __exportStar(require("./normalize"), exports);
66
+ __exportStar(require("./compat"), exports);
67
+ __exportStar(require("./sanitize"), exports);
68
+ exports.Rules = __importStar(require("./rules"));
@@ -0,0 +1,28 @@
1
+ export interface SplitMetadata {
2
+ hop: Record<string, string>;
3
+ rest: Record<string, string>;
4
+ flag?: string;
5
+ }
6
+ /**
7
+ * Separates the trace keys a component put in its response metadata from
8
+ * the metadata that continues to the EdgePort.
9
+ *
10
+ * @param {Record<string, string>} metadata - Response metadata, if any
11
+ * @return {SplitMetadata} Annotations, remaining metadata and the flag
12
+ */
13
+ export declare function splitTraceMetadata(metadata?: Record<string, string>): SplitMetadata;
14
+ /**
15
+ * Returns the metadata without any trace.* key, or undefined when nothing
16
+ * is left.
17
+ *
18
+ * @param {Record<string, string>} metadata - Response metadata, if any
19
+ * @return {Record<string, string> | undefined} Metadata for the EdgePort
20
+ */
21
+ export declare function withoutTraceMetadata(metadata?: Record<string, string>): Record<string, string> | undefined;
22
+ /**
23
+ * Builds the metadata a processor returns to annotate its hop in the trace.
24
+ *
25
+ * @param {Record<string, string | number | undefined>} annotations - Keys without the prefix
26
+ * @return {Record<string, string>} Metadata entries, prefix added, undefined values skipped
27
+ */
28
+ export declare function traceAnnotations(annotations: Record<string, string | number | undefined>): Record<string, string>;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitTraceMetadata = splitTraceMetadata;
4
+ exports.withoutTraceMetadata = withoutTraceMetadata;
5
+ exports.traceAnnotations = traceAnnotations;
6
+ /*
7
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
8
+ * http://github.com/fonoster/routr
9
+ *
10
+ * This file is part of Routr.
11
+ *
12
+ * Licensed under the MIT License (the "License");
13
+ * you may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at
15
+ *
16
+ * https://opensource.org/licenses/MIT
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const types_1 = require("./types");
25
+ /**
26
+ * Separates the trace keys a component put in its response metadata from
27
+ * the metadata that continues to the EdgePort.
28
+ *
29
+ * @param {Record<string, string>} metadata - Response metadata, if any
30
+ * @return {SplitMetadata} Annotations, remaining metadata and the flag
31
+ */
32
+ function splitTraceMetadata(metadata) {
33
+ const hop = {};
34
+ const rest = {};
35
+ let flag;
36
+ Object.entries(metadata !== null && metadata !== void 0 ? metadata : {}).forEach(([key, value]) => {
37
+ if (key === types_1.TRACE_FLAG_METADATA_KEY) {
38
+ flag = value;
39
+ }
40
+ else if (key.startsWith(types_1.TRACE_METADATA_PREFIX)) {
41
+ hop[key.slice(types_1.TRACE_METADATA_PREFIX.length)] = value;
42
+ }
43
+ else {
44
+ rest[key] = value;
45
+ }
46
+ });
47
+ return Object.assign({ hop, rest }, (flag !== undefined ? { flag } : {}));
48
+ }
49
+ /**
50
+ * Returns the metadata without any trace.* key, or undefined when nothing
51
+ * is left.
52
+ *
53
+ * @param {Record<string, string>} metadata - Response metadata, if any
54
+ * @return {Record<string, string> | undefined} Metadata for the EdgePort
55
+ */
56
+ function withoutTraceMetadata(metadata) {
57
+ if (!metadata)
58
+ return undefined;
59
+ const { rest } = splitTraceMetadata(metadata);
60
+ return rest;
61
+ }
62
+ /**
63
+ * Builds the metadata a processor returns to annotate its hop in the trace.
64
+ *
65
+ * @param {Record<string, string | number | undefined>} annotations - Keys without the prefix
66
+ * @return {Record<string, string>} Metadata entries, prefix added, undefined values skipped
67
+ */
68
+ function traceAnnotations(annotations) {
69
+ const out = {};
70
+ Object.entries(annotations).forEach(([key, value]) => {
71
+ if (value !== undefined)
72
+ out[types_1.TRACE_METADATA_PREFIX + key] = String(value);
73
+ });
74
+ return out;
75
+ }
@@ -0,0 +1,11 @@
1
+ import { SIPMessage } from "../types";
2
+ /**
3
+ * Returns a copy of the message with the values that legitimately differ
4
+ * between two runs of the same scenario blanked: Via branches, From and To
5
+ * tags, and the nonces of a digest exchange. Everything else a component
6
+ * produces is deterministic for the same input and configuration.
7
+ *
8
+ * @param {SIPMessage} message - A message as recorded or as returned live
9
+ * @return {SIPMessage} A copy safe to diff against another run
10
+ */
11
+ export declare function normalizeMessage(message: SIPMessage): SIPMessage;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMessage = normalizeMessage;
4
+ /**
5
+ * Returns a copy of the message with the values that legitimately differ
6
+ * between two runs of the same scenario blanked: Via branches, From and To
7
+ * tags, and the nonces of a digest exchange. Everything else a component
8
+ * produces is deterministic for the same input and configuration.
9
+ *
10
+ * @param {SIPMessage} message - A message as recorded or as returned live
11
+ * @return {SIPMessage} A copy safe to diff against another run
12
+ */
13
+ function normalizeMessage(message) {
14
+ var _a, _b;
15
+ const copy = JSON.parse(JSON.stringify(message));
16
+ (copy.via || []).forEach((v) => {
17
+ if (v.branch)
18
+ v.branch = "*";
19
+ });
20
+ if ((_a = copy.from) === null || _a === void 0 ? void 0 : _a.tag)
21
+ copy.from.tag = "*";
22
+ if ((_b = copy.to) === null || _b === void 0 ? void 0 : _b.tag)
23
+ copy.to.tag = "*";
24
+ if (copy.wwwAuthenticate) {
25
+ if (copy.wwwAuthenticate.nonce)
26
+ copy.wwwAuthenticate.nonce = "*";
27
+ if (copy.wwwAuthenticate.opaque)
28
+ copy.wwwAuthenticate.opaque = "*";
29
+ }
30
+ if (copy.authorization) {
31
+ if (copy.authorization.nonce)
32
+ copy.authorization.nonce = "*";
33
+ if (copy.authorization.cNonce)
34
+ copy.authorization.cNonce = "*";
35
+ if (copy.authorization.response)
36
+ copy.authorization.response = "*";
37
+ }
38
+ return copy;
39
+ }
@@ -0,0 +1,19 @@
1
+ import { MessageRequest, SIPMessage } from "../types";
2
+ export declare const REDACTED = "REDACTED";
3
+ /**
4
+ * Returns a deep copy of the message with credentials replaced by REDACTED.
5
+ * The digest `response` is the hash of the password and the only secret in a
6
+ * SIP Digest exchange; nonce, realm and username stay so the exchange remains
7
+ * readable.
8
+ *
9
+ * @param {SIPMessage} message - Message to copy
10
+ * @return {SIPMessage} A redacted copy
11
+ */
12
+ export declare function redactMessage(message: SIPMessage): SIPMessage;
13
+ /**
14
+ * Returns a deep copy of the request with its message redacted.
15
+ *
16
+ * @param {MessageRequest} request - Request to copy
17
+ * @return {MessageRequest} A redacted copy
18
+ */
19
+ export declare function redactRequest(request: MessageRequest): MessageRequest;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REDACTED = void 0;
4
+ exports.redactMessage = redactMessage;
5
+ exports.redactRequest = redactRequest;
6
+ exports.REDACTED = "REDACTED";
7
+ // Header names whose value is a credential or a hash of one
8
+ const SECRET_HEADERS = new Set([
9
+ "authorization",
10
+ "proxy-authorization",
11
+ "x-gateway-auth"
12
+ ]);
13
+ /**
14
+ * Returns a deep copy of the message with credentials replaced by REDACTED.
15
+ * The digest `response` is the hash of the password and the only secret in a
16
+ * SIP Digest exchange; nonce, realm and username stay so the exchange remains
17
+ * readable.
18
+ *
19
+ * @param {SIPMessage} message - Message to copy
20
+ * @return {SIPMessage} A redacted copy
21
+ */
22
+ function redactMessage(message) {
23
+ var _a, _b, _c, _d;
24
+ const copy = JSON.parse(JSON.stringify(message));
25
+ if (copy.authorization) {
26
+ copy.authorization.response = exports.REDACTED;
27
+ if (copy.authorization.cNonce)
28
+ copy.authorization.cNonce = exports.REDACTED;
29
+ }
30
+ copy.extensions = (copy.extensions || []).map((ext) => SECRET_HEADERS.has(ext.name.toLowerCase())
31
+ ? Object.assign(Object.assign({}, ext), { value: exports.REDACTED }) : ext);
32
+ [(_a = copy.from) === null || _a === void 0 ? void 0 : _a.address, (_b = copy.to) === null || _b === void 0 ? void 0 : _b.address, (_c = copy.contact) === null || _c === void 0 ? void 0 : _c.address]
33
+ .concat((copy.route || []).map((r) => r.address))
34
+ .concat((copy.recordRoute || []).map((r) => r.address))
35
+ .forEach((address) => {
36
+ var _a;
37
+ if ((_a = address === null || address === void 0 ? void 0 : address.uri) === null || _a === void 0 ? void 0 : _a.userPassword)
38
+ address.uri.userPassword = exports.REDACTED;
39
+ });
40
+ if ((_d = copy.requestUri) === null || _d === void 0 ? void 0 : _d.userPassword)
41
+ copy.requestUri.userPassword = exports.REDACTED;
42
+ return copy;
43
+ }
44
+ /**
45
+ * Returns a deep copy of the request with its message redacted.
46
+ *
47
+ * @param {MessageRequest} request - Request to copy
48
+ * @return {MessageRequest} A redacted copy
49
+ */
50
+ function redactRequest(request) {
51
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(Object.assign(Object.assign({}, request), { message: undefined })))), { message: redactMessage(request.message) });
52
+ }