namirasoft-account-react 1.0.1 → 1.2.0

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/.gitlab-ci.yml ADDED
@@ -0,0 +1,14 @@
1
+ stages:
2
+ - publish
3
+
4
+ publish:
5
+ stage: publish
6
+ script:
7
+ - rm -rf node_modules
8
+ - rm -rf dist
9
+ - ncu -u
10
+ - npm i
11
+ - tsc
12
+ - npm publish
13
+ only:
14
+ - master
@@ -1,7 +1,6 @@
1
1
  import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
2
  import { Messenger } from "./Messenger";
3
3
  import { ParsedNameValue } from "namirasoft-core";
4
- import { RouteComponentProps } from "react-router-dom";
5
4
  export interface IAccountProps {
6
5
  account: {
7
6
  token_manager: TokenManager;
@@ -16,5 +15,5 @@ export interface IAccountProps {
16
15
  redirect(sub: string, customQuery: {
17
16
  [name: string]: ParsedNameValue;
18
17
  }): void;
19
- } & RouteComponentProps;
18
+ };
20
19
  }
@@ -2,13 +2,9 @@ import { ReactNode } from "react";
2
2
  import { ParsedNameValue } from "namirasoft-core";
3
3
  import { IRouterStateChanger } from "./IRouterStateChanger";
4
4
  import { IRouterMaker } from "./IRouterMaker";
5
- import { RouteComponentProps } from 'react-router-dom';
6
- interface IProps extends RouteComponentProps {
7
- }
8
5
  export default class RouterMaker {
9
6
  private component;
10
- private props;
11
- constructor(component: IRouterStateChanger & IRouterMaker, props: IProps);
7
+ constructor(component: IRouterStateChanger & IRouterMaker);
12
8
  private init;
13
9
  getQuery(name: string): string;
14
10
  getLink(sub: string, customQuery: {
@@ -20,4 +16,3 @@ export default class RouterMaker {
20
16
  onComponentDidMount(): void;
21
17
  onRender(): ReactNode;
22
18
  }
23
- export {};
@@ -8,10 +8,22 @@ const namirasoft_core_1 = require("namirasoft-core");
8
8
  const Messenger_1 = require("./Messenger");
9
9
  const namirasoft_account_1 = require("namirasoft-account");
10
10
  const axios_1 = __importDefault(require("axios"));
11
+ // todo
12
+ // import { RouteComponentProps } from 'react-router-dom';
13
+ // todo
14
+ // interface IProps extends RouteComponentProps
15
+ // {
16
+ // }
11
17
  class RouterMaker {
12
- constructor(component, props) {
18
+ // todo
19
+ // private props: IProps;
20
+ constructor(component
21
+ // todo
22
+ // , props: IProps
23
+ ) {
13
24
  this.component = component;
14
- this.props = props;
25
+ // todo
26
+ // this.props = props;
15
27
  this.init = this.init.bind(this);
16
28
  this.getQuery = this.getQuery.bind(this);
17
29
  this.getLink = this.getLink.bind(this);
@@ -52,7 +64,13 @@ class RouterMaker {
52
64
  token_manager,
53
65
  server,
54
66
  },
55
- url: Object.assign({ getLink: this.getLink, redirect: this.redirect, getQuery: this.getQuery }, this.props),
67
+ url: {
68
+ getLink: this.getLink,
69
+ redirect: this.redirect,
70
+ getQuery: this.getQuery,
71
+ // todo
72
+ // ...this.props
73
+ },
56
74
  messenger,
57
75
  };
58
76
  let inited = true;
@@ -61,7 +79,7 @@ class RouterMaker {
61
79
  return { props, inited };
62
80
  }
63
81
  getQuery(name) {
64
- let location = this.props.location;
82
+ // todo fix location.
65
83
  let query = query_string_1.default.parse(location.search);
66
84
  let item = query[name];
67
85
  return new namirasoft_core_1.ObjectService(item).getString();
@@ -69,23 +87,25 @@ class RouterMaker {
69
87
  getLink(sub, customQuery) {
70
88
  if (!customQuery)
71
89
  customQuery = {};
72
- let location = this.props.location;
90
+ // todo fix location.
73
91
  let query = query_string_1.default.parse(location.search);
74
92
  let final = Object.assign(Object.assign({}, query), customQuery);
75
93
  return namirasoft_core_1.URLOperation.getLink("", sub, final);
76
94
  }
77
95
  redirect(sub, customQuery) {
78
- let ans = this.getLink(sub, customQuery);
79
- const { history } = this.props;
80
- history.push(ans);
96
+ // todo fix location.
97
+ console.log({ sub, customQuery });
98
+ // let ans = this.getLink(sub, customQuery);
99
+ // const { history } = this.props;
100
+ // history.push(ans);
81
101
  }
82
102
  onComponentDidMount() {
83
103
  let { inited, props } = this.init();
84
104
  this.component.setState({ notifications: [], inited });
85
105
  let token = this.getQuery("token");
86
106
  if (token) {
87
- if (!props.account.token_manager.getUserData(u => u.id, 0)) {
88
- props.account.server.session.get()
107
+ if (!props.account.token_manager.getUserData(u => u.id, "")) {
108
+ props.account.server.session.Current()
89
109
  .then(response => {
90
110
  props.account.token_manager.set(response, false);
91
111
  this.component.setState({ inited: true });
@@ -1 +1 @@
1
- {"version":3,"file":"RouterMaker.js","sourceRoot":"","sources":["../src/RouterMaker.ts"],"names":[],"mappings":";;;;;AAEA,gEAAuC;AACvC,qDAAwH;AAExH,2CAAwC;AACxC,2DAA2E;AAG3E,kDAA0B;AAO1B,MAAqB,WAAW;IAI5B,YAAY,SAA6C,EAAE,KAAa;QAEpE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IACO,IAAI;;QAER,IAAI,SAAS,GAAc,IAAI,qBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,QAAQ,GAAW,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,IAAI,GAA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{
2
- "name": "namirasoft-account-react",
3
- "description": "Namira Software Corporation Account React NPM Package",
4
- "version": "1.0.1",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "scripts": {},
8
- "author": "Amir Abolhasani",
9
- "license": "MIT",
10
- "dependencies": {
11
- "@types/react": "^18.2.36",
12
- "@types/react-router-dom": "^5.3.3",
13
- "namirasoft-account": "^1.0.3",
14
- "namirasoft-core": "^1.0.5",
15
- "query-string": "^8.1.0",
16
- "react": "^18.2.0",
17
- "react-router-dom": "^5.3.4",
18
- "run": "^1.4.0"
19
- }
1
+ {
2
+ "name": "namirasoft-account-react",
3
+ "description": "Namira Software Corporation Account React NPM Package",
4
+ "version": "1.2.0",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {},
8
+ "author": "Amir Abolhasani",
9
+ "license": "MIT",
10
+ "dependencies": {
11
+ "@types/react": "^18.2.47",
12
+ "namirasoft-account": "^1.2.3",
13
+ "namirasoft-core": "^1.2.5",
14
+ "query-string": "^8.1.0",
15
+ "react": "^18.2.0",
16
+ "react-router-dom": "^6.21.2",
17
+ "run": "^1.5.0"
18
+ }
20
19
  }
@@ -1,18 +1,17 @@
1
- import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
- import { Messenger } from "./Messenger";
3
- import { ParsedNameValue } from "namirasoft-core";
4
- import { RouteComponentProps } from "react-router-dom";
5
-
6
- export interface IAccountProps
7
- {
8
- account: {
9
- token_manager: TokenManager
10
- server: NamirasoftAccountServer;
11
- },
12
- messenger: Messenger;
13
- url: {
14
- getQuery(name: string): string;
15
- getLink(sub: string, customQuery: { [name: string]: ParsedNameValue }): string;
16
- redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void;
17
- } & RouteComponentProps
1
+ import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
+ import { Messenger } from "./Messenger";
3
+ import { ParsedNameValue } from "namirasoft-core";
4
+
5
+ export interface IAccountProps
6
+ {
7
+ account: {
8
+ token_manager: TokenManager
9
+ server: NamirasoftAccountServer;
10
+ },
11
+ messenger: Messenger;
12
+ url: {
13
+ getQuery(name: string): string;
14
+ getLink(sub: string, customQuery: { [name: string]: ParsedNameValue }): string;
15
+ redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void;
16
+ }
18
17
  }
@@ -1,8 +1,8 @@
1
- import { ReactNode } from "react";
2
- import { IAccountProps } from "./IAccountProps";
3
- export interface IRouterMaker
4
- {
5
- on401(): void;
6
- onRenderOnLogin(props: IAccountProps): ReactNode;
7
- onRenderOnLogout(props: IAccountProps, banned: boolean): ReactNode;
1
+ import { ReactNode } from "react";
2
+ import { IAccountProps } from "./IAccountProps";
3
+ export interface IRouterMaker
4
+ {
5
+ on401(): void;
6
+ onRenderOnLogin(props: IAccountProps): ReactNode;
7
+ onRenderOnLogout(props: IAccountProps, banned: boolean): ReactNode;
8
8
  }
@@ -1,7 +1,7 @@
1
- import { Notification } from "./Notification";
2
-
3
- export interface IRouterState
4
- {
5
- inited?: boolean;
6
- notifications?: Notification[];
1
+ import { Notification } from "./Notification";
2
+
3
+ export interface IRouterState
4
+ {
5
+ inited?: boolean;
6
+ notifications?: Notification[];
7
7
  }
@@ -1,7 +1,7 @@
1
- import { IRouterState } from "./IRouterState";
2
-
3
- export interface IRouterStateChanger
4
- {
5
- setState(state: IRouterState): void;
6
- getState(): IRouterState;
1
+ import { IRouterState } from "./IRouterState";
2
+
3
+ export interface IRouterStateChanger
4
+ {
5
+ setState(state: IRouterState): void;
6
+ getState(): IRouterState;
7
7
  }
package/src/Messenger.ts CHANGED
@@ -1,67 +1,67 @@
1
- import axios from "axios";
2
- import { IRouterStateChanger } from "./IRouterStateChanger";
3
- import { Notification } from "./Notification";
4
- import { NotificationType } from "./NotificationType";
5
-
6
- export class Messenger
7
- {
8
- static Counter: number = 1;
9
- private component: IRouterStateChanger;
10
- constructor(component: IRouterStateChanger)
11
- {
12
- this.component = component;
13
- this.notify = this.notify.bind(this);
14
- this.onInformation = this.onInformation.bind(this);
15
- this.onSuccess = this.onSuccess.bind(this);
16
- this.onWarning = this.onWarning.bind(this);
17
- this.onError = this.onError.bind(this);
18
- this.delNotification = this.delNotification.bind(this);
19
- }
20
- private notify(message: Notification)
21
- {
22
- let state = this.component.getState();
23
- let id = Messenger.Counter++;
24
- if (!state.notifications)
25
- state.notifications = [];
26
- state.notifications[id] = message;
27
- this.component.setState(state);
28
- setTimeout(() =>
29
- {
30
- this.delNotification(id);
31
- }, 5000);
32
- window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
33
- }
34
- onInformation(text: string)
35
- {
36
- this.notify({ text, type: NotificationType.Information, color: "black" });
37
- }
38
- onSuccess(text: string)
39
- {
40
- this.notify({ text, type: NotificationType.Success, color: "green" });
41
- }
42
- onWarning(text: string)
43
- {
44
- this.notify({ text, type: NotificationType.Warning, color: "yellow" });
45
- }
46
- onError(error: Error | string)
47
- {
48
- let text: string = "";
49
- if (error instanceof Error)
50
- {
51
- text = error.message;
52
- if (axios.isAxiosError(error))
53
- if (error.response?.data)
54
- text = error.response.data;
55
- }
56
- else
57
- text = error;
58
- this.notify({ text, type: NotificationType.Error, color: "red" });
59
- }
60
- delNotification(id: number): void
61
- {
62
- let state = this.component.getState();
63
- if (state.notifications)
64
- delete state.notifications[id];
65
- this.component.setState(state);
66
- }
1
+ import axios from "axios";
2
+ import { IRouterStateChanger } from "./IRouterStateChanger";
3
+ import { Notification } from "./Notification";
4
+ import { NotificationType } from "./NotificationType";
5
+
6
+ export class Messenger
7
+ {
8
+ static Counter: number = 1;
9
+ private component: IRouterStateChanger;
10
+ constructor(component: IRouterStateChanger)
11
+ {
12
+ this.component = component;
13
+ this.notify = this.notify.bind(this);
14
+ this.onInformation = this.onInformation.bind(this);
15
+ this.onSuccess = this.onSuccess.bind(this);
16
+ this.onWarning = this.onWarning.bind(this);
17
+ this.onError = this.onError.bind(this);
18
+ this.delNotification = this.delNotification.bind(this);
19
+ }
20
+ private notify(message: Notification)
21
+ {
22
+ let state = this.component.getState();
23
+ let id = Messenger.Counter++;
24
+ if (!state.notifications)
25
+ state.notifications = [];
26
+ state.notifications[id] = message;
27
+ this.component.setState(state);
28
+ setTimeout(() =>
29
+ {
30
+ this.delNotification(id);
31
+ }, 5000);
32
+ window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
33
+ }
34
+ onInformation(text: string)
35
+ {
36
+ this.notify({ text, type: NotificationType.Information, color: "black" });
37
+ }
38
+ onSuccess(text: string)
39
+ {
40
+ this.notify({ text, type: NotificationType.Success, color: "green" });
41
+ }
42
+ onWarning(text: string)
43
+ {
44
+ this.notify({ text, type: NotificationType.Warning, color: "yellow" });
45
+ }
46
+ onError(error: Error | string)
47
+ {
48
+ let text: string = "";
49
+ if (error instanceof Error)
50
+ {
51
+ text = error.message;
52
+ if (axios.isAxiosError(error))
53
+ if (error.response?.data)
54
+ text = error.response.data;
55
+ }
56
+ else
57
+ text = error;
58
+ this.notify({ text, type: NotificationType.Error, color: "red" });
59
+ }
60
+ delNotification(id: number): void
61
+ {
62
+ let state = this.component.getState();
63
+ if (state.notifications)
64
+ delete state.notifications[id];
65
+ this.component.setState(state);
66
+ }
67
67
  }
@@ -1,8 +1,8 @@
1
- import { NotificationType } from "./NotificationType";
2
-
3
- export type Notification =
4
- {
5
- text: string;
6
- type: NotificationType;
7
- color: string;
1
+ import { NotificationType } from "./NotificationType";
2
+
3
+ export type Notification =
4
+ {
5
+ text: string;
6
+ type: NotificationType;
7
+ color: string;
8
8
  }
@@ -1,7 +1,7 @@
1
- export enum NotificationType
2
- {
3
- Information = "Information",
4
- Warning = "Warning",
5
- Success = "Success",
6
- Error = "Error",
1
+ export enum NotificationType
2
+ {
3
+ Information = "Information",
4
+ Warning = "Warning",
5
+ Success = "Success",
6
+ Error = "Error",
7
7
  }
@@ -1,137 +1,147 @@
1
-
2
- import { ReactNode } from "react";
3
- import queryString from 'query-string';
4
- import { IStorage, IStorageLocal, IStorageMemory, ObjectService, ParsedNameValue, URLOperation } from "namirasoft-core";
5
- import { IRouterStateChanger } from "./IRouterStateChanger";
6
- import { Messenger } from "./Messenger";
7
- import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
8
- import { IAccountProps } from "./IAccountProps";
9
- import { IRouterMaker } from "./IRouterMaker";
10
- import axios from "axios";
11
- import { RouteComponentProps } from 'react-router-dom';
12
-
13
- interface IProps extends RouteComponentProps
14
- {
15
- }
16
-
17
- export default class RouterMaker
18
- {
19
- private component: IRouterStateChanger & IRouterMaker;
20
- private props: IProps;
21
- constructor(component: IRouterStateChanger & IRouterMaker, props: IProps)
22
- {
23
- this.component = component;
24
- this.props = props;
25
- this.init = this.init.bind(this);
26
- this.getQuery = this.getQuery.bind(this);
27
- this.getLink = this.getLink.bind(this);
28
- this.redirect = this.redirect.bind(this);
29
- this.onComponentDidMount = this.onComponentDidMount.bind(this);
30
- this.onRender = this.onRender.bind(this);
31
- }
32
- private init(): { props: IAccountProps, inited: boolean }
33
- {
34
- let messenger: Messenger = new Messenger(this.component);
35
- let qStorage: string = this.getQuery("location");
36
- let qAPI: string = this.getQuery("api");
37
- let qToken: string = this.getQuery("token");
38
- if (!qStorage)
39
- if (qAPI)
40
- qStorage = "memory";
41
- let storage: IStorage;
42
- if (qStorage === "memory")
43
- storage = new IStorageMemory();
44
- else
45
- storage = new IStorageLocal();
46
- let token_manager = new TokenManager(storage, () => this.component.setState({}));
47
- if (qToken)
48
- token_manager.setValue(qToken, true);
49
- let server = new NamirasoftAccountServer(token_manager, (error: Error) =>
50
- {
51
- if (axios.isAxiosError(error))
52
- if (error.response)
53
- if (error.response?.status === 401)
54
- {
55
- token_manager.del();
56
- this.component.on401();
57
- return;
58
- }
59
- messenger.onError(error);
60
- });
61
- let props: IAccountProps = {
62
- account: {
63
- token_manager,
64
- server,
65
- },
66
- url: {
67
- getLink: this.getLink,
68
- redirect: this.redirect,
69
- getQuery: this.getQuery,
70
- ...this.props
71
- },
72
- messenger,
73
- };
74
- let inited = true;
75
- if (qToken)
76
- inited = this.component.getState().inited ?? false;
77
- return { props, inited };
78
- }
79
- getQuery(name: string): string
80
- {
81
- let location = this.props.location;
82
- let query = queryString.parse(location.search);
83
- let item = query[name];
84
- return new ObjectService(item).getString();
85
- }
86
- getLink(sub: string, customQuery: { [name: string]: ParsedNameValue })
87
- {
88
- if (!customQuery)
89
- customQuery = {};
90
- let location = this.props.location;
91
- let query = queryString.parse(location.search);
92
- let final = { ...query, ...customQuery };
93
- return URLOperation.getLink("", sub, final);
94
- }
95
- redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void
96
- {
97
- let ans = this.getLink(sub, customQuery);
98
- const { history } = this.props;
99
- history.push(ans);
100
- }
101
- onComponentDidMount(): void
102
- {
103
- let { inited, props } = this.init();
104
- this.component.setState({ notifications: [], inited });
105
- let token = this.getQuery("token");
106
- if (token)
107
- {
108
- if (!props.account.token_manager.getUserData(u => u.id, 0))
109
- {
110
- props.account.server.session.get()
111
- .then(response =>
112
- {
113
- props.account.token_manager.set(response, false);
114
- this.component.setState({ inited: true });
115
- })
116
- .catch(() =>
117
- {
118
- this.component.setState({ inited: true });
119
- });
120
- }
121
- }
122
- }
123
- onRender(): ReactNode
124
- {
125
- let { inited, props } = this.init();
126
- if (!inited)
127
- return null;
128
- let banned = false;
129
- if (props.account.token_manager.exists())
130
- {
131
- banned = props.account.token_manager.getUserData(user => user.banned, false);
132
- if (!banned)
133
- return this.component.onRenderOnLogin(props);
134
- }
135
- return this.component.onRenderOnLogout(props, banned);
136
- }
1
+
2
+ import { ReactNode } from "react";
3
+ import queryString from 'query-string';
4
+ import { IStorage, IStorageLocal, IStorageMemory, ObjectService, ParsedNameValue, URLOperation } from "namirasoft-core";
5
+ import { IRouterStateChanger } from "./IRouterStateChanger";
6
+ import { Messenger } from "./Messenger";
7
+ import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
8
+ import { IAccountProps } from "./IAccountProps";
9
+ import { IRouterMaker } from "./IRouterMaker";
10
+ import axios from "axios";
11
+ // todo
12
+ // import { RouteComponentProps } from 'react-router-dom';
13
+
14
+ // todo
15
+ // interface IProps extends RouteComponentProps
16
+ // {
17
+ // }
18
+
19
+ export default class RouterMaker
20
+ {
21
+ private component: IRouterStateChanger & IRouterMaker;
22
+ // todo
23
+ // private props: IProps;
24
+ constructor(component: IRouterStateChanger & IRouterMaker
25
+ // todo
26
+ // , props: IProps
27
+ )
28
+ {
29
+ this.component = component;
30
+ // todo
31
+ // this.props = props;
32
+ this.init = this.init.bind(this);
33
+ this.getQuery = this.getQuery.bind(this);
34
+ this.getLink = this.getLink.bind(this);
35
+ this.redirect = this.redirect.bind(this);
36
+ this.onComponentDidMount = this.onComponentDidMount.bind(this);
37
+ this.onRender = this.onRender.bind(this);
38
+ }
39
+ private init(): { props: IAccountProps, inited: boolean }
40
+ {
41
+ let messenger: Messenger = new Messenger(this.component);
42
+ let qStorage: string = this.getQuery("location");
43
+ let qAPI: string = this.getQuery("api");
44
+ let qToken: string = this.getQuery("token");
45
+ if (!qStorage)
46
+ if (qAPI)
47
+ qStorage = "memory";
48
+ let storage: IStorage;
49
+ if (qStorage === "memory")
50
+ storage = new IStorageMemory();
51
+ else
52
+ storage = new IStorageLocal();
53
+ let token_manager = new TokenManager(storage, () => this.component.setState({}));
54
+ if (qToken)
55
+ token_manager.setValue(qToken, true);
56
+ let server = new NamirasoftAccountServer(token_manager, (error: Error) =>
57
+ {
58
+ if (axios.isAxiosError(error))
59
+ if (error.response)
60
+ if (error.response?.status === 401)
61
+ {
62
+ token_manager.del();
63
+ this.component.on401();
64
+ return;
65
+ }
66
+ messenger.onError(error);
67
+ });
68
+ let props: IAccountProps = {
69
+ account: {
70
+ token_manager,
71
+ server,
72
+ },
73
+ url: {
74
+ getLink: this.getLink,
75
+ redirect: this.redirect,
76
+ getQuery: this.getQuery,
77
+ // todo
78
+ // ...this.props
79
+ },
80
+ messenger,
81
+ };
82
+ let inited = true;
83
+ if (qToken)
84
+ inited = this.component.getState().inited ?? false;
85
+ return { props, inited };
86
+ }
87
+ getQuery(name: string): string
88
+ {
89
+ // todo fix location.
90
+ let query = queryString.parse(location.search);
91
+ let item = query[name];
92
+ return new ObjectService(item).getString();
93
+ }
94
+ getLink(sub: string, customQuery: { [name: string]: ParsedNameValue })
95
+ {
96
+ if (!customQuery)
97
+ customQuery = {};
98
+ // todo fix location.
99
+ let query = queryString.parse(location.search);
100
+ let final = { ...query, ...customQuery };
101
+ return URLOperation.getLink("", sub, final);
102
+ }
103
+ redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void
104
+ {
105
+ // todo fix location.
106
+ console.log({ sub, customQuery });
107
+ // let ans = this.getLink(sub, customQuery);
108
+ // const { history } = this.props;
109
+ // history.push(ans);
110
+ }
111
+ onComponentDidMount(): void
112
+ {
113
+ let { inited, props } = this.init();
114
+ this.component.setState({ notifications: [], inited });
115
+ let token = this.getQuery("token");
116
+ if (token)
117
+ {
118
+ if (!props.account.token_manager.getUserData(u => u.id, ""))
119
+ {
120
+ props.account.server.session.Current()
121
+ .then(response =>
122
+ {
123
+ props.account.token_manager.set(response, false);
124
+ this.component.setState({ inited: true });
125
+ })
126
+ .catch(() =>
127
+ {
128
+ this.component.setState({ inited: true });
129
+ });
130
+ }
131
+ }
132
+ }
133
+ onRender(): ReactNode
134
+ {
135
+ let { inited, props } = this.init();
136
+ if (!inited)
137
+ return null;
138
+ let banned = false;
139
+ if (props.account.token_manager.exists())
140
+ {
141
+ banned = props.account.token_manager.getUserData(user => user.banned, false);
142
+ if (!banned)
143
+ return this.component.onRenderOnLogin(props);
144
+ }
145
+ return this.component.onRenderOnLogout(props, banned);
146
+ }
137
147
  };
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
- export * from "./IAccountProps";
2
- export * from "./IRouterMaker";
3
- export * from "./IRouterState";
4
- export * from "./IRouterStateChanger";
5
- export * from "./Messenger";
6
- export * from "./Notification";
7
- export * from "./NotificationType";
1
+ export * from "./IAccountProps";
2
+ export * from "./IRouterMaker";
3
+ export * from "./IRouterState";
4
+ export * from "./IRouterStateChanger";
5
+ export * from "./Messenger";
6
+ export * from "./Notification";
7
+ export * from "./NotificationType";
8
8
  export { default as RouterMaker } from "./RouterMaker";
package/tsconfig.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "CommonJS",
5
- "rootDir": "./src",
6
- "outDir": "./dist",
7
- "lib": [
8
- "es6",
9
- "dom"
10
- ],
11
- "allowJs": false,
12
- "checkJs": false,
13
- "strict": true,
14
- "esModuleInterop": true,
15
- "sourceMap": true,
16
- "resolveJsonModule": true,
17
- "declaration": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "noImplicitAny": true,
21
- "noImplicitOverride": true,
22
- "noImplicitReturns": true,
23
- "noImplicitThis": true,
24
- "skipLibCheck": false,
25
- "allowSyntheticDefaultImports": true,
26
- "forceConsistentCasingInFileNames": true,
27
- "noFallthroughCasesInSwitch": true,
28
- "isolatedModules": false,
29
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "module": "CommonJS",
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "lib": [
8
+ "es6",
9
+ "dom"
10
+ ],
11
+ "allowJs": false,
12
+ "checkJs": false,
13
+ "strict": true,
14
+ "esModuleInterop": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "declaration": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noImplicitAny": true,
21
+ "noImplicitOverride": true,
22
+ "noImplicitReturns": true,
23
+ "noImplicitThis": true,
24
+ "skipLibCheck": false,
25
+ "allowSyntheticDefaultImports": true,
26
+ "forceConsistentCasingInFileNames": true,
27
+ "noFallthroughCasesInSwitch": true,
28
+ "isolatedModules": false,
29
+ }
30
30
  }