Skip to content

Commit

Permalink
👷 Transpile components for better DX
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Sep 27, 2022
1 parent 898367a commit c1dd4d4
Show file tree
Hide file tree
Showing 147 changed files with 343 additions and 485 deletions.
22 changes: 16 additions & 6 deletions apps/builder/contexts/TypebotContext/actions/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,26 @@ const duplicateBlockDraft =
(groupId: string) =>
(block: Block): Block => {
const blockId = cuid()
if (blockHasItems(block))
return {
...block,
groupId,
id: blockId,
items: block.items.map(duplicateItemDraft(blockId)),
outgoingEdgeId: undefined,
} as Block
if (isWebhookBlock(block))
return {
...block,
groupId,
id: blockId,
webhookId: cuid(),
outgoingEdgeId: undefined,
}
return {
...block,
groupId,
id: blockId,
items: blockHasItems(block)
? block.items.map(duplicateItemDraft(blockId))
: undefined,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
webhookId: isWebhookBlock(block) ? cuid() : undefined,
outgoingEdgeId: undefined,
}
}
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/libs/google-sheets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Credentials as CredentialsFromDb } from 'db'
import { OAuth2Client, Credentials } from 'google-auth-library'
import { GoogleSheetsCredentialsData } from 'models'
import { decrypt, encrypt, isDefined } from 'utils'
import { isDefined } from 'utils'
import { decrypt, encrypt } from 'utils/api'
import prisma from './prisma'

export const oauth2Client = new OAuth2Client(
Expand Down
9 changes: 6 additions & 3 deletions apps/builder/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { withSentryConfig } = require('@sentry/nextjs')
const path = require('path')
const withTM = require('next-transpile-modules')(['utils', 'models'])

/** @type {import('next').NextConfig} */
const nextConfig = {
Expand All @@ -15,6 +16,8 @@ const sentryWebpackPluginOptions = {
silent: true,
}

module.exports = process.env.SENTRY_AUTH_TOKEN
? withSentryConfig(nextConfig, sentryWebpackPluginOptions)
: nextConfig
module.exports = withTM(
process.env.SENTRY_AUTH_TOKEN
? withSentryConfig(nextConfig, sentryWebpackPluginOptions)
: nextConfig
)
2 changes: 1 addition & 1 deletion apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.1.0",
"license": "AGPL-3.0-or-later",
"scripts": {
"dx": "pnpm dev",
"dev": "ENVSH_ENV=.env.local bash ../../env.sh next dev -p 3000",
"build": "next build",
"start": "next start",
Expand Down Expand Up @@ -108,6 +107,7 @@
"eslint-config-next": "12.3.0",
"eslint-plugin-react": "^7.31.8",
"models": "workspace:*",
"next-transpile-modules": "^9.0.0",
"typescript": "^4.8.3",
"utils": "workspace:*"
}
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/pages/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import {
badRequest,
encrypt,
forbidden,
methodNotAllowed,
notAuthenticated,
} from 'utils'
encrypt,
} from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/credentials/[credentialsId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import prisma from 'libs/prisma'
import { googleSheetsScopes } from './consent-url'
import { stringify } from 'querystring'
import { CredentialsType } from 'models'
import { badRequest, encrypt, notAuthenticated } from 'utils'
import { badRequest, encrypt, notAuthenticated } from 'utils/api'
import { oauth2Client } from 'libs/google-sheets'
import { withSentry } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/customDomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
forbidden,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/customDomains/[domain].ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
import { got } from 'got'
import { getAuthenticatedUser } from 'services/api/utils'

Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DashboardFolder, WorkspaceRole } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/folders/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DashboardFolder } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/integrations/email/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SmtpCredentialsData } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { createTransport } from 'nodemailer'
import { getAuthenticatedUser } from 'services/api/utils'
import { notAuthenticated } from 'utils'
import { notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { drive } from '@googleapis/drive'
import { getAuthenticatedGoogleClient } from 'libs/google-sheets'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
import { setUser, withSentry } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { GoogleSpreadsheet } from 'google-spreadsheet'
import { getAuthenticatedGoogleClient } from 'libs/google-sheets'
import {
badRequest,
isDefined,
methodNotAllowed,
notAuthenticated,
} from 'utils'
import { isDefined } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'
import { withSentry, setUser } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'

Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/mock/webhook-easy-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
import { methodNotAllowed } from 'utils/api'

const handler = (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/mock/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
import { methodNotAllowed } from 'utils/api'

const handler = (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/publicTypebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InputBlockType, PublicTypebot } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { canPublishFileInput } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/publicTypebots/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InputBlockType, PublicTypebot } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { canPublishFileInput } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/storage/upload-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
generatePresignedUrl,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'

const handler = async (
req: NextApiRequest,
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/stripe/billing-portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
forbidden,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'
import Stripe from 'stripe'
import { withSentry } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/stripe/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
forbidden,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'
import Stripe from 'stripe'
import { withSentry } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/pages/api/stripe/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { isDefined } from 'utils'
import {
badRequest,
forbidden,
isDefined,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'
import Stripe from 'stripe'
import { withSentry } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/stripe/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
import { methodNotAllowed } from 'utils/api'
import Stripe from 'stripe'
import Cors from 'micro-cors'
import { buffer } from 'micro'
Expand Down
7 changes: 6 additions & 1 deletion apps/builder/pages/api/typebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import { parseNewTypebot } from 'services/typebots/typebots'
import { badRequest, methodNotAllowed, notAuthenticated, notFound } from 'utils'
import {
badRequest,
methodNotAllowed,
notAuthenticated,
notFound,
} from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/typebots/[typebotId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canReadTypebot, canWriteTypebot } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/typebots/[typebotId]/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canReadTypebot } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated, notFound } from 'utils'
import { methodNotAllowed, notAuthenticated, notFound } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canReadTypebot } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canEditGuests } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
8 changes: 4 additions & 4 deletions apps/builder/pages/api/typebots/[typebotId]/invitations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { CollaborationType, WorkspaceRole } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canReadTypebot, canWriteTypebot } from 'services/api/dbRules'
import { sendEmailNotification } from 'utils'
import { getAuthenticatedUser } from 'services/api/utils'
import {
sendEmailNotification,
badRequest,
env,
forbidden,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'
import { getAuthenticatedUser } from 'services/api/utils'
import { env } from 'utils'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canEditGuests } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/typebots/[typebotId]/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
forbidden,
methodNotAllowed,
notAuthenticated,
} from 'utils'
} from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { canReadTypebot } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PublicTypebot } from 'models'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'
import { withSentry } from '@sentry/nextjs'
import { getAuthenticatedUser } from 'services/api/utils'
import { canReadTypebot } from 'services/api/dbRules'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Stats } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { canReadTypebot } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/typebots/[typebotId]/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultWebhookAttributes } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { canWriteTypebot } from 'services/api/dbRules'
import { getAuthenticatedUser } from 'services/api/utils'
import { forbidden, methodNotAllowed, notAuthenticated } from 'utils'
import { forbidden, methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/pages/api/users/[userId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
import { methodNotAllowed, notAuthenticated } from 'utils/api'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
Expand Down
Loading

0 comments on commit c1dd4d4

Please sign in to comment.