diff --git a/package-lock.json b/package-lock.json index 14580188f..113407a05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.2.2", + "warframe-public-export-plus": "^0.2.3", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" @@ -3909,9 +3909,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.2.tgz", - "integrity": "sha512-PAsiyiRDqXcsUwZTweihwrSksd+GT3USrbHwS/TrJUC3TqLS0Ng24OfefFKPWOmPfMxDbdkg2zV39uq72iZ/Yg==" + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.3.tgz", + "integrity": "sha512-Bl4gb3f1LIdGXLEOJg2XTIFYqrialdTIvVhDqDzVJIRfii0PKsy9jsr9vqM14tWz7oVpQMeCUyvisDkkXijTSg==" }, "node_modules/warframe-riven-info": { "version": "0.1.0", diff --git a/package.json b/package.json index 88a714124..9da3bcca3 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.2.2", + "warframe-public-export-plus": "^0.2.3", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index ba13666a2..b8a1c1eaf 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -3,6 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers"; import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService"; import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; +import { ExportBundles } from "warframe-public-export-plus"; export const getStoreItemCategory = (storeItem: string) => { const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/"); @@ -21,26 +22,12 @@ export const getStoreItemTypesCategory = (typesItem: string) => { export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => { logger.debug("purchase request", purchaseRequest); - const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem); - const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", ""); - logger.debug(`store category ${storeCategory}`); - let purchaseResponse; - switch (storeCategory) { - default: - purchaseResponse = await addItem(accountId, internalName); - break; - case "Types": - purchaseResponse = await handleTypesPurchase( - internalName, - accountId, - purchaseRequest.PurchaseParams.Quantity - ); - break; - case "Boosters": - purchaseResponse = await handleBoostersPurchase(internalName, accountId); - break; - } + const purchaseResponse = await handleStoreItemAcquisition( + purchaseRequest.PurchaseParams.StoreItem, + accountId, + purchaseRequest.PurchaseParams.Quantity + ); if (!purchaseResponse) throw new Error("purchase response was undefined"); @@ -58,6 +45,43 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI return purchaseResponse; }; +const handleStoreItemAcquisition = async ( + storeItemName: string, + accountId: string, + quantity: number +): Promise<{ InventoryChanges: object }> => { + let purchaseResponse = { + InventoryChanges: {} + }; + logger.debug(`handling acquision of ${storeItemName}`); + if (storeItemName in ExportBundles) { + const bundle = ExportBundles[storeItemName]; + logger.debug("acquiring bundle", bundle); + for (const component of bundle.components) { + purchaseResponse = { + ...purchaseResponse, + ...(await handleStoreItemAcquisition(component.typeName, accountId, component.purchaseQuantity)) + }; + } + } else { + const storeCategory = getStoreItemCategory(storeItemName); + const internalName = storeItemName.replace("/StoreItems", ""); + logger.debug(`store category ${storeCategory}`); + switch (storeCategory) { + default: + purchaseResponse = await addItem(accountId, internalName); + break; + case "Types": + purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity); + break; + case "Boosters": + purchaseResponse = await handleBoostersPurchase(internalName, accountId); + break; + } + } + return purchaseResponse; +}; + export const slotPurchaseNameToSlotName: SlotPurchase = { SuitSlotItem: { name: "SuitBin", slotsPerPurchase: 1 }, TwoSentinelSlotItem: { name: "SentinelBin", slotsPerPurchase: 2 }, @@ -122,7 +146,9 @@ const boosterCollection = [ const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => { const match = boosterStoreName.match(/(\d+)Day/); - if (!match) return; + if (!match) { + return { InventoryChanges: {} }; + } const extractedDigit = Number(match[1]); const ItemType = boosterCollection.find(i =>