@time2win/t2w 1.4.23 → 1.5.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 +4 -0
- package/index.d.ts +1 -0
- package/index.js +50 -9
- package/package.json +2 -2
- package/test.js +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ 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
|
+
## 1.5.0 - 2025-06-12
|
|
9
|
+
### Added
|
|
10
|
+
```getEventDataWithCache()``` method to fetch event data with caching support
|
|
11
|
+
|
|
8
12
|
## 1.4.23 - 2025-05-22
|
|
9
13
|
### Added
|
|
10
14
|
field ```gender``` to team types
|
package/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export default class Time2WinAPI {
|
|
|
5
5
|
private readonly pageSize;
|
|
6
6
|
constructor(apiKey: string, pageSize?: number);
|
|
7
7
|
getEventData(eventId: number, dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[]): Promise<T2WEvent>;
|
|
8
|
+
getEventDataWithCache(eventId: number, dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[], maxAge?: number): Promise<T2WEvent>;
|
|
8
9
|
getTeamResult(eventId: number, raceId: number, dataExtra?: ('splits' | 'attributes' | 'laps')[], teamType?: 'M' | 'F' | 'U', page?: number): Promise<T2WTeamResultsResponse>;
|
|
9
10
|
getTeamsWithMembers(eventId: number, raceId?: number, dataExtra?: ('teammembers' | 'attributes')[], page?: number): Promise<T2WTeamResponse>;
|
|
10
11
|
getIndividualResults(eventId: number, raceId: number, dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[], gender?: 'M' | 'F' | 'U', page?: number): Promise<T2WIndividualResultResponse>;
|
package/index.js
CHANGED
|
@@ -60,7 +60,46 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
60
60
|
return __generator(this, function (_a) {
|
|
61
61
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
62
62
|
var queryParams = { 'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '', 'page_size': _this.pageSize };
|
|
63
|
-
fetch(_this.getUrl("event/".concat(eventId, "/eventdata"), queryParams))
|
|
63
|
+
fetch(_this.getUrl(_this.apiUrl, "event/".concat(eventId, "/eventdata"), queryParams))
|
|
64
|
+
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
|
+
var body;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0: return [4 /*yield*/, response.json()];
|
|
69
|
+
case 1:
|
|
70
|
+
body = _a.sent();
|
|
71
|
+
if (response.status === 403) {
|
|
72
|
+
reject(body);
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
// Convert strings to dates
|
|
76
|
+
body.races = body.races.map(function (r) {
|
|
77
|
+
return __assign(__assign({}, r), { starttime: new Date(r.starttime) });
|
|
78
|
+
});
|
|
79
|
+
body.registration_start = new Date("".concat(body.registration_start, "Z"));
|
|
80
|
+
body.registration_end = new Date("".concat(body.registration_end, "Z"));
|
|
81
|
+
resolve(body);
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); })
|
|
86
|
+
.catch(function (reason) { return reject(reason); });
|
|
87
|
+
})];
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
Time2WinAPI.prototype.getEventDataWithCache = function (eventId, dataExtra, maxAge) {
|
|
92
|
+
if (maxAge === void 0) { maxAge = 0; }
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var _this = this;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
97
|
+
var queryParams = {
|
|
98
|
+
data_extra: (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
|
|
99
|
+
page_size: _this.pageSize,
|
|
100
|
+
max_age: maxAge
|
|
101
|
+
};
|
|
102
|
+
fetch(_this.getUrl('https://t2wserver.ddns.net/server/{{route}}', "events/".concat(eventId), queryParams))
|
|
64
103
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
104
|
var body;
|
|
66
105
|
return __generator(this, function (_a) {
|
|
@@ -101,7 +140,7 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
101
140
|
'team_type': teamType || '',
|
|
102
141
|
'page_size': _this.pageSize
|
|
103
142
|
};
|
|
104
|
-
fetch(_this.getUrl("results/".concat(eventId, "/teams"), queryParams))
|
|
143
|
+
fetch(_this.getUrl(_this.apiUrl, "results/".concat(eventId, "/teams"), queryParams))
|
|
105
144
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
106
145
|
var body, _a, _b, _c;
|
|
107
146
|
var _d;
|
|
@@ -150,7 +189,7 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
150
189
|
'page_size': _this.pageSize,
|
|
151
190
|
page: page
|
|
152
191
|
};
|
|
153
|
-
fetch(_this.getUrl("participants/".concat(eventId, "/teams"), queryParams))
|
|
192
|
+
fetch(_this.getUrl(_this.apiUrl, "participants/".concat(eventId, "/teams"), queryParams))
|
|
154
193
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
155
194
|
var body, _a, _b, _c;
|
|
156
195
|
var _d;
|
|
@@ -233,7 +272,7 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
233
272
|
to.setDate(to.getDate() + 7);
|
|
234
273
|
}
|
|
235
274
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
236
|
-
fetch(_this.getUrl("/events/list?from=".concat(_this.formatDate(from), "&to=").concat(_this.formatDate(to), "&page=").concat(page)))
|
|
275
|
+
fetch(_this.getUrl(_this.apiUrl, "/events/list?from=".concat(_this.formatDate(from), "&to=").concat(_this.formatDate(to), "&page=").concat(page)))
|
|
237
276
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
238
277
|
var body, _a, _b, _c;
|
|
239
278
|
var _d;
|
|
@@ -280,7 +319,7 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
280
319
|
'gender': gender || '',
|
|
281
320
|
'page_size': _this.pageSize
|
|
282
321
|
};
|
|
283
|
-
fetch(_this.getUrl("results/".concat(event.event_id, "/individuals"), queryParams))
|
|
322
|
+
fetch(_this.getUrl(_this.apiUrl, "results/".concat(event.event_id, "/individuals"), queryParams))
|
|
284
323
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
285
324
|
var body, _a, _b, _c;
|
|
286
325
|
var _d;
|
|
@@ -334,14 +373,16 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
334
373
|
page: page,
|
|
335
374
|
'page_size': this.pageSize
|
|
336
375
|
};
|
|
337
|
-
fetch(this.getUrl("/participants/".concat(event.event_id, "/individuals"), queryParams))
|
|
376
|
+
fetch(this.getUrl(this.apiUrl, "/participants/".concat(event.event_id, "/individuals"), queryParams))
|
|
338
377
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
339
378
|
var body, _a, _b, _c;
|
|
340
379
|
var _d;
|
|
341
380
|
var _this = this;
|
|
342
381
|
return __generator(this, function (_e) {
|
|
343
382
|
switch (_e.label) {
|
|
344
|
-
case 0:
|
|
383
|
+
case 0:
|
|
384
|
+
console.log(response.status);
|
|
385
|
+
return [4 /*yield*/, response.json()];
|
|
345
386
|
case 1:
|
|
346
387
|
body = _e.sent();
|
|
347
388
|
if (response.status === 403) {
|
|
@@ -375,8 +416,8 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
375
416
|
});
|
|
376
417
|
});
|
|
377
418
|
};
|
|
378
|
-
Time2WinAPI.prototype.getUrl = function (route, queryParams) {
|
|
379
|
-
var url =
|
|
419
|
+
Time2WinAPI.prototype.getUrl = function (apiUrl, route, queryParams) {
|
|
420
|
+
var url = apiUrl.replace('{{route}}', route);
|
|
380
421
|
if (url.endsWith('/')) {
|
|
381
422
|
url = url.slice(0, -1);
|
|
382
423
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@time2win/t2w",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "providing latest-state models and advanced methods to interact with the T2W API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"time2win",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"main": "index.js",
|
|
12
12
|
"types": "models.d.ts, index.d.ts",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"start:dev": "nodemon --watch src src/
|
|
14
|
+
"start:dev": "nodemon --watch src src/test.ts",
|
|
15
15
|
"start": "node dist/index.js",
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"publish": "npm publish --access public"
|
package/test.js
CHANGED
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var index_1 = __importDefault(require("./index"));
|
|
7
7
|
var api = new index_1.default('09f006ca-23ee-44da-bec5-4372580f4113');
|
|
8
|
-
api.getIndividualResults(38, 161).then(
|
|
9
|
-
|
|
10
|
-
});
|
|
8
|
+
// api.getIndividualResults(38, 161).then(res => {
|
|
9
|
+
// console.log(res.list[0]);
|
|
10
|
+
// });
|
|
11
|
+
api.getEventDataWithCache(664, ['splits'], 5).then(function (res) {
|
|
12
|
+
console.log(res);
|
|
13
|
+
}).catch(console.log);
|