@routr/common 2.0.8-alpha.9 → 2.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/assertions.js +2 -2
  2. package/dist/auth.d.ts +18 -11
  3. package/dist/auth.js +34 -12
  4. package/dist/connect/api/client.d.ts +3 -0
  5. package/dist/connect/api/client.js +158 -0
  6. package/dist/connect/api/index.d.ts +2 -0
  7. package/dist/connect/api/index.js +36 -0
  8. package/dist/connect/api/types.d.ts +51 -0
  9. package/dist/connect/api/types.js +2 -0
  10. package/dist/connect/assertions.d.ts +37 -0
  11. package/dist/connect/assertions.js +112 -0
  12. package/dist/connect/client.d.ts +8 -0
  13. package/dist/connect/client.js +94 -0
  14. package/dist/connect/config.d.ts +113 -0
  15. package/dist/connect/config.js +2 -0
  16. package/dist/connect/connect_error.d.ts +21 -0
  17. package/dist/connect/connect_error.js +44 -0
  18. package/dist/connect/index.d.ts +7 -2
  19. package/dist/connect/index.js +8 -3
  20. package/dist/connect/mappers/acl.d.ts +3 -0
  21. package/dist/connect/mappers/acl.js +19 -0
  22. package/dist/connect/mappers/agent.d.ts +3 -0
  23. package/dist/connect/mappers/agent.js +42 -0
  24. package/dist/connect/mappers/assertions.d.ts +3 -0
  25. package/dist/connect/mappers/assertions.js +43 -0
  26. package/dist/connect/mappers/credentials.d.ts +3 -0
  27. package/dist/connect/mappers/credentials.js +18 -0
  28. package/dist/connect/mappers/domain.d.ts +3 -0
  29. package/dist/connect/mappers/domain.js +19 -0
  30. package/dist/connect/mappers/index.d.ts +7 -0
  31. package/dist/connect/mappers/index.js +41 -0
  32. package/dist/connect/mappers/number.d.ts +3 -0
  33. package/dist/connect/mappers/number.js +26 -0
  34. package/dist/connect/mappers/peer.d.ts +3 -0
  35. package/dist/connect/mappers/peer.js +26 -0
  36. package/dist/connect/mappers/trunk.d.ts +3 -0
  37. package/dist/connect/mappers/trunk.js +34 -0
  38. package/dist/connect/protos/acl.proto +112 -0
  39. package/dist/connect/protos/agents.proto +153 -0
  40. package/dist/connect/protos/credentials.proto +114 -0
  41. package/dist/connect/protos/domains.proto +146 -0
  42. package/dist/connect/protos/numbers.proto +166 -0
  43. package/dist/connect/protos/peers.proto +174 -0
  44. package/dist/connect/protos/trunks.proto +178 -0
  45. package/dist/connect/schemas/acl.d.ts +66 -0
  46. package/dist/connect/schemas/acl.js +85 -0
  47. package/dist/connect/schemas/agent.d.ts +61 -0
  48. package/dist/connect/schemas/agent.js +80 -0
  49. package/dist/connect/schemas/crendentials.d.ts +59 -0
  50. package/dist/connect/schemas/crendentials.js +78 -0
  51. package/dist/connect/schemas/domain.d.ts +72 -0
  52. package/dist/connect/schemas/domain.js +91 -0
  53. package/dist/connect/schemas/index.d.ts +1 -0
  54. package/dist/connect/schemas/index.js +35 -0
  55. package/dist/connect/schemas/number.d.ts +81 -0
  56. package/dist/connect/schemas/number.js +100 -0
  57. package/dist/connect/schemas/peer.d.ts +84 -0
  58. package/dist/connect/schemas/peer.js +103 -0
  59. package/dist/connect/schemas/trunk.d.ts +125 -0
  60. package/dist/connect/schemas/trunk.js +157 -0
  61. package/dist/connect/schemas/validators.d.ts +2 -0
  62. package/dist/connect/schemas/validators.js +43 -0
  63. package/dist/connect/types.d.ts +89 -23
  64. package/dist/connect/types.js +7 -29
  65. package/dist/connect/validations.d.ts +43 -0
  66. package/dist/connect/validations.js +272 -0
  67. package/dist/envs.d.ts +2 -0
  68. package/dist/envs.js +23 -0
  69. package/dist/errors.d.ts +35 -1
  70. package/dist/errors.js +52 -6
  71. package/dist/healthcheck.d.ts +1 -0
  72. package/dist/healthcheck.js +24 -0
  73. package/dist/helper.d.ts +13 -0
  74. package/dist/helper.js +78 -4
  75. package/dist/index.d.ts +8 -4
  76. package/dist/index.js +9 -6
  77. package/dist/ip_utils.js +1 -1
  78. package/dist/protos/common.proto +2 -4
  79. package/dist/protos/location.proto +21 -8
  80. package/dist/protos/processor.proto +8 -6
  81. package/dist/protos/requester.proto +6 -6
  82. package/dist/protos/sipmessage.proto +9 -2
  83. package/dist/protos/verifier.proto +39 -0
  84. package/dist/requester/grpc_client.js +1 -1
  85. package/dist/requester/index.js +1 -1
  86. package/dist/service.d.ts +2 -2
  87. package/dist/service.js +27 -5
  88. package/dist/tracer.js +1 -1
  89. package/dist/types.d.ts +119 -87
  90. package/dist/types.js +79 -69
  91. package/dist/verifier/grpc_client.d.ts +1 -0
  92. package/dist/{connect → verifier}/grpc_client.js +4 -4
  93. package/dist/verifier/index.d.ts +2 -0
  94. package/dist/verifier/index.js +36 -0
  95. package/dist/verifier/types.d.ts +10 -0
  96. package/dist/verifier/types.js +2 -0
  97. package/dist/verifier/verifier.d.ts +3 -0
  98. package/dist/verifier/verifier.js +64 -0
  99. package/package.json +17 -7
  100. package/dist/connect/data_api.d.ts +0 -11
  101. package/dist/connect/data_api.js +0 -91
  102. package/dist/connect/grpc_client.d.ts +0 -1
  103. package/dist/protos/resources.proto +0 -108
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertEnvsAreSet = void 0;
4
4
  /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
@@ -29,7 +29,7 @@ const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename
29
29
  function assertEnvsAreSet(variables) {
30
30
  variables.forEach((variable) => {
31
31
  if (!(variable in process.env)) {
32
- logger.error(`The environment variable ${variable} is required but was not found`);
32
+ logger.error(`the environment variable ${variable} is required but was not found`);
33
33
  process.exit(1);
34
34
  }
35
35
  });
package/dist/auth.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { AuthChallengeRequest, AuthChallengeResponse } from "./types";
1
+ import { AuthChallengeRequest, AuthChallengeResponse, ResponseType } from "./types";
2
2
  export declare const generateNonce: (algorithm?: string) => string;
3
3
  export declare const buildAuthChallenge: (request: AuthChallengeRequest) => {
4
4
  realm: string;
5
- scheme: string;
6
- algorithm: string;
7
- qop: string;
5
+ scheme: "Digest";
6
+ algorithm: "MD5";
7
+ qop: import("./types").Qop;
8
8
  opaque: string;
9
9
  stale: boolean;
10
10
  nonce: string;
@@ -25,7 +25,8 @@ export declare const createUnauthorizedResponse: (realm: string, params?: {
25
25
  algorithm: string;
26
26
  }) => {
27
27
  message: {
28
- responseType: number;
28
+ responseType: ResponseType;
29
+ reasonPhrase: string;
29
30
  wwwAuthenticate: {
30
31
  scheme: string;
31
32
  realm: string;
@@ -37,18 +38,24 @@ export declare const createUnauthorizedResponse: (realm: string, params?: {
37
38
  };
38
39
  };
39
40
  };
40
- export declare const createUnauthorizedResponseWithoutChallenge: () => {
41
+ export declare const createUnauthorizedResponseWithoutChallenge: (metadata?: Record<string, string>) => {
42
+ metadata: Record<string, string>;
41
43
  message: {
42
- responseType: number;
44
+ responseType: ResponseType;
45
+ reasonPhrase: string;
43
46
  };
44
47
  };
45
- export declare const createServerInternalErrorResponse: () => {
48
+ export declare const createServerInternalErrorResponse: (metadata?: Record<string, string>) => {
49
+ metadata: Record<string, string>;
46
50
  message: {
47
- responseType: number;
51
+ responseType: ResponseType;
52
+ reasonPhrase: string;
48
53
  };
49
54
  };
50
- export declare const createForbideenResponse: () => {
55
+ export declare const createForbideenResponse: (metadata?: Record<string, string>) => {
56
+ metadata: Record<string, string>;
51
57
  message: {
52
- responseType: number;
58
+ responseType: ResponseType;
59
+ reasonPhrase: string;
53
60
  };
54
61
  };
package/dist/auth.js CHANGED
@@ -4,6 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createForbideenResponse = exports.createServerInternalErrorResponse = exports.createUnauthorizedResponseWithoutChallenge = exports.createUnauthorizedResponse = exports.getCredentials = exports.calculateAuthResponse = exports.buildAuthChallenge = exports.generateNonce = void 0;
7
+ /*
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/routr
10
+ *
11
+ * This file is part of Routr
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const types_1 = require("./types");
7
26
  const crypto_1 = __importDefault(require("crypto"));
8
27
  const DEFAULT_ALGORITHM = "MD5";
9
28
  const md5hex = (str, algorithm = DEFAULT_ALGORITHM) => crypto_1.default.createHash(algorithm).update(str).digest("hex");
@@ -37,11 +56,11 @@ const calculateAuthResponse = (res, credentials) => {
37
56
  exports.calculateAuthResponse = calculateAuthResponse;
38
57
  const getCredentials = (username, users) => users.find((user) => user.username === username);
39
58
  exports.getCredentials = getCredentials;
40
- const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: "MD5" }) => {
59
+ const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: DEFAULT_ALGORITHM }) => {
41
60
  return {
42
61
  message: {
43
- // Unauthorized Code
44
- responseType: 17,
62
+ responseType: types_1.ResponseType.UNAUTHORIZED,
63
+ reasonPhrase: "Unauthorized",
45
64
  wwwAuthenticate: {
46
65
  scheme: "Digest",
47
66
  realm: realm,
@@ -55,29 +74,32 @@ const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: "M
55
74
  };
56
75
  };
57
76
  exports.createUnauthorizedResponse = createUnauthorizedResponse;
58
- const createUnauthorizedResponseWithoutChallenge = () => {
77
+ const createUnauthorizedResponseWithoutChallenge = (metadata) => {
59
78
  return {
79
+ metadata,
60
80
  message: {
61
- // Unauthorized Code
62
- responseType: 17
81
+ responseType: types_1.ResponseType.UNAUTHORIZED,
82
+ reasonPhrase: "Unauthorized"
63
83
  }
64
84
  };
65
85
  };
66
86
  exports.createUnauthorizedResponseWithoutChallenge = createUnauthorizedResponseWithoutChallenge;
67
- const createServerInternalErrorResponse = () => {
87
+ const createServerInternalErrorResponse = (metadata) => {
68
88
  return {
89
+ metadata,
69
90
  message: {
70
- // Unauthorized Code
71
- responseType: 46
91
+ responseType: types_1.ResponseType.SERVER_INTERNAL_ERROR,
92
+ reasonPhrase: "Server Internal Error"
72
93
  }
73
94
  };
74
95
  };
75
96
  exports.createServerInternalErrorResponse = createServerInternalErrorResponse;
76
- const createForbideenResponse = () => {
97
+ const createForbideenResponse = (metadata) => {
77
98
  return {
99
+ metadata,
78
100
  message: {
79
- // Forbideen Code
80
- responseType: 19
101
+ responseType: types_1.ResponseType.FORBIDDEN,
102
+ reasonPhrase: "Forbidden"
81
103
  }
82
104
  };
83
105
  };
@@ -0,0 +1,3 @@
1
+ import { APIClient, DataAPIOptions, ServiceAPI, ServiceAPIOptions } from "./types";
2
+ export declare function apiClient(options: DataAPIOptions): APIClient;
3
+ export declare function serviceAPI<R>(options: ServiceAPIOptions): ServiceAPI<R>;
@@ -0,0 +1,158 @@
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.serviceAPI = exports.apiClient = void 0;
27
+ /*
28
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
+ * http://github.com/fonoster/routr
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
+ /* eslint-disable require-jsdoc */
46
+ const grpc = __importStar(require("@grpc/grpc-js"));
47
+ const pb_util_1 = require("pb-util");
48
+ const errors_1 = require("../../errors");
49
+ const client_1 = require("../client");
50
+ const types_1 = require("../types");
51
+ function fire(err, apiAddr) {
52
+ if (err.code === grpc.status.UNAVAILABLE) {
53
+ return new errors_1.ServiceUnavailableError(apiAddr);
54
+ }
55
+ return err;
56
+ }
57
+ function apiClient(options) {
58
+ return {
59
+ agents: serviceAPI(Object.assign({ kind: types_1.Kind.AGENT }, options)),
60
+ domains: serviceAPI(Object.assign({ kind: types_1.Kind.DOMAIN }, options)),
61
+ trunks: serviceAPI(Object.assign({ kind: types_1.Kind.TRUNK }, options)),
62
+ credentials: serviceAPI(Object.assign({ kind: types_1.Kind.CREDENTIALS }, options)),
63
+ acl: serviceAPI(Object.assign({ kind: types_1.Kind.ACL }, options)),
64
+ peers: serviceAPI(Object.assign({ kind: types_1.Kind.PEER }, options)),
65
+ numbers: serviceAPI(Object.assign({ kind: types_1.Kind.NUMBER }, options))
66
+ };
67
+ }
68
+ exports.apiClient = apiClient;
69
+ function serviceAPI(options) {
70
+ const { kind, apiAddr, credentials, metadata } = options;
71
+ // Workaround for issue not allowing to pass metadata to grpc-js
72
+ const meta = new grpc.Metadata();
73
+ if (metadata) {
74
+ Object.keys(metadata.toJSON()).forEach((key) => {
75
+ meta.set(key, metadata.getMap()[key]);
76
+ });
77
+ }
78
+ const client = (0, client_1.createConnectClient)({
79
+ kind,
80
+ apiAddr,
81
+ credentials: credentials !== null && credentials !== void 0 ? credentials : grpc.credentials.createInsecure()
82
+ });
83
+ return {
84
+ create: (request) => new Promise((resolve, reject) => {
85
+ if (request.extended) {
86
+ request.extended = pb_util_1.struct.encode(request.extended);
87
+ }
88
+ client.create(request, meta, (err, response) => {
89
+ if (err) {
90
+ return reject(fire(err, apiAddr));
91
+ }
92
+ if (response.extended) {
93
+ response.extended = pb_util_1.struct.decode(response.extended);
94
+ }
95
+ resolve(response);
96
+ });
97
+ }),
98
+ update: (request) => new Promise((resolve, reject) => {
99
+ if (request.extended) {
100
+ request.extended = pb_util_1.struct.encode(request.extended);
101
+ }
102
+ client.update(request, meta, (err, response) => {
103
+ if (err) {
104
+ return reject(fire(err, apiAddr));
105
+ }
106
+ if (response.extended) {
107
+ response.extended = pb_util_1.struct.decode(response.extended);
108
+ }
109
+ resolve(response);
110
+ });
111
+ }),
112
+ get: (ref) => new Promise((resolve, reject) => {
113
+ client.get({ ref }, meta, (err, response) => {
114
+ if (err) {
115
+ return reject(fire(err, apiAddr));
116
+ }
117
+ if (response.extended) {
118
+ response.extended = pb_util_1.struct.decode(response.extended);
119
+ }
120
+ resolve(response);
121
+ });
122
+ }),
123
+ list: (request) => new Promise((resolve, reject) => {
124
+ client.list(request, meta, (err, response) => {
125
+ var _a;
126
+ if (err) {
127
+ return reject(fire(err, apiAddr));
128
+ }
129
+ response.items.forEach((item) => {
130
+ if (item.extended) {
131
+ item.extended = pb_util_1.struct.decode(item.extended);
132
+ }
133
+ });
134
+ resolve({
135
+ items: (_a = response === null || response === void 0 ? void 0 : response.items) !== null && _a !== void 0 ? _a : [],
136
+ nextPageToken: response.nextPageToken
137
+ });
138
+ });
139
+ }),
140
+ findBy: (request) => new Promise((resolve, reject) => {
141
+ client.findBy(request, meta, (err, response) => {
142
+ if (err) {
143
+ return reject(fire(err, apiAddr));
144
+ }
145
+ response.items.forEach((item) => {
146
+ if (item.extended) {
147
+ item.extended = pb_util_1.struct.decode(item.extended);
148
+ }
149
+ });
150
+ resolve(response);
151
+ });
152
+ }),
153
+ del: (ref) => new Promise((resolve, reject) => {
154
+ client.delete({ ref }, meta, (err) => err ? reject(fire(err, apiAddr)) : resolve());
155
+ })
156
+ };
157
+ }
158
+ exports.serviceAPI = serviceAPI;
@@ -0,0 +1,2 @@
1
+ export * from "./client";
2
+ export * from "./types";
@@ -0,0 +1,36 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster
20
+ *
21
+ * This file is part of Routr.
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./client"), exports);
36
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,51 @@
1
+ import * as grpc from "@grpc/grpc-js";
2
+ import { JsonObject } from "pb-util/build";
3
+ import { AccessControlList, Agent, Credentials, Domain, INumber, Kind, Peer, Trunk } from "../types";
4
+ export interface DataAPIOptions {
5
+ apiAddr: string;
6
+ credentials?: grpc.ChannelCredentials;
7
+ metadata?: grpc.Metadata;
8
+ }
9
+ export interface ServiceAPIOptions {
10
+ apiAddr: string;
11
+ kind: Kind;
12
+ credentials?: grpc.ChannelCredentials;
13
+ metadata?: grpc.Metadata;
14
+ }
15
+ export interface FindByRequest {
16
+ fieldName: string;
17
+ fieldValue: string | boolean | number;
18
+ }
19
+ export interface ListRequest {
20
+ pageSize: number;
21
+ pageToken: string;
22
+ }
23
+ export interface ListResponse<R> {
24
+ items: R[];
25
+ nextPageToken: string;
26
+ }
27
+ export interface FindByResponse<R> {
28
+ items: R[];
29
+ }
30
+ export type APIClient = {
31
+ agents: ServiceAPI<Agent>;
32
+ domains: ServiceAPI<Domain>;
33
+ trunks: ServiceAPI<Trunk>;
34
+ credentials: ServiceAPI<Credentials>;
35
+ acl: ServiceAPI<AccessControlList>;
36
+ peers: ServiceAPI<Peer>;
37
+ numbers: ServiceAPI<INumber>;
38
+ };
39
+ export type ServiceAPI<R extends {
40
+ extended?: JsonObject;
41
+ }> = {
42
+ create: (request: unknown) => Promise<R>;
43
+ update: (request: unknown) => Promise<R>;
44
+ get: (ref: string) => Promise<R>;
45
+ del: (ref: string) => Promise<void>;
46
+ list: (request: {
47
+ pageSize: number;
48
+ pageToken: string;
49
+ }) => Promise<ListResponse<R>>;
50
+ findBy: (request: FindByRequest) => Promise<FindByResponse<R>>;
51
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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;
@@ -0,0 +1,8 @@
1
+ import * as grpc from "@grpc/grpc-js";
2
+ import { Kind, KindWithoutUnknown } from "./types";
3
+ export declare function createConnectClient(options: {
4
+ kind: Kind;
5
+ credentials: grpc.ChannelCredentials;
6
+ apiAddr: string;
7
+ }): any;
8
+ export declare function createConnectService(kind: KindWithoutUnknown): any;
@@ -0,0 +1,94 @@
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.createConnectService = exports.createConnectClient = void 0;
27
+ /*
28
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
+ * http://github.com/fonoster/routr
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
+ /* eslint-disable require-jsdoc */
46
+ const grpc = __importStar(require("@grpc/grpc-js"));
47
+ const protoLoader = require("@grpc/proto-loader");
48
+ const helper_1 = require("../helper");
49
+ const types_1 = require("./types");
50
+ const protoOptions = {
51
+ keepCase: false,
52
+ longs: String,
53
+ enums: String,
54
+ defaults: true,
55
+ oneofs: true
56
+ };
57
+ function getProtoPath(kind) {
58
+ switch (kind) {
59
+ case types_1.Kind.ACL:
60
+ return __dirname + "/protos/acl.proto";
61
+ case types_1.Kind.CREDENTIALS:
62
+ return __dirname + "/protos/credentials.proto";
63
+ default:
64
+ return __dirname + `/protos/${kind}s.proto`;
65
+ }
66
+ }
67
+ function createConnectClient(options) {
68
+ const def = protoLoader.loadSync(getProtoPath(options.kind), protoOptions);
69
+ const descriptor = grpc.loadPackageDefinition(def);
70
+ const base = descriptor.fonoster.routr.connect;
71
+ switch (options.kind) {
72
+ case types_1.Kind.ACL:
73
+ return new base.acl.v2beta1.ACLService(options.apiAddr, options.credentials);
74
+ case types_1.Kind.CREDENTIALS:
75
+ return new base.credentials.v2beta1.CredentialsService(options.apiAddr, options.credentials);
76
+ default:
77
+ return new base[options.kind + "s"].v2beta1[(0, helper_1.toPascaleCase)(options.kind) + "s"](options.apiAddr, options.credentials);
78
+ }
79
+ }
80
+ exports.createConnectClient = createConnectClient;
81
+ function createConnectService(kind) {
82
+ const def = protoLoader.loadSync(getProtoPath(kind), protoOptions);
83
+ const descriptor = grpc.loadPackageDefinition(def);
84
+ const base = descriptor.fonoster.routr.connect;
85
+ switch (kind) {
86
+ case types_1.Kind.ACL:
87
+ return base.acl.v2beta1.ACLService.service;
88
+ case types_1.Kind.CREDENTIALS:
89
+ return base.credentials.v2beta1.CredentialsService.service;
90
+ default:
91
+ return base[kind + "s"].v2beta1[(0, helper_1.toPascaleCase)(kind) + "s"].service;
92
+ }
93
+ }
94
+ exports.createConnectService = createConnectService;