@routr/common 2.32.2 → 2.33.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.
- package/dist/auth.d.ts +13 -1
- package/dist/auth.js +30 -2
- package/dist/connect/config.d.ts +5 -0
- package/dist/connect/index.d.ts +4 -0
- package/dist/connect/index.js +4 -0
- package/dist/connect/mappers/number.js +2 -0
- package/dist/connect/mappers/trunk.js +10 -18
- package/dist/connect/number_aliases_schema.d.ts +22 -0
- package/dist/connect/number_aliases_schema.js +49 -0
- package/dist/connect/protos/numbers.proto +8 -0
- package/dist/connect/protos/trunks.proto +36 -0
- package/dist/connect/schemas/number.d.ts +7 -0
- package/dist/connect/schemas/number.js +7 -0
- package/dist/connect/schemas/trunk.d.ts +18 -0
- package/dist/connect/schemas/trunk.js +18 -0
- package/dist/connect/trunk_number_format_schema.d.ts +10 -0
- package/dist/connect/trunk_number_format_schema.js +36 -0
- package/dist/connect/types.d.ts +6 -1
- package/dist/connect/validate_number_aliases.d.ts +15 -0
- package/dist/connect/validate_number_aliases.js +59 -0
- package/dist/connect/validate_trunk_number_format.d.ts +11 -0
- package/dist/connect/validate_trunk_number_format.js +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/response.d.ts +16 -0
- package/dist/response.js +11 -2
- package/dist/types.d.ts +19 -0
- package/dist/types.js +13 -1
- package/dist/with_error_handling_and_validation.d.ts +11 -0
- package/dist/with_error_handling_and_validation.js +31 -0
- package/package.json +2 -2
package/dist/auth.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { AuthChallengeResponse } from "./types";
|
|
2
2
|
export declare const DEFAULT_ALGORITHM = "MD5";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const NONCE_MAX_AGE_SECONDS = 300;
|
|
4
|
+
export declare const generateNonce: (algorithm?: string, now?: () => number) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a nonce was issued by generateNonce within the last maxAgeSeconds.
|
|
7
|
+
* A nonce in another format is never fresh, so a header captured before
|
|
8
|
+
* nonces carried their time can't be replayed either.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} nonce - the nonce from the Authorization header
|
|
11
|
+
* @param {number} maxAgeSeconds - how long a nonce stays valid; 0 means forever
|
|
12
|
+
* @param {Function} now - the clock, injected by tests
|
|
13
|
+
* @return {boolean} true when the nonce is fresh
|
|
14
|
+
*/
|
|
15
|
+
export declare const isNonceFresh: (nonce: string | undefined, maxAgeSeconds?: number, now?: () => number) => boolean;
|
|
4
16
|
export declare const calculateAuthResponse: (res: AuthChallengeResponse, credentials: {
|
|
5
17
|
username: string;
|
|
6
18
|
secret: string;
|
package/dist/auth.js
CHANGED
|
@@ -3,13 +3,41 @@ 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.getCredentials = exports.calculateAuthResponse = exports.generateNonce = exports.DEFAULT_ALGORITHM = void 0;
|
|
6
|
+
exports.getCredentials = exports.calculateAuthResponse = exports.isNonceFresh = exports.generateNonce = exports.NONCE_MAX_AGE_SECONDS = exports.DEFAULT_ALGORITHM = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
exports.DEFAULT_ALGORITHM = "MD5";
|
|
9
9
|
const md5hex = (str, algorithm = exports.DEFAULT_ALGORITHM) => crypto_1.default.createHash(algorithm).update(str).digest("hex");
|
|
10
10
|
const decToHex = (dec) => (dec + Math.pow(16, 8)).toString(16).slice(-8);
|
|
11
|
-
|
|
11
|
+
// A nonce carries the second it was issued, so a captured Authorization
|
|
12
|
+
// header stops working once NONCE_MAX_AGE_SECONDS have passed (isNonceFresh)
|
|
13
|
+
exports.NONCE_MAX_AGE_SECONDS = 300;
|
|
14
|
+
const generateNonce = (algorithm = exports.DEFAULT_ALGORITHM, now = Date.now) => {
|
|
15
|
+
const issuedAt = Math.floor(now() / 1000).toString(16);
|
|
16
|
+
return `${issuedAt}.${md5hex(`${now()}${Math.random()}`, algorithm)}`;
|
|
17
|
+
};
|
|
12
18
|
exports.generateNonce = generateNonce;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a nonce was issued by generateNonce within the last maxAgeSeconds.
|
|
21
|
+
* A nonce in another format is never fresh, so a header captured before
|
|
22
|
+
* nonces carried their time can't be replayed either.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} nonce - the nonce from the Authorization header
|
|
25
|
+
* @param {number} maxAgeSeconds - how long a nonce stays valid; 0 means forever
|
|
26
|
+
* @param {Function} now - the clock, injected by tests
|
|
27
|
+
* @return {boolean} true when the nonce is fresh
|
|
28
|
+
*/
|
|
29
|
+
const isNonceFresh = (nonce, maxAgeSeconds = exports.NONCE_MAX_AGE_SECONDS, now = Date.now) => {
|
|
30
|
+
if (maxAgeSeconds === 0)
|
|
31
|
+
return true;
|
|
32
|
+
const [issuedAtHex, digest] = (nonce !== null && nonce !== void 0 ? nonce : "").split(".");
|
|
33
|
+
if (!digest || !/^[0-9a-f]+$/.test(issuedAtHex))
|
|
34
|
+
return false;
|
|
35
|
+
// A nonce dated ahead of this clock (another instance's) is only as fresh
|
|
36
|
+
// as it gets: the digest binds it, so no one gains by choosing one
|
|
37
|
+
const age = Math.floor(now() / 1000) - parseInt(issuedAtHex, 16);
|
|
38
|
+
return age <= maxAgeSeconds;
|
|
39
|
+
};
|
|
40
|
+
exports.isNonceFresh = isNonceFresh;
|
|
13
41
|
const calculateAuthResponse = (res, credentials) => {
|
|
14
42
|
if (!credentials)
|
|
15
43
|
return null;
|
package/dist/connect/config.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export interface NumberConfig extends Omit<ConfigBase, "metadata"> {
|
|
|
89
89
|
name: string;
|
|
90
90
|
value: string;
|
|
91
91
|
}[];
|
|
92
|
+
aliases?: string[];
|
|
92
93
|
};
|
|
93
94
|
};
|
|
94
95
|
}
|
|
@@ -98,6 +99,10 @@ export interface TrunkConfig extends ConfigBase {
|
|
|
98
99
|
normalizeToE164?: boolean;
|
|
99
100
|
rewriteFromWithNumber?: boolean;
|
|
100
101
|
fromDomain?: string;
|
|
102
|
+
calledNumberFormat?: string;
|
|
103
|
+
calledNumberPrefix?: string;
|
|
104
|
+
callerNumberFormat?: string;
|
|
105
|
+
callerNumberPrefix?: string;
|
|
101
106
|
inbound: {
|
|
102
107
|
uri: string;
|
|
103
108
|
accessControlListRef: string;
|
package/dist/connect/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export * from "./trunk_number_format_schema";
|
|
2
|
+
export * from "./validate_trunk_number_format";
|
|
1
3
|
export * from "./api";
|
|
2
4
|
export * from "./client";
|
|
3
5
|
export * from "./types";
|
|
@@ -5,4 +7,6 @@ export * from "./config";
|
|
|
5
7
|
export * from "./mappers";
|
|
6
8
|
export * from "./assertions";
|
|
7
9
|
export * from "./validations";
|
|
10
|
+
export * from "./number_aliases_schema";
|
|
11
|
+
export * from "./validate_number_aliases";
|
|
8
12
|
export * from "./connect_error";
|
package/dist/connect/index.js
CHANGED
|
@@ -32,6 +32,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
+
__exportStar(require("./trunk_number_format_schema"), exports);
|
|
36
|
+
__exportStar(require("./validate_trunk_number_format"), exports);
|
|
35
37
|
__exportStar(require("./api"), exports);
|
|
36
38
|
__exportStar(require("./client"), exports);
|
|
37
39
|
__exportStar(require("./types"), exports);
|
|
@@ -39,4 +41,6 @@ __exportStar(require("./config"), exports);
|
|
|
39
41
|
__exportStar(require("./mappers"), exports);
|
|
40
42
|
__exportStar(require("./assertions"), exports);
|
|
41
43
|
__exportStar(require("./validations"), exports);
|
|
44
|
+
__exportStar(require("./number_aliases_schema"), exports);
|
|
45
|
+
__exportStar(require("./validate_number_aliases"), exports);
|
|
42
46
|
__exportStar(require("./connect_error"), exports);
|
|
@@ -6,6 +6,7 @@ const types_1 = require("../types");
|
|
|
6
6
|
const assertions_1 = require("./assertions");
|
|
7
7
|
const valid = schemas_1.schemaValidators.get(types_1.Kind.NUMBER);
|
|
8
8
|
function mapToNumber(config) {
|
|
9
|
+
var _a;
|
|
9
10
|
(0, assertions_1.assertValidSchema)(config, valid);
|
|
10
11
|
const metadata = config.metadata;
|
|
11
12
|
const location = config.spec.location;
|
|
@@ -20,6 +21,7 @@ function mapToNumber(config) {
|
|
|
20
21
|
aorLink: location.aorLink,
|
|
21
22
|
sessionAffinityHeader: location.sessionAffinityHeader,
|
|
22
23
|
extraHeaders: location.extraHeaders,
|
|
24
|
+
aliases: (_a = location.aliases) !== null && _a !== void 0 ? _a : [],
|
|
23
25
|
trunkRef: config.spec.trunkRef,
|
|
24
26
|
createdAt: new Date().getTime(),
|
|
25
27
|
updatedAt: new Date().getTime()
|
|
@@ -5,22 +5,18 @@ const schemas_1 = require("../schemas");
|
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const assertions_1 = require("./assertions");
|
|
7
7
|
const valid = schemas_1.schemaValidators.get(types_1.Kind.TRUNK);
|
|
8
|
+
// YAML writes the formats in kebab-case: e164-without-plus
|
|
9
|
+
const toNumberFormat = (format) => format === null || format === void 0 ? void 0 : format.replace(/-/g, "_").toUpperCase();
|
|
8
10
|
function mapToTrunk(config) {
|
|
9
11
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
10
12
|
(0, assertions_1.assertValidSchema)(config, valid);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
fromDomain: config.spec.fromDomain,
|
|
19
|
-
inboundUri: (_d = config.spec.inbound) === null || _d === void 0 ? void 0 : _d.uri,
|
|
20
|
-
inboundCredentialsRef: (_e = config.spec.inbound) === null || _e === void 0 ? void 0 : _e.credentialsRef,
|
|
21
|
-
outboundCredentialsRef: (_f = config.spec.outbound) === null || _f === void 0 ? void 0 : _f.credentialsRef,
|
|
22
|
-
accessControlListRef: (_g = config.spec.inbound) === null || _g === void 0 ? void 0 : _g.accessControlListRef,
|
|
23
|
-
uris: (_j = (_h = config.spec.outbound) === null || _h === void 0 ? void 0 : _h.uris) === null || _j === void 0 ? void 0 : _j.map((entry) => {
|
|
13
|
+
const numberFormat = {
|
|
14
|
+
calledNumberFormat: toNumberFormat(config.spec.calledNumberFormat),
|
|
15
|
+
calledNumberPrefix: config.spec.calledNumberPrefix,
|
|
16
|
+
callerNumberFormat: toNumberFormat(config.spec.callerNumberFormat),
|
|
17
|
+
callerNumberPrefix: config.spec.callerNumberPrefix
|
|
18
|
+
};
|
|
19
|
+
return Object.assign(Object.assign({ apiVersion: config.apiVersion, ref: config.ref, name: config.metadata.name, sendRegister: (_a = config.spec.outbound) === null || _a === void 0 ? void 0 : _a.sendRegister, normalizeToE164: (_b = config.spec.normalizeToE164) !== null && _b !== void 0 ? _b : false, rewriteFromWithNumber: (_c = config.spec.rewriteFromWithNumber) !== null && _c !== void 0 ? _c : false, fromDomain: config.spec.fromDomain }, numberFormat), { inboundUri: (_d = config.spec.inbound) === null || _d === void 0 ? void 0 : _d.uri, inboundCredentialsRef: (_e = config.spec.inbound) === null || _e === void 0 ? void 0 : _e.credentialsRef, outboundCredentialsRef: (_f = config.spec.outbound) === null || _f === void 0 ? void 0 : _f.credentialsRef, accessControlListRef: (_g = config.spec.inbound) === null || _g === void 0 ? void 0 : _g.accessControlListRef, uris: (_j = (_h = config.spec.outbound) === null || _h === void 0 ? void 0 : _h.uris) === null || _j === void 0 ? void 0 : _j.map((entry) => {
|
|
24
20
|
var _a;
|
|
25
21
|
return {
|
|
26
22
|
user: entry.uri.user,
|
|
@@ -31,9 +27,5 @@ function mapToTrunk(config) {
|
|
|
31
27
|
weight: entry.weight,
|
|
32
28
|
priority: entry.priority
|
|
33
29
|
};
|
|
34
|
-
}),
|
|
35
|
-
trace: config.spec.trace,
|
|
36
|
-
createdAt: new Date().getTime(),
|
|
37
|
-
updatedAt: new Date().getTime()
|
|
38
|
-
};
|
|
30
|
+
}), trace: config.spec.trace, createdAt: new Date().getTime(), updatedAt: new Date().getTime() });
|
|
39
31
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
/** Schema for checking the aliases a Number is about to be stored with. */
|
|
3
|
+
export declare const validateNumberAliasesSchema: z.ZodObject<{
|
|
4
|
+
number: z.ZodObject<{
|
|
5
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
6
|
+
trunkRef: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
7
|
+
aliases: z.ZodArray<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
trunkNumbers: z.ZodArray<z.ZodObject<{
|
|
10
|
+
ref: z.ZodString;
|
|
11
|
+
aliases: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
12
|
+
}, z.core.$strip>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
/** Schema for the alias fields of a request that creates or updates a Number. */
|
|
15
|
+
export declare const assertNumberAliasesSchema: z.ZodObject<{
|
|
16
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
17
|
+
aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
18
|
+
clearAliases: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
trunkRef: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type ValidateNumberAliasesInput = z.infer<typeof validateNumberAliasesSchema>;
|
|
22
|
+
export type AssertNumberAliasesInput = z.infer<typeof assertNumberAliasesSchema>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNumberAliasesSchema = exports.validateNumberAliasesSchema = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/routr
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Routr.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const v4_1 = require("zod/v4");
|
|
23
|
+
const aliasList = v4_1.z.array(v4_1.z.string({ error: "an alias must be a string" }), {
|
|
24
|
+
error: "aliases must be a list"
|
|
25
|
+
});
|
|
26
|
+
/** Schema for checking the aliases a Number is about to be stored with. */
|
|
27
|
+
exports.validateNumberAliasesSchema = v4_1.z.object({
|
|
28
|
+
number: v4_1.z.object({
|
|
29
|
+
ref: v4_1.z.string({ error: "ref must be a string" }).optional(),
|
|
30
|
+
trunkRef: v4_1.z.string({ error: "trunkRef must be a string" }).nullish(),
|
|
31
|
+
aliases: aliasList
|
|
32
|
+
}, { error: "number is required" }),
|
|
33
|
+
trunkNumbers: v4_1.z.array(v4_1.z.object({
|
|
34
|
+
ref: v4_1.z.string({ error: "ref must be a string" }),
|
|
35
|
+
aliases: aliasList.nullish()
|
|
36
|
+
}), { error: "trunkNumbers must be a list" })
|
|
37
|
+
});
|
|
38
|
+
/** Schema for the alias fields of a request that creates or updates a Number. */
|
|
39
|
+
exports.assertNumberAliasesSchema = v4_1.z.object({
|
|
40
|
+
// Absent on create
|
|
41
|
+
ref: v4_1.z.string({ error: "ref must be a string" }).optional(),
|
|
42
|
+
// A non-empty list replaces the stored one; an empty list keeps it
|
|
43
|
+
aliases: aliasList.optional(),
|
|
44
|
+
clearAliases: v4_1.z
|
|
45
|
+
.boolean({ error: "clearAliases must be a boolean" })
|
|
46
|
+
.optional(),
|
|
47
|
+
// Absent when the request leaves the Trunk as it is
|
|
48
|
+
trunkRef: v4_1.z.string({ error: "trunkRef must be a string" }).nullish()
|
|
49
|
+
});
|
|
@@ -70,6 +70,8 @@ message Number {
|
|
|
70
70
|
fonoster.routr.connect.trunks.v2beta1.Trunk trunk = 13;
|
|
71
71
|
// The extended attributes of the Number
|
|
72
72
|
.google.protobuf.Struct extended = 14;
|
|
73
|
+
// Other identifiers the Number's Trunk sends for it, such as a carrier label
|
|
74
|
+
repeated string aliases = 15;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
// The message for the ExtraHeader field
|
|
@@ -102,6 +104,8 @@ message CreateNumberRequest {
|
|
|
102
104
|
string trunk_ref = 10;
|
|
103
105
|
// The extended attributes of the Number
|
|
104
106
|
.google.protobuf.Struct extended = 11;
|
|
107
|
+
// Other identifiers the Number's Trunk sends for it, such as a carrier label
|
|
108
|
+
repeated string aliases = 12;
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
// The request message for Numbers.Update
|
|
@@ -120,6 +124,10 @@ message UpdateNumberRequest {
|
|
|
120
124
|
optional string trunk_ref = 10;
|
|
121
125
|
// The extended attributes of the Number
|
|
122
126
|
.google.protobuf.Struct extended = 11;
|
|
127
|
+
// A non-empty list replaces the stored aliases; an empty list keeps them
|
|
128
|
+
repeated string aliases = 12;
|
|
129
|
+
// Removes every alias; wins over aliases when both are sent
|
|
130
|
+
bool clear_aliases = 13;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
// The request message for Numbers.Get
|
|
@@ -60,6 +60,18 @@ message TrunkURI {
|
|
|
60
60
|
bool enabled = 7;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// How a phone number is written on calls leaving through the Trunk
|
|
64
|
+
enum NumberFormat {
|
|
65
|
+
// As today: as routed, or +E.164 when normalize_to_e164 is set
|
|
66
|
+
UNSPECIFIED = 0;
|
|
67
|
+
// +442079460018
|
|
68
|
+
E164 = 1;
|
|
69
|
+
// 442079460018
|
|
70
|
+
E164_WITHOUT_PLUS = 2;
|
|
71
|
+
// 02079460018
|
|
72
|
+
NATIONAL = 3;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
// The message for the Trunk resource
|
|
64
76
|
message Trunk {
|
|
65
77
|
// The API version of the Trunk
|
|
@@ -94,6 +106,14 @@ message Trunk {
|
|
|
94
106
|
bool rewrite_from_with_number = 15;
|
|
95
107
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
96
108
|
string from_domain = 16;
|
|
109
|
+
// How the To and Request-URI users are written on calls leaving through this Trunk
|
|
110
|
+
NumberFormat called_number_format = 17;
|
|
111
|
+
// Prepended to the called number after formatting
|
|
112
|
+
string called_number_prefix = 18;
|
|
113
|
+
// How the Number in From, P-Asserted-Identity and Remote-Party-ID is written
|
|
114
|
+
NumberFormat caller_number_format = 19;
|
|
115
|
+
// Prepended to the caller number after formatting
|
|
116
|
+
string caller_number_prefix = 20;
|
|
97
117
|
}
|
|
98
118
|
|
|
99
119
|
// The message for the Trunk.Create
|
|
@@ -124,6 +144,14 @@ message CreateTrunkRequest {
|
|
|
124
144
|
bool rewrite_from_with_number = 12;
|
|
125
145
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
126
146
|
string from_domain = 13;
|
|
147
|
+
// How the To and Request-URI users are written on calls leaving through this Trunk
|
|
148
|
+
NumberFormat called_number_format = 14;
|
|
149
|
+
// Prepended to the called number after formatting
|
|
150
|
+
string called_number_prefix = 15;
|
|
151
|
+
// How the Number in From, P-Asserted-Identity and Remote-Party-ID is written
|
|
152
|
+
NumberFormat caller_number_format = 16;
|
|
153
|
+
// Prepended to the caller number after formatting
|
|
154
|
+
string caller_number_prefix = 17;
|
|
127
155
|
}
|
|
128
156
|
|
|
129
157
|
// The message for the Trunk.Update
|
|
@@ -156,6 +184,14 @@ message UpdateTrunkRequest {
|
|
|
156
184
|
optional bool rewrite_from_with_number = 13;
|
|
157
185
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
158
186
|
optional string from_domain = 14;
|
|
187
|
+
// How the To and Request-URI users are written; UNSPECIFIED resets it
|
|
188
|
+
optional NumberFormat called_number_format = 15;
|
|
189
|
+
// Prepended to the called number after formatting; an empty string clears it
|
|
190
|
+
optional string called_number_prefix = 16;
|
|
191
|
+
// How the Number in From, P-Asserted-Identity and Remote-Party-ID is written; UNSPECIFIED resets it
|
|
192
|
+
optional NumberFormat caller_number_format = 17;
|
|
193
|
+
// Prepended to the caller number after formatting; an empty string clears it
|
|
194
|
+
optional string caller_number_prefix = 18;
|
|
159
195
|
}
|
|
160
196
|
|
|
161
197
|
// The message for the Trunk.Get
|
|
@@ -62,6 +62,13 @@ exports.default = {
|
|
|
62
62
|
description: "Tel URL",
|
|
63
63
|
type: "string"
|
|
64
64
|
},
|
|
65
|
+
aliases: {
|
|
66
|
+
description: "Other identifiers the Trunk sends for the Number, such as a carrier label",
|
|
67
|
+
type: "array",
|
|
68
|
+
items: {
|
|
69
|
+
type: "string"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
65
72
|
aorLink: {
|
|
66
73
|
description: "AOR link",
|
|
67
74
|
type: "string",
|
|
@@ -43,6 +43,24 @@ declare const _default: {
|
|
|
43
43
|
type: string;
|
|
44
44
|
maxLength: number;
|
|
45
45
|
};
|
|
46
|
+
calledNumberFormat: {
|
|
47
|
+
description: string;
|
|
48
|
+
enum: string[];
|
|
49
|
+
};
|
|
50
|
+
calledNumberPrefix: {
|
|
51
|
+
description: string;
|
|
52
|
+
type: string;
|
|
53
|
+
pattern: string;
|
|
54
|
+
};
|
|
55
|
+
callerNumberFormat: {
|
|
56
|
+
description: string;
|
|
57
|
+
enum: string[];
|
|
58
|
+
};
|
|
59
|
+
callerNumberPrefix: {
|
|
60
|
+
description: string;
|
|
61
|
+
type: string;
|
|
62
|
+
pattern: string;
|
|
63
|
+
};
|
|
46
64
|
trace: {
|
|
47
65
|
description: string;
|
|
48
66
|
type: string;
|
|
@@ -63,6 +63,24 @@ exports.default = {
|
|
|
63
63
|
type: "string",
|
|
64
64
|
maxLength: 255
|
|
65
65
|
},
|
|
66
|
+
calledNumberFormat: {
|
|
67
|
+
description: "How the To and Request-URI users are written on calls leaving through this Trunk",
|
|
68
|
+
enum: ["e164", "e164-without-plus", "national"]
|
|
69
|
+
},
|
|
70
|
+
calledNumberPrefix: {
|
|
71
|
+
description: "Prepended to the called number after formatting",
|
|
72
|
+
type: "string",
|
|
73
|
+
pattern: "^[0-9*]{0,20}$"
|
|
74
|
+
},
|
|
75
|
+
callerNumberFormat: {
|
|
76
|
+
description: "How the Number in P-Asserted-Identity, Remote-Party-ID and a rewritten From is written on calls leaving through this Trunk",
|
|
77
|
+
enum: ["e164", "e164-without-plus", "national"]
|
|
78
|
+
},
|
|
79
|
+
callerNumberPrefix: {
|
|
80
|
+
description: "Prepended to the caller number after formatting",
|
|
81
|
+
type: "string",
|
|
82
|
+
pattern: "^[0-9*]{0,20}$"
|
|
83
|
+
},
|
|
66
84
|
trace: {
|
|
67
85
|
description: "Message recording for the calls that touch this Trunk",
|
|
68
86
|
type: "object",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { NumberFormat } from "../types";
|
|
3
|
+
/** Schema for the number format settings of a request that writes a Trunk. */
|
|
4
|
+
export declare const trunkNumberFormatSchema: z.ZodObject<{
|
|
5
|
+
calledNumberFormat: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof NumberFormat>>>;
|
|
6
|
+
calledNumberPrefix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
7
|
+
callerNumberFormat: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof NumberFormat>>>;
|
|
8
|
+
callerNumberPrefix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export type TrunkNumberFormatInput = z.infer<typeof trunkNumberFormatSchema>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trunkNumberFormatSchema = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/routr
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Routr.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const v4_1 = require("zod/v4");
|
|
23
|
+
const types_1 = require("../types");
|
|
24
|
+
const format = v4_1.z
|
|
25
|
+
.enum(types_1.NumberFormat, { error: "the number format is not one Routr knows" })
|
|
26
|
+
.nullish();
|
|
27
|
+
const prefix = v4_1.z
|
|
28
|
+
.string({ error: "the number prefix must be a string" })
|
|
29
|
+
.nullish();
|
|
30
|
+
/** Schema for the number format settings of a request that writes a Trunk. */
|
|
31
|
+
exports.trunkNumberFormatSchema = v4_1.z.object({
|
|
32
|
+
calledNumberFormat: format,
|
|
33
|
+
calledNumberPrefix: prefix,
|
|
34
|
+
callerNumberFormat: format,
|
|
35
|
+
callerNumberPrefix: prefix
|
|
36
|
+
});
|
package/dist/connect/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoadBalancingAlgorithm, Privacy, Transport } from "../types";
|
|
1
|
+
import { LoadBalancingAlgorithm, NumberFormat, Privacy, Transport } from "../types";
|
|
2
2
|
export declare enum Kind {
|
|
3
3
|
AGENT = "agent",
|
|
4
4
|
PEER = "peer",
|
|
@@ -68,6 +68,7 @@ export interface INumber extends BaseConnectModel {
|
|
|
68
68
|
name: string;
|
|
69
69
|
value: string;
|
|
70
70
|
}[];
|
|
71
|
+
aliases?: string[];
|
|
71
72
|
trunkRef?: string;
|
|
72
73
|
trunk?: Trunk;
|
|
73
74
|
}
|
|
@@ -76,6 +77,10 @@ export interface Trunk extends BaseConnectModel {
|
|
|
76
77
|
normalizeToE164?: boolean;
|
|
77
78
|
rewriteFromWithNumber?: boolean;
|
|
78
79
|
fromDomain?: string;
|
|
80
|
+
calledNumberFormat?: NumberFormat;
|
|
81
|
+
calledNumberPrefix?: string;
|
|
82
|
+
callerNumberFormat?: NumberFormat;
|
|
83
|
+
callerNumberPrefix?: string;
|
|
79
84
|
inboundUri: string;
|
|
80
85
|
accessControlListRef?: string;
|
|
81
86
|
accessControlList?: AccessControlList;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the aliases a Number is about to be stored with: each is 1 to 60
|
|
3
|
+
* letters, digits or + * . _ -, and none belongs to another Number of the
|
|
4
|
+
* same Trunk. Aliases are matched only on the Number's own Trunk, so a Number
|
|
5
|
+
* with no Trunk can't collide. pgdata and simpledata both call this, so the
|
|
6
|
+
* rules and the messages are the same in both.
|
|
7
|
+
*
|
|
8
|
+
* @param {ValidateNumberAliasesInput} params - the check to make
|
|
9
|
+
* @param {object} params.number - the Number as it will be stored: its ref
|
|
10
|
+
* (absent on create), Trunk and aliases
|
|
11
|
+
* @param {object[]} params.trunkNumbers - the Numbers of that Trunk today
|
|
12
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
13
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) naming the alias that breaks a rule
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateNumberAliases(params: unknown): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateNumberAliases = validateNumberAliases;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/routr
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Routr.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const errors_1 = require("../errors");
|
|
23
|
+
const validation_error_1 = require("../validation_error");
|
|
24
|
+
const number_aliases_schema_1 = require("./number_aliases_schema");
|
|
25
|
+
// 1 to 60 letters, digits or + * . _ -
|
|
26
|
+
const ALIAS = /^[A-Za-z0-9+*._-]{1,60}$/;
|
|
27
|
+
/**
|
|
28
|
+
* Checks the aliases a Number is about to be stored with: each is 1 to 60
|
|
29
|
+
* letters, digits or + * . _ -, and none belongs to another Number of the
|
|
30
|
+
* same Trunk. Aliases are matched only on the Number's own Trunk, so a Number
|
|
31
|
+
* with no Trunk can't collide. pgdata and simpledata both call this, so the
|
|
32
|
+
* rules and the messages are the same in both.
|
|
33
|
+
*
|
|
34
|
+
* @param {ValidateNumberAliasesInput} params - the check to make
|
|
35
|
+
* @param {object} params.number - the Number as it will be stored: its ref
|
|
36
|
+
* (absent on create), Trunk and aliases
|
|
37
|
+
* @param {object[]} params.trunkNumbers - the Numbers of that Trunk today
|
|
38
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
39
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) naming the alias that breaks a rule
|
|
40
|
+
*/
|
|
41
|
+
function validateNumberAliases(params) {
|
|
42
|
+
const parsed = number_aliases_schema_1.validateNumberAliasesSchema.safeParse(params);
|
|
43
|
+
if (!parsed.success)
|
|
44
|
+
throw new validation_error_1.ValidationError(parsed.error);
|
|
45
|
+
const { number, trunkNumbers } = parsed.data;
|
|
46
|
+
const invalid = number.aliases.find((alias) => !ALIAS.test(alias));
|
|
47
|
+
if (invalid !== undefined) {
|
|
48
|
+
throw new errors_1.BadRequestError(`alias "${invalid}" is invalid: use 1 to 60 letters, digits or + * . _ -`);
|
|
49
|
+
}
|
|
50
|
+
if (!number.trunkRef)
|
|
51
|
+
return;
|
|
52
|
+
const others = trunkNumbers.filter((other) => other.ref !== number.ref);
|
|
53
|
+
number.aliases.forEach((alias) => {
|
|
54
|
+
const owner = others.find((other) => { var _a; return (_a = other.aliases) === null || _a === void 0 ? void 0 : _a.includes(alias); });
|
|
55
|
+
if (owner) {
|
|
56
|
+
throw new errors_1.BadRequestError(`alias "${alias}" is already used by Number ${owner.ref} on this Trunk`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the number format settings of a request that creates or updates a
|
|
3
|
+
* Trunk: a prefix holds only digits and *, up to 20. A prefix stored without
|
|
4
|
+
* its format does nothing, so it needs no format to be valid.
|
|
5
|
+
*
|
|
6
|
+
* @param {TrunkNumberFormatInput} params - the Trunk's calledNumberFormat,
|
|
7
|
+
* calledNumberPrefix, callerNumberFormat and callerNumberPrefix
|
|
8
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
9
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when a prefix breaks a rule
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateTrunkNumberFormat(params: unknown): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTrunkNumberFormat = validateTrunkNumberFormat;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/routr
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Routr.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const errors_1 = require("../errors");
|
|
23
|
+
const validation_error_1 = require("../validation_error");
|
|
24
|
+
const trunk_number_format_schema_1 = require("./trunk_number_format_schema");
|
|
25
|
+
// What a carrier's tech prefix is made of
|
|
26
|
+
const PREFIX = /^[0-9*]{0,20}$/;
|
|
27
|
+
/**
|
|
28
|
+
* Checks the number format settings of a request that creates or updates a
|
|
29
|
+
* Trunk: a prefix holds only digits and *, up to 20. A prefix stored without
|
|
30
|
+
* its format does nothing, so it needs no format to be valid.
|
|
31
|
+
*
|
|
32
|
+
* @param {TrunkNumberFormatInput} params - the Trunk's calledNumberFormat,
|
|
33
|
+
* calledNumberPrefix, callerNumberFormat and callerNumberPrefix
|
|
34
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
35
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when a prefix breaks a rule
|
|
36
|
+
*/
|
|
37
|
+
function validateTrunkNumberFormat(params) {
|
|
38
|
+
const parsed = trunk_number_format_schema_1.trunkNumberFormatSchema.safeParse(params);
|
|
39
|
+
if (!parsed.success)
|
|
40
|
+
throw new validation_error_1.ValidationError(parsed.error);
|
|
41
|
+
const { calledNumberPrefix, callerNumberPrefix } = parsed.data;
|
|
42
|
+
[calledNumberPrefix, callerNumberPrefix].forEach((prefix) => {
|
|
43
|
+
if (prefix && !PREFIX.test(prefix)) {
|
|
44
|
+
throw new errors_1.BadRequestError("prefix may contain only digits and * (up to 20)");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
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
|
+
export { withErrorHandlingAndValidation } from "./with_error_handling_and_validation";
|
|
4
5
|
export * as Auth from "./auth";
|
|
5
6
|
export * as Redis from "./redis";
|
|
6
7
|
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.Config = exports.Identity = exports.Trace = exports.Verifier = 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;
|
|
36
|
+
exports.Config = exports.Identity = exports.Trace = exports.Verifier = 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.withErrorHandlingAndValidation = 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
|
|
@@ -62,6 +62,8 @@ Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get
|
|
|
62
62
|
const types_1 = require("./types");
|
|
63
63
|
Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return types_1.Method; } });
|
|
64
64
|
Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return types_1.Transport; } });
|
|
65
|
+
var with_error_handling_and_validation_1 = require("./with_error_handling_and_validation");
|
|
66
|
+
Object.defineProperty(exports, "withErrorHandlingAndValidation", { enumerable: true, get: function () { return with_error_handling_and_validation_1.withErrorHandlingAndValidation; } });
|
|
65
67
|
exports.Auth = __importStar(require("./auth"));
|
|
66
68
|
exports.Redis = __importStar(require("./redis"));
|
|
67
69
|
exports.Helper = __importStar(require("./helper"));
|
package/dist/response.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ResponseType } from "./types";
|
|
|
2
2
|
export declare const createUnauthorizedResponse: (realm: string, params?: {
|
|
3
3
|
qop: string;
|
|
4
4
|
algorithm: string;
|
|
5
|
+
stale?: boolean;
|
|
5
6
|
}) => {
|
|
6
7
|
message: {
|
|
7
8
|
responseType: ResponseType;
|
|
@@ -17,6 +18,21 @@ export declare const createUnauthorizedResponse: (realm: string, params?: {
|
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
20
|
};
|
|
21
|
+
export declare const createStaleUnauthorizedResponse: (realm: string) => {
|
|
22
|
+
message: {
|
|
23
|
+
responseType: ResponseType;
|
|
24
|
+
reasonPhrase: string;
|
|
25
|
+
wwwAuthenticate: {
|
|
26
|
+
scheme: string;
|
|
27
|
+
realm: string;
|
|
28
|
+
qop: string;
|
|
29
|
+
opaque: string;
|
|
30
|
+
stale: boolean;
|
|
31
|
+
nonce: string;
|
|
32
|
+
algorithm: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
20
36
|
export declare const createUnauthorizedResponseWithoutChallenge: (metadata?: Record<string, string>) => {
|
|
21
37
|
metadata: Record<string, string>;
|
|
22
38
|
message: {
|
package/dist/response.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNotFoundResponse = exports.createBadRequestResponse = exports.createForbiddenResponse = exports.createServerInternalErrorResponse = exports.createUnauthorizedResponseWithoutChallenge = exports.createUnauthorizedResponse = void 0;
|
|
3
|
+
exports.createNotFoundResponse = exports.createBadRequestResponse = exports.createForbiddenResponse = exports.createServerInternalErrorResponse = exports.createUnauthorizedResponseWithoutChallenge = exports.createStaleUnauthorizedResponse = exports.createUnauthorizedResponse = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/routr
|
|
@@ -22,6 +22,7 @@ exports.createNotFoundResponse = exports.createBadRequestResponse = exports.crea
|
|
|
22
22
|
const auth_1 = require("./auth");
|
|
23
23
|
const types_1 = require("./types");
|
|
24
24
|
const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: auth_1.DEFAULT_ALGORITHM }) => {
|
|
25
|
+
var _a;
|
|
25
26
|
return {
|
|
26
27
|
message: {
|
|
27
28
|
responseType: types_1.ResponseType.UNAUTHORIZED,
|
|
@@ -31,7 +32,7 @@ const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: au
|
|
|
31
32
|
realm: realm,
|
|
32
33
|
qop: params.qop,
|
|
33
34
|
opaque: "",
|
|
34
|
-
stale: false,
|
|
35
|
+
stale: (_a = params.stale) !== null && _a !== void 0 ? _a : false,
|
|
35
36
|
nonce: (0, auth_1.generateNonce)(),
|
|
36
37
|
algorithm: params.algorithm
|
|
37
38
|
}
|
|
@@ -39,6 +40,14 @@ const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: au
|
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
42
|
exports.createUnauthorizedResponse = createUnauthorizedResponse;
|
|
43
|
+
// The credentials were right but the nonce had expired: a client retries with
|
|
44
|
+
// the new nonce without asking the user again (RFC 7616 section 3.3)
|
|
45
|
+
const createStaleUnauthorizedResponse = (realm) => (0, exports.createUnauthorizedResponse)(realm, {
|
|
46
|
+
qop: "auth",
|
|
47
|
+
algorithm: auth_1.DEFAULT_ALGORITHM,
|
|
48
|
+
stale: true
|
|
49
|
+
});
|
|
50
|
+
exports.createStaleUnauthorizedResponse = createStaleUnauthorizedResponse;
|
|
42
51
|
const createUnauthorizedResponseWithoutChallenge = (metadata) => {
|
|
43
52
|
return {
|
|
44
53
|
metadata,
|
package/dist/types.d.ts
CHANGED
|
@@ -33,6 +33,16 @@ export declare enum LoadBalancingAlgorithm {
|
|
|
33
33
|
ROUND_ROBIN = "ROUND_ROBIN",
|
|
34
34
|
LEAST_SESSIONS = "LEAST_SESSIONS"
|
|
35
35
|
}
|
|
36
|
+
export declare enum NumberFormat {
|
|
37
|
+
UNSPECIFIED = "UNSPECIFIED",
|
|
38
|
+
E164 = "E164",
|
|
39
|
+
E164_WITHOUT_PLUS = "E164_WITHOUT_PLUS",
|
|
40
|
+
NATIONAL = "NATIONAL"
|
|
41
|
+
}
|
|
42
|
+
export interface NumberFormatSetting {
|
|
43
|
+
format: NumberFormat;
|
|
44
|
+
prefix?: string;
|
|
45
|
+
}
|
|
36
46
|
export declare enum ExtraHeader {
|
|
37
47
|
REQUEST_URI = "X-Request-Uri",
|
|
38
48
|
GATEWAY_AUTH = "X-Gateway-Auth",
|
|
@@ -158,6 +168,15 @@ export interface Route {
|
|
|
158
168
|
user: string;
|
|
159
169
|
host: string;
|
|
160
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Set on routes to a Trunk with calledNumberFormat or callerNumberFormat: how
|
|
173
|
+
* the numbers are written before the request leaves.
|
|
174
|
+
*/
|
|
175
|
+
numberFormat?: {
|
|
176
|
+
countryIsoCode?: string;
|
|
177
|
+
called?: NumberFormatSetting;
|
|
178
|
+
caller?: NumberFormatSetting;
|
|
179
|
+
};
|
|
161
180
|
}
|
|
162
181
|
export declare enum ResponseType {
|
|
163
182
|
UNKNOWN = "UNKNOWN",
|
package/dist/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageType = exports.ResponseType = exports.HeaderModifierAction = exports.Privacy = exports.ExtraHeader = exports.LoadBalancingAlgorithm = exports.Transport = exports.Method = exports.ANONYMOUS = void 0;
|
|
3
|
+
exports.MessageType = exports.ResponseType = exports.HeaderModifierAction = exports.Privacy = exports.ExtraHeader = exports.NumberFormat = exports.LoadBalancingAlgorithm = exports.Transport = exports.Method = exports.ANONYMOUS = void 0;
|
|
4
4
|
exports.ANONYMOUS = "anonymous";
|
|
5
5
|
var Method;
|
|
6
6
|
(function (Method) {
|
|
@@ -35,6 +35,18 @@ var LoadBalancingAlgorithm;
|
|
|
35
35
|
LoadBalancingAlgorithm["ROUND_ROBIN"] = "ROUND_ROBIN";
|
|
36
36
|
LoadBalancingAlgorithm["LEAST_SESSIONS"] = "LEAST_SESSIONS";
|
|
37
37
|
})(LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = LoadBalancingAlgorithm = {}));
|
|
38
|
+
// How a phone number is written on calls leaving through a Trunk
|
|
39
|
+
var NumberFormat;
|
|
40
|
+
(function (NumberFormat) {
|
|
41
|
+
// As routed, or +E.164 when the Trunk has normalizeToE164
|
|
42
|
+
NumberFormat["UNSPECIFIED"] = "UNSPECIFIED";
|
|
43
|
+
// +442079460018
|
|
44
|
+
NumberFormat["E164"] = "E164";
|
|
45
|
+
// 442079460018
|
|
46
|
+
NumberFormat["E164_WITHOUT_PLUS"] = "E164_WITHOUT_PLUS";
|
|
47
|
+
// 02079460018
|
|
48
|
+
NumberFormat["NATIONAL"] = "NATIONAL";
|
|
49
|
+
})(NumberFormat || (exports.NumberFormat = NumberFormat = {}));
|
|
38
50
|
var ExtraHeader;
|
|
39
51
|
(function (ExtraHeader) {
|
|
40
52
|
ExtraHeader["REQUEST_URI"] = "X-Request-Uri";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a function so its input is validated before it runs: the door of every
|
|
4
|
+
* validated function. Invalid input never reaches fn.
|
|
5
|
+
*
|
|
6
|
+
* @param {Function} fn - the function, typed with the schema's output
|
|
7
|
+
* @param {z.ZodType} schema - the schema its input must satisfy
|
|
8
|
+
* @return {Function} fn behind the validation
|
|
9
|
+
* @throws {ValidationError} from the returned function, when the input is invalid
|
|
10
|
+
*/
|
|
11
|
+
export declare function withErrorHandlingAndValidation<TSchema extends z.ZodType, TResult>(fn: (params: z.infer<TSchema>) => Promise<TResult>, schema: TSchema): (params: unknown) => Promise<TResult>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.withErrorHandlingAndValidation = withErrorHandlingAndValidation;
|
|
13
|
+
const validation_error_1 = require("./validation_error");
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a function so its input is validated before it runs: the door of every
|
|
16
|
+
* validated function. Invalid input never reaches fn.
|
|
17
|
+
*
|
|
18
|
+
* @param {Function} fn - the function, typed with the schema's output
|
|
19
|
+
* @param {z.ZodType} schema - the schema its input must satisfy
|
|
20
|
+
* @return {Function} fn behind the validation
|
|
21
|
+
* @throws {ValidationError} from the returned function, when the input is invalid
|
|
22
|
+
*/
|
|
23
|
+
function withErrorHandlingAndValidation(fn, schema) {
|
|
24
|
+
return (params) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const result = schema.safeParse(params);
|
|
26
|
+
if (!result.success) {
|
|
27
|
+
throw new validation_error_1.ValidationError(result.error);
|
|
28
|
+
}
|
|
29
|
+
return fn(result.data);
|
|
30
|
+
});
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/js-yaml": "^4.0.5"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "ae7d4c7b239c7ba0c9283c010cb16f388980fa5d"
|
|
65
65
|
}
|