Skip to content

Commit

Permalink
v0.4.1 of the library. Now returns es6 promises
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa committed Dec 3, 2018
1 parent c4512ed commit a5f8948
Show file tree
Hide file tree
Showing 36 changed files with 973 additions and 315 deletions.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apigee-edge-js-examples",
"version": "0.3.15",
"version": "0.4.1",
"description": "Examples for using the Apigee Edge nodeJS library",
"main": "importAndDeploy.js",
"scripts": {
Expand Down
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
// limitations under the License.
//
// created: Thu Mar 23 14:34:12 2017
// last saved: <2017-December-08 13:12:55>
// last saved: <2018-December-03 08:52:25>

var edge = require('./lib/edge.js'),
utility = require('./lib/utility.js');
const Edge = require('./lib/edge.js');

module.exports = {
edge : edge,
utility : utility
edge : new Edge(),
utility : require('./lib/utility.js')
};
31 changes: 16 additions & 15 deletions lib/apiproduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

(function (){
'use strict';
const utility = require('./utility.js'),
common = require('./common.js'),
request = require('request'),
path = require('path'),
merge = require('merge'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf;
const utility = require('./utility.js'),
common = require('./common.js'),
promiseWrap = require('./promiseWrap.js'),
request = require('request'),
path = require('path'),
merge = require('merge'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf;

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

ApiProduct.prototype.create = function(options, cb) {
ApiProduct.prototype.create = promiseWrap(function(options, cb) {
// POST :mgmtserver/v1/o/:orgname/apiproducts/:product
// Content-Type: application/json
// Authorization: :edge-auth
Expand Down Expand Up @@ -91,9 +92,9 @@
// request.debug = true;
request.post(requestOptions, common.callback(conn, [201], cb));
});
};
});

ApiProduct.prototype.get = function(options, cb) {
ApiProduct.prototype.get = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apiproducts
// or
// GET :mgmtserver/v1/o/:orgname/apiproducts/NAME_OF_PRODUCT
Expand All @@ -108,9 +109,9 @@
}
request.get(requestOptions, common.callback(conn, [200], cb));
});
};
});

ApiProduct.prototype.update = function(options, cb) {
ApiProduct.prototype.update = promiseWrap(function(options, cb) {
// POST :mgmtserver/v1/o/:orgname/apiproducts/NAME_OF_PRODUCT
var name = options.productName || options.name;
if ( ! name ) {
Expand All @@ -131,9 +132,9 @@
}
request.post(requestOptions, common.callback(conn, [200], cb));
});
};
});

ApiProduct.prototype.del = function(options, cb) {
ApiProduct.prototype.del = promiseWrap(function(options, cb) {
// DELETE :mgmtserver/v1/o/:orgname/apiproducts/:apiproductname
// Authorization: :edge-auth
var conn = this.conn;
Expand All @@ -151,7 +152,7 @@
}
request.del(requestOptions, common.callback(conn, [200], cb));
});
};
});

module.exports = ApiProduct;

Expand Down
67 changes: 34 additions & 33 deletions lib/apiproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,55 @@
(function (){
'use strict';
const utility = require('./utility.js'),
path = require('path'),
common = require('./common.js'),
deployableAsset = require('./deployableAsset.js'),
promiseWrap = require('./promiseWrap.js'),
path = require('path'),
request = require('request'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf;

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

ApiProxy.prototype.get = function(options, cb) {
ApiProxy.prototype.get = promiseWrap(function(options, cb) {
var conn = this.conn;
if (cb == null) {
cb = options;
options = {};
}
return deployableAsset.get('apis', conn, options, cb);
};
});

ApiProxy.prototype.update = function(options, value, cb) {
ApiProxy.prototype.update = promiseWrap(function(options, value, cb) {
var conn = this.conn;
return deployableAsset.update('apis', conn, options, value, cb);
};
});

ApiProxy.prototype.getRevisions = function(options, cb) {
ApiProxy.prototype.getRevisions = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions
var conn = this.conn;
return deployableAsset.getRevisions(conn, 'proxy', 'apis', options, cb);
};
});

ApiProxy.prototype.getDeployments = function(options, cb) {
ApiProxy.prototype.getDeployments = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apis/:name/revisions/:revision/deployments
// or
// GET :mgmtserver/v1/o/:orgname/apis/:name/deployments
var conn = this.conn;
return deployableAsset.getDeployments(conn, 'proxy', 'apis', options, cb);
};
});

ApiProxy.prototype.getResourcesForRevision = function(options, cb) {
ApiProxy.prototype.getResourcesForRevision = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions/:revision/resources
var conn = this.conn;
return deployableAsset.getResourcesForRevision(conn, 'proxy', 'apis', options, cb);
};
});

ApiProxy.prototype.getPoliciesForRevision = function(options, cb) {
ApiProxy.prototype.getPoliciesForRevision = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apis/:api/revisions/:REV/resources
var conn = this.conn;
return deployableAsset.getPoliciesForRevision(conn, 'proxy', 'apis', options, cb);
};
});

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

ApiProxy.prototype.getProxyEndpoints = function(options, cb) {
ApiProxy.prototype.getProxyEndpoints = promiseWrap(function(options, cb) {
return getEndpoints0(this.conn, options, cb);
};
ApiProxy.prototype.getEndpoints = function(options, cb) {
});
ApiProxy.prototype.getEndpoints = promiseWrap(function(options, cb) {
return getEndpoints0(this.conn, options, cb);
};
ApiProxy.prototype.getEndpoint = function(options, cb) {
});
ApiProxy.prototype.getEndpoint = promiseWrap(function(options, cb) {
if ( ! options.endpoint) {
return cb(new Error('missing endpoint for apiproxy'));
}
return getEndpoints0(this.conn, options, cb);
};
});

ApiProxy.prototype.del = function(options, cb) {
ApiProxy.prototype.del = promiseWrap(function(options, cb) {
// DELETE :mgmtserver/v1/o/:orgname/apis/:name
// or
// DELETE :mgmtserver/v1/o/:orgname/apis/:name/revisions/:revision
var conn = this.conn;
return deployableAsset.del('apis', conn, options, cb);
};
});

ApiProxy.prototype.deploy = function(options, cb) {
ApiProxy.prototype.deploy = promiseWrap(function(options, cb) {
return deployableAsset.deploy(this.conn, options, 'apiproxy', cb);
};
});

ApiProxy.prototype.undeploy = function(options, cb) {
ApiProxy.prototype.undeploy = promiseWrap(function(options, cb) {
return deployableAsset.undeploy(this.conn, options, 'apiproxy', cb);
};
});

ApiProxy.prototype.export = function(options, cb) {
ApiProxy.prototype.export = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apis/:name/revisions/:rev?format=bundle
var conn = this.conn;
deployableAsset.export0(conn, 'apiproxy', 'apis', options, cb);
};
});

ApiProxy.prototype.importFromDir = function(options, cb) {
ApiProxy.prototype.importFromDir = promiseWrap(function(options, cb) {
var conn = this.conn;
var srcDir = path.resolve(options.srcDir || options.source);
if (srcDir.endsWith('/apiproxy')) {
Expand All @@ -134,23 +135,23 @@
// utility.logWrite(sprintf('import proxy %s from dir %s', optionsName, srcDir));
// }
return deployableAsset.importFromDir(conn, options.name, 'apiproxy', srcDir, cb);
};
});

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

ApiProxy.prototype.import = function(options, cb) {
ApiProxy.prototype.import = promiseWrap(function(options, cb) {
// import from either a zip or a directory.
var conn = this.conn;
return deployableAsset.import0(conn, options, 'apiproxy', cb);
};
});

module.exports = ApiProxy;

Expand Down
19 changes: 10 additions & 9 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

(function (){
'use strict';
const utility = require('./utility.js'),
common = require('./common.js'),
request = require('request'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf;
const utility = require('./utility.js'),
common = require('./common.js'),
promiseWrap = require('./promiseWrap.js'),
request = require('request'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf;

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

App.prototype.get = function(options, cb) {
App.prototype.get = promiseWrap(function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apps
// or
// GET :mgmtserver/v1/o/:orgname/apps/ID_OF_APP
Expand All @@ -40,9 +41,9 @@
}
request.get(requestOptions, common.callback(conn, [200], cb));
});
};
});

App.prototype.del = function(options, cb) {
App.prototype.del = promiseWrap(function(options, cb) {
// DELETE :mgmtserver/v1/o/:orgname/apps/:appid
// Authorization: :edge-auth
var conn = this.conn;
Expand All @@ -56,7 +57,7 @@
}
request.del(requestOptions, common.callback(conn, [200], cb));
});
};
});

module.exports = App;

Expand Down
33 changes: 17 additions & 16 deletions lib/appcredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@

(function (){
'use strict';
const utility = require('./utility.js'),
common = require('./common.js'),
request = require('request'),
merge = require('merge'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf,
const utility = require('./utility.js'),
common = require('./common.js'),
promiseWrap = require('./promiseWrap.js'),
request = require('request'),
merge = require('merge'),
urljoin = require('url-join'),
sprintf = require('sprintf-js').sprintf,
DEFAULT_CREDENTIAL_EXPIRY = -1;

// comment out to debug
//request.debug = true;

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

AppCredential.prototype.add = function(options, cb) {
AppCredential.prototype.add = promiseWrap(function(options, cb) {
// POST /v1/o/ORGNAME/developers/EMAIL/apps/APPNAME/keys/create
// {
// "consumerKey": "CDX-QAoqiu93ui20170301",
Expand Down Expand Up @@ -111,9 +112,9 @@
request.post(requestOptions, common.callback(conn, [201], cb));
}
});
};
});

AppCredential.prototype.del = function(options, cb) {
AppCredential.prototype.del = promiseWrap(function(options, cb) {
// DELETE /v1/o/ORGNAME/developers/EMAIL/apps/APPNAME/keys/CONSUMERKEY
var conn = this.conn;
var urlTail = sprintf('developers/%s/apps/%s/keys/%s',
Expand All @@ -130,9 +131,9 @@
}
request.del(requestOptions, common.callback(conn, [200], cb));
});
};
});

AppCredential.prototype.find = function(options, cb) {
AppCredential.prototype.find = promiseWrap(function(options, cb) {
var conn = this.conn;
if (conn.verbosity>0) {
utility.logWrite(sprintf('find key %s', options.key));
Expand Down Expand Up @@ -169,7 +170,7 @@
cb(null);
}
});
};
});

function revokeOrApprove0(conn, options, cb) {
// POST -H content-type:application/octet-stream
Expand Down Expand Up @@ -230,15 +231,15 @@
});
}

AppCredential.prototype.revoke = function(options, cb) {
AppCredential.prototype.revoke = promiseWrap(function(options, cb) {
var conn = this.conn;
revokeOrApprove(conn, merge(options, {action:'revoke'}), cb);
};
});

AppCredential.prototype.approve = function(options, cb) {
AppCredential.prototype.approve = promiseWrap(function(options, cb) {
var conn = this.conn;
revokeOrApprove(conn, merge(options, {action:'approve'}), cb);
};
});

module.exports = AppCredential;

Expand Down
Loading

0 comments on commit a5f8948

Please sign in to comment.