ozon-grabber 0.1.5 → 0.1.6

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 (2) hide show
  1. package/dist/index.js +36 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -581,20 +581,23 @@ var getOrderPageWidgetState = async (client, tools) => {
581
581
  function: `() => {
582
582
  const shipmentWidget = document.querySelector('[data-widget="shipmentWidget"]');
583
583
  const titleWidget = document.querySelector('[data-widget="titleWithTimer"]');
584
+ const returnWidget = document.querySelector('[data-widget="returnDetails"]');
584
585
  return {
585
586
  hasShipmentWidget: Boolean(shipmentWidget),
586
- hasTitleWithTimer: Boolean(titleWidget)
587
+ hasTitleWithTimer: Boolean(titleWidget),
588
+ hasReturnWidget: Boolean(returnWidget)
587
589
  };
588
590
  }`
589
591
  }
590
592
  });
591
593
  const payload = unwrapToolContent2(result.content);
592
594
  if (!isRecord3(payload)) {
593
- return { hasShipmentWidget: false, hasTitleWithTimer: false };
595
+ return { hasShipmentWidget: false, hasTitleWithTimer: false, hasReturnWidget: false };
594
596
  }
595
597
  return {
596
598
  hasShipmentWidget: Boolean(payload.hasShipmentWidget),
597
- hasTitleWithTimer: Boolean(payload.hasTitleWithTimer)
599
+ hasTitleWithTimer: Boolean(payload.hasTitleWithTimer),
600
+ hasReturnWidget: Boolean(payload.hasReturnWidget)
598
601
  };
599
602
  };
600
603
  var waitForOrderPageWidgets = async (client, tools, options, description, timeoutMs, predicate) => {
@@ -603,7 +606,8 @@ var waitForOrderPageWidgets = async (client, tools, options, description, timeou
603
606
  let attempts = 0;
604
607
  let state = {
605
608
  hasShipmentWidget: false,
606
- hasTitleWithTimer: false
609
+ hasTitleWithTimer: false,
610
+ hasReturnWidget: false
607
611
  };
608
612
  logMessage(options, `Waiting for ${description} (timeout ${timeoutMs}ms).`);
609
613
  while (true) {
@@ -659,7 +663,34 @@ var scanOrders = async (client, tools, userId, startOrder, options = {}) => {
659
663
  logMessage(options, `Opening ${options.isReturns ? "return" : "order"} ${orderId}`);
660
664
  await openPage(client, tools, url);
661
665
  if (options.isReturns) {
662
- const { hasReturnWidget } = await getReturnPageState(client, tools);
666
+ await waitForOrderPageWidgets(
667
+ client,
668
+ tools,
669
+ options,
670
+ "return page widgets",
671
+ pageLoadTimeoutMs,
672
+ (state) => state.hasReturnWidget
673
+ );
674
+ let { hasReturnWidget } = await getReturnPageState(client, tools);
675
+ if (!hasReturnWidget) {
676
+ logMessage(
677
+ options,
678
+ `No return widget detected for ${orderId}, retrying after ${pageLoadRetryDelayMs}ms.`
679
+ );
680
+ if (pageLoadRetryDelayMs > 0) {
681
+ await sleep(pageLoadRetryDelayMs);
682
+ }
683
+ await waitForOrderPageWidgets(
684
+ client,
685
+ tools,
686
+ options,
687
+ "returnDetails",
688
+ shipmentWidgetTimeoutMs,
689
+ (state) => state.hasReturnWidget
690
+ );
691
+ const updatedState = await getReturnPageState(client, tools);
692
+ hasReturnWidget = updatedState.hasReturnWidget;
693
+ }
663
694
  if (!hasReturnWidget) {
664
695
  logMessage(options, `Return widget missing for ${orderId}, stopping.`);
665
696
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ozon-grabber",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Ozon order history grabber CLI",
5
5
  "repository": {
6
6
  "type": "git",