Skip to content

Corporation History and NPC Corporations ​

No token needed Runs nightly against live ESI

Follows a character's employment history, the alliance history and logo of their current corporation, then lists the NPC corporations and the loyalty store offers of one of them.

No authentication required.

Calls: characters.getCharacterCorporationHistory · corporations.getCorporationAllianceHistory · corporations.getCorporationIcon · corporations.getNpcCorporations · loyalty.getLoyaltyStoreOffers

Run it ​

bash
git clone https://github.com/lgriffin/ESI.ts.git && cd ESI.ts
npm ci
npm run example:corporation-history

examples/corporation-history.ts on GitHub. The imports below are written as a consumer of the package writes them; the file in the repository imports from ../src.

Source ​

ts
import { EsiClient } from '@lgriffin/esi.ts';
import { createConsoleLogger } from '@lgriffin/esi.ts';

// The program's own output. The client logs through the same console sink
// at ESI_LOG_LEVEL (default warn), so its diagnostics stay out of the way.
const log = createConsoleLogger('info');
const esiLog = createConsoleLogger();

const CHARACTER_ID = 1689391488; // deiseman
const CALDARI_NAVY = 1000035;

async function main() {
  const client = new EsiClient({ logger: esiLog });

  try {
    const history =
      await client.characters.getCharacterCorporationHistory(CHARACTER_ID);
    log.info(`Employment history (${history.length} entries):`);
    for (const entry of history.slice(0, 5)) {
      log.info(`  ${entry.start_date}  corporation ${entry.corporation_id}`);
    }

    const current = [...history].sort((a, b) => b.record_id - a.record_id)[0];
    if (current) {
      const corporationId = current.corporation_id;
      const alliances =
        await client.corporations.getCorporationAllianceHistory(corporationId);
      log.info(
        `\nAlliance history of corporation ${corporationId}: ${alliances.length} entries`,
      );
      for (const entry of alliances.slice(0, 5)) {
        log.info(
          `  ${entry.start_date}  ${entry.alliance_id ?? 'no alliance'}`,
        );
      }

      const icon = await client.corporations.getCorporationIcon(corporationId);
      log.info(`Logo (128px): ${icon.px128x128 ?? 'none'}`);
    }

    const npcCorporations = await client.corporations.getNpcCorporations();
    log.info(`\nNPC corporations: ${npcCorporations.length}`);

    const offers = await client.loyalty.getLoyaltyStoreOffers(CALDARI_NAVY);
    const cheapest = [...offers].sort((a, b) => a.lp_cost - b.lp_cost);
    log.info(`Caldari Navy LP store: ${offers.length} offers, cheapest:`);
    for (const offer of cheapest.slice(0, 5)) {
      log.info(
        `  ${offer.quantity} x type ${offer.type_id}: ${offer.lp_cost} LP + ${offer.isk_cost.toLocaleString()} ISK`,
      );
    }
  } catch (err) {
    log.error('Request failed', { error: err });
    process.exit(1);
  } finally {
    await client.shutdown();
  }
}

main();

Released under the GPL-3.0-or-later license.