Compare commits

..

15 Commits

Author SHA1 Message Date
6425e4a93f 5.0.0 2024-06-16 13:56:31 +02:00
55fa1215ae BREAKING CHANGE(structure): renamed classes to avoid confusion 2024-06-16 13:56:30 +02:00
3769468b01 update description 2024-05-29 14:11:35 +02:00
6ea919780c update tsconfig 2024-04-14 17:18:13 +02:00
b5afe8e842 update npmextra.json: githost 2024-04-01 21:33:37 +02:00
942e444d41 update npmextra.json: githost 2024-04-01 19:57:35 +02:00
1ab15c0b72 update npmextra.json: githost 2024-03-30 21:46:32 +01:00
f1db9c1c5d 4.0.8 2024-01-28 16:08:33 +01:00
e3974b3bb1 fix(core): update 2024-01-28 16:08:32 +01:00
016b93ea3a 4.0.7 2024-01-28 02:50:42 +01:00
ab870af0bb fix(core): update 2024-01-28 02:50:41 +01:00
8cda69b3c2 4.0.6 2023-07-21 19:01:26 +02:00
3641d75e2f fix(core): update 2023-07-21 19:01:26 +02:00
fd343c1558 4.0.5 2023-07-21 18:59:18 +02:00
76650ac199 fix(core): update 2023-07-21 18:59:17 +02:00
15 changed files with 7125 additions and 4221 deletions

View File

@ -119,6 +119,6 @@ jobs:
run: | run: |
npmci node install stable npmci node install stable
npmci npm install npmci npm install
pnpm install -g @gitzone/tsdoc pnpm install -g @git.zone/tsdoc
npmci command tsdoc npmci command tsdoc
continue-on-error: true continue-on-error: true

View File

@ -2,17 +2,37 @@
"gitzone": { "gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartacme", "gitrepo": "smartacme",
"description": "acme with an easy yet powerful interface in TypeScript", "description": "A TypeScript-based ACME client for LetsEncrypt certificate management with a focus on simplicity and power.",
"npmPackagename": "@push.rocks/smartacme", "npmPackagename": "@push.rocks/smartacme",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks",
"keywords": [
"ACME",
"LetsEncrypt",
"TypeScript",
"certificate management",
"DNS challenges",
"SSL/TLS",
"secure communication",
"domain validation",
"automation",
"crypto",
"MongoDB",
"dns-01 challenge",
"token-based challenges",
"certificate renewal",
"wildcard certificates"
]
} }
}, },
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
} }
} }

View File

@ -1,8 +1,8 @@
{ {
"name": "@push.rocks/smartacme", "name": "@push.rocks/smartacme",
"version": "4.0.4", "version": "5.0.0",
"private": false, "private": false,
"description": "acme with an easy yet powerful interface in TypeScript", "description": "A TypeScript-based ACME client for LetsEncrypt certificate management with a focus on simplicity and power.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module", "type": "module",
@ -13,42 +13,54 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+ssh://git@gitlab.com/umbrellazone/smartacme.git" "url": "https://code.foss.global/push.rocks/smartacme.git"
}, },
"keywords": [ "keywords": [
"ACME",
"LetsEncrypt",
"TypeScript", "TypeScript",
"acme", "certificate management",
"letsencrypt" "DNS challenges",
"SSL/TLS",
"secure communication",
"domain validation",
"automation",
"crypto",
"MongoDB",
"dns-01 challenge",
"token-based challenges",
"certificate renewal",
"wildcard certificates"
], ],
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/umbrellazone/smartacme/issues" "url": "https://gitlab.com/umbrellazone/smartacme/issues"
}, },
"homepage": "https://gitlab.com/umbrellazone/smartacme#README", "homepage": "https://code.foss.global/push.rocks/smartacme",
"dependencies": { "dependencies": {
"@apiglobal/typedserver": "^2.0.65", "@api.global/typedserver": "^3.0.50",
"@push.rocks/lik": "^6.0.3", "@push.rocks/lik": "^6.0.15",
"@push.rocks/smartdata": "^5.0.8", "@push.rocks/smartdata": "^5.2.4",
"@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartdns": "^5.0.2", "@push.rocks/smartdns": "^5.0.2",
"@push.rocks/smartlog": "^3.0.3", "@push.rocks/smartlog": "^3.0.7",
"@push.rocks/smartpromise": "^4.0.3", "@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartrequest": "^2.0.18", "@push.rocks/smartrequest": "^2.0.22",
"@push.rocks/smartstring": "^4.0.5", "@push.rocks/smartstring": "^4.0.15",
"@push.rocks/smarttime": "^4.0.4", "@push.rocks/smarttime": "^4.0.6",
"@push.rocks/smartunique": "^3.0.3", "@push.rocks/smartunique": "^3.0.9",
"@tsclass/tsclass": "^4.0.42", "@tsclass/tsclass": "^4.0.58",
"acme-client": "^4.2.5" "acme-client": "^4.2.5"
}, },
"devDependencies": { "devDependencies": {
"@apiclient.xyz/cloudflare": "^6.0.3", "@apiclient.xyz/cloudflare": "^6.0.3",
"@gitzone/tsbuild": "^2.1.66", "@git.zone/tsbuild": "^2.1.80",
"@gitzone/tsrun": "^1.2.44", "@git.zone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.77", "@git.zone/tstest": "^1.0.90",
"@push.rocks/qenv": "^5.0.2", "@push.rocks/qenv": "^6.0.5",
"@push.rocks/tapbundle": "^5.0.12", "@push.rocks/tapbundle": "^5.0.23",
"@types/node": "^20.4.2" "@types/node": "^20.14.2"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

10830
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

2
readme.hints.md Normal file
View File

@ -0,0 +1,2 @@
- this repo is dependent on letsencrypt and its limits
- to simpify the outside API, smartacme is stateful, meaning it works with a mongodb and a collection called 'SmartacmeCert'.

295
readme.md
View File

@ -1,35 +1,227 @@
```markdown
# @push.rocks/smartacme # @push.rocks/smartacme
acme with an easy yet powerful interface in TypeScript
## Availabililty and Links A TypeScript-based ACME client with an easy yet powerful interface for LetsEncrypt certificate management.
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartacme)
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartacme)
* [github.com (source mirror)](https://github.com/push.rocks/smartacme)
* [docs (typedoc)](https://push.rocks.gitlab.io/smartacme/)
## Status for master ## Install
Status Category | Status Badge To install `@push.rocks/smartacme`, you can use npm or yarn. Run one of the following commands in your project directory:
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartacme/badges/master/pipeline.svg)](https://lossless.cloud) ```bash
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartacme/badges/master/coverage.svg)](https://lossless.cloud) npm install @push.rocks/smartacme --save
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartacme)](https://lossless.cloud) ```
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartacme)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) or
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) ```bash
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartacme)](https://lossless.cloud) yarn add @push.rocks/smartacme
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartacme)](https://lossless.cloud) ```
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartacme)](https://lossless.cloud)
Make sure your project is set up to use TypeScript and supports ECMAScript Modules (ESM).
## Usage ## Usage
Use TypeScript for best in class instellisense. This guide will walk you through using `@push.rocks/smartacme` to set up and manage ACME (Automated Certificate Management Environment) certificates with a focus on the Let's Encrypt service, which provides free SSL certificates. The library provides an easy yet powerful TypeScript interface to automate the process of obtaining, renewing, and installing your SSL certificates.
```javascript ### Table of Contents
import { SmartAcme } from 'smartacme';
const run = async () => { 1. [Setting Up Your Project](#setting-up-your-project)
2. [Creating a SmartAcme Instance](#creating-a-smartacme-instance)
3. [Initializing SmartAcme](#initializing-smartacme)
4. [Obtaining a Certificate for a Domain](#obtaining-a-certificate-for-a-domain)
5. [Automating DNS Challenges](#automating-dns-challenges)
6. [Managing Certificates](#managing-certificates)
7. [Environmental Considerations](#environmental-considerations)
8. [Complete Example](#complete-example)
### Setting Up Your Project
Ensure your project includes the necessary TypeScript configuration and dependencies. You'll need to have TypeScript installed and configured for ECMAScript Modules. If you are new to TypeScript, review its [documentation](https://www.typescriptlang.org/docs/) to get started.
### Creating a SmartAcme Instance
Start by importing the `SmartAcme` class from the `@push.rocks/smartacme` package. You'll also need to import or define interfaces for your setup options:
```typescript
import { SmartAcme } from '@push.rocks/smartacme';
const smartAcmeInstance = new SmartAcme({
accountEmail: 'youremail@example.com', // Email used for Let's Encrypt registration and recovery
accountPrivateKey: null, // Private key for the account (optional, if not provided it will be generated)
mongoDescriptor: {
mongoDbUrl: 'mongodb://yourmongoURL',
mongoDbName: 'yourDbName',
mongoDbPass: 'yourDbPassword',
},
removeChallenge: async (dnsChallenge) => {
// Implement logic here to remove DNS challenge records
},
setChallenge: async (dnsChallenge) => {
// Implement logic here to create DNS challenge records
},
environment: 'integration', // Use 'production' for actual certificates
});
```
### Initializing SmartAcme
Before proceeding to request certificates, initialize your SmartAcme instance:
```typescript
await smartAcmeInstance.init();
```
### Obtaining a Certificate for a Domain
To obtain a certificate for a specific domain, use the `getCertificateForDomain` method. This function ensures that if a valid certificate is already present, it will be reused; otherwise, a new certificate is obtained:
```typescript
const myDomain = 'example.com';
const myCert = await smartAcmeInstance.getCertificateForDomain(myDomain);
console.log('Certificate:', myCert);
```
### Automating DNS Challenges
Part of the ACME protocol involves responding to DNS challenges issued by the certificate authority to prove control over a domain. Implement the `setChallenge` and `removeChallenge` functions in your SmartAcme configuration to automate this process. These functions receive a `dnsChallenge` argument containing details needed to create or remove the necessary DNS records.
```typescript
import * as cloudflare from '@apiclient.xyz/cloudflare';
import { Qenv } from '@push.rocks/qenv';
const testQenv = new Qenv('./', './.nogit/');
const testCloudflare = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_TOKEN'));
const smartAcmeInstance = new SmartAcme({
accountEmail: 'domains@example.com',
accountPrivateKey: null,
mongoDescriptor: {
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
},
removeChallenge: async (dnsChallenge) => {
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
},
setChallenge: async (dnsChallenge) => {
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
},
environment: 'integration',
});
await smartAcmeInstance.init();
```
### Managing Certificates
The library automatically handles fetching, renewing, and storing your certificates in a MongoDB database specified in your configuration. Ensure your MongoDB instance is accessible and properly configured for use with SmartAcme.
```typescript
const mongoDescriptor = {
mongoDbUrl: 'mongodb://yourmongoURL',
mongoDbName: 'yourDbName',
mongoDbPass: 'yourDbPassword',
};
```
### 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.
### Complete Example
Below is a complete example demonstrating how to use `@push.rocks/smartacme` to obtain and manage an ACME certificate with Let's Encrypt:
```typescript
import { SmartAcme } from '@push.rocks/smartacme';
import * as cloudflare from '@apiclient.xyz/cloudflare';
import { Qenv } from '@push.rocks/qenv';
const qenv = new Qenv('./', './.nogit/');
const cloudflareAccount = new cloudflare.CloudflareAccount(qenv.getEnvVarOnDemand('CF_TOKEN'));
async function main() {
const smartAcmeInstance = new SmartAcme({
accountEmail: 'youremail@example.com',
accountPrivateKey: null,
mongoDescriptor: {
mongoDbUrl: qenv.getEnvVarRequired('MONGODB_URL'),
mongoDbName: qenv.getEnvVarRequired('MONGODB_DATABASE'),
mongoDbPass: qenv.getEnvVarRequired('MONGODB_PASSWORD'),
},
setChallenge: async (dnsChallenge) => {
await cloudflareAccount.convenience.acmeSetDnsChallenge(dnsChallenge);
},
removeChallenge: async (dnsChallenge) => {
await cloudflareAccount.convenience.acmeRemoveDnsChallenge(dnsChallenge);
},
environment: 'integration',
});
await smartAcmeInstance.init();
const myDomain = 'example.com';
const myCert = await smartAcmeInstance.getCertificateForDomain(myDomain);
console.log('Certificate:', myCert);
await smartAcmeInstance.stop();
}
main().catch(console.error);
```
In this example, `Qenv` is used to manage environment variables, and `cloudflare` library is used to handle DNS challenges required by Let's Encrypt ACME protocol. The `setChallenge` and `removeChallenge` methods are essential for automating the DNS challenge process, which is a key part of domain validation.
## Additional Details
### Certificate Object
The certificate object obtained from the `getCertificateForDomain` method has the following properties:
- `id`: Unique identifier for the certificate.
- `domainName`: The domain name for which the certificate is issued.
- `created`: Timestamp of when the certificate was created.
- `privateKey`: The private key associated with the certificate.
- `publicKey`: The public key or certificate itself.
- `csr`: Certificate Signing Request (CSR) used to obtain the certificate.
- `validUntil`: Timestamp indicating the expiration date of the certificate.
### Methods Summary
- **start()**: Initializes the SmartAcme instance, sets up the ACME client, and registers the account with Let's Encrypt.
- **stop()**: Closes the MongoDB connection and performs any necessary cleanup.
- **getCertificateForDomain(domainArg: string)**: Retrieves or obtains a certificate for the specified domain name. If a valid certificate exists in the database, it is returned. Otherwise, a new certificate is requested and stored.
- **setChallenge(dnsChallenge: any)**: Automates the process of setting DNS challenge records.
- **removeChallenge(dnsChallenge: any)**: Automates the process of removing DNS challenge records.
### Handling Domain Matching
The `SmartacmeCertMatcher` class is responsible for matching certificates with the broadest scope for wildcard certificates. The `getCertificateDomainNameByDomainName` method ensures that domains at various levels are correctly matched.
```typescript
import { SmartacmeCertMatcher } from '@push.rocks/smartacme';
const certMatcher = new SmartacmeCertMatcher();
const certDomainName = certMatcher.getCertificateDomainNameByDomainName('subdomain.example.com');
console.log('Certificate Domain Name:', certDomainName); // Output: example.com
```
### Testing
Automated tests can be added to ensure that the setup and functions work as expected. Using a testing framework such as `tap` and mock services for DNS providers (e.g., Cloudflare), you can simulate the process of obtaining and managing certificates without the need for actual domain ownership.
```typescript
import { tap, expect } from '@push.rocks/tapbundle';
import { Qenv } from '@push.rocks/qenv';
import * as cloudflare from '@apiclient.xyz/cloudflare';
import * as smartacme from '@push.rocks/smartacme';
const testQenv = new Qenv('./', './.nogit/');
const testCloudflare = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_TOKEN'));
let smartAcmeInstance: smartacme.SmartAcme;
tap.test('should create a valid instance of SmartAcme', async () => {
smartAcmeInstance = new smartacme.SmartAcme({ smartAcmeInstance = new smartacme.SmartAcme({
accountEmail: 'domains@lossless.org', accountEmail: 'domains@lossless.org',
accountPrivateKey: null, accountPrivateKey: null,
@ -38,27 +230,58 @@ const run = async () => {
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'), mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'), mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
}, },
removeChallenge: async (dnsChallenge) => {
// somehow provide a function that is able to remove the dns challenge
},
setChallenge: async (dnsChallenge) => { setChallenge: async (dnsChallenge) => {
// somehow provide a function that is able to the dns challenge await testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
},
removeChallenge: async (dnsChallenge) => {
await testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
}, },
environment: 'integration', environment: 'integration',
}); });
await smartAcmeInstance.init(); await smartAcmeInstance.init();
expect(smartAcmeInstance).toBeInstanceOf(smartacme.SmartAcme);
});
// myCert has properties for public/private keys and csr ;) tap.test('should get a domain certificate', async () => {
const myCert = await smartAcmeInstance.getCertificateForDomain('bleu.de'); const certificate = await smartAcmeInstance.getCertificateForDomain('example.com');
}; console.log('Certificate:', certificate);
expect(certificate).toHaveProperty('domainName', 'example.com');
});
tap.test('certmatcher should correctly match domains', async () => {
const certMatcher = new smartacme.SmartacmeCertMatcher();
const matchedCert = certMatcher.getCertificateDomainNameByDomainName('subdomain.example.com');
expect(matchedCert).toBe('example.com');
});
tap.test('should stop correctly', async () => {
await smartAcmeInstance.stop();
expect(smartAcmeInstance).toHaveProperty('client', null);
});
tap.start();
``` ```
## Contribution This comprehensive guide ensures you can set up, manage, and test ACME certificates efficiently and effectively using `@push.rocks/smartacme`.
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) ---
```
For further information read the linked docs at the top of this readme. ## License and Legal Information
## Legal This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -26,7 +26,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
}, },
environment: 'integration', environment: 'integration',
}); });
await smartAcmeInstance.init(); await smartAcmeInstance.start();
}); });
tap.test('should get a domain certificate', async () => { tap.test('should get a domain certificate', async () => {
@ -36,7 +36,7 @@ tap.test('should get a domain certificate', async () => {
tap.test('certmatcher should correctly match domains', async () => { tap.test('certmatcher should correctly match domains', async () => {
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher.js'); const certMatcherMod = await import('../ts/smartacme.classes.certmatcher.js');
const certMatcher = new certMatcherMod.CertMatcher(); const certMatcher = new certMatcherMod.SmartacmeCertMatcher();
const matchedCert = certMatcher.getCertificateDomainNameByDomainName('level3.level2.level1'); const matchedCert = certMatcher.getCertificateDomainNameByDomainName('level3.level2.level1');
expect(matchedCert).toEqual('level2.level1'); expect(matchedCert).toEqual('level2.level1');
}); });

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartacme', name: '@push.rocks/smartacme',
version: '4.0.4', version: '5.0.0',
description: 'acme with an easy yet powerful interface in TypeScript' description: 'A TypeScript-based ACME client for LetsEncrypt certificate management with a focus on simplicity and power.'
} }

View File

@ -1 +1,2 @@
export * from './smartacme.classes.smartacme.js'; export * from './smartacme.classes.smartacme.js';
export { SmartacmeCert as Cert } from './smartacme.classes.cert.js';

View File

@ -2,15 +2,15 @@ import * as plugins from './smartacme.plugins.js';
import * as interfaces from './interfaces/index.js'; import * as interfaces from './interfaces/index.js';
import { CertManager } from './smartacme.classes.certmanager.js'; import { SmartacmeCertManager } from './smartacme.classes.certmanager.js';
import { Collection, svDb, unI } from '@push.rocks/smartdata'; import { Collection, svDb, unI } from '@push.rocks/smartdata';
@plugins.smartdata.Collection(() => { @plugins.smartdata.Collection(() => {
return CertManager.activeDB; return SmartacmeCertManager.activeDB;
}) })
export class Cert export class SmartacmeCert
extends plugins.smartdata.SmartDataDbDoc<Cert, plugins.tsclass.network.ICert> extends plugins.smartdata.SmartDataDbDoc<SmartacmeCert, plugins.tsclass.network.ICert>
implements plugins.tsclass.network.ICert implements plugins.tsclass.network.ICert
{ {
@unI() @unI()

View File

@ -1,10 +1,10 @@
import * as plugins from './smartacme.plugins.js'; import * as plugins from './smartacme.plugins.js';
import { Cert } from './smartacme.classes.cert.js'; import { SmartacmeCert } from './smartacme.classes.cert.js';
import { SmartAcme } from './smartacme.classes.smartacme.js'; import { SmartAcme } from './smartacme.classes.smartacme.js';
import * as interfaces from './interfaces/index.js'; import * as interfaces from './interfaces/index.js';
export class CertManager { export class SmartacmeCertManager {
// ========= // =========
// STATIC // STATIC
// ========= // =========
@ -16,7 +16,7 @@ export class CertManager {
private mongoDescriptor: plugins.smartdata.IMongoDescriptor; private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
public smartdataDb: plugins.smartdata.SmartdataDb; public smartdataDb: plugins.smartdata.SmartdataDb;
public interestMap: plugins.lik.InterestMap<string, Cert>; public interestMap: plugins.lik.InterestMap<string, SmartacmeCert>;
constructor( constructor(
smartAcmeArg: SmartAcme, smartAcmeArg: SmartAcme,
@ -31,7 +31,7 @@ export class CertManager {
// Smartdata DB // Smartdata DB
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor); this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
await this.smartdataDb.init(); await this.smartdataDb.init();
CertManager.activeDB = this.smartdataDb; SmartacmeCertManager.activeDB = this.smartdataDb;
// Pending Map // Pending Map
this.interestMap = new plugins.lik.InterestMap((certName) => certName); this.interestMap = new plugins.lik.InterestMap((certName) => certName);
@ -42,8 +42,8 @@ export class CertManager {
* @returns the Cert class or null * @returns the Cert class or null
* @param certDomainNameArg the domain Name to retrieve the vcertificate for * @param certDomainNameArg the domain Name to retrieve the vcertificate for
*/ */
public async retrieveCertificate(certDomainNameArg: string): Promise<Cert> { public async retrieveCertificate(certDomainNameArg: string): Promise<SmartacmeCert> {
const existingCertificate: Cert = await Cert.getInstance<Cert>({ const existingCertificate: SmartacmeCert = await SmartacmeCert.getInstance<SmartacmeCert>({
domainName: certDomainNameArg, domainName: certDomainNameArg,
}); });
@ -59,7 +59,7 @@ export class CertManager {
* @param optionsArg * @param optionsArg
*/ */
public async storeCertificate(optionsArg: plugins.tsclass.network.ICert) { public async storeCertificate(optionsArg: plugins.tsclass.network.ICert) {
const cert = new Cert(optionsArg); const cert = new SmartacmeCert(optionsArg);
await cert.save(); await cert.save();
const interest = this.interestMap.findInterest(cert.domainName); const interest = this.interestMap.findInterest(cert.domainName);
if (interest) { if (interest) {
@ -69,7 +69,7 @@ export class CertManager {
} }
public async deleteCertificate(certDomainNameArg: string) { public async deleteCertificate(certDomainNameArg: string) {
const cert: Cert = await Cert.getInstance<Cert>({ const cert: SmartacmeCert = await SmartacmeCert.getInstance<SmartacmeCert>({
domainName: certDomainNameArg, domainName: certDomainNameArg,
}); });
await cert.delete(); await cert.delete();

View File

@ -4,7 +4,7 @@ import * as interfaces from './interfaces/index.js';
/** /**
* certmatcher is responsible for matching certificates * certmatcher is responsible for matching certificates
*/ */
export class CertMatcher { export class SmartacmeCertMatcher {
/** /**
* creates a domainName for the certificate that will include the broadest scope * creates a domainName for the certificate that will include the broadest scope
* for wild card certificates * for wild card certificates

View File

@ -1,7 +1,8 @@
import * as plugins from './smartacme.plugins.js'; import * as plugins from './smartacme.plugins.js';
import { Cert } from './smartacme.classes.cert.js'; import { SmartacmeCert } from './smartacme.classes.cert.js';
import { CertManager } from './smartacme.classes.certmanager.js'; import { SmartacmeCertManager } from './smartacme.classes.certmanager.js';
import { CertMatcher } from './smartacme.classes.certmatcher.js'; import { SmartacmeCertMatcher } from './smartacme.classes.certmatcher.js';
import { commitinfo } from './00_commitinfo_data.js';
/** /**
* the options for the class @see SmartAcme * the options for the class @see SmartAcme
@ -31,7 +32,7 @@ export class SmartAcme {
// the acme client // the acme client
private client: any; private client: any;
private smartdns = new plugins.smartdns.Smartdns({}); private smartdns = new plugins.smartdns.Smartdns({});
public logger: plugins.smartlog.ConsoleLog; public logger: plugins.smartlog.Smartlog;
// the account private key // the account private key
private privateKey: string; private privateKey: string;
@ -41,34 +42,34 @@ export class SmartAcme {
private removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>; private removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
// certmanager // certmanager
private certmanager: CertManager; private certmanager: SmartacmeCertManager;
private certmatcher: CertMatcher; private certmatcher: SmartacmeCertMatcher;
constructor(optionsArg: ISmartAcmeOptions) { constructor(optionsArg: ISmartAcmeOptions) {
this.options = optionsArg; this.options = optionsArg;
this.logger = new plugins.smartlog.ConsoleLog(); this.logger = plugins.smartlog.Smartlog.createForCommitinfo(commitinfo);
} }
/** /**
* inits the instance * starts the instance
* ```ts * ```ts
* await myCloudlyInstance.init() // does not support options * await myCloudlyInstance.start() // does not support options
* ``` * ```
*/ */
public async init() { public async start() {
this.privateKey = this.privateKey =
this.options.accountPrivateKey || (await plugins.acme.forge.createPrivateKey()).toString(); this.options.accountPrivateKey || (await plugins.acme.forge.createPrivateKey()).toString();
this.setChallenge = this.options.setChallenge; this.setChallenge = this.options.setChallenge;
this.removeChallenge = this.options.removeChallenge; this.removeChallenge = this.options.removeChallenge;
// CertMangaer // CertMangaer
this.certmanager = new CertManager(this, { this.certmanager = new SmartacmeCertManager(this, {
mongoDescriptor: this.options.mongoDescriptor, mongoDescriptor: this.options.mongoDescriptor,
}); });
await this.certmanager.init(); await this.certmanager.init();
// CertMatcher // CertMatcher
this.certmatcher = new CertMatcher(); this.certmatcher = new SmartacmeCertMatcher();
// ACME Client // ACME Client
this.client = new plugins.acme.Client({ this.client = new plugins.acme.Client({
@ -107,7 +108,7 @@ export class SmartAcme {
* *
* @param domainArg * @param domainArg
*/ */
public async getCertificateForDomain(domainArg: string): Promise<Cert> { public async getCertificateForDomain(domainArg: string): Promise<SmartacmeCert> {
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg); const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName); const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName);
@ -209,4 +210,8 @@ export class SmartAcme {
currentDomainInterst.destroy(); currentDomainInterst.destroy();
return newCertificate; return newCertificate;
} }
public async getAllCertificates(): Promise<SmartacmeCert[]> {
return SmartacmeCert.getInstances({});
}
} }

View File

@ -1,5 +1,5 @@
// @apiglobal scope // @apiglobal scope
import * as typedserver from '@apiglobal/typedserver'; import * as typedserver from '@api.global/typedserver';
export { typedserver }; export { typedserver };

View File

@ -3,9 +3,12 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true
} },
"exclude": [
"dist_*/**/*.d.ts"
]
} }