# capacitor-luna-id-sdk

LUNA SDK is a face recognition and analysis system that provides efficient and accurate processing of faces in images and video streams, and can run on a wide variety of mobile operating systems.

## Install

```bash
npm install capacitor-luna-id-sdk
npx cap sync
```

## Requirements

| Plugin | LUNA ID (iOS / Android) | iOS  | Android                 |
| ------ | ----------------------- | ---- | ----------------------- |
| 7.3.x  | 1.23.0 / 1.23.0         | 15.0+ | 6.0+ (API 23)           |
| 7.2.x  | 1.22.0 / 1.22.1         | 15.0+ | 6.0+ (API 23)           |

> **Android 6–7 (API 23–25):** VisionLabs documentation lists Android 8.0 (API 26) as the minimum for LUNA ID 1.23.0,
> but the SDK itself declares `minSdkVersion 23`. The plugin keeps `minSdk 23`; test on Android 6–7 devices before release.

## LICENCING & Configuration

1. Get `licence.conf` from VisionLabs
2. Configure Luna Platform 5 and get `LunaAccountID`
3. Configure `LunaServerURL`


## iOS

1. Add to  `./node_modules/capacitor-luna-id-sdk/ios/Frameworks/fsdk.framework/data/license.conf` your own `licence.conf` file;
2. Add to `Info.plist`
```bash
<key>LunaServerURL</key>
<string>https://[path-to-luna-platform-api]/6/</string>
```
```bash
<key>LunaAccountID</key>
<string><your luna account id></string>
```

## Android

Add to your project `android/app/src/main/assets/data/license.conf` license file


Add to your root project `local.properties`
```bash
DEFAULT_BASE_URL="https://[path-to-luna-platform-api]/6/"
DEFAULT_LUNA_ACCOUNT_ID="<your luna account id>"
vl.login=YOUR_LOGIN
vl.pass=YOUR_PASSWORD
```

## Security check errors

When the device fails the security check, `start()` is rejected with extra data in `error.data`
(see [`StartErrorData`](src/definitions.ts)):

```ts
import type { StartErrorData } from 'capacitor-luna-id-sdk';

try {
  await LunaSDK.start();
} catch (e: any) {
  const data = e.data as StartErrorData | undefined;
  if (data?.reasons) {
    // Android: e.code === 'SECURITY', reasons: ROOT | VIRTUAL_CAMERA | CLOUD_PHONE | DESKTOP_EMULATOR | OTHER
    // iOS:     e.code === 'ERROR' (jailbroken device), reasons: ['ROOT']
    console.log(data.primaryReason, data.reasons);
  }
}
```

## Orientation error (iOS)

On iOS the capture is interrupted when the device orientation changes during the session
(for example, the phone is put flat on a table screen up). `start()` is then rejected with
`e.code === 'ORIENTATION'` and `e.data.orientation` (`FACE_UP`, `FACE_DOWN`, `LANDSCAPE_LEFT`, …).
Ask the user to hold the phone upright and call `start()` again. Android never returns this code.

```ts
try {
  await LunaSDK.start();
} catch (e: any) {
  if (e.code === 'ORIENTATION') {
    // e.data.orientation: 'FACE_UP' | 'FACE_DOWN' | 'LANDSCAPE_LEFT' | ...
    showHint('Держите телефон вертикально');
  }
}
```

## API

<docgen-index>

* [`initialize(...)`](#initialize)
* [`start(...)`](#start)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### initialize(...)

```typescript
initialize(options?: LunaOptions | undefined) => Promise<InitializeResponse>
```

Initialize plugin with configs

| Param         | Type                                                |
| ------------- | --------------------------------------------------- |
| **`options`** | <code><a href="#lunaoptions">LunaOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#initializeresponse">InitializeResponse</a>&gt;</code>

**Since:** 1.0.8

--------------------


### start(...)

```typescript
start(options?: StartOptions | undefined) => Promise<BestShot>
```

Start face recognition

| Param         | Type                                                  |
| ------------- | ----------------------------------------------------- |
| **`options`** | <code><a href="#startoptions">StartOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#bestshot">BestShot</a>&gt;</code>

**Since:** 1.0.0

--------------------


### Interfaces


#### InitializeResponse

| Prop               | Type                 | Description      | Since |
| ------------------ | -------------------- | ---------------- | ----- |
| **`initialized`**  | <code>boolean</code> | is initialized.  | 1.0.0 |
| **`initializing`** | <code>boolean</code> | is initializing. | 7.0.4 |


#### LunaOptions

| Prop                       | Type                                                        | Description                                                                                                                                                    | Default            | Since |
| -------------------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| **`livenessEnabled`**      | <code>boolean</code>                                        |                                                                                                                                                                |                    |       |
| **`occludeCheck`**         | <code>boolean</code>                                        |                                                                                                                                                                |                    |       |
| **`trackFaceIdentity`**    | <code>boolean</code>                                        |                                                                                                                                                                |                    |       |
| **`eyesCheck`**            | <code>boolean</code>                                        |                                                                                                                                                                |                    |       |
| **`glassesCheckEnabled`**  | <code>boolean</code>                                        |                                                                                                                                                                |                    |       |
| **`interactionEnabled`**   | <code>boolean</code>                                        |                                                                                                                                                                |                    |       |
| **`interactionTimeout`**   | <code>number</code>                                         |                                                                                                                                                                |                    |       |
| **`plistLicenseFileName`** | <code>string</code>                                         |                                                                                                                                                                |                    |       |
| **`debugLogs`**            | <code>boolean</code>                                        | iOS only. Verbose LUNA ID SDK logs (LunaCore debug + low-level fsdk logs) in the Xcode console. Without it only SDK errors are logged.                         | <code>false</code> | 7.3.0 |
| **`security`**             | <code><a href="#securityoptions">SecurityOptions</a></code> | Android only. Security check settings (LUNA ID `Security` feature). Applied on the first successful `initialize()` call. Not set — SDK defaults (LEGACY mode). |                    | 7.3.1 |
| **`lunaConfig`**           | <code><a href="#lunaconfig">LunaConfig</a></code>           |                                                                                                                                                                |                    |       |
| **`headers`**              | <code><a href="#headers">Headers</a></code>                 |                                                                                                                                                                |                    |       |


#### SecurityOptions

Android only. Mirrors LUNA ID `Security(...)`. Every field is optional — SDK default when omitted.

| Prop                          | Type                                                                                                            | Description                                                                                                                 | Default               |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| **`scoringMode`**             | <code><a href="#securityscoringmode">SecurityScoringMode</a></code>                                             |                                                                                                                             | <code>'LEGACY'</code> |
| **`scoreThreshold`**          | <code>number</code>                                                                                             | Score that blocks the session in `BLOCKING` mode.                                                                           | <code>100</code>      |
| **`blockOnReasons`**          | <code>SecurityReason[]</code>                                                                                   | Reasons that may block the session. Default — all reasons.                                                                  |                       |
| **`signalWeightOverrides`**   | <code><a href="#record">Record</a>&lt;number, <a href="#securityweightclass">SecurityWeightClass</a>&gt;</code> | Override weights of individual signals by code (`score.signals[].code`), e.g. `{ 34: 'IGNORED' }` — ignore missing sensors. |                       |
| **`allowBestShotOnFailure`**  | <code>boolean</code>                                                                                            | Do not interrupt capture on a failed check (the result is still reported).                                                  |                       |
| **`blockUntrustedInstaller`** | <code>boolean</code>                                                                                            | Block when the app was installed not from a trusted store.                                                                  |                       |


#### LunaConfig

| Prop                          | Type                                                    | Description  | Since |
| ----------------------------- | ------------------------------------------------------- | ------------ | ----- |
| **`detectorStep`**            | <code>number</code>                                     |              |       |
| **`skipFrames`**              | <code>number</code>                                     |              |       |
| **`compressionQuality`**      | <code>number</code>                                     |              |       |
| **`minimalTrackLength`**      | <code>number</code>                                     |              |       |
| **`bestShotsCount`**          | <code>number</code>                                     | Android only | 5.0.0 |
| **`numberOfBestShots`**       | <code>number</code>                                     | ios only     | 5.0.0 |
| **`borderDistance`**          | <code>number</code>                                     |              |       |
| **`detectFrameSize`**         | <code>number</code>                                     |              |       |
| **`bestShotInterval`**        | <code>number</code>                                     |              |       |
| **`headPitch`**               | <code>number</code>                                     |              |       |
| **`headYaw`**                 | <code>number</code>                                     |              |       |
| **`headRoll`**                | <code>number</code>                                     |              |       |
| **`ags`**                     | <code>number</code>                                     |              |       |
| **`eyesCheck`**               | <code>boolean</code>                                    |              |       |
| **`locationEnabled`**         | <code>boolean</code>                                    | ios only     | 5.0.0 |
| **`interactionEnabled`**      | <code>boolean</code>                                    |              |       |
| **`interactionTimeout`**      | <code>number</code>                                     |              |       |
| **`uploadImagesForLiveness`** | <code>boolean</code>                                    |              |       |
| **`livenessErrorTimeout`**    | <code>number</code>                                     |              |       |
| **`livenessQuality`**         | <code>number</code>                                     |              |       |
| **`livenessType`**            | <code><a href="#livenesstype">LivenessType</a></code>   |              |       |
| **`licenseParams`**           | <code><a href="#licenseparams">LicenseParams</a></code> | android only | 5.3.0 |


#### LicenseParams

| Prop            | Type                |
| --------------- | ------------------- |
| **`server`**    | <code>string</code> |
| **`eId`**       | <code>string</code> |
| **`productId`** | <code>string</code> |


#### BestShot

| Prop               | Type                | Description                                                 | Since |
| ------------------ | ------------------- | ----------------------------------------------------------- | ----- |
| **`base64String`** | <code>string</code> | The base64 encoded string representation of found bestShot. | 1.0.0 |
| **`videoPath`**    | <code>string</code> | The URI of video recorded from stream.                      | 5.0.0 |


#### StartOptions

| Prop                         | Type                 | Description                                                                         | Default              | Since |
| ---------------------------- | -------------------- | ----------------------------------------------------------------------------------- | -------------------- | ----- |
| **`disableErrors`**          | <code>boolean</code> | Define whether to record video or not.                                              | <code>: false</code> | 5.0.1 |
| **`disableInteractionTips`** | <code>boolean</code> | Define whether to disable interaction Tips.                                         | <code>: false</code> | 5.0.1 |
| **`ignoreVideoWithoutFace`** | <code>boolean</code> | Define whether to start record video from camera activated or from face is deteced. | <code>: false</code> | 5.0.1 |
| **`interactionEnabled`**     | <code>boolean</code> | Define whether to enable interaction or not.                                        | <code>: true</code>  | 5.0.1 |
| **`interactionTimeoutMs`**   | <code>number</code>  | Define timeout for interaction.                                                     | <code>: 30000</code> | 5.0.1 |
| **`recordVideo`**            | <code>boolean</code> | Define whether to record video or not.                                              | <code>: false</code> | 5.0.0 |


### Type Aliases


#### SecurityScoringMode

How the security check decides to block the session.
- `LEGACY` (SDK default) — any fired signal blocks (hard OR, pre-1.23 behavior).
- `BLOCKING` — blocks when the score reaches `scoreThreshold` (or a STRONG signal fired).
- `REPORT_ONLY` — never blocks, only computes the score (shadow rollout).

<code>'LEGACY' | 'BLOCKING' | 'REPORT_ONLY'</code>


#### SecurityReason

Reason why the device failed the security check.

<code>'ROOT' | 'CLOUD_PHONE' | 'DESKTOP_EMULATOR' | 'VIRTUAL_CAMERA' | 'OTHER'</code>


#### Record

Construct a type with a set of properties K of type T

<code>{ [P in K]: T; }</code>


#### SecurityWeightClass

Signal weight: IGNORED = 0, WEAK = 25, MEDIUM = 50, STRONG = 100 points.

<code>'IGNORED' | 'WEAK' | 'MEDIUM' | 'STRONG'</code>


#### Headers

<code><a href="#record">Record</a>&lt;string, string&gt; & <a href="#partial">Partial</a>&lt;<a href="#record">Record</a>&lt;<a href="#restrictedheaders">RestrictedHeaders</a>, never&gt;&gt;</code>


#### Partial

Make all properties in T optional

<code>{ [P in keyof T]?: T[P]; }</code>


#### RestrictedHeaders

<code>'Authorization' | 'Luna-Account-Id'</code>


### Enums


#### LivenessType

| Members            |
| ------------------ |
| **`None`**         |
| **`ByDescriptor`** |
| **`ByPhoto`**      |

</docgen-api>
