Skip to content

Commit bc1b409

Browse files
CCM-12875: Documentation update and fix package.json
1 parent c7b94c3 commit bc1b409

File tree

2 files changed

+1
-180
lines changed

2 files changed

+1
-180
lines changed

lambdas/pdm-mock-api/README.md

Lines changed: 0 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ The PDM Mock API simulates two key PDM endpoints:
1111

1212
The mock includes the same authentication mechanism used in the PDS mock, requiring a Bearer token in the Authorization header.
1313

14-
## Features
15-
16-
- ✅ Authentication using Bearer tokens (configurable for mock or SSM-stored tokens)
17-
- ✅ GET endpoint to retrieve resources by ID
18-
- ✅ POST endpoint to create new resources
19-
- ✅ Supports successful responses (200 OK, 201 Created)
20-
- ✅ Supports empty responses for testing
21-
- ✅ Configurable error responses (4XX, 5XX) for testing error scenarios
22-
- ✅ FHIR-compliant response format with OperationOutcome for errors
23-
- ✅ Comprehensive logging with structured log fields
24-
- ✅ API Gateway integration with CloudWatch logging
25-
2614
## API Endpoints
2715

2816
### POST /resource
@@ -138,169 +126,3 @@ The lambda is configured via environment variables:
138126
| `ACCESS_TOKEN_SSM_PATH` | SSM parameter path for the access token | `/mock/access-token` |
139127
| `USE_NON_MOCK_TOKEN` | Use SSM token instead of mock token | `false` |
140128
| `LOG_LEVEL` | Logging level (DEBUG, INFO, WARN, ERROR) | `INFO` |
141-
142-
## Development
143-
144-
### Prerequisites
145-
146-
- Node.js 22.x
147-
- pnpm (for workspace management)
148-
- AWS CLI configured
149-
150-
### Install Dependencies
151-
152-
```bash
153-
cd lambdas/pdm-mock-api
154-
npm install
155-
```
156-
157-
### Build
158-
159-
```bash
160-
npm run build
161-
```
162-
163-
This creates an optimized bundle in the `dist/` directory.
164-
165-
### Run Tests
166-
167-
```bash
168-
npm run test:unit
169-
```
170-
171-
### Type Checking
172-
173-
```bash
174-
npm run typecheck
175-
```
176-
177-
### Linting
178-
179-
```bash
180-
npm run lint
181-
npm run lint:fix # Auto-fix issues
182-
```
183-
184-
## Deployment
185-
186-
The lambda is deployed via Terraform in the Digital Letters infrastructure.
187-
188-
### Terraform Resources
189-
190-
- **Lambda Function**: `module.pdm_mock_api`
191-
- **API Gateway**: `aws_api_gateway_rest_api.pdm_mock`
192-
- **Lambda IAM Permissions**: SSM parameter access, KMS encryption
193-
194-
### Deploy to dev
195-
196-
```bash
197-
cd infrastructure/terraform
198-
# Follow standard tfscaffold deployment process
199-
./bin/terraform.sh <account> <region> <env> dl plan
200-
./bin/terraform.sh <account> <region> <env> dl apply
201-
```
202-
203-
### Access the API
204-
205-
After deployment, the API Gateway endpoint URL is available as a Terraform output:
206-
207-
```bash
208-
terraform output pdm_mock_api_endpoint
209-
```
210-
211-
### Key Components
212-
213-
1. **Authenticator** (`src/authenticator.ts`)
214-
- Validates Bearer tokens
215-
- Supports mock tokens and SSM-stored tokens
216-
217-
2. **Handlers** (`src/handlers.ts`)
218-
- `createGetResourceHandler`: Handles GET requests
219-
- `createCreateResourceHandler`: Handles POST requests
220-
- Generates mock FHIR resources
221-
- Supports error scenario triggers
222-
223-
3. **Container** (`src/container.ts`)
224-
- Dependency injection container
225-
- Manages configuration and service instances
226-
227-
4. **Index** (`src/index.ts`)
228-
- Main Lambda handler
229-
- Routes requests to appropriate handlers
230-
- Error handling
231-
232-
## Testing Integration
233-
234-
Example using the mock in integration tests:
235-
236-
```typescript
237-
const pdmMockEndpoint = process.env.PDM_MOCK_ENDPOINT;
238-
const token = process.env.PDM_MOCK_TOKEN || "mock-pdm-token";
239-
240-
// Create a resource
241-
const response = await fetch(`${pdmMockEndpoint}/resource`, {
242-
method: "POST",
243-
headers: {
244-
Authorization: `Bearer ${token}`,
245-
"Content-Type": "application/json",
246-
},
247-
body: JSON.stringify({ id: "test-resource" }),
248-
});
249-
250-
// Get the resource
251-
const getResponse = await fetch(`${pdmMockEndpoint}/resource/test-resource`, {
252-
headers: {
253-
Authorization: `Bearer ${token}`,
254-
},
255-
});
256-
257-
// Test error scenario
258-
const errorResponse = await fetch(
259-
`${pdmMockEndpoint}/resource/error-500-internal`,
260-
{
261-
headers: {
262-
Authorization: `Bearer ${token}`,
263-
},
264-
},
265-
);
266-
```
267-
268-
## Logging
269-
270-
The lambda uses structured logging with the following fields:
271-
272-
- `requestId`: API Gateway request ID for correlation
273-
- `resourceId`: Resource identifier being accessed
274-
- `httpMethod`: HTTP method (GET, POST)
275-
- `path`: Request path
276-
- `statusCode`: Response status code
277-
- `error`: Error details (for error scenarios)
278-
279-
Example log entry:
280-
281-
```json
282-
{
283-
"level": "INFO",
284-
"timestamp": "2025-11-24T12:00:00Z",
285-
"requestId": "abc-123",
286-
"httpMethod": "GET",
287-
"resourceId": "test-id",
288-
"message": "GET resource request received"
289-
}
290-
```
291-
292-
## Security Considerations
293-
294-
- The mock uses Bearer token authentication
295-
- In production-like environments, use SSM parameters for tokens (`USE_NON_MOCK_TOKEN=true`)
296-
- API Gateway logs are encrypted with KMS
297-
- Lambda IAM role has least-privilege permissions
298-
- X-Ray tracing enabled for request tracking
299-
300-
## Support
301-
302-
For issues or questions:
303-
304-
- Check the [main repository documentation](../../README.md)
305-
- Review CloudWatch logs for the lambda function
306-
- Check API Gateway access logs for request details

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"lambdas/ttl-poll-lambda",
6060
"utils/utils",
6161
"src/cloudevents",
62-
"tests/playwright",
63-
"components/apim-mock-api"
62+
"tests/playwright"
6463
]
6564
}

0 commit comments

Comments
 (0)