From f3af07b7ffb660bd9040e1f08839ab3809a5683d Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 15 Mar 2023 12:21:52 +0100 Subject: [PATCH] :recycle: (viewer) Remove barrel exports and flatten folder arch --- apps/docs/package.json | 2 +- apps/viewer/src/components/TypebotPageV2.tsx | 7 +- apps/viewer/src/features/answers/index.ts | 1 - apps/viewer/src/features/auth/api/index.ts | 1 - ...injectVariableValuesInButtonsInputBlock.ts | 4 +- .../features/blocks/inputs/date/api/index.ts | 1 - .../blocks/inputs/date/api/utils/index.ts | 1 - .../date/{api/utils => }/parseReadableDate.ts | 0 .../features/blocks/inputs/email/api/index.ts | 1 - .../blocks/inputs/email/api/utils/index.ts | 1 - .../email/{api/utils => }/validateEmail.ts | 0 .../blocks/inputs/payment/api/index.ts | 1 - .../blocks/inputs/payment/api/utils/index.ts | 1 - .../computePaymentInputRuntimeOptions.ts | 2 +- .../features/blocks/inputs/phone/api/index.ts | 1 - .../blocks/inputs/phone/api/utils/index.ts | 2 - .../{api/utils => }/formatPhoneNumber.ts | 0 .../{api/utils => }/validatePhoneNumber.ts | 0 .../features/blocks/inputs/url/api/index.ts | 1 - .../inputs/url/{api/utils => }/validateUrl.ts | 0 .../blocks/integrations/chatwoot/api/index.ts | 1 - .../{api/utils => }/executeChatwootBlock.ts | 12 +- .../integrations/googleAnalytics/api/index.ts | 1 - .../utils => }/executeGoogleAnalyticsBlock.ts | 6 +- .../integrations/googleSheets/api/index.ts | 1 - .../googleSheets/api/utils/index.ts | 1 - .../utils => }/executeGoogleSheetBlock.ts | 4 +- .../googleSheets/{api/utils => }/getRow.ts | 11 +- .../getAuthenticatedGoogleDoc.ts} | 14 -- .../googleSheets/helpers/parseCellValues.ts | 14 ++ .../googleSheets/{api/utils => }/insertRow.ts | 8 +- .../googleSheets/{api/utils => }/updateRow.ts | 12 +- .../openai/createChatCompletionOpenAI.ts | 5 +- .../integrations/sendEmail/api/index.ts | 1 - .../sendEmail/{api => }/constants.ts | 0 .../{api/utils => }/executeSendEmailBlock.tsx | 9 +- .../blocks/integrations/webhook/api/index.ts | 1 - .../integrations/webhook/api/utils/index.ts | 2 - .../{api/utils => }/executeWebhookBlock.ts | 8 +- .../{api/utils => }/parseSampleResult.ts | 0 .../blocks/logic/condition/api/index.ts | 1 - .../{api/utils => }/executeCondition.ts | 5 +- .../blocks/logic/jump/executeJumpBlock.ts | 4 +- .../blocks/logic/redirect/api/index.ts | 1 - .../{api/utils => }/executeRedirect.ts | 4 +- .../blocks/logic/script/executeScript.ts | 12 +- .../blocks/logic/setVariable/api/index.ts | 1 - .../{api/utils => }/executeSetVariable.ts | 12 +- .../blocks/logic/typebotLink/api/index.ts | 1 - .../logic/typebotLink/api/utils/index.ts | 3 - .../{api/utils => }/executeTypebotLink.ts | 6 +- .../{api/utils => }/getLinkedTypebots.ts | 0 .../utils => }/getLinkedTypebotsChildren.ts | 2 +- .../logic/wait/{api/utils => }/executeWait.ts | 4 +- .../src/features/chat/api/chatRouter.ts | 6 - apps/viewer/src/features/chat/api/index.ts | 2 - .../src/features/chat/api/procedures/index.ts | 1 - apps/viewer/src/features/chat/api/router.ts | 6 + ...sendMessageProcedure.ts => sendMessage.ts} | 26 +- .../utils => helpers}/addEdgeToTypebot.ts | 0 .../{api/utils => helpers}/continueBotFlow.ts | 13 +- .../{api/utils => helpers}/executeGroup.ts | 12 +- .../utils => helpers}/executeIntegration.ts | 12 +- .../{api/utils => helpers}/executeLogic.ts | 12 +- .../{api/utils => helpers}/getNextGroup.ts | 0 .../{api/utils => helpers}/getSessionState.ts | 0 .../chat/{api/utils => helpers}/index.ts | 0 .../{api/utils => helpers}/startBotFlow.ts | 0 apps/viewer/src/features/chat/index.ts | 1 - apps/viewer/src/features/logs/api/index.ts | 2 - .../features/logs/{api => }/saveErrorLog.ts | 2 +- .../logs/{api/utils.ts => saveLog.ts} | 0 .../features/logs/{api => }/saveSuccessLog.ts | 2 +- apps/viewer/src/features/results/index.ts | 1 - .../src/features/results/queries/index.ts | 2 - .../usage/{utils => }/checkChatsUsage.ts | 0 apps/viewer/src/features/usage/index.ts | 1 - apps/viewer/src/features/usage/utils/index.ts | 1 - .../features/variables/deepParseVariable.ts | 28 +++ .../variables/extractVariablesFromText.ts | 15 ++ .../variables/findUniqueVariableValue.ts | 12 + .../src/features/variables/hasVariable.ts | 1 + apps/viewer/src/features/variables/index.ts | 1 - .../injectVariablesFromExistingResult.ts | 17 ++ .../variables/parseGuessedValueType.ts | 20 ++ .../src/features/variables/parseVariables.ts | 40 +++ .../features/variables/prefillVariables.ts | 15 ++ .../src/features/variables/safeStringify.ts | 12 + .../src/features/variables/updateVariables.ts | 77 ++++++ apps/viewer/src/features/variables/utils.ts | 229 ------------------ .../src/{utils => helpers}/api/dbRules.ts | 0 .../auth/api => helpers}/authenticateUser.ts | 0 .../src/{utils => helpers}/server/context.ts | 0 .../server/generateOpenApi.ts | 0 .../server/routers/v1/_app.ts | 2 +- .../src/{utils => helpers}/server/trpc.ts | 0 .../src/{utils => helpers}/sessionStorage.ts | 0 .../[spreadsheetId]/sheets/[sheetId].ts | 3 +- .../stripe/createPaymentIntent.ts | 2 +- apps/viewer/src/pages/api/typebots.ts | 2 +- .../blocks/[blockId]/executeWebhook.ts | 13 +- .../blocks/[blockId]/sampleResult.ts | 6 +- .../[blockId]/steps/[stepId]/sampleResult.ts | 6 +- .../steps/[stepId]/subscribeWebhook.ts | 2 +- .../steps/[stepId]/unsubscribeWebhook.ts | 2 +- .../blocks/[blockId]/subscribeWebhook.ts | 2 +- .../blocks/[blockId]/unsubscribeWebhook.ts | 2 +- .../[typebotId]/integrations/email.tsx | 5 +- .../pages/api/typebots/[typebotId]/results.ts | 4 +- .../api/typebots/[typebotId]/webhookBlocks.ts | 2 +- .../api/typebots/[typebotId]/webhookSteps.ts | 2 +- apps/viewer/src/pages/api/users/me.ts | 2 +- apps/viewer/src/pages/api/v1/[...trpc].ts | 4 +- 113 files changed, 398 insertions(+), 426 deletions(-) delete mode 100644 apps/viewer/src/features/answers/index.ts delete mode 100644 apps/viewer/src/features/auth/api/index.ts rename apps/viewer/src/features/blocks/inputs/buttons/{api/utils => }/injectVariableValuesInButtonsInputBlock.ts (87%) delete mode 100644 apps/viewer/src/features/blocks/inputs/date/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/inputs/date/api/utils/index.ts rename apps/viewer/src/features/blocks/inputs/date/{api/utils => }/parseReadableDate.ts (100%) delete mode 100644 apps/viewer/src/features/blocks/inputs/email/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/inputs/email/api/utils/index.ts rename apps/viewer/src/features/blocks/inputs/email/{api/utils => }/validateEmail.ts (100%) delete mode 100644 apps/viewer/src/features/blocks/inputs/payment/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/inputs/payment/api/utils/index.ts rename apps/viewer/src/features/blocks/inputs/payment/{api/utils => }/computePaymentInputRuntimeOptions.ts (98%) delete mode 100644 apps/viewer/src/features/blocks/inputs/phone/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/inputs/phone/api/utils/index.ts rename apps/viewer/src/features/blocks/inputs/phone/{api/utils => }/formatPhoneNumber.ts (100%) rename apps/viewer/src/features/blocks/inputs/phone/{api/utils => }/validatePhoneNumber.ts (100%) delete mode 100644 apps/viewer/src/features/blocks/inputs/url/api/index.ts rename apps/viewer/src/features/blocks/inputs/url/{api/utils => }/validateUrl.ts (100%) delete mode 100644 apps/viewer/src/features/blocks/integrations/chatwoot/api/index.ts rename apps/viewer/src/features/blocks/integrations/chatwoot/{api/utils => }/executeChatwootBlock.ts (87%) delete mode 100644 apps/viewer/src/features/blocks/integrations/googleAnalytics/api/index.ts rename apps/viewer/src/features/blocks/integrations/googleAnalytics/{api/utils => }/executeGoogleAnalyticsBlock.ts (63%) delete mode 100644 apps/viewer/src/features/blocks/integrations/googleSheets/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/index.ts rename apps/viewer/src/features/blocks/integrations/googleSheets/{api/utils => }/executeGoogleSheetBlock.ts (93%) rename apps/viewer/src/features/blocks/integrations/googleSheets/{api/utils => }/getRow.ts (91%) rename apps/viewer/src/features/blocks/integrations/googleSheets/{api/utils/helpers.ts => helpers/getAuthenticatedGoogleDoc.ts} (63%) create mode 100644 apps/viewer/src/features/blocks/integrations/googleSheets/helpers/parseCellValues.ts rename apps/viewer/src/features/blocks/integrations/googleSheets/{api/utils => }/insertRow.ts (80%) rename apps/viewer/src/features/blocks/integrations/googleSheets/{api/utils => }/updateRow.ts (79%) delete mode 100644 apps/viewer/src/features/blocks/integrations/sendEmail/api/index.ts rename apps/viewer/src/features/blocks/integrations/sendEmail/{api => }/constants.ts (100%) rename apps/viewer/src/features/blocks/integrations/sendEmail/{api/utils => }/executeSendEmailBlock.tsx (94%) delete mode 100644 apps/viewer/src/features/blocks/integrations/webhook/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/integrations/webhook/api/utils/index.ts rename apps/viewer/src/features/blocks/integrations/webhook/{api/utils => }/executeWebhookBlock.ts (96%) rename apps/viewer/src/features/blocks/integrations/webhook/{api/utils => }/parseSampleResult.ts (100%) delete mode 100644 apps/viewer/src/features/blocks/logic/condition/api/index.ts rename apps/viewer/src/features/blocks/logic/condition/{api/utils => }/executeCondition.ts (93%) delete mode 100644 apps/viewer/src/features/blocks/logic/redirect/api/index.ts rename apps/viewer/src/features/blocks/logic/redirect/{api/utils => }/executeRedirect.ts (83%) delete mode 100644 apps/viewer/src/features/blocks/logic/setVariable/api/index.ts rename apps/viewer/src/features/blocks/logic/setVariable/{api/utils => }/executeSetVariable.ts (81%) delete mode 100644 apps/viewer/src/features/blocks/logic/typebotLink/api/index.ts delete mode 100644 apps/viewer/src/features/blocks/logic/typebotLink/api/utils/index.ts rename apps/viewer/src/features/blocks/logic/typebotLink/{api/utils => }/executeTypebotLink.ts (96%) rename apps/viewer/src/features/blocks/logic/typebotLink/{api/utils => }/getLinkedTypebots.ts (100%) rename apps/viewer/src/features/blocks/logic/typebotLink/{api/utils => }/getLinkedTypebotsChildren.ts (97%) rename apps/viewer/src/features/blocks/logic/wait/{api/utils => }/executeWait.ts (86%) delete mode 100644 apps/viewer/src/features/chat/api/chatRouter.ts delete mode 100644 apps/viewer/src/features/chat/api/index.ts delete mode 100644 apps/viewer/src/features/chat/api/procedures/index.ts create mode 100644 apps/viewer/src/features/chat/api/router.ts rename apps/viewer/src/features/chat/api/{procedures/sendMessageProcedure.ts => sendMessage.ts} (92%) rename apps/viewer/src/features/chat/{api/utils => helpers}/addEdgeToTypebot.ts (100%) rename apps/viewer/src/features/chat/{api/utils => helpers}/continueBotFlow.ts (93%) rename apps/viewer/src/features/chat/{api/utils => helpers}/executeGroup.ts (92%) rename apps/viewer/src/features/chat/{api/utils => helpers}/executeIntegration.ts (84%) rename apps/viewer/src/features/chat/{api/utils => helpers}/executeLogic.ts (85%) rename apps/viewer/src/features/chat/{api/utils => helpers}/getNextGroup.ts (100%) rename apps/viewer/src/features/chat/{api/utils => helpers}/getSessionState.ts (100%) rename apps/viewer/src/features/chat/{api/utils => helpers}/index.ts (100%) rename apps/viewer/src/features/chat/{api/utils => helpers}/startBotFlow.ts (100%) delete mode 100644 apps/viewer/src/features/chat/index.ts delete mode 100644 apps/viewer/src/features/logs/api/index.ts rename apps/viewer/src/features/logs/{api => }/saveErrorLog.ts (84%) rename apps/viewer/src/features/logs/{api/utils.ts => saveLog.ts} (100%) rename apps/viewer/src/features/logs/{api => }/saveSuccessLog.ts (84%) delete mode 100644 apps/viewer/src/features/results/index.ts delete mode 100644 apps/viewer/src/features/results/queries/index.ts rename apps/viewer/src/features/usage/{utils => }/checkChatsUsage.ts (100%) delete mode 100644 apps/viewer/src/features/usage/index.ts delete mode 100644 apps/viewer/src/features/usage/utils/index.ts create mode 100644 apps/viewer/src/features/variables/deepParseVariable.ts create mode 100644 apps/viewer/src/features/variables/extractVariablesFromText.ts create mode 100644 apps/viewer/src/features/variables/findUniqueVariableValue.ts create mode 100644 apps/viewer/src/features/variables/hasVariable.ts delete mode 100644 apps/viewer/src/features/variables/index.ts create mode 100644 apps/viewer/src/features/variables/injectVariablesFromExistingResult.ts create mode 100644 apps/viewer/src/features/variables/parseGuessedValueType.ts create mode 100644 apps/viewer/src/features/variables/parseVariables.ts create mode 100644 apps/viewer/src/features/variables/prefillVariables.ts create mode 100644 apps/viewer/src/features/variables/safeStringify.ts create mode 100644 apps/viewer/src/features/variables/updateVariables.ts delete mode 100644 apps/viewer/src/features/variables/utils.ts rename apps/viewer/src/{utils => helpers}/api/dbRules.ts (100%) rename apps/viewer/src/{features/auth/api => helpers}/authenticateUser.ts (100%) rename apps/viewer/src/{utils => helpers}/server/context.ts (100%) rename apps/viewer/src/{utils => helpers}/server/generateOpenApi.ts (100%) rename apps/viewer/src/{utils => helpers}/server/routers/v1/_app.ts (70%) rename apps/viewer/src/{utils => helpers}/server/trpc.ts (100%) rename apps/viewer/src/{utils => helpers}/sessionStorage.ts (100%) diff --git a/apps/docs/package.json b/apps/docs/package.json index 4cc9df721..b26bd78ab 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -13,7 +13,7 @@ "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", "update-search": "docker run -it --rm --env-file=.env -e \"CONFIG=$(cat docsearch-scrapper-config.json | jq -r tostring)\" algolia/docsearch-scraper", - "api:generate": "tsx --tsconfig ../builder/tsconfig.json ../builder/src/helpers/server/generateOpenApi.ts && tsx --tsconfig ../viewer/openapi.tsconfig.json ../viewer/src/utils/server/generateOpenApi.ts" + "api:generate": "tsx --tsconfig ../builder/tsconfig.json ../builder/src/helpers/server/generateOpenApi.ts && tsx --tsconfig ../viewer/openapi.tsconfig.json ../viewer/src/helpers/server/generateOpenApi.ts" }, "dependencies": { "@docusaurus/core": "2.3.1", diff --git a/apps/viewer/src/components/TypebotPageV2.tsx b/apps/viewer/src/components/TypebotPageV2.tsx index 0f3b84d1d..3a4e8ca43 100644 --- a/apps/viewer/src/components/TypebotPageV2.tsx +++ b/apps/viewer/src/components/TypebotPageV2.tsx @@ -15,13 +15,14 @@ import { } from '@typebot.io/lib' import { SEO } from './Seo' import { ErrorPage } from './ErrorPage' -import { createResultQuery, updateResultQuery } from '@/features/results' -import { upsertAnswerQuery } from '@/features/answers' import { gtmBodyElement } from '@/lib/google-tag-manager' import { getExistingResultFromSession, setResultInSession, -} from '@/utils/sessionStorage' +} from '@/helpers/sessionStorage' +import { upsertAnswerQuery } from '@/features/answers/queries/upsertAnswerQuery' +import { createResultQuery } from '@/features/results/queries/createResultQuery' +import { updateResultQuery } from '@/features/results/queries/updateResultQuery' export type TypebotPageProps = { publishedTypebot: Omit & { diff --git a/apps/viewer/src/features/answers/index.ts b/apps/viewer/src/features/answers/index.ts deleted file mode 100644 index 81e71169c..000000000 --- a/apps/viewer/src/features/answers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { upsertAnswerQuery } from './queries/upsertAnswerQuery' diff --git a/apps/viewer/src/features/auth/api/index.ts b/apps/viewer/src/features/auth/api/index.ts deleted file mode 100644 index 83c8052cd..000000000 --- a/apps/viewer/src/features/auth/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { authenticateUser } from './authenticateUser' diff --git a/apps/viewer/src/features/blocks/inputs/buttons/api/utils/injectVariableValuesInButtonsInputBlock.ts b/apps/viewer/src/features/blocks/inputs/buttons/injectVariableValuesInButtonsInputBlock.ts similarity index 87% rename from apps/viewer/src/features/blocks/inputs/buttons/api/utils/injectVariableValuesInButtonsInputBlock.ts rename to apps/viewer/src/features/blocks/inputs/buttons/injectVariableValuesInButtonsInputBlock.ts index d6178dacc..af5c990de 100644 --- a/apps/viewer/src/features/blocks/inputs/buttons/api/utils/injectVariableValuesInButtonsInputBlock.ts +++ b/apps/viewer/src/features/blocks/inputs/buttons/injectVariableValuesInButtonsInputBlock.ts @@ -1,4 +1,3 @@ -import { deepParseVariable } from '@/features/variables/utils' import { SessionState, VariableWithValue, @@ -6,6 +5,7 @@ import { ItemType, } from '@typebot.io/schemas' import { isDefined } from '@typebot.io/lib' +import { deepParseVariables } from '@/features/variables/deepParseVariable' export const injectVariableValuesInButtonsInputBlock = (variables: SessionState['typebot']['variables']) => @@ -27,5 +27,5 @@ export const injectVariableValuesInButtonsInputBlock = })), } } - return deepParseVariable(variables)(block) + return deepParseVariables(variables)(block) } diff --git a/apps/viewer/src/features/blocks/inputs/date/api/index.ts b/apps/viewer/src/features/blocks/inputs/date/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/inputs/date/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/inputs/date/api/utils/index.ts b/apps/viewer/src/features/blocks/inputs/date/api/utils/index.ts deleted file mode 100644 index 03c496897..000000000 --- a/apps/viewer/src/features/blocks/inputs/date/api/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './parseReadableDate' diff --git a/apps/viewer/src/features/blocks/inputs/date/api/utils/parseReadableDate.ts b/apps/viewer/src/features/blocks/inputs/date/parseReadableDate.ts similarity index 100% rename from apps/viewer/src/features/blocks/inputs/date/api/utils/parseReadableDate.ts rename to apps/viewer/src/features/blocks/inputs/date/parseReadableDate.ts diff --git a/apps/viewer/src/features/blocks/inputs/email/api/index.ts b/apps/viewer/src/features/blocks/inputs/email/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/inputs/email/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/inputs/email/api/utils/index.ts b/apps/viewer/src/features/blocks/inputs/email/api/utils/index.ts deleted file mode 100644 index 95e4487d0..000000000 --- a/apps/viewer/src/features/blocks/inputs/email/api/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './validateEmail' diff --git a/apps/viewer/src/features/blocks/inputs/email/api/utils/validateEmail.ts b/apps/viewer/src/features/blocks/inputs/email/validateEmail.ts similarity index 100% rename from apps/viewer/src/features/blocks/inputs/email/api/utils/validateEmail.ts rename to apps/viewer/src/features/blocks/inputs/email/validateEmail.ts diff --git a/apps/viewer/src/features/blocks/inputs/payment/api/index.ts b/apps/viewer/src/features/blocks/inputs/payment/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/inputs/payment/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/inputs/payment/api/utils/index.ts b/apps/viewer/src/features/blocks/inputs/payment/api/utils/index.ts deleted file mode 100644 index 2b3c45308..000000000 --- a/apps/viewer/src/features/blocks/inputs/payment/api/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './computePaymentInputRuntimeOptions' diff --git a/apps/viewer/src/features/blocks/inputs/payment/api/utils/computePaymentInputRuntimeOptions.ts b/apps/viewer/src/features/blocks/inputs/payment/computePaymentInputRuntimeOptions.ts similarity index 98% rename from apps/viewer/src/features/blocks/inputs/payment/api/utils/computePaymentInputRuntimeOptions.ts rename to apps/viewer/src/features/blocks/inputs/payment/computePaymentInputRuntimeOptions.ts index a81d285c9..c61a3508d 100644 --- a/apps/viewer/src/features/blocks/inputs/payment/api/utils/computePaymentInputRuntimeOptions.ts +++ b/apps/viewer/src/features/blocks/inputs/payment/computePaymentInputRuntimeOptions.ts @@ -1,4 +1,4 @@ -import { parseVariables } from '@/features/variables' +import { parseVariables } from '@/features/variables/parseVariables' import prisma from '@/lib/prisma' import { TRPCError } from '@trpc/server' import { diff --git a/apps/viewer/src/features/blocks/inputs/phone/api/index.ts b/apps/viewer/src/features/blocks/inputs/phone/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/inputs/phone/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/inputs/phone/api/utils/index.ts b/apps/viewer/src/features/blocks/inputs/phone/api/utils/index.ts deleted file mode 100644 index ac546003c..000000000 --- a/apps/viewer/src/features/blocks/inputs/phone/api/utils/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './formatPhoneNumber' -export * from './validatePhoneNumber' diff --git a/apps/viewer/src/features/blocks/inputs/phone/api/utils/formatPhoneNumber.ts b/apps/viewer/src/features/blocks/inputs/phone/formatPhoneNumber.ts similarity index 100% rename from apps/viewer/src/features/blocks/inputs/phone/api/utils/formatPhoneNumber.ts rename to apps/viewer/src/features/blocks/inputs/phone/formatPhoneNumber.ts diff --git a/apps/viewer/src/features/blocks/inputs/phone/api/utils/validatePhoneNumber.ts b/apps/viewer/src/features/blocks/inputs/phone/validatePhoneNumber.ts similarity index 100% rename from apps/viewer/src/features/blocks/inputs/phone/api/utils/validatePhoneNumber.ts rename to apps/viewer/src/features/blocks/inputs/phone/validatePhoneNumber.ts diff --git a/apps/viewer/src/features/blocks/inputs/url/api/index.ts b/apps/viewer/src/features/blocks/inputs/url/api/index.ts deleted file mode 100644 index cb0513d30..000000000 --- a/apps/viewer/src/features/blocks/inputs/url/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { validateUrl } from './utils/validateUrl' diff --git a/apps/viewer/src/features/blocks/inputs/url/api/utils/validateUrl.ts b/apps/viewer/src/features/blocks/inputs/url/validateUrl.ts similarity index 100% rename from apps/viewer/src/features/blocks/inputs/url/api/utils/validateUrl.ts rename to apps/viewer/src/features/blocks/inputs/url/validateUrl.ts diff --git a/apps/viewer/src/features/blocks/integrations/chatwoot/api/index.ts b/apps/viewer/src/features/blocks/integrations/chatwoot/api/index.ts deleted file mode 100644 index b201a45e8..000000000 --- a/apps/viewer/src/features/blocks/integrations/chatwoot/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils/executeChatwootBlock' diff --git a/apps/viewer/src/features/blocks/integrations/chatwoot/api/utils/executeChatwootBlock.ts b/apps/viewer/src/features/blocks/integrations/chatwoot/executeChatwootBlock.ts similarity index 87% rename from apps/viewer/src/features/blocks/integrations/chatwoot/api/utils/executeChatwootBlock.ts rename to apps/viewer/src/features/blocks/integrations/chatwoot/executeChatwootBlock.ts index d6bcd153b..9218ddd86 100644 --- a/apps/viewer/src/features/blocks/integrations/chatwoot/api/utils/executeChatwootBlock.ts +++ b/apps/viewer/src/features/blocks/integrations/chatwoot/executeChatwootBlock.ts @@ -1,9 +1,7 @@ -import { ExecuteIntegrationResponse } from '@/features/chat' -import { - parseVariables, - parseCorrectValueType, - extractVariablesFromText, -} from '@/features/variables' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { extractVariablesFromText } from '@/features/variables/extractVariablesFromText' +import { parseGuessedValueType } from '@/features/variables/parseGuessedValueType' +import { parseVariables } from '@/features/variables/parseVariables' import { ChatwootBlock, ChatwootOptions, @@ -85,7 +83,7 @@ export const executeChatwootBlock = ( args: extractVariablesFromText(variables)(chatwootCode).map( (variable) => ({ id: variable.id, - value: parseCorrectValueType(variable.value), + value: parseGuessedValueType(variable.value), }) ), }, diff --git a/apps/viewer/src/features/blocks/integrations/googleAnalytics/api/index.ts b/apps/viewer/src/features/blocks/integrations/googleAnalytics/api/index.ts deleted file mode 100644 index 732ccefbe..000000000 --- a/apps/viewer/src/features/blocks/integrations/googleAnalytics/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { executeGoogleAnalyticsBlock } from './utils/executeGoogleAnalyticsBlock' diff --git a/apps/viewer/src/features/blocks/integrations/googleAnalytics/api/utils/executeGoogleAnalyticsBlock.ts b/apps/viewer/src/features/blocks/integrations/googleAnalytics/executeGoogleAnalyticsBlock.ts similarity index 63% rename from apps/viewer/src/features/blocks/integrations/googleAnalytics/api/utils/executeGoogleAnalyticsBlock.ts rename to apps/viewer/src/features/blocks/integrations/googleAnalytics/executeGoogleAnalyticsBlock.ts index 019c95b0b..bfaa6ac4f 100644 --- a/apps/viewer/src/features/blocks/integrations/googleAnalytics/api/utils/executeGoogleAnalyticsBlock.ts +++ b/apps/viewer/src/features/blocks/integrations/googleAnalytics/executeGoogleAnalyticsBlock.ts @@ -1,5 +1,5 @@ -import { ExecuteIntegrationResponse } from '@/features/chat' -import { deepParseVariable } from '@/features/variables' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { deepParseVariables } from '@/features/variables/deepParseVariable' import { GoogleAnalyticsBlock, SessionState } from '@typebot.io/schemas' export const executeGoogleAnalyticsBlock = ( @@ -10,7 +10,7 @@ export const executeGoogleAnalyticsBlock = ( outgoingEdgeId: block.outgoingEdgeId, clientSideActions: [ { - googleAnalytics: deepParseVariable(variables)(block.options), + googleAnalytics: deepParseVariables(variables)(block.options), lastBubbleBlockId, }, ], diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/index.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/index.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/index.ts deleted file mode 100644 index 38fbec31d..000000000 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './executeGoogleSheetBlock' diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/executeGoogleSheetBlock.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/executeGoogleSheetBlock.ts similarity index 93% rename from apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/executeGoogleSheetBlock.ts rename to apps/viewer/src/features/blocks/integrations/googleSheets/executeGoogleSheetBlock.ts index 9b82a0f4b..aa9989e1d 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/executeGoogleSheetBlock.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/executeGoogleSheetBlock.ts @@ -1,12 +1,12 @@ -import { ExecuteIntegrationResponse } from '@/features/chat' import { GoogleSheetsBlock, GoogleSheetsAction, SessionState, } from '@typebot.io/schemas' -import { getRow } from './getRow' import { insertRow } from './insertRow' import { updateRow } from './updateRow' +import { getRow } from './getRow' +import { ExecuteIntegrationResponse } from '@/features/chat/types' export const executeGoogleSheetBlock = async ( state: SessionState, diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/getRow.ts similarity index 91% rename from apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts rename to apps/viewer/src/features/blocks/integrations/googleSheets/getRow.ts index 8d12fb7a3..4a65b95e2 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/getRow.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/getRow.ts @@ -6,12 +6,13 @@ import { LogicalOperator, ReplyLog, } from '@typebot.io/schemas' -import { saveErrorLog } from '@/features/logs/api' -import { getAuthenticatedGoogleDoc } from './helpers' -import { deepParseVariable, updateVariables } from '@/features/variables' import { isNotEmpty, byId, isDefined } from '@typebot.io/lib' -import { ExecuteIntegrationResponse } from '@/features/chat' import type { GoogleSpreadsheetRow } from 'google-spreadsheet' +import { getAuthenticatedGoogleDoc } from './helpers/getAuthenticatedGoogleDoc' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { updateVariables } from '@/features/variables/updateVariables' +import { deepParseVariables } from '@/features/variables/deepParseVariable' export const getRow = async ( state: SessionState, @@ -20,7 +21,7 @@ export const getRow = async ( options, }: { outgoingEdgeId?: string; options: GoogleSheetsGetOptions } ): Promise => { - const { sheetId, cellsToExtract, referenceCell, filter } = deepParseVariable( + const { sheetId, cellsToExtract, referenceCell, filter } = deepParseVariables( state.typebot.variables )(options) if (!sheetId) return { outgoingEdgeId } diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/helpers.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/helpers/getAuthenticatedGoogleDoc.ts similarity index 63% rename from apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/helpers.ts rename to apps/viewer/src/features/blocks/integrations/googleSheets/helpers/getAuthenticatedGoogleDoc.ts index 41fb064e4..0a98a20f7 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/helpers.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/helpers/getAuthenticatedGoogleDoc.ts @@ -1,20 +1,6 @@ -import { parseVariables } from '@/features/variables' import { getAuthenticatedGoogleClient } from '@/lib/google-sheets' import { TRPCError } from '@trpc/server' import { GoogleSpreadsheet } from 'google-spreadsheet' -import { Variable, Cell } from '@typebot.io/schemas' - -export const parseCellValues = - (variables: Variable[]) => - (cells: Cell[]): { [key: string]: string } => - cells.reduce((row, cell) => { - return !cell.column || !cell.value - ? row - : { - ...row, - [cell.column]: parseVariables(variables)(cell.value), - } - }, {}) export const getAuthenticatedGoogleDoc = async ({ credentialsId, diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/helpers/parseCellValues.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/helpers/parseCellValues.ts new file mode 100644 index 000000000..f5bc60450 --- /dev/null +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/helpers/parseCellValues.ts @@ -0,0 +1,14 @@ +import { parseVariables } from '@/features/variables/parseVariables' +import { Variable, Cell } from '@typebot.io/schemas' + +export const parseCellValues = + (variables: Variable[]) => + (cells: Cell[]): { [key: string]: string } => + cells.reduce((row, cell) => { + return !cell.column || !cell.value + ? row + : { + ...row, + [cell.column]: parseVariables(variables)(cell.value), + } + }, {}) diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/insertRow.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/insertRow.ts similarity index 80% rename from apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/insertRow.ts rename to apps/viewer/src/features/blocks/integrations/googleSheets/insertRow.ts index 14f18c5b1..59204f9ad 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/insertRow.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/insertRow.ts @@ -3,9 +3,11 @@ import { GoogleSheetsInsertRowOptions, ReplyLog, } from '@typebot.io/schemas' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' -import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers' -import { ExecuteIntegrationResponse } from '@/features/chat' +import { parseCellValues } from './helpers/parseCellValues' +import { getAuthenticatedGoogleDoc } from './helpers/getAuthenticatedGoogleDoc' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' export const insertRow = async ( { result, typebot: { variables } }: SessionState, diff --git a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts b/apps/viewer/src/features/blocks/integrations/googleSheets/updateRow.ts similarity index 79% rename from apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts rename to apps/viewer/src/features/blocks/integrations/googleSheets/updateRow.ts index 670157712..05e429955 100644 --- a/apps/viewer/src/features/blocks/integrations/googleSheets/api/utils/updateRow.ts +++ b/apps/viewer/src/features/blocks/integrations/googleSheets/updateRow.ts @@ -3,11 +3,13 @@ import { GoogleSheetsUpdateRowOptions, ReplyLog, } from '@typebot.io/schemas' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' -import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers' import { TRPCError } from '@trpc/server' -import { deepParseVariable } from '@/features/variables' -import { ExecuteIntegrationResponse } from '@/features/chat' +import { parseCellValues } from './helpers/parseCellValues' +import { getAuthenticatedGoogleDoc } from './helpers/getAuthenticatedGoogleDoc' +import { deepParseVariables } from '@/features/variables/deepParseVariable' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' export const updateRow = async ( { result, typebot: { variables } }: SessionState, @@ -16,7 +18,7 @@ export const updateRow = async ( options, }: { outgoingEdgeId?: string; options: GoogleSheetsUpdateRowOptions } ): Promise => { - const { sheetId, referenceCell } = deepParseVariable(variables)(options) + const { sheetId, referenceCell } = deepParseVariables(variables)(options) if (!options.cellsToUpsert || !sheetId || !referenceCell) return { outgoingEdgeId } diff --git a/apps/viewer/src/features/blocks/integrations/openai/createChatCompletionOpenAI.ts b/apps/viewer/src/features/blocks/integrations/openai/createChatCompletionOpenAI.ts index 7ffe28237..3b3292e1f 100644 --- a/apps/viewer/src/features/blocks/integrations/openai/createChatCompletionOpenAI.ts +++ b/apps/viewer/src/features/blocks/integrations/openai/createChatCompletionOpenAI.ts @@ -1,7 +1,5 @@ import { ExecuteIntegrationResponse } from '@/features/chat/types' -import { saveErrorLog } from '@/features/logs/api' import { transformStringVariablesToList } from '@/features/variables/transformVariablesToList' -import { parseVariables, updateVariables } from '@/features/variables/utils' import prisma from '@/lib/prisma' import { SessionState, @@ -16,6 +14,9 @@ import { import { OpenAIApi, Configuration, ChatCompletionRequestMessage } from 'openai' import { isDefined, byId, isNotEmpty } from '@typebot.io/lib' import { decrypt } from '@typebot.io/lib/api/encryption' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { updateVariables } from '@/features/variables/updateVariables' +import { parseVariables } from 'bot-engine' export const createChatCompletionOpenAI = async ( state: SessionState, diff --git a/apps/viewer/src/features/blocks/integrations/sendEmail/api/index.ts b/apps/viewer/src/features/blocks/integrations/sendEmail/api/index.ts deleted file mode 100644 index 036ff7c32..000000000 --- a/apps/viewer/src/features/blocks/integrations/sendEmail/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { executeSendEmailBlock } from './utils/executeSendEmailBlock' diff --git a/apps/viewer/src/features/blocks/integrations/sendEmail/api/constants.ts b/apps/viewer/src/features/blocks/integrations/sendEmail/constants.ts similarity index 100% rename from apps/viewer/src/features/blocks/integrations/sendEmail/api/constants.ts rename to apps/viewer/src/features/blocks/integrations/sendEmail/constants.ts diff --git a/apps/viewer/src/features/blocks/integrations/sendEmail/api/utils/executeSendEmailBlock.tsx b/apps/viewer/src/features/blocks/integrations/sendEmail/executeSendEmailBlock.tsx similarity index 94% rename from apps/viewer/src/features/blocks/integrations/sendEmail/api/utils/executeSendEmailBlock.tsx rename to apps/viewer/src/features/blocks/integrations/sendEmail/executeSendEmailBlock.tsx index e07a26c2b..66e45b702 100644 --- a/apps/viewer/src/features/blocks/integrations/sendEmail/api/utils/executeSendEmailBlock.tsx +++ b/apps/viewer/src/features/blocks/integrations/sendEmail/executeSendEmailBlock.tsx @@ -1,6 +1,4 @@ -import { ExecuteIntegrationResponse } from '@/features/chat' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' -import { parseVariables } from '@/features/variables' +import { parseVariables } from '@/features/variables/parseVariables' import prisma from '@/lib/prisma' import { render } from '@faire/mjml-react/utils/render' import { DefaultBotNotificationEmail } from '@typebot.io/emails' @@ -17,7 +15,10 @@ import Mail from 'nodemailer/lib/mailer' import { byId, isEmpty, isNotDefined, omit } from '@typebot.io/lib' import { parseAnswers } from '@typebot.io/lib/results' import { decrypt } from '@typebot.io/lib/api' -import { defaultFrom, defaultTransportOptions } from '../constants' +import { defaultFrom, defaultTransportOptions } from './constants' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' export const executeSendEmailBlock = async ( { result, typebot }: SessionState, diff --git a/apps/viewer/src/features/blocks/integrations/webhook/api/index.ts b/apps/viewer/src/features/blocks/integrations/webhook/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/integrations/webhook/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/integrations/webhook/api/utils/index.ts b/apps/viewer/src/features/blocks/integrations/webhook/api/utils/index.ts deleted file mode 100644 index 6dcb2cfe3..000000000 --- a/apps/viewer/src/features/blocks/integrations/webhook/api/utils/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './executeWebhookBlock' -export * from './parseSampleResult' diff --git a/apps/viewer/src/features/blocks/integrations/webhook/api/utils/executeWebhookBlock.ts b/apps/viewer/src/features/blocks/integrations/webhook/executeWebhookBlock.ts similarity index 96% rename from apps/viewer/src/features/blocks/integrations/webhook/api/utils/executeWebhookBlock.ts rename to apps/viewer/src/features/blocks/integrations/webhook/executeWebhookBlock.ts index 6cd7d6d57..7503efe4d 100644 --- a/apps/viewer/src/features/blocks/integrations/webhook/api/utils/executeWebhookBlock.ts +++ b/apps/viewer/src/features/blocks/integrations/webhook/executeWebhookBlock.ts @@ -1,6 +1,3 @@ -import { ExecuteIntegrationResponse } from '@/features/chat' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' -import { parseVariables, updateVariables } from '@/features/variables' import prisma from '@/lib/prisma' import { WebhookBlock, @@ -26,6 +23,11 @@ import { byId, omit } from '@typebot.io/lib' import { parseAnswers } from '@typebot.io/lib/results' import got, { Method, Headers, HTTPError } from 'got' import { parseSampleResult } from './parseSampleResult' +import { ExecuteIntegrationResponse } from '@/features/chat/types' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' +import { updateVariables } from '@/features/variables/updateVariables' +import { parseVariables } from 'bot-engine' export const executeWebhookBlock = async ( state: SessionState, diff --git a/apps/viewer/src/features/blocks/integrations/webhook/api/utils/parseSampleResult.ts b/apps/viewer/src/features/blocks/integrations/webhook/parseSampleResult.ts similarity index 100% rename from apps/viewer/src/features/blocks/integrations/webhook/api/utils/parseSampleResult.ts rename to apps/viewer/src/features/blocks/integrations/webhook/parseSampleResult.ts diff --git a/apps/viewer/src/features/blocks/logic/condition/api/index.ts b/apps/viewer/src/features/blocks/logic/condition/api/index.ts deleted file mode 100644 index 5039c53db..000000000 --- a/apps/viewer/src/features/blocks/logic/condition/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { executeCondition } from './utils/executeCondition' diff --git a/apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts b/apps/viewer/src/features/blocks/logic/condition/executeCondition.ts similarity index 93% rename from apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts rename to apps/viewer/src/features/blocks/logic/condition/executeCondition.ts index 29695ea8c..44dea97ce 100644 --- a/apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts +++ b/apps/viewer/src/features/blocks/logic/condition/executeCondition.ts @@ -1,5 +1,3 @@ -import { ExecuteLogicResponse } from '@/features/chat' -import { findUniqueVariableValue, parseVariables } from '@/features/variables' import { Comparison, ComparisonOperators, @@ -9,6 +7,9 @@ import { Variable, } from '@typebot.io/schemas' import { isNotDefined, isDefined } from '@typebot.io/lib' +import { ExecuteLogicResponse } from '@/features/chat/types' +import { findUniqueVariableValue } from '@/features/variables/findUniqueVariableValue' +import { parseVariables } from 'bot-engine' export const executeCondition = ( { typebot: { variables } }: SessionState, diff --git a/apps/viewer/src/features/blocks/logic/jump/executeJumpBlock.ts b/apps/viewer/src/features/blocks/logic/jump/executeJumpBlock.ts index 16ddd6095..8a7b93a11 100644 --- a/apps/viewer/src/features/blocks/logic/jump/executeJumpBlock.ts +++ b/apps/viewer/src/features/blocks/logic/jump/executeJumpBlock.ts @@ -1,8 +1,8 @@ -import { ExecuteLogicResponse } from '@/features/chat' import { addEdgeToTypebot, createPortalEdge, -} from '@/features/chat/api/utils/addEdgeToTypebot' +} from '@/features/chat/helpers/addEdgeToTypebot' +import { ExecuteLogicResponse } from '@/features/chat/types' import { TRPCError } from '@trpc/server' import { SessionState } from '@typebot.io/schemas' import { JumpBlock } from '@typebot.io/schemas/features/blocks/logic/jump' diff --git a/apps/viewer/src/features/blocks/logic/redirect/api/index.ts b/apps/viewer/src/features/blocks/logic/redirect/api/index.ts deleted file mode 100644 index e025d4927..000000000 --- a/apps/viewer/src/features/blocks/logic/redirect/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { executeRedirect } from './utils/executeRedirect' diff --git a/apps/viewer/src/features/blocks/logic/redirect/api/utils/executeRedirect.ts b/apps/viewer/src/features/blocks/logic/redirect/executeRedirect.ts similarity index 83% rename from apps/viewer/src/features/blocks/logic/redirect/api/utils/executeRedirect.ts rename to apps/viewer/src/features/blocks/logic/redirect/executeRedirect.ts index 8860e142a..a16b478d5 100644 --- a/apps/viewer/src/features/blocks/logic/redirect/api/utils/executeRedirect.ts +++ b/apps/viewer/src/features/blocks/logic/redirect/executeRedirect.ts @@ -1,7 +1,7 @@ -import { ExecuteLogicResponse } from '@/features/chat' -import { parseVariables } from '@/features/variables' +import { parseVariables } from '@/features/variables/parseVariables' import { RedirectBlock, SessionState } from '@typebot.io/schemas' import { sanitizeUrl } from '@typebot.io/lib' +import { ExecuteLogicResponse } from '@/features/chat/types' export const executeRedirect = ( { typebot: { variables } }: SessionState, diff --git a/apps/viewer/src/features/blocks/logic/script/executeScript.ts b/apps/viewer/src/features/blocks/logic/script/executeScript.ts index 0557a5d3e..94403d45d 100644 --- a/apps/viewer/src/features/blocks/logic/script/executeScript.ts +++ b/apps/viewer/src/features/blocks/logic/script/executeScript.ts @@ -1,9 +1,7 @@ -import { ExecuteLogicResponse } from '@/features/chat' -import { - parseVariables, - parseCorrectValueType, - extractVariablesFromText, -} from '@/features/variables' +import { ExecuteLogicResponse } from '@/features/chat/types' +import { extractVariablesFromText } from '@/features/variables/extractVariablesFromText' +import { parseGuessedValueType } from '@/features/variables/parseGuessedValueType' +import { parseVariables } from '@/features/variables/parseVariables' import { ScriptBlock, SessionState } from '@typebot.io/schemas' export const executeScript = ( @@ -19,7 +17,7 @@ export const executeScript = ( const args = extractVariablesFromText(variables)(block.options.content).map( (variable) => ({ id: variable.id, - value: parseCorrectValueType(variable.value), + value: parseGuessedValueType(variable.value), }) ) diff --git a/apps/viewer/src/features/blocks/logic/setVariable/api/index.ts b/apps/viewer/src/features/blocks/logic/setVariable/api/index.ts deleted file mode 100644 index 0d41cad27..000000000 --- a/apps/viewer/src/features/blocks/logic/setVariable/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { executeSetVariable } from './utils/executeSetVariable' diff --git a/apps/viewer/src/features/blocks/logic/setVariable/api/utils/executeSetVariable.ts b/apps/viewer/src/features/blocks/logic/setVariable/executeSetVariable.ts similarity index 81% rename from apps/viewer/src/features/blocks/logic/setVariable/api/utils/executeSetVariable.ts rename to apps/viewer/src/features/blocks/logic/setVariable/executeSetVariable.ts index 781008c26..8d04f0939 100644 --- a/apps/viewer/src/features/blocks/logic/setVariable/api/utils/executeSetVariable.ts +++ b/apps/viewer/src/features/blocks/logic/setVariable/executeSetVariable.ts @@ -1,11 +1,9 @@ import { SessionState, SetVariableBlock, Variable } from '@typebot.io/schemas' import { byId } from '@typebot.io/lib' -import { - parseVariables, - parseCorrectValueType, - updateVariables, -} from '@/features/variables' -import { ExecuteLogicResponse } from '@/features/chat' +import { ExecuteLogicResponse } from '@/features/chat/types' +import { updateVariables } from '@/features/variables/updateVariables' +import { parseVariables } from '@/features/variables/parseVariables' +import { parseGuessedValueType } from '@/features/variables/parseGuessedValueType' export const executeSetVariable = async ( state: SessionState, @@ -45,7 +43,7 @@ const evaluateSetVariableExpression = ) try { const func = Function(...variables.map((v) => v.id), evaluating) - return func(...variables.map((v) => parseCorrectValueType(v.value))) + return func(...variables.map((v) => parseGuessedValueType(v.value))) } catch (err) { return parseVariables(variables)(str) } diff --git a/apps/viewer/src/features/blocks/logic/typebotLink/api/index.ts b/apps/viewer/src/features/blocks/logic/typebotLink/api/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/blocks/logic/typebotLink/api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/index.ts b/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/index.ts deleted file mode 100644 index 575d276ed..000000000 --- a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './executeTypebotLink' -export * from './getLinkedTypebots' -export * from './getLinkedTypebotsChildren' diff --git a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/executeTypebotLink.ts b/apps/viewer/src/features/blocks/logic/typebotLink/executeTypebotLink.ts similarity index 96% rename from apps/viewer/src/features/blocks/logic/typebotLink/api/utils/executeTypebotLink.ts rename to apps/viewer/src/features/blocks/logic/typebotLink/executeTypebotLink.ts index 4765422ff..f908491f2 100644 --- a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/executeTypebotLink.ts +++ b/apps/viewer/src/features/blocks/logic/typebotLink/executeTypebotLink.ts @@ -1,9 +1,7 @@ -import { ExecuteLogicResponse } from '@/features/chat' import { addEdgeToTypebot, createPortalEdge, -} from '@/features/chat/api/utils/addEdgeToTypebot' -import { saveErrorLog } from '@/features/logs/api' +} from '@/features/chat/helpers/addEdgeToTypebot' import prisma from '@/lib/prisma' import { TypebotLinkBlock, @@ -12,6 +10,8 @@ import { Variable, } from '@typebot.io/schemas' import { byId } from '@typebot.io/lib' +import { ExecuteLogicResponse } from '@/features/chat/types' +import { saveErrorLog } from '@/features/logs/saveErrorLog' export const executeTypebotLink = async ( state: SessionState, diff --git a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/getLinkedTypebots.ts b/apps/viewer/src/features/blocks/logic/typebotLink/getLinkedTypebots.ts similarity index 100% rename from apps/viewer/src/features/blocks/logic/typebotLink/api/utils/getLinkedTypebots.ts rename to apps/viewer/src/features/blocks/logic/typebotLink/getLinkedTypebots.ts diff --git a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/getLinkedTypebotsChildren.ts b/apps/viewer/src/features/blocks/logic/typebotLink/getLinkedTypebotsChildren.ts similarity index 97% rename from apps/viewer/src/features/blocks/logic/typebotLink/api/utils/getLinkedTypebotsChildren.ts rename to apps/viewer/src/features/blocks/logic/typebotLink/getLinkedTypebotsChildren.ts index 624f9fe54..d696c1cfc 100644 --- a/apps/viewer/src/features/blocks/logic/typebotLink/api/utils/getLinkedTypebotsChildren.ts +++ b/apps/viewer/src/features/blocks/logic/typebotLink/getLinkedTypebotsChildren.ts @@ -1,5 +1,5 @@ import prisma from '@/lib/prisma' -import { canReadTypebots } from '@/utils/api/dbRules' +import { canReadTypebots } from '@/helpers/api/dbRules' import { User } from '@typebot.io/prisma' import { LogicBlockType, diff --git a/apps/viewer/src/features/blocks/logic/wait/api/utils/executeWait.ts b/apps/viewer/src/features/blocks/logic/wait/executeWait.ts similarity index 86% rename from apps/viewer/src/features/blocks/logic/wait/api/utils/executeWait.ts rename to apps/viewer/src/features/blocks/logic/wait/executeWait.ts index 61747383e..f0976a8c6 100644 --- a/apps/viewer/src/features/blocks/logic/wait/api/utils/executeWait.ts +++ b/apps/viewer/src/features/blocks/logic/wait/executeWait.ts @@ -1,5 +1,5 @@ -import { ExecuteLogicResponse } from '@/features/chat' -import { parseVariables } from '@/features/variables' +import { ExecuteLogicResponse } from '@/features/chat/types' +import { parseVariables } from '@/features/variables/parseVariables' import { SessionState, WaitBlock } from '@typebot.io/schemas' export const executeWait = async ( diff --git a/apps/viewer/src/features/chat/api/chatRouter.ts b/apps/viewer/src/features/chat/api/chatRouter.ts deleted file mode 100644 index ebcf026b4..000000000 --- a/apps/viewer/src/features/chat/api/chatRouter.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { router } from '@/utils/server/trpc' -import { sendMessageProcedure } from './procedures' - -export const chatRouter = router({ - sendMessage: sendMessageProcedure, -}) diff --git a/apps/viewer/src/features/chat/api/index.ts b/apps/viewer/src/features/chat/api/index.ts deleted file mode 100644 index 7449f8a51..000000000 --- a/apps/viewer/src/features/chat/api/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './chatRouter' -export { getSession } from './utils' diff --git a/apps/viewer/src/features/chat/api/procedures/index.ts b/apps/viewer/src/features/chat/api/procedures/index.ts deleted file mode 100644 index 4a861457c..000000000 --- a/apps/viewer/src/features/chat/api/procedures/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './sendMessageProcedure' diff --git a/apps/viewer/src/features/chat/api/router.ts b/apps/viewer/src/features/chat/api/router.ts new file mode 100644 index 000000000..787e40e10 --- /dev/null +++ b/apps/viewer/src/features/chat/api/router.ts @@ -0,0 +1,6 @@ +import { router } from '@/helpers/server/trpc' +import { sendMessage } from './sendMessage' + +export const chatRouter = router({ + sendMessage, +}) diff --git a/apps/viewer/src/features/chat/api/procedures/sendMessageProcedure.ts b/apps/viewer/src/features/chat/api/sendMessage.ts similarity index 92% rename from apps/viewer/src/features/chat/api/procedures/sendMessageProcedure.ts rename to apps/viewer/src/features/chat/api/sendMessage.ts index 034e1f344..3de097009 100644 --- a/apps/viewer/src/features/chat/api/procedures/sendMessageProcedure.ts +++ b/apps/viewer/src/features/chat/api/sendMessage.ts @@ -1,12 +1,5 @@ -import { checkChatsUsage } from '@/features/usage' -import { - prefillVariables, - deepParseVariable, - parseVariables, - injectVariablesFromExistingResult, -} from '@/features/variables' import prisma from '@/lib/prisma' -import { publicProcedure } from '@/utils/server/trpc' +import { publicProcedure } from '@/helpers/server/trpc' import { TRPCError } from '@trpc/server' import { Prisma } from '@typebot.io/prisma' import { @@ -28,10 +21,15 @@ import { getSession, setResultAsCompleted, startBotFlow, -} from '../utils' +} from '../helpers' import { env, isDefined, omit } from '@typebot.io/lib' +import { prefillVariables } from '@/features/variables/prefillVariables' +import { checkChatsUsage } from '@/features/usage/checkChatsUsage' +import { injectVariablesFromExistingResult } from '@/features/variables/injectVariablesFromExistingResult' +import { deepParseVariables } from '@/features/variables/deepParseVariable' +import { parseVariables } from '@/features/variables/parseVariables' -export const sendMessageProcedure = publicProcedure +export const sendMessage = publicProcedure .meta({ openapi: { method: 'POST', @@ -165,10 +163,10 @@ const startSession = async (startParams?: StartParams, userId?: string) => { clientSideActions, typebot: { id: typebot.id, - settings: deepParseVariable(newInitialState.typebot.variables)( + settings: deepParseVariables(newInitialState.typebot.variables)( typebot.settings ), - theme: deepParseVariable(newInitialState.typebot.variables)( + theme: deepParseVariables(newInitialState.typebot.variables)( typebot.theme ), }, @@ -195,10 +193,10 @@ const startSession = async (startParams?: StartParams, userId?: string) => { sessionId: session.id, typebot: { id: typebot.id, - settings: deepParseVariable(newInitialState.typebot.variables)( + settings: deepParseVariables(newInitialState.typebot.variables)( typebot.settings ), - theme: deepParseVariable(newInitialState.typebot.variables)( + theme: deepParseVariables(newInitialState.typebot.variables)( typebot.theme ), }, diff --git a/apps/viewer/src/features/chat/api/utils/addEdgeToTypebot.ts b/apps/viewer/src/features/chat/helpers/addEdgeToTypebot.ts similarity index 100% rename from apps/viewer/src/features/chat/api/utils/addEdgeToTypebot.ts rename to apps/viewer/src/features/chat/helpers/addEdgeToTypebot.ts diff --git a/apps/viewer/src/features/chat/api/utils/continueBotFlow.ts b/apps/viewer/src/features/chat/helpers/continueBotFlow.ts similarity index 93% rename from apps/viewer/src/features/chat/api/utils/continueBotFlow.ts rename to apps/viewer/src/features/chat/helpers/continueBotFlow.ts index 8043684ef..6a50b49dc 100644 --- a/apps/viewer/src/features/chat/api/utils/continueBotFlow.ts +++ b/apps/viewer/src/features/chat/helpers/continueBotFlow.ts @@ -1,10 +1,3 @@ -import { validateEmail } from '@/features/blocks/inputs/email/api' -import { - formatPhoneNumber, - validatePhoneNumber, -} from '@/features/blocks/inputs/phone/api' -import { validateUrl } from '@/features/blocks/inputs/url/api' -import { parseVariables, updateVariables } from '@/features/variables' import prisma from '@/lib/prisma' import { TRPCError } from '@trpc/server' import { Prisma } from '@typebot.io/prisma' @@ -22,6 +15,12 @@ import { import { isInputBlock, isNotDefined } from '@typebot.io/lib' import { executeGroup } from './executeGroup' import { getNextGroup } from './getNextGroup' +import { validateEmail } from '@/features/blocks/inputs/email/validateEmail' +import { formatPhoneNumber } from '@/features/blocks/inputs/phone/formatPhoneNumber' +import { validatePhoneNumber } from '@/features/blocks/inputs/phone/validatePhoneNumber' +import { validateUrl } from '@/features/blocks/inputs/url/validateUrl' +import { updateVariables } from '@/features/variables/updateVariables' +import { parseVariables } from '@/features/variables/parseVariables' export const continueBotFlow = (state: SessionState) => diff --git a/apps/viewer/src/features/chat/api/utils/executeGroup.ts b/apps/viewer/src/features/chat/helpers/executeGroup.ts similarity index 92% rename from apps/viewer/src/features/chat/api/utils/executeGroup.ts rename to apps/viewer/src/features/chat/helpers/executeGroup.ts index acf1c4a32..09043be4f 100644 --- a/apps/viewer/src/features/chat/api/utils/executeGroup.ts +++ b/apps/viewer/src/features/chat/helpers/executeGroup.ts @@ -1,4 +1,3 @@ -import { deepParseVariable } from '@/features/variables' import { BubbleBlock, BubbleBlockType, @@ -19,8 +18,9 @@ import { import { executeLogic } from './executeLogic' import { getNextGroup } from './getNextGroup' import { executeIntegration } from './executeIntegration' -import { computePaymentInputRuntimeOptions } from '@/features/blocks/inputs/payment/api' -import { injectVariableValuesInButtonsInputBlock } from '@/features/blocks/inputs/buttons/api/utils/injectVariableValuesInButtonsInputBlock' +import { injectVariableValuesInButtonsInputBlock } from '@/features/blocks/inputs/buttons/injectVariableValuesInButtonsInputBlock' +import { deepParseVariables } from '@/features/variables/deepParseVariable' +import { computePaymentInputRuntimeOptions } from '@/features/blocks/inputs/payment/computePaymentInputRuntimeOptions' export const executeGroup = ( @@ -137,7 +137,7 @@ const parseBubbleBlock = (block: BubbleBlock): ChatReply['messages'][0] => { switch (block.type) { case BubbleBlockType.EMBED: { - const message = deepParseVariable(variables)(block) + const message = deepParseVariables(variables)(block) return { ...message, content: { @@ -150,7 +150,7 @@ const parseBubbleBlock = } } default: - return deepParseVariable(variables)(block) + return deepParseVariables(variables)(block) } } @@ -164,7 +164,7 @@ const injectVariablesValueInBlock = ) } default: { - return deepParseVariable(state.typebot.variables)({ + return deepParseVariables(state.typebot.variables)({ ...block, runtimeOptions: await computeRuntimeOptions(state)(block), prefilledValue: getPrefilledInputValue(state.typebot.variables)( diff --git a/apps/viewer/src/features/chat/api/utils/executeIntegration.ts b/apps/viewer/src/features/chat/helpers/executeIntegration.ts similarity index 84% rename from apps/viewer/src/features/chat/api/utils/executeIntegration.ts rename to apps/viewer/src/features/chat/helpers/executeIntegration.ts index 64e575aa7..36e2028f0 100644 --- a/apps/viewer/src/features/chat/api/utils/executeIntegration.ts +++ b/apps/viewer/src/features/chat/helpers/executeIntegration.ts @@ -1,15 +1,15 @@ -import { executeChatwootBlock } from '@/features/blocks/integrations/chatwoot/api' -import { executeGoogleAnalyticsBlock } from '@/features/blocks/integrations/googleAnalytics/api' -import { executeGoogleSheetBlock } from '@/features/blocks/integrations/googleSheets/api' import { executeOpenAIBlock } from '@/features/blocks/integrations/openai/executeOpenAIBlock' -import { executeSendEmailBlock } from '@/features/blocks/integrations/sendEmail/api' -import { executeWebhookBlock } from '@/features/blocks/integrations/webhook/api' +import { executeSendEmailBlock } from '@/features/blocks/integrations/sendEmail/executeSendEmailBlock' +import { executeWebhookBlock } from '@/features/blocks/integrations/webhook/executeWebhookBlock' +import { executeChatwootBlock } from '@/features/blocks/integrations/chatwoot/executeChatwootBlock' +import { executeGoogleAnalyticsBlock } from '@/features/blocks/integrations/googleAnalytics/executeGoogleAnalyticsBlock' +import { executeGoogleSheetBlock } from '@/features/blocks/integrations/googleSheets/executeGoogleSheetBlock' import { IntegrationBlock, IntegrationBlockType, SessionState, } from '@typebot.io/schemas' -import { ExecuteIntegrationResponse } from '../../types' +import { ExecuteIntegrationResponse } from '../types' export const executeIntegration = (state: SessionState, lastBubbleBlockId?: string) => diff --git a/apps/viewer/src/features/chat/api/utils/executeLogic.ts b/apps/viewer/src/features/chat/helpers/executeLogic.ts similarity index 85% rename from apps/viewer/src/features/chat/api/utils/executeLogic.ts rename to apps/viewer/src/features/chat/helpers/executeLogic.ts index 4c0dd56f4..879264707 100644 --- a/apps/viewer/src/features/chat/api/utils/executeLogic.ts +++ b/apps/viewer/src/features/chat/helpers/executeLogic.ts @@ -1,12 +1,12 @@ -import { executeCondition } from '@/features/blocks/logic/condition/api' -import { executeRedirect } from '@/features/blocks/logic/redirect/api' -import { executeSetVariable } from '@/features/blocks/logic/setVariable/api' -import { executeTypebotLink } from '@/features/blocks/logic/typebotLink/api' -import { executeWait } from '@/features/blocks/logic/wait/api/utils/executeWait' +import { executeWait } from '@/features/blocks/logic/wait/executeWait' import { LogicBlock, LogicBlockType, SessionState } from '@typebot.io/schemas' -import { ExecuteLogicResponse } from '../../types' +import { ExecuteLogicResponse } from '../types' import { executeScript } from '@/features/blocks/logic/script/executeScript' import { executeJumpBlock } from '@/features/blocks/logic/jump/executeJumpBlock' +import { executeRedirect } from '@/features/blocks/logic/redirect/executeRedirect' +import { executeCondition } from '@/features/blocks/logic/condition/executeCondition' +import { executeSetVariable } from '@/features/blocks/logic/setVariable/executeSetVariable' +import { executeTypebotLink } from '@/features/blocks/logic/typebotLink/executeTypebotLink' export const executeLogic = (state: SessionState, lastBubbleBlockId?: string) => diff --git a/apps/viewer/src/features/chat/api/utils/getNextGroup.ts b/apps/viewer/src/features/chat/helpers/getNextGroup.ts similarity index 100% rename from apps/viewer/src/features/chat/api/utils/getNextGroup.ts rename to apps/viewer/src/features/chat/helpers/getNextGroup.ts diff --git a/apps/viewer/src/features/chat/api/utils/getSessionState.ts b/apps/viewer/src/features/chat/helpers/getSessionState.ts similarity index 100% rename from apps/viewer/src/features/chat/api/utils/getSessionState.ts rename to apps/viewer/src/features/chat/helpers/getSessionState.ts diff --git a/apps/viewer/src/features/chat/api/utils/index.ts b/apps/viewer/src/features/chat/helpers/index.ts similarity index 100% rename from apps/viewer/src/features/chat/api/utils/index.ts rename to apps/viewer/src/features/chat/helpers/index.ts diff --git a/apps/viewer/src/features/chat/api/utils/startBotFlow.ts b/apps/viewer/src/features/chat/helpers/startBotFlow.ts similarity index 100% rename from apps/viewer/src/features/chat/api/utils/startBotFlow.ts rename to apps/viewer/src/features/chat/helpers/startBotFlow.ts diff --git a/apps/viewer/src/features/chat/index.ts b/apps/viewer/src/features/chat/index.ts deleted file mode 100644 index c9f6f047d..000000000 --- a/apps/viewer/src/features/chat/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types' diff --git a/apps/viewer/src/features/logs/api/index.ts b/apps/viewer/src/features/logs/api/index.ts deleted file mode 100644 index a56349337..000000000 --- a/apps/viewer/src/features/logs/api/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './saveErrorLog' -export * from './saveSuccessLog' diff --git a/apps/viewer/src/features/logs/api/saveErrorLog.ts b/apps/viewer/src/features/logs/saveErrorLog.ts similarity index 84% rename from apps/viewer/src/features/logs/api/saveErrorLog.ts rename to apps/viewer/src/features/logs/saveErrorLog.ts index 0435e60a6..ef82e0399 100644 --- a/apps/viewer/src/features/logs/api/saveErrorLog.ts +++ b/apps/viewer/src/features/logs/saveErrorLog.ts @@ -1,4 +1,4 @@ -import { saveLog } from './utils' +import { saveLog } from './saveLog' export const saveErrorLog = ({ resultId, diff --git a/apps/viewer/src/features/logs/api/utils.ts b/apps/viewer/src/features/logs/saveLog.ts similarity index 100% rename from apps/viewer/src/features/logs/api/utils.ts rename to apps/viewer/src/features/logs/saveLog.ts diff --git a/apps/viewer/src/features/logs/api/saveSuccessLog.ts b/apps/viewer/src/features/logs/saveSuccessLog.ts similarity index 84% rename from apps/viewer/src/features/logs/api/saveSuccessLog.ts rename to apps/viewer/src/features/logs/saveSuccessLog.ts index 3666de4ab..4a00724ab 100644 --- a/apps/viewer/src/features/logs/api/saveSuccessLog.ts +++ b/apps/viewer/src/features/logs/saveSuccessLog.ts @@ -1,4 +1,4 @@ -import { saveLog } from './utils' +import { saveLog } from './saveLog' export const saveSuccessLog = ({ resultId, diff --git a/apps/viewer/src/features/results/index.ts b/apps/viewer/src/features/results/index.ts deleted file mode 100644 index 47f950029..000000000 --- a/apps/viewer/src/features/results/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { createResultQuery, updateResultQuery } from './queries' diff --git a/apps/viewer/src/features/results/queries/index.ts b/apps/viewer/src/features/results/queries/index.ts deleted file mode 100644 index 1b5113e65..000000000 --- a/apps/viewer/src/features/results/queries/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './createResultQuery' -export * from './updateResultQuery' diff --git a/apps/viewer/src/features/usage/utils/checkChatsUsage.ts b/apps/viewer/src/features/usage/checkChatsUsage.ts similarity index 100% rename from apps/viewer/src/features/usage/utils/checkChatsUsage.ts rename to apps/viewer/src/features/usage/checkChatsUsage.ts diff --git a/apps/viewer/src/features/usage/index.ts b/apps/viewer/src/features/usage/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/usage/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/usage/utils/index.ts b/apps/viewer/src/features/usage/utils/index.ts deleted file mode 100644 index e00dad5f1..000000000 --- a/apps/viewer/src/features/usage/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './checkChatsUsage' diff --git a/apps/viewer/src/features/variables/deepParseVariable.ts b/apps/viewer/src/features/variables/deepParseVariable.ts new file mode 100644 index 000000000..ed0955b80 --- /dev/null +++ b/apps/viewer/src/features/variables/deepParseVariable.ts @@ -0,0 +1,28 @@ +import { Variable } from '@typebot.io/schemas' +import { parseVariables } from './parseVariables' + +export const deepParseVariables = + (variables: Variable[]) => + >(object: T): T => + Object.keys(object).reduce((newObj, key) => { + const currentValue = object[key] + + if (typeof currentValue === 'string') + return { ...newObj, [key]: parseVariables(variables)(currentValue) } + + if (currentValue instanceof Object && currentValue.constructor === Object) + return { + ...newObj, + [key]: deepParseVariables(variables)( + currentValue as Record + ), + } + + if (currentValue instanceof Array) + return { + ...newObj, + [key]: currentValue.map(deepParseVariables(variables)), + } + + return { ...newObj, [key]: currentValue } + }, {} as T) diff --git a/apps/viewer/src/features/variables/extractVariablesFromText.ts b/apps/viewer/src/features/variables/extractVariablesFromText.ts new file mode 100644 index 000000000..029f14b55 --- /dev/null +++ b/apps/viewer/src/features/variables/extractVariablesFromText.ts @@ -0,0 +1,15 @@ +import { Variable } from '@typebot.io/schemas' + +export const extractVariablesFromText = + (variables: Variable[]) => + (text: string): Variable[] => { + const matches = [...text.matchAll(/\{\{(.*?)\}\}/g)] + return matches.reduce((acc, match) => { + const variableName = match[1] + const variable = variables.find( + (variable) => variable.name === variableName + ) + if (!variable) return acc + return [...acc, variable] + }, []) + } diff --git a/apps/viewer/src/features/variables/findUniqueVariableValue.ts b/apps/viewer/src/features/variables/findUniqueVariableValue.ts new file mode 100644 index 000000000..1e24e574f --- /dev/null +++ b/apps/viewer/src/features/variables/findUniqueVariableValue.ts @@ -0,0 +1,12 @@ +import { Variable } from '@typebot.io/schemas' + +export const findUniqueVariableValue = + (variables: Variable[]) => + (value: string | undefined): string | string[] | null => { + if (!value || !value.startsWith('{{') || !value.endsWith('}}')) return null + const variableName = value.slice(2, -2) + const variable = variables.find( + (variable) => variable.name === variableName + ) + return variable?.value ?? null + } diff --git a/apps/viewer/src/features/variables/hasVariable.ts b/apps/viewer/src/features/variables/hasVariable.ts new file mode 100644 index 000000000..766a0cc47 --- /dev/null +++ b/apps/viewer/src/features/variables/hasVariable.ts @@ -0,0 +1 @@ +export const hasVariable = (str: string): boolean => /\{\{(.*?)\}\}/g.test(str) diff --git a/apps/viewer/src/features/variables/index.ts b/apps/viewer/src/features/variables/index.ts deleted file mode 100644 index 9c56149ef..000000000 --- a/apps/viewer/src/features/variables/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './utils' diff --git a/apps/viewer/src/features/variables/injectVariablesFromExistingResult.ts b/apps/viewer/src/features/variables/injectVariablesFromExistingResult.ts new file mode 100644 index 000000000..bd6da8747 --- /dev/null +++ b/apps/viewer/src/features/variables/injectVariablesFromExistingResult.ts @@ -0,0 +1,17 @@ +import { Result, Variable } from '@typebot.io/schemas' + +export const injectVariablesFromExistingResult = ( + variables: Variable[], + resultVariables: Result['variables'] +): Variable[] => + variables.map((variable) => { + const resultVariable = resultVariables.find( + (resultVariable) => + resultVariable.name === variable.name && !variable.value + ) + if (!resultVariable) return variable + return { + ...variable, + value: resultVariable.value, + } + }) diff --git a/apps/viewer/src/features/variables/parseGuessedValueType.ts b/apps/viewer/src/features/variables/parseGuessedValueType.ts new file mode 100644 index 000000000..fd10cdb4e --- /dev/null +++ b/apps/viewer/src/features/variables/parseGuessedValueType.ts @@ -0,0 +1,20 @@ +import { Variable } from '@typebot.io/schemas' + +export const parseGuessedValueType = ( + value: Variable['value'] +): string | string[] | boolean | number | null | undefined => { + if (value === null) return null + if (value === undefined) return undefined + if (typeof value !== 'string') return value + const isNumberStartingWithZero = + value.startsWith('0') && !value.startsWith('0.') && value.length > 1 + if (typeof value === 'string' && isNumberStartingWithZero) return value + if (typeof value === 'number') return value + if (value === 'true') return true + if (value === 'false') return false + if (value === 'null') return null + if (value === 'undefined') return undefined + // isNaN works with strings + if (isNaN(value as unknown as number)) return value + return Number(value) +} diff --git a/apps/viewer/src/features/variables/parseVariables.ts b/apps/viewer/src/features/variables/parseVariables.ts new file mode 100644 index 000000000..ac6493a98 --- /dev/null +++ b/apps/viewer/src/features/variables/parseVariables.ts @@ -0,0 +1,40 @@ +import { isDefined } from '@typebot.io/lib' +import { Variable, VariableWithValue } from '@typebot.io/schemas' +import { safeStringify } from './safeStringify' + +export const parseVariables = + ( + variables: Variable[], + options: { fieldToParse?: 'value' | 'id'; escapeForJson?: boolean } = { + fieldToParse: 'value', + escapeForJson: false, + } + ) => + (text: string | undefined): string => { + if (!text || text === '') return '' + return text.replace(/\{\{(.*?)\}\}/g, (_, fullVariableString) => { + const matchedVarName = fullVariableString.replace(/{{|}}/g, '') + const variable = variables.find((variable) => { + return ( + matchedVarName === variable.name && + (options.fieldToParse === 'id' || isDefined(variable.value)) + ) + }) as VariableWithValue | undefined + if (!variable) return '' + if (options.fieldToParse === 'id') return variable.id + const { value } = variable + if (options.escapeForJson) + return jsonParse( + typeof value !== 'string' ? JSON.stringify(value) : value + ) + const parsedValue = safeStringify(value) + if (!parsedValue) return '' + return parsedValue + }) + } + +const jsonParse = (str: string) => + str + .replace(/\n/g, `\\n`) + .replace(/"/g, `\\"`) + .replace(/\\[^n"]/g, `\\\\ `) diff --git a/apps/viewer/src/features/variables/prefillVariables.ts b/apps/viewer/src/features/variables/prefillVariables.ts new file mode 100644 index 000000000..86d9bef00 --- /dev/null +++ b/apps/viewer/src/features/variables/prefillVariables.ts @@ -0,0 +1,15 @@ +import { StartParams, Variable } from '@typebot.io/schemas' +import { safeStringify } from './safeStringify' + +export const prefillVariables = ( + variables: Variable[], + prefilledVariables: NonNullable +): Variable[] => + variables.map((variable) => { + const prefilledVariable = prefilledVariables[variable.name] + if (!prefilledVariable) return variable + return { + ...variable, + value: safeStringify(prefilledVariable), + } + }) diff --git a/apps/viewer/src/features/variables/safeStringify.ts b/apps/viewer/src/features/variables/safeStringify.ts new file mode 100644 index 000000000..6536f577b --- /dev/null +++ b/apps/viewer/src/features/variables/safeStringify.ts @@ -0,0 +1,12 @@ +import { isNotDefined } from '@typebot.io/lib' + +export const safeStringify = (val: unknown): string | null => { + if (isNotDefined(val)) return null + if (typeof val === 'string') return val + try { + return JSON.stringify(val) + } catch { + console.warn('Failed to safely stringify variable value', val) + return null + } +} diff --git a/apps/viewer/src/features/variables/updateVariables.ts b/apps/viewer/src/features/variables/updateVariables.ts new file mode 100644 index 000000000..27e7f5517 --- /dev/null +++ b/apps/viewer/src/features/variables/updateVariables.ts @@ -0,0 +1,77 @@ +import prisma from '@/lib/prisma' +import { isDefined } from '@typebot.io/lib' +import { + SessionState, + VariableWithUnknowValue, + VariableWithValue, + Variable, +} from '@typebot.io/schemas' +import { safeStringify } from './safeStringify' + +export const updateVariables = + (state: SessionState) => + async (newVariables: VariableWithUnknowValue[]): Promise => ({ + ...state, + typebot: { + ...state.typebot, + variables: updateTypebotVariables(state)(newVariables), + }, + result: { + ...state.result, + variables: await updateResultVariables(state)(newVariables), + }, + }) + +const updateResultVariables = + ({ result }: Pick) => + async ( + newVariables: VariableWithUnknowValue[] + ): Promise => { + const serializedNewVariables = newVariables.map((variable) => ({ + ...variable, + value: Array.isArray(variable.value) + ? variable.value.map(safeStringify).filter(isDefined) + : safeStringify(variable.value), + })) + + const updatedVariables = [ + ...result.variables.filter((existingVariable) => + serializedNewVariables.every( + (newVariable) => existingVariable.id !== newVariable.id + ) + ), + ...serializedNewVariables, + ].filter((variable) => isDefined(variable.value)) as VariableWithValue[] + + if (result.id) + await prisma.result.update({ + where: { + id: result.id, + }, + data: { + variables: updatedVariables, + }, + }) + + return updatedVariables + } + +const updateTypebotVariables = + ({ typebot }: Pick) => + (newVariables: VariableWithUnknowValue[]): Variable[] => { + const serializedNewVariables = newVariables.map((variable) => ({ + ...variable, + value: Array.isArray(variable.value) + ? variable.value.map(safeStringify).filter(isDefined) + : safeStringify(variable.value), + })) + + return [ + ...typebot.variables.filter((existingVariable) => + serializedNewVariables.every( + (newVariable) => existingVariable.id !== newVariable.id + ) + ), + ...serializedNewVariables, + ] + } diff --git a/apps/viewer/src/features/variables/utils.ts b/apps/viewer/src/features/variables/utils.ts deleted file mode 100644 index 9d986ca1f..000000000 --- a/apps/viewer/src/features/variables/utils.ts +++ /dev/null @@ -1,229 +0,0 @@ -import prisma from '@/lib/prisma' -import { - Result, - SessionState, - StartParams, - Typebot, - Variable, - VariableWithUnknowValue, - VariableWithValue, -} from '@typebot.io/schemas' -import { isDefined, isNotDefined } from '@typebot.io/lib' - -export const stringContainsVariable = (str: string): boolean => - /\{\{(.*?)\}\}/g.test(str) - -export const parseVariables = - ( - variables: Variable[], - options: { fieldToParse?: 'value' | 'id'; escapeForJson?: boolean } = { - fieldToParse: 'value', - escapeForJson: false, - } - ) => - (text: string | undefined): string => { - if (!text || text === '') return '' - return text.replace(/\{\{(.*?)\}\}/g, (_, fullVariableString) => { - const matchedVarName = fullVariableString.replace(/{{|}}/g, '') - const variable = variables.find((variable) => { - return ( - matchedVarName === variable.name && - (options.fieldToParse === 'id' || isDefined(variable.value)) - ) - }) as VariableWithValue | undefined - if (!variable) return '' - if (options.fieldToParse === 'id') return variable.id - const { value } = variable - if (options.escapeForJson) - return jsonParse( - typeof value !== 'string' ? JSON.stringify(value) : value - ) - const parsedValue = safeStringify(value) - if (!parsedValue) return '' - return parsedValue - }) - } - -export const extractVariablesFromText = - (variables: Variable[]) => - (text: string): Variable[] => { - const matches = [...text.matchAll(/\{\{(.*?)\}\}/g)] - return matches.reduce((acc, match) => { - const variableName = match[1] - const variable = variables.find( - (variable) => variable.name === variableName - ) - if (!variable) return acc - return [...acc, variable] - }, []) - } - -export const safeStringify = (val: unknown): string | null => { - if (isNotDefined(val)) return null - if (typeof val === 'string') return val - try { - return JSON.stringify(val) - } catch { - console.warn('Failed to safely stringify variable value', val) - return null - } -} - -export const parseCorrectValueType = ( - value: Variable['value'] -): string | string[] | boolean | number | null | undefined => { - if (value === null) return null - if (value === undefined) return undefined - if (typeof value !== 'string') return value - const isNumberStartingWithZero = - value.startsWith('0') && !value.startsWith('0.') && value.length > 1 - if (typeof value === 'string' && isNumberStartingWithZero) return value - if (typeof value === 'number') return value - if (value === 'true') return true - if (value === 'false') return false - if (value === 'null') return null - if (value === 'undefined') return undefined - // isNaN works with strings - if (isNaN(value as unknown as number)) return value - return Number(value) -} - -const jsonParse = (str: string) => - str - .replace(/\n/g, `\\n`) - .replace(/"/g, `\\"`) - .replace(/\\[^n"]/g, `\\\\ `) - -export const deepParseVariable = - (variables: Variable[]) => - >(object: T): T => - Object.keys(object).reduce((newObj, key) => { - const currentValue = object[key] - - if (typeof currentValue === 'string') - return { ...newObj, [key]: parseVariables(variables)(currentValue) } - - if (currentValue instanceof Object && currentValue.constructor === Object) - return { - ...newObj, - [key]: deepParseVariable(variables)( - currentValue as Record - ), - } - - if (currentValue instanceof Array) - return { - ...newObj, - [key]: currentValue.map(deepParseVariable(variables)), - } - - return { ...newObj, [key]: currentValue } - }, {} as T) - -export const prefillVariables = ( - variables: Typebot['variables'], - prefilledVariables: NonNullable -): Variable[] => - variables.map((variable) => { - const prefilledVariable = prefilledVariables[variable.name] - if (!prefilledVariable) return variable - return { - ...variable, - value: safeStringify(prefilledVariable), - } - }) - -export const injectVariablesFromExistingResult = ( - variables: Typebot['variables'], - resultVariables: Result['variables'] -): Variable[] => - variables.map((variable) => { - const resultVariable = resultVariables.find( - (resultVariable) => - resultVariable.name === variable.name && !variable.value - ) - if (!resultVariable) return variable - return { - ...variable, - value: resultVariable.value, - } - }) - -export const updateVariables = - (state: SessionState) => - async (newVariables: VariableWithUnknowValue[]): Promise => ({ - ...state, - typebot: { - ...state.typebot, - variables: updateTypebotVariables(state)(newVariables), - }, - result: { - ...state.result, - variables: await updateResultVariables(state)(newVariables), - }, - }) - -const updateResultVariables = - ({ result }: Pick) => - async ( - newVariables: VariableWithUnknowValue[] - ): Promise => { - const serializedNewVariables = newVariables.map((variable) => ({ - ...variable, - value: Array.isArray(variable.value) - ? variable.value.map(safeStringify).filter(isDefined) - : safeStringify(variable.value), - })) - - const updatedVariables = [ - ...result.variables.filter((existingVariable) => - serializedNewVariables.every( - (newVariable) => existingVariable.id !== newVariable.id - ) - ), - ...serializedNewVariables, - ].filter((variable) => isDefined(variable.value)) as VariableWithValue[] - - if (result.id) - await prisma.result.update({ - where: { - id: result.id, - }, - data: { - variables: updatedVariables, - }, - }) - - return updatedVariables - } - -const updateTypebotVariables = - ({ typebot }: Pick) => - (newVariables: VariableWithUnknowValue[]): Variable[] => { - const serializedNewVariables = newVariables.map((variable) => ({ - ...variable, - value: Array.isArray(variable.value) - ? variable.value.map(safeStringify).filter(isDefined) - : safeStringify(variable.value), - })) - - return [ - ...typebot.variables.filter((existingVariable) => - serializedNewVariables.every( - (newVariable) => existingVariable.id !== newVariable.id - ) - ), - ...serializedNewVariables, - ] - } - -export const findUniqueVariableValue = - (variables: Variable[]) => - (value: string | undefined): string | string[] | null => { - if (!value || !value.startsWith('{{') || !value.endsWith('}}')) return null - const variableName = value.slice(2, -2) - const variable = variables.find( - (variable) => variable.name === variableName - ) - return variable?.value ?? null - } diff --git a/apps/viewer/src/utils/api/dbRules.ts b/apps/viewer/src/helpers/api/dbRules.ts similarity index 100% rename from apps/viewer/src/utils/api/dbRules.ts rename to apps/viewer/src/helpers/api/dbRules.ts diff --git a/apps/viewer/src/features/auth/api/authenticateUser.ts b/apps/viewer/src/helpers/authenticateUser.ts similarity index 100% rename from apps/viewer/src/features/auth/api/authenticateUser.ts rename to apps/viewer/src/helpers/authenticateUser.ts diff --git a/apps/viewer/src/utils/server/context.ts b/apps/viewer/src/helpers/server/context.ts similarity index 100% rename from apps/viewer/src/utils/server/context.ts rename to apps/viewer/src/helpers/server/context.ts diff --git a/apps/viewer/src/utils/server/generateOpenApi.ts b/apps/viewer/src/helpers/server/generateOpenApi.ts similarity index 100% rename from apps/viewer/src/utils/server/generateOpenApi.ts rename to apps/viewer/src/helpers/server/generateOpenApi.ts diff --git a/apps/viewer/src/utils/server/routers/v1/_app.ts b/apps/viewer/src/helpers/server/routers/v1/_app.ts similarity index 70% rename from apps/viewer/src/utils/server/routers/v1/_app.ts rename to apps/viewer/src/helpers/server/routers/v1/_app.ts index 085ecadc3..2a684d9b6 100644 --- a/apps/viewer/src/utils/server/routers/v1/_app.ts +++ b/apps/viewer/src/helpers/server/routers/v1/_app.ts @@ -1,4 +1,4 @@ -import { chatRouter } from '@/features/chat/api' +import { chatRouter } from '@/features/chat/api/router' import { router } from '../../trpc' export const appRouter = router({ diff --git a/apps/viewer/src/utils/server/trpc.ts b/apps/viewer/src/helpers/server/trpc.ts similarity index 100% rename from apps/viewer/src/utils/server/trpc.ts rename to apps/viewer/src/helpers/server/trpc.ts diff --git a/apps/viewer/src/utils/sessionStorage.ts b/apps/viewer/src/helpers/sessionStorage.ts similarity index 100% rename from apps/viewer/src/utils/sessionStorage.ts rename to apps/viewer/src/helpers/sessionStorage.ts diff --git a/apps/viewer/src/pages/api/integrations/google-sheets/spreadsheets/[spreadsheetId]/sheets/[sheetId].ts b/apps/viewer/src/pages/api/integrations/google-sheets/spreadsheets/[spreadsheetId]/sheets/[sheetId].ts index 4904d60c0..db2eb8482 100644 --- a/apps/viewer/src/pages/api/integrations/google-sheets/spreadsheets/[spreadsheetId]/sheets/[sheetId].ts +++ b/apps/viewer/src/pages/api/integrations/google-sheets/spreadsheets/[spreadsheetId]/sheets/[sheetId].ts @@ -17,7 +17,8 @@ import { } from '@typebot.io/schemas' import Cors from 'cors' import { getAuthenticatedGoogleClient } from '@/lib/google-sheets' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' const cors = initMiddleware(Cors()) diff --git a/apps/viewer/src/pages/api/integrations/stripe/createPaymentIntent.ts b/apps/viewer/src/pages/api/integrations/stripe/createPaymentIntent.ts index 30566b5f0..d2533bcef 100644 --- a/apps/viewer/src/pages/api/integrations/stripe/createPaymentIntent.ts +++ b/apps/viewer/src/pages/api/integrations/stripe/createPaymentIntent.ts @@ -15,7 +15,7 @@ import { Variable, } from '@typebot.io/schemas' import prisma from '@/lib/prisma' -import { parseVariables } from '@/features/variables' +import { parseVariables } from '@/features/variables/parseVariables' const cors = initMiddleware(Cors()) diff --git a/apps/viewer/src/pages/api/typebots.ts b/apps/viewer/src/pages/api/typebots.ts index ade2fc2ae..9da5e5ac3 100644 --- a/apps/viewer/src/pages/api/typebots.ts +++ b/apps/viewer/src/pages/api/typebots.ts @@ -1,4 +1,4 @@ -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from '@typebot.io/lib/api' diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts index d84d13d7f..5b90f13c0 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts @@ -19,13 +19,12 @@ import { initMiddleware, methodNotAllowed, notFound } from '@typebot.io/lib/api' import { stringify } from 'qs' import Cors from 'cors' import prisma from '@/lib/prisma' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' -import { parseSampleResult } from '@/features/blocks/integrations/webhook/api' -import { - getLinkedTypebots, - getLinkedTypebotsChildren, -} from '@/features/blocks/logic/typebotLink/api' -import { parseVariables } from '@/features/variables' +import { parseVariables } from '@/features/variables/parseVariables' +import { parseSampleResult } from '@/features/blocks/integrations/webhook/parseSampleResult' +import { getLinkedTypebots } from '@/features/blocks/logic/typebotLink/getLinkedTypebots' +import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/getLinkedTypebotsChildren' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' const cors = initMiddleware(Cors()) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/sampleResult.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/sampleResult.ts index 830f668e4..94a4384e6 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/sampleResult.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/sampleResult.ts @@ -1,10 +1,10 @@ -import { authenticateUser } from '@/features/auth/api' -import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/api' -import { parseSampleResult } from '@/features/blocks/integrations/webhook/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { Typebot } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from '@typebot.io/lib/api' +import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/getLinkedTypebotsChildren' +import { parseSampleResult } from '@/features/blocks/integrations/webhook/parseSampleResult' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const user = await authenticateUser(req) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/sampleResult.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/sampleResult.ts index e9bfb91fe..790627d04 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/sampleResult.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/sampleResult.ts @@ -1,10 +1,10 @@ -import { authenticateUser } from '@/features/auth/api' -import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/api' -import { parseSampleResult } from '@/features/blocks/integrations/webhook/api' import prisma from '@/lib/prisma' import { Typebot } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from '@typebot.io/lib/api' +import { parseSampleResult } from '@/features/blocks/integrations/webhook/parseSampleResult' +import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/getLinkedTypebotsChildren' +import { authenticateUser } from '@/helpers/authenticateUser' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const user = await authenticateUser(req) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts index 69edc174d..ccf709096 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts @@ -2,8 +2,8 @@ import { Typebot, WebhookBlock } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from '@typebot.io/lib/api' import { byId } from '@typebot.io/lib' -import { authenticateUser } from '@/features/auth/api' import prisma from '@/lib/prisma' +import { authenticateUser } from '@/helpers/authenticateUser' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const user = await authenticateUser(req) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/unsubscribeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/unsubscribeWebhook.ts index 9a80073a3..577264014 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/unsubscribeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/unsubscribeWebhook.ts @@ -2,7 +2,7 @@ import { Typebot, WebhookBlock } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from '@typebot.io/lib/api' import { byId } from '@typebot.io/lib' -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/subscribeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/subscribeWebhook.ts index 651b071b4..30e0c207f 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/subscribeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/subscribeWebhook.ts @@ -1,4 +1,4 @@ -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { Typebot, WebhookBlock } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/unsubscribeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/unsubscribeWebhook.ts index 6b1da7d35..dee67646e 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/unsubscribeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/unsubscribeWebhook.ts @@ -1,4 +1,4 @@ -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { Typebot, WebhookBlock } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/integrations/email.tsx b/apps/viewer/src/pages/api/typebots/[typebotId]/integrations/email.tsx index 86ccbbe20..3df6d72ad 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/integrations/email.tsx +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/integrations/email.tsx @@ -9,14 +9,15 @@ import { createTransport, getTestMessageUrl } from 'nodemailer' import { isDefined, isEmpty, isNotDefined, omit } from '@typebot.io/lib' import { parseAnswers } from '@typebot.io/lib/results' import { methodNotAllowed, initMiddleware, decrypt } from '@typebot.io/lib/api' -import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' import Cors from 'cors' import Mail from 'nodemailer/lib/mailer' import { DefaultBotNotificationEmail } from '@typebot.io/emails' import { render } from '@faire/mjml-react/utils/render' import prisma from '@/lib/prisma' -import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/api' +import { getLinkedTypebotsChildren } from '@/features/blocks/logic/typebotLink/getLinkedTypebotsChildren' +import { saveErrorLog } from '@/features/logs/saveErrorLog' +import { saveSuccessLog } from '@/features/logs/saveSuccessLog' const cors = initMiddleware(Cors()) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/results.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/results.ts index 10618ad03..ff206887d 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/results.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/results.ts @@ -1,9 +1,9 @@ -import { authenticateUser } from '@/features/auth/api' -import { checkChatsUsage } from '@/features/usage' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { ResultWithAnswers } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from '@typebot.io/lib/api' +import { checkChatsUsage } from '@/features/usage/checkChatsUsage' const handler = async (req: NextApiRequest, res: NextApiResponse) => { if (req.method === 'GET') { diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/webhookBlocks.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/webhookBlocks.ts index 1510d8a7f..7831407ef 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/webhookBlocks.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/webhookBlocks.ts @@ -1,4 +1,4 @@ -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { Group, WebhookBlock } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/webhookSteps.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/webhookSteps.ts index e7e1f636d..3858c1fb4 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/webhookSteps.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/webhookSteps.ts @@ -1,4 +1,4 @@ -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import prisma from '@/lib/prisma' import { Group, WebhookBlock } from '@typebot.io/schemas' import { NextApiRequest, NextApiResponse } from 'next' diff --git a/apps/viewer/src/pages/api/users/me.ts b/apps/viewer/src/pages/api/users/me.ts index 3d7db033a..bad8e5832 100644 --- a/apps/viewer/src/pages/api/users/me.ts +++ b/apps/viewer/src/pages/api/users/me.ts @@ -1,4 +1,4 @@ -import { authenticateUser } from '@/features/auth/api' +import { authenticateUser } from '@/helpers/authenticateUser' import { NextApiRequest, NextApiResponse } from 'next' import { isNotDefined } from '@typebot.io/lib' import { methodNotAllowed } from '@typebot.io/lib/api' diff --git a/apps/viewer/src/pages/api/v1/[...trpc].ts b/apps/viewer/src/pages/api/v1/[...trpc].ts index a5b24343d..a0285c014 100644 --- a/apps/viewer/src/pages/api/v1/[...trpc].ts +++ b/apps/viewer/src/pages/api/v1/[...trpc].ts @@ -1,9 +1,9 @@ -import { appRouter } from '@/utils/server/routers/v1/_app' +import { appRouter } from '@/helpers/server/routers/v1/_app' import { captureException } from '@sentry/nextjs' import { createOpenApiNextHandler } from 'trpc-openapi' import cors from 'nextjs-cors' import { NextApiRequest, NextApiResponse } from 'next' -import { createContext } from '@/utils/server/context' +import { createContext } from '@/helpers/server/context' const handler = async (req: NextApiRequest, res: NextApiResponse) => { await cors(req, res)