@medrunner/api-client 0.0.1-rc.1

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/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Medrunner API Client
2
+ This typescript library acts as a client for the Medrunner API.
3
+
4
+ ## Getting Started
5
+
6
+ ```ts
7
+ import MedrunnerApiClient from "@medrunner/api-client";
8
+
9
+ const apiConfig = {
10
+ baseUrl: "https://api.medrunner.space",
11
+ token: () => "MY_API_TOKEN",
12
+ };
13
+
14
+ const api = MedrunnerApiClient.buildClient(apiConfig);
15
+ const self = await api.client.get();
16
+
17
+ console.log(self)
18
+ ```
@@ -0,0 +1,444 @@
1
+ import { Logger } from 'ts-log';
2
+ import { HubConnection } from '@microsoft/signalr';
3
+
4
+ type Func<T> = () => T;
5
+ type AsyncProvider<T> = Func<Promise<T>>;
6
+ type AsyncAction<T> = (arg: T) => Promise<void>;
7
+ type HeaderProvider<T extends Headers = Headers> = AsyncProvider<T>;
8
+ type Headers = {
9
+ [key: string]: unknown;
10
+ };
11
+
12
+ interface DbItem {
13
+ id: string;
14
+ created: string;
15
+ updated: string;
16
+ }
17
+
18
+ interface ApiToken extends DbItem {
19
+ userId: string;
20
+ name: string;
21
+ expirationDate?: number;
22
+ lastUsed?: string;
23
+ }
24
+
25
+ interface ApiResponse<T = unknown> {
26
+ success: boolean;
27
+ data?: T;
28
+ errorMessage?: string;
29
+ statusCode?: number;
30
+ }
31
+
32
+ interface TokenGrant {
33
+ accessToken: string;
34
+ refreshToken: string;
35
+ }
36
+
37
+ interface ApiConfig {
38
+ baseUrl: string;
39
+ accessToken?: string;
40
+ refreshToken?: string;
41
+ }
42
+
43
+ declare class TokenManager extends ApiEndpoint {
44
+ private readonly refreshCallback?;
45
+ private accessToken?;
46
+ private refreshToken?;
47
+ constructor(config: ApiConfig, refreshCallback?: AsyncAction<TokenGrant> | undefined, log?: Logger, headerProvider?: HeaderProvider);
48
+ protected endpoint(): string;
49
+ getAccessToken(): Promise<string | undefined>;
50
+ private fetchToken;
51
+ private static getJwtFromAccessToken;
52
+ }
53
+
54
+ declare abstract class ApiEndpoint {
55
+ readonly baseUrl: string;
56
+ readonly tokenManager: TokenManager;
57
+ protected readonly log?: Logger | undefined;
58
+ private readonly headerProvider?;
59
+ protected constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger | undefined, headerProvider?: HeaderProvider | undefined);
60
+ protected abstract endpoint(): string;
61
+ protected endpointUrl(): string;
62
+ private headersForRequest;
63
+ protected getRequest<T = unknown>(endpoint: string, queryParams?: {
64
+ [key: string]: unknown;
65
+ }, noAuthentication?: boolean): Promise<ApiResponse<T>>;
66
+ protected postRequest<T = unknown>(endpoint: string, data?: unknown, noAuthentication?: boolean): Promise<ApiResponse<T>>;
67
+ protected putRequest<T = unknown>(endpoint: string, data?: unknown, noAuthentication?: boolean): Promise<ApiResponse<T>>;
68
+ protected patchRequest<T = unknown>(endpoint: string, data?: unknown, noAuthentication?: boolean): Promise<ApiResponse<T>>;
69
+ protected deleteRequest(endpoint: string, queryParams?: {
70
+ [key: string]: unknown;
71
+ }, noAuthentication?: boolean): Promise<ApiResponse>;
72
+ private makeRequestWithBody;
73
+ private makeRequestWithoutBody;
74
+ private buildUrl;
75
+ private makeRequest;
76
+ }
77
+
78
+ interface CreateApiTokenRequest {
79
+ name: string;
80
+ expirationDate?: Date;
81
+ }
82
+
83
+ interface SignOutRequest {
84
+ refreshToken: string;
85
+ }
86
+
87
+ declare class AuthEndpoint extends ApiEndpoint {
88
+ constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger, headerProvider?: HeaderProvider);
89
+ protected endpoint(): string;
90
+ signOut(oldToken: SignOutRequest): Promise<ApiResponse>;
91
+ getApiTokens(): Promise<ApiResponse<ApiToken[]>>;
92
+ createApiToken(newToken: CreateApiTokenRequest): Promise<ApiResponse<string>>;
93
+ deleteApiToken(id: string): Promise<ApiResponse>;
94
+ }
95
+
96
+ interface ChatMessage extends DbItem {
97
+ emergencyId: string;
98
+ senderId: string;
99
+ messageSentTimestamp: number;
100
+ contents: string;
101
+ }
102
+
103
+ interface PaginatedResponse<T = unknown> {
104
+ data: T[];
105
+ paginationToken?: string;
106
+ }
107
+
108
+ interface ChatMessageRequest {
109
+ emergencyId: string;
110
+ contents: string;
111
+ }
112
+
113
+ declare class ChatMessageEndpoint extends ApiEndpoint {
114
+ constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger, headerProvider?: HeaderProvider);
115
+ protected endpoint(): string;
116
+ getHistory(emergencyId: string, limit: number, paginationToken?: string): Promise<ApiResponse<PaginatedResponse<ChatMessage>>>;
117
+ sendMessage(message: ChatMessageRequest): Promise<ApiResponse<ChatMessage>>;
118
+ }
119
+
120
+ interface ClientHistory extends DbItem {
121
+ emergencyId: string;
122
+ clientId: string;
123
+ emergencyCreationTimestamp: string;
124
+ }
125
+
126
+ interface EmergencyStats {
127
+ success: number;
128
+ failed: number;
129
+ noContact: number;
130
+ refused: number;
131
+ aborted: number;
132
+ serverError: number;
133
+ canceled: number;
134
+ }
135
+
136
+ interface WritableDbItem extends DbItem {
137
+ updated: string;
138
+ }
139
+
140
+ interface Person extends WritableDbItem {
141
+ discordId: string;
142
+ rsiHandle?: string;
143
+ roles: UserRoles;
144
+ personType: PersonType;
145
+ active: boolean;
146
+ deactivationReason: AccountDeactivationReason;
147
+ clientStats: ClientStats;
148
+ activeEmergency?: string;
149
+ clientPortalPreferences: Record<string, unknown>;
150
+ }
151
+ declare enum UserRoles {
152
+ CLIENT = 1,
153
+ STAFF = 2,
154
+ DEVELOPER = 524288,
155
+ BOT = 1048576
156
+ }
157
+ declare enum PersonType {
158
+ CLIENT = 0,
159
+ STAFF = 1,
160
+ BOT = 2
161
+ }
162
+ declare enum AccountDeactivationReason {
163
+ NONE = 0,
164
+ CLIENT_DRIVEN_DELETION = 1,
165
+ TERMINATED = 2,
166
+ BLOCKED = 3
167
+ }
168
+ interface ClientStats {
169
+ missions: EmergencyStats;
170
+ }
171
+
172
+ declare class ClientEndpoint extends ApiEndpoint {
173
+ constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger, headerProvider?: HeaderProvider);
174
+ protected endpoint(): string;
175
+ get(): Promise<ApiResponse<Person>>;
176
+ getHistory(limit: number, paginationToken?: string): Promise<ApiResponse<PaginatedResponse<ClientHistory>>>;
177
+ linkClient(rsiHandle: string): Promise<ApiResponse>;
178
+ setSettings(settings: Record<string, unknown>): Promise<ApiResponse<Record<string, unknown>>>;
179
+ }
180
+
181
+ declare enum CancellationReason {
182
+ NONE = 0,
183
+ OTHER = 1,
184
+ SUCCUMBED_TO_WOUNDS = 2,
185
+ SERVER_ERROR = 3,
186
+ RESPAWNED = 4,
187
+ RESCUED = 5
188
+ }
189
+
190
+ declare enum MissionStatus {
191
+ CREATED = 0,
192
+ RECEIVED = 1,
193
+ IN_PROGRESS = 2,
194
+ SUCCESS = 3,
195
+ FAILED = 4,
196
+ NO_CONTACT = 5,
197
+ CANCELED = 6,
198
+ REFUSED = 7,
199
+ ABORTED = 8,
200
+ SERVER_ERROR = 9
201
+ }
202
+
203
+ declare enum ResponseRating {
204
+ NONE = 0,
205
+ GOOD = 1,
206
+ BAD = 2
207
+ }
208
+
209
+ declare enum Class {
210
+ NONE = 0,
211
+ MEDIC = 1,
212
+ SECURITY = 2,
213
+ PILOT = 3,
214
+ LEAD = 4,
215
+ DISPATCH = 5,
216
+ DISPATCH_LEAD = 6,
217
+ DISPATCH_TRAINEE = 7,
218
+ DISPATCH_OBSERVER = 8,
219
+ QRF = 9,
220
+ LOGISTICS = 10
221
+ }
222
+
223
+ interface TeamMember {
224
+ discordId: string;
225
+ id: string;
226
+ rsiHandle?: string;
227
+ class: Class;
228
+ teamId?: string;
229
+ }
230
+
231
+ interface Team {
232
+ staff: TeamMember[];
233
+ dispatchers: TeamMember[];
234
+ allMembers: TeamMember[];
235
+ maxMembers: number;
236
+ }
237
+
238
+ declare enum ThreatLevel {
239
+ UNKNOWN = 0,
240
+ LOW = 1,
241
+ MEDIUM = 2,
242
+ HIGH = 3
243
+ }
244
+
245
+ interface Emergency extends WritableDbItem {
246
+ system: string;
247
+ subsystem: string;
248
+ tertiaryLocation?: string;
249
+ threatLevel: ThreatLevel;
250
+ remarks?: string;
251
+ clientRsiHandle: string;
252
+ clientDiscordId?: string;
253
+ clientId?: string;
254
+ subscriptionTier: string;
255
+ status: MissionStatus;
256
+ alertMessage?: MessageCache;
257
+ clientMessage?: MessageCache;
258
+ coordinationThread?: MessageCache;
259
+ afterActionReportMessage?: MessageCache;
260
+ interactionMessageId?: string;
261
+ respondingTeam: Team;
262
+ respondingTeams: RespondingTeam[];
263
+ creationTimestamp: number;
264
+ acceptedTimestamp?: number;
265
+ completionTimestamp?: number;
266
+ rating: ResponseRating;
267
+ ratingRemarks?: string;
268
+ test: boolean;
269
+ cancellationReason: CancellationReason;
270
+ refusalReason?: string;
271
+ origin: Origin;
272
+ clientData?: ClientData;
273
+ isComplete: boolean;
274
+ missionName?: string;
275
+ afterActionReport?: AfterActionReport;
276
+ submissionSource: SubmissionSource;
277
+ }
278
+ interface MessageCache {
279
+ id: string;
280
+ channelId: string;
281
+ }
282
+ interface ClientData {
283
+ rsiHandle: string;
284
+ rsiProfileLink: string;
285
+ gotClientData: boolean;
286
+ redactedOrgOnProfile: boolean;
287
+ reported: boolean;
288
+ }
289
+ interface AfterActionReport {
290
+ remarks?: string;
291
+ submitterStaffId: string;
292
+ servicesProvided: MissionServices;
293
+ suspectedTrap: boolean;
294
+ hasBeenEdited: boolean;
295
+ submittedOn: number;
296
+ editHistory: AfterActionReportEdit[];
297
+ }
298
+ interface AfterActionReportEdit {
299
+ editorStaffId: string;
300
+ editTime: number;
301
+ }
302
+ declare enum MissionServices {
303
+ NONE = 0,
304
+ PVE = 1,
305
+ PVP = 2,
306
+ REVIVED_HEALED = 4,
307
+ HEALED_IN_SHIP = 8,
308
+ EXTRACT_SAFE_ZONE = 16
309
+ }
310
+ declare enum Origin {
311
+ UNKNOWN = 0,
312
+ REPORT = 1,
313
+ BEACON = 2,
314
+ EVALUATION = 3
315
+ }
316
+ declare enum SubmissionSource {
317
+ UNKNOWN = 0,
318
+ API = 1,
319
+ BOT = 2
320
+ }
321
+ interface RespondingTeam {
322
+ id: string;
323
+ teamName: string;
324
+ }
325
+
326
+ interface CreateEmergencyRequest {
327
+ remarks?: string;
328
+ location: Location;
329
+ threatLevel: ThreatLevel;
330
+ }
331
+ interface Location {
332
+ system: string;
333
+ subsystem: string;
334
+ tertiaryLocation?: string;
335
+ }
336
+
337
+ interface LocationDetail {
338
+ name: string;
339
+ type: LocationType;
340
+ children: LocationDetail[];
341
+ }
342
+ declare enum LocationType {
343
+ UNKNOWN = 0,
344
+ SYSTEM = 1,
345
+ PLANET = 2,
346
+ MOON = 3
347
+ }
348
+
349
+ declare enum Level {
350
+ None = 0,
351
+ Tier1Section1 = 101,
352
+ Tier1Section2 = 102,
353
+ Tier1Section3 = 103,
354
+ Tier2Section1 = 201,
355
+ Tier2Section2 = 202,
356
+ Tier2Section3 = 203,
357
+ Tier3Section1 = 301,
358
+ Tier3Section2 = 302,
359
+ Tier3Section3 = 303,
360
+ Tier4Section1 = 401,
361
+ Tier4Section2 = 402,
362
+ Tier4Section3 = 403,
363
+ Tier5Section1 = 501,
364
+ Tier5Section2 = 502,
365
+ Tier5Section3 = 503,
366
+ Tier6Section1 = 601,
367
+ Tier6Section2 = 602,
368
+ Tier6Section3 = 603,
369
+ Tier7Section1 = 701,
370
+ Tier7Section2 = 702,
371
+ Tier7Section3 = 703,
372
+ Tier8Section1 = 801,
373
+ Tier8Section2 = 802,
374
+ Tier8Section3 = 803,
375
+ Tier9Section1 = 901,
376
+ Tier9Section2 = 902,
377
+ Tier9Section3 = 903,
378
+ Tier10Section1 = 1001,
379
+ Tier10Section2 = 1002,
380
+ Tier10Section3 = 1003
381
+ }
382
+
383
+ interface TeamDetailsResponse {
384
+ stats: ResponderDetails[];
385
+ aggregatedSuccessRate: number;
386
+ }
387
+ interface ResponderDetails {
388
+ id: string;
389
+ level: Level;
390
+ missionSuccessRate: number;
391
+ dispatchSuccessRate: number;
392
+ }
393
+
394
+ declare class EmergencyEndpoint extends ApiEndpoint {
395
+ constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger | undefined, headerProvider?: HeaderProvider | undefined);
396
+ protected endpoint(): string;
397
+ getEmergency(id: string): Promise<ApiResponse<Emergency>>;
398
+ getEmergencies(ids: string[]): Promise<ApiResponse<Emergency[]>>;
399
+ createEmergency(newEmergency: CreateEmergencyRequest): Promise<ApiResponse<Emergency>>;
400
+ cancelEmergencyWithReason(id: string, reason: CancellationReason): Promise<ApiResponse>;
401
+ rateServices(id: string, rating: ResponseRating, remarks?: string): Promise<ApiResponse>;
402
+ teamDetails(id: string): Promise<ApiResponse<TeamDetailsResponse>>;
403
+ emergencyLocations(): Promise<ApiResponse<LocationDetail[]>>;
404
+ }
405
+
406
+ interface MedalInformation {
407
+ level: Level;
408
+ successfulMissions: number;
409
+ }
410
+
411
+ declare class StaffEndpoint extends ApiEndpoint {
412
+ constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger, headerProvider?: HeaderProvider);
413
+ protected endpoint(): string;
414
+ medalsInformation(): Promise<ApiResponse<MedalInformation[]>>;
415
+ }
416
+
417
+ declare class WebsocketEndpoint extends ApiEndpoint {
418
+ constructor(baseUrl: string, tokenManager: TokenManager, log?: Logger | undefined, headerProvider?: HeaderProvider | undefined);
419
+ private websocketManager;
420
+ protected endpoint(): string;
421
+ initialize(): Promise<HubConnection>;
422
+ }
423
+
424
+ interface ApiClient<TEmergency extends EmergencyEndpoint = EmergencyEndpoint, TClient extends ClientEndpoint = ClientEndpoint, TStaff extends StaffEndpoint = StaffEndpoint, TChatMessage extends ChatMessageEndpoint = ChatMessageEndpoint, TAuth extends AuthEndpoint = AuthEndpoint, TWebsocket extends WebsocketEndpoint = WebsocketEndpoint> {
425
+ emergency: TEmergency;
426
+ client: TClient;
427
+ staff: TStaff;
428
+ chatMessage: TChatMessage;
429
+ auth: TAuth;
430
+ websocket: TWebsocket;
431
+ }
432
+
433
+ declare class MedrunnerApiClient<TEmergency extends EmergencyEndpoint = EmergencyEndpoint, TClient extends ClientEndpoint = ClientEndpoint, TStaff extends StaffEndpoint = StaffEndpoint, TChatMessage extends ChatMessageEndpoint = ChatMessageEndpoint, TAuth extends AuthEndpoint = AuthEndpoint, TWebsocket extends WebsocketEndpoint = WebsocketEndpoint> implements ApiClient<TEmergency, TClient, TStaff, TChatMessage, TAuth, TWebsocket> {
434
+ readonly emergency: TEmergency;
435
+ readonly client: TClient;
436
+ readonly staff: TStaff;
437
+ readonly chatMessage: TChatMessage;
438
+ readonly auth: TAuth;
439
+ readonly websocket: TWebsocket;
440
+ protected constructor(emergency: TEmergency, client: TClient, staff: TStaff, chatMessage: TChatMessage, auth: TAuth, websocket: TWebsocket);
441
+ static buildClient(config: ApiConfig, refreshCallback?: AsyncAction<TokenGrant>, log?: Logger): MedrunnerApiClient;
442
+ }
443
+
444
+ export { AccountDeactivationReason, AfterActionReport, AfterActionReportEdit, ApiClient, ApiConfig, ApiEndpoint, ApiResponse, ApiToken, AsyncAction, AsyncProvider, AuthEndpoint, CancellationReason, ChatMessage, ChatMessageEndpoint, ChatMessageRequest, Class, ClientData, ClientEndpoint, ClientHistory, ClientStats, CreateEmergencyRequest, DbItem, Emergency, EmergencyEndpoint, EmergencyStats, Func, HeaderProvider, Headers, Level, Location, LocationDetail, LocationType, MedalInformation, MedrunnerApiClient, MessageCache, MissionServices, MissionStatus, Origin, PaginatedResponse, Person, PersonType, ResponderDetails, RespondingTeam, ResponseRating, StaffEndpoint, SubmissionSource, Team, TeamDetailsResponse, TeamMember, ThreatLevel, TokenGrant, TokenManager, UserRoles, WebsocketEndpoint };