torn-client 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Neon0404
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # Torn API Client
2
+
3
+
4
+ [![API Compatibility](https://img.shields.io/badge/Torn%20API-3.0.0-62a03f)](https://www.torn.com/api.html)
5
+ [![NPM Version](https://img.shields.io/npm/v/torn-client.svg)](https://www.npmjs.com/package/torn-client)
6
+ [![License](https://img.shields.io/npm/l/torn-client?color=62a03f)](https://github.com/neon0404/torn-client/blob/main/LICENSE)
7
+ [![PRs](https://img.shields.io/badge/PRs-welcome-blue)](https://github.com/neon0404/torn-client/pulls)
8
+
9
+ A TypeScript-first, auto-generated client for the [Torn City v2 API](https://www.torn.com/swagger.php)
10
+
11
+ This client provides full type safety, built-in rate limiting and automatic multi-key balancing to simplify interactions with the Torn API
12
+
13
+ > **⚠️ Warning**
14
+ > The Torn v2 API is under active development and changes frequently
15
+ > This client is also a work in progress and may contain bugs
16
+ >
17
+ > Some multi-selection endpoints like `/user` - are not yet fully tested and may behave unexpectedly
18
+
19
+
20
+ ## Features
21
+
22
+ - **Fully Typed**: Provides strong type safety and autocompletion for all API methods and responses
23
+ - **Cross-Environment**: Works seamlessly in both Node.js and browser environments
24
+ - **Zero Dependencies**: No external dependencies, ensuring a lightweight footprint and easy integration
25
+ - **Multi-Key Management**: Automatically balances requests across multiple API keys using round-robin or random strategies
26
+ - **Built-in Rate Limiting**: Avoids hitting the API limit by auto-delaying requests
27
+ - **Robust Pagination**: Simple `.next()` and `.prev()` methods are always available on paginated API responses
28
+ - **Auto-Generated**: The client is generated from the official OpenAPI specification, ensuring it stays up-to-date with API changes
29
+
30
+ ## Installation
31
+
32
+ ```sh
33
+ # Using npm
34
+ npm install torn-client
35
+
36
+ # Using yarn
37
+ yarn add torn-client
38
+
39
+ # Using pnpm
40
+ pnpm add torn-client
41
+
42
+ ```
43
+ You can also use `torn-client` directly in a browser without any build tools by importing it from a CDN like [unpkg](https://unpkg.com/)
44
+
45
+ ```html
46
+ <script type="module">
47
+ import { TornAPI, TornApiError } from 'https://unpkg.com/torn-client/dist/index.mjs';
48
+
49
+ const client = new TornAPI({ apiKeys: ['YOUR_API_KEY'] });
50
+ </script>
51
+ ```
52
+
53
+ ## Quick Start
54
+
55
+ ```ts
56
+ import { TornAPI } from 'torn-client';
57
+
58
+ // Initialize the client with your API keys
59
+ const client = new TornAPI({
60
+ apiKeys: ['YOUR_API_KEY'],
61
+ comment: 'MyTornApp',
62
+ });
63
+
64
+ // Example: Fetch a user's profile using a context method
65
+ async function getUserProfile() {
66
+ try {
67
+ const user = await client.user.withId(1).get();
68
+ console.log(user.name, user.level, user.gender);
69
+ } catch (error) {
70
+ console.error('Failed to fetch user profile:', error);
71
+ }
72
+ }
73
+
74
+ getUserProfile();
75
+ ```
76
+
77
+ ## Usage with Context
78
+
79
+ The client separates general calls from ID-based ones
80
+
81
+ **Global Call**
82
+ ```ts
83
+ // Fetches the Hall of Fame for factions, sorted by respect
84
+ const factionHof = await client.torn.factionhof({ cat: 'respect' });
85
+ ```
86
+
87
+ **Context-Specific Call**
88
+ ```ts
89
+ // All subsequent calls are now in the context of user ID 1
90
+ const userContext = client.user.withId(1);
91
+
92
+ // Fetch multiple details for the same user without repeating the ID
93
+ const profile = await userContext.get();
94
+ const personalStats = await userContext.personalstats({ cat: 'all' });
95
+ const properties = await userContext.properties();
96
+ ```
97
+ ## Documentation
98
+
99
+ Full API client reference is available at the [Torn Client Docs](https://neon0404.github.io/torn-client/)
100
+ For information about Torn API endpoints and parameters, see the [official Torn API v2 documentation](https://www.torn.com/swagger.php)
101
+
102
+ ## Contributing
103
+
104
+ Contributions, issues, and feature requests are welcome!
105
+ Please feel free to open an issue or submit a pull request on GitHub
106
+ Please read [contributing guide](https://github.com/neon0404/torn-client/blob/main/CONTRIBUTING.md) first
107
+
108
+ ## Contact
109
+
110
+ Got a question? [Open an issue](https://github.com/neon0404/torn-client/issues/new) with the **"question"** label
111
+ You can also contact me in **Torn:** [Neon](https://www.torn.com/profiles.php?XID=3772610) or on **Discord:** `neon0404`