@time2win/t2w 2.0.4 → 2.1.0

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.1.0 - 2025-08-28
9
+ ### Added
10
+ getIndividualResult() to get a single individual result by signupId
11
+
12
+ ## 2.0.5 - 2025-08-26
13
+ ### Added
14
+ page size option to participantInfo and individualResults methods
15
+
8
16
  ## 2.0.4 - 2025-08-22
9
17
  ### Added
10
18
  non binary gender support
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventDataOptions, IndividualResultsOptions, ParticipantInfoOptions, T2WEvent, T2WEventResponse, T2WIndividualResultResponse, T2WParticipantResponse, T2WTeamResponse, T2WTeamResultsResponse, TeamResultOptions, TeamsWithMembersOptions } from './models';
1
+ import { EventDataOptions, IndividualResultOptions, IndividualResultsOptions, ParticipantInfoOptions, T2WEvent, T2WEventResponse, T2WIndividualResultResponse, T2WIndividualResultsResponse, T2WParticipantResponse, T2WTeamResponse, T2WTeamResultsResponse, TeamResultOptions, TeamsWithMembersOptions } from './models';
2
2
  export default class Time2WinAPI {
3
3
  private readonly apiUrl;
4
4
  private readonly _apiKey;
@@ -9,7 +9,8 @@ export default class Time2WinAPI {
9
9
  getEventDataWithCache(eventId: number, options?: EventDataOptions, maxAge?: number): Promise<T2WEvent>;
10
10
  getTeamResult(eventId: number, raceId: number, options?: TeamResultOptions, page?: number): Promise<T2WTeamResultsResponse>;
11
11
  getTeamsWithMembers(eventId: number, options?: TeamsWithMembersOptions, page?: number): Promise<T2WTeamResponse>;
12
- getIndividualResults(eventId: number, raceId: number, options?: IndividualResultsOptions, page?: number): Promise<T2WIndividualResultResponse>;
12
+ getIndividualResults(eventId: number, raceId: number, options?: IndividualResultsOptions, page?: number): Promise<T2WIndividualResultsResponse>;
13
+ getIndividualResult(eventId: number, raceId: number, signupId: number, options?: IndividualResultOptions): Promise<T2WIndividualResultResponse>;
13
14
  getParticipantInfos(eventId: number, options?: ParticipantInfoOptions, page?: number): Promise<T2WParticipantResponse>;
14
15
  /**
15
16
  * if no params are given, the events in the next seven days are returned
package/index.js CHANGED
@@ -254,11 +254,52 @@ var Time2WinAPI = /** @class */ (function () {
254
254
  case 0:
255
255
  _a = this.fetchIndividualResults;
256
256
  return [4 /*yield*/, this.getEventDataWithCache(eventId, { dataExtra: ['splits'] }, options === null || options === void 0 ? void 0 : options.maxEventAge)];
257
- 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])];
257
+ 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, options === null || options === void 0 ? void 0 : options.pageSize])];
258
258
  }
259
259
  });
260
260
  });
261
261
  };
262
+ Time2WinAPI.prototype.getIndividualResult = function (eventId, raceId, signupId, options) {
263
+ return __awaiter(this, void 0, void 0, function () {
264
+ var _this = this;
265
+ return __generator(this, function (_a) {
266
+ return [2 /*return*/, new Promise(function (resolve, reject) {
267
+ var _a;
268
+ var queryParams = {
269
+ 'race_id': raceId,
270
+ id: signupId,
271
+ 'data_extra': ((_a = options === null || options === void 0 ? void 0 : options.dataExtra) === null || _a === void 0 ? void 0 : _a.join(',')) || ''
272
+ };
273
+ fetch(_this.getUrl(_this.apiUrl, "results/".concat(eventId, "/individual"), queryParams))
274
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
275
+ var body, event;
276
+ var _this = this;
277
+ var _a;
278
+ return __generator(this, function (_b) {
279
+ switch (_b.label) {
280
+ case 0: return [4 /*yield*/, response.json()];
281
+ case 1:
282
+ body = _b.sent();
283
+ if (response.status === 403) {
284
+ reject(body);
285
+ return [2 /*return*/];
286
+ }
287
+ return [4 /*yield*/, this.getEventDataWithCache(eventId, { dataExtra: ['splits'] }, options === null || options === void 0 ? void 0 : options.maxEventAge)];
288
+ case 2:
289
+ event = _b.sent();
290
+ body.results = ((_a = body.results) === null || _a === void 0 ? void 0 : _a.map(function (p) {
291
+ return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null, racenumNumeric: _this.getNumericBib(p.racenum), speedNetto: _this.calculateSpeed(p, event, 'speed', 'netto') + ' km/h', speedBrutto: _this.calculateSpeed(p, event, 'speed', 'brutto') + ' km/h', paceNetto: _this.calculateSpeed(p, event, 'pace', 'netto') + ' min/km', paceBrutto: _this.calculateSpeed(p, event, 'pace', 'brutto') + ' min/km' });
292
+ })) || [];
293
+ resolve(body);
294
+ return [2 /*return*/];
295
+ }
296
+ });
297
+ }); })
298
+ .catch(function (reason) { return reject(reason); });
299
+ })];
300
+ });
301
+ });
302
+ };
262
303
  Time2WinAPI.prototype.getParticipantInfos = function (eventId, options, page) {
263
304
  if (page === void 0) { page = 1; }
264
305
  return __awaiter(this, void 0, void 0, function () {
@@ -268,7 +309,7 @@ var Time2WinAPI = /** @class */ (function () {
268
309
  case 0:
269
310
  _a = this.fetchParticipantInfos;
270
311
  return [4 /*yield*/, this.getEventDataWithCache(eventId, {}, options === null || options === void 0 ? void 0 : options.maxEventAge)];
271
- 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])];
312
+ 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, options === null || options === void 0 ? void 0 : options.pageSize])];
272
313
  }
273
314
  });
274
315
  });
@@ -321,8 +362,9 @@ var Time2WinAPI = /** @class */ (function () {
321
362
  });
322
363
  });
323
364
  };
324
- Time2WinAPI.prototype.fetchIndividualResults = function (event, raceId, dataExtra, gender, page) {
365
+ Time2WinAPI.prototype.fetchIndividualResults = function (event, raceId, dataExtra, gender, page, pageSize) {
325
366
  if (page === void 0) { page = 1; }
367
+ if (pageSize === void 0) { pageSize = this.pageSize; }
326
368
  return __awaiter(this, void 0, void 0, function () {
327
369
  var _this = this;
328
370
  return __generator(this, function (_a) {
@@ -332,7 +374,7 @@ var Time2WinAPI = /** @class */ (function () {
332
374
  'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
333
375
  page: page,
334
376
  'gender': gender || '',
335
- 'page_size': _this.pageSize
377
+ 'page_size': pageSize
336
378
  };
337
379
  fetch(_this.getUrl(_this.apiUrl, "results/".concat(event.event_id, "/individuals"), queryParams))
338
380
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
@@ -372,8 +414,9 @@ var Time2WinAPI = /** @class */ (function () {
372
414
  });
373
415
  });
374
416
  };
375
- Time2WinAPI.prototype.fetchParticipantInfos = function (event, raceId, dataExtra, gender, page) {
417
+ Time2WinAPI.prototype.fetchParticipantInfos = function (event, raceId, dataExtra, gender, page, pageSize) {
376
418
  if (page === void 0) { page = 1; }
419
+ if (pageSize === void 0) { pageSize = this.pageSize; }
377
420
  return __awaiter(this, void 0, void 0, function () {
378
421
  var _this = this;
379
422
  return __generator(this, function (_a) {
@@ -386,7 +429,7 @@ var Time2WinAPI = /** @class */ (function () {
386
429
  'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
387
430
  gender: gender || '',
388
431
  page: page,
389
- 'page_size': this.pageSize
432
+ 'page_size': pageSize
390
433
  };
391
434
  fetch(this.getUrl(this.apiUrl, "/participants/".concat(event.event_id, "/individuals"), queryParams))
392
435
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
package/models.d.ts CHANGED
@@ -152,13 +152,16 @@ export interface T2WTeam {
152
152
  attr_2: string | null;
153
153
  members: T2WTeamMember[];
154
154
  }
155
- export interface T2WIndividualResultResponse {
155
+ export interface T2WIndividualResultsResponse {
156
156
  page_size: number;
157
157
  page: number;
158
158
  page_total: number;
159
159
  count_total: number;
160
160
  list: T2WIndividualResult[];
161
161
  }
162
+ export interface T2WIndividualResultResponse {
163
+ results: T2WIndividualResult[];
164
+ }
162
165
  export interface T2WIndividualResult extends T2WParticipantBasic {
163
166
  pos_overall: number;
164
167
  pos_gender: number;
@@ -276,11 +279,17 @@ export interface ParticipantInfoOptions {
276
279
  dataExtra?: ('order' | 'attributes' | 'categories' | 'uci_id' | 'chip_code' | 'externalticket' | 'contactinfo')[];
277
280
  gender?: T2WGender;
278
281
  maxEventAge?: number;
282
+ pageSize?: number;
279
283
  }
280
284
  export interface IndividualResultsOptions {
281
285
  dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[];
282
286
  gender?: T2WGender;
283
287
  maxEventAge?: number;
288
+ pageSize?: number;
289
+ }
290
+ export interface IndividualResultOptions {
291
+ dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[];
292
+ maxEventAge?: number;
284
293
  }
285
294
  export interface EventDataOptions {
286
295
  dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@time2win/t2w",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
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, { dataExtra: ['splits'] }, 5).then(function (res) {
12
- console.log(res);
13
- }).catch(console.log);
11
+ // api.getEventDataWithCache(664, { dataExtra: [ 'splits'] }, 5).then(res => {
12
+ // console.log(res);
13
+ // }).catch(console.log);