@sonoransoftware/sonoran.js 1.0.19 → 1.0.22
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,266 +1,266 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.CMSManager = void 0;
|
|
27
|
-
const src_1 = require("../libs/rest/src");
|
|
28
|
-
const BaseManager_1 = require("./BaseManager");
|
|
29
|
-
const globalTypes = __importStar(require("../constants"));
|
|
30
|
-
const CMSServerManager_1 = require("./CMSServerManager");
|
|
31
|
-
/**
|
|
32
|
-
* Manages all Sonoran CMS data and methods to interact with the public API.
|
|
33
|
-
*/
|
|
34
|
-
class CMSManager extends BaseManager_1.BaseManager {
|
|
35
|
-
constructor(instance) {
|
|
36
|
-
super(instance);
|
|
37
|
-
this.ready = false;
|
|
38
|
-
this.version = 0;
|
|
39
|
-
this.failReason = null;
|
|
40
|
-
this.rest = new src_1.REST(instance, this, globalTypes.productEnums.CMS, src_1.DefaultCMSRestOptions);
|
|
41
|
-
this.buildManager(instance);
|
|
42
|
-
}
|
|
43
|
-
async buildManager(instance) {
|
|
44
|
-
var _a;
|
|
45
|
-
const mutableThis = this;
|
|
46
|
-
try {
|
|
47
|
-
const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SUB_VERSION'));
|
|
48
|
-
const version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
|
|
49
|
-
if (version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
|
|
50
|
-
this.servers = new CMSServerManager_1.CMSServerManager(instance, this);
|
|
51
|
-
}
|
|
52
|
-
mutableThis.ready = true;
|
|
53
|
-
mutableThis.version = version;
|
|
54
|
-
instance.isCMSSuccessful = true;
|
|
55
|
-
instance.emit('CMS_SETUP_SUCCESSFUL');
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
mutableThis.failReason = err;
|
|
59
|
-
instance.emit('CMS_SETUP_UNSUCCESSFUL', err);
|
|
60
|
-
throw err;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
65
|
-
* @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).
|
|
66
|
-
* @param {string} [data.accId] The account id to find a community account.
|
|
67
|
-
* @param {string} [data.apiId] The api id to find a community account.
|
|
68
|
-
* @param {string} [data.serverId] The username to find a community account.
|
|
69
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
70
|
-
*/
|
|
71
|
-
async verifyWhitelist(data) {
|
|
72
|
-
return new Promise(async (resolve, reject) => {
|
|
73
|
-
var _a, _b;
|
|
74
|
-
try {
|
|
75
|
-
const isString = typeof data === 'string';
|
|
76
|
-
const whitelistRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('VERIFY_WHITELIST', isString ? data : data.apiId, isString ? data : data.accId, isString ? this.instance.cmsDefaultServerId : (_b = data.serverId) !== null && _b !== void 0 ? _b : this.instance.cmsDefaultServerId));
|
|
77
|
-
if (typeof whitelistRequest === 'string') {
|
|
78
|
-
resolve({ success: true, reason: whitelistRequest });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
resolve({ success: false, reason: whitelistRequest.message });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
if (err instanceof src_1.APIError) {
|
|
86
|
-
resolve({ success: false, reason: err.response });
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
reject(err);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Gets a full whitelist allowed list for a specific server.
|
|
96
|
-
* @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.
|
|
97
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
98
|
-
*/
|
|
99
|
-
async getFullWhitelist(serverId) {
|
|
100
|
-
return new Promise(async (resolve, reject) => {
|
|
101
|
-
var _a;
|
|
102
|
-
try {
|
|
103
|
-
const getFullWhitelistRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('FULL_WHITELIST', serverId !== null && serverId !== void 0 ? serverId : this.instance.cmsDefaultServerId));
|
|
104
|
-
resolve({ success: true, data: getFullWhitelistRequest });
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
if (err instanceof src_1.APIError) {
|
|
108
|
-
resolve({ success: false, reason: err.response });
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
reject(err);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
118
|
-
* @param {Object} params The object that contains parameters to get a community account.
|
|
119
|
-
* @param {string} [data.accId] The account id to find a community account.
|
|
120
|
-
* @param {string} [data.apiId] The api id to find a community account.
|
|
121
|
-
* @param {string} [data.username] The username to find a community account.
|
|
122
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
123
|
-
*/
|
|
124
|
-
async getComAccount(params) {
|
|
125
|
-
return new Promise(async (resolve, reject) => {
|
|
126
|
-
var _a;
|
|
127
|
-
try {
|
|
128
|
-
const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId, params.discord));
|
|
129
|
-
resolve({ success: true, data: getAccountRequest });
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
if (err instanceof src_1.APIError) {
|
|
133
|
-
resolve({ success: false, reason: err.response });
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
reject(err);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
143
|
-
* @param {Object} params The object that contains parameters to get a community account.
|
|
144
|
-
* @param {string} [data.accId] (Optional) The account id to find a community account.
|
|
145
|
-
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
146
|
-
* @param {string} [data.username] (Optional) The username to find a community account.
|
|
147
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
148
|
-
*/
|
|
149
|
-
async getAccountRanks(params) {
|
|
150
|
-
return new Promise(async (resolve, reject) => {
|
|
151
|
-
var _a;
|
|
152
|
-
try {
|
|
153
|
-
const getAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId, params.discord));
|
|
154
|
-
resolve({ success: true, data: getAccountRanksRequest });
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
if (err instanceof src_1.APIError) {
|
|
158
|
-
resolve({ success: false, reason: err.response });
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
reject(err);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Clocks in or out an account by `accId` or `apiId`.
|
|
168
|
-
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
169
|
-
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
170
|
-
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
171
|
-
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
172
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
173
|
-
*/
|
|
174
|
-
async clockInOut(data) {
|
|
175
|
-
return new Promise(async (resolve, reject) => {
|
|
176
|
-
var _a;
|
|
177
|
-
try {
|
|
178
|
-
const clockInOutRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
|
|
179
|
-
const clockInOutResponse = clockInOutRequest;
|
|
180
|
-
if (!clockInOutResponse)
|
|
181
|
-
resolve({ success: false, reason: clockInOutRequest });
|
|
182
|
-
resolve({ success: true, clockedIn: clockInOutResponse.completed });
|
|
183
|
-
}
|
|
184
|
-
catch (err) {
|
|
185
|
-
if (err instanceof src_1.APIError) {
|
|
186
|
-
resolve({ success: false, reason: err.response });
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
reject(err);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
196
|
-
* @param {string} apiId The api id to check for an account.
|
|
197
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
198
|
-
*/
|
|
199
|
-
async checkComApiId(apiId) {
|
|
200
|
-
return new Promise(async (resolve, reject) => {
|
|
201
|
-
var _a;
|
|
202
|
-
try {
|
|
203
|
-
const checkComApiIdRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CHECK_COM_APIID', apiId));
|
|
204
|
-
resolve({ success: true, username: checkComApiIdRequest });
|
|
205
|
-
}
|
|
206
|
-
catch (err) {
|
|
207
|
-
if (err instanceof src_1.APIError) {
|
|
208
|
-
resolve({ success: false, reason: err.response });
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
reject(err);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Gets all department information within the community CMS.
|
|
218
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
219
|
-
*/
|
|
220
|
-
async getDepartments() {
|
|
221
|
-
return new Promise(async (resolve, reject) => {
|
|
222
|
-
var _a;
|
|
223
|
-
try {
|
|
224
|
-
const getDepartmentsRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_DEPARTMENTS'));
|
|
225
|
-
resolve({ success: true, data: getDepartmentsRequest });
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
if (err instanceof src_1.APIError) {
|
|
229
|
-
resolve({ success: false, reason: err.response });
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
reject(err);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Sets a community account's ranks for the CMS community.
|
|
239
|
-
* @param {string} accountId The object that contains critical data to clock in or out an account.
|
|
240
|
-
* @param {Object} changes The object that contains change data for setting account ranks.
|
|
241
|
-
* @param {Object} [changes.set] (Optional) The object that contains primary and secondary data for setting account ranks.
|
|
242
|
-
* @param {string} [changes.set.primary] (Optional) The primary rank ID wanting to set to the account.
|
|
243
|
-
* @param {string} [changes.set.secondary] (Optional) The secondary rank ID(s) wanting to set to the account.
|
|
244
|
-
* @param {Array} [changes.add] (Optional) The secondary rank IDs wanting to add to the account.
|
|
245
|
-
* @param {Array} [changes.remove] (Optional) The secondary rank IDs wanting to remove to the account.
|
|
246
|
-
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
247
|
-
*/
|
|
248
|
-
async setAccountRanks(accountId, changes) {
|
|
249
|
-
return new Promise(async (resolve, reject) => {
|
|
250
|
-
var _a;
|
|
251
|
-
try {
|
|
252
|
-
const setAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('SET_ACCOUNT_RANKS', accountId, changes.set, changes.add, changes.remove));
|
|
253
|
-
resolve({ success: true, data: setAccountRanksRequest });
|
|
254
|
-
}
|
|
255
|
-
catch (err) {
|
|
256
|
-
if (err instanceof src_1.APIError) {
|
|
257
|
-
resolve({ success: false, reason: err.response });
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
reject(err);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
exports.CMSManager = CMSManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.CMSManager = void 0;
|
|
27
|
+
const src_1 = require("../libs/rest/src");
|
|
28
|
+
const BaseManager_1 = require("./BaseManager");
|
|
29
|
+
const globalTypes = __importStar(require("../constants"));
|
|
30
|
+
const CMSServerManager_1 = require("./CMSServerManager");
|
|
31
|
+
/**
|
|
32
|
+
* Manages all Sonoran CMS data and methods to interact with the public API.
|
|
33
|
+
*/
|
|
34
|
+
class CMSManager extends BaseManager_1.BaseManager {
|
|
35
|
+
constructor(instance) {
|
|
36
|
+
super(instance);
|
|
37
|
+
this.ready = false;
|
|
38
|
+
this.version = 0;
|
|
39
|
+
this.failReason = null;
|
|
40
|
+
this.rest = new src_1.REST(instance, this, globalTypes.productEnums.CMS, src_1.DefaultCMSRestOptions);
|
|
41
|
+
this.buildManager(instance);
|
|
42
|
+
}
|
|
43
|
+
async buildManager(instance) {
|
|
44
|
+
var _a;
|
|
45
|
+
const mutableThis = this;
|
|
46
|
+
try {
|
|
47
|
+
const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SUB_VERSION'));
|
|
48
|
+
const version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
|
|
49
|
+
if (version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
|
|
50
|
+
this.servers = new CMSServerManager_1.CMSServerManager(instance, this);
|
|
51
|
+
}
|
|
52
|
+
mutableThis.ready = true;
|
|
53
|
+
mutableThis.version = version;
|
|
54
|
+
instance.isCMSSuccessful = true;
|
|
55
|
+
instance.emit('CMS_SETUP_SUCCESSFUL');
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
mutableThis.failReason = err;
|
|
59
|
+
instance.emit('CMS_SETUP_UNSUCCESSFUL', err);
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
65
|
+
* @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).
|
|
66
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
67
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
68
|
+
* @param {string} [data.serverId] The username to find a community account.
|
|
69
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
70
|
+
*/
|
|
71
|
+
async verifyWhitelist(data) {
|
|
72
|
+
return new Promise(async (resolve, reject) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
try {
|
|
75
|
+
const isString = typeof data === 'string';
|
|
76
|
+
const whitelistRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('VERIFY_WHITELIST', isString ? data : data.apiId, isString ? data : data.accId, isString ? this.instance.cmsDefaultServerId : (_b = data.serverId) !== null && _b !== void 0 ? _b : this.instance.cmsDefaultServerId));
|
|
77
|
+
if (typeof whitelistRequest === 'string') {
|
|
78
|
+
resolve({ success: true, reason: whitelistRequest });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
resolve({ success: false, reason: whitelistRequest.message });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (err instanceof src_1.APIError) {
|
|
86
|
+
resolve({ success: false, reason: err.response });
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
reject(err);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets a full whitelist allowed list for a specific server.
|
|
96
|
+
* @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.
|
|
97
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
98
|
+
*/
|
|
99
|
+
async getFullWhitelist(serverId) {
|
|
100
|
+
return new Promise(async (resolve, reject) => {
|
|
101
|
+
var _a;
|
|
102
|
+
try {
|
|
103
|
+
const getFullWhitelistRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('FULL_WHITELIST', serverId !== null && serverId !== void 0 ? serverId : this.instance.cmsDefaultServerId));
|
|
104
|
+
resolve({ success: true, data: getFullWhitelistRequest });
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
if (err instanceof src_1.APIError) {
|
|
108
|
+
resolve({ success: false, reason: err.response });
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
reject(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
118
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
119
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
120
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
121
|
+
* @param {string} [data.username] The username to find a community account.
|
|
122
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
123
|
+
*/
|
|
124
|
+
async getComAccount(params) {
|
|
125
|
+
return new Promise(async (resolve, reject) => {
|
|
126
|
+
var _a;
|
|
127
|
+
try {
|
|
128
|
+
const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId, params.discord));
|
|
129
|
+
resolve({ success: true, data: getAccountRequest });
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
if (err instanceof src_1.APIError) {
|
|
133
|
+
resolve({ success: false, reason: err.response });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
reject(err);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
143
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
144
|
+
* @param {string} [data.accId] (Optional) The account id to find a community account.
|
|
145
|
+
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
146
|
+
* @param {string} [data.username] (Optional) The username to find a community account.
|
|
147
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
148
|
+
*/
|
|
149
|
+
async getAccountRanks(params) {
|
|
150
|
+
return new Promise(async (resolve, reject) => {
|
|
151
|
+
var _a;
|
|
152
|
+
try {
|
|
153
|
+
const getAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId, params.discord));
|
|
154
|
+
resolve({ success: true, data: getAccountRanksRequest });
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
if (err instanceof src_1.APIError) {
|
|
158
|
+
resolve({ success: false, reason: err.response });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
reject(err);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Clocks in or out an account by `accId` or `apiId`.
|
|
168
|
+
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
169
|
+
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
170
|
+
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
171
|
+
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
172
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
173
|
+
*/
|
|
174
|
+
async clockInOut(data) {
|
|
175
|
+
return new Promise(async (resolve, reject) => {
|
|
176
|
+
var _a;
|
|
177
|
+
try {
|
|
178
|
+
const clockInOutRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
|
|
179
|
+
const clockInOutResponse = clockInOutRequest;
|
|
180
|
+
if (!clockInOutResponse)
|
|
181
|
+
resolve({ success: false, reason: clockInOutRequest });
|
|
182
|
+
resolve({ success: true, clockedIn: clockInOutResponse.completed });
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
if (err instanceof src_1.APIError) {
|
|
186
|
+
resolve({ success: false, reason: err.response });
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
reject(err);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
196
|
+
* @param {string} apiId The api id to check for an account.
|
|
197
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
198
|
+
*/
|
|
199
|
+
async checkComApiId(apiId) {
|
|
200
|
+
return new Promise(async (resolve, reject) => {
|
|
201
|
+
var _a;
|
|
202
|
+
try {
|
|
203
|
+
const checkComApiIdRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CHECK_COM_APIID', apiId));
|
|
204
|
+
resolve({ success: true, username: checkComApiIdRequest });
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
if (err instanceof src_1.APIError) {
|
|
208
|
+
resolve({ success: false, reason: err.response });
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
reject(err);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets all department information within the community CMS.
|
|
218
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
219
|
+
*/
|
|
220
|
+
async getDepartments() {
|
|
221
|
+
return new Promise(async (resolve, reject) => {
|
|
222
|
+
var _a;
|
|
223
|
+
try {
|
|
224
|
+
const getDepartmentsRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_DEPARTMENTS'));
|
|
225
|
+
resolve({ success: true, data: getDepartmentsRequest });
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
if (err instanceof src_1.APIError) {
|
|
229
|
+
resolve({ success: false, reason: err.response });
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
reject(err);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Sets a community account's ranks for the CMS community.
|
|
239
|
+
* @param {string} accountId The object that contains critical data to clock in or out an account.
|
|
240
|
+
* @param {Object} changes The object that contains change data for setting account ranks.
|
|
241
|
+
* @param {Object} [changes.set] (Optional) The object that contains primary and secondary data for setting account ranks.
|
|
242
|
+
* @param {string} [changes.set.primary] (Optional) The primary rank ID wanting to set to the account.
|
|
243
|
+
* @param {string} [changes.set.secondary] (Optional) The secondary rank ID(s) wanting to set to the account.
|
|
244
|
+
* @param {Array} [changes.add] (Optional) The secondary rank IDs wanting to add to the account.
|
|
245
|
+
* @param {Array} [changes.remove] (Optional) The secondary rank IDs wanting to remove to the account.
|
|
246
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
247
|
+
*/
|
|
248
|
+
async setAccountRanks(accountId, changes) {
|
|
249
|
+
return new Promise(async (resolve, reject) => {
|
|
250
|
+
var _a;
|
|
251
|
+
try {
|
|
252
|
+
const setAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('SET_ACCOUNT_RANKS', accountId, changes.set, changes.add, changes.remove));
|
|
253
|
+
resolve({ success: true, data: setAccountRanksRequest });
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
if (err instanceof src_1.APIError) {
|
|
257
|
+
resolve({ success: false, reason: err.response });
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
reject(err);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.CMSManager = CMSManager;
|
|
@@ -1,8 +1,8 @@
|
|
|
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
|
-
export declare class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
|
|
7
|
-
constructor(instance: Instance, manager: CMSManager);
|
|
8
|
-
}
|
|
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
|
+
export declare class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
|
|
7
|
+
constructor(instance: Instance, manager: CMSManager);
|
|
8
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CMSServerManager = void 0;
|
|
4
|
-
const CMSServer_1 = require("../structures/CMSServer");
|
|
5
|
-
const CacheManager_1 = require("./CacheManager");
|
|
6
|
-
class CMSServerManager extends CacheManager_1.CacheManager {
|
|
7
|
-
constructor(instance, manager) {
|
|
8
|
-
super(instance, CMSServer_1.CMSServer, []);
|
|
9
|
-
(async () => {
|
|
10
|
-
var _a;
|
|
11
|
-
while (!manager.ready) {
|
|
12
|
-
await new Promise((resolve) => {
|
|
13
|
-
setTimeout(resolve, 100);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
|
|
18
|
-
const servers = serversRes.servers;
|
|
19
|
-
servers.forEach((server) => {
|
|
20
|
-
const serverStruct = {
|
|
21
|
-
id: server.id,
|
|
22
|
-
config: server
|
|
23
|
-
};
|
|
24
|
-
this._add(serverStruct, true, server.id);
|
|
25
|
-
});
|
|
26
|
-
console.log(`Found ${servers.length} servers`);
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
throw new Error(String(err));
|
|
30
|
-
}
|
|
31
|
-
})();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.CMSServerManager = CMSServerManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CMSServerManager = void 0;
|
|
4
|
+
const CMSServer_1 = require("../structures/CMSServer");
|
|
5
|
+
const CacheManager_1 = require("./CacheManager");
|
|
6
|
+
class CMSServerManager extends CacheManager_1.CacheManager {
|
|
7
|
+
constructor(instance, manager) {
|
|
8
|
+
super(instance, CMSServer_1.CMSServer, []);
|
|
9
|
+
(async () => {
|
|
10
|
+
var _a;
|
|
11
|
+
while (!manager.ready) {
|
|
12
|
+
await new Promise((resolve) => {
|
|
13
|
+
setTimeout(resolve, 100);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
|
|
18
|
+
const servers = serversRes.servers;
|
|
19
|
+
servers.forEach((server) => {
|
|
20
|
+
const serverStruct = {
|
|
21
|
+
id: server.id,
|
|
22
|
+
config: server
|
|
23
|
+
};
|
|
24
|
+
this._add(serverStruct, true, server.id);
|
|
25
|
+
});
|
|
26
|
+
console.log(`Found ${servers.length} servers`);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new Error(String(err));
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.CMSServerManager = CMSServerManager;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Collection } from '@discordjs/collection';
|
|
2
|
-
import { Instance } from '../instance/Instance';
|
|
3
|
-
import { Constructable } from '../constants';
|
|
4
|
-
import { DataManager } from './DataManager';
|
|
5
|
-
export declare class CacheManager<K, Holds, R> extends DataManager<K, Holds, R> {
|
|
6
|
-
_cache: Collection<any, any> | never;
|
|
7
|
-
protected constructor(instance: Instance, holds: Constructable<Holds>, iterable: Iterable<any>);
|
|
8
|
-
get cache(): Collection<any, any>;
|
|
9
|
-
_add(data: any, cache?: boolean, id?: K): any;
|
|
10
|
-
}
|
|
1
|
+
import { Collection } from '@discordjs/collection';
|
|
2
|
+
import { Instance } from '../instance/Instance';
|
|
3
|
+
import { Constructable } from '../constants';
|
|
4
|
+
import { DataManager } from './DataManager';
|
|
5
|
+
export declare class CacheManager<K, Holds, R> extends DataManager<K, Holds, R> {
|
|
6
|
+
_cache: Collection<any, any> | never;
|
|
7
|
+
protected constructor(instance: Instance, holds: Constructable<Holds>, iterable: Iterable<any>);
|
|
8
|
+
get cache(): Collection<any, any>;
|
|
9
|
+
_add(data: any, cache?: boolean, id?: K): any;
|
|
10
|
+
}
|