AiHelper.mjs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // @ts-check
  2. // Initially, this functions lived in PaymentProviderEntities.js,
  3. // but it was moved to this file to prevent circular dependency issue
  4. export const AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE = 'assistant'
  5. export const AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE = 'assistant-annual'
  6. export const AI_ADD_ON_CODE = 'assistant'
  7. /**
  8. * Returns whether the given plan code is a standalone AI plan
  9. *
  10. * @param {string | null | undefined} planCode
  11. * @return {boolean}
  12. */
  13. export function isStandaloneAiAddOnPlanCode(planCode) {
  14. return (
  15. planCode === AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE ||
  16. planCode === AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE
  17. )
  18. }
  19. /**
  20. * Returns whether subscription change will have have the ai bundle once the change is processed
  21. *
  22. * @param {Record<string, any>} subscriptionChange The subscription change object coming from payment provider
  23. * type should be PaymentProviderSubscriptionChange but if imported here, it creates a circular dependency
  24. * TODO: fix this when moved to es modules
  25. *
  26. * @return {boolean}
  27. */
  28. export function subscriptionChangeIsAiAssistUpgrade(subscriptionChange) {
  29. return Boolean(
  30. isStandaloneAiAddOnPlanCode(subscriptionChange.nextPlanCode) ||
  31. subscriptionChange.nextAddOns?.some(
  32. /** @param {any} addOn */ addOn => addOn.code === AI_ADD_ON_CODE
  33. )
  34. )
  35. }
  36. export default {
  37. AI_ADD_ON_CODE,
  38. AI_ASSIST_STANDALONE_MONTHLY_PLAN_CODE,
  39. AI_ASSIST_STANDALONE_ANNUAL_PLAN_CODE,
  40. isStandaloneAiAddOnPlanCode,
  41. subscriptionChangeIsAiAssistUpgrade,
  42. }