Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@twilio/flex-plugins-library-utils

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twilio/flex-plugins-library-utils - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

CHANGELOG.md

2

dist/common/BaseClasses/PluginUtils.d.ts
import { Twilio } from 'twilio';
export declare abstract class PluginUtils {
client: Twilio;
protected client: Twilio;
constructor(client: Twilio);
protected isValidMetaData(config: any): boolean;
}

@@ -39,3 +39,3 @@ "use strict";

const retryHandler = (metaData, error, parameters, callback) => __awaiter(void 0, void 0, void 0, function* () {
const { TWILIO_SERVICE_MAX_BACKOFF, TWILIO_SERVICE_MIN_BACKOFF, TWILIO_SERVICE_RETRY_LIMIT } = metaData;
const { maxBackoff, minBackoff, retryLimit } = metaData;
const { attempts } = parameters;

@@ -50,6 +50,6 @@ const { response, message: errorMessage } = error;

(0, lodash_1.isNumber)(attempts) &&
attempts < TWILIO_SERVICE_RETRY_LIMIT) {
attempts < retryLimit) {
console.warn(`retrying ${callback.name}() after ${logWarning}, status code: ${status}`);
if (status === statusCodes_1.HttpErrorCode.TooManyRequests || status === statusCodes_1.HttpErrorCode.ServiceUnavailable)
yield (0, utils_1.snooze)((0, lodash_1.random)(TWILIO_SERVICE_MIN_BACKOFF, TWILIO_SERVICE_MAX_BACKOFF));
yield (0, utils_1.snooze)((0, lodash_1.random)(minBackoff, maxBackoff));
const updatedAttempts = attempts + 1;

@@ -56,0 +56,0 @@ const updatedParameters = Object.assign(Object.assign({}, parameters), { attempts: updatedAttempts });

import { Twilio } from 'twilio';
import { PluginsUtilsMetaData } from '../../types';
import { Parameters, APIReturnType } from '../../types';
import { Parameters, ApiReturnType } from '../../types';
import { IncomingPhoneNumberInstance } from 'twilio/lib/rest/api/v2010/account/incomingPhoneNumber';
import { PluginUtils } from '../../common/BaseClasses/PluginUtils';
export declare class PhoneNumbersUtils extends PluginUtils {
export default class PhoneNumbersUtils extends PluginUtils {
private config;

@@ -11,7 +11,7 @@ /**

* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* */

@@ -25,5 +25,5 @@ constructor(client: Twilio, config: PluginsUtilsMetaData);

*/
listPhoneNumbers(parameters: Parameters): Promise<APIReturnType & {
listPhoneNumbers(parameters: Parameters): Promise<ApiReturnType & {
phoneNumbers?: Array<IncomingPhoneNumberInstance>;
}>;
}

@@ -12,8 +12,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.PhoneNumbersUtils = void 0;
const retryHandler_1 = require("../../common/retryHandler");
const lodash_1 = require("lodash");
const PluginUtils_1 = require("../../common/BaseClasses/PluginUtils");
const statusCodes_1 = require("../../constants/statusCodes");
const moduleErrors_1 = require("../../constants/moduleErrors");
const PluginUtilsErrorManager_1 = require("../../common/PluginUtilsErrorManager");
class PhoneNumbersUtils extends PluginUtils_1.PluginUtils {

@@ -23,7 +22,7 @@ /**

* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* */

@@ -45,10 +44,13 @@ constructor(client, config) {

listPhoneNumbers(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts } = parameters;
const parameterChecks = {
attempts: 'number',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const phoneNumbers = yield this.client.incomingPhoneNumbers.list({
limit: 1000,
limit: parameters.limit || 1000,
});

@@ -58,3 +60,3 @@ return { success: true, phoneNumbers, status: statusCodes_1.HttpErrorCode.OK };

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -71,3 +73,3 @@ success: false,

}
exports.PhoneNumbersUtils = PhoneNumbersUtils;
exports.default = PhoneNumbersUtils;
//# sourceMappingURL=index.js.map
import { Twilio } from 'twilio';
import { PluginsUtilsMetaData } from '../../types';
import { Parameters, APIReturnType } from '../../types';
import { Parameters, ApiReturnType } from '../../types';
import { CallInstance } from 'twilio/lib/rest/api/v2010/account/call';

@@ -9,12 +9,12 @@ import { RecordingInstance, RecordingListInstanceCreateOptions } from 'twilio/lib/rest/api/v2010/account/call/recording';

import { PluginUtils } from '../../common/BaseClasses/PluginUtils';
export declare class ProgrammableVoiceUtils extends PluginUtils {
export default class ProgrammableVoiceUtils extends PluginUtils {
private config;
/**
* Utility class for ProgrammableVoice resources
* Utility class for Twilio's Programmable Voice resources
* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* */

@@ -30,3 +30,3 @@ constructor(client: Twilio, config: PluginsUtilsMetaData);

callSid: string;
}): Promise<APIReturnType & {
}): Promise<ApiReturnType & {
callProperties?: CallInstance;

@@ -44,3 +44,3 @@ }>;

to: string;
}): Promise<APIReturnType>;
}): Promise<ApiReturnType>;
/**

@@ -56,3 +56,3 @@ * @param {number} parameters.attempts the number of retry attempts performed

params: RecordingListInstanceCreateOptions;
}): Promise<APIReturnType & {
}): Promise<ApiReturnType & {
recording?: RecordingInstance;

@@ -68,3 +68,3 @@ }>;

*/
updateCallRecording(parameters: updateCallRecordingParams): Promise<APIReturnType & {
updateCallRecording(parameters: updateCallRecordingParams): Promise<ApiReturnType & {
recording?: RecordingInstance;

@@ -80,5 +80,5 @@ }>;

*/
updateConferenceRecording(parameters: updateConferenceRecording): Promise<APIReturnType & {
updateConferenceRecording(parameters: updateConferenceRecording): Promise<ApiReturnType & {
recording?: ConferenceRecordingInstance;
}>;
}

@@ -12,17 +12,16 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ProgrammableVoiceUtils = void 0;
const retryHandler_1 = require("../../common/retryHandler");
const lodash_1 = require("lodash");
const PluginUtils_1 = require("../../common/BaseClasses/PluginUtils");
const statusCodes_1 = require("../../constants/statusCodes");
const moduleErrors_1 = require("../../constants/moduleErrors");
const PluginUtilsErrorManager_1 = require("../../common/PluginUtilsErrorManager");
class ProgrammableVoiceUtils extends PluginUtils_1.PluginUtils {
/**
* Utility class for ProgrammableVoice resources
* Utility class for Twilio's Programmable Voice resources
* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* */

@@ -44,10 +43,13 @@ constructor(client, config) {

fetchProperties(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, callSid } = parameters;
const { callSid } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const callProperties = yield this.client.calls(callSid).fetch();

@@ -57,3 +59,3 @@ return { success: true, callProperties, status: statusCodes_1.HttpErrorCode.OK };

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -77,12 +79,14 @@ success: false,

coldTransfer(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, callSid, to } = parameters;
const { callSid, to } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
to: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
if (!(0, lodash_1.isString)(to))
throw new Error('Invalid parameters object passed. Parameters must contain to string');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
yield this.client.calls(callSid).update({

@@ -94,3 +98,3 @@ twiml: `<Response><Dial>${to}</Dial></Response>`,

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -114,12 +118,14 @@ success: false,

createRecording(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, callSid, params } = parameters;
const { callSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
params: 'object',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
if (!(0, lodash_1.isObject)(params))
throw new Error('Invalid parameters object passed. Parameters must contain recording creation parameters object');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const recording = yield this.client.calls(callSid).recordings.create(params);

@@ -129,3 +135,3 @@ return { success: true, recording, status: statusCodes_1.HttpErrorCode.OK };

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -150,14 +156,15 @@ success: false,

updateCallRecording(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, callSid, recordingSid, params } = parameters;
const { callSid, recordingSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
recordingSid: 'string',
params: 'object',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
if (!(0, lodash_1.isString)(recordingSid))
throw new Error('Invalid parameters object passed. Parameters must contain recordingSid string');
if (!(0, lodash_1.isObject)(params))
throw new Error('Invalid parameters object passed. Parameters must contain params object');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const recording = yield this.client.calls(callSid).recordings(recordingSid).update(params);

@@ -167,3 +174,3 @@ return { success: true, recording, status: statusCodes_1.HttpErrorCode.OK };

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -188,14 +195,15 @@ success: false,

updateConferenceRecording(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, conferenceSid, recordingSid, params } = parameters;
const { conferenceSid, recordingSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
conferenceSid: 'string',
recordingSid: 'string',
params: 'object',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(conferenceSid))
throw new Error('Invalid parameters object passed. Parameters must contain conferenceSid string');
if (!(0, lodash_1.isString)(recordingSid))
throw new Error('Invalid parameters object passed. Parameters must contain recordingSid string');
if (!(0, lodash_1.isObject)(params))
throw new Error('Invalid parameters object passed. Parameters must contain params object');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const recording = yield this.client.conferences(conferenceSid).recordings(recordingSid).update(params);

@@ -205,3 +213,3 @@ return { success: true, recording, status: statusCodes_1.HttpErrorCode.OK };

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -218,3 +226,3 @@ success: false,

}
exports.ProgrammableVoiceUtils = ProgrammableVoiceUtils;
exports.default = ProgrammableVoiceUtils;
//# sourceMappingURL=index.js.map

@@ -8,17 +8,17 @@ import { Twilio } from 'twilio';

import { WorkflowInstance } from 'twilio/lib/rest/taskrouter/v1/workspace/workflow';
import { Parameters, APIReturnType } from '../../types';
import { Parameters, ApiReturnType } from '../../types';
import { TaskRouterMetaData, CompleteTaskParams, UpdateReservationParams, UpdateTaskAttributesParams, UpdateTaskParams, WorkerChannelParams } from './types';
import { PluginUtils } from '../../common/BaseClasses/PluginUtils';
export declare class TaskRouterUtils extends PluginUtils {
export default class TaskRouterUtils extends PluginUtils {
private api;
private config;
/**
* Utility class for Taskrouter resources
* Utility class for Twilio's Taskrouter resources
* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.TWILIO_FLEX_WORKSPACE_SID Flex workspace sid
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* @param {TaskRouterMetaData} config.flexWorkSpaceSid Flex workspace sid
* */

@@ -34,3 +34,3 @@ constructor(client: Twilio, config: TaskRouterMetaData);

* */
getAllWorkersFromWorkspace(parameters: Parameters): Promise<APIReturnType & {
getAllWorkersFromWorkspace(parameters: Parameters): Promise<ApiReturnType & {
workersList?: Array<WorkerInstance>;

@@ -46,3 +46,3 @@ }>;

* */
getAllTasksFromWorkspace(parameters: Parameters): Promise<APIReturnType & {
getAllTasksFromWorkspace(parameters: Parameters): Promise<ApiReturnType & {
taskList?: Array<TaskInstance>;

@@ -58,3 +58,3 @@ }>;

*/
getAllQueues(parameters: Parameters): Promise<APIReturnType & {
getAllQueues(parameters: Parameters): Promise<ApiReturnType & {
taskQueueList?: Array<TaskQueueInstance>;

@@ -70,3 +70,3 @@ }>;

*/
getAllWorkflows(parameters: Parameters): Promise<APIReturnType & {
getAllWorkflows(parameters: Parameters): Promise<ApiReturnType & {
workFlowList?: Array<WorkflowInstance>;

@@ -83,3 +83,3 @@ }>;

workerSid: string;
}): Promise<APIReturnType & {
}): Promise<ApiReturnType & {
workerChannels?: Array<WorkerChannelInstance>;

@@ -92,4 +92,4 @@ }>;

* @param {string} parameters.workerChannelSid the worker channel sid to fetch channels for
* @param {string} parameters.capacity channel capacity to be updated
* @param {string} parameters.available channel availability to be updated
* @param {number} parameters.capacity channel capacity to be updated
* @param {boolean} parameters.available channel availability to be updated
* @returns {object} worker channel capacity object

@@ -99,3 +99,3 @@ * @description the following method is used to robustly update

*/
updateWorkerChannel(parameters: WorkerChannelParams): Promise<APIReturnType & {
updateWorkerChannel(parameters: WorkerChannelParams): Promise<ApiReturnType & {
workerChannelCapacity?: WorkerChannelInstance;

@@ -110,3 +110,3 @@ }>;

*/
updateTask(parameters: UpdateTaskParams): Promise<APIReturnType & {
updateTask(parameters: UpdateTaskParams): Promise<ApiReturnType & {
task?: TaskInstance;

@@ -122,3 +122,3 @@ }>;

taskSid: string;
}): Promise<APIReturnType & {
}): Promise<ApiReturnType & {
task?: TaskInstance;

@@ -131,3 +131,3 @@ }>;

* @param {string} parameters.taskChannel the task channel to submit the task on
* @param {object} parameters.attributes the attributes applied to the task
* @param {string} parameters.attributes the attributes applied to the task
* @param {number} parameters.priority the priority

@@ -138,3 +138,3 @@ * @param {number} parameters.timeout timeout

*/
createTask(parameters: Parameters & TaskListInstanceCreateOptions): Promise<APIReturnType & {
createTask(parameters: Parameters & TaskListInstanceCreateOptions): Promise<ApiReturnType & {
task?: TaskInstance;

@@ -150,3 +150,3 @@ taskSid?: string;

*/
completeTask(parameters: CompleteTaskParams): Promise<APIReturnType & {
completeTask(parameters: CompleteTaskParams): Promise<ApiReturnType & {
task?: TaskInstance;

@@ -162,3 +162,3 @@ }>;

*/
updateReservation(parameters: UpdateReservationParams): Promise<APIReturnType & {
updateReservation(parameters: UpdateReservationParams): Promise<ApiReturnType & {
reservation?: ReservationInstance;

@@ -169,3 +169,3 @@ }>;

* @param {string} parameters.taskSid the task to update
* @param {string} parameters.attributesUpdate a JSON object to merge with the task
* @param {string} parameters.attributesUpdate a string JSON object to merge with the task
* @returns {object} an object containing the task if successful

@@ -172,0 +172,0 @@ * @description this operation safely updates the task attributes with the object

@@ -15,3 +15,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskRouterUtils = void 0;
const lodash_1 = require("lodash");

@@ -23,2 +22,3 @@ const Api_1 = __importDefault(require("./Api"));

const moduleErrors_1 = require("../../constants/moduleErrors");
const PluginUtilsErrorManager_1 = require("../../common/PluginUtilsErrorManager");
const defaultTimeout = 86400;

@@ -28,10 +28,10 @@ const defaultTaskPriority = 0;

/**
* Utility class for Taskrouter resources
* Utility class for Twilio's Taskrouter resources
* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.TWILIO_FLEX_WORKSPACE_SID Flex workspace sid
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* @param {TaskRouterMetaData} config.flexWorkSpaceSid Flex workspace sid
* */

@@ -44,5 +44,5 @@ constructor(client, config) {

}
const { ACCOUNT_SID, AUTH_TOKEN, TWILIO_FLEX_WORKSPACE_SID } = config;
const { accountSid, authToken, flexWorkSpaceSid } = config;
this.config = config;
this.api = new Api_1.default(ACCOUNT_SID, AUTH_TOKEN, TWILIO_FLEX_WORKSPACE_SID);
this.api = new Api_1.default(accountSid, authToken, flexWorkSpaceSid);
}

@@ -62,3 +62,3 @@ /**

workersList = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workers.list({ limit: parameters.limit });

@@ -89,3 +89,3 @@ return {

taskList = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks.list({ limit: parameters.limit });

@@ -116,3 +116,3 @@ return {

taskQueueList = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.taskQueues.list({ limit: parameters.limit });

@@ -143,3 +143,3 @@ return {

workFlowList = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workflows.list({ limit: parameters.limit });

@@ -165,12 +165,15 @@ return {

getWorkerChannels(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, workerSid } = parameters;
const parameterChecks = {
attempts: 'number',
workerSid: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(workerSid))
throw new Error('Invalid parameters object passed. Parameters must contain workerSid string');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const workerChannels = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workers(workerSid)

@@ -185,3 +188,3 @@ .workerChannels.list();

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -202,4 +205,4 @@ success: false,

* @param {string} parameters.workerChannelSid the worker channel sid to fetch channels for
* @param {string} parameters.capacity channel capacity to be updated
* @param {string} parameters.available channel availability to be updated
* @param {number} parameters.capacity channel capacity to be updated
* @param {boolean} parameters.available channel availability to be updated
* @returns {object} worker channel capacity object

@@ -210,18 +213,18 @@ * @description the following method is used to robustly update

updateWorkerChannel(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, workerSid, workerChannelSid, capacity, available } = parameters;
const { workerSid, workerChannelSid, capacity, available } = parameters;
const parameterChecks = {
attempts: 'number',
workerSid: 'string',
workerChannelSid: 'string',
capacity: 'number',
available: 'boolean',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(workerSid))
throw new Error('Invalid parameters object passed. Parameters must contain workerSid string');
if (!(0, lodash_1.isString)(workerChannelSid))
throw new Error('Invalid parameters object passed. Parameters must contain workerChannelSid string');
if (!(0, lodash_1.isNumber)(capacity))
throw new Error('Invalid parameters object passed. Parameters must contain capacity number');
if (!(0, lodash_1.isBoolean)(available))
throw new Error('Invalid parameters object passed. Parameters must contain available boolean');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const workerChannelCapacity = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workers(workerSid)

@@ -237,3 +240,3 @@ .workerChannels(workerChannelSid)

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -257,14 +260,16 @@ success: false,

updateTask(parameters) {
var _a;
return __awaiter(this, arguments, void 0, function* () {
const { attempts, taskSid, updateParams } = parameters;
const { taskSid, updateParams } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
updateParams: 'object',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!(0, lodash_1.isObject)(updateParams))
throw new Error('Invalid parameters object passed. Parameters must contain updateParams object');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const task = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks(taskSid)

@@ -279,3 +284,3 @@ .update(updateParams);

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -306,14 +311,14 @@ success: false,

fetchTask(parameters) {
var _a;
return __awaiter(this, arguments, void 0, function* () {
const { attempts, taskSid } = parameters;
const { taskSid } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
const task = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.tasks(taskSid)
.fetch();
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const task = yield this.client.taskrouter.v1.workspaces(this.config.flexWorkSpaceSid).tasks(taskSid).fetch();
return {

@@ -326,3 +331,3 @@ success: true,

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -351,3 +356,3 @@ success: false,

* @param {string} parameters.taskChannel the task channel to submit the task on
* @param {object} parameters.attributes the attributes applied to the task
* @param {string} parameters.attributes the attributes applied to the task
* @param {number} parameters.priority the priority

@@ -359,17 +364,18 @@ * @param {number} parameters.timeout timeout

createTask(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { workflowSid, taskChannel, attributes, priority: overriddenPriority, timeout: overriddenTimeout, attempts, } = parameters;
const { workflowSid, taskChannel, attributes, priority: overriddenPriority, timeout: overriddenTimeout, } = parameters;
const timeout = overriddenTimeout || defaultTimeout;
const priority = overriddenPriority || defaultTaskPriority;
const parameterChecks = {
attempts: 'number',
workflowSid: 'string',
attributes: 'string',
taskChannel: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(workflowSid) || workflowSid.length == 0)
throw new Error('Invalid parameters object passed. Parameters must contain workflowSid string');
if (!(0, lodash_1.isString)(taskChannel) || taskChannel.length == 0)
throw new Error('Invalid parameters object passed. Parameters must contain taskChannel string');
if (!(0, lodash_1.isString)(attributes))
throw new Error('Invalid parameters object passed. Parameters must contain attributes object');
const task = yield this.client.taskrouter.v1.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID).tasks.create({
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const task = yield this.client.taskrouter.v1.workspaces(this.config.flexWorkSpaceSid).tasks.create({
attributes,

@@ -389,3 +395,3 @@ workflowSid,

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -409,14 +415,16 @@ success: false,

completeTask(parameters) {
var _a;
return __awaiter(this, arguments, void 0, function* () {
const { attempts, taskSid, reason } = parameters;
const { taskSid, reason } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
reason: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!(0, lodash_1.isString)(reason))
throw new Error('Invalid parameters object passed. Parameters must contain reason string');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const task = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks(taskSid)

@@ -431,3 +439,3 @@ .update({ assignmentStatus: 'completed', reason });

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -460,16 +468,18 @@ success: false,

updateReservation(parameters) {
var _a;
return __awaiter(this, arguments, void 0, function* () {
const { attempts, taskSid, reservationSid, status } = parameters;
const { taskSid, reservationSid, status } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
reservationSid: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!(0, lodash_1.isString)(reservationSid))
throw new Error('Invalid parameters object passed. Parameters must contain reservationSid string');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
if (!(0, lodash_1.isString)(status) || (status != 'completed' && status != 'wrapping'))
throw new Error('Invalid parameters object passed. Parameters must contain status to update the reservation to and it must be one of "completed" or "wrapping"');
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager('Invalid parameters object passed. Parameters must contain status to update the reservation to and it must be one of "completed" or "wrapping"', statusCodes_1.HttpErrorCode.BadRequest);
const reservation = yield this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks(taskSid)

@@ -485,3 +495,3 @@ .reservations(reservationSid)

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -508,3 +518,3 @@ success: false,

* @param {string} parameters.taskSid the task to update
* @param {string} parameters.attributesUpdate a JSON object to merge with the task
* @param {string} parameters.attributesUpdate a string JSON object to merge with the task
* @returns {object} an object containing the task if successful

@@ -517,12 +527,14 @@ * @description this operation safely updates the task attributes with the object

updateTaskAttributes(parameters) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { attempts, taskSid, attributesUpdate } = parameters;
const { taskSid, attributesUpdate } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
attributesUpdate: 'string',
};
try {
if (!(0, lodash_1.isNumber)(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!(0, lodash_1.isString)(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!(0, lodash_1.isString)(attributesUpdate))
throw new Error('Invalid parameters object passed. Parameters must contain attributesUpdate JSON string');
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
// we need to fetch the task using a rest API because

@@ -550,3 +562,3 @@ // we need to examine the headers to get the ETag

catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Invalid parameters object passed')) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {

@@ -563,3 +575,3 @@ success: false,

}
exports.TaskRouterUtils = TaskRouterUtils;
exports.default = TaskRouterUtils;
//# sourceMappingURL=index.js.map
import { TaskContextUpdateOptions } from 'twilio/lib/rest/taskrouter/v1/workspace/task';
import { PluginsUtilsMetaData, Parameters } from '../../types';
export interface TaskRouterMetaData extends PluginsUtilsMetaData {
TWILIO_FLEX_WORKSPACE_SID: string;
flexWorkSpaceSid: string;
}

@@ -6,0 +6,0 @@ export interface WorkerChannelParams extends Parameters {

@@ -1,4 +0,6 @@

import { TaskRouterUtils } from './core/TaskRouterUtils';
import { ProgrammableVoiceUtils } from './core/ProgrammableVoiceUtils';
import { PhoneNumbersUtils } from './core/PhoneNumberUtils';
export { TaskRouterUtils, ProgrammableVoiceUtils, PhoneNumbersUtils };
import TaskRouterUtils from './core/TaskRouterUtils';
import ProgrammableVoiceUtils from './core/ProgrammableVoiceUtils';
import PhoneNumbersUtils from './core/PhoneNumberUtils';
import ConferenceUtils from './core/ConferenceUtils';
import InteractionUtils from './core/InteractionUtils';
export { TaskRouterUtils, ProgrammableVoiceUtils, PhoneNumbersUtils, ConferenceUtils, InteractionUtils };
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PhoneNumbersUtils = exports.ProgrammableVoiceUtils = exports.TaskRouterUtils = void 0;
const TaskRouterUtils_1 = require("./core/TaskRouterUtils");
Object.defineProperty(exports, "TaskRouterUtils", { enumerable: true, get: function () { return TaskRouterUtils_1.TaskRouterUtils; } });
const ProgrammableVoiceUtils_1 = require("./core/ProgrammableVoiceUtils");
Object.defineProperty(exports, "ProgrammableVoiceUtils", { enumerable: true, get: function () { return ProgrammableVoiceUtils_1.ProgrammableVoiceUtils; } });
const PhoneNumberUtils_1 = require("./core/PhoneNumberUtils");
Object.defineProperty(exports, "PhoneNumbersUtils", { enumerable: true, get: function () { return PhoneNumberUtils_1.PhoneNumbersUtils; } });
exports.InteractionUtils = exports.ConferenceUtils = exports.PhoneNumbersUtils = exports.ProgrammableVoiceUtils = exports.TaskRouterUtils = void 0;
const TaskRouterUtils_1 = __importDefault(require("./core/TaskRouterUtils"));
exports.TaskRouterUtils = TaskRouterUtils_1.default;
const ProgrammableVoiceUtils_1 = __importDefault(require("./core/ProgrammableVoiceUtils"));
exports.ProgrammableVoiceUtils = ProgrammableVoiceUtils_1.default;
const PhoneNumberUtils_1 = __importDefault(require("./core/PhoneNumberUtils"));
exports.PhoneNumbersUtils = PhoneNumberUtils_1.default;
const ConferenceUtils_1 = __importDefault(require("./core/ConferenceUtils"));
exports.ConferenceUtils = ConferenceUtils_1.default;
const InteractionUtils_1 = __importDefault(require("./core/InteractionUtils"));
exports.InteractionUtils = InteractionUtils_1.default;
//# sourceMappingURL=index.js.map
import { AxiosResponse } from 'axios';
export interface PluginsUtilsMetaData {
TWILIO_SERVICE_MAX_BACKOFF: number;
TWILIO_SERVICE_MIN_BACKOFF: number;
TWILIO_SERVICE_RETRY_LIMIT: number;
ACCOUNT_SID: string;
AUTH_TOKEN: string;
maxBackoff: number;
minBackoff: number;
retryLimit: number;
accountSid: string;
authToken: string;
}

@@ -13,3 +13,3 @@ export interface Parameters {

}
export interface APIReturnType {
export interface ApiReturnType {
success: boolean;

@@ -16,0 +16,0 @@ status: number;

{
"name": "@twilio/flex-plugins-library-utils",
"version": "0.2.0",
"version": "1.0.0",
"description": "Flex Plugins Library Utils",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -6,3 +6,2 @@ # Flex Plugins Library Utils

This package is a utility library to be used in serverless functions to interact with commonly used Twilio resources and APIs such as Taskrouter, Programmable voice etc.
## Usage

@@ -28,8 +27,8 @@

const config = {
TWILIO_SERVICE_MAX_BACKOFF: 2000,
TWILIO_SERVICE_MIN_BACKOFF: 1000,
TWILIO_SERVICE_RETRY_LIMIT: 3,
ACCOUNT_SID: 'YOUR_TWILIO_ACCOUNT_SID',
AUTH_TOKEN: 'YOUR_TWILIO_AUTH_TOKEN',
TWILIO_FLEX_WORKSPACE_SID: 'YOUR_TWILIO_FLEX_WORKSPACE_SID',
maxBackoff: 2000,
minBackoff: 1000,
retryLimit: 3,
accountSid: 'YOUR_TWILIO_ACCOUNT_SID',
authToken: 'YOUR_TWILIO_AUTH_TOKEN',
flexWorkSpaceSid: 'YOUR_TWILIO_FLEX_WORKSPACE_SID',
};

@@ -36,0 +35,0 @@

import { Twilio } from 'twilio';
export abstract class PluginUtils {
client: Twilio;
protected client: Twilio;
constructor(client: Twilio) {

@@ -6,0 +6,0 @@ this.client = client;

@@ -34,3 +34,3 @@ import { Parameters, PluginsUtilsMetaData, TwilioError, RetryCallbackFunction } from '../types';

) => {
const { TWILIO_SERVICE_MAX_BACKOFF, TWILIO_SERVICE_MIN_BACKOFF, TWILIO_SERVICE_RETRY_LIMIT } = metaData;
const { maxBackoff, minBackoff, retryLimit } = metaData;
const { attempts } = parameters;

@@ -47,7 +47,7 @@ const { response, message: errorMessage } = error;

isNumber(attempts) &&
attempts < TWILIO_SERVICE_RETRY_LIMIT
attempts < retryLimit
) {
console.warn(`retrying ${callback.name}() after ${logWarning}, status code: ${status}`);
if (status === HttpErrorCode.TooManyRequests || status === HttpErrorCode.ServiceUnavailable)
await snooze(random(TWILIO_SERVICE_MIN_BACKOFF, TWILIO_SERVICE_MAX_BACKOFF));
await snooze(random(minBackoff, maxBackoff));

@@ -54,0 +54,0 @@ const updatedAttempts = attempts + 1;

import { Twilio } from 'twilio';
import { retryHandler } from '../../common/retryHandler';
import { PluginsUtilsMetaData } from '../../types';
import { Parameters, APIReturnType } from '../../types';
import { Parameters, ApiReturnType } from '../../types';
import { IncomingPhoneNumberInstance } from 'twilio/lib/rest/api/v2010/account/incomingPhoneNumber';

@@ -10,4 +10,5 @@ import { isNumber } from 'lodash';

import { invalidConfigError } from '../../constants/moduleErrors';
import { PluginUtilsErrorManager } from '../../common/PluginUtilsErrorManager';
export class PhoneNumbersUtils extends PluginUtils {
export default class PhoneNumbersUtils extends PluginUtils {
private config: PluginsUtilsMetaData;

@@ -18,7 +19,7 @@

* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* */

@@ -43,10 +44,15 @@ constructor(client: Twilio, config: PluginsUtilsMetaData) {

parameters: Parameters,
): Promise<APIReturnType & { phoneNumbers?: Array<IncomingPhoneNumberInstance> }> {
const { attempts } = parameters;
): Promise<ApiReturnType & { phoneNumbers?: Array<IncomingPhoneNumberInstance> }> {
const parameterChecks = {
attempts: 'number',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters>(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const phoneNumbers = await this.client.incomingPhoneNumbers.list({
limit: 1000,
limit: parameters.limit || 1000,
});

@@ -56,3 +62,3 @@

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -59,0 +65,0 @@ success: false,

import { Twilio } from 'twilio';
import { retryHandler } from '../../common/retryHandler';
import { PluginsUtilsMetaData } from '../../types';
import { Parameters, APIReturnType } from '../../types';
import { Parameters, ApiReturnType } from '../../types';
import { isNumber, isObject, isString } from 'lodash';

@@ -16,14 +16,15 @@ import { CallInstance } from 'twilio/lib/rest/api/v2010/account/call';

import { invalidConfigError } from '../../constants/moduleErrors';
import { PluginUtilsErrorManager } from '../../common/PluginUtilsErrorManager';
export class ProgrammableVoiceUtils extends PluginUtils {
export default class ProgrammableVoiceUtils extends PluginUtils {
private config: PluginsUtilsMetaData;
/**
* Utility class for ProgrammableVoice resources
* Utility class for Twilio's Programmable Voice resources
* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* */

@@ -48,10 +49,19 @@ constructor(client: Twilio, config: PluginsUtilsMetaData) {

parameters: Parameters & { callSid: string },
): Promise<APIReturnType & { callProperties?: CallInstance }> {
const { attempts, callSid } = parameters;
): Promise<ApiReturnType & { callProperties?: CallInstance }> {
const { callSid } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters & { callSid: string }>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const callProperties = await this.client.calls(callSid).fetch();

@@ -61,3 +71,3 @@

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -80,11 +90,20 @@ success: false,

*/
public async coldTransfer(parameters: Parameters & { callSid: string; to: string }): Promise<APIReturnType> {
const { attempts, callSid, to } = parameters;
public async coldTransfer(parameters: Parameters & { callSid: string; to: string }): Promise<ApiReturnType> {
const { callSid, to } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
to: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
if (!isString(to)) throw new Error('Invalid parameters object passed. Parameters must contain to string');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters & { callSid: string; to: string }>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
await this.client.calls(callSid).update({

@@ -96,3 +115,3 @@ twiml: `<Response><Dial>${to}</Dial></Response>`,

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -122,14 +141,19 @@ success: false,

parameters: Parameters & { callSid: string; params: RecordingListInstanceCreateOptions },
): Promise<APIReturnType & { recording?: RecordingInstance }> {
const { attempts, callSid, params } = parameters;
): Promise<ApiReturnType & { recording?: RecordingInstance }> {
const { callSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
params: 'object',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
if (!isObject(params))
throw new Error(
'Invalid parameters object passed. Parameters must contain recording creation parameters object',
);
const inputError = PluginUtilsErrorManager.checkInvalidParameters<
Parameters & { callSid: string; params: RecordingListInstanceCreateOptions }
>(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const recording = await this.client.calls(callSid).recordings.create(params);

@@ -139,3 +163,3 @@

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -166,13 +190,21 @@ success: false,

parameters: updateCallRecordingParams,
): Promise<APIReturnType & { recording?: RecordingInstance }> {
const { attempts, callSid, recordingSid, params } = parameters;
): Promise<ApiReturnType & { recording?: RecordingInstance }> {
const { callSid, recordingSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
recordingSid: 'string',
params: 'object',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(callSid))
throw new Error('Invalid parameters object passed. Parameters must contain callSid string');
if (!isString(recordingSid))
throw new Error('Invalid parameters object passed. Parameters must contain recordingSid string');
if (!isObject(params)) throw new Error('Invalid parameters object passed. Parameters must contain params object');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<updateCallRecordingParams>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const recording = await this.client.calls(callSid).recordings(recordingSid).update(params);

@@ -182,3 +214,3 @@

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -204,13 +236,21 @@ success: false,

parameters: updateConferenceRecording,
): Promise<APIReturnType & { recording?: ConferenceRecordingInstance }> {
const { attempts, conferenceSid, recordingSid, params } = parameters;
): Promise<ApiReturnType & { recording?: ConferenceRecordingInstance }> {
const { conferenceSid, recordingSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
conferenceSid: 'string',
recordingSid: 'string',
params: 'object',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(conferenceSid))
throw new Error('Invalid parameters object passed. Parameters must contain conferenceSid string');
if (!isString(recordingSid))
throw new Error('Invalid parameters object passed. Parameters must contain recordingSid string');
if (!isObject(params)) throw new Error('Invalid parameters object passed. Parameters must contain params object');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<updateConferenceRecording>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const recording = await this.client.conferences(conferenceSid).recordings(recordingSid).update(params);

@@ -220,3 +260,3 @@

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -223,0 +263,0 @@ success: false,

@@ -9,3 +9,3 @@ import { Twilio } from 'twilio';

import { WorkflowInstance } from 'twilio/lib/rest/taskrouter/v1/workspace/workflow';
import { Parameters, APIReturnType } from '../../types';
import { Parameters, ApiReturnType } from '../../types';
import {

@@ -24,6 +24,7 @@ TaskRouterMetaData,

import { invalidConfigError } from '../../constants/moduleErrors';
import { PluginUtilsErrorManager } from '../../common/PluginUtilsErrorManager';
const defaultTimeout = 86400;
const defaultTaskPriority = 0;
export class TaskRouterUtils extends PluginUtils {
export default class TaskRouterUtils extends PluginUtils {
private api: TwilioTaskRouterAPI;

@@ -33,10 +34,10 @@ private config: TaskRouterMetaData;

/**
* Utility class for Taskrouter resources
* Utility class for Twilio's Taskrouter resources
* @param {Twilio} client Twilio client
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MAX_BACKOFF Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_MIN_BACKOFF Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.TWILIO_SERVICE_RETRY_LIMIT Service retry limit
* @param {TaskRouterMetaData} config.ACCOUNT_SID Twilio account sid
* @param {TaskRouterMetaData} config.AUTH_TOKEN Twilio auth token
* @param {TaskRouterMetaData} config.TWILIO_FLEX_WORKSPACE_SID Flex workspace sid
* @param {TaskRouterMetaData} config.maxBackoff Twilio service backoff max timeout
* @param {TaskRouterMetaData} config.minBackoff Twilio service backoff min timeout
* @param {TaskRouterMetaData} config.retryLimit Service retry limit
* @param {TaskRouterMetaData} config.accountSid Twilio account sid
* @param {TaskRouterMetaData} config.authToken Twilio auth token
* @param {TaskRouterMetaData} config.flexWorkSpaceSid Flex workspace sid
* */

@@ -51,5 +52,5 @@ constructor(client: Twilio, config: TaskRouterMetaData) {

const { ACCOUNT_SID, AUTH_TOKEN, TWILIO_FLEX_WORKSPACE_SID } = config;
const { accountSid, authToken, flexWorkSpaceSid } = config;
this.config = config;
this.api = new TwilioTaskRouterAPI(ACCOUNT_SID, AUTH_TOKEN, TWILIO_FLEX_WORKSPACE_SID);
this.api = new TwilioTaskRouterAPI(accountSid, authToken, flexWorkSpaceSid);
}

@@ -67,3 +68,3 @@

parameters: Parameters,
): Promise<APIReturnType & { workersList?: Array<WorkerInstance> }> {
): Promise<ApiReturnType & { workersList?: Array<WorkerInstance> }> {
let workersList: Array<WorkerInstance> = [];

@@ -73,3 +74,3 @@

workersList = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workers.list({ limit: parameters.limit });

@@ -96,3 +97,3 @@ return {

parameters: Parameters,
): Promise<APIReturnType & { taskList?: Array<TaskInstance> }> {
): Promise<ApiReturnType & { taskList?: Array<TaskInstance> }> {
let taskList: Array<TaskInstance> = [];

@@ -102,3 +103,3 @@

taskList = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks.list({ limit: parameters.limit });

@@ -125,3 +126,3 @@ return {

parameters: Parameters,
): Promise<APIReturnType & { taskQueueList?: Array<TaskQueueInstance> }> {
): Promise<ApiReturnType & { taskQueueList?: Array<TaskQueueInstance> }> {
let taskQueueList: Array<TaskQueueInstance> = [];

@@ -131,3 +132,3 @@

taskQueueList = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.taskQueues.list({ limit: parameters.limit });

@@ -155,3 +156,3 @@

parameters: Parameters,
): Promise<APIReturnType & { workFlowList?: Array<WorkflowInstance> }> {
): Promise<ApiReturnType & { workFlowList?: Array<WorkflowInstance> }> {
let workFlowList: Array<WorkflowInstance> = [];

@@ -161,3 +162,3 @@

workFlowList = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workflows.list({ limit: parameters.limit });

@@ -184,12 +185,21 @@

parameters: Parameters & { workerSid: string },
): Promise<APIReturnType & { workerChannels?: Array<WorkerChannelInstance> }> {
): Promise<ApiReturnType & { workerChannels?: Array<WorkerChannelInstance> }> {
const { attempts, workerSid } = parameters;
const parameterChecks = {
attempts: 'number',
workerSid: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(workerSid))
throw new Error('Invalid parameters object passed. Parameters must contain workerSid string');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters & { workerSid: string }>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const workerChannels = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workers(workerSid)

@@ -204,3 +214,3 @@ .workerChannels.list();

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -221,4 +231,4 @@ success: false,

* @param {string} parameters.workerChannelSid the worker channel sid to fetch channels for
* @param {string} parameters.capacity channel capacity to be updated
* @param {string} parameters.available channel availability to be updated
* @param {number} parameters.capacity channel capacity to be updated
* @param {boolean} parameters.available channel availability to be updated
* @returns {object} worker channel capacity object

@@ -230,18 +240,24 @@ * @description the following method is used to robustly update

parameters: WorkerChannelParams,
): Promise<APIReturnType & { workerChannelCapacity?: WorkerChannelInstance }> {
const { attempts, workerSid, workerChannelSid, capacity, available } = parameters;
): Promise<ApiReturnType & { workerChannelCapacity?: WorkerChannelInstance }> {
const { workerSid, workerChannelSid, capacity, available } = parameters;
const parameterChecks = {
attempts: 'number',
workerSid: 'string',
workerChannelSid: 'string',
capacity: 'number',
available: 'boolean',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(workerSid))
throw new Error('Invalid parameters object passed. Parameters must contain workerSid string');
if (!isString(workerChannelSid))
throw new Error('Invalid parameters object passed. Parameters must contain workerChannelSid string');
if (!isNumber(capacity))
throw new Error('Invalid parameters object passed. Parameters must contain capacity number');
if (!isBoolean(available))
throw new Error('Invalid parameters object passed. Parameters must contain available boolean');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<WorkerChannelParams>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const workerChannelCapacity = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.workers(workerSid)

@@ -257,3 +273,3 @@ .workerChannels(workerChannelSid)

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -276,14 +292,22 @@ success: false,

*/
public async updateTask(parameters: UpdateTaskParams): Promise<APIReturnType & { task?: TaskInstance }> {
const { attempts, taskSid, updateParams } = parameters;
public async updateTask(parameters: UpdateTaskParams): Promise<ApiReturnType & { task?: TaskInstance }> {
const { taskSid, updateParams } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
updateParams: 'object',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!isObject(updateParams))
throw new Error('Invalid parameters object passed. Parameters must contain updateParams object');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters & { taskSid: string }>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const task = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks(taskSid)

@@ -298,3 +322,3 @@ .update(updateParams);

} catch (error: any) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -326,15 +350,21 @@ success: false,

parameters: Parameters & { taskSid: string },
): Promise<APIReturnType & { task?: TaskInstance }> {
const { attempts, taskSid } = parameters;
): Promise<ApiReturnType & { task?: TaskInstance }> {
const { taskSid } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
const task = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.tasks(taskSid)
.fetch();
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters & { taskSid: string }>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const task = await this.client.taskrouter.v1.workspaces(this.config.flexWorkSpaceSid).tasks(taskSid).fetch();
return {

@@ -346,3 +376,3 @@ success: true,

} catch (error: any) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -372,3 +402,3 @@ success: false,

* @param {string} parameters.taskChannel the task channel to submit the task on
* @param {object} parameters.attributes the attributes applied to the task
* @param {string} parameters.attributes the attributes applied to the task
* @param {number} parameters.priority the priority

@@ -381,3 +411,3 @@ * @param {number} parameters.timeout timeout

parameters: Parameters & TaskListInstanceCreateOptions,
): Promise<APIReturnType & { task?: TaskInstance; taskSid?: string }> {
): Promise<ApiReturnType & { task?: TaskInstance; taskSid?: string }> {
const {

@@ -389,3 +419,2 @@ workflowSid,

timeout: overriddenTimeout,
attempts,
} = parameters;

@@ -396,13 +425,18 @@

const parameterChecks = {
attempts: 'number',
workflowSid: 'string',
attributes: 'string',
taskChannel: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(workflowSid) || workflowSid.length == 0)
throw new Error('Invalid parameters object passed. Parameters must contain workflowSid string');
if (!isString(taskChannel) || taskChannel.length == 0)
throw new Error('Invalid parameters object passed. Parameters must contain taskChannel string');
if (!isString(attributes))
throw new Error('Invalid parameters object passed. Parameters must contain attributes object');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters & TaskListInstanceCreateOptions>(
parameters,
parameterChecks,
);
const task = await this.client.taskrouter.v1.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID).tasks.create({
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const task = await this.client.taskrouter.v1.workspaces(this.config.flexWorkSpaceSid).tasks.create({
attributes,

@@ -422,3 +456,3 @@ workflowSid,

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -441,13 +475,21 @@ success: false,

*/
public async completeTask(parameters: CompleteTaskParams): Promise<APIReturnType & { task?: TaskInstance }> {
const { attempts, taskSid, reason } = parameters;
public async completeTask(parameters: CompleteTaskParams): Promise<ApiReturnType & { task?: TaskInstance }> {
const { taskSid, reason } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
reason: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!isString(reason)) throw new Error('Invalid parameters object passed. Parameters must contain reason string');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<CompleteTaskParams>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const task = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks(taskSid)

@@ -462,3 +504,3 @@ .update({ assignmentStatus: 'completed', reason });

} catch (error: any) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -493,19 +535,28 @@ success: false,

parameters: UpdateReservationParams,
): Promise<APIReturnType & { reservation?: ReservationInstance }> {
const { attempts, taskSid, reservationSid, status } = parameters;
): Promise<ApiReturnType & { reservation?: ReservationInstance }> {
const { taskSid, reservationSid, status } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
reservationSid: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!isString(reservationSid))
throw new Error('Invalid parameters object passed. Parameters must contain reservationSid string');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<UpdateReservationParams>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
if (!isString(status) || (status != 'completed' && status != 'wrapping'))
throw new Error(
throw new PluginUtilsErrorManager(
'Invalid parameters object passed. Parameters must contain status to update the reservation to and it must be one of "completed" or "wrapping"',
HttpErrorCode.BadRequest,
);
const reservation = await this.client.taskrouter.v1
.workspaces(this.config.TWILIO_FLEX_WORKSPACE_SID)
.workspaces(this.config.flexWorkSpaceSid)
.tasks(taskSid)

@@ -521,3 +572,3 @@ .reservations(reservationSid)

} catch (error: any) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -545,3 +596,3 @@ success: false,

* @param {string} parameters.taskSid the task to update
* @param {string} parameters.attributesUpdate a JSON object to merge with the task
* @param {string} parameters.attributesUpdate a string JSON object to merge with the task
* @returns {object} an object containing the task if successful

@@ -554,10 +605,18 @@ * @description this operation safely updates the task attributes with the object

public async updateTaskAttributes(parameters: UpdateTaskAttributesParams) {
const { attempts, taskSid, attributesUpdate } = parameters;
const { taskSid, attributesUpdate } = parameters;
const parameterChecks = {
attempts: 'number',
taskSid: 'string',
attributesUpdate: 'string',
};
try {
if (!isNumber(attempts))
throw new Error('Invalid parameters object passed. Parameters must contain the number of attempts');
if (!isString(taskSid))
throw new Error('Invalid parameters object passed. Parameters must contain the taskSid string');
if (!isString(attributesUpdate))
throw new Error('Invalid parameters object passed. Parameters must contain attributesUpdate JSON string');
const inputError = PluginUtilsErrorManager.checkInvalidParameters<UpdateTaskAttributesParams>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
// we need to fetch the task using a rest API because

@@ -591,3 +650,3 @@ // we need to examine the headers to get the ETag

} catch (error) {
if (error.message?.includes('Invalid parameters object passed')) {
if (error.code === HttpErrorCode.BadRequest) {
return {

@@ -594,0 +653,0 @@ success: false,

@@ -6,3 +6,3 @@ import { TaskContextUpdateOptions, TaskInstance } from 'twilio/lib/rest/taskrouter/v1/workspace/task';

export interface TaskRouterMetaData extends PluginsUtilsMetaData {
TWILIO_FLEX_WORKSPACE_SID: string;
flexWorkSpaceSid: string;
}

@@ -9,0 +9,0 @@

@@ -1,5 +0,7 @@

import { TaskRouterUtils } from './core/TaskRouterUtils';
import { ProgrammableVoiceUtils } from './core/ProgrammableVoiceUtils';
import { PhoneNumbersUtils } from './core/PhoneNumberUtils';
import TaskRouterUtils from './core/TaskRouterUtils';
import ProgrammableVoiceUtils from './core/ProgrammableVoiceUtils';
import PhoneNumbersUtils from './core/PhoneNumberUtils';
import ConferenceUtils from './core/ConferenceUtils';
import InteractionUtils from './core/InteractionUtils';
export { TaskRouterUtils, ProgrammableVoiceUtils, PhoneNumbersUtils };
export { TaskRouterUtils, ProgrammableVoiceUtils, PhoneNumbersUtils, ConferenceUtils, InteractionUtils };
import { AxiosResponse } from 'axios';
export interface PluginsUtilsMetaData {
TWILIO_SERVICE_MAX_BACKOFF: number;
TWILIO_SERVICE_MIN_BACKOFF: number;
TWILIO_SERVICE_RETRY_LIMIT: number;
ACCOUNT_SID: string;
AUTH_TOKEN: string;
maxBackoff: number;
minBackoff: number;
retryLimit: number;
accountSid: string;
authToken: string;
}

@@ -16,3 +16,3 @@

export interface APIReturnType {
export interface ApiReturnType {
success: boolean;

@@ -32,3 +32,3 @@ status: number;

data: T;
// Add any additional properties you need here
// Add any additional properties if required
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc