diff --git a/api/Dockerfile b/api/Dockerfile index c35c2d60..7143bcbb 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -18,12 +18,12 @@ WORKDIR /app COPY package*.json ./ +COPY --from=builder /app/node_modules ./node_modules + COPY --from=builder /app/src/extensions ./src/extensions COPY --from=builder /app/patches ./patches -RUN npm install - COPY . . ENV NODE_ENV=development diff --git a/api/package-lock.json b/api/package-lock.json index aa96393b..edff421b 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -1,12 +1,12 @@ { "name": "hexabot", - "version": "2.1.9", + "version": "2.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "hexabot", - "version": "2.1.9", + "version": "2.2.0", "hasInstallScript": true, "license": "AGPL-3.0-only", "dependencies": { diff --git a/api/package.json b/api/package.json index 43a78026..227d3800 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "hexabot", - "version": "2.1.9", + "version": "2.2.0", "description": "Hexabot is a solution for creating and managing chatbots across multiple channels, leveraging AI for advanced conversational capabilities. It provides a user-friendly interface for building, training, and deploying chatbots with integrated support for various messaging platforms.", "author": "Hexastack", "license": "AGPL-3.0-only", @@ -178,4 +178,4 @@ "@/(.*)": "/$1" } } -} \ No newline at end of file +} diff --git a/api/src/channel/lib/Handler.ts b/api/src/channel/lib/Handler.ts index a803ae5b..e1dd33ef 100644 --- a/api/src/channel/lib/Handler.ts +++ b/api/src/channel/lib/Handler.ts @@ -235,6 +235,19 @@ export default abstract class ChannelHandler< event: EventWrapper, ): Promise; + /** + * Fetch the subscriber profile data + * + * @deprecated + * @param event - The message event received + * @returns {Promise} - The channel's response, otherwise an error + */ + async getUserData( + event: EventWrapper, + ): Promise { + return await this.getSubscriberData(event); + } + /** * Fetch the subscriber profile data * diff --git a/api/src/chat/repositories/subscriber.repository.ts b/api/src/chat/repositories/subscriber.repository.ts index 817f6810..3950e656 100644 --- a/api/src/chat/repositories/subscriber.repository.ts +++ b/api/src/chat/repositories/subscriber.repository.ts @@ -82,6 +82,10 @@ export class SubscriberRepository extends BaseRepository< const oldSubscriber = await this.findOne(criteria); + if (!oldSubscriber) { + throw new Error('Something went wrong: subscriber does not exist'); + } + if (subscriberUpdates.assignedTo !== oldSubscriber?.assignedTo) { this.eventEmitter.emit( 'hook:subscriber:assign', diff --git a/api/src/chat/schemas/types/attachment.ts b/api/src/chat/schemas/types/attachment.ts index cdf02e5f..bb52b303 100644 --- a/api/src/chat/schemas/types/attachment.ts +++ b/api/src/chat/schemas/types/attachment.ts @@ -31,7 +31,11 @@ export type AttachmentRef = url: string; }; -export interface AttachmentPayload { +/** IMPORTANT: No need to use generic type here */ +export interface AttachmentPayload { type: FileType; - payload: AttachmentRef; + payload: T; } + +/** @deprecated */ +export type WithUrl = A & { url?: string }; diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 6becd3ae..449ee683 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -52,6 +52,9 @@ COPY ./widget ./widget RUN npm install + +# used to by pass Next.js paching lock file +ENV NEXT_IGNORE_INCORRECT_LOCKFILE=true ENV NODE_ENV=development ENV CHOKIDAR_USEPOLLING=true ENV WATCHPACK_POLLING=true @@ -64,6 +67,8 @@ CMD ["npm", "run", "dev", "--", "-p", "8080"] FROM base AS production WORKDIR /app +# used to by pass Next.js paching lock file +ENV NEXT_IGNORE_INCORRECT_LOCKFILE=true ENV NODE_ENV=production # Uncomment the following line in case you want to disable telemetry during runtime. ENV NEXT_TELEMETRY_DISABLED 1 diff --git a/frontend/package.json b/frontend/package.json index 689a162e..beb2aafa 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "hexabot-ui", "private": true, - "version": "2.1.9", + "version": "2.2.0", "description": "Hexabot is a solution for creating and managing chatbots across multiple channels, leveraging AI for advanced conversational capabilities. It provides a user-friendly interface for building, training, and deploying chatbots with integrated support for various messaging platforms.", "author": "Hexastack", "license": "AGPL-3.0-only", diff --git a/frontend/src/contexts/auth.context.tsx b/frontend/src/contexts/auth.context.tsx index 2c7e39d5..dfdc1089 100644 --- a/frontend/src/contexts/auth.context.tsx +++ b/frontend/src/contexts/auth.context.tsx @@ -1,30 +1,27 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import getConfig from "next/config"; import { useRouter } from "next/router"; -import { useState, useEffect, createContext, ReactNode } from "react"; +import { createContext, ReactNode, useEffect, useState } from "react"; import { - useQueryClient, - useQuery, QueryObserverResult, RefetchOptions, UseMutateFunction, + useQuery, + useQueryClient, } from "react-query"; import { Progress } from "@/app-components/displays/Progress"; import { useLogout } from "@/hooks/entities/auth-hooks"; import { useApiClient } from "@/hooks/useApiClient"; -import { - useLogoutRedirection, - CURRENT_USER_KEY, - PUBLIC_PATHS, -} from "@/hooks/useAuth"; +import { CURRENT_USER_KEY, PUBLIC_PATHS } from "@/hooks/useAuth"; import { useToast } from "@/hooks/useToast"; import { useTranslate } from "@/hooks/useTranslate"; import { RouterType } from "@/services/types"; @@ -55,7 +52,6 @@ const { publicRuntimeConfig } = getConfig(); export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => { const router = useRouter(); - const { logoutRedirection } = useLogoutRedirection(); const [search, setSearch] = useState(""); const hasPublicPath = PUBLIC_PATHS.includes(router.pathname); const { i18n, t } = useTranslate(); @@ -67,10 +63,8 @@ export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => { }; const { mutateAsync: logoutSession } = useLogout(); const logout = async () => { - queryClient.removeQueries([CURRENT_USER_KEY]); updateLanguage(publicRuntimeConfig.lang.default); await logoutSession(); - logoutRedirection(); toast.success(t("message.logout_success")); }; const authRedirection = async (isAuthenticated: boolean) => { @@ -79,8 +73,10 @@ export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => { const nextPage = redirect && decodeURIComponent(redirect); if (nextPage?.startsWith("/")) { - router.push(nextPage); - } else if (hasPublicPath) router.push(RouterType.HOME); + await router.push(nextPage); + } else if (hasPublicPath) { + await router.push(RouterType.HOME); + } } }; const { apiClient } = useApiClient(); diff --git a/frontend/src/hooks/entities/auth-hooks.ts b/frontend/src/hooks/entities/auth-hooks.ts index d6127003..c1fa01a1 100755 --- a/frontend/src/hooks/entities/auth-hooks.ts +++ b/frontend/src/hooks/entities/auth-hooks.ts @@ -6,7 +6,6 @@ * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ - import { useEffect } from "react"; import { useMutation, useQuery, useQueryClient } from "react-query"; @@ -22,7 +21,7 @@ import { useSocket } from "@/websocket/socket-hooks"; import { useFind } from "../crud/useFind"; import { useApiClient } from "../useApiClient"; -import { useAuth } from "../useAuth"; +import { CURRENT_USER_KEY, useAuth, useLogoutRedirection } from "../useAuth"; export const useLogin = ( options?: Omit< @@ -51,8 +50,10 @@ export const useLogout = ( "mutationFn" >, ) => { + const queryClient = useQueryClient(); const { apiClient } = useApiClient(); const { socket } = useSocket(); + const { logoutRedirection } = useLogoutRedirection(); return useMutation({ ...options, @@ -61,7 +62,10 @@ export const useLogout = ( return await apiClient.logout(); }, - onSuccess: () => {}, + onSuccess: async () => { + queryClient.removeQueries([CURRENT_USER_KEY]); + await logoutRedirection(); + }, }); }; diff --git a/frontend/src/hooks/useApiClient.ts b/frontend/src/hooks/useApiClient.ts index ca7fc2b1..346ad7f7 100644 --- a/frontend/src/hooks/useApiClient.ts +++ b/frontend/src/hooks/useApiClient.ts @@ -45,7 +45,7 @@ export const useAxiosInstance = () => { // Response Interceptor instance.interceptors.response.use( (resp) => resp, - (error) => { + async (error) => { if (!error.response) { // Optionally redirect to an error page or show a notification toast.error(t("message.network_error")); @@ -53,7 +53,7 @@ export const useAxiosInstance = () => { return Promise.reject(new Error("Network error")); } if (error.response.status === 401) { - logoutRedirection(true); + await logoutRedirection(true); } return Promise.reject(error.response.data); diff --git a/package-lock.json b/package-lock.json index 6a174930..6fb4641e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,7 @@ }, "frontend": { "name": "hexabot-ui", - "version": "2.1.9", + "version": "2.2.0", "license": "AGPL-3.0-only", "dependencies": { "@chatscope/chat-ui-kit-react": "^2.0.3", @@ -10304,7 +10304,7 @@ }, "widget": { "name": "hexabot-chat-widget", - "version": "2.1.9", + "version": "2.2.0", "license": "AGPL-3.0-only", "dependencies": { "@types/emoji-js": "^3.5.2", diff --git a/package.json b/package.json index aba70e0a..7e2aea6f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "frontend", "widget" ], - "version": "2.1.9", + "version": "2.2.0", "description": "Hexabot is a solution for creating and managing chatbots across multiple channels, leveraging AI for advanced conversational capabilities. It provides a user-friendly interface for building, training, and deploying chatbots with integrated support for various messaging platforms.", "author": "Hexastack", "license": "AGPL-3.0-only", diff --git a/widget/package.json b/widget/package.json index bedf97bb..01516fa9 100644 --- a/widget/package.json +++ b/widget/package.json @@ -1,6 +1,6 @@ { "name": "hexabot-chat-widget", - "version": "2.1.9", + "version": "2.2.0", "description": "Hexabot is a solution for creating and managing chatbots across multiple channels, leveraging AI for advanced conversational capabilities. It provides a user-friendly interface for building, training, and deploying chatbots with integrated support for various messaging platforms.", "author": "Hexastack", "license": "AGPL-3.0-only",