Skip to content

Commit

Permalink
♻️ (viewer) Remove barrel exports and flatten folder arch
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 15, 2023
1 parent 44d7a0b commit f3af07b
Show file tree
Hide file tree
Showing 113 changed files with 398 additions and 426 deletions.
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions apps/viewer/src/components/TypebotPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublicTypebot, 'createdAt' | 'updatedAt'> & {
Expand Down
1 change: 0 additions & 1 deletion apps/viewer/src/features/answers/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/viewer/src/features/auth/api/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { deepParseVariable } from '@/features/variables/utils'
import {
SessionState,
VariableWithValue,
ChoiceInputBlock,
ItemType,
} from '@typebot.io/schemas'
import { isDefined } from '@typebot.io/lib'
import { deepParseVariables } from '@/features/variables/deepParseVariable'

export const injectVariableValuesInButtonsInputBlock =
(variables: SessionState['typebot']['variables']) =>
Expand All @@ -27,5 +27,5 @@ export const injectVariableValuesInButtonsInputBlock =
})),
}
}
return deepParseVariable(variables)(block)
return deepParseVariables(variables)(block)
}
1 change: 0 additions & 1 deletion apps/viewer/src/features/blocks/inputs/date/api/index.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion apps/viewer/src/features/blocks/inputs/email/api/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion apps/viewer/src/features/blocks/inputs/phone/api/index.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion apps/viewer/src/features/blocks/inputs/url/api/index.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -85,7 +83,7 @@ export const executeChatwootBlock = (
args: extractVariablesFromText(variables)(chatwootCode).map(
(variable) => ({
id: variable.id,
value: parseCorrectValueType(variable.value),
value: parseGuessedValueType(variable.value),
})
),
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 = (
Expand All @@ -10,7 +10,7 @@ export const executeGoogleAnalyticsBlock = (
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: [
{
googleAnalytics: deepParseVariable(variables)(block.options),
googleAnalytics: deepParseVariables(variables)(block.options),
lastBubbleBlockId,
},
],
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,7 +21,7 @@ export const getRow = async (
options,
}: { outgoingEdgeId?: string; options: GoogleSheetsGetOptions }
): Promise<ExecuteIntegrationResponse> => {
const { sheetId, cellsToExtract, referenceCell, filter } = deepParseVariable(
const { sheetId, cellsToExtract, referenceCell, filter } = deepParseVariables(
state.typebot.variables
)(options)
if (!sheetId) return { outgoingEdgeId }
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
}
}, {})
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,7 +18,7 @@ export const updateRow = async (
options,
}: { outgoingEdgeId?: string; options: GoogleSheetsUpdateRowOptions }
): Promise<ExecuteIntegrationResponse> => {
const { sheetId, referenceCell } = deepParseVariable(variables)(options)
const { sheetId, referenceCell } = deepParseVariables(variables)(options)
if (!options.cellsToUpsert || !sheetId || !referenceCell)
return { outgoingEdgeId }

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ExecuteLogicResponse } from '@/features/chat'
import { findUniqueVariableValue, parseVariables } from '@/features/variables'
import {
Comparison,
ComparisonOperators,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 5 additions & 7 deletions apps/viewer/src/features/blocks/logic/script/executeScript.ts
Original file line number Diff line number Diff line change
@@ -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 = (
Expand All @@ -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),
})
)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
Loading

1 comment on commit f3af07b

@vercel
Copy link

@vercel vercel bot commented on f3af07b Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.