From af7f44e5f1f97274a8902063b621bde1e94bd08f Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Tue, 23 May 2023 15:48:02 -0500 Subject: [PATCH] Support complete dingId (#1222) --- .changeset/real-onions-tickle.md | 5 +++ package-lock.json | 45 +++++++++++++++++++++++++ packages/ring-client-api/api.ts | 5 ++- packages/ring-client-api/package.json | 2 ++ packages/ring-client-api/ring-camera.ts | 2 +- packages/ring-client-api/ring-types.ts | 2 +- 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 .changeset/real-onions-tickle.md diff --git a/.changeset/real-onions-tickle.md b/.changeset/real-onions-tickle.md new file mode 100644 index 00000000..53efb589 --- /dev/null +++ b/.changeset/real-onions-tickle.md @@ -0,0 +1,5 @@ +--- +'ring-client-api': patch +--- + +Update push notifications to include a full and accurate ding `id`. Note, this is technically a breaking change because the `id` was previously a `number` instead of a `string`, but the last few digits were truncated due to number rounding. We are releasing this as a patch because the `number` version was unusable for fetching additional information about the ding. diff --git a/package-lock.json b/package-lock.json index 659d1a0a..e3dce75c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5353,6 +5353,12 @@ "resolved": "https://registry.npmjs.org/@types/js-levenshtein/-/js-levenshtein-1.1.1.tgz", "integrity": "sha512-qC4bCqYGy1y/NP7dDVr7KJarn+PbX1nSpwA7JXdu0HxT3QYjO8MJ+cntENtHFVy2dRAyBV23OZ6MxsW1AM1L8g==" }, + "node_modules/@types/json-bigint": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/json-bigint/-/json-bigint-1.0.1.tgz", + "integrity": "sha512-zpchZLNsNuzJHi6v64UBoFWAvQlPhch7XAi36FkH6tL1bbbmimIF+cS7vwkzY4u5RaSWMoflQfu+TshMPPw8uw==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -7040,6 +7046,14 @@ "node": "*" } }, + "node_modules/bignumber.js": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.1.tgz", + "integrity": "sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==", + "engines": { + "node": "*" + } + }, "node_modules/binary-data": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/binary-data/-/binary-data-0.6.0.tgz", @@ -14076,6 +14090,14 @@ "node": ">=4" } }, + "node_modules/json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "dependencies": { + "bignumber.js": "^9.0.0" + } + }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -23104,6 +23126,7 @@ "colors": "1.4.0", "debug": "^4.3.4", "got": "^11.8.5", + "json-bigint": "^1.0.0", "msw": "^1.2.1", "rxjs": "^7.8.0", "socket.io-client": "^2.5.0", @@ -23120,6 +23143,7 @@ "devDependencies": { "@types/debug": "4.1.7", "@types/jest": "29.5.0", + "@types/json-bigint": "^1.0.1", "@types/node": "18.15.9", "@types/uuid": "9.0.1", "@types/ws": "^8.5.4", @@ -27127,6 +27151,12 @@ "resolved": "https://registry.npmjs.org/@types/js-levenshtein/-/js-levenshtein-1.1.1.tgz", "integrity": "sha512-qC4bCqYGy1y/NP7dDVr7KJarn+PbX1nSpwA7JXdu0HxT3QYjO8MJ+cntENtHFVy2dRAyBV23OZ6MxsW1AM1L8g==" }, + "@types/json-bigint": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/json-bigint/-/json-bigint-1.0.1.tgz", + "integrity": "sha512-zpchZLNsNuzJHi6v64UBoFWAvQlPhch7XAi36FkH6tL1bbbmimIF+cS7vwkzY4u5RaSWMoflQfu+TshMPPw8uw==", + "dev": true + }, "@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -28377,6 +28407,11 @@ "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", "dev": true }, + "bignumber.js": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.1.tgz", + "integrity": "sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==" + }, "binary-data": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/binary-data/-/binary-data-0.6.0.tgz", @@ -33745,6 +33780,14 @@ "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", "dev": true }, + "json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "requires": { + "bignumber.js": "^9.0.0" + } + }, "json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -37696,6 +37739,7 @@ "@peculiar/webcrypto": "^1.4.3", "@types/debug": "4.1.7", "@types/jest": "29.5.0", + "@types/json-bigint": "^1.0.1", "@types/node": "18.15.9", "@types/socket.io-client": "1.4.36", "@types/uuid": "9.0.1", @@ -37705,6 +37749,7 @@ "eslint-config-shared": "*", "got": "^11.8.5", "jest": "29.5.0", + "json-bigint": "^1.0.0", "msw": "^1.2.1", "rxjs": "^7.8.0", "socket.io-client": "^2.5.0", diff --git a/packages/ring-client-api/api.ts b/packages/ring-client-api/api.ts index 0523087a..54e8f6e2 100644 --- a/packages/ring-client-api/api.ts +++ b/packages/ring-client-api/api.ts @@ -29,6 +29,7 @@ import { setFfmpegPath } from './ffmpeg' import { Subscribed } from './subscribed' import PushReceiver from '@eneris/push-receiver' import { RingIntercom } from './ring-intercom' +import JSONbig from 'json-bigint' export interface RingApiOptions extends SessionOptions { locationIds?: string[] @@ -270,7 +271,9 @@ export class RingApi extends Subscribed { const dataJson = message.data?.gcmData as string try { - const notification = JSON.parse(dataJson) as PushNotification + const notification = JSONbig({ storeAsString: true }).parse( + dataJson + ) as PushNotification if ('ding' in notification) { sendToDevice(notification.ding.doorbot_id, notification) diff --git a/packages/ring-client-api/package.json b/packages/ring-client-api/package.json index 21636244..9a931e85 100644 --- a/packages/ring-client-api/package.json +++ b/packages/ring-client-api/package.json @@ -25,6 +25,7 @@ "colors": "1.4.0", "debug": "^4.3.4", "got": "^11.8.5", + "json-bigint": "^1.0.0", "msw": "^1.2.1", "rxjs": "^7.8.0", "socket.io-client": "^2.5.0", @@ -37,6 +38,7 @@ "devDependencies": { "@types/debug": "4.1.7", "@types/jest": "29.5.0", + "@types/json-bigint": "^1.0.1", "@types/node": "18.15.9", "@types/uuid": "9.0.1", "@types/ws": "^8.5.4", diff --git a/packages/ring-client-api/ring-camera.ts b/packages/ring-client-api/ring-camera.ts index bd214cb1..7599ad8f 100644 --- a/packages/ring-client-api/ring-camera.ts +++ b/packages/ring-client-api/ring-camera.ts @@ -398,7 +398,7 @@ export class RingCamera extends Subscribed { return new StreamingSession(this, connection) } - private removeDingById(idToRemove: number) { + private removeDingById(idToRemove: string) { const allActiveDings = this.activeNotifications, otherDings = allActiveDings.filter(({ ding }) => ding.id !== idToRemove) diff --git a/packages/ring-client-api/ring-types.ts b/packages/ring-client-api/ring-types.ts index c63f74bb..c8b2df87 100644 --- a/packages/ring-client-api/ring-types.ts +++ b/packages/ring-client-api/ring-types.ts @@ -1016,7 +1016,7 @@ export interface PushNotificationDing { device_kind: RingCameraKind detection_type: NotificationDetectionType human_detected?: boolean - id: number + id: string pod_id: number request_id: string image_uuid: string