# @serve.zone/platformclient `@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. ## Install ```bash pnpm add @serve.zone/platformclient ``` ## Quick Start ```typescript import { SzPlatformClient } from '@serve.zone/platformclient'; 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', from: 'hello@example.com', title: 'Workspace ready', body: 'Your serve.zone workspace is ready.', }); ``` ## 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 The client needs an authorization string and a platform endpoint. You can provide both directly, through environment variables, or through platform bindings. | 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 import { SzPlatformClient } from '@serve.zone/platformclient'; const client = new SzPlatformClient(process.env.SERVEZONE_PLATFORM_AUTHORIZATION); await client.init(); ``` ```typescript import { SzPlatformClient } from '@serve.zone/platformclient'; const client = new SzPlatformClient({ authorization: process.env.SERVEZONE_PLATFORM_AUTHORIZATION, url: process.env.SERVEZONE_PLATFORM_URL, }); await client.init(); ``` ## Debug Mode 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', from: 'hello@example.com', title: 'Preview only', body: 'This message is logged, not sent.', }); const verificationCode = await client.smsConnector.sendSmsVerifcation({ toNumber: 491234567890, fromName: 'ServeZone', }); console.log(verificationCode); // 123456 ``` The current SMS verification method is spelled `sendSmsVerifcation()` in code. Use that exact method name until the public API changes. ## Connector Examples Email: ```typescript await client.emailConnector.sendEmail({ to: 'user@example.com', from: 'hello@example.com', 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.', }); ``` Push notification: ```typescript const status = await client.pushNotificationConnector.sendPushNotification({ deviceToken: 'device-token-from-your-app', message: 'Deployment complete: your service is live.', }); ``` 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'], }); ``` Exact fields are defined in `@serve.zone/interfaces` under `platform.email`, `platform.sms`, `platform.pushnotification`, and `platform.letter`. ## Platform Bindings Platform bindings allow a workload to discover endpoint URLs and credentials from its runtime environment. ```typescript import { SzPlatformClient } from '@serve.zone/platformclient'; import { platform } from '@serve.zone/interfaces'; const binding: platform.IPlatformBinding = JSON.parse( process.env.SERVEZONE_PLATFORM_BINDING! ); const client = new SzPlatformClient({ binding }); await client.init(); const emailBinding = client.getPlatformBinding('email'); ``` 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 ``` 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 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.