break up library, move bots to their own repositories
This commit is contained in:
132
packages/eve/src/esi/assets.ts
Normal file
132
packages/eve/src/esi/assets.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* EVE ESI Assets API
|
||||
* https://developers.eveonline.com/api-explorer#/operations/GetCharactersCharacterIdAssets
|
||||
*/
|
||||
import { ESI_SCOPE } from '../oauth';
|
||||
import { ESI_RATE_LIMIT_GROUP } from './util/rate-limits';
|
||||
import { checkScopesAndGetCharacterId, esiFetch, type EsiOptions } from './util/fetch';
|
||||
import type { LocationFlag } from './types/location-flag';
|
||||
|
||||
export enum AssetLocationType {
|
||||
STATION = 'station',
|
||||
SOLAR_SYSTEM = 'solar_system',
|
||||
ITEM = 'item',
|
||||
OTHER = 'other',
|
||||
}
|
||||
|
||||
export interface Asset {
|
||||
is_blueprint_copy: boolean;
|
||||
is_singleton: boolean;
|
||||
item_id: number;
|
||||
location_flag: LocationFlag;
|
||||
location_id: number;
|
||||
location_type: AssetLocationType;
|
||||
quantity: number;
|
||||
type_id: number;
|
||||
}
|
||||
|
||||
export function getCharacterAssets(options: EsiOptions, page: number = 1): Promise<Partial<Asset>[]> {
|
||||
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-assets.read_assets.v1']);
|
||||
return esiFetch<Partial<Asset>[]>(`/characters/${character_id}/assets/?page=${page}`, {
|
||||
...options,
|
||||
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CHAR_ASSET,
|
||||
});
|
||||
}
|
||||
|
||||
export interface AssetLocation {
|
||||
item_id: number;
|
||||
position: {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
}
|
||||
|
||||
export function getCharacterAssetLocations(options: EsiOptions, ids: number[]): any[] | Promise<Partial<AssetLocation>[]> {
|
||||
if (ids.length === 0) return [];
|
||||
if (ids.length > 1000) throw 'Maximum of 1000 IDs can be requested at once';
|
||||
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-assets.read_assets.v1']);
|
||||
|
||||
return esiFetch<Partial<AssetLocation>[]>(`/characters/${character_id}/assets/locations/`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(ids),
|
||||
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CHAR_ASSET,
|
||||
});
|
||||
}
|
||||
|
||||
export interface AssetNames {
|
||||
item_id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function getCharacterAssetNames(options: EsiOptions, ids: number[]): any[] | Promise<Partial<AssetNames>[]> {
|
||||
if (ids.length === 0) return [];
|
||||
if (ids.length > 1000) throw 'Maximum of 1000 IDs can be requested at once';
|
||||
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-assets.read_assets.v1']);
|
||||
return esiFetch<Partial<AssetNames>[]>(`/characters/${character_id}/assets/names/`, {
|
||||
...options,
|
||||
method: 'POST',
|
||||
body: JSON.stringify(ids),
|
||||
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CHAR_ASSET,
|
||||
});
|
||||
}
|
||||
|
||||
export interface CorpAsset {
|
||||
is_blueprint_copy: boolean;
|
||||
is_singleton: boolean;
|
||||
item_id: number;
|
||||
location_flag: LocationFlag;
|
||||
location_id: number;
|
||||
location_type: 'station' | 'solar_system' | 'item' | 'other';
|
||||
quantity: number;
|
||||
type_id: number;
|
||||
}
|
||||
|
||||
export async function getCorporationAssets(options: EsiOptions, corporation_id: number, page: number = 1): Promise<Partial<CorpAsset>[]> {
|
||||
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-assets.read_corporation_assets.v1']);
|
||||
return await esiFetch<Partial<CorpAsset>[]>(`/corporations/${corporation_id}/assets/?page=${page}`, {
|
||||
...options,
|
||||
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CORP_ASSET,
|
||||
});
|
||||
}
|
||||
|
||||
export interface AssetLocation {
|
||||
item_id: number;
|
||||
position: {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getCorporationAssetLocations(
|
||||
options: EsiOptions,
|
||||
corporation_id: number,
|
||||
ids: number[],
|
||||
): Promise<Partial<AssetLocation>[]> {
|
||||
if (ids.length === 0) return [];
|
||||
if (ids.length > 1000) throw 'Maximum of 1000 IDs can be requested at once';
|
||||
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-assets.read_corporation_assets.v1']);
|
||||
return await esiFetch<Partial<AssetLocation>[]>(`/corporations/${corporation_id}/assets/locations/`, {
|
||||
...options,
|
||||
method: 'POST',
|
||||
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CORP_ASSET,
|
||||
});
|
||||
}
|
||||
|
||||
export interface AssetNames {
|
||||
item_id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export async function getCorporationAssetNames(options: EsiOptions, id: number, ids: number[]): Promise<Partial<AssetNames>[]> {
|
||||
if (ids.length === 0) return [];
|
||||
if (ids.length > 1000) throw 'Maximum of 1000 IDs can be requested at once';
|
||||
const character_id = checkScopesAndGetCharacterId(options, ESI_SCOPE['esi-assets.read_corporation_assets.v1']);
|
||||
return await esiFetch<Partial<AssetNames>[]>(`/corporations/${id}/assets/names/`, {
|
||||
...options,
|
||||
method: 'POST',
|
||||
body: JSON.stringify(ids),
|
||||
rateLimitGroup: ESI_RATE_LIMIT_GROUP.CORP_ASSET,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user