@felloh-org/lambda-wrapper 1.11.192 → 1.11.194

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 CHANGED
@@ -1,4 +1,231 @@
1
- # Lambda Wrapper [![release](https://github.com/felloh-org/lambda-wrapper/actions/workflows/release.yml/badge.svg)](https://github.com/felloh-org/lambda-wrapper/actions/workflows/release.yml)
1
+ # Lambda Wrapper
2
2
 
3
- A function wrapper to wrap all of our lambdas and provide core functionality, monitoring and logging + time saving tooling to all of our serverless services.
3
+ [![release](https://github.com/felloh-org/lambda-wrapper/actions/workflows/release.yml/badge.svg)](https://github.com/felloh-org/lambda-wrapper/actions/workflows/release.yml)
4
4
 
5
+ A shared library for Felloh serverless projects that provides core functionality including dependency injection, logging, request handling, database entities, and response models for AWS Lambda functions.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @felloh-org/lambda-wrapper
11
+ # or
12
+ yarn add @felloh-org/lambda-wrapper
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```javascript
18
+ import { LambdaWrapper, DEFINITIONS, ResponseModel } from '@felloh-org/lambda-wrapper';
19
+
20
+ const configuration = {
21
+ SERVICE_NAME: 'my-service',
22
+ };
23
+
24
+ export const handler = LambdaWrapper(configuration, async (di, request) => {
25
+ const logger = di.get(DEFINITIONS.LOGGER);
26
+ const warehouse = di.get(DEFINITIONS.WAREHOUSE);
27
+
28
+ logger.info('Processing request');
29
+
30
+ // Your handler logic here
31
+
32
+ return new ResponseModel({ message: 'Success' }, 200).generate();
33
+ });
34
+ ```
35
+
36
+ ## Features
37
+
38
+ ### Lambda Wrapper
39
+
40
+ The core wrapper provides:
41
+
42
+ - **Dependency Injection** - Access services via `di.get(DEFINITIONS.SERVICE_NAME)`
43
+ - **Automatic Error Handling** - Catches and formats errors consistently
44
+ - **Request Parsing** - Parses body, query params, path params, and headers
45
+ - **Logging & Metrics** - Built-in logging with automatic metric collection
46
+ - **Warm-up Support** - Handles `serverless-plugin-warmup` events automatically
47
+
48
+ ### Built-in Services
49
+
50
+ Access these via `di.get(DEFINITIONS.SERVICE_NAME)`:
51
+
52
+ | Service | Definition | Description |
53
+ |---------|------------|-------------|
54
+ | Logger | `DEFINITIONS.LOGGER` | Structured logging with metric support |
55
+ | Request | `DEFINITIONS.REQUEST` | Parsed request data (body, params, headers) |
56
+ | Warehouse | `DEFINITIONS.WAREHOUSE` | TypeORM database connection manager |
57
+ | Authentication | `DEFINITIONS.AUTHENTICATION` | JWT authentication and user context |
58
+ | EventBridge | `DEFINITIONS.EVENT_BRIDGE` | AWS EventBridge event publishing |
59
+ | Secrets | `DEFINITIONS.SECRETS` | AWS Secrets Manager integration |
60
+ | HTTP | `DEFINITIONS.HTTP` | HTTP client for external requests |
61
+ | Webhook | `DEFINITIONS.WEBHOOK` | Webhook dispatch service |
62
+ | User | `DEFINITIONS.USER` | User service utilities |
63
+ | AuditLogger | `DEFINITIONS.AUDIT_LOGGER` | Audit trail logging |
64
+
65
+ ### Response Model
66
+
67
+ All Lambda responses are standardised:
68
+
69
+ ```javascript
70
+ import { ResponseModel } from '@felloh-org/lambda-wrapper';
71
+
72
+ // Success response
73
+ return new ResponseModel({ users: [...] }, 200).generate();
74
+
75
+ // Error response
76
+ return new ResponseModel({}, 400)
77
+ .setErrors([{ field: 'email', message: 'Invalid email' }])
78
+ .generate();
79
+ ```
80
+
81
+ Response format:
82
+
83
+ ```json
84
+ {
85
+ "statusCode": 200,
86
+ "headers": {
87
+ "Content-Type": "application/json",
88
+ "Access-Control-Allow-Origin": "*"
89
+ },
90
+ "body": {
91
+ "data": { ... },
92
+ "errors": [],
93
+ "meta": {
94
+ "code": 200,
95
+ "reason": "OK",
96
+ "message": "Success",
97
+ "request_id": "uuid"
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### Database Entities (TypeORM)
104
+
105
+ The library includes TypeORM entities organised by domain:
106
+
107
+ | Domain | Description |
108
+ |--------|-------------|
109
+ | `payment` | Transactions, refunds, chargebacks, payment links, providers |
110
+ | `user` | Users, organisations, roles, features, webhooks |
111
+ | `bank` | Accounts, ledgers, settlements, disbursals |
112
+ | `agent-data` | Bookings, components, suppliers |
113
+ | `acquirer` | BIN data, batches, adjustments |
114
+ | `aisp` | Open banking transactions and connections |
115
+ | `nuapay` | Nuapay integration entities |
116
+ | `nuvei` | Nuvei payment processor entities |
117
+ | `trust-payments` | Trust Payments integration |
118
+ | `total-processing` | Total Processing integration |
119
+ | `planet` | Planet payment processor entities |
120
+ | `saltedge` | Saltedge banking integration |
121
+ | `basis-theory` | Tokenisation entities |
122
+ | `go-cardless` | GoCardless Direct Debit |
123
+ | `marketing` | Marketing contacts and ESUs |
124
+
125
+ ### EventBridge Events
126
+
127
+ Publish events to AWS EventBridge:
128
+
129
+ ```javascript
130
+ import { LambdaWrapper, DEFINITIONS, TransactionCustomerReceipt } from '@felloh-org/lambda-wrapper';
131
+
132
+ export const handler = LambdaWrapper(configuration, async (di, request) => {
133
+ const eventBridge = di.get(DEFINITIONS.EVENT_BRIDGE);
134
+
135
+ const event = new TransactionCustomerReceipt();
136
+ event.setCustomerEmail('customer@example.com');
137
+ event.setOrgName('Acme Travel');
138
+ event.setAmount(150000);
139
+ event.setCurrencyMajorUnit('GBP');
140
+ event.setId('txn_123');
141
+
142
+ await eventBridge.send(event);
143
+ });
144
+ ```
145
+
146
+ See [Event Documentation](./docs/events/README.md) for all available events.
147
+
148
+ ### Dependency Injection
149
+
150
+ Create custom services by extending `DependencyAwareClass`:
151
+
152
+ ```javascript
153
+ import { DependencyAwareClass, DEFINITIONS } from '@felloh-org/lambda-wrapper';
154
+
155
+ class MyCustomService extends DependencyAwareClass {
156
+ async doSomething() {
157
+ const logger = this.di.get(DEFINITIONS.LOGGER);
158
+ const warehouse = this.di.get(DEFINITIONS.WAREHOUSE);
159
+
160
+ // Your service logic
161
+ }
162
+ }
163
+
164
+ // Register in configuration
165
+ const configuration = {
166
+ DEPENDENCIES: {
167
+ MY_SERVICE: MyCustomService,
168
+ },
169
+ };
170
+ ```
171
+
172
+ ## Development
173
+
174
+ ### Commands
175
+
176
+ ```bash
177
+ # Build for production (webpack)
178
+ yarn build
179
+
180
+ # Build for TypeORM migrations (babel)
181
+ yarn build:orm
182
+
183
+ # Run linter
184
+ yarn lint
185
+
186
+ # Run tests with coverage
187
+ yarn test
188
+
189
+ # Run database migrations
190
+ yarn orm:migration:run
191
+
192
+ # Generate a new migration
193
+ yarn orm:migration:generate <name>
194
+
195
+ # Revert last migration
196
+ yarn orm:revert
197
+
198
+ # Create database schemas
199
+ yarn orm:schema:create
200
+ ```
201
+
202
+ ### Environment Variables
203
+
204
+ | Variable | Description |
205
+ |----------|-------------|
206
+ | `SERVICE_NAME` | Service identifier for logging and events |
207
+ | `EVENT_BRIDGE_ARN` | AWS EventBridge bus ARN |
208
+ | `DB_HOST` | Database host |
209
+ | `DB_PORT` | Database port |
210
+ | `DB_USERNAME` | Database username |
211
+ | `DB_PASSWORD` | Database password |
212
+ | `DB_DATABASE` | Database name |
213
+
214
+ ### Project Structure
215
+
216
+ ```
217
+ src/
218
+ ├── config/ # Dependency definitions
219
+ ├── dependency-injection/ # DI implementation
220
+ ├── entity/ # TypeORM entities by domain
221
+ ├── event/ # EventBridge event classes
222
+ ├── migration/ # Database migrations by schema
223
+ ├── model/ # Response and data models
224
+ ├── service/ # Core services
225
+ ├── util/ # Utility functions
226
+ └── wrapper/ # Lambda wrapper implementation
227
+ ```
228
+
229
+ ## License
230
+
231
+ MIT
@@ -35,6 +35,7 @@ const run = async () => {
35
35
  await queryRunner.createSchema('amex', true);
36
36
  await queryRunner.createSchema('crm', true);
37
37
  await queryRunner.createSchema('shield', true);
38
+ await queryRunner.createSchema('traveltek', true);
38
39
 
39
40
  process.exit(0);
40
41
  } catch (error) {