Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuki-api

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuki-api - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

132

index.js

@@ -8,2 +8,3 @@ const request = require('request'),

smartLocks: [],
models: models,

@@ -190,9 +191,21 @@ setApiKey: function(key) {

},
findAccountUserAuthName: function(smartlockId, name) {
findAccountUserByAuthId: function(smartlockId, authId) {
return new Promise(function (resolve, reject) {
e.getSmartLockUsers(smartlockId).then(function (users) {
var user = users.filter(function (user) {
var users = users.filter(function (user) {
return user.id == authId;
});
return resolve(users);
}).catch(function (error) {
return reject(error);
});
});
},
findAccountUserAuthByName: function(smartlockId, name) {
return new Promise(function (resolve, reject) {
e.getSmartLockUsers(smartlockId).then(function (users) {
var users = users.filter(function (user) {
return user.name == name;
});
return resolve(user);
return resolve(users);
}).catch(function (error) {

@@ -240,2 +253,42 @@ return reject(error);

},
updateNukiUser: function (accountUserId, accountUser) {
return new Promise(function (resolve, reject) {
e.findAccountUserByName(accountUser.name).then(function(result) {
if(result != null) {
var body = JSON.stringify(accountUser);
var contentLength = Buffer.byteLength(body);
var options = {
url: "https://api.nuki.io/account/user/" + accountUserId,
method: "POST",
headers: {
'User-Agent': 'none',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': contentLength,
'Authorization': 'Bearer ' + e.apiKey
},
body: body
};
function callback(error, response, body) {
if(response.statusCode == 204) {
e.getAccountUsers(true).then(function () {
return resolve(e.findAccountUserByName(accountUser.name));
});
} else {
return reject(new Error(response.statusMessage));
}
};
request(options, callback);
} else {
e.createNukiUser(accountUser).then(function (result) {
return resolve(result);
}).catch(function(error) {
return reject(error);
});
};
}).catch(function (error) {
reject(error);
});
});
},
removeNukiUser: function (accountUserId) {

@@ -271,9 +324,49 @@ return new Promise(function (resolve, reject) {

},
grantAccess: function (smartlockId, smartlockAuth) {
return new Promise(function (resolve, reject) {
e.findAccountUserAuthByName(smartlockAuth.name).then(function(result) {
if(result == null) {
var body = JSON.stringify(smartlockAuth);
var contentLength = Buffer.byteLength(body);
var options = {
url: "https://api.nuki.io/smartlock/" + smartlockId + "/auth",
method: "PUT",
headers: {
'User-Agent': 'none',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': contentLength,
'Authorization': 'Bearer ' + e.apiKey
},
body: body
};
function callback(error, response, body) {
if(response.statusCode == 204) {
e.getSmartLockUsers(smartlockId);
return resolve(true);
} else {
return reject(new Error(response.statusMessage));
}
};
request(options, callback);
} else {
e.updateAccess(smartlockId, result.id, smartlockAuth).then(function (result) {
return resolve(result);
}).catch(function (error) {
return reject(error);
});
};
}).catch(function (error) {
return reject(error);
});
});
},
updateAccess: function (smartlockId, authId, smartlockAuth) {
return new Promise(function (resolve, reject) {
var body = JSON.stringify(smartlockAuth);
var contentLength = Buffer.byteLength(body);
var options = {
url: "https://api.nuki.io/smartlock/" + smartlockId + "/auth",
method: "PUT",
url: "https://api.nuki.io/smartlock/" + smartlockId + "/auth/" + authId,
method: "POST",
headers: {

@@ -294,3 +387,3 @@ 'User-Agent': 'none',

return reject(new Error(response.statusMessage));
}
};
};

@@ -322,2 +415,29 @@ request(options, callback);

});
},
getLog: function (smartlockId = null) {
return new Promise(function (resolve, reject) {
var url = "https://api.nuki.io/smartlock/log/";
if(smartlockId != null)
url += smartlockId;
var options = {
url: url,
method: "GET",
headers: {
'User-Agent': 'none',
'Accept': 'application/json',
'Authorization': 'Bearer ' + e.apiKey
}
};
function callback(error, response, body) {
if(response.statusCode == 200) {
return resolve(JSON.parse(body));
} else {
return reject(new Error(response.statusMessage));
}
};
request(options, callback);
});
}

@@ -324,0 +444,0 @@ };

2

package.json
{
"name": "nuki-api",
"version": "0.0.6",
"version": "0.0.7",
"description": "NUKI WEB API",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,3 +24,21 @@ ## Synopsis

t.b.d.
Request | Parameter
--------------------------- | -----------------------------------------------------------------------
setApiKey | (string) apiKey
getAccountUsers | (bool) reload (optional)
getSmartLocks | (bool) reload (optional)
getSmartLockUsers | (int) smartlockId, (bool) reload (optional)
findAccountUserById | (int) accountUserId
findAccountUserByName | (string) name
findSmartlockById | (int) smartlockId
findSmartlockByName | (string) name
findAccountUserByAuthId | (int) smartlockId, (int) authId
findAccountUserAuthByName | (int) smartlockId, (string) name
createNukiUser | (models.AccountUser) accountUser
updateNukiUser | (int) accountUserId, (models.AccountUser) accountUser
removeNukiUser | (int) accountUserId
grantAccess | (int) smartlockId, (models.SmartlockAuth) smartlockAuth
updateAccess | (int) smartlockId, (int) authId, (models.SmartlockAuth) smartlockAuth
revokeAccess | (int) smartlockId, (int) authId
getLog | (int) smartlockId (optional)

@@ -27,0 +45,0 @@ ## Contributors

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc