@sonoransoftware/sonoran.js 1.0.35 → 1.0.37

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.
@@ -25,8 +25,7 @@ export class CMSManager extends BaseManager {
25
25
  protected async buildManager(instance: Instance) {
26
26
  const mutableThis = this as globalTypes.Mutable<CMSManager>;
27
27
  try {
28
- const versionResp: any = await this.rest?.request('GET_SUB_VERSION');
29
- const version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
28
+ const version = await this.getSubscriptionVersion();
30
29
  if (version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
31
30
  this.servers = new CMSServerManager(instance, this);
32
31
  }
@@ -41,6 +40,15 @@ export class CMSManager extends BaseManager {
41
40
  }
42
41
  }
43
42
 
43
+ /**
44
+ * Retrieves the community's CMS subscription version.
45
+ */
46
+ public async getSubscriptionVersion(): Promise<number> {
47
+ const versionResp: any = await this.rest?.request('GET_SUB_VERSION');
48
+ const versionString = String(versionResp);
49
+ return Number.parseInt(versionString.replace(/(^\d+)(.+$)/i, '$1'), 10);
50
+ }
51
+
44
52
  /**
45
53
  * Verifies the whitelist of a given account with the given parameters to search of said account.
46
54
  * @param {Object | string} data The object or [accId | apiId as a string] that contains data to get a community account to verify if it has whitelist to the specified server. *If given as a string it will default to the set or default cms server id (1).
@@ -328,6 +336,46 @@ export class CMSManager extends BaseManager {
328
336
  });
329
337
  }
330
338
 
339
+ /**
340
+ * Triggers promotion flows for the specified users.
341
+ */
342
+ public async triggerPromotionFlows(flows: globalTypes.CMSTriggerPromotionFlowPayload[]): Promise<globalTypes.CMSTriggerPromotionFlowsPromiseResult> {
343
+ if (!Array.isArray(flows) || flows.length === 0) {
344
+ throw new Error('flows array must include at least one promotion flow payload.');
345
+ }
346
+
347
+ return new Promise(async (resolve, reject) => {
348
+ try {
349
+ const response: any = await this.rest?.request('TRIGGER_PROMOTION_FLOWS', flows);
350
+ resolve({ success: true, data: response });
351
+ } catch (err) {
352
+ if (err instanceof APIError) {
353
+ resolve({ success: false, reason: err.response });
354
+ } else {
355
+ reject(err);
356
+ }
357
+ }
358
+ });
359
+ }
360
+
361
+ /**
362
+ * Retrieves the available promotion flows configured in CMS.
363
+ */
364
+ public async getPromotionFlows(): Promise<globalTypes.CMSGetPromotionFlowsPromiseResult> {
365
+ return new Promise(async (resolve, reject) => {
366
+ try {
367
+ const response: any = await this.rest?.request('GET_PROMOTION_FLOWS');
368
+ resolve({ success: true, data: response });
369
+ } catch (err) {
370
+ if (err instanceof APIError) {
371
+ resolve({ success: false, reason: err.response });
372
+ } else {
373
+ reject(err);
374
+ }
375
+ }
376
+ });
377
+ }
378
+
331
379
  /**
332
380
  * Gets a list of online ERLC players for the given roblox join code.
333
381
  * @param {string} robloxJoinCode The roblox join code to get the online players for.
@@ -370,6 +418,31 @@ export class CMSManager extends BaseManager {
370
418
  });
371
419
  }
372
420
 
421
+ /**
422
+ * Updates the stage of a form for the specified account.
423
+ */
424
+ public async changeFormStage(params: { accId?: string, formId: number, newStageId: string, apiId?: string, username?: string, discord?: string, uniqueId: number }): Promise<globalTypes.CMSChangeFormStagePromiseResult> {
425
+ if (!params.formId || !params.newStageId) {
426
+ throw new Error('formId and newStageId are required to change a form stage.');
427
+ }
428
+ if (params.uniqueId === undefined || Number.isNaN(Number(params.uniqueId))) {
429
+ throw new Error('uniqueId is required to change a form stage.');
430
+ }
431
+
432
+ return new Promise(async (resolve, reject) => {
433
+ try {
434
+ const response: any = await this.rest?.request('CHANGE_FORM_STAGE', params.accId, params.formId, params.newStageId, params.apiId, params.username, params.discord, params.uniqueId);
435
+ resolve({ success: true, data: response });
436
+ } catch (err) {
437
+ if (err instanceof APIError) {
438
+ resolve({ success: false, reason: err.response });
439
+ } else {
440
+ reject(err);
441
+ }
442
+ }
443
+ });
444
+ }
445
+
373
446
  /**
374
447
  * Retrieves submissions for a specific form template.
375
448
  */
@@ -8,28 +8,39 @@ import { CMSManager } from './CMSManager';
8
8
  export class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
9
9
  constructor(instance: Instance, private readonly manager: CMSManager) {
10
10
  super(instance, CMSServer, []);
11
- (async () => {
12
- const managerRef = this.manager;
13
- while(!managerRef.ready) {
14
- await new Promise((resolve) => {
15
- setTimeout(resolve, 100);
16
- });
17
- }
18
- try {
19
- const serversRes: any = await managerRef.rest?.request('GET_GAME_SERVERS');
20
- const servers = serversRes.servers;
21
- servers.forEach((server: CMSServerAPIStruct) => {
22
- const serverStruct = {
23
- id: server.id,
24
- config: server
25
- };
26
- this._add(serverStruct, true, server.id);
27
- });
28
- console.log(`Found ${servers.length} servers`);
29
- } catch (err) {
30
- throw new Error(String(err));
31
- }
32
- })();
11
+ void this.initialize();
12
+ }
13
+
14
+ /**
15
+ * Retrieves the CMS game servers belonging to the community.
16
+ */
17
+ public async getGameServers(): Promise<CMSServerAPIStruct[]> {
18
+ const serversRes: any = await this.manager.rest?.request('GET_GAME_SERVERS');
19
+ const parsed = typeof serversRes === 'string' ? JSON.parse(serversRes) : serversRes;
20
+ const servers = Array.isArray(parsed?.servers) ? parsed.servers : [];
21
+ return servers;
22
+ }
23
+
24
+ private async initialize(): Promise<void> {
25
+ const managerRef = this.manager;
26
+ while(!managerRef.ready) {
27
+ await new Promise((resolve) => {
28
+ setTimeout(resolve, 100);
29
+ });
30
+ }
31
+ try {
32
+ const servers = await this.getGameServers();
33
+ servers.forEach((server: CMSServerAPIStruct) => {
34
+ const serverStruct = {
35
+ id: server.id,
36
+ config: server
37
+ };
38
+ this._add(serverStruct, true, server.id);
39
+ });
40
+ console.log(`Found ${servers.length} servers`);
41
+ } catch (err) {
42
+ throw new Error(String(err));
43
+ }
33
44
  }
34
45
 
35
46
  public async setGameServers(servers: globalTypes.CMSSetGameServerStruct[]): Promise<globalTypes.CMSSetGameServersPromiseResult> {
@@ -184,4 +184,25 @@ export class RadioManager extends BaseManager {
184
184
  }
185
185
  });
186
186
  }
187
+
188
+ /**
189
+ * Plays one or more tones to radio channels, groups, or in-game speakers.
190
+ * @param {number} roomId Multi-server room id for tone playback.
191
+ * @param {number[]} tones Tone identifiers to play.
192
+ * @param {globalTypes.RadioTonePlayTarget[]} playTo Targets that should receive the tones.
193
+ */
194
+ public async playTone(roomId: number, tones: number[], playTo: globalTypes.RadioTonePlayTarget[]): Promise<globalTypes.RadioPlayTonePromiseResult> {
195
+ return new Promise(async (resolve, reject) => {
196
+ try {
197
+ const response: any = await this.rest?.request('PLAY_TONE', roomId, tones, playTo);
198
+ resolve({ success: true, result: response?.result ?? response });
199
+ } catch (err) {
200
+ if (err instanceof APIError) {
201
+ resolve({ success: false, reason: err.response });
202
+ } else {
203
+ reject(err);
204
+ }
205
+ }
206
+ });
207
+ }
187
208
  }