@dashx/react-native 1.1.5 → 1.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.
@@ -60,8 +60,8 @@ class DashXReactNative: RCTEventEmitter {
60
60
  DashX.screen(screenName, withData: data as? [String: Any])
61
61
  }
62
62
 
63
- @objc(fetchRecord:options:resolver:rejecter:)
64
- func fetchRecord(_ urn: String, options: NSDictionary?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
63
+ @objc(fetchRecord:options:resolve:reject:)
64
+ func fetchRecord(_ urn: String, options: NSDictionary?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
65
65
  DashXClient.instance.fetchRecord(
66
66
  urn: urn,
67
67
  preview: options?["preview"] as? Bool,
@@ -77,8 +77,8 @@ class DashXReactNative: RCTEventEmitter {
77
77
  }
78
78
  }
79
79
 
80
- @objc(searchRecords:options:resolver:rejecter:)
81
- func searchRecords(_ resource: String, options: NSDictionary?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
80
+ @objc(searchRecords:options:resolve:reject:)
81
+ func searchRecords(_ resource: String, options: NSDictionary?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
82
82
  DashXClient.instance.searchRecords(
83
83
  resource: resource,
84
84
  filter: options?["filter"] as? [String: Any],
@@ -98,8 +98,8 @@ class DashXReactNative: RCTEventEmitter {
98
98
  }
99
99
  }
100
100
 
101
- @objc(fetchStoredPreferences:rejecter:)
102
- func fetchStoredPreferences(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
101
+ @objc(fetchStoredPreferences:reject:)
102
+ func fetchStoredPreferences(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
103
103
  DashXClient.instance.fetchStoredPreferences { result in
104
104
  switch result {
105
105
  case .success(let prefs): resolve(prefs)
@@ -108,8 +108,8 @@ class DashXReactNative: RCTEventEmitter {
108
108
  }
109
109
  }
110
110
 
111
- @objc(saveStoredPreferences:resolver:rejecter:)
112
- func saveStoredPreferences(_ preferenceData: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
111
+ @objc(saveStoredPreferences:resolve:reject:)
112
+ func saveStoredPreferences(_ preferenceData: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
113
113
  guard let dict = preferenceData as? [String: Any] else {
114
114
  reject("EINVAL", "preferenceData must be a plain object", nil)
115
115
  return
@@ -133,13 +133,21 @@ class DashXReactNative: RCTEventEmitter {
133
133
  }
134
134
 
135
135
  @objc(setLogLevel:)
136
- func setLogLevel(_ level: Int) {
137
- let logLevel = DashXLog.LogLevel(rawValue: level) ?? DashXLog.LogLevel.off
136
+ func setLogLevel(_ level: Double) {
137
+ // JS contract: 0 = off, 1 = errors, 2 = debug
138
+ // Native SDK: off = -1, error = 0, info = 1, debug = 2
139
+ let logLevel: DashXLog.LogLevel
140
+ switch Int(level) {
141
+ case 0: logLevel = .off
142
+ case 1: logLevel = .error
143
+ case 2: logLevel = .debug
144
+ default: logLevel = .off
145
+ }
138
146
  DashXLog.setLogLevel(to: logLevel)
139
147
  }
140
148
 
141
- @objc(uploadAsset:resource:attribute:resolver:rejecter:)
142
- func uploadAsset(_ filePath: String, resource: String, attribute: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
149
+ @objc(uploadAsset:resource:attribute:resolve:reject:)
150
+ func uploadAsset(_ filePath: String, resource: String, attribute: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
143
151
  let fileURL = URL(fileURLWithPath: filePath)
144
152
  DashXClient.instance.uploadAsset(fileURL: fileURL, resource: resource, attribute: attribute) { result in
145
153
  switch result {
@@ -156,8 +164,8 @@ class DashXReactNative: RCTEventEmitter {
156
164
  }
157
165
  }
158
166
 
159
- @objc(fetchAsset:resolver:rejecter:)
160
- func fetchAsset(_ assetId: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
167
+ @objc(fetchAsset:resolve:reject:)
168
+ func fetchAsset(_ assetId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
161
169
  DashXClient.instance.fetchAsset(assetId: assetId) { result in
162
170
  switch result {
163
171
  case .success(let assetResponse):
@@ -217,13 +225,13 @@ class DashXReactNative: RCTEventEmitter {
217
225
  DashX.trackNotificationNavigation(navigationAction, notificationId: notificationId as String?)
218
226
  }
219
227
 
220
- @objc(requestNotificationPermission:rejecter:)
221
- func requestNotificationPermission(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
228
+ @objc(requestNotificationPermission:reject:)
229
+ func requestNotificationPermission(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
222
230
  DashX.requestNotificationPermission { status in resolve(status.rawValue) }
223
231
  }
224
232
 
225
- @objc(getNotificationPermissionStatus:rejecter:)
226
- func getNotificationPermissionStatus(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
233
+ @objc(getNotificationPermissionStatus:reject:)
234
+ func getNotificationPermissionStatus(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
227
235
  DashX.getNotificationPermissionStatus { status in resolve(status.rawValue) }
228
236
  }
229
237
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dashx/react-native",
3
3
  "title": "DashX React Native",
4
- "version": "1.1.5",
4
+ "version": "1.2.0",
5
5
  "description": "DashX SDK for React Native",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
@@ -22,8 +22,17 @@
22
22
  "index.js",
23
23
  "index.d.ts",
24
24
  "ios",
25
+ "src",
25
26
  "README.md"
26
27
  ],
28
+ "codegenConfig": {
29
+ "name": "RNDashXReactNativeSpec",
30
+ "type": "modules",
31
+ "jsSrcsDir": "src",
32
+ "android": {
33
+ "javaPackageName": "com.dashx.rn.sdk"
34
+ }
35
+ },
27
36
  "scripts": {
28
37
  "test": "jest",
29
38
  "lint": "eslint index.js"
@@ -49,7 +58,7 @@
49
58
  },
50
59
  "peerDependencies": {
51
60
  "react": ">=17.0.0",
52
- "react-native": ">=0.71.0"
61
+ "react-native": ">=0.74.0"
53
62
  },
54
63
  "devDependencies": {
55
64
  "@commitlint/config-conventional": "^17.0.2",
@@ -0,0 +1,42 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ configure(options: Object): void;
6
+ identify(options: Object | null): void;
7
+ setIdentity(uid: string | null, token: string | null): void;
8
+ reset(): void;
9
+ track(event: string, data: Object | null): void;
10
+ screen(screenName: string, data: Object | null): void;
11
+ fetchRecord(urn: string, options: Object | null): Promise<Object>;
12
+ searchRecords(resource: string, options: Object | null): Promise<Object[]>;
13
+ fetchStoredPreferences(): Promise<Object>;
14
+ saveStoredPreferences(preferenceData: Object): Promise<Object>;
15
+ subscribe(): void;
16
+ unsubscribe(): void;
17
+ setLogLevel(level: number): void;
18
+ uploadAsset(
19
+ filePath: string,
20
+ resource: string,
21
+ attribute: string
22
+ ): Promise<Object>;
23
+ fetchAsset(assetId: string): Promise<Object>;
24
+ enableLifecycleTracking(): void;
25
+ enableAdTracking(): void;
26
+ processURL(
27
+ url: string,
28
+ source: string | null,
29
+ forwardToLinkHandler: boolean
30
+ ): void;
31
+ trackNotificationNavigation(
32
+ action: Object | null,
33
+ notificationId: string | null
34
+ ): void;
35
+ requestNotificationPermission(): Promise<number>;
36
+ getNotificationPermissionStatus(): Promise<number>;
37
+
38
+ addListener(eventName: string): void;
39
+ removeListeners(count: number): void;
40
+ }
41
+
42
+ export default TurboModuleRegistry.get<Spec>('DashXReactNative');
@@ -1,231 +0,0 @@
1
- package com.dashx.rn.sdk
2
-
3
- import com.dashx.rn.sdk.util.*
4
- import com.dashx.android.DashX
5
- import com.dashx.android.DashXLog
6
- import com.dashx.android.DashXLog.LogLevel
7
- import com.facebook.react.bridge.*
8
- import kotlinx.serialization.decodeFromString
9
- import kotlinx.serialization.encodeToString
10
- import kotlinx.serialization.json.Json
11
- import kotlinx.serialization.json.JsonObject
12
-
13
- class DashXReactNativeModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
14
- private val tag = DashXReactNativeModule::class.java.simpleName
15
-
16
- override fun initialize() {
17
- super.initialize()
18
- MessageReceivedEventHolder.reactContext = reactContext
19
- }
20
-
21
- override fun invalidate() {
22
- MessageReceivedEventHolder.reactContext = null
23
- super.invalidate()
24
- }
25
-
26
- override fun getName(): String {
27
- return "DashXReactNative"
28
- }
29
-
30
- @ReactMethod
31
- fun setLogLevel(level: Int) {
32
- val logLevel = LogLevel.values().firstOrNull { it.code == level } ?: LogLevel.OFF
33
- DashXLog.setLogLevel(logLevel)
34
- }
35
-
36
- @ReactMethod
37
- fun configure(options: ReadableMap) {
38
- DashX.configure(
39
- reactContext,
40
- options.getString("publicKey")!!,
41
- options.getStringIfPresent("baseURI"),
42
- options.getStringIfPresent("targetEnvironment")
43
- )
44
- }
45
-
46
- @ReactMethod
47
- fun identify(options: ReadableMap?) {
48
- val optionsHashMap = options?.toHashMap()
49
- ?.filterValues { it != null }
50
- ?.mapValues { it.value.toString() }
51
- DashX.identify(optionsHashMap?.let { HashMap(it) })
52
- }
53
-
54
- @ReactMethod
55
- fun setIdentity(uid: String?, token: String?) {
56
- DashX.setIdentity(uid, token)
57
- }
58
-
59
- @ReactMethod
60
- fun reset() {
61
- DashX.reset()
62
- }
63
-
64
- @ReactMethod
65
- fun track(event: String, data: ReadableMap?) {
66
- val jsonData = try {
67
- data?.toHashMap()
68
- ?.filterValues { it != null }
69
- ?.mapValues { it.value.toString() }
70
- ?.let { HashMap(it) }
71
- } catch (e: Exception) {
72
- DashXLog.d(tag, e.message)
73
- return
74
- }
75
-
76
- DashX.track(event, jsonData)
77
- }
78
-
79
- @ReactMethod
80
- fun screen(screenName: String, data: ReadableMap?) {
81
- val screenData = data?.toHashMap()
82
- ?.filterValues { it != null }
83
- ?.mapValues { it.value.toString() }
84
- ?.let { HashMap(it) }
85
- ?: HashMap()
86
- DashX.screen(screenName, screenData)
87
- }
88
-
89
- @ReactMethod
90
- fun fetchRecord(urn: String, options: ReadableMap?, promise: Promise) {
91
- val preview = options?.getBooleanIfPresent("preview")
92
- val language = options?.getStringIfPresent("language")
93
- val fields = try {
94
- convertReadableArrayToKJsonList(options?.getArray("fields"))
95
- } catch (e: Exception) {
96
- DashXLog.d(tag, e.message)
97
- promise.reject("EUNSPECIFIED", "Error parsing fields: ${e.message}")
98
- return
99
- }
100
- val include = try {
101
- convertReadableArrayToKJsonList(options?.getArray("include"))
102
- } catch (e: Exception) {
103
- DashXLog.d(tag, e.message)
104
- promise.reject("EUNSPECIFIED", "Error parsing include: ${e.message}")
105
- return
106
- }
107
- val exclude = try {
108
- convertReadableArrayToKJsonList(options?.getArray("exclude"))
109
- } catch (e: Exception) {
110
- DashXLog.d(tag, e.message)
111
- promise.reject("EUNSPECIFIED", "Error parsing exclude: ${e.message}")
112
- return
113
- }
114
-
115
- DashX.fetchRecord(
116
- urn = urn,
117
- preview = preview,
118
- language = language,
119
- fields = fields,
120
- include = include,
121
- exclude = exclude,
122
- onError = {
123
- promise.reject("EUNSPECIFIED", it.message)
124
- },
125
- onSuccess = {
126
- promise.resolve(convertJsonToMap(convertKJsonToJson(it)))
127
- }
128
- )
129
- }
130
-
131
- @ReactMethod
132
- fun searchRecords(resource: String, options: ReadableMap?, promise: Promise) {
133
- val jsonFilter = try {
134
- convertMapToJson(options?.getMap("filter"))?.let { convertJsonToKJson(it) }
135
- } catch (e: Exception) {
136
- DashXLog.d(tag, e.message)
137
- promise.reject("EUNSPECIFIED", "Error parsing filter: ${e.message}")
138
- return
139
- }
140
- val order = try {
141
- convertReadableArrayToKJsonList(options?.getArray("order"))
142
- } catch (e: Exception) {
143
- DashXLog.d(tag, e.message)
144
- promise.reject("EUNSPECIFIED", "Error parsing order: ${e.message}")
145
- return
146
- }
147
- val limit = options?.getIntIfPresent("limit")
148
- val preview = options?.getBooleanIfPresent("preview")
149
- val language = options?.getStringIfPresent("language")
150
- val fields = try {
151
- convertReadableArrayToKJsonList(options?.getArray("fields"))
152
- } catch (e: Exception) {
153
- DashXLog.d(tag, e.message)
154
- promise.reject("EUNSPECIFIED", "Error parsing fields: ${e.message}")
155
- return
156
- }
157
- val include = try {
158
- convertReadableArrayToKJsonList(options?.getArray("include"))
159
- } catch (e: Exception) {
160
- DashXLog.d(tag, e.message)
161
- promise.reject("EUNSPECIFIED", "Error parsing include: ${e.message}")
162
- return
163
- }
164
- val exclude = try {
165
- convertReadableArrayToKJsonList(options?.getArray("exclude"))
166
- } catch (e: Exception) {
167
- DashXLog.d(tag, e.message)
168
- promise.reject("EUNSPECIFIED", "Error parsing exclude: ${e.message}")
169
- return
170
- }
171
-
172
- DashX.searchRecords(
173
- resource = resource,
174
- filter = jsonFilter,
175
- order = order,
176
- limit = limit,
177
- preview = preview,
178
- language = language,
179
- fields = fields,
180
- include = include,
181
- exclude = exclude,
182
- onError = {
183
- promise.reject("EUNSPECIFIED", it.message)
184
- },
185
- onSuccess = { records ->
186
- val readableArray = Arguments.createArray()
187
- records.forEach {
188
- readableArray.pushMap(convertJsonToMap(convertKJsonToJson(it)))
189
- }
190
- promise.resolve(readableArray)
191
- }
192
- )
193
- }
194
-
195
- @ReactMethod
196
- fun fetchStoredPreferences(promise: Promise) {
197
- DashX.fetchStoredPreferences(
198
- onError = {
199
- promise.reject("EUNSPECIFIED", it.message)
200
- },
201
- onSuccess = { content ->
202
- promise.resolve(convertJsonToMap(convertKJsonToJson(Json.decodeFromString<JsonObject>(Json.encodeToString(content)))))
203
- }
204
- )
205
- }
206
-
207
- @ReactMethod
208
- fun saveStoredPreferences(preferenceData: ReadableMap?, promise: Promise) {
209
- val preferencesString = MapUtil.toJSONElement(preferenceData).toString()
210
-
211
- DashX.saveStoredPreferences(
212
- Json.decodeFromString<JsonObject>(preferencesString),
213
- onError = {
214
- promise.reject("EUNSPECIFIED", it.message)
215
- },
216
- onSuccess = { content ->
217
- promise.resolve(convertJsonToMap(convertKJsonToJson(Json.decodeFromString<JsonObject>(Json.encodeToString(content)))))
218
- }
219
- )
220
- }
221
-
222
- @ReactMethod
223
- fun subscribe() {
224
- DashX.subscribe()
225
- }
226
-
227
- @ReactMethod
228
- fun unsubscribe() {
229
- DashX.unsubscribe()
230
- }
231
- }
@@ -1,18 +0,0 @@
1
- package com.dashx.rn.sdk
2
-
3
- import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.JavaScriptModule
5
- import com.facebook.react.bridge.NativeModule
6
- import com.facebook.react.bridge.ReactApplicationContext
7
- import com.facebook.react.uimanager.ViewManager
8
- import java.util.Arrays
9
-
10
- class DashXPackage : ReactPackage {
11
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
- return Arrays.asList<NativeModule>(DashXReactNativeModule(reactContext))
13
- }
14
-
15
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
- return emptyList()
17
- }
18
- }
@@ -1,3 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
- #import <React/RCTBundleURLProvider.h>
3
- #import <React_RCTAppDelegate/RCTAppDelegate.h>