import * as plugins from './plugins.js'; type TGetIdentityCredential = () => plugins.servezoneInterfaces.data.IIdentityCredential; type TFireRequest = ( methodArg: T['method'], requestArg: T['request'], ) => Promise; /** Organization-owned desired state. Successful requests do not prove runtime enforcement. */ export class PrivateNetworkClient { constructor( private readonly getIdentityCredential: TGetIdentityCredential, private readonly fireRequest: TFireRequest, ) {} /** Current picker entries are display data, never reusable authorization grants. */ public async listOwnedOrganizations(): Promise< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_ListOwnedOrganizations['response'] > { return this.fireRequest( 'listOwnedOrganizations', { identity: this.getIdentityCredential() }, ); } public async listServiceCandidates(optionsArg: Omit< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_ListPrivateNetworkServiceCandidates['request'], 'identity' >): Promise { return this.fireRequest( 'listPrivateNetworkServiceCandidates', { identity: this.getIdentityCredential(), organizationId: optionsArg.organizationId, cursor: optionsArg.cursor, limit: optionsArg.limit, }, ); } public async listNetworks(optionsArg: Omit< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_ListPrivateNetworks['request'], 'identity' >): Promise { return this.fireRequest( 'listPrivateNetworks', { identity: this.getIdentityCredential(), organizationId: optionsArg.organizationId, cursor: optionsArg.cursor, limit: optionsArg.limit, }, ); } public async getNetwork(optionsArg: Omit< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_GetPrivateNetwork['request'], 'identity' >): Promise { return this.fireRequest( 'getPrivateNetwork', { identity: this.getIdentityCredential(), organizationId: optionsArg.organizationId, networkId: optionsArg.networkId, }, ); } /** Retain the exact mutation and identifier for explicit retries; replay can return historical state. */ public async mutateNetwork(mutationArg: plugins.servezoneInterfaces.data.TPrivateNetworkMutation): Promise< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_MutatePrivateNetwork['response'] > { const identity = this.getIdentityCredential(); const mutation = plugins.servezoneInterfaces.data.snapshotPrivateNetworkMutation(mutationArg); return this.fireRequest( 'mutatePrivateNetwork', { identity, mutation }, ); } public async getServiceMembership(optionsArg: Omit< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_GetServicePrivateNetworks['request'], 'identity' >): Promise { return this.fireRequest( 'getServicePrivateNetworks', { identity: this.getIdentityCredential(), organizationId: optionsArg.organizationId, serviceId: optionsArg.serviceId, }, ); } /** null expectedRevision means never created; an existing empty membership retains its revision. */ public async setServiceMembership(mutationArg: plugins.servezoneInterfaces.data.ISetServicePrivateNetworks): Promise< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_SetServicePrivateNetworks['response'] > { const identity = this.getIdentityCredential(); const mutation = plugins.servezoneInterfaces.data.snapshotSetServicePrivateNetworks(mutationArg); return this.fireRequest( 'setServicePrivateNetworks', { identity, mutation }, ); } /** null means the service has never had a published-port document, not an empty list. */ public async getServicePublishedPorts(optionsArg: Omit< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_GetServicePublishedPorts['request'], 'identity' >): Promise { return this.fireRequest( 'getServicePublishedPorts', { identity: this.getIdentityCredential(), organizationId: optionsArg.organizationId, serviceId: optionsArg.serviceId, }, ); } /** * Desired publication policy only. Acceptance is neither node placement nor * applied packet state, and a replay returns the historical document. */ public async setServicePublishedPorts( mutationArg: plugins.servezoneInterfaces.data.ISetServicePublishedPorts, ): Promise< plugins.servezoneInterfaces.requests.network.IReq_Cloudly_SetServicePublishedPorts['response'] > { const identity = this.getIdentityCredential(); const mutation = plugins.servezoneInterfaces.data.snapshotSetServicePublishedPorts(mutationArg); return this.fireRequest( 'setServicePublishedPorts', { identity, mutation }, ); } }