bfg-common 1.5.490 → 1.5.492

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,63 +1,93 @@
1
- import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
2
- import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
3
- import type { UI_T_Project } from '~/lib/models/types'
4
- import { UI_E_Kind } from '~/lib/models/enums'
5
-
6
- export const checkValidityName = async (
7
- name: string,
8
- wizard: Wizard,
9
- project: UI_T_Project,
10
- sendMessage: (message: string) => void
11
- ): Promise<void> => {
12
-
13
- wizard.setLoader(true)
14
- const url =
15
- project === 'procurator'
16
- ? `/ui/ds/validate?name=${encodeURIComponent(name)}`
17
- : `/ui/object/validate_name?name=${encodeURIComponent(name)}&kind=${UI_E_Kind.STORAGE_VALIDATION_NAME}`
18
- // @ts-ignore
19
- const { error } = await useMyFetch<null, API_UI_I_Error>(url, {
20
- method: 'GET',
21
- })
22
- wizard.setLoader(false)
23
-
24
- if (error.value && error.value.data.error_code !== 0) {
25
- const existError = error.value.data?.error_message || error.value.data
26
- sendMessage(existError)
27
- return
28
- }
29
- sendMessage('')
30
- }
31
-
32
- export const validateNameAndGenerateDataId = (
33
- name: string,
34
- _errorMessage: string,
35
- defaultDataId?: string
36
- ): string => {
37
- let baseDataId = defaultDataId || 'storage-name-alert-error'
38
-
39
- const patterns = [
40
- {
41
- regex: /^[a-zA-Z0-9_\-\.]+$/,
42
- error_message:
43
- /invalid name, must only contain letters, numbers, and '_', '-' '.' symbols/,
44
- suffix: '-invalid-name-symbols',
45
- },
46
- {
47
- regex: /^.{3,64}$/,
48
- error_message:
49
- /invalid name length, must be between: \d+ and \d+ characters/,
50
- suffix: '-invalid-name-length',
51
- },
52
- ]
53
-
54
- // Проверка error_message на соответствие шаблонам
55
-
56
- for (const pattern of patterns) {
57
- if (!pattern.regex.test(name)) {
58
- return `${baseDataId}${pattern.suffix}`
59
- }
60
- }
61
-
62
- return baseDataId
63
- }
1
+ import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
2
+ import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
3
+ import type { UI_T_Project } from '~/lib/models/types'
4
+ import { UI_E_Kind } from '~/lib/models/enums'
5
+
6
+ export const checkValidityName = async ({
7
+ name,
8
+ wizard,
9
+ project,
10
+ sendMessage,
11
+ datacenterId,
12
+ }: {
13
+ name: string
14
+ wizard: Wizard
15
+ project: UI_T_Project
16
+ sendMessage: (message: string) => void
17
+ datacenterId?: string
18
+ }): Promise<void> => {
19
+ wizard.setLoader(true)
20
+
21
+ try {
22
+ const url = buildValidationUrl(name, project, datacenterId)
23
+
24
+ const { error } = await useMyFetch<null, API_UI_I_Error>(url, {
25
+ method: 'GET',
26
+ })
27
+
28
+ if (error?.value?.data?.error_code !== 0) {
29
+ const existError =
30
+ error.value.data?.error_message ?? String(error.value.data)
31
+ sendMessage(existError)
32
+ return
33
+ }
34
+
35
+ sendMessage('')
36
+ } catch (e) {
37
+ const msg = e instanceof Error ? e.message : 'Unknown error'
38
+ sendMessage(msg)
39
+ } finally {
40
+ wizard.setLoader(false)
41
+ }
42
+ }
43
+
44
+ const buildValidationUrl = (
45
+ name: string,
46
+ project: UI_T_Project,
47
+ datacenterId?: string
48
+ ): string => {
49
+ if (project === 'procurator') {
50
+ const params = new URLSearchParams({ name })
51
+ return `/ui/ds/validate?${params.toString()}`
52
+ }
53
+
54
+ const params = new URLSearchParams()
55
+ params.set('name', name)
56
+ params.set('kind', String(UI_E_Kind.STORAGE_VALIDATION_NAME))
57
+ if (datacenterId) params.set('datacenter', datacenterId)
58
+
59
+ return `/ui/object/validate_name?${params.toString()}`
60
+ }
61
+
62
+ export const validateNameAndGenerateDataId = (
63
+ name: string,
64
+ _errorMessage: string,
65
+ defaultDataId?: string
66
+ ): string => {
67
+ let baseDataId = defaultDataId || 'storage-name-alert-error'
68
+
69
+ const patterns = [
70
+ {
71
+ regex: /^[a-zA-Z0-9_\-\.]+$/,
72
+ error_message:
73
+ /invalid name, must only contain letters, numbers, and '_', '-' '.' symbols/,
74
+ suffix: '-invalid-name-symbols',
75
+ },
76
+ {
77
+ regex: /^.{3,64}$/,
78
+ error_message:
79
+ /invalid name length, must be between: \d+ and \d+ characters/,
80
+ suffix: '-invalid-name-length',
81
+ },
82
+ ]
83
+
84
+ // Проверка error_message на соответствие шаблонам
85
+
86
+ for (const pattern of patterns) {
87
+ if (!pattern.regex.test(name)) {
88
+ return `${baseDataId}${pattern.suffix}`
89
+ }
90
+ }
91
+
92
+ return baseDataId
93
+ }
@@ -13,7 +13,8 @@ const checkName = async (
13
13
  form: UI_I_CreateDatastoreForm,
14
14
  localization: UI_I_Localization,
15
15
  wizard: Wizard,
16
- project: UI_T_Project
16
+ project: UI_T_Project,
17
+ datacenterId?: string
17
18
  ): Promise<UI_I_AsyncCheckReturn> => {
18
19
  const typeCode = form.type_code
19
20
 
@@ -26,11 +27,17 @@ const checkName = async (
26
27
  }
27
28
  if (form.name && help) {
28
29
  return new Promise((resolve, _reject) =>
29
- checkValidityName(form.name, wizard, project, (message: string) => {
30
- resolve({
31
- isValid: message === '',
32
- message: message === '' ? '' : message,
33
- })
30
+ checkValidityName({
31
+ name: form.name,
32
+ wizard,
33
+ project,
34
+ datacenterId,
35
+ sendMessage: (message: string) => {
36
+ resolve({
37
+ isValid: message === '',
38
+ message: message === '' ? '' : message,
39
+ })
40
+ },
34
41
  })
35
42
  )
36
43
  } else {
@@ -47,14 +54,15 @@ export const checkDatastoreNameAsync = async (
47
54
  stepId: number,
48
55
  fieldName: string,
49
56
  wizard: Wizard,
50
- project: UI_T_Project
57
+ project: UI_T_Project,
58
+ datacenterId?: string
51
59
  ): Promise<UI_I_ValidationReturn> => {
52
60
  let stepHasError = false
53
61
 
54
62
  const labelValidation: {
55
63
  isValid: boolean
56
64
  message: string
57
- } = await checkName(form, localization, wizard, project)
65
+ } = await checkName(form, localization, wizard, project, datacenterId)
58
66
 
59
67
  if (!labelValidation.isValid) {
60
68
  stepHasError = wizard.setValidation(stepId, fieldName, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.5.490",
4
+ "version": "1.5.492",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",