fix: purchasing flawed mods from iron wake #802

Merged
Sainan merged 3 commits from vendor-fix into main 2025-01-18 02:11:52 -08:00
3 changed files with 24 additions and 22 deletions

8
package-lock.json generated
View File

@ -12,7 +12,7 @@
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"express": "^5", "express": "^5",
"mongoose": "^8.9.4", "mongoose": "^8.9.4",
"warframe-public-export-plus": "^0.5.22", "warframe-public-export-plus": "^0.5.23",
"warframe-riven-info": "^0.1.2", "warframe-riven-info": "^0.1.2",
"winston": "^3.17.0", "winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0" "winston-daily-rotate-file": "^5.0.0"
@ -3778,9 +3778,9 @@
} }
}, },
"node_modules/warframe-public-export-plus": { "node_modules/warframe-public-export-plus": {
"version": "0.5.22", "version": "0.5.23",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.22.tgz", "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.23.tgz",
"integrity": "sha512-IbOW7ndE17ceyd7IjRy1U1p3P0Q7Q1/E26N04+ha/gG5FIdLpZDR9kLzyHGlnBLDSl2Jro6rxgOq0wZ/0i0w3g==" "integrity": "sha512-AJLivzXpon+UDm+SYq3wIXiP4OXCDOgXvCG1VLawJrHW3VDff+NpsUJApBPA4S8oZ8N8NPyBVKBvuoF2Pplaeg=="
}, },
"node_modules/warframe-riven-info": { "node_modules/warframe-riven-info": {
"version": "0.1.2", "version": "0.1.2",

View File

@ -16,7 +16,7 @@
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"express": "^5", "express": "^5",
"mongoose": "^8.9.4", "mongoose": "^8.9.4",
"warframe-public-export-plus": "^0.5.22", "warframe-public-export-plus": "^0.5.23",
"warframe-riven-info": "^0.1.2", "warframe-riven-info": "^0.1.2",
"winston": "^3.17.0", "winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0" "winston-daily-rotate-file": "^5.0.0"

View File

@ -50,10 +50,9 @@ export const handlePurchase = async (
const inventoryChanges: IInventoryChanges = {}; const inventoryChanges: IInventoryChanges = {};
if (purchaseRequest.PurchaseParams.Source == 7) { if (purchaseRequest.PurchaseParams.Source == 7) {
const manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!); const manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
if (!manifest) { if (manifest) {
throw new Error(`unknown vendor id: ${purchaseRequest.PurchaseParams.SourceId!}`); const ItemId = (JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string })
} .ItemId;
const ItemId = (JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string }).ItemId;
const offer = manifest.VendorInfo.ItemManifest.find(x => x.Id.$oid == ItemId); const offer = manifest.VendorInfo.ItemManifest.find(x => x.Id.$oid == ItemId);
if (!offer) { if (!offer) {
throw new Error(`unknown vendor offer: ${ItemId}`); throw new Error(`unknown vendor offer: ${ItemId}`);
@ -67,6 +66,9 @@ export const handlePurchase = async (
); );
} }
purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier; purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier;
} else if (!ExportVendors[purchaseRequest.PurchaseParams.SourceId!]) {
throw new Error(`unknown vendor: ${purchaseRequest.PurchaseParams.SourceId!}`);
coderabbitai[bot] commented 2025-01-17 22:10:49 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add error handling for JSON parsing.

The JSON.parse operation could throw if ExtraPurchaseInfoJson is malformed. Consider adding try-catch block to handle parsing errors gracefully.

-            const ItemId = (JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string })
-                .ItemId;
+            let ItemId: string;
+            try {
+                const parsed = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string };
+                if (typeof parsed.ItemId !== 'string') {
+                    throw new Error('Invalid ItemId type');
+                }
+                ItemId = parsed.ItemId;
+            } catch (error) {
+                throw new Error(`Failed to parse vendor purchase info: ${error.message}`);
+            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

            let ItemId: string;
            try {
                const parsed = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string };
                if (typeof parsed.ItemId !== 'string') {
                    throw new Error('Invalid ItemId type');
                }
                ItemId = parsed.ItemId;
            } catch (error) {
                throw new Error(`Failed to parse vendor purchase info: ${error.message}`);
            }
_:hammer_and_wrench: Refactor suggestion_ **Add error handling for JSON parsing.** The JSON.parse operation could throw if `ExtraPurchaseInfoJson` is malformed. Consider adding try-catch block to handle parsing errors gracefully. ```diff - const ItemId = (JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string }) - .ItemId; + let ItemId: string; + try { + const parsed = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string }; + if (typeof parsed.ItemId !== 'string') { + throw new Error('Invalid ItemId type'); + } + ItemId = parsed.ItemId; + } catch (error) { + throw new Error(`Failed to parse vendor purchase info: ${error.message}`); + } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion let ItemId: string; try { const parsed = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string }; if (typeof parsed.ItemId !== 'string') { throw new Error('Invalid ItemId type'); } ItemId = parsed.ItemId; } catch (error) { throw new Error(`Failed to parse vendor purchase info: ${error.message}`); } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
}
} }
const purchaseResponse = await handleStoreItemAcquisition( const purchaseResponse = await handleStoreItemAcquisition(
@ -126,7 +128,7 @@ export const handlePurchase = async (
if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) { if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) {
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!]; const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
if (offer) { if (offer && offer.itemPrices) {
await handleItemPrices( await handleItemPrices(
accountId, accountId,
offer.itemPrices, offer.itemPrices,