@velocitycareerlabs/vcl-react-native 1.14.6 → 1.14.7

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,20 @@
1
+ /**
2
+ * Created by Michael Avoyan on 08/08/2023.
3
+ *
4
+ * Copyright 2022 Velocity Career Labs inc.
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ package io.velocitycareerlabs.reactnative
9
+
10
+ import io.velocitycareerlabs.api.VCLEnvironment
11
+
12
+ internal object GlobalConfig {
13
+
14
+ var CurrentEnvironment = VCLEnvironment.Prod
15
+
16
+ var IsDebugOn = false //BuildConfig.DEBUG
17
+
18
+ const val LogTagPrefix = "VCL RN Android "
19
+ val IsLoggerOn get() = CurrentEnvironment != VCLEnvironment.Prod || IsDebugOn
20
+ }
@@ -35,11 +35,13 @@ import io.velocitycareerlabs.reactnative.utlis.Converter.mapToVerifiedProfileDes
35
35
  import io.velocitycareerlabs.reactnative.utlis.Converter.verifiedProfileToMap
36
36
  import io.velocitycareerlabs.api.VCLProvider
37
37
  import io.velocitycareerlabs.api.entities.VCLError
38
+ import io.velocitycareerlabs.api.entities.VCLInitializationDescriptor
38
39
  import io.velocitycareerlabs.reactnative.extensions.toThrowable
39
40
  import io.velocitycareerlabs.reactnative.utlis.Converter.didJwkToMap
40
41
  import io.velocitycareerlabs.reactnative.utlis.Converter.mapToDidJwk
41
42
  import io.velocitycareerlabs.reactnative.utlis.Converter.mapToInitializationDescriptor
42
43
  import io.velocitycareerlabs.reactnative.utlis.Converter.mapToJwtDescriptor
44
+ import io.velocitycareerlabs.reactnative.utlis.VCLLog
43
45
  import java.lang.Exception
44
46
 
45
47
  /**
@@ -47,6 +49,8 @@ import java.lang.Exception
47
49
  */
48
50
  class VclReactNativeModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
49
51
 
52
+ val TAG = "VclReactNativeModule"
53
+
50
54
  companion object {
51
55
  const val ModuleName = "VclReactNative"
52
56
  }
@@ -57,17 +61,26 @@ class VclReactNativeModule(private val reactContext: ReactApplicationContext) :
57
61
  return ModuleName
58
62
  }
59
63
 
64
+ private fun initGlobalConfigurations(
65
+ initializationDescriptor: VCLInitializationDescriptor
66
+ ) {
67
+ GlobalConfig.CurrentEnvironment = initializationDescriptor.environment
68
+ GlobalConfig.IsDebugOn = initializationDescriptor.isDebugOn
69
+ }
70
+
60
71
  @ReactMethod
61
72
  fun initialize(
62
- initializationDescriptor: ReadableMap,
73
+ initializationDescriptorMap: ReadableMap,
63
74
  promise: Promise
64
75
  ) {
65
76
  try {
77
+ val initializationDescriptor = mapToInitializationDescriptor(
78
+ initializationDescriptorMap
79
+ )
80
+ initGlobalConfigurations(initializationDescriptor)
66
81
  vcl.initialize(
67
82
  context = reactContext.applicationContext,
68
- initializationDescriptor = mapToInitializationDescriptor(
69
- initializationDescriptor
70
- ),
83
+ initializationDescriptor = initializationDescriptor,
71
84
  successHandler = {
72
85
  promise.resolve("VCL initialization succeed!")
73
86
  },
@@ -192,7 +205,9 @@ class VclReactNativeModule(private val reactContext: ReactApplicationContext) :
192
205
  promise: Promise
193
206
  ) {
194
207
  try {
208
+ VCLLog.d(TAG, "credentialManifestDescriptorMap map: $credentialManifestDescriptorMap")
195
209
  mapToCredentialManifestDescriptor(credentialManifestDescriptorMap)?.let { credentialManifestDescriptor ->
210
+ VCLLog.d(TAG, "credentialManifestDescriptor VCL entity: ${credentialManifestDescriptor.toPropsString()}")
196
211
  vcl.getCredentialManifest(credentialManifestDescriptor,
197
212
  {
198
213
  promise.resolve(credentialManifestToMap(it))
@@ -15,9 +15,6 @@ import org.json.JSONArray
15
15
  import org.json.JSONObject
16
16
  import java.lang.Exception
17
17
 
18
- /**
19
- * Created by Michael Avoyan on 04/07/2021.
20
- */
21
18
  object Converter {
22
19
 
23
20
  fun mapToInitializationDescriptor(
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Created by Michael Avoyan on 08/08/2023.
3
+ *
4
+ * Copyright 2022 Velocity Career Labs inc.
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ package io.velocitycareerlabs.reactnative.utlis
9
+
10
+ import android.util.Log
11
+ import io.velocitycareerlabs.reactnative.GlobalConfig
12
+
13
+ internal object VCLLog {
14
+ /**
15
+ * Send a [.VERBOSE] log message.
16
+ * @param tag Used to identify the source of a log message. It usually identifies
17
+ * the class or activity where the log call occurs.
18
+ * @param msg The message you would like logged.
19
+ */
20
+ fun v(tag: String?, msg: String): Int {
21
+ return if (GlobalConfig.IsLoggerOn) Log.v(GlobalConfig.LogTagPrefix +tag, msg) else -1
22
+ }
23
+
24
+ /**
25
+ * Send a [.VERBOSE] log message and log the exception.
26
+ * @param tag Used to identify the source of a log message. It usually identifies
27
+ * the class or activity where the log call occurs.
28
+ * @param msg The message you would like logged.
29
+ * @param tr An exception to log
30
+ */
31
+ fun v(tag: String?, msg: String?, tr: Throwable?): Int {
32
+ return if (GlobalConfig.IsLoggerOn) Log.v(GlobalConfig.LogTagPrefix +tag, msg, tr) else -1
33
+ }
34
+
35
+ /**
36
+ * Send a [.DEBUG] log message.
37
+ * @param tag Used to identify the source of a log message. It usually identifies
38
+ * the class or activity where the log call occurs.
39
+ * @param msg The message you would like logged.
40
+ */
41
+ fun d(tag: String?, msg: String): Int {
42
+ return if (GlobalConfig.IsLoggerOn) Log.d(GlobalConfig.LogTagPrefix +tag, msg) else -1
43
+ }
44
+
45
+ /**
46
+ * Send a [.DEBUG] log message and log the exception.
47
+ * @param tag Used to identify the source of a log message. It usually identifies
48
+ * the class or activity where the log call occurs.
49
+ * @param msg The message you would like logged.
50
+ * @param tr An exception to log
51
+ */
52
+ fun d(tag: String?, msg: String?, tr: Throwable?): Int {
53
+ return if (GlobalConfig.IsLoggerOn) Log.d(GlobalConfig.LogTagPrefix +tag, msg, tr) else -1
54
+ }
55
+
56
+ /**
57
+ * Send an [.INFO] log message.
58
+ * @param tag Used to identify the source of a log message. It usually identifies
59
+ * the class or activity where the log call occurs.
60
+ * @param msg The message you would like logged.
61
+ */
62
+ fun i(tag: String?, msg: String): Int {
63
+ return if (GlobalConfig.IsLoggerOn) Log.i(GlobalConfig.LogTagPrefix +tag, msg) else -1
64
+ }
65
+
66
+ /**
67
+ * Send a [.INFO] log message and log the exception.
68
+ * @param tag Used to identify the source of a log message. It usually identifies
69
+ * the class or activity where the log call occurs.
70
+ * @param msg The message you would like logged.
71
+ * @param tr An exception to log
72
+ */
73
+ fun i(tag: String?, msg: String?, tr: Throwable?): Int {
74
+ return if (GlobalConfig.IsLoggerOn) Log.i(GlobalConfig.LogTagPrefix +tag, msg, tr) else -1
75
+ }
76
+
77
+ /**
78
+ * Send a [.WARN] log message.
79
+ * @param tag Used to identify the source of a log message. It usually identifies
80
+ * the class or activity where the log call occurs.
81
+ * @param msg The message you would like logged.
82
+ */
83
+ fun w(tag: String?, msg: String): Int {
84
+ return if (GlobalConfig.IsLoggerOn) Log.w(GlobalConfig.LogTagPrefix +tag, msg) else -1
85
+ }
86
+
87
+ /**
88
+ * Send a [.WARN] log message and log the exception.
89
+ * @param tag Used to identify the source of a log message. It usually identifies
90
+ * the class or activity where the log call occurs.
91
+ * @param msg The message you would like logged.
92
+ * @param tr An exception to log
93
+ */
94
+ fun w(tag: String?, msg: String?, tr: Throwable?): Int {
95
+ return if (GlobalConfig.IsLoggerOn) Log.w(GlobalConfig.LogTagPrefix +tag, msg, tr) else -1
96
+ }
97
+
98
+ /*
99
+ * Send a {@link #WARN} log message and log the exception.
100
+ * @param tag Used to identify the source of a log message. It usually identifies
101
+ * the class or activity where the log call occurs.
102
+ * @param tr An exception to log
103
+ */
104
+ fun w(tag: String?, tr: Throwable?): Int {
105
+ return if (GlobalConfig.IsLoggerOn) Log.w(GlobalConfig.LogTagPrefix +tag, tr) else -1
106
+ }
107
+
108
+ /**
109
+ * Send an [.ERROR] log message.
110
+ * @param tag Used to identify the source of a log message. It usually identifies
111
+ * the class or activity where the log call occurs.
112
+ * @param msg The message you would like logged.
113
+ */
114
+ fun e(tag: String?, msg: String): Int {
115
+ return if (GlobalConfig.IsLoggerOn) Log.e(GlobalConfig.LogTagPrefix +tag, msg) else -1
116
+ }
117
+
118
+ /**
119
+ * Send a [.ERROR] log message and log the exception.
120
+ * @param tag Used to identify the source of a log message. It usually identifies
121
+ * the class or activity where the log call occurs.
122
+ * @param msg The message you would like logged.
123
+ * @param tr An exception to log
124
+ */
125
+ fun e(tag: String?, msg: String?, tr: Throwable?): Int {
126
+ return if (GlobalConfig.IsLoggerOn) Log.e(GlobalConfig.LogTagPrefix +tag, msg, tr) else -1
127
+ }
128
+ }
@@ -0,0 +1,42 @@
1
+ //
2
+ // VCLLog.swift
3
+ // vcl-react-native
4
+ //
5
+ // Created by Michael Avoyan on 08/08/2023.
6
+ //
7
+ // Copyright 2022 Velocity Career Labs inc.
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ import Foundation
11
+
12
+ struct VCLLog {
13
+
14
+ enum LogLevel: String {
15
+ case error = "⛔️"
16
+ case warning = "⚠️"
17
+ case debug = "💬"
18
+ }
19
+ static func d(_ info: String, level: LogLevel = .debug, file: String = #file, function: String = #function, line: Int = #line) {
20
+ if GlobalConfig.IsLoggerOn {
21
+ print("\(level.rawValue), \((file as NSString).lastPathComponent), \(line), \(function), \(GlobalConfig.LogTagPrefix + info)")
22
+ }
23
+ }
24
+
25
+ static func w(_ warning: String, level: LogLevel = .warning, file: String = #file, function: String = #function, line: Int = #line) {
26
+ if GlobalConfig.IsLoggerOn {
27
+ print("\(level.rawValue), \((file as NSString).lastPathComponent), \(line), \(function), \(GlobalConfig.LogTagPrefix + warning)")
28
+ }
29
+ }
30
+
31
+ static func e(_ error: Error, level: LogLevel = .error, file: String = #file, function: String = #function, line: Int = #line) {
32
+ if GlobalConfig.IsLoggerOn {
33
+ VCLLog.e("\(error)", level: level, file: file, function: function, line: line)
34
+ }
35
+ }
36
+
37
+ static func e(_ error: String, level: LogLevel = .error, file: String = #file, function: String = #function, line: Int = #line) {
38
+ if GlobalConfig.IsLoggerOn {
39
+ print("\(level.rawValue), \((file as NSString).lastPathComponent), \(line), \(function), \(GlobalConfig.LogTagPrefix + error)")
40
+ }
41
+ }
42
+ }
@@ -11,13 +11,22 @@ class VclReactNative: NSObject {
11
11
 
12
12
  private let vcl = VCLProvider.vclInstance()
13
13
 
14
+ private func initGlobalConfigurations(
15
+ _ initializationDescriptor: VCLInitializationDescriptor
16
+ ) {
17
+ GlobalConfig.CurrentEnvironment = initializationDescriptor.environment
18
+ GlobalConfig.IsDebugOn = initializationDescriptor.isDebugOn
19
+ }
20
+
14
21
  @objc(initialize:withResolver:withRejecter:)
15
22
  func initialize(
16
23
  initializationDescriptorDictionary: [String: Any],
17
24
  resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
18
25
  ) {
26
+ let initializationDescriptor = dictionaryToInitializationDescriptor(initializationDescriptorDictionary)
27
+ initGlobalConfigurations(initializationDescriptor)
19
28
  vcl.initialize(
20
- initializationDescriptor: dictionaryToInitializationDescriptor(initializationDescriptorDictionary),
29
+ initializationDescriptor: initializationDescriptor,
21
30
  successHandler: {
22
31
  resolve("VCL initialization succeed!")
23
32
  },
@@ -132,15 +141,17 @@ class VclReactNative: NSObject {
132
141
  credentialManifestDescriptorDictionary: [String: Any],
133
142
  resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
134
143
  ) {
144
+ VCLLog.d("credentialManifestDescriptorDictionary dictionary: \(credentialManifestDescriptorDictionary)")
135
145
  if let credentialManifestDescriptor = dictionaryToCredentialManifestDescriptor(credentialManifestDescriptorDictionary) {
136
- vcl.getCredentialManifest(
137
- credentialManifestDescriptor: credentialManifestDescriptor,
138
- successHandler: {
139
- resolve(credentialManifestToDictionary($0))
140
- },
141
- errorHandler: {
142
- reject(nil, $0.toDictionary().toJsonString(), $0)
143
- })
146
+ VCLLog.d("credentialManifestDescriptor VCL entity: \(credentialManifestDescriptor.toPropsString())")
147
+ vcl.getCredentialManifest(
148
+ credentialManifestDescriptor: credentialManifestDescriptor,
149
+ successHandler: {
150
+ resolve(credentialManifestToDictionary($0))
151
+ },
152
+ errorHandler: {
153
+ reject(nil, $0.toDictionary().toJsonString(), $0)
154
+ })
144
155
  } else {
145
156
  reject(nil, "Unexpected Credential Credential Manifest Descriptor: \(credentialManifestDescriptorDictionary)", nil)
146
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velocitycareerlabs/vcl-react-native",
3
- "version": "1.14.6",
3
+ "version": "1.14.7",
4
4
  "description": "Velocity Career Labs React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",