incyclist-services 1.7.109 → 1.7.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ const gd_eventlog_1 = require("gd-eventlog");
9
9
  const sleep_1 = require("../../../../utils/sleep");
10
10
  const API_BASE_URL = 'https://www.strava.com/api/v3';
11
11
  const OAUTH_URL = 'https://www.strava.com/oauth';
12
+ const AUTH_SERVER_URL = 'https://auth.incyclist.com';
12
13
  class StravaApi extends base_1.AppApiBase {
13
14
  config;
14
15
  logger;
@@ -158,16 +159,14 @@ class StravaApi extends base_1.AppApiBase {
158
159
  async refreshToken() {
159
160
  this.logger.logEvent({ message: 'Strava refresh Token start' });
160
161
  let requestData;
162
+ const url = this.getAuthServerUrl() + '/strava/refresh';
161
163
  try {
162
164
  requestData = {
163
- grant_type: 'refresh_token',
164
- refresh_token: this.config.refreshToken,
165
- client_secret: this.config.clientSecret,
166
- client_id: this.config.clientId
165
+ refresh_token: this.config.refreshToken
167
166
  };
168
167
  const response = await this.getApi().request({
169
168
  method: 'post',
170
- url: this.getOauthBaseUrl() + '/token',
169
+ url,
171
170
  data: requestData
172
171
  });
173
172
  this.logger.logEvent({ message: 'Strava refresh Token result', status: 'success' });
@@ -182,7 +181,7 @@ class StravaApi extends base_1.AppApiBase {
182
181
  let errorStr = err.message;
183
182
  if (err.response) {
184
183
  const { response } = err;
185
- errorStr = `HTTP error ${response.status}: ${response.statusText}, url:${this.getOauthBaseUrl() + '/token'}, data:${JSON.stringify(requestData)}`;
184
+ errorStr = `HTTP error ${response.status}: ${response.statusText}, url:${url}, data:${JSON.stringify(requestData)}`;
186
185
  }
187
186
  this.logger.logEvent({ message: 'Strava refresh Token result', status: 'error', error: errorStr });
188
187
  }
@@ -209,6 +208,14 @@ class StravaApi extends base_1.AppApiBase {
209
208
  return OAUTH_URL;
210
209
  }
211
210
  }
211
+ getAuthServerUrl() {
212
+ try {
213
+ return this.getUserSettings().get('STRAVA_AUTH_SERVER_URL', AUTH_SERVER_URL);
214
+ }
215
+ catch {
216
+ return AUTH_SERVER_URL;
217
+ }
218
+ }
212
219
  getBaseUrl() {
213
220
  try {
214
221
  return this.getUserSettings().get('STRAVA_API', API_BASE_URL);
@@ -123,9 +123,7 @@ let StravaAppConnection = (() => {
123
123
  let isInitialized;
124
124
  try {
125
125
  const auth = this.getCredentials();
126
- const clientId = this.getSecret('STRAVA_CLIENT_ID');
127
- const clientSecret = this.getSecret('STRAVA_CLIENT_SECRET');
128
- if (clientId && clientSecret && auth) {
126
+ if (auth) {
129
127
  this.logEvent({ message: 'Strava init done', hasCredentials: true });
130
128
  this.config = this.buildConfigFromCredentials(auth);
131
129
  this.initApi(this.config);
@@ -6,6 +6,7 @@ import { EventLogger } from 'gd-eventlog';
6
6
  import { sleep } from "../../../../utils/sleep";
7
7
  const API_BASE_URL = 'https://www.strava.com/api/v3';
8
8
  const OAUTH_URL = 'https://www.strava.com/oauth';
9
+ const AUTH_SERVER_URL = 'https://auth.incyclist.com';
9
10
  export class StravaApi extends AppApiBase {
10
11
  config;
11
12
  logger;
@@ -155,16 +156,14 @@ export class StravaApi extends AppApiBase {
155
156
  async refreshToken() {
156
157
  this.logger.logEvent({ message: 'Strava refresh Token start' });
157
158
  let requestData;
159
+ const url = this.getAuthServerUrl() + '/strava/refresh';
158
160
  try {
159
161
  requestData = {
160
- grant_type: 'refresh_token',
161
- refresh_token: this.config.refreshToken,
162
- client_secret: this.config.clientSecret,
163
- client_id: this.config.clientId
162
+ refresh_token: this.config.refreshToken
164
163
  };
165
164
  const response = await this.getApi().request({
166
165
  method: 'post',
167
- url: this.getOauthBaseUrl() + '/token',
166
+ url,
168
167
  data: requestData
169
168
  });
170
169
  this.logger.logEvent({ message: 'Strava refresh Token result', status: 'success' });
@@ -179,7 +178,7 @@ export class StravaApi extends AppApiBase {
179
178
  let errorStr = err.message;
180
179
  if (err.response) {
181
180
  const { response } = err;
182
- errorStr = `HTTP error ${response.status}: ${response.statusText}, url:${this.getOauthBaseUrl() + '/token'}, data:${JSON.stringify(requestData)}`;
181
+ errorStr = `HTTP error ${response.status}: ${response.statusText}, url:${url}, data:${JSON.stringify(requestData)}`;
183
182
  }
184
183
  this.logger.logEvent({ message: 'Strava refresh Token result', status: 'error', error: errorStr });
185
184
  }
@@ -206,6 +205,14 @@ export class StravaApi extends AppApiBase {
206
205
  return OAUTH_URL;
207
206
  }
208
207
  }
208
+ getAuthServerUrl() {
209
+ try {
210
+ return this.getUserSettings().get('STRAVA_AUTH_SERVER_URL', AUTH_SERVER_URL);
211
+ }
212
+ catch {
213
+ return AUTH_SERVER_URL;
214
+ }
215
+ }
209
216
  getBaseUrl() {
210
217
  try {
211
218
  return this.getUserSettings().get('STRAVA_API', API_BASE_URL);
@@ -120,9 +120,7 @@ let StravaAppConnection = (() => {
120
120
  let isInitialized;
121
121
  try {
122
122
  const auth = this.getCredentials();
123
- const clientId = this.getSecret('STRAVA_CLIENT_ID');
124
- const clientSecret = this.getSecret('STRAVA_CLIENT_SECRET');
125
- if (clientId && clientSecret && auth) {
123
+ if (auth) {
126
124
  this.logEvent({ message: 'Strava init done', hasCredentials: true });
127
125
  this.config = this.buildConfigFromCredentials(auth);
128
126
  this.initApi(this.config);
@@ -36,5 +36,6 @@ export declare class StravaApi extends AppApiBase {
36
36
  protected refreshToken(): Promise<void>;
37
37
  protected get(url: string, config?: object): Promise<AxiosResponse>;
38
38
  protected getOauthBaseUrl(): any;
39
+ protected getAuthServerUrl(): any;
39
40
  protected getBaseUrl(): any;
40
41
  }
@@ -6,9 +6,6 @@ export type StravaConfig = {
6
6
  expiration?: Date;
7
7
  };
8
8
  export type StravaRefreshTokenRequest = {
9
- clientId: string;
10
- clientSecret: string;
11
- grant_type: string;
12
9
  refresh_token: string;
13
10
  };
14
11
  export type StravaRefreshTokenResponse = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.109",
3
+ "version": "1.7.110",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },