Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

Breaking changes:

- `client.integrations` is gone: `sync`, `status` and `disconnect`, with the types `IntegrationProvider`, `SyncProvider`, `IntegrationStatusDetail`, `IntegrationStatusResponse`, `IntegrationSyncResult`, `IntegrationSyncResponse` and `IntegrationDisconnectResponse`. The API no longer takes another app's intervals.icu access token: intervals.icu's API Terms, in force from 31 December 2026, have each developer use its credentials only for its own app (3.3) and bar sharing or transferring them (4.2, 10.2). Send an athlete's workouts from another platform with `activities.import_activities`. The error codes `invalid_provider`, `integration_not_found`, `sync_error`, `status_error` and `disconnect_error` leave the catalog with them.

## 0.9.0

Breaking changes:
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ with Saturday(api_key="sk_test_...") as client:
| `client.partner` | `get`, `usage`, `usage_daily`, `list_api_keys`, `create_api_key`, `revoke_api_key`, `rotate_api_key` |
| `client.webhooks` | `create`, `list`, `get`, `update`, `delete`, `test`, `list_deliveries` |
| `client.organizations` | `create`, `list`, `get`, `update`, `add_member`, `list_members`, `remove_member`, `set_offer`, `get_offer`, `delete_offer`, `create_subscription`, `list_subscriptions`, `update_subscription`, `add_licenses`, `list_licenses`, `remove_license` |
| `client.integrations` | `sync` (intervals.icu), `status`, `disconnect` |
| `client.testing` | `simulate_subscription` (test keys only) |
| `client.meta` | `discovery`, `errors`, `health` |
| `client.knowledge` | `search`, `list_topics`, `get_article` (early access) |
Expand All @@ -216,9 +215,9 @@ Every method returns the API's JSON as plain dictionaries, typed with the TypedD

Every timestamp a partner key receives is an integer of Unix seconds: on athletes, activities, webhooks and their deliveries, API keys, your account, `trial_ends_at`, the fueling profile's `updated_at`, the export's `exported_at` and every time in its records. Coach routes answer in Unix milliseconds.

`athletes.update_settings` replaces the whole settings object: send every setting you want kept. `athletes.delete` removes the athlete and everything stored under them in your account. `athletes.erase` is for a right-to-erasure request: it first revokes, at the provider, each connection you supplied for the athlete with `integrations.sync`, then deletes the athlete, everything stored under them and their link to a Saturday account. A linked athlete's own Saturday account is not changed. A 503 with code `provider_erasure_incomplete` means nothing was deleted yet: call `erase` again.
`athletes.update_settings` replaces the whole settings object: send every setting you want kept. `athletes.delete` removes the athlete and everything stored under them in your account. `athletes.erase` is for a right-to-erasure request: it deletes the athlete, everything stored under them and their link to a Saturday account. A linked athlete's own Saturday account is not changed. A 503 with code `provider_erasure_incomplete` means nothing was deleted yet: call `erase` again.

`integrations.sync("intervals_icu", ...)` fetches the activities of the intervals.icu user an access token belongs to, a token your intervals.icu app obtained, and stores them under your athlete; it is the only provider sync takes. Send TrainingPeaks workouts with `activities.import_activities` once the athlete agrees to share them. `integrations.disconnect` ends the connection you supplied and keeps the activities already synced; for a provider the athlete never connected it raises `NotFoundError` (`integration_not_found`).
To bring in an athlete's workouts from another platform, send them with `activities.import_activities`: Saturday no longer takes a platform's access token from you.

Nutrition and knowledge sit behind [feature gates](https://docs.saturday.fit/guides/feature-gates) that Saturday opens per partner. Until a gate is open for your key, its routes answer `403` with code `feature_alpha` (`PermissionDeniedError`); ask api@saturday.fit to open one.

Expand Down
14 changes: 0 additions & 14 deletions saturday/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@
HealthResponse,
ImportActivityRequest,
ImportPrescriptionItem,
IntegrationDisconnectResponse,
IntegrationProvider,
IntegrationStatusDetail,
IntegrationStatusResponse,
IntegrationSyncResponse,
IntegrationSyncResult,
LegPrescription,
License,
LicenseListResponse,
Expand Down Expand Up @@ -151,7 +145,6 @@
SimulateSubscriptionResponse,
StoredPrescriptionResponse,
SubscriptionCTA,
SyncProvider,
TrialMetadata,
UsagePeriod,
UsageResponse,
Expand Down Expand Up @@ -241,12 +234,6 @@
"HealthResponse",
"ImportActivityRequest",
"ImportPrescriptionItem",
"IntegrationDisconnectResponse",
"IntegrationProvider",
"IntegrationStatusDetail",
"IntegrationStatusResponse",
"IntegrationSyncResponse",
"IntegrationSyncResult",
"License",
"LicenseListResponse",
"LimitingFactor",
Expand Down Expand Up @@ -293,7 +280,6 @@
"SimulateSubscriptionResponse",
"StoredPrescriptionResponse",
"SubscriptionCTA",
"SyncProvider",
"TrialMetadata",
"UsagePeriod",
"UsageResponse",
Expand Down
51 changes: 2 additions & 49 deletions saturday/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
FuelingProfile,
HealthResponse,
ImportActivityRequest,
IntegrationDisconnectResponse,
IntegrationStatusResponse,
IntegrationSyncResponse,
LicenseListResponse,
NutritionCalculateResponse,
OnboardingLink,
Expand Down Expand Up @@ -177,7 +174,6 @@ def __init__(
self.partner = _PartnerResource(self)
self.webhooks = _WebhooksResource(self)
self.organizations = _OrganizationsResource(self)
self.integrations = _IntegrationsResource(self)
self.testing = _TestingResource(self)
self.meta = _MetaResource(self)
self.knowledge = _KnowledgeResource(self)
Expand Down Expand Up @@ -407,10 +403,8 @@ def export(self, athlete_id: str) -> AthleteDataExport:
def erase(self, athlete_id: str) -> None:
"""Erase everything Saturday holds for you about the athlete, for a right-to-erasure request.

Each provider connection you supplied for the athlete with ``integrations.sync`` is revoked
at the provider first; then the athlete and everything stored under them are deleted
(activities, those synced through your connections included, prescriptions, feedback,
consent records, usage logs) with the athlete's link to a Saturday account. A linked
The athlete and everything stored under them are deleted (activities, prescriptions,
feedback, consent records, usage logs) with the athlete's link to a Saturday account. A linked
athlete's own Saturday account is not changed. A ``SaturdayError`` with status 503 and code
``provider_erasure_incomplete`` means a connection could not be revoked yet and nothing was
deleted: call ``erase`` again.
Expand Down Expand Up @@ -707,47 +701,6 @@ def remove_license(self, org_id: str, sub_id: str, athlete_id: str) -> None:
)


class _IntegrationsResource:
def __init__(self, client: Saturday):
self._client = client

def sync(
self,
provider: str,
*,
athlete_id: str,
access_token: str,
date_range: Optional[Dict[str, str]] = None,
sync_types: Optional[List[str]] = None,
) -> IntegrationSyncResponse:
"""Fetch the activities of the intervals.icu user an access token belongs to and store each
as an activity of your athlete.

``provider`` is ``"intervals_icu"``, the only one: Strava and TrainingPeaks tokens raise
``ValidationError`` (``invalid_provider``). Send an OAuth access token your intervals.icu app
obtained from that user; the calls count against your app's intervals.icu limit.
``date_range`` is ``{"start": "YYYY-MM-DD", "end": "YYYY-MM-DD"}``, both or neither; without
it, the last 7 days. ``sync_types`` defaults to ``["activities"]``. The result is under
``result``.
"""
body: Dict[str, Any] = {"athlete_id": athlete_id, "access_token": access_token, "sync_types": sync_types or ["activities"]}
if date_range is not None:
body["date_range"] = date_range
return self._client.request("POST", f"/v1/integrations/{_seg(provider)}/sync", json=body)

def status(self, provider: str, athlete_id: str) -> IntegrationStatusResponse:
"""``provider``: ``intervals_icu``, ``strava`` or ``training_peaks``."""
return self._client.request("GET", f"/v1/integrations/{_seg(provider)}/status", params={"athlete_id": athlete_id})

def disconnect(self, provider: str, athlete_id: str) -> IntegrationDisconnectResponse:
"""End the connection you supplied for the athlete with ``sync``: it is revoked at the
provider and its tokens are removed. Activities already synced stay. A linked athlete's own
connection to the provider in their Saturday account is not changed. A provider the athlete
never connected raises ``NotFoundError`` (code ``integration_not_found``), and nothing
reaches the provider."""
return self._client.request("POST", f"/v1/integrations/{_seg(provider)}/disconnect", json={"athlete_id": athlete_id})


class _TestingResource:
"""Test environment only (``sk_test_`` keys). In production these routes answer 404."""

Expand Down
55 changes: 1 addition & 54 deletions saturday/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,60 +1519,7 @@ class AthleteDataExport(_AthleteDataExportRequired, total=False):
consent: List[Dict[str, Any]]


# --- Integrations and the test project ---


IntegrationProvider = Literal["intervals_icu", "strava", "training_peaks"]
"""The providers ``integrations.status`` and ``integrations.disconnect`` take."""

SyncProvider = Literal["intervals_icu"]
"""The provider ``integrations.sync`` takes. Strava and TrainingPeaks tokens are refused with a
``ValidationError`` (``invalid_provider``)."""


class _IntegrationStatusDetailRequired(TypedDict):
provider: IntegrationProvider
connected: bool
sync_count: int


class IntegrationStatusDetail(_IntegrationStatusDetailRequired, total=False):
last_sync_at: int # Unix seconds.
errors: List[str]


class IntegrationStatusResponse(TypedDict):
status: IntegrationStatusDetail
request_id: str


class _IntegrationSyncResultRequired(TypedDict):
provider: SyncProvider
# partial when some activities could not be stored, failed when none could or intervals.icu
# refused the token; errors says why.
status: Literal["completed", "partial", "failed"]
activities_found: int
activities_synced: int
activities_skipped: int # Found but not stored: the activity's type names no sport the API supports.


class IntegrationSyncResult(_IntegrationSyncResultRequired, total=False):
# Whether the athlete's prescriptions for these activities are exact (full) or ranges (teaser).
prescription_tier: Literal["full", "teaser"]
errors: List[str]


class IntegrationSyncResponse(TypedDict):
result: IntegrationSyncResult
request_id: str


class IntegrationDisconnectResponse(TypedDict):
"""The connection you supplied is ended."""

message: str # For example "Successfully disconnected intervals_icu".
provider: IntegrationProvider
request_id: str
# --- The test project ---


class SimulateSubscriptionResponse(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion tests/LIVE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ python -m pytest tests/test_live.py
- One run makes about 130 calls, of which about 45 are calculations, prep, product fit and compare, and creates 4 athletes (one of them with a simulated subscription, for the brick and triathlon block), 4 activities, an organization, an API key and a webhook pointed at `https://example.com`. The webhook receives two deliveries, a `webhook.test` and a `prescription.calculated`; example.com answers 405, and the suite reads each event body from its delivery record. It erases the athletes, with their activities, and deletes the key and webhook it created; the organization stays.
- The catalog products it sizes are Maurten Gel 100 and Tailwind Endurance Fuel.
- `athletes.erase` and `testing.simulate_subscription` need the test environment. The run marks 2 athletes with `testing.simulate_subscription`, inside the 10 a key may mark per UTC day.
- It also checks what the API refuses: a second athlete with a taken `external_id` (create, batch item and update), a Strava or TrainingPeaks token on `integrations.sync`, prep with both `products=` and `legs=`, and the stored prescription after an update that changes the session.
- It also checks what the API refuses: a second athlete with a taken `external_id` (create, batch item and update) prep with both `products=` and `legs=`, and the stored prescription after an update that changes the session.

Set `SATURDAY_LIVE_CAPTURE=tests/fixtures/live.json` to record every response. Keys, secrets, signed links and account details are replaced with placeholders before they are written. `tests/test_live_types.py`, part of the normal test run, checks every recorded response against the TypedDict its method returns: every required key, no undeclared key, every value of its declared type, so a field the API adds, drops or renames fails the suite until the types match.
11 changes: 0 additions & 11 deletions tests/fixtures/live.json
Original file line number Diff line number Diff line change
Expand Up @@ -2815,17 +2815,6 @@
]
}
},
"integration_status": {
"type": "IntegrationStatusResponse",
"body": {
"request_id": "req_188ac58bbdd9",
"status": {
"provider": "intervals_icu",
"connected": false,
"sync_count": 0
}
}
},
"calculate_brick": {
"type": "NutritionCalculateResponse",
"body": {
Expand Down
19 changes: 2 additions & 17 deletions tests/test_api_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
"licenses": [{"email": "sam@example.com", "added_at": 1700000000, "active": True, "athlete_id": "ath_1", "name": "Sam"}],
"total": 1, "request_id": "req_lic",
}
# CONSTRUCTED from IntegrationSyncResponse in saturday/types.py.
SYNCED = {
"result": {"provider": "intervals_icu", "status": "completed", "activities_found": 2,
"activities_synced": 2, "activities_skipped": 0, "prescription_tier": "full"},
"request_id": "req_sync",
}
# CONSTRUCTED from IntegrationDisconnectResponse (its docstring gives the message).
DISCONNECTED = {"message": "Successfully disconnected intervals_icu", "provider": "intervals_icu", "request_id": "req_disc"}
# CONSTRUCTED: nutrition.extract, infer.* and knowledge.* return Dict and no
# response shape for them exists in this repository's docs, types or fixtures.
EXTRACTED = {"product_name": "Example Gel", "per_serving": {"carb_g": 25.0, "sodium_mg": 50.0, "fluid_ml": 0.0}}
Expand Down Expand Up @@ -249,14 +241,7 @@
"GET", "/v1/organizations/org_1/subscriptions/sub_1/licenses", {}, None, 200, LICENSES, "LicenseListResponse"),
("organizations-remove-license", lambda c: c.organizations.remove_license("org_1", "sub_1", "ath_1"),
"DELETE", "/v1/organizations/org_1/subscriptions/sub_1/licenses/ath_1", {}, None, 204, None, None),
# integrations, testing, meta, knowledge
("integrations-sync", lambda c: c.integrations.sync("intervals_icu", athlete_id="ath_1", access_token="tok"),
"POST", "/v1/integrations/intervals_icu/sync", {}, {"athlete_id": "ath_1", "access_token": "tok", "sync_types": ["activities"]},
200, SYNCED, "IntegrationSyncResponse"),
("integrations-status", lambda c: c.integrations.status("intervals_icu", "ath_1"),
"GET", "/v1/integrations/intervals_icu/status", {"athlete_id": "ath_1"}, None, 200, LIVE["integration_status"], "IntegrationStatusResponse"),
("integrations-disconnect", lambda c: c.integrations.disconnect("intervals_icu", "ath_1"),
"POST", "/v1/integrations/intervals_icu/disconnect", {}, {"athlete_id": "ath_1"}, 200, DISCONNECTED, "IntegrationDisconnectResponse"),
# testing, meta, knowledge
("testing-simulate-subscription", lambda c: c.testing.simulate_subscription("ath_1"),
"POST", "/v1/test/athletes/ath_1/simulate-subscription", {}, {"active": True}, 200, LIVE["simulate_subscription"], "SimulateSubscriptionResponse"),
("meta-discovery", lambda c: c.meta.discovery(),
Expand Down Expand Up @@ -385,7 +370,7 @@ def test_case_table_covers_every_resource_method():
"nutrition": client.nutrition, "athletes": client.athletes, "activities": client.activities,
"onboarding": client.onboarding, "reference": client.reference, "infer": client.infer,
"partner": client.partner, "webhooks": client.webhooks, "organizations": client.organizations,
"integrations": client.integrations, "testing": client.testing, "meta": client.meta,
"testing": client.testing, "meta": client.meta,
"knowledge": client.knowledge, "coach": client.coach,
}
# coach.report_pdf returns bytes: its case is the separate test below.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bugfixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_retry_after_is_kept_on_typed_errors(status, klass):
lambda c: c.activities.get("ath_1", ""),
lambda c: c.knowledge.get_article(""),
lambda c: c.coach.delete_webhook(""),
lambda c: c.integrations.status("", "ath_1"),
lambda c: c.organizations.get(""),
])
def test_empty_path_segment_is_rejected_before_any_request(call):
"""Bug: _seg rejected "." and ".." for reaching another route but encoded
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_readme_resource_table_lists_every_method():
client = Saturday(api_key="sk_test_fake")
try:
for name in ("nutrition", "athletes", "activities", "onboarding", "reference", "infer", "partner",
"webhooks", "organizations", "integrations", "testing", "meta", "knowledge"):
"webhooks", "organizations", "testing", "meta", "knowledge"):
actual = {m for m, _ in inspect.getmembers(getattr(client, name), predicate=inspect.ismethod)
if not m.startswith("_")}
assert rows[name] == actual, f"README row for {name}: table {sorted(rows[name])} != client {sorted(actual)}"
Expand Down
6 changes: 1 addition & 5 deletions tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ def test_shared_profile_carries_every_answer_and_unshared_carries_none():
"POST", "/v1/infer/activity-type", {"activity_name": "Morning Ride", "tags": ["bike"]}),
(lambda c: c.infer.brick_types(activity_name="Brick session"),
"POST", "/v1/infer/brick-types", {"activity_name": "Brick session"}),
(lambda c: c.integrations.disconnect("intervals_icu", "ath_1"),
"POST", "/v1/integrations/intervals_icu/disconnect", {"athlete_id": "ath_1"}),
(lambda c: c.organizations.update_subscription("org_1", "sub_1", seats=10),
"PATCH", "/v1/organizations/org_1/subscriptions/sub_1", {"seats": 10}),
(lambda c: c.organizations.add_licenses("org_1", "sub_1", [{"athlete_id": "ath_1"}]),
Expand Down Expand Up @@ -358,8 +356,6 @@ def send(request):
"POST", "/v1/organizations/org_1/subscriptions", {},
{"type": "team", "seats": 10, "start_date": 1700000000, "end_date": 1730000000}),
(lambda c: c.organizations.list_subscriptions("org_1"), "GET", "/v1/organizations/org_1/subscriptions", {}, None),
(lambda c: c.integrations.status("intervals_icu", "ath_1"),
"GET", "/v1/integrations/intervals_icu/status", {"athlete_id": "ath_1"}, None),
(lambda c: c.testing.simulate_subscription("ath_1"),
"POST", "/v1/test/athletes/ath_1/simulate-subscription", {}, {"active": True}),
(lambda c: c.testing.simulate_subscription("ath_1", active=False),
Expand All @@ -375,7 +371,7 @@ def send(request):
"webhook-update-full", "webhook-update-partial", "webhook-delete", "webhook-test",
"org-create-full", "org-create-minimal", "org-add-member-full", "org-add-member-default",
"org-list-members", "org-remove-member", "org-set-offer", "org-delete-offer",
"org-create-subscription", "org-list-subscriptions", "integration-status",
"org-create-subscription", "org-list-subscriptions",
"simulate-on", "simulate-off", "discovery", "error-catalog", "health",
"knowledge-full", "knowledge-plain",
])
Expand Down
Loading