mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-30 02:01:46 +00:00
Add definitions for axios-token-interceptor
This commit is contained in:
@@ -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
@@ -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" }
|
||||
Reference in New Issue
Block a user