From 500cec008a009526575bd36e610d4f9bba0c8a24 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sat, 25 Apr 2026 15:03:12 +0000 Subject: [PATCH] refactor(cloudly): consume external api package --- package.json | 2 +- pnpm-lock.yaml | 18 + test/test.apiclient.ts | 9 +- ts_apiclient/classes.cloudlyapiclient.ts | 587 ----------------------- ts_apiclient/classes.cluster.ts | 84 ---- ts_apiclient/classes.externalregistry.ts | 84 ---- ts_apiclient/classes.image.ts | 113 ----- ts_apiclient/classes.secretbundle.ts | 135 ------ ts_apiclient/classes.secretgroup.ts | 96 ---- ts_apiclient/classes.server.ts | 7 - ts_apiclient/classes.service.ts | 78 --- ts_apiclient/index.ts | 1 - ts_apiclient/plugins.ts | 37 -- ts_apiclient/readme.md | 306 ------------ ts_apiclient/tspublish.json | 17 - tsconfig.json | 3 - 16 files changed, 23 insertions(+), 1554 deletions(-) delete mode 100644 ts_apiclient/classes.cloudlyapiclient.ts delete mode 100644 ts_apiclient/classes.cluster.ts delete mode 100644 ts_apiclient/classes.externalregistry.ts delete mode 100644 ts_apiclient/classes.image.ts delete mode 100644 ts_apiclient/classes.secretbundle.ts delete mode 100644 ts_apiclient/classes.secretgroup.ts delete mode 100644 ts_apiclient/classes.server.ts delete mode 100644 ts_apiclient/classes.service.ts delete mode 100644 ts_apiclient/index.ts delete mode 100644 ts_apiclient/plugins.ts delete mode 100644 ts_apiclient/readme.md delete mode 100644 ts_apiclient/tspublish.json diff --git a/package.json b/package.json index 5cb975f..12b6264 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "type": "module", "exports": { ".": "./dist/index.js", - "./apiclient": "./dist_apiclient/index.js", "./cliclient": "./dist_cliclient/index.js", "./web": "./dist_web/index.js" }, @@ -73,6 +72,7 @@ "@push.rocks/smartunique": "^3.0.9", "@push.rocks/taskbuffer": "^3.4.0", "@push.rocks/webjwt": "^1.0.9", + "@serve.zone/api": "^5.3.1", "@serve.zone/interfaces": "^5.4.3", "@tsclass/tsclass": "^9.2.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 461368d..05fc35c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -134,6 +134,9 @@ importers: '@push.rocks/webjwt': specifier: ^1.0.9 version: 1.0.9 + '@serve.zone/api': + specifier: ^5.3.1 + version: 5.3.1 '@serve.zone/interfaces': specifier: ^5.4.3 version: 5.4.3 @@ -1941,6 +1944,9 @@ packages: '@sec-ant/readable-stream@0.4.1': resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==} + '@serve.zone/api@5.3.1': + resolution: {integrity: sha512-P6f3VWr2ljM8dwEtWYBROSZVtcW1HMc5oiorOCcvDeWY6roJbZobK6UFDlcdop02TxGEneJD+jVKoCwBoBLJVw==} + '@serve.zone/interfaces@5.4.3': resolution: {integrity: sha512-9ijFhHoC7GYyyAUJbBoDYmcoCmIXTFPiD6fI3x68SWiC0xA+2LG0nOe14D32c1QN9X/3i2Ac5/1sUibfjHsIGg==} @@ -9061,6 +9067,18 @@ snapshots: '@sec-ant/readable-stream@0.4.1': {} + '@serve.zone/api@5.3.1': + dependencies: + '@api.global/typedrequest': 3.1.10 + '@api.global/typedrequest-interfaces': 3.0.19 + '@api.global/typedsocket': 3.0.1 + '@push.rocks/smartexpect': 2.5.0 + '@push.rocks/smartpromise': 4.2.3 + '@push.rocks/smartrx': 3.0.10 + '@push.rocks/smartstream': 3.2.5 + '@serve.zone/interfaces': 5.4.3 + '@tsclass/tsclass': 9.2.0 + '@serve.zone/interfaces@5.4.3': dependencies: '@api.global/typedrequest-interfaces': 3.0.19 diff --git a/test/test.apiclient.ts b/test/test.apiclient.ts index dfdee37..d09f222 100644 --- a/test/test.apiclient.ts +++ b/test/test.apiclient.ts @@ -2,8 +2,7 @@ import { tap, expect } from '@git.zone/tstest/tapbundle'; import * as helpers from './helpers/index.js'; import * as cloudly from '../ts/index.js'; -import * as cloudlyApiClient from '../ts_apiclient/index.js'; -import { Image } from '../ts_apiclient/classes.image.js'; +import * as cloudlyApiClient from '@serve.zone/api'; let testCloudly: cloudly.Cloudly; let testClient: cloudlyApiClient.CloudlyApiClient; @@ -85,7 +84,7 @@ tap.test('should get an identity', async () => { } }); -let image: Image; +let image: any; tap.test('should create and upload an image', async () => { console.log('๐Ÿ”ต Test: Creating and uploading image...'); console.log(` - Image name: 'test'`); @@ -99,7 +98,7 @@ tap.test('should create and upload an image', async () => { console.log('โœ… Image created successfully:'); console.log(` - Image ID: ${image?.id}`); console.log(` - Image data:`, image); - expect(image).toBeInstanceOf(Image); + expect(image).toBeTruthy(); } catch (error) { console.error('โŒ Failed to create image:'); console.error(` - Error message: ${error.message}`); @@ -135,4 +134,4 @@ tap.test('should stop the apiclient', async (toolsArg) => { await testCloudly.stop(); }) -export default tap.start(); \ No newline at end of file +export default tap.start(); diff --git a/ts_apiclient/classes.cloudlyapiclient.ts b/ts_apiclient/classes.cloudlyapiclient.ts deleted file mode 100644 index b098080..0000000 --- a/ts_apiclient/classes.cloudlyapiclient.ts +++ /dev/null @@ -1,587 +0,0 @@ -import * as plugins from './plugins.js'; - -export type TClientType = 'api' | 'ci' | 'coreflow' | 'cli' | 'serverconfig'; - -import { Image } from './classes.image.js'; -import { Service } from './classes.service.js'; -import { Cluster } from './classes.cluster.js'; -import { SecretBundle } from './classes.secretbundle.js'; -import { SecretGroup } from './classes.secretgroup.js'; -import { ExternalRegistry } from './classes.externalregistry.js'; - -export class CloudlyApiClient { - private cloudlyUrl: string; - private registerAs: string; - - public typedrouter = new plugins.typedrequest.TypedRouter(); - public typedsocketClient: plugins.typedsocket.TypedSocket; - - // Subjects - public configUpdateSubject = new plugins.smartrx.rxjs.Subject< - plugins.servezoneInterfaces.requests.config.IRequest_Cloudly_Coreflow_PushClusterConfig['request'] - >(); - - public serverActionSubject = new plugins.smartrx.rxjs.Subject< - plugins.servezoneInterfaces.requests.server.IRequest_TriggerServerAction['request'] - >(); - - constructor(optionsArg: { - registerAs: TClientType; - cloudlyUrl?: string; - }) { - this.registerAs = optionsArg.registerAs; - this.cloudlyUrl = - optionsArg?.cloudlyUrl || process.env.CLOUDLY_URL || 'https://cloudly.layer.io:443'; - - console.log( - `creating LoleCloudlyClient: registering as ${this.registerAs} and target url ${this.cloudlyUrl}` - ); - - this.typedrouter.addTypedHandler( - new plugins.typedrequest.TypedHandler('pushClusterConfig', async (dataArg) => { - this.configUpdateSubject.next(dataArg); - return {}; - }) - ); - - this.typedrouter.addTypedHandler( - new plugins.typedrequest.TypedHandler('triggerServerAction', async (dataArg) => { - this.serverActionSubject.next(dataArg); - return { - actionConfirmed: true, - }; - }) - ); - } - - // Helper: resolve HTTP typedrequest endpoint - private get httpEndpoint() { - const base = (this.cloudlyUrl || '').replace(/\/$/, ''); - return `${base}/typedrequest`; - } - - // Helper: choose transport (WS if available, else HTTP) - private createWsRequest(operation: string) { - return this.typedsocketClient?.createTypedRequest(operation); - } - - private createHttpRequest(operation: string) { - return new plugins.typedrequest.TypedRequest(this.httpEndpoint, operation); - } - - public async start() { - this.typedsocketClient = await plugins.typedsocket.TypedSocket.createClient( - this.typedrouter, - this.cloudlyUrl - ); - console.log( - `CloudlyClient connected to cloudly at ${this.cloudlyUrl}. Remember to get an identity.` - ); - } - - public async stop() { - await this.typedsocketClient.stop(); - } - - public identity: plugins.servezoneInterfaces.data.IIdentity; - public async getIdentityByToken( - token: string, - optionsArg?: { - tagConnection?: boolean; - statefullIdentity?: boolean; - } - ): Promise { - optionsArg = Object.assign({}, { - tagConnection: false, - statefullIdentity: true, - }, optionsArg); - - const identityRequest = - this.typedsocketClient.createTypedRequest( - 'getIdentityByToken' - ); - console.log(`trying to get identity from cloudly with supplied jumpCodeArg: ${token}`); - const response = await identityRequest.fire({ - token: token, - }); - console.log('got identity response'); - const identity = response.identity; - - if (optionsArg.tagConnection) { - this.typedsocketClient.addTag('identity', identity); - } - - if (optionsArg.statefullIdentity) { - this.identity = identity; - } - - return identity; - } - - /** - * will use statefull identity by default - */ - public async getClusterConfigFromCloudlyByIdentity( - identityArg: plugins.servezoneInterfaces.data.IIdentity = this.identity - ): Promise { - const clusterConfigRequest = - this.typedsocketClient.createTypedRequest( - 'getClusterConfig' - ); - const response = await clusterConfigRequest.fire({ - identity: identityArg, - }); - return response.configData; - } - - /** - * will use statefull identity by default - */ - public async getServerConfigFromCloudlyByIdentity( - identityArg: plugins.servezoneInterfaces.data.IIdentity = this.identity - ): Promise { - const serverConfigRequest = - this.typedsocketClient.createTypedRequest( - 'getServerConfig' - ); - const response = await serverConfigRequest.fire({ - identity: identityArg, - serverId: '', // TODO: get server id here - }); - return response.configData; - } - - /** - * gets a certificate for a domain used by a service - */ - public async getCertificateForDomain(optionsArg: { - domainName: string; - type: plugins.servezoneInterfaces.requests.certificate.IRequest_Any_Cloudly_GetCertificateForDomain['request']['type']; - identity?: plugins.servezoneInterfaces.data.IIdentity; - }): Promise { - optionsArg.identity = optionsArg.identity || this.identity; - if (!optionsArg.identity) { - throw new Error('identity is required. Either provide one or login first.'); - } - const typedCertificateRequest = - this.typedsocketClient.createTypedRequest( - 'getCertificateForDomain' - ); - const typedResponse = await typedCertificateRequest.fire({ - identity: this.identity, // do proper auth here - domainName: optionsArg.domainName, - type: optionsArg.type, - }); - return typedResponse.certificate; - } - - public externalRegistry = { - // ExternalRegistry - getRegistryById: async (registryNameArg: string) => { - return ExternalRegistry.getExternalRegistryById(this, registryNameArg); - }, - updateRegistry: async (registryId: string, registryData: plugins.servezoneInterfaces.data.IExternalRegistry['data']): Promise<{ resultRegistry: plugins.servezoneInterfaces.data.IExternalRegistry }> => { - const op = 'updateExternalRegistry'; - const payload = { identity: this.identity, registryId, registryData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - deleteRegistry: async (registryId: string): Promise<{ ok: boolean }> => { - const op = 'deleteExternalRegistryById'; - const payload = { identity: this.identity, registryId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - getRegistries: async () => { - return ExternalRegistry.getExternalRegistries(this); - }, - createRegistry: async (optionsArg: Parameters[1]) => { - return ExternalRegistry.createExternalRegistry(this, optionsArg); - }, - verifyRegistry: async (registryId: string): Promise<{ success: boolean; message: string; registry?: ExternalRegistry }> => { - const op = 'verifyExternalRegistry'; - const wsReq = this.createWsRequest(op); - const payload = { identity: this.identity, registryId } as any; - const resp = wsReq ? await wsReq.fire(payload) : await this.createHttpRequest(op).fire(payload); - let registryInstance: ExternalRegistry | undefined; - if (resp.registry) { - registryInstance = new ExternalRegistry(this); - Object.assign(registryInstance, resp.registry); - } - return { success: resp.success, message: resp.message, registry: registryInstance }; - } - } - - // Auth helpers - public async loginWithUsernameAndPassword(username: string, password: string): Promise { - const op = 'adminLoginWithUsernameAndPassword'; - // Login endpoint is exposed via HTTP typedrequest - const httpReq = this.createHttpRequest(op); - const response = await httpReq.fire({ username, password }); - this.identity = response.identity; - // If WS connection is available, tag it with identity for server-side guards - if (this.typedsocketClient) { - try { this.typedsocketClient.addTag('identity', this.identity); } catch {} - } - return this.identity; - } - - public image = { - // Images - getImageById: async (imageIdArg: string) => { - return Image.getImageById(this, imageIdArg); - }, - getImages: async () => { - return Image.getImages(this); - }, - createImage: async (optionsArg: Parameters[1]) => { - return Image.createImage(this, optionsArg); - }, - deleteImage: async (imageId: string): Promise => { - const op = 'deleteImage'; - const payload = { identity: this.identity, imageId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) { await wsReq.fire(payload); return; } - await this.createHttpRequest(op).fire(payload); - } - } - - public services = { - // Services - getServiceById: async (serviceIdArg: string) => { - return Service.getServiceById(this, serviceIdArg); - }, - getServices: async () => { - return Service.getServices(this); - }, - createService: async (optionsArg: Parameters[1]) => { - return Service.createService(this, optionsArg); - }, - updateService: async (serviceId: string, serviceData: plugins.servezoneInterfaces.data.IService['data']): Promise<{ service: plugins.servezoneInterfaces.data.IService }> => { - const op = 'updateService'; - const payload = { identity: this.identity, serviceId, serviceData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - deleteService: async (serviceId: string): Promise => { - const op = 'deleteServiceById'; - const payload = { identity: this.identity, serviceId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) { await wsReq.fire(payload); return; } - await this.createHttpRequest(op).fire(payload); - } - } - - public cluster = { - // Clusters - getClusterById: async (clusterIdArg: string) => { - return Cluster.getClusterById(this, clusterIdArg); - }, - getClusters: async () => { - return Cluster.getClusters(this); - }, - createCluster: async (optionsArg: Parameters[1]) => { - return Cluster.createCluster(this, optionsArg); - }, - createClusterAdvanced: async (clusterName: string, setupMode?: 'manual' | 'hetzner' | 'aws' | 'digitalocean') => { - const op = 'createCluster'; - const payload: any = { identity: this.identity, clusterName }; - if (setupMode) payload.setupMode = setupMode; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - } - } - - public secretbundle = { - // SecretBundles - getSecretBundleById: async (secretBundleIdArg: string) => { - return SecretBundle.getSecretBundleById(this, secretBundleIdArg); - }, - getSecretBundles: async () => { - return SecretBundle.getSecretBundles(this); - }, - createSecretBundle: async (optionsArg: Parameters[1]) => { - return SecretBundle.createSecretBundle(this, optionsArg); - }, - deleteSecretBundleById: async (secretBundleId: string): Promise<{ ok: boolean }> => { - const op = 'deleteSecretBundleById'; - const payload = { identity: this.identity, secretBundleId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - } - } - - public secretgroup = { - // SecretGroups - getSecretGroupById: async (secretGroupIdArg: string) => { - return SecretGroup.getSecretGroupById(this, secretGroupIdArg); - }, - getSecretGroups: async () => { - return SecretGroup.getSecretGroups(this); - }, - createSecretGroup: async (optionsArg: Parameters[1]) => { - return SecretGroup.createSecretGroup(this, optionsArg); - }, - deleteSecretGroupById: async (secretGroupId: string): Promise<{ ok: boolean }> => { - const op = 'deleteSecretGroupById'; - const payload = { identity: this.identity, secretGroupId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - } - } - - // Settings API - public settings = { - getSettings: async (): Promise<{ - settings: plugins.servezoneInterfaces.data.ICloudlySettingsMasked - }> => { - const op = 'getSettings'; - const wsReq = this.createWsRequest(op); - if (wsReq) { - return wsReq.fire({ identity: this.identity }); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire({ identity: this.identity }); - }, - updateSettings: async (updates: Partial): Promise<{ - success: boolean; - message: string; - }> => { - const op = 'updateSettings'; - const wsReq = this.createWsRequest(op); - const payload = { identity: this.identity, updates } as any; - if (wsReq) { - return wsReq.fire(payload); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire(payload); - }, - testProviderConnection: async (provider: string): Promise<{ - connectionValid: boolean; - message: string; - }> => { - const op = 'testProviderConnection'; - const wsReq = this.createWsRequest(op); - const payload = { identity: this.identity, provider: provider as any } as any; - if (wsReq) { - return wsReq.fire(payload); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire(payload); - } - } - - // Task API - public tasks = { - getTasks: async (): Promise<{ - tasks: Array<{ - name: string; - description: string; - category: 'maintenance' | 'deployment' | 'backup' | 'monitoring' | 'cleanup' | 'system' | 'security'; - schedule?: string; - lastRun?: number; - enabled: boolean; - }> - }> => { - const op = 'getTasks'; - const wsReq = this.createWsRequest(op); - if (wsReq) { - return wsReq.fire({ identity: this.identity }); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire({ identity: this.identity }); - }, - getTaskExecutions: async (filter?: any): Promise<{ - executions: plugins.servezoneInterfaces.data.ITaskExecution[]; - }> => { - const op = 'getTaskExecutions'; - const wsReq = this.createWsRequest(op); - if (wsReq) { - return wsReq.fire({ identity: this.identity, filter }); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire({ identity: this.identity, filter }); - }, - getTaskExecutionById: async (executionId: string): Promise<{ - execution: plugins.servezoneInterfaces.data.ITaskExecution - }> => { - const op = 'getTaskExecutionById'; - const wsReq = this.createWsRequest(op); - if (wsReq) { - return wsReq.fire({ identity: this.identity, executionId }); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire({ identity: this.identity, executionId }); - }, - triggerTask: async (taskName: string, userId?: string): Promise<{ - execution: plugins.servezoneInterfaces.data.ITaskExecution - }> => { - const op = 'triggerTask'; - const wsReq = this.createWsRequest(op); - if (wsReq) { - return wsReq.fire({ identity: this.identity, taskName, userId }); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire({ identity: this.identity, taskName, userId }); - }, - cancelTask: async (executionId: string): Promise<{ success: boolean }> => { - const op = 'cancelTask'; - const wsReq = this.createWsRequest(op); - if (wsReq) { - return wsReq.fire({ identity: this.identity, executionId }); - } - const httpReq = this.createHttpRequest(op); - return httpReq.fire({ identity: this.identity, executionId }); - } - } - - // Domain API - public domains = { - getDomains: async (): Promise<{ domains: plugins.servezoneInterfaces.data.IDomain[] }> => { - const op = 'getDomains'; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire({ identity: this.identity }); - return this.createHttpRequest(op).fire({ identity: this.identity }); - }, - getDomainById: async (domainId: string): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain }> => { - const op = 'getDomainById'; - const payload = { identity: this.identity, domainId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - createDomain: async (domainData: plugins.servezoneInterfaces.data.IDomain['data']): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain }> => { - const op = 'createDomain'; - const payload = { identity: this.identity, domainData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - updateDomain: async (domainId: string, domainData: Partial): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain }> => { - const op = 'updateDomain'; - const payload = { identity: this.identity, domainId, domainData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - deleteDomain: async (domainId: string): Promise<{ success: boolean }> => { - const op = 'deleteDomain'; - const payload = { identity: this.identity, domainId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - verifyDomain: async (domainId: string, verificationMethod?: 'dns' | 'http' | 'email' | 'manual'): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain; verificationResult: any }> => { - const op = 'verifyDomain'; - const payload = { identity: this.identity, domainId, verificationMethod } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - }; - - // DNS API - public dns = { - getDnsEntries: async (zone?: string): Promise<{ dnsEntries: plugins.servezoneInterfaces.data.IDnsEntry[] }> => { - const op = 'getDnsEntries'; - const payload = { identity: this.identity, zone } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - getDnsEntryById: async (dnsEntryId: string): Promise<{ dnsEntry: plugins.servezoneInterfaces.data.IDnsEntry }> => { - const op = 'getDnsEntryById'; - const payload = { identity: this.identity, dnsEntryId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - createDnsEntry: async (dnsEntryData: plugins.servezoneInterfaces.data.IDnsEntry['data']): Promise<{ dnsEntry: plugins.servezoneInterfaces.data.IDnsEntry }> => { - const op = 'createDnsEntry'; - const payload = { identity: this.identity, dnsEntryData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - updateDnsEntry: async (dnsEntryId: string, dnsEntryData: plugins.servezoneInterfaces.data.IDnsEntry['data']): Promise<{ dnsEntry: plugins.servezoneInterfaces.data.IDnsEntry }> => { - const op = 'updateDnsEntry'; - const payload = { identity: this.identity, dnsEntryId, dnsEntryData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - deleteDnsEntry: async (dnsEntryId: string): Promise<{ success: boolean }> => { - const op = 'deleteDnsEntry'; - const payload = { identity: this.identity, dnsEntryId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - getDnsZones: async (): Promise<{ zones: string[] }> => { - const op = 'getDnsZones'; - const payload = { identity: this.identity } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - }; - - // Deployment API - public deployments = { - getDeployments: async (): Promise<{ deployments: plugins.servezoneInterfaces.data.IDeployment[] }> => { - const op = 'getDeployments'; - const payload = { identity: this.identity } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - getDeploymentById: async (deploymentId: string): Promise<{ deployment: plugins.servezoneInterfaces.data.IDeployment }> => { - const op = 'getDeploymentById'; - const payload = { identity: this.identity, deploymentId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - createDeployment: async (deploymentData: Partial): Promise<{ deployment: plugins.servezoneInterfaces.data.IDeployment }> => { - const op = 'createDeployment'; - const payload = { identity: this.identity, deploymentData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - updateDeployment: async (deploymentId: string, deploymentData: Partial): Promise<{ deployment: plugins.servezoneInterfaces.data.IDeployment }> => { - const op = 'updateDeployment'; - const payload = { identity: this.identity, deploymentId, deploymentData } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - deleteDeployment: async (deploymentId: string): Promise<{ success: boolean }> => { - const op = 'deleteDeploymentById'; - const payload = { identity: this.identity, deploymentId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - restartDeployment: async (deploymentId: string): Promise<{ success: boolean; deployment: plugins.servezoneInterfaces.data.IDeployment }> => { - const op = 'restartDeployment'; - const payload = { identity: this.identity, deploymentId } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - scaleDeployment: async (deploymentId: string, replicas: number): Promise<{ success: boolean; deployment: plugins.servezoneInterfaces.data.IDeployment }> => { - const op = 'scaleDeployment'; - const payload = { identity: this.identity, deploymentId, replicas } as any; - const wsReq = this.createWsRequest(op); - if (wsReq) return wsReq.fire(payload); - return this.createHttpRequest(op).fire(payload); - }, - }; -} diff --git a/ts_apiclient/classes.cluster.ts b/ts_apiclient/classes.cluster.ts deleted file mode 100644 index a2b55e9..0000000 --- a/ts_apiclient/classes.cluster.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { CloudlyApiClient } from './classes.cloudlyapiclient.js'; -import * as plugins from './plugins.js'; - -export class Cluster implements plugins.servezoneInterfaces.data.ICluster { - // STATIC - public static async getClusterById(cloudlyClientRef: CloudlyApiClient, clusterIdArg: string) { - const getClusterByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getClusterById' - ); - const response = await getClusterByIdTR.fire({ - identity: cloudlyClientRef.identity, - clusterId: clusterIdArg, - }); - const newCluster = new Cluster(cloudlyClientRef); - Object.assign(newCluster, response.cluster); - return newCluster; - } - - public static async getClusters(cloudlyClientRef: CloudlyApiClient) { - const getClustersTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getClusters' - ); - const response = await getClustersTR.fire({ - identity: cloudlyClientRef.identity, - }); - const clusterConfigs: Cluster[] = []; - for (const clusterConfig of response.clusters) { - const newCluster = new Cluster(cloudlyClientRef); - Object.assign(newCluster, clusterConfig); - clusterConfigs.push(newCluster); - } - return clusterConfigs; - } - - public static async createCluster(cloudlyClientRef: CloudlyApiClient, clusterNameArg: string) { - const createClusterTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'createCluster' - ); - const response = await createClusterTR.fire({ - identity: cloudlyClientRef.identity, - clusterName: clusterNameArg, - }); - const newCluster = new Cluster(cloudlyClientRef); - Object.assign(newCluster, response.cluster); - return newCluster; - } - - // INSTANCE - public id: string; - public data: plugins.servezoneInterfaces.data.ICluster['data']; - public cloudlyClientRef: CloudlyApiClient; - - constructor(cloudlyClientRef: CloudlyApiClient) { - this.cloudlyClientRef = cloudlyClientRef; - } - - - public async update() { - const updateClusterTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'updateCluster' - ); - const response = await updateClusterTR.fire({ - identity: this.cloudlyClientRef.identity, - clusterData: this.data, - }); - - const resultClusterData = response.resultCluster.data; - plugins.smartexpect.expect(resultClusterData).toEqual(this.data); - - return this; - } - - public async delete(cloudlyClientRef: CloudlyApiClient, clusterIdArg: string) { - const deleteClusterTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'deleteClusterById' - ); - const response = await deleteClusterTR.fire({ - identity: cloudlyClientRef.identity, - clusterId: this.id, - }); - plugins.smartexpect.expect(response.ok).toBeTrue(); - return null; - } -} diff --git a/ts_apiclient/classes.externalregistry.ts b/ts_apiclient/classes.externalregistry.ts deleted file mode 100644 index 86d4537..0000000 --- a/ts_apiclient/classes.externalregistry.ts +++ /dev/null @@ -1,84 +0,0 @@ -import * as plugins from './plugins.js'; -import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; - -export class ExternalRegistry implements plugins.servezoneInterfaces.data.IExternalRegistry { - // STATIC - public static async getExternalRegistryById(cloudlyClientRef: CloudlyApiClient, registryNameArg: string) { - const getRegistryByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getExternalRegistryById' - ); - const response = await getRegistryByIdTR.fire({ - identity: cloudlyClientRef.identity, - id: registryNameArg, - }); - const newRegistry = new ExternalRegistry(cloudlyClientRef); - Object.assign(newRegistry, response.registry); - return newRegistry; - } - - public static async getExternalRegistries(cloudlyClientRef: CloudlyApiClient) { - const getRegistriesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getExternalRegistries' - ); - const response = await getRegistriesTR.fire({ - identity: cloudlyClientRef.identity, - }); - const registryConfigs: ExternalRegistry[] = []; - for (const registryConfig of response.registries) { - const newRegistry = new ExternalRegistry(cloudlyClientRef); - Object.assign(newRegistry, registryConfig); - registryConfigs.push(newRegistry); - } - return registryConfigs; - } - - public static async createExternalRegistry(cloudlyClientRef: CloudlyApiClient, registryDataArg: Partial) { - const createRegistryTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'createExternalRegistry' - ); - const response = await createRegistryTR.fire({ - identity: cloudlyClientRef.identity, - registryData: registryDataArg as plugins.servezoneInterfaces.data.IExternalRegistry['data'], - }); - const newRegistry = new ExternalRegistry(cloudlyClientRef); - Object.assign(newRegistry, response.registry); - return newRegistry; - } - - // INSTANCE - public id: string; - public data: plugins.servezoneInterfaces.data.IExternalRegistry['data']; - public cloudlyClientRef: CloudlyApiClient; - - constructor(cloudlyClientRef: CloudlyApiClient) { - this.cloudlyClientRef = cloudlyClientRef; - } - - public async update() { - const updateRegistryTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'updateExternalRegistry' - ); - const response = await updateRegistryTR.fire({ - identity: this.cloudlyClientRef.identity, - registryId: this.id, - registryData: this.data, - }); - - const resultRegistryData = response.resultRegistry.data; - plugins.smartexpect.expect(resultRegistryData).toEqual(this.data); - - return this; - } - - public async delete(cloudlyClientRef: CloudlyApiClient, registryIdArg: string) { - const deleteRegistryTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'deleteExternalRegistryById' - ); - const response = await deleteRegistryTR.fire({ - identity: cloudlyClientRef.identity, - registryId: this.id, - }); - plugins.smartexpect.expect(response.ok).toBeTrue(); - return null; - } -} diff --git a/ts_apiclient/classes.image.ts b/ts_apiclient/classes.image.ts deleted file mode 100644 index b58e6cd..0000000 --- a/ts_apiclient/classes.image.ts +++ /dev/null @@ -1,113 +0,0 @@ -import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; -import * as plugins from './plugins.js'; - -export class Image implements plugins.servezoneInterfaces.data.IImage { - public static async getImages(cloudlyClientRef: CloudlyApiClient) { - const getAllImagesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getAllImages' - ); - const response = await getAllImagesTR.fire({ - identity: cloudlyClientRef.identity, - }); - const resultImages: Image[] = []; - for (const image of response.images) { - const newImage = new Image(cloudlyClientRef); - Object.assign(newImage, image); - resultImages.push(newImage); - } - return resultImages; - } - - public static async getImageById(cloudlyClientRef: CloudlyApiClient, imageIdArg: string) { - const getImageByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getImage' - ); - const response = await getImageByIdTR.fire({ - identity: cloudlyClientRef.identity, - imageId: imageIdArg, - }); - const newImage = new Image(cloudlyClientRef); - Object.assign(newImage, response.image); - return newImage; - } - - /** - * creates a new image - */ - public static async createImage(cloudlyClientRef: CloudlyApiClient, imageDataArg: Partial) { - const createImageTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'createImage' - ); - const response = await createImageTR.fire({ - identity: cloudlyClientRef.identity, - name: imageDataArg.name, - description: imageDataArg.description, - }); - const newImage = new Image(cloudlyClientRef); - Object.assign(newImage, response.image); - return newImage; - } - - // INSTANCE - cloudlyClientRef: CloudlyApiClient; - - id: plugins.servezoneInterfaces.data.IImage['id']; - data: plugins.servezoneInterfaces.data.IImage['data']; - - constructor(cloudlyClientRef: CloudlyApiClient) { - this.cloudlyClientRef = cloudlyClientRef; - } - - /** - * updates the image data - */ - public async update() { - const getVersionsTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getImage' - ); - const response = await getVersionsTR.fire({ - identity: this.cloudlyClientRef.identity, - imageId: this.id, - }); - Object.assign(this, response.image); - } - - /** - * pushes a new version of the image - * @param imageVersion - * @param imageReadableArg - */ - public async pushImageVersion(imageVersion: string, imageReadableArg: ReadableStream): Promise { - const done = plugins.smartpromise.defer(); - const pushImageTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'pushImageVersion' - ); - const virtualStream = new plugins.typedrequest.VirtualStream(); - const response = await pushImageTR.fire({ - identity: this.cloudlyClientRef.identity, - imageId: this.id, - versionString: '', - imageStream: virtualStream, - }); - await virtualStream.readFromWebstream(imageReadableArg); - await this.update(); - }; - - /** - * pulls a version of the image - */ - public async pullImageVersion(versionStringArg: string): Promise> { - const pullImageTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'pullImageVersion' - ); - const response = await pullImageTR.fire({ - identity: this.cloudlyClientRef.identity, - imageId: this.id, - versionString: versionStringArg, - }); - const imageStream = response.imageStream; - const webduplexStream = new plugins.webstream.WebDuplexStream({}); - imageStream.writeToWebstream(webduplexStream.writable); - return webduplexStream.readable; - }; -} diff --git a/ts_apiclient/classes.secretbundle.ts b/ts_apiclient/classes.secretbundle.ts deleted file mode 100644 index 8b4d127..0000000 --- a/ts_apiclient/classes.secretbundle.ts +++ /dev/null @@ -1,135 +0,0 @@ -import * as plugins from './plugins.js'; -import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; -import { SecretGroup } from './classes.secretgroup.js'; - -export class SecretBundle implements plugins.servezoneInterfaces.data.ISecretBundle { - // STATIC - public static async getSecretBundleById(cloudlyClientRef: CloudlyApiClient, secretBundleIdArg: string) { - const getSecretBundleByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getSecretBundleById' - ); - const response = await getSecretBundleByIdTR.fire({ - identity: cloudlyClientRef.identity, - secretBundleId: secretBundleIdArg, - }); - const newSecretBundle = new SecretBundle(cloudlyClientRef); - Object.assign(newSecretBundle, response.secretBundle); - return newSecretBundle; - } - - public static async getSecretBundleByAuthorization(cloudlyClientRef: CloudlyApiClient, secretBundleAuthorizationArg: plugins.servezoneInterfaces.data.ISecretBundleAuthorization) { - const getSecretBundleByAuthorizationTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getSecretBundleByAuthorization' - ); - const response = await getSecretBundleByAuthorizationTR.fire({ - identity: cloudlyClientRef.identity, - secretBundleAuthorization: secretBundleAuthorizationArg, - }); - const newSecretBundle = new SecretBundle(cloudlyClientRef); - Object.assign(newSecretBundle, response.secretBundle); - return newSecretBundle; - } - - public static async getSecretBundles(cloudlyClientRef: CloudlyApiClient) { - const getSecretBundlesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getSecretBundles' - ); - const response = await getSecretBundlesTR.fire({ - identity: cloudlyClientRef.identity, - }); - const secretBundles: SecretBundle[] = []; - for (const secretBundle of response.secretBundles) { - const newSecretBundle = new SecretBundle(cloudlyClientRef); - Object.assign(newSecretBundle, secretBundle); - secretBundles.push(newSecretBundle); - } - return secretBundles; - } - - public static async createSecretBundle(cloudlyClientRef: CloudlyApiClient, secretBundleDataArg: Partial) { - const createSecretBundleTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'createSecretBundle' - ); - const response = await createSecretBundleTR.fire({ - identity: cloudlyClientRef.identity, - secretBundle: { - id: null, - data: { - name: secretBundleDataArg.name, - description: secretBundleDataArg.description, - type: secretBundleDataArg.type, - authorizations: secretBundleDataArg.authorizations, - imageClaims: secretBundleDataArg.imageClaims, - includedSecretGroupIds: secretBundleDataArg.includedSecretGroupIds, - includedTags: secretBundleDataArg.includedTags, - }, - }, - }); - const newSecretBundle = new SecretBundle(cloudlyClientRef); - Object.assign(newSecretBundle, response.resultSecretBundle); - return newSecretBundle; - } - - // INSTANCE - - public cloudlyClientRef: CloudlyApiClient; - - public id: string; - public data: plugins.servezoneInterfaces.data.ISecretBundle['data']; - - constructor(cloudlyClientRef: CloudlyApiClient) { - this.cloudlyClientRef = cloudlyClientRef; - } - - public async update() { - const updateSecretBundleTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'updateSecretBundle' - ); - const response = await updateSecretBundleTR.fire({ - identity: this.cloudlyClientRef.identity, - secretBundle: { - id: this.id, - data: this.data, - }, - }); - - const resultSecretBundleData = response.resultSecretBundle.data; - plugins.smartexpect.expect(resultSecretBundleData).toEqual(this.data); - - return this; - } - - public async delete(cloudlyClientRef: CloudlyApiClient, secretBundleIdArg: string) { - const deleteSecretBundleTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'deleteSecretBundleById' - ); - const response = await deleteSecretBundleTR.fire({ - identity: cloudlyClientRef.identity, - secretBundleId: this.id, - }); - plugins.smartexpect.expect(response.ok).toBeTrue(); - return null; - } - - public async getFlatKeyValueObjectForEnvironment(environmentArg: string = 'production') { - const bundleAuthorization = this.data.authorizations.find(authorization => { - return authorization.environment === environmentArg; - }); - if (bundleAuthorization) { - throw new Error(`no matching environment >>${environmentArg} found in secret bundle`); - } - - const getFlatKeyValueObjectTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getFlatKeyValueObject' - ); - const response = await getFlatKeyValueObjectTR.fire({ - identity: this.cloudlyClientRef.identity, - seccretBundleId: this.id, - secretBundleAuthorization: bundleAuthorization, - }); - - const flatKeyValueObject: {[key: string]: string} = response.flatKeyValueObject; - - return flatKeyValueObject; - } -} \ No newline at end of file diff --git a/ts_apiclient/classes.secretgroup.ts b/ts_apiclient/classes.secretgroup.ts deleted file mode 100644 index c057276..0000000 --- a/ts_apiclient/classes.secretgroup.ts +++ /dev/null @@ -1,96 +0,0 @@ -import * as plugins from './plugins.js'; -import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; - -export class SecretGroup implements plugins.servezoneInterfaces.data.ISecretGroup { - public cloudlyClientRef: CloudlyApiClient; - - public id: string; - public data: plugins.servezoneInterfaces.data.ISecretGroup['data']; - - constructor(cloudlyClientRef: CloudlyApiClient) { - this.cloudlyClientRef = cloudlyClientRef; - } - - public static async getSecretGroupById(cloudlyClientRef: CloudlyApiClient, secretGroupIdArg: string) { - const getSecretGroupByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getSecretGroupById' - ); - const response = await getSecretGroupByIdTR.fire({ - identity: cloudlyClientRef.identity, - secretGroupId: secretGroupIdArg, - }); - const newSecretGroup = new SecretGroup(cloudlyClientRef); - Object.assign(newSecretGroup, response.secretGroup); - return newSecretGroup; - } - - public static async getSecretGroups(cloudlyClientRef: CloudlyApiClient) { - const getSecretGroupsTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getSecretGroups' - ); - const response = await getSecretGroupsTR.fire({ - identity: cloudlyClientRef.identity, - }); - const secretGroups: SecretGroup[] = []; - for (const secretGroup of response.secretGroups) { - const newSecretGroup = new SecretGroup(cloudlyClientRef); - Object.assign(newSecretGroup, secretGroup); - secretGroups.push(newSecretGroup); - } - return secretGroups; - } - - public static async createSecretGroup(cloudlyClientRef: CloudlyApiClient, secretGroupDataArg: Partial) { - const createSecretGroupTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'createSecretGroup' - ); - const response = await createSecretGroupTR.fire({ - identity: cloudlyClientRef.identity, - secretGroup: { - id: null, - data: { - name: secretGroupDataArg.name, - description: secretGroupDataArg.description, - environments: secretGroupDataArg.environments, - key: secretGroupDataArg.key, - tags: secretGroupDataArg.tags, - priority: secretGroupDataArg.priority, - }, - }, - }); - const newSecretGroup = new SecretGroup(cloudlyClientRef); - Object.assign(newSecretGroup, response.resultSecretGroup); - return newSecretGroup; - } - - // INSTANCE - public async update() { - const updateSecretGroupTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'updateSecretGroup' - ); - const response = await updateSecretGroupTR.fire({ - identity: this.cloudlyClientRef.identity, - secretGroup: { - id: this.id, - data: this.data, - }, - }); - - const resultSecretGroupData = response.resultSecretGroup.data; - plugins.smartexpect.expect(resultSecretGroupData).toEqual(this.data); - - return this; - } - - public async delete(cloudlyClientRef: CloudlyApiClient, secretGroupIdArg: string) { - const deleteSecretGroupTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'deleteSecretGroupById' - ); - const response = await deleteSecretGroupTR.fire({ - identity: cloudlyClientRef.identity, - secretGroupId: this.id, - }); - plugins.smartexpect.expect(response.ok).toBeTrue(); - return null; - } -} diff --git a/ts_apiclient/classes.server.ts b/ts_apiclient/classes.server.ts deleted file mode 100644 index 80518b5..0000000 --- a/ts_apiclient/classes.server.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as plugins from './plugins.js'; - -export class Server { - public static getServers() { - - } -} \ No newline at end of file diff --git a/ts_apiclient/classes.service.ts b/ts_apiclient/classes.service.ts deleted file mode 100644 index 3dc79bc..0000000 --- a/ts_apiclient/classes.service.ts +++ /dev/null @@ -1,78 +0,0 @@ -import * as plugins from './plugins.js'; -import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; - -export class Service implements plugins.servezoneInterfaces.data.IService { - public static async getServices(cloudlyClientRef: CloudlyApiClient) { - const getAllServicesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getServices' - ); - const response = await getAllServicesTR.fire({ - identity: cloudlyClientRef.identity, - }); - const resultServices: Service[] = []; - for (const service of response.services) { - const newService = new Service(cloudlyClientRef); - Object.assign(newService, service); - resultServices.push(newService); - } - return resultServices; - } - - public static async getServiceById(cloudlyClientRef: CloudlyApiClient, serviceIdArg: string) { - const getServiceByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getServiceById' - ); - const response = await getServiceByIdTR.fire({ - identity: cloudlyClientRef.identity, - serviceId: serviceIdArg, - }); - const newService = new Service(cloudlyClientRef); - Object.assign(newService, response.service); - return newService; - } - - /** - * creates a new service - */ - public static async createService(cloudlyClientRef: CloudlyApiClient, serviceDataArg: Partial) { - const createServiceTR = cloudlyClientRef.typedsocketClient.createTypedRequest( - 'createService' - ); - const response = await createServiceTR.fire({ - identity: cloudlyClientRef.identity, - serviceData: serviceDataArg as plugins.servezoneInterfaces.data.IService['data'], - }); - const newService = new Service(cloudlyClientRef); - Object.assign(newService, response.service); - return newService; - } - - // INSTANCE - cloudlyClientRef: CloudlyApiClient; - - public id: string; - public data: plugins.servezoneInterfaces.data.IService['data']; - - constructor(cloudlyClientRef: CloudlyApiClient) { - this.cloudlyClientRef = cloudlyClientRef; - } - - /** - * The service has a secret bundle. - * This function essentially returns the secret bundle as a flat object. - * In other words, it resolves secret groups and - */ - public async getSecretBundleAsFlatObject(environmentArg: string = 'production') { - const getServiceSecretBundlesAsFlatObjectTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( - 'getServiceSecretBundlesAsFlatObject' - ); - const response = await getServiceSecretBundlesAsFlatObjectTR.fire({ - identity: this.cloudlyClientRef.identity, - serviceId: this.id, - environment: environmentArg, - }); - const flatKeyValueObject: {[key: string]: string} = response.flatKeyValueObject; - - return flatKeyValueObject; - } -} diff --git a/ts_apiclient/index.ts b/ts_apiclient/index.ts deleted file mode 100644 index 8e3529d..0000000 --- a/ts_apiclient/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './classes.cloudlyapiclient.js'; \ No newline at end of file diff --git a/ts_apiclient/plugins.ts b/ts_apiclient/plugins.ts deleted file mode 100644 index dbc9950..0000000 --- a/ts_apiclient/plugins.ts +++ /dev/null @@ -1,37 +0,0 @@ -// @serve.zone scope -import * as servezoneInterfaces from '@serve.zone/interfaces'; - -export { - servezoneInterfaces -} - -// @push.rocks scope -import * as smartexpect from '@push.rocks/smartexpect'; -import * as smartpromise from '@push.rocks/smartpromise'; -import * as smartrx from '@push.rocks/smartrx'; -import * as webstream from '@push.rocks/smartstream/web'; - -export { - smartexpect, - smartpromise, - smartrx, - webstream, -} - -// @api.global scope -import * as typedrequest from '@api.global/typedrequest'; -import * as typedsocket from '@api.global/typedsocket'; -import * as typedRequestInterfaces from '@api.global/typedrequest-interfaces'; - -export { - typedrequest, - typedsocket, - typedRequestInterfaces, -} - -// @tsclass scope -import * as tsclass from '@tsclass/tsclass'; - -export { - tsclass, -} diff --git a/ts_apiclient/readme.md b/ts_apiclient/readme.md deleted file mode 100644 index 702a467..0000000 --- a/ts_apiclient/readme.md +++ /dev/null @@ -1,306 +0,0 @@ -# @serve.zone/api ๐Ÿ”Œ - -**The powerful API client for Cloudly.** Connect your applications to multi-cloud infrastructure with type-safe, real-time communication. - -## ๐ŸŽฏ What is @serve.zone/api? - -This is your programmatic gateway to the Cloudly platform. Built with TypeScript, it provides a robust, type-safe interface for managing cloud resources, orchestrating containers, and automating infrastructure operations. - -## โœจ Features - -- **๐Ÿ”’ Type-Safe** - Full TypeScript support with comprehensive interfaces -- **โšก Real-Time** - WebSocket-based communication for instant updates -- **๐Ÿ”‘ Secure Authentication** - Token-based identity management -- **๐Ÿ“ฆ Resource Management** - Complete control over clusters, images, and services -- **๐ŸŽญ Multi-Identity** - Support for service accounts and user authentication -- **๐Ÿ”„ Reactive Streams** - RxJS integration for event-driven programming - -## ๐Ÿš€ Installation - -```bash -pnpm add @serve.zone/api -``` - -## ๐ŸŽฌ Quick Start - -```typescript -import { CloudlyApiClient } from '@serve.zone/api'; - -// Initialize the client -const client = new CloudlyApiClient({ - registerAs: 'api', - cloudlyUrl: 'https://cloudly.example.com:443' -}); - -// Start the connection -await client.start(); - -// Authenticate with a service token -const identity = await client.getIdentityByToken('your-service-token', { - tagConnection: true, - statefullIdentity: true -}); - -console.log('๐ŸŽ‰ Connected as:', identity.name); -``` - -## ๐Ÿ” Authentication - -### Service Token Authentication - -```typescript -// Authenticate using a service token -const identity = await client.getIdentityByToken(serviceToken, { - tagConnection: true, // Tag this connection with the identity - statefullIdentity: true // Maintain state across reconnections -}); -``` - -### Identity Management - -```typescript -// Get current identity -const currentIdentity = client.identity; - -// Check permissions -if (currentIdentity.permissions.includes('cluster:write')) { - // Perform cluster operations -} -``` - -## ๐Ÿ“š Core Operations - -### ๐Ÿณ Image Management - -```typescript -// Create an image entry -const image = await client.images.createImage({ - name: 'my-app', - description: 'Production application image' -}); - -// Push a new version -const imageStream = fs.createReadStream('app.tar'); -await image.pushImageVersion('2.0.0', imageStream); - -// List all images -const images = await client.images.listImages(); -``` - -### ๐ŸŒ Cluster Operations - -```typescript -// Get cluster configuration -const clusterConfig = await client.getClusterConfigFromCloudlyByIdentity(identity); - -// Deploy to cluster -await client.deployToCluster({ - clusterName: 'production', - serviceName: 'api-service', - image: 'my-app:2.0.0', - replicas: 3 -}); -``` - -### ๐Ÿ”’ Certificate Management - -```typescript -// Request SSL certificate -const certificate = await client.getCertificateForDomain({ - domainName: 'api.example.com', - type: 'ssl', - identity: identity -}); - -// Use certificate in your application -console.log('Certificate:', certificate.cert); -console.log('Private Key:', certificate.key); -``` - -### ๐Ÿ” Secret Management - -```typescript -// Create secret group -const secretGroup = await client.secrets.createSecretGroup({ - name: 'api-secrets', - secrets: [ - { key: 'DATABASE_URL', value: 'postgres://...' }, - { key: 'REDIS_URL', value: 'redis://...' } - ] -}); - -// Retrieve secrets -const secrets = await client.secrets.getSecretGroup('api-secrets'); -``` - -## ๐Ÿ”„ Real-Time Updates - -Subscribe to configuration changes and server actions using RxJS: - -```typescript -// Listen for configuration updates -client.configUpdateSubject.subscribe({ - next: (config) => { - console.log('๐Ÿ“ก Configuration updated:', config); - // React to configuration changes - } -}); - -// Handle server action requests -client.serverActionSubject.subscribe({ - next: (action) => { - console.log('โšก Server action:', action.type); - // Process server-initiated actions - } -}); -``` - -## ๐ŸŽฏ Advanced Usage - -### Streaming Operations - -```typescript -// Stream logs from a service -const logStream = await client.logs.streamLogs({ - service: 'api-service', - follow: true -}); - -logStream.on('data', (log) => { - console.log(log.message); -}); -``` - -### Batch Operations - -```typescript -// Deploy multiple services -const deployments = await Promise.all([ - client.deploy({ service: 'frontend', image: 'app:latest' }), - client.deploy({ service: 'backend', image: 'api:latest' }), - client.deploy({ service: 'worker', image: 'worker:latest' }) -]); -``` - -### Error Handling - -```typescript -try { - await client.start(); -} catch (error) { - if (error.code === 'AUTH_FAILED') { - console.error('Authentication failed:', error.message); - } else if (error.code === 'CONNECTION_LOST') { - console.error('Connection lost, retrying...'); - await client.reconnect(); - } -} -``` - -## ๐Ÿงน Cleanup - -Always gracefully disconnect when done: - -```typescript -// Stop the client connection -await client.stop(); -console.log('โœ… Disconnected cleanly'); -``` - -## ๐Ÿ”Œ API Reference - -### CloudlyApiClient - -Main client class for interacting with Cloudly. - -#### Constructor Options - -```typescript -interface ICloudlyApiClientOptions { - registerAs: TClientType; // 'api' | 'cli' | 'web' - cloudlyUrl: string; // Full URL including protocol and port -} -``` - -#### Methods - -- `start()` - Initialize connection -- `stop()` - Close connection -- `getIdentityByToken()` - Authenticate with token -- `getClusterConfigFromCloudlyByIdentity()` - Get cluster configuration -- `getCertificateForDomain()` - Request SSL certificate -- `images` - Image management namespace -- `secrets` - Secret management namespace -- `clusters` - Cluster management namespace - -## ๐ŸŽฌ Complete Example - -```typescript -import { CloudlyApiClient } from '@serve.zone/api'; - -async function main() { - // Initialize client - const client = new CloudlyApiClient({ - registerAs: 'api', - cloudlyUrl: 'https://cloudly.example.com:443' - }); - - try { - // Connect and authenticate - await client.start(); - const identity = await client.getIdentityByToken(process.env.SERVICE_TOKEN, { - tagConnection: true, - statefullIdentity: true - }); - - // Create and deploy an image - const image = await client.images.createImage({ - name: 'my-service', - description: 'Microservice application' - }); - - // Push image version - const stream = getImageStream(); // Your image stream - await image.pushImageVersion('1.0.0', stream); - - // Deploy to cluster - await client.deployToCluster({ - clusterName: 'production', - serviceName: 'my-service', - image: 'my-service:1.0.0', - replicas: 3, - environment: { - NODE_ENV: 'production' - } - }); - - console.log('โœ… Deployment successful!'); - - } catch (error) { - console.error('โŒ Error:', error); - } finally { - await client.stop(); - } -} - -main(); -``` - -## License and Legal Information - -This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. - -**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 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, and any usage must be approved in writing by Task Venture Capital GmbH. - -### Company Information - -Task Venture Capital GmbH -Registered at District court Bremen HRB 35230 HB, Germany - -For any legal inquiries or if you require 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. \ No newline at end of file diff --git a/ts_apiclient/tspublish.json b/ts_apiclient/tspublish.json deleted file mode 100644 index 658f8d7..0000000 --- a/ts_apiclient/tspublish.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "order": 1, - "name": "@serve.zone/api", - "dependencies": [ - "@serve.zone/interfaces", - "@push.rocks/smartpromise", - "@push.rocks/smartrx", - "@push.rocks/smartstream", - "@api.global/typedrequest", - "@api.global/typedsocket", - "@tsclass/tsclass" - ], - "registries": [ - "registry.npmjs.org:public", - "verdaccio.lossless.digital:public" - ] -} diff --git a/tsconfig.json b/tsconfig.json index db5bd0d..12beab0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,6 @@ "verbatimModuleSyntax": true, "baseUrl": ".", "paths": { - "@serve.zone/api": [ - "./ts_apiclient/index.js" - ], "@serve.zone/cli": [ "./ts_cliclient/index.js" ]