@incodetech/web 2.0.0-alpha.1 → 2.0.0-alpha.11

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 (209) hide show
  1. package/dist/base.css +1071 -0
  2. package/dist/browser-ponyfill-B6W6hHVY.js +344 -0
  3. package/dist/email/email.es.js +145 -0
  4. package/dist/email/styles.css +123 -0
  5. package/dist/flow/flow.es.js +555 -0
  6. package/dist/flow/styles.css +1119 -0
  7. package/dist/incodeModule-Dv8Qllrv.js +254 -0
  8. package/dist/index.es.js +6 -0
  9. package/dist/instance-B-q0ZREN.js +2140 -0
  10. package/dist/otpInput-BtoZe0Wz.js +151 -0
  11. package/dist/page-Dh_Zw2ik.js +234 -0
  12. package/dist/phone/phone.es.js +3441 -0
  13. package/dist/phone/styles.css +305 -0
  14. package/dist/selfie/selfie.es.js +893 -0
  15. package/dist/selfie/styles.css +590 -0
  16. package/dist/selfieTutorial-C-u5GufD.js +29 -0
  17. package/dist/setup-wNL83jmW.js +20 -0
  18. package/dist/themes/dark.css +652 -0
  19. package/dist/themes/light.css +543 -0
  20. package/dist/title-BfO5Dlzk.js +25 -0
  21. package/dist/types/base.d.ts +1 -0
  22. package/dist/types/dark.d.ts +1 -0
  23. package/dist/types/email.d.ts +57 -0
  24. package/dist/types/flow.d.ts +69 -0
  25. package/dist/types/index.d.ts +38 -0
  26. package/dist/types/light.d.ts +1 -0
  27. package/dist/types/phone.d.ts +58 -0
  28. package/dist/types/selfie.d.ts +31 -0
  29. package/dist/types/styles.d.ts +1 -0
  30. package/dist/types/themes/dark.d.ts +1 -0
  31. package/dist/types/themes/light.d.ts +1 -0
  32. package/dist/uiConfig-CQ1W9cUD.js +23 -0
  33. package/dist/vendor-preact-CK0WeTOR.js +584 -0
  34. package/package.json +32 -26
  35. package/dev/README.md +0 -163
  36. package/dev/getToken.ts +0 -36
  37. package/dev/headless.html +0 -875
  38. package/dev/index.html +0 -366
  39. package/dev/main-headless.tsx +0 -1332
  40. package/dev/main-orchestrated-flow.tsx +0 -1158
  41. package/dev/main-preact.tsx +0 -323
  42. package/dev/main-simplified.tsx +0 -123
  43. package/dev/main-web-component.tsx +0 -256
  44. package/dev/main.tsx +0 -332
  45. package/dev/manual.html +0 -27
  46. package/dev/orchestrated-flow.html +0 -64
  47. package/dev/simplified.html +0 -64
  48. package/dev/tiktok-logo.svg +0 -7
  49. package/src/defineCustomElement.tsx +0 -30
  50. package/src/email/email.test.tsx +0 -368
  51. package/src/email/email.tsx +0 -255
  52. package/src/email/emailInput.test.tsx +0 -264
  53. package/src/email/emailInput.tsx +0 -85
  54. package/src/email/styles.css +0 -59
  55. package/src/flow/flow.test.tsx +0 -796
  56. package/src/flow/flow.tsx +0 -292
  57. package/src/flow/flowCompleted.css +0 -30
  58. package/src/flow/flowCompleted.test.tsx +0 -331
  59. package/src/flow/flowCompleted.tsx +0 -121
  60. package/src/flow/flowInit.test.ts +0 -264
  61. package/src/flow/flowInit.ts +0 -94
  62. package/src/flow/flowStart.css +0 -58
  63. package/src/flow/flowStart.test.tsx +0 -49
  64. package/src/flow/flowStart.tsx +0 -41
  65. package/src/flow/incode-logo.svg +0 -8
  66. package/src/flow/index.ts +0 -7
  67. package/src/flow/preloadFlow.test.ts +0 -421
  68. package/src/flow/preloadFlow.ts +0 -171
  69. package/src/flow/styles.css +0 -9
  70. package/src/flow/unsupportedModule.css +0 -21
  71. package/src/flow/unsupportedModule.tsx +0 -39
  72. package/src/flow/useFlowInitialization.test.tsx +0 -292
  73. package/src/flow/useFlowInitialization.ts +0 -128
  74. package/src/flow/useModuleLoader.test.tsx +0 -212
  75. package/src/flow/useModuleLoader.ts +0 -92
  76. package/src/hooks/index.ts +0 -1
  77. package/src/hooks/useManager.test.ts +0 -91
  78. package/src/hooks/useManager.ts +0 -40
  79. package/src/i18n/index.ts +0 -3
  80. package/src/i18n/instance.ts +0 -16
  81. package/src/i18n/setup.ts +0 -184
  82. package/src/i18n/useTranslation.ts +0 -42
  83. package/src/index.ts +0 -27
  84. package/src/permissions/assets/android-dots-icon.svg +0 -7
  85. package/src/permissions/assets/android-settings-icon.svg +0 -16
  86. package/src/permissions/assets/android-toggle-icon.svg +0 -20
  87. package/src/permissions/assets/bank-card-icon.svg +0 -14
  88. package/src/permissions/assets/camera-icon.svg +0 -12
  89. package/src/permissions/assets/camera-ios.svg +0 -53
  90. package/src/permissions/assets/check-icon.svg +0 -8
  91. package/src/permissions/assets/chrome-icon.svg +0 -43
  92. package/src/permissions/assets/password-icon.svg +0 -11
  93. package/src/permissions/assets/permissions-img.svg +0 -51
  94. package/src/permissions/assets/safari-icon.svg +0 -37
  95. package/src/permissions/assets/settings-icon.svg +0 -33
  96. package/src/permissions/assets/toggle-icon.svg +0 -19
  97. package/src/permissions/assets/warning-icon.svg +0 -6
  98. package/src/permissions/boldWithArrow.css +0 -9
  99. package/src/permissions/boldWithArrow.tsx +0 -41
  100. package/src/permissions/denied.css +0 -37
  101. package/src/permissions/denied.tsx +0 -29
  102. package/src/permissions/deniedAndroid.tsx +0 -56
  103. package/src/permissions/deniedDesktop.css +0 -9
  104. package/src/permissions/deniedDesktop.tsx +0 -64
  105. package/src/permissions/deniedIOS.tsx +0 -73
  106. package/src/permissions/deniedInstructions.tsx +0 -19
  107. package/src/permissions/iconWrapper.css +0 -9
  108. package/src/permissions/iconWrapper.tsx +0 -15
  109. package/src/permissions/learnMore.css +0 -37
  110. package/src/permissions/learnMore.tsx +0 -85
  111. package/src/permissions/numberedStep.css +0 -13
  112. package/src/permissions/numberedStep.tsx +0 -14
  113. package/src/permissions/permissions.css +0 -13
  114. package/src/permissions/permissions.tsx +0 -68
  115. package/src/phone/phone.tsx +0 -246
  116. package/src/phone/phoneInput.test.tsx +0 -275
  117. package/src/phone/phoneInput.tsx +0 -249
  118. package/src/phone/styles.css +0 -158
  119. package/src/selfie/cameraButton.css +0 -13
  120. package/src/selfie/cameraButton.tsx +0 -35
  121. package/src/selfie/capture.css +0 -57
  122. package/src/selfie/capture.tsx +0 -232
  123. package/src/selfie/errorModal.tsx +0 -218
  124. package/src/selfie/errorModalContent.css +0 -33
  125. package/src/selfie/errorModalContent.tsx +0 -44
  126. package/src/selfie/faceOutline.css +0 -5
  127. package/src/selfie/faceOutline.tsx +0 -22
  128. package/src/selfie/loadingBorder.css +0 -12
  129. package/src/selfie/loadingBorder.tsx +0 -77
  130. package/src/selfie/manualCaptureButton.css +0 -13
  131. package/src/selfie/manualCaptureButton.tsx +0 -35
  132. package/src/selfie/noMoreAttemptsModal.tsx +0 -44
  133. package/src/selfie/notification.css +0 -9
  134. package/src/selfie/notification.tsx +0 -36
  135. package/src/selfie/retryErrorModal.tsx +0 -56
  136. package/src/selfie/selfie.test.tsx +0 -458
  137. package/src/selfie/selfie.tsx +0 -83
  138. package/src/selfie/selfieTutorial.json +0 -2626
  139. package/src/selfie/styles.css +0 -1
  140. package/src/selfie/tutorial.test.tsx +0 -200
  141. package/src/selfie/tutorial.tsx +0 -43
  142. package/src/setup.ts +0 -33
  143. package/src/shared/baseTutorial/baseTutorial.css +0 -21
  144. package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
  145. package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
  146. package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
  147. package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
  148. package/src/shared/button/button.css +0 -55
  149. package/src/shared/button/button.test.tsx +0 -101
  150. package/src/shared/button/button.tsx +0 -47
  151. package/src/shared/componentRoot/incodeComponent.tsx +0 -12
  152. package/src/shared/countries/countries.test.ts +0 -75
  153. package/src/shared/countries/countries.ts +0 -139
  154. package/src/shared/countries/index.ts +0 -6
  155. package/src/shared/icons/chevronDown.tsx +0 -22
  156. package/src/shared/icons/index.ts +0 -2
  157. package/src/shared/icons/successIcon.css +0 -5
  158. package/src/shared/icons/successIcon.test.tsx +0 -40
  159. package/src/shared/icons/successIcon.tsx +0 -26
  160. package/src/shared/loader/loadingIcon.css +0 -28
  161. package/src/shared/loader/loadingIcon.tsx +0 -67
  162. package/src/shared/lottie/lottie.tsx +0 -108
  163. package/src/shared/otpInput/otpInput.css +0 -85
  164. package/src/shared/otpInput/otpInput.test.tsx +0 -356
  165. package/src/shared/otpInput/otpInput.tsx +0 -241
  166. package/src/shared/page/incode-logo.svg +0 -3
  167. package/src/shared/page/page.css +0 -47
  168. package/src/shared/page/page.test.tsx +0 -97
  169. package/src/shared/page/page.tsx +0 -91
  170. package/src/shared/page/pageUiConfig.test.ts +0 -112
  171. package/src/shared/page/pageUiConfig.ts +0 -64
  172. package/src/shared/page/verifiedByIncode.css +0 -5
  173. package/src/shared/page/verifiedByIncode.tsx +0 -75
  174. package/src/shared/spacer/spacer.css +0 -149
  175. package/src/shared/spacer/spacer.test.tsx +0 -143
  176. package/src/shared/spacer/spacer.tsx +0 -88
  177. package/src/shared/spinner/index.ts +0 -2
  178. package/src/shared/spinner/spinner.css +0 -28
  179. package/src/shared/spinner/spinner.test.tsx +0 -82
  180. package/src/shared/spinner/spinner.tsx +0 -65
  181. package/src/shared/title/title.css +0 -7
  182. package/src/shared/title/title.tsx +0 -12
  183. package/src/shared/uiConfig/uiConfig.ts +0 -36
  184. package/src/shared/webComponent/incodeModule.ts +0 -29
  185. package/src/shared/webComponent/registerIncodeElement.ts +0 -15
  186. package/src/styles/__mocks__/fetchTheme.ts +0 -19
  187. package/src/styles/applyTheme.ts +0 -37
  188. package/src/styles/cn.test.tsx +0 -57
  189. package/src/styles/cn.tsx +0 -21
  190. package/src/styles/core.css +0 -12
  191. package/src/styles/fetchTheme.test.ts +0 -390
  192. package/src/styles/fetchTheme.ts +0 -88
  193. package/src/styles/generatePalette.ts +0 -111
  194. package/src/styles/reset.css +0 -65
  195. package/src/styles/resolveCssVariableToHex.ts +0 -28
  196. package/src/styles/tailwind.css +0 -291
  197. package/src/styles/themeTypes.ts +0 -18
  198. package/src/styles/tokens/colors.css +0 -190
  199. package/src/styles/tokens/components.css +0 -174
  200. package/src/styles/tokens/index.css +0 -4
  201. package/src/styles/tokens/primitives.css +0 -129
  202. package/src/styles/tokens/semantic.css +0 -51
  203. package/src/svg.d.ts +0 -4
  204. package/src/types/assets.d.ts +0 -1
  205. package/src/types/custom-elements.d.ts +0 -104
  206. package/tsconfig.json +0 -22
  207. package/vite.config.ts +0 -260
  208. package/vitest.config.ts +0 -40
  209. package/vitest.setup.ts +0 -16
@@ -1,368 +0,0 @@
1
- import { fireEvent, render, screen } from '@testing-library/preact';
2
- import { beforeEach, describe, expect, it, vi } from 'vitest';
3
- import { Email } from './email';
4
-
5
- // Mock the email manager
6
- const mockManager = {
7
- load: vi.fn(),
8
- setEmail: vi.fn(),
9
- submit: vi.fn(),
10
- submitOtp: vi.fn(),
11
- resendOtp: vi.fn(),
12
- back: vi.fn(),
13
- reset: vi.fn(),
14
- getState: vi.fn(),
15
- subscribe: vi.fn(),
16
- stop: vi.fn(),
17
- };
18
-
19
- vi.mock('@incodetech/core/email', () => ({
20
- createEmailManager: vi.fn(() => mockManager),
21
- }));
22
-
23
- // Mock state type for testing different states
24
- type MockState = {
25
- status: string;
26
- resendTimer?: number;
27
- canResend?: boolean;
28
- error?: string;
29
- prefilledEmail?: string;
30
- emailError?: string;
31
- };
32
-
33
- // Mock the useManager hook to control state
34
- let mockState: MockState = { status: 'idle' };
35
- vi.mock('@/hooks', () => ({
36
- useManager: vi.fn((factory) => {
37
- factory(); // Call factory to create manager
38
- return [mockState, mockManager];
39
- }),
40
- }));
41
-
42
- describe('Email', () => {
43
- const defaultConfig = {
44
- otpVerification: true,
45
- otpExpirationInMinutes: 5,
46
- prefill: false,
47
- maxOtpAttempts: 3,
48
- };
49
-
50
- const defaultProps = {
51
- config: defaultConfig,
52
- onFinish: vi.fn(),
53
- onError: vi.fn(),
54
- };
55
-
56
- beforeEach(() => {
57
- vi.clearAllMocks();
58
- mockState = { status: 'idle' };
59
- });
60
-
61
- describe('Rendering states', () => {
62
- it('renders input page with loading button when status is idle', () => {
63
- mockState = { status: 'idle' };
64
- const { container } = render(<Email {...defaultProps} />);
65
-
66
- expect(container.querySelector('.IncodeEmailPage')).toBeTruthy();
67
- expect(screen.getByText('Verify Email')).toBeTruthy();
68
- expect(screen.getByTestId('email-input')).toBeTruthy();
69
- const button = screen.getByTestId('email-submit');
70
- expect(button.classList.contains('IncodeButtonLoading')).toBeTruthy();
71
- expect(button.hasAttribute('disabled')).toBeTruthy();
72
- });
73
-
74
- it('renders input page with loading button when status is loadingPrefill', () => {
75
- mockState = { status: 'loadingPrefill' };
76
- const { container } = render(<Email {...defaultProps} />);
77
-
78
- expect(container.querySelector('.IncodeEmailPage')).toBeTruthy();
79
- expect(screen.getByText('Verify Email')).toBeTruthy();
80
- expect(screen.getByTestId('email-input')).toBeTruthy();
81
- const button = screen.getByTestId('email-submit');
82
- expect(button.classList.contains('IncodeButtonLoading')).toBeTruthy();
83
- expect(button.hasAttribute('disabled')).toBeTruthy();
84
- });
85
-
86
- it('renders email input page when status is inputting', () => {
87
- mockState = { status: 'inputting' };
88
- render(<Email {...defaultProps} />);
89
-
90
- expect(screen.getByText('Verify Email')).toBeTruthy();
91
- expect(screen.getByTestId('email-input')).toBeTruthy();
92
- const button = screen.getByTestId('email-submit');
93
- expect(button.classList.contains('IncodeButtonLoading')).toBeFalsy();
94
- });
95
-
96
- it('renders input page with loading button when status is submitting', () => {
97
- mockState = { status: 'submitting' };
98
- const { container } = render(<Email {...defaultProps} />);
99
-
100
- expect(container.querySelector('.IncodeEmailPage')).toBeTruthy();
101
- expect(screen.getByTestId('email-input')).toBeTruthy();
102
- const button = screen.getByTestId('email-submit');
103
- expect(button.classList.contains('IncodeButtonLoading')).toBeTruthy();
104
- expect(button.hasAttribute('disabled')).toBeTruthy();
105
- });
106
-
107
- it('renders input page with loading button when status is sendingOtp', () => {
108
- mockState = { status: 'sendingOtp' };
109
- const { container } = render(<Email {...defaultProps} />);
110
-
111
- expect(container.querySelector('.IncodeEmailPage')).toBeTruthy();
112
- expect(screen.getByTestId('email-input')).toBeTruthy();
113
- const button = screen.getByTestId('email-submit');
114
- expect(button.classList.contains('IncodeButtonLoading')).toBeTruthy();
115
- expect(button.hasAttribute('disabled')).toBeTruthy();
116
- });
117
-
118
- it('renders OTP input page when status is awaitingOtp', () => {
119
- mockState = {
120
- status: 'awaitingOtp',
121
- resendTimer: 30,
122
- canResend: false,
123
- };
124
- render(<Email {...defaultProps} />);
125
-
126
- expect(screen.getByText('Enter Verification Code')).toBeTruthy();
127
- expect(screen.getByTestId('otp-submit')).toBeTruthy();
128
- });
129
-
130
- it('renders OTP input page when status is verifyingOtp', () => {
131
- mockState = { status: 'verifyingOtp' };
132
- render(<Email {...defaultProps} />);
133
-
134
- expect(screen.getByText('Enter Verification Code')).toBeTruthy();
135
- });
136
-
137
- it('renders OTP error state when status is otpError', () => {
138
- mockState = {
139
- status: 'otpError',
140
- error: 'Invalid code',
141
- };
142
- render(<Email {...defaultProps} />);
143
-
144
- expect(screen.getByText('Enter Verification Code')).toBeTruthy();
145
- expect(screen.getByTestId('otp-error')).toBeTruthy();
146
- expect(screen.getByText('Invalid code')).toBeTruthy();
147
- });
148
- });
149
-
150
- describe('Inputting state', () => {
151
- beforeEach(() => {
152
- mockState = { status: 'inputting' };
153
- });
154
-
155
- it('shows subtitle when OTP verification is enabled', () => {
156
- render(<Email {...defaultProps} />);
157
-
158
- expect(
159
- screen.getByText('We will send you a verification code'),
160
- ).toBeTruthy();
161
- });
162
-
163
- it('does not show subtitle when OTP verification is disabled', () => {
164
- const configNoOtp = { ...defaultConfig, otpVerification: false };
165
- render(<Email {...defaultProps} config={configNoOtp} />);
166
-
167
- expect(
168
- screen.queryByText('We will send you a verification code'),
169
- ).toBeNull();
170
- });
171
-
172
- it('shows prefilled email when available', () => {
173
- mockState = {
174
- status: 'inputting',
175
- prefilledEmail: 'prefilled@example.com',
176
- };
177
- render(<Email {...defaultProps} />);
178
-
179
- const input = screen.getByTestId('email-input') as HTMLInputElement;
180
- expect(input.value).toBe('prefilled@example.com');
181
- });
182
-
183
- it('shows email error when present', () => {
184
- mockState = {
185
- status: 'inputting',
186
- emailError: 'Email already exists',
187
- };
188
- render(<Email {...defaultProps} />);
189
-
190
- expect(screen.getByTestId('email-error')).toBeTruthy();
191
- expect(screen.getByText('Email already exists')).toBeTruthy();
192
- });
193
-
194
- it('continue button is disabled initially', () => {
195
- render(<Email {...defaultProps} />);
196
-
197
- const button = screen.getByTestId('email-submit');
198
- expect(button.hasAttribute('disabled')).toBe(true);
199
- });
200
-
201
- it('calls manager.setEmail when email changes', () => {
202
- render(<Email {...defaultProps} />);
203
-
204
- const input = screen.getByTestId('email-input');
205
- fireEvent.input(input, { target: { value: 'user@example.com' } });
206
-
207
- expect(mockManager.setEmail).toHaveBeenCalledWith(
208
- 'user@example.com',
209
- true,
210
- );
211
- });
212
-
213
- it('calls manager.submit when continue button is clicked', async () => {
214
- render(<Email {...defaultProps} />);
215
-
216
- // First enter a valid email to enable the button
217
- const input = screen.getByTestId('email-input');
218
- fireEvent.input(input, { target: { value: 'user@example.com' } });
219
-
220
- // Now we need to update the mock to reflect that email is valid
221
- // In the actual component, isEmailValid state is set
222
-
223
- // For this test, we need to verify the button click handler
224
- const button = screen.getByTestId('email-submit');
225
- fireEvent.click(button);
226
-
227
- // Note: Button may still be disabled because we're not fully simulating state
228
- // The important thing is we test the integration
229
- });
230
- });
231
-
232
- describe('OTP state', () => {
233
- beforeEach(() => {
234
- mockState = {
235
- status: 'awaitingOtp',
236
- resendTimer: 0,
237
- canResend: true,
238
- };
239
- });
240
-
241
- it('shows "change email address" as back link text', () => {
242
- render(<Email {...defaultProps} />);
243
-
244
- expect(screen.getByText('change email address')).toBeTruthy();
245
- });
246
-
247
- it('calls manager.submitOtp when OTP is submitted', () => {
248
- mockState = {
249
- status: 'awaitingOtp',
250
- resendTimer: 0,
251
- canResend: true,
252
- };
253
- render(<Email {...defaultProps} />);
254
-
255
- // Fill OTP inputs
256
- for (let i = 0; i < 6; i++) {
257
- const input = screen.getByTestId(`otp-input-${i}`) as HTMLInputElement;
258
- fireEvent.input(input, { target: { value: String(i) } });
259
- }
260
-
261
- const button = screen.getByTestId('otp-submit');
262
- fireEvent.click(button);
263
-
264
- expect(mockManager.submitOtp).toHaveBeenCalledWith('012345');
265
- });
266
-
267
- it('calls manager.resendOtp when resend is clicked', () => {
268
- mockState = {
269
- status: 'awaitingOtp',
270
- resendTimer: 0,
271
- canResend: true,
272
- };
273
- render(<Email {...defaultProps} />);
274
-
275
- const resendLink = screen.getByText('Resend code');
276
- fireEvent.click(resendLink);
277
-
278
- expect(mockManager.resendOtp).toHaveBeenCalled();
279
- });
280
-
281
- it('calls manager.back when change email is clicked', () => {
282
- mockState = {
283
- status: 'awaitingOtp',
284
- resendTimer: 0,
285
- canResend: true,
286
- };
287
- render(<Email {...defaultProps} />);
288
-
289
- const backLink = screen.getByText('change email address');
290
- fireEvent.click(backLink);
291
-
292
- expect(mockManager.back).toHaveBeenCalled();
293
- });
294
-
295
- it('shows timer when canResend is false', () => {
296
- mockState = {
297
- status: 'awaitingOtp',
298
- resendTimer: 30,
299
- canResend: false,
300
- };
301
- render(<Email {...defaultProps} />);
302
-
303
- expect(screen.getByTestId('otp-timer')).toBeTruthy();
304
- });
305
- });
306
-
307
- describe('Success state', () => {
308
- it('calls onFinish when status is success', () => {
309
- const onFinish = vi.fn();
310
- mockState = { status: 'success' };
311
-
312
- render(<Email {...defaultProps} onFinish={onFinish} />);
313
-
314
- expect(onFinish).toHaveBeenCalled();
315
- });
316
-
317
- it('renders nothing in success state', () => {
318
- mockState = { status: 'success' };
319
- const { container } = render(<Email {...defaultProps} />);
320
-
321
- expect(container.querySelector('.IncodeEmailPage')).toBeNull();
322
- });
323
- });
324
-
325
- describe('Error state', () => {
326
- it('calls onError when status is error', () => {
327
- const onError = vi.fn();
328
- mockState = { status: 'error', error: 'Something went wrong' };
329
-
330
- render(<Email {...defaultProps} onError={onError} />);
331
-
332
- expect(onError).toHaveBeenCalledWith('Something went wrong');
333
- });
334
-
335
- it('renders nothing in error state', () => {
336
- mockState = { status: 'error', error: 'Error' };
337
- const { container } = render(<Email {...defaultProps} />);
338
-
339
- expect(container.querySelector('.IncodeEmailPage')).toBeNull();
340
- });
341
- });
342
-
343
- describe('Config prop', () => {
344
- it('renders nothing when config is not provided', () => {
345
- // @ts-expect-error - Testing null config
346
- const { container } = render(<Email config={null} {...defaultProps} />);
347
-
348
- // Should not crash and should render wrapper
349
- expect(container.querySelector('.IncodeComponent')).toBeTruthy();
350
- });
351
- });
352
-
353
- describe('Component structure', () => {
354
- it('wraps content in IncodeComponent div', () => {
355
- mockState = { status: 'inputting' };
356
- const { container } = render(<Email {...defaultProps} />);
357
-
358
- expect(container.querySelector('.IncodeComponent')).toBeTruthy();
359
- });
360
-
361
- it('renders Page component with correct class', () => {
362
- mockState = { status: 'inputting' };
363
- const { container } = render(<Email {...defaultProps} />);
364
-
365
- expect(container.querySelector('.IncodeEmailPage')).toBeTruthy();
366
- });
367
- });
368
- });
@@ -1,255 +0,0 @@
1
- /**
2
- * @module @incodetech/ui/email
3
- *
4
- * Email verification UI component for the Incode Web SDK.
5
- * Provides a complete, ready-to-use email verification experience
6
- * with email input and OTP verification.
7
- *
8
- * ## UI Usage
9
- *
10
- * The Email component can be used as a React/Preact component or as a
11
- * Web Component (`<incode-email>`).
12
- *
13
- * @example React/Preact component usage
14
- * ```tsx
15
- * import { Email } from '@incodetech/ui/email';
16
- * import { setup } from '@incodetech/core';
17
- *
18
- * // Configure the SDK first
19
- * setup({ apiURL: 'https://api.example.com', token: 'your-token' });
20
- *
21
- * function App() {
22
- * const config = {
23
- * otpVerification: true,
24
- * otpExpirationInMinutes: 5,
25
- * prefill: false,
26
- * };
27
- *
28
- * return (
29
- * <Email
30
- * config={config}
31
- * onFinish={() => console.log('Email verified!')}
32
- * onError={(error) => console.error('Error:', error)}
33
- * />
34
- * );
35
- * }
36
- * ```
37
- *
38
- * @example Web Component usage
39
- * ```html
40
- * <!-- Include the script -->
41
- * <script type="module">
42
- * import '@incodetech/ui/email';
43
- * import { setup } from '@incodetech/core';
44
- *
45
- * setup({ apiURL: 'https://api.example.com', token: 'your-token' });
46
- *
47
- * const email = document.querySelector('incode-email');
48
- * email.config = {
49
- * otpVerification: true,
50
- * otpExpirationInMinutes: 5,
51
- * prefill: false,
52
- * };
53
- * email.onFinish = () => console.log('Email verified!');
54
- * email.onError = (error) => console.error('Error:', error);
55
- * </script>
56
- *
57
- * <incode-email></incode-email>
58
- * ```
59
- *
60
- * ## Styling
61
- *
62
- * The component uses CSS custom properties (variables) for theming.
63
- * Override these variables to customize the appearance:
64
- *
65
- * ```css
66
- * :root {
67
- * --button-primary-surface-default: #0066cc;
68
- * --input-border-default: #cccccc;
69
- * --text-title: #333333;
70
- * }
71
- * ```
72
- *
73
- * ## Headless Alternative
74
- *
75
- * For complete control over the UI, use the headless `createEmailManager`
76
- * from `@incodetech/core/email` instead. See the core module documentation.
77
- */
78
- import './styles.css';
79
- import { createEmailManager, type EmailConfig } from '@incodetech/core/email';
80
- import type { FC } from 'preact/compat';
81
- import { useEffect, useState } from 'preact/hooks';
82
- import { useManager } from '@/hooks';
83
- import { Button } from '../shared/button/button';
84
- import { IncodeComponent } from '../shared/componentRoot/incodeComponent';
85
- import { OtpInput } from '../shared/otpInput/otpInput';
86
- import { Page } from '../shared/page/page';
87
- import { Spacer } from '../shared/spacer/spacer';
88
- import {
89
- type IncodeModuleProps,
90
- registerIncodeModuleElement,
91
- } from '../shared/webComponent/incodeModule';
92
- import { EmailInput } from './emailInput';
93
-
94
- /** @internal */
95
- type EmailContentProps = {
96
- config: EmailConfig;
97
- onFinish?: () => void;
98
- onError?: (error: string | undefined) => void;
99
- };
100
-
101
- const EmailContent: FC<EmailContentProps> = ({ config, onFinish, onError }) => {
102
- const [state, manager] = useManager(() => {
103
- if (!config) {
104
- throw new Error('Email config is required');
105
- }
106
- return createEmailManager({ config });
107
- });
108
- const [isEmailValid, setIsEmailValid] = useState(false);
109
-
110
- useEffect(() => {
111
- if (state.status === 'idle' && manager.load) {
112
- try {
113
- manager.load();
114
- } catch (error) {
115
- onError?.(
116
- error instanceof Error
117
- ? error.message
118
- : 'Failed to initialize email verification',
119
- );
120
- }
121
- }
122
- // eslint-disable-next-line react-hooks/exhaustive-deps
123
- }, []);
124
-
125
- // Handle input states: idle, loadingPrefill, inputting, submitting, sendingOtp
126
- const isInputState =
127
- state.status === 'idle' ||
128
- state.status === 'loadingPrefill' ||
129
- state.status === 'inputting' ||
130
- state.status === 'submitting' ||
131
- state.status === 'sendingOtp';
132
-
133
- if (isInputState) {
134
- const isLoading =
135
- state.status === 'idle' ||
136
- state.status === 'loadingPrefill' ||
137
- state.status === 'submitting' ||
138
- state.status === 'sendingOtp';
139
-
140
- const prefilledEmail =
141
- state.status === 'inputting' ? state.prefilledEmail : undefined;
142
- const emailError =
143
- state.status === 'inputting' ? state.emailError : undefined;
144
-
145
- return (
146
- <Page
147
- className="IncodeEmailPage"
148
- title="Verify Email"
149
- subtitle={
150
- config.otpVerification
151
- ? 'We will send you a verification code'
152
- : undefined
153
- }
154
- >
155
- <EmailInput
156
- prefilledEmail={prefilledEmail}
157
- emailError={emailError}
158
- disabled={isLoading}
159
- onEmailChange={(email, isValid) => {
160
- manager.setEmail(email, isValid);
161
- setIsEmailValid(isValid);
162
- }}
163
- />
164
- <Spacer />
165
- <Button
166
- onClick={() => manager.submit()}
167
- disabled={!isEmailValid}
168
- isLoading={isLoading}
169
- data-testid="email-submit"
170
- >
171
- Continue
172
- </Button>
173
- </Page>
174
- );
175
- }
176
-
177
- if (
178
- state.status === 'awaitingOtp' ||
179
- state.status === 'verifyingOtp' ||
180
- state.status === 'otpError'
181
- ) {
182
- const isVerifying = state.status === 'verifyingOtp';
183
-
184
- return (
185
- <Page
186
- className="IncodeEmailPage IncodeEmailOtpPage"
187
- title="Enter Verification Code"
188
- >
189
- <OtpInput
190
- resendTimer={state.status === 'awaitingOtp' ? state.resendTimer : 0}
191
- canResend={state.status === 'awaitingOtp' ? state.canResend : false}
192
- error={state.status === 'otpError' ? state.error : undefined}
193
- onSubmit={(code) => manager.submitOtp(code)}
194
- onResend={() => manager.resendOtp()}
195
- onBack={() => manager.back()}
196
- backLinkText="change email address"
197
- isLoading={isVerifying}
198
- />
199
- </Page>
200
- );
201
- }
202
-
203
- if (state.status === 'success') {
204
- onFinish?.();
205
- return null;
206
- }
207
-
208
- if (state.status === 'error') {
209
- onError?.(state.error);
210
- return null;
211
- }
212
-
213
- return null;
214
- };
215
-
216
- /**
217
- * Props for the Email component
218
- */
219
- type EmailProps = IncodeModuleProps<EmailConfig>;
220
-
221
- /**
222
- * Email verification UI component.
223
- *
224
- * Provides a complete email verification experience including:
225
- * - Email address input with validation
226
- * - OTP code entry with resend functionality
227
- * - Loading states and error handling
228
- *
229
- * @example Basic usage
230
- * ```tsx
231
- * <Email
232
- * config={{
233
- * otpVerification: true,
234
- * otpExpirationInMinutes: 5,
235
- * prefill: false,
236
- * }}
237
- * onFinish={() => router.push('/next-step')}
238
- * onError={(err) => toast.error(err)}
239
- * />
240
- * ```
241
- *
242
- * @see {@link createEmailManager} for headless usage
243
- */
244
- export const Email: FC<EmailProps> = ({ config, onFinish, onError }) => {
245
- return (
246
- <IncodeComponent>
247
- {config ? (
248
- <EmailContent config={config} onFinish={onFinish} onError={onError} />
249
- ) : null}
250
- </IncodeComponent>
251
- );
252
- };
253
-
254
- // Register as a Web Component
255
- registerIncodeModuleElement(Email, 'incode-email');