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

This commit is contained in:
dblythy
2021-10-09 14:04:12 +11:00
committed by GitHub
parent 68a3a87501
commit ab1dddd406
4 changed files with 30 additions and 1 deletions

View File

@@ -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)

View File

@@ -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."

View File

@@ -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(() => {

View File

@@ -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) {
@@ -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;