From c722b85d5ddde84cd6bf3fbb64a07848a0104fd3 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Sat, 26 Oct 2024 09:02:34 +0100 Subject: [PATCH] fix: express session --- api/package.json | 7 ++++++- api/src/channel/lib/Handler.ts | 1 + api/src/channel/types.ts | 1 + api/src/extensions/channels/web/base-web-channel.ts | 2 +- api/src/global.d.ts | 13 +++++++++++++ api/src/helper/lib/base-helper.ts | 1 + api/src/helper/types.ts | 1 + api/src/utils/generics/extension.ts | 2 +- api/src/utils/types/extension.ts | 3 +++ api/tsconfig.json | 1 + api/{src/index.d.ts => types/express-session.d.ts} | 7 ------- 11 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 api/src/global.d.ts rename api/{src/index.d.ts => types/express-session.d.ts} (87%) diff --git a/api/package.json b/api/package.json index f5b370fe..07f04137 100644 --- a/api/package.json +++ b/api/package.json @@ -5,6 +5,11 @@ "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", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], "scripts": { "postinstall": "patch-package", "build:clean": "rm -rf src/.hexabot", @@ -167,4 +172,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 4b265b23..2c8d2e0f 100644 --- a/api/src/channel/lib/Handler.ts +++ b/api/src/channel/lib/Handler.ts @@ -20,6 +20,7 @@ import { import { LoggerService } from '@/logger/logger.service'; import { SettingService } from '@/setting/services/setting.service'; import { Extension } from '@/utils/generics/extension'; +import { HyphenToUnderscore } from '@/utils/types/extension'; import { SocketRequest } from '@/websocket/utils/socket-request'; import { SocketResponse } from '@/websocket/utils/socket-response'; diff --git a/api/src/channel/types.ts b/api/src/channel/types.ts index c9174321..0c654f19 100644 --- a/api/src/channel/types.ts +++ b/api/src/channel/types.ts @@ -7,6 +7,7 @@ */ import { SettingCreateDto } from '@/setting/dto/setting.dto'; +import { HyphenToUnderscore } from '@/utils/types/extension'; export type ChannelName = `${string}-channel`; diff --git a/api/src/extensions/channels/web/base-web-channel.ts b/api/src/extensions/channels/web/base-web-channel.ts index 59e70f07..2ff785df 100644 --- a/api/src/extensions/channels/web/base-web-channel.ts +++ b/api/src/extensions/channels/web/base-web-channel.ts @@ -299,7 +299,7 @@ export default abstract class BaseWebChannelHandler< */ private async verifyToken(verificationToken: string) { const settings = - (await this.getSettings()) as Settings[typeof WEB_CHANNEL_NAMESPACE]; + (await this.getSettings()) as unknown as Settings[typeof WEB_CHANNEL_NAMESPACE]; const verifyToken = settings.verification_token; if (!verifyToken) { diff --git a/api/src/global.d.ts b/api/src/global.d.ts new file mode 100644 index 00000000..b6c42a96 --- /dev/null +++ b/api/src/global.d.ts @@ -0,0 +1,13 @@ +/* + * Copyright © 2024 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). + */ + +declare global { + type HyphenToUnderscore = S extends `${infer P}-${infer Q}` + ? `${P}_${HyphenToUnderscore}` + : S; +} diff --git a/api/src/helper/lib/base-helper.ts b/api/src/helper/lib/base-helper.ts index 4ef91ad0..1c46f0ac 100644 --- a/api/src/helper/lib/base-helper.ts +++ b/api/src/helper/lib/base-helper.ts @@ -12,6 +12,7 @@ import { LoggerService, OnModuleInit } from '@nestjs/common'; import { SettingService } from '@/setting/services/setting.service'; import { Extension } from '@/utils/generics/extension'; +import { HyphenToUnderscore } from '@/utils/types/extension'; import { HelperService } from '../helper.service'; import { HelperName, HelperSetting, HelperType } from '../types'; diff --git a/api/src/helper/types.ts b/api/src/helper/types.ts index 7692c5a9..2e6a7256 100644 --- a/api/src/helper/types.ts +++ b/api/src/helper/types.ts @@ -7,6 +7,7 @@ */ import { SettingCreateDto } from '@/setting/dto/setting.dto'; +import { HyphenToUnderscore } from '@/utils/types/extension'; import BaseHelper from './lib/base-helper'; import BaseLlmHelper from './lib/base-llm-helper'; diff --git a/api/src/utils/generics/extension.ts b/api/src/utils/generics/extension.ts index 7b530f7f..5d0b3be9 100644 --- a/api/src/utils/generics/extension.ts +++ b/api/src/utils/generics/extension.ts @@ -13,7 +13,7 @@ import { OnModuleInit } from '@nestjs/common'; import { I18nJsonLoader, I18nTranslation } from 'nestjs-i18n'; import { Observable } from 'rxjs'; -import { ExtensionName } from '../types/extension'; +import { ExtensionName, HyphenToUnderscore } from '../types/extension'; export abstract class Extension implements OnModuleInit { private translations: I18nTranslation | Observable; diff --git a/api/src/utils/types/extension.ts b/api/src/utils/types/extension.ts index 07ac62d5..feda082d 100644 --- a/api/src/utils/types/extension.ts +++ b/api/src/utils/types/extension.ts @@ -11,3 +11,6 @@ import { HelperName } from '@/helper/types'; import { PluginName } from '@/plugins/types'; export type ExtensionName = ChannelName | HelperName | PluginName; + +export type HyphenToUnderscore = + S extends `${infer P}-${infer Q}` ? `${P}_${HyphenToUnderscore}` : S; diff --git a/api/tsconfig.json b/api/tsconfig.json index d6f2c639..81fbd472 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -26,6 +26,7 @@ }, "include": [ "src/**/*.ts", + "src/global.d.ts", "types/**/*.d.ts", "src/**/*.json", "test/**/*.ts", diff --git a/api/src/index.d.ts b/api/types/express-session.d.ts similarity index 87% rename from api/src/index.d.ts rename to api/types/express-session.d.ts index 08851b37..7039765a 100644 --- a/api/src/index.d.ts +++ b/api/types/express-session.d.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 'mongoose'; import { SubscriberStub } from './chat/schemas/subscriber.schema'; declare module 'express-session' { @@ -41,9 +40,3 @@ declare module 'express-session' { }; } } - -declare global { - type HyphenToUnderscore = S extends `${infer P}-${infer Q}` - ? `${P}_${HyphenToUnderscore}` - : S; -}