From 7b19a3c3dfa8dec8873c2e10a08797260e8a68ea Mon Sep 17 00:00:00 2001 From: Dustin Do Date: Sun, 22 Sep 2024 10:27:19 +0700 Subject: [PATCH] feat(utils): add PLAN_CONFIG --- packages/utilities/src/config.ts | 57 ++++++++++++++++++++++++++++++++ packages/utilities/src/index.ts | 1 + 2 files changed, 58 insertions(+) create mode 100644 packages/utilities/src/config.ts diff --git a/packages/utilities/src/config.ts b/packages/utilities/src/config.ts new file mode 100644 index 00000000..27a8e57c --- /dev/null +++ b/packages/utilities/src/config.ts @@ -0,0 +1,57 @@ +export enum UserEntitlement { + Saver = 'saver', + Growth = 'growth', + Wealth = 'wealth', +} + +export type PlanConfig = { + maxTransactions: number + maxBudgets: number + maxWallets: number + canCreateCategories: boolean + maxAiTransactionPerDay: number + maxJoinableBudgets: number + maxOwnedBudgets: number + transactionRetentionDays: number +} + +/** Follows [[RFC] Monetization #132](https://github.com/get6pm/6pm/issues/132). */ +export const PLAN_CONFIG: Record = { + saver: { + maxTransactions: Infinity, + maxBudgets: 3, + maxWallets: 3, + canCreateCategories: false, + maxAiTransactionPerDay: 2, + maxJoinableBudgets: Infinity, + maxOwnedBudgets: 1, + transactionRetentionDays: 60, + }, + growth: { + maxTransactions: Infinity, + maxBudgets: 6, + maxWallets: 6, + canCreateCategories: true, + maxAiTransactionPerDay: 10, + maxJoinableBudgets: Infinity, + maxOwnedBudgets: 5, + transactionRetentionDays: 180, + }, + wealth: { + maxTransactions: Infinity, + maxBudgets: Infinity, + maxWallets: Infinity, + canCreateCategories: true, + maxAiTransactionPerDay: 25, + maxJoinableBudgets: Infinity, + maxOwnedBudgets: Infinity, + transactionRetentionDays: Infinity, + }, +} + +export function getPlanConfig< + P extends UserEntitlement, + K extends keyof PlanConfig, +>(plan: P, key: K): PlanConfig[K] | null { + return PLAN_CONFIG[plan][key] ?? null +} diff --git a/packages/utilities/src/index.ts b/packages/utilities/src/index.ts index 7ad1509d..35c04e1c 100644 --- a/packages/utilities/src/index.ts +++ b/packages/utilities/src/index.ts @@ -1,3 +1,4 @@ export * from './date/dayjs' export * from './date/period' export * from './transactions' +export * from './config'