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