npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bungie-api-ts-no-const-enum

v0.0.10

Published

TypeScript mappings for the Bungie.net API

Downloads

28

Readme

IMPORTANT: READ THIS FIRST, YES. YOU!

This project is a fork of bungie-api-ts-no-const-enum. The only reason this exists is to change export const enum to just export enum on this line. You can read more about why exporting a const enum is no bueno in this github thread.

Do not open issues in this repo unless they are specifically related to the removal of the word const

Here is the mapping of versions

| bungie-api-ts | bungie-api-ts-no-const-enum | | ------------- | --------------------------- | | 4.19.0 | 0.0.3 | | 4.22.3 | 0.0.8 | | 5.0.0 | 0.0.9 |

Modified development steps:

  1. Clobber this repo with the bungie-api-ts repo
  2. Replace export const enum with export enum in generate-interfaces.ts
  3. Run yarn && yarn submodule
  4. Run yarn start
  5. Replace all instances of bungie-api-ts with bungie-api-ts-no-const-enum
  6. Replace all instances of DestinyItemManager/bungie-api-ts-no-const-enum with jbccollins/bungie-api-ts-no-const-enum
  7. Bump the version and change it in all places (e.g. change all instances of 4.22.3 to 0.0.8)
  8. Add the version mapping to this README file.
  9. Commit and push all changes
  10. Run npm run publish

Bungie API TypeScript support

This project implements TypeScript definitions and API helpers for the Bungie.net API. It's meant for use in Destiny Item Manager, but should be general enough to use in any project. The code is completely generated from Bungie's documentation - I considered using something like Swagger Codegen, but instead opted for a custom generator so we could make the result as nice as possible.

Ports

Feel free to fork this and use it to generate for your favorite language!

Install

yarn add bungie-api-ts-no-const-enum

Interfaces and Enums

All the interface type definitions and enums are for type info only - everything will compile out. Only the API helpers produce real JavaScript output. You can import types from each service defined on Bungie.net:

import {
  DestinyInventoryComponent,
  DestinyInventoryItemDefinition,
} from 'bungie-api-ts-no-const-enum/destiny2';

There are definitions for every type defined in the Bungie.net services. See their documentation for a list - the interface names are the last part of the full name (for example, Destiny.Definitions.DestinyVendorActionDefinition becomes DestinyVendorActionDefinition). There are a few exceptions, like SingleComponentResponseOfDestinyInventoryComponent, which have been mapped into nicer forms like SingleComponentResponse<DestinyInventoryComponent>, and the server responses, which are now ServerResponse<T> instead of something like DestinyCharacterResponse.

API Helpers

In addition to the types, there are also simple helper functions for each API endpoint. They define the inputs and outputs to that endpoint, and will call a user-provided function with HTTP request info that you can then use to make an HTTP request. This pattern was used so the API helpers could provide full type information. These helpers are not a full API client - they assist in building one. An example:

import { getProfile, HttpClientConfig } from 'bungie-api-ts-no-const-enum/destiny2';

async function $http(config: HttpClientConfig) {
  // fill in the API key, handle OAuth, etc., then make an HTTP request using the config.
  return fetch(config.url, ...);
}

const profileInfo: ServerResponse<DestinyProfileResponse> = await getProfile($http, {
  components: [DestinyComponentType.Profiles, DestinyComponentType.Characters],
  destinyMembershipId: 12345,
  membershipType: BungieMembershipType.TigerPsn
});

Imports

It is possible to import all services from bungie-api-ts-no-const-enum directly, but it's better to import the specific service and pick out what you want:

// good
import { getProfile, HttpClientConfig } from 'bungie-api-ts-no-const-enum/destiny2';
getProfile(...);

// works, but not as good
import { Destiny2 } from 'bungie-api-ts-no-const-enum';
Destiny2.getProfile(...);

Manifest Helpers

The destiny2 import also contains helpers for typing and downloading the Destiny manifest:

import { getDestinyManifestSlice } from 'bungie-api-ts-no-const-enum/destiny2';

async function $http(config: HttpClientConfig) {
  // fill in the API key, handle OAuth, etc., then make an HTTP request using the config.
  return fetch(config.url, ...);
}

const destinyManifest = await getDestinyManifest($http);
const manifestTables = getDestinyManifestSlice($http, {
  destinyManifest,
  tableNames: ['DestinyInventoryItemDefinition', 'DestinySocketDefinition'],
  language: 'en',
});

// manifestTables is an object with properties DestinyInventoryItemDefinition and DestinySocketDefinition

Build

# setup
yarn && yarn submodule
# run
yarn start

Updating API sources

Run the update API sources GitHub Action and it should create a new PR for the updated sources.

Publishing

Update the version in package.json, and when the PR merges to master, a GitHub workflow will automatically publish to NPM. Don't forget to run yarn start and commit all changed files!