@sonoransoftware/sonoran.js 1.0.14 → 1.0.16
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/dist/constants.d.ts +5 -5
- package/dist/instance/Instance.d.ts +1 -0
- package/dist/instance/Instance.js +4 -0
- package/dist/instance/instance.types.d.ts +2 -1
- package/dist/libs/rest/src/lib/REST.d.ts +3 -1
- package/dist/libs/rest/src/lib/REST.js +5 -5
- package/dist/libs/rest/src/lib/RequestManager.d.ts +3 -3
- package/dist/libs/rest/src/lib/RequestManager.js +5 -7
- package/dist/libs/rest/src/lib/utils/constants.d.ts +2 -2
- package/dist/managers/CacheManager.d.ts +1 -1
- package/dist/managers/CacheManager.js +2 -5
- package/dist/managers/DataManager.d.ts +1 -1
- package/dist/managers/DataManager.js +2 -5
- package/dist/structures/CADActiveUnit.d.ts +1 -1
- package/dist/utils/utils.js +3 -6
- package/package.json +3 -3
- package/src/constants.ts +1 -1
- package/src/instance/Instance.ts +121 -117
- package/src/instance/instance.types.ts +17 -16
- package/src/libs/rest/src/lib/RequestManager.ts +3 -2
- package/src/managers/CacheManager.ts +1 -1
- package/src/managers/DataManager.ts +2 -2
- package/src/utils/utils.ts +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Collection from '@discordjs/collection';
|
|
1
|
+
import { Collection } from '@discordjs/collection';
|
|
2
2
|
import { CADDispatchOriginEnums, CADDispatchStatusEnums } from './libs/rest/src';
|
|
3
3
|
import { DataManager } from './managers/DataManager';
|
|
4
4
|
import { CADActiveUnitsManager } from './managers/CADActiveUnitsManager';
|
|
@@ -23,16 +23,16 @@ export interface CADNewDispatchBuilderOptions {
|
|
|
23
23
|
metaData?: Record<string, string>;
|
|
24
24
|
units?: string[];
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type Constructable<T> = abstract new (...args: any[]) => T;
|
|
27
27
|
export interface Caches {
|
|
28
28
|
CADActiveUnitsManager: [manager: typeof CADActiveUnitsManager, holds: CADActiveUnit];
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type CacheConstructors = {
|
|
31
31
|
[K in keyof Caches]: Caches[K][0] & {
|
|
32
32
|
name: K;
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
-
export
|
|
35
|
+
export type CacheFactory = (manager: CacheConstructors[keyof Caches], holds: Caches[typeof manager['name']][1]) => typeof manager['prototype'] extends DataManager<infer K, infer V, any> ? Collection<K, V> : never;
|
|
36
36
|
export interface CADActiveUnitFetchOptions {
|
|
37
37
|
id?: number | number[];
|
|
38
38
|
accId?: string | string[];
|
|
@@ -54,7 +54,7 @@ export declare enum CMSSubscriptionVersionEnum {
|
|
|
54
54
|
PRO = 4,
|
|
55
55
|
ONE = 6
|
|
56
56
|
}
|
|
57
|
-
export
|
|
57
|
+
export type Mutable<T> = {
|
|
58
58
|
-readonly [k in keyof T]: T[k];
|
|
59
59
|
};
|
|
60
60
|
export interface CMSVerifyWhitelistPromiseResult {
|
|
@@ -17,6 +17,7 @@ export declare class Instance extends EventEmitter {
|
|
|
17
17
|
cad: CADManager | undefined;
|
|
18
18
|
cms: CMSManager | undefined;
|
|
19
19
|
debug: boolean;
|
|
20
|
+
apiHeaders: HeadersInit;
|
|
20
21
|
constructor(options: InstanceTypes.InstanceOptions);
|
|
21
22
|
private initialize;
|
|
22
23
|
_debugLog(message: string): void;
|
|
@@ -42,9 +42,13 @@ class Instance extends events_1.default {
|
|
|
42
42
|
this.cmsDefaultServerId = 1;
|
|
43
43
|
this.isCMSSuccessful = false;
|
|
44
44
|
this.debug = false;
|
|
45
|
+
this.apiHeaders = {};
|
|
45
46
|
if (options.debug) {
|
|
46
47
|
this.debug = options.debug;
|
|
47
48
|
}
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(options, 'apiHeaders') && options.apiHeaders !== undefined) {
|
|
50
|
+
this.apiHeaders = options.apiHeaders;
|
|
51
|
+
}
|
|
48
52
|
if (Object.prototype.hasOwnProperty.call(options, 'apiKey') && Object.prototype.hasOwnProperty.call(options, 'communityId')) {
|
|
49
53
|
if (Object.prototype.hasOwnProperty.call(options, 'product')) {
|
|
50
54
|
switch (options.product) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as globalTypes from '../constants';
|
|
2
|
-
export
|
|
2
|
+
export type InstanceOptions = {
|
|
3
3
|
communityId?: string;
|
|
4
4
|
apiKey?: string;
|
|
5
5
|
product?: globalTypes.productEnums;
|
|
@@ -13,4 +13,5 @@ export declare type InstanceOptions = {
|
|
|
13
13
|
cmsApiUrl?: string;
|
|
14
14
|
cmsDefaultServerId?: number;
|
|
15
15
|
debug?: boolean;
|
|
16
|
+
apiHeaders?: HeadersInit;
|
|
16
17
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { EventEmitter } from 'events';
|
|
3
5
|
import { RequestData, RequestManager } from './RequestManager';
|
|
4
6
|
import { AllAPITypesType, RESTTypedAPIDataStructs } from './utils/constants';
|
|
@@ -84,7 +86,7 @@ export interface REST {
|
|
|
84
86
|
off: (<K extends keyof RestEvents>(event: K, listener: (...args: RestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof RestEvents>, listener: (...args: any[]) => void) => this);
|
|
85
87
|
removeAllListeners: (<K extends keyof RestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof RestEvents>) => this);
|
|
86
88
|
}
|
|
87
|
-
export
|
|
89
|
+
export type RestManagerTypes = CADManager | CMSManager;
|
|
88
90
|
export declare class REST extends EventEmitter {
|
|
89
91
|
readonly requestManager: RequestManager;
|
|
90
92
|
readonly instance: Instance;
|
|
@@ -12,15 +12,15 @@ class REST extends events_1.EventEmitter {
|
|
|
12
12
|
this.instance = _instance;
|
|
13
13
|
this.manager = _manager;
|
|
14
14
|
this.requestManager = new RequestManager_1.RequestManager(_instance, _product, options)
|
|
15
|
-
.on("restDebug" /* Debug */, this.emit.bind(this, "restDebug" /* Debug */))
|
|
16
|
-
.on("rateLimited" /* RateLimited */, this.emit.bind(this, "rateLimited" /* RateLimited */))
|
|
17
|
-
.on("invalidRequestWarning" /* InvalidRequestWarning */, this.emit.bind(this, "invalidRequestWarning" /* InvalidRequestWarning */));
|
|
15
|
+
.on("restDebug" /* RESTEvents.Debug */, this.emit.bind(this, "restDebug" /* RESTEvents.Debug */))
|
|
16
|
+
.on("rateLimited" /* RESTEvents.RateLimited */, this.emit.bind(this, "rateLimited" /* RESTEvents.RateLimited */))
|
|
17
|
+
.on("invalidRequestWarning" /* RESTEvents.InvalidRequestWarning */, this.emit.bind(this, "invalidRequestWarning" /* RESTEvents.InvalidRequestWarning */));
|
|
18
18
|
this.on('newListener', (name, listener) => {
|
|
19
|
-
if (name === "request" /* Request */ || name === "response" /* Response */)
|
|
19
|
+
if (name === "request" /* RESTEvents.Request */ || name === "response" /* RESTEvents.Response */)
|
|
20
20
|
this.requestManager.on(name, listener);
|
|
21
21
|
});
|
|
22
22
|
this.on('removeListener', (name, listener) => {
|
|
23
|
-
if (name === "request" /* Request */ || name === "response" /* Response */)
|
|
23
|
+
if (name === "request" /* RESTEvents.Request */ || name === "response" /* RESTEvents.Response */)
|
|
24
24
|
this.requestManager.off(name, listener);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import Collection from '@discordjs/collection';
|
|
2
|
+
import { Collection } from '@discordjs/collection';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import type { Instance } from '../../../../instance/Instance';
|
|
5
5
|
import { RESTOptions, RateLimitData, RestEvents } from './REST';
|
|
6
6
|
import { productEnums } from '../../../../constants';
|
|
7
7
|
import { IHandler } from './handlers/IHandler';
|
|
8
|
-
export
|
|
8
|
+
export type RouteLike = `/${string}`;
|
|
9
9
|
export declare const enum RequestMethod {
|
|
10
10
|
Delete = "delete",
|
|
11
11
|
Get = "get",
|
|
@@ -13,7 +13,7 @@ export declare const enum RequestMethod {
|
|
|
13
13
|
Post = "post",
|
|
14
14
|
Put = "put"
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export type ReqDataType = Array<unknown> | unknown;
|
|
17
17
|
export interface RequestData {
|
|
18
18
|
id: string;
|
|
19
19
|
key: string;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.RequestManager = void 0;
|
|
7
|
-
const collection_1 =
|
|
4
|
+
const collection_1 = require("@discordjs/collection");
|
|
8
5
|
// import { DiscordSnowflake } from '@sapphire/snowflake';
|
|
9
6
|
const events_1 = require("events");
|
|
10
7
|
const constants_1 = require("./utils/constants");
|
|
@@ -14,8 +11,8 @@ const utils_1 = require("../../../../utils/utils");
|
|
|
14
11
|
class RequestManager extends events_1.EventEmitter {
|
|
15
12
|
constructor(_instance, _product, options) {
|
|
16
13
|
super();
|
|
17
|
-
this.ratelimitedTypes = new collection_1.
|
|
18
|
-
this.handlers = new collection_1.
|
|
14
|
+
this.ratelimitedTypes = new collection_1.Collection();
|
|
15
|
+
this.handlers = new collection_1.Collection();
|
|
19
16
|
this.product = _product;
|
|
20
17
|
this.instance = _instance;
|
|
21
18
|
switch (_product) {
|
|
@@ -182,7 +179,8 @@ class RequestManager extends events_1.EventEmitter {
|
|
|
182
179
|
apiData.fetchOptions.body = JSON.stringify(apiData.data);
|
|
183
180
|
apiData.fetchOptions.headers = {
|
|
184
181
|
'Accept': 'application/json',
|
|
185
|
-
'Content-Type': 'application/json'
|
|
182
|
+
'Content-Type': 'application/json',
|
|
183
|
+
...instance.apiHeaders
|
|
186
184
|
};
|
|
187
185
|
return apiData;
|
|
188
186
|
}
|
|
@@ -33,7 +33,7 @@ export declare const GeneralCMSAPITypes: APITypeData[];
|
|
|
33
33
|
export declare const ServersCMSAPITypes: APITypeData[];
|
|
34
34
|
export declare const EventsCMSAPITypes: APITypeData[];
|
|
35
35
|
export declare const AllAPITypes: AllAPITypeData[];
|
|
36
|
-
export
|
|
36
|
+
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_DEPARTMENTS' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT' | 'FULL_WHITELIST' | 'GET_ACCOUNT_RANKS' | 'SET_ACCOUNT_RANKS' | 'RSVP';
|
|
37
37
|
export interface CMSServerAPIStruct {
|
|
38
38
|
id: number;
|
|
39
39
|
name: string;
|
|
@@ -428,7 +428,7 @@ export interface RESTTypedAPIDataStructs {
|
|
|
428
428
|
accId: string | undefined
|
|
429
429
|
];
|
|
430
430
|
}
|
|
431
|
-
export
|
|
431
|
+
export type PossibleRequestData = undefined | {
|
|
432
432
|
data: CADPenalCodeStruct[] | CADSetAPIIDStruct | CADNewEditRecordOptionOneStruct | CADNewEditRecordOptionTwoStruct | CADLookupByIntStruct | CADLookupStruct | CADModifyAccountPermsStruct | CADKickBanUserStruct | CADSetPostalStruct[] | CADModifyIdentifierStruct | CADAddBlipStruct[] | CADModifyBlipStruct[] | CADGetCallsStruct | CADGetActiveUnitsStruct | CADNewDispatchStruct;
|
|
433
433
|
} | {
|
|
434
434
|
servers: CADServerAPIStruct[];
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CacheManager = void 0;
|
|
7
|
-
const collection_1 =
|
|
4
|
+
const collection_1 = require("@discordjs/collection");
|
|
8
5
|
const DataManager_1 = require("./DataManager");
|
|
9
6
|
class CacheManager extends DataManager_1.DataManager {
|
|
10
7
|
constructor(instance, holds, iterable) {
|
|
11
8
|
super(instance, holds);
|
|
12
|
-
this._cache = new collection_1.
|
|
9
|
+
this._cache = new collection_1.Collection();
|
|
13
10
|
if (iterable) {
|
|
14
11
|
for (const item of iterable) {
|
|
15
12
|
this._add(item);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Instance } from '../instance/Instance';
|
|
2
2
|
import { BaseManager } from './BaseManager';
|
|
3
3
|
import { Constructable } from '../constants';
|
|
4
|
-
import Collection from '@discordjs/collection';
|
|
4
|
+
import { Collection } from '@discordjs/collection';
|
|
5
5
|
interface DataManagerInstanceObject {
|
|
6
6
|
id: string;
|
|
7
7
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.DataManager = void 0;
|
|
7
4
|
const BaseManager_1 = require("./BaseManager");
|
|
8
5
|
const errors_1 = require("../errors");
|
|
9
|
-
const collection_1 =
|
|
6
|
+
const collection_1 = require("@discordjs/collection");
|
|
10
7
|
class DataManager extends BaseManager_1.BaseManager {
|
|
11
8
|
constructor(instance, holds) {
|
|
12
9
|
super(instance);
|
|
@@ -34,7 +31,7 @@ class DataManager extends BaseManager_1.BaseManager {
|
|
|
34
31
|
*/
|
|
35
32
|
resolve(idOrInstance) {
|
|
36
33
|
var _a;
|
|
37
|
-
if (this.cache instanceof collection_1.
|
|
34
|
+
if (this.cache instanceof collection_1.Collection) {
|
|
38
35
|
if (typeof idOrInstance === 'object')
|
|
39
36
|
return idOrInstance;
|
|
40
37
|
if (typeof idOrInstance === 'string')
|
|
@@ -31,7 +31,7 @@ export interface CADActiveUnitDataStruct {
|
|
|
31
31
|
rank: string;
|
|
32
32
|
group: string;
|
|
33
33
|
}
|
|
34
|
-
export
|
|
34
|
+
export type CADActiveUnitResolvable = CADActiveUnit | number;
|
|
35
35
|
export declare class CADActiveUnit extends Base {
|
|
36
36
|
id: number;
|
|
37
37
|
accId: string;
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.debugLog = exports.errorLog = exports.infoLog = exports.warnLog = exports.flatten = exports.cloneObject = exports.mergeDefault = void 0;
|
|
7
|
-
const collection_1 =
|
|
4
|
+
const collection_1 = require("@discordjs/collection");
|
|
8
5
|
const isObject = (d) => typeof d === 'object' && d !== null;
|
|
9
6
|
function mergeDefault(def, given) {
|
|
10
7
|
if (!given)
|
|
@@ -46,10 +43,10 @@ function flatten(obj, ...props) {
|
|
|
46
43
|
const elemIsObj = isObject(element);
|
|
47
44
|
const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
|
|
48
45
|
// If it's a Collection, make the array of keys
|
|
49
|
-
if (element instanceof collection_1.
|
|
46
|
+
if (element instanceof collection_1.Collection)
|
|
50
47
|
out[newProp] = Array.from(element.keys());
|
|
51
48
|
// If the valueOf is a Collection, use its array of keys
|
|
52
|
-
else if (valueOf instanceof collection_1.
|
|
49
|
+
else if (valueOf instanceof collection_1.Collection)
|
|
53
50
|
out[newProp] = Array.from(valueOf.keys());
|
|
54
51
|
// If it's an array, flatten each element
|
|
55
52
|
else if (Array.isArray(element))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonoransoftware/sonoran.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
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
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"ext": "*.ts, *.json"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@discordjs/collection": "^
|
|
41
|
-
"@sapphire/async-queue": "^1.
|
|
40
|
+
"@discordjs/collection": "^1.5.0",
|
|
41
|
+
"@sapphire/async-queue": "^1.5.0",
|
|
42
42
|
"@sapphire/snowflake": "^3.2.0",
|
|
43
43
|
"events": "^3.3.0",
|
|
44
44
|
"node-abort-controller": "^3.0.1",
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Collection from '@discordjs/collection';
|
|
1
|
+
import { Collection } from '@discordjs/collection';
|
|
2
2
|
import { CADDispatchOriginEnums, CADDispatchStatusEnums } from './libs/rest/src';
|
|
3
3
|
import { DataManager } from './managers/DataManager';
|
|
4
4
|
import { CADActiveUnitsManager } from './managers/CADActiveUnitsManager';
|
package/src/instance/Instance.ts
CHANGED
|
@@ -1,118 +1,122 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
2
|
-
|
|
3
|
-
import * as globalTypes from '../constants';
|
|
4
|
-
import * as InstanceTypes from './instance.types';
|
|
5
|
-
import { CADManager } from '../managers/CADManager';
|
|
6
|
-
import { CMSManager } from '../managers/CMSManager';
|
|
7
|
-
import { debugLog } from '../utils';
|
|
8
|
-
|
|
9
|
-
export class Instance extends EventEmitter {
|
|
10
|
-
public cadCommunityId: string | undefined;
|
|
11
|
-
public cadApiKey: string | undefined;
|
|
12
|
-
public cadApiUrl: string = 'https://api.sonorancad.com';
|
|
13
|
-
public cadDefaultServerId: number = 1;
|
|
14
|
-
public isCADSuccessful: boolean = false;
|
|
15
|
-
public cmsCommunityId: string | undefined;
|
|
16
|
-
public cmsApiKey: string | undefined;
|
|
17
|
-
public cmsApiUrl: string = 'https://api.sonorancms.com';
|
|
18
|
-
public cmsDefaultServerId: number = 1;
|
|
19
|
-
public isCMSSuccessful: boolean = false;
|
|
20
|
-
|
|
21
|
-
public cad: CADManager | undefined;
|
|
22
|
-
public cms: CMSManager | undefined;
|
|
23
|
-
|
|
24
|
-
public debug: boolean = false;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
this._debugLog(`Overriding
|
|
43
|
-
this.
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
this._debugLog(`Overriding
|
|
58
|
-
this.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (options.
|
|
81
|
-
this._debugLog(`Overriding default
|
|
82
|
-
this.
|
|
83
|
-
}
|
|
84
|
-
if (
|
|
85
|
-
this._debugLog(`Overriding
|
|
86
|
-
this.
|
|
87
|
-
}
|
|
88
|
-
if (Object.prototype.hasOwnProperty.call(options, '
|
|
89
|
-
this._debugLog(`Overriding
|
|
90
|
-
this.
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
import * as globalTypes from '../constants';
|
|
4
|
+
import * as InstanceTypes from './instance.types';
|
|
5
|
+
import { CADManager } from '../managers/CADManager';
|
|
6
|
+
import { CMSManager } from '../managers/CMSManager';
|
|
7
|
+
import { debugLog } from '../utils';
|
|
8
|
+
|
|
9
|
+
export class Instance extends EventEmitter {
|
|
10
|
+
public cadCommunityId: string | undefined;
|
|
11
|
+
public cadApiKey: string | undefined;
|
|
12
|
+
public cadApiUrl: string = 'https://api.sonorancad.com';
|
|
13
|
+
public cadDefaultServerId: number = 1;
|
|
14
|
+
public isCADSuccessful: boolean = false;
|
|
15
|
+
public cmsCommunityId: string | undefined;
|
|
16
|
+
public cmsApiKey: string | undefined;
|
|
17
|
+
public cmsApiUrl: string = 'https://api.sonorancms.com';
|
|
18
|
+
public cmsDefaultServerId: number = 1;
|
|
19
|
+
public isCMSSuccessful: boolean = false;
|
|
20
|
+
|
|
21
|
+
public cad: CADManager | undefined;
|
|
22
|
+
public cms: CMSManager | undefined;
|
|
23
|
+
|
|
24
|
+
public debug: boolean = false;
|
|
25
|
+
public apiHeaders: HeadersInit = {};
|
|
26
|
+
|
|
27
|
+
constructor(options: InstanceTypes.InstanceOptions) {
|
|
28
|
+
super({ captureRejections: true });
|
|
29
|
+
if (options.debug) {
|
|
30
|
+
this.debug = options.debug;
|
|
31
|
+
}
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(options, 'apiHeaders') && options.apiHeaders !== undefined) {
|
|
33
|
+
this.apiHeaders = options.apiHeaders;
|
|
34
|
+
}
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(options, 'apiKey') && Object.prototype.hasOwnProperty.call(options, 'communityId')) {
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(options, 'product')) {
|
|
37
|
+
switch (options.product) {
|
|
38
|
+
case globalTypes.productEnums.CAD: {
|
|
39
|
+
this.cadCommunityId = options.communityId;
|
|
40
|
+
this.cadApiKey = options.apiKey;
|
|
41
|
+
if (options.serverId !== undefined) {
|
|
42
|
+
this._debugLog(`Overriding default server id... ${options.serverId}`);
|
|
43
|
+
this.cadDefaultServerId = options.serverId;
|
|
44
|
+
}
|
|
45
|
+
if (Object.prototype.hasOwnProperty.call(options, 'cadApiUrl') && typeof options.cadApiUrl === 'string') {
|
|
46
|
+
this._debugLog(`Overriding CAD API Url... ${options.cadApiUrl}`);
|
|
47
|
+
this.cadApiUrl = options.cadApiUrl;
|
|
48
|
+
}
|
|
49
|
+
this._debugLog('About to initialize instance.');
|
|
50
|
+
this.initialize();
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case globalTypes.productEnums.CMS: {
|
|
54
|
+
this.cmsCommunityId = options.communityId;
|
|
55
|
+
this.cmsApiKey = options.apiKey;
|
|
56
|
+
if (options.serverId !== undefined) {
|
|
57
|
+
this._debugLog(`Overriding default server id... ${options.serverId}`);
|
|
58
|
+
this.cmsDefaultServerId = options.serverId;
|
|
59
|
+
}
|
|
60
|
+
if (Object.prototype.hasOwnProperty.call(options, 'cmsApiUrl') && typeof options.cmsApiUrl === 'string') {
|
|
61
|
+
this._debugLog(`Overriding CMS API URL... ${options.cmsApiUrl}`);
|
|
62
|
+
this.cmsApiUrl = options.cmsApiUrl;
|
|
63
|
+
}
|
|
64
|
+
this.initialize();
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default: {
|
|
68
|
+
throw new Error('Invalid product enum given for constructor.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error('No product enum given when instancing.');
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
this.cadCommunityId = options.cadCommunityId;
|
|
76
|
+
this.cadApiKey = options.cadApiKey;
|
|
77
|
+
this.cmsCommunityId = options.cmsCommunityId;
|
|
78
|
+
this.cmsApiKey = options.cmsApiKey;
|
|
79
|
+
|
|
80
|
+
if (options.cadDefaultServerId !== undefined) {
|
|
81
|
+
this._debugLog(`Overriding default CAD server id... ${options.serverId}`);
|
|
82
|
+
this.cadDefaultServerId = options.cadDefaultServerId;
|
|
83
|
+
}
|
|
84
|
+
if (options.cmsDefaultServerId !== undefined) {
|
|
85
|
+
this._debugLog(`Overriding default CMS server id... ${options.serverId}`);
|
|
86
|
+
this.cmsDefaultServerId = options.cmsDefaultServerId;
|
|
87
|
+
}
|
|
88
|
+
if (Object.prototype.hasOwnProperty.call(options, 'cadApiUrl') && typeof options.cadApiUrl === 'string') {
|
|
89
|
+
this._debugLog(`Overriding CAD API Url... ${options.cadApiUrl}`);
|
|
90
|
+
this.cadApiUrl = options.cadApiUrl;
|
|
91
|
+
}
|
|
92
|
+
if (Object.prototype.hasOwnProperty.call(options, 'cmsApiUrl') && typeof options.cmsApiUrl === 'string') {
|
|
93
|
+
this._debugLog(`Overriding CMS API URL... ${options.cmsApiUrl}`);
|
|
94
|
+
this.cmsApiUrl = options.cmsApiUrl;
|
|
95
|
+
}
|
|
96
|
+
this.initialize();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
private initialize() {
|
|
103
|
+
if (this.cadCommunityId && this.cadApiKey && this.cadApiUrl) {
|
|
104
|
+
this._debugLog('About to initialize CAD Manager');
|
|
105
|
+
this.cad = new CADManager(this);
|
|
106
|
+
} else {
|
|
107
|
+
this._debugLog('Not initializing CAD Manager due to a missing community id, api key, or api url.');
|
|
108
|
+
}
|
|
109
|
+
if (this.cmsCommunityId && this.cmsApiKey && this.cmsApiUrl) {
|
|
110
|
+
this._debugLog('About to initialize CMS Manager');
|
|
111
|
+
this.cms = new CMSManager(this);
|
|
112
|
+
} else {
|
|
113
|
+
this._debugLog('Not initializing CMS Manager due to a missing community id, api key, or api url.');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public _debugLog(message: string): void {
|
|
118
|
+
if (this.debug) {
|
|
119
|
+
debugLog(message);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
118
122
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import * as globalTypes from '../constants';
|
|
2
|
-
|
|
3
|
-
export type InstanceOptions = {
|
|
4
|
-
communityId?: string;
|
|
5
|
-
apiKey?: string;
|
|
6
|
-
product?: globalTypes.productEnums;
|
|
7
|
-
serverId?: number;
|
|
8
|
-
cadCommunityId?: string;
|
|
9
|
-
cadApiKey?: string;
|
|
10
|
-
cadApiUrl?: string;
|
|
11
|
-
cadDefaultServerId?: number;
|
|
12
|
-
cmsCommunityId?: string;
|
|
13
|
-
cmsApiKey?: string;
|
|
14
|
-
cmsApiUrl?: string;
|
|
15
|
-
cmsDefaultServerId?: number;
|
|
16
|
-
debug?: boolean;
|
|
1
|
+
import * as globalTypes from '../constants';
|
|
2
|
+
|
|
3
|
+
export type InstanceOptions = {
|
|
4
|
+
communityId?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
product?: globalTypes.productEnums;
|
|
7
|
+
serverId?: number;
|
|
8
|
+
cadCommunityId?: string;
|
|
9
|
+
cadApiKey?: string;
|
|
10
|
+
cadApiUrl?: string;
|
|
11
|
+
cadDefaultServerId?: number;
|
|
12
|
+
cmsCommunityId?: string;
|
|
13
|
+
cmsApiKey?: string;
|
|
14
|
+
cmsApiUrl?: string;
|
|
15
|
+
cmsDefaultServerId?: number;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
apiHeaders?: HeadersInit ;
|
|
17
18
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Collection from '@discordjs/collection';
|
|
1
|
+
import { Collection } from '@discordjs/collection';
|
|
2
2
|
// import { DiscordSnowflake } from '@sapphire/snowflake';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
// import type { RequestInit, BodyInit } from 'node-fetch';
|
|
@@ -248,7 +248,8 @@ export class RequestManager extends EventEmitter {
|
|
|
248
248
|
apiData.fetchOptions.body = JSON.stringify(apiData.data);
|
|
249
249
|
apiData.fetchOptions.headers = {
|
|
250
250
|
'Accept': 'application/json',
|
|
251
|
-
'Content-Type': 'application/json'
|
|
251
|
+
'Content-Type': 'application/json',
|
|
252
|
+
...instance.apiHeaders
|
|
252
253
|
};
|
|
253
254
|
|
|
254
255
|
return apiData;
|
|
@@ -3,7 +3,7 @@ import { BaseManager } from './BaseManager';
|
|
|
3
3
|
import { GenericError } from '../errors';
|
|
4
4
|
import { Constructable } from '../constants';
|
|
5
5
|
|
|
6
|
-
import Collection from '@discordjs/collection';
|
|
6
|
+
import { Collection } from '@discordjs/collection';
|
|
7
7
|
|
|
8
8
|
interface DataManagerInstanceObject {
|
|
9
9
|
id: string;
|
|
@@ -39,7 +39,7 @@ export class DataManager<_K, Holds, _R> extends BaseManager {
|
|
|
39
39
|
* @param idOrInstance The id or instance of something in this Manager
|
|
40
40
|
* @returns {?Object} An instance from this Manager
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
public resolve(idOrInstance: string | object): object | null {
|
|
43
43
|
if (this.cache instanceof Collection) {
|
|
44
44
|
if (typeof idOrInstance === 'object') return idOrInstance;
|
|
45
45
|
if (typeof idOrInstance === 'string') return this.cache.get(idOrInstance) ?? null;
|
package/src/utils/utils.ts
CHANGED