Skip to content

Commit a5f8948

Browse files
committed
v0.4.1 of the library. Now returns es6 promises
1 parent c4512ed commit a5f8948

36 files changed

+973
-315
lines changed

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apigee-edge-js-examples",
3-
"version": "0.3.15",
3+
"version": "0.4.1",
44
"description": "Examples for using the Apigee Edge nodeJS library",
55
"main": "importAndDeploy.js",
66
"scripts": {

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
// limitations under the License.
1919
//
2020
// created: Thu Mar 23 14:34:12 2017
21-
// last saved: <2017-December-08 13:12:55>
21+
// last saved: <2018-December-03 08:52:25>
2222

23-
var edge = require('./lib/edge.js'),
24-
utility = require('./lib/utility.js');
23+
const Edge = require('./lib/edge.js');
2524

2625
module.exports = {
27-
edge : edge,
28-
utility : utility
26+
edge : new Edge(),
27+
utility : require('./lib/utility.js')
2928
};

lib/apiproduct.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
(function (){
1919
'use strict';
20-
const utility = require('./utility.js'),
21-
common = require('./common.js'),
22-
request = require('request'),
23-
path = require('path'),
24-
merge = require('merge'),
25-
urljoin = require('url-join'),
26-
sprintf = require('sprintf-js').sprintf;
20+
const utility = require('./utility.js'),
21+
common = require('./common.js'),
22+
promiseWrap = require('./promiseWrap.js'),
23+
request = require('request'),
24+
path = require('path'),
25+
merge = require('merge'),
26+
urljoin = require('url-join'),
27+
sprintf = require('sprintf-js').sprintf;
2728

2829
function ApiProduct(conn) { this.conn = conn; }
2930

30-
ApiProduct.prototype.create = function(options, cb) {
31+
ApiProduct.prototype.create = promiseWrap(function(options, cb) {
3132
// POST :mgmtserver/v1/o/:orgname/apiproducts/:product
3233
// Content-Type: application/json
3334
// Authorization: :edge-auth
@@ -91,9 +92,9 @@
9192
// request.debug = true;
9293
request.post(requestOptions, common.callback(conn, [201], cb));
9394
});
94-
};
95+
});
9596

96-
ApiProduct.prototype.get = function(options, cb) {
97+
ApiProduct.prototype.get = promiseWrap(function(options, cb) {
9798
// GET :mgmtserver/v1/o/:orgname/apiproducts
9899
// or
99100
// GET :mgmtserver/v1/o/:orgname/apiproducts/NAME_OF_PRODUCT
@@ -108,9 +109,9 @@
108109
}
109110
request.get(requestOptions, common.callback(conn, [200], cb));
110111
});
111-
};
112+
});
112113

113-
ApiProduct.prototype.update = function(options, cb) {
114+
ApiProduct.prototype.update = promiseWrap(function(options, cb) {
114115
// POST :mgmtserver/v1/o/:orgname/apiproducts/NAME_OF_PRODUCT
115116
var name = options.productName || options.name;
116117
if ( ! name ) {
@@ -131,9 +132,9 @@
131132
}
132133
request.post(requestOptions, common.callback(conn, [200], cb));
133134
});
134-
};
135+
});
135136

136-
ApiProduct.prototype.del = function(options, cb) {
137+
ApiProduct.prototype.del = promiseWrap(function(options, cb) {
137138
// DELETE :mgmtserver/v1/o/:orgname/apiproducts/:apiproductname
138139
// Authorization: :edge-auth
139140
var conn = this.conn;
@@ -151,7 +152,7 @@
151152
}
152153
request.del(requestOptions, common.callback(conn, [200], cb));
153154
});
154-
};
155+
});
155156

156157
module.exports = ApiProduct;
157158

lib/apiproxy.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,55 @@
1818
(function (){
1919
'use strict';
2020
const utility = require('./utility.js'),
21-
path = require('path'),
2221
common = require('./common.js'),
2322
deployableAsset = require('./deployableAsset.js'),
23+
promiseWrap = require('./promiseWrap.js'),
24+
path = require('path'),
2425
request = require('request'),
2526
urljoin = require('url-join'),
2627
sprintf = require('sprintf-js').sprintf;
2728

2829
function ApiProxy(conn) { this.conn = conn; }
2930

30-
ApiProxy.prototype.get = function(options, cb) {
31+
ApiProxy.prototype.get = promiseWrap(function(options, cb) {
3132
var conn = this.conn;
3233
if (cb == null) {
3334
cb = options;
3435
options = {};
3536
}
3637
return deployableAsset.get('apis', conn, options, cb);
37-
};
38+
});
3839

39-
ApiProxy.prototype.update = function(options, value, cb) {
40+
ApiProxy.prototype.update = promiseWrap(function(options, value, cb) {
4041
var conn = this.conn;
4142
return deployableAsset.update('apis', conn, options, value, cb);
42-
};
43+
});
4344

44-
ApiProxy.prototype.getRevisions = function(options, cb) {
45+
ApiProxy.prototype.getRevisions = promiseWrap(function(options, cb) {
4546
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions
4647
var conn = this.conn;
4748
return deployableAsset.getRevisions(conn, 'proxy', 'apis', options, cb);
48-
};
49+
});
4950

50-
ApiProxy.prototype.getDeployments = function(options, cb) {
51+
ApiProxy.prototype.getDeployments = promiseWrap(function(options, cb) {
5152
// GET :mgmtserver/v1/o/:orgname/apis/:name/revisions/:revision/deployments
5253
// or
5354
// GET :mgmtserver/v1/o/:orgname/apis/:name/deployments
5455
var conn = this.conn;
5556
return deployableAsset.getDeployments(conn, 'proxy', 'apis', options, cb);
56-
};
57+
});
5758

58-
ApiProxy.prototype.getResourcesForRevision = function(options, cb) {
59+
ApiProxy.prototype.getResourcesForRevision = promiseWrap(function(options, cb) {
5960
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions/:revision/resources
6061
var conn = this.conn;
6162
return deployableAsset.getResourcesForRevision(conn, 'proxy', 'apis', options, cb);
62-
};
63+
});
6364

64-
ApiProxy.prototype.getPoliciesForRevision = function(options, cb) {
65+
ApiProxy.prototype.getPoliciesForRevision = promiseWrap(function(options, cb) {
6566
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions/:REV/resources
6667
var conn = this.conn;
6768
return deployableAsset.getPoliciesForRevision(conn, 'proxy', 'apis', options, cb);
68-
};
69+
});
6970

7071
function getEndpoints0(conn, options, cb) {
7172
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions/:REV/proxies
@@ -89,42 +90,42 @@
8990
});
9091
}
9192

92-
ApiProxy.prototype.getProxyEndpoints = function(options, cb) {
93+
ApiProxy.prototype.getProxyEndpoints = promiseWrap(function(options, cb) {
9394
return getEndpoints0(this.conn, options, cb);
94-
};
95-
ApiProxy.prototype.getEndpoints = function(options, cb) {
95+
});
96+
ApiProxy.prototype.getEndpoints = promiseWrap(function(options, cb) {
9697
return getEndpoints0(this.conn, options, cb);
97-
};
98-
ApiProxy.prototype.getEndpoint = function(options, cb) {
98+
});
99+
ApiProxy.prototype.getEndpoint = promiseWrap(function(options, cb) {
99100
if ( ! options.endpoint) {
100101
return cb(new Error('missing endpoint for apiproxy'));
101102
}
102103
return getEndpoints0(this.conn, options, cb);
103-
};
104+
});
104105

105-
ApiProxy.prototype.del = function(options, cb) {
106+
ApiProxy.prototype.del = promiseWrap(function(options, cb) {
106107
// DELETE :mgmtserver/v1/o/:orgname/apis/:name
107108
// or
108109
// DELETE :mgmtserver/v1/o/:orgname/apis/:name/revisions/:revision
109110
var conn = this.conn;
110111
return deployableAsset.del('apis', conn, options, cb);
111-
};
112+
});
112113

113-
ApiProxy.prototype.deploy = function(options, cb) {
114+
ApiProxy.prototype.deploy = promiseWrap(function(options, cb) {
114115
return deployableAsset.deploy(this.conn, options, 'apiproxy', cb);
115-
};
116+
});
116117

117-
ApiProxy.prototype.undeploy = function(options, cb) {
118+
ApiProxy.prototype.undeploy = promiseWrap(function(options, cb) {
118119
return deployableAsset.undeploy(this.conn, options, 'apiproxy', cb);
119-
};
120+
});
120121

121-
ApiProxy.prototype.export = function(options, cb) {
122+
ApiProxy.prototype.export = promiseWrap(function(options, cb) {
122123
// GET :mgmtserver/v1/o/:orgname/apis/:name/revisions/:rev?format=bundle
123124
var conn = this.conn;
124125
deployableAsset.export0(conn, 'apiproxy', 'apis', options, cb);
125-
};
126+
});
126127

127-
ApiProxy.prototype.importFromDir = function(options, cb) {
128+
ApiProxy.prototype.importFromDir = promiseWrap(function(options, cb) {
128129
var conn = this.conn;
129130
var srcDir = path.resolve(options.srcDir || options.source);
130131
if (srcDir.endsWith('/apiproxy')) {
@@ -134,23 +135,23 @@
134135
// utility.logWrite(sprintf('import proxy %s from dir %s', optionsName, srcDir));
135136
// }
136137
return deployableAsset.importFromDir(conn, options.name, 'apiproxy', srcDir, cb);
137-
};
138+
});
138139

139-
ApiProxy.prototype.importFromZip = function(options, cb) {
140+
ApiProxy.prototype.importFromZip = promiseWrap(function(options, cb) {
140141
// curl -X POST "${mgmtserver}/v1/o/$org/apis?action=import&name=$proxyname" -T $zipname -H "Content-Type: application/octet-stream"
141142
var conn = this.conn;
142143
var source = path.resolve(options.zipArchive || options.source);
143144
if (conn.verbosity>0) {
144145
utility.logWrite(sprintf('import proxy %s from zip %s', options.name, source));
145146
}
146147
return deployableAsset.importFromZip(conn, options.name, 'apiproxy', source, cb);
147-
};
148+
});
148149

149-
ApiProxy.prototype.import = function(options, cb) {
150+
ApiProxy.prototype.import = promiseWrap(function(options, cb) {
150151
// import from either a zip or a directory.
151152
var conn = this.conn;
152153
return deployableAsset.import0(conn, options, 'apiproxy', cb);
153-
};
154+
});
154155

155156
module.exports = ApiProxy;
156157

lib/app.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818
(function (){
1919
'use strict';
20-
const utility = require('./utility.js'),
21-
common = require('./common.js'),
22-
request = require('request'),
23-
urljoin = require('url-join'),
24-
sprintf = require('sprintf-js').sprintf;
20+
const utility = require('./utility.js'),
21+
common = require('./common.js'),
22+
promiseWrap = require('./promiseWrap.js'),
23+
request = require('request'),
24+
urljoin = require('url-join'),
25+
sprintf = require('sprintf-js').sprintf;
2526

2627
function App(conn) {this.conn = conn;}
2728

28-
App.prototype.get = function(options, cb) {
29+
App.prototype.get = promiseWrap(function(options, cb) {
2930
// GET :mgmtserver/v1/o/:orgname/apps
3031
// or
3132
// GET :mgmtserver/v1/o/:orgname/apps/ID_OF_APP
@@ -40,9 +41,9 @@
4041
}
4142
request.get(requestOptions, common.callback(conn, [200], cb));
4243
});
43-
};
44+
});
4445

45-
App.prototype.del = function(options, cb) {
46+
App.prototype.del = promiseWrap(function(options, cb) {
4647
// DELETE :mgmtserver/v1/o/:orgname/apps/:appid
4748
// Authorization: :edge-auth
4849
var conn = this.conn;
@@ -56,7 +57,7 @@
5657
}
5758
request.del(requestOptions, common.callback(conn, [200], cb));
5859
});
59-
};
60+
});
6061

6162
module.exports = App;
6263

lib/appcredential.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717

1818
(function (){
1919
'use strict';
20-
const utility = require('./utility.js'),
21-
common = require('./common.js'),
22-
request = require('request'),
23-
merge = require('merge'),
24-
urljoin = require('url-join'),
25-
sprintf = require('sprintf-js').sprintf,
20+
const utility = require('./utility.js'),
21+
common = require('./common.js'),
22+
promiseWrap = require('./promiseWrap.js'),
23+
request = require('request'),
24+
merge = require('merge'),
25+
urljoin = require('url-join'),
26+
sprintf = require('sprintf-js').sprintf,
2627
DEFAULT_CREDENTIAL_EXPIRY = -1;
2728

2829
// comment out to debug
2930
//request.debug = true;
3031

3132
function AppCredential(conn) {this.conn = conn;}
3233

33-
AppCredential.prototype.add = function(options, cb) {
34+
AppCredential.prototype.add = promiseWrap(function(options, cb) {
3435
// POST /v1/o/ORGNAME/developers/EMAIL/apps/APPNAME/keys/create
3536
// {
3637
// "consumerKey": "CDX-QAoqiu93ui20170301",
@@ -111,9 +112,9 @@
111112
request.post(requestOptions, common.callback(conn, [201], cb));
112113
}
113114
});
114-
};
115+
});
115116

116-
AppCredential.prototype.del = function(options, cb) {
117+
AppCredential.prototype.del = promiseWrap(function(options, cb) {
117118
// DELETE /v1/o/ORGNAME/developers/EMAIL/apps/APPNAME/keys/CONSUMERKEY
118119
var conn = this.conn;
119120
var urlTail = sprintf('developers/%s/apps/%s/keys/%s',
@@ -130,9 +131,9 @@
130131
}
131132
request.del(requestOptions, common.callback(conn, [200], cb));
132133
});
133-
};
134+
});
134135

135-
AppCredential.prototype.find = function(options, cb) {
136+
AppCredential.prototype.find = promiseWrap(function(options, cb) {
136137
var conn = this.conn;
137138
if (conn.verbosity>0) {
138139
utility.logWrite(sprintf('find key %s', options.key));
@@ -169,7 +170,7 @@
169170
cb(null);
170171
}
171172
});
172-
};
173+
});
173174

174175
function revokeOrApprove0(conn, options, cb) {
175176
// POST -H content-type:application/octet-stream
@@ -230,15 +231,15 @@
230231
});
231232
}
232233

233-
AppCredential.prototype.revoke = function(options, cb) {
234+
AppCredential.prototype.revoke = promiseWrap(function(options, cb) {
234235
var conn = this.conn;
235236
revokeOrApprove(conn, merge(options, {action:'revoke'}), cb);
236-
};
237+
});
237238

238-
AppCredential.prototype.approve = function(options, cb) {
239+
AppCredential.prototype.approve = promiseWrap(function(options, cb) {
239240
var conn = this.conn;
240241
revokeOrApprove(conn, merge(options, {action:'approve'}), cb);
241-
};
242+
});
242243

243244
module.exports = AppCredential;
244245

0 commit comments

Comments
 (0)