Skip to content

Commit ebafa61

Browse files
authored
Merge branch 'main' into dev/demos-sdk
2 parents 0c8559f + be028c6 commit ebafa61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+337
-1249
lines changed

.github/labeler.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sdk:
2+
- changed-files:
3+
- any-glob-to-any-file: javscript_sdk/**
4+
logstf:
5+
- changed-files:
6+
- any-glob-to-any-file: logstf/**
7+
etf2l:
8+
- changed-files:
9+
- any-glob-to-any-file: etf2l/**
10+
rgl:
11+
- changed-files:
12+
- any-glob-to-any-file: rgl/**
13+
demostf:
14+
- changed-files:
15+
- any-glob-to-any-file: demostf/**

.github/workflows/labeler.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Pull Request Labeler"
2+
on:
3+
- pull_request_target
4+
5+
jobs:
6+
triage:
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/labeler@v5
13+
with:
14+
sync-labels: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Publish Javascript SDK
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'javascript-sdk/**'
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Publish package
21+
run: npx jsr publish

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/

CONTRIBUTING.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ The [Open Source Guides](https://opensource.guide/) website has great content th
66
- [Building Welcoming Communities](https://opensource.guide/building-community/)
77

88
## Get Involved
9+
910
The best way to get involved with this project is by opening a Pull Request. While this is good, we suggest you take a look at any issues that are marked "Help Wanted". An alternative would be to raise an issue on the GitHub with as much detail as you can put in.
1011

11-
Contributions are welcomed, please do not hesitate to make a pull request! We will guide you along the way.]
12+
Contributions are welcomed, please do not hesitate to make a pull request! We will guide you along the way.
1213

1314
# Pull Requests
1415

@@ -22,4 +23,4 @@ Pull requests should follow these guidelines:
2223

2324
## License
2425

25-
By contributing to this project, you agree that your contributions will be licensed under its [MIT license](https://github.com/tf2-software-enthusiasts/the-library/blob/main/LICENSE).
26+
By contributing to this project, you agree that your contributions will be licensed under its [MIT license](LICENSE).

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ We wish to provide highly consumable packages for developers to consume, without
88

99
# Strategy
1010

11-
The repoistory is set up as a lot of monorepos. There's different folders for each language, such as the `node-sdk` which is a monorepo of TypeScript libraries and packages that can be used to create and maintain both internal types for these APIs and also create SDK (libraries) for those APIs.
11+
The repoistory is set up as a lot of monorepos. There's different folders for each language, such as the `node-sdk` which is a monorepo of TypeScript libraries and packages that can be used to create and maintain both the types for these APIs and also the SDK for those APIs.
1212

1313
# Contributing
1414

15-
If you wish to contribute, please make sure to read our Contributing guidelines. There's a goal to have consistent design between languages (more or less!), and it will benefit if you could continue to follow those guidelines. Each language may have a set of their own standards to align to that specific language's syntax.
15+
If you wish to contribute, please make sure to read our [Contributing](CONTRIBUTING) guidelines. There's a goal to have consistent design between languages and it will benefit if you could continue to follow those guidelines. Each language may have a set of their own standards to align to that specific language's syntax.
1616

1717
# Contact
1818

19-
You can contact us by writing a GitHub issue.
19+
You can contact us by writing a GitHub issue.

javascript-sdk/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# JavaScript SDKs
2+
3+
This is a monorepo using [Deno](https://deno.com/) and packages support most major runtimes such as Node, Deno, Bun, etc.
4+
5+
## Guidelines
6+
7+
- Each SDK should have its own folder.
8+
- Use APIs available in as many runtimes as possible
9+
- Document public members
10+
- Create and export the public types of that package
11+
12+
## Creating your first SDK
13+
14+
If you wish to contribute, please make sure you read our [Contributing](CONTRIBUTING) guidelines in the root of the repository. If you wish to create a new package, please make sure you abide by the following:
15+
16+
- Edit the `deno.json` file with the new SDK you wish to create as a workspace
17+
- Create a new folder with the name of the new SDK you wish to support
18+
- Create both a `mod.ts` and `deno.json` file
19+
- Implement the SDK as needed

javascript-sdk/deno.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"exclude": [".git", "coverage", "docs"],
3+
"tasks": {
4+
"ok": "deno lint && deno fmt --check"
5+
},
6+
"workspace": ["./logstf"]
7+
}

javascript-sdk/logstf/api/logstf.ts

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import type {
2+
LogById,
3+
LogSearchRequest,
4+
LogSearchResponse,
5+
LogUploadRequest,
6+
LogUploadResponse,
7+
} from "../types/mod.ts";
8+
9+
/**
10+
* Gets the URL of the raw log file
11+
* @param id The id of the log
12+
* @returns The url of the log's zip file
13+
*
14+
* @internal
15+
*/
16+
const getRawLogUrl = (id: string) => `http://logs.tf/logs/log_${id}.log.zip`;
17+
18+
/**
19+
* The base URL of the for logs.tf
20+
* @internal
21+
*/
22+
const logsBaseUrl = "https://logs.tf";
23+
24+
/**
25+
* The logs API url
26+
* @internal
27+
*/
28+
const logsApiUrl = `${logsBaseUrl}/api/v1`;
29+
30+
/**
31+
* The logs upload url
32+
* @internal
33+
*/
34+
const logsUploadUrl = `${logsBaseUrl}/upload`;
35+
36+
/**
37+
* Gets a log by id
38+
* @param logId The log id to get
39+
* @returns {Promise<LogById>} The log json
40+
*/
41+
export async function getById(logId: string): Promise<LogById> {
42+
if (!logId) {
43+
throw new Error("LogId cannot be empty!");
44+
}
45+
46+
const data = await fetch(`${logsApiUrl}/log/${logId}`);
47+
48+
return (await data.json()) as LogById;
49+
}
50+
51+
/**
52+
* Searches for logs that match the filter
53+
* @param searchRequest The search request
54+
* @returns {Promise<LogSearchResponse>} The response of the search
55+
*/
56+
export async function search(
57+
searchRequest: LogSearchRequest
58+
): Promise<LogSearchResponse> {
59+
const {
60+
limit = 1000,
61+
map = null,
62+
offset = 0,
63+
player = [],
64+
title = null,
65+
uploader = null,
66+
} = searchRequest;
67+
68+
if (limit > 10_000) {
69+
throw new Error("Cannot take more than 10,000 logs at a time");
70+
}
71+
72+
const params = new URLSearchParams([
73+
["limit", limit.toString()],
74+
["offset", offset.toString()],
75+
]);
76+
77+
if (map) {
78+
params.append("map", map);
79+
}
80+
81+
if (player) {
82+
params.append("player", player.join(","));
83+
}
84+
85+
if (title) {
86+
params.append("title", title);
87+
}
88+
89+
if (uploader) {
90+
params.append("uploader", uploader);
91+
}
92+
93+
const response = await fetch(`${logsApiUrl}/log${params.toString()}`);
94+
95+
return (await response.json()) as LogSearchResponse;
96+
}
97+
98+
/**
99+
* Uploads a log to logs.tf
100+
* @param apiKey The API key
101+
* @param file The log data to upload
102+
* @param options The additional information to upload with the log
103+
* @returns {Promise<LogUploadResponse>} The log upload response
104+
*/
105+
export async function uploadLog(
106+
apiKey: string,
107+
file: Blob,
108+
options: LogUploadRequest
109+
): Promise<LogUploadResponse> {
110+
const { title, map, updatelog = null, uploader = "node-logs-sdk" } = options;
111+
112+
if (!apiKey) {
113+
throw new Error("Expected a valid API key, got a nullish value instead");
114+
}
115+
116+
if (title) {
117+
throw new Error("Title cannot be empty!");
118+
}
119+
120+
const body = new FormData();
121+
const headers = new Headers([["Content-Type", "multipart/form-data"]]);
122+
123+
body.append("logfile", file);
124+
body.append("title", title);
125+
body.append("key", apiKey);
126+
body.append("uploader", uploader!);
127+
128+
if (updatelog) {
129+
body.append("updatelog", updatelog);
130+
}
131+
132+
if (map) {
133+
body.append("map", map);
134+
}
135+
136+
const response = await fetch(logsUploadUrl, {
137+
body,
138+
headers,
139+
});
140+
141+
return (await response.json()) as LogUploadResponse;
142+
}
143+
144+
/**
145+
* Gets the raw log file for a given log id
146+
* @param logId The log id
147+
* @returns {Promise<Blob>} The raw log file
148+
*/
149+
export async function getRawLog(logId: string): Promise<Blob> {
150+
if (!logId) {
151+
throw new Error("LogId cannot be empty!");
152+
}
153+
154+
const response = await fetch(getRawLogUrl(logId));
155+
156+
return await response.blob();
157+
}

javascript-sdk/logstf/api/mod.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Provides methods used to interact with the [logs.tf api](https://logs.tf/about)
3+
*
4+
* @module
5+
*/
6+
7+
export * from "./logstf.ts";

javascript-sdk/logstf/deno.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@tf2software/logstf",
3+
"version": "0.0.1-alpha1",
4+
"exports": {
5+
".": "./mod.ts",
6+
"./api": "./mod.ts",
7+
"./types": "./types/mod.ts"
8+
}
9+
}

javascript-sdk/logstf/mod.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* The [logs.tf](https://logs.tf/about) SDK
3+
*
4+
* This API provides both the types and methods to interact with the API
5+
*
6+
* @module
7+
*/
8+
9+
export * from "./types/mod.ts";
10+
export * from "./api/mod.ts";

node-sdk/lib/logstf-api-types/src/types/endpoints/logById.ts renamed to javascript-sdk/logstf/types/endpoints/logById.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { TeamType } from "types/enums/teamType";
2-
import type { PlayerInformation } from "types/playerInformation";
3-
import type { RoundEvent } from "types/roundEvent";
4-
import type { TeamInformation } from "types/teamInformation";
5-
import type { TeamRoundInfo } from "types/teamRoundInfo";
6-
import type { Tf2ClassMap } from "types/tf2ClassMap";
1+
import type { TeamType } from "../mod.ts";
2+
import type { PlayerInformation } from "../playerInformation.ts";
3+
import type { RoundEvent } from "../roundEvent.ts";
4+
import type { TeamInformation } from "../teamInformation.ts";
5+
import type { TeamRoundInfo } from "../teamRoundInfo.ts";
6+
import type { Tf2ClassMap } from "../tf2ClassMap.ts";
77

88
export type LogById = {
99
version: string;

node-sdk/lib/logstf-api-types/src/types/endpoints/logSearch.ts renamed to javascript-sdk/logstf/types/endpoints/logSearch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LogSearchRequest } from "./logSearchRequest";
1+
import type { LogSearchRequest } from "./logSearchRequest.ts";
22

33
export type LogSearchResponse = {
44
success: boolean;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* The options for uploading a log
3+
*/
4+
export type LogUploadRequest = {
5+
/**
6+
* The title of the request
7+
*/
8+
title: string;
9+
10+
/**
11+
* The map that was played
12+
*/
13+
map: string | null;
14+
15+
/**
16+
* (Optional- default null) The name of the uploader
17+
*/
18+
uploader: string | null;
19+
20+
/**
21+
* (Optional- default null) The log id to update instead of uploading a new log
22+
*/
23+
updatelog: string | null;
24+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from "./logById.ts";
2+
export * from "./logSearch.ts";
3+
export * from "./logSearchRequest.ts";
4+
export * from "./logUploadRequest.ts";
5+
export * from "./logUploadResponse.ts";
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./teamType.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* The team
3+
*/
4+
export enum TeamType {
5+
/**
6+
* RED team
7+
*/
8+
Red,
9+
10+
/**
11+
* BLU team
12+
*/
13+
Blue,
14+
}

javascript-sdk/logstf/types/mod.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Provides types used when interacting with the [logs.tf api](https://logs.tf/about)
3+
*
4+
* @module
5+
*/
6+
7+
export * from "./endpoints/mod.ts";
8+
export * from "./enums/mod.ts";
9+
10+
export * from "./classStats.ts";
11+
export * from "./medicStats.ts";
12+
export * from "./playerInformation.ts";
13+
export * from "./roundEvent.ts";
14+
export * from "./teamInformation.ts";
15+
export * from "./teamRoundInfo.ts";
16+
export * from "./tf2ClassMap.ts";

0 commit comments

Comments
 (0)