@hellocoop/fastify 1.12.3 → 1.13.3
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 +2 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +24 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +2 -2
- package/package.json +8 -6
- package/dist/server.d.ts +0 -2
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -73
package/dist/auth.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FastifyPluginAsync } from 'fastify';
|
|
2
2
|
import { FastifyPluginOptions } from 'fastify';
|
|
3
|
-
import { Auth } from '@hellocoop/
|
|
4
|
-
import { Config } from '@hellocoop/
|
|
3
|
+
import { Auth } from '@hellocoop/definitions';
|
|
4
|
+
import { Config } from '@hellocoop/api';
|
|
5
5
|
declare module 'fastify' {
|
|
6
6
|
interface FastifyRequest {
|
|
7
7
|
auth?: Auth;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,kBAAkB,EACpB,MAAM,SAAS,CAAA;AAGjB,OAAO,EAGH,oBAAoB,EACvB,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,kBAAkB,EACpB,MAAM,SAAS,CAAA;AAGjB,OAAO,EAGH,oBAAoB,EACvB,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EASH,MAAM,EACT,MAAO,gBAAgB,CAAA;AAgDxB,OAAO,QAAQ,SAAS,CAAC;IACrB,UAAU,cAAc;QACtB,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;KAC7B;IACD,UAAU,YAAY;QACpB,SAAS,EAAE,MAAM,IAAI,CAAC;KACvB;CACF;AAEH,MAAM,WAAW,WAAY,SAAQ,oBAAoB,EAAE,MAAM;CAAG;AA8BpE,eAAO,MAAM,IAAI,iCAAoB,CAAA"}
|
package/dist/auth.js
CHANGED
|
@@ -7,22 +7,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.auth = void 0;
|
|
8
8
|
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
9
9
|
const cookie_1 = require("cookie");
|
|
10
|
-
const
|
|
11
|
-
const convertToHelloRequest = (req) => {
|
|
10
|
+
const api_1 = require("@hellocoop/api");
|
|
11
|
+
const convertToHelloRequest = (req, res) => {
|
|
12
12
|
return {
|
|
13
13
|
headers: () => { return req.headers; },
|
|
14
14
|
query: req.query,
|
|
15
|
-
path: req
|
|
15
|
+
path: req?.routeOptions?.url || '',
|
|
16
16
|
getAuth: () => { return req.auth; },
|
|
17
17
|
setAuth: (auth) => { req.auth = auth; },
|
|
18
18
|
method: req.method,
|
|
19
|
-
body: req.body
|
|
19
|
+
body: req.body,
|
|
20
|
+
frameWork: 'fastify',
|
|
21
|
+
loginSyncWrapper: (loginSync, params) => {
|
|
22
|
+
return loginSync({ ...params, req, res });
|
|
23
|
+
},
|
|
24
|
+
logoutSyncWrapper: (logoutSync) => {
|
|
25
|
+
return logoutSync({ req, res });
|
|
26
|
+
},
|
|
20
27
|
};
|
|
21
28
|
};
|
|
22
29
|
const convertToHelloResponse = (res) => {
|
|
23
30
|
return {
|
|
24
31
|
clearAuth: () => {
|
|
25
|
-
const { name, value, options } = (0,
|
|
32
|
+
const { name, value, options } = (0, api_1.clearAuthCookieParams)();
|
|
26
33
|
res.header('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
27
34
|
},
|
|
28
35
|
send: (data) => res.type('text/html').send(data),
|
|
@@ -42,27 +49,28 @@ const convertToHelloResponse = (res) => {
|
|
|
42
49
|
};
|
|
43
50
|
};
|
|
44
51
|
const helloPlugin = async (instance, options) => {
|
|
45
|
-
if (!
|
|
46
|
-
(0,
|
|
52
|
+
if (!api_1.isConfigured)
|
|
53
|
+
(0, api_1.configure)(options);
|
|
47
54
|
instance.decorateRequest('auth', undefined);
|
|
48
55
|
instance.decorateRequest('getAuth', async function () {
|
|
49
|
-
const
|
|
50
|
-
|
|
56
|
+
const dummyResponse = {};
|
|
57
|
+
const helloReq = convertToHelloRequest(this, dummyResponse);
|
|
58
|
+
this.auth = await (0, api_1.getAuthfromCookies)(helloReq);
|
|
51
59
|
return this.auth;
|
|
52
60
|
});
|
|
53
61
|
instance.decorateReply('clearAuth', function () {
|
|
54
|
-
const { name, value, options } = (0,
|
|
62
|
+
const { name, value, options } = (0, api_1.clearAuthCookieParams)();
|
|
55
63
|
this.header('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
56
64
|
});
|
|
57
|
-
instance.get(
|
|
58
|
-
const helloReq = convertToHelloRequest(req);
|
|
65
|
+
instance.get(api_1.configuration.apiRoute, async (req, res) => {
|
|
66
|
+
const helloReq = convertToHelloRequest(req, res);
|
|
59
67
|
const helloRes = convertToHelloResponse(res);
|
|
60
|
-
return await (0,
|
|
68
|
+
return await (0, api_1.router)(helloReq, helloRes);
|
|
61
69
|
});
|
|
62
|
-
instance.post(
|
|
63
|
-
const helloReq = convertToHelloRequest(req);
|
|
70
|
+
instance.post(api_1.configuration.apiRoute, async (req, res) => {
|
|
71
|
+
const helloReq = convertToHelloRequest(req, res);
|
|
64
72
|
const helloRes = convertToHelloResponse(res);
|
|
65
|
-
return await (0,
|
|
73
|
+
return await (0, api_1.router)(helloReq, helloRes);
|
|
66
74
|
});
|
|
67
75
|
};
|
|
68
76
|
exports.auth = (0, fastify_plugin_1.default)(helloPlugin);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { auth, HelloConfig } from './auth';
|
|
2
2
|
export default auth;
|
|
3
3
|
export { auth as helloAuth, HelloConfig };
|
|
4
|
-
export {
|
|
4
|
+
export { LoginSyncResponse, LogoutSyncResponse } from '@hellocoop/api';
|
|
5
5
|
export { redirect, unauthorized, setAuth } from './middleware';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC1C,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,WAAW,EAAE,CAAA;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC1C,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,WAAW,EAAE,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/middleware.d.ts
CHANGED
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAG7C,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,cAAc;QACtB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B;CACF;AAED,eAAO,MAAM,QAAQ,WAAY,MAAM,eACd,cAAc,SAAS,YAAY,uBAQ3D,CAAC;AAEF,eAAO,MAAM,YAAY,YAAmB,cAAc,SAAS,YAAY,uBAM9E,CAAC;AAEF,eAAO,MAAM,OAAO,YAAmB,cAAc,SAAS,YAAY,kBAEzE,CAAC"}
|
package/dist/middleware.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setAuth = exports.unauthorized = exports.redirect = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("@hellocoop/api");
|
|
5
5
|
const redirect = (target) => {
|
|
6
6
|
return async (request, reply) => {
|
|
7
7
|
const auth = await request.getAuth();
|
|
@@ -17,7 +17,7 @@ exports.redirect = redirect;
|
|
|
17
17
|
const unauthorized = async (request, reply) => {
|
|
18
18
|
const auth = await request.getAuth();
|
|
19
19
|
if (!auth.isLoggedIn) {
|
|
20
|
-
reply.header('WWW-Authenticate', `Hello ${
|
|
20
|
+
reply.header('WWW-Authenticate', `Hello ${api_1.configuration.clientId}`).status(401);
|
|
21
21
|
return reply.send();
|
|
22
22
|
}
|
|
23
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellocoop/fastify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.3",
|
|
4
4
|
"description": "Fastify SDK for Hellō https://hello.dev",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,9 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"watch": "tsc --watch --declaration",
|
|
38
|
-
"
|
|
39
|
-
"build
|
|
40
|
-
"
|
|
38
|
+
"prebuild": "rimraf dist node_modules",
|
|
39
|
+
"build": "tsc --declaration",
|
|
40
|
+
"test": "npm run build && docker compose -f ./spec/docker-compose.yml up --build --abort-on-container-exit",
|
|
41
|
+
"spec": "wait-on http://mockin:3333/mock && mocha './spec/**/*.spec.mjs'"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"fastify": "^4"
|
|
@@ -52,8 +53,9 @@
|
|
|
52
53
|
"node": ">=18"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@hellocoop/
|
|
56
|
+
"@hellocoop/api": "^2.0.3",
|
|
56
57
|
"dotenv": "^16.3.1",
|
|
57
58
|
"fastify-plugin": "^4.5.1"
|
|
58
|
-
}
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "018e57826706471620d6ac09e66121e53877c87e"
|
|
59
61
|
}
|
package/dist/server.d.ts
DELETED
package/dist/server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":""}
|
package/dist/server.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// test server
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
// import fastly from 'fastify'
|
|
8
|
-
// import auth from './index'
|
|
9
|
-
// import { redirect, unauthorized, setAuth } from './middleware'
|
|
10
|
-
// const app = fastly();
|
|
11
|
-
// const port = 8080; // default port to listen
|
|
12
|
-
// app.register(auth,{client_id:'90804992-8d01-474e-8a0c-59cddeb5a1a3'})
|
|
13
|
-
// app.get( "/", async ( req, res ) => {
|
|
14
|
-
// res.send( await req.getAuth())
|
|
15
|
-
// } );
|
|
16
|
-
// app.get( "/redirect", redirect('/'), async ( req, res ) => {
|
|
17
|
-
// res.send( await req.getAuth())
|
|
18
|
-
// } );
|
|
19
|
-
// app.get( "/unauthorized", unauthorized, async ( req, res ) => {
|
|
20
|
-
// res.send( await req.getAuth())
|
|
21
|
-
// } );
|
|
22
|
-
// app.get( "/setAuth", setAuth, ( req, res ) => {
|
|
23
|
-
// res.send( req.auth)
|
|
24
|
-
// } );
|
|
25
|
-
// // start the Express server
|
|
26
|
-
// app.listen( port, () => {
|
|
27
|
-
// console.log( `server started at http://localhost:${ port }` );
|
|
28
|
-
// } );
|
|
29
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
30
|
-
const index_1 = require("./index");
|
|
31
|
-
const middleware_1 = require("./middleware");
|
|
32
|
-
const config = require('../hello.config.js');
|
|
33
|
-
const app = (0, fastify_1.default)();
|
|
34
|
-
const port = 8080;
|
|
35
|
-
// Register your auth plugin with Fastify
|
|
36
|
-
app.register(index_1.helloAuth, config);
|
|
37
|
-
// Define your routes, using preHandler hooks to replace Express middleware
|
|
38
|
-
app.get("/", async (request, reply) => {
|
|
39
|
-
const auth = await request.getAuth();
|
|
40
|
-
return reply.send(auth);
|
|
41
|
-
});
|
|
42
|
-
app.get("/redirect", {
|
|
43
|
-
preHandler: (0, middleware_1.redirect)('/'),
|
|
44
|
-
handler: async (request, reply) => {
|
|
45
|
-
const auth = await request.getAuth();
|
|
46
|
-
return reply.send(auth);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
app.get("/unauthorized", {
|
|
50
|
-
preHandler: middleware_1.unauthorized,
|
|
51
|
-
handler: async (request, reply) => {
|
|
52
|
-
const auth = await request.getAuth();
|
|
53
|
-
return reply.send(auth);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
app.get("/setAuth", {
|
|
57
|
-
preHandler: middleware_1.setAuth,
|
|
58
|
-
handler: async (request, reply) => {
|
|
59
|
-
// Assuming setAuth sets something like request.auth
|
|
60
|
-
return reply.send(request.auth);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
const startServer = async () => {
|
|
64
|
-
try {
|
|
65
|
-
await app.listen({ port: port });
|
|
66
|
-
console.log(`Server started at http://localhost:${port}`);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
console.error(err);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
startServer();
|