@routr/common 2.32.3 → 2.34.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/connect/config.d.ts +5 -0
- package/dist/connect/country_iso_code_schema.d.ts +6 -0
- package/dist/connect/country_iso_code_schema.js +26 -0
- package/dist/connect/index.d.ts +8 -0
- package/dist/connect/index.js +8 -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 +39 -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/tel_url_schema.d.ts +7 -0
- package/dist/connect/tel_url_schema.js +28 -0
- package/dist/connect/trunk_number_format_schema.d.ts +19 -0
- package/dist/connect/trunk_number_format_schema.js +40 -0
- package/dist/connect/types.d.ts +6 -1
- package/dist/connect/validate_country_iso_code.d.ts +11 -0
- package/dist/connect/validate_country_iso_code.js +44 -0
- package/dist/connect/validate_number_aliases.d.ts +15 -0
- package/dist/connect/validate_number_aliases.js +59 -0
- package/dist/connect/validate_tel_url.d.ts +10 -0
- package/dist/connect/validate_tel_url.js +50 -0
- package/dist/connect/validate_trunk_number_format.d.ts +13 -0
- package/dist/connect/validate_trunk_number_format.js +63 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/parse_boolean_env.d.ts +10 -0
- package/dist/parse_boolean_env.js +37 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +17 -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 +3 -2
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;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
/** Schema for checking the countryIsoCode of a new Number. */
|
|
3
|
+
export declare const validateCountryIsoCodeSchema: z.ZodObject<{
|
|
4
|
+
countryIsoCode: z.ZodString;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export type ValidateCountryIsoCodeInput = z.infer<typeof validateCountryIsoCodeSchema>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCountryIsoCodeSchema = 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
|
+
/** Schema for checking the countryIsoCode of a new Number. */
|
|
24
|
+
exports.validateCountryIsoCodeSchema = v4_1.z.object({
|
|
25
|
+
countryIsoCode: v4_1.z.string({ error: "countryIsoCode must be a string" })
|
|
26
|
+
});
|
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,10 @@ 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";
|
|
12
|
+
export * from "./tel_url_schema";
|
|
13
|
+
export * from "./validate_tel_url";
|
|
14
|
+
export * from "./country_iso_code_schema";
|
|
15
|
+
export * from "./validate_country_iso_code";
|
|
8
16
|
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,10 @@ __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);
|
|
46
|
+
__exportStar(require("./tel_url_schema"), exports);
|
|
47
|
+
__exportStar(require("./validate_tel_url"), exports);
|
|
48
|
+
__exportStar(require("./country_iso_code_schema"), exports);
|
|
49
|
+
__exportStar(require("./validate_country_iso_code"), exports);
|
|
42
50
|
__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,21 @@ 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; a number of another country in international form
|
|
72
|
+
NATIONAL = 3;
|
|
73
|
+
// 00442079460018: the international prefix of the Number's country, the
|
|
74
|
+
// country code and the national number
|
|
75
|
+
INTERNATIONAL = 4;
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
// The message for the Trunk resource
|
|
64
79
|
message Trunk {
|
|
65
80
|
// The API version of the Trunk
|
|
@@ -94,6 +109,14 @@ message Trunk {
|
|
|
94
109
|
bool rewrite_from_with_number = 15;
|
|
95
110
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
96
111
|
string from_domain = 16;
|
|
112
|
+
// How the To and Request-URI users are written on calls leaving through this Trunk
|
|
113
|
+
NumberFormat called_number_format = 17;
|
|
114
|
+
// Prepended to the called number after formatting
|
|
115
|
+
string called_number_prefix = 18;
|
|
116
|
+
// How the Number in From, P-Asserted-Identity and Remote-Party-ID is written
|
|
117
|
+
NumberFormat caller_number_format = 19;
|
|
118
|
+
// Prepended to the caller number after formatting
|
|
119
|
+
string caller_number_prefix = 20;
|
|
97
120
|
}
|
|
98
121
|
|
|
99
122
|
// The message for the Trunk.Create
|
|
@@ -124,6 +147,14 @@ message CreateTrunkRequest {
|
|
|
124
147
|
bool rewrite_from_with_number = 12;
|
|
125
148
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
126
149
|
string from_domain = 13;
|
|
150
|
+
// How the To and Request-URI users are written on calls leaving through this Trunk
|
|
151
|
+
NumberFormat called_number_format = 14;
|
|
152
|
+
// Prepended to the called number after formatting
|
|
153
|
+
string called_number_prefix = 15;
|
|
154
|
+
// How the Number in From, P-Asserted-Identity and Remote-Party-ID is written
|
|
155
|
+
NumberFormat caller_number_format = 16;
|
|
156
|
+
// Prepended to the caller number after formatting
|
|
157
|
+
string caller_number_prefix = 17;
|
|
127
158
|
}
|
|
128
159
|
|
|
129
160
|
// The message for the Trunk.Update
|
|
@@ -156,6 +187,14 @@ message UpdateTrunkRequest {
|
|
|
156
187
|
optional bool rewrite_from_with_number = 13;
|
|
157
188
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
158
189
|
optional string from_domain = 14;
|
|
190
|
+
// How the To and Request-URI users are written; UNSPECIFIED resets it
|
|
191
|
+
optional NumberFormat called_number_format = 15;
|
|
192
|
+
// Prepended to the called number after formatting; an empty string clears it
|
|
193
|
+
optional string called_number_prefix = 16;
|
|
194
|
+
// How the Number in From, P-Asserted-Identity and Remote-Party-ID is written; UNSPECIFIED resets it
|
|
195
|
+
optional NumberFormat caller_number_format = 17;
|
|
196
|
+
// Prepended to the caller number after formatting; an empty string clears it
|
|
197
|
+
optional string caller_number_prefix = 18;
|
|
159
198
|
}
|
|
160
199
|
|
|
161
200
|
// 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", "international"]
|
|
69
|
+
},
|
|
70
|
+
calledNumberPrefix: {
|
|
71
|
+
description: "Prepended to the called number after formatting",
|
|
72
|
+
type: "string",
|
|
73
|
+
pattern: "^[0-9*#]{1,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", "international"]
|
|
78
|
+
},
|
|
79
|
+
callerNumberPrefix: {
|
|
80
|
+
description: "Prepended to the caller number after formatting",
|
|
81
|
+
type: "string",
|
|
82
|
+
pattern: "^[0-9*#]{1,20}$"
|
|
83
|
+
},
|
|
66
84
|
trace: {
|
|
67
85
|
description: "Message recording for the calls that touch this Trunk",
|
|
68
86
|
type: "object",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
/** Schema for checking the telUrl of a new Number. */
|
|
3
|
+
export declare const validateTelUrlSchema: z.ZodObject<{
|
|
4
|
+
telUrl: z.ZodString;
|
|
5
|
+
requireE164: z.ZodBoolean;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type ValidateTelUrlInput = z.infer<typeof validateTelUrlSchema>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTelUrlSchema = 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
|
+
/** Schema for checking the telUrl of a new Number. */
|
|
24
|
+
exports.validateTelUrlSchema = v4_1.z.object({
|
|
25
|
+
telUrl: v4_1.z.string({ error: "telUrl must be a string" }),
|
|
26
|
+
// REQUIRE_E164_NUMBERS, read by the service and passed in
|
|
27
|
+
requireE164: v4_1.z.boolean({ error: "requireE164 must be a boolean" })
|
|
28
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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>;
|
|
11
|
+
/** Schema for the Trunk Update check: the request's ref and format fields. */
|
|
12
|
+
export declare const assertTrunkNumberFormatSchema: z.ZodObject<{
|
|
13
|
+
calledNumberFormat: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof NumberFormat>>>;
|
|
14
|
+
calledNumberPrefix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
callerNumberFormat: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof NumberFormat>>>;
|
|
16
|
+
callerNumberPrefix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
ref: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type AssertTrunkNumberFormatInput = z.infer<typeof assertTrunkNumberFormatSchema>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertTrunkNumberFormatSchema = 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
|
+
});
|
|
37
|
+
/** Schema for the Trunk Update check: the request's ref and format fields. */
|
|
38
|
+
exports.assertTrunkNumberFormatSchema = exports.trunkNumberFormatSchema.extend({
|
|
39
|
+
ref: v4_1.z.string({ error: "ref must be a string" })
|
|
40
|
+
});
|
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,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the countryIsoCode of a Number created through the API: an ISO
|
|
3
|
+
* 3166-1 alpha-2 code, any case, of a country libphonenumber-js has a
|
|
4
|
+
* numbering plan for. Connect reads the Number's national and international
|
|
5
|
+
* forms with it.
|
|
6
|
+
*
|
|
7
|
+
* @param {ValidateCountryIsoCodeInput} params - the countryIsoCode
|
|
8
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
9
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when no numbering plan has the code
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateCountryIsoCode(params: unknown): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCountryIsoCode = validateCountryIsoCode;
|
|
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 libphonenumber_js_1 = require("libphonenumber-js");
|
|
23
|
+
const errors_1 = require("../errors");
|
|
24
|
+
const validation_error_1 = require("../validation_error");
|
|
25
|
+
const country_iso_code_schema_1 = require("./country_iso_code_schema");
|
|
26
|
+
/**
|
|
27
|
+
* Checks the countryIsoCode of a Number created through the API: an ISO
|
|
28
|
+
* 3166-1 alpha-2 code, any case, of a country libphonenumber-js has a
|
|
29
|
+
* numbering plan for. Connect reads the Number's national and international
|
|
30
|
+
* forms with it.
|
|
31
|
+
*
|
|
32
|
+
* @param {ValidateCountryIsoCodeInput} params - the countryIsoCode
|
|
33
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
34
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when no numbering plan has the code
|
|
35
|
+
*/
|
|
36
|
+
function validateCountryIsoCode(params) {
|
|
37
|
+
const parsed = country_iso_code_schema_1.validateCountryIsoCodeSchema.safeParse(params);
|
|
38
|
+
if (!parsed.success)
|
|
39
|
+
throw new validation_error_1.ValidationError(parsed.error);
|
|
40
|
+
const { countryIsoCode } = parsed.data;
|
|
41
|
+
if (!(0, libphonenumber_js_1.isSupportedCountry)(countryIsoCode.toUpperCase())) {
|
|
42
|
+
throw new errors_1.BadRequestError(`countryIsoCode "${countryIsoCode}" is not a country with a numbering plan`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -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,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the telUrl of a new Number. With requireE164 (REQUIRE_E164_NUMBERS)
|
|
3
|
+
* it must be tel:+ followed by an E.164 number; without it, it only has to
|
|
4
|
+
* start with tel:. A telUrl can't be updated, so only a create checks it.
|
|
5
|
+
*
|
|
6
|
+
* @param {ValidateTelUrlInput} params - the telUrl and whether it must be E.164
|
|
7
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
8
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when the telUrl breaks the rule
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateTelUrl(params: unknown): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTelUrl = validateTelUrl;
|
|
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 tel_url_schema_1 = require("./tel_url_schema");
|
|
25
|
+
// tel:+ then 2 to 15 digits, the first not 0 (ITU-T E.164)
|
|
26
|
+
const E164_TEL_URL = /^tel:\+[1-9][0-9]{1,14}$/;
|
|
27
|
+
/**
|
|
28
|
+
* Checks the telUrl of a new Number. With requireE164 (REQUIRE_E164_NUMBERS)
|
|
29
|
+
* it must be tel:+ followed by an E.164 number; without it, it only has to
|
|
30
|
+
* start with tel:. A telUrl can't be updated, so only a create checks it.
|
|
31
|
+
*
|
|
32
|
+
* @param {ValidateTelUrlInput} params - the telUrl and whether it must be E.164
|
|
33
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
34
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when the telUrl breaks the rule
|
|
35
|
+
*/
|
|
36
|
+
function validateTelUrl(params) {
|
|
37
|
+
const parsed = tel_url_schema_1.validateTelUrlSchema.safeParse(params);
|
|
38
|
+
if (!parsed.success)
|
|
39
|
+
throw new validation_error_1.ValidationError(parsed.error);
|
|
40
|
+
const { telUrl, requireE164 } = parsed.data;
|
|
41
|
+
if (!requireE164) {
|
|
42
|
+
if (!telUrl.startsWith("tel:")) {
|
|
43
|
+
throw new errors_1.BadRequestError("the telUrl must start with `tel:`");
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!E164_TEL_URL.test(telUrl)) {
|
|
48
|
+
throw new errors_1.BadRequestError(`telUrl "${telUrl}" is not E.164: use tel:+ followed by 2 to 15 digits, the first not 0; or set REQUIRE_E164_NUMBERS=false`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the number format settings of a Trunk as it will be stored: a prefix
|
|
3
|
+
* holds 1 to 20 digits, * and #, and goes only with the format
|
|
4
|
+
* e164-without-plus, national or international. An empty prefix is no prefix.
|
|
5
|
+
* The API Server, simpledata and rctl all call this, so the rules and the
|
|
6
|
+
* messages are the same everywhere.
|
|
7
|
+
*
|
|
8
|
+
* @param {TrunkNumberFormatInput} params - the Trunk's calledNumberFormat,
|
|
9
|
+
* calledNumberPrefix, callerNumberFormat and callerNumberPrefix
|
|
10
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
11
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when a prefix breaks a rule
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateTrunkNumberFormat(params: unknown): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
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 types_1 = require("../types");
|
|
24
|
+
const validation_error_1 = require("../validation_error");
|
|
25
|
+
const trunk_number_format_schema_1 = require("./trunk_number_format_schema");
|
|
26
|
+
// What a carrier's tech prefix is made of
|
|
27
|
+
const PREFIX = /^[0-9*#]{1,20}$/;
|
|
28
|
+
// The formats a prefix goes in front of: E164 starts with + and takes none
|
|
29
|
+
const FORMATS_WITH_PREFIX = [
|
|
30
|
+
types_1.NumberFormat.E164_WITHOUT_PLUS,
|
|
31
|
+
types_1.NumberFormat.NATIONAL,
|
|
32
|
+
types_1.NumberFormat.INTERNATIONAL
|
|
33
|
+
];
|
|
34
|
+
const checkPrefix = (name, formatName, prefix, format) => {
|
|
35
|
+
if (!prefix)
|
|
36
|
+
return;
|
|
37
|
+
if (!PREFIX.test(prefix)) {
|
|
38
|
+
throw new errors_1.BadRequestError(`${name} may contain only digits, * and # (up to 20)`);
|
|
39
|
+
}
|
|
40
|
+
if (!format || !FORMATS_WITH_PREFIX.includes(format)) {
|
|
41
|
+
throw new errors_1.BadRequestError(`${name} needs ${formatName} e164-without-plus, national or international`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Checks the number format settings of a Trunk as it will be stored: a prefix
|
|
46
|
+
* holds 1 to 20 digits, * and #, and goes only with the format
|
|
47
|
+
* e164-without-plus, national or international. An empty prefix is no prefix.
|
|
48
|
+
* The API Server, simpledata and rctl all call this, so the rules and the
|
|
49
|
+
* messages are the same everywhere.
|
|
50
|
+
*
|
|
51
|
+
* @param {TrunkNumberFormatInput} params - the Trunk's calledNumberFormat,
|
|
52
|
+
* calledNumberPrefix, callerNumberFormat and callerNumberPrefix
|
|
53
|
+
* @throws {ValidationError} when params has the wrong shape
|
|
54
|
+
* @throws {BadRequestError} (INVALID_ARGUMENT) when a prefix breaks a rule
|
|
55
|
+
*/
|
|
56
|
+
function validateTrunkNumberFormat(params) {
|
|
57
|
+
const parsed = trunk_number_format_schema_1.trunkNumberFormatSchema.safeParse(params);
|
|
58
|
+
if (!parsed.success)
|
|
59
|
+
throw new validation_error_1.ValidationError(parsed.error);
|
|
60
|
+
const { calledNumberFormat, calledNumberPrefix, callerNumberFormat, callerNumberPrefix } = parsed.data;
|
|
61
|
+
checkPrefix("calledNumberPrefix", "calledNumberFormat", calledNumberPrefix, calledNumberFormat);
|
|
62
|
+
checkPrefix("callerNumberPrefix", "callerNumberFormat", callerNumberPrefix, callerNumberFormat);
|
|
63
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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";
|
|
5
|
+
export { parseBooleanEnv } from "./parse_boolean_env";
|
|
4
6
|
export * as Auth from "./auth";
|
|
5
7
|
export * as Redis from "./redis";
|
|
6
8
|
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.parseBooleanEnv = 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,10 @@ 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; } });
|
|
67
|
+
var parse_boolean_env_1 = require("./parse_boolean_env");
|
|
68
|
+
Object.defineProperty(exports, "parseBooleanEnv", { enumerable: true, get: function () { return parse_boolean_env_1.parseBooleanEnv; } });
|
|
65
69
|
exports.Auth = __importStar(require("./auth"));
|
|
66
70
|
exports.Redis = __importStar(require("./redis"));
|
|
67
71
|
exports.Helper = __importStar(require("./helper"));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses an optional environment variable that must hold true or false, such
|
|
3
|
+
* as REQUIRE_E164_NUMBERS. Unset or empty is false.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} name - The variable name, used in the error message
|
|
6
|
+
* @param {string} value - The raw value
|
|
7
|
+
* @return {boolean} the parsed value
|
|
8
|
+
* @throws {Error} when the value is neither true nor false
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseBooleanEnv(name: string, value?: string): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBooleanEnv = parseBooleanEnv;
|
|
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
|
+
/**
|
|
23
|
+
* Parses an optional environment variable that must hold true or false, such
|
|
24
|
+
* as REQUIRE_E164_NUMBERS. Unset or empty is false.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} name - The variable name, used in the error message
|
|
27
|
+
* @param {string} value - The raw value
|
|
28
|
+
* @return {boolean} the parsed value
|
|
29
|
+
* @throws {Error} when the value is neither true nor false
|
|
30
|
+
*/
|
|
31
|
+
function parseBooleanEnv(name, value) {
|
|
32
|
+
if (value === undefined || value === "" || value === "false")
|
|
33
|
+
return false;
|
|
34
|
+
if (value === "true")
|
|
35
|
+
return true;
|
|
36
|
+
throw new Error(`${name} must be true or false, got "${value}"`);
|
|
37
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -33,12 +33,24 @@ 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
|
+
INTERNATIONAL = "INTERNATIONAL"
|
|
42
|
+
}
|
|
43
|
+
export interface NumberFormatSetting {
|
|
44
|
+
format: NumberFormat;
|
|
45
|
+
prefix?: string;
|
|
46
|
+
}
|
|
36
47
|
export declare enum ExtraHeader {
|
|
37
48
|
REQUEST_URI = "X-Request-Uri",
|
|
38
49
|
GATEWAY_AUTH = "X-Gateway-Auth",
|
|
39
50
|
EDGEPORT_REF = "X-Edgeport-Ref",
|
|
40
51
|
SESSION_COUNT = "X-Session-Count",
|
|
41
52
|
DOD_NUMBER = "X-DOD-Number",
|
|
53
|
+
DID_NUMBER = "X-DID-Number",
|
|
42
54
|
DOD_PRIVACY = "X-DOD-Privacy",
|
|
43
55
|
CONNECT_TOKEN = "X-Connect-Token",
|
|
44
56
|
CALL_DIRECTION = "X-Call-Direction",
|
|
@@ -158,6 +170,15 @@ export interface Route {
|
|
|
158
170
|
user: string;
|
|
159
171
|
host: string;
|
|
160
172
|
};
|
|
173
|
+
/**
|
|
174
|
+
* Set on routes to a Trunk with calledNumberFormat or callerNumberFormat: how
|
|
175
|
+
* the numbers are written before the request leaves.
|
|
176
|
+
*/
|
|
177
|
+
numberFormat?: {
|
|
178
|
+
countryIsoCode?: string;
|
|
179
|
+
called?: NumberFormatSetting;
|
|
180
|
+
caller?: NumberFormatSetting;
|
|
181
|
+
};
|
|
161
182
|
}
|
|
162
183
|
export declare enum ResponseType {
|
|
163
184
|
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,21 @@ 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; a number of another country in international form
|
|
48
|
+
NumberFormat["NATIONAL"] = "NATIONAL";
|
|
49
|
+
// 00442079460018: the international prefix of the Number's country, the
|
|
50
|
+
// country code and the national number
|
|
51
|
+
NumberFormat["INTERNATIONAL"] = "INTERNATIONAL";
|
|
52
|
+
})(NumberFormat || (exports.NumberFormat = NumberFormat = {}));
|
|
38
53
|
var ExtraHeader;
|
|
39
54
|
(function (ExtraHeader) {
|
|
40
55
|
ExtraHeader["REQUEST_URI"] = "X-Request-Uri";
|
|
@@ -42,6 +57,7 @@ var ExtraHeader;
|
|
|
42
57
|
ExtraHeader["EDGEPORT_REF"] = "X-Edgeport-Ref";
|
|
43
58
|
ExtraHeader["SESSION_COUNT"] = "X-Session-Count";
|
|
44
59
|
ExtraHeader["DOD_NUMBER"] = "X-DOD-Number";
|
|
60
|
+
ExtraHeader["DID_NUMBER"] = "X-DID-Number";
|
|
45
61
|
ExtraHeader["DOD_PRIVACY"] = "X-DOD-Privacy";
|
|
46
62
|
ExtraHeader["CONNECT_TOKEN"] = "X-Connect-Token";
|
|
47
63
|
ExtraHeader["CALL_DIRECTION"] = "X-Call-Direction";
|
|
@@ -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.34.0",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"grpc-health-check": "^2.1.0",
|
|
37
37
|
"ip-utils": "^2.4.0",
|
|
38
38
|
"js-yaml": "^4.1.1",
|
|
39
|
+
"libphonenumber-js": "1.11.20",
|
|
39
40
|
"pb-util": "^1.0.3",
|
|
40
41
|
"phone": "^3.1.68",
|
|
41
42
|
"validator": "^13.15.26",
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@types/js-yaml": "^4.0.5"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "7d2faf42bc43b7f3f1ac7d77097ffbca1b7cf4d2"
|
|
65
66
|
}
|