@pushpushgo/react-native-push 0.4.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.
Files changed (40) hide show
  1. package/LICENSE +20 -0
  2. package/PushPushGoRNPush.podspec +22 -0
  3. package/README.md +412 -0
  4. package/android/build.gradle +79 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +10 -0
  7. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsActivityCallbacks.kt +36 -0
  8. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsBeaconTranslator.kt +107 -0
  9. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsContentProvider.kt +72 -0
  10. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsError.kt +6 -0
  11. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsModule.kt +54 -0
  12. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsPackage.kt +36 -0
  13. package/ios/Bridge/PushNotificationsBeaconTranslator.swift +80 -0
  14. package/ios/Bridge/PushNotificationsModule.h +10 -0
  15. package/ios/Bridge/PushNotificationsModule.mm +53 -0
  16. package/ios/Bridge/PushNotificationsModuleDelegate.swift +68 -0
  17. package/ios/PushNotificationsRN.swift +35 -0
  18. package/lib/module/beacon/Beacon.js +51 -0
  19. package/lib/module/beacon/Beacon.js.map +1 -0
  20. package/lib/module/beacon/BeaconTag.js +32 -0
  21. package/lib/module/beacon/BeaconTag.js.map +1 -0
  22. package/lib/module/index.js +37 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/specs/NativePushNotifications.js +5 -0
  26. package/lib/module/specs/NativePushNotifications.js.map +1 -0
  27. package/lib/typescript/package.json +1 -0
  28. package/lib/typescript/src/beacon/Beacon.d.ts +38 -0
  29. package/lib/typescript/src/beacon/Beacon.d.ts.map +1 -0
  30. package/lib/typescript/src/beacon/BeaconTag.d.ts +31 -0
  31. package/lib/typescript/src/beacon/BeaconTag.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +12 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/specs/NativePushNotifications.d.ts +22 -0
  35. package/lib/typescript/src/specs/NativePushNotifications.d.ts.map +1 -0
  36. package/package.json +168 -0
  37. package/src/beacon/Beacon.ts +84 -0
  38. package/src/beacon/BeaconTag.ts +52 -0
  39. package/src/index.tsx +62 -0
  40. package/src/specs/NativePushNotifications.ts +25 -0
@@ -0,0 +1,72 @@
1
+ package com.pushpushgo.bridge.reactnative.push
2
+
3
+ import android.app.Application
4
+ import android.content.ContentProvider
5
+ import android.content.ContentValues
6
+ import android.content.Intent
7
+ import android.content.pm.PackageManager
8
+ import android.database.Cursor
9
+ import android.net.Uri
10
+ import com.pushpushgo.sdk.PushPushGo
11
+
12
+ class PushNotificationsContentProvider : ContentProvider() {
13
+ override fun onCreate(): Boolean {
14
+ context?.applicationContext?.let { ctx ->
15
+ val app = ctx as Application
16
+ val metadata =
17
+ ctx
18
+ .packageManager
19
+ .getApplicationInfo(ctx.packageName, PackageManager.GET_META_DATA)
20
+ .metaData
21
+
22
+ if (!PushPushGo.isInitialized()) {
23
+ PushPushGo.getInstance(
24
+ application = app,
25
+ projectId =
26
+ metadata.getString(
27
+ "com.pushpushgo.projectId",
28
+ ) ?: throw PushNotificationsError("com.pushpushgo.projectId is required"),
29
+ apiKey = metadata.getString("com.pushpushgo.apiKey") ?: throw PushNotificationsError("com.pushpushgo.apiKey is required"),
30
+ isDebug = metadata.getBoolean("com.pushpushgo.isDebug"),
31
+ isProduction = !metadata.getBoolean("com.pushpushgo.isStaging"),
32
+ )
33
+
34
+ PushPushGo
35
+ .getInstance()
36
+ .setCustomClickIntentFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
37
+ }
38
+
39
+ app.registerActivityLifecycleCallbacks(PushNotificationsActivityCallbacks())
40
+ }
41
+
42
+ return true
43
+ }
44
+
45
+ override fun getType(uri: Uri): String? = null
46
+
47
+ override fun query(
48
+ uri: Uri,
49
+ projection: Array<out String>?,
50
+ selection: String?,
51
+ selectionArgs: Array<out String>?,
52
+ sortOrder: String?,
53
+ ): Cursor? = null
54
+
55
+ override fun insert(
56
+ uri: Uri,
57
+ values: ContentValues?,
58
+ ): Uri? = null
59
+
60
+ override fun delete(
61
+ uri: Uri,
62
+ selection: String?,
63
+ selectionArgs: Array<out String>?,
64
+ ): Int = -1
65
+
66
+ override fun update(
67
+ uri: Uri,
68
+ values: ContentValues?,
69
+ selection: String?,
70
+ selectionArgs: Array<out String>?,
71
+ ): Int = -1
72
+ }
@@ -0,0 +1,6 @@
1
+ package com.pushpushgo.bridge.reactnative.push
2
+
3
+ class PushNotificationsError(
4
+ message: String,
5
+ cause: Throwable? = null,
6
+ ) : Exception(message, cause)
@@ -0,0 +1,54 @@
1
+ package com.pushpushgo.bridge.reactnative.push
2
+
3
+ import androidx.core.content.ContextCompat
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReadableMap
7
+ import com.google.common.util.concurrent.FutureCallback
8
+ import com.google.common.util.concurrent.Futures
9
+ import com.pushpushgo.sdk.PushPushGo
10
+
11
+ class PushNotificationsModule(
12
+ reactContext: ReactApplicationContext,
13
+ ) : NativePushNotificationsSpec(reactContext) {
14
+ private val ppg by lazy { PushPushGo.getInstance() }
15
+
16
+ companion object {
17
+ const val NAME: String = "PushPushGoPushNotifications"
18
+ }
19
+
20
+ override fun getSubscriberId(promise: Promise) {
21
+ promise.resolve(ppg.getSubscriberId().ifEmpty { null })
22
+ }
23
+
24
+ override fun subscribeToNotifications(promise: Promise) {
25
+ Futures.addCallback(
26
+ ppg.createSubscriber(),
27
+ object : FutureCallback<String> {
28
+ override fun onSuccess(result: String) {
29
+ promise.resolve(result.ifEmpty { null })
30
+ }
31
+
32
+ override fun onFailure(t: Throwable) {
33
+ promise.reject(PushNotificationsError("Cannot subscribe to notifications: " + t.message))
34
+ }
35
+ },
36
+ ContextCompat.getMainExecutor(reactApplicationContext),
37
+ )
38
+ }
39
+
40
+ override fun unsubscribeFromNotifications(promise: Promise) {
41
+ ppg.unregisterSubscriber()
42
+
43
+ promise.resolve(null)
44
+ }
45
+
46
+ override fun sendBeacon(
47
+ beacon: ReadableMap,
48
+ promise: Promise,
49
+ ) {
50
+ PushNotificationsBeaconTranslator.translate(beacon).send()
51
+
52
+ promise.resolve(null)
53
+ }
54
+ }
@@ -0,0 +1,36 @@
1
+ package com.pushpushgo.bridge.reactnative.push
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
+
9
+ class PushNotificationsPackage : BaseReactPackage() {
10
+ override fun getModule(
11
+ name: String,
12
+ reactContext: ReactApplicationContext,
13
+ ): NativeModule? {
14
+ if (name == PushNotificationsModule.NAME) {
15
+ return PushNotificationsModule(reactContext)
16
+ }
17
+
18
+ return null
19
+ }
20
+
21
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
22
+ ReactModuleInfoProvider {
23
+ mapOf(
24
+ PushNotificationsModule.NAME to
25
+ ReactModuleInfo(
26
+ name = PushNotificationsModule.NAME,
27
+ className = PushNotificationsModule.NAME,
28
+ canOverrideExistingModule = false,
29
+ needsEagerInit = false,
30
+ hasConstants = false,
31
+ isCxxModule = false,
32
+ isTurboModule = true,
33
+ ),
34
+ )
35
+ }
36
+ }
@@ -0,0 +1,80 @@
1
+ import Foundation
2
+ import PPG_framework
3
+
4
+ class PushNotificationsBeaconTranslator {
5
+ private static func translateSelectors(selectors: NSDictionary, beacon: Beacon) -> Void {
6
+ for (key, value) in selectors {
7
+ guard let keyString = key as? String else { continue }
8
+
9
+ if let stringValue = value as? String {
10
+ beacon.addSelector(keyString, stringValue)
11
+ continue
12
+ }
13
+
14
+ if let numberValue = value as? NSNumber {
15
+ let type = CFNumberGetType(numberValue)
16
+
17
+ if (type == .charType) {
18
+ beacon.addSelector(keyString, numberValue.boolValue)
19
+ } else {
20
+ beacon.addSelector(keyString, numberValue.floatValue)
21
+ }
22
+ }
23
+ }
24
+ }
25
+
26
+ private static func translateTag(rawTag: [String: Any]) -> BeaconTag? {
27
+ guard let tag = rawTag["tag"] as? String,
28
+ let label = rawTag["label"] as? String,
29
+ let _strategy = rawTag["strategy"] as? String,
30
+ let ttl = rawTag["ttl"] as? Int64 else { return nil }
31
+
32
+ let strategy: BeaconTagStrategy = _strategy == "rewrite" ? .rewrite : .append;
33
+
34
+ return BeaconTag(
35
+ tag: tag,
36
+ label: label,
37
+ strategy: strategy,
38
+ ttl: ttl
39
+ )
40
+ }
41
+
42
+ private static func translateTags(rawTags: NSArray, beacon: Beacon) -> Void {
43
+ for _rawTag in rawTags {
44
+ guard let rawTag = _rawTag as? [String: Any] else { continue }
45
+ guard let tag = translateTag(rawTag: rawTag) else { continue }
46
+
47
+ beacon.addTag(tag)
48
+ }
49
+ }
50
+
51
+ private static func translateTagsToDelete(rawTags: NSArray, beacon: Beacon) -> Void {
52
+ for _rawTag in rawTags {
53
+ guard let rawTag = _rawTag as? [String: Any] else { continue }
54
+ guard let tag = translateTag(rawTag: rawTag) else { continue }
55
+
56
+ beacon.addTagToDelete(tag)
57
+ }
58
+ }
59
+
60
+ static func translate(
61
+ selectors: NSDictionary,
62
+ tags: NSArray,
63
+ tagsToDelete: NSArray,
64
+ customId: NSString?,
65
+ assignToGroup: NSString?,
66
+ unassignFromGroup: NSString?
67
+ ) -> Beacon {
68
+ let beacon = Beacon()
69
+
70
+ translateSelectors(selectors: selectors, beacon: beacon)
71
+ translateTags(rawTags: tags, beacon: beacon)
72
+ translateTagsToDelete(rawTags: tagsToDelete, beacon: beacon)
73
+
74
+ beacon.customId = customId as? String ?? "";
75
+ beacon.assignToGroup = assignToGroup as? String
76
+ beacon.unassignFromGroup = unassignFromGroup as? String
77
+
78
+ return beacon
79
+ }
80
+ }
@@ -0,0 +1,10 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <PushNotificationsSpec/PushNotificationsSpec.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface PushNotificationsModule : NSObject<NativePushNotificationsSpec>
7
+
8
+ @end
9
+
10
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,53 @@
1
+ #import "PushNotificationsModule.h"
2
+ #import "PushPushGoRNPush-Swift.h"
3
+
4
+ static NSString* const MODULE_NAME = @"PushPushGoPushNotifications";
5
+
6
+ @implementation PushNotificationsModule {
7
+ PushPushGoModuleDelegate *delegate;
8
+ }
9
+
10
+ - (instancetype)init {
11
+ if (self = [super init]) {
12
+ delegate = [PushPushGoModuleDelegate new];
13
+ }
14
+
15
+ return self;
16
+ }
17
+
18
+ + (NSString *)moduleName {
19
+ return MODULE_NAME;
20
+ }
21
+
22
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
23
+ return std::make_shared<facebook::react::NativePushNotificationsSpecJSI>(params);
24
+ }
25
+
26
+ - (void)getSubscriberId:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
27
+ NSString* subscriberId = [delegate getSubscriberId];
28
+
29
+ resolve(subscriberId);
30
+ }
31
+
32
+ - (void)sendBeacon:(JS::NativePushNotifications::SpecBeacon &)beacon resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
33
+ NSDictionary *selectors = (NSDictionary*) beacon.selectors();
34
+ NSArray *tags = (NSArray*) beacon.tags();
35
+ NSArray *tagsToDelete = (NSArray*) beacon.tagsToDelete();
36
+ NSString *customId = (NSString*) beacon.customId();
37
+ NSString *assignToGroup = (NSString*) beacon.assignToGroup();
38
+ NSString *unassignFromGroup = (NSString*) beacon.unassignFromGroup();
39
+
40
+ [delegate sendBeaconWithSelectors:selectors tags:tags tagsToDelete:tagsToDelete customId:customId assignToGroup:assignToGroup unassignFromGroup:unassignFromGroup resolve:resolve reject:reject];
41
+ }
42
+
43
+ - (void)subscribeToNotifications:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
44
+ UIApplication *application = [UIApplication sharedApplication];
45
+
46
+ [delegate subscribeToNotificationsWithApplication:application resolve:resolve reject:reject];
47
+ }
48
+
49
+ - (void)unsubscribeFromNotifications:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
50
+ [delegate unsubscribeFromNotificationsWithResolve:resolve reject:reject];
51
+ }
52
+
53
+ @end
@@ -0,0 +1,68 @@
1
+ import Foundation
2
+ import PPG_framework
3
+ import React
4
+
5
+ @objc(PushPushGoModuleDelegate)
6
+ public class PushNotificationsModuleDelegate: NSObject {
7
+ @objc public func getSubscriberId() -> String? {
8
+ return PPG.subscriberId.isEmpty ? nil : PPG.subscriberId;
9
+ }
10
+
11
+ @objc public func subscribeToNotifications(
12
+ application: UIApplication,
13
+ resolve: @escaping RCTPromiseResolveBlock,
14
+ reject: @escaping RCTPromiseRejectBlock
15
+ ) -> Void {
16
+ PPG.registerForNotifications(application: application) { result in
17
+ switch result {
18
+ case .success:
19
+ resolve(nil)
20
+ case .error(let error):
21
+ reject(nil, "Cannot subscribe to notifications: " + error, nil)
22
+ }
23
+ }
24
+ }
25
+
26
+ @objc public func unsubscribeFromNotifications(
27
+ resolve: @escaping RCTPromiseResolveBlock,
28
+ reject: @escaping RCTPromiseRejectBlock
29
+ ) -> Void {
30
+ PPG.unsubscribeUser() { result in
31
+ switch result {
32
+ case .success:
33
+ resolve(nil)
34
+ case .error(let error):
35
+ reject(nil, "Cannot unregister from notifications: " + error, nil)
36
+ }
37
+ }
38
+ }
39
+
40
+ @objc public func sendBeacon(
41
+ selectors: NSDictionary,
42
+ tags: NSArray,
43
+ tagsToDelete: NSArray,
44
+ customId: NSString?,
45
+ assignToGroup: NSString?,
46
+ unassignFromGroup: NSString?,
47
+ resolve: @escaping RCTPromiseResolveBlock,
48
+ reject: @escaping RCTPromiseRejectBlock
49
+ ) {
50
+ let beacon = PushNotificationsBeaconTranslator.translate(
51
+ selectors: selectors,
52
+ tags: tags,
53
+ tagsToDelete: tagsToDelete,
54
+ customId: customId,
55
+ assignToGroup: assignToGroup,
56
+ unassignFromGroup: unassignFromGroup
57
+ )
58
+
59
+ PPG.sendBeacon(beacon) { result in
60
+ switch(result) {
61
+ case .success:
62
+ resolve(nil)
63
+ case .error(let error):
64
+ reject(nil, "Cannot send beacon: " + error, nil)
65
+ }
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,35 @@
1
+ import Foundation
2
+ import PPG_framework
3
+
4
+ public class PushNotificationsRN {
5
+ public static func initialize(
6
+ projectId: String,
7
+ apiKey: String,
8
+ appGroupId: String
9
+ ) {
10
+ PPG.initializeNotifications(
11
+ projectId: projectId,
12
+ apiToken: apiKey,
13
+ appGroupId: appGroupId
14
+ )
15
+
16
+ UNUserNotificationCenter.current().delegate = PPG.shared
17
+ }
18
+
19
+ public static func applicationDidBecomeActive() {
20
+ PPG.sendEventsDataToApi()
21
+ }
22
+
23
+ public static func applicationDidRegisterForRemoteNotificationsWithDeviceToken(deviceToken: Data) {
24
+ PPG.sendDeviceToken(deviceToken) { _ in }
25
+ }
26
+
27
+ public static func applicationDidReceiveRemoteNotification(
28
+ userInfo: [AnyHashable : Any],
29
+ fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
30
+ ) {
31
+ PPG.registerNotificationDeliveredFromUserInfo(userInfo: userInfo) { _ in
32
+ completionHandler(.newData)
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ class BeaconBuilder {
4
+ selectors = new Map();
5
+ tags = [];
6
+ tagsToDelete = [];
7
+ customId = null;
8
+ _assignToGroup = null;
9
+ _unassignFromGroup = null;
10
+ set(key, value) {
11
+ this.selectors.set(key, value);
12
+ return this;
13
+ }
14
+ appendTag(tag) {
15
+ this.tags.push(tag);
16
+ return this;
17
+ }
18
+ removeTag(tag) {
19
+ this.tagsToDelete.push(tag);
20
+ return this;
21
+ }
22
+ setCustomId(id) {
23
+ this.customId = id;
24
+ return this;
25
+ }
26
+ assignToGroup(groupId) {
27
+ this._assignToGroup = groupId;
28
+ return this;
29
+ }
30
+ unassignFromGroup(groupId) {
31
+ this._unassignFromGroup = groupId;
32
+ return this;
33
+ }
34
+ build() {
35
+ return new Beacon(this.selectors, this.tags, this.tagsToDelete, this.customId, this._assignToGroup, this._unassignFromGroup);
36
+ }
37
+ }
38
+ export class Beacon {
39
+ constructor(selectors, tags, tagsToDelete, customId, assignToGroup, unassignFromGroup) {
40
+ this.selectors = selectors;
41
+ this.tags = tags;
42
+ this.tagsToDelete = tagsToDelete;
43
+ this.customId = customId;
44
+ this.assignToGroup = assignToGroup;
45
+ this.unassignFromGroup = unassignFromGroup;
46
+ }
47
+ static builder() {
48
+ return new BeaconBuilder();
49
+ }
50
+ }
51
+ //# sourceMappingURL=Beacon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BeaconBuilder","selectors","Map","tags","tagsToDelete","customId","_assignToGroup","_unassignFromGroup","set","key","value","appendTag","tag","push","removeTag","setCustomId","id","assignToGroup","groupId","unassignFromGroup","build","Beacon","constructor","builder"],"sourceRoot":"../../../src","sources":["beacon/Beacon.ts"],"mappings":";;AAcA,MAAMA,aAAa,CAAC;EACVC,SAAS,GAAG,IAAIC,GAAG,CAAyC,CAAC;EAC7DC,IAAI,GAAgB,EAAE;EACtBC,YAAY,GAAgB,EAAE;EAC9BC,QAAQ,GAAkB,IAAI;EAC9BC,cAAc,GAAkB,IAAI;EACpCC,kBAAkB,GAAkB,IAAI;EAEhDC,GAAGA,CAACC,GAAsB,EAAEC,KAA0B,E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AO,IAAIvB,aAAa,CAAC,CAAC;EAC5B;AACF","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ export let BeaconTagStrategy = /*#__PURE__*/function (BeaconTagStrategy) {
4
+ BeaconTagStrategy["APPEND"] = "append";
5
+ BeaconTagStrategy["REWRITE"] = "rewrite";
6
+ return BeaconTagStrategy;
7
+ }({});
8
+ export class BeaconTag {
9
+ constructor({
10
+ tag,
11
+ label = 'default',
12
+ strategy = BeaconTagStrategy.APPEND,
13
+ ttl = 0
14
+ }) {
15
+ this.tag = tag;
16
+ this.label = label;
17
+ this.strategy = strategy;
18
+ this.ttl = ttl;
19
+ }
20
+ static fromTag(tag) {
21
+ return new BeaconTag({
22
+ tag
23
+ });
24
+ }
25
+ static fromTagAndLabel(tag, label) {
26
+ return new BeaconTag({
27
+ tag,
28
+ label
29
+ });
30
+ }
31
+ }
32
+ //# sourceMappingURL=BeaconTag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BeaconTagStrategy","BeaconTag","constructor","tag","label","strategy","APPEND","ttl","fromTag","fromTagAndLabel"],"sourceRoot":"../../../src","sources":["beacon/BeaconTag.ts"],"mappings":";;AAAA,WAAYA,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA;AA0B7B,OAAO,MAAMC,SAAS,CAAuB;EAM3CC,WAAWA,CAAC;IACVC,GAAG;IACHC,KAAK,GAAG,SAAS;IACjBC,QAAQ,GAAGL,iBAAiB,CAACM,MAAM;IACnCC,GAAG,GAAG;EACS,CAAC,EAAE;IAClB,IAAI,CAACJ,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACE,GAAG,GAAGA,GAAG;EAChB;EAEA,OAAOC,OAAOA,CAACL,GAAW,EAAa;IACrC,OAAO,IAAIF,SAAS,CAAC;MAAEE;IAAI,CAAC,CAAC;EAC/B;EAEA,OAAOM,eAAeA,CAACN,GAAW,EAAEC,KAAa,EAAE;IACjD,OAAO,IAAIH,SAAS,CAAC;MAAEE,GAAG;MAAEC;IAAM,CAAC,CAAC;EACtC;AACF","ignoreList":[]}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ import { PermissionsAndroid, Platform } from 'react-native';
4
+ import NativePushNotifications from "./specs/NativePushNotifications.js";
5
+ export const PushNotifications = {
6
+ getSubscriberId: async () => {
7
+ return await NativePushNotifications.getSubscriberId();
8
+ },
9
+ subscribeToNotifications: async () => {
10
+ if (Platform.OS === 'android' && Platform.Version >= 33) {
11
+ const hasNotificationsPermission = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
12
+ if (!hasNotificationsPermission) {
13
+ const hasGrantedNotificationsPermission = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
14
+ if (!hasGrantedNotificationsPermission) {
15
+ throw new Error('Cannot subscribe to notifications: no permission');
16
+ }
17
+ }
18
+ }
19
+ return await NativePushNotifications.subscribeToNotifications();
20
+ },
21
+ unsubscribeFromNotifications: async () => {
22
+ await NativePushNotifications.unsubscribeFromNotifications();
23
+ },
24
+ sendBeacon: async beacon => {
25
+ await NativePushNotifications.sendBeacon({
26
+ selectors: Object.fromEntries(beacon.selectors.entries()),
27
+ tags: beacon.tags,
28
+ tagsToDelete: beacon.tagsToDelete,
29
+ customId: beacon.customId,
30
+ assignToGroup: beacon.assignToGroup,
31
+ unassignFromGroup: beacon.unassignFromGroup
32
+ });
33
+ }
34
+ };
35
+ export { Beacon } from "./beacon/Beacon.js";
36
+ export { BeaconTag, BeaconTagStrategy } from "./beacon/BeaconTag.js";
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PermissionsAndroid","Platform","NativePushNotifications","PushNotifications","getSubscriberId","subscribeToNotifications","OS","Version","hasNotificationsPermission","check","PERMISSIONS","POST_NOTIFICATIONS","hasGrantedNotificationsPermission","request","Error","unsubscribeFromNotifications","sendBeacon","beacon","selectors","Object","fromEntries","entries","tags","tagsToDelete","customId","assignToGroup","unassignFromGroup","Beacon","BeaconTag","BeaconTagStrategy"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAE3D,OAAOC,uBAAuB,MAAM,oCAAiC;AAWrE,OAAO,MAAMC,iBAAqC,GAAG;EACnDC,eAAe,EAAE,MAAAA,CAAA,KAAY;IAC3B,OAAO,MAAMF,uBAAuB,CAACE,eAAe,CAAC,CAAC;EACxD,CAAC;EAEDC,wBAAwB,EAAE,MAAAA,CAAA,KAAY;IACpC,IAAIJ,QAAQ,CAACK,EAAE,KAAK,SAAS,IAAIL,QAAQ,CAACM,OAAO,IAAI,EAAE,EAAE;MACvD,MAAMC,0BAA0B,GAAG,MAAMR,kBAAkB,CAACS,KAAK,CAC/DT,kBAAkB,CAACU,WAAW,CAACC,kBACjC,CAAC;MAED,IAAI,CAACH,0BAA0B,EAAE;QAC/B,MAAMI,iCAAiC,GACrC,MAAMZ,kBAAkB,CAACa,OAAO,CAC9Bb,kBAAkB,CAACU,WAAW,CAACC,kBACjC,CAAC;QAEH,IAAI,CAACC,iCAAiC,EAAE;UACtC,MAAM,IAAIE,KAAK,CAAC,kDAAkD,CAAC;QACrE;MACF;IACF;IAEA,OAAO,MAAMZ,uBAAuB,CAACG,wBAAwB,CAAC,CAAC;EACjE,CAAC;EAEDU,4BAA4B,EAAE,MAAAA,CAAA,KAAY;IACxC,MAAMb,uBAAuB,CAACa,4BAA4B,CAAC,CAAC;EAC9D,CAAC;EAEDC,UAAU,EAAE,MAAOC,MAAM,IAAK;IAC5B,MAAMf,uBAAuB,CAACc,UAAU,CAAC;MACvCE,SAAS,EAAEC,MAAM,CAACC,WAAW,CAACH,MAAM,CAACC,SAAS,CAACG,OAAO,CAAC,CAAC,CAAC;MACzDC,IAAI,EAAEL,MAAM,CAACK,IAAI;MACjBC,YAAY,EAAEN,MAAM,CAACM,YAAY;MACjCC,QAAQ,EAAEP,MAAM,CAACO,QAAQ;MACzBC,aAAa,EAAER,MAAM,CAACQ,aAAa;MACnCC,iBAAiB,EAAET,MAAM,CAACS;IAC5B,CAAC,CAAC;EACJ;AACF,CAAC;AAED,SACEC,MAAM,QAGD,oBAAiB;AAExB,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,uBAAoB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('PushPushGoPushNotifications');
5
+ //# sourceMappingURL=NativePushNotifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../src","sources":["specs/NativePushNotifications.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAAQ,cAAc;AAsBlD,eAAeA,mBAAmB,CAACC,YAAY,CAC7C,6BACF,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,38 @@
1
+ import type { BeaconTag } from './BeaconTag';
2
+ export type BeaconSelectorKey = string;
3
+ export type BeaconSelectorValue = string | number | boolean;
4
+ export interface IBeacon {
5
+ selectors: Map<BeaconSelectorKey, BeaconSelectorValue>;
6
+ tags: BeaconTag[];
7
+ tagsToDelete: BeaconTag[];
8
+ customId: string | null;
9
+ assignToGroup: string | null;
10
+ unassignFromGroup: string | null;
11
+ }
12
+ declare class BeaconBuilder {
13
+ private selectors;
14
+ private tags;
15
+ private tagsToDelete;
16
+ private customId;
17
+ private _assignToGroup;
18
+ private _unassignFromGroup;
19
+ set(key: BeaconSelectorKey, value: BeaconSelectorValue): BeaconBuilder;
20
+ appendTag(tag: BeaconTag): BeaconBuilder;
21
+ removeTag(tag: BeaconTag): BeaconBuilder;
22
+ setCustomId(id: string | null): BeaconBuilder;
23
+ assignToGroup(groupId: string): BeaconBuilder;
24
+ unassignFromGroup(groupId: string): BeaconBuilder;
25
+ build(): Beacon;
26
+ }
27
+ export declare class Beacon implements IBeacon {
28
+ readonly selectors: Map<BeaconSelectorKey, BeaconSelectorValue>;
29
+ readonly tags: BeaconTag[];
30
+ readonly tagsToDelete: BeaconTag[];
31
+ readonly customId: string | null;
32
+ readonly assignToGroup: string | null;
33
+ readonly unassignFromGroup: string | null;
34
+ constructor(selectors: Map<BeaconSelectorKey, BeaconSelectorValue>, tags: BeaconTag[], tagsToDelete: BeaconTag[], customId: string | null, assignToGroup: string | null, unassignFromGroup: string | null);
35
+ static builder(): BeaconBuilder;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=Beacon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Beacon.d.ts","sourceRoot":"","sources":["../../../../src/beacon/Beacon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACvC,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;IACvD,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,cAAM,aAAa;IACjB,OAAO,CAAC,SAAS,CAAqD;IACtE,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,QAAQ,CAAuB;IACvC,O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 interface IBeaconTagProps {
12
+ /** Tag name */
13
+ tag: string;
14
+ /** Optional tag label */
15
+ label?: string;
16
+ /** Strategy dictating whether the tags assigned to the given label should be accumulated (APPEND) or overwritten (REWRITE) */
17
+ strategy?: BeaconTagStrategy;
18
+ /** Time-to-live for the tag in seconds (0 means no expiration) */
19
+ ttl?: number;
20
+ }
21
+ export declare class BeaconTag implements IBeaconTag {
22
+ readonly tag: string;
23
+ readonly label: string;
24
+ readonly strategy: BeaconTagStrategy;
25
+ readonly ttl: number;
26
+ constructor({ tag, label, strategy, ttl, }: IBeaconTagProps);
27
+ static fromTag(tag: string): BeaconTag;
28
+ static fromTagAndLabel(tag: string, label: string): BeaconTag;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=BeaconTag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BeaconTag.d.ts","sourceRoot":"","sources":["../../../../src/beacon/BeaconTag.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,eAAe;IACvB,eAAe;IACf,GAAG,EAAE,MAAM,CAAC;IAEZ,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,8HAA8H;IAC9H,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAE7B,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,SAAU,YAAW,UAAU;IAC1C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,EACV,GAAG,EACH,KAAiB,EACjB,QAAmC,EACnC,GAAO,GACR,EAAE,eAAe;IAOlB,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IAItC,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAGlD"}
@@ -0,0 +1,12 @@
1
+ import type { Beacon } from './beacon/Beacon';
2
+ export type SubscriberId = string;
3
+ export interface IPushNotifications {
4
+ getSubscriberId: () => Promise<SubscriberId | null>;
5
+ subscribeToNotifications: () => Promise<SubscriberId>;
6
+ unsubscribeFromNotifications: () => Promise<void>;
7
+ sendBeacon: (beacon: Beacon) => Promise<void>;
8
+ }
9
+ export declare const PushNotifications: IPushNotifications;
10
+ export { Beacon, type BeaconSelectorKey, type BeaconSelectorValue, } from './beacon/Beacon';
11
+ export { BeaconTag, BeaconTagStrategy } from './beacon/BeaconTag';
12
+ //# sourceMappingURL=index.d.ts.map