Skip to content

Open-source Xbox-inspired desktop launcher for Xodus on Linux

TypeScript

Require authoritative game types in Store and search

domsvoboda68e4e233e3b1
diff --git a/src/main/catalog-game-kind.test.ts b/src/main/catalog-game-kind.test.ts
new file mode 100644
index 0000000..27341c0
--- /dev/null
+++ b/src/main/catalog-game-kind.test.ts
@@ -0,0 +1,48 @@
+import {expect,it} from 'vitest';
+import {CatalogService,parseCatalogProducts} from './catalog.js';
+const GAME='9AAAAAAAAAAA',BUNDLE='9BBBBBBBBBBB',DLC='9CCCCCCCCCCC',APP='9DDDDDDDDDDD';
+const row=(productId=GAME,extra={})=>({productId,title:'Synthetic product',isGame:true,...extra});
+const game=(ProductId=GAME,extra={})=>({ProductId,ProductType:'Game',LocalizedProperties:[{ProductTitle:'Synthetic game'}],...extra});
+it('accepts only authoritative root Games and never title, category, endpoint or positive isGame hints',()=>{
+ for(const ProductType of ['Application','Durable','GameAddOn','Consumable','AvatarItem','Pass','game','Unknown',null,undefined,42]){
+ expect(parseCatalogProducts({productsList:[row(GAME,{categories:['Games']})]},{Products:[{ProductId:GAME,ProductType}]},'store')).toEqual([]);
+ }
+ expect(parseCatalogProducts({productsList:[row()]},{Products:[]},'store')).toEqual([]);
+ expect(parseCatalogProducts({productsList:[row(GAME,{isGame:false})]},{Products:[game()]},'store')).toEqual([]);
+ expect(parseCatalogProducts({productsList:[row(GAME,{isGame:undefined})]},{Products:[game()]},'store')).toHaveLength(1);
+});
+it('retains Game bundles and unsupported Games without deriving the root kind from a bundled child',()=>{
+ const bundle=(ProductId:string,ProductType:string,child:string)=>({ProductId,ProductType,DisplaySkuAvailabilities:[{Sku:{Properties:{BundledSkus:[{BigId:child}]}}}]});
+ const details={Products:[bundle(BUNDLE,'Game',DLC),bundle(DLC,'Durable',GAME),game()]};
+ expect(parseCatalogProducts({productsList:[row(BUNDLE),row(DLC)]},details,'store').map(p=>p.productId)).toEqual([BUNDLE]);
+ // Unknown/unsupported package metadata changes installability, not game kind.
+ expect(parseCatalogProducts({productsList:[row()]},{Products:[game()]},'store')[0].installability).not.toBe('supported');
+});
+it('filters actual search, featured, pagination and Product ID queries with the same root policy',async()=>{
+ const requests:URL[]=[];
+ const records=[game(),game(BUNDLE,{DisplaySkuAvailabilities:[{Sku:{Properties:{BundledSkus:[{BigId:DLC}]}}}]}),{ProductId:DLC,ProductType:'Durable'},{ProductId:APP,ProductType:'Application'}];
+ const service=new CatalogService((async(input:URL|RequestInfo)=>{
+ const url=new URL(String(input));requests.push(url);
+ if(url.hostname==='displaycatalog.mp.microsoft.com'){
+ const ids=url.searchParams.get('bigIds')!.split(',');return new Response(JSON.stringify({Products:records.filter(p=>ids.includes(p.ProductId))}));
+ }
+ const query=url.searchParams.get('query');
+ const productsList=query===DLC?[row(DLC)]:query===GAME?[row()]:[row(),row(BUNDLE),row(DLC),row(APP)];
+ return new Response(JSON.stringify({productsList,cursor:'page2',hasMorePages:true}));
+ }) as typeof fetch);
+ for(const result of [await service.search('Game','US'),await service.featured('US'),await service.search('Game','US','page2')])expect(result.products.map(p=>p.productId)).toEqual([GAME,BUNDLE]);
+ expect((await service.search(DLC,'US')).products).toEqual([]);
+ expect((await service.search(GAME,'US')).products.map(p=>p.productId)).toEqual([GAME]);
+ expect(await service.gameDetails(DLC,'US')).toBeUndefined();
+ expect(await service.gameDetails(GAME,'US')).toMatchObject({productId:GAME});
+ expect(requests.some(url=>url.searchParams.get('cursor')==='page2')).toBe(true);
+});
+it('fails closed on unavailable type enrichment without filtering licensed-library games',async()=>{
+ const service=new CatalogService((async(input:URL|RequestInfo)=>{
+ if(String(input).includes('displaycatalog'))return new Response('unavailable',{status:503});
+ return new Response(JSON.stringify({productsList:[row()]}));
+ }) as typeof fetch);
+ expect((await service.search('Game','US')).products).toEqual([]);
+ expect((await service.featured('US')).products).toEqual([]);
+ expect(parseCatalogProducts({productsList:[row()]},{Products:[]},'library')).toHaveLength(1);
+});
diff --git a/src/main/catalog.test.ts b/src/main/catalog.test.ts
index f5f9ee9..9beb0ab 100644
--- a/src/main/catalog.test.ts
+++ b/src/main/catalog.test.ts
@@ -27,12 +27,14 @@ const search = {
const catalog = {
Products: [{
ProductId: '9GAME123',
+ ProductType: 'Game',
DisplaySkuAvailabilities: [{ Sku: { Properties: { Packages: [{
PackageFormat: 'MSIXVC',
PlatformDependencies: [{ PlatformName: 'Windows.Desktop' }],
}] } } }],
}, {
ProductId: '9BUNDLE1',
+ ProductType: 'Game',
DisplaySkuAvailabilities: [{ Sku: { Properties: { Packages: [] } } }],
}],
};
@@ -212,7 +214,7 @@ describe('CatalogService', () => {
describe('Store-only offer policy',()=>{
const sku=(price:number,props:Record<string,unknown>={},type='full')=>({Sku:{SkuType:type,Properties:props},Availabilities:[{OrderManagementData:{Price:{MSRP:price,ListPrice:price}}}]});
- const parse=(skus:unknown[],extra={},policy:'store'|'library'='store')=>parseCatalogProducts({productsList:[{productId:'9AAAAAAAAAAA',title:'Free Spirit',isGame:true,...extra}]},{Products:[{ProductId:'9AAAAAAAAAAA',DisplaySkuAvailabilities:skus}]},policy);
+ const parse=(skus:unknown[],extra={},policy:'store'|'library'='store')=>parseCatalogProducts({productsList:[{productId:'9AAAAAAAAAAA',title:'Free Spirit',isGame:true,...extra}]},{Products:[{ProductId:'9AAAAAAAAAAA',ProductType:'Game',DisplaySkuAvailabilities:skus}]},policy);
it('excludes structured free, trial and demo but retains paid and missing/malformed prices',()=>{
expect(parse([sku(0)])).toEqual([]);
expect(parse([sku(0,{IsTrial:true})])).toEqual([]);
@@ -239,7 +241,7 @@ describe('Store-only offer policy',()=>{
expect(parse([sku(30,{...pkg,IsPreOrder:true}),sku(30,{IsTrial:false})])[0].installability).not.toBe('supported');
});
it('handles malformed rows without treating absent prices as free',()=>{
- expect(parseCatalogProducts({productsList:[null,{},false,{productId:'9AAAAAAAAAAA',title:'Valid'}]}, {Products:[null]},'store')).toHaveLength(1);
+ expect(parseCatalogProducts({productsList:[null,{},false,{productId:'9AAAAAAAAAAA',title:'Valid'}]}, {Products:[null,{ProductId:'9AAAAAAAAAAA',ProductType:'Game'}]},'store')).toHaveLength(1);
});
it('applies the same policy to actual search and featured service paths while preserving licensed games',async()=>{
const id='9AAAAAAAAAAA';
diff --git a/src/main/catalog.ts b/src/main/catalog.ts
index 3221d95..2e5254b 100644
--- a/src/main/catalog.ts
+++ b/src/main/catalog.ts
@@ -297,7 +297,10 @@ export function parseCatalogProducts(search: StoreSearchResponse, catalog: Displ
const productId = string(product.productId)?.toUpperCase();
const title = string(product.title);
if (!productId || !title || product.isGame === false) return [];
- if(policy==='store' && excludedStoreOffer(product as Record<string,unknown>,detailMap.get(productId)))return [];
+ const detail=detailMap.get(productId);
+ // Game includes base games and game bundles. Endpoint mediaType/isGame
+ // alone also admits extras; children cannot change the offer's own type.
+ if(policy==='store' && (detail?.ProductType!=='Game' || excludedStoreOffer(product as Record<string,unknown>,detail)))return [];
const support = packageSupport(productId, detailMap);
return [{
productId,