Skip to content

Commit ab1dddd

Browse files
authored
fix: add deprecation warning for Parse.Cloud.httpRequest (#7595)
1 parent 68a3a87 commit ab1dddd

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ ___
158158
- Allow setting descending sort to full text queries (dblythy) [#7496](https://github.com/parse-community/parse-server/pull/7496)
159159
- Allow cloud string for ES modules (Daniel Blyth) [#7560](https://github.com/parse-community/parse-server/pull/7560)
160160
- docs: Introduce deprecation ID for reference in comments and online search (Manuel Trezza) [#7562](https://github.com/parse-community/parse-server/pull/7562)
161+
- 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)
161162
- refactor: Modernize HTTPRequest tests (brandongregoryscott) [#7604](https://github.com/parse-community/parse-server/pull/7604)
162163
- Allow liveQuery on Session class (Daniel Blyth) [#7554](https://github.com/parse-community/parse-server/pull/7554)
163164

DEPRECATIONS.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
77
| 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 | - |
88
| 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 | - |
99
| 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 | - |
10+
| 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 | - |
1011

1112
[i_deprecation]: ## "The version and date of the deprecation."
1213
[i_removal]: ## "The version and date of the planned removal."

spec/CloudCode.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,25 @@ describe('Cloud Code', () => {
15541554
obj.save().then(done, done.fail);
15551555
});
15561556

1557+
it('can deprecate Parse.Cloud.httpRequest', async () => {
1558+
const logger = require('../lib/logger').logger;
1559+
spyOn(logger, 'warn').and.callFake(() => {});
1560+
Parse.Cloud.define('hello', () => {
1561+
return 'Hello world!';
1562+
});
1563+
await Parse.Cloud.httpRequest({
1564+
method: 'POST',
1565+
url: 'http://localhost:8378/1/functions/hello',
1566+
headers: {
1567+
'X-Parse-Application-Id': Parse.applicationId,
1568+
'X-Parse-REST-API-Key': 'rest',
1569+
},
1570+
});
1571+
expect(logger.warn).toHaveBeenCalledWith(
1572+
'DeprecationWarning: Parse.Cloud.httpRequest is deprecated and will be removed in a future version. Use a http request library instead.'
1573+
);
1574+
});
1575+
15571576
describe('cloud jobs', () => {
15581577
it('should define a job', done => {
15591578
expect(() => {

src/cloud-code/Parse.Cloud.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Parse } from 'parse/node';
22
import * as triggers from '../triggers';
3+
import Deprecator from '../Deprecator/Deprecator';
34
const Config = require('../Config');
45

56
function isParseObjectConstructor(object) {
@@ -716,7 +717,14 @@ ParseCloud.useMasterKey = () => {
716717
);
717718
};
718719

719-
ParseCloud.httpRequest = require('./httpRequest');
720+
const request = require('./httpRequest');
721+
ParseCloud.httpRequest = opts => {
722+
Deprecator.logRuntimeDeprecation({
723+
usage: 'Parse.Cloud.httpRequest',
724+
solution: 'Use a http request library instead.',
725+
});
726+
return request(opts);
727+
};
720728

721729
module.exports = ParseCloud;
722730

0 commit comments

Comments
 (0)