poad 2.1.1

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.
Files changed (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/main/OmneediaClient.d.ts +28 -0
  4. package/dist/main/OmneediaClient.d.ts.map +1 -0
  5. package/dist/main/OmneediaClient.js +58 -0
  6. package/dist/main/OmneediaClient.js.map +1 -0
  7. package/dist/main/env/prefix-dev.d.ts +7 -0
  8. package/dist/main/env/prefix-dev.d.ts.map +1 -0
  9. package/dist/main/env/prefix-dev.js +8 -0
  10. package/dist/main/env/prefix-dev.js.map +1 -0
  11. package/dist/main/env/prefix-prod.d.ts +7 -0
  12. package/dist/main/env/prefix-prod.d.ts.map +1 -0
  13. package/dist/main/env/prefix-prod.js +8 -0
  14. package/dist/main/env/prefix-prod.js.map +1 -0
  15. package/dist/main/env/prefix.d.ts +7 -0
  16. package/dist/main/env/prefix.d.ts.map +1 -0
  17. package/dist/main/env/prefix.js +8 -0
  18. package/dist/main/env/prefix.js.map +1 -0
  19. package/dist/main/index.d.ts +11 -0
  20. package/dist/main/index.d.ts.map +1 -0
  21. package/dist/main/index.js +19 -0
  22. package/dist/main/index.js.map +1 -0
  23. package/dist/main/lib/auth.d.ts +22 -0
  24. package/dist/main/lib/auth.d.ts.map +1 -0
  25. package/dist/main/lib/auth.js +352 -0
  26. package/dist/main/lib/auth.js.map +1 -0
  27. package/dist/main/lib/constants.d.ts +8 -0
  28. package/dist/main/lib/constants.d.ts.map +1 -0
  29. package/dist/main/lib/constants.js +11 -0
  30. package/dist/main/lib/constants.js.map +1 -0
  31. package/dist/main/lib/db.d.ts +45 -0
  32. package/dist/main/lib/db.d.ts.map +1 -0
  33. package/dist/main/lib/db.js +252 -0
  34. package/dist/main/lib/db.js.map +1 -0
  35. package/dist/main/lib/error-codes.d.ts +7 -0
  36. package/dist/main/lib/error-codes.d.ts.map +1 -0
  37. package/dist/main/lib/error-codes.js +3 -0
  38. package/dist/main/lib/error-codes.js.map +1 -0
  39. package/dist/main/lib/errors.d.ts +96 -0
  40. package/dist/main/lib/errors.d.ts.map +1 -0
  41. package/dist/main/lib/errors.js +127 -0
  42. package/dist/main/lib/errors.js.map +1 -0
  43. package/dist/main/lib/realtime.d.ts +9 -0
  44. package/dist/main/lib/realtime.d.ts.map +1 -0
  45. package/dist/main/lib/realtime.js +36 -0
  46. package/dist/main/lib/realtime.js.map +1 -0
  47. package/dist/main/lib/request.d.ts +40 -0
  48. package/dist/main/lib/request.d.ts.map +1 -0
  49. package/dist/main/lib/request.js +237 -0
  50. package/dist/main/lib/request.js.map +1 -0
  51. package/dist/main/lib/types.d.ts +408 -0
  52. package/dist/main/lib/types.d.ts.map +1 -0
  53. package/dist/main/lib/types.js +11 -0
  54. package/dist/main/lib/types.js.map +1 -0
  55. package/dist/main/lib/util.d.ts +7 -0
  56. package/dist/main/lib/util.d.ts.map +1 -0
  57. package/dist/main/lib/util.js +90 -0
  58. package/dist/main/lib/util.js.map +1 -0
  59. package/dist/main/lib copy/auth.d.ts +22 -0
  60. package/dist/main/lib copy/auth.d.ts.map +1 -0
  61. package/dist/main/lib copy/auth.js +283 -0
  62. package/dist/main/lib copy/auth.js.map +1 -0
  63. package/dist/main/lib copy/auth_api.d.ts +23 -0
  64. package/dist/main/lib copy/auth_api.d.ts.map +1 -0
  65. package/dist/main/lib copy/auth_api.js +90 -0
  66. package/dist/main/lib copy/auth_api.js.map +1 -0
  67. package/dist/main/lib copy/constants.d.ts +8 -0
  68. package/dist/main/lib copy/constants.d.ts.map +1 -0
  69. package/dist/main/lib copy/constants.js +11 -0
  70. package/dist/main/lib copy/constants.js.map +1 -0
  71. package/dist/main/lib copy/cookies.d.ts +20 -0
  72. package/dist/main/lib copy/cookies.d.ts.map +1 -0
  73. package/dist/main/lib copy/cookies.js +144 -0
  74. package/dist/main/lib copy/cookies.js.map +1 -0
  75. package/dist/main/lib copy/db.d.ts +45 -0
  76. package/dist/main/lib copy/db.d.ts.map +1 -0
  77. package/dist/main/lib copy/db.js +252 -0
  78. package/dist/main/lib copy/db.js.map +1 -0
  79. package/dist/main/lib copy/realtime.d.ts +9 -0
  80. package/dist/main/lib copy/realtime.d.ts.map +1 -0
  81. package/dist/main/lib copy/realtime.js +36 -0
  82. package/dist/main/lib copy/realtime.js.map +1 -0
  83. package/dist/main/lib copy/request.d.ts +40 -0
  84. package/dist/main/lib copy/request.d.ts.map +1 -0
  85. package/dist/main/lib copy/request.js +206 -0
  86. package/dist/main/lib copy/request.js.map +1 -0
  87. package/dist/main/lib copy/types.d.ts +124 -0
  88. package/dist/main/lib copy/types.d.ts.map +1 -0
  89. package/dist/main/lib copy/types.js +3 -0
  90. package/dist/main/lib copy/types.js.map +1 -0
  91. package/dist/main/lib copy/util.d.ts +7 -0
  92. package/dist/main/lib copy/util.d.ts.map +1 -0
  93. package/dist/main/lib copy/util.js +90 -0
  94. package/dist/main/lib copy/util.js.map +1 -0
  95. package/dist/module/OmneediaClient.d.ts +28 -0
  96. package/dist/module/OmneediaClient.d.ts.map +1 -0
  97. package/dist/module/OmneediaClient.js +52 -0
  98. package/dist/module/OmneediaClient.js.map +1 -0
  99. package/dist/module/env/prefix-dev.d.ts +7 -0
  100. package/dist/module/env/prefix-dev.d.ts.map +1 -0
  101. package/dist/module/env/prefix-dev.js +6 -0
  102. package/dist/module/env/prefix-dev.js.map +1 -0
  103. package/dist/module/env/prefix-prod.d.ts +7 -0
  104. package/dist/module/env/prefix-prod.d.ts.map +1 -0
  105. package/dist/module/env/prefix-prod.js +6 -0
  106. package/dist/module/env/prefix-prod.js.map +1 -0
  107. package/dist/module/env/prefix.d.ts +7 -0
  108. package/dist/module/env/prefix.d.ts.map +1 -0
  109. package/dist/module/env/prefix.js +6 -0
  110. package/dist/module/env/prefix.js.map +1 -0
  111. package/dist/module/index.d.ts +11 -0
  112. package/dist/module/index.d.ts.map +1 -0
  113. package/dist/module/index.js +12 -0
  114. package/dist/module/index.js.map +1 -0
  115. package/dist/module/lib/auth.d.ts +22 -0
  116. package/dist/module/lib/auth.d.ts.map +1 -0
  117. package/dist/module/lib/auth.js +349 -0
  118. package/dist/module/lib/auth.js.map +1 -0
  119. package/dist/module/lib/constants.d.ts +8 -0
  120. package/dist/module/lib/constants.d.ts.map +1 -0
  121. package/dist/module/lib/constants.js +8 -0
  122. package/dist/module/lib/constants.js.map +1 -0
  123. package/dist/module/lib/db.d.ts +45 -0
  124. package/dist/module/lib/db.d.ts.map +1 -0
  125. package/dist/module/lib/db.js +246 -0
  126. package/dist/module/lib/db.js.map +1 -0
  127. package/dist/module/lib/error-codes.d.ts +7 -0
  128. package/dist/module/lib/error-codes.d.ts.map +1 -0
  129. package/dist/module/lib/error-codes.js +2 -0
  130. package/dist/module/lib/error-codes.js.map +1 -0
  131. package/dist/module/lib/errors.d.ts +96 -0
  132. package/dist/module/lib/errors.d.ts.map +1 -0
  133. package/dist/module/lib/errors.js +108 -0
  134. package/dist/module/lib/errors.js.map +1 -0
  135. package/dist/module/lib/realtime.d.ts +9 -0
  136. package/dist/module/lib/realtime.d.ts.map +1 -0
  137. package/dist/module/lib/realtime.js +33 -0
  138. package/dist/module/lib/realtime.js.map +1 -0
  139. package/dist/module/lib/request.d.ts +40 -0
  140. package/dist/module/lib/request.d.ts.map +1 -0
  141. package/dist/module/lib/request.js +231 -0
  142. package/dist/module/lib/request.js.map +1 -0
  143. package/dist/module/lib/types.d.ts +408 -0
  144. package/dist/module/lib/types.d.ts.map +1 -0
  145. package/dist/module/lib/types.js +8 -0
  146. package/dist/module/lib/types.js.map +1 -0
  147. package/dist/module/lib/util.d.ts +7 -0
  148. package/dist/module/lib/util.d.ts.map +1 -0
  149. package/dist/module/lib/util.js +81 -0
  150. package/dist/module/lib/util.js.map +1 -0
  151. package/dist/module/lib copy/auth.d.ts +22 -0
  152. package/dist/module/lib copy/auth.d.ts.map +1 -0
  153. package/dist/module/lib copy/auth.js +277 -0
  154. package/dist/module/lib copy/auth.js.map +1 -0
  155. package/dist/module/lib copy/auth_api.d.ts +23 -0
  156. package/dist/module/lib copy/auth_api.d.ts.map +1 -0
  157. package/dist/module/lib copy/auth_api.js +87 -0
  158. package/dist/module/lib copy/auth_api.js.map +1 -0
  159. package/dist/module/lib copy/constants.d.ts +8 -0
  160. package/dist/module/lib copy/constants.d.ts.map +1 -0
  161. package/dist/module/lib copy/constants.js +8 -0
  162. package/dist/module/lib copy/constants.js.map +1 -0
  163. package/dist/module/lib copy/cookies.d.ts +20 -0
  164. package/dist/module/lib copy/cookies.d.ts.map +1 -0
  165. package/dist/module/lib copy/cookies.js +137 -0
  166. package/dist/module/lib copy/cookies.js.map +1 -0
  167. package/dist/module/lib copy/db.d.ts +45 -0
  168. package/dist/module/lib copy/db.d.ts.map +1 -0
  169. package/dist/module/lib copy/db.js +246 -0
  170. package/dist/module/lib copy/db.js.map +1 -0
  171. package/dist/module/lib copy/realtime.d.ts +9 -0
  172. package/dist/module/lib copy/realtime.d.ts.map +1 -0
  173. package/dist/module/lib copy/realtime.js +33 -0
  174. package/dist/module/lib copy/realtime.js.map +1 -0
  175. package/dist/module/lib copy/request.d.ts +40 -0
  176. package/dist/module/lib copy/request.d.ts.map +1 -0
  177. package/dist/module/lib copy/request.js +200 -0
  178. package/dist/module/lib copy/request.js.map +1 -0
  179. package/dist/module/lib copy/types.d.ts +124 -0
  180. package/dist/module/lib copy/types.d.ts.map +1 -0
  181. package/dist/module/lib copy/types.js +2 -0
  182. package/dist/module/lib copy/types.js.map +1 -0
  183. package/dist/module/lib copy/util.d.ts +7 -0
  184. package/dist/module/lib copy/util.d.ts.map +1 -0
  185. package/dist/module/lib copy/util.js +81 -0
  186. package/dist/module/lib copy/util.js.map +1 -0
  187. package/dist/umd/941.omneedia.js +1 -0
  188. package/dist/umd/omneedia.js +2 -0
  189. package/dist/umd/omneedia.js.LICENSE.txt +1 -0
  190. package/package.json +80 -0
  191. package/src/OmneediaClient.ts +65 -0
  192. package/src/env/prefix-dev.ts +5 -0
  193. package/src/env/prefix-prod.ts +5 -0
  194. package/src/env/prefix.ts +5 -0
  195. package/src/index.ts +26 -0
  196. package/src/lib/auth.ts +306 -0
  197. package/src/lib/constants.ts +7 -0
  198. package/src/lib/db.ts +216 -0
  199. package/src/lib/error-codes.ts +71 -0
  200. package/src/lib/errors.ts +153 -0
  201. package/src/lib/realtime.ts +21 -0
  202. package/src/lib/request.ts +198 -0
  203. package/src/lib/types.ts +512 -0
  204. package/src/lib/util.ts +83 -0
@@ -0,0 +1,306 @@
1
+ import { parseJwt, getHashParams, isBrowser, uuid, urlBase64Decode } from './util'
2
+ import { Capacitor } from '@capacitor/core'
3
+ import { Browser } from '@capacitor/browser'
4
+ import type { MailPhoneProps, PasswordCredentials, ProviderProps, EmailResetProps } from './types'
5
+
6
+ export default class OmneediaAuth {
7
+ protected ref: any
8
+ protected tokenListener: any = null
9
+ private options: any
10
+ constructor(ref: any, options?: any) {
11
+ this.options = options
12
+ this.ref = ref
13
+ this.tokenListener = setInterval(async () => {
14
+ if (isBrowser()) {
15
+ /** look storage */
16
+ let session = await this.session().getUser()
17
+ if (!session) return
18
+ let refresh = localStorage.getItem('omneedia.auth.refresh_token')
19
+ if (!refresh) {
20
+ localStorage.removeItem('omneedia.auth.token')
21
+ localStorage.removeItem('omneedia.auth.refresh_token')
22
+ return (location.href = `#new_token=${refresh}`)
23
+ }
24
+ let date = new Date(session.exp * 1000)
25
+ if (date < new Date()) {
26
+ let token = await this.getNewToken(refresh)
27
+ if (token === false) {
28
+ localStorage.removeItem('omneedia.auth.token')
29
+ localStorage.removeItem('omneedia.auth.refresh_token')
30
+ return (location.href = `#new_token=${refresh}`)
31
+ }
32
+ localStorage.setItem('omneedia.auth.token', token)
33
+ return (location.href = `#new_token=${refresh}`)
34
+ }
35
+ } else {
36
+ let session = await this.session().getUser()
37
+ if (!session) return
38
+ }
39
+ }, 1000)
40
+ }
41
+ public async getNewToken(refresh_token: string | null): Promise<any> {
42
+ let { data } = await this.ref.request.post(
43
+ this.ref.PREFIX.AUTH + '/token?grant_type=refresh_token',
44
+ {
45
+ refresh_token: refresh_token,
46
+ }
47
+ )
48
+ var response: string | null | boolean
49
+ if (data.error) response = false
50
+ else {
51
+ response = data.access_token
52
+ }
53
+ return response
54
+ }
55
+ private _setUserData(data: any) {
56
+ this.options.cookies.setAll([
57
+ {
58
+ name: 'omneedia.auth.token',
59
+ value: data.access_token,
60
+ lifetime: 60 * 3600 * 8,
61
+ domain: '',
62
+ path: '/',
63
+ sameSite: 'None',
64
+ },
65
+ ])
66
+ }
67
+ public async signInWithPassword(props: PasswordCredentials) {
68
+ let { data } = await this.ref.request.post(
69
+ this.ref.PREFIX.AUTH + '/token?grant_type=password',
70
+ {
71
+ props,
72
+ }
73
+ )
74
+ if (isBrowser()) {
75
+ if (data.error) url = [`#error=${data.error}`]
76
+ else {
77
+ var url = []
78
+ for (var el in data) url.push(`${el}=${data[el]}`)
79
+ }
80
+ location.href = '#' + url.join('&')
81
+ } else {
82
+ if (data.error) return { data: { user: null, session: null }, error: { message: data.error } }
83
+ this._setUserData(data)
84
+ return this.getUser(data.access_token)
85
+ }
86
+ }
87
+ public async signUp(props: PasswordCredentials) {
88
+ let { data } = await this.ref.request.post(this.ref.PREFIX.AUTH + '/signup', {
89
+ props,
90
+ })
91
+ console.log(data)
92
+ if (isBrowser()) {
93
+ if (data.error) url = [`#error=${data.error}`]
94
+ else {
95
+ var url = []
96
+ for (var el in data) url.push(`${el}=${data[el]}`)
97
+ }
98
+ if (data.waiting) url = [`#waiting`]
99
+ location.href = '#' + url.join('&')
100
+ } else {
101
+ if (data.error) return { data: { user: null, session: null }, error: { message: data.error } }
102
+ this._setUserData(data)
103
+ return this.getUser(data.access_token)
104
+ }
105
+ }
106
+ public async signInWithProvider(props: ProviderProps) {
107
+ // generateId :: Integer -> String
108
+ const generateId = (len?: number) => {
109
+ const dec2hex = (dec: number) => {
110
+ return dec.toString(16).padStart(2, '0')
111
+ }
112
+ var arr = new Uint8Array((len || 40) / 2)
113
+ window.crypto.getRandomValues(arr)
114
+ return Array.from(arr, dec2hex).join('')
115
+ }
116
+ if (props.config?.callback) {
117
+ return (location.href = `${this.ref.URI}${this.ref.PREFIX.AUTH}/authorize?provider=${props.provider}&callback=${props.config.callback}`)
118
+ }
119
+ const platform = await Capacitor.getPlatform()
120
+ const getSession = async (uid: string) => {
121
+ let { data } = await this.ref.request.post(this.ref.PREFIX.AUTH + '/session', {
122
+ sid: uid,
123
+ })
124
+ if (isBrowser()) {
125
+ if (data?.uri) {
126
+ location.hash = data.uri
127
+ Browser.close()
128
+ } else
129
+ setTimeout(() => {
130
+ getSession(uid)
131
+ }, 1000)
132
+ }
133
+ if (platform === 'ios' || platform === 'android') {
134
+ const uid = generateId()
135
+ getSession(uid)
136
+ Browser.open({
137
+ url: `${this.ref.URI}${this.ref.PREFIX.AUTH}/authorize?provider=${props.provider}&sid=${uid}`,
138
+ })
139
+ } else {
140
+ var win = window.open(
141
+ `${this.ref.URI}${this.ref.PREFIX.AUTH}/authorize?provider=${props.provider}`,
142
+ '_blank'
143
+ )
144
+ window.addEventListener(
145
+ 'message',
146
+ (event) => {
147
+ return (location.hash = event.data)
148
+ },
149
+ false
150
+ )
151
+ }
152
+ }
153
+ return true
154
+ }
155
+ public async updateUser(props: any) {
156
+ const urlParams = new URLSearchParams(window.location.search)
157
+ const token = urlParams.get('token')
158
+ if (token) props.token = token
159
+ let { data } = await this.ref.request.put(this.ref.PREFIX.AUTH + '/user', props)
160
+ return data
161
+ }
162
+ public onAuthStateChange(fn: Function) {
163
+ if (isBrowser()) {
164
+ var HashChange = () => {
165
+ if (location.href.indexOf('access_token') > -1) {
166
+ var params = getHashParams()
167
+ window.location.hash = ''
168
+ localStorage.setItem('omneedia.auth.token', params.access_token)
169
+ localStorage.setItem('omneedia.auth.refresh_token', params.refresh_token)
170
+ return fn('SIGNED_IN', params)
171
+ }
172
+ if (location.href.indexOf('#waiting') > -1) {
173
+ window.location.hash = ''
174
+ return fn('WAITING_FOR_CONFIRMATION', {})
175
+ }
176
+ if (location.href.indexOf('#logout') > -1) {
177
+ localStorage.removeItem('omneedia.auth.token')
178
+ localStorage.removeItem('omneedia.auth.refresh_token')
179
+ window.location.hash = ''
180
+ return fn('SIGNED_OUT', {})
181
+ }
182
+ if (location.href.indexOf('#error') > -1) {
183
+ var token = decodeURIComponent(location.href).split('#error=')[1]
184
+ fn('ERROR', token)
185
+ window.location.hash = ''
186
+ return false
187
+ }
188
+ if (location.href.indexOf('#new_token') > -1) {
189
+ var token = decodeURIComponent(location.href).split('#new_token=')[1]
190
+ fn('REFRESH_TOKEN', localStorage.getItem('omneedia.auth.token'))
191
+ window.location.hash = ''
192
+ return false
193
+ }
194
+
195
+ if (localStorage.getItem('omneedia.auth.token')) {
196
+ fn('AUTHENTICATED', localStorage.getItem('omneedia.auth.token'))
197
+ }
198
+ }
199
+ window.addEventListener('hashchange', HashChange)
200
+ window.addEventListener('load', HashChange)
201
+ HashChange()
202
+ } else {
203
+ // cookie based auth
204
+ }
205
+ }
206
+
207
+ public async resetPasswordForEmail(props: EmailResetProps) {
208
+ let { data } = await this.ref.request.post(this.ref.PREFIX.AUTH + '/recover', props)
209
+
210
+ if (data.error) url = [`error=${data.error}`]
211
+ else {
212
+ var url = []
213
+ for (var el in data) url.push(`${el}=${data[el]}`)
214
+ }
215
+ if (data.waiting) url = [`waiting`]
216
+ location.href = '#' + url.join('&')
217
+ }
218
+ public async signInWithEmail(props: MailPhoneProps) {
219
+ let { data } = await this.ref.request.post(this.ref.PREFIX.AUTH + '/magiclink', props)
220
+ if (data.error) url = [`error=${data.error}`]
221
+ else {
222
+ var url = []
223
+ for (var el in data) url.push(`${el}=${data[el]}`)
224
+ }
225
+ if (data.waiting) url = [`waiting`]
226
+ location.href = '#' + url.join('&')
227
+ }
228
+ public getSession(): boolean | any {
229
+ var session = false
230
+ if (isBrowser()) {
231
+ if (localStorage.getItem('omneedia.auth.token')) {
232
+ let token: string | null = localStorage.getItem('omneedia.auth.token')!
233
+ session = parseJwt(token)
234
+ }
235
+ } else {
236
+ // use cookie
237
+ }
238
+ return {
239
+ getUser: (): any => {
240
+ return session
241
+ },
242
+ }
243
+ }
244
+ public session = this.getSession
245
+ public async getUser(token?: string | null) {
246
+ if (token) {
247
+ if (isBrowser()) {
248
+ try {
249
+ token = urlBase64Decode(token)
250
+ return token
251
+ } catch (e) {
252
+ return null
253
+ }
254
+ } else {
255
+ const decoded = urlBase64Decode(token)
256
+ if (!decoded) return { data: { user: null, session: null }, error: null }
257
+ if (decoded.role == 'anon') {
258
+ return { data: { user: null, session: null }, error: { message: 'anonymous' } }
259
+ }
260
+ return { data: { user: decoded, session: token }, error: null }
261
+ }
262
+ }
263
+ let { data } = await this.ref.request.get(this.ref.PREFIX.AUTH + '/user')
264
+ if (!data) return { data: { user: null, session: null }, error: { message: 'anonymous' } }
265
+ if (data.role == 'anon') {
266
+ return { data: { user: null, session: null }, error: { message: 'anonymous' } }
267
+ }
268
+ if (data === false) {
269
+ if (isBrowser()) {
270
+ localStorage.removeItem('omneedia.auth.token')
271
+ localStorage.removeItem('omneedia.auth.refresh_token')
272
+ } else {
273
+ // use cookie
274
+ this.options.cookies.deleteAll()
275
+ }
276
+ }
277
+ if (isBrowser()) return data
278
+ else return { data: { user: data }, error: null }
279
+ }
280
+ public isAuthenticated() {
281
+ if (isBrowser()) {
282
+ if (window.localStorage.getItem('omneedia.auth.token')) return true
283
+ else return false
284
+ }
285
+ }
286
+ public async signOut() {
287
+ if (isBrowser()) {
288
+ await this.ref.request.get(this.ref.PREFIX.AUTH + '/signout')
289
+ location.hash = '#logout'
290
+ return
291
+ } else {
292
+ const { data } = await this.ref.request.get(this.ref.PREFIX.AUTH + '/signout')
293
+ //await this.options.auth.storage.removeItem('omneedia.auth.token')
294
+ this.options.cookies.setAll([
295
+ {
296
+ name: 'omneedia.auth.token',
297
+ value: data.token,
298
+ lifetime: new Date(0),
299
+ domain: '',
300
+ path: '/',
301
+ sameSite: 'lax',
302
+ },
303
+ ])
304
+ }
305
+ }
306
+ }
@@ -0,0 +1,7 @@
1
+ export const COOKIE_OPTIONS = {
2
+ name: 'oa:token',
3
+ lifetime: 60 * 3600 * 8,
4
+ domain: '',
5
+ path: '/',
6
+ sameSite: 'lax',
7
+ }
package/src/lib/db.ts ADDED
@@ -0,0 +1,216 @@
1
+ import OARequest from './request'
2
+
3
+ export default class OmneediaQueryDB {
4
+ private TABLE: string
5
+ private SELECT: Array<string> = []
6
+ private INSERT: Object = {}
7
+ private UPDATE: Object = {}
8
+ private DELETE: boolean = false
9
+ private WHERE: Array<string> = []
10
+ private ref: any = {}
11
+ private request: any
12
+ private FilterOperator = [
13
+ 'eq',
14
+ 'neq',
15
+ 'gt',
16
+ 'gte',
17
+ 'lt',
18
+ 'lte',
19
+ 'like',
20
+ 'ilike',
21
+ 'is',
22
+ 'in',
23
+ 'cs',
24
+ 'cd',
25
+ 'sl',
26
+ 'sr',
27
+ 'nxl',
28
+ 'nxr',
29
+ 'adj',
30
+ 'ov',
31
+ 'fts',
32
+ 'plfts',
33
+ 'phfts',
34
+ 'wfts',
35
+ ]
36
+ constructor(table: string, ref: any) {
37
+ this.TABLE = table
38
+ this.ref = ref
39
+ this.request = new OARequest(this)
40
+ }
41
+ rangeLt(key: string, value: any) {
42
+ this.WHERE.push(`${key}=sl.${value}`)
43
+ return this
44
+ }
45
+ rangeGt(key: string, value: any) {
46
+ this.WHERE.push(`${key}=sr.${value}`)
47
+ return this
48
+ }
49
+ rangeLte(key: string, value: any) {
50
+ this.WHERE.push(`${key}=nxr.${value}`)
51
+ return this
52
+ }
53
+ rangeGte(key: string, value: any) {
54
+ this.WHERE.push(`${key}=nxl.${value}`)
55
+ return this
56
+ }
57
+ rangeAdjacent(key: string, value: any) {
58
+ this.WHERE.push(`${key}=adj.${value}`)
59
+ return this
60
+ }
61
+ overlaps(key: string, value: any) {
62
+ if (!Array.isArray(value)) value = [value]
63
+ value = `[${value.join(',')}]`
64
+ this.WHERE.push(`${key}=ov.${value}`)
65
+ return this
66
+ }
67
+ not(key: string, value: any, o: any) {
68
+ if (this.FilterOperator.indexOf(value) == -1) return this
69
+ this.WHERE.push(`${key}=not.${value}.${o}`)
70
+ return this
71
+ }
72
+ is(key: string, value: any) {
73
+ this.WHERE.push(`${key}=is.${value}`)
74
+ return this
75
+ }
76
+ contains(key: string, value: any) {
77
+ if (!Array.isArray(value)) value = [value]
78
+ value = `{${value.join(',')}}`
79
+ this.WHERE.push(`${key}=cs.${value}`)
80
+ return this
81
+ }
82
+ containedBy(key: any, value: any) {
83
+ if (!Array.isArray(value)) value = [value]
84
+ value = `{${value.join(',')}}`
85
+ this.WHERE.push(`${key}=cd.${value}`)
86
+ return this
87
+ }
88
+ or(key: any) {
89
+ if (!Array.isArray(key)) key = [key]
90
+ if (key.length == 1) key = key[0].split(',')
91
+ this.WHERE.push(`or=(${key.join(',')})`)
92
+ return this
93
+ }
94
+ and(key: any) {
95
+ if (!Array.isArray(key)) key = [key]
96
+ if (key.length == 1) key = key[0].split(',')
97
+ this.WHERE.push(`and=(${key.join(',')})`)
98
+ return this
99
+ }
100
+ textSearch(key: string, value: any, o: any) {
101
+ let typePart = ''
102
+ if (o) {
103
+ if (o.type === 'plain') {
104
+ typePart = 'pl'
105
+ } else if (o.type === 'phrase') {
106
+ typePart = 'ph'
107
+ } else if (o.type === 'websearch') {
108
+ typePart = 'w'
109
+ }
110
+ }
111
+ let method = `${typePart}fts`
112
+ this.WHERE.push(`${key}=${method}.${value}`)
113
+ return this
114
+ }
115
+ in(key: string, value: any) {
116
+ if (!Array.isArray(value)) value = [value]
117
+ value = `(${value.join(',')})`
118
+ this.WHERE.push(`${key}=in.${value}`)
119
+ return this
120
+ }
121
+ nxr(key: string, value: any) {
122
+ if (!Array.isArray(value)) value = [value]
123
+ value = `(${value.join(',')})`
124
+ this.WHERE.push(`${key}=nxr.${value}`)
125
+ return this
126
+ }
127
+ sl(key: string, value: any) {
128
+ if (!Array.isArray(value)) value = [value]
129
+ value = `(${value.join(',')})`
130
+ this.WHERE.push(`${key}=sl.${value}`)
131
+ return this
132
+ }
133
+ adj(key: string, value: any) {
134
+ if (!Array.isArray(value)) value = [value]
135
+ value = `(${value.join(',')})`
136
+ this.WHERE.push(`${key}=adj.${value}`)
137
+ return this
138
+ }
139
+ imatch(key: any) {
140
+ for (var el in key) {
141
+ this.WHERE.push(`${el}=eq.${key[el]}`)
142
+ }
143
+ return this
144
+ }
145
+ match(key: any) {
146
+ for (var el in key) {
147
+ this.WHERE.push(`${el}=eq.${key[el]}`)
148
+ }
149
+ return this
150
+ }
151
+ gt(key: string, value: string) {
152
+ this.WHERE.push(`${key}=gt.${value}`)
153
+ return this
154
+ }
155
+ gte(key: string, value: string) {
156
+ this.WHERE.push(`${key}=gte.${value}`)
157
+ return this
158
+ }
159
+ lt(key: string, value: string) {
160
+ this.WHERE.push(`${key}=lt.${value}`)
161
+ return this
162
+ }
163
+ lte(key: string, value: string) {
164
+ this.WHERE.push(`${key}=lte.${value}`)
165
+ return this
166
+ }
167
+ neq(key: string, value: string) {
168
+ this.WHERE.push(`${key}=neq.${value}`)
169
+ return this
170
+ }
171
+ like(key: string, value: string) {
172
+ this.WHERE.push(`${key}=like.${value}`)
173
+ return this
174
+ }
175
+ ilike(key: string, value: string) {
176
+ this.WHERE.push(`${key}=ilike.${value}`)
177
+ return this
178
+ }
179
+ eq(key: string, value: string) {
180
+ this.WHERE.push(`${key}=eq.${value}`)
181
+ return this
182
+ }
183
+ select(...s: any) {
184
+ if (!s) s = ['']
185
+ if (s.length == 1) s = s[0].split(',')
186
+ this.SELECT = s
187
+ return this
188
+ }
189
+ insert(o: any) {
190
+ this.INSERT = o
191
+ return this
192
+ }
193
+ update(o: any) {
194
+ this.UPDATE = o
195
+ return this
196
+ }
197
+ delete() {
198
+ this.DELETE = true
199
+ return this
200
+ }
201
+ async then(resolve: any, reject: any) {
202
+ var uri = `/${this.TABLE}?`
203
+ if (Object.keys(this.INSERT).length > 0) {
204
+ var url = this.ref.PREFIX.REST + uri
205
+ return resolve(this.request.post(url, this.INSERT))
206
+ }
207
+ if (this.SELECT.length > 0) uri += `select=${this.SELECT.join(',')}&`
208
+ if (this.WHERE.length > 0) uri += this.WHERE.join('&')
209
+ var url = this.ref.PREFIX.REST + uri
210
+ var method = 'get'
211
+ if (this.DELETE === true) method = 'delete'
212
+ if (Object.keys(this.UPDATE).length > 0) {
213
+ resolve(this.request.patch(url, this.UPDATE))
214
+ } else resolve(this.request[method](url))
215
+ }
216
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Known error codes. Note that the server may also return other error codes
3
+ * not included in this list (if the client library is older than the version
4
+ * on the server).
5
+ */
6
+ export type ErrorCode =
7
+ | 'unexpected_failure'
8
+ | 'validation_failed'
9
+ | 'bad_json'
10
+ | 'email_exists'
11
+ | 'phone_exists'
12
+ | 'bad_jwt'
13
+ | 'not_admin'
14
+ | 'no_authorization'
15
+ | 'user_not_found'
16
+ | 'session_not_found'
17
+ | 'flow_state_not_found'
18
+ | 'flow_state_expired'
19
+ | 'signup_disabled'
20
+ | 'user_banned'
21
+ | 'provider_email_needs_verification'
22
+ | 'invite_not_found'
23
+ | 'bad_oauth_state'
24
+ | 'bad_oauth_callback'
25
+ | 'oauth_provider_not_supported'
26
+ | 'unexpected_audience'
27
+ | 'single_identity_not_deletable'
28
+ | 'email_conflict_identity_not_deletable'
29
+ | 'identity_already_exists'
30
+ | 'email_provider_disabled'
31
+ | 'phone_provider_disabled'
32
+ | 'too_many_enrolled_mfa_factors'
33
+ | 'mfa_factor_name_conflict'
34
+ | 'mfa_factor_not_found'
35
+ | 'mfa_ip_address_mismatch'
36
+ | 'mfa_challenge_expired'
37
+ | 'mfa_verification_failed'
38
+ | 'mfa_verification_rejected'
39
+ | 'insufficient_aal'
40
+ | 'captcha_failed'
41
+ | 'saml_provider_disabled'
42
+ | 'manual_linking_disabled'
43
+ | 'sms_send_failed'
44
+ | 'email_not_confirmed'
45
+ | 'phone_not_confirmed'
46
+ | 'reauth_nonce_missing'
47
+ | 'saml_relay_state_not_found'
48
+ | 'saml_relay_state_expired'
49
+ | 'saml_idp_not_found'
50
+ | 'saml_assertion_no_user_id'
51
+ | 'saml_assertion_no_email'
52
+ | 'user_already_exists'
53
+ | 'sso_provider_not_found'
54
+ | 'saml_metadata_fetch_failed'
55
+ | 'saml_idp_already_exists'
56
+ | 'sso_domain_already_exists'
57
+ | 'saml_entity_id_mismatch'
58
+ | 'conflict'
59
+ | 'provider_disabled'
60
+ | 'user_sso_managed'
61
+ | 'reauthentication_needed'
62
+ | 'same_password'
63
+ | 'reauthentication_not_valid'
64
+ | 'otp_expired'
65
+ | 'otp_disabled'
66
+ | 'identity_not_found'
67
+ | 'weak_password'
68
+ | 'over_request_rate_limit'
69
+ | 'over_email_send_rate_limit'
70
+ | 'over_sms_send_rate_limit'
71
+ | 'bad_code_verifier'