MCPcopy
hub / github.com/FlowiseAI/Flowise / getQuotas

Method getQuotas

packages/server/src/UsageCacheManager.ts:110–158  ·  view source on GitHub ↗
(subscriptionId: string, withoutCache: boolean = false)

Source from the content-addressed store, hash-verified

108 }
109
110 public async getQuotas(subscriptionId: string, withoutCache: boolean = false): Promise<Record<string, number>> {
111 const stripeManager = await StripeManager.getInstance()
112 if (!stripeManager || !subscriptionId) {
113 return UNLIMITED_QUOTAS
114 }
115
116 // Skip cache if withoutCache is true
117 if (!withoutCache) {
118 const subscriptionData = await this.getSubscriptionDataFromCache(subscriptionId)
119 if (subscriptionData?.quotas) {
120 return subscriptionData.quotas
121 }
122 }
123
124 // If not in cache, retrieve from Stripe
125 const subscription = await stripeManager.getStripe().subscriptions.retrieve(subscriptionId)
126 const items = subscription.items.data
127 if (items.length === 0) {
128 return DISABLED_QUOTAS
129 }
130
131 const productId = items[0].price.product as string
132 const product = await stripeManager.getStripe().products.retrieve(productId)
133 const productMetadata = product.metadata
134
135 if (!productMetadata || Object.keys(productMetadata).length === 0) {
136 return DISABLED_QUOTAS
137 }
138
139 const quotas: Record<string, number> = {}
140 for (const key in productMetadata) {
141 if (key.startsWith('quota:')) {
142 quotas[key] = parseInt(productMetadata[key])
143 }
144 }
145
146 const additionalSeatsItem = subscription.items.data.find(
147 (item) => (item.price.product as string) === process.env.ADDITIONAL_SEAT_ID
148 )
149 quotas[LICENSE_QUOTAS.ADDITIONAL_SEATS_LIMIT] = additionalSeatsItem?.quantity || 0
150
151 // Update subscription data cache with quotas
152 await this.updateSubscriptionDataToCache(subscriptionId, {
153 quotas,
154 subsriptionDetails: stripeManager.getSubscriptionObject(subscription)
155 })
156
157 return quotas
158 }
159
160 public async getSubscriptionDataFromCache(subscriptionId: string) {
161 const cacheKey = `subscription:${subscriptionId}`

Callers 6

getCurrentUsageFunction · 0.80
checkUsageLimitFunction · 0.80
updatePredictionsUsageFunction · 0.80
checkPredictionsFunction · 0.80
checkStorageFunction · 0.80

Calls 5

getStripeMethod · 0.80
getSubscriptionObjectMethod · 0.80
getInstanceMethod · 0.45

Tested by

no test coverage detected