Skip to content

Access Lists ​

Needs an access token

Retrieves an access list (ACL) and displays its members grouped by entity type. Requires ESI authentication.

Environment: ESI_ACCESS_TOKEN — a valid SSO token with the access-lists scope

Calls: accessLists.getAccessList

Run it ​

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

examples/access-lists.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 { EsiError } from '@lgriffin/esi.ts/errors';
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 = 90439768;
const ACCESS_LIST_ID = 1;

async function main() {
  const client = new EsiClient({
    logger: esiLog,
    clientId: 'esi-ts-access-lists-example',
  });

  try {
    log.info(`Access List #${ACCESS_LIST_ID}\n`);

    const list = await client.accessLists.getAccessList(
      CHARACTER_ID,
      ACCESS_LIST_ID,
    );

    const { membership } = list;
    log.info(`Name:           ${list.name}`);
    log.info(`ID:             ${list.id}`);
    log.info(`Description:    ${list.description}`);
    log.info(`Allow everyone: ${membership.allow_everyone ? 'yes' : 'no'}`);
    log.info('-'.repeat(60));

    const groups: Array<[string, Array<{ id: number; access: string }>]> = [
      [
        'Characters',
        membership.characters.map((m) => ({
          id: m.character_id,
          access: m.access,
        })),
      ],
      [
        'Corporations',
        membership.corporations.map((m) => ({
          id: m.corporation_id,
          access: m.access,
        })),
      ],
      [
        'Alliances',
        membership.alliances.map((m) => ({
          id: m.alliance_id,
          access: m.access,
        })),
      ],
    ];

    for (const [label, members] of groups) {
      if (members.length === 0) continue;
      log.info(`\n${label} (${members.length})`);
      for (const member of members.slice(0, 10)) {
        const icon = member.access === 'Blocked' ? '-' : '+';
        log.info(`  [${icon}] ${member.id} — ${member.access}`);
      }
      if (members.length > 10)
        log.info(`  ... and ${members.length - 10} more`);
    }
  } catch (err) {
    if (err instanceof EsiError && err.statusCode === 401) {
      log.error(
        'Authentication required. Set ESI_ACCESS_TOKEN to a valid SSO token.',
      );
    } else {
      log.error('Request failed', { error: err });
    }
    process.exit(1);
  } finally {
    await client.shutdown();
  }
}

main();

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