@sonoransoftware/sonoran.js 1.0.19 → 1.0.22
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/.eslintrc.js +10 -10
- package/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc.js +6 -6
- package/dist/builders/cad/DispatchCall.d.ts +92 -92
- package/dist/builders/cad/DispatchCall.js +144 -144
- package/dist/builders/cad/index.d.ts +1 -1
- package/dist/builders/cad/index.js +17 -17
- package/dist/builders/index.d.ts +1 -1
- package/dist/builders/index.js +19 -19
- package/dist/constants.d.ts +230 -230
- package/dist/constants.js +27 -27
- package/dist/errors/LibraryErrors.d.ts +19 -19
- package/dist/errors/LibraryErrors.js +47 -47
- package/dist/errors/Messages.d.ts +1 -1
- package/dist/errors/Messages.js +8 -8
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +18 -18
- package/dist/index.d.ts +4 -4
- package/dist/index.js +24 -24
- package/dist/instance/Instance.d.ts +24 -24
- package/dist/instance/Instance.js +139 -139
- package/dist/instance/instance.types.d.ts +17 -17
- package/dist/instance/instance.types.js +2 -2
- package/dist/libs/rest/src/index.d.ts +6 -6
- package/dist/libs/rest/src/index.js +22 -22
- package/dist/libs/rest/src/lib/REST.d.ts +101 -101
- package/dist/libs/rest/src/lib/REST.js +136 -129
- package/dist/libs/rest/src/lib/RequestManager.d.ts +59 -59
- package/dist/libs/rest/src/lib/RequestManager.js +191 -191
- package/dist/libs/rest/src/lib/errors/APIError.d.ts +9 -9
- package/dist/libs/rest/src/lib/errors/APIError.js +17 -17
- package/dist/libs/rest/src/lib/errors/HTTPError.d.ts +17 -17
- package/dist/libs/rest/src/lib/errors/HTTPError.js +23 -23
- package/dist/libs/rest/src/lib/errors/RateLimitError.d.ts +13 -13
- package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -19
- package/dist/libs/rest/src/lib/errors/index.d.ts +4 -4
- package/dist/libs/rest/src/lib/errors/index.js +20 -20
- package/dist/libs/rest/src/lib/handlers/IHandler.d.ts +7 -7
- package/dist/libs/rest/src/lib/handlers/IHandler.js +2 -2
- package/dist/libs/rest/src/lib/handlers/SequentialHandler.d.ts +45 -45
- package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +143 -143
- package/dist/libs/rest/src/lib/utils/constants.d.ts +533 -527
- package/dist/libs/rest/src/lib/utils/constants.js +463 -455
- package/dist/libs/rest/src/lib/utils/utils.d.ts +1 -1
- package/dist/libs/rest/src/lib/utils/utils.js +22 -22
- package/dist/managers/BaseManager.d.ts +14 -14
- package/dist/managers/BaseManager.js +18 -18
- package/dist/managers/CADActiveUnitsManager.d.ts +15 -15
- package/dist/managers/CADActiveUnitsManager.js +38 -38
- package/dist/managers/CADManager.d.ts +29 -29
- package/dist/managers/CADManager.js +86 -86
- package/dist/managers/CADServerManager.d.ts +8 -8
- package/dist/managers/CADServerManager.js +28 -28
- package/dist/managers/CMSManager.d.ts +101 -101
- package/dist/managers/CMSManager.js +266 -266
- package/dist/managers/CMSServerManager.d.ts +8 -8
- package/dist/managers/CMSServerManager.js +34 -34
- package/dist/managers/CacheManager.d.ts +10 -10
- package/dist/managers/CacheManager.js +36 -36
- package/dist/managers/DataManager.d.ts +31 -31
- package/dist/managers/DataManager.js +58 -58
- package/dist/structures/Base.d.ts +9 -9
- package/dist/structures/Base.js +24 -24
- package/dist/structures/CADActiveUnit.d.ts +47 -47
- package/dist/structures/CADActiveUnit.js +66 -66
- package/dist/structures/CADServer.d.ts +26 -26
- package/dist/structures/CADServer.js +15 -15
- package/dist/structures/CMSServer.d.ts +18 -18
- package/dist/structures/CMSServer.js +12 -12
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +17 -17
- package/dist/utils/utils.d.ts +13 -13
- package/dist/utils/utils.js +79 -79
- package/docs/CAD-Methods-and-Usage.md +58 -58
- package/docs/CMS-Methods-and-Usage.md +211 -211
- package/docs/REST-Methods-and-Usage.md +46 -46
- package/package.json +48 -48
- package/readme.md +53 -53
- package/src/constants.ts +248 -248
- package/src/instance/Instance.ts +121 -121
- package/src/instance/instance.types.ts +17 -17
- package/src/libs/rest/src/lib/REST.ts +241 -234
- package/src/libs/rest/src/lib/RequestManager.ts +260 -260
- package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +160 -160
- package/src/libs/rest/src/lib/utils/constants.ts +1012 -997
- package/src/managers/CADManager.ts +63 -63
- package/src/managers/CMSManager.ts +226 -226
- package/src/managers/CMSServerManager.ts +32 -32
- package/tsconfig.json +71 -71
|
@@ -1,234 +1,241 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import {
|
|
3
|
-
InternalRequestData,
|
|
4
|
-
// RequestMethod,
|
|
5
|
-
RequestData,
|
|
6
|
-
RequestManager,
|
|
7
|
-
// RouteLike
|
|
8
|
-
} from './RequestManager';
|
|
9
|
-
import { AllAPITypes, AllAPITypesType, RESTEvents, RESTTypedAPIDataStructs } from './utils/constants';
|
|
10
|
-
import { productEnums, uuidRegex } from '../../../../constants';
|
|
11
|
-
import type { AgentOptions } from 'node:https';
|
|
12
|
-
import type { RequestInit, Response } from 'node-fetch';
|
|
13
|
-
// import type Collection from '@discordjs/collection';
|
|
14
|
-
import { Instance } from '../../../../instance/Instance';
|
|
15
|
-
import { CADManager } from '../../../../managers/CADManager';
|
|
16
|
-
import { CMSManager } from '../../../../managers/CMSManager';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Options to be passed when creating the REST instance
|
|
20
|
-
*/
|
|
21
|
-
export interface RESTOptions {
|
|
22
|
-
/**
|
|
23
|
-
* HTTPS Agent options
|
|
24
|
-
* @default {}
|
|
25
|
-
*/
|
|
26
|
-
agent: Omit<AgentOptions, 'keepAlive'>;
|
|
27
|
-
/**
|
|
28
|
-
* The base api path, without version
|
|
29
|
-
*/
|
|
30
|
-
api: string;
|
|
31
|
-
/**
|
|
32
|
-
* Additional headers to send for all API requests
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers: Record<string, string>;
|
|
36
|
-
/**
|
|
37
|
-
* Wether the request should be queued if there's a current ratelimit or to reject.
|
|
38
|
-
* @default true
|
|
39
|
-
*/
|
|
40
|
-
rejectOnRateLimit: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Data emitted on `RESTEvents.RateLimited`
|
|
45
|
-
*/
|
|
46
|
-
export interface RateLimitData {
|
|
47
|
-
product: productEnums;
|
|
48
|
-
type: string;
|
|
49
|
-
timeTill: NodeJS.Timer;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface APIRequest {
|
|
53
|
-
/**
|
|
54
|
-
* The HTTP method used in this request
|
|
55
|
-
*/
|
|
56
|
-
type: AllAPITypesType;
|
|
57
|
-
/**
|
|
58
|
-
* Additional HTTP options for this request
|
|
59
|
-
*/
|
|
60
|
-
options: RequestInit;
|
|
61
|
-
/**
|
|
62
|
-
* The data that was used to form the body of this request
|
|
63
|
-
*/
|
|
64
|
-
data: RequestData;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface InvalidRequestWarningData {
|
|
68
|
-
/**
|
|
69
|
-
* Number of invalid requests that have been made in the window
|
|
70
|
-
*/
|
|
71
|
-
count: number;
|
|
72
|
-
/**
|
|
73
|
-
* API request type which the request is for
|
|
74
|
-
*/
|
|
75
|
-
type: string;
|
|
76
|
-
/**
|
|
77
|
-
* Product which the invalid request is for
|
|
78
|
-
*/
|
|
79
|
-
product: productEnums;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface RestEvents {
|
|
83
|
-
invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
|
|
84
|
-
restDebug: [info: string];
|
|
85
|
-
rateLimited: [rateLimitInfo: RateLimitData];
|
|
86
|
-
request: [request: APIRequest];
|
|
87
|
-
response: [request: APIRequest, response: Response];
|
|
88
|
-
newListener: [name: string, listener: (...args: any) => void];
|
|
89
|
-
removeListener: [name: string, listener: (...args: any) => void];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface REST {
|
|
93
|
-
on: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) &
|
|
94
|
-
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
95
|
-
|
|
96
|
-
once: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) &
|
|
97
|
-
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
98
|
-
|
|
99
|
-
emit: (<K extends keyof RestEvents>(event: K, ...args: RestEvents[K]) => boolean) &
|
|
100
|
-
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, ...args: any[]) => boolean);
|
|
101
|
-
|
|
102
|
-
off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) &
|
|
103
|
-
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
104
|
-
|
|
105
|
-
removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) &
|
|
106
|
-
(<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export type RestManagerTypes = CADManager | CMSManager;
|
|
110
|
-
|
|
111
|
-
export class REST extends EventEmitter {
|
|
112
|
-
public readonly requestManager: RequestManager;
|
|
113
|
-
public readonly instance: Instance;
|
|
114
|
-
public readonly manager: RestManagerTypes;
|
|
115
|
-
|
|
116
|
-
public constructor(_instance: Instance, _manager: RestManagerTypes,_product: productEnums, options: RESTOptions) {
|
|
117
|
-
super();
|
|
118
|
-
this.instance = _instance;
|
|
119
|
-
this.manager = _manager;
|
|
120
|
-
this.requestManager = new RequestManager(_instance, _product, options)
|
|
121
|
-
.on(RESTEvents.Debug, this.emit.bind(this, RESTEvents.Debug))
|
|
122
|
-
.on(RESTEvents.RateLimited, this.emit.bind(this, RESTEvents.RateLimited))
|
|
123
|
-
.on(RESTEvents.InvalidRequestWarning, this.emit.bind(this, RESTEvents.InvalidRequestWarning));
|
|
124
|
-
|
|
125
|
-
this.on('newListener', (name, listener) => {
|
|
126
|
-
if (name === RESTEvents.Request || name === RESTEvents.Response) this.requestManager.on(name, listener);
|
|
127
|
-
});
|
|
128
|
-
this.on('removeListener', (name, listener) => {
|
|
129
|
-
if (name === RESTEvents.Request || name === RESTEvents.Response) this.requestManager.off(name, listener);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Runs a request from the api
|
|
135
|
-
* @param type API Type Enum
|
|
136
|
-
*/
|
|
137
|
-
public request<K extends keyof RESTTypedAPIDataStructs>(type: K, ...args: RESTTypedAPIDataStructs[K]) {
|
|
138
|
-
const apiType = AllAPITypes.find((aT) => aT.type === type);
|
|
139
|
-
if (!apiType) throw new Error('Invalid API Type given for request.');
|
|
140
|
-
let communityId: string | undefined;
|
|
141
|
-
let apiKey: string | undefined;
|
|
142
|
-
switch (apiType.product) {
|
|
143
|
-
case productEnums.CAD: {
|
|
144
|
-
communityId = this.instance.cadCommunityId;
|
|
145
|
-
apiKey = this.instance.cadApiKey;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
case productEnums.CMS: {
|
|
149
|
-
communityId = this.instance.cmsCommunityId;
|
|
150
|
-
apiKey = this.instance.cmsApiKey;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (!communityId || !apiKey) throw new Error(`Community ID or API Key could not be found for request. P${apiType.product}`);
|
|
155
|
-
// if (apiType.minVersion > this.manager.version) throw new Error(`[${type}] Subscription version too low for this API type request. Current Version: ${convertSubNumToName(this.manager.version)} Needed Version: ${convertSubNumToName(apiType.minVersion)}`); // Verifies API Subscription Level Requirement which is deprecated currently
|
|
156
|
-
const formattedData = this.formatDataArguments(apiType.type, args);
|
|
157
|
-
const options: InternalRequestData = {
|
|
158
|
-
id: communityId,
|
|
159
|
-
key: apiKey,
|
|
160
|
-
type,
|
|
161
|
-
data: formattedData,
|
|
162
|
-
product: apiType.product
|
|
163
|
-
};
|
|
164
|
-
return this.requestManager.queueRequest(options);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private formatDataArguments(type: string, args: any) {
|
|
168
|
-
switch (type) {
|
|
169
|
-
case 'VERIFY_WHITELIST': {
|
|
170
|
-
return {
|
|
171
|
-
apiId: args[0],
|
|
172
|
-
accId: uuidRegex.test(args[1]) ? args[1] : undefined,
|
|
173
|
-
serverId: args[2]
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
case 'FULL_WHITELIST': {
|
|
177
|
-
return {
|
|
178
|
-
serverId: args[0]
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
case 'RSVP': {
|
|
182
|
-
return {
|
|
183
|
-
eventId: args[0],
|
|
184
|
-
apiId: args[1],
|
|
185
|
-
accId: args[2],
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
case 'GET_COM_ACCOUNT': {
|
|
189
|
-
return {
|
|
190
|
-
apiId: args[0],
|
|
191
|
-
username: args[1],
|
|
192
|
-
accId: args[2],
|
|
193
|
-
discord: args[3]
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
case 'GET_ACCOUNT_RANKS': {
|
|
197
|
-
return {
|
|
198
|
-
apiId: args[0],
|
|
199
|
-
username: args[1],
|
|
200
|
-
accId: args[2],
|
|
201
|
-
discord: args[3]
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
case 'CLOCK_IN_OUT': {
|
|
205
|
-
return {
|
|
206
|
-
apiId: args[0],
|
|
207
|
-
accId: args[1],
|
|
208
|
-
forceClockIn: args[2]
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
case 'CHECK_COM_APIID': {
|
|
212
|
-
return {
|
|
213
|
-
apiId: args[0]
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
case 'SET_ACCOUNT_RANKS': {
|
|
217
|
-
return {
|
|
218
|
-
accountId: args[0],
|
|
219
|
-
set: args[1],
|
|
220
|
-
add: args[2],
|
|
221
|
-
remove: args[3],
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
case 'VERIFY_SECRET': {
|
|
225
|
-
return {
|
|
226
|
-
secret: args[0],
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import {
|
|
3
|
+
InternalRequestData,
|
|
4
|
+
// RequestMethod,
|
|
5
|
+
RequestData,
|
|
6
|
+
RequestManager,
|
|
7
|
+
// RouteLike
|
|
8
|
+
} from './RequestManager';
|
|
9
|
+
import { AllAPITypes, AllAPITypesType, RESTEvents, RESTTypedAPIDataStructs } from './utils/constants';
|
|
10
|
+
import { productEnums, uuidRegex } from '../../../../constants';
|
|
11
|
+
import type { AgentOptions } from 'node:https';
|
|
12
|
+
import type { RequestInit, Response } from 'node-fetch';
|
|
13
|
+
// import type Collection from '@discordjs/collection';
|
|
14
|
+
import { Instance } from '../../../../instance/Instance';
|
|
15
|
+
import { CADManager } from '../../../../managers/CADManager';
|
|
16
|
+
import { CMSManager } from '../../../../managers/CMSManager';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options to be passed when creating the REST instance
|
|
20
|
+
*/
|
|
21
|
+
export interface RESTOptions {
|
|
22
|
+
/**
|
|
23
|
+
* HTTPS Agent options
|
|
24
|
+
* @default {}
|
|
25
|
+
*/
|
|
26
|
+
agent: Omit<AgentOptions, 'keepAlive'>;
|
|
27
|
+
/**
|
|
28
|
+
* The base api path, without version
|
|
29
|
+
*/
|
|
30
|
+
api: string;
|
|
31
|
+
/**
|
|
32
|
+
* Additional headers to send for all API requests
|
|
33
|
+
* @default {}
|
|
34
|
+
*/
|
|
35
|
+
headers: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Wether the request should be queued if there's a current ratelimit or to reject.
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
rejectOnRateLimit: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Data emitted on `RESTEvents.RateLimited`
|
|
45
|
+
*/
|
|
46
|
+
export interface RateLimitData {
|
|
47
|
+
product: productEnums;
|
|
48
|
+
type: string;
|
|
49
|
+
timeTill: NodeJS.Timer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface APIRequest {
|
|
53
|
+
/**
|
|
54
|
+
* The HTTP method used in this request
|
|
55
|
+
*/
|
|
56
|
+
type: AllAPITypesType;
|
|
57
|
+
/**
|
|
58
|
+
* Additional HTTP options for this request
|
|
59
|
+
*/
|
|
60
|
+
options: RequestInit;
|
|
61
|
+
/**
|
|
62
|
+
* The data that was used to form the body of this request
|
|
63
|
+
*/
|
|
64
|
+
data: RequestData;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface InvalidRequestWarningData {
|
|
68
|
+
/**
|
|
69
|
+
* Number of invalid requests that have been made in the window
|
|
70
|
+
*/
|
|
71
|
+
count: number;
|
|
72
|
+
/**
|
|
73
|
+
* API request type which the request is for
|
|
74
|
+
*/
|
|
75
|
+
type: string;
|
|
76
|
+
/**
|
|
77
|
+
* Product which the invalid request is for
|
|
78
|
+
*/
|
|
79
|
+
product: productEnums;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface RestEvents {
|
|
83
|
+
invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];
|
|
84
|
+
restDebug: [info: string];
|
|
85
|
+
rateLimited: [rateLimitInfo: RateLimitData];
|
|
86
|
+
request: [request: APIRequest];
|
|
87
|
+
response: [request: APIRequest, response: Response];
|
|
88
|
+
newListener: [name: string, listener: (...args: any) => void];
|
|
89
|
+
removeListener: [name: string, listener: (...args: any) => void];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface REST {
|
|
93
|
+
on: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) &
|
|
94
|
+
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
95
|
+
|
|
96
|
+
once: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) &
|
|
97
|
+
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
98
|
+
|
|
99
|
+
emit: (<K extends keyof RestEvents>(event: K, ...args: RestEvents[K]) => boolean) &
|
|
100
|
+
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, ...args: any[]) => boolean);
|
|
101
|
+
|
|
102
|
+
off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) &
|
|
103
|
+
(<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
104
|
+
|
|
105
|
+
removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) &
|
|
106
|
+
(<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type RestManagerTypes = CADManager | CMSManager;
|
|
110
|
+
|
|
111
|
+
export class REST extends EventEmitter {
|
|
112
|
+
public readonly requestManager: RequestManager;
|
|
113
|
+
public readonly instance: Instance;
|
|
114
|
+
public readonly manager: RestManagerTypes;
|
|
115
|
+
|
|
116
|
+
public constructor(_instance: Instance, _manager: RestManagerTypes,_product: productEnums, options: RESTOptions) {
|
|
117
|
+
super();
|
|
118
|
+
this.instance = _instance;
|
|
119
|
+
this.manager = _manager;
|
|
120
|
+
this.requestManager = new RequestManager(_instance, _product, options)
|
|
121
|
+
.on(RESTEvents.Debug, this.emit.bind(this, RESTEvents.Debug))
|
|
122
|
+
.on(RESTEvents.RateLimited, this.emit.bind(this, RESTEvents.RateLimited))
|
|
123
|
+
.on(RESTEvents.InvalidRequestWarning, this.emit.bind(this, RESTEvents.InvalidRequestWarning));
|
|
124
|
+
|
|
125
|
+
this.on('newListener', (name, listener) => {
|
|
126
|
+
if (name === RESTEvents.Request || name === RESTEvents.Response) this.requestManager.on(name, listener);
|
|
127
|
+
});
|
|
128
|
+
this.on('removeListener', (name, listener) => {
|
|
129
|
+
if (name === RESTEvents.Request || name === RESTEvents.Response) this.requestManager.off(name, listener);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Runs a request from the api
|
|
135
|
+
* @param type API Type Enum
|
|
136
|
+
*/
|
|
137
|
+
public request<K extends keyof RESTTypedAPIDataStructs>(type: K, ...args: RESTTypedAPIDataStructs[K]) {
|
|
138
|
+
const apiType = AllAPITypes.find((aT) => aT.type === type);
|
|
139
|
+
if (!apiType) throw new Error('Invalid API Type given for request.');
|
|
140
|
+
let communityId: string | undefined;
|
|
141
|
+
let apiKey: string | undefined;
|
|
142
|
+
switch (apiType.product) {
|
|
143
|
+
case productEnums.CAD: {
|
|
144
|
+
communityId = this.instance.cadCommunityId;
|
|
145
|
+
apiKey = this.instance.cadApiKey;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case productEnums.CMS: {
|
|
149
|
+
communityId = this.instance.cmsCommunityId;
|
|
150
|
+
apiKey = this.instance.cmsApiKey;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!communityId || !apiKey) throw new Error(`Community ID or API Key could not be found for request. P${apiType.product}`);
|
|
155
|
+
// if (apiType.minVersion > this.manager.version) throw new Error(`[${type}] Subscription version too low for this API type request. Current Version: ${convertSubNumToName(this.manager.version)} Needed Version: ${convertSubNumToName(apiType.minVersion)}`); // Verifies API Subscription Level Requirement which is deprecated currently
|
|
156
|
+
const formattedData = this.formatDataArguments(apiType.type, args);
|
|
157
|
+
const options: InternalRequestData = {
|
|
158
|
+
id: communityId,
|
|
159
|
+
key: apiKey,
|
|
160
|
+
type,
|
|
161
|
+
data: formattedData,
|
|
162
|
+
product: apiType.product
|
|
163
|
+
};
|
|
164
|
+
return this.requestManager.queueRequest(options);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private formatDataArguments(type: string, args: any) {
|
|
168
|
+
switch (type) {
|
|
169
|
+
case 'VERIFY_WHITELIST': {
|
|
170
|
+
return {
|
|
171
|
+
apiId: args[0],
|
|
172
|
+
accId: uuidRegex.test(args[1]) ? args[1] : undefined,
|
|
173
|
+
serverId: args[2]
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
case 'FULL_WHITELIST': {
|
|
177
|
+
return {
|
|
178
|
+
serverId: args[0]
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
case 'RSVP': {
|
|
182
|
+
return {
|
|
183
|
+
eventId: args[0],
|
|
184
|
+
apiId: args[1],
|
|
185
|
+
accId: args[2],
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
case 'GET_COM_ACCOUNT': {
|
|
189
|
+
return {
|
|
190
|
+
apiId: args[0],
|
|
191
|
+
username: args[1],
|
|
192
|
+
accId: args[2],
|
|
193
|
+
discord: args[3]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
case 'GET_ACCOUNT_RANKS': {
|
|
197
|
+
return {
|
|
198
|
+
apiId: args[0],
|
|
199
|
+
username: args[1],
|
|
200
|
+
accId: args[2],
|
|
201
|
+
discord: args[3]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
case 'CLOCK_IN_OUT': {
|
|
205
|
+
return {
|
|
206
|
+
apiId: args[0],
|
|
207
|
+
accId: args[1],
|
|
208
|
+
forceClockIn: args[2]
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
case 'CHECK_COM_APIID': {
|
|
212
|
+
return {
|
|
213
|
+
apiId: args[0]
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
case 'SET_ACCOUNT_RANKS': {
|
|
217
|
+
return {
|
|
218
|
+
accountId: args[0],
|
|
219
|
+
set: args[1],
|
|
220
|
+
add: args[2],
|
|
221
|
+
remove: args[3],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
case 'VERIFY_SECRET': {
|
|
225
|
+
return {
|
|
226
|
+
secret: args[0],
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
case 'CHANGE_FORM_STAGE': {
|
|
230
|
+
return {
|
|
231
|
+
accId: args[0],
|
|
232
|
+
formId: args[1],
|
|
233
|
+
newStageId: args[2],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
default: {
|
|
237
|
+
return args;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|