@routr/common 2.34.2 → 3.1.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/client.js +4 -3
- package/dist/connect/config.d.ts +0 -1
- package/dist/connect/index.d.ts +0 -4
- package/dist/connect/index.js +0 -4
- package/dist/connect/mappers/trunk.js +2 -2
- package/dist/connect/number_aliases_schema.d.ts +0 -7
- package/dist/connect/number_aliases_schema.js +1 -13
- package/dist/connect/protos/agents.proto +3 -3
- package/dist/connect/protos/domains.proto +3 -1
- package/dist/connect/protos/numbers.proto +3 -1
- package/dist/connect/protos/peers.proto +2 -2
- package/dist/connect/protos/trunks.proto +17 -13
- package/dist/connect/schemas/trunk.d.ts +0 -4
- package/dist/connect/schemas/trunk.js +0 -4
- package/dist/connect/trunk_number_format_schema.d.ts +0 -9
- package/dist/connect/trunk_number_format_schema.js +1 -5
- package/dist/connect/types.d.ts +0 -1
- package/dist/connect/validate_trunk_number_format.d.ts +6 -9
- package/dist/connect/validate_trunk_number_format.js +31 -25
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -5
- package/dist/proto_path.d.ts +1 -0
- package/dist/proto_path.js +36 -0
- package/dist/requester/grpc_client.js +2 -1
- package/dist/service.js +3 -2
- package/dist/types.d.ts +7 -21
- package/dist/types.js +15 -17
- package/dist/verifier/grpc_client.js +2 -1
- package/package.json +5 -5
- package/dist/connect/country_iso_code_schema.d.ts +0 -6
- package/dist/connect/country_iso_code_schema.js +0 -26
- package/dist/connect/tel_url_schema.d.ts +0 -7
- package/dist/connect/tel_url_schema.js +0 -28
- package/dist/connect/validate_country_iso_code.d.ts +0 -11
- package/dist/connect/validate_country_iso_code.js +0 -44
- package/dist/connect/validate_tel_url.d.ts +0 -10
- package/dist/connect/validate_tel_url.js +0 -50
- package/dist/parse_boolean_env.d.ts +0 -10
- package/dist/parse_boolean_env.js +0 -37
- package/dist/with_error_handling_and_validation.d.ts +0 -11
- package/dist/with_error_handling_and_validation.js +0 -31
package/dist/connect/client.js
CHANGED
|
@@ -59,14 +59,15 @@ const helper_1 = require("../helper");
|
|
|
59
59
|
const types_1 = require("./types");
|
|
60
60
|
const protoLoader = require("@grpc/proto-loader");
|
|
61
61
|
const service_1 = require("../service");
|
|
62
|
+
const proto_path_1 = require("../proto_path");
|
|
62
63
|
function getProtoPath(kind) {
|
|
63
64
|
switch (kind) {
|
|
64
65
|
case types_1.Kind.ACL:
|
|
65
|
-
return
|
|
66
|
+
return (0, proto_path_1.protoPath)("connect/acl.proto");
|
|
66
67
|
case types_1.Kind.CREDENTIALS:
|
|
67
|
-
return
|
|
68
|
+
return (0, proto_path_1.protoPath)("connect/credentials.proto");
|
|
68
69
|
default:
|
|
69
|
-
return
|
|
70
|
+
return (0, proto_path_1.protoPath)(`connect/${kind}s.proto`);
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
function createConnectClient(options) {
|
package/dist/connect/config.d.ts
CHANGED
|
@@ -96,7 +96,6 @@ export interface NumberConfig extends Omit<ConfigBase, "metadata"> {
|
|
|
96
96
|
export interface TrunkConfig extends ConfigBase {
|
|
97
97
|
kind: Kind.TRUNK;
|
|
98
98
|
spec: {
|
|
99
|
-
normalizeToE164?: boolean;
|
|
100
99
|
rewriteFromWithNumber?: boolean;
|
|
101
100
|
fromDomain?: string;
|
|
102
101
|
calledNumberFormat?: string;
|
package/dist/connect/index.d.ts
CHANGED
|
@@ -9,8 +9,4 @@ export * from "./assertions";
|
|
|
9
9
|
export * from "./validations";
|
|
10
10
|
export * from "./number_aliases_schema";
|
|
11
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";
|
|
16
12
|
export * from "./connect_error";
|
package/dist/connect/index.js
CHANGED
|
@@ -43,8 +43,4 @@ __exportStar(require("./assertions"), exports);
|
|
|
43
43
|
__exportStar(require("./validations"), exports);
|
|
44
44
|
__exportStar(require("./number_aliases_schema"), exports);
|
|
45
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);
|
|
50
46
|
__exportStar(require("./connect_error"), exports);
|
|
@@ -8,7 +8,7 @@ const valid = schemas_1.schemaValidators.get(types_1.Kind.TRUNK);
|
|
|
8
8
|
// YAML writes the formats in kebab-case: e164-without-plus
|
|
9
9
|
const toNumberFormat = (format) => format === null || format === void 0 ? void 0 : format.replace(/-/g, "_").toUpperCase();
|
|
10
10
|
function mapToTrunk(config) {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
12
12
|
(0, assertions_1.assertValidSchema)(config, valid);
|
|
13
13
|
const numberFormat = {
|
|
14
14
|
calledNumberFormat: toNumberFormat(config.spec.calledNumberFormat),
|
|
@@ -16,7 +16,7 @@ function mapToTrunk(config) {
|
|
|
16
16
|
callerNumberFormat: toNumberFormat(config.spec.callerNumberFormat),
|
|
17
17
|
callerNumberPrefix: config.spec.callerNumberPrefix
|
|
18
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,
|
|
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, rewriteFromWithNumber: (_b = config.spec.rewriteFromWithNumber) !== null && _b !== void 0 ? _b : false, fromDomain: config.spec.fromDomain }, numberFormat), { inboundUri: (_c = config.spec.inbound) === null || _c === void 0 ? void 0 : _c.uri, inboundCredentialsRef: (_d = config.spec.inbound) === null || _d === void 0 ? void 0 : _d.credentialsRef, outboundCredentialsRef: (_e = config.spec.outbound) === null || _e === void 0 ? void 0 : _e.credentialsRef, accessControlListRef: (_f = config.spec.inbound) === null || _f === void 0 ? void 0 : _f.accessControlListRef, uris: (_h = (_g = config.spec.outbound) === null || _g === void 0 ? void 0 : _g.uris) === null || _h === void 0 ? void 0 : _h.map((entry) => {
|
|
20
20
|
var _a;
|
|
21
21
|
return {
|
|
22
22
|
user: entry.uri.user,
|
|
@@ -12,11 +12,4 @@ export declare const validateNumberAliasesSchema: z.ZodObject<{
|
|
|
12
12
|
}, z.core.$strip>>;
|
|
13
13
|
}, z.core.$strip>;
|
|
14
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
15
|
export type ValidateNumberAliasesInput = z.infer<typeof validateNumberAliasesSchema>;
|
|
22
|
-
export type AssertNumberAliasesInput = z.infer<typeof assertNumberAliasesSchema>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateNumberAliasesSchema = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/routr
|
|
@@ -35,15 +35,3 @@ exports.validateNumberAliasesSchema = v4_1.z.object({
|
|
|
35
35
|
aliases: aliasList.nullish()
|
|
36
36
|
}), { error: "trunkNumbers must be a list" })
|
|
37
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
|
-
});
|
|
@@ -86,15 +86,15 @@ message CreateAgentRequest {
|
|
|
86
86
|
// The username of the Agent
|
|
87
87
|
string username = 2;
|
|
88
88
|
// The password of the Agent
|
|
89
|
-
Privacy privacy = 3;
|
|
89
|
+
optional Privacy privacy = 3;
|
|
90
90
|
// The enabled status of the Agent
|
|
91
|
-
bool enabled = 4;
|
|
91
|
+
optional bool enabled = 4;
|
|
92
92
|
// Reference to the Domain of the Agent
|
|
93
93
|
string domain_ref = 5;
|
|
94
94
|
// Reference to the Credentials of the Agent
|
|
95
95
|
string credentials_ref = 6;
|
|
96
96
|
// The maximum number of contacts that can be created for this Agent
|
|
97
|
-
int32 max_contacts = 8;
|
|
97
|
+
optional int32 max_contacts = 8;
|
|
98
98
|
// Value to override the expires requested by the Agent
|
|
99
99
|
int32 expires = 9;
|
|
100
100
|
// The extended attributes of the Agent
|
|
@@ -100,12 +100,14 @@ message UpdateDomainRequest {
|
|
|
100
100
|
optional string name = 2;
|
|
101
101
|
// Reference to the ACL to use for this Domain
|
|
102
102
|
optional string access_control_list_ref = 3;
|
|
103
|
-
//
|
|
103
|
+
// A non-empty list replaces the stored egress policies; an empty list keeps them
|
|
104
104
|
repeated EgressPolicy egress_policies = 4;
|
|
105
105
|
// The extended attributes of the Domain
|
|
106
106
|
.google.protobuf.Struct extended = 5;
|
|
107
107
|
// Message recording for the calls that touch this Domain
|
|
108
108
|
fonoster.routr.connect.trace.v2beta1.Trace trace = 6;
|
|
109
|
+
// Removes every egress policy; wins over egress_policies when both are sent
|
|
110
|
+
bool clear_egress_policies = 7;
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
// The request message for Domains.Get
|
|
@@ -118,7 +118,7 @@ message UpdateNumberRequest {
|
|
|
118
118
|
optional string aor_link = 4;
|
|
119
119
|
// The header to use for session affinity
|
|
120
120
|
optional string session_affinity_header = 8;
|
|
121
|
-
//
|
|
121
|
+
// A non-empty list replaces the stored extra headers; an empty list keeps them
|
|
122
122
|
repeated ExtraHeader extra_headers = 9;
|
|
123
123
|
// Reference to the trunk this number is associated with
|
|
124
124
|
optional string trunk_ref = 10;
|
|
@@ -128,6 +128,8 @@ message UpdateNumberRequest {
|
|
|
128
128
|
repeated string aliases = 12;
|
|
129
129
|
// Removes every alias; wins over aliases when both are sent
|
|
130
130
|
bool clear_aliases = 13;
|
|
131
|
+
// Removes every extra header; wins over extra_headers when both are sent
|
|
132
|
+
bool clear_extra_headers = 14;
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
// The request message for Numbers.Get
|
|
@@ -109,9 +109,9 @@ message CreatePeerRequest {
|
|
|
109
109
|
// Reference to the Credentials of the Peer
|
|
110
110
|
string credentials_ref = 8;
|
|
111
111
|
// The status of the Peer
|
|
112
|
-
bool enabled = 9;
|
|
112
|
+
optional bool enabled = 9;
|
|
113
113
|
// The maximum number of contacts that can be created for this Peer
|
|
114
|
-
int32 max_contacts = 11;
|
|
114
|
+
optional int32 max_contacts = 11;
|
|
115
115
|
// Value to override the expires requested by the Peer
|
|
116
116
|
int32 expires = 12;
|
|
117
117
|
// The extended attributes of the Peer
|
|
@@ -57,21 +57,20 @@ message TrunkURI {
|
|
|
57
57
|
// The priority of the Trunk
|
|
58
58
|
int32 priority = 6;
|
|
59
59
|
// The flag to enable or disable the Trunk
|
|
60
|
-
bool enabled = 7;
|
|
60
|
+
optional bool enabled = 7;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// How a phone number is written on calls leaving through the Trunk
|
|
64
64
|
enum NumberFormat {
|
|
65
|
-
// As
|
|
65
|
+
// As routed
|
|
66
66
|
UNSPECIFIED = 0;
|
|
67
67
|
// +442079460018
|
|
68
68
|
E164 = 1;
|
|
69
69
|
// 442079460018
|
|
70
70
|
E164_WITHOUT_PLUS = 2;
|
|
71
|
-
// 02079460018
|
|
71
|
+
// 02079460018
|
|
72
72
|
NATIONAL = 3;
|
|
73
|
-
// 00442079460018: the international prefix of the Number's country
|
|
74
|
-
// country code and the national number
|
|
73
|
+
// 00442079460018: the international prefix of the Number's country
|
|
75
74
|
INTERNATIONAL = 4;
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -103,8 +102,9 @@ message Trunk {
|
|
|
103
102
|
.google.protobuf.Struct extended = 12;
|
|
104
103
|
// Message recording for the calls that touch this Trunk
|
|
105
104
|
fonoster.routr.connect.trace.v2beta1.Trace trace = 13;
|
|
106
|
-
//
|
|
107
|
-
|
|
105
|
+
// normalize_to_e164 was removed in Routr 3: use the number formats
|
|
106
|
+
reserved 14;
|
|
107
|
+
reserved "normalize_to_e164";
|
|
108
108
|
// On calls leaving through this Trunk, From becomes the Number's E.164 at from_domain
|
|
109
109
|
bool rewrite_from_with_number = 15;
|
|
110
110
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
@@ -141,8 +141,9 @@ message CreateTrunkRequest {
|
|
|
141
141
|
.google.protobuf.Struct extended = 9;
|
|
142
142
|
// Message recording for the calls that touch this Trunk
|
|
143
143
|
fonoster.routr.connect.trace.v2beta1.Trace trace = 10;
|
|
144
|
-
//
|
|
145
|
-
|
|
144
|
+
// normalize_to_e164 was removed in Routr 3: use the number formats
|
|
145
|
+
reserved 11;
|
|
146
|
+
reserved "normalize_to_e164";
|
|
146
147
|
// On calls leaving through this Trunk, From becomes the Number's E.164 at from_domain
|
|
147
148
|
bool rewrite_from_with_number = 12;
|
|
148
149
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
@@ -175,19 +176,20 @@ message UpdateTrunkRequest {
|
|
|
175
176
|
optional string inbound_credentials_ref = 7;
|
|
176
177
|
// Reference to the outbound Credentials
|
|
177
178
|
optional string outbound_credentials_ref = 8;
|
|
178
|
-
//
|
|
179
|
+
// A non-empty list replaces the stored URIs; an empty list keeps them
|
|
179
180
|
repeated TrunkURI uris = 9;
|
|
180
181
|
// The extended attributes of the Trunk
|
|
181
182
|
.google.protobuf.Struct extended = 10;
|
|
182
183
|
// Message recording for the calls that touch this Trunk
|
|
183
184
|
fonoster.routr.connect.trace.v2beta1.Trace trace = 11;
|
|
184
|
-
//
|
|
185
|
-
|
|
185
|
+
// normalize_to_e164 was removed in Routr 3: use the number formats
|
|
186
|
+
reserved 12;
|
|
187
|
+
reserved "normalize_to_e164";
|
|
186
188
|
// On calls leaving through this Trunk, From becomes the Number's E.164 at from_domain
|
|
187
189
|
optional bool rewrite_from_with_number = 13;
|
|
188
190
|
// Host part of the rewritten From. Defaults to the outbound URI host
|
|
189
191
|
optional string from_domain = 14;
|
|
190
|
-
// How the To and Request-URI users are written; UNSPECIFIED resets it
|
|
192
|
+
// How the To and Request-URI users are written on calls leaving through this Trunk; UNSPECIFIED resets it
|
|
191
193
|
optional NumberFormat called_number_format = 15;
|
|
192
194
|
// Prepended to the called number after formatting; an empty string clears it
|
|
193
195
|
optional string called_number_prefix = 16;
|
|
@@ -195,6 +197,8 @@ message UpdateTrunkRequest {
|
|
|
195
197
|
optional NumberFormat caller_number_format = 17;
|
|
196
198
|
// Prepended to the caller number after formatting; an empty string clears it
|
|
197
199
|
optional string caller_number_prefix = 18;
|
|
200
|
+
// Removes every outbound URI; wins over uris when both are sent
|
|
201
|
+
bool clear_uris = 19;
|
|
198
202
|
}
|
|
199
203
|
|
|
200
204
|
// The message for the Trunk.Get
|
|
@@ -50,10 +50,6 @@ exports.default = {
|
|
|
50
50
|
description: "Operations spec for an Trunk",
|
|
51
51
|
type: "object",
|
|
52
52
|
properties: {
|
|
53
|
-
normalizeToE164: {
|
|
54
|
-
description: "Normalize From, To and Request-URI users to +E.164 on calls through this Trunk",
|
|
55
|
-
type: "boolean"
|
|
56
|
-
},
|
|
57
53
|
rewriteFromWithNumber: {
|
|
58
54
|
description: "On calls leaving through this Trunk, From becomes the Number's E.164 at fromDomain",
|
|
59
55
|
type: "boolean"
|
|
@@ -8,12 +8,3 @@ export declare const trunkNumberFormatSchema: z.ZodObject<{
|
|
|
8
8
|
callerNumberPrefix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
9
|
}, z.core.$strip>;
|
|
10
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>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.trunkNumberFormatSchema = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/routr
|
|
@@ -34,7 +34,3 @@ exports.trunkNumberFormatSchema = v4_1.z.object({
|
|
|
34
34
|
callerNumberFormat: format,
|
|
35
35
|
callerNumberPrefix: prefix
|
|
36
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
|
@@ -74,7 +74,6 @@ export interface INumber extends BaseConnectModel {
|
|
|
74
74
|
}
|
|
75
75
|
export interface Trunk extends BaseConnectModel {
|
|
76
76
|
sendRegister: boolean;
|
|
77
|
-
normalizeToE164?: boolean;
|
|
78
77
|
rewriteFromWithNumber?: boolean;
|
|
79
78
|
fromDomain?: string;
|
|
80
79
|
calledNumberFormat?: NumberFormat;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Checks the number
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* The API Server, simpledata and rctl all call this, so the rules and the
|
|
6
|
-
* messages are the same everywhere.
|
|
2
|
+
* Checks the number formats of a Trunk as it would be stored: a prefix needs
|
|
3
|
+
* e164-without-plus, national or international, and may contain only digits,
|
|
4
|
+
* * and #, up to 20. An empty prefix is no prefix.
|
|
7
5
|
*
|
|
8
|
-
* @param {
|
|
9
|
-
*
|
|
10
|
-
* @throws {
|
|
11
|
-
* @throws {BadRequestError} (INVALID_ARGUMENT) when a prefix breaks a rule
|
|
6
|
+
* @param {unknown} params - calledNumberFormat, calledNumberPrefix, callerNumberFormat, callerNumberPrefix
|
|
7
|
+
* @throws {ValidationError} when a field has the wrong type
|
|
8
|
+
* @throws {BadRequestError} when a prefix breaks a rule
|
|
12
9
|
*/
|
|
13
10
|
export declare function validateTrunkNumberFormat(params: unknown): void;
|
|
@@ -19,45 +19,51 @@ exports.validateTrunkNumberFormat = validateTrunkNumberFormat;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
const errors_1 = require("../errors");
|
|
23
22
|
const types_1 = require("../types");
|
|
23
|
+
const errors_1 = require("../errors");
|
|
24
24
|
const validation_error_1 = require("../validation_error");
|
|
25
25
|
const trunk_number_format_schema_1 = require("./trunk_number_format_schema");
|
|
26
26
|
// What a carrier's tech prefix is made of
|
|
27
27
|
const PREFIX = /^[0-9*#]{1,20}$/;
|
|
28
|
-
// The formats a prefix
|
|
29
|
-
const
|
|
28
|
+
// The formats a prefix can go in front of: a + must stay first
|
|
29
|
+
const TAKES_PREFIX = [
|
|
30
30
|
types_1.NumberFormat.E164_WITHOUT_PLUS,
|
|
31
31
|
types_1.NumberFormat.NATIONAL,
|
|
32
32
|
types_1.NumberFormat.INTERNATIONAL
|
|
33
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
34
|
/**
|
|
45
|
-
* Checks the number
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* The API Server, simpledata and rctl all call this, so the rules and the
|
|
49
|
-
* messages are the same everywhere.
|
|
35
|
+
* Checks the number formats of a Trunk as it would be stored: a prefix needs
|
|
36
|
+
* e164-without-plus, national or international, and may contain only digits,
|
|
37
|
+
* * and #, up to 20. An empty prefix is no prefix.
|
|
50
38
|
*
|
|
51
|
-
* @param {
|
|
52
|
-
*
|
|
53
|
-
* @throws {
|
|
54
|
-
* @throws {BadRequestError} (INVALID_ARGUMENT) when a prefix breaks a rule
|
|
39
|
+
* @param {unknown} params - calledNumberFormat, calledNumberPrefix, callerNumberFormat, callerNumberPrefix
|
|
40
|
+
* @throws {ValidationError} when a field has the wrong type
|
|
41
|
+
* @throws {BadRequestError} when a prefix breaks a rule
|
|
55
42
|
*/
|
|
56
43
|
function validateTrunkNumberFormat(params) {
|
|
57
44
|
const parsed = trunk_number_format_schema_1.trunkNumberFormatSchema.safeParse(params);
|
|
58
45
|
if (!parsed.success)
|
|
59
46
|
throw new validation_error_1.ValidationError(parsed.error);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
const sides = [
|
|
48
|
+
{
|
|
49
|
+
name: "called",
|
|
50
|
+
format: parsed.data.calledNumberFormat,
|
|
51
|
+
prefix: parsed.data.calledNumberPrefix
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "caller",
|
|
55
|
+
format: parsed.data.callerNumberFormat,
|
|
56
|
+
prefix: parsed.data.callerNumberPrefix
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
sides.forEach(({ name, format, prefix }) => {
|
|
60
|
+
if (!prefix)
|
|
61
|
+
return;
|
|
62
|
+
if (!PREFIX.test(prefix)) {
|
|
63
|
+
throw new errors_1.BadRequestError(`${name}NumberPrefix may contain only digits, * and # (up to 20)`);
|
|
64
|
+
}
|
|
65
|
+
if (!TAKES_PREFIX.includes(format)) {
|
|
66
|
+
throw new errors_1.BadRequestError(`${name}NumberPrefix needs ${name}NumberFormat e164-without-plus, national or international`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
63
69
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
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";
|
|
6
4
|
export * as Auth from "./auth";
|
|
7
5
|
export * as Redis from "./redis";
|
|
8
6
|
export * as Helper from "./helper";
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.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.
|
|
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;
|
|
37
37
|
/*
|
|
38
38
|
* Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
|
|
39
39
|
* http://github.com/fonoster/routr
|
|
@@ -62,10 +62,6 @@ 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; } });
|
|
69
65
|
exports.Auth = __importStar(require("./auth"));
|
|
70
66
|
exports.Redis = __importStar(require("./redis"));
|
|
71
67
|
exports.Helper = __importStar(require("./helper"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const protoPath: (file: string) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.protoPath = 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 fs_1 = require("fs");
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
// The protos live in protos/ at the repository root, the single source for Go and
|
|
25
|
+
// TypeScript. @routr/common's build copies them into dist/protos and dist/connect/protos,
|
|
26
|
+
// which is what a packed module reads. Running from src (ts-node, the unit tests) there is
|
|
27
|
+
// no copy, so the repository's protos/ is read instead.
|
|
28
|
+
const protoPath = (file) => {
|
|
29
|
+
const copied = file.startsWith("connect/")
|
|
30
|
+
? (0, path_1.join)(__dirname, "connect", "protos", file.slice("connect/".length))
|
|
31
|
+
: (0, path_1.join)(__dirname, "protos", file);
|
|
32
|
+
return (0, fs_1.existsSync)(copied)
|
|
33
|
+
? copied
|
|
34
|
+
: (0, path_1.join)(__dirname, "..", "..", "..", "protos", file);
|
|
35
|
+
};
|
|
36
|
+
exports.protoPath = protoPath;
|
|
@@ -55,7 +55,8 @@ exports.REQUESTER_PROTO = void 0;
|
|
|
55
55
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
56
56
|
const protoLoader = require("@grpc/proto-loader");
|
|
57
57
|
const service_1 = require("../service");
|
|
58
|
-
const
|
|
58
|
+
const proto_path_1 = require("../proto_path");
|
|
59
|
+
const packageDefinition = protoLoader.loadSync((0, proto_path_1.protoPath)("requester.proto"), service_1.protoLoadOptions);
|
|
59
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
61
|
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
|
|
61
62
|
exports.REQUESTER_PROTO = protoDescriptor.fonoster.routr.requester;
|
package/dist/service.js
CHANGED
|
@@ -57,6 +57,7 @@ exports.default = createService;
|
|
|
57
57
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
58
58
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
59
59
|
const errors_1 = require("./errors");
|
|
60
|
+
const proto_path_1 = require("./proto_path");
|
|
60
61
|
const logger_1 = require("@fonoster/logger");
|
|
61
62
|
const grpc_health_check_1 = require("grpc-health-check");
|
|
62
63
|
const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
|
|
@@ -76,12 +77,12 @@ const API_VERSION = "v2beta1";
|
|
|
76
77
|
exports.PROCESSOR_OBJECT_PROTO = getObjectProto({
|
|
77
78
|
name: "processor",
|
|
78
79
|
version: API_VERSION,
|
|
79
|
-
path:
|
|
80
|
+
path: (0, proto_path_1.protoPath)("processor.proto")
|
|
80
81
|
});
|
|
81
82
|
exports.LOCATION_OBJECT_PROTO = getObjectProto({
|
|
82
83
|
name: "location",
|
|
83
84
|
version: API_VERSION,
|
|
84
|
-
path:
|
|
85
|
+
path: (0, proto_path_1.protoPath)("location.proto")
|
|
85
86
|
});
|
|
86
87
|
/**
|
|
87
88
|
* Gets the proto definition for the given object.
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ import { ServiceDefinition } from "@grpc/proto-loader";
|
|
|
3
3
|
import { JsonArray, JsonValue, Struct } from "pb-util/build";
|
|
4
4
|
export type JsonData = Record<string, string | number | boolean | JsonValue | JsonArray | Struct>;
|
|
5
5
|
export declare const ANONYMOUS = "anonymous";
|
|
6
|
+
export declare enum NumberFormat {
|
|
7
|
+
UNSPECIFIED = "UNSPECIFIED",
|
|
8
|
+
E164 = "E164",
|
|
9
|
+
E164_WITHOUT_PLUS = "E164_WITHOUT_PLUS",
|
|
10
|
+
NATIONAL = "NATIONAL",
|
|
11
|
+
INTERNATIONAL = "INTERNATIONAL"
|
|
12
|
+
}
|
|
6
13
|
export declare enum Method {
|
|
7
14
|
UNKNOWN = "UNKNOWN",
|
|
8
15
|
REGISTER = "REGISTER",
|
|
@@ -33,24 +40,12 @@ export declare enum LoadBalancingAlgorithm {
|
|
|
33
40
|
ROUND_ROBIN = "ROUND_ROBIN",
|
|
34
41
|
LEAST_SESSIONS = "LEAST_SESSIONS"
|
|
35
42
|
}
|
|
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
|
-
}
|
|
47
43
|
export declare enum ExtraHeader {
|
|
48
44
|
REQUEST_URI = "X-Request-Uri",
|
|
49
45
|
GATEWAY_AUTH = "X-Gateway-Auth",
|
|
50
46
|
EDGEPORT_REF = "X-Edgeport-Ref",
|
|
51
47
|
SESSION_COUNT = "X-Session-Count",
|
|
52
48
|
DOD_NUMBER = "X-DOD-Number",
|
|
53
|
-
DID_NUMBER = "X-DID-Number",
|
|
54
49
|
DOD_PRIVACY = "X-DOD-Privacy",
|
|
55
50
|
CONNECT_TOKEN = "X-Connect-Token",
|
|
56
51
|
CALL_DIRECTION = "X-Call-Direction",
|
|
@@ -170,15 +165,6 @@ export interface Route {
|
|
|
170
165
|
user: string;
|
|
171
166
|
host: string;
|
|
172
167
|
};
|
|
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
|
-
};
|
|
182
168
|
}
|
|
183
169
|
export declare enum ResponseType {
|
|
184
170
|
UNKNOWN = "UNKNOWN",
|
package/dist/types.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageType = exports.ResponseType = exports.HeaderModifierAction = exports.Privacy = exports.ExtraHeader = exports.
|
|
3
|
+
exports.MessageType = exports.ResponseType = exports.HeaderModifierAction = exports.Privacy = exports.ExtraHeader = exports.LoadBalancingAlgorithm = exports.Transport = exports.Method = exports.NumberFormat = exports.ANONYMOUS = void 0;
|
|
4
4
|
exports.ANONYMOUS = "anonymous";
|
|
5
|
+
// How a phone number is written on calls leaving through a Trunk
|
|
6
|
+
var NumberFormat;
|
|
7
|
+
(function (NumberFormat) {
|
|
8
|
+
// As routed
|
|
9
|
+
NumberFormat["UNSPECIFIED"] = "UNSPECIFIED";
|
|
10
|
+
// +442079460018
|
|
11
|
+
NumberFormat["E164"] = "E164";
|
|
12
|
+
// 442079460018
|
|
13
|
+
NumberFormat["E164_WITHOUT_PLUS"] = "E164_WITHOUT_PLUS";
|
|
14
|
+
// 02079460018
|
|
15
|
+
NumberFormat["NATIONAL"] = "NATIONAL";
|
|
16
|
+
// 00442079460018: the international prefix of the Number's country
|
|
17
|
+
NumberFormat["INTERNATIONAL"] = "INTERNATIONAL";
|
|
18
|
+
})(NumberFormat || (exports.NumberFormat = NumberFormat = {}));
|
|
5
19
|
var Method;
|
|
6
20
|
(function (Method) {
|
|
7
21
|
Method["UNKNOWN"] = "UNKNOWN";
|
|
@@ -35,21 +49,6 @@ var LoadBalancingAlgorithm;
|
|
|
35
49
|
LoadBalancingAlgorithm["ROUND_ROBIN"] = "ROUND_ROBIN";
|
|
36
50
|
LoadBalancingAlgorithm["LEAST_SESSIONS"] = "LEAST_SESSIONS";
|
|
37
51
|
})(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 = {}));
|
|
53
52
|
var ExtraHeader;
|
|
54
53
|
(function (ExtraHeader) {
|
|
55
54
|
ExtraHeader["REQUEST_URI"] = "X-Request-Uri";
|
|
@@ -57,7 +56,6 @@ var ExtraHeader;
|
|
|
57
56
|
ExtraHeader["EDGEPORT_REF"] = "X-Edgeport-Ref";
|
|
58
57
|
ExtraHeader["SESSION_COUNT"] = "X-Session-Count";
|
|
59
58
|
ExtraHeader["DOD_NUMBER"] = "X-DOD-Number";
|
|
60
|
-
ExtraHeader["DID_NUMBER"] = "X-DID-Number";
|
|
61
59
|
ExtraHeader["DOD_PRIVACY"] = "X-DOD-Privacy";
|
|
62
60
|
ExtraHeader["CONNECT_TOKEN"] = "X-Connect-Token";
|
|
63
61
|
ExtraHeader["CALL_DIRECTION"] = "X-Call-Direction";
|
|
@@ -55,7 +55,8 @@ exports.VERIFIER_PROTO = void 0;
|
|
|
55
55
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
56
56
|
const protoLoader = require("@grpc/proto-loader");
|
|
57
57
|
const service_1 = require("../service");
|
|
58
|
-
const
|
|
58
|
+
const proto_path_1 = require("../proto_path");
|
|
59
|
+
const packageDefinition = protoLoader.loadSync((0, proto_path_1.protoPath)("verifier.proto"), service_1.protoLoadOptions);
|
|
59
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
61
|
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
|
|
61
62
|
exports.VERIFIER_PROTO = protoDescriptor.fonoster.verifier;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
12
12
|
"build": "tsc -b tsconfig.json",
|
|
13
|
-
"postbuild": "
|
|
13
|
+
"postbuild": "mkdir -p dist/protos dist/connect/protos && cp ../../protos/*.proto dist/protos/ && cp ../../protos/connect/*.proto dist/connect/protos/"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@fonoster/logger": "0.6.0",
|
|
@@ -36,7 +36,6 @@
|
|
|
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",
|
|
40
39
|
"pb-util": "^1.0.3",
|
|
41
40
|
"phone": "^3.1.68",
|
|
42
41
|
"validator": "^13.15.26",
|
|
@@ -60,7 +59,8 @@
|
|
|
60
59
|
"url": "https://github.com/fonoster/routr/issues"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
|
-
"@types/js-yaml": "^4.0.5"
|
|
62
|
+
"@types/js-yaml": "^4.0.5",
|
|
63
|
+
"@types/validator": "^13.15.10"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "e117105ae83d4078ccddd33fe9133d327171dd45"
|
|
66
66
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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>;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
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;
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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>;
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|