@incodetech/core 0.0.0-dev-20260325-72e1e24 → 0.0.0-dev-20260326-106dc21

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.
@@ -100,9 +100,13 @@ type PhoneInputtingState = {
100
100
  type PhoneSubmittingState = {
101
101
  status: 'submitting';
102
102
  };
103
- /** OTP is being sent to the phone number */
104
- type PhoneSendingOtpState = {
105
- status: 'sendingOtp';
103
+ /** OTP is being sent to the phone number on resend */
104
+ type PhoneResendingOtpState = {
105
+ status: 'resendingOtp';
106
+ };
107
+ /** OTP is being initialy sent to the phone number */
108
+ type PhoneSendingInitialOtp = {
109
+ status: 'sendingInitialOtp';
106
110
  };
107
111
  /**
108
112
  * Waiting for OTP code - use `submitOtp()`, `resendOtp()`, or `back()`
@@ -124,11 +128,15 @@ type PhoneVerifyingOtpState = {
124
128
  * OTP verification failed - user can retry with `submitOtp()`
125
129
  * @property error - Error message describing why verification failed
126
130
  * @property attemptsRemaining - Number of remaining attempts before lockout
131
+ * @property resendTimer - Seconds remaining on resend cooldown (same as awaiting OTP)
132
+ * @property canResend - Whether resend is allowed (cooldown finished)
127
133
  */
128
134
  type PhoneOtpErrorState = {
129
135
  status: 'otpError';
130
- error: string;
136
+ otpError: string;
131
137
  attemptsRemaining: number;
138
+ resendTimer: number;
139
+ canResend: boolean;
132
140
  };
133
141
  /** Phone verification completed successfully */
134
142
  type PhoneFinishedState = {
@@ -155,7 +163,7 @@ type PhoneErrorState = {
155
163
  * }
156
164
  * ```
157
165
  */
158
- type PhoneState = PhoneIdleState | PhoneLoadingPrefillState | PhoneInputtingState | PhoneSubmittingState | PhoneSendingOtpState | PhoneAwaitingOtpState | PhoneVerifyingOtpState | PhoneOtpErrorState | PhoneFinishedState | PhoneErrorState;
166
+ type PhoneState = PhoneIdleState | PhoneLoadingPrefillState | PhoneInputtingState | PhoneSubmittingState | PhoneResendingOtpState | PhoneSendingInitialOtp | PhoneAwaitingOtpState | PhoneVerifyingOtpState | PhoneOtpErrorState | PhoneFinishedState | PhoneErrorState;
159
167
  /**
160
168
  * Creates a phone verification manager for headless or UI-driven usage.
161
169
  *
@@ -152,7 +152,11 @@ const phoneMachine = setup({
152
152
  attemptsRemaining: context.config.maxOtpAttempts ?? 3,
153
153
  resendTimer: 0,
154
154
  resendTimerActive: false
155
- }))
155
+ })),
156
+ clearResendTimer: assign({
157
+ resendTimer: () => 0,
158
+ resendTimerActive: () => false
159
+ })
156
160
  },
157
161
  guards: {
158
162
  hasPrefill: ({ context }) => context.config.prefill,
@@ -224,7 +228,7 @@ const phoneMachine = setup({
224
228
  isInstantVerify: context.config.isInstantVerify ?? false
225
229
  }),
226
230
  onDone: [{
227
- target: "sendingOtp",
231
+ target: "sendingInitialOtp",
228
232
  guard: "hasOtpVerification"
229
233
  }, { target: "finished" }],
230
234
  onError: {
@@ -232,7 +236,16 @@ const phoneMachine = setup({
232
236
  actions: "setPhoneError"
233
237
  }
234
238
  } },
235
- sendingOtp: { invoke: {
239
+ sendingInitialOtp: { invoke: {
240
+ id: "sendOtp",
241
+ src: "sendOtp",
242
+ onDone: { target: "awaitingOtp" },
243
+ onError: {
244
+ target: "awaitingOtp",
245
+ actions: "setError"
246
+ }
247
+ } },
248
+ resendingOtp: { invoke: {
236
249
  id: "sendOtp",
237
250
  src: "sendOtp",
238
251
  onDone: { target: "awaitingOtp" },
@@ -252,7 +265,7 @@ const phoneMachine = setup({
252
265
  OTP_CHANGED: { actions: "setOtpCode" },
253
266
  VERIFY_OTP: { target: "verifyingOtp" },
254
267
  RESEND_OTP: {
255
- target: "sendingOtp",
268
+ target: "resendingOtp",
256
269
  guard: "canResend"
257
270
  },
258
271
  BACK: { target: "inputting" }
@@ -289,17 +302,20 @@ const phoneMachine = setup({
289
302
  actions: "setError"
290
303
  }]
291
304
  } },
292
- otpError: { on: {
293
- OTP_CHANGED: {
294
- target: "awaitingOtp",
295
- actions: "setOtpCode"
296
- },
297
- RESEND_OTP: {
298
- target: "sendingOtp",
299
- guard: "canResend"
300
- },
301
- BACK: { target: "inputting" }
302
- } },
305
+ otpError: {
306
+ entry: "clearResendTimer",
307
+ on: {
308
+ OTP_CHANGED: {
309
+ target: "awaitingOtp",
310
+ actions: "setOtpCode"
311
+ },
312
+ RESEND_OTP: {
313
+ target: "resendingOtp",
314
+ guard: "canResend"
315
+ },
316
+ BACK: { target: "inputting" }
317
+ }
318
+ },
303
319
  finished: { type: "final" },
304
320
  error: { on: { RESET: {
305
321
  target: "idle",
@@ -423,7 +439,8 @@ function mapState(snapshot) {
423
439
  phoneError: context.phoneError
424
440
  };
425
441
  if (typedSnapshot.matches("submitting")) return { status: "submitting" };
426
- if (typedSnapshot.matches("sendingOtp")) return { status: "sendingOtp" };
442
+ if (typedSnapshot.matches("resendingOtp")) return { status: "resendingOtp" };
443
+ if (typedSnapshot.matches("sendingInitialOtp")) return { status: "sendingInitialOtp" };
427
444
  if (typedSnapshot.matches("awaitingOtp")) return {
428
445
  status: "awaitingOtp",
429
446
  resendTimer: context.resendTimer,
@@ -433,8 +450,10 @@ function mapState(snapshot) {
433
450
  if (typedSnapshot.matches("verifyingOtp")) return { status: "verifyingOtp" };
434
451
  if (typedSnapshot.matches("otpError")) return {
435
452
  status: "otpError",
436
- error: context.otpError ?? "otp.errorv2",
437
- attemptsRemaining: context.attemptsRemaining
453
+ otpError: context.otpError ?? "otp.errorv2",
454
+ attemptsRemaining: context.attemptsRemaining,
455
+ resendTimer: context.resendTimer,
456
+ canResend: !context.resendTimerActive
438
457
  };
439
458
  if (typedSnapshot.matches("finished")) return { status: "finished" };
440
459
  if (typedSnapshot.matches("error")) return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@incodetech/core",
3
- "version": "0.0.0-dev-20260325-72e1e24",
3
+ "version": "0.0.0-dev-20260326-106dc21",
4
4
  "type": "module",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",