Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
82bfc20a6d | |||
b84714b208 | |||
6425e4a93f | |||
55fa1215ae | |||
3769468b01 | |||
6ea919780c | |||
b5afe8e842 | |||
942e444d41 | |||
1ab15c0b72 | |||
f1db9c1c5d | |||
e3974b3bb1 | |||
016b93ea3a | |||
ab870af0bb | |||
8cda69b3c2 | |||
3641d75e2f | |||
fd343c1558 | |||
76650ac199 | |||
d9ba5f20b1 | |||
941923e90f | |||
e38b4c1215 | |||
d405bf63a3 | |||
737f5bf5cc | |||
149cdf67bb | |||
c35ff8d711 | |||
f2bd9b65aa | |||
018a25ba6a | |||
3c052df1e7 | |||
17c85eb8b9 | |||
2bcb31e4d6 | |||
70aef3fe7e | |||
734bde4a98 | |||
c7d9a42feb | |||
f20bc72abb | |||
cd2cfce683 | |||
44ab180474 | |||
15557dfdd6 | |||
488f616d34 | |||
e920406ce9 | |||
e044fd81bd | |||
edaccc357d | |||
67f645ad50 | |||
bfeced5f34 | |||
24b9794a18 | |||
a781329a47 | |||
6b5e0a1207 | |||
2455adfbca | |||
a2cf86b62f | |||
7277906851 | |||
9da9ebb01e | |||
f70684b773 | |||
8b19b206a4 | |||
6be2866ddd | |||
ab55d3c91a | |||
c7ee7eb774 | |||
02daa13a2f | |||
28944b1100 | |||
7ec04d6d3d | |||
595d4d8894 | |||
04ed28f7d1 | |||
6c95cec709 | |||
59173b3ca8 | |||
c2036bba90 | |||
83afea95e6 | |||
ac515f5e80 | |||
6abbf58b83 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,5 +1,19 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
|
||||||
.nogit/
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
#------# custom
|
150
.gitlab-ci.yml
150
.gitlab-ci.yml
@ -1,150 +0,0 @@
|
|||||||
# gitzone standard
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
|
||||||
--volume "$PWD:/code"
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
sast: gl-sast-report.json
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SOURCE_CODE="$PWD"
|
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typedoc typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
12
.snyk
12
.snyk
@ -1,12 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.12.0
|
|
||||||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
|
||||||
ignore:
|
|
||||||
'npm:node-forge:20180226':
|
|
||||||
- rsa-compat > node-forge:
|
|
||||||
reason: None given
|
|
||||||
expires: '2018-09-11T19:17:24.148Z'
|
|
||||||
- acme-v2 > rsa-compat > node-forge:
|
|
||||||
reason: None given
|
|
||||||
expires: '2018-09-11T19:17:24.148Z'
|
|
||||||
patch: {}
|
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (C) 2016, Lossless GmbH
|
Copyright (C) 2016, Task Venture Capital GmbH
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
36
README.md
36
README.md
@ -1,36 +0,0 @@
|
|||||||
# @pushrocks/smartuniverse
|
|
||||||
acme with an easy yet powerful interface in TypeScript
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { SmartAcme } from 'smartacme';
|
|
||||||
|
|
||||||
let smac = new SmartAcme()
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
116
changelog.md
Normal file
116
changelog.md
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-04-26 - 5.0.1 - fix(build)
|
||||||
|
Update CI workflows, bump dependency versions, and refine import and TypeScript configuration
|
||||||
|
|
||||||
|
- Changed CI workflow image and npmci package from '@shipzone/npmci' to '@ship.zone/npmci', and updated repository URLs
|
||||||
|
- Bumped several dependency versions in package.json (e.g. @api.global/typedserver, @push.rocks/lik, @push.rocks/smartdata, @push.rocks/smartdns, @tsclass/tsclass) to newer releases
|
||||||
|
- Adjusted smartdns import to use the smartdnsClient module for proper module resolution
|
||||||
|
- Updated tsconfig.json to add emitDecoratorMetadata and baseUrl settings
|
||||||
|
- Minor markdown and formatting tweaks in readme and gitignore files, and slight improvements in test async handling
|
||||||
|
|
||||||
|
## 2024-06-16 - 5.0.0 - No significant changes
|
||||||
|
This release contains no user‑facing changes.
|
||||||
|
|
||||||
|
## 2024-06-16 - 4.0.8 - Structure and configuration updates
|
||||||
|
- BREAKING CHANGE(structure): renamed classes to avoid confusion
|
||||||
|
- update description
|
||||||
|
- update tsconfig
|
||||||
|
- update npmextra.json: githost
|
||||||
|
|
||||||
|
## 2024-01-28 - 4.0.7–4.0.6 - Internal fixes and updates
|
||||||
|
- A series of releases with routine bug fixes and maintenance updates.
|
||||||
|
|
||||||
|
## 2023-07-21 - 4.0.5–4.0.4 - Internal fixes and updates
|
||||||
|
- Multiple releases addressing internal issues and maintenance improvements.
|
||||||
|
|
||||||
|
## 2023-07-10 - 4.0.3 - Organizational changes
|
||||||
|
- switch to new org scheme
|
||||||
|
|
||||||
|
## 2022-09-27 - 4.0.0–4.0.2 - Internal fixes and updates
|
||||||
|
- Routine maintenance and internal bug fixes.
|
||||||
|
|
||||||
|
## 2022-09-27 - 3.0.15 - Breaking changes
|
||||||
|
- BREAKING CHANGE(core): update
|
||||||
|
|
||||||
|
## 2021-01-22 - 3.0.9–3.0.14 - Internal fixes and updates
|
||||||
|
- A range of releases focused on routine internal updates.
|
||||||
|
|
||||||
|
## 2020-11-18 - 3.0.0–3.0.8 - Internal fixes and updates
|
||||||
|
- Routine maintenance and internal bug fixes.
|
||||||
|
|
||||||
|
## 2020-02-10 - 2.1.2 - Breaking changes
|
||||||
|
- BREAKING CHANGE(core): streamline scope to certificate retrieval using dns challenge
|
||||||
|
|
||||||
|
## 2020-02-10 - 2.1.0–2.1.1 - Internal fixes and updates
|
||||||
|
- Routine fixes and updates.
|
||||||
|
|
||||||
|
## 2019-02-06 - 2.0.36 - New feature
|
||||||
|
- feat(Cert): now has validity check
|
||||||
|
|
||||||
|
## 2019-01-18 - 2.0.2–2.0.35 - Internal fixes and updates
|
||||||
|
- Routine internal updates and maintenance.
|
||||||
|
|
||||||
|
## 2018-10-07 - 2.0.0–2.0.1 - Internal fixes and updates
|
||||||
|
- Routine internal updates and maintenance.
|
||||||
|
|
||||||
|
## 2018-10-07 - 1.1.4 - Breaking changes
|
||||||
|
- BREAKING CHANGE(scope): change to @pushrocks
|
||||||
|
|
||||||
|
## 2018-08-12 - 1.1.1 - NPM publishing fix
|
||||||
|
- fix(npm publishing): update
|
||||||
|
|
||||||
|
## 2018-08-11 - 1.1.0 - Certificate issuance update
|
||||||
|
- fix(core): now creating certs all right
|
||||||
|
|
||||||
|
## 2018-08-11 - 1.0.11 - Feature update
|
||||||
|
- feat(swaitch to acme-v2): switch to letsencrypt v2
|
||||||
|
|
||||||
|
## 2017-04-28 - 1.0.10 - CI improvements
|
||||||
|
- add updated ci config
|
||||||
|
|
||||||
|
## 2017-04-28 - 1.0.9 - Standards update
|
||||||
|
- update to latest standards
|
||||||
|
|
||||||
|
## 2017-01-27 - 1.0.8 - Basic functionality
|
||||||
|
- basic functionality
|
||||||
|
|
||||||
|
## 2017-01-25 - 1.0.7 - Response and validation improvements
|
||||||
|
- now getting a valid response
|
||||||
|
- update validation
|
||||||
|
- improve README
|
||||||
|
|
||||||
|
## 2017-01-15 - 1.0.6 - Async and documentation improvements
|
||||||
|
- improve README
|
||||||
|
- add async checkDNS
|
||||||
|
|
||||||
|
## 2017-01-15 - 1.0.5 - Standards and process updates
|
||||||
|
- update to new standards
|
||||||
|
- now has working requestValidation method
|
||||||
|
- fix som things
|
||||||
|
- start better segregation of concerns
|
||||||
|
- start with certificate signing process
|
||||||
|
|
||||||
|
## 2017-01-01 - 1.0.4 - Certificate acquisition improvements
|
||||||
|
- now getting certificates
|
||||||
|
- can now agree to TOS
|
||||||
|
- remove test keys
|
||||||
|
|
||||||
|
## 2017-01-01 - 1.0.3 - NPM extra configuration
|
||||||
|
- add npmextra.json
|
||||||
|
|
||||||
|
## 2017-01-01 - 1.0.2 - README and integration update
|
||||||
|
- add better readme
|
||||||
|
- switch to rawacme for more basic letsencrypt access
|
||||||
|
|
||||||
|
## 2016-11-17 - 1.0.1 - Promise fix
|
||||||
|
- fix promise
|
||||||
|
|
||||||
|
## 2016-11-17 - 1.0.0 - Major initial release changes
|
||||||
|
- remove superflouous key creation
|
||||||
|
- switch to acme core
|
||||||
|
- prepare switch to le‑acme‑core
|
||||||
|
- improve upon keyCreation
|
||||||
|
- update to use more promises
|
||||||
|
- add README
|
||||||
|
- first version
|
@ -1,17 +1,38 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartuniverse",
|
"gitrepo": "smartacme",
|
||||||
"shortDescription": "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": "@pushrocks/smartuniverse",
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
2579
package-lock.json
generated
2579
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
98
package.json
98
package.json
@ -1,52 +1,84 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@push.rocks/smartacme",
|
||||||
"version": "2.1.0",
|
"version": "5.0.1",
|
||||||
"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/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"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": "Task Venture Capital GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/umbrellazone/smartacme/issues"
|
"url": "https://code.foss.global/push.rocks/smartacme/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
"homepage": "https://code.foss.global/push.rocks/smartacme#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.4",
|
"@api.global/typedserver": "^3.0.74",
|
||||||
"@pushrocks/smartdata": "^3.1.13",
|
"@push.rocks/lik": "^6.2.2",
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@push.rocks/smartdata": "^5.15.1",
|
||||||
"@pushrocks/smartdns": "^3.0.8",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@pushrocks/smartexpress": "^3.0.6",
|
"@push.rocks/smartdns": "^6.2.2",
|
||||||
"@pushrocks/smartlog": "^2.0.11",
|
"@push.rocks/smartlog": "^3.0.7",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@push.rocks/smartrequest": "^2.1.0",
|
||||||
"@pushrocks/smartstring": "^3.0.8",
|
"@push.rocks/smartstring": "^4.0.15",
|
||||||
"@pushrocks/smarttime": "^3.0.5",
|
"@push.rocks/smarttime": "^4.1.1",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@push.rocks/smartunique": "^3.0.9",
|
||||||
"acme-client": "2.2.2"
|
"@tsclass/tsclass": "^9.0.0",
|
||||||
|
"acme-client": "^4.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.4",
|
"@apiclient.xyz/cloudflare": "^6.3.2",
|
||||||
"@gitzone/tsrun": "^1.1.17",
|
"@git.zone/tsbuild": "^2.3.2",
|
||||||
"@gitzone/tstest": "^1.0.18",
|
"@git.zone/tsrun": "^1.3.3",
|
||||||
"@mojoio/cloudflare": "^2.0.0",
|
"@git.zone/tstest": "^1.0.96",
|
||||||
"@pushrocks/qenv": "^4.0.0",
|
"@push.rocks/qenv": "^6.1.0",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@push.rocks/tapbundle": "^5.6.3",
|
||||||
"@types/node": "^10.12.18",
|
"@types/node": "^22.15.2"
|
||||||
"tslint": "^5.12.1",
|
},
|
||||||
"tslint-config-prettier": "^1.17.0"
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6",
|
||||||
|
"pnpm": {
|
||||||
|
"overrides": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10451
pnpm-lock.yaml
generated
Normal file
10451
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
3
qenv.yml
3
qenv.yml
@ -1,6 +1,5 @@
|
|||||||
required:
|
required:
|
||||||
- CF_EMAIL
|
- CF_TOKEN
|
||||||
- CF_KEY
|
|
||||||
- MONGODB_URL
|
- MONGODB_URL
|
||||||
- MONGODB_PASSWORD
|
- MONGODB_PASSWORD
|
||||||
- MONGODB_DATABASE
|
- MONGODB_DATABASE
|
||||||
|
2
readme.hints.md
Normal file
2
readme.hints.md
Normal 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'.
|
290
readme.md
Normal file
290
readme.md
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
````markdown
|
||||||
|
# @push.rocks/smartacme
|
||||||
|
|
||||||
|
A TypeScript-based ACME client with an easy yet powerful interface for LetsEncrypt certificate management.
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
### Table of Contents
|
||||||
|
|
||||||
|
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({
|
||||||
|
accountEmail: 'domains@lossless.org',
|
||||||
|
accountPrivateKey: null,
|
||||||
|
mongoDescriptor: {
|
||||||
|
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
||||||
|
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||||
|
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
|
||||||
|
},
|
||||||
|
setChallenge: async (dnsChallenge) => {
|
||||||
|
await testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
|
||||||
|
},
|
||||||
|
removeChallenge: async (dnsChallenge) => {
|
||||||
|
await testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
|
||||||
|
},
|
||||||
|
environment: 'integration',
|
||||||
|
});
|
||||||
|
await smartAcmeInstance.init();
|
||||||
|
expect(smartAcmeInstance).toBeInstanceOf(smartacme.SmartAcme);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get a domain certificate', async () => {
|
||||||
|
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();
|
||||||
|
```
|
||||||
|
|
||||||
|
This comprehensive guide ensures you can set up, manage, and test ACME certificates efficiently and effectively using `@push.rocks/smartacme`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
```
|
38
test/test.ts
38
test/test.ts
@ -1,9 +1,11 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
import { Qenv } from '@pushrocks/qenv';
|
import { Qenv } from '@push.rocks/qenv';
|
||||||
|
import * as cloudflare from '@apiclient.xyz/cloudflare';
|
||||||
|
|
||||||
const testQenv = new Qenv('./', './.nogit/');
|
const testQenv = new Qenv('./', './.nogit/');
|
||||||
|
const testCloudflare = new cloudflare.CloudflareAccount(await testQenv.getEnvVarOnDemand('CF_TOKEN'));
|
||||||
|
|
||||||
import * as smartacme from '../ts/index';
|
import * as smartacme from '../ts/index.js';
|
||||||
|
|
||||||
let smartAcmeInstance: smartacme.SmartAcme;
|
let smartAcmeInstance: smartacme.SmartAcme;
|
||||||
|
|
||||||
@ -12,27 +14,31 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
accountEmail: 'domains@lossless.org',
|
accountEmail: 'domains@lossless.org',
|
||||||
accountPrivateKey: null,
|
accountPrivateKey: null,
|
||||||
mongoDescriptor: {
|
mongoDescriptor: {
|
||||||
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
mongoDbName: await testQenv.getEnvVarOnDemand('MONGODB_DATABASE'),
|
||||||
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
mongoDbPass: await testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'),
|
||||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
mongoDbUrl: await testQenv.getEnvVarOnDemand('MONGODB_URL'),
|
||||||
},
|
},
|
||||||
removeChallenge: async (...args) => {
|
removeChallenge: async (dnsChallenge) => {
|
||||||
console.log(args);
|
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
|
||||||
},
|
},
|
||||||
setChallenge: async (...args) => {
|
setChallenge: async (dnsChallenge) => {
|
||||||
console.log(args);
|
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
|
||||||
},
|
},
|
||||||
environment: 'integration'
|
environment: 'integration',
|
||||||
});
|
});
|
||||||
await smartAcmeInstance.init();
|
await smartAcmeInstance.start();
|
||||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
});
|
||||||
|
|
||||||
|
tap.test('should get a domain certificate', async () => {
|
||||||
|
const certificate = await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
|
console.log(certificate);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('certmatcher should correctly match domains', async () => {
|
tap.test('certmatcher should correctly match domains', async () => {
|
||||||
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher');
|
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).to.equal('level2.level1');
|
expect(matchedCert).toEqual('level2.level1');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop correctly', async () => {
|
tap.test('should stop correctly', async () => {
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartacme',
|
||||||
|
version: '5.0.1',
|
||||||
|
description: 'A TypeScript-based ACME client for LetsEncrypt certificate management with a focus on simplicity and power.'
|
||||||
|
}
|
@ -1,3 +1,2 @@
|
|||||||
export * from './smartacme.classes.smartacme';
|
export * from './smartacme.classes.smartacme.js';
|
||||||
|
export { SmartacmeCert as Cert } from './smartacme.classes.cert.js';
|
||||||
export * from './smartacme.classes.certremoteclient';
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
|
||||||
|
|
||||||
export interface ICert {
|
|
||||||
id: string;
|
|
||||||
domainName: string;
|
|
||||||
created: number;
|
|
||||||
privateKey: string;
|
|
||||||
publicKey: string;
|
|
||||||
csr: string;
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import { ICert, TCertStatus } from './cert';
|
|
||||||
|
|
||||||
export interface ICertRemoteRequest {
|
|
||||||
secret: string;
|
|
||||||
domainName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ICertRemoteResponse {
|
|
||||||
status: TCertStatus;
|
|
||||||
certificate?: ICert;
|
|
||||||
}
|
|
@ -1,3 +1 @@
|
|||||||
export * from './accountdata';
|
export * from './accountdata.js';
|
||||||
export * from './cert';
|
|
||||||
export * from './certremote';
|
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins.js';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
import { CertManager } from './smartacme.classes.certmanager';
|
import { SmartacmeCertManager } from './smartacme.classes.certmanager.js';
|
||||||
|
|
||||||
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
import { Collection, svDb, unI } from '@push.rocks/smartdata';
|
||||||
|
|
||||||
@plugins.smartdata.Collection(() => {
|
@plugins.smartdata.Collection(() => {
|
||||||
return CertManager.activeDB;
|
return SmartacmeCertManager.activeDB;
|
||||||
})
|
})
|
||||||
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements interfaces.ICert {
|
export class SmartacmeCert
|
||||||
|
extends plugins.smartdata.SmartDataDbDoc<SmartacmeCert, plugins.tsclass.network.ICert>
|
||||||
|
implements plugins.tsclass.network.ICert
|
||||||
|
{
|
||||||
@unI()
|
@unI()
|
||||||
public id: string;
|
public id: string;
|
||||||
|
|
||||||
@ -28,29 +31,32 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
|||||||
@svDb()
|
@svDb()
|
||||||
public csr: string;
|
public csr: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public validUntil: number;
|
||||||
|
|
||||||
|
public isStillValid(): boolean {
|
||||||
|
return this.validUntil >= Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public shouldBeRenewed(): boolean {
|
||||||
* computed value for when the certificate is still valid
|
const shouldBeValidAtLeastUntil =
|
||||||
*/
|
Date.now() +
|
||||||
get validUntil (): number {
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
return this.created + plugins.smarttime.getMilliSecondsFromUnits({
|
days: 10,
|
||||||
days: 90
|
});
|
||||||
|
return !(this.validUntil >= shouldBeValidAtLeastUntil);
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(certDataArg: plugins.tsclass.network.ICert) {
|
||||||
|
Object.keys(certDataArg).forEach((key) => {
|
||||||
|
this[key] = certDataArg[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
||||||
get isStillValid (): boolean {
|
|
||||||
const shouldBeValitAtLeastUntil = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({
|
|
||||||
days: 10
|
|
||||||
});
|
|
||||||
return this.validUntil >= shouldBeValitAtLeastUntil;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(optionsArg: interfaces.ICert) {
|
|
||||||
super();
|
super();
|
||||||
if (optionsArg) {
|
if (optionsArg) {
|
||||||
Object.keys(optionsArg).forEach(key => {
|
Object.keys(optionsArg).forEach((key) => {
|
||||||
this[key] = optionsArg[key];
|
this[key] = optionsArg[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins.js';
|
||||||
import { Cert } from './smartacme.classes.cert';
|
import { SmartacmeCert } from './smartacme.classes.cert.js';
|
||||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
import { SmartAcme } from './smartacme.classes.smartacme.js';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
export class CertManager {
|
export class SmartacmeCertManager {
|
||||||
// =========
|
// =========
|
||||||
// STATIC
|
// STATIC
|
||||||
// =========
|
// =========
|
||||||
@ -16,13 +16,13 @@ export class CertManager {
|
|||||||
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
public smartdataDb: plugins.smartdata.SmartdataDb;
|
public smartdataDb: plugins.smartdata.SmartdataDb;
|
||||||
|
|
||||||
public pendingMap: plugins.lik.Stringmap;
|
public interestMap: plugins.lik.InterestMap<string, SmartacmeCert>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
smartAcmeArg: SmartAcme,
|
smartAcmeArg: SmartAcme,
|
||||||
optionsArg: {
|
optionsArg: {
|
||||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
||||||
}
|
}
|
||||||
@ -31,21 +31,20 @@ 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.pendingMap = new plugins.lik.Stringmap();
|
this.interestMap = new plugins.lik.InterestMap((certName) => certName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retrieves a certificate
|
* retrieves a certificate
|
||||||
* @returns the Cert class or null
|
* @returns the Cert class or null
|
||||||
* @param domainName the domain Name to retrieve the vcertificate for
|
* @param certDomainNameArg the domain Name to retrieve the vcertificate for
|
||||||
*/
|
*/
|
||||||
public async retrieveCertificate(domainName: string): Promise<Cert> {
|
public async retrieveCertificate(certDomainNameArg: string): Promise<SmartacmeCert> {
|
||||||
await this.checkCerts();
|
const existingCertificate: SmartacmeCert = await SmartacmeCert.getInstance<SmartacmeCert>({
|
||||||
const existingCertificate: Cert = await Cert.getInstance({
|
domainName: certDomainNameArg,
|
||||||
domainName
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingCertificate) {
|
if (existingCertificate) {
|
||||||
@ -59,44 +58,20 @@ export class CertManager {
|
|||||||
* stores the certificate
|
* stores the certificate
|
||||||
* @param optionsArg
|
* @param optionsArg
|
||||||
*/
|
*/
|
||||||
public async storeCertificate(optionsArg: interfaces.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();
|
||||||
this.pendingMap.removeString(optionsArg.domainName);
|
const interest = this.interestMap.findInterest(cert.domainName);
|
||||||
}
|
if (interest) {
|
||||||
|
interest.fullfillInterest(cert);
|
||||||
public async deleteCertificate(domainNameArg: string) {}
|
interest.markLost();
|
||||||
|
|
||||||
/**
|
|
||||||
* announce a certificate as being in the process of being retrieved
|
|
||||||
*/
|
|
||||||
public async announceCertificate(domainNameArg: string) {
|
|
||||||
this.pendingMap.addString(domainNameArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the status of a certificate by certDomain name
|
|
||||||
* @param certDomainArg
|
|
||||||
*/
|
|
||||||
public async getCertificateStatus(certDomainArg: string): Promise<interfaces.TCertStatus> {
|
|
||||||
const isPending = this.pendingMap.checkString(certDomainArg);
|
|
||||||
if (isPending) {
|
|
||||||
return 'pending';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise lets continue
|
|
||||||
const existingCertificate = await this.retrieveCertificate(certDomainArg);
|
|
||||||
if (existingCertificate) {
|
|
||||||
return 'existing';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'nonexisting';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async deleteCertificate(certDomainNameArg: string) {
|
||||||
* checks all certs for expiration
|
const cert: SmartacmeCert = await SmartacmeCert.getInstance<SmartacmeCert>({
|
||||||
*/
|
domainName: certDomainNameArg,
|
||||||
private async checkCerts() {
|
});
|
||||||
// TODO
|
await cert.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins.js';
|
||||||
import * as interfaces from './interfaces';
|
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
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
|
||||||
import * as interfaces from './interfaces';
|
|
||||||
|
|
||||||
// tslint:disable-next-line: max-classes-per-file
|
|
||||||
export class CertRemoteClient {
|
|
||||||
private remoteUrl: string;
|
|
||||||
private secret: string;
|
|
||||||
private logger: plugins.smartlog.Smartlog;
|
|
||||||
|
|
||||||
constructor(optionsArg: {
|
|
||||||
remoteUrl: string;
|
|
||||||
secret: string;
|
|
||||||
logger?: plugins.smartlog.Smartlog;
|
|
||||||
}) {
|
|
||||||
this.remoteUrl = optionsArg.remoteUrl;
|
|
||||||
this.secret = optionsArg.secret;
|
|
||||||
optionsArg.logger
|
|
||||||
? (this.logger = optionsArg.logger)
|
|
||||||
: (this.logger = plugins.smartlog.defaultLogger);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param domainNameArg
|
|
||||||
*/
|
|
||||||
public async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> {
|
|
||||||
let certificate: interfaces.ICert;
|
|
||||||
const doRequestCycle = async (): Promise<interfaces.ICert> => {
|
|
||||||
const responseBody: interfaces.ICertRemoteResponse = (await plugins.smartrequest.postJson(
|
|
||||||
this.remoteUrl,
|
|
||||||
{
|
|
||||||
requestBody: <interfaces.ICertRemoteRequest>{
|
|
||||||
domainName: domainNameArg,
|
|
||||||
secret: this.secret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)).body;
|
|
||||||
switch (responseBody.status as interfaces.TCertStatus) {
|
|
||||||
case 'pending':
|
|
||||||
this.logger.log('info', `request for ${domainNameArg} still pending!`);
|
|
||||||
await plugins.smartdelay.delayFor(5000);
|
|
||||||
const finalResponse = await doRequestCycle();
|
|
||||||
return finalResponse;
|
|
||||||
case 'existing':
|
|
||||||
this.logger.log('ok', `got certificate for ${domainNameArg}`);
|
|
||||||
return responseBody.certificate;
|
|
||||||
case 'failed':
|
|
||||||
default:
|
|
||||||
console.log(`could not retrieve certificate for ${domainNameArg}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
certificate = await doRequestCycle();
|
|
||||||
return certificate;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,8 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins.js';
|
||||||
import { Cert } from './smartacme.classes.cert';
|
import { SmartacmeCert } from './smartacme.classes.cert.js';
|
||||||
import { CertManager } from './smartacme.classes.certmanager';
|
import { SmartacmeCertManager } from './smartacme.classes.certmanager.js';
|
||||||
import { CertMatcher } from './smartacme.classes.certmatcher';
|
import { SmartacmeCertMatcher } from './smartacme.classes.certmatcher.js';
|
||||||
|
import { commitinfo } from './00_commitinfo_data.js';
|
||||||
import * as interfaces from './interfaces';
|
|
||||||
import { request } from 'http';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the options for the class @see SmartAcme
|
* the options for the class @see SmartAcme
|
||||||
@ -13,10 +11,9 @@ export interface ISmartAcmeOptions {
|
|||||||
accountPrivateKey?: string;
|
accountPrivateKey?: string;
|
||||||
accountEmail: string;
|
accountEmail: string;
|
||||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
removeChallenge: (domainName: string) => Promise<any>;
|
removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
environment: 'production' | 'integration';
|
environment: 'production' | 'integration';
|
||||||
logger?: plugins.smartlog.Smartlog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,87 +31,45 @@ 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.smartdnsClient.Smartdns({});
|
||||||
public logger: plugins.smartlog.Smartlog;
|
public logger: plugins.smartlog.Smartlog;
|
||||||
|
|
||||||
// the account private key
|
// the account private key
|
||||||
private privateKey: string;
|
private privateKey: string;
|
||||||
|
|
||||||
// challenge fullfillment
|
// challenge fullfillment
|
||||||
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
private setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
private removeChallenge: (domainName: string) => 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;
|
||||||
|
|
||||||
/**
|
|
||||||
* the remote handler to hand the request and response to.
|
|
||||||
*/
|
|
||||||
public certremoteHandler = async (
|
|
||||||
req: plugins.smartexpress.Request,
|
|
||||||
res: plugins.smartexpress.Response
|
|
||||||
) => {
|
|
||||||
const requestBody: interfaces.ICertRemoteRequest = req.body;
|
|
||||||
this.logger.log('ok', `got certificate request for ${requestBody.domainName}`);
|
|
||||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(
|
|
||||||
requestBody.domainName
|
|
||||||
);
|
|
||||||
this.logger.log('ok', `mapping ${requestBody.domainName} to ${certDomain}`);
|
|
||||||
let status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(certDomain);
|
|
||||||
let response: interfaces.ICertRemoteResponse;
|
|
||||||
switch (status) {
|
|
||||||
case 'existing':
|
|
||||||
this.logger.log('ok', `certificate exists for ${certDomain}. Sending certificate!`);
|
|
||||||
response = {
|
|
||||||
status,
|
|
||||||
certificate: await (await this.certmanager.retrieveCertificate(
|
|
||||||
certDomain
|
|
||||||
)).createSavableObject()
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (status === 'nonexisting') {
|
|
||||||
this.getCertificateForDomain(certDomain);
|
|
||||||
status = 'pending';
|
|
||||||
}
|
|
||||||
response = {
|
|
||||||
status
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
res.status(200);
|
|
||||||
res.send(response);
|
|
||||||
res.end();
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(optionsArg: ISmartAcmeOptions) {
|
constructor(optionsArg: ISmartAcmeOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
this.options.logger
|
this.logger = plugins.smartlog.Smartlog.createForCommitinfo(commitinfo);
|
||||||
? (this.logger = optionsArg.logger)
|
|
||||||
: (this.logger = plugins.smartlog.defaultLogger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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());
|
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({
|
||||||
@ -125,13 +80,13 @@ export class SmartAcme {
|
|||||||
return plugins.acme.directory.letsencrypt.staging;
|
return plugins.acme.directory.letsencrypt.staging;
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
accountKey: this.privateKey
|
accountKey: this.privateKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Register account */
|
/* Register account */
|
||||||
await this.client.createAccount({
|
await this.client.createAccount({
|
||||||
termsOfServiceAgreed: true,
|
termsOfServiceAgreed: true,
|
||||||
contact: [`mailto:${this.options.accountEmail}`]
|
contact: [`mailto:${this.options.accountEmail}`],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +99,8 @@ export class SmartAcme {
|
|||||||
* it runs through the following steps
|
* it runs through the following steps
|
||||||
*
|
*
|
||||||
* * look in the database
|
* * look in the database
|
||||||
* * if in the database return it
|
* * if in the database and still valid return it
|
||||||
* * of not in the database announce it
|
* * if not in the database announce it
|
||||||
* * then get it from letsencrypt
|
* * then get it from letsencrypt
|
||||||
* * store it
|
* * store it
|
||||||
* * remove it from the pending map (which it go onto by announcing it)
|
* * remove it from the pending map (which it go onto by announcing it)
|
||||||
@ -153,19 +108,32 @@ export class SmartAcme {
|
|||||||
*
|
*
|
||||||
* @param domainArg
|
* @param domainArg
|
||||||
*/
|
*/
|
||||||
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
public async getCertificateForDomain(domainArg: string): Promise<SmartacmeCert> {
|
||||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||||
|
|
||||||
if (retrievedCertificate) {
|
if (
|
||||||
|
!retrievedCertificate &&
|
||||||
|
(await this.certmanager.interestMap.checkInterest(certDomainName))
|
||||||
|
) {
|
||||||
|
const existingCertificateInterest = this.certmanager.interestMap.findInterest(certDomainName);
|
||||||
|
const certificate = existingCertificateInterest.interestFullfilled;
|
||||||
|
return certificate;
|
||||||
|
} else if (retrievedCertificate && !retrievedCertificate.shouldBeRenewed()) {
|
||||||
return retrievedCertificate;
|
return retrievedCertificate;
|
||||||
} else {
|
} else if (retrievedCertificate && retrievedCertificate.shouldBeRenewed()) {
|
||||||
await this.certmanager.announceCertificate(certDomain);
|
await retrievedCertificate.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lets make sure others get the same interest
|
||||||
|
const currentDomainInterst = await this.certmanager.interestMap.addInterest(certDomainName);
|
||||||
|
|
||||||
/* Place new order */
|
/* Place new order */
|
||||||
const order = await this.client.createOrder({
|
const order = await this.client.createOrder({
|
||||||
identifiers: [{ type: 'dns', value: certDomain }, { type: 'dns', value: `*.${certDomain}` }]
|
identifiers: [
|
||||||
|
{ type: 'dns', value: certDomainName },
|
||||||
|
{ type: 'dns', value: `*.${certDomainName}` },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Get authorizations and select challenges */
|
/* Get authorizations and select challenges */
|
||||||
@ -173,8 +141,8 @@ export class SmartAcme {
|
|||||||
|
|
||||||
for (const authz of authorizations) {
|
for (const authz of authorizations) {
|
||||||
console.log(authz);
|
console.log(authz);
|
||||||
const domainDnsName: string = `_acme-challenge.${authz.identifier.value}`;
|
const fullHostName: string = `_acme-challenge.${authz.identifier.value}`;
|
||||||
const dnsChallenge: string = authz.challenges.find(challengeArg => {
|
const dnsChallenge: string = authz.challenges.find((challengeArg) => {
|
||||||
return challengeArg.type === 'dns-01';
|
return challengeArg.type === 'dns-01';
|
||||||
});
|
});
|
||||||
// process.exit(1);
|
// process.exit(1);
|
||||||
@ -182,8 +150,12 @@ export class SmartAcme {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
/* Satisfy challenge */
|
/* Satisfy challenge */
|
||||||
await this.setChallenge(domainDnsName, keyAuthorization);
|
await this.setChallenge({
|
||||||
await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', keyAuthorization, 100, 5000);
|
hostName: fullHostName,
|
||||||
|
challenge: keyAuthorization,
|
||||||
|
});
|
||||||
|
await plugins.smartdelay.delayFor(30000);
|
||||||
|
await this.smartdns.checkUntilAvailable(fullHostName, 'TXT', keyAuthorization, 100, 5000);
|
||||||
console.log('Cool down an extra 60 second for region availability');
|
console.log('Cool down an extra 60 second for region availability');
|
||||||
await plugins.smartdelay.delayFor(60000);
|
await plugins.smartdelay.delayFor(60000);
|
||||||
|
|
||||||
@ -198,7 +170,10 @@ export class SmartAcme {
|
|||||||
} finally {
|
} finally {
|
||||||
/* Clean up challenge response */
|
/* Clean up challenge response */
|
||||||
try {
|
try {
|
||||||
await this.removeChallenge(domainDnsName);
|
await this.removeChallenge({
|
||||||
|
hostName: fullHostName,
|
||||||
|
challenge: keyAuthorization,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@ -207,8 +182,8 @@ export class SmartAcme {
|
|||||||
|
|
||||||
/* Finalize order */
|
/* Finalize order */
|
||||||
const [key, csr] = await plugins.acme.forge.createCsr({
|
const [key, csr] = await plugins.acme.forge.createCsr({
|
||||||
commonName: `*.${certDomain}`,
|
commonName: `*.${certDomainName}`,
|
||||||
altNames: [certDomain]
|
altNames: [certDomainName],
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.client.finalizeOrder(order, csr);
|
await this.client.finalizeOrder(order, csr);
|
||||||
@ -218,14 +193,25 @@ export class SmartAcme {
|
|||||||
|
|
||||||
await this.certmanager.storeCertificate({
|
await this.certmanager.storeCertificate({
|
||||||
id: plugins.smartunique.shortId(),
|
id: plugins.smartunique.shortId(),
|
||||||
domainName: certDomain,
|
domainName: certDomainName,
|
||||||
privateKey: key.toString(),
|
privateKey: key.toString(),
|
||||||
publicKey: cert.toString(),
|
publicKey: cert.toString(),
|
||||||
csr: csr.toString(),
|
csr: csr.toString(),
|
||||||
created: Date.now()
|
created: Date.now(),
|
||||||
|
validUntil:
|
||||||
|
Date.now() +
|
||||||
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
|
days: 90,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const newCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
const newCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||||
|
currentDomainInterst.fullfillInterest(newCertificate);
|
||||||
|
currentDomainInterst.destroy();
|
||||||
return newCertificate;
|
return newCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getAllCertificates(): Promise<SmartacmeCert[]> {
|
||||||
|
return SmartacmeCert.getInstances({});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,39 @@
|
|||||||
|
// @apiglobal scope
|
||||||
|
import * as typedserver from '@api.global/typedserver';
|
||||||
|
|
||||||
|
export { typedserver };
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@push.rocks/lik';
|
||||||
import * as smartdata from '@pushrocks/smartdata';
|
import * as smartdata from '@push.rocks/smartdata';
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@push.rocks/smartdelay';
|
||||||
import * as smartdns from '@pushrocks/smartdns';
|
import * as smartdnsClient from '@push.rocks/smartdns/client';
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartlog from '@push.rocks/smartlog';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartrequest from '@push.rocks/smartrequest';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartunique from '@push.rocks/smartunique';
|
||||||
import * as smartunique from '@pushrocks/smartunique';
|
import * as smartstring from '@push.rocks/smartstring';
|
||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smarttime from '@push.rocks/smarttime';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
smartdata,
|
smartdata,
|
||||||
smartdelay,
|
smartdelay,
|
||||||
smartdns,
|
smartdnsClient,
|
||||||
smartexpress,
|
|
||||||
smartlog,
|
smartlog,
|
||||||
smartpromise,
|
smartpromise,
|
||||||
smartrequest,
|
smartrequest,
|
||||||
smartunique,
|
smartunique,
|
||||||
smartstring,
|
smartstring,
|
||||||
smarttime
|
smarttime,
|
||||||
};
|
};
|
||||||
|
|
||||||
// thirs party scope
|
// @tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export { tsclass };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
import * as acme from 'acme-client';
|
import * as acme from 'acme-client';
|
||||||
|
|
||||||
export { acme };
|
export { acme };
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"target": "es2017",
|
"emitDecoratorMetadata": true,
|
||||||
"module": "commonjs"
|
"useDefineForClassFields": false,
|
||||||
}
|
"target": "ES2022",
|
||||||
}
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {}
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user