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,SAAA,GAAY,cAAc,OAAO,CAAA;AACvC,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,SAAS,CAAA,CAAE,CAAC,CAAA;AACnC","file":"chatbot-shared-utils.mjs","sourcesContent":["/**\n * These utilities are meant to be shared both client and server.\n * Don't add anything that can't be shared (especially dependencies)\n */\n\nimport type { ChatApp, ChatAppFeature, FeatureIdType } from '../types/chatbot/chatbot-types';\nimport camelcaseKeys from 'camelcase-keys';\nimport snakecaseKeys from 'snakecase-keys';\n\n/**\n * Generate a unique S3 key name for a chat file upload.\n *\n * Use the uuid module to generate the v7 uuid as in\n *\n * Replace punctation that isn't _ or - with a _\n *\n * import { v7 as uuidv7 } from 'uuid';\n * uuidv7()\n *\n * @param userId - The user id of the user uploading the file\n * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName\n * @param v7Uuid - The uuidv7 uuid of the file\n * @returns The S3 key name for the file\n */\nexport function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string {\n    return `uploads/${userId}/${v7Uuid}_${fileName}`;\n}\n\n/**\n * Remove all punctuation from a file name except for the ending period for the file extension if it exists\n *\n * @param fileName - The name of the file to sanitize\n * @returns The sanitized file name\n */\nexport function sanitizeFileName(fileName: string): string {\n    const lastDotIndex = fileName.lastIndexOf('.');\n\n    // If there's no dot, or the dot is at the end, or the dot is at the beginning, just remove all punctuation\n    if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {\n        return fileName.replace(/[^a-zA-Z0-9_-]/g, '');\n    }\n\n    const nameWithoutExtension = fileName.substring(0, lastDotIndex);\n    const extension = fileName.substring(lastDotIndex + 1);\n\n    const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, '');\n    const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, '');\n\n    return sanitizedName + '.' + sanitizedExtension;\n}\n\ntype ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;\n\ntype ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;\n\nexport type SnakeCase<T> = {\n    [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];\n};\n\nexport type CamelCase<T> = {\n    [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];\n};\n\nexport function convertToCamelCase<T extends object>(data: SnakeCase<T>): T {\n    return camelcaseKeys(data, { deep: true }) as unknown as T;\n}\n\nexport function convertToSnakeCase<T extends { [key: string]: any }>(data: T): SnakeCase<T> {\n    return snakecaseKeys(data, { deep: true }) as SnakeCase<T>;\n}\n\nexport function convertStringToSnakeCase(str: string): string {\n    const tempObj = { [str]: true };\n    const converted = snakecaseKeys(tempObj);\n    return Object.keys(converted)[0];\n}\n\n// /**\n//  * This lets us get a feature from a chat app and make sure it is the correct type.\n//  */\n// export function getFeature<T extends FeatureIdType>(chatApp: ChatApp, featureId: T): Extract<ChatAppFeature, { featureId: T }> | undefined {\n//     const feature = chatApp.features?.[featureId];\n\n//     if (feature && feature.featureId === featureId) {\n//         return feature as Extract<ChatAppFeature, { featureId: T }>;\n//     }\n\n//     return undefined;\n// }\n"]}