@sonoransoftware/sonoran.js 1.0.1 → 1.0.2

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.
Files changed (45) hide show
  1. package/.github/workflows/npm-publish.yml +2 -2
  2. package/dist/builders/cad/DispatchCall.js +2 -2
  3. package/dist/instance/Instance.d.ts +2 -2
  4. package/dist/instance/Instance.js +4 -3
  5. package/dist/libs/rest/src/lib/REST.d.ts +2 -2
  6. package/dist/libs/rest/src/lib/REST.js +2 -2
  7. package/dist/libs/rest/src/lib/RequestManager.d.ts +2 -2
  8. package/dist/libs/rest/src/lib/RequestManager.js +9 -20
  9. package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +53 -65
  10. package/dist/libs/rest/src/lib/utils/constants.js +4 -1
  11. package/dist/managers/BaseManager.d.ts +1 -1
  12. package/dist/managers/CADActiveUnitsManager.d.ts +1 -1
  13. package/dist/managers/CADActiveUnitsManager.js +11 -22
  14. package/dist/managers/CADManager.d.ts +1 -1
  15. package/dist/managers/CADManager.js +25 -37
  16. package/dist/managers/CADServerManager.d.ts +1 -1
  17. package/dist/managers/CADServerManager.js +3 -12
  18. package/dist/managers/CMSManager.d.ts +1 -1
  19. package/dist/managers/CMSManager.js +74 -90
  20. package/dist/managers/CMSServerManager.d.ts +1 -1
  21. package/dist/managers/CMSServerManager.js +3 -12
  22. package/dist/managers/CacheManager.d.ts +1 -1
  23. package/dist/managers/DataManager.d.ts +1 -1
  24. package/dist/structures/Base.d.ts +1 -1
  25. package/dist/structures/CADActiveUnit.d.ts +1 -1
  26. package/dist/structures/CADServer.d.ts +1 -1
  27. package/dist/structures/CMSServer.d.ts +1 -1
  28. package/package.json +48 -46
  29. package/src/instance/Instance.ts +2 -2
  30. package/src/libs/rest/src/lib/REST.ts +2 -2
  31. package/src/libs/rest/src/lib/RequestManager.ts +2 -2
  32. package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +1 -0
  33. package/src/managers/BaseManager.ts +1 -1
  34. package/src/managers/CADActiveUnitsManager.ts +1 -1
  35. package/src/managers/CADManager.ts +2 -1
  36. package/src/managers/CADServerManager.ts +1 -1
  37. package/src/managers/CMSManager.ts +4 -1
  38. package/src/managers/CMSServerManager.ts +1 -1
  39. package/src/managers/CacheManager.ts +1 -1
  40. package/src/managers/DataManager.ts +1 -1
  41. package/src/structures/Base.ts +1 -1
  42. package/src/structures/CADActiveUnit.ts +1 -1
  43. package/src/structures/CADServer.ts +1 -1
  44. package/src/structures/CMSServer.ts +1 -1
  45. package/tsconfig.json +1 -1
@@ -15,7 +15,7 @@ jobs:
15
15
  - uses: actions/setup-node@v3
16
16
  with:
17
17
  node-version: 16
18
- - run: npm ci
18
+ - run: npm i
19
19
  - run: npm run build
20
20
 
21
21
  publish-npm:
@@ -27,7 +27,7 @@ jobs:
27
27
  with:
28
28
  node-version: 16
29
29
  registry-url: https://registry.npmjs.org/
30
- - run: npm ci
30
+ - run: npm i
31
31
  - run: npm run build
32
32
  - run: npm publish
33
33
  env:
@@ -10,7 +10,7 @@ class DispatchCallBuilder {
10
10
  * @param data Data Options (CADNewDispatchBuilderOptions) used to build the new dispatch call
11
11
  */
12
12
  constructor(data = {}) {
13
- this.data = Object.assign({}, data);
13
+ this.data = { ...data };
14
14
  }
15
15
  /**
16
16
  * Sets the origin for this dispatch call
@@ -138,7 +138,7 @@ class DispatchCallBuilder {
138
138
  * Transforms the dispatch call to a plain object
139
139
  */
140
140
  toJSON() {
141
- return Object.assign({}, this.data);
141
+ return { ...this.data };
142
142
  }
143
143
  }
144
144
  exports.DispatchCallBuilder = DispatchCallBuilder;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
- import EventEmitter from 'node:events';
2
+ import EventEmitter from 'events';
3
3
  import * as InstanceTypes from './instance.types';
4
4
  import { CADManager } from '../managers/CADManager';
5
5
  import { CMSManager } from '../managers/CMSManager';
6
- export default class Instance extends EventEmitter {
6
+ export declare class Instance extends EventEmitter {
7
7
  cadCommunityId: string | undefined;
8
8
  cadApiKey: string | undefined;
9
9
  cadApiUrl: string;
@@ -26,12 +26,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const node_events_1 = __importDefault(require("node:events"));
29
+ exports.Instance = void 0;
30
+ const events_1 = __importDefault(require("events"));
30
31
  const globalTypes = __importStar(require("../constants"));
31
32
  const CADManager_1 = require("../managers/CADManager");
32
33
  const CMSManager_1 = require("../managers/CMSManager");
33
34
  const utils_1 = require("../utils");
34
- class Instance extends node_events_1.default {
35
+ class Instance extends events_1.default {
35
36
  constructor(options) {
36
37
  super({ captureRejections: true });
37
38
  this.cadApiUrl = 'https://api.sonorancad.com';
@@ -131,4 +132,4 @@ class Instance extends node_events_1.default {
131
132
  }
132
133
  }
133
134
  }
134
- exports.default = Instance;
135
+ exports.Instance = Instance;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from 'node:events';
2
+ import { EventEmitter } from 'events';
3
3
  import { RequestData, RequestManager } from './RequestManager';
4
4
  import { AllAPITypesType, RESTTypedAPIDataStructs } from './utils/constants';
5
5
  import { productEnums } from '../../../../constants';
6
6
  import type { AgentOptions } from 'node:https';
7
7
  import type { RequestInit, Response } from 'node-fetch';
8
- import Instance from '../../../../instance/Instance';
8
+ import { Instance } from '../../../../instance/Instance';
9
9
  import { CADManager } from '../../../../managers/CADManager';
10
10
  import { CMSManager } from '../../../../managers/CMSManager';
11
11
  /**
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.REST = void 0;
4
- const node_events_1 = require("node:events");
4
+ const events_1 = require("events");
5
5
  const RequestManager_1 = require("./RequestManager");
6
6
  const constants_1 = require("./utils/constants");
7
7
  const constants_2 = require("../../../../constants");
8
8
  const Utils_1 = require("./utils/Utils");
9
- class REST extends node_events_1.EventEmitter {
9
+ class REST extends events_1.EventEmitter {
10
10
  constructor(_instance, _manager, _product, options) {
11
11
  super();
12
12
  this.instance = _instance;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import Collection from '@discordjs/collection';
3
- import { EventEmitter } from 'node:events';
4
- import type Instance from '../../../../instance/Instance';
3
+ import { EventEmitter } from 'events';
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';
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -15,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.RequestManager = void 0;
16
7
  const collection_1 = __importDefault(require("@discordjs/collection"));
17
8
  // import { DiscordSnowflake } from '@sapphire/snowflake';
18
- const node_events_1 = require("node:events");
9
+ const events_1 = require("events");
19
10
  const constants_1 = require("./utils/constants");
20
11
  const constants_2 = require("../../../../constants");
21
12
  const SequentialHandler_1 = require("./handlers/SequentialHandler");
22
13
  const utils_1 = require("../../../../utils/utils");
23
- class RequestManager extends node_events_1.EventEmitter {
14
+ class RequestManager extends events_1.EventEmitter {
24
15
  constructor(_instance, _product, options) {
25
16
  super();
26
17
  this.ratelimitedTypes = new collection_1.default();
@@ -29,11 +20,11 @@ class RequestManager extends node_events_1.EventEmitter {
29
20
  this.instance = _instance;
30
21
  switch (_product) {
31
22
  case constants_2.productEnums.CAD: {
32
- this.options = Object.assign(Object.assign({}, constants_1.DefaultCADRestOptions), options);
23
+ this.options = { ...constants_1.DefaultCADRestOptions, ...options };
33
24
  break;
34
25
  }
35
26
  case constants_2.productEnums.CMS: {
36
- this.options = Object.assign(Object.assign({}, constants_1.DefaultCMSRestOptions), options);
27
+ this.options = { ...constants_1.DefaultCMSRestOptions, ...options };
37
28
  break;
38
29
  }
39
30
  default: {
@@ -41,14 +32,12 @@ class RequestManager extends node_events_1.EventEmitter {
41
32
  }
42
33
  }
43
34
  }
44
- queueRequest(request) {
35
+ async queueRequest(request) {
45
36
  var _a;
46
- return __awaiter(this, void 0, void 0, function* () {
47
- let requestData = request;
48
- const resolvedData = RequestManager.resolveRequestData(this.instance, request.type, request.product, requestData);
49
- const handler = (_a = this.handlers.get(`${resolvedData.typePath}:${String(request.product)}`)) !== null && _a !== void 0 ? _a : this.createHandler(resolvedData);
50
- return handler.queueRequest(resolvedData.fullUrl, resolvedData.fetchOptions, resolvedData);
51
- });
37
+ let requestData = request;
38
+ const resolvedData = RequestManager.resolveRequestData(this.instance, request.type, request.product, requestData);
39
+ const handler = (_a = this.handlers.get(`${resolvedData.typePath}:${String(request.product)}`)) !== null && _a !== void 0 ? _a : this.createHandler(resolvedData);
40
+ return handler.queueRequest(resolvedData.fullUrl, resolvedData.fetchOptions, resolvedData);
52
41
  }
53
42
  onRateLimit(id, rateLimitData) {
54
43
  this.ratelimitedTypes.set(id, rateLimitData);
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -22,6 +13,7 @@ exports.SequentialHandler = void 0;
22
13
  // import { setTimeout as sleep } from 'node:timers/promises';
23
14
  const async_queue_1 = require("@sapphire/async-queue");
24
15
  const node_fetch_1 = __importDefault(require("node-fetch"));
16
+ const node_abort_controller_1 = require("node-abort-controller");
25
17
  // import { DiscordAPIError, DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError';
26
18
  const errors_1 = require("../errors");
27
19
  const HTTPError_1 = require("../errors/HTTPError");
@@ -77,20 +69,18 @@ class SequentialHandler {
77
69
  * @param options All the information needed to make a request
78
70
  * @param requestData Extra data from the user's request needed for errors and additional processing
79
71
  */
80
- queueRequest(url, options, data) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- let queue = __classPrivateFieldGet(this, _SequentialHandler_asyncQueue, "f");
83
- // Wait for any previous requests to be completed before this one is run
84
- yield queue.wait();
85
- try {
86
- // Make the request, and return the results
87
- return yield this.runRequest(url, options, data);
88
- }
89
- finally {
90
- // Allow the next request to fire
91
- queue.shift();
92
- }
93
- });
72
+ async queueRequest(url, options, data) {
73
+ let queue = __classPrivateFieldGet(this, _SequentialHandler_asyncQueue, "f");
74
+ // Wait for any previous requests to be completed before this one is run
75
+ await queue.wait();
76
+ try {
77
+ // Make the request, and return the results
78
+ return await this.runRequest(url, options, data);
79
+ }
80
+ finally {
81
+ // Allow the next request to fire
82
+ queue.shift();
83
+ }
94
84
  }
95
85
  /**
96
86
  * The method that actually makes the request to the api, and updates info about the bucket accordingly
@@ -100,48 +90,46 @@ class SequentialHandler {
100
90
  * @param requestData Extra data from the user's request needed for errors and additional processing
101
91
  * @param retries The number of retries this request has already attempted (recursion)
102
92
  */
103
- runRequest(url, options, data) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const controller = new AbortController();
106
- const timeout = setTimeout(() => controller.abort(), 30000).unref();
107
- let res;
108
- try {
109
- // node-fetch typings are a bit weird, so we have to cast to any to get the correct signature
110
- // Type 'AbortSignal' is not assignable to type 'import('discord.js-modules/node_modules/@types/node-fetch/externals').AbortSignal'
111
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
112
- res = yield (0, node_fetch_1.default)(url, Object.assign(Object.assign({}, options), { signal: controller.signal }));
113
- }
114
- catch (error) {
115
- throw error;
116
- }
117
- finally {
118
- clearTimeout(timeout);
119
- }
120
- if (res.ok) {
121
- const parsedRes = yield SequentialHandler.parseResponse(res);
122
- return parsedRes;
123
- }
124
- else if (res.status === 400 || res.status === 401 || res.status === 404) {
125
- const parsedRes = yield SequentialHandler.parseResponse(res);
126
- // throw new HTTPError(String(parsedRes), res.constructor.name, res.status, data.method, url);
127
- throw new errors_1.APIError(parsedRes, data.type, data.fullUrl, res.status, data);
128
- }
129
- else if (res.status === 429) {
130
- const timeout = setTimeout(() => {
131
- this.manager.removeRateLimit(data.requestTypeId);
132
- }, 60 * 1000);
133
- const ratelimitData = {
134
- product: data.product,
135
- type: data.type,
136
- timeTill: timeout
137
- };
138
- this.manager.onRateLimit(data.requestTypeId, ratelimitData);
139
- }
140
- else if (res.status >= 500 && res.status < 600) {
141
- throw new HTTPError_1.HTTPError(res.statusText, res.constructor.name, res.status, data.method, url);
142
- }
143
- return null;
144
- });
93
+ async runRequest(url, options, data) {
94
+ const controller = new node_abort_controller_1.AbortController();
95
+ const timeout = setTimeout(() => controller.abort(), 30000).unref();
96
+ let res;
97
+ try {
98
+ // node-fetch typings are a bit weird, so we have to cast to any to get the correct signature
99
+ // Type 'AbortSignal' is not assignable to type 'import('discord.js-modules/node_modules/@types/node-fetch/externals').AbortSignal'
100
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
101
+ res = await (0, node_fetch_1.default)(url, { ...options, signal: controller.signal });
102
+ }
103
+ catch (error) {
104
+ throw error;
105
+ }
106
+ finally {
107
+ clearTimeout(timeout);
108
+ }
109
+ if (res.ok) {
110
+ const parsedRes = await SequentialHandler.parseResponse(res);
111
+ return parsedRes;
112
+ }
113
+ else if (res.status === 400 || res.status === 401 || res.status === 404) {
114
+ const parsedRes = await SequentialHandler.parseResponse(res);
115
+ // throw new HTTPError(String(parsedRes), res.constructor.name, res.status, data.method, url);
116
+ throw new errors_1.APIError(parsedRes, data.type, data.fullUrl, res.status, data);
117
+ }
118
+ else if (res.status === 429) {
119
+ const timeout = setTimeout(() => {
120
+ this.manager.removeRateLimit(data.requestTypeId);
121
+ }, 60 * 1000);
122
+ const ratelimitData = {
123
+ product: data.product,
124
+ type: data.type,
125
+ timeTill: timeout
126
+ };
127
+ this.manager.onRateLimit(data.requestTypeId, ratelimitData);
128
+ }
129
+ else if (res.status >= 500 && res.status < 600) {
130
+ throw new HTTPError_1.HTTPError(res.statusText, res.constructor.name, res.status, data.method, url);
131
+ }
132
+ return null;
145
133
  }
146
134
  static parseResponse(res) {
147
135
  var _a;
@@ -351,7 +351,10 @@ exports.ServersCMSAPITypes = [
351
351
  ];
352
352
  function formatForAll(array, product) {
353
353
  return array.map((val) => {
354
- return Object.assign(Object.assign({}, val), { product });
354
+ return {
355
+ ...val,
356
+ product
357
+ };
355
358
  });
356
359
  }
357
360
  exports.AllAPITypes = [...formatForAll(exports.GeneralCADAPITypes, constants_1.productEnums.CAD), ...formatForAll(exports.CivilianCADAPITypes, constants_1.productEnums.CAD), ...formatForAll(exports.EmergencyCADAPITypes, constants_1.productEnums.CAD), ...formatForAll(exports.GeneralCMSAPITypes, constants_1.productEnums.CMS), ...formatForAll(exports.ServersCMSAPITypes, constants_1.productEnums.CMS)];
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  /**
3
3
  * Manages the API methods of a data model or a specific product methods.
4
4
  * @abstract
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { CADActiveUnit, CADActiveUnitResolvable, CADActiveUnitStruct } from '../structures/CADActiveUnit';
3
3
  import { CacheManager } from './CacheManager';
4
4
  export declare class CADActiveUnitsManager extends CacheManager<number, CADActiveUnit, CADActiveUnitResolvable> {
@@ -1,14 +1,5 @@
1
1
  "use strict";
2
2
  // Work in progress still...
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
3
  Object.defineProperty(exports, "__esModule", { value: true });
13
4
  exports.CADActiveUnitsManager = void 0;
14
5
  const CADActiveUnit_1 = require("../structures/CADActiveUnit");
@@ -30,20 +21,18 @@ class CADActiveUnitsManager extends CacheManager_1.CacheManager {
30
21
  force: false
31
22
  });
32
23
  }
33
- _fetchSingle({ unit, includeOffline = false, force = false }) {
24
+ async _fetchSingle({ unit, includeOffline = false, force = false }) {
34
25
  var _a, _b;
35
- return __awaiter(this, void 0, void 0, function* () {
36
- if (!force) {
37
- const existing = this.cache.get(unit);
38
- if (existing)
39
- return existing;
40
- }
41
- const data = yield ((_b = (_a = this.instance.cad) === null || _a === void 0 ? void 0 : _a.rest) === null || _b === void 0 ? void 0 : _b.request('GET_ACTIVE_UNITS', {
42
- serverId: this.serverId,
43
- includeOffline
44
- }));
45
- console.log(data);
46
- });
26
+ if (!force) {
27
+ const existing = this.cache.get(unit);
28
+ if (existing)
29
+ return existing;
30
+ }
31
+ const data = await ((_b = (_a = this.instance.cad) === null || _a === void 0 ? void 0 : _a.rest) === null || _b === void 0 ? void 0 : _b.request('GET_ACTIVE_UNITS', {
32
+ serverId: this.serverId,
33
+ includeOffline
34
+ }));
35
+ console.log(data);
47
36
  }
48
37
  }
49
38
  exports.CADActiveUnitsManager = CADActiveUnitsManager;
@@ -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 { REST } from '../libs/rest/src';
4
4
  import { BaseManager } from './BaseManager';
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.CADManager = void 0;
36
27
  const src_1 = require("../libs/rest/src");
@@ -47,21 +38,20 @@ class CADManager extends BaseManager_1.BaseManager {
47
38
  this.rest = new src_1.REST(instance, this, globalTypes.productEnums.CAD, src_1.DefaultCADRestOptions);
48
39
  this.buildManager(instance);
49
40
  }
50
- buildManager(instance) {
41
+ async buildManager(instance) {
51
42
  var _a;
52
- return __awaiter(this, void 0, void 0, function* () {
53
- try {
54
- const versionResp = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_VERSION'));
55
- const mutableThis = this;
56
- mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
57
- if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
58
- this.servers = new CADServerManager_1.CADServerManager(instance, this);
59
- }
60
- }
61
- catch (err) {
62
- console.log(err);
43
+ try {
44
+ const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_VERSION'));
45
+ const mutableThis = this;
46
+ mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
47
+ if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
48
+ this.servers = new CADServerManager_1.CADServerManager(instance, this);
63
49
  }
64
- });
50
+ instance.isCADSuccessful = true;
51
+ }
52
+ catch (err) {
53
+ console.log(err);
54
+ }
65
55
  }
66
56
  /**
67
57
  * Gets a community account by `accId` or `apiId`.
@@ -70,23 +60,21 @@ class CADManager extends BaseManager_1.BaseManager {
70
60
  * @param {string} [data.apiId] The api id to find a community account.
71
61
  * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
72
62
  */
73
- getAccount(params) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
76
- var _a;
77
- try {
78
- const getAccountRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT', params.apiId, params.username));
79
- resolve({ success: true, data: getAccountRequest });
63
+ async getAccount(params) {
64
+ return new Promise(async (resolve, reject) => {
65
+ var _a;
66
+ try {
67
+ const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT', params.apiId, params.username));
68
+ resolve({ success: true, data: getAccountRequest });
69
+ }
70
+ catch (err) {
71
+ if (err instanceof src_1.APIError) {
72
+ resolve({ success: false, reason: err.response });
80
73
  }
81
- catch (err) {
82
- if (err instanceof src_1.APIError) {
83
- resolve({ success: false, reason: err.response });
84
- }
85
- else {
86
- reject(err);
87
- }
74
+ else {
75
+ reject(err);
88
76
  }
89
- }));
77
+ }
90
78
  });
91
79
  }
92
80
  }
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { CADServerAPIStruct } from '../libs/rest/src';
3
3
  import { CADServer } from '../structures/CADServer';
4
4
  import { CacheManager } from './CacheManager';
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CADServerManager = void 0;
13
4
  const CADServer_1 = require("../structures/CADServer");
@@ -15,10 +6,10 @@ const CacheManager_1 = require("./CacheManager");
15
6
  class CADServerManager extends CacheManager_1.CacheManager {
16
7
  constructor(instance, manager) {
17
8
  super(instance, CADServer_1.CADServer, []);
18
- (() => __awaiter(this, void 0, void 0, function* () {
9
+ (async () => {
19
10
  var _a;
20
11
  try {
21
- const serversRes = yield ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SERVERS'));
12
+ const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SERVERS'));
22
13
  const servers = JSON.parse(serversRes).servers;
23
14
  servers.forEach((server) => {
24
15
  const serverStruct = {
@@ -31,7 +22,7 @@ class CADServerManager extends CacheManager_1.CacheManager {
31
22
  catch (err) {
32
23
  throw new Error(String(err));
33
24
  }
34
- }))();
25
+ })();
35
26
  }
36
27
  }
37
28
  exports.CADServerManager = CADServerManager;
@@ -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 { REST } from '../libs/rest/src';
4
4
  import { BaseManager } from './BaseManager';
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.CMSManager = void 0;
36
27
  const src_1 = require("../libs/rest/src");
@@ -48,22 +39,23 @@ class CMSManager extends BaseManager_1.BaseManager {
48
39
  this.rest = new src_1.REST(instance, this, globalTypes.productEnums.CMS, src_1.DefaultCMSRestOptions);
49
40
  this.buildManager(instance);
50
41
  }
51
- buildManager(instance) {
42
+ async buildManager(instance) {
52
43
  var _a;
53
- return __awaiter(this, void 0, void 0, function* () {
54
- try {
55
- const versionResp = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SUB_VERSION'));
56
- const mutableThis = this;
57
- mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
58
- if (this.version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
59
- this.servers = new CMSServerManager_1.CMSServerManager(instance, this);
60
- }
61
- mutableThis.ready = true;
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);
62
50
  }
63
- catch (err) {
64
- throw err;
65
- }
66
- });
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
+ }
67
59
  }
68
60
  /**
69
61
  * Verifies the whitelist of a given account with the given parameters to search of said account.
@@ -73,29 +65,27 @@ class CMSManager extends BaseManager_1.BaseManager {
73
65
  * @param {string} [data.serverId] The username to find a community account.
74
66
  * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
75
67
  */
76
- verifyWhitelist(data) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
79
- var _a, _b;
80
- try {
81
- const isString = typeof data === 'string';
82
- const whitelistRequest = yield ((_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));
83
- if (typeof whitelistRequest === 'string') {
84
- resolve({ success: true, reason: whitelistRequest });
85
- }
86
- else {
87
- resolve({ success: false, reason: whitelistRequest });
88
- }
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 });
89
84
  }
90
- catch (err) {
91
- if (err instanceof src_1.APIError) {
92
- resolve({ success: false, reason: err.response });
93
- }
94
- else {
95
- reject(err);
96
- }
85
+ else {
86
+ reject(err);
97
87
  }
98
- }));
88
+ }
99
89
  });
100
90
  }
101
91
  /**
@@ -106,23 +96,21 @@ class CMSManager extends BaseManager_1.BaseManager {
106
96
  * @param {string} [data.username] The username to find a community account.
107
97
  * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
108
98
  */
109
- getComAccount(params) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
112
- var _a;
113
- try {
114
- const getAccountRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId));
115
- resolve({ success: true, data: getAccountRequest });
99
+ async getComAccount(params) {
100
+ return new Promise(async (resolve, reject) => {
101
+ var _a;
102
+ try {
103
+ const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId));
104
+ resolve({ success: true, data: getAccountRequest });
105
+ }
106
+ catch (err) {
107
+ if (err instanceof src_1.APIError) {
108
+ resolve({ success: false, reason: err.response });
116
109
  }
117
- catch (err) {
118
- if (err instanceof src_1.APIError) {
119
- resolve({ success: false, reason: err.response });
120
- }
121
- else {
122
- reject(err);
123
- }
110
+ else {
111
+ reject(err);
124
112
  }
125
- }));
113
+ }
126
114
  });
127
115
  }
128
116
  /**
@@ -133,24 +121,22 @@ class CMSManager extends BaseManager_1.BaseManager {
133
121
  * @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
134
122
  * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
135
123
  */
136
- clockInOut(data) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
139
- var _a;
140
- try {
141
- const clockInOutRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
142
- const clockInOutRequestString = clockInOutRequest;
143
- resolve({ success: true, clockedIn: clockInOutRequestString.includes('CLOCKED IN') });
124
+ async clockInOut(data) {
125
+ return new Promise(async (resolve, reject) => {
126
+ var _a;
127
+ try {
128
+ const clockInOutRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
129
+ const clockInOutRequestString = clockInOutRequest;
130
+ resolve({ success: true, clockedIn: clockInOutRequestString.includes('CLOCKED IN') });
131
+ }
132
+ catch (err) {
133
+ if (err instanceof src_1.APIError) {
134
+ resolve({ success: false, reason: err.response });
144
135
  }
145
- catch (err) {
146
- if (err instanceof src_1.APIError) {
147
- resolve({ success: false, reason: err.response });
148
- }
149
- else {
150
- reject(err);
151
- }
136
+ else {
137
+ reject(err);
152
138
  }
153
- }));
139
+ }
154
140
  });
155
141
  }
156
142
  /**
@@ -158,23 +144,21 @@ class CMSManager extends BaseManager_1.BaseManager {
158
144
  * @param {string} apiId The api id to check for an account.
159
145
  * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
160
146
  */
161
- checkComApiId(apiId) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
164
- var _a;
165
- try {
166
- const checkComApiIdRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CHECK_COM_APIID', apiId));
167
- resolve({ success: true, username: checkComApiIdRequest });
147
+ async checkComApiId(apiId) {
148
+ return new Promise(async (resolve, reject) => {
149
+ var _a;
150
+ try {
151
+ const checkComApiIdRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CHECK_COM_APIID', apiId));
152
+ resolve({ success: true, username: checkComApiIdRequest });
153
+ }
154
+ catch (err) {
155
+ if (err instanceof src_1.APIError) {
156
+ resolve({ success: false, reason: err.response });
168
157
  }
169
- catch (err) {
170
- if (err instanceof src_1.APIError) {
171
- resolve({ success: false, reason: err.response });
172
- }
173
- else {
174
- reject(err);
175
- }
158
+ else {
159
+ reject(err);
176
160
  }
177
- }));
161
+ }
178
162
  });
179
163
  }
180
164
  }
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { CMSServerAPIStruct } from '../libs/rest/src';
3
3
  import { CMSServer } from '../structures/CMSServer';
4
4
  import { CacheManager } from './CacheManager';
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CMSServerManager = void 0;
13
4
  const CMSServer_1 = require("../structures/CMSServer");
@@ -15,10 +6,10 @@ const CacheManager_1 = require("./CacheManager");
15
6
  class CMSServerManager extends CacheManager_1.CacheManager {
16
7
  constructor(instance, manager) {
17
8
  super(instance, CMSServer_1.CMSServer, []);
18
- (() => __awaiter(this, void 0, void 0, function* () {
9
+ (async () => {
19
10
  var _a;
20
11
  try {
21
- const serversRes = yield ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
12
+ const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
22
13
  const servers = serversRes.servers;
23
14
  servers.forEach((server) => {
24
15
  const serverStruct = {
@@ -31,7 +22,7 @@ class CMSServerManager extends CacheManager_1.CacheManager {
31
22
  catch (err) {
32
23
  throw new Error(String(err));
33
24
  }
34
- }))();
25
+ })();
35
26
  }
36
27
  }
37
28
  exports.CMSServerManager = CMSServerManager;
@@ -1,5 +1,5 @@
1
1
  import Collection from '@discordjs/collection';
2
- import Instance from '../instance/Instance';
2
+ import { Instance } from '../instance/Instance';
3
3
  import { Constructable } from '../constants';
4
4
  import { DataManager } from './DataManager';
5
5
  export declare class CacheManager<K, Holds, R> extends DataManager<K, Holds, R> {
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { BaseManager } from './BaseManager';
3
3
  import { Constructable } from '../constants';
4
4
  import Collection from '@discordjs/collection';
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  export declare abstract class Base {
3
3
  instance: Instance;
4
4
  constructor(instance: Instance);
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { Base } from './Base';
3
3
  export interface CADActiveUnitStruct {
4
4
  id: number;
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { Base } from './Base';
3
3
  export interface CADServerData {
4
4
  id: number;
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { Base } from './Base';
3
3
  export interface CMSServerData {
4
4
  id: number;
package/package.json CHANGED
@@ -1,46 +1,48 @@
1
- {
2
- "name": "@sonoransoftware/sonoran.js",
3
- "version": "1.0.1",
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
- "node-fetch": "^2.6.5"
44
- },
45
- "prepublish": "npm run build"
46
- }
1
+ {
2
+ "name": "@sonoransoftware/sonoran.js",
3
+ "version": "1.0.2",
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
+ }
@@ -1,4 +1,4 @@
1
- import EventEmitter from 'node:events';
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 default class Instance extends EventEmitter {
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 'node:events';
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';
@@ -1,9 +1,9 @@
1
1
  import Collection from '@discordjs/collection';
2
2
  // import { DiscordSnowflake } from '@sapphire/snowflake';
3
- import { EventEmitter } from 'node:events';
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';
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
 
3
3
  /**
4
4
  * Manages the API methods of a data model or a specific product methods.
@@ -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 { CADServerAPIStruct } from '../libs/rest/src';
3
3
  import { CADServer } from '../structures/CADServer';
4
4
  import { CacheManager } from './CacheManager';
@@ -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
  }
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { CMSServerAPIStruct } from '../libs/rest/src';
3
3
  import { CMSServer } from '../structures/CMSServer';
4
4
  import { CacheManager } from './CacheManager';
@@ -1,5 +1,5 @@
1
1
  import Collection from '@discordjs/collection';
2
- import Instance from '../instance/Instance';
2
+ import { Instance } from '../instance/Instance';
3
3
  import { Constructable } from '../constants';
4
4
  import { DataManager } from './DataManager';
5
5
 
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { BaseManager } from './BaseManager';
3
3
  import { GenericError } from '../errors';
4
4
  import { Constructable } from '../constants';
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { flatten } from '../utils';
3
3
 
4
4
  export abstract class Base {
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { Base } from './Base';
3
3
 
4
4
  export interface CADActiveUnitStruct {
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  // import { CADActiveUnitsManager } from '../managers/CADActiveUnitsManager';
3
3
  import { Base } from './Base';
4
4
 
@@ -1,4 +1,4 @@
1
- import Instance from '../instance/Instance';
1
+ import { Instance } from '../instance/Instance';
2
2
  import { Base } from './Base';
3
3
 
4
4
  export interface CMSServerData {
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  /* Basic Options */
6
6
  // "incremental": true, /* Enable incremental compilation */
7
- "target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
7
+ "target": "ES2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
8
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. */