@simonfestl/husky-cli 1.13.0 → 1.14.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/dist/index.js +1 -0
- package/dist/lib/biz/wattiz-playwright.js +205 -55
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -115,7 +115,6 @@ export class WattizPlaywrightClient {
|
|
|
115
115
|
if (!passwordInput) {
|
|
116
116
|
throw new Error('Could not find password input field');
|
|
117
117
|
}
|
|
118
|
-
console.log(`Using selectors: email="${emailInput}", password="${passwordInput}"`);
|
|
119
118
|
// Fill in login form
|
|
120
119
|
await page.fill(emailInput, this.config.username);
|
|
121
120
|
await page.fill(passwordInput, this.config.password);
|
|
@@ -142,24 +141,13 @@ export class WattizPlaywrightClient {
|
|
|
142
141
|
await page.waitForLoadState('networkidle', { timeout: 15000 }).catch(() => { });
|
|
143
142
|
// Check if logged in by looking for my-account page or logged-in indicators
|
|
144
143
|
const currentUrl = page.url();
|
|
145
|
-
console.log('After login, current URL:', currentUrl);
|
|
146
|
-
// Check for error messages first
|
|
147
|
-
const errorMsg = await page.locator('.alert-danger, .error-message, .ps-alert-error').textContent().catch(() => '');
|
|
148
|
-
if (errorMsg) {
|
|
149
|
-
console.log('Error message on page:', errorMsg.trim());
|
|
150
|
-
}
|
|
151
144
|
const isLoggedIn = currentUrl.includes('/my-account') ||
|
|
152
145
|
currentUrl.includes('/mon-compte') ||
|
|
153
146
|
await page.locator('.account-link').count() > 0 ||
|
|
154
147
|
await page.locator('[data-link-action="sign-out"]').count() > 0 ||
|
|
155
148
|
await page.locator('.logout, .sign-out').count() > 0 ||
|
|
156
149
|
await page.locator('a[href*="logout"]').count() > 0;
|
|
157
|
-
console.log('Is logged in:', isLoggedIn);
|
|
158
150
|
if (!isLoggedIn) {
|
|
159
|
-
// Save debug HTML
|
|
160
|
-
const debugHtml = await page.content();
|
|
161
|
-
await fs.promises.writeFile('/tmp/wattiz-after-login.html', debugHtml);
|
|
162
|
-
console.log('Debug HTML saved to /tmp/wattiz-after-login.html');
|
|
163
151
|
return {
|
|
164
152
|
success: false,
|
|
165
153
|
cookies: '',
|
|
@@ -200,16 +188,38 @@ export class WattizPlaywrightClient {
|
|
|
200
188
|
const count = await orderRows.count();
|
|
201
189
|
for (let i = 0; i < count; i++) {
|
|
202
190
|
const row = orderRows.nth(i);
|
|
203
|
-
// PrestaShop order structure
|
|
191
|
+
// PrestaShop order structure - get link for order ID
|
|
204
192
|
const orderLinkEl = row.locator('a[href*="order-detail"]').first();
|
|
205
193
|
const orderLink = await orderLinkEl.getAttribute('href').catch(() => '');
|
|
206
194
|
// Extract order ID from PrestaShop controller URL
|
|
207
195
|
const orderIdMatch = orderLink?.match(/id_order=(\d+)/);
|
|
208
196
|
const orderId = orderIdMatch ? orderIdMatch[1] : '';
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
|
|
197
|
+
// Get all table cells
|
|
198
|
+
const cells = row.locator('td');
|
|
199
|
+
const cellCount = await cells.count();
|
|
200
|
+
// Wattiz order-history table structure (customized PrestaShop):
|
|
201
|
+
// Col 0: Date, Col 1: Total, Col 2: ?, Col 3: ?, Col 4: Status, Col 5: Actions
|
|
202
|
+
// Order reference is in the link or we use order ID
|
|
203
|
+
let orderNumber = orderId;
|
|
204
|
+
let date = '';
|
|
205
|
+
let total = '';
|
|
206
|
+
let status = '';
|
|
207
|
+
if (cellCount >= 2) {
|
|
208
|
+
// First cell contains Date
|
|
209
|
+
date = (await cells.nth(0).textContent().catch(() => '')) || '';
|
|
210
|
+
// Second cell contains Total
|
|
211
|
+
total = (await cells.nth(1).textContent().catch(() => '')) || '';
|
|
212
|
+
}
|
|
213
|
+
if (cellCount >= 5) {
|
|
214
|
+
// Status is in column 5 (index 4)
|
|
215
|
+
status = (await cells.nth(4).textContent().catch(() => '')) || '';
|
|
216
|
+
}
|
|
217
|
+
// Try to find actual order reference in row text
|
|
218
|
+
const rowText = await row.textContent().catch(() => '') || '';
|
|
219
|
+
const refMatch = rowText.match(/WATTIZ[A-Z0-9]+|[A-Z]{2,}[0-9]{6,}/i);
|
|
220
|
+
if (refMatch) {
|
|
221
|
+
orderNumber = refMatch[0];
|
|
222
|
+
}
|
|
213
223
|
if (orderId) {
|
|
214
224
|
orders.push({
|
|
215
225
|
id: orderId,
|
|
@@ -226,62 +236,202 @@ export class WattizPlaywrightClient {
|
|
|
226
236
|
async getOrder(orderId) {
|
|
227
237
|
const page = await this.ensureBrowser();
|
|
228
238
|
// PrestaShop controller-based URL
|
|
229
|
-
await page.goto(`${this.config.baseUrl}/${this.config.language}/index.php?controller=order-detail&id_order=${orderId}
|
|
230
|
-
|
|
239
|
+
await page.goto(`${this.config.baseUrl}/${this.config.language}/index.php?controller=order-detail&id_order=${orderId}`, {
|
|
240
|
+
waitUntil: 'domcontentloaded',
|
|
241
|
+
timeout: 30000
|
|
242
|
+
});
|
|
243
|
+
await page.waitForLoadState('domcontentloaded').catch(() => { });
|
|
231
244
|
// Check if we need to login
|
|
232
|
-
const needsLogin =
|
|
245
|
+
const needsLogin = page.url().includes('/login');
|
|
233
246
|
if (needsLogin) {
|
|
234
247
|
await this.login();
|
|
235
|
-
await page.goto(`${this.config.baseUrl}/${this.config.language}/index.php?controller=order-detail&id_order=${orderId}
|
|
236
|
-
|
|
248
|
+
await page.goto(`${this.config.baseUrl}/${this.config.language}/index.php?controller=order-detail&id_order=${orderId}`, {
|
|
249
|
+
waitUntil: 'domcontentloaded',
|
|
250
|
+
timeout: 30000
|
|
251
|
+
});
|
|
252
|
+
await page.waitForLoadState('domcontentloaded').catch(() => { });
|
|
237
253
|
}
|
|
238
|
-
// Extract order information
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
254
|
+
// Extract order information from Wattiz order detail page
|
|
255
|
+
// Use order ID as the order number (Wattiz doesn't display a separate reference)
|
|
256
|
+
const orderNumber = orderId;
|
|
257
|
+
let orderDate = '';
|
|
258
|
+
let orderStatus = '';
|
|
259
|
+
// Get visible page text for pattern matching
|
|
260
|
+
const pageText = await page.locator('body').textContent().catch(() => '') || '';
|
|
261
|
+
// Find date - look for format DD/MM/YYYY or YYYY-MM-DD
|
|
262
|
+
const dateMatches = pageText.match(/\b(\d{2}[\/\-]\d{2}[\/\-]20\d{2}|20\d{2}[\/\-]\d{2}[\/\-]\d{2})\b/g);
|
|
263
|
+
if (dateMatches && dateMatches.length > 0 && dateMatches[0]) {
|
|
264
|
+
orderDate = dateMatches[0];
|
|
265
|
+
}
|
|
266
|
+
// Get status - look for common shipping status text
|
|
267
|
+
const statusPatterns = ['Shipped', 'Delivered', 'Processing', 'Pending', 'Cancelled', 'En cours', 'Expédié', 'Livré'];
|
|
268
|
+
for (const pattern of statusPatterns) {
|
|
269
|
+
if (pageText.includes(pattern)) {
|
|
270
|
+
orderStatus = pattern;
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// Also try status elements if no pattern found
|
|
275
|
+
if (!orderStatus) {
|
|
276
|
+
const statusSelectors = ['.label.bright', '.badge', '.order-status'];
|
|
277
|
+
for (const selector of statusSelectors) {
|
|
278
|
+
const statusText = await page.locator(selector).first().textContent().catch(() => '');
|
|
279
|
+
if (statusText && statusText.length > 2 && statusText.length < 25 && !statusText.includes('€')) {
|
|
280
|
+
orderStatus = statusText.trim();
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// Extract customer info from address blocks
|
|
243
286
|
let customerName = '';
|
|
244
287
|
let customerAddress = '';
|
|
245
288
|
let customerEmail = '';
|
|
246
289
|
let customerPhone = '';
|
|
247
290
|
try {
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
291
|
+
// PrestaShop uses .address class for address blocks
|
|
292
|
+
const addressBlocks = page.locator('.address, article.address');
|
|
293
|
+
const blockCount = await addressBlocks.count();
|
|
294
|
+
for (let i = 0; i < blockCount; i++) {
|
|
295
|
+
const block = addressBlocks.nth(i);
|
|
296
|
+
const addressText = await block.textContent() || '';
|
|
297
|
+
const lines = addressText.split('\n').map(l => l.trim()).filter(l => l && l.length > 1);
|
|
298
|
+
// First line is usually the name
|
|
299
|
+
if (lines.length > 0 && !customerName) {
|
|
300
|
+
customerName = lines[0];
|
|
301
|
+
}
|
|
302
|
+
// Combine address lines (skip name, email, phone)
|
|
303
|
+
if (lines.length > 1 && !customerAddress) {
|
|
304
|
+
customerAddress = lines.slice(1)
|
|
305
|
+
.filter(l => !l.includes('@') && !l.match(/^\+?\d[\d\s\-]+$/))
|
|
306
|
+
.join(', ');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// Try to find customer email (exclude wattiz domain)
|
|
310
|
+
const mailLinks = await page.locator('[href^="mailto:"]').all();
|
|
311
|
+
for (const link of mailLinks) {
|
|
312
|
+
const href = await link.getAttribute('href').catch(() => '') || '';
|
|
313
|
+
const email = href.replace('mailto:', '');
|
|
314
|
+
if (email && !email.includes('wattiz')) {
|
|
315
|
+
customerEmail = email;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// Fallback: look for email pattern in address blocks (exclude wattiz)
|
|
320
|
+
if (!customerEmail) {
|
|
321
|
+
for (let i = 0; i < blockCount; i++) {
|
|
322
|
+
const blockText = await addressBlocks.nth(i).textContent().catch(() => '') || '';
|
|
323
|
+
const emailMatch = blockText.match(/[\w.+-]+@[\w.-]+\.\w+/);
|
|
324
|
+
if (emailMatch && !emailMatch[0].includes('wattiz')) {
|
|
325
|
+
customerEmail = emailMatch[0];
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
257
330
|
customerPhone = await page.locator('[href^="tel:"]').first().textContent().catch(() => '') || '';
|
|
258
331
|
}
|
|
259
332
|
catch (error) {
|
|
260
333
|
// Customer details not available
|
|
261
334
|
}
|
|
262
|
-
// Extract line items
|
|
335
|
+
// Extract line items from product table
|
|
336
|
+
// Look for the products section specifically
|
|
263
337
|
const items = [];
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
338
|
+
// Try different selectors for the product table
|
|
339
|
+
const productSelectors = [
|
|
340
|
+
'#order-products table tbody tr',
|
|
341
|
+
'.order-products tbody tr',
|
|
342
|
+
'[id*="product"] table tbody tr',
|
|
343
|
+
'table.table-striped tbody tr'
|
|
344
|
+
];
|
|
345
|
+
let productRows = null;
|
|
346
|
+
for (const selector of productSelectors) {
|
|
347
|
+
const rows = page.locator(selector);
|
|
348
|
+
const count = await rows.count();
|
|
349
|
+
if (count > 0) {
|
|
350
|
+
// Check if first row looks like a product (not a date or header)
|
|
351
|
+
const firstRowText = await rows.first().textContent().catch(() => '') || '';
|
|
352
|
+
if (!firstRowText.match(/^\d{4}[\/\-]\d{2}/) && firstRowText.length > 10) {
|
|
353
|
+
productRows = rows;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (productRows) {
|
|
359
|
+
const itemCount = await productRows.count();
|
|
360
|
+
for (let i = 0; i < itemCount; i++) {
|
|
361
|
+
const itemRow = productRows.nth(i);
|
|
362
|
+
const rowText = await itemRow.textContent() || '';
|
|
363
|
+
// Skip rows that look like dates or headers
|
|
364
|
+
if (rowText.match(/^\s*\d{4}[\/\-]\d{2}/) || rowText.includes('Product') || rowText.trim().length < 5) {
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const cells = itemRow.locator('td');
|
|
368
|
+
const cellCount = await cells.count();
|
|
369
|
+
if (cellCount >= 2) {
|
|
370
|
+
const nameCell = await cells.nth(0).textContent() || '';
|
|
371
|
+
const name = nameCell.replace(/\s+/g, ' ').trim();
|
|
372
|
+
let qty = '1';
|
|
373
|
+
let total = '';
|
|
374
|
+
// Find quantity and price cells
|
|
375
|
+
for (let c = 1; c < cellCount; c++) {
|
|
376
|
+
const cellText = (await cells.nth(c).textContent() || '').trim();
|
|
377
|
+
if (cellText.match(/^\d+$/) && parseInt(cellText, 10) < 1000) {
|
|
378
|
+
qty = cellText;
|
|
379
|
+
}
|
|
380
|
+
else if (cellText.includes('€') || cellText.includes('$')) {
|
|
381
|
+
total = cellText;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
// Only add if name looks like a product
|
|
385
|
+
if (name && name.length > 5 && !name.match(/^\d{4}[\/\-]/)) {
|
|
386
|
+
items.push({
|
|
387
|
+
sku: '',
|
|
388
|
+
name: name,
|
|
389
|
+
quantity: parseInt(qty, 10) || 1,
|
|
390
|
+
price: '',
|
|
391
|
+
total: total,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
278
396
|
}
|
|
279
397
|
// Look for invoice link
|
|
280
|
-
const invoiceLink = await page.locator('a[href*="invoice"], a
|
|
281
|
-
// Extract total
|
|
282
|
-
|
|
398
|
+
const invoiceLink = await page.locator('a[href*="pdf-invoice"], a[href*="get-invoice"], a[href*="invoice"]').first().getAttribute('href').catch(() => '');
|
|
399
|
+
// Extract total - look for price patterns in page
|
|
400
|
+
let totalText = '';
|
|
401
|
+
// Look for total amount in page text
|
|
402
|
+
const priceMatches = pageText.match(/€\s*[\d,]+\.?\d*/g) || [];
|
|
403
|
+
if (priceMatches.length > 0) {
|
|
404
|
+
// Get the largest price as total (usually the order total)
|
|
405
|
+
let maxPrice = 0;
|
|
406
|
+
let maxPriceText = '';
|
|
407
|
+
for (const priceText of priceMatches) {
|
|
408
|
+
const value = parseFloat(priceText.replace('€', '').replace(/\s/g, '').replace(',', '.'));
|
|
409
|
+
if (value > maxPrice) {
|
|
410
|
+
maxPrice = value;
|
|
411
|
+
maxPriceText = priceText.trim();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (maxPriceText) {
|
|
415
|
+
totalText = maxPriceText;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
// Fallback: try specific selectors
|
|
419
|
+
if (!totalText) {
|
|
420
|
+
const totalSelectors = [
|
|
421
|
+
'.order-totals tr:last-child td:last-child',
|
|
422
|
+
'.total-value',
|
|
423
|
+
'table tfoot td:last-child'
|
|
424
|
+
];
|
|
425
|
+
for (const selector of totalSelectors) {
|
|
426
|
+
const text = await page.locator(selector).last().textContent().catch(() => '');
|
|
427
|
+
if (text && text.includes('€')) {
|
|
428
|
+
totalText = text.trim();
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
283
433
|
// Extract tracking number if available
|
|
284
|
-
const trackingNumber = await page.locator('.tracking-number, [href*="track"]').first().textContent().catch(() => '');
|
|
434
|
+
const trackingNumber = await page.locator('.tracking-number, [href*="track"], [data-tracking]').first().textContent().catch(() => '');
|
|
285
435
|
return {
|
|
286
436
|
id: orderId,
|
|
287
437
|
orderNumber: orderNumber?.trim() || orderId,
|