vantuz 3.4.2 → 3.5.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.
Files changed (92) hide show
  1. package/.env.example +21 -0
  2. package/.openclaw/completions/openclaw.bash +227 -0
  3. package/.openclaw/completions/openclaw.fish +1552 -0
  4. package/.openclaw/completions/openclaw.ps1 +1966 -0
  5. package/.openclaw/completions/openclaw.zsh +3571 -0
  6. package/.openclaw/gateway.cmd +10 -0
  7. package/.openclaw/identity/device.json +7 -0
  8. package/.openclaw/openclaw.json +40 -0
  9. package/.windsurf/workflows/vantuz-dev.md +31 -0
  10. package/DOCS_TR.md +80 -0
  11. package/LICENSE +45 -45
  12. package/README.md +52 -21
  13. package/cli.js +685 -585
  14. package/config.js +733 -733
  15. package/core/agent-loop.js +190 -190
  16. package/core/ai-provider.js +298 -261
  17. package/core/automation.js +523 -523
  18. package/core/brand-analyst.js +101 -0
  19. package/core/channels.js +167 -167
  20. package/core/dashboard.js +230 -230
  21. package/core/database.js +135 -37
  22. package/core/eia-monitor.js +3 -1
  23. package/core/engine.js +648 -636
  24. package/core/gateway.js +447 -447
  25. package/core/learning.js +214 -214
  26. package/core/license.js +113 -0
  27. package/core/marketplace-adapter.js +168 -168
  28. package/core/memory.js +190 -190
  29. package/core/migrations/001-initial-schema.sql +1 -1
  30. package/core/queue.js +120 -120
  31. package/core/self-healer.js +314 -314
  32. package/core/unified-product.js +214 -214
  33. package/core/vision-service.js +113 -113
  34. package/index.js +217 -174
  35. package/modules/crm/sentiment-crm.js +231 -231
  36. package/modules/healer/listing-healer.js +201 -201
  37. package/modules/oracle/predictor.js +214 -214
  38. package/modules/researcher/agent.js +169 -169
  39. package/modules/team/agents/base.js +92 -92
  40. package/modules/team/agents/dev.js +33 -33
  41. package/modules/team/agents/josh.js +40 -40
  42. package/modules/team/agents/marketing.js +33 -33
  43. package/modules/team/agents/milo.js +36 -36
  44. package/modules/team/index.js +78 -78
  45. package/modules/team/shared-memory.js +87 -87
  46. package/modules/war-room/competitor-tracker.js +250 -250
  47. package/modules/war-room/pricing-engine.js +308 -308
  48. package/n11docs.md +1680 -0
  49. package/nodes/warehouse.js +238 -238
  50. package/onboard.js +1 -1
  51. package/openclawdocs.md +3 -0
  52. package/package.json +7 -5
  53. package/platforms/pttavm.js +14 -14
  54. package/plugins/vantuz/index.js +528 -528
  55. package/plugins/vantuz/memory/hippocampus.js +465 -465
  56. package/plugins/vantuz/package.json +20 -20
  57. package/plugins/vantuz/platforms/_template.js +118 -118
  58. package/plugins/vantuz/platforms/amazon.js +236 -236
  59. package/plugins/vantuz/platforms/ciceksepeti.js +166 -166
  60. package/plugins/vantuz/platforms/hepsiburada.js +180 -180
  61. package/plugins/vantuz/platforms/index.js +165 -165
  62. package/plugins/vantuz/platforms/n11.js +229 -229
  63. package/plugins/vantuz/platforms/pazarama.js +154 -154
  64. package/plugins/vantuz/platforms/pttavm.js +127 -127
  65. package/plugins/vantuz/platforms/trendyol.js +326 -326
  66. package/plugins/vantuz/services/alerts.js +253 -253
  67. package/plugins/vantuz/services/license.js +34 -34
  68. package/plugins/vantuz/services/scheduler.js +232 -232
  69. package/plugins/vantuz/tools/analytics.js +152 -152
  70. package/plugins/vantuz/tools/crossborder.js +187 -187
  71. package/plugins/vantuz/tools/nl-parser.js +211 -211
  72. package/plugins/vantuz/tools/product.js +110 -110
  73. package/plugins/vantuz/tools/quick-report.js +175 -175
  74. package/plugins/vantuz/tools/repricer.js +314 -314
  75. package/plugins/vantuz/tools/sentiment.js +115 -115
  76. package/plugins/vantuz/tools/vision.js +257 -257
  77. package/public.pem +9 -0
  78. package/server/app.js +260 -260
  79. package/server/public/index.html +514 -514
  80. package/start.bat +33 -33
  81. package/vantuz.sqlite +0 -0
  82. package/workspace/AGENTS.md +73 -0
  83. package/workspace/BRAND.md +29 -0
  84. package/workspace/SOUL.md +72 -0
  85. package/workspace/team/DECISIONS.md +3 -0
  86. package/workspace/team/GOALS.md +3 -0
  87. package/workspace/team/PROJECT_STATUS.md +3 -0
  88. package/workspace/team/agents/dev/SOUL.md +12 -0
  89. package/workspace/team/agents/josh/SOUL.md +12 -0
  90. package/workspace/team/agents/marketing/SOUL.md +12 -0
  91. package/workspace/team/agents/milo/SOUL.md +12 -0
  92. package/vantuz-3.3.4.tgz +0 -0
@@ -1,314 +1,314 @@
1
- /**
2
- * 🩸 KAN EMİCİ (Blood Sucker) - Akıllı Fiyat Robotu
3
- *
4
- * Rakip fiyatlarını 7/24 izler ama aptal değil:
5
- * - Rakip fiyat düşürdüyse körü körüne takip etmez
6
- * - Stok durumuna, kar marjına ve satış hızına bakar
7
- * - Rakip stoku bitiyorsa fiyatı yükseltir
8
- */
9
-
10
- import platformHub from '../platforms/index.js';
11
-
12
- export const repricerTool = {
13
- name: 'repricer',
14
-
15
- async execute(params, context) {
16
- const { api, memory, license } = context;
17
- const { barcode, platform = 'all', targetMargin = 20, action = 'analyze' } = params;
18
-
19
- // Lisans kontrolü (demo modda da çalışsın)
20
- const isDemo = license?.isDemo?.() ?? true;
21
- if (isDemo) {
22
- api?.logger?.info('🔓 Demo modda çalışıyor...');
23
- }
24
-
25
- // Ürün bilgilerini al
26
- const product = await this._getProduct(barcode, platform);
27
- if (!product) {
28
- return { success: false, error: 'Ürün bulunamadı.' };
29
- }
30
-
31
- // Hafızadan geçmiş bağlamı al
32
- let historyContext = { recentDecisions: [], productHistory: [] };
33
- if (memory?.getRelevantContext) {
34
- historyContext = await memory.getRelevantContext(barcode, {
35
- barcode,
36
- type: 'decision'
37
- });
38
- }
39
-
40
- // Rakip fiyatlarını topla
41
- const competitors = await this._fetchCompetitorPrices(barcode, platform);
42
-
43
- // Analiz yap
44
- const analysis = this._analyzeAndDecide({
45
- product,
46
- competitors,
47
- targetMargin,
48
- history: historyContext.recentDecisions,
49
- productContext: historyContext.productHistory
50
- });
51
-
52
- // Kararı hafızaya kaydet
53
- if (memory?.recordPricingDecision) {
54
- await memory.recordPricingDecision({
55
- productId: product.id,
56
- barcode,
57
- platform,
58
- previousPrice: product.price,
59
- newPrice: analysis.recommendedPrice,
60
- reason: analysis.reason,
61
- factors: analysis.factors,
62
- outcome: action === 'apply' ? 'applied' : 'pending',
63
- profitImpact: analysis.profitImpact
64
- });
65
- }
66
-
67
- // Eğer action = apply ise fiyatı güncelle
68
- if (action === 'apply' && analysis.shouldChange && !isDemo) {
69
- await this._applyPrice(product, analysis.recommendedPrice, platform);
70
- }
71
-
72
- return {
73
- success: true,
74
- product: {
75
- name: product.name,
76
- barcode,
77
- currentPrice: product.price,
78
- cost: product.cost
79
- },
80
- analysis: {
81
- recommendedPrice: analysis.recommendedPrice,
82
- reason: analysis.reason,
83
- shouldChange: analysis.shouldChange,
84
- profitImpact: analysis.profitImpact,
85
- competitorSummary: analysis.competitorSummary
86
- },
87
- applied: action === 'apply' && analysis.shouldChange && !isDemo
88
- };
89
- },
90
-
91
- _analyzeAndDecide({ product, competitors, targetMargin, history, productContext }) {
92
- const { price: currentPrice, cost } = product;
93
- const minPrice = cost * (1 + targetMargin / 100);
94
-
95
- // Rakip analizi
96
- const activeCompetitors = competitors.filter(c => c.stock > 0);
97
- const lowestCompetitorPrice = activeCompetitors.length > 0
98
- ? Math.min(...activeCompetitors.map(c => c.price))
99
- : null;
100
-
101
- // Rakip stok durumu
102
- const lowStockCompetitors = competitors.filter(c => c.stock > 0 && c.stock < 5);
103
- const outOfStockCompetitors = competitors.filter(c => c.stock === 0);
104
-
105
- let recommendedPrice = currentPrice;
106
- let reason = '';
107
- let shouldChange = false;
108
-
109
- // KARAR MANTIĞI
110
-
111
- // Senaryo 1: Rakiplerin çoğu stoksuz
112
- if (outOfStockCompetitors.length >= competitors.length * 0.6 && competitors.length > 0) {
113
- recommendedPrice = Math.round(currentPrice * 1.15);
114
- reason = `🔥 Rakiplerin %${Math.round(outOfStockCompetitors.length / competitors.length * 100)}'i stoksuz. Fiyat artışı önerilir.`;
115
- shouldChange = true;
116
- }
117
- // Senaryo 2: En yakın rakip düşük stoklu
118
- else if (lowStockCompetitors.length > 0 && lowestCompetitorPrice) {
119
- const lowestStockCompetitor = lowStockCompetitors.sort((a, b) => a.price - b.price)[0];
120
- if (lowestStockCompetitor && lowestStockCompetitor.price <= currentPrice) {
121
- recommendedPrice = Math.round(currentPrice * 1.05);
122
- reason = `⏳ Rakip fiyatı düşük ama stoku kritik (${lowestStockCompetitor.stock} adet). Bekleyince müşteri bize gelecek.`;
123
- shouldChange = currentPrice < recommendedPrice;
124
- }
125
- }
126
- // Senaryo 3: Rakip fiyatı bizden düşük ve stoku bol
127
- else if (lowestCompetitorPrice && lowestCompetitorPrice < currentPrice * 0.95) {
128
- if (lowestCompetitorPrice >= minPrice) {
129
- recommendedPrice = Math.round(lowestCompetitorPrice * 0.99);
130
- reason = `📉 Rakip fiyatı düşürmüş (${lowestCompetitorPrice} ₺). Kar marjı uygun, takip ediyoruz.`;
131
- shouldChange = true;
132
- } else {
133
- recommendedPrice = minPrice;
134
- reason = `⚠️ Rakip fiyatı çok düşük (${lowestCompetitorPrice} ₺) ama minimum marjın (${targetMargin}%) altına inemeyiz.`;
135
- shouldChange = currentPrice > minPrice;
136
- }
137
- }
138
- // Senaryo 4: Fiyatımız çok düşük, artırabiliriz
139
- else if (lowestCompetitorPrice && currentPrice < lowestCompetitorPrice * 0.9) {
140
- recommendedPrice = Math.round(lowestCompetitorPrice * 0.95);
141
- reason = `📈 Fiyatımız gereksiz düşük. Rakip fiyatına yaklaştırılıyor.`;
142
- shouldChange = true;
143
- }
144
- // Senaryo 5: Stabil piyasa veya rakip yok
145
- else {
146
- reason = competitors.length > 0
147
- ? `✅ Fiyat optimal seviyede. Değişiklik gerekmiyor.`
148
- : `ℹ️ Rakip verisi bulunamadı.`;
149
- shouldChange = false;
150
- }
151
-
152
- // Kar etkisi hesapla
153
- const currentProfit = currentPrice - cost;
154
- const newProfit = recommendedPrice - cost;
155
- const profitImpact = currentProfit > 0
156
- ? ((newProfit - currentProfit) / currentProfit * 100).toFixed(1)
157
- : 0;
158
-
159
- return {
160
- recommendedPrice,
161
- reason,
162
- shouldChange,
163
- profitImpact: parseFloat(profitImpact),
164
- competitorSummary: {
165
- total: competitors.length,
166
- active: activeCompetitors.length,
167
- lowStock: lowStockCompetitors.length,
168
- outOfStock: outOfStockCompetitors.length,
169
- lowestPrice: lowestCompetitorPrice
170
- },
171
- factors: {
172
- currentPrice,
173
- cost,
174
- minPrice,
175
- targetMargin,
176
- competitorCount: competitors.length,
177
- lowestCompetitorPrice
178
- }
179
- };
180
- },
181
-
182
- async analyzeCompetitors(barcode, context) {
183
- const competitors = await this._fetchCompetitorPrices(barcode, 'all');
184
- const product = await this._getProduct(barcode, 'all');
185
-
186
- return {
187
- product: product?.name || barcode,
188
- competitors: competitors.slice(0, 5),
189
- recommendation: this._generateRecommendation(competitors, product)
190
- };
191
- },
192
-
193
- async runAutoCycle(context) {
194
- const decisions = [];
195
-
196
- // Bağlı platformlardan ürünleri al
197
- const connected = platformHub.getConnected();
198
- if (connected.length === 0) return decisions;
199
-
200
- for (const platformName of connected) {
201
- const api = platformHub.resolve(platformName);
202
- if (!api) continue;
203
-
204
- try {
205
- const result = await api.getProducts({ size: 50 });
206
- if (!result?.success) continue;
207
-
208
- const products = result.data.content || result.data.products || result.data || [];
209
-
210
- for (const product of products.slice(0, 10)) {
211
- const barcode = product.barcode || product.sku || product.merchantSku;
212
- if (!barcode) continue;
213
-
214
- const analysisResult = await this.execute({
215
- barcode,
216
- platform: platformName,
217
- action: 'analyze'
218
- }, context);
219
-
220
- if (analysisResult.success && analysisResult.analysis.shouldChange) {
221
- decisions.push({
222
- barcode,
223
- name: product.title || product.name,
224
- platform: platformName,
225
- ...analysisResult.analysis
226
- });
227
- }
228
- }
229
- } catch (err) {
230
- // Hata durumunda devam et
231
- }
232
- }
233
-
234
- return decisions;
235
- },
236
-
237
- // === Private Methods ===
238
-
239
- async _getProduct(barcode, platform) {
240
- // Platformlardan ürün bilgisi al
241
- const platforms = platform === 'all'
242
- ? platformHub.getConnected()
243
- : [platform];
244
-
245
- for (const p of platforms) {
246
- const api = platformHub.resolve(p);
247
- if (!api?.getProducts) continue;
248
-
249
- try {
250
- const result = await api.getProducts({ barcode });
251
- if (result?.success) {
252
- const products = result.data.content || result.data.products || result.data || [];
253
- const product = products.find(item =>
254
- item.barcode === barcode ||
255
- item.sku === barcode ||
256
- item.merchantSku === barcode
257
- );
258
-
259
- if (product) {
260
- return {
261
- id: product.id || `${p}_${barcode}`,
262
- barcode,
263
- name: product.title || product.name || 'Ürün',
264
- price: product.salePrice || product.price || product.salesPrice || 0,
265
- cost: product.cost || (product.salePrice || product.price || 0) * 0.6, // Maliyet yoksa %60 varsay
266
- stock: product.quantity || product.stock || product.availableStock || 0,
267
- platform: p
268
- };
269
- }
270
- }
271
- } catch (e) {
272
- // Hata durumunda diğer platformu dene
273
- }
274
- }
275
-
276
- return null;
277
- },
278
-
279
- async _fetchCompetitorPrices(barcode, platform) {
280
- // Not: Rakip fiyat çekme genelde web scraping gerektirir
281
- // Bu versiyonda placeholder - ileride Brave Search veya özel scraper eklenebilir
282
- return [];
283
- },
284
-
285
- async _applyPrice(product, newPrice, platform) {
286
- const api = platformHub.resolve(platform);
287
- if (!api?.updatePrice) return false;
288
-
289
- try {
290
- const result = await api.updatePrice(product.barcode, newPrice);
291
- return result?.success || false;
292
- } catch (e) {
293
- return false;
294
- }
295
- },
296
-
297
- _generateRecommendation(competitors, product) {
298
- if (!product) return 'Ürün bulunamadı.';
299
-
300
- const activeCompetitors = competitors.filter(c => c.stock > 0);
301
- if (activeCompetitors.length === 0) {
302
- return competitors.length > 0
303
- ? '🔥 Tüm rakipler stoksuz! Fiyatı yükseltebilirsiniz.'
304
- : 'ℹ️ Rakip verisi bulunamadı.';
305
- }
306
-
307
- const lowestPrice = Math.min(...activeCompetitors.map(c => c.price));
308
- if (product.price < lowestPrice) {
309
- return `📈 Fiyatınız en düşük (${product.price} ₺). Artırabilirsiniz.`;
310
- }
311
-
312
- return `📊 Rakip fiyat aralığı: ${lowestPrice} - ${Math.max(...activeCompetitors.map(c => c.price))} ₺`;
313
- }
314
- };
1
+ /**
2
+ * 🩸 KAN EMİCİ (Blood Sucker) - Akıllı Fiyat Robotu
3
+ *
4
+ * Rakip fiyatlarını 7/24 izler ama aptal değil:
5
+ * - Rakip fiyat düşürdüyse körü körüne takip etmez
6
+ * - Stok durumuna, kar marjına ve satış hızına bakar
7
+ * - Rakip stoku bitiyorsa fiyatı yükseltir
8
+ */
9
+
10
+ import platformHub from '../platforms/index.js';
11
+
12
+ export const repricerTool = {
13
+ name: 'repricer',
14
+
15
+ async execute(params, context) {
16
+ const { api, memory, license } = context;
17
+ const { barcode, platform = 'all', targetMargin = 20, action = 'analyze' } = params;
18
+
19
+ // Lisans kontrolü (demo modda da çalışsın)
20
+ const isDemo = license?.isDemo?.() ?? true;
21
+ if (isDemo) {
22
+ api?.logger?.info('🔓 Demo modda çalışıyor...');
23
+ }
24
+
25
+ // Ürün bilgilerini al
26
+ const product = await this._getProduct(barcode, platform);
27
+ if (!product) {
28
+ return { success: false, error: 'Ürün bulunamadı.' };
29
+ }
30
+
31
+ // Hafızadan geçmiş bağlamı al
32
+ let historyContext = { recentDecisions: [], productHistory: [] };
33
+ if (memory?.getRelevantContext) {
34
+ historyContext = await memory.getRelevantContext(barcode, {
35
+ barcode,
36
+ type: 'decision'
37
+ });
38
+ }
39
+
40
+ // Rakip fiyatlarını topla
41
+ const competitors = await this._fetchCompetitorPrices(barcode, platform);
42
+
43
+ // Analiz yap
44
+ const analysis = this._analyzeAndDecide({
45
+ product,
46
+ competitors,
47
+ targetMargin,
48
+ history: historyContext.recentDecisions,
49
+ productContext: historyContext.productHistory
50
+ });
51
+
52
+ // Kararı hafızaya kaydet
53
+ if (memory?.recordPricingDecision) {
54
+ await memory.recordPricingDecision({
55
+ productId: product.id,
56
+ barcode,
57
+ platform,
58
+ previousPrice: product.price,
59
+ newPrice: analysis.recommendedPrice,
60
+ reason: analysis.reason,
61
+ factors: analysis.factors,
62
+ outcome: action === 'apply' ? 'applied' : 'pending',
63
+ profitImpact: analysis.profitImpact
64
+ });
65
+ }
66
+
67
+ // Eğer action = apply ise fiyatı güncelle
68
+ if (action === 'apply' && analysis.shouldChange && !isDemo) {
69
+ await this._applyPrice(product, analysis.recommendedPrice, platform);
70
+ }
71
+
72
+ return {
73
+ success: true,
74
+ product: {
75
+ name: product.name,
76
+ barcode,
77
+ currentPrice: product.price,
78
+ cost: product.cost
79
+ },
80
+ analysis: {
81
+ recommendedPrice: analysis.recommendedPrice,
82
+ reason: analysis.reason,
83
+ shouldChange: analysis.shouldChange,
84
+ profitImpact: analysis.profitImpact,
85
+ competitorSummary: analysis.competitorSummary
86
+ },
87
+ applied: action === 'apply' && analysis.shouldChange && !isDemo
88
+ };
89
+ },
90
+
91
+ _analyzeAndDecide({ product, competitors, targetMargin, history, productContext }) {
92
+ const { price: currentPrice, cost } = product;
93
+ const minPrice = cost * (1 + targetMargin / 100);
94
+
95
+ // Rakip analizi
96
+ const activeCompetitors = competitors.filter(c => c.stock > 0);
97
+ const lowestCompetitorPrice = activeCompetitors.length > 0
98
+ ? Math.min(...activeCompetitors.map(c => c.price))
99
+ : null;
100
+
101
+ // Rakip stok durumu
102
+ const lowStockCompetitors = competitors.filter(c => c.stock > 0 && c.stock < 5);
103
+ const outOfStockCompetitors = competitors.filter(c => c.stock === 0);
104
+
105
+ let recommendedPrice = currentPrice;
106
+ let reason = '';
107
+ let shouldChange = false;
108
+
109
+ // KARAR MANTIĞI
110
+
111
+ // Senaryo 1: Rakiplerin çoğu stoksuz
112
+ if (outOfStockCompetitors.length >= competitors.length * 0.6 && competitors.length > 0) {
113
+ recommendedPrice = Math.round(currentPrice * 1.15);
114
+ reason = `🔥 Rakiplerin %${Math.round(outOfStockCompetitors.length / competitors.length * 100)}'i stoksuz. Fiyat artışı önerilir.`;
115
+ shouldChange = true;
116
+ }
117
+ // Senaryo 2: En yakın rakip düşük stoklu
118
+ else if (lowStockCompetitors.length > 0 && lowestCompetitorPrice) {
119
+ const lowestStockCompetitor = lowStockCompetitors.sort((a, b) => a.price - b.price)[0];
120
+ if (lowestStockCompetitor && lowestStockCompetitor.price <= currentPrice) {
121
+ recommendedPrice = Math.round(currentPrice * 1.05);
122
+ reason = `⏳ Rakip fiyatı düşük ama stoku kritik (${lowestStockCompetitor.stock} adet). Bekleyince müşteri bize gelecek.`;
123
+ shouldChange = currentPrice < recommendedPrice;
124
+ }
125
+ }
126
+ // Senaryo 3: Rakip fiyatı bizden düşük ve stoku bol
127
+ else if (lowestCompetitorPrice && lowestCompetitorPrice < currentPrice * 0.95) {
128
+ if (lowestCompetitorPrice >= minPrice) {
129
+ recommendedPrice = Math.round(lowestCompetitorPrice * 0.99);
130
+ reason = `📉 Rakip fiyatı düşürmüş (${lowestCompetitorPrice} ₺). Kar marjı uygun, takip ediyoruz.`;
131
+ shouldChange = true;
132
+ } else {
133
+ recommendedPrice = minPrice;
134
+ reason = `⚠️ Rakip fiyatı çok düşük (${lowestCompetitorPrice} ₺) ama minimum marjın (${targetMargin}%) altına inemeyiz.`;
135
+ shouldChange = currentPrice > minPrice;
136
+ }
137
+ }
138
+ // Senaryo 4: Fiyatımız çok düşük, artırabiliriz
139
+ else if (lowestCompetitorPrice && currentPrice < lowestCompetitorPrice * 0.9) {
140
+ recommendedPrice = Math.round(lowestCompetitorPrice * 0.95);
141
+ reason = `📈 Fiyatımız gereksiz düşük. Rakip fiyatına yaklaştırılıyor.`;
142
+ shouldChange = true;
143
+ }
144
+ // Senaryo 5: Stabil piyasa veya rakip yok
145
+ else {
146
+ reason = competitors.length > 0
147
+ ? `✅ Fiyat optimal seviyede. Değişiklik gerekmiyor.`
148
+ : `ℹ️ Rakip verisi bulunamadı.`;
149
+ shouldChange = false;
150
+ }
151
+
152
+ // Kar etkisi hesapla
153
+ const currentProfit = currentPrice - cost;
154
+ const newProfit = recommendedPrice - cost;
155
+ const profitImpact = currentProfit > 0
156
+ ? ((newProfit - currentProfit) / currentProfit * 100).toFixed(1)
157
+ : 0;
158
+
159
+ return {
160
+ recommendedPrice,
161
+ reason,
162
+ shouldChange,
163
+ profitImpact: parseFloat(profitImpact),
164
+ competitorSummary: {
165
+ total: competitors.length,
166
+ active: activeCompetitors.length,
167
+ lowStock: lowStockCompetitors.length,
168
+ outOfStock: outOfStockCompetitors.length,
169
+ lowestPrice: lowestCompetitorPrice
170
+ },
171
+ factors: {
172
+ currentPrice,
173
+ cost,
174
+ minPrice,
175
+ targetMargin,
176
+ competitorCount: competitors.length,
177
+ lowestCompetitorPrice
178
+ }
179
+ };
180
+ },
181
+
182
+ async analyzeCompetitors(barcode, context) {
183
+ const competitors = await this._fetchCompetitorPrices(barcode, 'all');
184
+ const product = await this._getProduct(barcode, 'all');
185
+
186
+ return {
187
+ product: product?.name || barcode,
188
+ competitors: competitors.slice(0, 5),
189
+ recommendation: this._generateRecommendation(competitors, product)
190
+ };
191
+ },
192
+
193
+ async runAutoCycle(context) {
194
+ const decisions = [];
195
+
196
+ // Bağlı platformlardan ürünleri al
197
+ const connected = platformHub.getConnected();
198
+ if (connected.length === 0) return decisions;
199
+
200
+ for (const platformName of connected) {
201
+ const api = platformHub.resolve(platformName);
202
+ if (!api) continue;
203
+
204
+ try {
205
+ const result = await api.getProducts({ size: 50 });
206
+ if (!result?.success) continue;
207
+
208
+ const products = result.data.content || result.data.products || result.data || [];
209
+
210
+ for (const product of products.slice(0, 10)) {
211
+ const barcode = product.barcode || product.sku || product.merchantSku;
212
+ if (!barcode) continue;
213
+
214
+ const analysisResult = await this.execute({
215
+ barcode,
216
+ platform: platformName,
217
+ action: 'analyze'
218
+ }, context);
219
+
220
+ if (analysisResult.success && analysisResult.analysis.shouldChange) {
221
+ decisions.push({
222
+ barcode,
223
+ name: product.title || product.name,
224
+ platform: platformName,
225
+ ...analysisResult.analysis
226
+ });
227
+ }
228
+ }
229
+ } catch (err) {
230
+ // Hata durumunda devam et
231
+ }
232
+ }
233
+
234
+ return decisions;
235
+ },
236
+
237
+ // === Private Methods ===
238
+
239
+ async _getProduct(barcode, platform) {
240
+ // Platformlardan ürün bilgisi al
241
+ const platforms = platform === 'all'
242
+ ? platformHub.getConnected()
243
+ : [platform];
244
+
245
+ for (const p of platforms) {
246
+ const api = platformHub.resolve(p);
247
+ if (!api?.getProducts) continue;
248
+
249
+ try {
250
+ const result = await api.getProducts({ barcode });
251
+ if (result?.success) {
252
+ const products = result.data.content || result.data.products || result.data || [];
253
+ const product = products.find(item =>
254
+ item.barcode === barcode ||
255
+ item.sku === barcode ||
256
+ item.merchantSku === barcode
257
+ );
258
+
259
+ if (product) {
260
+ return {
261
+ id: product.id || `${p}_${barcode}`,
262
+ barcode,
263
+ name: product.title || product.name || 'Ürün',
264
+ price: product.salePrice || product.price || product.salesPrice || 0,
265
+ cost: product.cost || (product.salePrice || product.price || 0) * 0.6, // Maliyet yoksa %60 varsay
266
+ stock: product.quantity || product.stock || product.availableStock || 0,
267
+ platform: p
268
+ };
269
+ }
270
+ }
271
+ } catch (e) {
272
+ // Hata durumunda diğer platformu dene
273
+ }
274
+ }
275
+
276
+ return null;
277
+ },
278
+
279
+ async _fetchCompetitorPrices(barcode, platform) {
280
+ // Not: Rakip fiyat çekme genelde web scraping gerektirir
281
+ // Bu versiyonda placeholder - ileride Brave Search veya özel scraper eklenebilir
282
+ return [];
283
+ },
284
+
285
+ async _applyPrice(product, newPrice, platform) {
286
+ const api = platformHub.resolve(platform);
287
+ if (!api?.updatePrice) return false;
288
+
289
+ try {
290
+ const result = await api.updatePrice(product.barcode, newPrice);
291
+ return result?.success || false;
292
+ } catch (e) {
293
+ return false;
294
+ }
295
+ },
296
+
297
+ _generateRecommendation(competitors, product) {
298
+ if (!product) return 'Ürün bulunamadı.';
299
+
300
+ const activeCompetitors = competitors.filter(c => c.stock > 0);
301
+ if (activeCompetitors.length === 0) {
302
+ return competitors.length > 0
303
+ ? '🔥 Tüm rakipler stoksuz! Fiyatı yükseltebilirsiniz.'
304
+ : 'ℹ️ Rakip verisi bulunamadı.';
305
+ }
306
+
307
+ const lowestPrice = Math.min(...activeCompetitors.map(c => c.price));
308
+ if (product.price < lowestPrice) {
309
+ return `📈 Fiyatınız en düşük (${product.price} ₺). Artırabilirsiniz.`;
310
+ }
311
+
312
+ return `📊 Rakip fiyat aralığı: ${lowestPrice} - ${Math.max(...activeCompetitors.map(c => c.price))} ₺`;
313
+ }
314
+ };