@degenerate/endpoints 0.0.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/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) [2024] [Degenerateiinc.ca]
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @Degenerate/<new-package-name> Package
2
+
3
+ This package contains the functions for <new-package-name>. The package <what-the-purpose-of-the-package-is> in the SAFE environment.
@@ -0,0 +1,12 @@
1
+ import { NextFunction, Request } from 'express';
2
+ import { BaseError } from '@degenerate/generic';
3
+ /**
4
+ * This is used to handle all errors. It is the last error handler in the chain.
5
+ *
6
+ * @param err the error
7
+ * @param req the incoming request
8
+ * @param res the response
9
+ * @param next the next function
10
+ */
11
+ export declare function allErrorHandler(err: BaseError, req: Request, res: any, next: NextFunction): void;
12
+ //# sourceMappingURL=all-error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"all-error-handler.d.ts","sourceRoot":"","sources":["../../../src/cors/errors/all-error-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AAElE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,GAAG,EAAE,SAAS,EACd,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,YAAY,GACnB,IAAI,CAON"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.allErrorHandler = allErrorHandler;
4
+ /**
5
+ * This is used to handle all errors. It is the last error handler in the chain.
6
+ *
7
+ * @param err the error
8
+ * @param req the incoming request
9
+ * @param res the response
10
+ * @param next the next function
11
+ */
12
+ function allErrorHandler(err, req, res, next) {
13
+ console.error(err);
14
+ const genericResponse = {
15
+ successful: false,
16
+ error: 'An error occurred. That is all we know.',
17
+ };
18
+ return res.status(err.errorCode || 500).send(genericResponse);
19
+ }
@@ -0,0 +1,12 @@
1
+ import { NextFunction } from 'express';
2
+ /**
3
+ * bad request moddleware handler
4
+ *
5
+ * @param err the error
6
+ * @param req the incoming request
7
+ * @param res the response
8
+ * @param next next function
9
+ * @returns
10
+ */
11
+ export declare function badRequestHandler(err: any, req: any, res: any, next: NextFunction): any;
12
+ //# sourceMappingURL=bad-request-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bad-request-handler.d.ts","sourceRoot":"","sources":["../../../src/cors/errors/bad-request-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,OAWjF"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.badRequestHandler = badRequestHandler;
4
+ const generic_1 = require("@degenerate/generic");
5
+ /**
6
+ * bad request moddleware handler
7
+ *
8
+ * @param err the error
9
+ * @param req the incoming request
10
+ * @param res the response
11
+ * @param next next function
12
+ * @returns
13
+ */
14
+ function badRequestHandler(err, req, res, next) {
15
+ if (err instanceof generic_1.BaseError && err.errorCode === 400) {
16
+ console.error(err.toJSON());
17
+ const response = {
18
+ successful: false,
19
+ error: 'Bad Request',
20
+ };
21
+ return res.status(400).send(response);
22
+ }
23
+ next(err);
24
+ return;
25
+ }
@@ -0,0 +1,12 @@
1
+ import { NextFunction } from 'express';
2
+ /**
3
+ * This is used to handle unauthorized requests in the middleware
4
+ *
5
+ * @param err the error
6
+ * @param req the incoming request
7
+ * @param res the response
8
+ * @param next the next function
9
+ * @returns
10
+ */
11
+ export declare function unauthorizedHandler(err: any, req: any, res: any, next: NextFunction): any;
12
+ //# sourceMappingURL=unauthorized-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unauthorized-handler.d.ts","sourceRoot":"","sources":["../../../src/cors/errors/unauthorized-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,OAWnF"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unauthorizedHandler = unauthorizedHandler;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const generic_1 = require("@degenerate/generic");
6
+ /**
7
+ * This is used to handle unauthorized requests in the middleware
8
+ *
9
+ * @param err the error
10
+ * @param req the incoming request
11
+ * @param res the response
12
+ * @param next the next function
13
+ * @returns
14
+ */
15
+ function unauthorizedHandler(err, req, res, next) {
16
+ if (err instanceof generic_1.BaseError && err.errorCode === 403) {
17
+ console.error(err.toJSON());
18
+ const response = {
19
+ successful: false,
20
+ error: 'Unauthorized',
21
+ };
22
+ return res.status(403).send(response);
23
+ }
24
+ next(err);
25
+ return;
26
+ }
@@ -0,0 +1,4 @@
1
+ export * from './errors/all-error-handler';
2
+ export * from './errors/bad-request-handler';
3
+ export * from './errors/unauthorized-handler';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cors/index.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ //#region cors functions
18
+ __exportStar(require("./errors/all-error-handler"), exports);
19
+ __exportStar(require("./errors/bad-request-handler"), exports);
20
+ __exportStar(require("./errors/unauthorized-handler"), exports);
21
+ //#endregion cors functions
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ // This is the main file for the package
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@degenerate/endpoints",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "devDependencies": {
7
+ "@types/jest": "^29.5.14",
8
+ "@types/node": "^22.9.0",
9
+ "jest": "^29.7.0",
10
+ "ts-jest": "^29.2.5",
11
+ "typescript": "^5.6.3"
12
+ },
13
+ "scripts": {
14
+ "build": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
15
+ "compile": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
16
+ "test": "jest --forceExit --detectOpenHandles --verbose --silent=false --env node --config tsconfig.pkg.json",
17
+ "test:coverage": "jest --forceExit --coverage --detectOpenHandles --verbose --silent=false --env node --config tsconfig.pkg.json",
18
+ "test:clearCache": "jest --clearCache"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/syncrude/safe.git"
23
+ },
24
+ "keywords": [
25
+ "ShareData Adaptive Framework Ecosystem",
26
+ "SAFE",
27
+ "SAFE Endpoints",
28
+ "ShareData",
29
+ "ShareBlock",
30
+ "SAFE RESTful API",
31
+ "SAFE Websockets",
32
+ "SAFE RxJS",
33
+ "SAFE Observables"
34
+ ],
35
+ "bugs": {
36
+ "url": "https://github.com/syncrude/safe/issues"
37
+ },
38
+ "homepage": "https://github.com/syncrude/safe#readme",
39
+ "author": "Degenerate Inc.",
40
+ "license": "ISC",
41
+ "dependencies": {
42
+ "@degenerate/generic": "^0.1.3"
43
+ }
44
+ }