-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathdevice-data.ts
90 lines (79 loc) · 2.29 KB
/
device-data.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* eslint-disable no-console */
import { RingApi } from './api.ts'
import { acquireRefreshToken } from './refresh-token.ts'
import { mapAsync } from './util.ts'
const sensitiveFields = [
'id',
'device_id',
'latitude',
'longitude',
'address',
'email',
'time_zone',
'location_id',
'serialNumber',
'catalogId',
'adapterZid',
'fingerprint',
'owner',
'ssid',
'ap_address',
'codes',
'groupId',
'group',
'groupMembers',
]
function stripSensitiveFields(input: any) {
if (typeof input === 'object') {
if (Array.isArray(input)) {
input.forEach((value) => stripSensitiveFields(value))
return
}
for (const key in input) {
if (sensitiveFields.includes(key) || key.endsWith('_id')) {
delete input[key]
} else {
const data = input[key]
if (key.length === 36) {
input[key.slice(0, 13) + '-uuid'] = data
delete input[key]
}
if (typeof data === 'string' && data.length === 36) {
input[key] = data.slice(0, 13) + '-uuid'
}
stripSensitiveFields(data)
}
}
}
}
export async function logDeviceData() {
console.log(
'This CLI will log data from you Ring Account to help debug issues and discovering new device types.',
)
console.log(
'The logged data is anonymized and should not compromise your account in any way.',
)
const refreshToken = await acquireRefreshToken(),
ringApi = new RingApi({ refreshToken })
console.log('Successfully logged in. Fetching devices...')
const locations = await ringApi.getLocations(),
amazonKeyLocks = await ringApi.fetchAmazonKeyLocks(),
locationsWithDevices = await mapAsync(locations, async (location) => {
const devices = await location.getDevices()
return {
name: location.name,
cameras: location.cameras.map((camera) => camera.data),
chimes: location.chimes.map((chime) => chime.data),
intercoms: location.intercoms.map((intercom) => intercom.data),
devices: devices.map((device) => device.data),
}
}),
results = {
locations: locationsWithDevices,
amazonKeyLocks,
}
stripSensitiveFields(results)
console.log('\nPlease copy and paste everything AFTER THIS LINE:\n\n')
console.log(JSON.stringify(results))
process.exit(0)
}