@rebilly/risk-data-collector 2.0.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -8
- package/cypress/integration/data-collector.spec.js +68 -7
- package/cypress/test-data/index.js +33 -0
- package/cypress.json +4 -1
- package/dist/data-collector.js +1 -1
- package/dist/data-collector.min.js +1 -1
- package/dist/data-collector.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-collector.js +38 -11
- package/src/kount.js +52 -0
- package/cypress/fixtures/example.json +0 -5
- package/cypress/plugins/index.js +0 -22
- package/cypress/support/commands.js +0 -25
- package/cypress/support/index.js +0 -20
package/package.json
CHANGED
package/src/data-collector.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import fingerprinter from './fingerprint';
|
|
3
|
+
import kount from './kount';
|
|
2
4
|
|
|
3
|
-
async function collectDataHelper(
|
|
5
|
+
async function collectDataHelper({
|
|
6
|
+
env = null,
|
|
7
|
+
screen,
|
|
8
|
+
navigator,
|
|
9
|
+
kountAccountId = null,
|
|
10
|
+
kountSessionId = null,
|
|
11
|
+
getFingerprint,
|
|
12
|
+
getFraudSessionId,
|
|
13
|
+
}) {
|
|
4
14
|
const {
|
|
5
15
|
colorDepth,
|
|
6
16
|
height: screenHeight,
|
|
@@ -11,25 +21,30 @@ async function collectDataHelper(screen, navigator, fingerprinter) {
|
|
|
11
21
|
language,
|
|
12
22
|
} = navigator || {};
|
|
13
23
|
let fingerprint;
|
|
24
|
+
let kountFraudSessionId;
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.error(e);
|
|
26
|
+
try {
|
|
27
|
+
fingerprint = await getFingerprint();
|
|
28
|
+
|
|
29
|
+
if (kountAccountId) {
|
|
30
|
+
kountFraudSessionId = await getFraudSessionId({ env, kountAccountId, kountSessionId });
|
|
21
31
|
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(e);
|
|
22
34
|
}
|
|
23
35
|
|
|
24
36
|
const data = {
|
|
25
37
|
riskMetadata: {
|
|
26
38
|
fingerprint: fingerprint || null,
|
|
39
|
+
extraData: {
|
|
40
|
+
kountFraudSessionId: kountFraudSessionId || null,
|
|
41
|
+
},
|
|
27
42
|
browserData: {
|
|
28
43
|
colorDepth: colorDepth || null,
|
|
29
44
|
isJavaEnabled: javaEnabled ? javaEnabled.call(navigator) : null,
|
|
30
45
|
language: language || null,
|
|
31
|
-
screenWidth: screenWidth || null,
|
|
32
46
|
screenHeight: screenHeight || null,
|
|
47
|
+
screenWidth: screenWidth || null,
|
|
33
48
|
timeZoneOffset: (new Date()).getTimezoneOffset(),
|
|
34
49
|
},
|
|
35
50
|
},
|
|
@@ -38,8 +53,20 @@ async function collectDataHelper(screen, navigator, fingerprinter) {
|
|
|
38
53
|
return data;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
async function collectData(
|
|
42
|
-
|
|
56
|
+
async function collectData({
|
|
57
|
+
env = null,
|
|
58
|
+
kountAccountId = null,
|
|
59
|
+
kountSessionId = null,
|
|
60
|
+
} = {}) {
|
|
61
|
+
return collectDataHelper({
|
|
62
|
+
env,
|
|
63
|
+
screen,
|
|
64
|
+
navigator,
|
|
65
|
+
kountAccountId,
|
|
66
|
+
kountSessionId,
|
|
67
|
+
getFingerprint: fingerprinter,
|
|
68
|
+
getFraudSessionId: kount,
|
|
69
|
+
});
|
|
43
70
|
}
|
|
44
71
|
|
|
45
72
|
export { collectData, collectDataHelper };
|
package/src/kount.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
const sandboxDataCollectorUrl = 'https://tst.kaptcha.com';
|
|
3
|
+
const prodDataCollectorUrl = 'https://ssl.kaptcha.com';
|
|
4
|
+
|
|
5
|
+
const isProd = (env) => env === 'production';
|
|
6
|
+
|
|
7
|
+
const addKountScriptElement = ({
|
|
8
|
+
env,
|
|
9
|
+
kountAccountId,
|
|
10
|
+
kountSessionId,
|
|
11
|
+
}) => {
|
|
12
|
+
const baseUrl = isProd(env) ? prodDataCollectorUrl : sandboxDataCollectorUrl;
|
|
13
|
+
const kountScriptUrl = new URL(`${baseUrl}/collect/sdk`);
|
|
14
|
+
kountScriptUrl.searchParams.append('m', kountAccountId);
|
|
15
|
+
if (kountSessionId) {
|
|
16
|
+
kountScriptUrl.searchParams.append('m', kountSessionId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const kountScript = document.createElement('script');
|
|
20
|
+
kountScript.setAttribute('class', 'kaxsdc');
|
|
21
|
+
kountScript.setAttribute('data-event', 'load');
|
|
22
|
+
kountScript.setAttribute('type', 'text/javascript');
|
|
23
|
+
kountScript.setAttribute('src', kountScriptUrl.href);
|
|
24
|
+
|
|
25
|
+
document.body.append(kountScript);
|
|
26
|
+
|
|
27
|
+
return kountScript;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default async function getFraudSessionId({ env, kountAccountId, kountSessionId }) {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const kountScript = addKountScriptElement({
|
|
33
|
+
env,
|
|
34
|
+
kountAccountId,
|
|
35
|
+
kountSessionId,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
kountScript.onload = () => {
|
|
39
|
+
const client = new ka.ClientSDK();
|
|
40
|
+
client.setupCallback({
|
|
41
|
+
'collect-begin': (params) => {
|
|
42
|
+
const { MercSessId } = params;
|
|
43
|
+
resolve(MercSessId);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
client.autoLoadEvents();
|
|
47
|
+
};
|
|
48
|
+
kountScript.onerror = () => {
|
|
49
|
+
reject(new Error('Error attempting to mount Kount script'));
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
package/cypress/plugins/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
// / <reference types="cypress" />
|
|
3
|
-
// ***********************************************************
|
|
4
|
-
// This example plugins/index.js can be used to load plugins
|
|
5
|
-
//
|
|
6
|
-
// You can change the location of this file or turn off loading
|
|
7
|
-
// the plugins file with the 'pluginsFile' configuration option.
|
|
8
|
-
//
|
|
9
|
-
// You can read more here:
|
|
10
|
-
// https://on.cypress.io/plugins-guide
|
|
11
|
-
// ***********************************************************
|
|
12
|
-
|
|
13
|
-
// This function is called when a project is opened or re-opened (e.g. due to
|
|
14
|
-
// the project's config changing)
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @type {Cypress.PluginConfig}
|
|
18
|
-
*/
|
|
19
|
-
module.exports = (on, config) => {
|
|
20
|
-
// `on` is used to hook into various events Cypress emits
|
|
21
|
-
// `config` is the resolved Cypress config
|
|
22
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// ***********************************************
|
|
2
|
-
// This example commands.js shows you how to
|
|
3
|
-
// create various custom commands and overwrite
|
|
4
|
-
// existing commands.
|
|
5
|
-
//
|
|
6
|
-
// For more comprehensive examples of custom
|
|
7
|
-
// commands please read more here:
|
|
8
|
-
// https://on.cypress.io/custom-commands
|
|
9
|
-
// ***********************************************
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// -- This is a parent command --
|
|
13
|
-
// Cypress.Commands.add("login", (email, password) => { ... })
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// -- This is a child command --
|
|
17
|
-
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// -- This is a dual command --
|
|
21
|
-
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
// -- This will overwrite an existing command --
|
|
25
|
-
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
package/cypress/support/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// ***********************************************************
|
|
2
|
-
// This example support/index.js is processed and
|
|
3
|
-
// loaded automatically before your test files.
|
|
4
|
-
//
|
|
5
|
-
// This is a great place to put global configuration and
|
|
6
|
-
// behavior that modifies Cypress.
|
|
7
|
-
//
|
|
8
|
-
// You can change the location of this file or turn off
|
|
9
|
-
// automatically serving support files with the
|
|
10
|
-
// 'supportFile' configuration option.
|
|
11
|
-
//
|
|
12
|
-
// You can read more here:
|
|
13
|
-
// https://on.cypress.io/configuration
|
|
14
|
-
// ***********************************************************
|
|
15
|
-
|
|
16
|
-
// Import commands.js using ES2015 syntax:
|
|
17
|
-
import './commands';
|
|
18
|
-
|
|
19
|
-
// Alternatively you can use CommonJS syntax:
|
|
20
|
-
// require('./commands')
|