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Ac,CAAC,EAD9F,OAJF,M,OAKI,OAAAC,EAAuB,SACxB,OAAQ,SAAAJ,EAAC,CAAI,OAAAA,EAAE,cAAgBH,EAAO,YAAzB,CAAqC,EACjDO,EAAoB,QAAU,IAChCA,EAAoB,CAAC,EAAE,MAAQA,EAAoB,CAAC,EAAE,aAAeA,EAAoB,CAAC,EAAE,SAAW,EAAIA,EAAoB,CAAC,EAAE,SAAW,GACvIC,EAAM,IAAI,KACVC,EAAgB,KAAK,IAAID,EAAI,eAAe,EAAGA,EAAI,YAAY,EAAGA,EAAI,WAAW,CAAC,EACpF,KAAAN,GAAkB,YAAlBA,EAAoB,WAAO,qBAAE,QAAUA,EAAmB,QAAQA,EAAmB,QAAQ,OAAO,CAAC,EAAE,WAAaO,EACtHP,EAAmB,QAAQA,EAAmB,QAAQ,OAAO,CAAC,EAAI,EAAH,CAAI,UAAWO,CAAa,KAAM,MAAcF,EAAoB,CAAC,EAAG,SAACH,EAAC,CAAG,OAAAA,CAAA,CAAC,CAAC,EAG9IF,EAAmB,QAAQ,KAAK,EAAD,CAAE,UAAWO,CAAa,KAAM,MAAcF,EAAoB,CAAC,EAAG,SAACH,EAAC,CAAG,OAAAA,CAAA,CAAC,CAAC,I,aAUpH,MAAO,CAAP,EAAOF,CAAkB,C,OAxI3B,GADC,U,kDAOD,GADC,U,gDAUD,GADC,U,yCAMD,GADC,U,uCAOD,GADC,Q,kCAQD,GADC,Q,qDAiBD,GADC,Q,kCAQD,GADC,Q,kCAOD,GADC,Q,iCAiBD,GADC,Q,uCAMD,GADC,Q,qCAMD,GADC,Q,4CAeD,GADC,Q,4CA9HgBQ,EAA0B,MAD9C,UAAO,CAAE,QAAS,GAAM,MAAK,UAAE,WAAY,GAAM,KAAM,QAAS,CAAC,C,EAC7CA,CAA0B,EAqK/C,C,EArKwD,YAAU,E,IAA7CA,C","sources":["webpack://[name]/./src/communication/axios/model/Product.ts","webpack://[name]/./src/store/LimitsAndConsumptions-store.ts"],"sourcesContent":["import { number } from \"mathjs\";\nimport { PageableFullDTO } from \"./generic\";\nimport { abbreviate } from \"@/utils/TextFormatUtil\";\nimport { i18n } from \"@/main\";\n\nexport interface Product {\n id?: number;\n code: string;\n label: string;\n resources: ProductResource[]\n type: ProductType,\n trial: boolean,\n lastVersion?: boolean,\n autorenewDefaultValueForNewLicenses: boolean,\n}\n\nexport enum ProductType {\n STANDARD = 'STANDARD', PLUS = 'PLUS'\n}\n\nexport interface ProductResource {\n duration: number,\n quantity: number,\n resourceType: ProductResourceType,\n}\n\nexport interface ProductResourceUse extends ProductResource{\n used: number;\n granted?: number;\n grantedUsed?: number;\n lastUpdateFreeQuantity?: number;\n licensed?: number;\n warnLevel?: number;\n}\n\nexport enum ProductResourceType {\n USERS = 'USERS',\n ORGANIZATIONS = 'ORGANIZATIONS',\n DEVICES = 'DEVICES',\n DEVICE_DATA = 'DEVICE_DATA',\n DEVICE_VPN = 'DEVICE_VPN',\n CREDITS = 'CREDITS'\n}\n\nexport function isConsumableResource(resourceType: ProductResourceType) {\n switch(resourceType) {\n case ProductResourceType.DEVICE_DATA:\n case ProductResourceType.DEVICE_VPN:\n case ProductResourceType.CREDITS:\n return true;\n default:\n return false;\n }\n}\n\nexport interface ResourceLimit {\n orgResourceId: string;\n quantity: number;\n used: number;\n resourceType: ProductResourceType\n}\n\nexport interface ResourceLimitOutDTO {\n expired: false\n grantingOrganization: string\n quantity: number\n resourceType: ProductResourceType\n targetOrganization: string\n used: number\n granted?: number\n grantedUsed?: number\n valid: boolean\n}\n\nexport interface LicenseDTO {\n autorenew: boolean,\n currency: string,\n expirationDate: number,\n externalRef: string,\n price: number,\n productId: number,\n targetOrgResourceId?:string\n}\n\nexport interface License {\n activationDate: number,\n product: Product,\n autorenew: boolean,\n}\n\nexport interface LicenseByBuyerOrg {\n id: number;\n name: string;\n orgCoreId: number;\n vpnEnabled: boolean;\n dealer: boolean;\n deleted: boolean;\n}\n\nexport interface SubscriptionResourceDTO {\n resourceType: ProductResourceType;\n quantity: number;\n used: number;\n expired: boolean;\n}\n\nexport interface LicenseByBuyer {\n autorenew: boolean;\n activationDate: number;\n code: string;\n creationDate: number;\n currency: string;\n licenseId: number;\n expired?: boolean;\n targetOrganization?: LicenseByBuyerOrg;\n organization: LicenseByBuyerOrg;\n product: {\n code: string;\n creationDate: number;\n dealer: boolean;\n id: number;\n label: string;\n }\n subscription: {\n activationDate: number;\n autorenew: boolean;\n creationDate: number;\n expirationDate: number;\n licenseId: number;\n productCode: string;\n productLabel: string;\n productType: ProductType;\n validity: number;\n resources: SubscriptionResourceDTO[],\n }\n price: number;\n used: boolean;\n}\n\nexport interface SubscriptionSummaryDTO {\n creationDate: number\n orgResourceId: string\n expirationDate: number\n activationDate: number\n validity: number\n licenseId: number\n productId: number\n licenseCode: string\n productCode: string\n productLabel: string\n currency: string\n price: number\n productType: ProductType\n resources: SubscriptionResourceDTO[]\n autorenew: boolean\n trial: boolean\n}\n\nexport interface PageSubscriptionSummaryDTO extends PageableFullDTO {\n content: SubscriptionSummaryDTO[]\n}\n\nexport interface SubscriptionAggregatedOutputDTO extends SubscriptionResourceDTO {\n org: string // NOTE: it seems not to be returned by API\n granted: number // NOTE: it seems not to be returned by API\n licensed?: number\n grantedUsed?: number\n resourceType: ProductResourceType\n lastUpdateFreeQuantity?: number;\n}\n\n\nexport const DEFAULT_VPN_CREDITS_UNIT = (31*24*60*60)\n\nexport const DEFAULT_IOT_CREDITS_UNIT = (4096)\n\n// used as combined key in i18n\nexport const DEFAULT_VPN_CREDITS_UNIT_NAME = 'months'\n\nexport const DEFAULT_PRODUCT_VALIDITY = (365*24*60*60)\n\nexport const DEFAULT_CREDITS_GENERIC_UNIT = 1000\n\nexport const scaleResource = (resource: {\n resourceType: ProductResourceType,\n quantity?: number,\n usage?: number,\n used?: number,\n grantedUsed?: number,\n licensed?: number,\n granted?: number,\n free?: number,\n lastUpdateFreeQuantity?: number,\n duration?: number\n}, rounding = Math.ceil) => {\n // allow to apply to null resources\n if (!resource) return;\n let scaleFactor = resource.resourceType == ProductResourceType.DEVICE_VPN\n ? DEFAULT_VPN_CREDITS_UNIT\n : resource.resourceType == ProductResourceType.DEVICE_DATA\n ? DEFAULT_IOT_CREDITS_UNIT\n : resource.resourceType == ProductResourceType.CREDITS\n ? DEFAULT_CREDITS_GENERIC_UNIT\n : 1;\n if (scaleFactor == 1) {\n return resource;\n }\n if (resource.quantity >= 0) resource.quantity = rounding( resource.quantity / scaleFactor );\n else if (resource.quantity) resource.quantity = -1;\n if (resource.granted >= 0) resource.granted = rounding( resource.granted / scaleFactor );\n else if (resource.granted) resource.granted = -1;\n if (resource.used) resource.used = rounding( resource.used / scaleFactor );\n if (resource.usage) resource.usage = rounding( resource.usage / scaleFactor );\n if (resource.grantedUsed) resource.grantedUsed = rounding( resource.grantedUsed / scaleFactor );\n if (resource.licensed) resource.licensed = rounding( resource.licensed / scaleFactor );\n if (resource.lastUpdateFreeQuantity) resource.lastUpdateFreeQuantity = rounding( resource.lastUpdateFreeQuantity / scaleFactor );\n\n // free is used to apply limits on consumable resources - is not managed directly by the backend\n if (resource.free >= 0) resource.free = rounding( resource.free / scaleFactor );\n else if (resource.free) resource.free = -1;\n return resource;\n}\n\nexport const unscaleResource = (resource: {\n resourceType: ProductResourceType,\n quantity?: number,\n used?: number,\n grantedUsed?: number,\n licensed?: number,\n granted?: number,\n lastUpdateFreeQuantity?: number,\n duration?: number\n} ) => {\n // allow to apply to null resources\n if (!resource) return;\n let scaleFactor = resource.resourceType == ProductResourceType.DEVICE_VPN\n ? DEFAULT_VPN_CREDITS_UNIT\n : resource.resourceType == ProductResourceType.DEVICE_DATA\n ? DEFAULT_IOT_CREDITS_UNIT\n : resource.resourceType == ProductResourceType.CREDITS\n ? DEFAULT_CREDITS_GENERIC_UNIT\n : 1;\n if (scaleFactor == 1) {\n return resource;\n }\n if (resource.quantity >= 0) resource.quantity = resource.quantity * scaleFactor ;\n else if (resource.quantity) resource.quantity = -1;\n if (resource.granted > 0) resource.granted = resource.granted * scaleFactor ;\n else if (resource.granted) resource.granted = -1;\n if (resource.used) resource.used = resource.used * scaleFactor;\n if (resource.grantedUsed) resource.grantedUsed = resource.grantedUsed * scaleFactor;\n if (resource.licensed) resource.licensed = resource.licensed * scaleFactor;\n if (resource.lastUpdateFreeQuantity) resource.lastUpdateFreeQuantity = resource.lastUpdateFreeQuantity * scaleFactor;\n return resource;\n}\n\n\nexport const formatResource = (resource: ProductResourceUse, showPercent: boolean): {\n num: string,\n denum: string,\n ratio: number,\n warnLevel: number,\n text: string,\n tooltip: string\n} => {\n const consumable = (resource.resourceType == ProductResourceType.DEVICE_DATA ||\n resource.resourceType == ProductResourceType.DEVICE_VPN ||\n resource.resourceType == ProductResourceType.CREDITS);\n const formatQuantity = (quantity: number, maxQuantity: number, showQuantity: boolean = false) => {\n return abbreviate(quantity) + (showQuantity\n ? '/' + (maxQuantity >= 0 ? abbreviate(maxQuantity) : '∞')\n : ''\n ) + ((showPercent && maxQuantity >= 0)\n ? (maxQuantity != 0 ? ` (${i18n.n((Math.round(100 * quantity / maxQuantity)))}%)` : '')\n : ''\n );\n }\n\n let num : number;\n let denum : number;\n let ratio: number;\n let warnLevel: number;\n let tooltip : string = '';\n if (resource.quantity < 0) {\n num = resource.used;\n denum = -1;\n } else if (consumable && resource.lastUpdateFreeQuantity) {\n num = resource.lastUpdateFreeQuantity - (resource.quantity - resource.used);\n denum = resource.lastUpdateFreeQuantity;\n } else {\n num = resource.used; // includes granted\n denum = resource.quantity;\n }\n if (denum < 0) {\n ratio = 0;\n } else {\n // HACK: adding an epsilon to quantity to both prevent divisions by 0\n // and to force showing a full circle instead of an empty one\n // in the case used == quantity\n ratio = num / (denum + 0.001);\n }\n if (denum == 0) {\n warnLevel = 0;\n } else if(denum < 0) {\n warnLevel = 1;\n } else {\n const lvls = [0, 0.75, 0.9];\n let lvl = 0;\n while (ratio >= lvls[lvl]) lvl++;\n warnLevel = lvl;\n }\n\n let text = formatQuantity(num, denum, true);\n\n if (!consumable) {\n const actualUsed = (resource.used - (resource.granted > 0 ? resource.granted : 0 ) - (resource.licensed > 0 ? resource.licensed : 0) );\n if ( actualUsed > 0) {\n tooltip += `${i18n.t(\"resourceLabels.self\", {amount: formatQuantity(actualUsed, resource.quantity)})}`\n }\n } else {\n // self resources cannot be safely computed for consumable resources (TODO: add explicit support in the backend)\n }\n\n if (resource.granted) {\n if (!consumable) {\n tooltip += '
' + `${i18n.t(\"resourceLabels.shared\", {amount: formatQuantity(resource.granted, denum)})}`;\n } else {\n tooltip += '
' + `${i18n.t(\"resourceLabels.shared\", {amount: formatQuantity(Math.max(0, resource.granted-resource.grantedUsed), denum)})}`;\n }\n }\n if (resource.licensed > 0) {\n tooltip += '
' + `${i18n.t(\"resourceLabels.licensed\", {amount: formatQuantity(resource.licensed, resource.quantity)})}`\n }\n\n return { num: num < 0 ? '∞' : abbreviate(num), denum: denum < 0 ? '∞' : abbreviate(denum), ratio, warnLevel, text, tooltip };\n\n}\n","\nimport LimitsAxiosInstance from \"../communication/axios/implementation/LimitsAxiosInstance\";\nimport { ProductResourceType, ResourceLimit, scaleResource } from \"../communication/axios/model/Product\";\nimport store from './store';\n\nimport {\n Action,\n Module,\n Mutation,\n VuexModule,\n config\n} from 'vuex-module-decorators'\nimport LicenseManagerAxiosInstance, { ConsumptionsFilter } from \"@/communication/axios/implementation/LicenseManagerAxiosInstance\";\nimport ProductsAxiosInstance from \"@/communication/axios/implementation/ProductsAxiosInstance\";\nimport { startOfDay } from \"date-fns\";\nimport { ConsumptionEntry, ConsumptionHistory } from \"@/interfaces/consumptionsTable\";\n// Set rawError to true by default on all @Action decorators\nconfig.rawError = true\n\n@Module({ dynamic: true, store, namespaced: true, name: 'limits' })\nexport default class LimitsAndConsumptionsStore extends VuexModule {\n limits = [];\n shouldForceUpdate = false;\n\n organizationsConsumptionsTable = {\n pagination: {\n totalElements: 0,\n totalPages: 0\n }\n };\n\n get getLimits() {\n return this.limits\n }\n\n get getShouldForceUpdate() {\n return this.shouldForceUpdate;\n }\n\n get getConsumptionsTablePagination(){\n return this.organizationsConsumptionsTable.pagination;\n }\n\n\n @Mutation\n SET_CONSUMPTIONS_TABLE_PAGE(page : { totalElements: number, totalPages: number } ){\n this.organizationsConsumptionsTable.pagination.totalElements = page.totalElements;\n this.organizationsConsumptionsTable.pagination.totalPages = page.totalPages;\n }\n\n @Mutation\n SAVE_ORGANIZATIONS_LIMITS(data) {\n if(data.length > this.limits.length) {\n this.limits = data;\n } else {\n console.warn(\"SAVE_ORGANIZATIONS_LIMITS refusing to update: current[\"+ this.limits.length+\"]-new[\"+data.lenght+\"]\", this.limits, data)\n }\n }\n\n @Mutation\n UNSET_FORCE_UPDATE() {\n this.shouldForceUpdate = false;\n }\n \n @Mutation\n SET_FORCE_UPDATE() {\n this.shouldForceUpdate = true;\n }\n\n\n @Action\n async fetchLimits(orgResourceId: string)\n {\n return LimitsAxiosInstance.fetchLimits(orgResourceId);\n }\n\n \n @Action\n async fetchCurrentOrganizationLimits()\n {\n const organizations = store.getters['permission/getOrganizations'];\n const selectedOrg = organizations.selectedOrganization;\n const selectedSuborg = organizations.selectedSubOrganization;\n const organization = selectedSuborg || selectedOrg;\n const resId = organization.resourceId;\n if (organization && resId) {\n return await LimitsAxiosInstance.fetchLimits(resId);\n //return await ProductsAxiosInstance.getSubscriptionAggregated(resId); \n }\n console.warn(\"Limits-store-actions fetchCurrentOrganizationLimits not enough data\")\n return null; \n }\n \n @Action\n async createLimit(arg: {limit: ResourceLimit })\n {\n // return LimitsAxiosInstance.post(`${CommunicationSettings.limitsApiUrl()}?orgResourceId=${arg.grantingOrganization}`, arg.limit)\n return LimitsAxiosInstance.createLimit(arg.limit);\n }\n \n @Action\n async updateLimit(arg: {limit: ResourceLimit })\n {\n return LimitsAxiosInstance.updateLimit(arg.limit);\n }\n \n @Action\n async saveLimits(arg: {grantingOrganization: string, limits: ResourceLimit[] })\n {\n const promises = [];\n for (let limit of arg.limits)\n {\n // we actually don't know here if the limit already exists in the db, \n // so we always create it and then update it\n const l = {grantingOrganization: arg.grantingOrganization, limit: limit};\n const p = this.updateLimit(l);\n promises.push(p);\n }\n \n return Promise.all(promises);\n }\n \n @Action\n unsetForceUpdate() {\n this.UNSET_FORCE_UPDATE();\n }\n \n @Action\n setForceUpdate() {\n this.SET_FORCE_UPDATE();\n }\n \n @Action\n async fetchConsumptionTable(filter: ConsumptionsFilter){\n let consumptionResult = await LicenseManagerAxiosInstance.fetchConsumptionTable(filter);\n if ((consumptionResult as ConsumptionHistory).content) {\n let consumptionHistory = consumptionResult as ConsumptionHistory;\n consumptionHistory.content = consumptionHistory.content.map( (c) => scaleResource({ resourceType: filter.resourceType, ... c}, (x)=>x ));\n return consumptionHistory;\n } else {\n let consumptionEntry = consumptionResult as ConsumptionEntry;\n consumptionEntry = scaleResource({ resourceType: filter.resourceType, ... consumptionResult});\n return consumptionEntry;\n }\n }\n\n @Action\n async fetchConsumptionGraph(filter: ConsumptionsFilter){\n let consumptionHistory = await LicenseManagerAxiosInstance.fetchConsumptionGraph(filter);\n consumptionHistory.content.map( (c) => {\n scaleResource(c);\n // shift back by one day (usually the history snapshot is taken at 00:00:00, so it refers to consumption of the previous day)\n c.timestamp = new Date(c.timestamp).valueOf() - 86400000;\n return c;\n }, (x) => x);\n\n if (consumptionHistory.last && new Date(filter.filterDate.end) >= startOfDay(new Date())) {\n const organization = store.getters['permission/getOrganizations'].selectedSubOrganization;\n const organizationId = organization && organization.resourceId;\n \n if (filter.resourceType !== ProductResourceType.DEVICE_DATA && filter.resourceType !== ProductResourceType.DEVICE_VPN) {\n let currentConsumptions = (await ProductsAxiosInstance.getSubscriptionAggregated(organizationId))\n .filter( c => c.resourceType == filter.resourceType );\n if (currentConsumptions.length == 1) {\n currentConsumptions[0].used -= currentConsumptions[0].grantedUsed + (currentConsumptions[0].licensed > 0 ? currentConsumptions[0].licensed : 0);\n const now = new Date();\n const startOfDayUTC = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());\n if (consumptionHistory?.content?.length && consumptionHistory.content[consumptionHistory.content.length-1].timestamp == startOfDayUTC) {\n consumptionHistory.content[consumptionHistory.content.length-1] = {timestamp: startOfDayUTC, ... scaleResource(currentConsumptions[0], (x)=>x)};\n\n } else {\n consumptionHistory.content.push({timestamp: startOfDayUTC, ... scaleResource(currentConsumptions[0], (x)=>x)});\n }\n }\n } else {\n // for consumable resources granted and grantedUsed are not usable since are the total from the origin of time\n // while we would like to just see the number for current licenses (TODO: add support in backend)\n }\n }\n\n\n return consumptionHistory;\n }\n \n\n}"],"names":["ProductType","ProductResourceType","isConsumableResource","resourceType","DEFAULT_VPN_CREDITS_UNIT","DEFAULT_IOT_CREDITS_UNIT","DEFAULT_VPN_CREDITS_UNIT_NAME","DEFAULT_PRODUCT_VALIDITY","DEFAULT_CREDITS_GENERIC_UNIT","scaleResource","resource","rounding","scaleFactor","unscaleResource","formatResource","showPercent","consumable","formatQuantity","quantity","maxQuantity","showQuantity","num","denum","ratio","warnLevel","tooltip","lvls","lvl","text","actualUsed","page","data","orgResourceId","organizations","selectedOrg","selectedSuborg","organization","resId","arg","promises","limit","l","p","filter","consumptionResult","consumptionHistory","c","x","consumptionEntry","organizationId","currentConsumptions","now","startOfDayUTC","LimitsAndConsumptionsStore"],"sourceRoot":""}