@routr/common 2.0.8-alpha.20 → 2.0.8-alpha.22
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/api/client.js +1 -1
- package/dist/connect/assertions.d.ts +37 -0
- package/dist/connect/assertions.js +112 -0
- package/dist/connect/index.d.ts +2 -0
- package/dist/connect/index.js +2 -0
- package/dist/connect/mappers/number.js +1 -1
- package/dist/connect/mappers/peer.js +2 -1
- package/dist/connect/protos/agents.proto +5 -7
- package/dist/connect/protos/domains.proto +3 -5
- package/dist/connect/protos/numbers.proto +0 -8
- package/dist/connect/protos/peers.proto +15 -14
- package/dist/connect/schemas/acl.d.ts +4 -1
- package/dist/connect/schemas/acl.js +7 -4
- package/dist/connect/schemas/agent.d.ts +0 -1
- package/dist/connect/schemas/agent.js +3 -4
- package/dist/connect/schemas/crendentials.d.ts +1 -1
- package/dist/connect/schemas/crendentials.js +5 -5
- package/dist/connect/schemas/domain.d.ts +0 -3
- package/dist/connect/schemas/domain.js +2 -5
- package/dist/connect/schemas/number.d.ts +0 -1
- package/dist/connect/schemas/number.js +2 -3
- package/dist/connect/schemas/peer.d.ts +1 -1
- package/dist/connect/schemas/peer.js +7 -7
- package/dist/connect/schemas/trunk.d.ts +7 -1
- package/dist/connect/schemas/trunk.js +13 -7
- package/dist/connect/types.d.ts +6 -4
- package/dist/connect/validations.d.ts +43 -0
- package/dist/connect/validations.js +272 -0
- package/dist/types.d.ts +3 -2
- package/dist/types.js +3 -2
- package/package.json +4 -3
|
@@ -151,7 +151,7 @@ function serviceAPI(options) {
|
|
|
151
151
|
});
|
|
152
152
|
}),
|
|
153
153
|
del: (ref) => new Promise((resolve, reject) => {
|
|
154
|
-
client.
|
|
154
|
+
client.delete({ ref }, meta, (err) => err ? reject(fire(err, apiAddr)) : resolve());
|
|
155
155
|
})
|
|
156
156
|
};
|
|
157
157
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LoadBalancingAlgorithm } from "../types";
|
|
2
|
+
import { TrunkURI } from "./types";
|
|
3
|
+
export declare const hasValidHeadersOrThrow: (headers: {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}[]) => void;
|
|
7
|
+
export declare const isValidBalancingAlgorithmOrThrow: (aor: string, algorithm: LoadBalancingAlgorithm) => void;
|
|
8
|
+
export declare const hasACLRulesOrThrow: (acl: {
|
|
9
|
+
deny: string[];
|
|
10
|
+
allow: string[];
|
|
11
|
+
}) => void;
|
|
12
|
+
export declare const hasValidACLRulesOrThrow: (acl: {
|
|
13
|
+
deny: string[];
|
|
14
|
+
allow: string[];
|
|
15
|
+
}) => void;
|
|
16
|
+
export declare const hasRefenceOrThrow: (ref: string) => void;
|
|
17
|
+
export declare const hasNameOrThrow: (name: string) => void;
|
|
18
|
+
export declare const isValidNameOrThrow: (name: string) => void;
|
|
19
|
+
export declare const hasUsernameOrThrow: (username: string) => void;
|
|
20
|
+
export declare const isValidUsernameOrThrow: (username: string) => void;
|
|
21
|
+
export declare const hasPasswordOrThrow: (password: string) => void;
|
|
22
|
+
export declare const hasDomainUriOrThrow: (domainUri: string) => void;
|
|
23
|
+
export declare const isValidDomainUriOrThrow: (domainUri: string) => void;
|
|
24
|
+
export declare const hasTelUrlOrThrow: (telUrl: string) => void;
|
|
25
|
+
export declare const isValidSessionAffinityHeaderOrThrow: (sessionAffinityHeader: string) => void;
|
|
26
|
+
export declare const hasCityOrThrow: (city: string) => void;
|
|
27
|
+
export declare const hasCountryOrThrow: (country: string) => void;
|
|
28
|
+
export declare const hasCountryISOCodeOrThrow: (countryIsoCode: string) => void;
|
|
29
|
+
export declare const hasInboundUriOrThrow: (inboundUri: string) => void;
|
|
30
|
+
export declare const isValidInboundUriOrThrow: (inboundUri: string) => void;
|
|
31
|
+
export declare const hasAOROrThrow: (aor: string) => void;
|
|
32
|
+
export declare const isValidAOROrThrow: (aor: string) => void;
|
|
33
|
+
export declare const hasAORLinkOrThrow: (aorLink: string) => void;
|
|
34
|
+
export declare const isValidAORLinkOrThrow: (aorLink: string) => void;
|
|
35
|
+
export declare const isValidContactAddressOrThrow: (contactAddress: string) => void;
|
|
36
|
+
export declare const isValidE164OrThrow: (e164Number: string, countryISOCode: string, validateMobilePrefix: boolean) => void;
|
|
37
|
+
export declare const hasValidOutboundUrisOrThrow: (outboundUris: TrunkURI[]) => void;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasValidOutboundUrisOrThrow = exports.isValidE164OrThrow = exports.isValidContactAddressOrThrow = exports.isValidAORLinkOrThrow = exports.hasAORLinkOrThrow = exports.isValidAOROrThrow = exports.hasAOROrThrow = exports.isValidInboundUriOrThrow = exports.hasInboundUriOrThrow = exports.hasCountryISOCodeOrThrow = exports.hasCountryOrThrow = exports.hasCityOrThrow = exports.isValidSessionAffinityHeaderOrThrow = exports.hasTelUrlOrThrow = exports.isValidDomainUriOrThrow = exports.hasDomainUriOrThrow = exports.hasPasswordOrThrow = exports.isValidUsernameOrThrow = exports.hasUsernameOrThrow = exports.isValidNameOrThrow = exports.hasNameOrThrow = exports.hasRefenceOrThrow = exports.hasValidACLRulesOrThrow = exports.hasACLRulesOrThrow = exports.isValidBalancingAlgorithmOrThrow = exports.hasValidHeadersOrThrow = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster
|
|
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 validations_1 = require("./validations");
|
|
24
|
+
const validOrThrow = (method, value) => {
|
|
25
|
+
const R = method(value);
|
|
26
|
+
if (R instanceof errors_1.BadRequestError) {
|
|
27
|
+
throw R;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const hasValidHeadersOrThrow = (headers) => {
|
|
31
|
+
const E = (0, validations_1.hasValidHeaders)(headers);
|
|
32
|
+
if (E instanceof errors_1.BadRequestError) {
|
|
33
|
+
throw E;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.hasValidHeadersOrThrow = hasValidHeadersOrThrow;
|
|
37
|
+
const isValidBalancingAlgorithmOrThrow = (aor, algorithm) => {
|
|
38
|
+
const E = (0, validations_1.isValidBalancingAlgorithm)(aor, algorithm);
|
|
39
|
+
if (E instanceof errors_1.BadRequestError) {
|
|
40
|
+
throw E;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.isValidBalancingAlgorithmOrThrow = isValidBalancingAlgorithmOrThrow;
|
|
44
|
+
const hasACLRulesOrThrow = (acl) => validOrThrow(validations_1.hasACLRules, acl);
|
|
45
|
+
exports.hasACLRulesOrThrow = hasACLRulesOrThrow;
|
|
46
|
+
const hasValidACLRulesOrThrow = (acl) => validOrThrow(validations_1.hasValidACLRules, acl);
|
|
47
|
+
exports.hasValidACLRulesOrThrow = hasValidACLRulesOrThrow;
|
|
48
|
+
const hasRefenceOrThrow = (ref) => validOrThrow(validations_1.hasReference, ref);
|
|
49
|
+
exports.hasRefenceOrThrow = hasRefenceOrThrow;
|
|
50
|
+
const hasNameOrThrow = (name) => validOrThrow(validations_1.hasName, name);
|
|
51
|
+
exports.hasNameOrThrow = hasNameOrThrow;
|
|
52
|
+
const isValidNameOrThrow = (name) => validOrThrow(validations_1.isValidName, name);
|
|
53
|
+
exports.isValidNameOrThrow = isValidNameOrThrow;
|
|
54
|
+
const hasUsernameOrThrow = (username) => validOrThrow(validations_1.hasUsername, username);
|
|
55
|
+
exports.hasUsernameOrThrow = hasUsernameOrThrow;
|
|
56
|
+
const isValidUsernameOrThrow = (username) => validOrThrow(validations_1.isValidUsername, username);
|
|
57
|
+
exports.isValidUsernameOrThrow = isValidUsernameOrThrow;
|
|
58
|
+
const hasPasswordOrThrow = (password) => validOrThrow(validations_1.hasPassword, password);
|
|
59
|
+
exports.hasPasswordOrThrow = hasPasswordOrThrow;
|
|
60
|
+
const hasDomainUriOrThrow = (domainUri) => validOrThrow(validations_1.hasDomainUri, domainUri);
|
|
61
|
+
exports.hasDomainUriOrThrow = hasDomainUriOrThrow;
|
|
62
|
+
const isValidDomainUriOrThrow = (domainUri) => validOrThrow(validations_1.isValidDomainUri, domainUri);
|
|
63
|
+
exports.isValidDomainUriOrThrow = isValidDomainUriOrThrow;
|
|
64
|
+
const hasTelUrlOrThrow = (telUrl) => validOrThrow(validations_1.hasTelUrl, telUrl);
|
|
65
|
+
exports.hasTelUrlOrThrow = hasTelUrlOrThrow;
|
|
66
|
+
const isValidSessionAffinityHeaderOrThrow = (sessionAffinityHeader) => validOrThrow(validations_1.isValidSessionAffinityHeader, sessionAffinityHeader);
|
|
67
|
+
exports.isValidSessionAffinityHeaderOrThrow = isValidSessionAffinityHeaderOrThrow;
|
|
68
|
+
const hasCityOrThrow = (city) => validOrThrow(validations_1.hasCity, city);
|
|
69
|
+
exports.hasCityOrThrow = hasCityOrThrow;
|
|
70
|
+
const hasCountryOrThrow = (country) => validOrThrow(validations_1.hasCountry, country);
|
|
71
|
+
exports.hasCountryOrThrow = hasCountryOrThrow;
|
|
72
|
+
const hasCountryISOCodeOrThrow = (countryIsoCode) => validOrThrow(validations_1.hasCountryISOCode, countryIsoCode);
|
|
73
|
+
exports.hasCountryISOCodeOrThrow = hasCountryISOCodeOrThrow;
|
|
74
|
+
const hasInboundUriOrThrow = (inboundUri) => validOrThrow(validations_1.hasInboundUri, inboundUri);
|
|
75
|
+
exports.hasInboundUriOrThrow = hasInboundUriOrThrow;
|
|
76
|
+
const isValidInboundUriOrThrow = (inboundUri) => validOrThrow(validations_1.isValidInboundUri, inboundUri);
|
|
77
|
+
exports.isValidInboundUriOrThrow = isValidInboundUriOrThrow;
|
|
78
|
+
const hasAOROrThrow = (aor) => validOrThrow(validations_1.hasAOR, aor);
|
|
79
|
+
exports.hasAOROrThrow = hasAOROrThrow;
|
|
80
|
+
const isValidAOROrThrow = (aor) => validOrThrow(validations_1.isValidAOR, aor);
|
|
81
|
+
exports.isValidAOROrThrow = isValidAOROrThrow;
|
|
82
|
+
const hasAORLinkOrThrow = (aorLink) => validOrThrow(validations_1.hasAORLink, aorLink);
|
|
83
|
+
exports.hasAORLinkOrThrow = hasAORLinkOrThrow;
|
|
84
|
+
const isValidAORLinkOrThrow = (aorLink) => validOrThrow(validations_1.isValidAORLink, aorLink);
|
|
85
|
+
exports.isValidAORLinkOrThrow = isValidAORLinkOrThrow;
|
|
86
|
+
const isValidContactAddressOrThrow = (contactAddress) => validOrThrow(validations_1.isValidContactAddress, contactAddress);
|
|
87
|
+
exports.isValidContactAddressOrThrow = isValidContactAddressOrThrow;
|
|
88
|
+
const isValidE164OrThrow = (e164Number, countryISOCode, validateMobilePrefix) => {
|
|
89
|
+
const R = (0, validations_1.isValidE164)(e164Number, countryISOCode, validateMobilePrefix);
|
|
90
|
+
if (R instanceof errors_1.BadRequestError) {
|
|
91
|
+
throw R;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.isValidE164OrThrow = isValidE164OrThrow;
|
|
95
|
+
const hasValidOutboundUrisOrThrow = (outboundUris) => outboundUris === null || outboundUris === void 0 ? void 0 : outboundUris.forEach((uri) => {
|
|
96
|
+
if ((0, validations_1.hasHost)(uri.host) instanceof errors_1.BadRequestError) {
|
|
97
|
+
throw (0, validations_1.hasHost)(uri.host);
|
|
98
|
+
}
|
|
99
|
+
if ((0, validations_1.isValidHost)(uri.host) instanceof errors_1.BadRequestError) {
|
|
100
|
+
throw (0, validations_1.isValidHost)(uri.host);
|
|
101
|
+
}
|
|
102
|
+
if ((0, validations_1.isValidPort)(uri.port + "") instanceof errors_1.BadRequestError) {
|
|
103
|
+
throw (0, validations_1.isValidPort)(uri.port + "");
|
|
104
|
+
}
|
|
105
|
+
if ((0, validations_1.isValidPriority)(uri.priority + "") instanceof errors_1.BadRequestError) {
|
|
106
|
+
throw (0, validations_1.isValidPriority)(uri.priority + "");
|
|
107
|
+
}
|
|
108
|
+
if ((0, validations_1.isValidWeight)(uri.weight + "") instanceof errors_1.BadRequestError) {
|
|
109
|
+
throw (0, validations_1.isValidWeight)(uri.priority + "");
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
exports.hasValidOutboundUrisOrThrow = hasValidOutboundUrisOrThrow;
|
package/dist/connect/index.d.ts
CHANGED
package/dist/connect/index.js
CHANGED
|
@@ -37,3 +37,5 @@ __exportStar(require("./client"), exports);
|
|
|
37
37
|
__exportStar(require("./types"), exports);
|
|
38
38
|
__exportStar(require("./config"), exports);
|
|
39
39
|
__exportStar(require("./mappers"), exports);
|
|
40
|
+
__exportStar(require("./assertions"), exports);
|
|
41
|
+
__exportStar(require("./validations"), exports);
|
|
@@ -15,7 +15,7 @@ function mapToNumber(config) {
|
|
|
15
15
|
name: metadata.name,
|
|
16
16
|
city: metadata.geoInfo.city,
|
|
17
17
|
country: metadata.geoInfo.country,
|
|
18
|
-
|
|
18
|
+
countryIsoCode: metadata.geoInfo.countryISOCode,
|
|
19
19
|
telUrl: location.telUrl,
|
|
20
20
|
aorLink: location.aorLink,
|
|
21
21
|
sessionAffinityHeader: location.sessionAffinityHeader,
|
|
@@ -9,6 +9,7 @@ function mapToPeer(config) {
|
|
|
9
9
|
var _a, _b;
|
|
10
10
|
(0, assertions_1.assertValidSchema)(config, valid);
|
|
11
11
|
(0, assertions_1.assertValidAorSchema)(config);
|
|
12
|
+
const normalizeAlgorithm = (algorithm) => algorithm === null || algorithm === void 0 ? void 0 : algorithm.replace(/-/g, "_").toUpperCase();
|
|
12
13
|
return {
|
|
13
14
|
apiVersion: config.apiVersion,
|
|
14
15
|
ref: config.ref,
|
|
@@ -18,7 +19,7 @@ function mapToPeer(config) {
|
|
|
18
19
|
contactAddr: config.spec.contactAddr,
|
|
19
20
|
enabled: config.spec.enabled,
|
|
20
21
|
credentialsRef: config.spec.credentialsRef,
|
|
21
|
-
balancingAlgorithm: (_a = config.spec.loadBalancing) === null || _a === void 0 ? void 0 : _a.algorithm
|
|
22
|
+
balancingAlgorithm: normalizeAlgorithm((_a = config.spec.loadBalancing) === null || _a === void 0 ? void 0 : _a.algorithm),
|
|
22
23
|
withSessionAffinity: (_b = config.spec.loadBalancing) === null || _b === void 0 ? void 0 : _b.withSessionAffinity
|
|
23
24
|
};
|
|
24
25
|
}
|
|
@@ -96,18 +96,16 @@ message UpdateAgentRequest {
|
|
|
96
96
|
string ref = 1;
|
|
97
97
|
// The name of the Agent
|
|
98
98
|
string name = 2;
|
|
99
|
-
// The username of the Agent
|
|
100
|
-
string username = 3;
|
|
101
99
|
// The privacy settings of the Agent
|
|
102
|
-
Privacy privacy =
|
|
100
|
+
Privacy privacy = 3;
|
|
103
101
|
// The enabled status of the Agent
|
|
104
|
-
bool enabled =
|
|
102
|
+
bool enabled = 4;
|
|
105
103
|
// Reference to the Domain of the Agent
|
|
106
|
-
string domain_ref =
|
|
104
|
+
string domain_ref = 5;
|
|
107
105
|
// Reference to the Credentials of the Agent
|
|
108
|
-
string credentials_ref =
|
|
106
|
+
string credentials_ref = 6;
|
|
109
107
|
// The extended attributes of the Agent
|
|
110
|
-
.google.protobuf.Struct extended =
|
|
108
|
+
.google.protobuf.Struct extended = 7;
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
// The request message for the Agents.Get method
|
|
@@ -93,14 +93,12 @@ message UpdateDomainRequest {
|
|
|
93
93
|
string ref = 1;
|
|
94
94
|
// The name of the Domain
|
|
95
95
|
string name = 2;
|
|
96
|
-
// The domain_uri of the Domain
|
|
97
|
-
string domain_uri = 3;
|
|
98
96
|
// Reference to the ACL to use for this Domain
|
|
99
|
-
string access_control_list_ref =
|
|
97
|
+
string access_control_list_ref = 3;
|
|
100
98
|
// The egress_policy of the Domain
|
|
101
|
-
repeated EgressPolicy egress_policies =
|
|
99
|
+
repeated EgressPolicy egress_policies = 4;
|
|
102
100
|
// The extended attributes of the Domain
|
|
103
|
-
.google.protobuf.Struct extended =
|
|
101
|
+
.google.protobuf.Struct extended = 5;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
// The request message for Domains.Get
|
|
@@ -110,16 +110,8 @@ message UpdateNumberRequest {
|
|
|
110
110
|
string ref = 1;
|
|
111
111
|
// The name of the Number
|
|
112
112
|
string name = 2;
|
|
113
|
-
// The tel_url of the Number
|
|
114
|
-
string tel_url = 3;
|
|
115
113
|
// The aor_link of the Number
|
|
116
114
|
string aor_link = 4;
|
|
117
|
-
// The city of the Number
|
|
118
|
-
string city = 5;
|
|
119
|
-
// The country of the Number
|
|
120
|
-
string country = 6;
|
|
121
|
-
// The country_iso_code of the Number
|
|
122
|
-
string country_iso_code = 7;
|
|
123
115
|
// The header to use for session affinity
|
|
124
116
|
string session_affinity_header = 8;
|
|
125
117
|
// Extra headers to send to the trunk
|
|
@@ -42,10 +42,13 @@ service Peers {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
enum LoadBalancingAlgorithm {
|
|
45
|
+
// Value for situations where the load balancing algorithm is not specified
|
|
46
|
+
// Such as having an aor starting with "sip:"
|
|
47
|
+
UNSPECIFIED = 0;
|
|
45
48
|
// The round robin load balancing algorithm
|
|
46
|
-
ROUND_ROBIN =
|
|
49
|
+
ROUND_ROBIN = 1;
|
|
47
50
|
// The least sessions load balancing algorithm
|
|
48
|
-
LEAST_SESSIONS =
|
|
51
|
+
LEAST_SESSIONS = 2;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
// The message for the Peer resource
|
|
@@ -63,7 +66,7 @@ message Peer {
|
|
|
63
66
|
// The contact address of the Peer
|
|
64
67
|
string contact_addr = 6;
|
|
65
68
|
// The load balancing algorithm of the Peer
|
|
66
|
-
LoadBalancingAlgorithm
|
|
69
|
+
LoadBalancingAlgorithm balancing_algorithm = 7;
|
|
67
70
|
// The session affinity of the Peer
|
|
68
71
|
bool with_session_affinity = 8;
|
|
69
72
|
// The status of the Peer
|
|
@@ -91,7 +94,7 @@ message CreatePeerRequest {
|
|
|
91
94
|
// The contact address of the Peer
|
|
92
95
|
string contact_addr = 4;
|
|
93
96
|
// The load balancing algorithm of the Peer
|
|
94
|
-
LoadBalancingAlgorithm
|
|
97
|
+
LoadBalancingAlgorithm balancing_algorithm = 5;
|
|
95
98
|
// The session affinity of the Peer
|
|
96
99
|
bool with_session_affinity = 6;
|
|
97
100
|
// Reference to the ACL of the Peer
|
|
@@ -110,24 +113,22 @@ message UpdatePeerRequest {
|
|
|
110
113
|
string ref = 1;
|
|
111
114
|
// The name of the Peer
|
|
112
115
|
string name = 2;
|
|
113
|
-
// The username of the Peer
|
|
114
|
-
string username = 3;
|
|
115
116
|
// The address of record of the Peer
|
|
116
|
-
string aor =
|
|
117
|
+
string aor = 3;
|
|
117
118
|
// The contact address of the Peer
|
|
118
|
-
string contact_addr =
|
|
119
|
+
string contact_addr = 4;
|
|
119
120
|
// The load balancing algorithm of the Peer
|
|
120
|
-
LoadBalancingAlgorithm
|
|
121
|
+
LoadBalancingAlgorithm balancing_algorithm = 5;
|
|
121
122
|
// The session affinity of the Peer
|
|
122
|
-
bool with_session_affinity =
|
|
123
|
+
bool with_session_affinity = 6;
|
|
123
124
|
// Reference to the ACL of the Peer
|
|
124
|
-
string access_control_list_ref =
|
|
125
|
+
string access_control_list_ref = 7;
|
|
125
126
|
// Reference to the Credentials of the Peer
|
|
126
|
-
string credentials_ref =
|
|
127
|
+
string credentials_ref = 8;
|
|
127
128
|
// The status of the Peer
|
|
128
|
-
bool enabled =
|
|
129
|
+
bool enabled = 9;
|
|
129
130
|
// The extended attributes of the Peer
|
|
130
|
-
.google.protobuf.Struct extended =
|
|
131
|
+
.google.protobuf.Struct extended = 10;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
// The request message for the Peers.Get method
|
|
@@ -21,7 +21,6 @@ declare const _default: {
|
|
|
21
21
|
name: {
|
|
22
22
|
description: string;
|
|
23
23
|
type: string;
|
|
24
|
-
minLength: number;
|
|
25
24
|
maxLength: number;
|
|
26
25
|
};
|
|
27
26
|
};
|
|
@@ -40,6 +39,8 @@ declare const _default: {
|
|
|
40
39
|
type: string;
|
|
41
40
|
items: {
|
|
42
41
|
type: string;
|
|
42
|
+
minLength: number;
|
|
43
|
+
maxLength: number;
|
|
43
44
|
};
|
|
44
45
|
minItems: number;
|
|
45
46
|
uniqueItems: boolean;
|
|
@@ -49,6 +50,8 @@ declare const _default: {
|
|
|
49
50
|
type: string;
|
|
50
51
|
items: {
|
|
51
52
|
type: string;
|
|
53
|
+
minLength: number;
|
|
54
|
+
maxLength: number;
|
|
52
55
|
};
|
|
53
56
|
minItems: number;
|
|
54
57
|
uniqueItems: boolean;
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -59,7 +58,9 @@ exports.default = {
|
|
|
59
58
|
description: "Allowed list of access control rules",
|
|
60
59
|
type: "array",
|
|
61
60
|
items: {
|
|
62
|
-
type: "string"
|
|
61
|
+
type: "string",
|
|
62
|
+
minLength: 7,
|
|
63
|
+
maxLength: 18
|
|
63
64
|
},
|
|
64
65
|
minItems: 1,
|
|
65
66
|
uniqueItems: true
|
|
@@ -68,7 +69,9 @@ exports.default = {
|
|
|
68
69
|
description: "Denied list of access control rules",
|
|
69
70
|
type: "array",
|
|
70
71
|
items: {
|
|
71
|
-
type: "string"
|
|
72
|
+
type: "string",
|
|
73
|
+
minLength: 7,
|
|
74
|
+
maxLength: 18
|
|
72
75
|
},
|
|
73
76
|
minItems: 1,
|
|
74
77
|
uniqueItems: true
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -54,8 +53,8 @@ exports.default = {
|
|
|
54
53
|
username: {
|
|
55
54
|
description: "The username for the Agent",
|
|
56
55
|
type: "string",
|
|
57
|
-
minLength:
|
|
58
|
-
maxLength:
|
|
56
|
+
minLength: 4,
|
|
57
|
+
maxLength: 60,
|
|
59
58
|
readOnly: true
|
|
60
59
|
},
|
|
61
60
|
domainRef: {
|
|
@@ -21,7 +21,6 @@ declare const _default: {
|
|
|
21
21
|
name: {
|
|
22
22
|
description: string;
|
|
23
23
|
type: string;
|
|
24
|
-
minLength: number;
|
|
25
24
|
maxLength: number;
|
|
26
25
|
};
|
|
27
26
|
};
|
|
@@ -46,6 +45,7 @@ declare const _default: {
|
|
|
46
45
|
description: string;
|
|
47
46
|
type: string;
|
|
48
47
|
writeOnly: boolean;
|
|
48
|
+
maxLength: number;
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
required: string[];
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -59,13 +58,14 @@ exports.default = {
|
|
|
59
58
|
description: "Username",
|
|
60
59
|
type: "string",
|
|
61
60
|
readOnly: true,
|
|
62
|
-
minLength:
|
|
63
|
-
maxLength:
|
|
61
|
+
minLength: 4,
|
|
62
|
+
maxLength: 60
|
|
64
63
|
},
|
|
65
64
|
password: {
|
|
66
65
|
description: "Password",
|
|
67
66
|
type: "string",
|
|
68
|
-
writeOnly: true
|
|
67
|
+
writeOnly: true,
|
|
68
|
+
maxLength: 255
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
required: ["username", "password"]
|
|
@@ -21,7 +21,6 @@ declare const _default: {
|
|
|
21
21
|
name: {
|
|
22
22
|
description: string;
|
|
23
23
|
type: string;
|
|
24
|
-
minLength: number;
|
|
25
24
|
maxLength: number;
|
|
26
25
|
};
|
|
27
26
|
};
|
|
@@ -38,7 +37,6 @@ declare const _default: {
|
|
|
38
37
|
domainUri: {
|
|
39
38
|
description: string;
|
|
40
39
|
type: string;
|
|
41
|
-
minLength: number;
|
|
42
40
|
maxLength: number;
|
|
43
41
|
};
|
|
44
42
|
accessControlListRef: {
|
|
@@ -54,7 +52,6 @@ declare const _default: {
|
|
|
54
52
|
rule: {
|
|
55
53
|
description: string;
|
|
56
54
|
type: string;
|
|
57
|
-
minLength: number;
|
|
58
55
|
};
|
|
59
56
|
numberRef: {
|
|
60
57
|
description: string;
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -58,7 +57,6 @@ exports.default = {
|
|
|
58
57
|
domainUri: {
|
|
59
58
|
description: "The URI of the Domain",
|
|
60
59
|
type: "string",
|
|
61
|
-
minLength: 3,
|
|
62
60
|
maxLength: 255
|
|
63
61
|
},
|
|
64
62
|
accessControlListRef: {
|
|
@@ -73,8 +71,7 @@ exports.default = {
|
|
|
73
71
|
properties: {
|
|
74
72
|
rule: {
|
|
75
73
|
description: "The rule for the egress policy",
|
|
76
|
-
type: "string"
|
|
77
|
-
minLength: 1
|
|
74
|
+
type: "string"
|
|
78
75
|
},
|
|
79
76
|
numberRef: {
|
|
80
77
|
description: "The reference to the number",
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -66,7 +65,7 @@ exports.default = {
|
|
|
66
65
|
aorLink: {
|
|
67
66
|
description: "AOR link",
|
|
68
67
|
type: "string",
|
|
69
|
-
minLength:
|
|
68
|
+
minLength: 5,
|
|
70
69
|
maxLength: 255
|
|
71
70
|
},
|
|
72
71
|
sessionAffinityHeader: {
|
|
@@ -21,7 +21,6 @@ declare const _default: {
|
|
|
21
21
|
name: {
|
|
22
22
|
description: string;
|
|
23
23
|
type: string;
|
|
24
|
-
minLength: number;
|
|
25
24
|
maxLength: number;
|
|
26
25
|
};
|
|
27
26
|
};
|
|
@@ -47,6 +46,7 @@ declare const _default: {
|
|
|
47
46
|
contactAddr: {
|
|
48
47
|
description: string;
|
|
49
48
|
type: string;
|
|
49
|
+
minLength: number;
|
|
50
50
|
maxLength: number;
|
|
51
51
|
};
|
|
52
52
|
credentialsRef: {
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -54,20 +53,21 @@ exports.default = {
|
|
|
54
53
|
username: {
|
|
55
54
|
description: "The username for the Peer",
|
|
56
55
|
type: "string",
|
|
57
|
-
minLength:
|
|
58
|
-
maxLength:
|
|
56
|
+
minLength: 4,
|
|
57
|
+
maxLength: 60,
|
|
59
58
|
readOnly: true
|
|
60
59
|
},
|
|
61
60
|
aor: {
|
|
62
61
|
description: "Address of the Peer (acceptable schemas are sip, backend.)",
|
|
63
62
|
type: "string",
|
|
64
|
-
minLength:
|
|
65
|
-
maxLength:
|
|
63
|
+
minLength: 5,
|
|
64
|
+
maxLength: 323
|
|
66
65
|
},
|
|
67
66
|
contactAddr: {
|
|
68
67
|
description: "Contact address of the Peer",
|
|
69
68
|
type: "string",
|
|
70
|
-
|
|
69
|
+
minLength: 7,
|
|
70
|
+
maxLength: 20
|
|
71
71
|
},
|
|
72
72
|
credentialsRef: {
|
|
73
73
|
description: "The credential the Peer uses to authenticate",
|
|
@@ -21,7 +21,6 @@ declare const _default: {
|
|
|
21
21
|
name: {
|
|
22
22
|
description: string;
|
|
23
23
|
type: string;
|
|
24
|
-
minLength: number;
|
|
25
24
|
maxLength: number;
|
|
26
25
|
};
|
|
27
26
|
};
|
|
@@ -76,10 +75,12 @@ declare const _default: {
|
|
|
76
75
|
host: {
|
|
77
76
|
description: string;
|
|
78
77
|
type: string;
|
|
78
|
+
maxLength: number;
|
|
79
79
|
};
|
|
80
80
|
port: {
|
|
81
81
|
description: string;
|
|
82
82
|
type: string;
|
|
83
|
+
maximum: number;
|
|
83
84
|
};
|
|
84
85
|
transport: {
|
|
85
86
|
description: string;
|
|
@@ -88,6 +89,7 @@ declare const _default: {
|
|
|
88
89
|
user: {
|
|
89
90
|
description: string;
|
|
90
91
|
type: string;
|
|
92
|
+
maxLength: number;
|
|
91
93
|
};
|
|
92
94
|
};
|
|
93
95
|
required: string[];
|
|
@@ -95,10 +97,14 @@ declare const _default: {
|
|
|
95
97
|
weight: {
|
|
96
98
|
description: string;
|
|
97
99
|
type: string;
|
|
100
|
+
minimum: number;
|
|
101
|
+
maximum: number;
|
|
98
102
|
};
|
|
99
103
|
priority: {
|
|
100
104
|
description: string;
|
|
101
105
|
type: string;
|
|
106
|
+
minimum: number;
|
|
107
|
+
maximum: number;
|
|
102
108
|
};
|
|
103
109
|
enabled: {
|
|
104
110
|
description: string;
|
|
@@ -41,8 +41,7 @@ exports.default = {
|
|
|
41
41
|
name: {
|
|
42
42
|
description: "Resource's friendly name",
|
|
43
43
|
type: "string",
|
|
44
|
-
|
|
45
|
-
maxLength: 64
|
|
44
|
+
maxLength: 60
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
required: ["name"]
|
|
@@ -95,11 +94,13 @@ exports.default = {
|
|
|
95
94
|
properties: {
|
|
96
95
|
host: {
|
|
97
96
|
description: "Hostname of the URI",
|
|
98
|
-
type: "string"
|
|
97
|
+
type: "string",
|
|
98
|
+
maxLength: 255
|
|
99
99
|
},
|
|
100
100
|
port: {
|
|
101
101
|
description: "Port of the URI",
|
|
102
|
-
type: "integer"
|
|
102
|
+
type: "integer",
|
|
103
|
+
maximum: 65535
|
|
103
104
|
},
|
|
104
105
|
transport: {
|
|
105
106
|
description: "Transport of the URI",
|
|
@@ -120,18 +121,23 @@ exports.default = {
|
|
|
120
121
|
},
|
|
121
122
|
user: {
|
|
122
123
|
description: "Username of the URI",
|
|
123
|
-
type: "string"
|
|
124
|
+
type: "string",
|
|
125
|
+
maxLength: 60
|
|
124
126
|
}
|
|
125
127
|
},
|
|
126
128
|
required: ["host", "port", "transport"]
|
|
127
129
|
},
|
|
128
130
|
weight: {
|
|
129
131
|
description: "Weight of the URI",
|
|
130
|
-
type: "integer"
|
|
132
|
+
type: "integer",
|
|
133
|
+
minimum: 1,
|
|
134
|
+
maximum: 65535
|
|
131
135
|
},
|
|
132
136
|
priority: {
|
|
133
137
|
description: "Priority of the URI",
|
|
134
|
-
type: "integer"
|
|
138
|
+
type: "integer",
|
|
139
|
+
minimum: 0,
|
|
140
|
+
maximum: 65535
|
|
135
141
|
},
|
|
136
142
|
enabled: {
|
|
137
143
|
description: "Whether the URI is enabled",
|
package/dist/connect/types.d.ts
CHANGED
|
@@ -19,8 +19,8 @@ export interface BaseConnectModel {
|
|
|
19
19
|
apiVersion: string;
|
|
20
20
|
ref: string;
|
|
21
21
|
name: string;
|
|
22
|
-
createdAt?:
|
|
23
|
-
updatedAt?:
|
|
22
|
+
createdAt?: number;
|
|
23
|
+
updatedAt?: number;
|
|
24
24
|
extended?: JsonObject;
|
|
25
25
|
}
|
|
26
26
|
export interface AccessControlList extends BaseConnectModel {
|
|
@@ -56,7 +56,7 @@ export interface INumber extends BaseConnectModel {
|
|
|
56
56
|
aorLink: string;
|
|
57
57
|
city: string;
|
|
58
58
|
country: string;
|
|
59
|
-
|
|
59
|
+
countryIsoCode: string;
|
|
60
60
|
sessionAffinityHeader: string;
|
|
61
61
|
extraHeaders: {
|
|
62
62
|
name: string;
|
|
@@ -74,9 +74,11 @@ export interface Trunk extends BaseConnectModel {
|
|
|
74
74
|
inboundCredentials?: Credentials;
|
|
75
75
|
outboundCredentialsRef?: string;
|
|
76
76
|
outboundCredentials?: Credentials;
|
|
77
|
-
uris
|
|
77
|
+
uris?: TrunkURI[];
|
|
78
78
|
}
|
|
79
79
|
export interface TrunkURI {
|
|
80
|
+
ref?: string;
|
|
81
|
+
trunkRef?: string;
|
|
80
82
|
host: string;
|
|
81
83
|
port: number;
|
|
82
84
|
transport: Transport;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BadRequestError } from "../errors";
|
|
2
|
+
import { LoadBalancingAlgorithm } from "../types";
|
|
3
|
+
export declare const hasReference: (ref: string) => true | BadRequestError;
|
|
4
|
+
export declare const hasName: (name: string) => true | BadRequestError;
|
|
5
|
+
export declare const isValidName: (name: string) => true | BadRequestError;
|
|
6
|
+
export declare const hasUsername: (username: string) => true | BadRequestError;
|
|
7
|
+
export declare const isValidUsername: (username: string) => true | BadRequestError;
|
|
8
|
+
export declare const hasPassword: (password: string) => true | BadRequestError;
|
|
9
|
+
export declare const hasDomainUri: (domainUri: string) => true | BadRequestError;
|
|
10
|
+
export declare const isValidDomainUri: (domainUri: string) => true | BadRequestError;
|
|
11
|
+
export declare const hasTelUrl: (telUrl: string) => true | BadRequestError;
|
|
12
|
+
export declare const isValidSessionAffinityHeader: (sessionAffinityHeader: string) => true | BadRequestError;
|
|
13
|
+
export declare const isValidHeader: (header: string) => true | BadRequestError;
|
|
14
|
+
export declare const hasValidHeaders: (headers: {
|
|
15
|
+
name: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}[]) => true | BadRequestError;
|
|
18
|
+
export declare const hasAOR: (aor: string) => true | BadRequestError;
|
|
19
|
+
export declare const isValidAOR: (aor: string) => true | BadRequestError;
|
|
20
|
+
export declare const hasAORLink: (aorLink: string) => true | BadRequestError;
|
|
21
|
+
export declare const isValidAORLink: (aorLink: string) => true | BadRequestError;
|
|
22
|
+
export declare const hasCity: (city: string) => true | BadRequestError;
|
|
23
|
+
export declare const hasCountry: (country: string) => true | BadRequestError;
|
|
24
|
+
export declare const hasCountryISOCode: (countryIsoCode: string) => true | BadRequestError;
|
|
25
|
+
export declare const hasACLRules: (acl: {
|
|
26
|
+
deny: string[];
|
|
27
|
+
allow: string[];
|
|
28
|
+
}) => true | BadRequestError;
|
|
29
|
+
export declare const isValidACLRule: (rules: string[]) => true | BadRequestError;
|
|
30
|
+
export declare const hasValidACLRules: (acl: {
|
|
31
|
+
deny: string[];
|
|
32
|
+
allow: string[];
|
|
33
|
+
}) => true | BadRequestError;
|
|
34
|
+
export declare const hasInboundUri: (inboundUri: string) => true | BadRequestError;
|
|
35
|
+
export declare const isValidInboundUri: (inboundUri: string) => true | BadRequestError;
|
|
36
|
+
export declare const isValidBalancingAlgorithm: (aor: string, algorithm: LoadBalancingAlgorithm) => BadRequestError;
|
|
37
|
+
export declare const isValidPort: (port: string) => BadRequestError;
|
|
38
|
+
export declare const hasHost: (host: string) => true | BadRequestError;
|
|
39
|
+
export declare const isValidHost: (host: string) => true | BadRequestError;
|
|
40
|
+
export declare const isValidContactAddress: (contactAddress: string) => BadRequestError;
|
|
41
|
+
export declare const isValidPriority: (priority: string) => BadRequestError;
|
|
42
|
+
export declare const isValidWeight: (weight: string) => BadRequestError;
|
|
43
|
+
export declare const isValidE164: (e164Number: string, countryISOCode: string, validateMobilePrefix?: boolean) => BadRequestError;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isValidE164 = exports.isValidWeight = exports.isValidPriority = exports.isValidContactAddress = exports.isValidHost = exports.hasHost = exports.isValidPort = exports.isValidBalancingAlgorithm = exports.isValidInboundUri = exports.hasInboundUri = exports.hasValidACLRules = exports.isValidACLRule = exports.hasACLRules = exports.hasCountryISOCode = exports.hasCountry = exports.hasCity = exports.isValidAORLink = exports.hasAORLink = exports.isValidAOR = exports.hasAOR = exports.hasValidHeaders = exports.isValidHeader = exports.isValidSessionAffinityHeader = exports.hasTelUrl = exports.isValidDomainUri = exports.hasDomainUri = exports.hasPassword = exports.isValidUsername = exports.hasUsername = exports.isValidName = exports.hasName = exports.hasReference = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Routr.
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License");
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
const Validator = __importStar(require("validator"));
|
|
46
|
+
const errors_1 = require("../errors");
|
|
47
|
+
const types_1 = require("../types");
|
|
48
|
+
const phone_1 = require("phone");
|
|
49
|
+
const hasReference = (ref) => ref ? true : new errors_1.BadRequestError("the reference to the resource is required");
|
|
50
|
+
exports.hasReference = hasReference;
|
|
51
|
+
const hasName = (name) => name
|
|
52
|
+
? true
|
|
53
|
+
: new errors_1.BadRequestError("the friendly name for the resource is required");
|
|
54
|
+
exports.hasName = hasName;
|
|
55
|
+
const isValidName = (name) => {
|
|
56
|
+
return Validator.default.isLength(name, { min: 1, max: 60 })
|
|
57
|
+
? true
|
|
58
|
+
: new errors_1.BadRequestError("the friendly name must have less than 60 characters");
|
|
59
|
+
};
|
|
60
|
+
exports.isValidName = isValidName;
|
|
61
|
+
const hasUsername = (username) => username ? true : new errors_1.BadRequestError("the username is required");
|
|
62
|
+
exports.hasUsername = hasUsername;
|
|
63
|
+
const isValidUsername = (username) => {
|
|
64
|
+
if (username &&
|
|
65
|
+
(!Validator.default.isAlphanumeric(username) ||
|
|
66
|
+
!Validator.default.isLowercase(username))) {
|
|
67
|
+
return new errors_1.BadRequestError("the username must be a lowercase, alphanumeric, and without spaces");
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
exports.isValidUsername = isValidUsername;
|
|
72
|
+
const hasPassword = (password) => password ? true : new errors_1.BadRequestError("the password is required");
|
|
73
|
+
exports.hasPassword = hasPassword;
|
|
74
|
+
const hasDomainUri = (domainUri) => domainUri ? true : new errors_1.BadRequestError("the domainUri is required");
|
|
75
|
+
exports.hasDomainUri = hasDomainUri;
|
|
76
|
+
const isValidDomainUri = (domainUri) => {
|
|
77
|
+
return Validator.default.isFQDN(domainUri)
|
|
78
|
+
? true
|
|
79
|
+
: new errors_1.BadRequestError("the domainUri must be a valid fully qualified domain name");
|
|
80
|
+
};
|
|
81
|
+
exports.isValidDomainUri = isValidDomainUri;
|
|
82
|
+
const hasTelUrl = (telUrl) => telUrl ? true : new errors_1.BadRequestError("the telUrl is required");
|
|
83
|
+
exports.hasTelUrl = hasTelUrl;
|
|
84
|
+
// Supports alphanumeric, underscore, and dash (cannot end with dash)
|
|
85
|
+
const isValidAlphanumeric = (value) => {
|
|
86
|
+
if (value.endsWith("-")) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const regex = /^[a-zA-Z0-9-]+$/;
|
|
90
|
+
return regex.test(value);
|
|
91
|
+
};
|
|
92
|
+
const isValidSessionAffinityHeader = (sessionAffinityHeader) => {
|
|
93
|
+
return sessionAffinityHeader
|
|
94
|
+
? isValidAlphanumeric(sessionAffinityHeader)
|
|
95
|
+
? true
|
|
96
|
+
: new errors_1.BadRequestError("the sessionAffinityHeader must be alphanumeric and without spaces")
|
|
97
|
+
: true;
|
|
98
|
+
};
|
|
99
|
+
exports.isValidSessionAffinityHeader = isValidSessionAffinityHeader;
|
|
100
|
+
const isValidHeader = (header) => {
|
|
101
|
+
return header
|
|
102
|
+
? isValidAlphanumeric(header)
|
|
103
|
+
? true
|
|
104
|
+
: new errors_1.BadRequestError("the header must be alphanumeric and without spaces")
|
|
105
|
+
: true;
|
|
106
|
+
};
|
|
107
|
+
exports.isValidHeader = isValidHeader;
|
|
108
|
+
const hasValidHeaders = (headers) => {
|
|
109
|
+
// eslint-disable-next-line no-loops/no-loops
|
|
110
|
+
for (const header of headers) {
|
|
111
|
+
const E = (0, exports.isValidHeader)(header.name);
|
|
112
|
+
if (!header.value) {
|
|
113
|
+
return new errors_1.BadRequestError("the header value cannot be empty");
|
|
114
|
+
}
|
|
115
|
+
if (E instanceof errors_1.BadRequestError) {
|
|
116
|
+
return E;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
121
|
+
exports.hasValidHeaders = hasValidHeaders;
|
|
122
|
+
const hasAOR = (aor) => aor ? true : new errors_1.BadRequestError("the address of record (aor) is required");
|
|
123
|
+
exports.hasAOR = hasAOR;
|
|
124
|
+
const isValidAOR = (aor) => {
|
|
125
|
+
if (aor) {
|
|
126
|
+
if (!aor.startsWith("backend:") && !aor.startsWith("sip:")) {
|
|
127
|
+
return new errors_1.BadRequestError("the aor schema must start with `backend:` or `sip:`");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
exports.isValidAOR = isValidAOR;
|
|
133
|
+
const hasAORLink = (aorLink) => aorLink ? true : new errors_1.BadRequestError("the aorLink is required");
|
|
134
|
+
exports.hasAORLink = hasAORLink;
|
|
135
|
+
const isValidAORLink = (aorLink) => {
|
|
136
|
+
if (aorLink) {
|
|
137
|
+
if (!aorLink.startsWith("backend:") && !aorLink.startsWith("sip:")) {
|
|
138
|
+
return new errors_1.BadRequestError("the aorLink must start with backend: or sip:");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
};
|
|
143
|
+
exports.isValidAORLink = isValidAORLink;
|
|
144
|
+
const hasCity = (city) => city ? true : new errors_1.BadRequestError("the city is required");
|
|
145
|
+
exports.hasCity = hasCity;
|
|
146
|
+
const hasCountry = (country) => country ? true : new errors_1.BadRequestError("the country is required");
|
|
147
|
+
exports.hasCountry = hasCountry;
|
|
148
|
+
const hasCountryISOCode = (countryIsoCode) => countryIsoCode ? true : new errors_1.BadRequestError("the countryISOCode is required");
|
|
149
|
+
exports.hasCountryISOCode = hasCountryISOCode;
|
|
150
|
+
const hasACLRules = (acl) => {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
if (!(acl === null || acl === void 0 ? void 0 : acl.deny) ||
|
|
153
|
+
!(acl === null || acl === void 0 ? void 0 : acl.allow) ||
|
|
154
|
+
((_a = acl.deny) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
155
|
+
((_b = acl.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
156
|
+
return new errors_1.BadRequestError("acl rules are required");
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
};
|
|
160
|
+
exports.hasACLRules = hasACLRules;
|
|
161
|
+
const isValidACLRule = (rules) => {
|
|
162
|
+
// eslint-disable-next-line no-loops/no-loops
|
|
163
|
+
for (const cidr of rules) {
|
|
164
|
+
if (!Validator.default.isIPRange(cidr, 4) &&
|
|
165
|
+
!Validator.default.isIP(cidr, 4)) {
|
|
166
|
+
return new errors_1.BadRequestError(`${cidr} is not a valid cidr or ip`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
};
|
|
171
|
+
exports.isValidACLRule = isValidACLRule;
|
|
172
|
+
const hasValidACLRules = (acl) => {
|
|
173
|
+
const deny = (0, exports.isValidACLRule)(acl === null || acl === void 0 ? void 0 : acl.deny);
|
|
174
|
+
if (deny instanceof errors_1.BadRequestError) {
|
|
175
|
+
return deny;
|
|
176
|
+
}
|
|
177
|
+
const allow = (0, exports.isValidACLRule)(acl === null || acl === void 0 ? void 0 : acl.allow);
|
|
178
|
+
if (allow instanceof errors_1.BadRequestError) {
|
|
179
|
+
return allow;
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
};
|
|
183
|
+
exports.hasValidACLRules = hasValidACLRules;
|
|
184
|
+
const hasInboundUri = (inboundUri) => inboundUri ? true : new errors_1.BadRequestError("the inboundUri is required");
|
|
185
|
+
exports.hasInboundUri = hasInboundUri;
|
|
186
|
+
const isValidInboundUri = (inboundUri) => {
|
|
187
|
+
if (inboundUri && !Validator.default.isFQDN(inboundUri)) {
|
|
188
|
+
return new errors_1.BadRequestError("the inbound URI must be a valid FQDN (e.g. sip.example.com)");
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
};
|
|
192
|
+
exports.isValidInboundUri = isValidInboundUri;
|
|
193
|
+
const isValidBalancingAlgorithm = (aor, algorithm) => {
|
|
194
|
+
if (aor.startsWith("backend:")) {
|
|
195
|
+
if (!algorithm || algorithm === types_1.LoadBalancingAlgorithm.UNSPECIFIED) {
|
|
196
|
+
return new errors_1.BadRequestError("when the aor schema is `backend:`, the balancing algorithm is required");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
if (algorithm && algorithm !== types_1.LoadBalancingAlgorithm.UNSPECIFIED) {
|
|
201
|
+
return new errors_1.BadRequestError("when the aor schema is `sip:`, the balancing algorithm is not allowed");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
exports.isValidBalancingAlgorithm = isValidBalancingAlgorithm;
|
|
206
|
+
const isValidPort = (port) => {
|
|
207
|
+
if (port) {
|
|
208
|
+
if (!Validator.default.isPort(port)) {
|
|
209
|
+
return new errors_1.BadRequestError("the port must be a valid port");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
exports.isValidPort = isValidPort;
|
|
214
|
+
const hasHost = (host) => host ? true : new errors_1.BadRequestError("the host is required");
|
|
215
|
+
exports.hasHost = hasHost;
|
|
216
|
+
const isValidHost = (host) => {
|
|
217
|
+
if (host) {
|
|
218
|
+
if (!Validator.default.isFQDN(host) && !Validator.default.isIP(host)) {
|
|
219
|
+
return new errors_1.BadRequestError("the host must be a valid FQDN or IP");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
};
|
|
224
|
+
exports.isValidHost = isValidHost;
|
|
225
|
+
const isValidContactAddress = (contactAddress) => {
|
|
226
|
+
if (contactAddress) {
|
|
227
|
+
const hostPart = contactAddress.split(":")[0];
|
|
228
|
+
const portPart = hostPart.split(":")[1] || "5060";
|
|
229
|
+
if (!Validator.default.isFQDN(hostPart) &&
|
|
230
|
+
!Validator.default.isIP(hostPart)) {
|
|
231
|
+
return new errors_1.BadRequestError("the contact address must be a valid FQDN or IP");
|
|
232
|
+
}
|
|
233
|
+
if (!Validator.default.isPort(portPart)) {
|
|
234
|
+
return new errors_1.BadRequestError("the contact port must be a valid port");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
exports.isValidContactAddress = isValidContactAddress;
|
|
239
|
+
const isValidPriority = (priority) => {
|
|
240
|
+
if (priority) {
|
|
241
|
+
if (!Validator.default.isInt(priority)) {
|
|
242
|
+
return new errors_1.BadRequestError("the priority must be a valid integer");
|
|
243
|
+
}
|
|
244
|
+
const p = parseInt(priority);
|
|
245
|
+
if (p < 0 || p > 65535) {
|
|
246
|
+
return new errors_1.BadRequestError("the priority must be between 0 and 65535");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
exports.isValidPriority = isValidPriority;
|
|
251
|
+
const isValidWeight = (weight) => {
|
|
252
|
+
if (weight) {
|
|
253
|
+
if (!Validator.default.isInt(weight)) {
|
|
254
|
+
return new errors_1.BadRequestError("the priority must be a valid integer");
|
|
255
|
+
}
|
|
256
|
+
const w = parseInt(weight);
|
|
257
|
+
if (w < 1 || w > 65535) {
|
|
258
|
+
return new errors_1.BadRequestError("the weight must be between 1 and 65535");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
exports.isValidWeight = isValidWeight;
|
|
263
|
+
const isValidE164 = (e164Number, countryISOCode, validateMobilePrefix = false) => {
|
|
264
|
+
const result = (0, phone_1.phone)(e164Number, {
|
|
265
|
+
country: countryISOCode,
|
|
266
|
+
validateMobilePrefix
|
|
267
|
+
});
|
|
268
|
+
if (!result.isValid) {
|
|
269
|
+
return new errors_1.BadRequestError("the telUrl must be a valid e164 number");
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
exports.isValidE164 = isValidE164;
|
package/dist/types.d.ts
CHANGED
|
@@ -24,8 +24,9 @@ export declare enum Transport {
|
|
|
24
24
|
WSS = "WSS"
|
|
25
25
|
}
|
|
26
26
|
export declare enum LoadBalancingAlgorithm {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
UNSPECIFIED = "UNSPECIFIED",
|
|
28
|
+
ROUND_ROBIN = "ROUND_ROBIN",
|
|
29
|
+
LEAST_SESSIONS = "LEAST_SESSIONS"
|
|
29
30
|
}
|
|
30
31
|
export declare enum ExtraHeader {
|
|
31
32
|
REQUEST_URI = "X-Request-Uri",
|
package/dist/types.js
CHANGED
|
@@ -26,8 +26,9 @@ var Transport;
|
|
|
26
26
|
})(Transport = exports.Transport || (exports.Transport = {}));
|
|
27
27
|
var LoadBalancingAlgorithm;
|
|
28
28
|
(function (LoadBalancingAlgorithm) {
|
|
29
|
-
LoadBalancingAlgorithm["
|
|
30
|
-
LoadBalancingAlgorithm["
|
|
29
|
+
LoadBalancingAlgorithm["UNSPECIFIED"] = "UNSPECIFIED";
|
|
30
|
+
LoadBalancingAlgorithm["ROUND_ROBIN"] = "ROUND_ROBIN";
|
|
31
|
+
LoadBalancingAlgorithm["LEAST_SESSIONS"] = "LEAST_SESSIONS";
|
|
31
32
|
})(LoadBalancingAlgorithm = exports.LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = {}));
|
|
32
33
|
var ExtraHeader;
|
|
33
34
|
(function (ExtraHeader) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/common",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.22",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"ip-utils": "^2.4.0",
|
|
30
30
|
"js-yaml": "^4.1.0",
|
|
31
31
|
"pb-util": "^1.0.3",
|
|
32
|
-
"toml": "^3.0.0"
|
|
32
|
+
"toml": "^3.0.0",
|
|
33
|
+
"validator": "^13.7.0"
|
|
33
34
|
},
|
|
34
35
|
"directories": {
|
|
35
36
|
"src": "src",
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@types/js-yaml": "^4.0.5"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "7c1e14c20e077f817605be62cf61a68904583bb8"
|
|
55
56
|
}
|