From 854f1f73dcf5ab3611441644b36b3259504394f3 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sat, 5 Oct 2024 07:54:09 +0200 Subject: [PATCH] fix(platformclient): Refactor debug mode checks in SzPlatformClient connectors --- changelog.md | 6 ++++ package.json | 2 +- pnpm-lock.yaml | 10 +++--- ts/00_commitinfo_data.ts | 2 +- ts/classes.platformclient.ts | 4 +++ ts/email/classes.letterconnector.ts | 9 +++++ ts/email/classes.pushnotificationconnector.ts | 34 +++++++++++++++++++ ts/email/classes.smsconnector.ts | 6 +++- 8 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 ts/email/classes.pushnotificationconnector.ts diff --git a/changelog.md b/changelog.md index ca72cef..6ae1bad 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-10-05 - 1.1.1 - fix(platformclient) +Refactor debug mode checks in SzPlatformClient connectors + +- Unified debug mode checks across email, SMS, and letter connectors +- Added new SzPushNotificationConnector class with debug mode functionality + ## 2024-10-04 - 1.1.0 - feat(SzPlatformClient) Add debug mode functionality to SzPlatformClient and SzEmailConnector diff --git a/package.json b/package.json index b225422..1cffc30 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@push.rocks/qenv": "^6.0.5", "@push.rocks/smartlog": "^3.0.7", "@push.rocks/smartntml": "^2.0.4", - "@serve.zone/interfaces": "^1.0.81" + "@serve.zone/interfaces": "^1.1.1" }, "repository": { "type": "git", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 776571b..521ba10 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,8 +27,8 @@ importers: specifier: ^2.0.4 version: 2.0.4 '@serve.zone/interfaces': - specifier: ^1.0.81 - version: 1.0.81 + specifier: ^1.1.1 + version: 1.1.1 devDependencies: '@git.zone/tsbuild': specifier: ^2.1.84 @@ -599,8 +599,8 @@ packages: '@sec-ant/readable-stream@0.4.1': resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==} - '@serve.zone/interfaces@1.0.81': - resolution: {integrity: sha512-ra0pALnvhYut2Ts55BHWKv8q1ysjf84AS0cG/Pi8FB53/OqCnaaETr2qJrAETa6OcuDDDm++R0KVZm+R5evbwQ==} + '@serve.zone/interfaces@1.1.1': + resolution: {integrity: sha512-Ir9xs06UYvsGoo67en7hitzMxZJ3kOBZWoQs5HIV+dTTd/5eMBjidFPJH+x6MSZsr3mb907s5Sfmb8FEtgMFYA==} '@sindresorhus/is@5.6.0': resolution: {integrity: sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==} @@ -3963,7 +3963,7 @@ snapshots: '@sec-ant/readable-stream@0.4.1': {} - '@serve.zone/interfaces@1.0.81': + '@serve.zone/interfaces@1.1.1': dependencies: '@api.global/typedrequest-interfaces': 3.0.19 '@push.rocks/smartlog-interfaces': 3.0.2 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 1f8dda5..415e0fb 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/platformclient', - version: '1.1.0', + version: '1.1.1', description: 'a module that makes it really easy to use the serve.zone platform inside your app' } diff --git a/ts/classes.platformclient.ts b/ts/classes.platformclient.ts index 125ab32..1385417 100644 --- a/ts/classes.platformclient.ts +++ b/ts/classes.platformclient.ts @@ -1,5 +1,7 @@ import { SzEmailConnector } from './email/classes.emailconnector.js'; import { SzSmsConnector } from './email/classes.smsconnector.js'; +import { SzPushNotificationConnector } from './email/classes.pushnotificationconnector.js'; +import { SzLetterConnector } from './email/classes.letterconnector.js'; import * as plugins from './plugins.js'; export class SzPlatformClient { @@ -11,6 +13,8 @@ export class SzPlatformClient { public emailConnector = new SzEmailConnector(this); public smsConnector = new SzSmsConnector(this); + public pushNotificationConnector = new SzPushNotificationConnector(this); + public letterConnector = new SzLetterConnector(this); constructor(authorizationStringArg?: string) { this.authorizationString = authorizationStringArg; diff --git a/ts/email/classes.letterconnector.ts b/ts/email/classes.letterconnector.ts index ec52498..ed9c38c 100644 --- a/ts/email/classes.letterconnector.ts +++ b/ts/email/classes.letterconnector.ts @@ -11,6 +11,15 @@ export class SzLetterConnector { public async sendLetter( optionsArg: plugins.servezoneInterfaces.platformservice.letter.IRequest_SendLetter['request'] ) { + + if (this.platformClientRef.debugMode) { + console.log('sendLetter', optionsArg); + } + + if (this.platformClientRef.debugMode) { + return; + } + const typedRequest = this.platformClientRef.typedsocket.createTypedRequest( 'sendLetter' diff --git a/ts/email/classes.pushnotificationconnector.ts b/ts/email/classes.pushnotificationconnector.ts new file mode 100644 index 0000000..d046540 --- /dev/null +++ b/ts/email/classes.pushnotificationconnector.ts @@ -0,0 +1,34 @@ +import type { SzPlatformClient } from '../classes.platformclient.js'; +import * as plugins from '../plugins.js'; + +export class SzPushNotificationConnector { + public platformClientRef: SzPlatformClient; + + constructor(platformClientRefArg: SzPlatformClient) { + this.platformClientRef = platformClientRefArg; + } + + public async sendPushNotification( + optionsArg: plugins.servezoneInterfaces.platformservice.pushnotification.IRequest_SendPushNotification['request'] + ) { + if (this.platformClientRef.debugMode) { + console.log('sendPushNotification', optionsArg); + } + + if (this.platformClientRef.debugMode) { + return; + } + + const typedRequest = + this.platformClientRef.typedsocket.createTypedRequest( + 'sendPushNotification' + ); + const response = await typedRequest.fire(optionsArg); + + if (process.env.SERVEZONE_PLATFORMCLIENT_DEBUG) { + console.log('sendPushNotification response', response); + } + + return response.status; + } +} \ No newline at end of file diff --git a/ts/email/classes.smsconnector.ts b/ts/email/classes.smsconnector.ts index 79bee70..45262e2 100644 --- a/ts/email/classes.smsconnector.ts +++ b/ts/email/classes.smsconnector.ts @@ -10,13 +10,17 @@ export class SzSmsConnector { } public async sendSms(messageArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendSms['request']) { - if (process.env.SERVEZONE_PLATFORMCLIENT_DEBUG) { + if (this.platformClientRef.debugMode) { logger.log('info', `sent sms to ${messageArg.toNumber}} body: ${messageArg.messageText.split('\n').map(line => ` ${line}`).join('\n')} `); } + + if (this.platformClientRef.debugMode) { + return; + } const typedrequest = this.platformClientRef.typedsocket.createTypedRequest( 'sendSms'