@incodetech/core 2.0.0-alpha.1 → 2.0.0-alpha.10

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 (106) hide show
  1. package/dist/Manager-BGfxEmyv.d.ts +19 -0
  2. package/dist/OpenViduLogger-BdPfiZO6.esm.js +3 -0
  3. package/dist/OpenViduLogger-CQyDxBvM.esm.js +803 -0
  4. package/dist/StateMachine-DRE1oH2B.d.ts +2 -0
  5. package/dist/addEvent-W0ORK0jT.esm.js +16 -0
  6. package/dist/chunk-C_Yo44FK.esm.js +49 -0
  7. package/dist/email.d.ts +264 -0
  8. package/dist/email.esm.js +479 -0
  9. package/dist/endpoints-BSTFaHYo.esm.js +1706 -0
  10. package/dist/flow.d.ts +578 -0
  11. package/dist/flow.esm.js +628 -0
  12. package/dist/index.d.ts +226 -0
  13. package/dist/index.esm.js +155 -0
  14. package/dist/lib-Bu9XGMBW.esm.js +11700 -0
  15. package/dist/permissionServices-I6vX6DBy.esm.js +72 -0
  16. package/dist/phone.d.ts +292 -0
  17. package/dist/phone.esm.js +550 -0
  18. package/dist/selfie.d.ts +759 -0
  19. package/dist/selfie.esm.js +995 -0
  20. package/dist/types-iZi2rawo.d.ts +5 -0
  21. package/dist/warmup-CEJTfxQr.d.ts +55 -0
  22. package/dist/xstate.esm-B_rda9yU.esm.js +3261 -0
  23. package/package.json +14 -11
  24. package/src/camera/cameraActor.ts +0 -21
  25. package/src/camera/cameraService.test.ts +0 -437
  26. package/src/camera/cameraService.ts +0 -165
  27. package/src/camera/cameraServices.test.ts +0 -66
  28. package/src/camera/cameraServices.ts +0 -26
  29. package/src/camera/cameraStateMachine.test.ts +0 -602
  30. package/src/camera/cameraStateMachine.ts +0 -264
  31. package/src/camera/index.ts +0 -5
  32. package/src/camera/types.ts +0 -17
  33. package/src/device/getBrowser.ts +0 -31
  34. package/src/device/getDeviceClass.ts +0 -29
  35. package/src/device/index.ts +0 -2
  36. package/src/email/__mocks__/emailMocks.ts +0 -59
  37. package/src/email/emailActor.ts +0 -15
  38. package/src/email/emailManager.test.ts +0 -573
  39. package/src/email/emailManager.ts +0 -427
  40. package/src/email/emailServices.ts +0 -66
  41. package/src/email/emailStateMachine.test.ts +0 -741
  42. package/src/email/emailStateMachine.ts +0 -367
  43. package/src/email/index.ts +0 -39
  44. package/src/email/types.ts +0 -60
  45. package/src/events/addEvent.ts +0 -20
  46. package/src/events/types.ts +0 -7
  47. package/src/flow/__mocks__/flowMocks.ts +0 -84
  48. package/src/flow/flowActor.ts +0 -13
  49. package/src/flow/flowAnalyzer.test.ts +0 -266
  50. package/src/flow/flowAnalyzer.ts +0 -37
  51. package/src/flow/flowCompletionService.ts +0 -21
  52. package/src/flow/flowManager.test.ts +0 -560
  53. package/src/flow/flowManager.ts +0 -235
  54. package/src/flow/flowServices.test.ts +0 -109
  55. package/src/flow/flowServices.ts +0 -13
  56. package/src/flow/flowStateMachine.test.ts +0 -334
  57. package/src/flow/flowStateMachine.ts +0 -182
  58. package/src/flow/index.ts +0 -21
  59. package/src/flow/moduleLoader.test.ts +0 -136
  60. package/src/flow/moduleLoader.ts +0 -73
  61. package/src/flow/orchestratedFlowManager.test.ts +0 -240
  62. package/src/flow/orchestratedFlowManager.ts +0 -231
  63. package/src/flow/orchestratedFlowStateMachine.test.ts +0 -199
  64. package/src/flow/orchestratedFlowStateMachine.ts +0 -325
  65. package/src/flow/types.ts +0 -434
  66. package/src/http/__mocks__/api.ts +0 -88
  67. package/src/http/api.test.ts +0 -231
  68. package/src/http/api.ts +0 -90
  69. package/src/http/endpoints.ts +0 -17
  70. package/src/index.ts +0 -33
  71. package/src/permissions/index.ts +0 -2
  72. package/src/permissions/permissionServices.ts +0 -31
  73. package/src/permissions/types.ts +0 -3
  74. package/src/phone/__mocks__/phoneMocks.ts +0 -71
  75. package/src/phone/index.ts +0 -39
  76. package/src/phone/phoneActor.ts +0 -15
  77. package/src/phone/phoneManager.test.ts +0 -393
  78. package/src/phone/phoneManager.ts +0 -458
  79. package/src/phone/phoneServices.ts +0 -98
  80. package/src/phone/phoneStateMachine.test.ts +0 -918
  81. package/src/phone/phoneStateMachine.ts +0 -422
  82. package/src/phone/types.ts +0 -83
  83. package/src/recordings/recordingsRepository.test.ts +0 -87
  84. package/src/recordings/recordingsRepository.ts +0 -48
  85. package/src/recordings/streamingEvents.ts +0 -10
  86. package/src/selfie/__mocks__/selfieMocks.ts +0 -26
  87. package/src/selfie/index.ts +0 -14
  88. package/src/selfie/selfieActor.ts +0 -17
  89. package/src/selfie/selfieErrorUtils.test.ts +0 -116
  90. package/src/selfie/selfieErrorUtils.ts +0 -66
  91. package/src/selfie/selfieManager.test.ts +0 -297
  92. package/src/selfie/selfieManager.ts +0 -301
  93. package/src/selfie/selfieServices.ts +0 -362
  94. package/src/selfie/selfieStateMachine.test.ts +0 -283
  95. package/src/selfie/selfieStateMachine.ts +0 -804
  96. package/src/selfie/selfieUploadService.test.ts +0 -90
  97. package/src/selfie/selfieUploadService.ts +0 -81
  98. package/src/selfie/types.ts +0 -103
  99. package/src/session/index.ts +0 -5
  100. package/src/session/sessionService.ts +0 -78
  101. package/src/setup.test.ts +0 -61
  102. package/src/setup.ts +0 -171
  103. package/tsconfig.json +0 -13
  104. package/tsdown.config.ts +0 -22
  105. package/vitest.config.ts +0 -37
  106. package/vitest.setup.ts +0 -135
@@ -0,0 +1,550 @@
1
+ import { g as createManager, n as api, t as endpoints } from "./endpoints-BSTFaHYo.esm.js";
2
+ import { a as createActor, i as fromPromise, n as assign, r as fromCallback, t as setup } from "./xstate.esm-B_rda9yU.esm.js";
3
+ import { t as addEvent } from "./addEvent-W0ORK0jT.esm.js";
4
+
5
+ //#region src/modules/phone/phoneServices.ts
6
+ async function fetchPhone(signal) {
7
+ const res = await api.get(endpoints.getPhone, { signal });
8
+ if (!res.ok) throw new Error(`GET ${endpoints.getPhone} failed: ${res.status} ${res.statusText}`);
9
+ return res.data;
10
+ }
11
+ async function fetchStartInfo(signal) {
12
+ const res = await api.get(endpoints.startInfo, { signal });
13
+ if (!res.ok) throw new Error(`GET ${endpoints.startInfo} failed: ${res.status} ${res.statusText}`);
14
+ return res.data;
15
+ }
16
+ async function addPhone(params, signal) {
17
+ const res = await api.post(endpoints.phone, {
18
+ phone: params.phone,
19
+ optInGranted: params.optInGranted
20
+ }, { signal });
21
+ if (!res.ok) throw new Error(`POST ${endpoints.phone} failed: ${res.status} ${res.statusText}`);
22
+ return res.data;
23
+ }
24
+ async function addPhoneInstantVerify(params, signal) {
25
+ const res = await api.post(endpoints.phoneInstant, {
26
+ phone: params.phone,
27
+ optInGranted: params.optInGranted
28
+ }, { signal });
29
+ if (!res.ok) throw new Error(`POST ${endpoints.phoneInstant} failed: ${res.status} ${res.statusText}`);
30
+ return res.data;
31
+ }
32
+ async function sendOtp(signal) {
33
+ const res = await api.get(`${endpoints.sendSmsOtp}?communicationchannel=SMS`, { signal });
34
+ if (!res.ok) throw new Error(`GET ${endpoints.sendSmsOtp} failed: ${res.status} ${res.statusText}`);
35
+ }
36
+ async function verifyOtp(code, signal) {
37
+ const res = await api.get(`${endpoints.compareOtp}?code=${code}&channel=SMS`, { signal });
38
+ if (!res.ok) throw new Error(`GET ${endpoints.compareOtp} failed: ${res.status} ${res.statusText}`);
39
+ return res.data;
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/modules/phone/phoneStateMachine.ts
44
+ const RESEND_TIMER_SECONDS = 30;
45
+ const phoneMachine = setup({
46
+ types: {
47
+ context: {},
48
+ events: {},
49
+ input: {}
50
+ },
51
+ actors: {
52
+ fetchPhone: fromPromise(async ({ signal }) => {
53
+ return fetchPhone(signal);
54
+ }),
55
+ fetchStartInfo: fromPromise(async ({ signal }) => {
56
+ return fetchStartInfo(signal);
57
+ }),
58
+ submitPhone: fromPromise(async ({ input, signal }) => {
59
+ if (input.isInstantVerify) return addPhoneInstantVerify({
60
+ phone: input.phone,
61
+ optInGranted: input.optInGranted
62
+ }, signal);
63
+ return addPhone({
64
+ phone: input.phone,
65
+ optInGranted: input.optInGranted
66
+ }, signal);
67
+ }),
68
+ sendOtp: fromPromise(async ({ signal }) => {
69
+ return sendOtp(signal);
70
+ }),
71
+ verifyOtp: fromPromise(async ({ input, signal }) => {
72
+ return verifyOtp(input.code, signal);
73
+ }),
74
+ resendTimer: fromCallback(({ sendBack }) => {
75
+ let seconds = RESEND_TIMER_SECONDS;
76
+ const interval = setInterval(() => {
77
+ seconds -= 1;
78
+ sendBack({ type: "TICK" });
79
+ if (seconds <= 0) clearInterval(interval);
80
+ }, 1e3);
81
+ return () => clearInterval(interval);
82
+ })
83
+ },
84
+ actions: {
85
+ setStartInfo: assign(({ event }) => {
86
+ const info = event.output;
87
+ return {
88
+ startInfo: info,
89
+ countryCode: info.ipIsoCode,
90
+ phonePrefix: info.phonePrefix
91
+ };
92
+ }),
93
+ setPrefilledPhone: assign(({ event }) => {
94
+ const phone = event.output.phone;
95
+ return {
96
+ prefilledPhone: phone,
97
+ phone
98
+ };
99
+ }),
100
+ setPhone: assign(({ event }) => {
101
+ const e = event;
102
+ return {
103
+ phone: e.phone,
104
+ isValid: e.isValid,
105
+ phoneError: e.isValid ? void 0 : "Invalid phone number"
106
+ };
107
+ }),
108
+ setPhoneError: assign(({ event }) => ({ phoneError: String(event.error) })),
109
+ setOptInGranted: assign(({ event }) => ({ optInGranted: event.granted })),
110
+ setError: assign(({ event }) => ({ error: String(event.error) })),
111
+ clearError: assign({ error: () => void 0 }),
112
+ clearPhoneError: assign({ phoneError: () => void 0 }),
113
+ setOtpCode: assign(({ event }) => ({
114
+ otpCode: event.code,
115
+ otpError: void 0
116
+ })),
117
+ setOtpError: assign(({ context, event }) => ({
118
+ otpError: String(event.error),
119
+ attemptsRemaining: context.attemptsRemaining - 1
120
+ })),
121
+ clearOtpError: assign({
122
+ otpError: () => void 0,
123
+ otpCode: () => ""
124
+ }),
125
+ startResendTimer: assign({
126
+ resendTimer: () => RESEND_TIMER_SECONDS,
127
+ resendTimerActive: () => true
128
+ }),
129
+ tickResendTimer: assign(({ context }) => {
130
+ const newTimer = Math.max(0, context.resendTimer - 1);
131
+ return {
132
+ resendTimer: newTimer,
133
+ resendTimerActive: newTimer > 0
134
+ };
135
+ }),
136
+ stopResendTimer: assign({ resendTimerActive: () => false }),
137
+ resetContext: assign(({ context }) => ({
138
+ config: context.config,
139
+ phone: "",
140
+ isValid: false,
141
+ phoneError: void 0,
142
+ countryCode: "",
143
+ phonePrefix: "",
144
+ prefilledPhone: void 0,
145
+ optInGranted: false,
146
+ startInfo: void 0,
147
+ error: void 0,
148
+ otpCode: "",
149
+ otpError: void 0,
150
+ attemptsRemaining: context.config.maxOtpAttempts ?? 3,
151
+ resendTimer: 0,
152
+ resendTimerActive: false
153
+ })),
154
+ sendPhoneSubmitEvent: () => {
155
+ addEvent({
156
+ code: "continue",
157
+ module: "phone",
158
+ screen: "phoneInput"
159
+ });
160
+ }
161
+ },
162
+ guards: {
163
+ hasPrefill: ({ context }) => context.config.prefill,
164
+ hasOtpVerification: ({ context }) => context.config.otpVerification,
165
+ isValidPhone: ({ context }) => context.isValid,
166
+ hasAttemptsRemaining: ({ context }) => context.attemptsRemaining > 0,
167
+ canResend: ({ context }) => !context.resendTimerActive
168
+ }
169
+ }).createMachine({
170
+ id: "phone",
171
+ initial: "idle",
172
+ context: ({ input }) => ({
173
+ config: input.config,
174
+ phone: "",
175
+ isValid: false,
176
+ phoneError: void 0,
177
+ countryCode: "",
178
+ phonePrefix: "",
179
+ prefilledPhone: void 0,
180
+ optInGranted: false,
181
+ startInfo: void 0,
182
+ error: void 0,
183
+ otpCode: "",
184
+ otpError: void 0,
185
+ attemptsRemaining: input.config.maxOtpAttempts ?? 3,
186
+ resendTimer: 0,
187
+ resendTimerActive: false
188
+ }),
189
+ states: {
190
+ idle: { on: { LOAD: [{
191
+ target: "loadingPrefill",
192
+ guard: "hasPrefill"
193
+ }, { target: "loadingStartInfo" }] } },
194
+ loadingPrefill: { invoke: {
195
+ id: "fetchPhone",
196
+ src: "fetchPhone",
197
+ onDone: {
198
+ target: "loadingStartInfo",
199
+ actions: "setPrefilledPhone"
200
+ },
201
+ onError: { target: "loadingStartInfo" }
202
+ } },
203
+ loadingStartInfo: { invoke: {
204
+ id: "fetchStartInfo",
205
+ src: "fetchStartInfo",
206
+ onDone: {
207
+ target: "inputting",
208
+ actions: "setStartInfo"
209
+ },
210
+ onError: { target: "inputting" }
211
+ } },
212
+ inputting: {
213
+ entry: "clearPhoneError",
214
+ on: {
215
+ PHONE_CHANGED: { actions: "setPhone" },
216
+ OPT_IN_CHANGED: { actions: "setOptInGranted" },
217
+ SUBMIT: {
218
+ target: "submitting",
219
+ guard: "isValidPhone"
220
+ }
221
+ }
222
+ },
223
+ submitting: { invoke: {
224
+ id: "submitPhone",
225
+ src: "submitPhone",
226
+ input: ({ context }) => ({
227
+ phone: context.phone,
228
+ optInGranted: context.config.optinEnabled ? context.optInGranted : void 0,
229
+ isInstantVerify: context.config.isInstantVerify ?? false
230
+ }),
231
+ onDone: [{
232
+ target: "sendingOtp",
233
+ guard: "hasOtpVerification",
234
+ actions: "sendPhoneSubmitEvent"
235
+ }, {
236
+ target: "success",
237
+ actions: "sendPhoneSubmitEvent"
238
+ }],
239
+ onError: {
240
+ target: "inputting",
241
+ actions: "setPhoneError"
242
+ }
243
+ } },
244
+ sendingOtp: { invoke: {
245
+ id: "sendOtp",
246
+ src: "sendOtp",
247
+ onDone: { target: "awaitingOtp" },
248
+ onError: {
249
+ target: "awaitingOtp",
250
+ actions: "setError"
251
+ }
252
+ } },
253
+ awaitingOtp: {
254
+ entry: "startResendTimer",
255
+ invoke: {
256
+ id: "resendTimer",
257
+ src: "resendTimer"
258
+ },
259
+ on: {
260
+ TICK: { actions: "tickResendTimer" },
261
+ OTP_CHANGED: { actions: "setOtpCode" },
262
+ VERIFY_OTP: { target: "verifyingOtp" },
263
+ RESEND_OTP: {
264
+ target: "sendingOtp",
265
+ guard: "canResend"
266
+ },
267
+ BACK: { target: "inputting" }
268
+ }
269
+ },
270
+ verifyingOtp: { invoke: {
271
+ id: "verifyOtp",
272
+ src: "verifyOtp",
273
+ input: ({ context }) => ({ code: context.otpCode }),
274
+ onDone: [
275
+ {
276
+ target: "success",
277
+ guard: ({ event }) => event.output.success === true
278
+ },
279
+ {
280
+ target: "otpError",
281
+ guard: "hasAttemptsRemaining",
282
+ actions: assign(({ context }) => ({
283
+ otpError: "Invalid OTP code",
284
+ attemptsRemaining: context.attemptsRemaining - 1
285
+ }))
286
+ },
287
+ {
288
+ target: "error",
289
+ actions: assign({ error: () => "Maximum OTP attempts exceeded" })
290
+ }
291
+ ],
292
+ onError: [{
293
+ target: "otpError",
294
+ guard: "hasAttemptsRemaining",
295
+ actions: "setOtpError"
296
+ }, {
297
+ target: "error",
298
+ actions: "setError"
299
+ }]
300
+ } },
301
+ otpError: { on: {
302
+ OTP_CHANGED: {
303
+ target: "awaitingOtp",
304
+ actions: "setOtpCode"
305
+ },
306
+ RESEND_OTP: {
307
+ target: "sendingOtp",
308
+ guard: "canResend"
309
+ },
310
+ BACK: { target: "inputting" }
311
+ } },
312
+ success: { type: "final" },
313
+ error: { on: { RESET: {
314
+ target: "idle",
315
+ actions: "resetContext"
316
+ } } }
317
+ }
318
+ });
319
+
320
+ //#endregion
321
+ //#region src/modules/phone/phoneActor.ts
322
+ function createPhoneActor(options) {
323
+ return createActor(phoneMachine, { input: { config: options.config } }).start();
324
+ }
325
+
326
+ //#endregion
327
+ //#region src/modules/phone/phoneManager.ts
328
+ /**
329
+ * @module @incodetech/core/phone
330
+ *
331
+ * Phone verification module for the Incode Web SDK.
332
+ * Supports both headless (programmatic) and UI-driven usage patterns.
333
+ *
334
+ * ## Headless Usage
335
+ *
336
+ * The phone manager can be used entirely without UI for backend integrations,
337
+ * custom UI implementations, or automated workflows.
338
+ *
339
+ * @example Basic headless phone verification with OTP
340
+ * ```typescript
341
+ * import { createPhoneManager } from '@incodetech/core/phone';
342
+ * import { setup } from '@incodetech/core';
343
+ *
344
+ * // 1. Configure the SDK (required before using any module)
345
+ * setup({ apiURL: 'https://api.example.com', token: 'your-token' });
346
+ *
347
+ * // 2. Create the phone manager
348
+ * const phoneManager = createPhoneManager({
349
+ * config: {
350
+ * otpVerification: true,
351
+ * otpExpirationInMinutes: 5,
352
+ * prefill: false,
353
+ * maxOtpAttempts: 3,
354
+ * },
355
+ * });
356
+ *
357
+ * // 3. Subscribe to state changes (optional but recommended)
358
+ * phoneManager.subscribe((state) => {
359
+ * console.log('Phone state:', state.status);
360
+ * if (state.status === 'success') {
361
+ * console.log('Phone verified successfully!');
362
+ * }
363
+ * if (state.status === 'error') {
364
+ * console.error('Error:', state.error);
365
+ * }
366
+ * });
367
+ *
368
+ * // 4. Start the flow
369
+ * phoneManager.load();
370
+ *
371
+ * // 5. When state is 'inputting', set the phone number
372
+ * phoneManager.setPhoneNumber('+14155551234', true);
373
+ *
374
+ * // 6. Submit the phone number
375
+ * phoneManager.submit();
376
+ *
377
+ * // 7. When state is 'awaitingOtp', submit the OTP code
378
+ * phoneManager.submitOtp('ABC123');
379
+ *
380
+ * // 8. Clean up when done
381
+ * phoneManager.stop();
382
+ * ```
383
+ *
384
+ * @example Polling-based headless usage
385
+ * ```typescript
386
+ * const phoneManager = createPhoneManager({ config });
387
+ *
388
+ * phoneManager.load();
389
+ *
390
+ * // Poll for state changes
391
+ * const interval = setInterval(() => {
392
+ * const state = phoneManager.getState();
393
+ *
394
+ * switch (state.status) {
395
+ * case 'inputting':
396
+ * phoneManager.setPhoneNumber('+14155551234', true);
397
+ * phoneManager.submit();
398
+ * break;
399
+ * case 'awaitingOtp':
400
+ * // Get OTP from user or external source
401
+ * phoneManager.submitOtp(otpCode);
402
+ * break;
403
+ * case 'success':
404
+ * clearInterval(interval);
405
+ * phoneManager.stop();
406
+ * break;
407
+ * case 'error':
408
+ * clearInterval(interval);
409
+ * console.error(state.error);
410
+ * phoneManager.stop();
411
+ * break;
412
+ * }
413
+ * }, 100);
414
+ * ```
415
+ */
416
+ function mapState(snapshot) {
417
+ const typedSnapshot = snapshot;
418
+ const { context } = typedSnapshot;
419
+ if (typedSnapshot.matches("idle")) return { status: "idle" };
420
+ if (typedSnapshot.matches("loadingPrefill")) return { status: "loadingPrefill" };
421
+ if (typedSnapshot.matches("loadingStartInfo")) return {
422
+ status: "inputting",
423
+ countryCode: context.countryCode,
424
+ phonePrefix: context.phonePrefix,
425
+ prefilledPhone: context.prefilledPhone
426
+ };
427
+ if (typedSnapshot.matches("inputting")) return {
428
+ status: "inputting",
429
+ countryCode: context.countryCode,
430
+ phonePrefix: context.phonePrefix,
431
+ prefilledPhone: context.prefilledPhone,
432
+ phoneError: context.phoneError
433
+ };
434
+ if (typedSnapshot.matches("submitting")) return { status: "submitting" };
435
+ if (typedSnapshot.matches("sendingOtp")) return { status: "sendingOtp" };
436
+ if (typedSnapshot.matches("awaitingOtp")) return {
437
+ status: "awaitingOtp",
438
+ resendTimer: context.resendTimer,
439
+ canResend: !context.resendTimerActive,
440
+ attemptsRemaining: context.attemptsRemaining
441
+ };
442
+ if (typedSnapshot.matches("verifyingOtp")) return { status: "verifyingOtp" };
443
+ if (typedSnapshot.matches("otpError")) return {
444
+ status: "otpError",
445
+ error: context.otpError ?? "Invalid OTP code",
446
+ attemptsRemaining: context.attemptsRemaining
447
+ };
448
+ if (typedSnapshot.matches("success")) return { status: "success" };
449
+ if (typedSnapshot.matches("error")) return {
450
+ status: "error",
451
+ error: context.error ?? "An error occurred"
452
+ };
453
+ return { status: "idle" };
454
+ }
455
+ function createApi({ actor }) {
456
+ return {
457
+ load() {
458
+ actor.send({ type: "LOAD" });
459
+ },
460
+ setPhoneNumber(phone, isValid) {
461
+ actor.send({
462
+ type: "PHONE_CHANGED",
463
+ phone,
464
+ isValid
465
+ });
466
+ },
467
+ setOptInGranted(granted) {
468
+ actor.send({
469
+ type: "OPT_IN_CHANGED",
470
+ granted
471
+ });
472
+ },
473
+ submit() {
474
+ actor.send({ type: "SUBMIT" });
475
+ },
476
+ setOtpCode(code) {
477
+ actor.send({
478
+ type: "OTP_CHANGED",
479
+ code
480
+ });
481
+ },
482
+ submitOtp(code) {
483
+ actor.send({
484
+ type: "OTP_CHANGED",
485
+ code
486
+ });
487
+ actor.send({ type: "VERIFY_OTP" });
488
+ },
489
+ resendOtp() {
490
+ actor.send({ type: "RESEND_OTP" });
491
+ },
492
+ back() {
493
+ actor.send({ type: "BACK" });
494
+ },
495
+ reset() {
496
+ actor.send({ type: "RESET" });
497
+ }
498
+ };
499
+ }
500
+ /**
501
+ * Creates a phone verification manager for headless or UI-driven usage.
502
+ *
503
+ * The manager provides a state machine-based API for phone number verification
504
+ * with optional OTP (one-time password) verification.
505
+ *
506
+ * @param options - Configuration options
507
+ * @param options.config - Phone verification configuration
508
+ * @param options.config.otpVerification - Whether to require OTP verification
509
+ * @param options.config.otpExpirationInMinutes - How long the OTP is valid
510
+ * @param options.config.prefill - Whether to fetch a pre-filled phone number
511
+ * @param options.config.isInstantVerify - Use instant verification API
512
+ * @param options.config.optinEnabled - Show marketing opt-in checkbox
513
+ * @param options.config.maxOtpAttempts - Maximum OTP verification attempts (default: 3)
514
+ *
515
+ * @returns Phone manager with state, API methods, and subscription
516
+ *
517
+ * @example Headless usage
518
+ * ```typescript
519
+ * const manager = createPhoneManager({
520
+ * config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false },
521
+ * });
522
+ *
523
+ * manager.subscribe((state) => console.log(state.status));
524
+ * manager.load();
525
+ * manager.setPhoneNumber('+14155551234', true);
526
+ * manager.submit();
527
+ * // ... wait for 'awaitingOtp' state ...
528
+ * manager.submitOtp('ABC123');
529
+ * manager.stop();
530
+ * ```
531
+ *
532
+ * @example With React/Preact UI hook
533
+ * ```tsx
534
+ * const [state, manager] = useManager(() => createPhoneManager({ config }));
535
+ *
536
+ * if (state.status === 'inputting') {
537
+ * return <input onChange={(e) => manager.setPhoneNumber(e.target.value, true)} />;
538
+ * }
539
+ * ```
540
+ */
541
+ function createPhoneManager(options) {
542
+ return createManager({
543
+ actor: createPhoneActor(options),
544
+ mapState,
545
+ createApi
546
+ });
547
+ }
548
+
549
+ //#endregion
550
+ export { createPhoneManager, phoneMachine };