{"id":15715575,"url":"https://github.com/kustom-dev/workos-events-consumer","last_synced_at":"2026-04-27T21:31:21.087Z","repository":{"id":255787628,"uuid":"853539012","full_name":"kustom-dev/workos-events-consumer","owner":"kustom-dev","description":"Cloudflare worker for processing events from the WorkOS Events API","archived":false,"fork":false,"pushed_at":"2024-09-19T00:36:18.000Z","size":90,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-30T20:18:04.071Z","etag":null,"topics":["cloudflare","cloudflare-workers","d1","miniflare","vitest","workos"],"latest_commit_sha":null,"homepage":"https://www.kustom.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kustom-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-06T21:32:37.000Z","updated_at":"2024-09-19T00:36:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"5649af90-6ad5-4bc8-ab42-9684f356740f","html_url":"https://github.com/kustom-dev/workos-events-consumer","commit_stats":null,"previous_names":["kustom-dev/workos-events-consumer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kustom-dev/workos-events-consumer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kustom-dev%2Fworkos-events-consumer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kustom-dev%2Fworkos-events-consumer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kustom-dev%2Fworkos-events-consumer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kustom-dev%2Fworkos-events-consumer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kustom-dev","download_url":"https://codeload.github.com/kustom-dev/workos-events-consumer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kustom-dev%2Fworkos-events-consumer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32356596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-workers","d1","miniflare","vitest","workos"],"created_at":"2024-10-03T21:42:01.630Z","updated_at":"2026-04-27T21:31:21.071Z","avatar_url":"https://github.com/kustom-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @kustom/workos-events-consumer\n\n## What does this Cloudflare Worker do?\n[WorkOS](https://workos.com/) is an auth service provider with a variety of products. It has an [Events API](https://workos.com/docs/events/data-syncing/events-api) which allows customers to sync WorkOS data within their application. WorkOS also provides webhooks but the Events API is the recommended approach to syncing data.\n\nThis repository contains a Cloudflare worker which runs on a schedule (every 60 seconds) and persists WorkOS data to a [Cloudflare D1 database](https://developers.cloudflare.com/d1). You can still use this code with another SQL database by using [Hyperdrive](https://developers.cloudflare.com/hyperdrive/). As of now, this repository does not contain a Hyperdrive example.\n\n## Getting Started\n- Have `npm`, `yarn` or `pnpm` installed. Commands in this repo use `pnpm`\n- Install dependencies via `pnpm i`\n- Initialize the dev DB with `pnpm run dev:init-db`\n- Start jaeger containers for viewing telemetry with `docker compose up -d`\n- Go to http://localhost:16686 for the dev environment and http://localhost:16687 for the test environment to view traces\n- Copy `sample.dev.vars` to `.dev.vars`\n- Add your WorkOS credentials to the `.dev.vars` file\n- Run with `pnpm run dev`\n- In another terminal tab run `curl 'http://localhost:8787/__scheduled?cron=*+*+*+*+*'`\n- The default behavior for the development environment is to request events in the last 60 seconds from the WorkOS Events API\n- You can modify this behavior by adding `EVENTS_RANGE_START` and/or `EVENTS_RANGE_END` to `.dev.vars` to fetch events within a given time range. Both env vars need to be a Unix Timestamp in Milliseconds\n- See the [Testing](#testing) section for how to generate and test events within a specific time range\n\n### Known limitations\n- This example worker does not take in event replay into account, processing the same event again will result in an error because the `event_id` and payload will already be in the database. This can be viewed as a feature or a bug depending on how you look at it\n- Running newer events is considered safe but please do your own testing\n\n## Local Database \u0026 Migrations\n- Create a new migration\n```\npnpm run migrations:create kustom_app_dev create_user_org_cursor_tables --env dev\n```\n\n- Apply migrations\n```\npnpm run dev:init-db\n```\n\n- Reset development DB\n```\npnpm run dev:destroy-db\n```\n\n## Testing\nThe current recommended approach for testing Cloudflare Workers is the [Vitest Integration](https://developers.cloudflare.com/workers/testing/vitest-integration/). It is in beta and I have not had a great experience with it, so far. The Vitest Integration is pinned to vitest version `1.5.0` at the time of writing (Sep 2024).\n\nThe tests in this repo DO NOT use the Vitest Integration. They run on the latest version of Vitest and Miniflare. The setup probably seems tedious but since I've invested the time and effort to get it working, I'm rolling with it until the Vitest Integration is stable.\n\nI didn't want to create new events every time the test suite runs. To get around that, I create a set of events that are appropriate for my use case, then set the `EVENTS_RANGE_START` and `EVENTS_RANGE_END` environment variables for the `test` environment. This ensures that I'm always processing the same events but still calling out to the real WorkOS API.\n\nOver time, when new events are added, they can be re-processed and the time interval for test events can be updated.\n\n- To run the test suite, copy `sample.envrc` to `.envrc` if you use [direnv](https://direnv.net/) or ensure those env vars are loaded\n- The test suite uses Vitest and Node's `process.env` to read environment variables\n- Uncomment the test at the top of `cursor.test.ts` and run the suite with `pnpm run test`\n- The tests will fail since the IDs for each entity will be different compared to the ones I've used\n- You can replace the IDs or change the `emitTestingEvents()` function to match your use case\n- Once you've matched the IDs, the tests should pass\n- If you want to examine your test D1 database, it's in `.wrangler/state/test/v3/d1/miniflare-D1DatabaseObject`\n\n### References\n\nThe implementation in this repo was informed by [this blog post](https://workos.com/blog/why-you-should-rethink-your-webhook-strategy) from WorkOS.\n\nThanks for providing an alternative to the webhook strategy and writing a detailed post about it.\n\n### Questions/Comments\n\nIf you have questions or would like to chat about this implementation, feel free to reach out via email: `hello@kustom.dev`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkustom-dev%2Fworkos-events-consumer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkustom-dev%2Fworkos-events-consumer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkustom-dev%2Fworkos-events-consumer/lists"}