@serve.zone/dcrouter 14.3.1 → 15.0.0
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/deno.json +1 -1
- package/dist_serve/bundle.js +121 -121
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/config/classes.route-config-manager.js +6 -22
- package/dist_ts/email/classes.workapp-mail-manager.d.ts +11 -1
- package/dist_ts/email/classes.workapp-mail-manager.js +1 -1
- package/dist_ts/opsserver/classes.opsserver.d.ts +1 -1
- package/dist_ts/opsserver/classes.opsserver.js +3 -3
- package/dist_ts/opsserver/handlers/{workhoster.handler.d.ts → gatewayclient.handler.d.ts} +1 -3
- package/dist_ts/opsserver/handlers/gatewayclient.handler.js +578 -0
- package/dist_ts/opsserver/handlers/index.d.ts +1 -1
- package/dist_ts/opsserver/handlers/index.js +2 -2
- package/dist_ts_apiclient/classes.certificate.js +1 -1
- package/dist_ts_apiclient/classes.dcrouterapiclient.d.ts +2 -2
- package/dist_ts_apiclient/classes.dcrouterapiclient.js +4 -4
- package/dist_ts_apiclient/classes.gatewayclient.d.ts +16 -0
- package/dist_ts_apiclient/classes.gatewayclient.js +36 -0
- package/dist_ts_apiclient/index.d.ts +1 -1
- package/dist_ts_apiclient/index.js +2 -2
- package/dist_ts_interfaces/data/route-management.d.ts +2 -17
- package/dist_ts_interfaces/data/route-management.js +1 -1
- package/dist_ts_interfaces/data/workhoster.d.ts +1 -95
- package/dist_ts_interfaces/requests/certificate.d.ts +0 -41
- package/dist_ts_interfaces/requests/certificate.js +3 -1
- package/dist_ts_interfaces/requests/workhoster.d.ts +1 -107
- package/dist_ts_migrations/index.js +63 -2
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/appstate.d.ts +1 -9
- package/dist_ts_web/appstate.js +1 -1
- package/package.json +2 -2
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/config/classes.route-config-manager.ts +5 -20
- package/ts/email/classes.workapp-mail-manager.ts +11 -1
- package/ts/opsserver/classes.opsserver.ts +2 -2
- package/ts/opsserver/handlers/certificate.handler.ts +2 -2
- package/ts/opsserver/handlers/{workhoster.handler.ts → gatewayclient.handler.ts} +26 -105
- package/ts/opsserver/handlers/index.ts +1 -1
- package/ts_apiclient/classes.certificate.ts +3 -2
- package/ts_apiclient/classes.dcrouterapiclient.ts +3 -3
- package/ts_apiclient/classes.gatewayclient.ts +65 -0
- package/ts_apiclient/index.ts +1 -1
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/appstate.ts +3 -2
- package/dist_ts/opsserver/handlers/workhoster.handler.js +0 -635
- package/dist_ts_apiclient/classes.workhoster.d.ts +0 -15
- package/dist_ts_apiclient/classes.workhoster.js +0 -33
- package/ts_apiclient/classes.workhoster.ts +0 -57
|
@@ -491,19 +491,14 @@ export class RouteConfigManager {
|
|
|
491
491
|
lastResolvedAt: typeof metadata.lastResolvedAt === 'number' && Number.isFinite(metadata.lastResolvedAt)
|
|
492
492
|
? metadata.lastResolvedAt
|
|
493
493
|
: undefined,
|
|
494
|
-
ownerType: metadata.ownerType === 'gatewayClient' || metadata.ownerType === '
|
|
494
|
+
ownerType: metadata.ownerType === 'gatewayClient' || metadata.ownerType === 'operator' || metadata.ownerType === 'system'
|
|
495
495
|
? metadata.ownerType
|
|
496
496
|
: undefined,
|
|
497
497
|
gatewayClientType: metadata.gatewayClientType === 'onebox' || metadata.gatewayClientType === 'cloudly' || metadata.gatewayClientType === 'custom'
|
|
498
498
|
? metadata.gatewayClientType
|
|
499
|
-
:
|
|
500
|
-
gatewayClientId: normalizeString(metadata.gatewayClientId
|
|
501
|
-
gatewayClientAppId: normalizeString(metadata.gatewayClientAppId
|
|
502
|
-
workHosterType: metadata.workHosterType === 'onebox' || metadata.workHosterType === 'cloudly' || metadata.workHosterType === 'custom'
|
|
503
|
-
? metadata.workHosterType
|
|
504
|
-
: metadata.gatewayClientType,
|
|
505
|
-
workHosterId: normalizeString(metadata.workHosterId || metadata.gatewayClientId),
|
|
506
|
-
workAppId: normalizeString(metadata.workAppId || metadata.gatewayClientAppId),
|
|
499
|
+
: undefined,
|
|
500
|
+
gatewayClientId: normalizeString(metadata.gatewayClientId),
|
|
501
|
+
gatewayClientAppId: normalizeString(metadata.gatewayClientAppId),
|
|
507
502
|
externalKey: normalizeString(metadata.externalKey),
|
|
508
503
|
};
|
|
509
504
|
|
|
@@ -513,19 +508,11 @@ export class RouteConfigManager {
|
|
|
513
508
|
if (!normalized.sourceBindings && !normalized.networkTargetRef) {
|
|
514
509
|
normalized.lastResolvedAt = undefined;
|
|
515
510
|
}
|
|
516
|
-
if (normalized.ownerType !== 'gatewayClient'
|
|
511
|
+
if (normalized.ownerType !== 'gatewayClient') {
|
|
517
512
|
normalized.gatewayClientType = undefined;
|
|
518
513
|
normalized.gatewayClientId = undefined;
|
|
519
514
|
normalized.gatewayClientAppId = undefined;
|
|
520
|
-
normalized.workHosterType = undefined;
|
|
521
|
-
normalized.workHosterId = undefined;
|
|
522
|
-
normalized.workAppId = undefined;
|
|
523
515
|
normalized.externalKey = undefined;
|
|
524
|
-
} else {
|
|
525
|
-
normalized.ownerType = 'gatewayClient';
|
|
526
|
-
normalized.workHosterType = normalized.gatewayClientType;
|
|
527
|
-
normalized.workHosterId = normalized.gatewayClientId;
|
|
528
|
-
normalized.workAppId = normalized.gatewayClientAppId;
|
|
529
516
|
}
|
|
530
517
|
|
|
531
518
|
if (Object.values(normalized).every((value) => value === undefined)) {
|
|
@@ -825,9 +812,7 @@ export class RouteConfigManager {
|
|
|
825
812
|
return false;
|
|
826
813
|
}
|
|
827
814
|
return metadata.ownerType === 'gatewayClient'
|
|
828
|
-
|| metadata.ownerType === 'workhoster'
|
|
829
815
|
|| Boolean(metadata.gatewayClientId)
|
|
830
|
-
|| Boolean(metadata.workHosterId)
|
|
831
816
|
|| Boolean(metadata.externalKey);
|
|
832
817
|
}
|
|
833
818
|
|
|
@@ -5,7 +5,17 @@ import type {
|
|
|
5
5
|
import * as plugins from '../plugins.js';
|
|
6
6
|
import type * as interfaces from '../../ts_interfaces/index.js';
|
|
7
7
|
|
|
8
|
-
type TSyncRequest =
|
|
8
|
+
type TSyncRequest = {
|
|
9
|
+
ownership: interfaces.data.IWorkAppMailOwnership;
|
|
10
|
+
localPart: string;
|
|
11
|
+
domain: string;
|
|
12
|
+
displayName?: string;
|
|
13
|
+
inbound?: interfaces.data.IWorkAppMailInboundRoute;
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
smtpEnabled?: boolean;
|
|
16
|
+
resetSmtpPassword?: boolean;
|
|
17
|
+
delete?: boolean;
|
|
18
|
+
};
|
|
9
19
|
type TMailResourceOwner = plugins.servezoneInterfaces.data.IMailResourceOwner;
|
|
10
20
|
type TMailAddressBinding = plugins.servezoneInterfaces.data.IMailAddressBinding;
|
|
11
21
|
type TMailAddressBindingSync = plugins.servezoneInterfaces.requests.mail.TMailAddressBindingSync;
|
|
@@ -38,7 +38,7 @@ export class OpsServer {
|
|
|
38
38
|
private dnsRecordHandler!: handlers.DnsRecordHandler;
|
|
39
39
|
private acmeConfigHandler!: handlers.AcmeConfigHandler;
|
|
40
40
|
private emailDomainHandler!: handlers.EmailDomainHandler;
|
|
41
|
-
private
|
|
41
|
+
private gatewayClientHandler!: handlers.GatewayClientHandler;
|
|
42
42
|
|
|
43
43
|
constructor(dcRouterRefArg: DcRouter) {
|
|
44
44
|
this.dcRouterRef = dcRouterRefArg;
|
|
@@ -98,7 +98,7 @@ export class OpsServer {
|
|
|
98
98
|
this.dnsRecordHandler = new handlers.DnsRecordHandler(this);
|
|
99
99
|
this.acmeConfigHandler = new handlers.AcmeConfigHandler(this);
|
|
100
100
|
this.emailDomainHandler = new handlers.EmailDomainHandler(this);
|
|
101
|
-
this.
|
|
101
|
+
this.gatewayClientHandler = new handlers.GatewayClientHandler(this);
|
|
102
102
|
|
|
103
103
|
console.log('✅ OpsServer TypedRequest handlers initialized');
|
|
104
104
|
}
|
|
@@ -85,7 +85,7 @@ export class CertificateHandler {
|
|
|
85
85
|
|
|
86
86
|
// Export certificate
|
|
87
87
|
router.addTypedHandler(
|
|
88
|
-
new plugins.typedrequest.TypedHandler<
|
|
88
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_ExportCertificate>(
|
|
89
89
|
'exportCertificate',
|
|
90
90
|
async (dataArg) => {
|
|
91
91
|
await this.requireAuth(dataArg, 'certificates:read');
|
|
@@ -96,7 +96,7 @@ export class CertificateHandler {
|
|
|
96
96
|
|
|
97
97
|
// Import certificate
|
|
98
98
|
router.addTypedHandler(
|
|
99
|
-
new plugins.typedrequest.TypedHandler<
|
|
99
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_ImportCertificate>(
|
|
100
100
|
'importCertificate',
|
|
101
101
|
async (dataArg) => {
|
|
102
102
|
await this.requireAuth(dataArg, 'certificates:write');
|
|
@@ -9,7 +9,7 @@ type TAuthContext = {
|
|
|
9
9
|
token?: interfaces.data.IStoredApiToken;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export class
|
|
12
|
+
export class GatewayClientHandler {
|
|
13
13
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
|
14
14
|
|
|
15
15
|
constructor(private opsServerRef: OpsServer) {
|
|
@@ -42,7 +42,7 @@ export class WorkHosterHandler {
|
|
|
42
42
|
|
|
43
43
|
private registerHandlers(): void {
|
|
44
44
|
this.typedrouter.addTypedHandler(
|
|
45
|
-
new plugins.typedrequest.TypedHandler<
|
|
45
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_GetGatewayCapabilities>(
|
|
46
46
|
'getGatewayCapabilities',
|
|
47
47
|
async (dataArg) => {
|
|
48
48
|
await this.requireAuth(dataArg, 'gateway-clients:read');
|
|
@@ -52,7 +52,7 @@ export class WorkHosterHandler {
|
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
this.typedrouter.addTypedHandler(
|
|
55
|
-
new plugins.typedrequest.TypedHandler<
|
|
55
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_GetGatewayClientContext>(
|
|
56
56
|
'getGatewayClientContext',
|
|
57
57
|
async (dataArg) => {
|
|
58
58
|
const auth = await this.requireAuth(dataArg, 'gateway-clients:read');
|
|
@@ -168,7 +168,7 @@ export class WorkHosterHandler {
|
|
|
168
168
|
);
|
|
169
169
|
|
|
170
170
|
this.typedrouter.addTypedHandler(
|
|
171
|
-
new plugins.typedrequest.TypedHandler<
|
|
171
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_GetGatewayClientDomains>(
|
|
172
172
|
'getGatewayClientDomains',
|
|
173
173
|
async (dataArg) => {
|
|
174
174
|
const auth = await this.requireAuth(dataArg, 'gateway-clients:read');
|
|
@@ -179,7 +179,7 @@ export class WorkHosterHandler {
|
|
|
179
179
|
);
|
|
180
180
|
|
|
181
181
|
this.typedrouter.addTypedHandler(
|
|
182
|
-
new plugins.typedrequest.TypedHandler<
|
|
182
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_GetGatewayClientDnsRecords>(
|
|
183
183
|
'getGatewayClientDnsRecords',
|
|
184
184
|
async (dataArg) => {
|
|
185
185
|
const auth = await this.requireAuth(dataArg, 'gateway-clients:read');
|
|
@@ -189,19 +189,9 @@ export class WorkHosterHandler {
|
|
|
189
189
|
),
|
|
190
190
|
);
|
|
191
191
|
|
|
192
|
-
this.typedrouter.addTypedHandler(
|
|
193
|
-
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetWorkHosterDomains>(
|
|
194
|
-
'getWorkHosterDomains',
|
|
195
|
-
async (dataArg) => {
|
|
196
|
-
const auth = await this.requireAuth(dataArg, 'workhosters:read');
|
|
197
|
-
this.assertCapability(auth, 'readDomains');
|
|
198
|
-
return { domains: await this.listGatewayClientDomains(auth) };
|
|
199
|
-
},
|
|
200
|
-
),
|
|
201
|
-
);
|
|
202
192
|
|
|
203
193
|
this.typedrouter.addTypedHandler(
|
|
204
|
-
new plugins.typedrequest.TypedHandler<
|
|
194
|
+
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.gateway.IReq_SyncGatewayClientRoute>(
|
|
205
195
|
'syncGatewayClientRoute',
|
|
206
196
|
async (dataArg) => {
|
|
207
197
|
const auth = await this.requireAuth(dataArg, 'gateway-clients:write');
|
|
@@ -211,52 +201,8 @@ export class WorkHosterHandler {
|
|
|
211
201
|
),
|
|
212
202
|
);
|
|
213
203
|
|
|
214
|
-
this.typedrouter.addTypedHandler(
|
|
215
|
-
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_SyncWorkAppRoute>(
|
|
216
|
-
'syncWorkAppRoute',
|
|
217
|
-
async (dataArg) => {
|
|
218
|
-
const auth = await this.requireAuth(dataArg, 'workhosters:write');
|
|
219
|
-
this.assertCapability(auth, 'syncRoutes');
|
|
220
|
-
const ownership: interfaces.data.IGatewayClientOwnership = {
|
|
221
|
-
gatewayClientType: dataArg.ownership.workHosterType,
|
|
222
|
-
gatewayClientId: dataArg.ownership.workHosterId,
|
|
223
|
-
appId: dataArg.ownership.workAppId,
|
|
224
|
-
hostname: dataArg.ownership.hostname,
|
|
225
|
-
};
|
|
226
|
-
return await this.syncGatewayClientRoute(auth, ownership, dataArg.route, dataArg.enabled, dataArg.delete);
|
|
227
|
-
},
|
|
228
|
-
),
|
|
229
|
-
);
|
|
230
204
|
|
|
231
|
-
this.typedrouter.addTypedHandler(
|
|
232
|
-
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetWorkAppMailIdentities>(
|
|
233
|
-
'getWorkAppMailIdentities',
|
|
234
|
-
async (dataArg) => {
|
|
235
|
-
await this.requireAuth(dataArg, 'workhosters:read');
|
|
236
|
-
const manager = this.opsServerRef.dcRouterRef.workAppMailManager;
|
|
237
|
-
if (!manager) return { identities: [] };
|
|
238
|
-
return { identities: await manager.listMailIdentities(dataArg.ownership) };
|
|
239
|
-
},
|
|
240
|
-
),
|
|
241
|
-
);
|
|
242
205
|
|
|
243
|
-
this.typedrouter.addTypedHandler(
|
|
244
|
-
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_SyncWorkAppMailIdentity>(
|
|
245
|
-
'syncWorkAppMailIdentity',
|
|
246
|
-
async (dataArg) => {
|
|
247
|
-
const auth = await this.requireAuth(dataArg, 'workhosters:write');
|
|
248
|
-
const manager = this.opsServerRef.dcRouterRef.workAppMailManager;
|
|
249
|
-
if (!manager) {
|
|
250
|
-
return { success: false, message: 'WorkApp mail manager not initialized' };
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
return await manager.syncMailIdentity(dataArg, auth.userId);
|
|
254
|
-
} catch (error) {
|
|
255
|
-
return { success: false, message: (error as Error).message };
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
),
|
|
259
|
-
);
|
|
260
206
|
|
|
261
207
|
this.typedrouter.addTypedHandler(
|
|
262
208
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.mail.IReq_ListMailAddressBindings>(
|
|
@@ -336,7 +282,7 @@ export class WorkHosterHandler {
|
|
|
336
282
|
);
|
|
337
283
|
}
|
|
338
284
|
|
|
339
|
-
private getGatewayCapabilities():
|
|
285
|
+
private getGatewayCapabilities(): plugins.servezoneInterfaces.data.IGatewayCapabilities {
|
|
340
286
|
const dcRouter = this.opsServerRef.dcRouterRef;
|
|
341
287
|
return {
|
|
342
288
|
routes: {
|
|
@@ -371,7 +317,7 @@ export class WorkHosterHandler {
|
|
|
371
317
|
};
|
|
372
318
|
}
|
|
373
319
|
|
|
374
|
-
private getGatewayClientContext(auth: TAuthContext):
|
|
320
|
+
private getGatewayClientContext(auth: TAuthContext): plugins.servezoneInterfaces.data.IGatewayClientContext {
|
|
375
321
|
const policy = auth.token?.policy;
|
|
376
322
|
const role = auth.isAdmin ? 'admin' : policy?.role || 'operator';
|
|
377
323
|
return {
|
|
@@ -395,14 +341,6 @@ export class WorkHosterHandler {
|
|
|
395
341
|
}));
|
|
396
342
|
}
|
|
397
343
|
|
|
398
|
-
private buildExternalKey(ownership: interfaces.data.IWorkAppRouteOwnership): string {
|
|
399
|
-
return [
|
|
400
|
-
ownership.workHosterType,
|
|
401
|
-
ownership.workHosterId,
|
|
402
|
-
ownership.workAppId,
|
|
403
|
-
ownership.hostname,
|
|
404
|
-
].map((part) => part.trim()).join(':');
|
|
405
|
-
}
|
|
406
344
|
|
|
407
345
|
private assertCapability(
|
|
408
346
|
auth: TAuthContext,
|
|
@@ -426,8 +364,8 @@ export class WorkHosterHandler {
|
|
|
426
364
|
|
|
427
365
|
private resolveGatewayClientOwnership(
|
|
428
366
|
auth: TAuthContext,
|
|
429
|
-
ownership:
|
|
430
|
-
): Required<
|
|
367
|
+
ownership: plugins.servezoneInterfaces.data.IGatewayClientOwnership,
|
|
368
|
+
): Required<plugins.servezoneInterfaces.data.IGatewayClientOwnership> {
|
|
431
369
|
const policy = auth.token?.policy;
|
|
432
370
|
if (policy?.role === 'gatewayClient') {
|
|
433
371
|
if (!policy.gatewayClient) {
|
|
@@ -450,7 +388,7 @@ export class WorkHosterHandler {
|
|
|
450
388
|
if (!ownership.gatewayClientType || !ownership.gatewayClientId) {
|
|
451
389
|
throw new plugins.typedrequest.TypedResponseError('gateway client ownership is missing type or id');
|
|
452
390
|
}
|
|
453
|
-
return ownership as Required<
|
|
391
|
+
return ownership as Required<plugins.servezoneInterfaces.data.IGatewayClientOwnership>;
|
|
454
392
|
}
|
|
455
393
|
|
|
456
394
|
private resolveMailOwnerFilter(
|
|
@@ -486,7 +424,7 @@ export class WorkHosterHandler {
|
|
|
486
424
|
return resolvedOwner as plugins.servezoneInterfaces.data.IMailResourceOwner;
|
|
487
425
|
}
|
|
488
426
|
|
|
489
|
-
private assertGatewayClientOwnership(auth: TAuthContext, ownership: Required<
|
|
427
|
+
private assertGatewayClientOwnership(auth: TAuthContext, ownership: Required<plugins.servezoneInterfaces.data.IGatewayClientOwnership>): void {
|
|
490
428
|
const policy = auth.token?.policy;
|
|
491
429
|
if (!policy || policy.role !== 'gatewayClient') return;
|
|
492
430
|
if (!this.matchesHostnamePatterns(ownership.hostname, policy.hostnamePatterns || [])) {
|
|
@@ -568,18 +506,15 @@ export class WorkHosterHandler {
|
|
|
568
506
|
return manager.getMergedRoutes().routes.filter((route) => {
|
|
569
507
|
const metadata = route.metadata;
|
|
570
508
|
if (!metadata) return false;
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (!isGatewayOwned) return false;
|
|
574
|
-
const routeGatewayClientId = metadata.gatewayClientId || metadata.workHosterId;
|
|
575
|
-
return gatewayClientId ? routeGatewayClientId === gatewayClientId : true;
|
|
509
|
+
if (metadata.ownerType !== 'gatewayClient') return false;
|
|
510
|
+
return gatewayClientId ? metadata.gatewayClientId === gatewayClientId : true;
|
|
576
511
|
});
|
|
577
512
|
}
|
|
578
513
|
|
|
579
514
|
private async listGatewayClientDomains(
|
|
580
515
|
auth: TAuthContext,
|
|
581
516
|
requestedGatewayClientId?: string,
|
|
582
|
-
): Promise<
|
|
517
|
+
): Promise<plugins.servezoneInterfaces.data.IGatewayDomain[]> {
|
|
583
518
|
const dnsManager = this.opsServerRef.dcRouterRef.dnsManager;
|
|
584
519
|
if (!dnsManager) return [];
|
|
585
520
|
const gatewayClientId = this.resolveGatewayClientId(auth, requestedGatewayClientId);
|
|
@@ -606,27 +541,27 @@ export class WorkHosterHandler {
|
|
|
606
541
|
canIssueCertificates: Boolean(this.opsServerRef.dcRouterRef.smartProxy),
|
|
607
542
|
canHostEmail: Boolean(this.opsServerRef.dcRouterRef.emailDomainManager),
|
|
608
543
|
},
|
|
609
|
-
} satisfies
|
|
544
|
+
} satisfies plugins.servezoneInterfaces.data.IGatewayDomain;
|
|
610
545
|
});
|
|
611
546
|
}
|
|
612
547
|
|
|
613
548
|
private async listGatewayClientDnsRecords(
|
|
614
549
|
auth: TAuthContext,
|
|
615
550
|
requestedGatewayClientId?: string,
|
|
616
|
-
): Promise<
|
|
551
|
+
): Promise<plugins.servezoneInterfaces.data.IGatewayDnsRecord[]> {
|
|
617
552
|
const dnsManager = this.opsServerRef.dcRouterRef.dnsManager;
|
|
618
553
|
if (!dnsManager) return [];
|
|
619
554
|
const gatewayClientId = this.resolveGatewayClientId(auth, requestedGatewayClientId);
|
|
620
555
|
const ownedRoutes = this.getOwnedRoutes(gatewayClientId);
|
|
621
556
|
const domains = await dnsManager.listDomains();
|
|
622
|
-
const records:
|
|
557
|
+
const records: plugins.servezoneInterfaces.data.IGatewayDnsRecord[] = [];
|
|
623
558
|
|
|
624
559
|
for (const route of ownedRoutes) {
|
|
625
560
|
const metadata = route.metadata;
|
|
626
561
|
if (!metadata) continue;
|
|
627
|
-
const gatewayClientType = metadata.gatewayClientType ||
|
|
628
|
-
const routeGatewayClientId = metadata.gatewayClientId ||
|
|
629
|
-
const appId = metadata.gatewayClientAppId ||
|
|
562
|
+
const gatewayClientType = metadata.gatewayClientType || 'custom';
|
|
563
|
+
const routeGatewayClientId = metadata.gatewayClientId || '';
|
|
564
|
+
const appId = metadata.gatewayClientAppId || '';
|
|
630
565
|
|
|
631
566
|
for (const hostname of this.getRouteHostnames(route.route)) {
|
|
632
567
|
if (auth.token?.policy?.role === 'gatewayClient' && !this.matchesHostnamePatterns(hostname, auth.token.policy.hostnamePatterns || [])) {
|
|
@@ -686,11 +621,11 @@ export class WorkHosterHandler {
|
|
|
686
621
|
|
|
687
622
|
private async syncGatewayClientRoute(
|
|
688
623
|
auth: TAuthContext,
|
|
689
|
-
ownership:
|
|
690
|
-
route?:
|
|
624
|
+
ownership: plugins.servezoneInterfaces.data.IGatewayClientOwnership,
|
|
625
|
+
route?: plugins.servezoneInterfaces.data.IGatewayRouteConfig,
|
|
691
626
|
enabled?: boolean,
|
|
692
627
|
deleteRoute?: boolean,
|
|
693
|
-
): Promise<
|
|
628
|
+
): Promise<plugins.servezoneInterfaces.data.IGatewayRouteSyncResult> {
|
|
694
629
|
const resolvedOwnership = this.resolveGatewayClientOwnership(auth, ownership);
|
|
695
630
|
this.assertGatewayClientOwnership(auth, resolvedOwnership);
|
|
696
631
|
this.assertRouteTargetsAllowed(auth, route);
|
|
@@ -728,9 +663,6 @@ export class WorkHosterHandler {
|
|
|
728
663
|
gatewayClientType: resolvedOwnership.gatewayClientType,
|
|
729
664
|
gatewayClientId: resolvedOwnership.gatewayClientId,
|
|
730
665
|
gatewayClientAppId: resolvedOwnership.appId,
|
|
731
|
-
workHosterType: resolvedOwnership.gatewayClientType,
|
|
732
|
-
workHosterId: resolvedOwnership.gatewayClientId,
|
|
733
|
-
workAppId: resolvedOwnership.appId,
|
|
734
666
|
externalKey,
|
|
735
667
|
};
|
|
736
668
|
const normalizedRoute = this.normalizeGatewayClientRoute(route, resolvedOwnership, externalKey);
|
|
@@ -752,7 +684,7 @@ export class WorkHosterHandler {
|
|
|
752
684
|
return { success: true, action: 'created', routeId };
|
|
753
685
|
}
|
|
754
686
|
|
|
755
|
-
private buildGatewayClientExternalKey(ownership: Required<
|
|
687
|
+
private buildGatewayClientExternalKey(ownership: Required<plugins.servezoneInterfaces.data.IGatewayClientOwnership>): string {
|
|
756
688
|
return [
|
|
757
689
|
ownership.gatewayClientType,
|
|
758
690
|
ownership.gatewayClientId,
|
|
@@ -761,21 +693,10 @@ export class WorkHosterHandler {
|
|
|
761
693
|
].map((part) => part.trim()).join(':');
|
|
762
694
|
}
|
|
763
695
|
|
|
764
|
-
private normalizeWorkAppRoute(
|
|
765
|
-
route: interfaces.data.IDcRouterRouteConfig,
|
|
766
|
-
ownership: interfaces.data.IWorkAppRouteOwnership,
|
|
767
|
-
externalKey: string,
|
|
768
|
-
): interfaces.data.IDcRouterRouteConfig {
|
|
769
|
-
const normalizedRoute = { ...route };
|
|
770
|
-
if (!normalizedRoute.name) {
|
|
771
|
-
normalizedRoute.name = `workapp-${externalKey.replace(/[^a-zA-Z0-9-]+/g, '-').slice(0, 80)}`;
|
|
772
|
-
}
|
|
773
|
-
return normalizedRoute;
|
|
774
|
-
}
|
|
775
696
|
|
|
776
697
|
private normalizeGatewayClientRoute(
|
|
777
698
|
route: interfaces.data.IDcRouterRouteConfig,
|
|
778
|
-
ownership: Required<
|
|
699
|
+
ownership: Required<plugins.servezoneInterfaces.data.IGatewayClientOwnership>,
|
|
779
700
|
externalKey: string,
|
|
780
701
|
): interfaces.data.IDcRouterRouteConfig {
|
|
781
702
|
const normalizedRoute = structuredClone(route);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as servezoneInterfaces from '@serve.zone/interfaces';
|
|
1
2
|
import * as interfaces from '../ts_interfaces/index.js';
|
|
2
3
|
import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
|
|
3
4
|
|
|
@@ -65,7 +66,7 @@ export class Certificate {
|
|
|
65
66
|
publicKey: string;
|
|
66
67
|
csr: string;
|
|
67
68
|
} | undefined> {
|
|
68
|
-
const response = await this.clientRef.request<
|
|
69
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_ExportCertificate>(
|
|
69
70
|
'exportCertificate',
|
|
70
71
|
this.clientRef.buildRequestPayload({ domain: this.domain }) as any,
|
|
71
72
|
);
|
|
@@ -112,7 +113,7 @@ export class CertificateManager {
|
|
|
112
113
|
publicKey: string;
|
|
113
114
|
csr: string;
|
|
114
115
|
}): Promise<void> {
|
|
115
|
-
const response = await this.clientRef.request<
|
|
116
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_ImportCertificate>(
|
|
116
117
|
'importCertificate',
|
|
117
118
|
this.clientRef.buildRequestPayload({ cert }) as any,
|
|
118
119
|
);
|
|
@@ -10,7 +10,7 @@ import { ConfigManager } from './classes.config.js';
|
|
|
10
10
|
import { LogManager } from './classes.logs.js';
|
|
11
11
|
import { EmailManager } from './classes.email.js';
|
|
12
12
|
import { RadiusManager } from './classes.radius.js';
|
|
13
|
-
import {
|
|
13
|
+
import { GatewayClientApi } from './classes.gatewayclient.js';
|
|
14
14
|
|
|
15
15
|
export interface IDcRouterApiClientOptions {
|
|
16
16
|
baseUrl: string;
|
|
@@ -32,7 +32,7 @@ export class DcRouterApiClient {
|
|
|
32
32
|
public logs: LogManager;
|
|
33
33
|
public emails: EmailManager;
|
|
34
34
|
public radius: RadiusManager;
|
|
35
|
-
public
|
|
35
|
+
public gatewayClients: GatewayClientApi;
|
|
36
36
|
|
|
37
37
|
constructor(options: IDcRouterApiClientOptions) {
|
|
38
38
|
this.baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
@@ -47,7 +47,7 @@ export class DcRouterApiClient {
|
|
|
47
47
|
this.logs = new LogManager(this);
|
|
48
48
|
this.emails = new EmailManager(this);
|
|
49
49
|
this.radius = new RadiusManager(this);
|
|
50
|
-
this.
|
|
50
|
+
this.gatewayClients = new GatewayClientApi(this);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// =====================
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type * as servezoneInterfaces from '@serve.zone/interfaces';
|
|
2
|
+
import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
|
|
3
|
+
|
|
4
|
+
export class GatewayClientApi {
|
|
5
|
+
constructor(private clientRef: DcRouterApiClient) {}
|
|
6
|
+
|
|
7
|
+
public async getCapabilities(): Promise<servezoneInterfaces.data.IGatewayCapabilities> {
|
|
8
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_GetGatewayCapabilities>(
|
|
9
|
+
'getGatewayCapabilities',
|
|
10
|
+
this.clientRef.buildRequestPayload() as any,
|
|
11
|
+
);
|
|
12
|
+
return response.capabilities;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async getGatewayClientContext(): Promise<servezoneInterfaces.data.IGatewayClientContext> {
|
|
16
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_GetGatewayClientContext>(
|
|
17
|
+
'getGatewayClientContext',
|
|
18
|
+
this.clientRef.buildRequestPayload() as any,
|
|
19
|
+
);
|
|
20
|
+
return response.context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async getDomains(): Promise<servezoneInterfaces.data.IGatewayDomain[]> {
|
|
24
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_GetGatewayClientDomains>(
|
|
25
|
+
'getGatewayClientDomains',
|
|
26
|
+
this.clientRef.buildRequestPayload() as any,
|
|
27
|
+
);
|
|
28
|
+
return response.domains;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async getDnsRecords(): Promise<servezoneInterfaces.data.IGatewayDnsRecord[]> {
|
|
32
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_GetGatewayClientDnsRecords>(
|
|
33
|
+
'getGatewayClientDnsRecords',
|
|
34
|
+
this.clientRef.buildRequestPayload() as any,
|
|
35
|
+
);
|
|
36
|
+
return response.records;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async syncRoute(options: {
|
|
40
|
+
ownership: servezoneInterfaces.data.IGatewayClientOwnership;
|
|
41
|
+
route: servezoneInterfaces.data.IGatewayRouteConfig;
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
}): Promise<servezoneInterfaces.data.IGatewayRouteSyncResult> {
|
|
44
|
+
return this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_SyncGatewayClientRoute>(
|
|
45
|
+
'syncGatewayClientRoute',
|
|
46
|
+
this.clientRef.buildRequestPayload({
|
|
47
|
+
ownership: options.ownership,
|
|
48
|
+
route: options.route,
|
|
49
|
+
enabled: options.enabled,
|
|
50
|
+
}) as any,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async deleteRoute(
|
|
55
|
+
ownership: servezoneInterfaces.data.IGatewayClientOwnership,
|
|
56
|
+
): Promise<servezoneInterfaces.data.IGatewayRouteSyncResult> {
|
|
57
|
+
return this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_SyncGatewayClientRoute>(
|
|
58
|
+
'syncGatewayClientRoute',
|
|
59
|
+
this.clientRef.buildRequestPayload({
|
|
60
|
+
ownership,
|
|
61
|
+
delete: true,
|
|
62
|
+
}) as any,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
package/ts_apiclient/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { Certificate, CertificateManager, type ICertificateSummary } from './cla
|
|
|
7
7
|
export { ApiToken, ApiTokenBuilder, ApiTokenManager } from './classes.apitoken.js';
|
|
8
8
|
export { RemoteIngress, RemoteIngressBuilder, RemoteIngressManager } from './classes.remoteingress.js';
|
|
9
9
|
export { Email, EmailManager } from './classes.email.js';
|
|
10
|
-
export {
|
|
10
|
+
export { GatewayClientApi } from './classes.gatewayclient.js';
|
|
11
11
|
|
|
12
12
|
// Read-only managers
|
|
13
13
|
export { StatsManager } from './classes.stats.js';
|
package/ts_web/appstate.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
+
import type * as servezoneInterfaces from '@serve.zone/interfaces';
|
|
2
3
|
import * as interfaces from '../ts_interfaces/index.js';
|
|
3
4
|
|
|
4
5
|
// Create main app state instance
|
|
@@ -1037,7 +1038,7 @@ export const importCertificateAction = certificateStatePart.createAction<{
|
|
|
1037
1038
|
|
|
1038
1039
|
try {
|
|
1039
1040
|
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
1040
|
-
|
|
1041
|
+
servezoneInterfaces.requests.gateway.IReq_ImportCertificate
|
|
1041
1042
|
>('/typedrequest', 'importCertificate');
|
|
1042
1043
|
|
|
1043
1044
|
await request.fire({
|
|
@@ -1059,7 +1060,7 @@ export const importCertificateAction = certificateStatePart.createAction<{
|
|
|
1059
1060
|
export async function fetchCertificateExport(domain: string) {
|
|
1060
1061
|
const context = getActionContext();
|
|
1061
1062
|
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
1062
|
-
|
|
1063
|
+
servezoneInterfaces.requests.gateway.IReq_ExportCertificate
|
|
1063
1064
|
>('/typedrequest', 'exportCertificate');
|
|
1064
1065
|
|
|
1065
1066
|
return request.fire({
|