Skip to content

Add Oura webhook subscriptions#926

Open
darinkrauss wants to merge 1 commit intodarin/refactor-work-mixinsfrom
darin/oura-webhook-subscribe
Open

Add Oura webhook subscriptions#926
darinkrauss wants to merge 1 commit intodarin/refactor-work-mixinsfrom
darin/oura-webhook-subscribe

Conversation

@darinkrauss
Copy link
Contributor

- Add Oura webhook subscriptions
- Add Oura partner endpoints
- Add webhook work to periodically check and renew subscriptions
- Add custom error parser for Oura response with status 422
- Add UpdateSubscription struct and function
- Add OuraClient to data service context
- Add bson tags throughout in case struct is captured in persisted error
- Use time.ParseInLocation with default location time.UTC
- Add various Oura data validations
- Fix bugs
- Add and update tests
- https://tidepool.atlassian.net/browse/BACK-4027
- https://tidepool.atlassian.net/browse/BACK-4028
- https://tidepool.atlassian.net/browse/BACK-4029
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end support for Oura webhook subscription management (partner verification endpoint + periodic subscription sync/renew work), along with related client changes, validation updates, and broader BSON serialization coverage.

Changes:

  • Introduces Oura webhook subscription synchronization work (create/update/renew) and wires it into the work coordinator.
  • Adds Oura partner webhook verification endpoint and threads an OuraClient through the data service context/API.
  • Expands Oura models/validation (incl. UpdateSubscription, Subscriptions parsing/validation), adds BSON tags for persistence/serializable errors, and standardizes time parsing to UTC.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
work/store/structured/mongo/mongo.go Improves logging around work creation and duplicate-key handling.
test/array.go Adds generic helper to convert typed slices to []any for serialization tests.
structure/validator/string.go Parses times in UTC by default.
structure/parser/object_parser.go Parses times in UTC by default.
structure/parser/array_parser.go Parses times in UTC by default.
request/values_parser.go Parses times in UTC by default.
request/parser.go Parses time headers in UTC by default.
oura/work/processors/processors_test.go Updates EnsureWork tests for new signature and webhook subscribe work creation.
oura/work/processors/processors.go Changes EnsureWork to accept (ctx, workClient) and enqueue webhook subscribe work.
oura/webhook/work/subscribe/processor_test.go Adds comprehensive tests for subscription create/update/renew behavior.
oura/webhook/work/subscribe/processor.go Implements subscription synchronization logic (list/create/update/renew).
oura/webhook/webhook_test.go Renames webhook path constant and adds BSON serialization assertions.
oura/webhook/webhook.go Renames WebhookPathEventEventPath and adds BSON tags to webhook structs.
oura/test/oura_mocks.go Updates mocks for expanded Oura client/base client interfaces and signature changes.
oura/test/oura.go Adds UpdateSubscription test helpers and improves subscription serialization helpers.
oura/service/api/v1/v1.go Wires Oura webhook routes using the renamed EventPath.
oura/service/api/v1/subscription.go Implements webhook verification (challenge response + token validation).
oura/provider/provider.go Switches to OAuth provider client with custom error parser; stores partner URL as string.
oura/provider/config.go Adds BSON tags to partner config fields.
oura/oura_test.go Adds/extends tests for new constants, subscription structs, validators, and BSON serialization.
oura/oura.go Adds subscription structs/validation, subscriptions collection helpers, constants, and BSON tags.
oura/data/work/setup/processor_test.go Adjusts expectations ordering around data source deletion/update.
oura/data/work/historic/processor_test.go Adds BSON serialization assertions for work metadata.
oura/data/work/historic/processor.go Adds BSON inline tags to metadata structs.
oura/data/work/event/processor_test.go Adds BSON serialization assertions for work metadata.
oura/data/work/event/processor.go Adds BSON inline tags to metadata structs.
oura/client/error_parser.go Adds custom 422 → 400-style error parsing with response metadata capture.
oura/client/client.go Implements subscription CRUD/renew calls; refactors request sending and metrics patterns.
data/work/mixin_test.go Refactors tests to match new replace/delete/update sequencing.
data/work/mixin.go Moves original data source deletion earlier to avoid providerSessionId uniqueness conflicts.
data/source/source_test.go Adds BSON serialization assertions for filter/create/update structs.
data/source/source.go Adds BSON tags across data source API structs.
data/service/service/standard.go Ensures Oura work with logger context; threads Oura client into API creation.
data/service/context/standard.go Adds OuraClient to standard data service context.
data/service/context.go Extends data service context interface with OuraClient().
data/service/api/v1/v1.go Registers Oura service API v1 routes.
data/service/api/v1/users_datasets_create_test.go Updates mock context to satisfy new OuraClient() requirement.
data/service/api/standard.go Threads Oura client through API standard construction and request context creation.
data/raw/raw_test.go Adds BSON serialization checks (one formatting issue found in review).
data/raw/raw.go Adds BSON tags across raw data API structs.
auth/service/service/service.go Moves reconciler ensure step after registering processor factories.
auth/provider_session.go Adds BSON tags to provider session filter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@toddkazakov toddkazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is reason for adding bson struct tags to structs that are not being serialized as bson anywhere in the code base except in tests?

Copilot comments seems valid and good to be addressed. Everything else looks ok.

@darinkrauss
Copy link
Contributor Author

Updates based upon feedback included in later PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants