@sonoransoftware/sonoran.js 1.0.34 → 1.0.36
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/.github/workflows/auto-pr-on-branch-push.yml +89 -0
- package/.github/workflows/codex_instructions.md +24 -0
- package/.github/workflows/push-pr-nudge-codex.yml +50 -0
- package/dist/constants.d.ts +242 -1
- package/dist/constants.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/instance/Instance.d.ts +6 -0
- package/dist/instance/Instance.js +27 -0
- package/dist/instance/instance.types.d.ts +3 -0
- package/dist/libs/rest/src/lib/REST.d.ts +2 -1
- package/dist/libs/rest/src/lib/REST.js +118 -0
- package/dist/libs/rest/src/lib/RequestManager.d.ts +2 -0
- package/dist/libs/rest/src/lib/RequestManager.js +209 -0
- package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -1
- package/dist/libs/rest/src/lib/utils/constants.d.ts +108 -24
- package/dist/libs/rest/src/lib/utils/constants.js +118 -2
- package/dist/managers/CADActiveUnitsManager.d.ts +3 -0
- package/dist/managers/CADActiveUnitsManager.js +16 -6
- package/dist/managers/CADManager.d.ts +223 -0
- package/dist/managers/CADManager.js +513 -4
- package/dist/managers/CADServerManager.d.ts +11 -0
- package/dist/managers/CADServerManager.js +56 -13
- package/dist/managers/CMSManager.d.ts +78 -0
- package/dist/managers/CMSManager.js +213 -3
- package/dist/managers/CMSServerManager.d.ts +8 -0
- package/dist/managers/CMSServerManager.js +61 -18
- package/dist/managers/RadioManager.d.ts +55 -0
- package/dist/managers/RadioManager.js +224 -0
- package/package.json +1 -1
- package/readme.md +294 -12
- package/src/constants.ts +281 -1
- package/src/index.ts +42 -1
- package/src/instance/Instance.ts +30 -1
- package/src/instance/instance.types.ts +4 -1
- package/src/libs/rest/src/lib/REST.ts +117 -1
- package/src/libs/rest/src/lib/RequestManager.ts +229 -10
- package/src/libs/rest/src/lib/errors/RateLimitError.ts +20 -2
- package/src/libs/rest/src/lib/utils/constants.ts +223 -26
- package/src/managers/CADActiveUnitsManager.ts +19 -6
- package/src/managers/CADManager.ts +574 -4
- package/src/managers/CADServerManager.ts +59 -15
- package/src/managers/CMSManager.ts +196 -2
- package/src/managers/CMSServerManager.ts +65 -21
- package/src/managers/RadioManager.ts +187 -0
|
@@ -41,12 +41,11 @@ class CADManager extends BaseManager_1.BaseManager {
|
|
|
41
41
|
this.buildManager(instance);
|
|
42
42
|
}
|
|
43
43
|
async buildManager(instance) {
|
|
44
|
-
var _a;
|
|
45
44
|
const mutableThis = this;
|
|
46
45
|
try {
|
|
47
|
-
const
|
|
48
|
-
mutableThis.version =
|
|
49
|
-
if (
|
|
46
|
+
const version = await this.getVersion();
|
|
47
|
+
mutableThis.version = version;
|
|
48
|
+
if (version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
|
|
50
49
|
this.servers = new CADServerManager_1.CADServerManager(instance, this);
|
|
51
50
|
}
|
|
52
51
|
instance.isCADSuccessful = true;
|
|
@@ -58,6 +57,33 @@ class CADManager extends BaseManager_1.BaseManager {
|
|
|
58
57
|
throw err;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
60
|
+
getRest() {
|
|
61
|
+
if (!this.rest) {
|
|
62
|
+
throw new Error('CAD REST client is not initialized.');
|
|
63
|
+
}
|
|
64
|
+
return this.rest;
|
|
65
|
+
}
|
|
66
|
+
async executeCadRequest(type, ...args) {
|
|
67
|
+
try {
|
|
68
|
+
const response = await this.getRest().request(type, ...args);
|
|
69
|
+
return { success: true, data: response };
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err instanceof src_1.APIError) {
|
|
73
|
+
return { success: false, reason: err.response };
|
|
74
|
+
}
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves the community's CAD subscription version.
|
|
80
|
+
*/
|
|
81
|
+
async getVersion() {
|
|
82
|
+
var _a;
|
|
83
|
+
const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_VERSION'));
|
|
84
|
+
const versionString = String(versionResp);
|
|
85
|
+
return Number.parseInt(versionString.replace(/(^\d+)(.+$)/i, '$1'), 10);
|
|
86
|
+
}
|
|
61
87
|
/**
|
|
62
88
|
* Gets a community account by `accId` or `apiId`.
|
|
63
89
|
* @param {Object} params The object that contains parameters to get a community account.
|
|
@@ -82,5 +108,488 @@ class CADManager extends BaseManager_1.BaseManager {
|
|
|
82
108
|
}
|
|
83
109
|
});
|
|
84
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Updates the CAD clock to match in-game time.
|
|
113
|
+
*/
|
|
114
|
+
async setClockTime(data) {
|
|
115
|
+
return new Promise(async (resolve, reject) => {
|
|
116
|
+
var _a;
|
|
117
|
+
try {
|
|
118
|
+
const response = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('SET_CLOCK', data));
|
|
119
|
+
resolve({ success: true, data: response });
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
if (err instanceof src_1.APIError) {
|
|
123
|
+
resolve({ success: false, reason: err.response });
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
reject(err);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Adds accounts to the community via the join community endpoint.
|
|
133
|
+
* NOTE: This endpoint is intended for internal CMS use and requires an internal key.
|
|
134
|
+
*/
|
|
135
|
+
async joinCommunity(internalKey, accounts) {
|
|
136
|
+
if (!internalKey) {
|
|
137
|
+
throw new Error('internalKey is required to join a community.');
|
|
138
|
+
}
|
|
139
|
+
const normalizedAccounts = this.normalizeAccountEntries(accounts);
|
|
140
|
+
if (normalizedAccounts.length === 0) {
|
|
141
|
+
throw new Error('At least one account must be provided to join the community.');
|
|
142
|
+
}
|
|
143
|
+
return new Promise(async (resolve, reject) => {
|
|
144
|
+
var _a;
|
|
145
|
+
try {
|
|
146
|
+
const response = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('JOIN_COMMUNITY', { internalKey, accounts: normalizedAccounts }));
|
|
147
|
+
resolve({ success: true, data: response });
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
if (err instanceof src_1.APIError) {
|
|
151
|
+
resolve({ success: false, reason: err.response });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
reject(err);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Removes accounts from the community via the leave community endpoint.
|
|
161
|
+
* NOTE: This endpoint is intended for internal CMS use and requires an internal key.
|
|
162
|
+
*/
|
|
163
|
+
async leaveCommunity(internalKey, accounts) {
|
|
164
|
+
if (!internalKey) {
|
|
165
|
+
throw new Error('internalKey is required to leave a community.');
|
|
166
|
+
}
|
|
167
|
+
const normalizedAccounts = this.normalizeAccountEntries(accounts);
|
|
168
|
+
if (normalizedAccounts.length === 0) {
|
|
169
|
+
throw new Error('At least one account must be provided to leave the community.');
|
|
170
|
+
}
|
|
171
|
+
return new Promise(async (resolve, reject) => {
|
|
172
|
+
var _a;
|
|
173
|
+
try {
|
|
174
|
+
const response = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('LEAVE_COMMUNITY', { internalKey, accounts: normalizedAccounts }));
|
|
175
|
+
resolve({ success: true, data: response });
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
if (err instanceof src_1.APIError) {
|
|
179
|
+
resolve({ success: false, reason: err.response });
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
reject(err);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Updates the penal code configuration for the community.
|
|
189
|
+
*/
|
|
190
|
+
async setPenalCodes(codes) {
|
|
191
|
+
if (!Array.isArray(codes) || codes.length === 0) {
|
|
192
|
+
throw new Error('codes array must include at least one penal code entry.');
|
|
193
|
+
}
|
|
194
|
+
return this.executeCadRequest('SET_PENAL_CODES', codes);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Assigns API IDs to a community account.
|
|
198
|
+
*/
|
|
199
|
+
async setAccountApiIds(data) {
|
|
200
|
+
if (!(data === null || data === void 0 ? void 0 : data.username) || !Array.isArray(data.apiIds)) {
|
|
201
|
+
throw new Error('username and apiIds are required to set account API IDs.');
|
|
202
|
+
}
|
|
203
|
+
return this.executeCadRequest('SET_API_ID', data);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Retrieves record templates filtered by a specific record type.
|
|
207
|
+
*/
|
|
208
|
+
async getRecordTemplates(recordTypeId) {
|
|
209
|
+
if (typeof recordTypeId === 'number') {
|
|
210
|
+
return this.executeCadRequest('GET_TEMPLATES', recordTypeId);
|
|
211
|
+
}
|
|
212
|
+
return this.executeCadRequest('GET_TEMPLATES');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Creates a new record entry.
|
|
216
|
+
*/
|
|
217
|
+
async createRecord(data) {
|
|
218
|
+
return this.executeCadRequest('NEW_RECORD', data);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Updates an existing record entry.
|
|
222
|
+
*/
|
|
223
|
+
async updateRecord(data) {
|
|
224
|
+
return this.executeCadRequest('EDIT_RECORD', data);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Removes a record by its identifier.
|
|
228
|
+
*/
|
|
229
|
+
async removeRecord(id) {
|
|
230
|
+
if (!Number.isInteger(id)) {
|
|
231
|
+
throw new Error('id must be an integer when removing a record.');
|
|
232
|
+
}
|
|
233
|
+
return this.executeCadRequest('REMOVE_RECORD', id);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Performs an internal lookup using the CAD lookup by identifier endpoint.
|
|
237
|
+
*/
|
|
238
|
+
async lookupByInt(data) {
|
|
239
|
+
if (!data || !('searchType' in data) || !('value' in data)) {
|
|
240
|
+
throw new Error('searchType and value are required for lookupByInt.');
|
|
241
|
+
}
|
|
242
|
+
return this.executeCadRequest('LOOKUP_INT', data);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Executes a CAD lookup using first/last name, plate, or other values.
|
|
246
|
+
*/
|
|
247
|
+
async lookupRecords(data) {
|
|
248
|
+
return this.executeCadRequest('LOOKUP', data);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Checks whether the provided API ID exists.
|
|
252
|
+
*/
|
|
253
|
+
async checkApiId(apiId) {
|
|
254
|
+
if (!apiId) {
|
|
255
|
+
throw new Error('apiId is required to check for existence.');
|
|
256
|
+
}
|
|
257
|
+
return this.executeCadRequest('CHECK_APIID', apiId);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Applies a permission key to an account.
|
|
261
|
+
*/
|
|
262
|
+
async applyPermissionKey(apiId, permissionKey) {
|
|
263
|
+
if (!permissionKey) {
|
|
264
|
+
throw new Error('permissionKey is required when applying a permission key.');
|
|
265
|
+
}
|
|
266
|
+
return this.executeCadRequest('APPLY_PERMISSION_KEY', apiId, permissionKey);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Sets account permissions for a CAD user.
|
|
270
|
+
*/
|
|
271
|
+
async setAccountPermissions(data) {
|
|
272
|
+
if (!data || (!Array.isArray(data.add) && !Array.isArray(data.remove))) {
|
|
273
|
+
throw new Error('At least one permission change is required.');
|
|
274
|
+
}
|
|
275
|
+
return this.executeCadRequest('SET_ACCOUNT_PERMISSIONS', data);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Bans or kicks a CAD user.
|
|
279
|
+
*/
|
|
280
|
+
async banUser(data) {
|
|
281
|
+
if (!(data === null || data === void 0 ? void 0 : data.apiId)) {
|
|
282
|
+
throw new Error('apiId is required when banning or kicking a user.');
|
|
283
|
+
}
|
|
284
|
+
return this.executeCadRequest('BAN_USER', data);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Verifies a secret string against CAD configuration.
|
|
288
|
+
*/
|
|
289
|
+
async verifySecret(secret) {
|
|
290
|
+
if (!secret) {
|
|
291
|
+
throw new Error('secret is required to verify.');
|
|
292
|
+
}
|
|
293
|
+
return this.executeCadRequest('VERIFY_SECRET', secret);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Authorizes street sign changes for a CAD server.
|
|
297
|
+
*/
|
|
298
|
+
async authorizeStreetSigns(serverId) {
|
|
299
|
+
if (!Number.isInteger(serverId)) {
|
|
300
|
+
throw new Error('serverId must be an integer when authorizing street signs.');
|
|
301
|
+
}
|
|
302
|
+
return this.executeCadRequest('AUTH_STREETSIGNS', serverId);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Replaces the community postal list.
|
|
306
|
+
*/
|
|
307
|
+
async setPostals(data) {
|
|
308
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
309
|
+
throw new Error('data must include at least one postal entry.');
|
|
310
|
+
}
|
|
311
|
+
return this.executeCadRequest('SET_POSTALS', data);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Sends a photo to CAD for the provided API ID.
|
|
315
|
+
*/
|
|
316
|
+
async sendPhoto(apiId, url) {
|
|
317
|
+
if (!url) {
|
|
318
|
+
throw new Error('url is required to send a CAD photo.');
|
|
319
|
+
}
|
|
320
|
+
return this.executeCadRequest('SEND_PHOTO', apiId, url);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Retrieves characters belonging to an API ID.
|
|
324
|
+
*/
|
|
325
|
+
async getCharacters(apiId) {
|
|
326
|
+
if (!apiId) {
|
|
327
|
+
throw new Error('apiId is required to fetch characters.');
|
|
328
|
+
}
|
|
329
|
+
return this.executeCadRequest('GET_CHARACTERS', apiId);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Creates a new civilian character.
|
|
333
|
+
*/
|
|
334
|
+
async createCharacter(data) {
|
|
335
|
+
return this.executeCadRequest('NEW_CHARACTER', data);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Updates an existing civilian character.
|
|
339
|
+
*/
|
|
340
|
+
async updateCharacter(data) {
|
|
341
|
+
return this.executeCadRequest('EDIT_CHARACTER', data);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Removes a civilian character by identifier.
|
|
345
|
+
*/
|
|
346
|
+
async removeCharacter(id) {
|
|
347
|
+
if (!Number.isInteger(id)) {
|
|
348
|
+
throw new Error('id must be an integer when removing a character.');
|
|
349
|
+
}
|
|
350
|
+
return this.executeCadRequest('REMOVE_CHARACTER', id);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Retrieves identifiers assigned to an API ID.
|
|
354
|
+
*/
|
|
355
|
+
async getIdentifiers(apiId) {
|
|
356
|
+
if (!apiId) {
|
|
357
|
+
throw new Error('apiId is required to fetch identifiers.');
|
|
358
|
+
}
|
|
359
|
+
return this.executeCadRequest('GET_IDENTIFIERS', apiId);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Modifies identifiers for an account.
|
|
363
|
+
*/
|
|
364
|
+
async modifyIdentifier(data) {
|
|
365
|
+
if (!(data === null || data === void 0 ? void 0 : data.apiId)) {
|
|
366
|
+
throw new Error('apiId is required when modifying an identifier.');
|
|
367
|
+
}
|
|
368
|
+
return this.executeCadRequest('MODIFY_IDENTIFIER', data);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Sets the active identifier by identifier ID.
|
|
372
|
+
*/
|
|
373
|
+
async setIdentifier(apiId, identId) {
|
|
374
|
+
if (!Number.isInteger(identId)) {
|
|
375
|
+
throw new Error('identId must be an integer when setting an identifier.');
|
|
376
|
+
}
|
|
377
|
+
return this.executeCadRequest('SET_IDENTIFIER', apiId, identId);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Toggles panic state for a unit.
|
|
381
|
+
*/
|
|
382
|
+
async setUnitPanic(apiId, isPanic) {
|
|
383
|
+
return this.executeCadRequest('UNIT_PANIC', apiId, isPanic);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Updates a unit's status.
|
|
387
|
+
*/
|
|
388
|
+
async setUnitStatus(apiId, status, serverId) {
|
|
389
|
+
if (!Number.isInteger(serverId)) {
|
|
390
|
+
throw new Error('serverId must be an integer when updating unit status.');
|
|
391
|
+
}
|
|
392
|
+
return this.executeCadRequest('UNIT_STATUS', apiId, status, serverId);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Retrieves live map blips for a CAD server.
|
|
396
|
+
*/
|
|
397
|
+
async getBlips(serverId) {
|
|
398
|
+
if (!Number.isInteger(serverId)) {
|
|
399
|
+
throw new Error('serverId must be an integer when retrieving blips.');
|
|
400
|
+
}
|
|
401
|
+
return this.executeCadRequest('GET_BLIPS', serverId);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Adds blips to the CAD map.
|
|
405
|
+
*/
|
|
406
|
+
async addBlips(blips) {
|
|
407
|
+
const payload = Array.isArray(blips) ? blips : [blips];
|
|
408
|
+
if (payload.length === 0) {
|
|
409
|
+
throw new Error('At least one blip must be provided when adding blips.');
|
|
410
|
+
}
|
|
411
|
+
return this.executeCadRequest('ADD_BLIP', payload);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Updates existing CAD map blips.
|
|
415
|
+
*/
|
|
416
|
+
async updateBlips(blips) {
|
|
417
|
+
const payload = Array.isArray(blips) ? blips : [blips];
|
|
418
|
+
if (payload.length === 0) {
|
|
419
|
+
throw new Error('At least one blip must be provided when updating blips.');
|
|
420
|
+
}
|
|
421
|
+
return this.executeCadRequest('MODIFY_BLIP', payload);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Removes a CAD map blip.
|
|
425
|
+
*/
|
|
426
|
+
async removeBlip(id) {
|
|
427
|
+
if (!Number.isInteger(id)) {
|
|
428
|
+
throw new Error('id must be an integer when removing a blip.');
|
|
429
|
+
}
|
|
430
|
+
return this.executeCadRequest('REMOVE_BLIP', id);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Creates a new 911 call entry.
|
|
434
|
+
*/
|
|
435
|
+
async create911Call(params) {
|
|
436
|
+
const { serverId, isEmergency, caller, location, description, metaData = {} } = params;
|
|
437
|
+
if (!Number.isInteger(serverId)) {
|
|
438
|
+
throw new Error('serverId must be an integer when creating a 911 call.');
|
|
439
|
+
}
|
|
440
|
+
return this.executeCadRequest('911_CALL', serverId, isEmergency, caller, location, description, metaData);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Removes a 911 call by its identifier.
|
|
444
|
+
*/
|
|
445
|
+
async remove911Call(callId) {
|
|
446
|
+
if (!Number.isInteger(callId)) {
|
|
447
|
+
throw new Error('callId must be an integer when removing a 911 call.');
|
|
448
|
+
}
|
|
449
|
+
return this.executeCadRequest('REMOVE_911', callId);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Retrieves dispatch calls with optional pagination.
|
|
453
|
+
*/
|
|
454
|
+
async getCalls(options) {
|
|
455
|
+
return this.executeCadRequest('GET_CALLS', options);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Retrieves active units for the provided filters.
|
|
459
|
+
*/
|
|
460
|
+
async getActiveUnits(options) {
|
|
461
|
+
return this.executeCadRequest('GET_ACTIVE_UNITS', options);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Kicks an active unit from the CAD.
|
|
465
|
+
*/
|
|
466
|
+
async kickUnit(apiId, reason, serverId) {
|
|
467
|
+
if (!reason) {
|
|
468
|
+
throw new Error('reason is required when kicking a unit.');
|
|
469
|
+
}
|
|
470
|
+
if (!Number.isInteger(serverId)) {
|
|
471
|
+
throw new Error('serverId must be an integer when kicking a unit.');
|
|
472
|
+
}
|
|
473
|
+
return this.executeCadRequest('KICK_UNIT', apiId, reason, serverId);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Creates a new dispatch call.
|
|
477
|
+
*/
|
|
478
|
+
async createDispatch(data) {
|
|
479
|
+
return this.executeCadRequest('NEW_DISPATCH', data);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Attaches units to an existing dispatch call.
|
|
483
|
+
*/
|
|
484
|
+
async attachUnits(serverId, callId, units) {
|
|
485
|
+
if (!Number.isInteger(serverId) || !Number.isInteger(callId)) {
|
|
486
|
+
throw new Error('serverId and callId must be integers when attaching units.');
|
|
487
|
+
}
|
|
488
|
+
if (!Array.isArray(units) || units.length === 0) {
|
|
489
|
+
throw new Error('units must include at least one entry when attaching.');
|
|
490
|
+
}
|
|
491
|
+
return this.executeCadRequest('ATTACH_UNIT', serverId, callId, units);
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Detaches units from dispatch calls.
|
|
495
|
+
*/
|
|
496
|
+
async detachUnits(serverId, units) {
|
|
497
|
+
if (!Number.isInteger(serverId)) {
|
|
498
|
+
throw new Error('serverId must be an integer when detaching units.');
|
|
499
|
+
}
|
|
500
|
+
if (!Array.isArray(units) || units.length === 0) {
|
|
501
|
+
throw new Error('units must include at least one entry when detaching.');
|
|
502
|
+
}
|
|
503
|
+
return this.executeCadRequest('DETACH_UNIT', serverId, units);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Updates the postal code on a call.
|
|
507
|
+
*/
|
|
508
|
+
async setCallPostal(serverId, callId, postal) {
|
|
509
|
+
if (!Number.isInteger(serverId) || !Number.isInteger(callId)) {
|
|
510
|
+
throw new Error('serverId and callId must be integers when setting a call postal.');
|
|
511
|
+
}
|
|
512
|
+
if (!postal) {
|
|
513
|
+
throw new Error('postal is required when setting a call postal.');
|
|
514
|
+
}
|
|
515
|
+
return this.executeCadRequest('SET_CALL_POSTAL', serverId, callId, postal);
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Updates a call's primary unit.
|
|
519
|
+
*/
|
|
520
|
+
async setCallPrimary(serverId, callId, primary, trackPrimary) {
|
|
521
|
+
if (!Number.isInteger(serverId) || !Number.isInteger(callId)) {
|
|
522
|
+
throw new Error('serverId and callId must be integers when setting a call primary.');
|
|
523
|
+
}
|
|
524
|
+
return this.executeCadRequest('SET_CALL_PRIMARY', serverId, callId, primary, trackPrimary);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Adds a note to an active call.
|
|
528
|
+
*/
|
|
529
|
+
async addCallNote(serverId, callId, note) {
|
|
530
|
+
if (!Number.isInteger(serverId) || !Number.isInteger(callId)) {
|
|
531
|
+
throw new Error('serverId and callId must be integers when adding a call note.');
|
|
532
|
+
}
|
|
533
|
+
if (!note) {
|
|
534
|
+
throw new Error('note is required when adding a call note.');
|
|
535
|
+
}
|
|
536
|
+
return this.executeCadRequest('ADD_CALL_NOTE', serverId, callId, note);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Closes a CAD call.
|
|
540
|
+
*/
|
|
541
|
+
async closeCall(serverId, callId) {
|
|
542
|
+
if (!Number.isInteger(serverId) || !Number.isInteger(callId)) {
|
|
543
|
+
throw new Error('serverId and callId must be integers when closing a call.');
|
|
544
|
+
}
|
|
545
|
+
return this.executeCadRequest('CLOSE_CALL', serverId, callId);
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Updates live unit locations on the CAD map.
|
|
549
|
+
*/
|
|
550
|
+
async updateUnitLocations(locations) {
|
|
551
|
+
if (!Array.isArray(locations) || locations.length === 0) {
|
|
552
|
+
throw new Error('locations must include at least one entry when updating unit locations.');
|
|
553
|
+
}
|
|
554
|
+
return this.executeCadRequest('UNIT_LOCATION', locations);
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Replaces the street sign configuration for a server.
|
|
558
|
+
*/
|
|
559
|
+
async setStreetSignConfig(serverId, signConfig) {
|
|
560
|
+
if (!Number.isInteger(serverId)) {
|
|
561
|
+
throw new Error('serverId must be an integer when setting street sign config.');
|
|
562
|
+
}
|
|
563
|
+
if (!Array.isArray(signConfig) || signConfig.length === 0) {
|
|
564
|
+
throw new Error('signConfig must include at least one entry when setting street sign config.');
|
|
565
|
+
}
|
|
566
|
+
return this.executeCadRequest('SET_STREETSIGN_CONFIG', serverId, signConfig);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Updates an existing street sign's text.
|
|
570
|
+
*/
|
|
571
|
+
async updateStreetSign(serverId, signData) {
|
|
572
|
+
if (!Number.isInteger(serverId)) {
|
|
573
|
+
throw new Error('serverId must be an integer when updating a street sign.');
|
|
574
|
+
}
|
|
575
|
+
if (!signData || !Array.isArray(signData.ids) || signData.ids.length === 0) {
|
|
576
|
+
throw new Error('signData.ids must include at least one identifier when updating a street sign.');
|
|
577
|
+
}
|
|
578
|
+
return this.executeCadRequest('UPDATE_STREETSIGN', serverId, signData);
|
|
579
|
+
}
|
|
580
|
+
normalizeAccountEntries(input) {
|
|
581
|
+
const entries = Array.isArray(input) ? input : [input];
|
|
582
|
+
return entries
|
|
583
|
+
.filter((entry) => entry !== undefined && entry !== null)
|
|
584
|
+
.map((entry) => {
|
|
585
|
+
if (typeof entry === 'string') {
|
|
586
|
+
return { account: entry };
|
|
587
|
+
}
|
|
588
|
+
if ('account' in entry) {
|
|
589
|
+
return { account: entry.account };
|
|
590
|
+
}
|
|
591
|
+
throw new Error('Invalid account entry provided.');
|
|
592
|
+
});
|
|
593
|
+
}
|
|
85
594
|
}
|
|
86
595
|
exports.CADManager = CADManager;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { Instance } from '../instance/Instance';
|
|
2
|
+
import * as globalTypes from '../constants';
|
|
2
3
|
import { CADServerAPIStruct } from '../libs/rest/src';
|
|
3
4
|
import { CADServer } from '../structures/CADServer';
|
|
4
5
|
import { CacheManager } from './CacheManager';
|
|
5
6
|
import { CADManager } from './CADManager';
|
|
6
7
|
export declare class CADServerManager extends CacheManager<number, CADServer, CADServerAPIStruct> {
|
|
8
|
+
private readonly manager;
|
|
7
9
|
constructor(instance: Instance, manager: CADManager);
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the CAD servers belonging to the community.
|
|
12
|
+
*/
|
|
13
|
+
getServers(): Promise<CADServerAPIStruct[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Updates the CAD server configuration.
|
|
16
|
+
*/
|
|
17
|
+
setServers(servers: CADServerAPIStruct[], deployMap?: boolean): Promise<globalTypes.CADStandardResponse<CADServerAPIStruct[]>>;
|
|
18
|
+
private initialize;
|
|
8
19
|
}
|
|
@@ -1,28 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CADServerManager = void 0;
|
|
4
|
+
const src_1 = require("../libs/rest/src");
|
|
4
5
|
const CADServer_1 = require("../structures/CADServer");
|
|
5
6
|
const CacheManager_1 = require("./CacheManager");
|
|
6
7
|
class CADServerManager extends CacheManager_1.CacheManager {
|
|
7
8
|
constructor(instance, manager) {
|
|
8
9
|
super(instance, CADServer_1.CADServer, []);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
this.manager = manager;
|
|
11
|
+
void this.initialize();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the CAD servers belonging to the community.
|
|
15
|
+
*/
|
|
16
|
+
async getServers() {
|
|
17
|
+
if (!this.manager.rest) {
|
|
18
|
+
throw new Error('CAD REST client is not initialized.');
|
|
19
|
+
}
|
|
20
|
+
const serversRes = await this.manager.rest.request('GET_SERVERS');
|
|
21
|
+
const parsed = typeof serversRes === 'string' ? JSON.parse(serversRes) : serversRes;
|
|
22
|
+
const servers = Array.isArray(parsed === null || parsed === void 0 ? void 0 : parsed.servers) ? parsed.servers : [];
|
|
23
|
+
return servers;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Updates the CAD server configuration.
|
|
27
|
+
*/
|
|
28
|
+
async setServers(servers, deployMap = false) {
|
|
29
|
+
if (!Array.isArray(servers) || servers.length === 0) {
|
|
30
|
+
throw new Error('servers array must include at least one server configuration.');
|
|
31
|
+
}
|
|
32
|
+
if (!this.manager.rest) {
|
|
33
|
+
throw new Error('CAD REST client is not initialized.');
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const response = await this.manager.rest.request('SET_SERVERS', servers, deployMap);
|
|
37
|
+
const parsed = typeof response === 'string' ? JSON.parse(response) : response;
|
|
38
|
+
const updated = Array.isArray(parsed === null || parsed === void 0 ? void 0 : parsed.servers) ? parsed.servers : Array.isArray(parsed) ? parsed : [];
|
|
39
|
+
if (updated.length > 0) {
|
|
40
|
+
this.cache.clear();
|
|
41
|
+
updated.forEach((server) => {
|
|
42
|
+
const serverStruct = { id: server.id, config: server };
|
|
19
43
|
this._add(serverStruct, true, server.id);
|
|
20
44
|
});
|
|
21
45
|
}
|
|
22
|
-
|
|
23
|
-
|
|
46
|
+
return { success: true, data: updated };
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err instanceof src_1.APIError) {
|
|
50
|
+
return { success: false, reason: err.response };
|
|
24
51
|
}
|
|
25
|
-
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async initialize() {
|
|
56
|
+
try {
|
|
57
|
+
const servers = await this.getServers();
|
|
58
|
+
servers.forEach((server) => {
|
|
59
|
+
const serverStruct = {
|
|
60
|
+
id: server.id,
|
|
61
|
+
config: server
|
|
62
|
+
};
|
|
63
|
+
this._add(serverStruct, true, server.id);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
throw new Error(String(err));
|
|
68
|
+
}
|
|
26
69
|
}
|
|
27
70
|
}
|
|
28
71
|
exports.CADServerManager = CADServerManager;
|