parse 3.5.1 → 4.0.0-alpha.10
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/LICENSE +167 -25
- package/NOTICE +10 -0
- package/README.md +20 -7
- package/dist/parse.js +12838 -21190
- package/dist/parse.min.js +7 -6
- package/dist/parse.weapp.js +7921 -17062
- package/dist/parse.weapp.min.js +7 -6
- package/lib/browser/Analytics.js +2 -27
- package/lib/browser/AnonymousUtils.js +6 -42
- package/lib/browser/Cloud.js +12 -77
- package/lib/browser/CloudCode.js +0 -3
- package/lib/browser/CoreManager.js +46 -191
- package/lib/browser/CryptoController.js +2 -16
- package/lib/browser/EventEmitter.js +1 -8
- package/lib/browser/EventuallyQueue.js +277 -824
- package/lib/browser/FacebookUtils.js +6 -42
- package/lib/browser/IndexedDBStorageController.js +3 -14
- package/lib/browser/InstallationController.js +2 -20
- package/lib/browser/LiveQueryClient.js +105 -213
- package/lib/browser/LiveQuerySubscription.js +10 -39
- package/lib/browser/LocalDatastore.js +451 -1081
- package/lib/browser/LocalDatastoreController.js +145 -602
- package/lib/browser/LocalDatastoreController.react-native.js +137 -573
- package/lib/browser/LocalDatastoreUtils.js +2 -19
- package/lib/browser/ObjectStateMutations.js +18 -121
- package/lib/browser/OfflineQuery.js +61 -222
- package/lib/browser/Parse.js +12 -115
- package/lib/browser/ParseACL.js +33 -148
- package/lib/browser/ParseCLP.js +96 -314
- package/lib/browser/ParseConfig.js +18 -95
- package/lib/browser/ParseError.js +63 -99
- package/lib/browser/ParseFile.js +128 -685
- package/lib/browser/ParseGeoPoint.js +23 -89
- package/lib/browser/ParseHooks.js +1 -34
- package/lib/browser/ParseInstallation.js +4 -32
- package/lib/browser/ParseLiveQuery.js +96 -505
- package/lib/browser/ParseObject.js +665 -1845
- package/lib/browser/ParseOp.js +41 -287
- package/lib/browser/ParsePolygon.js +13 -70
- package/lib/browser/ParseQuery.js +403 -1504
- package/lib/browser/ParseRelation.js +12 -68
- package/lib/browser/ParseRole.js +13 -75
- package/lib/browser/ParseSchema.js +49 -208
- package/lib/browser/ParseSession.js +11 -69
- package/lib/browser/ParseUser.js +274 -1127
- package/lib/browser/Push.js +7 -50
- package/lib/browser/RESTController.js +28 -157
- package/lib/browser/SingleInstanceStateController.js +19 -144
- package/lib/browser/Socket.weapp.js +0 -10
- package/lib/browser/Storage.js +10 -80
- package/lib/browser/StorageController.browser.js +4 -24
- package/lib/browser/StorageController.default.js +4 -24
- package/lib/browser/StorageController.react-native.js +6 -40
- package/lib/browser/StorageController.weapp.js +5 -23
- package/lib/browser/TaskQueue.js +1 -29
- package/lib/browser/UniqueInstanceStateController.js +19 -149
- package/lib/browser/Xhr.weapp.js +0 -17
- package/lib/browser/arrayContainsObject.js +2 -23
- package/lib/browser/canBeSerialized.js +3 -40
- package/lib/browser/decode.js +3 -40
- package/lib/browser/encode.js +9 -77
- package/lib/browser/equals.js +2 -34
- package/lib/browser/escape.js +1 -15
- package/lib/browser/isRevocableSession.js +2 -18
- package/lib/browser/parseDate.js +2 -20
- package/lib/browser/promiseUtils.js +3 -21
- package/lib/browser/unique.js +3 -24
- package/lib/browser/unsavedChildren.js +6 -57
- package/lib/browser/uuid.js +3 -1
- package/lib/node/Analytics.js +1 -25
- package/lib/node/AnonymousUtils.js +5 -44
- package/lib/node/Cloud.js +10 -73
- package/lib/node/CloudCode.js +0 -3
- package/lib/node/CoreManager.js +47 -227
- package/lib/node/CryptoController.js +2 -16
- package/lib/node/EventEmitter.js +1 -8
- package/lib/node/EventuallyQueue.js +16 -123
- package/lib/node/FacebookUtils.js +5 -44
- package/lib/node/IndexedDBStorageController.js +3 -19
- package/lib/node/InstallationController.js +2 -22
- package/lib/node/LiveQueryClient.js +72 -154
- package/lib/node/LiveQuerySubscription.js +7 -26
- package/lib/node/LocalDatastore.js +19 -182
- package/lib/node/LocalDatastoreController.js +6 -45
- package/lib/node/LocalDatastoreController.react-native.js +6 -52
- package/lib/node/LocalDatastoreUtils.js +1 -13
- package/lib/node/ObjectStateMutations.js +18 -134
- package/lib/node/OfflineQuery.js +27 -151
- package/lib/node/Parse.js +11 -108
- package/lib/node/ParseACL.js +32 -157
- package/lib/node/ParseCLP.js +73 -302
- package/lib/node/ParseConfig.js +16 -91
- package/lib/node/ParseError.js +61 -74
- package/lib/node/ParseFile.js +55 -244
- package/lib/node/ParseGeoPoint.js +21 -89
- package/lib/node/ParseHooks.js +0 -35
- package/lib/node/ParseInstallation.js +1 -17
- package/lib/node/ParseLiveQuery.js +10 -43
- package/lib/node/ParseObject.js +234 -997
- package/lib/node/ParseOp.js +31 -262
- package/lib/node/ParsePolygon.js +12 -69
- package/lib/node/ParseQuery.js +169 -888
- package/lib/node/ParseRelation.js +11 -68
- package/lib/node/ParseRole.js +10 -64
- package/lib/node/ParseSchema.js +46 -229
- package/lib/node/ParseSession.js +8 -57
- package/lib/node/ParseUser.js +107 -583
- package/lib/node/Push.js +4 -44
- package/lib/node/RESTController.js +19 -169
- package/lib/node/SingleInstanceStateController.js +17 -137
- package/lib/node/Socket.weapp.js +0 -7
- package/lib/node/Storage.js +10 -90
- package/lib/node/StorageController.browser.js +4 -30
- package/lib/node/StorageController.default.js +5 -28
- package/lib/node/StorageController.react-native.js +6 -47
- package/lib/node/StorageController.weapp.js +6 -28
- package/lib/node/TaskQueue.js +1 -24
- package/lib/node/UniqueInstanceStateController.js +16 -140
- package/lib/node/Xhr.weapp.js +0 -15
- package/lib/node/arrayContainsObject.js +1 -19
- package/lib/node/canBeSerialized.js +2 -35
- package/lib/node/decode.js +1 -33
- package/lib/node/encode.js +3 -61
- package/lib/node/equals.js +0 -27
- package/lib/node/escape.js +1 -13
- package/lib/node/isRevocableSession.js +1 -12
- package/lib/node/parseDate.js +1 -14
- package/lib/node/promiseUtils.js +2 -14
- package/lib/node/unique.js +1 -18
- package/lib/node/unsavedChildren.js +2 -45
- package/lib/node/uuid.js +6 -1
- package/lib/react-native/Analytics.js +0 -9
- package/lib/react-native/AnonymousUtils.js +0 -10
- package/lib/react-native/Cloud.js +0 -26
- package/lib/react-native/CoreManager.js +2 -6
- package/lib/react-native/CryptoController.js +0 -2
- package/lib/react-native/EventEmitter.js +0 -2
- package/lib/react-native/EventuallyQueue.js +156 -711
- package/lib/react-native/FacebookUtils.js +0 -22
- package/lib/react-native/IndexedDBStorageController.js +0 -1
- package/lib/react-native/InstallationController.js +0 -6
- package/lib/react-native/LiveQueryClient.js +46 -157
- package/lib/react-native/LiveQuerySubscription.js +3 -27
- package/lib/react-native/LocalDatastore.js +281 -948
- package/lib/react-native/LocalDatastoreController.js +71 -552
- package/lib/react-native/LocalDatastoreController.react-native.js +91 -526
- package/lib/react-native/LocalDatastoreUtils.js +0 -1
- package/lib/react-native/ObjectStateMutations.js +2 -65
- package/lib/react-native/OfflineQuery.js +25 -196
- package/lib/react-native/Parse.js +0 -65
- package/lib/react-native/ParseACL.js +0 -44
- package/lib/react-native/ParseCLP.js +23 -161
- package/lib/react-native/ParseConfig.js +0 -42
- package/lib/react-native/ParseError.js +1 -21
- package/lib/react-native/ParseFile.js +55 -529
- package/lib/react-native/ParseGeoPoint.js +0 -17
- package/lib/react-native/ParseHooks.js +0 -30
- package/lib/react-native/ParseInstallation.js +1 -23
- package/lib/react-native/ParseLiveQuery.js +55 -472
- package/lib/react-native/ParseObject.js +245 -1246
- package/lib/react-native/ParseOp.js +1 -138
- package/lib/react-native/ParsePolygon.js +0 -24
- package/lib/react-native/ParseQuery.js +182 -874
- package/lib/react-native/ParseRelation.js +0 -25
- package/lib/react-native/ParseRole.js +1 -36
- package/lib/react-native/ParseSchema.js +3 -54
- package/lib/react-native/ParseSession.js +1 -40
- package/lib/react-native/ParseUser.js +95 -773
- package/lib/react-native/Push.js +0 -16
- package/lib/react-native/RESTController.js +12 -109
- package/lib/react-native/SingleInstanceStateController.js +0 -44
- package/lib/react-native/Socket.weapp.js +0 -10
- package/lib/react-native/Storage.js +0 -24
- package/lib/react-native/StorageController.browser.js +0 -2
- package/lib/react-native/StorageController.default.js +0 -1
- package/lib/react-native/StorageController.react-native.js +0 -2
- package/lib/react-native/TaskQueue.js +0 -15
- package/lib/react-native/UniqueInstanceStateController.js +0 -47
- package/lib/react-native/Xhr.weapp.js +0 -16
- package/lib/react-native/arrayContainsObject.js +0 -5
- package/lib/react-native/canBeSerialized.js +0 -18
- package/lib/react-native/decode.js +0 -21
- package/lib/react-native/encode.js +0 -25
- package/lib/react-native/equals.js +0 -18
- package/lib/react-native/escape.js +0 -1
- package/lib/react-native/isRevocableSession.js +0 -1
- package/lib/react-native/parseDate.js +0 -3
- package/lib/react-native/promiseUtils.js +0 -13
- package/lib/react-native/unique.js +0 -4
- package/lib/react-native/unsavedChildren.js +0 -21
- package/lib/react-native/uuid.js +3 -1
- package/lib/weapp/Analytics.js +2 -27
- package/lib/weapp/AnonymousUtils.js +6 -42
- package/lib/weapp/Cloud.js +12 -77
- package/lib/weapp/CloudCode.js +0 -3
- package/lib/weapp/CoreManager.js +46 -191
- package/lib/weapp/CryptoController.js +2 -16
- package/lib/weapp/EventEmitter.js +1 -8
- package/lib/weapp/EventuallyQueue.js +277 -824
- package/lib/weapp/FacebookUtils.js +6 -42
- package/lib/weapp/IndexedDBStorageController.js +3 -14
- package/lib/weapp/InstallationController.js +2 -20
- package/lib/weapp/LiveQueryClient.js +105 -213
- package/lib/weapp/LiveQuerySubscription.js +10 -39
- package/lib/weapp/LocalDatastore.js +451 -1081
- package/lib/weapp/LocalDatastoreController.js +145 -602
- package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
- package/lib/weapp/LocalDatastoreUtils.js +2 -19
- package/lib/weapp/ObjectStateMutations.js +18 -121
- package/lib/weapp/OfflineQuery.js +61 -222
- package/lib/weapp/Parse.js +12 -115
- package/lib/weapp/ParseACL.js +33 -148
- package/lib/weapp/ParseCLP.js +96 -314
- package/lib/weapp/ParseConfig.js +18 -95
- package/lib/weapp/ParseError.js +63 -99
- package/lib/weapp/ParseFile.js +129 -686
- package/lib/weapp/ParseGeoPoint.js +23 -89
- package/lib/weapp/ParseHooks.js +1 -34
- package/lib/weapp/ParseInstallation.js +4 -32
- package/lib/weapp/ParseLiveQuery.js +96 -505
- package/lib/weapp/ParseObject.js +665 -1845
- package/lib/weapp/ParseOp.js +41 -287
- package/lib/weapp/ParsePolygon.js +13 -70
- package/lib/weapp/ParseQuery.js +403 -1504
- package/lib/weapp/ParseRelation.js +12 -68
- package/lib/weapp/ParseRole.js +13 -75
- package/lib/weapp/ParseSchema.js +49 -208
- package/lib/weapp/ParseSession.js +11 -69
- package/lib/weapp/ParseUser.js +274 -1127
- package/lib/weapp/Push.js +7 -50
- package/lib/weapp/RESTController.js +28 -157
- package/lib/weapp/SingleInstanceStateController.js +19 -144
- package/lib/weapp/Socket.weapp.js +0 -10
- package/lib/weapp/Storage.js +10 -80
- package/lib/weapp/StorageController.browser.js +4 -24
- package/lib/weapp/StorageController.default.js +4 -24
- package/lib/weapp/StorageController.react-native.js +6 -40
- package/lib/weapp/StorageController.weapp.js +5 -23
- package/lib/weapp/TaskQueue.js +1 -29
- package/lib/weapp/UniqueInstanceStateController.js +19 -149
- package/lib/weapp/Xhr.weapp.js +0 -17
- package/lib/weapp/arrayContainsObject.js +2 -23
- package/lib/weapp/canBeSerialized.js +3 -40
- package/lib/weapp/decode.js +3 -40
- package/lib/weapp/encode.js +9 -77
- package/lib/weapp/equals.js +2 -34
- package/lib/weapp/escape.js +1 -15
- package/lib/weapp/isRevocableSession.js +2 -18
- package/lib/weapp/parseDate.js +2 -20
- package/lib/weapp/promiseUtils.js +3 -21
- package/lib/weapp/unique.js +3 -24
- package/lib/weapp/unsavedChildren.js +6 -57
- package/lib/weapp/uuid.js +1 -6
- package/package.json +37 -30
- package/PATENTS +0 -37
package/lib/node/Push.js
CHANGED
|
@@ -5,24 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getPushStatus = getPushStatus;
|
|
7
7
|
exports.send = send;
|
|
8
|
-
|
|
9
8
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
10
|
-
|
|
11
9
|
var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) {
|
|
14
11
|
return obj && obj.__esModule ? obj : {
|
|
15
12
|
default: obj
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
|
-
* Copyright (c) 2015-present, Parse, LLC.
|
|
20
|
-
* All rights reserved.
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the BSD-style license found in the
|
|
23
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
24
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
25
|
-
*
|
|
26
16
|
* @flow
|
|
27
17
|
*/
|
|
28
18
|
|
|
@@ -62,41 +52,28 @@ function _interopRequireDefault(obj) {
|
|
|
62
52
|
* @returns {Promise} A promise that is fulfilled when the push request
|
|
63
53
|
* completes.
|
|
64
54
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function send(data
|
|
68
|
-
/*: PushData*/
|
|
69
|
-
, options
|
|
70
|
-
/*:: ?: FullOptions*/
|
|
71
|
-
= {})
|
|
72
|
-
/*: Promise*/
|
|
73
|
-
{
|
|
55
|
+
function send(data /*: PushData*/, options /*:: ?: FullOptions*/ = {}) /*: Promise*/{
|
|
74
56
|
if (data.where && data.where instanceof _ParseQuery.default) {
|
|
75
57
|
data.where = data.where.toJSON().where;
|
|
76
58
|
}
|
|
77
|
-
|
|
78
59
|
if (data.push_time && typeof data.push_time === 'object') {
|
|
79
60
|
data.push_time = data.push_time.toJSON();
|
|
80
61
|
}
|
|
81
|
-
|
|
82
62
|
if (data.expiration_time && typeof data.expiration_time === 'object') {
|
|
83
63
|
data.expiration_time = data.expiration_time.toJSON();
|
|
84
64
|
}
|
|
85
|
-
|
|
86
65
|
if (data.expiration_time && data.expiration_interval) {
|
|
87
66
|
throw new Error('expiration_time and expiration_interval cannot both be set.');
|
|
88
67
|
}
|
|
89
|
-
|
|
90
68
|
const pushOptions = {
|
|
91
69
|
useMasterKey: true
|
|
92
70
|
};
|
|
93
|
-
|
|
94
71
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
95
72
|
pushOptions.useMasterKey = options.useMasterKey;
|
|
96
73
|
}
|
|
97
|
-
|
|
98
74
|
return _CoreManager.default.getPushController().send(data, pushOptions);
|
|
99
75
|
}
|
|
76
|
+
|
|
100
77
|
/**
|
|
101
78
|
* Gets push status by Id
|
|
102
79
|
*
|
|
@@ -110,36 +87,19 @@ function send(data
|
|
|
110
87
|
* </ul>
|
|
111
88
|
* @returns {Parse.Object} Status of Push.
|
|
112
89
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
function getPushStatus(pushStatusId
|
|
116
|
-
/*: string*/
|
|
117
|
-
, options
|
|
118
|
-
/*:: ?: FullOptions*/
|
|
119
|
-
= {})
|
|
120
|
-
/*: Promise<string>*/
|
|
121
|
-
{
|
|
90
|
+
function getPushStatus(pushStatusId /*: string*/, options /*:: ?: FullOptions*/ = {}) /*: Promise<string>*/{
|
|
122
91
|
const pushOptions = {
|
|
123
92
|
useMasterKey: true
|
|
124
93
|
};
|
|
125
|
-
|
|
126
94
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
127
95
|
pushOptions.useMasterKey = options.useMasterKey;
|
|
128
96
|
}
|
|
129
|
-
|
|
130
97
|
const query = new _ParseQuery.default('_PushStatus');
|
|
131
98
|
return query.get(pushStatusId, pushOptions);
|
|
132
99
|
}
|
|
133
|
-
|
|
134
100
|
const DefaultController = {
|
|
135
|
-
send(data
|
|
136
|
-
/*: PushData*/
|
|
137
|
-
, options
|
|
138
|
-
/*:: ?: FullOptions*/
|
|
139
|
-
) {
|
|
101
|
+
send(data /*: PushData*/, options /*:: ?: FullOptions*/) {
|
|
140
102
|
return _CoreManager.default.getRESTController().request('POST', 'push', data, options);
|
|
141
103
|
}
|
|
142
|
-
|
|
143
104
|
};
|
|
144
|
-
|
|
145
105
|
_CoreManager.default.setPushController(DefaultController);
|
|
@@ -1,116 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
4
|
-
|
|
5
4
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
6
|
-
|
|
7
5
|
var _promiseUtils = require("./promiseUtils");
|
|
8
|
-
|
|
9
6
|
function _interopRequireDefault(obj) {
|
|
10
7
|
return obj && obj.__esModule ? obj : {
|
|
11
8
|
default: obj
|
|
12
9
|
};
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) {
|
|
16
|
-
var keys = Object.keys(object);
|
|
17
|
-
|
|
18
|
-
if (Object.getOwnPropertySymbols) {
|
|
19
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
20
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
21
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
22
|
-
})), keys.push.apply(keys, symbols);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return keys;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _objectSpread(target) {
|
|
29
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
30
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
31
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
32
|
-
_defineProperty(target, key, source[key]);
|
|
33
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
34
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return target;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function _defineProperty(obj, key, value) {
|
|
42
|
-
if (key in obj) {
|
|
43
|
-
Object.defineProperty(obj, key, {
|
|
44
|
-
value: value,
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
obj[key] = value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return obj;
|
|
54
|
-
}
|
|
55
11
|
/**
|
|
56
|
-
* Copyright (c) 2015-present, Parse, LLC.
|
|
57
|
-
* All rights reserved.
|
|
58
|
-
*
|
|
59
|
-
* This source code is licensed under the BSD-style license found in the
|
|
60
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
61
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
62
|
-
*
|
|
63
12
|
* @flow
|
|
64
13
|
*/
|
|
65
|
-
|
|
66
14
|
/* global XMLHttpRequest, XDomainRequest */
|
|
67
|
-
|
|
68
|
-
|
|
69
15
|
const uuidv4 = require('./uuid');
|
|
70
|
-
|
|
71
16
|
let XHR = null;
|
|
72
|
-
|
|
73
17
|
if (typeof XMLHttpRequest !== 'undefined') {
|
|
74
18
|
XHR = XMLHttpRequest;
|
|
75
19
|
}
|
|
76
|
-
|
|
77
20
|
XHR = require('xmlhttprequest').XMLHttpRequest;
|
|
78
21
|
let useXDomainRequest = false;
|
|
79
|
-
|
|
80
22
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
81
23
|
useXDomainRequest = true;
|
|
82
24
|
}
|
|
83
|
-
|
|
84
|
-
function ajaxIE9(method
|
|
85
|
-
/*: string*/
|
|
86
|
-
, url
|
|
87
|
-
/*: string*/
|
|
88
|
-
, data
|
|
89
|
-
/*: any*/
|
|
90
|
-
, headers
|
|
91
|
-
/*:: ?: any*/
|
|
92
|
-
, options
|
|
93
|
-
/*:: ?: FullOptions*/
|
|
94
|
-
) {
|
|
25
|
+
function ajaxIE9(method /*: string*/, url /*: string*/, data /*: any*/, headers /*:: ?: any*/, options /*:: ?: FullOptions*/) {
|
|
95
26
|
return new Promise((resolve, reject) => {
|
|
96
27
|
const xdr = new XDomainRequest();
|
|
97
|
-
|
|
98
28
|
xdr.onload = function () {
|
|
99
29
|
let response;
|
|
100
|
-
|
|
101
30
|
try {
|
|
102
31
|
response = JSON.parse(xdr.responseText);
|
|
103
32
|
} catch (e) {
|
|
104
33
|
reject(e);
|
|
105
34
|
}
|
|
106
|
-
|
|
107
35
|
if (response) {
|
|
108
36
|
resolve({
|
|
109
37
|
response
|
|
110
38
|
});
|
|
111
39
|
}
|
|
112
40
|
};
|
|
113
|
-
|
|
114
41
|
xdr.onerror = xdr.ontimeout = function () {
|
|
115
42
|
// Let's fake a real error message.
|
|
116
43
|
const fakeResponse = {
|
|
@@ -121,69 +48,46 @@ function ajaxIE9(method
|
|
|
121
48
|
};
|
|
122
49
|
reject(fakeResponse);
|
|
123
50
|
};
|
|
124
|
-
|
|
125
51
|
xdr.onprogress = function () {
|
|
126
52
|
if (options && typeof options.progress === 'function') {
|
|
127
53
|
options.progress(xdr.responseText);
|
|
128
54
|
}
|
|
129
55
|
};
|
|
130
|
-
|
|
131
56
|
xdr.open(method, url);
|
|
132
57
|
xdr.send(data);
|
|
133
|
-
|
|
134
58
|
if (options && typeof options.requestTask === 'function') {
|
|
135
59
|
options.requestTask(xdr);
|
|
136
60
|
}
|
|
137
61
|
});
|
|
138
62
|
}
|
|
139
|
-
|
|
140
63
|
const RESTController = {
|
|
141
|
-
ajax(method
|
|
142
|
-
/*: string*/
|
|
143
|
-
, url
|
|
144
|
-
/*: string*/
|
|
145
|
-
, data
|
|
146
|
-
/*: any*/
|
|
147
|
-
, headers
|
|
148
|
-
/*:: ?: any*/
|
|
149
|
-
, options
|
|
150
|
-
/*:: ?: FullOptions*/
|
|
151
|
-
) {
|
|
64
|
+
ajax(method /*: string*/, url /*: string*/, data /*: any*/, headers /*:: ?: any*/, options /*:: ?: FullOptions*/) {
|
|
152
65
|
if (useXDomainRequest) {
|
|
153
66
|
return ajaxIE9(method, url, data, headers, options);
|
|
154
67
|
}
|
|
155
|
-
|
|
156
68
|
const promise = (0, _promiseUtils.resolvingPromise)();
|
|
157
69
|
const isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && ['POST', 'PUT'].includes(method);
|
|
158
70
|
const requestId = isIdempotent ? uuidv4() : '';
|
|
159
71
|
let attempts = 0;
|
|
160
|
-
|
|
161
72
|
const dispatch = function () {
|
|
162
73
|
if (XHR == null) {
|
|
163
74
|
throw new Error('Cannot make a request: No definition of XMLHttpRequest was found.');
|
|
164
75
|
}
|
|
165
|
-
|
|
166
76
|
let handled = false;
|
|
167
77
|
const xhr = new XHR();
|
|
168
|
-
|
|
169
78
|
xhr.onreadystatechange = function () {
|
|
170
79
|
if (xhr.readyState !== 4 || handled || xhr._aborted) {
|
|
171
80
|
return;
|
|
172
81
|
}
|
|
173
|
-
|
|
174
82
|
handled = true;
|
|
175
|
-
|
|
176
83
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
177
84
|
let response;
|
|
178
|
-
|
|
179
85
|
try {
|
|
180
86
|
response = JSON.parse(xhr.responseText);
|
|
181
|
-
|
|
182
87
|
if (typeof xhr.getResponseHeader === 'function') {
|
|
183
88
|
if ((xhr.getAllResponseHeaders() || '').includes('x-parse-job-status-id: ')) {
|
|
184
89
|
response = xhr.getResponseHeader('x-parse-job-status-id');
|
|
185
90
|
}
|
|
186
|
-
|
|
187
91
|
if ((xhr.getAllResponseHeaders() || '').includes('x-parse-push-status-id: ')) {
|
|
188
92
|
response = xhr.getResponseHeader('x-parse-push-status-id');
|
|
189
93
|
}
|
|
@@ -191,7 +95,6 @@ const RESTController = {
|
|
|
191
95
|
} catch (e) {
|
|
192
96
|
promise.reject(e.toString());
|
|
193
97
|
}
|
|
194
|
-
|
|
195
98
|
if (response) {
|
|
196
99
|
promise.resolve({
|
|
197
100
|
response,
|
|
@@ -215,9 +118,7 @@ const RESTController = {
|
|
|
215
118
|
promise.reject(xhr);
|
|
216
119
|
}
|
|
217
120
|
};
|
|
218
|
-
|
|
219
121
|
headers = headers || {};
|
|
220
|
-
|
|
221
122
|
if (typeof headers['Content-Type'] !== 'string') {
|
|
222
123
|
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight
|
|
223
124
|
}
|
|
@@ -225,23 +126,18 @@ const RESTController = {
|
|
|
225
126
|
if (_CoreManager.default.get('IS_NODE')) {
|
|
226
127
|
headers['User-Agent'] = 'Parse/' + _CoreManager.default.get('VERSION') + ' (NodeJS ' + process.versions.node + ')';
|
|
227
128
|
}
|
|
228
|
-
|
|
229
129
|
if (isIdempotent) {
|
|
230
130
|
headers['X-Parse-Request-Id'] = requestId;
|
|
231
131
|
}
|
|
232
|
-
|
|
233
132
|
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
234
133
|
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
235
134
|
}
|
|
236
|
-
|
|
237
135
|
const customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
238
|
-
|
|
239
136
|
for (const key in customHeaders) {
|
|
240
137
|
headers[key] = customHeaders[key];
|
|
241
138
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (options && typeof options.progress === 'function') {
|
|
139
|
+
if (options && typeof options.progress === 'function') {
|
|
140
|
+
const handleProgress = function (type, event) {
|
|
245
141
|
if (event.lengthComputable) {
|
|
246
142
|
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
247
143
|
type
|
|
@@ -251,25 +147,20 @@ const RESTController = {
|
|
|
251
147
|
type
|
|
252
148
|
});
|
|
253
149
|
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
xhr.onprogress = event => {
|
|
258
|
-
handleProgress('download', event);
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
if (xhr.upload) {
|
|
262
|
-
xhr.upload.onprogress = event => {
|
|
263
|
-
handleProgress('upload', event);
|
|
264
150
|
};
|
|
151
|
+
xhr.onprogress = event => {
|
|
152
|
+
handleProgress('download', event);
|
|
153
|
+
};
|
|
154
|
+
if (xhr.upload) {
|
|
155
|
+
xhr.upload.onprogress = event => {
|
|
156
|
+
handleProgress('upload', event);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
265
159
|
}
|
|
266
|
-
|
|
267
160
|
xhr.open(method, url, true);
|
|
268
|
-
|
|
269
161
|
for (const h in headers) {
|
|
270
162
|
xhr.setRequestHeader(h, headers[h]);
|
|
271
163
|
}
|
|
272
|
-
|
|
273
164
|
xhr.onabort = function () {
|
|
274
165
|
promise.resolve({
|
|
275
166
|
response: {
|
|
@@ -279,71 +170,47 @@ const RESTController = {
|
|
|
279
170
|
xhr
|
|
280
171
|
});
|
|
281
172
|
};
|
|
282
|
-
|
|
283
173
|
xhr.send(data);
|
|
284
|
-
|
|
285
174
|
if (options && typeof options.requestTask === 'function') {
|
|
286
175
|
options.requestTask(xhr);
|
|
287
176
|
}
|
|
288
177
|
};
|
|
289
|
-
|
|
290
178
|
dispatch();
|
|
291
179
|
return promise;
|
|
292
180
|
},
|
|
293
|
-
|
|
294
|
-
request(method
|
|
295
|
-
/*: string*/
|
|
296
|
-
, path
|
|
297
|
-
/*: string*/
|
|
298
|
-
, data
|
|
299
|
-
/*: mixed*/
|
|
300
|
-
, options
|
|
301
|
-
/*:: ?: RequestOptions*/
|
|
302
|
-
) {
|
|
181
|
+
request(method /*: string*/, path /*: string*/, data /*: mixed*/, options /*:: ?: RequestOptions*/) {
|
|
303
182
|
options = options || {};
|
|
304
|
-
|
|
305
183
|
let url = _CoreManager.default.get('SERVER_URL');
|
|
306
|
-
|
|
307
184
|
if (url[url.length - 1] !== '/') {
|
|
308
185
|
url += '/';
|
|
309
186
|
}
|
|
310
|
-
|
|
311
187
|
url += path;
|
|
312
188
|
const payload = {};
|
|
313
|
-
|
|
314
189
|
if (data && typeof data === 'object') {
|
|
315
190
|
for (const k in data) {
|
|
316
191
|
payload[k] = data[k];
|
|
317
192
|
}
|
|
318
|
-
}
|
|
319
|
-
|
|
193
|
+
}
|
|
320
194
|
|
|
195
|
+
// Add context
|
|
321
196
|
const context = options.context;
|
|
322
|
-
|
|
323
197
|
if (context !== undefined) {
|
|
324
198
|
payload._context = context;
|
|
325
199
|
}
|
|
326
|
-
|
|
327
200
|
if (method !== 'POST') {
|
|
328
201
|
payload._method = method;
|
|
329
202
|
method = 'POST';
|
|
330
203
|
}
|
|
331
|
-
|
|
332
204
|
payload._ApplicationId = _CoreManager.default.get('APPLICATION_ID');
|
|
333
|
-
|
|
334
205
|
const jsKey = _CoreManager.default.get('JAVASCRIPT_KEY');
|
|
335
|
-
|
|
336
206
|
if (jsKey) {
|
|
337
207
|
payload._JavaScriptKey = jsKey;
|
|
338
208
|
}
|
|
339
|
-
|
|
340
209
|
payload._ClientVersion = _CoreManager.default.get('VERSION');
|
|
341
210
|
let useMasterKey = options.useMasterKey;
|
|
342
|
-
|
|
343
211
|
if (typeof useMasterKey === 'undefined') {
|
|
344
212
|
useMasterKey = _CoreManager.default.get('USE_MASTER_KEY');
|
|
345
213
|
}
|
|
346
|
-
|
|
347
214
|
if (useMasterKey) {
|
|
348
215
|
if (_CoreManager.default.get('MASTER_KEY')) {
|
|
349
216
|
delete payload._JavaScriptKey;
|
|
@@ -352,27 +219,20 @@ const RESTController = {
|
|
|
352
219
|
throw new Error('Cannot use the Master Key, it has not been provided.');
|
|
353
220
|
}
|
|
354
221
|
}
|
|
355
|
-
|
|
356
222
|
if (_CoreManager.default.get('FORCE_REVOCABLE_SESSION')) {
|
|
357
223
|
payload._RevocableSession = '1';
|
|
358
224
|
}
|
|
359
|
-
|
|
360
225
|
const installationId = options.installationId;
|
|
361
226
|
let installationIdPromise;
|
|
362
|
-
|
|
363
227
|
if (installationId && typeof installationId === 'string') {
|
|
364
228
|
installationIdPromise = Promise.resolve(installationId);
|
|
365
229
|
} else {
|
|
366
230
|
const installationController = _CoreManager.default.getInstallationController();
|
|
367
|
-
|
|
368
231
|
installationIdPromise = installationController.currentInstallationId();
|
|
369
232
|
}
|
|
370
|
-
|
|
371
233
|
return installationIdPromise.then(iid => {
|
|
372
234
|
payload._InstallationId = iid;
|
|
373
|
-
|
|
374
235
|
const userController = _CoreManager.default.getUserController();
|
|
375
|
-
|
|
376
236
|
if (options && typeof options.sessionToken === 'string') {
|
|
377
237
|
return Promise.resolve(options.sessionToken);
|
|
378
238
|
} else if (userController) {
|
|
@@ -380,38 +240,34 @@ const RESTController = {
|
|
|
380
240
|
if (user) {
|
|
381
241
|
return Promise.resolve(user.getSessionToken());
|
|
382
242
|
}
|
|
383
|
-
|
|
384
243
|
return Promise.resolve(null);
|
|
385
244
|
});
|
|
386
245
|
}
|
|
387
|
-
|
|
388
246
|
return Promise.resolve(null);
|
|
389
247
|
}).then(token => {
|
|
390
248
|
if (token) {
|
|
391
249
|
payload._SessionToken = token;
|
|
392
250
|
}
|
|
393
|
-
|
|
394
251
|
const payloadString = JSON.stringify(payload);
|
|
395
252
|
return RESTController.ajax(method, url, payloadString, {}, options).then(({
|
|
396
253
|
response,
|
|
397
254
|
status
|
|
398
255
|
}) => {
|
|
399
256
|
if (options.returnStatus) {
|
|
400
|
-
return
|
|
257
|
+
return {
|
|
258
|
+
...response,
|
|
401
259
|
_status: status
|
|
402
|
-
}
|
|
260
|
+
};
|
|
403
261
|
} else {
|
|
404
262
|
return response;
|
|
405
263
|
}
|
|
406
264
|
});
|
|
407
265
|
}).catch(RESTController.handleError);
|
|
408
266
|
},
|
|
409
|
-
|
|
410
267
|
handleError(response) {
|
|
411
268
|
// Transform the error into an instance of ParseError by trying to parse
|
|
412
269
|
// the error string as JSON
|
|
413
270
|
let error;
|
|
414
|
-
|
|
415
271
|
if (response && response.responseText) {
|
|
416
272
|
try {
|
|
417
273
|
const errorJSON = JSON.parse(response.responseText);
|
|
@@ -424,19 +280,13 @@ const RESTController = {
|
|
|
424
280
|
const message = response.message ? response.message : response;
|
|
425
281
|
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + JSON.stringify(message));
|
|
426
282
|
}
|
|
427
|
-
|
|
428
283
|
return Promise.reject(error);
|
|
429
284
|
},
|
|
430
|
-
|
|
431
|
-
_setXHR(xhr
|
|
432
|
-
/*: any*/
|
|
433
|
-
) {
|
|
285
|
+
_setXHR(xhr /*: any*/) {
|
|
434
286
|
XHR = xhr;
|
|
435
287
|
},
|
|
436
|
-
|
|
437
288
|
_getXHR() {
|
|
438
289
|
return XHR;
|
|
439
290
|
}
|
|
440
|
-
|
|
441
291
|
};
|
|
442
292
|
module.exports = RESTController;
|