bt-core-app 1.2.2 → 1.2.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.
- package/README.md +4 -4
- package/dist/bt-core-app.js +2923 -2906
- package/dist/composables/auth.d.ts +1 -2
- package/dist/composables/urls.d.ts +16 -2
- package/dist/core.d.ts +5 -3
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/composables/auth.ts +6 -4
- package/src/composables/forage.ts +3 -3
- package/src/composables/navigation.ts +2 -2
- package/src/composables/urls.ts +54 -4
- package/src/core.ts +7 -16
- package/src/index.ts +2 -2
- package/test/auth.test.ts +1 -2
- package/test/forage.test.ts +1 -1
- package/test/stores-session.test.ts +3 -3
- package/test/urls.test.ts +42 -0
|
@@ -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
|
-
|
|
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
|
-
*
|
|
16
|
+
*
|
|
4
17
|
* @param microservice
|
|
5
18
|
* @returns
|
|
6
19
|
*/
|
|
7
|
-
export declare function
|
|
20
|
+
export declare function useDataUrl(microservice?: string): string;
|
|
21
|
+
export declare function createUrl(options: CreateUrlOptions): void;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
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 {
|
|
5
|
+
import { AuthSubscription } from './composables/auth';
|
|
5
6
|
import { App } from 'vue';
|
|
6
7
|
|
|
7
8
|
export interface CoreApp {
|
|
8
9
|
install(app: App): void;
|
|
9
10
|
}
|
|
10
|
-
export interface CreateCoreOptions extends UseCosmeticsOptions<BaseCosmeticTheme
|
|
11
|
+
export interface CreateCoreOptions extends UseCosmeticsOptions<BaseCosmeticTheme>, CreateUrlOptions {
|
|
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[];
|
|
17
19
|
}
|
|
18
20
|
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 {
|
|
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
package/src/composables/auth.ts
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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 {
|
|
2
|
+
import { useDbName } from '../composables/urls';
|
|
3
3
|
|
|
4
4
|
let localDb: LocalForage | null = null;
|
|
5
5
|
|
|
6
6
|
localforage.config({
|
|
7
|
-
name:
|
|
7
|
+
name: useDbName()
|
|
8
8
|
})
|
|
9
9
|
|
|
10
10
|
export function useLocalDb(): LocalForage {
|
|
11
|
-
const dbName =
|
|
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 {
|
|
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 =
|
|
144
|
+
let vPath = useDataUrl(navItem.microservice ?? 'default') ?? ''
|
|
145
145
|
|
|
146
146
|
if (navItem.path != null)
|
|
147
147
|
vPath = appendUrl(vPath, navItem.path)
|
package/src/composables/urls.ts
CHANGED
|
@@ -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
|
-
*
|
|
39
|
+
*
|
|
5
40
|
* @param microservice
|
|
6
41
|
* @returns
|
|
7
42
|
*/
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
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
|
|
|
@@ -34,13 +35,13 @@ export interface CoreApp {
|
|
|
34
35
|
install(app: App) : void
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export interface CreateCoreOptions extends UseCosmeticsOptions<BaseCosmeticTheme
|
|
38
|
+
export interface CreateCoreOptions extends UseCosmeticsOptions<BaseCosmeticTheme>, CreateUrlOptions {
|
|
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[]
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -83,7 +84,7 @@ export function createCore(options: CreateCoreOptions): CoreApp {
|
|
|
83
84
|
const auth = createAuth({
|
|
84
85
|
demo: demo,
|
|
85
86
|
getAuthItem: navigation.findItem,
|
|
86
|
-
|
|
87
|
+
getAuthQuery: options.getAuthQuery,
|
|
87
88
|
setCredentials: options.setCredentials,
|
|
88
89
|
subscriptionOptions: options.subscriptionOptions
|
|
89
90
|
})
|
|
@@ -109,17 +110,7 @@ export function createCore(options: CreateCoreOptions): CoreApp {
|
|
|
109
110
|
auth
|
|
110
111
|
})
|
|
111
112
|
|
|
112
|
-
|
|
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)
|
|
113
|
+
createUrl(options)
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
116
|
}
|
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 {
|
|
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
|
-
|
|
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
|
})
|
package/test/forage.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setActivePinia, createPinia } from 'pinia'
|
|
2
|
-
import {
|
|
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 =
|
|
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 =
|
|
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
|
+
})
|