@sonoransoftware/sonoran.js 1.0.18 → 1.0.20

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