♻️ Remove @typebot.io/schemas from @typebot.io/lib
This commit is contained in:
167
packages/billing/constants.ts
Normal file
167
packages/billing/constants.ts
Normal file
@ -0,0 +1,167 @@
|
||||
import { Plan } from '@typebot.io/prisma'
|
||||
import type { Stripe } from 'stripe'
|
||||
|
||||
export const prices = {
|
||||
[Plan.STARTER]: 39,
|
||||
[Plan.PRO]: 89,
|
||||
} as const
|
||||
|
||||
export const chatsLimits = {
|
||||
[Plan.FREE]: 200,
|
||||
[Plan.STARTER]: 2000,
|
||||
[Plan.PRO]: 10000,
|
||||
} as const
|
||||
|
||||
export const seatsLimits = {
|
||||
[Plan.FREE]: 1,
|
||||
[Plan.OFFERED]: 1,
|
||||
[Plan.STARTER]: 2,
|
||||
[Plan.PRO]: 5,
|
||||
[Plan.LIFETIME]: 8,
|
||||
} as const
|
||||
|
||||
export const starterChatTiers = [
|
||||
{
|
||||
up_to: 2000,
|
||||
flat_amount: 0,
|
||||
},
|
||||
{
|
||||
up_to: 2500,
|
||||
flat_amount: 1000,
|
||||
},
|
||||
{
|
||||
up_to: 3000,
|
||||
flat_amount: 2000,
|
||||
},
|
||||
{
|
||||
up_to: 3500,
|
||||
flat_amount: 3000,
|
||||
},
|
||||
{
|
||||
up_to: 4000,
|
||||
flat_amount: 4000,
|
||||
},
|
||||
{
|
||||
up_to: 'inf',
|
||||
unit_amount: 2,
|
||||
},
|
||||
] satisfies Stripe.PriceCreateParams.Tier[]
|
||||
|
||||
export const proChatTiers = [
|
||||
{
|
||||
up_to: 10000,
|
||||
flat_amount: 0,
|
||||
},
|
||||
{
|
||||
up_to: 15000,
|
||||
flat_amount: 5000,
|
||||
},
|
||||
{
|
||||
up_to: 20000,
|
||||
flat_amount: 9500,
|
||||
},
|
||||
{
|
||||
up_to: 30000,
|
||||
flat_amount: 18000,
|
||||
},
|
||||
{
|
||||
up_to: 40000,
|
||||
flat_amount: 26000,
|
||||
},
|
||||
{
|
||||
up_to: 50000,
|
||||
flat_amount: 33500,
|
||||
},
|
||||
{
|
||||
up_to: 60000,
|
||||
flat_amount: 40700,
|
||||
},
|
||||
{
|
||||
up_to: 70000,
|
||||
flat_amount: 47700,
|
||||
},
|
||||
{
|
||||
up_to: 80000,
|
||||
flat_amount: 54500,
|
||||
},
|
||||
{
|
||||
up_to: 90000,
|
||||
flat_amount: 61100,
|
||||
},
|
||||
{
|
||||
up_to: 100000,
|
||||
flat_amount: 67500,
|
||||
},
|
||||
{
|
||||
up_to: 120000,
|
||||
flat_amount: 79900,
|
||||
},
|
||||
{
|
||||
up_to: 140000,
|
||||
flat_amount: 91900,
|
||||
},
|
||||
{
|
||||
up_to: 160000,
|
||||
flat_amount: 103700,
|
||||
},
|
||||
{
|
||||
up_to: 180000,
|
||||
flat_amount: 115300,
|
||||
},
|
||||
{
|
||||
up_to: 200000,
|
||||
flat_amount: 126700,
|
||||
},
|
||||
{
|
||||
up_to: 300000,
|
||||
flat_amount: 181700,
|
||||
},
|
||||
{
|
||||
up_to: 400000,
|
||||
flat_amount: 234700,
|
||||
},
|
||||
{
|
||||
up_to: 500000,
|
||||
flat_amount: 285700,
|
||||
},
|
||||
{
|
||||
up_to: 600000,
|
||||
flat_amount: 335700,
|
||||
},
|
||||
{
|
||||
up_to: 700000,
|
||||
flat_amount: 384700,
|
||||
},
|
||||
{
|
||||
up_to: 800000,
|
||||
flat_amount: 432700,
|
||||
},
|
||||
{
|
||||
up_to: 900000,
|
||||
flat_amount: 479700,
|
||||
},
|
||||
{
|
||||
up_to: 1000000,
|
||||
flat_amount: 525700,
|
||||
},
|
||||
{
|
||||
up_to: 1200000,
|
||||
flat_amount: 617100,
|
||||
},
|
||||
{
|
||||
up_to: 1400000,
|
||||
flat_amount: 707900,
|
||||
},
|
||||
{
|
||||
up_to: 1600000,
|
||||
flat_amount: 797900,
|
||||
},
|
||||
{
|
||||
up_to: 1800000,
|
||||
flat_amount: 887300,
|
||||
},
|
||||
{
|
||||
up_to: 'inf',
|
||||
unit_amount_decimal: '0.442',
|
||||
},
|
||||
] satisfies Stripe.PriceCreateParams.Tier[]
|
21
packages/billing/formatPrice.ts
Normal file
21
packages/billing/formatPrice.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { guessIfUserIsEuropean } from './guessIfUserIsEuropean'
|
||||
|
||||
type FormatPriceParams = {
|
||||
currency?: 'eur' | 'usd'
|
||||
maxFractionDigits?: number
|
||||
}
|
||||
|
||||
export const formatPrice = (
|
||||
price: number,
|
||||
{ currency, maxFractionDigits = 0 }: FormatPriceParams = {
|
||||
maxFractionDigits: 0,
|
||||
}
|
||||
) => {
|
||||
const isEuropean = guessIfUserIsEuropean()
|
||||
const formatter = new Intl.NumberFormat(isEuropean ? 'fr-FR' : 'en-US', {
|
||||
style: 'currency',
|
||||
currency: currency?.toUpperCase() ?? (isEuropean ? 'EUR' : 'USD'),
|
||||
maximumFractionDigits: maxFractionDigits,
|
||||
})
|
||||
return formatter.format(price)
|
||||
}
|
19
packages/billing/getChatsLimit.ts
Normal file
19
packages/billing/getChatsLimit.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Plan } from '@typebot.io/prisma'
|
||||
import { chatsLimits } from './constants'
|
||||
import { Workspace } from '@typebot.io/schemas'
|
||||
|
||||
export const getChatsLimit = ({
|
||||
plan,
|
||||
customChatsLimit,
|
||||
}: Pick<Workspace, 'plan'> & {
|
||||
customChatsLimit?: Workspace['customChatsLimit']
|
||||
}) => {
|
||||
if (
|
||||
plan === Plan.UNLIMITED ||
|
||||
plan === Plan.LIFETIME ||
|
||||
plan === Plan.OFFERED
|
||||
)
|
||||
return 'inf'
|
||||
if (plan === Plan.CUSTOM) return customChatsLimit ?? 'inf'
|
||||
return chatsLimits[plan]
|
||||
}
|
12
packages/billing/getSeatsLimit.ts
Normal file
12
packages/billing/getSeatsLimit.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Workspace } from '@typebot.io/schemas'
|
||||
import { seatsLimits } from './constants'
|
||||
import { Plan } from '@typebot.io/prisma'
|
||||
|
||||
export const getSeatsLimit = ({
|
||||
plan,
|
||||
customSeatsLimit,
|
||||
}: Pick<Workspace, 'plan' | 'customSeatsLimit'>) => {
|
||||
if (plan === Plan.UNLIMITED) return 'inf'
|
||||
if (plan === Plan.CUSTOM) return customSeatsLimit ? customSeatsLimit : 'inf'
|
||||
return seatsLimits[plan]
|
||||
}
|
56
packages/billing/guessIfUserIsEuropean.ts
Normal file
56
packages/billing/guessIfUserIsEuropean.ts
Normal file
@ -0,0 +1,56 @@
|
||||
const europeanUnionCountryCodes = [
|
||||
'AT',
|
||||
'BE',
|
||||
'BG',
|
||||
'CY',
|
||||
'CZ',
|
||||
'DE',
|
||||
'DK',
|
||||
'EE',
|
||||
'ES',
|
||||
'FI',
|
||||
'FR',
|
||||
'GR',
|
||||
'HR',
|
||||
'HU',
|
||||
'IE',
|
||||
'IT',
|
||||
'LT',
|
||||
'LU',
|
||||
'LV',
|
||||
'MT',
|
||||
'NL',
|
||||
'PL',
|
||||
'PT',
|
||||
'RO',
|
||||
'SE',
|
||||
'SI',
|
||||
'SK',
|
||||
]
|
||||
|
||||
const europeanUnionExclusiveLanguageCodes = [
|
||||
'fr',
|
||||
'de',
|
||||
'it',
|
||||
'el',
|
||||
'pl',
|
||||
'fi',
|
||||
'nl',
|
||||
'hr',
|
||||
'cs',
|
||||
'hu',
|
||||
'ro',
|
||||
'sl',
|
||||
'sv',
|
||||
'bg',
|
||||
]
|
||||
|
||||
export const guessIfUserIsEuropean = () => {
|
||||
if (typeof window === 'undefined') return false
|
||||
return window.navigator.languages.some((language) => {
|
||||
const [languageCode, countryCode] = language.split('-')
|
||||
return countryCode
|
||||
? europeanUnionCountryCodes.includes(countryCode)
|
||||
: europeanUnionExclusiveLanguageCodes.includes(languageCode)
|
||||
})
|
||||
}
|
20
packages/billing/package.json
Normal file
20
packages/billing/package.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@typebot.io/billing",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Baptiste Arnaud",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@typebot.io/prisma": "workspace:*",
|
||||
"@typebot.io/schemas": "workspace:*",
|
||||
"stripe": "12.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typebot.io/tsconfig": "workspace:*"
|
||||
}
|
||||
}
|
8
packages/billing/tsconfig.json
Normal file
8
packages/billing/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@typebot.io/tsconfig/base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["node_modules"],
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2021", "DOM"]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user