@sonoransoftware/sonoran.js 1.0.0 → 1.0.3
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/.github/workflows/npm-publish.yml +34 -0
- package/dist/builders/cad/DispatchCall.d.ts +92 -0
- package/dist/builders/cad/DispatchCall.js +144 -0
- package/dist/builders/cad/index.d.ts +1 -0
- package/dist/builders/cad/index.js +17 -0
- package/dist/builders/index.d.ts +1 -0
- package/dist/builders/index.js +19 -0
- package/dist/constants.d.ts +174 -0
- package/dist/constants.js +27 -0
- package/dist/errors/LibraryErrors.d.ts +19 -0
- package/dist/errors/LibraryErrors.js +47 -0
- package/dist/errors/Messages.d.ts +1 -0
- package/dist/errors/Messages.js +8 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +18 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +24 -0
- package/dist/instance/Instance.d.ts +23 -0
- package/dist/instance/Instance.js +135 -0
- package/dist/instance/instance.types.d.ts +16 -0
- package/dist/instance/instance.types.js +2 -0
- package/dist/libs/rest/src/index.d.ts +6 -0
- package/dist/libs/rest/src/index.js +22 -0
- package/dist/libs/rest/src/lib/REST.d.ts +99 -0
- package/dist/libs/rest/src/lib/REST.js +102 -0
- package/dist/libs/rest/src/lib/RequestManager.d.ts +58 -0
- package/dist/libs/rest/src/lib/RequestManager.js +190 -0
- package/dist/libs/rest/src/lib/errors/APIError.d.ts +9 -0
- package/dist/libs/rest/src/lib/errors/APIError.js +17 -0
- package/dist/libs/rest/src/lib/errors/HTTPError.d.ts +17 -0
- package/dist/libs/rest/src/lib/errors/HTTPError.js +23 -0
- package/dist/libs/rest/src/lib/errors/RateLimitError.d.ts +13 -0
- package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -0
- package/dist/libs/rest/src/lib/errors/index.d.ts +4 -0
- package/dist/libs/rest/src/lib/errors/index.js +20 -0
- package/dist/libs/rest/src/lib/handlers/IHandler.d.ts +7 -0
- package/dist/libs/rest/src/lib/handlers/IHandler.js +2 -0
- package/dist/libs/rest/src/lib/handlers/SequentialHandler.d.ts +45 -0
- package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +143 -0
- package/dist/libs/rest/src/lib/utils/Utils.d.ts +1 -0
- package/dist/libs/rest/src/lib/utils/Utils.js +22 -0
- package/dist/libs/rest/src/lib/utils/constants.d.ts +501 -0
- package/dist/libs/rest/src/lib/utils/constants.js +423 -0
- package/dist/managers/BaseManager.d.ts +14 -0
- package/dist/managers/BaseManager.js +18 -0
- package/dist/managers/CADActiveUnitsManager.d.ts +15 -0
- package/dist/managers/CADActiveUnitsManager.js +38 -0
- package/dist/managers/CADManager.d.ts +27 -0
- package/dist/managers/CADManager.js +81 -0
- package/dist/managers/CADServerManager.d.ts +8 -0
- package/dist/managers/CADServerManager.js +28 -0
- package/dist/managers/CMSManager.d.ts +81 -0
- package/dist/managers/CMSManager.js +212 -0
- package/dist/managers/CMSServerManager.d.ts +8 -0
- package/dist/managers/CMSServerManager.js +28 -0
- package/dist/managers/CacheManager.d.ts +10 -0
- package/dist/managers/CacheManager.js +39 -0
- package/dist/managers/DataManager.d.ts +31 -0
- package/dist/managers/DataManager.js +61 -0
- package/dist/structures/Base.d.ts +9 -0
- package/dist/structures/Base.js +24 -0
- package/dist/structures/CADActiveUnit.d.ts +47 -0
- package/dist/structures/CADActiveUnit.js +66 -0
- package/dist/structures/CADServer.d.ts +26 -0
- package/dist/structures/CADServer.js +15 -0
- package/dist/structures/CMSServer.d.ts +18 -0
- package/dist/structures/CMSServer.js +12 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +13 -0
- package/dist/utils/utils.js +82 -0
- package/package.json +48 -42
- package/src/constants.ts +27 -10
- package/src/index.ts +1 -9
- package/src/instance/Instance.ts +2 -2
- package/src/libs/rest/src/lib/REST.ts +7 -2
- package/src/libs/rest/src/lib/RequestManager.ts +2 -2
- package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +1 -0
- package/src/libs/rest/src/lib/utils/constants.ts +21 -1
- package/src/managers/BaseManager.ts +1 -1
- package/src/managers/CADActiveUnitsManager.ts +1 -1
- package/src/managers/CADManager.ts +2 -1
- package/src/managers/CADServerManager.ts +1 -1
- package/src/managers/CMSManager.ts +49 -3
- package/src/managers/CMSServerManager.ts +1 -1
- package/src/managers/CacheManager.ts +1 -1
- package/src/managers/DataManager.ts +1 -1
- package/src/structures/Base.ts +1 -1
- package/src/structures/CADActiveUnit.ts +1 -1
- package/src/structures/CADServer.ts +1 -1
- package/src/structures/CMSServer.ts +1 -1
- package/tsconfig.json +4 -4
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { CMSSubscriptionVersionEnum } from '../constants';
|
|
3
|
+
import { REST } from '../libs/rest/src';
|
|
4
|
+
import { BaseManager } from './BaseManager';
|
|
5
|
+
import * as globalTypes from '../constants';
|
|
6
|
+
import { CMSServerManager } from './CMSServerManager';
|
|
7
|
+
/**
|
|
8
|
+
* Manages all Sonoran CMS data and methods to interact with the public API.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CMSManager extends BaseManager {
|
|
11
|
+
readonly ready: boolean;
|
|
12
|
+
readonly version: CMSSubscriptionVersionEnum;
|
|
13
|
+
rest: REST | undefined;
|
|
14
|
+
servers: CMSServerManager | undefined;
|
|
15
|
+
constructor(instance: Instance);
|
|
16
|
+
protected buildManager(instance: Instance): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
19
|
+
* @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).
|
|
20
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
21
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
22
|
+
* @param {string} [data.serverId] The username to find a community account.
|
|
23
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
24
|
+
*/
|
|
25
|
+
verifyWhitelist(data: {
|
|
26
|
+
accId?: string;
|
|
27
|
+
apiId?: string;
|
|
28
|
+
serverId?: number;
|
|
29
|
+
} | string): Promise<globalTypes.CMSVerifyWhitelistPromiseResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Gets a full whitelist allowed list for a specific server.
|
|
32
|
+
* @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.
|
|
33
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
34
|
+
*/
|
|
35
|
+
getFullWhitelist(serverId?: number): Promise<globalTypes.CMSGetFullWhitelistPromiseResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
38
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
39
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
40
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
41
|
+
* @param {string} [data.username] The username to find a community account.
|
|
42
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
43
|
+
*/
|
|
44
|
+
getComAccount(params: {
|
|
45
|
+
accId?: string;
|
|
46
|
+
apiId?: string;
|
|
47
|
+
username?: string;
|
|
48
|
+
}): Promise<globalTypes.CMSGetComAccountPromiseResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
51
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
52
|
+
* @param {string} [data.accId] (Optional) The account id to find a community account.
|
|
53
|
+
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
54
|
+
* @param {string} [data.username] (Optional) The username to find a community account.
|
|
55
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
56
|
+
*/
|
|
57
|
+
getAccountRanks(params: {
|
|
58
|
+
accId?: string;
|
|
59
|
+
apiId?: string;
|
|
60
|
+
username?: string;
|
|
61
|
+
}): Promise<globalTypes.CMSGetAccountRanksPromiseResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Clocks in or out an account by `accId` or `apiId`.
|
|
64
|
+
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
65
|
+
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
66
|
+
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
67
|
+
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
68
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
69
|
+
*/
|
|
70
|
+
clockInOut(data: {
|
|
71
|
+
accId?: string;
|
|
72
|
+
apiId?: string;
|
|
73
|
+
forceClockIn?: boolean;
|
|
74
|
+
}): Promise<globalTypes.CMSClockInOutPromiseResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
77
|
+
* @param {string} apiId The api id to check for an account.
|
|
78
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
79
|
+
*/
|
|
80
|
+
checkComApiId(apiId: string): Promise<globalTypes.CMSCheckComApiIdPromiseResult>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
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.rest = new src_1.REST(instance, this, globalTypes.productEnums.CMS, src_1.DefaultCMSRestOptions);
|
|
40
|
+
this.buildManager(instance);
|
|
41
|
+
}
|
|
42
|
+
async buildManager(instance) {
|
|
43
|
+
var _a;
|
|
44
|
+
try {
|
|
45
|
+
const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SUB_VERSION'));
|
|
46
|
+
const mutableThis = this;
|
|
47
|
+
mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
|
|
48
|
+
if (this.version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
|
|
49
|
+
this.servers = new CMSServerManager_1.CMSServerManager(instance, this);
|
|
50
|
+
}
|
|
51
|
+
mutableThis.ready = true;
|
|
52
|
+
instance.isCMSSuccessful = true;
|
|
53
|
+
instance.emit('CMS_SETUP_SUCCESSFUL');
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
instance.emit('CMS_SETUP_UNSUCCESSFUL', err);
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
62
|
+
* @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).
|
|
63
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
64
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
65
|
+
* @param {string} [data.serverId] The username to find a community account.
|
|
66
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
67
|
+
*/
|
|
68
|
+
async verifyWhitelist(data) {
|
|
69
|
+
return new Promise(async (resolve, reject) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
try {
|
|
72
|
+
const isString = typeof data === 'string';
|
|
73
|
+
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));
|
|
74
|
+
if (typeof whitelistRequest === 'string') {
|
|
75
|
+
resolve({ success: true, reason: whitelistRequest });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
resolve({ success: false, reason: whitelistRequest });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (err instanceof src_1.APIError) {
|
|
83
|
+
resolve({ success: false, reason: err.response });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets a full whitelist allowed list for a specific server.
|
|
93
|
+
* @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.
|
|
94
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
95
|
+
*/
|
|
96
|
+
async getFullWhitelist(serverId) {
|
|
97
|
+
return new Promise(async (resolve, reject) => {
|
|
98
|
+
var _a;
|
|
99
|
+
try {
|
|
100
|
+
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));
|
|
101
|
+
resolve({ success: true, data: getFullWhitelistRequest });
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (err instanceof src_1.APIError) {
|
|
105
|
+
resolve({ success: false, reason: err.response });
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
reject(err);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
115
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
116
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
117
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
118
|
+
* @param {string} [data.username] The username to find a community account.
|
|
119
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
120
|
+
*/
|
|
121
|
+
async getComAccount(params) {
|
|
122
|
+
return new Promise(async (resolve, reject) => {
|
|
123
|
+
var _a;
|
|
124
|
+
try {
|
|
125
|
+
const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId));
|
|
126
|
+
resolve({ success: true, data: getAccountRequest });
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
if (err instanceof src_1.APIError) {
|
|
130
|
+
resolve({ success: false, reason: err.response });
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
reject(err);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
140
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
141
|
+
* @param {string} [data.accId] (Optional) The account id to find a community account.
|
|
142
|
+
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
143
|
+
* @param {string} [data.username] (Optional) The username to find a community account.
|
|
144
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
145
|
+
*/
|
|
146
|
+
async getAccountRanks(params) {
|
|
147
|
+
return new Promise(async (resolve, reject) => {
|
|
148
|
+
var _a;
|
|
149
|
+
try {
|
|
150
|
+
const getAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId));
|
|
151
|
+
resolve({ success: true, data: getAccountRanksRequest });
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
if (err instanceof src_1.APIError) {
|
|
155
|
+
resolve({ success: false, reason: err.response });
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
reject(err);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Clocks in or out an account by `accId` or `apiId`.
|
|
165
|
+
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
166
|
+
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
167
|
+
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
168
|
+
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
169
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
170
|
+
*/
|
|
171
|
+
async clockInOut(data) {
|
|
172
|
+
return new Promise(async (resolve, reject) => {
|
|
173
|
+
var _a;
|
|
174
|
+
try {
|
|
175
|
+
const clockInOutRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
|
|
176
|
+
const clockInOutRequestString = clockInOutRequest;
|
|
177
|
+
resolve({ success: true, clockedIn: clockInOutRequestString.includes('CLOCKED IN') });
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
if (err instanceof src_1.APIError) {
|
|
181
|
+
resolve({ success: false, reason: err.response });
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
reject(err);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
191
|
+
* @param {string} apiId The api id to check for an account.
|
|
192
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
193
|
+
*/
|
|
194
|
+
async checkComApiId(apiId) {
|
|
195
|
+
return new Promise(async (resolve, reject) => {
|
|
196
|
+
var _a;
|
|
197
|
+
try {
|
|
198
|
+
const checkComApiIdRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CHECK_COM_APIID', apiId));
|
|
199
|
+
resolve({ success: true, username: checkComApiIdRequest });
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
if (err instanceof src_1.APIError) {
|
|
203
|
+
resolve({ success: false, reason: err.response });
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
reject(err);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.CMSManager = CMSManager;
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
try {
|
|
12
|
+
const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
|
|
13
|
+
const servers = serversRes.servers;
|
|
14
|
+
servers.forEach((server) => {
|
|
15
|
+
const serverStruct = {
|
|
16
|
+
id: server.id,
|
|
17
|
+
config: server
|
|
18
|
+
};
|
|
19
|
+
this._add(serverStruct, true, server.id);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
throw new Error(String(err));
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CMSServerManager = CMSServerManager;
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CacheManager = void 0;
|
|
7
|
+
const collection_1 = __importDefault(require("@discordjs/collection"));
|
|
8
|
+
const DataManager_1 = require("./DataManager");
|
|
9
|
+
class CacheManager extends DataManager_1.DataManager {
|
|
10
|
+
constructor(instance, holds, iterable) {
|
|
11
|
+
super(instance, holds);
|
|
12
|
+
this._cache = new collection_1.default();
|
|
13
|
+
if (iterable) {
|
|
14
|
+
for (const item of iterable) {
|
|
15
|
+
this._add(item);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
get cache() {
|
|
20
|
+
return this._cache;
|
|
21
|
+
}
|
|
22
|
+
_add(data, cache = true, id) {
|
|
23
|
+
const existing = this.cache.get(id !== null && id !== void 0 ? id : data.id);
|
|
24
|
+
if (existing) {
|
|
25
|
+
if (cache) {
|
|
26
|
+
existing._patch(data);
|
|
27
|
+
return existing;
|
|
28
|
+
}
|
|
29
|
+
const clone = existing._clone();
|
|
30
|
+
clone._patch(data);
|
|
31
|
+
return clone;
|
|
32
|
+
}
|
|
33
|
+
const entry = data;
|
|
34
|
+
if (cache)
|
|
35
|
+
this.cache.set(id !== null && id !== void 0 ? id : entry.id, entry);
|
|
36
|
+
return entry;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.CacheManager = CacheManager;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { BaseManager } from './BaseManager';
|
|
3
|
+
import { Constructable } from '../constants';
|
|
4
|
+
import Collection from '@discordjs/collection';
|
|
5
|
+
interface DataManagerInstanceObject {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class DataManager<_K, Holds, _R> extends BaseManager {
|
|
9
|
+
holds: Constructable<Holds>;
|
|
10
|
+
constructor(instance: Instance, holds: any);
|
|
11
|
+
/**
|
|
12
|
+
* The cache of items for this manager.
|
|
13
|
+
* @type {Collection}
|
|
14
|
+
* @abstract
|
|
15
|
+
*/
|
|
16
|
+
get cache(): Collection<any, any>;
|
|
17
|
+
/**
|
|
18
|
+
* Resolves a data entry to a data Object.
|
|
19
|
+
* @param idOrInstance The id or instance of something in this Manager
|
|
20
|
+
* @returns {?Object} An instance from this Manager
|
|
21
|
+
*/
|
|
22
|
+
resolve(idOrInstance: string | object): object | null;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a data entry to an instance id.
|
|
25
|
+
* @param {string|Object} idOrInstance The id or instance of something in this Manager
|
|
26
|
+
* @returns {?Snowflake}
|
|
27
|
+
*/
|
|
28
|
+
resolveId(idOrInstance: string | DataManagerInstanceObject): string | null;
|
|
29
|
+
valueOf(): Collection<any, any>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DataManager = void 0;
|
|
7
|
+
const BaseManager_1 = require("./BaseManager");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
const collection_1 = __importDefault(require("@discordjs/collection"));
|
|
10
|
+
class DataManager extends BaseManager_1.BaseManager {
|
|
11
|
+
constructor(instance, holds) {
|
|
12
|
+
super(instance);
|
|
13
|
+
/**
|
|
14
|
+
* The data structure belonging to this manager.
|
|
15
|
+
* @name DataManager#holds
|
|
16
|
+
* @type {Function}
|
|
17
|
+
* @private
|
|
18
|
+
* @readonly
|
|
19
|
+
*/
|
|
20
|
+
this.holds = holds;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The cache of items for this manager.
|
|
24
|
+
* @type {Collection}
|
|
25
|
+
* @abstract
|
|
26
|
+
*/
|
|
27
|
+
get cache() {
|
|
28
|
+
throw new errors_1.GenericError('NOT_IMPLEMENTED', 'get cache', this.constructor.name);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves a data entry to a data Object.
|
|
32
|
+
* @param idOrInstance The id or instance of something in this Manager
|
|
33
|
+
* @returns {?Object} An instance from this Manager
|
|
34
|
+
*/
|
|
35
|
+
resolve(idOrInstance) {
|
|
36
|
+
var _a;
|
|
37
|
+
if (this.cache instanceof collection_1.default) {
|
|
38
|
+
if (typeof idOrInstance === 'object')
|
|
39
|
+
return idOrInstance;
|
|
40
|
+
if (typeof idOrInstance === 'string')
|
|
41
|
+
return (_a = this.cache.get(idOrInstance)) !== null && _a !== void 0 ? _a : null;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a data entry to an instance id.
|
|
47
|
+
* @param {string|Object} idOrInstance The id or instance of something in this Manager
|
|
48
|
+
* @returns {?Snowflake}
|
|
49
|
+
*/
|
|
50
|
+
resolveId(idOrInstance) {
|
|
51
|
+
if (typeof idOrInstance === 'object')
|
|
52
|
+
return idOrInstance.id;
|
|
53
|
+
if (typeof idOrInstance === 'string')
|
|
54
|
+
return idOrInstance;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
valueOf() {
|
|
58
|
+
return this.cache;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.DataManager = DataManager;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
export declare abstract class Base {
|
|
3
|
+
instance: Instance;
|
|
4
|
+
constructor(instance: Instance);
|
|
5
|
+
_clone(): any;
|
|
6
|
+
_patch(data: any): any;
|
|
7
|
+
_update(data: any): any;
|
|
8
|
+
toJSON(...props: Record<string, boolean | string>[]): unknown;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
class Base {
|
|
6
|
+
constructor(instance) {
|
|
7
|
+
this.instance = instance;
|
|
8
|
+
}
|
|
9
|
+
_clone() {
|
|
10
|
+
return Object.assign(Object.create(this), this);
|
|
11
|
+
}
|
|
12
|
+
_patch(data) {
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
_update(data) {
|
|
16
|
+
const clone = this._clone();
|
|
17
|
+
this._patch(data);
|
|
18
|
+
return clone;
|
|
19
|
+
}
|
|
20
|
+
toJSON(...props) {
|
|
21
|
+
return (0, utils_1.flatten)(this, ...props);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Base = Base;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { Base } from './Base';
|
|
3
|
+
export interface CADActiveUnitStruct {
|
|
4
|
+
id: number;
|
|
5
|
+
accId: string;
|
|
6
|
+
status: number;
|
|
7
|
+
isPanic: boolean;
|
|
8
|
+
location: string;
|
|
9
|
+
aop: string;
|
|
10
|
+
isDispatch: boolean;
|
|
11
|
+
data: CADActiveUnitDataStruct;
|
|
12
|
+
}
|
|
13
|
+
interface CADActiveUnitStructPartial {
|
|
14
|
+
id: number;
|
|
15
|
+
accId: string;
|
|
16
|
+
status: number;
|
|
17
|
+
isPanic: boolean;
|
|
18
|
+
location: string;
|
|
19
|
+
aop: string;
|
|
20
|
+
isDispatch: boolean;
|
|
21
|
+
data: Partial<CADActiveUnitDataStruct>;
|
|
22
|
+
}
|
|
23
|
+
export interface CADActiveUnitDataStruct {
|
|
24
|
+
apiId1: string;
|
|
25
|
+
apiId2: string;
|
|
26
|
+
unitNum: string;
|
|
27
|
+
name: string;
|
|
28
|
+
district: string;
|
|
29
|
+
department: string;
|
|
30
|
+
subdivision: string;
|
|
31
|
+
rank: string;
|
|
32
|
+
group: string;
|
|
33
|
+
}
|
|
34
|
+
export declare type CADActiveUnitResolvable = CADActiveUnit | number;
|
|
35
|
+
export declare class CADActiveUnit extends Base {
|
|
36
|
+
id: number;
|
|
37
|
+
accId: string;
|
|
38
|
+
status: number;
|
|
39
|
+
isPanic: boolean;
|
|
40
|
+
location: string;
|
|
41
|
+
aop: string;
|
|
42
|
+
isDispatch: boolean;
|
|
43
|
+
data: CADActiveUnitDataStruct;
|
|
44
|
+
constructor(instance: Instance, data: any);
|
|
45
|
+
_patch(data: Partial<CADActiveUnitStructPartial>): void;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CADActiveUnit = void 0;
|
|
4
|
+
const Base_1 = require("./Base");
|
|
5
|
+
class CADActiveUnit extends Base_1.Base {
|
|
6
|
+
constructor(instance, data) {
|
|
7
|
+
super(instance);
|
|
8
|
+
this.id = -1;
|
|
9
|
+
this.accId = '';
|
|
10
|
+
this.status = 0;
|
|
11
|
+
this.isPanic = false;
|
|
12
|
+
this.location = '';
|
|
13
|
+
this.aop = '';
|
|
14
|
+
this.isDispatch = false;
|
|
15
|
+
this.data = {
|
|
16
|
+
apiId1: '',
|
|
17
|
+
apiId2: '',
|
|
18
|
+
unitNum: '',
|
|
19
|
+
name: '',
|
|
20
|
+
district: '',
|
|
21
|
+
department: '',
|
|
22
|
+
subdivision: '',
|
|
23
|
+
rank: '',
|
|
24
|
+
group: ''
|
|
25
|
+
};
|
|
26
|
+
if (data)
|
|
27
|
+
this._patch(data);
|
|
28
|
+
}
|
|
29
|
+
_patch(data) {
|
|
30
|
+
if (data.id !== undefined)
|
|
31
|
+
this.id = data.id;
|
|
32
|
+
if (data.accId !== undefined)
|
|
33
|
+
this.accId = data.accId;
|
|
34
|
+
if (data.status !== undefined)
|
|
35
|
+
this.status = data.status;
|
|
36
|
+
if (data.isPanic !== undefined)
|
|
37
|
+
this.isPanic = data.isPanic;
|
|
38
|
+
if (data.location !== undefined)
|
|
39
|
+
this.location = data.location;
|
|
40
|
+
if (data.aop !== undefined)
|
|
41
|
+
this.aop = data.aop;
|
|
42
|
+
if (data.isDispatch !== undefined)
|
|
43
|
+
this.isDispatch = data.isDispatch;
|
|
44
|
+
if (data.data !== undefined) {
|
|
45
|
+
if (data.data.apiId1 !== undefined)
|
|
46
|
+
this.data.apiId1 = data.data.apiId1;
|
|
47
|
+
if (data.data.apiId2 !== undefined)
|
|
48
|
+
this.data.apiId2 = data.data.apiId2;
|
|
49
|
+
if (data.data.unitNum !== undefined)
|
|
50
|
+
this.data.unitNum = data.data.unitNum;
|
|
51
|
+
if (data.data.name !== undefined)
|
|
52
|
+
this.data.name = data.data.name;
|
|
53
|
+
if (data.data.district !== undefined)
|
|
54
|
+
this.data.district = data.data.district;
|
|
55
|
+
if (data.data.department !== undefined)
|
|
56
|
+
this.data.department = data.data.department;
|
|
57
|
+
if (data.data.subdivision !== undefined)
|
|
58
|
+
this.data.subdivision = data.data.subdivision;
|
|
59
|
+
if (data.data.rank !== undefined)
|
|
60
|
+
this.data.rank = data.data.rank;
|
|
61
|
+
if (data.data.group !== undefined)
|
|
62
|
+
this.data.group = data.data.group;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.CADActiveUnit = CADActiveUnit;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { Base } from './Base';
|
|
3
|
+
export interface CADServerData {
|
|
4
|
+
id: number;
|
|
5
|
+
config: CADServerConfig;
|
|
6
|
+
}
|
|
7
|
+
export interface CADServerConfig {
|
|
8
|
+
id: number;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
signal: null;
|
|
12
|
+
mapUrl: string;
|
|
13
|
+
mapIp: string;
|
|
14
|
+
mapPort: string;
|
|
15
|
+
differingOutbound: boolean;
|
|
16
|
+
outboundIp: string;
|
|
17
|
+
listenerPort: string;
|
|
18
|
+
enableMap: boolean;
|
|
19
|
+
mapType: string;
|
|
20
|
+
isStatic: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class CADServer extends Base {
|
|
23
|
+
id: number;
|
|
24
|
+
config: CADServerConfig;
|
|
25
|
+
constructor(instance: Instance, data: CADServerData);
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CADServer = void 0;
|
|
4
|
+
// import { CADActiveUnitsManager } from '../managers/CADActiveUnitsManager';
|
|
5
|
+
const Base_1 = require("./Base");
|
|
6
|
+
class CADServer extends Base_1.Base {
|
|
7
|
+
// public units!: CADActiveUnitsManager;
|
|
8
|
+
constructor(instance, data) {
|
|
9
|
+
super(instance);
|
|
10
|
+
this.id = data.id;
|
|
11
|
+
this.config = data.config;
|
|
12
|
+
// this.units = new CADActiveUnitsManager(instance, [], this.id);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.CADServer = CADServer;
|