// Copyright: © 2026 TWWIM UG. All rights reserved. (www.twwim.com) /** * Plugin Settings API * * HTTP methods for the tenant-level widget configuration (visibility + * attention) consumed by the plugin. * * Response and request shapes are identical (`PluginSettingsResponse` === * `UpdatePluginSettingsRequest`), so no domain mapper layer is required — * the UI works with the raw shape from `@archer/api-interface`. * * @layer Infrastructure - API Client */ import { TENANT_PLUGIN_SETTINGS_GET, TENANT_PLUGIN_SETTINGS_UPDATE, } from '@archer/api-interface/endpoints/customer-api'; import type { PluginSettingsResponse, UpdatePluginSettingsRequest, } from '@archer/api-interface'; import { ApiClient, apiClient } from '../../ApiClient'; /** * PluginSettingsApi * * Provides plugin-settings read/replace operations. * PUT semantics are full replacement (not patch). */ export class PluginSettingsApi { constructor(private client: ApiClient) {} /** * Fetches the current plugin widget configuration for a tenant. * * @param tenantId - Tenant ID to fetch settings for. * @returns Current settings. * @throws ApiError on failure. */ async get(tenantId: string): Promise { const path = TENANT_PLUGIN_SETTINGS_GET.path.replace(':tenantId', tenantId); return this.client.get(path); } /** * Replaces the plugin widget configuration for a tenant. * * @param tenantId - Tenant ID to update. * @param dto - Full replacement payload. * @returns The saved settings. * @throws ApiError on failure. */ async update( tenantId: string, dto: UpdatePluginSettingsRequest, ): Promise { const path = TENANT_PLUGIN_SETTINGS_UPDATE.path.replace(':tenantId', tenantId); return this.client.put(path, dto); } } /** * Factory helper — primarily used in tests to inject a custom ApiClient. */ export function createPluginSettingsApi(client: ApiClient): PluginSettingsApi { return new PluginSettingsApi(client); } /** * Default PluginSettingsApi singleton instance. * * Uses the shared `apiClient` with auth token management. */ export const pluginSettingsApi = new PluginSettingsApi(apiClient);