Skip to content

Commit

Permalink
Merge pull request #149 from getyoti/release-3.9.0
Browse files Browse the repository at this point in the history
Release 3.9.0
  • Loading branch information
davidgrayston authored Mar 19, 2020
2 parents 236506a + db8ec4d commit 0215623
Show file tree
Hide file tree
Showing 159 changed files with 6,113 additions and 1,777 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ tests
coverage
.scannerwork
sonar-project.properties
.travis.yml
.travis.yml
.dependabot
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ jobs:
- cd ./examples/profile
- npm update
- npm run lint
- name: Doc Scan
node_js: "10"
script:
- cd ./examples/doc-scan
- npm install
- npm run lint
- stage: Coverage
name: Coveralls
if: type = pull_request OR branch = master
Expand Down
22 changes: 4 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,24 +313,10 @@ yotiClient.performAmlCheck(amlProfile).then((amlResult) => {

## Running the Examples

### Fetching the profile

The example can be found [here](examples/profile).
1. From the [Yoti Hub](https://hub.yoti.com) set the application domain of your app to `localhost:9443`
1. Set the scenario callback URL to `/profile`
1. Rename the [.env.example](examples/profile/.env.example) file to `.env` and fill in the required configuration values
1. Install the dependencies with `npm install`
1. Start the server `node index.js`

Visiting the `https://localhost:9443` should show a Yoti Connect button

### Performing an AML check

The example can be found [here](examples/aml-check).

* rename the [.env.example](examples/aml-check/.env.example) file to `.env` and fill in the required configuration values
* install the dependencies with `npm install`
* run the script with `node aml.js` or `node aml-usa.js`
### Follow instructions in the README for each example:
* [Profile](examples/profile)
* [AML](examples/aml-check)
* [Doc Scan](examples/doc-scan)

## API Coverage

Expand Down
5 changes: 4 additions & 1 deletion config/yoti.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

const constants = require('../src/yoti_common/constants');

const yoti = {
connectApi: process.env.YOTI_CONNECT_API || 'https://api.yoti.com/api/v1',
connectApi: process.env.YOTI_CONNECT_API || `${constants.API_BASE_URL}/api/v1`,
docScanApi: process.env.YOTI_DOC_SCAN_API || `${constants.API_BASE_URL}/idverify/v1`,
};

module.exports = yoti;
7 changes: 7 additions & 0 deletions examples/aml-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# AML Example

## Performing an AML check

1. Rename the [.env.example](.env.example) file to `.env` and fill in the required configuration values
1. Install the dependencies with `npm install`
1. Run the script with `node aml.js` or `node aml-usa.js`
8 changes: 8 additions & 0 deletions examples/doc-scan/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Required configuration.
# The client SDK ID and PEM file for your application are generated on https://hub.yoti.com.
YOTI_CLIENT_SDK_ID=
YOTI_KEY_FILE_PATH=

# Optional configuration.
YOTI_DOC_SCAN_IFRAME_URL=
YOTI_DOC_SCAN_API=
18 changes: 18 additions & 0 deletions examples/doc-scan/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
"plugins": ["node"],
"extends": ["plugin:node/recommended", "airbnb-base"],
rules: {
"no-console": 0,
"comma-dangle": ["error", {
"arrays": "always-multiline",
"exports": "always-multiline",
"functions": "never",
"imports": "always-multiline",
"objects": "always-multiline"
}],
"function-paren-newline": ["error", "multiline-arguments"],
},
env: {
"node": true
}
};
3 changes: 3 additions & 0 deletions examples/doc-scan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
/keys
package-lock.json
8 changes: 8 additions & 0 deletions examples/doc-scan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Doc Scan Example

## Running the example

1. Rename the [.env.example](.env.example) file to `.env` and fill in the required configuration values
1. Install the dependencies with `npm install`
1. Start the server `npm start`
1. Visit `https://localhost:3000`
8 changes: 8 additions & 0 deletions examples/doc-scan/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require('fs');

module.exports = {
YOTI_CLIENT_SDK_ID: process.env.YOTI_CLIENT_SDK_ID,
YOTI_PEM: fs.readFileSync(process.env.YOTI_KEY_FILE_PATH),
YOTI_DOC_SCAN_IFRAME_URL: process.env.YOTI_DOC_SCAN_IFRAME_URL || 'https://api.yoti.com/idverify/v1/web/index.html',
YOTI_APP_BASE_URL: process.env.YOTI_APP_BASE_URL || 'http://localhost:3000',
};
37 changes: 37 additions & 0 deletions examples/doc-scan/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require('dotenv').config();

const express = require('express');
const https = require('https');
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const session = require('express-session');
const controllers = require('./src/controllers');

const app = express();
const port = process.env.PORT || 3000;

app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/static', express.static('static'));
app.use(session({
secret: 'some-secret',
resave: false,
saveUninitialized: true,
}));

const router = express.Router();

router.get('/', controllers.indexController);
router.get('/success', controllers.successController);
router.get('/media', controllers.mediaController);

app.use('/', router);

https.createServer({
key: fs.readFileSync(path.join(__dirname, '../keys', 'server-key.pem')),
cert: fs.readFileSync(path.join(__dirname, '../keys', 'server-cert.pem')),
}, app).listen(port);

console.log(`Server running on https://localhost:${port}`);
28 changes: 28 additions & 0 deletions examples/doc-scan/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "yoti-node-sdk-doc-scan-demo",
"description": "A Yoti Doc Scan Demo",
"private": true,
"license": "MIT",
"engines": {
"node": ">=10"
},
"scripts": {
"start": "node index.js",
"lint": "node_modules/.bin/eslint *.js src/*/**.js"
},
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"ejs": "^3.0.1",
"express": "^4.17.1",
"express-session": "^1.17.0",
"file-type": "^14.1.4",
"yoti": "file:../.."
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-node": "^6.0.1"
}
}
75 changes: 75 additions & 0 deletions examples/doc-scan/src/controllers/index.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const config = require('../../config');

const {
DocScanClient,
SessionSpecificationBuilder,
RequestedDocumentAuthenticityCheckBuilder,
RequestedLivenessCheckBuilder,
RequestedTextExtractionTaskBuilder,
RequestedFaceMatchCheckBuilder,
SdkConfigBuilder,
} = require('yoti');

/**
* Create a Doc Scan session.
*/
async function createSession() {
const docScanClient = new DocScanClient(
config.YOTI_CLIENT_SDK_ID,
config.YOTI_PEM
);

const sessionSpec = new SessionSpecificationBuilder()
.withClientSessionTokenTtl(600)
.withResourcesTtl(90000)
.withUserTrackingId('some-user-tracking-id')
.withRequestedCheck(
new RequestedDocumentAuthenticityCheckBuilder()
.build()
)
.withRequestedCheck(
new RequestedLivenessCheckBuilder()
.forZoomLiveness()
.build()
)
.withRequestedCheck(
new RequestedFaceMatchCheckBuilder()
.withManualCheckFallback()
.build()
)
.withRequestedTask(
new RequestedTextExtractionTaskBuilder()
.withManualCheckAlways()
.build()
)
.withSdkConfig(
new SdkConfigBuilder()
.withAllowsCameraAndUpload()
.withPrimaryColour('#2d9fff')
.withSecondaryColour('#FFFFFF')
.withFontColour('#FFFFFF')
.withLocale('en-GB')
.withPresetIssuingCountry('GBR')
.withSuccessUrl(`${config.YOTI_APP_BASE_URL}/success`)
.withErrorUrl(`${config.YOTI_APP_BASE_URL}/error`)
.build()
)
.build();

return docScanClient.createSession(sessionSpec);
}

module.exports = async (req, res) => {
try {
const session = await createSession();

req.session.DOC_SCAN_SESSION_ID = session.getSessionId();
req.session.DOC_SCAN_SESSION_TOKEN = session.getClientSessionToken();

res.render('pages/index', {
iframeUrl: `${config.YOTI_DOC_SCAN_IFRAME_URL}?sessionID=${req.session.DOC_SCAN_SESSION_ID}&sessionToken=${req.session.DOC_SCAN_SESSION_TOKEN}`,
});
} catch (error) {
res.render('pages/error', { error });
}
};
9 changes: 9 additions & 0 deletions examples/doc-scan/src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const indexController = require('./index.controller');
const successController = require('./success.controller');
const mediaController = require('./media.controller');

module.exports = {
indexController,
successController,
mediaController,
};
35 changes: 35 additions & 0 deletions examples/doc-scan/src/controllers/media.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const config = require('../../config');
const FileType = require('file-type');

const {
DocScanClient,
} = require('yoti');

module.exports = async (req, res) => {
const docScanClient = new DocScanClient(
config.YOTI_CLIENT_SDK_ID,
config.YOTI_PEM
);

try {
const media = await docScanClient.getMediaContent(
req.session.DOC_SCAN_SESSION_ID,
req.query.mediaId
);

let contentType = media.getMimeType();
let buffer = media.getContent().toBuffer();

// If the media is base64 encoded, decode and detect the mime type.
if (req.query.base64 === '1' && contentType === 'application/octet-stream') {
buffer = Buffer.from(buffer.toString('utf8'), 'base64');
const fileInfo = await FileType.fromBuffer(buffer);
contentType = fileInfo.mime || contentType;
}

res.set('Content-Type', contentType);
res.status(200).end(buffer);
} catch (error) {
res.render('pages/error', { error });
}
};
19 changes: 19 additions & 0 deletions examples/doc-scan/src/controllers/success.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const config = require('../../config');

const {
DocScanClient,
} = require('yoti');

module.exports = async (req, res) => {
const docScanClient = new DocScanClient(
config.YOTI_CLIENT_SDK_ID,
config.YOTI_PEM
);

try {
const sessionResult = await docScanClient.getSession(req.session.DOC_SCAN_SESSION_ID);
res.render('pages/success', { sessionResult });
} catch (error) {
res.render('pages/error', { error });
}
};
Binary file added examples/doc-scan/static/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/doc-scan/static/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions examples/doc-scan/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

body {
padding-top: 4.5rem;
}

table td:first-child {
width: 30%;
}
9 changes: 9 additions & 0 deletions examples/doc-scan/views/pages/error.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%- include('layout/header'); -%>
<div class="container">
<div class="row pt-4">
<div class="col">
<p class="alert alert-danger"><%= error %></p>
</div>
</div>
</div>
<%- include('layout/footer'); -%>
3 changes: 3 additions & 0 deletions examples/doc-scan/views/pages/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- include('layout/header'); -%>
<iframe style="border:none;" width="100%" height="750" allow="camera" src="<%= iframeUrl %>"></iframe>
<%- include('layout/footer'); -%>
13 changes: 13 additions & 0 deletions examples/doc-scan/views/pages/layout/footer.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>

</body>

</html>
18 changes: 18 additions & 0 deletions examples/doc-scan/views/pages/layout/header.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>

<head>
<title>Yoti Doc Scan</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="/static/style.css">
<link rel="icon" type="image/png" href="/static/images/favicon.png" />
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<a href="/" class="navbar-brand">
<img src="/static/images/logo.svg" height="30" class="d-inline-block align-top mr-2">
Doc Scan
</a>
</nav>
Loading

0 comments on commit 0215623

Please sign in to comment.