{"id":19077973,"url":"https://github.com/rfoel/strava","last_synced_at":"2025-04-30T04:40:10.229Z","repository":{"id":36960202,"uuid":"314059635","full_name":"rfoel/strava","owner":"rfoel","description":"JavaScript wrapper for the Strava JSON API","archived":false,"fork":false,"pushed_at":"2024-03-15T14:17:58.000Z","size":1575,"stargazers_count":26,"open_issues_count":12,"forks_count":11,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-13T06:03:15.458Z","etag":null,"topics":["api","json","node","strava"],"latest_commit_sha":null,"homepage":"","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/rfoel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-11-18T21:13:48.000Z","updated_at":"2025-04-03T14:35:40.000Z","dependencies_parsed_at":"2024-10-03T12:17:43.574Z","dependency_job_id":"3f7ed126-c320-4c40-82ee-f7a947348334","html_url":"https://github.com/rfoel/strava","commit_stats":{"total_commits":89,"total_committers":14,"mean_commits":6.357142857142857,"dds":0.6404494382022472,"last_synced_commit":"7e0bb09a49168b1fc182ec52f6d7c6d345c5136e"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfoel%2Fstrava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfoel%2Fstrava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfoel%2Fstrava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfoel%2Fstrava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rfoel","download_url":"https://codeload.github.com/rfoel/strava/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250559532,"owners_count":21450167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["api","json","node","strava"],"created_at":"2024-11-09T02:04:30.091Z","updated_at":"2025-04-30T04:40:10.208Z","avatar_url":"https://github.com/rfoel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strava\n\n[![npm](https://img.shields.io/npm/v/strava)](https://www.npmjs.com/strava)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/strava)](https://www.npmjs.com/strava)\n[![NPM](https://img.shields.io/npm/l/strava)](LICENSE)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nThis library is a fully typed JavaScript wrapper of the [Strava JSON API](https://developers.strava.com/docs/reference/).\n\n## Installation\n\nTo install the package, run:\n\n```\nnpm install strava\n```\n\nor\n\n```\nyarn add strava\n```\n\n## Usage\n\nThe library can be initialized with a refresh token and optionally an access token.\nIf these are not available, see below (**Token exchange**).\n\n```javascript\nimport { Strava } from 'strava'\n\nconst strava = new Strava({\n  client_id: '123',\n  client_secret: 'abc',\n  refresh_token: 'def',\n})\n\ntry {\n  const activities = await strava.activities.getLoggedInAthleteActivities()\n  console.log(activities)\n} catch (error) {\n  console.log(error)\n}\n```\n\n### Refreshing the access token\n\nThis library will automatically refresh the access token when needed.\nIn order to store the token, you can use the `on_token_refresh` callback.\nThis received an `AccessToken` object (consisting of `access_token`, `expires_at`, and `refresh_token`).\nNote that the refresh token as returned by this call can sometimes change,\nat which point the old token becomes invalid.\n\nAn `AccessToken` object can also be passed as a second argument to the Strava constructor.\nThis can save an initial token refresh.\nAs `AccessToken` contains a refresh token,\nthe first argument does not need to contain a refresh token.\n\n```javascript\nimport { Strava } from 'strava'\n\nconst strava = new Strava(\n  {\n    client_id: '123',\n    client_secret: 'abc',\n\n    on_token_refresh: response =\u003e {\n      cache.accessToken = response\n    },\n  },\n  cache.accessToken,\n)\n```\n\n### Token exchange\n\nWhen a user logs in for the first time, you will need to perform authorization with OAuth.\nThis involves sending the user to \u003chttps://www.strava.com/oauth/authorize\u003e,\nand receiving the auth code as a query parameter.\n\nThis can be used as follows:\n\n```javascript\nimport { Strava } from 'strava'\n\ntry {\n  const strava = await Strava.createFromTokenExchange(\n    {\n      client_id: '123',\n      client_secret: 'abc',\n    },\n    token,\n  )\n\n  const activities = await strava.activities.getLoggedInAthleteActivities()\n  console.log(activities)\n} catch (error) {\n  console.log(error)\n}\n```\n\n### Getting athlete info\n\nWhen a user logs in for the first time, the Strava API returns information about the newly logged-in user.\nThis can be read using the on_token_refresh callback.\nNote that this will only ever be provided on the initial token exchange,\nbefore the promise returned from `Strava.createFromTokenExchange` returns.\nWhen the `on_token_refresh` callback is called again after the token expires,\n`response.athlete` will always be undefined.\n\n```javascript\nimport { Strava } from 'strava'\n\ntry {\n  const strava = await Strava.createFromTokenExchange(\n    {\n      client_id: '123',\n      client_secret: 'abc',\n      on_token_refresh: response =\u003e {\n        if (response.athlete) {\n          console.log(response.athlete)\n        }\n\n        db.set('refresh_token', response.refresh_token)\n      },\n    },\n    token,\n  )\n\n  const activities = await strava.activities.getLoggedInAthleteActivities()\n  console.log(activities)\n} catch (error) {\n  console.log(error)\n}\n```\n\n## Contributing\n\nIssues and pull requests are welcome.\n\n## License\n\n[MIT](https://github.com/rfoel/strava/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfoel%2Fstrava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frfoel%2Fstrava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfoel%2Fstrava/lists"}