@dashx/react-native 1.0.2 → 1.0.4

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,24 @@
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 = "DashXReactNative"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.description = <<-DESC
10
+ @dashx/react-native
11
+ DESC
12
+ s.homepage = "https://github.com/github_account/@dashx/react-native"
13
+ # brief license entry:
14
+ s.license = "MIT"
15
+ s.authors = { "DashXDev" => "dev@dashx.com" }
16
+ s.platforms = { :ios => "10.0" }
17
+ s.source = { :git => "https://github.com/dashxhq/dashx-react-native.git", :tag => "#{s.version}" }
18
+
19
+ s.source_files = "ios/**/*.{h,c,m,swift}"
20
+ s.requires_arc = true
21
+
22
+ s.dependency "DashX", "1.0.5"
23
+ s.dependency "React"
24
+ end
@@ -1,7 +1,8 @@
1
+ import groovy.json.JsonSlurper
1
2
 
2
3
  buildscript {
3
4
  ext {
4
- kotlinVersion = '1.5.31'
5
+ kotlinVersion = '1.6.0'
5
6
  androidToolsVersion = '7.0.4'
6
7
  }
7
8
 
@@ -19,6 +20,14 @@ buildscript {
19
20
  apply plugin: 'com.android.library'
20
21
  apply plugin: 'kotlin-android'
21
22
 
23
+ def getVersionFromNpm() {
24
+ // Read and parse package.json file from project root
25
+ def inputFile = new File("../node_modules/@dashx/react-native/package.json")
26
+ def packageJson = new JsonSlurper().parseText(inputFile.text)
27
+
28
+ return packageJson["version"]
29
+ }
30
+
22
31
  android {
23
32
  compileSdkVersion 30
24
33
  buildToolsVersion '28.0.3'
@@ -28,7 +37,9 @@ android {
28
37
  targetSdkVersion 30
29
38
  compileSdkVersion 30
30
39
  versionCode 1
31
- versionName "1.0"
40
+ versionName getVersionFromNpm()
41
+
42
+ buildConfigField 'String', 'VERSION_NAME', "\"$versionName\""
32
43
  }
33
44
  lintOptions {
34
45
  abortOnError false
@@ -45,6 +56,5 @@ dependencies {
45
56
  implementation 'com.facebook.react:react-native:+'
46
57
  implementation 'com.google.code.gson:gson:2.9.0'
47
58
 
48
- implementation "com.dashx:dashx-android:1.0.3"
59
+ implementation "com.dashx:dashx-android:1.0.7"
49
60
  }
50
-
@@ -0,0 +1 @@
1
+ android.useAndroidX=true
@@ -2,5 +2,4 @@
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
3
  package="com.dashx.rn.sdk">
4
4
 
5
- </manifest>
6
-
5
+ </manifest>
@@ -1,15 +1,12 @@
1
1
  package com.dashx.rn.sdk
2
2
 
3
- import android.annotation.TargetApi
4
- import android.content.Context
5
- import android.database.Cursor
3
+ import android.content.pm.PackageInfo
4
+ import android.content.pm.PackageManager.NameNotFoundException
6
5
  import android.net.Uri
7
- import android.os.Build
8
- import android.provider.DocumentsContract
9
- import android.provider.MediaStore
10
6
  import com.dashx.rn.sdk.util.*
11
7
  import com.dashx.sdk.DashXLog
12
8
  import com.dashx.sdk.data.ExternalAsset
9
+ import com.dashx.sdk.data.LibraryInfo
13
10
  import com.facebook.react.bridge.*
14
11
  import com.google.gson.Gson
15
12
  import java.io.File
@@ -31,17 +28,18 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
31
28
 
32
29
  @ReactMethod
33
30
  fun configure(options: ReadableMap) {
34
- dashXClient = DashX.createInstance(
35
- reactContext,
31
+ dashXClient = DashX.configure(
32
+ reactContext,
36
33
  options.getString("publicKey")!!,
37
34
  options.getStringIfPresent("baseURI"),
38
- options.getStringIfPresent("targetEnvironment")
35
+ options.getStringIfPresent("targetEnvironment"),
36
+ LibraryInfo("dashx-react-native", BuildConfig.VERSION_NAME)
39
37
  )
40
38
  }
41
39
 
42
40
  @ReactMethod
43
41
  fun identify(options: ReadableMap?) {
44
- val optionsHashMap = MapUtil.toMap(options)
42
+ val optionsHashMap = options?.toHashMap()
45
43
  dashXClient?.identify(optionsHashMap as HashMap<String, String>?)
46
44
  }
47
45
 
@@ -58,7 +56,7 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
58
56
  @ReactMethod
59
57
  fun track(event: String, data: ReadableMap?) {
60
58
  val jsonData = try {
61
- MapUtil.toMap(data) as HashMap<String, String>
59
+ data?.toHashMap() as HashMap<String, String>
62
60
  } catch (e: Exception) {
63
61
  DashXLog.d(tag, e.message)
64
62
  return
@@ -69,7 +67,7 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
69
67
 
70
68
  @ReactMethod
71
69
  fun screen(screenName: String, data: ReadableMap?) {
72
- dashXClient?.screen(screenName, MapUtil.toMap(data) as HashMap<String, String>)
70
+ dashXClient?.screen(screenName, data?.toHashMap() as HashMap<String, String>)
73
71
  }
74
72
 
75
73
  @ReactMethod
@@ -185,6 +183,21 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
185
183
  )
186
184
  }
187
185
 
186
+ @ReactMethod
187
+ fun saveStoredPreferences(preferenceData: ReadableMap?, promise: Promise) {
188
+ val preferencesString = MapUtil.toJSONElement(preferenceData).toString()
189
+
190
+ dashXClient?.saveStoredPreferences(
191
+ preferencesString,
192
+ onError = {
193
+ promise.reject("EUNSPECIFIED", it)
194
+ },
195
+ onSuccess = { content ->
196
+ promise.resolve(convertJsonToMap(content))
197
+ }
198
+ )
199
+ }
200
+
188
201
  @ReactMethod
189
202
  fun uploadExternalAsset(
190
203
  file: ReadableMap,
@@ -215,23 +228,6 @@ class DashXReactNativeModule(private val reactContext: ReactApplicationContext)
215
228
  )
216
229
  }
217
230
 
218
- @ReactMethod
219
- fun externalAsset(
220
- id: String,
221
- promise: Promise
222
- ) {
223
- dashXClient?.externalAsset(
224
- id,
225
- onError = {
226
- promise.reject("EUNSPECIFIED", it)
227
- },
228
- onSuccess = { content ->
229
- val jsonObject = Gson().toJsonTree(content, ExternalAsset::class.java).asJsonObject
230
- promise.resolve(convertJsonToMap(jsonObject))
231
- }
232
- )
233
- }
234
-
235
231
  @ReactMethod
236
232
  fun subscribe() {
237
233
  dashXClient?.subscribe()
@@ -43,38 +43,6 @@ import org.json.JSONObject;
43
43
  import org.json.JSONException;
44
44
 
45
45
  public class ArrayUtil {
46
-
47
- public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
48
- JSONArray jsonArray = new JSONArray();
49
-
50
- for (int i = 0; i < readableArray.size(); i++) {
51
- ReadableType type = readableArray.getType(i);
52
-
53
- switch (type) {
54
- case Null:
55
- jsonArray.put(i, null);
56
- break;
57
- case Boolean:
58
- jsonArray.put(i, readableArray.getBoolean(i));
59
- break;
60
- case Number:
61
- jsonArray.put(i, readableArray.getDouble(i));
62
- break;
63
- case String:
64
- jsonArray.put(i, readableArray.getString(i));
65
- break;
66
- case Map:
67
- jsonArray.put(i, MapUtil.toJSONObject(readableArray.getMap(i)));
68
- break;
69
- case Array:
70
- jsonArray.put(i, ArrayUtil.toJSONArray(readableArray.getArray(i)));
71
- break;
72
- }
73
- }
74
-
75
- return jsonArray;
76
- }
77
-
78
46
  public static Object[] toArray(JSONArray jsonArray) throws JSONException {
79
47
  Object[] array = new Object[jsonArray.length()];
80
48
 
@@ -32,6 +32,9 @@ import com.facebook.react.bridge.ReadableMap;
32
32
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
33
33
  import com.facebook.react.bridge.ReadableType;
34
34
  import com.facebook.react.bridge.WritableMap;
35
+ import com.google.gson.Gson;
36
+ import com.google.gson.JsonElement;
37
+ import com.google.gson.JsonNull;
35
38
 
36
39
  import java.util.Map;
37
40
  import java.util.HashMap;
@@ -43,38 +46,9 @@ import org.json.JSONException;
43
46
 
44
47
  public class MapUtil {
45
48
 
46
- public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
47
- JSONObject jsonObject = new JSONObject();
48
-
49
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
50
-
51
- while (iterator.hasNextKey()) {
52
- String key = iterator.nextKey();
53
- ReadableType type = readableMap.getType(key);
54
-
55
- switch (type) {
56
- case Null:
57
- jsonObject.put(key, null);
58
- break;
59
- case Boolean:
60
- jsonObject.put(key, readableMap.getBoolean(key));
61
- break;
62
- case Number:
63
- jsonObject.put(key, readableMap.getDouble(key));
64
- break;
65
- case String:
66
- jsonObject.put(key, readableMap.getString(key));
67
- break;
68
- case Map:
69
- jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
70
- break;
71
- case Array:
72
- jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
73
- break;
74
- }
75
- }
76
-
77
- return jsonObject;
49
+ public static JsonElement toJSONElement(ReadableMap readableMap) throws JSONException {
50
+ HashMap<String, Object> hashMap = readableMap.toHashMap();
51
+ return new Gson().toJsonTree(hashMap);
78
52
  }
79
53
 
80
54
  public static Map<String, Object> toMap(JSONObject jsonObject) throws JSONException {
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NativeEventEmitter, NativeModules } from "react-native";
2
2
  import { parseFilterObject, toContentSingleton } from "./utils";
3
+ import { getRealPathFromURI } from "react-native-get-real-path";
3
4
 
4
5
  import ContentOptionsBuilder from "./ContentOptionsBuilder";
5
6
 
@@ -16,6 +17,8 @@ const {
16
17
  uploadExternalAsset,
17
18
  prepareExternalAsset,
18
19
  externalAsset,
20
+ fetchStoredPreferences,
21
+ saveStoredPreferences,
19
22
  } = DashX;
20
23
 
21
24
  DashX.identify = (options) => {
@@ -50,8 +53,13 @@ DashX.fetchContent = (contentType, options) => {
50
53
  return fetchContent(contentType, options);
51
54
  };
52
55
 
53
- DashX.uploadExternalAsset = (file, externalColumnId) => {
54
- return uploadExternalAsset(file, externalColumnId);
56
+ DashX.uploadExternalAsset = async (file, externalColumnId) => {
57
+ // Convert content uri to file uri
58
+ if (file.uri.startsWith("content://")) {
59
+ file.uri = `file://${await getRealPathFromURI(file.uri)}`;
60
+ }
61
+
62
+ return uploadExternalAsset(file, externalColumnId);
55
63
  };
56
64
 
57
65
  DashX.prepareExternalAsset = (externalColumnId) => {
@@ -62,6 +70,14 @@ DashX.externalAsset = (assetId) => {
62
70
  return externalAsset(assetId);
63
71
  };
64
72
 
73
+ DashX.fetchStoredPreferences = () => {
74
+ return fetchStoredPreferences();
75
+ };
76
+
77
+ DashX.saveStoredPreferences = (preferenceData) => {
78
+ return saveStoredPreferences(preferenceData);
79
+ };
80
+
65
81
  DashX.onMessageReceived = (callback) => {
66
82
  dashXEventEmitter.addListener("messageReceived", callback);
67
83
  };
package/ios/DashX.swift CHANGED
@@ -92,7 +92,6 @@ class DashXReactNative: RCTEventEmitter {
92
92
 
93
93
  @objc(addItemToCart:pricingId:quantity:reset:custom:resolver:rejecter:)
94
94
  func addItemToCart(_ itemId: String, _ pricingId: String, _ quantity: String, _ reset: Bool, _ custom: NSDictionary?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
95
-
96
95
  dashXClient.addItemToCart(
97
96
  itemId: itemId,
98
97
  pricingId: pricingId,
@@ -106,7 +105,6 @@ class DashXReactNative: RCTEventEmitter {
106
105
 
107
106
  @objc(fetchCart:rejecter:)
108
107
  func fetchCart(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
109
-
110
108
  dashXClient.fetchCart(
111
109
  successCallback: CBU.resolveToSuccessCallback(resolve),
112
110
  failureCallback: CBU.rejectToFailureCallback(reject)
@@ -115,13 +113,22 @@ class DashXReactNative: RCTEventEmitter {
115
113
 
116
114
  @objc(fetchStoredPreferences:rejecter:)
117
115
  func fetchStoredPreferences(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
118
-
119
116
  dashXClient.fetchStoredPreferences(
120
117
  successCallback: CBU.resolveToSuccessCallback(resolve),
121
118
  failureCallback: CBU.rejectToFailureCallback(reject)
122
119
  )
123
120
  }
124
121
 
122
+ @objc(saveStoredPreferences:resolve:rejecter:)
123
+ func saveStoredPreferences(_ preferenceData: NSDictionary, _ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
124
+ dashXClient.saveStoredPreferences(
125
+ preferenceData: preferenceData,
126
+ successCallback: CBU.resolveToSuccessCallback(resolve),
127
+ failureCallback: CBU.rejectToFailureCallback(reject)
128
+ )
129
+ }
130
+
131
+
125
132
  @objc(uploadExternalAsset:externalColumnId:resolver:rejecter:)
126
133
  func uploadExternalAsset(_ file: NSDictionary, _ externalColumnId: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
127
134
  if let fileDictionary = file as? [String: Any], let fileURI = fileDictionary["uri"] as? String {
@@ -18,6 +18,7 @@ RCT_EXTERN_METHOD(fetchContent:(NSString *)urn options:(NSDictionary *)options r
18
18
  RCT_EXTERN_METHOD(addItemToCart:(NSString *)itemId pricingId:(NSString *)pricingId quantity:(NSString *)quantity reset:(BOOL)reset custom:(NSDictionary *)custom resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
19
19
  RCT_EXTERN_METHOD(fetchCart:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
20
20
  RCT_EXTERN_METHOD(fetchStoredPreferences:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
21
+ RCT_EXTERN_METHOD(saveStoredPreferences:(NSDictionary *)preferenceData resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
21
22
  RCT_EXTERN_METHOD(uploadExternalAsset:(NSDictionary *)file externalColumnId:(NSString *)externalColumnId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
22
23
  RCT_EXTERN_METHOD(externalAsset:(NSString *)assetId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
23
24
  RCT_EXTERN_METHOD(subscribe)
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.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "DashX SDK for React Native",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -11,14 +11,14 @@
11
11
  "ContentOptionsBuilder.js",
12
12
  "utils.js",
13
13
  "ios",
14
- "DashX.podspec"
14
+ "DashXReactNative.podspec"
15
15
  ],
16
16
  "scripts": {
17
17
  "test": "echo \"Error: no test specified\" && exit 1"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/dashxhq/dashx-react-native"
21
+ "url": "https://github.com/dashxhq/dashx-react-native"
22
22
  },
23
23
  "keywords": [
24
24
  "react-native"
@@ -35,5 +35,8 @@
35
35
  "devDependencies": {
36
36
  "eslint": "^8.21.0",
37
37
  "eslint-plugin-react": "^7.30.1"
38
+ },
39
+ "dependencies": {
40
+ "react-native-get-real-path": "github:Wraptime/react-native-get-real-path"
38
41
  }
39
42
  }