-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindRemote.ts
More file actions
39 lines (32 loc) · 1.17 KB
/
findRemote.ts
File metadata and controls
39 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import axios from "axios"
import * as prompts from "prompts"
async function run() {
const apiKey = process.env.API_KEY
const axiosOptions = {
headers: { Authorization: `Bearer: ${apiKey}` }
}
// Get list of users
const users = (await axios.get("https://api.nuki.io/account/user", {
headers: { Authorization: `Bearer: ${apiKey}` }
})).data
console.log(`✅ Received ${users.length} users.`)
// Get list of authorizations
const authorizations: any[] = (await axios.get("https://api.nuki.io/smartlock/auth", axiosOptions)).data
console.log(`✅ Received ${authorizations.length} authorizations.`)
// Just as an additional service: Provide list of users with remote-locking permissions
const remoteAuthorizations = authorizations.filter(a => a.remoteAllowed)
const remoteableUsers = remoteAuthorizations.reduce((ttl: string[], curr) => {
if(ttl.find(i => i === curr.name) === undefined) {
ttl.push(curr.name)
}
return ttl
}, [])
console.log("")
console.log("⚠️ These users have remote unlocking permissions:")
remoteableUsers.forEach(u => {
console.log(u)
})
console.log("")
console.log("🏁 Complete!")
}
run()