feat(listen): support headless mode for Docker/CI#8
Open
jamierpond wants to merge 12 commits intopolarsource:mainfrom
Open
feat(listen): support headless mode for Docker/CI#8jamierpond wants to merge 12 commits intopolarsource:mainfrom
jamierpond wants to merge 12 commits intopolarsource:mainfrom
Conversation
5b62333 to
3a4e190
Compare
Add --access-token, --env, and --org flags (with env var fallbacks) to `polar listen` so it can run without interactive prompts. This enables usage in Docker containers, CI pipelines, and scripts where no TTY or browser is available for OAuth login.
3a4e190 to
0360186
Compare
Author
|
@emilwidlund you got a moment to check this out? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
polar listenrequires interactive prompts (environment selection, OAuth browser login, organization selection), making it unusable in Docker containers, CI pipelines, or any headless context.Additionally, the prebuilt binary only ships for
linux/amd64anddarwin. On Apple Silicon Macs running Docker (linux/arm64), the binary crashes under Rosetta (SIGILL / exit code 132). Building from source solves the arch problem, but the interactive prompts still block headless use.What
Three new optional flags for
polar listen(each with an env var fallback):--access-token/POLAR_ACCESS_TOKEN— Use a personal access token directly, skipping the OAuth browser login flow--env sandbox|production/POLAR_ENVIRONMENT— Select the environment without the interactive prompt--org <slug-or-id>— Select an organization by slug or ID. Auto-selects when only one org existsOne new optional flag for webhook relay integrity:
--webhook-secret/POLAR_WEBHOOK_SECRET— Re-sign forwarded payloads using the standardwebhooks format (HMAC-SHA256), so the receiving app'svalidateEvent/Webhooks()signature verification passes without needing to disable it in developmentA multi-stage Dockerfile is included so the CLI can be built from source and run as a lightweight container — useful for local dev
docker-composesetups where you need a webhook relay sidecar alongside your app, database, etc. The final image only contains the built output and runtime dependencies.All existing interactive behavior is preserved when flags/env vars are not provided.
How
resolveEnvironment()checks--envflag, thenPOLAR_ENVIRONMENTenv var, then falls back to the interactive promptresolveAccessToken()checks--access-tokenflag, thenPOLAR_ACCESS_TOKENenv var, then falls back to the OAuth login flowresolveOrganization()fetches orgs via the API when using a personal access token (bypassing the OAuth-dependentPolarservice), auto-selects when only one org exists, and matches by slug or ID when--orgis providedsignPayload()generates standardwebhooks-compatible headers (webhook-id,webhook-timestamp,webhook-signature) using HMAC-SHA256 with the raw UTF-8 bytes of the secret — matching the key derivation in@polar-sh/sdk'svalidateEventWhat's not in scope
polar loginor other commandslinux/arm64prebuilt binaries (separate infrastructure change)@polar-sh/cliExamples
docker-compose sidecar
Test plan
--access-token+--env sandboxconnects without any promptsPOLAR_ACCESS_TOKEN+POLAR_ENVIRONMENTenv vars work identically--org <slug>selects the correct org when multiple exist--webhook-secretre-signs payloads; receiving app returns 200 (was 403 without signing)polar listen --helpshows all new options with descriptionssignPayloadsignatures verified against standardwebhooks (unit tests)