{"version":3,"file":"DmdK_pQb.js","sources":["../../../../stores/oauth_providers.js"],"sourcesContent":["import { defineStore } from \"pinia\"\nimport { useContentStore } from \"~/composables/stores/useContentStore.js\"\n\nexport const providersEndpoint = \"/airtable/providers\"\n\nexport const useOAuthProvidersStore = defineStore(\"oauth_providers\", () => {\n const contentStore = useContentStore()\n const alert = useAlert()\n\n const googleDrivePermission = 'https://www.googleapis.com/auth/drive.file'\n\n const services = computed(() => {\n return [\n {\n name: 'google',\n title: 'Google',\n icon: 'mdi:google',\n enabled: true\n }\n ]\n })\n\n const getService = (service) => {\n return services.value.find((item) => item.name === service)\n }\n\n const fetchOAuthProviders = () => {\n contentStore.resetState()\n contentStore.startLoading()\n\n return airtableFormsFetch(providersEndpoint).then(\n (data) => {\n contentStore.save(data)\n contentStore.stopLoading()\n },\n )\n }\n\n const connect = (service, redirect = false) => {\n contentStore.resetState()\n contentStore.startLoading()\n\n const intention = new URL(window.location.href).pathname\n\n airtableFormsFetch(`/settings/providers/connect/${service}`, {\n method: 'POST',\n body: {\n ...redirect ? { intention } : {},\n }\n })\n .then((data) => {\n window.location.href = data.url\n })\n .catch((error) => {\n try {\n alert.error(error.data.message)\n } catch (e) {\n alert.error(\"An error occurred while connecting an account\")\n }\n })\n .finally(() => {\n contentStore.stopLoading()\n })\n }\n\n const guestConnect = (service, redirect = false) => {\n contentStore.resetState()\n contentStore.startLoading()\n\n const intention = new URL(window.location.href).pathname\n\n airtableFormsFetch(`/oauth/connect/${service}`, {\n method: 'POST',\n body: {\n ...redirect ? { intention } : {},\n }\n })\n .then((data) => {\n window.location.href = data.url\n })\n .catch((error) => {\n try {\n alert.error(error.data.message)\n } catch (e) {\n alert.error(\"An error occurred while connecting an account\")\n }\n })\n .finally(() => {\n contentStore.stopLoading()\n })\n }\n\n const providers = computed(() => contentStore.getAll.value)\n\n return {\n ...contentStore,\n googleDrivePermission,\n services,\n getService,\n fetchOAuthProviders,\n providers,\n connect,\n guestConnect\n }\n})\n"],"names":["providersEndpoint","useOAuthProvidersStore","defineStore","contentStore","useContentStore","alert","useAlert","googleDrivePermission","services","computed","getService","service","item","fetchOAuthProviders","airtableFormsFetch","data","connect","redirect","intention","error","guestConnect","providers"],"mappings":"uXAGO,MAAMA,EAAoB,sBAEpBC,EAAyBC,EAAY,kBAAmB,IAAM,CACzE,MAAMC,EAAeC,EAAiB,EAChCC,EAAQC,EAAU,EAElBC,EAAwB,6CAExBC,EAAWC,EAAS,IACjB,CACL,CACE,KAAM,SACN,MAAO,SACP,KAAM,aACN,QAAS,EACV,CACF,CACF,EAEKC,EAAcC,GACXH,EAAS,MAAM,KAAMI,GAASA,EAAK,OAASD,CAAO,EAGtDE,EAAsB,KAC1BV,EAAa,WAAY,EACzBA,EAAa,aAAc,EAEpBW,EAAmBd,CAAiB,EAAE,KAC1Ce,GAAS,CACRZ,EAAa,KAAKY,CAAI,EACtBZ,EAAa,YAAa,CAC3B,CACF,GAGGa,EAAU,CAACL,EAASM,EAAW,KAAU,CAC7Cd,EAAa,WAAY,EACzBA,EAAa,aAAc,EAE3B,MAAMe,EAAY,IAAI,IAAI,OAAO,SAAS,IAAI,EAAE,SAEhDJ,EAAmB,+BAA+BH,CAAO,GAAI,CAC3D,OAAQ,OACR,KAAM,CACJ,GAAGM,EAAW,CAAE,UAAAC,CAAS,EAAK,CAAE,CACjC,CACP,CAAK,EACE,KAAMH,GAAS,CACd,OAAO,SAAS,KAAOA,EAAK,GACpC,CAAO,EACA,MAAOI,GAAU,CAChB,GAAI,CACFd,EAAM,MAAMc,EAAM,KAAK,OAAO,CAC/B,MAAW,CACVd,EAAM,MAAM,+CAA+C,CAC5D,CACT,CAAO,EACA,QAAQ,IAAM,CACbF,EAAa,YAAa,CAClC,CAAO,CACJ,EAEKiB,EAAe,CAACT,EAASM,EAAW,KAAU,CAClDd,EAAa,WAAY,EACzBA,EAAa,aAAc,EAE3B,MAAMe,EAAY,IAAI,IAAI,OAAO,SAAS,IAAI,EAAE,SAEhDJ,EAAmB,kB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