@koraidv/react 1.8.1 → 1.8.3

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 (3) hide show
  1. package/dist/index.js +105 -20
  2. package/dist/index.mjs +105 -20
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -101,8 +101,10 @@ function useKoraIDV() {
101
101
  });
102
102
  const [selectedDocumentType, setSelectedDocumentType] = (0, import_react2.useState)(null);
103
103
  const [documentFrontCaptured, setDocumentFrontCaptured] = (0, import_react2.useState)(false);
104
+ const lastStartArgsRef = (0, import_react2.useRef)(null);
104
105
  const startVerification = (0, import_react2.useCallback)(
105
106
  async (externalId, tier = "standard", expectedFirstName, expectedLastName) => {
107
+ lastStartArgsRef.current = { externalId, tier, expectedFirstName, expectedLastName };
106
108
  setState((prev) => ({ ...prev, isLoading: true, error: null }));
107
109
  try {
108
110
  await sdk.startVerification(
@@ -363,14 +365,28 @@ function useKoraIDV() {
363
365
  error: null,
364
366
  lastChallengeError: null
365
367
  });
368
+ setSelectedDocumentType(null);
369
+ setDocumentFrontCaptured(false);
366
370
  }, [sdk]);
367
371
  const retry = (0, import_react2.useCallback)(() => {
368
- setState((prev) => ({
369
- ...prev,
372
+ const args = lastStartArgsRef.current;
373
+ sdk.reset();
374
+ setState({
375
+ step: "consent",
376
+ verification: null,
377
+ livenessSession: null,
378
+ currentChallenge: null,
379
+ completedChallenges: 0,
380
+ isLoading: false,
370
381
  error: null,
371
- isLoading: false
372
- }));
373
- }, []);
382
+ lastChallengeError: null
383
+ });
384
+ setSelectedDocumentType(null);
385
+ setDocumentFrontCaptured(false);
386
+ if (args) {
387
+ startVerification(args.externalId, args.tier, args.expectedFirstName, args.expectedLastName);
388
+ }
389
+ }, [sdk, startVerification]);
374
390
  return {
375
391
  state,
376
392
  startVerification,
@@ -3093,11 +3109,28 @@ function ResultScreen({ verification, onDone, onRetry, resultPageMode, simplifie
3093
3109
  case "approved":
3094
3110
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SimplifiedSuccess, { onDone, customMessages });
3095
3111
  case "rejected":
3096
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SimplifiedFailed, { onRetry: onRetry || onDone, customMessages });
3112
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3113
+ SimplifiedFailed,
3114
+ {
3115
+ verification,
3116
+ onRetry: onRetry || onDone,
3117
+ customMessages
3118
+ }
3119
+ );
3097
3120
  case "review_required":
3098
3121
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SimplifiedReview, { verification, onDone, customMessages });
3099
3122
  case "expired":
3100
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SimplifiedFailed, { onRetry: onRetry || onDone, customMessages: { failedTitle: "Document Expired", failedMessage: "The document you submitted has expired. Please use a valid document." } });
3123
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3124
+ SimplifiedFailed,
3125
+ {
3126
+ verification,
3127
+ onRetry: onRetry || onDone,
3128
+ customMessages: {
3129
+ failedTitle: "Document Expired",
3130
+ failedMessage: "The document you submitted has expired. Please use a valid document."
3131
+ }
3132
+ }
3133
+ );
3101
3134
  default:
3102
3135
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SimplifiedSuccess, { onDone, customMessages });
3103
3136
  }
@@ -3159,9 +3192,6 @@ function SuccessResult({ verification, onDone }) {
3159
3192
  ] });
3160
3193
  }
3161
3194
  function RejectedResult({ verification, onRetry }) {
3162
- const score = Math.round(
3163
- verification.scores?.overall ?? 100 - (verification.riskScore ?? 58)
3164
- );
3165
3195
  const metrics = computeScoreBreakdown(verification);
3166
3196
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: styles.resultContainer, children: [
3167
3197
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: styles.resultContent, children: [
@@ -3187,13 +3217,45 @@ function RejectedResult({ verification, onRetry }) {
3187
3217
  }
3188
3218
  ),
3189
3219
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h1", { style: styles.resultTitle, children: "Verification rejected" }),
3190
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { style: styles.resultSubtitle, children: "We could not verify your identity. Please try again with a valid document." }),
3191
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3192
- ScoreCard,
3220
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3221
+ "div",
3193
3222
  {
3194
- score,
3195
- badge: "REJECTED",
3196
- gradient: `linear-gradient(135deg, ${colors.error}, #B91C1C)`
3223
+ style: {
3224
+ margin: "16px 0",
3225
+ padding: "16px 20px",
3226
+ borderRadius: "12px",
3227
+ backgroundColor: `${colors.error}10`,
3228
+ border: `1px solid ${colors.error}40`
3229
+ },
3230
+ children: [
3231
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3232
+ "p",
3233
+ {
3234
+ style: {
3235
+ margin: 0,
3236
+ fontSize: "13px",
3237
+ fontWeight: 600,
3238
+ letterSpacing: "0.06em",
3239
+ textTransform: "uppercase",
3240
+ color: colors.error,
3241
+ marginBottom: 6
3242
+ },
3243
+ children: "Reason for rejection"
3244
+ }
3245
+ ),
3246
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3247
+ "p",
3248
+ {
3249
+ style: {
3250
+ margin: 0,
3251
+ fontSize: "15px",
3252
+ lineHeight: 1.45,
3253
+ color: colors.textPrimary
3254
+ },
3255
+ children: verification.decisionReason || verification.rejectionReason || "We could not verify your identity. Please try again with a valid document."
3256
+ }
3257
+ )
3258
+ ]
3197
3259
  }
3198
3260
  ),
3199
3261
  metrics.map((m, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ScoreMetricRow, { ...m }, i))
@@ -3227,7 +3289,7 @@ function ExpiredResult({ verification, onRetry }) {
3227
3289
  }
3228
3290
  ),
3229
3291
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h1", { style: styles.resultTitle, children: "Document expired" }),
3230
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { style: styles.resultSubtitle, children: "The document you submitted has expired. Please use a valid, non-expired document." }),
3292
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { style: styles.resultSubtitle, children: verification.decisionReason || verification.rejectionReason || "The document you submitted has expired. Please use a valid, non-expired document." }),
3231
3293
  verification.documentVerification && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: styles.expiryCard, children: [
3232
3294
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: styles.expiryRow, children: [
3233
3295
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { style: styles.expiryLabel, children: "Document type" }),
@@ -3336,7 +3398,13 @@ function SimplifiedSuccess({ onDone, customMessages }) {
3336
3398
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: styles.footer, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { style: styles.primaryButton, onClick: onDone, children: "Continue" }) })
3337
3399
  ] });
3338
3400
  }
3339
- function SimplifiedFailed({ onRetry, customMessages }) {
3401
+ function SimplifiedFailed({
3402
+ verification,
3403
+ onRetry,
3404
+ customMessages
3405
+ }) {
3406
+ const backendReason = verification?.decisionReason || verification?.rejectionReason || "";
3407
+ const message = customMessages?.failedMessage || backendReason || "We could not verify your identity. Please try again with a valid document.";
3340
3408
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: styles.resultContainer, children: [
3341
3409
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { style: { ...styles.resultContent, textAlign: "center" }, children: [
3342
3410
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
@@ -3366,7 +3434,19 @@ function SimplifiedFailed({ onRetry, customMessages }) {
3366
3434
  }
3367
3435
  ),
3368
3436
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h1", { style: { ...styles.resultTitle, fontSize: 24, marginTop: 16 }, children: customMessages?.failedTitle || "Verification Failed" }),
3369
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { style: { ...styles.resultSubtitle, fontSize: 16, maxWidth: 320, margin: "8px auto 0" }, children: customMessages?.failedMessage || "We could not verify your identity. Please try again with a valid document." })
3437
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3438
+ "p",
3439
+ {
3440
+ style: {
3441
+ ...styles.resultSubtitle,
3442
+ fontSize: 16,
3443
+ maxWidth: 380,
3444
+ margin: "8px auto 0",
3445
+ lineHeight: 1.45
3446
+ },
3447
+ children: message
3448
+ }
3449
+ )
3370
3450
  ] }),
3371
3451
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: styles.footer, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { style: styles.primaryButton, onClick: onRetry, children: "Try Again" }) })
3372
3452
  ] });
@@ -3658,7 +3738,12 @@ function VerificationFlow({
3658
3738
  {
3659
3739
  verification: state.verification,
3660
3740
  onDone: () => onComplete?.(state.verification),
3661
- onRetry: retry
3741
+ onRetry: () => {
3742
+ setFlowStep("consent");
3743
+ setSelectedCountry(null);
3744
+ setShowFlipInstruction(true);
3745
+ retry();
3746
+ }
3662
3747
  }
3663
3748
  )
3664
3749
  ] });
package/dist/index.mjs CHANGED
@@ -52,8 +52,10 @@ function useKoraIDV() {
52
52
  });
53
53
  const [selectedDocumentType, setSelectedDocumentType] = useState(null);
54
54
  const [documentFrontCaptured, setDocumentFrontCaptured] = useState(false);
55
+ const lastStartArgsRef = useRef(null);
55
56
  const startVerification = useCallback(
56
57
  async (externalId, tier = "standard", expectedFirstName, expectedLastName) => {
58
+ lastStartArgsRef.current = { externalId, tier, expectedFirstName, expectedLastName };
57
59
  setState((prev) => ({ ...prev, isLoading: true, error: null }));
58
60
  try {
59
61
  await sdk.startVerification(
@@ -314,14 +316,28 @@ function useKoraIDV() {
314
316
  error: null,
315
317
  lastChallengeError: null
316
318
  });
319
+ setSelectedDocumentType(null);
320
+ setDocumentFrontCaptured(false);
317
321
  }, [sdk]);
318
322
  const retry = useCallback(() => {
319
- setState((prev) => ({
320
- ...prev,
323
+ const args = lastStartArgsRef.current;
324
+ sdk.reset();
325
+ setState({
326
+ step: "consent",
327
+ verification: null,
328
+ livenessSession: null,
329
+ currentChallenge: null,
330
+ completedChallenges: 0,
331
+ isLoading: false,
321
332
  error: null,
322
- isLoading: false
323
- }));
324
- }, []);
333
+ lastChallengeError: null
334
+ });
335
+ setSelectedDocumentType(null);
336
+ setDocumentFrontCaptured(false);
337
+ if (args) {
338
+ startVerification(args.externalId, args.tier, args.expectedFirstName, args.expectedLastName);
339
+ }
340
+ }, [sdk, startVerification]);
325
341
  return {
326
342
  state,
327
343
  startVerification,
@@ -3044,11 +3060,28 @@ function ResultScreen({ verification, onDone, onRetry, resultPageMode, simplifie
3044
3060
  case "approved":
3045
3061
  return /* @__PURE__ */ jsx11(SimplifiedSuccess, { onDone, customMessages });
3046
3062
  case "rejected":
3047
- return /* @__PURE__ */ jsx11(SimplifiedFailed, { onRetry: onRetry || onDone, customMessages });
3063
+ return /* @__PURE__ */ jsx11(
3064
+ SimplifiedFailed,
3065
+ {
3066
+ verification,
3067
+ onRetry: onRetry || onDone,
3068
+ customMessages
3069
+ }
3070
+ );
3048
3071
  case "review_required":
3049
3072
  return /* @__PURE__ */ jsx11(SimplifiedReview, { verification, onDone, customMessages });
3050
3073
  case "expired":
3051
- return /* @__PURE__ */ jsx11(SimplifiedFailed, { onRetry: onRetry || onDone, customMessages: { failedTitle: "Document Expired", failedMessage: "The document you submitted has expired. Please use a valid document." } });
3074
+ return /* @__PURE__ */ jsx11(
3075
+ SimplifiedFailed,
3076
+ {
3077
+ verification,
3078
+ onRetry: onRetry || onDone,
3079
+ customMessages: {
3080
+ failedTitle: "Document Expired",
3081
+ failedMessage: "The document you submitted has expired. Please use a valid document."
3082
+ }
3083
+ }
3084
+ );
3052
3085
  default:
3053
3086
  return /* @__PURE__ */ jsx11(SimplifiedSuccess, { onDone, customMessages });
3054
3087
  }
@@ -3110,9 +3143,6 @@ function SuccessResult({ verification, onDone }) {
3110
3143
  ] });
3111
3144
  }
3112
3145
  function RejectedResult({ verification, onRetry }) {
3113
- const score = Math.round(
3114
- verification.scores?.overall ?? 100 - (verification.riskScore ?? 58)
3115
- );
3116
3146
  const metrics = computeScoreBreakdown(verification);
3117
3147
  return /* @__PURE__ */ jsxs10("div", { style: styles.resultContainer, children: [
3118
3148
  /* @__PURE__ */ jsxs10("div", { style: styles.resultContent, children: [
@@ -3138,13 +3168,45 @@ function RejectedResult({ verification, onRetry }) {
3138
3168
  }
3139
3169
  ),
3140
3170
  /* @__PURE__ */ jsx11("h1", { style: styles.resultTitle, children: "Verification rejected" }),
3141
- /* @__PURE__ */ jsx11("p", { style: styles.resultSubtitle, children: "We could not verify your identity. Please try again with a valid document." }),
3142
- /* @__PURE__ */ jsx11(
3143
- ScoreCard,
3171
+ /* @__PURE__ */ jsxs10(
3172
+ "div",
3144
3173
  {
3145
- score,
3146
- badge: "REJECTED",
3147
- gradient: `linear-gradient(135deg, ${colors.error}, #B91C1C)`
3174
+ style: {
3175
+ margin: "16px 0",
3176
+ padding: "16px 20px",
3177
+ borderRadius: "12px",
3178
+ backgroundColor: `${colors.error}10`,
3179
+ border: `1px solid ${colors.error}40`
3180
+ },
3181
+ children: [
3182
+ /* @__PURE__ */ jsx11(
3183
+ "p",
3184
+ {
3185
+ style: {
3186
+ margin: 0,
3187
+ fontSize: "13px",
3188
+ fontWeight: 600,
3189
+ letterSpacing: "0.06em",
3190
+ textTransform: "uppercase",
3191
+ color: colors.error,
3192
+ marginBottom: 6
3193
+ },
3194
+ children: "Reason for rejection"
3195
+ }
3196
+ ),
3197
+ /* @__PURE__ */ jsx11(
3198
+ "p",
3199
+ {
3200
+ style: {
3201
+ margin: 0,
3202
+ fontSize: "15px",
3203
+ lineHeight: 1.45,
3204
+ color: colors.textPrimary
3205
+ },
3206
+ children: verification.decisionReason || verification.rejectionReason || "We could not verify your identity. Please try again with a valid document."
3207
+ }
3208
+ )
3209
+ ]
3148
3210
  }
3149
3211
  ),
3150
3212
  metrics.map((m, i) => /* @__PURE__ */ jsx11(ScoreMetricRow, { ...m }, i))
@@ -3178,7 +3240,7 @@ function ExpiredResult({ verification, onRetry }) {
3178
3240
  }
3179
3241
  ),
3180
3242
  /* @__PURE__ */ jsx11("h1", { style: styles.resultTitle, children: "Document expired" }),
3181
- /* @__PURE__ */ jsx11("p", { style: styles.resultSubtitle, children: "The document you submitted has expired. Please use a valid, non-expired document." }),
3243
+ /* @__PURE__ */ jsx11("p", { style: styles.resultSubtitle, children: verification.decisionReason || verification.rejectionReason || "The document you submitted has expired. Please use a valid, non-expired document." }),
3182
3244
  verification.documentVerification && /* @__PURE__ */ jsxs10("div", { style: styles.expiryCard, children: [
3183
3245
  /* @__PURE__ */ jsxs10("div", { style: styles.expiryRow, children: [
3184
3246
  /* @__PURE__ */ jsx11("span", { style: styles.expiryLabel, children: "Document type" }),
@@ -3287,7 +3349,13 @@ function SimplifiedSuccess({ onDone, customMessages }) {
3287
3349
  /* @__PURE__ */ jsx11("div", { style: styles.footer, children: /* @__PURE__ */ jsx11("button", { style: styles.primaryButton, onClick: onDone, children: "Continue" }) })
3288
3350
  ] });
3289
3351
  }
3290
- function SimplifiedFailed({ onRetry, customMessages }) {
3352
+ function SimplifiedFailed({
3353
+ verification,
3354
+ onRetry,
3355
+ customMessages
3356
+ }) {
3357
+ const backendReason = verification?.decisionReason || verification?.rejectionReason || "";
3358
+ const message = customMessages?.failedMessage || backendReason || "We could not verify your identity. Please try again with a valid document.";
3291
3359
  return /* @__PURE__ */ jsxs10("div", { style: styles.resultContainer, children: [
3292
3360
  /* @__PURE__ */ jsxs10("div", { style: { ...styles.resultContent, textAlign: "center" }, children: [
3293
3361
  /* @__PURE__ */ jsx11(
@@ -3317,7 +3385,19 @@ function SimplifiedFailed({ onRetry, customMessages }) {
3317
3385
  }
3318
3386
  ),
3319
3387
  /* @__PURE__ */ jsx11("h1", { style: { ...styles.resultTitle, fontSize: 24, marginTop: 16 }, children: customMessages?.failedTitle || "Verification Failed" }),
3320
- /* @__PURE__ */ jsx11("p", { style: { ...styles.resultSubtitle, fontSize: 16, maxWidth: 320, margin: "8px auto 0" }, children: customMessages?.failedMessage || "We could not verify your identity. Please try again with a valid document." })
3388
+ /* @__PURE__ */ jsx11(
3389
+ "p",
3390
+ {
3391
+ style: {
3392
+ ...styles.resultSubtitle,
3393
+ fontSize: 16,
3394
+ maxWidth: 380,
3395
+ margin: "8px auto 0",
3396
+ lineHeight: 1.45
3397
+ },
3398
+ children: message
3399
+ }
3400
+ )
3321
3401
  ] }),
3322
3402
  /* @__PURE__ */ jsx11("div", { style: styles.footer, children: /* @__PURE__ */ jsx11("button", { style: styles.primaryButton, onClick: onRetry, children: "Try Again" }) })
3323
3403
  ] });
@@ -3609,7 +3689,12 @@ function VerificationFlow({
3609
3689
  {
3610
3690
  verification: state.verification,
3611
3691
  onDone: () => onComplete?.(state.verification),
3612
- onRetry: retry
3692
+ onRetry: () => {
3693
+ setFlowStep("consent");
3694
+ setSelectedCountry(null);
3695
+ setShowFlipInstruction(true);
3696
+ retry();
3697
+ }
3613
3698
  }
3614
3699
  )
3615
3700
  ] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koraidv/react",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "Kora IDV React Components for Identity Verification",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,7 +21,7 @@
21
21
  "test": "vitest run"
22
22
  },
23
23
  "dependencies": {
24
- "@koraidv/core": "^1.8.1"
24
+ "@koraidv/core": "^1.8.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "^18.2.0",