@davra/ui-core 1.0.0-alpha.2 → 1.0.0-alpha.3
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.
- package/package.json +1 -2
- package/src/assets/fonts/myfont.woff +0 -0
- package/src/assets/main.scss +0 -17
- package/src/auto-imports.d.ts +0 -200
- package/src/components/ComponentA.vue +0 -13
- package/src/components/ComponentB.vue +0 -26
- package/src/components/index.ts +0 -7
- package/src/constants/MyConstants.ts +0 -1
- package/src/constants/index.ts +0 -5
- package/src/env.d.ts +0 -8
- package/src/index.ts +0 -23
- package/src/services/davraApi.ts +0 -18
- package/src/services/devicesCountersService.test.ts +0 -209
- package/src/services/devicesCountersService.ts +0 -117
- package/src/services/devicesService.test.ts +0 -207
- package/src/services/devicesService.ts +0 -110
- package/src/services/index.ts +0 -22
- package/src/services/labelsService.test.ts +0 -124
- package/src/services/labelsService.ts +0 -71
- package/src/services/metricsCountersService.test.ts +0 -44
- package/src/services/metricsCountersService.ts +0 -24
- package/src/services/metricsService.test.ts +0 -97
- package/src/services/metricsService.ts +0 -54
- package/src/services/timeseriesService.test.ts +0 -86
- package/src/services/timeseriesService.ts +0 -24
- package/src/services/twinTypesService.test.ts +0 -74
- package/src/services/twinTypesService.ts +0 -24
- package/src/services/twinsCountersService.test.ts +0 -72
- package/src/services/twinsCountersService.ts +0 -40
- package/src/services/twinsService.test.ts +0 -228
- package/src/services/twinsService.ts +0 -137
- package/src/services/userSessionService.test.ts +0 -74
- package/src/services/userSessionService.ts +0 -82
- package/src/stores/alertMessages.test.ts +0 -27
- package/src/stores/alertMessages.ts +0 -26
- package/src/stores/devices.test.ts +0 -149
- package/src/stores/devices.ts +0 -78
- package/src/stores/index.ts +0 -12
- package/src/stores/labels.test.ts +0 -72
- package/src/stores/labels.ts +0 -39
- package/src/stores/metrics.test.ts +0 -116
- package/src/stores/metrics.ts +0 -71
- package/src/stores/twinTypes.test.ts +0 -71
- package/src/stores/twinTypes.ts +0 -36
- package/src/stores/twins.test.ts +0 -148
- package/src/stores/twins.ts +0 -78
- package/src/stores/userSession.test.ts +0 -107
- package/src/stores/userSession.ts +0 -57
- package/src/types.ts +0 -173
- package/src/utils/MyUtil.ts +0 -7
- package/src/utils/index.ts +0 -5
@@ -1,24 +0,0 @@
|
|
1
|
-
import {DavraApiClient} from './davraApi'
|
2
|
-
import type { MetricCounter } from '~/types'
|
3
|
-
|
4
|
-
const getMetricsCounters = async (): Promise< MetricCounter[] > => {
|
5
|
-
try {
|
6
|
-
const { data } = await DavraApiClient().get<any>(
|
7
|
-
'/api/v1/iotdata/metrics/counters',
|
8
|
-
{
|
9
|
-
headers: {
|
10
|
-
Accept: 'application/json',
|
11
|
-
},
|
12
|
-
},
|
13
|
-
|
14
|
-
)
|
15
|
-
return data
|
16
|
-
}
|
17
|
-
catch (error) {
|
18
|
-
throw new Error('Metric Counter API Error')
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
export default {
|
23
|
-
getMetricsCounters,
|
24
|
-
}
|
@@ -1,97 +0,0 @@
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
2
|
-
import MetricsService from '~/services/metricsService'
|
3
|
-
|
4
|
-
const mockGet = vi.fn()
|
5
|
-
const mockPost = vi.fn()
|
6
|
-
vi.mock('./davraApi', () => {
|
7
|
-
return {
|
8
|
-
default: vi.fn(() => ({
|
9
|
-
get: mockGet,
|
10
|
-
post: mockPost,
|
11
|
-
})),
|
12
|
-
}
|
13
|
-
})
|
14
|
-
|
15
|
-
describe('Metrics Service', () => {
|
16
|
-
beforeEach(() => {
|
17
|
-
|
18
|
-
})
|
19
|
-
|
20
|
-
afterEach(() => {
|
21
|
-
|
22
|
-
})
|
23
|
-
|
24
|
-
it('getMetrics success', async () => {
|
25
|
-
const mockMetrics = ['metric1']
|
26
|
-
const axiosGet = mockGet.mockResolvedValueOnce({ data: { fields: mockMetrics }, status: 200 })
|
27
|
-
|
28
|
-
const result = await MetricsService.getMetrics()
|
29
|
-
|
30
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/iotdata/meta-data/metrics', {
|
31
|
-
headers: {
|
32
|
-
Accept: 'application/json',
|
33
|
-
},
|
34
|
-
})
|
35
|
-
|
36
|
-
expect(result).toEqual(mockMetrics)
|
37
|
-
})
|
38
|
-
|
39
|
-
it('getMetrics api unkown error', async () => {
|
40
|
-
mockGet.mockRejectedValueOnce({ response: { status: 500 } })
|
41
|
-
|
42
|
-
await expect(MetricsService.getMetrics()).rejects.toThrow(new Error('API Error 500 '))
|
43
|
-
})
|
44
|
-
|
45
|
-
it('postMetrics success', async () => {
|
46
|
-
const mockMetric = {
|
47
|
-
name: 'm1',
|
48
|
-
label: 'M1',
|
49
|
-
units: '%',
|
50
|
-
description: 'long description here',
|
51
|
-
semantics: 'metric',
|
52
|
-
labels: {},
|
53
|
-
}
|
54
|
-
const axiosPost = mockPost.mockResolvedValueOnce({ status: 200 })
|
55
|
-
|
56
|
-
await MetricsService.postMetric(mockMetric)
|
57
|
-
|
58
|
-
expect(axiosPost).toHaveBeenCalledWith('/api/v1/iotdata/meta-data',
|
59
|
-
mockMetric, {
|
60
|
-
headers: {
|
61
|
-
Accept: 'application/json',
|
62
|
-
},
|
63
|
-
})
|
64
|
-
})
|
65
|
-
it('postMetrcis success with no smantics', async () => {
|
66
|
-
const mockMetric = {
|
67
|
-
name: 'm1',
|
68
|
-
label: 'M1',
|
69
|
-
units: '%',
|
70
|
-
description: 'long description here',
|
71
|
-
labels: {},
|
72
|
-
}
|
73
|
-
const axiosPost = mockPost.mockResolvedValueOnce({ status: 200 })
|
74
|
-
|
75
|
-
await MetricsService.postMetric(mockMetric)
|
76
|
-
|
77
|
-
expect(axiosPost).toHaveBeenCalledWith('/api/v1/iotdata/meta-data',
|
78
|
-
{ ...mockMetric, semantics: 'metric' }, {
|
79
|
-
headers: {
|
80
|
-
Accept: 'application/json',
|
81
|
-
},
|
82
|
-
})
|
83
|
-
})
|
84
|
-
|
85
|
-
it('postMetrcis api unkown error', async () => {
|
86
|
-
mockPost.mockRejectedValueOnce({ response: { status: 500 } })
|
87
|
-
const mockMetric = {
|
88
|
-
name: 'm1',
|
89
|
-
label: 'M1',
|
90
|
-
units: '%',
|
91
|
-
description: 'long description here',
|
92
|
-
labels: {},
|
93
|
-
}
|
94
|
-
|
95
|
-
await expect(MetricsService.postMetric(mockMetric)).rejects.toThrow(new Error('API Error 500 '))
|
96
|
-
})
|
97
|
-
})
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import {DavraApiClient} from './davraApi'
|
2
|
-
|
3
|
-
import type { Metric } from '~/types'
|
4
|
-
|
5
|
-
const getMetrics = async (): Promise<any[]> => {
|
6
|
-
try {
|
7
|
-
const { data } = await DavraApiClient().get<any>(
|
8
|
-
'/api/v1/iotdata/meta-data/metrics',
|
9
|
-
{
|
10
|
-
headers: {
|
11
|
-
Accept: 'application/json',
|
12
|
-
},
|
13
|
-
},
|
14
|
-
|
15
|
-
)
|
16
|
-
return data.fields
|
17
|
-
}
|
18
|
-
catch (error: any) {
|
19
|
-
const errorMessage: string = typeof error?.response?.data?.message === 'string' ? error?.response?.data?.message : typeof error?.response?.data === 'string' ? error?.response?.data : ''
|
20
|
-
throw new Error(`API Error ${error?.response?.status} ${errorMessage}`)
|
21
|
-
}
|
22
|
-
}
|
23
|
-
const postMetric = async (metric: Metric): Promise<any> => {
|
24
|
-
try {
|
25
|
-
const { data } = await DavraApiClient().post<any>(
|
26
|
-
'/api/v1/iotdata/meta-data',
|
27
|
-
{
|
28
|
-
name: metric.name,
|
29
|
-
label: metric.label,
|
30
|
-
units: metric.units,
|
31
|
-
description: metric.description,
|
32
|
-
semantics: metric.semantics || 'metric',
|
33
|
-
labels: metric.labels,
|
34
|
-
},
|
35
|
-
{
|
36
|
-
headers: {
|
37
|
-
Accept: 'application/json',
|
38
|
-
},
|
39
|
-
},
|
40
|
-
|
41
|
-
)
|
42
|
-
return data
|
43
|
-
}
|
44
|
-
catch (error: any) {
|
45
|
-
const errorMessage: string = typeof error?.response?.data?.message === 'string' ? error?.response?.data?.message : typeof error?.response?.data === 'string' ? error?.response?.data : ''
|
46
|
-
throw new Error(`API Error ${error?.response?.status} ${errorMessage}`)
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
export default {
|
51
|
-
getMetrics,
|
52
|
-
postMetric,
|
53
|
-
}
|
54
|
-
|
@@ -1,86 +0,0 @@
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
2
|
-
import TimeseriesService from '~/services/timeseriesService'
|
3
|
-
|
4
|
-
const mockGet = vi.fn()
|
5
|
-
const mockPost = vi.fn()
|
6
|
-
vi.mock('./davraApi', () => {
|
7
|
-
return {
|
8
|
-
default: vi.fn(() => ({
|
9
|
-
get: mockGet,
|
10
|
-
post: mockPost,
|
11
|
-
})),
|
12
|
-
}
|
13
|
-
})
|
14
|
-
|
15
|
-
describe('Timeseries Service', () => {
|
16
|
-
beforeEach(() => {
|
17
|
-
|
18
|
-
})
|
19
|
-
|
20
|
-
afterEach(() => {
|
21
|
-
|
22
|
-
})
|
23
|
-
|
24
|
-
it('queryTimeseries success', async () => {
|
25
|
-
const mockQuery = {
|
26
|
-
metrics: [
|
27
|
-
{
|
28
|
-
name: 'davra.auditLog',
|
29
|
-
limit: 100000,
|
30
|
-
},
|
31
|
-
],
|
32
|
-
start_absolute: 1593513044000,
|
33
|
-
end_absolute: 1593599444000,
|
34
|
-
}
|
35
|
-
const mockResponse = {
|
36
|
-
queries: [
|
37
|
-
{
|
38
|
-
sample_size: 0,
|
39
|
-
results: [
|
40
|
-
{
|
41
|
-
name: 'davra.auditLog',
|
42
|
-
tags: {},
|
43
|
-
values: [],
|
44
|
-
},
|
45
|
-
],
|
46
|
-
},
|
47
|
-
],
|
48
|
-
}
|
49
|
-
const axiosPost = mockPost.mockResolvedValueOnce({
|
50
|
-
data: mockResponse,
|
51
|
-
status: 200,
|
52
|
-
})
|
53
|
-
|
54
|
-
const result = await TimeseriesService.queryTimeseries(mockQuery)
|
55
|
-
|
56
|
-
expect(axiosPost).toHaveBeenCalledWith('/api/v2/timeseriesdata', mockQuery, {
|
57
|
-
headers: {
|
58
|
-
Accept: 'application/json',
|
59
|
-
},
|
60
|
-
})
|
61
|
-
|
62
|
-
expect(result).toEqual(mockResponse)
|
63
|
-
})
|
64
|
-
|
65
|
-
it('queryTimeseries api unkown error', async () => {
|
66
|
-
const mockQuery = {
|
67
|
-
metrics: [
|
68
|
-
{
|
69
|
-
name: 'davra.auditLog',
|
70
|
-
limit: 100000,
|
71
|
-
},
|
72
|
-
],
|
73
|
-
start_absolute: 1593513044000,
|
74
|
-
end_absolute: 1593599444000,
|
75
|
-
}
|
76
|
-
const axiosPost = mockPost.mockRejectedValueOnce('')
|
77
|
-
|
78
|
-
await expect(TimeseriesService.queryTimeseries(mockQuery)).rejects.toThrowError()
|
79
|
-
|
80
|
-
expect(axiosPost).toHaveBeenCalledWith('/api/v2/timeseriesdata', mockQuery, {
|
81
|
-
headers: {
|
82
|
-
Accept: 'application/json',
|
83
|
-
},
|
84
|
-
})
|
85
|
-
})
|
86
|
-
})
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import {DavraApiClient} from './davraApi'
|
2
|
-
import type { TimeseriesDataResponse } from '~/types'
|
3
|
-
|
4
|
-
const queryTimeseries = async (query: any): Promise<TimeseriesDataResponse<any> | null > => {
|
5
|
-
try {
|
6
|
-
const { data } = await DavraApiClient().post<any>(
|
7
|
-
'/api/v2/timeseriesdata',
|
8
|
-
query,
|
9
|
-
{
|
10
|
-
headers: {
|
11
|
-
Accept: 'application/json',
|
12
|
-
},
|
13
|
-
},
|
14
|
-
)
|
15
|
-
return data
|
16
|
-
}
|
17
|
-
catch (error) {
|
18
|
-
throw new Error('Timeseries Error')
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
export default {
|
23
|
-
queryTimeseries,
|
24
|
-
}
|
@@ -1,74 +0,0 @@
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
2
|
-
import TwinTypesService from '~/services/twinTypesService'
|
3
|
-
|
4
|
-
const mockGet = vi.fn()
|
5
|
-
const mockPost = vi.fn()
|
6
|
-
vi.mock('./davraApi', () => {
|
7
|
-
return {
|
8
|
-
default: vi.fn(() => ({
|
9
|
-
get: mockGet,
|
10
|
-
post: mockPost,
|
11
|
-
})),
|
12
|
-
}
|
13
|
-
})
|
14
|
-
|
15
|
-
describe('TwinTypes Service', () => {
|
16
|
-
beforeEach(() => {
|
17
|
-
|
18
|
-
})
|
19
|
-
|
20
|
-
afterEach(() => {
|
21
|
-
|
22
|
-
})
|
23
|
-
|
24
|
-
it('getTwinTypes success', async () => {
|
25
|
-
const mockTwinTypes = [{
|
26
|
-
_id: '5fb7fdd919ed592dd321d767',
|
27
|
-
tenantId: 'ruban',
|
28
|
-
UUID: 'e8cc8e7d-900b-49da-b3df-43dceb101690',
|
29
|
-
created: 1605893593664,
|
30
|
-
owner: '451e5a4868b3fd5bda206fc82e436ac3',
|
31
|
-
name: 'stateful_incident',
|
32
|
-
description: 'Default type for stateful incidents. Do not delete.',
|
33
|
-
customAttributes: {},
|
34
|
-
},
|
35
|
-
{
|
36
|
-
_id: '5fbd141f5d07a570541dec20',
|
37
|
-
name: 'testTypes',
|
38
|
-
description: 'sample description',
|
39
|
-
labels: {},
|
40
|
-
customAttributes: {
|
41
|
-
testAttribute: 'x',
|
42
|
-
},
|
43
|
-
tenantId: 'ruban',
|
44
|
-
UUID: 'de68d333-7cd6-45ff-bfb4-d7d55b99eec5',
|
45
|
-
created: 1606226975987,
|
46
|
-
owner: '451e5a4868b3fd5bda206fc82e436ac3',
|
47
|
-
}]
|
48
|
-
const axiosGet = mockGet.mockResolvedValueOnce({ data: mockTwinTypes, status: 200 })
|
49
|
-
|
50
|
-
const result = await TwinTypesService.getTwinTypes()
|
51
|
-
|
52
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/twintypes', {
|
53
|
-
headers: {
|
54
|
-
Accept: 'application/json',
|
55
|
-
},
|
56
|
-
})
|
57
|
-
|
58
|
-
expect(result).toEqual(mockTwinTypes)
|
59
|
-
})
|
60
|
-
|
61
|
-
it('getTwinTypes api unkown error', async () => {
|
62
|
-
const axiosGet = mockGet.mockRejectedValueOnce('')
|
63
|
-
|
64
|
-
const result = await TwinTypesService.getTwinTypes()
|
65
|
-
|
66
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/twintypes', {
|
67
|
-
headers: {
|
68
|
-
Accept: 'application/json',
|
69
|
-
},
|
70
|
-
})
|
71
|
-
|
72
|
-
expect(result).toEqual([])
|
73
|
-
})
|
74
|
-
})
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { DavraApiClient } from './davraApi'
|
2
|
-
import type { TwinType } from '~/types'
|
3
|
-
|
4
|
-
const getTwinTypes = async (): Promise<TwinType[]> => {
|
5
|
-
try {
|
6
|
-
const { data } = await DavraApiClient().get<any>(
|
7
|
-
'/api/v1/twintypes',
|
8
|
-
{
|
9
|
-
headers: {
|
10
|
-
Accept: 'application/json',
|
11
|
-
},
|
12
|
-
},
|
13
|
-
|
14
|
-
)
|
15
|
-
return Object.values(data) || []
|
16
|
-
}
|
17
|
-
catch (error) {
|
18
|
-
return []
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
export default {
|
23
|
-
getTwinTypes,
|
24
|
-
}
|
@@ -1,72 +0,0 @@
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
2
|
-
import TwinsCountersService from '~/services/twinsCountersService'
|
3
|
-
|
4
|
-
const mockGet = vi.fn()
|
5
|
-
const mockPost = vi.fn()
|
6
|
-
vi.mock('./davraApi', () => {
|
7
|
-
return {
|
8
|
-
default: vi.fn(() => ({
|
9
|
-
get: mockGet,
|
10
|
-
post: mockPost,
|
11
|
-
})),
|
12
|
-
}
|
13
|
-
})
|
14
|
-
|
15
|
-
describe('Twins Counters Service', () => {
|
16
|
-
beforeEach(() => {
|
17
|
-
|
18
|
-
})
|
19
|
-
|
20
|
-
afterEach(() => {
|
21
|
-
|
22
|
-
})
|
23
|
-
|
24
|
-
it('getTwinsCountersByUUID success', async () => {
|
25
|
-
const axiosGet = mockGet.mockResolvedValueOnce({ data: '', status: 200, headers: { 'com-davra-total-results': '1' } })
|
26
|
-
|
27
|
-
const result = await TwinsCountersService.getTwinsCountersByUUID('uuid111')
|
28
|
-
|
29
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/iotdata/twins/counters/uuid111', {
|
30
|
-
headers: {
|
31
|
-
Accept: 'application/json',
|
32
|
-
},
|
33
|
-
})
|
34
|
-
|
35
|
-
expect(result).toEqual('')
|
36
|
-
})
|
37
|
-
|
38
|
-
it('getTwinsCountersByUUID api unkown error', async () => {
|
39
|
-
const axiosGet = mockGet.mockRejectedValueOnce('')
|
40
|
-
|
41
|
-
await expect(TwinsCountersService.getTwinsCountersByUUID('uuid111')).rejects.toThrow(new Error('Twins Counters API Error'))
|
42
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/iotdata/twins/counters/uuid111', {
|
43
|
-
headers: {
|
44
|
-
Accept: 'application/json',
|
45
|
-
},
|
46
|
-
})
|
47
|
-
})
|
48
|
-
it('getTwinsCountersLatestByUUID success', async () => {
|
49
|
-
const axiosGet = mockGet.mockResolvedValueOnce({ data: '', status: 200 })
|
50
|
-
|
51
|
-
const result = await TwinsCountersService.getTwinsCountersLatestByUUID('uuid111')
|
52
|
-
|
53
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/iotdata/twins/counters/latest/uuid111', {
|
54
|
-
headers: {
|
55
|
-
Accept: 'application/json',
|
56
|
-
},
|
57
|
-
})
|
58
|
-
|
59
|
-
expect(result).toEqual('')
|
60
|
-
})
|
61
|
-
|
62
|
-
it('getTwinsCountersLatestByUUID api unkown error', async () => {
|
63
|
-
const axiosGet = mockGet.mockRejectedValueOnce('')
|
64
|
-
|
65
|
-
await expect(TwinsCountersService.getTwinsCountersLatestByUUID('uuid111')).rejects.toThrow(new Error('Twins Counters API Error'))
|
66
|
-
expect(axiosGet).toHaveBeenCalledWith('/api/v1/iotdata/twins/counters/latest/uuid111', {
|
67
|
-
headers: {
|
68
|
-
Accept: 'application/json',
|
69
|
-
},
|
70
|
-
})
|
71
|
-
})
|
72
|
-
})
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import {DavraApiClient} from './davraApi'
|
2
|
-
import type { TwinCounter } from '~/types'
|
3
|
-
|
4
|
-
const getTwinsCountersByUUID = async (uuid: string): Promise< TwinCounter > => {
|
5
|
-
try {
|
6
|
-
const { data } = await DavraApiClient().get<any>(
|
7
|
-
`/api/v1/iotdata/twins/counters/${uuid}`,
|
8
|
-
{
|
9
|
-
headers: {
|
10
|
-
Accept: 'application/json',
|
11
|
-
},
|
12
|
-
},
|
13
|
-
)
|
14
|
-
return data
|
15
|
-
}
|
16
|
-
catch (error) {
|
17
|
-
throw new Error('Twins Counters API Error')
|
18
|
-
}
|
19
|
-
}
|
20
|
-
const getTwinsCountersLatestByUUID = async (uuid: string): Promise< TwinCounter > => {
|
21
|
-
try {
|
22
|
-
const { data } = await DavraApiClient().get<any>(
|
23
|
-
`/api/v1/iotdata/twins/counters/latest/${uuid}`,
|
24
|
-
{
|
25
|
-
headers: {
|
26
|
-
Accept: 'application/json',
|
27
|
-
},
|
28
|
-
},
|
29
|
-
)
|
30
|
-
return data
|
31
|
-
}
|
32
|
-
catch (error) {
|
33
|
-
throw new Error('Twins Counters API Error')
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
export default {
|
38
|
-
getTwinsCountersLatestByUUID,
|
39
|
-
getTwinsCountersByUUID,
|
40
|
-
}
|