/** * Campaign Frontend Service * * Demonstrates extending BaseFrontendDomainService which provides: * - Automatic CRUD operations (fetchAll, fetchById, create, update, delete) * - Store integration (Zustand-compatible) * - Error handling with @plyaz/errors * - Event emission and subscription * - Loading/error state management * - Automatic DTO validation and mapping via validator and mapper * * This service only needs to: * - Set eventPrefix for event emission * - Add any custom domain methods (e.g., polling) * - Override lifecycle hooks if needed * * All standard CRUD operations are inherited: * - fetchAll(query?) - Inherited from BaseFrontendDomainService * - fetchById(id) - Inherited from BaseFrontendDomainService * - create(data) - Inherited from BaseFrontendDomainService * - update(id, data) - Inherited from BaseFrontendDomainService * - delete(id) - Inherited from BaseFrontendDomainService * * Runtime: Frontend only (Browser/React/Next.js) * * @example * ```tsx * // Service automatically gets stores via ServiceRegistry injection * const service = await ServiceRegistry.getAsync('campaign'); * * // Or create directly (stores injected if configured) * const service = new FrontendCampaignDomainService({ * enabled: true, * apiBasePath: '/api/campaigns', * }); * * // Use inherited CRUD methods * const items = await service.fetchAll(); * const activeItems = await service.fetchAll({ status: 'ACTIVE' }); * const item = await service.create({ title: 'Test', funding_target: 100 }); * const updated = await service.update(item.id, { funding_target: 200 }); * await service.delete(item.id); * ``` */ import { type CampaignEntity, type CampaignResponseDTO, type CreateCampaignDTO, type PatchCampaignDTO, type QueryCampaignDTO, type CampaignStoreItem } from '@plyaz/types/campaign'; import { BaseFrontendDomainService } from '../base/BaseFrontendDomainService'; import { CampaignMapperClass } from './mappers/CampaignMapper'; export type { CampaignFrontendStoreData, CampaignFrontendStoreSlice, CampaignFrontendServiceConfig, CampaignFrontendEventType, } from '@plyaz/types/campaign'; import type { CampaignFrontendStoreData, CampaignFrontendStoreSlice, CampaignFrontendServiceConfig as _CampaignFrontendServiceConfig, CampaignFrontendEventType } from '@plyaz/types/campaign'; import type { CoreServiceCreateOptions } from '@plyaz/types/core'; import type { CoreBaseValidatorInstance } from '@plyaz/types/core'; /** * Campaign Frontend Service * * Extends BaseFrontendDomainService with all generic types: * - TConfig: CampaignFrontendServiceConfig * - TStore: CampaignFrontendStoreSlice * - TData: CampaignFrontendStoreData * - TEntity: CampaignEntity * - TResponseDTO: CampaignResponseDTO * - TCreateDTO: CreateCampaignDTO * - TPatchDTO: PatchCampaignDTO * - TQueryDTO: QueryCampaignDTO * - TStoreState: CampaignStoreItem * - TMapper: CampaignMapper * * All CRUD methods are inherited from base class - no need to implement! */ export declare class FrontendCampaignDomainService extends BaseFrontendDomainService<_CampaignFrontendServiceConfig, CampaignFrontendStoreSlice, CampaignFrontendStoreData, CampaignEntity, CampaignResponseDTO, CreateCampaignDTO, PatchCampaignDTO, QueryCampaignDTO, CampaignStoreItem, InstanceType, CoreBaseValidatorInstance, void> { /** * Event prefix for all events emitted by this service * Required by BaseFrontendDomainService */ protected eventPrefix: string; /** * Read-only store keys - inherits error and featureFlags from base * No need to redeclare them - they're always included by default */ static readonly serviceKey: "campaign-frontend"; /** * Primary store key for this service. * Used by ServiceRegistry to auto-inject the store if not specified in config. * Also used by base class constructor to set instance primaryStoreKey. */ static readonly primaryStoreKey: "campaign"; /** * Factory method for ServiceRegistry auto-initialization. * Creates and initializes the service instance. */ static create(config: _CampaignFrontendServiceConfig, options?: CoreServiceCreateOptions): Promise; constructor(config?: _CampaignFrontendServiceConfig, options?: CoreServiceCreateOptions); /** * After fetchAll - emit event (store sync handled automatically) * Note: Base class automatically calls syncToStores() which uses storeHandlers */ protected afterFetchAll(entities: CampaignEntity[]): Promise; /** * Subscribe to service events * * @example * ```tsx * const unsubscribe = service.on('campaign:created', (data) => { * console.log('Campaign created:', data.entity); * }); * * // Later: cleanup * unsubscribe(); * ``` */ on(event: CampaignFrontendEventType, handler: (data: unknown) => void): () => void; /** * Demo: Fetch all campaigns with optional filters * Demonstrates the fetchAll() method with typed query parameters * * @param filters - Optional query filters (status, pagination, sorting) * @returns Promise resolving to array of CampaignEntity * * @example * ```typescript * // Fetch all active campaigns * const activeCampaigns = await service.getCampaigns({ status: 'ACTIVE' }); * * // Fetch campaigns with pagination * const pagedCampaigns = await service.getCampaigns({ * page: 2, * limit: 10 * }); * * // Fetch campaigns sorted by funding target * const sortedCampaigns = await service.getCampaigns({ * sort_by: 'funding_target', * sort_order: 'desc' * }); * ``` */ getCampaigns(filters?: QueryCampaignDTO): Promise; /** * Demo: Fetch active campaigns only * Convenience method demonstrating filtering */ getActiveCampaigns(): Promise; /** * Demo: Fetch draft campaigns only * Convenience method demonstrating filtering */ getDraftCampaigns(): Promise; /** * Demo: Fetch completed campaigns only * Convenience method demonstrating filtering */ getCompletedCampaigns(): Promise; } /** * Default instance of FrontendCampaignDomainService * Use this for singleton pattern usage * * @example * ```tsx * import { frontendCampaignDomainService } from '@plyaz/core'; * * const campaigns = await frontendCampaignDomainService.fetchAll(); * ``` */ export declare const frontendCampaignDomainService: FrontendCampaignDomainService; //# sourceMappingURL=FrontendCampaignDomainService.d.ts.map