@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.
package/dist/index.js ADDED
@@ -0,0 +1,849 @@
1
+ import { registerPlugin } from "@capacitor/core";
2
+ //#region src/DebugNamespace.ts
3
+ const LogLevel = {
4
+ None: 0,
5
+ Fatal: 1,
6
+ Error: 2,
7
+ Warn: 3,
8
+ Info: 4,
9
+ Debug: 5,
10
+ Verbose: 6
11
+ };
12
+ var Debug = class {
13
+ constructor(plugin) {
14
+ this._plugin = plugin;
15
+ }
16
+ /**
17
+ * Enable logging to help debug if you run into an issue setting up OneSignal.
18
+ * @param {LogLevel} logLevel - Sets the logging level to print to the Android LogCat log or Xcode log.
19
+ * @returns void
20
+ */
21
+ setLogLevel(logLevel) {
22
+ this._plugin.setLogLevel({ logLevel });
23
+ }
24
+ /**
25
+ * Enable logging to help debug if you run into an issue setting up OneSignal.
26
+ * @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs.
27
+ * @returns void
28
+ */
29
+ setAlertLevel(visualLogLevel) {
30
+ this._plugin.setAlertLevel({ logLevel: visualLogLevel });
31
+ }
32
+ };
33
+ //#endregion
34
+ //#region src/helpers.ts
35
+ /**
36
+ * Removes a listener from an array of listeners.
37
+ * @param array The array of listeners
38
+ * @param listener The listener to remove
39
+ */
40
+ function removeListener(array, listener) {
41
+ const index = array.indexOf(listener);
42
+ if (index !== -1) array.splice(index, 1);
43
+ }
44
+ /**
45
+ * Returns true if the value is a JSON-serializable object.
46
+ */
47
+ function isObjectSerializable(value) {
48
+ if (!(typeof value === "object" && value !== null && !Array.isArray(value))) return false;
49
+ try {
50
+ JSON.stringify(value);
51
+ return true;
52
+ } catch {
53
+ return false;
54
+ }
55
+ }
56
+ //#endregion
57
+ //#region src/InAppMessagesNamespace.ts
58
+ var InAppMessages = class {
59
+ constructor(plugin) {
60
+ this._inAppMessageClickListeners = [];
61
+ this._willDisplayInAppMessageListeners = [];
62
+ this._didDisplayInAppMessageListeners = [];
63
+ this._willDismissInAppMessageListeners = [];
64
+ this._didDismissInAppMessageListeners = [];
65
+ this._plugin = plugin;
66
+ }
67
+ _processFunctionList(array, param) {
68
+ for (let i = 0; i < array.length; i++) array[i](param);
69
+ }
70
+ /**
71
+ * Add event listeners for In-App Message click and/or lifecycle events.
72
+ * @param event
73
+ * @param listener
74
+ * @returns
75
+ */
76
+ addEventListener(event, listener) {
77
+ if (event === "click") {
78
+ this._inAppMessageClickListeners.push(listener);
79
+ this._plugin.addListener("inAppMessageClick", (json) => {
80
+ this._processFunctionList(this._inAppMessageClickListeners, json);
81
+ });
82
+ } else if (event === "willDisplay") {
83
+ this._willDisplayInAppMessageListeners.push(listener);
84
+ this._plugin.addListener("inAppMessageWillDisplay", (event) => {
85
+ this._processFunctionList(this._willDisplayInAppMessageListeners, event);
86
+ });
87
+ } else if (event === "didDisplay") {
88
+ this._didDisplayInAppMessageListeners.push(listener);
89
+ this._plugin.addListener("inAppMessageDidDisplay", (event) => {
90
+ this._processFunctionList(this._didDisplayInAppMessageListeners, event);
91
+ });
92
+ } else if (event === "willDismiss") {
93
+ this._willDismissInAppMessageListeners.push(listener);
94
+ this._plugin.addListener("inAppMessageWillDismiss", (event) => {
95
+ this._processFunctionList(this._willDismissInAppMessageListeners, event);
96
+ });
97
+ } else if (event === "didDismiss") {
98
+ this._didDismissInAppMessageListeners.push(listener);
99
+ this._plugin.addListener("inAppMessageDidDismiss", (event) => {
100
+ this._processFunctionList(this._didDismissInAppMessageListeners, event);
101
+ });
102
+ }
103
+ }
104
+ /**
105
+ * Remove event listeners for In-App Message click and/or lifecycle events.
106
+ * @param event
107
+ * @param listener
108
+ * @returns
109
+ */
110
+ removeEventListener(event, listener) {
111
+ if (event === "click") removeListener(this._inAppMessageClickListeners, listener);
112
+ else if (event === "willDisplay") removeListener(this._willDisplayInAppMessageListeners, listener);
113
+ else if (event === "didDisplay") removeListener(this._didDisplayInAppMessageListeners, listener);
114
+ else if (event === "willDismiss") removeListener(this._willDismissInAppMessageListeners, listener);
115
+ else if (event === "didDismiss") removeListener(this._didDismissInAppMessageListeners, listener);
116
+ }
117
+ /**
118
+ * Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
119
+ * @param {string} key
120
+ * @param {string} value
121
+ * @returns Promise<void>
122
+ */
123
+ addTrigger(key, value) {
124
+ return this.addTriggers({ [key]: value });
125
+ }
126
+ /**
127
+ * Add multiple triggers for the current user.
128
+ * @param {[key: string]: string} triggers
129
+ * @returns Promise<void>
130
+ */
131
+ addTriggers(triggers) {
132
+ Object.keys(triggers).forEach(function(key) {
133
+ if (typeof triggers[key] !== "string") triggers[key] = JSON.stringify(triggers[key]);
134
+ });
135
+ return this._plugin.addTriggers({ triggers });
136
+ }
137
+ /**
138
+ * Remove the trigger with the provided key from the current user.
139
+ * @param {string} key
140
+ * @returns Promise<void>
141
+ */
142
+ removeTrigger(key) {
143
+ return this.removeTriggers([key]);
144
+ }
145
+ /**
146
+ * Remove multiple triggers from the current user.
147
+ * @param {string[]} keys
148
+ * @returns Promise<void>
149
+ */
150
+ removeTriggers(keys) {
151
+ if (!Array.isArray(keys)) console.error("OneSignal: removeTriggers: argument must be of type Array");
152
+ return this._plugin.removeTriggers({ keys });
153
+ }
154
+ /**
155
+ * Clear all triggers from the current user.
156
+ * @returns Promise<void>
157
+ */
158
+ clearTriggers() {
159
+ return this._plugin.clearTriggers();
160
+ }
161
+ /**
162
+ * Set whether in-app messaging is currently paused.
163
+ * @param {boolean} pause
164
+ * @returns void
165
+ */
166
+ setPaused(pause) {
167
+ this._plugin.setPaused({ pause });
168
+ }
169
+ /**
170
+ * Whether in-app messaging is currently paused.
171
+ * @returns {Promise<boolean>}
172
+ */
173
+ async getPaused() {
174
+ return (await this._plugin.isPaused()).paused;
175
+ }
176
+ };
177
+ //#endregion
178
+ //#region src/LiveActivitiesNamespace.ts
179
+ var LiveActivities = class {
180
+ constructor(plugin) {
181
+ this._plugin = plugin;
182
+ }
183
+ /**
184
+ * Enter a live activity
185
+ * @param {string} activityId
186
+ * @param {string} token
187
+ * @param {Function} onSuccess
188
+ * @param {Function} onFailure
189
+ * @returns void
190
+ */
191
+ enter(activityId, token, onSuccess, onFailure) {
192
+ this._plugin.enterLiveActivity({
193
+ activityId,
194
+ token
195
+ }).then((result) => {
196
+ onSuccess?.(result);
197
+ }).catch((error) => {
198
+ onFailure?.(error);
199
+ });
200
+ }
201
+ /**
202
+ * Exit a live activity
203
+ * @param {string} activityId
204
+ * @param {Function} onSuccess
205
+ * @param {Function} onFailure
206
+ * @returns void
207
+ * @deprecated Currently unsupported, avoid using this method.
208
+ */
209
+ exit(activityId, onSuccess, onFailure) {
210
+ this._plugin.exitLiveActivity({ activityId }).then((result) => {
211
+ onSuccess?.(result);
212
+ }).catch((error) => {
213
+ onFailure?.(error);
214
+ });
215
+ }
216
+ /**
217
+ * Indicate this device is capable of receiving pushToStart live activities for the
218
+ * `activityType`. Only applies to iOS.
219
+ * @param {string} activityType
220
+ * @param {string} token
221
+ */
222
+ setPushToStartToken(activityType, token) {
223
+ return this._plugin.setPushToStartToken({
224
+ activityType,
225
+ token
226
+ });
227
+ }
228
+ /**
229
+ * Indicate this device is no longer capable of receiving pushToStart live activities
230
+ * for the `activityType`. Only applies to iOS.
231
+ * @param {string} activityType
232
+ */
233
+ removePushToStartToken(activityType) {
234
+ return this._plugin.removePushToStartToken({ activityType });
235
+ }
236
+ /**
237
+ * Enable the OneSignalSDK to setup the default `DefaultLiveActivityAttributes` structure.
238
+ * Only applies to iOS.
239
+ * @param {LiveActivitySetupOptions} options
240
+ */
241
+ setupDefault(options) {
242
+ return this._plugin.setupDefaultLiveActivity(options);
243
+ }
244
+ /**
245
+ * Start a new LiveActivity that is modelled by the default `DefaultLiveActivityAttributes`
246
+ * structure. Only applies to iOS.
247
+ * @param {string} activityId
248
+ * @param {object} attributes
249
+ * @param {object} content
250
+ */
251
+ startDefault(activityId, attributes, content) {
252
+ return this._plugin.startDefaultLiveActivity({
253
+ activityId,
254
+ attributes,
255
+ content
256
+ });
257
+ }
258
+ };
259
+ //#endregion
260
+ //#region src/LocationNamespace.ts
261
+ var Location = class {
262
+ constructor(plugin) {
263
+ this._plugin = plugin;
264
+ }
265
+ /**
266
+ * Prompts the user for location permissions to allow geotagging from the OneSignal dashboard.
267
+ * @returns Promise<void>
268
+ */
269
+ requestPermission() {
270
+ return this._plugin.requestLocationPermission();
271
+ }
272
+ /**
273
+ * Disable or enable location collection (defaults to enabled if your app has location permission).
274
+ * @param {boolean} shared
275
+ * @returns void
276
+ */
277
+ setShared(shared) {
278
+ this._plugin.setLocationShared({ shared });
279
+ }
280
+ /**
281
+ * Whether location is currently shared with OneSignal.
282
+ * @returns {Promise<boolean>}
283
+ */
284
+ async isShared() {
285
+ return (await this._plugin.isLocationShared()).shared;
286
+ }
287
+ };
288
+ //#endregion
289
+ //#region src/OSNotification.ts
290
+ let _pluginRef$1;
291
+ function _setOSNotificationPlugin(plugin) {
292
+ _pluginRef$1 = plugin;
293
+ }
294
+ var OSNotification = class {
295
+ constructor(receivedEvent) {
296
+ this.notificationId = receivedEvent.notificationId;
297
+ this.body = receivedEvent.body;
298
+ this.title = receivedEvent.title;
299
+ this.additionalData = receivedEvent.additionalData;
300
+ if (typeof receivedEvent.rawPayload === "string") this.rawPayload = JSON.parse(receivedEvent.rawPayload);
301
+ else this.rawPayload = receivedEvent.rawPayload;
302
+ this.launchURL = receivedEvent.launchURL;
303
+ this.sound = receivedEvent.sound;
304
+ if (receivedEvent.actionButtons) this.actionButtons = receivedEvent.actionButtons;
305
+ if (receivedEvent.groupKey) this.groupKey = receivedEvent.groupKey;
306
+ if (receivedEvent.ledColor) this.ledColor = receivedEvent.ledColor;
307
+ if (typeof receivedEvent.priority !== "undefined") this.priority = receivedEvent.priority;
308
+ if (receivedEvent.smallIcon) this.smallIcon = receivedEvent.smallIcon;
309
+ if (receivedEvent.largeIcon) this.largeIcon = receivedEvent.largeIcon;
310
+ if (receivedEvent.bigPicture) this.bigPicture = receivedEvent.bigPicture;
311
+ if (receivedEvent.collapseId) this.collapseId = receivedEvent.collapseId;
312
+ if (receivedEvent.groupMessage) this.groupMessage = receivedEvent.groupMessage;
313
+ if (receivedEvent.fromProjectNumber) this.fromProjectNumber = receivedEvent.fromProjectNumber;
314
+ if (receivedEvent.smallIconAccentColor) this.smallIconAccentColor = receivedEvent.smallIconAccentColor;
315
+ if (receivedEvent.lockScreenVisibility) this.lockScreenVisibility = receivedEvent.lockScreenVisibility;
316
+ if (receivedEvent.androidNotificationId) this.androidNotificationId = receivedEvent.androidNotificationId;
317
+ if (receivedEvent.groupedNotifications && receivedEvent.groupedNotifications.length) this.groupedNotifications = receivedEvent.groupedNotifications;
318
+ if (receivedEvent.badge) this.badge = receivedEvent.badge;
319
+ if (receivedEvent.category) this.category = receivedEvent.category;
320
+ if (receivedEvent.threadId) this.threadId = receivedEvent.threadId;
321
+ if (receivedEvent.subtitle) this.subtitle = receivedEvent.subtitle;
322
+ if (receivedEvent.templateId) this.templateId = receivedEvent.templateId;
323
+ if (receivedEvent.attachments) this.attachments = receivedEvent.attachments;
324
+ if (receivedEvent.templateName) this.templateName = receivedEvent.templateName;
325
+ if (receivedEvent.mutableContent) this.mutableContent = receivedEvent.mutableContent;
326
+ if (receivedEvent.badgeIncrement) this.badgeIncrement = receivedEvent.badgeIncrement;
327
+ if (receivedEvent.contentAvailable) this.contentAvailable = receivedEvent.contentAvailable;
328
+ if (receivedEvent.relevanceScore) this.relevanceScore = receivedEvent.relevanceScore;
329
+ if (receivedEvent.interruptionLevel) this.interruptionLevel = receivedEvent.interruptionLevel;
330
+ }
331
+ /**
332
+ * Display the notification.
333
+ * @returns void
334
+ */
335
+ display() {
336
+ if (_pluginRef$1) _pluginRef$1.displayNotification({ notificationId: this.notificationId });
337
+ }
338
+ };
339
+ //#endregion
340
+ //#region src/NotificationReceivedEvent.ts
341
+ let _pluginRef;
342
+ function _setNotificationEventPlugin(plugin) {
343
+ _pluginRef = plugin;
344
+ }
345
+ var NotificationWillDisplayEvent = class {
346
+ constructor(displayEvent) {
347
+ this.notification = new OSNotification(displayEvent);
348
+ }
349
+ /**
350
+ * Call this to prevent OneSignal from displaying the notification automatically.
351
+ * This method can be called up to two times with false and then true, if processing time is needed.
352
+ * Typically this is only possible within a short
353
+ * time-frame (~30 seconds) after the notification is received on the device.
354
+ * @param discard an [preventDefault] set to true to dismiss the notification with no
355
+ * possibility of displaying it in the future.
356
+ */
357
+ preventDefault(discard = false) {
358
+ if (_pluginRef) _pluginRef.preventDefault({
359
+ notificationId: this.notification.notificationId,
360
+ discard
361
+ });
362
+ }
363
+ getNotification() {
364
+ return this.notification;
365
+ }
366
+ };
367
+ //#endregion
368
+ //#region src/NotificationsNamespace.ts
369
+ const OSNotificationPermission = {
370
+ NotDetermined: 0,
371
+ Denied: 1,
372
+ Authorized: 2,
373
+ Provisional: 3,
374
+ Ephemeral: 4
375
+ };
376
+ var Notifications = class {
377
+ constructor(plugin) {
378
+ this._permissionObserverList = [];
379
+ this._notificationClickedListeners = [];
380
+ this._notificationWillDisplayListeners = [];
381
+ this._hasRegisteredClickListener = false;
382
+ this._hasRegisteredForegroundWillDisplayListener = false;
383
+ this._hasRegisteredPermissionListener = false;
384
+ this._plugin = plugin;
385
+ }
386
+ _processFunctionList(array, param) {
387
+ for (let i = 0; i < array.length; i++) array[i](param);
388
+ }
389
+ /**
390
+ * Whether this app has push notification permission. Returns true if the user has accepted permissions,
391
+ * or if the app has ephemeral or provisional permission.
392
+ */
393
+ async hasPermission() {
394
+ return (await this._plugin.getPermission()).permission;
395
+ }
396
+ /**
397
+ * iOS Only.
398
+ * Returns the native permission of the device.
399
+ * @returns {Promise<OSNotificationPermission>}
400
+ */
401
+ async permissionNative() {
402
+ return (await this._plugin.permissionNative()).permission;
403
+ }
404
+ /**
405
+ * Prompt the user for permission to receive push notifications.
406
+ * Use the fallbackToSettings parameter to prompt to open the settings app if a user has already declined push permissions.
407
+ * @param {boolean} fallbackToSettings
408
+ * @returns {Promise<boolean>}
409
+ */
410
+ async requestPermission(fallbackToSettings) {
411
+ const fallback = fallbackToSettings ?? false;
412
+ return (await this._plugin.requestPermission({ fallbackToSettings: fallback })).permission;
413
+ }
414
+ /**
415
+ * Whether attempting to request notification permission will show a prompt.
416
+ * Returns true if the device has not been prompted for push notification permission already.
417
+ * @returns {Promise<boolean>}
418
+ */
419
+ async canRequestPermission() {
420
+ return (await this._plugin.canRequestPermission()).canRequest;
421
+ }
422
+ /**
423
+ * iOS Only.
424
+ * Instead of having to prompt the user for permission to send them push notifications,
425
+ * your app can request provisional authorization.
426
+ * @param {(response: boolean)=>void} handler
427
+ * @returns void
428
+ */
429
+ registerForProvisionalAuthorization(handler) {
430
+ this._plugin.registerForProvisionalAuthorization().then((result) => {
431
+ handler?.(result.accepted);
432
+ });
433
+ }
434
+ /**
435
+ * Add listeners for notification events.
436
+ * @param event
437
+ * @param listener
438
+ * @returns
439
+ */
440
+ addEventListener(event, listener) {
441
+ if (event === "click") {
442
+ this._notificationClickedListeners.push(listener);
443
+ if (!this._hasRegisteredClickListener) {
444
+ this._hasRegisteredClickListener = true;
445
+ this._plugin.addListener("notificationClick", (json) => {
446
+ this._processFunctionList(this._notificationClickedListeners, json);
447
+ });
448
+ }
449
+ } else if (event === "foregroundWillDisplay") {
450
+ this._notificationWillDisplayListeners.push(listener);
451
+ if (!this._hasRegisteredForegroundWillDisplayListener) {
452
+ this._hasRegisteredForegroundWillDisplayListener = true;
453
+ this._plugin.addListener("notificationForegroundWillDisplay", (notification) => {
454
+ this._notificationWillDisplayListeners.forEach((listener) => {
455
+ listener(new NotificationWillDisplayEvent(notification));
456
+ });
457
+ this._plugin.proceedWithWillDisplay({ notificationId: notification.notificationId });
458
+ });
459
+ }
460
+ } else if (event === "permissionChange") {
461
+ this._permissionObserverList.push(listener);
462
+ if (!this._hasRegisteredPermissionListener) {
463
+ this._hasRegisteredPermissionListener = true;
464
+ this._plugin.addListener("permissionChange", (state) => {
465
+ this._processFunctionList(this._permissionObserverList, state.permission);
466
+ });
467
+ }
468
+ }
469
+ }
470
+ /**
471
+ * Remove listeners for notification events.
472
+ * @param event
473
+ * @param listener
474
+ * @returns
475
+ */
476
+ removeEventListener(event, listener) {
477
+ if (event === "click") removeListener(this._notificationClickedListeners, listener);
478
+ else if (event === "foregroundWillDisplay") removeListener(this._notificationWillDisplayListeners, listener);
479
+ else if (event === "permissionChange") removeListener(this._permissionObserverList, listener);
480
+ }
481
+ /**
482
+ * Removes all OneSignal notifications.
483
+ * @returns Promise<void>
484
+ */
485
+ clearAll() {
486
+ return this._plugin.clearAllNotifications();
487
+ }
488
+ /**
489
+ * Android only.
490
+ * Cancels a single OneSignal notification based on its Android notification integer ID.
491
+ * @param {number} id - notification id to cancel
492
+ * @returns Promise<void>
493
+ */
494
+ removeNotification(id) {
495
+ return this._plugin.removeNotification({ id });
496
+ }
497
+ /**
498
+ * Android only.
499
+ * Cancels a group of OneSignal notifications with the provided group key.
500
+ * @param {string} id - notification group id to cancel
501
+ * @returns Promise<void>
502
+ */
503
+ removeGroupedNotifications(id) {
504
+ return this._plugin.removeGroupedNotifications({ id });
505
+ }
506
+ };
507
+ //#endregion
508
+ //#region src/SessionNamespace.ts
509
+ var Session = class {
510
+ constructor(plugin) {
511
+ this._plugin = plugin;
512
+ }
513
+ /**
514
+ * Add an outcome with the provided name, captured against the current session.
515
+ * @param {string} name
516
+ * @returns Promise<void>
517
+ */
518
+ addOutcome(name) {
519
+ return this._plugin.addOutcome({ name });
520
+ }
521
+ /**
522
+ * Add a unique outcome with the provided name, captured against the current session.
523
+ * @param {string} name
524
+ * @returns Promise<void>
525
+ */
526
+ addUniqueOutcome(name) {
527
+ return this._plugin.addUniqueOutcome({ name });
528
+ }
529
+ /**
530
+ * Add an outcome with the provided name and value, captured against the current session.
531
+ * @param {string} name
532
+ * @param {number} value
533
+ * @returns Promise<void>
534
+ */
535
+ addOutcomeWithValue(name, value) {
536
+ return this._plugin.addOutcomeWithValue({
537
+ name,
538
+ value
539
+ });
540
+ }
541
+ };
542
+ //#endregion
543
+ //#region src/PushSubscriptionNamespace.ts
544
+ var PushSubscription = class {
545
+ constructor(plugin) {
546
+ this._subscriptionObserverList = [];
547
+ this._plugin = plugin;
548
+ }
549
+ _processFunctionList(array, param) {
550
+ for (let i = 0; i < array.length; i++) array[i](param);
551
+ }
552
+ /**
553
+ * The readonly push subscription ID.
554
+ * @returns {Promise<string | null>}
555
+ */
556
+ async getIdAsync() {
557
+ return (await this._plugin.getPushSubscriptionId()).id;
558
+ }
559
+ /**
560
+ * The readonly push token.
561
+ * @returns {Promise<string | null>}
562
+ */
563
+ async getTokenAsync() {
564
+ return (await this._plugin.getPushSubscriptionToken()).token;
565
+ }
566
+ /**
567
+ * Gets a boolean value indicating whether the current user is opted in to push notifications.
568
+ * This returns true when the app has notifications permission and optOut() is NOT called.
569
+ * Note: Does not take into account the existence of the subscription ID and push token.
570
+ * This boolean may return true but push notifications may still not be received by the user.
571
+ * @returns {Promise<boolean>}
572
+ */
573
+ async getOptedInAsync() {
574
+ return (await this._plugin.getPushSubscriptionOptedIn()).optedIn;
575
+ }
576
+ /**
577
+ * Add a callback that fires when the OneSignal push subscription state changes.
578
+ * @param {(event: PushSubscriptionChangedState)=>void} listener
579
+ * @returns void
580
+ */
581
+ addEventListener(_event, listener) {
582
+ this._subscriptionObserverList.push(listener);
583
+ this._plugin.addListener("pushSubscriptionChange", (state) => {
584
+ this._processFunctionList(this._subscriptionObserverList, state);
585
+ });
586
+ }
587
+ /**
588
+ * Remove a push subscription observer that has been previously added.
589
+ * @param {(event: PushSubscriptionChangedState)=>void} listener
590
+ * @returns void
591
+ */
592
+ removeEventListener(_event, listener) {
593
+ removeListener(this._subscriptionObserverList, listener);
594
+ }
595
+ /**
596
+ * 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.
597
+ * @returns Promise<void>
598
+ */
599
+ optIn() {
600
+ return this._plugin.optInPushSubscription();
601
+ }
602
+ /**
603
+ * 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.
604
+ * @returns Promise<void>
605
+ */
606
+ optOut() {
607
+ return this._plugin.optOutPushSubscription();
608
+ }
609
+ };
610
+ //#endregion
611
+ //#region src/UserNamespace.ts
612
+ var User = class {
613
+ constructor(plugin) {
614
+ this._userStateObserverList = [];
615
+ this._plugin = plugin;
616
+ this.pushSubscription = new PushSubscription(plugin);
617
+ }
618
+ _processFunctionList(array, param) {
619
+ for (let i = 0; i < array.length; i++) array[i](param);
620
+ }
621
+ /**
622
+ * Explicitly set a 2-character language code for the user.
623
+ * @param {string} language
624
+ * @returns Promise<void>
625
+ */
626
+ setLanguage(language) {
627
+ return this._plugin.setLanguage({ language });
628
+ }
629
+ /**
630
+ * 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.
631
+ * @param {string} label
632
+ * @param {string} id
633
+ * @returns Promise<void>
634
+ */
635
+ addAlias(label, id) {
636
+ return this._plugin.addAliases({ aliases: { [label]: id } });
637
+ }
638
+ /**
639
+ * Set aliases for the current user. If any alias already exists, it will be overwritten to the new values.
640
+ * @param {object} aliases
641
+ * @returns Promise<void>
642
+ */
643
+ addAliases(aliases) {
644
+ return this._plugin.addAliases({ aliases });
645
+ }
646
+ /**
647
+ * Remove an alias from the current user.
648
+ * @param {string} label
649
+ * @returns Promise<void>
650
+ */
651
+ removeAlias(label) {
652
+ return this._plugin.removeAliases({ labels: [label] });
653
+ }
654
+ /**
655
+ * Remove aliases from the current user.
656
+ * @param {string[]} labels
657
+ * @returns Promise<void>
658
+ */
659
+ removeAliases(labels) {
660
+ return this._plugin.removeAliases({ labels });
661
+ }
662
+ /**
663
+ * Add a new email subscription to the current user.
664
+ * @param {string} email
665
+ * @returns Promise<void>
666
+ */
667
+ addEmail(email) {
668
+ return this._plugin.addEmail({ email });
669
+ }
670
+ /**
671
+ * Remove an email subscription from the current user.
672
+ * @param {string} email
673
+ * @returns Promise<void>
674
+ */
675
+ removeEmail(email) {
676
+ return this._plugin.removeEmail({ email });
677
+ }
678
+ /**
679
+ * Add a new SMS subscription to the current user.
680
+ * @param {string} smsNumber
681
+ * @returns Promise<void>
682
+ */
683
+ addSms(smsNumber) {
684
+ return this._plugin.addSms({ smsNumber });
685
+ }
686
+ /**
687
+ * Remove an SMS subscription from the current user.
688
+ * @param {string} smsNumber
689
+ * @returns Promise<void>
690
+ */
691
+ removeSms(smsNumber) {
692
+ return this._plugin.removeSms({ smsNumber });
693
+ }
694
+ /**
695
+ * 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.
696
+ * @param {string} key
697
+ * @param {string} value
698
+ * @returns Promise<void>
699
+ */
700
+ addTag(key, value) {
701
+ return this._plugin.addTags({ tags: { [key]: value } });
702
+ }
703
+ /**
704
+ * 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.
705
+ * @param {object} tags
706
+ * @returns Promise<void>
707
+ */
708
+ addTags(tags) {
709
+ const convertedTags = tags;
710
+ Object.keys(tags).forEach(function(key) {
711
+ if (typeof convertedTags[key] !== "string") convertedTags[key] = JSON.stringify(convertedTags[key]);
712
+ });
713
+ return this._plugin.addTags({ tags: convertedTags });
714
+ }
715
+ /**
716
+ * Remove the data tag with the provided key from the current user.
717
+ * @param {string} key
718
+ * @returns Promise<void>
719
+ */
720
+ removeTag(key) {
721
+ return this._plugin.removeTags({ keys: [key] });
722
+ }
723
+ /**
724
+ * Remove multiple tags with the provided keys from the current user.
725
+ * @param {string[]} keys
726
+ * @returns Promise<void>
727
+ */
728
+ removeTags(keys) {
729
+ return this._plugin.removeTags({ keys });
730
+ }
731
+ /**
732
+ * Returns the local tags for the current user.
733
+ * @returns Promise<{ [key: string]: string }>
734
+ */
735
+ async getTags() {
736
+ return (await this._plugin.getTags()).tags;
737
+ }
738
+ /**
739
+ * Add a callback that fires when the OneSignal User state changes.
740
+ * @param {(event: UserChangedState)=>void} listener
741
+ * @returns void
742
+ */
743
+ addEventListener(_event, listener) {
744
+ this._userStateObserverList.push(listener);
745
+ this._plugin.addListener("userStateChange", (state) => {
746
+ this._processFunctionList(this._userStateObserverList, state);
747
+ });
748
+ }
749
+ /**
750
+ * Remove a User State observer that has been previously added.
751
+ * @param {(event: UserChangedState)=>void} listener
752
+ * @returns void
753
+ */
754
+ removeEventListener(_event, listener) {
755
+ removeListener(this._userStateObserverList, listener);
756
+ }
757
+ /**
758
+ * Get the nullable OneSignal Id associated with the current user.
759
+ * @returns {Promise<string | null>}
760
+ */
761
+ async getOnesignalId() {
762
+ return (await this._plugin.getOnesignalId()).onesignalId;
763
+ }
764
+ /**
765
+ * Get the nullable External Id associated with the current user.
766
+ * @returns {Promise<string | null>}
767
+ */
768
+ async getExternalId() {
769
+ return (await this._plugin.getExternalId()).externalId;
770
+ }
771
+ /**
772
+ * Track a custom event with the provided name and optional properties.
773
+ * @param {string} name - The name of the custom event
774
+ * @param {object} [properties] - Optional properties to associate with the event
775
+ * @returns Promise<void>
776
+ */
777
+ trackEvent(name, properties) {
778
+ if (properties !== void 0 && !isObjectSerializable(properties)) {
779
+ console.error("Properties must be a JSON-serializable object");
780
+ return Promise.resolve();
781
+ }
782
+ return this._plugin.trackEvent({
783
+ name,
784
+ properties
785
+ });
786
+ }
787
+ };
788
+ //#endregion
789
+ //#region src/OneSignalPlugin.ts
790
+ var OneSignalPlugin = class {
791
+ constructor(plugin) {
792
+ this._appID = "";
793
+ this._plugin = plugin;
794
+ _setOSNotificationPlugin(plugin);
795
+ _setNotificationEventPlugin(plugin);
796
+ this.User = new User(plugin);
797
+ this.Debug = new Debug(plugin);
798
+ this.Session = new Session(plugin);
799
+ this.Location = new Location(plugin);
800
+ this.InAppMessages = new InAppMessages(plugin);
801
+ this.Notifications = new Notifications(plugin);
802
+ this.LiveActivities = new LiveActivities(plugin);
803
+ }
804
+ /**
805
+ * Initializes the OneSignal SDK. This should be called during startup of the application.
806
+ * @param {string} appId
807
+ * @returns Promise<void>
808
+ */
809
+ initialize(appId) {
810
+ this._appID = appId;
811
+ return this._plugin.initialize({ appId: this._appID });
812
+ }
813
+ /**
814
+ * 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.
815
+ * @param {string} externalId
816
+ * @returns Promise<void>
817
+ */
818
+ login(externalId) {
819
+ return this._plugin.login({ externalId });
820
+ }
821
+ /**
822
+ * Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user.
823
+ * @returns Promise<void>
824
+ */
825
+ logout() {
826
+ return this._plugin.logout();
827
+ }
828
+ /**
829
+ * 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.
830
+ * @param {boolean} required
831
+ * @returns void
832
+ */
833
+ setConsentRequired(required) {
834
+ this._plugin.setConsentRequired({ required });
835
+ }
836
+ /**
837
+ * Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.
838
+ * @param {boolean} granted
839
+ * @returns void
840
+ */
841
+ setConsentGiven(granted) {
842
+ this._plugin.setConsentGiven({ granted });
843
+ }
844
+ };
845
+ //#endregion
846
+ //#region src/index.ts
847
+ const OneSignal = new OneSignalPlugin(registerPlugin("OneSignalCapacitor"));
848
+ //#endregion
849
+ export { LogLevel, NotificationWillDisplayEvent, OSNotification, OSNotificationPermission, OneSignalPlugin, OneSignal as default };