Skip to content

feat: merge processors #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7b47b8d
feat: created `FaceProcessor` to android
DanielAraldi Sep 12, 2023
a8b34ac
feat: added `uploadMessageIos` property to iOS
DanielAraldi Sep 12, 2023
3482f01
fix: changed error messages and added more one send event on close mo…
DanielAraldi Sep 12, 2023
6d35b51
feat: removed `Processors`, upgraded types and documentation
DanielAraldi Sep 12, 2023
75bd3fb
fix: small adjusts on `hasProperty` method when map contains no key-v…
DanielAraldi Sep 12, 2023
45d3384
fix: small adjusts in compare enum and key value that returned `false`
DanielAraldi Sep 12, 2023
f1bd9c2
fix: added if conditional to check if is flow enroll to set external …
DanielAraldi Sep 12, 2023
0c0c275
fix: removed `photoIdScan` method references
DanielAraldi Sep 12, 2023
31c13de
feat: added default value to custom comments and rename `principalKey…
DanielAraldi Sep 12, 2023
c84a53b
feat: starting merge processors on ios
bruno-fialho Sep 12, 2023
985dba2
fix: small adjusts in code iOS
DanielAraldi Sep 12, 2023
f319cb0
feat: changed name from external database ref id from iOS and Android
DanielAraldi Sep 12, 2023
ace955a
fix: created `getUploadMessage` method and used the `FaceConfig` meth…
DanielAraldi Sep 12, 2023
25a766c
chore: upgraded documentation
DanielAraldi Sep 13, 2023
77f2ca0
chore: refactored messages in Android
DanielAraldi Sep 13, 2023
853851b
chore: more informations to documentation about authentication flow
DanielAraldi Sep 13, 2023
831bb9b
fix: resolved problem with sent `externalDatabaseRefID` and merged `P…
DanielAraldi Sep 13, 2023
b08ebed
fix: statusBarStyle
bruno-fialho Sep 13, 2023
6f20c24
feat: created convert to rgb color to hexadecimal color helper
DanielAraldi Sep 14, 2023
8404e07
chore: add `no-bitwise`eslint rule
DanielAraldi Sep 14, 2023
274c158
feat: created format hexadecimal colors helper
DanielAraldi Sep 14, 2023
e843807
feat: created convert to rgba color to hexadecimal color helper
DanielAraldi Sep 14, 2023
7fb7866
fix: a small adjusts when rgba color is dark
DanielAraldi Sep 14, 2023
3ab9697
feat: created convert to hsl color to hexadecimal color helper
DanielAraldi Sep 14, 2023
b21d249
feat: created convert to hsla color to hexadecimal color helper
DanielAraldi Sep 14, 2023
1e97dc3
chore: small refactor in hsl functions
DanielAraldi Sep 14, 2023
ba990ad
chore: refactoring convert color functions
DanielAraldi Sep 14, 2023
386a17f
feat: created `convertToHexColor` function to manager colors
DanielAraldi Sep 14, 2023
b066959
chore: added custom comments
DanielAraldi Sep 15, 2023
32c7863
fix: small adjusts in hexadecimal regex
DanielAraldi Sep 15, 2023
3c558a1
chore: created unit test to colors helpers
DanielAraldi Sep 15, 2023
409d9f7
chore: added jest clear cache command
DanielAraldi Sep 15, 2023
a678a2f
fix: types and exports
bruno-fialho Sep 15, 2023
5b43412
fix: small adjusts in hexadecimal colors in documentation
DanielAraldi Sep 15, 2023
8afc406
feat: added `convertToHexColor` to `setTheme` method
DanielAraldi Sep 15, 2023
e4968bd
fix: update app.tsx
bruno-fialho Sep 15, 2023
f197674
fix: added convert theme properties to hexadecimal colores and small …
DanielAraldi Sep 15, 2023
9494856
Merge branch 'feat/merge-processors' of https://github.com/capitual/r…
DanielAraldi Sep 15, 2023
48115cd
chore: remove unnecessaries code block in `setTheme` method
DanielAraldi Sep 15, 2023
01f9cf1
fix: resolving format problem with hexadecimal color with alpha value it
DanielAraldi Sep 15, 2023
fbb3277
chore: move `handleTheme` method to end of the `initilizeSdk`
DanielAraldi Sep 15, 2023
ae4e22b
chore: changed `equals` to `equalsIgnoreCase` in conditions
DanielAraldi Sep 15, 2023
76c306f
chore: added real values in test colors
DanielAraldi Sep 15, 2023
80c3e48
fix: adjusts on alpha value of the color in iOS
DanielAraldi Sep 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions NATIVE_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@

## Introduction

- [Let's go talk about colors](#lets-go-talk-about-colors-🧑‍🎨)
- [Enabling Camera](#enabling-camera-ios-only)
- [Contributing](#contributing)
- [License](#license)

<hr />

## Let's go talk about colors 🧑‍🎨

Our SDK has support for some format of the hexadecimal colors and some colors name, but not all.

- **Android**: Support for some hexadecimal colors between **six** and **eight** characters and some colors name. We have support only these colors because we use `parseColor` method in our native module Java. It doesn't support others colors types like RGB, RGBA, HSL and HSLA, [click here to learn more about `parseColor`](<https://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)>). If you have some suggestions to improve it, thank you very much.

- **iOS**: Support for hexadecimal colors only. We have support for this color because we use `UIColor` method in our native module Swift, when we call it in your constructor we provided only hexadecimal `strings`. We didn't find another way per hour to support others colors. If you have some suggestions to improve it, thank you very much.

<hr />

## Enabling Camera (iOS only)

If you want to enable the camera, you need to add the following instructions in your `Info.plist` file:
Expand Down
416 changes: 219 additions & 197 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions android/src/main/java/com/capitual/processors/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import okhttp3.Request;

public class Config {
private static final ThemeUtils CapThemeUtils = new ThemeUtils();
public static String DeviceKeyIdentifier;
public static String BaseURL;
public static String PublicFaceScanEncryptionKey;
public static String ProductionKeyText;
public static ReadableMap Theme;
public static ReadableMap RequestHeaders;
private static final ThemeUtils CapThemeUtils = new ThemeUtils();

private static Map<String, String> parseReadableMapToMap() {
Map<String, String> headers = new HashMap<String, String>();
Expand All @@ -42,7 +42,7 @@ private static Headers parseHeadersMapToHeaders(Map<String, String> headersMap,
.header("X-Device-Key", DeviceKeyIdentifier)
.header("X-User-Agent", FaceTecSDK.createFaceTecAPIUserAgentString(""));

if (!httpMethod.equals("GET")) {
if (!httpMethod.equalsIgnoreCase("GET")) {
buildHeader = buildHeader.header("Content-Type", "application/json");
}

Expand Down

This file was deleted.

80 changes: 80 additions & 0 deletions android/src/main/java/com/capitual/processors/FaceConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.capitual.processors;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.ReadableMap;

import java.util.Map;

public class FaceConfig {
private final Map config;

public FaceConfig(ReadableMap config) {
this.config = config.toHashMap();
}

private boolean hasProperty(String key) {
if (this.config == null) {
return false;
}

return !this.config.isEmpty() || this.config.containsKey(key);
}

private String getValue(String key) {
return this.hasProperty(key) ? this.config.get(key).toString() : null;
}

public boolean isWhichFlow(@NonNull KeyFaceProcessor keyFlow, String key) {
return keyFlow.toString().equalsIgnoreCase(key);
}

public String getKey() {
if (this.hasProperty("key")) {
final String key = this.getValue("key");
final boolean isAuthenticate = this.isWhichFlow(KeyFaceProcessor.authenticateMessage, key);
final boolean isEnroll = this.isWhichFlow(KeyFaceProcessor.enrollMessage, key);
final boolean isLiveness = this.isWhichFlow(KeyFaceProcessor.livenessMessage, key);
final boolean isValidKey = isAuthenticate || isEnroll || isLiveness;
if (isValidKey) {
return key;
}
}
return null;
}

public String getEndpoint() {
return this.hasProperty("endpoint") ? this.getValue("endpoint") : null;
}

public String getSuccessMessage() {
final String key = this.getKey();
if (key != null) {
final boolean isAuthenticate = this.isWhichFlow(KeyFaceProcessor.authenticateMessage, key);
final String defaultMessage = isAuthenticate ? "Authenticated" : "Liveness\nConfirmed";
if (this.hasProperty("successMessage")) {
return this.getValue("successMessage");
}
return defaultMessage;
}
return null;
}

public boolean getHasExternalDatabaseRefID() {
final String key = this.getKey();
if (key != null) {
final boolean isLiveness = this.isWhichFlow(KeyFaceProcessor.livenessMessage, key);
if (isLiveness) {
return false;
}
if (this.hasProperty("hasExternalDatabaseRefID")) {
return this.getValue("hasExternalDatabaseRefID").equalsIgnoreCase("true");
}
}
return false;
}

public Map getParameters() {
return hasProperty("parameters") ? (Map) this.config.get("parameters") : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.capitual.processors;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

Expand All @@ -14,26 +13,27 @@
import org.json.JSONObject;

import java.io.IOException;
import java.util.Map;

import com.capitual.processors.helpers.ThemeUtils;
import com.capitual.reactnativecapfacesdk.ReactNativeCapfaceSdkModule;
import com.facebook.react.bridge.ReadableMap;
import com.facetec.sdk.*;

public class AuthenticateProcessor extends Processor implements FaceTecFaceScanProcessor {
private boolean success = false;
private final String principalKey = "authenticateMessage";
public class FaceProcessor extends Processor implements FaceTecFaceScanProcessor {
private final String key;
private final ReactNativeCapfaceSdkModule capFaceModule;
private final ReadableMap data;
private final FaceConfig faceConfig;
private final ThemeUtils capThemeUtils = new ThemeUtils();
private boolean success = false;

public AuthenticateProcessor(String sessionToken, Context context, ReactNativeCapfaceSdkModule capFaceModule,
ReadableMap data) {
public FaceProcessor(String sessionToken, Context context, ReactNativeCapfaceSdkModule capFaceModule,
FaceConfig faceConfig) {
this.capFaceModule = capFaceModule;
this.data = data;
this.faceConfig = faceConfig;
this.key = faceConfig.getKey();

capFaceModule.sendEvent("onCloseModal", true);
FaceTecSessionActivity.createAndLaunchSession(context, AuthenticateProcessor.this, sessionToken);
FaceTecSessionActivity.createAndLaunchSession(context, FaceProcessor.this, sessionToken);
}

public void processSessionWhileFaceTecSDKWaits(final FaceTecSessionResult sessionResult,
Expand All @@ -50,23 +50,28 @@ public void processSessionWhileFaceTecSDKWaits(final FaceTecSessionResult sessio

JSONObject parameters = new JSONObject();
try {
if (this.data != null) {
parameters.put("data", new JSONObject(this.data.toHashMap()));
final Map extraParameters = this.faceConfig.getParameters();
if (extraParameters != null) {
parameters.put("data", new JSONObject(extraParameters));
}
parameters.put("faceScan", sessionResult.getFaceScanBase64());
parameters.put("auditTrailImage", sessionResult.getAuditTrailCompressedBase64()[0]);
parameters.put("lowQualityAuditTrailImage", sessionResult.getLowQualityAuditTrailCompressedBase64()[0]);
parameters.put("externalDatabaseRefID", capFaceModule.getLatestExternalDatabaseRefID());

final boolean hasExternalDatabaseRefID = this.faceConfig.getHasExternalDatabaseRefID();
if (hasExternalDatabaseRefID) {
parameters.put("externalDatabaseRefID", capFaceModule.getLatestExternalDatabaseRefID());
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("Capitual - JSON", "Exception raised while attempting to create JSON payload for upload.");
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Exception raised while attempting to create JSON payload for upload.",
"JSONError");
}

final String endpoint = this.faceConfig.getEndpoint();
okhttp3.Request request = new okhttp3.Request.Builder()
.url(Config.BaseURL + "/match-3d-3d")
.url(Config.BaseURL + endpoint)
.headers(Config.getHeaders("POST"))
.post(new ProgressRequestBody(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), parameters.toString()),
Expand All @@ -90,8 +95,9 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
String scanResultBlob = responseJSON.getString("scanResultBlob");

if (wasProcessed) {
final String message = faceConfig.getSuccessMessage();
FaceTecCustomization.overrideResultScreenSuccessMessage = capThemeUtils
.handleMessage(principalKey, "successMessage", "Authenticated");
.handleMessage(key, "successMessage", message);
success = faceScanResultCallback.proceedToNextStep(scanResultBlob);
if (success) {
capFaceModule.sendEvent("onCloseModal", false);
Expand All @@ -105,7 +111,6 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("Capitual - JSON", "Exception raised while attempting to parse JSON result.");
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Exception raised while attempting to parse JSON result.",
Expand All @@ -115,7 +120,6 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t

@Override
public void onFailure(@NonNull Call call, IOException e) {
Log.d("Capitual - HTTPS", "Exception raised while attempting HTTPS call.");
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Exception raised while attempting HTTPS call.", "HTTPSError");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.capitual.processors;

public enum KeyFaceProcessor {
livenessMessage,
authenticateMessage,
enrollMessage,
}
Loading