parse 5.2.0-alpha.1 → 5.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse.js +10102 -15029
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +10093 -15165
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Analytics.js +7 -11
- package/lib/browser/AnonymousUtils.js +17 -22
- package/lib/browser/Cloud.js +23 -41
- package/lib/browser/CoreManager.js +71 -79
- package/lib/browser/CryptoController.js +14 -9
- package/lib/browser/EventEmitter.js +9 -2
- package/lib/browser/EventuallyQueue.js +156 -357
- package/lib/browser/FacebookUtils.js +23 -28
- package/lib/browser/IndexedDBStorageController.js +18 -14
- package/lib/browser/InstallationController.js +55 -121
- package/lib/browser/LiveQueryClient.js +308 -484
- package/lib/browser/LiveQuerySubscription.js +25 -28
- package/lib/browser/LocalDatastore.js +258 -624
- package/lib/browser/LocalDatastoreController.default.js +42 -226
- package/lib/browser/LocalDatastoreController.js +11 -1
- package/lib/browser/LocalDatastoreController.react-native.js +66 -160
- package/lib/browser/LocalDatastoreUtils.js +4 -7
- package/lib/browser/ObjectStateMutations.js +54 -96
- package/lib/browser/OfflineQuery.js +106 -198
- package/lib/browser/Parse.js +44 -60
- package/lib/browser/ParseACL.js +242 -288
- package/lib/browser/ParseCLP.js +372 -572
- package/lib/browser/ParseConfig.js +115 -138
- package/lib/browser/ParseError.js +85 -182
- package/lib/browser/ParseFile.js +294 -438
- package/lib/browser/ParseGeoPoint.js +121 -146
- package/lib/browser/ParseHooks.js +23 -25
- package/lib/browser/ParseInstallation.js +225 -367
- package/lib/browser/ParseLiveQuery.js +74 -148
- package/lib/browser/ParseObject.js +2014 -2621
- package/lib/browser/ParseOp.js +343 -484
- package/lib/browser/ParsePolygon.js +101 -120
- package/lib/browser/ParseQuery.js +1708 -2052
- package/lib/browser/ParseRelation.js +99 -118
- package/lib/browser/ParseRole.js +88 -140
- package/lib/browser/ParseSchema.js +372 -434
- package/lib/browser/ParseSession.js +62 -110
- package/lib/browser/ParseUser.js +941 -1284
- package/lib/browser/Push.js +15 -38
- package/lib/browser/RESTController.js +85 -124
- package/lib/browser/SingleInstanceStateController.js +57 -86
- package/lib/browser/Socket.weapp.js +50 -33
- package/lib/browser/Storage.js +23 -28
- package/lib/browser/StorageController.browser.js +16 -13
- package/lib/browser/StorageController.default.js +15 -14
- package/lib/browser/StorageController.js +14 -1
- package/lib/browser/StorageController.react-native.js +31 -30
- package/lib/browser/StorageController.weapp.js +19 -13
- package/lib/browser/TaskQueue.js +31 -43
- package/lib/browser/UniqueInstanceStateController.js +65 -86
- package/lib/browser/WebSocketController.js +11 -4
- package/lib/browser/Xhr.weapp.js +90 -78
- package/lib/browser/arrayContainsObject.js +3 -3
- package/lib/browser/canBeSerialized.js +10 -11
- package/lib/browser/decode.js +11 -11
- package/lib/browser/encode.js +11 -11
- package/lib/browser/equals.js +9 -10
- package/lib/browser/escape.js +2 -2
- package/lib/browser/isRevocableSession.js +1 -1
- package/lib/browser/parseDate.js +10 -10
- package/lib/browser/promiseUtils.js +19 -19
- package/lib/browser/unique.js +4 -4
- package/lib/browser/unsavedChildren.js +20 -21
- package/lib/browser/uuid.js +2 -4
- package/lib/node/Analytics.js +2 -6
- package/lib/node/AnonymousUtils.js +7 -12
- package/lib/node/Cloud.js +8 -8
- package/lib/node/CoreManager.js +59 -67
- package/lib/node/CryptoController.js +8 -3
- package/lib/node/EventEmitter.js +7 -1
- package/lib/node/EventuallyQueue.js +17 -36
- package/lib/node/FacebookUtils.js +1 -5
- package/lib/node/IndexedDBStorageController.js +14 -10
- package/lib/node/InstallationController.js +9 -10
- package/lib/node/LiveQueryClient.js +12 -14
- package/lib/node/LiveQuerySubscription.js +3 -4
- package/lib/node/LocalDatastore.js +20 -20
- package/lib/node/LocalDatastoreController.default.js +8 -9
- package/lib/node/LocalDatastoreController.js +14 -1
- package/lib/node/LocalDatastoreController.react-native.js +25 -21
- package/lib/node/LocalDatastoreUtils.js +4 -7
- package/lib/node/ObjectStateMutations.js +9 -19
- package/lib/node/OfflineQuery.js +37 -23
- package/lib/node/Parse.js +33 -47
- package/lib/node/ParseACL.js +18 -27
- package/lib/node/ParseCLP.js +35 -37
- package/lib/node/ParseConfig.js +7 -14
- package/lib/node/ParseError.js +457 -458
- package/lib/node/ParseFile.js +24 -44
- package/lib/node/ParseGeoPoint.js +16 -17
- package/lib/node/ParseHooks.js +13 -15
- package/lib/node/ParseInstallation.js +7 -8
- package/lib/node/ParseLiveQuery.js +6 -11
- package/lib/node/ParseObject.js +139 -170
- package/lib/node/ParseOp.js +32 -44
- package/lib/node/ParsePolygon.js +11 -17
- package/lib/node/ParseQuery.js +97 -120
- package/lib/node/ParseRelation.js +7 -16
- package/lib/node/ParseRole.js +7 -8
- package/lib/node/ParseSchema.js +26 -39
- package/lib/node/ParseSession.js +7 -8
- package/lib/node/ParseUser.js +73 -84
- package/lib/node/Push.js +4 -9
- package/lib/node/RESTController.js +21 -33
- package/lib/node/SingleInstanceStateController.js +41 -69
- package/lib/node/Socket.weapp.js +23 -2
- package/lib/node/Storage.js +11 -16
- package/lib/node/StorageController.browser.js +10 -8
- package/lib/node/StorageController.default.js +9 -9
- package/lib/node/StorageController.js +16 -1
- package/lib/node/StorageController.react-native.js +17 -17
- package/lib/node/StorageController.weapp.js +14 -8
- package/lib/node/TaskQueue.js +2 -3
- package/lib/node/UniqueInstanceStateController.js +40 -60
- package/lib/node/WebSocketController.js +15 -2
- package/lib/node/Xhr.weapp.js +11 -2
- package/lib/node/arrayContainsObject.js +1 -1
- package/lib/node/canBeSerialized.js +2 -2
- package/lib/node/decode.js +1 -1
- package/lib/node/encode.js +2 -2
- package/lib/node/equals.js +1 -1
- package/lib/node/escape.js +1 -1
- package/lib/node/isRevocableSession.js +1 -1
- package/lib/node/parseDate.js +1 -1
- package/lib/node/promiseUtils.js +7 -7
- package/lib/node/unique.js +2 -2
- package/lib/node/unsavedChildren.js +2 -2
- package/lib/node/uuid.js +2 -4
- package/lib/react-native/Analytics.js +2 -2
- package/lib/react-native/AnonymousUtils.js +3 -4
- package/lib/react-native/CoreManager.js +2 -3
- package/lib/react-native/CryptoController.js +6 -1
- package/lib/react-native/EventEmitter.js +6 -1
- package/lib/react-native/EventuallyQueue.js +1 -2
- package/lib/react-native/FacebookUtils.js +1 -2
- package/lib/react-native/IndexedDBStorageController.js +11 -5
- package/lib/react-native/InstallationController.js +1 -2
- package/lib/react-native/LiveQueryClient.js +2 -4
- package/lib/react-native/LiveQuerySubscription.js +2 -4
- package/lib/react-native/LocalDatastore.js +3 -3
- package/lib/react-native/LocalDatastoreController.default.js +1 -2
- package/lib/react-native/LocalDatastoreController.js +11 -1
- package/lib/react-native/LocalDatastoreController.react-native.js +11 -12
- package/lib/react-native/LocalDatastoreUtils.js +3 -6
- package/lib/react-native/OfflineQuery.js +25 -20
- package/lib/react-native/Parse.js +24 -38
- package/lib/react-native/ParseACL.js +4 -6
- package/lib/react-native/ParseCLP.js +2 -4
- package/lib/react-native/ParseConfig.js +4 -6
- package/lib/react-native/ParseError.js +13 -31
- package/lib/react-native/ParseFile.js +3 -4
- package/lib/react-native/ParseGeoPoint.js +2 -4
- package/lib/react-native/ParseInstallation.js +13 -30
- package/lib/react-native/ParseLiveQuery.js +2 -4
- package/lib/react-native/ParseObject.js +77 -87
- package/lib/react-native/ParseOp.js +41 -79
- package/lib/react-native/ParsePolygon.js +2 -4
- package/lib/react-native/ParseQuery.js +43 -45
- package/lib/react-native/ParseRelation.js +2 -4
- package/lib/react-native/ParseRole.js +13 -30
- package/lib/react-native/ParseSchema.js +3 -5
- package/lib/react-native/ParseSession.js +12 -29
- package/lib/react-native/ParseUser.js +24 -49
- package/lib/react-native/RESTController.js +10 -4
- package/lib/react-native/SingleInstanceStateController.js +23 -37
- package/lib/react-native/Socket.weapp.js +9 -4
- package/lib/react-native/Storage.js +1 -2
- package/lib/react-native/StorageController.browser.js +6 -1
- package/lib/react-native/StorageController.default.js +6 -1
- package/lib/react-native/StorageController.js +13 -1
- package/lib/react-native/StorageController.react-native.js +11 -6
- package/lib/react-native/StorageController.weapp.js +6 -1
- package/lib/react-native/TaskQueue.js +2 -4
- package/lib/react-native/UniqueInstanceStateController.js +23 -37
- package/lib/react-native/WebSocketController.js +9 -1
- package/lib/react-native/Xhr.weapp.js +9 -4
- package/lib/react-native/unsavedChildren.js +3 -3
- package/lib/react-native/uuid.js +1 -2
- package/lib/weapp/Analytics.js +7 -11
- package/lib/weapp/AnonymousUtils.js +17 -22
- package/lib/weapp/Cloud.js +23 -41
- package/lib/weapp/CoreManager.js +71 -79
- package/lib/weapp/CryptoController.js +14 -9
- package/lib/weapp/EventEmitter.js +9 -2
- package/lib/weapp/EventuallyQueue.js +156 -357
- package/lib/weapp/FacebookUtils.js +23 -28
- package/lib/weapp/IndexedDBStorageController.js +18 -14
- package/lib/weapp/InstallationController.js +55 -121
- package/lib/weapp/LiveQueryClient.js +308 -484
- package/lib/weapp/LiveQuerySubscription.js +25 -28
- package/lib/weapp/LocalDatastore.js +258 -624
- package/lib/weapp/LocalDatastoreController.default.js +42 -226
- package/lib/weapp/LocalDatastoreController.js +11 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +66 -160
- package/lib/weapp/LocalDatastoreUtils.js +4 -7
- package/lib/weapp/ObjectStateMutations.js +54 -96
- package/lib/weapp/OfflineQuery.js +106 -198
- package/lib/weapp/Parse.js +44 -59
- package/lib/weapp/ParseACL.js +242 -288
- package/lib/weapp/ParseCLP.js +372 -572
- package/lib/weapp/ParseConfig.js +115 -138
- package/lib/weapp/ParseError.js +85 -182
- package/lib/weapp/ParseFile.js +295 -440
- package/lib/weapp/ParseGeoPoint.js +121 -146
- package/lib/weapp/ParseHooks.js +23 -25
- package/lib/weapp/ParseInstallation.js +225 -367
- package/lib/weapp/ParseLiveQuery.js +74 -148
- package/lib/weapp/ParseObject.js +2014 -2621
- package/lib/weapp/ParseOp.js +343 -484
- package/lib/weapp/ParsePolygon.js +101 -120
- package/lib/weapp/ParseQuery.js +1708 -2052
- package/lib/weapp/ParseRelation.js +99 -118
- package/lib/weapp/ParseRole.js +88 -140
- package/lib/weapp/ParseSchema.js +372 -434
- package/lib/weapp/ParseSession.js +62 -110
- package/lib/weapp/ParseUser.js +941 -1284
- package/lib/weapp/Push.js +15 -38
- package/lib/weapp/RESTController.js +86 -125
- package/lib/weapp/SingleInstanceStateController.js +57 -86
- package/lib/weapp/Socket.weapp.js +50 -33
- package/lib/weapp/Storage.js +23 -28
- package/lib/weapp/StorageController.browser.js +16 -13
- package/lib/weapp/StorageController.default.js +15 -14
- package/lib/weapp/StorageController.js +14 -1
- package/lib/weapp/StorageController.react-native.js +31 -30
- package/lib/weapp/StorageController.weapp.js +19 -13
- package/lib/weapp/TaskQueue.js +31 -43
- package/lib/weapp/UniqueInstanceStateController.js +65 -86
- package/lib/weapp/WebSocketController.js +11 -4
- package/lib/weapp/Xhr.weapp.js +90 -78
- package/lib/weapp/arrayContainsObject.js +3 -3
- package/lib/weapp/canBeSerialized.js +10 -11
- package/lib/weapp/decode.js +11 -11
- package/lib/weapp/encode.js +11 -11
- package/lib/weapp/equals.js +9 -10
- package/lib/weapp/escape.js +2 -2
- package/lib/weapp/isRevocableSession.js +1 -1
- package/lib/weapp/parseDate.js +10 -10
- package/lib/weapp/promiseUtils.js +19 -19
- package/lib/weapp/unique.js +4 -4
- package/lib/weapp/unsavedChildren.js +20 -21
- package/lib/weapp/uuid.js +6 -8
- package/package.json +19 -25
package/lib/browser/Push.js
CHANGED
|
@@ -7,17 +7,8 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getPushStatus = getPushStatus;
|
|
9
9
|
exports.send = send;
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
|
12
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
|
|
13
10
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
14
11
|
var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
15
|
-
/*:: export type PushData = {
|
|
16
|
-
where?: WhereClause | ParseQuery,
|
|
17
|
-
push_time?: Date | string,
|
|
18
|
-
expiration_time?: Date | string,
|
|
19
|
-
expiration_interval?: number,
|
|
20
|
-
};*/
|
|
21
12
|
/**
|
|
22
13
|
* Contains functions to deal with Push in Parse.
|
|
23
14
|
*
|
|
@@ -25,6 +16,7 @@ var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
|
25
16
|
* @static
|
|
26
17
|
* @hideconstructor
|
|
27
18
|
*/
|
|
19
|
+
|
|
28
20
|
/**
|
|
29
21
|
* Sends a push notification.
|
|
30
22
|
* **Available in Cloud Code only.**
|
|
@@ -53,21 +45,21 @@ var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
|
53
45
|
* @returns {Promise} A promise that is fulfilled when the push request
|
|
54
46
|
* completes and returns `pushStatusId`.
|
|
55
47
|
*/
|
|
56
|
-
function send(data
|
|
57
|
-
|
|
48
|
+
function send(data) {
|
|
49
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
58
50
|
if (data.where && data.where instanceof _ParseQuery.default) {
|
|
59
51
|
data.where = data.where.toJSON().where;
|
|
60
52
|
}
|
|
61
|
-
if (data.push_time &&
|
|
53
|
+
if (data.push_time && typeof data.push_time === 'object') {
|
|
62
54
|
data.push_time = data.push_time.toJSON();
|
|
63
55
|
}
|
|
64
|
-
if (data.expiration_time &&
|
|
56
|
+
if (data.expiration_time && typeof data.expiration_time === 'object') {
|
|
65
57
|
data.expiration_time = data.expiration_time.toJSON();
|
|
66
58
|
}
|
|
67
59
|
if (data.expiration_time && data.expiration_interval) {
|
|
68
60
|
throw new Error('expiration_time and expiration_interval cannot both be set.');
|
|
69
61
|
}
|
|
70
|
-
|
|
62
|
+
const pushOptions = {
|
|
71
63
|
useMasterKey: true
|
|
72
64
|
};
|
|
73
65
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
@@ -89,37 +81,22 @@ function send(data /*: PushData*/) /*: Promise<string>*/{
|
|
|
89
81
|
* </ul>
|
|
90
82
|
* @returns {Parse.Object} Status of Push.
|
|
91
83
|
*/
|
|
92
|
-
function getPushStatus(pushStatusId
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
function getPushStatus(pushStatusId) {
|
|
85
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
|
+
const pushOptions = {
|
|
95
87
|
useMasterKey: true
|
|
96
88
|
};
|
|
97
89
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
98
90
|
pushOptions.useMasterKey = options.useMasterKey;
|
|
99
91
|
}
|
|
100
|
-
|
|
92
|
+
const query = new _ParseQuery.default('_PushStatus');
|
|
101
93
|
return query.get(pushStatusId, pushOptions);
|
|
102
94
|
}
|
|
103
|
-
|
|
104
|
-
send
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return _regenerator.default.wrap(function (_context) {
|
|
109
|
-
while (1) switch (_context.prev = _context.next) {
|
|
110
|
-
case 0:
|
|
111
|
-
options.returnStatus = true;
|
|
112
|
-
_context.next = 3;
|
|
113
|
-
return _CoreManager.default.getRESTController().request('POST', 'push', data, options);
|
|
114
|
-
case 3:
|
|
115
|
-
response = _context.sent;
|
|
116
|
-
return _context.abrupt("return", (_response$_headers = response._headers) === null || _response$_headers === void 0 ? void 0 : _response$_headers['X-Parse-Push-Status-Id']);
|
|
117
|
-
case 5:
|
|
118
|
-
case "end":
|
|
119
|
-
return _context.stop();
|
|
120
|
-
}
|
|
121
|
-
}, _callee);
|
|
122
|
-
}))();
|
|
95
|
+
const DefaultController = {
|
|
96
|
+
async send(data, options) {
|
|
97
|
+
options.returnStatus = true;
|
|
98
|
+
const response = await _CoreManager.default.getRESTController().request('POST', 'push', data, options);
|
|
99
|
+
return response._headers?.['X-Parse-Push-Status-Id'];
|
|
123
100
|
}
|
|
124
101
|
};
|
|
125
102
|
_CoreManager.default.setPushController(DefaultController);
|
|
@@ -1,86 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
5
|
-
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
6
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
7
|
-
var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
8
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
9
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
10
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
11
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
14
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
15
10
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
16
11
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
17
|
-
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
18
12
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
13
|
+
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
19
14
|
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
15
|
+
var _uuid = _interopRequireDefault(require("./uuid"));
|
|
20
16
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
21
17
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
22
18
|
var _promiseUtils = require("./promiseUtils");
|
|
23
|
-
|
|
24
|
-
var keys = _Object$keys(object);
|
|
25
|
-
if (_Object$getOwnPropertySymbols) {
|
|
26
|
-
var symbols = _Object$getOwnPropertySymbols(object);
|
|
27
|
-
enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) {
|
|
28
|
-
return _Object$getOwnPropertyDescriptor(object, sym).enumerable;
|
|
29
|
-
})), keys.push.apply(keys, symbols);
|
|
30
|
-
}
|
|
31
|
-
return keys;
|
|
32
|
-
}
|
|
33
|
-
function _objectSpread(target) {
|
|
34
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
35
|
-
var _context2, _context3;
|
|
36
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
37
|
-
i % 2 ? _forEachInstanceProperty2(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) {
|
|
38
|
-
(0, _defineProperty2.default)(target, key, source[key]);
|
|
39
|
-
}) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context3 = ownKeys(Object(source))).call(_context3, function (key) {
|
|
40
|
-
_Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return target;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @flow
|
|
47
|
-
*/
|
|
19
|
+
var _Xhr = _interopRequireDefault(require("./Xhr.weapp"));
|
|
48
20
|
/* global XMLHttpRequest, XDomainRequest */
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
useMasterKey?: boolean,
|
|
52
|
-
sessionToken?: string,
|
|
53
|
-
installationId?: string,
|
|
54
|
-
returnStatus?: boolean,
|
|
55
|
-
batchSize?: number,
|
|
56
|
-
include?: any,
|
|
57
|
-
progress?: any,
|
|
58
|
-
context?: any,
|
|
59
|
-
usePost?: boolean,
|
|
60
|
-
ignoreEmailVerification?: boolean,
|
|
61
|
-
};*/
|
|
62
|
-
/*:: export type FullOptions = {
|
|
63
|
-
success?: any,
|
|
64
|
-
error?: any,
|
|
65
|
-
useMasterKey?: boolean,
|
|
66
|
-
sessionToken?: string,
|
|
67
|
-
installationId?: string,
|
|
68
|
-
progress?: any,
|
|
69
|
-
usePost?: boolean,
|
|
70
|
-
};*/
|
|
71
|
-
var XHR = null;
|
|
21
|
+
|
|
22
|
+
let XHR = null;
|
|
72
23
|
if (typeof XMLHttpRequest !== 'undefined') {
|
|
73
24
|
XHR = XMLHttpRequest;
|
|
74
25
|
}
|
|
75
|
-
|
|
26
|
+
let useXDomainRequest = false;
|
|
27
|
+
// @ts-ignore
|
|
76
28
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
77
29
|
useXDomainRequest = true;
|
|
78
30
|
}
|
|
79
|
-
function ajaxIE9(method
|
|
80
|
-
return new _promise.default(
|
|
81
|
-
|
|
31
|
+
function ajaxIE9(method, url, data, headers, options) {
|
|
32
|
+
return new _promise.default((resolve, reject) => {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const xdr = new XDomainRequest();
|
|
82
35
|
xdr.onload = function () {
|
|
83
|
-
|
|
36
|
+
let response;
|
|
84
37
|
try {
|
|
85
38
|
response = JSON.parse(xdr.responseText);
|
|
86
39
|
} catch (e) {
|
|
@@ -88,13 +41,13 @@ function ajaxIE9(method /*: string*/, url /*: string*/, data /*: any*/, headers
|
|
|
88
41
|
}
|
|
89
42
|
if (response) {
|
|
90
43
|
resolve({
|
|
91
|
-
response
|
|
44
|
+
response
|
|
92
45
|
});
|
|
93
46
|
}
|
|
94
47
|
};
|
|
95
48
|
xdr.onerror = xdr.ontimeout = function () {
|
|
96
49
|
// Let's fake a real error message.
|
|
97
|
-
|
|
50
|
+
const fakeResponse = {
|
|
98
51
|
responseText: (0, _stringify.default)({
|
|
99
52
|
code: _ParseError.default.X_DOMAIN_REQUEST,
|
|
100
53
|
error: "IE's XDomainRequest does not supply error info."
|
|
@@ -109,41 +62,43 @@ function ajaxIE9(method /*: string*/, url /*: string*/, data /*: any*/, headers
|
|
|
109
62
|
};
|
|
110
63
|
xdr.open(method, url);
|
|
111
64
|
xdr.send(data);
|
|
65
|
+
// @ts-ignore
|
|
112
66
|
if (options && typeof options.requestTask === 'function') {
|
|
67
|
+
// @ts-ignore
|
|
113
68
|
options.requestTask(xdr);
|
|
114
69
|
}
|
|
115
70
|
});
|
|
116
71
|
}
|
|
117
|
-
|
|
118
|
-
ajax
|
|
72
|
+
const RESTController = {
|
|
73
|
+
ajax(method, url, data, headers, options) {
|
|
119
74
|
var _context;
|
|
120
75
|
if (useXDomainRequest) {
|
|
121
76
|
return ajaxIE9(method, url, data, headers, options);
|
|
122
77
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
78
|
+
const promise = (0, _promiseUtils.resolvingPromise)();
|
|
79
|
+
const isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && (0, _includes.default)(_context = ['POST', 'PUT']).call(_context, method);
|
|
80
|
+
const requestId = isIdempotent ? (0, _uuid.default)() : '';
|
|
81
|
+
let attempts = 0;
|
|
82
|
+
const dispatch = function () {
|
|
128
83
|
if (XHR == null) {
|
|
129
84
|
throw new Error('Cannot make a request: No definition of XMLHttpRequest was found.');
|
|
130
85
|
}
|
|
131
|
-
|
|
132
|
-
|
|
86
|
+
let handled = false;
|
|
87
|
+
const xhr = new XHR();
|
|
133
88
|
xhr.onreadystatechange = function () {
|
|
134
89
|
if (xhr.readyState !== 4 || handled || xhr._aborted) {
|
|
135
90
|
return;
|
|
136
91
|
}
|
|
137
92
|
handled = true;
|
|
138
93
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
139
|
-
|
|
94
|
+
let response;
|
|
140
95
|
try {
|
|
141
96
|
response = JSON.parse(xhr.responseText);
|
|
142
|
-
|
|
97
|
+
const availableHeaders = typeof xhr.getAllResponseHeaders === 'function' ? xhr.getAllResponseHeaders() : '';
|
|
143
98
|
headers = {};
|
|
144
|
-
if (typeof xhr.getResponseHeader === 'function' &&
|
|
145
|
-
|
|
146
|
-
(0, _forEach.default)(responseHeaders).call(responseHeaders,
|
|
99
|
+
if (typeof xhr.getResponseHeader === 'function' && availableHeaders?.indexOf('access-control-expose-headers') >= 0) {
|
|
100
|
+
const responseHeaders = xhr.getResponseHeader('access-control-expose-headers').split(', ');
|
|
101
|
+
(0, _forEach.default)(responseHeaders).call(responseHeaders, header => {
|
|
147
102
|
if ((0, _indexOf.default)(availableHeaders).call(availableHeaders, header.toLowerCase()) >= 0) {
|
|
148
103
|
headers[header] = xhr.getResponseHeader(header.toLowerCase());
|
|
149
104
|
}
|
|
@@ -154,17 +109,17 @@ var RESTController = {
|
|
|
154
109
|
}
|
|
155
110
|
if (response) {
|
|
156
111
|
promise.resolve({
|
|
157
|
-
response
|
|
158
|
-
headers
|
|
112
|
+
response,
|
|
113
|
+
headers,
|
|
159
114
|
status: xhr.status,
|
|
160
|
-
xhr
|
|
115
|
+
xhr
|
|
161
116
|
});
|
|
162
117
|
}
|
|
163
118
|
} else if (xhr.status >= 500 || xhr.status === 0) {
|
|
164
119
|
// retry on 5XX or node-xmlhttprequest error
|
|
165
120
|
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
166
121
|
// Exponentially-growing random delay
|
|
167
|
-
|
|
122
|
+
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
168
123
|
(0, _setTimeout2.default)(dispatch, delay);
|
|
169
124
|
} else if (xhr.status === 0) {
|
|
170
125
|
promise.reject('Unable to connect to the Parse API');
|
|
@@ -180,7 +135,6 @@ var RESTController = {
|
|
|
180
135
|
if (typeof headers['Content-Type'] !== 'string') {
|
|
181
136
|
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight
|
|
182
137
|
}
|
|
183
|
-
|
|
184
138
|
if (_CoreManager.default.get('IS_NODE')) {
|
|
185
139
|
headers['User-Agent'] = 'Parse/' + _CoreManager.default.get('VERSION') + ' (NodeJS ' + process.versions.node + ')';
|
|
186
140
|
}
|
|
@@ -190,33 +144,33 @@ var RESTController = {
|
|
|
190
144
|
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
191
145
|
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
192
146
|
}
|
|
193
|
-
|
|
194
|
-
for (
|
|
147
|
+
const customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
148
|
+
for (const key in customHeaders) {
|
|
195
149
|
headers[key] = customHeaders[key];
|
|
196
150
|
}
|
|
197
151
|
if (options && typeof options.progress === 'function') {
|
|
198
|
-
|
|
152
|
+
const handleProgress = function (type, event) {
|
|
199
153
|
if (event.lengthComputable) {
|
|
200
154
|
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
201
|
-
type
|
|
155
|
+
type
|
|
202
156
|
});
|
|
203
157
|
} else {
|
|
204
158
|
options.progress(null, null, null, {
|
|
205
|
-
type
|
|
159
|
+
type
|
|
206
160
|
});
|
|
207
161
|
}
|
|
208
162
|
};
|
|
209
|
-
xhr.onprogress =
|
|
163
|
+
xhr.onprogress = event => {
|
|
210
164
|
handleProgress('download', event);
|
|
211
165
|
};
|
|
212
166
|
if (xhr.upload) {
|
|
213
|
-
xhr.upload.onprogress =
|
|
167
|
+
xhr.upload.onprogress = event => {
|
|
214
168
|
handleProgress('upload', event);
|
|
215
169
|
};
|
|
216
170
|
}
|
|
217
171
|
}
|
|
218
172
|
xhr.open(method, url, true);
|
|
219
|
-
for (
|
|
173
|
+
for (const h in headers) {
|
|
220
174
|
xhr.setRequestHeader(h, headers[h]);
|
|
221
175
|
}
|
|
222
176
|
xhr.onabort = function () {
|
|
@@ -225,32 +179,35 @@ var RESTController = {
|
|
|
225
179
|
results: []
|
|
226
180
|
},
|
|
227
181
|
status: 0,
|
|
228
|
-
xhr
|
|
182
|
+
xhr
|
|
229
183
|
});
|
|
230
184
|
};
|
|
231
185
|
xhr.send(data);
|
|
186
|
+
// @ts-ignore
|
|
232
187
|
if (options && typeof options.requestTask === 'function') {
|
|
188
|
+
// @ts-ignore
|
|
233
189
|
options.requestTask(xhr);
|
|
234
190
|
}
|
|
235
|
-
}
|
|
191
|
+
};
|
|
192
|
+
dispatch();
|
|
236
193
|
return promise;
|
|
237
194
|
},
|
|
238
|
-
request
|
|
195
|
+
request(method, path, data, options) {
|
|
239
196
|
options = options || {};
|
|
240
|
-
|
|
197
|
+
let url = _CoreManager.default.get('SERVER_URL');
|
|
241
198
|
if (url[url.length - 1] !== '/') {
|
|
242
199
|
url += '/';
|
|
243
200
|
}
|
|
244
201
|
url += path;
|
|
245
|
-
|
|
246
|
-
if (data &&
|
|
247
|
-
for (
|
|
202
|
+
const payload = {};
|
|
203
|
+
if (data && typeof data === 'object') {
|
|
204
|
+
for (const k in data) {
|
|
248
205
|
payload[k] = data[k];
|
|
249
206
|
}
|
|
250
207
|
}
|
|
251
208
|
|
|
252
209
|
// Add context
|
|
253
|
-
|
|
210
|
+
const context = options.context;
|
|
254
211
|
if (context !== undefined) {
|
|
255
212
|
payload._context = context;
|
|
256
213
|
}
|
|
@@ -259,12 +216,12 @@ var RESTController = {
|
|
|
259
216
|
method = 'POST';
|
|
260
217
|
}
|
|
261
218
|
payload._ApplicationId = _CoreManager.default.get('APPLICATION_ID');
|
|
262
|
-
|
|
219
|
+
const jsKey = _CoreManager.default.get('JAVASCRIPT_KEY');
|
|
263
220
|
if (jsKey) {
|
|
264
221
|
payload._JavaScriptKey = jsKey;
|
|
265
222
|
}
|
|
266
223
|
payload._ClientVersion = _CoreManager.default.get('VERSION');
|
|
267
|
-
|
|
224
|
+
let useMasterKey = options.useMasterKey;
|
|
268
225
|
if (typeof useMasterKey === 'undefined') {
|
|
269
226
|
useMasterKey = _CoreManager.default.get('USE_MASTER_KEY');
|
|
270
227
|
}
|
|
@@ -279,21 +236,21 @@ var RESTController = {
|
|
|
279
236
|
if (_CoreManager.default.get('FORCE_REVOCABLE_SESSION')) {
|
|
280
237
|
payload._RevocableSession = '1';
|
|
281
238
|
}
|
|
282
|
-
|
|
283
|
-
|
|
239
|
+
const installationId = options.installationId;
|
|
240
|
+
let installationIdPromise;
|
|
284
241
|
if (installationId && typeof installationId === 'string') {
|
|
285
242
|
installationIdPromise = _promise.default.resolve(installationId);
|
|
286
243
|
} else {
|
|
287
|
-
|
|
244
|
+
const installationController = _CoreManager.default.getInstallationController();
|
|
288
245
|
installationIdPromise = installationController.currentInstallationId();
|
|
289
246
|
}
|
|
290
|
-
return installationIdPromise.then(
|
|
247
|
+
return installationIdPromise.then(iid => {
|
|
291
248
|
payload._InstallationId = iid;
|
|
292
|
-
|
|
249
|
+
const userController = _CoreManager.default.getUserController();
|
|
293
250
|
if (options && typeof options.sessionToken === 'string') {
|
|
294
251
|
return _promise.default.resolve(options.sessionToken);
|
|
295
252
|
} else if (userController) {
|
|
296
|
-
return userController.currentUserAsync().then(
|
|
253
|
+
return userController.currentUserAsync().then(user => {
|
|
297
254
|
if (user) {
|
|
298
255
|
return _promise.default.resolve(user.getSessionToken());
|
|
299
256
|
}
|
|
@@ -301,51 +258,55 @@ var RESTController = {
|
|
|
301
258
|
});
|
|
302
259
|
}
|
|
303
260
|
return _promise.default.resolve(null);
|
|
304
|
-
}).then(
|
|
261
|
+
}).then(token => {
|
|
305
262
|
if (token) {
|
|
306
263
|
payload._SessionToken = token;
|
|
307
264
|
}
|
|
308
|
-
|
|
309
|
-
return RESTController.ajax(method, url, payloadString, {}, options).then(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
265
|
+
const payloadString = (0, _stringify.default)(payload);
|
|
266
|
+
return RESTController.ajax(method, url, payloadString, {}, options).then(_ref => {
|
|
267
|
+
let {
|
|
268
|
+
response,
|
|
269
|
+
status,
|
|
270
|
+
headers,
|
|
271
|
+
xhr
|
|
272
|
+
} = _ref;
|
|
314
273
|
if (options.returnStatus) {
|
|
315
|
-
return
|
|
274
|
+
return {
|
|
275
|
+
...response,
|
|
316
276
|
_status: status,
|
|
317
277
|
_headers: headers,
|
|
318
278
|
_xhr: xhr
|
|
319
|
-
}
|
|
279
|
+
};
|
|
320
280
|
} else {
|
|
321
281
|
return response;
|
|
322
282
|
}
|
|
323
283
|
});
|
|
324
284
|
}).catch(RESTController.handleError);
|
|
325
285
|
},
|
|
326
|
-
handleError
|
|
286
|
+
handleError(response) {
|
|
327
287
|
// Transform the error into an instance of ParseError by trying to parse
|
|
328
288
|
// the error string as JSON
|
|
329
|
-
|
|
289
|
+
let error;
|
|
330
290
|
if (response && response.responseText) {
|
|
331
291
|
try {
|
|
332
|
-
|
|
292
|
+
const errorJSON = JSON.parse(response.responseText);
|
|
333
293
|
error = new _ParseError.default(errorJSON.code, errorJSON.error);
|
|
334
294
|
} catch (e) {
|
|
335
295
|
// If we fail to parse the error text, that's okay.
|
|
336
296
|
error = new _ParseError.default(_ParseError.default.INVALID_JSON, 'Received an error with invalid JSON from Parse: ' + response.responseText);
|
|
337
297
|
}
|
|
338
298
|
} else {
|
|
339
|
-
|
|
299
|
+
const message = response.message ? response.message : response;
|
|
340
300
|
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + (0, _stringify.default)(message));
|
|
341
301
|
}
|
|
342
302
|
return _promise.default.reject(error);
|
|
343
303
|
},
|
|
344
|
-
_setXHR
|
|
304
|
+
_setXHR(xhr) {
|
|
345
305
|
XHR = xhr;
|
|
346
306
|
},
|
|
347
|
-
_getXHR
|
|
307
|
+
_getXHR() {
|
|
348
308
|
return XHR;
|
|
349
309
|
}
|
|
350
310
|
};
|
|
351
|
-
module.exports = RESTController;
|
|
311
|
+
module.exports = RESTController;
|
|
312
|
+
var _default = exports.default = RESTController;
|