@emoyly/problem 4.1.8 → 4.1.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.
Files changed (56) hide show
  1. package/defaults/4xx.d.ts +147 -0
  2. package/defaults/4xx.js +151 -0
  3. package/defaults/5xx.d.ts +57 -0
  4. package/defaults/5xx.js +61 -0
  5. package/defaults/aws.d.ts +12 -0
  6. package/defaults/aws.js +16 -0
  7. package/defaults/cloudflare.d.ts +47 -0
  8. package/defaults/cloudflare.js +52 -0
  9. package/defaults/iis.d.ts +17 -0
  10. package/defaults/iis.js +21 -0
  11. package/defaults/index.d.ts +7 -0
  12. package/defaults/index.js +17 -0
  13. package/defaults/nginx.d.ts +32 -0
  14. package/defaults/nginx.js +36 -0
  15. package/defaults/others.d.ts +37 -0
  16. package/defaults/others.js +40 -0
  17. package/index.d.ts +4 -0
  18. package/index.js +34 -0
  19. package/middleware/axios.d.ts +13 -0
  20. package/middleware/axios.js +36 -0
  21. package/middleware/base.d.ts +24 -0
  22. package/middleware/base.js +49 -0
  23. package/middleware/express.d.ts +19 -0
  24. package/middleware/express.js +57 -0
  25. package/package.json +7 -25
  26. package/parsers/axios.d.ts +3 -0
  27. package/parsers/axios.js +39 -0
  28. package/parsers/http.d.ts +3 -0
  29. package/parsers/http.js +15 -0
  30. package/parsers/jsonwebtoken.d.ts +3 -0
  31. package/parsers/jsonwebtoken.js +96 -0
  32. package/parsers/mikroorm.d.ts +3 -0
  33. package/parsers/mikroorm.js +15 -0
  34. package/parsers/tsoa.d.ts +3 -0
  35. package/parsers/tsoa.js +17 -0
  36. package/problem.d.ts +13 -0
  37. package/problem.js +50 -0
  38. package/tsconfig.tsbuildinfo +3797 -0
  39. package/typings/events.d.ts +2 -0
  40. package/typings/events.js +2 -0
  41. package/typings/index.d.ts +5 -0
  42. package/typings/index.js +17 -0
  43. package/typings/middleware.d.ts +9 -0
  44. package/typings/middleware.js +2 -0
  45. package/typings/misc.d.ts +3 -0
  46. package/typings/misc.js +2 -0
  47. package/typings/parser.d.ts +9 -0
  48. package/typings/parser.js +2 -0
  49. package/typings/problem.d.ts +23 -0
  50. package/typings/problem.js +12 -0
  51. package/util/events.d.ts +16 -0
  52. package/util/events.js +29 -0
  53. package/util/getProblems.d.ts +5 -0
  54. package/util/getProblems.js +45 -0
  55. package/util/version.d.ts +3 -0
  56. package/util/version.js +20 -0
@@ -0,0 +1,2 @@
1
+ import type { Problem } from '../problem';
2
+ export declare type ProblemListener = (problems: Problem[]) => void;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './middleware';
2
+ export * from './misc';
3
+ export * from './parser';
4
+ export * from './problem';
5
+ export * from './events';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./middleware"), exports);
14
+ __exportStar(require("./misc"), exports);
15
+ __exportStar(require("./parser"), exports);
16
+ __exportStar(require("./problem"), exports);
17
+ __exportStar(require("./events"), exports);
@@ -0,0 +1,9 @@
1
+ import type { Parser } from './parser';
2
+ export interface MiddlewareOptions {
3
+ /**
4
+ * A list of parsers to be used by the middleware.
5
+ * Parsers are run in the order they sit in the array
6
+ */
7
+ parsers: Parser[];
8
+ }
9
+ export declare type PartialMiddlewareOptions = Partial<MiddlewareOptions>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface ResponseHeaders {
2
+ [key: string]: string;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import type { Problem } from '../problem';
2
+ import type { ResponseHeaders } from './misc';
3
+ export declare type Parser = (input: any) => Problem[];
4
+ export interface HTTPErrorDetails {
5
+ statusCode?: number;
6
+ url: string;
7
+ body?: string;
8
+ headers?: ResponseHeaders;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @param {string} type - A URI refrence that identifies the problem type.
3
+ * @param {string} title - A short, human-readable summary of the problem
4
+ * type. It SHOULD NOT change from occurrence to occurrence of the problem
5
+ * @param {number} status - The HTTP status code
6
+ * @param {string} detail - A human-readable explanation specific to this
7
+ occurrence of the problem.
8
+ * @property {string} instance - A URI reference that identifies the specific
9
+ occurrence of the problem
10
+ **/
11
+ export interface IProblem {
12
+ type: string;
13
+ title: string;
14
+ status: number;
15
+ detail?: string;
16
+ instance?: string;
17
+ stack?: string;
18
+ errorObject?: unknown;
19
+ __problemVersion: string;
20
+ data?: any;
21
+ }
22
+ export declare type JsonProblem = Omit<IProblem, 'stack' | 'errorObject'>;
23
+ export declare type ProblemOpts = Omit<IProblem, '__problemVersion'>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * @param {string} type - A URI refrence that identifies the problem type.
4
+ * @param {string} title - A short, human-readable summary of the problem
5
+ * type. It SHOULD NOT change from occurrence to occurrence of the problem
6
+ * @param {number} status - The HTTP status code
7
+ * @param {string} detail - A human-readable explanation specific to this
8
+ occurrence of the problem.
9
+ * @property {string} instance - A URI reference that identifies the specific
10
+ occurrence of the problem
11
+ **/
12
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import type { ProblemListener } from '../typings/events';
2
+ import { Problem } from '../problem';
3
+ declare class ProblemEvents {
4
+ listeners: ProblemListener[];
5
+ emit: (list: Problem[]) => void;
6
+ /**
7
+ * Listen to problems
8
+ */
9
+ onProblem: (listener: ProblemListener) => void;
10
+ /**
11
+ * Un-listen to problems
12
+ */
13
+ offProblem: (listener: ProblemListener) => void;
14
+ }
15
+ declare const instance: ProblemEvents;
16
+ export default instance;
package/util/events.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ProblemEvents {
4
+ constructor() {
5
+ this.listeners = [];
6
+ this.emit = (list) => {
7
+ for (const listener of this.listeners) {
8
+ listener(list);
9
+ }
10
+ };
11
+ /**
12
+ * Listen to problems
13
+ */
14
+ this.onProblem = (listener) => {
15
+ this.listeners.push(listener);
16
+ };
17
+ /**
18
+ * Un-listen to problems
19
+ */
20
+ this.offProblem = (listener) => {
21
+ const idx = this.listeners.findIndex(val => val === listener);
22
+ if (idx < 0 || isNaN(idx))
23
+ return;
24
+ this.listeners.splice(idx, 1);
25
+ };
26
+ }
27
+ }
28
+ const instance = new ProblemEvents();
29
+ exports.default = instance;
@@ -0,0 +1,5 @@
1
+ import { Problem } from '../problem';
2
+ import type { JsonProblem } from '../typings/problem';
3
+ export declare function isJsonProblem(input: any): input is JsonProblem;
4
+ export declare function createFromJson({ title, type, instance, detail, status, data }: JsonProblem): Problem;
5
+ export declare function getProblems(input: any): Problem[] | void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProblems = exports.createFromJson = exports.isJsonProblem = void 0;
4
+ const problem_1 = require("../problem");
5
+ const version_1 = require("./version");
6
+ const strings = ['title', 'type', 'instance', 'detail', '__problemVersion'];
7
+ function isJsonProblem(input) {
8
+ if (typeof input !== 'object')
9
+ return false;
10
+ if (!strings.every(val => typeof input[val] === 'string'))
11
+ return false;
12
+ if (!version_1.isCompatibleVersion(input === null || input === void 0 ? void 0 : input.__problemVersion))
13
+ return false;
14
+ if (typeof input.status !== 'number')
15
+ return false;
16
+ return true;
17
+ }
18
+ exports.isJsonProblem = isJsonProblem;
19
+ function createFromJson({ title, type, instance, detail, status, data }) {
20
+ return new problem_1.Problem({ title, type, instance, detail, status, data });
21
+ }
22
+ exports.createFromJson = createFromJson;
23
+ function getProblems(input) {
24
+ if (typeof input === 'string') {
25
+ try {
26
+ const p = JSON.parse(input);
27
+ input = p;
28
+ }
29
+ catch (err) { /**/ }
30
+ }
31
+ if (input instanceof problem_1.Problem) {
32
+ return [input];
33
+ }
34
+ if (input instanceof Array && input.every(val => val instanceof problem_1.Problem)) {
35
+ return input;
36
+ }
37
+ if (input instanceof Array && input.every(val => isJsonProblem(val))) {
38
+ const _input = input;
39
+ return _input.map(val => createFromJson(val));
40
+ }
41
+ if (isJsonProblem(input)) {
42
+ return [createFromJson(input)];
43
+ }
44
+ }
45
+ exports.getProblems = getProblems;
@@ -0,0 +1,3 @@
1
+ export declare const version = "4.0.0";
2
+ export declare const major: number;
3
+ export declare function isCompatibleVersion(inputVersion: string): boolean;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCompatibleVersion = exports.major = exports.version = void 0;
4
+ exports.version = '4.0.0';
5
+ exports.major = Number(exports.version.split('.')[0]);
6
+ function isCompatibleVersion(inputVersion) {
7
+ // TODO: Remove this
8
+ if (inputVersion === 'lua-dev')
9
+ return true;
10
+ const parts = inputVersion.split('.');
11
+ const inputMajor = Number(parts[0]);
12
+ if (parts.length !== 3)
13
+ return false;
14
+ if (isNaN(inputMajor))
15
+ return false;
16
+ if (inputMajor !== exports.major)
17
+ return false;
18
+ return true;
19
+ }
20
+ exports.isCompatibleVersion = isCompatibleVersion;