@sonoransoftware/sonoran.js 1.0.19 → 1.0.20
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/.eslintrc.js +10 -10
- package/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc.js +6 -6
- package/dist/builders/cad/DispatchCall.d.ts +92 -92
- package/dist/builders/cad/DispatchCall.js +144 -144
- package/dist/builders/cad/index.d.ts +1 -1
- package/dist/builders/cad/index.js +17 -17
- package/dist/builders/index.d.ts +1 -1
- package/dist/builders/index.js +19 -19
- package/dist/constants.d.ts +230 -230
- package/dist/constants.js +27 -27
- package/dist/errors/LibraryErrors.d.ts +19 -19
- package/dist/errors/LibraryErrors.js +47 -47
- package/dist/errors/Messages.d.ts +1 -1
- package/dist/errors/Messages.js +8 -8
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +18 -18
- package/dist/index.d.ts +4 -4
- package/dist/index.js +24 -24
- package/dist/instance/Instance.d.ts +24 -24
- package/dist/instance/Instance.js +139 -139
- package/dist/instance/instance.types.d.ts +17 -17
- package/dist/instance/instance.types.js +2 -2
- package/dist/libs/rest/src/index.d.ts +6 -6
- package/dist/libs/rest/src/index.js +22 -22
- package/dist/libs/rest/src/lib/REST.d.ts +101 -101
- package/dist/libs/rest/src/lib/REST.js +136 -129
- package/dist/libs/rest/src/lib/RequestManager.d.ts +59 -59
- package/dist/libs/rest/src/lib/RequestManager.js +191 -191
- package/dist/libs/rest/src/lib/errors/APIError.d.ts +9 -9
- package/dist/libs/rest/src/lib/errors/APIError.js +17 -17
- package/dist/libs/rest/src/lib/errors/HTTPError.d.ts +17 -17
- package/dist/libs/rest/src/lib/errors/HTTPError.js +23 -23
- package/dist/libs/rest/src/lib/errors/RateLimitError.d.ts +13 -13
- package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -19
- package/dist/libs/rest/src/lib/errors/index.d.ts +4 -4
- package/dist/libs/rest/src/lib/errors/index.js +20 -20
- package/dist/libs/rest/src/lib/handlers/IHandler.d.ts +7 -7
- package/dist/libs/rest/src/lib/handlers/IHandler.js +2 -2
- package/dist/libs/rest/src/lib/handlers/SequentialHandler.d.ts +45 -45
- package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +143 -143
- package/dist/libs/rest/src/lib/utils/constants.d.ts +533 -527
- package/dist/libs/rest/src/lib/utils/constants.js +463 -455
- package/dist/libs/rest/src/lib/utils/utils.d.ts +1 -1
- package/dist/libs/rest/src/lib/utils/utils.js +22 -22
- package/dist/managers/BaseManager.d.ts +14 -14
- package/dist/managers/BaseManager.js +18 -18
- package/dist/managers/CADActiveUnitsManager.d.ts +15 -15
- package/dist/managers/CADActiveUnitsManager.js +38 -38
- package/dist/managers/CADManager.d.ts +29 -29
- package/dist/managers/CADManager.js +86 -86
- package/dist/managers/CADServerManager.d.ts +8 -8
- package/dist/managers/CADServerManager.js +28 -28
- package/dist/managers/CMSManager.d.ts +101 -101
- package/dist/managers/CMSManager.js +266 -266
- package/dist/managers/CMSServerManager.d.ts +8 -8
- package/dist/managers/CMSServerManager.js +34 -34
- package/dist/managers/CacheManager.d.ts +10 -10
- package/dist/managers/CacheManager.js +36 -36
- package/dist/managers/DataManager.d.ts +31 -31
- package/dist/managers/DataManager.js +58 -58
- package/dist/structures/Base.d.ts +9 -9
- package/dist/structures/Base.js +24 -24
- package/dist/structures/CADActiveUnit.d.ts +47 -47
- package/dist/structures/CADActiveUnit.js +66 -66
- package/dist/structures/CADServer.d.ts +26 -26
- package/dist/structures/CADServer.js +15 -15
- package/dist/structures/CMSServer.d.ts +18 -18
- package/dist/structures/CMSServer.js +12 -12
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +17 -17
- package/dist/utils/utils.d.ts +13 -13
- package/dist/utils/utils.js +79 -79
- package/docs/CAD-Methods-and-Usage.md +58 -58
- package/docs/CMS-Methods-and-Usage.md +211 -211
- package/docs/REST-Methods-and-Usage.md +46 -46
- package/package.json +48 -48
- package/readme.md +53 -53
- package/src/constants.ts +248 -248
- package/src/instance/Instance.ts +121 -121
- package/src/instance/instance.types.ts +17 -17
- package/src/libs/rest/src/lib/REST.ts +241 -234
- package/src/libs/rest/src/lib/RequestManager.ts +260 -260
- package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +160 -160
- package/src/libs/rest/src/lib/utils/constants.ts +1012 -997
- package/src/managers/CADManager.ts +63 -63
- package/src/managers/CMSManager.ts +226 -226
- package/src/managers/CMSServerManager.ts +32 -32
- package/tsconfig.json +71 -71
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { Instance } from '../instance/Instance';
|
|
2
|
-
import { CADSubscriptionVersionEnum } from '../constants';
|
|
3
|
-
import { APIError, DefaultCADRestOptions, REST } from '../libs/rest/src';
|
|
4
|
-
import { BaseManager } from './BaseManager';
|
|
5
|
-
import * as globalTypes from '../constants';
|
|
6
|
-
import type { Mutable } from '../constants';
|
|
7
|
-
import { CADServerManager } from './CADServerManager';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Manages all Sonoran CAD data and methods to interact with the public API.
|
|
11
|
-
*/
|
|
12
|
-
export class CADManager extends BaseManager {
|
|
13
|
-
public readonly ready = false;
|
|
14
|
-
public readonly version: CADSubscriptionVersionEnum = 0;
|
|
15
|
-
public readonly failReason: unknown = null;
|
|
16
|
-
public rest: REST | undefined;
|
|
17
|
-
public servers: CADServerManager | undefined;
|
|
18
|
-
|
|
19
|
-
constructor(instance: Instance) {
|
|
20
|
-
super(instance);
|
|
21
|
-
|
|
22
|
-
this.rest = new REST(instance, this, globalTypes.productEnums.CAD, DefaultCADRestOptions);
|
|
23
|
-
this.buildManager(instance);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
protected async buildManager(instance: Instance) {
|
|
27
|
-
const mutableThis = this as Mutable<CADManager>;
|
|
28
|
-
try {
|
|
29
|
-
const versionResp: any = await this.rest?.request('GET_VERSION');
|
|
30
|
-
mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
|
|
31
|
-
if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
|
|
32
|
-
this.servers = new CADServerManager(instance, this);
|
|
33
|
-
}
|
|
34
|
-
instance.isCADSuccessful = true;
|
|
35
|
-
instance.emit('CAD_SETUP_SUCCESSFUL');
|
|
36
|
-
} catch (err) {
|
|
37
|
-
mutableThis.failReason = err;
|
|
38
|
-
instance.emit('CAD_SETUP_UNSUCCESSFUL', err);
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Gets a community account by `accId` or `apiId`.
|
|
45
|
-
* @param {Object} params The object that contains parameters to get a community account.
|
|
46
|
-
* @param {string} [data.accId] The account id to find a community account.
|
|
47
|
-
* @param {string} [data.apiId] The api id to find a community account.
|
|
48
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
49
|
-
*/
|
|
50
|
-
public async getAccount(params: { apiId?: string, username?: string }): Promise<globalTypes.CADGetAccountPromiseResult> {
|
|
51
|
-
return new Promise(async (resolve, reject) => {
|
|
52
|
-
try {
|
|
53
|
-
const getAccountRequest: any = await this.rest?.request('GET_ACCOUNT', params.apiId, params.username);
|
|
54
|
-
resolve({ success: true, data: getAccountRequest });
|
|
55
|
-
} catch (err) {
|
|
56
|
-
if (err instanceof APIError) {
|
|
57
|
-
resolve({ success: false, reason: err.response });
|
|
58
|
-
} else {
|
|
59
|
-
reject(err);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { CADSubscriptionVersionEnum } from '../constants';
|
|
3
|
+
import { APIError, DefaultCADRestOptions, REST } from '../libs/rest/src';
|
|
4
|
+
import { BaseManager } from './BaseManager';
|
|
5
|
+
import * as globalTypes from '../constants';
|
|
6
|
+
import type { Mutable } from '../constants';
|
|
7
|
+
import { CADServerManager } from './CADServerManager';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Manages all Sonoran CAD data and methods to interact with the public API.
|
|
11
|
+
*/
|
|
12
|
+
export class CADManager extends BaseManager {
|
|
13
|
+
public readonly ready = false;
|
|
14
|
+
public readonly version: CADSubscriptionVersionEnum = 0;
|
|
15
|
+
public readonly failReason: unknown = null;
|
|
16
|
+
public rest: REST | undefined;
|
|
17
|
+
public servers: CADServerManager | undefined;
|
|
18
|
+
|
|
19
|
+
constructor(instance: Instance) {
|
|
20
|
+
super(instance);
|
|
21
|
+
|
|
22
|
+
this.rest = new REST(instance, this, globalTypes.productEnums.CAD, DefaultCADRestOptions);
|
|
23
|
+
this.buildManager(instance);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected async buildManager(instance: Instance) {
|
|
27
|
+
const mutableThis = this as Mutable<CADManager>;
|
|
28
|
+
try {
|
|
29
|
+
const versionResp: any = await this.rest?.request('GET_VERSION');
|
|
30
|
+
mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
|
|
31
|
+
if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
|
|
32
|
+
this.servers = new CADServerManager(instance, this);
|
|
33
|
+
}
|
|
34
|
+
instance.isCADSuccessful = true;
|
|
35
|
+
instance.emit('CAD_SETUP_SUCCESSFUL');
|
|
36
|
+
} catch (err) {
|
|
37
|
+
mutableThis.failReason = err;
|
|
38
|
+
instance.emit('CAD_SETUP_UNSUCCESSFUL', err);
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Gets a community account by `accId` or `apiId`.
|
|
45
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
46
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
47
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
48
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
49
|
+
*/
|
|
50
|
+
public async getAccount(params: { apiId?: string, username?: string }): Promise<globalTypes.CADGetAccountPromiseResult> {
|
|
51
|
+
return new Promise(async (resolve, reject) => {
|
|
52
|
+
try {
|
|
53
|
+
const getAccountRequest: any = await this.rest?.request('GET_ACCOUNT', params.apiId, params.username);
|
|
54
|
+
resolve({ success: true, data: getAccountRequest });
|
|
55
|
+
} catch (err) {
|
|
56
|
+
if (err instanceof APIError) {
|
|
57
|
+
resolve({ success: false, reason: err.response });
|
|
58
|
+
} else {
|
|
59
|
+
reject(err);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
64
|
}
|
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
import { Instance } from '../instance/Instance';
|
|
2
|
-
import { CMSSubscriptionVersionEnum } from '../constants';
|
|
3
|
-
import { APIError, DefaultCMSRestOptions, REST } from '../libs/rest/src';
|
|
4
|
-
import { BaseManager } from './BaseManager';
|
|
5
|
-
import * as globalTypes from '../constants';
|
|
6
|
-
import { CMSServerManager } from './CMSServerManager';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Manages all Sonoran CMS data and methods to interact with the public API.
|
|
10
|
-
*/
|
|
11
|
-
export class CMSManager extends BaseManager {
|
|
12
|
-
public readonly ready: boolean = false;
|
|
13
|
-
public readonly version: CMSSubscriptionVersionEnum = 0;
|
|
14
|
-
public readonly failReason: unknown = null;
|
|
15
|
-
public rest: REST | undefined;
|
|
16
|
-
public servers: CMSServerManager | undefined;
|
|
17
|
-
|
|
18
|
-
constructor(instance: Instance) {
|
|
19
|
-
super(instance);
|
|
20
|
-
|
|
21
|
-
this.rest = new REST(instance, this, globalTypes.productEnums.CMS, DefaultCMSRestOptions);
|
|
22
|
-
this.buildManager(instance);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
protected async buildManager(instance: Instance) {
|
|
26
|
-
const mutableThis = this as globalTypes.Mutable<CMSManager>;
|
|
27
|
-
try {
|
|
28
|
-
const versionResp: any = await this.rest?.request('GET_SUB_VERSION');
|
|
29
|
-
const version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
|
|
30
|
-
if (version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
|
|
31
|
-
this.servers = new CMSServerManager(instance, this);
|
|
32
|
-
}
|
|
33
|
-
mutableThis.ready = true;
|
|
34
|
-
mutableThis.version = version;
|
|
35
|
-
instance.isCMSSuccessful = true;
|
|
36
|
-
instance.emit('CMS_SETUP_SUCCESSFUL');
|
|
37
|
-
} catch (err) {
|
|
38
|
-
mutableThis.failReason = err;
|
|
39
|
-
instance.emit('CMS_SETUP_UNSUCCESSFUL', err);
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
46
|
-
* @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).
|
|
47
|
-
* @param {string} [data.accId] The account id to find a community account.
|
|
48
|
-
* @param {string} [data.apiId] The api id to find a community account.
|
|
49
|
-
* @param {string} [data.serverId] The username to find a community account.
|
|
50
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
51
|
-
*/
|
|
52
|
-
public async verifyWhitelist(data: { accId?: string, apiId?: string, serverId?: number } | string): Promise<globalTypes.CMSVerifyWhitelistPromiseResult> {
|
|
53
|
-
return new Promise(async (resolve, reject) => {
|
|
54
|
-
try {
|
|
55
|
-
const isString = typeof data === 'string';
|
|
56
|
-
const whitelistRequest: any = await this.rest?.request('VERIFY_WHITELIST', isString ? data : data.apiId, isString ? data : data.accId, isString ? this.instance.cmsDefaultServerId : data.serverId ?? this.instance.cmsDefaultServerId);
|
|
57
|
-
if (typeof whitelistRequest === 'string') {
|
|
58
|
-
resolve({ success: true, reason: whitelistRequest });
|
|
59
|
-
} else {
|
|
60
|
-
resolve({ success: false, reason: whitelistRequest.message });
|
|
61
|
-
}
|
|
62
|
-
} catch (err) {
|
|
63
|
-
if (err instanceof APIError) {
|
|
64
|
-
resolve({ success: false, reason: err.response });
|
|
65
|
-
} else {
|
|
66
|
-
reject(err);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Gets a full whitelist allowed list for a specific server.
|
|
74
|
-
* @param {number} serverId (Optional) Server ID to get the whole allow list for, if not specified it will grab the default server ID that is set.
|
|
75
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
76
|
-
*/
|
|
77
|
-
public async getFullWhitelist(serverId?: number): Promise<globalTypes.CMSGetFullWhitelistPromiseResult> {
|
|
78
|
-
return new Promise(async (resolve, reject) => {
|
|
79
|
-
try {
|
|
80
|
-
const getFullWhitelistRequest: any = await this.rest?.request('FULL_WHITELIST', serverId ?? this.instance.cmsDefaultServerId);
|
|
81
|
-
resolve({ success: true, data: getFullWhitelistRequest });
|
|
82
|
-
} catch (err) {
|
|
83
|
-
if (err instanceof APIError) {
|
|
84
|
-
resolve({ success: false, reason: err.response });
|
|
85
|
-
} else {
|
|
86
|
-
reject(err);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
94
|
-
* @param {Object} params The object that contains parameters to get a community account.
|
|
95
|
-
* @param {string} [data.accId] The account id to find a community account.
|
|
96
|
-
* @param {string} [data.apiId] The api id to find a community account.
|
|
97
|
-
* @param {string} [data.username] The username to find a community account.
|
|
98
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
99
|
-
*/
|
|
100
|
-
public async getComAccount(params: { accId?: string, apiId?: string, username?: string, discord?: string }): Promise<globalTypes.CMSGetComAccountPromiseResult> {
|
|
101
|
-
return new Promise(async (resolve, reject) => {
|
|
102
|
-
try {
|
|
103
|
-
const getAccountRequest: any = await this.rest?.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId, params.discord);
|
|
104
|
-
resolve({ success: true, data: getAccountRequest });
|
|
105
|
-
} catch (err) {
|
|
106
|
-
if (err instanceof APIError) {
|
|
107
|
-
resolve({ success: false, reason: err.response });
|
|
108
|
-
} else {
|
|
109
|
-
reject(err);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
117
|
-
* @param {Object} params The object that contains parameters to get a community account.
|
|
118
|
-
* @param {string} [data.accId] (Optional) The account id to find a community account.
|
|
119
|
-
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
120
|
-
* @param {string} [data.username] (Optional) The username to find a community account.
|
|
121
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
122
|
-
*/
|
|
123
|
-
public async getAccountRanks(params: { accId?: string, apiId?: string, username?: string, discord?: string }): Promise<globalTypes.CMSGetAccountRanksPromiseResult> {
|
|
124
|
-
return new Promise(async (resolve, reject) => {
|
|
125
|
-
try {
|
|
126
|
-
const getAccountRanksRequest: any = await this.rest?.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId, params.discord);
|
|
127
|
-
resolve({ success: true, data: getAccountRanksRequest });
|
|
128
|
-
} catch (err) {
|
|
129
|
-
if (err instanceof APIError) {
|
|
130
|
-
resolve({ success: false, reason: err.response });
|
|
131
|
-
} else {
|
|
132
|
-
reject(err);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Clocks in or out an account by `accId` or `apiId`.
|
|
140
|
-
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
141
|
-
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
142
|
-
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
143
|
-
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
144
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
145
|
-
*/
|
|
146
|
-
public async clockInOut(data: { accId?: string, apiId?: string, forceClockIn?: boolean }): Promise<globalTypes.CMSClockInOutPromiseResult> {
|
|
147
|
-
return new Promise(async (resolve, reject) => {
|
|
148
|
-
try {
|
|
149
|
-
const clockInOutRequest = await this.rest?.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn);
|
|
150
|
-
const clockInOutResponse = clockInOutRequest as globalTypes.clockInOutRequest;
|
|
151
|
-
if (!clockInOutResponse) resolve({ success: false, reason: clockInOutRequest as string });
|
|
152
|
-
resolve({ success: true, clockedIn: clockInOutResponse.completed });
|
|
153
|
-
} catch (err) {
|
|
154
|
-
if (err instanceof APIError) {
|
|
155
|
-
resolve({ success: false, reason: err.response });
|
|
156
|
-
} else {
|
|
157
|
-
reject(err);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
165
|
-
* @param {string} apiId The api id to check for an account.
|
|
166
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
167
|
-
*/
|
|
168
|
-
public async checkComApiId(apiId: string): Promise<globalTypes.CMSCheckComApiIdPromiseResult> {
|
|
169
|
-
return new Promise(async (resolve, reject) => {
|
|
170
|
-
try {
|
|
171
|
-
const checkComApiIdRequest: any = await this.rest?.request('CHECK_COM_APIID', apiId);
|
|
172
|
-
resolve({ success: true, username: checkComApiIdRequest as string });
|
|
173
|
-
} catch (err) {
|
|
174
|
-
if (err instanceof APIError) {
|
|
175
|
-
resolve({ success: false, reason: err.response });
|
|
176
|
-
} else {
|
|
177
|
-
reject(err);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Gets all department information within the community CMS.
|
|
185
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
186
|
-
*/
|
|
187
|
-
public async getDepartments(): Promise<globalTypes.CMSGetDepartmentsPromiseResult> {
|
|
188
|
-
return new Promise(async (resolve, reject) => {
|
|
189
|
-
try {
|
|
190
|
-
const getDepartmentsRequest: any = await this.rest?.request('GET_DEPARTMENTS');
|
|
191
|
-
resolve({ success: true, data: getDepartmentsRequest });
|
|
192
|
-
} catch (err) {
|
|
193
|
-
if (err instanceof APIError) {
|
|
194
|
-
resolve({ success: false, reason: err.response });
|
|
195
|
-
} else {
|
|
196
|
-
reject(err);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Sets a community account's ranks for the CMS community.
|
|
204
|
-
* @param {string} accountId The object that contains critical data to clock in or out an account.
|
|
205
|
-
* @param {Object} changes The object that contains change data for setting account ranks.
|
|
206
|
-
* @param {Object} [changes.set] (Optional) The object that contains primary and secondary data for setting account ranks.
|
|
207
|
-
* @param {string} [changes.set.primary] (Optional) The primary rank ID wanting to set to the account.
|
|
208
|
-
* @param {string} [changes.set.secondary] (Optional) The secondary rank ID(s) wanting to set to the account.
|
|
209
|
-
* @param {Array} [changes.add] (Optional) The secondary rank IDs wanting to add to the account.
|
|
210
|
-
* @param {Array} [changes.remove] (Optional) The secondary rank IDs wanting to remove to the account.
|
|
211
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
212
|
-
*/
|
|
213
|
-
public async setAccountRanks(accountId: string, changes: globalTypes.CMSSetAccountRanksChangesObject): Promise<globalTypes.CMSSetAccountRanksPromiseResult> {
|
|
214
|
-
return new Promise(async (resolve, reject) => {
|
|
215
|
-
try {
|
|
216
|
-
const setAccountRanksRequest: any = await this.rest?.request('SET_ACCOUNT_RANKS', accountId, changes.set, changes.add, changes.remove);
|
|
217
|
-
resolve({ success: true, data: setAccountRanksRequest });
|
|
218
|
-
} catch (err) {
|
|
219
|
-
if (err instanceof APIError) {
|
|
220
|
-
resolve({ success: false, reason: err.response });
|
|
221
|
-
} else {
|
|
222
|
-
reject(err);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { CMSSubscriptionVersionEnum } from '../constants';
|
|
3
|
+
import { APIError, DefaultCMSRestOptions, REST } from '../libs/rest/src';
|
|
4
|
+
import { BaseManager } from './BaseManager';
|
|
5
|
+
import * as globalTypes from '../constants';
|
|
6
|
+
import { CMSServerManager } from './CMSServerManager';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages all Sonoran CMS data and methods to interact with the public API.
|
|
10
|
+
*/
|
|
11
|
+
export class CMSManager extends BaseManager {
|
|
12
|
+
public readonly ready: boolean = false;
|
|
13
|
+
public readonly version: CMSSubscriptionVersionEnum = 0;
|
|
14
|
+
public readonly failReason: unknown = null;
|
|
15
|
+
public rest: REST | undefined;
|
|
16
|
+
public servers: CMSServerManager | undefined;
|
|
17
|
+
|
|
18
|
+
constructor(instance: Instance) {
|
|
19
|
+
super(instance);
|
|
20
|
+
|
|
21
|
+
this.rest = new REST(instance, this, globalTypes.productEnums.CMS, DefaultCMSRestOptions);
|
|
22
|
+
this.buildManager(instance);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected async buildManager(instance: Instance) {
|
|
26
|
+
const mutableThis = this as globalTypes.Mutable<CMSManager>;
|
|
27
|
+
try {
|
|
28
|
+
const versionResp: any = await this.rest?.request('GET_SUB_VERSION');
|
|
29
|
+
const version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
|
|
30
|
+
if (version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
|
|
31
|
+
this.servers = new CMSServerManager(instance, this);
|
|
32
|
+
}
|
|
33
|
+
mutableThis.ready = true;
|
|
34
|
+
mutableThis.version = version;
|
|
35
|
+
instance.isCMSSuccessful = true;
|
|
36
|
+
instance.emit('CMS_SETUP_SUCCESSFUL');
|
|
37
|
+
} catch (err) {
|
|
38
|
+
mutableThis.failReason = err;
|
|
39
|
+
instance.emit('CMS_SETUP_UNSUCCESSFUL', err);
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
46
|
+
* @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).
|
|
47
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
48
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
49
|
+
* @param {string} [data.serverId] The username to find a community account.
|
|
50
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
51
|
+
*/
|
|
52
|
+
public async verifyWhitelist(data: { accId?: string, apiId?: string, serverId?: number } | string): Promise<globalTypes.CMSVerifyWhitelistPromiseResult> {
|
|
53
|
+
return new Promise(async (resolve, reject) => {
|
|
54
|
+
try {
|
|
55
|
+
const isString = typeof data === 'string';
|
|
56
|
+
const whitelistRequest: any = await this.rest?.request('VERIFY_WHITELIST', isString ? data : data.apiId, isString ? data : data.accId, isString ? this.instance.cmsDefaultServerId : data.serverId ?? this.instance.cmsDefaultServerId);
|
|
57
|
+
if (typeof whitelistRequest === 'string') {
|
|
58
|
+
resolve({ success: true, reason: whitelistRequest });
|
|
59
|
+
} else {
|
|
60
|
+
resolve({ success: false, reason: whitelistRequest.message });
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err instanceof APIError) {
|
|
64
|
+
resolve({ success: false, reason: err.response });
|
|
65
|
+
} else {
|
|
66
|
+
reject(err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets a full whitelist allowed list for a specific server.
|
|
74
|
+
* @param {number} serverId (Optional) Server ID to get the whole allow list for, if not specified it will grab the default server ID that is set.
|
|
75
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
76
|
+
*/
|
|
77
|
+
public async getFullWhitelist(serverId?: number): Promise<globalTypes.CMSGetFullWhitelistPromiseResult> {
|
|
78
|
+
return new Promise(async (resolve, reject) => {
|
|
79
|
+
try {
|
|
80
|
+
const getFullWhitelistRequest: any = await this.rest?.request('FULL_WHITELIST', serverId ?? this.instance.cmsDefaultServerId);
|
|
81
|
+
resolve({ success: true, data: getFullWhitelistRequest });
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (err instanceof APIError) {
|
|
84
|
+
resolve({ success: false, reason: err.response });
|
|
85
|
+
} else {
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
94
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
95
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
96
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
97
|
+
* @param {string} [data.username] The username to find a community account.
|
|
98
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
99
|
+
*/
|
|
100
|
+
public async getComAccount(params: { accId?: string, apiId?: string, username?: string, discord?: string }): Promise<globalTypes.CMSGetComAccountPromiseResult> {
|
|
101
|
+
return new Promise(async (resolve, reject) => {
|
|
102
|
+
try {
|
|
103
|
+
const getAccountRequest: any = await this.rest?.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId, params.discord);
|
|
104
|
+
resolve({ success: true, data: getAccountRequest });
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof APIError) {
|
|
107
|
+
resolve({ success: false, reason: err.response });
|
|
108
|
+
} else {
|
|
109
|
+
reject(err);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
117
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
118
|
+
* @param {string} [data.accId] (Optional) The account id to find a community account.
|
|
119
|
+
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
120
|
+
* @param {string} [data.username] (Optional) The username to find a community account.
|
|
121
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
122
|
+
*/
|
|
123
|
+
public async getAccountRanks(params: { accId?: string, apiId?: string, username?: string, discord?: string }): Promise<globalTypes.CMSGetAccountRanksPromiseResult> {
|
|
124
|
+
return new Promise(async (resolve, reject) => {
|
|
125
|
+
try {
|
|
126
|
+
const getAccountRanksRequest: any = await this.rest?.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId, params.discord);
|
|
127
|
+
resolve({ success: true, data: getAccountRanksRequest });
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (err instanceof APIError) {
|
|
130
|
+
resolve({ success: false, reason: err.response });
|
|
131
|
+
} else {
|
|
132
|
+
reject(err);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Clocks in or out an account by `accId` or `apiId`.
|
|
140
|
+
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
141
|
+
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
142
|
+
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
143
|
+
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
144
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
145
|
+
*/
|
|
146
|
+
public async clockInOut(data: { accId?: string, apiId?: string, forceClockIn?: boolean }): Promise<globalTypes.CMSClockInOutPromiseResult> {
|
|
147
|
+
return new Promise(async (resolve, reject) => {
|
|
148
|
+
try {
|
|
149
|
+
const clockInOutRequest = await this.rest?.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn);
|
|
150
|
+
const clockInOutResponse = clockInOutRequest as globalTypes.clockInOutRequest;
|
|
151
|
+
if (!clockInOutResponse) resolve({ success: false, reason: clockInOutRequest as string });
|
|
152
|
+
resolve({ success: true, clockedIn: clockInOutResponse.completed });
|
|
153
|
+
} catch (err) {
|
|
154
|
+
if (err instanceof APIError) {
|
|
155
|
+
resolve({ success: false, reason: err.response });
|
|
156
|
+
} else {
|
|
157
|
+
reject(err);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
165
|
+
* @param {string} apiId The api id to check for an account.
|
|
166
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
167
|
+
*/
|
|
168
|
+
public async checkComApiId(apiId: string): Promise<globalTypes.CMSCheckComApiIdPromiseResult> {
|
|
169
|
+
return new Promise(async (resolve, reject) => {
|
|
170
|
+
try {
|
|
171
|
+
const checkComApiIdRequest: any = await this.rest?.request('CHECK_COM_APIID', apiId);
|
|
172
|
+
resolve({ success: true, username: checkComApiIdRequest as string });
|
|
173
|
+
} catch (err) {
|
|
174
|
+
if (err instanceof APIError) {
|
|
175
|
+
resolve({ success: false, reason: err.response });
|
|
176
|
+
} else {
|
|
177
|
+
reject(err);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Gets all department information within the community CMS.
|
|
185
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
186
|
+
*/
|
|
187
|
+
public async getDepartments(): Promise<globalTypes.CMSGetDepartmentsPromiseResult> {
|
|
188
|
+
return new Promise(async (resolve, reject) => {
|
|
189
|
+
try {
|
|
190
|
+
const getDepartmentsRequest: any = await this.rest?.request('GET_DEPARTMENTS');
|
|
191
|
+
resolve({ success: true, data: getDepartmentsRequest });
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (err instanceof APIError) {
|
|
194
|
+
resolve({ success: false, reason: err.response });
|
|
195
|
+
} else {
|
|
196
|
+
reject(err);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Sets a community account's ranks for the CMS community.
|
|
204
|
+
* @param {string} accountId The object that contains critical data to clock in or out an account.
|
|
205
|
+
* @param {Object} changes The object that contains change data for setting account ranks.
|
|
206
|
+
* @param {Object} [changes.set] (Optional) The object that contains primary and secondary data for setting account ranks.
|
|
207
|
+
* @param {string} [changes.set.primary] (Optional) The primary rank ID wanting to set to the account.
|
|
208
|
+
* @param {string} [changes.set.secondary] (Optional) The secondary rank ID(s) wanting to set to the account.
|
|
209
|
+
* @param {Array} [changes.add] (Optional) The secondary rank IDs wanting to add to the account.
|
|
210
|
+
* @param {Array} [changes.remove] (Optional) The secondary rank IDs wanting to remove to the account.
|
|
211
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
212
|
+
*/
|
|
213
|
+
public async setAccountRanks(accountId: string, changes: globalTypes.CMSSetAccountRanksChangesObject): Promise<globalTypes.CMSSetAccountRanksPromiseResult> {
|
|
214
|
+
return new Promise(async (resolve, reject) => {
|
|
215
|
+
try {
|
|
216
|
+
const setAccountRanksRequest: any = await this.rest?.request('SET_ACCOUNT_RANKS', accountId, changes.set, changes.add, changes.remove);
|
|
217
|
+
resolve({ success: true, data: setAccountRanksRequest });
|
|
218
|
+
} catch (err) {
|
|
219
|
+
if (err instanceof APIError) {
|
|
220
|
+
resolve({ success: false, reason: err.response });
|
|
221
|
+
} else {
|
|
222
|
+
reject(err);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
227
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Instance } from '../instance/Instance';
|
|
2
|
-
import { CMSServerAPIStruct } from '../libs/rest/src';
|
|
3
|
-
import { CMSServer } from '../structures/CMSServer';
|
|
4
|
-
import { CacheManager } from './CacheManager';
|
|
5
|
-
import { CMSManager } from './CMSManager';
|
|
6
|
-
|
|
7
|
-
export class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
|
|
8
|
-
constructor(instance: Instance, manager: CMSManager) {
|
|
9
|
-
super(instance, CMSServer, []);
|
|
10
|
-
|
|
11
|
-
(async () => {
|
|
12
|
-
while(!manager.ready) {
|
|
13
|
-
await new Promise((resolve) => {
|
|
14
|
-
setTimeout(resolve, 100);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const serversRes: any = await manager.rest?.request('GET_GAME_SERVERS');
|
|
19
|
-
const servers = serversRes.servers;
|
|
20
|
-
servers.forEach((server: CMSServerAPIStruct) => {
|
|
21
|
-
const serverStruct = {
|
|
22
|
-
id: server.id,
|
|
23
|
-
config: server
|
|
24
|
-
};
|
|
25
|
-
this._add(serverStruct, true, server.id);
|
|
26
|
-
});
|
|
27
|
-
console.log(`Found ${servers.length} servers`);
|
|
28
|
-
} catch (err) {
|
|
29
|
-
throw new Error(String(err));
|
|
30
|
-
}
|
|
31
|
-
})();
|
|
32
|
-
}
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { CMSServerAPIStruct } from '../libs/rest/src';
|
|
3
|
+
import { CMSServer } from '../structures/CMSServer';
|
|
4
|
+
import { CacheManager } from './CacheManager';
|
|
5
|
+
import { CMSManager } from './CMSManager';
|
|
6
|
+
|
|
7
|
+
export class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
|
|
8
|
+
constructor(instance: Instance, manager: CMSManager) {
|
|
9
|
+
super(instance, CMSServer, []);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
while(!manager.ready) {
|
|
13
|
+
await new Promise((resolve) => {
|
|
14
|
+
setTimeout(resolve, 100);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const serversRes: any = await manager.rest?.request('GET_GAME_SERVERS');
|
|
19
|
+
const servers = serversRes.servers;
|
|
20
|
+
servers.forEach((server: CMSServerAPIStruct) => {
|
|
21
|
+
const serverStruct = {
|
|
22
|
+
id: server.id,
|
|
23
|
+
config: server
|
|
24
|
+
};
|
|
25
|
+
this._add(serverStruct, true, server.id);
|
|
26
|
+
});
|
|
27
|
+
console.log(`Found ${servers.length} servers`);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
throw new Error(String(err));
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
}
|
|
33
33
|
}
|