Skip to content
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

SP-18172 - major improvement. Update FaceSDK constructor input types #116

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ If you have any problems with or questions about this client, please contact us
through a [GitHub issue](https://github.com/regulaforensics/FaceSDK-web-js-client/issues).
You are invited to contribute [new features, fixes, or updates](https://github.com/regulaforensics/FaceSDK-web-js-client/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22), large or small; We are always thrilled to receive pull requests, and do our best to process them as fast as we can. See [dev guide](./dev.md).

## Major Update: Constructor Now Accepts an Object
Starting with version 8.x.x, we have updated the input parameters for the declaration of the FaceSDK class. Now the input parameters are set only through the object (see the typing)

Old approach
```js

const sdk = new FaceSdk({ username: 'username' }, 'http://localhost:41101' );

```

New approach
```javascript
/** configuration and base path */
const sdk = new FaceSdk({
configuration: { username: 'username' },
basePath: 'http://localhost:41101'
});

/** only base path */
const sdk = new FaceSdk({
basePath: 'http://localhost:41101'
});

/** set base path via configuration */
const sdk = new FaceSdk({
configuration: { username: 'username', password: 'xxx', basePath: 'http://localhost:41101' },
});


```

## Install package

```
Expand Down
4 changes: 3 additions & 1 deletion examples/auth/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ async function get_authorization_token() {
const face1 = fs.readFileSync('face1.jpg').buffer;
const face2 = fs.readFileSync('face2.jpg').buffer;
const token = await get_authorization_token();
const sdk = new FaceSdk({ basePath: apiBasePath, baseOptions: { headers: { Authorization: `Bearer ${token}` } } });
const sdk = new FaceSdk({
configuration: { basePath: apiBasePath, baseOptions: { headers: { Authorization: `Bearer ${token}` } } },
});

const matchingResponse = await sdk.matchingApi.match({
tag: '1',
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class AppComponent {
private faceSdk: FaceSdk;
resultObject: any;
constructor() {
this.faceSdk = new FaceSdk(undefined, 'https://faceapi.regulaforensics.com');
this.faceSdk = new FaceSdk( {basePath: 'https://faceapi.regulaforensics.com'});
}
title = 'Face Sdk Web Client Example';

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/esm/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FaceSdk, ImageSource } from '@regulaforensics/facesdk-webclient';
import {FaceSdk, ImageSource} from '@regulaforensics/facesdk-webclient';
import fs from 'fs';

(async () => {
Expand Down
30 changes: 18 additions & 12 deletions src/ext/face-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BASE_PATH } from '../base';
import { Configuration } from '../configuration';
import { Configuration, ConfigurationParameters } from '../configuration';
import globalAxios, { AxiosInstance } from 'axios';
import { MatchingApi } from './matching-api';
import { GroupApi } from './group-api';
Expand All @@ -16,16 +16,22 @@ export class FaceSdk {
diagnosticsApi: DiagnosticsApi;
livenessApi: Liveness20Api;

constructor(
configuration?: Configuration,
protected basePath: string = BASE_PATH,
protected axios: AxiosInstance = globalAxios,
) {
this.matchingApi = new MatchingApi(configuration, basePath, axios);
this.groupApi = new GroupApi(configuration, basePath, axios);
this.personApi = new PersonApi(configuration, basePath, axios);
this.searchApi = new SearchApi(configuration, basePath, axios);
this.diagnosticsApi = new DiagnosticsApi(configuration, basePath, axios);
this.livenessApi = new Liveness20Api(configuration, basePath, axios);
constructor({
configuration,
basePath = BASE_PATH,
axios = globalAxios,
}: {
configuration?: ConfigurationParameters;
basePath?: string;
axios?: AxiosInstance;
}) {
const config = configuration ? new Configuration(configuration) : undefined;

this.matchingApi = new MatchingApi(config, basePath, axios);
this.groupApi = new GroupApi(config, basePath, axios);
this.personApi = new PersonApi(config, basePath, axios);
this.searchApi = new SearchApi(config, basePath, axios);
this.diagnosticsApi = new DiagnosticsApi(config, basePath, axios);
this.livenessApi = new Liveness20Api(config, basePath, axios);
}
}
Loading