@onesignal/capacitor-plugin 1.0.0

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.
@@ -0,0 +1,1012 @@
1
+ import { Plugin } from "@capacitor/core";
2
+
3
+ //#region src/OSNotification.d.ts
4
+ type ReceivedEvent = Omit<OSNotification, 'display' | 'rawPayload'> & {
5
+ rawPayload: string | object;
6
+ };
7
+ declare class OSNotification {
8
+ body: string;
9
+ sound?: string;
10
+ title?: string;
11
+ launchURL?: string;
12
+ rawPayload: object;
13
+ actionButtons?: object[];
14
+ additionalData: object;
15
+ notificationId: string;
16
+ groupKey?: string;
17
+ groupMessage?: string;
18
+ groupedNotifications?: object[];
19
+ ledColor?: string;
20
+ priority?: number;
21
+ smallIcon?: string;
22
+ largeIcon?: string;
23
+ bigPicture?: string;
24
+ collapseId?: string;
25
+ fromProjectNumber?: string;
26
+ smallIconAccentColor?: string;
27
+ lockScreenVisibility?: string;
28
+ androidNotificationId?: number;
29
+ badge?: string;
30
+ badgeIncrement?: string;
31
+ category?: string;
32
+ threadId?: string;
33
+ subtitle?: string;
34
+ templateId?: string;
35
+ templateName?: string;
36
+ attachments?: object;
37
+ mutableContent?: boolean;
38
+ contentAvailable?: string;
39
+ relevanceScore?: number;
40
+ interruptionLevel?: string;
41
+ constructor(receivedEvent: ReceivedEvent);
42
+ /**
43
+ * Display the notification.
44
+ * @returns void
45
+ */
46
+ display(): void;
47
+ }
48
+ //#endregion
49
+ //#region src/NotificationReceivedEvent.d.ts
50
+ declare class NotificationWillDisplayEvent {
51
+ private notification;
52
+ constructor(displayEvent: OSNotification);
53
+ /**
54
+ * Call this to prevent OneSignal from displaying the notification automatically.
55
+ * This method can be called up to two times with false and then true, if processing time is needed.
56
+ * Typically this is only possible within a short
57
+ * time-frame (~30 seconds) after the notification is received on the device.
58
+ * @param discard an [preventDefault] set to true to dismiss the notification with no
59
+ * possibility of displaying it in the future.
60
+ */
61
+ preventDefault(discard?: boolean): void;
62
+ getNotification(): OSNotification;
63
+ }
64
+ //#endregion
65
+ //#region src/types/NotificationClicked.d.ts
66
+ type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'permissionChange';
67
+ type NotificationEventTypeMap = {
68
+ click: NotificationClickEvent;
69
+ foregroundWillDisplay: NotificationWillDisplayEvent;
70
+ permissionChange: boolean;
71
+ };
72
+ interface NotificationClickEvent {
73
+ result: NotificationClickResult;
74
+ notification: OSNotification;
75
+ }
76
+ interface NotificationClickResult {
77
+ actionId?: string;
78
+ url?: string;
79
+ }
80
+ //#endregion
81
+ //#region src/NotificationsNamespace.d.ts
82
+ declare const OSNotificationPermission: {
83
+ readonly NotDetermined: 0;
84
+ readonly Denied: 1;
85
+ readonly Authorized: 2;
86
+ readonly Provisional: 3;
87
+ readonly Ephemeral: 4;
88
+ };
89
+ type OSNotificationPermission = (typeof OSNotificationPermission)[keyof typeof OSNotificationPermission];
90
+ declare class Notifications implements OneSignalNotificationsAPI {
91
+ private _plugin;
92
+ private _permissionObserverList;
93
+ private _notificationClickedListeners;
94
+ private _notificationWillDisplayListeners;
95
+ private _hasRegisteredClickListener;
96
+ private _hasRegisteredForegroundWillDisplayListener;
97
+ private _hasRegisteredPermissionListener;
98
+ constructor(plugin: OneSignalCapacitorPlugin);
99
+ private _processFunctionList;
100
+ /**
101
+ * Whether this app has push notification permission. Returns true if the user has accepted permissions,
102
+ * or if the app has ephemeral or provisional permission.
103
+ */
104
+ hasPermission(): Promise<boolean>;
105
+ /**
106
+ * iOS Only.
107
+ * Returns the native permission of the device.
108
+ * @returns {Promise<OSNotificationPermission>}
109
+ */
110
+ permissionNative(): Promise<OSNotificationPermission>;
111
+ /**
112
+ * Prompt the user for permission to receive push notifications.
113
+ * Use the fallbackToSettings parameter to prompt to open the settings app if a user has already declined push permissions.
114
+ * @param {boolean} fallbackToSettings
115
+ * @returns {Promise<boolean>}
116
+ */
117
+ requestPermission(fallbackToSettings?: boolean): Promise<boolean>;
118
+ /**
119
+ * Whether attempting to request notification permission will show a prompt.
120
+ * Returns true if the device has not been prompted for push notification permission already.
121
+ * @returns {Promise<boolean>}
122
+ */
123
+ canRequestPermission(): Promise<boolean>;
124
+ /**
125
+ * iOS Only.
126
+ * Instead of having to prompt the user for permission to send them push notifications,
127
+ * your app can request provisional authorization.
128
+ * @param {(response: boolean)=>void} handler
129
+ * @returns void
130
+ */
131
+ registerForProvisionalAuthorization(handler?: (response: boolean) => void): void;
132
+ /**
133
+ * Add listeners for notification events.
134
+ * @param event
135
+ * @param listener
136
+ * @returns
137
+ */
138
+ addEventListener<K extends NotificationEventName>(event: K, listener: (event: NotificationEventTypeMap[K]) => void): void;
139
+ /**
140
+ * Remove listeners for notification events.
141
+ * @param event
142
+ * @param listener
143
+ * @returns
144
+ */
145
+ removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
146
+ /**
147
+ * Removes all OneSignal notifications.
148
+ * @returns Promise<void>
149
+ */
150
+ clearAll(): Promise<void>;
151
+ /**
152
+ * Android only.
153
+ * Cancels a single OneSignal notification based on its Android notification integer ID.
154
+ * @param {number} id - notification id to cancel
155
+ * @returns Promise<void>
156
+ */
157
+ removeNotification(id: number): Promise<void>;
158
+ /**
159
+ * Android only.
160
+ * Cancels a group of OneSignal notifications with the provided group key.
161
+ * @param {string} id - notification group id to cancel
162
+ * @returns Promise<void>
163
+ */
164
+ removeGroupedNotifications(id: string): Promise<void>;
165
+ }
166
+ //#endregion
167
+ //#region src/definitions.d.ts
168
+ interface OneSignalCapacitorPlugin extends Plugin {
169
+ initialize(options: {
170
+ appId: string;
171
+ }): Promise<void>;
172
+ login(options: {
173
+ externalId: string;
174
+ }): Promise<void>;
175
+ logout(): Promise<void>;
176
+ setConsentRequired(options: {
177
+ required: boolean;
178
+ }): Promise<void>;
179
+ setConsentGiven(options: {
180
+ granted: boolean;
181
+ }): Promise<void>;
182
+ setLogLevel(options: {
183
+ logLevel: LogLevel;
184
+ }): Promise<void>;
185
+ setAlertLevel(options: {
186
+ logLevel: LogLevel;
187
+ }): Promise<void>;
188
+ setLanguage(options: {
189
+ language: string;
190
+ }): Promise<void>;
191
+ addAliases(options: {
192
+ aliases: Record<string, string>;
193
+ }): Promise<void>;
194
+ removeAliases(options: {
195
+ labels: string[];
196
+ }): Promise<void>;
197
+ addEmail(options: {
198
+ email: string;
199
+ }): Promise<void>;
200
+ removeEmail(options: {
201
+ email: string;
202
+ }): Promise<void>;
203
+ addSms(options: {
204
+ smsNumber: string;
205
+ }): Promise<void>;
206
+ removeSms(options: {
207
+ smsNumber: string;
208
+ }): Promise<void>;
209
+ addTags(options: {
210
+ tags: Record<string, string>;
211
+ }): Promise<void>;
212
+ removeTags(options: {
213
+ keys: string[];
214
+ }): Promise<void>;
215
+ getTags(): Promise<{
216
+ tags: Record<string, string>;
217
+ }>;
218
+ getOnesignalId(): Promise<{
219
+ onesignalId: string | null;
220
+ }>;
221
+ getExternalId(): Promise<{
222
+ externalId: string | null;
223
+ }>;
224
+ trackEvent(options: {
225
+ name: string;
226
+ properties?: Record<string, unknown>;
227
+ }): Promise<void>;
228
+ getPushSubscriptionId(): Promise<{
229
+ id: string | null;
230
+ }>;
231
+ getPushSubscriptionToken(): Promise<{
232
+ token: string | null;
233
+ }>;
234
+ getPushSubscriptionOptedIn(): Promise<{
235
+ optedIn: boolean;
236
+ }>;
237
+ optInPushSubscription(): Promise<void>;
238
+ optOutPushSubscription(): Promise<void>;
239
+ getPermission(): Promise<{
240
+ permission: boolean;
241
+ }>;
242
+ permissionNative(): Promise<{
243
+ permission: OSNotificationPermission;
244
+ }>;
245
+ requestPermission(options: {
246
+ fallbackToSettings: boolean;
247
+ }): Promise<{
248
+ permission: boolean;
249
+ }>;
250
+ canRequestPermission(): Promise<{
251
+ canRequest: boolean;
252
+ }>;
253
+ registerForProvisionalAuthorization(): Promise<{
254
+ accepted: boolean;
255
+ }>;
256
+ clearAllNotifications(): Promise<void>;
257
+ removeNotification(options: {
258
+ id: number;
259
+ }): Promise<void>;
260
+ removeGroupedNotifications(options: {
261
+ id: string;
262
+ }): Promise<void>;
263
+ preventDefault(options: {
264
+ notificationId: string;
265
+ discard: boolean;
266
+ }): Promise<void>;
267
+ proceedWithWillDisplay(options: {
268
+ notificationId: string;
269
+ }): Promise<void>;
270
+ displayNotification(options: {
271
+ notificationId: string;
272
+ }): Promise<void>;
273
+ addTriggers(options: {
274
+ triggers: Record<string, string>;
275
+ }): Promise<void>;
276
+ removeTriggers(options: {
277
+ keys: string[];
278
+ }): Promise<void>;
279
+ clearTriggers(): Promise<void>;
280
+ setPaused(options: {
281
+ pause: boolean;
282
+ }): Promise<void>;
283
+ isPaused(): Promise<{
284
+ paused: boolean;
285
+ }>;
286
+ addOutcome(options: {
287
+ name: string;
288
+ }): Promise<void>;
289
+ addUniqueOutcome(options: {
290
+ name: string;
291
+ }): Promise<void>;
292
+ addOutcomeWithValue(options: {
293
+ name: string;
294
+ value: number;
295
+ }): Promise<void>;
296
+ requestLocationPermission(): Promise<void>;
297
+ setLocationShared(options: {
298
+ shared: boolean;
299
+ }): Promise<void>;
300
+ isLocationShared(): Promise<{
301
+ shared: boolean;
302
+ }>;
303
+ enterLiveActivity(options: {
304
+ activityId: string;
305
+ token: string;
306
+ }): Promise<void>;
307
+ exitLiveActivity(options: {
308
+ activityId: string;
309
+ }): Promise<void>;
310
+ setPushToStartToken(options: {
311
+ activityType: string;
312
+ token: string;
313
+ }): Promise<void>;
314
+ removePushToStartToken(options: {
315
+ activityType: string;
316
+ }): Promise<void>;
317
+ setupDefaultLiveActivity(options?: {
318
+ enablePushToStart: boolean;
319
+ enablePushToUpdate: boolean;
320
+ }): Promise<void>;
321
+ startDefaultLiveActivity(options: {
322
+ activityId: string;
323
+ attributes: Record<string, unknown>;
324
+ content: Record<string, unknown>;
325
+ }): Promise<void>;
326
+ }
327
+ //#endregion
328
+ //#region src/DebugNamespace.d.ts
329
+ declare const LogLevel: {
330
+ readonly None: 0;
331
+ readonly Fatal: 1;
332
+ readonly Error: 2;
333
+ readonly Warn: 3;
334
+ readonly Info: 4;
335
+ readonly Debug: 5;
336
+ readonly Verbose: 6;
337
+ };
338
+ type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
339
+ declare class Debug implements OneSignalDebugAPI {
340
+ private _plugin;
341
+ constructor(plugin: OneSignalCapacitorPlugin);
342
+ /**
343
+ * Enable logging to help debug if you run into an issue setting up OneSignal.
344
+ * @param {LogLevel} logLevel - Sets the logging level to print to the Android LogCat log or Xcode log.
345
+ * @returns void
346
+ */
347
+ setLogLevel(logLevel: LogLevel): void;
348
+ /**
349
+ * Enable logging to help debug if you run into an issue setting up OneSignal.
350
+ * @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs.
351
+ * @returns void
352
+ */
353
+ setAlertLevel(visualLogLevel: LogLevel): void;
354
+ }
355
+ //#endregion
356
+ //#region src/PushSubscriptionNamespace.d.ts
357
+ interface PushSubscriptionState {
358
+ id?: string;
359
+ token?: string;
360
+ optedIn: boolean;
361
+ }
362
+ interface PushSubscriptionChangedState {
363
+ previous: PushSubscriptionState;
364
+ current: PushSubscriptionState;
365
+ }
366
+ declare class PushSubscription implements OneSignalPushSubscriptionAPI {
367
+ private _plugin;
368
+ private _subscriptionObserverList;
369
+ constructor(plugin: OneSignalCapacitorPlugin);
370
+ private _processFunctionList;
371
+ /**
372
+ * The readonly push subscription ID.
373
+ * @returns {Promise<string | null>}
374
+ */
375
+ getIdAsync(): Promise<string | null>;
376
+ /**
377
+ * The readonly push token.
378
+ * @returns {Promise<string | null>}
379
+ */
380
+ getTokenAsync(): Promise<string | null>;
381
+ /**
382
+ * Gets a boolean value indicating whether the current user is opted in to push notifications.
383
+ * This returns true when the app has notifications permission and optOut() is NOT called.
384
+ * Note: Does not take into account the existence of the subscription ID and push token.
385
+ * This boolean may return true but push notifications may still not be received by the user.
386
+ * @returns {Promise<boolean>}
387
+ */
388
+ getOptedInAsync(): Promise<boolean>;
389
+ /**
390
+ * Add a callback that fires when the OneSignal push subscription state changes.
391
+ * @param {(event: PushSubscriptionChangedState)=>void} listener
392
+ * @returns void
393
+ */
394
+ addEventListener(_event: 'change', listener: (event: PushSubscriptionChangedState) => void): void;
395
+ /**
396
+ * Remove a push subscription observer that has been previously added.
397
+ * @param {(event: PushSubscriptionChangedState)=>void} listener
398
+ * @returns void
399
+ */
400
+ removeEventListener(_event: 'change', listener: (event: PushSubscriptionChangedState) => void): void;
401
+ /**
402
+ * Call this method to receive push notifications on the device or to resume receiving of push notifications after calling optOut. If needed, this method will prompt the user for push notifications permission.
403
+ * @returns Promise<void>
404
+ */
405
+ optIn(): Promise<void>;
406
+ /**
407
+ * If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can call this method to opt out.
408
+ * @returns Promise<void>
409
+ */
410
+ optOut(): Promise<void>;
411
+ }
412
+ //#endregion
413
+ //#region src/types/InAppMessage.d.ts
414
+ type InAppMessageEventName = 'click' | 'willDisplay' | 'didDisplay' | 'willDismiss' | 'didDismiss';
415
+ type InAppMessageEventTypeMap = {
416
+ click: InAppMessageClickEvent;
417
+ willDisplay: InAppMessageWillDisplayEvent;
418
+ didDisplay: InAppMessageDidDisplayEvent;
419
+ willDismiss: InAppMessageWillDismissEvent;
420
+ didDismiss: InAppMessageDidDismissEvent;
421
+ };
422
+ interface InAppMessageClickEvent {
423
+ message: OSInAppMessage;
424
+ result: InAppMessageClickResult;
425
+ }
426
+ interface InAppMessageClickResult {
427
+ closingMessage: boolean;
428
+ actionId?: string;
429
+ url?: string;
430
+ urlTarget?: InAppMessageActionUrlType;
431
+ }
432
+ type InAppMessageActionUrlType = 'browser' | 'webview' | 'replacement';
433
+ interface InAppMessageWillDisplayEvent {
434
+ message: OSInAppMessage;
435
+ }
436
+ interface InAppMessageDidDisplayEvent {
437
+ message: OSInAppMessage;
438
+ }
439
+ interface InAppMessageWillDismissEvent {
440
+ message: OSInAppMessage;
441
+ }
442
+ interface InAppMessageDidDismissEvent {
443
+ message: OSInAppMessage;
444
+ }
445
+ interface OSInAppMessage {
446
+ messageId: string;
447
+ }
448
+ //#endregion
449
+ //#region src/types/LiveActivities.d.ts
450
+ /**
451
+ * The setup options for `OneSignal.LiveActivities.setupDefault`.
452
+ */
453
+ type LiveActivitySetupOptions = {
454
+ /**
455
+ * When true, OneSignal will listen for pushToStart tokens for the `OneSignalLiveActivityAttributes` structure.
456
+ */
457
+ enablePushToStart: boolean;
458
+ /**
459
+ * When true, OneSignal will listen for pushToUpdate tokens for each start live activity that uses the
460
+ * `OneSignalLiveActivityAttributes` structure.
461
+ */
462
+ enablePushToUpdate: boolean;
463
+ };
464
+ //#endregion
465
+ //#region src/UserNamespace.d.ts
466
+ interface UserState {
467
+ onesignalId?: string;
468
+ externalId?: string;
469
+ }
470
+ interface UserChangedState {
471
+ current: UserState;
472
+ }
473
+ declare class User implements OneSignalUserAPI {
474
+ pushSubscription: PushSubscription;
475
+ private _plugin;
476
+ private _userStateObserverList;
477
+ constructor(plugin: OneSignalCapacitorPlugin);
478
+ private _processFunctionList;
479
+ /**
480
+ * Explicitly set a 2-character language code for the user.
481
+ * @param {string} language
482
+ * @returns Promise<void>
483
+ */
484
+ setLanguage(language: string): Promise<void>;
485
+ /**
486
+ * Set an alias for the current user. If this alias label already exists on this user, it will be overwritten with the new alias id.
487
+ * @param {string} label
488
+ * @param {string} id
489
+ * @returns Promise<void>
490
+ */
491
+ addAlias(label: string, id: string): Promise<void>;
492
+ /**
493
+ * Set aliases for the current user. If any alias already exists, it will be overwritten to the new values.
494
+ * @param {object} aliases
495
+ * @returns Promise<void>
496
+ */
497
+ addAliases(aliases: Record<string, string>): Promise<void>;
498
+ /**
499
+ * Remove an alias from the current user.
500
+ * @param {string} label
501
+ * @returns Promise<void>
502
+ */
503
+ removeAlias(label: string): Promise<void>;
504
+ /**
505
+ * Remove aliases from the current user.
506
+ * @param {string[]} labels
507
+ * @returns Promise<void>
508
+ */
509
+ removeAliases(labels: string[]): Promise<void>;
510
+ /**
511
+ * Add a new email subscription to the current user.
512
+ * @param {string} email
513
+ * @returns Promise<void>
514
+ */
515
+ addEmail(email: string): Promise<void>;
516
+ /**
517
+ * Remove an email subscription from the current user.
518
+ * @param {string} email
519
+ * @returns Promise<void>
520
+ */
521
+ removeEmail(email: string): Promise<void>;
522
+ /**
523
+ * Add a new SMS subscription to the current user.
524
+ * @param {string} smsNumber
525
+ * @returns Promise<void>
526
+ */
527
+ addSms(smsNumber: string): Promise<void>;
528
+ /**
529
+ * Remove an SMS subscription from the current user.
530
+ * @param {string} smsNumber
531
+ * @returns Promise<void>
532
+ */
533
+ removeSms(smsNumber: string): Promise<void>;
534
+ /**
535
+ * Add a tag for the current user. Tags are key:value string pairs used as building blocks for targeting specific users and/or personalizing messages.
536
+ * @param {string} key
537
+ * @param {string} value
538
+ * @returns Promise<void>
539
+ */
540
+ addTag(key: string, value: string): Promise<void>;
541
+ /**
542
+ * Add multiple tags for the current user. Tags are key:value string pairs used as building blocks for targeting specific users and/or personalizing messages.
543
+ * @param {object} tags
544
+ * @returns Promise<void>
545
+ */
546
+ addTags(tags: object): Promise<void>;
547
+ /**
548
+ * Remove the data tag with the provided key from the current user.
549
+ * @param {string} key
550
+ * @returns Promise<void>
551
+ */
552
+ removeTag(key: string): Promise<void>;
553
+ /**
554
+ * Remove multiple tags with the provided keys from the current user.
555
+ * @param {string[]} keys
556
+ * @returns Promise<void>
557
+ */
558
+ removeTags(keys: string[]): Promise<void>;
559
+ /**
560
+ * Returns the local tags for the current user.
561
+ * @returns Promise<{ [key: string]: string }>
562
+ */
563
+ getTags(): Promise<{
564
+ [key: string]: string;
565
+ }>;
566
+ /**
567
+ * Add a callback that fires when the OneSignal User state changes.
568
+ * @param {(event: UserChangedState)=>void} listener
569
+ * @returns void
570
+ */
571
+ addEventListener(_event: 'change', listener: (event: UserChangedState) => void): void;
572
+ /**
573
+ * Remove a User State observer that has been previously added.
574
+ * @param {(event: UserChangedState)=>void} listener
575
+ * @returns void
576
+ */
577
+ removeEventListener(_event: 'change', listener: (event: UserChangedState) => void): void;
578
+ /**
579
+ * Get the nullable OneSignal Id associated with the current user.
580
+ * @returns {Promise<string | null>}
581
+ */
582
+ getOnesignalId(): Promise<string | null>;
583
+ /**
584
+ * Get the nullable External Id associated with the current user.
585
+ * @returns {Promise<string | null>}
586
+ */
587
+ getExternalId(): Promise<string | null>;
588
+ /**
589
+ * Track a custom event with the provided name and optional properties.
590
+ * @param {string} name - The name of the custom event
591
+ * @param {object} [properties] - Optional properties to associate with the event
592
+ * @returns Promise<void>
593
+ */
594
+ trackEvent(name: string, properties?: object): Promise<void>;
595
+ }
596
+ //#endregion
597
+ //#region src/api.d.ts
598
+ /**
599
+ * Debug helpers exposed via `OneSignal.Debug`.
600
+ */
601
+ interface OneSignalDebugAPI {
602
+ /** Set the log level printed to LogCat (Android) or the Xcode console (iOS). */
603
+ setLogLevel(logLevel: LogLevel): void;
604
+ /** Set the log level shown to the user as alert dialogs. */
605
+ setAlertLevel(visualLogLevel: LogLevel): void;
606
+ }
607
+ /**
608
+ * Push subscription state and controls exposed via `OneSignal.User.pushSubscription`.
609
+ */
610
+ interface OneSignalPushSubscriptionAPI {
611
+ /** Get the current device's push subscription ID, or null if not yet assigned. */
612
+ getIdAsync(): Promise<string | null>;
613
+ /** Get the current device's push token, or null if not yet available. */
614
+ getTokenAsync(): Promise<string | null>;
615
+ /**
616
+ * Whether the current user is opted in to push notifications. Returns true when the app has
617
+ * notification permission and `optOut()` has not been called. Does not guarantee a token has
618
+ * been received.
619
+ */
620
+ getOptedInAsync(): Promise<boolean>;
621
+ /** Add a listener for push subscription state changes. */
622
+ addEventListener(event: 'change', listener: (event: PushSubscriptionChangedState) => void): void;
623
+ /** Remove a previously added push subscription state listener. */
624
+ removeEventListener(event: 'change', listener: (event: PushSubscriptionChangedState) => void): void;
625
+ /** Opt the user in to push notifications. Prompts for permission if needed. */
626
+ optIn(): Promise<void>;
627
+ /** Opt the user out of push notifications on this device. */
628
+ optOut(): Promise<void>;
629
+ }
630
+ /**
631
+ * Current-user operations exposed via `OneSignal.User`.
632
+ */
633
+ interface OneSignalUserAPI {
634
+ /** Push subscription controls for the current user. */
635
+ pushSubscription: OneSignalPushSubscriptionAPI;
636
+ /** Explicitly set a 2-character language code for the current user. */
637
+ setLanguage(language: string): Promise<void>;
638
+ /** Add or overwrite a single alias on the current user. */
639
+ addAlias(label: string, id: string): Promise<void>;
640
+ /** Add or overwrite multiple aliases on the current user. */
641
+ addAliases(aliases: Record<string, string>): Promise<void>;
642
+ /** Remove a single alias by label from the current user. */
643
+ removeAlias(label: string): Promise<void>;
644
+ /** Remove multiple aliases by label from the current user. */
645
+ removeAliases(labels: string[]): Promise<void>;
646
+ /** Add a new email subscription to the current user. */
647
+ addEmail(email: string): Promise<void>;
648
+ /** Remove an email subscription from the current user. */
649
+ removeEmail(email: string): Promise<void>;
650
+ /** Add a new SMS subscription to the current user. */
651
+ addSms(smsNumber: string): Promise<void>;
652
+ /** Remove an SMS subscription from the current user. */
653
+ removeSms(smsNumber: string): Promise<void>;
654
+ /** Add a single tag (key/value) on the current user, used for targeting and personalization. */
655
+ addTag(key: string, value: string): Promise<void>;
656
+ /** Add or overwrite multiple tags on the current user. */
657
+ addTags(tags: object): Promise<void>;
658
+ /** Remove a single tag by key from the current user. */
659
+ removeTag(key: string): Promise<void>;
660
+ /** Remove multiple tags by key from the current user. */
661
+ removeTags(keys: string[]): Promise<void>;
662
+ /** Get the local tags for the current user. */
663
+ getTags(): Promise<{
664
+ [key: string]: string;
665
+ }>;
666
+ /** Add a listener for OneSignal user state changes. */
667
+ addEventListener(event: 'change', listener: (event: UserChangedState) => void): void;
668
+ /** Remove a previously added user state listener. */
669
+ removeEventListener(event: 'change', listener: (event: UserChangedState) => void): void;
670
+ /** Get the OneSignal-assigned ID for the current user, or null if not yet available. */
671
+ getOnesignalId(): Promise<string | null>;
672
+ /** Get the external ID set via `login`, or null if the user is anonymous. */
673
+ getExternalId(): Promise<string | null>;
674
+ /** Track a custom event with an optional set of JSON-serializable properties. */
675
+ trackEvent(name: string, properties?: object): Promise<void>;
676
+ }
677
+ /**
678
+ * Notification permission and event handling exposed via `OneSignal.Notifications`.
679
+ */
680
+ interface OneSignalNotificationsAPI {
681
+ /** Whether the app currently has notification permission (including provisional/ephemeral). */
682
+ hasPermission(): Promise<boolean>;
683
+ /** iOS only. The native notification permission status. */
684
+ permissionNative(): Promise<OSNotificationPermission>;
685
+ /** Prompt the user for notification permission. Optionally fall back to system settings. */
686
+ requestPermission(fallbackToSettings?: boolean): Promise<boolean>;
687
+ /** Whether requesting notification permission would still show a prompt. */
688
+ canRequestPermission(): Promise<boolean>;
689
+ /** iOS only. Request provisional authorization for quiet notifications without prompting. */
690
+ registerForProvisionalAuthorization(handler?: (response: boolean) => void): void;
691
+ /** Add a listener for `click`, `foregroundWillDisplay`, or `permissionChange` events. */
692
+ addEventListener<K extends NotificationEventName>(event: K, listener: (event: NotificationEventTypeMap[K]) => void): void;
693
+ /** Remove a previously added notification event listener. */
694
+ removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
695
+ /** Remove all OneSignal notifications from the notification center. */
696
+ clearAll(): Promise<void>;
697
+ /** Android only. Cancel a single notification by its Android notification ID. */
698
+ removeNotification(id: number): Promise<void>;
699
+ /** Android only. Cancel a group of notifications by group key. */
700
+ removeGroupedNotifications(id: string): Promise<void>;
701
+ }
702
+ /**
703
+ * In-app message triggers and event handling exposed via `OneSignal.InAppMessages`.
704
+ */
705
+ interface OneSignalInAppMessagesAPI {
706
+ /** Add a listener for IAM `click`, `willDisplay`, `didDisplay`, `willDismiss`, or `didDismiss` events. */
707
+ addEventListener<K extends InAppMessageEventName>(event: K, listener: (event: InAppMessageEventTypeMap[K]) => void): void;
708
+ /** Remove a previously added IAM event listener. */
709
+ removeEventListener<K extends InAppMessageEventName>(event: K, listener: (obj: InAppMessageEventTypeMap[K]) => void): void;
710
+ /** Add a single trigger (key/value) used to determine which IAMs are displayed to the user. */
711
+ addTrigger(key: string, value: string): Promise<void>;
712
+ /** Add or overwrite multiple triggers for the current user. */
713
+ addTriggers(triggers: {
714
+ [key: string]: string;
715
+ }): Promise<void>;
716
+ /** Remove a single trigger by key. */
717
+ removeTrigger(key: string): Promise<void>;
718
+ /** Remove multiple triggers by key. */
719
+ removeTriggers(keys: string[]): Promise<void>;
720
+ /** Clear all triggers from the current user. */
721
+ clearTriggers(): Promise<void>;
722
+ /** Pause or resume the display of in-app messages. */
723
+ setPaused(pause: boolean): void;
724
+ /** Whether in-app messaging is currently paused. */
725
+ getPaused(): Promise<boolean>;
726
+ }
727
+ /**
728
+ * Outcome reporting exposed via `OneSignal.Session`.
729
+ */
730
+ interface OneSignalSessionAPI {
731
+ /** Record an outcome with the given name against the current session. */
732
+ addOutcome(name: string): Promise<void>;
733
+ /** Record a unique outcome with the given name against the current session. */
734
+ addUniqueOutcome(name: string): Promise<void>;
735
+ /** Record an outcome with the given name and value against the current session. */
736
+ addOutcomeWithValue(name: string, value: number): Promise<void>;
737
+ }
738
+ /**
739
+ * Location permission and sharing exposed via `OneSignal.Location`.
740
+ */
741
+ interface OneSignalLocationAPI {
742
+ /** Prompt the user for location permission to enable geotagging. */
743
+ requestPermission(): Promise<void>;
744
+ /** Enable or disable sharing the device location with OneSignal. */
745
+ setShared(shared: boolean): void;
746
+ /** Whether the device location is currently shared with OneSignal. */
747
+ isShared(): Promise<boolean>;
748
+ }
749
+ /**
750
+ * Live activity controls exposed via `OneSignal.LiveActivities`. iOS only unless noted.
751
+ */
752
+ interface OneSignalLiveActivitiesAPI {
753
+ /** Associate a live activity ID with a push token so OneSignal can target it. */
754
+ enter(activityId: string, token: string, onSuccess?: (data: unknown) => void, onFailure?: (data: unknown) => void): void;
755
+ /**
756
+ * Disassociate a live activity ID.
757
+ * @deprecated Currently unsupported on the native side.
758
+ */
759
+ exit(activityId: string, onSuccess?: (data: unknown) => void, onFailure?: (data: unknown) => void): void;
760
+ /** Register a `pushToStart` token for the given live activity attributes type. */
761
+ setPushToStartToken(activityType: string, token: string): Promise<void>;
762
+ /** Remove a previously registered `pushToStart` token for the given attributes type. */
763
+ removePushToStartToken(activityType: string): Promise<void>;
764
+ /** Set up the OneSignal default live activity, optionally enabling pushToStart/pushToUpdate. */
765
+ setupDefault(options?: LiveActivitySetupOptions): Promise<void>;
766
+ /** Start a live activity backed by the OneSignal default attributes type. */
767
+ startDefault(activityId: string, attributes: Record<string, unknown>, content: Record<string, unknown>): Promise<void>;
768
+ }
769
+ /**
770
+ * The public OneSignal Capacitor plugin API. This is the shape of the default `OneSignal` export.
771
+ */
772
+ interface OneSignalAPI {
773
+ /** Debug helpers. */
774
+ Debug: OneSignalDebugAPI;
775
+ /** Current-user operations (aliases, tags, email/SMS, push subscription). */
776
+ User: OneSignalUserAPI;
777
+ /** Notification permission and click/foreground event handling. */
778
+ Notifications: OneSignalNotificationsAPI;
779
+ /** In-app message triggers and lifecycle events. */
780
+ InAppMessages: OneSignalInAppMessagesAPI;
781
+ /** Outcome reporting against the current session. */
782
+ Session: OneSignalSessionAPI;
783
+ /** Location permission and sharing. */
784
+ Location: OneSignalLocationAPI;
785
+ /** iOS live activity controls. */
786
+ LiveActivities: OneSignalLiveActivitiesAPI;
787
+ /** Initialize the SDK with your OneSignal app ID. Call during app startup. */
788
+ initialize(appId: string): Promise<void>;
789
+ /** Log in to OneSignal as the user identified by `externalId`, switching the user context. */
790
+ login(externalId: string): Promise<void>;
791
+ /** Log out the current user. The SDK will reference a new device-scoped user. */
792
+ logout(): Promise<void>;
793
+ /** Set whether user privacy consent is required before sending data to OneSignal. Call before `initialize`. */
794
+ setConsentRequired(required: boolean): void;
795
+ /** Indicate whether the user has granted privacy consent. */
796
+ setConsentGiven(granted: boolean): void;
797
+ }
798
+ //#endregion
799
+ //#region src/InAppMessagesNamespace.d.ts
800
+ declare class InAppMessages implements OneSignalInAppMessagesAPI {
801
+ private _plugin;
802
+ private _inAppMessageClickListeners;
803
+ private _willDisplayInAppMessageListeners;
804
+ private _didDisplayInAppMessageListeners;
805
+ private _willDismissInAppMessageListeners;
806
+ private _didDismissInAppMessageListeners;
807
+ constructor(plugin: OneSignalCapacitorPlugin);
808
+ private _processFunctionList;
809
+ /**
810
+ * Add event listeners for In-App Message click and/or lifecycle events.
811
+ * @param event
812
+ * @param listener
813
+ * @returns
814
+ */
815
+ addEventListener<K extends InAppMessageEventName>(event: K, listener: (event: InAppMessageEventTypeMap[K]) => void): void;
816
+ /**
817
+ * Remove event listeners for In-App Message click and/or lifecycle events.
818
+ * @param event
819
+ * @param listener
820
+ * @returns
821
+ */
822
+ removeEventListener<K extends InAppMessageEventName>(event: K, listener: (obj: InAppMessageEventTypeMap[K]) => void): void;
823
+ /**
824
+ * Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
825
+ * @param {string} key
826
+ * @param {string} value
827
+ * @returns Promise<void>
828
+ */
829
+ addTrigger(key: string, value: string): Promise<void>;
830
+ /**
831
+ * Add multiple triggers for the current user.
832
+ * @param {[key: string]: string} triggers
833
+ * @returns Promise<void>
834
+ */
835
+ addTriggers(triggers: {
836
+ [key: string]: string;
837
+ }): Promise<void>;
838
+ /**
839
+ * Remove the trigger with the provided key from the current user.
840
+ * @param {string} key
841
+ * @returns Promise<void>
842
+ */
843
+ removeTrigger(key: string): Promise<void>;
844
+ /**
845
+ * Remove multiple triggers from the current user.
846
+ * @param {string[]} keys
847
+ * @returns Promise<void>
848
+ */
849
+ removeTriggers(keys: string[]): Promise<void>;
850
+ /**
851
+ * Clear all triggers from the current user.
852
+ * @returns Promise<void>
853
+ */
854
+ clearTriggers(): Promise<void>;
855
+ /**
856
+ * Set whether in-app messaging is currently paused.
857
+ * @param {boolean} pause
858
+ * @returns void
859
+ */
860
+ setPaused(pause: boolean): void;
861
+ /**
862
+ * Whether in-app messaging is currently paused.
863
+ * @returns {Promise<boolean>}
864
+ */
865
+ getPaused(): Promise<boolean>;
866
+ }
867
+ //#endregion
868
+ //#region src/LiveActivitiesNamespace.d.ts
869
+ declare class LiveActivities implements OneSignalLiveActivitiesAPI {
870
+ private _plugin;
871
+ constructor(plugin: OneSignalCapacitorPlugin);
872
+ /**
873
+ * Enter a live activity
874
+ * @param {string} activityId
875
+ * @param {string} token
876
+ * @param {Function} onSuccess
877
+ * @param {Function} onFailure
878
+ * @returns void
879
+ */
880
+ enter(activityId: string, token: string, onSuccess?: (data: unknown) => void, onFailure?: (data: unknown) => void): void;
881
+ /**
882
+ * Exit a live activity
883
+ * @param {string} activityId
884
+ * @param {Function} onSuccess
885
+ * @param {Function} onFailure
886
+ * @returns void
887
+ * @deprecated Currently unsupported, avoid using this method.
888
+ */
889
+ exit(activityId: string, onSuccess?: (data: unknown) => void, onFailure?: (data: unknown) => void): void;
890
+ /**
891
+ * Indicate this device is capable of receiving pushToStart live activities for the
892
+ * `activityType`. Only applies to iOS.
893
+ * @param {string} activityType
894
+ * @param {string} token
895
+ */
896
+ setPushToStartToken(activityType: string, token: string): Promise<void>;
897
+ /**
898
+ * Indicate this device is no longer capable of receiving pushToStart live activities
899
+ * for the `activityType`. Only applies to iOS.
900
+ * @param {string} activityType
901
+ */
902
+ removePushToStartToken(activityType: string): Promise<void>;
903
+ /**
904
+ * Enable the OneSignalSDK to setup the default `DefaultLiveActivityAttributes` structure.
905
+ * Only applies to iOS.
906
+ * @param {LiveActivitySetupOptions} options
907
+ */
908
+ setupDefault(options?: LiveActivitySetupOptions): Promise<void>;
909
+ /**
910
+ * Start a new LiveActivity that is modelled by the default `DefaultLiveActivityAttributes`
911
+ * structure. Only applies to iOS.
912
+ * @param {string} activityId
913
+ * @param {object} attributes
914
+ * @param {object} content
915
+ */
916
+ startDefault(activityId: string, attributes: Record<string, unknown>, content: Record<string, unknown>): Promise<void>;
917
+ }
918
+ //#endregion
919
+ //#region src/LocationNamespace.d.ts
920
+ declare class Location implements OneSignalLocationAPI {
921
+ private _plugin;
922
+ constructor(plugin: OneSignalCapacitorPlugin);
923
+ /**
924
+ * Prompts the user for location permissions to allow geotagging from the OneSignal dashboard.
925
+ * @returns Promise<void>
926
+ */
927
+ requestPermission(): Promise<void>;
928
+ /**
929
+ * Disable or enable location collection (defaults to enabled if your app has location permission).
930
+ * @param {boolean} shared
931
+ * @returns void
932
+ */
933
+ setShared(shared: boolean): void;
934
+ /**
935
+ * Whether location is currently shared with OneSignal.
936
+ * @returns {Promise<boolean>}
937
+ */
938
+ isShared(): Promise<boolean>;
939
+ }
940
+ //#endregion
941
+ //#region src/SessionNamespace.d.ts
942
+ declare class Session implements OneSignalSessionAPI {
943
+ private _plugin;
944
+ constructor(plugin: OneSignalCapacitorPlugin);
945
+ /**
946
+ * Add an outcome with the provided name, captured against the current session.
947
+ * @param {string} name
948
+ * @returns Promise<void>
949
+ */
950
+ addOutcome(name: string): Promise<void>;
951
+ /**
952
+ * Add a unique outcome with the provided name, captured against the current session.
953
+ * @param {string} name
954
+ * @returns Promise<void>
955
+ */
956
+ addUniqueOutcome(name: string): Promise<void>;
957
+ /**
958
+ * Add an outcome with the provided name and value, captured against the current session.
959
+ * @param {string} name
960
+ * @param {number} value
961
+ * @returns Promise<void>
962
+ */
963
+ addOutcomeWithValue(name: string, value: number): Promise<void>;
964
+ }
965
+ //#endregion
966
+ //#region src/OneSignalPlugin.d.ts
967
+ declare class OneSignalPlugin implements OneSignalAPI {
968
+ User: User;
969
+ Debug: Debug;
970
+ Session: Session;
971
+ Location: Location;
972
+ InAppMessages: InAppMessages;
973
+ Notifications: Notifications;
974
+ LiveActivities: LiveActivities;
975
+ private _plugin;
976
+ private _appID;
977
+ constructor(plugin: OneSignalCapacitorPlugin);
978
+ /**
979
+ * Initializes the OneSignal SDK. This should be called during startup of the application.
980
+ * @param {string} appId
981
+ * @returns Promise<void>
982
+ */
983
+ initialize(appId: string): Promise<void>;
984
+ /**
985
+ * Login to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user.
986
+ * @param {string} externalId
987
+ * @returns Promise<void>
988
+ */
989
+ login(externalId: string): Promise<void>;
990
+ /**
991
+ * Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user.
992
+ * @returns Promise<void>
993
+ */
994
+ logout(): Promise<void>;
995
+ /**
996
+ * Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to true prior to the invocation of initialization to ensure compliance.
997
+ * @param {boolean} required
998
+ * @returns void
999
+ */
1000
+ setConsentRequired(required: boolean): void;
1001
+ /**
1002
+ * Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.
1003
+ * @param {boolean} granted
1004
+ * @returns void
1005
+ */
1006
+ setConsentGiven(granted: boolean): void;
1007
+ }
1008
+ //#endregion
1009
+ //#region src/index.d.ts
1010
+ declare const OneSignal: OneSignalPlugin;
1011
+ //#endregion
1012
+ export { type InAppMessageActionUrlType, type InAppMessageClickEvent, type InAppMessageClickResult, type InAppMessageDidDismissEvent, type InAppMessageDidDisplayEvent, type InAppMessageWillDismissEvent, type InAppMessageWillDisplayEvent, LogLevel, type NotificationClickEvent, type NotificationClickResult, NotificationWillDisplayEvent, type OSInAppMessage, OSNotification, OSNotificationPermission, type OneSignalCapacitorPlugin, OneSignalPlugin, type PushSubscriptionChangedState, type PushSubscriptionState, type UserChangedState, type UserState, OneSignal as default };