@prosopo/api-express-router 3.1.49 → 3.1.51
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/.turbo/turbo-build$colon$cjs.log +14 -12
- package/.turbo/turbo-build$colon$tsc.log +21 -21
- package/.turbo/turbo-build.log +16 -13
- package/CHANGELOG.md +22 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/apiExpressRouterFactory.js +17 -27
- package/dist/cjs/apiExpressRouterFactory.cjs +18 -28
- package/dist/cjs/endpointAdapter/apiExpressDefaultEndpointAdapter.cjs +29 -35
- package/dist/cjs/errorHandler.cjs +10 -10
- package/dist/cjs/index.cjs +14 -13
- package/dist/cjs/middlewares/authMiddleware.cjs +54 -56
- package/dist/cjs/middlewares/requestLoggerMiddleware.cjs +57 -59
- package/dist/endpointAdapter/apiExpressDefaultEndpointAdapter.js +26 -33
- package/dist/errorHandler.js +10 -10
- package/dist/index.js +8 -12
- package/dist/middlewares/authMiddleware.js +54 -57
- package/dist/middlewares/requestLoggerMiddleware.js +56 -58
- package/package.json +10 -10
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/api-express-router@3.1.
|
|
2
|
+
> @prosopo/api-express-router@3.1.51 build:cjs
|
|
3
3
|
> NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
|
|
4
4
|
|
|
5
5
|
ViteCommonJSConfig: .
|
|
@@ -43,16 +43,18 @@ ViteCommonJSConfig: .
|
|
|
43
43
|
'@prosopo/keyring'
|
|
44
44
|
]
|
|
45
45
|
}
|
|
46
|
-
[
|
|
46
|
+
[33mThe plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the [1mresolve.tsconfigPaths[22m option. You can remove the plugin and set [1mresolve.tsconfigPaths: true[22m in your Vite config instead.[39m
|
|
47
|
+
[36mvite v8.1.5 [32mbuilding ssr environment for production...[36m[39m
|
|
47
48
|
Bundle build started
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
[32m✓[39m 6 modules transformed.
|
|
49
|
+
[2K
|
|
50
|
+
✓ 7 modules transformed.
|
|
51
51
|
rendering chunks...
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
computing gzip size...
|
|
53
|
+
dist/cjs/errorHandler.cjs 0.45 kB │ gzip: 0.25 kB
|
|
54
|
+
dist/cjs/apiExpressRouterFactory.cjs 0.78 kB │ gzip: 0.35 kB
|
|
55
|
+
dist/cjs/endpointAdapter/apiExpressDefaultEndpointAdapter.cjs 1.05 kB │ gzip: 0.50 kB
|
|
56
|
+
dist/cjs/index.cjs 1.25 kB │ gzip: 0.37 kB
|
|
57
|
+
dist/cjs/middlewares/authMiddleware.cjs 1.71 kB │ gzip: 0.74 kB
|
|
58
|
+
dist/cjs/middlewares/requestLoggerMiddleware.cjs 1.81 kB │ gzip: 0.78 kB
|
|
59
|
+
|
|
60
|
+
[32m✓ built in 41ms[39m
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/api-express-router@3.1.
|
|
2
|
+
> @prosopo/api-express-router@3.1.51 build:tsc
|
|
3
3
|
> tsc --build --verbose
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
8:59:58 PM - Projects in this build:
|
|
6
6
|
* ../../dev/config/tsconfig.json
|
|
7
7
|
* ../util/tsconfig.json
|
|
8
8
|
* ../logger/tsconfig.json
|
|
@@ -22,41 +22,41 @@
|
|
|
22
22
|
* ../env/tsconfig.json
|
|
23
23
|
* tsconfig.json
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
8:59:58 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
8:59:58 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
8:59:58 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
8:59:58 PM - Project '../api-route/tsconfig.json' is up to date because newest input '../api-route/src/apiRoutes.ts' is older than output '../api-route/tsconfig.tsbuildinfo'
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
8:59:58 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
8:59:58 PM - Project '../util-crypto/tsconfig.json' is up to date because newest input '../util-crypto/src/types.ts' is older than output '../util-crypto/tsconfig.tsbuildinfo'
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
8:59:58 PM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/provider/api.ts' is older than output '../types/tsconfig.tsbuildinfo'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
8:59:58 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/tests/utils/batches.unit.test.ts' is older than output '../common/tsconfig.tsbuildinfo'
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
8:59:58 PM - Project '../ipinfo/tsconfig.json' is up to date because newest input '../ipinfo/src/IpInfoService.ts' is older than output '../ipinfo/tsconfig.tsbuildinfo'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
8:59:58 PM - Project '../redis-client/tsconfig.json' is up to date because newest input '../redis-client/src/index.ts' is older than output '../redis-client/tsconfig.tsbuildinfo'
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
8:59:58 PM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/index.ts' is older than output '../api/tsconfig.tsbuildinfo'
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
8:59:58 PM - Project '../user-access-policy/tsconfig.json' is up to date because newest input '../user-access-policy/src/ruleRecord.ts' is older than output '../user-access-policy/tsconfig.tsbuildinfo'
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
8:59:58 PM - Project '../types-database/tsconfig.json' is up to date because newest input '../types-database/src/types/bannedDomain.ts' is older than output '../types-database/tsconfig.tsbuildinfo'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
8:59:58 PM - Project '../database/tsconfig.json' is up to date because newest input '../database/src/tests/mongoGlobalSetup.ts' is older than output '../database/tsconfig.tsbuildinfo'
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
8:59:58 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/keyring/keyring.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
8:59:58 PM - Project '../types-env/tsconfig.json' is up to date because newest input '../types-env/src/index.ts' is older than output '../types-env/tsconfig.tsbuildinfo'
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
8:59:58 PM - Project '../env/tsconfig.json' is up to date because newest input '../env/src/index.ts' is older than output '../env/tsconfig.tsbuildinfo'
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
8:59:58 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
8:59:58 PM - Building project '/home/runner/work/captcha/captcha/packages/api-express-router/tsconfig.json'...
|
|
62
62
|
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/api-express-router@3.1.
|
|
2
|
+
> @prosopo/api-express-router@3.1.51 build
|
|
3
3
|
> npm run build:cross-env -- --mode ${NODE_ENV:-development}
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @prosopo/api-express-router@3.1.
|
|
6
|
+
> @prosopo/api-express-router@3.1.51 build:cross-env
|
|
7
7
|
> vite build --config vite.esm.config.ts --mode production
|
|
8
8
|
|
|
9
9
|
ViteEsmConfig: .
|
|
@@ -47,16 +47,19 @@ ViteEsmConfig: .
|
|
|
47
47
|
'@prosopo/keyring'
|
|
48
48
|
]
|
|
49
49
|
}
|
|
50
|
-
[
|
|
50
|
+
[33mThe plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the [1mresolve.tsconfigPaths[22m option. You can remove the plugin and set [1mresolve.tsconfigPaths: true[22m in your Vite config instead.[39m
|
|
51
|
+
[36mvite v8.1.5 [32mbuilding ssr environment for production...[36m[39m
|
|
51
52
|
Bundle build started
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
[32m✓[39m 6 modules transformed.
|
|
53
|
+
[2K
|
|
54
|
+
✓ 7 modules transformed.
|
|
55
55
|
rendering chunks...
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
computing gzip size...
|
|
57
|
+
dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
58
|
+
dist/errorHandler.js 0.42 kB │ gzip: 0.24 kB
|
|
59
|
+
dist/apiExpressRouterFactory.js 0.71 kB │ gzip: 0.34 kB
|
|
60
|
+
dist/index.js 0.84 kB │ gzip: 0.31 kB
|
|
61
|
+
dist/endpointAdapter/apiExpressDefaultEndpointAdapter.js 0.94 kB │ gzip: 0.47 kB
|
|
62
|
+
dist/middlewares/authMiddleware.js 1.60 kB │ gzip: 0.72 kB
|
|
63
|
+
dist/middlewares/requestLoggerMiddleware.js 1.75 kB │ gzip: 0.76 kB
|
|
64
|
+
|
|
65
|
+
[32m✓ built in 55ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @prosopo/api-express-router
|
|
2
2
|
|
|
3
|
+
## 3.1.51
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [a58d007]
|
|
7
|
+
- Updated dependencies [2c47bb7]
|
|
8
|
+
- Updated dependencies [0e1171c]
|
|
9
|
+
- Updated dependencies [103318c]
|
|
10
|
+
- Updated dependencies [270a8d8]
|
|
11
|
+
- Updated dependencies [e14fce6]
|
|
12
|
+
- @prosopo/api-route@2.6.53
|
|
13
|
+
- @prosopo/util@3.3.5
|
|
14
|
+
- @prosopo/locale@3.2.8
|
|
15
|
+
- @prosopo/types@4.10.0
|
|
16
|
+
- @prosopo/common@3.1.48
|
|
17
|
+
- @prosopo/env@3.6.20
|
|
18
|
+
- @prosopo/logger@2.0.4
|
|
19
|
+
|
|
20
|
+
## 3.1.50
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- @prosopo/env@3.6.19
|
|
24
|
+
|
|
3
25
|
## 3.1.49
|
|
4
26
|
### Patch Changes
|
|
5
27
|
|
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import { Router } from "express";
|
|
2
1
|
import { handleErrors } from "./errorHandler.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
request,
|
|
19
|
-
response,
|
|
20
|
-
next
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
ApiExpressRouterFactory
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
//#region src/apiExpressRouterFactory.ts
|
|
4
|
+
var ApiExpressRouterFactory = class {
|
|
5
|
+
createRouter(routersProvider, apiEndpointAdapter) {
|
|
6
|
+
const router = Router();
|
|
7
|
+
const apiRoutes = routersProvider.getRoutes();
|
|
8
|
+
this.registerRoutes(router, apiRoutes, apiEndpointAdapter);
|
|
9
|
+
router.use(handleErrors);
|
|
10
|
+
return router;
|
|
11
|
+
}
|
|
12
|
+
registerRoutes(router, routes, apiEndpointAdapter) {
|
|
13
|
+
for (const [route, endpoint] of Object.entries(routes)) router.post(route, async (request, response, next) => {
|
|
14
|
+
return await apiEndpointAdapter.handleRequest(endpoint, request, response, next);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
29
17
|
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ApiExpressRouterFactory };
|
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
endpoint,
|
|
20
|
-
request,
|
|
21
|
-
response,
|
|
22
|
-
next
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
const require_errorHandler = require("./errorHandler.cjs");
|
|
2
|
+
let express = require("express");
|
|
3
|
+
//#region src/apiExpressRouterFactory.ts
|
|
4
|
+
var ApiExpressRouterFactory = class {
|
|
5
|
+
createRouter(routersProvider, apiEndpointAdapter) {
|
|
6
|
+
const router = (0, express.Router)();
|
|
7
|
+
const apiRoutes = routersProvider.getRoutes();
|
|
8
|
+
this.registerRoutes(router, apiRoutes, apiEndpointAdapter);
|
|
9
|
+
router.use(require_errorHandler.handleErrors);
|
|
10
|
+
return router;
|
|
11
|
+
}
|
|
12
|
+
registerRoutes(router, routes, apiEndpointAdapter) {
|
|
13
|
+
for (const [route, endpoint] of Object.entries(routes)) router.post(route, async (request, response, next) => {
|
|
14
|
+
return await apiEndpointAdapter.handleRequest(endpoint, request, response, next);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
29
19
|
exports.ApiExpressRouterFactory = ApiExpressRouterFactory;
|
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
err: error
|
|
31
|
-
}));
|
|
32
|
-
response.status(500).send("An internal server error occurred.");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
let _prosopo_common = require("@prosopo/common");
|
|
2
|
+
let _prosopo_util = require("@prosopo/util");
|
|
3
|
+
//#region src/endpointAdapter/apiExpressDefaultEndpointAdapter.ts
|
|
4
|
+
var ApiExpressDefaultEndpointAdapter = class {
|
|
5
|
+
constructor(logLevel, errorStatusCode) {
|
|
6
|
+
this.logLevel = logLevel;
|
|
7
|
+
this.errorStatusCode = errorStatusCode;
|
|
8
|
+
}
|
|
9
|
+
async handleRequest(endpoint, request, response, next) {
|
|
10
|
+
let args;
|
|
11
|
+
try {
|
|
12
|
+
args = endpoint.getRequestArgsSchema()?.parse(request.body);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return next(new _prosopo_common.ProsopoApiError("API.PARSE_ERROR", { context: {
|
|
15
|
+
code: 400,
|
|
16
|
+
error
|
|
17
|
+
} }));
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const apiEndpointResponse = await endpoint.processRequest(args, request.logger);
|
|
21
|
+
const responseObject = (0, _prosopo_util.stringifyBigInts)(apiEndpointResponse);
|
|
22
|
+
response.json(responseObject);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
request.logger.error(() => ({ err: error }));
|
|
25
|
+
response.status(500).send("An internal server error occurred.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
36
30
|
exports.ApiExpressDefaultEndpointAdapter = ApiExpressDefaultEndpointAdapter;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
response.end();
|
|
1
|
+
let _prosopo_common = require("@prosopo/common");
|
|
2
|
+
//#region src/errorHandler.ts
|
|
3
|
+
var handleErrors = (err, request, response, next) => {
|
|
4
|
+
const { code, statusMessage, jsonError } = (0, _prosopo_common.unwrapError)(err, request.i18n);
|
|
5
|
+
response.statusMessage = statusMessage;
|
|
6
|
+
response.set("content-type", "application/json");
|
|
7
|
+
response.status(code);
|
|
8
|
+
response.send({ error: jsonError });
|
|
9
|
+
response.end();
|
|
11
10
|
};
|
|
11
|
+
//#endregion
|
|
12
12
|
exports.handleErrors = handleErrors;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
const require_errorHandler = require("./errorHandler.cjs");
|
|
3
|
+
const require_apiExpressRouterFactory = require("./apiExpressRouterFactory.cjs");
|
|
4
|
+
const require_apiExpressDefaultEndpointAdapter = require("./endpointAdapter/apiExpressDefaultEndpointAdapter.cjs");
|
|
5
|
+
const require_authMiddleware = require("./middlewares/authMiddleware.cjs");
|
|
6
|
+
const require_requestLoggerMiddleware = require("./middlewares/requestLoggerMiddleware.cjs");
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
var apiExpressRouterFactory = new require_apiExpressRouterFactory.ApiExpressRouterFactory();
|
|
9
|
+
var createApiExpressDefaultEndpointAdapter = (logLevel, errorStatusCode = 500) => {
|
|
10
|
+
return new require_apiExpressDefaultEndpointAdapter.ApiExpressDefaultEndpointAdapter(logLevel, errorStatusCode);
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
exports.authMiddleware = authMiddleware.authMiddleware;
|
|
14
|
-
exports.verifySignature = authMiddleware.verifySignature;
|
|
15
|
-
exports.requestLoggerMiddleware = requestLoggerMiddleware.requestLoggerMiddleware;
|
|
12
|
+
//#endregion
|
|
16
13
|
exports.apiExpressRouterFactory = apiExpressRouterFactory;
|
|
14
|
+
exports.authMiddleware = require_authMiddleware.authMiddleware;
|
|
17
15
|
exports.createApiExpressDefaultEndpointAdapter = createApiExpressDefaultEndpointAdapter;
|
|
16
|
+
exports.handleErrors = require_errorHandler.handleErrors;
|
|
17
|
+
exports.requestLoggerMiddleware = require_requestLoggerMiddleware.requestLoggerMiddleware;
|
|
18
|
+
exports.verifySignature = require_authMiddleware.verifySignature;
|
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
let _prosopo_common = require("@prosopo/common");
|
|
2
|
+
let _polkadot_util = require("@polkadot/util");
|
|
3
|
+
//#region src/middlewares/authMiddleware.ts
|
|
4
|
+
var authMiddleware = (pair, authAccount) => {
|
|
5
|
+
return async (req, res, next) => {
|
|
6
|
+
try {
|
|
7
|
+
const jwt = extractJWT(req);
|
|
8
|
+
if (authAccount?.jwtVerify(jwt).isValid) {
|
|
9
|
+
next();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (pair?.jwtVerify(jwt).isValid) {
|
|
13
|
+
next();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
res.status(401).json({ error: new _prosopo_common.ProsopoEnvError("API.UNAUTHORIZED", { context: {
|
|
17
|
+
i18n: req.i18n,
|
|
18
|
+
code: 401
|
|
19
|
+
} }) });
|
|
20
|
+
return;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
req.logger.error(() => ({
|
|
23
|
+
err,
|
|
24
|
+
msg: "Auth Middleware Error"
|
|
25
|
+
}));
|
|
26
|
+
res.status(401).json({
|
|
27
|
+
error: "Unauthorized",
|
|
28
|
+
message: err
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
30
33
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return jwt;
|
|
34
|
+
var extractJWT = (req) => {
|
|
35
|
+
const authHeader = req.headers.Authorization || req.headers.authorization;
|
|
36
|
+
if (!authHeader || typeof authHeader !== "string") throw new _prosopo_common.ProsopoApiError("GENERAL.MISSING_AUTH_HEADER", { context: {
|
|
37
|
+
error: "Missing Authorization header",
|
|
38
|
+
code: 401
|
|
39
|
+
} });
|
|
40
|
+
const jwt = authHeader.replace("Bearer ", "");
|
|
41
|
+
if (!jwt) throw new _prosopo_common.ProsopoApiError("GENERAL.INVALID_JWT", { context: {
|
|
42
|
+
error: "Missing JWT",
|
|
43
|
+
code: 400
|
|
44
|
+
} });
|
|
45
|
+
return jwt;
|
|
45
46
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
signature
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
47
|
+
var verifySignature = (signature, message, pair) => {
|
|
48
|
+
const u8Sig = (0, _polkadot_util.hexToU8a)(signature);
|
|
49
|
+
if (!pair.verify(message, u8Sig, pair.publicKey)) throw new _prosopo_common.ProsopoApiError("GENERAL.INVALID_SIGNATURE", { context: {
|
|
50
|
+
error: "Signature verification failed",
|
|
51
|
+
code: 401,
|
|
52
|
+
account: pair.address,
|
|
53
|
+
message,
|
|
54
|
+
signature
|
|
55
|
+
} });
|
|
59
56
|
};
|
|
57
|
+
//#endregion
|
|
60
58
|
exports.authMiddleware = authMiddleware;
|
|
61
59
|
exports.verifySignature = verifySignature;
|