117 lines
5.6 KiB
Markdown
117 lines
5.6 KiB
Markdown
# @push.rocks/smartacme
|
|
acme with an easy yet powerful interface in TypeScript
|
|
|
|
## Install
|
|
To install `@push.rocks/smartacme`, you can use npm or yarn. Run one of the following commands in your project directory:
|
|
|
|
```bash
|
|
npm install @push.rocks/smartacme --save
|
|
```
|
|
or
|
|
```bash
|
|
yarn add @push.rocks/smartacme
|
|
```
|
|
|
|
Make sure your project is set up to use TypeScript and supports ECMAScript Modules (ESM).
|
|
|
|
## Usage
|
|
|
|
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.
|
|
|
|
### 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.
|
|
|
|
### Importing @push.rocks/smartacme
|
|
|
|
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';
|
|
```
|
|
|
|
### Creating a SmartAcme Instance
|
|
|
|
The `SmartAcme` class is central to interaction with the ACME service. Create an instance of `SmartAcme` with your configuration:
|
|
|
|
```typescript
|
|
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: { // MongoDB connection details for storing your certificates
|
|
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.
|
|
|
|
### 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
|
|
// Example MongoDB configuration
|
|
{
|
|
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.
|
|
|
|
---
|
|
|
|
This documentation covers the basic setup and operation of `@push.rocks/smartacme`. The library is designed to simplify interactions with ACME services and automate certificate management tasks, enabling secure communication for your applications with minimal hassle.
|
|
|
|
## License and Legal Information
|
|
|
|
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.
|
|
|
|
**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.
|