Files
star-kitten/packages/lib/src/eve/esi/contracts.ts

162 lines
6.1 KiB
TypeScript

import { ESI_SCOPE } from '../oauth/auth.types';
import { ESI_RATE_LIMIT_GROUP } from './util/rate-limits';
import { checkScopesAndGetCharacterId, esiFetch, type EsiOptions, type PublicEsiOptions } from './util/fetch';
export enum ContractType {
ITEM_EXCHANGE = 'item_exchange',
AUCTION = 'auction',
COURIER = 'courier',
LOAN = 'loan',
}
export interface PublicContract {
buyout?: number;
collateral?: number;
contract_id: number;
date_expired: string;
date_issued: string;
days_to_complete?: number;
end_location_id?: number;
for_corporation: boolean;
issuer_corporation_id: number;
issuer_id: number;
price?: number;
reward?: number;
start_location_id?: number;
title?: string;
type: 'item_exchange' | 'auction' | 'courier' | 'loan';
volume?: number;
}
export enum ContractAvailability {
PUBLIC = 'public',
PERSONAL = 'personal',
CORPORATION = 'corporation',
ALLIANCE = 'alliance',
}
export enum ContractStatus {
OUTSTANDING = 'outstanding',
IN_PROGRESS = 'in_progress',
FINISHED_ISSUER = 'finished_issuer',
FINISHED_CONTRACTOR = 'finished_contractor',
CANCELLED = 'cancelled',
REJECTED = 'rejected',
FAILED = 'failed',
DELETED = 'deleted',
REVERSED = 'reversed',
}
export interface Contract extends PublicContract {
acceptor_id: number;
assignee_id: number;
availability: ContractAvailability;
date_accepted?: string;
date_completed?: string;
status:
| 'outstanding'
| 'in_progress'
| 'finished_issuer'
| 'finished_contractor'
| 'cancelled'
| 'rejected'
| 'failed'
| 'deleted'
| 'reversed';
}
/**
* Returns contracts available to a character, only if the character is issuer, acceptor or assignee.
* Only returns contracts no older than 30 days, or if the status is "in_progress".
*/
export function getCharacterContracts(options: EsiOptions, page: number = 1): Promise<Contract[]> {
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-contracts.read_character_contracts.v1']);
return esiFetch<Contract[]>(`/characters/${character_id}/contracts/?page=${page}`, {
...options,
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CHAR_CONTRACT,
});
}
export interface PublicContractBid {
amount: number;
bid_id: number;
date_bid: string;
}
export interface ContractBid extends PublicContractBid {
bidder_id: number;
}
export function getContractBids(options: EsiOptions, contract_id: number): Promise<ContractBid[]> {
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-contracts.read_character_contracts.v1']);
return esiFetch<ContractBid[]>(`/characters/${character_id}/contracts/${contract_id}/bids/`, {
...options,
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CHAR_CONTRACT,
});
}
export interface ContractItem {
is_included: boolean; // true if the item is included in the contract, false if it is being requested
is_singleton: boolean;
quantity: number; // number of items (for stackable items)
raw_quantity?: number; // -1 indicates that the item is a singleton (non-stackable). If the item happens to be a Blueprint, -1 is an Original and -2 is a Blueprint Copy
record_id: number; // unique ID for this item in the contract
type_id: number; // type ID of the item
}
export function getContractItems(options: EsiOptions, contract_id: number): Promise<ContractItem[]> {
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-contracts.read_character_contracts.v1']);
return esiFetch<ContractItem[]>(`/characters/${character_id}/contracts/${contract_id}/items/`, {
...options,
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CHAR_CONTRACT,
});
}
export function getPublicContractBids(contract_id: number, page: number = 1, options?: PublicEsiOptions): Promise<PublicContractBid[]> {
return esiFetch<PublicContractBid[]>(`/contracts/public/bids/${contract_id}?page=${page}`, options);
}
export interface PublicContractItem {
is_blueprint_copy?: boolean;
is_included: boolean; // true if the item is included in the contract, false if it is being requested
item_id: number;
material_efficiency?: number; // Material efficiency level of the blueprint
quantity: number;
record_id: number; // unique ID for this item in the contract
runs?: number; // Number of runs for the blueprint
time_efficiency?: number; // Time efficiency level of the blueprint
type_id: number; // type ID of the item
}
export function getPublicContractItems(contract_id: number, page: number = 1, options?: PublicEsiOptions): Promise<PublicContractItem[]> {
return esiFetch<PublicContractItem[]>(`/contracts/public/items/${contract_id}?page=${page}`, options);
}
export function getPublicContracts(region_id: number, page: number = 1, options?: PublicEsiOptions): Promise<PublicContract[]> {
return esiFetch<PublicContract[]>(`/contracts/public/${region_id}?page=${page}`, options);
}
export function getCorporationContracts(options: EsiOptions, corporation_id: number, page: number = 1): Promise<Contract[]> {
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-contracts.read_corporation_contracts.v1']);
return esiFetch<Contract[]>(`/corporations/${corporation_id}/contracts/?page=${page}`, {
...options,
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CORP_CONTRACT,
});
}
export function getCorporationContractBids(options: EsiOptions, corporation_id: number, contract_id: number): Promise<ContractBid[]> {
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-contracts.read_corporation_contracts.v1']);
return esiFetch<ContractBid[]>(`/corporations/${corporation_id}/contracts/${contract_id}/bids/`, {
...options,
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CORP_CONTRACT,
});
}
export function getCorporationContractItems(options: EsiOptions, corporation_id: number, contract_id: number): Promise<ContractItem[]> {
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-contracts.read_corporation_contracts.v1']);
return esiFetch<ContractItem[]>(`/corporations/${corporation_id}/contracts/${contract_id}/items/`, {
...options,
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CORP_CONTRACT,
});
}