astra-sdk-web 1.1.8 → 1.1.9

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.
package/dist/index.d.ts CHANGED
@@ -76,10 +76,6 @@ declare class ApiClient {
76
76
  getConfig(): Required<AstraSDKConfig>;
77
77
  }
78
78
 
79
- /**
80
- * KYC API Service
81
- * Handles all KYC-related API calls (face scan, document upload, status check)
82
- */
83
79
  interface KycApiConfig {
84
80
  apiBaseUrl: string;
85
81
  sessionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astra-sdk-web",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Official Astra SDK for JavaScript/TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/astra-sdk.cjs.js",
@@ -78,8 +78,8 @@ export function useFaceScan(
78
78
  const handleFaceCapture = useCallback(async () => {
79
79
  if (!videoRef.current) return;
80
80
 
81
- // Check if face is straight before capturing
82
- const centerThreshold = 0.05;
81
+ // Check if face is straight before capturing (reduced threshold, no center check)
82
+ const reducedThreshold = 0.08; // More lenient threshold - only check if face is straight
83
83
  const currentAbsYaw = livenessStateRef.current.currentAbsYaw;
84
84
 
85
85
  if (currentAbsYaw === null || currentAbsYaw === undefined) {
@@ -90,7 +90,7 @@ export function useFaceScan(
90
90
  return;
91
91
  }
92
92
 
93
- if (currentAbsYaw >= centerThreshold) {
93
+ if (currentAbsYaw >= reducedThreshold) {
94
94
  setState(prev => ({
95
95
  ...prev,
96
96
  livenessInstruction: "Please look straight at the camera before capturing",
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
2
2
  import { useNavigate } from 'react-router-dom';
3
3
  import { useDocumentUpload } from '../features/documentUpload/hooks/useDocumentUpload';
4
4
  import { useKycContext } from '../contexts/KycContext';
5
+ import { COMPLETED_STEPS } from '../services/kycApiService';
5
6
  import type { DocumentType } from '../features/documentUpload/types';
6
7
 
7
8
  interface DocumentUploadModalProps {
@@ -47,7 +48,26 @@ function DocumentUploadModal({ onComplete }: DocumentUploadModalProps) {
47
48
  if (!apiService) return;
48
49
 
49
50
  try {
50
- await apiService.checkSessionActive();
51
+ const statusResponse = await apiService.getSessionStatus();
52
+ const { completed_steps, next_step, status } = statusResponse.data;
53
+
54
+ // Check if session is active
55
+ if (status !== 'ACTIVE') {
56
+ throw new Error('Session expired or inactive');
57
+ }
58
+
59
+ // If document_upload is already completed, show completion message
60
+ if (completed_steps.includes(COMPLETED_STEPS.DOCS)) {
61
+ // Document already uploaded, could show completion or redirect
62
+ console.log('Document already uploaded');
63
+ }
64
+
65
+ // If next_step is not document_upload and face_scan is not completed, redirect to face scan
66
+ if (next_step === COMPLETED_STEPS.FACE && !completed_steps.includes(COMPLETED_STEPS.FACE)) {
67
+ // Should not happen if we're in document upload modal, but handle it
68
+ console.warn('Face scan not completed, but in document upload modal');
69
+ }
70
+
51
71
  setSessionError(null);
52
72
  } catch (error: any) {
53
73
  const message = error.message || 'Session expired or inactive';
@@ -5,6 +5,7 @@ import { useCamera } from '../features/faceScan/hooks/useCamera';
5
5
  import { useFaceScan } from '../features/faceScan/hooks/useFaceScan';
6
6
  import { useKycContext } from '../contexts/KycContext';
7
7
  import { Toast } from '../components/Toast';
8
+ import { COMPLETED_STEPS } from '../services/kycApiService';
8
9
  import '../index.css';
9
10
 
10
11
  interface FaceScanModalProps {
@@ -58,7 +59,28 @@ function FaceScanModal({ onComplete }: FaceScanModalProps) {
58
59
  if (!apiService) return;
59
60
 
60
61
  try {
61
- await apiService.checkSessionActive();
62
+ const statusResponse = await apiService.getSessionStatus();
63
+ const { completed_steps, next_step, status } = statusResponse.data;
64
+
65
+ // Check if session is active
66
+ if (status !== 'ACTIVE') {
67
+ throw new Error('Session expired or inactive');
68
+ }
69
+
70
+ // If face_scan is already completed, skip to document upload
71
+ if (completed_steps.includes(COMPLETED_STEPS.FACE)) {
72
+ setState(prev => ({ ...prev, showDocumentUpload: true }));
73
+ return;
74
+ }
75
+
76
+ // If next_step is not face_scan, redirect accordingly
77
+ if (next_step !== COMPLETED_STEPS.FACE && next_step !== COMPLETED_STEPS.INITIATED) {
78
+ if (next_step === COMPLETED_STEPS.DOCS) {
79
+ setState(prev => ({ ...prev, showDocumentUpload: true }));
80
+ return;
81
+ }
82
+ }
83
+
62
84
  setSessionError(null);
63
85
  } catch (error: any) {
64
86
  const message = error.message || 'Session expired or inactive';
@@ -70,7 +92,7 @@ function FaceScanModal({ onComplete }: FaceScanModalProps) {
70
92
  };
71
93
 
72
94
  checkSession();
73
- }, [apiService, navigate]);
95
+ }, [apiService, navigate, setState]);
74
96
 
75
97
  useEffect(() => {
76
98
  setState(prev => ({ ...prev, cameraReady }));
@@ -265,8 +265,10 @@ export class FaceMeshService {
265
265
  }
266
266
  }
267
267
  } else if (state.stage === "DONE") {
268
- // In DONE stage, wait for face to be straight before capturing
269
- if (absYaw < centerThreshold && insideGuide) {
268
+ // In DONE stage, wait for face to be straight before capturing (no center check needed)
269
+ // Reduced threshold for easier capture when face is straight
270
+ const reducedThreshold = 0.08; // More lenient threshold
271
+ if (absYaw < reducedThreshold) {
270
272
  state.centerHold += 1;
271
273
  if (state.centerHold >= holdFramesCenter && !state.snapTriggered) {
272
274
  state.snapTriggered = true;
@@ -280,11 +282,7 @@ export class FaceMeshService {
280
282
  } else {
281
283
  state.centerHold = 0;
282
284
  if (this.callbacks.onLivenessUpdate) {
283
- if (!insideGuide) {
284
- this.callbacks.onLivenessUpdate(state.stage, "Center your face inside the circle");
285
- } else {
286
- this.callbacks.onLivenessUpdate(state.stage, "Please look straight at the camera");
287
- }
285
+ this.callbacks.onLivenessUpdate(state.stage, "Please look straight at the camera");
288
286
  }
289
287
  }
290
288
  }
@@ -3,6 +3,13 @@
3
3
  * Handles all KYC-related API calls (face scan, document upload, status check)
4
4
  */
5
5
 
6
+ export const COMPLETED_STEPS = {
7
+ INITIATED: "initiated",
8
+ FACE: "face_scan",
9
+ DOCS: "document_upload",
10
+ COMPLETED: "completed",
11
+ } as const;
12
+
6
13
  export interface KycApiConfig {
7
14
  apiBaseUrl: string;
8
15
  sessionId: string;