@@ -120,16 +120,16 @@ const isPushSupported = (): boolean => {
120
120
return isPushNotificationsSupported ( ) ;
121
121
}
122
122
123
- interface AutoPromptOptions { force ?: boolean ; forceSlidedownOverNative ?: boolean ; slidedownPromptOptions ?: IOneSignalAutoPromptOptions ; }
124
- interface IOneSignalAutoPromptOptions { force ?: boolean ; forceSlidedownOverNative ?: boolean ; isInUpdateMode ?: boolean ; categoryOptions ?: IOneSignalCategories ; }
125
- interface IOneSignalCategories { positiveUpdateButton : string ; negativeUpdateButton : string ; savingButtonText : string ; errorButtonText : string ; updateMessage : string ; tags : IOneSignalTagCategory [ ] ; }
126
- interface IOneSignalTagCategory { tag : string ; label : string ; checked ?: boolean ; }
127
- type PushSubscriptionNamespaceProperties = { id : string | null | undefined ; token : string | null | undefined ; optedIn : boolean ; } ;
128
- type SubscriptionChangeEvent = { previous : PushSubscriptionNamespaceProperties ; current : PushSubscriptionNamespaceProperties ; } ;
129
- type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay' ;
130
- type SlidedownEventName = 'slidedownShown' ;
131
- type OneSignalDeferredLoadedCallback = ( onesignal : IOneSignalOneSignal ) => void ;
132
- interface IOSNotification {
123
+ export interface AutoPromptOptions { force ?: boolean ; forceSlidedownOverNative ?: boolean ; slidedownPromptOptions ?: IOneSignalAutoPromptOptions ; }
124
+ export interface IOneSignalAutoPromptOptions { force ?: boolean ; forceSlidedownOverNative ?: boolean ; isInUpdateMode ?: boolean ; categoryOptions ?: IOneSignalCategories ; }
125
+ export interface IOneSignalCategories { positiveUpdateButton : string ; negativeUpdateButton : string ; savingButtonText : string ; errorButtonText : string ; updateMessage : string ; tags : IOneSignalTagCategory [ ] ; }
126
+ export interface IOneSignalTagCategory { tag : string ; label : string ; checked ?: boolean ; }
127
+ export type PushSubscriptionNamespaceProperties = { id : string | null | undefined ; token : string | null | undefined ; optedIn : boolean ; } ;
128
+ export type SubscriptionChangeEvent = { previous : PushSubscriptionNamespaceProperties ; current : PushSubscriptionNamespaceProperties ; } ;
129
+ export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay' ;
130
+ export type SlidedownEventName = 'slidedownShown' ;
131
+ export type OneSignalDeferredLoadedCallback = ( onesignal : IOneSignalOneSignal ) => void ;
132
+ export interface IOSNotification {
133
133
/**
134
134
* The OneSignal notification id;
135
135
* - Primary id on OneSignal's REST API and dashboard
@@ -191,7 +191,7 @@ interface IOSNotification {
191
191
readonly confirmDelivery : boolean ;
192
192
}
193
193
194
- interface IOSNotificationActionButton {
194
+ export interface IOSNotificationActionButton {
195
195
/**
196
196
* Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
197
197
* and host page through events to identify which button was clicked.
@@ -212,50 +212,232 @@ interface IOSNotificationActionButton {
212
212
readonly launchURL ?: string ;
213
213
}
214
214
215
- interface NotificationClickResult {
215
+ export interface NotificationClickResult {
216
216
readonly actionId ?: string ;
217
217
readonly url ?: string ;
218
218
}
219
219
220
- type NotificationEventTypeMap = {
220
+ export type NotificationEventTypeMap = {
221
221
'click' : NotificationClickEvent ;
222
222
'foregroundWillDisplay' : NotificationForegroundWillDisplayEvent ;
223
223
'dismiss' : NotificationDismissEvent ;
224
224
'permissionChange' : boolean ;
225
225
'permissionPromptDisplay' : void ;
226
226
} ;
227
227
228
- interface NotificationForegroundWillDisplayEvent {
228
+ export interface NotificationForegroundWillDisplayEvent {
229
229
readonly notification : IOSNotification ;
230
230
preventDefault ( ) : void ;
231
231
}
232
232
233
- interface NotificationDismissEvent {
233
+ export interface NotificationDismissEvent {
234
234
notification : IOSNotification ;
235
235
}
236
236
237
- interface NotificationClickEvent {
237
+ export interface NotificationClickEvent {
238
238
readonly notification : IOSNotification ;
239
239
readonly result : NotificationClickResult ;
240
240
}
241
241
242
- type UserChangeEvent = {
242
+ export type UserChangeEvent = {
243
243
current : UserNamespaceProperties ;
244
244
} ;
245
- type UserNamespaceProperties = {
245
+ export type UserNamespaceProperties = {
246
246
onesignalId : string | undefined ;
247
247
externalId : string | undefined ;
248
248
} ;
249
249
250
- interface IInitObject {
250
+ export interface IInitObject {
251
251
appId : string ;
252
252
subdomainName ?: string ;
253
253
requiresUserPrivacyConsent ?: boolean ;
254
- promptOptions ?: object ;
255
- welcomeNotification ?: object ;
256
- notifyButton ?: object ;
254
+ promptOptions ?: {
255
+ slidedown : {
256
+ prompts : {
257
+ /**
258
+ * Whether to automatically display the prompt.
259
+ * `true` will display the prompt based on the delay options.
260
+ * `false` will prevent the prompt from displaying until the Slidedowns methods are used.
261
+ */
262
+ autoPrompt : boolean ;
263
+
264
+ /**
265
+ * Only available for type: category. Up to 10 categories.
266
+ * @example
267
+ * categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt.
268
+ */
269
+ categories : {
270
+ /** Should identify the action. */
271
+ tag : string ;
272
+
273
+ /** What the user will see. */
274
+ label : string ;
275
+ } [ ] ;
276
+
277
+ /**
278
+ * The delay options for the prompt.
279
+ * @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view.
280
+ */
281
+ delay : {
282
+ /** The number of pages a user needs to visit before the prompt is displayed. */
283
+ pageViews ?: number ;
284
+
285
+ /** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */
286
+ timeDelay ?: number ;
287
+ } ;
288
+
289
+ /**
290
+ * The text to display in the prompt.
291
+ */
292
+ text ?: {
293
+ /** The callout asking the user to opt-in. Up to 90 characters. */
294
+ actionMessage ?: string ;
295
+
296
+ /** Triggers the opt-in. Up to 15 characters. */
297
+ acceptButton ?: string ;
298
+
299
+ /** Cancels opt-in. Up to 15 characters. */
300
+ cancelMessage ?: string ;
301
+
302
+ /** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */
303
+ confirmMessage ?: string ;
304
+
305
+ /** Identifies the email text field. Up to 15 characters. */
306
+ emailLabel ?: string ;
307
+
308
+ /** Cancels the category update. Up to 15 characters. */
309
+ negativeUpdateButton ?: string ;
310
+
311
+ /** Saves the updated category tags. Up to 15 characters. */
312
+ positiveUpdateButton ?: string ;
313
+
314
+ /** Identifies the phone number text field. Up to 15 characters. */
315
+ smsLabel ?: string ;
316
+
317
+ /** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */
318
+ updateMessage ?: string ;
319
+ } ;
320
+
321
+ /**
322
+ * The type of prompt to display.
323
+ * `push` which is the Slide Prompt without categories.
324
+ * `category` which is the Slide Prompt with categories.
325
+ * `sms` only asks for phone number.
326
+ * `email` only asks for email address.
327
+ * `smsAndEmail` asks for both phone number and email address.
328
+ */
329
+ type : 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail' ;
330
+ } [ ] ;
331
+ } ;
332
+ } ;
333
+ welcomeNotification ?: {
334
+ /**
335
+ * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
336
+ */
337
+ disabled ?: boolean ;
338
+
339
+ /**
340
+ * The welcome notification's message. You can localize this to your own language.
341
+ * If left blank or set to blank, the default of 'Thanks for subscribing!' will be used.
342
+ */
343
+ message : string ;
344
+
345
+ /**
346
+ * The welcome notification's title. You can localize this to your own language. If not set, or left blank, the site's title will be used.
347
+ * Set to one space ' ' to clear the title, although this is not recommended.
348
+ */
349
+ title ?: string ;
350
+
351
+ /**
352
+ * By default, clicking the welcome notification does not open any link.
353
+ * This is recommended because the user has just visited your site and subscribed.
354
+ */
355
+ url : string ;
356
+ } ;
357
+
358
+ /**
359
+ * Will enable customization of the notify/subscription bell button.
360
+ */
361
+ notifyButton ?: {
362
+ /**
363
+ * A function you define that returns true to show the Subscription Bell, or false to hide it.
364
+ * Typically used the hide the Subscription Bell after the user is subscribed.
365
+ * This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show.
366
+ */
367
+ displayPredicate ?: ( ) => boolean | Promise < boolean > ;
368
+
369
+ /**
370
+ * Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default.
371
+ */
372
+ enable ?: boolean ;
373
+
374
+ /** Specify CSS-valid pixel offsets using bottom, left, and right. */
375
+ offset ?: { bottom : string ; left : string ; right : string } ;
376
+
377
+ /**
378
+ * If `true`, the Subscription Bell will display an icon that there is 1 unread message.
379
+ * When hovering over the Subscription Bell, the user will see custom text set by message.prenotify.
380
+ */
381
+ prenotify : boolean ;
382
+
383
+ /** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */
384
+ position ?: 'bottom-left' | 'bottom-right' ;
385
+
386
+ /** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */
387
+ showCredit : boolean ;
388
+
389
+ /**
390
+ * The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes.
391
+ */
392
+ size ?: 'small' | 'medium' | 'large' ;
393
+
394
+ /** Customize the Subscription Bell text. */
395
+ text : {
396
+ 'dialog.blocked.message' : string ;
397
+ 'dialog.blocked.title' : string ;
398
+ 'dialog.main.button.subscribe' : string ;
399
+ 'dialog.main.button.unsubscribe' : string ;
400
+ 'dialog.main.title' : string ;
401
+ 'message.action.resubscribed' : string ;
402
+ 'message.action.subscribed' : string ;
403
+ 'message.action.subscribing' : string ;
404
+ 'message.action.unsubscribed' : string ;
405
+ 'message.prenotify' : string ;
406
+ 'tip.state.blocked' : string ;
407
+ 'tip.state.subscribed' : string ;
408
+ 'tip.state.unsubscribed' : string ;
409
+ } ;
410
+ } ;
411
+
257
412
persistNotification ?: boolean ;
258
- webhooks ?: object ;
413
+ webhooks ?: {
414
+ /**
415
+ * Enable this setting only if your server has CORS enabled and supports non-simple CORS requests.
416
+ * If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers.
417
+ * The simplest option is to leave it disabled.
418
+ * @default false
419
+ */
420
+ cors : boolean ;
421
+
422
+ /**
423
+ * This event occurs after a notification is clicked.
424
+ * @example https://site.com/hook
425
+ */
426
+ 'notification.clicked' ?: string ;
427
+
428
+ /**
429
+ * This event occurs after a notification is intentionally dismissed by the user (clicking the notification body or one of the notification action buttons does not trigger the dismissed webhook),
430
+ * after a group of notifications are all dismissed (with this notification as part of that group), or after a notification expires on its own time and disappears. This event is supported on Chrome only.
431
+ * @example https://site.com/hook
432
+ */
433
+ 'notification.dismissed' ?: string ;
434
+
435
+ /**
436
+ * This event occurs after a notification is displayed.
437
+ * @example https://site.com/hook
438
+ */
439
+ 'notification.willDisplay' ?: string ;
440
+ } ;
259
441
autoResubscribe ?: boolean ;
260
442
autoRegister ?: boolean ;
261
443
notificationClickHandlerMatch ?: string ;
@@ -269,7 +451,7 @@ interface IInitObject {
269
451
[ key : string ] : any ;
270
452
}
271
453
272
- interface IOneSignalOneSignal {
454
+ export interface IOneSignalOneSignal {
273
455
Slidedown : IOneSignalSlidedown ;
274
456
Notifications : IOneSignalNotifications ;
275
457
Session : IOneSignalSession ;
@@ -281,7 +463,7 @@ interface IOneSignalOneSignal {
281
463
setConsentGiven ( consent : boolean ) : Promise < void > ;
282
464
setConsentRequired ( requiresConsent : boolean ) : Promise < void > ;
283
465
}
284
- interface IOneSignalNotifications {
466
+ export interface IOneSignalNotifications {
285
467
permissionNative : NotificationPermission ;
286
468
permission : boolean ;
287
469
setDefaultUrl ( url : string ) : Promise < void > ;
@@ -291,7 +473,7 @@ interface IOneSignalNotifications {
291
473
addEventListener < K extends NotificationEventName > ( event : K , listener : ( obj : NotificationEventTypeMap [ K ] ) => void ) : void ;
292
474
removeEventListener < K extends NotificationEventName > ( event : K , listener : ( obj : NotificationEventTypeMap [ K ] ) => void ) : void ;
293
475
}
294
- interface IOneSignalSlidedown {
476
+ export interface IOneSignalSlidedown {
295
477
promptPush ( options ?: AutoPromptOptions ) : Promise < void > ;
296
478
promptPushCategories ( options ?: AutoPromptOptions ) : Promise < void > ;
297
479
promptSms ( options ?: AutoPromptOptions ) : Promise < void > ;
@@ -300,14 +482,14 @@ interface IOneSignalSlidedown {
300
482
addEventListener ( event : SlidedownEventName , listener : ( wasShown : boolean ) => void ) : void ;
301
483
removeEventListener ( event : SlidedownEventName , listener : ( wasShown : boolean ) => void ) : void ;
302
484
}
303
- interface IOneSignalDebug {
485
+ export interface IOneSignalDebug {
304
486
setLogLevel ( logLevel : string ) : void ;
305
487
}
306
- interface IOneSignalSession {
488
+ export interface IOneSignalSession {
307
489
sendOutcome ( outcomeName : string , outcomeWeight ?: number ) : Promise < void > ;
308
490
sendUniqueOutcome ( outcomeName : string ) : Promise < void > ;
309
491
}
310
- interface IOneSignalUser {
492
+ export interface IOneSignalUser {
311
493
onesignalId : string | undefined ;
312
494
externalId : string | undefined ;
313
495
PushSubscription : IOneSignalPushSubscription ;
@@ -329,7 +511,7 @@ interface IOneSignalUser {
329
511
setLanguage ( language : string ) : void ;
330
512
getLanguage ( ) : string ;
331
513
}
332
- interface IOneSignalPushSubscription {
514
+ export interface IOneSignalPushSubscription {
333
515
id : string | null | undefined ;
334
516
token : string | null | undefined ;
335
517
optedIn : boolean | undefined ;
0 commit comments