fix(core): update
This commit is contained in:
commit
5b0c5a5dae
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
71
.gitea/workflows/docker_nottags.yaml
Normal file
71
.gitea/workflows/docker_nottags.yaml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
name: Docker (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{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_LOGIN_DOCKER_GITEA: ${{ github.server_url }}|${{ gitea.repository_owner }}|${{ secrets.GITEA_TOKEN }}
|
||||||
|
NPMCI_LOGIN_DOCKER_DOCKERREGISTRY: ${{ secrets.NPMCI_LOGIN_DOCKER_DOCKERREGISTRY }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/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:
|
||||||
|
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 @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci npm prepare
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci command npm run build
|
106
.gitea/workflows/docker_tags.yaml
Normal file
106
.gitea/workflows/docker_tags.yaml
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
name: Docker (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{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_LOGIN_DOCKER_GITEA: ${{ github.server_url }}|${{ gitea.repository_owner }}|${{ secrets.GITEA_TOKEN }}
|
||||||
|
NPMCI_LOGIN_DOCKER_DOCKERREGISTRY: ${{ secrets.NPMCI_LOGIN_DOCKER_DOCKERREGISTRY }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
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 @shipzone/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:
|
||||||
|
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 @shipzone/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 command npm run build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci docker login
|
||||||
|
npmci docker build
|
||||||
|
npmci docker test
|
||||||
|
# npmci docker push gitea.lossless.digital
|
||||||
|
npmci docker push dockerregistry.lossless.digital
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
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: Trigger
|
||||||
|
run: npmci trigger
|
20
.gitignore
vendored
Normal file
20
.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
46
Dockerfile
Normal file
46
Dockerfile
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# gitzone dockerfile_service
|
||||||
|
## STAGE 1 // BUILD
|
||||||
|
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci as node1
|
||||||
|
COPY ./ /app
|
||||||
|
WORKDIR /app
|
||||||
|
ARG NPMCI_TOKEN_NPM2
|
||||||
|
ENV NPMCI_TOKEN_NPM2 $NPMCI_TOKEN_NPM2
|
||||||
|
RUN npmci npm prepare
|
||||||
|
RUN pnpm config set store-dir .pnpm-store
|
||||||
|
RUN rm -rf node_modules && pnpm install
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# gitzone dockerfile_service
|
||||||
|
## STAGE 2 // install production
|
||||||
|
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci as node2
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=node1 /app /app
|
||||||
|
RUN rm -rf .pnpm-store
|
||||||
|
ARG NPMCI_TOKEN_NPM2
|
||||||
|
ENV NPMCI_TOKEN_NPM2 $NPMCI_TOKEN_NPM2
|
||||||
|
RUN npmci npm prepare
|
||||||
|
RUN pnpm config set store-dir .pnpm-store
|
||||||
|
RUN rm -rf node_modules/ && pnpm install --prod
|
||||||
|
|
||||||
|
|
||||||
|
## STAGE 3 // rebuild dependencies for alpine
|
||||||
|
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpinenpmci as node3
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=node2 /app /app
|
||||||
|
ARG NPMCI_TOKEN_NPM2
|
||||||
|
ENV NPMCI_TOKEN_NPM2 $NPMCI_TOKEN_NPM2
|
||||||
|
RUN npmci npm prepare
|
||||||
|
RUN pnpm config set store-dir .pnpm-store
|
||||||
|
RUN pnpm rebuild -r
|
||||||
|
|
||||||
|
## STAGE 4 // the final production image with all dependencies in place
|
||||||
|
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine as node4
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=node3 /app /app
|
||||||
|
|
||||||
|
### Healthchecks
|
||||||
|
RUN pnpm install -g @servezone/healthy
|
||||||
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 CMD [ "healthy" ]
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["npm", "start"]
|
4
cli.child.ts
Normal file
4
cli.child.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
process.env.CLI_CALL = 'true';
|
||||||
|
import * as cliTool from './ts/index.js';
|
||||||
|
cliTool.runCli();
|
4
cli.js
Normal file
4
cli.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
process.env.CLI_CALL = 'true';
|
||||||
|
const cliTool = await import('./dist_ts/index.js');
|
||||||
|
cliTool.runCli();
|
5
cli.ts.js
Normal file
5
cli.ts.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
process.env.CLI_CALL = 'true';
|
||||||
|
|
||||||
|
import * as tsrun from '@git.zone/tsrun';
|
||||||
|
tsrun.runPath('./cli.child.js', import.meta.url);
|
24
npmextra.json
Normal file
24
npmextra.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "service",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "serve.zone",
|
||||||
|
"gitrepo": "platformservice",
|
||||||
|
"description": "contains the platformservice container with mail, sms, letter, ai services.",
|
||||||
|
"npmPackagename": "@serve.zone/platformservice",
|
||||||
|
"license": "MIT",
|
||||||
|
"projectDomain": "serve.zone"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"npmci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"dockerRegistryRepoMap": {
|
||||||
|
"registry.gitlab.com": "code.foss.global/serve.zone/platformservice"
|
||||||
|
},
|
||||||
|
"dockerBuildargEnvMap": {
|
||||||
|
"NPMCI_TOKEN_NPM2": "NPMCI_TOKEN_NPM2"
|
||||||
|
},
|
||||||
|
"npmRegistryUrl": "verdaccio.lossless.digital"
|
||||||
|
}
|
||||||
|
}
|
32
package.json
Normal file
32
package.json
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"name": "@serve.zone/platformservice",
|
||||||
|
"version": "1.0.1",
|
||||||
|
"description": "contains the platformservice container with mail, sms, letter, ai services.",
|
||||||
|
"main": "dist_ts/index.js",
|
||||||
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
|
"author": "Task Venture Capital GmbH",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"test": "(tstest test/)",
|
||||||
|
"start": "(node --max_old_space_size=100 ./cli.js)",
|
||||||
|
"startTs": "(node cli.ts.js)",
|
||||||
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@git.zone/tsbuild": "^2.1.17",
|
||||||
|
"@git.zone/tsrun": "^1.2.8",
|
||||||
|
"@git.zone/tstest": "^1.0.28",
|
||||||
|
"@git.zone/tswatch": "^2.0.1",
|
||||||
|
"@push.rocks/tapbundle": "^5.0.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@api.global/typedrequest": "^3.0.4",
|
||||||
|
"@api.global/typedserver": "^3.0.20",
|
||||||
|
"@push.rocks/projectinfo": "^5.0.1",
|
||||||
|
"@push.rocks/qenv": "^6.0.5",
|
||||||
|
"@push.rocks/smartdata": "^5.0.7",
|
||||||
|
"@push.rocks/smartpath": "^5.0.5",
|
||||||
|
"@push.rocks/smartstate": "^2.0.0"
|
||||||
|
}
|
||||||
|
}
|
6875
pnpm-lock.yaml
generated
Normal file
6875
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
readme.md
Normal file
31
readme.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# @serve.zone/platformservice
|
||||||
|
contains the platformservice container with mail, sms, letter, ai services.
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@serve.zone/platformservice)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/serve.zone/platformservice)
|
||||||
|
* [github.com (source mirror)](https://github.com/serve.zone/platformservice)
|
||||||
|
* [docs (typedoc)](https://serve.zone.gitlab.io/platformservice/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [![pipeline status](https://gitlab.com/serve.zone/platformservice/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/serve.zone/platformservice/badges/master/coverage.svg)](https://lossless.cloud)
|
||||||
|
npm | [![npm downloads per month](https://badgen.net/npm/dy/@serve.zone/platformservice)](https://lossless.cloud)
|
||||||
|
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/serve.zone/platformservice)](https://lossless.cloud)
|
||||||
|
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||||
|
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)
|
||||||
|
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@serve.zone/platformservice)](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@serve.zone/platformservice)](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@serve.zone/platformservice)](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Use TypeScript for best in class intellisense.
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@serve.zone/platformservice',
|
||||||
|
version: '1.0.2',
|
||||||
|
description: 'contains the platformservice container with mail, sms, letter, ai services.'
|
||||||
|
}
|
21
ts/classes.platformservice.ts
Normal file
21
ts/classes.platformservice.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import * as plugins from './platformservice.plugins.js';
|
||||||
|
import * as paths from './platformservice.paths.js';
|
||||||
|
import { PlatformServiceDb } from './classes.platformservicedb.js'
|
||||||
|
|
||||||
|
export class SzPlatformService {
|
||||||
|
public projectinfo: plugins.projectinfo.ProjectInfo;
|
||||||
|
public serviceQenv = new plugins.qenv.Qenv('./', './.nogit');
|
||||||
|
public platformserviceDb: PlatformServiceDb;
|
||||||
|
|
||||||
|
public typedserver: plugins.typedserver.TypedServer;
|
||||||
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||||
|
|
||||||
|
public async start() {
|
||||||
|
this.platformserviceDb = new PlatformServiceDb(this);
|
||||||
|
this.projectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
|
||||||
|
this.typedserver = new plugins.typedserver.TypedServer({
|
||||||
|
cors: true,
|
||||||
|
});
|
||||||
|
await this.typedserver.start();
|
||||||
|
}
|
||||||
|
}
|
27
ts/classes.platformservicedb.ts
Normal file
27
ts/classes.platformservicedb.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import * as plugins from './platformservice.plugins.js';
|
||||||
|
import { SzPlatformService } from './classes.platformservice.js';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class PlatformServiceDb {
|
||||||
|
public smartdataDb: plugins.smartdata.SmartdataDb;
|
||||||
|
public platformserviceRef: SzPlatformService;
|
||||||
|
|
||||||
|
constructor(platformserviceRefArg: SzPlatformService) {
|
||||||
|
this.platformserviceRef = platformserviceRefArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start() {
|
||||||
|
this.smartdataDb = new plugins.smartdata.SmartdataDb({
|
||||||
|
mongoDbUser: await this.platformserviceRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_USER'),
|
||||||
|
mongoDbName: await this.platformserviceRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_NAME'),
|
||||||
|
mongoDbPass: await this.platformserviceRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_PASS'),
|
||||||
|
mongoDbUrl: await this.platformserviceRef.serviceQenv.getEnvVarOnDemand('MONGO_DB_URL'),
|
||||||
|
});
|
||||||
|
await this.smartdataDb.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
await this.smartdataDb.close();
|
||||||
|
}
|
||||||
|
}
|
52
ts/email/email.classes.apimanager.ts
Normal file
52
ts/email/email.classes.apimanager.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
import { Email } from './email.classes.email.js';
|
||||||
|
import { request } from 'http';
|
||||||
|
import { logger } from './email.logging.js';
|
||||||
|
|
||||||
|
export class ApiManager {
|
||||||
|
public emailRef: Email;
|
||||||
|
|
||||||
|
public typedRouter = new plugins.typedrequest.TypedRouter();
|
||||||
|
|
||||||
|
constructor(emailRefArg: Email) {
|
||||||
|
this.emailRef = emailRefArg;
|
||||||
|
this.emailRef.mainTypedRouter.addTypedRouter(this.typedRouter);
|
||||||
|
this.typedRouter.addTypedHandler<plugins.lointEmail.IRequestSendEmail>(
|
||||||
|
new plugins.typedrequest.TypedHandler('sendEmail', async (requestData) => {
|
||||||
|
const mailToSend = new plugins.smartmail.Smartmail({
|
||||||
|
body: requestData.body,
|
||||||
|
from: requestData.from,
|
||||||
|
subject: requestData.title,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (requestData.attachments) {
|
||||||
|
for (const attachment of requestData.attachments) {
|
||||||
|
mailToSend.addAttachment(
|
||||||
|
await plugins.smartfile.Smartfile.fromString(
|
||||||
|
attachment.name,
|
||||||
|
attachment.binaryAttachmentString,
|
||||||
|
'binary'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.emailRef.mailgunConnector.sendEmail(mailToSend, requestData.to, {});
|
||||||
|
logger.log(
|
||||||
|
'info',
|
||||||
|
`send an email to ${requestData.to} with subject '${mailToSend.getSubject()}'`,
|
||||||
|
{
|
||||||
|
eventType: 'sentEmail',
|
||||||
|
email: {
|
||||||
|
to: requestData.to,
|
||||||
|
subject: mailToSend.getSubject(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
responseId: 'abc', // TODO: generate proper response id
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
30
ts/email/email.classes.connector.mailgun.ts
Normal file
30
ts/email/email.classes.connector.mailgun.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
import { Email } from './email.classes.email.js';
|
||||||
|
|
||||||
|
export class MailgunConnector {
|
||||||
|
public emailRef: Email;
|
||||||
|
public mailgunAccount: plugins.mailgun.MailgunAccount;
|
||||||
|
|
||||||
|
constructor(emailRefArg: Email) {
|
||||||
|
this.emailRef = emailRefArg;
|
||||||
|
this.mailgunAccount = new plugins.mailgun.MailgunAccount({
|
||||||
|
apiToken: this.emailRef.qenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'),
|
||||||
|
region: 'eu',
|
||||||
|
});
|
||||||
|
this.mailgunAccount.addSmtpCredentials(
|
||||||
|
this.emailRef.qenv.getEnvVarOnDemand('MAILGUN_SMTP_CREDENTIALS')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async sendEmail(
|
||||||
|
smartMailArg: plugins.smartmail.Smartmail<any>,
|
||||||
|
toArg: string,
|
||||||
|
dataArg: any = {}
|
||||||
|
) {
|
||||||
|
this.mailgunAccount.sendSmartMail(smartMailArg, toArg, dataArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async receiveEmail(messageUrl: string) {
|
||||||
|
return await this.mailgunAccount.retrieveSmartMailFromMessageUrl(messageUrl);
|
||||||
|
}
|
||||||
|
}
|
47
ts/email/email.classes.email.ts
Normal file
47
ts/email/email.classes.email.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
import * as paths from './email.paths.js';
|
||||||
|
import { MailgunConnector } from './email.classes.connector.mailgun.js';
|
||||||
|
import { RuleManager } from './email.classes.rulemanager.js';
|
||||||
|
import { ApiManager } from './email.classes.apimanager.js';
|
||||||
|
import { logger } from './email.logging.js';
|
||||||
|
import type { SzPlatformService } from '../classes.platformservice.js';
|
||||||
|
|
||||||
|
export class Email {
|
||||||
|
public platformServiceRef: SzPlatformService;
|
||||||
|
|
||||||
|
// typedrouter
|
||||||
|
public mainTypedRouter = new plugins.typedrequest.TypedRouter();
|
||||||
|
|
||||||
|
// connectors
|
||||||
|
public mailgunConnector: MailgunConnector;
|
||||||
|
public qenv = new plugins.qenv.Qenv('./', '.nogit/');
|
||||||
|
|
||||||
|
// server
|
||||||
|
public apiManager = new ApiManager(this);
|
||||||
|
public ruleManager: RuleManager;
|
||||||
|
|
||||||
|
constructor(platformServiceRefArg: SzPlatformService) {
|
||||||
|
this.platformServiceRef = platformServiceRefArg;
|
||||||
|
this.mailgunConnector = new MailgunConnector(this);
|
||||||
|
this.ruleManager = new RuleManager(this);
|
||||||
|
this.platformServiceRef.typedserver.server.addRoute(
|
||||||
|
'/mailgun-notify',
|
||||||
|
new plugins.loleServiceserver.Handler('POST', async (req, res) => {
|
||||||
|
console.log('Got a mailgun email notification');
|
||||||
|
res.status(200);
|
||||||
|
res.end();
|
||||||
|
this.ruleManager.handleNotification(req.body);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start() {
|
||||||
|
await this.ruleManager.init();
|
||||||
|
logger.log('success', `Started email service`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
137
ts/email/email.classes.rulemanager.ts
Normal file
137
ts/email/email.classes.rulemanager.ts
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
import { Email } from './email.classes.email.js';
|
||||||
|
import { logger } from './email.logging.js';
|
||||||
|
|
||||||
|
export class RuleManager {
|
||||||
|
public emailRef: Email;
|
||||||
|
public smartruleInstance = new plugins.smartrule.SmartRule<
|
||||||
|
plugins.smartmail.Smartmail<plugins.mailgun.IMailgunMessage>
|
||||||
|
>();
|
||||||
|
|
||||||
|
constructor(emailRefArg: Email) {
|
||||||
|
this.emailRef = emailRefArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async handleNotification(notification: plugins.mailgun.IMailgunNotification) {
|
||||||
|
console.log(notification['message-url']);
|
||||||
|
|
||||||
|
// basic checks here
|
||||||
|
// none for now
|
||||||
|
|
||||||
|
const fetchedSmartmail = await this.emailRef.mailgunConnector.receiveEmail(
|
||||||
|
notification['message-url']
|
||||||
|
);
|
||||||
|
console.log('=======================');
|
||||||
|
console.log('Received a mail:');
|
||||||
|
console.log(`From: ${fetchedSmartmail.options.creationObjectRef.From}`);
|
||||||
|
console.log(`To: ${fetchedSmartmail.options.creationObjectRef.To}`);
|
||||||
|
console.log(`Subject: ${fetchedSmartmail.options.creationObjectRef.Subject}`);
|
||||||
|
console.log('^^^^^^^^^^^^^^^^^^^^^^^');
|
||||||
|
|
||||||
|
logger.log(
|
||||||
|
'info',
|
||||||
|
`email from ${fetchedSmartmail.options.creationObjectRef.From} to ${fetchedSmartmail.options.creationObjectRef.To} with subject '${fetchedSmartmail.options.creationObjectRef.Subject}'`,
|
||||||
|
{
|
||||||
|
eventType: 'receivedEmail',
|
||||||
|
email: {
|
||||||
|
from: fetchedSmartmail.options.creationObjectRef.From,
|
||||||
|
to: fetchedSmartmail.options.creationObjectRef.To,
|
||||||
|
subject: fetchedSmartmail.options.creationObjectRef.Subject,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.smartruleInstance.makeDecision(fetchedSmartmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
// lets forward stuff
|
||||||
|
await this.createForwards();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates the default forwards
|
||||||
|
*/
|
||||||
|
public async createForwards() {
|
||||||
|
const forwards: { originalToAddress: string[]; forwardedToAddress: string[] }[] = [
|
||||||
|
{
|
||||||
|
originalToAddress: ['bot@mail.nevermind.group'],
|
||||||
|
forwardedToAddress: ['phil@metadata.company', 'dominik@metadata.company'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
originalToAddress: ['legal@mail.lossless.com'],
|
||||||
|
forwardedToAddress: ['phil@lossless.com'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
originalToAddress: ['christine.nyamwaro@mail.lossless.com', 'christine@nyamwaro.com'],
|
||||||
|
forwardedToAddress: ['phil@lossless.com'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
console.log(`${forwards.length} forward rules configured:`);
|
||||||
|
for (const forward of forwards) {
|
||||||
|
console.log(forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const forward of forwards) {
|
||||||
|
this.smartruleInstance.createRule(
|
||||||
|
10,
|
||||||
|
async (smartmailArg) => {
|
||||||
|
const matched = forward.originalToAddress.reduce<boolean>((prevValue, currentValue) => {
|
||||||
|
return smartmailArg.options.creationObjectRef.To.includes(currentValue) || prevValue;
|
||||||
|
}, false);
|
||||||
|
if (matched) {
|
||||||
|
console.log('Forward rule matched');
|
||||||
|
console.log(forward);
|
||||||
|
return 'apply-continue';
|
||||||
|
} else {
|
||||||
|
return 'continue';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async (smartmailArg: plugins.smartmail.Smartmail<plugins.mailgun.IMailgunMessage>) => {
|
||||||
|
forward.forwardedToAddress.map(async (toArg) => {
|
||||||
|
const forwardedSmartMail = new plugins.smartmail.Smartmail({
|
||||||
|
body:
|
||||||
|
`
|
||||||
|
<div style="background: #CCC; padding: 10px; border-radius: 3px;">
|
||||||
|
<div><b>Original Sender:</b></div>
|
||||||
|
<div>${smartmailArg.options.creationObjectRef.From}</div>
|
||||||
|
<div><b>Original Recipient:</b></div>
|
||||||
|
<div>${smartmailArg.options.creationObjectRef.To}</div>
|
||||||
|
<div><b>Forwarded to:</b></div>
|
||||||
|
<div>${forward.forwardedToAddress.reduce<string>((pVal, cVal) => {
|
||||||
|
return `${pVal ? pVal + ', ' : ''}${cVal}`;
|
||||||
|
}, null)}</div>
|
||||||
|
<div><b>Subject:</b></div>
|
||||||
|
<div>${smartmailArg.getSubject()}</div>
|
||||||
|
<div><b>The original body can be found below.</b></div>
|
||||||
|
</div>
|
||||||
|
` + smartmailArg.getBody(),
|
||||||
|
from: 'forwarder@mail.lossless.one',
|
||||||
|
subject: `Forwarded mail for '${smartmailArg.options.creationObjectRef.To}'`,
|
||||||
|
});
|
||||||
|
for (const attachment of smartmailArg.attachments) {
|
||||||
|
forwardedSmartMail.addAttachment(attachment);
|
||||||
|
}
|
||||||
|
await this.emailRef.mailgunConnector.sendEmail(forwardedSmartMail, toArg);
|
||||||
|
console.log(`forwarded mail to ${toArg}`);
|
||||||
|
logger.log(
|
||||||
|
'info',
|
||||||
|
`email from ${
|
||||||
|
smartmailArg.options.creationObjectRef.From
|
||||||
|
} to phil@lossless.com with subject '${smartmailArg.getSubject()}'`,
|
||||||
|
{
|
||||||
|
eventType: 'forwardedEmail',
|
||||||
|
email: {
|
||||||
|
from: smartmailArg.options.creationObjectRef.From,
|
||||||
|
to: smartmailArg.options.creationObjectRef.To,
|
||||||
|
forwardedTo: toArg,
|
||||||
|
subject: smartmailArg.options.creationObjectRef.Subject,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
ts/email/email.classes.templatemanager.ts
Normal file
13
ts/email/email.classes.templatemanager.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
|
||||||
|
export class TemplateManager {
|
||||||
|
public smartmailDefault = new plugins.smartmail.Smartmail({
|
||||||
|
body: `
|
||||||
|
|
||||||
|
`,
|
||||||
|
from: `noreply@mail.lossless.com`,
|
||||||
|
subject: `{{subject}}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
public createSmartmailFromData(tempalteTypeArg: plugins.lointEmail.TTemplates) {}
|
||||||
|
}
|
13
ts/email/email.logging.ts
Normal file
13
ts/email/email.logging.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
import * as paths from './email.paths.js';
|
||||||
|
|
||||||
|
const projectInfoNpm = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
|
||||||
|
|
||||||
|
export const logger = plugins.loleLog.createLoleLogger({
|
||||||
|
companyUnit: 'lossless.cloud',
|
||||||
|
containerName: 'email',
|
||||||
|
containerVersion: projectInfoNpm.version,
|
||||||
|
sentryAppName: 'email',
|
||||||
|
sentryDsn: 'https://7037e86f36134ced85ae56a57daa1e5e@o169278.ingest.sentry.io/5280282',
|
||||||
|
zone: 'servezone',
|
||||||
|
});
|
6
ts/email/email.paths.ts
Normal file
6
ts/email/email.paths.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import * as plugins from './email.plugins.js';
|
||||||
|
|
||||||
|
export const packageDir = plugins.path.join(
|
||||||
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
|
'../'
|
||||||
|
);
|
43
ts/email/email.plugins.ts
Normal file
43
ts/email/email.plugins.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// native scope
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export { path };
|
||||||
|
|
||||||
|
// @losslessone_private scope
|
||||||
|
import * as loleLog from '@losslessone_private/lole-log';
|
||||||
|
import * as loleServiceserver from '@losslessone_private/lole-serviceserver';
|
||||||
|
|
||||||
|
import * as lointEmail from '@losslessone_private/loint-email';
|
||||||
|
|
||||||
|
export { loleLog, loleServiceserver, lointEmail };
|
||||||
|
|
||||||
|
// @apiglobal scope
|
||||||
|
import * as typedrequest from '@apiglobal/typedrequest';
|
||||||
|
|
||||||
|
export { typedrequest };
|
||||||
|
|
||||||
|
// @mojoio scope
|
||||||
|
import * as mailgun from '@mojoio/mailgun';
|
||||||
|
|
||||||
|
export { mailgun };
|
||||||
|
|
||||||
|
// @pushrocks scope
|
||||||
|
import * as projectinfo from '@pushrocks/projectinfo';
|
||||||
|
import * as qenv from '@pushrocks/qenv';
|
||||||
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
import * as smartmail from '@pushrocks/smartmail';
|
||||||
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
import * as smartrule from '@pushrocks/smartrule';
|
||||||
|
import * as smartvalidator from '@pushrocks/smartvalidator';
|
||||||
|
|
||||||
|
export {
|
||||||
|
projectinfo,
|
||||||
|
qenv,
|
||||||
|
smartfile,
|
||||||
|
smartmail,
|
||||||
|
smartpath,
|
||||||
|
smartrequest,
|
||||||
|
smartrule,
|
||||||
|
smartvalidator,
|
||||||
|
};
|
3
ts/email/index.ts
Normal file
3
ts/email/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { Email } from './email.classes.email.js';
|
||||||
|
|
||||||
|
export { Email };
|
4
ts/index.ts
Normal file
4
ts/index.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export * from './00_commitinfo_data.js';
|
||||||
|
import { SzPlatformService } from './classes.platformservice.js'
|
||||||
|
|
||||||
|
export const runCli = async () => {}
|
6
ts/platformservice.paths.ts
Normal file
6
ts/platformservice.paths.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import * as plugins from './platformservice.plugins.js';
|
||||||
|
|
||||||
|
export const packageDir = plugins.path.join(
|
||||||
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
|
'../'
|
||||||
|
);
|
24
ts/platformservice.plugins.ts
Normal file
24
ts/platformservice.plugins.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// node native
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
export {
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
// @api.global scope
|
||||||
|
import * as typedrequest from '@api.global/typedrequest';
|
||||||
|
import * as typedserver from '@api.global/typedserver';
|
||||||
|
|
||||||
|
export {
|
||||||
|
typedrequest,
|
||||||
|
typedserver,
|
||||||
|
}
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
|
// pushrocks scope
|
||||||
|
import * as projectinfo from '@push.rocks/projectinfo';
|
||||||
|
import * as qenv from '@push.rocks/qenv';
|
||||||
|
import * as smartdata from '@push.rocks/smartdata';
|
||||||
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
|
|
||||||
|
export { projectinfo, qenv, smartdata, smartpath };
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user