Pushwoosh / pushwoosh-react-native-plugin

Other
57 stars 43 forks source link

Typescript support #112

Closed Mighty683 closed 2 years ago

Mighty683 commented 3 years ago

Typescript is getting more popular in world of react native maybe it would be good to add official typescript typing for project?

For now issue can be solved by adding declarations file to project.

wfhm commented 3 years ago

@Mighty683,

Thanks for the suggestion. We will discuss such a possibility internally, and I will get back to you once there is any news.

For now issue can be omitted by adding declarations file to project.

Could you please be a bit more specific on the issue?

ctomichael commented 3 years ago

+1 on this. We are currently evaluating push notification platforms for all our apps, and typescript support is a must.

Mighty683 commented 3 years ago

@Mighty683,

Thanks for the suggestion. We will discuss such a possibility internally, and I will get back to you once there is any news.

For now issue can be omitted by adding declarations file to project.

Could you please be a bit more specific on the issue?

I created in my project declaration file on my own so I have typing of pushwoosh module

declare module 'pushwoosh-react-native-plugin' {
  interface PushwooshConfig {
    pw_appid: string,
    project_number: string,
  }
  interface Pushwoosh {
    register(
      success?: (token: string) => void,
      fail?: (token: Error) => void),
    setTags(tags: Object, success?: Function, fail?: Function),
    setUserId(userId: string),
    getHwid(success?: (token: string) => void),
    getPushToken(success?: (token: string) => void),
    init(
      config: PushwooshConfig,
      success?: () => void,
      fail?: () => void),
  }

  declare var pushwoosh: Pushwoosh;
  export = pushwoosh;
}
wfhm commented 3 years ago

@Mighty683 @district-michael we have added it to our backlog, however it is pretty unlikely to be done in the nearest future. I will update this thread as soon as there is any ETA on it.

Meanwhile we have tested the solution offered by @Mighty683 and it seems to be working nice so far, so it can be used as a workaround.

breezertwo commented 2 years ago

In case anyone needs a fully typed one (based on current documentation):

declare module 'pushwoosh-react-native-plugin' {
  interface PushwooshConfig {
    pw_appid: string
    project_number: string
    pw_notification_handling?: string
  }

  interface PushwooshTags {
    [index: string]: string | number | string[] | number[]
  }

  interface Pushwoosh {
    /** Initializes Pushwoosh module with application id and google project number. */
    init(config: PushwooshConfig, success?: () => void, fail?: () => void): void
    /** Registers current device for push notifications. */
    register(
      success?: (token: string) => void,
      fail?: (error: Error) => void,
    ): void
    /** Unregisters current deivce from receiving push notifications. */
    unregister(success?: () => void, fail?: () => void): void
    /** Set tags associated with current device and application. */
    setTags(
      tags: PushwooshTags,
      success?: () => void,
      fail?: (error: Error) => void,
    ): void
    /** Get tags associated with current device and application. */
    getTags(success?: (tags: Tags) => void, fail?: (error: Error) => void): void
    /** Set User indentifier. This could be Facebook ID, username or email, or any other user ID. This allows data and events to be matched across multiple user devices. */
    setUserId(
      userId: string,
      success?: () => void,
      fail?: (error: Error) => void,
    ): void
    /** Returns Pushwoosh HWID used for communications with Pushwoosh API. */
    getHwid(success?: (token: string) => void): void
    /** Returns push token or null if device is not registered for push notifications. */
    getPushToken(success?: (token: string) => void): void
    /** Post events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel. */
    postEvent(event: string, attributes?: Record<string, string>): void
    /** Allows multiple notifications to be displayed in the Android Notification Center. Android only */
    setMultiNotificationMode(on: boolean): void
    /** Turns screen on when notification arrives. Android only*/
    setLightScreenOnNotification(on: boolean): void
    /** Enables LED blinking when notification arrives and display is off. Android only*/
    setEnableLED(on: boolean): void
    /** Set led color. Use with setEnableLED.
     * Android only
     * @param color - color in ARGB integer format
     */
    setColorLED(color: number): void
    /** A binary method enabling/disabling all communication with Pushwoosh. The boolean value is false unsubscribes the device from receiving push notifications and stops in-app messages download. The value true reverses the effect. */
    setCommunicationEnabled(on: boolean): void
    /** Removes all data about the device. Cannot be undone. */
    removeAllDeviceData(): void
    /** Set application icon badge number. */
    setApplicationIconBadgeNumber(badgeNumber: number): void
    /** Returns application icon badge number. */
    getApplicationIconBadgeNumber(callback: (badge: number) => void): void
    /** Adds value to application icon badge. */
    addToApplicationIconBadgeNumber(badgeNumber: number): void
    /** Sets default sound for incoming push notifications.
     * Android only
     * @param type Sound type (0: default, 1: no sound, 2: always)
     */
    setSoundType(type: number): void
    /** Sets default vibration mode for incoming push notifications.
     * Android only
     * @param type Vibration type (0: default, 1: no vibration, 2: always)
     */
    setVibrateType(type: number): void
    /** Opens Inbox screen. */
    presentInboxUI(): void
    /** Shows the GDPR Consent Form */
    showGDPRConsentUI(): void
    /** Shows the GDPR Deletion Form */
    showGDPRDeletionUI(): void
    /** Enables Huawei push messaging. Requires configured Huawei platform for your Pushwoosh application */
    enableHuaweiPushNotifications(): void
  }

  declare const pushwoosh: Pushwoosh
  export = pushwoosh
}
wfhm commented 2 years ago

Typescript support is added with the 6.1.14 release. The docs will be updated with the typings shortly.