Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| df542ec67a | |||
| f0b924ba9d | |||
| b4b2ed9571 | |||
| 4b3a2b2e75 | |||
| 19344b2535 | |||
| e16c8876b8 | |||
| 1212ee9116 | |||
| b610cba9ac | |||
| 854f1f73dc | |||
| edc54f4fc1 | |||
| 7e721eb48e | |||
| 965dad9b15 | |||
| 4a75c109e3 |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"@git.zone/cli": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
@@ -9,10 +9,17 @@
|
||||
"npmPackagename": "@serve.zone/platformclient",
|
||||
"license": "MIT",
|
||||
"projectDomain": "serve.zone"
|
||||
},
|
||||
"release": {
|
||||
"registries": [
|
||||
"https://verdaccio.lossless.digital",
|
||||
"https://registry.npmjs.org"
|
||||
],
|
||||
"accessLevel": "public"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"@ship.zone/szci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+5
-5
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"fileMatch": ["/.smartconfig.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"@ship.zone/szci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
"description": "settings for szci"
|
||||
},
|
||||
"gitzone": {
|
||||
"@git.zone/cli": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"description": "settings for git.zone CLI",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
|
||||
+37
-1
@@ -1,5 +1,41 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-04-28 - 1.1.4 - fix(platformclient)
|
||||
Keep platform environment configuration clean.
|
||||
|
||||
- Kept only `SERVEZONE_PLATFORM_URL`, `SERVEZONE_PLATFORM_AUTHORIZATION`, `SERVEZONE_PLATFORM_TOKEN`, and platform binding discovery.
|
||||
|
||||
## 2026-04-28 - 1.1.3 - feat(platformclient)
|
||||
Add runtime platform binding configuration.
|
||||
|
||||
- Added `SERVEZONE_PLATFORM_URL`, `SERVEZONE_PLATFORM_AUTHORIZATION`, and `SERVEZONE_PLATFORM_TOKEN` support.
|
||||
- Added environment binding discovery through `SERVEZONE_PLATFORM_BINDING` and `SERVEZONE_PLATFORM_BINDINGS`.
|
||||
|
||||
## 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
|
||||
|
||||
@@ -46,4 +82,4 @@ Maintenance updates
|
||||
## 2024-02-17 - 1.0.1 to 1.0.3 - General Updates
|
||||
Maintenance updates
|
||||
|
||||
- Fix(core): update
|
||||
- Fix(core): update
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Task Venture Capital GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+16
-16
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@serve.zone/platformclient",
|
||||
"version": "1.0.10",
|
||||
"version": "1.1.4",
|
||||
"private": false,
|
||||
"description": "a module that makes it really easy to use the serve.zone platform inside your app",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -14,21 +14,20 @@
|
||||
"localPublish": "gitzone commit && pnpm run build && pnpm publish && pnpm publish --access public --registry=\"https://registry.npmjs.org\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.84",
|
||||
"@git.zone/tsbundle": "^2.0.5",
|
||||
"@git.zone/tsrun": "^1.2.49",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.3.0",
|
||||
"@types/node": "^22.7.4"
|
||||
"@git.zone/tsbuild": "^4.4.0",
|
||||
"@git.zone/tsbundle": "^2.10.0",
|
||||
"@git.zone/tsrun": "^2.0.2",
|
||||
"@git.zone/tstest": "^3.6.3",
|
||||
"@types/node": "^25.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest": "^3.0.32",
|
||||
"@api.global/typedserver": "^3.0.51",
|
||||
"@api.global/typedsocket": "^3.0.1",
|
||||
"@push.rocks/qenv": "^6.0.5",
|
||||
"@push.rocks/smartlog": "^3.0.7",
|
||||
"@push.rocks/smartntml": "^2.0.4",
|
||||
"@serve.zone/interfaces": "^1.0.81"
|
||||
"@api.global/typedrequest": "^3.3.0",
|
||||
"@api.global/typedserver": "^8.4.6",
|
||||
"@api.global/typedsocket": "^4.1.2",
|
||||
"@push.rocks/qenv": "^6.1.3",
|
||||
"@push.rocks/smartlog": "^3.2.2",
|
||||
"@push.rocks/smartntml": "^2.0.8",
|
||||
"@serve.zone/interfaces": "^5.4.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -50,7 +49,8 @@
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
".smartconfig.json",
|
||||
"readme.md"
|
||||
]
|
||||
],
|
||||
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
|
||||
}
|
||||
|
||||
Generated
+6053
-3471
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,205 @@
|
||||
# @serve.zone/platformclient
|
||||
a module that makes it really easy to use the serve.zone platform inside your app
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@serve.zone/platformclient)
|
||||
* [gitlab.com (source)](https://gitlab.com/serve.zone/platformclient)
|
||||
* [github.com (source mirror)](https://github.com/serve.zone/platformclient)
|
||||
* [docs (typedoc)](https://serve.zone.gitlab.io/platformclient/)
|
||||
`@serve.zone/platformclient` is the TypeScript SDK for talking to serve.zone platform services from application code. It wraps the serve.zone TypedSocket API and exposes focused connectors for transactional email, SMS, push notifications, and physical letters.
|
||||
|
||||
## Status for master
|
||||
Use it when your app should trigger serve.zone communication workflows without manually wiring TypedRequest methods or transport setup.
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
## Issue Reporting and Security
|
||||
|
||||
## Usage
|
||||
Use TypeScript for best in class intellisense
|
||||
For further information read the linked docs at the top of this readme.
|
||||
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pnpm add @serve.zone/platformclient
|
||||
```
|
||||
|
||||
## What It Does
|
||||
|
||||
`SzPlatformClient` handles the shared serve.zone platform connection and gives you these connectors:
|
||||
|
||||
| Connector | Purpose | TypedRequest method |
|
||||
| --- | --- | --- |
|
||||
| `emailConnector` | Send transactional email | `sendEmail` |
|
||||
| `smsConnector` | Send SMS messages and verification codes | `sendSms`, `sendVerificationCode` |
|
||||
| `pushNotificationConnector` | Send push notifications | `sendPushNotification` |
|
||||
| `letterConnector` | Send physical letters through the platform | `sendLetter` |
|
||||
|
||||
Requests use the types from `@serve.zone/interfaces`, so payloads stay aligned with the serve.zone backend contracts.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```typescript
|
||||
import { SzPlatformClient } from '@serve.zone/platformclient';
|
||||
|
||||
const platformClient = new SzPlatformClient(process.env.SERVEZONE_PLATFORM_AUTHORIZATION);
|
||||
await platformClient.init();
|
||||
|
||||
await platformClient.emailConnector.sendEmail({
|
||||
to: 'user@example.com',
|
||||
from: 'hello@serve.zone',
|
||||
title: 'Welcome to the platform',
|
||||
body: 'Your workspace is ready.',
|
||||
});
|
||||
```
|
||||
|
||||
The client connects to the platform endpoint configured through `SERVEZONE_PLATFORM_URL` or a runtime platform binding.
|
||||
|
||||
## Configuration
|
||||
|
||||
The client needs two values:
|
||||
|
||||
| Value | How to provide it | Notes |
|
||||
| --- | --- | --- |
|
||||
| Authorization token | Constructor argument, `init()` argument, `SERVEZONE_PLATFORM_AUTHORIZATION`, `SERVEZONE_PLATFORM_TOKEN`, or binding credential env | Loaded on demand through `@push.rocks/qenv`. |
|
||||
| Platform URL | Constructor options, `SERVEZONE_PLATFORM_URL`, or binding endpoint | Loaded on demand through `@push.rocks/qenv`. |
|
||||
| Runtime bindings | Constructor options, `SERVEZONE_PLATFORM_BINDING`, or `SERVEZONE_PLATFORM_BINDINGS` | Values are JSON-encoded `IPlatformBinding` objects from `@serve.zone/interfaces`. |
|
||||
|
||||
```typescript
|
||||
const client = new SzPlatformClient();
|
||||
await client.init('your-platform-authorization-token');
|
||||
```
|
||||
|
||||
Constructor and `init()` also accept options:
|
||||
|
||||
```typescript
|
||||
const client = new SzPlatformClient({
|
||||
token: process.env.SERVEZONE_PLATFORM_TOKEN,
|
||||
platformUrl: process.env.SERVEZONE_PLATFORM_URL,
|
||||
});
|
||||
await client.init();
|
||||
```
|
||||
|
||||
## Debug Mode
|
||||
|
||||
Pass `test` as the authorization string to enable debug mode. In debug mode, the client does not open a TypedSocket connection and connector methods log or return deterministic test values instead of sending real platform requests.
|
||||
|
||||
```typescript
|
||||
const client = new SzPlatformClient('test');
|
||||
await client.init();
|
||||
|
||||
await client.emailConnector.sendEmail({
|
||||
to: 'developer@example.com',
|
||||
from: 'hello@serve.zone',
|
||||
title: 'Preview only',
|
||||
body: 'This message is logged, not sent.',
|
||||
});
|
||||
|
||||
const verificationCode = await client.smsConnector.sendSmsVerifcation({
|
||||
toNumber: 491234567890,
|
||||
fromName: 'ServeZone',
|
||||
});
|
||||
// verificationCode === '123456'
|
||||
```
|
||||
|
||||
## Connector Examples
|
||||
|
||||
### Email
|
||||
|
||||
```typescript
|
||||
await client.emailConnector.sendEmail({
|
||||
to: 'user@example.com',
|
||||
from: 'hello@serve.zone',
|
||||
title: 'Invoice ready',
|
||||
body: 'Your invoice is available in the dashboard.',
|
||||
});
|
||||
```
|
||||
|
||||
### SMS
|
||||
|
||||
```typescript
|
||||
const status = await client.smsConnector.sendSms({
|
||||
toNumber: 491234567890,
|
||||
fromName: 'ServeZone',
|
||||
messageText: 'Your code is 123456.',
|
||||
});
|
||||
```
|
||||
|
||||
### SMS Verification
|
||||
|
||||
```typescript
|
||||
const code = await client.smsConnector.sendSmsVerifcation({
|
||||
toNumber: 491234567890,
|
||||
fromName: 'ServeZone',
|
||||
});
|
||||
```
|
||||
|
||||
### Push Notifications
|
||||
|
||||
```typescript
|
||||
const status = await client.pushNotificationConnector.sendPushNotification({
|
||||
deviceToken: 'device-token-from-your-app',
|
||||
message: 'Deployment complete: your service is live.',
|
||||
});
|
||||
```
|
||||
|
||||
### Letters
|
||||
|
||||
```typescript
|
||||
await client.letterConnector.sendLetter({
|
||||
description: 'Important account information',
|
||||
needsCover: true,
|
||||
title: 'Account update',
|
||||
coverBody: 'This letter was generated through serve.zone.',
|
||||
service: ['Einschreiben'],
|
||||
});
|
||||
```
|
||||
|
||||
Exact request fields are defined by `@serve.zone/interfaces` and may evolve with the platform API.
|
||||
|
||||
## InfoHtml Helper
|
||||
|
||||
The repository also contains an `InfoHtml` helper in `ts_infohtml/` for rendering simple branded informational HTML pages from text or option objects.
|
||||
|
||||
```typescript
|
||||
import { InfoHtml } from './ts_infohtml/index.js';
|
||||
|
||||
const infoPage = await InfoHtml.fromOptions({
|
||||
title: 'Service unavailable',
|
||||
heading: 'Maintenance in progress',
|
||||
text: 'Please try again in a few minutes.',
|
||||
redirectTo: 'https://serve.zone',
|
||||
});
|
||||
|
||||
console.log(infoPage.htmlString);
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
pnpm test
|
||||
pnpm run build
|
||||
```
|
||||
|
||||
The package is authored in TypeScript and builds the source folders through `tsbuild tsfolders --web --allowimplicitany`.
|
||||
|
||||
## Links
|
||||
|
||||
| Resource | URL |
|
||||
| --- | --- |
|
||||
| npm package | <https://www.npmjs.com/package/@serve.zone/platformclient> |
|
||||
| Source | <https://gitlab.com/serve.zone/platformclient> |
|
||||
| Source mirror | <https://github.com/serve.zone/platformclient> |
|
||||
| Typedoc | <https://serve.zone.gitlab.io/platformclient/> |
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license) file.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||
|
||||
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import { tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as platformclient from '../ts/index.js';
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(platformclient);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@serve.zone/platformclient',
|
||||
version: '1.0.10',
|
||||
version: '1.1.4',
|
||||
description: 'a module that makes it really easy to use the serve.zone platform inside your app'
|
||||
}
|
||||
|
||||
+216
-11
@@ -1,29 +1,234 @@
|
||||
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 interface ISzPlatformClientOptions {
|
||||
authorizationString?: string;
|
||||
authorization?: string;
|
||||
token?: string;
|
||||
url?: string;
|
||||
platformUrl?: string;
|
||||
binding?: plugins.servezoneInterfaces.platform.IPlatformBinding;
|
||||
bindings?: plugins.servezoneInterfaces.platform.IPlatformBinding[];
|
||||
}
|
||||
|
||||
export class SzPlatformClient {
|
||||
private authorizationString: string;
|
||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||
public typedsocket: plugins.typedsocket.TypedSocket;
|
||||
public debugMode = false;
|
||||
private authorizationString?: string;
|
||||
private connectionAddress?: string;
|
||||
public platformBindings: plugins.servezoneInterfaces.platform.IPlatformBinding[] = [];
|
||||
public typedrouter: plugins.typedrequest.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);
|
||||
public pushNotificationConnector = new SzPushNotificationConnector(this);
|
||||
public letterConnector = new SzLetterConnector(this);
|
||||
|
||||
constructor(authorizationStringArg?: string) {
|
||||
this.authorizationString = authorizationStringArg;
|
||||
constructor(authorizationStringArg?: string | ISzPlatformClientOptions) {
|
||||
this.applyOptions(authorizationStringArg);
|
||||
}
|
||||
|
||||
public async init(authorizationStringArg?: string) {
|
||||
if (authorizationStringArg) this.authorizationString = authorizationStringArg;
|
||||
if (!this.authorizationString) this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION;
|
||||
public async init(authorizationStringArg?: string | ISzPlatformClientOptions) {
|
||||
this.applyOptions(authorizationStringArg);
|
||||
if (!this.authorizationString) {
|
||||
this.authorizationString = await this.getConfiguredAuthorizationString();
|
||||
}
|
||||
if (this.authorizationString === 'test') {
|
||||
this.activateDebugMode();
|
||||
return;
|
||||
}
|
||||
|
||||
this.platformBindings = this.mergePlatformBindings(
|
||||
this.platformBindings,
|
||||
await this.discoverPlatformBindings()
|
||||
);
|
||||
if (!this.authorizationString) {
|
||||
this.authorizationString = this.getAuthorizationStringFromBindings();
|
||||
}
|
||||
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.activateDebugMode();
|
||||
return;
|
||||
}
|
||||
this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(
|
||||
this.typedrouter as any,
|
||||
await this.getConnectionAddress()
|
||||
);
|
||||
await this.setAuthorizationTag();
|
||||
}
|
||||
|
||||
private activateDebugMode() {
|
||||
this.debugMode = true;
|
||||
console.log('debug mode activated.');
|
||||
}
|
||||
|
||||
public getPlatformBinding(
|
||||
capabilityArg?: plugins.servezoneInterfaces.platform.TPlatformCapability
|
||||
) {
|
||||
return this.platformBindings.find((bindingArg) => {
|
||||
return (
|
||||
bindingArg.desiredState !== 'disabled' &&
|
||||
bindingArg.status !== 'failed' &&
|
||||
(!capabilityArg || bindingArg.capability === capabilityArg)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private applyOptions(optionsArg?: string | ISzPlatformClientOptions) {
|
||||
if (!optionsArg) {
|
||||
return;
|
||||
}
|
||||
if (typeof optionsArg === 'string') {
|
||||
this.authorizationString = optionsArg;
|
||||
return;
|
||||
}
|
||||
|
||||
this.authorizationString =
|
||||
optionsArg.authorizationString ||
|
||||
optionsArg.authorization ||
|
||||
optionsArg.token ||
|
||||
this.authorizationString;
|
||||
this.connectionAddress = optionsArg.url || optionsArg.platformUrl || this.connectionAddress;
|
||||
this.platformBindings = this.mergePlatformBindings(
|
||||
this.platformBindings,
|
||||
[optionsArg.binding, ...(optionsArg.bindings || [])].filter(
|
||||
Boolean
|
||||
) as plugins.servezoneInterfaces.platform.IPlatformBinding[]
|
||||
);
|
||||
}
|
||||
|
||||
private async getConnectionAddress() {
|
||||
const connectionAddress = await this.qenvInstance.getEnvVarOnDemand('SERVEZONE_API_DOMAIN');
|
||||
const connectionAddress =
|
||||
this.connectionAddress ||
|
||||
(await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_URL')) ||
|
||||
this.getConnectionAddressFromBindings();
|
||||
if (!connectionAddress) throw new Error('SERVEZONE_PLATFORM_URL or platform binding endpoint is required');
|
||||
return connectionAddress;
|
||||
}
|
||||
}
|
||||
|
||||
private getConnectionAddressFromBindings() {
|
||||
for (const binding of this.platformBindings) {
|
||||
if (binding.desiredState === 'disabled' || binding.status === 'failed') {
|
||||
continue;
|
||||
}
|
||||
if (!this.isSupportedConnectorCapability(binding.capability)) {
|
||||
continue;
|
||||
}
|
||||
const endpoint = binding.endpoints?.find((endpointArg) => {
|
||||
return endpointArg.protocol === 'typedrequest' || endpointArg.protocol === 'http';
|
||||
});
|
||||
const endpointUrl = endpoint?.internalUrl || endpoint?.externalUrl;
|
||||
if (endpointUrl) {
|
||||
return endpointUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private isSupportedConnectorCapability(
|
||||
capabilityArg: plugins.servezoneInterfaces.platform.TPlatformCapability
|
||||
) {
|
||||
return ['email', 'sms', 'pushnotification', 'letter'].includes(capabilityArg);
|
||||
}
|
||||
|
||||
private async getConfiguredAuthorizationString() {
|
||||
return (
|
||||
(await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_AUTHORIZATION')) ||
|
||||
(await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_TOKEN'))
|
||||
);
|
||||
}
|
||||
|
||||
private getAuthorizationStringFromBindings() {
|
||||
const authEnvNames = [
|
||||
'SERVEZONE_PLATFORM_AUTHORIZATION',
|
||||
'SERVEZONE_PLATFORM_TOKEN',
|
||||
'SERVEZONE_API_TOKEN',
|
||||
'AUTHORIZATION',
|
||||
'TOKEN',
|
||||
];
|
||||
for (const binding of this.platformBindings) {
|
||||
for (const credential of binding.credentials || []) {
|
||||
for (const envName of authEnvNames) {
|
||||
const value = credential.env?.[envName];
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async setAuthorizationTag() {
|
||||
if (!this.authorizationString) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.typedsocket.setTag('authorization' as any, this.authorizationString);
|
||||
} catch (error) {
|
||||
if (await this.getConfiguredEnvVar('SERVEZONE_PLATFORMCLIENT_DEBUG')) {
|
||||
console.warn('Could not set platform authorization tag:', (error as Error).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async discoverPlatformBindings() {
|
||||
const bindings: plugins.servezoneInterfaces.platform.IPlatformBinding[] = [];
|
||||
const envBindings = await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_BINDINGS');
|
||||
const envBinding = await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_BINDING');
|
||||
|
||||
if (envBindings) {
|
||||
bindings.push(...this.parsePlatformBindingsEnv('SERVEZONE_PLATFORM_BINDINGS', envBindings));
|
||||
}
|
||||
if (envBinding) {
|
||||
bindings.push(...this.parsePlatformBindingsEnv('SERVEZONE_PLATFORM_BINDING', envBinding));
|
||||
}
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
private parsePlatformBindingsEnv(envNameArg: string, envValueArg: string) {
|
||||
let parsedValue: unknown;
|
||||
try {
|
||||
parsedValue = JSON.parse(envValueArg);
|
||||
} catch (error) {
|
||||
throw new Error(`${envNameArg} must contain valid JSON`);
|
||||
}
|
||||
|
||||
if (Array.isArray(parsedValue)) {
|
||||
return parsedValue as plugins.servezoneInterfaces.platform.IPlatformBinding[];
|
||||
}
|
||||
if (parsedValue && typeof parsedValue === 'object') {
|
||||
return [parsedValue as plugins.servezoneInterfaces.platform.IPlatformBinding];
|
||||
}
|
||||
throw new Error(`${envNameArg} must contain a platform binding object or array`);
|
||||
}
|
||||
|
||||
private mergePlatformBindings(
|
||||
existingBindingsArg: plugins.servezoneInterfaces.platform.IPlatformBinding[],
|
||||
newBindingsArg: plugins.servezoneInterfaces.platform.IPlatformBinding[]
|
||||
) {
|
||||
const bindingMap = new Map<string, plugins.servezoneInterfaces.platform.IPlatformBinding>();
|
||||
for (const binding of [...existingBindingsArg, ...newBindingsArg]) {
|
||||
bindingMap.set(binding.id, binding);
|
||||
}
|
||||
return Array.from(bindingMap.values());
|
||||
}
|
||||
|
||||
private async getConfiguredEnvVar(envNameArg: string) {
|
||||
const processValue = this.getProcessEnvVar(envNameArg);
|
||||
if (processValue) {
|
||||
return processValue;
|
||||
}
|
||||
return this.qenvInstance.getEnvVarOnDemand(envNameArg);
|
||||
}
|
||||
|
||||
private getProcessEnvVar(envNameArg: string) {
|
||||
const processEnv = (globalThis as typeof globalThis & {
|
||||
process?: { env?: Record<string, string | undefined> };
|
||||
}).process?.env;
|
||||
return processEnv?.[envNameArg];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,15 +11,9 @@ export class SzEmailConnector {
|
||||
}
|
||||
|
||||
public async sendEmail(
|
||||
optionsArg: plugins.servezoneInterfaces.platformservice.mta.IRequest_SendEmail['request']
|
||||
optionsArg: plugins.servezoneInterfaces.platform.email.IReq_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.platform.email.IReq_SendEmail>(
|
||||
'sendEmail'
|
||||
);
|
||||
const response = await typedRequest.fire(optionsArg);
|
||||
|
||||
}
|
||||
|
||||
public async sendNotification(optionsArg: { toArg: string; subject: string; text: string }) {}
|
||||
|
||||
@@ -9,12 +9,21 @@ export class SzLetterConnector {
|
||||
}
|
||||
|
||||
public async sendLetter(
|
||||
optionsArg: plugins.servezoneInterfaces.platformservice.letter.IRequest_SendLetter['request']
|
||||
optionsArg: plugins.servezoneInterfaces.platform.letter.IReq_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>(
|
||||
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.letter.IReq_SendLetter>(
|
||||
'sendLetter'
|
||||
);
|
||||
const response = await typedRequest.fire(optionsArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.platform.pushnotification.IReq_SendPushNotification['request']
|
||||
) {
|
||||
if (this.platformClientRef.debugMode) {
|
||||
console.log('sendPushNotification', optionsArg);
|
||||
}
|
||||
|
||||
if (this.platformClientRef.debugMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
const typedRequest =
|
||||
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.pushnotification.IReq_SendPushNotification>(
|
||||
'sendPushNotification'
|
||||
);
|
||||
const response = await typedRequest.fire(optionsArg);
|
||||
|
||||
if (process.env.SERVEZONE_PLATFORMCLIENT_DEBUG) {
|
||||
console.log('sendPushNotification response', response);
|
||||
}
|
||||
|
||||
return response.status;
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,8 @@ export class SzSmsConnector {
|
||||
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);
|
||||
|
||||
if (process.env.SERVEZONE_PLATFORMCLIENT_DEBUG) {
|
||||
public async sendSms(messageArg: plugins.servezoneInterfaces.platform.sms.IReq_SendSms['request']) {
|
||||
if (this.platformClientRef.debugMode) {
|
||||
logger.log('info', `sent sms to ${messageArg.toNumber}}
|
||||
body:
|
||||
${messageArg.messageText.split('\n').map(line => ` ${line}`).join('\n')}
|
||||
@@ -23,15 +18,29 @@ export class SzSmsConnector {
|
||||
`);
|
||||
}
|
||||
|
||||
if (this.platformClientRef.debugMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
const typedrequest = this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.sms.IReq_SendSms>(
|
||||
'sendSms'
|
||||
);
|
||||
const response = await typedrequest.fire(messageArg);
|
||||
|
||||
return response.status;
|
||||
}
|
||||
|
||||
public async sendSmsVerifcation(
|
||||
recipientArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode['request']
|
||||
recipientArg: plugins.servezoneInterfaces.platform.sms.IReq_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>(
|
||||
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.sms.IReq_SendVerificationCode>(
|
||||
'sendVerificationCode'
|
||||
);
|
||||
const response = await typedrequest.fire(recipientArg);
|
||||
|
||||
@@ -16,7 +16,6 @@ export class InfoHtml {
|
||||
public static async fromSimpleText(textArg: string) {
|
||||
const infohtmlInstance = new InfoHtml({
|
||||
text: textArg,
|
||||
heading: null,
|
||||
});
|
||||
await infohtmlInstance.init();
|
||||
return infohtmlInstance;
|
||||
@@ -30,8 +29,8 @@ export class InfoHtml {
|
||||
|
||||
// INSTANCE
|
||||
public options: IHtmlInfoOptions;
|
||||
public smartntmlInstance: plugins.smartntml.Smartntml;
|
||||
public htmlString: string;
|
||||
public smartntmlInstance?: plugins.smartntml.Smartntml;
|
||||
public htmlString = '';
|
||||
constructor(optionsArg: IHtmlInfoOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as smartntml from '@push.rocks/smartntml';
|
||||
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user