Skip to content

Commit f6aa450

Browse files
committed
feat: attributes to handle endpoint and query
1 parent 0f83b78 commit f6aa450

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/index.js

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,6 @@ const CoCreateApi = {
124124
Socket.send({ method: name + '.' + method, [name]: data, broadcast: false, broadcastBrowser: false, status: 'await' });
125125
},
126126

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-
*/
157127
getData: async function ({ name, method, element, form }) {
158128
let data = {}
159129

@@ -173,6 +143,15 @@ const CoCreateApi = {
173143
if (key) {
174144
data[key] = await elements[i].getValue()
175145
}
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+
}
176155
}
177156

178157
let params = {}, hasParams = false
@@ -215,8 +194,12 @@ const CoCreateApi = {
215194
});
216195
} else {
217196
let key = elements[i].getAttribute(`${name}-key`)
218-
let value = getValueFromObject(data[name], key);
219-
elements[i].setValue(value);
197+
if (key === '{}')
198+
elements[i].setValue(data[name])
199+
else {
200+
let value = getValueFromObject(data[name], key);
201+
elements[i].setValue(value);
202+
}
220203
}
221204
}
222205
}

0 commit comments

Comments
 (0)