@dashx/react-native 0.1.25 → 1.0.3

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 (51) hide show
  1. package/android/build.gradle +22 -149
  2. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  3. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  4. package/android/gradlew +34 -21
  5. package/android/gradlew.bat +24 -19
  6. package/android/src/main/AndroidManifest.xml +2 -8
  7. package/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +248 -0
  8. package/android/src/main/java/com/dashx/rn/sdk/{DashXPackage.kt → DashXReactNativePackage.kt} +2 -1
  9. package/android/src/main/java/com/dashx/rn/sdk/util/ArrayUtil.java +131 -0
  10. package/android/src/main/java/com/dashx/rn/sdk/util/MapUtil.java +142 -0
  11. package/android/src/main/java/com/dashx/rn/sdk/{Utils.kt → util/Utils.kt} +5 -5
  12. package/index.js +68 -72
  13. package/ios/DashX.swift +110 -95
  14. package/ios/DashXReactNative-Bridging-Header.h +4 -0
  15. package/ios/DashXReactNative.m +25 -0
  16. package/ios/DashXReactNative.xcodeproj/project.pbxproj +280 -0
  17. package/ios/{DashX.xcworkspace → DashXReactNative.xcworkspace}/contents.xcworkspacedata +1 -1
  18. package/ios/{DashX.xcworkspace → DashXReactNative.xcworkspace}/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  19. package/package.json +6 -12
  20. package/DashX.podspec +0 -27
  21. package/android/README.md +0 -23
  22. package/android/src/main/java/com/dashx/rn/sdk/DashXActivityLifecycleCallbacks.kt +0 -93
  23. package/android/src/main/java/com/dashx/rn/sdk/DashXClientInterceptor.kt +0 -66
  24. package/android/src/main/java/com/dashx/rn/sdk/DashXExceptionHandler.kt +0 -28
  25. package/android/src/main/java/com/dashx/rn/sdk/DashXMessagingService.kt +0 -176
  26. package/android/src/main/java/com/dashx/rn/sdk/DashXModule.kt +0 -193
  27. package/android/src/main/java/com/dashx/rn/sdk/NotificationReceiver.kt +0 -17
  28. package/ios/API.swift +0 -2420
  29. package/ios/Constants.swift +0 -14
  30. package/ios/DashX.m +0 -17
  31. package/ios/DashX.xcodeproj/project.pbxproj +0 -356
  32. package/ios/DashX.xcodeproj/xcshareddata/xcschemes/DashX.xcscheme +0 -67
  33. package/ios/DashXAppDelegate.swift +0 -73
  34. package/ios/DashXApplicationLifecycleCallbacks.swift +0 -65
  35. package/ios/DashXClient.swift +0 -319
  36. package/ios/DashXData.swift +0 -19
  37. package/ios/DashXLog.swift +0 -44
  38. package/ios/DashXUIViewController.swift +0 -15
  39. package/ios/Network.swift +0 -74
  40. package/ios/README.md +0 -80
  41. package/ios/Utils.swift +0 -13
  42. package/ios/graphql/AddContent.graphql +0 -8
  43. package/ios/graphql/AddItemToCart.graphql +0 -33
  44. package/ios/graphql/EditContent.graphql +0 -8
  45. package/ios/graphql/FetchCart.graphql +0 -33
  46. package/ios/graphql/FetchContent.graphql +0 -3
  47. package/ios/graphql/IdentifyAccount.graphql +0 -5
  48. package/ios/graphql/SearchContent.graphql +0 -3
  49. package/ios/graphql/SubscribeContact.graphql +0 -6
  50. package/ios/graphql/TrackEvent.graphql +0 -5
  51. package/ios/schema.json +0 -37038
@@ -0,0 +1,131 @@
1
+
2
+ /*
3
+ ArrayUtil exposes a set of helper methods for working with
4
+ ReadableArray (by React Native), Object[], and JSONArray.
5
+
6
+ MIT License
7
+
8
+ Copyright (c) 2020 Marc Mendiola
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ */
28
+
29
+ package com.dashx.rn.sdk.util;
30
+
31
+ import com.facebook.react.bridge.Arguments;
32
+ import com.facebook.react.bridge.ReadableArray;
33
+ import com.facebook.react.bridge.ReadableType;
34
+ import com.facebook.react.bridge.WritableArray;
35
+
36
+ import java.util.ArrayList;
37
+ import java.util.Arrays;
38
+ import java.util.List;
39
+ import java.util.Map;
40
+
41
+ import org.json.JSONArray;
42
+ import org.json.JSONObject;
43
+ import org.json.JSONException;
44
+
45
+ public class ArrayUtil {
46
+ public static Object[] toArray(JSONArray jsonArray) throws JSONException {
47
+ Object[] array = new Object[jsonArray.length()];
48
+
49
+ for (int i = 0; i < jsonArray.length(); i++) {
50
+ Object value = jsonArray.get(i);
51
+
52
+ if (value instanceof JSONObject) {
53
+ value = MapUtil.toMap((JSONObject) value);
54
+ }
55
+ if (value instanceof JSONArray) {
56
+ value = ArrayUtil.toArray((JSONArray) value);
57
+ }
58
+
59
+ array[i] = value;
60
+ }
61
+
62
+ return array;
63
+ }
64
+
65
+ public static Object[] toArray(ReadableArray readableArray) {
66
+ Object[] array = new Object[readableArray.size()];
67
+
68
+ for (int i = 0; i < readableArray.size(); i++) {
69
+ ReadableType type = readableArray.getType(i);
70
+
71
+ switch (type) {
72
+ case Null:
73
+ array[i] = null;
74
+ break;
75
+ case Boolean:
76
+ array[i] = readableArray.getBoolean(i);
77
+ break;
78
+ case Number:
79
+ array[i] = readableArray.getDouble(i);
80
+ break;
81
+ case String:
82
+ array[i] = readableArray.getString(i);
83
+ break;
84
+ case Map:
85
+ array[i] = MapUtil.toMap(readableArray.getMap(i));
86
+ break;
87
+ case Array:
88
+ array[i] = ArrayUtil.toArray(readableArray.getArray(i));
89
+ break;
90
+ }
91
+ }
92
+
93
+ return array;
94
+ }
95
+
96
+ public static List<Object> toList(ReadableArray readableArray) {
97
+ return Arrays.asList(toArray(readableArray));
98
+ }
99
+
100
+ public static WritableArray toWritableArray(Object[] array) {
101
+ WritableArray writableArray = Arguments.createArray();
102
+
103
+ for (int i = 0; i < array.length; i++) {
104
+ Object value = array[i];
105
+
106
+ if (value == null) {
107
+ writableArray.pushNull();
108
+ }
109
+ if (value instanceof Boolean) {
110
+ writableArray.pushBoolean((Boolean) value);
111
+ }
112
+ if (value instanceof Double) {
113
+ writableArray.pushDouble((Double) value);
114
+ }
115
+ if (value instanceof Integer) {
116
+ writableArray.pushInt((Integer) value);
117
+ }
118
+ if (value instanceof String) {
119
+ writableArray.pushString((String) value);
120
+ }
121
+ if (value instanceof Map) {
122
+ writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value));
123
+ }
124
+ if (value.getClass().isArray()) {
125
+ writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value));
126
+ }
127
+ }
128
+
129
+ return writableArray;
130
+ }
131
+ }
@@ -0,0 +1,142 @@
1
+ /*
2
+ MapUtil exposes a set of helper methods for working with
3
+ ReadableMap (by React Native), Map<String, Object>, and JSONObject.
4
+
5
+ MIT License
6
+
7
+ Copyright (c) 2020 Marc Mendiola
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ */
27
+
28
+ package com.dashx.rn.sdk.util;
29
+
30
+ import com.facebook.react.bridge.Arguments;
31
+ import com.facebook.react.bridge.ReadableMap;
32
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
33
+ import com.facebook.react.bridge.ReadableType;
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;
38
+
39
+ import java.util.Map;
40
+ import java.util.HashMap;
41
+ import java.util.Iterator;
42
+
43
+ import org.json.JSONArray;
44
+ import org.json.JSONObject;
45
+ import org.json.JSONException;
46
+
47
+ public class MapUtil {
48
+
49
+ public static JsonElement toJSONElement(ReadableMap readableMap) throws JSONException {
50
+ HashMap<String, Object> hashMap = readableMap.toHashMap();
51
+ return new Gson().toJsonTree(hashMap);
52
+ }
53
+
54
+ public static Map<String, Object> toMap(JSONObject jsonObject) throws JSONException {
55
+ Map<String, Object> map = new HashMap<>();
56
+ Iterator<String> iterator = jsonObject.keys();
57
+
58
+ while (iterator.hasNext()) {
59
+ String key = iterator.next();
60
+ Object value = jsonObject.get(key);
61
+
62
+ if (value instanceof JSONObject) {
63
+ value = MapUtil.toMap((JSONObject) value);
64
+ }
65
+ if (value instanceof JSONArray) {
66
+ value = ArrayUtil.toArray((JSONArray) value);
67
+ }
68
+
69
+ map.put(key, value);
70
+ }
71
+
72
+ return map;
73
+ }
74
+
75
+ public static Map<String, Object> toMap(ReadableMap readableMap) {
76
+ Map<String, Object> map = new HashMap<>();
77
+
78
+ if(readableMap == null) {
79
+ return map;
80
+ }
81
+
82
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
83
+
84
+ while (iterator.hasNextKey()) {
85
+ String key = iterator.nextKey();
86
+ ReadableType type = readableMap.getType(key);
87
+
88
+ switch (type) {
89
+ case Null:
90
+ map.put(key, null);
91
+ break;
92
+ case Boolean:
93
+ map.put(key, readableMap.getBoolean(key));
94
+ break;
95
+ case Number:
96
+ map.put(key, readableMap.getDouble(key));
97
+ break;
98
+ case String:
99
+ map.put(key, readableMap.getString(key));
100
+ break;
101
+ case Map:
102
+ map.put(key, MapUtil.toMap(readableMap.getMap(key)));
103
+ break;
104
+ case Array:
105
+ map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
106
+ break;
107
+ }
108
+ }
109
+
110
+ return map;
111
+ }
112
+
113
+ public static WritableMap toWritableMap(Map<String, Object> map) {
114
+ WritableMap writableMap = Arguments.createMap();
115
+ Iterator iterator = map.entrySet().iterator();
116
+
117
+ while (iterator.hasNext()) {
118
+ Map.Entry pair = (Map.Entry)iterator.next();
119
+ Object value = pair.getValue();
120
+
121
+ if (value == null) {
122
+ writableMap.putNull((String) pair.getKey());
123
+ } else if (value instanceof Boolean) {
124
+ writableMap.putBoolean((String) pair.getKey(), (Boolean) value);
125
+ } else if (value instanceof Double) {
126
+ writableMap.putDouble((String) pair.getKey(), (Double) value);
127
+ } else if (value instanceof Integer) {
128
+ writableMap.putInt((String) pair.getKey(), (Integer) value);
129
+ } else if (value instanceof String) {
130
+ writableMap.putString((String) pair.getKey(), (String) value);
131
+ } else if (value instanceof Map) {
132
+ writableMap.putMap((String) pair.getKey(), MapUtil.toWritableMap((Map<String, Object>) value));
133
+ } else if (value.getClass() != null && value.getClass().isArray()) {
134
+ writableMap.putArray((String) pair.getKey(), ArrayUtil.toWritableArray((Object[]) value));
135
+ }
136
+
137
+ iterator.remove();
138
+ }
139
+
140
+ return writableMap;
141
+ }
142
+ }
@@ -1,6 +1,6 @@
1
1
  @file:JvmName("Utils")
2
2
 
3
- package com.dashx.rn.sdk
3
+ package com.dashx.rn.sdk.util
4
4
 
5
5
  import com.facebook.react.bridge.*
6
6
  import com.google.gson.JsonArray
@@ -45,8 +45,8 @@ fun convertArrayToJson(readableArray: ReadableArray?): JsonArray {
45
45
  @JvmOverloads
46
46
  @Throws(Exception::class)
47
47
  fun convertToWritableMap(
48
- map: Map<*, *>,
49
- blacklist: List<String> = emptyList<String>()
48
+ map: Map<*, *>,
49
+ blacklist: List<String> = emptyList<String>()
50
50
  ): WritableMap {
51
51
  val writableMap: WritableMap = WritableNativeMap()
52
52
  val iterator: Iterator<String> = map.keys.iterator() as Iterator<String>
@@ -54,7 +54,7 @@ fun convertToWritableMap(
54
54
  val key = iterator.next()
55
55
 
56
56
  if (blacklist.contains(key)) {
57
- continue;
57
+ continue
58
58
  }
59
59
 
60
60
  when (val value = map[key]) {
@@ -128,4 +128,4 @@ fun ReadableMap.getStringIfPresent(key: String): String? {
128
128
 
129
129
  fun ReadableMap.getBooleanIfPresent(key: String): Boolean? {
130
130
  return if (this.hasKey(key)) this.getBoolean(key) else null
131
- }
131
+ }
package/index.js CHANGED
@@ -1,89 +1,85 @@
1
- import { NativeEventEmitter, NativeModules } from 'react-native'
2
- import { parseFilterObject, toContentSingleton } from './utils'
3
- import {
4
- prepareExternalAsset,
5
- queryExternalAsset,
6
- uploadExternalAsset,
7
- } from './utils/RestAPIClient'
1
+ import { NativeEventEmitter, NativeModules } from "react-native";
2
+ import { parseFilterObject, toContentSingleton } from "./utils";
3
+ import { getRealPathFromURI } from "react-native-get-real-path";
8
4
 
9
- import ContentOptionsBuilder from './ContentOptionsBuilder'
5
+ import ContentOptionsBuilder from "./ContentOptionsBuilder";
10
6
 
11
- const { DashX } = NativeModules
12
- const dashXEventEmitter = new NativeEventEmitter(DashX)
7
+ const { DashXReactNative: DashX } = NativeModules;
13
8
 
14
- //TODO Get connection config from Android layer as well
15
- const { identify, track, fetchContent, searchContent, getConnectionConfig } =
16
- DashX
9
+ const dashXEventEmitter = new NativeEventEmitter(DashX);
10
+
11
+ const {
12
+ identify,
13
+ setIdentity,
14
+ track,
15
+ fetchContent,
16
+ searchContent,
17
+ uploadExternalAsset,
18
+ prepareExternalAsset,
19
+ externalAsset,
20
+ fetchStoredPreferences,
21
+ saveStoredPreferences,
22
+ } = DashX;
17
23
 
18
- // Handle overloads at JS, because Native modules doesn't allow that
19
- // https://github.com/facebook/react-native/issues/19116
20
24
  DashX.identify = (options) => {
21
- if (typeof options === 'string') {
22
- return identify(options, null) // options is a string ie. uid
23
- } else {
24
- return identify(null, options)
25
- }
26
- }
25
+ return identify(options);
26
+ };
27
27
 
28
- DashX.track = (event, data) => track(event, data || null)
28
+ DashX.setIdentity = (uid, token) => {
29
+ return setIdentity(uid, token);
30
+ };
29
31
 
30
- DashX.getConnectionConfig = () => {
31
- return getConnectionConfig()
32
- }
32
+ DashX.track = (event, data) => track(event, data || null);
33
33
 
34
34
  DashX.searchContent = (contentType, options) => {
35
- if (!options) {
36
- return new ContentOptionsBuilder((wrappedOptions) =>
37
- searchContent(contentType, wrappedOptions)
38
- )
39
- }
35
+ if (!options) {
36
+ return new ContentOptionsBuilder((wrappedOptions) =>
37
+ searchContent(contentType, wrappedOptions)
38
+ );
39
+ }
40
40
 
41
- const filter = parseFilterObject(options.filter)
41
+ const filter = parseFilterObject(options.filter);
42
42
 
43
- const result = searchContent(contentType, { ...options, filter })
43
+ const result = searchContent(contentType, { ...options, filter });
44
44
 
45
- if (options.returnType === 'all') {
46
- return result
47
- }
45
+ if (options.returnType === "all") {
46
+ return result;
47
+ }
48
48
 
49
- return result.then(toContentSingleton)
50
- }
49
+ return result.then(toContentSingleton);
50
+ };
51
51
 
52
52
  DashX.fetchContent = (contentType, options) => {
53
- return fetchContent(contentType, options)
54
- }
53
+ return fetchContent(contentType, options);
54
+ };
55
55
 
56
56
  DashX.uploadExternalAsset = async (file, externalColumnId) => {
57
- const connectionConfig = await getConnectionConfig()
58
-
59
- return new Promise((resolve, reject) => {
60
- uploadExternalAsset(
61
- file,
62
- externalColumnId,
63
- connectionConfig,
64
- resolve,
65
- reject
66
- )
67
- })
68
- }
69
-
70
- DashX.prepareExternalAsset = async (externalColumnId) => {
71
- const connectionConfig = await getConnectionConfig()
72
-
73
- return new Promise((resolve, reject) => {
74
- prepareExternalAsset(externalColumnId, connectionConfig, resolve, reject)
75
- })
76
- }
77
-
78
- DashX.externalAsset = async (assetId) => {
79
- const connectionConfig = await getConnectionConfig()
80
-
81
- return new Promise((resolve, reject) => {
82
- queryExternalAsset(assetId, connectionConfig, resolve, reject)
83
- })
84
- }
85
-
86
- DashX.onMessageReceived = (callback) =>
87
- dashXEventEmitter.addListener('messageReceived', callback)
88
-
89
- export default DashX
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);
63
+ };
64
+
65
+ DashX.prepareExternalAsset = (externalColumnId) => {
66
+ return prepareExternalAsset(externalColumnId);
67
+ };
68
+
69
+ DashX.externalAsset = (assetId) => {
70
+ return externalAsset(assetId);
71
+ };
72
+
73
+ DashX.fetchStoredPreferences = () => {
74
+ return fetchStoredPreferences();
75
+ };
76
+
77
+ DashX.saveStoredPreferences = (preferenceData) => {
78
+ return saveStoredPreferences(preferenceData);
79
+ };
80
+
81
+ DashX.onMessageReceived = (callback) => {
82
+ dashXEventEmitter.addListener("messageReceived", callback);
83
+ };
84
+
85
+ export default DashX;