import BaseSDK from '../base-sdk'; import { QelosSDKOptions } from '../types'; import { IPlugin, IEventSubscriber, IMicroFrontend, IPluginCrud, IInjectable, INavbarGroup } from '@qelos/global-types'; // Fields that are typically set by the server or not directly updatable by admin type ServerManagedPluginFields = 'tenant' | 'user' | 'token' | 'auth' | '_id' | 'id' | 'createdAt' | 'updatedAt'; export type IPluginCreateParams = Omit & { // Make optional arrays explicitly optional for creation if they can be omitted subscribedEvents?: Partial[]; microFrontends?: Partial[]; cruds?: Partial[]; injectables?: Partial[]; navBarGroups?: Partial[]; version?: string; // Add version if it's part of creation payload url?: string; // Add url if it's part of creation payload (often same as appUrl) proxyUrl?: string; // Allow setting proxyUrl during creation }; export type IPluginUpdateParams = Partial>; export default class QlManagePlugins extends BaseSDK { private relativePath = '/api/plugins'; // Please confirm/adjust this path constructor(options: QelosSDKOptions) { super(options); } async create(pluginData: IPluginCreateParams): Promise { return this.callJsonApi(this.relativePath, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(pluginData), }); } async update(pluginId: string, pluginData: IPluginUpdateParams): Promise { return this.callJsonApi(`${this.relativePath}/${pluginId}`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(pluginData), }); } async remove(pluginId: string): Promise { // callApi usually doesn't expect a JSON response, so no generic needed for it. // It will throw on non-2xx responses. await this.callApi(`${this.relativePath}/${pluginId}`, { method: 'DELETE' }); } async getList(): Promise { return this.callJsonApi(this.relativePath); } async getById(pluginId: string): Promise { return this.callJsonApi(`${this.relativePath}/${pluginId}`); } }