{"version":3,"file":"index-DCTOUsXi.js","sources":["../../../app/assets/javascripts/app/authentication/contact_info_caching/index.ts"],"sourcesContent":["\nimport Promise from \"plugins/bluebird/index\"\nimport * as Sentry from \"@sentry/browser\"\n\nimport {\n get as get_current_authenticated_user,\n ResultTypeEnums as GetCurrentAuthenticatedUserTypes,\n} from \"app/resources/current_authenticated_user/get/index\"\n\nimport { setContactInfoData } from \"app/local_storages/contact_info_storage\"\n\nimport auth_ee from \"app/authentication/manager\"\n\nimport {\n performance,\n} from \"plugins/user-timing-polyfill\"\n\nlet last_contact_info_sync_promise = Promise.resolve()\n\nconst cacheContactInfoToLocal = () => {\n performance.mark(\"spacious_mark__cacheContactInfoToLocal__get_current_authenticated_user__start\")\n\n return get_current_authenticated_user()\n .then(({result_type, data}) => {\n performance.mark(\"spacious_mark__cacheContactInfoToLocal__get_current_authenticated_user__end\")\n performance.measure(\n \"spacious_measure__cacheContactInfoToLocal__get_current_authenticated_user\",\n \"spacious_mark__cacheContactInfoToLocal__get_current_authenticated_user__start\",\n \"spacious_mark__cacheContactInfoToLocal__get_current_authenticated_user__end\",\n )\n\n switch (result_type) {\n case GetCurrentAuthenticatedUserTypes.SUCCESS: {\n setContactInfoData({\n user_authentication_handle: data.authentication_handle,\n contact_name: data.contact_name,\n contact_email_address: data.contact_email_address,\n contact_phone_number: data.contact_phone_number,\n })\n // Sneaking Sentry code in here to avoid duplicate requests\n Sentry.setUser({\n id: data.authentication_handle,\n email: data.contact_email_address,\n username: data.contact_name,\n })\n break\n }\n case GetCurrentAuthenticatedUserTypes.NOT_SIGNED_IN: {\n setContactInfoData({\n user_authentication_handle: null,\n })\n break\n }\n default: {\n break\n }\n }\n\n if (result_type !== GetCurrentAuthenticatedUserTypes.SUCCESS) {\n return\n }\n\n setContactInfoData({\n user_authentication_handle: data.authentication_handle,\n contact_name: data.contact_name,\n contact_email_address: data.contact_email_address,\n contact_phone_number: data.contact_phone_number,\n })\n })\n}\n\nconst onLoad = () => {\n auth_ee.on(\"sign_up:success:action\", () => {\n last_contact_info_sync_promise = cacheContactInfoToLocal()\n last_contact_info_sync_promise.done()\n })\n auth_ee.on(\"sign_in:success:action\", () => {\n last_contact_info_sync_promise = cacheContactInfoToLocal()\n last_contact_info_sync_promise.done()\n })\n\n // Do this after TTI since not very urgent task\n window.spacious_post_tti_tasks = window.spacious_post_tti_tasks || []\n window.spacious_post_tti_tasks.push(() => {\n cacheContactInfoToLocal().done()\n })\n\n return Promise.resolve()\n}\n\nconst getLastContactInfoSyncPromise = () => last_contact_info_sync_promise\n\nexport {\n onLoad,\n getLastContactInfoSyncPromise,\n}\n"],"names":["last_contact_info_sync_promise","Promise","cacheContactInfoToLocal","performance","get_current_authenticated_user","result_type","data","GetCurrentAuthenticatedUserTypes","setContactInfoData","Sentry.setUser","onLoad","auth_ee","getLastContactInfoSyncPromise"],"mappings":"+nBAiBA,IAAIA,EAAiCC,EAAQ,QAAQ,EAErD,MAAMC,EAA0B,KAC9BC,EAAY,KAAK,+EAA+E,EAEzFC,EACN,EAAA,KAAK,CAAC,CAAC,YAAAC,EAAa,KAAAC,KAAU,CAQ7B,OAPAH,EAAY,KAAK,6EAA6E,EAClFA,EAAA,QACV,4EACA,gFACA,6EACF,EAEQE,EAAa,CACnB,KAAKE,EAAiC,QAAS,CAC1BC,EAAA,CACjB,2BAA4BF,EAAK,sBACjC,aAA4BA,EAAK,aACjC,sBAA4BA,EAAK,sBACjC,qBAA4BA,EAAK,oBAAA,CAClC,EAEDG,EAAe,CACb,GAAYH,EAAK,sBACjB,MAAYA,EAAK,sBACjB,SAAYA,EAAK,YAAA,CAClB,EACD,KAAA,CAEF,KAAKC,EAAiC,cAAe,CAChCC,EAAA,CACjB,2BAA4B,IAAA,CAC7B,EACD,KAAA,CAIF,CAGEH,IAAgBE,EAAiC,SAIlCC,EAAA,CACjB,2BAA4BF,EAAK,sBACjC,aAA4BA,EAAK,aACjC,sBAA4BA,EAAK,sBACjC,qBAA4BA,EAAK,oBAAA,CAClC,CAAA,CACF,GAGGI,EAAS,KACLC,EAAA,GAAG,yBAA0B,IAAM,CACzCX,EAAiCE,EAAwB,EACzDF,EAA+B,KAAK,CAAA,CACrC,EACOW,EAAA,GAAG,yBAA0B,IAAM,CACzCX,EAAiCE,EAAwB,EACzDF,EAA+B,KAAK,CAAA,CACrC,EAGM,OAAA,wBAA0B,OAAO,yBAA2B,CAAC,EAC7D,OAAA,wBAAwB,KAAK,IAAM,CACxCE,EAAA,EAA0B,KAAK,CAAA,CAChC,EAEMD,EAAQ,QAAQ,GAGnBW,EAAgC,IAAMZ"}