feat(core): Refactor SmartAcme core to centralize interest coordination and update dependencies
This commit is contained in:
@ -1,44 +1,16 @@
|
||||
# Plan: Diskless HTTP-01 Handler and Renaming Existing Handler
|
||||
# Plan: Move interestMap from certmanager to smartacme core
|
||||
|
||||
This plan outlines steps to rename the existing filesystem-based HTTP-01 handler to `Http01Webroot`
|
||||
and introduce a new diskless (in-memory) HTTP-01 handler for integration with arbitrary HTTP servers
|
||||
(e.g., Express).
|
||||
## Goal
|
||||
- Pull the interest coordination mechanism out of the ICertManager implementations and into the SmartAcme class.
|
||||
|
||||
## 1. Rename existing handler to Http01Webroot
|
||||
- In `ts/handlers/Http01Handler.ts`:
|
||||
- Rename `Http01HandlerOptions` to `Http01WebrootOptions`.
|
||||
- Rename class `Http01Handler` to `Http01Webroot`.
|
||||
- Remove the legacy alias; rename the handler directly.
|
||||
- In `ts/handlers/index.ts`:
|
||||
- Export `Http01Webroot` under its new name.
|
||||
- Remove any `Http01Handler` export.
|
||||
- Update existing tests (e.g., `test.handlers-http01.ts`) to import `Http01Webroot` instead of `Http01Handler`.
|
||||
## Steps
|
||||
1. Remove `interestMap` from `ICertManager` interface (`ts/interfaces/certmanager.ts`) and its import of `InterestMap`.
|
||||
2. Strip out `interestMap` property, initialization, and usage from `MemoryCertManager` and `MongoCertManager` (`ts/certmanagers/*.ts`).
|
||||
3. In `Smartacme` class (`ts/smartacme.classes.smartacme.ts`):
|
||||
- Add a private `interestMap: plugins.lik.InterestMap<string, SmartacmeCert>` property.
|
||||
- Initialize it in the constructor: `this.interestMap = new plugins.lik.InterestMap((domain) => domain);`.
|
||||
- Update `getCertificateForDomain()` and any other consumers to reference `this.interestMap` instead of `this.certmanager.interestMap`.
|
||||
4. Remove any tests or code that reference the old `interestMap` on `ICertManager` (if any).
|
||||
5. Run CI (`pnpm build` and `pnpm test`) and fix any regressions.
|
||||
|
||||
## 2. Add new diskless (in-memory) HTTP-01 handler
|
||||
- Create `ts/handlers/Http01MemoryHandler.ts`:
|
||||
- Implement `IChallengeHandler<{ token: string; keyAuthorization: string; webPath: string }>`, storing challenges in a private `Map<string, string>`.
|
||||
- `prepare()`: add token→keyAuthorization mapping.
|
||||
- `verify()`: no-op.
|
||||
- `cleanup()`: remove mapping.
|
||||
- Add `handleRequest(req, res, next?)` method:
|
||||
- Parse `/.well-known/acme-challenge/:token` from `req.url`.
|
||||
- If token exists, respond with the key authorization and status 200.
|
||||
- If missing and `next` provided, call `next()`, otherwise respond 404.
|
||||
- Export `Http01MemoryHandler` in `ts/handlers/index.ts`.
|
||||
|
||||
## 3. Write tests for Http01MemoryHandler
|
||||
- Create `test/test.handlers-http01-memory.ts`:
|
||||
- Use `tap` and `expect` to:
|
||||
1. `prepare()` a challenge.
|
||||
2. Invoke `handleRequest()` with a fake `req`/`res` to confirm 200 and correct body.
|
||||
3. `cleanup()` the challenge.
|
||||
4. Confirm `handleRequest()` now yields 404.
|
||||
|
||||
## 4. Update documentation
|
||||
- Add examples in `readme.md` showing how to use both `Http01Webroot` and the new `Http01MemoryHandler`:
|
||||
- Sample code for Express integration using `handleRequest`.
|
||||
|
||||
## 5. Build and test
|
||||
- Run `pnpm build` and `pnpm test`, ensuring existing tests are updated for `Http01Webroot` and new tests pass.
|
||||
|
||||
Please review and let me know if this plan makes sense before proceeding with implementation.
|
||||
Please review and confirm before we begin the refactor.
|
Reference in New Issue
Block a user