2.1.1 • Published 8 months ago

bungie-net-core v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

bungie-net-core

This is a Typescript wrapper for the Bungie API. It is mostly for personal use, but if you find any bugs please report them.

Installation

npm i bungie-net-core

Example Usage

import { BungieClientProtocol } from 'bungie-net-core';
import { getProfile } from 'bungie-net-core/services/Destiny2';
import { BungieMembershipType, DestinyComponentType, PlatformErrorCodes } from 'bungie-net-core/enums';

class BungieClient implements BungieClientProtocol {
  // while not required, sometimes you will need an access_token for priviledged routes
  private access_token: undefined | string;

  // this method is required
  async fetch<T>(config: BungieFetchConfig): Promise<T> {
    const apiKey = process.env.BUNGIE_API_KEY!;

    const headers: Record<string, string> = {
      ...config.headers,
      // we must provide the API key in the headers
      'X-API-KEY': apiKey
    };

    // attach the acces_token if we have it as a Bearer token
    if (this.access_token) {
      headers['Authorization'] = `Bearer ${this.access_token}`;
    }

    const payload = {
      method: config.method,
      body: config.body,
      headers
    };

    const res = await fetch(config.url, payload);
    const data = await res.json();
    if (!res.ok) {
      throw data
    }
    return data as T;
  }

const client = new BungieClient();

getProfile(client, {
  components: [DestinyComponentType.CharacterInventories],
  destinyMembershipId: '4611741274194011',
  membershipType: BungieMembershipType.TigerPsn
});
1.1.7

10 months ago

1.1.6

10 months ago

2.1.1

8 months ago

2.1.0

9 months ago

2.0.0

9 months ago

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.6

10 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago