(
type: UsageType,
subscriptionId: string,
usageCacheManager: UsageCacheManager,
currentUsage: number
)
| 48 | |
| 49 | // For usage that doesn't renew per month, we just get the count from database and check |
| 50 | export const checkUsageLimit = async ( |
| 51 | type: UsageType, |
| 52 | subscriptionId: string, |
| 53 | usageCacheManager: UsageCacheManager, |
| 54 | currentUsage: number |
| 55 | ) => { |
| 56 | if (!usageCacheManager || !subscriptionId) return |
| 57 | |
| 58 | const quotas = await usageCacheManager.getQuotas(subscriptionId) |
| 59 | |
| 60 | let limit = -1 |
| 61 | switch (type) { |
| 62 | case 'flows': |
| 63 | limit = quotas[LICENSE_QUOTAS.FLOWS_LIMIT] |
| 64 | break |
| 65 | case 'users': |
| 66 | limit = quotas[LICENSE_QUOTAS.USERS_LIMIT] + (Math.max(quotas[LICENSE_QUOTAS.ADDITIONAL_SEATS_LIMIT], 0) || 0) |
| 67 | break |
| 68 | } |
| 69 | |
| 70 | if (limit === -1) return |
| 71 | |
| 72 | if (currentUsage > limit) { |
| 73 | throw new InternalFlowiseError(StatusCodes.PAYMENT_REQUIRED, `Limit exceeded: ${type}`) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // As predictions limit renew per month, we set to cache with 1 month TTL |
| 78 | export const updatePredictionsUsage = async ( |
no test coverage detected