@@ -13,6 +13,7 @@ import CoreManager from './CoreManager';
13
13
import ParseQuery from './ParseQuery' ;
14
14
15
15
import type { WhereClause } from './ParseQuery' ;
16
+ import type { FullOptions } from './RESTController' ;
16
17
17
18
export type PushData = {
18
19
where ?: WhereClause | ParseQuery ,
@@ -37,7 +38,7 @@ export type PushData = {
37
38
*
38
39
* @function send
39
40
* @name Parse.Push.send
40
- * @param {object } data - The data of the push notification. Valid fields
41
+ * @param {object } data - The data of the push notification. Valid fields
41
42
* are:
42
43
* <ol>
43
44
* <li>channels - An Array of channels to push to.</li>
@@ -49,10 +50,15 @@ export type PushData = {
49
50
* a set of installations to push to.</li>
50
51
* <li>data - The data to send as part of the push.</li>
51
52
* <ol>
53
+ * @param {object } options Valid options
54
+ * are:<ul>
55
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
56
+ * be used for this request.
57
+ * </ul>
52
58
* @returns {Promise } A promise that is fulfilled when the push request
53
59
* completes.
54
60
*/
55
- export function send ( data : PushData ) : Promise {
61
+ export function send ( data : PushData , options ?: FullOptions = { } ) : Promise {
56
62
if ( data . where && data . where instanceof ParseQuery ) {
57
63
data . where = data . where . toJSON ( ) . where ;
58
64
}
@@ -69,14 +75,39 @@ export function send(data: PushData): Promise {
69
75
throw new Error ( 'expiration_time and expiration_interval cannot both be set.' ) ;
70
76
}
71
77
72
- return CoreManager . getPushController ( ) . send ( data ) ;
78
+ const pushOptions = { useMasterKey : true } ;
79
+ if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
80
+ pushOptions . useMasterKey = options . useMasterKey ;
81
+ }
82
+
83
+ return CoreManager . getPushController ( ) . send ( data , pushOptions ) ;
84
+ }
85
+
86
+ /**
87
+ * Gets push status by Id
88
+ *
89
+ * @function getPushStatus
90
+ * @name Parse.Push.getPushStatus
91
+ * @param {string } pushStatusId The Id of Push Status.
92
+ * @param {object } options Valid options
93
+ * are:<ul>
94
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
95
+ * be used for this request.
96
+ * </ul>
97
+ * @returns {Parse.Object } Status of Push.
98
+ */
99
+ export function getPushStatus ( pushStatusId : string , options ?: FullOptions = { } ) : Promise < string > {
100
+ const pushOptions = { useMasterKey : true } ;
101
+ if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
102
+ pushOptions . useMasterKey = options . useMasterKey ;
103
+ }
104
+ const query = new ParseQuery ( '_PushStatus' ) ;
105
+ return query . get ( pushStatusId , pushOptions ) ;
73
106
}
74
107
75
108
const DefaultController = {
76
- send ( data : PushData ) {
77
- return CoreManager . getRESTController ( ) . request ( 'POST' , 'push' , data , {
78
- useMasterKey : true ,
79
- } ) ;
109
+ send ( data : PushData , options ?: FullOptions ) {
110
+ return CoreManager . getRESTController ( ) . request ( 'POST' , 'push' , data , options ) ;
80
111
} ,
81
112
} ;
82
113
0 commit comments