bt-core-app 1.2.2 → 1.2.4

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.
@@ -24,7 +24,6 @@ export interface BaseAuthCredentials {
24
24
  userID?: string;
25
25
  userPermissions?: string[];
26
26
  }
27
- export type GetAuthUrl = (redirectPath?: string, state?: string) => string;
28
27
  export interface CreateAuthOptions {
29
28
  defaultTimeZone?: string;
30
29
  demo?: BTDemo;
@@ -33,7 +32,7 @@ export interface CreateAuthOptions {
33
32
  /**retrieve the auth item */
34
33
  getAuthItem: (navName?: string | AuthItem) => AuthItem | null;
35
34
  /**retrieve the url to navigate to for the OAuth 2.0 process */
36
- getAuthUrl: GetAuthUrl;
35
+ getAuthQuery: (redirectPath?: string, state?: string) => string;
37
36
  /**sets current credentials on top of default function*/
38
37
  setCredentials?: (state: RemovableRef<any>, payload: any) => void;
39
38
  /**suboptions */
@@ -1,7 +1,21 @@
1
1
  export type Environment = 'production' | 'staging' | 'development';
2
+ export interface CreateUrlOptions {
3
+ production: UrlSet;
4
+ staging: UrlSet;
5
+ development: UrlSet;
6
+ }
7
+ export interface UrlSet {
8
+ auth?: string;
9
+ data?: string;
10
+ localDbName?: string;
11
+ other?: any;
12
+ }
13
+ export declare function useDbName(): string;
14
+ export declare function useAuthUrl(): string;
2
15
  /**
3
- * ms: BASE_AUTH_URL, BASE_DATA_URL, WEB_APP_URL, Microservice, LOCAL_DB_NAME
16
+ *
4
17
  * @param microservice
5
18
  * @returns
6
19
  */
7
- export declare function useUrl(microservice?: string): string | undefined;
20
+ export declare function useDataUrl(microservice?: string): string;
21
+ export declare function createUrl(options: CreateUrlOptions): void;
package/dist/core.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { RemovableRef } from '@vueuse/core';
2
+ import { CreateUrlOptions } from './composables/urls';
2
3
  import { NavigationItem } from './composables/navigation';
3
4
  import { BaseCosmeticTheme, UseCosmeticsOptions } from './composables/cosmetics';
4
- import { GetAuthUrl, AuthSubscription } from './composables/auth';
5
+ import { AuthSubscription } from './composables/auth';
5
6
  import { App } from 'vue';
6
7
 
7
8
  export interface CoreApp {
@@ -9,10 +10,12 @@ export interface CoreApp {
9
10
  }
10
11
  export interface CreateCoreOptions extends UseCosmeticsOptions<BaseCosmeticTheme> {
11
12
  defaultCacheExpiryHours?: number;
13
+ getAuthQuery: (redirectPath?: string, state?: string) => string;
12
14
  navItems?: NavigationItem[];
13
- getAuthUrl: GetAuthUrl;
14
15
  presets: any;
15
16
  setCredentials?: (state: RemovableRef<any>, payload: any) => void;
17
+ /**suboptions */
16
18
  subscriptionOptions?: AuthSubscription[];
19
+ urls: CreateUrlOptions;
17
20
  }
18
21
  export declare function createCore(options: CreateCoreOptions): CoreApp;
package/dist/index.d.ts CHANGED
@@ -36,7 +36,7 @@ export type { BTStoreDefinition, BTStore, StoreMode, StorageMode, LocalMeta, Loc
36
36
  export { createStoreBuilder, createStoreDefinition, useStore, useStoreDefinition, createWholeLastUpdateStoreDefinition, createSessionStoreDefinition } from './composables/stores';
37
37
  export type { UseTrackerOptions } from './composables/track';
38
38
  export { useTracker } from './composables/track';
39
- export { useUrl } from './composables/urls';
39
+ export { createUrl, useAuthUrl, useDbName, useDataUrl } from './composables/urls';
40
40
  export * from './types';
41
41
  export type { CoreApp, CreateCoreOptions } from './core';
42
42
  export { createCore } from './core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-core-app",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
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": {
@@ -1,9 +1,10 @@
1
- import { isLengthyArray } from '../composables/helpers';
1
+ import { isLengthyArray } from '../composables/helpers'
2
2
  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
6
  import { toValue } from 'vue'
7
+ import { useAuthUrl } from './urls'
7
8
 
8
9
  export interface AuthItem {
9
10
  children?: AuthItem[]
@@ -33,7 +34,7 @@ export interface BaseAuthCredentials {
33
34
 
34
35
  let defaultTimeZone = 'Australia/Melbourne'
35
36
 
36
- export type GetAuthUrl = (redirectPath?: string, state?: string) => string
37
+ // export type GetAuthUrl = (redirectPath?: string, state?: string) => string
37
38
 
38
39
  export interface CreateAuthOptions {
39
40
  defaultTimeZone?: string,
@@ -43,7 +44,7 @@ export interface CreateAuthOptions {
43
44
  /**retrieve the auth item */
44
45
  getAuthItem: (navName?: string | AuthItem) => AuthItem | null
45
46
  /**retrieve the url to navigate to for the OAuth 2.0 process */
46
- getAuthUrl: GetAuthUrl
47
+ getAuthQuery: (redirectPath?: string, state?: string) => string
47
48
  /**sets current credentials on top of default function*/
48
49
  setCredentials?: (state: RemovableRef<any>, payload: any) => void
49
50
  /**suboptions */
@@ -222,7 +223,8 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
222
223
  }
223
224
 
224
225
  function getAuthUrl(redirectPath?: string) {
225
- return options.getAuthUrl(redirectPath, authState.value)
226
+ return `${useAuthUrl()}?${options.getAuthQuery(redirectPath, authState.value)}`
227
+ //return options.getAuthUrl(redirectPath, authState.value)
226
228
  }
227
229
 
228
230
  /**undefined or unfound is worth 0 */
@@ -1,14 +1,14 @@
1
1
  import localforage from 'localforage';
2
- import { useUrl } from '../composables/urls';
2
+ import { useDbName } from '../composables/urls';
3
3
 
4
4
  let localDb: LocalForage | null = null;
5
5
 
6
6
  localforage.config({
7
- name: useUrl(`Db_${import.meta.env.MODE}`)
7
+ name: useDbName()
8
8
  })
9
9
 
10
10
  export function useLocalDb(): LocalForage {
11
- const dbName = `Db_${useUrl('LOCAL_DB_NAME')}`
11
+ const dbName = useDbName()
12
12
  if (localDb == null || localDb.config.name != dbName) {
13
13
  localDb = localforage.createInstance({ name: dbName })
14
14
  }
@@ -1,5 +1,5 @@
1
1
  //nav item needs to have a 'ignore Suspension' prop
2
- import { useUrl } from '../composables/urls'
2
+ import { useDataUrl } from '../composables/urls'
3
3
  import { appendUrl, deepSelect } from '../composables/helpers'
4
4
  import { ref, type Ref } from 'vue'
5
5
  import { type AuthItem } from './auth'
@@ -141,7 +141,7 @@ export function createNavigation(options: UseNavigationOptions): BTNavigation {
141
141
  const navItem = findItem(navName)
142
142
  if (navItem == null) return undefined
143
143
 
144
- let vPath = useUrl(navItem.microservice ?? 'default') ?? ''
144
+ let vPath = useDataUrl(navItem.microservice ?? 'default') ?? ''
145
145
 
146
146
  if (navItem.path != null)
147
147
  vPath = appendUrl(vPath, navItem.path)
@@ -1,11 +1,61 @@
1
1
  export type Environment = 'production' | 'staging' | 'development'
2
2
 
3
+ export interface CreateUrlOptions {
4
+ production: UrlSet
5
+ staging: UrlSet
6
+ development: UrlSet
7
+ }
8
+
9
+ export interface UrlSet {
10
+ auth?: string
11
+ data?: string
12
+ localDbName?: string
13
+ other?: any
14
+ }
15
+
16
+ let current: CreateUrlOptions
17
+
18
+ export function useDbName(): string {
19
+ const env = import.meta.env.MODE as Environment
20
+
21
+ if (current == null)
22
+ return env as string
23
+
24
+ const urlSet = current[env] ?? current['development']
25
+ return urlSet.localDbName ?? env as string
26
+ }
27
+
28
+ export function useAuthUrl(): string {
29
+ const env = import.meta.env.MODE as Environment
30
+
31
+ if (current == null)
32
+ return ''
33
+
34
+ const urlSet = current[env] ?? current['development']
35
+ return urlSet.auth ?? ''
36
+ }
37
+
3
38
  /**
4
- * ms: BASE_AUTH_URL, BASE_DATA_URL, WEB_APP_URL, Microservice, LOCAL_DB_NAME
39
+ *
5
40
  * @param microservice
6
41
  * @returns
7
42
  */
8
- export function useUrl(microservice?: string) {
9
- let ms = `VITE_${microservice ?? 'BASE_DATA_URL'}`
10
- return import.meta.env[ms] as string | undefined
43
+ export function useDataUrl(microservice?: string): string {
44
+ const env = import.meta.env.MODE as Environment
45
+
46
+ if (current == null)
47
+ return ''
48
+
49
+ const urlSet = current[env] ?? current['development']
50
+
51
+ if (microservice == null)
52
+ return urlSet.data ?? ''
53
+
54
+ let other = urlSet.other[microservice]
55
+
56
+ return other ?? urlSet.data ?? ''
57
+ }
58
+
59
+ export function createUrl(options: CreateUrlOptions) {
60
+ current = options
11
61
  }
package/src/core.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { App } from 'vue'
2
2
  import { createApi } from './composables/api'
3
- import { createAuth, type GetAuthUrl, type AuthSubscription } from './composables/auth'
3
+ import { createAuth, type AuthSubscription } from './composables/auth'
4
4
  import { BaseCosmeticTheme, createCosmetics, UseCosmeticsOptions } from './composables/cosmetics'
5
5
  import { createDates } from './composables/dates'
6
6
  import { createDemo } from './composables/demo'
@@ -9,6 +9,7 @@ import { createNavigation, type NavigationItem } from './composables/navigation'
9
9
  import { createPresets } from './composables/presets'
10
10
  import { createPWA } from './composables/pwa'
11
11
  import { createStoreBuilder } from './composables/stores'
12
+ import { CreateUrlOptions, createUrl } from './composables/urls'
12
13
  import { RemovableRef } from '@vueuse/core'
13
14
 
14
15
 
@@ -36,12 +37,13 @@ export interface CoreApp {
36
37
 
37
38
  export interface CreateCoreOptions extends UseCosmeticsOptions<BaseCosmeticTheme> {
38
39
  defaultCacheExpiryHours?: number
40
+ getAuthQuery: (redirectPath?: string, state?: string) => string
39
41
  navItems?: NavigationItem[]
40
-
41
- getAuthUrl: GetAuthUrl
42
42
  presets: any
43
43
  setCredentials?: (state: RemovableRef<any>, payload: any) => void
44
+ /**suboptions */
44
45
  subscriptionOptions?: AuthSubscription[]
46
+ urls: CreateUrlOptions
45
47
  }
46
48
 
47
49
  export function createCore(options: CreateCoreOptions): CoreApp {
@@ -83,7 +85,7 @@ export function createCore(options: CreateCoreOptions): CoreApp {
83
85
  const auth = createAuth({
84
86
  demo: demo,
85
87
  getAuthItem: navigation.findItem,
86
- getAuthUrl: options.getAuthUrl,
88
+ getAuthQuery: options.getAuthQuery,
87
89
  setCredentials: options.setCredentials,
88
90
  subscriptionOptions: options.subscriptionOptions
89
91
  })
@@ -109,17 +111,7 @@ export function createCore(options: CreateCoreOptions): CoreApp {
109
111
  auth
110
112
  })
111
113
 
112
- // //provide
113
- // app.provide('bt-api', api)
114
- // app.provide('bt-auth', auth)
115
- // // app.provide('bt-cosmetics', cosmetics)
116
- // app.provide('bt-dates', dates)
117
- // app.provide('bt-demo', demo)
118
- // app.provide('bt-filters', filters)
119
- // app.provide('bt-navigation', navigation)
120
- // app.provide('bt-presets', presets)
121
- // app.provide('bt-pwa', pwa)
122
- // app.provide('bt-store', storeBuilder)
114
+ createUrl(options.urls)
123
115
  }
124
116
  }
125
117
  }
package/src/index.ts CHANGED
@@ -36,7 +36,7 @@ export type { BTStoreDefinition, BTStore, StoreMode, StorageMode, LocalMeta, Loc
36
36
  export { createStoreBuilder, createStoreDefinition, useStore, useStoreDefinition, createWholeLastUpdateStoreDefinition, createSessionStoreDefinition } from './composables/stores'
37
37
  export type { UseTrackerOptions } from './composables/track'
38
38
  export { useTracker } from './composables/track'
39
- export { useUrl } from './composables/urls'
39
+ export { createUrl, useAuthUrl, useDbName, useDataUrl } from './composables/urls'
40
40
  // export { useApi, useAuth, useDates, useDemo, useFilters, useNavigation, usePresets, usePWA, useStore } from './useApi'
41
41
  export * from './types'
42
42
  export type { CoreApp, CreateCoreOptions } from './core'
@@ -46,4 +46,4 @@ export { createCore } from './core'
46
46
  // import BTBtn from './components/BT-Btn.vue'
47
47
  // import BTCol from './components/BT-Col.vue'
48
48
 
49
- // export { BTBtn, BTCol }
49
+ // export { BTBtn, BTCol }
package/test/auth.test.ts CHANGED
@@ -43,7 +43,7 @@ describe('default auth', () => {
43
43
  const auth = createAuth({
44
44
  defaultTimeZone: 'Aus',
45
45
  getAuthItem: () => { return {}},
46
- getAuthUrl: () => ''
46
+ getAuthQuery: () => ''
47
47
  })
48
48
 
49
49
  test('creates successfully', () => {
@@ -61,7 +61,6 @@ describe('default auth', () => {
61
61
  expect(a.authState).toEqual(auth.authState)
62
62
  })
63
63
 
64
-
65
64
  test('login', () => {
66
65
  auth.login()
67
66
  })
@@ -7,7 +7,7 @@ describe('foraging', () => {
7
7
 
8
8
  test('local db exists', () => {
9
9
  expect(db).not.toBeNull()
10
- expect(db._config.name).toEqual('Db_undefined')
10
+ expect(db._config.name).toEqual('test')
11
11
  })
12
12
 
13
13
  })
@@ -1,5 +1,5 @@
1
1
  import { setActivePinia, createPinia } from 'pinia'
2
- import { createSessionStore, createWholeLastUpdateStore } from '../src/composables/stores'
2
+ import { createSessionStoreDefinition, createWholeLastUpdateStoreDefinition } from '../src/composables/stores'
3
3
  import { createApi } from '../src/composables/api'
4
4
  import { describe, test, expect, beforeEach, afterAll, afterEach, beforeAll } from 'vitest'
5
5
  import { setupServer } from 'msw/node'
@@ -50,7 +50,7 @@ describe('use session store with no api no caching', () => {
50
50
  app.use(pinia)
51
51
  setActivePinia(pinia)
52
52
 
53
- const store = createSessionStore({
53
+ const store = createSessionStoreDefinition({
54
54
  storageMode: 'session',
55
55
  storeName: 'sesh'
56
56
  })()
@@ -79,7 +79,7 @@ describe('use session store with api no caching', () => {
79
79
 
80
80
  setActivePinia(pinia)
81
81
 
82
- const store = createSessionStore({
82
+ const store = createSessionStoreDefinition({
83
83
  storageMode: 'session',
84
84
  api: api,
85
85
  storeName: 'test'
@@ -0,0 +1,42 @@
1
+ import { describe, test, expect } from 'vitest'
2
+ import { createUrl, useDbName, useAuthUrl, useDataUrl } from '../src/composables/urls'
3
+
4
+ describe('default urls', () => {
5
+ const url = createUrl({
6
+ production: {
7
+ auth: 'pauth',
8
+ data: 'pdata',
9
+ localDbName: 'pdb',
10
+ other: {
11
+ ordering: 'pordering',
12
+ stock: 'pstock'
13
+ }
14
+ },
15
+ staging: {
16
+ auth: 'sauth',
17
+ data: 'sdata',
18
+ localDbName: 'sdb',
19
+ other: {
20
+ ordering: 'sordering',
21
+ stock: 'sstock'
22
+ }
23
+ },
24
+ development: {
25
+ auth: 'dauth',
26
+ data: 'ddata',
27
+ localDbName: 'ddb',
28
+ other: {
29
+ ordering: 'dordering',
30
+ stock: 'dstock'
31
+ }
32
+ }
33
+ })
34
+
35
+ test('use prod db name', () => {
36
+ const d = useDbName()
37
+ expect(useDbName()).toEqual('ddb')
38
+ expect(useAuthUrl()).toEqual('dauth')
39
+ expect(useDataUrl()).toEqual('ddata')
40
+ expect(useDataUrl('stock')).toEqual('dstock')
41
+ })
42
+ })