@bagelink/sdk 0.0.736 → 0.0.740

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.
@@ -0,0 +1,47 @@
1
+ import type { AxiosInstance, AxiosResponse } from 'axios'
2
+ // @ts-expect-error - required for axios to work
3
+ import { axios } from './api'
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/utils.ts ADDED
@@ -0,0 +1,81 @@
1
+ import fs from 'node:fs'
2
+
3
+ import { join } from 'node:path'
4
+ import { createRequire } from 'node:module'
5
+ import * as prettier from 'prettier'
6
+ import { ESLint } from 'eslint'
7
+ import { loadEnv } from 'vite'
8
+
9
+ const _require = createRequire(import.meta.url)
10
+
11
+ const proc = _require('process') as typeof import('process')
12
+
13
+ const cwd = proc.cwd()
14
+ const env = loadEnv('', cwd)
15
+
16
+ if (!env.VITE_BAGEL_BASE_URL) {
17
+ throw new Error('VITE_BAGEL_BASE_URL is not defined')
18
+ }
19
+
20
+ const [_, __, dirFlag, withAuthArg] = proc.argv as Partial<string[]>
21
+
22
+ const withAuth = withAuthArg === '--auth'
23
+
24
+ if (dirFlag !== undefined) {
25
+ console.log(`using passed in dir to generate sdk client: ${dirFlag}`)
26
+ } else {
27
+ console.log(`using default dir to generate sdk client: .bagelink`)
28
+ console.log(`to use a different dir, pass it as an argument to the command`)
29
+ }
30
+
31
+ // const bagelinkDir = join(cwd, (dirFlag ?? '.bagelink').replace(/\/$/, ''))
32
+
33
+ const bagelinkDir = join(cwd, dirFlag ?? '.bagelink')
34
+ const baseUrl = `${env.VITE_BAGEL_BASE_URL}`
35
+ const baseUrlEnvStr = 'import.meta.env.VITE_BAGEL_BASE_URL'
36
+ const openApiUrl = `${baseUrl}/openapi.json`
37
+
38
+ export function getKwargs() {
39
+ return {
40
+ baseUrl,
41
+ baseUrlEnvStr,
42
+ openApiUrl,
43
+ bagelinkDir,
44
+ withAuth,
45
+ cwd,
46
+ env,
47
+ proc
48
+ } as const
49
+ }
50
+
51
+ export async function formatAndWriteCode(outPath: string, code: string) {
52
+ const prettyCode = await prettier.format(code, { parser: 'typescript' })
53
+ fs.writeFileSync(outPath, prettyCode)
54
+ }
55
+
56
+ export async function runEsLintOnDir(dir: string) {
57
+ // ! only run if eslint.config.js exists
58
+ if (!fs.existsSync(join(cwd, 'eslint.config.js'))) {
59
+ console.log('no eslint.config.js found, skipping eslint')
60
+ return
61
+ }
62
+
63
+ const eslint = new ESLint({ fix: true, overrideConfigFile: join(cwd, 'eslint.config.js'), cwd })
64
+ const results = await eslint.lintFiles(`${dir}/**/*.ts`)
65
+
66
+ await ESLint.outputFixes(results)
67
+ }
68
+
69
+ export async function handleAuthCode(_withAuth: boolean, _bagelinkDir: string) {
70
+ if (_withAuth) {
71
+ const authCode = fs.readFileSync(
72
+ join(__dirname, 'authClientCode.ts'),
73
+ 'utf-8'
74
+ ).replace(
75
+ '// @ts-expect-error - required for axios to work',
76
+ ''
77
+ )
78
+ const authPath = join(_bagelinkDir, 'auth.ts')
79
+ await formatAndWriteCode(authPath, authCode)
80
+ }
81
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.736",
4
+ "version": "0.0.740",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -43,13 +43,14 @@
43
43
  "files": [
44
44
  "dist",
45
45
  "src",
46
- "bin/auth.ts"
46
+ "bin/authClientCode.ts",
47
+ "bin/utils.ts"
47
48
  ],
48
49
  "publishConfig": {
49
50
  "access": "public"
50
51
  },
51
52
  "dependencies": {
52
- "axios": "^1.7.5"
53
+ "axios": "^1.7.7"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@apidevtools/swagger-parser": "^10.1.0",
@@ -6,6 +6,7 @@ import type {
6
6
  ResponseObject,
7
7
  ResponsesObject,
8
8
  } from './openApiTypes'
9
+
9
10
  import {
10
11
  cleanPath,
11
12
  formatType,