dromanis.finora.functions.common 1.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/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # dromanis.finora.functions.common
2
+
3
+ A set of common utilities used across different AWS Lambda functions in the Dromanis Finora ecosystem.
4
+
5
+ ## Features
6
+ - **userAuthenticator**: Easily add JWT authentication to your AWS Lambda functions.
7
+ - TypeScript-first, fully typed for safety and autocompletion.
8
+ - Includes automated tests and Husky hooks for code quality.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ npm install dromanis.finora.functions.common
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ````typescript
19
+ import { userAuthenticator } from 'dromanis.finora.functions.common';
20
+ import { APIGatewayProxyEvent } from 'aws-lambda';
21
+
22
+ const authenticator = new userAuthenticator();
23
+
24
+ export const handler = async (event: APIGatewayProxyEvent) => {
25
+ const result = authenticator.authenticate(event);
26
+ if (result.statusCode !== 200) {
27
+ return result;
28
+ }
29
+ // Proceed with your logic
30
+ return {
31
+ statusCode: 200,
32
+ body: JSON.stringify({ message: 'Success!' })
33
+ };
34
+ };
35
+ ````
36
+
37
+ ## Testing
38
+
39
+ This project uses [Jest](https://jestjs.io/) for testing. To run tests:
40
+
41
+ ```
42
+ npm test
43
+ ```
44
+
45
+ Tests are automatically run before every commit and push using [Husky](https://typicode.github.io/husky/).
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork the repository
50
+ 2. Create your feature branch (`git checkout -b feature/YourFeature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin feature/YourFeature`)
53
+ 5. Create a new Pull Request
54
+
55
+ ## License
56
+
57
+ ISC
@@ -0,0 +1,2 @@
1
+ export * from './userAuthenticator';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./userAuthenticator"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
@@ -0,0 +1,9 @@
1
+ import { APIGatewayProxyEvent } from 'aws-lambda';
2
+ export declare class userAuthenticator {
3
+ constructor();
4
+ authenticate(event: APIGatewayProxyEvent): {
5
+ statusCode: number;
6
+ body: string;
7
+ };
8
+ }
9
+ //# sourceMappingURL=userAuthenticator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userAuthenticator.d.ts","sourceRoot":"","sources":["../src/userAuthenticator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGlD,qBAAa,iBAAiB;;IAK1B,YAAY,CAAC,KAAK,EAAE,oBAAoB;;;;CA6B3C"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.userAuthenticator = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ class userAuthenticator {
9
+ constructor() {
10
+ // Initialization logic if needed
11
+ }
12
+ authenticate(event) {
13
+ const authHeader = event.headers?.['Authorization'] || event.headers?.['authorization'];
14
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
15
+ return {
16
+ statusCode: 401,
17
+ body: JSON.stringify({ error: 'Missing or invalid Authorization header' })
18
+ };
19
+ }
20
+ const token = authHeader.replace('Bearer ', '');
21
+ const secret = process.env['JWT_SECRET'];
22
+ if (!secret) {
23
+ return {
24
+ statusCode: 500,
25
+ body: JSON.stringify({ error: 'JWT secret not configured' })
26
+ };
27
+ }
28
+ try {
29
+ jsonwebtoken_1.default.verify(token, secret);
30
+ return {
31
+ statusCode: 200,
32
+ body: JSON.stringify({ message: 'Authenticated' })
33
+ };
34
+ }
35
+ catch (err) {
36
+ return {
37
+ statusCode: 401,
38
+ body: JSON.stringify({ error: 'Invalid or expired token' })
39
+ };
40
+ }
41
+ }
42
+ }
43
+ exports.userAuthenticator = userAuthenticator;
44
+ //# sourceMappingURL=userAuthenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userAuthenticator.js","sourceRoot":"","sources":["../src/userAuthenticator.ts"],"names":[],"mappings":";;;;;;AACA,gEAA+B;AAE/B,MAAa,iBAAiB;IAC1B;QACI,iCAAiC;IACrC,CAAC;IAED,YAAY,CAAC,KAA2B;QACpC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC;QACxF,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACnD,OAAO;gBACH,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,yCAAyC,EAAE,CAAC;aAC7E,CAAC;QACN,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO;gBACH,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,2BAA2B,EAAE,CAAC;aAC/D,CAAC;QACN,CAAC;QACD,IAAI,CAAC;YACD,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC1B,OAAO;gBACH,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;aACrD,CAAC;QACN,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO;gBACH,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,0BAA0B,EAAE,CAAC;aAC9D,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AAlCD,8CAkCC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "dromanis.finora.functions.common",
3
+ "version": "1.0.1",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "clean": "rm -rf dist",
13
+ "test": "jest --config jest.config.js",
14
+ "prepare": "husky install"
15
+ },
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "description": "The set of common utiltities used across by different lambda functions",
20
+ "devDependencies": {
21
+ "@types/aws-lambda": "^8.10.150",
22
+ "@types/jest": "^30.0.0",
23
+ "@types/jsonwebtoken": "^9.0.10",
24
+ "@types/node": "^24.0.10",
25
+ "husky": "^9.1.7",
26
+ "jest": "^29.7.0",
27
+ "ts-jest": "^29.4.0",
28
+ "typescript": "^5.8.3"
29
+ },
30
+ "dependencies": {
31
+ "aws-lambda": "^1.0.7",
32
+ "jsonwebtoken": "^9.0.2"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }