@plyaz/core 1.22.9 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/backend/campaign/campaign.controller.d.ts +216 -0
  2. package/dist/backend/campaign/campaign.controller.d.ts.map +1 -0
  3. package/dist/backend/campaign/campaign.module.d.ts +58 -0
  4. package/dist/backend/campaign/campaign.module.d.ts.map +1 -0
  5. package/dist/backend/campaign/index.d.ts +16 -0
  6. package/dist/backend/campaign/index.d.ts.map +1 -0
  7. package/dist/domain/campaign/BackendCampaignDomainService.d.ts +161 -0
  8. package/dist/domain/campaign/BackendCampaignDomainService.d.ts.map +1 -0
  9. package/dist/domain/campaign/FrontendCampaignDomainService.d.ts +165 -0
  10. package/dist/domain/campaign/FrontendCampaignDomainService.d.ts.map +1 -0
  11. package/dist/domain/campaign/index.d.ts +13 -0
  12. package/dist/domain/campaign/index.d.ts.map +1 -0
  13. package/dist/domain/campaign/mappers/CampaignMapper.d.ts +79 -0
  14. package/dist/domain/campaign/mappers/CampaignMapper.d.ts.map +1 -0
  15. package/dist/domain/campaign/validators/CampaignValidator.d.ts +63 -0
  16. package/dist/domain/campaign/validators/CampaignValidator.d.ts.map +1 -0
  17. package/dist/entry-backend.cjs +17 -1
  18. package/dist/entry-backend.cjs.map +1 -1
  19. package/dist/entry-backend.mjs +17 -1
  20. package/dist/entry-backend.mjs.map +1 -1
  21. package/dist/entry-frontend-browser.cjs +7 -1
  22. package/dist/entry-frontend-browser.cjs.map +1 -1
  23. package/dist/entry-frontend-browser.mjs +7 -1
  24. package/dist/entry-frontend-browser.mjs.map +1 -1
  25. package/dist/entry-frontend.cjs +7 -1
  26. package/dist/entry-frontend.cjs.map +1 -1
  27. package/dist/entry-frontend.mjs +7 -1
  28. package/dist/entry-frontend.mjs.map +1 -1
  29. package/dist/frontend/campaign/index.d.ts +5 -0
  30. package/dist/frontend/campaign/index.d.ts.map +1 -0
  31. package/dist/frontend/campaign/useCampaign.d.ts +124 -0
  32. package/dist/frontend/campaign/useCampaign.d.ts.map +1 -0
  33. package/dist/frontend/providers/PlyazProvider.d.ts.map +1 -1
  34. package/dist/index.cjs +24 -2
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.mjs +24 -2
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/models/campaign/CampaignRepository.d.ts +94 -0
  39. package/dist/models/campaign/CampaignRepository.d.ts.map +1 -0
  40. package/dist/models/campaign/index.d.ts +11 -0
  41. package/dist/models/campaign/index.d.ts.map +1 -0
  42. package/dist/utils/common/time.d.ts +10 -0
  43. package/dist/utils/common/time.d.ts.map +1 -1
  44. package/dist/utils/index.cjs +17 -1
  45. package/dist/utils/index.cjs.map +1 -1
  46. package/dist/utils/index.mjs +17 -1
  47. package/dist/utils/index.mjs.map +1 -1
  48. package/package.json +4 -3
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Campaign Controller
3
+ *
4
+ * NestJS controller demonstrating Core + BackendCampaignDomainService integration.
5
+ *
6
+ * @fileoverview Campaign REST API controller providing CRUD operations for campaigns
7
+ * @module CampaignController
8
+ */
9
+ import { BackendCampaignDomainService } from '../../domain/campaign';
10
+ import type { CampaignEntity, CreateCampaignDTO, PatchCampaignDTO } from '@plyaz/types/campaign';
11
+ import type { ReturnResponseType } from '@plyaz/types/errors';
12
+ /**
13
+ * Injection token for BackendCampaignDomainService
14
+ * @constant {string}
15
+ */
16
+ export declare const BACKEND_CAMPAIGN_DOMAIN_SERVICE = "BACKEND_CAMPAIGN_DOMAIN_SERVICE";
17
+ /**
18
+ * Campaign Controller
19
+ *
20
+ * Provides REST API endpoints for campaign management operations.
21
+ * All endpoints return standardized response format using SuccessResponseStandard.
22
+ *
23
+ * @class CampaignController
24
+ * @decorator @Controller('campaign')
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Usage in app.module.ts
29
+ * import { CampaignModule } from '@plyaz/core';
30
+ *
31
+ * @Module({
32
+ * imports: [CampaignModule],
33
+ * })
34
+ * export class AppModule {}
35
+ * ```
36
+ *
37
+ * Routes:
38
+ * - GET /campaign/health - Health check
39
+ * - GET /campaign/entities/:id - Get campaign by ID
40
+ * - POST /campaign/entities - Create campaign
41
+ * - PATCH /campaign/entities/:id - Update campaign
42
+ * - DELETE /campaign/entities/:id - Delete campaign
43
+ */
44
+ export declare class CampaignController {
45
+ private readonly campaignService;
46
+ /**
47
+ * Creates an instance of CampaignController
48
+ *
49
+ * @param {BackendCampaignDomainService} campaignService - Injected campaign domain service
50
+ */
51
+ constructor(campaignService: BackendCampaignDomainService);
52
+ /**
53
+ * Health check endpoint
54
+ *
55
+ * @method GET
56
+ * @route /campaign/health
57
+ * @returns {ReturnResponseType<{service: boolean, timestamp: string}>} Service health status
58
+ *
59
+ * @example
60
+ * ```http
61
+ * GET /campaign/health
62
+ * ```
63
+ *
64
+ * @example Response
65
+ * ```json
66
+ * {
67
+ * "success": true,
68
+ * "message": "Service is healthy",
69
+ * "data": {
70
+ * "service": true,
71
+ * "timestamp": "2024-01-01T00:00:00.000Z"
72
+ * }
73
+ * }
74
+ * ```
75
+ */
76
+ health(): ReturnResponseType<{
77
+ service: boolean;
78
+ timestamp: string;
79
+ }>;
80
+ /**
81
+ * Get campaign by ID
82
+ *
83
+ * @method GET
84
+ * @route /campaign/entities/:id
85
+ * @param {string} id - Campaign ID
86
+ * @returns {Promise<ReturnResponseType<CampaignEntity | null>>} Campaign entity or null if not found
87
+ * @throws {ValidationError} When ID format is invalid
88
+ * @throws {NotFoundError} When campaign doesn't exist
89
+ *
90
+ * @example
91
+ * ```http
92
+ * GET /campaign/entities/campaign-123
93
+ * ```
94
+ *
95
+ * @example Response
96
+ * ```json
97
+ * {
98
+ * "success": true,
99
+ * "message": "Campaign retrieved successfully",
100
+ * "data": {
101
+ * "id": "campaign-123",
102
+ * "name": "Summer Sale",
103
+ * "description": "Summer promotional campaign",
104
+ * "amount": 50000,
105
+ * "status": "active"
106
+ * }
107
+ * }
108
+ * ```
109
+ */
110
+ getCampaignById(id: string): Promise<ReturnResponseType<CampaignEntity | null>>;
111
+ /**
112
+ * Create a new campaign
113
+ *
114
+ * @method POST
115
+ * @route /campaign/entities
116
+ * @param {CreateCampaignDTO} dto - Campaign creation data
117
+ * @returns {Promise<ReturnResponseType<CampaignEntity>>} Created campaign entity
118
+ * @throws {ValidationError[]} When validation fails
119
+ * @throws {ConflictError} When campaign with same name exists
120
+ *
121
+ * @example
122
+ * ```http
123
+ * POST /campaign/entities
124
+ * Content-Type: application/json
125
+ *
126
+ * {
127
+ * "name": "Winter Sale",
128
+ * "description": "Winter promotional campaign",
129
+ * "amount": 75000,
130
+ * "is_visible": true
131
+ * }
132
+ * ```
133
+ *
134
+ * @example Response
135
+ * ```json
136
+ * {
137
+ * "success": true,
138
+ * "message": "Campaign created successfully",
139
+ * "data": {
140
+ * "id": "campaign-456",
141
+ * "name": "Winter Sale",
142
+ * "description": "Winter promotional campaign",
143
+ * "amount": 75000,
144
+ * "status": "draft",
145
+ * "createdAt": "2024-01-01T00:00:00.000Z"
146
+ * },
147
+ * "codeStatus": 201
148
+ * }
149
+ * ```
150
+ */
151
+ createCampaign(dto: CreateCampaignDTO): Promise<ReturnResponseType<CampaignEntity>>;
152
+ /**
153
+ * Update a campaign (partial update)
154
+ *
155
+ * @method PATCH
156
+ * @route /campaign/entities/:id
157
+ * @param {string} id - Campaign ID to update
158
+ * @param {PatchCampaignDTO} dto - Partial campaign update data
159
+ * @returns {Promise<ReturnResponseType<CampaignEntity>>} Updated campaign entity
160
+ * @throws {ValidationError[]} When validation fails
161
+ * @throws {NotFoundError} When campaign doesn't exist
162
+ *
163
+ * @example
164
+ * ```http
165
+ * PATCH /campaign/entities/campaign-123
166
+ * Content-Type: application/json
167
+ *
168
+ * {
169
+ * "amount": 60000,
170
+ * "status": "active"
171
+ * }
172
+ * ```
173
+ *
174
+ * @example Response
175
+ * ```json
176
+ * {
177
+ * "success": true,
178
+ * "message": "Campaign updated successfully",
179
+ * "data": {
180
+ * "id": "campaign-123",
181
+ * "name": "Summer Sale",
182
+ * "amount": 60000,
183
+ * "status": "active",
184
+ * "updatedAt": "2024-01-01T00:00:00.000Z"
185
+ * }
186
+ * }
187
+ * ```
188
+ */
189
+ updateCampaign(id: string, dto: PatchCampaignDTO): Promise<ReturnResponseType<CampaignEntity>>;
190
+ /**
191
+ * Delete a campaign
192
+ *
193
+ * @method DELETE
194
+ * @route /campaign/entities/:id
195
+ * @param {string} id - Campaign ID to delete
196
+ * @returns {Promise<ReturnResponseType<null>>} Null on successful deletion
197
+ * @throws {NotFoundError} When campaign doesn't exist
198
+ * @throws {ConflictError} When campaign cannot be deleted (e.g., has dependencies)
199
+ *
200
+ * @example
201
+ * ```http
202
+ * DELETE /campaign/entities/campaign-123
203
+ * ```
204
+ *
205
+ * @example Response
206
+ * ```json
207
+ * {
208
+ * "success": true,
209
+ * "message": "Campaign deleted successfully",
210
+ * "data": null
211
+ * }
212
+ * ```
213
+ */
214
+ deleteCampaign(id: string): Promise<ReturnResponseType<null>>;
215
+ }
216
+ //# sourceMappingURL=campaign.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"campaign.controller.d.ts","sourceRoot":"","sources":["../../../src/backend/campaign/campaign.controller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9D;;;GAGG;AACH,eAAO,MAAM,+BAA+B,oCAAoC,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBACa,kBAAkB;IAQ3B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAPlC;;;;OAIG;gBAGgB,eAAe,EAAE,4BAA4B;IAGhE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAEH,MAAM,IAAI,kBAAkB,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAOrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IAEG,eAAe,CACN,EAAE,EAAE,MAAM,GACtB,OAAO,CAAC,kBAAkB,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAKrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IAGG,cAAc,CACV,GAAG,EAAE,iBAAiB,GAC7B,OAAO,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;IAK9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IAEG,cAAc,CACL,EAAE,EAAE,MAAM,EACf,GAAG,EAAE,gBAAgB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;IAK9C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAGG,cAAc,CAAc,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;CAIjF"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Campaign Module
3
+ *
4
+ * NestJS module demonstrating the proper pattern using domain service directly:
5
+ * Module → Controller → BackendCampaignService
6
+ *
7
+ * @fileoverview Campaign NestJS module configuration
8
+ * @module CampaignModule
9
+ */
10
+ import { BACKEND_CAMPAIGN_DOMAIN_SERVICE } from './campaign.controller';
11
+ import { BackendCampaignDomainService } from '../../domain/campaign';
12
+ /**
13
+ * Campaign Module
14
+ *
15
+ * Configures the campaign feature module with controller and domain service.
16
+ * Uses factory pattern to provide singleton instance of BackendCampaignDomainService.
17
+ *
18
+ * @class CampaignModule
19
+ * @decorator @Module
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Usage in app.module.ts
24
+ * import { CoreModule } from '@plyaz/core/nestjs';
25
+ * import { CampaignModule } from '@plyaz/core';
26
+ *
27
+ * @Module({
28
+ * imports: [
29
+ * CoreModule.forRoot({ envPath: '.env' }),
30
+ * CampaignModule,
31
+ * ],
32
+ * })
33
+ * export class AppModule {}
34
+ * ```
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Direct service injection in other modules
39
+ * import { BACKEND_CAMPAIGN_DOMAIN_SERVICE } from '@plyaz/core';
40
+ *
41
+ * @Injectable()
42
+ * export class SomeService {
43
+ * constructor(
44
+ * @Inject(BACKEND_CAMPAIGN_DOMAIN_SERVICE)
45
+ * private campaignService: BackendCampaignDomainService
46
+ * ) {}
47
+ * }
48
+ * ```
49
+ */
50
+ export declare class CampaignModule {
51
+ }
52
+ /**
53
+ * Re-exported for convenience
54
+ * @see {BackendCampaignDomainService}
55
+ * @see {BACKEND_CAMPAIGN_DOMAIN_SERVICE}
56
+ */
57
+ export { BackendCampaignDomainService, BACKEND_CAMPAIGN_DOMAIN_SERVICE };
58
+ //# sourceMappingURL=campaign.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"campaign.module.d.ts","sourceRoot":"","sources":["../../../src/backend/campaign/campaign.module.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAsB,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,4BAA4B,EAAgC,MAAM,uBAAuB,CAAC;AAEnG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAiBa,cAAc;CAAG;AAE9B;;;;GAIG;AACH,OAAO,EAAE,4BAA4B,EAAE,+BAA+B,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Campaign Module Exports
3
+ *
4
+ * Pattern: Module → Controller → BackendCampaignDomainService (from domain)
5
+ *
6
+ * @fileoverview Campaign backend module entry point
7
+ * @module CampaignBackend
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { CampaignModule, CampaignController } from '@plyaz/core/backend/campaign';
12
+ * ```
13
+ */
14
+ export { CampaignModule, BACKEND_CAMPAIGN_DOMAIN_SERVICE, BackendCampaignDomainService, } from './campaign.module';
15
+ export { CampaignController } from './campaign.controller';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backend/campaign/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,cAAc,EACd,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Backend Campaign Domain Service
3
+ *
4
+ * Demonstrates extending BaseBackendDomainService which provides:
5
+ * - Automatic validation → mapper → repository/API → mapper flow
6
+ * - Event emission throughout CRUD lifecycle
7
+ * - Dual mode: Repository (DbService/dummy) OR HTTP API
8
+ * - Configurable error throwing behavior
9
+ *
10
+ * @fileoverview Campaign domain service for backend operations
11
+ * @module BackendCampaignDomainService
12
+ */
13
+ import { BaseBackendDomainService } from '../base';
14
+ import type { CampaignEntity, CampaignResponseDTO, CreateCampaignDTO, PatchCampaignDTO, QueryCampaignDTO, DeleteCampaignDTO, CampaignStoreItem, CampaignDomainServiceConfig as _CampaignDomainServiceConfig } from '@plyaz/types/campaign';
15
+ import type { CoreServiceCreateOptions, CoreInjectedServices } from '@plyaz/types/core';
16
+ import { CampaignRepository, type CampaignDatabaseRow } from '../../models/campaign';
17
+ import { CampaignMapperClass } from './mappers/CampaignMapper';
18
+ import { CampaignValidatorClass } from './validators/CampaignValidator';
19
+ /**
20
+ * Mapper type for this service
21
+ * @typedef {InstanceType<typeof CampaignMapperClass>} CampaignMapper
22
+ */
23
+ type CampaignMapper = InstanceType<typeof CampaignMapperClass>;
24
+ /**
25
+ * Validator type for this service
26
+ * @typedef {InstanceType<typeof CampaignValidatorClass>} CampaignValidator
27
+ */
28
+ type CampaignValidator = InstanceType<typeof CampaignValidatorClass>;
29
+ /**
30
+ * Campaign event types for subscription
31
+ * @typedef {string} CampaignEventType
32
+ */
33
+ export type CampaignEventType = 'campaign:creating' | 'campaign:created' | 'campaign:updating' | 'campaign:updated' | 'campaign:deleting' | 'campaign:deleted';
34
+ /**
35
+ * Backend Campaign Domain Service
36
+ *
37
+ * Extends BaseBackendDomainService with campaign-specific functionality.
38
+ * Provides CRUD operations, validation, mapping, and event emission.
39
+ *
40
+ * @class BackendCampaignDomainService
41
+ * @extends {BaseBackendDomainService}
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Create service instance
46
+ * const service = await BackendCampaignDomainService.create({
47
+ * throwOnValidationError: true,
48
+ * throwOnRepositoryError: true,
49
+ * });
50
+ *
51
+ * // Use inherited CRUD methods
52
+ * const campaign = await service.create({ name: 'Test Campaign', amount: 100 });
53
+ * const updated = await service.patch(campaign.id, { amount: 200 });
54
+ * await service.delete(campaign.id, { soft: true });
55
+ * ```
56
+ */
57
+ export declare class BackendCampaignDomainService extends BaseBackendDomainService<_CampaignDomainServiceConfig, CampaignEntity, CampaignResponseDTO, CreateCampaignDTO, CreateCampaignDTO, PatchCampaignDTO, QueryCampaignDTO, DeleteCampaignDTO, CampaignDatabaseRow, CampaignRepository, CampaignStoreItem, CampaignMapper, CampaignValidator> {
58
+ /**
59
+ * Repository instance for data access
60
+ * @protected
61
+ * @type {CampaignRepository}
62
+ */
63
+ protected repository: CampaignRepository;
64
+ /**
65
+ * Event prefix for all events emitted by this service
66
+ * @protected
67
+ * @type {string}
68
+ */
69
+ protected eventPrefix: string;
70
+ /**
71
+ * Cache prefix for namespacing cache keys
72
+ * @protected
73
+ * @type {string}
74
+ */
75
+ protected cachePrefix: string;
76
+ /**
77
+ * Unique key for this service (used by ServiceRegistry)
78
+ * @static
79
+ * @readonly
80
+ * @type {string}
81
+ */
82
+ static readonly serviceKey: "campaign";
83
+ /**
84
+ * Factory method for ServiceRegistry auto-initialization.
85
+ * Creates and initializes the service instance.
86
+ *
87
+ * @static
88
+ * @param {_CampaignDomainServiceConfig} config - Service configuration
89
+ * @param {CoreServiceCreateOptions} [options] - Global options from the registry
90
+ * @returns {Promise<BackendCampaignDomainService>} Promise resolving to initialized service instance
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const service = await BackendCampaignDomainService.create({
95
+ * enabled: true,
96
+ * throwOnValidationError: true,
97
+ * cache: { enabled: true, defaultTtl: 300 }
98
+ * });
99
+ * ```
100
+ */
101
+ static create(config: _CampaignDomainServiceConfig, options?: CoreServiceCreateOptions): Promise<BackendCampaignDomainService>;
102
+ /**
103
+ * Creates an instance of BackendCampaignDomainService
104
+ *
105
+ * @param {_CampaignDomainServiceConfig} [config={}] - Service configuration
106
+ * @param {CoreInjectedServices} [injected] - Injected core services
107
+ */
108
+ constructor(config?: _CampaignDomainServiceConfig, injected?: CoreInjectedServices);
109
+ /**
110
+ * Check if service is available
111
+ *
112
+ * @returns {boolean} True if service is enabled and available
113
+ */
114
+ isAvailable(): boolean;
115
+ /**
116
+ * Dispose/cleanup the service
117
+ * Called when service is being destroyed
118
+ */
119
+ dispose(): void;
120
+ /**
121
+ * Get all campaigns with optional filters
122
+ * Demonstrates the getAll() method with typed query parameters
123
+ *
124
+ * @param {QueryCampaignDTO} [filters] - Optional query filters (status, pagination, sorting)
125
+ * @returns {Promise<CampaignEntity[]>} Promise resolving to array of CampaignEntity
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Get all active campaigns
130
+ * const activeCampaigns = await service.getCampaigns({ status: 'active' });
131
+ *
132
+ * // Get campaigns with pagination
133
+ * const campaigns = await service.getCampaigns({
134
+ * page: 2,
135
+ * limit: 10,
136
+ * sort_by: 'name',
137
+ * sort_order: 'asc'
138
+ * });
139
+ * ```
140
+ */
141
+ getCampaigns(filters?: QueryCampaignDTO): Promise<CampaignEntity[]>;
142
+ }
143
+ /**
144
+ * Default singleton instance of BackendCampaignDomainService
145
+ * Use this for singleton pattern usage
146
+ *
147
+ * @constant {BackendCampaignDomainService}
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { backendCampaignDomainService } from '@plyaz/core';
152
+ *
153
+ * const campaign = await backendCampaignDomainService.create({
154
+ * name: 'Test Campaign',
155
+ * amount: 100
156
+ * });
157
+ * ```
158
+ */
159
+ export declare const backendCampaignDomainService: BackendCampaignDomainService;
160
+ export {};
161
+ //# sourceMappingURL=BackendCampaignDomainService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackendCampaignDomainService.d.ts","sourceRoot":"","sources":["../../../src/domain/campaign/BackendCampaignDomainService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,2BAA2B,IAAI,4BAA4B,EAC5D,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;GAGG;AACH,KAAK,cAAc,GAAG,YAAY,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE/D;;;GAGG;AACH,KAAK,iBAAiB,GAAG,YAAY,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,mBAAmB,GACnB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,4BAA6B,SAAQ,wBAAwB,CACxE,4BAA4B,EAC5B,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,CAClB;IACC;;;;OAIG;IACH,SAAS,CAAC,UAAU,EAAE,kBAAkB,CAAC;IAEzC;;;;OAIG;IACH,SAAS,CAAC,WAAW,SAAc;IAEnC;;;;OAIG;IACH,SAAS,CAAC,WAAW,SAAc;IAEnC;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,aAAyB;IAEnD;;;;;;;;;;;;;;;;;OAiBG;WAEU,MAAM,CACjB,MAAM,EAAE,4BAA4B,EACpC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,4BAA4B,CAAC;IAYxC;;;;;OAKG;gBACS,MAAM,GAAE,4BAAiC,EAAE,QAAQ,CAAC,EAAE,oBAAoB;IAyBtF;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CAG1E;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,4BAA4B,8BAAqC,CAAC"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Campaign Frontend Service
3
+ *
4
+ * Demonstrates extending BaseFrontendDomainService which provides:
5
+ * - Automatic CRUD operations (fetchAll, fetchById, create, update, delete)
6
+ * - Store integration (Zustand-compatible)
7
+ * - Error handling with @plyaz/errors
8
+ * - Event emission and subscription
9
+ * - Loading/error state management
10
+ * - Automatic DTO validation and mapping via validator and mapper
11
+ *
12
+ * This service only needs to:
13
+ * - Set eventPrefix for event emission
14
+ * - Add any custom domain methods (e.g., polling)
15
+ * - Override lifecycle hooks if needed
16
+ *
17
+ * All standard CRUD operations are inherited:
18
+ * - fetchAll(query?) - Inherited from BaseFrontendDomainService
19
+ * - fetchById(id) - Inherited from BaseFrontendDomainService
20
+ * - create(data) - Inherited from BaseFrontendDomainService
21
+ * - update(id, data) - Inherited from BaseFrontendDomainService
22
+ * - delete(id) - Inherited from BaseFrontendDomainService
23
+ *
24
+ * Runtime: Frontend only (Browser/React/Next.js)
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * // Service automatically gets stores via ServiceRegistry injection
29
+ * const service = await ServiceRegistry.getAsync<FrontendCampaignDomainService>('campaign');
30
+ *
31
+ * // Or create directly (stores injected if configured)
32
+ * const service = new FrontendCampaignDomainService({
33
+ * enabled: true,
34
+ * apiBasePath: '/api/campaigns',
35
+ * });
36
+ *
37
+ * // Use inherited CRUD methods
38
+ * const items = await service.fetchAll();
39
+ * const activeItems = await service.fetchAll({ status: 'ACTIVE' });
40
+ * const item = await service.create({ title: 'Test', funding_target: 100 });
41
+ * const updated = await service.update(item.id, { funding_target: 200 });
42
+ * await service.delete(item.id);
43
+ * ```
44
+ */
45
+ import { type CampaignEntity, type CampaignResponseDTO, type CreateCampaignDTO, type PatchCampaignDTO, type QueryCampaignDTO, type CampaignStoreItem } from '@plyaz/types/campaign';
46
+ import { BaseFrontendDomainService } from '../base/BaseFrontendDomainService';
47
+ import { CampaignMapperClass } from './mappers/CampaignMapper';
48
+ export type { CampaignFrontendStoreData, CampaignFrontendStoreSlice, CampaignFrontendServiceConfig, CampaignFrontendEventType, } from '@plyaz/types/campaign';
49
+ import type { CampaignFrontendStoreData, CampaignFrontendStoreSlice, CampaignFrontendServiceConfig as _CampaignFrontendServiceConfig, CampaignFrontendEventType } from '@plyaz/types/campaign';
50
+ import type { CoreServiceCreateOptions } from '@plyaz/types/core';
51
+ import type { CoreBaseValidatorInstance } from '@plyaz/types/core';
52
+ /**
53
+ * Campaign Frontend Service
54
+ *
55
+ * Extends BaseFrontendDomainService with all generic types:
56
+ * - TConfig: CampaignFrontendServiceConfig
57
+ * - TStore: CampaignFrontendStoreSlice
58
+ * - TData: CampaignFrontendStoreData
59
+ * - TEntity: CampaignEntity
60
+ * - TResponseDTO: CampaignResponseDTO
61
+ * - TCreateDTO: CreateCampaignDTO
62
+ * - TPatchDTO: PatchCampaignDTO
63
+ * - TQueryDTO: QueryCampaignDTO
64
+ * - TStoreState: CampaignStoreItem
65
+ * - TMapper: CampaignMapper
66
+ *
67
+ * All CRUD methods are inherited from base class - no need to implement!
68
+ */
69
+ export declare class FrontendCampaignDomainService extends BaseFrontendDomainService<_CampaignFrontendServiceConfig, CampaignFrontendStoreSlice, CampaignFrontendStoreData, CampaignEntity, CampaignResponseDTO, CreateCampaignDTO, PatchCampaignDTO, QueryCampaignDTO, CampaignStoreItem, InstanceType<typeof CampaignMapperClass>, CoreBaseValidatorInstance, void> {
70
+ /**
71
+ * Event prefix for all events emitted by this service
72
+ * Required by BaseFrontendDomainService
73
+ */
74
+ protected eventPrefix: string;
75
+ /**
76
+ * Read-only store keys - inherits error and featureFlags from base
77
+ * No need to redeclare them - they're always included by default
78
+ */
79
+ static readonly serviceKey: "campaign-frontend";
80
+ /**
81
+ * Primary store key for this service.
82
+ * Used by ServiceRegistry to auto-inject the store if not specified in config.
83
+ * Also used by base class constructor to set instance primaryStoreKey.
84
+ */
85
+ static readonly primaryStoreKey: "campaign";
86
+ /**
87
+ * Factory method for ServiceRegistry auto-initialization.
88
+ * Creates and initializes the service instance.
89
+ */
90
+ static create(config: _CampaignFrontendServiceConfig, options?: CoreServiceCreateOptions): Promise<FrontendCampaignDomainService>;
91
+ constructor(config?: _CampaignFrontendServiceConfig, options?: CoreServiceCreateOptions);
92
+ /**
93
+ * After fetchAll - emit event (store sync handled automatically)
94
+ * Note: Base class automatically calls syncToStores() which uses storeHandlers
95
+ */
96
+ protected afterFetchAll(entities: CampaignEntity[]): Promise<void>;
97
+ /**
98
+ * Subscribe to service events
99
+ *
100
+ * @example
101
+ * ```tsx
102
+ * const unsubscribe = service.on('campaign:created', (data) => {
103
+ * console.log('Campaign created:', data.entity);
104
+ * });
105
+ *
106
+ * // Later: cleanup
107
+ * unsubscribe();
108
+ * ```
109
+ */
110
+ on(event: CampaignFrontendEventType, handler: (data: unknown) => void): () => void;
111
+ /**
112
+ * Demo: Fetch all campaigns with optional filters
113
+ * Demonstrates the fetchAll() method with typed query parameters
114
+ *
115
+ * @param filters - Optional query filters (status, pagination, sorting)
116
+ * @returns Promise resolving to array of CampaignEntity
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Fetch all active campaigns
121
+ * const activeCampaigns = await service.getCampaigns({ status: 'ACTIVE' });
122
+ *
123
+ * // Fetch campaigns with pagination
124
+ * const pagedCampaigns = await service.getCampaigns({
125
+ * page: 2,
126
+ * limit: 10
127
+ * });
128
+ *
129
+ * // Fetch campaigns sorted by funding target
130
+ * const sortedCampaigns = await service.getCampaigns({
131
+ * sort_by: 'funding_target',
132
+ * sort_order: 'desc'
133
+ * });
134
+ * ```
135
+ */
136
+ getCampaigns(filters?: QueryCampaignDTO): Promise<CampaignEntity[]>;
137
+ /**
138
+ * Demo: Fetch active campaigns only
139
+ * Convenience method demonstrating filtering
140
+ */
141
+ getActiveCampaigns(): Promise<CampaignEntity[]>;
142
+ /**
143
+ * Demo: Fetch draft campaigns only
144
+ * Convenience method demonstrating filtering
145
+ */
146
+ getDraftCampaigns(): Promise<CampaignEntity[]>;
147
+ /**
148
+ * Demo: Fetch completed campaigns only
149
+ * Convenience method demonstrating filtering
150
+ */
151
+ getCompletedCampaigns(): Promise<CampaignEntity[]>;
152
+ }
153
+ /**
154
+ * Default instance of FrontendCampaignDomainService
155
+ * Use this for singleton pattern usage
156
+ *
157
+ * @example
158
+ * ```tsx
159
+ * import { frontendCampaignDomainService } from '@plyaz/core';
160
+ *
161
+ * const campaigns = await frontendCampaignDomainService.fetchAll();
162
+ * ```
163
+ */
164
+ export declare const frontendCampaignDomainService: FrontendCampaignDomainService;
165
+ //# sourceMappingURL=FrontendCampaignDomainService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FrontendCampaignDomainService.d.ts","sourceRoot":"","sources":["../../../src/domain/campaign/FrontendCampaignDomainService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAS/D,YAAY,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,6BAA6B,EAC7B,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,6BAA6B,IAAI,8BAA8B,EAC/D,yBAAyB,EAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAOnE;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,6BAA8B,SAAQ,yBAAyB,CAC1E,8BAA8B,EAC9B,0BAA0B,EAC1B,yBAAyB,EACzB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,CAAC,OAAO,mBAAmB,CAAC,EACxC,yBAAyB,EACzB,IAAI,CACL;IAKC;;;OAGG;IACH,SAAS,CAAC,WAAW,SAAc;IAEnC;;;OAGG;IAOH,MAAM,CAAC,QAAQ,CAAC,UAAU,sBAAkC;IAE5D;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,eAAe,aAAuB;IAEtD;;;OAGG;WACU,MAAM,CACjB,MAAM,EAAE,8BAA8B,EACtC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,6BAA6B,CAAC;gBAuB7B,MAAM,GAAE,8BAAmC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAmG3F;;;OAGG;cACsB,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjF;;;;;;;;;;;;OAYG;IACH,EAAE,CAAC,KAAK,EAAE,yBAAyB,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI;IASlF;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAIzE;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAIrD;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAIpD;;;OAGG;IACG,qBAAqB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;CAGzD;AAiBD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,6BAA6B,+BAAsC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Campaign Domain Exports
3
+ *
4
+ * Types and schemas should be imported from @plyaz/types/campaign
5
+ *
6
+ * @fileoverview Campaign domain service exports
7
+ * @module CampaignDomain
8
+ */
9
+ export { BackendCampaignDomainService, backendCampaignDomainService, type CampaignEventType, } from './BackendCampaignDomainService';
10
+ export { FrontendCampaignDomainService, frontendCampaignDomainService, type CampaignFrontendStoreSlice, type CampaignFrontendStoreData, type CampaignFrontendServiceConfig, type CampaignFrontendEventType, } from './FrontendCampaignDomainService';
11
+ export { CampaignMapper } from './mappers/CampaignMapper';
12
+ export { CampaignValidator } from './validators/CampaignValidator';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/campaign/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,KAAK,iBAAiB,GACvB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,GAC/B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC"}