@leanstacks/lambda-utils 0.1.0-alpha.4 → 0.1.0-alpha.5
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/.github/workflows/ci.yml +43 -0
- package/.github/workflows/publish.yml +51 -0
- package/.husky/pre-commit +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/logger.d.ts +59 -0
- package/package.json +8 -1
- package/rollup.config.js +18 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Continuous Integration
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
ci:
|
|
15
|
+
name: Build, Lint, and Test
|
|
16
|
+
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
timeout-minutes: 5
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout repository
|
|
22
|
+
uses: actions/checkout@v5
|
|
23
|
+
|
|
24
|
+
- name: Setup Node.js
|
|
25
|
+
uses: actions/setup-node@v5
|
|
26
|
+
with:
|
|
27
|
+
node-version-file: '.nvmrc'
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: npm ci
|
|
32
|
+
|
|
33
|
+
- name: Lint code
|
|
34
|
+
run: npm run lint
|
|
35
|
+
|
|
36
|
+
- name: Check code formatting
|
|
37
|
+
run: npm run format:check
|
|
38
|
+
|
|
39
|
+
- name: Build
|
|
40
|
+
run: npm run build
|
|
41
|
+
|
|
42
|
+
- name: Run tests with coverage
|
|
43
|
+
run: npm run test:coverage
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- published
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}
|
|
11
|
+
cancel-in-progress: false
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
contents: read
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
name: Build and Publish
|
|
20
|
+
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
timeout-minutes: 10
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- name: Checkout repository
|
|
26
|
+
uses: actions/checkout@v5
|
|
27
|
+
|
|
28
|
+
- name: Setup Node.js
|
|
29
|
+
uses: actions/setup-node@v5
|
|
30
|
+
with:
|
|
31
|
+
node-version-file: '.nvmrc'
|
|
32
|
+
cache: 'npm'
|
|
33
|
+
registry-url: 'https://registry.npmjs.org'
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: npm ci
|
|
37
|
+
|
|
38
|
+
- name: Lint code
|
|
39
|
+
run: npm run lint
|
|
40
|
+
|
|
41
|
+
- name: Check code formatting
|
|
42
|
+
run: npm run format:check
|
|
43
|
+
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: npm run test
|
|
46
|
+
|
|
47
|
+
- name: Build
|
|
48
|
+
run: npm run build
|
|
49
|
+
|
|
50
|
+
- name: Publish
|
|
51
|
+
run: npm publish
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Logger, LoggerConfig, withRequestTracking } from './logging/logger';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"pino";import{lambdaRequestTracker as n,StructuredLogFormatter as t,CloudwatchLogFormatter as o,pinoLambdaDestination as i}from"pino-lambda";const l=n();class r{constructor(n){this._loggerConfig={enabled:!0,level:"info",format:"json"},this._instance=null,this._createLogger=()=>{const n="json"===this._loggerConfig.format?new t:new o,l=i({formatter:n});return e({enabled:this._loggerConfig.enabled,level:this._loggerConfig.level},l)},n&&(this._loggerConfig={enabled:n.enabled??!0,level:n.level??"info",format:n.format??"json"})}get instance(){return null===this._instance&&(this._instance=this._createLogger()),this._instance}}export{r as Logger,l as withRequestTracking};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("pino"),t=require("pino-lambda");const n=t.lambdaRequestTracker();exports.Logger=class{constructor(n){this._loggerConfig={enabled:!0,level:"info",format:"json"},this._instance=null,this._createLogger=()=>{const n="json"===this._loggerConfig.format?new t.StructuredLogFormatter:new t.CloudwatchLogFormatter,r=t.pinoLambdaDestination({formatter:n});return e({enabled:this._loggerConfig.enabled,level:this._loggerConfig.level},r)},n&&(this._loggerConfig={enabled:n.enabled??!0,level:n.level??"info",format:n.format??"json"})}get instance(){return null===this._instance&&(this._instance=this._createLogger()),this._instance}},exports.withRequestTracking=n;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
/**
|
|
3
|
+
* Logger middleware which adds AWS Lambda attributes to log messages.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { withRequestTracking } from '@leanstacks/lambda-utils';
|
|
8
|
+
*
|
|
9
|
+
* export const handler = async (event, context) => {
|
|
10
|
+
* withRequestTracking(event, context);
|
|
11
|
+
*
|
|
12
|
+
* // Your Lambda handler logic here
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const withRequestTracking: (event: import("pino-lambda").LambdaEvent, context: import("pino-lambda").LambdaContext) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options for the Logger
|
|
19
|
+
*/
|
|
20
|
+
export interface LoggerConfig {
|
|
21
|
+
/** Whether logging is enabled */
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
/** Minimum log level (e.g., 'debug', 'info', 'warn', 'error') */
|
|
24
|
+
level?: 'debug' | 'info' | 'warn' | 'error';
|
|
25
|
+
/** Output format: 'json' for StructuredLogFormatter, 'text' for CloudwatchLogFormatter */
|
|
26
|
+
format?: 'json' | 'text';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Logger class which provides a Pino logger instance with AWS Lambda attributes.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { Logger } from '@leanstacks/lambda-utils';
|
|
34
|
+
* const logger = new Logger().instance;
|
|
35
|
+
*
|
|
36
|
+
* logger.info('Hello, world!');
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class Logger {
|
|
40
|
+
private _loggerConfig;
|
|
41
|
+
private _instance;
|
|
42
|
+
constructor(config?: LoggerConfig);
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new, fully configured Pino logger instance.
|
|
45
|
+
*/
|
|
46
|
+
private _createLogger;
|
|
47
|
+
/**
|
|
48
|
+
* Get the logger instance.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { Logger } from '@leanstacks/lambda-utils';
|
|
53
|
+
* const logger = new Logger().instance;
|
|
54
|
+
*
|
|
55
|
+
* logger.info('Hello, world!');
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
get instance(): pino.Logger;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leanstacks/lambda-utils",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"description": "A collection of utilities and helper functions designed to streamline the development of AWS Lambda functions using TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"build": "rollup -c",
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
13
14
|
"lint": "eslint src",
|
|
14
15
|
"lint:fix": "eslint src --fix",
|
|
16
|
+
"prepare": "husky",
|
|
15
17
|
"test": "jest",
|
|
16
18
|
"test:watch": "jest --watch",
|
|
17
19
|
"test:coverage": "jest --coverage"
|
|
@@ -27,16 +29,21 @@
|
|
|
27
29
|
"license": "MIT",
|
|
28
30
|
"devDependencies": {
|
|
29
31
|
"@eslint/js": "9.39.2",
|
|
32
|
+
"@rollup/plugin-commonjs": "29.0.0",
|
|
33
|
+
"@rollup/plugin-node-resolve": "16.0.3",
|
|
34
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
30
35
|
"@types/aws-lambda": "8.10.159",
|
|
31
36
|
"@types/jest": "30.0.0",
|
|
32
37
|
"@types/node": "25.0.3",
|
|
33
38
|
"@typescript-eslint/eslint-plugin": "8.50.0",
|
|
34
39
|
"@typescript-eslint/parser": "8.50.0",
|
|
35
40
|
"eslint": "9.39.2",
|
|
41
|
+
"husky": "9.1.7",
|
|
36
42
|
"jest": "30.2.0",
|
|
37
43
|
"prettier": "3.7.4",
|
|
38
44
|
"rimraf": "6.1.2",
|
|
39
45
|
"rollup": "4.53.5",
|
|
46
|
+
"rollup-plugin-peer-deps-external": "2.2.4",
|
|
40
47
|
"rollup-plugin-typescript2": "0.36.0",
|
|
41
48
|
"ts-jest": "29.4.6",
|
|
42
49
|
"ts-node": "10.9.2",
|
package/rollup.config.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
3
|
+
import terser from '@rollup/plugin-terser';
|
|
4
|
+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
|
1
5
|
import typescript from 'rollup-plugin-typescript2';
|
|
2
6
|
|
|
7
|
+
import packageJson from './package.json' with { type: 'json' };
|
|
8
|
+
|
|
3
9
|
export default {
|
|
4
10
|
input: 'src/index.ts',
|
|
5
11
|
output: [
|
|
6
12
|
{
|
|
7
|
-
file:
|
|
13
|
+
file: packageJson.main,
|
|
14
|
+
format: 'cjs',
|
|
15
|
+
sourcemap: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
file: packageJson.module,
|
|
8
19
|
format: 'esm',
|
|
20
|
+
sourcemap: true,
|
|
9
21
|
},
|
|
10
22
|
],
|
|
11
|
-
external: ['pino', 'pino-lambda', 'zod', '@aws-sdk/client-dynamodb', '@aws-sdk/client-lambda'],
|
|
12
23
|
plugins: [
|
|
24
|
+
peerDepsExternal(),
|
|
25
|
+
nodeResolve(),
|
|
26
|
+
commonjs(),
|
|
13
27
|
typescript({
|
|
14
28
|
tsconfig: 'tsconfig.json',
|
|
15
29
|
clean: true,
|
|
16
30
|
}),
|
|
31
|
+
terser(),
|
|
17
32
|
],
|
|
33
|
+
external: [...Object.keys(packageJson.dependencies || {})],
|
|
18
34
|
};
|