@usesoftwareau/jwt-state 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -1
- package/deploy.sh +0 -10
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -85
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1633
- package/docs/functions/common.JWTProvider.html +0 -7
- package/docs/functions/common._useJWTState.html +0 -5
- package/docs/functions/index._useAuthReady.html +0 -3
- package/docs/functions/index._useClaims.html +0 -7
- package/docs/functions/index._useToken.html +0 -7
- package/docs/hierarchy.html +0 -1
- package/docs/index.html +0 -1
- package/docs/modules/common.html +0 -1
- package/docs/modules/index.html +0 -1
- package/docs/types/common.JWTContextValue.html +0 -2
- package/docs/types/common.JWTProviderProps.html +0 -2
- package/src/common.tsx +0 -73
- package/src/hooks.ts +0 -98
- package/src/index.tsx +0 -4
- package/src/reducer.ts +0 -98
- package/tsconfig.json +0 -12
- package/typedoc.json +0 -6
package/src/reducer.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { ActionsWithBatching } from "@usesoftwareau/react-utils";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface representing the standard claims type.
|
|
5
|
-
*/
|
|
6
|
-
export interface _ClaimsType {
|
|
7
|
-
aud: string;
|
|
8
|
-
exp: number;
|
|
9
|
-
iat: number;
|
|
10
|
-
iss: string;
|
|
11
|
-
sub: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Interface representing the state of the JWT reducer.
|
|
16
|
-
*/
|
|
17
|
-
export interface JWTReducerState<CustomClaims extends Record<string, any> = Record<string, any>> {
|
|
18
|
-
authReady: boolean;
|
|
19
|
-
claims: (_ClaimsType & CustomClaims) | null;
|
|
20
|
-
token: string | null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Action interface to set the authentication readiness value.
|
|
25
|
-
*/
|
|
26
|
-
interface SetAuthReadyValueAction {
|
|
27
|
-
type: "SET_AUTH_READY_VALUE";
|
|
28
|
-
payload: JWTReducerState["authReady"];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Action interface to set the token value.
|
|
33
|
-
*/
|
|
34
|
-
interface SetTokenValueAction {
|
|
35
|
-
type: "SET_TOKEN_VALUE";
|
|
36
|
-
payload: JWTReducerState["token"];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Action interface to set the claims value.
|
|
41
|
-
*/
|
|
42
|
-
interface SetClaimsValueAction<CustomClaims extends Record<string, any> = Record<string, any>> {
|
|
43
|
-
type: "SET_CLAIMS_VALUE";
|
|
44
|
-
payload: JWTReducerState<CustomClaims>["claims"];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Base action types for the JWT reducer.
|
|
49
|
-
*/
|
|
50
|
-
type ReducerBaseActions<CustomClaims extends Record<string, any> = Record<string, any>> =
|
|
51
|
-
| SetAuthReadyValueAction
|
|
52
|
-
| SetClaimsValueAction<CustomClaims>
|
|
53
|
-
| SetTokenValueAction;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* All possible action types for the JWT reducer.
|
|
57
|
-
*/
|
|
58
|
-
type ReducerAllActions<CustomClaims extends Record<string, any>> = ActionsWithBatching<ReducerBaseActions<CustomClaims>>;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Type representing all actions for the JWT reducer.
|
|
62
|
-
*/
|
|
63
|
-
export type JWTReducerActions<CustomClaims extends Record<string, any> = Record<string, any>> = ReducerAllActions<CustomClaims>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Reducer function to handle JWT reducer actions.
|
|
67
|
-
*/
|
|
68
|
-
export function reducerHandler<CustomClaims extends Record<string, any>>(prev: JWTReducerState<CustomClaims>, action: JWTReducerActions<CustomClaims>, originalPrev?: JWTReducerState<CustomClaims>): JWTReducerState<CustomClaims> {
|
|
69
|
-
const isSubAction = !!originalPrev;
|
|
70
|
-
const newState = isSubAction ? prev : { ...prev };
|
|
71
|
-
switch(action.type) {
|
|
72
|
-
case "MULTIPLE":
|
|
73
|
-
for(const subAction of action.payload) {
|
|
74
|
-
reducerHandler(newState, subAction, prev);
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
case "SET_AUTH_READY_VALUE":
|
|
78
|
-
newState.authReady = action.payload;
|
|
79
|
-
break;
|
|
80
|
-
case "SET_TOKEN_VALUE": {
|
|
81
|
-
newState.token = action.payload ?? null;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case "SET_CLAIMS_VALUE":
|
|
85
|
-
newState.claims = action.payload;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
return newState;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Initial state for the JWT reducer.
|
|
93
|
-
*/
|
|
94
|
-
export const initialJWTReducerState: JWTReducerState<any> = {
|
|
95
|
-
authReady: false,
|
|
96
|
-
claims: null,
|
|
97
|
-
token: null
|
|
98
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsconfig/react-native/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"outDir": "./build",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"noEmit": false,
|
|
9
|
-
"declaration": true
|
|
10
|
-
},
|
|
11
|
-
"exclude": ["./build", "./docs"]
|
|
12
|
-
}
|