dromanis.finora.functions.common 1.0.1 → 1.0.2
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 +30 -2
- package/dist/corsHandler.d.ts +6 -0
- package/dist/corsHandler.d.ts.map +1 -0
- package/dist/corsHandler.js +24 -0
- package/dist/corsHandler.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ A set of common utilities used across different AWS Lambda functions in the Drom
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
- **userAuthenticator**: Easily add JWT authentication to your AWS Lambda functions.
|
|
7
|
+
- **corsHandler**: Handle CORS headers and OPTIONS requests for API Gateway responses.
|
|
7
8
|
- TypeScript-first, fully typed for safety and autocompletion.
|
|
8
9
|
- Includes automated tests and Husky hooks for code quality.
|
|
9
10
|
|
|
@@ -15,7 +16,9 @@ npm install dromanis.finora.functions.common
|
|
|
15
16
|
|
|
16
17
|
## Usage
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
### JWT Authentication
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
19
22
|
import { userAuthenticator } from 'dromanis.finora.functions.common';
|
|
20
23
|
import { APIGatewayProxyEvent } from 'aws-lambda';
|
|
21
24
|
|
|
@@ -32,7 +35,32 @@ export const handler = async (event: APIGatewayProxyEvent) => {
|
|
|
32
35
|
body: JSON.stringify({ message: 'Success!' })
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
|
-
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### CORS Handling
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { corsHandler } from 'dromanis.finora.functions.common';
|
|
44
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
|
|
45
|
+
|
|
46
|
+
const cors = new corsHandler();
|
|
47
|
+
|
|
48
|
+
export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
|
|
49
|
+
// Handle OPTIONS requests
|
|
50
|
+
if (event.httpMethod === 'OPTIONS') {
|
|
51
|
+
return cors.handleOptionsMethod();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Your main logic
|
|
55
|
+
const response = {
|
|
56
|
+
statusCode: 200,
|
|
57
|
+
body: JSON.stringify({ message: 'Success!' })
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Add CORS headers to your response
|
|
61
|
+
return cors.handleWithCors(response);
|
|
62
|
+
};
|
|
63
|
+
```
|
|
36
64
|
|
|
37
65
|
## Testing
|
|
38
66
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corsHandler.d.ts","sourceRoot":"","sources":["../src/corsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,qBAAa,WAAW;IACtB,cAAc,CAAC,QAAQ,EAAE,qBAAqB,GAAG,qBAAqB;IAYtE,mBAAmB,IAAI,qBAAqB;CAM7C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.corsHandler = void 0;
|
|
4
|
+
class corsHandler {
|
|
5
|
+
handleWithCors(response) {
|
|
6
|
+
return {
|
|
7
|
+
...response,
|
|
8
|
+
headers: {
|
|
9
|
+
...(response.headers || {}),
|
|
10
|
+
'Access-Control-Allow-Origin': '*',
|
|
11
|
+
'Access-Control-Allow-Headers': '*',
|
|
12
|
+
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
handleOptionsMethod() {
|
|
17
|
+
return this.handleWithCors({
|
|
18
|
+
statusCode: 200,
|
|
19
|
+
body: ''
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.corsHandler = corsHandler;
|
|
24
|
+
//# sourceMappingURL=corsHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corsHandler.js","sourceRoot":"","sources":["../src/corsHandler.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IACtB,cAAc,CAAC,QAA+B;QAC5C,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE;gBACP,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC;gBAC3B,6BAA6B,EAAE,GAAG;gBAClC,8BAA8B,EAAE,GAAG;gBACnC,8BAA8B,EAAE,6BAA6B;aAC9D;SACF,CAAC;IACJ,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,cAAc,CAAC;YACzB,UAAU,EAAE,GAAG;YACf,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC;CACF;AAnBD,kCAmBC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./userAuthenticator"), exports);
|
|
18
|
+
__exportStar(require("./corsHandler"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,gDAA8B"}
|