@fonoster/ctl 0.7.40 → 0.7.42
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/commands/applications/create.d.ts +6 -0
- package/dist/commands/applications/create.js +164 -0
- package/dist/commands/applications/delete.d.ts +9 -0
- package/dist/commands/applications/delete.js +99 -0
- package/dist/commands/applications/get.d.ts +9 -0
- package/dist/commands/applications/get.js +120 -0
- package/dist/commands/applications/list.d.ts +5 -2
- package/dist/commands/applications/list.js +18 -7
- package/dist/commands/applications/update.d.ts +9 -0
- package/dist/commands/applications/update.js +187 -0
- package/dist/commands/bug.js +1 -1
- package/dist/commands/feedback.js +1 -1
- package/dist/commands/numbers/get.d.ts +9 -0
- package/dist/commands/numbers/get.js +125 -0
- package/dist/commands/numbers/linkTwilioNumber.d.ts +10 -0
- package/dist/commands/numbers/linkTwilioNumber.js +155 -0
- package/dist/commands/numbers/list.d.ts +9 -0
- package/dist/commands/numbers/list.js +116 -0
- package/dist/commands/workspaces/login.js +1 -2
- package/dist/commands/workspaces/logout.js +1 -2
- package/dist/commands/workspaces/{set.d.ts → use.d.ts} +1 -1
- package/dist/commands/workspaces/{set.js → use.js} +6 -6
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/utils/assignTwilioNumberToTrunk.d.ts +3 -0
- package/dist/utils/assignTwilioNumberToTrunk.js +33 -0
- package/dist/utils/createTwilioTrunk.d.ts +4 -0
- package/dist/utils/createTwilioTrunk.js +54 -0
- package/dist/utils/getFonosterNumberByTelUrl.d.ts +4 -0
- package/dist/utils/getFonosterNumberByTelUrl.js +76 -0
- package/dist/utils/getFonosterTrunkByInboundUri.d.ts +4 -0
- package/dist/utils/getFonosterTrunkByInboundUri.js +76 -0
- package/dist/utils/getTwilioNumber.d.ts +4 -0
- package/dist/utils/getTwilioNumber.js +23 -0
- package/dist/utils/getTwilioTrunk.d.ts +4 -0
- package/dist/utils/getTwilioTrunk.js +23 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +42 -0
- package/dist/utils/linkTwilioNumberToApplication.d.ts +5 -0
- package/dist/utils/linkTwilioNumberToApplication.js +128 -0
- package/dist/utils/types.d.ts +14 -0
- package/dist/utils/types.js +2 -0
- package/package.json +7 -3
|
@@ -32,10 +32,10 @@ const core_1 = require("@oclif/core");
|
|
|
32
32
|
const config_1 = require("../../config");
|
|
33
33
|
const saveConfig_1 = require("../../config/saveConfig");
|
|
34
34
|
const constants_1 = require("../../constants");
|
|
35
|
-
class
|
|
35
|
+
class Use extends core_1.Command {
|
|
36
36
|
run() {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const { args } = yield this.parse(
|
|
38
|
+
const { args } = yield this.parse(Use);
|
|
39
39
|
if (!args.ref) {
|
|
40
40
|
this.error("Missing Workspace reference");
|
|
41
41
|
return;
|
|
@@ -49,9 +49,9 @@ class Set extends core_1.Command {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
Use.description = "make a Workspace the default";
|
|
53
|
+
Use.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
54
|
+
Use.args = {
|
|
55
55
|
ref: core_1.Args.string({ description: "The Workspace to unlink from" })
|
|
56
56
|
};
|
|
57
|
-
exports.default =
|
|
57
|
+
exports.default = Use;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const BASE_DIR: string;
|
|
2
2
|
export declare const CONFIG_FILE: string;
|
|
3
|
+
export declare const FONOSTER_ACCESS_CONTROL_LIST: string[];
|
|
4
|
+
export declare const FONOSTER_ORIGINATION_URI_BASE = "pstn.fonoster.dev";
|
|
5
|
+
export declare const TWILIO_PSTN_URI_BASE = "pstn.twilio.com";
|
|
3
6
|
export declare const WORKSPACE_ENDPOINT = "api.fonoster.dev";
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WORKSPACE_ENDPOINT = exports.CONFIG_FILE = exports.BASE_DIR = void 0;
|
|
3
|
+
exports.WORKSPACE_ENDPOINT = exports.TWILIO_PSTN_URI_BASE = exports.FONOSTER_ORIGINATION_URI_BASE = exports.FONOSTER_ACCESS_CONTROL_LIST = exports.CONFIG_FILE = exports.BASE_DIR = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
@@ -23,4 +23,7 @@ const os_1 = require("os");
|
|
|
23
23
|
const path_1 = require("path");
|
|
24
24
|
exports.BASE_DIR = (0, path_1.join)((0, os_1.homedir)(), ".fonoster");
|
|
25
25
|
exports.CONFIG_FILE = (0, path_1.join)((0, os_1.homedir)(), ".fonoster", "config.json");
|
|
26
|
+
exports.FONOSTER_ACCESS_CONTROL_LIST = ["165.22.7.155/32"]; // Warning: We will need to allow passing this as a parameter
|
|
27
|
+
exports.FONOSTER_ORIGINATION_URI_BASE = "pstn.fonoster.dev";
|
|
28
|
+
exports.TWILIO_PSTN_URI_BASE = "pstn.twilio.com";
|
|
26
29
|
exports.WORKSPACE_ENDPOINT = "api.fonoster.dev";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.assignTwilioNumberToTrunk = assignTwilioNumberToTrunk;
|
|
13
|
+
function assignTwilioNumberToTrunk(client, phoneNumber, trunkSid) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
const numbers = yield client.incomingPhoneNumbers.list({
|
|
17
|
+
phoneNumber,
|
|
18
|
+
limit: 1
|
|
19
|
+
});
|
|
20
|
+
if (numbers.length === 0) {
|
|
21
|
+
throw new Error(`Phone number ${phoneNumber} not found in your Twilio account.`);
|
|
22
|
+
}
|
|
23
|
+
const numberSid = numbers[0].sid;
|
|
24
|
+
// Step 2: Update the Voice URL of the number to point to the trunk's domain URI
|
|
25
|
+
yield client.incomingPhoneNumbers(numberSid).update({
|
|
26
|
+
trunkSid
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new Error(`Failed to assign phone number to trunk: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createTwilioTrunk = createTwilioTrunk;
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
function createTwilioTrunk(client, params) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const { resourceRef, originationUriBase, aclEntries } = params;
|
|
17
|
+
try {
|
|
18
|
+
const aclName = `ACL-${resourceRef}`;
|
|
19
|
+
const trunkName = `Trunk-${resourceRef}`;
|
|
20
|
+
const domainName = `${resourceRef}.${constants_1.TWILIO_PSTN_URI_BASE}`;
|
|
21
|
+
const originationUri = `sip:${resourceRef}.${originationUriBase}`;
|
|
22
|
+
// Create ACLresource and entries
|
|
23
|
+
const acl = yield client.sip.ipAccessControlLists.create({
|
|
24
|
+
friendlyName: aclName
|
|
25
|
+
});
|
|
26
|
+
for (const ip of aclEntries) {
|
|
27
|
+
yield client.sip.ipAccessControlLists(acl.sid).ipAddresses.create({
|
|
28
|
+
friendlyName: `${resourceRef}-entry-${ip}`,
|
|
29
|
+
ipAddress: ip
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Create the trunk
|
|
33
|
+
const trunk = yield client.trunking.v1.trunks.create({
|
|
34
|
+
friendlyName: trunkName,
|
|
35
|
+
domainName: domainName
|
|
36
|
+
});
|
|
37
|
+
// Add the ACL to the trunk
|
|
38
|
+
yield client.trunking.v1.trunks(trunk.sid).ipAccessControlLists.create({
|
|
39
|
+
ipAccessControlListSid: acl.sid
|
|
40
|
+
});
|
|
41
|
+
// Create origination URL
|
|
42
|
+
yield client.trunking.v1.trunks(trunk.sid).originationUrls.create({
|
|
43
|
+
friendlyName: `Origination-${resourceRef}`,
|
|
44
|
+
sipUrl: originationUri,
|
|
45
|
+
priority: 10,
|
|
46
|
+
weight: 10,
|
|
47
|
+
enabled: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error(`Failed to create resources: ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.getFonosterNumberByTelUrl = getFonosterNumberByTelUrl;
|
|
46
|
+
/*
|
|
47
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
48
|
+
* http://github.com/fonoster/fonoster
|
|
49
|
+
*
|
|
50
|
+
* This file is part of Fonoster
|
|
51
|
+
*
|
|
52
|
+
* Licensed under the MIT License (the "License");
|
|
53
|
+
* you may not use this file except in compliance with
|
|
54
|
+
* the License. You may obtain a copy of the License at
|
|
55
|
+
*
|
|
56
|
+
* https://opensource.org/licenses/MIT
|
|
57
|
+
*
|
|
58
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
59
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
60
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
61
|
+
* See the License for the specific language governing permissions and
|
|
62
|
+
* limitations under the License.
|
|
63
|
+
*/
|
|
64
|
+
const Fonoster = __importStar(require("@fonoster/sdk"));
|
|
65
|
+
function getFonosterNumberByTelUrl(client, telUrl) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const numbers = new Fonoster.Numbers(client);
|
|
69
|
+
const numbersList = yield numbers.listNumbers({ pageSize: 1000 });
|
|
70
|
+
return numbersList.items.filter((number) => number.telUrl === telUrl)[0];
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(`Error checking Fonoster Number existence: ${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.getFonosterTrunkByInboundUri = getFonosterTrunkByInboundUri;
|
|
46
|
+
/*
|
|
47
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
48
|
+
* http://github.com/fonoster/fonoster
|
|
49
|
+
*
|
|
50
|
+
* This file is part of Fonoster
|
|
51
|
+
*
|
|
52
|
+
* Licensed under the MIT License (the "License");
|
|
53
|
+
* you may not use this file except in compliance with
|
|
54
|
+
* the License. You may obtain a copy of the License at
|
|
55
|
+
*
|
|
56
|
+
* https://opensource.org/licenses/MIT
|
|
57
|
+
*
|
|
58
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
59
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
60
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
61
|
+
* See the License for the specific language governing permissions and
|
|
62
|
+
* limitations under the License.
|
|
63
|
+
*/
|
|
64
|
+
const Fonoster = __importStar(require("@fonoster/sdk"));
|
|
65
|
+
function getFonosterTrunkByInboundUri(client, inboundUri) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const trunks = new Fonoster.Trunks(client);
|
|
69
|
+
const trunksList = yield trunks.listTrunks({ pageSize: 1000 });
|
|
70
|
+
return trunksList.items.filter((trunk) => trunk.inboundUri === inboundUri)[0];
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(`Error checking SIP trunk existence: ${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Twilio } from "twilio";
|
|
2
|
+
import { IncomingPhoneNumberInstance } from "twilio/lib/rest/api/v2010/account/incomingPhoneNumber";
|
|
3
|
+
declare function getTwilioNumber(client: Twilio, phoneNumber: string): Promise<IncomingPhoneNumberInstance>;
|
|
4
|
+
export { getTwilioNumber };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTwilioNumber = getTwilioNumber;
|
|
13
|
+
function getTwilioNumber(client, phoneNumber) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
const numbers = yield client.incomingPhoneNumbers.list();
|
|
17
|
+
return numbers.filter((number) => number.phoneNumber === phoneNumber)[0];
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error(`Error checking ownership of phone number: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTwilioTrunk = getTwilioTrunk;
|
|
13
|
+
function getTwilioTrunk(client, terminationSipUri) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
const trunks = yield client.trunking.v1.trunks.list();
|
|
17
|
+
return trunks.filter((trunk) => trunk.domainName === terminationSipUri)[0];
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error(`Error checking SIP trunk existence: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./assignTwilioNumberToTrunk";
|
|
2
|
+
export * from "./createTwilioTrunk";
|
|
3
|
+
export * from "./getFonosterNumberByTelUrl";
|
|
4
|
+
export * from "./getFonosterTrunkByInboundUri";
|
|
5
|
+
export * from "./getTwilioNumber";
|
|
6
|
+
export * from "./getTwilioTrunk";
|
|
7
|
+
export * from "./linkTwilioNumberToApplication";
|
|
8
|
+
export * from "./types";
|
|
@@ -0,0 +1,42 @@
|
|
|
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) 2024 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Fonoster
|
|
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("./assignTwilioNumberToTrunk"), exports);
|
|
36
|
+
__exportStar(require("./createTwilioTrunk"), exports);
|
|
37
|
+
__exportStar(require("./getFonosterNumberByTelUrl"), exports);
|
|
38
|
+
__exportStar(require("./getFonosterTrunkByInboundUri"), exports);
|
|
39
|
+
__exportStar(require("./getTwilioNumber"), exports);
|
|
40
|
+
__exportStar(require("./getTwilioTrunk"), exports);
|
|
41
|
+
__exportStar(require("./linkTwilioNumberToApplication"), exports);
|
|
42
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as Fonoster from "@fonoster/sdk";
|
|
2
|
+
import { Twilio } from "twilio";
|
|
3
|
+
import { LinkTwilioNumberToApplicationParams } from ".";
|
|
4
|
+
declare function linkTwilioNumberToApplication(twilioClient: Twilio, fonosterClient: Fonoster.Client, params: LinkTwilioNumberToApplicationParams): Promise<void>;
|
|
5
|
+
export { linkTwilioNumberToApplication };
|
|
@@ -0,0 +1,128 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.linkTwilioNumberToApplication = linkTwilioNumberToApplication;
|
|
49
|
+
/*
|
|
50
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
51
|
+
* http://github.com/fonoster/fonoster
|
|
52
|
+
*
|
|
53
|
+
* This file is part of Fonoster
|
|
54
|
+
*
|
|
55
|
+
* Licensed under the MIT License (the "License");
|
|
56
|
+
* you may not use this file except in compliance with
|
|
57
|
+
* the License. You may obtain a copy of the License at
|
|
58
|
+
*
|
|
59
|
+
* https://opensource.org/licenses/MIT
|
|
60
|
+
*
|
|
61
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
62
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
63
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
64
|
+
* See the License for the specific language governing permissions and
|
|
65
|
+
* limitations under the License.
|
|
66
|
+
*/
|
|
67
|
+
const Fonoster = __importStar(require("@fonoster/sdk"));
|
|
68
|
+
const phone_1 = __importDefault(require("phone"));
|
|
69
|
+
const constants_1 = require("../constants");
|
|
70
|
+
const _1 = require(".");
|
|
71
|
+
function linkTwilioNumberToApplication(twilioClient, fonosterClient, params) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const { applicationRef, accessKeyId, aclEntries, originationUriBase, phoneNumber, friendlyName } = params;
|
|
74
|
+
const resourceRef = accessKeyId.toLowerCase();
|
|
75
|
+
const twilioNumber = yield (0, _1.getTwilioNumber)(twilioClient, phoneNumber);
|
|
76
|
+
let twilioTrunk = yield (0, _1.getTwilioTrunk)(twilioClient, `${resourceRef}.${constants_1.TWILIO_PSTN_URI_BASE}`);
|
|
77
|
+
const fonosterTrunk = yield (0, _1.getFonosterTrunkByInboundUri)(fonosterClient, `${resourceRef}.${originationUriBase}`);
|
|
78
|
+
const fonosterNumber = yield (0, _1.getFonosterNumberByTelUrl)(fonosterClient, `tel:${phoneNumber}`);
|
|
79
|
+
if (!twilioNumber) {
|
|
80
|
+
throw Error(`The number ${phoneNumber} was not found in your account.`);
|
|
81
|
+
}
|
|
82
|
+
if (!twilioTrunk) {
|
|
83
|
+
yield (0, _1.createTwilioTrunk)(twilioClient, {
|
|
84
|
+
resourceRef,
|
|
85
|
+
aclEntries,
|
|
86
|
+
originationUriBase
|
|
87
|
+
});
|
|
88
|
+
twilioTrunk = yield (0, _1.getTwilioTrunk)(twilioClient, `${resourceRef}.${constants_1.TWILIO_PSTN_URI_BASE}`);
|
|
89
|
+
}
|
|
90
|
+
yield (0, _1.assignTwilioNumberToTrunk)(twilioClient, phoneNumber, twilioTrunk.sid);
|
|
91
|
+
let trunkRef = fonosterTrunk === null || fonosterTrunk === void 0 ? void 0 : fonosterTrunk.ref;
|
|
92
|
+
if (!fonosterTrunk) {
|
|
93
|
+
const trunks = new Fonoster.Trunks(fonosterClient);
|
|
94
|
+
const response = yield trunks.createTrunk({
|
|
95
|
+
name: "Twilio Trunk",
|
|
96
|
+
inboundUri: `${resourceRef}.${originationUriBase}`,
|
|
97
|
+
sendRegister: true,
|
|
98
|
+
uris: [
|
|
99
|
+
{
|
|
100
|
+
host: `${resourceRef}.${constants_1.TWILIO_PSTN_URI_BASE}`,
|
|
101
|
+
port: 5060,
|
|
102
|
+
transport: "TCP",
|
|
103
|
+
enabled: true,
|
|
104
|
+
weight: 10,
|
|
105
|
+
priority: 10,
|
|
106
|
+
user: ""
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
trunkRef = response.ref;
|
|
111
|
+
}
|
|
112
|
+
if (fonosterNumber) {
|
|
113
|
+
const numbers = new Fonoster.Numbers(fonosterClient);
|
|
114
|
+
yield numbers.deleteNumber(fonosterNumber.ref);
|
|
115
|
+
}
|
|
116
|
+
const numbers = new Fonoster.Numbers(fonosterClient);
|
|
117
|
+
const phoneInfo = (0, phone_1.default)(phoneNumber);
|
|
118
|
+
yield numbers.createNumber({
|
|
119
|
+
name: friendlyName !== null && friendlyName !== void 0 ? friendlyName : phoneNumber,
|
|
120
|
+
telUrl: `tel:${phoneNumber}`,
|
|
121
|
+
appRef: applicationRef,
|
|
122
|
+
trunkRef,
|
|
123
|
+
city: "unknown",
|
|
124
|
+
country: phoneInfo.countryIso3,
|
|
125
|
+
countryIsoCode: phoneInfo.countryIso2
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type LinkTwilioNumberToApplicationParams = {
|
|
2
|
+
phoneNumber: string;
|
|
3
|
+
accessKeyId: string;
|
|
4
|
+
aclEntries: string[];
|
|
5
|
+
originationUriBase: string;
|
|
6
|
+
applicationRef: string;
|
|
7
|
+
friendlyName?: string;
|
|
8
|
+
};
|
|
9
|
+
type TwilioTrunkParams = {
|
|
10
|
+
resourceRef: string;
|
|
11
|
+
originationUriBase: string;
|
|
12
|
+
aclEntries: string[];
|
|
13
|
+
};
|
|
14
|
+
export { LinkTwilioNumberToApplicationParams, TwilioTrunkParams };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/ctl",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.42",
|
|
4
4
|
"description": "Fonoster Control Tool",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"bugs": {
|
|
31
31
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "50867fa36ff09aedbbf44529d50c73c967defc78",
|
|
34
34
|
"bin": {
|
|
35
35
|
"fonoster": "./bin/run.js"
|
|
36
36
|
},
|
|
@@ -42,15 +42,19 @@
|
|
|
42
42
|
"helpClass": "./dist/help"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@fonoster/sdk": "^0.7.
|
|
45
|
+
"@fonoster/sdk": "^0.7.42",
|
|
46
46
|
"@inquirer/prompts": "^7.1.0",
|
|
47
47
|
"@oclif/core": "^4.0.34",
|
|
48
48
|
"cliui": "^8.0.1",
|
|
49
49
|
"figlet": "^1.8.0",
|
|
50
|
+
"moment": "^2.30.1",
|
|
51
|
+
"phone": "^3.1.55",
|
|
50
52
|
"terminal-link": "^3.0.0",
|
|
53
|
+
"twilio": "^5.3.7",
|
|
51
54
|
"zod": "^3.23.8"
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
57
|
+
"@oclif/test": "^4.1.3",
|
|
54
58
|
"@types/figlet": "^1.7.0",
|
|
55
59
|
"@types/node": "22.10.1",
|
|
56
60
|
"ts-node": "^10.9.2"
|