Chore/refractor (#4454)

* markdown files and env examples cleanup

* components update

* update jsonlines description

* server refractor

* update telemetry

* add execute custom node

* add ui refractor

* add username and password authenticate

* correctly retrieve past images in agentflowv2

* disable e2e temporarily

* add existing username and password authenticate

* update migration to default workspace

* update todo

* blob storage migrating

* throw error on agent tool call error

* add missing execution import

* add referral

* chore: add error message when importData is undefined

* migrate api keys to db

* fix: data too long for column executionData

* migrate api keys from json to db at init

* add info on account setup

* update docstore missing fields

---------

Co-authored-by: chungyau97 <chungyau97@gmail.com>
This commit is contained in:
Henry Heng
2025-05-27 14:29:42 +08:00
committed by GitHub
parent e35a126b46
commit 5a37227d14
560 changed files with 62127 additions and 4100 deletions
+81
View File
@@ -0,0 +1,81 @@
const getCurrentUser = () => {
if (!localStorage.getItem('user') || localStorage.getItem('user') === 'undefined') return undefined
return JSON.parse(localStorage.getItem('user'))
}
const updateCurrentUser = (user) => {
let stringifiedUser = user
if (typeof user === 'object') {
stringifiedUser = JSON.stringify(user)
}
localStorage.setItem('user', stringifiedUser)
}
const removeCurrentUser = () => {
_removeFromStorage()
clearAllCookies()
}
const _removeFromStorage = () => {
localStorage.removeItem('isAuthenticated')
localStorage.removeItem('isGlobal')
localStorage.removeItem('user')
localStorage.removeItem('permissions')
localStorage.removeItem('features')
localStorage.removeItem('isSSO')
}
const clearAllCookies = () => {
document.cookie.split(';').forEach((cookie) => {
const name = cookie.split('=')[0].trim()
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`
})
}
const extractUser = (payload) => {
const user = {
id: payload.id,
email: payload.email,
name: payload.name,
status: payload.status,
role: payload.role,
isSSO: payload.isSSO,
activeOrganizationId: payload.activeOrganizationId,
activeOrganizationSubscriptionId: payload.activeOrganizationSubscriptionId,
activeOrganizationCustomerId: payload.activeOrganizationCustomerId,
activeOrganizationProductId: payload.activeOrganizationProductId,
activeWorkspaceId: payload.activeWorkspaceId,
activeWorkspace: payload.activeWorkspace,
lastLogin: payload.lastLogin,
isOrganizationAdmin: payload.isOrganizationAdmin,
assignedWorkspaces: payload.assignedWorkspaces,
permissions: payload.permissions
}
return user
}
const updateStateAndLocalStorage = (state, payload) => {
const user = extractUser(payload)
state.user = user
state.token = payload.token
state.permissions = payload.permissions
state.features = payload.features
state.isAuthenticated = true
state.isGlobal = user.isOrganizationAdmin
localStorage.setItem('isAuthenticated', 'true')
localStorage.setItem('isGlobal', state.isGlobal)
localStorage.setItem('isSSO', state.user.isSSO)
localStorage.setItem('user', JSON.stringify(user))
localStorage.setItem('permissions', JSON.stringify(payload.permissions))
localStorage.setItem('features', JSON.stringify(payload.features))
}
const AuthUtils = {
getCurrentUser,
updateCurrentUser,
removeCurrentUser,
updateStateAndLocalStorage,
extractUser
}
export default AuthUtils
+34 -3
View File
@@ -66,6 +66,37 @@ const sanitizeAssistant = (Assistant) => {
}
}
const sanitizeCustomTemplate = (CustomTemplate) => {
try {
return CustomTemplate.map((customTemplate) => {
return { ...customTemplate, usecases: JSON.stringify(customTemplate.usecases), workspaceId: undefined }
})
} catch (error) {
throw new Error(`exportImport.sanitizeCustomTemplate ${getErrorMessage(error)}`)
}
}
const sanitizeDocumentStore = (DocumentStore) => {
try {
return DocumentStore.map((documentStore) => {
return { ...documentStore, workspaceId: undefined }
})
} catch (error) {
throw new Error(`exportImport.sanitizeDocumentStore ${getErrorMessage(error)}`)
}
}
const sanitizeExecution = (Execution) => {
try {
return Execution.map((execution) => {
execution.agentflow.workspaceId = undefined
return { ...execution, workspaceId: undefined }
})
} catch (error) {
throw new Error(`exportImport.sanitizeExecution ${getErrorMessage(error)}`)
}
}
export const stringify = (object) => {
try {
return JSON.stringify(object, null, 2)
@@ -86,10 +117,10 @@ export const exportData = (exportAllData) => {
ChatFlow: sanitizeChatflow(exportAllData.ChatFlow),
ChatMessage: exportAllData.ChatMessage,
ChatMessageFeedback: exportAllData.ChatMessageFeedback,
CustomTemplate: exportAllData.CustomTemplate,
DocumentStore: exportAllData.DocumentStore,
CustomTemplate: sanitizeCustomTemplate(exportAllData.CustomTemplate),
DocumentStore: sanitizeDocumentStore(exportAllData.DocumentStore),
DocumentStoreFileChunk: exportAllData.DocumentStoreFileChunk,
Execution: exportAllData.Execution,
Execution: sanitizeExecution(exportAllData.Execution),
Tool: sanitizeTool(exportAllData.Tool),
Variable: sanitizeVariable(exportAllData.Variable)
}
+12
View File
@@ -982,6 +982,18 @@ export const kFormatter = (num) => {
return item ? (num / item.value).toFixed(1).replace(regexp, '').concat(item.symbol) : '0'
}
export const redirectWhenUnauthorized = ({ error, redirectTo }) => {
if (error === 'unauthorized') {
window.location.href = redirectTo
} else if (error === 'subscription_canceled') {
window.location.href = `${redirectTo}?error=${error}`
}
}
export const truncateString = (str, maxLength) => {
return str.length > maxLength ? `${str.slice(0, maxLength - 3)}...` : str
}
const toCamelCase = (str) => {
return str
.split(' ') // Split by space to process each word
+17
View File
@@ -0,0 +1,17 @@
import { z } from 'zod'
export const passwordSchema = z
.string()
.min(8, 'Password must be at least 8 characters')
.regex(/[a-z]/, 'Password must contain at least one lowercase letter')
.regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
.regex(/\d/, 'Password must contain at least one digit')
.regex(/[@$!%*?&-]/, 'Password must contain at least one special character (@$!%*?&-)')
export const validatePassword = (password) => {
const result = passwordSchema.safeParse(password)
if (!result.success) {
return result.error.errors.map((err) => err.message)
}
return []
}