Skip to content

Commit

Permalink
🐛 Improve parse runtime env reading function
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Aug 28, 2023
1 parent efd4600 commit 036b407
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.1.18",
"version": "0.1.19",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { ScriptToExecute } from '@typebot.io/schemas'
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor

export const executeScript = async ({ content, args }: ScriptToExecute) => {
const func = AsyncFunction(
...args.map((arg) => arg.id),
parseContent(content)
)
try {
const func = AsyncFunction(
...args.map((arg) => arg.id),
parseContent(content)
)
await func(...args.map((arg) => arg.value))
} catch (err) {
console.error(err)
Expand Down
6 changes: 3 additions & 3 deletions packages/embeds/js/src/utils/guessApiHost.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { env } from '@typebot.io/env'
import { getRuntimeVariable } from '@typebot.io/env/getRuntimeVariable'

const cloudViewerUrl = 'https://viewer.typebot.io'

export const guessApiHost = () =>
env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ??
env.NEXT_PUBLIC_VIEWER_URL[0] ??
getRuntimeVariable('NEXT_PUBLIC_VIEWER_INTERNAL_URL') ??
getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ??
cloudViewerUrl
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.1.18",
"version": "0.1.19",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.1.18",
"version": "0.1.19",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
10 changes: 1 addition & 9 deletions packages/env/env.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'

declare const window: {
__ENV: any
}

const getRuntimeVariable = (key: string) => {
if (typeof window === 'undefined') return process.env[key]
return window.__ENV[key]
}
import { getRuntimeVariable } from './getRuntimeVariable'

const boolean = z.enum(['true', 'false']).transform((value) => value === 'true')

Expand Down
10 changes: 10 additions & 0 deletions packages/env/getRuntimeVariable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare const window: {
__ENV?: any
}

const isBrowser = () => Boolean(typeof window !== 'undefined' && window.__ENV)

export const getRuntimeVariable = (key: string) => {
if (isBrowser()) return window.__ENV[key]
return process.env[key]
}
2 changes: 1 addition & 1 deletion packages/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"esbuild": "^0.19.1"
},
"scripts": {
"build": "esbuild env.ts --packages=external --outfile=dist/env.mjs"
"build": "esbuild env.ts --bundle --packages=external --format=esm --outfile=dist/env.mjs"
}
}

4 comments on commit 036b407

@vercel
Copy link

@vercel vercel bot commented on 036b407 Aug 28, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 036b407 Aug 28, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 036b407 Aug 28, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 036b407 Aug 28, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

faqs.nigerias.io
feiraodehoje.com
georgemarttt.com
go.chatbotcv.com
haymanevents.com
kw.wpwakanda.com
localamor.online
lojamundobox.com
myrentalhost.com
silvercop.com.br
silvercop.online
typebot.aloe.bot
support.wawplus.com
survey1.digienge.io
surveys.essiell.com
test.botscientis.us
test.getreview.help
test.reventepro.com
typebot.stillio.app
typebot.stillio.com
vg.onewebcenter.com
wa.onewebcenter.com
web.draleticiah.com
whatsdigital.online
wordsandimagery.com
88584434.therpm.club
92109660.therpm.club
app.horadelucrar.com
assistent.m-vogel.de
ativandograna.online
bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.buenanoticia.fun
bot.conhecaojogo.com
bot.cotemeuplano.com
bot.gameincrivel.com
bot.gamesimples.club
bot.grupodojo.com.br
bot.jogoquelucra.com
bot.leadbooster.help
bot.mycompay.reviews
bot.socialcliques.me
cha.onewebcenter.com
chat.gnipharmahq.com
chat.hayurihijab.com
chat.jottagreens.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
detetivepatricia.com
drapamela.gikpro.com
drgisellegarcia.site
forms.bonanza.design
hello.advergreen.com
infomakeracademy.com
kuiz.sistemniaga.com
leoborges-app.online
linspecteuremma.site
malayanboosterhq.com
menukb.wpwakanda.com
offer.botscientis.us
viewer-v2-typebot-io.vercel.app
mdb.assessoria.jbatista.progenbr.com
mdb.assessoria.mauricio.progenbr.com
mdb.evento.autocadastro.progenbr.com
form.shopmercedesbenzsouthorlando.com
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

Please sign in to comment.