@lwrjs/core 0.8.0 → 0.8.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.
|
@@ -28,7 +28,7 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_http = __toModule(require("http"));
|
|
30
30
|
var import_https = __toModule(require("https"));
|
|
31
|
-
var
|
|
31
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
32
|
var NetworkDispatcher = class {
|
|
33
33
|
constructor(port, internalRequestKey) {
|
|
34
34
|
this.port = port || 3e3;
|
|
@@ -39,7 +39,11 @@ var NetworkDispatcher = class {
|
|
|
39
39
|
this.internalRequestKey = internalRequestKey || "";
|
|
40
40
|
}
|
|
41
41
|
dispatchUrl(url, method, lang) {
|
|
42
|
-
const options =
|
|
42
|
+
const options = this.createRequestOptions(url, method, lang);
|
|
43
|
+
return this.handleRequest(options, url, method, lang);
|
|
44
|
+
}
|
|
45
|
+
createRequestOptions(url, method, lang) {
|
|
46
|
+
return {
|
|
43
47
|
method,
|
|
44
48
|
host: "localhost",
|
|
45
49
|
port: this.port,
|
|
@@ -50,41 +54,53 @@ var NetworkDispatcher = class {
|
|
|
50
54
|
"lwr-metadata-request": this.internalRequestKey
|
|
51
55
|
}
|
|
52
56
|
};
|
|
57
|
+
}
|
|
58
|
+
handleRequest(options, url, method, lang) {
|
|
53
59
|
return new Promise((resolve, reject) => {
|
|
54
60
|
const httpClient = options.port == 443 ? import_https.default : import_http.default;
|
|
55
61
|
const bodyChunks = [];
|
|
62
|
+
import_shared_utils.logger.verbose(`[NetworkDispatcher] Request: [${method}][${lang}] ${url}`);
|
|
56
63
|
const req = httpClient.request(options, (res) => {
|
|
57
64
|
res.on("data", (chunk) => {
|
|
58
65
|
bodyChunks.push(chunk);
|
|
59
66
|
});
|
|
60
67
|
res.on("end", () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
import_shared_utils.logger.verbose(`[END][NetworkDispatcher] Request: [${method}][${lang}] ${url}`);
|
|
69
|
+
if (!res.statusCode || res.statusCode >= 200 && res.statusCode < 300) {
|
|
70
|
+
const body = Buffer.concat(bodyChunks).toString();
|
|
71
|
+
try {
|
|
72
|
+
const jsonResponse = JSON.parse(body);
|
|
73
|
+
resolve(jsonResponse);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (import_shared_utils.logger.currentLevel == import_shared_utils.DEBUG || import_shared_utils.logger.currentLevel == import_shared_utils.VERBOSE) {
|
|
76
|
+
import_shared_utils.logger.warn(`[NetworkDispatcher] unexpected response body: [${method}][${lang}] ${url}: '${body}'`, err);
|
|
77
|
+
} else {
|
|
78
|
+
import_shared_utils.logger.warn(`[NetworkDispatcher] unexpected response body: [${method}][${lang}] ${url}: '${body}'`);
|
|
79
|
+
}
|
|
80
|
+
resolve({});
|
|
81
|
+
}
|
|
82
|
+
} else if (res.statusCode === 301 || res.statusCode === 302) {
|
|
83
|
+
if (res.headers?.location && (0, import_shared_utils.isModuleOrBundleUrl)(res.headers?.location)) {
|
|
84
|
+
import_shared_utils.logger.debug(`[NetworkDispatcher] Follow redirect: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`);
|
|
85
|
+
const location = res.headers.location;
|
|
86
|
+
return this.handleRequest(this.createRequestOptions(location, method, lang), location, method, lang).then((resRedirect) => resolve(resRedirect)).catch((rejectRedirect) => reject(rejectRedirect));
|
|
71
87
|
} else {
|
|
72
|
-
|
|
88
|
+
import_shared_utils.logger.warn(`Redirect not followed: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`);
|
|
89
|
+
resolve({});
|
|
73
90
|
}
|
|
91
|
+
} else {
|
|
92
|
+
import_shared_utils.logger.warn(`Unexpected status code: [${method}][${lang}][${res.statusCode}] ${url}`);
|
|
74
93
|
resolve({});
|
|
75
94
|
}
|
|
76
95
|
});
|
|
77
96
|
});
|
|
78
97
|
req.on("error", (err) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.log("LWR Diagnostic Error: ");
|
|
82
|
-
console.log(err.diagnostics);
|
|
83
|
-
console.log(err.stack);
|
|
98
|
+
if (import_shared_utils.logger.currentLevel == import_shared_utils.DEBUG || import_shared_utils.logger.currentLevel == import_shared_utils.VERBOSE) {
|
|
99
|
+
import_shared_utils.logger.warn(`[NetworkDispatcher] Request Failed: [${method}][${lang}] ${url}`, err);
|
|
84
100
|
} else {
|
|
85
|
-
|
|
101
|
+
import_shared_utils.logger.warn(`[NetworkDispatcher] Request Failed: [${method}][${lang}] ${url}`);
|
|
86
102
|
}
|
|
87
|
-
|
|
103
|
+
resolve({});
|
|
88
104
|
});
|
|
89
105
|
req.end();
|
|
90
106
|
});
|
|
@@ -7,5 +7,7 @@ export default class NetworkDispatcher implements LwrDispatcher {
|
|
|
7
7
|
pool: http.Agent;
|
|
8
8
|
constructor(port: number, internalRequestKey: string);
|
|
9
9
|
dispatchUrl(url: string, method: string, lang: string): Promise<FsContext>;
|
|
10
|
+
private createRequestOptions;
|
|
11
|
+
private handleRequest;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=network-dispatcher.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import https from 'https';
|
|
3
|
-
import {
|
|
3
|
+
import { DEBUG, isModuleOrBundleUrl, logger, VERBOSE } from '@lwrjs/shared-utils';
|
|
4
4
|
export default class NetworkDispatcher {
|
|
5
5
|
constructor(port, internalRequestKey) {
|
|
6
6
|
this.port = port || 3000;
|
|
@@ -11,7 +11,11 @@ export default class NetworkDispatcher {
|
|
|
11
11
|
this.internalRequestKey = internalRequestKey || '';
|
|
12
12
|
}
|
|
13
13
|
dispatchUrl(url, method, lang) {
|
|
14
|
-
const options =
|
|
14
|
+
const options = this.createRequestOptions(url, method, lang);
|
|
15
|
+
return this.handleRequest(options, url, method, lang);
|
|
16
|
+
}
|
|
17
|
+
createRequestOptions(url, method, lang) {
|
|
18
|
+
return {
|
|
15
19
|
method: method,
|
|
16
20
|
host: 'localhost',
|
|
17
21
|
port: this.port,
|
|
@@ -23,46 +27,65 @@ export default class NetworkDispatcher {
|
|
|
23
27
|
'lwr-metadata-request': this.internalRequestKey,
|
|
24
28
|
},
|
|
25
29
|
};
|
|
30
|
+
}
|
|
31
|
+
handleRequest(options, url, method, lang) {
|
|
26
32
|
return new Promise((resolve, reject) => {
|
|
27
33
|
const httpClient = options.port == 443 ? https : http;
|
|
28
34
|
const bodyChunks = [];
|
|
29
|
-
|
|
35
|
+
logger.verbose(`[NetworkDispatcher] Request: [${method}][${lang}] ${url}`);
|
|
30
36
|
const req = httpClient.request(options, (res) => {
|
|
31
37
|
res.on('data', (chunk) => {
|
|
32
38
|
bodyChunks.push(chunk);
|
|
33
39
|
});
|
|
34
40
|
res.on('end', () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
logger.verbose(`[END][NetworkDispatcher] Request: [${method}][${lang}] ${url}`);
|
|
42
|
+
if (!res.statusCode || (res.statusCode >= 200 && res.statusCode < 300)) {
|
|
43
|
+
const body = Buffer.concat(bodyChunks).toString();
|
|
44
|
+
try {
|
|
45
|
+
const jsonResponse = JSON.parse(body);
|
|
46
|
+
resolve(jsonResponse);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (logger.currentLevel == DEBUG || logger.currentLevel == VERBOSE) {
|
|
50
|
+
logger.warn(`[NetworkDispatcher] unexpected response body: [${method}][${lang}] ${url}: '${body}'`, err);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
logger.warn(`[NetworkDispatcher] unexpected response body: [${method}][${lang}] ${url}: '${body}'`);
|
|
54
|
+
}
|
|
55
|
+
resolve({});
|
|
56
|
+
}
|
|
40
57
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
else if (res.statusCode === 301 || res.statusCode === 302) {
|
|
59
|
+
// Lets follw if we know it is a module or bundle refrence
|
|
60
|
+
if (res.headers?.location && isModuleOrBundleUrl(res.headers?.location)) {
|
|
61
|
+
logger.debug(`[NetworkDispatcher] Follow redirect: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`);
|
|
62
|
+
const location = res.headers.location;
|
|
63
|
+
return (this.handleRequest(this.createRequestOptions(location, method, lang), location, method, lang)
|
|
64
|
+
// Send nested response to the resolve or reject functions defined above
|
|
65
|
+
.then((resRedirect) => resolve(resRedirect))
|
|
66
|
+
// Should not happen since we are just warning on error
|
|
67
|
+
.catch((rejectRedirect) => reject(rejectRedirect)));
|
|
47
68
|
}
|
|
48
69
|
else {
|
|
49
|
-
|
|
70
|
+
logger.warn(`Redirect not followed: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`);
|
|
71
|
+
resolve({});
|
|
50
72
|
}
|
|
73
|
+
}
|
|
74
|
+
// if any other status codes are returned, those needed to be added here
|
|
75
|
+
else {
|
|
76
|
+
logger.warn(`Unexpected status code: [${method}][${lang}][${res.statusCode}] ${url}`);
|
|
51
77
|
resolve({});
|
|
52
78
|
}
|
|
53
79
|
});
|
|
54
80
|
});
|
|
55
81
|
req.on('error', (err) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
console.log('LWR Diagnostic Error: ');
|
|
59
|
-
console.log(err.diagnostics);
|
|
60
|
-
console.log(err.stack);
|
|
82
|
+
if (logger.currentLevel == DEBUG || logger.currentLevel == VERBOSE) {
|
|
83
|
+
logger.warn(`[NetworkDispatcher] Request Failed: [${method}][${lang}] ${url}`, err);
|
|
61
84
|
}
|
|
62
85
|
else {
|
|
63
|
-
|
|
86
|
+
logger.warn(`[NetworkDispatcher] Request Failed: [${method}][${lang}] ${url}`);
|
|
64
87
|
}
|
|
65
|
-
|
|
88
|
+
resolve({});
|
|
66
89
|
});
|
|
67
90
|
req.end();
|
|
68
91
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.8.
|
|
7
|
+
"version": "0.8.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -32,32 +32,32 @@
|
|
|
32
32
|
"package.cjs"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@lwrjs/app-service": "0.8.
|
|
36
|
-
"@lwrjs/asset-registry": "0.8.
|
|
37
|
-
"@lwrjs/asset-transformer": "0.8.
|
|
38
|
-
"@lwrjs/base-template-engine": "0.8.
|
|
39
|
-
"@lwrjs/base-view-provider": "0.8.
|
|
40
|
-
"@lwrjs/base-view-transformer": "0.8.
|
|
41
|
-
"@lwrjs/client-modules": "0.8.
|
|
42
|
-
"@lwrjs/compiler": "0.8.
|
|
43
|
-
"@lwrjs/config": "0.8.
|
|
44
|
-
"@lwrjs/diagnostics": "0.8.
|
|
45
|
-
"@lwrjs/fs-asset-provider": "0.8.
|
|
46
|
-
"@lwrjs/html-view-provider": "0.8.
|
|
47
|
-
"@lwrjs/loader": "0.8.
|
|
48
|
-
"@lwrjs/lwc-module-provider": "0.8.
|
|
49
|
-
"@lwrjs/lwc-ssr": "0.8.
|
|
50
|
-
"@lwrjs/markdown-view-provider": "0.8.
|
|
51
|
-
"@lwrjs/module-bundler": "0.8.
|
|
52
|
-
"@lwrjs/module-registry": "0.8.
|
|
53
|
-
"@lwrjs/npm-module-provider": "0.8.
|
|
54
|
-
"@lwrjs/nunjucks-view-provider": "0.8.
|
|
55
|
-
"@lwrjs/o11y": "0.8.
|
|
56
|
-
"@lwrjs/resource-registry": "0.8.
|
|
57
|
-
"@lwrjs/router": "0.8.
|
|
58
|
-
"@lwrjs/server": "0.8.
|
|
59
|
-
"@lwrjs/shared-utils": "0.8.
|
|
60
|
-
"@lwrjs/view-registry": "0.8.
|
|
35
|
+
"@lwrjs/app-service": "0.8.1",
|
|
36
|
+
"@lwrjs/asset-registry": "0.8.1",
|
|
37
|
+
"@lwrjs/asset-transformer": "0.8.1",
|
|
38
|
+
"@lwrjs/base-template-engine": "0.8.1",
|
|
39
|
+
"@lwrjs/base-view-provider": "0.8.1",
|
|
40
|
+
"@lwrjs/base-view-transformer": "0.8.1",
|
|
41
|
+
"@lwrjs/client-modules": "0.8.1",
|
|
42
|
+
"@lwrjs/compiler": "0.8.1",
|
|
43
|
+
"@lwrjs/config": "0.8.1",
|
|
44
|
+
"@lwrjs/diagnostics": "0.8.1",
|
|
45
|
+
"@lwrjs/fs-asset-provider": "0.8.1",
|
|
46
|
+
"@lwrjs/html-view-provider": "0.8.1",
|
|
47
|
+
"@lwrjs/loader": "0.8.1",
|
|
48
|
+
"@lwrjs/lwc-module-provider": "0.8.1",
|
|
49
|
+
"@lwrjs/lwc-ssr": "0.8.1",
|
|
50
|
+
"@lwrjs/markdown-view-provider": "0.8.1",
|
|
51
|
+
"@lwrjs/module-bundler": "0.8.1",
|
|
52
|
+
"@lwrjs/module-registry": "0.8.1",
|
|
53
|
+
"@lwrjs/npm-module-provider": "0.8.1",
|
|
54
|
+
"@lwrjs/nunjucks-view-provider": "0.8.1",
|
|
55
|
+
"@lwrjs/o11y": "0.8.1",
|
|
56
|
+
"@lwrjs/resource-registry": "0.8.1",
|
|
57
|
+
"@lwrjs/router": "0.8.1",
|
|
58
|
+
"@lwrjs/server": "0.8.1",
|
|
59
|
+
"@lwrjs/shared-utils": "0.8.1",
|
|
60
|
+
"@lwrjs/view-registry": "0.8.1",
|
|
61
61
|
"fs-extra": "^10.1.0",
|
|
62
62
|
"ms": "^2.1.3",
|
|
63
63
|
"path-to-regexp": "^6.2.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"ws": "^8.8.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@lwrjs/types": "0.8.
|
|
68
|
+
"@lwrjs/types": "0.8.1",
|
|
69
69
|
"@types/ws": "^8.5.3"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=14.15.4 <19"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "171c43556c5624849c8ee6b61ef6de5b65630e38"
|
|
78
78
|
}
|