/
Audits.ts
124 lines (111 loc) · 2.58 KB
/
Audits.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { QlikSaaSClient } from "qlik-rest-api";
import { URLBuild } from "../util/UrlBuild";
export interface IAudit {
id: string;
source: string;
contentType: string;
eventType: string;
eventId: string;
eventTime: string;
tenantId: string;
userId: string;
data: {
createdByUser: string;
description: string;
id: string;
sub: string;
subType: string;
tenantId: string;
};
links: {
Self: {
Href: string;
};
self: {
href: string;
};
};
}
export interface IAudit {
id: string;
source: string;
contentType: string;
eventType: string;
eventId: string;
eventTime: string;
tenantId: string;
userId: string;
data: {
createdByUser: string;
description: string;
id: string;
sub: string;
subType: string;
tenantId: string;
};
links: {
Self: {
Href: string;
};
self: {
href: string;
};
};
}
export interface IAuditsFilter {
id?: string[];
source?: string;
eventType?: string;
eventTime?: string;
userId?: string;
}
export interface IAuditsSettings {
EventTTL: number;
ArchiveEnabled: boolean;
}
export class Audits {
#saasClient: QlikSaaSClient;
constructor(saasClient: QlikSaaSClient) {
this.#saasClient = saasClient;
}
async get(arg: { id: string }) {
if (!arg.id) throw new Error(`audits.get: "id" parameter is required`);
return await this.#saasClient
.Get<IAudit>(`audits/${arg.id}`)
.then((res) => res.data);
}
async getAll(arg: IAuditsFilter) {
const urlBuild = new URLBuild("audits");
urlBuild.addParam("id", arg.id);
urlBuild.addParam("source", arg.source);
urlBuild.addParam("eventType", arg.eventType);
urlBuild.addParam("eventTime", arg.eventTime);
urlBuild.addParam("userId", arg.userId);
return await this.#saasClient
.Get<IAudit[]>(urlBuild.getUrl())
.then((res) => res.data);
}
async settings() {
return await this.#saasClient
.Get<IAuditsSettings>(`audits/settings`)
.then((res) => res.data);
}
async sources() {
return await this.#saasClient
.Get<string[]>(`audits/sources`)
.then((res) => res.data);
}
async types() {
return await this.#saasClient
.Get<string[]>(`audits/types`)
.then((res) => res.data);
}
// TODO: different types are returned in data:{...}
async archive(arg: { date: string }) {
if (!arg.date)
throw new Error(`audits.archive: "date" parameter is required`);
return await this.#saasClient
.Get<IAudit[]>(`audits/archive?date=${arg.date}`)
.then((res) => res.data);
}
}