@bcrumbs.net/bc-shared 0.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/README.md +0 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +11093 -0
- package/package.json +28 -0
- package/src/index.d.ts +6 -0
- package/src/lib/components/LogoutRoute/index.d.ts +4 -0
- package/src/lib/components/RoutesGaurd/index.d.ts +10 -0
- package/src/lib/components/index.d.ts +2 -0
- package/src/lib/config/routes.d.ts +43 -0
- package/src/lib/services/auth/index.d.ts +123 -0
- package/src/lib/services/i18n/index.d.ts +11 -0
- package/src/lib/types/index.d.ts +7 -0
- package/src/lib/utils/allSynchronously.d.ts +1 -0
- package/src/lib/utils/arrays.d.ts +4 -0
- package/src/lib/utils/index.d.ts +4 -0
- package/src/lib/utils/strings.d.ts +5 -0
- package/src/lib/utils/time.d.ts +5 -0
- package/src/lib/utils/typesUtils.d.ts +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bcrumbs.net/bc-shared",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"keyword": [
|
|
5
|
+
"bcrumbs",
|
|
6
|
+
"bc-shared",
|
|
7
|
+
"Bread Crumbs"
|
|
8
|
+
],
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "Ahmad Mhaish"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"i18next": "^21.6.14",
|
|
14
|
+
"react-i18next": "^11.15.6",
|
|
15
|
+
"date-fns": "^2.28.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"jwt-decode": "^3.1.2",
|
|
19
|
+
"i18next-browser-languagedetector": "^6.1.3",
|
|
20
|
+
"i18next-http-backend": "^1.3.2",
|
|
21
|
+
"next-with-apollo": "^5.3.0",
|
|
22
|
+
"apollo-cache-inmemory": "^1.6.6",
|
|
23
|
+
"apollo-link-http": "^1.5.17"
|
|
24
|
+
},
|
|
25
|
+
"module": "./index.esm.js",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./index.esm.js"
|
|
28
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const BCRoutes: {
|
|
2
|
+
AccountDashboard: string;
|
|
3
|
+
Subscriptions: string;
|
|
4
|
+
NewSubscription: string;
|
|
5
|
+
Upgrade: string;
|
|
6
|
+
Payments: string;
|
|
7
|
+
Invitation: string;
|
|
8
|
+
Forget: string;
|
|
9
|
+
Guide: string;
|
|
10
|
+
Welcome: string;
|
|
11
|
+
Login: string;
|
|
12
|
+
Register: string;
|
|
13
|
+
Password: string;
|
|
14
|
+
Profile: string;
|
|
15
|
+
Logout: string;
|
|
16
|
+
NotFound: string;
|
|
17
|
+
Error: string;
|
|
18
|
+
NoPermissions: string;
|
|
19
|
+
ShowcaseDashboard: string;
|
|
20
|
+
ShowcasePages: string;
|
|
21
|
+
ShowcaseSections: string;
|
|
22
|
+
ShowcaseContentEditor: string;
|
|
23
|
+
ShowcasePageDesigner: string;
|
|
24
|
+
ShowcaseTemplates: string;
|
|
25
|
+
ShowcaseSectionTemplates: string;
|
|
26
|
+
ShowcaseSettings: string;
|
|
27
|
+
ShowcaseNotFound: string;
|
|
28
|
+
HyChartCharts: string;
|
|
29
|
+
HyChartSettings: string;
|
|
30
|
+
HyChartNotFound: string;
|
|
31
|
+
ListResources: string;
|
|
32
|
+
CreateResource: string;
|
|
33
|
+
PatchResource: string;
|
|
34
|
+
DeleteResource: string;
|
|
35
|
+
ResourcesNotFound: string;
|
|
36
|
+
Inbox: string;
|
|
37
|
+
EmbeddedInbox: string;
|
|
38
|
+
Broadcast: string;
|
|
39
|
+
BroadcastEdit: string;
|
|
40
|
+
BroadcastCreate: string;
|
|
41
|
+
ConvsSearch: string;
|
|
42
|
+
Dashboard: string;
|
|
43
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
type STORES_TYPES = 'localStorage' | 'sessionStorage';
|
|
2
|
+
type Storage = STORES_TYPES;
|
|
3
|
+
type TokenKey = string;
|
|
4
|
+
type ContextKey = string;
|
|
5
|
+
type UserInfoKey = string;
|
|
6
|
+
type User = {
|
|
7
|
+
name?: string;
|
|
8
|
+
surname?: string;
|
|
9
|
+
username?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
id: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const auth: {
|
|
14
|
+
/**
|
|
15
|
+
* get token from localstorage
|
|
16
|
+
*
|
|
17
|
+
* @param {'localStorage' | 'sessionStorage'} [fromStorage='localStorage'] specify storage
|
|
18
|
+
* @param {any} [tokenKey=TOKEN_KEY] optionnal parameter to specify a token key
|
|
19
|
+
* @returns {string} token value
|
|
20
|
+
*/
|
|
21
|
+
getToken(fromStorage?: Storage, tokenKey?: TokenKey): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* set the token value into localstorage (managed by localforage)
|
|
24
|
+
*
|
|
25
|
+
* @param {string} [value=''] token value
|
|
26
|
+
* @param {'localStorage' | 'sessionStorage'} [toStorage='localStorage'] specify storage
|
|
27
|
+
* @param {any} [tokenKey='token'] token key
|
|
28
|
+
* @returns {boolean} success/failure flag
|
|
29
|
+
*/
|
|
30
|
+
setToken(value?: string, toStorage?: Storage, tokenKey?: TokenKey): void;
|
|
31
|
+
/**
|
|
32
|
+
* check
|
|
33
|
+
* - if token key contains a valid token value (defined and not an empty value)
|
|
34
|
+
* - if the token expiration date is passed
|
|
35
|
+
*
|
|
36
|
+
*
|
|
37
|
+
* Note: 'isAuthenticated' just checks 'tokenKey' on store (localStorage by default or sessionStorage)
|
|
38
|
+
*
|
|
39
|
+
* You may think: 'ok I just put an empty token key and I have access to protected routes?''
|
|
40
|
+
* -> answer is: YES^^
|
|
41
|
+
* BUT
|
|
42
|
+
* -> : your backend will not recognize a wrong token so private data or safe and you protected view could be a bit ugly without any data.
|
|
43
|
+
*
|
|
44
|
+
* => ON CONCLUSION: this aim of 'isAuthenticated'
|
|
45
|
+
* -> is to help for a better "user experience" (= better than displaying a view with no data since server did not accept the user).
|
|
46
|
+
* -> it is not a security purpose (security comes from backend, since frontend is easily hackable => user has access to all your frontend)
|
|
47
|
+
*
|
|
48
|
+
* @param {'localStorage' | 'sessionStorage'} [fromStorage='localStorage'] specify storage
|
|
49
|
+
* @param {any} [tokenKey=TOKEN_KEY] token key
|
|
50
|
+
* @returns {bool} is authenticed response
|
|
51
|
+
*/
|
|
52
|
+
isAuthenticated(fromStorage?: Storage, tokenKey?: TokenKey): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* delete token
|
|
55
|
+
*
|
|
56
|
+
* @param {any} [tokenKey='token'] token key
|
|
57
|
+
* @returns {bool} success/failure flag
|
|
58
|
+
*/
|
|
59
|
+
clearToken(storage?: Storage, tokenKey?: TokenKey): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* return expiration date from token
|
|
62
|
+
*
|
|
63
|
+
* @param {string} encodedToken - base 64 token received from server and stored in local storage
|
|
64
|
+
* @returns {date | null} returns expiration date or null id expired props not found in decoded token
|
|
65
|
+
*/
|
|
66
|
+
getTokenExpirationDate(encodedToken: string): Date;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* tell is token is expired (compared to now)
|
|
70
|
+
*
|
|
71
|
+
* @param {string} encodedToken - base 64 token received from server and stored in local storage
|
|
72
|
+
* @returns {bool} returns true if expired else false
|
|
73
|
+
*/
|
|
74
|
+
isExpiredToken(encodedToken: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* get user info from localstorage
|
|
77
|
+
*
|
|
78
|
+
* @param {'localStorage' | 'sessionStorage'} [fromStorage='localStorage'] specify storage
|
|
79
|
+
* @param {any} [userInfoKey='userInfo'] optionnal parameter to specify a token key
|
|
80
|
+
* @returns {string} token value
|
|
81
|
+
*/
|
|
82
|
+
getUserInfo(fromStorage?: Storage, userInfoKey?: UserInfoKey): any;
|
|
83
|
+
/**
|
|
84
|
+
* set the userInfo value into localstorage
|
|
85
|
+
*
|
|
86
|
+
* @param {object} [value=''] token value
|
|
87
|
+
* @param {'localStorage' | 'sessionStorage'} [toStorage='localStorage'] specify storage
|
|
88
|
+
* @param {any} [userInfoKey='userInfo'] token key
|
|
89
|
+
* @returns {boolean} success/failure flag
|
|
90
|
+
*/
|
|
91
|
+
setUserInfo(value: User, toStorage?: Storage, userInfoKey?: UserInfoKey): void;
|
|
92
|
+
updateUserInfo(value: User, toStorage?: Storage, userInfoKey?: UserInfoKey): any;
|
|
93
|
+
/**
|
|
94
|
+
* delete userInfo
|
|
95
|
+
*
|
|
96
|
+
* @param {string} [userInfoKey='userInfo'] token key
|
|
97
|
+
* @returns {bool} success/failure flag
|
|
98
|
+
*/
|
|
99
|
+
clearUserInfo(userInfoKey?: UserInfoKey): any;
|
|
100
|
+
/**
|
|
101
|
+
* forget me method: clear all
|
|
102
|
+
* @returns {bool} success/failure flag
|
|
103
|
+
*/
|
|
104
|
+
clearAllAppStorage(): void;
|
|
105
|
+
/**
|
|
106
|
+
* set the context value into localstorage (managed by localforage)
|
|
107
|
+
*
|
|
108
|
+
* @param {string} [value=''] context value
|
|
109
|
+
* @param {'localStorage' | 'sessionStorage'} [toStorage='localStorage'] specify storage
|
|
110
|
+
* @param {any} [tokenKey='token'] token key
|
|
111
|
+
* @returns {boolean} success/failure flag
|
|
112
|
+
*/
|
|
113
|
+
setContext(value?: string, toStorage?: Storage, contextKey?: ContextKey): void;
|
|
114
|
+
/**
|
|
115
|
+
* get context from localstorage
|
|
116
|
+
*
|
|
117
|
+
* @param {'localStorage' | 'sessionStorage'} [fromStorage='localStorage'] specify storage
|
|
118
|
+
* @param {any} [tokenKey=TOKEN_KEY] optionnal parameter to specify a token key
|
|
119
|
+
* @returns {number} token value
|
|
120
|
+
*/
|
|
121
|
+
getContext(fromStorage?: Storage, contextKey?: ContextKey): number | null | undefined;
|
|
122
|
+
};
|
|
123
|
+
export default auth;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const LOCAL_STORAGE_I18N_STRING = "I18N_SELECTION";
|
|
2
|
+
export declare const LangService: {
|
|
3
|
+
init: () => void;
|
|
4
|
+
changeLang: (lang: Languages) => void;
|
|
5
|
+
getLang: () => string;
|
|
6
|
+
};
|
|
7
|
+
export declare enum Languages {
|
|
8
|
+
EN = "en",
|
|
9
|
+
AR = "ar",
|
|
10
|
+
TR = "tr"
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function allSynchronously<T>(resolvables: (() => Promise<T>)[]): Promise<T[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const propertyOf: <TObj>(name: keyof TObj) => keyof TObj;
|