ma3route-sdk
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -10,2 +10,12 @@ # Change Log | ||
## 2.3.0 - 2022-06-09 | ||
Added: | ||
* Support path parameters/variables in endpoints. | ||
* Support DELETE requests. | ||
* Added methods: | ||
* `users.destroyOne()`: Delete a single user. | ||
## 2.2.0 - 2022-05-29 | ||
@@ -12,0 +22,0 @@ |
14
index.js
@@ -64,2 +64,8 @@ /** | ||
/** | ||
* A callback passed an error on failure, or nothing otherwise. | ||
* @callback emptySuccessCallback | ||
* @param {Error} error - error object | ||
*/ | ||
/** | ||
* A callack passed a single item, such as a single traffic update. | ||
@@ -79,2 +85,10 @@ * @callback itemCallback | ||
/** | ||
* Sends a DELETE request to delete a single item. | ||
* @typedef {Function} itemsDeleteOneRequest | ||
* @param {Number|Object} identifier - ID of the item | ||
* @param {Object} [params] - parameters | ||
* @param {emptySuccessCallback} callback | ||
*/ | ||
/** | ||
* Sends a GET request to fetch an array of items. | ||
@@ -81,0 +95,0 @@ * @typedef {Function} itemsGetRequest |
@@ -12,2 +12,3 @@ /** | ||
newCustomPostOne: newCustomPostOne, | ||
newDestroyOne: newDestroyOne, | ||
newGet: newGet, | ||
@@ -30,2 +31,17 @@ newGetOne: newGetOne, | ||
/** | ||
* Return a function for deleting an item | ||
* | ||
* @param {Endpoint} endpoint | ||
* @param {Object} options | ||
* @param {String[]} [options.allowable=[]] | ||
* @param {Number} [options.apiVersion=2] API version used | ||
* @param {Boolean} [options.camelcase=true] | ||
*/ | ||
function newDestroyOne(endpoint, options) { | ||
options = options || {}; | ||
options.method = "delete"; | ||
return newGetOne(endpoint, options); | ||
} | ||
/** | ||
* Return a function for retrieving one or more items | ||
@@ -38,2 +54,3 @@ * | ||
* @param {Boolean} [options.camelcase=true] | ||
* @param {String} [options.method=get] | ||
* @return {itemsGetRequest} | ||
@@ -62,3 +79,3 @@ */ | ||
// create the URI | ||
var uri = utils.url(endpoint, uriOptions); | ||
var uri = utils.url(endpoint, uriOptions, args.params); | ||
// get the auth options | ||
@@ -89,4 +106,14 @@ var authOptions = utils.getAuthOptions([ | ||
var url = uri.toString(); | ||
debug("[GET] /%s (%s)", endpoint, url); | ||
return utils.request().get(url, utils.passResponse(args.callback)); | ||
var method; | ||
switch (options.method) { | ||
case "delete": | ||
method = "delete"; | ||
break; | ||
case "get": | ||
default: | ||
method = "get"; | ||
} | ||
debug("[%s] /%s (%s)", method.toUpperCase(), endpoint, url); | ||
return utils.request()[method](url, utils.passResponse(args.callback)); | ||
}; | ||
@@ -99,7 +126,20 @@ } | ||
* @param {Endpoint} endpoint | ||
* @param {String[]} [allowable] | ||
* @param {Object} [options] | ||
* @param {String[]} [options.allowable=[]] | ||
* @param {Number} [options.apiVersion=2] API version used | ||
* @param {Boolean} [options.camelcase=true] | ||
* @param {String} [options.method=get] | ||
* @return {itemsGetOneRequest} | ||
*/ | ||
function newGetOne(endpoint, allowable) { | ||
var get = newGet(endpoint, allowable); | ||
function newGetOne(endpoint, options) { | ||
// for backwards-compatibility <= 2.2.0 | ||
if (_.isArray(options)) { | ||
options = { allowable: options }; | ||
} | ||
options = _.defaultsDeep({}, options, { | ||
allowable: [], | ||
method: "get", | ||
}); | ||
var get = newGet(endpoint, options); | ||
return function(id, params, callback) { | ||
@@ -147,3 +187,3 @@ var args = utils.allowOptionalParams(params, callback); | ||
// create a URI | ||
var uri = utils.url(endpoint, uriOptions); | ||
var uri = utils.url(endpoint, uriOptions, body); | ||
// get auth options | ||
@@ -150,0 +190,0 @@ var authOptions = utils.getAuthOptions([utils.setup(), this, body]); |
@@ -65,2 +65,7 @@ { | ||
"create": ["firstname", "middlename", "lastname", "gender", "email", "country", "alias"], | ||
"delete": { | ||
"apiVersion": 3, | ||
"allowable": ["id", "userid"], | ||
"camelcase": false | ||
}, | ||
"edit": ["firstname", "middlename", "lastname", "email", "alias", "resetpassword", "editprofile"], | ||
@@ -67,0 +72,0 @@ "login": ["email", "password"], |
@@ -22,2 +22,7 @@ /** | ||
/** | ||
* Deleting a single user | ||
* @type {itemsDeleteOneRequest} | ||
*/ | ||
destroyOne: generate.newDestroyOne("users/:id", paramsConfig.users.delete), | ||
/** | ||
* Editing user's profile | ||
@@ -24,0 +29,0 @@ * @type {itemsPostOneRequest} |
@@ -108,5 +108,6 @@ /** | ||
* @param {Object} [options] options - options to be used | ||
* @param {Object} [ctx] ctx - context used for path param interpolation | ||
* @return {URI} an instance of URI.js | ||
*/ | ||
function url(label, options) { | ||
function url(label, options, ctx) { | ||
switch (label) { | ||
@@ -153,2 +154,3 @@ case "activations": | ||
options = options || {}; | ||
ctx = ctx || {}; | ||
if (label && typeof label === "object") { | ||
@@ -166,3 +168,10 @@ options = label; | ||
var uri = URI(topLevel); | ||
if (label) return uri.segment(label); | ||
if (label) { | ||
var match = /:(\w+)/.exec(label); | ||
if (match && ctx[match[1]]) { | ||
label = label.replace(match[0], ctx[match[1]]); | ||
delete ctx[match[1]]; | ||
} | ||
return uri.segment(label); | ||
} | ||
return uri; | ||
@@ -169,0 +178,0 @@ } |
{ | ||
"name": "ma3route-sdk", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Node.js SDK for developing with the Ma3Route REST API", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63881
1803