# Project plan — lambdaNodejsPdf

Evidence date: 2026-10-10.

Source repository: `git@bitbucket.org:overdrive/lambdanodejspdf.git`.

Inspected revision: `master` at `012edf2` (2021-09-30 00:11:45 +0200, Jaco Brits, "new hk html to pdf function"). That commit is `origin/HEAD`. The only remote branch is `master`. There are no tags.

The scan-host path named on the onboarding issue (`~/projects/sonar_scan/repos/lambdaNodejsPdf`) was not on this machine. The tree below was read from a clone of the git revision above. That revision matches the commit the issue records (`012edf2`, 2021-09-30).

This plan describes what the repository contains. It does not decide what the product should become.

## Product

**Inferred** from the Serverless service name `lambdanodepdf`, the two HTTP routes, and the handlers.

What the code actually does is two AWS Lambda functions behind an API Gateway HTTP API:

- `GET /api/pdf` builds a one-line PDF with PDFKit from a query-string parameter.
- `POST /api/htmltopdf` is written to turn an HTML string into a PDF with the `wkhtmltopdf` npm wrapper, write it under `/tmp`, and upload it to the S3 bucket named `pmf-invoices`.

No README, product brief, or package description states a purpose, owner, or audience. The commit subject "new hk html to pdf function" does not define "hk".

The AWS CLI profile in `serverless.yml` is `unity`. The S3 bucket string is `pmf-invoices`. Those two names point at different product lines already documented elsewhere in Silicon Ark. This repository does not name Unity, Pay My Fines, or `nodehtmltopdf`.

**Unknown / Requires Confirmation:** which product owns this service, who calls it, and whether the stack is still deployed.

## Related Silicon Ark sets

These are other directories. This repository does not reference them. The link is the shared bucket string and the dates.

| Silicon Ark directory | What it records | Relation to this repo |
|---|---|---|
| `nodehtmltopdf` | Express HTML-to-PDF service. First application commit `9025de3` (2021-10-04) uploads to bucket `pmf-invoices`. Its README says the service was created because Lambda struggled to generate PDFs. Later revisions move the bucket to `tmt-pmf-prod-invoices`. | Four days after `012edf2`. Same early bucket name. **Unknown / Requires Confirmation** whether that service replaced this Lambda. |
| `paymyfines-backend-new` | Names a secret id `pmf-invoices-bucket` and a PDF microservice `pmf-pdf-server`. | The secret id is not the bucket name `pmf-invoices`. This repository does not mention that secret or that service. |

## Branch reality

| Line | Tip | Date | What it is |
|---|---|---|---|
| `master` (default; `origin/HEAD`) | `012edf2` | 2021-09-30 | Only branch. 4 commits, 2021-09-29 through 2021-09-30 |

No other local or remote branches were present at inspection. Nothing in git is dated after 2021-09-30.

| Commit | Date | Author | Subject |
|---|---|---|---|
| `afb73db` | 2021-09-29 14:13:34 +0000 | Jaco Brits `<jaco@overdrive.co.za>` | Initial commit |
| `c651a1a` | 2021-09-29 16:24:33 +0200 | Jaco Brits `<jaco@netstart.co.za>` | Update pdf update |
| `ee231d5` | 2021-09-29 20:08:23 +0200 | Jaco Brits `<jaco@netstart.co.za>` | Update new pdf file |
| `012edf2` | 2021-09-30 00:11:45 +0200 | Jaco Brits `<jaco@netstart.co.za>` | new hk html to pdf function |

## Objectives

No objectives file exists. The behaviour the commits introduced:

1. `afb73db` — Bitbucket initial commit. `.gitignore` only. The ignore list is the stock Atlassian example (Node, Java, Python, Maven, JetBrains, media). It does not ignore `.serverless/`.
2. `c651a1a` — Serverless service `lambdanodepdf`, `GET /api/pdf`, `handler.js`, `package-lock.json`, and the `.serverless` package output including `generate-pdf.zip`. `serverless.yml` at this commit points the route at `handler.pdf`. The export in `handler.js` is `generate_pdf`.
3. `ee231d5` — The route handler string becomes `handler.generate_pdf`, matching the export.
4. `012edf2` — `POST /api/htmltopdf`, `htmltopdf.js`, `config.js` (bucket `pmf-invoices`, `hewer` logger), and `generate-htmltopdf.zip`. The committed CloudFormation update template includes both functions.

## Scope

### In scope of `master` at `012edf2`

Tracked files:

| Path | Role |
|---|---|
| `serverless.yml` | Service, provider, two functions |
| `handler.js` | `generate_pdf` |
| `htmltopdf.js` | `main` |
| `config.js` | Bucket name, PATH prefix, `hewer` logger |
| `package-lock.json` | npm lockfileVersion 1. No `package.json` is tracked |
| `.npmignore` | Ignores `node_modules`, `jspm_packages`, `.serverless` for npm packs |
| `.gitignore` | Stock ignore list. Does not ignore `.serverless` |
| `.serverless/serverless-state.json` | Serverless Framework state from a local package |
| `.serverless/cloudformation-template-create-stack.json` | Earlier template (PDF function only) |
| `.serverless/cloudformation-template-update-stack.json` | Template with both functions |
| `.serverless/generate-pdf.zip` | Packaged function artifact |
| `.serverless/generate-htmltopdf.zip` | Packaged function artifact |

### Out of scope / not in this repository

- `package.json`. Dependencies are visible only as `require()` calls and as lockfile entries.
- `sonar-project.properties` and `sonarqube_scan.bat`. The onboarding scan listed them beside the git files. They are not in any commit.
- README, tests, Dockerfile, Bitbucket Pipelines, Lambda layers, VPC, custom domain, and an authorizer.
- The S3 bucket `pmf-invoices`. The name is a string in `config.js`. The template does not create that bucket and the execution role has no `s3:PutObject`.
- The `wkhtmltopdf` operating-system binary. The npm package in the zip spawns a command named `wkhtmltopdf`. The zip roots do not contain that binary.
- A caller. Not named in this tree.

## System shape

```text
Caller (unknown, no authorizer on the route)
    |
    v
API Gateway HTTP API   name dev-lambdanodepdf
    stage $default, payload format 2.0
    |
    +-- GET  /api/pdf        -> Lambda lambdanodepdf-dev-generate-pdf
    |                              handler.generate_pdf
    |                              PDFKit -> base64 PDF response
    |
    +-- POST /api/htmltopdf  -> Lambda lambdanodepdf-dev-generate-htmltopdf
                                   htmltopdf.main
                                   wkhtmltopdf binary (not in the zip)
                                   /tmp file
                                   S3 bucket pmf-invoices (no IAM grant in the template)
```

Region `eu-west-1`. Runtime `nodejs12.x`. Stage `dev`. AWS CLI profile `unity`. Both functions in the update template: 1024 MB, timeout 6 seconds. One execution role, CloudWatch Logs only. No VPC.

The packaging path recorded in `.serverless/serverless-state.json` is `C:\wamp64\www\lambdanodejspdf\.serverless\`. That is the machine that produced the committed artifacts. It is not a runtime path.

## Milestones

There is no milestone plan. The four commits above are the whole history. The service was packaged at `2021-09-29T21:44:08.497Z` (artifact directory `serverless/lambdanodepdf/dev/1632951848497-2021-09-29T21:44:08.497Z`). The git commit that records that package is `012edf2`, about half an hour later.

## Implementation plan

No forward plan is written in the repository. Nothing is marked TODO. The HTML-to-PDF handler, as committed, does not return an API Gateway response: it calls a `callback` that is not defined, and it returns before `wkhtmltopdf` finishes. See `prd.md` WF-2 and `business-rules.md`.

## Known dependencies

- Serverless Framework `frameworkVersion: '2'`.
- Node.js 12.x on Lambda.
- npm packages in the lockfile that the handlers require: `pdfkit` 0.12.3, `wkhtmltopdf` 0.4.0, `hewer` 0.4.0.
- `aws-sdk`, required by `htmltopdf.js`, absent from `package-lock.json`. The Node.js 12 Lambda runtime included AWS SDK v2. This repo does not pin that SDK.
- The `wkhtmltopdf` binary on `PATH`. `config.js` prepends `LAMBDA_TASK_ROOT` to `PATH`. The packaged zip does not contain that binary.
- S3 bucket `pmf-invoices` in the default AWS region of the runtime (no `region` is passed to `new AWS.S3()`). The provider region is `eu-west-1`. Whether the client uses that region is **Inferred** from the Lambda environment.

## Current project status

**Implemented** as a four-commit Serverless project whose last change is 2021-09-30. The PDFKit route is a complete handler. The HTML-to-PDF route is present in source and in the update template, and the handler cannot finish a successful HTTP response as written.

Whether AWS still has the stack `lambdanodepdf-dev`, and whether `nodejs12.x` can still be updated, is **Unknown / Requires Confirmation**. The template pins `nodejs12.x`. AWS has since retired that runtime. This repository has no evidence of a later runtime upgrade.
