fiftyone.devicedetection.shared 4.4.78 → 4.4.95

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.
@@ -20,15 +20,24 @@
20
20
  * such notice(s) shall fulfill the requirements of that article.
21
21
  * ********************************************************************* */
22
22
 
23
- /*
24
- This file is used for development package.
25
- */
23
+ class DataExtension {
24
+ // Helper function to read property values from flowData
25
+ static getValueHelper (elementData, propertyName) {
26
+ try {
27
+ const property = elementData[propertyName];
28
+ if (property && property.hasValue) {
29
+ if (Array.isArray(property.value)) {
30
+ return property.value.join(', ');
31
+ } else {
32
+ return property.value;
33
+ }
34
+ } else {
35
+ return `Unknown (${property.noValueMessage})`;
36
+ }
37
+ } catch (e) {
38
+ return `Unknown (${e})`;
39
+ }
40
+ };
41
+ }
26
42
 
27
- module.exports = {
28
- errorMessages: require('./errorMessages'),
29
- testConstants: require('./tests/testConstants'),
30
- keyUtils: require('./tests/keyUtils'),
31
- exampleConstants: require('./examples/exampleConstants'),
32
- optionsExtension: require('./examples/optionsExtension'),
33
- dataExtension: require('./examples/dataExtension')
34
- };
43
+ module.exports = DataExtension;
@@ -0,0 +1,59 @@
1
+ /* *********************************************************************
2
+ * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4
+ * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5
+ *
6
+ * This Original Work is licensed under the European Union Public Licence
7
+ * (EUPL) v.1.2 and is subject to its terms as set out below.
8
+ *
9
+ * If a copy of the EUPL was not distributed with this file, You can obtain
10
+ * one at https://opensource.org/licenses/EUPL-1.2.
11
+ *
12
+ * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13
+ * amended by the European Commission) shall be deemed incompatible for
14
+ * the purposes of the Work and the provisions of the compatibility
15
+ * clause in Article 5 of the EUPL shall not apply.
16
+ *
17
+ * If using the Work as, or as part of, a network application, by
18
+ * including the attribution notice(s) required under Article 5 of the EUPL
19
+ * in the end user terms of the application under an appropriate heading,
20
+ * such notice(s) shall fulfill the requirements of that article.
21
+ * ********************************************************************* */
22
+
23
+ module.exports = {
24
+ // This collection contains the various input values that will
25
+ // be used when running the examples.
26
+ defaultEvidenceValues: [
27
+ // A User-Agent from a mobile device.
28
+ new Map([
29
+ ['header.user-agent', 'Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-G960U) ' +
30
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' +
31
+ 'SamsungBrowser/10.1 Chrome/71.0.3578.99 Mobile ' +
32
+ 'Safari/537.36']
33
+ ]),
34
+ // A User-Agent from a desktop device.
35
+ new Map([
36
+ ['header.user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
37
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' +
38
+ 'Chrome/78.0.3904.108 Safari/537.36']
39
+ ]),
40
+ // Evidence values from a windows 11 device using a browser
41
+ // that supports User-Agent Client Hints.
42
+ new Map([
43
+ ['header.user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
44
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' +
45
+ 'Chrome/98.0.4758.102 Safari/537.36'],
46
+ ['header.sec-ch-ua-mobile', '?0'],
47
+ ['header.sec-ch-ua', '" Not A; Brand";v="99", "Chromium";v="98", ' +
48
+ '"Google Chrome";v="98"'],
49
+ ['header.sec-ch-ua-platform', '"Windows"'],
50
+ ['header.sec-ch-ua-platform-version', '"14.0.0"']
51
+ ])
52
+ ],
53
+ fileNames: {
54
+ enterpriseDataFileName: 'Enterprise-HashV41.hash',
55
+ liteDataFileName: '51Degrees-LiteV4.1.hash',
56
+ uaFileName: '20000 User Agents.csv',
57
+ evidenceFileName: '20000 Evidence Records.yml'
58
+ }
59
+ };
@@ -0,0 +1,95 @@
1
+ /* *********************************************************************
2
+ * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4
+ * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5
+ *
6
+ * This Original Work is licensed under the European Union Public Licence
7
+ * (EUPL) v.1.2 and is subject to its terms as set out below.
8
+ *
9
+ * If a copy of the EUPL was not distributed with this file, You can obtain
10
+ * one at https://opensource.org/licenses/EUPL-1.2.
11
+ *
12
+ * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13
+ * amended by the European Commission) shall be deemed incompatible for
14
+ * the purposes of the Work and the provisions of the compatibility
15
+ * clause in Article 5 of the EUPL shall not apply.
16
+ *
17
+ * If using the Work as, or as part of, a network application, by
18
+ * including the attribution notice(s) required under Article 5 of the EUPL
19
+ * in the end user terms of the application under an appropriate heading,
20
+ * such notice(s) shall fulfill the requirements of that article.
21
+ * ********************************************************************* */
22
+
23
+ const CLOUD_REQUEST_ENGINE_NAME = 'cloudRequestEngine';
24
+
25
+ const ONPREMISE_DEVICE_ENGINE = 'deviceDetectionOnPremise';
26
+
27
+ class OptionsExtension {
28
+ static getElement (options, elementName) {
29
+ if (options.PipelineOptions) {
30
+ if (options.PipelineOptions.Elements) {
31
+ for (const e of options.PipelineOptions.Elements) {
32
+ if (e.elementName &&
33
+ e.elementName.endsWith(elementName)) {
34
+ return e;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ static getDataFilePath (options) {
42
+ const cloudRequestElement = this.getElement(options, ONPREMISE_DEVICE_ENGINE);
43
+ if (cloudRequestElement &&
44
+ cloudRequestElement.elementParameters &&
45
+ cloudRequestElement.elementParameters.dataFilePath) {
46
+ return cloudRequestElement.elementParameters.dataFilePath;
47
+ }
48
+ }
49
+
50
+ static setDataFilePath (options, newDataFilePath) {
51
+ const cloudRequestElement = this.getElement(options, ONPREMISE_DEVICE_ENGINE);
52
+ if (cloudRequestElement) {
53
+ if (!cloudRequestElement.elementParameters) {
54
+ cloudRequestElement.elementParameters = { dataFilePath: newDataFilePath };
55
+ } else {
56
+ cloudRequestElement.elementParameters.dataFilePath = newDataFilePath;
57
+ }
58
+ }
59
+ }
60
+
61
+ static updateElementPath (options, appendDir) {
62
+ if (options.PipelineOptions) {
63
+ if (options.PipelineOptions.Elements) {
64
+ for (const e of options.PipelineOptions.Elements) {
65
+ if (e.elementName &&
66
+ e.elementName.startsWith('.')) {
67
+ e.elementName = appendDir + '/' + e.elementName;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ static getResourceKey (options) {
75
+ const cloudRequestElement = this.getElement(options, CLOUD_REQUEST_ENGINE_NAME);
76
+ if (cloudRequestElement &&
77
+ cloudRequestElement.elementParameters &&
78
+ cloudRequestElement.elementParameters.resourceKey) {
79
+ return cloudRequestElement.elementParameters.resourceKey;
80
+ }
81
+ }
82
+
83
+ static setResourceKey (options, resourceKey) {
84
+ const cloudRequestElement = this.getElement(options, CLOUD_REQUEST_ENGINE_NAME);
85
+ if (cloudRequestElement) {
86
+ if (!cloudRequestElement.elementParameters) {
87
+ cloudRequestElement.elementParameters = { resourceKey };
88
+ } else {
89
+ cloudRequestElement.elementParameters.resourceKey = resourceKey;
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ module.exports = OptionsExtension;
package/index.js CHANGED
@@ -1,29 +1,34 @@
1
- /* *********************************************************************
2
- * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
- * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4
- * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5
- *
6
- * This Original Work is licensed under the European Union Public Licence
7
- * (EUPL) v.1.2 and is subject to its terms as set out below.
8
- *
9
- * If a copy of the EUPL was not distributed with this file, You can obtain
10
- * one at https://opensource.org/licenses/EUPL-1.2.
11
- *
12
- * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13
- * amended by the European Commission) shall be deemed incompatible for
14
- * the purposes of the Work and the provisions of the compatibility
15
- * clause in Article 5 of the EUPL shall not apply.
16
- *
17
- * If using the Work as, or as part of, a network application, by
18
- * including the attribution notice(s) required under Article 5 of the EUPL
19
- * in the end user terms of the application under an appropriate heading,
20
- * such notice(s) shall fulfill the requirements of that article.
1
+ /* *********************************************************************
2
+ * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4
+ * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5
+ *
6
+ * This Original Work is licensed under the European Union Public Licence
7
+ * (EUPL) v.1.2 and is subject to its terms as set out below.
8
+ *
9
+ * If a copy of the EUPL was not distributed with this file, You can obtain
10
+ * one at https://opensource.org/licenses/EUPL-1.2.
11
+ *
12
+ * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13
+ * amended by the European Commission) shall be deemed incompatible for
14
+ * the purposes of the Work and the provisions of the compatibility
15
+ * clause in Article 5 of the EUPL shall not apply.
16
+ *
17
+ * If using the Work as, or as part of, a network application, by
18
+ * including the attribution notice(s) required under Article 5 of the EUPL
19
+ * in the end user terms of the application under an appropriate heading,
20
+ * such notice(s) shall fulfill the requirements of that article.
21
21
  * ********************************************************************* */
22
22
 
23
23
  /*
24
- This file is used for release package.
24
+ This file is used for development package.
25
25
  */
26
26
 
27
27
  module.exports = {
28
- errorMessages: require('./errorMessages')
28
+ errorMessages: require('./errorMessages'),
29
+ testConstants: require('./tests/testConstants'),
30
+ keyUtils: require('./tests/keyUtils'),
31
+ exampleConstants: require('./examples/exampleConstants'),
32
+ optionsExtension: require('./examples/optionsExtension'),
33
+ dataExtension: require('./examples/dataExtension')
29
34
  };
package/package.json CHANGED
@@ -1,31 +1,42 @@
1
1
  {
2
2
  "name": "fiftyone.devicedetection.shared",
3
- "version": "4.4.78",
3
+ "version": "4.4.95",
4
4
  "description": "Shared functionality for implementing device detection engine for the 51Degrees Pipeline API",
5
+ "keywords": [
6
+ "51degrees",
7
+ "device detection",
8
+ "user-agent",
9
+ "client hints",
10
+ "browser",
11
+ "os",
12
+ "device",
13
+ "cpu",
14
+ "mobile",
15
+ "phone",
16
+ "tablet",
17
+ "tv",
18
+ "bot",
19
+ "crawler",
20
+ "WURFL",
21
+ "DeviceAtlas"
22
+ ],
5
23
  "main": "index.js",
6
24
  "types": "types/index.d.ts",
7
25
  "repository": {
8
26
  "type": "git",
9
27
  "url": "https://github.com/51Degrees/device-detection-node"
10
28
  },
11
- "author": "51Degrees",
12
- "contributors": [
13
- "Filip Hnízdo <filip@octophin.com> (https://octophindigital.com/)",
14
- "Steve Ballantine <stephen@51degrees.com> (https://51degrees.com)",
15
- "Ben Shilito <ben@51degrees.com> (https://51degrees.com)",
16
- "Joseph Dix <joseph@51degrees.com> (https://51degrees.com)",
17
- "Tung Pham <tung@51degrees.com> (https://51degrees.com)"
18
- ],
29
+ "author": "51Degrees Engineering <engineering@51degrees.com>",
19
30
  "devDependencies": {
20
- "eslint": "^8.48.0",
21
- "eslint-config-standard": "^17.1.0",
22
- "eslint-plugin-import": "^2.28.1",
23
- "eslint-plugin-jest": "^26.9.0",
31
+ "eslint": "^8.16.0",
32
+ "eslint-config-standard": "^17.0.0",
33
+ "eslint-plugin-import": "^2.26.0",
24
34
  "eslint-plugin-jsdoc": "^38.1.6",
25
- "eslint-plugin-n": "^15.7.0",
26
35
  "eslint-plugin-node": "^11.1.0",
27
- "eslint-plugin-promise": "^6.1.1",
28
- "jest": "^28.1.3",
36
+ "eslint-plugin-promise": "^6.0.0",
37
+ "eslint-plugin-jest": "^26.2.2",
38
+ "eslint-plugin-n": "^15.0.0",
39
+ "jest": "^28.1.0",
29
40
  "jest-junit": "^13.2.0"
30
41
  },
31
42
  "license": "EUPL-1.2",
@@ -33,6 +44,8 @@
33
44
  "url": "https://github.com/51Degrees/device-detection-node/issues"
34
45
  },
35
46
  "files": [
47
+ "examples",
48
+ "tests",
36
49
  "*.js"
37
50
  ]
38
51
  }
@@ -0,0 +1,56 @@
1
+ /* *********************************************************************
2
+ * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4
+ * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5
+ *
6
+ * This Original Work is licensed under the European Union Public Licence
7
+ * (EUPL) v.1.2 and is subject to its terms as set out below.
8
+ *
9
+ * If a copy of the EUPL was not distributed with this file, You can obtain
10
+ * one at https://opensource.org/licenses/EUPL-1.2.
11
+ *
12
+ * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13
+ * amended by the European Commission) shall be deemed incompatible for
14
+ * the purposes of the Work and the provisions of the compatibility
15
+ * clause in Article 5 of the EUPL shall not apply.
16
+ *
17
+ * If using the Work as, or as part of, a network application, by
18
+ * including the attribution notice(s) required under Article 5 of the EUPL
19
+ * in the end user terms of the application under an appropriate heading,
20
+ * such notice(s) shall fulfill the requirements of that article.
21
+ * ********************************************************************* */
22
+
23
+ /**
24
+ * Helpers to obtain keys from the environment
25
+ */
26
+ module.exports = {
27
+ /**
28
+ * Obtain a key either from environment variable or from a property.
29
+ * Try resource key as env var, then as upper case env var, the system property
30
+ * @param keyName
31
+ */
32
+ getNamedKey: function (keyName) {
33
+ let value = process.env[keyName];
34
+ if (!value) {
35
+ value = process.env[keyName.toUpperCase()];
36
+ }
37
+ return value;
38
+ },
39
+
40
+ /**
41
+ * Evaluate whether a key might be valid
42
+ * @param keyValue value to test
43
+ * @returns boolean
44
+ */
45
+ isInvalidKey: function (keyValue) {
46
+ try {
47
+ const buff = Buffer.from(keyValue, 'base64');
48
+ const decoded = buff.toString('ascii');
49
+ return !keyValue ||
50
+ keyValue.trim().length < 19 ||
51
+ decoded.length < 14;
52
+ } catch (e) {
53
+ return true;
54
+ }
55
+ }
56
+ };
@@ -0,0 +1,48 @@
1
+ /* *********************************************************************
2
+ * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4
+ * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5
+ *
6
+ * This Original Work is licensed under the European Union Public Licence
7
+ * (EUPL) v.1.2 and is subject to its terms as set out below.
8
+ *
9
+ * If a copy of the EUPL was not distributed with this file, You can obtain
10
+ * one at https://opensource.org/licenses/EUPL-1.2.
11
+ *
12
+ * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13
+ * amended by the European Commission) shall be deemed incompatible for
14
+ * the purposes of the Work and the provisions of the compatibility
15
+ * clause in Article 5 of the EUPL shall not apply.
16
+ *
17
+ * If using the Work as, or as part of, a network application, by
18
+ * including the attribution notice(s) required under Article 5 of the EUPL
19
+ * in the end user terms of the application under an appropriate heading,
20
+ * such notice(s) shall fulfill the requirements of that article.
21
+ * ********************************************************************* */
22
+
23
+ module.exports = {
24
+ // Environment variables name for testing
25
+ envVars: {
26
+ superResourceKeyEnvVar: 'TEST_SUPER_RESOURCE_KEY',
27
+ platformResourceKeyEnvVar: 'TEST_PLATFORM_RESOURCE_KEY',
28
+ hardwareResourceKeyEnvVar: 'TEST_HARDWARE_RESOURCE_KEY',
29
+ browserResourceKeyEnvVar: 'TEST_BROWSER_RESOURCE_KEY',
30
+ noSetHeaderResourceKeyEnvVar: 'TEST_NO_SETHEADER_RESOURCE_KEY',
31
+ licenseKeyEnvVar: 'TEST_LICENSE_KEY'
32
+ },
33
+ // User-Agent string for testing
34
+ userAgents: {
35
+ chromeUA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
36
+ 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 ' +
37
+ 'Safari/537.36',
38
+ edgeUA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
39
+ 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 ' +
40
+ 'Safari/537.36 Edg/95.0.1020.44',
41
+ firefoxUA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) ' +
42
+ 'Gecko/20100101 Firefox/94.0',
43
+ safariUA: 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 like Mac OS X) ' +
44
+ 'AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 ' +
45
+ 'Mobile/15E148 Safari/604.1',
46
+ curlUA: 'curl/7.80.0'
47
+ }
48
+ };