incyclist-services 1.9.7 → 1.9.9

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.
Files changed (58) hide show
  1. package/lib/cjs/activities/active-rides/service.js +90 -13
  2. package/lib/cjs/api/rest/api.js +7 -3
  3. package/lib/cjs/api/rest/external.js +26 -0
  4. package/lib/cjs/apps/googleMaps/service.js +2 -0
  5. package/lib/cjs/apps/service.js +4 -1
  6. package/lib/cjs/devices/pairing/service.js +0 -1
  7. package/lib/cjs/i18n/countries/service.js +2 -2
  8. package/lib/cjs/routes/base/api/api.js +196 -0
  9. package/lib/cjs/routes/base/api/factory.js +93 -0
  10. package/lib/cjs/routes/base/api/index.js +14 -184
  11. package/lib/cjs/routes/base/parsers/tacx/TacxParser.js +1 -1
  12. package/lib/cjs/routes/free-ride/service.js +41 -0
  13. package/lib/cjs/routes/list/loaders/DBLoader.js +0 -1
  14. package/lib/cjs/routes/list/loaders/api.js +270 -176
  15. package/lib/cjs/routes/list/service.js +401 -357
  16. package/lib/cjs/ui/service.js +2 -2
  17. package/lib/cjs/utils/string.js +21 -1
  18. package/lib/esm/activities/active-rides/service.js +90 -13
  19. package/lib/esm/api/rest/api.js +7 -3
  20. package/lib/esm/api/rest/external.js +22 -0
  21. package/lib/esm/api/rest/incyclist copy.js +33 -0
  22. package/lib/esm/apps/googleMaps/service.js +2 -0
  23. package/lib/esm/apps/service.js +4 -1
  24. package/lib/esm/devices/configuration/model/add/index.js +1 -0
  25. package/lib/esm/devices/configuration/model/exclusion/index.js +1 -0
  26. package/lib/esm/devices/pairing/capability.js +1 -0
  27. package/lib/esm/devices/pairing/service.js +0 -1
  28. package/lib/esm/i18n/countries/service.js +2 -2
  29. package/lib/esm/routes/base/api/api.js +194 -0
  30. package/lib/esm/routes/base/api/factory.js +86 -0
  31. package/lib/esm/routes/base/api/index.js +2 -186
  32. package/lib/esm/routes/base/parsers/tacx/TacxParser.js +1 -1
  33. package/lib/esm/routes/free-ride/service.js +41 -0
  34. package/lib/esm/routes/list/loaders/DBLoader.js +0 -1
  35. package/lib/esm/routes/list/loaders/api.js +272 -174
  36. package/lib/esm/routes/list/service.js +401 -357
  37. package/lib/esm/ui/service.js +2 -2
  38. package/lib/esm/utils/string.js +18 -0
  39. package/lib/types/activities/active-rides/service.d.ts +9 -0
  40. package/lib/types/api/rest/api.d.ts +2 -2
  41. package/lib/types/api/rest/external.d.ts +7 -0
  42. package/lib/types/api/rest/incyclist copy.d.ts +7 -0
  43. package/lib/types/api/rest/types.d.ts +5 -3
  44. package/lib/types/apps/service.d.ts +1 -0
  45. package/lib/types/devices/configuration/model/add/index.d.ts +10 -0
  46. package/lib/types/devices/configuration/model/exclusion/index.d.ts +19 -0
  47. package/lib/types/devices/pairing/capability.d.ts +10 -0
  48. package/lib/types/routes/base/api/api.d.ts +23 -0
  49. package/lib/types/routes/base/api/factory.d.ts +7 -0
  50. package/lib/types/routes/base/api/index.d.ts +2 -26
  51. package/lib/types/routes/base/api/types.d.ts +10 -0
  52. package/lib/types/routes/base/parsers/tacx/TacxParser.d.ts +1 -1
  53. package/lib/types/routes/base/types/index.d.ts +1 -0
  54. package/lib/types/routes/free-ride/service.d.ts +6 -0
  55. package/lib/types/routes/list/loaders/api.d.ts +6 -3
  56. package/lib/types/routes/list/service.d.ts +37 -29
  57. package/lib/types/utils/string.d.ts +2 -0
  58. package/package.json +1 -1
@@ -99,6 +99,8 @@ let ActiveRidesService = (() => {
99
99
  isStarted = false;
100
100
  routeListObserver;
101
101
  routesStats = [];
102
+ routeListSessions = new Map();
103
+ isSubscribedRouteListEvents = false;
102
104
  activityEventHandlers = {
103
105
  update: this.onActivityUpdateEvent.bind(this),
104
106
  start: this.onActivityStartEvent.bind(this),
@@ -111,6 +113,7 @@ let ActiveRidesService = (() => {
111
113
  routeList.on('opened', this.onRoutePageOpened.bind(this));
112
114
  routeList.on('closed', () => {
113
115
  delete this.routeListObserver;
116
+ this.unsubscribeRouteListEvents();
114
117
  });
115
118
  }
116
119
  init(session, maxLength = 10) {
@@ -182,7 +185,10 @@ let ActiveRidesService = (() => {
182
185
  }
183
186
  async onRoutePageOpened(observer) {
184
187
  this.routeListObserver = observer;
185
- await this.getActiveRideCounts();
188
+ if (!this.isSubscribedRouteListEvents) {
189
+ await this.getActiveRideCounts();
190
+ this.subscribeRouteListEvents();
191
+ }
186
192
  this.routeListObserver.emit('stats-update', this.routesStats);
187
193
  }
188
194
  async getActiveRideCounts() {
@@ -191,19 +197,17 @@ let ActiveRidesService = (() => {
191
197
  if (!isOnline)
192
198
  return;
193
199
  const activeRides = (await this.getApi().getAll()).filter(ar => ar.ride !== undefined && ar.ride !== null);
194
- const routes = this.getRouteList().getAllRoutes();
195
- const counts = [];
196
- routes.forEach(route => {
197
- const routeRides = activeRides.filter(ar => ar.ride?.routeHash && ar.ride?.routeHash === route.description?.routeHash) ?? [];
198
- const count = routeRides.length;
199
- counts.push({
200
- count,
201
- routeId: route.description.id,
202
- routeHash: route.description.routeHash
203
- });
200
+ this.routeListSessions = new Map();
201
+ activeRides.forEach(ar => {
202
+ const hash = ar.ride?.routeHash;
203
+ if (!hash)
204
+ return;
205
+ if (!this.routeListSessions.has(hash))
206
+ this.routeListSessions.set(hash, new Set());
207
+ this.routeListSessions.get(hash).add(ar.sessionId ?? ar.id);
204
208
  });
205
- this.routesStats = counts;
206
- return counts;
209
+ this.routesStats = this.buildRouteListStats();
210
+ return this.routesStats;
207
211
  }
208
212
  catch (err) {
209
213
  const isOnline = this.getOnlineStatusMonitoring().onlineStatus;
@@ -212,6 +216,73 @@ let ActiveRidesService = (() => {
212
216
  }
213
217
  return [];
214
218
  }
219
+ buildRouteListStats() {
220
+ const routes = this.getRouteList().getAllRoutes();
221
+ return routes.map(route => ({
222
+ count: this.routeListSessions.get(route.description.routeHash)?.size ?? 0,
223
+ routeId: route.description.id,
224
+ routeHash: route.description.routeHash
225
+ }));
226
+ }
227
+ subscribeRouteListEvents() {
228
+ if (this.isSubscribedRouteListEvents)
229
+ return;
230
+ this.getMessageQueue()?.subscribe('incyclist/activity/+/+/+', this.onRouteListActivityEvent.bind(this), 'incyclist/activity');
231
+ this.isSubscribedRouteListEvents = true;
232
+ }
233
+ unsubscribeRouteListEvents() {
234
+ if (!this.isSubscribedRouteListEvents)
235
+ return;
236
+ this.getMessageQueue()?.unsubscribe('incyclist/activity/+/+/+');
237
+ this.isSubscribedRouteListEvents = false;
238
+ }
239
+ onRouteListActivityEvent(topic) {
240
+ const keys = topic.split('/');
241
+ const session = keys[2];
242
+ const routeHash = keys[3];
243
+ const event = keys[4];
244
+ if (!routeHash || !session)
245
+ return;
246
+ if (event === 'start')
247
+ this.addRouteListSession(routeHash, session);
248
+ else if (event === 'stop')
249
+ this.removeRouteListSession(routeHash, session);
250
+ }
251
+ addRouteListSession(routeHash, session) {
252
+ if (!this.routeListSessions.has(routeHash))
253
+ this.routeListSessions.set(routeHash, new Set());
254
+ const sessions = this.routeListSessions.get(routeHash);
255
+ if (sessions.has(session))
256
+ return;
257
+ sessions.add(session);
258
+ this.emitRouteListStatUpdate(routeHash);
259
+ }
260
+ removeRouteListSession(routeHash, session) {
261
+ const sessions = this.routeListSessions.get(routeHash);
262
+ if (!sessions?.has(session))
263
+ return;
264
+ sessions.delete(session);
265
+ this.emitRouteListStatUpdate(routeHash);
266
+ }
267
+ emitRouteListStatUpdate(routeHash) {
268
+ const route = this.getRouteList().getAllRoutes().find(r => r.description.routeHash === routeHash);
269
+ if (!route)
270
+ return;
271
+ const stat = {
272
+ count: this.routeListSessions.get(routeHash)?.size ?? 0,
273
+ routeId: route.description.id,
274
+ routeHash
275
+ };
276
+ const idx = this.routesStats?.findIndex(s => s.routeHash === routeHash) ?? -1;
277
+ if (idx >= 0) {
278
+ this.routesStats[idx] = stat;
279
+ }
280
+ else {
281
+ this.routesStats ??= [];
282
+ this.routesStats.push(stat);
283
+ }
284
+ this.routeListObserver?.emit('stats-update', [stat]);
285
+ }
215
286
  start(session) {
216
287
  if (this.onlineStatusHandler || this.isOnline) {
217
288
  this.initList().catch(err => { this.logError(err, 'start'); });
@@ -600,6 +671,7 @@ let ActiveRidesService = (() => {
600
671
  onDisconnect() {
601
672
  this.getMessageQueue().onDisconnect();
602
673
  this.isSubscribed = false;
674
+ this.isSubscribedRouteListEvents = false;
603
675
  }
604
676
  async onConnect(props) {
605
677
  const { initial = false } = props ?? {};
@@ -607,6 +679,8 @@ let ActiveRidesService = (() => {
607
679
  this.getMessageQueue().onConnect();
608
680
  if (!initial && this.current && !this.isSubscribed)
609
681
  this.subscribeActivityEvents().catch(err => { this.logError(err, 'onConnect'); });
682
+ if (!initial && this.routeListObserver && !this.isSubscribedRouteListEvents)
683
+ this.subscribeRouteListEvents();
610
684
  }
611
685
  async subscribeActivityEvents() {
612
686
  const hash = this.current?.ride.routeHash;
@@ -625,8 +699,11 @@ let ActiveRidesService = (() => {
625
699
  onActivityEvent(topic, payload) {
626
700
  const keys = topic.split('/');
627
701
  const session = keys[2];
702
+ const routeHash = keys[3];
628
703
  if (session === this.current.sessionId)
629
704
  return;
705
+ if (routeHash !== this.current?.ride?.routeHash)
706
+ return;
630
707
  const event = keys[4];
631
708
  const handler = this.activityEventHandlers[event];
632
709
  if (handler)
@@ -12,10 +12,8 @@ class ApiClient {
12
12
  logger;
13
13
  requests;
14
14
  init(props) {
15
- const { uuid, apiKey, requestLog = true, version, appVersion, channel = 'desktop', platform } = props;
15
+ const { requestLog = true, version, appVersion, channel = 'desktop', platform } = props;
16
16
  const headers = {
17
- "X-uuid": uuid,
18
- "X-API-Key": apiKey,
19
17
  "x-app-channel": channel,
20
18
  "x-app-version": appVersion,
21
19
  "x-react-version": version
@@ -23,6 +21,12 @@ class ApiClient {
23
21
  if (platform) {
24
22
  headers['x-app-platform'] = platform;
25
23
  }
24
+ if (props['uuid']) {
25
+ headers['X-uuid'] = props['uuid'];
26
+ }
27
+ if (props['apiKey']) {
28
+ headers['X-API-Key'] = props['apiKey'];
29
+ }
26
30
  this.axios = axios_1.default.create({ headers });
27
31
  if (requestLog) {
28
32
  this.logger = new gd_eventlog_1.EventLogger('API');
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IncyclistExternalRestApiClient = void 0;
4
+ const bindings_1 = require("../bindings");
5
+ const api_1 = require("./api");
6
+ class IncyclistExternalRestApiClient {
7
+ static _api;
8
+ static getClient(requestLog) {
9
+ const appInfo = (0, bindings_1.getBindings)().appInfo;
10
+ const props = {
11
+ channel: appInfo?.getChannel(),
12
+ appVersion: appInfo?.getAppVersion(),
13
+ version: appInfo?.getUIVersion(),
14
+ platform: appInfo?.getOS()?.platform,
15
+ requestLog: requestLog ?? true
16
+ };
17
+ this.api().init(props);
18
+ return this.api().client();
19
+ }
20
+ static api() {
21
+ if (!this._api)
22
+ this._api = new api_1.ApiClient();
23
+ return this._api;
24
+ }
25
+ }
26
+ exports.IncyclistExternalRestApiClient = IncyclistExternalRestApiClient;
@@ -66,6 +66,8 @@ let GoogleMapsService = (() => {
66
66
  api = __runInitializers(this, _instanceExtraInitializers);
67
67
  constructor() {
68
68
  super('GoogleMaps');
69
+ const observer = this.getUserSettings().requestNotifyOnChange?.('maps', 'GOOGLE_MAPS_API_KEY');
70
+ observer?.on('changed', this.onPersonalApiKeySet.bind(this));
69
71
  }
70
72
  setApi(api) {
71
73
  this.api = api;
@@ -143,7 +143,7 @@ let AppsService = (() => {
143
143
  return operations;
144
144
  }
145
145
  getConnectedServices(operation) {
146
- const available = this.services[operation];
146
+ const available = this.getAvailableServices(operation);
147
147
  if (operation === 'ActivityUpload') {
148
148
  const factory = this.getActivityUploadFactory();
149
149
  const uploaders = available.map(a => factory.get(a));
@@ -158,6 +158,9 @@ let AppsService = (() => {
158
158
  }
159
159
  return [];
160
160
  }
161
+ getAvailableServices(operation) {
162
+ return this.services[operation];
163
+ }
161
164
  getName(key) {
162
165
  const found = this.serviceMap.find(r => r.key === key);
163
166
  return found ? found.name : key;
@@ -478,7 +478,6 @@ let DevicePairingService = (() => {
478
478
  delete state.deleted;
479
479
  delete state.waiting;
480
480
  state.interfaces = state.interfaces?.filter(i => !i.invisible);
481
- const oldState = this.state ?? {};
482
481
  return state;
483
482
  }
484
483
  emitStateChange(newState) {
@@ -41,7 +41,7 @@ exports.getCountries = exports.Countries = void 0;
41
41
  const service_1 = require("../../base/service");
42
42
  const types_1 = require("../../base/types");
43
43
  const countries_json_1 = __importDefault(require("./countries.json"));
44
- const api_1 = __importDefault(require("../../routes/base/api"));
44
+ const factory_1 = require("../../routes/base/api/factory");
45
45
  let Countries = (() => {
46
46
  let _classDecorators = [types_1.Singleton];
47
47
  let _classDescriptor;
@@ -91,7 +91,7 @@ let Countries = (() => {
91
91
  return countries.map(c => this.getIsoFromCountry(c, locale));
92
92
  }
93
93
  async getIsoFromLatLng(point) {
94
- const api = api_1.default.getInstance();
94
+ const api = (0, factory_1.useIncyclistRoutesApi)().create();
95
95
  return api.getCountry(point);
96
96
  }
97
97
  };
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const gd_eventlog_1 = require("gd-eventlog");
38
+ const consts_1 = require("./consts");
39
+ const api_1 = require("../../../api");
40
+ const settings_1 = require("../../../settings");
41
+ const decorators_1 = require("../../../base/decorators");
42
+ const external_1 = require("../../../api/rest/external");
43
+ const fixMissingRouteDistances = (points) => {
44
+ let routeDistance = 0;
45
+ points.forEach((p) => {
46
+ if (!p.routeDistance)
47
+ p.routeDistance = routeDistance;
48
+ routeDistance = p.routeDistance + p['distance'];
49
+ });
50
+ };
51
+ const verify = (route) => {
52
+ if (route['decoded']) {
53
+ route.points = route['decoded'];
54
+ delete route['decoded'];
55
+ fixMissingRouteDistances(route.points);
56
+ }
57
+ };
58
+ let IncyclistRoutesApi = (() => {
59
+ let _instanceExtraInitializers = [];
60
+ let _getUserSettings_decorators;
61
+ return class IncyclistRoutesApi {
62
+ static {
63
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
64
+ _getUserSettings_decorators = [decorators_1.Injectable];
65
+ __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
66
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
+ }
68
+ logger = __runInitializers(this, _instanceExtraInitializers);
69
+ api;
70
+ baseUrl;
71
+ isExternal;
72
+ source;
73
+ constructor(baseUrl) {
74
+ this.logger = new gd_eventlog_1.EventLogger('RouteListApi');
75
+ this.baseUrl = baseUrl;
76
+ if (baseUrl) {
77
+ this.isExternal = true;
78
+ }
79
+ }
80
+ setSource(source) {
81
+ this.source = source;
82
+ }
83
+ logError(err, fn, logInfo) {
84
+ const args = logInfo ?? {};
85
+ this.logger.logEvent({ message: 'Error', error: err.message, fn, ...args });
86
+ }
87
+ getApi() {
88
+ if (!this.api) {
89
+ this.api = this.baseUrl ?
90
+ external_1.IncyclistExternalRestApiClient.getClient() :
91
+ api_1.IncyclistRestApiClient.getClient();
92
+ return this.api;
93
+ }
94
+ return this.api;
95
+ }
96
+ getBaseUrl() {
97
+ if (this.baseUrl)
98
+ return this.baseUrl;
99
+ const domain = this.getUserSettings().getValue('DOMAIN', consts_1.DEFAULT_DOMAIN);
100
+ const defaultUrl = `https://dlws.${domain}/api/v1/routes`;
101
+ const baseUrl = this.getUserSettings().getValue(consts_1.ROUTE_API, defaultUrl);
102
+ return baseUrl;
103
+ }
104
+ async getRouteDescriptions(query, throws = false) {
105
+ const { type = 'gpx', category } = query;
106
+ let url = (type === 'gpx') ? `?private=false` : `/?type=${type}`;
107
+ if (category)
108
+ url += `&category=${category}`;
109
+ try {
110
+ const res = await this._get(url, consts_1.NO_CACHE);
111
+ if (this.isExternal && Array.isArray(res.data)) {
112
+ res.data.forEach(route => {
113
+ route.apiServer = this.source;
114
+ });
115
+ }
116
+ return res.data;
117
+ }
118
+ catch (err) {
119
+ if (throws)
120
+ throw (err);
121
+ this.logError(err, 'getRouteDescriptions', { query });
122
+ return undefined;
123
+ }
124
+ }
125
+ async getRouteDetails(routeId) {
126
+ try {
127
+ const res = await this._get(`/${routeId}`);
128
+ verify(res.data);
129
+ return res.data;
130
+ }
131
+ catch {
132
+ return undefined;
133
+ }
134
+ }
135
+ async getRoutePreview(routeId) {
136
+ try {
137
+ const res = await this._get(`/${routeId}/preview`);
138
+ return res.data?.url;
139
+ }
140
+ catch {
141
+ return undefined;
142
+ }
143
+ }
144
+ async getCountry(query) {
145
+ if (this.isExternal)
146
+ return;
147
+ if (!query)
148
+ return;
149
+ let url;
150
+ if (Array.isArray(query)) {
151
+ const points = query.slice(0, 100).map((p) => `${p.lat},${p.lng}`).join(';');
152
+ url = `/country?points=${points}`;
153
+ }
154
+ else {
155
+ const { lat, lng } = query;
156
+ url = `/country?lat=${lat}&lng=${lng}`;
157
+ }
158
+ try {
159
+ const conf = {};
160
+ conf.validateStatus = (status) => {
161
+ return (status >= 200 && status < 300) || status == 404 || status == 429;
162
+ };
163
+ const res = await this._get(url, conf);
164
+ if (res.status === 404)
165
+ return;
166
+ if (res.status === 429) {
167
+ this.logger.logEvent({ message: 'getCountry hit rate limit', query });
168
+ return;
169
+ }
170
+ return res.data.country?.toUpperCase();
171
+ }
172
+ catch (err) {
173
+ this.logError(err, 'getCountry');
174
+ }
175
+ }
176
+ async reload() {
177
+ if (this.isExternal)
178
+ return;
179
+ try {
180
+ await this._get(`/reload`);
181
+ }
182
+ catch (err) {
183
+ this.logError(err, 'reload');
184
+ }
185
+ }
186
+ async _get(url, ...args) {
187
+ const api = this.getApi();
188
+ const baseUrl = this.getBaseUrl();
189
+ return await api.get(baseUrl + url, ...args);
190
+ }
191
+ getUserSettings() {
192
+ return (0, settings_1.useUserSettings)();
193
+ }
194
+ };
195
+ })();
196
+ exports.default = IncyclistRoutesApi;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.useIncyclistRoutesApi = exports.IncyclistRoutesApiFactory = void 0;
41
+ const api_1 = __importDefault(require("./api"));
42
+ const decorators_1 = require("../../../base/decorators");
43
+ const settings_1 = require("../../../settings");
44
+ let IncyclistRoutesApiFactory = (() => {
45
+ let _classDecorators = [decorators_1.Singleton];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ let _instanceExtraInitializers = [];
50
+ let _getUserSettings_decorators;
51
+ var IncyclistRoutesApiFactory = class {
52
+ static { _classThis = this; }
53
+ static {
54
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
55
+ _getUserSettings_decorators = [decorators_1.Injectable];
56
+ __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
57
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
58
+ IncyclistRoutesApiFactory = _classThis = _classDescriptor.value;
59
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
60
+ __runInitializers(_classThis, _classExtraInitializers);
61
+ }
62
+ apis = (__runInitializers(this, _instanceExtraInitializers), new Map());
63
+ create(key = 'default') {
64
+ if (this.apis.has(key))
65
+ return this.apis.get(key);
66
+ const ROUTE_API = this.getUserSettings().getValue('ROUTE_API', undefined);
67
+ if (key === 'default' && ROUTE_API === undefined) {
68
+ const api = new api_1.default();
69
+ this.apis.set('default', api);
70
+ return api;
71
+ }
72
+ else if (key === 'default' && ROUTE_API !== undefined) {
73
+ const api = new api_1.default(ROUTE_API);
74
+ this.apis.set('default', api);
75
+ return api;
76
+ }
77
+ else {
78
+ const baseUrl = this.getUserSettings().getValue(`routes.servers.${key}`, null);
79
+ const api = new api_1.default(baseUrl ?? key);
80
+ api.setSource(key);
81
+ this.apis.set(key, api);
82
+ return api;
83
+ }
84
+ }
85
+ getUserSettings() {
86
+ return (0, settings_1.useUserSettings)();
87
+ }
88
+ };
89
+ return IncyclistRoutesApiFactory = _classThis;
90
+ })();
91
+ exports.IncyclistRoutesApiFactory = IncyclistRoutesApiFactory;
92
+ const useIncyclistRoutesApi = () => new IncyclistRoutesApiFactory();
93
+ exports.useIncyclistRoutesApi = useIncyclistRoutesApi;