2.0.9 • Published 2 years ago

oodestiny v2.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

oodestiny

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 oodestiny

Example Usage

import { generateOAuthURL, Tokens, Client } from 'oodestiny/lib';

// You MUST configure the library with your Bungie API credentials,
// using the following enviroment variables:

// -> BUNGIE_API_KEY,
// -> BUNGIE_CLIENT_ID,
// -> BUNGIE_CLIENT_SECRET

// dotenv is a good way to do this
dotenv.config();

// creates a new client, easy-peasy way for accessing basic queries
const client = new Client();
// All endpoints are available as fields of the client
// See the bungie website for all the possible endpoints you can hit :D
const manifest = await client.Destiny2.getDestinyManifest();

If you want to make a simple query without a client, you can do directly import the endpoints as of version 1.7.0

import { BungieMembershipType, DestinyActivityModeType } from 'oodestiny/lib/schemas'
import { getActivityHistory } from 'oodestiny/lib/endpoints/Destiny2';

const res = await getActivityHistory({
    characterId: "2305843009468984093",
    count: 1,
    destinyMembershipId: "4611686018488107374",
    membershipType: BungieMembershipType.TigerSteam,
    mode: DestinyActivityModeType.Raid,
    page: 0
})

// you could also bind an acccess_token to the call
const res = await getActivityHistory.bind({ access_token: "nads7yfdafnd" })({ ... })

Of course, to access the full potential of the API, you will need OAuth access.

// Let's generate our OAuth url!
// you should use something more secure/complex, this is an example
const state = (Math.random() * 999).toString();

// creates a url for users to click on to login with OAuth 2.0
const url = generateOAuthURL({
  redirectURL: 'google.com',
  state
});
console.log({ url });

// it's good practice to verify the state parameter in your URL matches the state parameter you expected
const urlObj = new URL(url);
if (urlObj.searchParams.get('state') !== state) throw Error();

const code = urlObj.searchParams.get('code');

// one way to get the tokens is with an oauth code, you'll need to execute this the first time
const tokens = await Tokens.getAccessTokenFromAuthCode(code);
console.log({ tokens });

// if you have a stored refresh token, you can execute this instead, you will execute this more often then not
const tokens2 = await Tokens.getAccessTokenFromRefreshToken(tokens.refresh.value);
console.log({ tokens2 });

// authenticate the client we created earlier!
// You can also pass the token into the client constructor if you prefer that
client.login(tokens2.access.value);
2.0.3

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.7.7

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.12

3 years ago

1.4.11

3 years ago

1.4.10

3 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.15

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago