@lwrjs/diagnostics 0.7.0-alpha.0 → 0.7.0-alpha.11

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.
@@ -91,6 +91,10 @@ var configParser = (0, import_core_diagnostics.createDiagnosticsCategory)({
91
91
  category: "lwrConfig/invalidSchema",
92
92
  message: `Property "${configProperty}" must be a URI path string which starts but does not end with a slash, received ${actualProp}`
93
93
  }),
94
+ INVALID_BASEPATH: (configProperty, actualProp) => ({
95
+ category: "lwrConfig/invalidSchema",
96
+ message: `Property "${configProperty}" must be a URI base path string which starts with a slash, received ${actualProp}`
97
+ }),
94
98
  INVALID_SERVICE: (configProperty, actualProp) => ({
95
99
  category: "lwrConfig/invalidSchema",
96
100
  message: `Property "${configProperty}" must be a valid service (a non-empty string or array with [non-empty string, any]), received ${actualProp}`
@@ -67,6 +67,11 @@ var unresolvable = (0, import_core_diagnostics.createDiagnosticsCategory)({
67
67
  LABEL_MODULE: (file, error) => ({
68
68
  category: "lwrUnresolvable/label",
69
69
  message: `Invalid JSON: Labels file ${file} must be a JSON object with string values or nested string values
70
+ ${error}`
71
+ }),
72
+ ROUTES_MODULE: (file, error) => ({
73
+ category: "lwrUnresolvable/routes",
74
+ message: `Invalid JSON: Route config file ${file} is invalid
70
75
  ${error}`
71
76
  })
72
77
  });
@@ -1,9 +1,25 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2
7
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
8
  var __export = (target, all) => {
4
9
  for (var name in all)
5
10
  __defProp(target, name, {get: all[name], enumerable: true});
6
11
  };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
7
23
 
8
24
  // packages/@lwrjs/diagnostics/src/errors.ts
9
25
  __markAsModule(exports);
@@ -12,9 +28,15 @@ __export(exports, {
12
28
  LwrConfigValidationError: () => LwrConfigValidationError,
13
29
  LwrServerError: () => LwrServerError,
14
30
  LwrUnresolvableError: () => LwrUnresolvableError,
31
+ createReturnStatus: () => createReturnStatus,
15
32
  createSingleDiagnosticError: () => createSingleDiagnosticError,
16
33
  isNodeError: () => isNodeError
17
34
  });
35
+ var import_descriptions = __toModule(require("./descriptions/index.cjs"));
36
+ var import_dompurify = __toModule(require("dompurify"));
37
+ var import_jsdom = __toModule(require("jsdom"));
38
+ var window = new import_jsdom.JSDOM("").window;
39
+ var DOMPurify = (0, import_dompurify.default)(window);
18
40
  function isNodeError(error) {
19
41
  return error instanceof Error;
20
42
  }
@@ -46,3 +68,17 @@ var LwrUnresolvableError = class extends DiagnosticsError {
46
68
  };
47
69
  var LwrServerError = class extends DiagnosticsError {
48
70
  };
71
+ function createReturnStatus(name, error) {
72
+ let returnStatus = {status: 501, message: ""};
73
+ if (isNodeError(error) && error.code === "NO_LWC_MODULE_FOUND") {
74
+ returnStatus = {status: 404, message: import_descriptions.descriptions.UNRESOLVABLE.LWC_MODULE(name).message};
75
+ } else if (error instanceof LwrUnresolvableError && error.diagnostics[0].description.category === "lwrUnresolvable/invalid") {
76
+ returnStatus = {status: 400, message: error.message};
77
+ } else if (error instanceof LwrUnresolvableError) {
78
+ returnStatus = {status: 404, message: error.message};
79
+ } else {
80
+ returnStatus = {status: 500, message: import_descriptions.descriptions.UNRESOLVABLE.SERVER_ERROR(name).message};
81
+ }
82
+ returnStatus.message = DOMPurify.sanitize(returnStatus.message);
83
+ return returnStatus;
84
+ }
@@ -1,6 +1,6 @@
1
1
  export declare type DiagnosticCategory = DiagnosticLwrConfigCategory | DiagnosticCompiler | DiagnosticLwrUnresolvableCategory | DiagnosticLwrServer | '...more here';
2
2
  export declare type DiagnosticLwrConfigCategory = 'lwrConfig/invalidJson' | 'lwrConfig/invalidSchema';
3
- export declare type DiagnosticLwrUnresolvableCategory = 'lwrUnresolvable/asset' | 'lwrUnresolvable/module' | 'lwrUnresolvable/label' | 'lwrUnresolvable/resource' | 'lwrUnresolvable/invalid' | 'lwrUnresolvable/fatal';
3
+ export declare type DiagnosticLwrUnresolvableCategory = 'lwrUnresolvable/asset' | 'lwrUnresolvable/module' | 'lwrUnresolvable/label' | 'lwrUnresolvable/routes' | 'lwrUnresolvable/resource' | 'lwrUnresolvable/invalid' | 'lwrUnresolvable/fatal';
4
4
  export declare type DiagnosticCompiler = 'compile/umd_transform';
5
5
  export declare type DiagnosticLwrServer = 'lwrServer/warmupError';
6
6
  //# sourceMappingURL=categories.d.ts.map
@@ -114,6 +114,13 @@ export declare const configParser: {
114
114
  advice: import("../types.js").DiagnosticAdvice;
115
115
  message: string;
116
116
  };
117
+ INVALID_BASEPATH: (configProperty: string, actualProp: string) => Omit<{
118
+ category: "lwrConfig/invalidSchema";
119
+ message: string;
120
+ }, "message" | "advice"> & {
121
+ advice: import("../types.js").DiagnosticAdvice;
122
+ message: string;
123
+ };
117
124
  INVALID_SERVICE: (configProperty: string, actualProp: string) => Omit<{
118
125
  category: "lwrConfig/invalidSchema";
119
126
  message: string;
@@ -63,6 +63,10 @@ export const configParser = createDiagnosticsCategory({
63
63
  category: 'lwrConfig/invalidSchema',
64
64
  message: `Property "${configProperty}" must be a URI path string which starts but does not end with a slash, received ${actualProp}`,
65
65
  }),
66
+ INVALID_BASEPATH: (configProperty, actualProp) => ({
67
+ category: 'lwrConfig/invalidSchema',
68
+ message: `Property "${configProperty}" must be a URI base path string which starts with a slash, received ${actualProp}`,
69
+ }),
66
70
  INVALID_SERVICE: (configProperty, actualProp) => ({
67
71
  category: 'lwrConfig/invalidSchema',
68
72
  message: `Property "${configProperty}" must be a valid service (a non-empty string or array with [non-empty string, any]), received ${actualProp}`,
@@ -114,6 +114,13 @@ export declare const descriptions: {
114
114
  advice: import("../types.js").DiagnosticAdvice;
115
115
  message: string;
116
116
  };
117
+ INVALID_BASEPATH: (configProperty: string, actualProp: string) => Omit<{
118
+ category: "lwrConfig/invalidSchema";
119
+ message: string;
120
+ }, "message" | "advice"> & {
121
+ advice: import("../types.js").DiagnosticAdvice;
122
+ message: string;
123
+ };
117
124
  INVALID_SERVICE: (configProperty: string, actualProp: string) => Omit<{
118
125
  category: "lwrConfig/invalidSchema";
119
126
  message: string;
@@ -228,6 +235,13 @@ export declare const descriptions: {
228
235
  advice: import("../types.js").DiagnosticAdvice;
229
236
  message: string;
230
237
  };
238
+ ROUTES_MODULE: (file: string, error: string) => Omit<{
239
+ category: "lwrUnresolvable/routes";
240
+ message: string;
241
+ }, "message" | "advice"> & {
242
+ advice: import("../types.js").DiagnosticAdvice;
243
+ message: string;
244
+ };
231
245
  };
232
246
  SERVER: {
233
247
  WARMUP_ERROR: (error: string) => Omit<{
@@ -69,5 +69,12 @@ export declare const unresolvable: {
69
69
  advice: import("../types.js").DiagnosticAdvice;
70
70
  message: string;
71
71
  };
72
+ ROUTES_MODULE: (file: string, error: string) => Omit<{
73
+ category: "lwrUnresolvable/routes";
74
+ message: string;
75
+ }, "message" | "advice"> & {
76
+ advice: import("../types.js").DiagnosticAdvice;
77
+ message: string;
78
+ };
72
79
  };
73
80
  //# sourceMappingURL=unresolvable.d.ts.map
@@ -40,5 +40,9 @@ export const unresolvable = createDiagnosticsCategory({
40
40
  category: 'lwrUnresolvable/label',
41
41
  message: `Invalid JSON: Labels file ${file} must be a JSON object with string values or nested string values\n${error}`,
42
42
  }),
43
+ ROUTES_MODULE: (file, error) => ({
44
+ category: 'lwrUnresolvable/routes',
45
+ message: `Invalid JSON: Route config file ${file} is invalid\n${error}`,
46
+ }),
43
47
  });
44
48
  //# sourceMappingURL=unresolvable.js.map
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Diagnostic, Diagnostics } from './types';
2
+ import { Diagnostic, Diagnostics } from './types.js';
3
3
  export declare function isNodeError(error: unknown): error is NodeJS.ErrnoException;
4
4
  export declare function createSingleDiagnosticError(diag: Diagnostic, errorClass?: typeof DiagnosticsError): DiagnosticsError;
5
5
  export declare class DiagnosticsError extends Error {
@@ -15,4 +15,14 @@ export declare class LwrUnresolvableError extends DiagnosticsError {
15
15
  }
16
16
  export declare class LwrServerError extends DiagnosticsError {
17
17
  }
18
+ /**
19
+ * Create a status object Express can return when there is an error
20
+ *
21
+ * @param name - string name of the problem module/resource
22
+ * @param error - an Error/Diagnostic object; thrown from try/catch
23
+ */
24
+ export declare function createReturnStatus(name: string, error: unknown): {
25
+ status: number;
26
+ message: string;
27
+ };
18
28
  //# sourceMappingURL=errors.d.ts.map
@@ -1,3 +1,8 @@
1
+ import { descriptions } from './descriptions/index.js';
2
+ import createDOMPurify from 'dompurify';
3
+ import { JSDOM } from 'jsdom';
4
+ const window = new JSDOM('').window;
5
+ const DOMPurify = createDOMPurify(window);
1
6
  // The NodeJS Error is different from the JavaScript Error (e.g. NodeJS Error has a code)
2
7
  export function isNodeError(error) {
3
8
  return error instanceof Error;
@@ -32,4 +37,28 @@ export class LwrUnresolvableError extends DiagnosticsError {
32
37
  }
33
38
  export class LwrServerError extends DiagnosticsError {
34
39
  }
40
+ /**
41
+ * Create a status object Express can return when there is an error
42
+ *
43
+ * @param name - string name of the problem module/resource
44
+ * @param error - an Error/Diagnostic object; thrown from try/catch
45
+ */
46
+ export function createReturnStatus(name, error) {
47
+ let returnStatus = { status: 501, message: '' };
48
+ if (isNodeError(error) && error.code === 'NO_LWC_MODULE_FOUND') {
49
+ returnStatus = { status: 404, message: descriptions.UNRESOLVABLE.LWC_MODULE(name).message };
50
+ }
51
+ else if (error instanceof LwrUnresolvableError &&
52
+ error.diagnostics[0].description.category === 'lwrUnresolvable/invalid') {
53
+ returnStatus = { status: 400, message: error.message };
54
+ }
55
+ else if (error instanceof LwrUnresolvableError) {
56
+ returnStatus = { status: 404, message: error.message };
57
+ }
58
+ else {
59
+ returnStatus = { status: 500, message: descriptions.UNRESOLVABLE.SERVER_ERROR(name).message };
60
+ }
61
+ returnStatus.message = DOMPurify.sanitize(returnStatus.message);
62
+ return returnStatus;
63
+ }
35
64
  //# sourceMappingURL=errors.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.7.0-alpha.0",
7
+ "version": "0.7.0-alpha.11",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -29,11 +29,15 @@
29
29
  "build/**/*.cjs",
30
30
  "build/**/*.d.ts"
31
31
  ],
32
+ "dependencies": {
33
+ "dompurify": "^2.3.0",
34
+ "jsdom": "^16.7.0"
35
+ },
32
36
  "devDependencies": {
33
- "@lwrjs/types": "0.7.0-alpha.0"
37
+ "@lwrjs/types": "0.7.0-alpha.11"
34
38
  },
35
39
  "engines": {
36
40
  "node": ">=14.15.4 <17"
37
41
  },
38
- "gitHead": "4ed70d0bb9fd53feb629468b558b882adade0967"
42
+ "gitHead": "0b272d15905ec7b949974e8c5ba668a98eaa7e2d"
39
43
  }