From 7bd7db4a1cb2f71588354a77c9e25161ca0111a8 Mon Sep 17 00:00:00 2001 From: Karol Janyst Date: Fri, 10 Mar 2017 17:09:20 +0900 Subject: [PATCH 1/3] Add definitions for redux-auth-wrapper --- redux-auth-wrapper/index.d.ts | 32 +++++++++++++++++++ redux-auth-wrapper/package.json | 5 +++ .../redux-auth-wrapper-tests.tsx | 28 ++++++++++++++++ redux-auth-wrapper/tsconfig.json | 26 +++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 redux-auth-wrapper/index.d.ts create mode 100644 redux-auth-wrapper/package.json create mode 100644 redux-auth-wrapper/redux-auth-wrapper-tests.tsx create mode 100644 redux-auth-wrapper/tsconfig.json diff --git a/redux-auth-wrapper/index.d.ts b/redux-auth-wrapper/index.d.ts new file mode 100644 index 0000000000..a5f8d777a5 --- /dev/null +++ b/redux-auth-wrapper/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for redux-auth-wrapper 1.0 +// Project: https://github.com/mjrussell/redux-auth-wrapper +// Definitions by: Karol Janyst +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { ComponentClass, StatelessComponent, ReactType } from "react"; +import { Action } from "redux"; +import { Location } from "history"; + +type ComponentConstructor

= ComponentClass

| StatelessComponent

; + +interface InjectedProps { + authData?: AuthData; +} + +export interface AuthWrapperConfig { + allowRedirectBack?: boolean | ((location: Location, redirectPath: string) => boolean); + authenticatingSelector?: (state: State, ownProps?: Props) => boolean; + authSelector: (state: State, ownProps?: Props) => AuthData; + FailureComponent?: ReactType; + failureRedirectPath?: string | ((state: State, ownProps?: Props) => string); + LoadingComponent?: ReactType; + redirectQueryParamName?: string; + wrapperDisplayName?: string; + predicate?: (authData: AuthData) => boolean; + propMapper?: (ownProps: Props) => InjectedProps & Props; + redirectAction?: (...args: any[]) => Action; +} + +type AuthDecorator = (component: ComponentConstructor) => ComponentClass; + +export function UserAuthWrapper(config: AuthWrapperConfig): AuthDecorator; diff --git a/redux-auth-wrapper/package.json b/redux-auth-wrapper/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/redux-auth-wrapper/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/redux-auth-wrapper/redux-auth-wrapper-tests.tsx b/redux-auth-wrapper/redux-auth-wrapper-tests.tsx new file mode 100644 index 0000000000..a6d363dc06 --- /dev/null +++ b/redux-auth-wrapper/redux-auth-wrapper-tests.tsx @@ -0,0 +1,28 @@ +import * as React from "react"; +import { StatelessComponent } from "react"; +import { UserAuthWrapper } from "redux-auth-wrapper"; + +const Auth = UserAuthWrapper({ + allowRedirectBack: true, + authenticatingSelector(state: any) { + return state.auth.loading + }, + authSelector(state: any) { + return state.auth + }, + FailureComponent: () => (

), + failureRedirectPath: "/401", + LoadingComponent: () => (
), + redirectAction: () => ({ type : "redirect" }), + redirectQueryParamName: "next", + predicate(authData: any) { + return authData.authorized + }, + wrapperDisplayName: "TestAuth" +}); + +export const TestAuthComponent: StatelessComponent = () => { + return (
); +}; + +const TestAuth = Auth(TestAuthComponent); diff --git a/redux-auth-wrapper/tsconfig.json b/redux-auth-wrapper/tsconfig.json new file mode 100644 index 0000000000..844f327d0e --- /dev/null +++ b/redux-auth-wrapper/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": ["../"], + "paths": { + "history": ["history/v3"], + "history/*": ["history/v3/*"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "redux-auth-wrapper-tests.tsx" + ] +} From d0000c9c8c53775069299deed9705886b6fd1d35 Mon Sep 17 00:00:00 2001 From: Karol Janyst Date: Fri, 10 Mar 2017 17:17:52 +0900 Subject: [PATCH 2/3] Add compiler flag --- redux-auth-wrapper/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/redux-auth-wrapper/index.d.ts b/redux-auth-wrapper/index.d.ts index a5f8d777a5..ffde27da52 100644 --- a/redux-auth-wrapper/index.d.ts +++ b/redux-auth-wrapper/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/mjrussell/redux-auth-wrapper // Definitions by: Karol Janyst // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 import { ComponentClass, StatelessComponent, ReactType } from "react"; import { Action } from "redux"; From 056d64da8b563002ca0fa2c3d7836fed15f8204a Mon Sep 17 00:00:00 2001 From: LKay Date: Sat, 11 Mar 2017 14:41:56 +0900 Subject: [PATCH 3/3] Enable strict null checks, add tslint.json --- redux-auth-wrapper/tsconfig.json | 2 +- redux-auth-wrapper/tslint.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 redux-auth-wrapper/tslint.json diff --git a/redux-auth-wrapper/tsconfig.json b/redux-auth-wrapper/tsconfig.json index 844f327d0e..5aae706c27 100644 --- a/redux-auth-wrapper/tsconfig.json +++ b/redux-auth-wrapper/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": ["../"], "paths": { diff --git a/redux-auth-wrapper/tslint.json b/redux-auth-wrapper/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/redux-auth-wrapper/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }