From fe495a5f03c04c193e199c43d40d94129431e12e Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 5 May 2025 10:50:23 +0000 Subject: [PATCH] fix(smartacme): Refactor module exports and update wildcard certificate support documentation --- changelog.md | 7 +++++++ readme.plan.md | 28 ++-------------------------- test/test.smartacme.integration.ts | 4 ++-- test/test.smartacme.ts | 8 ++++---- ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 3 ++- ts/smartacme.classes.smartacme.ts | 2 +- 7 files changed, 19 insertions(+), 35 deletions(-) diff --git a/changelog.md b/changelog.md index 091e61c..4e3daf7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-05-05 - 7.2.5 - fix(smartacme) +Refactor module exports and update wildcard certificate support documentation + +- Updated readme.plan.md to streamline and remove obsolete wildcard plan details +- Normalized certmanager imports by consolidating exports in ts/index.ts and updating tests accordingly +- Reordered ISmartAcmeOptions interface properties for clarity (accountEmail moved to the top) + ## 2025-05-04 - 7.2.4 - fix(test) Refactor wildcard certificate test to properly stub SmartAcme.start and getCertificateForDomain for robust integration. diff --git a/readme.plan.md b/readme.plan.md index 3a4b2ce..41a81db 100644 --- a/readme.plan.md +++ b/readme.plan.md @@ -1,27 +1,3 @@ -# Plan: Add wildcard domain support to SmartAcme +## Plan -## Goal -- Enable SmartAcme to accept wildcard domain inputs like `*.domain.com` or `*.sub.example.com` and correctly request and match wildcard certificates. - -## Steps -1. [x] Extend SmartacmeCertMatcher: - - [x] Update `getCertificateDomainNameByDomainName()` to handle wildcard prefixes: - - If input starts with `*.` strip the prefix and return the base domain. - - For example: - - `*.example.com` → `example.com` - - `*.sub.example.com` → `sub.example.com` - - `*.a.b.example.com` → `a.b.example.com` - - [x] Ensure existing logic for non-wildcards remains unchanged. -2. [x] Update `SmartAcme.getCertificateForDomain()`: - - [x] Detect wildcard inputs (`domainArg.startsWith('*.')`). - - [x] For wildcard cases, enforce DNS-01 challenge only (throw error if handlers don't support DNS-01). - - [x] Use the matcher result to request wildcard certificate identifiers (e.g., `value: '*.baseDomain'`). -3. [x] Update tests: - - [x] Add unit tests in `test/test.certmatcher.ts` for wildcard handling: - - `*.example.com` → `example.com` - - `*.sub.example.com` → `sub.example.com` - - `*.a.b.example.com` → `a.b.example.com` - - [x] Add integration stub in `test/test.smartacme.ts` for wildcard input in integration mode: - - Call `getCertificateForDomain('*.domain.com')` and expect returned cert `domainName` equals `*.domain.com`. -4. [x] Update documentation (README.md) if needed. -5. [x] Run CI (`pnpm build` & `pnpm test`) and fix any regressions. \ No newline at end of file +Move the \ No newline at end of file diff --git a/test/test.smartacme.integration.ts b/test/test.smartacme.integration.ts index 89a0f99..e3db9fb 100644 --- a/test/test.smartacme.integration.ts +++ b/test/test.smartacme.integration.ts @@ -1,7 +1,7 @@ import { tap, expect } from '@push.rocks/tapbundle'; import { Qenv } from '@push.rocks/qenv'; import * as cloudflare from '@apiclient.xyz/cloudflare'; -import { SmartAcme, MongoCertManager, MemoryCertManager } from '../ts/index.js'; +import { SmartAcme, certmanagers } from '../ts/index.js'; import { Dns01Handler } from '../ts/handlers/Dns01Handler.js'; // Load environment variables for credentials (stored under .nogit/) @@ -21,7 +21,7 @@ tap.test('create SmartAcme instance with DNS-01 handler and start', async () => smartAcmeInstance = new SmartAcme({ accountEmail: 'domains@lossless.org', // certManager: new MongoCertManager({ mongoDbName, mongoDbPass, mongoDbUrl }), - certManager: new MemoryCertManager(), + certManager: new certmanagers.MemoryCertManager(), environment: 'integration', retryOptions: {}, challengeHandlers: [new Dns01Handler(cfAccount)], diff --git a/test/test.smartacme.ts b/test/test.smartacme.ts index 29df910..eb16497 100644 --- a/test/test.smartacme.ts +++ b/test/test.smartacme.ts @@ -1,5 +1,5 @@ import { tap, expect } from '@push.rocks/tapbundle'; -import { SmartAcme, MemoryCertManager } from '../ts/index.js'; +import { SmartAcme, certmanagers } from '../ts/index.js'; import { Cert } from '../ts/index.js'; import type { IChallengeHandler } from '../ts/handlers/IChallengeHandler.js'; @@ -13,7 +13,7 @@ class DummyHandler implements IChallengeHandler { tap.test('constructor throws without challengeHandlers', async () => { expect(() => new SmartAcme({ accountEmail: 'test@example.com', - certManager: new MemoryCertManager(), + certManager: new certmanagers.MemoryCertManager(), environment: 'integration', retryOptions: {}, } as any)).toThrow(); @@ -22,7 +22,7 @@ tap.test('constructor throws without challengeHandlers', async () => { tap.test('constructor accepts valid challengeHandlers', async () => { const sa = new SmartAcme({ accountEmail: 'test@example.com', - certManager: new MemoryCertManager(), + certManager: new certmanagers.MemoryCertManager(), environment: 'integration', retryOptions: {}, challengeHandlers: [new DummyHandler()], @@ -41,7 +41,7 @@ tap.test('get wildcard certificate stub in integration mode', async () => { }; const sa = new SmartAcme({ accountEmail: 'domains@lossless.org', - certManager: new MemoryCertManager(), + certManager: new certmanagers.MemoryCertManager(), environment: 'integration', retryOptions: {}, challengeHandlers: [new DummyHandler()], diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 7cec1a7..bbfcf9e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartacme', - version: '7.2.4', + version: '7.2.5', description: 'A TypeScript-based ACME client for LetsEncrypt certificate management with a focus on simplicity and power.' } diff --git a/ts/index.ts b/ts/index.ts index 44e1ba2..9afbfbd 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,4 +1,5 @@ export * from './smartacme.classes.smartacme.js'; export { SmartacmeCert as Cert } from './smartacme.classes.cert.js'; export type { ICertManager } from './interfaces/certmanager.js'; -export { MemoryCertManager, MongoCertManager } from './certmanagers/index.js'; +import * as certmanagers from './certmanagers/index.js'; +export { certmanagers }; \ No newline at end of file diff --git a/ts/smartacme.classes.smartacme.ts b/ts/smartacme.classes.smartacme.ts index 97ba3e1..1fe07cc 100644 --- a/ts/smartacme.classes.smartacme.ts +++ b/ts/smartacme.classes.smartacme.ts @@ -8,8 +8,8 @@ import { SmartacmeCert } from './smartacme.classes.cert.js'; * the options for the class @see SmartAcme */ export interface ISmartAcmeOptions { - accountPrivateKey?: string; accountEmail: string; + accountPrivateKey?: string; /** * Certificate storage manager (e.g., Mongo or in-memory). */