From b4e04a97b0216d514fbd1c7db2bdabd9fc18ee4f Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 19:11:39 +0200 Subject: [PATCH 1/3] add PurchaseSource enum --- src/controllers/api/giftingController.ts | 4 ++-- src/services/purchaseService.ts | 18 +++++++++----- src/types/purchaseTypes.ts | 30 +++++++++++++++++++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/controllers/api/giftingController.ts b/src/controllers/api/giftingController.ts index 55865cee..9a532776 100644 --- a/src/controllers/api/giftingController.ts +++ b/src/controllers/api/giftingController.ts @@ -11,13 +11,13 @@ import { import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService"; import { handleStoreItemAcquisition } from "@/src/services/purchaseService"; import { IOid } from "@/src/types/commonTypes"; -import { IInventoryChanges, IPurchaseParams } from "@/src/types/purchaseTypes"; +import { IInventoryChanges, IPurchaseParams, PurchaseSource } from "@/src/types/purchaseTypes"; import { RequestHandler } from "express"; import { ExportBundles, ExportFlavour } from "warframe-public-export-plus"; export const giftingController: RequestHandler = async (req, res) => { const data = getJSONfromString(String(req.body)); - if (data.PurchaseParams.Source != 0 || !data.PurchaseParams.UsePremium) { + if (data.PurchaseParams.Source != PurchaseSource.Market || !data.PurchaseParams.UsePremium) { throw new Error(`unexpected purchase params in gifting request: ${String(req.body)}`); } diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 4fb5bb2d..eeef731c 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -11,7 +11,13 @@ import { import { getRandomWeightedRewardUc } from "@/src/services/rngService"; import { applyStandingToVendorManifest, getVendorManifestByOid } from "@/src/services/serversideVendorsService"; import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; -import { IPurchaseRequest, IPurchaseResponse, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes"; +import { + IPurchaseRequest, + IPurchaseResponse, + SlotPurchase, + IInventoryChanges, + PurchaseSource +} from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; import worldState from "@/static/fixed_responses/worldState/worldState.json"; import { @@ -52,7 +58,7 @@ export const handlePurchase = async ( const prePurchaseInventoryChanges: IInventoryChanges = {}; let seed: bigint | undefined; - if (purchaseRequest.PurchaseParams.Source == 7) { + if (purchaseRequest.PurchaseParams.Source == PurchaseSource.Vendor) { let manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!); if (manifest) { manifest = applyStandingToVendorManifest(inventory, manifest); @@ -177,7 +183,7 @@ export const handlePurchase = async ( }; switch (purchaseRequest.PurchaseParams.Source) { - case 1: { + case PurchaseSource.VoidTrader: { if (purchaseRequest.PurchaseParams.SourceId! != worldState.VoidTraders[0]._id.$oid) { throw new Error("invalid request source"); } @@ -207,7 +213,7 @@ export const handlePurchase = async ( } break; } - case 2: + case PurchaseSource.SyndicateFavor: { const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!; if (purchaseRequest.PurchaseParams.UseFreeFavor!) { @@ -244,7 +250,7 @@ export const handlePurchase = async ( } } break; - case 7: + case PurchaseSource.Vendor: if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) { const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!]; const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); @@ -275,7 +281,7 @@ export const handlePurchase = async ( throw new Error(`vendor purchase should not have an expected price`); } break; - case 18: { + case PurchaseSource.PrimeVaultTrader: { if (purchaseRequest.PurchaseParams.SourceId! != worldState.PrimeVaultTraders[0]._id.$oid) { throw new Error("invalid request source"); } diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index 8cb92ccc..ad41ebff 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -10,13 +10,41 @@ import { ICrewMemberClient } from "./inventoryTypes/inventoryTypes"; +export enum PurchaseSource { + Market = 0, + VoidTrader = 1, + SyndicateFavor = 2, + DailyDeal = 3, + Arsenal = 4, + Profile = 5, + Hub = 6, + Vendor = 7, + AppearancePreview = 8, + Museum = 9, + Operator = 10, + PlayerShip = 11, + Crewship = 12, + MenuStyle = 13, + MenuHud = 14, + Chat = 15, + Inventory = 16, + StarChart = 17, + PrimeVaultTrader = 18, + Incubator = 19, + Prompt = 20, + Kaithe = 21, + DuviriWeapon = 22, + UpdateScreen = 23, + Motorcycle = 24 +} + export interface IPurchaseRequest { PurchaseParams: IPurchaseParams; buildLabel: string; } export interface IPurchaseParams { - Source: number; + Source: PurchaseSource; SourceId?: string; // for Source 1, 7 & 18 StoreItem: string; StorePage: string; -- 2.47.2 From 9eb9392b8b252622c73d453d7d89f4099edac129 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 19:18:43 +0200 Subject: [PATCH 2/3] simplify calls to updateCurrency in purchaseService --- src/services/purchaseService.ts | 34 ++++++++------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index eeef731c..56cc9ed7 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -75,18 +75,12 @@ export const handlePurchase = async ( } if (!config.dontSubtractPurchaseCreditCost) { if (offer.RegularPrice) { - combineInventoryChanges( - prePurchaseInventoryChanges, - updateCurrency(inventory, offer.RegularPrice[0], false) - ); + updateCurrency(inventory, offer.RegularPrice[0], false, prePurchaseInventoryChanges); } } if (!config.dontSubtractPurchasePlatinumCost) { if (offer.PremiumPrice) { - combineInventoryChanges( - prePurchaseInventoryChanges, - updateCurrency(inventory, offer.PremiumPrice[0], true) - ); + updateCurrency(inventory, offer.PremiumPrice[0], true, prePurchaseInventoryChanges); } } if (!config.dontSubtractPurchaseItemCost) { @@ -172,15 +166,12 @@ export const handlePurchase = async ( ); combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges); - const currencyChanges = updateCurrency( + updateCurrency( inventory, purchaseRequest.PurchaseParams.ExpectedPrice, - purchaseRequest.PurchaseParams.UsePremium + purchaseRequest.PurchaseParams.UsePremium, + prePurchaseInventoryChanges ); - purchaseResponse.InventoryChanges = { - ...currencyChanges, - ...purchaseResponse.InventoryChanges - }; switch (purchaseRequest.PurchaseParams.Source) { case PurchaseSource.VoidTrader: { @@ -192,10 +183,7 @@ export const handlePurchase = async ( ); if (offer) { if (!config.dontSubtractPurchaseCreditCost) { - combineInventoryChanges( - purchaseResponse.InventoryChanges, - updateCurrency(inventory, offer.RegularPrice, false) - ); + updateCurrency(inventory, offer.RegularPrice, false, purchaseResponse.InventoryChanges); } if (purchaseRequest.PurchaseParams.ExpectedPrice) { throw new Error(`vendor purchase should not have an expected price`); @@ -256,16 +244,10 @@ export const handlePurchase = async ( const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); if (offer) { if (typeof offer.credits == "number" && !config.dontSubtractPurchaseCreditCost) { - combineInventoryChanges( - purchaseResponse.InventoryChanges, - updateCurrency(inventory, offer.credits, false) - ); + updateCurrency(inventory, offer.credits, false, purchaseResponse.InventoryChanges); } if (typeof offer.platinum == "number" && !config.dontSubtractPurchasePlatinumCost) { - combineInventoryChanges( - purchaseResponse.InventoryChanges, - updateCurrency(inventory, offer.platinum, true) - ); + updateCurrency(inventory, offer.platinum, true, purchaseResponse.InventoryChanges); } if (offer.itemPrices && !config.dontSubtractPurchaseItemCost) { handleItemPrices( -- 2.47.2 From 9b07cf36e3c8634edce0ab5fed0b6bcae0329632 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Tue, 24 Jun 2025 01:37:01 +0200 Subject: [PATCH 3/3] update comments --- src/types/purchaseTypes.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index ad41ebff..0ccff176 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -45,7 +45,7 @@ export interface IPurchaseRequest { export interface IPurchaseParams { Source: PurchaseSource; - SourceId?: string; // for Source 1, 7 & 18 + SourceId?: string; // VoidTrader, Vendor, PrimeVaultTrader StoreItem: string; StorePage: string; SearchTerm: string; @@ -53,10 +53,10 @@ export interface IPurchaseParams { Quantity: number; UsePremium: boolean; ExpectedPrice: number; - SyndicateTag?: string; // for Source 2 - UseFreeFavor?: boolean; // for Source 2 - ExtraPurchaseInfoJson?: string; // for Source 7 - IsWeekly?: boolean; // for Source 7 + SyndicateTag?: string; // SyndicateFavor + UseFreeFavor?: boolean; // SyndicateFavor + ExtraPurchaseInfoJson?: string; // Vendor + IsWeekly?: boolean; // Vendor } export type IInventoryChanges = { -- 2.47.2