@sonoransoftware/sonoran.js 1.0.19 → 1.0.22

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 (89) hide show
  1. package/.eslintrc.js +10 -10
  2. package/.github/workflows/npm-publish.yml +34 -34
  3. package/.prettierrc.js +6 -6
  4. package/dist/builders/cad/DispatchCall.d.ts +92 -92
  5. package/dist/builders/cad/DispatchCall.js +144 -144
  6. package/dist/builders/cad/index.d.ts +1 -1
  7. package/dist/builders/cad/index.js +17 -17
  8. package/dist/builders/index.d.ts +1 -1
  9. package/dist/builders/index.js +19 -19
  10. package/dist/constants.d.ts +230 -230
  11. package/dist/constants.js +27 -27
  12. package/dist/errors/LibraryErrors.d.ts +19 -19
  13. package/dist/errors/LibraryErrors.js +47 -47
  14. package/dist/errors/Messages.d.ts +1 -1
  15. package/dist/errors/Messages.js +8 -8
  16. package/dist/errors/index.d.ts +2 -2
  17. package/dist/errors/index.js +18 -18
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +24 -24
  20. package/dist/instance/Instance.d.ts +24 -24
  21. package/dist/instance/Instance.js +139 -139
  22. package/dist/instance/instance.types.d.ts +17 -17
  23. package/dist/instance/instance.types.js +2 -2
  24. package/dist/libs/rest/src/index.d.ts +6 -6
  25. package/dist/libs/rest/src/index.js +22 -22
  26. package/dist/libs/rest/src/lib/REST.d.ts +101 -101
  27. package/dist/libs/rest/src/lib/REST.js +136 -129
  28. package/dist/libs/rest/src/lib/RequestManager.d.ts +59 -59
  29. package/dist/libs/rest/src/lib/RequestManager.js +191 -191
  30. package/dist/libs/rest/src/lib/errors/APIError.d.ts +9 -9
  31. package/dist/libs/rest/src/lib/errors/APIError.js +17 -17
  32. package/dist/libs/rest/src/lib/errors/HTTPError.d.ts +17 -17
  33. package/dist/libs/rest/src/lib/errors/HTTPError.js +23 -23
  34. package/dist/libs/rest/src/lib/errors/RateLimitError.d.ts +13 -13
  35. package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -19
  36. package/dist/libs/rest/src/lib/errors/index.d.ts +4 -4
  37. package/dist/libs/rest/src/lib/errors/index.js +20 -20
  38. package/dist/libs/rest/src/lib/handlers/IHandler.d.ts +7 -7
  39. package/dist/libs/rest/src/lib/handlers/IHandler.js +2 -2
  40. package/dist/libs/rest/src/lib/handlers/SequentialHandler.d.ts +45 -45
  41. package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +143 -143
  42. package/dist/libs/rest/src/lib/utils/constants.d.ts +533 -527
  43. package/dist/libs/rest/src/lib/utils/constants.js +463 -455
  44. package/dist/libs/rest/src/lib/utils/utils.d.ts +1 -1
  45. package/dist/libs/rest/src/lib/utils/utils.js +22 -22
  46. package/dist/managers/BaseManager.d.ts +14 -14
  47. package/dist/managers/BaseManager.js +18 -18
  48. package/dist/managers/CADActiveUnitsManager.d.ts +15 -15
  49. package/dist/managers/CADActiveUnitsManager.js +38 -38
  50. package/dist/managers/CADManager.d.ts +29 -29
  51. package/dist/managers/CADManager.js +86 -86
  52. package/dist/managers/CADServerManager.d.ts +8 -8
  53. package/dist/managers/CADServerManager.js +28 -28
  54. package/dist/managers/CMSManager.d.ts +101 -101
  55. package/dist/managers/CMSManager.js +266 -266
  56. package/dist/managers/CMSServerManager.d.ts +8 -8
  57. package/dist/managers/CMSServerManager.js +34 -34
  58. package/dist/managers/CacheManager.d.ts +10 -10
  59. package/dist/managers/CacheManager.js +36 -36
  60. package/dist/managers/DataManager.d.ts +31 -31
  61. package/dist/managers/DataManager.js +58 -58
  62. package/dist/structures/Base.d.ts +9 -9
  63. package/dist/structures/Base.js +24 -24
  64. package/dist/structures/CADActiveUnit.d.ts +47 -47
  65. package/dist/structures/CADActiveUnit.js +66 -66
  66. package/dist/structures/CADServer.d.ts +26 -26
  67. package/dist/structures/CADServer.js +15 -15
  68. package/dist/structures/CMSServer.d.ts +18 -18
  69. package/dist/structures/CMSServer.js +12 -12
  70. package/dist/utils/index.d.ts +1 -1
  71. package/dist/utils/index.js +17 -17
  72. package/dist/utils/utils.d.ts +13 -13
  73. package/dist/utils/utils.js +79 -79
  74. package/docs/CAD-Methods-and-Usage.md +58 -58
  75. package/docs/CMS-Methods-and-Usage.md +211 -211
  76. package/docs/REST-Methods-and-Usage.md +46 -46
  77. package/package.json +48 -48
  78. package/readme.md +53 -53
  79. package/src/constants.ts +248 -248
  80. package/src/instance/Instance.ts +121 -121
  81. package/src/instance/instance.types.ts +17 -17
  82. package/src/libs/rest/src/lib/REST.ts +241 -234
  83. package/src/libs/rest/src/lib/RequestManager.ts +260 -260
  84. package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +160 -160
  85. package/src/libs/rest/src/lib/utils/constants.ts +1012 -997
  86. package/src/managers/CADManager.ts +63 -63
  87. package/src/managers/CMSManager.ts +226 -226
  88. package/src/managers/CMSServerManager.ts +32 -32
  89. package/tsconfig.json +71 -71
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,45 +1,45 @@
1
- import { RequestInit } from 'node-fetch';
2
- import type { RequestManager, APIData } from '../RequestManager';
3
- import type { IHandler } from './IHandler';
4
- export declare class SequentialHandler implements IHandler {
5
- #private;
6
- private readonly manager;
7
- private readonly data;
8
- /**
9
- * The unique id of the handler
10
- */
11
- readonly id: string;
12
- /**
13
- * @param manager The request manager
14
- * @param hash The hash that this RequestHandler handles
15
- * @param majorParameter The major parameter for this handler
16
- */
17
- constructor(manager: RequestManager, data: APIData);
18
- /**
19
- * If the bucket is currently inactive (no pending requests)
20
- */
21
- get inactive(): boolean;
22
- getMang(): RequestManager;
23
- /**
24
- * Emits a debug message
25
- * @param message The message to debug
26
- */
27
- /**
28
- * Queues a request to be sent
29
- * @param routeId The generalized api route with literal ids for major parameters
30
- * @param url The url to do the request on
31
- * @param options All the information needed to make a request
32
- * @param requestData Extra data from the user's request needed for errors and additional processing
33
- */
34
- queueRequest(url: string, options: RequestInit, data: APIData): Promise<unknown>;
35
- /**
36
- * The method that actually makes the request to the api, and updates info about the bucket accordingly
37
- * @param routeId The generalized api route with literal ids for major parameters
38
- * @param url The fully resolved url to make the request to
39
- * @param options The node-fetch options needed to make the request
40
- * @param requestData Extra data from the user's request needed for errors and additional processing
41
- * @param retries The number of retries this request has already attempted (recursion)
42
- */
43
- private runRequest;
44
- private static parseResponse;
45
- }
1
+ import { RequestInit } from 'node-fetch';
2
+ import type { RequestManager, APIData } from '../RequestManager';
3
+ import type { IHandler } from './IHandler';
4
+ export declare class SequentialHandler implements IHandler {
5
+ #private;
6
+ private readonly manager;
7
+ private readonly data;
8
+ /**
9
+ * The unique id of the handler
10
+ */
11
+ readonly id: string;
12
+ /**
13
+ * @param manager The request manager
14
+ * @param hash The hash that this RequestHandler handles
15
+ * @param majorParameter The major parameter for this handler
16
+ */
17
+ constructor(manager: RequestManager, data: APIData);
18
+ /**
19
+ * If the bucket is currently inactive (no pending requests)
20
+ */
21
+ get inactive(): boolean;
22
+ getMang(): RequestManager;
23
+ /**
24
+ * Emits a debug message
25
+ * @param message The message to debug
26
+ */
27
+ /**
28
+ * Queues a request to be sent
29
+ * @param routeId The generalized api route with literal ids for major parameters
30
+ * @param url The url to do the request on
31
+ * @param options All the information needed to make a request
32
+ * @param requestData Extra data from the user's request needed for errors and additional processing
33
+ */
34
+ queueRequest(url: string, options: RequestInit, data: APIData): Promise<unknown>;
35
+ /**
36
+ * The method that actually makes the request to the api, and updates info about the bucket accordingly
37
+ * @param routeId The generalized api route with literal ids for major parameters
38
+ * @param url The fully resolved url to make the request to
39
+ * @param options The node-fetch options needed to make the request
40
+ * @param requestData Extra data from the user's request needed for errors and additional processing
41
+ * @param retries The number of retries this request has already attempted (recursion)
42
+ */
43
+ private runRequest;
44
+ private static parseResponse;
45
+ }
@@ -1,143 +1,143 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- var _SequentialHandler_asyncQueue;
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SequentialHandler = void 0;
13
- // import { setTimeout as sleep } from 'node:timers/promises';
14
- const async_queue_1 = require("@sapphire/async-queue");
15
- const node_fetch_1 = __importDefault(require("node-fetch"));
16
- const node_abort_controller_1 = require("node-abort-controller");
17
- // import { DiscordAPIError, DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError';
18
- const errors_1 = require("../errors");
19
- const HTTPError_1 = require("../errors/HTTPError");
20
- class SequentialHandler {
21
- /**
22
- * @param manager The request manager
23
- * @param hash The hash that this RequestHandler handles
24
- * @param majorParameter The major parameter for this handler
25
- */
26
- constructor(manager, data) {
27
- this.manager = manager;
28
- this.data = data;
29
- /**
30
- * The total number of requests that can be made before we are rate limited
31
- */
32
- // private limit = Infinity;
33
- /**
34
- * The interface used to sequence async requests sequentially
35
- */
36
- // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
37
- _SequentialHandler_asyncQueue.set(this, new async_queue_1.AsyncQueue());
38
- this.id = `${this.data.typePath}:${String(this.data.product)}`;
39
- }
40
- /**
41
- * If the bucket is currently inactive (no pending requests)
42
- */
43
- get inactive() {
44
- return (__classPrivateFieldGet(this, _SequentialHandler_asyncQueue, "f").remaining === 0);
45
- }
46
- getMang() {
47
- return this.manager;
48
- }
49
- /**
50
- * Emits a debug message
51
- * @param message The message to debug
52
- */
53
- // private debug(message: string) {
54
- // this.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);
55
- // }
56
- /*
57
- * Determines whether the request should be queued or whether a RateLimitError should be thrown
58
- */
59
- // private async onRateLimit(rateLimitData: RateLimitData) {
60
- // const { options } = this.manager;
61
- // if (options.rejectOnRateLimit) {
62
- // throw new RateLimitError(rateLimitData);
63
- // }
64
- // }
65
- /**
66
- * Queues a request to be sent
67
- * @param routeId The generalized api route with literal ids for major parameters
68
- * @param url The url to do the request on
69
- * @param options All the information needed to make a request
70
- * @param requestData Extra data from the user's request needed for errors and additional processing
71
- */
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
- }
84
- }
85
- /**
86
- * The method that actually makes the request to the api, and updates info about the bucket accordingly
87
- * @param routeId The generalized api route with literal ids for major parameters
88
- * @param url The fully resolved url to make the request to
89
- * @param options The node-fetch options needed to make the request
90
- * @param requestData Extra data from the user's request needed for errors and additional processing
91
- * @param retries The number of retries this request has already attempted (recursion)
92
- */
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
- void this.manager.debug(`[${url} Request] - ${JSON.stringify({ url, options, data })}`);
98
- try {
99
- // node-fetch typings are a bit weird, so we have to cast to any to get the correct signature
100
- // Type 'AbortSignal' is not assignable to type 'import('discord.js-modules/node_modules/@types/node-fetch/externals').AbortSignal'
101
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
102
- res = await (0, node_fetch_1.default)(url, { ...options, signal: controller.signal });
103
- }
104
- catch (error) {
105
- throw error;
106
- }
107
- finally {
108
- clearTimeout(timeout);
109
- }
110
- const parsedRes = await SequentialHandler.parseResponse(res);
111
- void this.manager.debug(`[${url} Response] - ${JSON.stringify({ body: parsedRes, res, status: res.status, headers: res.headers })}`);
112
- if (res.ok) {
113
- return parsedRes;
114
- }
115
- else if (res.status === 400 || res.status === 401 || res.status === 404) {
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;
133
- }
134
- static parseResponse(res) {
135
- var _a;
136
- if ((_a = res.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.startsWith('application/json')) {
137
- return res.json();
138
- }
139
- return res.text();
140
- }
141
- }
142
- exports.SequentialHandler = SequentialHandler;
143
- _SequentialHandler_asyncQueue = new WeakMap();
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _SequentialHandler_asyncQueue;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SequentialHandler = void 0;
13
+ // import { setTimeout as sleep } from 'node:timers/promises';
14
+ const async_queue_1 = require("@sapphire/async-queue");
15
+ const node_fetch_1 = __importDefault(require("node-fetch"));
16
+ const node_abort_controller_1 = require("node-abort-controller");
17
+ // import { DiscordAPIError, DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError';
18
+ const errors_1 = require("../errors");
19
+ const HTTPError_1 = require("../errors/HTTPError");
20
+ class SequentialHandler {
21
+ /**
22
+ * @param manager The request manager
23
+ * @param hash The hash that this RequestHandler handles
24
+ * @param majorParameter The major parameter for this handler
25
+ */
26
+ constructor(manager, data) {
27
+ this.manager = manager;
28
+ this.data = data;
29
+ /**
30
+ * The total number of requests that can be made before we are rate limited
31
+ */
32
+ // private limit = Infinity;
33
+ /**
34
+ * The interface used to sequence async requests sequentially
35
+ */
36
+ // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
37
+ _SequentialHandler_asyncQueue.set(this, new async_queue_1.AsyncQueue());
38
+ this.id = `${this.data.typePath}:${String(this.data.product)}`;
39
+ }
40
+ /**
41
+ * If the bucket is currently inactive (no pending requests)
42
+ */
43
+ get inactive() {
44
+ return (__classPrivateFieldGet(this, _SequentialHandler_asyncQueue, "f").remaining === 0);
45
+ }
46
+ getMang() {
47
+ return this.manager;
48
+ }
49
+ /**
50
+ * Emits a debug message
51
+ * @param message The message to debug
52
+ */
53
+ // private debug(message: string) {
54
+ // this.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);
55
+ // }
56
+ /*
57
+ * Determines whether the request should be queued or whether a RateLimitError should be thrown
58
+ */
59
+ // private async onRateLimit(rateLimitData: RateLimitData) {
60
+ // const { options } = this.manager;
61
+ // if (options.rejectOnRateLimit) {
62
+ // throw new RateLimitError(rateLimitData);
63
+ // }
64
+ // }
65
+ /**
66
+ * Queues a request to be sent
67
+ * @param routeId The generalized api route with literal ids for major parameters
68
+ * @param url The url to do the request on
69
+ * @param options All the information needed to make a request
70
+ * @param requestData Extra data from the user's request needed for errors and additional processing
71
+ */
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
+ }
84
+ }
85
+ /**
86
+ * The method that actually makes the request to the api, and updates info about the bucket accordingly
87
+ * @param routeId The generalized api route with literal ids for major parameters
88
+ * @param url The fully resolved url to make the request to
89
+ * @param options The node-fetch options needed to make the request
90
+ * @param requestData Extra data from the user's request needed for errors and additional processing
91
+ * @param retries The number of retries this request has already attempted (recursion)
92
+ */
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
+ void this.manager.debug(`[${url} Request] - ${JSON.stringify({ url, options, data })}`);
98
+ try {
99
+ // node-fetch typings are a bit weird, so we have to cast to any to get the correct signature
100
+ // Type 'AbortSignal' is not assignable to type 'import('discord.js-modules/node_modules/@types/node-fetch/externals').AbortSignal'
101
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
102
+ res = await (0, node_fetch_1.default)(url, { ...options, signal: controller.signal });
103
+ }
104
+ catch (error) {
105
+ throw error;
106
+ }
107
+ finally {
108
+ clearTimeout(timeout);
109
+ }
110
+ const parsedRes = await SequentialHandler.parseResponse(res);
111
+ void this.manager.debug(`[${url} Response] - ${JSON.stringify({ body: parsedRes, res, status: res.status, headers: res.headers })}`);
112
+ if (res.ok) {
113
+ return parsedRes;
114
+ }
115
+ else if (res.status === 400 || res.status === 401 || res.status === 404) {
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;
133
+ }
134
+ static parseResponse(res) {
135
+ var _a;
136
+ if ((_a = res.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.startsWith('application/json')) {
137
+ return res.json();
138
+ }
139
+ return res.text();
140
+ }
141
+ }
142
+ exports.SequentialHandler = SequentialHandler;
143
+ _SequentialHandler_asyncQueue = new WeakMap();