From f37cddf26d24c2fc6e0b9ae9eb34d279c6008de0 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 20 May 2025 19:46:59 +0000 Subject: [PATCH] update --- package.json | 8 +- pnpm-lock.yaml | 152 +++++++++--------- test/test.bouncemanager.ts | 2 +- test/test.dcrouter.ts | 146 ------------------ test/test.emailauth.ts | 2 +- test/test.integration.ts | 2 +- ts/aibridge/classes.aibridge.ts | 3 - ts/classes.dcrouter.ts | 66 +++++++- ts/classes.platformservicedb.ts | 27 ---- ts/classes.smtp.portconfig.ts | 10 -- ts/index.ts | 2 +- ts/mail/delivery/classes.mta.config.ts | 71 +++++++++ ts/mail/delivery/classes.mta.patch.ts | 72 --------- ts/mail/delivery/classes.mta.ts | 131 ++++++++++++++-- ts/mail/delivery/index.ts | 5 +- ts/mail/services/classes.emailservice.ts | 2 +- ts/platformservice.ts | 188 ----------------------- ts/sms/classes.smsservice.ts | 2 +- 18 files changed, 338 insertions(+), 553 deletions(-) delete mode 100644 test/test.dcrouter.ts delete mode 100644 ts/aibridge/classes.aibridge.ts delete mode 100644 ts/classes.platformservicedb.ts create mode 100644 ts/mail/delivery/classes.mta.config.ts delete mode 100644 ts/mail/delivery/classes.mta.patch.ts delete mode 100644 ts/platformservice.ts diff --git a/package.json b/package.json index ee78464..ac19c7a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "@git.zone/tsrun": "^1.2.8", "@git.zone/tstest": "^1.9.0", "@git.zone/tswatch": "^2.0.1", - "@types/node": "^22.15.19" + "@types/node": "^22.15.20" }, "dependencies": { "@api.global/typedrequest": "^3.0.19", @@ -33,11 +33,11 @@ "@push.rocks/smartdata": "^5.15.1", "@push.rocks/smartdns": "^6.2.2", "@push.rocks/smartfile": "^11.0.4", - "@push.rocks/smartlog": "^3.1.3", + "@push.rocks/smartlog": "^3.1.7", "@push.rocks/smartmail": "^2.1.0", "@push.rocks/smartpath": "^5.0.5", "@push.rocks/smartpromise": "^4.0.3", - "@push.rocks/smartproxy": "^19.3.11", + "@push.rocks/smartproxy": "^19.4.2", "@push.rocks/smartrequest": "^2.1.0", "@push.rocks/smartrule": "^2.0.1", "@push.rocks/smartrx": "^3.0.10", @@ -48,7 +48,7 @@ "ip": "^2.0.1", "lru-cache": "^11.1.0", "mailauth": "^4.8.5", - "mailparser": "^3.6.9", + "mailparser": "^3.7.3", "uuid": "^11.1.0" }, "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce4145f..de202ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,8 +39,8 @@ importers: specifier: ^11.0.4 version: 11.2.0 '@push.rocks/smartlog': - specifier: ^3.1.3 - version: 3.1.3 + specifier: ^3.1.7 + version: 3.1.7 '@push.rocks/smartmail': specifier: ^2.1.0 version: 2.1.0 @@ -51,8 +51,8 @@ importers: specifier: ^4.0.3 version: 4.2.3 '@push.rocks/smartproxy': - specifier: ^19.3.11 - version: 19.3.11(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4) + specifier: ^19.4.2 + version: 19.4.2(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4) '@push.rocks/smartrequest': specifier: ^2.1.0 version: 2.1.0 @@ -84,8 +84,8 @@ importers: specifier: ^4.8.5 version: 4.8.5 mailparser: - specifier: ^3.6.9 - version: 3.7.2 + specifier: ^3.7.3 + version: 3.7.3 uuid: specifier: ^11.1.0 version: 11.1.0 @@ -103,8 +103,8 @@ importers: specifier: ^2.0.1 version: 2.1.0 '@types/node': - specifier: ^22.15.19 - version: 22.15.19 + specifier: ^22.15.20 + version: 22.15.20 packages: @@ -869,8 +869,8 @@ packages: '@push.rocks/smartlog-interfaces@3.0.2': resolution: {integrity: sha512-8hGRTJehbsFSJxLhCQkA018mZtXVPxPTblbg9VaE/EqISRzUw+eosJ2EJV7M4Qu0eiTJZjnWnNLn8CkD77ziWw==} - '@push.rocks/smartlog@3.1.3': - resolution: {integrity: sha512-aUh6fybWGabRVOHaFpEDMW8pi702+6sA1CObai0KMJCv2MJ8QjJlmcZG0wGwTjFKoTqnkxzh4EL5OvJwh7G0Bg==} + '@push.rocks/smartlog@3.1.7': + resolution: {integrity: sha512-ltg4oALFBrAflWMTOhN7lcK6OJ50MvrDx46wyXVGZZ+zRzYUUjBqyBzSXLQrOohOt/r6vQH+KYPgt6D0tYJA9A==} '@push.rocks/smartmail@2.1.0': resolution: {integrity: sha512-PUzxHuDQRdUZGKb5CejjkFr4JyRAZjUmEyX0jL/kTr9BEX+Ba+/t0cAOFC4v/xFbIxvFAlF3VvFtULCbgAvwaA==} @@ -926,8 +926,8 @@ packages: '@push.rocks/smartpromise@4.2.3': resolution: {integrity: sha512-Ycg/TJR+tMt+S3wSFurOpEoW6nXv12QBtKXgBcjMZ4RsdO28geN46U09osPn9N9WuwQy1PkmTV5J/V4F9U8qEw==} - '@push.rocks/smartproxy@19.3.11': - resolution: {integrity: sha512-hQ3drxiqR9YSlFeuRRFBQr/MX3TBbQC+HzXQaZXu9QpEUB8SjbPYFcHAnCa6jURRpFlRaUpafJiBEe+vZWVLPQ==} + '@push.rocks/smartproxy@19.4.2': + resolution: {integrity: sha512-x7UuD4beEa/QAFP+zYCpmB3xl2f9KNXVN+8xSsCTIflhFUfQT6jWk5PlicsddYN9i6e2O3gWcjikTHvpAw37QQ==} '@push.rocks/smartpuppeteer@2.0.5': resolution: {integrity: sha512-yK/qSeWVHIGWRp3c8S5tfdGP6WCKllZC4DR8d8CQlEjszOSBmHtlTdyyqOMBZ/BA4kd+eU5f3A1r4K2tGYty1g==} @@ -1494,11 +1494,11 @@ packages: '@types/node-forge@1.3.11': resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==} - '@types/node@18.19.101': - resolution: {integrity: sha512-Ykg7fcE3+cOQlLUv2Ds3zil6DVjriGQaSN/kEpl5HQ3DIGM6W0F2n9+GkWV4bRt7KjLymgzNdTnSKCbFUUJ7Kw==} + '@types/node@18.19.102': + resolution: {integrity: sha512-8+SHxopyHeI9xdylfts948LTTr7ZOCSQWMEEDS1qmFIv1kdl03YoMcy3H2NhmxeozCxJiTw6al1h5PAp9h0a5w==} - '@types/node@22.15.19': - resolution: {integrity: sha512-3vMNr4TzNQyjHcRZadojpRaD9Ofr6LsonZAoQ+HMUa/9ORTPoxVIw0e0mpqWpdjj8xybyCM+oKOUH2vwFu/oEw==} + '@types/node@22.15.20': + resolution: {integrity: sha512-A6BohGFRGHAscJsTslDCA9JG7qSJr/DWUvrvY8yi9IgnGtMxCyat7vvQ//MFa0DnLsyuS3wYTpLdw4Hf+Q5JXw==} '@types/ping@0.4.4': resolution: {integrity: sha512-ifvo6w2f5eJYlXm+HiVx67iJe8WZp87sfa683nlqED5Vnt9Z93onkokNoWqOG21EaE8fMxyKPobE+mkPEyxsdw==} @@ -2868,11 +2868,11 @@ packages: engines: {node: '>=18.0.0'} hasBin: true - mailparser@3.7.2: - resolution: {integrity: sha512-iI0p2TCcIodR1qGiRoDBBwboSSff50vQAWytM5JRggLfABa4hHYCf3YVujtuzV454xrOP352VsAPIzviqMTo4Q==} + mailparser@3.7.3: + resolution: {integrity: sha512-0RM14cZF0gO1y2Q/82hhWranispZOUSYHwvQ21h12x90NwD6+D5q59S5nOLqCtCdYitHN58LJXWEHa4RWm7BYA==} - mailsplit@5.4.2: - resolution: {integrity: sha512-4cczG/3Iu3pyl8JgQ76dKkisurZTmxMrA4dj/e8d2jKYcFTZ7MxOzg1gTioTDMPuFXwTrVuN/gxhkrO7wLg7qA==} + mailsplit@5.4.3: + resolution: {integrity: sha512-PFV0BBh4Tv7Omui5FtXXVtN4ExAxIi8Yvmb9JgBz+J6Hnnrv/YYXLlKKudLhXwd3/qWEATOslRsnzVCWDeCnmQ==} make-dir@3.1.0: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} @@ -3208,10 +3208,6 @@ packages: resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} engines: {node: '>= 6.13.0'} - nodemailer@6.9.16: - resolution: {integrity: sha512-psAuZdTIRN08HKVd/E8ObdV6NO7NTBY3KsC30F7M4H1OnmLCUNaS56FpYxyb26zWLSyYF9Ozch9KYHhHegsiOQ==} - engines: {node: '>=6.0.0'} - nodemailer@7.0.3: resolution: {integrity: sha512-Ajq6Sz1x7cIK3pN6KesGTah+1gnwMnx5gKl3piQlQQE/PwyJ4Mbc8is2psWYxK3RJTVeqsDaCv8ZzXLCDHMTZw==} engines: {node: '>=6.0.0'} @@ -3836,8 +3832,8 @@ packages: tiny-worker@2.3.0: resolution: {integrity: sha512-pJ70wq5EAqTAEl9IkGzA+fN0836rycEuz2Cn6yeZ6FRzlVS5IDOkFHpIoEsksPRQV34GDqXm65+OlnZqUSyK2g==} - tlds@1.255.0: - resolution: {integrity: sha512-tcwMRIioTcF/FcxLev8MJWxCp+GUALRhFEqbDoZrnowmKSGqPrl5pqS+Sut2m8BgJ6S4FExCSSpGffZ0Tks6Aw==} + tlds@1.259.0: + resolution: {integrity: sha512-AldGGlDP0PNgwppe2quAvuBl18UcjuNtOnDuUkqhd6ipPqrYYBt3aTxK1QTsBVknk97lS2JcafWMghjGWFtunw==} hasBin: true tldts-core@7.0.7: @@ -4182,7 +4178,7 @@ snapshots: '@push.rocks/smartfeed': 1.0.11 '@push.rocks/smartfile': 11.2.0 '@push.rocks/smartjson': 5.0.20 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartlog-destination-devtools': 1.0.12 '@push.rocks/smartlog-interfaces': 3.0.2 '@push.rocks/smartmanifest': 2.0.2 @@ -4236,7 +4232,7 @@ snapshots: '@apiclient.xyz/cloudflare@6.4.1': dependencies: '@push.rocks/smartdelay': 3.0.5 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrequest': 2.1.0 '@push.rocks/smartstring': 4.0.15 @@ -5012,7 +5008,7 @@ snapshots: '@push.rocks/smartcli': 4.0.11 '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartpath': 5.0.18 '@push.rocks/smartpromise': 4.2.3 typescript: 5.7.3 @@ -5025,7 +5021,7 @@ snapshots: '@push.rocks/smartcli': 4.0.11 '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartlog-destination-local': 9.0.2 '@push.rocks/smartpath': 5.0.18 '@push.rocks/smartpromise': 4.2.3 @@ -5042,7 +5038,7 @@ snapshots: '@push.rocks/smartcli': 4.0.11 '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartnpm': 2.0.4 '@push.rocks/smartpath': 5.0.18 '@push.rocks/smartrequest': 2.1.0 @@ -5070,7 +5066,7 @@ snapshots: '@push.rocks/smartexpect': 2.4.2 '@push.rocks/smartfile': 11.2.0 '@push.rocks/smartjson': 5.0.20 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartmongo': 2.0.12(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4) '@push.rocks/smartpath': 5.0.18 '@push.rocks/smartpromise': 4.2.3 @@ -5110,7 +5106,7 @@ snapshots: '@push.rocks/smartcli': 4.0.11 '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartlog-destination-local': 9.0.2 '@push.rocks/smartshell': 3.2.3 '@push.rocks/taskbuffer': 3.1.7 @@ -5388,7 +5384,7 @@ snapshots: '@api.global/typedrequest': 3.1.10 '@configvault.io/interfaces': 1.0.17 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartpath': 5.0.18 '@push.rocks/smartacme@8.0.0(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4)': @@ -5400,7 +5396,7 @@ snapshots: '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartdns': 6.2.2 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartnetwork': 4.0.2 '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrequest': 2.1.0 @@ -5490,7 +5486,7 @@ snapshots: '@push.rocks/smartcli@4.0.11': dependencies: '@push.rocks/lik': 6.2.2 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartobject': 1.0.12 '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrx': 3.0.10 @@ -5515,7 +5511,7 @@ snapshots: dependencies: '@push.rocks/lik': 6.2.2 '@push.rocks/smartdelay': 3.0.5 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartmongo': 2.0.12(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4) '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrx': 3.0.10 @@ -5653,7 +5649,7 @@ snapshots: '@api.global/typedrequest-interfaces': 2.0.2 '@tsclass/tsclass': 4.4.4 - '@push.rocks/smartlog@3.1.3': + '@push.rocks/smartlog@3.1.7': dependencies: '@api.global/typedrequest-interfaces': 3.0.19 '@push.rocks/consolecolor': 2.0.2 @@ -5817,14 +5813,14 @@ snapshots: '@push.rocks/smartpromise@4.2.3': {} - '@push.rocks/smartproxy@19.3.11(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4)': + '@push.rocks/smartproxy@19.4.2(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4)': dependencies: '@push.rocks/lik': 6.2.2 '@push.rocks/smartacme': 8.0.0(@aws-sdk/credential-providers@3.812.0)(socks@2.8.4) '@push.rocks/smartcrypto': 2.0.4 '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartfile': 11.2.0 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartnetwork': 4.0.2 '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrequest': 2.1.0 @@ -5926,7 +5922,7 @@ snapshots: '@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartenv': 5.0.12 '@push.rocks/smartjson': 5.0.20 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrx': 3.0.10 '@push.rocks/smarttime': 4.1.1 @@ -6024,7 +6020,7 @@ snapshots: dependencies: '@push.rocks/lik': 6.2.2 '@push.rocks/smartdelay': 3.0.5 - '@push.rocks/smartlog': 3.1.3 + '@push.rocks/smartlog': 3.1.7 '@push.rocks/smartpromise': 4.2.3 '@push.rocks/smartrx': 3.0.10 '@push.rocks/smarttime': 4.1.1 @@ -6620,27 +6616,27 @@ snapshots: '@types/bn.js@5.1.6': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/body-parser@1.19.5': dependencies: '@types/connect': 3.4.38 - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/buffer-json@2.0.3': {} '@types/clean-css@4.2.11': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 source-map: 0.6.1 '@types/connect@3.4.38': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/cors@2.8.18': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/debug@4.1.12': dependencies: @@ -6652,7 +6648,7 @@ snapshots: '@types/dns-packet@5.6.5': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/elliptic@6.4.18': dependencies: @@ -6660,7 +6656,7 @@ snapshots: '@types/express-serve-static-core@5.0.6': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/qs': 6.14.0 '@types/range-parser': 1.2.7 '@types/send': 0.17.4 @@ -6677,30 +6673,30 @@ snapshots: '@types/from2@2.3.5': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/fs-extra@11.0.4': dependencies: '@types/jsonfile': 6.1.4 - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/fs-extra@9.0.13': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/glob@7.2.0': dependencies: '@types/minimatch': 5.1.2 - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/glob@8.1.0': dependencies: '@types/minimatch': 5.1.2 - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/gunzip-maybe@1.4.2': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/hast@3.0.4': dependencies: @@ -6722,11 +6718,11 @@ snapshots: '@types/jsonfile@6.1.4': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/mailparser@3.4.6': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 iconv-lite: 0.6.3 '@types/mdast@4.0.4': @@ -6745,18 +6741,18 @@ snapshots: '@types/node-fetch@2.6.12': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 form-data: 4.0.2 '@types/node-forge@1.3.11': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 - '@types/node@18.19.101': + '@types/node@18.19.102': dependencies: undici-types: 5.26.5 - '@types/node@22.15.19': + '@types/node@22.15.20': dependencies: undici-types: 6.21.0 @@ -6772,30 +6768,30 @@ snapshots: '@types/s3rver@3.7.4': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/semver@7.7.0': {} '@types/send@0.17.4': dependencies: '@types/mime': 1.3.5 - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/serve-static@1.15.7': dependencies: '@types/http-errors': 2.0.4 - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/send': 0.17.4 '@types/symbol-tree@3.2.5': {} '@types/tar-stream@2.2.3': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/through2@2.0.41': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/triple-beam@1.3.5': {} @@ -6819,18 +6815,18 @@ snapshots: '@types/whatwg-url@8.2.2': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/webidl-conversions': 7.0.3 '@types/which@3.0.4': {} '@types/ws@8.18.1': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 '@types/yauzl@2.10.3': dependencies: - '@types/node': 22.15.19 + '@types/node': 22.15.20 optional: true '@ungap/structured-clone@1.3.0': {} @@ -7110,7 +7106,7 @@ snapshots: cloudflare@4.2.0: dependencies: - '@types/node': 18.19.101 + '@types/node': 18.19.102 '@types/node-fetch': 2.6.12 abort-controller: 3.0.0 agentkeepalive: 4.6.0 @@ -7381,7 +7377,7 @@ snapshots: engine.io@6.6.4: dependencies: '@types/cors': 2.8.18 - '@types/node': 22.15.19 + '@types/node': 22.15.20 accepts: 1.3.8 base64id: 2.0.0 cookie: 0.7.2 @@ -8287,7 +8283,7 @@ snapshots: undici: 7.9.0 yargs: 17.7.2 - mailparser@3.7.2: + mailparser@3.7.3: dependencies: encoding-japanese: 2.2.0 he: 1.2.0 @@ -8295,12 +8291,12 @@ snapshots: iconv-lite: 0.6.3 libmime: 5.3.6 linkify-it: 5.0.0 - mailsplit: 5.4.2 - nodemailer: 6.9.16 + mailsplit: 5.4.3 + nodemailer: 7.0.3 punycode.js: 2.3.1 - tlds: 1.255.0 + tlds: 1.259.0 - mailsplit@5.4.2: + mailsplit@5.4.3: dependencies: libbase64: 1.3.0 libmime: 5.3.6 @@ -8810,8 +8806,6 @@ snapshots: node-forge@1.3.1: {} - nodemailer@6.9.16: {} - nodemailer@7.0.3: {} normalize-newline@4.1.0: @@ -9564,7 +9558,7 @@ snapshots: dependencies: esm: 3.2.25 - tlds@1.255.0: {} + tlds@1.259.0: {} tldts-core@7.0.7: {} diff --git a/test/test.bouncemanager.ts b/test/test.bouncemanager.ts index 603cf7f..14d129c 100644 --- a/test/test.bouncemanager.ts +++ b/test/test.bouncemanager.ts @@ -1,6 +1,6 @@ import { tap, expect } from '@git.zone/tstest/tapbundle'; import * as plugins from '../ts/plugins.js'; -import { SzPlatformService } from '../ts/platformservice.js'; +import { SzPlatformService } from '../ts/classes.platformservice.js'; import { BounceManager, BounceType, BounceCategory } from '../ts/mail/core/classes.bouncemanager.js'; /** diff --git a/test/test.dcrouter.ts b/test/test.dcrouter.ts deleted file mode 100644 index 5c839df..0000000 --- a/test/test.dcrouter.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { tap, expect } from '@git.zone/tstest/tapbundle'; -import * as plugins from '../ts/plugins.js'; -import { - DcRouter, - type IDcRouterOptions, - type IEmailConfig, - type EmailProcessingMode, - type IDomainRule -} from '../ts/classes.dcrouter.js'; - -tap.test('DcRouter class - basic functionality', async () => { - // Create a simple DcRouter instance - const options: IDcRouterOptions = { - tls: { - contactEmail: 'test@example.com' - } - }; - - const router = new DcRouter(options); - expect(router).toBeTruthy(); - expect(router instanceof DcRouter).toEqual(true); - expect(router.options.tls.contactEmail).toEqual('test@example.com'); -}); - -tap.test('DcRouter class - SmartProxy configuration', async () => { - // Create SmartProxy configuration - const smartProxyConfig: plugins.smartproxy.ISmartProxyOptions = { - fromPort: 443, - toPort: 8080, - targetIP: '10.0.0.10', - sniEnabled: true, - acme: { - port: 80, - enabled: true, - autoRenew: true, - useProduction: false, - renewThresholdDays: 30, - accountEmail: 'admin@example.com' - }, - globalPortRanges: [ - { from: 80, to: 80 }, - { from: 443, to: 443 } - ], - domainConfigs: [ - { - domains: ['example.com', 'www.example.com'], - allowedIPs: ['0.0.0.0/0'], - targetIPs: ['10.0.0.10'], - portRanges: [ - { from: 80, to: 80 }, - { from: 443, to: 443 } - ] - } - ] - }; - - const options: IDcRouterOptions = { - smartProxyConfig, - tls: { - contactEmail: 'test@example.com' - } - }; - - const router = new DcRouter(options); - expect(router.options.smartProxyConfig).toBeTruthy(); - expect(router.options.smartProxyConfig.domainConfigs.length).toEqual(1); - expect(router.options.smartProxyConfig.domainConfigs[0].domains[0]).toEqual('example.com'); -}); - -tap.test('DcRouter class - Email configuration', async () => { - // Create consolidated email configuration - const emailConfig: IEmailConfig = { - ports: [25, 587, 465], - hostname: 'mail.example.com', - maxMessageSize: 50 * 1024 * 1024, // 50MB - - defaultMode: 'forward' as EmailProcessingMode, - defaultServer: 'fallback-mail.example.com', - defaultPort: 25, - defaultTls: true, - - domainRules: [ - { - pattern: '*@example.com', - mode: 'forward' as EmailProcessingMode, - target: { - server: 'mail1.example.com', - port: 25, - useTls: true - } - }, - { - pattern: '*@example.org', - mode: 'mta' as EmailProcessingMode, - mtaOptions: { - domain: 'example.org', - allowLocalDelivery: true - } - } - ] - }; - - const options: IDcRouterOptions = { - emailConfig, - tls: { - contactEmail: 'test@example.com' - } - }; - - const router = new DcRouter(options); - expect(router.options.emailConfig).toBeTruthy(); - expect(router.options.emailConfig.ports.length).toEqual(3); - expect(router.options.emailConfig.domainRules.length).toEqual(2); - expect(router.options.emailConfig.domainRules[0].pattern).toEqual('*@example.com'); - expect(router.options.emailConfig.domainRules[1].pattern).toEqual('*@example.org'); -}); - -tap.test('DcRouter class - Domain pattern matching', async () => { - const router = new DcRouter({}); - - // Use the internal method for testing if accessible - // This requires knowledge of the implementation, so it's a bit brittle - if (typeof router['isDomainMatch'] === 'function') { - // Test exact match - expect(router['isDomainMatch']('example.com', 'example.com')).toEqual(true); - expect(router['isDomainMatch']('example.com', 'example.org')).toEqual(false); - - // Test wildcard match - expect(router['isDomainMatch']('sub.example.com', '*.example.com')).toEqual(true); - expect(router['isDomainMatch']('sub.sub.example.com', '*.example.com')).toEqual(true); - expect(router['isDomainMatch']('example.com', '*.example.com')).toEqual(false); - expect(router['isDomainMatch']('sub.example.org', '*.example.com')).toEqual(false); - } -}); - -// Final clean-up test -tap.test('clean up after tests', async () => { - // No-op - just to make sure everything is cleaned up properly -}); - -tap.test('stop', async () => { - await tap.stopForcefully(); -}); - -// Export a function to run all tests -export default tap.start(); \ No newline at end of file diff --git a/test/test.emailauth.ts b/test/test.emailauth.ts index dd16c3f..fcf227c 100644 --- a/test/test.emailauth.ts +++ b/test/test.emailauth.ts @@ -1,5 +1,5 @@ import { tap, expect } from '@git.zone/tstest/tapbundle'; -import { SzPlatformService } from '../ts/platformservice.js'; +import { SzPlatformService } from '../ts/classes.platformservice.js'; import { SpfVerifier, SpfQualifier, SpfMechanismType } from '../ts/mail/security/classes.spfverifier.js'; import { DmarcVerifier, DmarcPolicy, DmarcAlignment } from '../ts/mail/security/classes.dmarcverifier.js'; import { Email } from '../ts/mail/core/classes.email.js'; diff --git a/test/test.integration.ts b/test/test.integration.ts index 8040190..4962557 100644 --- a/test/test.integration.ts +++ b/test/test.integration.ts @@ -1,6 +1,6 @@ import { tap, expect } from '@git.zone/tstest/tapbundle'; import * as plugins from '../ts/plugins.js'; -import { SzPlatformService } from '../ts/platformservice.js'; +import { SzPlatformService } from '../ts/classes.platformservice.js'; import { MtaService } from '../ts/mail/delivery/classes.mta.js'; import { EmailService } from '../ts/mail/services/classes.emailservice.js'; import { BounceManager } from '../ts/mail/core/classes.bouncemanager.js'; diff --git a/ts/aibridge/classes.aibridge.ts b/ts/aibridge/classes.aibridge.ts deleted file mode 100644 index 84e9848..0000000 --- a/ts/aibridge/classes.aibridge.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class AIBridge { - -} \ No newline at end of file diff --git a/ts/classes.dcrouter.ts b/ts/classes.dcrouter.ts index b605fbb..3be54de 100644 --- a/ts/classes.dcrouter.ts +++ b/ts/classes.dcrouter.ts @@ -11,7 +11,8 @@ import { UnifiedDeliveryQueue, type IQueueOptions } from './mail/delivery/classe import { MultiModeDeliverySystem, type IMultiModeDeliveryOptions } from './mail/delivery/classes.delivery.system.js'; import { UnifiedRateLimiter, type IHierarchicalRateLimits } from './mail/delivery/classes.unified.rate.limiter.js'; import { logger } from './logger.js'; -import { applyCustomEmailStorage } from './mail/delivery/classes.mta.patch.js'; +// Import the MTA configuration helpers directly from mail/delivery +import { configureMtaStorage, configureMtaService } from './mail/delivery/index.js'; export interface IDcRouterOptions { /** @@ -121,7 +122,7 @@ export class DcRouter { // Apply custom email storage configuration if available if (this.platformServiceRef && this.options.emailPortConfig?.receivedEmailsPath) { logger.log('info', 'Applying custom email storage configuration'); - applyCustomEmailStorage(this.platformServiceRef, this.options); + configureMtaStorage(this.platformServiceRef, this.options); } } @@ -160,7 +161,9 @@ export class DcRouter { // If email config exists, automatically add email routes if (this.options.emailConfig) { const emailRoutes = this.generateEmailRoutes(this.options.emailConfig); - routes = [...routes, ...emailRoutes]; + console.log(`Email Routes are:`) + console.log(emailRoutes) + routes = [...routes, /* ...emailRoutes */]; } // Merge TLS/ACME configuration if provided at root level @@ -662,6 +665,63 @@ export class DcRouter { return stats; } + + /** + * Configure MTA for email handling with custom port and storage settings + * @param config Configuration for the MTA service + */ + public async configureEmailMta(config: { + internalPort: number; + host?: string; + secure?: boolean; + storagePath?: string; + portMapping?: Record; + }): Promise { + logger.log('info', 'Configuring MTA service with custom settings'); + + if (!this.platformServiceRef) { + throw new Error('Platform service reference is required for MTA configuration'); + } + + // Update email port configuration + if (!this.options.emailPortConfig) { + this.options.emailPortConfig = {}; + } + + // Configure storage paths for received emails + if (config.storagePath) { + // Set the storage path for received emails + this.options.emailPortConfig.receivedEmailsPath = config.storagePath; + } + + // Apply port mapping if provided + if (config.portMapping) { + this.options.emailPortConfig.portMapping = { + ...this.options.emailPortConfig.portMapping, + ...config.portMapping + }; + + logger.log('info', `Updated MTA port mappings: ${JSON.stringify(this.options.emailPortConfig.portMapping)}`); + } + + // Use the dedicated helper to configure the MTA service + // Pass through the port specified by the implementation + configureMtaService(this.platformServiceRef, { + port: config.internalPort, // Use whatever port the implementation specifies + host: config.host, + secure: config.secure, + storagePath: config.storagePath + }); + + // If email handling is already set up, restart it to apply changes + if (this.unifiedEmailServer) { + logger.log('info', 'Restarting unified email handling to apply MTA configuration changes'); + await this.stopUnifiedEmailComponents(); + await this.setupUnifiedEmailHandling(); + } + + return true; + } } export default DcRouter; diff --git a/ts/classes.platformservicedb.ts b/ts/classes.platformservicedb.ts deleted file mode 100644 index bb36078..0000000 --- a/ts/classes.platformservicedb.ts +++ /dev/null @@ -1,27 +0,0 @@ -import * as plugins from './plugins.js'; -import { SzPlatformService } from './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(); - } -} diff --git a/ts/classes.smtp.portconfig.ts b/ts/classes.smtp.portconfig.ts index d89ea9a..a6d03fd 100644 --- a/ts/classes.smtp.portconfig.ts +++ b/ts/classes.smtp.portconfig.ts @@ -282,14 +282,4 @@ export class SmtpPortConfig { return routes; } - - /** - * Apply port configurations to SmartProxy settings - * @param smartProxy SmartProxy instance - * @deprecated Use toSmartProxyRoutes() instead to generate routes - */ - public applyToSmartProxy(smartProxy: plugins.smartproxy.SmartProxy): void { - console.warn('SmtpPortConfig.applyToSmartProxy() is deprecated. Use toSmartProxyRoutes() instead.'); - // This method is deprecated and no longer functional - } } \ No newline at end of file diff --git a/ts/index.ts b/ts/index.ts index 10508bf..4d2aca6 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,5 +1,5 @@ export * from './00_commitinfo_data.js'; -import { SzPlatformService } from './platformservice.js'; +import { SzPlatformService } from './classes.platformservice.js'; export * from './mail/index.js'; // DcRouter diff --git a/ts/mail/delivery/classes.mta.config.ts b/ts/mail/delivery/classes.mta.config.ts new file mode 100644 index 0000000..a8e1937 --- /dev/null +++ b/ts/mail/delivery/classes.mta.config.ts @@ -0,0 +1,71 @@ +import * as plugins from '../../plugins.js'; +import * as paths from '../../paths.js'; +import type { SzPlatformService } from '../../classes.platformservice.js'; + +/** + * Configures MTA storage settings for the platform service + * @param platformService Reference to the platform service + * @param options Configuration options containing storage paths + */ +export function configureMtaStorage(platformService: SzPlatformService, options: any): void { + // Extract the receivedEmailsPath if available + if (options?.emailPortConfig?.receivedEmailsPath) { + const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath; + + // Ensure the directory exists + plugins.smartfile.fs.ensureDirSync(receivedEmailsPath); + + // Apply configuration to MTA service if available + if (platformService.mtaService) { + platformService.mtaService.configure({ + storagePath: receivedEmailsPath + }); + + console.log(`Configured MTA to store received emails to: ${receivedEmailsPath}`); + } + } +} + +/** + * Configure MTA service with port and storage settings + * @param platformService Reference to the platform service + * @param config Configuration settings for MTA + */ +export function configureMtaService( + platformService: SzPlatformService, + config: { + port?: number; + host?: string; + secure?: boolean; + storagePath?: string; + } +): boolean { + if (!platformService?.mtaService) { + console.error('MTA service not available in platform service'); + return false; + } + + // Configure MTA with the provided port + const mtaConfig = { + port: config.port, // Use the port provided by the config + host: config.host || 'localhost', + secure: config.secure || false, + storagePath: config.storagePath + }; + + // Configure the MTA service + platformService.mtaService.configure(mtaConfig); + + console.log(`Configured MTA service on port ${mtaConfig.port}`); + + // Set up storage path if provided + if (config.storagePath) { + configureMtaStorage(platformService, { + emailPortConfig: { + receivedEmailsPath: config.storagePath + } + }); + } + + return true; +} \ No newline at end of file diff --git a/ts/mail/delivery/classes.mta.patch.ts b/ts/mail/delivery/classes.mta.patch.ts deleted file mode 100644 index a46ff4d..0000000 --- a/ts/mail/delivery/classes.mta.patch.ts +++ /dev/null @@ -1,72 +0,0 @@ -import * as plugins from '../../plugins.js'; -import * as paths from '../../paths.js'; -import type { SzPlatformService } from '../../platformservice.js'; - -/** - * Extension to the MTA service to handle custom email storage - */ -export function configureEmailStorage(mtaService: any, options: any = {}) { - const originalSaveToLocalMailbox = mtaService.saveToLocalMailbox; - - // Override the saveToLocalMailbox method to use custom path - mtaService.saveToLocalMailbox = async function(email: any): Promise { - try { - // Use the custom received emails path if configured - const customPath = options?.receivedEmailsPath; - - if (customPath) { - // Ensure the directory exists - plugins.smartfile.fs.ensureDirSync(customPath); - - // Check if this is a bounce notification - const isBounceNotification = this.isBounceNotification(email); - - if (isBounceNotification) { - await this.processBounceNotification(email); - return; - } - - // Store the email in the custom path - const emailContent = email.toRFC822String(); - const filename = `${Date.now()}_${email.to[0].replace(/[^a-zA-Z0-9]/g, '_')}.eml`; - - plugins.smartfile.memory.toFsSync( - emailContent, - plugins.path.join(customPath, filename) - ); - - console.log(`Email saved to custom mailbox location: ${customPath}/${filename}`); - } else { - // Use the original implementation - await originalSaveToLocalMailbox.call(this, email); - } - } catch (error) { - console.error('Error saving email to local mailbox:', error); - throw error; - } - }; - - return mtaService; -} - -/** - * Apply the email storage configuration to the platform service - */ -export function applyCustomEmailStorage(platformService: SzPlatformService, options: any): void { - // Extract the receivedEmailsPath if available - if (options?.emailPortConfig?.receivedEmailsPath) { - const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath; - - // Ensure the directory exists - plugins.smartfile.fs.ensureDirSync(receivedEmailsPath); - - // Apply configuration to MTA service if available - if (platformService.mtaService) { - configureEmailStorage(platformService.mtaService, { - receivedEmailsPath - }); - - console.log(`Configured MTA to store received emails to: ${receivedEmailsPath}`); - } - } -} \ No newline at end of file diff --git a/ts/mail/delivery/classes.mta.ts b/ts/mail/delivery/classes.mta.ts index 23a3351..af0625d 100644 --- a/ts/mail/delivery/classes.mta.ts +++ b/ts/mail/delivery/classes.mta.ts @@ -14,7 +14,7 @@ import { RateLimiter, type IRateLimitConfig } from './classes.ratelimiter.js'; import { ContentScanner } from '../../security/classes.contentscanner.js'; import { IPWarmupManager } from '../../deliverability/classes.ipwarmupmanager.js'; import { SenderReputationMonitor } from '../../deliverability/classes.senderreputationmonitor.js'; -import type { SzPlatformService } from '../../platformservice.js'; +import type { SzPlatformService } from '../../classes.platformservice.js'; /** * Configuration options for the MTA service @@ -41,6 +41,8 @@ export interface IMtaConfig { keyPath?: string; certPath?: string; }; + /** Custom path to store received emails */ + customStoragePath?: string; /** Outbound email sending configuration */ outbound?: { /** Maximum concurrent sending jobs */ @@ -694,6 +696,8 @@ export class MtaService { /** * Save an email to a local mailbox + * + * This implementation supports custom email storage paths via options.receivedEmailsPath */ private async saveToLocalMailbox(email: Email): Promise { // Check if this is a bounce notification @@ -704,19 +708,43 @@ export class MtaService { return; } - // Simplified implementation - in a real system, this would store to a user's mailbox - const mailboxPath = plugins.path.join(paths.receivedEmailsDir, 'local'); - plugins.smartfile.fs.ensureDirSync(mailboxPath); - - const emailContent = email.toRFC822String(); - const filename = `${Date.now()}_${email.to[0].replace('@', '_at_')}.eml`; - - plugins.smartfile.memory.toFsSync( - emailContent, - plugins.path.join(mailboxPath, filename) - ); - - console.log(`Email saved to local mailbox: ${filename}`); + try { + // Check if we have a custom storage path configured + const customPath = this.config?.customStoragePath; + + if (customPath) { + // Ensure the directory exists + plugins.smartfile.fs.ensureDirSync(customPath); + + // Store the email in the custom path + const emailContent = email.toRFC822String(); + const filename = `${Date.now()}_${email.to[0].replace(/[^a-zA-Z0-9]/g, '_')}.eml`; + + plugins.smartfile.memory.toFsSync( + emailContent, + plugins.path.join(customPath, filename) + ); + + console.log(`Email saved to custom mailbox location: ${customPath}/${filename}`); + } else { + // Use the default path + const mailboxPath = plugins.path.join(paths.receivedEmailsDir, 'local'); + plugins.smartfile.fs.ensureDirSync(mailboxPath); + + const emailContent = email.toRFC822String(); + const filename = `${Date.now()}_${email.to[0].replace('@', '_at_')}.eml`; + + plugins.smartfile.memory.toFsSync( + emailContent, + plugins.path.join(mailboxPath, filename) + ); + + console.log(`Email saved to local mailbox: ${filename}`); + } + } catch (error) { + console.error('Error saving email to local mailbox:', error); + throw error; + } } /** @@ -1322,6 +1350,81 @@ export class MtaService { return this.reputationMonitor; } + /** + * Configure MTA with new settings + */ + public configure(config: { + port?: number; + host?: string; + secure?: boolean; + storagePath?: string; + }): void { + console.log('Configuring MTA service with new settings:', config); + + // Update SMTP port if provided + if (config.port !== undefined) { + // Store the original port + const originalPort = this.config.smtp.port; + this.config.smtp.port = config.port; + + console.log(`Updated MTA port from ${originalPort} to ${config.port}`); + + // If the server is already running, we need to restart it + if (this.server && this.running) { + console.log('Restarting SMTP server with new port'); + + const restartServer = async () => { + try { + // Stop the current server + await this.server.stop(); + + // Create and start the new server with updated config + const smtpOptions: ISmtpServerOptions = { + port: this.config.smtp.port, + key: this.certificate.privateKey, + cert: this.certificate.publicKey, + hostname: this.config.smtp.hostname + }; + + this.server = new SMTPServer(this, smtpOptions); + this.server.start(); + + console.log(`SMTP server restarted on port ${smtpOptions.port}`); + } catch (error) { + console.error('Error restarting SMTP server:', error); + } + }; + + // Execute the restart + restartServer().catch(error => { + console.error('Failed to restart SMTP server:', error); + }); + } + } + + // Update hostname if provided + if (config.host) { + this.config.smtp.hostname = config.host; + console.log(`Updated MTA hostname to ${config.host}`); + } + + // Update TLS settings if secure flag is provided + if (config.secure !== undefined) { + // This would update TLS settings as appropriate + console.log(`Updated MTA TLS settings (secure: ${config.secure})`); + } + + // Update storage path if provided + if (config.storagePath) { + this.config.customStoragePath = config.storagePath; + + // Ensure the directory exists + plugins.smartfile.fs.ensureDirSync(config.storagePath); + + console.log(`Updated MTA storage path to ${config.storagePath}`); + } + } + /** * Get MTA service statistics */ diff --git a/ts/mail/delivery/index.ts b/ts/mail/delivery/index.ts index 15f96e8..0378efb 100644 --- a/ts/mail/delivery/index.ts +++ b/ts/mail/delivery/index.ts @@ -15,4 +15,7 @@ export { RateLimiter } from './classes.ratelimiter.js'; export type { IRateLimitConfig } from './classes.ratelimiter.js'; // Unified rate limiter -export * from './classes.unified.rate.limiter.js'; \ No newline at end of file +export * from './classes.unified.rate.limiter.js'; + +// MTA configuration helpers +export * from './classes.mta.config.js'; \ No newline at end of file diff --git a/ts/mail/services/classes.emailservice.ts b/ts/mail/services/classes.emailservice.ts index 92cf22b..1bfe4c5 100644 --- a/ts/mail/services/classes.emailservice.ts +++ b/ts/mail/services/classes.emailservice.ts @@ -7,7 +7,7 @@ import { TemplateManager } from '../core/classes.templatemanager.js'; import { EmailValidator } from '../core/classes.emailvalidator.js'; import { BounceManager } from '../core/classes.bouncemanager.js'; import { logger } from '../../logger.js'; -import type { SzPlatformService } from '../../platformservice.js'; +import type { SzPlatformService } from '../../classes.platformservice.js'; // Import MTA service import { MtaService } from '../delivery/classes.mta.js'; diff --git a/ts/platformservice.ts b/ts/platformservice.ts deleted file mode 100644 index 21009e9..0000000 --- a/ts/platformservice.ts +++ /dev/null @@ -1,188 +0,0 @@ -import * as plugins from './plugins.js'; -import * as paths from './paths.js'; -import { PlatformServiceDb } from './classes.platformservicedb.js' -import { EmailService } from './mail/services/classes.emailservice.js'; -import { SmsService } from './sms/classes.smsservice.js'; -import { MtaService } from './mail/delivery/classes.mta.js'; -import { logger } from './logger.js'; -import { type IPlatformConfig } from './config/index.js'; -import { ConfigurationError } from './errors/base.errors.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(); - - // SubServices - public emailService: EmailService; - public mtaService: MtaService; - public smsService: SmsService; - - // Platform configuration - public config: IPlatformConfig; - - /** - * Create a new platform service instance - * - * @param config Optional platform configuration - */ - constructor(config: IPlatformConfig) { - // Store configuration - this.config = config; - - // Initialize typed router - this.typedrouter = new plugins.typedrequest.TypedRouter(); - } - - /** - * Initialize the platform service - * Applies configuration provided in constructor - */ - public async initialize(): Promise { - // Simple validation of config - must be provided - if (!this.config) { - throw new ConfigurationError( - 'Platform configuration must be provided in constructor', - 'PLATFORM_CONFIG_MISSING', - {} - ); - } - - // Apply configuration to logger - if (this.config.logging) { - logger.setContext({ - environment: this.config.environment, - component: 'PlatformService' - }); - } - - // Create project info - this.projectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir); - - // Initialize database - this.platformserviceDb = new PlatformServiceDb(this); - - logger.info('Platform service initialized successfully'); - } - - /** - * Start the platform service - */ - public async start(): Promise { - // Initialize first if needed - if (!this.config) { - await this.initialize(); - } - - // Check if service is enabled - if (this.config.enabled === false) { - logger.warn('Platform service is disabled in configuration, not starting services'); - return; - } - - logger.info('Starting platform service...'); - - // Initialize sub-services - await this.initializeServices(); - - // Start the HTTP server - await this.startServer(); - - logger.info('Platform service started successfully'); - } - - /** - * Initialize and start sub-services - */ - private async initializeServices(): Promise { - // Initialize email service - if (this.config.email?.enabled !== false) { - this.emailService = new EmailService(this, this.config.email); - await this.emailService.start(); - logger.info('Email service started'); - - // Initialize MTA service if needed - if (this.config.email?.useMta) { - this.mtaService = new MtaService(this, this.config.email.mtaConfig); - logger.info('MTA service initialized'); - } - } else { - logger.info('Email service disabled in configuration'); - } - - // Initialize SMS service - if (this.config.sms?.enabled !== false) { - // Get API token from config or env var - const apiToken = this.config.sms?.apiGatewayApiToken || - await this.serviceQenv.getEnvVarOnDemand('SMS_API_TOKEN'); - - if (!apiToken) { - logger.warn('No SMS API token provided, SMS service will not be started'); - } else { - this.smsService = new SmsService(this, { - apiGatewayApiToken: apiToken, - ...this.config.sms - }); - await this.smsService.start(); - logger.info('SMS service started'); - } - } else { - logger.info('SMS service disabled in configuration'); - } - } - - /** - * Start the HTTP server - */ - private async startServer(): Promise { - // Check if server is enabled - if (this.config.server?.enabled === false) { - logger.info('HTTP server disabled in configuration'); - return; - } - - // Create server with configuration - this.typedserver = new plugins.typedserver.TypedServer({ - cors: this.config.server?.cors === false ? false : true, - port: this.config.server?.port || 3000, - // hostname is not supported directly, will be set during start - }); - - // Add the router - // Note: Using any type to bypass TypeScript restriction - (this.typedserver as any).addRouter(this.typedrouter); - - // Start server - await this.typedserver.start(); - logger.info(`HTTP server started on ${this.config.server?.host || '0.0.0.0'}:${this.config.server?.port || 3000}`); - } - - /** - * Stop the platform service - */ - public async stop(): Promise { - logger.info('Stopping platform service...'); - - // Stop sub-services - if (this.emailService) { - await this.emailService.stop(); - logger.info('Email service stopped'); - } - - if (this.smsService) { - await this.smsService.stop(); - logger.info('SMS service stopped'); - } - - // Stop the server if it's running - if (this.typedserver) { - await this.typedserver.stop(); - logger.info('HTTP server stopped'); - } - - logger.info('Platform service stopped successfully'); - } -} \ No newline at end of file diff --git a/ts/sms/classes.smsservice.ts b/ts/sms/classes.smsservice.ts index df6b366..ad60ca3 100644 --- a/ts/sms/classes.smsservice.ts +++ b/ts/sms/classes.smsservice.ts @@ -1,7 +1,7 @@ import * as plugins from '../plugins.js'; import * as paths from '../paths.js'; import { logger } from '../logger.js'; -import type { SzPlatformService } from '../platformservice.js'; +import type { SzPlatformService } from '../classes.platformservice.js'; import type { ISmsConfig } from '../config/sms.config.js'; import { ConfigValidator, smsConfigSchema } from '../config/index.js';