feat(SzPlatformClient): Add debug mode functionality to SzPlatformClient and SzEmailConnector

This commit is contained in:
Philipp Kunz 2024-10-04 13:39:41 +02:00
parent 965dad9b15
commit 7e721eb48e
4 changed files with 18 additions and 2 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 2024-10-04 - 1.1.0 - feat(SzPlatformClient)
Add debug mode functionality to SzPlatformClient and SzEmailConnector
- Introduced a debug mode in SzPlatformClient to handle authorization in test scenarios.
- Updated SzEmailConnector to log emails and early return in debug mode for testing purposes.
## 2024-10-02 - 1.0.11 - fix(email,sms) ## 2024-10-02 - 1.0.11 - fix(email,sms)
Reorder debug logging to avoid confusion in email and sms connectors Reorder debug logging to avoid confusion in email and sms connectors

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@serve.zone/platformclient', name: '@serve.zone/platformclient',
version: '1.0.11', version: '1.1.0',
description: 'a module that makes it really easy to use the serve.zone platform inside your app' description: 'a module that makes it really easy to use the serve.zone platform inside your app'
} }

View File

@ -3,6 +3,7 @@ import { SzSmsConnector } from './email/classes.smsconnector.js';
import * as plugins from './plugins.js'; import * as plugins from './plugins.js';
export class SzPlatformClient { export class SzPlatformClient {
public debugMode = false;
private authorizationString: string; private authorizationString: string;
public typedrouter = new plugins.typedrequest.TypedRouter(); public typedrouter = new plugins.typedrequest.TypedRouter();
public typedsocket: plugins.typedsocket.TypedSocket; public typedsocket: plugins.typedsocket.TypedSocket;
@ -19,6 +20,10 @@ export class SzPlatformClient {
if (authorizationStringArg) this.authorizationString = authorizationStringArg; if (authorizationStringArg) this.authorizationString = authorizationStringArg;
if (!this.authorizationString) this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION; if (!this.authorizationString) this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION;
if (!this.authorizationString) throw new Error('authorizationString is required'); if (!this.authorizationString) throw new Error('authorizationString is required');
if (authorizationStringArg === 'test') {
this.debugMode = true;
return;
}
this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(this.typedrouter, await this.getConnectionAddress()); this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(this.typedrouter, await this.getConnectionAddress());
} }

View File

@ -13,13 +13,18 @@ export class SzEmailConnector {
public async sendEmail( public async sendEmail(
optionsArg: plugins.servezoneInterfaces.platformservice.mta.IRequest_SendEmail['request'] optionsArg: plugins.servezoneInterfaces.platformservice.mta.IRequest_SendEmail['request']
) { ) {
if (process.env.SERVEZONE_PLATFORMCLIENT_DEBUG) { if (this.platformClientRef.debugMode) {
logger.log('info', `sent email with subject ${optionsArg.title} to ${optionsArg.to} logger.log('info', `sent email with subject ${optionsArg.title} to ${optionsArg.to}
body: body:
${optionsArg.body.split('\n').map(line => ` ${line}`).join('\n')} ${optionsArg.body.split('\n').map(line => ` ${line}`).join('\n')}
`); `);
} }
if (this.platformClientRef.debugMode) {
return;
}
const typedRequest = const typedRequest =
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.mta.IRequest_SendEmail>( this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.mta.IRequest_SendEmail>(
'sendEmail' 'sendEmail'