Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add deprecation warning for Parse.Cloud.httpRequest #7595

Merged
merged 14 commits into from
Oct 9, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ ___
- Allow setting descending sort to full text queries (dblythy) [#7496](https://github.com/parse-community/parse-server/pull/7496)
- Allow cloud string for ES modules (Daniel Blyth) [#7560](https://github.com/parse-community/parse-server/pull/7560)
- docs: Introduce deprecation ID for reference in comments and online search (Manuel Trezza) [#7562](https://github.com/parse-community/parse-server/pull/7562)
- refactor: deprecate `Parse.Cloud.httpRequest`; it is recommended to use a HTTP library instead. (Daniel Blyth) [#7595](https://github.com/parse-community/parse-server/pull/7595)
- refactor: Modernize HTTPRequest tests (brandongregoryscott) [#7604](https://github.com/parse-community/parse-server/pull/7604)
- Allow liveQuery on Session class (Daniel Blyth) [#7554](https://github.com/parse-community/parse-server/pull/7554)

Expand Down
1 change: 1 addition & 0 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
| DEPPS1 | Native MongoDB syntax in aggregation pipeline | [#7338](https://github.com/parse-community/parse-server/issues/7338) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
| DEPPS2 | Config option `directAccess` defaults to `true` | [#6636](https://github.com/parse-community/parse-server/pull/6636) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
| DEPPS3 | Config option `enforcePrivateUsers` defaults to `true` | [#7319](https://github.com/parse-community/parse-server/pull/7319) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
| DEPPS4 | Remove convenience method for http request `Parse.Cloud.httpRequest` | [#7589](https://github.com/parse-community/parse-server/pull/7589) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |

[i_deprecation]: ## "The version and date of the deprecation."
[i_removal]: ## "The version and date of the planned removal."
Expand Down
19 changes: 19 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,25 @@ describe('Cloud Code', () => {
obj.save().then(done, done.fail);
});

it('can deprecate Parse.Cloud.httpRequest', async () => {
const logger = require('../lib/logger').logger;
spyOn(logger, 'warn').and.callFake(() => {});
Parse.Cloud.define('hello', () => {
return 'Hello world!';
});
await Parse.Cloud.httpRequest({
method: 'POST',
url: 'http://localhost:8378/1/functions/hello',
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-REST-API-Key': 'rest',
},
});
expect(logger.warn).toHaveBeenCalledWith(
'DeprecationWarning: Parse.Cloud.httpRequest is deprecated and will be removed in a future version. Use a http request library instead.'
);
});

describe('cloud jobs', () => {
it('should define a job', done => {
expect(() => {
Expand Down
10 changes: 9 additions & 1 deletion src/cloud-code/Parse.Cloud.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Parse } from 'parse/node';
import * as triggers from '../triggers';
import Deprecator from '../Deprecator/Deprecator';
const Config = require('../Config');

function isParseObjectConstructor(object) {
Expand Down Expand Up @@ -716,7 +717,14 @@ ParseCloud.useMasterKey = () => {
);
};

ParseCloud.httpRequest = require('./httpRequest');
const request = require('./httpRequest');
ParseCloud.httpRequest = opts => {
Deprecator.logRuntimeDeprecation({
usage: 'Parse.Cloud.httpRequest',
solution: 'Use a http request library instead.',
});
return request(opts);
};

module.exports = ParseCloud;

Expand Down