@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,18 @@
|
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
|
+
import { Base } from './Base';
|
|
3
|
+
export interface CMSServerData {
|
|
4
|
+
id: number;
|
|
5
|
+
config: CMSServerConfig;
|
|
6
|
+
}
|
|
7
|
+
export interface CMSServerConfig {
|
|
8
|
+
id: number;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
allowedRanks: string[];
|
|
12
|
+
blockedRanks: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare class CMSServer extends Base {
|
|
15
|
+
id: number;
|
|
16
|
+
config: CMSServerConfig;
|
|
17
|
+
constructor(instance: Instance, data: CMSServerData);
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CMSServer = void 0;
|
|
4
|
+
const Base_1 = require("./Base");
|
|
5
|
+
class CMSServer extends Base_1.Base {
|
|
6
|
+
constructor(instance, data) {
|
|
7
|
+
super(instance);
|
|
8
|
+
this.id = data.id;
|
|
9
|
+
this.config = data.config;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.CMSServer = CMSServer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function mergeDefault(def: any, given: any): any;
|
|
2
|
+
/**
|
|
3
|
+
* Shallow-copies an object with its class/prototype intact.
|
|
4
|
+
* @param {Object} obj Object to clone
|
|
5
|
+
* @returns {Object}
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare function cloneObject(obj: any): any;
|
|
9
|
+
export declare function flatten(obj: any, ...props: any[]): any;
|
|
10
|
+
export declare function warnLog(message: string): void;
|
|
11
|
+
export declare function infoLog(message: string): void;
|
|
12
|
+
export declare function errorLog(message: string): void;
|
|
13
|
+
export declare function debugLog(message: string): void;
|
|
@@ -0,0 +1,82 @@
|
|
|
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.debugLog = exports.errorLog = exports.infoLog = exports.warnLog = exports.flatten = exports.cloneObject = exports.mergeDefault = void 0;
|
|
7
|
+
const collection_1 = __importDefault(require("@discordjs/collection"));
|
|
8
|
+
const isObject = (d) => typeof d === 'object' && d !== null;
|
|
9
|
+
function mergeDefault(def, given) {
|
|
10
|
+
if (!given)
|
|
11
|
+
return def;
|
|
12
|
+
for (const key in def) {
|
|
13
|
+
if (!Object.prototype.hasOwnProperty.call(given, key) || given[key] === undefined) {
|
|
14
|
+
given[key] = def[key];
|
|
15
|
+
}
|
|
16
|
+
else if (given[key] === Object(given[key])) {
|
|
17
|
+
given[key] = mergeDefault(def[key], given[key]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return given;
|
|
21
|
+
}
|
|
22
|
+
exports.mergeDefault = mergeDefault;
|
|
23
|
+
/**
|
|
24
|
+
* Shallow-copies an object with its class/prototype intact.
|
|
25
|
+
* @param {Object} obj Object to clone
|
|
26
|
+
* @returns {Object}
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
function cloneObject(obj) {
|
|
30
|
+
return Object.assign(Object.create(obj), obj);
|
|
31
|
+
}
|
|
32
|
+
exports.cloneObject = cloneObject;
|
|
33
|
+
function flatten(obj, ...props) {
|
|
34
|
+
if (!isObject(obj))
|
|
35
|
+
return obj;
|
|
36
|
+
const objProps = Object.keys(obj)
|
|
37
|
+
.filter((k) => !k.startsWith('_'))
|
|
38
|
+
.map((k) => ({ [k]: true }));
|
|
39
|
+
props = objProps.length ? Object.assign([...objProps], ...props) : Object.assign({}, ...props); // eslint-disable-line
|
|
40
|
+
const out = {};
|
|
41
|
+
for (let [prop, newProp] of Object.entries(props)) {
|
|
42
|
+
if (!newProp)
|
|
43
|
+
continue;
|
|
44
|
+
newProp = newProp === true ? prop : newProp;
|
|
45
|
+
const element = obj[prop];
|
|
46
|
+
const elemIsObj = isObject(element);
|
|
47
|
+
const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
|
|
48
|
+
// If it's a Collection, make the array of keys
|
|
49
|
+
if (element instanceof collection_1.default)
|
|
50
|
+
out[newProp] = Array.from(element.keys());
|
|
51
|
+
// If the valueOf is a Collection, use its array of keys
|
|
52
|
+
else if (valueOf instanceof collection_1.default)
|
|
53
|
+
out[newProp] = Array.from(valueOf.keys());
|
|
54
|
+
// If it's an array, flatten each element
|
|
55
|
+
else if (Array.isArray(element))
|
|
56
|
+
out[newProp] = element.map(e => flatten(e));
|
|
57
|
+
// If it's an object with a primitive `valueOf`, use that value
|
|
58
|
+
else if (typeof valueOf !== 'object')
|
|
59
|
+
out[newProp] = valueOf;
|
|
60
|
+
// If it's a primitive
|
|
61
|
+
else if (!elemIsObj)
|
|
62
|
+
out[newProp] = element;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
exports.flatten = flatten;
|
|
67
|
+
function warnLog(message) {
|
|
68
|
+
return console.log(`[Sonoran.js - DEBUG] ${message}`);
|
|
69
|
+
}
|
|
70
|
+
exports.warnLog = warnLog;
|
|
71
|
+
function infoLog(message) {
|
|
72
|
+
return console.log(`[Sonoran.js - INFO] ${message}`);
|
|
73
|
+
}
|
|
74
|
+
exports.infoLog = infoLog;
|
|
75
|
+
function errorLog(message) {
|
|
76
|
+
return console.log(`[Sonoran.js - ERROR] ${message}`);
|
|
77
|
+
}
|
|
78
|
+
exports.errorLog = errorLog;
|
|
79
|
+
function debugLog(message) {
|
|
80
|
+
return console.log(`[Sonoran.js - DEBUG] ${message}`);
|
|
81
|
+
}
|
|
82
|
+
exports.debugLog = debugLog;
|
package/package.json
CHANGED
|
@@ -1,42 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@sonoransoftware/sonoran.js",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Sonoran.js is a library that allows you to interact with the Sonoran CAD and Sonoran CMS API. Based off of and utilizes several Discord.js library techniques for ease of use.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"eslint
|
|
23
|
-
"eslint-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@sonoransoftware/sonoran.js",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Sonoran.js is a library that allows you to interact with the Sonoran CAD and Sonoran CMS API. Based off of and utilizes several Discord.js library techniques for ease of use.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"start": "ts-node src/index.ts",
|
|
10
|
+
"build": "rimraf ./dist && tsc"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/Sonoran-Software/Sonoran.js.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^17.0.21",
|
|
21
|
+
"@types/node-fetch": "^2.6.1",
|
|
22
|
+
"eslint": "^8.10.0",
|
|
23
|
+
"eslint-config-prettier": "^8.5.0",
|
|
24
|
+
"eslint-plugin-import": "^2.25.4",
|
|
25
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
26
|
+
"prettier": "^2.5.1",
|
|
27
|
+
"rimraf": "^3.0.2",
|
|
28
|
+
"ts-loader": "^9.2.7",
|
|
29
|
+
"ts-node": "^10.7.0",
|
|
30
|
+
"tslint": "^6.1.3",
|
|
31
|
+
"typescript": "^4.6.2"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=16.9.0"
|
|
35
|
+
},
|
|
36
|
+
"nodemonConfig": {
|
|
37
|
+
"ext": "*.ts, *.json"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@discordjs/collection": "^0.5.0",
|
|
41
|
+
"@sapphire/async-queue": "^1.3.0",
|
|
42
|
+
"@sapphire/snowflake": "^3.2.0",
|
|
43
|
+
"events": "^3.3.0",
|
|
44
|
+
"node-abort-controller": "^3.0.1",
|
|
45
|
+
"node-fetch": "^2.6.5"
|
|
46
|
+
},
|
|
47
|
+
"prepublish": "npm run build"
|
|
48
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -74,26 +74,41 @@ export interface CMSVerifyWhitelistPromiseResult {
|
|
|
74
74
|
reason?: string;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export interface CMSGetFullWhitelistPromiseResult {
|
|
78
|
+
success: boolean;
|
|
79
|
+
reason?: string;
|
|
80
|
+
data?: {
|
|
81
|
+
name: string;
|
|
82
|
+
apiIds: string[];
|
|
83
|
+
}[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface CMSGetAccountRanksPromiseResult {
|
|
87
|
+
success: boolean;
|
|
88
|
+
reason?: string;
|
|
89
|
+
data?: string[];
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
export interface CMSGetComAccountPromiseResult {
|
|
78
93
|
success: boolean;
|
|
79
94
|
reason?: string;
|
|
80
95
|
data?: {
|
|
81
96
|
accId: string;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
sysStatus: boolean;
|
|
98
|
+
comStatus: boolean;
|
|
99
|
+
joinDate: string;
|
|
100
|
+
lastLogin: string;
|
|
101
|
+
owner: boolean;
|
|
102
|
+
banned: boolean;
|
|
103
|
+
activeApiIds: string[];
|
|
85
104
|
primaryIdentifier: string;
|
|
86
|
-
secondaryIdentifiers:
|
|
105
|
+
secondaryIdentifiers: {
|
|
106
|
+
identifiers: { id: string; label: string; }[];
|
|
107
|
+
}
|
|
87
108
|
primaryRank: string;
|
|
88
109
|
secondaryRanks: string[];
|
|
89
110
|
primaryDepartment: string;
|
|
90
111
|
secondaryDepartments: string[];
|
|
91
|
-
joinDate: string;
|
|
92
|
-
totalRankPower: number;
|
|
93
|
-
comOwner: boolean;
|
|
94
|
-
isBanned: boolean;
|
|
95
|
-
lastLogin: string;
|
|
96
|
-
activeApiIds: string[];
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
114
|
|
|
@@ -142,6 +157,7 @@ export interface CADGetAccountPromiseResult {
|
|
|
142
157
|
polEditUnit: boolean;
|
|
143
158
|
polEditOtherUnit: boolean;
|
|
144
159
|
selfDispatch: boolean;
|
|
160
|
+
liveMap: boolean;
|
|
145
161
|
medRecAdd: boolean;
|
|
146
162
|
medRecEdit: boolean;
|
|
147
163
|
medRecRemove: boolean;
|
|
@@ -154,6 +170,7 @@ export interface CADGetAccountPromiseResult {
|
|
|
154
170
|
dmvRecEdit: boolean;
|
|
155
171
|
dmvRecRemove: boolean;
|
|
156
172
|
dmvSuper: boolean;
|
|
173
|
+
modifyStreetSigns: boolean;
|
|
157
174
|
lawRecAdd: boolean;
|
|
158
175
|
lawRecEdit: boolean;
|
|
159
176
|
lawRecRemove: boolean;
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
export * from './instance/Instance';
|
|
2
2
|
export * from './builders';
|
|
3
3
|
export * from './libs/rest/src';
|
|
4
|
-
|
|
5
|
-
import { productEnums, CADNewDispatchBuilderOptions, CADSubscriptionVersionEnum, CMSSubscriptionVersionEnum } from './constants';
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
productEnums,
|
|
9
|
-
CADNewDispatchBuilderOptions,
|
|
10
|
-
CADSubscriptionVersionEnum,
|
|
11
|
-
CMSSubscriptionVersionEnum
|
|
12
|
-
}
|
|
4
|
+
export { productEnums, CADNewDispatchBuilderOptions, CADSubscriptionVersionEnum, CMSSubscriptionVersionEnum } from './constants';
|
package/src/instance/Instance.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import EventEmitter from '
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
2
|
|
|
3
3
|
import * as globalTypes from '../constants';
|
|
4
4
|
import * as InstanceTypes from './instance.types';
|
|
@@ -6,7 +6,7 @@ import { CADManager } from '../managers/CADManager';
|
|
|
6
6
|
import { CMSManager } from '../managers/CMSManager';
|
|
7
7
|
import { debugLog } from '../utils';
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export class Instance extends EventEmitter {
|
|
10
10
|
public cadCommunityId: string | undefined;
|
|
11
11
|
public cadApiKey: string | undefined;
|
|
12
12
|
public cadApiUrl: string = 'https://api.sonorancad.com';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter } from '
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
2
|
import {
|
|
3
3
|
InternalRequestData,
|
|
4
4
|
// RequestMethod,
|
|
@@ -11,7 +11,7 @@ import { productEnums, uuidRegex } from '../../../../constants';
|
|
|
11
11
|
import type { AgentOptions } from 'node:https';
|
|
12
12
|
import type { RequestInit, Response } from 'node-fetch';
|
|
13
13
|
// import type Collection from '@discordjs/collection';
|
|
14
|
-
import Instance from '../../../../instance/Instance';
|
|
14
|
+
import { Instance } from '../../../../instance/Instance';
|
|
15
15
|
import { CADManager } from '../../../../managers/CADManager';
|
|
16
16
|
import { convertSubNumToName } from './utils/Utils';
|
|
17
17
|
import { CMSManager } from '../../../../managers/CMSManager';
|
|
@@ -174,6 +174,11 @@ export class REST extends EventEmitter {
|
|
|
174
174
|
serverId: args[2]
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
+
case 'FULL_WHITELIST': {
|
|
178
|
+
return {
|
|
179
|
+
serverId: args[0]
|
|
180
|
+
}
|
|
181
|
+
}
|
|
177
182
|
case 'GET_COM_ACCOUNT': {
|
|
178
183
|
return {
|
|
179
184
|
apiId: args[0],
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Collection from '@discordjs/collection';
|
|
2
2
|
// import { DiscordSnowflake } from '@sapphire/snowflake';
|
|
3
|
-
import { EventEmitter } from '
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
4
|
// import type { RequestInit, BodyInit } from 'node-fetch';
|
|
5
5
|
|
|
6
|
-
import type Instance from '../../../../instance/Instance';
|
|
6
|
+
import type { Instance } from '../../../../instance/Instance';
|
|
7
7
|
import { RESTOptions, RateLimitData, RestEvents } from './REST';
|
|
8
8
|
import { DefaultCADRestOptions, DefaultCMSRestOptions, AllAPITypes/**, RESTTypedAPIDataStructs, PossibleRequestData*/ } from './utils/constants';
|
|
9
9
|
import { productEnums } from '../../../../constants';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
2
|
import { AsyncQueue } from '@sapphire/async-queue';
|
|
3
3
|
import fetch, { RequestInit, Response } from 'node-fetch';
|
|
4
|
+
import { AbortController } from "node-abort-controller";
|
|
4
5
|
// import { DiscordAPIError, DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError';
|
|
5
6
|
import { APIError } from '../errors';
|
|
6
7
|
import { HTTPError } from '../errors/HTTPError';
|
|
@@ -347,6 +347,12 @@ export const GeneralCMSAPITypes: APITypeData[] = [
|
|
|
347
347
|
method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
|
|
348
348
|
minVersion: 3
|
|
349
349
|
},
|
|
350
|
+
{
|
|
351
|
+
type: 'GET_ACCOUNT_RANKS',
|
|
352
|
+
path: 'general/get_account_ranks',
|
|
353
|
+
method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
|
|
354
|
+
minVersion: 2,
|
|
355
|
+
},
|
|
350
356
|
{
|
|
351
357
|
type: 'GET_SUB_VERSION',
|
|
352
358
|
path: 'general/get_sub_version',
|
|
@@ -379,6 +385,12 @@ export const ServersCMSAPITypes: APITypeData[] = [
|
|
|
379
385
|
path: 'servers/verify_whitelist',
|
|
380
386
|
method: 'POST',
|
|
381
387
|
minVersion: 3
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
type: 'FULL_WHITELIST',
|
|
391
|
+
path: 'servers/full_whitelist',
|
|
392
|
+
method: 'POST',
|
|
393
|
+
minVersion: 3
|
|
382
394
|
}
|
|
383
395
|
];
|
|
384
396
|
|
|
@@ -393,7 +405,7 @@ function formatForAll(array: APITypeData[], product: productEnums): AllAPITypeDa
|
|
|
393
405
|
|
|
394
406
|
export const AllAPITypes: AllAPITypeData[] = [ ...formatForAll(GeneralCADAPITypes, productEnums.CAD), ...formatForAll(CivilianCADAPITypes, productEnums.CAD), ...formatForAll(EmergencyCADAPITypes, productEnums.CAD), ...formatForAll(GeneralCMSAPITypes, productEnums.CMS), ...formatForAll(ServersCMSAPITypes, productEnums.CMS) ];
|
|
395
407
|
|
|
396
|
-
export type AllAPITypesType = 'GET_SERVERS' | 'SET_SERVERS' | 'GET_VERSION' | 'SET_PENAL_CODES' | 'SET_API_ID' | 'GET_TEMPLATES' | 'NEW_RECORD' | 'EDIT_RECORD' | 'REMOVE_RECORD' | 'LOOKUP_INT' | 'LOOKUP' | 'GET_ACCOUNT' | 'CHECK_APIID' | 'APPLY_PERMISSION_KEY' | 'SET_ACCOUNT_PERMISSIONS' | 'BAN_USER' | 'VERIFY_SECRET' | 'AUTH_STREETSIGNS' | 'SET_POSTALS' | 'SEND_PHOTO' | 'GET_CHARACTERS' | 'NEW_CHARACTER' | 'EDIT_CHARACTER' | 'REMOVE_CHARACTER' | 'GET_IDENTIFIERS' | 'MODIFY_IDENTIFIER' | 'SET_IDENTIFIER' | 'UNIT_PANIC' | 'UNIT_STATUS' | 'GET_BLIPS' | 'ADD_BLIP' | 'MODIFY_BLIP' | 'REMOVE_BLIP' | '911_CALL' | 'REMOVE_911' | 'GET_CALLS' | 'GET_ACTIVE_UNITS' | 'KICK_UNIT' | 'NEW_DISPATCH' | 'ATTACH_UNIT' | 'DETACH_UNIT' | 'SET_CALL_POSTAL' | 'SET_CALL_PRIMARY' | 'ADD_CALL_NOTE' | 'CLOSE_CALL' | 'UNIT_LOCATION' | 'SET_STREETSIGN_CONFIG' | 'UPDATE_STREETSIGN' | 'GET_COM_ACCOUNT' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT';
|
|
408
|
+
export type AllAPITypesType = 'GET_SERVERS' | 'SET_SERVERS' | 'GET_VERSION' | 'SET_PENAL_CODES' | 'SET_API_ID' | 'GET_TEMPLATES' | 'NEW_RECORD' | 'EDIT_RECORD' | 'REMOVE_RECORD' | 'LOOKUP_INT' | 'LOOKUP' | 'GET_ACCOUNT' | 'CHECK_APIID' | 'APPLY_PERMISSION_KEY' | 'SET_ACCOUNT_PERMISSIONS' | 'BAN_USER' | 'VERIFY_SECRET' | 'AUTH_STREETSIGNS' | 'SET_POSTALS' | 'SEND_PHOTO' | 'GET_CHARACTERS' | 'NEW_CHARACTER' | 'EDIT_CHARACTER' | 'REMOVE_CHARACTER' | 'GET_IDENTIFIERS' | 'MODIFY_IDENTIFIER' | 'SET_IDENTIFIER' | 'UNIT_PANIC' | 'UNIT_STATUS' | 'GET_BLIPS' | 'ADD_BLIP' | 'MODIFY_BLIP' | 'REMOVE_BLIP' | '911_CALL' | 'REMOVE_911' | 'GET_CALLS' | 'GET_ACTIVE_UNITS' | 'KICK_UNIT' | 'NEW_DISPATCH' | 'ATTACH_UNIT' | 'DETACH_UNIT' | 'SET_CALL_POSTAL' | 'SET_CALL_PRIMARY' | 'ADD_CALL_NOTE' | 'CLOSE_CALL' | 'UNIT_LOCATION' | 'SET_STREETSIGN_CONFIG' | 'UPDATE_STREETSIGN' | 'GET_COM_ACCOUNT' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT' | 'FULL_WHITELIST' | 'GET_ACCOUNT_RANKS';
|
|
397
409
|
|
|
398
410
|
export interface CMSServerAPIStruct {
|
|
399
411
|
id: number;
|
|
@@ -791,6 +803,11 @@ export interface RESTTypedAPIDataStructs {
|
|
|
791
803
|
accId?: string,
|
|
792
804
|
forceClockIn?: boolean
|
|
793
805
|
];
|
|
806
|
+
GET_ACCOUNT_RANKS: [
|
|
807
|
+
apiId?: string,
|
|
808
|
+
username?: string,
|
|
809
|
+
accId?: string,
|
|
810
|
+
],
|
|
794
811
|
// CMS - Servers
|
|
795
812
|
GET_GAME_SERVERS: [];
|
|
796
813
|
VERIFY_WHITELIST: [
|
|
@@ -798,6 +815,9 @@ export interface RESTTypedAPIDataStructs {
|
|
|
798
815
|
accId: string | undefined,
|
|
799
816
|
serverId: number
|
|
800
817
|
];
|
|
818
|
+
FULL_WHITELIST: [
|
|
819
|
+
serverId?: number,
|
|
820
|
+
]
|
|
801
821
|
}
|
|
802
822
|
|
|
803
823
|
export type PossibleRequestData =
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Work in progress still...
|
|
2
2
|
|
|
3
3
|
// import { CADActiveUnitFetchOptions } from '../constants';
|
|
4
|
-
import Instance from '../instance/Instance';
|
|
4
|
+
import { Instance } from '../instance/Instance';
|
|
5
5
|
import { CADActiveUnit, CADActiveUnitResolvable, CADActiveUnitStruct } from '../structures/CADActiveUnit';
|
|
6
6
|
import { CacheManager } from './CacheManager';
|
|
7
7
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Instance from '../instance/Instance';
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
2
|
import { CADSubscriptionVersionEnum } from '../constants';
|
|
3
3
|
import { APIError, DefaultCADRestOptions, REST } from '../libs/rest/src';
|
|
4
4
|
import { BaseManager } from './BaseManager';
|
|
@@ -29,6 +29,7 @@ export class CADManager extends BaseManager {
|
|
|
29
29
|
if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
|
|
30
30
|
this.servers = new CADServerManager(instance, this);
|
|
31
31
|
}
|
|
32
|
+
instance.isCADSuccessful = true;
|
|
32
33
|
} catch (err) {
|
|
33
34
|
console.log(err);
|
|
34
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Instance from '../instance/Instance';
|
|
1
|
+
import { Instance } from '../instance/Instance';
|
|
2
2
|
import { CMSSubscriptionVersionEnum } from '../constants';
|
|
3
3
|
import { APIError, DefaultCMSRestOptions, REST } from '../libs/rest/src';
|
|
4
4
|
import { BaseManager } from './BaseManager';
|
|
@@ -31,7 +31,10 @@ export class CMSManager extends BaseManager {
|
|
|
31
31
|
this.servers = new CMSServerManager(instance, this);
|
|
32
32
|
}
|
|
33
33
|
mutableThis.ready = true;
|
|
34
|
+
instance.isCMSSuccessful = true;
|
|
35
|
+
instance.emit('CMS_SETUP_SUCCESSFUL');
|
|
34
36
|
} catch (err) {
|
|
37
|
+
instance.emit('CMS_SETUP_UNSUCCESSFUL', err);
|
|
35
38
|
throw err;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
@@ -64,6 +67,26 @@ export class CMSManager extends BaseManager {
|
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Gets a full whitelist allowed list for a specific server.
|
|
72
|
+
* @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.
|
|
73
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
74
|
+
*/
|
|
75
|
+
public async getFullWhitelist(serverId?: number): Promise<globalTypes.CMSGetFullWhitelistPromiseResult> {
|
|
76
|
+
return new Promise(async (resolve, reject) => {
|
|
77
|
+
try {
|
|
78
|
+
const getFullWhitelistRequest: any = await this.rest?.request('FULL_WHITELIST', serverId ?? this.instance.cmsDefaultServerId);
|
|
79
|
+
resolve({ success: true, data: getFullWhitelistRequest });
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err instanceof APIError) {
|
|
82
|
+
resolve({ success: false, reason: err.response });
|
|
83
|
+
} else {
|
|
84
|
+
reject(err);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
67
90
|
/**
|
|
68
91
|
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
69
92
|
* @param {Object} params The object that contains parameters to get a community account.
|
|
@@ -87,11 +110,34 @@ export class CMSManager extends BaseManager {
|
|
|
87
110
|
});
|
|
88
111
|
}
|
|
89
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] (Optional) The account id to find a community account.
|
|
117
|
+
* @param {string} [data.apiId] (Optional) The api id to find a community account.
|
|
118
|
+
* @param {string} [data.username] (Optional) 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
|
+
public async getAccountRanks(params: { accId?: string, apiId?: string, username?: string }): Promise<globalTypes.CMSGetAccountRanksPromiseResult> {
|
|
122
|
+
return new Promise(async (resolve, reject) => {
|
|
123
|
+
try {
|
|
124
|
+
const getAccountRanksRequest: any = await this.rest?.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId);
|
|
125
|
+
resolve({ success: true, data: getAccountRanksRequest });
|
|
126
|
+
} catch (err) {
|
|
127
|
+
if (err instanceof APIError) {
|
|
128
|
+
resolve({ success: false, reason: err.response });
|
|
129
|
+
} else {
|
|
130
|
+
reject(err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
90
136
|
/**
|
|
91
137
|
* Clocks in or out an account by `accId` or `apiId`.
|
|
92
138
|
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
93
|
-
* @param {string} [data.accId] The account id to clock in or out.
|
|
94
|
-
* @param {string} [data.apiId] The api id to clock in or out.
|
|
139
|
+
* @param {string} [data.accId] (Optional) The account id to clock in or out.
|
|
140
|
+
* @param {string} [data.apiId] (Optional) The api id to clock in or out.
|
|
95
141
|
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
96
142
|
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
97
143
|
*/
|
package/src/structures/Base.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
/* Basic Options */
|
|
6
6
|
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "
|
|
8
|
-
|
|
7
|
+
"target": "ES2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
8
|
+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
9
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
10
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
11
|
// "checkJs": true, /* Report errors in .js files. */
|
|
12
12
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
13
|
-
|
|
13
|
+
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
14
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
15
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
16
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
|
|
17
|
+
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
18
18
|
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
19
|
// "composite": true, /* Enable project compilation */
|
|
20
20
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|