diff --git a/package.json b/package.json index 687e954..78bfef6 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "module": "dist/vue-authenticate.esm.min.js", "browser": "dist/vue-authenticate.umd.min.js", "main": "dist/vue-authenticate.esm.min.js", + "types": "types/index.d.ts", + "typings": "types/index.d.ts", "scripts": { "build": "rollup -c", "lint": "eslint src", @@ -33,7 +35,7 @@ "url": "https://github.com/ajmas/vue-authenticate.git" }, "files": [ - "dist" + "dist", "types/index.d.ts" ], "license": "MIT", "devDependencies": { diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..34e1902 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,80 @@ +import { AxiosResponse, AxiosInstance, AxiosRequestConfig } from 'axios'; + +export interface CookieStorageOptions { + domain?: string; + path?: string; + secure?: boolean; +} + +export interface ProviderOptions { + name?: string; + url?: string; + clientId?: string; + authorizationEndpoint?: string; + redirectUri?: string; + requiredUrlParams?: string[]; + defaultUrlParams?: string[]; + optionalUrlParams?: string[]; + scope?: string[]; + scopePrefix?: string; + scopeDelimiter?: string; + state?: string; + display?: string; + oauthType?: string; + responseType?: string; + responseParams?: { + code?: string; + clientId?: string; + redirectUri?: string; + }; + popupOptions?: { + width: number; + height: number; + }; +} + +export declare class VueAuthenticate { + login(user: Object): Promise; + login( + user: Object, + requestOptions: AxiosRequestConfig + ): Promise; + isAuthenticated(): boolean; + getToken(): string; + setToken(token: string | object): void; + register( + user: any, + requestOptions?: AxiosRequestConfig + ): Promise; + logout(requestOptions?: AxiosRequestConfig): Promise; + authenticate( + provider: string, + userData: any, + requestOptions?: AxiosRequestConfig + ): Promise<{}>; +} + +export interface AuthenticateOptions { + baseUrl?: string; + axios?: AxiosInstance; + tokenName?: string; + tokenPrefix?: string; + tokenHeader?: string; + tokenType?: string; + loginUrl?: string; + registerUrl?: string; + logoutUrl?: string; + storageType?: string; + storageNamespace?: string; + cookieStorage?: CookieStorageOptions; + requestDataKey?: string; + responseDataKey?: string; + withCredentials?: boolean; + providers: { [key: string]: ProviderOptions }; +} + +declare module "vue/types/vue" { + interface Vue { + $auth: VueAuthenticate; + } +} \ No newline at end of file