2
0

♻️ Re-organize workspace folders

This commit is contained in:
Baptiste Arnaud
2023-03-15 08:35:16 +01:00
parent 25c367901f
commit cbc8194f19
987 changed files with 2716 additions and 2770 deletions

View File

@ -1,5 +1,5 @@
import { Answer, AnswerInput } from 'models'
import { sendRequest } from 'utils'
import { Answer, AnswerInput } from '@typebot.io/schemas'
import { sendRequest } from '@typebot.io/lib'
export const upsertAnswerQuery = async (
answer: AnswerInput & { resultId: string } & { uploadedFiles?: boolean }

View File

@ -1,4 +1,4 @@
import { User } from 'db'
import { User } from '@typebot.io/prisma'
import { NextApiRequest } from 'next'
import prisma from '@/lib/prisma'

View File

@ -4,8 +4,8 @@ import {
VariableWithValue,
ChoiceInputBlock,
ItemType,
} from 'models'
import { isDefined } from 'utils'
} from '@typebot.io/schemas'
import { isDefined } from '@typebot.io/lib'
export const injectVariableValuesInButtonsInputBlock =
(variables: SessionState['typebot']['variables']) =>

View File

@ -2,14 +2,14 @@ import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { parse } from 'papaparse'
import { readFileSync } from 'fs'
import { isDefined } from 'utils'
import { isDefined } from '@typebot.io/lib'
import {
createWorkspaces,
importTypebotInDatabase,
injectFakeResults,
} from 'utils/playwright/databaseActions'
} from '@typebot.io/lib/playwright/databaseActions'
import { getTestAsset } from '@/test/utils/playwright'
import { Plan } from 'db'
import { Plan } from '@typebot.io/prisma'
const THREE_GIGABYTES = 3 * 1024 * 1024 * 1024

View File

@ -6,9 +6,9 @@ import {
PaymentInputRuntimeOptions,
SessionState,
StripeCredentials,
} from 'models'
} from '@typebot.io/schemas'
import Stripe from 'stripe'
import { decrypt } from 'utils/api/encryption'
import { decrypt } from '@typebot.io/lib/api/encryption'
export const computePaymentInputRuntimeOptions =
(state: Pick<SessionState, 'result' | 'typebot'>) =>

View File

@ -4,7 +4,11 @@ import {
parseCorrectValueType,
extractVariablesFromText,
} from '@/features/variables'
import { ChatwootBlock, ChatwootOptions, SessionState } from 'models'
import {
ChatwootBlock,
ChatwootOptions,
SessionState,
} from '@typebot.io/schemas'
const parseSetUserCode = (user: ChatwootOptions['user']) => `
window.$chatwoot.setUser("${user?.id ?? ''}", {

View File

@ -1,8 +1,11 @@
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { createTypebots } from 'utils/playwright/databaseActions'
import { parseDefaultGroupWithBlock } from 'utils/playwright/databaseHelpers'
import { defaultChatwootOptions, IntegrationBlockType } from 'models'
import { createTypebots } from '@typebot.io/lib/playwright/databaseActions'
import { parseDefaultGroupWithBlock } from '@typebot.io/lib/playwright/databaseHelpers'
import {
defaultChatwootOptions,
IntegrationBlockType,
} from '@typebot.io/schemas'
const typebotId = createId()

View File

@ -1,6 +1,6 @@
import { ExecuteIntegrationResponse } from '@/features/chat'
import { deepParseVariable } from '@/features/variables'
import { GoogleAnalyticsBlock, SessionState } from 'models'
import { GoogleAnalyticsBlock, SessionState } from '@typebot.io/schemas'
export const executeGoogleAnalyticsBlock = (
{ typebot: { variables } }: SessionState,

View File

@ -1,5 +1,9 @@
import { ExecuteIntegrationResponse } from '@/features/chat'
import { GoogleSheetsBlock, GoogleSheetsAction, SessionState } from 'models'
import {
GoogleSheetsBlock,
GoogleSheetsAction,
SessionState,
} from '@typebot.io/schemas'
import { getRow } from './getRow'
import { insertRow } from './insertRow'
import { updateRow } from './updateRow'

View File

@ -5,11 +5,11 @@ import {
ComparisonOperators,
LogicalOperator,
ReplyLog,
} from 'models'
} 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 'utils'
import { isNotEmpty, byId, isDefined } from '@typebot.io/lib'
import { ExecuteIntegrationResponse } from '@/features/chat'
import type { GoogleSpreadsheetRow } from 'google-spreadsheet'

View File

@ -2,7 +2,7 @@ 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 'models'
import { Variable, Cell } from '@typebot.io/schemas'
export const parseCellValues =
(variables: Variable[]) =>

View File

@ -1,4 +1,8 @@
import { SessionState, GoogleSheetsInsertRowOptions, ReplyLog } from 'models'
import {
SessionState,
GoogleSheetsInsertRowOptions,
ReplyLog,
} from '@typebot.io/schemas'
import { saveErrorLog, saveSuccessLog } from '@/features/logs/api'
import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers'
import { ExecuteIntegrationResponse } from '@/features/chat'

View File

@ -1,4 +1,8 @@
import { SessionState, GoogleSheetsUpdateRowOptions, ReplyLog } from 'models'
import {
SessionState,
GoogleSheetsUpdateRowOptions,
ReplyLog,
} from '@typebot.io/schemas'
import { saveErrorLog, saveSuccessLog } from '@/features/logs/api'
import { getAuthenticatedGoogleDoc, parseCellValues } from './helpers'
import { TRPCError } from '@trpc/server'

View File

@ -8,14 +8,14 @@ import {
Variable,
VariableWithUnknowValue,
VariableWithValue,
} from 'models'
} from '@typebot.io/schemas'
import {
ChatCompletionOpenAIOptions,
OpenAICredentials,
} from 'models/features/blocks/integrations/openai'
} from '@typebot.io/schemas/features/blocks/integrations/openai'
import { OpenAIApi, Configuration, ChatCompletionRequestMessage } from 'openai'
import { isDefined, byId, isNotEmpty } from 'utils'
import { decrypt } from 'utils/api/encryption'
import { isDefined, byId, isNotEmpty } from '@typebot.io/lib'
import { decrypt } from '@typebot.io/lib/api/encryption'
export const createChatCompletionOpenAI = async (
state: SessionState,

View File

@ -1,6 +1,6 @@
import { ExecuteIntegrationResponse } from '@/features/chat/types'
import { SessionState } from 'models'
import { OpenAIBlock } from 'models/features/blocks/integrations/openai'
import { SessionState } from '@typebot.io/schemas'
import { OpenAIBlock } from '@typebot.io/schemas/features/blocks/integrations/openai'
import { createChatCompletionOpenAI } from './createChatCompletionOpenAI'
export const executeOpenAIBlock = async (

View File

@ -3,7 +3,7 @@ import { saveErrorLog, saveSuccessLog } from '@/features/logs/api'
import { parseVariables } from '@/features/variables'
import prisma from '@/lib/prisma'
import { render } from '@faire/mjml-react/utils/render'
import { DefaultBotNotificationEmail } from 'emails'
import { DefaultBotNotificationEmail } from '@typebot.io/emails'
import {
PublicTypebot,
ResultInSession,
@ -11,12 +11,12 @@ import {
SendEmailOptions,
SessionState,
SmtpCredentials,
} from 'models'
} from '@typebot.io/schemas'
import { createTransport } from 'nodemailer'
import Mail from 'nodemailer/lib/mailer'
import { byId, isEmpty, isNotDefined, omit } from 'utils'
import { parseAnswers } from 'utils/results'
import { decrypt } from 'utils/api'
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'
export const executeSendEmailBlock = async (

View File

@ -1,9 +1,9 @@
import test, { expect } from '@playwright/test'
import { createSmtpCredentials } from '../../../../test/utils/databaseActions'
import { createId } from '@paralleldrive/cuid2'
import { importTypebotInDatabase } from 'utils/playwright/databaseActions'
import { importTypebotInDatabase } from '@typebot.io/lib/playwright/databaseActions'
import { getTestAsset } from '@/test/utils/playwright'
import { SmtpCredentials } from 'models'
import { SmtpCredentials } from '@typebot.io/schemas'
export const mockSmtpCredentials: SmtpCredentials['data'] = {
from: {

View File

@ -20,10 +20,10 @@ import {
KeyValue,
ReplyLog,
ResultInSession,
} from 'models'
} from '@typebot.io/schemas'
import { stringify } from 'qs'
import { byId, omit } from 'utils'
import { parseAnswers } from 'utils/results'
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'

View File

@ -8,9 +8,9 @@ import {
Typebot,
TypebotLinkBlock,
Variable,
} from 'models'
import { isInputBlock, byId, isNotDefined } from 'utils'
import { parseResultHeader } from 'utils/results'
} from '@typebot.io/schemas'
import { isInputBlock, byId, isNotDefined } from '@typebot.io/lib'
import { parseResultHeader } from '@typebot.io/lib/results'
export const parseSampleResult =
(

View File

@ -1,10 +1,10 @@
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { HttpMethod } from 'models'
import { HttpMethod } from '@typebot.io/schemas'
import {
createWebhook,
importTypebotInDatabase,
} from 'utils/playwright/databaseActions'
} from '@typebot.io/lib/playwright/databaseActions'
import { getTestAsset } from '@/test/utils/playwright'
const typebotId = createId()

View File

@ -7,8 +7,8 @@ import {
LogicalOperator,
SessionState,
Variable,
} from 'models'
import { isNotDefined, isDefined } from 'utils'
} from '@typebot.io/schemas'
import { isNotDefined, isDefined } from '@typebot.io/lib'
export const executeCondition = (
{ typebot: { variables } }: SessionState,

View File

@ -4,8 +4,8 @@ import {
createPortalEdge,
} from '@/features/chat/api/utils/addEdgeToTypebot'
import { TRPCError } from '@trpc/server'
import { SessionState } from 'models'
import { JumpBlock } from 'models/features/blocks/logic/jump'
import { SessionState } from '@typebot.io/schemas'
import { JumpBlock } from '@typebot.io/schemas/features/blocks/logic/jump'
export const executeJumpBlock = (
state: SessionState,

View File

@ -1,7 +1,7 @@
import { ExecuteLogicResponse } from '@/features/chat'
import { parseVariables } from '@/features/variables'
import { RedirectBlock, SessionState } from 'models'
import { sanitizeUrl } from 'utils'
import { RedirectBlock, SessionState } from '@typebot.io/schemas'
import { sanitizeUrl } from '@typebot.io/lib'
export const executeRedirect = (
{ typebot: { variables } }: SessionState,

View File

@ -4,7 +4,7 @@ import {
parseCorrectValueType,
extractVariablesFromText,
} from '@/features/variables'
import { ScriptBlock, SessionState } from 'models'
import { ScriptBlock, SessionState } from '@typebot.io/schemas'
export const executeScript = (
{ typebot: { variables } }: SessionState,

View File

@ -1,5 +1,5 @@
import { SessionState, SetVariableBlock, Variable } from 'models'
import { byId } from 'utils'
import { SessionState, SetVariableBlock, Variable } from '@typebot.io/schemas'
import { byId } from '@typebot.io/lib'
import {
parseVariables,
parseCorrectValueType,

View File

@ -10,8 +10,8 @@ import {
SessionState,
TypebotInSession,
Variable,
} from 'models'
import { byId } from 'utils'
} from '@typebot.io/schemas'
import { byId } from '@typebot.io/lib'
export const executeTypebotLink = async (
state: SessionState,

View File

@ -1,5 +1,5 @@
import prisma from '@/lib/prisma'
import { PublicTypebot, Typebot } from 'models'
import { PublicTypebot, Typebot } from '@typebot.io/schemas'
type Props = {
isPreview: boolean

View File

@ -1,13 +1,13 @@
import prisma from '@/lib/prisma'
import { canReadTypebots } from '@/utils/api/dbRules'
import { User } from 'db'
import { User } from '@typebot.io/prisma'
import {
LogicBlockType,
PublicTypebot,
Typebot,
TypebotLinkBlock,
} from 'models'
import { isDefined } from 'utils'
} from '@typebot.io/schemas'
import { isDefined } from '@typebot.io/lib'
type Props = {
typebots: Pick<PublicTypebot, 'groups'>[]

View File

@ -1,6 +1,6 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import { importTypebotInDatabase } from 'utils/playwright/databaseActions'
import { importTypebotInDatabase } from '@typebot.io/lib/playwright/databaseActions'
const typebotId = 'cl0ibhi7s0018n21aarlmg0cm'
const linkedTypebotId = 'cl0ibhv8d0130n21aw8doxhj5'

View File

@ -1,6 +1,6 @@
import { ExecuteLogicResponse } from '@/features/chat'
import { parseVariables } from '@/features/variables'
import { SessionState, WaitBlock } from 'models'
import { SessionState, WaitBlock } from '@typebot.io/schemas'
export const executeWait = async (
{ typebot: { variables } }: SessionState,

View File

@ -8,7 +8,7 @@ import {
import prisma from '@/lib/prisma'
import { publicProcedure } from '@/utils/server/trpc'
import { TRPCError } from '@trpc/server'
import { Prisma } from 'db'
import { Prisma } from '@typebot.io/prisma'
import {
ChatReply,
chatReplySchema,
@ -22,14 +22,14 @@ import {
Typebot,
Variable,
VariableWithValue,
} from 'models'
} from '@typebot.io/schemas'
import {
continueBotFlow,
getSession,
setResultAsCompleted,
startBotFlow,
} from '../utils'
import { env, isDefined, omit } from 'utils'
import { env, isDefined, omit } from '@typebot.io/lib'
export const sendMessageProcedure = publicProcedure
.meta({

View File

@ -1,5 +1,5 @@
import { createId } from '@paralleldrive/cuid2'
import { SessionState, Edge } from 'models'
import { SessionState, Edge } from '@typebot.io/schemas'
export const addEdgeToTypebot = (
state: SessionState,

View File

@ -7,7 +7,7 @@ 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 'db'
import { Prisma } from '@typebot.io/prisma'
import got from 'got'
import {
Block,
@ -18,8 +18,8 @@ import {
InputBlockType,
ResultInSession,
SessionState,
} from 'models'
import { isInputBlock, isNotDefined } from 'utils'
} from '@typebot.io/schemas'
import { isInputBlock, isNotDefined } from '@typebot.io/lib'
import { executeGroup } from './executeGroup'
import { getNextGroup } from './getNextGroup'

View File

@ -8,14 +8,14 @@ import {
InputBlockType,
RuntimeOptions,
SessionState,
} from 'models'
} from '@typebot.io/schemas'
import {
isBubbleBlock,
isDefined,
isInputBlock,
isIntegrationBlock,
isLogicBlock,
} from 'utils'
} from '@typebot.io/lib'
import { executeLogic } from './executeLogic'
import { getNextGroup } from './getNextGroup'
import { executeIntegration } from './executeIntegration'

View File

@ -4,7 +4,11 @@ import { executeGoogleSheetBlock } from '@/features/blocks/integrations/googleSh
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 { IntegrationBlock, IntegrationBlockType, SessionState } from 'models'
import {
IntegrationBlock,
IntegrationBlockType,
SessionState,
} from '@typebot.io/schemas'
import { ExecuteIntegrationResponse } from '../../types'
export const executeIntegration =

View File

@ -3,7 +3,7 @@ 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 { LogicBlock, LogicBlockType, SessionState } from 'models'
import { LogicBlock, LogicBlockType, SessionState } from '@typebot.io/schemas'
import { ExecuteLogicResponse } from '../../types'
import { executeScript } from '@/features/blocks/logic/script/executeScript'
import { executeJumpBlock } from '@/features/blocks/logic/jump/executeJumpBlock'

View File

@ -1,5 +1,5 @@
import { byId } from 'utils'
import { Group, SessionState } from 'models'
import { byId } from '@typebot.io/lib'
import { Group, SessionState } from '@typebot.io/schemas'
export type NextGroup = {
group: Group

View File

@ -1,5 +1,5 @@
import prisma from '@/lib/prisma'
import { ChatSession } from 'models'
import { ChatSession } from '@typebot.io/schemas'
export const getSession = async (
sessionId: string

View File

@ -1,5 +1,5 @@
import { TRPCError } from '@trpc/server'
import { ChatReply, SessionState } from 'models'
import { ChatReply, SessionState } from '@typebot.io/schemas'
import { executeGroup } from './executeGroup'
import { getNextGroup } from './getNextGroup'

View File

@ -2,13 +2,13 @@ import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import prisma from '@/lib/prisma'
import { HttpMethod, SendMessageInput } from 'models'
import { HttpMethod, SendMessageInput } from '@typebot.io/schemas'
import {
createWebhook,
deleteTypebots,
deleteWebhooks,
importTypebotInDatabase,
} from 'utils/playwright/databaseActions'
} from '@typebot.io/lib/playwright/databaseActions'
test.afterEach(async () => {
await deleteWebhooks(['chat-webhook-id'])

View File

@ -1,4 +1,4 @@
import { ChatReply, SessionState } from 'models'
import { ChatReply, SessionState } from '@typebot.io/schemas'
export type EdgeId = string

View File

@ -1,5 +1,5 @@
import prisma from '@/lib/prisma'
import { isNotDefined } from 'utils'
import { isNotDefined } from '@typebot.io/lib'
export const saveLog = (
status: 'error' | 'success',

View File

@ -1,5 +1,5 @@
import { Result } from 'models'
import { sendRequest } from 'utils'
import { Result } from '@typebot.io/schemas'
import { sendRequest } from '@typebot.io/lib'
export const createResultQuery = async (typebotId: string) => {
return sendRequest<{ result: Result; hasReachedLimit: boolean }>({

View File

@ -1,5 +1,5 @@
import { Result } from 'models'
import { sendRequest } from 'utils'
import { Result } from '@typebot.io/schemas'
import { sendRequest } from '@typebot.io/lib'
export const updateResultQuery = async (
resultId: string,

View File

@ -1,7 +1,7 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { importTypebotInDatabase } from 'utils/playwright/databaseActions'
import { importTypebotInDatabase } from '@typebot.io/lib/playwright/databaseActions'
test('Big groups should work as expected', async ({ page }) => {
const typebotId = createId()

View File

@ -5,9 +5,12 @@ import {
defaultTextInputOptions,
InputBlockType,
Metadata,
} from 'models'
import { createTypebots, updateTypebot } from 'utils/playwright/databaseActions'
import { parseDefaultGroupWithBlock } from 'utils/playwright/databaseHelpers'
} from '@typebot.io/schemas'
import {
createTypebots,
updateTypebot,
} from '@typebot.io/lib/playwright/databaseActions'
import { parseDefaultGroupWithBlock } from '@typebot.io/lib/playwright/databaseHelpers'
test('Result should be overwritten on page refresh', async ({ page }) => {
const typebotId = createId()

View File

@ -1,13 +1,13 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { Plan } from 'db'
import { defaultSettings } from 'models'
import { Plan } from '@typebot.io/prisma'
import { defaultSettings } from '@typebot.io/schemas'
import {
createWorkspaces,
importTypebotInDatabase,
injectFakeResults,
} from 'utils/playwright/databaseActions'
} from '@typebot.io/lib/playwright/databaseActions'
test('should not start if chat limit is reached', async ({ page, context }) => {
await test.step('Free plan', async () => {

View File

@ -1,12 +1,12 @@
import prisma from '@/lib/prisma'
import { WorkspaceRole } from 'db'
import { WorkspaceRole } from '@typebot.io/prisma'
import {
sendAlmostReachedChatsLimitEmail,
sendReachedChatsLimitEmail,
} from 'emails'
import { Workspace } from 'models'
import { env, isDefined } from 'utils'
import { getChatsLimit } from 'utils/pricing'
} from '@typebot.io/emails'
import { Workspace } from '@typebot.io/schemas'
import { env, isDefined } from '@typebot.io/lib'
import { getChatsLimit } from '@typebot.io/lib/pricing'
const LIMIT_EMAIL_TRIGGER_PERCENT = 0.8

View File

@ -1,5 +1,5 @@
import { Variable, VariableWithValue } from 'models'
import { isNotDefined } from 'utils'
import { Variable, VariableWithValue } from '@typebot.io/schemas'
import { isNotDefined } from '@typebot.io/lib'
export const transformStringVariablesToList =
(variables: Variable[]) =>

View File

@ -7,8 +7,8 @@ import {
Variable,
VariableWithUnknowValue,
VariableWithValue,
} from 'models'
import { isDefined, isNotDefined } from 'utils'
} from '@typebot.io/schemas'
import { isDefined, isNotDefined } from '@typebot.io/lib'
export const stringContainsVariable = (str: string): boolean =>
/\{\{(.*?)\}\}/g.test(str)

View File

@ -1,7 +1,7 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { importTypebotInDatabase } from 'utils/playwright/databaseActions'
import { importTypebotInDatabase } from '@typebot.io/lib/playwright/databaseActions'
test('should correctly be injected', async ({ page }) => {
const typebotId = createId()