@63klabs/cache-data 1.3.4 → 1.3.5

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/CHANGELOG.md CHANGED
@@ -8,6 +8,19 @@ Report all vulnerabilities under the [Security menu](https://github.com/63Klabs/
8
8
 
9
9
  > Note: This project is still in beta. Even though changes are tested and breaking changes are avoided, things may break.
10
10
 
11
+ ## v1.3.5 (2025-01-13)
12
+
13
+ ### Enhancements
14
+
15
+ - `endpoint.getDataDirectFromURI()` has been renamed to `endpoint.get()` and the old name is now a deprecated alias. This was just to simplify naming.
16
+
17
+ Example Use:
18
+
19
+ ```javascript
20
+ const { endpoint } = require("@63klabs/cache-data");
21
+ const data = await endpoint.get({host: "api.example.com", path: "data"}, { parameters: {q: "Chicago" }});
22
+ ```
23
+
11
24
  ## v1.3.4 (2025-01-12)
12
25
 
13
26
  ### Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@63klabs/cache-data",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "Cache data from an API endpoint or application process using AWS S3 and DynamoDb",
5
5
  "author": "Chad Leigh Kluck (https://chadkluck.me)",
6
6
  "license": "MIT",
@@ -59,16 +59,19 @@ const tools = require("./tools/index.js");
59
59
  /**
60
60
  *
61
61
  * @param {ConnectionObject} connection An object with details about the connection (method, uri, host, etc)
62
- * @param {*} data Additional data to perform a query for the request, or transformation of the response within the DAO object. This data is not directly sent to the endpoint. It is used within the DAO object to transform the request and/or response. Any data sent to the endpoint should be in the connection or handled within the DAO
63
- * @returns {object} The response
62
+ * @param {Object} query Additional data to perform a query for the request.
63
+ * @returns {Object} The response
64
+ * @example
65
+ const { endpoint } = require("@63klabs/cache-data");
66
+ const data = await endpoint.get({host: "api.example.com", path: "data"}, { parameters: {q: "Chicago" }});
64
67
  */
65
- const getDataDirectFromURI = async (connection, data = null) => {
66
- return (new Endpoint(connection).get());
68
+ const get = async (connection, query = null) => {
69
+ return (new Endpoint(connection, query).get());
67
70
  };
68
71
 
69
72
  /**
70
73
  * A bare bones request to an endpoint. Can be used as a template to
71
- * create more elaboarate requests.
74
+ * create more elaborate requests.
72
75
  */
73
76
  class Endpoint {
74
77
 
@@ -76,10 +79,21 @@ class Endpoint {
76
79
  *
77
80
  * @param {ConnectionObject} connection An object with connection data
78
81
  */
79
- constructor(connection) {
82
+ constructor(connection, query = {}) {
80
83
 
81
84
  this.response = null;
82
85
 
86
+ // if query has parameters property then we will combine with connection parameters
87
+ if ( query !== null && "parameters" in query ) {
88
+ if ( !("parameters" in connection) || connection.parameters === null ) {
89
+ connection.parameters = {};
90
+ }
91
+
92
+ for ( const [key, value] of Object.entries( query.parameters ) ) {
93
+ connection.parameters[key] = value;
94
+ }
95
+ }
96
+
83
97
  this.request = {
84
98
  method: this._setRequestSetting(connection, "method", "GET"),
85
99
  uri: this._setRequestSetting(connection, "uri", ""),
@@ -182,5 +196,6 @@ class Endpoint {
182
196
  };
183
197
 
184
198
  module.exports = {
185
- getDataDirectFromURI
199
+ getDataDirectFromURI: get, // deprecated alias
200
+ get
186
201
  };