parse 8.0.1 → 8.0.2-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/README.md +4 -5
- package/dist/parse.js +1 -1
- package/dist/parse.min.js +1 -1
- package/dist/parse.weapp.js +1 -1
- package/dist/parse.weapp.min.js +1 -1
- package/lib/browser/CloudCode.js +222 -195
- package/lib/browser/CoreManager.js +1 -1
- package/lib/node/CloudCode.js +221 -195
- package/lib/node/CoreManager.js +1 -1
- package/lib/react-native/CloudCode.js +12 -0
- package/lib/react-native/CoreManager.js +1 -1
- package/lib/weapp/CloudCode.js +222 -195
- package/lib/weapp/CoreManager.js +1 -1
- package/package.json +15 -12
- package/types/CloudCode.d.ts +391 -175
- package/types/node.d.ts +46 -0
- package/types/tests.ts +238 -151
package/types/CloudCode.d.ts
CHANGED
|
@@ -1,63 +1,296 @@
|
|
|
1
|
+
import type ParseObject from './ParseObject';
|
|
2
|
+
import type ParseUser from './ParseUser';
|
|
3
|
+
import type ParseFile from './ParseFile';
|
|
4
|
+
import type ParseQuery from './ParseQuery';
|
|
5
|
+
/**
|
|
6
|
+
* @typedef Parse.Cloud.FunctionRequest
|
|
7
|
+
* @property {string} installationId If set, the installationId triggering the request.
|
|
8
|
+
* @property {boolean} master If true, means the master key was used.
|
|
9
|
+
* @property {Parse.User} user If set, the user that made the request.
|
|
10
|
+
* @property {object} params The params passed to the cloud function.
|
|
11
|
+
*/
|
|
12
|
+
export interface FunctionRequest<T = Record<string, any>> {
|
|
13
|
+
installationId?: string;
|
|
14
|
+
master: boolean;
|
|
15
|
+
user?: ParseUser;
|
|
16
|
+
params: T;
|
|
17
|
+
ip: string;
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
log: any;
|
|
20
|
+
functionName: string;
|
|
21
|
+
context: Record<string, unknown>;
|
|
22
|
+
config: any;
|
|
23
|
+
}
|
|
24
|
+
export interface FunctionResponse {
|
|
25
|
+
success: (result?: any) => void;
|
|
26
|
+
error: (message?: string) => void;
|
|
27
|
+
status: (code: number) => FunctionResponse;
|
|
28
|
+
header: (name: string, value: string) => FunctionResponse;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @typedef Parse.Cloud.TriggerRequest
|
|
32
|
+
* @property {string} installationId If set, the installationId triggering the request.
|
|
33
|
+
* @property {boolean} master If true, means the master key was used.
|
|
34
|
+
* @property {Parse.User} user If set, the user that made the request.
|
|
35
|
+
* @property {Parse.Object} object The object triggering the hook.
|
|
36
|
+
* @property {string} ip The IP address of the client making the request.
|
|
37
|
+
* @property {object} headers The original HTTP headers for the request.
|
|
38
|
+
* @property {string} triggerName The name of the trigger (`beforeSave`, `afterSave`, ...)
|
|
39
|
+
* @property {object} log The current logger inside Parse Server.
|
|
40
|
+
* @property {Parse.Object} original If set, the object, as currently stored.
|
|
41
|
+
*/
|
|
42
|
+
export interface TriggerRequest<T extends ParseObject = ParseObject> {
|
|
43
|
+
installationId?: string;
|
|
44
|
+
master: boolean;
|
|
45
|
+
isChallenge: boolean;
|
|
46
|
+
user?: ParseUser;
|
|
47
|
+
object: T;
|
|
48
|
+
original?: T;
|
|
49
|
+
ip: string;
|
|
50
|
+
headers: Record<string, string>;
|
|
51
|
+
triggerName: string;
|
|
52
|
+
log: any;
|
|
53
|
+
context: Record<string, unknown>;
|
|
54
|
+
config: any;
|
|
55
|
+
}
|
|
56
|
+
export type BeforeSaveRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>;
|
|
57
|
+
export type AfterSaveRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>;
|
|
58
|
+
export type BeforeDeleteRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>;
|
|
59
|
+
export type AfterDeleteRequest<T extends ParseObject = ParseObject> = TriggerRequest<T>;
|
|
60
|
+
export interface BeforeFindRequest<T extends ParseObject = ParseObject> {
|
|
61
|
+
installationId?: string;
|
|
62
|
+
master: boolean;
|
|
63
|
+
user?: ParseUser;
|
|
64
|
+
query: ParseQuery<T>;
|
|
65
|
+
ip: string;
|
|
66
|
+
headers: Record<string, string>;
|
|
67
|
+
triggerName: string;
|
|
68
|
+
log: any;
|
|
69
|
+
isGet: boolean;
|
|
70
|
+
config: any;
|
|
71
|
+
context: Record<string, unknown>;
|
|
72
|
+
readPreference?: string;
|
|
73
|
+
count?: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface AfterFindRequest<T extends ParseObject = ParseObject> {
|
|
76
|
+
installationId?: string;
|
|
77
|
+
master: boolean;
|
|
78
|
+
user?: ParseUser;
|
|
79
|
+
query: ParseQuery<T>;
|
|
80
|
+
results: T[];
|
|
81
|
+
ip: string;
|
|
82
|
+
headers: Record<string, string>;
|
|
83
|
+
triggerName: string;
|
|
84
|
+
log: any;
|
|
85
|
+
config: any;
|
|
86
|
+
context: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @typedef Parse.Cloud.FileTriggerRequest
|
|
90
|
+
* @property {string} installationId If set, the installationId triggering the request.
|
|
91
|
+
* @property {boolean} master If true, means the master key was used.
|
|
92
|
+
* @property {Parse.User} user If set, the user that made the request.
|
|
93
|
+
* @property {Parse.File} file The file triggering the hook.
|
|
94
|
+
* @property {string} ip The IP address of the client making the request.
|
|
95
|
+
* @property {object} headers The original HTTP headers for the request.
|
|
96
|
+
* @property {string} triggerName The name of the trigger (`beforeSaveFile`, `afterSaveFile`, ...)
|
|
97
|
+
* @property {object} log The current logger inside Parse Server.
|
|
98
|
+
*/
|
|
99
|
+
export interface FileTriggerRequest {
|
|
100
|
+
installationId?: string;
|
|
101
|
+
master: boolean;
|
|
102
|
+
user?: ParseUser;
|
|
103
|
+
file: ParseFile;
|
|
104
|
+
fileSize: number;
|
|
105
|
+
contentLength: number;
|
|
106
|
+
ip: string;
|
|
107
|
+
headers: Record<string, string>;
|
|
108
|
+
triggerName: string;
|
|
109
|
+
log: any;
|
|
110
|
+
config: any;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @typedef Parse.Cloud.ConnectTriggerRequest
|
|
114
|
+
* @property {string} installationId If set, the installationId triggering the request.
|
|
115
|
+
* @property {boolean} useMasterKey If true, means the master key was used.
|
|
116
|
+
* @property {Parse.User} user If set, the user that made the request.
|
|
117
|
+
* @property {number} clients The number of clients connected.
|
|
118
|
+
* @property {number} subscriptions The number of subscriptions connected.
|
|
119
|
+
* @property {string} sessionToken If set, the session of the user that made the request.
|
|
120
|
+
*/
|
|
121
|
+
export interface ConnectTriggerRequest {
|
|
122
|
+
installationId?: string;
|
|
123
|
+
useMasterKey: boolean;
|
|
124
|
+
user?: ParseUser;
|
|
125
|
+
clients: number;
|
|
126
|
+
subscriptions: number;
|
|
127
|
+
sessionToken?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface LiveQueryEventTrigger<T extends ParseObject = ParseObject> {
|
|
130
|
+
installationId?: string;
|
|
131
|
+
useMasterKey: boolean;
|
|
132
|
+
user?: ParseUser;
|
|
133
|
+
sessionToken?: string;
|
|
134
|
+
event: string;
|
|
135
|
+
object: T;
|
|
136
|
+
original?: T;
|
|
137
|
+
clients: number;
|
|
138
|
+
subscriptions: number;
|
|
139
|
+
sendEvent: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @typedef Parse.Cloud.JobRequest
|
|
143
|
+
* @property {object} params The params passed to the background job.
|
|
144
|
+
* @property {Function} message If message is called with a string argument, will update the current message to be stored in the job status.
|
|
145
|
+
*/
|
|
146
|
+
export interface JobRequest {
|
|
147
|
+
params: Record<string, any>;
|
|
148
|
+
message: (message: string) => void;
|
|
149
|
+
config: any;
|
|
150
|
+
}
|
|
151
|
+
export interface ValidatorField {
|
|
152
|
+
type?: any;
|
|
153
|
+
constant?: boolean;
|
|
154
|
+
default?: any;
|
|
155
|
+
options?: any[] | (() => any[]) | any;
|
|
156
|
+
required?: boolean;
|
|
157
|
+
error?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface ValidatorObject {
|
|
160
|
+
requireUser?: boolean;
|
|
161
|
+
requireMaster?: boolean;
|
|
162
|
+
validateMasterKey?: boolean;
|
|
163
|
+
skipWithMasterKey?: boolean;
|
|
164
|
+
requireAnyUserRoles?: string[] | (() => string[]);
|
|
165
|
+
requireAllUserRoles?: string[] | (() => string[]);
|
|
166
|
+
requireUserKeys?: string[] | Record<string, ValidatorField>;
|
|
167
|
+
fields?: string[] | Record<string, ValidatorField>;
|
|
168
|
+
rateLimit?: {
|
|
169
|
+
requestPath?: string;
|
|
170
|
+
requestMethods?: string | string[];
|
|
171
|
+
requestTimeWindow?: number;
|
|
172
|
+
requestCount?: number;
|
|
173
|
+
errorResponseMessage?: string;
|
|
174
|
+
includeInternalRequests?: boolean;
|
|
175
|
+
includeMasterKey?: boolean;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* @typedef Parse.Cloud.HTTPOptions
|
|
180
|
+
* @property {string | object} body The body of the request.
|
|
181
|
+
* @property {boolean} followRedirects Whether to follow redirects caused by HTTP 3xx responses. Defaults to false.
|
|
182
|
+
* @property {object} headers The headers for the request.
|
|
183
|
+
* @property {string} method The method of the request. GET, POST, PUT, DELETE, HEAD, and OPTIONS are supported.
|
|
184
|
+
* @property {string | object} params The query portion of the url.
|
|
185
|
+
* @property {string} url The url to send the request to.
|
|
186
|
+
*/
|
|
187
|
+
export interface HTTPOptions {
|
|
188
|
+
body?: string | object;
|
|
189
|
+
error?: (response: HTTPResponse) => void;
|
|
190
|
+
followRedirects?: boolean;
|
|
191
|
+
headers?: Record<string, string>;
|
|
192
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
193
|
+
params?: string | Record<string, string>;
|
|
194
|
+
success?: (response: HTTPResponse) => void;
|
|
195
|
+
url: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @typedef Parse.Cloud.HTTPResponse
|
|
199
|
+
* @property {Buffer} buffer The raw byte representation of the response body.
|
|
200
|
+
* @property {object} cookies The cookies sent by the server.
|
|
201
|
+
* @property {object} data The parsed response body as a JavaScript object.
|
|
202
|
+
* @property {object} headers The headers sent by the server.
|
|
203
|
+
* @property {number} status The status code.
|
|
204
|
+
* @property {string} text The raw text representation of the response body.
|
|
205
|
+
*/
|
|
206
|
+
export interface HTTPResponse {
|
|
207
|
+
buffer?: Buffer;
|
|
208
|
+
cookies?: Record<string, any>;
|
|
209
|
+
data?: any;
|
|
210
|
+
headers?: Record<string, string>;
|
|
211
|
+
status: number;
|
|
212
|
+
text?: string;
|
|
213
|
+
}
|
|
214
|
+
export declare enum ReadPreferenceOption {
|
|
215
|
+
Primary = "PRIMARY",
|
|
216
|
+
PrimaryPreferred = "PRIMARY_PREFERRED",
|
|
217
|
+
Secondary = "SECONDARY",
|
|
218
|
+
SecondaryPreferred = "SECONDARY_PREFERRED",
|
|
219
|
+
Nearest = "NEAREST"
|
|
220
|
+
}
|
|
1
221
|
/**
|
|
2
222
|
* Defines a Cloud Function.
|
|
3
223
|
*
|
|
4
224
|
* **Available in Cloud Code only.**
|
|
5
225
|
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @param
|
|
9
|
-
* @param {Function} data The Cloud Function to register. This function should take one parameter {@link Parse.Cloud.FunctionRequest}
|
|
226
|
+
* @param name The name of the Cloud Function
|
|
227
|
+
* @param handler The Cloud Function to register. This function should take one parameter {@link FunctionRequest}
|
|
228
|
+
* @param validator An optional function to validate the request
|
|
10
229
|
*/
|
|
230
|
+
export declare function define<T extends Record<string, any> = Record<string, any>>(name: string, handler: (request: FunctionRequest<T>) => any, validator?: ValidatorObject | ((request: FunctionRequest<T>) => any)): void;
|
|
11
231
|
/**
|
|
12
|
-
*
|
|
232
|
+
* Defines a Background Job.
|
|
13
233
|
*
|
|
14
234
|
* **Available in Cloud Code only.**
|
|
15
235
|
*
|
|
16
|
-
*
|
|
236
|
+
* @param name The name of the Background Job
|
|
237
|
+
* @param handler The Background Job to register. This function should take one parameter {@link JobRequest}
|
|
238
|
+
*/
|
|
239
|
+
export declare function job(name: string, handler: (request: JobRequest) => any): void;
|
|
240
|
+
/**
|
|
241
|
+
* Registers a before save function.
|
|
242
|
+
*
|
|
243
|
+
* **Available in Cloud Code only.**
|
|
244
|
+
*
|
|
245
|
+
* If you want to use beforeSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}),
|
|
246
|
+
* you should pass the class itself and not the String for arg1.
|
|
247
|
+
*
|
|
17
248
|
* ```
|
|
18
|
-
* Parse.Cloud.
|
|
249
|
+
* Parse.Cloud.beforeSave('MyCustomClass', (request) => {
|
|
19
250
|
* // code here
|
|
20
251
|
* })
|
|
21
252
|
*
|
|
22
|
-
* Parse.Cloud.
|
|
253
|
+
* Parse.Cloud.beforeSave(Parse.User, (request) => {
|
|
23
254
|
* // code here
|
|
24
255
|
* })
|
|
25
|
-
|
|
256
|
+
* ```
|
|
26
257
|
*
|
|
27
|
-
* @function
|
|
28
|
-
* @
|
|
29
|
-
* @param
|
|
30
|
-
* @param {Function} func The function to run after a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
|
|
258
|
+
* @param className The Parse.Object subclass to register the before save function for.
|
|
259
|
+
* @param handler The function to run before a save.
|
|
260
|
+
* @param validator An optional function to validate the request
|
|
31
261
|
*/
|
|
262
|
+
export declare function beforeSave<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: BeforeSaveRequest<T>) => T | undefined | Promise<T | undefined>, validator?: ValidatorObject | ((request: BeforeSaveRequest<T>) => any)): void;
|
|
32
263
|
/**
|
|
33
|
-
*
|
|
34
264
|
* Registers an after save function.
|
|
35
265
|
*
|
|
36
266
|
* **Available in Cloud Code only.**
|
|
37
267
|
*
|
|
38
|
-
* If you want to use afterSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}),
|
|
268
|
+
* If you want to use afterSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}),
|
|
269
|
+
* you should pass the class itself and not the String for arg1.
|
|
39
270
|
*
|
|
40
271
|
* ```
|
|
41
|
-
* Parse.Cloud.afterSave('MyCustomClass',
|
|
272
|
+
* Parse.Cloud.afterSave('MyCustomClass', (request) => {
|
|
42
273
|
* // code here
|
|
43
274
|
* })
|
|
44
275
|
*
|
|
45
|
-
* Parse.Cloud.afterSave(Parse.User,
|
|
276
|
+
* Parse.Cloud.afterSave(Parse.User, (request) => {
|
|
46
277
|
* // code here
|
|
47
278
|
* })
|
|
48
279
|
* ```
|
|
49
280
|
*
|
|
50
|
-
* @function
|
|
51
|
-
* @
|
|
52
|
-
* @param
|
|
53
|
-
* @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
|
|
281
|
+
* @param className The Parse.Object subclass to register the after save function for.
|
|
282
|
+
* @param handler The function to run after a save.
|
|
283
|
+
* @param validator An optional function to validate the request
|
|
54
284
|
*/
|
|
285
|
+
export declare function afterSave<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: AfterSaveRequest<T>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: AfterSaveRequest<T>) => any)): void;
|
|
55
286
|
/**
|
|
56
|
-
* Registers
|
|
287
|
+
* Registers a before delete function.
|
|
57
288
|
*
|
|
58
289
|
* **Available in Cloud Code only.**
|
|
59
290
|
*
|
|
60
|
-
* If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}),
|
|
291
|
+
* If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}),
|
|
292
|
+
* you should pass the class itself and not the String for arg1.
|
|
293
|
+
*
|
|
61
294
|
* ```
|
|
62
295
|
* Parse.Cloud.beforeDelete('MyCustomClass', (request) => {
|
|
63
296
|
* // code here
|
|
@@ -66,111 +299,145 @@
|
|
|
66
299
|
* Parse.Cloud.beforeDelete(Parse.User, (request) => {
|
|
67
300
|
* // code here
|
|
68
301
|
* })
|
|
69
|
-
|
|
302
|
+
* ```
|
|
70
303
|
*
|
|
71
|
-
* @function
|
|
72
|
-
* @
|
|
73
|
-
* @param
|
|
74
|
-
* @param {Function} func The function to run before a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
|
|
304
|
+
* @param className The Parse.Object subclass to register the before delete function for.
|
|
305
|
+
* @param handler The function to run before a delete.
|
|
306
|
+
* @param validator An optional function to validate the request
|
|
75
307
|
*/
|
|
308
|
+
export declare function beforeDelete<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: BeforeDeleteRequest<T>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: BeforeDeleteRequest<T>) => any)): void;
|
|
76
309
|
/**
|
|
77
|
-
*
|
|
78
|
-
* Registers an before save function.
|
|
310
|
+
* Registers an after delete function.
|
|
79
311
|
*
|
|
80
312
|
* **Available in Cloud Code only.**
|
|
81
313
|
*
|
|
82
|
-
* If you want to use
|
|
314
|
+
* If you want to use afterDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}),
|
|
315
|
+
* you should pass the class itself and not the String for arg1.
|
|
83
316
|
*
|
|
84
317
|
* ```
|
|
85
|
-
* Parse.Cloud.
|
|
318
|
+
* Parse.Cloud.afterDelete('MyCustomClass', (request) => {
|
|
86
319
|
* // code here
|
|
87
320
|
* })
|
|
88
321
|
*
|
|
89
|
-
* Parse.Cloud.
|
|
322
|
+
* Parse.Cloud.afterDelete(Parse.User, (request) => {
|
|
90
323
|
* // code here
|
|
91
324
|
* })
|
|
92
325
|
* ```
|
|
93
326
|
*
|
|
94
|
-
* @function
|
|
95
|
-
* @
|
|
96
|
-
* @param
|
|
97
|
-
* @param {Function} func The function to run before a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
|
|
327
|
+
* @param className The Parse.Object subclass to register the after delete function for.
|
|
328
|
+
* @param handler The function to run after a delete.
|
|
329
|
+
* @param validator An optional function to validate the request
|
|
98
330
|
*/
|
|
331
|
+
export declare function afterDelete<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: AfterDeleteRequest<T>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: AfterDeleteRequest<T>) => any)): void;
|
|
99
332
|
/**
|
|
333
|
+
* Registers a before find function.
|
|
100
334
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
335
|
+
* **Available in Cloud Code only.**
|
|
336
|
+
*
|
|
337
|
+
* @param className The Parse.Object subclass to register the before find function for.
|
|
338
|
+
* @param handler The function to run before a find.
|
|
339
|
+
* @param validator An optional function to validate the request
|
|
340
|
+
*/
|
|
341
|
+
export declare function beforeFind<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: BeforeFindRequest<T>) => ParseQuery<T> | undefined | Promise<ParseQuery<T> | undefined>, validator?: ValidatorObject | ((request: BeforeFindRequest<T>) => any)): void;
|
|
342
|
+
/**
|
|
343
|
+
* Registers an after find function.
|
|
104
344
|
*
|
|
105
345
|
* **Available in Cloud Code only.**
|
|
106
346
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
347
|
+
* @param className The Parse.Object subclass to register the after find function for.
|
|
348
|
+
* @param handler The function to run after a find.
|
|
349
|
+
* @param validator An optional function to validate the request
|
|
350
|
+
*/
|
|
351
|
+
export declare function afterFind<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: AfterFindRequest<T>) => T[] | undefined | Promise<T[] | undefined>, validator?: ValidatorObject | ((request: AfterFindRequest<T>) => any)): void;
|
|
352
|
+
/**
|
|
353
|
+
* Registers a before login function.
|
|
113
354
|
*
|
|
114
|
-
*
|
|
355
|
+
* **Available in Cloud Code only.**
|
|
115
356
|
*
|
|
116
|
-
*
|
|
357
|
+
* @param handler The function to run before a login.
|
|
358
|
+
* @param validator An optional function to validate the request
|
|
359
|
+
*/
|
|
360
|
+
export declare function beforeLogin(handler: (request: TriggerRequest<ParseUser>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: TriggerRequest<ParseUser>) => any)): void;
|
|
361
|
+
/**
|
|
362
|
+
* Registers an after login function.
|
|
117
363
|
*
|
|
118
|
-
*
|
|
119
|
-
* Parse.Cloud.beforeSaveFile(({ file, user }) => {
|
|
120
|
-
* return user.get('avatar');
|
|
121
|
-
* });
|
|
364
|
+
* **Available in Cloud Code only.**
|
|
122
365
|
*
|
|
123
|
-
*
|
|
366
|
+
* @param handler The function to run after a login.
|
|
367
|
+
*/
|
|
368
|
+
export declare function afterLogin(handler: (request: TriggerRequest<ParseUser>) => Promise<void> | undefined): void;
|
|
369
|
+
/**
|
|
370
|
+
* Registers an after logout function.
|
|
371
|
+
*
|
|
372
|
+
* **Available in Cloud Code only.**
|
|
124
373
|
*
|
|
125
|
-
*
|
|
374
|
+
* @param handler The function to run after a logout.
|
|
375
|
+
*/
|
|
376
|
+
export declare function afterLogout(handler: (request: TriggerRequest) => Promise<void> | undefined): void;
|
|
377
|
+
/**
|
|
378
|
+
* Registers a before password reset request function.
|
|
379
|
+
*
|
|
380
|
+
* **Available in Cloud Code only.**
|
|
381
|
+
*
|
|
382
|
+
* @param handler The function to run before a password reset request.
|
|
383
|
+
* @param validator An optional function to validate the request
|
|
384
|
+
*/
|
|
385
|
+
export declare function beforePasswordResetRequest(handler: (request: TriggerRequest<ParseUser>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: TriggerRequest<ParseUser>) => any)): void;
|
|
386
|
+
/**
|
|
387
|
+
* Registers a before save file function.
|
|
388
|
+
*
|
|
389
|
+
* **Available in Cloud Code only.**
|
|
390
|
+
*
|
|
391
|
+
* A new Parse.File can be returned to override the file that gets saved.
|
|
126
392
|
*
|
|
127
393
|
* ```
|
|
128
394
|
* Parse.Cloud.beforeSaveFile(({ file, user }) => {
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* const newFile = new Parse.File(file.name(), <some other file data>, 'text/plain', metadata, tags);
|
|
132
|
-
* return newFile;
|
|
395
|
+
* file.addMetadata('foo', 'bar');
|
|
396
|
+
* file.addTag('createdBy', user.id);
|
|
133
397
|
* });
|
|
134
|
-
*
|
|
135
398
|
* ```
|
|
136
399
|
*
|
|
137
|
-
* @function
|
|
138
|
-
* @name Parse.Cloud.beforeSaveFile
|
|
139
|
-
* @param {Function} func The function to run before a file saves. This function should take one parameter, a {@link Parse.Cloud.FileTriggerRequest}.
|
|
400
|
+
* @param handler The function to run before a file saves.
|
|
140
401
|
*/
|
|
402
|
+
export declare function beforeSaveFile(handler: (request: FileTriggerRequest) => ParseFile | undefined | Promise<ParseFile | undefined>): void;
|
|
141
403
|
/**
|
|
142
|
-
*
|
|
143
404
|
* Registers an after save file function.
|
|
144
405
|
*
|
|
145
406
|
* **Available in Cloud Code only.**
|
|
146
407
|
*
|
|
147
|
-
* Example: creating a new object that references this file in a separate collection
|
|
148
408
|
* ```
|
|
149
409
|
* Parse.Cloud.afterSaveFile(async ({ file, user }) => {
|
|
150
410
|
* const fileObject = new Parse.Object('FileObject');
|
|
151
|
-
* fileObject.set('metadata', file.metadata());
|
|
152
|
-
* fileObject.set('tags', file.tags());
|
|
153
411
|
* fileObject.set('name', file.name());
|
|
154
412
|
* fileObject.set('createdBy', user);
|
|
155
413
|
* await fileObject.save({ sessionToken: user.getSessionToken() });
|
|
156
414
|
* });
|
|
415
|
+
* ```
|
|
157
416
|
*
|
|
158
|
-
* @
|
|
159
|
-
* @name Parse.Cloud.afterSaveFile
|
|
160
|
-
* @param {Function} func The function to run after a file saves. This function should take one parameter, a {@link Parse.Cloud.FileTriggerRequest}.
|
|
417
|
+
* @param handler The function to run after a file saves.
|
|
161
418
|
*/
|
|
419
|
+
export declare function afterSaveFile(handler: (request: FileTriggerRequest) => Promise<void> | undefined): void;
|
|
162
420
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
421
|
+
* Registers a before delete file function.
|
|
422
|
+
*
|
|
423
|
+
* **Available in Cloud Code only.**
|
|
424
|
+
*
|
|
425
|
+
* @param handler The function to run before a file is deleted.
|
|
166
426
|
*/
|
|
427
|
+
export declare function beforeDeleteFile(handler: (request: FileTriggerRequest) => Promise<void> | undefined): void;
|
|
167
428
|
/**
|
|
429
|
+
* Registers an after delete file function.
|
|
168
430
|
*
|
|
169
|
-
*
|
|
431
|
+
* **Available in Cloud Code only.**
|
|
432
|
+
*
|
|
433
|
+
* @param handler The function to run after a file is deleted.
|
|
434
|
+
*/
|
|
435
|
+
export declare function afterDeleteFile(handler: (request: FileTriggerRequest) => Promise<void> | undefined): void;
|
|
436
|
+
/**
|
|
437
|
+
* Registers a before connect function for LiveQuery.
|
|
170
438
|
*
|
|
171
439
|
* **Available in Cloud Code only.**
|
|
172
440
|
*
|
|
173
|
-
* Example: restrict LiveQueries to logged in users.
|
|
174
441
|
* ```
|
|
175
442
|
* Parse.Cloud.beforeConnect((request) => {
|
|
176
443
|
* if (!request.user) {
|
|
@@ -178,130 +445,79 @@
|
|
|
178
445
|
* }
|
|
179
446
|
* });
|
|
180
447
|
* ```
|
|
448
|
+
*
|
|
449
|
+
* @param handler The function to run before a LiveQuery connection is made.
|
|
450
|
+
* @param validator An optional function to validate the request
|
|
181
451
|
*/
|
|
452
|
+
export declare function beforeConnect(handler: (request: ConnectTriggerRequest) => Promise<void> | undefined, validator?: ValidatorObject | ((request: ConnectTriggerRequest) => any)): void;
|
|
182
453
|
/**
|
|
183
|
-
*
|
|
184
|
-
* @name Parse.Cloud.beforeSubscribe
|
|
185
|
-
* @param {(string | Parse.Object)} arg1 The Parse.Object subclass to register the before subscription function for. This can instead be a String that is the className of the subclass.
|
|
186
|
-
* @param {Function} func The function to run before a subscription. This function can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}.
|
|
187
|
-
*/
|
|
188
|
-
/**
|
|
189
|
-
*
|
|
190
|
-
* Registers a before subscribe function.
|
|
454
|
+
* Registers a before subscribe function for LiveQuery.
|
|
191
455
|
*
|
|
192
456
|
* **Available in Cloud Code only.**
|
|
193
|
-
*
|
|
457
|
+
*
|
|
194
458
|
* ```
|
|
195
|
-
*
|
|
459
|
+
* Parse.Cloud.beforeSubscribe('MyObject', (request) => {
|
|
196
460
|
* if (!request.user.get('Admin')) {
|
|
197
|
-
*
|
|
461
|
+
* throw new Parse.Error(101, 'You are not authorized to subscribe to MyObject.');
|
|
198
462
|
* }
|
|
199
|
-
* let query = request.query;
|
|
200
|
-
* query.select("name","year")
|
|
463
|
+
* let query = request.query;
|
|
464
|
+
* query.select("name", "year");
|
|
201
465
|
* });
|
|
202
466
|
* ```
|
|
467
|
+
*
|
|
468
|
+
* @param className The Parse.Object subclass to register the before subscribe function for.
|
|
469
|
+
* @param handler The function to run before a subscription.
|
|
470
|
+
* @param validator An optional function to validate the request
|
|
471
|
+
*/
|
|
472
|
+
export declare function beforeSubscribe<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: TriggerRequest<T>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: TriggerRequest<T>) => any)): void;
|
|
473
|
+
/**
|
|
474
|
+
* Registers an after live query event function.
|
|
475
|
+
*
|
|
476
|
+
* **Available in Cloud Code only.**
|
|
477
|
+
*
|
|
478
|
+
* @param className The Parse.Object subclass to register the after live query event function for.
|
|
479
|
+
* @param handler The function to run after a live query event.
|
|
480
|
+
* @param validator An optional function to validate the request
|
|
203
481
|
*/
|
|
482
|
+
export declare function afterLiveQueryEvent<T extends ParseObject = ParseObject>(className: string | (new () => T), handler: (request: LiveQueryEventTrigger<T>) => Promise<void> | undefined, validator?: ValidatorObject | ((request: LiveQueryEventTrigger<T>) => any)): void;
|
|
483
|
+
/**
|
|
484
|
+
* Sends an email.
|
|
485
|
+
*
|
|
486
|
+
* **Available in Cloud Code only.**
|
|
487
|
+
*
|
|
488
|
+
* @param data The email data.
|
|
489
|
+
* @param data.from The sender email address.
|
|
490
|
+
* @param data.to The recipient email address.
|
|
491
|
+
* @param data.subject The email subject.
|
|
492
|
+
* @param data.text The plain text content.
|
|
493
|
+
* @param data.html The HTML content.
|
|
494
|
+
*/
|
|
495
|
+
export declare function sendEmail(data: {
|
|
496
|
+
from?: string;
|
|
497
|
+
to: string;
|
|
498
|
+
subject?: string;
|
|
499
|
+
text?: string;
|
|
500
|
+
html?: string;
|
|
501
|
+
}): Promise<void>;
|
|
204
502
|
/**
|
|
205
503
|
* Makes an HTTP Request.
|
|
206
504
|
*
|
|
207
505
|
* **Available in Cloud Code only.**
|
|
208
506
|
*
|
|
209
|
-
* By default, Parse.Cloud.httpRequest does not follow redirects caused by HTTP 3xx response codes.
|
|
507
|
+
* By default, Parse.Cloud.httpRequest does not follow redirects caused by HTTP 3xx response codes.
|
|
508
|
+
* You can use the followRedirects option in the {@link HTTPOptions} object to change this behavior.
|
|
210
509
|
*
|
|
211
|
-
* Sample request:
|
|
212
510
|
* ```
|
|
213
511
|
* Parse.Cloud.httpRequest({
|
|
214
512
|
* url: 'http://www.example.com/'
|
|
215
513
|
* }).then(function(httpResponse) {
|
|
216
|
-
* // success
|
|
217
514
|
* console.log(httpResponse.text);
|
|
218
|
-
* },function(httpResponse) {
|
|
219
|
-
* // error
|
|
515
|
+
* }, function(httpResponse) {
|
|
220
516
|
* console.error('Request failed with response code ' + httpResponse.status);
|
|
221
517
|
* });
|
|
222
518
|
* ```
|
|
223
519
|
*
|
|
224
|
-
* @
|
|
225
|
-
* @
|
|
226
|
-
* @param {Parse.Cloud.HTTPOptions} options The Parse.Cloud.HTTPOptions object that makes the request.
|
|
227
|
-
* @returns {Promise<Parse.Cloud.HTTPResponse>} A promise that will be resolved with a {@link Parse.Cloud.HTTPResponse} object when the request completes.
|
|
228
|
-
*/
|
|
229
|
-
/**
|
|
230
|
-
* Defines a Background Job.
|
|
231
|
-
*
|
|
232
|
-
* **Available in Cloud Code only.**
|
|
233
|
-
*
|
|
234
|
-
* @function job
|
|
235
|
-
* @name Parse.Cloud.job
|
|
236
|
-
* @param {string} name The name of the Background Job
|
|
237
|
-
* @param {Function} func The Background Job to register. This function should take two parameters a {@link Parse.Cloud.JobRequest} and a {@link Parse.Cloud.JobStatus}
|
|
238
|
-
*/
|
|
239
|
-
/**
|
|
240
|
-
* @typedef Parse.Cloud.TriggerRequest
|
|
241
|
-
* @property {string} installationId If set, the installationId triggering the request.
|
|
242
|
-
* @property {boolean} master If true, means the master key was used.
|
|
243
|
-
* @property {Parse.User} user If set, the user that made the request.
|
|
244
|
-
* @property {Parse.Object} object The object triggering the hook.
|
|
245
|
-
* @property {string} ip The IP address of the client making the request.
|
|
246
|
-
* @property {object} headers The original HTTP headers for the request.
|
|
247
|
-
* @property {string} triggerName The name of the trigger (`beforeSave`, `afterSave`, ...)
|
|
248
|
-
* @property {object} log The current logger inside Parse Server.
|
|
249
|
-
* @property {Parse.Object} original If set, the object, as currently stored.
|
|
250
|
-
*/
|
|
251
|
-
/**
|
|
252
|
-
* @typedef Parse.Cloud.FileTriggerRequest
|
|
253
|
-
* @property {string} installationId If set, the installationId triggering the request.
|
|
254
|
-
* @property {boolean} master If true, means the master key was used.
|
|
255
|
-
* @property {Parse.User} user If set, the user that made the request.
|
|
256
|
-
* @property {Parse.File} file The file triggering the hook.
|
|
257
|
-
* @property {string} ip The IP address of the client making the request.
|
|
258
|
-
* @property {object} headers The original HTTP headers for the request.
|
|
259
|
-
* @property {string} triggerName The name of the trigger (`beforeSaveFile`, `afterSaveFile`, ...)
|
|
260
|
-
* @property {object} log The current logger inside Parse Server.
|
|
261
|
-
*/
|
|
262
|
-
/**
|
|
263
|
-
* @typedef Parse.Cloud.ConnectTriggerRequest
|
|
264
|
-
* @property {string} installationId If set, the installationId triggering the request.
|
|
265
|
-
* @property {boolean} useMasterKey If true, means the master key was used.
|
|
266
|
-
* @property {Parse.User} user If set, the user that made the request.
|
|
267
|
-
* @property {number} clients The number of clients connected.
|
|
268
|
-
* @property {number} subscriptions The number of subscriptions connected.
|
|
269
|
-
* @property {string} sessionToken If set, the session of the user that made the request.
|
|
270
|
-
*/
|
|
271
|
-
/**
|
|
272
|
-
* @typedef Parse.Cloud.FunctionRequest
|
|
273
|
-
* @property {string} installationId If set, the installationId triggering the request.
|
|
274
|
-
* @property {boolean} master If true, means the master key was used.
|
|
275
|
-
* @property {Parse.User} user If set, the user that made the request.
|
|
276
|
-
* @property {object} params The params passed to the cloud function.
|
|
277
|
-
*/
|
|
278
|
-
/**
|
|
279
|
-
* @typedef Parse.Cloud.JobRequest
|
|
280
|
-
* @property {object} params The params passed to the background job.
|
|
281
|
-
*/
|
|
282
|
-
/**
|
|
283
|
-
* @typedef Parse.Cloud.JobStatus
|
|
284
|
-
* @property {Function} error If error is called, will end the job unsuccessfully with an optional completion message to be stored in the job status.
|
|
285
|
-
* @property {Function} message If message is called with a string argument, will update the current message to be stored in the job status.
|
|
286
|
-
* @property {Function} success If success is called, will end the job successfullly with the optional completion message to be stored in the job status.
|
|
287
|
-
*/
|
|
288
|
-
/**
|
|
289
|
-
* @typedef Parse.Cloud.HTTPOptions
|
|
290
|
-
* @property {string | object} body The body of the request. If it is a JSON object, then the Content-Type set in the headers must be application/x-www-form-urlencoded or application/json. You can also set this to a {@link Buffer} object to send raw bytes. If you use a Buffer, you should also set the Content-Type header explicitly to describe what these bytes represent.
|
|
291
|
-
* @property {Function} error The function that is called when the request fails. It will be passed a Parse.Cloud.HTTPResponse object.
|
|
292
|
-
* @property {boolean} followRedirects Whether to follow redirects caused by HTTP 3xx responses. Defaults to false.
|
|
293
|
-
* @property {object} headers The headers for the request.
|
|
294
|
-
* @property {string} method The method of the request. GET, POST, PUT, DELETE, HEAD, and OPTIONS are supported. Will default to GET if not specified.
|
|
295
|
-
* @property {string | object} params The query portion of the url. You can pass a JSON object of key value pairs like params: {q : 'Sean Plott'} or a raw string like params:q=Sean Plott.
|
|
296
|
-
* @property {Function} success The function that is called when the request successfully completes. It will be passed a Parse.Cloud.HTTPResponse object.
|
|
297
|
-
* @property {string} url The url to send the request to.
|
|
298
|
-
*/
|
|
299
|
-
/**
|
|
300
|
-
* @typedef Parse.Cloud.HTTPResponse
|
|
301
|
-
* @property {Buffer} buffer The raw byte representation of the response body. Use this to receive binary data. See Buffer for more details.
|
|
302
|
-
* @property {object} cookies The cookies sent by the server. The keys in this object are the names of the cookies. The values are Parse.Cloud.Cookie objects.
|
|
303
|
-
* @property {object} data The parsed response body as a JavaScript object. This is only available when the response Content-Type is application/x-www-form-urlencoded or application/json.
|
|
304
|
-
* @property {object} headers The headers sent by the server. The keys in this object are the names of the headers. We do not support multiple response headers with the same name. In the common case of Set-Cookie headers, please use the cookies field instead.
|
|
305
|
-
* @property {number} status The status code.
|
|
306
|
-
* @property {string} text The raw text representation of the response body.
|
|
520
|
+
* @param options The HTTPOptions object that makes the request.
|
|
521
|
+
* @returns A promise that will be resolved with a {@link HTTPResponse} object when the request completes.
|
|
307
522
|
*/
|
|
523
|
+
export declare function httpRequest(options: HTTPOptions): Promise<HTTPResponse>;
|