@transfergratis/react-native-sdk 0.1.23 → 0.1.25

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 (207) hide show
  1. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +12 -5
  2. package/android/build/intermediates/aar_main_jar/debug/syncDebugLibJars/classes.jar +0 -0
  3. package/android/build/intermediates/annotations_typedef_file/debug/extractDebugAnnotations/typedefs.txt +0 -0
  4. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
  5. package/android/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  6. package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +61 -59
  7. package/android/build/intermediates/merged_java_res/debug/mergeDebugJavaResource/feature-transfergratis-react-native-sdk.jar +0 -0
  8. package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +12 -5
  9. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  10. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  11. package/android/build/outputs/aar/transfergratis-react-native-sdk-debug.aar +0 -0
  12. package/android/build/outputs/logs/manifest-merger-debug-report.txt +26 -34
  13. package/android/src/main/AndroidManifest.xml +13 -5
  14. package/build/components/EnhancedCameraView.d.ts.map +1 -1
  15. package/build/components/EnhancedCameraView.js +26 -3
  16. package/build/components/EnhancedCameraView.js.map +1 -1
  17. package/build/components/EnhancedCameraView.web.d.ts.map +1 -1
  18. package/build/components/EnhancedCameraView.web.js +21 -0
  19. package/build/components/EnhancedCameraView.web.js.map +1 -1
  20. package/build/components/KYCElements/AdditionalDocumentsTemplate.d.ts +12 -0
  21. package/build/components/KYCElements/AdditionalDocumentsTemplate.d.ts.map +1 -0
  22. package/build/components/KYCElements/AdditionalDocumentsTemplate.js +283 -0
  23. package/build/components/KYCElements/AdditionalDocumentsTemplate.js.map +1 -0
  24. package/build/components/KYCElements/CameraCapture.d.ts.map +1 -1
  25. package/build/components/KYCElements/CameraCapture.js +4 -3
  26. package/build/components/KYCElements/CameraCapture.js.map +1 -1
  27. package/build/components/KYCElements/CountrySelectionTemplate.d.ts +5 -2
  28. package/build/components/KYCElements/CountrySelectionTemplate.d.ts.map +1 -1
  29. package/build/components/KYCElements/CountrySelectionTemplate.js +360 -101
  30. package/build/components/KYCElements/CountrySelectionTemplate.js.map +1 -1
  31. package/build/components/KYCElements/EmailVerificationTemplate.d.ts +12 -0
  32. package/build/components/KYCElements/EmailVerificationTemplate.d.ts.map +1 -0
  33. package/build/components/KYCElements/EmailVerificationTemplate.js +193 -0
  34. package/build/components/KYCElements/EmailVerificationTemplate.js.map +1 -0
  35. package/build/components/KYCElements/FileUpload.d.ts.map +1 -1
  36. package/build/components/KYCElements/FileUpload.js +5 -4
  37. package/build/components/KYCElements/FileUpload.js.map +1 -1
  38. package/build/components/KYCElements/FileUploadTemplate.d.ts.map +1 -1
  39. package/build/components/KYCElements/FileUploadTemplate.js +5 -4
  40. package/build/components/KYCElements/FileUploadTemplate.js.map +1 -1
  41. package/build/components/KYCElements/IDCardCapture.d.ts.map +1 -1
  42. package/build/components/KYCElements/IDCardCapture.js +356 -227
  43. package/build/components/KYCElements/IDCardCapture.js.map +1 -1
  44. package/build/components/KYCElements/LocationCaptureTemplate.d.ts.map +1 -1
  45. package/build/components/KYCElements/LocationCaptureTemplate.js +78 -37
  46. package/build/components/KYCElements/LocationCaptureTemplate.js.map +1 -1
  47. package/build/components/KYCElements/OrientationVideoCapture.d.ts +2 -0
  48. package/build/components/KYCElements/OrientationVideoCapture.d.ts.map +1 -1
  49. package/build/components/KYCElements/OrientationVideoCapture.js +5 -4
  50. package/build/components/KYCElements/OrientationVideoCapture.js.map +1 -1
  51. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.d.ts +2 -0
  52. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.d.ts.map +1 -1
  53. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.js +5 -4
  54. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.js.map +1 -1
  55. package/build/components/KYCElements/OrientationVideoCaptureFinal.d.ts +2 -0
  56. package/build/components/KYCElements/OrientationVideoCaptureFinal.d.ts.map +1 -1
  57. package/build/components/KYCElements/OrientationVideoCaptureFinal.js +5 -4
  58. package/build/components/KYCElements/OrientationVideoCaptureFinal.js.map +1 -1
  59. package/build/components/KYCElements/PersonalInformationTemplate.d.ts +12 -0
  60. package/build/components/KYCElements/PersonalInformationTemplate.d.ts.map +1 -0
  61. package/build/components/KYCElements/PersonalInformationTemplate.js +120 -0
  62. package/build/components/KYCElements/PersonalInformationTemplate.js.map +1 -0
  63. package/build/components/KYCElements/PhoneVerificationTemplate.d.ts +12 -0
  64. package/build/components/KYCElements/PhoneVerificationTemplate.d.ts.map +1 -0
  65. package/build/components/KYCElements/PhoneVerificationTemplate.js +185 -0
  66. package/build/components/KYCElements/PhoneVerificationTemplate.js.map +1 -0
  67. package/build/components/KYCElements/SelfieCapture.d.ts.map +1 -1
  68. package/build/components/KYCElements/SelfieCapture.js +4 -3
  69. package/build/components/KYCElements/SelfieCapture.js.map +1 -1
  70. package/build/components/KYCElements/SelfieCaptureTemplate.d.ts.map +1 -1
  71. package/build/components/KYCElements/SelfieCaptureTemplate.js +189 -42
  72. package/build/components/KYCElements/SelfieCaptureTemplate.js.map +1 -1
  73. package/build/components/KYCElements/WelcomeTemplate.d.ts +12 -0
  74. package/build/components/KYCElements/WelcomeTemplate.d.ts.map +1 -0
  75. package/build/components/KYCElements/WelcomeTemplate.js +243 -0
  76. package/build/components/KYCElements/WelcomeTemplate.js.map +1 -0
  77. package/build/components/TemplateKYCExample.d.ts +8 -2
  78. package/build/components/TemplateKYCExample.d.ts.map +1 -1
  79. package/build/components/TemplateKYCExample.js +10 -97
  80. package/build/components/TemplateKYCExample.js.map +1 -1
  81. package/build/components/TemplateKYCFlowRefactored.d.ts +6 -1
  82. package/build/components/TemplateKYCFlowRefactored.d.ts.map +1 -1
  83. package/build/components/TemplateKYCFlowRefactored.js +108 -11
  84. package/build/components/TemplateKYCFlowRefactored.js.map +1 -1
  85. package/build/components/example/DynamicTemplateExample.d.ts +10 -0
  86. package/build/components/example/DynamicTemplateExample.d.ts.map +1 -0
  87. package/build/components/example/DynamicTemplateExample.js +241 -0
  88. package/build/components/example/DynamicTemplateExample.js.map +1 -0
  89. package/build/config/KYCConfig.d.ts +14 -0
  90. package/build/config/KYCConfig.d.ts.map +1 -0
  91. package/build/config/KYCConfig.js +26 -0
  92. package/build/config/KYCConfig.js.map +1 -0
  93. package/build/config/allowedDomains.d.ts +30 -0
  94. package/build/config/allowedDomains.d.ts.map +1 -0
  95. package/build/config/allowedDomains.js +112 -0
  96. package/build/config/allowedDomains.js.map +1 -0
  97. package/build/hooks/useOrientationVideo.d.ts +2 -1
  98. package/build/hooks/useOrientationVideo.d.ts.map +1 -1
  99. package/build/hooks/useOrientationVideo.js +3 -3
  100. package/build/hooks/useOrientationVideo.js.map +1 -1
  101. package/build/hooks/useTemplateKYCFlow.d.ts +6 -1
  102. package/build/hooks/useTemplateKYCFlow.d.ts.map +1 -1
  103. package/build/hooks/useTemplateKYCFlow.js +317 -34
  104. package/build/hooks/useTemplateKYCFlow.js.map +1 -1
  105. package/build/hooks/useTemplateLoader.d.ts +14 -0
  106. package/build/hooks/useTemplateLoader.d.ts.map +1 -0
  107. package/build/hooks/useTemplateLoader.js +85 -0
  108. package/build/hooks/useTemplateLoader.js.map +1 -0
  109. package/build/i18n/en/index.d.ts +49 -0
  110. package/build/i18n/en/index.d.ts.map +1 -1
  111. package/build/i18n/en/index.js +50 -1
  112. package/build/i18n/en/index.js.map +1 -1
  113. package/build/i18n/fr/index.d.ts +35 -0
  114. package/build/i18n/fr/index.d.ts.map +1 -1
  115. package/build/i18n/fr/index.js +36 -1
  116. package/build/i18n/fr/index.js.map +1 -1
  117. package/build/index.d.ts +6 -0
  118. package/build/index.d.ts.map +1 -1
  119. package/build/index.js +10 -0
  120. package/build/index.js.map +1 -1
  121. package/build/modules/api/CardAuthentification.d.ts +24 -3
  122. package/build/modules/api/CardAuthentification.d.ts.map +1 -1
  123. package/build/modules/api/CardAuthentification.js +69 -10
  124. package/build/modules/api/CardAuthentification.js.map +1 -1
  125. package/build/modules/api/KYCService.d.ts +7 -7
  126. package/build/modules/api/KYCService.d.ts.map +1 -1
  127. package/build/modules/api/KYCService.js +108 -39
  128. package/build/modules/api/KYCService.js.map +1 -1
  129. package/build/modules/api/SelfieVerification.d.ts +3 -1
  130. package/build/modules/api/SelfieVerification.d.ts.map +1 -1
  131. package/build/modules/api/SelfieVerification.js +17 -1
  132. package/build/modules/api/SelfieVerification.js.map +1 -1
  133. package/build/modules/api/TemplateService.d.ts +44 -0
  134. package/build/modules/api/TemplateService.d.ts.map +1 -0
  135. package/build/modules/api/TemplateService.js +145 -0
  136. package/build/modules/api/TemplateService.js.map +1 -0
  137. package/build/types/KYC.types.d.ts +265 -4
  138. package/build/types/KYC.types.d.ts.map +1 -1
  139. package/build/types/KYC.types.js +15 -0
  140. package/build/types/KYC.types.js.map +1 -1
  141. package/build/types/env.types.d.ts +13 -0
  142. package/build/types/env.types.d.ts.map +1 -0
  143. package/build/types/env.types.js +2 -0
  144. package/build/types/env.types.js.map +1 -0
  145. package/build/utils/cropByObb.d.ts +1 -0
  146. package/build/utils/cropByObb.d.ts.map +1 -1
  147. package/build/utils/cropByObb.js +70 -0
  148. package/build/utils/cropByObb.js.map +1 -1
  149. package/build/utils/deviceDetection.d.ts +6 -0
  150. package/build/utils/deviceDetection.d.ts.map +1 -0
  151. package/build/utils/deviceDetection.js +12 -0
  152. package/build/utils/deviceDetection.js.map +1 -0
  153. package/build/utils/platformAlert.d.ts +20 -0
  154. package/build/utils/platformAlert.d.ts.map +1 -0
  155. package/build/utils/platformAlert.js +67 -0
  156. package/build/utils/platformAlert.js.map +1 -0
  157. package/build/utils/template-transformer.d.ts +10 -0
  158. package/build/utils/template-transformer.d.ts.map +1 -0
  159. package/build/utils/template-transformer.js +365 -0
  160. package/build/utils/template-transformer.js.map +1 -0
  161. package/build/web/WebKYCEntry.d.ts.map +1 -1
  162. package/build/web/WebKYCEntry.js +158 -32
  163. package/build/web/WebKYCEntry.js.map +1 -1
  164. package/package.json +1 -1
  165. package/plugin/build/withVisionCamera.js +3 -4
  166. package/plugin/src/withVisionCamera.js +3 -4
  167. package/plugin/src/withVisionCamera.ts +3 -4
  168. package/src/components/EnhancedCameraView.tsx +31 -2
  169. package/src/components/EnhancedCameraView.web.tsx +24 -0
  170. package/src/components/KYCElements/AdditionalDocumentsTemplate.tsx +346 -0
  171. package/src/components/KYCElements/CameraCapture.tsx +4 -3
  172. package/src/components/KYCElements/CountrySelectionTemplate.tsx +410 -113
  173. package/src/components/KYCElements/EmailVerificationTemplate.tsx +264 -0
  174. package/src/components/KYCElements/FileUpload.tsx +5 -4
  175. package/src/components/KYCElements/FileUploadTemplate.tsx +5 -4
  176. package/src/components/KYCElements/IDCardCapture.tsx +397 -254
  177. package/src/components/KYCElements/LocationCaptureTemplate.tsx +95 -44
  178. package/src/components/KYCElements/OrientationVideoCapture.tsx +6 -3
  179. package/src/components/KYCElements/OrientationVideoCaptureEnhanced.tsx +6 -3
  180. package/src/components/KYCElements/OrientationVideoCaptureFinal.tsx +6 -3
  181. package/src/components/KYCElements/PersonalInformationTemplate.tsx +158 -0
  182. package/src/components/KYCElements/PhoneVerificationTemplate.tsx +253 -0
  183. package/src/components/KYCElements/SelfieCapture.tsx +4 -3
  184. package/src/components/KYCElements/SelfieCaptureTemplate.tsx +201 -44
  185. package/src/components/KYCElements/WelcomeTemplate.tsx +289 -0
  186. package/src/components/TemplateKYCExample.tsx +37 -108
  187. package/src/components/TemplateKYCFlowRefactored.tsx +148 -12
  188. package/src/components/example/DynamicTemplateExample.tsx +289 -0
  189. package/src/config/KYCConfig.ts +34 -0
  190. package/src/config/allowedDomains.ts +133 -0
  191. package/src/hooks/useOrientationVideo.ts +5 -4
  192. package/src/hooks/useTemplateKYCFlow.tsx +347 -32
  193. package/src/hooks/useTemplateLoader.ts +102 -0
  194. package/src/i18n/en/index.ts +53 -2
  195. package/src/i18n/fr/index.ts +37 -1
  196. package/src/index.ts +14 -0
  197. package/src/modules/api/CardAuthentification.ts +76 -11
  198. package/src/modules/api/KYCService.ts +129 -45
  199. package/src/modules/api/SelfieVerification.ts +25 -3
  200. package/src/modules/api/TemplateService.ts +167 -0
  201. package/src/types/KYC.types.ts +331 -3
  202. package/src/types/env.types.ts +13 -0
  203. package/src/utils/cropByObb.ts +83 -3
  204. package/src/utils/deviceDetection.ts +11 -0
  205. package/src/utils/platformAlert.ts +86 -0
  206. package/src/utils/template-transformer.ts +445 -0
  207. package/src/web/WebKYCEntry.tsx +199 -50
@@ -0,0 +1,365 @@
1
+ import { logger } from './logger';
2
+ /**
3
+ * Hash a string to a number (simple hash function)
4
+ */
5
+ function hashStringToNumber(str) {
6
+ let hash = 0;
7
+ for (let i = 0; i < str.length; i++) {
8
+ const char = str.charCodeAt(i);
9
+ hash = ((hash << 5) - hash) + char;
10
+ hash = hash & hash; // Convert to 32-bit integer
11
+ }
12
+ return Math.abs(hash);
13
+ }
14
+ /**
15
+ * Map backend component types to SDK component types
16
+ */
17
+ const COMPONENT_TYPE_MAPPING = {
18
+ 'welcome': 'welcome',
19
+ 'government-id': 'id_card',
20
+ 'selfie-capture': 'selfie',
21
+ 'location-capture': 'location',
22
+ 'review-submit': 'review_submit',
23
+ 'verification-progress': 'verification_progress',
24
+ 'file-upload': 'file_upload',
25
+ 'country-selection': 'country_selection',
26
+ 'email-verification': 'email_verification',
27
+ 'phone-verification': 'phone_verification',
28
+ 'personal-information': 'personal_information',
29
+ 'additional-documents': 'additional_documents',
30
+ };
31
+ /**
32
+ * Transform backend translations to SDK labels and instructions
33
+ */
34
+ function transformTranslations(translations, defaultLanguage = 'en') {
35
+ const labels = { en: '', fr: '' };
36
+ const instructions = { en: '', fr: '' };
37
+ // Extract title as label
38
+ if (translations.en?.title)
39
+ labels.en = translations.en.title;
40
+ if (translations.fr?.title)
41
+ labels.fr = translations.fr.title;
42
+ // Extract instructions
43
+ if (translations.en?.instructions)
44
+ instructions.en = translations.en.instructions;
45
+ if (translations.fr?.instructions)
46
+ instructions.fr = translations.fr.instructions;
47
+ // Fallback to description if instructions not available
48
+ if (!instructions.en && translations.en?.description) {
49
+ instructions.en = translations.en.description;
50
+ }
51
+ if (!instructions.fr && translations.fr?.description) {
52
+ instructions.fr = translations.fr.description;
53
+ }
54
+ // Support other languages
55
+ Object.keys(translations).forEach((lang) => {
56
+ if (lang !== 'en' && lang !== 'fr' && translations[lang]) {
57
+ labels[lang] = translations[lang]?.title || '';
58
+ instructions[lang] = translations[lang]?.instructions || translations[lang]?.description || '';
59
+ }
60
+ });
61
+ return { labels, instructions };
62
+ }
63
+ /**
64
+ * Transform UI configuration
65
+ */
66
+ function transformUI(translations) {
67
+ const buttonText = { en: '', fr: '' };
68
+ if (translations.en?.buttonText)
69
+ buttonText.en = translations.en.buttonText;
70
+ if (translations.fr?.buttonText)
71
+ buttonText.fr = translations.fr.buttonText;
72
+ // Support other languages
73
+ Object.keys(translations).forEach((lang) => {
74
+ if (lang !== 'en' && lang !== 'fr' && translations[lang]?.buttonText) {
75
+ buttonText[lang] = translations[lang].buttonText;
76
+ }
77
+ });
78
+ return {
79
+ buttonText,
80
+ themeColor: '#2DBD60', // Default theme color
81
+ };
82
+ }
83
+ /**
84
+ * Transform welcome config
85
+ */
86
+ function transformWelcomeConfig(config) {
87
+ return {
88
+ subtitle: config.subtitle,
89
+ buttonText: config.buttonText,
90
+ requirements: config.requirements || [],
91
+ estimatedTime: config.estimatedTime,
92
+ consentOptions: config.consentOptions || {
93
+ showPrivacyPolicy: true,
94
+ showTermsOfService: true,
95
+ showMarketingConsent: false,
96
+ },
97
+ welcomeMessage: config.welcomeMessage,
98
+ showEstimatedTime: config.showEstimatedTime !== false,
99
+ };
100
+ }
101
+ /**
102
+ * Transform government ID config to IDCardConfig
103
+ */
104
+ function transformGovernmentIdConfig(config) {
105
+ const documentTypes = config.documentTypes || ['passport', 'nationalId'];
106
+ const sides = [];
107
+ if (config.requiredSides === 'front-back' || config.requiredSides === 'both') {
108
+ sides.push('front', 'back');
109
+ }
110
+ else if (config.requiredSides === 'front') {
111
+ sides.push('front');
112
+ }
113
+ else if (config.requiredSides === 'back') {
114
+ sides.push('back');
115
+ }
116
+ else {
117
+ // Default to both sides
118
+ sides.push('front', 'back');
119
+ }
120
+ const idCardConfig = {
121
+ sides,
122
+ allowed_formats: ['jpg', 'jpeg', 'png'],
123
+ max_size_mb: 10,
124
+ document_types: documentTypes.map((dt) => {
125
+ const mapping = {
126
+ 'passport': 'passport',
127
+ 'nationalId': 'national_id',
128
+ 'driversLicense': 'drivers_licence',
129
+ 'identityCard': 'identity_card',
130
+ };
131
+ return mapping[dt] || dt;
132
+ }),
133
+ };
134
+ // Add bbox configs if available
135
+ if (config.cameraOverlay?.bbox) {
136
+ const bbox = config.cameraOverlay.bbox;
137
+ idCardConfig.bbox_configs = {};
138
+ documentTypes.forEach((dt) => {
139
+ const docType = dt;
140
+ idCardConfig.bbox_configs[docType] = {
141
+ xMin: bbox.xMin || 20,
142
+ yMin: bbox.yMin || 140,
143
+ xMax: bbox.xMax || 370,
144
+ yMax: bbox.yMax || 340,
145
+ borderColor: bbox.borderColor || '#2DBD60',
146
+ borderWidth: bbox.borderWidth || 3,
147
+ cornerRadius: bbox.cornerRadius || 8,
148
+ };
149
+ });
150
+ }
151
+ // Store additional backend-specific config in a way that can be accessed
152
+ idCardConfig.authenticationMethods = config.authenticationMethods;
153
+ idCardConfig.documentTypesByCountry = config.documentTypesByCountry;
154
+ idCardConfig.selectedCountries = config.selectedCountries;
155
+ idCardConfig.instructionsByDocumentType = config.instructionsByDocumentType;
156
+ idCardConfig.cameraSettings = config.cameraSettings;
157
+ idCardConfig.validationRules = config.validationRules;
158
+ return idCardConfig;
159
+ }
160
+ /**
161
+ * Transform location capture config
162
+ */
163
+ function transformLocationConfig(config) {
164
+ return {
165
+ accuracy: config.accuracy || 'high',
166
+ required: config.required !== false,
167
+ };
168
+ }
169
+ /**
170
+ * Transform selfie capture config
171
+ */
172
+ function transformSelfieConfig(config) {
173
+ return {
174
+ liveness_check: config.livenessEnabled !== false,
175
+ max_attempts: config.maxAttempts || 5,
176
+ orientations: config.orientations || ['center'],
177
+ };
178
+ }
179
+ /**
180
+ * Transform component config based on type
181
+ */
182
+ function transformComponentConfig(type, backendConfig) {
183
+ switch (type) {
184
+ case 'welcome':
185
+ return transformWelcomeConfig(backendConfig);
186
+ case 'id_card':
187
+ return transformGovernmentIdConfig(backendConfig);
188
+ case 'location':
189
+ return transformLocationConfig(backendConfig);
190
+ case 'selfie':
191
+ return transformSelfieConfig(backendConfig);
192
+ case 'file_upload':
193
+ return {
194
+ allowed_formats: backendConfig.allowed_formats || ['jpg', 'jpeg', 'png', 'pdf'],
195
+ max_size_mb: backendConfig.max_size_mb || 10,
196
+ required: backendConfig.required !== false,
197
+ };
198
+ case 'country_selection':
199
+ return {
200
+ allowed_countries: backendConfig.allowed_countries || [],
201
+ default_country: backendConfig.default_country || '',
202
+ required: backendConfig.required !== false,
203
+ };
204
+ case 'email_verification':
205
+ return backendConfig;
206
+ case 'phone_verification':
207
+ return backendConfig;
208
+ case 'personal_information':
209
+ return backendConfig;
210
+ case 'additional_documents':
211
+ return backendConfig;
212
+ default:
213
+ return backendConfig;
214
+ }
215
+ }
216
+ /**
217
+ * Transform a single backend component to SDK component
218
+ */
219
+ function transformComponent(backendComponent, componentIndex) {
220
+ const mappedType = COMPONENT_TYPE_MAPPING[backendComponent.type];
221
+ if (!mappedType) {
222
+ logger.warn(`Unknown component type: ${backendComponent.type}, defaulting to initialization`);
223
+ }
224
+ const componentId = hashStringToNumber(backendComponent.id);
225
+ const { labels, instructions } = transformTranslations(backendComponent.translations);
226
+ const ui = transformUI(backendComponent.translations);
227
+ const config = transformComponentConfig(mappedType || 'initialization', backendComponent.config);
228
+ // For components with multiple sides (like id_card), create nested structure
229
+ let finalLabels = labels;
230
+ let finalInstructions = instructions;
231
+ let finalUI = ui;
232
+ if (mappedType === 'id_card' && backendComponent.config.requiredSides === 'front-back') {
233
+ // Create separate labels/instructions for front and back
234
+ finalLabels = {
235
+ front: {
236
+ en: backendComponent.translations.en?.title || labels.en,
237
+ fr: backendComponent.translations.fr?.title || labels.fr,
238
+ },
239
+ back: {
240
+ en: `${labels.en} (Back)`,
241
+ fr: `${labels.fr} (Verso)`,
242
+ },
243
+ };
244
+ finalInstructions = {
245
+ front: instructions,
246
+ back: instructions,
247
+ };
248
+ finalUI = {
249
+ front: ui,
250
+ back: ui,
251
+ };
252
+ }
253
+ return {
254
+ id: componentId,
255
+ type: mappedType || 'initialization',
256
+ order: backendComponent.order,
257
+ labels: finalLabels,
258
+ instructions: finalInstructions,
259
+ ui: finalUI,
260
+ config,
261
+ required: backendComponent.required !== false,
262
+ };
263
+ }
264
+ /**
265
+ * Transform backend template to SDK template format
266
+ */
267
+ export function transformBackendTemplateToSDK(backendTemplate) {
268
+ try {
269
+ // Validate backend template
270
+ if (!backendTemplate.id || !backendTemplate.name || !Array.isArray(backendTemplate.components)) {
271
+ throw new Error('Invalid backend template structure');
272
+ }
273
+ // Sort components by order
274
+ const sortedComponents = [...backendTemplate.components].sort((a, b) => a.order - b.order);
275
+ // Transform each component
276
+ const transformedComponents = sortedComponents.map((comp, index) => transformComponent(comp, index));
277
+ // Auto-create country_selection component before id_card if government-id has selection data
278
+ // Check if country_selection already exists in backend template
279
+ const hasCountrySelectionInBackend = sortedComponents.some(c => c.type === 'country-selection');
280
+ if (!hasCountrySelectionInBackend) {
281
+ // Find the first government-id component with selection data
282
+ const govIdWithSelection = sortedComponents.find(backendComp => backendComp.type === 'government-id' &&
283
+ backendComp.config && (backendComp.config.selectedCountries ||
284
+ backendComp.config.documentTypesByCountry));
285
+ if (govIdWithSelection) {
286
+ // Find the corresponding transformed id_card component
287
+ const transformedIdCard = transformedComponents.find(c => hashStringToNumber(govIdWithSelection.id) === c.id);
288
+ if (transformedIdCard) {
289
+ // Create a country_selection component before id_card
290
+ const countrySelectionComponent = {
291
+ id: hashStringToNumber(`${govIdWithSelection.id}-country-selection`),
292
+ type: 'country_selection',
293
+ order: transformedIdCard.order - 0.5, // Insert before id_card
294
+ labels: {
295
+ en: govIdWithSelection.translations.en?.title || 'Select Country and Document',
296
+ fr: govIdWithSelection.translations.fr?.title || 'Sélectionnez le pays et le document',
297
+ },
298
+ instructions: {
299
+ en: 'Please select your country and document type',
300
+ fr: 'Veuillez sélectionner votre pays et le type de document',
301
+ },
302
+ ui: {
303
+ themeColor: '#2DBD60',
304
+ buttonText: {
305
+ en: 'Continue',
306
+ fr: 'Continuer',
307
+ },
308
+ },
309
+ config: {
310
+ allowed_countries: govIdWithSelection.config.selectedCountries || [],
311
+ default_country: '',
312
+ required: true,
313
+ },
314
+ };
315
+ // Insert country_selection before id_card in transformedComponents
316
+ const idCardIndex = transformedComponents.indexOf(transformedIdCard);
317
+ transformedComponents.splice(idCardIndex, 0, countrySelectionComponent);
318
+ }
319
+ }
320
+ }
321
+ // Re-assign order values sequentially after insertion
322
+ transformedComponents.forEach((comp, index) => {
323
+ comp.order = index + 1;
324
+ });
325
+ // Create SDK template
326
+ const sdkTemplate = {
327
+ id: hashStringToNumber(backendTemplate.id),
328
+ name: backendTemplate.name,
329
+ description: backendTemplate.description || {
330
+ en: '',
331
+ fr: '',
332
+ },
333
+ version: backendTemplate.version || '1.0.0',
334
+ components: transformedComponents,
335
+ };
336
+ logger.log(`Template transformed: ${backendTemplate.id} -> ${sdkTemplate.id} with ${transformedComponents.length} components`);
337
+ return sdkTemplate;
338
+ }
339
+ catch (error) {
340
+ logger.error('Error transforming template:', error);
341
+ throw new Error(`Failed to transform template: ${error.message}`);
342
+ }
343
+ }
344
+ /**
345
+ * Validate transformed template
346
+ */
347
+ export function validateTransformedTemplate(template) {
348
+ if (!template.id || !template.name || !Array.isArray(template.components)) {
349
+ return false;
350
+ }
351
+ if (!template.name.en || !template.name.fr) {
352
+ return false;
353
+ }
354
+ // Validate each component
355
+ for (const component of template.components) {
356
+ if (!component.id || !component.type || typeof component.order !== 'number') {
357
+ return false;
358
+ }
359
+ if (!component.labels || !component.instructions || !component.config) {
360
+ return false;
361
+ }
362
+ }
363
+ return true;
364
+ }
365
+ //# sourceMappingURL=template-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-transformer.js","sourceRoot":"","sources":["../../src/utils/template-transformer.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;GAEG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACnC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,4BAA4B;IAClD,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,sBAAsB,GAA8C;IACxE,SAAS,EAAE,SAAS;IACpB,eAAe,EAAE,SAAS;IAC1B,gBAAgB,EAAE,QAAQ;IAC1B,kBAAkB,EAAE,UAAU;IAC9B,eAAe,EAAE,eAAe;IAChC,uBAAuB,EAAE,uBAAuB;IAChD,aAAa,EAAE,aAAa;IAC5B,mBAAmB,EAAE,mBAAmB;IACxC,oBAAoB,EAAE,oBAAoB;IAC1C,oBAAoB,EAAE,oBAAoB;IAC1C,sBAAsB,EAAE,sBAAsB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ACpD,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAqB;IAC/D,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,0BAA0B;IAC1B,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC5C,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5E,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {\n BackendKYCTemplate,\n BackendTemplateComponent,\n KYCTemplate,\n TemplateComponent,\n LocalizedText,\n ComponentUI,\n IDCardConfig,\n LocationConfig,\n SelfieConfig,\n FileUploadConfig,\n CountrySelectionConfig,\n ComponentConfig,\n WelcomeConfig,\n GovernmentDocumentType,\n GovernmentIdConfig,\n} from '../types/KYC.types';\nimport { logger } from './logger';\n\n/**\n * Hash a string to a number (simple hash function)\n */\nfunction hashStringToNumber(str: string): number {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return Math.abs(hash);\n}\n\n/**\n * Map backend component types to SDK component types\n */\nconst COMPONENT_TYPE_MAPPING: Record<string, TemplateComponent['type']> = {\n 'welcome': 'welcome',\n 'government-id': 'id_card',\n 'selfie-capture': 'selfie',\n 'location-capture': 'location',\n 'review-submit': 'review_submit',\n 'verification-progress': 'verification_progress',\n 'file-upload': 'file_upload',\n 'country-selection': 'country_selection',\n 'email-verification': 'email_verification',\n 'phone-verification': 'phone_verification',\n 'personal-information': 'personal_information',\n 'additional-documents': 'additional_documents',\n};\n\n/**\n * Transform backend translations to SDK labels and instructions\n */\nfunction transformTranslations(\n translations: BackendTemplateComponent['translations'],\n defaultLanguage: string = 'en'\n): { labels: LocalizedText; instructions: LocalizedText } {\n const labels: LocalizedText = { en: '', fr: '' };\n const instructions: LocalizedText = { en: '', fr: '' };\n\n // Extract title as label\n if (translations.en?.title) labels.en = translations.en.title;\n if (translations.fr?.title) labels.fr = translations.fr.title;\n\n // Extract instructions\n if (translations.en?.instructions) instructions.en = translations.en.instructions;\n if (translations.fr?.instructions) instructions.fr = translations.fr.instructions;\n\n // Fallback to description if instructions not available\n if (!instructions.en && translations.en?.description) {\n instructions.en = translations.en.description;\n }\n if (!instructions.fr && translations.fr?.description) {\n instructions.fr = translations.fr.description;\n }\n\n // Support other languages\n Object.keys(translations).forEach((lang) => {\n if (lang !== 'en' && lang !== 'fr' && translations[lang]) {\n labels[lang] = translations[lang]?.title || '';\n instructions[lang] = translations[lang]?.instructions || translations[lang]?.description || '';\n }\n });\n\n return { labels, instructions };\n}\n\n/**\n * Transform UI configuration\n */\nfunction transformUI(translations: BackendTemplateComponent['translations']): ComponentUI {\n const buttonText: LocalizedText = { en: '', fr: '' };\n\n if (translations.en?.buttonText) buttonText.en = translations.en.buttonText;\n if (translations.fr?.buttonText) buttonText.fr = translations.fr.buttonText;\n\n // Support other languages\n Object.keys(translations).forEach((lang) => {\n if (lang !== 'en' && lang !== 'fr' && translations[lang]?.buttonText) {\n buttonText[lang] = translations[lang]!.buttonText!;\n }\n });\n\n return {\n buttonText,\n themeColor: '#2DBD60', // Default theme color\n };\n}\n\n/**\n * Transform welcome config\n */\nfunction transformWelcomeConfig(config: any): WelcomeConfig {\n return {\n subtitle: config.subtitle,\n buttonText: config.buttonText,\n requirements: config.requirements || [],\n estimatedTime: config.estimatedTime,\n consentOptions: config.consentOptions || {\n showPrivacyPolicy: true,\n showTermsOfService: true,\n showMarketingConsent: false,\n },\n welcomeMessage: config.welcomeMessage,\n showEstimatedTime: config.showEstimatedTime !== false,\n } as WelcomeConfig;\n}\n\n/**\n * Transform government ID config to IDCardConfig\n */\nfunction transformGovernmentIdConfig(config: any): IDCardConfig {\n const documentTypes: string[] = config.documentTypes || ['passport', 'nationalId'];\n const sides: string[] = [];\n\n if (config.requiredSides === 'front-back' || config.requiredSides === 'both') {\n sides.push('front', 'back');\n } else if (config.requiredSides === 'front') {\n sides.push('front');\n } else if (config.requiredSides === 'back') {\n sides.push('back');\n } else {\n // Default to both sides\n sides.push('front', 'back');\n }\n\n const idCardConfig: IDCardConfig = {\n sides,\n allowed_formats: ['jpg', 'jpeg', 'png'],\n max_size_mb: 10,\n document_types: documentTypes.map((dt: string) => {\n const mapping: Record<string, any> = {\n 'passport': 'passport',\n 'nationalId': 'national_id',\n 'driversLicense': 'drivers_licence',\n 'identityCard': 'identity_card',\n };\n return mapping[dt] || dt;\n }) as any[],\n };\n\n // Add bbox configs if available\n if (config.cameraOverlay?.bbox) {\n const bbox = config.cameraOverlay.bbox;\n idCardConfig.bbox_configs = {} as Record<GovernmentDocumentType, {\n xMin: number;\n yMin: number;\n xMax: number;\n yMax: number;\n borderColor?: string;\n borderWidth?: number;\n cornerRadius?: number;\n }>;\n documentTypes.forEach((dt: string) => {\n const docType = dt as GovernmentDocumentType;\n (idCardConfig.bbox_configs as any)[docType] = {\n xMin: bbox.xMin || 20,\n yMin: bbox.yMin || 140,\n xMax: bbox.xMax || 370,\n yMax: bbox.yMax || 340,\n borderColor: bbox.borderColor || '#2DBD60',\n borderWidth: bbox.borderWidth || 3,\n cornerRadius: bbox.cornerRadius || 8,\n };\n });\n }\n\n // Store additional backend-specific config in a way that can be accessed\n (idCardConfig as any).authenticationMethods = config.authenticationMethods;\n (idCardConfig as any).documentTypesByCountry = config.documentTypesByCountry;\n (idCardConfig as any).selectedCountries = config.selectedCountries;\n (idCardConfig as any).instructionsByDocumentType = config.instructionsByDocumentType;\n (idCardConfig as any).cameraSettings = config.cameraSettings;\n (idCardConfig as any).validationRules = config.validationRules;\n\n return idCardConfig;\n}\n\n/**\n * Transform location capture config\n */\nfunction transformLocationConfig(config: any): LocationConfig {\n return {\n accuracy: config.accuracy || 'high',\n required: config.required !== false,\n } as LocationConfig;\n}\n\n/**\n * Transform selfie capture config\n */\nfunction transformSelfieConfig(config: any): SelfieConfig {\n return {\n liveness_check: config.livenessEnabled !== false,\n max_attempts: config.maxAttempts || 5,\n orientations: config.orientations || ['center'],\n } as SelfieConfig;\n}\n\n/**\n * Transform component config based on type\n */\nfunction transformComponentConfig(\n type: TemplateComponent['type'],\n backendConfig: any\n): ComponentConfig {\n switch (type) {\n case 'welcome':\n return transformWelcomeConfig(backendConfig);\n case 'id_card':\n return transformGovernmentIdConfig(backendConfig);\n case 'location':\n return transformLocationConfig(backendConfig);\n case 'selfie':\n return transformSelfieConfig(backendConfig);\n case 'file_upload':\n return {\n allowed_formats: backendConfig.allowed_formats || ['jpg', 'jpeg', 'png', 'pdf'],\n max_size_mb: backendConfig.max_size_mb || 10,\n required: backendConfig.required !== false,\n } as FileUploadConfig;\n case 'country_selection':\n return {\n allowed_countries: backendConfig.allowed_countries || [],\n default_country: backendConfig.default_country || '',\n required: backendConfig.required !== false,\n } as CountrySelectionConfig;\n case 'email_verification':\n return backendConfig as any;\n case 'phone_verification':\n return backendConfig as any;\n case 'personal_information':\n return backendConfig as any;\n case 'additional_documents':\n return backendConfig as any;\n default:\n return backendConfig as ComponentConfig;\n }\n}\n\n/**\n * Transform a single backend component to SDK component\n */\nfunction transformComponent(\n backendComponent: BackendTemplateComponent,\n componentIndex: number\n): TemplateComponent {\n const mappedType = COMPONENT_TYPE_MAPPING[backendComponent.type];\n\n if (!mappedType) {\n logger.warn(`Unknown component type: ${backendComponent.type}, defaulting to initialization`);\n }\n\n const componentId = hashStringToNumber(backendComponent.id);\n const { labels, instructions } = transformTranslations(backendComponent.translations);\n const ui = transformUI(backendComponent.translations);\n const config = transformComponentConfig(mappedType || 'initialization', backendComponent.config);\n\n // For components with multiple sides (like id_card), create nested structure\n let finalLabels: LocalizedText | Record<string, LocalizedText> = labels;\n let finalInstructions: LocalizedText | Record<string, LocalizedText> = instructions;\n let finalUI: ComponentUI | Record<string, ComponentUI> = ui;\n\n if (mappedType === 'id_card' && (backendComponent.config as GovernmentIdConfig).requiredSides === 'front-back') {\n // Create separate labels/instructions for front and back\n finalLabels = {\n front: {\n en: backendComponent.translations.en?.title || labels.en,\n fr: backendComponent.translations.fr?.title || labels.fr,\n },\n back: {\n en: `${labels.en} (Back)`,\n fr: `${labels.fr} (Verso)`,\n },\n };\n finalInstructions = {\n front: instructions,\n back: instructions,\n };\n finalUI = {\n front: ui,\n back: ui,\n };\n }\n\n return {\n id: componentId,\n type: mappedType || 'initialization',\n order: backendComponent.order,\n labels: finalLabels,\n instructions: finalInstructions,\n ui: finalUI,\n config,\n required: backendComponent.required !== false,\n } as TemplateComponent;\n}\n\n/**\n * Transform backend template to SDK template format\n */\nexport function transformBackendTemplateToSDK(\n backendTemplate: BackendKYCTemplate\n): KYCTemplate {\n try {\n // Validate backend template\n if (!backendTemplate.id || !backendTemplate.name || !Array.isArray(backendTemplate.components)) {\n throw new Error('Invalid backend template structure');\n }\n\n // Sort components by order\n const sortedComponents = [...backendTemplate.components].sort(\n (a, b) => a.order - b.order\n );\n\n // Transform each component\n const transformedComponents = sortedComponents.map((comp, index) =>\n transformComponent(comp, index)\n );\n\n // Auto-create country_selection component before id_card if government-id has selection data\n // Check if country_selection already exists in backend template\n const hasCountrySelectionInBackend = sortedComponents.some(c => (c as any).type === 'country-selection');\n\n if (!hasCountrySelectionInBackend) {\n // Find the first government-id component with selection data\n const govIdWithSelection = sortedComponents.find(backendComp =>\n backendComp.type === 'government-id' &&\n backendComp.config && (\n (backendComp.config as any).selectedCountries ||\n (backendComp.config as any).documentTypesByCountry\n )\n );\n\n if (govIdWithSelection) {\n // Find the corresponding transformed id_card component\n const transformedIdCard = transformedComponents.find(c =>\n hashStringToNumber(govIdWithSelection.id) === c.id\n );\n\n if (transformedIdCard) {\n // Create a country_selection component before id_card\n const countrySelectionComponent: TemplateComponent = {\n id: hashStringToNumber(`${govIdWithSelection.id}-country-selection`),\n type: 'country_selection',\n order: transformedIdCard.order - 0.5, // Insert before id_card\n labels: {\n en: govIdWithSelection.translations.en?.title || 'Select Country and Document',\n fr: govIdWithSelection.translations.fr?.title || 'Sélectionnez le pays et le document',\n },\n instructions: {\n en: 'Please select your country and document type',\n fr: 'Veuillez sélectionner votre pays et le type de document',\n },\n ui: {\n themeColor: '#2DBD60',\n buttonText: {\n en: 'Continue',\n fr: 'Continuer',\n },\n } as ComponentUI,\n config: {\n allowed_countries: (govIdWithSelection.config as any).selectedCountries || [],\n default_country: '',\n required: true,\n } as CountrySelectionConfig,\n };\n\n // Insert country_selection before id_card in transformedComponents\n const idCardIndex = transformedComponents.indexOf(transformedIdCard);\n transformedComponents.splice(idCardIndex, 0, countrySelectionComponent);\n }\n }\n }\n\n // Re-assign order values sequentially after insertion\n transformedComponents.forEach((comp, index) => {\n comp.order = index + 1;\n });\n\n // Create SDK template\n const sdkTemplate: KYCTemplate = {\n id: hashStringToNumber(backendTemplate.id),\n name: backendTemplate.name as LocalizedText,\n description: backendTemplate.description || {\n en: '',\n fr: '',\n },\n version: backendTemplate.version || '1.0.0',\n components: transformedComponents,\n };\n\n logger.log(`Template transformed: ${backendTemplate.id} -> ${sdkTemplate.id} with ${transformedComponents.length} components`);\n\n return sdkTemplate;\n } catch (error: any) {\n logger.error('Error transforming template:', error);\n throw new Error(`Failed to transform template: ${error.message}`);\n }\n}\n\n/**\n * Validate transformed template\n */\nexport function validateTransformedTemplate(template: KYCTemplate): boolean {\n if (!template.id || !template.name || !Array.isArray(template.components)) {\n return false;\n }\n\n if (!template.name.en || !template.name.fr) {\n return false;\n }\n\n // Validate each component\n for (const component of template.components) {\n if (!component.id || !component.type || typeof component.order !== 'number') {\n return false;\n }\n\n if (!component.labels || !component.instructions || !component.config) {\n return false;\n }\n }\n\n return true;\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WebKYCEntry.d.ts","sourceRoot":"","sources":["../../src/web/WebKYCEntry.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAOhE,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAUD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA2K3C,CAAC;AAsBF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"WebKYCEntry.d.ts","sourceRoot":"","sources":["../../src/web/WebKYCEntry.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAUhE,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAsBD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA6Q3C,CAAC;AA0DF,eAAe,WAAW,CAAC"}