Skip to content

Commit 9550dd6

Browse files
willmanduffyWillman Duffy
andauthored
Migrate Audit Logs to camelCased (#780)
## Description * Part of a wider initiative to migrate our Node SDK to camel case for the 3.0.0 release. * Migrates the Audit Log module to camel case. ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [x] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. Co-authored-by: Willman Duffy <[email protected]>
1 parent 5e8a996 commit 9550dd6

11 files changed

+266
-116
lines changed

src/audit-logs/audit-logs.spec.ts

Lines changed: 148 additions & 103 deletions
Large diffs are not rendered by default.

src/audit-logs/audit-logs.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import {
44
CreateAuditLogEventRequestOptions,
55
} from './interfaces';
66
import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface';
7-
import { AuditLogExport } from './interfaces/audit-log-export.interface';
7+
import {
8+
AuditLogExport,
9+
AuditLogExportResponse,
10+
} from './interfaces/audit-log-export.interface';
11+
import {
12+
deserializeAuditLogExport,
13+
serializeAuditLogExportOptions,
14+
serializeCreateAuditLogEventOptions,
15+
} from './serializers';
816

917
export class AuditLogs {
1018
constructor(private readonly workos: WorkOS) {}
@@ -17,24 +25,27 @@ export class AuditLogs {
1725
await this.workos.post(
1826
'/audit_logs/events',
1927
{
20-
event,
28+
event: serializeCreateAuditLogEventOptions(event),
2129
organization_id: organization,
2230
},
2331
options,
2432
);
2533
}
2634

2735
async createExport(options: AuditLogExportOptions): Promise<AuditLogExport> {
28-
const { data } = await this.workos.post('/audit_logs/exports', options);
36+
const { data } = await this.workos.post<AuditLogExportResponse>(
37+
'/audit_logs/exports',
38+
serializeAuditLogExportOptions(options),
39+
);
2940

30-
return data;
41+
return deserializeAuditLogExport(data);
3142
}
3243

3344
async getExport(auditLogExportId: string): Promise<AuditLogExport> {
34-
const { data } = await this.workos.get(
45+
const { data } = await this.workos.get<AuditLogExportResponse>(
3546
`/audit_logs/exports/${auditLogExportId}`,
3647
);
3748

38-
return data;
49+
return deserializeAuditLogExport(data);
3950
}
4051
}
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
export interface AuditLogExportOptions {
22
actions?: string[];
33
/**
4-
* @deprecated Please use `actor_names` instead.
4+
* @deprecated Please use `actorNames` instead.
55
*/
66
actors?: string[];
7+
actorNames?: string[];
8+
actorIds?: string[];
9+
organizationId: string;
10+
rangeEnd: Date;
11+
rangeStart: Date;
12+
targets?: string[];
13+
}
14+
15+
export interface SerializedAuditLogExportOptions {
16+
actions?: string[];
17+
actors?: string[];
718
actor_names?: string[];
819
actor_ids?: string[];
920
organization_id: string;
10-
range_end: Date;
11-
range_start: Date;
21+
range_end: string;
22+
range_start: string;
1223
targets?: string[];
1324
}

src/audit-logs/interfaces/audit-log-export.interface.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
export interface AuditLogExport {
2+
object: 'audit_log_export';
3+
id: string;
4+
state: 'pending' | 'ready' | 'error';
5+
url?: string;
6+
createdAt: string;
7+
updatedAt: string;
8+
}
9+
10+
export interface AuditLogExportResponse {
211
object: 'audit_log_export';
312
id: string;
413
state: 'pending' | 'ready' | 'error';

src/audit-logs/interfaces/create-audit-log-event-options.interface.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@ export interface AuditLogTarget {
1717
export interface CreateAuditLogEventOptions {
1818
action: string;
1919
version?: number;
20-
occurred_at: Date;
20+
occurredAt: Date;
21+
actor: AuditLogActor;
22+
targets: AuditLogTarget[];
23+
context: {
24+
location: string;
25+
userAgent?: string;
26+
};
27+
metadata?: Record<string, string | number | boolean>;
28+
}
29+
30+
export interface SerializedCreateAuditLogEventOptions {
31+
action: string;
32+
version?: number;
33+
occurred_at: string;
2134
actor: AuditLogActor;
2235
targets: AuditLogTarget[];
2336
context: {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {
2+
AuditLogExportOptions,
3+
SerializedAuditLogExportOptions,
4+
} from '../interfaces';
5+
6+
export const serializeAuditLogExportOptions = (
7+
options: AuditLogExportOptions,
8+
): SerializedAuditLogExportOptions => ({
9+
actions: options.actions,
10+
actors: options.actors,
11+
actor_names: options.actorNames,
12+
actor_ids: options.actorIds,
13+
organization_id: options.organizationId,
14+
range_end: options.rangeEnd.toISOString(),
15+
range_start: options.rangeStart.toISOString(),
16+
targets: options.targets,
17+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AuditLogExport, AuditLogExportResponse } from '../interfaces';
2+
3+
export const deserializeAuditLogExport = (
4+
auditLogExport: AuditLogExportResponse,
5+
): AuditLogExport => ({
6+
object: auditLogExport.object,
7+
id: auditLogExport.id,
8+
state: auditLogExport.state,
9+
url: auditLogExport.url,
10+
createdAt: auditLogExport.created_at,
11+
updatedAt: auditLogExport.updated_at,
12+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {
2+
CreateAuditLogEventOptions,
3+
SerializedCreateAuditLogEventOptions,
4+
} from '../interfaces';
5+
6+
export const serializeCreateAuditLogEventOptions = (
7+
event: CreateAuditLogEventOptions,
8+
): SerializedCreateAuditLogEventOptions => ({
9+
action: event.action,
10+
version: event.version,
11+
occurred_at: event.occurredAt.toISOString(),
12+
actor: event.actor,
13+
targets: event.targets,
14+
context: {
15+
location: event.context.location,
16+
user_agent: event.context.userAgent,
17+
},
18+
metadata: event.metadata,
19+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './audit-log-export.serializer';
2+
export * from './audit-log-export-options.serializer';
3+
export * from './create-audit-log-event-options.serializer';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const mockWorkOsResponse = (status: number, data: unknown) => ({
2+
data,
3+
status,
4+
headers: {},
5+
statusText: '',
6+
config: {} as any,
7+
});

0 commit comments

Comments
 (0)