ring-client-api 13.2.1 → 14.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.d.ts +10 -8
- package/lib/api.js +57 -64
- package/lib/device-data.js +6 -9
- package/lib/ffmpeg.js +2 -6
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- package/lib/location.d.ts +32 -31
- package/lib/location.js +67 -72
- package/lib/refresh-token.js +6 -11
- package/lib/rest-client.d.ts +4 -4
- package/lib/rest-client.js +40 -51
- package/lib/ring-auth-cli.js +2 -4
- package/lib/ring-camera.d.ts +26 -23
- package/lib/ring-camera.js +64 -61
- package/lib/ring-chime.d.ts +7 -7
- package/lib/ring-chime.js +14 -18
- package/lib/ring-device-data-cli.js +2 -4
- package/lib/ring-device.d.ts +7 -7
- package/lib/ring-device.js +16 -20
- package/lib/ring-intercom.d.ts +8 -8
- package/lib/ring-intercom.js +23 -27
- package/lib/ring-types.d.ts +142 -133
- package/lib/ring-types.js +137 -153
- package/lib/streaming/peer-connection.d.ts +5 -3
- package/lib/streaming/peer-connection.js +25 -30
- package/lib/streaming/simple-webrtc-session.d.ts +3 -3
- package/lib/streaming/simple-webrtc-session.js +3 -7
- package/lib/streaming/streaming-messages.d.ts +6 -5
- package/lib/streaming/streaming-messages.js +6 -9
- package/lib/streaming/streaming-session.d.ts +5 -5
- package/lib/streaming/streaming-session.js +34 -38
- package/lib/streaming/webrtc-connection.d.ts +5 -5
- package/lib/streaming/webrtc-connection.js +39 -43
- package/lib/subscribed.d.ts +1 -1
- package/lib/subscribed.js +1 -5
- package/lib/test/rest-client.spec.js +44 -45
- package/lib/test/ring-camera.spec.js +12 -13
- package/lib/util.js +33 -54
- package/package.json +17 -19
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const index_1 = require("../index");
|
|
1
|
+
import { getBatteryLevel, cleanSnapshotUuid } from "../ring-camera.js";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
4
3
|
describe('Ring Camera', () => {
|
|
5
4
|
describe('battery level', () => {
|
|
6
5
|
it('should handle string battery life', () => {
|
|
7
|
-
expect(
|
|
6
|
+
expect(getBatteryLevel({
|
|
8
7
|
battery_life: '49',
|
|
9
8
|
})).toEqual(49);
|
|
10
9
|
});
|
|
11
10
|
it('should handle null battery life', () => {
|
|
12
|
-
expect(
|
|
11
|
+
expect(getBatteryLevel({ battery_life: null })).toEqual(null);
|
|
13
12
|
});
|
|
14
13
|
it('should handle right battery only', () => {
|
|
15
|
-
expect(
|
|
14
|
+
expect(getBatteryLevel({ battery_life: null, battery_life_2: 24 })).toEqual(24);
|
|
16
15
|
});
|
|
17
16
|
it('should handle left battery only', () => {
|
|
18
|
-
expect(
|
|
17
|
+
expect(getBatteryLevel({ battery_life: 76, battery_life_2: null })).toEqual(76);
|
|
19
18
|
});
|
|
20
19
|
it('should handle dual batteries', () => {
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
20
|
+
expect(getBatteryLevel({ battery_life: '92', battery_life_2: 84 })).toEqual(84);
|
|
21
|
+
expect(getBatteryLevel({ battery_life: '92', battery_life_2: 100 })).toEqual(92);
|
|
23
22
|
});
|
|
24
23
|
});
|
|
25
24
|
describe('cleanSnapshotUuid', () => {
|
|
26
25
|
it('should return the original uuid if it is already clean', () => {
|
|
27
|
-
expect(
|
|
26
|
+
expect(cleanSnapshotUuid('c2a0a397-3538-422d-bb4e-51837a56b870')).toBe('c2a0a397-3538-422d-bb4e-51837a56b870');
|
|
28
27
|
});
|
|
29
28
|
it('should return remove anything after :', () => {
|
|
30
|
-
expect(
|
|
29
|
+
expect(cleanSnapshotUuid('c2a0a397-3538-422d-bb4e-51837a56b870:122429140')).toBe('c2a0a397-3538-422d-bb4e-51837a56b870');
|
|
31
30
|
});
|
|
32
31
|
it('should handle falsy values', () => {
|
|
33
|
-
expect(
|
|
34
|
-
expect(
|
|
32
|
+
expect(cleanSnapshotUuid(undefined)).toBe(undefined);
|
|
33
|
+
expect(cleanSnapshotUuid(null)).toBe(null);
|
|
35
34
|
});
|
|
36
35
|
});
|
|
37
36
|
});
|
package/lib/util.js
CHANGED
|
@@ -1,47 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.logDebug = logDebug;
|
|
9
|
-
exports.logInfo = logInfo;
|
|
10
|
-
exports.logError = logError;
|
|
11
|
-
exports.useLogger = useLogger;
|
|
12
|
-
exports.enableDebug = enableDebug;
|
|
13
|
-
exports.generateUuid = generateUuid;
|
|
14
|
-
exports.getHardwareId = getHardwareId;
|
|
15
|
-
exports.requestInput = requestInput;
|
|
16
|
-
exports.stringify = stringify;
|
|
17
|
-
exports.mapAsync = mapAsync;
|
|
18
|
-
exports.randomInteger = randomInteger;
|
|
19
|
-
exports.randomString = randomString;
|
|
20
|
-
exports.fromBase64 = fromBase64;
|
|
21
|
-
exports.toBase64 = toBase64;
|
|
22
|
-
exports.buildSearchString = buildSearchString;
|
|
23
|
-
const debug_1 = __importDefault(require("debug"));
|
|
24
|
-
const colors_1 = require("colors");
|
|
25
|
-
const readline_1 = require("readline");
|
|
26
|
-
const uuid_1 = require("uuid");
|
|
27
|
-
const systeminformation_1 = require("systeminformation");
|
|
28
|
-
const logger_1 = __importDefault(require("@eneris/push-receiver/dist/utils/logger"));
|
|
29
|
-
const debugLogger = (0, debug_1.default)('ring'), uuidNamespace = 'e53ffdc0-e91d-4ce1-bec2-df939d94739d';
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import colors from 'colors';
|
|
3
|
+
import { createInterface } from 'readline';
|
|
4
|
+
import { v4 as generateRandomUuid, v5 as generateUuidFromNamespace } from 'uuid';
|
|
5
|
+
import { uuid as getSystemUuid } from 'systeminformation';
|
|
6
|
+
import pushReceiverLogger from '@eneris/push-receiver/dist/utils/logger.js';
|
|
7
|
+
const debugLogger = debug('ring'), uuidNamespace = 'e53ffdc0-e91d-4ce1-bec2-df939d94739d';
|
|
30
8
|
let logger = {
|
|
31
9
|
logInfo(message) {
|
|
32
10
|
debugLogger(message);
|
|
33
11
|
},
|
|
34
12
|
logError(message) {
|
|
35
|
-
debugLogger(
|
|
13
|
+
debugLogger(colors.red(message));
|
|
36
14
|
},
|
|
37
15
|
}, debugEnabled = false;
|
|
38
16
|
const timeouts = new Set();
|
|
39
|
-
function clearTimeouts() {
|
|
17
|
+
export function clearTimeouts() {
|
|
40
18
|
timeouts.forEach((timeout) => {
|
|
41
19
|
clearTimeout(timeout);
|
|
42
20
|
});
|
|
43
21
|
}
|
|
44
|
-
function delay(milliseconds) {
|
|
22
|
+
export function delay(milliseconds) {
|
|
45
23
|
return new Promise((resolve) => {
|
|
46
24
|
const timeout = setTimeout(() => {
|
|
47
25
|
timeouts.delete(timeout);
|
|
@@ -50,50 +28,50 @@ function delay(milliseconds) {
|
|
|
50
28
|
timeouts.add(timeout);
|
|
51
29
|
});
|
|
52
30
|
}
|
|
53
|
-
function logDebug(message) {
|
|
31
|
+
export function logDebug(message) {
|
|
54
32
|
if (debugEnabled) {
|
|
55
33
|
logger.logInfo(message);
|
|
56
34
|
}
|
|
57
35
|
}
|
|
58
|
-
function logInfo(...message) {
|
|
36
|
+
export function logInfo(...message) {
|
|
59
37
|
logger.logInfo(...message);
|
|
60
38
|
}
|
|
61
|
-
function logError(message) {
|
|
39
|
+
export function logError(message) {
|
|
62
40
|
logger.logError(message);
|
|
63
41
|
}
|
|
64
|
-
function useLogger(newLogger) {
|
|
42
|
+
export function useLogger(newLogger) {
|
|
65
43
|
logger = newLogger;
|
|
66
44
|
}
|
|
67
|
-
function enableDebug() {
|
|
45
|
+
export function enableDebug() {
|
|
68
46
|
debugEnabled = true;
|
|
69
47
|
}
|
|
70
|
-
function generateUuid(seed) {
|
|
48
|
+
export function generateUuid(seed) {
|
|
71
49
|
if (seed) {
|
|
72
|
-
return (
|
|
50
|
+
return generateUuidFromNamespace(seed, uuidNamespace);
|
|
73
51
|
}
|
|
74
|
-
return (
|
|
52
|
+
return generateRandomUuid();
|
|
75
53
|
}
|
|
76
|
-
async function getHardwareId(systemId) {
|
|
54
|
+
export async function getHardwareId(systemId) {
|
|
77
55
|
if (systemId) {
|
|
78
56
|
return generateUuid(systemId);
|
|
79
57
|
}
|
|
80
58
|
const timeoutValue = '-1', { os: id } = await Promise.race([
|
|
81
|
-
(
|
|
59
|
+
getSystemUuid(),
|
|
82
60
|
delay(5000).then(() => ({ os: timeoutValue })),
|
|
83
61
|
]);
|
|
84
62
|
if (id === timeoutValue) {
|
|
85
63
|
logError('Request for system uuid timed out. Falling back to random session id');
|
|
86
|
-
return (
|
|
64
|
+
return generateRandomUuid();
|
|
87
65
|
}
|
|
88
66
|
if (id === '-') {
|
|
89
67
|
// default value set by systeminformation if it can't find a real value
|
|
90
68
|
logError('Unable to get system uuid. Falling back to random session id');
|
|
91
|
-
return (
|
|
69
|
+
return generateRandomUuid();
|
|
92
70
|
}
|
|
93
71
|
return generateUuid(id);
|
|
94
72
|
}
|
|
95
|
-
async function requestInput(question) {
|
|
96
|
-
const lineReader =
|
|
73
|
+
export async function requestInput(question) {
|
|
74
|
+
const lineReader = createInterface({
|
|
97
75
|
input: process.stdin,
|
|
98
76
|
output: process.stdout,
|
|
99
77
|
}), answer = await new Promise((resolve) => {
|
|
@@ -102,7 +80,7 @@ async function requestInput(question) {
|
|
|
102
80
|
lineReader.close();
|
|
103
81
|
return answer.trim();
|
|
104
82
|
}
|
|
105
|
-
function stringify(data) {
|
|
83
|
+
export function stringify(data) {
|
|
106
84
|
if (typeof data === 'string') {
|
|
107
85
|
return data;
|
|
108
86
|
}
|
|
@@ -111,13 +89,13 @@ function stringify(data) {
|
|
|
111
89
|
}
|
|
112
90
|
return JSON.stringify(data) + '';
|
|
113
91
|
}
|
|
114
|
-
function mapAsync(records, asyncMapper) {
|
|
92
|
+
export function mapAsync(records, asyncMapper) {
|
|
115
93
|
return Promise.all(records.map((record) => asyncMapper(record)));
|
|
116
94
|
}
|
|
117
|
-
function randomInteger() {
|
|
95
|
+
export function randomInteger() {
|
|
118
96
|
return Math.floor(Math.random() * 99999999) + 100000;
|
|
119
97
|
}
|
|
120
|
-
function randomString(length) {
|
|
98
|
+
export function randomString(length) {
|
|
121
99
|
const uuid = generateUuid();
|
|
122
100
|
return uuid.replace(/-/g, '').substring(0, length).toLowerCase();
|
|
123
101
|
}
|
|
@@ -135,16 +113,17 @@ function logPushReceiver(...args) {
|
|
|
135
113
|
logDebug('[Push Receiver]');
|
|
136
114
|
logDebug(args[0]);
|
|
137
115
|
}
|
|
138
|
-
|
|
139
|
-
|
|
116
|
+
const pushReceiverLoggerDefault = pushReceiverLogger.default || pushReceiverLogger; // fix for vitest
|
|
117
|
+
pushReceiverLoggerDefault.error = logPushReceiver;
|
|
118
|
+
export function fromBase64(encodedInput) {
|
|
140
119
|
const buff = Buffer.from(encodedInput, 'base64');
|
|
141
120
|
return buff.toString('ascii');
|
|
142
121
|
}
|
|
143
|
-
function toBase64(input) {
|
|
122
|
+
export function toBase64(input) {
|
|
144
123
|
const buff = Buffer.from(input);
|
|
145
124
|
return buff.toString('base64');
|
|
146
125
|
}
|
|
147
|
-
function buildSearchString(search) {
|
|
126
|
+
export function buildSearchString(search) {
|
|
148
127
|
return ('?' +
|
|
149
128
|
Object.entries(search)
|
|
150
129
|
.filter(([, value]) => value !== undefined && value !== null)
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ring-client-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0-beta.1",
|
|
4
4
|
"description": "Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": "./lib/index.js",
|
|
8
9
|
"./ffmpeg": "./lib/ffmpeg.js",
|
|
@@ -11,40 +12,37 @@
|
|
|
11
12
|
"./streaming/streaming-session": "./lib/streaming/streaming-session.js"
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
|
-
"build": "rm -rf lib && tsc --declaration && chmod +x ./lib/ring-*-cli.js",
|
|
15
|
+
"build": "rm -rf lib && tsc --declaration && chmod +x ./lib/ring-*-cli.js && rm -rf ./lib/test",
|
|
15
16
|
"dev": "tsc --declaration --watch --preserveWatchOutput",
|
|
16
17
|
"lint": "eslint .",
|
|
17
|
-
"test": "
|
|
18
|
-
"test:watch": "jest --watch"
|
|
18
|
+
"test": "vitest run"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eneris/push-receiver": "4.3.0",
|
|
22
|
-
"@homebridge/camera-utils": "^
|
|
22
|
+
"@homebridge/camera-utils": "^3.0.0",
|
|
23
23
|
"colors": "1.4.0",
|
|
24
|
-
"debug": "^4.
|
|
24
|
+
"debug": "^4.4.0",
|
|
25
25
|
"json-bigint": "^1.0.0",
|
|
26
|
-
"rxjs": "^7.8.
|
|
26
|
+
"rxjs": "^7.8.2",
|
|
27
27
|
"socket.io-client": "^2.5.0",
|
|
28
|
-
"systeminformation": "^5.
|
|
29
|
-
"undici": "^
|
|
30
|
-
"uuid": "^11.0
|
|
31
|
-
"werift": "0.
|
|
32
|
-
"ws": "^8.18.
|
|
28
|
+
"systeminformation": "^5.25.11",
|
|
29
|
+
"undici": "^7.8.0",
|
|
30
|
+
"uuid": "^11.1.0",
|
|
31
|
+
"werift": "0.22.1",
|
|
32
|
+
"ws": "^8.18.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/debug": "4.1.12",
|
|
36
|
-
"@types/jest": "29.5.14",
|
|
37
36
|
"@types/json-bigint": "^1.0.4",
|
|
38
|
-
"@types/node": "22.
|
|
37
|
+
"@types/node": "22.14.1",
|
|
39
38
|
"@types/socket.io-client": "1.4.36",
|
|
40
39
|
"@types/uuid": "10.0.0",
|
|
41
|
-
"@types/ws": "^8.
|
|
40
|
+
"@types/ws": "^8.18.1",
|
|
42
41
|
"eslint-config-shared": "*",
|
|
43
|
-
"
|
|
44
|
-
"msw": "^2.6.4",
|
|
45
|
-
"ts-jest": "29.2.5",
|
|
42
|
+
"msw": "^2.7.5",
|
|
46
43
|
"tsconfig": "*",
|
|
47
|
-
"typescript": "5.
|
|
44
|
+
"typescript": "5.8.3",
|
|
45
|
+
"vitest": "^3.1.1"
|
|
48
46
|
},
|
|
49
47
|
"engines": {
|
|
50
48
|
"node": "^18 || ^20 || ^22"
|