Compare commits

...

14 Commits

13 changed files with 148 additions and 28 deletions

View File

@ -1,5 +1,48 @@
# Changelog
## 2024-10-05 - 1.1.2 - fix(core)
Fix authorization handling and format code.
- Resolved the incorrect condition check for 'authorizationStringArg' within the 'init' function.
- Corrected the condition to activate 'debugMode' within the 'init' function.
- Improved code formatting for better readability.
## 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
- 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)
Reorder debug logging to avoid confusion in email and sms connectors
- Reordered the logging after request creation in `sendEmail` method of `SzEmailConnector`
- Reordered the logging after request creation in `sendSms` method of `SzSmsConnector`
## 2024-10-02 - 1.0.10 - fix(build)
Fix build script configuration and plugins import path
- Corrected the build script in package.json to include tsfolders parameter
- Fixed the import path for plugins in classes.infohtml.ts
## 2024-10-02 - 1.0.9 - fix(infohtml)
Refactor infohtml module and fix import paths
- Refactored ts_infohtml module.
- Fixed incorrect import paths in ts_infohtml module.
- Ensured that the InfoHtml class and related templates are properly imported and used.
## 2024-10-02 - 1.0.8 - fix(core)
Maintain dependencies, update metadata
- No changes detected
## 2024-10-02 - 1.0.7 - fix(core)
Update dependencies and add logging for email and SMS functions

View File

@ -1,6 +1,6 @@
{
"name": "@serve.zone/platformclient",
"version": "1.0.7",
"version": "1.1.2",
"private": false,
"description": "a module that makes it really easy to use the serve.zone platform inside your app",
"main": "dist_ts/index.js",
@ -10,7 +10,7 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"build": "(tsbuild tsfolders --web --allowimplicitany)",
"localPublish": "gitzone commit && pnpm run build && pnpm publish && pnpm publish --access public --registry=\"https://registry.npmjs.org\""
},
"devDependencies": {
@ -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",

10
pnpm-lock.yaml generated
View File

@ -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

View File

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

View File

@ -1,8 +1,11 @@
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 {
public debugMode = false;
private authorizationString: string;
public typedrouter = new plugins.typedrequest.TypedRouter();
public typedsocket: plugins.typedsocket.TypedSocket;
@ -10,20 +13,33 @@ 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;
}
public async init(authorizationStringArg?: string) {
if (authorizationStringArg) this.authorizationString = authorizationStringArg;
if (!this.authorizationString) this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION;
if (authorizationStringArg) {
this.authorizationString = authorizationStringArg;
}
if (!this.authorizationString)
this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION;
if (!this.authorizationString) throw new Error('authorizationString is required');
this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(this.typedrouter, await this.getConnectionAddress());
if (this.authorizationString === 'test') {
this.debugMode = true;
console.log('debug mode activated.');
return;
}
this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(
this.typedrouter,
await this.getConnectionAddress()
);
}
private async getConnectionAddress() {
const connectionAddress = await this.qenvInstance.getEnvVarOnDemand('SERVEZONE_API_DOMAIN');
return connectionAddress;
}
}
}

View File

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

View File

@ -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<plugins.servezoneInterfaces.platformservice.letter.IRequest_SendLetter>(
'sendLetter'

View File

@ -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<plugins.servezoneInterfaces.platformservice.pushnotification.IRequest_SendPushNotification>(
'sendPushNotification'
);
const response = await typedRequest.fire(optionsArg);
if (process.env.SERVEZONE_PLATFORMCLIENT_DEBUG) {
console.log('sendPushNotification response', response);
}
return response.status;
}
}

View File

@ -10,12 +10,7 @@ export class SzSmsConnector {
}
public async sendSms(messageArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendSms['request']) {
const typedrequest = this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.sms.IRequest_SendSms>(
'sendSms'
);
const response = await typedrequest.fire(messageArg);
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')}
@ -23,6 +18,14 @@ export class SzSmsConnector {
`);
}
if (this.platformClientRef.debugMode) {
return;
}
const typedrequest = this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.sms.IRequest_SendSms>(
'sendSms'
);
const response = await typedrequest.fire(messageArg);
return response.status;
}
@ -30,6 +33,12 @@ export class SzSmsConnector {
public async sendSmsVerifcation(
recipientArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode['request']
) {
if (this.platformClientRef.debugMode) {
console.log('sendSmsVerifcation', recipientArg, '123456');
return '123456';
}
const typedrequest =
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode>(
'sendVerificationCode'

View File

@ -1,4 +1,4 @@
import * as plugins from '../plugins.js';
import * as plugins from './plugins.js';
import { simpleInfo } from './template.js';

5
ts_infohtml/plugins.ts Normal file
View File

@ -0,0 +1,5 @@
import * as smartntml from '@push.rocks/smartntml';
export {
smartntml,
}

View File

@ -1,4 +1,4 @@
import * as plugins from '../plugins.js';
import * as plugins from './plugins.js';
import { type IHtmlInfoOptions } from './classes.infohtml.js';
export const simpleInfo = async (