From 744b7215617472723e455572d5dabd390bc6f719 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:38:21 +0100 Subject: [PATCH 1/3] refactor: Bump parse-server from `81304be` to `7cb266b` (#1607) --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index beafcd016..8ec037f82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18000,8 +18000,8 @@ "dev": true }, "parse-server": { - "version": "git+https://github.com/parse-community/parse-server.git#81304be649306708fe63a26ae828edcdf4d0ad17", - "from": "git+https://github.com/parse-community/parse-server.git#alpha", + "version": "git+https://github.com/parse-community/parse-server.git#7cb266b207f2619d466922c6c227cfd2f430a8cc", + "from": "git+https://github.com/parse-community/parse-server.git#7cb266b207f2619d466922c6c227cfd2f430a8cc", "dev": true, "requires": { "@graphql-tools/merge": "8.3.6", @@ -18033,7 +18033,7 @@ "mustache": "4.2.0", "parse": "3.4.2", "pg-monitor": "1.5.0", - "pg-promise": "10.12.0", + "pg-promise": "10.12.1", "pluralize": "8.0.0", "redis": "3.1.2", "semver": "7.3.8", @@ -18488,9 +18488,9 @@ "dev": true }, "pg-promise": { - "version": "10.12.0", - "resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-10.12.0.tgz", - "integrity": "sha512-7uN64iEHrhtRcOaU/AT3925S20JzQJG2nWVK2IUz5SlhB1eNdkXjAYoQtei+5kLJo81mOWcFq7x9J9VRldp0ig==", + "version": "10.12.1", + "resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-10.12.1.tgz", + "integrity": "sha512-SiJkBUDGq7PNfJFJbWferodsSH+vLrhte0Q0kVgQbwlNYeKmp9Hhkr+357+5DWEuBGOHhSu1UQffSSf5HVqRtA==", "dev": true, "requires": { "assert-options": "0.7.0", From 96d71744e4a12088f98ad33a5f7a0c06c90a0a4c Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 15 Nov 2022 13:35:15 +1100 Subject: [PATCH 2/3] fix: `Parse.Query.subscribe()` does not return a rejected promise on error in Cloud Code Triggers `beforeConnect` or `beforeSubscribe` (#1490) BREAKING CHANGE: Calling `Parse.Query.subscribe()` will now return a rejected promise if an error is thrown in Cloud Code Triggers `beforeConnect` or `beforeSubscribe`; in previous releases a resolved promise was returned, even if subscribing failed and it was necessary to create an `error.on` listener to handle these errors (#1490) --- integration/test/ParseLiveQueryTest.js | 52 ++++++++++++++++++++++++++ src/LiveQueryClient.js | 21 ++++++++--- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index d3089f691..ab779b186 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -256,4 +256,56 @@ describe('Parse LiveQuery', () => { object.set({ foo: 'bar' }); await object.save(); }); + + it('live query can handle beforeConnect and beforeSubscribe errors', async () => { + await reconfigureServer({ + cloud({ Cloud }) { + Cloud.beforeSubscribe('TestError', () => { + throw 'not allowed to subscribe'; + }); + }, + }); + const client = new Parse.LiveQueryClient({ + applicationId: 'integration', + serverURL: 'ws://localhost:1337', + javascriptKey: null, + masterKey: null, + sessionToken: null, + installationId: null, + }); + client.open(); + const query = new Parse.Query('TestError'); + const subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'not allowed to subscribe') + ); + client.close(); + }); + + it('connectPromise does throw', async () => { + await reconfigureServer({ + cloud({ Cloud }) { + Cloud.beforeConnect((params) => { + if (params.sessionToken === 'testToken') { + throw 'not allowed to connect'; + } + }); + }, + }); + const client = new Parse.LiveQueryClient({ + applicationId: 'integration', + serverURL: 'ws://localhost:1337', + javascriptKey: null, + masterKey: null, + sessionToken: 'testToken', + installationId: null, + }); + client.open(); + const query = new Parse.Query('TestError'); + const subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'not allowed to connect') + ); + client.close(); + }); }); diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 2210dee4d..9d1ae2785 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -14,6 +14,7 @@ import EventEmitter from './EventEmitter'; import ParseObject from './ParseObject'; import LiveQuerySubscription from './LiveQuerySubscription'; import { resolvingPromise } from './promiseUtils'; +import ParseError from './ParseError'; // The LiveQuery client inner state const CLIENT_STATE = { @@ -217,9 +218,13 @@ class LiveQueryClient extends EventEmitter { const subscription = new LiveQuerySubscription(this.requestId, query, sessionToken); this.subscriptions.set(this.requestId, subscription); this.requestId += 1; - this.connectPromise.then(() => { - this.socket.send(JSON.stringify(subscribeRequest)); - }); + this.connectPromise + .then(() => { + this.socket.send(JSON.stringify(subscribeRequest)); + }) + .catch(error => { + subscription.subscribePromise.reject(error); + }); return subscription; } @@ -382,10 +387,15 @@ class LiveQueryClient extends EventEmitter { setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200); } break; - case OP_EVENTS.ERROR: + case OP_EVENTS.ERROR: { + const parseError = new ParseError(data.code, data.error); + if (!this.id) { + this.connectPromise.reject(parseError); + this.state = CLIENT_STATE.DISCONNECTED; + } if (data.requestId) { if (subscription) { - subscription.subscribePromise.resolve(); + subscription.subscribePromise.reject(parseError); setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error), 200); } } else { @@ -398,6 +408,7 @@ class LiveQueryClient extends EventEmitter { this._handleReconnect(); } break; + } case OP_EVENTS.UNSUBSCRIBED: // We have already deleted subscription in unsubscribe(), do nothing here break; From e180bac74198b44e8e430cbf1920186b7f716423 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 15 Nov 2022 02:36:47 +0000 Subject: [PATCH 3/3] chore(release): 4.0.0-alpha.2 [skip ci] # [4.0.0-alpha.2](https://github.com/parse-community/Parse-SDK-JS/compare/4.0.0-alpha.1...4.0.0-alpha.2) (2022-11-15) ### Bug Fixes * `Parse.Query.subscribe()` does not return a rejected promise on error in Cloud Code Triggers `beforeConnect` or `beforeSubscribe` ([#1490](https://github.com/parse-community/Parse-SDK-JS/issues/1490)) ([96d7174](https://github.com/parse-community/Parse-SDK-JS/commit/96d71744e4a12088f98ad33a5f7a0c06c90a0a4c)) ### BREAKING CHANGES * Calling `Parse.Query.subscribe()` will now return a rejected promise if an error is thrown in Cloud Code Triggers `beforeConnect` or `beforeSubscribe`; in previous releases a resolved promise was returned, even if subscribing failed and it was necessary to create an `error.on` listener to handle these errors (#1490) ([96d7174](96d7174)) --- changelogs/CHANGELOG_alpha.md | 12 ++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/changelogs/CHANGELOG_alpha.md b/changelogs/CHANGELOG_alpha.md index 7d60d9295..af5b796e0 100644 --- a/changelogs/CHANGELOG_alpha.md +++ b/changelogs/CHANGELOG_alpha.md @@ -1,3 +1,15 @@ +# [4.0.0-alpha.2](https://github.com/parse-community/Parse-SDK-JS/compare/4.0.0-alpha.1...4.0.0-alpha.2) (2022-11-15) + + +### Bug Fixes + +* `Parse.Query.subscribe()` does not return a rejected promise on error in Cloud Code Triggers `beforeConnect` or `beforeSubscribe` ([#1490](https://github.com/parse-community/Parse-SDK-JS/issues/1490)) ([96d7174](https://github.com/parse-community/Parse-SDK-JS/commit/96d71744e4a12088f98ad33a5f7a0c06c90a0a4c)) + + +### BREAKING CHANGES + +* Calling `Parse.Query.subscribe()` will now return a rejected promise if an error is thrown in Cloud Code Triggers `beforeConnect` or `beforeSubscribe`; in previous releases a resolved promise was returned, even if subscribing failed and it was necessary to create an `error.on` listener to handle these errors (#1490) ([96d7174](96d7174)) + # [4.0.0-alpha.1](https://github.com/parse-community/Parse-SDK-JS/compare/3.5.1-alpha.2...4.0.0-alpha.1) (2022-11-10) diff --git a/package-lock.json b/package-lock.json index 8ec037f82..528a4e16f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "parse", - "version": "4.0.0-alpha.1", + "version": "4.0.0-alpha.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9fb9d7802..93f232ef1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "parse", - "version": "4.0.0-alpha.1", + "version": "4.0.0-alpha.2", "description": "The Parse JavaScript SDK", "homepage": "https://parseplatform.org/", "keywords": [