onesignal-vue 2.0.1 → 2.2.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/.eslintrc.cjs +38 -0
- package/.github/workflows/release.yml +40 -0
- package/.releaserc.json +133 -0
- package/CHANGELOG.md +13 -0
- package/README.md +98 -81
- package/dist/index.d.ts +204 -30
- package/dist/index.js +89 -48
- package/dist/index.js.map +1 -1
- package/index.ts +378 -136
- package/package.json +5 -5
- package/tsconfig.json +0 -1
- package/.eslintrc.js +0 -44
package/dist/index.d.ts
CHANGED
|
@@ -13,18 +13,18 @@ declare global {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
interface AutoPromptOptions {
|
|
16
|
+
export interface AutoPromptOptions {
|
|
17
17
|
force?: boolean;
|
|
18
18
|
forceSlidedownOverNative?: boolean;
|
|
19
19
|
slidedownPromptOptions?: IOneSignalAutoPromptOptions;
|
|
20
20
|
}
|
|
21
|
-
interface IOneSignalAutoPromptOptions {
|
|
21
|
+
export interface IOneSignalAutoPromptOptions {
|
|
22
22
|
force?: boolean;
|
|
23
23
|
forceSlidedownOverNative?: boolean;
|
|
24
24
|
isInUpdateMode?: boolean;
|
|
25
25
|
categoryOptions?: IOneSignalCategories;
|
|
26
26
|
}
|
|
27
|
-
interface IOneSignalCategories {
|
|
27
|
+
export interface IOneSignalCategories {
|
|
28
28
|
positiveUpdateButton: string;
|
|
29
29
|
negativeUpdateButton: string;
|
|
30
30
|
savingButtonText: string;
|
|
@@ -32,24 +32,24 @@ interface IOneSignalCategories {
|
|
|
32
32
|
updateMessage: string;
|
|
33
33
|
tags: IOneSignalTagCategory[];
|
|
34
34
|
}
|
|
35
|
-
interface IOneSignalTagCategory {
|
|
35
|
+
export interface IOneSignalTagCategory {
|
|
36
36
|
tag: string;
|
|
37
37
|
label: string;
|
|
38
38
|
checked?: boolean;
|
|
39
39
|
}
|
|
40
|
-
type PushSubscriptionNamespaceProperties = {
|
|
40
|
+
export type PushSubscriptionNamespaceProperties = {
|
|
41
41
|
id: string | null | undefined;
|
|
42
42
|
token: string | null | undefined;
|
|
43
43
|
optedIn: boolean;
|
|
44
44
|
};
|
|
45
|
-
type SubscriptionChangeEvent = {
|
|
45
|
+
export type SubscriptionChangeEvent = {
|
|
46
46
|
previous: PushSubscriptionNamespaceProperties;
|
|
47
47
|
current: PushSubscriptionNamespaceProperties;
|
|
48
48
|
};
|
|
49
|
-
type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
|
|
50
|
-
type SlidedownEventName = 'slidedownShown';
|
|
51
|
-
type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
|
|
52
|
-
interface IOSNotification {
|
|
49
|
+
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
|
|
50
|
+
export type SlidedownEventName = 'slidedownShown';
|
|
51
|
+
export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
|
|
52
|
+
export interface IOSNotification {
|
|
53
53
|
/**
|
|
54
54
|
* The OneSignal notification id;
|
|
55
55
|
* - Primary id on OneSignal's REST API and dashboard
|
|
@@ -84,7 +84,7 @@ interface IOSNotification {
|
|
|
84
84
|
* If this value is the same as existing notification, it will replace it
|
|
85
85
|
* Can be set when creating the notification with "Web Push Topic" on the dashboard
|
|
86
86
|
* or web_push_topic from the REST API.
|
|
87
|
-
|
|
87
|
+
*/
|
|
88
88
|
readonly topic?: string;
|
|
89
89
|
/**
|
|
90
90
|
* Custom object that was sent with the notification;
|
|
@@ -100,7 +100,7 @@ interface IOSNotification {
|
|
|
100
100
|
*/
|
|
101
101
|
readonly confirmDelivery: boolean;
|
|
102
102
|
}
|
|
103
|
-
interface IOSNotificationActionButton {
|
|
103
|
+
export interface IOSNotificationActionButton {
|
|
104
104
|
/**
|
|
105
105
|
* Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
|
|
106
106
|
* and host page through events to identify which button was clicked.
|
|
@@ -120,51 +120,216 @@ interface IOSNotificationActionButton {
|
|
|
120
120
|
*/
|
|
121
121
|
readonly launchURL?: string;
|
|
122
122
|
}
|
|
123
|
-
interface NotificationClickResult {
|
|
123
|
+
export interface NotificationClickResult {
|
|
124
124
|
readonly actionId?: string;
|
|
125
125
|
readonly url?: string;
|
|
126
126
|
}
|
|
127
|
-
type NotificationEventTypeMap = {
|
|
127
|
+
export type NotificationEventTypeMap = {
|
|
128
128
|
'click': NotificationClickEvent;
|
|
129
129
|
'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
|
|
130
130
|
'dismiss': NotificationDismissEvent;
|
|
131
131
|
'permissionChange': boolean;
|
|
132
132
|
'permissionPromptDisplay': void;
|
|
133
133
|
};
|
|
134
|
-
interface NotificationForegroundWillDisplayEvent {
|
|
134
|
+
export interface NotificationForegroundWillDisplayEvent {
|
|
135
135
|
readonly notification: IOSNotification;
|
|
136
136
|
preventDefault(): void;
|
|
137
137
|
}
|
|
138
|
-
interface NotificationDismissEvent {
|
|
138
|
+
export interface NotificationDismissEvent {
|
|
139
139
|
notification: IOSNotification;
|
|
140
140
|
}
|
|
141
|
-
interface NotificationClickEvent {
|
|
141
|
+
export interface NotificationClickEvent {
|
|
142
142
|
readonly notification: IOSNotification;
|
|
143
143
|
readonly result: NotificationClickResult;
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
export type UserChangeEvent = {
|
|
146
|
+
current: UserNamespaceProperties;
|
|
147
|
+
};
|
|
148
|
+
export type UserNamespaceProperties = {
|
|
149
|
+
onesignalId: string | undefined;
|
|
150
|
+
externalId: string | undefined;
|
|
151
|
+
};
|
|
152
|
+
export interface IInitObject {
|
|
146
153
|
appId: string;
|
|
147
154
|
subdomainName?: string;
|
|
148
155
|
requiresUserPrivacyConsent?: boolean;
|
|
149
|
-
promptOptions?:
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
promptOptions?: {
|
|
157
|
+
slidedown: {
|
|
158
|
+
prompts: {
|
|
159
|
+
/**
|
|
160
|
+
* Whether to automatically display the prompt.
|
|
161
|
+
* `true` will display the prompt based on the delay options.
|
|
162
|
+
* `false` will prevent the prompt from displaying until the Slidedowns methods are used.
|
|
163
|
+
*/
|
|
164
|
+
autoPrompt: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Only available for type: category. Up to 10 categories.
|
|
167
|
+
* @example
|
|
168
|
+
* categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt.
|
|
169
|
+
*/
|
|
170
|
+
categories: {
|
|
171
|
+
/** Should identify the action. */
|
|
172
|
+
tag: string;
|
|
173
|
+
/** What the user will see. */
|
|
174
|
+
label: string;
|
|
175
|
+
}[];
|
|
176
|
+
/**
|
|
177
|
+
* The delay options for the prompt.
|
|
178
|
+
* @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view.
|
|
179
|
+
*/
|
|
180
|
+
delay: {
|
|
181
|
+
/** The number of pages a user needs to visit before the prompt is displayed. */
|
|
182
|
+
pageViews?: number;
|
|
183
|
+
/** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */
|
|
184
|
+
timeDelay?: number;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* The text to display in the prompt.
|
|
188
|
+
*/
|
|
189
|
+
text?: {
|
|
190
|
+
/** The callout asking the user to opt-in. Up to 90 characters. */
|
|
191
|
+
actionMessage?: string;
|
|
192
|
+
/** Triggers the opt-in. Up to 15 characters. */
|
|
193
|
+
acceptButton?: string;
|
|
194
|
+
/** Cancels opt-in. Up to 15 characters. */
|
|
195
|
+
cancelMessage?: string;
|
|
196
|
+
/** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */
|
|
197
|
+
confirmMessage?: string;
|
|
198
|
+
/** Identifies the email text field. Up to 15 characters. */
|
|
199
|
+
emailLabel?: string;
|
|
200
|
+
/** Cancels the category update. Up to 15 characters. */
|
|
201
|
+
negativeUpdateButton?: string;
|
|
202
|
+
/** Saves the updated category tags. Up to 15 characters. */
|
|
203
|
+
positiveUpdateButton?: string;
|
|
204
|
+
/** Identifies the phone number text field. Up to 15 characters. */
|
|
205
|
+
smsLabel?: string;
|
|
206
|
+
/** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */
|
|
207
|
+
updateMessage?: string;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* The type of prompt to display.
|
|
211
|
+
* `push` which is the Slide Prompt without categories.
|
|
212
|
+
* `category` which is the Slide Prompt with categories.
|
|
213
|
+
* `sms` only asks for phone number.
|
|
214
|
+
* `email` only asks for email address.
|
|
215
|
+
* `smsAndEmail` asks for both phone number and email address.
|
|
216
|
+
*/
|
|
217
|
+
type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail';
|
|
218
|
+
}[];
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
welcomeNotification?: {
|
|
222
|
+
/**
|
|
223
|
+
* Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
|
|
224
|
+
*/
|
|
225
|
+
disabled?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* The welcome notification's message. You can localize this to your own language.
|
|
228
|
+
* If left blank or set to blank, the default of 'Thanks for subscribing!' will be used.
|
|
229
|
+
*/
|
|
230
|
+
message: string;
|
|
231
|
+
/**
|
|
232
|
+
* 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.
|
|
233
|
+
* Set to one space ' ' to clear the title, although this is not recommended.
|
|
234
|
+
*/
|
|
235
|
+
title?: string;
|
|
236
|
+
/**
|
|
237
|
+
* By default, clicking the welcome notification does not open any link.
|
|
238
|
+
* This is recommended because the user has just visited your site and subscribed.
|
|
239
|
+
*/
|
|
240
|
+
url: string;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Will enable customization of the notify/subscription bell button.
|
|
244
|
+
*/
|
|
245
|
+
notifyButton?: {
|
|
246
|
+
/**
|
|
247
|
+
* A function you define that returns true to show the Subscription Bell, or false to hide it.
|
|
248
|
+
* Typically used the hide the Subscription Bell after the user is subscribed.
|
|
249
|
+
* This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show.
|
|
250
|
+
*/
|
|
251
|
+
displayPredicate?: () => boolean | Promise<boolean>;
|
|
252
|
+
/**
|
|
253
|
+
* Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default.
|
|
254
|
+
*/
|
|
255
|
+
enable?: boolean;
|
|
256
|
+
/** Specify CSS-valid pixel offsets using bottom, left, and right. */
|
|
257
|
+
offset?: {
|
|
258
|
+
bottom: string;
|
|
259
|
+
left: string;
|
|
260
|
+
right: string;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* If `true`, the Subscription Bell will display an icon that there is 1 unread message.
|
|
264
|
+
* When hovering over the Subscription Bell, the user will see custom text set by message.prenotify.
|
|
265
|
+
*/
|
|
266
|
+
prenotify: boolean;
|
|
267
|
+
/** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */
|
|
268
|
+
position?: 'bottom-left' | 'bottom-right';
|
|
269
|
+
/** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */
|
|
270
|
+
showCredit: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes.
|
|
273
|
+
*/
|
|
274
|
+
size?: 'small' | 'medium' | 'large';
|
|
275
|
+
/** Customize the Subscription Bell text. */
|
|
276
|
+
text: {
|
|
277
|
+
'dialog.blocked.message': string;
|
|
278
|
+
'dialog.blocked.title': string;
|
|
279
|
+
'dialog.main.button.subscribe': string;
|
|
280
|
+
'dialog.main.button.unsubscribe': string;
|
|
281
|
+
'dialog.main.title': string;
|
|
282
|
+
'message.action.resubscribed': string;
|
|
283
|
+
'message.action.subscribed': string;
|
|
284
|
+
'message.action.subscribing': string;
|
|
285
|
+
'message.action.unsubscribed': string;
|
|
286
|
+
'message.prenotify': string;
|
|
287
|
+
'tip.state.blocked': string;
|
|
288
|
+
'tip.state.subscribed': string;
|
|
289
|
+
'tip.state.unsubscribed': string;
|
|
290
|
+
};
|
|
291
|
+
};
|
|
152
292
|
persistNotification?: boolean;
|
|
153
|
-
webhooks?:
|
|
293
|
+
webhooks?: {
|
|
294
|
+
/**
|
|
295
|
+
* Enable this setting only if your server has CORS enabled and supports non-simple CORS requests.
|
|
296
|
+
* If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers.
|
|
297
|
+
* The simplest option is to leave it disabled.
|
|
298
|
+
* @default false
|
|
299
|
+
*/
|
|
300
|
+
cors: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* This event occurs after a notification is clicked.
|
|
303
|
+
* @example https://site.com/hook
|
|
304
|
+
*/
|
|
305
|
+
'notification.clicked'?: string;
|
|
306
|
+
/**
|
|
307
|
+
* 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),
|
|
308
|
+
* 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.
|
|
309
|
+
* @example https://site.com/hook
|
|
310
|
+
*/
|
|
311
|
+
'notification.dismissed'?: string;
|
|
312
|
+
/**
|
|
313
|
+
* This event occurs after a notification is displayed.
|
|
314
|
+
* @example https://site.com/hook
|
|
315
|
+
*/
|
|
316
|
+
'notification.willDisplay'?: string;
|
|
317
|
+
};
|
|
154
318
|
autoResubscribe?: boolean;
|
|
155
319
|
autoRegister?: boolean;
|
|
156
320
|
notificationClickHandlerMatch?: string;
|
|
157
321
|
notificationClickHandlerAction?: string;
|
|
322
|
+
path?: string;
|
|
158
323
|
serviceWorkerParam?: {
|
|
159
324
|
scope: string;
|
|
160
325
|
};
|
|
161
326
|
serviceWorkerPath?: string;
|
|
327
|
+
serviceWorkerOverrideForTypical?: boolean;
|
|
162
328
|
serviceWorkerUpdaterPath?: string;
|
|
163
|
-
path?: string;
|
|
164
329
|
allowLocalhostAsSecureOrigin?: boolean;
|
|
165
330
|
[key: string]: any;
|
|
166
331
|
}
|
|
167
|
-
interface IOneSignalOneSignal {
|
|
332
|
+
export interface IOneSignalOneSignal {
|
|
168
333
|
Slidedown: IOneSignalSlidedown;
|
|
169
334
|
Notifications: IOneSignalNotifications;
|
|
170
335
|
Session: IOneSignalSession;
|
|
@@ -176,7 +341,7 @@ interface IOneSignalOneSignal {
|
|
|
176
341
|
setConsentGiven(consent: boolean): Promise<void>;
|
|
177
342
|
setConsentRequired(requiresConsent: boolean): Promise<void>;
|
|
178
343
|
}
|
|
179
|
-
interface IOneSignalNotifications {
|
|
344
|
+
export interface IOneSignalNotifications {
|
|
180
345
|
permissionNative: NotificationPermission;
|
|
181
346
|
permission: boolean;
|
|
182
347
|
setDefaultUrl(url: string): Promise<void>;
|
|
@@ -186,7 +351,7 @@ interface IOneSignalNotifications {
|
|
|
186
351
|
addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
|
|
187
352
|
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
|
|
188
353
|
}
|
|
189
|
-
interface IOneSignalSlidedown {
|
|
354
|
+
export interface IOneSignalSlidedown {
|
|
190
355
|
promptPush(options?: AutoPromptOptions): Promise<void>;
|
|
191
356
|
promptPushCategories(options?: AutoPromptOptions): Promise<void>;
|
|
192
357
|
promptSms(options?: AutoPromptOptions): Promise<void>;
|
|
@@ -195,14 +360,16 @@ interface IOneSignalSlidedown {
|
|
|
195
360
|
addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
|
|
196
361
|
removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
|
|
197
362
|
}
|
|
198
|
-
interface IOneSignalDebug {
|
|
363
|
+
export interface IOneSignalDebug {
|
|
199
364
|
setLogLevel(logLevel: string): void;
|
|
200
365
|
}
|
|
201
|
-
interface IOneSignalSession {
|
|
366
|
+
export interface IOneSignalSession {
|
|
202
367
|
sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>;
|
|
203
368
|
sendUniqueOutcome(outcomeName: string): Promise<void>;
|
|
204
369
|
}
|
|
205
|
-
interface IOneSignalUser {
|
|
370
|
+
export interface IOneSignalUser {
|
|
371
|
+
onesignalId: string | undefined;
|
|
372
|
+
externalId: string | undefined;
|
|
206
373
|
PushSubscription: IOneSignalPushSubscription;
|
|
207
374
|
addAlias(label: string, id: string): void;
|
|
208
375
|
addAliases(aliases: {
|
|
@@ -220,8 +387,15 @@ interface IOneSignalUser {
|
|
|
220
387
|
}): void;
|
|
221
388
|
removeTag(key: string): void;
|
|
222
389
|
removeTags(keys: string[]): void;
|
|
390
|
+
getTags(): {
|
|
391
|
+
[key: string]: string;
|
|
392
|
+
};
|
|
393
|
+
addEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void;
|
|
394
|
+
removeEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void;
|
|
395
|
+
setLanguage(language: string): void;
|
|
396
|
+
getLanguage(): string;
|
|
223
397
|
}
|
|
224
|
-
interface IOneSignalPushSubscription {
|
|
398
|
+
export interface IOneSignalPushSubscription {
|
|
225
399
|
id: string | null | undefined;
|
|
226
400
|
token: string | null | undefined;
|
|
227
401
|
optedIn: boolean | undefined;
|
package/dist/index.js
CHANGED
|
@@ -87,12 +87,12 @@ function oneSignalLogin(externalId, jwtToken) {
|
|
|
87
87
|
return new Promise(function (resolve, reject) {
|
|
88
88
|
var _a;
|
|
89
89
|
if (isOneSignalScriptFailed) {
|
|
90
|
-
reject();
|
|
90
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
91
|
+
return;
|
|
91
92
|
}
|
|
92
93
|
try {
|
|
93
94
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
94
|
-
OneSignal.login(externalId, jwtToken)
|
|
95
|
-
.then(value => resolve(value))
|
|
95
|
+
OneSignal.login(externalId, jwtToken).then(() => resolve())
|
|
96
96
|
.catch(error => reject(error));
|
|
97
97
|
});
|
|
98
98
|
}
|
|
@@ -105,12 +105,12 @@ function oneSignalLogout() {
|
|
|
105
105
|
return new Promise(function (resolve, reject) {
|
|
106
106
|
var _a;
|
|
107
107
|
if (isOneSignalScriptFailed) {
|
|
108
|
-
reject();
|
|
108
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
109
|
+
return;
|
|
109
110
|
}
|
|
110
111
|
try {
|
|
111
112
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
112
|
-
OneSignal.logout()
|
|
113
|
-
.then(value => resolve(value))
|
|
113
|
+
OneSignal.logout().then(() => resolve())
|
|
114
114
|
.catch(error => reject(error));
|
|
115
115
|
});
|
|
116
116
|
}
|
|
@@ -123,12 +123,12 @@ function oneSignalSetConsentGiven(consent) {
|
|
|
123
123
|
return new Promise(function (resolve, reject) {
|
|
124
124
|
var _a;
|
|
125
125
|
if (isOneSignalScriptFailed) {
|
|
126
|
-
reject();
|
|
126
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
127
|
+
return;
|
|
127
128
|
}
|
|
128
129
|
try {
|
|
129
130
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
130
|
-
OneSignal.setConsentGiven(consent)
|
|
131
|
-
.then(value => resolve(value))
|
|
131
|
+
OneSignal.setConsentGiven(consent).then(() => resolve())
|
|
132
132
|
.catch(error => reject(error));
|
|
133
133
|
});
|
|
134
134
|
}
|
|
@@ -141,12 +141,12 @@ function oneSignalSetConsentRequired(requiresConsent) {
|
|
|
141
141
|
return new Promise(function (resolve, reject) {
|
|
142
142
|
var _a;
|
|
143
143
|
if (isOneSignalScriptFailed) {
|
|
144
|
-
reject();
|
|
144
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
145
|
+
return;
|
|
145
146
|
}
|
|
146
147
|
try {
|
|
147
148
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
148
|
-
OneSignal.setConsentRequired(requiresConsent)
|
|
149
|
-
.then(value => resolve(value))
|
|
149
|
+
OneSignal.setConsentRequired(requiresConsent).then(() => resolve())
|
|
150
150
|
.catch(error => reject(error));
|
|
151
151
|
});
|
|
152
152
|
}
|
|
@@ -159,12 +159,12 @@ function slidedownPromptPush(options) {
|
|
|
159
159
|
return new Promise(function (resolve, reject) {
|
|
160
160
|
var _a;
|
|
161
161
|
if (isOneSignalScriptFailed) {
|
|
162
|
-
reject();
|
|
162
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
163
|
+
return;
|
|
163
164
|
}
|
|
164
165
|
try {
|
|
165
166
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
166
|
-
OneSignal.Slidedown.promptPush(options)
|
|
167
|
-
.then(value => resolve(value))
|
|
167
|
+
OneSignal.Slidedown.promptPush(options).then(() => resolve())
|
|
168
168
|
.catch(error => reject(error));
|
|
169
169
|
});
|
|
170
170
|
}
|
|
@@ -177,12 +177,12 @@ function slidedownPromptPushCategories(options) {
|
|
|
177
177
|
return new Promise(function (resolve, reject) {
|
|
178
178
|
var _a;
|
|
179
179
|
if (isOneSignalScriptFailed) {
|
|
180
|
-
reject();
|
|
180
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
181
|
+
return;
|
|
181
182
|
}
|
|
182
183
|
try {
|
|
183
184
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
184
|
-
OneSignal.Slidedown.promptPushCategories(options)
|
|
185
|
-
.then(value => resolve(value))
|
|
185
|
+
OneSignal.Slidedown.promptPushCategories(options).then(() => resolve())
|
|
186
186
|
.catch(error => reject(error));
|
|
187
187
|
});
|
|
188
188
|
}
|
|
@@ -195,12 +195,12 @@ function slidedownPromptSms(options) {
|
|
|
195
195
|
return new Promise(function (resolve, reject) {
|
|
196
196
|
var _a;
|
|
197
197
|
if (isOneSignalScriptFailed) {
|
|
198
|
-
reject();
|
|
198
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
199
|
+
return;
|
|
199
200
|
}
|
|
200
201
|
try {
|
|
201
202
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
202
|
-
OneSignal.Slidedown.promptSms(options)
|
|
203
|
-
.then(value => resolve(value))
|
|
203
|
+
OneSignal.Slidedown.promptSms(options).then(() => resolve())
|
|
204
204
|
.catch(error => reject(error));
|
|
205
205
|
});
|
|
206
206
|
}
|
|
@@ -213,12 +213,12 @@ function slidedownPromptEmail(options) {
|
|
|
213
213
|
return new Promise(function (resolve, reject) {
|
|
214
214
|
var _a;
|
|
215
215
|
if (isOneSignalScriptFailed) {
|
|
216
|
-
reject();
|
|
216
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
217
|
+
return;
|
|
217
218
|
}
|
|
218
219
|
try {
|
|
219
220
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
220
|
-
OneSignal.Slidedown.promptEmail(options)
|
|
221
|
-
.then(value => resolve(value))
|
|
221
|
+
OneSignal.Slidedown.promptEmail(options).then(() => resolve())
|
|
222
222
|
.catch(error => reject(error));
|
|
223
223
|
});
|
|
224
224
|
}
|
|
@@ -231,12 +231,12 @@ function slidedownPromptSmsAndEmail(options) {
|
|
|
231
231
|
return new Promise(function (resolve, reject) {
|
|
232
232
|
var _a;
|
|
233
233
|
if (isOneSignalScriptFailed) {
|
|
234
|
-
reject();
|
|
234
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
235
|
+
return;
|
|
235
236
|
}
|
|
236
237
|
try {
|
|
237
238
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
238
|
-
OneSignal.Slidedown.promptSmsAndEmail(options)
|
|
239
|
-
.then(value => resolve(value))
|
|
239
|
+
OneSignal.Slidedown.promptSmsAndEmail(options).then(() => resolve())
|
|
240
240
|
.catch(error => reject(error));
|
|
241
241
|
});
|
|
242
242
|
}
|
|
@@ -261,12 +261,12 @@ function notificationsSetDefaultUrl(url) {
|
|
|
261
261
|
return new Promise(function (resolve, reject) {
|
|
262
262
|
var _a;
|
|
263
263
|
if (isOneSignalScriptFailed) {
|
|
264
|
-
reject();
|
|
264
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
265
|
+
return;
|
|
265
266
|
}
|
|
266
267
|
try {
|
|
267
268
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
268
|
-
OneSignal.Notifications.setDefaultUrl(url)
|
|
269
|
-
.then(value => resolve(value))
|
|
269
|
+
OneSignal.Notifications.setDefaultUrl(url).then(() => resolve())
|
|
270
270
|
.catch(error => reject(error));
|
|
271
271
|
});
|
|
272
272
|
}
|
|
@@ -279,12 +279,12 @@ function notificationsSetDefaultTitle(title) {
|
|
|
279
279
|
return new Promise(function (resolve, reject) {
|
|
280
280
|
var _a;
|
|
281
281
|
if (isOneSignalScriptFailed) {
|
|
282
|
-
reject();
|
|
282
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
283
|
+
return;
|
|
283
284
|
}
|
|
284
285
|
try {
|
|
285
286
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
286
|
-
OneSignal.Notifications.setDefaultTitle(title)
|
|
287
|
-
.then(value => resolve(value))
|
|
287
|
+
OneSignal.Notifications.setDefaultTitle(title).then(() => resolve())
|
|
288
288
|
.catch(error => reject(error));
|
|
289
289
|
});
|
|
290
290
|
}
|
|
@@ -297,12 +297,12 @@ function notificationsRequestPermission() {
|
|
|
297
297
|
return new Promise(function (resolve, reject) {
|
|
298
298
|
var _a;
|
|
299
299
|
if (isOneSignalScriptFailed) {
|
|
300
|
-
reject();
|
|
300
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
301
|
+
return;
|
|
301
302
|
}
|
|
302
303
|
try {
|
|
303
304
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
304
|
-
OneSignal.Notifications.requestPermission()
|
|
305
|
-
.then(value => resolve(value))
|
|
305
|
+
OneSignal.Notifications.requestPermission().then(() => resolve())
|
|
306
306
|
.catch(error => reject(error));
|
|
307
307
|
});
|
|
308
308
|
}
|
|
@@ -327,12 +327,12 @@ function sessionSendOutcome(outcomeName, outcomeWeight) {
|
|
|
327
327
|
return new Promise(function (resolve, reject) {
|
|
328
328
|
var _a;
|
|
329
329
|
if (isOneSignalScriptFailed) {
|
|
330
|
-
reject();
|
|
330
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
331
|
+
return;
|
|
331
332
|
}
|
|
332
333
|
try {
|
|
333
334
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
334
|
-
OneSignal.Session.sendOutcome(outcomeName, outcomeWeight)
|
|
335
|
-
.then(value => resolve(value))
|
|
335
|
+
OneSignal.Session.sendOutcome(outcomeName, outcomeWeight).then(() => resolve())
|
|
336
336
|
.catch(error => reject(error));
|
|
337
337
|
});
|
|
338
338
|
}
|
|
@@ -345,12 +345,12 @@ function sessionSendUniqueOutcome(outcomeName) {
|
|
|
345
345
|
return new Promise(function (resolve, reject) {
|
|
346
346
|
var _a;
|
|
347
347
|
if (isOneSignalScriptFailed) {
|
|
348
|
-
reject();
|
|
348
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
349
|
+
return;
|
|
349
350
|
}
|
|
350
351
|
try {
|
|
351
352
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
352
|
-
OneSignal.Session.sendUniqueOutcome(outcomeName)
|
|
353
|
-
.then(value => resolve(value))
|
|
353
|
+
OneSignal.Session.sendUniqueOutcome(outcomeName).then(() => resolve())
|
|
354
354
|
.catch(error => reject(error));
|
|
355
355
|
});
|
|
356
356
|
}
|
|
@@ -431,16 +431,50 @@ function userRemoveTags(keys) {
|
|
|
431
431
|
OneSignal.User.removeTags(keys);
|
|
432
432
|
});
|
|
433
433
|
}
|
|
434
|
+
function userGetTags() {
|
|
435
|
+
var _a;
|
|
436
|
+
let retVal;
|
|
437
|
+
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
438
|
+
retVal = OneSignal.User.getTags();
|
|
439
|
+
});
|
|
440
|
+
return retVal;
|
|
441
|
+
}
|
|
442
|
+
function userAddEventListener(event, listener) {
|
|
443
|
+
var _a;
|
|
444
|
+
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
445
|
+
OneSignal.User.addEventListener(event, listener);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
function userRemoveEventListener(event, listener) {
|
|
449
|
+
var _a;
|
|
450
|
+
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
451
|
+
OneSignal.User.removeEventListener(event, listener);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
function userSetLanguage(language) {
|
|
455
|
+
var _a;
|
|
456
|
+
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
457
|
+
OneSignal.User.setLanguage(language);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
function userGetLanguage() {
|
|
461
|
+
var _a;
|
|
462
|
+
let retVal;
|
|
463
|
+
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
464
|
+
retVal = OneSignal.User.getLanguage();
|
|
465
|
+
});
|
|
466
|
+
return retVal;
|
|
467
|
+
}
|
|
434
468
|
function pushSubscriptionOptIn() {
|
|
435
469
|
return new Promise(function (resolve, reject) {
|
|
436
470
|
var _a;
|
|
437
471
|
if (isOneSignalScriptFailed) {
|
|
438
|
-
reject();
|
|
472
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
473
|
+
return;
|
|
439
474
|
}
|
|
440
475
|
try {
|
|
441
476
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
442
|
-
OneSignal.User.PushSubscription.optIn()
|
|
443
|
-
.then(value => resolve(value))
|
|
477
|
+
OneSignal.User.PushSubscription.optIn().then(() => resolve())
|
|
444
478
|
.catch(error => reject(error));
|
|
445
479
|
});
|
|
446
480
|
}
|
|
@@ -453,12 +487,12 @@ function pushSubscriptionOptOut() {
|
|
|
453
487
|
return new Promise(function (resolve, reject) {
|
|
454
488
|
var _a;
|
|
455
489
|
if (isOneSignalScriptFailed) {
|
|
456
|
-
reject();
|
|
490
|
+
reject(new Error('OneSignal script failed to load.'));
|
|
491
|
+
return;
|
|
457
492
|
}
|
|
458
493
|
try {
|
|
459
494
|
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
|
|
460
|
-
OneSignal.User.PushSubscription.optOut()
|
|
461
|
-
.then(value => resolve(value))
|
|
495
|
+
OneSignal.User.PushSubscription.optOut().then(() => resolve())
|
|
462
496
|
.catch(error => reject(error));
|
|
463
497
|
});
|
|
464
498
|
}
|
|
@@ -495,6 +529,8 @@ const PushSubscriptionNamespace = {
|
|
|
495
529
|
removeEventListener: pushSubscriptionRemoveEventListener,
|
|
496
530
|
};
|
|
497
531
|
const UserNamespace = {
|
|
532
|
+
get onesignalId() { var _a, _b; return (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.onesignalId; },
|
|
533
|
+
get externalId() { var _a, _b; return (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.externalId; },
|
|
498
534
|
addAlias: userAddAlias,
|
|
499
535
|
addAliases: userAddAliases,
|
|
500
536
|
removeAlias: userRemoveAlias,
|
|
@@ -507,6 +543,11 @@ const UserNamespace = {
|
|
|
507
543
|
addTags: userAddTags,
|
|
508
544
|
removeTag: userRemoveTag,
|
|
509
545
|
removeTags: userRemoveTags,
|
|
546
|
+
getTags: userGetTags,
|
|
547
|
+
addEventListener: userAddEventListener,
|
|
548
|
+
removeEventListener: userRemoveEventListener,
|
|
549
|
+
setLanguage: userSetLanguage,
|
|
550
|
+
getLanguage: userGetLanguage,
|
|
510
551
|
PushSubscription: PushSubscriptionNamespace,
|
|
511
552
|
};
|
|
512
553
|
const SessionNamespace = {
|