fix(core): update

This commit is contained in:
2024-02-17 20:24:28 +01:00
commit 450e4e023d
23 changed files with 7216 additions and 0 deletions

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@serve.zone/platformclient',
version: '1.0.2',
description: 'a module that makes it really easy to use the serve.zone platform inside your app'
}

View File

@ -0,0 +1,26 @@
import { SzEmailConnector } from './email/classes.emailconnector.js';
import { SzSmsConnector } from './email/classes.smsconnector.js';
import * as plugins from './plugins.js';
export class SzPlatformClient {
private authorizationString: string;
public typedrouter = new plugins.typedrequest.TypedRouter();
public typedsocket: plugins.typedsocket.TypedSocket;
private qenvInstance = new plugins.qenv.Qenv();
public emailConnector = new SzEmailConnector(this);
public smsConnector = new SzSmsConnector(this);
constructor(authorizationStringArg: string) {
this.authorizationString = authorizationStringArg;
}
public async init() {
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

@ -0,0 +1,51 @@
import * as plugins from './plugins.js';
import { InfoHtml } from './infohtml/index.js';
export interface IServiceServerConstructorOptions {
addCustomRoutes?: (serverArg: plugins.typedserver.servertools.Server) => Promise<any>;
serviceName: string;
serviceVersion: string;
serviceDomain: string;
port?: number;
}
/**
* a server for serving your app to the outside world
*/
export class ServiceServer {
public options: IServiceServerConstructorOptions;
public typedServer: plugins.typedserver.TypedServer;
constructor(optionsArg: IServiceServerConstructorOptions) {
this.options = optionsArg;
}
public async start() {
console.log('starting lole-serviceserver...')
this.typedServer = new plugins.typedserver.TypedServer({
cors: true,
domain: this.options.serviceDomain,
forceSsl: false,
port: this.options.port || 3000,
robots: true,
defaultAnswer: async () => {
return (
await InfoHtml.fromSimpleText(
`${this.options.serviceName} (version ${this.options.serviceVersion})`
)
).htmlString;
},
});
// lets add any custom routes
if (this.options.addCustomRoutes) {
await this.options.addCustomRoutes(this.typedServer.server);
}
await this.typedServer.start();
}
public async stop() {
await this.typedServer.stop();
}
}

View File

@ -0,0 +1,24 @@
import type { SzPlatformClient } from '../classes.platformclient.js';
import * as plugins from '../plugins.js';
export class SzEmailConnector {
public platformClientRef: SzPlatformClient;
constructor(platformClientRefArg: SzPlatformClient) {
this.platformClientRef = platformClientRefArg;
}
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);
}
public async sendNotification(optionsArg: { toArg: string; subject: string; text: string }) {}
public async sendActionLink(optionsArg: { toArg: string; subject: string; text: string }) {}
}

View File

@ -0,0 +1,20 @@
import * as plugins from '../plugins.js';
import type { SzPlatformClient } from '../classes.platformclient.js';
export class SzLetterConnector {
public platformClientRef: SzPlatformClient;
constructor(platformClientRefArg: SzPlatformClient) {
this.platformClientRef = platformClientRefArg;
}
public async sendLetter(
optionsArg: plugins.servezoneInterfaces.platformservice.letter.IRequest_SendLetter['request']
) {
const typedRequest =
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.letter.IRequest_SendLetter>(
'sendLetter'
);
const response = await typedRequest.fire(optionsArg);
}
}

View File

@ -0,0 +1,29 @@
import type { SzPlatformClient } from '../classes.platformclient.js';
import * as plugins from '../plugins.js';
export class SzSmsConnector {
public platformClientRef: SzPlatformClient;
constructor(platformClientRefArg: SzPlatformClient) {
this.platformClientRef = platformClientRefArg;
}
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);
return response.status;
}
public async sendSmsVerifcation(
recipientArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode['request']
) {
const typedrequest =
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode>(
'sendVerificationCode'
);
const response = await typedrequest.fire(recipientArg);
return response.verificationCode;
}
}

7
ts/index.ts Normal file
View File

@ -0,0 +1,7 @@
export * from './classes.serviceserver.js';
// Things for building a server
import { servertools } from '@api.global/typedserver';
const { Handler, HandlerTypedRouter } = servertools;
export { Handler, HandlerTypedRouter };

View File

@ -0,0 +1,44 @@
import * as plugins from '../plugins.js';
import { simpleInfo } from './template.js';
export interface IHtmlInfoOptions {
text: string;
heading?: string;
title?: string;
sentryMessage?: string;
sentryDsn?: string;
redirectTo?: string;
}
export class InfoHtml {
// STATIC
public static async fromSimpleText(textArg: string) {
const infohtmlInstance = new InfoHtml({
text: textArg,
heading: null,
});
await infohtmlInstance.init();
return infohtmlInstance;
}
public static async fromOptions(optionsArg: IHtmlInfoOptions) {
const infohtmlInstance = new InfoHtml(optionsArg);
await infohtmlInstance.init();
return infohtmlInstance;
}
// INSTANCE
public options: IHtmlInfoOptions;
public smartntmlInstance: plugins.smartntml.Smartntml;
public htmlString: string;
constructor(optionsArg: IHtmlInfoOptions) {
this.options = optionsArg;
}
public async init() {
this.smartntmlInstance = new plugins.smartntml.Smartntml();
this.htmlString = await simpleInfo(this.smartntmlInstance, this.options);
return this.htmlString;
}
}

1
ts/infohtml/index.ts Normal file
View File

@ -0,0 +1 @@
export { InfoHtml } from './classes.infohtml.js';

162
ts/infohtml/template.ts Normal file
View File

@ -0,0 +1,162 @@
import * as plugins from '../plugins.js';
import { type IHtmlInfoOptions } from './classes.infohtml.js';
export const simpleInfo = async (
smartntmlInstanceArg: plugins.smartntml.Smartntml,
optionsArg: IHtmlInfoOptions
) => {
const html = plugins.smartntml.deesElement.html;
const htmlTemplate = await plugins.smartntml.deesElement.html`
<html lang="en">
<head>
<title>${optionsArg.title}</title>
<script>
setTimeout(() => {
const redirectUrl = '${optionsArg.redirectTo}';
if (redirectUrl) {
window.location = redirectUrl;
}
}, 5000);
</script>
<style>
body {
margin: 0px;
background: #000000;
font-family: 'Roboto Mono', monospace;
min-height: 100vh;
min-width: 100vw;
border: 1px solid #e4002b;
}
* {
box-sizing: border-box;
}
.logo {
width: 150px;
padding-top: 70px;
margin: 0px auto 30px auto;
}
.content {
text-align: center;
max-width: 800px;
margin: auto;
}
.content .maintext {
margin: 10px;
color: #ffffff;
background: #333;
display: block;
border-radius: 3px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
padding: 20px;
}
.content .maintext h1 {
margin: 0px;
}
.content .addontext {
margin: 10px;
color: #ffffff;
background: #222;
display: block;
padding: 10px 15px;
border-radius: 3px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
padding: 10px;
}
.content .text h1 {
margin: 0px;
font-weight: 100;
font-size: 40px;
}
.content .text ul {
text-align: left;
}
a {
color: #ffffff;
}
.legal {
color: #fff;
position: fixed;
bottom: 0px;
width: 100vw;
text-align: center;
padding: 10px;
}
</style>
<meta
name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"
/>
<script
src="https://browser.sentry-cdn.com/5.4.0/bundle.min.js"
crossorigin="anonymous"
></script>
<script>
const sentryDsn = '${optionsArg.sentryDsn}';
const sentryMessage = '${optionsArg.sentryMessage}';
if (optionsArg.sentryDsn && optionsArg.sentryMessage) {
Sentry.init({
dsn: '${optionsArg.sentryDsn}',
// ...
});
Sentry.setExtra('location', window.location.href);
Sentry.captureMessage('${optionsArg.sentryMessage} @ ' + window.location.host);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="logo">
<img src="https://assetbroker.lossless.one/brandfiles/lossless/svg-minimal-bright.svg" />
</div>
<div class="content">
${(() => {
const returnArray: plugins.smartntml.deesElement.TemplateResult[] = [];
if (optionsArg.heading) {
returnArray.push(html`
<div class="maintext">
<h1>${optionsArg.heading}</h1>
${optionsArg.text}
</div>
`);
} else {
returnArray.push(html` <div class="maintext">${optionsArg.text}</div> `);
}
if (optionsArg.sentryDsn && optionsArg.sentryMessage) {
returnArray.push(
html`<div class="addontext">
We recorded this event. Should you continue to see this page against your
expectations, feel free to mail us at
<a href="mailto:hello@lossless.com">hello@lossless.com</a>
</div>`
);
}
if (optionsArg.redirectTo) {
returnArray.push(
html`<div class="addontext">
We will redirect you to ${optionsArg.redirectTo} in a few seconds.
</div>`
);
}
return returnArray;
})()}
</div>
<div class="legal">
<a href="https://lossless.com">Lossless GmbH</a> / &copy 2014-${new Date().getFullYear()}
/ <a href="https://lossless.gmbh">Legal Info</a> /
<a href="https://lossless.gmbh">Privacy Policy</a>
</div>
</body>
</html>
`;
return smartntmlInstanceArg.renderTemplateResult(htmlTemplate);
};

9
ts/logger.ts Normal file
View File

@ -0,0 +1,9 @@
import * as plugins from './plugins.js';
export const logger = new plugins.smartlog.Smartlog({
logContext: {
environment: 'production',
runtime: 'node',
zone: 'serve.zone',
}
});

29
ts/plugins.ts Normal file
View File

@ -0,0 +1,29 @@
// @serve.zone scope
import * as servezoneInterfaces from '@serve.zone/interfaces';
export {
servezoneInterfaces,
}
// @push.rocks scope
import * as qenv from '@push.rocks/qenv';
import * as smartlog from '@push.rocks/smartlog';
import * as smartntml from '@push.rocks/smartntml';
export {
qenv,
smartlog,
smartntml,
}
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
import * as typedserver from '@api.global/typedserver';
import * as typedsocket from '@api.global/typedsocket';
export {
typedrequest,
typedserver,
typedsocket,
}