fiftyone.pipeline.cloudrequestengine 4.4.98 → 4.4.100

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/cloudEngine.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');
@@ -27,6 +27,13 @@ const AspectDataDictionary = engines.AspectDataDictionary;
27
27
  const AspectPropertyValue = core.AspectPropertyValue;
28
28
  const BasicListEvidenceKeyFilter = core.BasicListEvidenceKeyFilter;
29
29
 
30
+ /**
31
+ * @typedef {import('fiftyone.pipeline.core').Pipeline} Pipeline
32
+ * @typedef {import('fiftyone.pipeline.core').FlowElement} FlowElement
33
+ * @typedef {import('fiftyone.pipeline.core').FlowData} FlowData
34
+ * @typedef {import('./cloudRequestEngine')} CloudRequestEngine
35
+ */
36
+
30
37
  /**
31
38
  * This is a template for all 51Degrees cloud engines.
32
39
  * It requires the 51Degrees cloudRequestEngine to be placed in a
@@ -57,7 +64,9 @@ class CloudEngine extends Engine {
57
64
  if (!pipeline.flowElements.cloud) {
58
65
  pipeline.log('error', 'No CloudRequestEngine in Pipeline');
59
66
  }
60
-
67
+ /**
68
+ * @type {CloudRequestEngine}
69
+ */
61
70
  this._cloudRequestEngine = pipeline.flowElements.cloud;
62
71
  this._flowElement = flowElement;
63
72
  }
@@ -99,7 +108,7 @@ class CloudEngine extends Engine {
99
108
  * Internal process method for all cloud engines
100
109
  *
101
110
  * @param {FlowData} flowData FlowData to process
102
- * @returns {void}
111
+ * @returns {Promise<void> | void} Completion promise
103
112
  */
104
113
  processInternal (flowData) {
105
114
  const engine = this;
@@ -114,10 +123,9 @@ class CloudEngine extends Engine {
114
123
  flowData.pipeline.log('error', engine.dataKey + ' not populated. ' +
115
124
  cloudData[engine.dataKey + 'nullreason'] !== null
116
125
  ? cloudData[engine.dataKey + 'nullreason']
117
- : '' +
118
- '\n' + 'This may be because the provided API key is not authorised for ' + engine.dataKey + ' queries.');
126
+ : '\nThis may be because the provided API key is not authorised for ' + engine.dataKey + ' queries.');
119
127
  } else {
120
- // Loop over cloudData.device properties to check if they have a value
128
+ // Loop over cloudData.device properties to check if they have a value
121
129
  Object.entries(cloudData[engine.dataKey]).forEach(function ([key, value]) {
122
130
  result[key] = new AspectPropertyValue();
123
131
 
@@ -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 util = require('util');
@@ -33,6 +33,7 @@ const CloudRequestError = require('./cloudRequestError');
33
33
 
34
34
  /**
35
35
  * @typedef {import('fiftyone.pipeline.core').FlowData} FlowData
36
+ * @typedef {import('fiftyone.pipeline.core').Evidence} Evidence
36
37
  */
37
38
 
38
39
  // Engine that makes a call to the 51Degrees cloud service
@@ -195,7 +196,7 @@ class CloudRequestEngine extends Engine {
195
196
  /**
196
197
  * Used to handle errors from http requests
197
198
  *
198
- * @param {http.ServerResponse} response Responce to get errors from
199
+ * @param {import('http').ServerResponse} response Responce to get errors from
199
200
  * @returns {Array<CloudRequestError>} Array of CloudRequestError from response
200
201
  */
201
202
  getErrorsFromResponse (response) {
@@ -216,7 +217,7 @@ class CloudRequestEngine extends Engine {
216
217
  if (cloudErrors.length === 0 &&
217
218
  response.statusCode > 299) {
218
219
  const message = 'Cloud service returned status code ' +
219
- response.statusCode + ' with content ' + content + '.';
220
+ response.statusCode + ' with content ' + content + '.';
220
221
  cloudErrors.push(new CloudRequestError(
221
222
  message,
222
223
  response.headers,
@@ -229,7 +230,7 @@ class CloudRequestEngine extends Engine {
229
230
  /**
230
231
  * Internal process to fetch all the properties available under a resourcekey
231
232
  *
232
- * @returns {Promise} properties from the cloud server
233
+ * @returns {Promise<object>} properties from the cloud server
233
234
  */
234
235
  fetchProperties () {
235
236
  const engine = this;
@@ -266,6 +267,12 @@ class CloudRequestEngine extends Engine {
266
267
  });
267
268
  }
268
269
 
270
+ /**
271
+ * Properties transform
272
+ *
273
+ * @param {object} properties properties to transform
274
+ * @returns {object} transformed properties
275
+ */
269
276
  propertiesTransform (properties) {
270
277
  const result = {};
271
278
  const self = this;
@@ -285,6 +292,13 @@ class CloudRequestEngine extends Engine {
285
292
  return result;
286
293
  }
287
294
 
295
+ /**
296
+ * Meta property transform
297
+ *
298
+ * @param {string} key key to check
299
+ * @param {object} value properties to transform
300
+ * @returns {object} transformed properties
301
+ */
288
302
  metaPropertyTransform (key, value) {
289
303
  switch (key) {
290
304
  case 'itemproperties':
@@ -342,7 +356,7 @@ class CloudRequestEngine extends Engine {
342
356
  /**
343
357
  * Internal function to get evidenceKeys used by cloud resourcekey
344
358
  *
345
- * @returns {Array} evidence key list
359
+ * @returns {Promise} evidence promise
346
360
  */
347
361
  getEvidenceKeys () {
348
362
  const engine = this;
@@ -371,7 +385,7 @@ class CloudRequestEngine extends Engine {
371
385
  * this is unexpected so a warning will be logged.
372
386
  *
373
387
  * @param {FlowData} flowData FlowData to get evidence from
374
- * @returns {Evidence} Evidence Dictionary
388
+ * @returns {object} Evidence Dictionary
375
389
  */
376
390
  getContent (flowData) {
377
391
  const queryData = {};
@@ -448,7 +462,7 @@ class CloudRequestEngine extends Engine {
448
462
  * Get evidence with specified prefix.
449
463
  *
450
464
  * @param {Evidence} evidence All evidence in the flow data.
451
- * @param {stirng} type Required evidence key prefix
465
+ * @param {string} type Required evidence key prefix
452
466
  * @returns {Evidence} Selected evidence
453
467
  */
454
468
  getSelectedEvidence (evidence, type) {
@@ -457,8 +471,8 @@ class CloudRequestEngine extends Engine {
457
471
  if (type === 'other') {
458
472
  for (const [key, value] of Object.entries(evidence)) {
459
473
  if (this.hasKeyPrefix(key, 'query') === false &&
460
- this.hasKeyPrefix(key, 'header') === false &&
461
- this.hasKeyPrefix(key, 'cookie') === false) {
474
+ this.hasKeyPrefix(key, 'header') === false &&
475
+ this.hasKeyPrefix(key, 'cookie') === false) {
462
476
  selectedEvidence[key] = value;
463
477
  }
464
478
  }
@@ -18,20 +18,27 @@
18
18
  * including the attribution notice(s) required under Article 5 of the EUPL
19
19
  * in the end user terms of the application under an appropriate heading,
20
20
  * such notice(s) shall fulfill the requirements of that article.
21
- * ********************************************************************* */
22
-
23
- class CloudRequestError extends Error {
24
- constructor (message, responseHeaders, httpStatusCode) {
25
- super(message);
26
- this.name = this.constructor.name;
27
- this.errorMessage = message;
28
- this.responseHeaders = responseHeaders;
29
- this.httpStatusCode = httpStatusCode;
30
- // This clips the constructor invocation from the stack trace.
31
- // It's not absolutely essential, but it does make the stack
32
- // trace a little nicer.
33
- Error.captureStackTrace(this, this.constructor);
34
- }
35
- }
36
-
37
- module.exports = CloudRequestError;
21
+ * ********************************************************************* */
22
+
23
+ class CloudRequestError extends Error {
24
+ /**
25
+ * Constructor for Cloud Request Error
26
+ *
27
+ * @param {string} message error message
28
+ * @param {*} responseHeaders response headers
29
+ * @param {number} httpStatusCode http status code
30
+ */
31
+ constructor (message, responseHeaders, httpStatusCode) {
32
+ super(message);
33
+ this.name = this.constructor.name;
34
+ this.errorMessage = message;
35
+ this.responseHeaders = responseHeaders;
36
+ this.httpStatusCode = httpStatusCode;
37
+ // This clips the constructor invocation from the stack trace.
38
+ // It's not absolutely essential, but it does make the stack
39
+ // trace a little nicer.
40
+ Error.captureStackTrace(this, this.constructor);
41
+ }
42
+ }
43
+
44
+ module.exports = CloudRequestError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiftyone.pipeline.cloudrequestengine",
3
- "version": "4.4.98",
3
+ "version": "4.4.100",
4
4
  "description": "Cloud request engine for the 51Degrees Pipeline API",
5
5
  "keywords": [
6
6
  "51degrees",
@@ -10,6 +10,7 @@
10
10
  "cloud"
11
11
  ],
12
12
  "main": "index.js",
13
+ "types": "types/index.d.ts",
13
14
  "directories": {
14
15
  "test": "tests"
15
16
  },
package/readme.md CHANGED
@@ -8,18 +8,33 @@ The 51Degrees Pipeline API is a generic web request intelligence and data proces
8
8
 
9
9
  ## This package - fiftyone.pipeline.cloudrequestengine
10
10
 
11
- This package uses the `engines` class created by the `fiftyone.pipeline.engines`. It makes available:
11
+ This package uses the `engines` class created by the [`fiftyone.pipeline.engines`](/fiftyone.pipeline.engines#readme.md). It makes available:
12
12
 
13
13
  * A `Cloud Request Engine` which calls the 51Degrees cloud service to fetch properties and metadata about them based on a provided resource key. Get a resource key at https://configure.51degrees.com/
14
14
  * A `Cloud Engine` template which reads data from the Cloud Request Engine.
15
15
 
16
16
  It is used by the cloud versions of the following 51Degrees engines:
17
17
 
18
- - **fiftyone.devicedetection** - A device detection engine
19
- - **fiftyone.location** - A geolocation lookup engine
18
+ - [**fiftyone.devicedetection**](https://github.com/51Degrees/device-detection-node#readme) - A device detection engine
19
+ - [**fiftyone.geolocation**](https://github.com/51Degrees/location-node#readme) - A geolocation lookup engine
20
20
 
21
21
  ## Installation
22
22
 
23
23
  ```
24
24
  npm install fiftyone.pipeline.cloudrequestengine
25
25
  ```
26
+
27
+ ## Tests
28
+
29
+ To run tests you will need to install the `jest` library.
30
+
31
+ ```
32
+ npm install jest --global
33
+ ```
34
+
35
+ Then, navigate to the module directory and execute:
36
+
37
+ ```
38
+ npm test
39
+ ```
40
+
package/requestClient.js CHANGED
@@ -24,9 +24,9 @@ class RequestClient {
24
24
  /**
25
25
  * Make a POST request to the specified url
26
26
  *
27
- * @param {*} url The url to send a request to
28
- * @param {*} data The data to send in the body of the request
29
- * @param {*} origin The value to use for the Origin header when
27
+ * @param {string} url The url to send a request to
28
+ * @param {object | null} data The data to send in the body of the request
29
+ * @param {string | null} origin The value to use for the Origin header when
30
30
  * making the request
31
31
  * @returns {Promise} The resolve function will be passed the content
32
32
  * from the response and the reject function will be passed
@@ -100,8 +100,8 @@ class RequestClient {
100
100
  /**
101
101
  * Make a GET request to the specified url
102
102
  *
103
- * @param {*} url The url to send a request to
104
- * @param {*} origin The value to use for the Origin header when
103
+ * @param {string} url The url to send a request to
104
+ * @param {string | null} origin The value to use for the Origin header when
105
105
  * making the request
106
106
  * @returns {Promise} The resolve function will be passed the content
107
107
  * from the response and the reject function will be passed
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
+ }
@@ -1,5 +1,11 @@
1
1
  export = CloudEngine;
2
2
  declare const CloudEngine_base: typeof import("fiftyone.pipeline.engines/types/engine");
3
+ /**
4
+ * @typedef {import('fiftyone.pipeline.core').Pipeline} Pipeline
5
+ * @typedef {import('fiftyone.pipeline.core').FlowElement} FlowElement
6
+ * @typedef {import('fiftyone.pipeline.core').FlowData} FlowData
7
+ * @typedef {import('./cloudRequestEngine')} CloudRequestEngine
8
+ */
3
9
  /**
4
10
  * This is a template for all 51Degrees cloud engines.
5
11
  * It requires the 51Degrees cloudRequestEngine to be placed in a
@@ -9,4 +15,42 @@ declare const CloudEngine_base: typeof import("fiftyone.pipeline.engines/types/e
9
15
  **/
10
16
  declare class CloudEngine extends CloudEngine_base {
11
17
  constructor(...args: any[]);
18
+ /**
19
+ * Handles the registration of the Cloud Engine in a pipeline.
20
+ * This method is called when a pipeline is registered,
21
+ * and it ensures that the CloudRequestEngine is present in the pipeline.
22
+ *
23
+ * @param {Pipeline} pipeline - The pipeline being registered.
24
+ * @param {FlowElement} flowElement - The flow element associated with the Cloud Engine.
25
+ */
26
+ handlePipelineRegistration(pipeline: Pipeline, flowElement: FlowElement): void;
27
+ /**
28
+ * @type {CloudRequestEngine}
29
+ */
30
+ _cloudRequestEngine: CloudRequestEngine;
31
+ _flowElement: import("fiftyone.pipeline.core/types/flowElement");
32
+ /**
33
+ * Updates the Cloud Engine when the CloudRequestEngine is ready.
34
+ * This method fetches properties and evidence keys from the CloudRequestEngine,
35
+ * updating the Cloud Engine accordingly.
36
+ *
37
+ * @param {Function} resolve - Callback to be called on successful completion.
38
+ * @param {Function} reject - Callback to be called if there is an error.
39
+ */
40
+ updateEngineWhenCloudRequestEngineReady(resolve: Function, reject: Function): void;
41
+ errors: any;
42
+ /**
43
+ * Internal process method for all cloud engines
44
+ *
45
+ * @param {FlowData} flowData FlowData to process
46
+ * @returns {Promise<void> | void} Completion promise
47
+ */
48
+ processInternal(flowData: FlowData): Promise<void> | void;
49
+ }
50
+ declare namespace CloudEngine {
51
+ export { Pipeline, FlowElement, FlowData, CloudRequestEngine };
12
52
  }
53
+ type Pipeline = import("fiftyone.pipeline.core/types/pipeline");
54
+ type FlowElement = import("fiftyone.pipeline.core/types/flowElement");
55
+ type FlowData = import("fiftyone.pipeline.core/types/flowData");
56
+ type CloudRequestEngine = import("./cloudRequestEngine");
@@ -2,6 +2,7 @@ export = CloudRequestEngine;
2
2
  declare const CloudRequestEngine_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').Evidence} Evidence
5
6
  */
6
7
  declare class CloudRequestEngine extends CloudRequestEngine_base {
7
8
  /**
@@ -12,23 +13,95 @@ declare class CloudRequestEngine extends CloudRequestEngine_base {
12
13
  * @param {string} options.licenseKey licensekey for cloud service
13
14
  * @param {string} options.baseURL url the cloud service is located at
14
15
  * if overriding default
16
+ * @param {string} options.cloudRequestOrigin The value to set for the Origin
17
+ * header when making requests to the cloud service.
18
+ * This is used by the cloud service to check that the request is being
19
+ * made from a origin matching those allowed by the resource key.
20
+ * For more detail, see the 'Request Headers' section in the
21
+ * <a href="https://cloud.51degrees.com/api-docs/index.html">cloud documentation</a>.
22
+ * @param {RequestClient} options.requestClient Set predefined RequestClient.
15
23
  */
16
- constructor({ resourceKey, licenseKey, baseURL }: {
24
+ constructor({ resourceKey, licenseKey, baseURL, cloudRequestOrigin, requestClient }: {
17
25
  resourceKey: string;
18
26
  licenseKey: string;
19
27
  baseURL: string;
28
+ cloudRequestOrigin: string;
29
+ requestClient: RequestClient;
20
30
  }, ...args: any[]);
21
31
  resourceKey: string;
22
32
  licenseKey: string;
33
+ cloudRequestOrigin: string;
34
+ requestClient: RequestClient;
23
35
  baseURL: string;
24
36
  evidenceKeys: any[];
25
37
  flowElementProperties: {};
38
+ /**
39
+ * Check if the keys and properties have been fetched.
40
+ *
41
+ * This computed property determines whether the keys of a 'flowElementProperties' object and the 'evidenceKeyFilter'
42
+ * array both have elements, indicating that the necessary data has been fetched and is ready for use.
43
+ *
44
+ * @returns {boolean} True if the keys and properties are fetched and ready; otherwise, false.
45
+ */
46
+ get keysAndPropertiesFetched(): boolean;
47
+ /**
48
+ * Fetches evidence keys and properties data.
49
+ *
50
+ * This method asynchronously fetches evidence keys and properties required for the operation.
51
+ * It uses Promises to handle data retrieval and provides callback functions for success and failure scenarios.
52
+ *
53
+ * @param {Function} resolveCallback - A callback function to be called when the data is successfully fetched.
54
+ * It will receive the current instance as a parameter.
55
+ *
56
+ * @param {Function} rejectCallback - A callback function to be called when an error occurs during data retrieval.
57
+ * It will receive the error information as a parameter.
58
+ */
59
+ fetchEvidenceKeysAndProperties(resolveCallback: Function, rejectCallback: Function): void;
60
+ /**
61
+ * Internal process for cloud engine
62
+ * Returns raw JSON as a "cloud" property in "cloud"
63
+ *
64
+ * @param {FlowData} flowData flowData to process
65
+ * @returns {Promise} data from cloud service
66
+ */
67
+ processInternal(flowData: FlowData): Promise<any>;
68
+ /**
69
+ * Typically, cloud will return errors as JSON.
70
+ * However, transport level errors or other failures can result in
71
+ * responses that are plain text. This function handles these cases.
72
+ *
73
+ * @param {string} responseBody the response data to process
74
+ * @returns {Array} The error messages
75
+ */
76
+ getErrorMessages(responseBody: string): any[];
77
+ /**
78
+ * Used to handle errors from http requests
79
+ *
80
+ * @param {import('http').ServerResponse} response Responce to get errors from
81
+ * @returns {Array<CloudRequestError>} Array of CloudRequestError from response
82
+ */
83
+ getErrorsFromResponse(response: import("http").ServerResponse): Array<CloudRequestError>;
26
84
  /**
27
85
  * Internal process to fetch all the properties available under a resourcekey
28
86
  *
29
- * @returns {Promise} properties from the cloud server
87
+ * @returns {Promise<object>} properties from the cloud server
30
88
  */
31
- fetchProperties(): Promise<any>;
89
+ fetchProperties(): Promise<object>;
90
+ /**
91
+ * Properties transform
92
+ *
93
+ * @param {object} properties properties to transform
94
+ * @returns {object} transformed properties
95
+ */
96
+ propertiesTransform(properties: object): object;
97
+ /**
98
+ * Meta property transform
99
+ *
100
+ * @param {string} key key to check
101
+ * @param {object} value properties to transform
102
+ * @returns {object} transformed properties
103
+ */
104
+ metaPropertyTransform(key: string, value: object): object;
32
105
  /**
33
106
  * Internal function to get data from cloud service
34
107
  *
@@ -41,11 +114,53 @@ declare class CloudRequestEngine extends CloudRequestEngine_base {
41
114
  /**
42
115
  * Internal function to get evidenceKeys used by cloud resourcekey
43
116
  *
44
- * @returns {Array} evidence key list
117
+ * @returns {Promise} evidence promise
118
+ */
119
+ getEvidenceKeys(): Promise<any>;
120
+ /**
121
+ * Generate the Content to send in the POST request. The evidence keys
122
+ * e.g. 'query.' and 'header.' have an order of precedence. These are
123
+ * added to the evidence in reverse order, if there is conflict then
124
+ * the queryData value is overwritten.
125
+ * 'query.' evidence should take precedence over all other evidence.
126
+ * If there are evidence keys other than 'query.' that conflict then
127
+ * this is unexpected so a warning will be logged.
128
+ *
129
+ * @param {FlowData} flowData FlowData to get evidence from
130
+ * @returns {object} Evidence Dictionary
131
+ */
132
+ getContent(flowData: FlowData): object;
133
+ /**
134
+ * Add query data to the evidence.
135
+ *
136
+ * @param {FlowData} flowData FlowData for logging
137
+ * @param {object} queryData The destination dictionary to add query data to.
138
+ * @param {Evidence} allEvidence All evidence in the flow data. This is used to
139
+ * report which evidence keys are conflicting.
140
+ * @param {object} evidence Evidence to add to the query Data.
141
+ */
142
+ addQueryData(flowData: FlowData, queryData: object, allEvidence: Evidence, evidence: object): void;
143
+ /**
144
+ * Get evidence with specified prefix.
145
+ *
146
+ * @param {Evidence} evidence All evidence in the flow data.
147
+ * @param {string} type Required evidence key prefix
148
+ * @returns {Evidence} Selected evidence
149
+ */
150
+ getSelectedEvidence(evidence: Evidence, type: string): Evidence;
151
+ /**
152
+ * Check that the key of a KeyValuePair has the given prefix.
153
+ *
154
+ * @param {string} itemKey Key to check
155
+ * @param {string} prefix The prefix to check for.
156
+ * @returns {boolean} True if the key has the prefix.
45
157
  */
46
- getEvidenceKeys(): any[];
158
+ hasKeyPrefix(itemKey: string, prefix: string): boolean;
47
159
  }
48
160
  declare namespace CloudRequestEngine {
49
- export { FlowData };
161
+ export { FlowData, Evidence };
50
162
  }
163
+ import RequestClient = require("./requestClient");
164
+ import CloudRequestError = require("./cloudRequestError");
51
165
  type FlowData = import("fiftyone.pipeline.core/types/flowData");
166
+ type Evidence = import("fiftyone.pipeline.core/types/evidence");
@@ -0,0 +1,14 @@
1
+ export = CloudRequestError;
2
+ declare class CloudRequestError extends Error {
3
+ /**
4
+ * Constructor for Cloud Request Error
5
+ *
6
+ * @param {string} message error message
7
+ * @param {*} responseHeaders response headers
8
+ * @param {number} httpStatusCode http status code
9
+ */
10
+ constructor(message: string, responseHeaders: any, httpStatusCode: number);
11
+ errorMessage: string;
12
+ responseHeaders: any;
13
+ httpStatusCode: number;
14
+ }
@@ -0,0 +1 @@
1
+ export let evidenceConflict: string;
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const CloudRequestEngine: typeof import("./cloudRequestEngine");
2
- export const CloudEngine: typeof import("./cloudEngine");
1
+ export let CloudRequestEngine: typeof import("./cloudRequestEngine");
2
+ export let CloudEngine: typeof import("./cloudEngine");
@@ -0,0 +1,32 @@
1
+ export = RequestClient;
2
+ declare class RequestClient {
3
+ /**
4
+ * Make a POST request to the specified url
5
+ *
6
+ * @param {string} url The url to send a request to
7
+ * @param {object | null} data The data to send in the body of the request
8
+ * @param {string | null} origin The value to use for the Origin header when
9
+ * making the request
10
+ * @returns {Promise} The resolve function will be passed the content
11
+ * from the response and the reject function will be passed
12
+ * an object with 3 properties:
13
+ * headers = HTTP headers in the response
14
+ * statusCode = HTTP status code of response
15
+ * content = The content of the response or an error message
16
+ */
17
+ post(url: string, data: object | null, origin: string | null): Promise<any>;
18
+ /**
19
+ * Make a GET request to the specified url
20
+ *
21
+ * @param {string} url The url to send a request to
22
+ * @param {string | null} origin The value to use for the Origin header when
23
+ * making the request
24
+ * @returns {Promise} The resolve function will be passed the content
25
+ * from the response and the reject function will be passed
26
+ * an object with 3 properties:
27
+ * headers = HTTP headers in the response
28
+ * statusCode = HTTP status code of response
29
+ * content = The content of the response or an error message
30
+ */
31
+ get(url: string, origin: string | null): Promise<any>;
32
+ }
@@ -1 +1 @@
1
- export const baseURLDefault: string;
1
+ export let baseURLDefault: string;