@binoban/react-native 1.0.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.
- package/BinobanReactNative.podspec +23 -0
- package/LICENSE +20 -0
- package/README.md +228 -0
- package/android/build.gradle +77 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/binoban/sdk/reactNative/BinobanReactNativeModule.kt +248 -0
- package/android/src/main/java/io/binoban/sdk/reactNative/BinobanReactNativePackage.kt +32 -0
- package/android/src/main/java/io/binoban/sdk/reactNative/BinobanSafe.kt +22 -0
- package/android/src/main/java/io/binoban/sdk/reactNative/utils.kt +87 -0
- package/ios/BinobanReactNative.h +7 -0
- package/ios/BinobanReactNative.mm +244 -0
- package/lib/module/NativeBinobanReactNative.js +18 -0
- package/lib/module/NativeBinobanReactNative.js.map +1 -0
- package/lib/module/binobanClient.js +143 -0
- package/lib/module/binobanClient.js.map +1 -0
- package/lib/module/constants.js +31 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +94 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeBinobanReactNative.d.ts +101 -0
- package/lib/typescript/src/NativeBinobanReactNative.d.ts.map +1 -0
- package/lib/typescript/src/binobanClient.d.ts +30 -0
- package/lib/typescript/src/binobanClient.d.ts.map +1 -0
- package/lib/typescript/src/constants.d.ts +3 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +53 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +173 -0
- package/react-native.config.js +8 -0
- package/src/NativeBinobanReactNative.ts +168 -0
- package/src/binobanClient.ts +199 -0
- package/src/constants.ts +30 -0
- package/src/index.tsx +105 -0
- package/src/types.ts +78 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
package io.binoban.sdk.reactNative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import com.facebook.react.bridge.ReadableType
|
|
6
|
+
import kotlinx.serialization.json.JsonArray
|
|
7
|
+
import kotlinx.serialization.json.JsonNull
|
|
8
|
+
import kotlinx.serialization.json.JsonObject
|
|
9
|
+
import kotlinx.serialization.json.JsonPrimitive
|
|
10
|
+
import kotlinx.serialization.json.buildJsonArray
|
|
11
|
+
import kotlinx.serialization.json.buildJsonObject
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var BINOBAN_PUSH_DEFAULT_ICON = "io.binoban.sdk.reactNative.default_notification_icon"
|
|
15
|
+
var BINOBAN_PUSH_CHANNEL_ID = "io.binoban.sdk.reactNative.push_channel_id"
|
|
16
|
+
var BINOBAN_PUSH_CHANNEL_NAME = "io.binoban.sdk.reactNative.push_channel_name"
|
|
17
|
+
var BINOBAN_PUSH_CHANNEL_DESCRIPTION = "io.binoban.sdk.reactNative.push_channel_description"
|
|
18
|
+
|
|
19
|
+
fun ReadableMap.toJsonObject(): JsonObject {
|
|
20
|
+
return buildJsonObject {
|
|
21
|
+
val iterator = this@toJsonObject.keySetIterator()
|
|
22
|
+
while (iterator.hasNextKey()) {
|
|
23
|
+
val key = iterator.nextKey()
|
|
24
|
+
when (this@toJsonObject.getType(key)) {
|
|
25
|
+
ReadableType.Null -> put(key, JsonNull)
|
|
26
|
+
|
|
27
|
+
ReadableType.Boolean -> put(key, JsonPrimitive(getBoolean(key)))
|
|
28
|
+
|
|
29
|
+
ReadableType.Number -> {
|
|
30
|
+
// RN numbers are Double by default
|
|
31
|
+
val number = getDouble(key)
|
|
32
|
+
// Optional: preserve int if possible
|
|
33
|
+
if (number % 1 == 0.0) {
|
|
34
|
+
put(key, JsonPrimitive(number.toLong()))
|
|
35
|
+
} else {
|
|
36
|
+
put(key, JsonPrimitive(number))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ReadableType.String -> put(key, JsonPrimitive(getString(key)))
|
|
41
|
+
|
|
42
|
+
ReadableType.Map -> {
|
|
43
|
+
val map = getMap(key)
|
|
44
|
+
put(key, map?.toJsonObject() ?: JsonNull)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ReadableType.Array -> {
|
|
48
|
+
val array = getArray(key)
|
|
49
|
+
put(key, array?.toJsonArray() ?: JsonNull)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fun ReadableArray.toJsonArray(): JsonArray {
|
|
57
|
+
return buildJsonArray {
|
|
58
|
+
for (i in 0 until size()) {
|
|
59
|
+
when (getType(i)) {
|
|
60
|
+
ReadableType.Null -> add(JsonNull)
|
|
61
|
+
|
|
62
|
+
ReadableType.Boolean -> add(JsonPrimitive(getBoolean(i)))
|
|
63
|
+
|
|
64
|
+
ReadableType.Number -> {
|
|
65
|
+
val number = getDouble(i)
|
|
66
|
+
if (number % 1 == 0.0) {
|
|
67
|
+
add(JsonPrimitive(number.toLong()))
|
|
68
|
+
} else {
|
|
69
|
+
add(JsonPrimitive(number))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
ReadableType.String -> add(JsonPrimitive(getString(i)))
|
|
74
|
+
|
|
75
|
+
ReadableType.Map -> {
|
|
76
|
+
val map = getMap(i)
|
|
77
|
+
add(map?.toJsonObject() ?: JsonNull)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ReadableType.Array -> {
|
|
81
|
+
val array = getArray(i)
|
|
82
|
+
add(array?.toJsonArray() ?: JsonNull)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#import <BinobanReactNativeSpec/BinobanReactNativeSpec.h>
|
|
2
|
+
|
|
3
|
+
// Inherits the generated spec base (not NSObject) so it gains
|
|
4
|
+
// -emitOnNotificationInteraction: and the codegen event-emitter wiring.
|
|
5
|
+
@interface BinobanReactNative : NativeBinobanReactNativeSpecBase <NativeBinobanReactNativeSpec>
|
|
6
|
+
|
|
7
|
+
@end
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#import "BinobanReactNative.h"
|
|
2
|
+
#import <binoban/binoban.h>
|
|
3
|
+
|
|
4
|
+
// Internal surface the interaction handler calls back into.
|
|
5
|
+
@interface BinobanReactNative ()
|
|
6
|
+
- (void)handleInteraction:(BinobanNotificationInteraction *)interaction;
|
|
7
|
+
- (void)emitNativeError:(BinobanKotlinThrowable *)t;
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
// Extends the SDK's default handler so backend tracking (via super) is preserved,
|
|
11
|
+
// then forwards the interaction to the RN module for emission to JS.
|
|
12
|
+
@interface BinobanRNInteractionHandler : BinobanDefaultNotificationInteractionHandler
|
|
13
|
+
@property (nonatomic, weak) BinobanReactNative *module;
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation BinobanRNInteractionHandler
|
|
17
|
+
- (void)onNotificationInteractionInteraction:(BinobanNotificationInteraction *)interaction {
|
|
18
|
+
[super onNotificationInteractionInteraction:interaction];
|
|
19
|
+
[self.module handleInteraction:interaction];
|
|
20
|
+
}
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
@implementation BinobanReactNative {
|
|
24
|
+
BinobanBinoban *_binoban;
|
|
25
|
+
BOOL _initialized;
|
|
26
|
+
BOOL _initializing;
|
|
27
|
+
BOOL _debug;
|
|
28
|
+
NSDictionary *_initialInteraction;
|
|
29
|
+
BinobanRNInteractionHandler *_interactionHandler;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (NSNumber *)setup:(JS::NativeBinobanReactNative::InternalConfig &)config {
|
|
33
|
+
if (_initialized || _initializing) return @(NO);
|
|
34
|
+
_initializing = YES;
|
|
35
|
+
@try {
|
|
36
|
+
_debug = config.debug().has_value() ? config.debug().value() : NO;
|
|
37
|
+
|
|
38
|
+
NSString *apiKey = config.apiKey();
|
|
39
|
+
NSString *sourceIdentifier = config.sourceIdentifier();
|
|
40
|
+
NSString *apiHost = config.apiHost();
|
|
41
|
+
BOOL collectDeviceId = config.collectDeviceId().has_value() ? config.collectDeviceId().value() : YES;
|
|
42
|
+
BOOL trackLifecycle = config.trackAppLifecycleEvents().has_value() ? config.trackAppLifecycleEvents().value() : YES;
|
|
43
|
+
BOOL useLifecycleObserver = config.useLifecycleObserver().has_value() ? config.useLifecycleObserver().value() : YES;
|
|
44
|
+
BOOL trackDeepLinks = config.trackDeepLinks().has_value() ? config.trackDeepLinks().value() : YES;
|
|
45
|
+
int32_t flushAt = (int32_t)(config.flushAt().has_value() ? config.flushAt().value() : 20);
|
|
46
|
+
int32_t flushInterval = (int32_t)(config.flushInterval().has_value() ? config.flushInterval().value() : 30);
|
|
47
|
+
BOOL autoAddSegmentDestination = config.autoAddSegmentDestination().has_value() ? config.autoAddSegmentDestination().value() : YES;
|
|
48
|
+
BOOL disableTelemetry = config.disableTelemetry().has_value() ? config.disableTelemetry().value() : NO;
|
|
49
|
+
NSString *telemetryHost = config.telemetryHost();
|
|
50
|
+
|
|
51
|
+
// Upload resilience tunables (sdk 1.0.0). Fall back to KMP defaults when absent.
|
|
52
|
+
int32_t uploadMaxRetries = (int32_t)(config.uploadMaxRetries().has_value() ? config.uploadMaxRetries().value() : 3);
|
|
53
|
+
int64_t backoffBaseMillis = (int64_t)(config.backoffBaseMillis().has_value() ? config.backoffBaseMillis().value() : 1000);
|
|
54
|
+
double backoffFactor = config.backoffFactor().has_value() ? config.backoffFactor().value() : 2.0;
|
|
55
|
+
int64_t backoffMaxMillis = (int64_t)(config.backoffMaxMillis().has_value() ? config.backoffMaxMillis().value() : 60000);
|
|
56
|
+
int32_t maxFilesPerFlush = (int32_t)(config.maxFilesPerFlush().has_value() ? config.maxFilesPerFlush().value() : 20);
|
|
57
|
+
|
|
58
|
+
__weak BinobanReactNative *weakSelf = self;
|
|
59
|
+
_binoban = [[BinobanFactory shared] createApiKey:apiKey
|
|
60
|
+
sourceIdentifier:sourceIdentifier
|
|
61
|
+
configs:^(BinobanConfiguration *c) {
|
|
62
|
+
// Route the KMP SDK's internal errors to JS (createClient's onError).
|
|
63
|
+
c.errorHandler = ^(BinobanKotlinThrowable *t) { [weakSelf emitNativeError:t]; };
|
|
64
|
+
c.apiHost = apiHost;
|
|
65
|
+
c.collectDeviceId = collectDeviceId;
|
|
66
|
+
c.trackApplicationLifecycleEvents = trackLifecycle;
|
|
67
|
+
c.useLifecycleObserver = useLifecycleObserver;
|
|
68
|
+
c.trackDeepLinks = trackDeepLinks;
|
|
69
|
+
c.flushAt = flushAt;
|
|
70
|
+
c.flushInterval = flushInterval;
|
|
71
|
+
c.autoAddSegmentDestination = autoAddSegmentDestination;
|
|
72
|
+
c.disableTelemetry = disableTelemetry;
|
|
73
|
+
if (telemetryHost.length > 0) {
|
|
74
|
+
c.telemetryHost = telemetryHost;
|
|
75
|
+
}
|
|
76
|
+
c.uploadMaxRetries = uploadMaxRetries;
|
|
77
|
+
c.backoffBaseMillis = backoffBaseMillis;
|
|
78
|
+
c.backoffFactor = backoffFactor;
|
|
79
|
+
c.backoffMaxMillis = backoffMaxMillis;
|
|
80
|
+
c.maxFilesPerFlush = maxFilesPerFlush;
|
|
81
|
+
}];
|
|
82
|
+
|
|
83
|
+
[BinobanBinobanCompanion shared].debugLogsEnabled = _debug;
|
|
84
|
+
|
|
85
|
+
// Install the interaction handler that preserves default tracking and forwards to JS.
|
|
86
|
+
BinobanRNInteractionHandler *handler = [BinobanRNInteractionHandler new];
|
|
87
|
+
handler.module = self;
|
|
88
|
+
[[BinobanNotificationInteractionManager shared] setHandlerHandler:handler];
|
|
89
|
+
_interactionHandler = handler;
|
|
90
|
+
|
|
91
|
+
_initialized = YES;
|
|
92
|
+
_initializing = NO;
|
|
93
|
+
return @(YES);
|
|
94
|
+
} @catch (NSException *e) {
|
|
95
|
+
if (_debug) NSLog(@"[binoban] setup failed: %@", e);
|
|
96
|
+
_initializing = NO;
|
|
97
|
+
return @(NO);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (void)track:(NSString *)eventName properties:(NSDictionary *)properties {
|
|
102
|
+
@try {
|
|
103
|
+
if (!_binoban || !eventName) return;
|
|
104
|
+
[_binoban trackName:eventName properties:properties ?: @{} enrichment:nil];
|
|
105
|
+
} @catch (NSException *e) { if (_debug) NSLog(@"[binoban] track failed: %@", e); }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
- (void)identify:(NSString *)userId userTraits:(NSDictionary *)userTraits {
|
|
109
|
+
@try {
|
|
110
|
+
if (!_binoban || !userId) return;
|
|
111
|
+
[_binoban identifyUserId:userId traits:userTraits ?: @{} enrichment:nil];
|
|
112
|
+
} @catch (NSException *e) { if (_debug) NSLog(@"[binoban] identify failed: %@", e); }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)flush {
|
|
116
|
+
@try { if (_binoban) [_binoban flush]; }
|
|
117
|
+
@catch (NSException *e) { if (_debug) NSLog(@"[binoban] flush failed: %@", e); }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
- (void)reset {
|
|
121
|
+
@try { if (_binoban) [_binoban reset]; }
|
|
122
|
+
@catch (NSException *e) { if (_debug) NSLog(@"[binoban] reset failed: %@", e); }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (NSString * _Nullable)anonymousId {
|
|
126
|
+
@try { return _binoban ? [_binoban anonymousId] : nil; }
|
|
127
|
+
@catch (NSException *e) { if (_debug) NSLog(@"[binoban] anonymousId failed: %@", e); return nil; }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
- (NSString * _Nullable)userId {
|
|
131
|
+
@try { return _binoban ? [_binoban userId] : nil; }
|
|
132
|
+
@catch (NSException *e) { if (_debug) NSLog(@"[binoban] userId failed: %@", e); return nil; }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
- (NSString * _Nullable)deviceId {
|
|
136
|
+
@try { return _binoban ? [_binoban deviceId] : nil; }
|
|
137
|
+
@catch (NSException *e) { if (_debug) NSLog(@"[binoban] deviceId failed: %@", e); return nil; }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
- (void)notify:(NSDictionary *)payloadData {
|
|
141
|
+
@try {
|
|
142
|
+
if (![payloadData[@"source"] isEqualToString:@"binoban"]) return;
|
|
143
|
+
NSMutableDictionary<NSString *, NSString *> *stringDict = [NSMutableDictionary new];
|
|
144
|
+
[payloadData enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
145
|
+
if ([key isKindOfClass:[NSString class]] && [obj isKindOfClass:[NSString class]]) {
|
|
146
|
+
stringDict[key] = obj;
|
|
147
|
+
}
|
|
148
|
+
}];
|
|
149
|
+
[[BinobanNotification shared] notifyData:stringDict];
|
|
150
|
+
} @catch (NSException *e) { if (_debug) NSLog(@"[binoban] notify failed: %@", e); }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
- (void)setDeviceToken:(NSString *)token {
|
|
154
|
+
@try { if (_binoban) [_binoban setDeviceTokenToken:token]; }
|
|
155
|
+
@catch (NSException *e) { if (_debug) NSLog(@"[binoban] setDeviceToken failed: %@", e); }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
- (void)emitNativeError:(BinobanKotlinThrowable *)t {
|
|
159
|
+
@try {
|
|
160
|
+
NSMutableDictionary *d = [NSMutableDictionary new];
|
|
161
|
+
d[@"message"] = t.message ?: ([t description] ?: @"");
|
|
162
|
+
d[@"name"] = [NSNull null];
|
|
163
|
+
[self emitOnNativeError:d];
|
|
164
|
+
} @catch (NSException *e) {
|
|
165
|
+
if (_debug) NSLog(@"[binoban] emitNativeError failed: %@", e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
- (void)handleInteraction:(BinobanNotificationInteraction *)interaction {
|
|
170
|
+
@try {
|
|
171
|
+
NSDictionary *dict = [self dictFromInteraction:interaction];
|
|
172
|
+
// Buffer for a cold-start pull (consumed by getInitialNotificationInteraction).
|
|
173
|
+
_initialInteraction = dict;
|
|
174
|
+
[self emitOnNotificationInteraction:dict];
|
|
175
|
+
} @catch (NSException *e) {
|
|
176
|
+
if (_debug) NSLog(@"[binoban] handleInteraction failed: %@", e);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
- (NSDictionary *)dictFromInteraction:(BinobanNotificationInteraction *)i {
|
|
181
|
+
NSMutableDictionary *d = [NSMutableDictionary new];
|
|
182
|
+
d[@"notificationUuid"] = i.notificationUuid ?: [NSNull null];
|
|
183
|
+
d[@"type"] = i.type.name ?: [NSNull null];
|
|
184
|
+
d[@"actionId"] = i.actionId ?: [NSNull null];
|
|
185
|
+
d[@"uri"] = i.uri ?: [NSNull null];
|
|
186
|
+
d[@"reason"] = i.reason ?: [NSNull null];
|
|
187
|
+
d[@"customData"] = i.customData ?: [NSNull null];
|
|
188
|
+
return d;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
- (void)getInitialNotificationInteraction:(RCTPromiseResolveBlock)resolve
|
|
192
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
193
|
+
@try {
|
|
194
|
+
NSDictionary *i = _initialInteraction;
|
|
195
|
+
_initialInteraction = nil;
|
|
196
|
+
resolve(i ?: (id)[NSNull null]);
|
|
197
|
+
} @catch (NSException *e) {
|
|
198
|
+
if (_debug) NSLog(@"[binoban] getInitialNotificationInteraction failed: %@", e);
|
|
199
|
+
resolve((id)[NSNull null]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Host forwards its UNUserNotificationCenter callbacks here so the SDK (which never
|
|
204
|
+
// registers its own delegate) can report interactions and delivery.
|
|
205
|
+
- (void)didReceiveNotificationResponse:(NSDictionary *)userInfo
|
|
206
|
+
actionId:(NSString *)actionId
|
|
207
|
+
dismissed:(NSNumber *)dismissed {
|
|
208
|
+
@try {
|
|
209
|
+
[BinobanNotificationForwarding_iosKt onDidReceiveForwardedUserInfo:userInfo
|
|
210
|
+
actionId:actionId
|
|
211
|
+
dismissed:[dismissed boolValue]];
|
|
212
|
+
} @catch (NSException *e) {
|
|
213
|
+
if (_debug) NSLog(@"[binoban] didReceiveNotificationResponse failed: %@", e);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
- (void)willPresentNotification:(NSDictionary *)userInfo {
|
|
218
|
+
@try {
|
|
219
|
+
[BinobanNotificationForwarding_iosKt onWillPresentForwardedUserInfo:userInfo];
|
|
220
|
+
} @catch (NSException *e) {
|
|
221
|
+
if (_debug) NSLog(@"[binoban] willPresentNotification failed: %@", e);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
|
226
|
+
@try {
|
|
227
|
+
[BinobanNotificationForwarding_iosKt onApplicationDidReceiveRemoteNotificationUserInfo:userInfo];
|
|
228
|
+
} @catch (NSException *e) {
|
|
229
|
+
if (_debug) NSLog(@"[binoban] didReceiveRemoteNotification failed: %@", e);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
234
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
235
|
+
{
|
|
236
|
+
return std::make_shared<facebook::react::NativeBinobanReactNativeSpecJSI>(params);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
+ (NSString *)moduleName
|
|
240
|
+
{
|
|
241
|
+
return @"BinobanReactNative";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// backward compatibility
|
|
4
|
+
|
|
5
|
+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
|
|
6
|
+
|
|
7
|
+
// Emitted to JS when the user interacts with a Binoban notification (tap on the
|
|
8
|
+
// body, tap on an action button, dismissal, or a delivery report). Mirrors the KMP
|
|
9
|
+
// `NotificationInteraction` (../kotlin/.../notification/NotificationInteractionHandler.kt).
|
|
10
|
+
|
|
11
|
+
// Emitted to JS when the KMP SDK routes an internal error to its
|
|
12
|
+
// `Configuration.errorHandler` (e.g. a disabled instance from invalid config, or a
|
|
13
|
+
// contained failure at the upload/plugin boundary). Bridged to the `onError`
|
|
14
|
+
// callback passed to `createClient`.
|
|
15
|
+
|
|
16
|
+
const BinobanReactNative = TurboModuleRegistry.get('BinobanReactNative');
|
|
17
|
+
export default BinobanReactNative;
|
|
18
|
+
//# sourceMappingURL=NativeBinobanReactNative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","BinobanReactNative","get"],"sourceRoot":"../../src","sources":["NativeBinobanReactNative.ts"],"mappings":";;AAAA;;AAGA,OAAO,KAAKA,mBAAmB,MAAM,wDAAwD;;AAG7F;AACA;AACA;;AAcA;AACA;AACA;AACA;;AA4IA,MAAMC,kBAAkB,GAAGD,mBAAmB,CAACE,GAAG,CAAO,oBAAoB,CAAC;AAE9E,eAAeD,kBAAkB","ignoreList":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import BinobanReactNative from "./NativeBinobanReactNative.js";
|
|
4
|
+
const noopSubscription = {
|
|
5
|
+
remove: () => {}
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Native event → public shape. customData arrives as an untyped map (UnsafeObject);
|
|
9
|
+
// normalize it to a string→string record and leave nullables as-is.
|
|
10
|
+
const toInteraction = e => ({
|
|
11
|
+
notificationUuid: e.notificationUuid,
|
|
12
|
+
type: e.type,
|
|
13
|
+
actionId: e.actionId ?? null,
|
|
14
|
+
uri: e.uri ?? null,
|
|
15
|
+
customData: e.customData ?? null,
|
|
16
|
+
reason: e.reason ?? null
|
|
17
|
+
});
|
|
18
|
+
export class BinobanClient {
|
|
19
|
+
constructor({
|
|
20
|
+
config,
|
|
21
|
+
onError
|
|
22
|
+
}) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.onError = onError;
|
|
25
|
+
}
|
|
26
|
+
safe(method, fn, fallback) {
|
|
27
|
+
try {
|
|
28
|
+
return fn();
|
|
29
|
+
} catch (e) {
|
|
30
|
+
this.onError?.({
|
|
31
|
+
method,
|
|
32
|
+
message: e instanceof Error ? e.message : String(e),
|
|
33
|
+
cause: e
|
|
34
|
+
});
|
|
35
|
+
if (this.config.debug) {
|
|
36
|
+
console.warn(`[binoban] ${method}() failed`, e);
|
|
37
|
+
}
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async init() {
|
|
42
|
+
return this.safe('init', () => {
|
|
43
|
+
if (!BinobanReactNative) return true;
|
|
44
|
+
// Subscribe before setup() so an error the native SDK reports during
|
|
45
|
+
// initialization (e.g. a disabled instance from invalid config) is caught.
|
|
46
|
+
this.subscribeToNativeErrors();
|
|
47
|
+
return BinobanReactNative.setup(this.config);
|
|
48
|
+
}, false);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Bridge the KMP Configuration.errorHandler to the onError callback. Only wired
|
|
52
|
+
// when an onError was provided — otherwise there is nothing to route errors to.
|
|
53
|
+
subscribeToNativeErrors() {
|
|
54
|
+
if (!BinobanReactNative || !this.onError) return;
|
|
55
|
+
this.safe('subscribeToNativeErrors', () => {
|
|
56
|
+
BinobanReactNative?.onNativeError(e => {
|
|
57
|
+
this.onError?.({
|
|
58
|
+
method: e.name ? `native:${e.name}` : 'native',
|
|
59
|
+
message: e.message
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async track(eventName, properties) {
|
|
65
|
+
this.safe('track', () => {
|
|
66
|
+
if (BinobanReactNative) BinobanReactNative.track(eventName, properties);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async identify(userId, userTraits) {
|
|
70
|
+
this.safe('identify', () => {
|
|
71
|
+
if (BinobanReactNative) BinobanReactNative.identify(userId, userTraits);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async flush() {
|
|
75
|
+
this.safe('flush', () => {
|
|
76
|
+
if (BinobanReactNative) BinobanReactNative.flush();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async reset() {
|
|
80
|
+
this.safe('reset', () => {
|
|
81
|
+
if (BinobanReactNative) BinobanReactNative.reset();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
anonymousId() {
|
|
85
|
+
return this.safe('anonymousId', () => BinobanReactNative?.anonymousId());
|
|
86
|
+
}
|
|
87
|
+
userId() {
|
|
88
|
+
return this.safe('userId', () => BinobanReactNative?.userId());
|
|
89
|
+
}
|
|
90
|
+
deviceId() {
|
|
91
|
+
return this.safe('deviceId', () => BinobanReactNative?.deviceId());
|
|
92
|
+
}
|
|
93
|
+
notify(payloadData) {
|
|
94
|
+
this.safe('notify', () => {
|
|
95
|
+
if (BinobanReactNative) BinobanReactNative.notify(payloadData);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
setDeviceToken(token) {
|
|
99
|
+
this.safe('setDeviceToken', () => {
|
|
100
|
+
if (BinobanReactNative) BinobanReactNative.setDeviceToken(token);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Subscribe to notification interactions (body/action-button taps, dismissals,
|
|
105
|
+
// delivery). Returns a subscription; call remove() to stop listening.
|
|
106
|
+
onNotificationInteraction(listener) {
|
|
107
|
+
return this.safe('onNotificationInteraction', () => {
|
|
108
|
+
if (!BinobanReactNative) return noopSubscription;
|
|
109
|
+
return BinobanReactNative.onNotificationInteraction(e => {
|
|
110
|
+
this.safe('onNotificationInteraction:listener', () => listener(toInteraction(e)));
|
|
111
|
+
});
|
|
112
|
+
}) ?? noopSubscription;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The interaction that cold-started the app (a tap delivered before JS could
|
|
116
|
+
// subscribe), consumed once. Resolves null when there is none.
|
|
117
|
+
async getInitialNotificationInteraction() {
|
|
118
|
+
return this.safe('getInitialNotificationInteraction', async () => {
|
|
119
|
+
const e = await BinobanReactNative?.getInitialNotificationInteraction();
|
|
120
|
+
return e ? toInteraction(e) : null;
|
|
121
|
+
}) ?? Promise.resolve(null);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// iOS only — forward UNUserNotificationCenter callbacks from the host (a native
|
|
125
|
+
// AppDelegate or a JS push library). No-ops on Android, where the SDK's
|
|
126
|
+
// notification trampoline delivers interactions on its own.
|
|
127
|
+
didReceiveNotificationResponse(userInfo, actionId, dismissed) {
|
|
128
|
+
this.safe('didReceiveNotificationResponse', () => {
|
|
129
|
+
BinobanReactNative?.didReceiveNotificationResponse(userInfo, actionId ?? null, dismissed ?? false);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
willPresentNotification(userInfo) {
|
|
133
|
+
this.safe('willPresentNotification', () => {
|
|
134
|
+
BinobanReactNative?.willPresentNotification(userInfo);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
didReceiveRemoteNotification(userInfo) {
|
|
138
|
+
this.safe('didReceiveRemoteNotification', () => {
|
|
139
|
+
BinobanReactNative?.didReceiveRemoteNotification(userInfo);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=binobanClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BinobanReactNative","noopSubscription","remove","toInteraction","e","notificationUuid","type","actionId","uri","customData","reason","BinobanClient","constructor","config","onError","safe","method","fn","fallback","message","Error","String","cause","debug","console","warn","init","subscribeToNativeErrors","setup","onNativeError","name","track","eventName","properties","identify","userId","userTraits","flush","reset","anonymousId","deviceId","notify","payloadData","setDeviceToken","token","onNotificationInteraction","listener","getInitialNotificationInteraction","Promise","resolve","didReceiveNotificationResponse","userInfo","dismissed","willPresentNotification","didReceiveRemoteNotification"],"sourceRoot":"../../src","sources":["binobanClient.ts"],"mappings":";;AAAA,OAAOA,kBAAkB,MAIlB,+BAA4B;AAYnC,MAAMC,gBAAqD,GAAG;EAC5DC,MAAM,EAAEA,CAAA,KAAM,CAAC;AACjB,CAAC;;AAED;AACA;AACA,MAAMC,aAAa,GACjBC,CAA+B,KACF;EAC7BC,gBAAgB,EAAED,CAAC,CAACC,gBAAgB;EACpCC,IAAI,EAAEF,CAAC,CAACE,IAAmC;EAC3CC,QAAQ,EAAEH,CAAC,CAACG,QAAQ,IAAI,IAAI;EAC5BC,GAAG,EAAEJ,CAAC,CAACI,GAAG,IAAI,IAAI;EAClBC,UAAU,EAAGL,CAAC,CAACK,UAAU,IAAsC,IAAI;EACnEC,MAAM,EAAEN,CAAC,CAACM,MAAM,IAAI;AACtB,CAAC,CAAC;AAEF,OAAO,MAAMC,aAAa,CAAC;EAIzBC,WAAWA,CAAC;IACVC,MAAM;IACNC;EAIF,CAAC,EAAE;IACD,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;EAEQC,IAAIA,CAAIC,MAAc,EAAEC,EAAW,EAAEC,QAAY,EAAiB;IACxE,IAAI;MACF,OAAOD,EAAE,CAAC,CAAC;IACb,CAAC,CAAC,OAAOb,CAAC,EAAE;MACV,IAAI,CAACU,OAAO,GAAG;QACbE,MAAM;QACNG,OAAO,EAAEf,CAAC,YAAYgB,KAAK,GAAGhB,CAAC,CAACe,OAAO,GAAGE,MAAM,CAACjB,CAAC,CAAC;QACnDkB,KAAK,EAAElB;MACT,CAAC,CAAC;MACF,IAAI,IAAI,CAACS,MAAM,CAACU,KAAK,EAAE;QACrBC,OAAO,CAACC,IAA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credentials: {
|
|
5
|
+
android: {
|
|
6
|
+
apiKey: '',
|
|
7
|
+
sourceIdentifier: ''
|
|
8
|
+
},
|
|
9
|
+
iOS: {
|
|
10
|
+
apiKey: '',
|
|
11
|
+
sourceIdentifier: ''
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
apiHost: '',
|
|
15
|
+
debug: false,
|
|
16
|
+
collectDeviceId: true,
|
|
17
|
+
trackAppLifecycleEvents: true,
|
|
18
|
+
useLifecycleObserver: true,
|
|
19
|
+
trackDeepLinks: true,
|
|
20
|
+
flushAt: 20,
|
|
21
|
+
flushInterval: 30,
|
|
22
|
+
autoAddSegmentDestination: true,
|
|
23
|
+
disableTelemetry: false,
|
|
24
|
+
telemetryHost: '',
|
|
25
|
+
uploadMaxRetries: 3,
|
|
26
|
+
backoffBaseMillis: 1000,
|
|
27
|
+
backoffFactor: 2.0,
|
|
28
|
+
backoffMaxMillis: 60000,
|
|
29
|
+
maxFilesPerFlush: 20
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultConfig","credentials","android","apiKey","sourceIdentifier","iOS","apiHost","debug","collectDeviceId","trackAppLifecycleEvents","useLifecycleObserver","trackDeepLinks","flushAt","flushInterval","autoAddSegmentDestination","disableTelemetry","telemetryHost","uploadMaxRetries","backoffBaseMillis","backoffFactor","backoffMaxMillis","maxFilesPerFlush"],"sourceRoot":"../../src","sources":["constants.ts"],"mappings":";;AAEA,OAAO,MAAMA,aAAqB,GAAG;EACnCC,WAAW,EAAE;IACXC,OAAO,EAAE;MACPC,MAAM,EAAE,EAAE;MACVC,gBAAgB,EAAE;IACpB,CAAC;IACDC,GAAG,EAAE;MACHF,MAAM,EAAE,EAAE;MACVC,gBAAgB,EAAE;IACpB;EACF,CAAC;EACDE,OAAO,EAAE,EAAE;EACXC,KAAK,EAAE,KAAK;EACZC,eAAe,EAAE,IAAI;EACrBC,uBAAuB,EAAE,IAAI;EAC7BC,oBAAoB,EAAE,IAAI;EAC1BC,cAAc,EAAE,IAAI;EACpBC,OAAO,EAAE,EAAE;EACXC,aAAa,EAAE,EAAE;EACjBC,yBAAyB,EAAE,IAAI;EAC/BC,gBAAgB,EAAE,KAAK;EACvBC,aAAa,EAAE,EAAE;EACjBC,gBAAgB,EAAE,CAAC;EACnBC,iBAAiB,EAAE,IAAI;EACvBC,aAAa,EAAE,GAAG;EAClBC,gBAAgB,EAAE,KAAK;EACvBC,gBAAgB,EAAE;AACpB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext } from 'react';
|
|
4
|
+
import { defaultConfig } from "./constants.js";
|
|
5
|
+
import { BinobanClient } from "./binobanClient.js";
|
|
6
|
+
import { Platform } from 'react-native';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export const createClient = config => {
|
|
9
|
+
const clientConfig = {
|
|
10
|
+
...defaultConfig,
|
|
11
|
+
...config
|
|
12
|
+
};
|
|
13
|
+
const onError = config.onError;
|
|
14
|
+
const platformCreds = Platform.OS === 'android' ? clientConfig.credentials?.android : clientConfig.credentials?.iOS;
|
|
15
|
+
const internalConfig = {
|
|
16
|
+
apiHost: clientConfig.apiHost,
|
|
17
|
+
debug: clientConfig.debug,
|
|
18
|
+
collectDeviceId: clientConfig.collectDeviceId,
|
|
19
|
+
trackAppLifecycleEvents: clientConfig.trackAppLifecycleEvents,
|
|
20
|
+
useLifecycleObserver: clientConfig.useLifecycleObserver,
|
|
21
|
+
trackDeepLinks: clientConfig.trackDeepLinks,
|
|
22
|
+
flushAt: clientConfig.flushAt,
|
|
23
|
+
flushInterval: clientConfig.flushInterval,
|
|
24
|
+
autoAddSegmentDestination: clientConfig.autoAddSegmentDestination,
|
|
25
|
+
disableTelemetry: clientConfig.disableTelemetry,
|
|
26
|
+
telemetryHost: clientConfig.telemetryHost,
|
|
27
|
+
uploadMaxRetries: clientConfig.uploadMaxRetries,
|
|
28
|
+
backoffBaseMillis: clientConfig.backoffBaseMillis,
|
|
29
|
+
backoffFactor: clientConfig.backoffFactor,
|
|
30
|
+
backoffMaxMillis: clientConfig.backoffMaxMillis,
|
|
31
|
+
maxFilesPerFlush: clientConfig.maxFilesPerFlush,
|
|
32
|
+
apiKey: platformCreds?.apiKey ?? '',
|
|
33
|
+
sourceIdentifier: platformCreds?.sourceIdentifier ?? ''
|
|
34
|
+
};
|
|
35
|
+
const client = new BinobanClient({
|
|
36
|
+
config: internalConfig,
|
|
37
|
+
onError
|
|
38
|
+
});
|
|
39
|
+
const credsValid = !!platformCreds?.apiKey && !!platformCreds?.sourceIdentifier;
|
|
40
|
+
if (credsValid) {
|
|
41
|
+
// Fire-and-forget; init() is internally guarded and never throws.
|
|
42
|
+
void client.init();
|
|
43
|
+
} else {
|
|
44
|
+
const message = `Missing Binoban credentials for platform "${Platform.OS}". SDK will be inert.`;
|
|
45
|
+
onError?.({
|
|
46
|
+
method: 'createClient',
|
|
47
|
+
message
|
|
48
|
+
});
|
|
49
|
+
if (clientConfig.debug) {
|
|
50
|
+
console.warn(`[binoban] ${message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return client;
|
|
54
|
+
};
|
|
55
|
+
const Context = /*#__PURE__*/createContext(null);
|
|
56
|
+
export const BinobanProvider = ({
|
|
57
|
+
client,
|
|
58
|
+
children
|
|
59
|
+
}) => {
|
|
60
|
+
if (!client) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
64
|
+
value: client,
|
|
65
|
+
children: children
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
export const useBinoban = () => {
|
|
69
|
+
const client = useContext(Context);
|
|
70
|
+
return React.useMemo(() => {
|
|
71
|
+
if (!client) {
|
|
72
|
+
console.error('Binoban client not configured!', 'To use the useBinoban() hook, pass an initialized Binoban client into the BinobanProvider');
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
track: async (...args) => client?.track(...args),
|
|
76
|
+
identify: async (...args) => client?.identify(...args),
|
|
77
|
+
flush: async () => client?.flush(),
|
|
78
|
+
reset: async () => client?.reset(),
|
|
79
|
+
anonymousId: () => client?.anonymousId(),
|
|
80
|
+
userId: () => client?.userId(),
|
|
81
|
+
deviceId: () => client?.deviceId(),
|
|
82
|
+
notify: (...args) => client?.notify(...args),
|
|
83
|
+
setDeviceToken: token => client?.setDeviceToken(token),
|
|
84
|
+
onNotificationInteraction: listener => client?.onNotificationInteraction(listener) ?? {
|
|
85
|
+
remove: () => {}
|
|
86
|
+
},
|
|
87
|
+
getInitialNotificationInteraction: () => client?.getInitialNotificationInteraction() ?? Promise.resolve(null),
|
|
88
|
+
didReceiveNotificationResponse: (...args) => client?.didReceiveNotificationResponse(...args),
|
|
89
|
+
willPresentNotification: (...args) => client?.willPresentNotification(...args),
|
|
90
|
+
didReceiveRemoteNotification: (...args) => client?.didReceiveRemoteNotification(...args)
|
|
91
|
+
};
|
|
92
|
+
}, [client]);
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","createContext","useContext","defaultConfig","BinobanClient","Platform","jsx","_jsx","createClient","config","clientConfig","onError","platformCreds","OS","credentials","android","iOS","internalConfig","apiHost","debug","collectDeviceId","trackAppLifecycleEvents","useLifecycleObserver","trackDeepLinks","flushAt","flushInterval","autoAddSegmentDestination","disableTelemetry","telemetryHost","uploadMaxRetries","backoffBaseMillis","backoffFactor","backoffMaxMillis","maxFilesPerFlush","apiKey","sourceIdentifier","client","credsValid","init","message","method","console","warn","Context","BinobanProvider","children","Provider","value","useBinoban","useMemo","error","track","args","identify","flush","reset","anonymousId","userId","deviceId","notify","setDeviceToken","token","onNotificationInteraction","listener","remove","getInitialNotificationInteraction","Promise","resolve","didReceiveNotificationResponse","will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