@iankibetsh/shframework 1.1.9 → 1.2.2

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,4 +1,36 @@
1
1
 
2
+ .colored-toast.swal2-icon-success {
3
+ background-color: #a5dc86 !important;
4
+ }
5
+
6
+ .colored-toast.swal2-icon-error {
7
+ background-color: #f27474 !important;
8
+ }
9
+
10
+ .colored-toast.swal2-icon-warning {
11
+ background-color: #f8bb86 !important;
12
+ }
13
+
14
+ .colored-toast.swal2-icon-info {
15
+ background-color: #3fc3ee !important;
16
+ }
17
+
18
+ .colored-toast.swal2-icon-question {
19
+ background-color: #87adbd !important;
20
+ }
21
+
22
+ .colored-toast .swal2-title {
23
+ color: white;
24
+ }
25
+
26
+ .colored-toast .swal2-close {
27
+ color: white;
28
+ }
29
+
30
+ .colored-toast .swal2-html-container {
31
+ color: white;
32
+ }
33
+
2
34
  .sh-phone{
3
35
  display: flex;
4
36
  width: 100%;
@@ -31,36 +63,19 @@
31
63
  opacity: 0.5;
32
64
  }
33
65
 
34
- .colored-toast.swal2-icon-success {
35
- background-color: #a5dc86 !important;
36
- }
37
-
38
- .colored-toast.swal2-icon-error {
39
- background-color: #f27474 !important;
40
- }
41
-
42
- .colored-toast.swal2-icon-warning {
43
- background-color: #f8bb86 !important;
44
- }
45
-
46
- .colored-toast.swal2-icon-info {
47
- background-color: #3fc3ee !important;
48
- }
49
-
50
- .colored-toast.swal2-icon-question {
51
- background-color: #87adbd !important;
66
+ .sh-selected-item{
67
+ line-height: unset!important;
52
68
  }
53
-
54
- .colored-toast .swal2-title {
55
- color: white;
69
+ .sh-suggestion-input{
70
+ padding: 0.375rem 0.75rem;
56
71
  }
57
-
58
- .colored-toast .swal2-close {
59
- color: white;
72
+ .sh-suggest{
73
+ margin-bottom: 1rem;
60
74
  }
61
-
62
- .colored-toast .swal2-html-container {
63
- color: white;
75
+ .sh-suggest-control::after{
76
+ margin-top: auto;
77
+ margin-bottom: auto;
78
+ margin-right: 0.255em;
64
79
  }
65
80
 
66
81
  :root {
@@ -84,21 +99,6 @@
84
99
  }
85
100
  }
86
101
 
87
- .sh-selected-item{
88
- line-height: unset!important;
89
- }
90
- .sh-suggestion-input{
91
- padding: 0.375rem 0.75rem;
92
- }
93
- .sh-suggest{
94
- margin-bottom: 1rem;
95
- }
96
- .sh-suggest-control::after{
97
- margin-top: auto;
98
- margin-bottom: auto;
99
- margin-right: 0.255em;
100
- }
101
-
102
102
  .sh-forgot-link, .sh-register-link{
103
103
  cursor: pointer;
104
104
  }
package/dist/library.js CHANGED
@@ -9,6 +9,7 @@ var vue = require('vue');
9
9
  var NProgress = require('nprogress');
10
10
  var Editor = require('@tinymce/tinymce-vue');
11
11
  var pinia = require('pinia');
12
+ var shRepo$1 = require('@/lib/repo/helpers/ShRepo.js');
12
13
  var vueRouter = require('vue-router');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -18,6 +19,7 @@ var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
18
19
  var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
19
20
  var NProgress__default = /*#__PURE__*/_interopDefaultLegacy(NProgress);
20
21
  var Editor__default = /*#__PURE__*/_interopDefaultLegacy(Editor);
22
+ var shRepo__default = /*#__PURE__*/_interopDefaultLegacy(shRepo$1);
21
23
 
22
24
  function setItem (key, value) {
23
25
  let toStore = value;
@@ -135,6 +137,23 @@ function getMenuCount (url) {
135
137
  });
136
138
  }
137
139
 
140
+ const signOutUser = ()=>{
141
+ const loginUrl = getShConfig('loginUrl','auth/login');
142
+ const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
143
+ console.log(loginUrl,logoutApiEndPoint);
144
+ shApis.doPost(logoutApiEndPoint).then(res=>{
145
+ ShStorage.removeItem('access_token');
146
+ ShStorage.removeItem('user');
147
+ ShStorage.removeItem('last_activity');
148
+ window.location.href = loginUrl;
149
+ }).catch(ex=>{
150
+ ShStorage.removeItem('access_token');
151
+ ShStorage.removeItem('user');
152
+ ShStorage.removeItem('last_activity');
153
+ window.location.href = loginUrl;
154
+ });
155
+ };
156
+
138
157
 
139
158
  const Toast = Swal__default["default"].mixin({
140
159
  toast: true,
@@ -151,9 +170,11 @@ const Toast = Swal__default["default"].mixin({
151
170
  toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
152
171
  }
153
172
  });
154
- function getConfig() {
173
+ function getShConfig(key = null,def = '') {
155
174
  const config = ShStorage.getItem('ShConfig');
156
- console.log(config);
175
+ if(key) {
176
+ return config[key] ?? def
177
+ }
157
178
  return config
158
179
  }
159
180
  function showToast (message, toastType, position) {
@@ -225,37 +246,32 @@ var shRepo = {
225
246
  runPlainRequest,
226
247
  getMenuCount,
227
248
  setTabCounts,
228
- getConfig,
249
+ getShConfig,
229
250
  showToast,
230
251
  runSilentRequest,
231
252
  swalHttpError,
232
253
  formatHttpCatchError,
233
254
  formatDate,
234
255
  numberFormat,
235
- formatNumber
256
+ formatNumber,
257
+ signOutUser
236
258
  };
237
259
 
238
260
  startSession();
239
261
  function logoutUser(){
240
- const loginUrl = shRepo.getConfig().loginUrl;
241
- const logoutApiEndpoint = vue.inject('logoutApiEndpoint','auth/logout');
242
- shApis.doPost(logoutApiEndpoint ?? 'auth/logout').then(res=>{
243
- ShStorage.removeItem('access_token');
244
- ShStorage.removeItem('user');
245
- ShStorage.removeItem('last_activity');
246
- if(window.shInterval){
247
- clearInterval(window.shInterval);
248
- }
249
- window.location.href = loginUrl;
250
- }).catch(ex=>{
251
- ShStorage.removeItem('access_token');
252
- ShStorage.removeItem('user');
253
- if(window.shInterval){
254
- clearInterval(window.shInterval);
255
- }
256
- window.location.href = loginUrl;
257
- });
258
- ShStorage.getItem('user');
262
+ if(!sessionRestored()){
263
+ shRepo.signOutUser();
264
+ } else {
265
+ console.log('session has been restored in another tab');
266
+ }
267
+ }
268
+ function sessionRestored(){
269
+ const timeout = ShStorage.getItem('sessionTimeout') * 60;
270
+ const last_activity = ShStorage.getItem('last_activity');
271
+ const pastSeconds = moment__default["default"]().diff(last_activity, 'seconds');
272
+ if(!ShStorage.getItem('access_token'))
273
+ return false
274
+ return pastSeconds < timeout
259
275
  }
260
276
  const checkSession = function (isCheking) {
261
277
  const timeout = ShStorage.getItem('sessionTimeout');
@@ -297,6 +313,10 @@ async function shSwalLogout (seconds = 30) {
297
313
  showLoaderOnConfirm: true,
298
314
  didOpen(popup) {
299
315
  timerInterval = setInterval(() => {
316
+ // if(sessionRestored() && ShStorage.getItem('access_token')){
317
+ // console.log('swal closed by session restored')
318
+ // Swal.close()
319
+ // }
300
320
  Swal__default["default"].getHtmlContainer().querySelector('strong')
301
321
  .textContent = (Swal__default["default"].getTimerLeft() / 1000)
302
322
  .toFixed(0);
@@ -4498,6 +4518,9 @@ const useUserStore = pinia.defineStore('user-store', {
4498
4518
  user = res.data;
4499
4519
  }
4500
4520
  ShStorage.setItem('user',user);
4521
+ user.signOut = this.signOut;
4522
+ user.logout = this.signOut;
4523
+ user.logOut = this.signOut;
4501
4524
  user.isAllowedTo = function (slug) {
4502
4525
  if(!slug){
4503
4526
  return true
@@ -4534,9 +4557,7 @@ const useUserStore = pinia.defineStore('user-store', {
4534
4557
  ShStorage.setItem('session_start',timeNow);
4535
4558
  },
4536
4559
  signOut () {
4537
- ShStorage.setItem('user',null);
4538
- ShStorage.setItem('access_token',null);
4539
- this.user = null;
4560
+ shRepo__default["default"].signOutUser();
4540
4561
  },
4541
4562
  logOut () {
4542
4563
  this.signOut();
package/dist/library.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import Axios from 'axios';
2
2
  import moment from 'moment';
3
3
  import Swal from 'sweetalert2';
4
- import { inject, openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, renderSlot, normalizeProps, guardReactiveProps, withCtx, mergeProps, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, watch, pushScopeId, popScopeId } from 'vue';
4
+ import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, renderSlot, normalizeProps, guardReactiveProps, withCtx, mergeProps, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, inject, watch, pushScopeId, popScopeId } from 'vue';
5
5
  import NProgress from 'nprogress';
6
6
  import Editor from '@tinymce/tinymce-vue';
7
7
  import { defineStore, storeToRefs } from 'pinia';
8
+ import shRepo$1 from '@/lib/repo/helpers/ShRepo.js';
8
9
  import { useRoute, useRouter } from 'vue-router';
9
10
 
10
11
  function setItem (key, value) {
@@ -123,6 +124,23 @@ function getMenuCount (url) {
123
124
  });
124
125
  }
125
126
 
127
+ const signOutUser = ()=>{
128
+ const loginUrl = getShConfig('loginUrl','auth/login');
129
+ const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
130
+ console.log(loginUrl,logoutApiEndPoint);
131
+ shApis.doPost(logoutApiEndPoint).then(res=>{
132
+ ShStorage.removeItem('access_token');
133
+ ShStorage.removeItem('user');
134
+ ShStorage.removeItem('last_activity');
135
+ window.location.href = loginUrl;
136
+ }).catch(ex=>{
137
+ ShStorage.removeItem('access_token');
138
+ ShStorage.removeItem('user');
139
+ ShStorage.removeItem('last_activity');
140
+ window.location.href = loginUrl;
141
+ });
142
+ };
143
+
126
144
 
127
145
  const Toast = Swal.mixin({
128
146
  toast: true,
@@ -139,9 +157,11 @@ const Toast = Swal.mixin({
139
157
  toast.addEventListener('mouseleave', Swal.resumeTimer);
140
158
  }
141
159
  });
142
- function getConfig() {
160
+ function getShConfig(key = null,def = '') {
143
161
  const config = ShStorage.getItem('ShConfig');
144
- console.log(config);
162
+ if(key) {
163
+ return config[key] ?? def
164
+ }
145
165
  return config
146
166
  }
147
167
  function showToast (message, toastType, position) {
@@ -213,37 +233,32 @@ var shRepo = {
213
233
  runPlainRequest,
214
234
  getMenuCount,
215
235
  setTabCounts,
216
- getConfig,
236
+ getShConfig,
217
237
  showToast,
218
238
  runSilentRequest,
219
239
  swalHttpError,
220
240
  formatHttpCatchError,
221
241
  formatDate,
222
242
  numberFormat,
223
- formatNumber
243
+ formatNumber,
244
+ signOutUser
224
245
  };
225
246
 
226
247
  startSession();
227
248
  function logoutUser(){
228
- const loginUrl = shRepo.getConfig().loginUrl;
229
- const logoutApiEndpoint = inject('logoutApiEndpoint','auth/logout');
230
- shApis.doPost(logoutApiEndpoint ?? 'auth/logout').then(res=>{
231
- ShStorage.removeItem('access_token');
232
- ShStorage.removeItem('user');
233
- ShStorage.removeItem('last_activity');
234
- if(window.shInterval){
235
- clearInterval(window.shInterval);
236
- }
237
- window.location.href = loginUrl;
238
- }).catch(ex=>{
239
- ShStorage.removeItem('access_token');
240
- ShStorage.removeItem('user');
241
- if(window.shInterval){
242
- clearInterval(window.shInterval);
243
- }
244
- window.location.href = loginUrl;
245
- });
246
- ShStorage.getItem('user');
249
+ if(!sessionRestored()){
250
+ shRepo.signOutUser();
251
+ } else {
252
+ console.log('session has been restored in another tab');
253
+ }
254
+ }
255
+ function sessionRestored(){
256
+ const timeout = ShStorage.getItem('sessionTimeout') * 60;
257
+ const last_activity = ShStorage.getItem('last_activity');
258
+ const pastSeconds = moment().diff(last_activity, 'seconds');
259
+ if(!ShStorage.getItem('access_token'))
260
+ return false
261
+ return pastSeconds < timeout
247
262
  }
248
263
  const checkSession = function (isCheking) {
249
264
  const timeout = ShStorage.getItem('sessionTimeout');
@@ -285,6 +300,10 @@ async function shSwalLogout (seconds = 30) {
285
300
  showLoaderOnConfirm: true,
286
301
  didOpen(popup) {
287
302
  timerInterval = setInterval(() => {
303
+ // if(sessionRestored() && ShStorage.getItem('access_token')){
304
+ // console.log('swal closed by session restored')
305
+ // Swal.close()
306
+ // }
288
307
  Swal.getHtmlContainer().querySelector('strong')
289
308
  .textContent = (Swal.getTimerLeft() / 1000)
290
309
  .toFixed(0);
@@ -4486,6 +4505,9 @@ const useUserStore = defineStore('user-store', {
4486
4505
  user = res.data;
4487
4506
  }
4488
4507
  ShStorage.setItem('user',user);
4508
+ user.signOut = this.signOut;
4509
+ user.logout = this.signOut;
4510
+ user.logOut = this.signOut;
4489
4511
  user.isAllowedTo = function (slug) {
4490
4512
  if(!slug){
4491
4513
  return true
@@ -4522,9 +4544,7 @@ const useUserStore = defineStore('user-store', {
4522
4544
  ShStorage.setItem('session_start',timeNow);
4523
4545
  },
4524
4546
  signOut () {
4525
- ShStorage.setItem('user',null);
4526
- ShStorage.setItem('access_token',null);
4527
- this.user = null;
4547
+ shRepo$1.signOutUser();
4528
4548
  },
4529
4549
  logOut () {
4530
4550
  this.signOut();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "1.1.9",
3
+ "version": "1.2.2",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",