//#region src/constants/subscription.d.ts declare enum OSNotificationPermission { NotDetermined = 0, Denied = 1, Authorized = 2, Provisional = 3, // only available in iOS 12 Ephemeral = 4 } //#endregion //#region src/OSNotification.d.ts interface BaseNotificationData { body: string; sound?: string; title?: string; launchURL?: string; rawPayload: object | string; actionButtons?: object[]; additionalData?: object; notificationId: string; } interface AndroidNotificationData extends BaseNotificationData { groupKey?: string; groupMessage?: string; ledColor?: string; priority?: number; smallIcon?: string; largeIcon?: string; bigPicture?: string; collapseId?: string; fromProjectNumber?: string; smallIconAccentColor?: string; lockScreenVisibility?: string; androidNotificationId?: number; } interface iOSNotificationData extends BaseNotificationData { badge?: string; badgeIncrement?: string; category?: string; threadId?: string; subtitle?: string; templateId?: string; templateName?: string; attachments?: object; mutableContent?: boolean; contentAvailable?: string; relevanceScore?: number; interruptionLevel?: string; } type OSNotificationData = AndroidNotificationData | iOSNotificationData; declare class OSNotification { body: string; sound?: string; title?: string; launchURL?: string; rawPayload: object | string; actionButtons?: object[]; additionalData?: object; notificationId: string; groupKey?: string; groupMessage?: string; ledColor?: string; priority?: number; smallIcon?: string; largeIcon?: string; bigPicture?: string; collapseId?: string; fromProjectNumber?: string; smallIconAccentColor?: string; lockScreenVisibility?: string; androidNotificationId?: number; badge?: string; badgeIncrement?: string; category?: string; threadId?: string; subtitle?: string; templateId?: string; templateName?: string; attachments?: object; mutableContent?: boolean; contentAvailable?: string; relevanceScore?: number; interruptionLevel?: string; constructor(receivedEvent: OSNotificationData); display(): void; } //#endregion //#region src/events/NotificationWillDisplayEvent.d.ts declare class NotificationWillDisplayEvent { notification: OSNotification; constructor(displayEvent: OSNotification); preventDefault(): void; getNotification(): OSNotification; } //#endregion //#region src/constants/events.d.ts declare const NOTIFICATION_WILL_DISPLAY = "OneSignal-notificationWillDisplayInForeground"; declare const NOTIFICATION_CLICKED = "OneSignal-notificationClicked"; declare const IN_APP_MESSAGE_CLICKED = "OneSignal-inAppMessageClicked"; declare const IN_APP_MESSAGE_WILL_DISPLAY = "OneSignal-inAppMessageWillDisplay"; declare const IN_APP_MESSAGE_DID_DISPLAY = "OneSignal-inAppMessageDidDisplay"; declare const IN_APP_MESSAGE_WILL_DISMISS = "OneSignal-inAppMessageWillDismiss"; declare const IN_APP_MESSAGE_DID_DISMISS = "OneSignal-inAppMessageDidDismiss"; declare const PERMISSION_CHANGED = "OneSignal-permissionChanged"; declare const SUBSCRIPTION_CHANGED = "OneSignal-subscriptionChanged"; declare const USER_STATE_CHANGED = "OneSignal-userStateChanged"; //#endregion //#region src/types/notificationEvents.d.ts type NotificationListeners = ['click', EventListenerMap['OneSignal-notificationClicked']] | ['foregroundWillDisplay', EventListenerMap['OneSignal-notificationWillDisplayInForeground']] | ['permissionChange', EventListenerMap['OneSignal-permissionChanged']]; interface NotificationClickEvent { result: NotificationClickResult; notification: OSNotification; } interface NotificationClickResult { actionId?: string; url?: string; } //#endregion //#region src/types/subscription.d.ts interface PushSubscriptionState { id?: string; token?: string; optedIn: boolean; } interface PushSubscriptionChangedState { previous: PushSubscriptionState; current: PushSubscriptionState; } //#endregion //#region src/types/user.d.ts interface UserState { externalId?: string; onesignalId?: string; } interface UserChangedState { current: UserState; } //#endregion //#region src/events/EventManager.d.ts interface EventListenerMap { [PERMISSION_CHANGED]: (event: boolean) => void; [SUBSCRIPTION_CHANGED]: (event: PushSubscriptionChangedState) => void; [USER_STATE_CHANGED]: (event: UserChangedState) => void; [NOTIFICATION_WILL_DISPLAY]: (event: NotificationWillDisplayEvent) => void; [NOTIFICATION_CLICKED]: (event: NotificationClickEvent) => void; [IN_APP_MESSAGE_CLICKED]: (event: InAppMessageClickEvent) => void; [IN_APP_MESSAGE_WILL_DISPLAY]: (event: InAppMessageWillDisplayEvent) => void; [IN_APP_MESSAGE_WILL_DISMISS]: (event: InAppMessageWillDismissEvent) => void; [IN_APP_MESSAGE_DID_DISMISS]: (event: InAppMessageDidDismissEvent) => void; [IN_APP_MESSAGE_DID_DISPLAY]: (event: InAppMessageDidDisplayEvent) => void; } //#endregion //#region src/types/inAppMessage.d.ts type InAppMessageListeners = ['click', EventListenerMap['OneSignal-inAppMessageClicked']] | ['willDisplay', EventListenerMap['OneSignal-inAppMessageWillDisplay']] | ['didDisplay', EventListenerMap['OneSignal-inAppMessageDidDisplay']] | ['willDismiss', EventListenerMap['OneSignal-inAppMessageWillDismiss']] | ['didDismiss', EventListenerMap['OneSignal-inAppMessageDidDismiss']]; interface InAppMessage { messageId: string; } interface InAppMessageClickEvent { message: InAppMessage; result: InAppMessageClickResult; } interface InAppMessageClickResult { closingMessage: boolean; actionId?: string; url?: string; urlTarget?: string; } interface InAppMessageWillDisplayEvent { message: InAppMessage; } interface InAppMessageDidDisplayEvent { message: InAppMessage; } interface InAppMessageWillDismissEvent { message: InAppMessage; } interface InAppMessageDidDismissEvent { message: InAppMessage; } //#endregion //#region src/types/liveActivities.d.ts /** * The setup options for `OneSignal.LiveActivities.setupDefault`. */ type LiveActivitySetupOptions = { /** * When true, OneSignal will listen for pushToStart tokens for the `OneSignalLiveActivityAttributes` structure. */ enablePushToStart: boolean; /** * When true, OneSignal will listen for pushToUpdate tokens for each start live activity that uses the * `OneSignalLiveActivityAttributes` structure. */ enablePushToUpdate: boolean; }; //#endregion //#region src/index.d.ts declare enum LogLevel { None = 0, Fatal = 1, Error = 2, Warn = 3, Info = 4, Debug = 5, Verbose = 6 } declare namespace OneSignal { /** Initializes the OneSignal SDK. This should be called during startup of the application. */ function initialize(appId: string): void; /** * If your integration is user-centric, or you want the ability to identify the user beyond the current device, the * login method should be called to identify the user. */ function login(externalId: string): void; /** * Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the logout method should be * called. */ function logout(): void; /** For GDPR users, your application should call this method before setting the App ID. */ function setConsentRequired(required: boolean): void; /** * If your application is set to require the user's privacy consent, you can provide this consent using this method. * Indicates whether privacy consent has been granted. This field is only relevant when the application has opted * into data privacy protections. */ function setConsentGiven(granted: boolean): void; namespace Debug { /** * Enable logging to help debug if you run into an issue setting up OneSignal. * @param {LogLevel} nsLogLevel - Sets the logging level to print to the Android LogCat log or Xcode log. */ function setLogLevel(nsLogLevel: LogLevel): void; /** * Enable logging to help debug if you run into an issue setting up OneSignal. * @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs. */ function setAlertLevel(visualLogLevel: LogLevel): void; } namespace LiveActivities { /** * Indicate this device has entered a live activity, identified within OneSignal by the `activityId`. * * Only applies to iOS * * @param activityId: The activity identifier the live activity on this device will receive updates for. * @param token: The activity's update token to receive the updates. **/ function enter(activityId: string, token: string, handler?: (result: object) => void): void; /** * Indicate this device has exited a live activity, identified within OneSignal by the `activityId`. * * Only applies to iOS * * @deprecated Currently unsupported, avoid using this method. * @param activityId: The activity identifier the live activity on this device will no longer receive updates for. **/ function exit(activityId: string, handler?: (result: object) => void): void; /** * Indicate this device is capable of receiving pushToStart live activities for the * `activityType`. The `activityType` **must** be the name of the struct conforming * to `ActivityAttributes` that will be used to start the live activity. * * Only applies to iOS * * @param activityType: The name of the specific `ActivityAttributes` structure tied * to the live activity. * @param token: The activity type's pushToStart token. */ function setPushToStartToken(activityType: string, token: string): void; /** * Indicate this device is no longer capable of receiving pushToStart live activities * for the `activityType`. The `activityType` **must** be the name of the struct conforming * to `ActivityAttributes` that will be used to start the live activity. * * Only applies to iOS * * @param activityType: The name of the specific `ActivityAttributes` structure tied * to the live activity. */ function removePushToStartToken(activityType: string): void; /** * Enable the OneSignalSDK to setup the default`DefaultLiveActivityAttributes` structure, * which conforms to the `OneSignalLiveActivityAttributes`. When using this function, the * widget attributes are owned by the OneSignal SDK, which will allow the SDK to handle the * entire lifecycle of the live activity. All that is needed from an app-perspective is to * create a Live Activity widget in a widget extension, with a `ActivityConfiguration` for * `DefaultLiveActivityAttributes`. This is most useful for users that (1) only have one Live * Activity widget and (2) are using a cross-platform framework and do not want to create the * cross-platform <-> iOS native bindings to manage ActivityKit. * * Only applies to iOS * * @param options: An optional structure to provide for more granular setup options. */ function setupDefault(options?: LiveActivitySetupOptions): void; /** * Start a new LiveActivity that is modelled by the default`DefaultLiveActivityAttributes` * structure. The `DefaultLiveActivityAttributes` is initialized with the dynamic `attributes` * and `content` passed in. * * Only applies to iOS * * @param activityId: The activity identifier the live activity on this device will be started * and eligible to receive updates for. * @param attributes: A dynamic type containing the static attributes passed into `DefaultLiveActivityAttributes`. * @param content: A dynamic type containing the content attributes passed into `DefaultLiveActivityAttributes`. */ function startDefault(activityId: string, attributes: object, content: object): void; } namespace User { namespace pushSubscription { /** Add a callback that fires when the OneSignal subscription state changes. */ function addEventListener(_event: 'change', listener: (event: PushSubscriptionChangedState) => void): void; /** Clears current subscription observers. */ function removeEventListener(_event: 'change', listener: (event: PushSubscriptionChangedState) => void): void; /** * @deprecated This method is deprecated. It has been replaced by {@link getIdAsync}. */ function getPushSubscriptionId(): string; function getIdAsync(): Promise; /** * @deprecated This method is deprecated. It has been replaced by {@link getTokenAsync}. */ function getPushSubscriptionToken(): string; /** The readonly push subscription token */ function getTokenAsync(): Promise; /** * @deprecated This method is deprecated. It has been replaced by {@link getOptedInAsync}. */ function getOptedIn(): boolean; /** * Gets a boolean value indicating whether the current user is opted in to push notifications. * This returns true when the app has notifications permission and optOut is not called. * Note: Does not take into account the existence of the subscription ID and push token. * This boolean may return true but push notifications may still not be received by the user. */ function getOptedInAsync(): Promise; /** Disable the push notification subscription to OneSignal. */ function optOut(): void; /** Enable the push notification subscription to OneSignal. */ function optIn(): void; } /** * Add a callback that fires when the OneSignal user state changes. * Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user. */ function addEventListener(_event: 'change', listener: (event: UserChangedState) => void): void; /** Clears current user state observers. */ function removeEventListener(_event: 'change', listener: (event: UserChangedState) => void): void; /** Get the nullable OneSignal Id associated with the user. */ function getOnesignalId(): Promise; /** Get the nullable External Id associated with the user. */ function getExternalId(): Promise; /** Explicitly set a 2-character language code for the user. */ function setLanguage(language: string): void; /** 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. */ function addAlias(label: string, id: string): void; /** Set aliases for the current user. If any alias already exists, it will be overwritten to the new values. */ function addAliases(aliases: Record): void; /** Remove an alias from the current user. */ function removeAlias(label: string): void; /** Remove aliases from the current user. */ function removeAliases(labels: string[]): void; /** Add a new email subscription to the current user. */ function addEmail(email: string): void; /** * Remove an email subscription from the current user. Returns false if the specified email does not exist on the user within the SDK, * and no request will be made. */ function removeEmail(email: string): void; /** Add a new SMS subscription to the current user. */ function addSms(smsNumber: string): void; /** * Remove an SMS subscription from the current user. Returns false if the specified SMS number does not exist on the user within the SDK, * and no request will be made. */ function removeSms(smsNumber: string): void; /** * Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing * messages. If the tag key already exists, it will be replaced with the value provided here. */ function addTag(key: string, value: string): void; /** * Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting * specific users and/or personalizing messages. If the tag key already exists, it will be replaced with * the value provided here. */ function addTags(tags: Record): void; /** Remove the data tag with the provided key from the current user. */ function removeTag(key: string): void; /** Remove multiple tags with the provided keys from the current user. */ function removeTags(keys: string[]): void; /** Returns the local tags for the current user. */ function getTags(): Promise<{ [key: string]: string; }>; /** * Track custom events for the current user. * Note: Currently, null values will be omitted for Android. * */ function trackEvent(name: string, properties?: Record): void; } namespace Notifications { /** * @deprecated This method is deprecated. It has been replaced by {@link getPermissionAsync}. */ function hasPermission(): boolean; /** * Whether this app has push notification permission. Returns true if the user has accepted permissions, * or if the app has ephemeral or provisional permission. */ function getPermissionAsync(): Promise; /** * Prompt the user for permission to receive push notifications. This will display the native system prompt to request push * notification permission. Use the fallbackToSettings parameter to prompt to open the settings app if a user has already * declined push permissions. */ function requestPermission(fallbackToSettings: boolean): Promise; /** * Whether attempting to request notification permission will show a prompt. Returns true if the device has not been prompted for push * notification permission already. */ function canRequestPermission(): Promise; /** * Instead of having to prompt the user for permission to send them push notifications, your app can request provisional authorization. * For more information: https://documentation.onesignal.com/docs/ios-customizations#provisional-push-notifications * @param {(response:{accepted:boolean})=>void} handler */ function registerForProvisionalAuthorization(handler: (response: boolean) => void): void; /** iOS Only. * Returns the enum for the native permission of the device. It will be one of: * OSNotificationPermissionNotDetermined, * OSNotificationPermissionDenied, * OSNotificationPermissionAuthorized, * OSNotificationPermissionProvisional - only available in iOS 12, * OSNotificationPermissionEphemeral - only available in iOS 14 * */ function permissionNative(): Promise; /** * Add listeners for notification click and/or lifecycle events. */ function addEventListener(...[event, listener]: NotificationListeners): void; /** * Remove listeners for notification click and/or lifecycle events. */ function removeEventListener(...[event, listener]: NotificationListeners): void; /** * Removes all OneSignal notifications. */ function clearAll(): void; /** * Android Only. * Removes a single OneSignal notification based on its Android notification integer id. */ function removeNotification(id: number): void; /** * Android Only. * Removes all OneSignal notifications based on its Android notification group Id. * @param {string} id - notification group id to cancel */ function removeGroupedNotifications(id: string): void; } namespace InAppMessages { /** * Add listeners for In-App Message click and/or lifecycle events. */ function addEventListener(...[event, listener]: InAppMessageListeners): void; /** * Remove listeners for In-App Message click and/or lifecycle events. */ function removeEventListener(...[event, listener]: InAppMessageListeners): void; /** * Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be * displayed to the user. */ function addTrigger(key: string, value: string): void; /** * Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should * be displayed to the user. */ function addTriggers(triggers: Record): void; /** Remove the trigger with the provided key from the current user. */ function removeTrigger(key: string): void; /** Remove multiple triggers from the current user. */ function removeTriggers(keys: string[]): void; /** Clear all triggers from the current user. */ function clearTriggers(): void; /** * Set whether in-app messaging is currently paused. * When set to true no IAM will be presented to the user regardless of whether they qualify for them. * When set to 'false` any IAMs the user qualifies for will be presented to the user at the appropriate time. */ function setPaused(pause: boolean): void; /** Whether in-app messaging is currently paused. */ function getPaused(): Promise; } namespace Location { /** Prompts the user for location permissions to allow geotagging from the OneSignal dashboard. */ function requestPermission(): void; /** Disable or enable location collection (defaults to enabled if your app has location permission). */ function setShared(shared: boolean): void; /** * Checks if location collection is enabled or disabled. * @param {(value: boolean) => void} handler */ function isShared(): Promise; } namespace Session { /** Increases the "Count" of this Outcome by 1 and will be counted each time sent. */ function addOutcome(name: string): void; /** Increases "Count" by 1 only once. This can only be attributed to a single notification. */ function addUniqueOutcome(name: string): void; /** * Increases the "Count" of this Outcome by 1 and the "Sum" by the value. Will be counted each time sent. * If the method is called outside of an attribution window, it will be unattributed until a new session occurs. */ function addOutcomeWithValue(name: string, value: string | number): void; } } //#endregion export { type InAppMessage, type InAppMessageClickEvent, type InAppMessageClickResult, type InAppMessageDidDismissEvent, type InAppMessageDidDisplayEvent, type InAppMessageWillDismissEvent, type InAppMessageWillDisplayEvent, LogLevel, type NotificationClickEvent, type NotificationClickResult, NotificationWillDisplayEvent, OSNotification, OSNotificationPermission, OneSignal, type PushSubscriptionChangedState, type PushSubscriptionState, type UserChangedState, type UserState };