bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
import {
|
|
GetWorkspacePlanPriceId,
|
|
GetWorkspacePlanProductAndPriceIds,
|
|
GetWorkspacePlanProductId
|
|
} from '@/modules/gatekeeper/domain/billing'
|
|
import { getStringFromEnv } from '@/modules/shared/helpers/envHelper'
|
|
import { NotImplementedError } from '@/modules/shared/errors'
|
|
|
|
const loadProductAndPriceIds: GetWorkspacePlanProductAndPriceIds = () => ({
|
|
team: {
|
|
productId: getStringFromEnv('WORKSPACE_TEAM_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: {
|
|
gbp: getStringFromEnv('WORKSPACE_MONTHLY_TEAM_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_MONTHLY_TEAM_SEAT_USD_STRIPE_PRICE_ID')
|
|
},
|
|
yearly: {
|
|
gbp: getStringFromEnv('WORKSPACE_YEARLY_TEAM_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_YEARLY_TEAM_SEAT_USD_STRIPE_PRICE_ID')
|
|
}
|
|
},
|
|
teamUnlimited: {
|
|
productId: getStringFromEnv('WORKSPACE_TEAM_UNLIMITED_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: {
|
|
gbp: getStringFromEnv(
|
|
'WORKSPACE_MONTHLY_TEAM_UNLIMITED_SEAT_GBP_STRIPE_PRICE_ID'
|
|
),
|
|
usd: getStringFromEnv('WORKSPACE_MONTHLY_TEAM_UNLIMITED_SEAT_USD_STRIPE_PRICE_ID')
|
|
},
|
|
yearly: {
|
|
gbp: getStringFromEnv('WORKSPACE_YEARLY_TEAM_UNLIMITED_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_YEARLY_TEAM_UNLIMITED_SEAT_USD_STRIPE_PRICE_ID')
|
|
}
|
|
},
|
|
pro: {
|
|
productId: getStringFromEnv('WORKSPACE_PRO_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: {
|
|
gbp: getStringFromEnv('WORKSPACE_MONTHLY_PRO_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_MONTHLY_PRO_SEAT_USD_STRIPE_PRICE_ID')
|
|
},
|
|
yearly: {
|
|
gbp: getStringFromEnv('WORKSPACE_YEARLY_PRO_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_YEARLY_PRO_SEAT_USD_STRIPE_PRICE_ID')
|
|
}
|
|
},
|
|
proUnlimited: {
|
|
productId: getStringFromEnv('WORKSPACE_PRO_UNLIMITED_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: {
|
|
gbp: getStringFromEnv('WORKSPACE_MONTHLY_PRO_UNLIMITED_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_MONTHLY_PRO_UNLIMITED_SEAT_USD_STRIPE_PRICE_ID')
|
|
},
|
|
yearly: {
|
|
gbp: getStringFromEnv('WORKSPACE_YEARLY_PRO_UNLIMITED_SEAT_GBP_STRIPE_PRICE_ID'),
|
|
usd: getStringFromEnv('WORKSPACE_YEARLY_PRO_UNLIMITED_SEAT_USD_STRIPE_PRICE_ID')
|
|
}
|
|
}
|
|
})
|
|
|
|
let priceIds: ReturnType<typeof getWorkspacePlanProductAndPriceIds> | null = null
|
|
|
|
export const getWorkspacePlanProductAndPriceIds: GetWorkspacePlanProductAndPriceIds =
|
|
() => {
|
|
if (!priceIds) priceIds = loadProductAndPriceIds()
|
|
return priceIds
|
|
}
|
|
|
|
export const getWorkspacePlanPriceId: GetWorkspacePlanPriceId = ({
|
|
workspacePlan,
|
|
billingInterval,
|
|
currency
|
|
}) => {
|
|
const plan = getWorkspacePlanProductAndPriceIds()[workspacePlan]
|
|
const priceIds = plan[billingInterval]
|
|
return priceIds[currency]
|
|
}
|
|
|
|
export const getWorkspacePlanProductId: GetWorkspacePlanProductId = ({
|
|
workspacePlan
|
|
}) => {
|
|
const planMetadata = getWorkspacePlanProductAndPriceIds()[workspacePlan]
|
|
if (!planMetadata) {
|
|
throw new NotImplementedError(`Plan {workspacePlan} not supported`, {
|
|
info: { workspacePlan }
|
|
})
|
|
}
|
|
|
|
return planMetadata.productId
|
|
}
|