Define strict JSON Schema for validating event metadata.
Audit Log Events can contain arbitrary metadata for adding additional details to your events. Normally this data can take any shape. However, custom metadata schemas can be defined when configuring the event for additional type safety and data consistency. When an event is emitted that does not match the provided schema, an error will be returned.
When first creating an event schema, check the “Require metadata schema validation” checkbox. You will then be navigated to the schema editor where you can modify the underlying JSON Schema for all metadata
objects.
There are metadata
objects located at the root of the event, and within actor
and targets
objects. Each can contain a unique JSON Schema. To add to a metadata
object, click the ”+” sign.
Metadata objects have a limit of 50 keys. Key names can be up to 40 characters long, and values can be up to 500 characters long.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); await workos.auditLogs.createEvent('org_01EHWNCE74X7JSDV0X3SZ3KJNY', { action: 'user.signed_in', occurredAt: new Date(), actor: { type: 'user', id: 'user_01GBNJC3MX9ZZJW1FSTF4C5938', metadata: { role: 'admin', }, }, targets: [ { type: 'team', id: 'team_01GBNJD4MKHVKJGEWK42JNMBGS', metadata: { owner: 'user_01GBTCQ2MZG9C87R7NAQZZS7M6', }, }, ], context: { location: '123.123.123.123', userAgent: 'Chrome/104.0.0.0', }, metadata: { environment: 'staging', }, });