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.
- package/LICENSE +21 -0
- package/README.md +404 -0
- package/dist/cjs/SWCombine.js +120 -0
- package/dist/cjs/SWCombine.js.map +1 -0
- package/dist/cjs/auth/OAuthClient.js +195 -0
- package/dist/cjs/auth/OAuthClient.js.map +1 -0
- package/dist/cjs/auth/TokenManager.js +139 -0
- package/dist/cjs/auth/TokenManager.js.map +1 -0
- package/dist/cjs/auth/permissions.js +281 -0
- package/dist/cjs/auth/permissions.js.map +1 -0
- package/dist/cjs/auth/scopes.js +285 -0
- package/dist/cjs/auth/scopes.js.map +1 -0
- package/dist/cjs/http/HttpClient.js +216 -0
- package/dist/cjs/http/HttpClient.js.map +1 -0
- package/dist/cjs/http/errors.js +156 -0
- package/dist/cjs/http/errors.js.map +1 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/resources/ApiResource.js +44 -0
- package/dist/cjs/resources/ApiResource.js.map +1 -0
- package/dist/cjs/resources/BaseResource.js +33 -0
- package/dist/cjs/resources/BaseResource.js.map +1 -0
- package/dist/cjs/resources/CharacterResource.js +178 -0
- package/dist/cjs/resources/CharacterResource.js.map +1 -0
- package/dist/cjs/resources/DatacardResource.js +42 -0
- package/dist/cjs/resources/DatacardResource.js.map +1 -0
- package/dist/cjs/resources/EventsResource.js +42 -0
- package/dist/cjs/resources/EventsResource.js.map +1 -0
- package/dist/cjs/resources/FactionResource.js +162 -0
- package/dist/cjs/resources/FactionResource.js.map +1 -0
- package/dist/cjs/resources/GalaxyResource.js +184 -0
- package/dist/cjs/resources/GalaxyResource.js.map +1 -0
- package/dist/cjs/resources/InventoryResource.js +95 -0
- package/dist/cjs/resources/InventoryResource.js.map +1 -0
- package/dist/cjs/resources/LocationResource.js +20 -0
- package/dist/cjs/resources/LocationResource.js.map +1 -0
- package/dist/cjs/resources/MarketResource.js +44 -0
- package/dist/cjs/resources/MarketResource.js.map +1 -0
- package/dist/cjs/resources/NewsResource.js +109 -0
- package/dist/cjs/resources/NewsResource.js.map +1 -0
- package/dist/cjs/resources/TypesResource.js +75 -0
- package/dist/cjs/resources/TypesResource.js.map +1 -0
- package/dist/cjs/types/index.js +25 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/SWCombine.js +116 -0
- package/dist/esm/SWCombine.js.map +1 -0
- package/dist/esm/auth/OAuthClient.js +188 -0
- package/dist/esm/auth/OAuthClient.js.map +1 -0
- package/dist/esm/auth/TokenManager.js +135 -0
- package/dist/esm/auth/TokenManager.js.map +1 -0
- package/dist/esm/auth/permissions.js +275 -0
- package/dist/esm/auth/permissions.js.map +1 -0
- package/dist/esm/auth/scopes.js +274 -0
- package/dist/esm/auth/scopes.js.map +1 -0
- package/dist/esm/http/HttpClient.js +209 -0
- package/dist/esm/http/HttpClient.js.map +1 -0
- package/dist/esm/http/errors.js +152 -0
- package/dist/esm/http/errors.js.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/resources/ApiResource.js +40 -0
- package/dist/esm/resources/ApiResource.js.map +1 -0
- package/dist/esm/resources/BaseResource.js +29 -0
- package/dist/esm/resources/BaseResource.js.map +1 -0
- package/dist/esm/resources/CharacterResource.js +168 -0
- package/dist/esm/resources/CharacterResource.js.map +1 -0
- package/dist/esm/resources/DatacardResource.js +38 -0
- package/dist/esm/resources/DatacardResource.js.map +1 -0
- package/dist/esm/resources/EventsResource.js +38 -0
- package/dist/esm/resources/EventsResource.js.map +1 -0
- package/dist/esm/resources/FactionResource.js +153 -0
- package/dist/esm/resources/FactionResource.js.map +1 -0
- package/dist/esm/resources/GalaxyResource.js +175 -0
- package/dist/esm/resources/GalaxyResource.js.map +1 -0
- package/dist/esm/resources/InventoryResource.js +90 -0
- package/dist/esm/resources/InventoryResource.js.map +1 -0
- package/dist/esm/resources/LocationResource.js +16 -0
- package/dist/esm/resources/LocationResource.js.map +1 -0
- package/dist/esm/resources/MarketResource.js +39 -0
- package/dist/esm/resources/MarketResource.js.map +1 -0
- package/dist/esm/resources/NewsResource.js +103 -0
- package/dist/esm/resources/NewsResource.js.map +1 -0
- package/dist/esm/resources/TypesResource.js +69 -0
- package/dist/esm/resources/TypesResource.js.map +1 -0
- package/dist/esm/types/index.js +22 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/types/SWCombine.d.ts +66 -0
- package/dist/types/SWCombine.d.ts.map +1 -0
- package/dist/types/auth/OAuthClient.d.ts +48 -0
- package/dist/types/auth/OAuthClient.d.ts.map +1 -0
- package/dist/types/auth/TokenManager.d.ts +66 -0
- package/dist/types/auth/TokenManager.d.ts.map +1 -0
- package/dist/types/auth/permissions.d.ts +173 -0
- package/dist/types/auth/permissions.d.ts.map +1 -0
- package/dist/types/auth/scopes.d.ts +309 -0
- package/dist/types/auth/scopes.d.ts.map +1 -0
- package/dist/types/http/HttpClient.d.ts +64 -0
- package/dist/types/http/HttpClient.d.ts.map +1 -0
- package/dist/types/http/errors.d.ts +54 -0
- package/dist/types/http/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/resources/ApiResource.d.ts +56 -0
- package/dist/types/resources/ApiResource.d.ts.map +1 -0
- package/dist/types/resources/BaseResource.d.ts +16 -0
- package/dist/types/resources/BaseResource.d.ts.map +1 -0
- package/dist/types/resources/CharacterResource.d.ts +151 -0
- package/dist/types/resources/CharacterResource.d.ts.map +1 -0
- package/dist/types/resources/DatacardResource.d.ts +42 -0
- package/dist/types/resources/DatacardResource.d.ts.map +1 -0
- package/dist/types/resources/EventsResource.d.ts +34 -0
- package/dist/types/resources/EventsResource.d.ts.map +1 -0
- package/dist/types/resources/FactionResource.d.ts +166 -0
- package/dist/types/resources/FactionResource.d.ts.map +1 -0
- package/dist/types/resources/GalaxyResource.d.ts +134 -0
- package/dist/types/resources/GalaxyResource.d.ts.map +1 -0
- package/dist/types/resources/InventoryResource.d.ts +77 -0
- package/dist/types/resources/InventoryResource.d.ts.map +1 -0
- package/dist/types/resources/LocationResource.d.ts +18 -0
- package/dist/types/resources/LocationResource.d.ts.map +1 -0
- package/dist/types/resources/MarketResource.d.ts +34 -0
- package/dist/types/resources/MarketResource.d.ts.map +1 -0
- package/dist/types/resources/NewsResource.d.ts +54 -0
- package/dist/types/resources/NewsResource.d.ts.map +1 -0
- package/dist/types/resources/TypesResource.d.ts +72 -0
- package/dist/types/resources/TypesResource.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +296 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OAuth Scopes for SW Combine API
|
|
4
|
+
*
|
|
5
|
+
* This module defines all available OAuth scopes and provides utilities
|
|
6
|
+
* for requesting common scope combinations.
|
|
7
|
+
*
|
|
8
|
+
* @see https://www.swcombine.com/ws/developers/permissions/
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Scopes = exports.FactionInventoryScopes = exports.FactionScopes = exports.PersonalInventoryScopes = exports.MessageScopes = exports.CharacterScopes = void 0;
|
|
12
|
+
exports.getAllCharacterScopes = getAllCharacterScopes;
|
|
13
|
+
exports.getAllMessageScopes = getAllMessageScopes;
|
|
14
|
+
exports.getAllPersonalInventoryScopes = getAllPersonalInventoryScopes;
|
|
15
|
+
exports.getAllFactionScopes = getAllFactionScopes;
|
|
16
|
+
exports.getAllFactionInventoryScopes = getAllFactionInventoryScopes;
|
|
17
|
+
exports.getAllScopes = getAllScopes;
|
|
18
|
+
exports.getReadOnlyScopes = getReadOnlyScopes;
|
|
19
|
+
exports.getMinimalScopes = getMinimalScopes;
|
|
20
|
+
/**
|
|
21
|
+
* Character-related scopes
|
|
22
|
+
*/
|
|
23
|
+
exports.CharacterScopes = {
|
|
24
|
+
/** Solely provides the character name and ID for use by clients who want to verify a character's identity */
|
|
25
|
+
AUTH: 'CHARACTER_AUTH',
|
|
26
|
+
/** Read basic character information (UID, handle, image, race, gender, etc.) */
|
|
27
|
+
READ: 'CHARACTER_READ',
|
|
28
|
+
/** Read character HP and XP */
|
|
29
|
+
STATS: 'CHARACTER_STATS',
|
|
30
|
+
/** Read character privileges */
|
|
31
|
+
PRIVILEGES: 'CHARACTER_PRIVILEGES',
|
|
32
|
+
/** Read character skills */
|
|
33
|
+
SKILLS: 'CHARACTER_SKILLS',
|
|
34
|
+
/** Read character credit information */
|
|
35
|
+
CREDITS: 'CHARACTER_CREDITS',
|
|
36
|
+
/** Transfer character credits */
|
|
37
|
+
CREDITS_WRITE: 'CHARACTER_CREDITS_WRITE',
|
|
38
|
+
/** Read character force-related information (FP, FXP, regen rate, Force Meter) */
|
|
39
|
+
FORCE: 'CHARACTER_FORCE',
|
|
40
|
+
/** Read location information in-game */
|
|
41
|
+
LOCATION: 'CHARACTER_LOCATION',
|
|
42
|
+
/** Read character events */
|
|
43
|
+
EVENTS: 'CHARACTER_EVENTS',
|
|
44
|
+
/** Access all character information (includes all above) */
|
|
45
|
+
ALL: 'CHARACTER_ALL',
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Message-related scopes
|
|
49
|
+
*/
|
|
50
|
+
exports.MessageScopes = {
|
|
51
|
+
/** Read messages */
|
|
52
|
+
READ: 'MESSAGES_READ',
|
|
53
|
+
/** Send messages */
|
|
54
|
+
SEND: 'MESSAGES_SEND',
|
|
55
|
+
/** Delete messages */
|
|
56
|
+
DELETE: 'MESSAGES_DELETE',
|
|
57
|
+
/** All message permissions */
|
|
58
|
+
ALL: 'MESSAGES_ALL',
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Generate personal inventory scopes for a specific entity type
|
|
62
|
+
*/
|
|
63
|
+
function generatePersonalInventoryScopes(entityType, hasRename = true) {
|
|
64
|
+
const scopes = {};
|
|
65
|
+
scopes.READ = `PERSONAL_INV_${entityType}_READ`;
|
|
66
|
+
if (hasRename) {
|
|
67
|
+
scopes.RENAME = `PERSONAL_INV_${entityType}_RENAME`;
|
|
68
|
+
}
|
|
69
|
+
scopes.ASSIGN = `PERSONAL_INV_${entityType}_ASSIGN`;
|
|
70
|
+
if (hasRename) {
|
|
71
|
+
scopes.MAKEOVER = `PERSONAL_INV_${entityType}_MAKEOVER`;
|
|
72
|
+
}
|
|
73
|
+
scopes.TAGS_READ = `PERSONAL_INV_${entityType}_TAGS_READ`;
|
|
74
|
+
scopes.TAGS_WRITE = `PERSONAL_INV_${entityType}_TAGS_WRITE`;
|
|
75
|
+
scopes.ALL = `PERSONAL_INV_${entityType}_ALL`;
|
|
76
|
+
return scopes;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Personal inventory scopes
|
|
80
|
+
*/
|
|
81
|
+
exports.PersonalInventoryScopes = {
|
|
82
|
+
/** Overview of personal inventory */
|
|
83
|
+
OVERVIEW: 'PERSONAL_INV_OVERVIEW',
|
|
84
|
+
/** Personal ship scopes */
|
|
85
|
+
SHIPS: generatePersonalInventoryScopes('SHIPS'),
|
|
86
|
+
/** Personal vehicle scopes */
|
|
87
|
+
VEHICLES: generatePersonalInventoryScopes('VEHICLES'),
|
|
88
|
+
/** Personal station scopes */
|
|
89
|
+
STATIONS: generatePersonalInventoryScopes('STATIONS'),
|
|
90
|
+
/** Personal city scopes */
|
|
91
|
+
CITIES: generatePersonalInventoryScopes('CITIES'),
|
|
92
|
+
/** Personal facility scopes */
|
|
93
|
+
FACILITIES: generatePersonalInventoryScopes('FACILITIES'),
|
|
94
|
+
/** Personal planet scopes (no RENAME/MAKEOVER) */
|
|
95
|
+
PLANETS: generatePersonalInventoryScopes('PLANETS', false),
|
|
96
|
+
/** Personal item scopes */
|
|
97
|
+
ITEMS: generatePersonalInventoryScopes('ITEMS'),
|
|
98
|
+
/** Personal NPC scopes (no RENAME) */
|
|
99
|
+
NPCS: generatePersonalInventoryScopes('NPCS', false),
|
|
100
|
+
/** Personal droid scopes */
|
|
101
|
+
DROIDS: generatePersonalInventoryScopes('DROIDS'),
|
|
102
|
+
/** Personal material scopes (no ASSIGN) */
|
|
103
|
+
MATERIALS: {
|
|
104
|
+
READ: 'PERSONAL_INV_MATERIALS_READ',
|
|
105
|
+
RENAME: 'PERSONAL_INV_MATERIALS_RENAME',
|
|
106
|
+
MAKEOVER: 'PERSONAL_INV_MATERIALS_MAKEOVER',
|
|
107
|
+
TAGS_READ: 'PERSONAL_INV_MATERIALS_TAGS_READ',
|
|
108
|
+
TAGS_WRITE: 'PERSONAL_INV_MATERIALS_TAGS_WRITE',
|
|
109
|
+
ALL: 'PERSONAL_INV_MATERIALS_ALL',
|
|
110
|
+
},
|
|
111
|
+
/** Personal creature scopes */
|
|
112
|
+
CREATURES: generatePersonalInventoryScopes('CREATURES'),
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Faction management scopes
|
|
116
|
+
*/
|
|
117
|
+
exports.FactionScopes = {
|
|
118
|
+
/** Read faction information */
|
|
119
|
+
READ: 'FACTION_READ',
|
|
120
|
+
/** Read faction members */
|
|
121
|
+
MEMBERS: 'FACTION_MEMBERS',
|
|
122
|
+
/** Read faction stocks */
|
|
123
|
+
STOCKS: 'FACTION_STOCKS',
|
|
124
|
+
/** Read faction credits */
|
|
125
|
+
CREDITS_READ: 'FACTION_CREDITS_READ',
|
|
126
|
+
/** Write/transfer faction credits */
|
|
127
|
+
CREDITS_WRITE: 'FACTION_CREDITS_WRITE',
|
|
128
|
+
/** Read faction budgets */
|
|
129
|
+
BUDGETS_READ: 'FACTION_BUDGETS_READ',
|
|
130
|
+
/** Write faction budgets */
|
|
131
|
+
BUDGETS_WRITE: 'FACTION_BUDGETS_WRITE',
|
|
132
|
+
/** Read faction datacards */
|
|
133
|
+
DATACARDS_READ: 'FACTION_DATACARDS_READ',
|
|
134
|
+
/** Write faction datacards */
|
|
135
|
+
DATACARDS_WRITE: 'FACTION_DATACARDS_WRITE',
|
|
136
|
+
/** All faction permissions */
|
|
137
|
+
ALL: 'FACTION_ALL',
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Generate faction inventory scopes for a specific entity type
|
|
141
|
+
*/
|
|
142
|
+
function generateFactionInventoryScopes(entityType, hasRename = true) {
|
|
143
|
+
const scopes = {};
|
|
144
|
+
scopes.READ = `FACTION_INV_${entityType}_READ`;
|
|
145
|
+
if (hasRename) {
|
|
146
|
+
scopes.RENAME = `FACTION_INV_${entityType}_RENAME`;
|
|
147
|
+
}
|
|
148
|
+
scopes.ASSIGN = `FACTION_INV_${entityType}_ASSIGN`;
|
|
149
|
+
if (hasRename) {
|
|
150
|
+
scopes.MAKEOVER = `FACTION_INV_${entityType}_MAKEOVER`;
|
|
151
|
+
}
|
|
152
|
+
scopes.TAGS_READ = `FACTION_INV_${entityType}_TAGS_READ`;
|
|
153
|
+
scopes.TAGS_WRITE = `FACTION_INV_${entityType}_TAGS_WRITE`;
|
|
154
|
+
scopes.ALL = `FACTION_INV_${entityType}_ALL`;
|
|
155
|
+
return scopes;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Faction inventory scopes
|
|
159
|
+
*/
|
|
160
|
+
exports.FactionInventoryScopes = {
|
|
161
|
+
/** Overview of faction inventory */
|
|
162
|
+
OVERVIEW: 'FACTION_INV_OVERVIEW',
|
|
163
|
+
/** Faction ship scopes */
|
|
164
|
+
SHIPS: generateFactionInventoryScopes('SHIPS'),
|
|
165
|
+
/** Faction vehicle scopes */
|
|
166
|
+
VEHICLES: generateFactionInventoryScopes('VEHICLES'),
|
|
167
|
+
/** Faction station scopes */
|
|
168
|
+
STATIONS: generateFactionInventoryScopes('STATIONS'),
|
|
169
|
+
/** Faction city scopes */
|
|
170
|
+
CITIES: generateFactionInventoryScopes('CITIES'),
|
|
171
|
+
/** Faction facility scopes */
|
|
172
|
+
FACILITIES: generateFactionInventoryScopes('FACILITIES'),
|
|
173
|
+
/** Faction planet scopes (no RENAME/MAKEOVER) */
|
|
174
|
+
PLANETS: generateFactionInventoryScopes('PLANETS', false),
|
|
175
|
+
/** Faction item scopes */
|
|
176
|
+
ITEMS: generateFactionInventoryScopes('ITEMS'),
|
|
177
|
+
/** Faction NPC scopes (no RENAME) */
|
|
178
|
+
NPCS: generateFactionInventoryScopes('NPCS', false),
|
|
179
|
+
/** Faction droid scopes */
|
|
180
|
+
DROIDS: generateFactionInventoryScopes('DROIDS'),
|
|
181
|
+
/** Faction material scopes (no ASSIGN) */
|
|
182
|
+
MATERIALS: {
|
|
183
|
+
READ: 'FACTION_INV_MATERIALS_READ',
|
|
184
|
+
RENAME: 'FACTION_INV_MATERIALS_RENAME',
|
|
185
|
+
MAKEOVER: 'FACTION_INV_MATERIALS_MAKEOVER',
|
|
186
|
+
TAGS_READ: 'FACTION_INV_MATERIALS_TAGS_READ',
|
|
187
|
+
TAGS_WRITE: 'FACTION_INV_MATERIALS_TAGS_WRITE',
|
|
188
|
+
ALL: 'FACTION_INV_MATERIALS_ALL',
|
|
189
|
+
},
|
|
190
|
+
/** Faction creature scopes */
|
|
191
|
+
CREATURES: generateFactionInventoryScopes('CREATURES'),
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* All available scopes organized by category
|
|
195
|
+
*/
|
|
196
|
+
exports.Scopes = {
|
|
197
|
+
Character: exports.CharacterScopes,
|
|
198
|
+
Messages: exports.MessageScopes,
|
|
199
|
+
PersonalInventory: exports.PersonalInventoryScopes,
|
|
200
|
+
Faction: exports.FactionScopes,
|
|
201
|
+
FactionInventory: exports.FactionInventoryScopes,
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Helper function to get all character scopes
|
|
205
|
+
*/
|
|
206
|
+
function getAllCharacterScopes() {
|
|
207
|
+
return Object.values(exports.CharacterScopes);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Helper function to get all message scopes
|
|
211
|
+
*/
|
|
212
|
+
function getAllMessageScopes() {
|
|
213
|
+
return Object.values(exports.MessageScopes);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Helper function to get all personal inventory scopes
|
|
217
|
+
*/
|
|
218
|
+
function getAllPersonalInventoryScopes() {
|
|
219
|
+
const scopes = [exports.PersonalInventoryScopes.OVERVIEW];
|
|
220
|
+
// Add all entity-specific scopes
|
|
221
|
+
Object.entries(exports.PersonalInventoryScopes).forEach(([key, value]) => {
|
|
222
|
+
if (key !== 'OVERVIEW' && typeof value === 'object') {
|
|
223
|
+
scopes.push(...Object.values(value));
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return scopes;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Helper function to get all faction scopes
|
|
230
|
+
*/
|
|
231
|
+
function getAllFactionScopes() {
|
|
232
|
+
return Object.values(exports.FactionScopes);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Helper function to get all faction inventory scopes
|
|
236
|
+
*/
|
|
237
|
+
function getAllFactionInventoryScopes() {
|
|
238
|
+
const scopes = [exports.FactionInventoryScopes.OVERVIEW];
|
|
239
|
+
// Add all entity-specific scopes
|
|
240
|
+
Object.entries(exports.FactionInventoryScopes).forEach(([key, value]) => {
|
|
241
|
+
if (key !== 'OVERVIEW' && typeof value === 'object') {
|
|
242
|
+
scopes.push(...Object.values(value));
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return scopes;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get all available scopes (for comprehensive testing)
|
|
249
|
+
*/
|
|
250
|
+
function getAllScopes() {
|
|
251
|
+
return [
|
|
252
|
+
...getAllCharacterScopes(),
|
|
253
|
+
...getAllMessageScopes(),
|
|
254
|
+
...getAllPersonalInventoryScopes(),
|
|
255
|
+
...getAllFactionScopes(),
|
|
256
|
+
...getAllFactionInventoryScopes(),
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get basic read-only scopes (good for read-only integrations)
|
|
261
|
+
*/
|
|
262
|
+
function getReadOnlyScopes() {
|
|
263
|
+
return [
|
|
264
|
+
exports.CharacterScopes.READ,
|
|
265
|
+
exports.CharacterScopes.STATS,
|
|
266
|
+
exports.CharacterScopes.PRIVILEGES,
|
|
267
|
+
exports.CharacterScopes.SKILLS,
|
|
268
|
+
exports.CharacterScopes.CREDITS,
|
|
269
|
+
exports.CharacterScopes.FORCE,
|
|
270
|
+
exports.CharacterScopes.LOCATION,
|
|
271
|
+
exports.CharacterScopes.EVENTS,
|
|
272
|
+
exports.MessageScopes.READ,
|
|
273
|
+
exports.PersonalInventoryScopes.OVERVIEW,
|
|
274
|
+
exports.FactionScopes.READ,
|
|
275
|
+
exports.FactionScopes.MEMBERS,
|
|
276
|
+
exports.FactionInventoryScopes.OVERVIEW,
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Get minimal scopes for basic character info (authentication only)
|
|
281
|
+
*/
|
|
282
|
+
function getMinimalScopes() {
|
|
283
|
+
return [exports.CharacterScopes.AUTH, exports.CharacterScopes.READ];
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../../src/auth/scopes.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAmOH,sDAEC;AAKD,kDAEC;AAKD,sEAWC;AAKD,kDAEC;AAKD,oEAWC;AAKD,oCAQC;AAKD,8CAgBC;AAKD,4CAEC;AA1TD;;GAEG;AACU,QAAA,eAAe,GAAG;IAC7B,6GAA6G;IAC7G,IAAI,EAAE,gBAAgB;IACtB,gFAAgF;IAChF,IAAI,EAAE,gBAAgB;IACtB,+BAA+B;IAC/B,KAAK,EAAE,iBAAiB;IACxB,gCAAgC;IAChC,UAAU,EAAE,sBAAsB;IAClC,4BAA4B;IAC5B,MAAM,EAAE,kBAAkB;IAC1B,w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|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP client for making requests to SW Combine API
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpClient = void 0;
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const errors_js_1 = require("./errors.js");
|
|
12
|
+
/**
|
|
13
|
+
* HTTP client that handles requests, retries, and token refresh
|
|
14
|
+
*/
|
|
15
|
+
class HttpClient {
|
|
16
|
+
constructor(options, tokenManager) {
|
|
17
|
+
this.tokenManager = tokenManager;
|
|
18
|
+
this.maxRetries = options.maxRetries ?? 3;
|
|
19
|
+
this.retryDelay = options.retryDelay ?? 1000;
|
|
20
|
+
this.debug = options.debug ?? false;
|
|
21
|
+
// Create axios instance
|
|
22
|
+
this.axios = axios_1.default.create({
|
|
23
|
+
baseURL: options.baseURL ?? 'https://www.swcombine.com/ws/v2.0/',
|
|
24
|
+
timeout: options.timeout ?? 30000,
|
|
25
|
+
headers: {
|
|
26
|
+
'Accept': 'application/json',
|
|
27
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
// Set up interceptors
|
|
31
|
+
this.setupRequestInterceptor();
|
|
32
|
+
this.setupResponseInterceptor();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set up request interceptor to add auth token
|
|
36
|
+
*/
|
|
37
|
+
setupRequestInterceptor() {
|
|
38
|
+
this.axios.interceptors.request.use(async (config) => {
|
|
39
|
+
// Add access token if available
|
|
40
|
+
if (this.tokenManager) {
|
|
41
|
+
try {
|
|
42
|
+
const token = await this.tokenManager.getAccessToken();
|
|
43
|
+
if (token) {
|
|
44
|
+
// Try query parameter method instead of header
|
|
45
|
+
// SW Combine API docs say: "Access tokens are sent to a Resource in the HTTP
|
|
46
|
+
// Authorization header, or as a query string parameter"
|
|
47
|
+
config.params = config.params || {};
|
|
48
|
+
config.params.access_token = token;
|
|
49
|
+
if (this.debug) {
|
|
50
|
+
console.log(`[SWC SDK] Added auth token as query param: ${token.substring(0, 20)}...`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
if (this.debug) {
|
|
55
|
+
console.log(`[SWC SDK] No token available from TokenManager`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (this.debug) {
|
|
61
|
+
console.log(`[SWC SDK] Error getting token: ${error.message}`);
|
|
62
|
+
}
|
|
63
|
+
// Don't fail the request, just proceed without token
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (this.debug) {
|
|
67
|
+
console.log(`[SWC SDK] ${config.method?.toUpperCase()} ${config.url}`);
|
|
68
|
+
console.log(`[SWC SDK] Query params:`, config.params);
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}, (error) => {
|
|
72
|
+
return Promise.reject(error);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set up response interceptor to handle errors and retries
|
|
77
|
+
*/
|
|
78
|
+
setupResponseInterceptor() {
|
|
79
|
+
this.axios.interceptors.response.use((response) => {
|
|
80
|
+
// Extract data from swcapi wrapper if present
|
|
81
|
+
if (response.data && typeof response.data === 'object' && 'swcapi' in response.data) {
|
|
82
|
+
const swcapiData = response.data.swcapi;
|
|
83
|
+
// Get the first key's value (e.g., swcapi.character -> character data)
|
|
84
|
+
const keys = Object.keys(swcapiData);
|
|
85
|
+
if (keys.length === 1) {
|
|
86
|
+
response.data = swcapiData[keys[0]];
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// If multiple keys or no keys, return the swcapi object itself
|
|
90
|
+
response.data = swcapiData;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return response;
|
|
94
|
+
}, async (error) => {
|
|
95
|
+
const config = error.config;
|
|
96
|
+
// Handle 401 - attempt token refresh
|
|
97
|
+
if (error.response?.status === 401 && this.tokenManager) {
|
|
98
|
+
try {
|
|
99
|
+
await this.tokenManager.refreshToken();
|
|
100
|
+
// Retry the request with new token
|
|
101
|
+
return this.axios.request(config);
|
|
102
|
+
}
|
|
103
|
+
catch (refreshError) {
|
|
104
|
+
// Token refresh failed, throw auth error
|
|
105
|
+
throw errors_js_1.SWCError.fromHttpResponse(401, error.response?.data, error.response?.headers['x-request-id']);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Handle retryable errors
|
|
109
|
+
if (this.shouldRetry(error, config._retryCount ?? 0)) {
|
|
110
|
+
config._retryCount = (config._retryCount ?? 0) + 1;
|
|
111
|
+
// Wait before retrying (exponential backoff)
|
|
112
|
+
const delay = this.retryDelay * Math.pow(2, config._retryCount - 1);
|
|
113
|
+
await this.sleep(delay);
|
|
114
|
+
if (this.debug) {
|
|
115
|
+
console.log(`[SWC SDK] Retrying request (attempt ${config._retryCount}/${this.maxRetries})`);
|
|
116
|
+
}
|
|
117
|
+
return this.axios.request(config);
|
|
118
|
+
}
|
|
119
|
+
// Convert to SWCError
|
|
120
|
+
if (error.response) {
|
|
121
|
+
throw errors_js_1.SWCError.fromHttpResponse(error.response.status, error.response.data, error.response.headers['x-request-id']);
|
|
122
|
+
}
|
|
123
|
+
else if (error.request) {
|
|
124
|
+
throw errors_js_1.SWCError.fromNetworkError(error);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new errors_js_1.SWCError(error.message, {
|
|
128
|
+
type: 'unknown',
|
|
129
|
+
cause: error,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Determine if a request should be retried
|
|
136
|
+
*/
|
|
137
|
+
shouldRetry(error, retryCount) {
|
|
138
|
+
// Don't retry if we've exceeded max retries
|
|
139
|
+
if (retryCount >= this.maxRetries) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
// Network errors are retryable
|
|
143
|
+
if (!error.response) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
const status = error.response.status;
|
|
147
|
+
const responseData = error.response.data;
|
|
148
|
+
// Check if HTTP 400 is actually a rate limit error
|
|
149
|
+
const isRateLimitError = status === 400 &&
|
|
150
|
+
(responseData?.error === 'rate_limit_exceeded' ||
|
|
151
|
+
responseData?.message?.toLowerCase().includes('rate limit') ||
|
|
152
|
+
responseData?.error_description?.toLowerCase().includes('rate limit'));
|
|
153
|
+
// Retry rate limit errors (429 or 400 with rate limit content)
|
|
154
|
+
if (status === 429 || isRateLimitError) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
// Don't retry other 4xx errors
|
|
158
|
+
if (status >= 400 && status < 500) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
// Retry 5xx server errors
|
|
162
|
+
if (status >= 500) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Sleep for specified milliseconds
|
|
169
|
+
*/
|
|
170
|
+
sleep(ms) {
|
|
171
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Make a GET request
|
|
175
|
+
*/
|
|
176
|
+
async get(url, config) {
|
|
177
|
+
const response = await this.axios.get(url, config);
|
|
178
|
+
return response.data;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Make a POST request
|
|
182
|
+
*/
|
|
183
|
+
async post(url, data, config) {
|
|
184
|
+
const response = await this.axios.post(url, data, config);
|
|
185
|
+
return response.data;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Make a PUT request
|
|
189
|
+
*/
|
|
190
|
+
async put(url, data, config) {
|
|
191
|
+
const response = await this.axios.put(url, data, config);
|
|
192
|
+
return response.data;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Make a DELETE request
|
|
196
|
+
*/
|
|
197
|
+
async delete(url, config) {
|
|
198
|
+
const response = await this.axios.delete(url, config);
|
|
199
|
+
return response.data;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Make a custom request
|
|
203
|
+
*/
|
|
204
|
+
async request(config) {
|
|
205
|
+
const response = await this.axios.request(config);
|
|
206
|
+
return response.data;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Set token manager (useful for late initialization)
|
|
210
|
+
*/
|
|
211
|
+
setTokenManager(tokenManager) {
|
|
212
|
+
this.tokenManager = tokenManager;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.HttpClient = HttpClient;
|
|
216
|
+
//# sourceMappingURL=HttpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../../src/http/HttpClient.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,kDAKe;AACf,2CAAuC;AAWvC;;GAEG;AACH,MAAa,UAAU;IAOrB,YAAY,OAA0B,EAAE,YAA2B;QACjE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;QAC7C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QAEpC,wBAAwB;QACxB,IAAI,CAAC,KAAK,GAAG,eAAK,CAAC,MAAM,CAAC;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,oCAAoC;YAChE,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK;YACjC,OAAO,EAAE;gBACP,QAAQ,EAAE,kBAAkB;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AAC;QACrD,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,YAA0B;QACxC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AApPD,gCAoPC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error handling for SW Combine SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SWCError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Custom error class for SW Combine API errors
|
|
9
|
+
*/
|
|
10
|
+
class SWCError extends Error {
|
|
11
|
+
constructor(message, options) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'SWCError';
|
|
14
|
+
this.type = options.type;
|
|
15
|
+
this.statusCode = options.statusCode;
|
|
16
|
+
this.requestId = options.requestId;
|
|
17
|
+
this.response = options.response;
|
|
18
|
+
this.retryable = options.retryable ?? this.determineRetryable(options.type, options.statusCode);
|
|
19
|
+
this.retryAfter = options.retryAfter;
|
|
20
|
+
this.cause = options.cause;
|
|
21
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
22
|
+
if (Error.captureStackTrace) {
|
|
23
|
+
Error.captureStackTrace(this, SWCError);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Determine if an error is retryable based on type and status code
|
|
28
|
+
*/
|
|
29
|
+
determineRetryable(type, statusCode) {
|
|
30
|
+
// Network errors are always retryable
|
|
31
|
+
if (type === 'network') {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// Server errors (5xx) are retryable
|
|
35
|
+
if (type === 'server' || (statusCode && statusCode >= 500 && statusCode < 600)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
// Rate limit errors are technically retryable (with backoff)
|
|
39
|
+
if (type === 'rate_limit') {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
// Everything else is not retryable
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an error from an HTTP status code and response
|
|
47
|
+
*/
|
|
48
|
+
static fromHttpResponse(statusCode, response, requestId) {
|
|
49
|
+
let type;
|
|
50
|
+
let message;
|
|
51
|
+
// Check if this is a rate limit error (SW Combine uses HTTP 400 for rate limiting)
|
|
52
|
+
const isRateLimitError = statusCode === 400 &&
|
|
53
|
+
(response?.error === 'rate_limit_exceeded' ||
|
|
54
|
+
response?.message?.toLowerCase().includes('rate limit') ||
|
|
55
|
+
response?.error_description?.toLowerCase().includes('rate limit'));
|
|
56
|
+
// Determine error type from status code and content
|
|
57
|
+
if (isRateLimitError) {
|
|
58
|
+
type = 'rate_limit';
|
|
59
|
+
message = 'Rate limit exceeded. Please wait before making more requests.';
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
switch (statusCode) {
|
|
63
|
+
case 401:
|
|
64
|
+
type = 'auth';
|
|
65
|
+
message = 'Authentication failed. Check your credentials or token.';
|
|
66
|
+
break;
|
|
67
|
+
case 403:
|
|
68
|
+
type = 'auth';
|
|
69
|
+
message = 'Forbidden. You do not have permission to access this resource.';
|
|
70
|
+
break;
|
|
71
|
+
case 404:
|
|
72
|
+
type = 'not_found';
|
|
73
|
+
message = 'Resource not found.';
|
|
74
|
+
break;
|
|
75
|
+
case 400:
|
|
76
|
+
case 422:
|
|
77
|
+
type = 'validation';
|
|
78
|
+
message = 'Invalid request parameters.';
|
|
79
|
+
break;
|
|
80
|
+
case 429:
|
|
81
|
+
type = 'rate_limit';
|
|
82
|
+
message = 'Rate limit exceeded. Please wait before making more requests.';
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
if (statusCode >= 500) {
|
|
86
|
+
type = 'server';
|
|
87
|
+
message = 'Server error occurred. Please try again later.';
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
type = 'unknown';
|
|
91
|
+
message = 'An unknown error occurred.';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Use error message from response if available
|
|
96
|
+
if (response?.error_description) {
|
|
97
|
+
message = response.error_description;
|
|
98
|
+
}
|
|
99
|
+
else if (response?.message) {
|
|
100
|
+
message = response.message;
|
|
101
|
+
}
|
|
102
|
+
else if (response?.error) {
|
|
103
|
+
message = typeof response.error === 'string' ? response.error : message;
|
|
104
|
+
}
|
|
105
|
+
// Extract retry-after header for rate limit errors
|
|
106
|
+
const retryAfter = type === 'rate_limit' ? response?.retry_after : undefined;
|
|
107
|
+
return new SWCError(message, {
|
|
108
|
+
type,
|
|
109
|
+
statusCode,
|
|
110
|
+
requestId,
|
|
111
|
+
response,
|
|
112
|
+
retryAfter,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create an error from a network failure
|
|
117
|
+
*/
|
|
118
|
+
static fromNetworkError(error) {
|
|
119
|
+
return new SWCError(`Network error: ${error.message}`, {
|
|
120
|
+
type: 'network',
|
|
121
|
+
retryable: true,
|
|
122
|
+
cause: error,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Check if an error is a SWCError
|
|
127
|
+
*/
|
|
128
|
+
static isSWCError(error) {
|
|
129
|
+
return error instanceof SWCError;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get a user-friendly error message
|
|
133
|
+
*/
|
|
134
|
+
toUserFriendlyMessage() {
|
|
135
|
+
switch (this.type) {
|
|
136
|
+
case 'auth':
|
|
137
|
+
return 'Authentication failed. Please check your credentials and try again.';
|
|
138
|
+
case 'rate_limit':
|
|
139
|
+
return this.retryAfter
|
|
140
|
+
? `Rate limit exceeded. Please wait ${this.retryAfter} seconds before trying again.`
|
|
141
|
+
: 'Rate limit exceeded. Please wait before making more requests.';
|
|
142
|
+
case 'not_found':
|
|
143
|
+
return 'The requested resource was not found.';
|
|
144
|
+
case 'validation':
|
|
145
|
+
return 'Invalid request. Please check your parameters and try again.';
|
|
146
|
+
case 'server':
|
|
147
|
+
return 'A server error occurred. Please try again later.';
|
|
148
|
+
case 'network':
|
|
149
|
+
return 'Network connection failed. Please check your internet connection and try again.';
|
|
150
|
+
default:
|
|
151
|
+
return 'An unexpected error occurred. Please try again.';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.SWCError = SWCError;
|
|
156
|
+
//# sourceMappingURL=errors.js.map
|