@plyaz/core 1.1.1 → 1.2.1
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.
- package/dist/adapters/index.d.ts +16 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/nestjs.d.ts +79 -0
- package/dist/adapters/nestjs.d.ts.map +1 -0
- package/dist/adapters/nextjs.d.ts +28 -0
- package/dist/adapters/nextjs.d.ts.map +1 -0
- package/dist/backend/example/example.controller.d.ts +121 -0
- package/dist/backend/example/example.controller.d.ts.map +1 -0
- package/dist/backend/example/example.module.d.ts +29 -0
- package/dist/backend/example/example.module.d.ts.map +1 -0
- package/dist/backend/example/index.d.ts +8 -0
- package/dist/backend/example/index.d.ts.map +1 -0
- package/dist/backend/featureFlags/FeatureFlagDomainService.d.ts +150 -0
- package/dist/backend/featureFlags/FeatureFlagDomainService.d.ts.map +1 -0
- package/dist/backend/featureFlags/config/feature-flag.config.d.ts +89 -0
- package/dist/backend/featureFlags/config/feature-flag.config.d.ts.map +1 -0
- package/dist/backend/featureFlags/config/validation.d.ts +181 -0
- package/dist/backend/featureFlags/config/validation.d.ts.map +1 -0
- package/dist/backend/featureFlags/decorators/feature-disabled.decorator.d.ts +6 -0
- package/dist/backend/featureFlags/decorators/feature-disabled.decorator.d.ts.map +1 -0
- package/dist/backend/featureFlags/decorators/feature-enabled.decorator.d.ts +8 -0
- package/dist/backend/featureFlags/decorators/feature-enabled.decorator.d.ts.map +1 -0
- package/dist/backend/featureFlags/decorators/feature-flag.decorator.d.ts +11 -0
- package/dist/backend/featureFlags/decorators/feature-flag.decorator.d.ts.map +1 -0
- package/dist/backend/featureFlags/feature-flag.controller.d.ts +14 -56
- package/dist/backend/featureFlags/feature-flag.controller.d.ts.map +1 -1
- package/dist/backend/featureFlags/feature-flag.module.d.ts +36 -44
- package/dist/backend/featureFlags/feature-flag.module.d.ts.map +1 -1
- package/dist/backend/featureFlags/guards/feature-flag.guard.d.ts +33 -0
- package/dist/backend/featureFlags/guards/feature-flag.guard.d.ts.map +1 -0
- package/dist/backend/featureFlags/index.d.ts +14 -41
- package/dist/backend/featureFlags/index.d.ts.map +1 -1
- package/dist/backend/featureFlags/interceptors/error-handling-interceptor.d.ts +16 -0
- package/dist/backend/featureFlags/interceptors/error-handling-interceptor.d.ts.map +1 -0
- package/dist/backend/featureFlags/interceptors/feature-flag-logging-interceptor.d.ts +18 -0
- package/dist/backend/featureFlags/interceptors/feature-flag-logging-interceptor.d.ts.map +1 -0
- package/dist/backend/featureFlags/middleware/feature-flag-middleware.d.ts +162 -0
- package/dist/backend/featureFlags/middleware/feature-flag-middleware.d.ts.map +1 -0
- package/dist/backend/index.d.ts +5 -0
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/base/cache/CacheKeyBuilder.d.ts +115 -0
- package/dist/base/cache/CacheKeyBuilder.d.ts.map +1 -0
- package/dist/base/cache/feature/caching.d.ts +16 -0
- package/dist/base/cache/feature/caching.d.ts.map +1 -0
- package/dist/base/cache/index.d.ts +2 -0
- package/dist/base/cache/index.d.ts.map +1 -1
- package/dist/base/cache/strategies/redis.d.ts.map +1 -1
- package/dist/base/observability/BaseAdapter.d.ts +79 -0
- package/dist/base/observability/BaseAdapter.d.ts.map +1 -0
- package/dist/base/observability/CompositeAdapter.d.ts +72 -0
- package/dist/base/observability/CompositeAdapter.d.ts.map +1 -0
- package/dist/base/observability/DatadogAdapter.d.ts +117 -0
- package/dist/base/observability/DatadogAdapter.d.ts.map +1 -0
- package/dist/base/observability/LoggerAdapter.d.ts +54 -0
- package/dist/base/observability/LoggerAdapter.d.ts.map +1 -0
- package/dist/base/observability/ObservabilityService.d.ts +160 -0
- package/dist/base/observability/ObservabilityService.d.ts.map +1 -0
- package/dist/base/observability/index.d.ts +17 -0
- package/dist/base/observability/index.d.ts.map +1 -0
- package/dist/domain/base/BaseBackendDomainService.d.ts +528 -0
- package/dist/domain/base/BaseBackendDomainService.d.ts.map +1 -0
- package/dist/domain/base/BaseDomainService.d.ts +284 -0
- package/dist/domain/base/BaseDomainService.d.ts.map +1 -0
- package/dist/domain/base/BaseFrontendDomainService.d.ts +493 -0
- package/dist/domain/base/BaseFrontendDomainService.d.ts.map +1 -0
- package/dist/domain/base/BaseMapper.d.ts +100 -0
- package/dist/domain/base/BaseMapper.d.ts.map +1 -0
- package/dist/domain/base/BaseValidator.d.ts +105 -0
- package/dist/domain/base/BaseValidator.d.ts.map +1 -0
- package/dist/domain/base/index.d.ts +10 -0
- package/dist/domain/base/index.d.ts.map +1 -0
- package/dist/domain/example/BackendExampleDomainService.d.ts +257 -0
- package/dist/domain/example/BackendExampleDomainService.d.ts.map +1 -0
- package/dist/domain/example/FrontendExampleDomainService.d.ts +164 -0
- package/dist/domain/example/FrontendExampleDomainService.d.ts.map +1 -0
- package/dist/domain/example/index.d.ts +10 -0
- package/dist/domain/example/index.d.ts.map +1 -0
- package/dist/domain/example/mappers/ExampleMapper.d.ts +67 -0
- package/dist/domain/example/mappers/ExampleMapper.d.ts.map +1 -0
- package/dist/domain/example/validators/ExampleValidator.d.ts +33 -0
- package/dist/domain/example/validators/ExampleValidator.d.ts.map +1 -0
- package/dist/domain/featureFlags/FrontendFeatureFlagDomainService.d.ts +86 -0
- package/dist/domain/featureFlags/FrontendFeatureFlagDomainService.d.ts.map +1 -0
- package/dist/domain/featureFlags/index.d.ts +10 -5
- package/dist/domain/featureFlags/index.d.ts.map +1 -1
- package/dist/domain/featureFlags/mappers/FeatureFlagMapper.d.ts +72 -0
- package/dist/domain/featureFlags/mappers/FeatureFlagMapper.d.ts.map +1 -0
- package/dist/domain/featureFlags/mappers/index.d.ts +8 -0
- package/dist/domain/featureFlags/mappers/index.d.ts.map +1 -0
- package/dist/domain/featureFlags/module.d.ts +20 -0
- package/dist/domain/featureFlags/module.d.ts.map +1 -0
- package/dist/domain/featureFlags/provider.d.ts +40 -1
- package/dist/domain/featureFlags/provider.d.ts.map +1 -1
- package/dist/domain/featureFlags/providers/api.d.ts +59 -34
- package/dist/domain/featureFlags/providers/api.d.ts.map +1 -1
- package/dist/domain/featureFlags/providers/database.d.ts +59 -52
- package/dist/domain/featureFlags/providers/database.d.ts.map +1 -1
- package/dist/domain/featureFlags/providers/factory.d.ts +50 -33
- package/dist/domain/featureFlags/providers/factory.d.ts.map +1 -1
- package/dist/domain/featureFlags/providers/file.d.ts +48 -1
- package/dist/domain/featureFlags/providers/file.d.ts.map +1 -1
- package/dist/domain/featureFlags/providers/memory.d.ts +32 -6
- package/dist/domain/featureFlags/providers/memory.d.ts.map +1 -1
- package/dist/domain/featureFlags/providers/redis.d.ts +6 -1
- package/dist/domain/featureFlags/providers/redis.d.ts.map +1 -1
- package/dist/domain/featureFlags/service.d.ts +112 -0
- package/dist/domain/featureFlags/service.d.ts.map +1 -0
- package/dist/domain/index.d.ts +2 -0
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/engine/featureFlags/engine.d.ts +8 -0
- package/dist/engine/featureFlags/engine.d.ts.map +1 -1
- package/dist/entry-backend.d.ts +24 -0
- package/dist/entry-backend.d.ts.map +1 -0
- package/dist/entry-backend.js +15635 -0
- package/dist/entry-backend.js.map +1 -0
- package/dist/entry-backend.mjs +15506 -0
- package/dist/entry-backend.mjs.map +1 -0
- package/dist/entry-frontend.d.ts +23 -0
- package/dist/entry-frontend.d.ts.map +1 -0
- package/dist/entry-frontend.js +11152 -0
- package/dist/entry-frontend.js.map +1 -0
- package/dist/entry-frontend.mjs +11089 -0
- package/dist/entry-frontend.mjs.map +1 -0
- package/dist/events/CoreEventManager.d.ts +116 -0
- package/dist/events/CoreEventManager.d.ts.map +1 -0
- package/dist/events/index.d.ts +27 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/frontend/base/index.d.ts +8 -0
- package/dist/frontend/base/index.d.ts.map +1 -0
- package/dist/frontend/components/InitializationError.d.ts +25 -0
- package/dist/frontend/components/InitializationError.d.ts.map +1 -0
- package/dist/frontend/components/InitializationLoading.d.ts +22 -0
- package/dist/frontend/components/InitializationLoading.d.ts.map +1 -0
- package/dist/frontend/components/index.d.ts +9 -0
- package/dist/frontend/components/index.d.ts.map +1 -0
- package/dist/frontend/example/index.d.ts +9 -0
- package/dist/frontend/example/index.d.ts.map +1 -0
- package/dist/frontend/featureFlags/index.d.ts +28 -7
- package/dist/frontend/featureFlags/index.d.ts.map +1 -1
- package/dist/frontend/index.d.ts +5 -0
- package/dist/frontend/index.d.ts.map +1 -1
- package/dist/frontend/providers/ApiProvider.d.ts +41 -0
- package/dist/frontend/providers/ApiProvider.d.ts.map +1 -0
- package/dist/frontend/providers/PlyazProvider.d.ts +305 -0
- package/dist/frontend/providers/PlyazProvider.d.ts.map +1 -0
- package/dist/frontend/providers/index.d.ts +8 -0
- package/dist/frontend/providers/index.d.ts.map +1 -0
- package/dist/frontend/store/feature-flags.d.ts +63 -0
- package/dist/frontend/store/feature-flags.d.ts.map +1 -0
- package/dist/frontend/store/index.d.ts +14 -0
- package/dist/frontend/store/index.d.ts.map +1 -0
- package/dist/frontend/store/integrations.d.ts +36 -0
- package/dist/frontend/store/integrations.d.ts.map +1 -0
- package/dist/frontend/store/service-accessors.d.ts +78 -0
- package/dist/frontend/store/service-accessors.d.ts.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15450 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +13461 -2440
- package/dist/index.mjs.map +1 -1
- package/dist/init/CoreInitializer.d.ts +582 -0
- package/dist/init/CoreInitializer.d.ts.map +1 -0
- package/dist/init/ServiceRegistry.d.ts +256 -0
- package/dist/init/ServiceRegistry.d.ts.map +1 -0
- package/dist/init/index.d.ts +14 -0
- package/dist/init/index.d.ts.map +1 -0
- package/dist/init/nestjs/CoreModule.d.ts +63 -0
- package/dist/init/nestjs/CoreModule.d.ts.map +1 -0
- package/dist/init/nestjs/index.d.ts +5 -0
- package/dist/init/nestjs/index.d.ts.map +1 -0
- package/dist/init/nestjs/index.js +9059 -0
- package/dist/init/nestjs/index.js.map +1 -0
- package/dist/init/nestjs/index.mjs +9055 -0
- package/dist/init/nestjs/index.mjs.map +1 -0
- package/dist/init/react.d.ts +33 -0
- package/dist/init/react.d.ts.map +1 -0
- package/dist/models/example/ExampleRepository.d.ts +124 -0
- package/dist/models/example/ExampleRepository.d.ts.map +1 -0
- package/dist/models/example/index.d.ts +7 -0
- package/dist/models/example/index.d.ts.map +1 -0
- package/dist/models/featureFlags/FeatureFlagRepository.d.ts +560 -0
- package/dist/models/featureFlags/FeatureFlagRepository.d.ts.map +1 -0
- package/dist/models/featureFlags/index.d.ts +7 -0
- package/dist/models/featureFlags/index.d.ts.map +1 -0
- package/dist/models/index.d.ts +9 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/services/ApiClientService.d.ts +178 -0
- package/dist/services/ApiClientService.d.ts.map +1 -0
- package/dist/services/CacheService.d.ts +176 -0
- package/dist/services/CacheService.d.ts.map +1 -0
- package/dist/services/DbService.d.ts +391 -0
- package/dist/services/DbService.d.ts.map +1 -0
- package/dist/services/NotificationService.d.ts +151 -0
- package/dist/services/NotificationService.d.ts.map +1 -0
- package/dist/services/StorageService.d.ts +144 -0
- package/dist/services/StorageService.d.ts.map +1 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/utils/common/id.d.ts +83 -0
- package/dist/utils/common/id.d.ts.map +1 -0
- package/dist/utils/common/index.d.ts +3 -1
- package/dist/utils/common/index.d.ts.map +1 -1
- package/dist/utils/common/object.d.ts +70 -0
- package/dist/utils/common/object.d.ts.map +1 -0
- package/dist/utils/common/validation.d.ts +20 -0
- package/dist/utils/common/validation.d.ts.map +1 -0
- package/dist/utils/featureFlags/conditions.d.ts.map +1 -1
- package/dist/utils/featureFlags/context.d.ts +0 -1
- package/dist/utils/featureFlags/context.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/mapperUtils.d.ts +38 -0
- package/dist/utils/mapperUtils.d.ts.map +1 -0
- package/dist/utils/runtime.d.ts +15 -0
- package/dist/utils/runtime.d.ts.map +1 -0
- package/dist/version.d.ts +24 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/web_app/auth/add_user.d.ts +3 -0
- package/dist/web_app/auth/add_user.d.ts.map +1 -0
- package/dist/web_app/auth/update_user.d.ts +2 -0
- package/dist/web_app/auth/update_user.d.ts.map +1 -0
- package/package.json +102 -15
- package/dist/backend/featureFlags/feature-flag.repository.d.ts +0 -85
- package/dist/backend/featureFlags/feature-flag.repository.d.ts.map +0 -1
- package/dist/backend/featureFlags/feature-flag.service.d.ts +0 -123
- package/dist/backend/featureFlags/feature-flag.service.d.ts.map +0 -1
- package/dist/frontend/featureFlags/hooks/useFeatureFlag.d.ts +0 -103
- package/dist/frontend/featureFlags/hooks/useFeatureFlag.d.ts.map +0 -1
- package/dist/frontend/featureFlags/hooks/useFeatureFlagActions.d.ts +0 -35
- package/dist/frontend/featureFlags/hooks/useFeatureFlagActions.d.ts.map +0 -1
- package/dist/frontend/featureFlags/hooks/useFeatureFlagHelpers.d.ts +0 -55
- package/dist/frontend/featureFlags/hooks/useFeatureFlagHelpers.d.ts.map +0 -1
- package/dist/frontend/featureFlags/hooks/useFeatureFlagProvider.d.ts +0 -57
- package/dist/frontend/featureFlags/hooks/useFeatureFlagProvider.d.ts.map +0 -1
- package/dist/frontend/featureFlags/providers/FeatureFlagProvider.d.ts +0 -99
- package/dist/frontend/featureFlags/providers/FeatureFlagProvider.d.ts.map +0 -1
- package/dist/frontend/featureFlags/providers/FeatureFlagProviderHelpers.d.ts +0 -31
- package/dist/frontend/featureFlags/providers/FeatureFlagProviderHelpers.d.ts.map +0 -1
- package/dist/frontend/featureFlags/providers/types.d.ts +0 -21
- package/dist/frontend/featureFlags/providers/types.d.ts.map +0 -1
- package/dist/index.cjs +0 -4383
- package/dist/index.cjs.map +0 -1
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DbService - Singleton Database Connection Manager
|
|
3
|
+
*
|
|
4
|
+
* @description Manages database connections for the entire application using a singleton pattern.
|
|
5
|
+
* This service wraps @plyaz/db and provides a centralized way to initialize and access
|
|
6
|
+
* the database across all domains (feature flags, users, campaigns, backoffice, etc.).
|
|
7
|
+
*
|
|
8
|
+
* **Architecture:**
|
|
9
|
+
* - Uses `createDatabaseService()` from @plyaz/db which builds an adapter chain
|
|
10
|
+
* - Supports Drizzle (direct PostgreSQL), Supabase (REST API), or raw SQL adapters
|
|
11
|
+
* - Extension layers: Encryption → SoftDelete → Caching → Audit → ReadReplica
|
|
12
|
+
*
|
|
13
|
+
* **Adapter Configuration:**
|
|
14
|
+
* - **Drizzle**: Requires `connectionString` (PostgreSQL URL)
|
|
15
|
+
* - **Supabase**: Requires `supabaseUrl`, `supabaseServiceKey`, `supabaseAnonKey`
|
|
16
|
+
* - **SQL**: Requires `connectionString`
|
|
17
|
+
*
|
|
18
|
+
* **Required Environment Variables (Drizzle with Supabase):**
|
|
19
|
+
* - DATABASE_URL: PostgreSQL connection string (from Supabase Dashboard > Database > URI)
|
|
20
|
+
*
|
|
21
|
+
* **Required Environment Variables (Supabase REST API):**
|
|
22
|
+
* - SUPABASE_URL: Your Supabase project URL
|
|
23
|
+
* - SUPABASE_SERVICE_ROLE_KEY: Service role key for admin operations
|
|
24
|
+
* - SUPABASE_ANON_PUBLIC_KEY: Anonymous key for public operations
|
|
25
|
+
*
|
|
26
|
+
* @example Using with Core.initialize() (Recommended)
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { Core } from '@plyaz/core';
|
|
29
|
+
*
|
|
30
|
+
* // Core.initialize() handles loading env and passing to DbService
|
|
31
|
+
* await Core.initialize({
|
|
32
|
+
* envPath: '.env',
|
|
33
|
+
* db: {
|
|
34
|
+
* adapter: 'sql',
|
|
35
|
+
* cache: { enabled: true, ttl: 60 },
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Access via Core.db
|
|
40
|
+
* const db = Core.db.getDatabase();
|
|
41
|
+
* const result = await db.list('users', { pagination: { limit: 10, offset: 0 } });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Direct Usage (requires explicit config)
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Direct usage requires explicit connectionString
|
|
47
|
+
* await DbService.initialize({
|
|
48
|
+
* adapter: 'drizzle',
|
|
49
|
+
* drizzle: {
|
|
50
|
+
* connectionString: 'postgresql://user:pass@localhost:5432/db',
|
|
51
|
+
* poolSize: 20,
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example With Extensions
|
|
57
|
+
* ```typescript
|
|
58
|
+
* await Core.initialize({
|
|
59
|
+
* envPath: '.env',
|
|
60
|
+
* db: {
|
|
61
|
+
* adapter: 'drizzle',
|
|
62
|
+
* softDelete: {
|
|
63
|
+
* enabled: true,
|
|
64
|
+
* field: 'deleted_at',
|
|
65
|
+
* excludeTables: ['audit_logs', 'feature_flag_evaluations'],
|
|
66
|
+
* },
|
|
67
|
+
* cache: {
|
|
68
|
+
* enabled: true,
|
|
69
|
+
* provider: 'memory',
|
|
70
|
+
* ttl: 300,
|
|
71
|
+
* },
|
|
72
|
+
* audit: {
|
|
73
|
+
* enabled: true,
|
|
74
|
+
* retentionDays: 90,
|
|
75
|
+
* },
|
|
76
|
+
* },
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example Using with BaseRepository
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { BaseRepository } from '@plyaz/db';
|
|
83
|
+
* import { DbService } from '@plyaz/core';
|
|
84
|
+
*
|
|
85
|
+
* class UserRepository extends BaseRepository<User> {
|
|
86
|
+
* constructor() {
|
|
87
|
+
* super(DbService.getInstance().getDatabase(), 'users');
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @module services
|
|
93
|
+
*/
|
|
94
|
+
import { type DatabaseServiceInterface, type Transaction } from '@plyaz/types/db';
|
|
95
|
+
/**
|
|
96
|
+
* Default fields to encrypt per table
|
|
97
|
+
* Contains sensitive PII and financial data that should be encrypted at rest
|
|
98
|
+
*
|
|
99
|
+
* @see docs/db-schemas/dbdiagram_schema.dbml for field definitions
|
|
100
|
+
*/
|
|
101
|
+
export declare const DEFAULT_ENCRYPTION_FIELDS: Record<string, string[]>;
|
|
102
|
+
export type { CoreDbServiceConfig } from '@plyaz/types/core';
|
|
103
|
+
import type { CoreDbServiceConfig as DbServiceConfig } from '@plyaz/types/core';
|
|
104
|
+
/**
|
|
105
|
+
* Complete table registry from database migrations
|
|
106
|
+
* Maps logical table names to their ID columns
|
|
107
|
+
*
|
|
108
|
+
* @see docs/db-schemas/migrations/ for schema definitions
|
|
109
|
+
* @see docs/db-schemas/dbdiagram_schema.dbml for full schema
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* TABLE_REGISTRY - Custom ID Column and Schema Registry
|
|
113
|
+
*
|
|
114
|
+
* ONLY register tables with:
|
|
115
|
+
* 1. Custom ID columns (anything other than 'id')
|
|
116
|
+
* 2. Custom database schemas (anything other than 'public')
|
|
117
|
+
*
|
|
118
|
+
* Tables with standard 'id' column in 'public' schema do NOT need registration.
|
|
119
|
+
* You can also override ID column and schema per-query using OperationConfig.
|
|
120
|
+
*
|
|
121
|
+
* Schema can be defined in the table key or in the config object (or both):
|
|
122
|
+
* - 'schema.table': { idColumn: 'key' } ← Schema in key only
|
|
123
|
+
* - 'schema.table': { idColumn: 'key', schema: 'schema' } ← Redundant but allowed
|
|
124
|
+
* - 'schema.table': {} ← Empty config, schema in key
|
|
125
|
+
* - 'table': { idColumn: 'key', schema: 'schema' } ← Schema in config only
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Using registry
|
|
130
|
+
* await db.get('feature_flags', 'my-flag-key'); // Uses 'key' column from registry
|
|
131
|
+
*
|
|
132
|
+
* // Per-query override
|
|
133
|
+
* await db.get('custom_table', 'some-key', { idColumn: 'custom_id' });
|
|
134
|
+
*
|
|
135
|
+
* // Schema override
|
|
136
|
+
* await db.get('logs', '123', { schema: 'logging' });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare const TABLE_REGISTRY: Record<string, {
|
|
140
|
+
idColumn?: string;
|
|
141
|
+
schema?: string;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* DbService - Singleton Database Connection Manager
|
|
145
|
+
*
|
|
146
|
+
* Provides centralized database connection management for all domains.
|
|
147
|
+
* Uses @plyaz/db under the hood with configurable adapters and extensions.
|
|
148
|
+
*/
|
|
149
|
+
export declare class DbService {
|
|
150
|
+
private static instance;
|
|
151
|
+
private databaseService;
|
|
152
|
+
private namedAdapters;
|
|
153
|
+
private config;
|
|
154
|
+
private initialized;
|
|
155
|
+
private constructor();
|
|
156
|
+
/**
|
|
157
|
+
* Emits a database error event via CoreEventManager.
|
|
158
|
+
* Called when database operations fail to integrate with global error handling.
|
|
159
|
+
*
|
|
160
|
+
* @param error - The error that occurred
|
|
161
|
+
* @param operation - The operation that failed (e.g., 'transaction', 'query', 'healthCheck')
|
|
162
|
+
* @param table - Optional table name involved in the operation
|
|
163
|
+
* @param query - Optional query string that failed
|
|
164
|
+
* @param recoverable - Whether the error is recoverable (default: false)
|
|
165
|
+
*/
|
|
166
|
+
private emitDatabaseError;
|
|
167
|
+
/**
|
|
168
|
+
* Gets the singleton instance of DbService
|
|
169
|
+
*
|
|
170
|
+
* @returns {DbService} The singleton instance
|
|
171
|
+
*/
|
|
172
|
+
static getInstance(): DbService;
|
|
173
|
+
/**
|
|
174
|
+
* Checks if the database service has been initialized
|
|
175
|
+
*
|
|
176
|
+
* @returns {boolean} True if initialized
|
|
177
|
+
*/
|
|
178
|
+
static isInitialized(): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Resets the database service by closing connections and clearing the singleton instance
|
|
181
|
+
*
|
|
182
|
+
* @description Properly closes the database connection and clears the singleton.
|
|
183
|
+
* Useful for testing or when you need to reinitialize with different configuration.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* await DbService.reset();
|
|
188
|
+
* await DbService.initialize({ adapter: 'sql', ... });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
static reset(): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Initializes the database connection
|
|
194
|
+
*
|
|
195
|
+
* @description Sets up the database connection using the provided configuration
|
|
196
|
+
* or environment variables. This method is idempotent - calling it multiple
|
|
197
|
+
* times won't create additional connections.
|
|
198
|
+
*
|
|
199
|
+
* **Environment Variables:**
|
|
200
|
+
* - `DATABASE_URL` - PostgreSQL connection string (for sql/drizzle adapters)
|
|
201
|
+
* - `ENCRYPTION_KEY` - 32-byte encryption key for field encryption (optional)
|
|
202
|
+
* - `SUPABASE_URL`, `SUPABASE_SERVICE_ROLE_KEY`, `SUPABASE_ANON_PUBLIC_KEY` - For supabase adapter
|
|
203
|
+
*
|
|
204
|
+
* **Encryption:** If `ENCRYPTION_KEY` env is set, encryption is auto-enabled
|
|
205
|
+
* using `DEFAULT_ENCRYPTION_FIELDS`. Override via config.encryption.
|
|
206
|
+
*
|
|
207
|
+
* @param {DbServiceConfig} [config] - Optional configuration
|
|
208
|
+
* @returns {Promise<DbService>} The initialized DbService instance
|
|
209
|
+
* @throws {DatabasePackageError} When configuration is invalid or connection fails
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* // Minimal - uses DATABASE_URL env, auto-enables encryption if ENCRYPTION_KEY set
|
|
214
|
+
* await DbService.initialize();
|
|
215
|
+
*
|
|
216
|
+
* // With explicit encryption
|
|
217
|
+
* await DbService.initialize({
|
|
218
|
+
* adapter: 'sql',
|
|
219
|
+
* encryption: {
|
|
220
|
+
* enabled: true,
|
|
221
|
+
* key: 'your-32-byte-encryption-key-here!!',
|
|
222
|
+
* fields: DEFAULT_ENCRYPTION_FIELDS,
|
|
223
|
+
* },
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* // Or via Core.initialize() with env:
|
|
227
|
+
* await Core.initialize({
|
|
228
|
+
* env: { ENCRYPTION_KEY: '...' },
|
|
229
|
+
* db: { adapter: 'sql' },
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
/** Build encryption config from user config */
|
|
234
|
+
private static buildEncryptionConfig;
|
|
235
|
+
/** Merge user config with defaults */
|
|
236
|
+
private static mergeConfig;
|
|
237
|
+
/** Initialize named adapters */
|
|
238
|
+
private initializeNamedAdapters;
|
|
239
|
+
static initialize(config?: DbServiceConfig): Promise<DbService>;
|
|
240
|
+
/**
|
|
241
|
+
* Builds the DatabaseServiceConfig based on the adapter type
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
/** Builds adapter-specific config based on adapter type */
|
|
245
|
+
private buildAdapterConfig;
|
|
246
|
+
/** Builds soft delete extension config */
|
|
247
|
+
private buildSoftDeleteExtension;
|
|
248
|
+
/** Builds cache extension config */
|
|
249
|
+
private buildCacheExtension;
|
|
250
|
+
/** Builds audit extension config */
|
|
251
|
+
private buildAuditExtension;
|
|
252
|
+
/** Builds encryption extension config */
|
|
253
|
+
private buildEncryptionExtension;
|
|
254
|
+
private buildDatabaseConfig;
|
|
255
|
+
/**
|
|
256
|
+
* Builds Drizzle adapter configuration
|
|
257
|
+
* @private
|
|
258
|
+
*/
|
|
259
|
+
private buildDrizzleConfig;
|
|
260
|
+
/**
|
|
261
|
+
* Builds Supabase adapter configuration
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
private buildSupabaseConfig;
|
|
265
|
+
/**
|
|
266
|
+
* Builds SQL adapter configuration
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
269
|
+
private buildSqlConfig;
|
|
270
|
+
/**
|
|
271
|
+
* Builds table ID column mappings from TABLE_REGISTRY
|
|
272
|
+
* @private
|
|
273
|
+
* @returns Record of table names to ID column names
|
|
274
|
+
*/
|
|
275
|
+
private buildTableIdColumns;
|
|
276
|
+
/**
|
|
277
|
+
* Gets the initialized database service instance
|
|
278
|
+
*
|
|
279
|
+
* @param {string} [adapterName] - Optional named adapter to use instead of default
|
|
280
|
+
* @returns {DatabaseServiceInterface} The database service instance
|
|
281
|
+
* @throws {DatabasePackageError} When database is not initialized or named adapter not found
|
|
282
|
+
*/
|
|
283
|
+
getDatabase(adapterName?: string): DatabaseServiceInterface;
|
|
284
|
+
/**
|
|
285
|
+
* Gets a named adapter by name
|
|
286
|
+
*
|
|
287
|
+
* @param {string} name - The name of the adapter
|
|
288
|
+
* @returns {DatabaseServiceInterface} The named adapter instance
|
|
289
|
+
* @throws {DatabasePackageError} When adapter not found
|
|
290
|
+
*/
|
|
291
|
+
getAdapter(name: string): DatabaseServiceInterface;
|
|
292
|
+
/**
|
|
293
|
+
* Lists all available named adapters
|
|
294
|
+
*
|
|
295
|
+
* @returns {string[]} Array of adapter names
|
|
296
|
+
*/
|
|
297
|
+
getAvailableAdapters(): string[];
|
|
298
|
+
/**
|
|
299
|
+
* Executes a database transaction with automatic rollback on failure
|
|
300
|
+
*
|
|
301
|
+
* @template T The return type of the transaction callback
|
|
302
|
+
* @param {Function} callback - Function that receives transaction object
|
|
303
|
+
* @returns {Promise<T>} The result of the transaction callback
|
|
304
|
+
* @throws {DatabasePackageError} When transaction fails
|
|
305
|
+
*/
|
|
306
|
+
transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
307
|
+
/**
|
|
308
|
+
* Sets audit context for subsequent operations
|
|
309
|
+
*
|
|
310
|
+
* @param context - Audit context (userId, requestId, etc.)
|
|
311
|
+
*/
|
|
312
|
+
setAuditContext(context: {
|
|
313
|
+
userId?: string;
|
|
314
|
+
requestId?: string;
|
|
315
|
+
ipAddress?: string;
|
|
316
|
+
userAgent?: string;
|
|
317
|
+
}): Promise<void>;
|
|
318
|
+
/**
|
|
319
|
+
* Performs a health check on the database connection
|
|
320
|
+
*
|
|
321
|
+
* @returns Health check result
|
|
322
|
+
*/
|
|
323
|
+
healthCheck(): Promise<{
|
|
324
|
+
isHealthy: boolean;
|
|
325
|
+
responseTime?: number;
|
|
326
|
+
error?: string;
|
|
327
|
+
}>;
|
|
328
|
+
/**
|
|
329
|
+
* Gets the table registry with all known tables and their ID columns
|
|
330
|
+
*
|
|
331
|
+
* @returns The complete table registry
|
|
332
|
+
*/
|
|
333
|
+
static getTableRegistry(): typeof TABLE_REGISTRY;
|
|
334
|
+
/**
|
|
335
|
+
* Gets ID column for a specific table
|
|
336
|
+
*
|
|
337
|
+
* @param tableName - Name of the table
|
|
338
|
+
* @returns ID column name or 'id' as default
|
|
339
|
+
*/
|
|
340
|
+
static getTableIdColumn(tableName: string): string;
|
|
341
|
+
/**
|
|
342
|
+
* Reinitializes the database connection with new config
|
|
343
|
+
*
|
|
344
|
+
* @param {DbServiceConfig} [config] - New configuration
|
|
345
|
+
* @returns {Promise<DbService>} The reinitialized DbService instance
|
|
346
|
+
*/
|
|
347
|
+
static reinitialize(config?: DbServiceConfig): Promise<DbService>;
|
|
348
|
+
/**
|
|
349
|
+
* Closes the database connection and cleans up resources
|
|
350
|
+
*/
|
|
351
|
+
close(): Promise<void>;
|
|
352
|
+
/**
|
|
353
|
+
* Gets the current configuration
|
|
354
|
+
*
|
|
355
|
+
* @returns {DbServiceConfig | null} Current config or null if not initialized
|
|
356
|
+
*/
|
|
357
|
+
getConfig(): DbServiceConfig | null;
|
|
358
|
+
/**
|
|
359
|
+
* Gets the current adapter type
|
|
360
|
+
*
|
|
361
|
+
* @returns The adapter type or null if not initialized
|
|
362
|
+
*/
|
|
363
|
+
getAdapterType(): 'drizzle' | 'supabase' | 'sql' | null;
|
|
364
|
+
/**
|
|
365
|
+
* Creates a dedicated database service instance (NOT the singleton)
|
|
366
|
+
*
|
|
367
|
+
* Use this when you need an isolated database connection with its own configuration
|
|
368
|
+
* that doesn't affect or get affected by the shared singleton instance.
|
|
369
|
+
*
|
|
370
|
+
* @param config - Database service configuration
|
|
371
|
+
* @returns Promise that resolves to a new dedicated DbService instance
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* // Create a dedicated instance for analytics database
|
|
376
|
+
* const analyticsDb = await DbService.createInstance({
|
|
377
|
+
* adapter: 'sql',
|
|
378
|
+
* sql: { connectionString: process.env.ANALYTICS_DB_URL },
|
|
379
|
+
* cache: { enabled: false }, // No caching for analytics
|
|
380
|
+
* });
|
|
381
|
+
*
|
|
382
|
+
* // This instance is independent from DbService.getInstance()
|
|
383
|
+
* const data = await analyticsDb.getDatabase().list('events');
|
|
384
|
+
*
|
|
385
|
+
* // Clean up when done
|
|
386
|
+
* await analyticsDb.close();
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
static createInstance(config: DbServiceConfig): Promise<DbService>;
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=DbService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbService.d.ts","sourceRoot":"","sources":["../../src/services/DbService.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NotificationService - Singleton Notification Manager
|
|
3
|
+
*
|
|
4
|
+
* @description Manages notification delivery for the entire application using a singleton pattern.
|
|
5
|
+
* This service wraps @plyaz/notifications and provides a centralized way to initialize and access
|
|
6
|
+
* notification capabilities across all domains (transactional, marketing, system alerts, etc.).
|
|
7
|
+
*
|
|
8
|
+
* **Architecture:**
|
|
9
|
+
* - Uses `NotificationService` from @plyaz/notifications which supports multi-provider setup
|
|
10
|
+
* - Supports email (Infobip primary, SendGrid fallback), SMS, and push notifications
|
|
11
|
+
* - Automatic failover between providers based on health status
|
|
12
|
+
* - Event-driven architecture for tracking delivery, opens, clicks
|
|
13
|
+
* - **Proxy-based method forwarding**: All methods from the underlying service are
|
|
14
|
+
* automatically available with error handling - no manual wrapping needed
|
|
15
|
+
*
|
|
16
|
+
* **Provider Configuration:**
|
|
17
|
+
* - **Infobip**: Primary email provider (unified omnichannel platform)
|
|
18
|
+
* - **SendGrid**: Fallback email provider for transactional emails
|
|
19
|
+
*
|
|
20
|
+
* **Required Environment Variables (Infobip):**
|
|
21
|
+
* - INFOBIP_API_KEY: Your Infobip API key
|
|
22
|
+
* - INFOBIP_BASE_URL: Infobip API base URL
|
|
23
|
+
* - FROM_EMAIL: Default sender email address
|
|
24
|
+
*
|
|
25
|
+
* **Required Environment Variables (SendGrid):**
|
|
26
|
+
* - SENDGRID_API_KEY: Your SendGrid API key
|
|
27
|
+
* - FROM_EMAIL: Default sender email address
|
|
28
|
+
*
|
|
29
|
+
* @example Using with Core.initialize() (Recommended)
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { Core } from '@plyaz/core';
|
|
32
|
+
*
|
|
33
|
+
* await Core.initialize({
|
|
34
|
+
* notifications: {
|
|
35
|
+
* providers: {
|
|
36
|
+
* email: [infobipAdapter, sendGridAdapter],
|
|
37
|
+
* sms: [],
|
|
38
|
+
* push: [],
|
|
39
|
+
* },
|
|
40
|
+
* events: {
|
|
41
|
+
* onSent: (event) => console.log('Notification sent:', event),
|
|
42
|
+
* onFailed: (event) => console.error('Notification failed:', event),
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Access via Core.notifications - all methods automatically available
|
|
48
|
+
* await Core.notifications.sendEmail({
|
|
49
|
+
* recipientId: 'user-123',
|
|
50
|
+
* to: 'user@example.com',
|
|
51
|
+
* templateId: 'welcome',
|
|
52
|
+
* templateData: { userName: 'John' },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @module services
|
|
57
|
+
*/
|
|
58
|
+
import { NotificationService as NotificationServiceImpl } from '@plyaz/notifications';
|
|
59
|
+
import type { CoreNotificationConfig } from '@plyaz/types/core';
|
|
60
|
+
export type { CoreNotificationConfig } from '@plyaz/types/core';
|
|
61
|
+
/**
|
|
62
|
+
* NotificationService - Singleton Notification Manager with Proxy-based method forwarding
|
|
63
|
+
*
|
|
64
|
+
* Provides centralized notification management for all domains.
|
|
65
|
+
* Uses @plyaz/notifications under the hood with configurable providers and templates.
|
|
66
|
+
*
|
|
67
|
+
* All methods from the underlying NotificationServiceImpl are automatically available
|
|
68
|
+
* via Proxy - when new methods are added to @plyaz/notifications, they're instantly
|
|
69
|
+
* accessible here with automatic error handling.
|
|
70
|
+
*/
|
|
71
|
+
export declare class NotificationService {
|
|
72
|
+
private static instance;
|
|
73
|
+
private notificationService;
|
|
74
|
+
private config;
|
|
75
|
+
private initialized;
|
|
76
|
+
private constructor();
|
|
77
|
+
/**
|
|
78
|
+
* Emits a notification error event via CoreEventManager.
|
|
79
|
+
* Called when notification operations fail to integrate with global error handling.
|
|
80
|
+
*/
|
|
81
|
+
private emitNotificationError;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the singleton instance of NotificationService
|
|
84
|
+
*/
|
|
85
|
+
static getInstance(): NotificationService;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if the notification service has been initialized
|
|
88
|
+
*/
|
|
89
|
+
static isInitialized(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Resets the notification service by clearing the singleton instance
|
|
92
|
+
*/
|
|
93
|
+
static reset(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Initializes the notification service
|
|
96
|
+
*
|
|
97
|
+
* @param config - Notification service configuration
|
|
98
|
+
* @returns The initialized NotificationService instance
|
|
99
|
+
*/
|
|
100
|
+
static initialize(config: CoreNotificationConfig): Promise<NotificationService>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the raw underlying notification service instance without error handling wrapper.
|
|
103
|
+
* Use this only if you need direct access to the underlying service.
|
|
104
|
+
*
|
|
105
|
+
* @returns The raw NotificationService instance from @plyaz/notifications
|
|
106
|
+
* @throws {NotificationsPackageError} When notifications is not initialized
|
|
107
|
+
*/
|
|
108
|
+
private getRawNotifications;
|
|
109
|
+
/**
|
|
110
|
+
* Gets the notification service with automatic error handling.
|
|
111
|
+
* All method calls are wrapped with try/catch and emit error events on failure.
|
|
112
|
+
* Any method added to @plyaz/notifications will be automatically available.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const notifications = NotificationService.getInstance().getNotifications();
|
|
117
|
+
* await notifications.sendEmail({ to: 'user@example.com', templateId: 'welcome' });
|
|
118
|
+
* await notifications.sendSMS({ to: '+1234567890', message: 'Hello!' });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @returns NotificationServiceImpl with automatic error handling
|
|
122
|
+
*/
|
|
123
|
+
getNotifications(): NotificationServiceImpl;
|
|
124
|
+
/**
|
|
125
|
+
* Performs a health check on the notification service.
|
|
126
|
+
* This method has special handling to transform the response format.
|
|
127
|
+
*/
|
|
128
|
+
healthCheck(): Promise<{
|
|
129
|
+
isHealthy: boolean;
|
|
130
|
+
providers?: unknown[];
|
|
131
|
+
error?: string;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Gets the current configuration
|
|
135
|
+
*/
|
|
136
|
+
getConfig(): CoreNotificationConfig | null;
|
|
137
|
+
/**
|
|
138
|
+
* Closes the notification service and cleans up resources
|
|
139
|
+
*/
|
|
140
|
+
close(): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a dedicated notification service instance (NOT the singleton)
|
|
143
|
+
*
|
|
144
|
+
* Use this when you need an isolated notification service with its own configuration.
|
|
145
|
+
*
|
|
146
|
+
* @param config - Notification service configuration
|
|
147
|
+
* @returns Promise that resolves to a new dedicated NotificationService instance
|
|
148
|
+
*/
|
|
149
|
+
static createInstance(config: CoreNotificationConfig): Promise<NotificationService>;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=NotificationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationService.d.ts","sourceRoot":"","sources":["../../src/services/NotificationService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,EAAE,mBAAmB,IAAI,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAMhE,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAShE;;;;;;;;;GASG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAoC;IAC3D,OAAO,CAAC,mBAAmB,CAAwC;IACnE,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAMP;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAmB7B;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,mBAAmB;IAKzC;;OAEG;IACH,MAAM,CAAC,aAAa,IAAI,OAAO;IAI/B;;OAEG;WACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IASnC;;;;;OAKG;WACU,UAAU,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAcrF;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAc3B;;;;;;;;;;;;;OAaG;IACH,gBAAgB,IAAI,uBAAuB;IA6C3C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAyB3F;;OAEG;IACH,SAAS,IAAI,sBAAsB,GAAG,IAAI;IAI1C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B;;;;;;;OAOG;WACU,cAAc,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAO1F"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageService - Singleton File Storage Manager
|
|
3
|
+
*
|
|
4
|
+
* @description Manages file storage operations for the entire application using a singleton pattern.
|
|
5
|
+
* This service wraps @plyaz/storage and provides a centralized way to initialize and access
|
|
6
|
+
* file storage across all domains (media uploads, compliance documents, user avatars, etc.).
|
|
7
|
+
*
|
|
8
|
+
* **Architecture:**
|
|
9
|
+
* - Uses `StorageService` from @plyaz/storage which supports multi-provider setup
|
|
10
|
+
* - Supports Cloudflare R2 (compliance documents) and Supabase Storage (assets/media)
|
|
11
|
+
* - Automatic failover between providers based on health status
|
|
12
|
+
* - Event-driven architecture with 40+ event types
|
|
13
|
+
* - **Proxy-based method forwarding**: All methods from the underlying service are
|
|
14
|
+
* automatically available with error handling - no manual wrapping needed
|
|
15
|
+
*
|
|
16
|
+
* **Provider Configuration:**
|
|
17
|
+
* - **Cloudflare R2**: For compliance documents (tax, invoices, KYC) with zero egress fees
|
|
18
|
+
* - **Supabase Storage**: For assets like images, user avatars, media files
|
|
19
|
+
*
|
|
20
|
+
* **Required Environment Variables (Cloudflare R2):**
|
|
21
|
+
* - CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account ID
|
|
22
|
+
* - R2_ACCESS_KEY_ID: R2 access key
|
|
23
|
+
* - R2_SECRET_ACCESS_KEY: R2 secret key
|
|
24
|
+
* - R2_BUCKET_NAME: Default bucket name
|
|
25
|
+
*
|
|
26
|
+
* **Required Environment Variables (Supabase Storage):**
|
|
27
|
+
* - SUPABASE_URL: Your Supabase project URL
|
|
28
|
+
* - SUPABASE_SERVICE_ROLE_KEY: Service role key for storage operations
|
|
29
|
+
*
|
|
30
|
+
* @example Using with Core.initialize() (Recommended)
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { Core } from '@plyaz/core';
|
|
33
|
+
*
|
|
34
|
+
* await Core.initialize({
|
|
35
|
+
* storage: {
|
|
36
|
+
* adapters: [r2Adapter, supabaseAdapter],
|
|
37
|
+
* plugins: [virusScanPlugin, sharpImagePlugin],
|
|
38
|
+
* },
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Access via Core.storage - all methods automatically available
|
|
42
|
+
* const result = await Core.storage.uploadFile({
|
|
43
|
+
* file: buffer,
|
|
44
|
+
* filename: 'document.pdf',
|
|
45
|
+
* category: FILE_CATEGORY.COMPLIANCE_DOCUMENT,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @module services
|
|
50
|
+
*/
|
|
51
|
+
import { StorageService as StorageServiceImpl } from '@plyaz/storage';
|
|
52
|
+
import type { CoreStorageConfig } from '@plyaz/types/core';
|
|
53
|
+
export type { CoreStorageConfig } from '@plyaz/types/core';
|
|
54
|
+
/**
|
|
55
|
+
* StorageService - Singleton File Storage Manager with Proxy-based method forwarding
|
|
56
|
+
*
|
|
57
|
+
* Provides centralized file storage management for all domains.
|
|
58
|
+
* Uses @plyaz/storage under the hood with configurable providers and plugins.
|
|
59
|
+
*
|
|
60
|
+
* All methods from the underlying StorageServiceImpl are automatically available
|
|
61
|
+
* via Proxy - when new methods are added to @plyaz/storage, they're instantly
|
|
62
|
+
* accessible here with automatic error handling.
|
|
63
|
+
*/
|
|
64
|
+
export declare class StorageService {
|
|
65
|
+
private static instance;
|
|
66
|
+
private storageService;
|
|
67
|
+
private config;
|
|
68
|
+
private initialized;
|
|
69
|
+
private constructor();
|
|
70
|
+
/**
|
|
71
|
+
* Emits a storage error event via CoreEventManager.
|
|
72
|
+
* Called when storage operations fail to integrate with global error handling.
|
|
73
|
+
*/
|
|
74
|
+
private emitStorageError;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the singleton instance of StorageService
|
|
77
|
+
*/
|
|
78
|
+
static getInstance(): StorageService;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the storage service has been initialized
|
|
81
|
+
*/
|
|
82
|
+
static isInitialized(): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Resets the storage service by clearing the singleton instance
|
|
85
|
+
*/
|
|
86
|
+
static reset(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Initializes the storage service
|
|
89
|
+
*
|
|
90
|
+
* @param config - Storage service configuration
|
|
91
|
+
* @returns The initialized StorageService instance
|
|
92
|
+
*/
|
|
93
|
+
static initialize(config: CoreStorageConfig): Promise<StorageService>;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the raw underlying storage service instance without error handling wrapper.
|
|
96
|
+
* Use this only if you need direct access to the underlying service.
|
|
97
|
+
*
|
|
98
|
+
* @returns The raw StorageService instance from @plyaz/storage
|
|
99
|
+
* @throws {StoragePackageError} When storage is not initialized
|
|
100
|
+
*/
|
|
101
|
+
private getRawStorage;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the storage service with automatic error handling.
|
|
104
|
+
* All method calls are wrapped with try/catch and emit error events on failure.
|
|
105
|
+
* Any method added to @plyaz/storage will be automatically available.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const storage = StorageService.getInstance().getStorage();
|
|
110
|
+
* await storage.uploadFile({ file, filename: 'doc.pdf' });
|
|
111
|
+
* await storage.deleteFile({ fileId: '123' });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @returns StorageServiceImpl with automatic error handling
|
|
115
|
+
*/
|
|
116
|
+
getStorage(): StorageServiceImpl;
|
|
117
|
+
/**
|
|
118
|
+
* Performs a health check on the storage service by checking all adapter health.
|
|
119
|
+
* This method has special handling to transform the response format.
|
|
120
|
+
*/
|
|
121
|
+
healthCheck(): Promise<{
|
|
122
|
+
isHealthy: boolean;
|
|
123
|
+
responseTime?: number;
|
|
124
|
+
error?: string;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Gets the current configuration
|
|
128
|
+
*/
|
|
129
|
+
getConfig(): CoreStorageConfig | null;
|
|
130
|
+
/**
|
|
131
|
+
* Closes the storage service and cleans up resources
|
|
132
|
+
*/
|
|
133
|
+
close(): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Creates a dedicated storage service instance (NOT the singleton)
|
|
136
|
+
*
|
|
137
|
+
* Use this when you need an isolated storage connection with its own configuration.
|
|
138
|
+
*
|
|
139
|
+
* @param config - Storage service configuration
|
|
140
|
+
* @returns Promise that resolves to a new dedicated StorageService instance
|
|
141
|
+
*/
|
|
142
|
+
static createInstance(config: CoreStorageConfig): Promise<StorageService>;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=StorageService.d.ts.map
|