Files
platformclient/readme.md
T

203 lines
7.3 KiB
Markdown
Raw Normal View History

2024-02-17 20:24:28 +01:00
# @serve.zone/platformclient
2026-05-07 20:22:12 +00:00
`@serve.zone/platformclient` is the application SDK for serve.zone platform services. It opens a TypedSocket connection to a platform endpoint and gives application code focused connectors for transactional email, SMS, push notifications, and physical letters without hand-writing TypedRequest setup.
## Issue Reporting and Security
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.
2026-05-07 20:22:12 +00:00
## Install
```bash
pnpm add @serve.zone/platformclient
```
## Quick Start
```typescript
import { SzPlatformClient } from '@serve.zone/platformclient';
2026-05-07 20:22:12 +00:00
const platformClient = new SzPlatformClient({
token: process.env.SERVEZONE_PLATFORM_TOKEN,
platformUrl: process.env.SERVEZONE_PLATFORM_URL,
});
await platformClient.init();
await platformClient.emailConnector.sendEmail({
to: 'user@example.com',
2026-05-07 20:22:12 +00:00
from: 'hello@example.com',
title: 'Workspace ready',
body: 'Your serve.zone workspace is ready.',
});
```
2026-05-07 20:22:12 +00:00
## Connectors
`SzPlatformClient` owns the shared connection and exposes connector instances:
| Connector | Main methods | Platform capability |
| --- | --- | --- |
| `emailConnector` | `sendEmail()` | `email` |
| `smsConnector` | `sendSms()`, `sendSmsVerifcation()` | `sms` |
| `pushNotificationConnector` | `sendPushNotification()` | `pushnotification` |
| `letterConnector` | `sendLetter()` | `letter` |
The request and response payloads come from `@serve.zone/interfaces`, so TypeScript stays aligned with the serve.zone platform contracts.
## Configuration
2026-05-07 20:22:12 +00:00
The client needs an authorization string and a platform endpoint. You can provide both directly, through environment variables, or through platform bindings.
2026-05-07 20:22:12 +00:00
| Value | Sources |
| --- | --- |
| Authorization | Constructor string, `authorizationString`, `authorization`, `token`, `init()` argument, `SERVEZONE_PLATFORM_AUTHORIZATION`, `SERVEZONE_PLATFORM_TOKEN`, or binding credentials. |
| Platform URL | `url`, `platformUrl`, `SERVEZONE_PLATFORM_URL`, or the first active binding endpoint using `typedrequest` or `http`. |
| Platform bindings | Constructor `binding` or `bindings`, `SERVEZONE_PLATFORM_BINDING`, or `SERVEZONE_PLATFORM_BINDINGS`. |
Binding environment variables must contain JSON encoded `IPlatformBinding` objects from `@serve.zone/interfaces`.
```typescript
2026-05-07 20:22:12 +00:00
import { SzPlatformClient } from '@serve.zone/platformclient';
2026-05-07 20:22:12 +00:00
const client = new SzPlatformClient(process.env.SERVEZONE_PLATFORM_AUTHORIZATION);
await client.init();
```
2026-04-28 12:30:38 +00:00
```typescript
2026-05-07 20:22:12 +00:00
import { SzPlatformClient } from '@serve.zone/platformclient';
2026-04-28 12:30:38 +00:00
const client = new SzPlatformClient({
2026-05-07 20:22:12 +00:00
authorization: process.env.SERVEZONE_PLATFORM_AUTHORIZATION,
url: process.env.SERVEZONE_PLATFORM_URL,
2026-04-28 12:30:38 +00:00
});
2026-05-07 20:22:12 +00:00
2026-04-28 12:30:38 +00:00
await client.init();
```
## Debug Mode
2026-05-07 20:22:12 +00:00
Pass `test` as the authorization string to activate debug mode. In debug mode, the client does not open a TypedSocket connection. 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',
2026-05-07 20:22:12 +00:00
from: 'hello@example.com',
title: 'Preview only',
body: 'This message is logged, not sent.',
});
const verificationCode = await client.smsConnector.sendSmsVerifcation({
toNumber: 491234567890,
fromName: 'ServeZone',
});
2026-05-07 20:22:12 +00:00
console.log(verificationCode); // 123456
```
2026-05-07 20:22:12 +00:00
The current SMS verification method is spelled `sendSmsVerifcation()` in code. Use that exact method name until the public API changes.
## Connector Examples
2026-05-07 20:22:12 +00:00
Email:
```typescript
await client.emailConnector.sendEmail({
to: 'user@example.com',
2026-05-07 20:22:12 +00:00
from: 'hello@example.com',
title: 'Invoice ready',
body: 'Your invoice is available in the dashboard.',
});
```
2026-05-07 20:22:12 +00:00
SMS:
```typescript
const status = await client.smsConnector.sendSms({
toNumber: 491234567890,
fromName: 'ServeZone',
messageText: 'Your code is 123456.',
});
```
2026-05-07 20:22:12 +00:00
Push notification:
```typescript
const status = await client.pushNotificationConnector.sendPushNotification({
deviceToken: 'device-token-from-your-app',
message: 'Deployment complete: your service is live.',
});
```
2026-05-07 20:22:12 +00:00
Letter:
```typescript
await client.letterConnector.sendLetter({
description: 'Important account information',
needsCover: true,
title: 'Account update',
coverBody: 'This letter was generated through serve.zone.',
service: ['Einschreiben'],
});
```
2026-05-07 20:22:12 +00:00
Exact fields are defined in `@serve.zone/interfaces` under `platform.email`, `platform.sms`, `platform.pushnotification`, and `platform.letter`.
2026-05-07 20:22:12 +00:00
## Platform Bindings
2026-05-07 20:22:12 +00:00
Platform bindings allow a workload to discover endpoint URLs and credentials from its runtime environment.
```typescript
2026-05-07 20:22:12 +00:00
import { SzPlatformClient } from '@serve.zone/platformclient';
import { platform } from '@serve.zone/interfaces';
2026-05-07 20:22:12 +00:00
const binding: platform.IPlatformBinding = JSON.parse(
process.env.SERVEZONE_PLATFORM_BINDING!
);
const client = new SzPlatformClient({ binding });
await client.init();
2026-05-07 20:22:12 +00:00
const emailBinding = client.getPlatformBinding('email');
```
2026-05-07 20:22:12 +00:00
Bindings with `desiredState: 'disabled'` or `status: 'failed'` are ignored when the client auto-selects an endpoint.
## InfoHtml Helper
The repository also contains a small `ts_infohtml` source folder for rendering simple informational HTML pages from text or options. It is not exported from the package root, so treat it as a source-level helper rather than the main SDK API.
## Development
```bash
pnpm install
pnpm test
pnpm run build
```
2026-05-07 20:22:12 +00:00
The package is authored as ESM TypeScript and builds source folders with `tsbuild tsfolders --web --allowimplicitany`.
## 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
2026-05-07 20:22:12 +00:00
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.