Add definitions for axios-token-interceptor

This commit is contained in:
Michael Dodge
2018-04-23 12:29:43 -06:00
parent ee2f1b215e
commit 27e6fddf22
5 changed files with 79 additions and 0 deletions
@@ -0,0 +1,18 @@
import tokenProvider, { tokenCache } from 'axios-token-interceptor';
tokenProvider(); // $ExpectError
const validOptions = {
getToken: () => Promise.resolve('qwerty'),
};
tokenProvider(validOptions); // $ExpectType TokenProvider
tokenCache(); // $ExpectError
const getToken = Promise.resolve('qwerty');
const validCacheOptions = {
maxAge: 3600,
};
const cache = tokenCache(getToken, validCacheOptions); // $Expect TokenCache
cache.reset(); // $ExpectType void
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for axios-token-interceptor 0.1
// Project: https://github.com/sandrinodimattia/axios-token-interceptor#readme
// Definitions by: Mike Dodge <https://github.com/innovation-team>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { AxiosRequestConfig } from 'axios';
/*~ If this module has methods, declare them as functions like so.
*/
export default function tokenProvider(Options: InterceptorOptions): TokenProvider;
export function tokenCache(getToken: Promise<string>, options: TokenCacheOptions): TokenCache;
/*~ You can declare types that are available via importing the module */
export interface InterceptorOptions {
token?: string;
getToken?: () => string | Promise<string>;
header?: string;
headerFormatter?: (token: string) => string;
}
export type TokenProvider = (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
export interface TokenCacheOptions {
getMaxAge?: () => number;
maxAge?: number;
}
export interface TokenCache {
reset(): void;
}
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"axios": "^0.16.2"
}
}
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"axios-token-interceptor-tests.ts"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }