@thzero/library_client_vue3_store_pinia 0.19.2 → 0.19.3

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.
@@ -1,41 +1,41 @@
1
- import LibraryClientConstants from '@thzero/library_client/constants';
2
-
3
- import LibraryClientUtility from '@thzero/library_client/utility/index';
4
- import LibraryCommonUtility from '@thzero/library_common/utility';
5
-
6
- const store = {
7
- pluginPersistPaths: {
8
- persist: [
9
- // the state key; this said 'news', which is not one, so nothing persisted
10
- 'latest'
11
- ]
12
- },
13
- state: () => ({
14
- latest: null
15
- }),
16
- actions: {
17
- async deleteNews(correlationId, id) {
18
- LibraryCommonUtility.deleteArrayById(this.latest, id);
19
- },
20
- async getLatestNews(correlationId) {
21
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_NEWS);
22
- const response = await service.latest(correlationId);
23
- this.$logger.debug('store.news', 'getLatestNews', 'response', response, correlationId);
24
- const latest = response.success && response.results ? response.results.data : null;
25
- this.$logger.debug('store.news', 'getLatestNews', 'item.a', latest, correlationId);
26
- this.$logger.debug('store.news', 'getLatestNews', 'item.b', this.latest, correlationId);
27
- this.latest = latest;
28
- this.$logger.debug('store.news', 'getLatestNews', 'item.c', this.latest, correlationId);
29
- }
30
- },
31
- dispatcher: {
32
- async delete(correlationId, id) {
33
- await LibraryClientUtility.$store.news.deleteNews(correlationId, id);
34
- },
35
- async getLatest(correlationId) {
36
- await LibraryClientUtility.$store.news.getLatestNews(correlationId);
37
- }
38
- }
39
- };
40
-
41
- export default store;
1
+ import LibraryClientConstants from '@thzero/library_client/constants';
2
+
3
+ import LibraryClientUtility from '@thzero/library_client/utility/index';
4
+ import LibraryCommonUtility from '@thzero/library_common/utility';
5
+
6
+ const store = {
7
+ pluginPersistPaths: {
8
+ persist: [
9
+ // the state key; this said 'news', which is not one, so nothing persisted
10
+ 'latest'
11
+ ]
12
+ },
13
+ state: () => ({
14
+ latest: null
15
+ }),
16
+ actions: {
17
+ async deleteNews(correlationId, id) {
18
+ LibraryCommonUtility.deleteArrayById(this.latest, id);
19
+ },
20
+ async getLatestNews(correlationId) {
21
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_NEWS);
22
+ const response = await service.latest(correlationId);
23
+ this.$logger.debug('store.news', 'getLatestNews', 'response', response, correlationId);
24
+ const latest = response.success && response.results ? response.results.data : null;
25
+ this.$logger.debug('store.news', 'getLatestNews', 'item.a', latest, correlationId);
26
+ this.$logger.debug('store.news', 'getLatestNews', 'item.b', this.latest, correlationId);
27
+ this.latest = latest;
28
+ this.$logger.debug('store.news', 'getLatestNews', 'item.c', this.latest, correlationId);
29
+ }
30
+ },
31
+ dispatcher: {
32
+ async delete(correlationId, id) {
33
+ await LibraryClientUtility.$store.news.deleteNews(correlationId, id);
34
+ },
35
+ async getLatest(correlationId) {
36
+ await LibraryClientUtility.$store.news.getLatestNews(correlationId);
37
+ }
38
+ }
39
+ };
40
+
41
+ export default store;
@@ -1,138 +1,138 @@
1
- import LibraryClientConstants from '@thzero/library_client/constants';
2
-
3
- import LibraryClientUtility from '@thzero/library_client/utility/index';
4
- import LibraryClientVueUtility from '@thzero/library_client_vue3/utility';
5
-
6
- import Response from '@thzero/library_common/response';
7
-
8
- const store = {
9
- pluginPersistPaths: {
10
- persist: [
11
- 'settings',
12
- 'user'
13
- ]
14
- },
15
- state: () => ({
16
- authCompleted: false,
17
- claims: null,
18
- isLoggedIn: false,
19
- settings: {},
20
- theme: 'defaultTheme',
21
- token: null,
22
- tokenResult: null,
23
- user: null
24
- }),
25
- actions: {
26
- async refreshUserSettings(correlationId) {
27
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
28
- const response = await service.refreshSettings(correlationId, this.user);
29
- this.$logger.debug('store.user', 'refreshUserSettings', 'response', response);
30
- // setUser(correlationId, user): without the correlationId the user was
31
- // set to undefined
32
- if (Response.hasSucceeded(response) && response.results)
33
- await this.setUser(correlationId, response.results);
34
- return response;
35
- },
36
- async resetUser(correlationId) {
37
- this.$patch({
38
- claims: null,
39
- isLoggedIn: false,
40
- token: null,
41
- tokenResult: null,
42
- settings: {},
43
- user: null
44
- });
45
- },
46
- async setUser(correlationId, user) {
47
- if (user) {
48
- this.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, user.settings);
49
- delete user.settings;
50
- }
51
- this.user = user;
52
- },
53
- async setUserAuthCompleted(correlationId, authCompleted) {
54
- this.authCompleted = authCompleted;
55
- },
56
- async setUserClaims(correlationId, claims) {
57
- this.claims = claims;
58
- },
59
- async setUserLoggedIn(correlationId, isLoggedIn) {
60
- this.isLoggedIn = isLoggedIn;
61
- },
62
- async setUserSettings(correlationId, settings) {
63
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
64
- settings = LibraryClientVueUtility.settings().mergeUser(correlationId, settings);
65
- if (this.isLoggedIn) {
66
- const response = await service.updateSettings(correlationId, this.user, settings);
67
- this.$logger.debug('store.user', 'setUserSettings', 'response', response);
68
- if (Response.hasSucceeded(response) && response.results) {
69
- // this.settings = response.results.settings;
70
- // delete response.results.settings;
71
- // this.user = response.results;
72
- // response.results = this.settings;
73
- this.setUser(correlationId, response.results);
74
- response.results = this.settings;
75
- }
76
- return response;
77
- }
78
- this.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, settings);
79
- return Response.success(correlationId, this.settings);
80
- },
81
- async setUserTheme(correlationId, theme) {
82
- this.theme = theme;
83
- },
84
- async setUserTokenResult(correlationId, tokenResult) {
85
- this.$patch({
86
- tokenResult: tokenResult ?? null,
87
- token: tokenResult ? tokenResult.token : null
88
- });
89
- }
90
- },
91
- getters: {
92
- getUser (correlationId) {
93
- return LibraryClientUtility.$store.user.user;
94
- },
95
- getUserTheme (correlationId) {
96
- // theme lives on the user module, not the root store
97
- return LibraryClientUtility.$store.user.theme;
98
- },
99
- getUserSettings(correlationId) {
100
- if (LibraryClientUtility.$store.user.settings) // TODO: userRef
101
- return LibraryClientUtility.$store.user.settings;
102
-
103
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
104
- return service.initializeSettings();
105
- }
106
- },
107
- dispatcher: {
108
- async refreshUserSettings(correlationId) {
109
- return await LibraryClientUtility.$store.user.refreshUserSettings(correlationId);
110
- },
111
- async resetUser(correlationId) {
112
- await LibraryClientUtility.$store.user.resetUser(correlationId);
113
- },
114
- async setUserAuthCompleted(correlationId, authCompleted) {
115
- await LibraryClientUtility.$store.user.setUserAuthCompleted(correlationId, authCompleted);
116
- },
117
- async setUserClaims(correlationId, claims) {
118
- await LibraryClientUtility.$store.user.setUserClaims(correlationId, claims);
119
- },
120
- async setUserLoggedIn(correlationId, isLoggedIn) {
121
- await LibraryClientUtility.$store.user.setUserLoggedIn(correlationId, isLoggedIn);
122
- },
123
- async setUserSettings(correlationId, settings) {
124
- return await LibraryClientUtility.$store.user.setUserSettings(correlationId, settings);
125
- },
126
- async setUserTheme(correlationId, theme) {
127
- await LibraryClientUtility.$store.user.setUserTheme(correlationId, theme);
128
- },
129
- async setUserTokenResult(correlationId, tokenResult) {
130
- await LibraryClientUtility.$store.user.setUserTokenResult(correlationId, tokenResult);
131
- },
132
- async setUser(correlationId, user) {
133
- await LibraryClientUtility.$store.user.setUser(correlationId, user);
134
- }
135
- }
136
- };
137
-
138
- export default store;
1
+ import LibraryClientConstants from '@thzero/library_client/constants';
2
+
3
+ import LibraryClientUtility from '@thzero/library_client/utility/index';
4
+ import LibraryClientVueUtility from '@thzero/library_client_vue3/utility';
5
+
6
+ import Response from '@thzero/library_common/response';
7
+
8
+ const store = {
9
+ pluginPersistPaths: {
10
+ persist: [
11
+ 'settings',
12
+ 'user'
13
+ ]
14
+ },
15
+ state: () => ({
16
+ authCompleted: false,
17
+ claims: null,
18
+ isLoggedIn: false,
19
+ settings: {},
20
+ theme: 'defaultTheme',
21
+ token: null,
22
+ tokenResult: null,
23
+ user: null
24
+ }),
25
+ actions: {
26
+ async refreshUserSettings(correlationId) {
27
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
28
+ const response = await service.refreshSettings(correlationId, this.user);
29
+ this.$logger.debug('store.user', 'refreshUserSettings', 'response', response);
30
+ // setUser(correlationId, user): without the correlationId the user was
31
+ // set to undefined
32
+ if (Response.hasSucceeded(response) && response.results)
33
+ await this.setUser(correlationId, response.results);
34
+ return response;
35
+ },
36
+ async resetUser(correlationId) {
37
+ this.$patch({
38
+ claims: null,
39
+ isLoggedIn: false,
40
+ token: null,
41
+ tokenResult: null,
42
+ settings: {},
43
+ user: null
44
+ });
45
+ },
46
+ async setUser(correlationId, user) {
47
+ if (user) {
48
+ this.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, user.settings);
49
+ delete user.settings;
50
+ }
51
+ this.user = user;
52
+ },
53
+ async setUserAuthCompleted(correlationId, authCompleted) {
54
+ this.authCompleted = authCompleted;
55
+ },
56
+ async setUserClaims(correlationId, claims) {
57
+ this.claims = claims;
58
+ },
59
+ async setUserLoggedIn(correlationId, isLoggedIn) {
60
+ this.isLoggedIn = isLoggedIn;
61
+ },
62
+ async setUserSettings(correlationId, settings) {
63
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
64
+ settings = LibraryClientVueUtility.settings().mergeUser(correlationId, settings);
65
+ if (this.isLoggedIn) {
66
+ const response = await service.updateSettings(correlationId, this.user, settings);
67
+ this.$logger.debug('store.user', 'setUserSettings', 'response', response);
68
+ if (Response.hasSucceeded(response) && response.results) {
69
+ // this.settings = response.results.settings;
70
+ // delete response.results.settings;
71
+ // this.user = response.results;
72
+ // response.results = this.settings;
73
+ this.setUser(correlationId, response.results);
74
+ response.results = this.settings;
75
+ }
76
+ return response;
77
+ }
78
+ this.settings = LibraryClientVueUtility.settings().mergeUser(correlationId, settings);
79
+ return Response.success(correlationId, this.settings);
80
+ },
81
+ async setUserTheme(correlationId, theme) {
82
+ this.theme = theme;
83
+ },
84
+ async setUserTokenResult(correlationId, tokenResult) {
85
+ this.$patch({
86
+ tokenResult: tokenResult ?? null,
87
+ token: tokenResult ? tokenResult.token : null
88
+ });
89
+ }
90
+ },
91
+ getters: {
92
+ getUser (correlationId) {
93
+ return LibraryClientUtility.$store.user.user;
94
+ },
95
+ getUserTheme (correlationId) {
96
+ // theme lives on the user module, not the root store
97
+ return LibraryClientUtility.$store.user.theme;
98
+ },
99
+ getUserSettings(correlationId) {
100
+ if (LibraryClientUtility.$store.user.settings) // TODO: userRef
101
+ return LibraryClientUtility.$store.user.settings;
102
+
103
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_USER);
104
+ return service.initializeSettings();
105
+ }
106
+ },
107
+ dispatcher: {
108
+ async refreshUserSettings(correlationId) {
109
+ return await LibraryClientUtility.$store.user.refreshUserSettings(correlationId);
110
+ },
111
+ async resetUser(correlationId) {
112
+ await LibraryClientUtility.$store.user.resetUser(correlationId);
113
+ },
114
+ async setUserAuthCompleted(correlationId, authCompleted) {
115
+ await LibraryClientUtility.$store.user.setUserAuthCompleted(correlationId, authCompleted);
116
+ },
117
+ async setUserClaims(correlationId, claims) {
118
+ await LibraryClientUtility.$store.user.setUserClaims(correlationId, claims);
119
+ },
120
+ async setUserLoggedIn(correlationId, isLoggedIn) {
121
+ await LibraryClientUtility.$store.user.setUserLoggedIn(correlationId, isLoggedIn);
122
+ },
123
+ async setUserSettings(correlationId, settings) {
124
+ return await LibraryClientUtility.$store.user.setUserSettings(correlationId, settings);
125
+ },
126
+ async setUserTheme(correlationId, theme) {
127
+ await LibraryClientUtility.$store.user.setUserTheme(correlationId, theme);
128
+ },
129
+ async setUserTokenResult(correlationId, tokenResult) {
130
+ await LibraryClientUtility.$store.user.setUserTokenResult(correlationId, tokenResult);
131
+ },
132
+ async setUser(correlationId, user) {
133
+ await LibraryClientUtility.$store.user.setUser(correlationId, user);
134
+ }
135
+ }
136
+ };
137
+
138
+ export default store;