@cocreate/lazy-loader 1.19.4 → 1.20.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/server.js +51 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.20.0](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.4...v1.20.0) (2024-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* $crud operator handles an array of objects ([1cd7205](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/1cd7205b8a021cc9e98edb74cc3df7575357fd6e))
|
|
7
|
+
|
|
1
8
|
## [1.19.4](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.3...v1.19.4) (2024-05-10)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -150,6 +150,37 @@ class CoCreateLazyLoader {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
/**
|
|
154
|
+
* TODO: Implement Enhanced API Configuration Handling
|
|
155
|
+
*
|
|
156
|
+
* Description:
|
|
157
|
+
* - Implement functionality to dynamically handle API configurations, supporting both complete and base URL endpoints with automatic method-based path appending.
|
|
158
|
+
* - Enable dynamic generation of query parameters from a designated object (`stripe` in the examples) when `query` is true.
|
|
159
|
+
*
|
|
160
|
+
* Requirements:
|
|
161
|
+
* 1. Dynamic Endpoint Handling:
|
|
162
|
+
* - Check if the endpoint configuration is a complete URL or a base URL.
|
|
163
|
+
* - If the `method` derived path is not already included in the endpoint, append it dynamically.
|
|
164
|
+
* Example:
|
|
165
|
+
* `{ "method": "stripe.accounts.retrieve", "endpoint": "https://api.stripe.com", "query": true, "stripe": { "acct": "acct_123", "name": "John Doe" } }`
|
|
166
|
+
* `{ "method": "stripe.accounts.retrieve", "endpoint": "https://api.stripe.com/accounts/retrieve", "query": true, "stripe": { "acct": "acct_123", "name": "John Doe" } }`
|
|
167
|
+
* - Develop logic to parse the `method` and check against the endpoint. If necessary, append the appropriate API method segment.
|
|
168
|
+
*
|
|
169
|
+
* 2. Query Parameter Handling:
|
|
170
|
+
* - Dynamically construct and append query parameters from the `stripe` object if `query` is true. Ensure proper URL-encoding of keys and values.
|
|
171
|
+
*
|
|
172
|
+
* 3. Security:
|
|
173
|
+
* - Use the `method` for permission checks, ensuring that each API request complies with security protocols.
|
|
174
|
+
*
|
|
175
|
+
* 4. Testing:
|
|
176
|
+
* - Test both scenarios where the endpoint may or may not include the method path to ensure the dynamic construction works correctly.
|
|
177
|
+
* - Ensure that all query parameters are correctly formatted and appended.
|
|
178
|
+
*
|
|
179
|
+
* Notes:
|
|
180
|
+
* - Consider utility functions for parsing and modifying URLs, as well as for encoding parameters.
|
|
181
|
+
* - Maintain clear and detailed documentation for each part of the implementation to assist future development and troubleshooting.
|
|
182
|
+
*/
|
|
183
|
+
|
|
153
184
|
async api(config, data) {
|
|
154
185
|
try {
|
|
155
186
|
const methodPath = data.method.split('.')
|
|
@@ -161,6 +192,7 @@ class CoCreateLazyLoader {
|
|
|
161
192
|
if (!key)
|
|
162
193
|
throw new Error(`Missing ${name} key in organization apis object`);
|
|
163
194
|
|
|
195
|
+
// ToDo: if data.endpoint service not required as endpoint will be used
|
|
164
196
|
const service = require(config.path);
|
|
165
197
|
let instance
|
|
166
198
|
if (config.initialize)
|
|
@@ -337,11 +369,25 @@ class CoCreateLazyLoader {
|
|
|
337
369
|
} else if (operator.startsWith('$rawBody')) {
|
|
338
370
|
return getValueFromObject(data, operator.substring(1))
|
|
339
371
|
} else if (operator.startsWith('$crud')) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
|
|
372
|
+
let results = context
|
|
373
|
+
let isObject = false
|
|
374
|
+
if (!Array.isArray(results)) {
|
|
375
|
+
isObject = true
|
|
376
|
+
results = [results]
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
for (let i = 0; i < results.length; i++) {
|
|
380
|
+
results[i] = await this.processOperators(data, event, results[i]);
|
|
381
|
+
results[i] = await this.crud.send(results[i])
|
|
382
|
+
if (operator.startsWith('$crud.'))
|
|
383
|
+
results[i] = getValueFromObject(operator, operator.substring(6))
|
|
384
|
+
results[i] = await this.processOperators(data, event, results[i])
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (isObject)
|
|
388
|
+
results = results[0]
|
|
389
|
+
|
|
390
|
+
return results;
|
|
345
391
|
} else if (operator.startsWith('$socket')) {
|
|
346
392
|
context = await this.processOperators(data, event, context);
|
|
347
393
|
result = await this.socket.send(context)
|