import type * as servezoneInterfaces from '@serve.zone/interfaces'; import type { DcRouterApiClient } from './classes.dcrouterapiclient.js'; export class GatewayClientApi { constructor(private clientRef: DcRouterApiClient) {} public async getCapabilities(): Promise { const response = await this.clientRef.request( 'getGatewayCapabilities', this.clientRef.buildRequestPayload() as any, ); return response.capabilities; } public async getGatewayClientContext(): Promise { const response = await this.clientRef.request( 'getGatewayClientContext', this.clientRef.buildRequestPayload() as any, ); return response.context; } public async provisionCredential(options: { provisioning: servezoneInterfaces.data.IGatewayClientProvisioningSpec; credentialName?: string; expiresInDays?: number | null; }): Promise { return await this.clientRef.request( 'provisionGatewayClientCredential', this.clientRef.buildRequestPayload(options) as any, ); } public async finalizeCredential( credential: Pick, ): Promise { return await this.clientRef.request( 'finalizeGatewayClientCredential', { apiToken: credential.tokenValue, tokenId: credential.tokenId }, ); } public async getMailOverview( limit?: number, ): Promise { return await this.clientRef.request( 'getGatewayClientMailOverview', this.clientRef.buildRequestPayload({ limit }) as any, ); } public async getDomains(): Promise { const response = await this.clientRef.request( 'getGatewayClientDomains', this.clientRef.buildRequestPayload() as any, ); return response.domains; } public async getDnsRecords(): Promise { const response = await this.clientRef.request( 'getGatewayClientDnsRecords', this.clientRef.buildRequestPayload() as any, ); return response.records; } public async getRoutes(): Promise { const response = await this.clientRef.request( 'getGatewayClientRoutes', this.clientRef.buildRequestPayload() as any, ); return response.routes; } public async syncRoute(options: { ownership: servezoneInterfaces.data.IGatewayClientOwnership; route: servezoneInterfaces.data.IGatewayRouteConfig; enabled?: boolean; dnsMode?: servezoneInterfaces.data.TGatewayRouteDnsMode; sourceProfileRef?: string; }): Promise { return this.clientRef.request( 'syncGatewayClientRoute', this.clientRef.buildRequestPayload({ ownership: options.ownership, route: options.route, enabled: options.enabled, dnsMode: options.dnsMode, sourceProfileRef: options.sourceProfileRef, }) as any, ); } public async deleteRoute( ownership: servezoneInterfaces.data.IGatewayClientOwnership, options: { dnsMode?: servezoneInterfaces.data.TGatewayRouteDnsMode; } = {}, ): Promise { return this.clientRef.request( 'syncGatewayClientRoute', this.clientRef.buildRequestPayload({ ownership, delete: true, dnsMode: options.dnsMode, }) as any, ); } }