@dashx/react-native 0.1.25 → 1.0.2

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 -148
  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 -7
  7. package/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +250 -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 +163 -0
  10. package/android/src/main/java/com/dashx/rn/sdk/util/MapUtil.java +168 -0
  11. package/android/src/main/java/com/dashx/rn/sdk/{Utils.kt → util/Utils.kt} +5 -5
  12. package/index.js +54 -74
  13. package/ios/DashX.swift +101 -93
  14. package/ios/DashXReactNative-Bridging-Header.h +4 -0
  15. package/ios/DashXReactNative.m +24 -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 +4 -13
  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
@@ -1,176 +1,50 @@
1
- import groovy.json.JsonSlurper
2
-
3
- // android/build.gradle
4
-
5
- // based on:
6
- //
7
- // * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
8
- // original location:
9
- // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
10
- //
11
- // * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
12
- // original location:
13
- // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
14
-
15
- def DEFAULT_COMPILE_SDK_VERSION = 30
16
- def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
17
- def DEFAULT_MIN_SDK_VERSION = 16
18
- def DEFAULT_TARGET_SDK_VERSION = 30
19
-
20
- def safeExtGet(prop, fallback) {
21
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
22
- }
23
1
 
24
2
  buildscript {
25
- ext.kotlin_version = '1.5.20'
26
- ext.apollo_version = '2.5.3'
27
- // The Android Gradle plugin is only required when opening the android folder stand-alone.
28
- // This avoids unnecessary downloads and potential conflicts when the library is included as a
29
- // module dependency in an application project.
30
- // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
31
- repositories {
32
- if (project == rootProject) {
33
- google()
34
- jcenter()
3
+ ext {
4
+ kotlinVersion = '1.5.31'
5
+ androidToolsVersion = '7.0.4'
35
6
  }
36
7
 
37
- mavenCentral()
38
- }
39
-
40
-
41
- dependencies {
42
- if (project == rootProject) {
43
- classpath 'com.android.tools.build:gradle:3.4.1'
8
+ repositories {
9
+ mavenCentral()
10
+ google()
44
11
  }
45
12
 
46
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
47
- classpath "com.apollographql.apollo:apollo-gradle-plugin:$apollo_version"
48
- }
13
+ dependencies {
14
+ classpath "com.android.tools.build:gradle:${project.ext.androidToolsVersion}"
15
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}"
16
+ }
49
17
  }
50
18
 
51
19
  apply plugin: 'com.android.library'
52
- apply plugin: 'maven'
53
20
  apply plugin: 'kotlin-android'
54
- apply plugin: 'com.apollographql.apollo'
55
21
 
56
22
  android {
57
- compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
58
- buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
23
+ compileSdkVersion 30
24
+ buildToolsVersion '28.0.3'
25
+
59
26
  defaultConfig {
60
- minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
61
- targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
27
+ minSdkVersion 16
28
+ targetSdkVersion 30
29
+ compileSdkVersion 30
62
30
  versionCode 1
63
31
  versionName "1.0"
64
32
  }
65
33
  lintOptions {
66
34
  abortOnError false
67
35
  }
68
- kotlinOptions {
69
- jvmTarget = "1.8"
70
- }
71
36
  }
72
37
 
73
38
  repositories {
74
- // ref: https://www.baeldung.com/maven-local-repository
75
- mavenLocal()
76
- maven {
77
- // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
78
- url "$rootDir/../node_modules/react-native/android"
79
- }
80
- maven {
81
- // Android JSC is installed from npm
82
- url "$rootDir/../node_modules/jsc-android/dist"
83
- }
39
+ mavenCentral()
84
40
  google()
85
- jcenter()
86
- maven { url "https://jitpack.io" }
87
41
  }
88
42
 
89
43
  dependencies {
90
- implementation 'com.github.dashxhq.dashx-android:app:0498742785'
91
- //noinspection GradleDynamicVersion
92
- implementation 'com.facebook.react:react-native:+' // From node_modules
93
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
94
-
95
- implementation 'com.google.code.gson:gson:2.8.6'
96
-
97
- // Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom)
98
- implementation platform('com.google.firebase:firebase-bom:28.3.0')
99
- implementation 'com.google.firebase:firebase-messaging-ktx'
100
-
101
- // The Firebase SDK for Google Analytics is needed for delivery reports
102
- implementation 'com.google.firebase:firebase-analytics-ktx'
103
- }
104
-
105
- def configureReactNativePom(def pom) {
106
- def packageJson = new JsonSlurper().parseText(file('../package.json').text)
107
-
108
- pom.project {
109
- name packageJson.title
110
- artifactId packageJson.name
111
- version = packageJson.version
112
- group = 'com.dashx.rn.sdk'
113
- description packageJson.description
114
- url packageJson.repository.baseUrl
115
-
116
- licenses {
117
- license {
118
- name packageJson.license
119
- url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
120
- distribution 'repo'
121
- }
122
- }
123
-
124
- developers {
125
- developer {
126
- id packageJson.author.username
127
- name packageJson.author.name
128
- }
129
- }
130
- }
131
- }
44
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${project.ext.kotlinVersion}"
45
+ implementation 'com.facebook.react:react-native:+'
46
+ implementation 'com.google.code.gson:gson:2.9.0'
132
47
 
133
- afterEvaluate { project ->
134
- // some Gradle build hooks ref:
135
- // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
136
- task androidJavadoc(type: Javadoc) {
137
- source = android.sourceSets.main.java.srcDirs
138
- classpath += files(android.bootClasspath)
139
- classpath += files(project.getConfigurations().getByName('compile').asList())
140
- include '**/*.java'
141
- }
142
-
143
- task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
144
- classifier = 'javadoc'
145
- from androidJavadoc.destinationDir
146
- }
147
-
148
- task androidSourcesJar(type: Jar) {
149
- classifier = 'sources'
150
- from android.sourceSets.main.java.srcDirs
151
- include '**/*.java'
152
- }
153
-
154
- android.libraryVariants.all { variant ->
155
- def name = variant.name.capitalize()
156
- def javaCompileTask = variant.javaCompileProvider.get()
157
-
158
- task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
159
- from javaCompileTask.destinationDir
160
- }
161
- }
162
-
163
- artifacts {
164
- archives androidSourcesJar
165
- archives androidJavadocJar
166
- }
167
-
168
- task installArchives(type: Upload) {
169
- configuration = configurations.archives
170
- repositories.mavenDeployer {
171
- // Deploy to react-native-event-bridge/maven, ready to publish to npm
172
- repository url: "file://${projectDir}/../android/maven"
173
- configureReactNativePom pom
174
- }
175
- }
48
+ implementation "com.dashx:dashx-android:1.0.3"
176
49
  }
50
+
@@ -1,6 +1,5 @@
1
- #Wed Aug 19 17:17:29 IST 2020
2
1
  distributionBase=GRADLE_USER_HOME
3
2
  distributionPath=wrapper/dists
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4
4
  zipStoreBase=GRADLE_USER_HOME
5
5
  zipStorePath=wrapper/dists
6
- distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
package/android/gradlew CHANGED
@@ -1,5 +1,21 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
+ #
4
+ # Copyright 2015 the original author or authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
3
19
  ##############################################################################
4
20
  ##
5
21
  ## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
28
44
  APP_BASE_NAME=`basename "$0"`
29
45
 
30
46
  # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31
- DEFAULT_JVM_OPTS=""
47
+ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
32
48
 
33
49
  # Use the maximum available, or set MAX_FD != -1 to use that value.
34
50
  MAX_FD="maximum"
@@ -56,7 +72,7 @@ case "`uname`" in
56
72
  Darwin* )
57
73
  darwin=true
58
74
  ;;
59
- MINGW* )
75
+ MSYS* | MINGW* )
60
76
  msys=true
61
77
  ;;
62
78
  NONSTOP* )
@@ -66,6 +82,7 @@ esac
66
82
 
67
83
  CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68
84
 
85
+
69
86
  # Determine the Java command to use to start the JVM.
70
87
  if [ -n "$JAVA_HOME" ] ; then
71
88
  if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -109,10 +126,11 @@ if $darwin; then
109
126
  GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110
127
  fi
111
128
 
112
- # For Cygwin, switch paths to Windows format before running java
113
- if $cygwin ; then
129
+ # For Cygwin or MSYS, switch paths to Windows format before running java
130
+ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
114
131
  APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115
132
  CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133
+
116
134
  JAVACMD=`cygpath --unix "$JAVACMD"`
117
135
 
118
136
  # We build the pattern for arguments to be converted via cygpath
@@ -138,19 +156,19 @@ if $cygwin ; then
138
156
  else
139
157
  eval `echo args$i`="\"$arg\""
140
158
  fi
141
- i=$((i+1))
159
+ i=`expr $i + 1`
142
160
  done
143
161
  case $i in
144
- (0) set -- ;;
145
- (1) set -- "$args0" ;;
146
- (2) set -- "$args0" "$args1" ;;
147
- (3) set -- "$args0" "$args1" "$args2" ;;
148
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
162
+ 0) set -- ;;
163
+ 1) set -- "$args0" ;;
164
+ 2) set -- "$args0" "$args1" ;;
165
+ 3) set -- "$args0" "$args1" "$args2" ;;
166
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154
172
  esac
155
173
  fi
156
174
 
@@ -159,14 +177,9 @@ save () {
159
177
  for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160
178
  echo " "
161
179
  }
162
- APP_ARGS=$(save "$@")
180
+ APP_ARGS=`save "$@"`
163
181
 
164
182
  # Collect all arguments for the java command, following the shell quoting and substitution rules
165
183
  eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166
184
 
167
- # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168
- if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169
- cd "$(dirname "$0")"
170
- fi
171
-
172
185
  exec "$JAVACMD" "$@"
@@ -1,3 +1,19 @@
1
+ @rem
2
+ @rem Copyright 2015 the original author or authors.
3
+ @rem
4
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
5
+ @rem you may not use this file except in compliance with the License.
6
+ @rem You may obtain a copy of the License at
7
+ @rem
8
+ @rem https://www.apache.org/licenses/LICENSE-2.0
9
+ @rem
10
+ @rem Unless required by applicable law or agreed to in writing, software
11
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
12
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ @rem See the License for the specific language governing permissions and
14
+ @rem limitations under the License.
15
+ @rem
16
+
1
17
  @if "%DEBUG%" == "" @echo off
2
18
  @rem ##########################################################################
3
19
  @rem
@@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
13
29
  set APP_BASE_NAME=%~n0
14
30
  set APP_HOME=%DIRNAME%
15
31
 
32
+ @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33
+ for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34
+
16
35
  @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17
- set DEFAULT_JVM_OPTS=
36
+ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
18
37
 
19
38
  @rem Find java.exe
20
39
  if defined JAVA_HOME goto findJavaFromJavaHome
21
40
 
22
41
  set JAVA_EXE=java.exe
23
42
  %JAVA_EXE% -version >NUL 2>&1
24
- if "%ERRORLEVEL%" == "0" goto init
43
+ if "%ERRORLEVEL%" == "0" goto execute
25
44
 
26
45
  echo.
27
46
  echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -35,7 +54,7 @@ goto fail
35
54
  set JAVA_HOME=%JAVA_HOME:"=%
36
55
  set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
56
 
38
- if exist "%JAVA_EXE%" goto init
57
+ if exist "%JAVA_EXE%" goto execute
39
58
 
40
59
  echo.
41
60
  echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -45,28 +64,14 @@ echo location of your Java installation.
45
64
 
46
65
  goto fail
47
66
 
48
- :init
49
- @rem Get command-line arguments, handling Windows variants
50
-
51
- if not "%OS%" == "Windows_NT" goto win9xME_args
52
-
53
- :win9xME_args
54
- @rem Slurp the command line arguments.
55
- set CMD_LINE_ARGS=
56
- set _SKIP=2
57
-
58
- :win9xME_args_slurp
59
- if "x%~1" == "x" goto execute
60
-
61
- set CMD_LINE_ARGS=%*
62
-
63
67
  :execute
64
68
  @rem Setup the command line
65
69
 
66
70
  set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67
71
 
72
+
68
73
  @rem Execute Gradle
69
- "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
74
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
70
75
 
71
76
  :end
72
77
  @rem End local scope for the variables with windows NT shell
@@ -1,11 +1,6 @@
1
+
1
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
3
  package="com.dashx.rn.sdk">
3
4
 
4
- <application>
5
- <service android:name=".DashXMessagingService" android:exported="false">
6
- <intent-filter>
7
- <action android:name="com.google.firebase.MESSAGING_EVENT" />
8
- </intent-filter>
9
- </service>
10
- </application>
11
5
  </manifest>
6
+
@@ -0,0 +1,250 @@
1
+ package com.dashx.rn.sdk
2
+
3
+ import android.annotation.TargetApi
4
+ import android.content.Context
5
+ import android.database.Cursor
6
+ import android.net.Uri
7
+ import android.os.Build
8
+ import android.provider.DocumentsContract
9
+ import android.provider.MediaStore
10
+ import com.dashx.rn.sdk.util.*
11
+ import com.dashx.sdk.DashXLog
12
+ import com.dashx.sdk.data.ExternalAsset
13
+ import com.facebook.react.bridge.*
14
+ import com.google.gson.Gson
15
+ import java.io.File
16
+ import com.dashx.sdk.DashXClient as DashX
17
+
18
+
19
+ class DashXReactNativeModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
20
+ private val tag = DashXReactNativeModule::class.java.simpleName
21
+ private var dashXClient: DashX? = null
22
+
23
+ override fun getName(): String {
24
+ return "DashXReactNative"
25
+ }
26
+
27
+ @ReactMethod
28
+ fun setLogLevel(logLevel: Int) {
29
+ DashXLog.setLogLevel(logLevel)
30
+ }
31
+
32
+ @ReactMethod
33
+ fun configure(options: ReadableMap) {
34
+ dashXClient = DashX.createInstance(
35
+ reactContext,
36
+ options.getString("publicKey")!!,
37
+ options.getStringIfPresent("baseURI"),
38
+ options.getStringIfPresent("targetEnvironment")
39
+ )
40
+ }
41
+
42
+ @ReactMethod
43
+ fun identify(options: ReadableMap?) {
44
+ val optionsHashMap = MapUtil.toMap(options)
45
+ dashXClient?.identify(optionsHashMap as HashMap<String, String>?)
46
+ }
47
+
48
+ @ReactMethod
49
+ fun setIdentity(uid: String?, token: String?) {
50
+ dashXClient?.setIdentity(uid, token)
51
+ }
52
+
53
+ @ReactMethod
54
+ fun reset() {
55
+ dashXClient?.reset()
56
+ }
57
+
58
+ @ReactMethod
59
+ fun track(event: String, data: ReadableMap?) {
60
+ val jsonData = try {
61
+ MapUtil.toMap(data) as HashMap<String, String>
62
+ } catch (e: Exception) {
63
+ DashXLog.d(tag, e.message)
64
+ return
65
+ }
66
+
67
+ dashXClient?.track(event, jsonData)
68
+ }
69
+
70
+ @ReactMethod
71
+ fun screen(screenName: String, data: ReadableMap?) {
72
+ dashXClient?.screen(screenName, MapUtil.toMap(data) as HashMap<String, String>)
73
+ }
74
+
75
+ @ReactMethod
76
+ fun fetchContent(urn: String, options: ReadableMap?, promise: Promise) {
77
+ dashXClient?.fetchContent(
78
+ urn,
79
+ options?.getBooleanIfPresent("preview"),
80
+ options?.getStringIfPresent("language"),
81
+ listOf(options?.getArray("fields")) as List<String>?,
82
+ listOf(options?.getArray("include")) as List<String>?,
83
+ listOf(options?.getArray("exclude")) as List<String>?,
84
+ onError = {
85
+ promise.reject("EUNSPECIFIED", it)
86
+ },
87
+ onSuccess = {
88
+ promise.resolve(convertJsonToMap(it))
89
+ }
90
+ )
91
+ }
92
+
93
+ @ReactMethod
94
+ fun searchContent(contentType: String, options: ReadableMap?, promise: Promise) {
95
+ val jsonFilter = try {
96
+ convertMapToJson(options?.getMap("filter"))
97
+ } catch (e: Exception) {
98
+ DashXLog.d(tag, e.message)
99
+ throw Exception("Encountered an error while parsing filter")
100
+ }
101
+
102
+ val jsonOrder = try {
103
+ convertMapToJson(options?.getMap("order"))
104
+ } catch (e: Exception) {
105
+ DashXLog.d(tag, e.message)
106
+ throw Exception("Encountered an error while parsing order")
107
+ }
108
+
109
+ dashXClient?.searchContent(
110
+ contentType,
111
+ options?.getString("returnType") ?: "all",
112
+ jsonFilter,
113
+ jsonOrder,
114
+ options?.getIntIfPresent("limit"),
115
+ options?.getBooleanIfPresent("preview"),
116
+ options?.getStringIfPresent("language"),
117
+ listOf(options?.getArray("fields")) as List<String>?,
118
+ listOf(options?.getArray("include")) as List<String>?,
119
+ listOf(options?.getArray("exclude")) as List<String>?,
120
+ onError = {
121
+ promise.reject("EUNSPECIFIED", it)
122
+ },
123
+ onSuccess = { content ->
124
+ val readableArray = Arguments.createArray()
125
+ content.forEach {
126
+ readableArray.pushMap(convertJsonToMap(it))
127
+ }
128
+ promise.resolve(readableArray)
129
+ }
130
+ )
131
+ }
132
+
133
+ @ReactMethod
134
+ fun addItemToCart(
135
+ itemId: String,
136
+ pricingId: String,
137
+ quantity: String,
138
+ reset: Boolean? = false,
139
+ custom: ReadableMap? = null,
140
+ promise: Promise
141
+ ) {
142
+ val jsonCustom = try {
143
+ convertMapToJson(custom)
144
+ } catch (e: Exception) {
145
+ DashXLog.d(tag, e.message)
146
+ throw Exception("Encountered an error while parsing custom")
147
+ }
148
+
149
+ dashXClient?.addItemToCart(
150
+ itemId,
151
+ pricingId,
152
+ quantity,
153
+ reset ?: false,
154
+ jsonCustom,
155
+ onError = {
156
+ promise.reject("EUNSPECIFIED", it)
157
+ },
158
+ onSuccess = { content ->
159
+ promise.resolve(convertJsonToMap(content))
160
+ }
161
+ )
162
+ }
163
+
164
+ @ReactMethod
165
+ fun fetchCart(promise: Promise) {
166
+ dashXClient?.fetchCart(
167
+ onError = {
168
+ promise.reject("EUNSPECIFIED", it)
169
+ },
170
+ onSuccess = { content ->
171
+ promise.resolve(convertJsonToMap(content))
172
+ }
173
+ )
174
+ }
175
+
176
+ @ReactMethod
177
+ fun fetchStoredPreferences(promise: Promise) {
178
+ dashXClient?.fetchStoredPreferences(
179
+ onError = {
180
+ promise.reject("EUNSPECIFIED", it)
181
+ },
182
+ onSuccess = { content ->
183
+ promise.resolve(convertJsonToMap(content))
184
+ }
185
+ )
186
+ }
187
+
188
+ @ReactMethod
189
+ fun uploadExternalAsset(
190
+ file: ReadableMap,
191
+ externalColumnId: String,
192
+ promise: Promise
193
+ ) {
194
+ val jsonFile = try {
195
+ convertMapToJson(file)
196
+ } catch (e: Exception) {
197
+ DashXLog.d(tag, e.message)
198
+ throw Exception("Encountered an error while parsing file")
199
+ }
200
+
201
+ // Remove unnecessary double quotes from RN URI
202
+ val filePath = getFilePathFromURIString(jsonFile?.get("uri").toString())
203
+ val fileObject = File(filePath)
204
+
205
+ dashXClient?.uploadExternalAsset(
206
+ fileObject,
207
+ externalColumnId,
208
+ onError = {
209
+ promise.reject("EUNSPECIFIED", it)
210
+ },
211
+ onSuccess = { content ->
212
+ val jsonObject = Gson().toJsonTree(content, ExternalAsset::class.java).asJsonObject
213
+ promise.resolve(convertJsonToMap(jsonObject))
214
+ }
215
+ )
216
+ }
217
+
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
+ @ReactMethod
236
+ fun subscribe() {
237
+ dashXClient?.subscribe()
238
+ }
239
+
240
+ //FIXME Amend the logic to work with React Native content URIs
241
+ fun getFilePathFromURIString(contentUriString: String): String {
242
+ val sanitizedURI = contentUriString.replace("\"", "")
243
+ val path = Uri.parse(sanitizedURI).path
244
+
245
+ // Remove unnecessary URI component
246
+ val filePath = path!!.substring(path?.indexOf(':') + 1)
247
+
248
+ return filePath
249
+ }
250
+ }
@@ -1,6 +1,7 @@
1
1
  package com.dashx.rn.sdk
2
2
 
3
3
  import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.JavaScriptModule
4
5
  import com.facebook.react.bridge.NativeModule
5
6
  import com.facebook.react.bridge.ReactApplicationContext
6
7
  import com.facebook.react.uimanager.ViewManager
@@ -8,7 +9,7 @@ import java.util.Arrays
8
9
 
9
10
  class DashXPackage : ReactPackage {
10
11
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
- return Arrays.asList<NativeModule>(DashXModule(reactContext))
12
+ return Arrays.asList<NativeModule>(DashXReactNativeModule(reactContext))
12
13
  }
13
14
 
14
15
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {