bt-core-app 1.2.5 → 1.2.6

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.
@@ -29,12 +29,13 @@ export interface CreateAuthOptions {
29
29
  demo?: BTDemo;
30
30
  /**expiry token date format. Defaults to 'd/MM/yyyy h:mm:ss a' */
31
31
  expiryTokenFormat?: string;
32
- /**retrieve the auth item */
33
- getAuthItem: (navName?: string | AuthItem) => AuthItem | null;
34
- /**the url to start the OAuth 2.0 process */
32
+ /**OVERRIDES CORE DEFAULT. retrieve the auth item */
33
+ getAuthItem?: (navName?: string | AuthItem) => AuthItem | null;
34
+ /**OVERRIDES DEFAULT. the url to start the OAuth 2.0 process */
35
35
  getAuthorizeUrl?: (redirectPath?: string, state?: string) => string;
36
- /**use the given code and generate the url to convert to an access token */
36
+ /**OVERRIDES DEFAULT. use the given code and generate the url to convert to an access token */
37
37
  getTokenUrl?: (code: string, redirect_uri: string, grant_type: string, client_id: string) => string;
38
+ /**OVERRIDES DEFAULT. */
38
39
  getToken?: () => Promise<void>;
39
40
  oauthGrantType?: string;
40
41
  oauthClientID?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-core-app",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
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": {
@@ -41,12 +41,13 @@ export interface CreateAuthOptions {
41
41
  demo?: BTDemo,
42
42
  /**expiry token date format. Defaults to 'd/MM/yyyy h:mm:ss a' */
43
43
  expiryTokenFormat?: string
44
- /**retrieve the auth item */
45
- getAuthItem: (navName?: string | AuthItem) => AuthItem | null
46
- /**the url to start the OAuth 2.0 process */
44
+ /**OVERRIDES CORE DEFAULT. retrieve the auth item */
45
+ getAuthItem?: (navName?: string | AuthItem) => AuthItem | null
46
+ /**OVERRIDES DEFAULT. the url to start the OAuth 2.0 process */
47
47
  getAuthorizeUrl?: (redirectPath?: string, state?: string) => string
48
- /**use the given code and generate the url to convert to an access token */
48
+ /**OVERRIDES DEFAULT. use the given code and generate the url to convert to an access token */
49
49
  getTokenUrl?: (code: string, redirect_uri: string, grant_type: string, client_id: string) => string
50
+ /**OVERRIDES DEFAULT. */
50
51
  getToken?: () => Promise<void>
51
52
  oauthGrantType?: string
52
53
  oauthClientID?: string
@@ -91,7 +92,7 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
91
92
  function canEdit(navName?: string): boolean {
92
93
  if (navName == null) return true
93
94
 
94
- var navItem = options.getAuthItem(navName);
95
+ var navItem = options.getAuthItem != null ? options.getAuthItem(navName) : null;
95
96
  if (navItem == null) return false
96
97
  if (navItem.requiresAuth === false) return true
97
98
 
@@ -133,7 +134,7 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
133
134
  function canView(navName: string | undefined): boolean {
134
135
  if (navName == null) return true
135
136
 
136
- var navItem = options.getAuthItem(navName);
137
+ var navItem = options.getAuthItem != null ? options.getAuthItem(navName) : null;
137
138
  if (navItem == null) return false
138
139
  if (navItem.requiresAuth === false) return true
139
140
 
@@ -207,7 +208,7 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
207
208
  }
208
209
 
209
210
  function doShowByNav(navName?: string | AuthItem, includeChildren: boolean = false) {
210
- var navItem = options.getAuthItem(navName);
211
+ var navItem = options.getAuthItem != null ? options.getAuthItem(navName) : null;
211
212
  let doShowRes = false;
212
213
 
213
214
  if (navItem == null) return false
@@ -231,6 +232,10 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
231
232
  }
232
233
 
233
234
  function getAuthorizeUrl(redirectPath?: string) {
235
+ options.getAuthorizeUrl ??= (redirectPath?: string, state?: string) => {
236
+ return appendUrl(useAuthUrl(), `authorize?response_type=code&client_id=${options.oauthClientID}&redirect_uri=${redirectPath}&state=${state}`)
237
+ }
238
+
234
239
  if (options.getAuthorizeUrl != null)
235
240
  return options.getAuthorizeUrl(redirectPath, authState.value) ?? ''
236
241
 
package/src/core.ts CHANGED
@@ -82,6 +82,7 @@ export function createCore(options: CreateCoreOptions): CoreApp {
82
82
  createPresets(options)
83
83
 
84
84
  options.auth.demo ??= demo
85
+ options.auth.getAuthItem = navigation.findItem
85
86
 
86
87
  const auth = createAuth(options.auth)
87
88