Files
Verso/services/web/app/src/Features/Subscription/AiHelper.mjs
T
Anna Claire FieldsandCopybot 6113c6c291 Enable TS noImplicitAny in web (#31636)
GitOrigin-RevId: 18881694770f2476c475f8fef4c6a2678a2a12fe
2026-03-27 09:05:30 +00:00

47 lines
1.5 KiB
JavaScript

// @ts-check
// Initially, this functions lived in PaymentProviderEntities.js,
// but it was moved to this file to prevent circular dependency issue
export const AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE = 'assistant'
export const AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE = 'assistant-annual'
export const AI_ADD_ON_CODE = 'assistant'
/**
* Returns whether the given plan code is a standalone AI plan
*
* @param {string | null | undefined} planCode
* @return {boolean}
*/
export function isStandaloneAiAddOnPlanCode(planCode) {
return (
planCode === AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE ||
planCode === AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE
)
}
/**
* Returns whether subscription change will have have the ai bundle once the change is processed
*
* @param {Record<string, any>} subscriptionChange The subscription change object coming from payment provider
* type should be PaymentProviderSubscriptionChange but if imported here, it creates a circular dependency
* TODO: fix this when moved to es modules
*
* @return {boolean}
*/
export function subscriptionChangeIsAiAssistUpgrade(subscriptionChange) {
return Boolean(
isStandaloneAiAddOnPlanCode(subscriptionChange.nextPlanCode) ||
subscriptionChange.nextAddOns?.some(
/** @param {any} addOn */ addOn => addOn.code === AI_ADD_ON_CODE
)
)
}
export default {
AI_ADD_ON_CODE,
AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE,
AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE,
isStandaloneAiAddOnPlanCode,
subscriptionChangeIsAiAssistUpgrade,
}