@cocreate/api 1.20.4 → 1.20.6

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
@@ -1,3 +1,18 @@
1
+ ## [1.20.6](https://github.com/CoCreate-app/CoCreate-api/compare/v1.20.5...v1.20.6) (2024-04-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump cocreate dependencies ([28dabef](https://github.com/CoCreate-app/CoCreate-api/commit/28dabefd52299a59fc7cbe1fe6fbe1d15c074479))
7
+
8
+ ## [1.20.5](https://github.com/CoCreate-app/CoCreate-api/compare/v1.20.4...v1.20.5) (2024-04-27)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bug in param handeling ([083b77e](https://github.com/CoCreate-app/CoCreate-api/commit/083b77eebec53f5523fd228ccfb1a88911e6132b))
14
+ * handeling of params ([9685e08](https://github.com/CoCreate-app/CoCreate-api/commit/9685e080d0bd0f3940aab9a7f277324c00526750))
15
+
1
16
  ## [1.20.4](https://github.com/CoCreate-app/CoCreate-api/compare/v1.20.3...v1.20.4) (2024-02-18)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/api",
3
- "version": "1.20.4",
3
+ "version": "1.20.6",
4
4
  "description": "A simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. CoCreate-api includes the client component and server side for api processing. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. ",
5
5
  "keywords": [
6
6
  "thirdparty-api-intergration",
@@ -59,11 +59,11 @@
59
59
  "webpack-log": "^3.0.1"
60
60
  },
61
61
  "dependencies": {
62
- "@cocreate/actions": "^1.15.1",
63
- "@cocreate/crud-client": "^1.32.2",
64
- "@cocreate/element-prototype": "^1.15.0",
65
- "@cocreate/render": "^1.37.1",
66
- "@cocreate/socket-client": "^1.36.1",
67
- "@cocreate/utils": "^1.30.0"
62
+ "@cocreate/actions": "^1.18.1",
63
+ "@cocreate/crud-client": "^1.33.8",
64
+ "@cocreate/element-prototype": "^1.22.2",
65
+ "@cocreate/render": "^1.40.3",
66
+ "@cocreate/socket-client": "^1.39.0",
67
+ "@cocreate/utils": "^1.33.6"
68
68
  }
69
69
  }
package/src/index.js CHANGED
@@ -124,9 +124,38 @@ const CoCreateApi = {
124
124
  Socket.send({ method: name + '.' + method, [name]: data, broadcast: false, broadcastBrowser: false, status: 'await' });
125
125
  },
126
126
 
127
- // TODO: handle $param operator
127
+ /**
128
+ * TODO: Implement Enhanced API Configuration Handling
129
+ *
130
+ * Description:
131
+ * - Implement functionality to dynamically handle API configurations, supporting both complete and base URL endpoints with automatic method-based path appending.
132
+ * - Enable dynamic generation of query parameters from a designated object (`stripe` in the examples) when `query` is true.
133
+ *
134
+ * Requirements:
135
+ * 1. Dynamic Endpoint Handling:
136
+ * - Check if the endpoint configuration is a complete URL or a base URL.
137
+ * - If the `method` derived path is not already included in the endpoint, append it dynamically.
138
+ * Example:
139
+ * `{ "method": "stripe.accounts.retrieve", "endpoint": "https://api.stripe.com", "query": true, "stripe": { "acct": "acct_123", "name": "John Doe" } }`
140
+ * `{ "method": "stripe.accounts.retrieve", "endpoint": "https://api.stripe.com/accounts/retrieve", "query": true, "stripe": { "acct": "acct_123", "name": "John Doe" } }`
141
+ * - Develop logic to parse the `method` and check against the endpoint. If necessary, append the appropriate API method segment.
142
+ *
143
+ * 2. Query Parameter Handling:
144
+ * - Dynamically construct and append query parameters from the `stripe` object if `query` is true. Ensure proper URL-encoding of keys and values.
145
+ *
146
+ * 3. Security:
147
+ * - Use the `method` for permission checks, ensuring that each API request complies with security protocols.
148
+ *
149
+ * 4. Testing:
150
+ * - Test both scenarios where the endpoint may or may not include the method path to ensure the dynamic construction works correctly.
151
+ * - Ensure that all query parameters are correctly formatted and appended.
152
+ *
153
+ * Notes:
154
+ * - Consider utility functions for parsing and modifying URLs, as well as for encoding parameters.
155
+ * - Maintain clear and detailed documentation for each part of the implementation to assist future development and troubleshooting.
156
+ */
128
157
  getData: async function ({ name, method, element, form }) {
129
- const data = {}
158
+ let data = {}
130
159
 
131
160
  if (!form && element)
132
161
  form = element.closest('form');
@@ -146,10 +175,23 @@ const CoCreateApi = {
146
175
  }
147
176
  }
148
177
 
149
- return dotNotationToObject(data);
178
+ let params = {}, hasParams = false
179
+ for (let i = 0; true; i++) {
180
+ if (`$param[${i}]` in data) {
181
+ params[`$param[${i}]`] = data[`$param[${i}]`]
182
+ delete data[`$param[${i}]`]
183
+ hasParams = true
184
+ } else {
185
+ break;
186
+ }
187
+ }
188
+ data = dotNotationToObject(data);
189
+ if (hasParams)
190
+ data = { ...params, ...data }
191
+
192
+ return data
150
193
  },
151
194
 
152
- // TODO: handle $param operator
153
195
  setData: function ({ name, method, data, form }) {
154
196
  if (!form)
155
197
  form = document;