vantuz 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +45 -45
  2. package/admin-keygen.js +51 -0
  3. package/cli.js +685 -585
  4. package/config.js +733 -733
  5. package/core/agent-loop.js +190 -190
  6. package/core/ai-provider.js +298 -261
  7. package/core/automation.js +523 -523
  8. package/core/brand-analyst.js +101 -0
  9. package/core/channels.js +167 -167
  10. package/core/dashboard.js +230 -230
  11. package/core/database.js +135 -36
  12. package/core/eia-monitor.js +3 -1
  13. package/core/engine.js +648 -636
  14. package/core/gateway.js +447 -447
  15. package/core/learning.js +214 -214
  16. package/core/license.js +113 -0
  17. package/core/marketplace-adapter.js +168 -168
  18. package/core/memory.js +190 -190
  19. package/core/migrations/001-initial-schema.sql +1 -1
  20. package/core/queue.js +120 -120
  21. package/core/self-healer.js +314 -314
  22. package/core/unified-product.js +214 -214
  23. package/core/vision-service.js +113 -113
  24. package/index.js +217 -174
  25. package/modules/crm/sentiment-crm.js +231 -231
  26. package/modules/healer/listing-healer.js +201 -201
  27. package/modules/oracle/predictor.js +214 -214
  28. package/modules/researcher/agent.js +169 -169
  29. package/modules/team/agents/base.js +92 -92
  30. package/modules/team/agents/dev.js +33 -33
  31. package/modules/team/agents/josh.js +40 -40
  32. package/modules/team/agents/marketing.js +33 -33
  33. package/modules/team/agents/milo.js +36 -36
  34. package/modules/team/index.js +78 -78
  35. package/modules/team/shared-memory.js +87 -87
  36. package/modules/war-room/competitor-tracker.js +250 -250
  37. package/modules/war-room/pricing-engine.js +308 -308
  38. package/nodes/warehouse.js +238 -238
  39. package/onboard.js +1 -1
  40. package/package.json +7 -6
  41. package/platforms/pttavm.js +14 -14
  42. package/plugins/vantuz/index.js +528 -528
  43. package/plugins/vantuz/memory/hippocampus.js +465 -464
  44. package/plugins/vantuz/package.json +20 -20
  45. package/plugins/vantuz/platforms/_template.js +118 -118
  46. package/plugins/vantuz/platforms/amazon.js +236 -236
  47. package/plugins/vantuz/platforms/ciceksepeti.js +166 -166
  48. package/plugins/vantuz/platforms/hepsiburada.js +180 -180
  49. package/plugins/vantuz/platforms/index.js +165 -165
  50. package/plugins/vantuz/platforms/n11.js +229 -229
  51. package/plugins/vantuz/platforms/pazarama.js +154 -154
  52. package/plugins/vantuz/platforms/pttavm.js +127 -127
  53. package/plugins/vantuz/platforms/trendyol.js +326 -326
  54. package/plugins/vantuz/services/alerts.js +253 -253
  55. package/plugins/vantuz/services/license.js +34 -34
  56. package/plugins/vantuz/services/scheduler.js +232 -232
  57. package/plugins/vantuz/tools/analytics.js +152 -152
  58. package/plugins/vantuz/tools/crossborder.js +187 -187
  59. package/plugins/vantuz/tools/nl-parser.js +211 -211
  60. package/plugins/vantuz/tools/product.js +110 -110
  61. package/plugins/vantuz/tools/quick-report.js +175 -175
  62. package/plugins/vantuz/tools/repricer.js +314 -314
  63. package/plugins/vantuz/tools/sentiment.js +115 -115
  64. package/plugins/vantuz/tools/vision.js +257 -257
  65. package/private.pem +28 -0
  66. package/public.pem +9 -0
  67. package/server/app.js +260 -260
  68. package/server/public/index.html +514 -514
  69. package/start.bat +33 -33
  70. package/vantuz.sqlite +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
+ };