Skip to content

Commit

Permalink
⚗️ Add inspect user script
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 21, 2023
1 parent 3be39cb commit 931540b
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
130 changes: 130 additions & 0 deletions packages/scripts/inspectUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { PrismaClient } from '@typebot.io/prisma'
import { promptAndSetEnvironment } from './utils'
import prompts from 'prompts'
import { isEmpty } from '@typebot.io/lib'

const inspectUser = async () => {
await promptAndSetEnvironment('production')
const response = await prompts({
type: 'text',
name: 'email',
message: 'User email',
})

if (isEmpty(response.email)) process.exit()
const prisma = new PrismaClient({
log: [{ emit: 'event', level: 'query' }, 'info', 'warn', 'error'],
})

const user = await prisma.user.findFirst({
where: {
email: response.email,
},
select: {
name: true,
lastActivityAt: true,
company: true,
onboardingCategories: true,
workspaces: {
where: {
role: 'ADMIN',
},
select: {
workspace: {
select: {
name: true,
plan: true,
members: {
where: {
user: { email: { not: response.email } },
},
},
additionalChatsIndex: true,
additionalStorageIndex: true,
typebots: {
orderBy: {
updatedAt: 'desc',
},
select: {
id: true,
name: true,
createdAt: true,
updatedAt: true,
publishedTypebot: {
select: {
typebot: {
select: { publicId: true },
},
},
},
},
},
},
},
},
},
},
})

if (!user) {
console.log('User not found')
process.exit()
}

console.log('Name:', user.name)
console.log('Last activity:', user.lastActivityAt.toLocaleDateString())
console.log('Company:', user.company)
console.log('Onboarding categories:', user.onboardingCategories)
console.log('Total workspaces:', user.workspaces.length)
console.log('Workspaces:')

for (const workspace of user.workspaces) {
console.log(' - Name:', workspace.workspace.name)
console.log(' Plan:', workspace.workspace.plan)
console.log(' Members:', workspace.workspace.members.length + 1)
console.log(
' Additional chats:',
workspace.workspace.additionalChatsIndex
)
console.log(
' Additional storage:',
workspace.workspace.additionalStorageIndex
)
console.log(' Typebots:', workspace.workspace.typebots.length)

for (const typebot of workspace.workspace.typebots) {
console.log(' - Name:', typebot.name)
console.log(' Created:', typebot.createdAt.toLocaleDateString())
console.log(
' Last updated:',
typebot.updatedAt.toLocaleDateString()
)
console.log(
' Public ID:',
typebot.publishedTypebot?.typebot.publicId
)
console.log(
' URL:',
`https://app.typebot.io/typebots/${typebot.id}/edit`
)

if (!typebot.publishedTypebot) continue

const totalTraffic = await prisma.result.count({
where: {
typebotId: typebot.id,
isArchived: false,
},
select: {
_all: true,
hasStarted: true,
},
})

console.log(' Total traffic:', totalTraffic._all)
console.log(' Started:', totalTraffic.hasStarted)
}
}
}

inspectUser()
3 changes: 2 additions & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"db:bulkUpdate": "tsx bulkUpdate.ts",
"db:fixTypebots": "tsx fixTypebots.ts",
"telemetry:sendTotalResultsDigest": "tsx sendTotalResultsDigest.ts",
"sendAlertEmails": "tsx sendAlertEmails.ts"
"sendAlertEmails": "tsx sendAlertEmails.ts",
"inspectUser": "tsx inspectUser.ts"
},
"devDependencies": {
"@typebot.io/emails": "workspace:*",
Expand Down

0 comments on commit 931540b

Please sign in to comment.