@cocreate/api
Advanced tools
Comparing version 1.20.6 to 1.21.0
{ | ||
"name": "@cocreate/api", | ||
"version": "1.20.6", | ||
"version": "1.21.0", | ||
"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,0 +5,0 @@ "keywords": [ |
@@ -127,32 +127,2 @@ /*globals CustomEvent, config*/ | ||
/** | ||
* TODO: Implement Enhanced API Configuration Handling | ||
* | ||
* Description: | ||
* - Implement functionality to dynamically handle API configurations, supporting both complete and base URL endpoints with automatic method-based path appending. | ||
* - Enable dynamic generation of query parameters from a designated object (`stripe` in the examples) when `query` is true. | ||
* | ||
* Requirements: | ||
* 1. Dynamic Endpoint Handling: | ||
* - Check if the endpoint configuration is a complete URL or a base URL. | ||
* - If the `method` derived path is not already included in the endpoint, append it dynamically. | ||
* Example: | ||
* `{ "method": "stripe.accounts.retrieve", "endpoint": "https://api.stripe.com", "query": true, "stripe": { "acct": "acct_123", "name": "John Doe" } }` | ||
* `{ "method": "stripe.accounts.retrieve", "endpoint": "https://api.stripe.com/accounts/retrieve", "query": true, "stripe": { "acct": "acct_123", "name": "John Doe" } }` | ||
* - Develop logic to parse the `method` and check against the endpoint. If necessary, append the appropriate API method segment. | ||
* | ||
* 2. Query Parameter Handling: | ||
* - Dynamically construct and append query parameters from the `stripe` object if `query` is true. Ensure proper URL-encoding of keys and values. | ||
* | ||
* 3. Security: | ||
* - Use the `method` for permission checks, ensuring that each API request complies with security protocols. | ||
* | ||
* 4. Testing: | ||
* - Test both scenarios where the endpoint may or may not include the method path to ensure the dynamic construction works correctly. | ||
* - Ensure that all query parameters are correctly formatted and appended. | ||
* | ||
* Notes: | ||
* - Consider utility functions for parsing and modifying URLs, as well as for encoding parameters. | ||
* - Maintain clear and detailed documentation for each part of the implementation to assist future development and troubleshooting. | ||
*/ | ||
getData: async function ({ name, method, element, form }) { | ||
@@ -177,2 +147,11 @@ let data = {} | ||
} | ||
let endpoint = elements[i].getAttribute('endpoint') | ||
if (endpoint) { | ||
data.endpoint = endpoint | ||
} | ||
if (elements[i].getAttribute('query') && elements[i].getAttribute('query') !== 'false') { | ||
data.query = true | ||
} | ||
} | ||
@@ -220,4 +199,8 @@ | ||
let key = elements[i].getAttribute(`${name}-key`) | ||
let value = getValueFromObject(data[name], key); | ||
elements[i].setValue(value); | ||
if (key === '{}') | ||
elements[i].setValue(data[name]) | ||
else { | ||
let value = getValueFromObject(data[name], key); | ||
elements[i].setValue(value); | ||
} | ||
} | ||
@@ -224,0 +207,0 @@ } |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190194
345