diff --git a/changelog.md b/changelog.md index fba66cd..ef67e6a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-12-22 - 4.5.5 - fix(apiclient) +Fixed image creation method in cloudlyApiClient + +- Corrected method call from 'images.createImage' to 'image.createImage' to ensure proper image creation. +- Updated cluster retrieval methods and ensured proper API routes are being called. + ## 2024-12-21 - 4.5.4 - fix(ts_web) Fix action type and data fields in appstate for CRUD operations diff --git a/test/test.apiclient.ts b/test/test.apiclient.ts index 1146e86..904214e 100644 --- a/test/test.apiclient.ts +++ b/test/test.apiclient.ts @@ -57,7 +57,7 @@ tap.test('should get an identity', async () => { let image: Image; tap.test('should create and upload an image', async () => { - image = await testClient.images.createImage({ + image = await testClient.image.createImage({ name: 'test', description: 'test' }); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 6ab174b..3c91967 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/cloudly', - version: '4.5.4', + version: '4.5.5', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' } diff --git a/ts/manager.cluster/classes.clustermanager.ts b/ts/manager.cluster/classes.clustermanager.ts index 5df5ed5..be18c35 100644 --- a/ts/manager.cluster/classes.clustermanager.ts +++ b/ts/manager.cluster/classes.clustermanager.ts @@ -38,12 +38,12 @@ export class ClusterManager { console.log(await cluster.createSavableObject()); this.cloudlyRef.serverManager.ensureServerInfrastructure(); return { - clusterConfig: await cluster.createSavableObject(), + cluster: await cluster.createSavableObject(), }; }), ); - this.typedrouter.addTypedHandler( + this.typedrouter.addTypedHandler( new plugins.typedrequest.TypedHandler('getAllClusters', async (dataArg) => { // TODO: do authentication here const clusters = await this.getAllClusters(); @@ -56,7 +56,7 @@ export class ClusterManager { ); // delete cluster - this.typedrouter.addTypedHandler( + this.typedrouter.addTypedHandler( new plugins.typedrequest.TypedHandler('deleteCluster', async (reqDataArg, toolsArg) => { await toolsArg.passGuards([this.cloudlyRef.authManager.adminIdentityGuard], reqDataArg); await this.deleteCluster(reqDataArg.clusterId); diff --git a/ts_apiclient/classes.cloudlyapiclient.ts b/ts_apiclient/classes.cloudlyapiclient.ts index ec10180..f108f88 100644 --- a/ts_apiclient/classes.cloudlyapiclient.ts +++ b/ts_apiclient/classes.cloudlyapiclient.ts @@ -156,7 +156,7 @@ export class CloudlyApiClient { return typedResponse.certificate; } - public images = { + public image = { // Images getImageById: async (imageIdArg: string) => { return Image.getImageById(this, imageIdArg); diff --git a/ts_apiclient/classes.cluster.ts b/ts_apiclient/classes.cluster.ts index b5cebea..a2b55e9 100644 --- a/ts_apiclient/classes.cluster.ts +++ b/ts_apiclient/classes.cluster.ts @@ -1,6 +1,84 @@ +import { CloudlyApiClient } from './classes.cloudlyapiclient.js'; import * as plugins from './plugins.js'; -export class Cluster { - public getServers() {} - +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_interfaces/requests/cluster.ts b/ts_interfaces/requests/cluster.ts index daaf91a..357bf8e 100644 --- a/ts_interfaces/requests/cluster.ts +++ b/ts_interfaces/requests/cluster.ts @@ -5,11 +5,11 @@ import * as plugins from '../plugins.js'; /** * get all clusters */ -export interface IRequest_GetAllClusters extends plugins.typedrequestInterfaces.implementsTR< +export interface IReq_Any_Cloudly_GetClusters extends plugins.typedrequestInterfaces.implementsTR< plugins.typedrequestInterfaces.ITypedRequest, - IRequest_GetAllClusters + IReq_Any_Cloudly_GetClusters > { - method: 'getAllClusters'; + method: 'getClusters'; request: { identity: userInterfaces.IIdentity; }; @@ -18,6 +18,21 @@ export interface IRequest_GetAllClusters extends plugins.typedrequestInterfaces. }; } +export interface IReq_Any_Cloudly_GetClusterById +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Any_Cloudly_GetClusterById +> { + method: 'getClusterById'; + request: { + identity: userInterfaces.IIdentity; + clusterId: string; + }; + response: { + cluster: clusterInterfaces.ICluster; + }; +} + export interface IRequest_CreateCluster extends plugins.typedrequestInterfaces.implementsTR< plugins.typedrequestInterfaces.ITypedRequest, IRequest_CreateCluster @@ -28,40 +43,40 @@ export interface IRequest_CreateCluster extends plugins.typedrequestInterfaces.i clusterName: string; }; response: { - clusterConfig: clusterInterfaces.ICluster; + cluster: clusterInterfaces.ICluster; }; } /** * updates a cluster */ -export interface IRequest_UpdateCluster extends plugins.typedrequestInterfaces.implementsTR< +export interface IReq_Any_Cloudly_UpdateCluster extends plugins.typedrequestInterfaces.implementsTR< plugins.typedrequestInterfaces.ITypedRequest, - IRequest_UpdateCluster + IReq_Any_Cloudly_UpdateCluster > { method: 'updateCluster'; request: { identity: userInterfaces.IIdentity; - clusterConfig: clusterInterfaces.ICluster; + clusterData: clusterInterfaces.ICluster['data']; }; response: { - clusterConfig: clusterInterfaces.ICluster; + resultCluster: clusterInterfaces.ICluster; }; } /** * deletes a cluster */ -export interface IRequest_DeleteCluster extends plugins.typedrequestInterfaces.implementsTR< +export interface IReq_Any_Cloudly_DeleteClusterById extends plugins.typedrequestInterfaces.implementsTR< plugins.typedrequestInterfaces.ITypedRequest, - IRequest_DeleteCluster + IReq_Any_Cloudly_DeleteClusterById > { - method: 'deleteCluster'; + method: 'deleteClusterById'; request: { identity: userInterfaces.IIdentity; clusterId: string; }; response: { - success: boolean; + ok: boolean; }; } diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index 6ab174b..3c91967 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/cloudly', - version: '4.5.4', + version: '4.5.5', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' } diff --git a/ts_web/appstate.ts b/ts_web/appstate.ts index a67b6f1..19b2704 100644 --- a/ts_web/appstate.ts +++ b/ts_web/appstate.ts @@ -123,9 +123,9 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { // Clusters const trGetClusters = - new domtools.plugins.typedrequest.TypedRequest( + new domtools.plugins.typedrequest.TypedRequest( '/typedrequest', - 'getAllClusters' + 'getClusters' ); const responseClusters = await trGetClusters.fire({ identity: loginStatePart.getState().identity, @@ -260,7 +260,7 @@ export const addClusterAction = dataState.createAction( currentState = { ...currentState, ...{ - clusters: [...currentState.clusters, response.clusterConfig], + clusters: [...currentState.clusters, response.cluster], }, } return currentState;