@sonoransoftware/sonoran.js 1.0.0 → 1.0.3

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 (92) hide show
  1. package/.github/workflows/npm-publish.yml +34 -0
  2. package/dist/builders/cad/DispatchCall.d.ts +92 -0
  3. package/dist/builders/cad/DispatchCall.js +144 -0
  4. package/dist/builders/cad/index.d.ts +1 -0
  5. package/dist/builders/cad/index.js +17 -0
  6. package/dist/builders/index.d.ts +1 -0
  7. package/dist/builders/index.js +19 -0
  8. package/dist/constants.d.ts +174 -0
  9. package/dist/constants.js +27 -0
  10. package/dist/errors/LibraryErrors.d.ts +19 -0
  11. package/dist/errors/LibraryErrors.js +47 -0
  12. package/dist/errors/Messages.d.ts +1 -0
  13. package/dist/errors/Messages.js +8 -0
  14. package/dist/errors/index.d.ts +2 -0
  15. package/dist/errors/index.js +18 -0
  16. package/dist/index.d.ts +4 -0
  17. package/dist/index.js +24 -0
  18. package/dist/instance/Instance.d.ts +23 -0
  19. package/dist/instance/Instance.js +135 -0
  20. package/dist/instance/instance.types.d.ts +16 -0
  21. package/dist/instance/instance.types.js +2 -0
  22. package/dist/libs/rest/src/index.d.ts +6 -0
  23. package/dist/libs/rest/src/index.js +22 -0
  24. package/dist/libs/rest/src/lib/REST.d.ts +99 -0
  25. package/dist/libs/rest/src/lib/REST.js +102 -0
  26. package/dist/libs/rest/src/lib/RequestManager.d.ts +58 -0
  27. package/dist/libs/rest/src/lib/RequestManager.js +190 -0
  28. package/dist/libs/rest/src/lib/errors/APIError.d.ts +9 -0
  29. package/dist/libs/rest/src/lib/errors/APIError.js +17 -0
  30. package/dist/libs/rest/src/lib/errors/HTTPError.d.ts +17 -0
  31. package/dist/libs/rest/src/lib/errors/HTTPError.js +23 -0
  32. package/dist/libs/rest/src/lib/errors/RateLimitError.d.ts +13 -0
  33. package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -0
  34. package/dist/libs/rest/src/lib/errors/index.d.ts +4 -0
  35. package/dist/libs/rest/src/lib/errors/index.js +20 -0
  36. package/dist/libs/rest/src/lib/handlers/IHandler.d.ts +7 -0
  37. package/dist/libs/rest/src/lib/handlers/IHandler.js +2 -0
  38. package/dist/libs/rest/src/lib/handlers/SequentialHandler.d.ts +45 -0
  39. package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +143 -0
  40. package/dist/libs/rest/src/lib/utils/Utils.d.ts +1 -0
  41. package/dist/libs/rest/src/lib/utils/Utils.js +22 -0
  42. package/dist/libs/rest/src/lib/utils/constants.d.ts +501 -0
  43. package/dist/libs/rest/src/lib/utils/constants.js +423 -0
  44. package/dist/managers/BaseManager.d.ts +14 -0
  45. package/dist/managers/BaseManager.js +18 -0
  46. package/dist/managers/CADActiveUnitsManager.d.ts +15 -0
  47. package/dist/managers/CADActiveUnitsManager.js +38 -0
  48. package/dist/managers/CADManager.d.ts +27 -0
  49. package/dist/managers/CADManager.js +81 -0
  50. package/dist/managers/CADServerManager.d.ts +8 -0
  51. package/dist/managers/CADServerManager.js +28 -0
  52. package/dist/managers/CMSManager.d.ts +81 -0
  53. package/dist/managers/CMSManager.js +212 -0
  54. package/dist/managers/CMSServerManager.d.ts +8 -0
  55. package/dist/managers/CMSServerManager.js +28 -0
  56. package/dist/managers/CacheManager.d.ts +10 -0
  57. package/dist/managers/CacheManager.js +39 -0
  58. package/dist/managers/DataManager.d.ts +31 -0
  59. package/dist/managers/DataManager.js +61 -0
  60. package/dist/structures/Base.d.ts +9 -0
  61. package/dist/structures/Base.js +24 -0
  62. package/dist/structures/CADActiveUnit.d.ts +47 -0
  63. package/dist/structures/CADActiveUnit.js +66 -0
  64. package/dist/structures/CADServer.d.ts +26 -0
  65. package/dist/structures/CADServer.js +15 -0
  66. package/dist/structures/CMSServer.d.ts +18 -0
  67. package/dist/structures/CMSServer.js +12 -0
  68. package/dist/utils/index.d.ts +1 -0
  69. package/dist/utils/index.js +17 -0
  70. package/dist/utils/utils.d.ts +13 -0
  71. package/dist/utils/utils.js +82 -0
  72. package/package.json +48 -42
  73. package/src/constants.ts +27 -10
  74. package/src/index.ts +1 -9
  75. package/src/instance/Instance.ts +2 -2
  76. package/src/libs/rest/src/lib/REST.ts +7 -2
  77. package/src/libs/rest/src/lib/RequestManager.ts +2 -2
  78. package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +1 -0
  79. package/src/libs/rest/src/lib/utils/constants.ts +21 -1
  80. package/src/managers/BaseManager.ts +1 -1
  81. package/src/managers/CADActiveUnitsManager.ts +1 -1
  82. package/src/managers/CADManager.ts +2 -1
  83. package/src/managers/CADServerManager.ts +1 -1
  84. package/src/managers/CMSManager.ts +49 -3
  85. package/src/managers/CMSServerManager.ts +1 -1
  86. package/src/managers/CacheManager.ts +1 -1
  87. package/src/managers/DataManager.ts +1 -1
  88. package/src/structures/Base.ts +1 -1
  89. package/src/structures/CADActiveUnit.ts +1 -1
  90. package/src/structures/CADServer.ts +1 -1
  91. package/src/structures/CMSServer.ts +1 -1
  92. package/tsconfig.json +4 -4
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CADDispatchStatusEnums = exports.CADDispatchOriginEnums = exports.CADModifyIdentifierActionEnums = exports.CADLookupByIntSearchTypeEnums = exports.CADRecordSectionCategoryEnums = exports.CADRecordTypeEnums = exports.AllAPITypes = exports.ServersCMSAPITypes = exports.GeneralCMSAPITypes = exports.EmergencyCADAPITypes = exports.CivilianCADAPITypes = exports.GeneralCADAPITypes = exports.DefaultCMSRestOptions = exports.DefaultCADRestOptions = exports.DefaultUserAgent = void 0;
4
+ const constants_1 = require("../../../../../constants");
5
+ exports.DefaultUserAgent = 'Sonoran.js NPM Module';
6
+ exports.DefaultCADRestOptions = {
7
+ agent: {},
8
+ api: 'https://api.sonorancad.com',
9
+ headers: {},
10
+ rejectOnRateLimit: true
11
+ };
12
+ exports.DefaultCMSRestOptions = {
13
+ agent: {},
14
+ api: 'https://api.sonorancms.com',
15
+ headers: {},
16
+ rejectOnRateLimit: true
17
+ };
18
+ exports.GeneralCADAPITypes = [
19
+ {
20
+ type: 'GET_SERVERS',
21
+ path: 'general/get_servers',
22
+ method: 'POST',
23
+ minVersion: 2
24
+ },
25
+ {
26
+ type: 'SET_SERVERS',
27
+ path: 'general/set_servers',
28
+ method: 'POST',
29
+ minVersion: 3
30
+ },
31
+ {
32
+ type: 'GET_VERSION',
33
+ path: 'general/get_version',
34
+ method: 'POST',
35
+ minVersion: 0
36
+ },
37
+ {
38
+ type: 'SET_PENAL_CODES',
39
+ path: 'general/set_penal_codes',
40
+ method: 'POST',
41
+ minVersion: 2
42
+ },
43
+ {
44
+ type: 'SET_API_ID',
45
+ path: 'general/set_api_id',
46
+ method: 'POST',
47
+ minVersion: 2
48
+ },
49
+ {
50
+ type: 'GET_TEMPLATES',
51
+ path: 'general/get_templates',
52
+ method: 'POST',
53
+ minVersion: 2
54
+ },
55
+ {
56
+ type: 'NEW_RECORD',
57
+ path: 'general/new_record',
58
+ method: 'POST',
59
+ minVersion: 3
60
+ },
61
+ {
62
+ type: 'EDIT_RECORD',
63
+ path: 'general/edit_record',
64
+ method: 'POST',
65
+ minVersion: 3
66
+ },
67
+ {
68
+ type: 'REMOVE_RECORD',
69
+ path: 'general/remove_record',
70
+ method: 'POST',
71
+ minVersion: 3
72
+ },
73
+ {
74
+ type: 'LOOKUP_INT',
75
+ path: 'general/lookup_int',
76
+ method: 'POST',
77
+ minVersion: 3
78
+ },
79
+ {
80
+ type: 'LOOKUP',
81
+ path: 'general/lookup',
82
+ method: 'POST',
83
+ minVersion: 3
84
+ },
85
+ {
86
+ type: 'GET_ACCOUNT',
87
+ path: 'general/get_account',
88
+ method: 'POST',
89
+ minVersion: 3
90
+ },
91
+ {
92
+ type: 'CHECK_APIID',
93
+ path: 'general/check_apiid',
94
+ method: 'POST',
95
+ minVersion: 2
96
+ },
97
+ {
98
+ type: 'APPLY_PERMISSION_KEY',
99
+ path: 'general/apply_permission_key',
100
+ method: 'POST',
101
+ minVersion: 3
102
+ },
103
+ {
104
+ type: 'SET_ACCOUNT_PERMISSIONS',
105
+ path: 'general/set_account_permissions',
106
+ method: 'POST',
107
+ minVersion: 3
108
+ },
109
+ {
110
+ type: 'BAN_USER',
111
+ path: 'general/ban_user',
112
+ method: 'POST',
113
+ minVersion: 3
114
+ },
115
+ {
116
+ type: 'VERIFY_SECRET',
117
+ path: 'general/verify_secret',
118
+ method: 'POST',
119
+ minVersion: 2
120
+ },
121
+ {
122
+ type: 'AUTH_STREETSIGNS',
123
+ path: 'general/auth_streetsigns',
124
+ method: 'POST',
125
+ minVersion: 4
126
+ },
127
+ {
128
+ type: 'SET_POSTALS',
129
+ path: 'general/set_postals',
130
+ method: 'POST',
131
+ minVersion: 4
132
+ },
133
+ {
134
+ type: 'SEND_PHOTO',
135
+ path: 'general/send_photo',
136
+ method: 'POST',
137
+ minVersion: 4
138
+ }
139
+ ];
140
+ exports.CivilianCADAPITypes = [
141
+ {
142
+ type: 'GET_CHARACTERS',
143
+ path: 'civilian/get_characters',
144
+ method: 'POST',
145
+ minVersion: 2
146
+ },
147
+ {
148
+ type: 'NEW_CHARACTER',
149
+ path: 'civilian/new_character',
150
+ method: 'POST',
151
+ minVersion: 2
152
+ },
153
+ {
154
+ type: 'EDIT_CHARACTER',
155
+ path: 'civilian/edit_characters',
156
+ method: 'POST',
157
+ minVersion: 2
158
+ },
159
+ {
160
+ type: 'REMOVE_CHARACTER',
161
+ path: 'civilian/remove_character',
162
+ method: 'POST',
163
+ minVersion: 2
164
+ }
165
+ ];
166
+ exports.EmergencyCADAPITypes = [
167
+ {
168
+ type: 'GET_IDENTIFIERS',
169
+ path: 'emergency/get_identifiers',
170
+ method: 'POST',
171
+ minVersion: 3
172
+ },
173
+ {
174
+ type: 'MODIFY_IDENTIFIER',
175
+ path: 'emergency/modify_identifier',
176
+ method: 'POST',
177
+ minVersion: 4
178
+ },
179
+ {
180
+ type: 'SET_IDENTIFIER',
181
+ path: 'emergency/set_identifier',
182
+ method: 'POST',
183
+ minVersion: 3
184
+ },
185
+ {
186
+ type: 'UNIT_PANIC',
187
+ path: 'emergency/unit_panic',
188
+ method: 'POST',
189
+ minVersion: 2
190
+ },
191
+ {
192
+ type: 'UNIT_STATUS',
193
+ path: 'emergency/unit_status',
194
+ method: 'POST',
195
+ minVersion: 2
196
+ },
197
+ {
198
+ type: 'GET_BLIPS',
199
+ path: 'emergency/get_blips',
200
+ method: 'POST',
201
+ minVersion: 4
202
+ },
203
+ {
204
+ type: 'ADD_BLIP',
205
+ path: 'emergency/add_blip',
206
+ method: 'POST',
207
+ minVersion: 4
208
+ },
209
+ {
210
+ type: 'MODIFY_BLIP',
211
+ path: 'emergency/modify_blip',
212
+ method: 'POST',
213
+ minVersion: 4
214
+ },
215
+ {
216
+ type: 'REMOVE_BLIP',
217
+ path: 'emergency/remove_blip',
218
+ method: 'POST',
219
+ minVersion: 4
220
+ },
221
+ {
222
+ type: '911_CALL',
223
+ path: 'emergency/911_call',
224
+ method: 'POST',
225
+ minVersion: 2
226
+ },
227
+ {
228
+ type: 'REMOVE_911',
229
+ path: 'emergency/remove_911',
230
+ method: 'POST',
231
+ minVersion: 2
232
+ },
233
+ {
234
+ type: 'GET_CALLS',
235
+ path: 'emergency/get_calls',
236
+ method: 'POST',
237
+ minVersion: 3
238
+ },
239
+ {
240
+ type: 'GET_ACTIVE_UNITS',
241
+ path: 'emergency/get_active_units',
242
+ method: 'POST',
243
+ minVersion: 3
244
+ },
245
+ {
246
+ type: 'KICK_UNIT',
247
+ path: 'emergency/kick_unit',
248
+ method: 'POST',
249
+ minVersion: 2
250
+ },
251
+ {
252
+ type: 'NEW_DISPATCH',
253
+ path: 'emergency/new_dispatch',
254
+ method: 'POST',
255
+ minVersion: 3
256
+ },
257
+ {
258
+ type: 'ATTACH_UNIT',
259
+ path: 'emergency/attach_unit',
260
+ method: 'POST',
261
+ minVersion: 3
262
+ },
263
+ {
264
+ type: 'DETACH_UNIT',
265
+ path: 'emergency/detach_unit',
266
+ method: 'POST',
267
+ minVersion: 3
268
+ },
269
+ {
270
+ type: 'SET_CALL_POSTAL',
271
+ path: 'emergency/set_call_postal',
272
+ method: 'POST',
273
+ minVersion: 3
274
+ },
275
+ {
276
+ type: 'SET_CALL_PRIMARY',
277
+ path: 'emergency/set_call_primary',
278
+ method: 'POST',
279
+ minVersion: 3
280
+ },
281
+ {
282
+ type: 'ADD_CALL_NOTE',
283
+ path: 'emergency/add_call_note',
284
+ method: 'POST',
285
+ minVersion: 3
286
+ },
287
+ {
288
+ type: 'CLOSE_CALL',
289
+ path: 'emergency/close_call',
290
+ method: 'POST',
291
+ minVersion: 2
292
+ },
293
+ {
294
+ type: 'UNIT_LOCATION',
295
+ path: 'emergency/unit_location',
296
+ method: 'POST',
297
+ minVersion: 2
298
+ },
299
+ {
300
+ type: 'SET_STREETSIGN_CONFIG',
301
+ path: 'emergency/set_streetsign_config',
302
+ method: 'POST',
303
+ minVersion: 4
304
+ },
305
+ {
306
+ type: 'UPDATE_STREETSIGN',
307
+ path: 'emergency/update_streetsign',
308
+ method: 'POST',
309
+ minVersion: 4
310
+ }
311
+ ];
312
+ exports.GeneralCMSAPITypes = [
313
+ {
314
+ type: 'GET_COM_ACCOUNT',
315
+ path: 'general/get_com_account',
316
+ method: 'POST',
317
+ minVersion: 3
318
+ },
319
+ {
320
+ type: 'GET_ACCOUNT_RANKS',
321
+ path: 'general/get_account_ranks',
322
+ method: 'POST',
323
+ minVersion: 2,
324
+ },
325
+ {
326
+ type: 'GET_SUB_VERSION',
327
+ path: 'general/get_sub_version',
328
+ method: 'POST',
329
+ minVersion: 0
330
+ },
331
+ {
332
+ type: 'CHECK_COM_APIID',
333
+ path: 'general/check_com_apiid',
334
+ method: 'POST',
335
+ minVersion: 2
336
+ },
337
+ {
338
+ type: 'CLOCK_IN_OUT',
339
+ path: 'general/clock_in_out',
340
+ method: 'POST',
341
+ minVersion: 3
342
+ }
343
+ ];
344
+ exports.ServersCMSAPITypes = [
345
+ {
346
+ type: 'GET_GAME_SERVERS',
347
+ path: 'servers/get_game_servers',
348
+ method: 'POST',
349
+ minVersion: 2
350
+ },
351
+ {
352
+ type: 'VERIFY_WHITELIST',
353
+ path: 'servers/verify_whitelist',
354
+ method: 'POST',
355
+ minVersion: 3
356
+ },
357
+ {
358
+ type: 'FULL_WHITELIST',
359
+ path: 'servers/full_whitelist',
360
+ method: 'POST',
361
+ minVersion: 3
362
+ }
363
+ ];
364
+ function formatForAll(array, product) {
365
+ return array.map((val) => {
366
+ return {
367
+ ...val,
368
+ product
369
+ };
370
+ });
371
+ }
372
+ exports.AllAPITypes = [...formatForAll(exports.GeneralCADAPITypes, constants_1.productEnums.CAD), ...formatForAll(exports.CivilianCADAPITypes, constants_1.productEnums.CAD), ...formatForAll(exports.EmergencyCADAPITypes, constants_1.productEnums.CAD), ...formatForAll(exports.GeneralCMSAPITypes, constants_1.productEnums.CMS), ...formatForAll(exports.ServersCMSAPITypes, constants_1.productEnums.CMS)];
373
+ var CADRecordTypeEnums;
374
+ (function (CADRecordTypeEnums) {
375
+ CADRecordTypeEnums[CADRecordTypeEnums["Warrant"] = 2] = "Warrant";
376
+ CADRecordTypeEnums[CADRecordTypeEnums["Bolo"] = 3] = "Bolo";
377
+ CADRecordTypeEnums[CADRecordTypeEnums["License"] = 4] = "License";
378
+ CADRecordTypeEnums[CADRecordTypeEnums["VehicleRegistration"] = 5] = "VehicleRegistration";
379
+ CADRecordTypeEnums[CADRecordTypeEnums["Character"] = 7] = "Character";
380
+ CADRecordTypeEnums[CADRecordTypeEnums["PoliceRecord"] = 8] = "PoliceRecord";
381
+ CADRecordTypeEnums[CADRecordTypeEnums["PoliceReport"] = 9] = "PoliceReport";
382
+ CADRecordTypeEnums[CADRecordTypeEnums["MedicalRecord"] = 10] = "MedicalRecord";
383
+ CADRecordTypeEnums[CADRecordTypeEnums["MedicalReport"] = 11] = "MedicalReport";
384
+ CADRecordTypeEnums[CADRecordTypeEnums["FireRecord"] = 12] = "FireRecord";
385
+ CADRecordTypeEnums[CADRecordTypeEnums["FireReport"] = 13] = "FireReport";
386
+ CADRecordTypeEnums[CADRecordTypeEnums["DMVRecord"] = 14] = "DMVRecord";
387
+ CADRecordTypeEnums[CADRecordTypeEnums["LawRecord"] = 15] = "LawRecord";
388
+ CADRecordTypeEnums[CADRecordTypeEnums["LawReport"] = 16] = "LawReport";
389
+ })(CADRecordTypeEnums = exports.CADRecordTypeEnums || (exports.CADRecordTypeEnums = {}));
390
+ var CADRecordSectionCategoryEnums;
391
+ (function (CADRecordSectionCategoryEnums) {
392
+ CADRecordSectionCategoryEnums[CADRecordSectionCategoryEnums["Custom"] = 0] = "Custom";
393
+ CADRecordSectionCategoryEnums[CADRecordSectionCategoryEnums["Flags"] = 1] = "Flags";
394
+ CADRecordSectionCategoryEnums[CADRecordSectionCategoryEnums["Speed"] = 5] = "Speed";
395
+ CADRecordSectionCategoryEnums[CADRecordSectionCategoryEnums["Charges"] = 6] = "Charges";
396
+ CADRecordSectionCategoryEnums[CADRecordSectionCategoryEnums["LinkedRecords"] = 9] = "LinkedRecords";
397
+ })(CADRecordSectionCategoryEnums = exports.CADRecordSectionCategoryEnums || (exports.CADRecordSectionCategoryEnums = {}));
398
+ var CADLookupByIntSearchTypeEnums;
399
+ (function (CADLookupByIntSearchTypeEnums) {
400
+ CADLookupByIntSearchTypeEnums[CADLookupByIntSearchTypeEnums["IDENTIFIER"] = 0] = "IDENTIFIER";
401
+ CADLookupByIntSearchTypeEnums[CADLookupByIntSearchTypeEnums["SUPERVISOR_STATUS"] = 1] = "SUPERVISOR_STATUS";
402
+ CADLookupByIntSearchTypeEnums[CADLookupByIntSearchTypeEnums["ACTIVE_STATUS"] = 2] = "ACTIVE_STATUS";
403
+ CADLookupByIntSearchTypeEnums[CADLookupByIntSearchTypeEnums["NUMBER"] = 3] = "NUMBER";
404
+ })(CADLookupByIntSearchTypeEnums = exports.CADLookupByIntSearchTypeEnums || (exports.CADLookupByIntSearchTypeEnums = {}));
405
+ var CADModifyIdentifierActionEnums;
406
+ (function (CADModifyIdentifierActionEnums) {
407
+ CADModifyIdentifierActionEnums[CADModifyIdentifierActionEnums["ADD"] = 0] = "ADD";
408
+ CADModifyIdentifierActionEnums[CADModifyIdentifierActionEnums["EDIT"] = 1] = "EDIT";
409
+ CADModifyIdentifierActionEnums[CADModifyIdentifierActionEnums["REMOVE"] = 2] = "REMOVE";
410
+ })(CADModifyIdentifierActionEnums = exports.CADModifyIdentifierActionEnums || (exports.CADModifyIdentifierActionEnums = {}));
411
+ var CADDispatchOriginEnums;
412
+ (function (CADDispatchOriginEnums) {
413
+ CADDispatchOriginEnums[CADDispatchOriginEnums["Caller"] = 0] = "Caller";
414
+ CADDispatchOriginEnums[CADDispatchOriginEnums["RadioDispatch"] = 1] = "RadioDispatch";
415
+ CADDispatchOriginEnums[CADDispatchOriginEnums["Observed"] = 2] = "Observed";
416
+ CADDispatchOriginEnums[CADDispatchOriginEnums["WalkUp"] = 3] = "WalkUp";
417
+ })(CADDispatchOriginEnums = exports.CADDispatchOriginEnums || (exports.CADDispatchOriginEnums = {}));
418
+ var CADDispatchStatusEnums;
419
+ (function (CADDispatchStatusEnums) {
420
+ CADDispatchStatusEnums[CADDispatchStatusEnums["Pending"] = 0] = "Pending";
421
+ CADDispatchStatusEnums[CADDispatchStatusEnums["Active"] = 1] = "Active";
422
+ CADDispatchStatusEnums[CADDispatchStatusEnums["Closed"] = 2] = "Closed";
423
+ })(CADDispatchStatusEnums = exports.CADDispatchStatusEnums || (exports.CADDispatchStatusEnums = {}));
@@ -0,0 +1,14 @@
1
+ import { Instance } from '../instance/Instance';
2
+ /**
3
+ * Manages the API methods of a data model or a specific product methods.
4
+ * @abstract
5
+ */
6
+ export declare abstract class BaseManager {
7
+ readonly instance: Instance;
8
+ /**
9
+ *
10
+ * @param {Instance} instance The instance that instantiated this Manager
11
+ * @readonly
12
+ */
13
+ constructor(instance: Instance);
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseManager = void 0;
4
+ /**
5
+ * Manages the API methods of a data model or a specific product methods.
6
+ * @abstract
7
+ */
8
+ class BaseManager {
9
+ /**
10
+ *
11
+ * @param {Instance} instance The instance that instantiated this Manager
12
+ * @readonly
13
+ */
14
+ constructor(instance) {
15
+ this.instance = instance;
16
+ }
17
+ }
18
+ exports.BaseManager = BaseManager;
@@ -0,0 +1,15 @@
1
+ import { Instance } from '../instance/Instance';
2
+ import { CADActiveUnit, CADActiveUnitResolvable, CADActiveUnitStruct } from '../structures/CADActiveUnit';
3
+ import { CacheManager } from './CacheManager';
4
+ export declare class CADActiveUnitsManager extends CacheManager<number, CADActiveUnit, CADActiveUnitResolvable> {
5
+ serverId: number;
6
+ instance: Instance;
7
+ constructor(instance: Instance, iterable: Iterable<CADActiveUnitStruct>, serverId: number);
8
+ _add(data: any, cache?: boolean): any;
9
+ fetch(): void;
10
+ _fetchSingle({ unit, includeOffline, force }: {
11
+ unit: CADActiveUnitResolvable;
12
+ includeOffline: boolean;
13
+ force: boolean;
14
+ }): Promise<any>;
15
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ // Work in progress still...
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CADActiveUnitsManager = void 0;
5
+ const CADActiveUnit_1 = require("../structures/CADActiveUnit");
6
+ const CacheManager_1 = require("./CacheManager");
7
+ class CADActiveUnitsManager extends CacheManager_1.CacheManager {
8
+ constructor(instance, iterable, serverId) {
9
+ super(instance, CADActiveUnit_1.CADActiveUnit, iterable);
10
+ this.instance = instance;
11
+ this.serverId = serverId;
12
+ }
13
+ _add(data, cache = true) {
14
+ return super._add(data, cache, data.id);
15
+ }
16
+ fetch( /*options: CADActiveUnitResolvable | CADActiveUnitFetchOptions**/) {
17
+ // if (!options) return this._fetchMany();
18
+ this._fetchSingle({
19
+ unit: -1,
20
+ includeOffline: false,
21
+ force: false
22
+ });
23
+ }
24
+ async _fetchSingle({ unit, includeOffline = false, force = false }) {
25
+ var _a, _b;
26
+ if (!force) {
27
+ const existing = this.cache.get(unit);
28
+ if (existing)
29
+ return existing;
30
+ }
31
+ const data = await ((_b = (_a = this.instance.cad) === null || _a === void 0 ? void 0 : _a.rest) === null || _b === void 0 ? void 0 : _b.request('GET_ACTIVE_UNITS', {
32
+ serverId: this.serverId,
33
+ includeOffline
34
+ }));
35
+ console.log(data);
36
+ }
37
+ }
38
+ exports.CADActiveUnitsManager = CADActiveUnitsManager;
@@ -0,0 +1,27 @@
1
+ import { Instance } from '../instance/Instance';
2
+ import { CADSubscriptionVersionEnum } from '../constants';
3
+ import { REST } from '../libs/rest/src';
4
+ import { BaseManager } from './BaseManager';
5
+ import * as globalTypes from '../constants';
6
+ import { CADServerManager } from './CADServerManager';
7
+ /**
8
+ * Manages all Sonoran CAD data and methods to interact with the public API.
9
+ */
10
+ export declare class CADManager extends BaseManager {
11
+ readonly version: CADSubscriptionVersionEnum;
12
+ rest: REST | undefined;
13
+ servers: CADServerManager | undefined;
14
+ constructor(instance: Instance);
15
+ protected buildManager(instance: Instance): Promise<void>;
16
+ /**
17
+ * Gets a community account by `accId` or `apiId`.
18
+ * @param {Object} params The object that contains parameters to get a community account.
19
+ * @param {string} [data.accId] The account id to find a community account.
20
+ * @param {string} [data.apiId] The api id to find a community account.
21
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
22
+ */
23
+ getAccount(params: {
24
+ apiId?: string;
25
+ username?: string;
26
+ }): Promise<globalTypes.CADGetAccountPromiseResult>;
27
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CADManager = void 0;
27
+ const src_1 = require("../libs/rest/src");
28
+ const BaseManager_1 = require("./BaseManager");
29
+ const globalTypes = __importStar(require("../constants"));
30
+ const CADServerManager_1 = require("./CADServerManager");
31
+ /**
32
+ * Manages all Sonoran CAD data and methods to interact with the public API.
33
+ */
34
+ class CADManager extends BaseManager_1.BaseManager {
35
+ constructor(instance) {
36
+ super(instance);
37
+ this.version = 0;
38
+ this.rest = new src_1.REST(instance, this, globalTypes.productEnums.CAD, src_1.DefaultCADRestOptions);
39
+ this.buildManager(instance);
40
+ }
41
+ async buildManager(instance) {
42
+ var _a;
43
+ try {
44
+ const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_VERSION'));
45
+ const mutableThis = this;
46
+ mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
47
+ if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
48
+ this.servers = new CADServerManager_1.CADServerManager(instance, this);
49
+ }
50
+ instance.isCADSuccessful = true;
51
+ }
52
+ catch (err) {
53
+ console.log(err);
54
+ }
55
+ }
56
+ /**
57
+ * Gets a community account by `accId` or `apiId`.
58
+ * @param {Object} params The object that contains parameters to get a community account.
59
+ * @param {string} [data.accId] The account id to find a community account.
60
+ * @param {string} [data.apiId] The api id to find a community account.
61
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
62
+ */
63
+ async getAccount(params) {
64
+ return new Promise(async (resolve, reject) => {
65
+ var _a;
66
+ try {
67
+ const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT', params.apiId, params.username));
68
+ resolve({ success: true, data: getAccountRequest });
69
+ }
70
+ catch (err) {
71
+ if (err instanceof src_1.APIError) {
72
+ resolve({ success: false, reason: err.response });
73
+ }
74
+ else {
75
+ reject(err);
76
+ }
77
+ }
78
+ });
79
+ }
80
+ }
81
+ exports.CADManager = CADManager;
@@ -0,0 +1,8 @@
1
+ import { Instance } from '../instance/Instance';
2
+ import { CADServerAPIStruct } from '../libs/rest/src';
3
+ import { CADServer } from '../structures/CADServer';
4
+ import { CacheManager } from './CacheManager';
5
+ import { CADManager } from './CADManager';
6
+ export declare class CADServerManager extends CacheManager<number, CADServer, CADServerAPIStruct> {
7
+ constructor(instance: Instance, manager: CADManager);
8
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CADServerManager = void 0;
4
+ const CADServer_1 = require("../structures/CADServer");
5
+ const CacheManager_1 = require("./CacheManager");
6
+ class CADServerManager extends CacheManager_1.CacheManager {
7
+ constructor(instance, manager) {
8
+ super(instance, CADServer_1.CADServer, []);
9
+ (async () => {
10
+ var _a;
11
+ try {
12
+ const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SERVERS'));
13
+ const servers = JSON.parse(serversRes).servers;
14
+ servers.forEach((server) => {
15
+ const serverStruct = {
16
+ id: server.id,
17
+ config: server
18
+ };
19
+ this._add(serverStruct, true, server.id);
20
+ });
21
+ }
22
+ catch (err) {
23
+ throw new Error(String(err));
24
+ }
25
+ })();
26
+ }
27
+ }
28
+ exports.CADServerManager = CADServerManager;