@kwik-id/sdk-react-native 0.0.0-stage → 0.1.0-alpha.1
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/LICENSE +22 -0
- package/README.md +312 -2
- package/app.plugin.js +40 -0
- package/lib/commonjs/api/api-client.js +213 -0
- package/lib/commonjs/api/api-client.js.map +1 -0
- package/lib/commonjs/api/api-error.js +29 -0
- package/lib/commonjs/api/api-error.js.map +1 -0
- package/lib/commonjs/api/index.js +33 -0
- package/lib/commonjs/api/index.js.map +1 -0
- package/lib/commonjs/api/upload.js +74 -0
- package/lib/commonjs/api/upload.js.map +1 -0
- package/lib/commonjs/camera/camera-view.js +227 -0
- package/lib/commonjs/camera/camera-view.js.map +1 -0
- package/lib/commonjs/camera/index.js +20 -0
- package/lib/commonjs/camera/index.js.map +1 -0
- package/lib/commonjs/camera/photo-capture.js +50 -0
- package/lib/commonjs/camera/photo-capture.js.map +1 -0
- package/lib/commonjs/crypto/fingerprint.js +43 -0
- package/lib/commonjs/crypto/fingerprint.js.map +1 -0
- package/lib/commonjs/crypto/hmac.js +150 -0
- package/lib/commonjs/crypto/hmac.js.map +1 -0
- package/lib/commonjs/crypto/index.js +39 -0
- package/lib/commonjs/crypto/index.js.map +1 -0
- package/lib/commonjs/crypto/session-manager.js +173 -0
- package/lib/commonjs/crypto/session-manager.js.map +1 -0
- package/lib/commonjs/i18n/en.js +297 -0
- package/lib/commonjs/i18n/en.js.map +1 -0
- package/lib/commonjs/i18n/fr.js +294 -0
- package/lib/commonjs/i18n/fr.js.map +1 -0
- package/lib/commonjs/i18n/index.js +34 -0
- package/lib/commonjs/i18n/index.js.map +1 -0
- package/lib/commonjs/i18n/locale.js +20 -0
- package/lib/commonjs/i18n/locale.js.map +1 -0
- package/lib/commonjs/i18n/translator.js +37 -0
- package/lib/commonjs/i18n/translator.js.map +1 -0
- package/lib/commonjs/index.js +187 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/lib/device-detector.js +34 -0
- package/lib/commonjs/lib/device-detector.js.map +1 -0
- package/lib/commonjs/lib/event-emitter.js +85 -0
- package/lib/commonjs/lib/event-emitter.js.map +1 -0
- package/lib/commonjs/lib/index.js +63 -0
- package/lib/commonjs/lib/index.js.map +1 -0
- package/lib/commonjs/lib/kwik-id-rn-sdk.js +156 -0
- package/lib/commonjs/lib/kwik-id-rn-sdk.js.map +1 -0
- package/lib/commonjs/lib/verification-machine.js +276 -0
- package/lib/commonjs/lib/verification-machine.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/events.js +6 -0
- package/lib/commonjs/types/events.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/ui/components/KwikIDVerificationModal.js +407 -0
- package/lib/commonjs/ui/components/KwikIDVerificationModal.js.map +1 -0
- package/lib/commonjs/ui/components/screens.js +338 -0
- package/lib/commonjs/ui/components/screens.js.map +1 -0
- package/lib/commonjs/ui/context/kwik-id-provider.js +52 -0
- package/lib/commonjs/ui/context/kwik-id-provider.js.map +1 -0
- package/lib/commonjs/ui/hooks/use-kwik-verification.js +77 -0
- package/lib/commonjs/ui/hooks/use-kwik-verification.js.map +1 -0
- package/lib/commonjs/ui/index.js +33 -0
- package/lib/commonjs/ui/index.js.map +1 -0
- package/lib/module/api/api-client.js +208 -0
- package/lib/module/api/api-client.js.map +1 -0
- package/lib/module/api/api-error.js +24 -0
- package/lib/module/api/api-error.js.map +1 -0
- package/lib/module/api/index.js +6 -0
- package/lib/module/api/index.js.map +1 -0
- package/lib/module/api/upload.js +68 -0
- package/lib/module/api/upload.js.map +1 -0
- package/lib/module/camera/camera-view.js +222 -0
- package/lib/module/camera/camera-view.js.map +1 -0
- package/lib/module/camera/index.js +5 -0
- package/lib/module/camera/index.js.map +1 -0
- package/lib/module/camera/photo-capture.js +45 -0
- package/lib/module/camera/photo-capture.js.map +1 -0
- package/lib/module/crypto/fingerprint.js +37 -0
- package/lib/module/crypto/fingerprint.js.map +1 -0
- package/lib/module/crypto/hmac.js +143 -0
- package/lib/module/crypto/hmac.js.map +1 -0
- package/lib/module/crypto/index.js +6 -0
- package/lib/module/crypto/index.js.map +1 -0
- package/lib/module/crypto/session-manager.js +169 -0
- package/lib/module/crypto/session-manager.js.map +1 -0
- package/lib/module/i18n/en.js +293 -0
- package/lib/module/i18n/en.js.map +1 -0
- package/lib/module/i18n/fr.js +290 -0
- package/lib/module/i18n/fr.js.map +1 -0
- package/lib/module/i18n/index.js +11 -0
- package/lib/module/i18n/index.js.map +1 -0
- package/lib/module/i18n/locale.js +15 -0
- package/lib/module/i18n/locale.js.map +1 -0
- package/lib/module/i18n/translator.js +34 -0
- package/lib/module/i18n/translator.js.map +1 -0
- package/lib/module/index.js +30 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/lib/device-detector.js +26 -0
- package/lib/module/lib/device-detector.js.map +1 -0
- package/lib/module/lib/event-emitter.js +80 -0
- package/lib/module/lib/event-emitter.js.map +1 -0
- package/lib/module/lib/index.js +6 -0
- package/lib/module/lib/index.js.map +1 -0
- package/lib/module/lib/kwik-id-rn-sdk.js +150 -0
- package/lib/module/lib/kwik-id-rn-sdk.js.map +1 -0
- package/lib/module/lib/verification-machine.js +268 -0
- package/lib/module/lib/verification-machine.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/events.js +4 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/ui/components/KwikIDVerificationModal.js +402 -0
- package/lib/module/ui/components/KwikIDVerificationModal.js.map +1 -0
- package/lib/module/ui/components/screens.js +328 -0
- package/lib/module/ui/components/screens.js.map +1 -0
- package/lib/module/ui/context/kwik-id-provider.js +46 -0
- package/lib/module/ui/context/kwik-id-provider.js.map +1 -0
- package/lib/module/ui/hooks/use-kwik-verification.js +72 -0
- package/lib/module/ui/hooks/use-kwik-verification.js.map +1 -0
- package/lib/module/ui/index.js +6 -0
- package/lib/module/ui/index.js.map +1 -0
- package/lib/typescript/commonjs/api/api-client.d.ts +82 -0
- package/lib/typescript/commonjs/api/api-client.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/api-error.d.ts +13 -0
- package/lib/typescript/commonjs/api/api-error.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/index.d.ts +6 -0
- package/lib/typescript/commonjs/api/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/upload.d.ts +19 -0
- package/lib/typescript/commonjs/api/upload.d.ts.map +1 -0
- package/lib/typescript/commonjs/camera/camera-view.d.ts +25 -0
- package/lib/typescript/commonjs/camera/camera-view.d.ts.map +1 -0
- package/lib/typescript/commonjs/camera/index.d.ts +5 -0
- package/lib/typescript/commonjs/camera/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/camera/photo-capture.d.ts +9 -0
- package/lib/typescript/commonjs/camera/photo-capture.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/fingerprint.d.ts +3 -0
- package/lib/typescript/commonjs/crypto/fingerprint.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/hmac.d.ts +18 -0
- package/lib/typescript/commonjs/crypto/hmac.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/index.d.ts +4 -0
- package/lib/typescript/commonjs/crypto/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/session-manager.d.ts +27 -0
- package/lib/typescript/commonjs/crypto/session-manager.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/en.d.ts +291 -0
- package/lib/typescript/commonjs/i18n/en.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/fr.d.ts +6 -0
- package/lib/typescript/commonjs/i18n/fr.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/index.d.ts +10 -0
- package/lib/typescript/commonjs/i18n/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/locale.d.ts +4 -0
- package/lib/typescript/commonjs/i18n/locale.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/translator.d.ts +15 -0
- package/lib/typescript/commonjs/i18n/translator.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +24 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/device-detector.d.ts +5 -0
- package/lib/typescript/commonjs/lib/device-detector.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/event-emitter.d.ts +19 -0
- package/lib/typescript/commonjs/lib/event-emitter.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/index.d.ts +5 -0
- package/lib/typescript/commonjs/lib/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts +43 -0
- package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/verification-machine.d.ts +78 -0
- package/lib/typescript/commonjs/lib/verification-machine.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/types/events.d.ts +94 -0
- package/lib/typescript/commonjs/types/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +242 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts +21 -0
- package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/screens.d.ts +46 -0
- package/lib/typescript/commonjs/ui/components/screens.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts +19 -0
- package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts +29 -0
- package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/index.d.ts +7 -0
- package/lib/typescript/commonjs/ui/index.d.ts.map +1 -0
- package/lib/typescript/module/api/api-client.d.ts +82 -0
- package/lib/typescript/module/api/api-client.d.ts.map +1 -0
- package/lib/typescript/module/api/api-error.d.ts +13 -0
- package/lib/typescript/module/api/api-error.d.ts.map +1 -0
- package/lib/typescript/module/api/index.d.ts +6 -0
- package/lib/typescript/module/api/index.d.ts.map +1 -0
- package/lib/typescript/module/api/upload.d.ts +19 -0
- package/lib/typescript/module/api/upload.d.ts.map +1 -0
- package/lib/typescript/module/camera/camera-view.d.ts +25 -0
- package/lib/typescript/module/camera/camera-view.d.ts.map +1 -0
- package/lib/typescript/module/camera/index.d.ts +5 -0
- package/lib/typescript/module/camera/index.d.ts.map +1 -0
- package/lib/typescript/module/camera/photo-capture.d.ts +9 -0
- package/lib/typescript/module/camera/photo-capture.d.ts.map +1 -0
- package/lib/typescript/module/crypto/fingerprint.d.ts +3 -0
- package/lib/typescript/module/crypto/fingerprint.d.ts.map +1 -0
- package/lib/typescript/module/crypto/hmac.d.ts +18 -0
- package/lib/typescript/module/crypto/hmac.d.ts.map +1 -0
- package/lib/typescript/module/crypto/index.d.ts +4 -0
- package/lib/typescript/module/crypto/index.d.ts.map +1 -0
- package/lib/typescript/module/crypto/session-manager.d.ts +27 -0
- package/lib/typescript/module/crypto/session-manager.d.ts.map +1 -0
- package/lib/typescript/module/i18n/en.d.ts +291 -0
- package/lib/typescript/module/i18n/en.d.ts.map +1 -0
- package/lib/typescript/module/i18n/fr.d.ts +6 -0
- package/lib/typescript/module/i18n/fr.d.ts.map +1 -0
- package/lib/typescript/module/i18n/index.d.ts +10 -0
- package/lib/typescript/module/i18n/index.d.ts.map +1 -0
- package/lib/typescript/module/i18n/locale.d.ts +4 -0
- package/lib/typescript/module/i18n/locale.d.ts.map +1 -0
- package/lib/typescript/module/i18n/translator.d.ts +15 -0
- package/lib/typescript/module/i18n/translator.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +24 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/lib/device-detector.d.ts +5 -0
- package/lib/typescript/module/lib/device-detector.d.ts.map +1 -0
- package/lib/typescript/module/lib/event-emitter.d.ts +19 -0
- package/lib/typescript/module/lib/event-emitter.d.ts.map +1 -0
- package/lib/typescript/module/lib/index.d.ts +5 -0
- package/lib/typescript/module/lib/index.d.ts.map +1 -0
- package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts +43 -0
- package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts.map +1 -0
- package/lib/typescript/module/lib/verification-machine.d.ts +78 -0
- package/lib/typescript/module/lib/verification-machine.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/types/events.d.ts +94 -0
- package/lib/typescript/module/types/events.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +242 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts +21 -0
- package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/screens.d.ts +46 -0
- package/lib/typescript/module/ui/components/screens.d.ts.map +1 -0
- package/lib/typescript/module/ui/context/kwik-id-provider.d.ts +19 -0
- package/lib/typescript/module/ui/context/kwik-id-provider.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts +29 -0
- package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts.map +1 -0
- package/lib/typescript/module/ui/index.d.ts +7 -0
- package/lib/typescript/module/ui/index.d.ts.map +1 -0
- package/package.json +121 -3
- package/src/api/api-client.ts +319 -0
- package/src/api/api-error.ts +28 -0
- package/src/api/index.ts +12 -0
- package/src/api/upload.ts +87 -0
- package/src/camera/camera-view.tsx +217 -0
- package/src/camera/index.ts +4 -0
- package/src/camera/photo-capture.ts +58 -0
- package/src/crypto/fingerprint.ts +46 -0
- package/src/crypto/hmac.ts +172 -0
- package/src/crypto/index.ts +3 -0
- package/src/crypto/session-manager.ts +200 -0
- package/src/i18n/en.ts +315 -0
- package/src/i18n/fr.ts +325 -0
- package/src/i18n/index.ts +9 -0
- package/src/i18n/locale.ts +15 -0
- package/src/i18n/translator.ts +37 -0
- package/src/index.ts +102 -0
- package/src/lib/device-detector.ts +32 -0
- package/src/lib/event-emitter.ts +90 -0
- package/src/lib/index.ts +15 -0
- package/src/lib/kwik-id-rn-sdk.ts +160 -0
- package/src/lib/verification-machine.ts +273 -0
- package/src/types/events.ts +75 -0
- package/src/types/index.ts +309 -0
- package/src/ui/components/KwikIDVerificationModal.tsx +450 -0
- package/src/ui/components/screens.tsx +283 -0
- package/src/ui/context/kwik-id-provider.tsx +72 -0
- package/src/ui/hooks/use-kwik-verification.ts +121 -0
- package/src/ui/index.ts +9 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Translate } from "../../i18n/index.js";
|
|
2
|
+
import type { CaptureAsset, DocumentType } from "../../types/index.js";
|
|
3
|
+
export interface Theme {
|
|
4
|
+
primary: string;
|
|
5
|
+
background: string;
|
|
6
|
+
foreground: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function IntroScreen({ orgName, onNext, theme, t, }: {
|
|
9
|
+
orgName?: string;
|
|
10
|
+
onNext: () => void;
|
|
11
|
+
theme: Theme;
|
|
12
|
+
t: Translate;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function DocumentTypeScreen({ allowed, onSelect, theme, t, }: {
|
|
15
|
+
allowed: DocumentType[];
|
|
16
|
+
onSelect: (doc: DocumentType) => void;
|
|
17
|
+
theme: Theme;
|
|
18
|
+
t: Translate;
|
|
19
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare function PrepareScreen({ kind, onNext, theme, t, }: {
|
|
21
|
+
kind: "front" | "back" | "selfie";
|
|
22
|
+
onNext: () => void;
|
|
23
|
+
theme: Theme;
|
|
24
|
+
t: Translate;
|
|
25
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare function ConfirmScreen({ asset, onConfirm, onRetake, theme, t, }: {
|
|
27
|
+
asset: CaptureAsset;
|
|
28
|
+
onConfirm: () => void;
|
|
29
|
+
onRetake: () => void;
|
|
30
|
+
theme: Theme;
|
|
31
|
+
t: Translate;
|
|
32
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export declare function ProcessingScreen({ progress, stage, theme, t, }: {
|
|
34
|
+
progress: number;
|
|
35
|
+
stage: string | null;
|
|
36
|
+
theme: Theme;
|
|
37
|
+
t: Translate;
|
|
38
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export declare function ResultScreen({ success, message, onDone, theme, t, }: {
|
|
40
|
+
success: boolean;
|
|
41
|
+
message: string;
|
|
42
|
+
onDone: () => void;
|
|
43
|
+
theme: Theme;
|
|
44
|
+
t: Translate;
|
|
45
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
//# sourceMappingURL=screens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screens.d.ts","sourceRoot":"","sources":["../../../../../src/ui/components/screens.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,qBAAY,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAa,CAAC;AAE9D,MAAM,WAAW,KAAK;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AA8BD,wBAAgB,WAAW,CAAC,EACxB,OAAO,EACP,MAAM,EACN,KAAK,EACL,CAAC,GACJ,EAAE;IACC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,EAAE,SAAS,CAAC;CAChB,2CAYA;AAED,wBAAgB,kBAAkB,CAAC,EAC/B,OAAO,EACP,QAAQ,EACR,KAAK,EACL,CAAC,GACJ,EAAE;IACC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;IACtC,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,EAAE,SAAS,CAAC;CAChB,2CAqBA;AAWD,wBAAgB,aAAa,CAAC,EAC1B,IAAI,EACJ,MAAM,EACN,KAAK,EACL,CAAC,GACJ,EAAE;IACC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,EAAE,SAAS,CAAC;CAChB,2CAUA;AAED,wBAAgB,aAAa,CAAC,EAC1B,KAAK,EACL,SAAS,EACT,QAAQ,EACR,KAAK,EACL,CAAC,GACJ,EAAE;IACC,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,EAAE,SAAS,CAAC;CAChB,2CAgBA;AAED,wBAAgB,gBAAgB,CAAC,EAC7B,QAAQ,EACR,KAAK,EACL,KAAK,EACL,CAAC,GACJ,EAAE;IACC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,EAAE,SAAS,CAAC;CAChB,2CAyBA;AAED,wBAAgB,YAAY,CAAC,EACzB,OAAO,EACP,OAAO,EACP,MAAM,EACN,KAAK,EACL,CAAC,GACJ,EAAE;IACC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,EAAE,SAAS,CAAC;CAChB,2CAkBA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { KwikIdRNSDK } from "../../lib/kwik-id-rn-sdk.js";
|
|
2
|
+
import type { DocumentType, KwikIdConfig, KwikIdTheme, LivenessMode, SessionInfo } from "../../types/index.js";
|
|
3
|
+
export interface KwikIDContextValue {
|
|
4
|
+
sdk: KwikIdRNSDK;
|
|
5
|
+
sessionInfo: SessionInfo | null;
|
|
6
|
+
orgName?: string;
|
|
7
|
+
allowedDocumentTypes: DocumentType[];
|
|
8
|
+
livenessMode: LivenessMode;
|
|
9
|
+
theme: KwikIdTheme;
|
|
10
|
+
}
|
|
11
|
+
export interface KwikIDProviderProps {
|
|
12
|
+
config: KwikIdConfig;
|
|
13
|
+
/** Initialize the session immediately on mount (default true). */
|
|
14
|
+
autoInitialize?: boolean;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export declare function KwikIDProvider({ config, autoInitialize, children }: KwikIDProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<KwikIDContextValue | null>>;
|
|
18
|
+
export declare function useKwikID(): KwikIDContextValue;
|
|
19
|
+
//# sourceMappingURL=kwik-id-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kwik-id-provider.d.ts","sourceRoot":"","sources":["../../../../../src/ui/context/kwik-id-provider.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA0B,CAAC;AACvD,OAAO,KAAK,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,WAAW,EACd,MAAM,sBAAa,CAAC;AAErB,MAAM,WAAW,kBAAkB;IAC/B,GAAG,EAAE,WAAW,CAAC;IACjB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,YAAY,EAAE,CAAC;IACrC,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,WAAW,CAAC;CACtB;AAID,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,YAAY,CAAC;IACrB,kEAAkE;IAClE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,cAAqB,EAAE,QAAQ,EAAE,EAAE,mBAAmB,sGA6B9F;AAED,wBAAgB,SAAS,IAAI,kBAAkB,CAM9C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DocumentType, KwikIdTheme, LivenessMode, Locale, VerificationOutcome } from "../../types/index.js";
|
|
2
|
+
export interface UseKwikVerificationOptions {
|
|
3
|
+
clientSecret: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
appName?: string;
|
|
6
|
+
theme?: KwikIdTheme;
|
|
7
|
+
locale?: Locale;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Not yet supported: accepted for forward compatibility but ignored.
|
|
10
|
+
* Phase 1 is capture-only; on-device liveness (and this option) lands in Phase 2.
|
|
11
|
+
*/
|
|
12
|
+
livenessMode?: LivenessMode;
|
|
13
|
+
documentTypes?: DocumentType[];
|
|
14
|
+
skipRuntimeCheck?: boolean;
|
|
15
|
+
onSubmitted?: (data: {
|
|
16
|
+
jobId: string;
|
|
17
|
+
}) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface UseKwikVerification {
|
|
20
|
+
/** Open the flow; resolves when the user reaches a terminal state. */
|
|
21
|
+
start: () => Promise<VerificationOutcome>;
|
|
22
|
+
/** Programmatically dismiss (resolves a pending start() as cancelled). */
|
|
23
|
+
cancel: () => void;
|
|
24
|
+
isOpen: boolean;
|
|
25
|
+
/** Render this once in your tree; the verification UI mounts here. */
|
|
26
|
+
Modal: React.FC;
|
|
27
|
+
}
|
|
28
|
+
export declare function useKwikVerification(options: UseKwikVerificationOptions): UseKwikVerification;
|
|
29
|
+
//# sourceMappingURL=use-kwik-verification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-kwik-verification.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/use-kwik-verification.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,MAAM,EACN,mBAAmB,EACtB,MAAM,sBAAa,CAAC;AAGrB,MAAM,WAAW,0BAA0B;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,mBAAmB;IAChC,sEAAsE;IACtE,KAAK,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1C,0EAA0E;IAC1E,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;CACnB;AAQD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CAyE5F"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { KwikIDVerificationModal } from "./components/KwikIDVerificationModal.js";
|
|
2
|
+
export type { KwikIDVerificationModalProps } from "./components/KwikIDVerificationModal.js";
|
|
3
|
+
export { useKwikVerification } from "./hooks/use-kwik-verification.js";
|
|
4
|
+
export type { UseKwikVerification, UseKwikVerificationOptions, } from "./hooks/use-kwik-verification.js";
|
|
5
|
+
export { KwikIDProvider, useKwikID } from "./context/kwik-id-provider.js";
|
|
6
|
+
export type { KwikIDProviderProps, KwikIDContextValue } from "./context/kwik-id-provider.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAsC,CAAC;AAC/E,YAAY,EAAE,4BAA4B,EAAE,MAAM,yCAAsC,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAA+B,CAAC;AACpE,YAAY,EACR,mBAAmB,EACnB,0BAA0B,GAC7B,MAAM,kCAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,+BAA4B,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,+BAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,124 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kwik-id/sdk-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "KwikId on-device KYC + liveness SDK for React Native / Expo",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"author": "Kwik Nkap Technologies",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/kwik-nkap/kwik-id.git",
|
|
10
|
+
"directory": "libs/sdk-react-native"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/kwik-nkap/kwik-id/tree/main/libs/sdk-react-native#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/kwik-nkap/kwik-id/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "./lib/commonjs/index.js",
|
|
17
|
+
"module": "./lib/module/index.js",
|
|
18
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
19
|
+
"react-native": "./src/index.ts",
|
|
20
|
+
"source": "./src/index.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"source": "./src/index.ts",
|
|
25
|
+
"react-native": "./src/index.ts",
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./lib/typescript/module/index.d.ts",
|
|
28
|
+
"default": "./lib/module/index.js"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
32
|
+
"default": "./lib/commonjs/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./app.plugin.js": "./app.plugin.js"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"src",
|
|
39
|
+
"lib",
|
|
40
|
+
"app.plugin.js",
|
|
41
|
+
"!**/__tests__",
|
|
42
|
+
"!**/*.test.*",
|
|
43
|
+
"!**/__mocks__",
|
|
44
|
+
"!**/__compat__*",
|
|
45
|
+
"!**/*.tsbuildinfo"
|
|
46
|
+
],
|
|
47
|
+
"react-native-builder-bob": {
|
|
48
|
+
"source": "src",
|
|
49
|
+
"output": "lib",
|
|
50
|
+
"exclude": "**/{__tests__,__mocks__,__compat__}/**",
|
|
51
|
+
"targets": [
|
|
52
|
+
[
|
|
53
|
+
"commonjs",
|
|
54
|
+
{
|
|
55
|
+
"esm": true
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
"module",
|
|
60
|
+
{
|
|
61
|
+
"esm": true
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"typescript",
|
|
66
|
+
{
|
|
67
|
+
"project": "tsconfig.lib.json"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"nx": {
|
|
73
|
+
"name": "sdk-react-native"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"expo": ">=53.0.0 <54.0.0",
|
|
77
|
+
"expo-constants": "~17.1.0",
|
|
78
|
+
"expo-device": "~7.1.0",
|
|
79
|
+
"expo-file-system": "~18.1.0",
|
|
80
|
+
"expo-image-manipulator": "~13.1.0",
|
|
81
|
+
"expo-localization": "~16.1.0",
|
|
82
|
+
"react": ">=19.0.0",
|
|
83
|
+
"react-native": ">=0.79.0",
|
|
84
|
+
"react-native-reanimated": ">=3.10.0 <4.0.0",
|
|
85
|
+
"react-native-vision-camera": ">=4.6.0 <5.0.0",
|
|
86
|
+
"react-native-vision-camera-face-detector": ">=1.8.0 <2.0.0",
|
|
87
|
+
"react-native-worklets-core": ">=1.3.0 <2.0.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"react-native-reanimated": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"react-native-vision-camera-face-detector": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"react-native-worklets-core": {
|
|
97
|
+
"optional": true
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"expo": "~53.0.0",
|
|
102
|
+
"expo-constants": "~17.1.0",
|
|
103
|
+
"expo-device": "~7.1.0",
|
|
104
|
+
"expo-file-system": "~18.1.0",
|
|
105
|
+
"expo-image-manipulator": "~13.1.0",
|
|
106
|
+
"expo-localization": "~16.1.0",
|
|
107
|
+
"react": "19.0.0",
|
|
108
|
+
"react-native": "0.79.5",
|
|
109
|
+
"react-native-builder-bob": "^0.43.0",
|
|
110
|
+
"react-native-reanimated": "~3.17.0",
|
|
111
|
+
"react-native-vision-camera": "^4.6.0",
|
|
112
|
+
"react-native-vision-camera-face-detector": "^1.8.0",
|
|
113
|
+
"react-native-worklets-core": "^1.6.0",
|
|
114
|
+
"@kwik-id/types": "0.0.1",
|
|
115
|
+
"@kwik-id/sdk-core": "0.0.1"
|
|
116
|
+
},
|
|
117
|
+
"scripts": {
|
|
118
|
+
"build": "bob build",
|
|
119
|
+
"typecheck": "tsc --noEmit -p tsconfig.lib.json",
|
|
120
|
+
"test": "jest",
|
|
121
|
+
"publish:alpha": "bob build && pnpm publish --tag alpha --access public",
|
|
122
|
+
"publish:latest": "bob build && pnpm publish --access public"
|
|
123
|
+
}
|
|
6
124
|
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RN API client for the KwikId SDK gateway (`/sdk/v1/*`).
|
|
3
|
+
*
|
|
4
|
+
* Ported from @kwik-id/sdk-core: the JSON `request()` (fetch + AbortController) is
|
|
5
|
+
* unchanged; the XMLHttpRequest upload is replaced with an injectable multipart
|
|
6
|
+
* uploader (expo-file-system by default). `liveness_frame` has no server endpoint
|
|
7
|
+
* and is rejected.
|
|
8
|
+
*/
|
|
9
|
+
import { SessionManager } from "../crypto/session-manager";
|
|
10
|
+
import type {
|
|
11
|
+
CaptureAsset,
|
|
12
|
+
CaptureType,
|
|
13
|
+
DocumentType,
|
|
14
|
+
LivenessResult,
|
|
15
|
+
QualityResult,
|
|
16
|
+
SessionInfo,
|
|
17
|
+
VerificationResult,
|
|
18
|
+
} from "../types";
|
|
19
|
+
import { ApiError } from "./api-error";
|
|
20
|
+
import { type Uploader, uploadMultipart } from "./upload";
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_BASE_URL = "https://api.identity.kwiknkap.com";
|
|
23
|
+
|
|
24
|
+
export interface ApiClientConfig {
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
/** Custom fetch implementation (for testing). */
|
|
29
|
+
fetch?: typeof fetch;
|
|
30
|
+
/** Custom multipart uploader (for testing). */
|
|
31
|
+
uploader?: Uploader;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface UploadResponse {
|
|
35
|
+
uploadId: string;
|
|
36
|
+
status: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SubmitResponse {
|
|
40
|
+
success: boolean;
|
|
41
|
+
message?: string;
|
|
42
|
+
jobId?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface StatusResponse {
|
|
46
|
+
jobId: string;
|
|
47
|
+
status: "queued" | "processing" | "completed" | "failed" | "verified" | "rejected";
|
|
48
|
+
progress?: number;
|
|
49
|
+
processingStep?: string;
|
|
50
|
+
errorCode?: string;
|
|
51
|
+
errorMessage?: string;
|
|
52
|
+
errorDetails?: {
|
|
53
|
+
document: string;
|
|
54
|
+
errorCode: string;
|
|
55
|
+
errorMessage: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface HandoffValidateResponse {
|
|
60
|
+
valid: boolean;
|
|
61
|
+
orgName?: string;
|
|
62
|
+
orgLogoUrl?: string;
|
|
63
|
+
expiresAt?: string;
|
|
64
|
+
error?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface HandoffRedeemResponse {
|
|
68
|
+
sessionToken: string;
|
|
69
|
+
jobId: string;
|
|
70
|
+
expiresAt: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const CAPTURE_PATH: Record<CaptureType, string | null> = {
|
|
74
|
+
document_front: "front",
|
|
75
|
+
document_back: "back",
|
|
76
|
+
selfie: "selfie",
|
|
77
|
+
liveness_frame: null, // no server endpoint — liveness evidence rides in /submit
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export class ApiClient {
|
|
81
|
+
private config: ApiClientConfig;
|
|
82
|
+
private sessionManager: SessionManager;
|
|
83
|
+
private uploader: Uploader;
|
|
84
|
+
|
|
85
|
+
constructor(sessionManager: SessionManager, config?: Partial<ApiClientConfig>) {
|
|
86
|
+
this.config = {
|
|
87
|
+
baseUrl: DEFAULT_BASE_URL,
|
|
88
|
+
timeout: 30000,
|
|
89
|
+
debug: false,
|
|
90
|
+
...config,
|
|
91
|
+
};
|
|
92
|
+
this.sessionManager = sessionManager;
|
|
93
|
+
this.uploader = config?.uploader ?? uploadMultipart;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async validateSession(clientSecret: string): Promise<SessionInfo> {
|
|
97
|
+
await this.sessionManager.initializeFromClientSecret(clientSecret);
|
|
98
|
+
const response = await this.request<SessionInfo>("GET", "/sdk/v1/session");
|
|
99
|
+
this.sessionManager.updateSession({ expiresAt: new Date(response.expiresAt) });
|
|
100
|
+
return response;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async uploadCapture(
|
|
104
|
+
type: CaptureType,
|
|
105
|
+
asset: CaptureAsset,
|
|
106
|
+
onProgress?: (progress: number) => void
|
|
107
|
+
): Promise<UploadResponse> {
|
|
108
|
+
const path = CAPTURE_PATH[type];
|
|
109
|
+
if (!path) {
|
|
110
|
+
throw new Error(`Unsupported capture type for upload: ${type}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const url = `${this.config.baseUrl}/sdk/v1/upload/${path}`;
|
|
114
|
+
const headers = this.sessionManager.getRequestHeaders();
|
|
115
|
+
return this.uploader({
|
|
116
|
+
url,
|
|
117
|
+
asset,
|
|
118
|
+
headers,
|
|
119
|
+
onProgress,
|
|
120
|
+
timeoutMs: this.config.timeout,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async submitVerification(
|
|
125
|
+
documentType: DocumentType,
|
|
126
|
+
clientAnalysis?: { qualityScores?: QualityResult; livenessResult?: LivenessResult }
|
|
127
|
+
): Promise<SubmitResponse> {
|
|
128
|
+
const payload = await this.sessionManager.createSecurePayload({
|
|
129
|
+
documentType,
|
|
130
|
+
clientAnalysis,
|
|
131
|
+
submittedAt: Date.now(),
|
|
132
|
+
});
|
|
133
|
+
return this.request<SubmitResponse>("POST", "/sdk/v1/submit", payload);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async getStatus(): Promise<StatusResponse> {
|
|
137
|
+
return this.request<StatusResponse>("GET", "/sdk/v1/status");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async getResult(): Promise<VerificationResult> {
|
|
141
|
+
return this.request<VerificationResult>("GET", "/sdk/v1/result");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async pollForResult(
|
|
145
|
+
options: {
|
|
146
|
+
maxAttempts?: number;
|
|
147
|
+
intervalMs?: number;
|
|
148
|
+
onProgress?: (status: StatusResponse) => void;
|
|
149
|
+
} = {}
|
|
150
|
+
): Promise<VerificationResult> {
|
|
151
|
+
const { maxAttempts = 60, intervalMs = 2000, onProgress } = options;
|
|
152
|
+
let attempts = 0;
|
|
153
|
+
|
|
154
|
+
while (attempts < maxAttempts) {
|
|
155
|
+
const status = await this.getStatus();
|
|
156
|
+
onProgress?.(status);
|
|
157
|
+
|
|
158
|
+
if (status.status === "verified") {
|
|
159
|
+
return this.getResult();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (status.status === "rejected") {
|
|
163
|
+
const result = await this.getResult();
|
|
164
|
+
const contextualError = status.errorDetails
|
|
165
|
+
? `${status.errorDetails.document === "front" ? "Front" : "Back"} document: ${status.errorDetails.errorMessage}`
|
|
166
|
+
: undefined;
|
|
167
|
+
return {
|
|
168
|
+
...result,
|
|
169
|
+
status: "rejected",
|
|
170
|
+
errorDetails: status.errorDetails,
|
|
171
|
+
rejectionReasons: [
|
|
172
|
+
contextualError || status.errorMessage || "Verification rejected",
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (status.status === "failed") {
|
|
178
|
+
// A failed job may have no result record, so fall back to a minimal one.
|
|
179
|
+
const result = await this.getResult().catch(
|
|
180
|
+
(): VerificationResult => ({
|
|
181
|
+
jobId: status.jobId,
|
|
182
|
+
status: "rejected",
|
|
183
|
+
overallScore: 0,
|
|
184
|
+
scores: {
|
|
185
|
+
documentQuality: 0,
|
|
186
|
+
documentAuthenticity: 0,
|
|
187
|
+
faceMatch: 0,
|
|
188
|
+
liveness: 0,
|
|
189
|
+
},
|
|
190
|
+
timestamps: { submitted: "" },
|
|
191
|
+
referenceId: "",
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
return {
|
|
195
|
+
...result,
|
|
196
|
+
// VerificationResult has no "failed" status (it mirrors sdk-core).
|
|
197
|
+
status: "rejected",
|
|
198
|
+
errorDetails: status.errorDetails,
|
|
199
|
+
rejectionReasons: [
|
|
200
|
+
status.errorDetails?.errorMessage ||
|
|
201
|
+
status.errorMessage ||
|
|
202
|
+
"Verification failed",
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
attempts++;
|
|
208
|
+
await this.delay(intervalMs);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
throw new Error("Verification timeout");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---- Handoff (mobile redeemer) ----
|
|
215
|
+
|
|
216
|
+
async validateHandoff(code: string): Promise<HandoffValidateResponse> {
|
|
217
|
+
const url = `${this.config.baseUrl}/sdk/v1/handoff/${encodeURIComponent(code)}`;
|
|
218
|
+
const fetchFn = this.config.fetch || fetch;
|
|
219
|
+
const response = await fetchFn(url);
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
return { valid: false, error: `Validation failed: ${response.status}` };
|
|
222
|
+
}
|
|
223
|
+
return (await response.json()) as HandoffValidateResponse;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async redeemHandoff(code: string): Promise<HandoffRedeemResponse> {
|
|
227
|
+
const url = `${this.config.baseUrl}/sdk/v1/handoff/${encodeURIComponent(code)}/redeem`;
|
|
228
|
+
const fetchFn = this.config.fetch || fetch;
|
|
229
|
+
const response = await fetchFn(url, {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers: { "Content-Type": "application/json" },
|
|
232
|
+
});
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
const error = (await response.json().catch(() => ({}))) as Record<string, string>;
|
|
235
|
+
throw new ApiError(
|
|
236
|
+
error.message || `Redeem failed: ${response.status}`,
|
|
237
|
+
response.status
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
return (await response.json()) as HandoffRedeemResponse;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async reportHandoffStatus(code: string, status: "completed" | "abandoned"): Promise<void> {
|
|
244
|
+
await this.request<{ success: boolean }>(
|
|
245
|
+
"POST",
|
|
246
|
+
`/sdk/v1/handoff/${encodeURIComponent(code)}/status`,
|
|
247
|
+
{ status }
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
getBaseUrl(): string {
|
|
252
|
+
return this.config.baseUrl;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private async request<T>(
|
|
256
|
+
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
257
|
+
path: string,
|
|
258
|
+
body?: unknown
|
|
259
|
+
): Promise<T> {
|
|
260
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
261
|
+
const controller = new AbortController();
|
|
262
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const headers: Record<string, string> = {
|
|
266
|
+
"Content-Type": "application/json",
|
|
267
|
+
...this.sessionManager.getRequestHeaders(),
|
|
268
|
+
};
|
|
269
|
+
const fetchFn = this.config.fetch || fetch;
|
|
270
|
+
|
|
271
|
+
const response = await fetchFn(url, {
|
|
272
|
+
method,
|
|
273
|
+
headers,
|
|
274
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
275
|
+
signal: controller.signal,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
clearTimeout(timeoutId);
|
|
279
|
+
|
|
280
|
+
if (!response.ok) {
|
|
281
|
+
throw await this.parseErrorResponse(response);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const data = await response.json();
|
|
285
|
+
if (this.config.debug) {
|
|
286
|
+
console.log(`[KwikID API] ${method} ${path}`, { body, response: data });
|
|
287
|
+
}
|
|
288
|
+
return data as T;
|
|
289
|
+
} catch (error) {
|
|
290
|
+
clearTimeout(timeoutId);
|
|
291
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
292
|
+
throw new Error("Request timeout");
|
|
293
|
+
}
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private async parseErrorResponse(response: Response): Promise<Error> {
|
|
299
|
+
try {
|
|
300
|
+
const data = (await response.json()) as {
|
|
301
|
+
message?: string;
|
|
302
|
+
code?: string;
|
|
303
|
+
details?: unknown;
|
|
304
|
+
};
|
|
305
|
+
return new ApiError(
|
|
306
|
+
data.message || `API error: ${response.status}`,
|
|
307
|
+
response.status,
|
|
308
|
+
data.code,
|
|
309
|
+
data.details
|
|
310
|
+
);
|
|
311
|
+
} catch {
|
|
312
|
+
return new ApiError(`API error: ${response.status}`, response.status);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private delay(ms: number): Promise<void> {
|
|
317
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API error (ported verbatim from @kwik-id/sdk-core).
|
|
3
|
+
*/
|
|
4
|
+
export class ApiError extends Error {
|
|
5
|
+
public readonly statusCode: number;
|
|
6
|
+
public readonly code?: string;
|
|
7
|
+
public readonly details?: unknown;
|
|
8
|
+
|
|
9
|
+
constructor(message: string, statusCode: number, code?: string, details?: unknown) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "ApiError";
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
isRetryable(): boolean {
|
|
18
|
+
return this.statusCode >= 500 || this.statusCode === 429;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
isAuthError(): boolean {
|
|
22
|
+
return this.statusCode === 401 || this.statusCode === 403;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isValidationError(): boolean {
|
|
26
|
+
return this.statusCode === 400 || this.statusCode === 422;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ApiClient, DEFAULT_BASE_URL } from "./api-client";
|
|
2
|
+
export type {
|
|
3
|
+
ApiClientConfig,
|
|
4
|
+
UploadResponse,
|
|
5
|
+
SubmitResponse,
|
|
6
|
+
StatusResponse,
|
|
7
|
+
HandoffValidateResponse,
|
|
8
|
+
HandoffRedeemResponse,
|
|
9
|
+
} from "./api-client";
|
|
10
|
+
export { ApiError } from "./api-error";
|
|
11
|
+
export { uploadMultipart } from "./upload";
|
|
12
|
+
export type { Uploader, UploadResult } from "./upload";
|