/** * Example 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('example'); * * // Or create directly (stores injected if configured) * const service = new FrontendExampleDomainService({ * enabled: true, * apiBasePath: '/api/examples', * }); * * // Use inherited CRUD methods * const items = await service.fetchAll(); * const activeItems = await service.fetchAll({ status: 'active' }); * const item = await service.create({ name: 'Test', amount: 100 }); * const updated = await service.update(item.id, { amount: 200 }); * await service.delete(item.id); * ``` */ import type { ExampleEntity, ExampleResponseDTO, CreateExampleDTO, PatchExampleDTO, QueryExampleDTO, ExampleStoreItem, ExampleSendEmailResult } from '@plyaz/types/examples'; import { BaseFrontendDomainService } from '../base/BaseFrontendDomainService'; import { ExampleMapperClass } from './mappers/ExampleMapper'; export type { ExampleFrontendStoreData, ExampleFrontendStoreSlice, ExampleFrontendServiceConfig, ExampleFrontendEventType, } from '@plyaz/types/examples'; import type { ExampleFrontendStoreData, ExampleFrontendStoreSlice, ExampleFrontendServiceConfig as _ExampleFrontendServiceConfig, ExampleFrontendEventType } from '@plyaz/types/examples'; import type { CoreServiceCreateOptions } from '@plyaz/types/core'; import type { CoreBaseValidatorInstance } from '@plyaz/types/core'; /** * Example Frontend Service * * Extends BaseFrontendDomainService with all generic types: * - TConfig: ExampleFrontendServiceConfig * - TStore: ExampleFrontendStoreSlice * - TData: ExampleFrontendStoreData * - TEntity: ExampleEntity * - TResponseDTO: ExampleResponseDTO * - TCreateDTO: CreateExampleDTO * - TPatchDTO: PatchExampleDTO * - TQueryDTO: QueryExampleDTO * - TStoreState: ExampleStoreItem * - TMapper: ExampleMapper * * All CRUD methods are inherited from base class - no need to implement! */ export declare class FrontendExampleDomainService extends BaseFrontendDomainService<_ExampleFrontendServiceConfig, ExampleFrontendStoreSlice, ExampleFrontendStoreData, ExampleEntity, ExampleResponseDTO, CreateExampleDTO, PatchExampleDTO, QueryExampleDTO, ExampleStoreItem, 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: "example-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: "example"; /** * Factory method for ServiceRegistry auto-initialization. * Creates and initializes the service instance. */ static create(config: _ExampleFrontendServiceConfig, options?: CoreServiceCreateOptions): Promise; constructor(config?: _ExampleFrontendServiceConfig, options?: CoreServiceCreateOptions); /** * After fetchAll - emit event (store sync handled automatically) * Note: Base class automatically calls syncToStores() which uses storeHandlers */ protected afterFetchAll(entities: ExampleEntity[]): Promise; /** * Subscribe to service events * * @example * ```tsx * const unsubscribe = service.on('example:created', (data) => { * console.log('Item created:', data.entity); * }); * * // Later: cleanup * unsubscribe(); * ``` */ on(event: ExampleFrontendEventType, handler: (data: unknown) => void): () => void; /** * Demo: Fetch all examples 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 ExampleEntity * * @example * ```typescript * // Fetch all active examples * const activeExamples = await service.getExamples({ status: 'active' }); * * // Fetch archived examples with pagination * const archivedExamples = await service.getExamples({ * status: 'archived', * page: 2, * limit: 10 * }); * * // Fetch all examples sorted by name * const sortedExamples = await service.getExamples({ * sort_by: 'name', * sort_order: 'asc' * }); * ``` */ getExamples(filters?: QueryExampleDTO): Promise; /** * Demo: Fetch active examples only * Convenience method demonstrating filtering */ getActiveExamples(): Promise; /** * Demo: Fetch draft examples only * Convenience method demonstrating filtering */ getDraftExamples(): Promise; /** * Demo: Fetch archived examples only * Convenience method demonstrating filtering */ getArchivedExamples(): Promise; /** * Send an email via backend API (TEST/DEMO ONLY). * * Calls POST /api/examples/email which uses @plyaz/notifications template engine. * * **NOTE:** In production, email sending should be triggered from the backend * (e.g., after successful order, user signup, etc.), not from the frontend. * This method is included here only for testing the notification system. * * @typeParam TInput - Email parameters type * @typeParam TOptions - Options type (can include endpoint override) * * @param data - Email parameters (to, templateId, templateData, etc.) * @param options - Options (endpoint, etc.) * @returns Promise resolving to send result */ sendEmail(data: TInput, options?: TOptions): Promise; } //# sourceMappingURL=FrontendExampleDomainService.d.ts.map