Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit fb531fd

Browse files
authored
Merge pull request #160 from amiller-gh/master
fix: Messaging v2 application creation endpoints. Add v2 API typescript types.
2 parents d10b5ea + 6da1529 commit fb531fd

10 files changed

Lines changed: 4244 additions & 3666 deletions

File tree

docs/api.md

Lines changed: 3978 additions & 3631 deletions
Large diffs are not rendered by default.

lib/client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ var Client = function (config) {
3838
}
3939

4040
function createRequestOptions (params) {
41-
//Added to allow the V1/V2 base url split
42-
//V1 endpoint functions remain unchanged, V2 inclues the new URL as 'apiBaseUrl' param
43-
var apiBaseUrl = params.apiBaseUrl ? params.apiBaseUrl : config.baseUrl;
41+
//Added to allow the V1/V2 base url split
42+
//V1 endpoint functions remain unchanged, V2 inclues the new URL as 'apiBaseUrl' param
43+
var apiBaseUrl = params.apiBaseUrl ? params.apiBaseUrl : config.baseUrl;
4444
var baseUrl = apiBaseUrl + (params.apiVersion ? "/" + params.apiVersion : apiVersionPath);
4545
var userPath = params.pathWithoutUser ? "" : (usersPath + "/" + config.userId);
46+
4647
return {
4748
url : baseUrl + userPath + "/" + params.path,
4849
headers : {

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var queries = require("./v2/searchAndOrderNumberQueries");
3030
* Configurable for using alternative Catapult environments.
3131
*/
3232
var CatapultClient = function (config) {
33-
var client = new Client(config);
33+
var client = new Client(config);
3434
this.Account = new Account(client);
3535
this.Media = new Media(client);
3636
this.Message = new Message(client);
@@ -44,7 +44,7 @@ var CatapultClient = function (config) {
4444
this.Recording = new Recording(client);
4545
this.Application = new Application(client);
4646
this.AvailableNumber = new AvailableNumber(client);
47-
this.PhoneNumber = new PhoneNumber(client);
47+
this.PhoneNumber = new PhoneNumber(client);
4848
this.v2 = {
4949
Message : new MessageV2(client)
5050
};

lib/v2/message.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function findFirstDescendant(obj, name){
6363
var Message = function (client) {
6464
this._createIrisRequestOptions = function (params) {
6565
var auth = params.auth;
66-
var baseUrl = "https://dashboard.bandwidth.com/v1.0";
66+
var baseUrl = "https://dashboard.bandwidth.com";
6767
var accountPath = "/api/accounts/" + auth.accountId;
6868
var xml = null;
6969
var headers = {
@@ -134,7 +134,7 @@ var Message = function (client) {
134134
"Application": {
135135
"AppName": {_text: data.name},
136136
"CallbackUrl": {_text: data.callbackUrl},
137-
"CallBackCreds": data.callbackAuthData ? {
137+
"CallbackCreds": data.callbackAuthData ? {
138138
"UserId": {_text: data.callbackAuthData.userName},
139139
"Password": {_text: data.callbackAuthData.password}
140140
} : null
@@ -184,7 +184,7 @@ var Message = function (client) {
184184
"Zone5": {_text: false}
185185
},
186186
"HttpSettings": {
187-
"ProxyPeerId": {_text: "539692"}
187+
// "ProxyPeerId": {_text: "539692"}
188188
}
189189
}
190190
}
@@ -202,12 +202,12 @@ var Message = function (client) {
202202
body: {
203203
"MmsFeature": {
204204
"MmsSettings": {
205-
"protocol": {_text: "HTTP"}
205+
"Protocol": {_text: "HTTP"}
206206
},
207207
"Protocols": {
208208
"HTTP": {
209209
"HttpSettings": {
210-
"ProxyPeerId": {_text: "539692"}
210+
// "ProxyPeerId": {_text: "539692"}
211211
}
212212
}
213213
}
@@ -219,7 +219,7 @@ var Message = function (client) {
219219
this._assignApplicationToLocation = function (auth, application) {
220220
return this._makeIrisRequest({
221221
path : "sites/" + auth.subaccountId + "/sippeers/" + application.locationId + "/products/messaging/applicationSettings",
222-
method : "POST",
222+
method : "PUT",
223223
auth : auth,
224224
body: {
225225
"ApplicationsSettings": {
@@ -286,7 +286,7 @@ var Message = function (client) {
286286
* @returns {Array} Array of reserved phone number
287287
*
288288
* @example
289-
* client.v2.Message.searchAndOrderNumbers(authData, new client.AreaCodeSearchAndOrderNumbersQuery({areaCode: "910", quantity: 3})).then(function (numbers) {});
289+
* client.v2.Message.searchAndOrderNumbers(authData, app, new client.AreaCodeSearchAndOrderNumbersQuery({areaCode: "910", quantity: 3})).then(function (numbers) {});
290290
*/
291291
this.searchAndOrderNumbers = function (auth, app, query, callback) {
292292
var self = this;
@@ -372,7 +372,7 @@ var Message = function (client) {
372372
*/
373373
this.send = function (params, callback) {
374374
return client.makeRequest({
375-
apiBaseUrl : "https://messaging.bandwidth.com/api",
375+
apiBaseUrl : "https://messaging.bandwidth.com/api",
376376
apiVersion : "v2",
377377
path : "messages",
378378
method : "POST",

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "node-bandwidth",
3-
"version": "3.0.3",
3+
"version": "4.0.0",
44
"description": "NodeJS Client library for Bandwidth API",
55
"main": "index.js",
6+
"types": "types/index.d.ts",
67
"scripts": {
78
"test": "cross-env NODE_ENV=test gulp",
89
"docs": "./node_modules/.bin/jsdoc --configure conf.json"

test/message-v2-test.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("Message v2 API", function () {
2727
method : "DELETE"
2828
});
2929
options.should.containDeep({
30-
url : "https://dashboard.bandwidth.com/v1.0/api/accounts/id/test",
30+
url : "https://dashboard.bandwidth.com/api/accounts/id/test",
3131
headers : {
3232
"User-Agent" : "agent",
3333
"Content-Type" : "application/xml"
@@ -62,7 +62,7 @@ describe("Message v2 API", function () {
6262
body : templates.irisError1,
6363
statusCode : 200
6464
});
65-
}, "Code: Description");
65+
}, "Fails with Code: Description");
6666
});
6767
it("should handle iris error 2", function () {
6868
var message = new Message({});
@@ -71,7 +71,7 @@ describe("Message v2 API", function () {
7171
body : templates.irisError2,
7272
statusCode : 200
7373
});
74-
}, "Code: Description");
74+
}, "Fails with Code: Description");
7575
});
7676
it("should handle iris error 3", function () {
7777
var message = new Message({});
@@ -80,7 +80,7 @@ describe("Message v2 API", function () {
8080
body : templates.irisError3,
8181
statusCode : 200
8282
});
83-
}, "Code: Description");
83+
}, "Fails with Code: Description");
8484
});
8585
it("should handle iris error 4", function () {
8686
var message = new Message({});
@@ -89,7 +89,7 @@ describe("Message v2 API", function () {
8989
body : templates.irisError4,
9090
statusCode : 200
9191
});
92-
}, "Code: Description");
92+
}, "Fails with Code: Description");
9393
});
9494
it("should handle iris undefined error", function () {
9595
var message = new Message({});
@@ -98,15 +98,15 @@ describe("Message v2 API", function () {
9898
body : "",
9999
statusCode : 400
100100
});
101-
}, "Http code 400");
101+
}, "WerHttp code 400");
102102
});
103103
});
104104
describe("makeIrisRequest()", function () {
105105
before(function () {
106106
nock.disableNetConnect();
107107
nock("https://dashboard.bandwidth.com")
108108
.persist()
109-
.get("/v1.0/api/accounts/id/test")
109+
.get("/api/accounts/id/test")
110110
.reply(200, "<Test>test</Test>", {});
111111
});
112112

@@ -138,7 +138,7 @@ describe("Message v2 API", function () {
138138
nock.disableNetConnect();
139139
nock("https://dashboard.bandwidth.com")
140140
.persist()
141-
.post("/v1.0/api/accounts/id/applications", templates.createApplicationRequest)
141+
.post("/api/accounts/id/applications", templates.createApplicationRequest)
142142
.reply(200, templates.createApplicationResponse, {});
143143
});
144144

@@ -170,7 +170,7 @@ describe("Message v2 API", function () {
170170
nock.disableNetConnect();
171171
nock("https://dashboard.bandwidth.com")
172172
.persist()
173-
.post("/v1.0/api/accounts/id/sites/sub/sippeers", templates.createLocationRequest)
173+
.post("/api/accounts/id/sites/sub/sippeers", templates.createLocationRequest)
174174
.reply(201, "", { "Location" : "http://host/LocationId" });
175175
});
176176

@@ -198,12 +198,13 @@ describe("Message v2 API", function () {
198198
}, done);
199199
});
200200
});
201+
201202
describe("enableSms()", function () {
202203
before(function () {
203204
nock.disableNetConnect();
204205
nock("https://dashboard.bandwidth.com")
205206
.persist()
206-
.post("/v1.0/api/accounts/id/sites/sub/sippeers/locationId/products/messaging/features/sms",
207+
.post("/api/accounts/id/sites/sub/sippeers/locationId/products/messaging/features/sms",
207208
templates.enableSmsRequest)
208209
.reply(200, "", {});
209210
});
@@ -238,7 +239,7 @@ describe("Message v2 API", function () {
238239
nock.disableNetConnect();
239240
nock("https://dashboard.bandwidth.com")
240241
.persist()
241-
.post("/v1.0/api/accounts/id/sites/sub/sippeers/locationId/products/messaging/features/mms",
242+
.post("/api/accounts/id/sites/sub/sippeers/locationId/products/messaging/features/mms",
242243
templates.enableMmsRequest)
243244
.reply(200, "", {});
244245
});
@@ -267,12 +268,13 @@ describe("Message v2 API", function () {
267268
}, done);
268269
});
269270
});
271+
270272
describe("assignApplicationToLocation()", function () {
271273
before(function () {
272274
nock.disableNetConnect();
273275
nock("https://dashboard.bandwidth.com")
274276
.persist()
275-
.post("/v1.0/api/accounts/id/sites/sub/sippeers/locationId/products/messaging/applicationSettings",
277+
.put("/api/accounts/id/sites/sub/sippeers/locationId/products/messaging/applicationSettings",
276278
templates.assignApplicationToLocationRequest)
277279
.reply(200, "", {});
278280
});
@@ -352,10 +354,10 @@ describe("Message v2 API", function () {
352354
nock.disableNetConnect();
353355
nock("https://dashboard.bandwidth.com")
354356
.persist()
355-
.post("/v1.0/api/accounts/id/orders",
357+
.post("/api/accounts/id/orders",
356358
templates.createOrderRequest)
357359
.reply(200, templates.createOrderResponse, {})
358-
.get("/v1.0/api/accounts/id/orders/OrderId")
360+
.get("/api/accounts/id/orders/OrderId")
359361
.reply(200, templates.orderResponseSuccess);
360362
});
361363
after(function () {
@@ -400,10 +402,10 @@ describe("Message v2 API", function () {
400402
nock.disableNetConnect();
401403
nock("https://dashboard.bandwidth.com")
402404
.persist()
403-
.post("/v1.0/api/accounts/id/orders",
405+
.post("/api/accounts/id/orders",
404406
templates.createOrderRequest)
405407
.reply(200, templates.createOrderResponse, {})
406-
.get("/v1.0/api/accounts/id/orders/OrderId")
408+
.get("/api/accounts/id/orders/OrderId")
407409
.reply(200, templates.orderResponseFail);
408410
});
409411
after(function () {
@@ -450,10 +452,10 @@ describe("Message v2 API", function () {
450452
nock.disableNetConnect();
451453
nock("https://dashboard.bandwidth.com")
452454
.persist()
453-
.post("/v1.0/api/accounts/id/orders",
455+
.post("/api/accounts/id/orders",
454456
templates.createOrderRequest)
455457
.reply(200, templates.createOrderResponse, {})
456-
.get("/v1.0/api/accounts/id/orders/OrderId")
458+
.get("/api/accounts/id/orders/OrderId")
457459
.reply(200, templates.orderResponseWait);
458460
});
459461
after(function () {

test/templates.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"irisError2": "<Response><Error><Code>Code</Code><Description>Description</Description></Error></Response>",
44
"irisError3": "<Response><Errors><Code>Code</Code><Description>Description</Description></Errors></Response>",
55
"irisError4": "<Response><resultCode>Code</resultCode><resultMessage>Description</resultMessage></Response>",
6-
"createApplicationRequest": "<Application><AppName>App1</AppName><CallbackUrl>url</CallbackUrl><CallBackCreds/></Application>",
6+
"createApplicationRequest": "<Application><AppName>App1</AppName><CallbackUrl>url</CallbackUrl><CallbackCreds/></Application>",
77
"createApplicationResponse": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse><Application><ApplicationId>ApplicationId</ApplicationId><ServiceType>Messaging-V2</ServiceType><AppName>Demo Server</AppName><CallbackUrl>https://requestb.in/1m009f61</CallbackUrl><CallbackCreds /></Application></ApplicationProvisioningResponse>",
88
"createLocationRequest": "<SipPeer><PeerName>Location1</PeerName><IsDefaultPeer>false</IsDefaultPeer></SipPeer>",
9-
"enableSmsRequest": "<SipPeerSmsFeature><SipPeerSmsFeatureSettings><TollFree>true</TollFree><ShortCode>false</ShortCode><Protocol>HTTP</Protocol><Zone1>true</Zone1><Zone2>false</Zone2><Zone3>false</Zone3><Zone4>false</Zone4><Zone5>false</Zone5></SipPeerSmsFeatureSettings><HttpSettings><ProxyPeerId>539692</ProxyPeerId></HttpSettings></SipPeerSmsFeature>",
10-
"enableMmsRequest": "<MmsFeature><MmsSettings><protocol>HTTP</protocol></MmsSettings><Protocols><HTTP><HttpSettings><ProxyPeerId>539692</ProxyPeerId></HttpSettings></HTTP></Protocols></MmsFeature>",
9+
"enableSmsRequest": "<SipPeerSmsFeature><SipPeerSmsFeatureSettings><TollFree>true</TollFree><ShortCode>false</ShortCode><Protocol>HTTP</Protocol><Zone1>true</Zone1><Zone2>false</Zone2><Zone3>false</Zone3><Zone4>false</Zone4><Zone5>false</Zone5></SipPeerSmsFeatureSettings><HttpSettings/></SipPeerSmsFeature>",
10+
"enableMmsRequest": "<MmsFeature><MmsSettings><Protocol>HTTP</Protocol></MmsSettings><Protocols><HTTP><HttpSettings/></HTTP></Protocols></MmsFeature>",
1111
"assignApplicationToLocationRequest": "<ApplicationsSettings><HttpMessagingV2AppId>applicationId</HttpMessagingV2AppId></ApplicationsSettings>",
1212
"createOrderRequest": "<Order><OrderType><Quantity>1</Quantity></OrderType><SiteId>sub</SiteId><PeerId>locationId</PeerId></Order>",
1313
"createOrderResponse": "<OrderResponse><Order><OrderCreateDate>2017-09-18T17:36:57.274Z</OrderCreateDate><PeerId>{{location}}</PeerId><BackOrderRequested>false</BackOrderRequested><id>OrderId</id><AreaCodeSearchAndOrderType><AreaCode>910</AreaCode><Quantity>1</Quantity></AreaCodeSearchAndOrderType><PartialAllowed>true</PartialAllowed><SiteId>{{subaccount}}</SiteId></Order><OrderStatus>RECEIVED</OrderStatus></OrderResponse>",

types/index.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { V2MessageAPI } from './v2';
2+
import {
3+
AreaCodeSearchAndOrderNumbersQuery,
4+
RateCenterSearchAndOrderNumbersQuery,
5+
NpaNxxSearchAndOrderNumbersQuery,
6+
TollFreeVanitySearchAndOrderNumbersQuery,
7+
TollFreeWildCharSearchAndOrderNumbersQuery,
8+
StateSearchAndOrderNumbersQuery,
9+
CitySearchAndOrderNumbersQuery,
10+
ZipSearchAndOrderNumbersQuery,
11+
LataSearchAndOrderNumbersQuery,
12+
CombinedSearchAndOrderNumbersQuery,
13+
} from './v2/searchAndOrderNumberQueries';
14+
15+
export interface BandwidthOptions {
16+
userId : string;
17+
apiToken : string;
18+
apiSecret: string;
19+
baseUrl?: string;
20+
}
21+
22+
export interface v2 {
23+
Message: V2MessageAPI;
24+
}
25+
26+
export default class Bandwidth {
27+
constructor(options: BandwidthOptions);
28+
public v2: v2;
29+
public static AreaCodeSearchAndOrderNumbersQuery: typeof AreaCodeSearchAndOrderNumbersQuery;
30+
public static RateCenterSearchAndOrderNumbersQuery: typeof RateCenterSearchAndOrderNumbersQuery;
31+
public static NpaNxxSearchAndOrderNumbersQuery: typeof NpaNxxSearchAndOrderNumbersQuery;
32+
public static TollFreeVanitySearchAndOrderNumbersQuery: typeof TollFreeVanitySearchAndOrderNumbersQuery;
33+
public static TollFreeWildCharSearchAndOrderNumbersQuery: typeof TollFreeWildCharSearchAndOrderNumbersQuery;
34+
public static StateSearchAndOrderNumbersQuery: typeof StateSearchAndOrderNumbersQuery;
35+
public static CitySearchAndOrderNumbersQuery: typeof CitySearchAndOrderNumbersQuery;
36+
public static ZipSearchAndOrderNumbersQuery: typeof ZipSearchAndOrderNumbersQuery;
37+
public static LataSearchAndOrderNumbersQuery: typeof LataSearchAndOrderNumbersQuery;
38+
public static CombinedSearchAndOrderNumbersQuery: typeof CombinedSearchAndOrderNumbersQuery;
39+
}

0 commit comments

Comments
 (0)