Skip to content

Commit 16a245f

Browse files
committed
Types Definitions
1 parent 92731a2 commit 16a245f

File tree

1 file changed

+396
-0
lines changed

1 file changed

+396
-0
lines changed

src/index.d.ts

Lines changed: 396 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,396 @@
1+
declare module 'react-native-onesignal' {
2+
/* O P T I O N T Y P E V A L U E S */
3+
// 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose
4+
export type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6;
5+
6+
// 0 = NotDetermined, 1 = Authorized, 2 = Denied, 3 = Provisional, 4 = Ephemeral
7+
export type IosPermissionStatus = 0 | 1 | 2 | 3 | 4;
8+
9+
// 0 = NotificationClicked, 1 = ButtonClicked
10+
export type OpenedEventActionType = 0 | 1;
11+
12+
/* O B S E R V E R C H A N G E E V E N T S */
13+
export interface ChangeEvent<T> {
14+
from : T;
15+
to : T;
16+
}
17+
18+
export interface PermissionChange {
19+
status ?: IosPermissionStatus; // ios
20+
hasPrompted ?: boolean; // ios
21+
provisional ?: boolean; // ios
22+
areNotificationsEnabled ?: boolean; // android
23+
};
24+
25+
export interface SubscriptionChange {
26+
userId ?: string;
27+
pushToken ?: string;
28+
isSubscribed : boolean;
29+
isPushDisabled : boolean;
30+
};
31+
32+
export interface EmailSubscriptionChange {
33+
emailAddress ?: string;
34+
emailUserId ?: string;
35+
isEmailSubscribed : boolean;
36+
};
37+
38+
/* N O T I F I C A T I O N S */
39+
export interface OSNotification {
40+
body : string;
41+
sound ?: string;
42+
title ?: string;
43+
launchURL ?: string;
44+
rawPayload : object | string; // platform bridges return different types
45+
actionButtons ?: object[];
46+
additionalData : object;
47+
notificationId : string;
48+
// android only
49+
groupKey ?: string;
50+
groupMessage ?: string;
51+
ledColor ?: string;
52+
priority ?: number;
53+
smallIcon ?: string;
54+
largeIcon ?: string;
55+
bigPicture ?: string;
56+
collapseId ?: string;
57+
fromProjectNumber ?: string;
58+
smallIconAccentColor ?: string;
59+
lockScreenVisibility ?: string;
60+
androidNotificationId ?: number;
61+
// ios only
62+
badge ?: string;
63+
badgeIncrement ?: string;
64+
category ?: string;
65+
threadId ?: string;
66+
subtitle ?: string;
67+
templateId ?: string;
68+
templateName ?: string;
69+
attachments ?: object;
70+
mutableContent ?: boolean;
71+
contentAvailable ?: string;
72+
}
73+
74+
/* N O T I F I C A T I O N & I A M E V E N T S */
75+
export interface NotificationReceivedEvent {
76+
complete : (notification: OSNotification) => void;
77+
getNotification : () => OSNotification;
78+
};
79+
80+
export interface OpenedEvent {
81+
action : OpenedEventAction;
82+
notification : OSNotification;
83+
}
84+
85+
export interface OpenedEventAction {
86+
type : OpenedEventActionType
87+
}
88+
89+
export interface InAppMessageAction {
90+
closes_message : boolean;
91+
first_click : boolean;
92+
click_name ?: string;
93+
click_url ?: string;
94+
outcomes ?: object[];
95+
tags ?: object;
96+
}
97+
98+
export interface OutcomeEvent {
99+
session : string;
100+
id : string;
101+
timestamp : number;
102+
weight : number;
103+
notification_ids: string[];
104+
}
105+
106+
/* D E V I C E */
107+
export interface DeviceState {
108+
userId : string;
109+
pushToken : string;
110+
emailUserId : string;
111+
emailAddress : string;
112+
isSubscribed : boolean;
113+
isPushDisabled : boolean;
114+
isEmailSubscribed : boolean;
115+
hasNotificationPermission ?: boolean; // ios only
116+
notificationPermissionStatus ?: number; // ios only
117+
// areNotificationsEnabled (android) not included since it is converted to hasNotificationPermission in bridge
118+
}
119+
120+
/* O N E S I G N A L I N T E R F A C E */
121+
export interface OneSignal {
122+
/**
123+
* Completes OneSignal initialization by setting the OneSignal Application ID.
124+
* @param {string} appId
125+
* @returns void
126+
*/
127+
setAppId(appId: string): void;
128+
129+
/**
130+
* Add a callback that fires when the native push permission changes.
131+
* @param {(event:ChangeEvent<PermissionChange>)=>void} observer
132+
* @returns void
133+
*/
134+
addPermissionObserver(observer: (event: ChangeEvent<PermissionChange>) => void): void;
135+
136+
/**
137+
* Add a callback that fires when the OneSignal subscription state changes.
138+
* @param {(event:ChangeEvent<SubscriptionChange>)=>void} observer
139+
* @returns void
140+
*/
141+
addSubscriptionObserver(observer: (event: ChangeEvent<SubscriptionChange>) => void): void;
142+
143+
/**
144+
* Add a callback that fires when the OneSignal email subscription changes.
145+
* @param {(event:ChangeEvent<EmailSubscriptionChange>)=>void} observer
146+
* @returns void
147+
*/
148+
addEmailSubscriptionObserver(observer: (event: ChangeEvent<EmailSubscriptionChange>) => void): void;
149+
150+
/**
151+
* Set the callback to run just before displaying a notification while the app is in focus.
152+
* @param {(event:NotificationReceivedEvent)=>void} handler
153+
* @returns void
154+
*/
155+
setNotificationWillShowInForegroundHandler(handler: (event: NotificationReceivedEvent) => void): void;
156+
157+
/**
158+
* Set the callback to run on notification open.
159+
* @param {(openedEvent:OpenedEvent)=>void} handler
160+
* @returns void
161+
*/
162+
setNotificationOpenedHandler(handler: (openedEvent: OpenedEvent) => void): void;
163+
164+
/**
165+
* Prompts the iOS user for push notifications.
166+
* @param {(response:boolean)=>void} handler
167+
* @returns void
168+
*/
169+
promptForPushNotificationsWithUserResponse(handler?: (response: boolean) => void): void;
170+
171+
/**
172+
* Disable the push notification subscription to OneSignal.
173+
* @param {boolean} disable
174+
* @returns void
175+
*/
176+
disablePush(disable: boolean): void;
177+
178+
/**
179+
* Disable or enable location collection (defaults to enabled if your app has location permission).
180+
* @param {boolean} shared
181+
* @returns void
182+
*/
183+
setLocationShared(shared: boolean): void;
184+
185+
/**
186+
* Prompts the user for location permissions to allow geotagging from the OneSignal dashboard.
187+
* @returns void
188+
*/
189+
promptLocation(): void;
190+
191+
/**
192+
* This method returns a "snapshot" of the device state for when it was called.
193+
* @returns Promise<DeviceState>
194+
*/
195+
getDeviceState(): Promise<DeviceState>;
196+
197+
/**
198+
* Did the user provide privacy consent for GDPR purposes.
199+
* @returns Promise<boolean>
200+
*/
201+
userProvidedPrivacyConsent(): Promise<boolean>;
202+
203+
/**
204+
* Tag a user based on an app event of your choosing so they can be targeted later via segments.
205+
* @param {string} key
206+
* @param {string} value
207+
* @returns void
208+
*/
209+
sendTag(key: string, value: string): void;
210+
211+
/**
212+
* Tag a user wiht multiple tags based on an app event of your choosing so they can be targeted later via segments.
213+
* @param {object} tags
214+
* @returns void
215+
*/
216+
sendTags(tags: object): void;
217+
218+
/**
219+
* Retrieve a list of tags that have been set on the user from the OneSignal server.
220+
* @param {(tags:object)=>void} handler
221+
* @returns void
222+
*/
223+
getTags(handler: (tags: object) => void): void;
224+
225+
/**
226+
* Deletes a single tag that was previously set on a user.
227+
* @param {string} key
228+
* @returns void
229+
*/
230+
deleteTag(key: string): void;
231+
232+
/**
233+
* Deletes multiple tags that were previously set on a user.
234+
* @param {string[]} keys
235+
*/
236+
deleteTags(keys: string[]);
237+
238+
/**
239+
* Allows you to set the user's email address with the OneSignal SDK.
240+
* @param {string} email
241+
* @param {string} authCode
242+
* @param {Function} handler
243+
* @returns void
244+
*/
245+
setEmail(email: string, authCode?: string, handler?: Function): void;
246+
247+
/**
248+
* If your app implements logout functionality, you can call logoutEmail to dissociate the email from the device.
249+
* @param {Function} handler
250+
*/
251+
logoutEmail(handler?: Function);
252+
253+
/**
254+
* Send a notification
255+
* @param {string} notificationObjectString - JSON string payload (see REST API reference)
256+
* @param {(success:object)=>void} onSuccess
257+
* @param {(failure:object)=>void} onFailure
258+
* @returns void
259+
*/
260+
postNotification(notificationObjectString: string, onSuccess: (success: object) => void, onFailure: (failure: object) => void): void;
261+
262+
/**
263+
* Android Only. iOS provides a standard way to clear notifications by clearing badge count.
264+
* @returns void
265+
*/
266+
clearOneSignalNotifications(): void;
267+
268+
/**
269+
* Cancels a single OneSignal notification based on its Android notification integer id.
270+
* @param {number} id - notification id to cancel
271+
* @returns void
272+
*/
273+
cancelNotification(id: number): void;
274+
275+
/**
276+
* Allows you to use your own system's user ID's to send push notifications to your users.
277+
* @param {string} externalId
278+
* @param {(results:object)=>void} handler
279+
* @returns void
280+
*/
281+
setExternalUserId(externalId: string, handler?: (results: object) => void): void;
282+
283+
/**
284+
* Removes whatever was set as the current user's external user ID.
285+
* @param {(results:object)=>void} handler
286+
* @returns void
287+
*/
288+
removeExternalUserId(handler?: (results: object) => void): void;
289+
290+
/**
291+
* Sets an In-App Message click event handler.
292+
* @param {(action:InAppMessageAction)=>void} handler
293+
* @returns void
294+
*/
295+
setInAppMessageClickHandler(handler: (action: InAppMessageAction) => void): void;
296+
297+
/**
298+
* Add an In-App Message Trigger.
299+
* @param {string} key
300+
* @param {string} value
301+
* @returns void
302+
*/
303+
addTrigger(key: string, value: string): void;
304+
305+
/**
306+
* Adds Multiple In-App Message Triggers.
307+
* @param {object} triggers
308+
* @returns void
309+
*/
310+
addTriggers(triggers: object): void;
311+
312+
/**
313+
* Removes a list of triggers based on a collection of keys.
314+
* @param {string[]} keys
315+
* @returns void
316+
*/
317+
removeTriggersForKeys(keys: string[]): void;
318+
319+
/**
320+
* Removes a list of triggers based on a key.
321+
* @param {string} key
322+
* @returns void
323+
*/
324+
removeTriggerForKey(key: string): void;
325+
326+
/**
327+
* Gets a trigger value for a provided trigger key.
328+
* @param {string} key
329+
* @returns void
330+
*/
331+
getTriggerValueForKey(key: string): Promise<string>;
332+
333+
/**
334+
* Pause & unpause In-App Messages
335+
* @param {boolean} pause
336+
* @returns void
337+
*/
338+
pauseInAppMessages(pause: boolean): void;
339+
340+
/**
341+
* Increases the "Count" of this Outcome by 1 and will be counted each time sent.
342+
* @param {string} name
343+
* @param {(event:OutcomeEvent)=>void} handler
344+
* @returns void
345+
*/
346+
sendOutcome(name: string, handler?: (event: OutcomeEvent) => void): void;
347+
348+
/**
349+
* Increases "Count" by 1 only once. This can only be attributed to a single notification.
350+
* @param {string} name
351+
* @param {(event:OutcomeEvent)=>void} handler
352+
* @returns void
353+
*/
354+
sendUniqueOutcome(name: string, handler?: (event: OutcomeEvent) => void): void;
355+
356+
/**
357+
* Increases the "Count" of this Outcome by 1 and the "Sum" by the value. Will be counted each time sent.
358+
* If the method is called outside of an attribution window, it will be unattributed until a new session occurs.
359+
* @param {string} name
360+
* @param {string|number} value
361+
* @param {(event:OutcomeEvent)=>void} handler
362+
* @returns void
363+
*/
364+
sendOutcomeWithValue(name: string, value: string|number, handler?: (event: OutcomeEvent) => void): void;
365+
366+
/**
367+
* Enable logging to help debug if you run into an issue setting up OneSignal.
368+
* @param {LogLevel} nsLogLevel - Sets the logging level to print to the Android LogCat log or Xcode log.
369+
* @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs.
370+
* @returns void
371+
*/
372+
setLogLevel(nsLogLevel: LogLevel, visualLogLevel: LogLevel): void;
373+
374+
/**
375+
* Clears all handlers and observers.
376+
* @returns void
377+
*/
378+
clearHandlers(): void;
379+
380+
/**
381+
* For GDPR users, your application should call this method before setting the App ID.
382+
* @param {boolean} required
383+
* @returns void
384+
*/
385+
setRequiresUserPrivacyConsent(required: boolean): void;
386+
387+
/**
388+
* If your application is set to require the user's privacy consent, you can provide this consent using this method.
389+
* @param {boolean} granted
390+
* @returns void
391+
*/
392+
provideUserConsent(granted: boolean): void;
393+
}
394+
const OneSignal: OneSignal;
395+
export default OneSignal;
396+
}

0 commit comments

Comments
 (0)