@time2win/t2w 1.5.3 → 2.0.1

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2.0.1 - 2025-07-28
9
+ ### Changed
10
+ Optional check for all response map calls
11
+
12
+ ## 2.0.0 - 2025-06-12
13
+ ### Changed
14
+ All method signatures to use options object for optional params
15
+
8
16
  ## 1.5.3 - 2025-06-12
9
17
  ### Use
10
18
  Cached Event Data for wrapper calls
package/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { T2WEvent, T2WEventResponse, T2WIndividualResultResponse, T2WParticipantResponse, T2WTeamResponse, T2WTeamResultsResponse } from './models';
1
+ import { EventDataOptions, IndividualResultsOptions, ParticipantInfoOptions, T2WEvent, T2WEventResponse, T2WIndividualResultResponse, T2WParticipantResponse, T2WTeamResponse, T2WTeamResultsResponse, TeamResultOptions, TeamsWithMembersOptions } from './models';
2
2
  export default class Time2WinAPI {
3
3
  private readonly apiUrl;
4
4
  private readonly apiKey;
5
5
  private readonly pageSize;
6
6
  constructor(apiKey: string, pageSize?: number);
7
- getEventData(eventId: number, dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[]): Promise<T2WEvent>;
8
- getEventDataWithCache(eventId: number, dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[], maxAge?: number): Promise<T2WEvent>;
9
- getTeamResult(eventId: number, raceId: number, dataExtra?: ('splits' | 'attributes' | 'laps')[], teamType?: 'M' | 'F' | 'U', page?: number): Promise<T2WTeamResultsResponse>;
10
- getTeamsWithMembers(eventId: number, raceId?: number, dataExtra?: ('teammembers' | 'attributes')[], page?: number): Promise<T2WTeamResponse>;
11
- getIndividualResults(eventId: number, raceId: number, dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[], gender?: 'M' | 'F' | 'U', page?: number): Promise<T2WIndividualResultResponse>;
12
- getParticipantInfos(eventId: number, raceId?: number, dataExtra?: ('order' | 'attributes' | 'categories' | 'uci_id' | 'chip_code' | 'externalticket' | 'contactinfo')[], gender?: 'M' | 'F' | 'U', page?: number): Promise<T2WParticipantResponse>;
7
+ getEventData(eventId: number, options?: EventDataOptions): Promise<T2WEvent>;
8
+ getEventDataWithCache(eventId: number, options?: EventDataOptions, maxAge?: number): Promise<T2WEvent>;
9
+ getTeamResult(eventId: number, raceId: number, options?: TeamResultOptions, page?: number): Promise<T2WTeamResultsResponse>;
10
+ getTeamsWithMembers(eventId: number, options?: TeamsWithMembersOptions, page?: number): Promise<T2WTeamResponse>;
11
+ getIndividualResults(eventId: number, raceId: number, options?: IndividualResultsOptions, page?: number): Promise<T2WIndividualResultResponse>;
12
+ getParticipantInfos(eventId: number, options?: ParticipantInfoOptions, page?: number): Promise<T2WParticipantResponse>;
13
13
  /**
14
14
  * if no params are given, the events in the next seven days are returned
15
15
  * */
package/index.js CHANGED
@@ -54,26 +54,28 @@ var Time2WinAPI = /** @class */ (function () {
54
54
  this.apiKey = apiKey;
55
55
  this.pageSize = pageSize;
56
56
  }
57
- Time2WinAPI.prototype.getEventData = function (eventId, dataExtra) {
57
+ Time2WinAPI.prototype.getEventData = function (eventId, options) {
58
58
  return __awaiter(this, void 0, void 0, function () {
59
59
  var _this = this;
60
60
  return __generator(this, function (_a) {
61
61
  return [2 /*return*/, new Promise(function (resolve, reject) {
62
- var queryParams = { 'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '', 'page_size': _this.pageSize };
62
+ var _a;
63
+ var queryParams = { 'data_extra': ((_a = options === null || options === void 0 ? void 0 : options.dataExtra) === null || _a === void 0 ? void 0 : _a.join(',')) || '', 'page_size': _this.pageSize };
63
64
  fetch(_this.getUrl(_this.apiUrl, "event/".concat(eventId, "/eventdata"), queryParams))
64
65
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
65
66
  var body;
66
- return __generator(this, function (_a) {
67
- switch (_a.label) {
67
+ var _a;
68
+ return __generator(this, function (_b) {
69
+ switch (_b.label) {
68
70
  case 0: return [4 /*yield*/, response.json()];
69
71
  case 1:
70
- body = _a.sent();
72
+ body = _b.sent();
71
73
  if (response.status === 403) {
72
74
  reject(body);
73
75
  return [2 /*return*/];
74
76
  }
75
77
  // Convert strings to dates
76
- body.races = body.races.map(function (r) {
78
+ body.races = (_a = body.races) === null || _a === void 0 ? void 0 : _a.map(function (r) {
77
79
  return __assign(__assign({}, r), { starttime: new Date(r.starttime) });
78
80
  });
79
81
  body.registration_start = new Date("".concat(body.registration_start, "Z"));
@@ -88,31 +90,33 @@ var Time2WinAPI = /** @class */ (function () {
88
90
  });
89
91
  });
90
92
  };
91
- Time2WinAPI.prototype.getEventDataWithCache = function (eventId, dataExtra, maxAge) {
93
+ Time2WinAPI.prototype.getEventDataWithCache = function (eventId, options, maxAge) {
92
94
  if (maxAge === void 0) { maxAge = 0; }
93
95
  return __awaiter(this, void 0, void 0, function () {
94
96
  var _this = this;
95
97
  return __generator(this, function (_a) {
96
98
  return [2 /*return*/, new Promise(function (resolve, reject) {
99
+ var _a;
97
100
  var queryParams = {
98
- data_extra: (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
101
+ data_extra: ((_a = options === null || options === void 0 ? void 0 : options.dataExtra) === null || _a === void 0 ? void 0 : _a.join(',')) || '',
99
102
  page_size: _this.pageSize,
100
103
  max_age: maxAge
101
104
  };
102
105
  fetch(_this.getUrl('https://t2wserver.ddns.net/server/{{route}}', "events/".concat(eventId), queryParams))
103
106
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
104
107
  var body;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
108
+ var _a;
109
+ return __generator(this, function (_b) {
110
+ switch (_b.label) {
107
111
  case 0: return [4 /*yield*/, response.json()];
108
112
  case 1:
109
- body = _a.sent();
113
+ body = _b.sent();
110
114
  if (response.status === 403) {
111
115
  reject(body);
112
116
  return [2 /*return*/];
113
117
  }
114
118
  // Convert strings to dates
115
- body.races = body.races.map(function (r) {
119
+ body.races = (_a = body.races) === null || _a === void 0 ? void 0 : _a.map(function (r) {
116
120
  return __assign(__assign({}, r), { starttime: new Date(r.starttime) });
117
121
  });
118
122
  body.registration_start = new Date("".concat(body.registration_start, "Z"));
@@ -127,17 +131,18 @@ var Time2WinAPI = /** @class */ (function () {
127
131
  });
128
132
  });
129
133
  };
130
- Time2WinAPI.prototype.getTeamResult = function (eventId, raceId, dataExtra, teamType, page) {
134
+ Time2WinAPI.prototype.getTeamResult = function (eventId, raceId, options, page) {
131
135
  if (page === void 0) { page = 1; }
132
136
  return __awaiter(this, void 0, void 0, function () {
133
137
  var _this = this;
134
138
  return __generator(this, function (_a) {
135
139
  return [2 /*return*/, new Promise(function (resolve, reject) {
140
+ var _a;
136
141
  var queryParams = {
137
142
  'race_id': raceId,
138
- 'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
143
+ 'data_extra': ((_a = options === null || options === void 0 ? void 0 : options.dataExtra) === null || _a === void 0 ? void 0 : _a.join(',')) || '',
139
144
  page: page,
140
- 'team_type': teamType || '',
145
+ 'team_type': (options === null || options === void 0 ? void 0 : options.teamType) || '',
141
146
  'page_size': _this.pageSize
142
147
  };
143
148
  fetch(_this.getUrl(_this.apiUrl, "results/".concat(eventId, "/teams"), queryParams))
@@ -145,11 +150,12 @@ var Time2WinAPI = /** @class */ (function () {
145
150
  var body, _a, _b, _c;
146
151
  var _d;
147
152
  var _this = this;
148
- return __generator(this, function (_e) {
149
- switch (_e.label) {
153
+ var _e;
154
+ return __generator(this, function (_f) {
155
+ switch (_f.label) {
150
156
  case 0: return [4 /*yield*/, response.json()];
151
157
  case 1:
152
- body = _e.sent();
158
+ body = _f.sent();
153
159
  if (response.status === 403) {
154
160
  reject(body);
155
161
  return [2 /*return*/];
@@ -157,14 +163,14 @@ var Time2WinAPI = /** @class */ (function () {
157
163
  if (!(body.page < body.page_total)) return [3 /*break*/, 3];
158
164
  _b = (_a = (_d = body.list).push).apply;
159
165
  _c = [_d];
160
- return [4 /*yield*/, this.getTeamResult(eventId, raceId, dataExtra, teamType, body.page + 1)];
166
+ return [4 /*yield*/, this.getTeamResult(eventId, raceId, options, body.page + 1)];
161
167
  case 2:
162
- _b.apply(_a, _c.concat([(_e.sent()).list]));
168
+ _b.apply(_a, _c.concat([(_f.sent()).list]));
163
169
  body.page = Math.ceil(body.list.length / body.page_size);
164
170
  resolve(body);
165
- _e.label = 3;
171
+ _f.label = 3;
166
172
  case 3:
167
- body.list = body.list.map(function (p) {
173
+ body.list = (_e = body.list) === null || _e === void 0 ? void 0 : _e.map(function (p) {
168
174
  return __assign(__assign({}, p), { racenumNumeric: _this.getNumericBib(p.racenum), gender: p.team_type });
169
175
  });
170
176
  resolve(body);
@@ -177,15 +183,16 @@ var Time2WinAPI = /** @class */ (function () {
177
183
  });
178
184
  });
179
185
  };
180
- Time2WinAPI.prototype.getTeamsWithMembers = function (eventId, raceId, dataExtra, page) {
186
+ Time2WinAPI.prototype.getTeamsWithMembers = function (eventId, options, page) {
181
187
  if (page === void 0) { page = 1; }
182
188
  return __awaiter(this, void 0, void 0, function () {
183
189
  var _this = this;
184
190
  return __generator(this, function (_a) {
185
191
  return [2 /*return*/, new Promise(function (resolve, reject) {
192
+ var _a;
186
193
  var queryParams = {
187
- 'race_id': raceId || '',
188
- 'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
194
+ 'race_id': (options === null || options === void 0 ? void 0 : options.raceId) || '',
195
+ 'data_extra': ((_a = options === null || options === void 0 ? void 0 : options.dataExtra) === null || _a === void 0 ? void 0 : _a.join(',')) || '',
189
196
  'page_size': _this.pageSize,
190
197
  page: page
191
198
  };
@@ -194,11 +201,12 @@ var Time2WinAPI = /** @class */ (function () {
194
201
  var body, _a, _b, _c;
195
202
  var _d;
196
203
  var _this = this;
197
- return __generator(this, function (_e) {
198
- switch (_e.label) {
204
+ var _e;
205
+ return __generator(this, function (_f) {
206
+ switch (_f.label) {
199
207
  case 0: return [4 /*yield*/, response.json()];
200
208
  case 1:
201
- body = _e.sent();
209
+ body = _f.sent();
202
210
  if (response.status === 403) {
203
211
  reject(body);
204
212
  return [2 /*return*/];
@@ -206,15 +214,15 @@ var Time2WinAPI = /** @class */ (function () {
206
214
  if (!body.page_more) return [3 /*break*/, 3];
207
215
  _b = (_a = (_d = body.list).push).apply;
208
216
  _c = [_d];
209
- return [4 /*yield*/, this.getTeamsWithMembers(eventId, raceId, dataExtra, body.page + 1)];
217
+ return [4 /*yield*/, this.getTeamsWithMembers(eventId, options, body.page + 1)];
210
218
  case 2:
211
- _b.apply(_a, _c.concat([(_e.sent()).list]));
219
+ _b.apply(_a, _c.concat([(_f.sent()).list]));
212
220
  body.page_more = false;
213
221
  body.page = Math.ceil(body.list.length / body.page_size);
214
222
  resolve(body);
215
- _e.label = 3;
223
+ _f.label = 3;
216
224
  case 3:
217
- body.list = body.list.map(function (p) {
225
+ body.list = (_e = body.list) === null || _e === void 0 ? void 0 : _e.map(function (p) {
218
226
  var _a;
219
227
  return __assign(__assign({}, p), { racenumNumeric: _this.getNumericBib(p.racenum), gender: p.team_type, members: ((_a = p.members) === null || _a === void 0 ? void 0 : _a.map(function (m) {
220
228
  return __assign(__assign({}, m), { racenumNumeric: _this.getNumericBib(m.racenum) });
@@ -230,7 +238,7 @@ var Time2WinAPI = /** @class */ (function () {
230
238
  });
231
239
  });
232
240
  };
233
- Time2WinAPI.prototype.getIndividualResults = function (eventId, raceId, dataExtra, gender, page) {
241
+ Time2WinAPI.prototype.getIndividualResults = function (eventId, raceId, options, page) {
234
242
  if (page === void 0) { page = 1; }
235
243
  return __awaiter(this, void 0, void 0, function () {
236
244
  var _a;
@@ -238,13 +246,13 @@ var Time2WinAPI = /** @class */ (function () {
238
246
  switch (_b.label) {
239
247
  case 0:
240
248
  _a = this.fetchIndividualResults;
241
- return [4 /*yield*/, this.getEventDataWithCache(eventId, ['splits'])];
242
- case 1: return [2 /*return*/, _a.apply(this, [_b.sent(), raceId, dataExtra, gender, page])];
249
+ return [4 /*yield*/, this.getEventDataWithCache(eventId, { dataExtra: ['splits'] }, options === null || options === void 0 ? void 0 : options.maxEventAge)];
250
+ case 1: return [2 /*return*/, _a.apply(this, [_b.sent(), raceId, options === null || options === void 0 ? void 0 : options.dataExtra, options === null || options === void 0 ? void 0 : options.gender, page])];
243
251
  }
244
252
  });
245
253
  });
246
254
  };
247
- Time2WinAPI.prototype.getParticipantInfos = function (eventId, raceId, dataExtra, gender, page) {
255
+ Time2WinAPI.prototype.getParticipantInfos = function (eventId, options, page) {
248
256
  if (page === void 0) { page = 1; }
249
257
  return __awaiter(this, void 0, void 0, function () {
250
258
  var _a;
@@ -252,8 +260,8 @@ var Time2WinAPI = /** @class */ (function () {
252
260
  switch (_b.label) {
253
261
  case 0:
254
262
  _a = this.fetchParticipantInfos;
255
- return [4 /*yield*/, this.getEventDataWithCache(eventId)];
256
- case 1: return [2 /*return*/, _a.apply(this, [_b.sent(), raceId, dataExtra, gender, page])];
263
+ return [4 /*yield*/, this.getEventDataWithCache(eventId, {}, options === null || options === void 0 ? void 0 : options.maxEventAge)];
264
+ case 1: return [2 /*return*/, _a.apply(this, [_b.sent(), options === null || options === void 0 ? void 0 : options.raceId, options === null || options === void 0 ? void 0 : options.dataExtra, options === null || options === void 0 ? void 0 : options.gender, page])];
257
265
  }
258
266
  });
259
267
  });
@@ -378,11 +386,12 @@ var Time2WinAPI = /** @class */ (function () {
378
386
  var body, _a, _b, _c;
379
387
  var _d;
380
388
  var _this = this;
381
- return __generator(this, function (_e) {
382
- switch (_e.label) {
389
+ var _e;
390
+ return __generator(this, function (_f) {
391
+ switch (_f.label) {
383
392
  case 0: return [4 /*yield*/, response.json()];
384
393
  case 1:
385
- body = _e.sent();
394
+ body = _f.sent();
386
395
  if (response.status === 403) {
387
396
  reject(body);
388
397
  return [2 /*return*/];
@@ -392,13 +401,13 @@ var Time2WinAPI = /** @class */ (function () {
392
401
  _c = [_d];
393
402
  return [4 /*yield*/, this.fetchParticipantInfos(event, raceId, dataExtra, gender, body.page + 1)];
394
403
  case 2:
395
- _b.apply(_a, _c.concat([(_e.sent()).list]));
404
+ _b.apply(_a, _c.concat([(_f.sent()).list]));
396
405
  body.page_more = false;
397
406
  body.page = Math.ceil(body.list.length / body.page_size);
398
407
  resolve(body);
399
- _e.label = 3;
408
+ _f.label = 3;
400
409
  case 3:
401
- body.list = body.list.map(function (p) {
410
+ body.list = (_e = body.list) === null || _e === void 0 ? void 0 : _e.map(function (p) {
402
411
  var race = event.races.find(function (r) { return r.race_id === p.race_id; });
403
412
  return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null, age: p.birthdate && race ? _this.calculateAge(new Date(p.birthdate), race.starttime) : null, year: p.birthdate ? new Date(p.birthdate).getFullYear() : null, order_date: p.order_date ? new Date(p.order_date) : null, racenumNumeric: _this.getNumericBib(p.racenum) });
404
413
  });
package/models.d.ts CHANGED
@@ -271,4 +271,26 @@ export declare enum RaceStatus {
271
271
  CHECKED_IN = 50,
272
272
  PENALTY = 60
273
273
  }
274
+ export interface ParticipantInfoOptions {
275
+ raceId?: number;
276
+ dataExtra?: ('order' | 'attributes' | 'categories' | 'uci_id' | 'chip_code' | 'externalticket' | 'contactinfo')[];
277
+ gender?: 'M' | 'F' | 'U';
278
+ maxEventAge?: number;
279
+ }
280
+ export interface IndividualResultsOptions {
281
+ dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[];
282
+ gender?: 'M' | 'F' | 'U';
283
+ maxEventAge?: number;
284
+ }
285
+ export interface EventDataOptions {
286
+ dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[];
287
+ }
288
+ export interface TeamResultOptions {
289
+ dataExtra?: ('splits' | 'attributes' | 'laps')[];
290
+ teamType?: 'M' | 'F' | 'U';
291
+ }
292
+ export interface TeamsWithMembersOptions {
293
+ raceId?: number;
294
+ dataExtra?: ('teammembers' | 'attributes')[];
295
+ }
274
296
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@time2win/t2w",
3
- "version": "1.5.3",
3
+ "version": "2.0.1",
4
4
  "description": "providing latest-state models and advanced methods to interact with the T2W API",
5
5
  "keywords": [
6
6
  "time2win",
package/test.js CHANGED
@@ -8,6 +8,6 @@ var api = new index_1.default('09f006ca-23ee-44da-bec5-4372580f4113');
8
8
  // api.getIndividualResults(38, 161).then(res => {
9
9
  // console.log(res.list[0]);
10
10
  // });
11
- api.getEventDataWithCache(664, ['splits'], 5).then(function (res) {
11
+ api.getEventDataWithCache(664, { dataExtra: ['splits'] }, 5).then(function (res) {
12
12
  console.log(res);
13
13
  }).catch(console.log);