bt-core-app 2.2.45 → 2.2.46

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,151 +1,148 @@
1
- import { isLengthyArray as B, appendUrl as w, isNullOrEmpty as v, jwtDecrypt as J } from "./helpers.mjs";
1
+ import { isLengthyArray as q, appendUrl as S, isNullOrEmpty as v, jwtDecrypt as B } from "./helpers.mjs";
2
2
  import m from "../bt-core/core/node_modules/luxon/src/datetime.mjs";
3
3
  import "../bt-core/core/node_modules/luxon/src/duration.mjs";
4
- import { useStorage as K } from "@vueuse/core";
5
- import { ref as j, computed as L, toValue as o } from "vue";
6
- import { useAuthUrl as S } from "./urls.mjs";
7
- import { useApi as C } from "./api.mjs";
8
- let I = "Australia/Melbourne", O;
9
- const R = "auth-credentials-state";
10
- function ue() {
11
- return O;
4
+ import { useStorage as J } from "@vueuse/core";
5
+ import { ref as K, computed as L, toValue as o } from "vue";
6
+ import { useAuthUrl as k } from "./urls.mjs";
7
+ import { useApi as R } from "./api.mjs";
8
+ let b = "Australia/Melbourne", I;
9
+ const C = "auth-credentials-state";
10
+ function ne() {
11
+ return I;
12
12
  }
13
- function ie(n) {
14
- const c = n.expiryTokenFormat ?? "d/MM/yyyy h:mm:ss a", D = n.tokenRefreshMinuteWindow ?? 10800;
15
- let h = j(localStorage.getItem(R) ?? "");
16
- h.value.length == 0 && x();
17
- function x() {
18
- h.value = Math.random().toString(36).substring(4, 19) + Math.random().toString(12).substring(1, 11), localStorage.setItem(R, h.value);
13
+ function ue(u) {
14
+ const c = u.expiryTokenFormat ?? "d/MM/yyyy h:mm:ss a", D = u.tokenRefreshMinuteWindow ?? 10800;
15
+ let h = K(localStorage.getItem(C) ?? "");
16
+ h.value.length == 0 && O();
17
+ function O() {
18
+ h.value = Math.random().toString(36).substring(4, 19) + Math.random().toString(12).substring(1, 11), localStorage.setItem(C, h.value);
19
19
  }
20
- const i = K("auth-credentials", {});
21
- n.menu != null && (n.menu.currentView.value = i.value.subscriptionCode);
22
- function F(e) {
23
- if (e == null)
24
- return !0;
25
- var r = n.getAuthItem != null ? n.getAuthItem(e) : null;
20
+ const i = J("auth-credentials", {});
21
+ u.menu != null && (u.menu.currentView.value = i.value.subscriptionCode);
22
+ function F(r) {
26
23
  if (r == null)
24
+ return !0;
25
+ var e = u.getAuthItem != null ? u.getAuthItem(r) : null;
26
+ if (e == null)
27
27
  return !1;
28
- if (r.requiresAuth === !1)
28
+ if (e.requiresAuth === !1)
29
29
  return !0;
30
30
  const t = o(i);
31
- if (t.isSuspended && r.ignoreSuspension !== !0)
31
+ if (t.isSuspended && e.ignoreSuspension !== !0)
32
32
  return !1;
33
33
  if (t.isGlobalAdmin)
34
34
  return !0;
35
- if (r.permissions != null && r.permissions.length > 0) {
36
- if (Array.isArray(r.permissions[0])) {
37
- if (r.permissions.every((s) => s.some((a) => !d(a))))
35
+ if (e.permissions != null && e.permissions.length > 0) {
36
+ if (Array.isArray(e.permissions[0])) {
37
+ if (e.permissions.every((l) => l.some((a) => !d(a))))
38
38
  return !1;
39
39
  } else
40
- for (var u = 0; u < r.permissions.length; u++)
41
- if (!d(r.permissions[u]))
40
+ for (var n = 0; n < e.permissions.length; n++)
41
+ if (!d(e.permissions[n]))
42
42
  return !1;
43
43
  }
44
44
  return !0;
45
45
  }
46
- function d(e) {
47
- const r = o(i);
48
- if (r.userPermissions != null)
49
- for (var t = 0; t < r.userPermissions.length; t++) {
50
- var u = r.userPermissions[t].split(".");
51
- if (r.userPermissions[t] == "everything.edit" || e == u[0] && u.length > 1 && u[1] == "edit")
46
+ function d(r) {
47
+ const e = o(i);
48
+ if (e.userPermissions != null)
49
+ for (var t = 0; t < e.userPermissions.length; t++) {
50
+ var n = e.userPermissions[t].split(".");
51
+ if (e.userPermissions[t] == "everything.edit" || r == n[0] && n.length > 1 && n[1] == "edit")
52
52
  return !0;
53
53
  }
54
54
  return !1;
55
55
  }
56
- function _(e) {
57
- if (e == null)
58
- return !0;
59
- var r = n.getAuthItem != null ? n.getAuthItem(e) : null;
56
+ function _(r) {
60
57
  if (r == null)
58
+ return !0;
59
+ var e = u.getAuthItem != null ? u.getAuthItem(r) : null;
60
+ if (e == null)
61
61
  return !1;
62
- if (r.requiresAuth === !1)
62
+ if (e.requiresAuth === !1)
63
63
  return !0;
64
64
  const t = o(i);
65
- if (t.isSuspended && r.ignoreSuspension !== !0)
65
+ if (t.isSuspended && e.ignoreSuspension !== !0)
66
66
  return !1;
67
67
  if (t.isGlobalAdmin)
68
68
  return !0;
69
- if (r.permissions != null && r.permissions.length > 0) {
70
- if (Array.isArray(r.permissions[0])) {
71
- if (r.permissions.every((s) => s.some((a) => !g(a))))
69
+ if (e.permissions != null && e.permissions.length > 0) {
70
+ if (Array.isArray(e.permissions[0])) {
71
+ if (e.permissions.every((l) => l.some((a) => !g(a))))
72
72
  return !1;
73
73
  } else
74
- for (var u = 0; u < r.permissions.length; u++)
75
- if (!g(r.permissions[u]))
74
+ for (var n = 0; n < e.permissions.length; n++)
75
+ if (!g(e.permissions[n]))
76
76
  return !1;
77
77
  }
78
78
  return !0;
79
79
  }
80
- function g(e) {
81
- const r = o(i);
82
- if (r.userPermissions != null)
83
- for (var t = 0; t < r.userPermissions.length; t++) {
84
- var u = r.userPermissions[t].split(".");
85
- if (e == u[0] || e == "everything" || r.userPermissions[t] == "everything.view" || r.userPermissions[t] == "everything.edit")
80
+ function g(r) {
81
+ const e = o(i);
82
+ if (e.userPermissions != null)
83
+ for (var t = 0; t < e.userPermissions.length; t++) {
84
+ var n = e.userPermissions[t].split(".");
85
+ if (r == n[0] || r == "everything" || e.userPermissions[t] == "everything.view" || e.userPermissions[t] == "everything.edit")
86
86
  return !0;
87
87
  }
88
88
  return !1;
89
89
  }
90
- function E(e, r, t) {
91
- let u = !0, s = !0;
92
- return e != null && e.length > 0 && (e.some((l) => V(l)) || (s = !1)), s ? o(i).isGlobalAdmin ? !0 : (r != null && r.length > 0 && (Array.isArray(r[0]) ? t == "edit" ? r.some((l) => l.every((f) => d(f))) || (u = !1) : r.some((l) => l.every((f) => g(f))) || (u = !1) : r.forEach((l) => {
93
- t == "edit" ? d(l) || (u = !1) : g(l) || (u = !1);
94
- })), u) : !1;
90
+ function x(r, e, t) {
91
+ let n = !0, l = !0;
92
+ return r != null && r.length > 0 && (r.some((s) => V(s)) || (l = !1)), l ? o(i).isGlobalAdmin ? !0 : (e != null && e.length > 0 && (Array.isArray(e[0]) ? t == "edit" ? e.some((s) => s.every((f) => d(f))) || (n = !1) : e.some((s) => s.every((f) => g(f))) || (n = !1) : e.forEach((s) => {
93
+ t == "edit" ? d(s) || (n = !1) : g(s) || (n = !1);
94
+ })), n) : !1;
95
95
  }
96
- function p(e, r = !1) {
97
- var t = n.getAuthItem != null ? n.getAuthItem(e) : null;
98
- let u = !1;
96
+ function p(r, e = !1) {
97
+ var t = u.getAuthItem != null ? u.getAuthItem(r) : null;
98
+ let n = !1;
99
99
  if (t == null)
100
100
  return !1;
101
- let s = t.subscriptions ?? [], a = t.permissions ?? [], l = E(s, a, "view");
102
- return l || !r || !B(t.children) ? l : ((t == null ? void 0 : t.children) != null && t.children.forEach((f) => {
103
- p(f, !0) && (u = !0);
104
- }), u);
101
+ let l = t.subscriptions ?? [], a = t.permissions ?? [], s = x(l, a, "view");
102
+ return s || !e || !q(t.children) ? s : ((t == null ? void 0 : t.children) != null && t.children.forEach((f) => {
103
+ p(f, !0) && (n = !0);
104
+ }), n);
105
105
  }
106
- function k(e) {
107
- return n.getAuthorizeUrl ?? (n.getAuthorizeUrl = (r, t) => {
108
- const u = w(S(), `authorize?response_type=code&client_id=${n.oauthClientID}&redirect_uri=${window.location.origin}/authentication&state=${t}`);
109
- return r != null ? `${u}&redirect_path=${r}` : u;
110
- }), n.getAuthorizeUrl != null ? n.getAuthorizeUrl(e, h.value) ?? "" : "";
106
+ function w(r) {
107
+ return u.getAuthorizeUrl ?? (u.getAuthorizeUrl = (e, t) => {
108
+ const n = S(k(), `authorize?response_type=code&client_id=${u.oauthClientID}&redirect_uri=${window.location.origin}/authentication&state=${t}`);
109
+ return e != null ? `${n}&redirect_path=${e}` : n;
110
+ }), u.getAuthorizeUrl != null ? u.getAuthorizeUrl(r, h.value) ?? "" : "";
111
111
  }
112
- function P(e) {
112
+ function E(r) {
113
113
  var t;
114
- return e == null ? 0 : ((t = (n.subscriptionOptions ?? []).find((u) => u.code == e)) == null ? void 0 : t.value) ?? 0;
114
+ return r == null ? 0 : ((t = (u.subscriptionOptions ?? []).find((n) => n.code == r)) == null ? void 0 : t.value) ?? 0;
115
115
  }
116
- function V(e) {
117
- const r = o(i);
118
- if (r.subscriptionCode == null)
116
+ function V(r) {
117
+ const e = o(i);
118
+ if (e.subscriptionCode == null)
119
119
  return !1;
120
- if (r.subscriptionCode == e)
120
+ if (e.subscriptionCode == r)
121
121
  return !0;
122
- const t = P(e), u = P(r.subscriptionCode);
123
- return t <= u;
124
- }
125
- async function Z(e) {
126
- i.value = void 0, A(), n.firebase != null && await n.firebase.unregister(), e != null && n.router != null && n.router.currentRoute.value.path != e && n.router.push({ path: e });
122
+ const t = E(r), n = E(e.subscriptionCode);
123
+ return t <= n;
127
124
  }
128
- function y(e) {
129
- i.value = void 0, A(), e != null && n.router != null && n.router.currentRoute.value.path != e && n.router.push({ path: e });
125
+ function y(r) {
126
+ i.value = void 0, P(), r != null && u.router != null && u.router.currentRoute.value.path != r && u.router.push({ path: r });
130
127
  }
131
- function G(e, r) {
128
+ function Z(r, e) {
132
129
  const t = o(i);
133
- if (b() || !t.isLoggedIn) {
130
+ if (A() || !t.isLoggedIn) {
134
131
  y();
135
- let u = k(e);
136
- r != null && (u.includes("?") || (u = u + "?"), u.includes("&") && (u = u + "&"), u = u + new URLSearchParams(r).toString()), window.location.href = u;
132
+ let n = w(r);
133
+ e != null && (n.includes("?") || (n = n + "?"), n.includes("&") && (n = n + "&"), n = n + new URLSearchParams(e).toString()), window.location.href = n;
137
134
  } else
138
- !v(e) && n.router != null && n.router.push({ path: e });
135
+ !v(r) && u.router != null && u.router.push({ path: r });
139
136
  }
140
- async function M() {
141
- return n.tryRefreshToken ?? (n.tryRefreshToken = async () => {
142
- if (n.useTokenRefresh !== !0 || v(i.value.refreshToken) || v(i.value.refreshExpiresOn))
137
+ async function G() {
138
+ return u.tryRefreshToken ?? (u.tryRefreshToken = async () => {
139
+ if (u.useTokenRefresh !== !0 || v(i.value.refreshToken) || v(i.value.refreshExpiresOn))
143
140
  return;
144
- const e = m.fromFormat(i.value.refreshExpiresOn, c), r = m.fromFormat(i.value.expiresOn, c), t = m.utc().toFormat(c), u = r.plus({ minutes: 0 - D });
145
- if (!(t > e.toFormat(c)) && !(t < u.toFormat(c))) {
146
- var s = w(S(), n.tokenRefreshPath ?? "refreshtoken");
141
+ const r = m.fromFormat(i.value.refreshExpiresOn, c), e = m.fromFormat(i.value.expiresOn, c), t = m.utc().toFormat(c), n = e.plus({ minutes: 0 - D });
142
+ if (!(t > r.toFormat(c)) && !(t < n.toFormat(c))) {
143
+ var l = S(k(), u.tokenRefreshPath ?? "refreshtoken");
147
144
  try {
148
- var a = await fetch(s, {
145
+ var a = await fetch(l, {
149
146
  method: "POST",
150
147
  mode: "cors",
151
148
  cache: "no-cache",
@@ -155,107 +152,107 @@ function ie(n) {
155
152
  body: JSON.stringify({ refreshToken: i.value.refreshToken })
156
153
  });
157
154
  if (a.ok) {
158
- var l = await a.json();
159
- a != null && l.data != null && T(l.data);
155
+ var s = await a.json();
156
+ a != null && s.data != null && T(s.data);
160
157
  }
161
158
  } catch {
162
159
  }
163
160
  }
164
- }), await n.tryRefreshToken(i.value);
161
+ }), await u.tryRefreshToken(i.value);
165
162
  }
166
- async function $() {
167
- return n.testToken ?? (n.testToken = async () => {
168
- let e = i.value.token, r = !1;
169
- const t = n.getTokenTestUrl ?? (() => w(S(), "test"));
170
- return e != null && (await C().post({
171
- additionalUrl: t(e),
163
+ async function M() {
164
+ return u.testToken ?? (u.testToken = async () => {
165
+ let r = i.value.token, e = !1;
166
+ const t = u.getTokenTestUrl ?? (() => S(k(), "test"));
167
+ return r != null && (await R().post({
168
+ additionalUrl: t(r),
172
169
  data: {
173
- token: e
170
+ token: r
174
171
  }
175
- })).data === !0 && (r = !0), r ? !0 : (y(n.tokenInvalidPath), !1);
176
- }), await n.testToken();
172
+ })).data === !0 && (e = !0), e ? !0 : (y(u.tokenInvalidPath), !1);
173
+ }), await u.testToken();
177
174
  }
178
- async function z(e, r) {
179
- return n.getToken ?? (n.getToken = async () => {
180
- let t = e, u = r, s = n.oauthGrantType ?? "authorization_token", a = n.oauthClientID ?? "";
181
- if (t == null || u == null)
175
+ async function $(r, e) {
176
+ return u.getToken ?? (u.getToken = async () => {
177
+ let t = r, n = e, l = u.oauthGrantType ?? "authorization_token", a = u.oauthClientID ?? "";
178
+ if (t == null || n == null)
182
179
  throw new Error("Code and State required in OAuth token process");
183
- if (u != h.value)
180
+ if (n != h.value)
184
181
  throw new Error("state does not match");
185
- let l = "";
186
- n.getTokenUrl ?? (n.getTokenUrl = () => w(S(), "token")), l = n.getTokenUrl(t, `${window.location.origin}/authentication`, s, a);
182
+ let s = "";
183
+ u.getTokenUrl ?? (u.getTokenUrl = () => S(k(), "token")), s = u.getTokenUrl(t, `${window.location.origin}/authentication`, l, a);
187
184
  const f = {};
188
- f.grant_type = s, f.code = t, f.redirect_uri = `${window.location.origin}/authentication`, f.client_id = a;
189
- const q = await C().post({
190
- additionalUrl: l,
185
+ f.grant_type = l, f.code = t, f.redirect_uri = `${window.location.origin}/authentication`, f.client_id = a;
186
+ const N = await R().post({
187
+ additionalUrl: s,
191
188
  data: f
192
189
  });
193
- T(q.access_token);
194
- }), await n.getToken(e, r);
190
+ T(N.access_token);
191
+ }), await u.getToken(r, e);
195
192
  }
196
- function T(e) {
197
- if (e == null)
193
+ function T(r) {
194
+ if (r == null)
198
195
  return;
199
- const r = J(e);
200
- W(r, e), n.processTokenPayload != null && n.processTokenPayload(i, r);
196
+ const e = B(r);
197
+ z(e, r), u.processTokenPayload != null && u.processTokenPayload(i, e);
201
198
  }
202
- function W(e, r) {
203
- var u;
199
+ function z(r, e) {
200
+ var n;
204
201
  const t = i.value;
205
- t.expiresOn = e.ExpiresOn, t.isGlobalAdmin = e.IsGlobalAdmin == "True", t.isLoggedIn = !0, t.permissions = e.Permissions, t.subscriptionCode = e.Subscription, t.refreshExpiresOn = e.RefreshTokenExpiresOn, t.refreshToken = e.RefreshToken, (n == null ? void 0 : n.menu) != null && (n.menu.currentView.value = t.subscriptionCode), t.timeZone ?? (t.timeZone = n.defaultTimeZone ?? I), t.token = r, t.userID = e.UserLoginID, t.userPermissions = e.Permissions != null && e.Permissions.length > 0 ? ((u = e.Permissions) == null ? void 0 : u.split(",")) ?? [] : [];
202
+ t.expiresOn = r.ExpiresOn, t.isGlobalAdmin = r.IsGlobalAdmin == "True", t.isLoggedIn = !0, t.permissions = r.Permissions, t.subscriptionCode = r.Subscription, t.refreshExpiresOn = r.RefreshTokenExpiresOn, t.refreshToken = r.RefreshToken, (u == null ? void 0 : u.menu) != null && (u.menu.currentView.value = t.subscriptionCode), t.timeZone ?? (t.timeZone = u.defaultTimeZone ?? b), t.token = e, t.userID = r.UserLoginID, t.userPermissions = r.Permissions != null && r.Permissions.length > 0 ? ((n = r.Permissions) == null ? void 0 : n.split(",")) ?? [] : [];
206
203
  }
207
- function A() {
208
- var e;
209
- i.value ?? (i.value = {}), (e = i.value).timeZone ?? (e.timeZone = n.defaultTimeZone ?? I);
204
+ function P() {
205
+ var r;
206
+ i.value ?? (i.value = {}), (r = i.value).timeZone ?? (r.timeZone = u.defaultTimeZone ?? b);
210
207
  }
211
- function N(e, r) {
208
+ function W(r, e) {
212
209
  const t = o(i);
213
- if (t.isLoggedIn && b() && U()) {
210
+ if (t.isLoggedIn && A() && U()) {
214
211
  y();
215
- let u = k(e);
216
- r != null && (u.includes("?") || (u = u + "?"), u.includes("&") && (u = u + "&"), u = u + new URLSearchParams(r).toString()), window.location.href = u;
212
+ let n = w(r);
213
+ e != null && (n.includes("?") || (n = n + "?"), n.includes("&") && (n = n + "&"), n = n + new URLSearchParams(e).toString()), window.location.href = n;
217
214
  }
218
215
  return t.isLoggedIn;
219
216
  }
220
217
  function U() {
221
- if (!n.useTokenRefresh || v(i.value.refreshExpiresOn) || v(i.value.refreshToken))
218
+ if (!u.useTokenRefresh || v(i.value.refreshExpiresOn) || v(i.value.refreshToken))
222
219
  return !0;
223
- const e = m.fromFormat(i.value.refreshExpiresOn, c);
224
- return m.utc() > e;
220
+ const r = m.fromFormat(i.value.refreshExpiresOn, c);
221
+ return m.utc() > r;
225
222
  }
226
- function b() {
227
- const e = o(i);
228
- if (e == null || e.expiresOn == null)
223
+ function A() {
224
+ const r = o(i);
225
+ if (r == null || r.expiresOn == null)
229
226
  return !0;
230
- const r = m.fromFormat(e.expiresOn, c), t = m.utc();
231
- return r <= t;
227
+ const e = m.fromFormat(r.expiresOn, c), t = m.utc();
228
+ return e <= t;
232
229
  }
233
- return A(), O = {
230
+ return P(), I = {
234
231
  authState: h,
235
232
  canEdit: F,
236
233
  canEditPermit: d,
237
234
  canView: _,
238
235
  canViewPermit: g,
239
236
  credentials: i,
240
- doShow: E,
237
+ doShow: x,
241
238
  doShowByNav: p,
242
- getAuthorizeUrl: k,
243
- getToken: z,
239
+ getAuthorizeUrl: w,
240
+ getToken: $,
244
241
  isLoggedIn: L(() => i.value.isLoggedIn === !0),
245
- login: G,
242
+ login: Z,
246
243
  logout: y,
247
- logoutAsync: Z,
244
+ // logoutAsync,
248
245
  refreshTokenExpired: U,
249
- resetAuthState: x,
246
+ resetAuthState: O,
250
247
  setAuth: T,
251
- testToken: $,
252
- timeZone: L(() => i.value.timeZone ?? n.defaultTimeZone ?? I),
253
- tokenExpired: b,
254
- tryLogin: N,
255
- tryRefreshToken: M
256
- }, O;
248
+ testToken: M,
249
+ timeZone: L(() => i.value.timeZone ?? u.defaultTimeZone ?? b),
250
+ tokenExpired: A,
251
+ tryLogin: W,
252
+ tryRefreshToken: G
253
+ }, I;
257
254
  }
258
255
  export {
259
- ie as createAuth,
260
- ue as useAuth
256
+ ue as createAuth,
257
+ ne as useAuth
261
258
  };