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] 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;