2
0

🧑‍💻 Improve env variables type safety and management (#718)

Closes #679
This commit is contained in:
Baptiste Arnaud
2023-08-28 09:13:53 +02:00
committed by GitHub
parent a23a8c4456
commit 786e5cb582
148 changed files with 1550 additions and 1293 deletions

View File

@@ -1,18 +1,18 @@
import got from 'got'
import { TelemetryEvent } from '@typebot.io/schemas/features/telemetry'
import { isEmpty, isNotEmpty } from '../utils'
import { isNotEmpty } from '../utils'
import { env } from '@typebot.io/env'
export const sendTelemetryEvents = async (events: TelemetryEvent[]) => {
if (events.length === 0) return { message: 'No events to send' }
if (isEmpty(process.env.TELEMETRY_WEBHOOK_URL))
return { message: 'Telemetry not enabled' }
if (!env.TELEMETRY_WEBHOOK_URL) return { message: 'Telemetry not enabled' }
try {
await got.post(process.env.TELEMETRY_WEBHOOK_URL, {
await got.post(env.TELEMETRY_WEBHOOK_URL, {
json: { events },
headers: {
authorization: isNotEmpty(process.env.TELEMETRY_WEBHOOK_BEARER_TOKEN)
? `Bearer ${process.env.TELEMETRY_WEBHOOK_BEARER_TOKEN}`
authorization: env.TELEMETRY_WEBHOOK_BEARER_TOKEN
? `Bearer ${env.TELEMETRY_WEBHOOK_BEARER_TOKEN}`
: undefined,
},
})