{"version":3,"file":"currentSessions-d1315250.js","sources":["../../src/components/pages/composables/currentSessions.ts"],"sourcesContent":["import api from \"@/app/api\";\nimport { getById } from \"@/app/apiutils\";\nimport { billingPlanService } from \"@/app/services/generated/billingplanService\";\nimport type { User } from \"@/app/services/generated/userService\";\nimport { userService } from \"@/app/services/generated/userService\";\nimport type { LicensedUserSession } from \"@/app/services/generated/usersessionService\";\nimport { userSessionService } from \"@/app/services/generated/usersessionService\";\nimport { routes } from \"@/app/ui/navigation/menuItems\";\nimport { withLoading } from \"@/components/composables/componentTools\";\nimport GridConfigurationBuilder from \"@/components/controls/grid/builder/GridConfigurationBuilder\";\nimport BmGridStateRepository from \"@/components/controls/grid/state/BmGridStateRepository\";\nimport { translateWithParams, useI18n } from \"@/plugins/i18n\";\nimport { useVuetify } from \"@/plugins/vuetify\";\nimport { useRouter } from \"@/router/router\";\nimport userStore from \"@/store/modules/userStore\";\nimport type { Instant } from \"@js-joda/core\";\nimport { Duration, LocalDateTime } from \"@js-joda/core\";\nimport { computed, onBeforeUnmount, onMounted, ref, shallowRef } from \"vue\";\n\nexport function useCurrentSessions() {\n const { $m, $t } = useI18n();\n const { router } = useRouter();\n const { $vuetify } = useVuetify();\n\n const items = shallowRef([]);\n const users = shallowRef([]);\n const refreshTimer = ref(0);\n const tenantMaxSessions = ref(0);\n const gridState = BmGridStateRepository.getEphemeral();\n\n const gridConfiguration = computed(() => {\n let maker = new GridConfigurationBuilder({\n itemId: (item) => item.sessionId,\n title: $m.auth_current_sessions,\n });\n maker.addTextColumn(\n $m.keys.users_name,\n (item) => getById(users.value, item.userId)?.name ?? null\n );\n maker.addTextColumn(\n $m.keys.users_job_title,\n (item) => getById(users.value, item.userId)?.jobTitle ?? null\n );\n\n maker\n .addIntegerColumn($m.keys.auth_last_activity_time, (item) =>\n minutesSinceActive(item.lastAccess)\n )\n .defaultSort(0, true);\n\n maker.addBooleanCheckMarkColumn(\n $m.keys.auth_is_current_session,\n (item) => item.isCurrentSession\n );\n\n maker\n .addActionsColumn()\n .showNarrow(false)\n .withAction(\n $m.auth_end_session,\n (item) => endSession(item),\n (item) => !item.isCurrentSession\n );\n\n return maker.build();\n });\n\n const loadPrerequisites = async () => {\n let billingPlan;\n [users.value, billingPlan] = await Promise.all([\n userService.getAllUsers(api.tenantGroupId).then((x) => Object.freeze(x)),\n billingPlanService.getBillingStatus(api.tenantGroupId),\n ]);\n tenantMaxSessions.value = billingPlan.permittedConcurrentUsers;\n\n // If the user does not have any permitted users then they most likely have\n // a billing issue (or have cancelled) so send them over to billing to inform/resolve.\n if (billingPlan.permittedConcurrentUsers === 0) {\n await router.push({\n name: routes.administrationMenu.yourCompany.billingDetails,\n });\n }\n };\n\n const refresh = async () => {\n if (document.visibilityState === \"visible\") {\n items.value = await userSessionService\n .getAllLicensedUserSessions(api.tenantGroupId)\n .then((x) => Object.freeze(x));\n }\n\n await performLicenseCheck();\n };\n\n const performLicenseCheck = async () => {\n // form will automatically be closed once a license is allocated\n await userStore.performLicenseCheck();\n };\n\n const signOut = async () => {\n await userStore.signOut(\"current session sign out\");\n };\n\n const endSession = async (item: LicensedUserSession) => {\n await userSessionService.kickLicensedUserSession(\n api.tenantGroupId,\n item.sessionId\n );\n\n await userStore.performLicenseCheck();\n await refresh();\n };\n\n const minutesSinceActive = (lastActive: Instant) => {\n return Duration.between(\n LocalDateTime.ofInstant(lastActive),\n LocalDateTime.now()\n ).toMinutes();\n };\n\n const logoffPromptText = computed(() => {\n return translateWithParams(\"auth_force_logoff_description\", {\n sessionCount: items.value.length.toString(),\n licensedUsersNo: tenantMaxSessions.value.toString(),\n }).toString();\n });\n\n const isDesktopView = computed(() => {\n return $vuetify.breakpoint.smAndUp ?? true;\n });\n\n onMounted(\n withLoading(async () => {\n await Promise.all([loadPrerequisites(), refresh()]);\n // Refresh data after 1 Minute (\"+\" causes a toPrimitive call with \"number\" hint)\n refreshTimer.value = +setInterval(refresh, 60000);\n })\n );\n\n onBeforeUnmount(() => clearInterval(refreshTimer.value));\n\n return {\n items,\n users,\n refreshTimer,\n tenantMaxSessions,\n gridState,\n gridConfiguration,\n isDesktopView,\n logoffPromptText,\n loadPrerequisites,\n refresh,\n signOut,\n endSession,\n minutesSinceActive,\n performLicenseCheck,\n };\n}\n"],"names":["ref"],"mappings":"khBAmBO,SAAS,oBAAqB,CACnC,KAAM,CAAE,GAAI,EAAG,EAAI,QAAQ,EACrB,CAAE,QAAW,YACb,CAAE,UAAa,aAEf,MAAQ,WAA2C,CAAA,CAAE,EACrD,MAAQ,WAA4B,CAAA,CAAE,EACtC,aAAeA,MAAY,CAAC,EAC5B,kBAAoBA,MAAY,CAAC,EACjC,UAAY,sBAAsB,eAElC,kBAAoB,SAAS,IAAM,CACnC,IAAA,MAAQ,IAAI,yBAA8C,CAC5D,OAAS,MAAS,KAAK,UACvB,MAAO,GAAG,qBAAA,CACX,EACK,aAAA,cACJ,GAAG,KAAK,WACP,cAAS,mBAAQ,MAAM,MAAO,KAAK,MAAM,IAAhC,eAAmC,OAAQ,KAAA,EAEjD,MAAA,cACJ,GAAG,KAAK,gBACP,cAAS,mBAAQ,MAAM,MAAO,KAAK,MAAM,IAAhC,eAAmC,WAAY,KAAA,EAIxD,MAAA,iBAAiB,GAAG,KAAK,wBAA0B,MAClD,mBAAmB,KAAK,UAAU,CAAA,EAEnC,YAAY,EAAG,EAAI,EAEhB,MAAA,0BACJ,GAAG,KAAK,wBACP,MAAS,KAAK,gBAAA,EAGjB,MACG,iBAAiB,EACjB,WAAW,EAAK,EAChB,WACC,GAAG,iBACF,MAAS,WAAW,IAAI,EACxB,MAAS,CAAC,KAAK,gBAAA,EAGb,MAAM,OAAM,CACpB,EAEK,kBAAoB,gBAAY,CAChC,IAAA,YACJ,CAAC,MAAM,MAAO,WAAW,EAAI,MAAM,QAAQ,IAAI,CAC7C,YAAY,YAAY,IAAI,aAAa,EAAE,KAAM,GAAM,OAAO,OAAO,CAAC,CAAC,EACvE,mBAAmB,iBAAiB,IAAI,aAAa,CAAA,CACt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