refactor: some more sdk update

This commit is contained in:
melvinchia3636
2026-06-09 17:44:51 +08:00
parent 5159d67057
commit f6a43a5f2c
42 changed files with 6126 additions and 93 deletions

View File

@@ -13,15 +13,14 @@
"type": "module",
"scripts": {
"dev": "vite",
"types": "tsc -b",
"build": "tsc -b && vite build",
"types": "tsgo -b",
"build": "tsgo -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@iconify/react": "^6.0.2",
"@lifeforge/api": "workspace:*",
"@lifeforge/federation": "workspace:*",
"@lifeforge/ui": "workspace:*",
@@ -45,7 +44,6 @@
"react-virtualized": "^9.22.6",
"recharts": "^2.15.0",
"socket.io-client": "^4.8.1",
"typescript": "^5.9.3",
"uuid": "^13.0.0"
},
"devDependencies": {

View File

@@ -3,7 +3,7 @@ import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import {
Box,
Button,

View File

@@ -3,7 +3,7 @@ import _ from 'lodash'
import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Button, Flex, OptionsColumn, Text, useModalStore } from '@lifeforge/ui'
import ModifyModal from '../modals/ModifyModal'

View File

@@ -1,7 +1,7 @@
import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Flex, OptionsColumn, Switch, Text, useModalStore } from '@lifeforge/ui'
import DisableTwoFAModal from '../modals/DisableTwoFAModal'

View File

@@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { ConfirmationModal } from '@lifeforge/ui'
import forgeAPI from '@/forgeAPI'

View File

@@ -2,7 +2,7 @@ import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Box, ModalHeader } from '@lifeforge/ui'
import TwoFAEnableProcedure from './components/TwoFAEnableProcedure'

View File

@@ -5,7 +5,7 @@ import { useForm } from 'react-hook-form'
import { toast } from '@lifeforge/ui'
import z from 'zod'
import { useAuth, type UserData } from '@/providers/AuthProvider'
import { useAuth, type UserData } from '@lifeforge/api'
import {
DateField,
FormModal,

View File

@@ -6,7 +6,7 @@ import { useSearchParams } from 'react-router'
import { usePromiseLoading } from '@lifeforge/api'
import { Stack, TextInput, toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import AuthSignInButton from './AuthSignInButtons'

View File

@@ -1,6 +1,6 @@
import { memo } from 'react'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Button } from '@lifeforge/ui'
function SignInButton({

View File

@@ -2,7 +2,7 @@ import _ from 'lodash'
import { memo, useCallback } from 'react'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Button } from '@lifeforge/ui'
import forgeAPI from '@/forgeAPI'

View File

@@ -4,7 +4,7 @@ import { toast } from '@lifeforge/ui'
import { Socket, io } from 'socket.io-client'
import { v4 as uuidv4 } from 'uuid'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { useAPIEndpoint } from '@lifeforge/api'
import forgeAPI from '@/forgeAPI'

View File

@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Button, OTPInputBox, Stack, Text, TextInput } from '@lifeforge/ui'
import forgeAPI from '@/forgeAPI'

View File

@@ -2,7 +2,7 @@ import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { Button, Flex, ModalHeader } from '@lifeforge/ui'
import OrAuthWithDivider from '../../components/OrAuthWithDivider'

View File

@@ -1,7 +1,7 @@
import { useEffect } from 'react'
import { useSearchParams } from 'react-router'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import { ModalManager, Stack, WithQueryData } from '@lifeforge/ui'
import forgeAPI from '@/forgeAPI'

View File

@@ -1,7 +1,7 @@
import { createContext, useContext, useEffect } from 'react'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import {
type IBackdropFilters,
type IDashboardLayout,

View File

@@ -9,7 +9,7 @@ import {
SocketProvider
} from '@lifeforge/api'
import { FederationProvider } from '@lifeforge/federation'
import AuthProvider from '@/providers/AuthProvider'
import { AuthProvider } from '@lifeforge/api'
import {
APIOnlineStatusWrapper,
BackgroundProvider,

View File

@@ -2,7 +2,7 @@ import { useCallback } from 'react'
import { useNavigate } from 'react-router'
import { toast } from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import {
Box,
Card,

View File

@@ -2,7 +2,7 @@ import dayjs from 'dayjs'
import { useMemo } from 'react'
import tinycolor from 'tinycolor2'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import {
COLORS,
Flex,

View File

@@ -13,7 +13,7 @@ import {
useMainSidebarState
} from '@lifeforge/ui'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import MainSidebarTitle from './MainSidebarTitle'

View File

@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'
import { type DataRouter, createBrowserRouter } from 'react-router'
import { useFederation } from '@lifeforge/federation'
import { useAuth } from '@/providers/AuthProvider'
import { useAuth } from '@lifeforge/api'
import {
createAuthLoadingConfig,

View File

@@ -27,7 +27,6 @@
"verbatimModuleSyntax": true,
"composite": true,
"rootDir": "../",
"baseUrl": "./",
"paths": {
"@/*": [
"./src/*"

View File

@@ -33,8 +33,8 @@
"lifeforge"
],
"devDependencies": {
"@lifeforge/configs": "workspace:*",
"@eslint/js": "^9.26.0",
"@lifeforge/configs": "workspace:*",
"@originjs/vite-plugin-federation": "^1.4.1",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"@types/lodash": "^4.17.21",
@@ -45,6 +45,7 @@
"@types/tinycolor2": "^1.4.6",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript/native-preview": "^7.0.0-dev.20260609.1",
"@vitejs/plugin-react": "^4.4.1",
"bun-types": "latest",
"concurrently": "^9.1.2",

2985
packages/api/contract.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +3,13 @@
"version": "0.0.1",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"scripts": {
"dev": "tsc --watch",
"types": "tsc -b --noEmit",
"build": "tsc"
"dev": "vite build --watch",
"types": "tsgo -b --noEmit",
"build": "rm -rf dist && bun types && vite build"
},
"dependencies": {
"axios": "^1.12.2",
@@ -18,8 +19,8 @@
},
"devDependencies": {
"@types/crypto-js": "^4.2.2",
"@types/react": "^19.2.0",
"typescript": "^5.9.3"
"@vitejs/plugin-react": "^4.7.0",
"vite-plugin-dts": "^4.5.4"
},
"peerDependencies": {
"@tanstack/react-query": "^5.90.2",

View File

@@ -14,6 +14,8 @@ export * from './providers/EncryptionProvider'
export * from './providers/SocketProvider'
export * from './providers/AuthProvider'
export * from './utils/encryption'
export * from './utils/fetchAPI'

View File

@@ -8,13 +8,14 @@ import {
useRef,
useState
} from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from '@lifeforge/ui'
import type { InferOutput } from '@lifeforge/api'
import type forgeAPIInstance from '@/forgeAPI'
import { contract } from '../../contract'
import { createForgeProxy } from '../core/createForgeProxy'
import type { InferOutput, ProxyTree } from '../typescript/forge_proxy.types'
export type UserData = InferOutput<typeof forgeAPIInstance.user.auth.getUserData>
const _forgeAPI = createForgeProxy(contract)
export type UserData = InferOutput<typeof _forgeAPI.user.auth.getUserData>
interface AuthData {
auth: boolean
@@ -54,17 +55,15 @@ interface Verify2FAResponse {
export const AuthContext = createContext<AuthData | undefined>(undefined)
export default function AuthProvider({
export function AuthProvider({
forgeAPI,
onTwoFAModalOpen,
children
}: {
forgeAPI: typeof forgeAPIInstance
forgeAPI: ProxyTree<any>
onTwoFAModalOpen: () => void
children: React.ReactNode
}) {
const { t } = useTranslation('common.auth')
const [auth, _setAuth] = useState(false)
const [userData, setUserData] = useState<UserData | null>(null)
@@ -84,8 +83,8 @@ export default function AuthProvider({
async (
session: string
): Promise<{
success: boolean;
userData: UserData | null;
success: boolean
userData: UserData | null
}> => {
try {
const verifyRes = await fetch(
@@ -119,8 +118,8 @@ export default function AuthProvider({
email,
password
}: {
email: string;
password: string;
email: string
password: string
}): Promise<string | void> => {
try {
const data = await forgeAPI.user.auth.login.mutate({
@@ -163,8 +162,8 @@ export default function AuthProvider({
otp,
type
}: {
otp: string;
type: 'email' | 'app';
otp: string
type: 'email' | 'app'
}): Promise<string> => {
try {
const res = await fetch(forgeAPI.user['2fa'].verify.endpoint, {
@@ -237,8 +236,6 @@ export default function AuthProvider({
localStorage.setItem('session', session)
toast.success(t('auth.welcome') + userData.username)
return true
} else {
throw new Error('Invalid session')
@@ -247,7 +244,6 @@ export default function AuthProvider({
setAuth(false)
setUserData(null)
setAuthLoading(false)
toast.error(t('messages.invalidLoginAttempt'))
return false
} finally {

View File

@@ -1,11 +1,13 @@
{
"extends": "@lifeforge/configs/tsconfig/base.json",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"lib": [
"ESNext",
"DOM"
],
"target": "ESNext",
"module": "ESNext",
"declaration": true,
"rootDir": "./src",
"outDir": "./dist",
"noEmit": false,
"strict": true,
@@ -13,6 +15,12 @@
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true
},
"include": ["./src/**/*"],
"exclude": ["dist", "node_modules"]
}
"include": [
"./src/**/*",
"./contract.ts"
],
"exclude": [
"dist",
"node_modules"
]
}

View File

@@ -0,0 +1,46 @@
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
export default defineConfig({
plugins: [
react(),
dts({
rollupTypes: true
})
],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs'],
fileName: format => `index.${format === 'es' ? 'mjs' : 'js'}`
},
rollupOptions: {
external: [
'react',
'react-dom',
'react/jsx-runtime',
'@tanstack/react-query',
'zod',
'axios',
'crypto-js',
'json-schema-to-ts',
'socket.io-client'
],
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM'
}
}
},
sourcemap: false,
minify: true
}
})

View File

@@ -21,19 +21,16 @@
"./package.json": "./package.json"
},
"scripts": {
"build": "vite build && tsc --emitDeclarationOnly"
},
"dependencies": {
"zod": "4.3.5"
"build": "vite build && tsgo --emitDeclarationOnly"
},
"peerDependencies": {
"@originjs/vite-plugin-federation": "^1.4.1",
"@vitejs/plugin-react": "^4.4.1",
"react": "^19.2.0",
"vite": "^7.1.9"
"vite": "^7.1.9",
"zod": "4.3.5"
},
"devDependencies": {
"@types/react": "^19.2.0",
"typescript": "^5.9.3"
"@types/react": "^19.2.0"
}
}

View File

@@ -1,9 +1,12 @@
import { z } from 'zod'
import type { WidgetConfig } from './widget_config.types'
import type React from 'react';
export interface ModuleConfig {
provider?: React.LazyExoticComponent<React.ComponentType>
provider?: React.LazyExoticComponent<
React.ComponentType<{ children: React.ReactNode }>
>
routes: Record<string, React.LazyExoticComponent<React.ComponentType>>
subsection?: {
label: string

View File

@@ -10,14 +10,12 @@
"build": "tsc"
},
"dependencies": {
"@lifeforge/api": "workspace:*",
"zod": "4.3.5"
"@lifeforge/api": "workspace:*"
},
"peerDependencies": {
"react": "^19.2.0"
},
"devDependencies": {
"@types/react": "^19.2.0",
"typescript": "^5.9.3"
"@types/react": "^19.2.0"
}
}

View File

@@ -1,5 +1,4 @@
import { globalProxyRegistry } from '@lifeforge/api'
import {
type ModuleCategory,
type ModuleConfig,

View File

@@ -16,7 +16,7 @@
}
},
"scripts": {
"build": "bun build ./src/index.ts ./src/loggers/cliLogger.ts --outdir=dist --target=node && bun tsc --project tsconfig.json",
"build": "bun build ./src/index.ts ./src/loggers/cliLogger.ts --outdir=dist --target=node && bun tsgo --project tsconfig.json",
"test": "vitest run",
"test:watch": "vitest"
},
@@ -28,7 +28,6 @@
},
"devDependencies": {
"@types/node": "^25.0.6",
"typescript": "^5.9.0",
"vitest": "^4.0.0"
}
}

View File

@@ -11,11 +11,18 @@
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
"@/*": [
"./src/*"
]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist",
"**/*.test.ts"
]
}

View File

@@ -14,8 +14,8 @@
}
},
"scripts": {
"build": "rm -rf dist && bun build ./src/index.ts --outdir=dist --target=node && bun tsc --emitDeclarationOnly",
"types": "bun tsc --emitDeclarationOnly"
"build": "rm -rf dist && bun build ./src/index.ts --outdir=dist --target=node && bun tsgo --emitDeclarationOnly",
"types": "bun tsgo --emitDeclarationOnly"
},
"dependencies": {
"chalk": "^5.6.2",
@@ -31,7 +31,6 @@
"socket.io": "^4.8.3",
"tesseract.js": "^5.1.1",
"uuid": "^11.1.0",
"zod": "4.3.5",
"@lifeforge/log": "workspace:*"
},
"devDependencies": {
@@ -40,7 +39,6 @@
"@types/express-serve-static-core": "4",
"@types/lodash": "^4.17.21",
"@types/multer": "^1.4.13",
"typescript": "^5.8.3",
"vitest": "^4.1.7"
},
"peerDependencies": {

View File

@@ -1,10 +1,10 @@
import type OpenAI from 'openai'
import { Server } from 'socket.io'
import { CleanedSchemas } from 'utils/schemaUtils'
import z from 'zod'
import type { Logger } from '@lifeforge/log'
import { CleanedSchemas } from '../../utils/schemaUtils'
import IPBService from '../pb/PBService.interface'
import { CollectionKey } from '../pb/pb_service.types'
import { ITempFileManagerConstructor } from './tempfile_manager.types'

View File

@@ -3,7 +3,9 @@
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ESNext"],
"lib": [
"ESNext"
],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
@@ -15,8 +17,15 @@
"isolatedModules": true,
"noEmit": false,
"emitDeclarationOnly": true,
"baseUrl": "./src"
"types": [
"Multer"
]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}

2985
packages/ui/contract.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -23,8 +23,8 @@
},
"scripts": {
"dev": "storybook dev -p 6006",
"types": "tsc -b",
"build": "tsc -b && rm -rf dist && vite build",
"types": "tsgo -b",
"build": "tsgo -b && rm -rf dist && vite build",
"build-storybook": "cd ../../api && bun run build && cd ../packages/ui && storybook build"
},
"dependencies": {

View File

@@ -1,8 +1,8 @@
import { Icon, loadIcon } from '@iconify/react'
import { loadIcon } from '@iconify/react'
import { useEffect, useState } from 'react'
import type { InputVariant } from '@/components/inputs/shared/types'
import { Box } from '@/components/primitives'
import { Box, Icon } from '@/components/primitives'
import * as styles from '../IconInput.css'
@@ -52,10 +52,7 @@ export function IconPreview({
>
<Icon
icon={value && iconExists ? value : 'tabler:question-mark'}
style={{
height: variant === 'plain' ? '1.5em' : '1em',
width: variant === 'plain' ? '1.5em' : '1em'
}}
size={variant === 'plain' ? '1.5em' : '1em'}
/>
</span>
</Box>

View File

@@ -14,7 +14,7 @@
"type": "module",
"main": "./dist/server.js",
"scripts": {
"types": "tsc -b",
"types": "tsgo -b",
"build": "bun types && bun build ./src/index.ts --target bun --minify --production --outfile=./dist/server.js",
"start": "bun types && NODE_ENV=production bun --env-file=../env/.env.local ./src/index.ts",
"start:prod": "NODE_ENV=production bun ./dist/server.js",

View File

@@ -132,7 +132,12 @@ writeContractFileToClient(
)
writeContractFileToClient(
coreRoutes,
path.resolve(import.meta.dirname, '../../../../packages/ui/src'),
path.resolve(import.meta.dirname, '../../../../packages/ui'),
'.'
)
writeContractFileToClient(
coreRoutes,
path.resolve(import.meta.dirname, '../../../../packages/api'),
'.'
)