@bagelink/sdk 0.0.635 → 0.0.639

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/bin/auth.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type { AxiosInstance, AxiosResponse } from 'axios'
2
+ // @ts-expect-error - required for axios to work
3
+ import { axios } from '.'
4
+
5
+ export interface Message {
6
+ message: string
7
+ }
8
+
9
+ export interface NewPassword {
10
+ token: string
11
+ new_password: string
12
+ }
13
+ const ax: AxiosInstance = axios
14
+
15
+ ax.interceptors.request.use((config) => {
16
+ const token = localStorage.getItem('access_token')
17
+ if (token !== null) config.headers.Authorization = `Bearer ${token}`
18
+
19
+ const urlParams = new URLSearchParams(window.location.search)
20
+ const resetToken = urlParams.get('token')
21
+ if (resetToken !== null) config.data = { ...config.data, token: resetToken }
22
+ return config
23
+ })
24
+
25
+ export async function login(username: string, password: string) {
26
+ const formData = new FormData()
27
+ formData.append('username', username)
28
+ formData.append('password', password)
29
+ formData.append('scope', 'auth')
30
+ formData.append('grant_type', 'password')
31
+ const { data } = await ax.post('/auth/login', formData, {
32
+ headers: { 'withCredentials': true, 'Content-Type': 'multipart/form-data' },
33
+ })
34
+ localStorage.setItem('access_token', data.access_token)
35
+ }
36
+ export function logout() {
37
+ localStorage.removeItem('access_token')
38
+ window.location.reload()
39
+ }
40
+ export async function passwordRecovery(email?: string): Promise<AxiosResponse<Message>> {
41
+ return ax.post(`/auth/password-recovery/${email}`, {})
42
+ }
43
+ export async function resetPassword(
44
+ newPassword: Partial<NewPassword> & Pick<NewPassword, 'new_password'>
45
+ ): Promise<AxiosResponse<Record<string, any>>> {
46
+ return ax.post('/auth/reset-password', { new_password: newPassword })
47
+ }
package/bin/index.ts CHANGED
@@ -49,12 +49,6 @@ async function runEsLintOnDir(dir: string) {
49
49
  const results = await eslint.lintFiles(`${dir}/**/*.ts`)
50
50
 
51
51
  await ESLint.outputFixes(results)
52
-
53
- // const formatter = await eslint.loadFormatter('stylish')
54
- // const rulesMeta = eslint.getRulesMetaForResults(results)
55
- // await formatter.format(results, { cwd, rulesMeta })
56
- // const resultText =
57
- // console.log(resultText)
58
52
  }
59
53
 
60
54
  export async function loadTypes() {
@@ -73,8 +67,10 @@ export async function loadTypes() {
73
67
  await formatAndWriteCode(apiPath, code)
74
68
 
75
69
  if (withAuth) {
70
+ console.log({ cwd })
71
+
76
72
  const authCode = fs.readFileSync(
77
- join(cwd, 'auth.ts'),
73
+ join(__dirname, 'auth.ts'),
78
74
  'utf-8'
79
75
  ).replace(
80
76
  '',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.635",
4
+ "version": "0.0.639",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -42,7 +42,8 @@
42
42
  },
43
43
  "files": [
44
44
  "dist",
45
- "src"
45
+ "src",
46
+ "bin/auth.ts"
46
47
  ],
47
48
  "publishConfig": {
48
49
  "access": "public"