diff --git a/CHANGELOG.md b/CHANGELOG.md index b32fdd7..d7cc6b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [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. 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..c04149b 100644 --- a/lib/resources/powerpacks.js +++ b/lib/resources/powerpacks.js @@ -40,6 +40,22 @@ export class CreatePowerpackResponse { } } +export class RetrievePowerpack { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.applicationId = params.applicationId; + this.applicationType = params.applicationType; + this.createdOn = params.createdOn; + this.localConnect = params.localConnect; + this.name = params.name; + this.numberPool = params.numberPool; + this.numberPriority = params.numberPriority; + this.stickySender = params.stickySender; + this.uuid = params.uuid; + } +} + export class UpdatePowerpackResponse { constructor(params) { params = params || {}; @@ -696,9 +712,32 @@ export class PowerpackInterface extends PlivoResourceInterface { * @promise {object} return {@link Powerpack} object * @fail {Error} return Error */ - get(uuid) { - return super.get(uuid); + get(uuid) { + let errors = validate([{ + field: 'uuid', + value: uuid, + validators: ['isRequired'] + }]); + + if (errors) { + return errors; + } + + let client = this[clientKey]; + return new Promise((resolve, reject) => { + if (action !== '' && !uuid) { + reject(new Error(this[idKey] + ' must be set')); + } + client('GET', action + (uuid ? uuid + '/' : '')) + .then(response => { + resolve(new RetrievePowerpack(response.body, client)); + }) + .catch(error => { + reject(error); + }); + }); } + /** * create Powerpack * @method 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/package-lock.json b/package-lock.json index 347cb92..d516358 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5591,4 +5591,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index a287d5d..a471bda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.20.1", + "version": "4.21.0", "description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML", "homepage": "https://github.com/plivo/plivo-node", "files": [ diff --git a/types/base.d.ts b/types/base.d.ts index b53c07b..337f69a 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -4,8 +4,8 @@ export class PlivoGenericResponse { } export class PlivoResource { constructor(action: string, Klass: Symbol, idField: string, request: any); - update(params: object, id: string): Promise; - 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