Initial commit
This commit is contained in:
135
packages/lib/src/eve/esi/contracts.ts
Normal file
135
packages/lib/src/eve/esi/contracts.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
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 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 interface Contract extends PublicContract {
|
||||
acceptor_id: number;
|
||||
assignee_id: number;
|
||||
availability: 'public' | 'personal' | 'corporation' | 'alliance';
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
return esiFetch<PublicContractItem[]>(`/contracts/public/items/${contract_id}?page=${page}`, options);
|
||||
}
|
||||
|
||||
export function getPublicContracts(region_id: number, page: number = 1, options?: PublicEsiOptions) {
|
||||
return esiFetch<PublicContract[]>(`/contracts/public/${region_id}?page=${page}`, options);
|
||||
}
|
||||
|
||||
export function getCorporationContracts(options: EsiOptions, corporation_id: number, page: number = 1) {
|
||||
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) {
|
||||
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) {
|
||||
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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user