@cocreate/api 1.20.6 → 1.21.0
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 +7 -0
- package/package.json +1 -1
- package/src/index.js +15 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.21.0](https://github.com/CoCreate-app/CoCreate-api/compare/v1.20.6...v1.21.0) (2024-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* attributes to handle endpoint and query ([f6aa450](https://github.com/CoCreate-app/CoCreate-api/commit/f6aa4502147e5ef9e6f6d24daf326de14829b710))
|
|
7
|
+
|
|
1
8
|
## [1.20.6](https://github.com/CoCreate-app/CoCreate-api/compare/v1.20.5...v1.20.6) (2024-04-29)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
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",
|
package/src/index.js
CHANGED
|
@@ -124,36 +124,6 @@ const CoCreateApi = {
|
|
|
124
124
|
Socket.send({ method: name + '.' + method, [name]: data, broadcast: false, broadcastBrowser: false, status: 'await' });
|
|
125
125
|
},
|
|
126
126
|
|
|
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
|
-
*/
|
|
157
127
|
getData: async function ({ name, method, element, form }) {
|
|
158
128
|
let data = {}
|
|
159
129
|
|
|
@@ -173,6 +143,15 @@ const CoCreateApi = {
|
|
|
173
143
|
if (key) {
|
|
174
144
|
data[key] = await elements[i].getValue()
|
|
175
145
|
}
|
|
146
|
+
|
|
147
|
+
let endpoint = elements[i].getAttribute('endpoint')
|
|
148
|
+
if (endpoint) {
|
|
149
|
+
data.endpoint = endpoint
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (elements[i].getAttribute('query') && elements[i].getAttribute('query') !== 'false') {
|
|
153
|
+
data.query = true
|
|
154
|
+
}
|
|
176
155
|
}
|
|
177
156
|
|
|
178
157
|
let params = {}, hasParams = false
|
|
@@ -215,8 +194,12 @@ const CoCreateApi = {
|
|
|
215
194
|
});
|
|
216
195
|
} else {
|
|
217
196
|
let key = elements[i].getAttribute(`${name}-key`)
|
|
218
|
-
|
|
219
|
-
|
|
197
|
+
if (key === '{}')
|
|
198
|
+
elements[i].setValue(data[name])
|
|
199
|
+
else {
|
|
200
|
+
let value = getValueFromObject(data[name], key);
|
|
201
|
+
elements[i].setValue(value);
|
|
202
|
+
}
|
|
220
203
|
}
|
|
221
204
|
}
|
|
222
205
|
}
|