react-native-persona 2.25.2 → 2.26.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.
Files changed (54) hide show
  1. package/RNPersonaInquiry2.podspec +1 -1
  2. package/android/build.gradle +3 -2
  3. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  4. package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
  5. package/android/gradlew +174 -108
  6. package/android/gradlew.bat +12 -23
  7. package/android/src/main/java/com/withpersona/sdk2/reactnative/InquiryEventEmitter.java +110 -0
  8. package/android/src/main/java/com/withpersona/sdk2/reactnative/InquiryUtils.java +301 -0
  9. package/android/src/main/java/com/withpersona/sdk2/reactnative/PersonaInquiryModule2.java +12 -353
  10. package/android/src/main/java/com/withpersona/sdk2/reactnative/PersonaInquiryPackage2.java +7 -5
  11. package/android/src/main/java/com/withpersona/sdk2/reactnative/PersonaInquiryViewManager.java +190 -0
  12. package/android/src/main/res/values/ids.xml +4 -0
  13. package/ios/PersonaInquiry-Bridging-Header.h +2 -0
  14. package/ios/PersonaInquiry.xcodeproj/project.pbxproj +4 -0
  15. package/ios/PersonaInquiry2.swift +25 -23
  16. package/ios/PersonaInquiryBridge.m +13 -0
  17. package/ios/PersonaInquiryViewManager.swift +248 -0
  18. package/lib/commonjs/PersonaInquiryView.js +69 -0
  19. package/lib/commonjs/PersonaInquiryView.js.map +1 -0
  20. package/lib/commonjs/PersonaInquiryViewManager.js +10 -0
  21. package/lib/commonjs/PersonaInquiryViewManager.js.map +1 -0
  22. package/lib/commonjs/StepData.js +66 -0
  23. package/lib/commonjs/StepData.js.map +1 -0
  24. package/lib/commonjs/callbacks.js +6 -0
  25. package/lib/commonjs/callbacks.js.map +1 -0
  26. package/lib/commonjs/index.js +115 -143
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/util.js +71 -0
  29. package/lib/commonjs/util.js.map +1 -1
  30. package/lib/module/PersonaInquiryView.js +60 -0
  31. package/lib/module/PersonaInquiryView.js.map +1 -0
  32. package/lib/module/PersonaInquiryViewManager.js +5 -0
  33. package/lib/module/PersonaInquiryViewManager.js.map +1 -0
  34. package/lib/module/StepData.js +56 -0
  35. package/lib/module/StepData.js.map +1 -0
  36. package/lib/module/callbacks.js +2 -0
  37. package/lib/module/callbacks.js.map +1 -0
  38. package/lib/module/index.js +38 -142
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/util.js +67 -0
  41. package/lib/module/util.js.map +1 -1
  42. package/lib/typescript/PersonaInquiryView.d.ts +11 -0
  43. package/lib/typescript/PersonaInquiryViewManager.d.ts +1 -0
  44. package/lib/typescript/StepData.d.ts +56 -0
  45. package/lib/typescript/callbacks.d.ts +21 -0
  46. package/lib/typescript/index.d.ts +26 -68
  47. package/lib/typescript/util.d.ts +17 -0
  48. package/package.json +1 -1
  49. package/src/PersonaInquiryView.tsx +109 -0
  50. package/src/PersonaInquiryViewManager.ts +5 -0
  51. package/src/StepData.ts +83 -0
  52. package/src/callbacks.ts +37 -0
  53. package/src/index.ts +98 -221
  54. package/src/util.ts +111 -0
@@ -0,0 +1,301 @@
1
+ package com.withpersona.sdk2.reactnative;
2
+
3
+ import androidx.annotation.Nullable;
4
+
5
+ import com.facebook.react.bridge.Arguments;
6
+ import com.facebook.react.bridge.ReadableArray;
7
+ import com.facebook.react.bridge.ReadableMap;
8
+ import com.facebook.react.bridge.WritableArray;
9
+ import com.facebook.react.bridge.WritableMap;
10
+ import com.withpersona.sdk2.inquiry.ClientThemeSource;
11
+ import com.withpersona.sdk2.inquiry.Environment;
12
+ import com.withpersona.sdk2.inquiry.Fields;
13
+ import com.withpersona.sdk2.inquiry.Inquiry;
14
+ import com.withpersona.sdk2.inquiry.InquiryBuilder;
15
+ import com.withpersona.sdk2.inquiry.InquiryTemplateBuilder;
16
+ import com.withpersona.sdk2.inquiry.ServerThemeSource;
17
+ import com.withpersona.sdk2.inquiry.types.collected_data.CollectedData;
18
+ import com.withpersona.sdk2.inquiry.types.collected_data.DocumentFile;
19
+ import com.withpersona.sdk2.inquiry.types.collected_data.GovernmentIdCapture;
20
+ import com.withpersona.sdk2.inquiry.types.collected_data.SelfieCapture;
21
+ import com.withpersona.sdk2.inquiry.types.collected_data.StepData;
22
+
23
+ import java.util.HashMap;
24
+ import java.util.List;
25
+ import java.util.Map;
26
+ import java.util.Objects;
27
+
28
+ class InquiryUtils {
29
+ private static final String INQUIRY_ID = "inquiryId";
30
+ private static final String TEMPLATE_ID = "templateId";
31
+ private static final String TEMPLATE_VERSION = "templateVersion";
32
+ private static final String ACCOUNT_ID = "accountId";
33
+ private static final String REFERENCE_ID = "referenceId";
34
+ private static final String ACCESS_TOKEN = "sessionToken";
35
+ private static final String ENVIRONMENT = "environment";
36
+ private static final String ENVIRONMENT_ID = "environmentId";
37
+ private static final String FIELDS = "fields";
38
+ private static final String FIELD_ADDITIONAL_FIELDS = "additionalFields";
39
+ private static final String RETURN_COLLECTED_DATA = "returnCollectedData";
40
+ private static final String THEME_SOURCE = "themeSource";
41
+ private static final String THEME_SET_ID = "themeSetId";
42
+ private static final String LOCALE = "locale";
43
+
44
+ @Nullable
45
+ protected static Inquiry newInquiryFromMap(ReadableMap options) {
46
+ String inquiryId = options.hasKey(INQUIRY_ID) ? options.getString(INQUIRY_ID) : null;
47
+ String templateId = options.hasKey(TEMPLATE_ID) ? options.getString(TEMPLATE_ID) : null;
48
+ String templateVersion = options.hasKey(TEMPLATE_VERSION) ? options.getString(TEMPLATE_VERSION) : null;
49
+
50
+ if (inquiryId != null) {
51
+ InquiryBuilder builder = Inquiry.fromInquiry(inquiryId);
52
+
53
+ String themeSource = options.hasKey(THEME_SOURCE) ? options.getString(THEME_SOURCE) : null;
54
+ builder = builder.theme(themeSource != null && themeSource.equals("server") ?
55
+ new ServerThemeSource(R.style.Persona_Inquiry2_Theme) : new ClientThemeSource(R.style.Persona_Inquiry2_Theme));
56
+
57
+ String sessionToken = options.hasKey(ACCESS_TOKEN) ? options.getString(ACCESS_TOKEN) : null;
58
+ if (sessionToken != null) {
59
+ builder = builder.sessionToken(sessionToken);
60
+ }
61
+
62
+ String locale = options.hasKey(LOCALE) ? options.getString(LOCALE) : null;
63
+ if (locale != null) {
64
+ builder = builder.locale(locale);
65
+ }
66
+
67
+ return builder.build();
68
+ }
69
+
70
+ if (templateId != null || templateVersion != null) {
71
+ InquiryTemplateBuilder builder;
72
+ if (templateId != null) {
73
+ builder = Inquiry.fromTemplate(templateId);
74
+ } else {
75
+ builder = Inquiry.fromTemplateVersion(templateVersion);
76
+ }
77
+
78
+ String themeSource = options.hasKey(THEME_SOURCE) ? options.getString(THEME_SOURCE) : null;
79
+ builder = builder.theme(themeSource != null && themeSource.equals("server") ?
80
+ new ServerThemeSource(R.style.Persona_Inquiry2_Theme) : new ClientThemeSource(R.style.Persona_Inquiry2_Theme));
81
+
82
+ String referenceId = options.hasKey(REFERENCE_ID) ? options.getString(REFERENCE_ID) : null;
83
+ if (referenceId != null) {
84
+ builder = builder.referenceId(referenceId);
85
+ }
86
+
87
+ String accountId = options.hasKey(ACCOUNT_ID) ? options.getString(ACCOUNT_ID) : null;
88
+ if (accountId != null) {
89
+ builder = builder.accountId(accountId);
90
+ }
91
+
92
+ Environment environment = environmentFromString(
93
+ options.hasKey(ENVIRONMENT) ? options.getString(ENVIRONMENT) : null
94
+ );
95
+ if (environment != null) {
96
+ builder = builder.environment(environment);
97
+ }
98
+
99
+ String environmentId = options.hasKey(ENVIRONMENT_ID) ? options.getString(ENVIRONMENT_ID) : null;
100
+ if (environmentId != null) {
101
+ builder = builder.environmentId(environmentId);
102
+ }
103
+
104
+ String themeSetId = options.hasKey(THEME_SET_ID) ? options.getString(THEME_SET_ID) : null;
105
+ if (themeSetId != null) {
106
+ builder = builder.themeSetId(themeSetId);
107
+ }
108
+
109
+ String locale = options.hasKey(LOCALE) ? options.getString(LOCALE) : null;
110
+ if (locale != null) {
111
+ builder = builder.locale(locale);
112
+ }
113
+
114
+ ReadableMap fields = options.hasKey(FIELDS) ? options.getMap(FIELDS) : null;
115
+
116
+ if (fields != null) {
117
+ Fields.Builder fieldsBuilder = new Fields.Builder();
118
+
119
+ for (HashMap.Entry<String, Object> entry : fields.toHashMap().entrySet()) {
120
+ String key = entry.getKey();
121
+ Map<String, Object> wrappedValue = (Map<String, Object>) entry.getValue();
122
+ String type = (String) wrappedValue.get("type");
123
+ Object value = wrappedValue.get("value");
124
+
125
+ if (value == null) {
126
+ continue;
127
+ }
128
+
129
+ if (Objects.equals(type, "string")) {
130
+ fieldsBuilder.field(key, (String) value);
131
+ } else if (Objects.equals(type, "integer")) {
132
+ fieldsBuilder.field(key, ((Double) value).intValue());
133
+ } else if (Objects.equals(type, "boolean")) {
134
+ fieldsBuilder.field(key, (Boolean) value);
135
+ }
136
+ }
137
+
138
+ builder = builder.fields(fieldsBuilder.build());
139
+ }
140
+
141
+ Boolean returnCollectedData = options.hasKey(RETURN_COLLECTED_DATA) ? options.getBoolean(RETURN_COLLECTED_DATA) : null;
142
+ if (returnCollectedData != null) {
143
+ builder = builder.returnCollectedData(returnCollectedData);
144
+ }
145
+
146
+ return builder.build();
147
+ }
148
+ return null;
149
+ }
150
+
151
+ protected static ReadableMap wrapField(String type, String value) {
152
+ WritableMap map = Arguments.createMap();
153
+ map.putString("type", type);
154
+ map.putString("value", value);
155
+ return map;
156
+ }
157
+
158
+ @Nullable
159
+ protected static ReadableMap collectedDataToMap(@Nullable CollectedData collectedData) {
160
+ if (collectedData == null) {
161
+ return null;
162
+ }
163
+
164
+ WritableMap collectedDataMap = Arguments.createMap();
165
+
166
+ WritableArray stepDataMap = Arguments.createArray();
167
+ for (StepData stepDatum : collectedData.getStepData()) {
168
+ WritableMap stepDatumMap = Arguments.createMap();
169
+ stepDatumMap.putString("stepName", stepDatum.getStepName());
170
+
171
+ if (stepDatum instanceof StepData.DocumentStepData) {
172
+ WritableArray documentsArr = Arguments.createArray();
173
+
174
+ for (DocumentFile document : ((StepData.DocumentStepData) stepDatum).getDocuments()) {
175
+ WritableMap documentMap = Arguments.createMap();
176
+ documentMap.putString("absoluteFilePath", document.getData().getAbsolutePath());
177
+ documentsArr.pushMap(documentMap);
178
+ }
179
+
180
+ stepDatumMap.putArray("documents", documentsArr);
181
+ stepDatumMap.putString("type", "DocumentStepData");
182
+ } else if (stepDatum instanceof StepData.GovernmentIdStepData) {
183
+ WritableArray capturesArr = Arguments.createArray();
184
+
185
+ for (GovernmentIdCapture capture : ((StepData.GovernmentIdStepData) stepDatum).getCaptures()) {
186
+ WritableMap captureMap = Arguments.createMap();
187
+ captureMap.putString("idClass", capture.getIdClass());
188
+ captureMap.putString("captureMethod", capture.getCaptureMethod().name());
189
+ captureMap.putString("side", capture.getSide().name());
190
+
191
+ WritableArray framesArr = Arguments.createArray();
192
+ for (GovernmentIdCapture.Frame frame : capture.getFrames()) {
193
+ WritableMap frameMap = Arguments.createMap();
194
+ frameMap.putString("absoluteFilePath", frame.getData().getAbsolutePath());
195
+
196
+ framesArr.pushMap(frameMap);
197
+ }
198
+ captureMap.putArray("frames", framesArr);
199
+
200
+ capturesArr.pushMap(captureMap);
201
+ }
202
+
203
+ stepDatumMap.putArray("captures", capturesArr);
204
+ stepDatumMap.putString("type", "GovernmentIdStepData");
205
+ } else if (stepDatum instanceof StepData.SelfieStepData) {
206
+ StepData.SelfieStepData selfieStepData = (StepData.SelfieStepData) stepDatum;
207
+ ReadableMap centerCaptureMap = selfieCaptureToMap(selfieStepData.getCenterCapture());
208
+ ReadableMap leftCaptureMap = selfieCaptureToMap(selfieStepData.getLeftCapture());
209
+ ReadableMap rightCaptureMap = selfieCaptureToMap(selfieStepData.getRightCapture());
210
+
211
+ stepDatumMap.putMap("centerCapture", centerCaptureMap);
212
+ stepDatumMap.putMap("leftCapture", leftCaptureMap);
213
+ stepDatumMap.putMap("rightCapture", rightCaptureMap);
214
+ stepDatumMap.putString("type", "SelfieStepData");
215
+ } else if (stepDatum instanceof StepData.UiStepData) {
216
+ Map<String, Object> componentParams = ((StepData.UiStepData) stepDatum).getComponentParams();
217
+
218
+ stepDatumMap.putMap("componentParams", uiStepParamsMapToMap(componentParams));
219
+ stepDatumMap.putString("type", "UiStepData");
220
+ } else {
221
+ // do nothing
222
+ }
223
+
224
+ stepDataMap.pushMap(stepDatumMap);
225
+ }
226
+
227
+ collectedDataMap.putArray("stepData", stepDataMap);
228
+
229
+ return collectedDataMap;
230
+ }
231
+
232
+ private static Environment environmentFromString(@Nullable String environment) {
233
+ if (environment == null) {
234
+ return null;
235
+ }
236
+
237
+ switch (environment) {
238
+ case "production":
239
+ return Environment.PRODUCTION;
240
+ case "sandbox":
241
+ return Environment.SANDBOX;
242
+ default:
243
+ return null;
244
+ }
245
+ }
246
+
247
+ private static ReadableMap selfieCaptureToMap(@Nullable SelfieCapture selfieCapture) {
248
+ if (selfieCapture == null) {
249
+ return null;
250
+ }
251
+
252
+ WritableMap captureMap = Arguments.createMap();
253
+ captureMap.putString("captureMethod", selfieCapture.getCaptureMethod().name());
254
+ captureMap.putString("absoluteFilePath", selfieCapture.getData().getAbsolutePath());
255
+ return captureMap;
256
+ }
257
+
258
+ private static ReadableMap uiStepParamsMapToMap(Map<?, ?> map) {
259
+ WritableMap resultMap = Arguments.createMap();
260
+ for (Map.Entry<?, ?> param : map.entrySet()) {
261
+ Object key = param.getKey();
262
+ Object value = param.getValue();
263
+
264
+ if (!(key instanceof String)) {
265
+ continue; // All ui step params should have string keys.
266
+ }
267
+
268
+ String keyStr = (String) key;
269
+
270
+ if (value instanceof Map<?, ?>) {
271
+ resultMap.putMap(keyStr, uiStepParamsMapToMap((Map<?, ?>) value));
272
+ } else if (value instanceof List<?>) {
273
+ resultMap.putArray(keyStr, uiStepParamsArrToArr((List<?>) value));
274
+ } else if (value instanceof String) {
275
+ resultMap.putString(keyStr, (String) value);
276
+ } else if (value instanceof Boolean) {
277
+ resultMap.putBoolean(keyStr, (Boolean) value);
278
+ } else if (value instanceof Number) {
279
+ resultMap.putDouble(keyStr, (Double) value);
280
+ }
281
+ }
282
+
283
+ return resultMap;
284
+ }
285
+
286
+ private static ReadableArray uiStepParamsArrToArr(List<?> arr) {
287
+ WritableArray resultArr = Arguments.createArray();
288
+
289
+ for (Object element : arr) {
290
+ if (element instanceof String) {
291
+ resultArr.pushString((String) element);
292
+ } else if (element instanceof Boolean) {
293
+ resultArr.pushBoolean((Boolean) element);
294
+ } else if (element instanceof Number) {
295
+ resultArr.pushDouble((Double) element);
296
+ }
297
+ }
298
+
299
+ return resultArr;
300
+ }
301
+ }