Skip to content

Commit

Permalink
Draft: Audit log GraphQL API
Browse files Browse the repository at this point in the history
codegen setup

fix some

some

some

some

more

?

??

SOME?

??

?

fix some?

SOME

???

more

some some

test

fix some code review!

?

fix some

clean!

fix codegen path

???

?

??

?

?

added scope ti auditlogmanager

scheme publish & check & delete

members role

CLEAN MORE

target

project

prettier

fix resolver schema published

lint
  • Loading branch information
TuvalSimha committed Sep 18, 2024
1 parent 6f41001 commit 005b64a
Show file tree
Hide file tree
Showing 42 changed files with 1,715 additions and 13 deletions.
25 changes: 25 additions & 0 deletions codegen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ const config: CodegenConfig = {
ID: 'string',
},
mappers: {
AuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
UserInvitedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
UserJoinedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
UserRemovedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
OrganizationSettingsUpdatedAuditLog:
'../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
OrganizationTransferredAuditLog:
'../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
ProjectCreatedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
ProjectSettingsUpdatedAuditLog:
'../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
ProjectDeletedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
TargetCreatedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
TargetSettingsUpdatedAuditLog:
'../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
TargetDeletedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
SchemaPolicySettingsUpdatedAuditLog:
'../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
SchemaCheckedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
SchemaPublishAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
SchemaDeletedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
RoleCreatedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
RoleAssignedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
RoleDeletedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
RoleUpdatedAuditLog: '../modules/audit-logs/module.graphql.mappers#AuditLogMapper',
SchemaChange: '../modules/schema/module.graphql.mappers#SchemaChangeMapper',
SchemaChangeApproval:
'../modules/schema/module.graphql.mappers#SchemaChangeApprovalMapper',
Expand Down
1 change: 0 additions & 1 deletion packages/libraries/core/src/client/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export function createAgent<TEvent>(
const promise = captureAsync(event);
inProgressCaptures.push(promise);
void promise.finally(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
inProgressCaptures = inProgressCaptures.filter(p => p !== promise);
});
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/services/api/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { adminModule } from './modules/admin';
import { alertsModule } from './modules/alerts';
import { WEBHOOKS_CONFIG, WebhooksConfig } from './modules/alerts/providers/tokens';
import { appDeploymentsModule } from './modules/app-deployments';
import { auditLogsModule } from './modules/audit-logs';
import { authModule } from './modules/auth';
import { billingModule } from './modules/billing';
import { BILLING_CONFIG, BillingConfig } from './modules/billing/providers/tokens';
Expand Down Expand Up @@ -81,6 +82,7 @@ const modules = [
integrationsModule,
alertsModule,
feedbackModule,
auditLogsModule,
cdnModule,
adminModule,
usageEstimationModule,
Expand Down
12 changes: 12 additions & 0 deletions packages/services/api/src/modules/audit-logs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createModule } from 'graphql-modules';
import { AuditLogManager } from './providers/audit-logs-manager';
import { resolvers } from './resolvers.generated';
import { typeDefs } from './module.graphql';

export const auditLogsModule = createModule({
id: 'audit-logs',
dirname: __dirname,
typeDefs,
resolvers,
providers: [AuditLogManager],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { AuditLogEvent } from './providers/audit-logs-types';

export type AuditLogMapper = AuditLogEvent;
263 changes: 263 additions & 0 deletions packages/services/api/src/modules/audit-logs/module.graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
import { gql } from 'graphql-modules';

export const typeDefs = gql`
interface AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
}
type AuditLogUserRecord {
userId: ID!
userEmail: String!
user: User # this one is nullable because it can be deleted!
}
type AuditLogConnection {
nodes: [AuditLog]!
total: Int!
}
type AuditLogFileExport {
id: ID!
url: String!
validUntil: Date!
createdAt: Date!
}
type ExportResultEdge {
node: AuditLogFileExport!
cursor: String!
}
type ExportResultConnection {
edges: [ExportResultEdge!]!
pageInfo: PageInfo!
}
input AuditLogFilter {
startDate: Date
endDate: Date
userId: String
userEmail: String
projectId: String
targetId: String
eventType: String # Filter by __typename if needed
}
extend type Query {
auditLogs(
filter: AuditLogFilter
first: String = "100"
after: String = null
): AuditLogConnection!
auditLogExports(first: String = 100, after: String = null): ExportResultConnection!
}
extend type Mutation {
exportAuditLogsToFile(filter: AuditLogFilter!): AuditLogFileExport!
}
type ModifyAuditLogError implements Error {
message: String!
}
type UserInvitedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
inviteeId: String!
inviteeEmail: String!
}
type UserJoinedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
inviteeId: String!
inviteeEmail: String!
}
type UserRemovedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
removedUserId: String!
removedUserEmail: String!
}
type OrganizationSettingsUpdatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
updatedFields: JSON!
}
type OrganizationTransferredAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
newOwnerId: String!
newOwnerEmail: String!
}
type ProjectCreatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
projectName: String!
}
type ProjectSettingsUpdatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
updatedFields: JSON!
}
type ProjectDeletedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
projectName: String!
}
type TargetCreatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
targetId: String!
targetName: String!
}
type TargetSettingsUpdatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
targetId: String!
updatedFields: JSON!
}
type TargetDeletedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
targetId: String!
targetName: String!
}
type SchemaPolicySettingsUpdatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
updatedFields: JSON!
}
type SchemaCheckedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
targetId: String!
schemaSdl: String!
}
type SchemaPublishAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
targetId: String!
schemaName: String!
}
type SchemaDeletedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
projectId: String!
targetId: String!
schemaName: String!
}
type RoleCreatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
roleId: String!
roleName: String!
}
type RoleAssignedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
roleId: String!
roleName: String!
userIdAssigned: String!
userEmailAssigned: String!
}
type RoleDeletedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
roleId: String!
roleName: String!
}
type RoleUpdatedAuditLog implements AuditLog {
id: ID!
eventTime: Date!
user: AuditLogUserRecord!
organizationId: String!
eventType: String!
roleId: String!
roleName: String!
updatedFields: JSON!
}
`;
Loading

0 comments on commit 005b64a

Please sign in to comment.