> 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/capacitor/componentes/componente-principal.md).

# Main component

The installation of the **Core** **Plugin** is mandatory, regardless of the products that need to be used and the use case that has been defined. It contains basic functionality for the operation of the SDK, as well as other cross-cutting functionality necessary for auxiliary plugins.

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

### Capacitor:

```bash
npm i @facephi/sdk-core-capacitor@<Version>
npm run build
npx cap sync
```

### 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 execute different functionalities:

<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>initSession</td><td>Main controller of the component, which is responsible for validating the licenses, among other things.</td></tr><tr><td>initOperation</td><td>Method responsible for generating a new operation. Its ID is retrieved in the result object, data parameter.</td></tr><tr><td>getExtraData</td><td>The getExtraData method allows generating the identifiers necessary for an operation that must continue in the <em>Facephi Validation Service</em> (Backend).</td></tr><tr><td>closeSession</td><td>Before the application is destroyed, the SDK session must be closed to notify the platform of its completion.</td></tr></tbody></table>

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

Before any component can be used, the SDK session must be initialized. This initialization should be done as soon as possible, preferably at the start of the application. At the same time, once all operations with the SDK Mobile are finished, the session must also be closed.

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

The new licensing method allows licenses to be managed transparently for the integrator. The License can be injected in two ways:

* a. Obtaining the License through a service via a URL and API-KEY
* b. Injecting the License directly as String

In both cases, the result will be returned via a Promise, which contains an object of the class **CoreResult**.

```javascript
initSession(configuration: InitSessionConfiguration): Promise<CoreResult>;
```

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

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

The basic configuration needed for this is as follows:

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

### Advanced component configuration

Below are all the fields that are part of this class.

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

***

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

When starting a process or flow, **always** the call to the launchInitOperation method must be made

```javascript
initOperation(configuration: InitOperationConfiguration): Promise<CoreResult>;
```

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

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

The basic configuration needed for this is as follows:

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

### Advanced component configuration

Below are all the fields that are part of this class.

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

***

### closeSession <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 of its completion. To do this, the following code snippet is executed:

```javascript
closeSession(): Promise<CoreResult>;
```

***

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

The getExtraData method allows generating the identifiers necessary for an operation that must continue in the *Facephi Validation Service* (Backend). This situation usually occurs in cases where, once the necessary information has been obtained in the client's application, that information must be sent to a specific service for later validation or analysis. If the results of those processes need to be tracked on the Platform, it must be able to unify the first part of the process carried out on the client with the last part carried out in the service, since in the end they are part of the same operation.

```javascript
getExtraData(): Promise<CoreResult>;
```

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

The IDV process launches a flow configured on the platform from its ID (flowID). For this, two methods will need to be invoked: **initFlow + startFlow**.

### launchInitFlow

In this method, the necessary configuration will be set. The ID of the flow configured on the platform (flowID) and the client ID (customerID). See code:

```dart
initFlow = async (): Promise<CoreResult> => 
{
  const widgetConfig: InitFlowConfiguration = {
    flow: "f40c098c-a878-4976-aef1-xxxxxxx",
    customerId: CUSTOMER_ID
  };
  return SdkCore.initFlow(widgetConfig);
};
```

```typescript
startFlow = async (): Promise<CoreResult> => 
{
  console.log('Launching startFlow...');
  return SdkCore.startFlow();
};
```

To configure the flow controller, a list of the controllers of the components that will take part in the process will be created, which allows them to be initialized correctly. The order in which they are defined is not important; the flow itself will indicate the order in which they will be executed. For example:

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

Code for launching:

```javascript
/* Results are listened to by implementing an addListener, with the key 'core.flow' */
listener: any = SdkCore.addListener('core.flow', (response: any) => 
{
  console.log("core.flow:", response);
});

await this.coreService.initFlow().then(async (result: CoreResult) => 
{
  if (result.finishStatus == SdkFinishStatus.Ok)
  {
    await this.selphiFaceService.setSelphiFlow()
      .then((res: SelphiFaceResult) => console.log("setSelphiFlow res", res))
      .catch((err) => console.log("setSelphiFlow err", err));
      
    await this.selphidService.setSelphidFlow()
      .then((res: SelphIDResult) => console.log("setSelphidFlow res", res))
      .catch((err) => console.log("setSelphidFlow err", err));


    await this.coreService.startFlow()
      .then((res: CoreResult) => console.log("startFlow res", res))
      .catch((err) => console.log("startFlow err", err));
  }
}, 
(err: any) => console.log(err));
```

## Result reception <a href="#id-6-recepcion-del-resultado" id="id-6-recepcion-del-resultado"></a>

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

```dart
export interface CoreResult {
    finishStatus: number;
    finishStatusDescription?: string;
    errorType: string;
    errorMessage?: string;
    data?: string;
}
```

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