Skip to content

Commit fb3fac1

Browse files
author
OneSignal
committed
feat: sync with web-shim-codegen v3.0.1
1 parent 3a4e8e6 commit fb3fac1

File tree

4 files changed

+254
-32
lines changed

4 files changed

+254
-32
lines changed

.eslintrc.cjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es6: true,
6+
node: true,
7+
worker: true,
8+
},
9+
settings: {
10+
"import/resolver": {
11+
node: {
12+
paths: ["src"],
13+
extensions: [".js", ".ts"],
14+
},
15+
},
16+
},
17+
globals: {
18+
Atomics: "readonly",
19+
SharedArrayBuffer: "readonly",
20+
},
21+
parser: "@typescript-eslint/parser",
22+
parserOptions: {
23+
ecmaVersion: 2018,
24+
sourceType: "module",
25+
},
26+
plugins: ["@typescript-eslint"],
27+
extends: ["plugin:@typescript-eslint/recommended"],
28+
rules: {
29+
"prefer-destructuring": 0,
30+
"no-param-reassign": 0,
31+
"import/extensions": 0,
32+
"dot-notation": 0,
33+
"no-continue": 0,
34+
"no-unused-vars": "off",
35+
"@typescript-eslint/no-unused-vars": ["error"],
36+
"no-prototype-builtins": "warn",
37+
},
38+
};

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ dist
1616
.env.test.local
1717
.env.production.local
1818

19-
npm-debug.log*
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*

index.ts

Lines changed: 212 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ const isPushSupported = (): boolean => {
120120
return isPushNotificationsSupported();
121121
}
122122

123-
interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
124-
interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
125-
interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
126-
interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
127-
type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
128-
type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
129-
type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
130-
type SlidedownEventName = 'slidedownShown';
131-
type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
132-
interface IOSNotification {
123+
export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
124+
export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
125+
export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
126+
export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
127+
export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
128+
export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
129+
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
130+
export type SlidedownEventName = 'slidedownShown';
131+
export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
132+
export interface IOSNotification {
133133
/**
134134
* The OneSignal notification id;
135135
* - Primary id on OneSignal's REST API and dashboard
@@ -191,7 +191,7 @@ interface IOSNotification {
191191
readonly confirmDelivery: boolean;
192192
}
193193

194-
interface IOSNotificationActionButton {
194+
export interface IOSNotificationActionButton {
195195
/**
196196
* Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
197197
* and host page through events to identify which button was clicked.
@@ -212,50 +212,232 @@ interface IOSNotificationActionButton {
212212
readonly launchURL?: string;
213213
}
214214

215-
interface NotificationClickResult {
215+
export interface NotificationClickResult {
216216
readonly actionId?: string;
217217
readonly url?: string;
218218
}
219219

220-
type NotificationEventTypeMap = {
220+
export type NotificationEventTypeMap = {
221221
'click': NotificationClickEvent;
222222
'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
223223
'dismiss': NotificationDismissEvent;
224224
'permissionChange': boolean;
225225
'permissionPromptDisplay': void;
226226
};
227227

228-
interface NotificationForegroundWillDisplayEvent {
228+
export interface NotificationForegroundWillDisplayEvent {
229229
readonly notification: IOSNotification;
230230
preventDefault(): void;
231231
}
232232

233-
interface NotificationDismissEvent {
233+
export interface NotificationDismissEvent {
234234
notification: IOSNotification;
235235
}
236236

237-
interface NotificationClickEvent {
237+
export interface NotificationClickEvent {
238238
readonly notification: IOSNotification;
239239
readonly result: NotificationClickResult;
240240
}
241241

242-
type UserChangeEvent = {
242+
export type UserChangeEvent = {
243243
current: UserNamespaceProperties;
244244
};
245-
type UserNamespaceProperties = {
245+
export type UserNamespaceProperties = {
246246
onesignalId: string | undefined;
247247
externalId: string | undefined;
248248
};
249249

250-
interface IInitObject {
250+
export interface IInitObject {
251251
appId: string;
252252
subdomainName?: string;
253253
requiresUserPrivacyConsent?: boolean;
254-
promptOptions?: object;
255-
welcomeNotification?: object;
256-
notifyButton?: object;
254+
promptOptions?: {
255+
slidedown: {
256+
prompts: {
257+
/**
258+
* Whether to automatically display the prompt.
259+
* `true` will display the prompt based on the delay options.
260+
* `false` will prevent the prompt from displaying until the Slidedowns methods are used.
261+
*/
262+
autoPrompt: boolean;
263+
264+
/**
265+
* Only available for type: category. Up to 10 categories.
266+
* @example
267+
* categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt.
268+
*/
269+
categories: {
270+
/** Should identify the action. */
271+
tag: string;
272+
273+
/** What the user will see. */
274+
label: string;
275+
}[];
276+
277+
/**
278+
* The delay options for the prompt.
279+
* @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view.
280+
*/
281+
delay: {
282+
/** The number of pages a user needs to visit before the prompt is displayed. */
283+
pageViews?: number;
284+
285+
/** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */
286+
timeDelay?: number;
287+
};
288+
289+
/**
290+
* The text to display in the prompt.
291+
*/
292+
text?: {
293+
/** The callout asking the user to opt-in. Up to 90 characters. */
294+
actionMessage?: string;
295+
296+
/** Triggers the opt-in. Up to 15 characters. */
297+
acceptButton?: string;
298+
299+
/** Cancels opt-in. Up to 15 characters. */
300+
cancelMessage?: string;
301+
302+
/** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */
303+
confirmMessage?: string;
304+
305+
/** Identifies the email text field. Up to 15 characters. */
306+
emailLabel?: string;
307+
308+
/** Cancels the category update. Up to 15 characters. */
309+
negativeUpdateButton?: string;
310+
311+
/** Saves the updated category tags. Up to 15 characters. */
312+
positiveUpdateButton?: string;
313+
314+
/** Identifies the phone number text field. Up to 15 characters. */
315+
smsLabel?: string;
316+
317+
/** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */
318+
updateMessage?: string;
319+
};
320+
321+
/**
322+
* The type of prompt to display.
323+
* `push` which is the Slide Prompt without categories.
324+
* `category` which is the Slide Prompt with categories.
325+
* `sms` only asks for phone number.
326+
* `email` only asks for email address.
327+
* `smsAndEmail` asks for both phone number and email address.
328+
*/
329+
type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail';
330+
}[];
331+
};
332+
};
333+
welcomeNotification?: {
334+
/**
335+
* Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
336+
*/
337+
disabled?: boolean;
338+
339+
/**
340+
* The welcome notification's message. You can localize this to your own language.
341+
* If left blank or set to blank, the default of 'Thanks for subscribing!' will be used.
342+
*/
343+
message: string;
344+
345+
/**
346+
* The welcome notification's title. You can localize this to your own language. If not set, or left blank, the site's title will be used.
347+
* Set to one space ' ' to clear the title, although this is not recommended.
348+
*/
349+
title?: string;
350+
351+
/**
352+
* By default, clicking the welcome notification does not open any link.
353+
* This is recommended because the user has just visited your site and subscribed.
354+
*/
355+
url: string;
356+
};
357+
358+
/**
359+
* Will enable customization of the notify/subscription bell button.
360+
*/
361+
notifyButton?: {
362+
/**
363+
* A function you define that returns true to show the Subscription Bell, or false to hide it.
364+
* Typically used the hide the Subscription Bell after the user is subscribed.
365+
* This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show.
366+
*/
367+
displayPredicate?: () => boolean | Promise<boolean>;
368+
369+
/**
370+
* Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default.
371+
*/
372+
enable?: boolean;
373+
374+
/** Specify CSS-valid pixel offsets using bottom, left, and right. */
375+
offset?: { bottom: string; left: string; right: string };
376+
377+
/**
378+
* If `true`, the Subscription Bell will display an icon that there is 1 unread message.
379+
* When hovering over the Subscription Bell, the user will see custom text set by message.prenotify.
380+
*/
381+
prenotify: boolean;
382+
383+
/** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */
384+
position?: 'bottom-left' | 'bottom-right';
385+
386+
/** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */
387+
showCredit: boolean;
388+
389+
/**
390+
* The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes.
391+
*/
392+
size?: 'small' | 'medium' | 'large';
393+
394+
/** Customize the Subscription Bell text. */
395+
text: {
396+
'dialog.blocked.message': string;
397+
'dialog.blocked.title': string;
398+
'dialog.main.button.subscribe': string;
399+
'dialog.main.button.unsubscribe': string;
400+
'dialog.main.title': string;
401+
'message.action.resubscribed': string;
402+
'message.action.subscribed': string;
403+
'message.action.subscribing': string;
404+
'message.action.unsubscribed': string;
405+
'message.prenotify': string;
406+
'tip.state.blocked': string;
407+
'tip.state.subscribed': string;
408+
'tip.state.unsubscribed': string;
409+
};
410+
};
411+
257412
persistNotification?: boolean;
258-
webhooks?: object;
413+
webhooks?: {
414+
/**
415+
* Enable this setting only if your server has CORS enabled and supports non-simple CORS requests.
416+
* If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers.
417+
* The simplest option is to leave it disabled.
418+
* @default false
419+
*/
420+
cors: boolean;
421+
422+
/**
423+
* This event occurs after a notification is clicked.
424+
* @example https://site.com/hook
425+
*/
426+
'notification.clicked'?: string;
427+
428+
/**
429+
* This event occurs after a notification is intentionally dismissed by the user (clicking the notification body or one of the notification action buttons does not trigger the dismissed webhook),
430+
* after a group of notifications are all dismissed (with this notification as part of that group), or after a notification expires on its own time and disappears. This event is supported on Chrome only.
431+
* @example https://site.com/hook
432+
*/
433+
'notification.dismissed'?: string;
434+
435+
/**
436+
* This event occurs after a notification is displayed.
437+
* @example https://site.com/hook
438+
*/
439+
'notification.willDisplay'?: string;
440+
};
259441
autoResubscribe?: boolean;
260442
autoRegister?: boolean;
261443
notificationClickHandlerMatch?: string;
@@ -269,7 +451,7 @@ interface IInitObject {
269451
[key: string]: any;
270452
}
271453

272-
interface IOneSignalOneSignal {
454+
export interface IOneSignalOneSignal {
273455
Slidedown: IOneSignalSlidedown;
274456
Notifications: IOneSignalNotifications;
275457
Session: IOneSignalSession;
@@ -281,7 +463,7 @@ interface IOneSignalOneSignal {
281463
setConsentGiven(consent: boolean): Promise<void>;
282464
setConsentRequired(requiresConsent: boolean): Promise<void>;
283465
}
284-
interface IOneSignalNotifications {
466+
export interface IOneSignalNotifications {
285467
permissionNative: NotificationPermission;
286468
permission: boolean;
287469
setDefaultUrl(url: string): Promise<void>;
@@ -291,7 +473,7 @@ interface IOneSignalNotifications {
291473
addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
292474
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
293475
}
294-
interface IOneSignalSlidedown {
476+
export interface IOneSignalSlidedown {
295477
promptPush(options?: AutoPromptOptions): Promise<void>;
296478
promptPushCategories(options?: AutoPromptOptions): Promise<void>;
297479
promptSms(options?: AutoPromptOptions): Promise<void>;
@@ -300,14 +482,14 @@ interface IOneSignalSlidedown {
300482
addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
301483
removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
302484
}
303-
interface IOneSignalDebug {
485+
export interface IOneSignalDebug {
304486
setLogLevel(logLevel: string): void;
305487
}
306-
interface IOneSignalSession {
488+
export interface IOneSignalSession {
307489
sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>;
308490
sendUniqueOutcome(outcomeName: string): Promise<void>;
309491
}
310-
interface IOneSignalUser {
492+
export interface IOneSignalUser {
311493
onesignalId: string | undefined;
312494
externalId: string | undefined;
313495
PushSubscription: IOneSignalPushSubscription;
@@ -329,7 +511,7 @@ interface IOneSignalUser {
329511
setLanguage(language: string): void;
330512
getLanguage(): string;
331513
}
332-
interface IOneSignalPushSubscription {
514+
export interface IOneSignalPushSubscription {
333515
id: string | null | undefined;
334516
token: string | null | undefined;
335517
optedIn: boolean | undefined;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@onesignal/onesignal-vue3",
33
"version": "2.1.0",
44
"description": "Vue 3 OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!",
5-
"author": "rgomezp",
5+
"type": "module",
66
"contributors": [
77
{
88
"name": "Rodrigo Gomez-Palacio"

0 commit comments

Comments
 (0)