ozon-grabber 0.1.4 → 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.
- package/dist/index.js +43 -9
- 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
|
-
|
|
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 {
|
|
@@ -927,12 +958,15 @@ var cli = yargs(hideBin(process.argv)).scriptName("ozon-grabber").command(
|
|
|
927
958
|
if (isReturns) {
|
|
928
959
|
for (const item of order.items) {
|
|
929
960
|
try {
|
|
930
|
-
await markItemAsReturn(backendConfig, item.title, item.price);
|
|
931
|
-
|
|
961
|
+
const result = await markItemAsReturn(backendConfig, item.title, item.price);
|
|
962
|
+
if (result) {
|
|
963
|
+
console.log(`Marked item as return: ${item.title} (${item.price})`);
|
|
964
|
+
} else {
|
|
965
|
+
console.warn(`Could not find item to mark as return: ${item.title} (${item.price})`);
|
|
966
|
+
}
|
|
932
967
|
} catch (error) {
|
|
933
968
|
const message = error instanceof Error ? error.message : String(error);
|
|
934
|
-
console.error(`
|
|
935
|
-
throw error;
|
|
969
|
+
console.error(`Error marking item as return: ${message}`);
|
|
936
970
|
}
|
|
937
971
|
}
|
|
938
972
|
await updateSetting(backendConfig, "last_return_id", order.orderNumber);
|