react-native-persona 2.1.3 → 2.2.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 (72) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +156 -2
  3. package/{RNPersonaInquiry.podspec → RNPersonaInquiry2.podspec} +2 -2
  4. package/android/README.md +14 -0
  5. package/android/build.gradle +22 -99
  6. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  7. package/android/src/main/AndroidManifest.xml +1 -1
  8. package/android/src/main/java/com/withpersona/{sdk/reactnative/PersonaInquiryModule.java → sdk2/reactnative/PersonaInquiryModule2.java} +24 -14
  9. package/android/src/main/java/com/withpersona/{sdk/reactnative/PersonaInquiryPackage.java → sdk2/reactnative/PersonaInquiryPackage2.java} +3 -3
  10. package/android/src/main/java/com/withpersona/{sdk → sdk2}/reactnative/exceptions/InvalidConfiguration.java +1 -1
  11. package/android/src/main/res/values/theme.xml +2 -3
  12. package/ios/{PersonaInquiry.swift → PersonaInquiry2.swift} +17 -13
  13. package/ios/PersonaInquiryBridge.m +1 -1
  14. package/lib/commonjs/fields.js +141 -0
  15. package/lib/commonjs/fields.js.map +1 -0
  16. package/lib/commonjs/index.js +475 -0
  17. package/lib/commonjs/index.js.map +1 -0
  18. package/lib/commonjs/util.js +36 -0
  19. package/lib/commonjs/util.js.map +1 -0
  20. package/lib/commonjs/versions.js +25 -0
  21. package/lib/commonjs/versions.js.map +1 -0
  22. package/lib/module/fields.js +132 -0
  23. package/lib/module/fields.js.map +1 -0
  24. package/lib/module/index.js +435 -0
  25. package/lib/module/index.js.map +1 -0
  26. package/lib/module/util.js +29 -0
  27. package/lib/module/util.js.map +1 -0
  28. package/lib/module/versions.js +14 -0
  29. package/lib/module/versions.js.map +1 -0
  30. package/{generatedTypes/persona-tools/config.d.ts → lib/typescript/persona-tools/Config.d.ts} +0 -0
  31. package/{generatedTypes → lib/typescript}/persona-tools/Theme.d.ts +0 -0
  32. package/{generatedTypes → lib/typescript}/persona-tools/index.d.ts +0 -0
  33. package/{generatedTypes → lib/typescript}/persona-tools/lib/AndroidResourcePrinter.d.ts +2 -2
  34. package/{generatedTypes → lib/typescript}/persona-tools/lib/prompts.d.ts +0 -0
  35. package/{generatedTypes → lib/typescript}/persona-tools/tools/AndroidThemeGenerator.d.ts +0 -0
  36. package/{generatedTypes → lib/typescript}/persona-tools/tools/IosThemeInstructions.d.ts +0 -0
  37. package/{generatedTypes → lib/typescript}/src/fields.d.ts +0 -0
  38. package/{generatedTypes → lib/typescript}/src/index.d.ts +56 -5
  39. package/{generatedTypes → lib/typescript}/src/util.d.ts +0 -0
  40. package/lib/typescript/src/versions.d.ts +6 -0
  41. package/package.json +74 -18
  42. package/persona-tools/{config.ts → Config.ts} +7 -7
  43. package/persona-tools/Theme.ts +107 -107
  44. package/persona-tools/index.ts +9 -9
  45. package/persona-tools/lib/AndroidResourcePrinter.ts +4 -4
  46. package/persona-tools/tools/AndroidThemeGenerator.ts +18 -18
  47. package/persona-tools/tools/IosThemeInstructions.ts +8 -8
  48. package/src/fields.ts +7 -7
  49. package/src/index.ts +89 -26
  50. package/src/util.ts +2 -2
  51. package/src/versions.ts +12 -0
  52. package/generatedTypes/persona-tools/lib/AndroidResourcePrinter.spec.d.ts +0 -1
  53. package/generatedTypes/src/fields.spec.d.ts +0 -1
  54. package/generatedTypes/src/util.spec.d.ts +0 -1
  55. package/jest.config.js +0 -10
  56. package/persona-tools/Theme.js +0 -186
  57. package/persona-tools/config.js +0 -72
  58. package/persona-tools/index.js +0 -30
  59. package/persona-tools/lib/AndroidResourcePrinter.js +0 -573
  60. package/persona-tools/lib/AndroidResourcePrinter.spec.js +0 -914
  61. package/persona-tools/lib/AndroidResourcePrinter.spec.ts +0 -952
  62. package/persona-tools/lib/prompts.js +0 -39
  63. package/persona-tools/tools/AndroidThemeGenerator.js +0 -55
  64. package/persona-tools/tools/IosThemeInstructions.js +0 -34
  65. package/src/fields.js +0 -88
  66. package/src/fields.spec.js +0 -18
  67. package/src/fields.spec.ts +0 -17
  68. package/src/index.js +0 -271
  69. package/src/util.js +0 -29
  70. package/src/util.spec.js +0 -17
  71. package/src/util.spec.ts +0 -22
  72. package/tsconfig.json +0 -29
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.processThemeValues = processThemeValues;
7
+ const HEX_REGEX = /^[a-fA-F0-9]{6}$/;
8
+
9
+ function processThemeValues(themeObject) {
10
+ const result = {};
11
+
12
+ for (const [key, value] of Object.entries(themeObject)) {
13
+ if (value === null) {
14
+ continue;
15
+ }
16
+
17
+ if (key.includes('Color')) {
18
+ let colorValue = value;
19
+
20
+ if (value[0] === '#') {
21
+ colorValue = value.slice(1);
22
+ }
23
+
24
+ if (HEX_REGEX.test(colorValue)) {
25
+ result[key] = `#${colorValue}`;
26
+ } else {
27
+ continue;
28
+ }
29
+ } else {
30
+ result[key] = value.toString();
31
+ }
32
+ }
33
+
34
+ return result;
35
+ }
36
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["util.ts"],"names":["HEX_REGEX","processThemeValues","themeObject","result","key","value","Object","entries","includes","colorValue","slice","test","toString"],"mappings":";;;;;;AAAA,MAAMA,SAAS,GAAG,kBAAlB;;AACO,SAASC,kBAAT,CAA4BC,WAA5B,EAAiD;AACtD,QAAMC,MAAiC,GAAG,EAA1C;;AACA,OAAK,MAAM,CAACC,GAAD,EAAMC,KAAN,CAAX,IAA2BC,MAAM,CAACC,OAAP,CAAeL,WAAf,CAA3B,EAAwD;AACtD,QAAIG,KAAK,KAAK,IAAd,EAAoB;AAClB;AACD;;AAED,QAAID,GAAG,CAACI,QAAJ,CAAa,OAAb,CAAJ,EAA2B;AACzB,UAAIC,UAAU,GAAGJ,KAAjB;;AACA,UAAIA,KAAK,CAAC,CAAD,CAAL,KAAa,GAAjB,EAAsB;AACpBI,QAAAA,UAAU,GAAGJ,KAAK,CAACK,KAAN,CAAY,CAAZ,CAAb;AACD;;AAED,UAAIV,SAAS,CAACW,IAAV,CAAeF,UAAf,CAAJ,EAAgC;AAC9BN,QAAAA,MAAM,CAACC,GAAD,CAAN,GAAe,IAAGK,UAAW,EAA7B;AACD,OAFD,MAEO;AACL;AACD;AACF,KAXD,MAWO;AACLN,MAAAA,MAAM,CAACC,GAAD,CAAN,GAAcC,KAAK,CAACO,QAAN,EAAd;AACD;AACF;;AAED,SAAOT,MAAP;AACD","sourcesContent":["const HEX_REGEX = /^[a-fA-F0-9]{6}$/;\nexport function processThemeValues(themeObject: Object) {\n const result: { [key: string]: string } = {};\n for (const [key, value] of Object.entries(themeObject)) {\n if (value === null) {\n continue;\n }\n\n if (key.includes('Color')) {\n let colorValue = value;\n if (value[0] === '#') {\n colorValue = value.slice(1);\n }\n\n if (HEX_REGEX.test(colorValue)) {\n result[key] = `#${colorValue}`;\n } else {\n continue;\n }\n } else {\n result[key] = value.toString();\n }\n }\n\n return result;\n}\n"]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Versions = void 0;
7
+
8
+ var _reactNative = require("react-native");
9
+
10
+ const {
11
+ PersonaInquiry2
12
+ } = _reactNative.NativeModules;
13
+
14
+ class Versions {
15
+ /**
16
+ * @return version of the underlying Android/iOS Inquiry SDK
17
+ */
18
+ static nativeSdkVersion() {
19
+ return PersonaInquiry2.getConstants().INQUIRY_SDK_VERSION;
20
+ }
21
+
22
+ }
23
+
24
+ exports.Versions = Versions;
25
+ //# sourceMappingURL=versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["versions.ts"],"names":["PersonaInquiry2","NativeModules","Versions","nativeSdkVersion","getConstants","INQUIRY_SDK_VERSION"],"mappings":";;;;;;;AAAA;;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAsBC,0BAA5B;;AAEO,MAAMC,QAAN,CAAe;AACpB;AACF;AACA;AACyB,SAAhBC,gBAAgB,GAAW;AAChC,WAAOH,eAAe,CAACI,YAAhB,GAA+BC,mBAAtC;AACD;;AANmB","sourcesContent":["import { NativeModules } from 'react-native';\n\nconst { PersonaInquiry2 } = NativeModules;\n\nexport class Versions {\n /**\n * @return version of the underlying Android/iOS Inquiry SDK\n */\n static nativeSdkVersion(): String {\n return PersonaInquiry2.getConstants().INQUIRY_SDK_VERSION;\n }\n}\n"]}
@@ -0,0 +1,132 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ export let InquiryField;
4
+
5
+ (function (_InquiryField) {
6
+ class Integer {
7
+ constructor(value) {
8
+ _defineProperty(this, "type", 'integer');
9
+
10
+ _defineProperty(this, "value", void 0);
11
+
12
+ this.value = value;
13
+ }
14
+
15
+ }
16
+
17
+ _InquiryField.Integer = Integer;
18
+
19
+ class String {
20
+ constructor(value) {
21
+ _defineProperty(this, "type", 'string');
22
+
23
+ _defineProperty(this, "value", void 0);
24
+
25
+ this.value = value;
26
+ }
27
+
28
+ }
29
+
30
+ _InquiryField.String = String;
31
+
32
+ class Boolean {
33
+ constructor(value) {
34
+ _defineProperty(this, "type", 'boolean');
35
+
36
+ _defineProperty(this, "value", void 0);
37
+
38
+ this.value = value;
39
+ }
40
+
41
+ }
42
+
43
+ _InquiryField.Boolean = Boolean;
44
+
45
+ class Unknown {
46
+ constructor(type) {
47
+ _defineProperty(this, "type", void 0);
48
+
49
+ this.type = type;
50
+ }
51
+
52
+ }
53
+
54
+ _InquiryField.Unknown = Unknown;
55
+
56
+ function parse(_ref) {
57
+ let {
58
+ type,
59
+ value
60
+ } = _ref;
61
+
62
+ if (value == null) {
63
+ return null;
64
+ }
65
+
66
+ switch (type) {
67
+ case 'integer':
68
+ return new InquiryField.Integer(Number.parseInt(value));
69
+
70
+ case 'string':
71
+ return new InquiryField.String(value);
72
+
73
+ case 'boolean':
74
+ return new InquiryField.Boolean(JSON.parse(value));
75
+
76
+ case 'unknown':
77
+ return new InquiryField.Unknown(value);
78
+
79
+ default:
80
+ return new InquiryField.Unknown(type);
81
+ }
82
+ }
83
+
84
+ _InquiryField.parse = parse;
85
+ })(InquiryField || (InquiryField = {}));
86
+
87
+ export let Fields;
88
+
89
+ (function (_Fields) {
90
+ function builder() {
91
+ return new Fields.Builder();
92
+ }
93
+
94
+ _Fields.builder = builder;
95
+
96
+ class Builder {
97
+ constructor() {
98
+ _defineProperty(this, "_fields", void 0);
99
+
100
+ this._fields = {};
101
+ }
102
+
103
+ integer(fieldKey, value) {
104
+ this._fields = { ...this._fields,
105
+ [fieldKey]: new InquiryField.Integer(value)
106
+ };
107
+ return this;
108
+ }
109
+
110
+ boolean(fieldKey, value) {
111
+ this._fields = { ...this._fields,
112
+ [fieldKey]: new InquiryField.Boolean(value)
113
+ };
114
+ return this;
115
+ }
116
+
117
+ string(fieldKey, value) {
118
+ this._fields = { ...this._fields,
119
+ [fieldKey]: new InquiryField.String(value)
120
+ };
121
+ return this;
122
+ }
123
+
124
+ build() {
125
+ return this._fields;
126
+ }
127
+
128
+ }
129
+
130
+ _Fields.Builder = Builder;
131
+ })(Fields || (Fields = {}));
132
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["fields.ts"],"names":["Integer","constructor","value","String","Boolean","Unknown","type","parse","InquiryField","Number","parseInt","JSON","builder","Fields","Builder","_fields","integer","fieldKey","boolean","string","build"],"mappings":";;AASA;;;AACS,QAAMA,OAAN,CAAsC;AAI3CC,IAAAA,WAAW,CAACC,KAAD,EAAiB;AAAA,oCAHJ,SAGI;;AAAA;;AAC1B,WAAKA,KAAL,GAAaA,KAAb;AACD;;AAN0C;;;;AAStC,QAAMC,MAAN,CAAqC;AAI1CF,IAAAA,WAAW,CAACC,KAAD,EAAiB;AAAA,oCAHJ,QAGI;;AAAA;;AAC1B,WAAKA,KAAL,GAAaA,KAAb;AACD;;AANyC;;;;AASrC,QAAME,OAAN,CAAsC;AAI3CH,IAAAA,WAAW,CAACC,KAAD,EAAkB;AAAA,oCAHL,SAGK;;AAAA;;AAC3B,WAAKA,KAAL,GAAaA,KAAb;AACD;;AAN0C;;;;AAStC,QAAMG,OAAN,CAAsC;AAG3CJ,IAAAA,WAAW,CAACK,IAAD,EAAe;AAAA;;AACxB,WAAKA,IAAL,GAAYA,IAAZ;AACD;;AAL0C;;;;AAQtC,WAASC,KAAT,OAAsE;AAAA,QAAvD;AAAED,MAAAA,IAAF;AAAQJ,MAAAA;AAAR,KAAuD;;AAC3E,QAAIA,KAAK,IAAI,IAAb,EAAmB;AACjB,aAAO,IAAP;AACD;;AACD,YAAQI,IAAR;AACE,WAAK,SAAL;AACE,eAAO,IAAIE,YAAY,CAACR,OAAjB,CAAyBS,MAAM,CAACC,QAAP,CAAgBR,KAAhB,CAAzB,CAAP;;AACF,WAAK,QAAL;AACE,eAAO,IAAIM,YAAY,CAACL,MAAjB,CAAwBD,KAAxB,CAAP;;AACF,WAAK,SAAL;AACE,eAAO,IAAIM,YAAY,CAACJ,OAAjB,CAAyBO,IAAI,CAACJ,KAAL,CAAWL,KAAX,CAAzB,CAAP;;AACF,WAAK,SAAL;AACE,eAAO,IAAIM,YAAY,CAACH,OAAjB,CAAyBH,KAAzB,CAAP;;AACF;AACE,eAAO,IAAIM,YAAY,CAACH,OAAjB,CAAyBC,IAAzB,CAAP;AAVJ;AAYD;;;GApDcE,Y,KAAAA,Y;;AAyDjB;;;AACS,WAASI,OAAT,GAA4B;AACjC,WAAO,IAAIC,MAAM,CAACC,OAAX,EAAP;AACD;;;;AAEM,QAAMA,OAAN,CAAc;AAGnBb,IAAAA,WAAW,GAAG;AAAA;;AACZ,WAAKc,OAAL,GAAe,EAAf;AACD;;AAEMC,IAAAA,OAAO,CAACC,QAAD,EAAmBf,KAAnB,EAAmC;AAC/C,WAAKa,OAAL,GAAe,EACb,GAAG,KAAKA,OADK;AAEb,SAACE,QAAD,GAAY,IAAIT,YAAY,CAACR,OAAjB,CAAyBE,KAAzB;AAFC,OAAf;AAKA,aAAO,IAAP;AACD;;AAEMgB,IAAAA,OAAO,CAACD,QAAD,EAAmBf,KAAnB,EAAoC;AAChD,WAAKa,OAAL,GAAe,EACb,GAAG,KAAKA,OADK;AAEb,SAACE,QAAD,GAAY,IAAIT,YAAY,CAACJ,OAAjB,CAAyBF,KAAzB;AAFC,OAAf;AAKA,aAAO,IAAP;AACD;;AAEMiB,IAAAA,MAAM,CAACF,QAAD,EAAmBf,KAAnB,EAAmC;AAC9C,WAAKa,OAAL,GAAe,EACb,GAAG,KAAKA,OADK;AAEb,SAACE,QAAD,GAAY,IAAIT,YAAY,CAACL,MAAjB,CAAwBD,KAAxB;AAFC,OAAf;AAKA,aAAO,IAAP;AACD;;AAEMkB,IAAAA,KAAK,GAAW;AACrB,aAAO,KAAKL,OAAZ;AACD;;AApCkB;;;GALNF,M,KAAAA,M","sourcesContent":["interface InquiryField {\n readonly type: string;\n}\n\nexport type RawInquiryField = {\n type: string;\n value?: any;\n};\n\nexport namespace InquiryField {\n export class Integer implements InquiryField {\n readonly type: string = 'integer';\n readonly value?: number;\n\n constructor(value?: number) {\n this.value = value;\n }\n }\n\n export class String implements InquiryField {\n readonly type: string = 'string';\n readonly value?: string;\n\n constructor(value?: string) {\n this.value = value;\n }\n }\n\n export class Boolean implements InquiryField {\n readonly type: string = 'boolean';\n readonly value?: boolean;\n\n constructor(value?: boolean) {\n this.value = value;\n }\n }\n\n export class Unknown implements InquiryField {\n readonly type: string;\n\n constructor(type: string) {\n this.type = type;\n }\n }\n\n export function parse({ type, value }: RawInquiryField): InquiryField | null {\n if (value == null) {\n return null;\n }\n switch (type) {\n case 'integer':\n return new InquiryField.Integer(Number.parseInt(value));\n case 'string':\n return new InquiryField.String(value);\n case 'boolean':\n return new InquiryField.Boolean(JSON.parse(value));\n case 'unknown':\n return new InquiryField.Unknown(value);\n default:\n return new InquiryField.Unknown(type);\n }\n }\n}\n\nexport type Fields = Record<string, InquiryField | null>;\n\nexport namespace Fields {\n export function builder(): Builder {\n return new Fields.Builder();\n }\n\n export class Builder {\n private _fields: Record<string, InquiryField>;\n\n constructor() {\n this._fields = {};\n }\n\n public integer(fieldKey: string, value?: number) {\n this._fields = {\n ...this._fields,\n [fieldKey]: new InquiryField.Integer(value),\n };\n\n return this;\n }\n\n public boolean(fieldKey: string, value?: boolean) {\n this._fields = {\n ...this._fields,\n [fieldKey]: new InquiryField.Boolean(value),\n };\n\n return this;\n }\n\n public string(fieldKey: string, value?: string) {\n this._fields = {\n ...this._fields,\n [fieldKey]: new InquiryField.String(value),\n };\n\n return this;\n }\n\n public build(): Fields {\n return this._fields;\n }\n }\n}\n"]}
@@ -0,0 +1,435 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ import { NativeEventEmitter, NativeModules } from 'react-native';
4
+ import { processThemeValues } from './util';
5
+ import { Fields, InquiryField } from './fields';
6
+ export { Fields };
7
+ import { Versions } from './versions';
8
+ export { Versions };
9
+ const {
10
+ PersonaInquiry2
11
+ } = NativeModules; // Using Opaque types + Smart Constructor enforces validation at
12
+ // instantiation time for IDS
13
+
14
+ export class InvalidTemplateId extends Error {}
15
+ export class InvalidTemplateVersion extends Error {}
16
+ export class InvalidInquiryId extends Error {}
17
+ export class InvalidAccountId extends Error {}
18
+ /**
19
+ * Run validations that the string is in proper Inquiry token format
20
+ * and do a type conversion to InquiryId.
21
+ *
22
+ * @param candidate
23
+ */
24
+
25
+ function makeInquiryId(candidate) {
26
+ if (candidate.startsWith('inq_')) return candidate;
27
+ throw new InvalidInquiryId(`Valid template IDs start with "inq_". Received: ${candidate} `);
28
+ }
29
+ /**
30
+ * Run validations that the string is in proper Template token format
31
+ * and do a type conversion to TemplateId.
32
+ *
33
+ * @param candidate
34
+ */
35
+
36
+
37
+ function makeTemplateId(candidate) {
38
+ if (candidate.startsWith('itmpl_')) {
39
+ return candidate;
40
+ }
41
+
42
+ throw new InvalidTemplateId(`Valid template IDs start with "itmpl_". Received: ${candidate} `);
43
+ }
44
+ /**
45
+ * Run validations that the string is in proper Template Version token format
46
+ * and do a type conversion to TemplateVersion.
47
+ *
48
+ * @param candidate
49
+ */
50
+
51
+
52
+ function makeTemplateVersion(candidate) {
53
+ if (candidate.startsWith('itmplv_')) {
54
+ return candidate;
55
+ }
56
+
57
+ throw new InvalidTemplateVersion(`Valid template versions start with "itmplv_". Received: ${candidate} `);
58
+ }
59
+ /**
60
+ * Run validations that the string is in proper Template token format
61
+ * and do a type conversion to AccountId.
62
+ *
63
+ * @param candidate
64
+ */
65
+
66
+
67
+ function makeAccountId(candidate) {
68
+ if (candidate.startsWith('act_')) {
69
+ return candidate;
70
+ }
71
+
72
+ throw new InvalidAccountId(`Valid account IDs start with "act_". Received: ${candidate} `);
73
+ }
74
+ /**
75
+ * String enum for environments. These strings will be parsed
76
+ * on the native side bridge into Kotlin / Swift enums.
77
+ */
78
+
79
+
80
+ export let Environment;
81
+
82
+ (function (Environment) {
83
+ Environment["SANDBOX"] = "sandbox";
84
+ Environment["PRODUCTION"] = "production";
85
+ })(Environment || (Environment = {}));
86
+
87
+ const eventEmitter = new NativeEventEmitter(PersonaInquiry2);
88
+ export class Inquiry {
89
+ constructor(options) {
90
+ _defineProperty(this, "templateId", void 0);
91
+
92
+ _defineProperty(this, "inquiryId", void 0);
93
+
94
+ _defineProperty(this, "referenceId", void 0);
95
+
96
+ _defineProperty(this, "accountId", void 0);
97
+
98
+ _defineProperty(this, "environment", void 0);
99
+
100
+ _defineProperty(this, "sessionToken", void 0);
101
+
102
+ _defineProperty(this, "iosThemeObject", void 0);
103
+
104
+ _defineProperty(this, "fields", void 0);
105
+
106
+ _defineProperty(this, "onComplete", void 0);
107
+
108
+ _defineProperty(this, "onCanceled", void 0);
109
+
110
+ _defineProperty(this, "onError", void 0);
111
+
112
+ _defineProperty(this, "onCompleteListener", void 0);
113
+
114
+ _defineProperty(this, "onCanceledListener", void 0);
115
+
116
+ _defineProperty(this, "onErrorListener", void 0);
117
+
118
+ this.templateId = options.templateId;
119
+ this.inquiryId = options.inquiryId;
120
+ this.referenceId = options.referenceId;
121
+ this.accountId = options.accountId;
122
+ this.environment = options.environment;
123
+ this.sessionToken = options.sessionToken;
124
+ this.fields = options.fields; // Callbacks
125
+
126
+ this.onComplete = options.onComplete;
127
+ this.onCanceled = options.onCanceled;
128
+ this.onError = options.onError; // Theme object
129
+
130
+ this.iosThemeObject = options.iosThemeObject;
131
+ }
132
+
133
+ clearListeners() {
134
+ if (this.onCompleteListener) this.onCompleteListener.remove();
135
+ if (this.onCanceledListener) this.onCanceledListener.remove();
136
+ if (this.onErrorListener) this.onErrorListener.remove();
137
+ }
138
+ /**
139
+ * Create an Inquiry flow builder based on a template ID.
140
+ *
141
+ * You can find your template ID on the Dashboard under Inquiries > Templates.
142
+ * {@link https://app.withpersona.com/dashboard/inquiry-templates}
143
+ *
144
+ * @param templateId template ID from your Persona Dashboard
145
+ * @return builder for the Inquiry flow
146
+ */
147
+
148
+
149
+ static fromTemplate(templateId) {
150
+ return new TemplateBuilder(makeTemplateId(templateId), null);
151
+ }
152
+ /**
153
+ * Create an Inquiry flow builder based on a template ID version.
154
+ *
155
+ * You can find your template ID version on the Dashboard under the
156
+ * settings view of a specific template.
157
+ * {@link https://app.withpersona.com/dashboard/inquiry-templates}
158
+ *
159
+ * @param templateVersion template version from your Persona Dashboard
160
+ * @return builder for the Inquiry flow
161
+ */
162
+
163
+
164
+ static fromTemplateVersion(templateVersion) {
165
+ return new TemplateBuilder(null, makeTemplateVersion(templateVersion));
166
+ }
167
+ /**
168
+ * Create an Inquiry flow builder based on an inquiry ID.
169
+ *
170
+ * You will need to generate the inquiry ID on the server. To try it out, you can create an
171
+ * inquiry from the Persona Dashboard under "Inquiries". Click on the "Create Inquiry" button
172
+ * and copy the inquiry ID from the URL.
173
+ * {@link https://app.withpersona.com/dashboard/inquiries}
174
+ *
175
+ * @param inquiryId inquiry ID from your server
176
+ * @return builder for the Inquiry flow
177
+ */
178
+
179
+
180
+ static fromInquiry(inquiryId) {
181
+ return new InquiryBuilder(makeInquiryId(inquiryId));
182
+ }
183
+ /**
184
+ * Launch the Persona Inquiry.
185
+ */
186
+
187
+
188
+ start() {
189
+ this.onCompleteListener = eventEmitter.addListener('onComplete', event => {
190
+ if (this.onComplete) {
191
+ let fields = {};
192
+
193
+ for (let key of Object.keys(event.fields || {})) {
194
+ let field = event.fields[key];
195
+
196
+ if (field == undefined) {
197
+ fields[key] = new InquiryField.Unknown('null');
198
+ continue;
199
+ }
200
+
201
+ switch (field.type) {
202
+ case 'integer':
203
+ fields[key] = new InquiryField.Integer(Number.parseInt(field.value));
204
+ break;
205
+
206
+ case 'boolean':
207
+ fields[key] = new InquiryField.Boolean(field.value);
208
+ break;
209
+
210
+ case 'string':
211
+ fields[key] = new InquiryField.String(field.value);
212
+ break;
213
+
214
+ default:
215
+ fields[key] = new InquiryField.Unknown(field.type);
216
+ break;
217
+ }
218
+ }
219
+
220
+ this.onComplete(event.inquiryId, event.status, fields);
221
+ }
222
+
223
+ this.clearListeners();
224
+ });
225
+ this.onCanceledListener = eventEmitter.addListener('onCanceled', event => {
226
+ if (this.onCanceled) this.onCanceled(event.inquiryId, event.sessionToken);
227
+ this.clearListeners();
228
+ });
229
+ this.onErrorListener = eventEmitter.addListener('onError', event => {
230
+ if (this.onError) this.onError(new Error(event.debugMessage));
231
+ this.clearListeners();
232
+ });
233
+ PersonaInquiry2.startInquiry({
234
+ templateId: this.templateId,
235
+ inquiryId: this.inquiryId,
236
+ referenceId: this.referenceId,
237
+ accountId: this.accountId,
238
+ environment: this.environment,
239
+ sessionToken: this.sessionToken,
240
+ fields: this.fields,
241
+ iosTheme: processThemeValues(this.iosThemeObject || {})
242
+ });
243
+ }
244
+
245
+ }
246
+
247
+ class InquiryBuilder {
248
+ // Callbacks
249
+ constructor(inquiryId) {
250
+ _defineProperty(this, "_inquiryId", void 0);
251
+
252
+ _defineProperty(this, "_sessionToken", void 0);
253
+
254
+ _defineProperty(this, "_onComplete", void 0);
255
+
256
+ _defineProperty(this, "_onCanceled", void 0);
257
+
258
+ _defineProperty(this, "_onError", void 0);
259
+
260
+ _defineProperty(this, "_iosThemeObject", void 0);
261
+
262
+ _defineProperty(this, "_fields", void 0);
263
+
264
+ this._inquiryId = inquiryId;
265
+ }
266
+
267
+ sessionToken(sessionToken) {
268
+ this._sessionToken = sessionToken;
269
+ return this;
270
+ }
271
+
272
+ onComplete(callback) {
273
+ this._onComplete = callback;
274
+ return this;
275
+ }
276
+
277
+ onCanceled(callback) {
278
+ this._onCanceled = callback;
279
+ return this;
280
+ }
281
+
282
+ onError(callback) {
283
+ this._onError = callback;
284
+ return this;
285
+ }
286
+
287
+ iosTheme(themeObject) {
288
+ this._iosThemeObject = themeObject;
289
+ return this;
290
+ }
291
+
292
+ build() {
293
+ return new Inquiry({
294
+ inquiryId: this._inquiryId,
295
+ sessionToken: this._sessionToken,
296
+ onComplete: this._onComplete,
297
+ onCanceled: this._onCanceled,
298
+ onError: this._onError,
299
+ iosThemeObject: this._iosThemeObject,
300
+ fields: this._fields
301
+ });
302
+ }
303
+
304
+ }
305
+
306
+ class TemplateBuilder {
307
+ // Callbacks
308
+ // Customization
309
+ constructor(templateId, templateVersion) {
310
+ _defineProperty(this, "_templateId", void 0);
311
+
312
+ _defineProperty(this, "_templateVersion", void 0);
313
+
314
+ _defineProperty(this, "_accountId", void 0);
315
+
316
+ _defineProperty(this, "_referenceId", void 0);
317
+
318
+ _defineProperty(this, "_environment", void 0);
319
+
320
+ _defineProperty(this, "_fields", void 0);
321
+
322
+ _defineProperty(this, "_sessionToken", void 0);
323
+
324
+ _defineProperty(this, "_onComplete", void 0);
325
+
326
+ _defineProperty(this, "_onCanceled", void 0);
327
+
328
+ _defineProperty(this, "_onError", void 0);
329
+
330
+ _defineProperty(this, "_iosThemeObject", void 0);
331
+
332
+ if (templateId != null) {
333
+ this._templateId = templateId;
334
+ } else if (templateVersion != null) {
335
+ this._templateVersion = templateVersion;
336
+ } else {
337
+ throw new InvalidTemplateId(`Either templateId or templateVersion needs to be set.`);
338
+ }
339
+
340
+ return this;
341
+ }
342
+
343
+ referenceId(referenceId) {
344
+ this._accountId = undefined;
345
+ this._referenceId = referenceId;
346
+ return this;
347
+ }
348
+
349
+ accountId(accountId) {
350
+ this._referenceId = undefined;
351
+ this._accountId = makeAccountId(accountId);
352
+ return this;
353
+ }
354
+
355
+ environment(environment) {
356
+ this._environment = environment;
357
+ return this;
358
+ }
359
+
360
+ sessionToken(sessionToken) {
361
+ this._sessionToken = sessionToken;
362
+ return this;
363
+ }
364
+
365
+ fields(fields) {
366
+ this._fields = fields;
367
+ return this;
368
+ }
369
+
370
+ onComplete(callback) {
371
+ this._onComplete = callback;
372
+ return this;
373
+ }
374
+
375
+ onCanceled(callback) {
376
+ this._onCanceled = callback;
377
+ return this;
378
+ }
379
+
380
+ onError(callback) {
381
+ this._onError = callback;
382
+ return this;
383
+ }
384
+
385
+ iosTheme(themeObject) {
386
+ this._iosThemeObject = themeObject;
387
+ return this;
388
+ }
389
+
390
+ build() {
391
+ return new Inquiry({
392
+ templateId: this._templateId,
393
+ templateVersion: this._templateVersion,
394
+ accountId: this._accountId,
395
+ referenceId: this._referenceId,
396
+ environment: this._environment,
397
+ sessionToken: this._sessionToken,
398
+ fields: this._fields,
399
+ onComplete: this._onComplete,
400
+ onCanceled: this._onCanceled,
401
+ onError: this._onError,
402
+ iosThemeObject: this._iosThemeObject
403
+ });
404
+ }
405
+
406
+ }
407
+ /**
408
+ * @deprecated Use the `Inquiry` static methods instead
409
+ */
410
+
411
+
412
+ let InquiryBuilders;
413
+
414
+ (function (_InquiryBuilders) {
415
+ function fromInquiry(inquiryId) {
416
+ return Inquiry.fromInquiry(inquiryId);
417
+ }
418
+
419
+ _InquiryBuilders.fromInquiry = fromInquiry;
420
+
421
+ function fromTemplate(templateId) {
422
+ return Inquiry.fromTemplate(templateId);
423
+ }
424
+
425
+ _InquiryBuilders.fromTemplate = fromTemplate;
426
+
427
+ function fromTemplateVersion(templateVersion) {
428
+ return Inquiry.fromTemplateVersion(templateVersion);
429
+ }
430
+
431
+ _InquiryBuilders.fromTemplateVersion = fromTemplateVersion;
432
+ })(InquiryBuilders || (InquiryBuilders = {}));
433
+
434
+ export default InquiryBuilders;
435
+ //# sourceMappingURL=index.js.map