forked from ionic-team/capacitor-plugins
/
definitions.ts
441 lines (390 loc) · 9.48 KB
/
definitions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/// <reference types="@capacitor/cli" />
import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
export type PresentationOption = 'badge' | 'sound' | 'alert';
declare module '@capacitor/cli' {
export interface PluginsConfig {
/**
* On iOS you can configure the way the push notifications are displayed when the app is in foreground.
*/
PushNotifications?: {
/**
* This is an array of strings you can combine. Possible values in the array are:
* - `badge`: badge count on the app icon is updated (default value)
* - `sound`: the device will ring/vibrate when the push notification is received
* - `alert`: the push notification is displayed in a native dialog
*
* An empty array can be provided if none of the options are desired.
*
* Only available for iOS.
*
* @since 1.0.0
* @example ["badge", "sound", "alert"]
*/
presentationOptions: PresentationOption[];
};
}
}
export interface PushNotificationsPlugin {
/**
* Register the app to receive push notifications.
*
* This method will trigger the `'registration'` event with the push token or
* `'registrationError'` if there was a problem. It does not prompt the user for
* notification permissions, use `requestPermissions()` first.
*
* @since 1.0.0
*/
register(): Promise<void>;
/**
* Get a list of notifications that are visible on the notifications screen.
*
* @since 1.0.0
*/
getDeliveredNotifications(): Promise<DeliveredNotifications>;
/**
* Remove the specified notifications from the notifications screen.
*
* @since 1.0.0
*/
removeDeliveredNotifications(
delivered: DeliveredNotifications,
): Promise<void>;
/**
* Remove all the notifications from the notifications screen.
*
* @since 1.0.0
*/
removeAllDeliveredNotifications(): Promise<void>;
/**
* Create a notification channel.
*
* Only available on Android O or newer (SDK 26+).
*
* @since 1.0.0
*/
createChannel(channel: Channel): Promise<void>;
/**
* Delete a notification channel.
*
* Only available on Android O or newer (SDK 26+).
*
* @since 1.0.0
*/
deleteChannel(channel: Channel): Promise<void>;
/**
* List the available notification channels.
*
* Only available on Android O or newer (SDK 26+).
*
* @since 1.0.0
*/
listChannels(): Promise<ListChannelsResult>;
/**
* Check permission to receive push notifications.
*
* On Android the status is always granted because you can always
* receive push notifications. If you need to check if the user allows
* to display notifications, use local-notifications plugin.
*
* @since 1.0.0
*/
checkPermissions(): Promise<PermissionStatus>;
/**
* Request permission to receive push notifications.
*
* On Android it doesn't prompt for permission because you can always
* receive push notifications.
*
* On iOS, the first time you use the function, it will prompt the user
* for push notification permission and return granted or denied based
* on the user selection. On following calls it will currect status of
* the permission without prompting again.
*
* @since 1.0.0
*/
requestPermissions(): Promise<PermissionStatus>;
/**
* Called when the push notification registration finishes without problems.
*
* Provides the push notification token.
*
* @since 1.0.0
*/
addListener(
eventName: 'registration',
listenerFunc: (token: Token) => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
/**
* Called when the push notification registration finished with problems.
*
* Provides an error with the registration problem.
*
* @since 1.0.0
*/
addListener(
eventName: 'registrationError',
listenerFunc: (error: any) => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
/**
* Called when the device receives a push notification.
*
* @since 1.0.0
*/
addListener(
eventName: 'pushNotificationReceived',
listenerFunc: (notification: PushNotificationSchema) => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
/**
* Called when an action is performed on a push notification.
*
* @since 1.0.0
*/
addListener(
eventName: 'pushNotificationActionPerformed',
listenerFunc: (notification: ActionPerformed) => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
/**
* Remove all native listeners for this plugin.
*
* @since 1.0.0
*/
removeAllListeners(): Promise<void>;
}
export interface PushNotificationSchema {
/**
* The notification title.
*
* @since 1.0.0
*/
title?: string;
/**
* The notification subtitle.
*
* @since 1.0.0
*/
subtitle?: string;
/**
* The main text payload for the notification.
*
* @since 1.0.0
*/
body?: string;
/**
* The notification identifier.
*
* @since 1.0.0
*/
id: string;
/**
* The number to display for the app icon badge.
*
* @since 1.0.0
*/
badge?: number;
/**
* It's not being returned.
*
* @deprecated will be removed in next major version.
* @since 1.0.0
*/
notification?: any;
/**
* Any additional data that was included in the
* push notification payload.
*
* @since 1.0.0
*/
data: any;
/**
* The action to be performed on the user opening the notification.
*
* Only available on Android.
*
* @since 1.0.0
*/
click_action?: string;
/**
* Deep link from the notification.
*
* Only available on Android.
*
* @since 1.0.0
*/
link?: string;
/**
* Set the group identifier for notification grouping.
*
* Only available on Android. Works like `threadIdentifier` on iOS.
*
* @since 1.0.0
*/
group?: string;
/**
* Designate this notification as the summary for an associated `group`.
*
* Only available on Android.
*
* @since 1.0.0
*/
groupSummary?: boolean;
}
export interface ActionPerformed {
/**
* The action performed on the notification.
*
* @since 1.0.0
*/
actionId: string;
/**
* Text entered on the notification action.
*
* Only available on iOS.
*
* @since 1.0.0
*/
inputValue?: string;
/**
* The notification in which the action was performed.
*
* @since 1.0.0
*/
notification: PushNotificationSchema;
}
export interface Token {
/**
* On iOS it contains the APNS token.
* On Android it contains the FCM token.
*
* @since 1.0.0
*/
value: string;
}
export interface DeliveredNotifications {
/**
* List of notifications that are visible on the
* notifications screen.
*
* @since 1.0.0
*/
notifications: PushNotificationSchema[];
}
export interface Channel {
/**
* The channel identifier.
*
* @since 1.0.0
*/
id: string;
/**
* The human-friendly name of this channel (presented to the user).
*
* @since 1.0.0
*/
name: string;
/**
* The description of this channel (presented to the user).
*
* @since 1.0.0
*/
description?: string;
/**
* The sound that should be played for notifications posted to this channel.
*
* Notification channels with an importance of at least `3` should have a
* sound.
*
* The file name of a sound file should be specified relative to the android
* app `res/raw` directory.
*
* @since 1.0.0
* @example "jingle.wav"
*/
sound?: string;
/**
* The level of interruption for notifications posted to this channel.
*
* @since 1.0.0
*/
importance: Importance;
/**
* The visibility of notifications posted to this channel.
*
* This setting is for whether notifications posted to this channel appear on
* the lockscreen or not, and if so, whether they appear in a redacted form.
*
* @since 1.0.0
*/
visibility?: Visibility;
/**
* Whether notifications posted to this channel should display notification
* lights, on devices that support it.
*
* @since 1.0.0
*/
lights?: boolean;
/**
* The light color for notifications posted to this channel.
*
* Only supported if lights are enabled on this channel and the device
* supports it.
*
* Supported color formats are `#RRGGBB` and `#RRGGBBAA`.
*
* @since 1.0.0
*/
lightColor?: string;
/**
* Whether notifications posted to this channel should vibrate.
*
* @since 1.0.0
*/
vibration?: boolean;
}
export type Importance = 1 | 2 | 3 | 4 | 5;
export type Visibility = -1 | 0 | 1;
export interface ListChannelsResult {
/**
* List of all the Channels created by your app.
*
* @since 1.0.0
*/
channels: Channel[];
}
export interface PermissionStatus {
/**
* Permission state of receiving notifications.
*
* @since 1.0.0
*/
receive: PermissionState;
}
/**
* @deprecated Use 'Channel`.
* @since 1.0.0
*/
export type NotificationChannel = Channel;
/**
* @deprecated Use `ListChannelsResult`.
* @since 1.0.0
*/
export type NotificationChannelList = ListChannelsResult;
/**
* @deprecated Use `PushNotificationSchema`.
* @since 1.0.0
*/
export type PushNotification = PushNotificationSchema;
/**
* @deprecated Use `ActionPerformed`.
* @since 1.0.0
*/
export type PushNotificationActionPerformed = ActionPerformed;
/**
* @deprecated Use `DeliveredNotifications`.
* @since 1.0.0
*/
export type PushNotificationDeliveredList = DeliveredNotifications;
/**
* @deprecated Use `Token`.
* @since 1.0.0
*/
export type PushNotificationToken = Token;