bt-core-app 1.3.4 → 1.3.5

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,3 +1,4 @@
1
+ import { ComputedRef } from 'vue';
1
2
  import { BTDemo } from '../composables/demo';
2
3
  import { RemovableRef } from '@vueuse/core';
3
4
 
@@ -52,15 +53,17 @@ export interface BTAuth {
52
53
  canEditPermit: (permit: string) => boolean;
53
54
  canView: (navName?: string) => boolean;
54
55
  canViewPermit: (permit: string) => boolean;
55
- credentials: any;
56
+ credentials: RemovableRef<any>;
56
57
  doShow: (subcodes?: string[], permissions?: string[], action?: 'view' | 'edit') => boolean;
57
58
  doShowByNav: (navName?: string | AuthItem, includeChildren?: boolean) => boolean;
58
59
  getAuthorizeUrl: (redirectPath?: string) => string;
59
60
  getTimeZone: () => string;
60
61
  getToken: (code?: string, state?: string) => Promise<void>;
62
+ isLoggedIn: ComputedRef<boolean>;
61
63
  login: (redirectPath?: string) => void;
62
64
  logout: (navNameRedirect?: string) => void;
63
65
  setAuth: (jwtToken?: string) => void;
66
+ timeZone: ComputedRef<string>;
64
67
  tryLogin: () => boolean | undefined;
65
68
  }
66
69
  export declare function useAuth(): BTAuth;
@@ -1,3 +1,5 @@
1
+ import { RemovableRef } from '@vueuse/core';
2
+
1
3
  interface CosmeticData {
2
4
  dark?: BaseCosmeticTheme;
3
5
  drawer?: boolean;
@@ -22,7 +24,7 @@ export interface UseCosmeticsOptions<T extends BaseCosmeticTheme> {
22
24
  defaultTheme?: string;
23
25
  }
24
26
  export interface BTCosmetics {
25
- state: CosmeticData;
27
+ state: RemovableRef<CosmeticData>;
26
28
  initiate: () => void;
27
29
  resetCosmetics: (toDefault: boolean) => void;
28
30
  setTemporaryColor: (color: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-core-app",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "Core app tools for some basic features like navigation, authentication, server apis, and cosmetics",
5
5
  "homepage": "https://github.com/BlitzItTech/bt-core",
6
6
  "bugs": {
@@ -25,7 +25,7 @@
25
25
  inline
26
26
  :is-24="false"
27
27
  :time-picker-inline="useTime"
28
- :timezone="auth.credentials.timeZone.value"
28
+ :timezone="auth.timeZone.value"
29
29
  utc
30
30
  v-bind="$attrs"
31
31
  v-model="value" />
@@ -16,7 +16,7 @@
16
16
  :model-auto="range"
17
17
  :range="range"
18
18
  :time-picker-inline="!range && useTime"
19
- :timezone="credentials.timeZone"
19
+ :timezone="timeZone"
20
20
  utc
21
21
  v-bind="$attrs"
22
22
  v-model="date" />
@@ -50,7 +50,7 @@
50
50
 
51
51
  const emit = defineEmits(['confirm', 'cancel'])
52
52
  const date = ref()
53
- const { credentials } = useAuth()
53
+ const { timeZone } = useAuth()
54
54
 
55
55
  const canAccept = computed(() => {
56
56
  return !props.required || date.value
@@ -188,13 +188,13 @@ export function createApi(options?: UseApiOptions): BTApi {
188
188
 
189
189
  function defaultBuildHeaders(path: PathOptions): HeadersInit {
190
190
  let fetchOptions:any = { ...path.headers }
191
- const auth = options?.auth?.credentials
191
+ //const auth = options?.auth?.credentials
192
192
 
193
193
  if (path.proxyID)
194
194
  fetchOptions.ManagedCompanyAccountID ??= path.proxyID
195
195
 
196
- if (options?.useBearerToken != false && auth?.isLoggedIn == true)
197
- fetchOptions.authorization ??= `bearer ${auth.token}`
196
+ if (options?.useBearerToken != false && options?.auth?.isLoggedIn.value == true)
197
+ fetchOptions.authorization ??= `bearer ${options?.auth?.credentials.value.token}`
198
198
 
199
199
  fetchOptions['Content-Type'] ??= (path.contentType ?? options?.defaultContentType ?? 'application/json')
200
200
 
@@ -3,7 +3,7 @@ import { DateTime } from 'luxon'
3
3
  import { type RemovableRef, useStorage } from '@vueuse/core'
4
4
  import { type BTDemo } from '../composables/demo'
5
5
  import { useRouter } from 'vue-router'
6
- import { toValue } from 'vue'
6
+ import { computed, type ComputedRef, toValue } from 'vue'
7
7
  import { useAuthUrl } from './urls'
8
8
  import { useApi } from './api'
9
9
 
@@ -66,15 +66,17 @@ export interface BTAuth {
66
66
  canEditPermit: (permit: string) => boolean
67
67
  canView: (navName?: string) => boolean
68
68
  canViewPermit: (permit: string) => boolean
69
- credentials: any
69
+ credentials: RemovableRef<any>
70
70
  doShow: (subcodes?: string[], permissions?: string[], action?: 'view' | 'edit') => boolean
71
71
  doShowByNav: (navName?: string | AuthItem, includeChildren?: boolean) => boolean
72
72
  getAuthorizeUrl: (redirectPath?: string) => string
73
73
  getTimeZone: () => string
74
74
  getToken: (code?: string, state?: string) => Promise<void>
75
+ isLoggedIn: ComputedRef<boolean>
75
76
  login: (redirectPath?: string) => void
76
77
  logout: (navNameRedirect?: string) => void
77
78
  setAuth: (jwtToken?: string) => void
79
+ timeZone: ComputedRef<string>
78
80
  tryLogin: () => boolean | undefined
79
81
  }
80
82
 
@@ -430,15 +432,19 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
430
432
  canEditPermit,
431
433
  canView,
432
434
  canViewPermit,
433
- credentials: state.value,
435
+ credentials: state,
434
436
  doShow,
435
437
  doShowByNav,
436
438
  getAuthorizeUrl,
437
439
  getTimeZone,
438
440
  getToken,
441
+ isLoggedIn: computed(() => state.value.isLoggedIn === true),
439
442
  login,
440
443
  logout,
441
444
  setAuth,
445
+ timeZone: computed(() => {
446
+ return state.value.timeZone ?? options.defaultTimeZone ?? defaultTimeZone
447
+ }),
442
448
  tryLogin
443
449
  }
444
450
 
@@ -48,7 +48,7 @@ export interface UseCosmeticsOptions<T extends BaseCosmeticTheme> {
48
48
  }
49
49
 
50
50
  export interface BTCosmetics {
51
- state: CosmeticData
51
+ state: RemovableRef<CosmeticData>
52
52
  initiate: () => void
53
53
  resetCosmetics: (toDefault: boolean) => void
54
54
  setTemporaryColor: (color: string) => void
@@ -153,7 +153,7 @@ export function useCosmetics(): BTCosmetics {
153
153
  }
154
154
 
155
155
  return {
156
- state: state.value,
156
+ state: state,
157
157
  initiate: loadCosmetics,
158
158
  resetCosmetics,
159
159
  setTemporaryColor,
@@ -193,14 +193,14 @@ export function createSessionStoreDefinition(options: UseSessionStoreOptions): B
193
193
  // const authData = useAuthData()
194
194
 
195
195
  function getKey(dOptions: PathOptions) {
196
- return `${options.storeName}_${options.auth?.credentials.userID ?? 'no-user-id'}_${dOptions.id ?? dOptions.data?.id ?? 'no-item-id'}`
196
+ return `${options.storeName}_${options.auth?.credentials.value.userID ?? 'no-user-id'}_${dOptions.id ?? dOptions.data?.id ?? 'no-item-id'}`
197
197
  }
198
198
 
199
199
  async function getAll<T extends BaseModel>(dOptions: PathOptions): Promise<StoreGetAllReturn<T>> {
200
200
  dOptions.additionalUrl ??= '/getAll'
201
201
 
202
202
  const path = buildPath(dOptions)
203
- const key = `${options.storeName}_${options.auth?.credentials.userID ?? 'no-user-id'}_${path}`
203
+ const key = `${options.storeName}_${options.auth?.credentials.value.userID ?? 'no-user-id'}_${path}`
204
204
  const refresh = dOptions.refresh
205
205
 
206
206
  if (!refresh && searchMemory.value[key] !== undefined)
@@ -508,7 +508,7 @@ export function createWholeLastUpdateStoreDefinition(options: UseWholeLastUpdate
508
508
  const cacheLocally = options.storageMode == 'local-cache'
509
509
 
510
510
  function getKey() {
511
- return `${options.storeName}_${options.auth?.credentials.userID ?? 'no-user-id'}`
511
+ return `${options.storeName}_${options.auth?.credentials.value.userID ?? 'no-user-id'}`
512
512
  }
513
513
 
514
514
  async function trySaveToLocalCache() {
package/test/auth.test.ts CHANGED
@@ -47,7 +47,7 @@ describe('default auth', () => {
47
47
 
48
48
  test('creates successfully', () => {
49
49
  const state = auth.authState
50
- const creds = auth.credentials
50
+ const creds = auth.credentials.value
51
51
 
52
52
  expect(state).not.toBeNull()
53
53
  expect(auth.credentials).not.toBeNull()