@sonoransoftware/sonoran.js 1.0.48 → 1.0.50
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/dist/constants.d.ts +1 -1
- package/dist/libs/rest/src/lib/RequestManager.js +19 -4
- package/dist/libs/rest/src/lib/utils/constants.d.ts +9 -2
- package/dist/managers/CADManager.js +8 -1
- package/package.json +1 -1
- package/readme.md +18 -2
- package/src/constants.ts +1 -1
- package/src/libs/rest/src/lib/RequestManager.ts +18 -4
- package/src/libs/rest/src/lib/utils/constants.ts +5 -2
- package/src/managers/CADManager.ts +8 -1
package/dist/constants.d.ts
CHANGED
|
@@ -403,11 +403,26 @@ class RequestManager extends events_1.EventEmitter {
|
|
|
403
403
|
path = `${apiType.path}/${auth.encodedId}/${auth.encodedKey}/${encodeSegment(roomIdNumeric)}/${encodeSegment(identity)}`;
|
|
404
404
|
method = 'POST';
|
|
405
405
|
const requestBody = {};
|
|
406
|
-
|
|
407
|
-
|
|
406
|
+
const normalizeNumberArray = (label, value) => {
|
|
407
|
+
if (value === undefined)
|
|
408
|
+
return undefined;
|
|
409
|
+
const asArray = Array.isArray(value) ? value : [value];
|
|
410
|
+
const numbers = asArray.map((entry) => {
|
|
411
|
+
const numeric = typeof entry === 'number' ? entry : Number(entry);
|
|
412
|
+
if (Number.isNaN(numeric)) {
|
|
413
|
+
throw new Error(`${label} must be a number or array of numbers for RADIO_SET_USER_CHANNELS requests.`);
|
|
414
|
+
}
|
|
415
|
+
return numeric;
|
|
416
|
+
});
|
|
417
|
+
return numbers;
|
|
418
|
+
};
|
|
419
|
+
const transmit = normalizeNumberArray('transmit', options === null || options === void 0 ? void 0 : options.transmit);
|
|
420
|
+
if (transmit !== undefined) {
|
|
421
|
+
requestBody.transmit = transmit;
|
|
408
422
|
}
|
|
409
|
-
|
|
410
|
-
|
|
423
|
+
const scan = normalizeNumberArray('scan', options === null || options === void 0 ? void 0 : options.scan);
|
|
424
|
+
if (scan !== undefined) {
|
|
425
|
+
requestBody.scan = scan;
|
|
411
426
|
}
|
|
412
427
|
body = requestBody;
|
|
413
428
|
break;
|
|
@@ -272,7 +272,7 @@ export declare enum CADDispatchStatusEnums {
|
|
|
272
272
|
Active = 1,
|
|
273
273
|
Closed = 2
|
|
274
274
|
}
|
|
275
|
-
|
|
275
|
+
interface CADNewDispatchBaseStruct {
|
|
276
276
|
serverId: number;
|
|
277
277
|
origin: CADDispatchOriginEnums;
|
|
278
278
|
status: CADDispatchStatusEnums;
|
|
@@ -286,8 +286,14 @@ export interface CADNewDispatchStruct {
|
|
|
286
286
|
trackPrimary: boolean;
|
|
287
287
|
description: string;
|
|
288
288
|
metaData: Record<string, string>;
|
|
289
|
-
units: string[];
|
|
290
289
|
}
|
|
290
|
+
export type CADNewDispatchStruct = (CADNewDispatchBaseStruct & {
|
|
291
|
+
units: string[];
|
|
292
|
+
accounts?: string[];
|
|
293
|
+
}) | (CADNewDispatchBaseStruct & {
|
|
294
|
+
units?: string[];
|
|
295
|
+
accounts: string[];
|
|
296
|
+
});
|
|
291
297
|
export interface CADStreetSignStruct {
|
|
292
298
|
id: number;
|
|
293
299
|
label: string;
|
|
@@ -768,3 +774,4 @@ export type PossibleRequestData = undefined | {
|
|
|
768
774
|
add?: string[];
|
|
769
775
|
remove?: string[];
|
|
770
776
|
};
|
|
777
|
+
export {};
|
|
@@ -513,7 +513,14 @@ class CADManager extends BaseManager_1.BaseManager {
|
|
|
513
513
|
* Creates a new dispatch call.
|
|
514
514
|
*/
|
|
515
515
|
async createDispatch(data) {
|
|
516
|
-
|
|
516
|
+
const hasUnits = Array.isArray(data.units);
|
|
517
|
+
const hasAccounts = Array.isArray(data.accounts);
|
|
518
|
+
const payload = {
|
|
519
|
+
...data,
|
|
520
|
+
...(hasUnits ? { units: data.units } : {}),
|
|
521
|
+
...(hasAccounts ? { accounts: data.accounts } : {})
|
|
522
|
+
};
|
|
523
|
+
return this.executeCadRequest('NEW_DISPATCH', payload);
|
|
517
524
|
}
|
|
518
525
|
async attachUnits(serverIdOrParams, callId, unitsOrAccount) {
|
|
519
526
|
let payload;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonoransoftware/sonoran.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"description": "Sonoran.js is a library that allows you to interact with the Sonoran CAD and Sonoran CMS API. Based off of and utilizes several Discord.js library techniques for ease of use.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/readme.md
CHANGED
|
@@ -128,7 +128,7 @@ await instance.cad.setUnitPanic({ account: '91de0ce8-c571-11e9-9714-5600023b2434
|
|
|
128
128
|
- **`create911Call(details)`** / **`remove911Call(callId)`**
|
|
129
129
|
- **`getCalls(options)`**
|
|
130
130
|
- **`getMyCall({ account })`**
|
|
131
|
-
- **`createDispatch(data)`**
|
|
131
|
+
- **`createDispatch(data)`** - accepts either `units` (API IDs) or `accounts` (account UUIDs) as arrays.
|
|
132
132
|
- **`attachUnits(serverId, callId, unitsOrAccount)`** / **`detachUnits(serverId, unitsOrAccount)`**
|
|
133
133
|
- **`setCallPostal(serverId, callId, postal)`** / **`setCallPrimary(serverId, callId, primary, trackPrimary)`**
|
|
134
134
|
- **`addCallNote({ serverId, callId, note, label? })`**
|
|
@@ -151,6 +151,22 @@ const dispatch = await instance.cad.createDispatch({
|
|
|
151
151
|
metaData: {},
|
|
152
152
|
units: ['unit-1']
|
|
153
153
|
});
|
|
154
|
+
const dispatchByAccount = await instance.cad.createDispatch({
|
|
155
|
+
serverId: 1,
|
|
156
|
+
origin: Sonoran.CADDispatchOriginEnums.WalkUp,
|
|
157
|
+
status: Sonoran.CADDispatchStatusEnums.Active,
|
|
158
|
+
priority: 2,
|
|
159
|
+
block: '456',
|
|
160
|
+
address: '2nd St',
|
|
161
|
+
postal: '200',
|
|
162
|
+
title: 'Suspicious Person',
|
|
163
|
+
code: 'SP',
|
|
164
|
+
primary: 43,
|
|
165
|
+
trackPrimary: false,
|
|
166
|
+
description: 'Individual loitering near storefront',
|
|
167
|
+
metaData: {},
|
|
168
|
+
accounts: ['91de0ce8-c571-11e9-9714-5600023b2434']
|
|
169
|
+
});
|
|
154
170
|
await instance.cad.attachUnits(1, 1001, ['unit-2']);
|
|
155
171
|
// Or attach a single unit by account UUID
|
|
156
172
|
await instance.cad.attachUnits({ serverId: 1, callId: 1001, account: '91de0ce8-c571-11e9-9714-5600023b2434' });
|
|
@@ -470,7 +486,7 @@ const user = await instance.radio.getConnectedUser(1, 'account-uuid');
|
|
|
470
486
|
### setUserChannels(roomId, identity, options)
|
|
471
487
|
Updates a user's transmit or scan channels for a specific radio room.
|
|
472
488
|
```js
|
|
473
|
-
await instance.radio.setUserChannels(1, 'account-uuid', { transmit: 12, scan: [10, 11, 12] });
|
|
489
|
+
await instance.radio.setUserChannels(1, 'account-uuid', { transmit: [12], scan: [10, 11, 12] });
|
|
474
490
|
```
|
|
475
491
|
|
|
476
492
|
### setUserDisplayName(accId, displayName)
|
package/src/constants.ts
CHANGED
|
@@ -470,11 +470,25 @@ export class RequestManager extends EventEmitter {
|
|
|
470
470
|
path = `${apiType.path}/${auth.encodedId}/${auth.encodedKey}/${encodeSegment(roomIdNumeric)}/${encodeSegment(identity)}`;
|
|
471
471
|
method = 'POST';
|
|
472
472
|
const requestBody: Record<string, unknown> = {};
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
const normalizeNumberArray = (label: string, value: unknown) => {
|
|
474
|
+
if (value === undefined) return undefined;
|
|
475
|
+
const asArray = Array.isArray(value) ? value : [value];
|
|
476
|
+
const numbers = asArray.map((entry) => {
|
|
477
|
+
const numeric = typeof entry === 'number' ? entry : Number(entry);
|
|
478
|
+
if (Number.isNaN(numeric)) {
|
|
479
|
+
throw new Error(`${label} must be a number or array of numbers for RADIO_SET_USER_CHANNELS requests.`);
|
|
480
|
+
}
|
|
481
|
+
return numeric;
|
|
482
|
+
});
|
|
483
|
+
return numbers;
|
|
484
|
+
};
|
|
485
|
+
const transmit = normalizeNumberArray('transmit', options?.transmit);
|
|
486
|
+
if (transmit !== undefined) {
|
|
487
|
+
requestBody.transmit = transmit;
|
|
475
488
|
}
|
|
476
|
-
|
|
477
|
-
|
|
489
|
+
const scan = normalizeNumberArray('scan', options?.scan);
|
|
490
|
+
if (scan !== undefined) {
|
|
491
|
+
requestBody.scan = scan;
|
|
478
492
|
}
|
|
479
493
|
body = requestBody;
|
|
480
494
|
break;
|
|
@@ -910,7 +910,7 @@ export enum CADDispatchStatusEnums {
|
|
|
910
910
|
Closed
|
|
911
911
|
}
|
|
912
912
|
|
|
913
|
-
|
|
913
|
+
interface CADNewDispatchBaseStruct {
|
|
914
914
|
serverId: number;
|
|
915
915
|
origin: CADDispatchOriginEnums;
|
|
916
916
|
status: CADDispatchStatusEnums;
|
|
@@ -924,9 +924,12 @@ export interface CADNewDispatchStruct {
|
|
|
924
924
|
trackPrimary: boolean;
|
|
925
925
|
description: string;
|
|
926
926
|
metaData: Record<string, string>;
|
|
927
|
-
units: string[];
|
|
928
927
|
}
|
|
929
928
|
|
|
929
|
+
export type CADNewDispatchStruct =
|
|
930
|
+
| (CADNewDispatchBaseStruct & { units: string[]; accounts?: string[] })
|
|
931
|
+
| (CADNewDispatchBaseStruct & { units?: string[]; accounts: string[] });
|
|
932
|
+
|
|
930
933
|
export interface CADStreetSignStruct {
|
|
931
934
|
id: number;
|
|
932
935
|
label: string;
|
|
@@ -562,7 +562,14 @@ export class CADManager extends BaseManager {
|
|
|
562
562
|
* Creates a new dispatch call.
|
|
563
563
|
*/
|
|
564
564
|
public async createDispatch(data: CADNewDispatchStruct): Promise<globalTypes.CADStandardResponse> {
|
|
565
|
-
|
|
565
|
+
const hasUnits = Array.isArray(data.units);
|
|
566
|
+
const hasAccounts = Array.isArray(data.accounts);
|
|
567
|
+
const payload: CADNewDispatchStruct = {
|
|
568
|
+
...data,
|
|
569
|
+
...(hasUnits ? { units: data.units } : {}),
|
|
570
|
+
...(hasAccounts ? { accounts: data.accounts } : {})
|
|
571
|
+
};
|
|
572
|
+
return this.executeCadRequest('NEW_DISPATCH', payload);
|
|
566
573
|
}
|
|
567
574
|
|
|
568
575
|
/**
|