appambit-push-notifications 0.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.
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "AppAmbitSdkPushNotifications"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/AppAmbit/appambit-sdk-react-native.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+ s.dependency 'AppAmbitPushNotifications', '~> 0.5.0'
20
+
21
+ install_modules_dependencies(s)
22
+ end
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AppAmbit
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # AppAmbit Push Notifications SDK
2
+
3
+ **Seamlessly integrate push notifications with your AppAmbit analytics.**
4
+
5
+ This SDK is an extension of the core AppAmbit Android SDK, providing a simple and powerful way to handle Firebase Cloud Messaging (FCM) notifications.
6
+
7
+ ---
8
+
9
+ ## Contents
10
+
11
+ * [Features](#features)
12
+ * [Requirements](#requirements)
13
+ * [Install](#install)
14
+ * [Quickstart](#quickstart)
15
+ * [Usage](#usage)
16
+ * [Customization](#customization)
17
+
18
+ ---
19
+
20
+ ## Features
21
+
22
+ * **Simple Setup**: Integrates in minutes.
23
+ * **Enable/Disable Notifications**: Easily manage user preferences at both the business and FCM level.
24
+ * **Automatic Field Handling**: Automatically uses standard fields from the FCM payload like `color`, `icon`, `channel_id`, and `click_action`.
25
+ * **Smart Icon Selection**: Automatically uses your app's icon, with a safe fallback.
26
+ * **Advanced Customization**: Provides a powerful hook to modify notifications for advanced use cases.
27
+ * **Permission Helper**: Includes a simple utility to request the `POST_NOTIFICATIONS` permission.
28
+
29
+ ---
30
+
31
+ ## Requirements
32
+
33
+ * **AppAmbit Core SDK**: This SDK is an extension and requires the core `appambit-sdk` to be installed and configured.
34
+ * **Firebase Project**: A configured Firebase project and a `google-services.json` file in your application module.
35
+ * Android API level 21 (Lollipop) or newer.
36
+
37
+ ---
38
+
39
+ ## Install
40
+ To install the library from NPM, run the following commands in your project directory:
41
+
42
+ ```bash
43
+ npm install appambit
44
+ &
45
+ npm install appambit-push-notifications
46
+ ```
47
+
48
+ Add the following dependencies to your app's `build.gradle` file. Your app is still responsible for providing the Firebase Bill of Materials (BOM) and Firebase Messaging to ensure version compatibility.
49
+
50
+ **Kotlin DSL**
51
+
52
+ **`android/app/build.gradle.kts`**
53
+ ```groovy
54
+ apply plugin: "com.google.gms.google-services"
55
+
56
+ dependencies {
57
+ // The Firebase BOM and Messaging are required to align Firebase library versions.
58
+ implementation(platform("com.google.firebase:firebase-bom:33.1.2"))
59
+ implementation ("com.google.firebase:firebase-messaging:23.4.0")
60
+ }
61
+ ```
62
+ **`android/build.gradle.kts`**
63
+ ```groovy
64
+ dependencies {
65
+ classpath("com.google.gms:google-services:4.3.15")
66
+ }
67
+ ```
68
+
69
+ **Groovy**
70
+ **`android/app/build.gradle`**
71
+ ```groovy
72
+ apply plugin: "com.google.gms.google-services"
73
+
74
+ dependencies {
75
+ // The Firebase BOM and Messaging are required to align Firebase library versions.
76
+ implementation platform('com.google.firebase:firebase-bom:33.1.2')
77
+ implementation 'com.google.firebase:firebase-messaging:23.4.0'
78
+ }
79
+ ```
80
+
81
+ **`android/build.gradle`**
82
+ ```groovy
83
+ dependencies {
84
+ classpath("com.google.gms:google-services:4.3.15")
85
+ }
86
+ ```
87
+
88
+ Also, ensure you have the Google Services plugin configured in your project.
89
+
90
+ ---
91
+
92
+ ## Quickstart
93
+
94
+ **Import the SDKs**: In your `App.tsx` file, import both the AppAmbit SDK and the Push Notifications SDK.
95
+
96
+ ```javascript
97
+ import * as AppAmbit from "appambit";
98
+ ```
99
+ ```javascript
100
+ import * as PushNotifications from "appambit-push-notifications";
101
+ ```
102
+
103
+
104
+ 1. **Initialize the Core SDK**: In your `App.tsx` class, initialize the core AppAmbit SDK with your App Key.
105
+
106
+ ```javascript
107
+ AppAmbit.start("<YOUR-APPKEY>");
108
+ ```
109
+
110
+ 2. **Initialize the Push SDK**: Immediately after, start the Push Notifications SDK.
111
+
112
+ ```javascript
113
+ PushNotifications.start();
114
+ ```
115
+
116
+ 3. **Request Permissions**: In your main activity, request the required notification permission.
117
+
118
+ ```javascript
119
+ PushNotifications.requestNotificationPermission();
120
+ ```
121
+
122
+ **That's it!** Your app is now ready to receive and display push notifications.
123
+
124
+ ---
125
+
126
+ ## Usage
127
+
128
+ ### Enabling and Disabling Notifications
129
+
130
+ By default, notifications are enabled when you first call `start()`. To manage user preferences afterward, use `setNotificationsEnabled`.
131
+
132
+ ```javascript
133
+ // To disable all future notifications
134
+ PushNotifications.setNotificationsEnabled(false)
135
+
136
+ // To re-enable them
137
+ PushNotifications.setNotificationsEnabled(true)
138
+ ```
139
+
140
+ This method updates the opt-out status on the AppAmbit dashboard and stops the device from receiving FCM messages. You can check the current setting at any time:
141
+
142
+ ```javascript
143
+ const isEnabled = PushNotifications.isNotificationsEnabled()
144
+ ```
145
+
146
+ ### Permission Listener (Optional)
147
+
148
+ To know if the user granted or denied the notification permission, you can provide an optional listener.
149
+
150
+ ```javascript
151
+ PushNotifications.requestNotificationPermissionWithResult().then(
152
+ (granted: boolean) => {
153
+ if(granted) {
154
+ console.log("Notification permission granted");
155
+ } else {
156
+ console.log("Notification permission denied");
157
+ }
158
+ }
159
+ );
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Customization
165
+
166
+ The SDK is designed to be highly customizable, automatically adapting to the data you send in your FCM payload, while also offering a powerful hook for advanced modifications.
167
+
168
+ ### Automatic Customization
169
+
170
+ The SDK automatically configures the notification by reading standard fields from your FCM message. **For most use cases, you won't need to write any custom code.**
171
+
172
+ **`notification` object:**
173
+
174
+ The SDK uses the standard keys from the FCM `notification` object.
175
+
176
+ - **`title`**: The notification's title.
177
+ - **`body`**: The notification's main text.
178
+
179
+ **`data` object:**
180
+
181
+ The `data` object is a free-form container for any custom key-value pairs you wish to send (e.g., `{"your_key": "your_value", "another_key": 123}`). Its sole purpose is to pass custom data to your application, which you can then access using the `NotificationCustomizer` to implement any advanced logic you require.
182
+
183
+ ### Advanced Customization with `NotificationCustomizer`
184
+
185
+ The `data` payload is a **free-form key-value map**. You are not limited to any specific keys; you can send any data you need and use it to build your custom notification.
186
+
187
+ **Example: Building a Custom Notification**
188
+
189
+ The following example shows how to read custom fields from the `data` payload to add a custom action button. This is just one of many possibilities.
190
+
191
+ 1. **Send any custom data** you need. The keys and values are completely up to you. For example:
192
+
193
+ ```json
194
+ {
195
+ "title": "New Message",
196
+ "body": "You have a new message from a friend.",
197
+ "data": {
198
+ "key1": "Mark as Read",
199
+ "key2": "MARK_AS_READ_ACTION",
200
+ "any_other_key": "any_value"
201
+ }
202
+ }
203
+ ```
204
+
205
+ 2. **Register the `NotificationCustomizer`** and use your custom keys:
206
+
207
+ ```javascript
208
+ PushNotifications.setNotificationCustomizer((payload: PushNotifications.NotificationPayload) => {
209
+ console.log("Payload:", payload);
210
+ console.log("Data:", payload.data);
211
+ console.log("Title:", payload.title);
212
+ console.log("Body:", payload.body);
213
+ });
214
+ PushNotifications.start();
215
+ ```
@@ -0,0 +1,78 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AppambitPushNotifications_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AppambitPushNotifications_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.appambitpushnotifications"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.appambit:appambit.push.notifications:0.5.0"
76
+ implementation "com.facebook.react:react-android"
77
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
78
+ }
@@ -0,0 +1,5 @@
1
+ AppambitPushNotifications_kotlinVersion=2.0.21
2
+ AppambitPushNotifications_minSdkVersion=24
3
+ AppambitPushNotifications_targetSdkVersion=34
4
+ AppambitPushNotifications_compileSdkVersion=35
5
+ AppambitPushNotifications_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,93 @@
1
+ package com.appambitpushnotifications
2
+
3
+ import android.app.Activity
4
+ import androidx.activity.ComponentActivity
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.Promise
7
+ import com.facebook.react.module.annotations.ReactModule
8
+ import com.appambit.sdk.PushNotifications
9
+ import com.facebook.react.bridge.Arguments
10
+ import com.facebook.react.bridge.WritableMap
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule
12
+
13
+ @ReactModule(name = AppambitPushNotificationsModule.NAME)
14
+ class AppambitPushNotificationsModule(reactContext: ReactApplicationContext) :
15
+ NativeAppambitPushNotificationsSpec(reactContext) {
16
+
17
+ override fun getName(): String {
18
+ return NAME
19
+ }
20
+
21
+ override fun start() {
22
+ PushNotifications.start(reactApplicationContext.applicationContext)
23
+ }
24
+
25
+ override fun requestNotificationPermission() {
26
+ val activity: Activity? = currentActivity
27
+ if (activity is ComponentActivity) {
28
+ PushNotifications.requestNotificationPermission(activity)
29
+ }
30
+ }
31
+
32
+ override fun requestNotificationPermissionWithResult(promise: Promise) {
33
+ val activity: Activity? = currentActivity
34
+ if (activity is ComponentActivity) {
35
+ PushNotifications.requestNotificationPermission(activity) { isGranted ->
36
+ promise.resolve(isGranted)
37
+ }
38
+ } else {
39
+ promise.resolve(false)
40
+ }
41
+ }
42
+
43
+ override fun setNotificationsEnabled(enabled: Boolean) {
44
+ PushNotifications.setNotificationsEnabled(
45
+ reactApplicationContext.applicationContext,
46
+ enabled
47
+ )
48
+ }
49
+
50
+ override fun isNotificationsEnabled(promise: Promise) {
51
+ val enabled = PushNotifications.isNotificationsEnabled(
52
+ reactApplicationContext.applicationContext
53
+ )
54
+ promise.resolve(enabled)
55
+ }
56
+
57
+ override fun setNotificationCustomizer() {
58
+ PushNotifications.setNotificationCustomizer { _, _, notification ->
59
+ val params = Arguments.createMap()
60
+
61
+ val notificationMap = Arguments.createMap()
62
+ notificationMap.putString("title", notification.title)
63
+ notificationMap.putString("body", notification.body)
64
+
65
+ params.putMap("notification", notificationMap)
66
+
67
+ notification.data?.let { data ->
68
+ val dataMap = Arguments.createMap()
69
+ for ((key, value) in data) {
70
+ dataMap.putString(key, value)
71
+ }
72
+ params.putMap("data", dataMap)
73
+ }
74
+ sendEvent("onNotificationReceived", params)
75
+ }
76
+ }
77
+
78
+ private fun sendEvent(eventName: String, params: WritableMap?) {
79
+ if (reactApplicationContext.hasActiveReactInstance()) {
80
+ reactApplicationContext
81
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
82
+ .emit(eventName, params)
83
+ }
84
+ }
85
+
86
+ override fun addListener(eventName: String?) {}
87
+
88
+ override fun removeListeners(count: Double) {}
89
+
90
+ companion object {
91
+ const val NAME = "AppambitPushNotifications"
92
+ }
93
+ }
@@ -0,0 +1,33 @@
1
+ package com.appambitpushnotifications
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import java.util.HashMap
9
+
10
+ class AppambitPushNotificationsPackage : BaseReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == AppambitPushNotificationsModule.NAME) {
13
+ AppambitPushNotificationsModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ moduleInfos[AppambitPushNotificationsModule.NAME] = ReactModuleInfo(
23
+ AppambitPushNotificationsModule.NAME,
24
+ AppambitPushNotificationsModule.NAME,
25
+ false, // canOverrideExistingModule
26
+ false, // needsEagerInit
27
+ false, // isCxxModule
28
+ true // isTurboModule
29
+ )
30
+ moduleInfos
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,58 @@
1
+ import Foundation
2
+ import UserNotifications
3
+ import AppAmbitPushNotifications
4
+
5
+ @objc(AppAmbitPushWrapper)
6
+ public class AppAmbitPushWrapper: NSObject {
7
+
8
+ @objc public static func start() {
9
+ PushNotifications.start()
10
+ }
11
+
12
+ @objc public static func setNotificationsEnabled(_ enabled: Bool) {
13
+ PushNotifications.setNotificationsEnabled(enabled)
14
+ }
15
+
16
+ @objc public static func isNotificationsEnabled() -> Bool {
17
+ return PushNotifications.isNotificationsEnabled()
18
+ }
19
+
20
+ @objc public static func requestNotificationPermission(listener: ((Bool) -> Void)?) {
21
+ PushNotifications.requestNotificationPermission(listener: listener)
22
+ }
23
+
24
+ @objc(setNotificationCustomizer:)
25
+ public static func setNotificationCustomizer(listener: ((NSDictionary) -> Void)?) {
26
+ PushNotifications.setNotificationCustomizer { notification in
27
+ let content = notification.request.content
28
+ let userInfo = content.userInfo
29
+
30
+ var notificationData: [String: String] = [
31
+ "title": content.title,
32
+ "body": content.body
33
+ ]
34
+
35
+ if !content.subtitle.isEmpty {
36
+ notificationData["subtitle"] = content.subtitle
37
+ }
38
+
39
+ var customData: [String: String] = [:]
40
+ for (key, value) in userInfo {
41
+ guard let keyStr = key as? String else { continue }
42
+ // Exclude only the standard Apple payload. We keep the rest to see exactly what comes.
43
+ if keyStr == "aps" { continue }
44
+ customData[keyStr] = "\(value)"
45
+ }
46
+
47
+ var payload: [String: Any] = [
48
+ "notification": notificationData
49
+ ]
50
+
51
+ if !customData.isEmpty {
52
+ payload["data"] = customData
53
+ }
54
+
55
+ listener?(payload as NSDictionary)
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,6 @@
1
+ #import <AppambitPushNotificationsSpec/AppambitPushNotificationsSpec.h>
2
+ #import <React/RCTEventEmitter.h>
3
+
4
+ @interface AppambitPushNotifications : RCTEventEmitter <NativeAppambitPushNotificationsSpec>
5
+
6
+ @end
@@ -0,0 +1,74 @@
1
+ #import "AppambitPushNotifications.h"
2
+ #import <AppAmbitSdkPushNotifications-Swift.h>
3
+
4
+ @implementation AppambitPushNotifications {
5
+ BOOL _hasListeners;
6
+ }
7
+
8
+ RCT_EXPORT_MODULE(AppambitPushNotifications)
9
+
10
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
11
+ (const facebook::react::ObjCTurboModule::InitParams &)params
12
+ {
13
+ return std::make_shared<facebook::react::NativeAppambitPushNotificationsSpecJSI>(params);
14
+ }
15
+
16
+ // MARK: - Event Emitter
17
+
18
+ - (NSArray<NSString *> *)supportedEvents {
19
+ return @[@"onNotificationReceived"];
20
+ }
21
+
22
+ - (void)startObserving {
23
+ _hasListeners = YES;
24
+ }
25
+
26
+ - (void)stopObserving {
27
+ _hasListeners = NO;
28
+ }
29
+
30
+ // MARK: - TurboModule Methods
31
+
32
+ - (void)start {
33
+ [AppAmbitPushWrapper start];
34
+ }
35
+
36
+ - (void)requestNotificationPermission {
37
+ [AppAmbitPushWrapper requestNotificationPermissionWithListener:nil];
38
+ }
39
+
40
+ - (void)requestNotificationPermissionWithResult:(RCTPromiseResolveBlock)resolve
41
+ reject:(RCTPromiseRejectBlock)reject {
42
+ [AppAmbitPushWrapper requestNotificationPermissionWithListener:^(BOOL granted) {
43
+ resolve(@(granted));
44
+ }];
45
+ }
46
+
47
+ - (void)setNotificationsEnabled:(BOOL)enabled {
48
+ [AppAmbitPushWrapper setNotificationsEnabled:enabled];
49
+ }
50
+
51
+ - (void)isNotificationsEnabled:(RCTPromiseResolveBlock)resolve
52
+ reject:(RCTPromiseRejectBlock)reject {
53
+ resolve(@([AppAmbitPushWrapper isNotificationsEnabled]));
54
+ }
55
+
56
+ - (void)setNotificationCustomizer {
57
+ __weak AppambitPushNotifications *weakSelf = self;
58
+ [AppAmbitPushWrapper setNotificationCustomizer:^(NSDictionary * _Nonnull payload) {
59
+ AppambitPushNotifications *strongSelf = weakSelf;
60
+ if (strongSelf && strongSelf->_hasListeners) {
61
+ [strongSelf sendEventWithName:@"onNotificationReceived" body:payload];
62
+ }
63
+ }];
64
+ }
65
+
66
+ - (void)addListener:(NSString *)eventName {
67
+ [super addListener:eventName];
68
+ }
69
+
70
+ - (void)removeListeners:(double)count {
71
+ [super removeListeners:count];
72
+ }
73
+
74
+ @end
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('AppambitPushNotifications');
5
+ //# sourceMappingURL=NativeAppambitPushNotifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeAppambitPushNotifications.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAcpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,2BAA2B,CAAC","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ import { NativeEventEmitter } from 'react-native';
4
+ import AppambitPushNotifications from "./NativeAppambitPushNotifications.js";
5
+ const eventEmitter = new NativeEventEmitter(AppambitPushNotifications);
6
+ export const start = () => {
7
+ AppambitPushNotifications.start();
8
+ };
9
+ export const requestNotificationPermission = () => {
10
+ AppambitPushNotifications.requestNotificationPermission();
11
+ };
12
+ export const requestNotificationPermissionWithResult = async () => {
13
+ return await AppambitPushNotifications.requestNotificationPermissionWithResult();
14
+ };
15
+ export const setNotificationsEnabled = enabled => {
16
+ AppambitPushNotifications.setNotificationsEnabled(enabled);
17
+ };
18
+ export const isNotificationsEnabled = async () => {
19
+ return await AppambitPushNotifications.isNotificationsEnabled();
20
+ };
21
+ export const setNotificationCustomizer = callback => {
22
+ AppambitPushNotifications.setNotificationCustomizer();
23
+ eventEmitter.removeAllListeners('onNotificationReceived');
24
+ eventEmitter.addListener('onNotificationReceived', payload => {
25
+ callback(payload);
26
+ });
27
+ };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeEventEmitter","AppambitPushNotifications","eventEmitter","start","requestNotificationPermission","requestNotificationPermissionWithResult","setNotificationsEnabled","enabled","isNotificationsEnabled","setNotificationCustomizer","callback","removeAllListeners","addListener","payload"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,cAAc;AACjD,OAAOC,yBAAyB,MAAM,sCAAmC;AAEzE,MAAMC,YAAY,GAAG,IAAIF,kBAAkB,CAACC,yBAAyB,CAAC;AAUtE,OAAO,MAAME,KAAK,GAAGA,CAAA,KAAY;EAC/BF,yBAAyB,CAACE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,OAAO,MAAMC,6BAA6B,GAAGA,CAAA,KAAY;EACvDH,yBAAyB,CAACG,6BAA6B,CAAC,CAAC;AAC3D,CAAC;AAED,OAAO,MAAMC,uCAAuC,GAAG,MAAAA,CAAA,KAA8B;EACnF,OAAO,MAAMJ,yBAAyB,CAACI,uCAAuC,CAAC,CAAC;AAClF,CAAC;AAED,OAAO,MAAMC,uBAAuB,GAAIC,OAAgB,IAAW;EACjEN,yBAAyB,CAACK,uBAAuB,CAACC,OAAO,CAAC;AAC5D,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAG,MAAAA,CAAA,KAA8B;EAClE,OAAO,MAAMP,yBAAyB,CAACO,sBAAsB,CAAC,CAAC;AACjE,CAAC;AAED,OAAO,MAAMC,yBAAyB,GACpCC,QAAgD,IACvC;EACTT,yBAAyB,CAACQ,yBAAyB,CAAC,CAAC;EACrDP,YAAY,CAACS,kBAAkB,CAAC,wBAAwB,CAAC;EACzDT,YAAY,CAACU,WAAW,CAAC,wBAAwB,EAAGC,OAAO,IAAK;IAC9DH,QAAQ,CAACG,OAAc,CAAC;EAC1B,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,14 @@
1
+ import { type TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ start(): void;
4
+ requestNotificationPermission(): void;
5
+ requestNotificationPermissionWithResult(): Promise<boolean>;
6
+ setNotificationsEnabled(enabled: boolean): void;
7
+ isNotificationsEnabled(): Promise<boolean>;
8
+ setNotificationCustomizer(): void;
9
+ addListener(eventName: string): void;
10
+ removeListeners(count: number): void;
11
+ }
12
+ declare const _default: Spec;
13
+ export default _default;
14
+ //# sourceMappingURL=NativeAppambitPushNotifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeAppambitPushNotifications.d.ts","sourceRoot":"","sources":["../../../src/NativeAppambitPushNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,KAAK,IAAI,IAAI,CAAC;IACd,6BAA6B,IAAI,IAAI,CAAC;IACtC,uCAAuC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAChD,sBAAsB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3C,yBAAyB,IAAI,IAAI,CAAC;IAClC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAED,wBAAmF"}
@@ -0,0 +1,14 @@
1
+ export interface NotificationPayload {
2
+ notification: {
3
+ title: string;
4
+ body: string;
5
+ };
6
+ data?: Record<string, string>;
7
+ }
8
+ export declare const start: () => void;
9
+ export declare const requestNotificationPermission: () => void;
10
+ export declare const requestNotificationPermissionWithResult: () => Promise<boolean>;
11
+ export declare const setNotificationsEnabled: (enabled: boolean) => void;
12
+ export declare const isNotificationsEnabled: () => Promise<boolean>;
13
+ export declare const setNotificationCustomizer: (callback: (payload: NotificationPayload) => void) => void;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAA;IACD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,eAAO,MAAM,KAAK,QAAO,IAExB,CAAC;AAEF,eAAO,MAAM,6BAA6B,QAAO,IAEhD,CAAC;AAEF,eAAO,MAAM,uCAAuC,QAAa,OAAO,CAAC,OAAO,CAE/E,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,SAAS,OAAO,KAAG,IAE1D,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAa,OAAO,CAAC,OAAO,CAE9D,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,UAAU,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,KAC/C,IAMF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,160 @@
1
+ {
2
+ "name": "appambit-push-notifications",
3
+ "version": "0.2.0",
4
+ "description": "Push Notifications SDK for Android to send push notifications via AppAmbit platform.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace appambit-push-notifications-example",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "test": "jest",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/AppAmbit/appambit-sdk-react-native.git"
51
+ },
52
+ "author": "AppAmbit <hello@appambit.com> (https://appambit.com)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/AppAmbit/appambit-sdk-react-native/issues"
56
+ },
57
+ "homepage": "https://github.com/AppAmbit/appambit-sdk-react-native#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@eslint/compat": "^1.3.2",
63
+ "@eslint/eslintrc": "^3.3.1",
64
+ "@eslint/js": "^9.35.0",
65
+ "@react-native/babel-preset": "0.83.0",
66
+ "@react-native/eslint-config": "0.83.0",
67
+ "@release-it/conventional-changelog": "^10.0.1",
68
+ "@types/jest": "^29.5.14",
69
+ "@types/react": "^19.2.0",
70
+ "del-cli": "^6.0.0",
71
+ "eslint": "^9.35.0",
72
+ "eslint-config-prettier": "^10.1.8",
73
+ "eslint-plugin-prettier": "^5.5.4",
74
+ "jest": "^29.7.0",
75
+ "prettier": "^2.8.8",
76
+ "react": "19.2.0",
77
+ "react-native": "0.83.0",
78
+ "react-native-builder-bob": "^0.40.17",
79
+ "release-it": "^19.0.4",
80
+ "turbo": "^2.5.6",
81
+ "typescript": "^5.9.2"
82
+ },
83
+ "peerDependencies": {
84
+ "react": "*",
85
+ "react-native": "*"
86
+ },
87
+ "workspaces": [
88
+ "example"
89
+ ],
90
+ "packageManager": "yarn@4.11.0",
91
+ "react-native-builder-bob": {
92
+ "source": "src",
93
+ "output": "lib",
94
+ "targets": [
95
+ [
96
+ "module",
97
+ {
98
+ "esm": true
99
+ }
100
+ ],
101
+ [
102
+ "typescript",
103
+ {
104
+ "project": "tsconfig.build.json"
105
+ }
106
+ ]
107
+ ]
108
+ },
109
+ "codegenConfig": {
110
+ "name": "AppambitPushNotificationsSpec",
111
+ "type": "modules",
112
+ "jsSrcsDir": "src",
113
+ "android": {
114
+ "javaPackageName": "com.appambitpushnotifications"
115
+ }
116
+ },
117
+ "prettier": {
118
+ "quoteProps": "consistent",
119
+ "singleQuote": true,
120
+ "tabWidth": 2,
121
+ "trailingComma": "es5",
122
+ "useTabs": false
123
+ },
124
+ "jest": {
125
+ "preset": "react-native",
126
+ "modulePathIgnorePatterns": [
127
+ "<rootDir>/example/node_modules",
128
+ "<rootDir>/lib/"
129
+ ]
130
+ },
131
+ "release-it": {
132
+ "git": {
133
+ "commitMessage": "chore: release ${version}",
134
+ "tagName": "v${version}"
135
+ },
136
+ "npm": {
137
+ "publish": true
138
+ },
139
+ "github": {
140
+ "release": true
141
+ },
142
+ "plugins": {
143
+ "@release-it/conventional-changelog": {
144
+ "preset": {
145
+ "name": "angular"
146
+ }
147
+ }
148
+ }
149
+ },
150
+ "create-react-native-library": {
151
+ "type": "turbo-module",
152
+ "languages": "kotlin-objc",
153
+ "tools": [
154
+ "eslint",
155
+ "jest",
156
+ "release-it"
157
+ ],
158
+ "version": "0.56.0"
159
+ }
160
+ }
@@ -0,0 +1,15 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ export interface Spec extends TurboModule {
4
+ start(): void;
5
+ requestNotificationPermission(): void;
6
+ requestNotificationPermissionWithResult(): Promise<boolean>;
7
+ setNotificationsEnabled(enabled: boolean): void;
8
+ isNotificationsEnabled(): Promise<boolean>;
9
+
10
+ setNotificationCustomizer(): void;
11
+ addListener(eventName: string): void;
12
+ removeListeners(count: number): void;
13
+ }
14
+
15
+ export default TurboModuleRegistry.getEnforcing<Spec>('AppambitPushNotifications');
package/src/index.tsx ADDED
@@ -0,0 +1,42 @@
1
+ import { NativeEventEmitter } from 'react-native';
2
+ import AppambitPushNotifications from './NativeAppambitPushNotifications';
3
+
4
+ const eventEmitter = new NativeEventEmitter(AppambitPushNotifications);
5
+
6
+ export interface NotificationPayload {
7
+ notification: {
8
+ title: string;
9
+ body: string;
10
+ }
11
+ data?: Record<string, string>;
12
+ }
13
+
14
+ export const start = (): void => {
15
+ AppambitPushNotifications.start();
16
+ };
17
+
18
+ export const requestNotificationPermission = (): void => {
19
+ AppambitPushNotifications.requestNotificationPermission();
20
+ };
21
+
22
+ export const requestNotificationPermissionWithResult = async (): Promise<boolean> => {
23
+ return await AppambitPushNotifications.requestNotificationPermissionWithResult();
24
+ };
25
+
26
+ export const setNotificationsEnabled = (enabled: boolean): void => {
27
+ AppambitPushNotifications.setNotificationsEnabled(enabled);
28
+ };
29
+
30
+ export const isNotificationsEnabled = async (): Promise<boolean> => {
31
+ return await AppambitPushNotifications.isNotificationsEnabled();
32
+ };
33
+
34
+ export const setNotificationCustomizer = (
35
+ callback: (payload: NotificationPayload) => void
36
+ ): void => {
37
+ AppambitPushNotifications.setNotificationCustomizer();
38
+ eventEmitter.removeAllListeners('onNotificationReceived');
39
+ eventEmitter.addListener('onNotificationReceived', (payload) => {
40
+ callback(payload as any);
41
+ });
42
+ };