Skip to content

Commit

Permalink
Export types from global TypeScript file.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxswa committed Dec 17, 2019
1 parent 8ceb626 commit 559d2c9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
5 changes: 4 additions & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ jest.mock('../src/transaction-manager');
jest.mock('../src/utils');

import Auth0Client from '../src/Auth0Client';
import createAuth0Client from '../src/index';
import createAuth0Client, {
PopupConfigOptions,
GetTokenSilentlyOptions
} from '../src/index';
import { AuthenticationError } from '../src/errors';
import version from '../src/version';
import { DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS } from '../src/constants';
Expand Down
16 changes: 15 additions & 1 deletion src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ import { AuthenticationError } from './errors';
import * as ClientStorage from './storage';
import { DEFAULT_POPUP_CONFIG_OPTIONS } from './constants';
import version from './version';
import {
Auth0ClientOptions,
BaseLoginOptions,
AuthorizeOptions,
RedirectLoginOptions,
PopupLoginOptions,
PopupConfigOptions,
GetUserOptions,
GetIdTokenClaimsOptions,
RedirectLoginResult,
GetTokenSilentlyOptions,
GetTokenWithPopupOptions,
LogoutOptions
} from './global';

const lock = new Lock();
const GET_TOKEN_SILENTLY_LOCK_KEY = 'auth0.lock.getTokenSilently';
Expand Down Expand Up @@ -230,7 +244,7 @@ export default class Auth0Client {
* @param options
*/
public async getIdTokenClaims(
options: getIdTokenClaimsOptions = {
options: GetIdTokenClaimsOptions = {
audience: this.options.audience || 'default',
scope: this.options.scope || this.DEFAULT_SCOPE
}
Expand Down
2 changes: 2 additions & 0 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IdToken } from './global';

interface CacheKeyData {
audience: string;
scope: string;
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PopupConfigOptions } from './global';

/**
* @ignore
*/
Expand Down
34 changes: 17 additions & 17 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @ignore
*/
interface BaseLoginOptions {
export interface BaseLoginOptions {
/**
* - `'page'`: displays the UI with a full page view
* - `'popup'`: displays the UI with a popup window
* - `'touch'`: displays the UI in a way that leverages a touch interface
* - `'touch'`: displays the UI in a way that leverages a touch export interface
* - `'wap'`: displays the UI with a "feature phone" type interface
*/
display?: 'page' | 'popup' | 'touch' | 'wap';
Expand Down Expand Up @@ -61,7 +61,7 @@ interface BaseLoginOptions {
[key: string]: any;
}

interface Auth0ClientOptions extends BaseLoginOptions {
export interface Auth0ClientOptions extends BaseLoginOptions {
/**
* Your Auth0 account domain such as `'example.auth0.com'`,
* `'example.eu.auth0.com'` or , `'example.mycompany.com'`
Expand Down Expand Up @@ -95,7 +95,7 @@ interface Auth0ClientOptions extends BaseLoginOptions {
/**
* @ignore
*/
interface AuthorizeOptions extends BaseLoginOptions {
export interface AuthorizeOptions extends BaseLoginOptions {
response_type: string;
response_mode: string;
redirect_uri: string;
Expand All @@ -106,7 +106,7 @@ interface AuthorizeOptions extends BaseLoginOptions {
code_challenge_method: string;
}

interface RedirectLoginOptions extends BaseLoginOptions {
export interface RedirectLoginOptions extends BaseLoginOptions {
/**
* The URL where Auth0 will redirect your browser to with
* the authentication result. It must be whitelisted in
Expand All @@ -124,24 +124,24 @@ interface RedirectLoginOptions extends BaseLoginOptions {
fragment?: string;
}

interface RedirectLoginResult {
export interface RedirectLoginResult {
/**
* State stored when the redirect request was made
*/
appState?: any;
}

interface PopupLoginOptions extends BaseLoginOptions {}
export interface PopupLoginOptions extends BaseLoginOptions {}

interface PopupConfigOptions {
export interface PopupConfigOptions {
/**
* The number of seconds to wait for a popup response before
* throwing a timeout error. Defaults to 60s
*/
timeoutInSeconds?: number;
}

interface GetUserOptions {
export interface GetUserOptions {
/**
* The scope that was used in the authentication request
*/
Expand All @@ -152,7 +152,7 @@ interface GetUserOptions {
audience: string;
}

interface getIdTokenClaimsOptions {
export interface GetIdTokenClaimsOptions {
/**
* The scope that was used in the authentication request
*/
Expand All @@ -163,7 +163,7 @@ interface getIdTokenClaimsOptions {
audience: string;
}

interface GetTokenSilentlyOptions extends GetUserOptions {
export interface GetTokenSilentlyOptions extends GetUserOptions {
/**
* When `true`, ignores the cache and always sends a
* request to Auth0.
Expand All @@ -186,9 +186,9 @@ interface GetTokenSilentlyOptions extends GetUserOptions {
*/
[key: string]: any;
}
interface GetTokenWithPopupOptions extends PopupLoginOptions {}
export interface GetTokenWithPopupOptions extends PopupLoginOptions {}

interface LogoutOptions {
export interface LogoutOptions {
/**
* The URL where Auth0 will redirect your browser to after the logout.
*
Expand Down Expand Up @@ -218,7 +218,7 @@ interface LogoutOptions {
/**
* @ignore
*/
interface AuthenticationResult {
export interface AuthenticationResult {
state: string;
code?: string;
error?: string;
Expand All @@ -228,7 +228,7 @@ interface AuthenticationResult {
/**
* @ignore
*/
interface OAuthTokenOptions {
export interface OAuthTokenOptions {
baseUrl: string;
client_id: string;
audience?: string;
Expand All @@ -239,7 +239,7 @@ interface OAuthTokenOptions {
/**
* @ignore
*/
interface JWTVerifyOptions {
export interface JWTVerifyOptions {
iss: string;
aud: string;
id_token: string;
Expand All @@ -251,7 +251,7 @@ interface JWTVerifyOptions {
/**
* @ignore
*/
interface IdToken {
export interface IdToken {
__raw: string;
name?: string;
given_name?: string;
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import 'fast-text-encoding';

import Auth0Client from './Auth0Client';
import * as ClientStorage from './storage';
import { Auth0ClientOptions } from './global';

//this is necessary to export the type definitions used in this file
import './global';
import { validateCrypto } from './utils';

export * from './Auth0Client';
export * from './global';

export default async function createAuth0Client(options: Auth0ClientOptions) {
validateCrypto();

Expand Down
1 change: 1 addition & 0 deletions src/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { urlDecodeB64 } from './utils';
import { IdToken, JWTVerifyOptions } from './global';

const isNumber = n => typeof n === 'number';

Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import fetch from 'unfetch';

import { DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS } from './constants';
import {
AuthenticationResult,
PopupConfigOptions,
OAuthTokenOptions
} from './global';

const dedupe = arr => arr.filter((x, i) => arr.indexOf(x) === i);

Expand Down

0 comments on commit 559d2c9

Please sign in to comment.