@routr/ctl 2.0.8-alpha.21
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/LICENSE +21 -0
- package/README.md +973 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +25 -0
- package/bin/run.cmd +3 -0
- package/dist/base.d.ts +8 -0
- package/dist/base.js +42 -0
- package/dist/commands/acl/create.d.ts +6 -0
- package/dist/commands/acl/create.js +122 -0
- package/dist/commands/acl/delete.d.ts +6 -0
- package/dist/commands/acl/delete.js +40 -0
- package/dist/commands/acl/get.d.ts +19 -0
- package/dist/commands/acl/get.js +135 -0
- package/dist/commands/acl/update.d.ts +11 -0
- package/dist/commands/acl/update.js +100 -0
- package/dist/commands/agents/create.d.ts +6 -0
- package/dist/commands/agents/create.js +179 -0
- package/dist/commands/agents/delete.d.ts +6 -0
- package/dist/commands/agents/delete.js +40 -0
- package/dist/commands/agents/get.d.ts +19 -0
- package/dist/commands/agents/get.js +149 -0
- package/dist/commands/agents/update.d.ts +11 -0
- package/dist/commands/agents/update.js +150 -0
- package/dist/commands/credentials/create.d.ts +6 -0
- package/dist/commands/credentials/create.js +122 -0
- package/dist/commands/credentials/delete.d.ts +6 -0
- package/dist/commands/credentials/delete.js +40 -0
- package/dist/commands/credentials/get.d.ts +19 -0
- package/dist/commands/credentials/get.js +130 -0
- package/dist/commands/credentials/update.d.ts +11 -0
- package/dist/commands/credentials/update.js +98 -0
- package/dist/commands/domains/create.d.ts +6 -0
- package/dist/commands/domains/create.js +187 -0
- package/dist/commands/domains/delete.d.ts +6 -0
- package/dist/commands/domains/delete.js +40 -0
- package/dist/commands/domains/get.d.ts +19 -0
- package/dist/commands/domains/get.js +142 -0
- package/dist/commands/domains/update.d.ts +11 -0
- package/dist/commands/domains/update.js +163 -0
- package/dist/commands/numbers/create.d.ts +6 -0
- package/dist/commands/numbers/create.js +171 -0
- package/dist/commands/numbers/delete.d.ts +6 -0
- package/dist/commands/numbers/delete.js +40 -0
- package/dist/commands/numbers/get.d.ts +19 -0
- package/dist/commands/numbers/get.js +147 -0
- package/dist/commands/numbers/update.d.ts +11 -0
- package/dist/commands/numbers/update.js +130 -0
- package/dist/commands/peers/create.d.ts +6 -0
- package/dist/commands/peers/create.js +177 -0
- package/dist/commands/peers/delete.d.ts +6 -0
- package/dist/commands/peers/delete.js +40 -0
- package/dist/commands/peers/get.d.ts +19 -0
- package/dist/commands/peers/get.js +159 -0
- package/dist/commands/peers/update.d.ts +11 -0
- package/dist/commands/peers/update.js +156 -0
- package/dist/commands/trunks/create.d.ts +6 -0
- package/dist/commands/trunks/create.js +231 -0
- package/dist/commands/trunks/delete.d.ts +6 -0
- package/dist/commands/trunks/delete.js +40 -0
- package/dist/commands/trunks/get.d.ts +19 -0
- package/dist/commands/trunks/get.js +145 -0
- package/dist/commands/trunks/update.d.ts +11 -0
- package/dist/commands/trunks/update.js +217 -0
- package/dist/countries.d.ts +4 -0
- package/dist/countries.js +270 -0
- package/dist/delete.d.ts +9 -0
- package/dist/delete.js +46 -0
- package/dist/help.d.ts +6 -0
- package/dist/help.js +84 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +97 -0
- package/dist/validators.d.ts +16 -0
- package/dist/validators.js +180 -0
- package/oclif.manifest.json +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
/*
|
|
27
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
28
|
+
* http://github.com/fonoster
|
|
29
|
+
*
|
|
30
|
+
* This file is part of Routr.
|
|
31
|
+
*
|
|
32
|
+
* Licensed under the MIT License (the "License");
|
|
33
|
+
* you may not use this file except in compliance with
|
|
34
|
+
* the License. You may obtain a copy of the License at
|
|
35
|
+
*
|
|
36
|
+
* https://opensource.org/licenses/MIT
|
|
37
|
+
*
|
|
38
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
39
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
40
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
41
|
+
* See the License for the specific language governing permissions and
|
|
42
|
+
* limitations under the License.
|
|
43
|
+
*/
|
|
44
|
+
/* eslint-disable require-jsdoc */
|
|
45
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
|
+
const core_1 = require("@oclif/core");
|
|
47
|
+
const base_1 = require("../../base");
|
|
48
|
+
const utils_1 = require("../../utils");
|
|
49
|
+
const common_1 = require("@routr/common");
|
|
50
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
51
|
+
class GetDomainsCommand extends base_1.BaseCommand {
|
|
52
|
+
async run() {
|
|
53
|
+
const { args, flags } = await this.parse(GetDomainsCommand);
|
|
54
|
+
const showTable = (request) => {
|
|
55
|
+
const { showHeader, data, self, flags } = request;
|
|
56
|
+
core_1.CliUx.ux.table(data, {
|
|
57
|
+
ref: {
|
|
58
|
+
minWidth: 7,
|
|
59
|
+
extended: true
|
|
60
|
+
},
|
|
61
|
+
name: {
|
|
62
|
+
minWidth: 7
|
|
63
|
+
},
|
|
64
|
+
domainUri: {
|
|
65
|
+
header: "URI"
|
|
66
|
+
},
|
|
67
|
+
accessControlListRef: {
|
|
68
|
+
header: "IP Access Control List",
|
|
69
|
+
get: (row) => { var _a; return ((_a = row.accessControlList) === null || _a === void 0 ? void 0 : _a.name) || "None"; },
|
|
70
|
+
extended: true
|
|
71
|
+
},
|
|
72
|
+
egressPolicies: {
|
|
73
|
+
header: "Egress Policies",
|
|
74
|
+
get: (row) => row.egressPolicies
|
|
75
|
+
.map((p) => `${p.rule}/${p.number.telUrl.split("tel:")[1]}`)
|
|
76
|
+
.join(", "),
|
|
77
|
+
extended: true
|
|
78
|
+
},
|
|
79
|
+
createdAt: {
|
|
80
|
+
header: "Created",
|
|
81
|
+
get: (row) => new Date(row.createdAt * 1000),
|
|
82
|
+
extended: true
|
|
83
|
+
},
|
|
84
|
+
updatedAt: {
|
|
85
|
+
header: "Updated",
|
|
86
|
+
get: (row) => new Date(row.updatedAt * 1000),
|
|
87
|
+
extended: true
|
|
88
|
+
},
|
|
89
|
+
extended: {
|
|
90
|
+
header: "Extended",
|
|
91
|
+
get: (row) => row.extended || {},
|
|
92
|
+
extended: true
|
|
93
|
+
},
|
|
94
|
+
apiVersion: {
|
|
95
|
+
header: "API",
|
|
96
|
+
extended: true
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
"no-header": !showHeader,
|
|
100
|
+
printLine: self.log.bind(self),
|
|
101
|
+
...flags // parsed flags
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
await (0, utils_1.showPaginatedList)({
|
|
105
|
+
showTable,
|
|
106
|
+
args,
|
|
107
|
+
flags,
|
|
108
|
+
kind: common_1.CommonConnect.Kind.DOMAIN,
|
|
109
|
+
self: this
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async catch(error) {
|
|
113
|
+
// To be handled globally
|
|
114
|
+
if ("code" in error && error.code === grpc.status.NOT_FOUND) {
|
|
115
|
+
const { args } = await this.parse(GetDomainsCommand);
|
|
116
|
+
throw new errors_1.CLIError("the Domain you are looking for does not exist: " + args.ref);
|
|
117
|
+
}
|
|
118
|
+
throw new errors_1.CLIError(error.message);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.default = GetDomainsCommand;
|
|
122
|
+
GetDomainsCommand.description = "Shows a list of paginated Domains or a single Domain if ref is provided";
|
|
123
|
+
GetDomainsCommand.examples = [
|
|
124
|
+
`<%= config.bin %> <%= command.id %>
|
|
125
|
+
Ref Name URI
|
|
126
|
+
ab2b6959-f497-4b14-903b-85a7c464b564 Local Domain sip.local
|
|
127
|
+
`
|
|
128
|
+
];
|
|
129
|
+
GetDomainsCommand.flags = {
|
|
130
|
+
size: core_1.Flags.integer({
|
|
131
|
+
char: "s",
|
|
132
|
+
description: "the number of items to return",
|
|
133
|
+
default: 50
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
GetDomainsCommand.args = [
|
|
137
|
+
{
|
|
138
|
+
name: "ref",
|
|
139
|
+
required: false,
|
|
140
|
+
description: "optional reference to a Domain"
|
|
141
|
+
}
|
|
142
|
+
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base";
|
|
2
|
+
export default class UpdateCommand extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
name: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
description: string;
|
|
9
|
+
}[];
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Routr.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
/* eslint-disable require-jsdoc */
|
|
25
|
+
const core_1 = require("@oclif/core");
|
|
26
|
+
const base_1 = require("../../base");
|
|
27
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
28
|
+
const validators_1 = require("../../validators");
|
|
29
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
30
|
+
// NOTE: Newer versions of inquirer have a bug that causes the following error:
|
|
31
|
+
// (node:75345) [ERR_REQUIRE_ESM] Error Plugin: @routr/ctl [ERR_REQUIRE_ESM]: require() of ES Module
|
|
32
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
33
|
+
class UpdateCommand extends base_1.BaseCommand {
|
|
34
|
+
async run() {
|
|
35
|
+
const { args, flags } = await this.parse(UpdateCommand);
|
|
36
|
+
const { endpoint, insecure } = flags;
|
|
37
|
+
const api = new sdk_1.default.Domains({ endpoint, insecure });
|
|
38
|
+
this.log("This utility will help you update an existing Domain.");
|
|
39
|
+
this.log("Press ^C at any time to quit.");
|
|
40
|
+
this.warn("Adding Egress Policies will delete existing ones.");
|
|
41
|
+
const domainFromDB = await api.getDomain(args.ref);
|
|
42
|
+
// TODO: Fix hardcoded pageSize
|
|
43
|
+
const acls = await new sdk_1.default.ACL({ endpoint, insecure }).listACLs({
|
|
44
|
+
pageSize: 25,
|
|
45
|
+
pageToken: ""
|
|
46
|
+
});
|
|
47
|
+
const aclChoices = acls.items.map((acl) => {
|
|
48
|
+
return {
|
|
49
|
+
name: acl.name,
|
|
50
|
+
value: acl.ref
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
// TODO: Fix hardcoded pageSize
|
|
54
|
+
const numbers = await new sdk_1.default.Numbers({ endpoint, insecure }).listNumbers({
|
|
55
|
+
pageSize: 25,
|
|
56
|
+
pageToken: ""
|
|
57
|
+
});
|
|
58
|
+
const numberChoices = numbers.items.map((number) => {
|
|
59
|
+
return {
|
|
60
|
+
name: number.name,
|
|
61
|
+
value: number.ref
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
const group1 = await inquirer_1.default.prompt([
|
|
65
|
+
{
|
|
66
|
+
name: "name",
|
|
67
|
+
message: "Friendly Name",
|
|
68
|
+
type: "input",
|
|
69
|
+
default: domainFromDB.name,
|
|
70
|
+
validate: validators_1.nameValidator
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "accessControlListRef",
|
|
74
|
+
message: "IP Access Control List",
|
|
75
|
+
type: "list",
|
|
76
|
+
choices: [{ name: "None", value: undefined }, ...aclChoices],
|
|
77
|
+
default: domainFromDB.accessControlListRef
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "addEgressRule",
|
|
81
|
+
message: "Add an Egress Rule?",
|
|
82
|
+
type: "confirm",
|
|
83
|
+
default: false,
|
|
84
|
+
when: aclChoices.length > 0
|
|
85
|
+
}
|
|
86
|
+
]);
|
|
87
|
+
const group2Questions = [
|
|
88
|
+
{
|
|
89
|
+
name: "numberRef",
|
|
90
|
+
message: "Number",
|
|
91
|
+
type: "list",
|
|
92
|
+
choices: [{ name: "None", value: undefined }, ...numberChoices]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "rule",
|
|
96
|
+
message: "Rule",
|
|
97
|
+
type: "input",
|
|
98
|
+
default: ".*",
|
|
99
|
+
when: (answers) => answers.numberRef
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "addEgressRule",
|
|
103
|
+
message: "Add another Egress Rule?",
|
|
104
|
+
type: "confirm",
|
|
105
|
+
default: false,
|
|
106
|
+
when: (answers) => answers.numberRef
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
let addEgressRule = group1.addEgressRule;
|
|
110
|
+
const egressPolicies = [];
|
|
111
|
+
// eslint-disable-next-line no-loops/no-loops
|
|
112
|
+
while (addEgressRule) {
|
|
113
|
+
const group2 = await inquirer_1.default.prompt(group2Questions);
|
|
114
|
+
if (group2.numberRef) {
|
|
115
|
+
egressPolicies.push({
|
|
116
|
+
numberRef: group2.numberRef,
|
|
117
|
+
rule: group2.rule
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
addEgressRule = group2.addEgressRule;
|
|
121
|
+
}
|
|
122
|
+
const group3 = await inquirer_1.default.prompt([
|
|
123
|
+
{
|
|
124
|
+
name: "confirm",
|
|
125
|
+
message: "Ready?",
|
|
126
|
+
type: "confirm"
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
if (!group3.confirm) {
|
|
130
|
+
this.warn("Aborted");
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
try {
|
|
134
|
+
core_1.CliUx.ux.action.start(`Updating Domain ${group1.name}`);
|
|
135
|
+
const domain = await api.updateDomain({
|
|
136
|
+
ref: domainFromDB.ref,
|
|
137
|
+
...group1,
|
|
138
|
+
egressPolicies
|
|
139
|
+
});
|
|
140
|
+
await core_1.CliUx.ux.wait(1000);
|
|
141
|
+
core_1.CliUx.ux.action.stop(domain.ref);
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
core_1.CliUx.ux.action.stop();
|
|
145
|
+
throw new errors_1.CLIError(e.message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.default = UpdateCommand;
|
|
151
|
+
UpdateCommand.description = "Updates an existing Domain";
|
|
152
|
+
UpdateCommand.examples = [
|
|
153
|
+
`<%= config.bin %> <%= command.id %>
|
|
154
|
+
Updating Domain Local... 80181ca6-d4aa-4575-9375-8f72b07d5555
|
|
155
|
+
`
|
|
156
|
+
];
|
|
157
|
+
UpdateCommand.args = [
|
|
158
|
+
{
|
|
159
|
+
name: "ref",
|
|
160
|
+
required: true,
|
|
161
|
+
description: "reference to an existing Domain"
|
|
162
|
+
}
|
|
163
|
+
];
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/*
|
|
30
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
31
|
+
* http://github.com/fonoster
|
|
32
|
+
*
|
|
33
|
+
* This file is part of Routr.
|
|
34
|
+
*
|
|
35
|
+
* Licensed under the MIT License (the "License");
|
|
36
|
+
* you may not use this file except in compliance with
|
|
37
|
+
* the License. You may obtain a copy of the License at
|
|
38
|
+
*
|
|
39
|
+
* https://opensource.org/licenses/MIT
|
|
40
|
+
*
|
|
41
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
42
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
43
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
44
|
+
* See the License for the specific language governing permissions and
|
|
45
|
+
* limitations under the License.
|
|
46
|
+
*/
|
|
47
|
+
/* eslint-disable require-jsdoc */
|
|
48
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
49
|
+
const core_1 = require("@oclif/core");
|
|
50
|
+
const base_1 = require("../../base");
|
|
51
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
52
|
+
const countries_1 = require("../../countries");
|
|
53
|
+
const validators_1 = require("../../validators");
|
|
54
|
+
const utils_1 = require("../../utils");
|
|
55
|
+
const fuzzy_search_1 = __importDefault(require("fuzzy-search"));
|
|
56
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
57
|
+
// NOTE: Newer versions of inquirer have a bug that causes the following error:
|
|
58
|
+
// (node:75345) [ERR_REQUIRE_ESM] Error Plugin: @routr/ctl [ERR_REQUIRE_ESM]: require() of ES Module
|
|
59
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
60
|
+
class CreateNumberCommand extends base_1.BaseCommand {
|
|
61
|
+
async run() {
|
|
62
|
+
const { flags } = await this.parse(CreateNumberCommand);
|
|
63
|
+
const { endpoint, insecure } = flags;
|
|
64
|
+
this.log("This utility will help you create a new Number.");
|
|
65
|
+
this.log("Press ^C at any time to quit.");
|
|
66
|
+
const searcher = new fuzzy_search_1.default(countries_1.countries, ["name"], {
|
|
67
|
+
caseSensitive: false
|
|
68
|
+
});
|
|
69
|
+
const trunks = await new sdk_1.default.Trunks({ endpoint, insecure }).listTrunks({
|
|
70
|
+
pageSize: 25,
|
|
71
|
+
pageToken: ""
|
|
72
|
+
});
|
|
73
|
+
const trunksChoices = trunks.items.map((trunk) => {
|
|
74
|
+
return {
|
|
75
|
+
name: trunk.name,
|
|
76
|
+
value: trunk.ref
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
const answers = await inquirer_1.default.prompt([
|
|
80
|
+
{
|
|
81
|
+
name: "name",
|
|
82
|
+
message: "Friendly Name",
|
|
83
|
+
type: "input",
|
|
84
|
+
validate: validators_1.nameValidator
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "telUrl",
|
|
88
|
+
message: "Telephony URL",
|
|
89
|
+
type: "input",
|
|
90
|
+
validate: validators_1.telUrlValidator
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "aorLink",
|
|
94
|
+
message: "AOR Link",
|
|
95
|
+
type: "input",
|
|
96
|
+
validate: validators_1.aorLinkValidator
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "trunkRef",
|
|
100
|
+
message: "Trunk",
|
|
101
|
+
type: "list",
|
|
102
|
+
choices: [{ name: "None", value: undefined }, ...trunksChoices]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "city",
|
|
106
|
+
message: "City",
|
|
107
|
+
type: "input",
|
|
108
|
+
validate: (input) => {
|
|
109
|
+
if (input.length === 0) {
|
|
110
|
+
return "the city is required";
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: "autocomplete",
|
|
117
|
+
name: "countryISOCode",
|
|
118
|
+
message: "Select a Country",
|
|
119
|
+
source: (_, input) => searcher.search(input)
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "sessionAffinityHeader",
|
|
123
|
+
message: "Session Affinity Header",
|
|
124
|
+
type: "input",
|
|
125
|
+
validate: validators_1.sessionAffinityHeaderValidator
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "extraHeaders",
|
|
129
|
+
message: "Extra Headers",
|
|
130
|
+
type: "input",
|
|
131
|
+
validate: validators_1.headersValidator
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "confirm",
|
|
135
|
+
message: "Ready?",
|
|
136
|
+
type: "confirm"
|
|
137
|
+
}
|
|
138
|
+
]);
|
|
139
|
+
// Re-write extraHeaders
|
|
140
|
+
answers.extraHeaders = (0, utils_1.stringToHeaders)(answers.extraHeaders);
|
|
141
|
+
answers.country = countries_1.countries.find((country) => country.value === answers.countryISOCode).name;
|
|
142
|
+
if (!answers.confirm) {
|
|
143
|
+
this.warn("Aborted");
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
try {
|
|
147
|
+
core_1.CliUx.ux.action.start(`Creating Number ${answers.name}`);
|
|
148
|
+
const api = new sdk_1.default.Numbers({ endpoint, insecure });
|
|
149
|
+
const number = await api.createNumber(answers);
|
|
150
|
+
await core_1.CliUx.ux.wait(1000);
|
|
151
|
+
core_1.CliUx.ux.action.stop(number.ref);
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
core_1.CliUx.ux.action.stop();
|
|
155
|
+
if (e.code === grpc.status.ALREADY_EXISTS) {
|
|
156
|
+
throw new errors_1.CLIError("This Number already exist");
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
throw new errors_1.CLIError(e.message);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.default = CreateNumberCommand;
|
|
166
|
+
CreateNumberCommand.description = "Creates a new Number";
|
|
167
|
+
CreateNumberCommand.examples = [
|
|
168
|
+
`<%= config.bin %> <%= command.id %>
|
|
169
|
+
Creating Number (784) 317-8170... a134487f-a668-4509-9ddd-dcbc98175468
|
|
170
|
+
`
|
|
171
|
+
];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Routr.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
/* eslint-disable require-jsdoc */
|
|
25
|
+
const delete_1 = __importDefault(require("../../delete"));
|
|
26
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
27
|
+
class DeleteNumberCommand extends delete_1.default {
|
|
28
|
+
async run() {
|
|
29
|
+
const { flags } = await this.parse(DeleteNumberCommand);
|
|
30
|
+
const { endpoint, insecure } = flags;
|
|
31
|
+
await super.deleteResource(new sdk_1.default.Numbers({ endpoint, insecure }), "deleteNumber");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = DeleteNumberCommand;
|
|
35
|
+
DeleteNumberCommand.description = "Deletes a Number";
|
|
36
|
+
DeleteNumberCommand.examples = [
|
|
37
|
+
`<%= config.bin %> <%= command.id %>
|
|
38
|
+
Deleting item 80181ca6-d4aa-4575-9375-8f72b071111... Done
|
|
39
|
+
`
|
|
40
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base";
|
|
2
|
+
import { CommandError } from "@oclif/core/lib/interfaces";
|
|
3
|
+
export default class GetNumbersCommand extends BaseCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
size: import("@oclif/core/lib/interfaces").OptionFlag<number>;
|
|
8
|
+
};
|
|
9
|
+
static args: {
|
|
10
|
+
name: string;
|
|
11
|
+
required: boolean;
|
|
12
|
+
description: string;
|
|
13
|
+
}[];
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
catch(error: {
|
|
16
|
+
code: number;
|
|
17
|
+
message: string;
|
|
18
|
+
} | CommandError): Promise<void>;
|
|
19
|
+
}
|