@axova/shared 1.0.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.
- package/CONFIGURATION_GUIDE.md +1 -0
- package/README.md +384 -0
- package/SCHEMA_ORGANIZATION.md +209 -0
- package/dist/configs/index.d.ts +85 -0
- package/dist/configs/index.js +555 -0
- package/dist/events/kafka.d.ts +40 -0
- package/dist/events/kafka.js +311 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +41 -0
- package/dist/interfaces/customer-events.d.ts +85 -0
- package/dist/interfaces/customer-events.js +2 -0
- package/dist/interfaces/inventory-events.d.ts +453 -0
- package/dist/interfaces/inventory-events.js +3 -0
- package/dist/interfaces/inventory-types.d.ts +894 -0
- package/dist/interfaces/inventory-types.js +3 -0
- package/dist/interfaces/order-events.d.ts +320 -0
- package/dist/interfaces/order-events.js +3 -0
- package/dist/lib/auditLogger.d.ts +162 -0
- package/dist/lib/auditLogger.js +626 -0
- package/dist/lib/authOrganization.d.ts +24 -0
- package/dist/lib/authOrganization.js +110 -0
- package/dist/lib/db.d.ts +6 -0
- package/dist/lib/db.js +88 -0
- package/dist/middleware/serviceAuth.d.ts +60 -0
- package/dist/middleware/serviceAuth.js +272 -0
- package/dist/middleware/storeOwnership.d.ts +15 -0
- package/dist/middleware/storeOwnership.js +156 -0
- package/dist/middleware/storeValidationMiddleware.d.ts +44 -0
- package/dist/middleware/storeValidationMiddleware.js +180 -0
- package/dist/middleware/userAuth.d.ts +27 -0
- package/dist/middleware/userAuth.js +218 -0
- package/dist/schemas/admin/admin-schema.d.ts +741 -0
- package/dist/schemas/admin/admin-schema.js +111 -0
- package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +648 -0
- package/dist/schemas/ai-moderation/ai-moderation-schema.js +88 -0
- package/dist/schemas/common/common-schemas.d.ts +436 -0
- package/dist/schemas/common/common-schemas.js +94 -0
- package/dist/schemas/compliance/compliance-schema.d.ts +3388 -0
- package/dist/schemas/compliance/compliance-schema.js +472 -0
- package/dist/schemas/compliance/kyc-schema.d.ts +2642 -0
- package/dist/schemas/compliance/kyc-schema.js +361 -0
- package/dist/schemas/customer/customer-schema.d.ts +2727 -0
- package/dist/schemas/customer/customer-schema.js +399 -0
- package/dist/schemas/index.d.ts +27 -0
- package/dist/schemas/index.js +138 -0
- package/dist/schemas/inventory/inventory-tables.d.ts +9476 -0
- package/dist/schemas/inventory/inventory-tables.js +1470 -0
- package/dist/schemas/inventory/lot-tables.d.ts +3281 -0
- package/dist/schemas/inventory/lot-tables.js +608 -0
- package/dist/schemas/order/order-schema.d.ts +5825 -0
- package/dist/schemas/order/order-schema.js +954 -0
- package/dist/schemas/product/discount-relations.d.ts +15 -0
- package/dist/schemas/product/discount-relations.js +34 -0
- package/dist/schemas/product/discount-schema.d.ts +1975 -0
- package/dist/schemas/product/discount-schema.js +297 -0
- package/dist/schemas/product/product-relations.d.ts +41 -0
- package/dist/schemas/product/product-relations.js +133 -0
- package/dist/schemas/product/product-schema.d.ts +4544 -0
- package/dist/schemas/product/product-schema.js +671 -0
- package/dist/schemas/store/store-audit-schema.d.ts +4135 -0
- package/dist/schemas/store/store-audit-schema.js +556 -0
- package/dist/schemas/store/store-schema.d.ts +3100 -0
- package/dist/schemas/store/store-schema.js +381 -0
- package/dist/schemas/store/store-settings-schema.d.ts +665 -0
- package/dist/schemas/store/store-settings-schema.js +141 -0
- package/dist/schemas/types.d.ts +50 -0
- package/dist/schemas/types.js +3 -0
- package/dist/types/events.d.ts +2396 -0
- package/dist/types/events.js +505 -0
- package/dist/utils/errorHandler.d.ts +12 -0
- package/dist/utils/errorHandler.js +36 -0
- package/dist/utils/subdomain.d.ts +6 -0
- package/dist/utils/subdomain.js +20 -0
- package/nul +8 -0
- package/package.json +43 -0
- package/src/configs/index.ts +654 -0
- package/src/events/kafka.ts +429 -0
- package/src/index.ts +26 -0
- package/src/interfaces/customer-events.ts +106 -0
- package/src/interfaces/inventory-events.ts +545 -0
- package/src/interfaces/inventory-types.ts +1004 -0
- package/src/interfaces/order-events.ts +381 -0
- package/src/lib/auditLogger.ts +1117 -0
- package/src/lib/authOrganization.ts +153 -0
- package/src/lib/db.ts +64 -0
- package/src/middleware/serviceAuth.ts +328 -0
- package/src/middleware/storeOwnership.ts +199 -0
- package/src/middleware/storeValidationMiddleware.ts +247 -0
- package/src/middleware/userAuth.ts +248 -0
- package/src/schemas/admin/admin-schema.ts +208 -0
- package/src/schemas/ai-moderation/ai-moderation-schema.ts +180 -0
- package/src/schemas/common/common-schemas.ts +108 -0
- package/src/schemas/compliance/compliance-schema.ts +927 -0
- package/src/schemas/compliance/kyc-schema.ts +649 -0
- package/src/schemas/customer/customer-schema.ts +576 -0
- package/src/schemas/index.ts +189 -0
- package/src/schemas/inventory/inventory-tables.ts +1927 -0
- package/src/schemas/inventory/lot-tables.ts +799 -0
- package/src/schemas/order/order-schema.ts +1400 -0
- package/src/schemas/product/discount-relations.ts +44 -0
- package/src/schemas/product/discount-schema.ts +464 -0
- package/src/schemas/product/product-relations.ts +187 -0
- package/src/schemas/product/product-schema.ts +955 -0
- package/src/schemas/store/ethiopian_business_api.md.resolved +212 -0
- package/src/schemas/store/store-audit-schema.ts +1257 -0
- package/src/schemas/store/store-schema.ts +661 -0
- package/src/schemas/store/store-settings-schema.ts +231 -0
- package/src/schemas/types.ts +67 -0
- package/src/types/events.ts +646 -0
- package/src/utils/errorHandler.ts +44 -0
- package/src/utils/subdomain.ts +19 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// AXOVA SHARED CONFIGURATIONS
|
|
4
|
+
// Service-specific configuration profiles for the Axova platform
|
|
5
|
+
// =============================================================================
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SERVICE_PROFILES = exports.OXA_SERVICE_PROFILE = exports.ADMIN_API_SERVICE_PROFILE = exports.INVENTORY_SERVICE_PROFILE = exports.PRODUCT_SERVICE_PROFILE = exports.COMPLIANCE_SERVICE_PROFILE = exports.STORE_SERVICE_PROFILE = void 0;
|
|
8
|
+
exports.getServiceProfile = getServiceProfile;
|
|
9
|
+
exports.initializeServiceWithProfile = initializeServiceWithProfile;
|
|
10
|
+
exports.validateServiceConfig = validateServiceConfig;
|
|
11
|
+
const kafka_1 = require("../events/kafka");
|
|
12
|
+
const serviceAuth_1 = require("../middleware/serviceAuth");
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Service-Specific Configurations
|
|
15
|
+
// =============================================================================
|
|
16
|
+
exports.STORE_SERVICE_PROFILE = {
|
|
17
|
+
base: {
|
|
18
|
+
serviceName: "store-service",
|
|
19
|
+
port: Number(process.env.PORT) || 3001,
|
|
20
|
+
host: process.env.HOST || "0.0.0.0",
|
|
21
|
+
environment: process.env.NODE_ENV || "development",
|
|
22
|
+
cors: {
|
|
23
|
+
origins: process.env.CORS_ORIGINS?.split(",") || [
|
|
24
|
+
"http://localhost:3000",
|
|
25
|
+
],
|
|
26
|
+
credentials: true,
|
|
27
|
+
},
|
|
28
|
+
rateLimiting: {
|
|
29
|
+
max: Number(process.env.RATE_LIMIT_MAX) || 100,
|
|
30
|
+
timeWindow: process.env.RATE_LIMIT_WINDOW || "1 minute",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
database: {
|
|
34
|
+
url: process.env.DATABASE_URL ||
|
|
35
|
+
"postgresql://postgres:password@localhost:5432/axova_store_db",
|
|
36
|
+
host: process.env.POSTGRES_HOST || "localhost",
|
|
37
|
+
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
38
|
+
user: process.env.POSTGRES_USER || "postgres",
|
|
39
|
+
password: process.env.POSTGRES_PASSWORD || "password",
|
|
40
|
+
database: process.env.POSTGRES_DB || "axova_store_db",
|
|
41
|
+
ssl: process.env.DB_SSL === "true",
|
|
42
|
+
poolSize: Number(process.env.DB_POOL_SIZE) || 10,
|
|
43
|
+
},
|
|
44
|
+
kafka: {
|
|
45
|
+
enabled: process.env.KAFKA_ENABLED !== "false",
|
|
46
|
+
clientId: process.env.KAFKA_CLIENT_ID || "store-service",
|
|
47
|
+
groupId: process.env.KAFKA_GROUP_ID || "store-service-group",
|
|
48
|
+
topics: [
|
|
49
|
+
"store.created",
|
|
50
|
+
"store.updated",
|
|
51
|
+
"store.deleted",
|
|
52
|
+
"store.business.updated",
|
|
53
|
+
"store.social.updated",
|
|
54
|
+
"store.blog.created",
|
|
55
|
+
"store.blog.updated",
|
|
56
|
+
"store.contact.updated",
|
|
57
|
+
],
|
|
58
|
+
autoCommit: process.env.KAFKA_AUTO_COMMIT !== "false",
|
|
59
|
+
},
|
|
60
|
+
redis: {
|
|
61
|
+
host: process.env.REDIS_HOST || "localhost",
|
|
62
|
+
port: Number(process.env.REDIS_PORT) || 6379,
|
|
63
|
+
password: process.env.REDIS_PASSWORD,
|
|
64
|
+
db: Number(process.env.REDIS_DB) || 0,
|
|
65
|
+
ttl: Number(process.env.REDIS_TTL) || 3600,
|
|
66
|
+
},
|
|
67
|
+
audit: {
|
|
68
|
+
enabled: process.env.AUDIT_ENABLED !== "false",
|
|
69
|
+
level: process.env.AUDIT_LEVEL || "comprehensive",
|
|
70
|
+
bufferSize: Number(process.env.AUDIT_BUFFER_SIZE) || 100,
|
|
71
|
+
flushInterval: Number(process.env.AUDIT_FLUSH_INTERVAL) || 5000,
|
|
72
|
+
sensitiveFieldMasking: process.env.AUDIT_MASK_SENSITIVE !== "false",
|
|
73
|
+
},
|
|
74
|
+
features: {
|
|
75
|
+
realTimeSync: process.env.ENABLE_REAL_TIME_SYNC !== "false",
|
|
76
|
+
auditLogging: process.env.ENABLE_AUDIT_LOGGING !== "false",
|
|
77
|
+
advancedAnalytics: process.env.ENABLE_ADVANCED_ANALYTICS === "true",
|
|
78
|
+
multiTenant: true,
|
|
79
|
+
storeCustomization: true,
|
|
80
|
+
blogManagement: true,
|
|
81
|
+
socialProfiles: true,
|
|
82
|
+
businessDetails: true,
|
|
83
|
+
contactManagement: true,
|
|
84
|
+
},
|
|
85
|
+
customConfig: {
|
|
86
|
+
storeDomain: process.env.STORE_DOMAIN || "myaxova.store",
|
|
87
|
+
maxStoresPerUser: Number(process.env.MAX_STORES_PER_USER) || 5,
|
|
88
|
+
storeCustomizationLimits: {
|
|
89
|
+
maxThemes: 10,
|
|
90
|
+
maxPages: 50,
|
|
91
|
+
maxProducts: 10000,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
exports.COMPLIANCE_SERVICE_PROFILE = {
|
|
96
|
+
base: {
|
|
97
|
+
serviceName: "compliance-service",
|
|
98
|
+
port: Number(process.env.PORT) || 3002,
|
|
99
|
+
host: process.env.HOST || "0.0.0.0",
|
|
100
|
+
environment: process.env.NODE_ENV || "development",
|
|
101
|
+
cors: {
|
|
102
|
+
origins: process.env.CORS_ORIGINS?.split(",") || [
|
|
103
|
+
"http://localhost:3000",
|
|
104
|
+
],
|
|
105
|
+
credentials: true,
|
|
106
|
+
},
|
|
107
|
+
rateLimiting: {
|
|
108
|
+
max: Number(process.env.RATE_LIMIT_MAX) || 200,
|
|
109
|
+
timeWindow: process.env.RATE_LIMIT_WINDOW || "1 minute",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
database: {
|
|
113
|
+
url: process.env.DATABASE_URL ||
|
|
114
|
+
"postgresql://postgres:password@localhost:5432/axova_compliance_db",
|
|
115
|
+
host: process.env.POSTGRES_HOST || "localhost",
|
|
116
|
+
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
117
|
+
user: process.env.POSTGRES_USER || "postgres",
|
|
118
|
+
password: process.env.POSTGRES_PASSWORD || "password",
|
|
119
|
+
database: process.env.POSTGRES_DB || "axova_compliance_db",
|
|
120
|
+
ssl: process.env.DB_SSL === "true",
|
|
121
|
+
poolSize: Number(process.env.DB_POOL_SIZE) || 15,
|
|
122
|
+
},
|
|
123
|
+
kafka: {
|
|
124
|
+
enabled: process.env.KAFKA_ENABLED !== "false",
|
|
125
|
+
clientId: process.env.KAFKA_CLIENT_ID || "compliance-service",
|
|
126
|
+
groupId: process.env.KAFKA_GROUP_ID || "compliance-service-group",
|
|
127
|
+
topics: [
|
|
128
|
+
"store.created",
|
|
129
|
+
"store.updated",
|
|
130
|
+
"compliance.violation.detected",
|
|
131
|
+
"compliance.violation.resolved",
|
|
132
|
+
"appeal.submitted",
|
|
133
|
+
"appeal.reviewed",
|
|
134
|
+
"store.suspended",
|
|
135
|
+
"store.unbanned",
|
|
136
|
+
"audit.logged",
|
|
137
|
+
],
|
|
138
|
+
autoCommit: process.env.KAFKA_AUTO_COMMIT !== "false",
|
|
139
|
+
},
|
|
140
|
+
audit: {
|
|
141
|
+
enabled: process.env.AUDIT_ENABLED !== "false",
|
|
142
|
+
level: process.env.AUDIT_LEVEL || "comprehensive",
|
|
143
|
+
bufferSize: Number(process.env.AUDIT_BUFFER_SIZE) || 200,
|
|
144
|
+
flushInterval: Number(process.env.AUDIT_FLUSH_INTERVAL) || 3000,
|
|
145
|
+
sensitiveFieldMasking: process.env.AUDIT_MASK_SENSITIVE !== "false",
|
|
146
|
+
},
|
|
147
|
+
features: {
|
|
148
|
+
realTimeMonitoring: true,
|
|
149
|
+
automaticViolationDetection: true,
|
|
150
|
+
appealManagement: true,
|
|
151
|
+
riskAssessment: true,
|
|
152
|
+
complianceReporting: true,
|
|
153
|
+
auditTrails: true,
|
|
154
|
+
escalationMatrix: true,
|
|
155
|
+
mlBasedDetection: process.env.ENABLE_ML_DETECTION === "true",
|
|
156
|
+
},
|
|
157
|
+
customConfig: {
|
|
158
|
+
violationThresholds: {
|
|
159
|
+
low: 3,
|
|
160
|
+
medium: 5,
|
|
161
|
+
high: 2,
|
|
162
|
+
critical: 1,
|
|
163
|
+
},
|
|
164
|
+
appealProcessing: {
|
|
165
|
+
autoReviewEnabled: process.env.AUTO_REVIEW_APPEALS === "true",
|
|
166
|
+
maxAppealTime: Number(process.env.MAX_APPEAL_TIME) || 72, // hours
|
|
167
|
+
escalationLevels: 3,
|
|
168
|
+
},
|
|
169
|
+
suspensionRules: {
|
|
170
|
+
automaticSuspension: process.env.AUTO_SUSPEND === "true",
|
|
171
|
+
gracePeriod: Number(process.env.SUSPENSION_GRACE_PERIOD) || 24, // hours
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
exports.PRODUCT_SERVICE_PROFILE = {
|
|
176
|
+
base: {
|
|
177
|
+
serviceName: "product-service",
|
|
178
|
+
port: Number(process.env.PORT) || 3003,
|
|
179
|
+
host: process.env.HOST || "0.0.0.0",
|
|
180
|
+
environment: process.env.NODE_ENV || "development",
|
|
181
|
+
cors: {
|
|
182
|
+
origins: process.env.CORS_ORIGINS?.split(",") || [
|
|
183
|
+
"http://localhost:3000",
|
|
184
|
+
],
|
|
185
|
+
credentials: true,
|
|
186
|
+
},
|
|
187
|
+
rateLimiting: {
|
|
188
|
+
max: Number(process.env.RATE_LIMIT_MAX) || 500,
|
|
189
|
+
timeWindow: process.env.RATE_LIMIT_WINDOW || "1 minute",
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
database: {
|
|
193
|
+
url: process.env.DATABASE_URL ||
|
|
194
|
+
"postgresql://postgres:password@localhost:5432/axova_product_db",
|
|
195
|
+
host: process.env.POSTGRES_HOST || "localhost",
|
|
196
|
+
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
197
|
+
user: process.env.POSTGRES_USER || "postgres",
|
|
198
|
+
password: process.env.POSTGRES_PASSWORD || "password",
|
|
199
|
+
database: process.env.POSTGRES_DB || "axova_product_db",
|
|
200
|
+
ssl: process.env.DB_SSL === "true",
|
|
201
|
+
poolSize: Number(process.env.DB_POOL_SIZE) || 20,
|
|
202
|
+
},
|
|
203
|
+
kafka: {
|
|
204
|
+
enabled: process.env.KAFKA_ENABLED !== "false",
|
|
205
|
+
clientId: process.env.KAFKA_CLIENT_ID || "product-service",
|
|
206
|
+
groupId: process.env.KAFKA_GROUP_ID || "product-service-group",
|
|
207
|
+
topics: [
|
|
208
|
+
"product.created",
|
|
209
|
+
"product.updated",
|
|
210
|
+
"product.deleted",
|
|
211
|
+
"variant.created",
|
|
212
|
+
"variant.updated",
|
|
213
|
+
"variant.deleted",
|
|
214
|
+
"collection.created",
|
|
215
|
+
"collection.updated",
|
|
216
|
+
"collection.deleted",
|
|
217
|
+
"inventory.updated",
|
|
218
|
+
],
|
|
219
|
+
autoCommit: process.env.KAFKA_AUTO_COMMIT !== "false",
|
|
220
|
+
},
|
|
221
|
+
redis: {
|
|
222
|
+
host: process.env.REDIS_HOST || "localhost",
|
|
223
|
+
port: Number(process.env.REDIS_PORT) || 6379,
|
|
224
|
+
password: process.env.REDIS_PASSWORD,
|
|
225
|
+
db: Number(process.env.REDIS_DB) || 1,
|
|
226
|
+
ttl: Number(process.env.REDIS_TTL) || 7200,
|
|
227
|
+
},
|
|
228
|
+
audit: {
|
|
229
|
+
enabled: process.env.AUDIT_ENABLED !== "false",
|
|
230
|
+
level: process.env.AUDIT_LEVEL || "standard",
|
|
231
|
+
bufferSize: Number(process.env.AUDIT_BUFFER_SIZE) || 150,
|
|
232
|
+
flushInterval: Number(process.env.AUDIT_FLUSH_INTERVAL) || 4000,
|
|
233
|
+
sensitiveFieldMasking: process.env.AUDIT_MASK_SENSITIVE !== "false",
|
|
234
|
+
},
|
|
235
|
+
features: {
|
|
236
|
+
searchOptimization: true,
|
|
237
|
+
imageProcessing: true,
|
|
238
|
+
variantManagement: true,
|
|
239
|
+
collectionManagement: true,
|
|
240
|
+
bulkOperations: true,
|
|
241
|
+
seoOptimization: true,
|
|
242
|
+
analyticsIntegration: true,
|
|
243
|
+
recommendationEngine: process.env.ENABLE_RECOMMENDATIONS === "true",
|
|
244
|
+
},
|
|
245
|
+
customConfig: {
|
|
246
|
+
searchConfig: {
|
|
247
|
+
indexingEnabled: process.env.SEARCH_INDEXING !== "false",
|
|
248
|
+
elasticsearchUrl: process.env.ELASTICSEARCH_URL,
|
|
249
|
+
algoliaAppId: process.env.ALGOLIA_APP_ID,
|
|
250
|
+
algoliaApiKey: process.env.ALGOLIA_API_KEY,
|
|
251
|
+
},
|
|
252
|
+
imageProcessing: {
|
|
253
|
+
maxFileSize: Number(process.env.MAX_IMAGE_SIZE) || 10485760, // 10MB
|
|
254
|
+
allowedFormats: ["jpg", "jpeg", "png", "webp"],
|
|
255
|
+
autoOptimization: process.env.AUTO_OPTIMIZE_IMAGES !== "false",
|
|
256
|
+
},
|
|
257
|
+
productLimits: {
|
|
258
|
+
maxVariants: Number(process.env.MAX_VARIANTS_PER_PRODUCT) || 100,
|
|
259
|
+
maxImages: Number(process.env.MAX_IMAGES_PER_PRODUCT) || 20,
|
|
260
|
+
maxCategories: Number(process.env.MAX_CATEGORIES_PER_PRODUCT) || 5,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
exports.INVENTORY_SERVICE_PROFILE = {
|
|
265
|
+
base: {
|
|
266
|
+
serviceName: "inventory-core-service",
|
|
267
|
+
port: Number(process.env.PORT) || 3005,
|
|
268
|
+
host: process.env.HOST || "0.0.0.0",
|
|
269
|
+
environment: process.env.NODE_ENV || "development",
|
|
270
|
+
cors: {
|
|
271
|
+
origins: process.env.CORS_ORIGINS?.split(",") || [
|
|
272
|
+
"http://localhost:3000",
|
|
273
|
+
],
|
|
274
|
+
credentials: true,
|
|
275
|
+
},
|
|
276
|
+
rateLimiting: {
|
|
277
|
+
max: Number(process.env.RATE_LIMIT_MAX) || 300,
|
|
278
|
+
timeWindow: process.env.RATE_LIMIT_WINDOW || "1 minute",
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
database: {
|
|
282
|
+
url: process.env.DATABASE_URL ||
|
|
283
|
+
"postgresql://postgres:password@localhost:5432/inventory_core_db",
|
|
284
|
+
host: process.env.DB_HOST || "localhost",
|
|
285
|
+
port: Number(process.env.DB_PORT) || 5432,
|
|
286
|
+
user: process.env.DB_USER || "postgres",
|
|
287
|
+
password: process.env.DB_PASSWORD || "password",
|
|
288
|
+
database: process.env.DB_NAME || "inventory_core_db",
|
|
289
|
+
ssl: process.env.DB_SSL === "true",
|
|
290
|
+
poolSize: Number(process.env.DB_POOL_SIZE) || 15,
|
|
291
|
+
},
|
|
292
|
+
kafka: {
|
|
293
|
+
enabled: process.env.KAFKA_ENABLED !== "false",
|
|
294
|
+
clientId: process.env.KAFKA_CLIENT_ID || "inventory-core-service",
|
|
295
|
+
groupId: process.env.KAFKA_GROUP_ID || "inventory-core-group",
|
|
296
|
+
topics: [
|
|
297
|
+
"inventory.created",
|
|
298
|
+
"inventory.updated",
|
|
299
|
+
"inventory.adjusted",
|
|
300
|
+
"inventory.reserved",
|
|
301
|
+
"inventory.released",
|
|
302
|
+
"warehouse.created",
|
|
303
|
+
"warehouse.updated",
|
|
304
|
+
"pos.location.created",
|
|
305
|
+
"pos.location.updated",
|
|
306
|
+
],
|
|
307
|
+
autoCommit: process.env.KAFKA_AUTO_COMMIT !== "false",
|
|
308
|
+
},
|
|
309
|
+
redis: {
|
|
310
|
+
host: process.env.REDIS_HOST || "localhost",
|
|
311
|
+
port: Number(process.env.REDIS_PORT) || 6379,
|
|
312
|
+
password: process.env.REDIS_PASSWORD,
|
|
313
|
+
db: Number(process.env.REDIS_DB) || 2,
|
|
314
|
+
ttl: Number(process.env.REDIS_TTL) || 1800,
|
|
315
|
+
},
|
|
316
|
+
audit: {
|
|
317
|
+
enabled: process.env.ENABLE_AUDIT_LOGGING !== "false",
|
|
318
|
+
level: process.env.AUDIT_LEVEL || "comprehensive",
|
|
319
|
+
bufferSize: Number(process.env.AUDIT_BUFFER_SIZE) || 200,
|
|
320
|
+
flushInterval: Number(process.env.AUDIT_FLUSH_INTERVAL) || 3000,
|
|
321
|
+
sensitiveFieldMasking: process.env.AUDIT_MASK_SENSITIVE !== "false",
|
|
322
|
+
},
|
|
323
|
+
features: {
|
|
324
|
+
realTimeSync: process.env.ENABLE_REAL_TIME_SYNC !== "false",
|
|
325
|
+
batchProcessing: process.env.ENABLE_BATCH_PROCESSING !== "false",
|
|
326
|
+
warehouseManagement: true,
|
|
327
|
+
posLocationManagement: true,
|
|
328
|
+
inventoryReservations: true,
|
|
329
|
+
movementTracking: true,
|
|
330
|
+
qualityControl: true,
|
|
331
|
+
supplierManagement: true,
|
|
332
|
+
},
|
|
333
|
+
customConfig: {
|
|
334
|
+
inventoryLimits: {
|
|
335
|
+
maxReservationTime: Number(process.env.MAX_RESERVATION_TIME) || 1440, // minutes
|
|
336
|
+
lowStockThreshold: Number(process.env.LOW_STOCK_THRESHOLD) || 10,
|
|
337
|
+
criticalStockThreshold: Number(process.env.CRITICAL_STOCK_THRESHOLD) || 5,
|
|
338
|
+
},
|
|
339
|
+
warehouseConfig: {
|
|
340
|
+
maxWarehouses: Number(process.env.MAX_WAREHOUSES) || 100,
|
|
341
|
+
maxLocationsPerWarehouse: Number(process.env.MAX_LOCATIONS_PER_WAREHOUSE) || 1000,
|
|
342
|
+
},
|
|
343
|
+
posConfig: {
|
|
344
|
+
maxPosLocations: Number(process.env.MAX_POS_LOCATIONS) || 500,
|
|
345
|
+
syncInterval: Number(process.env.POS_SYNC_INTERVAL) || 300, // seconds
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
exports.ADMIN_API_SERVICE_PROFILE = {
|
|
350
|
+
base: {
|
|
351
|
+
serviceName: "admin-api-service",
|
|
352
|
+
port: Number(process.env.PORT) || 3004,
|
|
353
|
+
host: process.env.HOST || "0.0.0.0",
|
|
354
|
+
environment: process.env.NODE_ENV || "development",
|
|
355
|
+
cors: {
|
|
356
|
+
origins: process.env.CORS_ORIGINS?.split(",") || [
|
|
357
|
+
"http://localhost:3000",
|
|
358
|
+
],
|
|
359
|
+
credentials: true,
|
|
360
|
+
},
|
|
361
|
+
rateLimiting: {
|
|
362
|
+
max: Number(process.env.RATE_LIMIT_MAX) || 100,
|
|
363
|
+
timeWindow: process.env.RATE_LIMIT_WINDOW || "1 minute",
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
database: {
|
|
367
|
+
url: process.env.DATABASE_URL ||
|
|
368
|
+
"postgresql://postgres:password@localhost:5432/axova_admin_db",
|
|
369
|
+
host: process.env.POSTGRES_HOST || "localhost",
|
|
370
|
+
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
371
|
+
user: process.env.POSTGRES_USER || "postgres",
|
|
372
|
+
password: process.env.POSTGRES_PASSWORD || "password",
|
|
373
|
+
database: process.env.POSTGRES_DB || "axova_admin_db",
|
|
374
|
+
ssl: process.env.DB_SSL === "true",
|
|
375
|
+
poolSize: Number(process.env.DB_POOL_SIZE) || 10,
|
|
376
|
+
},
|
|
377
|
+
kafka: {
|
|
378
|
+
enabled: process.env.KAFKA_ENABLED !== "false",
|
|
379
|
+
clientId: process.env.KAFKA_CLIENT_ID || "admin-api-service",
|
|
380
|
+
groupId: process.env.KAFKA_GROUP_ID || "admin-api-service-group",
|
|
381
|
+
topics: [
|
|
382
|
+
"admin.action.performed",
|
|
383
|
+
"user.created",
|
|
384
|
+
"user.updated",
|
|
385
|
+
"user.deleted",
|
|
386
|
+
"system.configuration.changed",
|
|
387
|
+
"audit.requested",
|
|
388
|
+
],
|
|
389
|
+
autoCommit: process.env.KAFKA_AUTO_COMMIT !== "false",
|
|
390
|
+
},
|
|
391
|
+
audit: {
|
|
392
|
+
enabled: process.env.AUDIT_ENABLED !== "false",
|
|
393
|
+
level: process.env.AUDIT_LEVEL || "comprehensive",
|
|
394
|
+
bufferSize: Number(process.env.AUDIT_BUFFER_SIZE) || 50,
|
|
395
|
+
flushInterval: Number(process.env.AUDIT_FLUSH_INTERVAL) || 2000,
|
|
396
|
+
sensitiveFieldMasking: process.env.AUDIT_MASK_SENSITIVE !== "false",
|
|
397
|
+
},
|
|
398
|
+
features: {
|
|
399
|
+
userManagement: true,
|
|
400
|
+
systemConfiguration: true,
|
|
401
|
+
auditReporting: true,
|
|
402
|
+
complianceMonitoring: true,
|
|
403
|
+
serviceManagement: true,
|
|
404
|
+
analyticsAccess: true,
|
|
405
|
+
backupManagement: true,
|
|
406
|
+
securityMonitoring: true,
|
|
407
|
+
},
|
|
408
|
+
customConfig: {
|
|
409
|
+
adminSecurity: {
|
|
410
|
+
mfaRequired: process.env.ADMIN_MFA_REQUIRED !== "false",
|
|
411
|
+
sessionTimeout: Number(process.env.ADMIN_SESSION_TIMEOUT) || 1800, // seconds
|
|
412
|
+
maxLoginAttempts: Number(process.env.MAX_LOGIN_ATTEMPTS) || 3,
|
|
413
|
+
},
|
|
414
|
+
permissions: {
|
|
415
|
+
superAdminRoles: process.env.SUPER_ADMIN_ROLES?.split(",") || [
|
|
416
|
+
"super_admin",
|
|
417
|
+
],
|
|
418
|
+
adminRoles: process.env.ADMIN_ROLES?.split(",") || [
|
|
419
|
+
"admin",
|
|
420
|
+
"super_admin",
|
|
421
|
+
],
|
|
422
|
+
moderatorRoles: process.env.MODERATOR_ROLES?.split(",") || [
|
|
423
|
+
"moderator",
|
|
424
|
+
"admin",
|
|
425
|
+
"super_admin",
|
|
426
|
+
],
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
};
|
|
430
|
+
exports.OXA_SERVICE_PROFILE = {
|
|
431
|
+
base: {
|
|
432
|
+
serviceName: "oxa-service",
|
|
433
|
+
port: Number(process.env.PORT) || 3010,
|
|
434
|
+
host: process.env.HOST || "0.0.0.0",
|
|
435
|
+
environment: process.env.NODE_ENV || "development",
|
|
436
|
+
cors: {
|
|
437
|
+
origins: process.env.CORS_ORIGINS?.split(",") || [
|
|
438
|
+
"http://localhost:3000",
|
|
439
|
+
"http://localhost:3010",
|
|
440
|
+
],
|
|
441
|
+
credentials: true,
|
|
442
|
+
},
|
|
443
|
+
rateLimiting: {
|
|
444
|
+
max: Number(process.env.RATE_LIMIT_MAX) || 600,
|
|
445
|
+
timeWindow: process.env.RATE_LIMIT_WINDOW || "1 minute",
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
database: {
|
|
449
|
+
url: process.env.DATABASE_URL ||
|
|
450
|
+
"postgresql://postgres:password@localhost:5432/axova_oxa_db",
|
|
451
|
+
host: process.env.POSTGRES_HOST || "localhost",
|
|
452
|
+
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
453
|
+
user: process.env.POSTGRES_USER || "postgres",
|
|
454
|
+
password: process.env.POSTGRES_PASSWORD || "password",
|
|
455
|
+
database: process.env.POSTGRES_DB || "axova_oxa_db",
|
|
456
|
+
ssl: process.env.DB_SSL === "true",
|
|
457
|
+
poolSize: Number(process.env.DB_POOL_SIZE) || 10,
|
|
458
|
+
},
|
|
459
|
+
kafka: {
|
|
460
|
+
enabled: process.env.KAFKA_ENABLED === "true",
|
|
461
|
+
clientId: process.env.KAFKA_CLIENT_ID || "oxa-service",
|
|
462
|
+
groupId: process.env.KAFKA_GROUP_ID || "oxa-service-group",
|
|
463
|
+
topics: ["audit.logged", "notification.send"],
|
|
464
|
+
autoCommit: process.env.KAFKA_AUTO_COMMIT !== "false",
|
|
465
|
+
},
|
|
466
|
+
audit: {
|
|
467
|
+
enabled: process.env.AUDIT_ENABLED !== "false",
|
|
468
|
+
level: process.env.AUDIT_LEVEL || "comprehensive",
|
|
469
|
+
bufferSize: Number(process.env.AUDIT_BUFFER_SIZE) || 100,
|
|
470
|
+
flushInterval: Number(process.env.AUDIT_FLUSH_INTERVAL) || 5000,
|
|
471
|
+
sensitiveFieldMasking: process.env.AUDIT_MASK_SENSITIVE !== "false",
|
|
472
|
+
},
|
|
473
|
+
features: {
|
|
474
|
+
aiChat: true,
|
|
475
|
+
aiStreaming: true,
|
|
476
|
+
embeddings: true,
|
|
477
|
+
moderation: true,
|
|
478
|
+
tracing: process.env.OXA_TRACING === "true",
|
|
479
|
+
ratelimit: true,
|
|
480
|
+
},
|
|
481
|
+
customConfig: {
|
|
482
|
+
oxa: {
|
|
483
|
+
defaultModel: process.env.OXA_DEFAULT_MODEL || "gpt-4o-mini",
|
|
484
|
+
defaultEmbeddingModel: process.env.OXA_EMBEDDING_MODEL || "text-embedding-3-small",
|
|
485
|
+
requestTimeoutMs: Number(process.env.OXA_REQUEST_TIMEOUT_MS) || 60000,
|
|
486
|
+
maxRetries: Number(process.env.OXA_MAX_RETRIES) || 2,
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
exports.SERVICE_PROFILES = {
|
|
491
|
+
"store-service": exports.STORE_SERVICE_PROFILE,
|
|
492
|
+
"compliance-service": exports.COMPLIANCE_SERVICE_PROFILE,
|
|
493
|
+
"product-service": exports.PRODUCT_SERVICE_PROFILE,
|
|
494
|
+
"inventory-core-service": exports.INVENTORY_SERVICE_PROFILE,
|
|
495
|
+
"admin-api-service": exports.ADMIN_API_SERVICE_PROFILE,
|
|
496
|
+
"oxa-service": exports.OXA_SERVICE_PROFILE,
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Get configuration profile for a specific service
|
|
500
|
+
*/
|
|
501
|
+
function getServiceProfile(serviceName) {
|
|
502
|
+
const profile = exports.SERVICE_PROFILES[serviceName];
|
|
503
|
+
if (!profile) {
|
|
504
|
+
throw new Error(`Unknown service: ${serviceName}`);
|
|
505
|
+
}
|
|
506
|
+
return profile;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Initialize service with its profile and return configured instances
|
|
510
|
+
*/
|
|
511
|
+
async function initializeServiceWithProfile(serviceName) {
|
|
512
|
+
const profile = getServiceProfile(serviceName);
|
|
513
|
+
// Get base configurations
|
|
514
|
+
const kafkaConfig = (0, kafka_1.getKafkaConfigFromEnv)();
|
|
515
|
+
const serviceAuthConfig = (0, serviceAuth_1.getServiceAuthConfigFromEnv)();
|
|
516
|
+
// Return initialized configuration
|
|
517
|
+
return {
|
|
518
|
+
profile,
|
|
519
|
+
kafkaConfig,
|
|
520
|
+
serviceAuthConfig,
|
|
521
|
+
// Add convenience methods
|
|
522
|
+
isFeatureEnabled: (feature) => profile.features[feature] === true,
|
|
523
|
+
getCustomConfig: (key) => profile.customConfig?.[key],
|
|
524
|
+
isDevelopment: () => profile.base.environment === "development",
|
|
525
|
+
isProduction: () => profile.base.environment === "production",
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Validate service configuration
|
|
530
|
+
*/
|
|
531
|
+
function validateServiceConfig(profile) {
|
|
532
|
+
const errors = [];
|
|
533
|
+
// Validate required fields
|
|
534
|
+
if (!profile.base.serviceName)
|
|
535
|
+
errors.push("Service name is required");
|
|
536
|
+
if (!profile.base.port ||
|
|
537
|
+
profile.base.port < 1 ||
|
|
538
|
+
profile.base.port > 65535) {
|
|
539
|
+
errors.push("Valid port number is required");
|
|
540
|
+
}
|
|
541
|
+
if (!profile.database.url)
|
|
542
|
+
errors.push("Database URL is required");
|
|
543
|
+
// Validate kafka configuration
|
|
544
|
+
if (profile.kafka.enabled && !profile.kafka.clientId) {
|
|
545
|
+
errors.push("Kafka client ID is required when Kafka is enabled");
|
|
546
|
+
}
|
|
547
|
+
// Validate audit configuration
|
|
548
|
+
if (profile.audit.enabled && profile.audit.bufferSize < 1) {
|
|
549
|
+
errors.push("Valid audit buffer size is required when audit is enabled");
|
|
550
|
+
}
|
|
551
|
+
return {
|
|
552
|
+
valid: errors.length === 0,
|
|
553
|
+
errors,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ConsumerConfig, type ProducerConfig } from "kafkajs";
|
|
2
|
+
import { type AxovaEvent, KAFKA_TOPICS, type KafkaTopic } from "../types/events";
|
|
3
|
+
export interface AxovaKafkaConfig {
|
|
4
|
+
brokers: string[];
|
|
5
|
+
clientId: string;
|
|
6
|
+
ssl?: boolean;
|
|
7
|
+
sasl?: {
|
|
8
|
+
mechanism: "plain";
|
|
9
|
+
username: string;
|
|
10
|
+
password: string;
|
|
11
|
+
} | {
|
|
12
|
+
mechanism: "scram-sha-256";
|
|
13
|
+
username: string;
|
|
14
|
+
password: string;
|
|
15
|
+
} | {
|
|
16
|
+
mechanism: "scram-sha-512";
|
|
17
|
+
username: string;
|
|
18
|
+
password: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type EventHandler<T = unknown> = (event: T) => Promise<void>;
|
|
22
|
+
export declare class AxovaKafka {
|
|
23
|
+
private kafka;
|
|
24
|
+
private producer;
|
|
25
|
+
private consumers;
|
|
26
|
+
private eventHandlers;
|
|
27
|
+
constructor(config: AxovaKafkaConfig);
|
|
28
|
+
initializeProducer(config?: ProducerConfig): Promise<void>;
|
|
29
|
+
initializeConsumer(groupId: string, topics: KafkaTopic[], config?: ConsumerConfig): Promise<void>;
|
|
30
|
+
publishEvent(topic: KafkaTopic, event: AxovaEvent): Promise<void>;
|
|
31
|
+
publishEventsBatch(topic: KafkaTopic, events: AxovaEvent[]): Promise<void>;
|
|
32
|
+
onEvent<T extends AxovaEvent>(eventType: T["type"], handler: EventHandler<T>): void;
|
|
33
|
+
startConsuming(groupId: string): Promise<void>;
|
|
34
|
+
disconnect(): Promise<void>;
|
|
35
|
+
createEvent<T extends AxovaEvent>(type: T["type"], data: T["data"], source: string): T;
|
|
36
|
+
}
|
|
37
|
+
export declare function createKafkaInstance(config: AxovaKafkaConfig): AxovaKafka;
|
|
38
|
+
export declare function getKafkaInstance(): AxovaKafka;
|
|
39
|
+
export declare function getKafkaConfigFromEnv(): AxovaKafkaConfig;
|
|
40
|
+
export { KAFKA_TOPICS };
|