Skip to content

Commit

Permalink
Add tokeninfo
Browse files Browse the repository at this point in the history
ref #4
  • Loading branch information
darthmaim committed Feb 20, 2024
1 parent 69ec5d4 commit 0e3954e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions packages/types/data/tokeninfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { SchemaAfter, SchemaVersion } from "../schema";

export type Tokeninfo<Schema extends SchemaVersion = undefined> =
Schema extends undefined ? TokeninfoBase :
Schema extends SchemaAfter<'2019-05-22T00:00:00.000Z'> | 'latest' ? Tokeninfo_2019_05_22 :
TokeninfoBase;

export type Permission = 'account' | 'builds' | 'characters' | 'guilds' | 'inventories' | 'progression' | 'pvp' | 'tradingpost' | 'unlocks' | 'wallet';

interface TokeninfoBase {
/** The toke id */
id: number

/** The name of the base API key */
name: string

/** List of permissions */
permissions: Permission[]
}

type Tokeninfo_2019_05_22 = TokeninfoBase & ({
/** The type of the token */
type: 'APIKey'
} | {
/** The type of the token */
type: 'Subtoken'

/** Expiration date (ISO8601) of the subtoken. */
expires_at: string

/** The issue date (ISO8601) of the subtoken */
issued_at: string

/** The URLs included in this subtoken */
urls?: string[]
});
4 changes: 2 additions & 2 deletions packages/types/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Account } from './data/account';
import { Item } from './data/item';
import { Tokeninfo } from './data/tokeninfo';
import { SchemaVersion } from './schema';

export type KnwownAuthenticatedEndpoint =
Expand Down Expand Up @@ -321,8 +322,7 @@ export type EndpointType<Url extends string, Schema extends SchemaVersion = unde
Url extends '/v2/account' ? Account<Schema> :
Url extends BulkExpandedEndpointUrl<'/v2/items', number> ? BulkExpandedResponseType<'/v2/items', Url, number, Item<Schema>> :
Url extends BulkExpandedEndpointUrl<'/v2/quaggans', string> ? BulkExpandedResponseType<'/v2/quaggans', Url, string, { id: string, url: string }> :
Url extends `/v2/characters?ids=${number}` ? { name: string }[] :
Url extends '/v2/characters' ? string[] :
Url extends '/v2/tokeninfo' ? Tokeninfo<Schema> :
// fallback for all bulk expanded urls
Url extends BulkExpandedEndpointUrl<KnownBulkExpandedEndpoint, string | number> ? BulkExpandedResponseType<KnownBulkExpandedEndpoint, Url, string | number, unknown> :
// fallback for all other urls
Expand Down

0 comments on commit 0e3954e

Please sign in to comment.