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 1.1.1 to 1.1.2-beta.0

dist/core/ProgrammableVoiceUtils/Api.d.ts

1

dist/common/utils.d.ts
export declare const getEnvSpecificUrl: (url: string, region: string) => string;
export declare const getEnvSpecificRecordingUrl: (url: string, region: string, accountSid: string) => string;

4

dist/common/utils.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnvSpecificUrl = void 0;
exports.getEnvSpecificRecordingUrl = exports.getEnvSpecificUrl = void 0;
const getEnvSpecificUrl = (url, region) => (region ? url.replace('*', region) : url.replace('.*', ''));
exports.getEnvSpecificUrl = getEnvSpecificUrl;
const getEnvSpecificRecordingUrl = (url, region, accountSid) => (region ? url.replace('*', region).replace('ACCOUNT_SID', accountSid) : url.replace('.*', '').replace('ACCOUNT_SID', accountSid));
exports.getEnvSpecificRecordingUrl = getEnvSpecificRecordingUrl;
//# sourceMappingURL=utils.js.map
export declare const TwilioApis: {
TaskRouter: string;
Recording: string;
};

@@ -4,0 +5,0 @@ export declare const enum HTTP_METHODS {

@@ -7,3 +7,4 @@ "use strict";

TaskRouter: 'https://taskrouter.*.twilio.com/v1/Workspaces/',
Recording: 'https://api.*.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Recordings/'
};
//# sourceMappingURL=api.js.map

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

import { CallInstance } from 'twilio/lib/rest/api/v2010/account/call';
import { RecordingInstance, RecordingListInstanceCreateOptions } from 'twilio/lib/rest/api/v2010/account/call/recording';
import { QueueInstance } from 'twilio/lib/rest/api/v2010/account/queue';
import { RecordingInstance as CallRecordingInstance, RecordingListInstanceCreateOptions } from 'twilio/lib/rest/api/v2010/account/call/recording';
import { RecordingInstance } from 'twilio/lib/rest/api/v2010/account/recording';
import { OutgoingCallerIdInstance } from 'twilio/lib/rest/api/v2010/account/outgoingCallerId';
import { RecordingInstance as ConferenceRecordingInstance } from 'twilio/lib/rest/api/v2010/account/conference/recording';
import { updateCallRecordingParams, updateConferenceRecording } from './types';
import { fetchRecording, fetchVoiceQueue, updateCall, updateCallRecordingParams, updateConferenceRecording } from './types';
import { PluginUtils } from '../../common/BaseClasses/PluginUtils';
export default class ProgrammableVoiceUtils extends PluginUtils {
private config;
private api;
/**

@@ -55,3 +59,3 @@ * Utility class for Twilio's Programmable Voice resources

}): Promise<ApiReturnType & {
recording?: RecordingInstance;
recording?: CallRecordingInstance;
}>;

@@ -67,3 +71,3 @@ /**

updateCallRecording(parameters: updateCallRecordingParams): Promise<ApiReturnType & {
recording?: RecordingInstance;
recording?: CallRecordingInstance;
}>;

@@ -81,2 +85,52 @@ /**

}>;
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.callSid the unique call SID to update
* @param {object} parameters.params recording update parameters
* @returns {Map} The call's properties
* @description updates the given call
*/
updateCall(parameters: updateCall): Promise<ApiReturnType & {
call?: CallInstance;
}>;
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.queueSid the unique queue SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given queue's properties
* @description fetches the given queue SID's properties
*/
fetchVoiceQueue(parameters: fetchVoiceQueue): Promise<ApiReturnType & {
queueProperties?: QueueInstance;
}>;
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.recordingSid the unique recording SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given recording's properties
* @description fetches the given recording SID's properties
*/
fetchRecording(parameters: fetchRecording): Promise<ApiReturnType & {
recordingProperties?: RecordingInstance;
}>;
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.recordingSid the unique recording SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given recording's properties
* @description fetches the given recording SID's properties
*/
fetchRecordingMedia(parameters: fetchRecording): Promise<ApiReturnType & {
recording?: any;
type?: string;
}>;
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @returns {Array<PhoneNumber>} An array of outbound caller ids for the account
* @description the following method is used to robustly retrieve
* the outbound caller ids for the account
*/
listOutgoingCallerIds(parameters: Parameters): Promise<ApiReturnType & {
callerIds?: Array<OutgoingCallerIdInstance>;
}>;
}

@@ -11,2 +11,5 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,2 +20,3 @@ const retryHandler_1 = require("../../common/retryHandler");

const PluginUtilsErrorManager_1 = require("../../common/PluginUtilsErrorManager");
const Api_1 = __importDefault(require("./Api"));
class ProgrammableVoiceUtils extends PluginUtils_1.PluginUtils {

@@ -31,2 +35,4 @@ /**

this.config = config;
const { accountSid, authToken, region } = config;
this.api = new Api_1.default(accountSid, authToken, region);
}

@@ -212,4 +218,174 @@ /**

}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.callSid the unique call SID to update
* @param {object} parameters.params recording update parameters
* @returns {Map} The call's properties
* @description updates the given call
*/
updateCall(parameters) {
return __awaiter(this, void 0, void 0, function* () {
const { callSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
params: 'object',
};
try {
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const call = yield this.client.calls(callSid).update(params);
return { success: true, call, status: statusCodes_1.HttpErrorCode.OK };
}
catch (error) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {
success: false,
status: statusCodes_1.HttpErrorCode.BadRequest,
message: error.message,
};
}
return (0, retryHandler_1.retryHandler)(this.config, error, parameters, this.updateCall);
}
});
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.queueSid the unique queue SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given queue's properties
* @description fetches the given queue SID's properties
*/
fetchVoiceQueue(parameters) {
return __awaiter(this, void 0, void 0, function* () {
const { queueSid } = parameters;
const parameterChecks = {
attempts: 'number',
queueSid: 'string',
};
try {
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const queueProperties = yield this.client.queues(queueSid).fetch();
return { success: true, queueProperties, status: statusCodes_1.HttpErrorCode.OK };
}
catch (error) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {
success: false,
status: statusCodes_1.HttpErrorCode.BadRequest,
message: error.message,
};
}
return (0, retryHandler_1.retryHandler)(this.config, error, parameters, this.fetchVoiceQueue);
}
});
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.recordingSid the unique recording SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given recording's properties
* @description fetches the given recording SID's properties
*/
fetchRecording(parameters) {
return __awaiter(this, void 0, void 0, function* () {
const { recordingSid } = parameters;
const parameterChecks = {
attempts: 'number',
recordingSid: 'string',
};
try {
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const recordingProperties = yield this.client.recordings(recordingSid).fetch();
return { success: true, recordingProperties, status: statusCodes_1.HttpErrorCode.OK };
}
catch (error) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {
success: false,
status: statusCodes_1.HttpErrorCode.BadRequest,
message: error.message,
};
}
return (0, retryHandler_1.retryHandler)(this.config, error, parameters, this.fetchRecording);
}
});
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.recordingSid the unique recording SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given recording's properties
* @description fetches the given recording SID's properties
*/
fetchRecordingMedia(parameters) {
return __awaiter(this, void 0, void 0, function* () {
const { recordingSid } = parameters;
const parameterChecks = {
attempts: 'number',
recordingSid: 'string',
};
try {
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const { data, headers: responseHeaders } = yield this.api.getRecordingMedia(recordingSid);
const recording = data.toString('base64');
const type = responseHeaders['content-type'];
return { success: true, recording, type, status: statusCodes_1.HttpErrorCode.OK };
}
catch (error) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {
success: false,
status: statusCodes_1.HttpErrorCode.BadRequest,
message: error.message,
};
}
return (0, retryHandler_1.retryHandler)(this.config, error, parameters, this.fetchRecordingMedia);
}
});
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @returns {Array<PhoneNumber>} An array of outbound caller ids for the account
* @description the following method is used to robustly retrieve
* the outbound caller ids for the account
*/
listOutgoingCallerIds(parameters) {
return __awaiter(this, void 0, void 0, function* () {
const parameterChecks = {
attempts: 'number',
};
try {
const inputError = PluginUtilsErrorManager_1.PluginUtilsErrorManager.checkInvalidParameters(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager_1.PluginUtilsErrorManager(inputError, statusCodes_1.HttpErrorCode.BadRequest);
}
const callerIds = yield this.client.outgoingCallerIds.list({});
return { success: true, callerIds, status: statusCodes_1.HttpErrorCode.OK };
}
catch (error) {
if (error.code === statusCodes_1.HttpErrorCode.BadRequest) {
return {
success: false,
status: statusCodes_1.HttpErrorCode.BadRequest,
message: error.message,
};
}
return (0, retryHandler_1.retryHandler)(this.config, error, parameters, this.fetchRecording);
}
});
}
}
exports.default = ProgrammableVoiceUtils;
//# sourceMappingURL=index.js.map
import { RecordingContextUpdateOptions } from 'twilio/lib/rest/api/v2010/account/call/recording';
import { CallContextUpdateOptions } from 'twilio/lib/rest/api/v2010/account/call';
import { Parameters } from '../../types';

@@ -13,1 +14,11 @@ export interface updateCallRecordingParams extends Parameters {

}
export interface updateCall extends Parameters {
callSid: string;
params: CallContextUpdateOptions;
}
export interface fetchVoiceQueue extends Parameters {
queueSid: string;
}
export interface fetchRecording extends Parameters {
recordingSid: string;
}
{
"name": "@twilio/flex-plugins-library-utils",
"version": "1.1.1",
"version": "1.1.2-beta.0",
"description": "Flex Plugins Library Utils",

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

export const getEnvSpecificUrl = (url: string, region: string) => (region ? url.replace('*', region) : url.replace('.*', ''));
export const getEnvSpecificRecordingUrl = (url: string, region: string, accountSid: string) => (region ? url.replace('*', region).replace('ACCOUNT_SID', accountSid) : url.replace('.*', '').replace('ACCOUNT_SID', accountSid));
// add new APIs here
export const TwilioApis = {
TaskRouter: 'https://taskrouter.*.twilio.com/v1/Workspaces/',
Recording: 'https://api.*.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Recordings/'
};

@@ -5,0 +6,0 @@

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

import { CallInstance } from 'twilio/lib/rest/api/v2010/account/call';
import { QueueInstance } from 'twilio/lib/rest/api/v2010/account/queue';
import {
RecordingInstance,
RecordingInstance as CallRecordingInstance,
RecordingListInstanceCreateOptions,
} from 'twilio/lib/rest/api/v2010/account/call/recording';
import {
RecordingInstance,
} from 'twilio/lib/rest/api/v2010/account/recording';
import { OutgoingCallerIdInstance } from 'twilio/lib/rest/api/v2010/account/outgoingCallerId';
import { RecordingInstance as ConferenceRecordingInstance } from 'twilio/lib/rest/api/v2010/account/conference/recording';
import { updateCallRecordingParams, updateConferenceRecording } from './types';
import { fetchRecording, fetchVoiceQueue, updateCall, updateCallRecordingParams, updateConferenceRecording } from './types';
import { PluginUtils } from '../../common/BaseClasses/PluginUtils';

@@ -18,5 +23,7 @@ import { HttpErrorCode } from '../../constants/statusCodes';

import { PluginUtilsErrorManager } from '../../common/PluginUtilsErrorManager';
import TwilioRecordingAPI from './Api';
export default class ProgrammableVoiceUtils extends PluginUtils {
private config: PluginsUtilsMetaData;
private api: TwilioRecordingAPI;

@@ -35,2 +42,4 @@ /**

this.config = config;
const { accountSid, authToken, region } = config;
this.api = new TwilioRecordingAPI(accountSid, authToken, region);
}

@@ -134,3 +143,3 @@

parameters: Parameters & { callSid: string; params: RecordingListInstanceCreateOptions },
): Promise<ApiReturnType & { recording?: RecordingInstance }> {
): Promise<ApiReturnType & { recording?: CallRecordingInstance }> {
const { callSid, params } = parameters;

@@ -182,3 +191,3 @@ const parameterChecks = {

parameters: updateCallRecordingParams,
): Promise<ApiReturnType & { recording?: RecordingInstance }> {
): Promise<ApiReturnType & { recording?: CallRecordingInstance }> {
const { callSid, recordingSid, params } = parameters;

@@ -260,2 +269,207 @@

}
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.callSid the unique call SID to update
* @param {object} parameters.params recording update parameters
* @returns {Map} The call's properties
* @description updates the given call
*/
public async updateCall(
parameters: updateCall,
): Promise<ApiReturnType & { call?: CallInstance }> {
const { callSid, params } = parameters;
const parameterChecks = {
attempts: 'number',
callSid: 'string',
params: 'object',
};
try {
const inputError = PluginUtilsErrorManager.checkInvalidParameters<updateCall>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const call = await this.client.calls(callSid).update(params);
return { success: true, call, status: HttpErrorCode.OK };
} catch (error) {
if (error.code === HttpErrorCode.BadRequest) {
return {
success: false,
status: HttpErrorCode.BadRequest,
message: error.message,
};
}
return retryHandler<updateCall>(this.config, error, parameters, this.updateCall);
}
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.queueSid the unique queue SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given queue's properties
* @description fetches the given queue SID's properties
*/
public async fetchVoiceQueue(
parameters: fetchVoiceQueue,
): Promise<ApiReturnType & { queueProperties?: QueueInstance }> {
const { queueSid } = parameters;
const parameterChecks = {
attempts: 'number',
queueSid: 'string',
};
try {
const inputError = PluginUtilsErrorManager.checkInvalidParameters<fetchVoiceQueue>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const queueProperties = await this.client.queues(queueSid).fetch();
return { success: true, queueProperties, status: HttpErrorCode.OK };
} catch (error) {
if (error.code === HttpErrorCode.BadRequest) {
return {
success: false,
status: HttpErrorCode.BadRequest,
message: error.message,
};
}
return retryHandler<fetchVoiceQueue>(this.config, error, parameters, this.fetchVoiceQueue);
}
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.recordingSid the unique recording SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given recording's properties
* @description fetches the given recording SID's properties
*/
public async fetchRecording(
parameters: fetchRecording,
): Promise<ApiReturnType & { recordingProperties?: RecordingInstance }> {
const { recordingSid } = parameters;
const parameterChecks = {
attempts: 'number',
recordingSid: 'string',
};
try {
const inputError = PluginUtilsErrorManager.checkInvalidParameters<fetchRecording>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const recordingProperties = await this.client.recordings(recordingSid).fetch();
return { success: true, recordingProperties, status: HttpErrorCode.OK };
} catch (error) {
if (error.code === HttpErrorCode.BadRequest) {
return {
success: false,
status: HttpErrorCode.BadRequest,
message: error.message,
};
}
return retryHandler<fetchRecording>(this.config, error, parameters, this.fetchRecording);
}
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @param {string} parameters.recordingSid the unique recording SID to fetch
* @param {object} parameters.params recording update parameters
* @returns {Map} The given recording's properties
* @description fetches the given recording SID's properties
*/
public async fetchRecordingMedia(
parameters: fetchRecording,
): Promise<ApiReturnType & { recording?: any , type?: string}> {
const { recordingSid } = parameters;
const parameterChecks = {
attempts: 'number',
recordingSid: 'string',
};
try {
const inputError = PluginUtilsErrorManager.checkInvalidParameters<fetchRecording>(
parameters,
parameterChecks,
);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const { data, headers: responseHeaders } = await this.api.getRecordingMedia(recordingSid);
const recording = data.toString('base64');
const type = responseHeaders['content-type'];
return { success: true, recording, type, status: HttpErrorCode.OK };
} catch (error) {
if (error.code === HttpErrorCode.BadRequest) {
return {
success: false,
status: HttpErrorCode.BadRequest,
message: error.message,
};
}
return retryHandler<fetchRecording>(this.config, error, parameters, this.fetchRecordingMedia);
}
}
/**
* @param {number} parameters.attempts the number of retry attempts performed
* @returns {Array<PhoneNumber>} An array of outbound caller ids for the account
* @description the following method is used to robustly retrieve
* the outbound caller ids for the account
*/
public async listOutgoingCallerIds(
parameters: Parameters,
): Promise<ApiReturnType & { callerIds?: Array<OutgoingCallerIdInstance> }> {
const parameterChecks = {
attempts: 'number',
};
try {
const inputError = PluginUtilsErrorManager.checkInvalidParameters<Parameters>(parameters, parameterChecks);
if (inputError) {
throw new PluginUtilsErrorManager(inputError, HttpErrorCode.BadRequest);
}
const callerIds = await this.client.outgoingCallerIds.list({
});
return { success: true, callerIds, status: HttpErrorCode.OK };
} catch (error) {
if (error.code === HttpErrorCode.BadRequest) {
return {
success: false,
status: HttpErrorCode.BadRequest,
message: error.message,
};
}
return retryHandler(this.config, error, parameters, this.fetchRecording);
}
}
}
import { RecordingContextUpdateOptions } from 'twilio/lib/rest/api/v2010/account/call/recording';
import { CallContextUpdateOptions } from 'twilio/lib/rest/api/v2010/account/call';
import { Parameters } from '../../types';

@@ -15,1 +16,15 @@

}
export interface updateCall extends Parameters {
callSid: string;
params: CallContextUpdateOptions;
}
export interface fetchVoiceQueue extends Parameters {
queueSid: string;
}
export interface fetchRecording extends Parameters {
recordingSid: string;
}

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