bfg-common 1.3.36 → 1.3.37

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,77 +1,79 @@
1
- import type { UI_I_Localization } from '~/lib/models/interfaces'
2
- import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
3
- import type {
4
- UI_I_NotifyBodyMessage,
5
- UI_I_RequestBody,
6
- UI_I_SendTaskParams,
7
- } from '~/lib/models/interfaces'
8
- import { base64 } from './base64'
9
-
10
- const localization = computed<UI_I_Localization>(() => useLocal())
11
-
12
- const showNotification = (message: UI_I_NotifyBodyMessage): void => {
13
- const { title, desc, status } = message
14
- const { $store } = useNuxtApp()
15
-
16
- // @ts-ignore
17
- $store.dispatch('main/A_SHOW_NOTIFICATION', {
18
- status,
19
- messages: [
20
- {
21
- title,
22
- descriptions: [desc],
23
- },
24
- ],
25
- headline: '',
26
- timeout: status === 'success' ? 3000 : '',
27
- })
28
- }
29
- const msgError: UI_I_NotifyBodyMessage = {
30
- status: 'error',
31
- title: localization.value.error,
32
- desc: '',
33
- }
34
- const handleErrors = (error: Ref<API_UI_I_Error>): void => {
35
- if (error.value.data?.error_message) {
36
- msgError.desc = error.value.data?.error_message
37
- showNotification(msgError)
38
- }
39
- }
40
-
41
- export const handleRequest = async (
42
- url: string,
43
- body: UI_I_RequestBody
44
- ): Promise<boolean> => {
45
- // @ts-ignore
46
- const { error } = await useMyFetch<never, API_UI_I_Error>(url, {
47
- method: 'POST',
48
- key: Date.now().toString(),
49
- body,
50
- })
51
-
52
- if (error.value && error.value.data.error_code !== 0) {
53
- handleErrors(error)
54
- return false
55
- }
56
- return true
57
- }
58
-
59
- export async function sendTask({
60
- method,
61
- target,
62
- args,
63
- }: UI_I_SendTaskParams): Promise<void> {
64
- const { $store } = useNuxtApp()
65
-
66
- const argsToBase64 = args ? base64.encode(args) : ''
67
- const hasProcess = await handleRequest('/ui/tasks', {
68
- method,
69
- params: {
70
- target,
71
- args: argsToBase64,
72
- },
73
- })
74
-
75
- // @ts-ignore
76
- $store.dispatch('tasks/A_SET_PROCESS', hasProcess)
77
- }
1
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
2
+ import type {
3
+ API_UI_I_Error,
4
+ UI_I_RequestBody,
5
+ } from '~/lib/models/store/interfaces'
6
+ import type {
7
+ UI_I_NotifyBodyMessage,
8
+ UI_I_SendTaskParams,
9
+ } from '~/lib/models/interfaces'
10
+ import { base64 } from './base64'
11
+
12
+ const localization = computed<UI_I_Localization>(() => useLocal())
13
+
14
+ const showNotification = (message: UI_I_NotifyBodyMessage): void => {
15
+ const { title, desc, status } = message
16
+ const { $store } = useNuxtApp()
17
+
18
+ // @ts-ignore
19
+ $store.dispatch('main/A_SHOW_NOTIFICATION', {
20
+ status,
21
+ messages: [
22
+ {
23
+ title,
24
+ descriptions: [desc],
25
+ },
26
+ ],
27
+ headline: '',
28
+ timeout: status === 'success' ? 3000 : '',
29
+ })
30
+ }
31
+ const msgError: UI_I_NotifyBodyMessage = {
32
+ status: 'error',
33
+ title: localization.value.error,
34
+ desc: '',
35
+ }
36
+ const handleErrors = (error: Ref<API_UI_I_Error>): void => {
37
+ if (error.value.data?.error_message) {
38
+ msgError.desc = error.value.data?.error_message
39
+ showNotification(msgError)
40
+ }
41
+ }
42
+
43
+ export const handleRequest = async (
44
+ url: string,
45
+ body: UI_I_RequestBody
46
+ ): Promise<boolean> => {
47
+ // @ts-ignore
48
+ const { error } = await useMyFetch<never, API_UI_I_Error>(url, {
49
+ method: 'POST',
50
+ key: Date.now().toString(),
51
+ body,
52
+ })
53
+
54
+ if (error.value && error.value.data.error_code !== 0) {
55
+ handleErrors(error)
56
+ return false
57
+ }
58
+ return true
59
+ }
60
+
61
+ export async function sendTask({
62
+ method,
63
+ target,
64
+ args,
65
+ }: UI_I_SendTaskParams): Promise<void> {
66
+ const { $store } = useNuxtApp()
67
+
68
+ const argsToBase64 = args ? base64.encode(args) : ''
69
+ const hasProcess = await handleRequest('/ui/tasks', {
70
+ method,
71
+ params: {
72
+ target,
73
+ args: argsToBase64,
74
+ },
75
+ })
76
+
77
+ // @ts-ignore
78
+ $store.dispatch('tasks/A_SET_PROCESS', hasProcess)
79
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.3.36",
4
+ "version": "1.3.37",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  API_UI_I_Error,
3
+ API_UI_I_Response,
3
4
  UI_I_CommitOptions,
4
5
  } from '~/lib/models/store/interfaces'
5
6
  import type {
@@ -16,7 +17,6 @@ import type {
16
17
  API_UI_I_Task,
17
18
  } from '~/lib/models/store/tasks/interfaces'
18
19
  import type { UI_I_TasksState } from '~/store/tasks/lib/models/interfaces'
19
- import type { API_UI_I_Response } from '~/lib/models/interfaces'
20
20
  import type { UI_I_RefreshStack } from '~/store/main/lib/interfaces'
21
21
  import { tasksConstructor } from '~/store/tasks/mappers/tasks'
22
22
  import { recentTasks } from '~/store/tasks/mappers/recentTasks'