diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ef6033..bf298a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,17 @@ # Change Log -## [v4.21.0](https://github.com/plivo/plivo-node/tree/v4.21.0) (2021-07-20) -- This version includes advancements to the Messaging Interface that deals with the [Send SMS/MMS](https://www.plivo.com/docs/sms/api/message#send-a-message) interface, Creating a standard structure for `request/input` arguments to make implementation easier and incorporating support for the older interface. +## [v4.22.0](https://github.com/plivo/plivo-node/tree/v4.22.0) (2021-08-17) +- Fix [add numbers to a powerpack](https://www.plivo.com/docs/sms/api/numberpool/#add-a-number) API by reverting retrievable object responses support for [Retrieve a Power pack API](https://www.plivo.com/docs/sms/api/powerpack#retrieve-a-powerpack). + +## [v4.21.0](https://github.com/plivo/plivo-node/tree/v4.21.0) (2021-08-05) +- Fixed a Typescript warning about base interpretation. +- Add retrievable object responses support for [Retrieve a Power pack API](https://www.plivo.com/docs/sms/api/powerpack#retrieve-a-powerpack). + +## [v4.20.1](https://github.com/plivo/plivo-node/tree/v4.20.1) (2021-07-27) +- Updates to [add a member a multi-party call API](https://www.plivo.com/docs/voice/api/multiparty-call/participants#add-a-participant). + - Remove validation range for `delay` and `ringtimeout` parameters. + - Add appropriate error message for multiple `ringtimeout` and `delaydial` values. +- Updated default HTTP client request timeout to 5 seconds. ## [v4.20.0](https://github.com/plivo/plivo-node/tree/v4.20.0) (2021-07-13) - Power pack ID has been included to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message). diff --git a/lib/resources/multiPartyCall.js b/lib/resources/multiPartyCall.js index 0fe35c6..3fee3f8 100644 --- a/lib/resources/multiPartyCall.js +++ b/lib/resources/multiPartyCall.js @@ -106,24 +106,24 @@ export class MultiPartyCall extends PlivoResource{ if(params.ringTimeout || params.ringTimeout === 0){ validParam('ringTimeout', params.ringTimeout, [String, Number], false) - if(Number.isInteger(params.ringTimeout)){ - validRange('RingTimeout', params.ringTimeout, false, 15, 120) - } - else{ + if(typeof(params.ringTimeout) === 'string'){ validMultipleDestinationIntegers('ringTimeout', params.ringTimeout) } + else if (!Number.isInteger(params.ringTimeout) && typeof(params.ringTimeout) !== 'string'){ + throw new InvalidRequestError("RingTimeout must be of type int or string") + } } else { params.ringTimeout = 45 } if(params.delayDial){ validParam('delayDial', params.delayDial, [String, Number], false) - if(Number.isInteger(params.delayDial)){ - validRange('DelayDial', params.delayDial, false, 1, 120) - } - else{ + if(typeof(params.delayDial) === 'string'){ validMultipleDestinationIntegers('delayDial', params.delayDial) } + else if(!Number.isInteger(params.delayDial) && typeof(params.delayDial) !== 'string'){ + throw new InvalidRequestError("Dealydial must be of type int or string") + } } else { params.delayDial = 0 @@ -306,6 +306,12 @@ export class MultiPartyCall extends PlivoResource{ else { params.exitSoundMethod = 'GET' } + if(params.to && (String(params.ringTimeout).split('<').length > params.to.split('<').length)){ + throw new MPCError("RingTimeout:number of ring_timeout(s) should be same as number of destination(s)") + } + if(params.to && (String(params.delayDial).split('<').length > params.to.split('<').length)){ + throw new MPCError("DelayDial:number of delay_dial(s) should be same as number of destination(s)") + } params.isVoiceRequest = 'true'; params.callerName = params.callerName || params.from; return super.executeAction(this.id + '/Participant/', 'POST', params) diff --git a/lib/resources/numbers.js b/lib/resources/numbers.js index ccaec8b..b275123 100644 --- a/lib/resources/numbers.js +++ b/lib/resources/numbers.js @@ -1,4 +1,5 @@ import { + PlivoGenericResponse, PlivoResource, PlivoResourceInterface } from '../base'; @@ -271,7 +272,15 @@ export class NumberInterface extends PlivoResourceInterface { params.carrier = carrier; params.region = region; - return super.create(params); + return new Promise((resolve, reject) => { + client('POST', action, params) + .then(response => { + resolve(new PlivoGenericResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }) } /** diff --git a/lib/resources/powerpacks.js b/lib/resources/powerpacks.js index 9e96fed..2df1d4c 100644 --- a/lib/resources/powerpacks.js +++ b/lib/resources/powerpacks.js @@ -457,7 +457,6 @@ export class Powerpack extends PlivoResource { * @param {string} [params.sticky_sender] * @param {string} [params.local_connect] * @param {object} [params.number_priority] - * @promise {object} return {@link Powerpack} object * @fail {Error} return Error */ @@ -696,7 +695,7 @@ export class PowerpackInterface extends PlivoResourceInterface { * @promise {object} return {@link Powerpack} object * @fail {Error} return Error */ - get(uuid) { + get(uuid) { return super.get(uuid); } /** @@ -777,4 +776,4 @@ export class PowerpackInterface extends PlivoResourceInterface { list(params) { return super.list(params); } -} \ No newline at end of file +} diff --git a/lib/rest/axios.js b/lib/rest/axios.js index 5316274..ba74448 100644 --- a/lib/rest/axios.js +++ b/lib/rest/axios.js @@ -175,6 +175,9 @@ export function Axios(config) { if (typeof config.timeout !== 'undefined') { options.timeout = config.timeout; } + else if(typeof config.timeout === 'undefined'){ + options.timeout = 5000; + } return new Promise((resolve, reject) => { if (isVoiceReq) { diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index 18e1791..012a817 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -1,5 +1,5 @@ -import request from 'request'; import queryString from 'querystring'; +import request from 'request'; export function Request(config) { let auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken) @@ -1465,4 +1465,4 @@ export function Request(config) { } }); }; -} +} \ No newline at end of file diff --git a/lib/rest/request.js b/lib/rest/request.js index 94f1c72..67fd730 100644 --- a/lib/rest/request.js +++ b/lib/rest/request.js @@ -1,8 +1,9 @@ -import request from 'request'; -import queryString from 'querystring'; import * as Exceptions from '../utils/exceptions'; import * as _ from "lodash"; +import queryString from 'querystring'; +import request from 'request'; + export function Request(config) { let auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken) .toString('base64'); @@ -219,4 +220,4 @@ export function Request(config) { }); }); }; -} +} \ No newline at end of file diff --git a/lib/rest/utils.js b/lib/rest/utils.js index 8a7538c..934836c 100644 --- a/lib/rest/utils.js +++ b/lib/rest/utils.js @@ -115,17 +115,7 @@ export function validMultipleDestinationNos(paramName, paramValue, options = {}) export function validMultipleDestinationIntegers(paramName, paramValue){ let val = paramValue.split("<"); for (let i=0; i; - delete(params: object): Promise; + // update(params: any, id: any): Promise; + delete(params: any): Promise; executeAction(task: string, method: string, params: {}, action: string): Promise; customexecuteAction(url: string, method?: string, params?: {}): Promise; customexecuteGetNumberAction(url: string, method?: string, params?: {}): any; @@ -13,7 +13,7 @@ export class PlivoResource { } export class PlivoResourceInterface { constructor(action: string, Klass: Symbol, idField: string, request: any); - get(id: string, params?: {}): Promise; - list(params: object): Promise; - create(params: object): Promise; -} + // get(id: any, params?: {}): Promise; + // create(params: any): Promise; + list(params: any): Promise; +} \ No newline at end of file diff --git a/types/resources/endUsers.d.ts b/types/resources/endUsers.d.ts index fbdca55..f3efc54 100644 --- a/types/resources/endUsers.d.ts +++ b/types/resources/endUsers.d.ts @@ -29,7 +29,7 @@ export class ListEndUsersResponse { constructor(params: object); apiId: string; meta: Object; - objects: Array; + objects: Array; } /** diff --git a/types/resources/media.d.ts b/types/resources/media.d.ts index fe251e5..ca38f5f 100644 --- a/types/resources/media.d.ts +++ b/types/resources/media.d.ts @@ -42,7 +42,7 @@ export class MediaInterface extends PlivoResourceInterface { * @method * @fail {Error} return Error */ - upload(files: Array): Promise; + upload(files: Array): Promise; /** * Get Media by given id * @method diff --git a/types/resources/messages.d.ts b/types/resources/messages.d.ts index c709edc..a72264f 100644 --- a/types/resources/messages.d.ts +++ b/types/resources/messages.d.ts @@ -23,7 +23,7 @@ export class MessageGetResponse { } export class MessageListResponse { constructor(params: object); - errorCode: string; + errorCode: string; fromNumber: string; messageDirection: string; messageState: string; @@ -34,7 +34,7 @@ export class MessageListResponse { toNumber: string; totalAmount: string; totalRate: string; - units: string; + units: string; powerpackId: string; } export class MMSMediaResponse { @@ -90,7 +90,7 @@ export class MessageInterface extends PlivoResourceInterface { type: string; url: string; method: string; - media_urls: Array; + media_urls: Array; log: boolean; }): Promise < MessageResponse > ; /** diff --git a/types/resources/powerpacks.d.ts b/types/resources/powerpacks.d.ts index 1892aa3..a6d3492 100644 --- a/types/resources/powerpacks.d.ts +++ b/types/resources/powerpacks.d.ts @@ -17,6 +17,21 @@ export class CreatePowerpackResponse { stickySender: string; uuid: string; } + +export class RetrievePowerpack { + constructor(params: object); + apiId: string; + applicationId: string; + applicationType: string; + createdOn: string; + localConnect: string; + name: string; + numberPool: string; + numberPriority: object; + stickySender: string; + uuid: string; +} + export class UpdatePowerpackResponse { constructor(params: object); apiId: string; @@ -179,7 +194,7 @@ export class PowerpackInterface extends PlivoResourceInterface { * @promise {object} return {@link Powerpack} object * @fail {Error} return Error */ - get(uuid: string): any; + get(uuid: string): Promise; /** * create Powerpack * @method @@ -189,7 +204,7 @@ export class PowerpackInterface extends PlivoResourceInterface { * @param {string} [params.local_connect] * @param {string} [params.application_type] * @param {string} [params.application_id] - * @promise {object} return {@link PlivoGenericResponse} object + * @promise {object} return {@link RetrievePowerpack} object * @fail {Error} return Error */ create(name: string, params?: {}): Promise; diff --git a/types/rest/request-test.d.ts b/types/rest/request-test.d.ts index 1f56632..c2221c1 100644 --- a/types/rest/request-test.d.ts +++ b/types/rest/request-test.d.ts @@ -1 +1 @@ -export function Request(config: any): (method: string, action: string, params: object) => Promise; +export function Request(config: any): (method: string, action: string, params: object) => Promise; \ No newline at end of file diff --git a/types/rest/request.d.ts b/types/rest/request.d.ts index 1f56632..c2221c1 100644 --- a/types/rest/request.d.ts +++ b/types/rest/request.d.ts @@ -1 +1 @@ -export function Request(config: any): (method: string, action: string, params: object) => Promise; +export function Request(config: any): (method: string, action: string, params: object) => Promise; \ No newline at end of file