fiftyone.pipeline.engines.fiftyone 4.4.99 → 4.4.101

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiftyone.pipeline.engines.fiftyone",
3
- "version": "4.4.99",
3
+ "version": "4.4.101",
4
4
  "description": "Shared base functions for implementing 51Degrees engines for the 51Degrees Pipeline API",
5
5
  "keywords": [
6
6
  "51degrees",
@@ -9,6 +9,7 @@
9
9
  "service"
10
10
  ],
11
11
  "main": "index.js",
12
+ "types": "types/index.d.ts",
12
13
  "directories": {
13
14
  "test": "tests"
14
15
  },
@@ -21,7 +22,10 @@
21
22
  "fiftyone.pipeline.engines": "4.4.x"
22
23
  },
23
24
  "devDependencies": {
24
- "jest": "^27.5.1"
25
+ "@types/jest": "^27.5.2",
26
+ "@types/node": "^20.14.10",
27
+ "jest": "^27.5.1",
28
+ "typescript": "^5.5.3"
25
29
  },
26
30
  "license": "EUPL-1.2",
27
31
  "bugs": {
package/shareUsage.js CHANGED
@@ -1,23 +1,23 @@
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
  const engines = require('fiftyone.pipeline.engines');
@@ -40,6 +40,7 @@ const SHARE_USAGE_VERSION = '1.1';
40
40
 
41
41
  /**
42
42
  * @typedef {import('fiftyone.pipeline.core').FlowData} FlowData
43
+ * @typedef {import('fiftyone.pipeline.core').FlowElement} FlowElement
43
44
  */
44
45
 
45
46
  /**
@@ -317,6 +318,10 @@ class ShareUsage extends Engine {
317
318
  */
318
319
  getFlowElements () {
319
320
  if (!this.flowElements) {
321
+ /**
322
+ * @type {Array<FlowElement>}
323
+ */
324
+ this.flowElements = [];
320
325
  if (this.pipelines.length === 1) {
321
326
  const list = [];
322
327
  for (const [, value] of Object.entries(this.pipelines[0].flowElements)) {
@@ -330,9 +335,8 @@ class ShareUsage extends Engine {
330
335
  // make up the pipeline so a warning is logged
331
336
  // but otherwise, the system can continue as normal.
332
337
  this._log('warn', 'Share usage element registered ' +
333
- `to ${this.pipelines.length > 0 ? 'too many' : 'no'}` +
334
- ' pipelines. Unable to send share usage information.');
335
- this.flowElements = [];
338
+ `to ${this.pipelines.length > 0 ? 'too many' : 'no'}` +
339
+ ' pipelines. Unable to send share usage information.');
336
340
  }
337
341
  }
338
342
  return this.flowElements;
@@ -402,6 +406,12 @@ class ShareUsageData {
402
406
  this.sequence = '';
403
407
  }
404
408
 
409
+ /**
410
+ * Try to add data to shared usage
411
+ *
412
+ * @param {string} key key to add by
413
+ * @param {*} value value to add
414
+ */
405
415
  tryAddToData (key, value) {
406
416
  // Get the category and field names from the evidence key.
407
417
  let category = '';
@@ -1,23 +1,23 @@
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
  const engines = require('fiftyone.pipeline.engines');
@@ -50,7 +50,7 @@ class ShareUsageTracker extends Tracker {
50
50
  * Function to check if we should put the evidence in the cache
51
51
  *
52
52
  * @param {string} key key of piece of evidence
53
- * @param {mixed} value value of piece of evidence
53
+ * @param {*} value value of piece of evidence
54
54
  * @returns {boolean} whether put in cache
55
55
  **/
56
56
  match (key, value) {
@@ -69,7 +69,7 @@ class ShareUsageTracker extends Tracker {
69
69
  * Retreive entry from cache
70
70
  *
71
71
  * @param {object} cacheKey key value store of evidence to lookup
72
- * @returns {mixed} value stored in cache
72
+ * @returns {*} value stored in cache
73
73
  **/
74
74
  get (cacheKey) {
75
75
  return this.cache.read(cacheKey);
package/tsconfig.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
- // Change this to match your project
3
- "include": ["*"],
4
- "compilerOptions": {
5
- // Tells TypeScript to read JS files, as
6
- // normally they are ignored as source files
7
- "allowJs": true,
8
- // Generate d.ts files
9
- "declaration": true,
10
- // This compiler run should
11
- // only output d.ts files
12
- "emitDeclarationOnly": true,
13
- // Types should go into this directory.
14
- // Removing this would place the .d.ts files
15
- // next to the .js files
16
- "outDir": "types",
17
- "lib": ["ES2015"],
18
- "moduleResolution": "Node",
19
- "noImplicitAny": true
20
- }
21
- }
2
+ // Change this to match your project
3
+ "include": ["*"],
4
+ "exclude": ["node_modules"],
5
+ "compilerOptions": {
6
+ // Tells TypeScript to read JS files, as
7
+ // normally they are ignored as source files
8
+ "allowJs": true,
9
+ // Generate d.ts files
10
+ "declaration": true,
11
+ // This compiler run should
12
+ // only output d.ts files
13
+ "emitDeclarationOnly": true,
14
+ // Types should go into this directory.
15
+ // Removing this would place the .d.ts files
16
+ // next to the .js files
17
+ "outDir": "types",
18
+ "lib": ["ES2015"],
19
+ "moduleResolution": "Node",
20
+ "noImplicitAny": true
21
+ }
22
+ }
package/types/index.d.ts CHANGED
@@ -1 +1 @@
1
- export const ShareUsage: typeof import("./shareUsage");
1
+ export let ShareUsage: typeof import("./shareUsage");
@@ -2,6 +2,7 @@ export = ShareUsage;
2
2
  declare const ShareUsage_base: typeof import("fiftyone.pipeline.engines/types/engine");
3
3
  /**
4
4
  * @typedef {import('fiftyone.pipeline.core').FlowData} FlowData
5
+ * @typedef {import('fiftyone.pipeline.core').FlowElement} FlowElement
5
6
  */
6
7
  /**
7
8
  * The ShareUsage element sends usage data to 51Degrees in zipped batches
@@ -10,44 +11,114 @@ declare class ShareUsage extends ShareUsage_base {
10
11
  /**
11
12
  * Constructor for ShareUsage engine
12
13
  *
13
- * @param {object} options settings object for shareusage
14
- * @param {number} options.interval how often to send
15
- * @param {number} options.requestedPackageSize how many items
16
- * in one zipped packaged
17
- * @param {string} options.cookie which cookie is used to track evidence
18
- * @param {Array} options.queryWhitelist list of query string
19
- * whitelist evidence to keep
20
- * @param {Array} options.headerBlacklist list of header evidence to exclude
21
- * @param {number} options.sharePercentage percentage of requests to share
22
- */
23
- constructor({ interval, requestedPackageSize, cookie, queryWhitelist, headerBlacklist, sharePercentage }?: {
14
+ * @param {object} options settings object for share usage.
15
+ * @param {number} options.interval If exactly the same evidence values
16
+ * are seen multiple times within this time limit (in milliseconds) then
17
+ * they will only be shared once.
18
+ * @param {number} options.requestedPackageSize The usage element
19
+ * will group data into single requests before sending it.
20
+ * This setting controls the minimum number of entries before
21
+ * data is sent.
22
+ * If you are sharing large amounts of data, increasing this value
23
+ * is recommended in order to reduce the overhead of sending HTTP
24
+ * messages.
25
+ * For example, the 51Degrees cloud service uses a value of 2500.
26
+ * @param {string} options.cookie if a cookie is being used to identify
27
+ * user sessions, it can be specified here in order to reduce the
28
+ * sharing of duplicated data.
29
+ * @param {Array} options.queryWhitelist By default query string
30
+ * and HTTP form parameters are not shared unless prefixed with '51D_'.
31
+ * If you need to share query string parameters, a list can be
32
+ * specified here.
33
+ * @param {Array} options.headerBlacklist By default, all HTTP headers
34
+ * (except a few, such as Cookies) are shared. Individual headers can
35
+ * be excluded from sharing by adding them to this list.
36
+ * @param {number} options.sharePercentage approximate proportion of
37
+ * requests to be shared. 1 = 100%, 0.5 = 50%, etc..
38
+ * @param {string} options.endpoint The target destination for usage
39
+ * sharing data. The default is https://devices-v4.51degrees.com/new.ashx.
40
+ */
41
+ constructor({ interval, requestedPackageSize, cookie, queryWhitelist, headerBlacklist, sharePercentage, endpoint }?: {
24
42
  interval: number;
25
43
  requestedPackageSize: number;
26
44
  cookie: string;
27
45
  queryWhitelist: any[];
28
46
  headerBlacklist: any[];
29
47
  sharePercentage: number;
48
+ endpoint: string;
30
49
  }, ...args: any[]);
31
50
  trackingCookie: string;
51
+ evidenceKeyFilter: ShareUsageEvidenceKeyFilter;
32
52
  tracker: ShareUsageTracker;
33
53
  requestedPackageSize: number;
34
54
  sharePercentage: number;
35
- sharePercentageCounter: number;
36
55
  shareData: any[];
56
+ endpoint: url.URL;
57
+ http: typeof import("http") | typeof import("https");
58
+ /**
59
+ * Internal process method which uses the ShareUsageTracker
60
+ * to determine whether to add usage data to a batch and adds it if necessary.
61
+ *
62
+ * @param {FlowData} flowData flowData to process
63
+ */
64
+ processInternal(flowData: FlowData): void;
65
+ /**
66
+ * Creates a ShareUsageData instance populated from the evidence
67
+ * within the flow data provided.
68
+ *
69
+ * @param {FlowData} flowData the flow data containing the evidence to use
70
+ * @returns {ShareUsageData} New ShareUsageData instance, populated from the evidence
71
+ * provided
72
+ */
73
+ getDataFromEvidence(flowData: FlowData): ShareUsageData;
74
+ getConstantXml(): string;
75
+ constantXml: string;
37
76
  /**
38
77
  * Internal method which adds to the share usage bundle (generating XML)
39
78
  *
40
- * @param {object} key key value store of current
79
+ * @param {object} data key value store of current
41
80
  * evidence in FlowData (filtered by the ShareUsageEvidenceKeyFilter)
42
81
  */
43
- addToShareUsage(key: object): void;
82
+ addToShareUsage(data: object): void;
44
83
  /**
45
84
  * Internal method to send the share usage bundle to the 51Degrees servers
46
85
  */
47
86
  sendShareUsage(): void;
87
+ /**
88
+ * Return a list of FlowElements in the pipeline.
89
+ * If the list is null then populate from the pipeline.
90
+ * If there are multiple or no pipelines then log an error.
91
+ *
92
+ * @returns {Array<FlowElement>} list of flow elements
93
+ */
94
+ getFlowElements(): Array<FlowElement>;
95
+ /**
96
+ * @type {Array<FlowElement>}
97
+ */
98
+ flowElements: Array<FlowElement>;
48
99
  }
49
100
  declare namespace ShareUsage {
50
- export { FlowData };
101
+ export { FlowData, FlowElement };
51
102
  }
103
+ import ShareUsageEvidenceKeyFilter = require("./shareUsageEvidenceKeyFilter");
52
104
  import ShareUsageTracker = require("./shareUsageTracker");
105
+ import url = require("url");
106
+ /**
107
+ * Internal class that is used to store details of data in memory
108
+ * prior to it being sent to 51Degrees.
109
+ */
110
+ declare class ShareUsageData {
111
+ evidenceData: {};
112
+ sessionId: string;
113
+ clientIp: string;
114
+ sequence: string;
115
+ /**
116
+ * Try to add data to shared usage
117
+ *
118
+ * @param {string} key key to add by
119
+ * @param {*} value value to add
120
+ */
121
+ tryAddToData(key: string, value: any): void;
122
+ }
53
123
  type FlowData = import("fiftyone.pipeline.core/types/flowData");
124
+ type FlowElement = import("fiftyone.pipeline.core/types/flowElement");
@@ -20,7 +20,8 @@ declare class ShareUsageEvidenceKeyFilter extends ShareUsageEvidenceKeyFilter_ba
20
20
  queryWhitelist: any[];
21
21
  headerBlacklist: any[];
22
22
  }, ...args: any[]);
23
- queryWhitelist: any[];
24
- headerBlacklist: any[];
23
+ includedQueryStringParams: any[];
24
+ blockedHttpHeaders: any[];
25
25
  cookie: string;
26
+ shareAll: boolean;
26
27
  }
@@ -11,7 +11,7 @@ declare class ShareUsageTracker extends ShareUsageTracker_base {
11
11
  *
12
12
  * @param {object} options options for share usage tracker
13
13
  * @param {number} options.size size of the share usage lru cache
14
- * @param {number} options.interval how often to put evidence into the cache
14
+ * @param {number} options.interval if identical evidence values are seen by the tracker within this interval (in milliseconds) it will be ignored by the tracker.
15
15
  **/
16
16
  constructor({ size, interval }?: {
17
17
  size: number;
@@ -19,4 +19,18 @@ declare class ShareUsageTracker extends ShareUsageTracker_base {
19
19
  }, ...args: any[]);
20
20
  cache: import("fiftyone.pipeline.engines/types/lru");
21
21
  interval: number;
22
+ /**
23
+ * Retreive entry from cache
24
+ *
25
+ * @param {object} cacheKey key value store of evidence to lookup
26
+ * @returns {*} value stored in cache
27
+ **/
28
+ get(cacheKey: object): any;
29
+ /**
30
+ * Put entry in cache
31
+ *
32
+ * @param {object} cacheKey key value store of evidence
33
+ * to place in cache
34
+ **/
35
+ put(cacheKey: object): void;
22
36
  }