@sonoransoftware/sonoran.js 1.0.38 → 1.0.40

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.
@@ -395,6 +395,7 @@ export interface CMSERLCAddNewRecordPromiseResult {
395
395
  logId?: string;
396
396
  }
397
397
  export interface CMSERLCExecuteCommandPayload {
398
+ robloxJoinCode: string;
398
399
  type: string;
399
400
  args: unknown;
400
401
  discordId: string | number;
@@ -305,7 +305,16 @@ class REST extends events_1.EventEmitter {
305
305
  if (!Array.isArray(payload)) {
306
306
  throw new Error('ERLC_EXECUTE_COMMAND requires an array of command payloads.');
307
307
  }
308
- return payload;
308
+ return payload.map((cmd) => {
309
+ const robloxJoinCode = cmd.robloxJoinCode;
310
+ if (typeof robloxJoinCode !== 'string' || robloxJoinCode.length === 0) {
311
+ throw new Error('ERLC_EXECUTE_COMMAND requires each command to include a valid robloxJoinCode.');
312
+ }
313
+ return {
314
+ ...cmd,
315
+ robloxJoinCode
316
+ };
317
+ });
309
318
  }
310
319
  case 'RADIO_GET_COMMUNITY_CHANNELS':
311
320
  case 'RADIO_GET_CONNECTED_USERS':
@@ -514,7 +514,7 @@ exports.ERLCMSAPITypes = [
514
514
  },
515
515
  {
516
516
  type: "ERLC_EXECUTE_COMMAND",
517
- path: "erlc/execute_command",
517
+ path: "erlc/command",
518
518
  method: "POST",
519
519
  minVersion: 0
520
520
  }
@@ -634,10 +634,34 @@ class CMSManager extends BaseManager_1.BaseManager {
634
634
  if (!Array.isArray(commands) || commands.length === 0) {
635
635
  throw new Error('ERLC execute command requires at least one command payload.');
636
636
  }
637
+ const normalizedCommands = commands.map((cmd) => {
638
+ const type = cmd.type;
639
+ const args = cmd.args;
640
+ const discordId = cmd.discordId;
641
+ const includesPlayerNameOrId = cmd.includesPlayerNameOrId;
642
+ const robloxJoinCode = cmd.robloxJoinCode;
643
+ if (!type) {
644
+ throw new Error('Each ERLC command requires a type.');
645
+ }
646
+ if (!discordId) {
647
+ throw new Error('Each ERLC command requires a discordId.');
648
+ }
649
+ if (typeof robloxJoinCode !== 'string' || robloxJoinCode.length === 0) {
650
+ throw new Error('Each ERLC command requires a robloxJoinCode.');
651
+ }
652
+ return {
653
+ ...cmd,
654
+ type,
655
+ args,
656
+ discordId,
657
+ includesPlayerNameOrId,
658
+ robloxJoinCode,
659
+ };
660
+ });
637
661
  return new Promise(async (resolve, reject) => {
638
662
  var _a;
639
663
  try {
640
- const erlcExecuteCommandRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('ERLC_EXECUTE_COMMAND', commands));
664
+ const erlcExecuteCommandRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('ERLC_EXECUTE_COMMAND', normalizedCommands));
641
665
  resolve({ success: true, data: erlcExecuteCommandRequest });
642
666
  }
643
667
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonoransoftware/sonoran.js",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
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/src/constants.ts CHANGED
@@ -444,6 +444,7 @@ export interface CMSERLCAddNewRecordPromiseResult {
444
444
  }
445
445
 
446
446
  export interface CMSERLCExecuteCommandPayload {
447
+ robloxJoinCode: string;
447
448
  type: string;
448
449
  args: unknown;
449
450
  discordId: string | number;
@@ -409,7 +409,16 @@ export class REST extends EventEmitter {
409
409
  if (!Array.isArray(payload)) {
410
410
  throw new Error('ERLC_EXECUTE_COMMAND requires an array of command payloads.');
411
411
  }
412
- return payload;
412
+ return payload.map((cmd) => {
413
+ const robloxJoinCode = cmd.robloxJoinCode;
414
+ if (typeof robloxJoinCode !== 'string' || robloxJoinCode.length === 0) {
415
+ throw new Error('ERLC_EXECUTE_COMMAND requires each command to include a valid robloxJoinCode.');
416
+ }
417
+ return {
418
+ ...cmd,
419
+ robloxJoinCode
420
+ };
421
+ });
413
422
  }
414
423
  case 'RADIO_GET_COMMUNITY_CHANNELS':
415
424
  case 'RADIO_GET_CONNECTED_USERS':
@@ -551,7 +551,7 @@ export const ERLCMSAPITypes: APITypeData[] = [
551
551
  },
552
552
  {
553
553
  type: "ERLC_EXECUTE_COMMAND",
554
- path: "erlc/execute_command",
554
+ path: "erlc/command",
555
555
  method: "POST",
556
556
  minVersion: 0
557
557
  }
@@ -570,9 +570,36 @@ export class CMSManager extends BaseManager {
570
570
  throw new Error('ERLC execute command requires at least one command payload.');
571
571
  }
572
572
 
573
+ const normalizedCommands = commands.map((cmd) => {
574
+ const type = cmd.type;
575
+ const args = cmd.args;
576
+ const discordId = cmd.discordId;
577
+ const includesPlayerNameOrId = cmd.includesPlayerNameOrId;
578
+ const robloxJoinCode = cmd.robloxJoinCode;
579
+
580
+ if (!type) {
581
+ throw new Error('Each ERLC command requires a type.');
582
+ }
583
+ if (!discordId) {
584
+ throw new Error('Each ERLC command requires a discordId.');
585
+ }
586
+ if (typeof robloxJoinCode !== 'string' || robloxJoinCode.length === 0) {
587
+ throw new Error('Each ERLC command requires a robloxJoinCode.');
588
+ }
589
+
590
+ return {
591
+ ...cmd,
592
+ type,
593
+ args,
594
+ discordId,
595
+ includesPlayerNameOrId,
596
+ robloxJoinCode,
597
+ };
598
+ });
599
+
573
600
  return new Promise(async (resolve, reject) => {
574
601
  try {
575
- const erlcExecuteCommandRequest: any = await this.rest?.request('ERLC_EXECUTE_COMMAND', commands);
602
+ const erlcExecuteCommandRequest: any = await this.rest?.request('ERLC_EXECUTE_COMMAND', normalizedCommands);
576
603
  resolve({ success: true, data: erlcExecuteCommandRequest });
577
604
  } catch (err) {
578
605
  if (err instanceof APIError) {