@serve.zone/platformclient 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{npmextra.json → .smartconfig.json} +10 -3
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.platformclient.d.ts +27 -3
- package/dist_ts/classes.platformclient.js +150 -9
- package/dist_ts/email/classes.emailconnector.d.ts +1 -1
- package/dist_ts/email/classes.emailconnector.js +1 -1
- package/dist_ts/email/classes.letterconnector.d.ts +1 -1
- package/dist_ts/email/classes.letterconnector.js +1 -1
- package/dist_ts/email/classes.pushnotificationconnector.d.ts +1 -1
- package/dist_ts/email/classes.pushnotificationconnector.js +1 -1
- package/dist_ts/email/classes.smsconnector.d.ts +2 -2
- package/dist_ts/email/classes.smsconnector.js +1 -1
- package/dist_ts_infohtml/classes.infohtml.d.ts +1 -1
- package/dist_ts_infohtml/classes.infohtml.js +2 -2
- package/dist_ts_infohtml/plugins.js +2 -1
- package/license +21 -0
- package/package.json +14 -15
- package/readme.md +204 -30
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.platformclient.ts +203 -14
- package/ts/email/classes.emailconnector.ts +2 -2
- package/ts/email/classes.letterconnector.ts +3 -3
- package/ts/email/classes.pushnotificationconnector.ts +3 -3
- package/ts/email/classes.smsconnector.ts +4 -4
- package/dist_ts/classes.serviceserver.d.ts +0 -18
- package/dist_ts/classes.serviceserver.js +0 -32
- package/dist_ts/infohtml/classes.infohtml.d.ts +0 -18
- package/dist_ts/infohtml/classes.infohtml.js +0 -27
- package/dist_ts/infohtml/index.d.ts +0 -1
- package/dist_ts/infohtml/index.js +0 -2
- package/dist_ts/infohtml/template.d.ts +0 -3
- package/dist_ts/infohtml/template.js +0 -156
- package/readme.hints.md +0 -0
package/readme.md
CHANGED
|
@@ -1,31 +1,205 @@
|
|
|
1
1
|
# @serve.zone/platformclient
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
|
|
3
|
+
`@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.
|
|
4
|
+
|
|
5
|
+
Use it when your app should trigger serve.zone communication workflows without manually wiring TypedRequest methods or transport setup.
|
|
6
|
+
|
|
7
|
+
## Issue Reporting and Security
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @serve.zone/platformclient
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## What It Does
|
|
18
|
+
|
|
19
|
+
`SzPlatformClient` handles the shared serve.zone platform connection and gives you these connectors:
|
|
20
|
+
|
|
21
|
+
| Connector | Purpose | TypedRequest method |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| `emailConnector` | Send transactional email | `sendEmail` |
|
|
24
|
+
| `smsConnector` | Send SMS messages and verification codes | `sendSms`, `sendVerificationCode` |
|
|
25
|
+
| `pushNotificationConnector` | Send push notifications | `sendPushNotification` |
|
|
26
|
+
| `letterConnector` | Send physical letters through the platform | `sendLetter` |
|
|
27
|
+
|
|
28
|
+
Requests use the types from `@serve.zone/interfaces`, so payloads stay aligned with the serve.zone backend contracts.
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { SzPlatformClient } from '@serve.zone/platformclient';
|
|
34
|
+
|
|
35
|
+
const platformClient = new SzPlatformClient(process.env.SERVEZONE_PLATFORM_AUTHORIZATION);
|
|
36
|
+
await platformClient.init();
|
|
37
|
+
|
|
38
|
+
await platformClient.emailConnector.sendEmail({
|
|
39
|
+
to: 'user@example.com',
|
|
40
|
+
from: 'hello@serve.zone',
|
|
41
|
+
title: 'Welcome to the platform',
|
|
42
|
+
body: 'Your workspace is ready.',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The client connects to the platform endpoint configured through `SERVEZONE_PLATFORM_URL` or a runtime platform binding.
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
The client needs two values:
|
|
51
|
+
|
|
52
|
+
| Value | How to provide it | Notes |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| Authorization token | Constructor argument, `init()` argument, `SERVEZONE_PLATFORM_AUTHORIZATION`, `SERVEZONE_PLATFORM_TOKEN`, or binding credential env | Loaded on demand through `@push.rocks/qenv`. |
|
|
55
|
+
| Platform URL | Constructor options, `SERVEZONE_PLATFORM_URL`, or binding endpoint | Loaded on demand through `@push.rocks/qenv`. |
|
|
56
|
+
| Runtime bindings | Constructor options, `SERVEZONE_PLATFORM_BINDING`, or `SERVEZONE_PLATFORM_BINDINGS` | Values are JSON-encoded `IPlatformBinding` objects from `@serve.zone/interfaces`. |
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const client = new SzPlatformClient();
|
|
60
|
+
await client.init('your-platform-authorization-token');
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Constructor and `init()` also accept options:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const client = new SzPlatformClient({
|
|
67
|
+
token: process.env.SERVEZONE_PLATFORM_TOKEN,
|
|
68
|
+
platformUrl: process.env.SERVEZONE_PLATFORM_URL,
|
|
69
|
+
});
|
|
70
|
+
await client.init();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Debug Mode
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const client = new SzPlatformClient('test');
|
|
79
|
+
await client.init();
|
|
80
|
+
|
|
81
|
+
await client.emailConnector.sendEmail({
|
|
82
|
+
to: 'developer@example.com',
|
|
83
|
+
from: 'hello@serve.zone',
|
|
84
|
+
title: 'Preview only',
|
|
85
|
+
body: 'This message is logged, not sent.',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const verificationCode = await client.smsConnector.sendSmsVerifcation({
|
|
89
|
+
toNumber: 491234567890,
|
|
90
|
+
fromName: 'ServeZone',
|
|
91
|
+
});
|
|
92
|
+
// verificationCode === '123456'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Connector Examples
|
|
96
|
+
|
|
97
|
+
### Email
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
await client.emailConnector.sendEmail({
|
|
101
|
+
to: 'user@example.com',
|
|
102
|
+
from: 'hello@serve.zone',
|
|
103
|
+
title: 'Invoice ready',
|
|
104
|
+
body: 'Your invoice is available in the dashboard.',
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### SMS
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const status = await client.smsConnector.sendSms({
|
|
112
|
+
toNumber: 491234567890,
|
|
113
|
+
fromName: 'ServeZone',
|
|
114
|
+
messageText: 'Your code is 123456.',
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### SMS Verification
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
const code = await client.smsConnector.sendSmsVerifcation({
|
|
122
|
+
toNumber: 491234567890,
|
|
123
|
+
fromName: 'ServeZone',
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Push Notifications
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const status = await client.pushNotificationConnector.sendPushNotification({
|
|
131
|
+
deviceToken: 'device-token-from-your-app',
|
|
132
|
+
message: 'Deployment complete: your service is live.',
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Letters
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
await client.letterConnector.sendLetter({
|
|
140
|
+
description: 'Important account information',
|
|
141
|
+
needsCover: true,
|
|
142
|
+
title: 'Account update',
|
|
143
|
+
coverBody: 'This letter was generated through serve.zone.',
|
|
144
|
+
service: ['Einschreiben'],
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Exact request fields are defined by `@serve.zone/interfaces` and may evolve with the platform API.
|
|
149
|
+
|
|
150
|
+
## InfoHtml Helper
|
|
151
|
+
|
|
152
|
+
The repository also contains an `InfoHtml` helper in `ts_infohtml/` for rendering simple branded informational HTML pages from text or option objects.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { InfoHtml } from './ts_infohtml/index.js';
|
|
156
|
+
|
|
157
|
+
const infoPage = await InfoHtml.fromOptions({
|
|
158
|
+
title: 'Service unavailable',
|
|
159
|
+
heading: 'Maintenance in progress',
|
|
160
|
+
text: 'Please try again in a few minutes.',
|
|
161
|
+
redirectTo: 'https://serve.zone',
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
console.log(infoPage.htmlString);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Development
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
pnpm install
|
|
171
|
+
pnpm test
|
|
172
|
+
pnpm run build
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The package is authored in TypeScript and builds the source folders through `tsbuild tsfolders --web --allowimplicitany`.
|
|
176
|
+
|
|
177
|
+
## Links
|
|
178
|
+
|
|
179
|
+
| Resource | URL |
|
|
180
|
+
| --- | --- |
|
|
181
|
+
| npm package | <https://www.npmjs.com/package/@serve.zone/platformclient> |
|
|
182
|
+
| Source | <https://gitlab.com/serve.zone/platformclient> |
|
|
183
|
+
| Source mirror | <https://github.com/serve.zone/platformclient> |
|
|
184
|
+
| Typedoc | <https://serve.zone.gitlab.io/platformclient/> |
|
|
185
|
+
|
|
186
|
+
## License and Legal Information
|
|
187
|
+
|
|
188
|
+
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license) file.
|
|
189
|
+
|
|
190
|
+
**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.
|
|
191
|
+
|
|
192
|
+
### Trademarks
|
|
193
|
+
|
|
194
|
+
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.
|
|
195
|
+
|
|
196
|
+
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.
|
|
197
|
+
|
|
198
|
+
### Company Information
|
|
199
|
+
|
|
200
|
+
Task Venture Capital GmbH
|
|
201
|
+
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
202
|
+
|
|
203
|
+
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
|
204
|
+
|
|
205
|
+
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.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -4,11 +4,23 @@ import { SzPushNotificationConnector } from './email/classes.pushnotificationcon
|
|
|
4
4
|
import { SzLetterConnector } from './email/classes.letterconnector.js';
|
|
5
5
|
import * as plugins from './plugins.js';
|
|
6
6
|
|
|
7
|
+
export interface ISzPlatformClientOptions {
|
|
8
|
+
authorizationString?: string;
|
|
9
|
+
authorization?: string;
|
|
10
|
+
token?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
platformUrl?: string;
|
|
13
|
+
binding?: plugins.servezoneInterfaces.platform.IPlatformBinding;
|
|
14
|
+
bindings?: plugins.servezoneInterfaces.platform.IPlatformBinding[];
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
export class SzPlatformClient {
|
|
8
18
|
public debugMode = false;
|
|
9
|
-
private authorizationString
|
|
10
|
-
|
|
11
|
-
public
|
|
19
|
+
private authorizationString?: string;
|
|
20
|
+
private connectionAddress?: string;
|
|
21
|
+
public platformBindings: plugins.servezoneInterfaces.platform.IPlatformBinding[] = [];
|
|
22
|
+
public typedrouter: plugins.typedrequest.TypedRouter = new plugins.typedrequest.TypedRouter();
|
|
23
|
+
public typedsocket!: plugins.typedsocket.TypedSocket;
|
|
12
24
|
private qenvInstance = new plugins.qenv.Qenv();
|
|
13
25
|
|
|
14
26
|
public emailConnector = new SzEmailConnector(this);
|
|
@@ -16,30 +28,207 @@ export class SzPlatformClient {
|
|
|
16
28
|
public pushNotificationConnector = new SzPushNotificationConnector(this);
|
|
17
29
|
public letterConnector = new SzLetterConnector(this);
|
|
18
30
|
|
|
19
|
-
constructor(authorizationStringArg?: string) {
|
|
20
|
-
this.
|
|
31
|
+
constructor(authorizationStringArg?: string | ISzPlatformClientOptions) {
|
|
32
|
+
this.applyOptions(authorizationStringArg);
|
|
21
33
|
}
|
|
22
34
|
|
|
23
|
-
public async init(authorizationStringArg?: string) {
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
public async init(authorizationStringArg?: string | ISzPlatformClientOptions) {
|
|
36
|
+
this.applyOptions(authorizationStringArg);
|
|
37
|
+
if (!this.authorizationString) {
|
|
38
|
+
this.authorizationString = await this.getConfiguredAuthorizationString();
|
|
39
|
+
}
|
|
40
|
+
if (this.authorizationString === 'test') {
|
|
41
|
+
this.activateDebugMode();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.platformBindings = this.mergePlatformBindings(
|
|
46
|
+
this.platformBindings,
|
|
47
|
+
await this.discoverPlatformBindings()
|
|
48
|
+
);
|
|
49
|
+
if (!this.authorizationString) {
|
|
50
|
+
this.authorizationString = this.getAuthorizationStringFromBindings();
|
|
26
51
|
}
|
|
27
|
-
if (!this.authorizationString)
|
|
28
|
-
this.authorizationString = process.env.SERVEZONE_PLATFROM_AUTHORIZATION;
|
|
29
52
|
if (!this.authorizationString) throw new Error('authorizationString is required');
|
|
30
53
|
if (this.authorizationString === 'test') {
|
|
31
|
-
this.
|
|
32
|
-
console.log('debug mode activated.');
|
|
54
|
+
this.activateDebugMode();
|
|
33
55
|
return;
|
|
34
56
|
}
|
|
35
57
|
this.typedsocket = await plugins.typedsocket.TypedSocket.createClient(
|
|
36
|
-
this.typedrouter,
|
|
58
|
+
this.typedrouter as any,
|
|
37
59
|
await this.getConnectionAddress()
|
|
38
60
|
);
|
|
61
|
+
await this.setAuthorizationTag();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private activateDebugMode() {
|
|
65
|
+
this.debugMode = true;
|
|
66
|
+
console.log('debug mode activated.');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public getPlatformBinding(
|
|
70
|
+
capabilityArg?: plugins.servezoneInterfaces.platform.TPlatformCapability
|
|
71
|
+
) {
|
|
72
|
+
return this.platformBindings.find((bindingArg) => {
|
|
73
|
+
return (
|
|
74
|
+
bindingArg.desiredState !== 'disabled' &&
|
|
75
|
+
bindingArg.status !== 'failed' &&
|
|
76
|
+
(!capabilityArg || bindingArg.capability === capabilityArg)
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private applyOptions(optionsArg?: string | ISzPlatformClientOptions) {
|
|
82
|
+
if (!optionsArg) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (typeof optionsArg === 'string') {
|
|
86
|
+
this.authorizationString = optionsArg;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.authorizationString =
|
|
91
|
+
optionsArg.authorizationString ||
|
|
92
|
+
optionsArg.authorization ||
|
|
93
|
+
optionsArg.token ||
|
|
94
|
+
this.authorizationString;
|
|
95
|
+
this.connectionAddress = optionsArg.url || optionsArg.platformUrl || this.connectionAddress;
|
|
96
|
+
this.platformBindings = this.mergePlatformBindings(
|
|
97
|
+
this.platformBindings,
|
|
98
|
+
[optionsArg.binding, ...(optionsArg.bindings || [])].filter(
|
|
99
|
+
Boolean
|
|
100
|
+
) as plugins.servezoneInterfaces.platform.IPlatformBinding[]
|
|
101
|
+
);
|
|
39
102
|
}
|
|
40
103
|
|
|
41
104
|
private async getConnectionAddress() {
|
|
42
|
-
const connectionAddress =
|
|
105
|
+
const connectionAddress =
|
|
106
|
+
this.connectionAddress ||
|
|
107
|
+
(await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_URL')) ||
|
|
108
|
+
this.getConnectionAddressFromBindings();
|
|
109
|
+
if (!connectionAddress) throw new Error('SERVEZONE_PLATFORM_URL or platform binding endpoint is required');
|
|
43
110
|
return connectionAddress;
|
|
44
111
|
}
|
|
112
|
+
|
|
113
|
+
private getConnectionAddressFromBindings() {
|
|
114
|
+
for (const binding of this.platformBindings) {
|
|
115
|
+
if (binding.desiredState === 'disabled' || binding.status === 'failed') {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!this.isSupportedConnectorCapability(binding.capability)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const endpoint = binding.endpoints?.find((endpointArg) => {
|
|
122
|
+
return endpointArg.protocol === 'typedrequest' || endpointArg.protocol === 'http';
|
|
123
|
+
});
|
|
124
|
+
const endpointUrl = endpoint?.internalUrl || endpoint?.externalUrl;
|
|
125
|
+
if (endpointUrl) {
|
|
126
|
+
return endpointUrl;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private isSupportedConnectorCapability(
|
|
132
|
+
capabilityArg: plugins.servezoneInterfaces.platform.TPlatformCapability
|
|
133
|
+
) {
|
|
134
|
+
return ['email', 'sms', 'pushnotification', 'letter'].includes(capabilityArg);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private async getConfiguredAuthorizationString() {
|
|
138
|
+
return (
|
|
139
|
+
(await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_AUTHORIZATION')) ||
|
|
140
|
+
(await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_TOKEN'))
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private getAuthorizationStringFromBindings() {
|
|
145
|
+
const authEnvNames = [
|
|
146
|
+
'SERVEZONE_PLATFORM_AUTHORIZATION',
|
|
147
|
+
'SERVEZONE_PLATFORM_TOKEN',
|
|
148
|
+
'SERVEZONE_API_TOKEN',
|
|
149
|
+
'AUTHORIZATION',
|
|
150
|
+
'TOKEN',
|
|
151
|
+
];
|
|
152
|
+
for (const binding of this.platformBindings) {
|
|
153
|
+
for (const credential of binding.credentials || []) {
|
|
154
|
+
for (const envName of authEnvNames) {
|
|
155
|
+
const value = credential.env?.[envName];
|
|
156
|
+
if (value) {
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async setAuthorizationTag() {
|
|
165
|
+
if (!this.authorizationString) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
await this.typedsocket.setTag('authorization' as any, this.authorizationString);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (await this.getConfiguredEnvVar('SERVEZONE_PLATFORMCLIENT_DEBUG')) {
|
|
172
|
+
console.warn('Could not set platform authorization tag:', (error as Error).message);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private async discoverPlatformBindings() {
|
|
178
|
+
const bindings: plugins.servezoneInterfaces.platform.IPlatformBinding[] = [];
|
|
179
|
+
const envBindings = await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_BINDINGS');
|
|
180
|
+
const envBinding = await this.getConfiguredEnvVar('SERVEZONE_PLATFORM_BINDING');
|
|
181
|
+
|
|
182
|
+
if (envBindings) {
|
|
183
|
+
bindings.push(...this.parsePlatformBindingsEnv('SERVEZONE_PLATFORM_BINDINGS', envBindings));
|
|
184
|
+
}
|
|
185
|
+
if (envBinding) {
|
|
186
|
+
bindings.push(...this.parsePlatformBindingsEnv('SERVEZONE_PLATFORM_BINDING', envBinding));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return bindings;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private parsePlatformBindingsEnv(envNameArg: string, envValueArg: string) {
|
|
193
|
+
let parsedValue: unknown;
|
|
194
|
+
try {
|
|
195
|
+
parsedValue = JSON.parse(envValueArg);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
throw new Error(`${envNameArg} must contain valid JSON`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (Array.isArray(parsedValue)) {
|
|
201
|
+
return parsedValue as plugins.servezoneInterfaces.platform.IPlatformBinding[];
|
|
202
|
+
}
|
|
203
|
+
if (parsedValue && typeof parsedValue === 'object') {
|
|
204
|
+
return [parsedValue as plugins.servezoneInterfaces.platform.IPlatformBinding];
|
|
205
|
+
}
|
|
206
|
+
throw new Error(`${envNameArg} must contain a platform binding object or array`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private mergePlatformBindings(
|
|
210
|
+
existingBindingsArg: plugins.servezoneInterfaces.platform.IPlatformBinding[],
|
|
211
|
+
newBindingsArg: plugins.servezoneInterfaces.platform.IPlatformBinding[]
|
|
212
|
+
) {
|
|
213
|
+
const bindingMap = new Map<string, plugins.servezoneInterfaces.platform.IPlatformBinding>();
|
|
214
|
+
for (const binding of [...existingBindingsArg, ...newBindingsArg]) {
|
|
215
|
+
bindingMap.set(binding.id, binding);
|
|
216
|
+
}
|
|
217
|
+
return Array.from(bindingMap.values());
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private async getConfiguredEnvVar(envNameArg: string) {
|
|
221
|
+
const processValue = this.getProcessEnvVar(envNameArg);
|
|
222
|
+
if (processValue) {
|
|
223
|
+
return processValue;
|
|
224
|
+
}
|
|
225
|
+
return this.qenvInstance.getEnvVarOnDemand(envNameArg);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private getProcessEnvVar(envNameArg: string) {
|
|
229
|
+
const processEnv = (globalThis as typeof globalThis & {
|
|
230
|
+
process?: { env?: Record<string, string | undefined> };
|
|
231
|
+
}).process?.env;
|
|
232
|
+
return processEnv?.[envNameArg];
|
|
233
|
+
}
|
|
45
234
|
}
|
|
@@ -11,7 +11,7 @@ export class SzEmailConnector {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public async sendEmail(
|
|
14
|
-
optionsArg: plugins.servezoneInterfaces.
|
|
14
|
+
optionsArg: plugins.servezoneInterfaces.platform.email.IReq_SendEmail['request']
|
|
15
15
|
) {
|
|
16
16
|
if (this.platformClientRef.debugMode) {
|
|
17
17
|
logger.log('info', `sent email with subject ${optionsArg.title} to ${optionsArg.to}
|
|
@@ -26,7 +26,7 @@ export class SzEmailConnector {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const typedRequest =
|
|
29
|
-
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.
|
|
29
|
+
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.email.IReq_SendEmail>(
|
|
30
30
|
'sendEmail'
|
|
31
31
|
);
|
|
32
32
|
const response = await typedRequest.fire(optionsArg);
|
|
@@ -9,7 +9,7 @@ export class SzLetterConnector {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
public async sendLetter(
|
|
12
|
-
optionsArg: plugins.servezoneInterfaces.
|
|
12
|
+
optionsArg: plugins.servezoneInterfaces.platform.letter.IReq_SendLetter['request']
|
|
13
13
|
) {
|
|
14
14
|
|
|
15
15
|
if (this.platformClientRef.debugMode) {
|
|
@@ -21,9 +21,9 @@ export class SzLetterConnector {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const typedRequest =
|
|
24
|
-
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.
|
|
24
|
+
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.letter.IReq_SendLetter>(
|
|
25
25
|
'sendLetter'
|
|
26
26
|
);
|
|
27
27
|
const response = await typedRequest.fire(optionsArg);
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|
|
@@ -9,7 +9,7 @@ export class SzPushNotificationConnector {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
public async sendPushNotification(
|
|
12
|
-
optionsArg: plugins.servezoneInterfaces.
|
|
12
|
+
optionsArg: plugins.servezoneInterfaces.platform.pushnotification.IReq_SendPushNotification['request']
|
|
13
13
|
) {
|
|
14
14
|
if (this.platformClientRef.debugMode) {
|
|
15
15
|
console.log('sendPushNotification', optionsArg);
|
|
@@ -20,7 +20,7 @@ export class SzPushNotificationConnector {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const typedRequest =
|
|
23
|
-
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.
|
|
23
|
+
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.pushnotification.IReq_SendPushNotification>(
|
|
24
24
|
'sendPushNotification'
|
|
25
25
|
);
|
|
26
26
|
const response = await typedRequest.fire(optionsArg);
|
|
@@ -31,4 +31,4 @@ export class SzPushNotificationConnector {
|
|
|
31
31
|
|
|
32
32
|
return response.status;
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|
|
@@ -9,7 +9,7 @@ export class SzSmsConnector {
|
|
|
9
9
|
this.platformClientRef = platformClientRefArg;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
public async sendSms(messageArg: plugins.servezoneInterfaces.
|
|
12
|
+
public async sendSms(messageArg: plugins.servezoneInterfaces.platform.sms.IReq_SendSms['request']) {
|
|
13
13
|
if (this.platformClientRef.debugMode) {
|
|
14
14
|
logger.log('info', `sent sms to ${messageArg.toNumber}}
|
|
15
15
|
body:
|
|
@@ -22,7 +22,7 @@ export class SzSmsConnector {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const typedrequest = this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.
|
|
25
|
+
const typedrequest = this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.sms.IReq_SendSms>(
|
|
26
26
|
'sendSms'
|
|
27
27
|
);
|
|
28
28
|
const response = await typedrequest.fire(messageArg);
|
|
@@ -31,7 +31,7 @@ export class SzSmsConnector {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
public async sendSmsVerifcation(
|
|
34
|
-
recipientArg: plugins.servezoneInterfaces.
|
|
34
|
+
recipientArg: plugins.servezoneInterfaces.platform.sms.IReq_SendVerificationCode['request']
|
|
35
35
|
) {
|
|
36
36
|
if (this.platformClientRef.debugMode) {
|
|
37
37
|
console.log('sendSmsVerifcation', recipientArg, '123456');
|
|
@@ -40,7 +40,7 @@ export class SzSmsConnector {
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
const typedrequest =
|
|
43
|
-
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.
|
|
43
|
+
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platform.sms.IReq_SendVerificationCode>(
|
|
44
44
|
'sendVerificationCode'
|
|
45
45
|
);
|
|
46
46
|
const response = await typedrequest.fire(recipientArg);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as plugins from './plugins.js';
|
|
2
|
-
export interface IServiceServerConstructorOptions {
|
|
3
|
-
addCustomRoutes?: (serverArg: plugins.typedserver.servertools.Server) => Promise<any>;
|
|
4
|
-
serviceName: string;
|
|
5
|
-
serviceVersion: string;
|
|
6
|
-
serviceDomain: string;
|
|
7
|
-
port?: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* a server for serving your app to the outside world
|
|
11
|
-
*/
|
|
12
|
-
export declare class ServiceServer {
|
|
13
|
-
options: IServiceServerConstructorOptions;
|
|
14
|
-
typedServer: plugins.typedserver.TypedServer;
|
|
15
|
-
constructor(optionsArg: IServiceServerConstructorOptions);
|
|
16
|
-
start(): Promise<void>;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as plugins from './plugins.js';
|
|
2
|
-
import { InfoHtml } from './infohtml/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* a server for serving your app to the outside world
|
|
5
|
-
*/
|
|
6
|
-
export class ServiceServer {
|
|
7
|
-
constructor(optionsArg) {
|
|
8
|
-
this.options = optionsArg;
|
|
9
|
-
}
|
|
10
|
-
async start() {
|
|
11
|
-
console.log('starting lole-serviceserver...');
|
|
12
|
-
this.typedServer = new plugins.typedserver.TypedServer({
|
|
13
|
-
cors: true,
|
|
14
|
-
domain: this.options.serviceDomain,
|
|
15
|
-
forceSsl: false,
|
|
16
|
-
port: this.options.port || 3000,
|
|
17
|
-
robots: true,
|
|
18
|
-
defaultAnswer: async () => {
|
|
19
|
-
return (await InfoHtml.fromSimpleText(`${this.options.serviceName} (version ${this.options.serviceVersion})`)).htmlString;
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
// lets add any custom routes
|
|
23
|
-
if (this.options.addCustomRoutes) {
|
|
24
|
-
await this.options.addCustomRoutes(this.typedServer.server);
|
|
25
|
-
}
|
|
26
|
-
await this.typedServer.start();
|
|
27
|
-
}
|
|
28
|
-
async stop() {
|
|
29
|
-
await this.typedServer.stop();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5zZXJ2aWNlc2VydmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2xhc3Nlcy5zZXJ2aWNlc2VydmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sY0FBYyxDQUFDO0FBQ3hDLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQVUvQzs7R0FFRztBQUNILE1BQU0sT0FBTyxhQUFhO0lBSXhCLFlBQVksVUFBNEM7UUFDdEQsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUM7SUFDNUIsQ0FBQztJQUVNLEtBQUssQ0FBQyxLQUFLO1FBQ2hCLE9BQU8sQ0FBQyxHQUFHLENBQUMsZ0NBQWdDLENBQUMsQ0FBQTtRQUM3QyxJQUFJLENBQUMsV0FBVyxHQUFHLElBQUksT0FBTyxDQUFDLFdBQVcsQ0FBQyxXQUFXLENBQUM7WUFDckQsSUFBSSxFQUFFLElBQUk7WUFDVixNQUFNLEVBQUUsSUFBSSxDQUFDLE9BQU8sQ0FBQyxhQUFhO1lBQ2xDLFFBQVEsRUFBRSxLQUFLO1lBQ2YsSUFBSSxFQUFFLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxJQUFJLElBQUk7WUFDL0IsTUFBTSxFQUFFLElBQUk7WUFDWixhQUFhLEVBQUUsS0FBSyxJQUFJLEVBQUU7Z0JBQ3hCLE9BQU8sQ0FDTCxNQUFNLFFBQVEsQ0FBQyxjQUFjLENBQzNCLEdBQUcsSUFBSSxDQUFDLE9BQU8sQ0FBQyxXQUFXLGFBQWEsSUFBSSxDQUFDLE9BQU8sQ0FBQyxjQUFjLEdBQUcsQ0FDdkUsQ0FDRixDQUFDLFVBQVUsQ0FBQztZQUNmLENBQUM7U0FDRixDQUFDLENBQUM7UUFFSCw2QkFBNkI7UUFDN0IsSUFBSSxJQUFJLENBQUMsT0FBTyxDQUFDLGVBQWUsRUFBRSxDQUFDO1lBQ2pDLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUM5RCxDQUFDO1FBRUQsTUFBTSxJQUFJLENBQUMsV0FBVyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQ2pDLENBQUM7SUFFTSxLQUFLLENBQUMsSUFBSTtRQUNmLE1BQU0sSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLEVBQUUsQ0FBQztJQUNoQyxDQUFDO0NBQ0YifQ==
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as plugins from '../plugins.js';
|
|
2
|
-
export interface IHtmlInfoOptions {
|
|
3
|
-
text: string;
|
|
4
|
-
heading?: string;
|
|
5
|
-
title?: string;
|
|
6
|
-
sentryMessage?: string;
|
|
7
|
-
sentryDsn?: string;
|
|
8
|
-
redirectTo?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class InfoHtml {
|
|
11
|
-
static fromSimpleText(textArg: string): Promise<InfoHtml>;
|
|
12
|
-
static fromOptions(optionsArg: IHtmlInfoOptions): Promise<InfoHtml>;
|
|
13
|
-
options: IHtmlInfoOptions;
|
|
14
|
-
smartntmlInstance: plugins.smartntml.Smartntml;
|
|
15
|
-
htmlString: string;
|
|
16
|
-
constructor(optionsArg: IHtmlInfoOptions);
|
|
17
|
-
init(): Promise<string>;
|
|
18
|
-
}
|