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