idwise-cordova-sdk 0.1.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/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "idwise-cordova-sdk",
3
+ "version": "0.1.0",
4
+ "description": "IDWise SDK wrapper for Cordova projects",
5
+ "cordova": {
6
+ "id": "idwise-cordova-sdk",
7
+ "platforms": [
8
+ "ios",
9
+ "android"
10
+ ]
11
+ },
12
+ "keywords": [
13
+ "ecosystem:cordova",
14
+ "cordova-ios",
15
+ "cordova-android"
16
+ ],
17
+ "author": "Waqar-Khan",
18
+ "license": "ISC"
19
+ }
package/plugin.xml ADDED
@@ -0,0 +1,41 @@
1
+ <?xml version='1.0' encoding='utf-8'?>
2
+ <plugin id="idwise-cordova-sdk" version="0.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
+ xmlns:android="http://schemas.android.com/apk/res/android">
4
+ <name>IDWiseCordovaSDK</name>
5
+ <js-module name="IDWiseCordovaSDK" src="www/IDWiseCordovaSDK.js">
6
+ <clobbers target="IDWise" />
7
+ <!-- <clobbers target="IDWise" />-->
8
+ </js-module>
9
+ <platform name="ios">
10
+ <config-file parent="/*" target="config.xml">
11
+ <preference name="UseSwiftLanguageVersion" value="4.2" />
12
+ <preference name="deployment-target" value="12.0" />
13
+ <feature name="IDWiseCordovaSDK">
14
+ <param name="ios-package" value="IDWiseCordovaSDK" />
15
+ </feature>
16
+ </config-file>
17
+ <source-file src="src/ios/IDWiseCordovaSDK.swift" />
18
+ <!-- <<framework src="src/ios/IDWiseSDK.xcframework" custom="true" embed="true" />-->
19
+ <podspec>
20
+ <config>
21
+ <source url="https://cdn.cocoapods.org/" />
22
+ <source url="https://github.com/idwise/ios-sdk.git" />
23
+ </config>
24
+ <pods use-frameworks="true">
25
+ <pod name="IDWise" />
26
+ </pods>
27
+ </podspec>
28
+ </platform>
29
+ <platform name="android">
30
+ <config-file parent="/*" target="res/xml/config.xml">
31
+ <preference name="GradlePluginKotlinEnabled" value="true" />
32
+ <feature name="IDWiseCordovaSDK">
33
+ <param name="android-package" value="idwise_cordova_sdk.IDWiseCordovaSDK" />
34
+ </feature>
35
+ </config-file>
36
+ <config-file parent="/*" target="AndroidManifest.xml"></config-file>
37
+ <source-file src="src/android/IDWiseCordovaSDK.kt"
38
+ target-dir="src/main/java/idwise_cordova_sdk/IDWiseCordovaSDK" />
39
+ <framework custom="true" src="src/android/idwise-sdk.gradle" type="gradleReference" />
40
+ </platform>
41
+ </plugin>
@@ -0,0 +1,155 @@
1
+ package idwise_cordova_sdk;
2
+
3
+ import android.util.Log
4
+ import com.idwise.sdk.IDWise
5
+ import com.idwise.sdk.IDWiseSDKCallback
6
+ import com.idwise.sdk.data.models.IDWiseSDKError
7
+ import com.idwise.sdk.data.models.IDWiseSDKTheme
8
+ import com.idwise.sdk.data.models.JourneyInfo
9
+ import org.apache.cordova.CallbackContext
10
+ import org.apache.cordova.CordovaPlugin
11
+ import org.apache.cordova.PluginResult
12
+ import org.json.JSONArray
13
+ import org.json.JSONException
14
+ import org.json.JSONObject
15
+
16
+
17
+ /**
18
+ * This class echoes a string called from JavaScript.
19
+ */
20
+ class IDWiseCordovaSDK : CordovaPlugin() {
21
+ @Throws(JSONException::class)
22
+ override fun execute(
23
+ action: String,
24
+ args: JSONArray,
25
+ callbackContext: CallbackContext
26
+ ): Boolean {
27
+ when (action) {
28
+ "initialize" -> {
29
+ val clientKey = args.getString(0)
30
+ val theme = args.getString(1)
31
+
32
+ val idwiseTheme: IDWiseSDKTheme = try {
33
+ IDWiseSDKTheme.valueOf(theme!!)
34
+ } catch (e: Exception) {
35
+ IDWiseSDKTheme.SYSTEM_DEFAULT
36
+ }
37
+
38
+ clientKey?.let {
39
+ initialize(it, idwiseTheme, callbackContext)
40
+ }
41
+ return true
42
+ }
43
+
44
+ "startJourney" -> {
45
+ val flowId = args.getString(0)
46
+ val referenceNumber = args.getString(1)
47
+ val locale = args.getString(2)
48
+ startJourney(flowId, referenceNumber, locale, callbackContext)
49
+ return true
50
+ }
51
+ }
52
+ return false
53
+ }
54
+
55
+ private fun initialize(
56
+ clientKey: String,
57
+ theme: IDWiseSDKTheme,
58
+ callbackContext: CallbackContext
59
+ ) {
60
+
61
+ IDWise.initialize(clientKey, theme) { error: IDWiseSDKError? ->
62
+ Log.e("IDWISE", "onInitializeError: ${error?.message}")
63
+ callbackContext.error("onError: ${error?.message}")
64
+ }
65
+ }
66
+
67
+ private fun startJourney(
68
+ flowId: String,
69
+ referenceNumber: String,
70
+ locale: String,
71
+ callbackContext: CallbackContext
72
+ ) {
73
+ IDWise.startJourney(
74
+ this.cordova.activity,
75
+ flowId,
76
+ referenceNumber,
77
+ locale,
78
+ object : IDWiseSDKCallback {
79
+ override fun onJourneyStarted(journeyInfo: JourneyInfo) {
80
+ val params = JSONObject()
81
+ params.put("event", "onJourneyStarted")
82
+
83
+ val data = JSONObject()
84
+ data.put("journeyId", journeyInfo.journeyId)
85
+ params.put("data", data)
86
+
87
+ val result = PluginResult(PluginResult.Status.OK, params)
88
+ result.keepCallback = true
89
+
90
+ callbackContext.sendPluginResult(result)
91
+ }
92
+
93
+ override fun onJourneyResumed(journeyInfo: JourneyInfo) {
94
+ val params = JSONObject()
95
+ params.put("event", "onJourneyResumed")
96
+
97
+ val data = JSONObject()
98
+ data.put("journeyId", journeyInfo.journeyId)
99
+ params.put("data", data)
100
+
101
+ val result = PluginResult(PluginResult.Status.OK, params)
102
+ result.keepCallback = true
103
+
104
+ callbackContext.sendPluginResult(result)
105
+ }
106
+
107
+ override fun onJourneyCompleted(
108
+ journeyInfo: JourneyInfo,
109
+ isSucceeded: Boolean
110
+ ) {
111
+ val params = JSONObject()
112
+ params.put("event", "onJourneyCompleted")
113
+
114
+ val data = JSONObject()
115
+ data.put("journeyId", journeyInfo.journeyId)
116
+ params.put("data", data)
117
+
118
+ val result = PluginResult(PluginResult.Status.OK, params)
119
+ result.keepCallback = false
120
+
121
+ callbackContext.sendPluginResult(result)
122
+ }
123
+
124
+ override fun onJourneyCancelled(journeyInfo: JourneyInfo?) {
125
+ val params = JSONObject()
126
+ params.put("event", "onJourneyCancelled")
127
+
128
+ val data = JSONObject()
129
+ data.put("journeyId", journeyInfo?.journeyId?:"")
130
+ params.put("data", data)
131
+
132
+ val result = PluginResult(PluginResult.Status.OK, params)
133
+ result.keepCallback = false
134
+
135
+ callbackContext.sendPluginResult(result)
136
+
137
+ }
138
+
139
+ override fun onError(error: IDWiseSDKError) {
140
+ val params = JSONObject()
141
+ params.put("event", "onError")
142
+
143
+ val data = JSONObject()
144
+ data.put("errorCode", error.errorCode)
145
+ data.put("message", error.message)
146
+ params.put("data", data)
147
+
148
+ val result = PluginResult(PluginResult.Status.ERROR, params)
149
+ result.keepCallback = true
150
+ callbackContext.sendPluginResult(result)
151
+ }
152
+ }
153
+ )
154
+ }
155
+ }
@@ -0,0 +1,3 @@
1
+ dependencies {
2
+ implementation 'com.idwise:android-sdk:4.5.0'
3
+ }
@@ -0,0 +1,97 @@
1
+ import IDWiseSDK
2
+
3
+ @objc(IDWiseCordovaSDK) class IDWiseCordovaSDK: CDVPlugin {
4
+ // Member variables go here.
5
+
6
+ var journeyCallbackId: String = ""
7
+ var journeyID = ""
8
+
9
+ @objc(initialize:)
10
+ func initialize(_ command: CDVInvokedUrlCommand) {
11
+ let clientKey = command.arguments[0] as? String ?? ""
12
+ IDWise.initialize(clientKey: clientKey, theme: .systemDefault) { err in
13
+ // Deal with error here
14
+ if let error = err {
15
+ print(error)
16
+ var pluginResult = CDVPluginResult(
17
+ status: CDVCommandStatus_ERROR,
18
+ messageAs: error.message
19
+ )
20
+ self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
21
+
22
+ }
23
+ }
24
+ }
25
+
26
+ @objc(startJourney:)
27
+ func startJourney(_ command: CDVInvokedUrlCommand) {
28
+ let flowId = command.arguments[0] as? String ?? ""
29
+ self.journeyCallbackId = command.callbackId
30
+
31
+ IDWise.startJourney(
32
+ journeyDefinitionId: flowId, referenceNumber: "<YOUR_REFERENCE_NO>",
33
+ locale: "en", journeyDelegate: self)
34
+ }
35
+ }
36
+
37
+ extension IDWiseCordovaSDK: IDWiseSDKJourneyDelegate {
38
+ func onError(error: IDWiseSDKError) {
39
+ var pluginResult = CDVPluginResult(
40
+ status: CDVCommandStatus_ERROR,
41
+ messageAs: error.message
42
+ )
43
+ pluginResult?.keepCallback = true
44
+ self.commandDelegate!.send(pluginResult, callbackId: self.journeyCallbackId)
45
+ }
46
+
47
+ func JourneyCancelled() {
48
+ let arguments =
49
+ ["event": "onJourneyCancelled", "data": ["journeyId": self.journeyID] as [String: Any]]
50
+ as [String: Any]
51
+ var pluginResult = CDVPluginResult(
52
+ status: CDVCommandStatus_OK,
53
+ messageAs: arguments
54
+ )
55
+ pluginResult?.keepCallback = true
56
+ self.commandDelegate!.send(pluginResult, callbackId: self.journeyCallbackId)
57
+ }
58
+
59
+ func JourneyStarted(journeyID: String) {
60
+ self.journeyID = journeyID
61
+ let arguments =
62
+ ["event": "onJourneyStarted", "data": ["journeyId": journeyID] as [String: Any]]
63
+ as [String: Any]
64
+ var pluginResult = CDVPluginResult(
65
+ status: CDVCommandStatus_OK,
66
+ messageAs: arguments
67
+ )
68
+ pluginResult?.keepCallback = true
69
+ self.commandDelegate!.send(pluginResult, callbackId: self.journeyCallbackId)
70
+ }
71
+
72
+ func onJourneyResumed(journeyID: String) {
73
+ self.journeyID = journeyID
74
+ let arguments =
75
+ ["event": "onJourneyResumed", "data": ["journeyId": journeyID] as [String: Any]]
76
+ as [String: Any]
77
+ var pluginResult = CDVPluginResult(
78
+ status: CDVCommandStatus_OK,
79
+ messageAs: arguments
80
+ )
81
+ pluginResult?.keepCallback = true
82
+ self.commandDelegate!.send(pluginResult, callbackId: self.journeyCallbackId)
83
+
84
+ }
85
+
86
+ func JourneyFinished() {
87
+ let arguments =
88
+ ["event": "onJourneyCompleted", "data": ["journeyId": self.journeyID] as [String: Any]]
89
+ as [String: Any]
90
+ var pluginResult = CDVPluginResult(
91
+ status: CDVCommandStatus_OK,
92
+ messageAs: arguments
93
+ )
94
+ pluginResult?.keepCallback = true
95
+ self.commandDelegate!.send(pluginResult, callbackId: self.journeyCallbackId)
96
+ }
97
+ }
@@ -0,0 +1,39 @@
1
+ var exec = require('cordova/exec');
2
+
3
+ exports.initialize = function (clientKey,theme, error) {
4
+ console.log("IDWISE.JS -> initialize");
5
+ function success(result){
6
+ //dummy success required to pass to exec
7
+ }
8
+ exec(success, error, 'IDWiseCordovaSDK', 'initialize', [clientKey, theme]);
9
+ };
10
+
11
+
12
+ exports.startJourney = function (flowId, referenceNo, locale, journeyCallback) {
13
+
14
+ function success(result){
15
+ switch(result.event) {
16
+ case "onJourneyStarted":
17
+ journeyCallback.onJourneyStarted(result.data);
18
+ break;
19
+ case "onJourneyResumed":
20
+ journeyCallback.onJourneyResumed(result.data);
21
+ break;
22
+ case "onJourneyCompleted":
23
+ journeyCallback.onJourneyCompleted(result.data);
24
+ break;
25
+ case "onJourneyCancelled":
26
+ journeyCallback.onJourneyCancelled(result.data);
27
+ break;
28
+
29
+ default:
30
+ console.log("unknown event call", result.event);
31
+ }
32
+ }
33
+
34
+ function error(error){
35
+ journeyCallback.onError(error.data);
36
+ }
37
+
38
+ exec(success, error, 'IDWiseCordovaSDK', 'startJourney', [flowId, referenceNo, locale]);
39
+ };