-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
AuditEvents.ts
87 lines (78 loc) · 2.23 KB
/
AuditEvents.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type {
GitlabAPIResponse,
OneOrNoneOf,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
export interface AuditEventSchema extends Record<string, unknown> {
id: number;
author_id: number;
entity_id: number;
entity_type: string;
details: {
change?: string;
from?: string;
to?: string;
custom_message?: string;
author_name: string;
author_email: string;
target_id: string;
target_type: string;
target_details: string;
ip_address: string;
entity_path: string;
};
created_at: string;
}
function url({
projectId,
groupId,
}: { projectId?: string | number; groupId?: string | number } = {}): string {
let prefix = '';
if (projectId) prefix = endpoint`projects/${projectId}/`;
else if (groupId) prefix = endpoint`groups/${groupId}/`;
return `${prefix}audit_events`;
}
export interface AllAuditEventOptions {
createdAfter?: string;
createdBefore?: string;
entityType?: string;
entityId?: number;
}
export class AuditEvents<C extends boolean = false> extends BaseResource<C> {
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
{
projectId,
groupId,
...options
}: OneOrNoneOf<{ projectId: string | number; groupId: string | number }> &
AllAuditEventOptions &
Sudo &
ShowExpanded<E> &
PaginationRequestOptions<P> = {} as any,
): Promise<GitlabAPIResponse<AuditEventSchema[], C, E, P>> {
const uri = url({ projectId, groupId });
return RequestHelper.get<AuditEventSchema[]>()(
this,
uri,
options as AllAuditEventOptions & Sudo & ShowExpanded<E> & PaginationRequestOptions<P>,
);
}
show<E extends boolean = false>(
auditEventId: number,
{
projectId,
groupId,
...options
}: OneOrNoneOf<{ projectId: string | number; groupId: string | number }> &
Sudo &
ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<AuditEventSchema, C, E, void>> {
const uri = url({ projectId, groupId });
return RequestHelper.get<AuditEventSchema>()(this, `${uri}/${auditEventId}`, options);
}
}