@d-mok/quasar-app-extension-quasar-axe 2.1.2 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-mok/quasar-app-extension-quasar-axe",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@handsontable/vue3": "^12.1.0",
18
- "@supabase/supabase-js": "^2.24.0",
18
+ "@supabase/supabase-js": "^1.35.4",
19
19
  "@types/lodash": "^4.14.182",
20
20
  "@types/papaparse": "^5.3.2",
21
21
  "@types/webpack-env": "^1.17.0",
@@ -2,8 +2,6 @@ import {
2
2
  createClient,
3
3
  PostgrestError,
4
4
  SupabaseClient,
5
- Session,
6
- SupabaseClientOptions,
7
5
  } from '@supabase/supabase-js'
8
6
  import { qDialog } from './dialog'
9
7
 
@@ -12,69 +10,78 @@ export type {
12
10
  PostgrestSingleResponse,
13
11
  } from '@supabase/postgrest-js'
14
12
 
15
- class MySupabaseClient extends SupabaseClient {
16
- email: string = 'unauthenticated'
17
- session: Session | null = null
18
-
19
- constructor(
20
- supabaseUrl: string,
21
- supabaseKey: string,
22
- options?: SupabaseClientOptions<any>
23
- ) {
24
- super(supabaseUrl, supabaseKey, options)
25
- this.auth.onAuthStateChange((event, session) => {
26
- console.log('[SUPABASE AUTH]', event, session?.user?.email)
27
- this.session = session
28
- this.email = session?.user?.email ?? 'unauthenticated'
29
- })
13
+ declare module '@supabase/supabase-js' {
14
+ interface SupabaseClient {
15
+ signIn: () => void
16
+ accessTokenLife: () => number
17
+ waitForSignin: () => Promise<void>
18
+ email: () => string
19
+ call: <T>(fn: string, params?: object | undefined) => Promise<T[]>
20
+ callSingle: <T>(fn: string, params?: object | undefined) => Promise<T>
30
21
  }
22
+ }
31
23
 
32
- async signIn() {
33
- await this.auth.signOut()
34
- await this.auth.signInWithOAuth({
35
- provider: 'google',
36
- options: {
37
- redirectTo: window.location.href,
38
- },
39
- })
40
- }
24
+ export let supabase: SupabaseClient
25
+ let SUPABASE_URL = process.env.SUPABASE_URL
26
+ let SUPABASE_KEY = process.env.SUPABASE_KEY
41
27
 
42
- async call<T>(fn: string, params?: object | undefined): Promise<T[]> {
43
- let { data, error } = await this.rpc<string, any>(fn, params)
44
- HANDLE_ERROR(data, error)
45
- return data
28
+ if (SUPABASE_URL && SUPABASE_KEY) {
29
+ supabase = createClient(SUPABASE_URL, SUPABASE_KEY, {
30
+ autoRefreshToken: true,
31
+ })
32
+
33
+ supabase.signIn = async () => {
34
+ await supabase.auth.signOut()
35
+ await supabase.auth.signIn(
36
+ { provider: 'google' },
37
+ { redirectTo: window.location.href }
38
+ )
46
39
  }
47
40
 
48
- async callSingle<T>(fn: string, params?: object | undefined): Promise<T> {
49
- let { data, error } = await this.rpc<string, any>(fn, params).single()
50
- HANDLE_ERROR(data, error)
51
- return data as T
41
+ supabase.accessTokenLife = () => {
42
+ const session = supabase.auth.session()
43
+ if (session?.expires_at === undefined) return -999999
44
+ const expireAt = new Date(session.expires_at * 1000)
45
+ const ms = expireAt.getTime() - new Date().getTime() // ms
46
+ return Math.round(ms / 1000)
52
47
  }
53
48
 
54
- async waitForSignin(): Promise<void> {
49
+ supabase.auth.onAuthStateChange((event, session) => {
50
+ console.log('[SUPABASE AUTH]', event, session?.user?.email)
51
+ })
52
+
53
+ supabase.waitForSignin = async function (): Promise<void> {
55
54
  setInterval(() => {
56
- if (this.session === null) this.signIn()
55
+ if (supabase.auth.session() === null) supabase.signIn()
57
56
  }, 1000)
58
- waitFor(
59
- () => this.session !== null,
57
+ await waitFor(
58
+ () => supabase.auth.session() !== null,
60
59
  '[Wait for SignIn] waiting...',
61
60
  '[Wait for SignIn] DONE!'
62
61
  )
63
62
  }
64
- }
65
63
 
66
- export let supabase: MySupabaseClient
67
- let SUPABASE_URL = process.env.SUPABASE_URL
68
- let SUPABASE_KEY = process.env.SUPABASE_KEY
64
+ supabase.call = async function <T>(
65
+ fn: string,
66
+ params?: object | undefined
67
+ ): Promise<T[]> {
68
+ let { data, error } = await supabase.rpc<T>(fn, params)
69
+ HANDLE_ERROR(data, error)
70
+ return data
71
+ }
69
72
 
70
- if (SUPABASE_URL && SUPABASE_KEY) {
71
- supabase = new MySupabaseClient(SUPABASE_URL, SUPABASE_KEY, {
72
- auth: {
73
- autoRefreshToken: true,
74
- persistSession: true,
75
- detectSessionInUrl: true,
76
- },
77
- })
73
+ supabase.callSingle = async function <T>(
74
+ fn: string,
75
+ params?: object | undefined
76
+ ): Promise<T> {
77
+ let { data, error } = await supabase.rpc<T>(fn, params).single()
78
+ HANDLE_ERROR(data, error)
79
+ return data
80
+ }
81
+
82
+ supabase.email = function (): string {
83
+ return supabase.auth.user()?.email ?? 'unauthenticated'
84
+ }
78
85
  }
79
86
 
80
87
  export function HANDLE_ERROR<T>(
@@ -109,13 +116,13 @@ async function waitFor(
109
116
  doneMsg: string
110
117
  ) {
111
118
  return new Promise(resolve => {
112
- async function checker() {
119
+ function checker() {
113
120
  if (predicate()) {
114
121
  console.log(doneMsg)
115
122
  resolve(true)
116
123
  } else {
117
124
  console.log(waitingMsg)
118
- setTimeout(checker, 50)
125
+ setTimeout(() => checker(), 50)
119
126
  }
120
127
  }
121
128
  checker()
@@ -0,0 +1,123 @@
1
+ // import {
2
+ // createClient,
3
+ // PostgrestError,
4
+ // SupabaseClient,
5
+ // Session,
6
+ // SupabaseClientOptions,
7
+ // } from '@supabase/supabase-js'
8
+ // import { qDialog } from './dialog'
9
+
10
+ // export type {
11
+ // PostgrestFilterBuilder,
12
+ // PostgrestSingleResponse,
13
+ // } from '@supabase/postgrest-js'
14
+
15
+ // class MySupabaseClient extends SupabaseClient {
16
+ // email: string = 'unauthenticated'
17
+ // session: Session | null = null
18
+
19
+ // constructor(
20
+ // supabaseUrl: string,
21
+ // supabaseKey: string,
22
+ // options?: SupabaseClientOptions<any>
23
+ // ) {
24
+ // super(supabaseUrl, supabaseKey, options)
25
+ // this.auth.onAuthStateChange((event, session) => {
26
+ // console.log('[SUPABASE AUTH]', event, session?.user?.email)
27
+ // this.session = session
28
+ // this.email = session?.user?.email ?? 'unauthenticated'
29
+ // })
30
+ // }
31
+
32
+ // async signIn() {
33
+ // await this.auth.signOut()
34
+ // await this.auth.signInWithOAuth({
35
+ // provider: 'google',
36
+ // options: {
37
+ // redirectTo: window.location.href,
38
+ // },
39
+ // })
40
+ // }
41
+
42
+ // async call<T>(fn: string, params?: object | undefined): Promise<T[]> {
43
+ // let { data, error } = await this.rpc<string, any>(fn, params)
44
+ // HANDLE_ERROR(data, error)
45
+ // return data
46
+ // }
47
+
48
+ // async callSingle<T>(fn: string, params?: object | undefined): Promise<T> {
49
+ // let { data, error } = await this.rpc<string, any>(fn, params).single()
50
+ // HANDLE_ERROR(data, error)
51
+ // return data as T
52
+ // }
53
+
54
+ // async waitForSignin(): Promise<void> {
55
+ // setInterval(() => {
56
+ // if (this.session === null) this.signIn()
57
+ // }, 1000)
58
+ // waitFor(
59
+ // () => this.session !== null,
60
+ // '[Wait for SignIn] waiting...',
61
+ // '[Wait for SignIn] DONE!'
62
+ // )
63
+ // }
64
+ // }
65
+
66
+ // export let supabase: MySupabaseClient
67
+ // let SUPABASE_URL = process.env.SUPABASE_URL
68
+ // let SUPABASE_KEY = process.env.SUPABASE_KEY
69
+
70
+ // if (SUPABASE_URL && SUPABASE_KEY) {
71
+ // supabase = new MySupabaseClient(SUPABASE_URL, SUPABASE_KEY, {
72
+ // auth: {
73
+ // autoRefreshToken: true,
74
+ // persistSession: true,
75
+ // detectSessionInUrl: true,
76
+ // },
77
+ // })
78
+ // }
79
+
80
+ // export function HANDLE_ERROR<T>(
81
+ // data: T[] | T | null,
82
+ // error: PostgrestError | null
83
+ // ): asserts data {
84
+ // if (error) {
85
+ // if (error.message === 'JWSError JWSInvalidSignature') {
86
+ // localStorage.removeItem('supabase.auth.token')
87
+ // qDialog.error(
88
+ // 'Database Error!',
89
+ // 'Your login session has expired. Please try refreshing the website.'
90
+ // )
91
+ // throw error
92
+ // }
93
+ // let msg = ''
94
+ // msg += error.details ?? '' + '<br/>'
95
+ // msg += error.message ?? '' + '<br/>'
96
+ // msg += error.hint ?? ''
97
+ // qDialog.error('Database Error!', msg)
98
+ // throw error
99
+ // }
100
+ // if (data === null) {
101
+ // qDialog.error('Supabase Error!', 'Returned data is null')
102
+ // throw 'supabase return data is null!'
103
+ // }
104
+ // }
105
+
106
+ // async function waitFor(
107
+ // predicate: () => boolean,
108
+ // waitingMsg: string,
109
+ // doneMsg: string
110
+ // ) {
111
+ // return new Promise(resolve => {
112
+ // async function checker() {
113
+ // if (predicate()) {
114
+ // console.log(doneMsg)
115
+ // resolve(true)
116
+ // } else {
117
+ // console.log(waitingMsg)
118
+ // setTimeout(checker, 50)
119
+ // }
120
+ // }
121
+ // checker()
122
+ // })
123
+ // }