fiftyone.pipeline.engines.fiftyone 4.6.0 → 4.6.2

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.
Files changed (33) hide show
  1. package/examples/usageSharing/51d.json +4 -2
  2. package/examples/usageSharing/usageSharing.js +26 -10
  3. package/package.json +7 -5
  4. package/packageVersions.js +144 -0
  5. package/readme.md +10 -3
  6. package/shareUsage.js +568 -98
  7. package/shareUsageBackOff.js +178 -0
  8. package/shareUsageEvidenceKeyFilter.js +125 -54
  9. package/shareUsageTracker.js +1 -1
  10. package/shareUsageTrackerEvidenceKeyFilter.js +46 -0
  11. package/tests/readOnly.test.js +35 -0
  12. package/tests/shareUsage.test.js +658 -21
  13. package/tests/shareUsageAcceptsNoEvidence.test.js +409 -0
  14. package/tests/shareUsageBackOff.test.js +685 -0
  15. package/tests/shareUsageBillingKeys.test.js +62 -0
  16. package/tests/shareUsageConfiguration.test.js +132 -0
  17. package/tests/shareUsageDefaults.test.js +174 -0
  18. package/tests/shareUsageErrors.test.js +87 -0
  19. package/tests/shareUsageEvidenceKeyFilter.test.js +210 -0
  20. package/tests/shareUsageInvariantValues.test.js +196 -0
  21. package/tests/shareUsagePackages.test.js +130 -0
  22. package/tests/shareUsagePostForm.test.js +183 -0
  23. package/tests/shareUsageProcessId.test.js +178 -0
  24. package/tests/shareUsageSessionFromRequest.test.js +71 -0
  25. package/tests/shareUsageTracker.test.js +95 -0
  26. package/tests/usageSharingExample.test.js +87 -0
  27. package/tests/usageSharingLast.test.js +192 -0
  28. package/tsconfig.json +3 -1
  29. package/types/packageVersions.d.ts +14 -0
  30. package/types/shareUsage.d.ts +135 -16
  31. package/types/shareUsageBackOff.d.ts +76 -0
  32. package/types/shareUsageEvidenceKeyFilter.d.ts +43 -12
  33. package/types/shareUsageTrackerEvidenceKeyFilter.d.ts +9 -0
@@ -2,14 +2,16 @@
2
2
  "PipelineOptions": {
3
3
  "Elements": [
4
4
  {
5
- "elementName": "../../shareUsage",
5
+ "elementName": "fiftyone.pipeline.engines.fiftyone/shareUsage",
6
6
  "elementParameters": {
7
7
  "sharePercentage": 100,
8
8
  "interval": 1200000,
9
9
  "requestedPackageSize": 50,
10
10
  "cookie": "",
11
+ "trackSession": false,
11
12
  "queryWhitelist": [],
12
- "headerBlacklist": []
13
+ "headerBlacklist": [],
14
+ "shareAll": false
13
15
  }
14
16
  }
15
17
  ]
@@ -24,7 +24,7 @@
24
24
  * @example usageSharing/usageSharing.js
25
25
  *
26
26
  * Usage sharing is enabled by default if using some 51Degrees pipeline
27
- * builders such as the [DeviceDetectionOnPremisePipelineBuilder](https://github.com/51Degrees/device-detection-node/blob/master/fiftyone.devicedetection.onpremise/deviceDetectionOnPremisePipelineBuilder.js)
27
+ * builders such as the [DeviceDetectionOnPremisePipelineBuilder](https://github.com/51Degrees/51degrees-node/blob/main/device-detection/fiftyone.devicedetection.onpremise/deviceDetectionOnPremisePipelineBuilder.js)
28
28
  * In this example, we show how to specifically add a shareUsage element to a
29
29
  * Pipeline using configuration.
30
30
  *
@@ -39,9 +39,9 @@
39
39
  * For details of what each setting does, see the
40
40
  * [Share Usage reference](/documentation/4.5/_pipeline_api__features__usage_sharing.html)
41
41
  *
42
- * This example is available in full on [GitHub](https://github.com/51Degrees/pipeline-node/tree/master/fiftyone.pipeline.engines.fiftyone/examples/usageSharing/usageSharing.js).
42
+ * This example is available in full on [GitHub](https://github.com/51Degrees/51degrees-node/tree/main/pipeline/fiftyone.pipeline.engines.fiftyone/examples/usageSharing/usageSharing.js).
43
43
  *
44
- * Expected output
44
+ * Expected output, before the Find out more section
45
45
  * ```
46
46
  * Constructing pipeline from configuration file.
47
47
  *
@@ -51,30 +51,46 @@
51
51
  * ```
52
52
  */
53
53
 
54
+ const path = require('path');
55
+
54
56
  const core = require('fiftyone.pipeline.core');
55
57
 
56
- // Note that this example is designed to be run from within the
57
- // source repository. If this code has been copied to run standalone
58
- // then you'll need to replace the require below with the commented
59
- // out version below it.
60
- const engine51 = require('../..'); // eslint-disable-line
61
- // const engine51 = require("fiftyone.pipeline.engines.fiftyone");
58
+ // Where to go next, printed at the end of the example.
59
+ const FIND_OUT_MORE = [
60
+ '',
61
+ '='.repeat(79),
62
+ 'Find out more:',
63
+ '\tThe Pipeline API: https://github.com/51Degrees/51degrees-node/tree/main/pipeline',
64
+ '\tUsage sharing: https://51degrees.com/documentation/_pipeline_api__features__usage_sharing.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone-examples-usagesharing-usagesharing.js&utm_term=find-out-more-usage-sharing',
65
+ '\tPipeline API documentation: https://51degrees.com/documentation/_pipeline_api__concepts__pipeline_basics.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone-examples-usagesharing-usagesharing.js&utm_term=find-out-more-documentation',
66
+ '\tContact us: https://51degrees.com/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone-examples-usagesharing-usagesharing.js&utm_term=find-out-more-contact'
67
+ ].join('\n');
62
68
 
63
69
  console.log('Constructing pipeline from configuration file.');
64
70
  console.log();
65
71
 
66
72
  // Create a new pipeline from the supplied config file.
67
- const pipeline = new core.PipelineBuilder().buildFromConfigurationFile('51d.json'); // eslint-disable-line
73
+ // The file is read from the example's own folder, so that the example
74
+ // runs from any working folder.
75
+ const pipeline = new core.PipelineBuilder()
76
+ .buildFromConfigurationFile(path.join(__dirname, '51d.json'));
68
77
 
69
78
  // Alternatively, the commented code below shows how to
70
79
  // configure the ShareUsageElement in code, rather than
71
80
  // using a configuration file.
81
+ // const engine51 = require('fiftyone.pipeline.engines.fiftyone');
72
82
  // const usageElement = new engine51.ShareUsage({
73
83
  // sharePercentage: 0.1,
74
84
  // requestedPackageSize: 2000,
75
85
  // });
76
86
  // const pipeline = new core.PipelineBuilder().add(usageElement).build();
77
87
 
88
+ if (!pipeline.getElement('shareUsage')) {
89
+ throw new Error('51d.json does not add the share usage element.');
90
+ }
91
+
78
92
  console.log(`Pipeline created with share usage element. Evidence processed
79
93
  with this pipeline will now be periodically shared with 51Degrees using the
80
94
  specified configuration.`);
95
+
96
+ console.log(FIND_OUT_MORE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiftyone.pipeline.engines.fiftyone",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
4
4
  "description": "Shared base functions for implementing 51Degrees engines for the 51Degrees Pipeline API",
5
5
  "keywords": [
6
6
  "51degrees",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "author": "51Degrees Engineering <engineering@51degrees.com>",
20
20
  "dependencies": {
21
- "fiftyone.pipeline.core": "4.4.x",
22
- "fiftyone.pipeline.engines": "4.4.x"
21
+ "fiftyone.pipeline.core": "^4.6.2",
22
+ "fiftyone.pipeline.engines": "^4.6.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/jest": "^27.5.2",
@@ -28,11 +28,13 @@
28
28
  "typescript": "^5.9.3"
29
29
  },
30
30
  "license": "EUPL-1.2",
31
+ "homepage": "https://51degrees.com/build-your-own?utm_source=npm&utm_medium=package&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone&utm_term=homepage",
31
32
  "bugs": {
32
- "url": "https://github.com/51Degrees/pipeline-node/issues"
33
+ "url": "https://github.com/51Degrees/51degrees-node/issues"
33
34
  },
34
35
  "repository": {
35
36
  "type": "git",
36
- "url": "https://github.com/51Degrees/pipeline-node"
37
+ "url": "https://github.com/51Degrees/51degrees-node",
38
+ "directory": "pipeline/fiftyone.pipeline.engines.fiftyone"
37
39
  }
38
40
  }
@@ -0,0 +1,144 @@
1
+ /* *********************************************************************
2
+ * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ * Copyright 2026 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 fs = require('fs');
24
+ const path = require('path');
25
+
26
+ // Every 51Degrees package for Node.js is published under a name that starts
27
+ // with this.
28
+ const PACKAGE_PREFIX = 'fiftyone.';
29
+
30
+ // The package that holds the Pipeline.
31
+ const PIPELINE_PACKAGE = 'fiftyone.pipeline.core';
32
+
33
+ /**
34
+ * The name, version and folder of the package a file belongs to, read from
35
+ * the nearest package.json above it.
36
+ *
37
+ * @param {string} file the path of a file
38
+ * @returns {{name: string, version: string, folder: string}|undefined} the
39
+ * package, or undefined when no package.json can be read
40
+ */
41
+ function packageOfFile (file) {
42
+ let folder = path.dirname(file);
43
+ for (;;) {
44
+ const manifest = path.join(folder, 'package.json');
45
+ if (fs.existsSync(manifest)) {
46
+ try {
47
+ const json = JSON.parse(fs.readFileSync(manifest, 'utf8'));
48
+ return { name: json.name, version: json.version, folder };
49
+ } catch (e) {
50
+ return undefined;
51
+ }
52
+ }
53
+ const parent = path.dirname(folder);
54
+ if (parent === folder) {
55
+ return undefined;
56
+ }
57
+ folder = parent;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * The file of the loaded module that defines a class. A module that exports
63
+ * the class itself is preferred to one that exports it among others, so
64
+ * that a package which only passes on another package's class is not
65
+ * named for it.
66
+ *
67
+ * @param {Function} type the class
68
+ * @returns {string|undefined} the file, or undefined when no loaded module
69
+ * exports the class
70
+ */
71
+ function moduleFileOf (type) {
72
+ const loaded = Object.keys(require.cache).map((key) => require.cache[key]);
73
+ const direct = loaded.find((module) => module && module.exports === type);
74
+ if (direct) {
75
+ return direct.filename;
76
+ }
77
+ const among = loaded.find((module) => {
78
+ const exported = module && module.exports;
79
+ if (!exported || typeof exported !== 'object') {
80
+ return false;
81
+ }
82
+ try {
83
+ return Object.keys(exported).some((key) => exported[key] === type);
84
+ } catch (e) {
85
+ return false;
86
+ }
87
+ });
88
+ return among ? among.filename : undefined;
89
+ }
90
+
91
+ /**
92
+ * The 51Degrees packages a Pipeline uses, each once: the package that holds
93
+ * the Pipeline, the package that holds each of its Flow Elements and every
94
+ * 51Degrees package those depend on.
95
+ *
96
+ * @param {Array<object>} flowElements the Flow Elements of the Pipeline
97
+ * @returns {Array<{name: string, version: string}>} the packages, ordered by
98
+ * name
99
+ */
100
+ function packageVersions (flowElements) {
101
+ const found = new Map();
102
+ const add = (pkg) => {
103
+ if (!pkg || typeof pkg.name !== 'string' ||
104
+ !pkg.name.startsWith(PACKAGE_PREFIX) || found.has(pkg.name)) {
105
+ return;
106
+ }
107
+ found.set(pkg.name, pkg);
108
+ let dependencies = {};
109
+ try {
110
+ dependencies = JSON.parse(fs.readFileSync(
111
+ path.join(pkg.folder, 'package.json'), 'utf8')).dependencies || {};
112
+ } catch (e) {
113
+ dependencies = {};
114
+ }
115
+ Object.keys(dependencies)
116
+ .filter((name) => name.startsWith(PACKAGE_PREFIX))
117
+ .forEach((name) => {
118
+ try {
119
+ add(packageOfFile(require.resolve(`${name}/package.json`,
120
+ { paths: [pkg.folder] })));
121
+ } catch (e) {
122
+ // A dependency that cannot be found is not in use.
123
+ }
124
+ });
125
+ };
126
+
127
+ try {
128
+ add(packageOfFile(require.resolve(`${PIPELINE_PACKAGE}/package.json`)));
129
+ } catch (e) {
130
+ // A Pipeline package with no readable manifest cannot be named.
131
+ }
132
+ flowElements.forEach((element) => {
133
+ const file = element ? moduleFileOf(element.constructor) : undefined;
134
+ if (file) {
135
+ add(packageOfFile(file));
136
+ }
137
+ });
138
+
139
+ return Array.from(found.values())
140
+ .map(({ name, version }) => ({ name, version: String(version) }))
141
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
142
+ }
143
+
144
+ module.exports = packageVersions;
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
- ![51Degrees](https://51degrees.com/img/logo.png?utm_source=github&utm_medium=readme&utm_campaign=pipeline-node&utm_content=fiftyone.pipeline.engines.fiftyone-readme.md&utm_term=top "Data rewards the curious") **51Degrees Pipeline Engines Fiftyone**
1
+ ![51Degrees](https://raw.githubusercontent.com/51Degrees/51degrees-node/main/.github/images/logo-160.png "Data rewards the curious") **51Degrees Pipeline Engines Fiftyone**
2
2
 
3
- [Developer Documentation](https://51degrees.com/pipeline-node/index.html?utm_source=github&utm_medium=readme&utm_campaign=pipeline-node&utm_content=fiftyone.pipeline.engines.fiftyone-readme.md&utm_term=top "developer documentation")
3
+ [Developer Documentation](https://51degrees.com/documentation/_pipeline_api__concepts__pipeline_basics.html?utm_source=npm&utm_medium=package&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone&utm_term=top "developer documentation")
4
4
 
5
5
  ## Introduction
6
6
 
@@ -8,7 +8,7 @@ The 51Degrees Pipeline API is a generic web request intelligence and data proces
8
8
 
9
9
  ## This package - fiftyone.pipeline.engines.fiftyone
10
10
 
11
- This package uses the `engines` class created by the [`fiftyone.pipeline.engines`](/fiftyone.pipeline.engines#readme.md). It makes available:
11
+ This package uses the `engines` class created by the [`fiftyone.pipeline.engines`](https://github.com/51Degrees/51degrees-node/tree/main/pipeline/fiftyone.pipeline.engines). It makes available:
12
12
 
13
13
  * A `share usage` engine that is used to send usage information to 51Degrees.
14
14
 
@@ -31,3 +31,10 @@ Then, navigate to the module directory and execute:
31
31
  ```
32
32
  npm test
33
33
  ```
34
+
35
+ ## Find out more
36
+
37
+ - [Build your own](https://51degrees.com/build-your-own?utm_source=npm&utm_medium=package&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone&utm_term=find-out-more-build-your-own)
38
+ - [Pipeline API documentation](https://51degrees.com/documentation/_pipeline_api__concepts__pipeline_basics.html?utm_source=npm&utm_medium=package&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone&utm_term=find-out-more-documentation)
39
+ - [Pipeline API examples](https://51degrees.com/documentation/_pipeline_api__examples__index.html?utm_source=npm&utm_medium=package&utm_campaign=51degrees-node&utm_content=fiftyone.pipeline.engines.fiftyone&utm_term=find-out-more-examples)
40
+ - https://github.com/51Degrees/51degrees-node