@sonoransoftware/sonoran.js 1.0.13 → 1.0.15

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.
@@ -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 declare type Constructable<T> = abstract new (...args: any[]) => T;
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 declare type CacheConstructors = {
30
+ export type CacheConstructors = {
31
31
  [K in keyof Caches]: Caches[K][0] & {
32
32
  name: K;
33
33
  };
34
34
  };
35
- export declare 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;
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 declare type Mutable<T> = {
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 declare type InstanceOptions = {
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 declare type RestManagerTypes = CADManager | CMSManager;
89
+ export type RestManagerTypes = CADManager | CMSManager;
88
90
  export declare class REST extends EventEmitter {
89
91
  readonly requestManager: RequestManager;
90
92
  readonly instance: Instance;
@@ -5,22 +5,22 @@ 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
- const Utils_1 = require("./utils/Utils");
8
+ const utils_1 = require("./utils/utils");
9
9
  class REST extends events_1.EventEmitter {
10
10
  constructor(_instance, _manager, _product, options) {
11
11
  super();
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
  }
@@ -49,7 +49,7 @@ class REST extends events_1.EventEmitter {
49
49
  if (!communityId || !apiKey)
50
50
  throw new Error(`Community ID or API Key could not be found for request. P${apiType.product}`);
51
51
  if (apiType.minVersion > this.manager.version)
52
- throw new Error(`[${type}] Subscription version too low for this API type request. Current Version: ${(0, Utils_1.convertSubNumToName)(this.manager.version)} Needed Version: ${(0, Utils_1.convertSubNumToName)(apiType.minVersion)}`);
52
+ throw new Error(`[${type}] Subscription version too low for this API type request. Current Version: ${(0, utils_1.convertSubNumToName)(this.manager.version)} Needed Version: ${(0, utils_1.convertSubNumToName)(apiType.minVersion)}`);
53
53
  const formattedData = this.formatDataArguments(apiType.type, args);
54
54
  const options = {
55
55
  id: communityId,
@@ -74,6 +74,13 @@ class REST extends events_1.EventEmitter {
74
74
  serverId: args[0]
75
75
  };
76
76
  }
77
+ case 'RSVP': {
78
+ return {
79
+ eventId: args[0],
80
+ apiId: args[1],
81
+ accId: args[2],
82
+ };
83
+ }
77
84
  case 'GET_COM_ACCOUNT': {
78
85
  return {
79
86
  apiId: args[0],
@@ -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 declare type RouteLike = `/${string}`;
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 declare type ReqDataType = Array<unknown> | unknown;
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 = __importDefault(require("@discordjs/collection"));
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.default();
18
- this.handlers = new collection_1.default();
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
  }
@@ -31,8 +31,9 @@ export declare const CivilianCADAPITypes: APITypeData[];
31
31
  export declare const EmergencyCADAPITypes: APITypeData[];
32
32
  export declare const GeneralCMSAPITypes: APITypeData[];
33
33
  export declare const ServersCMSAPITypes: APITypeData[];
34
+ export declare const EventsCMSAPITypes: APITypeData[];
34
35
  export declare const AllAPITypes: AllAPITypeData[];
35
- export declare 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';
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';
36
37
  export interface CMSServerAPIStruct {
37
38
  id: number;
38
39
  name: string;
@@ -421,8 +422,13 @@ export interface RESTTypedAPIDataStructs {
421
422
  FULL_WHITELIST: [
422
423
  serverId?: number
423
424
  ];
425
+ RSVP: [
426
+ eventId: string,
427
+ apiId: string | undefined,
428
+ accId: string | undefined
429
+ ];
424
430
  }
425
- export declare type PossibleRequestData = undefined | {
431
+ export type PossibleRequestData = undefined | {
426
432
  data: CADPenalCodeStruct[] | CADSetAPIIDStruct | CADNewEditRecordOptionOneStruct | CADNewEditRecordOptionTwoStruct | CADLookupByIntStruct | CADLookupStruct | CADModifyAccountPermsStruct | CADKickBanUserStruct | CADSetPostalStruct[] | CADModifyIdentifierStruct | CADAddBlipStruct[] | CADModifyBlipStruct[] | CADGetCallsStruct | CADGetActiveUnitsStruct | CADNewDispatchStruct;
427
433
  } | {
428
434
  servers: CADServerAPIStruct[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CADDispatchStatusEnums = exports.CADDispatchOriginEnums = exports.CADModifyIdentifierActionEnums = exports.CADLookupByIntSearchTypeEnums = exports.CADRecordSectionCategoryEnums = exports.CADRecordTypeEnums = exports.AllAPITypes = exports.ServersCMSAPITypes = exports.GeneralCMSAPITypes = exports.EmergencyCADAPITypes = exports.CivilianCADAPITypes = exports.GeneralCADAPITypes = exports.DefaultCMSRestOptions = exports.DefaultCADRestOptions = exports.DefaultUserAgent = void 0;
3
+ exports.CADDispatchStatusEnums = exports.CADDispatchOriginEnums = exports.CADModifyIdentifierActionEnums = exports.CADLookupByIntSearchTypeEnums = exports.CADRecordSectionCategoryEnums = exports.CADRecordTypeEnums = exports.AllAPITypes = exports.EventsCMSAPITypes = exports.ServersCMSAPITypes = exports.GeneralCMSAPITypes = exports.EmergencyCADAPITypes = exports.CivilianCADAPITypes = exports.GeneralCADAPITypes = exports.DefaultCMSRestOptions = exports.DefaultCADRestOptions = exports.DefaultUserAgent = void 0;
4
4
  const constants_1 = require("../../../../../constants");
5
5
  exports.DefaultUserAgent = 'Sonoran.js NPM Module';
6
6
  exports.DefaultCADRestOptions = {
@@ -373,6 +373,14 @@ exports.ServersCMSAPITypes = [
373
373
  minVersion: 3
374
374
  }
375
375
  ];
376
+ exports.EventsCMSAPITypes = [
377
+ {
378
+ type: 'RSVP',
379
+ path: 'events/rsvp',
380
+ method: 'POST',
381
+ minVersion: 3
382
+ }
383
+ ];
376
384
  function formatForAll(array, product) {
377
385
  return array.map((val) => {
378
386
  return {
@@ -1,4 +1,4 @@
1
- import Collection from '@discordjs/collection';
1
+ import { Collection } from '@discordjs/collection';
2
2
  import { Instance } from '../instance/Instance';
3
3
  import { Constructable } from '../constants';
4
4
  import { DataManager } from './DataManager';
@@ -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 = __importDefault(require("@discordjs/collection"));
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.default();
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 = __importDefault(require("@discordjs/collection"));
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.default) {
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 declare type CADActiveUnitResolvable = CADActiveUnit | number;
34
+ export type CADActiveUnitResolvable = CADActiveUnit | number;
35
35
  export declare class CADActiveUnit extends Base {
36
36
  id: number;
37
37
  accId: 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.debugLog = exports.errorLog = exports.infoLog = exports.warnLog = exports.flatten = exports.cloneObject = exports.mergeDefault = void 0;
7
- const collection_1 = __importDefault(require("@discordjs/collection"));
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.default)
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.default)
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.13",
3
+ "version": "1.0.15",
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": "^0.5.0",
41
- "@sapphire/async-queue": "^1.3.0",
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';
@@ -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
- constructor(options: InstanceTypes.InstanceOptions) {
27
- super({ captureRejections: true });
28
- if (options.debug) {
29
- this.debug = options.debug;
30
- }
31
- if (Object.prototype.hasOwnProperty.call(options, 'apiKey') && Object.prototype.hasOwnProperty.call(options, 'communityId')) {
32
- if (Object.prototype.hasOwnProperty.call(options, 'product')) {
33
- switch (options.product) {
34
- case globalTypes.productEnums.CAD: {
35
- this.cadCommunityId = options.communityId;
36
- this.cadApiKey = options.apiKey;
37
- if (options.serverId !== undefined) {
38
- this._debugLog(`Overriding default server id... ${options.serverId}`);
39
- this.cadDefaultServerId = options.serverId;
40
- }
41
- if (Object.prototype.hasOwnProperty.call(options, 'cadApiUrl') && typeof options.cadApiUrl === 'string') {
42
- this._debugLog(`Overriding CAD API Url... ${options.cadApiUrl}`);
43
- this.cadApiUrl = options.cadApiUrl;
44
- }
45
- this._debugLog('About to initialize instance.');
46
- this.initialize();
47
- break;
48
- }
49
- case globalTypes.productEnums.CMS: {
50
- this.cmsCommunityId = options.communityId;
51
- this.cmsApiKey = options.apiKey;
52
- if (options.serverId !== undefined) {
53
- this._debugLog(`Overriding default server id... ${options.serverId}`);
54
- this.cmsDefaultServerId = options.serverId;
55
- }
56
- if (Object.prototype.hasOwnProperty.call(options, 'cmsApiUrl') && typeof options.cmsApiUrl === 'string') {
57
- this._debugLog(`Overriding CMS API URL... ${options.cmsApiUrl}`);
58
- this.cmsApiUrl = options.cmsApiUrl;
59
- }
60
- this.initialize();
61
- break;
62
- }
63
- default: {
64
- throw new Error('Invalid product enum given for constructor.');
65
- }
66
- }
67
- } else {
68
- throw new Error('No product enum given when instancing.');
69
- }
70
- } else {
71
- this.cadCommunityId = options.cadCommunityId;
72
- this.cadApiKey = options.cadApiKey;
73
- this.cmsCommunityId = options.cmsCommunityId;
74
- this.cmsApiKey = options.cmsApiKey;
75
-
76
- if (options.cadDefaultServerId !== undefined) {
77
- this._debugLog(`Overriding default CAD server id... ${options.serverId}`);
78
- this.cadDefaultServerId = options.cadDefaultServerId;
79
- }
80
- if (options.cmsDefaultServerId !== undefined) {
81
- this._debugLog(`Overriding default CMS server id... ${options.serverId}`);
82
- this.cmsDefaultServerId = options.cmsDefaultServerId;
83
- }
84
- if (Object.prototype.hasOwnProperty.call(options, 'cadApiUrl') && typeof options.cadApiUrl === 'string') {
85
- this._debugLog(`Overriding CAD API Url... ${options.cadApiUrl}`);
86
- this.cadApiUrl = options.cadApiUrl;
87
- }
88
- if (Object.prototype.hasOwnProperty.call(options, 'cmsApiUrl') && typeof options.cmsApiUrl === 'string') {
89
- this._debugLog(`Overriding CMS API URL... ${options.cmsApiUrl}`);
90
- this.cmsApiUrl = options.cmsApiUrl;
91
- }
92
- this.initialize();
93
- }
94
- }
95
-
96
-
97
-
98
- private initialize() {
99
- if (this.cadCommunityId && this.cadApiKey && this.cadApiUrl) {
100
- this._debugLog('About to initialize CAD Manager');
101
- this.cad = new CADManager(this);
102
- } else {
103
- this._debugLog('Not initializing CAD Manager due to a missing community id, api key, or api url.');
104
- }
105
- if (this.cmsCommunityId && this.cmsApiKey && this.cmsApiUrl) {
106
- this._debugLog('About to initialize CMS Manager');
107
- this.cms = new CMSManager(this);
108
- } else {
109
- this._debugLog('Not initializing CMS Manager due to a missing community id, api key, or api url.');
110
- }
111
- }
112
-
113
- public _debugLog(message: string): void {
114
- if (this.debug) {
115
- debugLog(message);
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
  };
@@ -13,7 +13,7 @@ import type { RequestInit, Response } from 'node-fetch';
13
13
  // import type Collection from '@discordjs/collection';
14
14
  import { Instance } from '../../../../instance/Instance';
15
15
  import { CADManager } from '../../../../managers/CADManager';
16
- import { convertSubNumToName } from './utils/Utils';
16
+ import { convertSubNumToName } from './utils/utils';
17
17
  import { CMSManager } from '../../../../managers/CMSManager';
18
18
 
19
19
  /**
@@ -179,6 +179,13 @@ export class REST extends EventEmitter {
179
179
  serverId: args[0]
180
180
  }
181
181
  }
182
+ case 'RSVP': {
183
+ return {
184
+ eventId: args[0],
185
+ apiId: args[1],
186
+ accId: args[2],
187
+ }
188
+ }
182
189
  case 'GET_COM_ACCOUNT': {
183
190
  return {
184
191
  apiId: args[0],
@@ -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;
@@ -406,6 +406,15 @@ export const ServersCMSAPITypes: APITypeData[] = [
406
406
  }
407
407
  ];
408
408
 
409
+ export const EventsCMSAPITypes: APITypeData[] = [
410
+ {
411
+ type: 'RSVP',
412
+ path: 'events/rsvp',
413
+ method: 'POST',
414
+ minVersion: 3
415
+ }
416
+ ];
417
+
409
418
  function formatForAll(array: APITypeData[], product: productEnums): AllAPITypeData[] {
410
419
  return array.map((val) => {
411
420
  return {
@@ -417,7 +426,7 @@ function formatForAll(array: APITypeData[], product: productEnums): AllAPITypeDa
417
426
 
418
427
  export const AllAPITypes: AllAPITypeData[] = [ ...formatForAll(GeneralCADAPITypes, productEnums.CAD), ...formatForAll(CivilianCADAPITypes, productEnums.CAD), ...formatForAll(EmergencyCADAPITypes, productEnums.CAD), ...formatForAll(GeneralCMSAPITypes, productEnums.CMS), ...formatForAll(ServersCMSAPITypes, productEnums.CMS) ];
419
428
 
420
- 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';
429
+ 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';
421
430
 
422
431
  export interface CMSServerAPIStruct {
423
432
  id: number;
@@ -719,7 +728,7 @@ export interface RESTTypedAPIDataStructs {
719
728
  ];
720
729
  // CAD - Civilian
721
730
  GET_CHARACTERS: [apiId: string];
722
- NEW_CHARACTER: [data: CADNewEditRecordOptionOneStruct | CADNewEditRecordOptionTwoStruct];
731
+ NEW_CHARACTER: [data: CADNewEditRecordOptionOneStruct | CADNewEditRecordOptionTwoStruct];
723
732
  EDIT_CHARACTER: [data: CADNewEditRecordOptionOneStruct | CADNewEditRecordOptionTwoStruct];
724
733
  REMOVE_CHARACTER: [id: number];
725
734
  // CAD - Emergency
@@ -842,10 +851,15 @@ export interface RESTTypedAPIDataStructs {
842
851
  FULL_WHITELIST: [
843
852
  serverId?: number,
844
853
  ]
854
+ RSVP : [
855
+ eventId: string,
856
+ apiId: string | undefined,
857
+ accId: string | undefined,
858
+ ]
845
859
  }
846
860
 
847
- export type PossibleRequestData =
848
- undefined |
861
+ export type PossibleRequestData =
862
+ undefined |
849
863
  {
850
864
  data: CADPenalCodeStruct[] | CADSetAPIIDStruct | CADNewEditRecordOptionOneStruct | CADNewEditRecordOptionTwoStruct | CADLookupByIntStruct | CADLookupStruct | CADModifyAccountPermsStruct | CADKickBanUserStruct | CADSetPostalStruct[] | CADModifyIdentifierStruct | CADAddBlipStruct[] | CADModifyBlipStruct[] | CADGetCallsStruct | CADGetActiveUnitsStruct | CADNewDispatchStruct
851
865
  } |
@@ -1,4 +1,4 @@
1
- import Collection from '@discordjs/collection';
1
+ import { Collection } from '@discordjs/collection';
2
2
  import { Instance } from '../instance/Instance';
3
3
  import { Constructable } from '../constants';
4
4
  import { DataManager } from './DataManager';
@@ -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
- public resolve(idOrInstance: string | object): object | null {
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;
@@ -1,4 +1,4 @@
1
- import Collection from '@discordjs/collection';
1
+ import { Collection } from '@discordjs/collection';
2
2
 
3
3
  const isObject = (d: any) => typeof d === 'object' && d !== null;
4
4