inventory types

This commit is contained in:
Boki 2026-02-12 12:00:29 -05:00
parent cf5d944fd1
commit 3d7a8aafdf
9 changed files with 532 additions and 369 deletions

View file

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import { logger } from '../util/logger.js';
import type { LinkMode } from '../types.js';
import type { LinkMode, PostAction } from '../types.js';
import type { ConfigStore, SavedLink } from './ConfigStore.js';
export interface TradeLink {
@ -10,6 +10,7 @@ export interface TradeLink {
label: string;
active: boolean;
mode: LinkMode;
postAction: PostAction;
addedAt: string;
}
@ -77,24 +78,26 @@ export class BotController extends EventEmitter {
this.emit('resumed');
}
addLink(url: string, name: string = '', mode?: LinkMode): TradeLink {
addLink(url: string, name: string = '', mode?: LinkMode, postAction?: PostAction): TradeLink {
url = this.stripLive(url);
const id = this.extractId(url);
const label = this.extractLabel(url);
// Check if we have saved state for this link
const savedLink = this.store.links.find((l) => l.url === url);
const resolvedMode = mode || savedLink?.mode || 'live';
const link: TradeLink = {
id,
url,
name: name || savedLink?.name || '',
label,
active: savedLink?.active !== undefined ? savedLink.active : true,
mode: mode || savedLink?.mode || 'live',
mode: resolvedMode,
postAction: postAction || savedLink?.postAction || (resolvedMode === 'scrap' ? 'salvage' : 'stash'),
addedAt: new Date().toISOString(),
};
this.links.set(id, link);
this.store.addLink(url, link.name, link.mode);
logger.info({ id, url, name: link.name, active: link.active, mode: link.mode }, 'Trade link added');
this.store.addLink(url, link.name, link.mode, link.postAction);
logger.info({ id, url, name: link.name, active: link.active, mode: link.mode, postAction: link.postAction }, 'Trade link added');
this.emit('link-added', link);
return link;
}
@ -136,6 +139,15 @@ export class BotController extends EventEmitter {
this.emit('link-mode-changed', { id, mode, link });
}
updateLinkPostAction(id: string, postAction: PostAction): void {
const link = this.links.get(id);
if (!link) return;
link.postAction = postAction;
this.store.updateLinkById(id, { postAction });
logger.info({ id, postAction }, 'Trade link postAction updated');
this.emit('link-postaction-changed', { id, postAction, link });
}
isLinkActive(searchId: string): boolean {
const link = this.links.get(searchId);
return link ? link.active : false;