@cocreate/lazy-loader 1.23.5 → 1.23.7
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/.github/workflows/automated.yml +5 -6
- package/CHANGELOG.md +15 -0
- package/package.json +1 -9
- package/src/client.js +1 -0
- package/src/server.js +54 -43
|
@@ -22,13 +22,13 @@ jobs:
|
|
|
22
22
|
runs-on: ubuntu-latest
|
|
23
23
|
steps:
|
|
24
24
|
- name: Checkout
|
|
25
|
-
uses: actions/checkout@
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
26
|
- name: Setup Node.js
|
|
27
|
-
uses: actions/setup-node@
|
|
27
|
+
uses: actions/setup-node@v4
|
|
28
28
|
with:
|
|
29
|
-
node-version:
|
|
29
|
+
node-version: 22 # Required for the latest semantic-release plugins
|
|
30
30
|
- name: Semantic Release
|
|
31
|
-
uses: cycjimmy/semantic-release-action@
|
|
31
|
+
uses: cycjimmy/semantic-release-action@v4 # Update to v4 for better Node 20+ support
|
|
32
32
|
id: semantic
|
|
33
33
|
with:
|
|
34
34
|
extra_plugins: |
|
|
@@ -36,9 +36,8 @@ jobs:
|
|
|
36
36
|
@semantic-release/git
|
|
37
37
|
@semantic-release/github
|
|
38
38
|
env:
|
|
39
|
-
GITHUB_TOKEN: "${{ secrets.
|
|
39
|
+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # Use the built-in token if possible
|
|
40
40
|
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
|
|
41
41
|
outputs:
|
|
42
42
|
new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
|
|
43
43
|
new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
|
|
44
|
-
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.23.7](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.23.6...v1.23.7) (2026-02-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update worklow ([fb8b3a0](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/fb8b3a08cdea2595420f701f551d151c15f09803))
|
|
7
|
+
|
|
8
|
+
## [1.23.6](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.23.5...v1.23.6) (2025-09-01)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* improve request handling and error reporting in executeEndpoint ([b452259](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/b452259fb28b97421badf7aeb21c24d99d5599c0))
|
|
14
|
+
* replace valideUrl with urlObject for URL handling consistency ([d53fe8a](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/d53fe8a78f2120805c1a9a60a72a5ac13bb361be))
|
|
15
|
+
|
|
1
16
|
## [1.23.5](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.23.4...v1.23.5) (2025-05-01)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/lazy-loader",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.7",
|
|
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",
|
|
7
|
-
"cocreate",
|
|
8
|
-
"low-code-framework",
|
|
9
|
-
"no-code-framework",
|
|
10
|
-
"cocreatejs",
|
|
11
|
-
"cocreatejs-component",
|
|
12
|
-
"cocreate-framework",
|
|
13
|
-
"no-code",
|
|
14
7
|
"low-code",
|
|
15
|
-
"collaborative-framework",
|
|
16
8
|
"realtime",
|
|
17
9
|
"realtime-framework",
|
|
18
10
|
"collaboration",
|
package/src/client.js
CHANGED
|
@@ -52,6 +52,7 @@ function listen(name, callback, selector) {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// ToDo: accept an array of items and lazyLoad or load then fire CoCreateLoaded event
|
|
55
56
|
export async function lazyLoad(name, selector, callback) {
|
|
56
57
|
if (document.querySelector(selector)) {
|
|
57
58
|
await dependency(name, await callback());
|
package/src/server.js
CHANGED
|
@@ -47,8 +47,8 @@ class CoCreateLazyLoader {
|
|
|
47
47
|
async request(req, res) {
|
|
48
48
|
try {
|
|
49
49
|
// TODO: track usage
|
|
50
|
-
const
|
|
51
|
-
const hostname =
|
|
50
|
+
const urlObject = new URL(`http://${req.headers.host}${req.url}`);
|
|
51
|
+
const hostname = urlObject.hostname;
|
|
52
52
|
let organization;
|
|
53
53
|
|
|
54
54
|
try {
|
|
@@ -61,11 +61,11 @@ class CoCreateLazyLoader {
|
|
|
61
61
|
res,
|
|
62
62
|
this.crud,
|
|
63
63
|
organization,
|
|
64
|
-
|
|
64
|
+
urlObject
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
if (
|
|
68
|
+
if (urlObject.pathname.startsWith("/webhooks/")) {
|
|
69
69
|
let name = req.url.split("/")[2]; // Assuming URL structure is /webhooks/name/...
|
|
70
70
|
if (this.modules[name]) {
|
|
71
71
|
this.executeScriptWithTimeout(name, {
|
|
@@ -73,7 +73,7 @@ class CoCreateLazyLoader {
|
|
|
73
73
|
res,
|
|
74
74
|
host: hostname,
|
|
75
75
|
organization,
|
|
76
|
-
|
|
76
|
+
urlObject,
|
|
77
77
|
organization_id: organization._id
|
|
78
78
|
});
|
|
79
79
|
} else {
|
|
@@ -82,7 +82,7 @@ class CoCreateLazyLoader {
|
|
|
82
82
|
res.end(JSON.stringify({ error: "Not found" }));
|
|
83
83
|
}
|
|
84
84
|
} else {
|
|
85
|
-
this.files.send(req, res, this.crud, organization,
|
|
85
|
+
this.files.send(req, res, this.crud, organization, urlObject);
|
|
86
86
|
}
|
|
87
87
|
} catch (error) {
|
|
88
88
|
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
@@ -129,21 +129,47 @@ class CoCreateLazyLoader {
|
|
|
129
129
|
headers = { ...headers, ...override.headers }; // Correct idea for merging
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
let body = formatRequestBody(data[name]);
|
|
132
|
+
// let body = formatRequestBody(data[name]);
|
|
133
133
|
|
|
134
|
-
let
|
|
134
|
+
let formatType = data.formatType || "json";
|
|
135
|
+
const timeout = 10000; // Set default timeout in ms (e.g., 10 seconds)
|
|
136
|
+
let options = { method, headers, timeout };
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
// Only add body for methods that support it (not GET or HEAD)
|
|
139
|
+
if (!["GET", "HEAD"].includes(method)) {
|
|
140
|
+
let { body } = this.formatRequestBody(data[name], formatType);
|
|
141
|
+
options.body = body;
|
|
142
|
+
}
|
|
143
|
+
// For GET/HEAD, do not create or send a body; all params should be in the URL
|
|
144
|
+
|
|
145
|
+
const response = await this.makeHttpRequest(url, options);
|
|
146
|
+
|
|
147
|
+
// If the response is not ok, makeHttpRequest will throw and be caught below.
|
|
148
|
+
// If you want to include more info in the error, you can log or attach response details here.
|
|
149
|
+
|
|
150
|
+
data[name] = await response.json();
|
|
138
151
|
|
|
139
152
|
this.wsManager.send(data);
|
|
140
153
|
} catch (error) {
|
|
154
|
+
// Add more detail to the error for debugging 404s
|
|
141
155
|
data.error = error.message;
|
|
156
|
+
if (error.response) {
|
|
157
|
+
data.status = error.response.status;
|
|
158
|
+
data.statusText = error.response.statusText;
|
|
159
|
+
data.responseData = error.response.data;
|
|
160
|
+
}
|
|
142
161
|
if (data.req) {
|
|
143
162
|
data.res.writeHead(400, {
|
|
144
|
-
"Content-Type": "
|
|
163
|
+
"Content-Type": "application/json"
|
|
145
164
|
});
|
|
146
|
-
data.res.end(
|
|
165
|
+
data.res.end(
|
|
166
|
+
JSON.stringify({
|
|
167
|
+
error: data.error,
|
|
168
|
+
status: data.status,
|
|
169
|
+
statusText: data.statusText,
|
|
170
|
+
responseData: data.responseData
|
|
171
|
+
})
|
|
172
|
+
);
|
|
147
173
|
}
|
|
148
174
|
if (data.socket) {
|
|
149
175
|
this.wsManager.send(data);
|
|
@@ -255,13 +281,12 @@ class CoCreateLazyLoader {
|
|
|
255
281
|
* @throws {Error} If the request fails or returns a non-ok status.
|
|
256
282
|
*/
|
|
257
283
|
async makeHttpRequest(url, options) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
284
|
+
let controller, timeoutId;
|
|
285
|
+
if (this.server.AbortController) {
|
|
286
|
+
controller = new this.server.AbortController();
|
|
287
|
+
timeoutId = setTimeout(() => controller.abort(), options.timeout);
|
|
288
|
+
options.signal = controller.signal;
|
|
261
289
|
}
|
|
262
|
-
const controller = new this.server.AbortController();
|
|
263
|
-
const timeoutId = setTimeout(() => controller.abort(), options.timeout);
|
|
264
|
-
options.signal = controller.signal;
|
|
265
290
|
|
|
266
291
|
// Remove Content-Type header if there's no body (relevant for GET, DELETE etc.)
|
|
267
292
|
if (
|
|
@@ -272,46 +297,32 @@ class CoCreateLazyLoader {
|
|
|
272
297
|
delete options.headers["Content-Type"];
|
|
273
298
|
}
|
|
274
299
|
|
|
300
|
+
const fetchFn = this.server.fetch || global.fetch;
|
|
301
|
+
if (typeof fetchFn !== "function") {
|
|
302
|
+
throw new Error("No fetch implementation available.");
|
|
303
|
+
}
|
|
304
|
+
|
|
275
305
|
try {
|
|
276
|
-
const response = await
|
|
277
|
-
clearTimeout(timeoutId);
|
|
306
|
+
const response = await fetchFn(url, options);
|
|
307
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
278
308
|
|
|
279
309
|
if (!response.ok) {
|
|
280
|
-
|
|
310
|
+
const text = await response.text();
|
|
281
311
|
const error = new Error(
|
|
282
312
|
`HTTP error! Status: ${response.status} ${response.statusText}`
|
|
283
313
|
);
|
|
284
|
-
// Attach structured response info to the error
|
|
285
314
|
error.response = {
|
|
286
315
|
status: response.status,
|
|
287
316
|
statusText: response.statusText,
|
|
288
317
|
headers: Object.fromEntries(response.headers.entries()),
|
|
289
|
-
data:
|
|
318
|
+
data: text
|
|
290
319
|
};
|
|
291
320
|
throw error;
|
|
292
321
|
}
|
|
293
322
|
return response;
|
|
294
323
|
} catch (error) {
|
|
295
|
-
clearTimeout(timeoutId);
|
|
296
|
-
|
|
297
|
-
console.error(
|
|
298
|
-
`Request timed out after ${options.timeout}ms: ${options.method} ${url}`
|
|
299
|
-
);
|
|
300
|
-
throw new Error(
|
|
301
|
-
`Request Timeout: API call exceeded ${options.timeout}ms`
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// If it already has response info (from !response.ok), rethrow it
|
|
306
|
-
if (error.response) {
|
|
307
|
-
throw error;
|
|
308
|
-
}
|
|
309
|
-
// Otherwise, wrap other errors (network, DNS, etc.)
|
|
310
|
-
console.error(
|
|
311
|
-
`Network/Request Error: ${options.method} ${url}`,
|
|
312
|
-
error
|
|
313
|
-
);
|
|
314
|
-
throw new Error(`Network/Request Error: ${error.message}`);
|
|
324
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
325
|
+
throw error;
|
|
315
326
|
}
|
|
316
327
|
}
|
|
317
328
|
|