Skip to content

Commit

Permalink
fix: add deprecation warning for Parse.Cloud.httpRequest (#7595)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy authored Oct 9, 2021
1 parent 68a3a87 commit ab1dddd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
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

0 comments on commit ab1dddd

Please sign in to comment.