@cocreate/lazy-loader 1.19.4 → 1.20.1

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.1](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.20.0...v1.20.1) (2024-06-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump cocreate dependencies ([8e19b5e](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/8e19b5e5b7e54f1141f28f44b2ffe438f995b91b))
7
+ * svg icon class ([2158676](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/215867667950fac30375e19362174a878498cb8f))
8
+
9
+ # [1.20.0](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.4...v1.20.0) (2024-05-19)
10
+
11
+
12
+ ### Features
13
+
14
+ * $crud operator handles an array of objects ([1cd7205](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/1cd7205b8a021cc9e98edb74cc3df7575357fd6e))
15
+
1
16
  ## [1.19.4](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.3...v1.19.4) (2024-05-10)
2
17
 
3
18
 
package/docs/index.html CHANGED
@@ -39,41 +39,31 @@
39
39
  href="https://github.com/CoCreate-app/CoCreate-lazy-loader"
40
40
  target="_blank"
41
41
  class="margin-right:15px"
42
- ><i
43
- class="height:20px fill:#505050"
44
- src="/assets/svg/github.svg"></i
42
+ ><i src="/assets/svg/github.svg"></i
45
43
  ></a>
46
44
  <a
47
45
  class="margin-right:15px share"
48
46
  share-network="twitter"
49
47
  title="Share on twitter"
50
- ><i
51
- class="height:20px fill:#505050"
52
- src="/assets/svg/twitter.svg"></i
48
+ ><i src="/assets/svg/twitter.svg"></i
53
49
  ></a>
54
50
  <a
55
51
  class="margin-right:15px share"
56
52
  share-network="facebook"
57
53
  title="Share on Facebook"
58
- ><i
59
- class="height:20px fill:#505050"
60
- src="/assets/svg/facebook.svg"></i
54
+ ><i src="/assets/svg/facebook.svg"></i
61
55
  ></a>
62
56
  <a
63
57
  class="margin-right:15px share"
64
58
  share-network="instagram"
65
59
  title="Share on instagram"
66
- ><i
67
- class="height:20px fill:#505050"
68
- src="/assets/svg/instagram.svg"></i
60
+ ><i src="/assets/svg/instagram.svg"></i
69
61
  ></a>
70
62
  <a
71
63
  class="margin-right:15px share"
72
64
  share-network="share"
73
65
  title="Share on share"
74
- ><i
75
- class="height:20px fill:#505050"
76
- src="/assets/svg/share-alt.svg"></i
66
+ ><i src="/assets/svg/share-alt.svg"></i
77
67
  ></a>
78
68
  </div>
79
69
  </div>
@@ -192,7 +182,7 @@
192
182
  toggle="code-height"
193
183
  toggle-selector="#demo-code"
194
184
  ><i
195
- class="height:18px fill:#505050"
185
+ class="height:18px"
196
186
  src="/assets/svg/eye.svg"></i
197
187
  ></a>
198
188
  <a
@@ -203,18 +193,14 @@
203
193
  hide="#eye-slash"
204
194
  toggle="code-height"
205
195
  toggle-selector="#demo-code"
206
- ><i
207
- class="height:20px fill:#505050"
208
- src="/assets/svg/eye-slash.svg"></i
196
+ ><i src="/assets/svg/eye-slash.svg"></i
209
197
  ></a>
210
198
  <a
211
199
  class="margin-right:10px"
212
200
  id="code"
213
201
  show="#code-slash"
214
202
  hide="#code, #demo-code"
215
- ><i
216
- class="height:20px fill:#505050"
217
- src="/assets/svg/code.svg"></i
203
+ ><i src="/assets/svg/code.svg"></i
218
204
  ></a>
219
205
  <a
220
206
  class="margin-right:10px"
@@ -223,7 +209,7 @@
223
209
  show="#code, #demo-code"
224
210
  hide="#code-slash"
225
211
  ><i
226
- class="display:flex height:18px fill:#505050"
212
+ class="height:18px"
227
213
  src="/assets/svg/code.svg"></i
228
214
  ></a>
229
215
  <a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/lazy-loader",
3
- "version": "1.19.4",
3
+ "version": "1.20.1",
4
4
  "description": "A simple lazy-loader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "lazy-loader",
@@ -58,7 +58,7 @@
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
60
  "dependencies": {
61
- "@cocreate/config": "^1.12.2",
62
- "@cocreate/observer": "^1.16.0"
61
+ "@cocreate/config": "^1.12.3",
62
+ "@cocreate/observer": "^1.16.1"
63
63
  }
64
64
  }
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
- context = await this.processOperators(data, event, context);
341
- result = await this.crud.send(context)
342
- if (operator.startsWith('$crud.'))
343
- result = getValueFromObject(operator, operator.substring(6))
344
- return await this.processOperators(data, event, result);
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)