> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/cordova/componentes/componente-principal.md).

# Main component

It is the SDK's most important component, as it contains the libraries needed to ensure everything works correctly.

The installation of the **Core** **Plugin** is required, regardless of the products to be used or the defined use case. It contains basic functionality for the SDK to operate, as well as other cross-cutting functionality required by the auxiliary plugins.

## Dependencies <a href="#id-2-dependencia" id="id-2-dependencia"></a>

### Cordova:

```swift
cordova plugin add @facephi/sdk-core-cordova@<versión>
```

### Android - Gradle:

```kotlin
api "com.facephi.androidsdk:sdk:$version"
api "com.facephi.androidsdk:core:$version"
implementation "com.facephi.androidsdk:tracking_component:$version"
```

### iOS - CocoaPods:

```swift
s.dependency 'FPHISDKMainComponent', '~> $version'
s.dependency 'FPHISDKTrackingComponent', '~> $version'
s.dependency 'FPHISDKLicensingComponent', '~> $version'
s.dependency 'FPHISDKTokenizeComponent', '~> $version'
s.dependency 'FPHISDKStatusComponent', '~> $version'
```

## Available methods

This component contains several methods that perform different functions:

<table data-header-hidden><thead><tr><th width="233.64453125"></th><th></th></tr></thead><tbody><tr><td><strong>Method</strong></td><td><strong>Description</strong></td></tr><tr><td>launchInitSession</td><td>Main component controller, responsible for validating licenses, among other things.</td></tr><tr><td>launchInitOperation</td><td>Method responsible for generating a new operation. Its ID is retrieved from the result object, in the data parameter.</td></tr><tr><td>launchGetExtraData</td><td>The getExtraData method generates the identifiers needed for an operation that needs to continue in the <em>Facephi Validation Service</em> (Backend).</td></tr><tr><td>launchCloseSession</td><td>Before the application is destroyed, the SDK session must be closed to notify the platform that it has ended.</td></tr></tbody></table>

### launchInitSession <a href="#id-2-inicializacion-de-la-sesion" id="id-2-inicializacion-de-la-sesion"></a>

Before you can use any component, you must initialize the SDK session. Initialize it as early as possible, preferably when the application starts. Likewise, once all operations with the SDK Mobile are complete, the session must be closed.

The current component can be initialized in two ways, depending on how you want to inject the license.

The new licensing method lets you manage licenses transparently for the integrator. The license can be injected in two ways:

* a. Obtaining the license through a service using a URL and API key
* b. Injecting the license directly as a String

In both cases, the result is returned through a *Promise*, which contains an object of the **CoreResult**.

```javascript
exports.launchInitSession = function (cfg) {
    return new Promise((resolve, reject) => {
        var config = [];
        try {
            config = [{
                config: cfg
            }];
        } catch (e) {
            console.log(e);
        }

        exec(resolve, reject, 'SdkCore', 'launchInitSession', config);
    });
};
```

## Basic Configuration <a href="#id-5-configuracion-basica" id="id-5-configuracion-basica"></a>

To launch the current component, an object must be created ***InitSessionConfiguration*** which will be the component controller configuration.

The basic configuration required is as follows:

```typescript
export interface InitSessionConfiguration {
    license?: string;
    licenseUrl?: string;
    licenseApiKey?: string;
    enableTracking?: boolean;
    enableFlow?: boolean;
    enableSecurityMode?: boolean;
    internalOptions?: Record<string, string>;
    locale?: string;
}
```

### Advanced component configuration

All the fields that are part of this class are described below.

{% content-ref url="/pages/8de20a0612fefc3ed40ba226ed4e9e4d403555a7" %}
[Init Session Configuration](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/extras/core/init-session-configuracion.md)
{% endcontent-ref %}

***

### launchInitOperation <a href="#id-3-inicializacion-de-la-operacion" id="id-3-inicializacion-de-la-operacion"></a>

When starting a process or flow, **always** the method *launchInitOperation*

```javascript
exports.launchInitOperation = function (cfg) {
    return new Promise((resolve, reject) => {
        var config = [];
        try {
            config = [{
                config: cfg
            }];
        } catch (e) {
            console.log(e);
        }

        exec(resolve, reject, 'SdkCore', 'launchInitOperation', config);
    });
};
```

## Basic Configuration <a href="#id-5-configuracion-basica" id="id-5-configuracion-basica"></a>

To launch the current component, you must create an ***InitOperationConfiguration*** object, which will be the component controller configuration.

The basic configuration required is as follows:

```typescript
export interface InitOperationConfiguration {
    type: SdkOperationType;
    steps?: string[];
    customerId: string;
}
```

### Advanced component configuration

All the fields that are part of this class are described below.

{% content-ref url="/pages/927144262d70be7548c816dd23cee42db3620f0a" %}
[Init Operation Configuration](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/extras/core/init-operation-configuracion.md)
{% endcontent-ref %}

***

### launchCloseSession <a href="#id-6-cierre-de-sesion" id="id-6-cierre-de-sesion"></a>

Before the application is destroyed, the SDK session must be closed to notify the platform that it has ended. To do this, run the following code snippet:

```javascript
exports.launchCloseSession = function (cfg) {
    return new Promise((resolve, reject) => {
        var config = [];
        try {
            config = [{
                config: cfg
            }];
        } catch (e) {
            console.log(e);
        }

        exec(resolve, reject, 'SdkCore', 'launchCloseSession', config);
    });
};
```

***

### launchGetExtraData <a href="#id-7-metodo-extradata" id="id-7-metodo-extradata"></a>

The method *getExtraData* makes it possible to generate the identifiers required for an operation that must continue in the *Facephi Validation Service* (Backend). This typically occurs when, after obtaining the necessary information in the client's application, that information must be sent to a specific service for further validation or analysis. If the results of these processes need to be tracked on the Platform, it must be able to link the first part of the process, performed on the client, with the final part, performed by the service, since they are ultimately part of the same operation.

```javascript
exports.launchGetExtraData = function () {
    return new Promise((resolve, reject) => {
        var config = [];
        try {
            config = [];
        } catch (e) {
            console.log(e);
        }

        exec(resolve, reject, 'SdkCore', 'launchGetExtraData', config);
    });
};
```

## Launching IDV <a href="#lanzamiento-de-idv" id="lanzamiento-de-idv"></a>

The IDV process launches a flow configured on the platform using its ID (flowID). To do this, you need to call two methods: **launchInitFlow + launchStartFlow**.

### launchInitFlow

In this method, you set the required configuration: the ID of the flow configured on the platform (flowID) and the customer ID (customerID). See the code:

```dart
await facephi.plugins.sdkcore.launchInitFlow({
     "customerId": "cordova@facephi.com",
     "flow": "f40c098c-a878-4976-aef1-xxxxxxx"
})
```

To configure the flow controller, create a list of the controllers for the components that will participate in the process, allowing them to be initialized correctly. The order in which they are defined does not matter; the flow itself determines the order in which they are executed. For example:

* **setSelphiFlow**: Face Capture
* **setSelphidFlow**: Document capture

Code for launching:

```javascript
/* Results are received by implementing a listener */
setTimeout(function()
{
    if (typeof facephi.plugins.sdkcore !== "undefined")
    {
        facephi.plugins.sdkcore.startListeningTrackingEvents(
            (event) => {
                console.log('📡 startListeningTrackingEvents recibido:', event);
            },
            (err) => {
                console.error('❌ Error:', err);
            }
        );
        facephi.plugins.sdkcore.startListeningFlowEvents(
            (event) => {
                console.log('📡 startListeningFlowEvents recibido:', event);
            },
            (err) => {
                console.error('❌ Error:', err);
            }
        );
    }
}, 2000);

await facephi.plugins.sdkcore.launchInitFlow({
     "customerId": "cordova@facephi.com",
     "flow": "f40c098c-a878-4976-aef1-xxxxxxx"
 })
.then(
    async (result) =>
    {
        if (parseInt(result.finishStatus) == SdkMobileFinishStatus.Ok)
        {
            console.log("launchInitFlow result", result);
            await facephi.plugins.sdkselphid.setSelphidFlow()
            .then(
                (result) => { console.log("setSelphidFlow result", result); },
                (err) => console.log(err),
            );
            await facephi.plugins.sdkselphi.setSelphiFlow()
            .then(
                (result) => { console.log("setSelphiFlow result", result); },
                (err) => console.log(err),
            );
            await facephi.plugins.sdkselphi.setSignatureSelphiFlow()
            .then(
                (result) => { console.log("setSignatureSelphiFlow result", result); },
                (err) => console.log(err),
            );
            
            /* At the end of adding the flows, launchStartFlow is called (provided the previous methods do not fail) */
            await facephi.plugins.sdkcore.launchStartFlow()
            .then(
                (result) => { console.log("launchStartFlow result", result); },
                (err) => console.log(err),
            );
        }
    },
    (err) => console.log(err),
);
```

## Receiving the result <a href="#id-6-recepcion-del-resultado" id="id-6-recepcion-del-resultado"></a>

Launching ***ALL*** methods will return information in **CoreResult**format. A successful launch can be distinguished from an unsuccessful one:

<pre class="language-typescript"><code class="lang-typescript"><strong>export interface CoreResult {
</strong>    finishStatus: number;
    finishStatusDescription?: string;
    errorType: string;
    errorMessage?: string;
    data?: string;
}
</code></pre>

{% content-ref url="/pages/c2409d1f2884ad7ba323fd2108cc99568268a702" %}
[Core Result](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/extras/core/core-resultado.md)
{% endcontent-ref %}
