Skip to content

Commit

Permalink
[KNOWAGE-8672] Removed crypto library dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Redjaw committed Nov 8, 2024
1 parent 8be0205 commit ba3c8df
Show file tree
Hide file tree
Showing 38 changed files with 220 additions and 210 deletions.
233 changes: 143 additions & 90 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
"caniuse-lite": "^1.0.30001618",
"chart.js": "^3.7.0",
"cronstrue": "^2.1.0",
"crypto-browserify": "^3.12.0",
"crypto-js": "^4.1.1",
"crypto-random-string": "^5.0.0",
"deasync": "^0.1.21",
"deepcopy": "^2.1.0",
"dexie": "^3.2.4",
Expand Down
3 changes: 1 addition & 2 deletions src/components/UI/KnDashboardTabs/KnDashboardTabsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import { defineComponent } from 'vue'
import type { PropType } from 'vue'
import type { ISheet } from '@/modules/documentExecution/dashboard/Dashboard'
import cryptoRandomString from 'crypto-random-string'
import KnIconPicker from '@/components/UI/KnIconPicker/KnIconPicker.vue'
export default defineComponent({
Expand Down Expand Up @@ -126,7 +125,7 @@ export default defineComponent({
},
methods: {
addSheet(): void {
this.$emit('update:sheets', [...this.sheets, { label: this.$t('dashboard.sheets.newSheet'), widgets: { lg: [], md: [], sm: [], xs: [], xxs: [] }, id: cryptoRandomString({ length: 16, type: 'base64' }) }])
this.$emit('update:sheets', [...this.sheets, { label: this.$t('dashboard.sheets.newSheet'), widgets: { lg: [], md: [], sm: [], xs: [], xxs: [] }, id: crypto.randomUUID() }])
},
renameSheet(index): void {
if (this.edit) {
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/commons/qbeHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import cryptoRandomString from 'crypto-random-string'

export function createNewField(editQueryObj, field) {
var newField = {
id: field.attributes.type === 'inLineCalculatedField' ? field.attributes.formState : field.id,
Expand Down Expand Up @@ -27,7 +25,7 @@ export function createNewField(editQueryObj, field) {
leaf: field.leaf,
originalId: field.id,
isSpatial: field.isSpatial,
uniqueID: cryptoRandomString({ length: 4, type: 'base64' })
uniqueID: crypto.randomUUID()
} as any

// eslint-disable-next-line no-prototype-builtins
Expand Down
12 changes: 5 additions & 7 deletions src/modules/documentBrowser/DocumentBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import Menu from 'primevue/menu'
import TabView from 'primevue/tabview'
import TabPanel from 'primevue/tabpanel'
import cryptoRandomString from 'crypto-random-string'
export default defineComponent({
name: 'document-browser',
components: { DocumentBrowserHome, DocumentBrowserTab, Menu, TabView, TabPanel },
Expand Down Expand Up @@ -93,7 +91,7 @@ export default defineComponent({
name: tempDocument.name,
label: id,
mode: this.$router.currentRoute.value.params.mode,
routerId: cryptoRandomString({ length: 16, type: 'base64' }),
routerId: crypto.randomUUID(),
id: id,
showMode: this.$router.currentRoute.value.name === 'document-browser-document-execution' ? 'execute' : 'documentDetail'
},
Expand Down Expand Up @@ -132,7 +130,7 @@ export default defineComponent({
},
onItemSelect(payload: any) {
if (payload.item) {
payload.item.routerId = cryptoRandomString({ length: 16, type: 'base64' })
payload.item.routerId = crypto.randomUUID()
}
const tempItem = { ...payload, item: { ...payload.item } }
Expand All @@ -153,7 +151,7 @@ export default defineComponent({
this.selectedItem.item.showMode = 'execute'
this.$router.push(`/document-browser/${routeDocumentType}/` + id)
} else {
this.selectedItem.item = { routerId: cryptoRandomString({ length: 16, type: 'base64' }) }
this.selectedItem.item = { routerId: crypto.randomUUID() }
this.selectedItem.item.showMode = payload.mode
const link = payload.mode === 'createCockpit' ? '/document-browser/new-cockpit' : `/document-browser/new-dashboard?folderId=${payload.functionalityId}`
this.$router.push(link)
Expand Down Expand Up @@ -232,7 +230,7 @@ export default defineComponent({
this.closeIframe()
await this.$router.push(`/document-browser/document-composite/${cockpit.DOCUMENT_LABEL}?documentMode=edit`)
setTimeout(() => {}, 2000)
this.selectedItem = { item: { ...cockpit, routerId: cryptoRandomString({ length: 16, type: 'base64' }), name: cockpit.DOCUMENT_NAME, label: cockpit.DOCUMENT_LABEL, showMode: 'execute' }, mode: 'execute' }
this.selectedItem = { item: { ...cockpit, routerId: crypto.randomUUID(), name: cockpit.DOCUMENT_NAME, label: cockpit.DOCUMENT_LABEL, showMode: 'execute' }, mode: 'execute' }
this.tabs[this.activeIndex - 1] = this.selectedItem
},
getTabName(tab: any) {
Expand All @@ -246,7 +244,7 @@ export default defineComponent({
this.documentSaved = document
this.documentSavedTrigger = !this.documentSavedTrigger
this.selectedItem.functionalityId = null
this.selectedItem.item = { name: document.name, label: document.id, routerId: cryptoRandomString({ length: 16, type: 'base64' }), id: document.id, showMode: 'documentDetail' }
this.selectedItem.item = { name: document.name, label: document.id, routerId: crypto.randomUUID(), id: document.id, showMode: 'documentDetail' }
this.$router.push(`/document-browser/document-details/${document.id}`)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ import mainStore from '../../../App.store'
import DatasetEditor from './dataset/DatasetEditor.vue'
import WidgetEditor from './widget/WidgetEditor/WidgetEditor.vue'
import descriptor from './DashboardDescriptor.json'
import cryptoRandomString from 'crypto-random-string'
import DashboardControllerSaveDialog from './DashboardControllerSaveDialog.vue'
import SelectionsListDialog from './widget/SelectorWidget/SelectionsListDialog.vue'
import DashboardGeneralSettings from './generalSettings/DashboardGeneralSettings.vue'
Expand Down Expand Up @@ -271,7 +270,7 @@ export default defineComponent({
},
async getData() {
this.loading = true
if (!this.dashboardId) this.dashboardId = cryptoRandomString({ length: 16, type: 'base64' })
if (!this.dashboardId) this.dashboardId = crypto.randomUUID()
this.$emit('dashboardIdSet', this.dashboardId)
if (this.filtersData) {
this.drivers = loadDrivers(this.filtersData, this.model)
Expand Down
9 changes: 4 additions & 5 deletions src/modules/documentExecution/dashboard/DashboardHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { formatWidgetForSave, recreateKnowageChartModel } from './widget/WidgetE
import { setVariableValueFromDataset } from './generalSettings/VariablesHelper'
import mitt from 'mitt'
export const emitter = mitt()
import cryptoRandomString from 'crypto-random-string'
import deepcopy from 'deepcopy'
import { formatChartJSWidget } from './widget/WidgetEditor/helpers/chartWidget/chartJS/ChartJSHelpers'
import { formatHighchartsWidget } from './widget/WidgetEditor/helpers/chartWidget/highcharts/HighchartsHelpers'
Expand All @@ -25,7 +24,7 @@ export const SHEET_WIDGET_SIZES = ['xxs', 'xs', 'sm', 'md', 'lg'] as string[]
export const createNewDashboardModel = () => {
const dashboardModel = deepcopy(descriptor.newDashboardModel) as IDashboard
dashboardModel.configuration.theme = { config: getDefaultDashboardThemeConfig() }
dashboardModel.configuration.id = cryptoRandomString({ length: 16, type: 'base64' })
dashboardModel.configuration.id = crypto.randomUUID()

return dashboardModel
}
Expand Down Expand Up @@ -82,7 +81,7 @@ const moveWidgetItemToSpecificSizeArray = (widgetToAdd: IWidgetSheetItem, size:
}

if (overlap) updateWidgetCoordinatesIfOverlaping(widgetToAdd, maxWidth, sheetWidgets[size])
if (sheetWidgets && widgetToAdd) sheetWidgets[size].push({ id: widgetToAdd.id ?? '', h: widgetToAdd.h, i: cryptoRandomString({ length: 16, type: 'base64' }), w: widgetToAdd.w, x: widgetToAdd.x, y: widgetToAdd.y, moved: false })
if (sheetWidgets && widgetToAdd) sheetWidgets[size].push({ id: widgetToAdd.id ?? '', h: widgetToAdd.h, i: crypto.randomUUID(), w: widgetToAdd.w, x: widgetToAdd.x, y: widgetToAdd.y, moved: false })
}

const getMaxWidthForSpecificSize = (size: string) => {
Expand Down Expand Up @@ -174,7 +173,7 @@ const updateSheetInWidgetSizeArray = (sheet: IDashboardSheet, size: string, widg
}

const createDashboardSheetWidgetItem = (widget: IWidget) => {
return { id: widget.id ?? cryptoRandomString({ length: 16, type: 'base64' }), h: 10, i: cryptoRandomString({ length: 16, type: 'base64' }), w: 25, x: 0, y: 0, moved: false }
return { id: widget.id ?? crypto.randomUUID(), h: 10, i: crypto.randomUUID(), w: 25, x: 0, y: 0, moved: false }
}

export const deleteWidgetHelper = (dashboardId: string, widget: IWidget, dashboards: any) => {
Expand Down Expand Up @@ -261,7 +260,7 @@ const formatWidget = (widget: IWidget) => {

const addColumnIdsToWidgetColumns = (widget: IWidget) => {
widget.columns.forEach((column: IWidgetColumn) => {
if (!column.id) column.id = cryptoRandomString({ length: 16, type: 'base64' })
if (!column.id) column.id = crypto.randomUUID()
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import { IBackground, IDashboardSheet, IDataset, IVariable } from './Dashboard'
import { canEditDashboard } from './DashboardHelpers'
import { mapActions, mapState } from 'pinia'
import { emitter } from './DashboardHelpers'
import cryptoRandomString from 'crypto-random-string'
import WidgetController from './widget/WidgetController.vue'
import KnDashboardTabsPanel from '@/components/UI/KnDashboardTabs/KnDashboardTabsPanel.vue'
import dashboardStore from './Dashboard.store'
Expand Down Expand Up @@ -150,7 +149,7 @@ export default defineComponent({
y: 0,
x: 0,
h: 20,
i: cryptoRandomString({ length: 16, type: 'base64' })
i: crypto.randomUUID()
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import KnHint from '@/components/UI/KnHint.vue'
import AssociationsList from './DatasetEditorAssociationsList/DatasetEditorAssociationsList.vue'
import AssociationsDetail from './DatasetEditorAssociationsDetail/DatasetEditorAssociationsDetail.vue'
import mainStore from '../../../../../App.store'
import cryptoRandomString from 'crypto-random-string'
export default defineComponent({
name: 'dataset-editor-data-tab',
Expand Down Expand Up @@ -63,7 +62,7 @@ export default defineComponent({
this.selectedDatasets = this.selectedDatasetsProp
},
createNewAssociation() {
this.selectedAssociation = { fields: [], id: cryptoRandomString({ length: 16, type: 'base64' }) } as IAssociation
this.selectedAssociation = { fields: [], id: crypto.randomUUID() } as IAssociation
this.dashboardAssociations.push(this.selectedAssociation)
this.$emit('associationSelected', this.selectedAssociation)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { IAssociation, IDashboard, IDashboardConfiguration, IDataset, IDatasetPa
import { formatSelectionWidget } from './selectionWidget/SelectionsWidgetCompatibilityHelper'
import { setVariableValueFromDataset } from '../generalSettings/VariablesHelper'
import deepcopy from 'deepcopy'
import cryptoRandomString from 'crypto-random-string'
import { formatHTMLWidget } from './htmlWidget/HTMLWidgetCompatibilityHelper'
import { formatTextWidget } from './textWidget/TextWidgetCompatibilityHelper'
import { getFormattedDatasetDrivers } from '../dataset/DatasetEditorDataTab/DatasetEditorDataDetail/DatasetEditorDriverDialog/DatasetEditorDatasetDriverFormatterHelper'
Expand All @@ -28,7 +27,7 @@ export const formatModel = async (model: any, document: any, datasets: IDataset[

loadDatasetIdNameMap(datasets)
const formattedModel = {
id: cryptoRandomString({ length: 16, type: 'base64' }),
id: crypto.randomUUID(),
widgets: [],
version: model.knowageVersion,
configuration: await getFormattedModelConfiguration(model, document, drivers, profileAttributes, datasets, $http),
Expand Down Expand Up @@ -199,13 +198,13 @@ const formatSheet = (sheet: any, formattedModel: any, user: any, drivers: IDashb
if (!sheet.widgets) return

const formattedSheet = deepcopy(sheet)
formattedSheet.id = cryptoRandomString({ length: 16, type: 'base64' })
formattedSheet.id = crypto.randomUUID()
formattedSheet.widgets = { lg: [], md: [], sm: [], xs: [], xxs: [] }

for (let i = 0; i < sheet.widgets.length; i++) {
const tempWidget = sheet.widgets[i]
const sizes = ['lg', 'md', 'sm', 'xs', 'xxs']
sizes.forEach((size: string) => formattedSheet.widgets[size].push({ id: tempWidget.id, h: tempWidget.sizeY, w: tempWidget.sizeX, x: tempWidget.col, y: tempWidget.row, i: cryptoRandomString({ length: 16, type: 'base64' }), moved: false }))
sizes.forEach((size: string) => formattedSheet.widgets[size].push({ id: tempWidget.id, h: tempWidget.sizeY, w: tempWidget.sizeX, x: tempWidget.col, y: tempWidget.row, i: crypto.randomUUID(), moved: false }))
addWidgetToModel(tempWidget, formattedModel, user, drivers)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IWidgetColumn } from '../../Dashboard'
import { IPivotFields } from '../../interfaces/pivotTable/DashboardPivotTableWidget'
import cryptoRandomString from 'crypto-random-string'

export const getFormattedPivotFields = (widget: any, columnNameIdMap: any) => {
if (!widget.content || !widget.content.crosstabDefinition) return []
Expand All @@ -19,7 +18,7 @@ export const getFormattedFields = (widgetColumns: any, columnNameIdMap: any) =>
const formattedColumns = [] as IWidgetColumn[]

widgetColumns.forEach((widgetColumn) => {
const formattedColumn = { id: cryptoRandomString({ length: 16, type: 'base64' }), columnName: widgetColumn.id, alias: widgetColumn.alias, type: '', fieldType: widgetColumn.nature.toUpperCase(), filter: {} } as IWidgetColumn
const formattedColumn = { id: crypto.randomUUID(), columnName: widgetColumn.id, alias: widgetColumn.alias, type: '', fieldType: widgetColumn.nature.toUpperCase(), filter: {} } as IWidgetColumn

if (widgetColumn.isCalculated) {
formattedColumn.formula = widgetColumn.formula
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IWidgetColumn } from "../../Dashboard"
import cryptoRandomString from "crypto-random-string"
import { IWidgetColumn } from '../../Dashboard'

export const getFormattedWidgetColumns = (widget: any, columnNameIdMap: any, allowDuplicates: boolean = true) => {
if (!widget.content || !widget.content.columnSelectedOfDataset) return []
Expand All @@ -13,19 +12,18 @@ export const getFormattedWidgetColumns = (widget: any, columnNameIdMap: any, all
const index = formattedColumns.findIndex((column: IWidgetColumn) => column.columnName === formattedColumn.columnName && column.alias === formattedColumn.alias)
if (index === -1) formattedColumns.push(formattedColumn)
}

}
return formattedColumns
}

export const getFormattedWidgetColumn = (widgetColumn: any, columnNameIdMap: any) => {
const formattedColumn = { id: cryptoRandomString({ length: 16, type: 'base64' }), columnName: widgetColumn.name, alias: widgetColumn.alias, type: widgetColumn.type, fieldType: widgetColumn.fieldType, multiValue: widgetColumn.multiValue, filter: {} } as IWidgetColumn
const formattedColumn = { id: crypto.randomUUID(), columnName: widgetColumn.name, alias: widgetColumn.alias, type: widgetColumn.type, fieldType: widgetColumn.fieldType, multiValue: widgetColumn.multiValue, filter: {} } as IWidgetColumn
if (widgetColumn.isCalculated) {
formattedColumn.formula = widgetColumn.formula
formattedColumn.formulaEditor = widgetColumn.formulaEditor
}
columnNameIdMap[formattedColumn.columnName] = formattedColumn.id
if (widgetColumn.aggregationSelected) formattedColumn.aggregation = widgetColumn.aggregationSelected
if (widgetColumn.aggregationColumn) formattedColumn.aggregationColumn = widgetColumn.aggregationSelected !== 'COUNT' ? widgetColumn.aggregationColumn : ""
if (widgetColumn.aggregationColumn) formattedColumn.aggregationColumn = widgetColumn.aggregationSelected !== 'COUNT' ? widgetColumn.aggregationColumn : ''
return formattedColumn
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IWidgetColumn } from '../../Dashboard'
import { IPivotFields } from '../../interfaces/pivotTable/DashboardPivotTableWidget'
import cryptoRandomString from 'crypto-random-string'

export const getFormattedPivotFields = (widget: any, columnNameIdMap: any) => {
if (!widget.content || !widget.content.crosstabDefinition) return []
Expand All @@ -19,7 +18,7 @@ export const getFormattedFields = (widgetColumns: any, columnNameIdMap: any) =>
const formattedColumns = [] as IWidgetColumn[]

widgetColumns.forEach((widgetColumn) => {
const formattedColumn = { id: cryptoRandomString({ length: 16, type: 'base64' }), columnName: widgetColumn.id, alias: widgetColumn.alias, type: '', fieldType: widgetColumn.nature.toUpperCase(), filter: {} } as IWidgetColumn
const formattedColumn = { id: crypto.randomUUID(), columnName: widgetColumn.id, alias: widgetColumn.alias, type: '', fieldType: widgetColumn.nature.toUpperCase(), filter: {} } as IWidgetColumn

if (widgetColumn.isCalculated) {
formattedColumn.formula = widgetColumn.formula
Expand Down
Loading

0 comments on commit ba3c8df

Please sign in to comment.