@ikatec/digisac-api-sdk 4.1.0 → 4.2.0
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/README.md +7 -4
- package/dist/apis/authHistory/AuthHistoryApi.cjs +12 -12
- package/dist/apis/authHistory/AuthHistoryApi.cjs.map +1 -1
- package/dist/apis/authHistory/AuthHistoryApi.d.ts +12 -19
- package/dist/apis/authHistory/AuthHistoryApi.d.ts.map +1 -1
- package/dist/apis/authHistory/AuthHistoryApi.mjs +12 -12
- package/dist/apis/authHistory/AuthHistoryApi.mjs.map +1 -1
- package/dist/apis/authHistory/types.d.ts +4 -3
- package/dist/apis/authHistory/types.d.ts.map +1 -1
- package/dist/apis/customFields/types.d.ts +21 -19
- package/dist/apis/customFields/types.d.ts.map +1 -1
- package/dist/apis/dashboard/DashboardApi.cjs +19 -0
- package/dist/apis/dashboard/DashboardApi.cjs.map +1 -0
- package/dist/apis/dashboard/DashboardApi.d.ts +12 -0
- package/dist/apis/dashboard/DashboardApi.d.ts.map +1 -0
- package/dist/apis/dashboard/DashboardApi.mjs +18 -0
- package/dist/apis/dashboard/DashboardApi.mjs.map +1 -0
- package/dist/apis/dashboard/index.cjs +4 -0
- package/dist/apis/dashboard/index.d.ts +3 -0
- package/dist/apis/dashboard/index.d.ts.map +1 -0
- package/dist/apis/dashboard/index.mjs +3 -0
- package/dist/apis/dashboard/types.cjs +0 -0
- package/dist/apis/dashboard/types.d.ts +53 -0
- package/dist/apis/dashboard/types.d.ts.map +1 -0
- package/dist/apis/dashboard/types.mjs +0 -0
- package/dist/apis/holiday/types.d.ts +34 -8
- package/dist/apis/holiday/types.d.ts.map +1 -1
- package/dist/apis/index.cjs +6 -0
- package/dist/apis/index.d.ts +2 -0
- package/dist/apis/index.d.ts.map +1 -1
- package/dist/apis/index.mjs +5 -1
- package/dist/apis/now/NowApi.cjs +37 -0
- package/dist/apis/now/NowApi.cjs.map +1 -0
- package/dist/apis/now/NowApi.d.ts +26 -0
- package/dist/apis/now/NowApi.d.ts.map +1 -0
- package/dist/apis/now/NowApi.mjs +36 -0
- package/dist/apis/now/NowApi.mjs.map +1 -0
- package/dist/apis/now/index.cjs +4 -0
- package/dist/apis/now/index.d.ts +3 -0
- package/dist/apis/now/index.d.ts.map +1 -0
- package/dist/apis/now/index.mjs +3 -0
- package/dist/apis/now/types.cjs +0 -0
- package/dist/apis/now/types.d.ts +45 -0
- package/dist/apis/now/types.d.ts.map +1 -0
- package/dist/apis/now/types.mjs +0 -0
- package/dist/apis/people/types.d.ts +7 -2
- package/dist/apis/people/types.d.ts.map +1 -1
- package/dist/apis/permissions/PermissionsApi.cjs +6 -2
- package/dist/apis/permissions/PermissionsApi.cjs.map +1 -1
- package/dist/apis/permissions/PermissionsApi.d.ts +7 -3
- package/dist/apis/permissions/PermissionsApi.d.ts.map +1 -1
- package/dist/apis/permissions/PermissionsApi.mjs +6 -2
- package/dist/apis/permissions/PermissionsApi.mjs.map +1 -1
- package/dist/apis/permissions/types.d.ts +4 -14
- package/dist/apis/permissions/types.d.ts.map +1 -1
- package/dist/apis/personalAccessTokens/PersonalAccessTokensApi.cjs +5 -0
- package/dist/apis/personalAccessTokens/PersonalAccessTokensApi.cjs.map +1 -1
- package/dist/apis/personalAccessTokens/PersonalAccessTokensApi.d.ts +5 -0
- package/dist/apis/personalAccessTokens/PersonalAccessTokensApi.d.ts.map +1 -1
- package/dist/apis/personalAccessTokens/PersonalAccessTokensApi.mjs +5 -0
- package/dist/apis/personalAccessTokens/PersonalAccessTokensApi.mjs.map +1 -1
- package/dist/apis/personalAccessTokens/types.d.ts +23 -4
- package/dist/apis/personalAccessTokens/types.d.ts.map +1 -1
- package/dist/apis/roles/RolesApi.cjs.map +1 -1
- package/dist/apis/roles/RolesApi.d.ts +2 -2
- package/dist/apis/roles/RolesApi.d.ts.map +1 -1
- package/dist/apis/roles/RolesApi.mjs.map +1 -1
- package/dist/apis/roles/types.d.ts +27 -4
- package/dist/apis/roles/types.d.ts.map +1 -1
- package/dist/apis/terms/TermsApi.cjs +4 -1
- package/dist/apis/terms/TermsApi.cjs.map +1 -1
- package/dist/apis/terms/TermsApi.d.ts +4 -1
- package/dist/apis/terms/TermsApi.d.ts.map +1 -1
- package/dist/apis/terms/TermsApi.mjs +4 -1
- package/dist/apis/terms/TermsApi.mjs.map +1 -1
- package/dist/apis/timetable/types.d.ts +12 -7
- package/dist/apis/timetable/types.d.ts.map +1 -1
- package/dist/core/BaseCrudApi.cjs +3 -30
- package/dist/core/BaseCrudApi.cjs.map +1 -1
- package/dist/core/BaseCrudApi.d.ts +4 -24
- package/dist/core/BaseCrudApi.d.ts.map +1 -1
- package/dist/core/BaseCrudApi.mjs +3 -30
- package/dist/core/BaseCrudApi.mjs.map +1 -1
- package/dist/core/BaseReadApi.cjs +44 -0
- package/dist/core/BaseReadApi.cjs.map +1 -0
- package/dist/core/BaseReadApi.d.ts +32 -0
- package/dist/core/BaseReadApi.d.ts.map +1 -0
- package/dist/core/BaseReadApi.mjs +43 -0
- package/dist/core/BaseReadApi.mjs.map +1 -0
- package/dist/core/index.cjs +2 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.mjs +2 -1
- package/dist/index.cjs +2 -0
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
- package/src/apis/authHistory/AuthHistoryApi.test.ts +10 -2
- package/src/apis/authHistory/AuthHistoryApi.ts +13 -39
- package/src/apis/authHistory/types.ts +4 -3
- package/src/apis/customFields/types.ts +21 -25
- package/src/apis/dashboard/DashboardApi.test.ts +82 -0
- package/src/apis/dashboard/DashboardApi.ts +18 -0
- package/src/apis/dashboard/index.ts +2 -0
- package/src/apis/dashboard/types.ts +53 -0
- package/src/apis/holiday/types.ts +36 -8
- package/src/apis/index.ts +2 -0
- package/src/apis/now/NowApi.test.ts +125 -0
- package/src/apis/now/NowApi.ts +59 -0
- package/src/apis/now/index.ts +2 -0
- package/src/apis/now/types.ts +47 -0
- package/src/apis/payloads.test-d.ts +39 -0
- package/src/apis/payloads.test.ts +81 -0
- package/src/apis/people/types.ts +7 -2
- package/src/apis/permissions/PermissionsApi.test.ts +93 -0
- package/src/apis/permissions/PermissionsApi.ts +7 -7
- package/src/apis/permissions/types.ts +4 -16
- package/src/apis/personalAccessTokens/PersonalAccessTokensApi.ts +5 -0
- package/src/apis/personalAccessTokens/types.ts +25 -4
- package/src/apis/queryFormat.test.ts +75 -0
- package/src/apis/roles/RolesApi.ts +7 -2
- package/src/apis/roles/types.ts +27 -4
- package/src/apis/terms/TermsApi.ts +4 -1
- package/src/apis/timetable/types.ts +13 -7
- package/src/core/BaseCrudApi.ts +4 -60
- package/src/core/BaseReadApi.ts +70 -0
- package/src/core/index.ts +1 -0
|
@@ -17,33 +17,29 @@ export type CustomFieldType =
|
|
|
17
17
|
| 'list'
|
|
18
18
|
|
|
19
19
|
export type CustomFieldOption = {
|
|
20
|
-
id?: string
|
|
21
|
-
label?: string
|
|
20
|
+
id?: string | null
|
|
21
|
+
label?: string | null
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Settings of a custom field — a free JSONB the backend does not validate, echoed back as sent.
|
|
26
|
+
* The fields below are the ones the web app form sends (`front/src/pages/custom-fields/components/
|
|
27
|
+
* form.tsx`): `options` for the `list` and `checkbox` types, `min`/`max` for `numeric` and `monetary`,
|
|
28
|
+
* `currency` for `monetary`, `maxLength` for `text` and `long-text`, and `placeholder` for the inputs.
|
|
29
|
+
*/
|
|
30
|
+
export type CustomFieldSettings = {
|
|
31
|
+
options?: CustomFieldOption[]
|
|
32
|
+
placeholder?: string | null
|
|
33
|
+
currency?: string | null
|
|
34
|
+
maxLength?: number | null
|
|
35
|
+
min?: string | null
|
|
36
|
+
max?: string | null
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
max?: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Settings for `text` and `long-text` types: optional max length constraint. */
|
|
37
|
-
export type CustomFieldTextSettings = {
|
|
38
|
-
options: CustomFieldOption[]
|
|
39
|
-
maxLength?: number
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type CustomFieldSettings =
|
|
43
|
-
| CustomFieldListSettings
|
|
44
|
-
| CustomFieldMonetarySettings
|
|
45
|
-
| CustomFieldTextSettings
|
|
46
|
-
|
|
39
|
+
/**
|
|
40
|
+
* A custom field of the account. Custom fields are soft-deleted, but `deletedAt` is never returned
|
|
41
|
+
* (customFieldsTransformer).
|
|
42
|
+
*/
|
|
47
43
|
export type CustomField = {
|
|
48
44
|
id: string
|
|
49
45
|
name: string
|
|
@@ -55,7 +51,6 @@ export type CustomField = {
|
|
|
55
51
|
accountId: string
|
|
56
52
|
createdAt: string
|
|
57
53
|
updatedAt: string
|
|
58
|
-
deletedAt: string | null
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
export type CreateCustomFieldPayload = {
|
|
@@ -64,12 +59,13 @@ export type CreateCustomFieldPayload = {
|
|
|
64
59
|
allowed: 'contacts'
|
|
65
60
|
showOnRegister?: boolean
|
|
66
61
|
required?: boolean
|
|
67
|
-
settings?: CustomFieldSettings
|
|
62
|
+
settings?: CustomFieldSettings | null
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
export type UpdateCustomFieldPayload = {
|
|
71
66
|
name?: string
|
|
72
67
|
type?: CustomFieldType
|
|
68
|
+
allowed?: 'contacts'
|
|
73
69
|
showOnRegister?: boolean
|
|
74
70
|
required?: boolean
|
|
75
71
|
settings?: CustomFieldSettings | null
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { DashboardApi } from './DashboardApi'
|
|
3
|
+
import type { ApiClient } from '../../core/ApiClient'
|
|
4
|
+
import type { DashboardGeneral } from './types'
|
|
5
|
+
|
|
6
|
+
// ── Mock client factory ──────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
function createMockClient(): ApiClient {
|
|
9
|
+
return {
|
|
10
|
+
setAccessToken: vi.fn().mockReturnThis(),
|
|
11
|
+
request: vi.fn(),
|
|
12
|
+
get: vi.fn(),
|
|
13
|
+
post: vi.fn(),
|
|
14
|
+
put: vi.fn(),
|
|
15
|
+
patch: vi.fn(),
|
|
16
|
+
delete: vi.fn(),
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ── Fixtures ─────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
const general: DashboardGeneral = {
|
|
23
|
+
sentMessagesCount: 10,
|
|
24
|
+
receivedMessagesCount: 5,
|
|
25
|
+
totalMessagesCount: 15,
|
|
26
|
+
openedTicketsCount: 2,
|
|
27
|
+
closedTicketsCount: 3,
|
|
28
|
+
totalTicketsCount: 5,
|
|
29
|
+
waitingTime: 60,
|
|
30
|
+
waitingTimeAfterBot: 30,
|
|
31
|
+
waitingTimeAvg: 45,
|
|
32
|
+
ticketTime: 600,
|
|
33
|
+
contactsCount: 4,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ── Tests ────────────────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
describe('DashboardApi', () => {
|
|
39
|
+
let client: ReturnType<typeof createMockClient>
|
|
40
|
+
let api: DashboardApi
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
client = createMockClient()
|
|
44
|
+
api = new DashboardApi(client)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('has no CRUD routes', () => {
|
|
48
|
+
expect(api.basePath).toBe('/dashboard')
|
|
49
|
+
expect(api).not.toHaveProperty('getMany')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('getGeneral', () => {
|
|
53
|
+
it('calls client.get with /dashboard/general and no query string', async () => {
|
|
54
|
+
vi.mocked(client.get).mockResolvedValue(general)
|
|
55
|
+
const result = await api.getGeneral()
|
|
56
|
+
expect(client.get).toHaveBeenCalledWith('/dashboard/general', undefined)
|
|
57
|
+
expect(result).toEqual(general)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('sends the filters in the query string', async () => {
|
|
61
|
+
vi.mocked(client.get).mockResolvedValue(general)
|
|
62
|
+
const query = {
|
|
63
|
+
startPeriod: '2026-09-01T00:00:00.000Z',
|
|
64
|
+
endPeriod: '2026-09-07T23:59:59.999Z',
|
|
65
|
+
status: 'closed' as const,
|
|
66
|
+
departmentId: ['d1'],
|
|
67
|
+
}
|
|
68
|
+
await api.getGeneral(query)
|
|
69
|
+
expect(client.get).toHaveBeenCalledWith(
|
|
70
|
+
`/dashboard/general?query=${encodeURIComponent(JSON.stringify(query))}`,
|
|
71
|
+
undefined,
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('forwards custom headers', async () => {
|
|
76
|
+
vi.mocked(client.get).mockResolvedValue(general)
|
|
77
|
+
const headers = { 'X-Custom': 'h' }
|
|
78
|
+
await api.getGeneral(undefined, headers)
|
|
79
|
+
expect(client.get).toHaveBeenCalledWith('/dashboard/general', headers)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseApi } from '../../core/BaseApi'
|
|
2
|
+
import type { DashboardGeneral, DashboardQuery } from './types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Service statistics ("Estatísticas de atendimento"). The `/dashboard` routes only require an
|
|
6
|
+
* authenticated user (no permission check).
|
|
7
|
+
*/
|
|
8
|
+
export class DashboardApi extends BaseApi {
|
|
9
|
+
public readonly basePath = '/dashboard'
|
|
10
|
+
|
|
11
|
+
/** Message, ticket, contact and time counts of the period (`GET /dashboard/general`). */
|
|
12
|
+
getGeneral(query?: DashboardQuery, headers?: Record<string, string>): Promise<DashboardGeneral> {
|
|
13
|
+
return this.client.get<DashboardGeneral>(
|
|
14
|
+
`${this.basePath}/general${this.toQueryString(query)}`,
|
|
15
|
+
headers,
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters of the service statistics (`/dashboard`). Every field is optional; the period defaults to
|
|
3
|
+
* the last 7 days.
|
|
4
|
+
*/
|
|
5
|
+
export type DashboardQuery = {
|
|
6
|
+
/** ISO date-time. Default: 7 days ago, 00:00. */
|
|
7
|
+
startPeriod?: string
|
|
8
|
+
/** ISO date-time. Default: the end of the `startPeriod` day (or of today). */
|
|
9
|
+
endPeriod?: string
|
|
10
|
+
/** Which ticket date the period filters: opening (default) or closing. */
|
|
11
|
+
periodType?: 'openDate' | 'closeDate'
|
|
12
|
+
/** Ticket status (`closed`, not `close`). */
|
|
13
|
+
status?: 'all' | 'open' | 'closed'
|
|
14
|
+
/**
|
|
15
|
+
* A department id, a list of ids, or `all`. Only applied together with `departmentParticipation`:
|
|
16
|
+
* without it the backend ignores `departmentId` and answers the totals of every department.
|
|
17
|
+
*/
|
|
18
|
+
departmentId?: string | string[]
|
|
19
|
+
/**
|
|
20
|
+
* Whether the department must be the ticket's last one or any one it went through. Required for
|
|
21
|
+
* `departmentId` to filter; sent WITHOUT `departmentId`, it filters the tickets with no department.
|
|
22
|
+
*/
|
|
23
|
+
departmentParticipation?: 'last' | 'middle'
|
|
24
|
+
/**
|
|
25
|
+
* A user id, a list of ids, or `all`. Only applied together with `userParticipation`: without it
|
|
26
|
+
* the backend ignores `userId` and answers the totals of every user.
|
|
27
|
+
*/
|
|
28
|
+
userId?: string | string[]
|
|
29
|
+
/**
|
|
30
|
+
* Whether the user must be the ticket's last one or any one it went through. Required for `userId`
|
|
31
|
+
* to filter; sent WITHOUT `userId`, it filters the tickets with no user.
|
|
32
|
+
*/
|
|
33
|
+
userParticipation?: 'last' | 'middle'
|
|
34
|
+
userStatus?: 'active' | 'archived' | 'all'
|
|
35
|
+
serviceId?: string | string[]
|
|
36
|
+
tagId?: string | string[]
|
|
37
|
+
ticketTopicId?: string | string[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `GET /dashboard/general` — counts of the period. Times are in seconds. */
|
|
41
|
+
export type DashboardGeneral = {
|
|
42
|
+
sentMessagesCount: number
|
|
43
|
+
receivedMessagesCount: number
|
|
44
|
+
totalMessagesCount: number
|
|
45
|
+
openedTicketsCount: number
|
|
46
|
+
closedTicketsCount: number
|
|
47
|
+
totalTicketsCount: number
|
|
48
|
+
waitingTime: number
|
|
49
|
+
waitingTimeAfterBot: number
|
|
50
|
+
waitingTimeAvg: number
|
|
51
|
+
ticketTime: number
|
|
52
|
+
contactsCount: number
|
|
53
|
+
}
|
|
@@ -1,25 +1,53 @@
|
|
|
1
|
+
import type { Account } from '../accounts/types'
|
|
2
|
+
import type { File } from '../files/types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A holiday: the account's services answer `message` during the period `from`–`to`.
|
|
6
|
+
* Holidays are soft-deleted, but `deletedAt` is never returned.
|
|
7
|
+
*/
|
|
1
8
|
export type Holiday = {
|
|
2
9
|
id: string
|
|
3
10
|
name: string
|
|
4
11
|
from: string
|
|
5
12
|
to: string
|
|
6
13
|
message: string
|
|
14
|
+
/** Whether the period is over. */
|
|
15
|
+
expired: boolean
|
|
16
|
+
/** Number of attached files (computed on the listing, derived from `files` on the detail). */
|
|
17
|
+
filesCount: number
|
|
18
|
+
/**
|
|
19
|
+
* Attached files — always an array. Only loaded on `getById` (or when listed with
|
|
20
|
+
* `include: ['files']`): `getMany` answers `[]` even when the holiday has files, so use
|
|
21
|
+
* `filesCount` there.
|
|
22
|
+
*/
|
|
23
|
+
files: File[]
|
|
7
24
|
accountId: string
|
|
8
25
|
createdAt: string
|
|
9
|
-
|
|
10
|
-
|
|
26
|
+
/** Virtual attribute of the model — may be absent. */
|
|
27
|
+
updatedAt?: string | null
|
|
28
|
+
// relationships
|
|
29
|
+
account?: Account
|
|
11
30
|
}
|
|
12
31
|
|
|
32
|
+
export type HolidayRelationships = 'account' | 'files'
|
|
33
|
+
|
|
34
|
+
/** A file attached by id (up to 10 per holiday). */
|
|
35
|
+
export type HolidayFileRef = { id: string }
|
|
36
|
+
|
|
13
37
|
export type CreateHolidayPayload = {
|
|
38
|
+
/** Up to 255 characters. */
|
|
14
39
|
name: string
|
|
40
|
+
/** Date string. A period overlapping another holiday answers 402 "Holiday time already exists.". */
|
|
15
41
|
from: string
|
|
42
|
+
/** Date string. */
|
|
16
43
|
to: string
|
|
44
|
+
/** Up to 1024 characters. */
|
|
17
45
|
message: string
|
|
46
|
+
files?: HolidayFileRef[]
|
|
18
47
|
}
|
|
19
48
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
49
|
+
/**
|
|
50
|
+
* The backend requires name, from, to and message on every update (same validator as the create).
|
|
51
|
+
* Omitting `files` keeps the current attachments.
|
|
52
|
+
*/
|
|
53
|
+
export type UpdateHolidayPayload = CreateHolidayPayload
|
package/src/apis/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './contactBlockListsControls'
|
|
|
15
15
|
export * from './contacts'
|
|
16
16
|
export * from './creditMovements'
|
|
17
17
|
export * from './customFields'
|
|
18
|
+
export * from './dashboard'
|
|
18
19
|
export * from './departments'
|
|
19
20
|
export * from './distribution'
|
|
20
21
|
export * from './files'
|
|
@@ -29,6 +30,7 @@ export * from './knowledgeBaseItem'
|
|
|
29
30
|
export * from './me'
|
|
30
31
|
export * from './messages'
|
|
31
32
|
export * from './notifications'
|
|
33
|
+
export * from './now'
|
|
32
34
|
export * from './organizations'
|
|
33
35
|
export * from './people'
|
|
34
36
|
export * from './permissions'
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { NowApi } from './NowApi'
|
|
3
|
+
import type { ApiClient } from '../../core/ApiClient'
|
|
4
|
+
import type {
|
|
5
|
+
NowAttendanceResume,
|
|
6
|
+
NowDepartmentResume,
|
|
7
|
+
NowResponse,
|
|
8
|
+
NowResumeTotals,
|
|
9
|
+
} from './types'
|
|
10
|
+
|
|
11
|
+
// ── Mock client factory ──────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
function createMockClient(): ApiClient {
|
|
14
|
+
return {
|
|
15
|
+
setAccessToken: vi.fn().mockReturnThis(),
|
|
16
|
+
request: vi.fn(),
|
|
17
|
+
get: vi.fn(),
|
|
18
|
+
post: vi.fn(),
|
|
19
|
+
put: vi.fn(),
|
|
20
|
+
patch: vi.fn(),
|
|
21
|
+
delete: vi.fn(),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ── Fixtures ─────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
const resume: NowResponse<NowResumeTotals> = {
|
|
28
|
+
totals: {
|
|
29
|
+
openTickets: 3,
|
|
30
|
+
queueTickets: 1,
|
|
31
|
+
usersWithAttendance: 2,
|
|
32
|
+
usersWithoutAttendance: 1,
|
|
33
|
+
averageOpenTicketsTime: '125.5',
|
|
34
|
+
averageOpenTicketsWaitTime: 0,
|
|
35
|
+
onlineUsersCount: 2,
|
|
36
|
+
offlineUsersCount: 4,
|
|
37
|
+
absentUsersCount: 0,
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
const attendance: NowResponse<NowAttendanceResume[]> = {
|
|
41
|
+
totals: [{ name: 'Ana', departments: ['Suporte'], status: 'online', ticketsOpenCount: 2 }],
|
|
42
|
+
}
|
|
43
|
+
const departments: NowResponse<NowDepartmentResume[]> = {
|
|
44
|
+
totals: [
|
|
45
|
+
{
|
|
46
|
+
name: 'Suporte',
|
|
47
|
+
onlineUserCount: 1,
|
|
48
|
+
offlineUserCount: 0,
|
|
49
|
+
absentUserCount: 0,
|
|
50
|
+
onQueueTicketCount: 1,
|
|
51
|
+
openTicketCount: 2,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const jsonQuery = (query: object) => `?query=${encodeURIComponent(JSON.stringify(query))}`
|
|
57
|
+
|
|
58
|
+
// ── Tests ────────────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
describe('NowApi', () => {
|
|
61
|
+
let client: ReturnType<typeof createMockClient>
|
|
62
|
+
let api: NowApi
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
client = createMockClient()
|
|
66
|
+
api = new NowApi(client)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('has no CRUD routes', () => {
|
|
70
|
+
expect(api.basePath).toBe('/now')
|
|
71
|
+
expect(api).not.toHaveProperty('getMany')
|
|
72
|
+
expect(api).not.toHaveProperty('create')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('getResume', () => {
|
|
76
|
+
it('calls client.get with /now/resume and no query string', async () => {
|
|
77
|
+
vi.mocked(client.get).mockResolvedValue(resume)
|
|
78
|
+
const result = await api.getResume()
|
|
79
|
+
expect(client.get).toHaveBeenCalledWith('/now/resume', undefined)
|
|
80
|
+
expect(result).toEqual(resume)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('sends the department/user filters in the query string', async () => {
|
|
84
|
+
vi.mocked(client.get).mockResolvedValue(resume)
|
|
85
|
+
await api.getResume({ departmentId: ['d1', 'd2'], userId: 'u1' })
|
|
86
|
+
expect(client.get).toHaveBeenCalledWith(
|
|
87
|
+
`/now/resume${jsonQuery({ departmentId: ['d1', 'd2'], userId: 'u1' })}`,
|
|
88
|
+
undefined,
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('forwards custom headers', async () => {
|
|
93
|
+
vi.mocked(client.get).mockResolvedValue(resume)
|
|
94
|
+
const headers = { 'X-Custom': 'h' }
|
|
95
|
+
await api.getResume(undefined, headers)
|
|
96
|
+
expect(client.get).toHaveBeenCalledWith('/now/resume', headers)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('getAttendanceResume', () => {
|
|
101
|
+
it('calls client.get with /now/attendance-resume', async () => {
|
|
102
|
+
vi.mocked(client.get).mockResolvedValue(attendance)
|
|
103
|
+
const result = await api.getAttendanceResume({ departmentId: 'd1' })
|
|
104
|
+
expect(client.get).toHaveBeenCalledWith(
|
|
105
|
+
`/now/attendance-resume${jsonQuery({ departmentId: 'd1' })}`,
|
|
106
|
+
undefined,
|
|
107
|
+
)
|
|
108
|
+
expect(result).toEqual(attendance)
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
describe('getDepartmentsResume', () => {
|
|
113
|
+
it('calls client.get with /now/departments-resume', async () => {
|
|
114
|
+
vi.mocked(client.get).mockResolvedValue(departments)
|
|
115
|
+
const result = await api.getDepartmentsResume()
|
|
116
|
+
expect(client.get).toHaveBeenCalledWith('/now/departments-resume', undefined)
|
|
117
|
+
expect(result).toEqual(departments)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('propagates errors from client.get', async () => {
|
|
121
|
+
vi.mocked(client.get).mockRejectedValue(new Error('Forbidden'))
|
|
122
|
+
await expect(api.getDepartmentsResume()).rejects.toThrow('Forbidden')
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseApi } from '../../core/BaseApi'
|
|
2
|
+
import type {
|
|
3
|
+
NowAttendanceResume,
|
|
4
|
+
NowDepartmentResume,
|
|
5
|
+
NowQuery,
|
|
6
|
+
NowResponse,
|
|
7
|
+
NowResumeTotals,
|
|
8
|
+
} from './types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The "Agora" (now) overview: live totals of tickets and attendants. Every route requires
|
|
12
|
+
* `overview.now.view.all` or `overview.now.view.departments` (the latter is scoped to the user's
|
|
13
|
+
* departments).
|
|
14
|
+
*/
|
|
15
|
+
export class NowApi extends BaseApi {
|
|
16
|
+
public readonly basePath = '/now'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Account totals: open/queued tickets, attendants with/without attendance and online/offline/absent users.
|
|
20
|
+
* @permissions overview.now.view.all | overview.now.view.departments
|
|
21
|
+
*/
|
|
22
|
+
getResume(
|
|
23
|
+
query?: NowQuery,
|
|
24
|
+
headers?: Record<string, string>,
|
|
25
|
+
): Promise<NowResponse<NowResumeTotals>> {
|
|
26
|
+
return this.client.get<NowResponse<NowResumeTotals>>(
|
|
27
|
+
`${this.basePath}/resume${this.toQueryString(query)}`,
|
|
28
|
+
headers,
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Per-attendant totals (name, departments, status and open tickets).
|
|
34
|
+
* @permissions overview.now.view.all | overview.now.view.departments
|
|
35
|
+
*/
|
|
36
|
+
getAttendanceResume(
|
|
37
|
+
query?: NowQuery,
|
|
38
|
+
headers?: Record<string, string>,
|
|
39
|
+
): Promise<NowResponse<NowAttendanceResume[]>> {
|
|
40
|
+
return this.client.get<NowResponse<NowAttendanceResume[]>>(
|
|
41
|
+
`${this.basePath}/attendance-resume${this.toQueryString(query)}`,
|
|
42
|
+
headers,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Per-department totals (online/offline/absent users, queued and open tickets).
|
|
48
|
+
* @permissions overview.now.view.all | overview.now.view.departments
|
|
49
|
+
*/
|
|
50
|
+
getDepartmentsResume(
|
|
51
|
+
query?: NowQuery,
|
|
52
|
+
headers?: Record<string, string>,
|
|
53
|
+
): Promise<NowResponse<NowDepartmentResume[]>> {
|
|
54
|
+
return this.client.get<NowResponse<NowDepartmentResume[]>>(
|
|
55
|
+
`${this.basePath}/departments-resume${this.toQueryString(query)}`,
|
|
56
|
+
headers,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { User } from '../users/types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filters of the "Agora" (now) overview. Each accepts one id, an array or a comma-separated list.
|
|
5
|
+
* A user with only `overview.now.view.departments` gets 403 for departments/users outside their
|
|
6
|
+
* departments.
|
|
7
|
+
*/
|
|
8
|
+
export type NowQuery = {
|
|
9
|
+
departmentId?: string | string[]
|
|
10
|
+
userId?: string | string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Every `/now` route answers its data under `totals`. */
|
|
14
|
+
export type NowResponse<T> = { totals: T }
|
|
15
|
+
|
|
16
|
+
export type NowResumeTotals = {
|
|
17
|
+
openTickets: number
|
|
18
|
+
queueTickets: number
|
|
19
|
+
usersWithAttendance: number
|
|
20
|
+
usersWithoutAttendance: number
|
|
21
|
+
/** Postgres `avg()` — a numeric string, or `0` when there is no data. */
|
|
22
|
+
averageOpenTicketsTime: number | string
|
|
23
|
+
/** Postgres `avg()` — a numeric string, or `0` when there is no data. */
|
|
24
|
+
averageOpenTicketsWaitTime: number | string
|
|
25
|
+
onlineUsersCount: number
|
|
26
|
+
offlineUsersCount: number
|
|
27
|
+
absentUsersCount: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One entry per department. */
|
|
31
|
+
export type NowDepartmentResume = {
|
|
32
|
+
name: string
|
|
33
|
+
onlineUserCount: number
|
|
34
|
+
offlineUserCount: number
|
|
35
|
+
absentUserCount: number
|
|
36
|
+
onQueueTicketCount: number
|
|
37
|
+
openTicketCount: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** One entry per attendant (user). */
|
|
41
|
+
export type NowAttendanceResume = {
|
|
42
|
+
name?: string
|
|
43
|
+
/** Department names — `0` when the attendant has no department. */
|
|
44
|
+
departments: string[] | 0
|
|
45
|
+
status?: User['status']
|
|
46
|
+
ticketsOpenCount: number
|
|
47
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { expectError } from 'tsd'
|
|
2
|
+
import type { ApiClient } from '../core/ApiClient'
|
|
3
|
+
import { PersonalAccessTokensApi } from './personalAccessTokens/PersonalAccessTokensApi'
|
|
4
|
+
import { RolesApi } from './roles/RolesApi'
|
|
5
|
+
import { TimetableApi } from './timetable/TimetableApi'
|
|
6
|
+
|
|
7
|
+
declare const client: ApiClient
|
|
8
|
+
|
|
9
|
+
// ── roles: the backend drops `permissionIds` in silence ─────────────
|
|
10
|
+
|
|
11
|
+
const roles = new RolesApi(client)
|
|
12
|
+
roles.create({ displayName: 'Supervisor', permissions: ['p-1', { id: 'p-2' }] })
|
|
13
|
+
expectError(roles.create({ displayName: 'Supervisor', permissionIds: ['p-1'] }))
|
|
14
|
+
expectError(roles.updateById('r-1', { permissions: ['p-1'] }))
|
|
15
|
+
|
|
16
|
+
// ── timetable: the old workPlan shape answers 400 ───────────────────
|
|
17
|
+
|
|
18
|
+
const timetable = new TimetableApi(client)
|
|
19
|
+
timetable.create({
|
|
20
|
+
name: 'Business hours',
|
|
21
|
+
previousTimeToNotification: 15,
|
|
22
|
+
workPlan: [{ start: '08:00', end: '18:00', weekDays: ['mon'] }],
|
|
23
|
+
})
|
|
24
|
+
expectError(
|
|
25
|
+
timetable.create({
|
|
26
|
+
name: 'Business hours',
|
|
27
|
+
previousTimeToNotification: 15,
|
|
28
|
+
workPlan: [{ day: 1, start: '08:00', end: '18:00', active: true }],
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
31
|
+
expectError(timetable.updateById('t-1', { name: 'Business hours' }))
|
|
32
|
+
|
|
33
|
+
// ── personal access tokens: `expiresIn` is the only lifetime accepted ─
|
|
34
|
+
|
|
35
|
+
const tokens = new PersonalAccessTokensApi(client)
|
|
36
|
+
tokens.create({ name: 'CI', expiresIn: '90d' })
|
|
37
|
+
expectError(tokens.create({ name: 'CI', accessTokenExpiresAt: '2030-01-01T00:00:00Z' }))
|
|
38
|
+
expectError(tokens.create({ name: 'CI', expiresIn: '7d' }))
|
|
39
|
+
expectError(tokens.updateById('t-1', { scope: '*' }))
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import type { ApiClient } from '../core/ApiClient'
|
|
3
|
+
import { PersonalAccessTokensApi } from './personalAccessTokens/PersonalAccessTokensApi'
|
|
4
|
+
import { RolesApi } from './roles/RolesApi'
|
|
5
|
+
import { TimetableApi } from './timetable/TimetableApi'
|
|
6
|
+
|
|
7
|
+
// Pins the body keys the backend reads: a key it does not know is dropped in silence, so a
|
|
8
|
+
// regression would only show up as missing data (e.g. a role created without permissions).
|
|
9
|
+
|
|
10
|
+
// ── Mock client factory ──────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
function createMockClient(): ApiClient {
|
|
13
|
+
return {
|
|
14
|
+
setAccessToken: vi.fn().mockReturnThis(),
|
|
15
|
+
request: vi.fn(),
|
|
16
|
+
get: vi.fn(),
|
|
17
|
+
post: vi.fn(),
|
|
18
|
+
put: vi.fn(),
|
|
19
|
+
patch: vi.fn(),
|
|
20
|
+
delete: vi.fn(),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ── Tests ────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
describe('payloads sent to the backend', () => {
|
|
27
|
+
let client: ReturnType<typeof createMockClient>
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
client = createMockClient()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('RolesApi', () => {
|
|
34
|
+
it('create sends the permissions under `permissions`', async () => {
|
|
35
|
+
await new RolesApi(client).create({
|
|
36
|
+
displayName: 'Supervisor',
|
|
37
|
+
permissions: ['p-1', { id: 'p-2' }],
|
|
38
|
+
})
|
|
39
|
+
expect(client.post).toHaveBeenCalledWith(
|
|
40
|
+
'/roles',
|
|
41
|
+
{ displayName: 'Supervisor', permissions: ['p-1', { id: 'p-2' }] },
|
|
42
|
+
undefined,
|
|
43
|
+
)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('updateById sends displayName and the permissions under `permissions`', async () => {
|
|
47
|
+
await new RolesApi(client).updateById('r-1', {
|
|
48
|
+
displayName: 'Supervisor',
|
|
49
|
+
permissions: ['p-1'],
|
|
50
|
+
})
|
|
51
|
+
expect(client.put).toHaveBeenCalledWith(
|
|
52
|
+
'/roles/r-1',
|
|
53
|
+
{ displayName: 'Supervisor', permissions: ['p-1'] },
|
|
54
|
+
undefined,
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('TimetableApi', () => {
|
|
60
|
+
it('create sends the workPlan as { start, end, weekDays }', async () => {
|
|
61
|
+
const body = {
|
|
62
|
+
name: 'Business hours',
|
|
63
|
+
previousTimeToNotification: 15,
|
|
64
|
+
workPlan: [{ start: '08:00', end: '18:00', weekDays: ['mon' as const, 'fri' as const] }],
|
|
65
|
+
}
|
|
66
|
+
await new TimetableApi(client).create(body)
|
|
67
|
+
expect(client.post).toHaveBeenCalledWith('/timetable', body, undefined)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('PersonalAccessTokensApi', () => {
|
|
72
|
+
it('create sends the lifetime under `expiresIn`', async () => {
|
|
73
|
+
await new PersonalAccessTokensApi(client).create({ name: 'CI', expiresIn: '90d' })
|
|
74
|
+
expect(client.post).toHaveBeenCalledWith(
|
|
75
|
+
'/me/tokens',
|
|
76
|
+
{ name: 'CI', expiresIn: '90d' },
|
|
77
|
+
undefined,
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|