{
  "version": 3,
  "sources": ["../../src/document/components/chrome/siteSettings/Plans/Stripe/addOns/api/getAddOnPlanId.ts", "../../src/document/components/chrome/siteSettings/Plans/Stripe/addOns/api/putAddOnSubscription.ts"],
  "sourcesContent": ["import type { AddOnLicenseType, ProjectLicensePeriod, ProjectLicenseType } from \"@framerjs/app-shared\"\nimport {\n\tLicensesSettingsStatus,\n\tgetLicensesSettings,\n\tisPaidLicenseSettings,\n} from \"document/components/chrome/siteSettings/Plans/Stripe/api/licenseSettings.ts\"\n\n/**\n * Fetches licenses settings and finds the addOn plan id,\n * given project license type and period.\n */\nexport async function getAddOnPlanId({\n\tprojectLicenseType,\n\taddonLicenseType,\n\tperiod,\n\tisBillingV3,\n}: {\n\tprojectLicenseType: ProjectLicenseType\n\taddonLicenseType: AddOnLicenseType\n\tperiod: ProjectLicensePeriod\n\tisBillingV3: boolean\n}): Promise<string | null> {\n\tconst abortController = new AbortController()\n\tconst licensesSettingsResponse = await getLicensesSettings(undefined, abortController.signal, isBillingV3)\n\tif (licensesSettingsResponse.status !== LicensesSettingsStatus.Success) {\n\t\treturn null\n\t}\n\n\tconst currentLicenseSetting = licensesSettingsResponse.licensesSettings.find(\n\t\t({ licenseType }) => licenseType === projectLicenseType,\n\t)\n\n\tif (currentLicenseSetting && isPaidLicenseSettings(currentLicenseSetting)) {\n\t\tconst price = currentLicenseSetting.prices[period]\n\t\treturn price.addOns[addonLicenseType]?.planId ?? null\n\t}\n\n\treturn null\n}\n", "import { ApiError } from \"@framerjs/app-shared\"\nimport { assertNever, getLogger } from \"@framerjs/shared\"\nimport { isSitePlanCancelledError } from \"document/components/chrome/siteSettings/Plans/Stripe/api/errors/paymentDeclinedError.ts\"\nimport {\n\tPaymentErrorStatus,\n\tclassifyPaymentError,\n\thandleRequiredAction,\n\ttype PaymentError,\n\ttype PutSubscriptionResponseAction,\n} from \"document/components/chrome/siteSettings/Plans/Stripe/api/errors/paymentError.ts\"\nimport { apiFetcher } from \"web/lib/apiFetcher.ts\"\n\nconst log = getLogger(\"putAddOnSubscription\")\n\nexport enum PutAddOnSubscriptionStatus {\n\tSuccess,\n\tPaymentError,\n\tSitePlanCancelled,\n}\n\nenum AddOnSubscriptionResults {\n\tSuccess = \"success\",\n\tActionRequired = \"action_required\",\n}\n\ntype AddOnSubscriptionApiResponse =\n\t| { result: AddOnSubscriptionResults.Success }\n\t| { result: AddOnSubscriptionResults.ActionRequired; action: PutSubscriptionResponseAction }\n\ntype PutAddOnSubscriptionResponse =\n\t| { status: PutAddOnSubscriptionStatus.Success }\n\t| { status: PutAddOnSubscriptionStatus.SitePlanCancelled }\n\t| { status: PutAddOnSubscriptionStatus.PaymentError; error: PaymentError }\n\nexport async function putAddOnSubscription(\n\tprojectId: string,\n\taddOnBody: { plan: string; quantity: number },\n\tisBillingV3: boolean,\n): Promise<PutAddOnSubscriptionResponse> {\n\ttry {\n\t\tconst url = isBillingV3\n\t\t\t? `/web/v4/projects/${projectId}/subscription`\n\t\t\t: `/web/v2/projects/${projectId}/subscription/addons?supportsNextActions=true`\n\t\tconst body = isBillingV3 ? { addOns: [addOnBody] } : addOnBody\n\t\tconst addOnResponse: AddOnSubscriptionApiResponse = await apiFetcher.put(url, body)\n\t\tswitch (addOnResponse.result) {\n\t\t\tcase AddOnSubscriptionResults.Success:\n\t\t\t\treturn { status: PutAddOnSubscriptionStatus.Success }\n\t\t\tcase AddOnSubscriptionResults.ActionRequired: {\n\t\t\t\tconst error = await handleRequiredAction(addOnResponse.action)\n\t\t\t\treturn error\n\t\t\t\t\t? { status: PutAddOnSubscriptionStatus.PaymentError, error }\n\t\t\t\t\t: { status: PutAddOnSubscriptionStatus.Success }\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tassertNever(addOnResponse, \"Unexpected addOn subscription response\")\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof ApiError && isSitePlanCancelledError(error)) {\n\t\t\treturn { status: PutAddOnSubscriptionStatus.SitePlanCancelled }\n\t\t}\n\t\tconst paymentError = classifyPaymentError(error)\n\t\tif (paymentError) return { status: PutAddOnSubscriptionStatus.PaymentError, error: paymentError }\n\t\tlog.reportError(error)\n\t\treturn {\n\t\t\tstatus: PutAddOnSubscriptionStatus.PaymentError,\n\t\t\terror: { status: PaymentErrorStatus.UnhandledError },\n\t\t}\n\t}\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;AAWA,eAAsB,eAAe;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAK2B;AAC1B,QAAM,kBAAkB,IAAI,gBAAgB;AAC5C,QAAM,2BAA2B,MAAM,oBAAoB,QAAW,gBAAgB,QAAQ,WAAW;AACzG,MAAI,yBAAyB,4BAA2C;AACvE,WAAO;AAAA,EACR;AAEA,QAAM,wBAAwB,yBAAyB,iBAAiB;AAAA,IACvE,CAAC,EAAE,YAAY,MAAM,gBAAgB;AAAA,EACtC;AAEA,MAAI,yBAAyB,sBAAsB,qBAAqB,GAAG;AAC1E,UAAM,QAAQ,sBAAsB,OAAO,MAAM;AACjD,WAAO,MAAM,OAAO,gBAAgB,GAAG,UAAU;AAAA,EAClD;AAEA,SAAO;AACR;;;AC1BA,IAAM,MAAM,UAAU,sBAAsB;AAsB5C,eAAsB,qBACrB,WACA,WACA,aACwC;AACxC,MAAI;AACH,UAAM,MAAM,cACT,oBAAoB,SAAS,kBAC7B,oBAAoB,SAAS;AAChC,UAAM,OAAO,cAAc,EAAE,QAAQ,CAAC,SAAS,EAAE,IAAI;AACrD,UAAM,gBAA8C,MAAM,WAAW,IAAI,KAAK,IAAI;AAClF,YAAQ,cAAc,QAAQ;AAAA,MAC7B,KAAK;AACJ,eAAO,EAAE,QAAQ,gBAAmC;AAAA,MACrD,KAAK,wCAAyC;AAC7C,cAAM,QAAQ,MAAM,qBAAqB,cAAc,MAAM;AAC7D,eAAO,QACJ,EAAE,QAAQ,sBAAyC,MAAM,IACzD,EAAE,QAAQ,gBAAmC;AAAA,MACjD;AAAA,MACA;AACC,oBAAY,eAAe,wCAAwC;AAAA,IACrE;AAAA,EACD,SAAS,OAAO;AACf,QAAI,iBAAiB,YAAY,yBAAyB,KAAK,GAAG;AACjE,aAAO,EAAE,QAAQ,0BAA6C;AAAA,IAC/D;AACA,UAAM,eAAe,qBAAqB,KAAK;AAC/C,QAAI,aAAc,QAAO,EAAE,QAAQ,sBAAyC,OAAO,aAAa;AAChG,QAAI,YAAY,KAAK;AACrB,WAAO;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,EAAE,+BAA0C;AAAA,IACpD;AAAA,EACD;AACD;",
  "names": []
}
