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
package/src/index.ts CHANGED
@@ -2,21 +2,27 @@ import {
2
2
  EventSubscription,
3
3
  NativeEventEmitter,
4
4
  NativeModules,
5
- } from "react-native";
6
- import { processThemeValues } from "./util";
7
- import { Fields, InquiryField, RawInquiryField } from "./fields";
5
+ } from 'react-native';
6
+ import { processThemeValues } from './util';
7
+ import { Fields, InquiryField, RawInquiryField } from './fields';
8
8
 
9
- const { PersonaInquiry } = NativeModules;
9
+ export { Fields };
10
+
11
+ import { Versions } from './versions';
12
+
13
+ export { Versions };
14
+
15
+ const { PersonaInquiry2 } = NativeModules;
10
16
 
11
17
  // Using Opaque types + Smart Constructor enforces validation at
12
18
  // instantiation time for IDS
13
19
  declare const Unique: unique symbol;
14
20
  export type Opaque<T, Tag> = T & { [Unique]: Tag };
15
21
 
16
- type TemplateId = Opaque<string, "TemplateId">;
17
- type TemplateVersion = Opaque<string, "TemplateVersion">;
18
- type InquiryId = Opaque<string, "InquiryId">;
19
- type AccountId = Opaque<string, "AccountId">;
22
+ type TemplateId = Opaque<string, 'TemplateId'>;
23
+ type TemplateVersion = Opaque<string, 'TemplateVersion'>;
24
+ type InquiryId = Opaque<string, 'InquiryId'>;
25
+ type AccountId = Opaque<string, 'AccountId'>;
20
26
 
21
27
  export class InvalidTemplateId extends Error {}
22
28
 
@@ -33,7 +39,7 @@ export class InvalidAccountId extends Error {}
33
39
  * @param candidate
34
40
  */
35
41
  function makeInquiryId(candidate: string): InquiryId {
36
- if (candidate.startsWith("inq_")) return candidate as InquiryId;
42
+ if (candidate.startsWith('inq_')) return candidate as InquiryId;
37
43
 
38
44
  throw new InvalidInquiryId(
39
45
  `Valid template IDs start with "inq_". Received: ${candidate} `
@@ -47,7 +53,7 @@ function makeInquiryId(candidate: string): InquiryId {
47
53
  * @param candidate
48
54
  */
49
55
  function makeTemplateId(candidate: string): TemplateId {
50
- if (candidate.startsWith("itmpl_")) {
56
+ if (candidate.startsWith('itmpl_')) {
51
57
  return candidate as TemplateId;
52
58
  }
53
59
 
@@ -63,7 +69,7 @@ function makeTemplateId(candidate: string): TemplateId {
63
69
  * @param candidate
64
70
  */
65
71
  function makeTemplateVersion(candidate: string): TemplateVersion {
66
- if (candidate.startsWith("itmplv_")) {
72
+ if (candidate.startsWith('itmplv_')) {
67
73
  return candidate as TemplateVersion;
68
74
  }
69
75
 
@@ -79,7 +85,7 @@ function makeTemplateVersion(candidate: string): TemplateVersion {
79
85
  * @param candidate
80
86
  */
81
87
  function makeAccountId(candidate: string): AccountId {
82
- if (candidate.startsWith("act_")) {
88
+ if (candidate.startsWith('act_')) {
83
89
  return candidate as AccountId;
84
90
  }
85
91
 
@@ -93,8 +99,8 @@ function makeAccountId(candidate: string): AccountId {
93
99
  * on the native side bridge into Kotlin / Swift enums.
94
100
  */
95
101
  export enum Environment {
96
- SANDBOX = "sandbox",
97
- PRODUCTION = "production",
102
+ SANDBOX = 'sandbox',
103
+ PRODUCTION = 'production',
98
104
  }
99
105
 
100
106
  export interface InquiryOptions {
@@ -128,7 +134,7 @@ type OnCanceledCallback = (inquiryId?: string, sessionToken?: string) => void;
128
134
 
129
135
  type OnErrorCallback = (error: Error) => void;
130
136
 
131
- const eventEmitter = new NativeEventEmitter(PersonaInquiry);
137
+ const eventEmitter = new NativeEventEmitter(PersonaInquiry2);
132
138
 
133
139
  export class Inquiry {
134
140
  templateId?: TemplateId;
@@ -173,9 +179,54 @@ export class Inquiry {
173
179
  if (this.onErrorListener) this.onErrorListener.remove();
174
180
  }
175
181
 
182
+ /**
183
+ * Create an Inquiry flow builder based on a template ID.
184
+ *
185
+ * You can find your template ID on the Dashboard under Inquiries > Templates.
186
+ * {@link https://app.withpersona.com/dashboard/inquiry-templates}
187
+ *
188
+ * @param templateId template ID from your Persona Dashboard
189
+ * @return builder for the Inquiry flow
190
+ */
191
+ static fromTemplate(templateId: string) {
192
+ return new TemplateBuilder(makeTemplateId(templateId), null);
193
+ }
194
+
195
+ /**
196
+ * Create an Inquiry flow builder based on a template ID version.
197
+ *
198
+ * You can find your template ID version on the Dashboard under the
199
+ * settings view of a specific template.
200
+ * {@link https://app.withpersona.com/dashboard/inquiry-templates}
201
+ *
202
+ * @param templateVersion template version from your Persona Dashboard
203
+ * @return builder for the Inquiry flow
204
+ */
205
+ static fromTemplateVersion(templateVersion: string) {
206
+ return new TemplateBuilder(null, makeTemplateVersion(templateVersion));
207
+ }
208
+
209
+ /**
210
+ * Create an Inquiry flow builder based on an inquiry ID.
211
+ *
212
+ * You will need to generate the inquiry ID on the server. To try it out, you can create an
213
+ * inquiry from the Persona Dashboard under "Inquiries". Click on the "Create Inquiry" button
214
+ * and copy the inquiry ID from the URL.
215
+ * {@link https://app.withpersona.com/dashboard/inquiries}
216
+ *
217
+ * @param inquiryId inquiry ID from your server
218
+ * @return builder for the Inquiry flow
219
+ */
220
+ static fromInquiry(inquiryId: string) {
221
+ return new InquiryBuilder(makeInquiryId(inquiryId));
222
+ }
223
+
224
+ /**
225
+ * Launch the Persona Inquiry.
226
+ */
176
227
  start() {
177
228
  this.onCompleteListener = eventEmitter.addListener(
178
- "onComplete",
229
+ 'onComplete',
179
230
  (event: {
180
231
  inquiryId: string;
181
232
  status: string;
@@ -186,19 +237,19 @@ export class Inquiry {
186
237
  for (let key of Object.keys(event.fields || {})) {
187
238
  let field = event.fields[key];
188
239
  if (field == undefined) {
189
- fields[key] = new InquiryField.Unknown("null");
240
+ fields[key] = new InquiryField.Unknown('null');
190
241
  continue;
191
242
  }
192
243
  switch (field.type) {
193
- case "integer":
244
+ case 'integer':
194
245
  fields[key] = new InquiryField.Integer(
195
246
  Number.parseInt(field.value)
196
247
  );
197
248
  break;
198
- case "boolean":
249
+ case 'boolean':
199
250
  fields[key] = new InquiryField.Boolean(field.value);
200
251
  break;
201
- case "string":
252
+ case 'string':
202
253
  fields[key] = new InquiryField.String(field.value);
203
254
  break;
204
255
  default:
@@ -213,7 +264,7 @@ export class Inquiry {
213
264
  );
214
265
 
215
266
  this.onCanceledListener = eventEmitter.addListener(
216
- "onCanceled",
267
+ 'onCanceled',
217
268
  (event: { inquiryId?: string; sessionToken?: string }) => {
218
269
  if (this.onCanceled)
219
270
  this.onCanceled(event.inquiryId, event.sessionToken);
@@ -222,14 +273,14 @@ export class Inquiry {
222
273
  );
223
274
 
224
275
  this.onErrorListener = eventEmitter.addListener(
225
- "onError",
276
+ 'onError',
226
277
  (event: { debugMessage: string }) => {
227
278
  if (this.onError) this.onError(new Error(event.debugMessage));
228
279
  this.clearListeners();
229
280
  }
230
281
  );
231
282
 
232
- PersonaInquiry.startInquiry({
283
+ PersonaInquiry2.startInquiry({
233
284
  templateId: this.templateId,
234
285
  inquiryId: this.inquiryId,
235
286
  referenceId: this.referenceId,
@@ -406,17 +457,29 @@ class TemplateBuilder {
406
457
  }
407
458
  }
408
459
 
460
+ /**
461
+ * @deprecated Use the `Inquiry` static methods instead
462
+ */
409
463
  namespace InquiryBuilders {
464
+ /**
465
+ * @deprecated Use {@link Inquiry#fromInquiry} instead
466
+ */
410
467
  export function fromInquiry(inquiryId: string) {
411
- return new InquiryBuilder(makeInquiryId(inquiryId));
468
+ return Inquiry.fromInquiry(inquiryId);
412
469
  }
413
470
 
471
+ /**
472
+ * @deprecated Use {@link Inquiry#fromTemplate} instead
473
+ */
414
474
  export function fromTemplate(templateId: string) {
415
- return new TemplateBuilder(makeTemplateId(templateId), null);
475
+ return Inquiry.fromTemplate(templateId);
416
476
  }
417
477
 
478
+ /**
479
+ * @deprecated Use {@link Inquiry#fromTemplateVersion} instead
480
+ */
418
481
  export function fromTemplateVersion(templateVersion: string) {
419
- return new TemplateBuilder(null, makeTemplateVersion(templateVersion));
482
+ return Inquiry.fromTemplateVersion(templateVersion);
420
483
  }
421
484
  }
422
485
 
package/src/util.ts CHANGED
@@ -6,9 +6,9 @@ export function processThemeValues(themeObject: Object) {
6
6
  continue;
7
7
  }
8
8
 
9
- if (key.includes("Color")) {
9
+ if (key.includes('Color')) {
10
10
  let colorValue = value;
11
- if (value[0] === "#") {
11
+ if (value[0] === '#') {
12
12
  colorValue = value.slice(1);
13
13
  }
14
14
 
@@ -0,0 +1,12 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ const { PersonaInquiry2 } = NativeModules;
4
+
5
+ export class Versions {
6
+ /**
7
+ * @return version of the underlying Android/iOS Inquiry SDK
8
+ */
9
+ static nativeSdkVersion(): String {
10
+ return PersonaInquiry2.getConstants().INQUIRY_SDK_VERSION;
11
+ }
12
+ }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/jest.config.js DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- preset: "ts-jest",
3
- testEnvironment: "node",
4
- testPathIgnorePatterns: [
5
- "<rootDir>/node_modules/",
6
- "<rootDir>/example/",
7
- ".js"
8
- ],
9
- moduleFileExtensions: ["ts", "tsx", "js", "json", "jsx", "node"]
10
- };
@@ -1,186 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.IOS_THEME_CONFIG_KEY = exports.ANDROID_THEME_CONFIG_KEY = void 0;
7
- const cli_table_1 = __importDefault(require("cli-table"));
8
- const chalk_1 = __importDefault(require("chalk"));
9
- const config_1 = __importDefault(require("./config"));
10
- const COLOR_REGEX = /^[a-zA-Z0-9]{6}$/;
11
- var ANDROID_THEME_CONFIG_KEY;
12
- (function (ANDROID_THEME_CONFIG_KEY) {
13
- ANDROID_THEME_CONFIG_KEY["backgroundColor"] = "backgroundColor";
14
- ANDROID_THEME_CONFIG_KEY["primaryColor"] = "primaryColor";
15
- ANDROID_THEME_CONFIG_KEY["darkPrimaryColor"] = "darkPrimaryColor";
16
- ANDROID_THEME_CONFIG_KEY["accentColor"] = "accentColor";
17
- ANDROID_THEME_CONFIG_KEY["titleTextColor"] = "titleTextColor";
18
- ANDROID_THEME_CONFIG_KEY["titleTextFont"] = "titleTextFont";
19
- ANDROID_THEME_CONFIG_KEY["bodyTextColor"] = "bodyTextColor";
20
- ANDROID_THEME_CONFIG_KEY["bodyTextFont"] = "bodyTextFont";
21
- ANDROID_THEME_CONFIG_KEY["footnoteTextColor"] = "footnoteTextColor";
22
- ANDROID_THEME_CONFIG_KEY["footnoteTextFont"] = "footnoteTextFont";
23
- // formLabelTextColor = "formLabelTextColor",
24
- // formLabelTextFont = "formLabelTextFont",
25
- ANDROID_THEME_CONFIG_KEY["textFieldTextColor"] = "textFieldTextColor";
26
- ANDROID_THEME_CONFIG_KEY["textFieldTextFont"] = "textFieldTextFont";
27
- ANDROID_THEME_CONFIG_KEY["pickerTextColor"] = "pickerTextColor";
28
- ANDROID_THEME_CONFIG_KEY["pickerTextFont"] = "pickerTextFont";
29
- ANDROID_THEME_CONFIG_KEY["buttonBackgroundColor"] = "buttonBackgroundColor";
30
- ANDROID_THEME_CONFIG_KEY["buttonDisabledBackgroundColor"] = "buttonDisabledBackgroundColor";
31
- ANDROID_THEME_CONFIG_KEY["buttonTouchedBackgroundColor"] = "buttonTouchedBackgroundColor";
32
- ANDROID_THEME_CONFIG_KEY["buttonTextColor"] = "buttonTextColor";
33
- ANDROID_THEME_CONFIG_KEY["buttonDisabledTextColor"] = "buttonDisabledTextColor";
34
- // buttonTextAlignment = "buttonTextAlignment",
35
- ANDROID_THEME_CONFIG_KEY["buttonCornerRadius"] = "buttonCornerRadius";
36
- ANDROID_THEME_CONFIG_KEY["buttonFont"] = "buttonFont";
37
- ANDROID_THEME_CONFIG_KEY["progressColor"] = "progressColor";
38
- ANDROID_THEME_CONFIG_KEY["successAsset"] = "successAsset";
39
- ANDROID_THEME_CONFIG_KEY["failAsset"] = "failAsset";
40
- ANDROID_THEME_CONFIG_KEY["loadingAnimationAsset"] = "loadingAnimationAsset";
41
- ANDROID_THEME_CONFIG_KEY["loadingAnimationWidthPercent"] = "loadingAnimationWidthPercent";
42
- ANDROID_THEME_CONFIG_KEY["selfieAnimationAsset"] = "selfieAnimationAsset";
43
- ANDROID_THEME_CONFIG_KEY["selfieAnimationWidthPercent"] = "selfieAnimationWidthPercent";
44
- })(ANDROID_THEME_CONFIG_KEY = exports.ANDROID_THEME_CONFIG_KEY || (exports.ANDROID_THEME_CONFIG_KEY = {}));
45
- var IOS_THEME_CONFIG_KEY;
46
- (function (IOS_THEME_CONFIG_KEY) {
47
- IOS_THEME_CONFIG_KEY["backgroundColor"] = "backgroundColor";
48
- IOS_THEME_CONFIG_KEY["primaryColor"] = "primaryColor";
49
- IOS_THEME_CONFIG_KEY["darkPrimaryColor"] = "darkPrimaryColor";
50
- IOS_THEME_CONFIG_KEY["accentColor"] = "accentColor";
51
- IOS_THEME_CONFIG_KEY["overlayBackgroundColor"] = "overlayBackgroundColor";
52
- IOS_THEME_CONFIG_KEY["titleTextColor"] = "titleTextColor";
53
- IOS_THEME_CONFIG_KEY["titleTextFont"] = "titleTextFont";
54
- IOS_THEME_CONFIG_KEY["bodyTextColor"] = "bodyTextColor";
55
- IOS_THEME_CONFIG_KEY["bodyTextFont"] = "bodyTextFont";
56
- IOS_THEME_CONFIG_KEY["footnoteTextColor"] = "footnoteTextColor";
57
- IOS_THEME_CONFIG_KEY["footnoteTextFont"] = "footnoteTextFont";
58
- IOS_THEME_CONFIG_KEY["formLabelTextColor"] = "formLabelTextColor";
59
- IOS_THEME_CONFIG_KEY["formLabelTextFont"] = "formLabelTextFont";
60
- IOS_THEME_CONFIG_KEY["textFieldTextColor"] = "textFieldTextColor";
61
- IOS_THEME_CONFIG_KEY["textFieldBackgroundColor"] = "textFieldBackgroundColor";
62
- IOS_THEME_CONFIG_KEY["textFieldBorderColor"] = "textFieldBorderColor";
63
- IOS_THEME_CONFIG_KEY["pickerTextColor"] = "pickerTextColor";
64
- IOS_THEME_CONFIG_KEY["pickerTextFont"] = "pickerTextFont";
65
- IOS_THEME_CONFIG_KEY["buttonBackgroundColor"] = "buttonBackgroundColor";
66
- IOS_THEME_CONFIG_KEY["buttonDisabledBackgroundColor"] = "buttonDisabledBackgroundColor";
67
- IOS_THEME_CONFIG_KEY["buttonTouchedBackgroundColor"] = "buttonTouchedBackgroundColor";
68
- IOS_THEME_CONFIG_KEY["buttonImageTintColor"] = "buttonImageTintColor";
69
- IOS_THEME_CONFIG_KEY["buttonTextColor"] = "buttonTextColor";
70
- IOS_THEME_CONFIG_KEY["buttonDisabledTextColor"] = "buttonDisabledTextColor";
71
- IOS_THEME_CONFIG_KEY["buttonTextAlignment"] = "buttonTextAlignment";
72
- IOS_THEME_CONFIG_KEY["buttonCornerRadius"] = "buttonCornerRadius";
73
- IOS_THEME_CONFIG_KEY["buttonFont"] = "buttonFont";
74
- IOS_THEME_CONFIG_KEY["selectedCellBackgroundColor"] = "selectedCellBackgroundColor";
75
- IOS_THEME_CONFIG_KEY["closeButtonTintColor"] = "closeButtonTintColor";
76
- IOS_THEME_CONFIG_KEY["cancelButtonBackgroundColor"] = "cancelButtonBackgroundColor";
77
- IOS_THEME_CONFIG_KEY["progressColor"] = "progressColor";
78
- IOS_THEME_CONFIG_KEY["cameraGuideCornersColor"] = "cameraGuideCornersColor";
79
- IOS_THEME_CONFIG_KEY["cameraButtonBackgroundColor"] = "cameraButtonBackgroundColor";
80
- IOS_THEME_CONFIG_KEY["successAssetName"] = "successAssetName";
81
- IOS_THEME_CONFIG_KEY["successAssetWidth"] = "successAssetWidth";
82
- IOS_THEME_CONFIG_KEY["successAssetHeight"] = "successAssetHeight";
83
- IOS_THEME_CONFIG_KEY["verificationFailAssetName"] = "verificationFailAssetName";
84
- IOS_THEME_CONFIG_KEY["verificationFailAssetWidth"] = "verificationFailAssetWidth";
85
- IOS_THEME_CONFIG_KEY["verificationFailAssetHeight"] = "verificationFailAssetHeight";
86
- IOS_THEME_CONFIG_KEY["failAssetName"] = "failAssetName";
87
- IOS_THEME_CONFIG_KEY["failAssetWidth"] = "failAssetWidth";
88
- IOS_THEME_CONFIG_KEY["failAssetHeight"] = "failAssetHeight";
89
- IOS_THEME_CONFIG_KEY["loadingAnimationAssetName"] = "loadingAnimationAssetName";
90
- IOS_THEME_CONFIG_KEY["loadingAnimationAssetWidth"] = "loadingAnimationAssetWidth";
91
- IOS_THEME_CONFIG_KEY["loadingAnimationAssetHeight"] = "loadingAnimationAssetHeight";
92
- IOS_THEME_CONFIG_KEY["processingAnimationAssetName"] = "processingAnimationAssetName";
93
- IOS_THEME_CONFIG_KEY["processingAnimationAssetWidth"] = "processingAnimationAssetWidth";
94
- IOS_THEME_CONFIG_KEY["processingAnimationAssetHeight"] = "processingAnimationAssetHeight";
95
- IOS_THEME_CONFIG_KEY["selfieAnimationAssetName"] = "selfieAnimationAssetName";
96
- IOS_THEME_CONFIG_KEY["selfieAnimationAssetWidth"] = "selfieAnimationAssetWidth";
97
- IOS_THEME_CONFIG_KEY["selfieAnimationAssetHeight"] = "selfieAnimationAssetHeight";
98
- })(IOS_THEME_CONFIG_KEY = exports.IOS_THEME_CONFIG_KEY || (exports.IOS_THEME_CONFIG_KEY = {}));
99
- class Theme {
100
- async print(platform = "android") {
101
- const config = await config_1.default.get();
102
- const themeConfig = platform === "android" ? config["androidTheme"] : config["iosTheme"];
103
- let usesCustomFontAndroid = false;
104
- let usesCustomFontIos = false;
105
- const head = platform === "android"
106
- ? ["Style Item", "Value", "Note"]
107
- : ["Style Item", "Value", "Note"];
108
- const table = new cli_table_1.default({
109
- head,
110
- // prettier-ignore
111
- chars: { 'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' },
112
- });
113
- console.log("Specified theme values:");
114
- const keyEnum = platform === "android" ? ANDROID_THEME_CONFIG_KEY : IOS_THEME_CONFIG_KEY;
115
- for (const key in keyEnum) {
116
- let override = themeConfig[key];
117
- let colorOverride = key.includes("Color") || key.includes("color");
118
- if (override) {
119
- if (colorOverride) {
120
- override = normalizeColor(override, key);
121
- }
122
- else {
123
- override = override.toString();
124
- }
125
- }
126
- if (key.includes("Font")) {
127
- if (platform == "android") {
128
- usesCustomFontAndroid = true;
129
- }
130
- else {
131
- usesCustomFontIos = true;
132
- }
133
- }
134
- let row;
135
- row = [
136
- key,
137
- override
138
- ? valueColor(colorOverride, override)
139
- : chalk_1.default.yellow("unspecified"),
140
- key.includes("Font")
141
- ? chalk_1.default.cyan("Fonts that are not built-in need to be installed.")
142
- : "",
143
- ];
144
- table.push(row);
145
- }
146
- console.log(table.toString());
147
- if (usesCustomFontAndroid) {
148
- console.log(chalk_1.default.yellow(" NOTE") +
149
- ": A font customization was made. If the font is not built-in to the Android platform (https://github.com/react-native-training/react-native-fonts#android), then the font(s) must first be installed. A guide to install a font can be found here: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml");
150
- }
151
- if (usesCustomFontIos) {
152
- console.log(chalk_1.default.yellow(" NOTE") +
153
- ": A font customization was made. If the font is not built-in iOS (https://github.com/react-native-training/react-native-ios), then the font(s) must first be installed. A guide to install a font can be found here: https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app");
154
- }
155
- // Add newline for spacing
156
- console.log("");
157
- }
158
- }
159
- // set default print color for non-color overrides
160
- function valueColor(isColorOverride, override) {
161
- return isColorOverride
162
- ? chalk_1.default.hex(override)(override)
163
- : chalk_1.default.magentaBright(override);
164
- }
165
- function normalizeColor(colorHex, themeKey) {
166
- let hex = colorHex;
167
- if (colorHex[0] === "#") {
168
- hex = colorHex.slice(1);
169
- }
170
- if (!COLOR_REGEX.test(hex)) {
171
- if (themeKey) {
172
- console.error(`Received a color value of ${chalk_1.default.yellow(colorHex)} for ${chalk_1.default.red(themeKey)}.\nFormat must follow standard 6 character hexadecimal color code. Eg. ${chalk_1.default
173
- .bgHex("#FFFFFF")
174
- .hex("#7E66B7")("#290087")}`);
175
- }
176
- else {
177
- console.error(`Received a color value of ${chalk_1.default.yellow(colorHex)}.\nFormat must follow standard 6 character hexadecimal color code. Eg. ${chalk_1.default
178
- .bgHex("#FFFFFF")
179
- .hex("#7E66B7")("#290087")}`);
180
- }
181
- console.log("");
182
- process.exit(1);
183
- }
184
- return colorHex;
185
- }
186
- exports.default = new Theme();
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const cosmiconfig_1 = require("cosmiconfig");
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const Theme_1 = require("./Theme");
9
- class Configuration {
10
- async loadConfig() {
11
- if (this.config)
12
- return this.config;
13
- try {
14
- const explorer = cosmiconfig_1.cosmiconfig("persona", { packageProp: "persona" });
15
- const result = await explorer.search();
16
- if (result == null) {
17
- return null;
18
- }
19
- this.config = result.config;
20
- return this.config;
21
- }
22
- catch (e) {
23
- console.error(e);
24
- process.exit(1);
25
- }
26
- }
27
- async get() {
28
- let config = await this.loadConfig();
29
- const androidThemeLines = [];
30
- for (const key in Theme_1.ANDROID_THEME_CONFIG_KEY) {
31
- androidThemeLines.push(` "${key}": null`);
32
- }
33
- const iosThemeLines = [];
34
- for (const key in Theme_1.IOS_THEME_CONFIG_KEY) {
35
- iosThemeLines.push(` "${key}": null`);
36
- }
37
- if (config == null) {
38
- console.log(`
39
- Missing configuration.
40
-
41
- In order to use this tool, it must be configured using a ${chalk_1.default.yellow("persona")} object within
42
- your package.json.
43
-
44
- To get started, paste the following configuration into your package.json
45
-
46
- {
47
- ...
48
-
49
- "persona": {
50
- "androidTheme": {
51
- ` +
52
- androidThemeLines.join(",\n") +
53
- `
54
- },
55
- "iosTheme": {
56
- ` +
57
- iosThemeLines.join(",\n") +
58
- `
59
- }
60
- }
61
-
62
- ...
63
- }
64
-
65
- and re-run this tool :).
66
- `);
67
- process.exit(1);
68
- }
69
- return config;
70
- }
71
- }
72
- exports.default = new Configuration();
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const config_1 = __importDefault(require("./config"));
7
- const prompts_1 = require("./lib/prompts");
8
- const AndroidThemeGenerator_1 = __importDefault(require("./tools/AndroidThemeGenerator"));
9
- const IosThemeInstructions_1 = __importDefault(require("./tools/IosThemeInstructions"));
10
- console.log("");
11
- console.log("============================================");
12
- console.log("Persona React Native SDK customization tool.");
13
- console.log("============================================");
14
- console.log("");
15
- const run = async () => {
16
- // Run this once to print warning messages if it's not configured.
17
- await config_1.default.get();
18
- const { choice } = await prompts_1.whatWouldYouLikePrompt();
19
- switch (choice) {
20
- case prompts_1.TOOL_CHOICE.AndroidTheme:
21
- await AndroidThemeGenerator_1.default.run();
22
- break;
23
- case prompts_1.TOOL_CHOICE.iosTheme:
24
- await IosThemeInstructions_1.default.run();
25
- break;
26
- default:
27
- return;
28
- }
29
- };
30
- run();