swcombine-sdk 1.0.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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +404 -0
  3. package/dist/cjs/SWCombine.js +120 -0
  4. package/dist/cjs/SWCombine.js.map +1 -0
  5. package/dist/cjs/auth/OAuthClient.js +195 -0
  6. package/dist/cjs/auth/OAuthClient.js.map +1 -0
  7. package/dist/cjs/auth/TokenManager.js +139 -0
  8. package/dist/cjs/auth/TokenManager.js.map +1 -0
  9. package/dist/cjs/auth/permissions.js +281 -0
  10. package/dist/cjs/auth/permissions.js.map +1 -0
  11. package/dist/cjs/auth/scopes.js +285 -0
  12. package/dist/cjs/auth/scopes.js.map +1 -0
  13. package/dist/cjs/http/HttpClient.js +216 -0
  14. package/dist/cjs/http/HttpClient.js.map +1 -0
  15. package/dist/cjs/http/errors.js +156 -0
  16. package/dist/cjs/http/errors.js.map +1 -0
  17. package/dist/cjs/index.js +48 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/resources/ApiResource.js +44 -0
  20. package/dist/cjs/resources/ApiResource.js.map +1 -0
  21. package/dist/cjs/resources/BaseResource.js +33 -0
  22. package/dist/cjs/resources/BaseResource.js.map +1 -0
  23. package/dist/cjs/resources/CharacterResource.js +178 -0
  24. package/dist/cjs/resources/CharacterResource.js.map +1 -0
  25. package/dist/cjs/resources/DatacardResource.js +42 -0
  26. package/dist/cjs/resources/DatacardResource.js.map +1 -0
  27. package/dist/cjs/resources/EventsResource.js +42 -0
  28. package/dist/cjs/resources/EventsResource.js.map +1 -0
  29. package/dist/cjs/resources/FactionResource.js +162 -0
  30. package/dist/cjs/resources/FactionResource.js.map +1 -0
  31. package/dist/cjs/resources/GalaxyResource.js +184 -0
  32. package/dist/cjs/resources/GalaxyResource.js.map +1 -0
  33. package/dist/cjs/resources/InventoryResource.js +95 -0
  34. package/dist/cjs/resources/InventoryResource.js.map +1 -0
  35. package/dist/cjs/resources/LocationResource.js +20 -0
  36. package/dist/cjs/resources/LocationResource.js.map +1 -0
  37. package/dist/cjs/resources/MarketResource.js +44 -0
  38. package/dist/cjs/resources/MarketResource.js.map +1 -0
  39. package/dist/cjs/resources/NewsResource.js +109 -0
  40. package/dist/cjs/resources/NewsResource.js.map +1 -0
  41. package/dist/cjs/resources/TypesResource.js +75 -0
  42. package/dist/cjs/resources/TypesResource.js.map +1 -0
  43. package/dist/cjs/types/index.js +25 -0
  44. package/dist/cjs/types/index.js.map +1 -0
  45. package/dist/esm/SWCombine.js +116 -0
  46. package/dist/esm/SWCombine.js.map +1 -0
  47. package/dist/esm/auth/OAuthClient.js +188 -0
  48. package/dist/esm/auth/OAuthClient.js.map +1 -0
  49. package/dist/esm/auth/TokenManager.js +135 -0
  50. package/dist/esm/auth/TokenManager.js.map +1 -0
  51. package/dist/esm/auth/permissions.js +275 -0
  52. package/dist/esm/auth/permissions.js.map +1 -0
  53. package/dist/esm/auth/scopes.js +274 -0
  54. package/dist/esm/auth/scopes.js.map +1 -0
  55. package/dist/esm/http/HttpClient.js +209 -0
  56. package/dist/esm/http/HttpClient.js.map +1 -0
  57. package/dist/esm/http/errors.js +152 -0
  58. package/dist/esm/http/errors.js.map +1 -0
  59. package/dist/esm/index.js +15 -0
  60. package/dist/esm/index.js.map +1 -0
  61. package/dist/esm/resources/ApiResource.js +40 -0
  62. package/dist/esm/resources/ApiResource.js.map +1 -0
  63. package/dist/esm/resources/BaseResource.js +29 -0
  64. package/dist/esm/resources/BaseResource.js.map +1 -0
  65. package/dist/esm/resources/CharacterResource.js +168 -0
  66. package/dist/esm/resources/CharacterResource.js.map +1 -0
  67. package/dist/esm/resources/DatacardResource.js +38 -0
  68. package/dist/esm/resources/DatacardResource.js.map +1 -0
  69. package/dist/esm/resources/EventsResource.js +38 -0
  70. package/dist/esm/resources/EventsResource.js.map +1 -0
  71. package/dist/esm/resources/FactionResource.js +153 -0
  72. package/dist/esm/resources/FactionResource.js.map +1 -0
  73. package/dist/esm/resources/GalaxyResource.js +175 -0
  74. package/dist/esm/resources/GalaxyResource.js.map +1 -0
  75. package/dist/esm/resources/InventoryResource.js +90 -0
  76. package/dist/esm/resources/InventoryResource.js.map +1 -0
  77. package/dist/esm/resources/LocationResource.js +16 -0
  78. package/dist/esm/resources/LocationResource.js.map +1 -0
  79. package/dist/esm/resources/MarketResource.js +39 -0
  80. package/dist/esm/resources/MarketResource.js.map +1 -0
  81. package/dist/esm/resources/NewsResource.js +103 -0
  82. package/dist/esm/resources/NewsResource.js.map +1 -0
  83. package/dist/esm/resources/TypesResource.js +69 -0
  84. package/dist/esm/resources/TypesResource.js.map +1 -0
  85. package/dist/esm/types/index.js +22 -0
  86. package/dist/esm/types/index.js.map +1 -0
  87. package/dist/types/SWCombine.d.ts +66 -0
  88. package/dist/types/SWCombine.d.ts.map +1 -0
  89. package/dist/types/auth/OAuthClient.d.ts +48 -0
  90. package/dist/types/auth/OAuthClient.d.ts.map +1 -0
  91. package/dist/types/auth/TokenManager.d.ts +66 -0
  92. package/dist/types/auth/TokenManager.d.ts.map +1 -0
  93. package/dist/types/auth/permissions.d.ts +173 -0
  94. package/dist/types/auth/permissions.d.ts.map +1 -0
  95. package/dist/types/auth/scopes.d.ts +309 -0
  96. package/dist/types/auth/scopes.d.ts.map +1 -0
  97. package/dist/types/http/HttpClient.d.ts +64 -0
  98. package/dist/types/http/HttpClient.d.ts.map +1 -0
  99. package/dist/types/http/errors.d.ts +54 -0
  100. package/dist/types/http/errors.d.ts.map +1 -0
  101. package/dist/types/index.d.ts +11 -0
  102. package/dist/types/index.d.ts.map +1 -0
  103. package/dist/types/resources/ApiResource.d.ts +56 -0
  104. package/dist/types/resources/ApiResource.d.ts.map +1 -0
  105. package/dist/types/resources/BaseResource.d.ts +16 -0
  106. package/dist/types/resources/BaseResource.d.ts.map +1 -0
  107. package/dist/types/resources/CharacterResource.d.ts +151 -0
  108. package/dist/types/resources/CharacterResource.d.ts.map +1 -0
  109. package/dist/types/resources/DatacardResource.d.ts +42 -0
  110. package/dist/types/resources/DatacardResource.d.ts.map +1 -0
  111. package/dist/types/resources/EventsResource.d.ts +34 -0
  112. package/dist/types/resources/EventsResource.d.ts.map +1 -0
  113. package/dist/types/resources/FactionResource.d.ts +166 -0
  114. package/dist/types/resources/FactionResource.d.ts.map +1 -0
  115. package/dist/types/resources/GalaxyResource.d.ts +134 -0
  116. package/dist/types/resources/GalaxyResource.d.ts.map +1 -0
  117. package/dist/types/resources/InventoryResource.d.ts +77 -0
  118. package/dist/types/resources/InventoryResource.d.ts.map +1 -0
  119. package/dist/types/resources/LocationResource.d.ts +18 -0
  120. package/dist/types/resources/LocationResource.d.ts.map +1 -0
  121. package/dist/types/resources/MarketResource.d.ts +34 -0
  122. package/dist/types/resources/MarketResource.d.ts.map +1 -0
  123. package/dist/types/resources/NewsResource.d.ts +54 -0
  124. package/dist/types/resources/NewsResource.d.ts.map +1 -0
  125. package/dist/types/resources/TypesResource.d.ts +72 -0
  126. package/dist/types/resources/TypesResource.d.ts.map +1 -0
  127. package/dist/types/types/index.d.ts +296 -0
  128. package/dist/types/types/index.d.ts.map +1 -0
  129. package/package.json +75 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
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,404 @@
1
+ # SW Combine SDK for Node.js
2
+
3
+ <div align="center">
4
+
5
+ **Comprehensive TypeScript SDK for the Star Wars Combine API v2.0**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/swcombine-sdk.svg)](https://www.npmjs.com/package/swcombine-sdk)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+
11
+ [Features](#features) •
12
+ [Installation](#installation) •
13
+ [Quick Start](#quick-start) •
14
+ [Documentation](#documentation) •
15
+ [Examples](#examples)
16
+
17
+ </div>
18
+
19
+ ## Features
20
+
21
+ - ✨ **Full API Coverage** - All 60+ endpoints across 11 resource categories
22
+ - 🔐 **OAuth 2.0 Built-in** - Complete OAuth flow with automatic token refresh
23
+ - 📘 **TypeScript First** - Full type definitions with IntelliSense support
24
+ - 🎯 **Type-Safe Scopes** - 230+ OAuth scope constants with autocomplete
25
+ - 🔄 **Automatic Retries** - Exponential backoff for failed requests
26
+ - 🌐 **Modern & Universal** - ES Modules + CommonJS, Node.js 18+
27
+ - 🛠️ **Developer Tools** - Helper scripts for OAuth and testing
28
+ - 📦 **Zero Dependencies** (except axios)
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install swcombine-sdk
34
+ # or
35
+ yarn add swcombine-sdk
36
+ # or
37
+ pnpm add swcombine-sdk
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ### 1. Initialize the Client
43
+
44
+ ```typescript
45
+ import { SWCombine } from 'swcombine-sdk';
46
+
47
+ const client = new SWCombine({
48
+ clientId: process.env.SWC_CLIENT_ID!,
49
+ clientSecret: process.env.SWC_CLIENT_SECRET!,
50
+ accessToken: process.env.SWC_ACCESS_TOKEN, // Optional
51
+ });
52
+ ```
53
+
54
+ ### 2. Make API Calls
55
+
56
+ ```typescript
57
+ // Get public character information (no auth required)
58
+ const character = await client.character.getByHandle({
59
+ handle: 'character-handle',
60
+ });
61
+
62
+ console.log(character.uid); // "1:12345"
63
+ console.log(character.name); // "Character Name"
64
+ ```
65
+
66
+ ### 3. Authenticated Endpoints
67
+
68
+ ```typescript
69
+ // For authenticated endpoints, provide an access token
70
+ const authenticatedClient = new SWCombine({
71
+ clientId: process.env.SWC_CLIENT_ID!,
72
+ clientSecret: process.env.SWC_CLIENT_SECRET!,
73
+ accessToken: process.env.SWC_ACCESS_TOKEN!,
74
+ });
75
+
76
+ // Get character details
77
+ const character = await authenticatedClient.character.get({
78
+ uid: '1:12345',
79
+ });
80
+
81
+ // Get character messages
82
+ const messages = await authenticatedClient.character.messages.list({
83
+ uid: '1:12345',
84
+ mode: 'received',
85
+ });
86
+
87
+ // Get faction information
88
+ const faction = await authenticatedClient.faction.get({
89
+ uid: '20:123',
90
+ });
91
+ ```
92
+
93
+ ## OAuth Authentication
94
+
95
+ ### Quick OAuth Setup
96
+
97
+ Use the included helper script to get an access token:
98
+
99
+ ```bash
100
+ # 1. Add your credentials to .env
101
+ echo "SWC_CLIENT_ID=your_client_id" >> .env
102
+ echo "SWC_CLIENT_SECRET=your_client_secret" >> .env
103
+
104
+ # 2. Run the OAuth helper
105
+ npm run get-token
106
+
107
+ # 3. Visit http://localhost:3000 in your browser
108
+ # 4. Authorize the app and copy the token to .env
109
+ ```
110
+
111
+ ### Manual OAuth Flow
112
+
113
+ ```typescript
114
+ import { SWCombine, CharacterScopes, MessageScopes } from 'swcombine-sdk';
115
+
116
+ const client = new SWCombine({
117
+ clientId: 'your-client-id',
118
+ clientSecret: 'your-client-secret',
119
+ redirectUri: 'http://localhost:3000/callback',
120
+ accessType: 'offline', // Get refresh token
121
+ });
122
+
123
+ // 1. Generate authorization URL
124
+ const authUrl = client.auth.getAuthorizationUrl({
125
+ scopes: [
126
+ CharacterScopes.READ,
127
+ CharacterScopes.STATS,
128
+ MessageScopes.READ,
129
+ MessageScopes.SEND,
130
+ ],
131
+ state: 'random-csrf-token',
132
+ });
133
+
134
+ // 2. Redirect user to authUrl...
135
+
136
+ // 3. Handle callback
137
+ const result = await client.auth.handleCallback(req.query);
138
+
139
+ if (result.success) {
140
+ const token = result.token!;
141
+ console.log('Access Token:', token.accessToken);
142
+ console.log('Refresh Token:', token.refreshToken);
143
+ }
144
+ ```
145
+
146
+ ## Type-Safe OAuth Scopes
147
+
148
+ ```typescript
149
+ import {
150
+ CharacterScopes,
151
+ MessageScopes,
152
+ Scopes,
153
+ getAllScopes,
154
+ getReadOnlyScopes,
155
+ } from 'swcombine-sdk';
156
+
157
+ // Use constants with autocomplete
158
+ const scopes = [
159
+ CharacterScopes.READ, // ✓ TypeScript suggests all scopes
160
+ CharacterScopes.STATS,
161
+ MessageScopes.SEND,
162
+ Scopes.PersonalInventory.SHIPS.READ,
163
+ ];
164
+
165
+ // Or use helpers
166
+ const readOnly = getReadOnlyScopes();
167
+ const everything = getAllScopes();
168
+ ```
169
+
170
+ See [OAuth Scopes Guide](docs/SCOPES.md) for all 230+ available scopes.
171
+
172
+ ## API Resources
173
+
174
+ The SDK provides access to all SW Combine API resources:
175
+
176
+ ### Characters
177
+
178
+ ```typescript
179
+ // Public endpoints
180
+ await client.character.getByHandle({ handle: 'character-handle' });
181
+
182
+ // Authenticated endpoints
183
+ await client.character.get({ uid: '1:12345' });
184
+ await client.character.skills.list({ uid: '1:12345' });
185
+ await client.character.privileges.list({ uid: '1:12345' });
186
+ await client.character.credits.get({ uid: '1:12345' });
187
+ await client.character.messages.list({ uid: '1:12345', mode: 'received' });
188
+ await client.character.permissions.list({ uid: '1:12345' });
189
+ ```
190
+
191
+ ### Factions
192
+
193
+ ```typescript
194
+ await client.faction.list();
195
+ await client.faction.get({ uid: '20:123' });
196
+ await client.faction.members.list({ uid: '20:123' });
197
+ await client.faction.budgets.list({ uid: '20:123' });
198
+ ```
199
+
200
+ ### Inventory
201
+
202
+ ```typescript
203
+ await client.inventory.get({ uid: '1:12345' });
204
+ await client.inventory.entities.list({
205
+ uid: '1:12345',
206
+ entityType: 'vehicle',
207
+ assignType: 'pilot',
208
+ });
209
+ ```
210
+
211
+ ### Galaxy
212
+
213
+ ```typescript
214
+ await client.galaxy.systems.list();
215
+ await client.galaxy.planets.list();
216
+ await client.galaxy.sectors.list();
217
+ ```
218
+
219
+ ### Events, Location, Datacards, and More
220
+
221
+ ```typescript
222
+ await client.events.list({ eventMode: 'character', eventType: 'all' });
223
+ await client.location.get({ entityType: 'character', uid: '1:12345' });
224
+ await client.datacard.list({ factionId: '20:123' });
225
+ await client.market.listings.list();
226
+ await client.news.list();
227
+ await client.types.races.list();
228
+ ```
229
+
230
+ See [API Documentation](docs/API.md) for complete reference.
231
+
232
+ ## Error Handling
233
+
234
+ ```typescript
235
+ import { SWCError } from 'swcombine-sdk';
236
+
237
+ try {
238
+ const character = await client.character.get({ uid: '1:12345' });
239
+ } catch (error) {
240
+ if (error instanceof SWCError) {
241
+ console.error('Status:', error.statusCode); // 404
242
+ console.error('Message:', error.message); // "Resource not found"
243
+ console.error('Type:', error.type); // "not_found"
244
+ console.error('Retryable:', error.retryable); // false
245
+ }
246
+ }
247
+ ```
248
+
249
+ ## TypeScript Support
250
+
251
+ Full TypeScript support with intelligent type inference:
252
+
253
+ ```typescript
254
+ // Types are automatically inferred
255
+ const character = await client.character.get({ uid: '1:12345' });
256
+ // character: Character
257
+
258
+ // Request parameters are typed
259
+ await client.character.messages.list({
260
+ uid: '1:12345',
261
+ mode: 'received', // TypeScript knows valid values
262
+ // mode: 'invalid', // ❌ TypeScript error
263
+ });
264
+ ```
265
+
266
+ ## Configuration Options
267
+
268
+ ```typescript
269
+ interface ClientConfig {
270
+ // Required OAuth credentials
271
+ clientId: string;
272
+ clientSecret: string;
273
+
274
+ // Optional authentication
275
+ accessToken?: string;
276
+ refreshToken?: string;
277
+
278
+ // Optional OAuth settings
279
+ redirectUri?: string;
280
+ accessType?: 'online' | 'offline';
281
+
282
+ // Optional HTTP settings
283
+ baseURL?: string; // Default: https://www.swcombine.com/ws/v2.0/
284
+ timeout?: number; // Default: 30000 (30 seconds)
285
+ maxRetries?: number; // Default: 3
286
+ retryDelay?: number; // Default: 1000ms
287
+ debug?: boolean; // Default: false
288
+ }
289
+ ```
290
+
291
+ ## Examples
292
+
293
+ See the [examples](examples/) directory for complete working examples:
294
+
295
+ - **[OAuth Scopes](examples/oauth-scopes-example.ts)** - 10 examples of scope usage
296
+
297
+ ### Basic Usage
298
+
299
+ ```typescript
300
+ import { SWCombine } from 'swcombine-sdk';
301
+
302
+ const client = new SWCombine({
303
+ clientId: process.env.SWC_CLIENT_ID!,
304
+ clientSecret: process.env.SWC_CLIENT_SECRET!,
305
+ });
306
+
307
+ // Get character info
308
+ const character = await client.character.getByHandle({
309
+ handle: 'character-name',
310
+ });
311
+
312
+ console.log(`${character.name} (${character.uid})`);
313
+ ```
314
+
315
+ ## Developer Tools
316
+
317
+ ### Get OAuth Token
318
+
319
+ Interactive OAuth flow to obtain access tokens:
320
+
321
+ ```bash
322
+ npm run get-token
323
+ ```
324
+
325
+ ### Get Character UID
326
+
327
+ Quickly get a character's UID from their handle:
328
+
329
+ ```bash
330
+ npm run get-character-uid YourHandle
331
+ ```
332
+
333
+ ### Run Integration Tests
334
+
335
+ ```bash
336
+ npm run test:integration
337
+ ```
338
+
339
+ ## Documentation
340
+
341
+ - **[Getting Started Guide](docs/GETTING_STARTED.md)** - Detailed setup and usage
342
+ - **[Authentication Guide](docs/AUTHENTICATION.md)** - OAuth 2.0 setup and token management
343
+ - **[OAuth Scopes Reference](docs/SCOPES.md)** - Complete scope documentation
344
+ - **[API Reference](docs/API.md)** - Detailed API endpoint documentation
345
+ - **[Examples](examples/)** - Working code examples
346
+
347
+ ## Development
348
+
349
+ ```bash
350
+ # Install dependencies
351
+ npm install
352
+
353
+ # Build
354
+ npm run build
355
+
356
+ # Run tests
357
+ npm test
358
+
359
+ # Run integration tests
360
+ npm run test:integration
361
+
362
+ # Lint
363
+ npm run lint
364
+
365
+ # Format code
366
+ npm run format
367
+ ```
368
+
369
+ ## Requirements
370
+
371
+ - Node.js 18 or higher
372
+ - TypeScript 5.0 or higher (for TypeScript projects)
373
+
374
+ ## Links
375
+
376
+ - [SW Combine API Documentation](https://www.swcombine.com/ws/developers/)
377
+ - [npm Package](https://www.npmjs.com/package/swcombine-sdk)
378
+ - [GitHub Repository](https://github.com/yourusername/swcombine-sdk-nodejs)
379
+
380
+ ## License
381
+
382
+ MIT © [Your Name]
383
+
384
+ ## Contributing
385
+
386
+ Contributions are welcome! Please:
387
+
388
+ 1. Fork the repository
389
+ 2. Create a feature branch
390
+ 3. Make your changes
391
+ 4. Add tests if applicable
392
+ 5. Submit a pull request
393
+
394
+ ## Support
395
+
396
+ - 📖 Check the [documentation](docs/)
397
+ - 💬 Submit issues on [GitHub](https://github.com/yourusername/swcombine-sdk-nodejs/issues)
398
+ - 📧 Contact support
399
+
400
+ ---
401
+
402
+ <div align="center">
403
+ Made with ❤️ for the Star Wars Combine community
404
+ </div>
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ /**
3
+ * Main SW Combine SDK client
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SWCombine = void 0;
7
+ const HttpClient_js_1 = require("./http/HttpClient.js");
8
+ const OAuthClient_js_1 = require("./auth/OAuthClient.js");
9
+ const TokenManager_js_1 = require("./auth/TokenManager.js");
10
+ // Import all resource classes
11
+ const ApiResource_js_1 = require("./resources/ApiResource.js");
12
+ const CharacterResource_js_1 = require("./resources/CharacterResource.js");
13
+ const FactionResource_js_1 = require("./resources/FactionResource.js");
14
+ const GalaxyResource_js_1 = require("./resources/GalaxyResource.js");
15
+ const InventoryResource_js_1 = require("./resources/InventoryResource.js");
16
+ const MarketResource_js_1 = require("./resources/MarketResource.js");
17
+ const NewsResource_js_1 = require("./resources/NewsResource.js");
18
+ const TypesResource_js_1 = require("./resources/TypesResource.js");
19
+ const EventsResource_js_1 = require("./resources/EventsResource.js");
20
+ const LocationResource_js_1 = require("./resources/LocationResource.js");
21
+ const DatacardResource_js_1 = require("./resources/DatacardResource.js");
22
+ /**
23
+ * Main SW Combine SDK client
24
+ */
25
+ class SWCombine {
26
+ constructor(config) {
27
+ this.config = config;
28
+ // Initialize token manager
29
+ this.tokenManager = new TokenManager_js_1.TokenManager(config.token);
30
+ // Initialize OAuth client
31
+ this.oauthClient = new OAuthClient_js_1.OAuthClient({
32
+ clientId: config.clientId,
33
+ clientSecret: config.clientSecret,
34
+ redirectUri: config.redirectUri,
35
+ accessType: config.accessType,
36
+ });
37
+ // Set up token refresh callback
38
+ this.tokenManager.setRefreshCallback(async () => {
39
+ const refreshToken = this.tokenManager.getRefreshToken();
40
+ if (!refreshToken) {
41
+ throw new Error('No refresh token available');
42
+ }
43
+ return this.oauthClient.refreshToken(refreshToken);
44
+ });
45
+ // Initialize HTTP client
46
+ this.http = new HttpClient_js_1.HttpClient({
47
+ baseURL: config.baseURL,
48
+ timeout: config.timeout,
49
+ maxRetries: config.maxRetries,
50
+ retryDelay: config.retryDelay,
51
+ debug: config.debug,
52
+ }, this.tokenManager);
53
+ // Initialize all resources
54
+ this.api = new ApiResource_js_1.ApiResource(this.http);
55
+ this.character = new CharacterResource_js_1.CharacterResource(this.http);
56
+ this.faction = new FactionResource_js_1.FactionResource(this.http);
57
+ this.galaxy = new GalaxyResource_js_1.GalaxyResource(this.http);
58
+ this.inventory = new InventoryResource_js_1.InventoryResource(this.http);
59
+ this.market = new MarketResource_js_1.MarketResource(this.http);
60
+ this.news = new NewsResource_js_1.NewsResource(this.http);
61
+ this.types = new TypesResource_js_1.TypesResource(this.http);
62
+ this.events = new EventsResource_js_1.EventsResource(this.http);
63
+ this.location = new LocationResource_js_1.LocationResource(this.http);
64
+ this.datacard = new DatacardResource_js_1.DatacardResource(this.http);
65
+ // Set up auth operations
66
+ this.auth = {
67
+ getAuthorizationUrl: (options) => {
68
+ return this.oauthClient.getAuthorizationUrl(options);
69
+ },
70
+ handleCallback: async (query) => {
71
+ const result = await this.oauthClient.handleCallback(query);
72
+ if (result.success && result.token) {
73
+ this.tokenManager.setToken(result.token);
74
+ }
75
+ return result;
76
+ },
77
+ revokeToken: async (refreshToken) => {
78
+ return this.oauthClient.revokeToken(refreshToken);
79
+ },
80
+ };
81
+ }
82
+ /**
83
+ * Set the access token
84
+ */
85
+ setToken(token) {
86
+ this.tokenManager.setToken(token);
87
+ }
88
+ /**
89
+ * Get the current token
90
+ */
91
+ getToken() {
92
+ return this.tokenManager.getToken();
93
+ }
94
+ /**
95
+ * Clear the token
96
+ */
97
+ clearToken() {
98
+ this.tokenManager.clear();
99
+ }
100
+ /**
101
+ * Manually refresh the token
102
+ */
103
+ async refreshToken() {
104
+ await this.tokenManager.refreshToken();
105
+ }
106
+ /**
107
+ * Check if token is expired
108
+ */
109
+ isTokenExpired() {
110
+ return this.tokenManager.isExpired();
111
+ }
112
+ /**
113
+ * Check if refresh token is available
114
+ */
115
+ hasRefreshToken() {
116
+ return this.tokenManager.hasRefreshToken();
117
+ }
118
+ }
119
+ exports.SWCombine = SWCombine;
120
+ //# sourceMappingURL=SWCombine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SWCombine.js","sourceRoot":"","sources":["../../src/SWCombine.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,wDAAkD;AAClD,0DAAoD;AACpD,4DAAsD;AAStD,8BAA8B;AAC9B,+DAAyD;AACzD,2EAAqE;AACrE,uEAAiE;AACjE,qEAA+D;AAC/D,2EAAqE;AACrE,qEAA+D;AAC/D,iEAA2D;AAC3D,mEAA6D;AAC7D,qEAA+D;AA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