Skip to content

Commit 05808ba

Browse files
Merge pull request #6 from workos/feature/sup-759-typescript-add-example-app-for-audit
Add example TypeScript app for Audit Logs
2 parents 3d4f78d + 97cfdcb commit 05808ba

File tree

13 files changed

+2823
-0
lines changed

13 files changed

+2823
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.env
3+
out/
4+
tsconfig.tsbuildinfo
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# TypeScript Example App with Audit Logs powered by WorkOS
2+
3+
An example Node.js / TypeScript application demonstrating how to use the [WorkOS Node.js SDK](https://github.com/workos/workos-node) to send and retrieve Audit Log events. This app is not meant to show a real-world example of an Audit Logs implementation, but rather to show concrete examples of how events can be sent using the Node.js SDK.
4+
5+
## Prerequisites
6+
7+
-Node.js version 10+
8+
9+
## TypeScript Project Setup
10+
11+
1. Clone the main repo and install dependencies for the app you'd like to use:
12+
13+
```bash
14+
# HTTPS
15+
git clone https://github.com/workos/typescript-example-applications.git
16+
```
17+
18+
or
19+
20+
```bash
21+
# SSH
22+
git clone git@github.com:workos/typescript-example-applications.git
23+
```
24+
25+
2. Navigate to Audit Logs app within the cloned repo.
26+
27+
```bash
28+
$ cd typescript-example-applications/typescript-audit-logs-example
29+
```
30+
31+
3. Install the dependencies.
32+
```bash
33+
$ npm install
34+
```
35+
36+
## Configure your environment
37+
38+
4. Grab your API Key and Client ID from the WorkOS Dashboard. Create a `.env`
39+
file at the root of the project, and store these like so:
40+
41+
```bash
42+
WORKOS_API_KEY=sk_xxxxxxxxxxxxx
43+
WORKOS_CLIENT_ID=project_xxxxxxxxxxxx
44+
```
45+
46+
## Testing the Integration
47+
48+
5. Start the server and head to `http://localhost:8000/ to begin the login flow!
49+
50+
```sh
51+
npm start
52+
```
53+
54+
## Audit Logs setup
55+
56+
Follow the [Audit Logs configuration steps](https://workos.com/docs/audit-logs/emit-an-audit-log-event/sign-in-to-your-workos-dashboard-account-and-configure-audit-log-event-schemas) to set up the following 5 events that are sent with this example:
57+
58+
Action title: "user.signed_in" | Target type: "team"
59+
Action title: "user.logged_out" | Target type: "team"
60+
Action title: "user.organization_set" | Target type: "team"
61+
Action title: "user.organization_deleted" | Target type: "team"
62+
Action title: "user.connection_deleted" | Target type: "team"
63+
64+
Next, take note of the Organization ID for the Org which you will be sending the Audit Log events for. This ID gets entered into the splash page of the example application.
65+
66+
Once you enter the Organization ID and submit it, you will be brought to the page where you'll be able to send the audit log events that were just configured. You'll also notice that the action of setting the Organization triggered an Audit Log already. Click the buttons to send the respective events.
67+
68+
To obtain a CSV of the Audit Log events that were sent for the last 30 days, click the "Export Events" button. This will bring you to a new page where you can download the events. Downloading the events is a 2 step process. First you need to create the report by clicking the "Generate CSV" button. Then click the "Access CSV" button to download a CSV of the Audit Log events for the selected Organization for the past 30 days.
69+
70+
## Need help?
71+
72+
First, make sure to reference the Audit Logs docs at https://workos.com/docs/audit-logs.
73+
74+
If you get stuck and aren't able to resolve the issue by reading our docs or API reference, you can reach out to us at support@workos.com and we'll lend a hand.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const user_signed_in = {
2+
"action": "user.signed_in",
3+
"occurred_at": new Date().toISOString(),
4+
"actor": {
5+
"type": "user",
6+
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938",
7+
},
8+
"targets": [
9+
{
10+
"type": "team",
11+
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS",
12+
},
13+
],
14+
"context": {
15+
"location": "123.123.123.123",
16+
"user_agent": "Chrome/104.0.0.0",
17+
},
18+
}
19+
20+
const user_logged_out = {
21+
"action": "user.logged_out",
22+
"occurred_at": new Date().toISOString(),
23+
"actor": {
24+
"type": "user",
25+
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938",
26+
},
27+
"targets": [
28+
{
29+
"type": "team",
30+
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS",
31+
},
32+
],
33+
"context": {
34+
"location": "123.123.123.123",
35+
"user_agent": "Chrome/104.0.0.0",
36+
},
37+
}
38+
39+
const user_organization_set = {
40+
"action": "user.organization_set",
41+
"occurred_at": new Date().toISOString(),
42+
"actor": {
43+
"type": "user",
44+
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938",
45+
},
46+
"targets": [
47+
{
48+
"type": "team",
49+
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS",
50+
},
51+
],
52+
"context": {
53+
"location": "123.123.123.123",
54+
"user_agent": "Chrome/104.0.0.0",
55+
},
56+
}
57+
58+
const user_organization_deleted = {
59+
"action": "user.organization_deleted",
60+
"occurred_at": new Date().toISOString(),
61+
"actor": {
62+
"type": "user",
63+
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938",
64+
},
65+
"targets": [
66+
{
67+
"type": "team",
68+
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS",
69+
},
70+
],
71+
"context": {
72+
"location": "123.123.123.123",
73+
"user_agent": "Chrome/104.0.0.0",
74+
},
75+
}
76+
77+
const user_connection_deleted = {
78+
"action": "user.connection_deleted",
79+
"occurred_at": new Date().toISOString(),
80+
"actor": {
81+
"type": "user",
82+
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938",
83+
},
84+
"targets": [
85+
{
86+
"type": "team",
87+
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS",
88+
},
89+
],
90+
"context": {
91+
"location": "123.123.123.123",
92+
"user_agent": "Chrome/104.0.0.0",
93+
},
94+
}
95+
96+
module.exports = { user_signed_in, user_logged_out, user_organization_set, user_organization_deleted, user_connection_deleted };
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const express = require('express')
2+
import 'dotenv/config.js'
3+
const router = require('./routes/index.ts')
4+
import morgan from 'morgan'
5+
6+
const app = express()
7+
8+
const port = process.env.PORT || 8000
9+
10+
app.use('/public', express.static('public'))
11+
12+
app.use(express.urlencoded({ extended: false }))
13+
14+
app.use(express.json())
15+
16+
app.use(morgan('dev'))
17+
18+
app.use('/', router)
19+
20+
app.listen(port, () => {
21+
console.log(`⚡️ [server]: Server is running at https://localhost:${port}`)
22+
})

0 commit comments

Comments
 (0)