From a0f6a14b63683051bbfb36c0b00ef37535c8d4ef Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Thu, 1 May 2025 11:38:35 +0000 Subject: [PATCH] fix(docs): Improve certificate manager documentation with detailed examples and custom implementation guide --- changelog.md | 7 ++++++ readme.md | 48 ++++++++++++++++++++++++++++++++++++++++ ts/00_commitinfo_data.ts | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 20795bd..e7cd51e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-05-01 - 7.2.3 - fix(docs) +Improve certificate manager documentation with detailed examples and custom implementation guide + +- Added usage examples for MemoryCertManager and MongoCertManager +- Provided a custom ICertManager implementation guide +- Enhanced overall documentation clarity for certificate storage configuration + ## 2025-05-01 - 7.2.2 - fix(readme) Update readme documentation: switch installation instructions to pnpm and clarify usage with MongoCertManager and updated SmartAcme options diff --git a/readme.md b/readme.md index 48bc9ae..2948761 100644 --- a/readme.md +++ b/readme.md @@ -113,6 +113,54 @@ const certManager = new MongoCertManager({ }); ``` +SmartAcme uses the `ICertManager` interface for certificate storage. Two built-in implementations are available: + +- **MemoryCertManager** + - In-memory storage, suitable for testing or ephemeral use. + - Import example: + ```typescript + import { MemoryCertManager } from '@push.rocks/smartacme'; + const certManager = new MemoryCertManager(); + ``` + +- **MongoCertManager** + - Persistent storage in MongoDB (collection: `SmartacmeCert`). + - Import example: + ```typescript + import { MongoCertManager } from '@push.rocks/smartacme'; + const certManager = new MongoCertManager({ + mongoDbUrl: 'mongodb://yourmongoURL', + mongoDbName: 'yourDbName', + mongoDbPass: 'yourDbPassword', + }); + ``` + +#### Custom Certificate Managers + +To implement a custom certificate manager, implement the `ICertManager` interface and pass it to `SmartAcme`: + +```typescript +import type { ICertManager, Cert as SmartacmeCert } from '@push.rocks/smartacme'; +import { SmartAcme } from '@push.rocks/smartacme'; + +class MyCustomCertManager implements ICertManager { + async init(): Promise { /* setup storage */ } + async get(domainName: string): Promise { /* lookup cert */ } + async put(cert: SmartacmeCert): Promise { /* store cert */ } + async delete(domainName: string): Promise { /* remove cert */ } + async close?(): Promise { /* optional cleanup */ } +} + +// Use your custom manager: +const customManager = new MyCustomCertManager(); +const smartAcme = new SmartAcme({ + accountEmail: 'youremail@example.com', + certManager: customManager, + environment: 'integration', + challengeHandlers: [], // add your handlers +}); +``` + ### Environmental Considerations When creating an instance of `SmartAcme`, you can specify an `environment` option. This is particularly useful for testing, as you can use the `integration` environment to avoid hitting rate limits and for testing your setup without issuing real certificates. Switch to `production` when you are ready to obtain actual certificates. diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 44956e0..67b5733 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.2', + version: '7.2.3', description: 'A TypeScript-based ACME client for LetsEncrypt certificate management with a focus on simplicity and power.' }