@hellocoop/express 1.12.2 → 1.14.0
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/dist/auth.d.ts +21 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +12 -5
- package/package.json +2 -2
package/dist/auth.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
import { Auth } from '@hellocoop/types';
|
|
3
|
-
import { Config } from '@hellocoop/router';
|
|
4
|
-
|
|
1
|
+
import { Router, Request, Response } from 'express';
|
|
2
|
+
import { Auth, Claims } from '@hellocoop/types';
|
|
3
|
+
import { LoginSyncResponse, LogoutSyncResponse, Config } from '@hellocoop/router';
|
|
4
|
+
type ExpressLoginParams = {
|
|
5
|
+
token: string;
|
|
6
|
+
payload: Claims;
|
|
7
|
+
target_uri: string;
|
|
8
|
+
req: Request;
|
|
9
|
+
res: Response;
|
|
10
|
+
};
|
|
11
|
+
type ExpressLogoutParams = {
|
|
12
|
+
req: Request;
|
|
13
|
+
res: Response;
|
|
14
|
+
};
|
|
15
|
+
type ExpressLoginSync = (params: ExpressLoginParams) => Promise<LoginSyncResponse>;
|
|
16
|
+
type ExpressLogoutSync = (params: ExpressLogoutParams) => Promise<LogoutSyncResponse>;
|
|
17
|
+
export type HelloConfig = Omit<Config, 'loginSync' | 'logoutSync'> & {
|
|
18
|
+
loginSync: ExpressLoginSync;
|
|
19
|
+
logoutSync: ExpressLogoutSync;
|
|
20
|
+
};
|
|
5
21
|
declare global {
|
|
6
22
|
namespace Express {
|
|
7
23
|
interface Request {
|
|
@@ -14,4 +30,5 @@ declare global {
|
|
|
14
30
|
}
|
|
15
31
|
}
|
|
16
32
|
export declare const auth: (config: Config) => Router;
|
|
33
|
+
export {};
|
|
17
34
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAsB,MAAM,SAAS,CAAA;AAEvE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAIH,iBAAiB,EACjB,kBAAkB,EAKlB,MAAM,EAET,MAAM,mBAAmB,CAAA;AAG1B,KAAK,kBAAkB,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAA;CAChB,CAAA;AAED,KAAK,mBAAmB,GAAG;IACvB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAA;CAChB,CAAA;AAED,KAAK,gBAAgB,GAAG,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAClF,KAAK,iBAAiB,GAAG,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAErF,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAAC,GAAG;IACjE,SAAS,EAAE,gBAAgB,CAAC;IAC5B,UAAU,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAuDF,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE,IAAI,CAAC;YACZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QACD,UAAU,QAAQ;YAChB,SAAS,IAAI,IAAI,CAAC;SACnB;KACF;CACF;AAmBH,eAAO,MAAM,IAAI,WAAsB,MAAM,KAAG,MAmC/C,CAAA"}
|
package/dist/auth.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.auth = void 0;
|
|
|
4
4
|
const express_1 = require("express");
|
|
5
5
|
const cookie_1 = require("cookie");
|
|
6
6
|
const router_1 = require("@hellocoop/router");
|
|
7
|
-
const convertToHelloRequest = (req) => {
|
|
7
|
+
const convertToHelloRequest = (req, res) => {
|
|
8
8
|
return {
|
|
9
9
|
headers: () => req.headers,
|
|
10
10
|
query: req.query,
|
|
@@ -12,7 +12,14 @@ const convertToHelloRequest = (req) => {
|
|
|
12
12
|
getAuth: () => req.auth,
|
|
13
13
|
setAuth: (auth) => { req.auth = auth; },
|
|
14
14
|
method: req.method,
|
|
15
|
-
body: req.body
|
|
15
|
+
body: req.body,
|
|
16
|
+
frameWork: 'express',
|
|
17
|
+
loginSyncWrapper: (loginSync, params) => {
|
|
18
|
+
return loginSync({ ...params, req, res });
|
|
19
|
+
},
|
|
20
|
+
logoutSyncWrapper: (logoutSync) => {
|
|
21
|
+
return logoutSync({ req, res });
|
|
22
|
+
},
|
|
16
23
|
};
|
|
17
24
|
};
|
|
18
25
|
const convertToHelloResponse = (res) => {
|
|
@@ -69,7 +76,7 @@ const auth = function (config) {
|
|
|
69
76
|
console.log({ isConfigured: router_1.isConfigured, configuration: router_1.configuration });
|
|
70
77
|
const r = (0, express_1.Router)();
|
|
71
78
|
r.use(async (req, res, next) => {
|
|
72
|
-
const helloReq = convertToHelloRequest(req);
|
|
79
|
+
const helloReq = convertToHelloRequest(req, res);
|
|
73
80
|
req.getAuth = async () => {
|
|
74
81
|
req.auth = await (0, router_1.getAuthfromCookies)(helloReq);
|
|
75
82
|
return req.auth;
|
|
@@ -82,12 +89,12 @@ const auth = function (config) {
|
|
|
82
89
|
});
|
|
83
90
|
r.use((0, express_1.text)()); // for parsing text/plain
|
|
84
91
|
r.post(router_1.configuration.apiRoute, async (req, res) => {
|
|
85
|
-
const helloReq = convertToHelloRequest(req);
|
|
92
|
+
const helloReq = convertToHelloRequest(req, res);
|
|
86
93
|
const helloRes = convertToHelloResponse(res);
|
|
87
94
|
await (0, router_1.router)(helloReq, helloRes);
|
|
88
95
|
});
|
|
89
96
|
r.get(router_1.configuration.apiRoute, async (req, res) => {
|
|
90
|
-
const helloReq = convertToHelloRequest(req);
|
|
97
|
+
const helloReq = convertToHelloRequest(req, res);
|
|
91
98
|
const helloRes = convertToHelloResponse(res);
|
|
92
99
|
await (0, router_1.router)(helloReq, helloRes);
|
|
93
100
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellocoop/express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Express SDK for Hellō https://hello.dev",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@hellocoop/constants": "~1.1.6",
|
|
63
63
|
"@hellocoop/core": "~1.4.8",
|
|
64
|
-
"@hellocoop/router": "
|
|
64
|
+
"@hellocoop/router": "1.14",
|
|
65
65
|
"cookie": "^0.5.0",
|
|
66
66
|
"cors": "^2.8.5",
|
|
67
67
|
"dotenv": "^16.3.1"
|