react-native-persona 2.2.30 → 2.4.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/src/index.ts CHANGED
@@ -103,6 +103,18 @@ export enum Environment {
103
103
  PRODUCTION = 'production',
104
104
  }
105
105
 
106
+ /**
107
+ * An enum value which determines whether this sdk should use the theme values sent from the server.
108
+ */
109
+ export enum ThemeSource {
110
+ SERVER = 'server',
111
+ /**
112
+ * @deprecated Client side theming is deprecated, please configure your theme inside
113
+ * the Persona Dashboard and use SERVER as the theme source.
114
+ */
115
+ CLIENT = 'client',
116
+ }
117
+
106
118
  export interface InquiryOptions {
107
119
  templateId?: TemplateId;
108
120
  templateVersion?: TemplateVersion;
@@ -111,6 +123,7 @@ export interface InquiryOptions {
111
123
  accountId?: AccountId;
112
124
  environment?: Environment;
113
125
  sessionToken?: string;
126
+ returnCollectedData?: boolean;
114
127
 
115
128
  // Fields
116
129
  fields?: Fields;
@@ -122,14 +135,115 @@ export interface InquiryOptions {
122
135
 
123
136
  // Customization
124
137
  iosThemeObject?: Object | null;
138
+ themeSource?: ThemeSource | null;
125
139
  }
126
140
 
127
141
  type OnCompleteCallback = (
128
142
  inquiryId: string,
129
143
  status: string,
130
- fields: Fields
144
+ fields: Fields,
145
+ extraData: ExtraData,
131
146
  ) => void;
132
147
 
148
+ /**
149
+ * Type for collected data that came directly from iOS/Android.
150
+ * Needs to be translated to TS classes before returning.
151
+ */
152
+ interface ExternalCollectedData {
153
+ stepData: any[]
154
+ }
155
+
156
+ export interface ExtraData {
157
+ collectedData: CollectedData | null;
158
+ }
159
+ export interface CollectedData {
160
+ stepData: StepData[]
161
+ }
162
+
163
+ export interface StepData {
164
+ stepName: string;
165
+ }
166
+
167
+ export class DocumentStepData implements StepData {
168
+ stepName: string;
169
+ documents: Document[];
170
+
171
+ constructor() {
172
+ this.stepName = ""
173
+ this.documents = []
174
+ }
175
+ }
176
+
177
+ export interface Document {
178
+ absoluteFilePath: string;
179
+ }
180
+
181
+ export class GovernmentIdStepData implements StepData {
182
+ stepName: string;
183
+ captures: GovernmentIdCapture[];
184
+
185
+ constructor() {
186
+ this.stepName = ""
187
+ this.captures = []
188
+ }
189
+ }
190
+
191
+ export interface GovernmentIdCapture {
192
+ idClass: string;
193
+ captureMethod: GovernmentIdCaptureMethod;
194
+ side: GovernmentIdCaptureSide;
195
+ frames: GovernmentIdCaptureFrames[];
196
+ }
197
+
198
+ export enum GovernmentIdCaptureMethod {
199
+ Manual = "Manual",
200
+ Auto = "Auto",
201
+ Upload = "Upload",
202
+ }
203
+
204
+ export enum GovernmentIdCaptureSide {
205
+ Front = "Front",
206
+ Back = "Back",
207
+ }
208
+
209
+ export interface GovernmentIdCaptureFrames {
210
+ absoluteFilePath: string;
211
+ }
212
+
213
+ export class SelfieStepData implements StepData {
214
+ stepName: string;
215
+ centerCapture: SelfieCapture | null;
216
+ leftCapture: SelfieCapture | null;
217
+ rightCapture: SelfieCapture | null;
218
+
219
+ constructor() {
220
+ this.stepName = ""
221
+ this.centerCapture = null
222
+ this.leftCapture = null
223
+ this.rightCapture = null
224
+ }
225
+ }
226
+
227
+ export interface SelfieCapture {
228
+ captureMethod: SelfieCaptureMethod;
229
+ absoluteFilePath: string;
230
+ }
231
+
232
+ export enum SelfieCaptureMethod {
233
+ Manual = "Manual",
234
+ Auto = "Auto",
235
+ }
236
+
237
+ export class UiStepData implements StepData {
238
+ stepName: string;
239
+ componentParams: { [key: string]: any }
240
+
241
+ constructor() {
242
+ this.stepName = ""
243
+ this.componentParams = {}
244
+ }
245
+ }
246
+
133
247
  type OnCanceledCallback = (inquiryId?: string, sessionToken?: string) => void;
134
248
 
135
249
  type OnErrorCallback = (error: Error) => void;
@@ -143,8 +257,10 @@ export class Inquiry {
143
257
  accountId?: AccountId;
144
258
  environment?: Environment;
145
259
  sessionToken?: string;
260
+ returnCollectedData?: boolean;
146
261
 
147
262
  iosThemeObject?: Object | null;
263
+ themeSource?: ThemeSource | null;
148
264
  fields?: Fields | null;
149
265
 
150
266
  private readonly onComplete?: OnCompleteCallback;
@@ -163,6 +279,7 @@ export class Inquiry {
163
279
  this.environment = options.environment;
164
280
  this.sessionToken = options.sessionToken;
165
281
  this.fields = options.fields;
282
+ this.returnCollectedData = options.returnCollectedData;
166
283
 
167
284
  // Callbacks
168
285
  this.onComplete = options.onComplete;
@@ -171,6 +288,7 @@ export class Inquiry {
171
288
 
172
289
  // Theme object
173
290
  this.iosThemeObject = options.iosThemeObject;
291
+ this.themeSource = options.themeSource;
174
292
  }
175
293
 
176
294
  private clearListeners() {
@@ -231,6 +349,7 @@ export class Inquiry {
231
349
  inquiryId: string;
232
350
  status: string;
233
351
  fields: Record<string, RawInquiryField>;
352
+ collectedData: ExternalCollectedData | null;
234
353
  }) => {
235
354
  if (this.onComplete) {
236
355
  let fields: Fields = {};
@@ -257,7 +376,41 @@ export class Inquiry {
257
376
  break;
258
377
  }
259
378
  }
260
- this.onComplete(event.inquiryId, event.status, fields);
379
+
380
+ let collectedData: CollectedData | null = null
381
+
382
+ let stepData = event.collectedData?.stepData
383
+ if (stepData != null) {
384
+ // Translate the step data from JSON to actual class objects
385
+ let translatedStepData = []
386
+
387
+ for (let stepDatum of stepData) {
388
+ switch (stepDatum.type) {
389
+ case 'DocumentStepData':
390
+ translatedStepData.push(Object.assign(new DocumentStepData(), stepDatum))
391
+ break;
392
+ case 'GovernmentIdStepData':
393
+ translatedStepData.push(Object.assign(new GovernmentIdStepData(), stepDatum))
394
+ break;
395
+ case 'SelfieStepData':
396
+ translatedStepData.push(Object.assign(new SelfieStepData(), stepDatum))
397
+ break;
398
+ case 'UiStepData':
399
+ translatedStepData.push(Object.assign(new UiStepData(), stepDatum))
400
+ break;
401
+ }
402
+ }
403
+
404
+ collectedData = {
405
+ stepData: translatedStepData
406
+ }
407
+ }
408
+
409
+ let extraData: ExtraData = {
410
+ collectedData: collectedData
411
+ }
412
+
413
+ this.onComplete(event.inquiryId, event.status, fields, extraData);
261
414
  }
262
415
  this.clearListeners();
263
416
  }
@@ -288,6 +441,8 @@ export class Inquiry {
288
441
  environment: this.environment,
289
442
  sessionToken: this.sessionToken,
290
443
  fields: this.fields,
444
+ returnCollectedData: this.returnCollectedData,
445
+ themeSource: this.themeSource,
291
446
  iosTheme: processThemeValues(this.iosThemeObject || {}),
292
447
  });
293
448
  }
@@ -302,6 +457,7 @@ class InquiryBuilder {
302
457
  private _onCanceled?: OnCanceledCallback;
303
458
  private _onError?: OnErrorCallback;
304
459
  private _iosThemeObject?: Object;
460
+ private _themeSource: ThemeSource = ThemeSource.SERVER;
305
461
  private _fields?: Fields;
306
462
 
307
463
  constructor(inquiryId: InquiryId) {
@@ -332,8 +488,19 @@ class InquiryBuilder {
332
488
  return this;
333
489
  }
334
490
 
491
+ /**
492
+ * @deprecated Use iosThemeToUse
493
+ */
335
494
  iosTheme(themeObject: Object): InquiryBuilder {
336
495
  this._iosThemeObject = themeObject;
496
+ this._themeSource = ThemeSource.CLIENT;
497
+
498
+ return this;
499
+ }
500
+
501
+ iosThemeToUse(themeObject: Object, themeSource: ThemeSource): InquiryBuilder {
502
+ this._iosThemeObject = themeObject;
503
+ this._themeSource = themeSource;
337
504
 
338
505
  return this;
339
506
  }
@@ -346,6 +513,7 @@ class InquiryBuilder {
346
513
  onCanceled: this._onCanceled,
347
514
  onError: this._onError,
348
515
  iosThemeObject: this._iosThemeObject,
516
+ themeSource: this._themeSource,
349
517
  fields: this._fields,
350
518
  });
351
519
  }
@@ -359,6 +527,7 @@ class TemplateBuilder {
359
527
  private _environment?: Environment;
360
528
  private _fields?: Fields;
361
529
  private _sessionToken?: string;
530
+ private _returnCollectedData?: boolean;
362
531
 
363
532
  // Callbacks
364
533
  private _onComplete?: OnCompleteCallback;
@@ -367,6 +536,7 @@ class TemplateBuilder {
367
536
 
368
537
  // Customization
369
538
  private _iosThemeObject?: Object;
539
+ private _themeSource: ThemeSource = ThemeSource.SERVER;
370
540
 
371
541
  constructor(
372
542
  templateId?: TemplateId | null,
@@ -384,6 +554,12 @@ class TemplateBuilder {
384
554
  return this;
385
555
  }
386
556
 
557
+ returnCollectedData(returnCollectedData: boolean) {
558
+ this._returnCollectedData = returnCollectedData
559
+
560
+ return this
561
+ }
562
+
387
563
  referenceId(referenceId: string): TemplateBuilder {
388
564
  this._accountId = undefined;
389
565
  this._referenceId = referenceId;
@@ -434,8 +610,19 @@ class TemplateBuilder {
434
610
  return this;
435
611
  }
436
612
 
613
+ /**
614
+ * @deprecated Use iosThemeToUse
615
+ */
437
616
  iosTheme(themeObject: Object): TemplateBuilder {
438
617
  this._iosThemeObject = themeObject;
618
+ this._themeSource = ThemeSource.CLIENT;
619
+
620
+ return this;
621
+ }
622
+
623
+ iosThemeToUse(themeObject: Object, themeSource: ThemeSource): TemplateBuilder {
624
+ this._iosThemeObject = themeObject;
625
+ this._themeSource = themeSource;
439
626
 
440
627
  return this;
441
628
  }
@@ -453,6 +640,8 @@ class TemplateBuilder {
453
640
  onCanceled: this._onCanceled,
454
641
  onError: this._onError,
455
642
  iosThemeObject: this._iosThemeObject,
643
+ themeSource: this._themeSource,
644
+ returnCollectedData: this._returnCollectedData,
456
645
  });
457
646
  }
458
647
  }