@elara-services/packages 6.1.1 → 7.0.0

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 (39) hide show
  1. package/dist/package.json +4 -6
  2. package/dist/src/interfaces/discord.d.ts +2 -2
  3. package/dist/src/lib/AES.js +16 -5
  4. package/dist/src/lib/discord.d.ts +1 -1
  5. package/dist/src/lib/discord.js +44 -44
  6. package/dist/src/lib/languages.js +2 -2
  7. package/dist/src/lib/misc.d.ts +21 -1
  8. package/dist/src/lib/misc.js +42 -71
  9. package/dist/src/lib/random.js +11 -11
  10. package/dist/src/lib/tasks.d.ts +3 -3
  11. package/dist/src/lib/tasks.js +5 -5
  12. package/docs/classes/AES.html +5 -5
  13. package/docs/classes/Minesweeper.html +11 -11
  14. package/docs/functions/fetch.html +8 -24
  15. package/docs/functions/randomNumber.html +1 -1
  16. package/docs/functions/randomWeight.html +1 -1
  17. package/docs/functions/randomWords.html +1 -1
  18. package/docs/interfaces/ButtonOptions.html +10 -10
  19. package/docs/interfaces/ModalOptions.html +8 -8
  20. package/docs/interfaces/RandomNumberOptions.html +4 -4
  21. package/docs/interfaces/RandomWord.html +9 -9
  22. package/docs/interfaces/SelectOptions.html +12 -12
  23. package/docs/interfaces/Slash.html +8 -8
  24. package/docs/interfaces/SlashOptions.html +14 -14
  25. package/docs/interfaces/TaskCreate.html +4 -4
  26. package/docs/interfaces/TextInputOptions.html +15 -15
  27. package/docs/types/ButtonNumberStyles.html +1 -1
  28. package/docs/types/ButtonStyles.html +1 -1
  29. package/docs/types/ChannelTypes.html +1 -1
  30. package/docs/types/Lang.html +1 -1
  31. package/docs/types/LangName.html +1 -1
  32. package/docs/types/TaskCreateRun.html +4 -4
  33. package/docs/variables/ButtonStyle.html +1 -1
  34. package/docs/variables/Duration.html +1 -1
  35. package/docs/variables/Interactions.html +6 -6
  36. package/docs/variables/Languages.html +2 -2
  37. package/docs/variables/SlashBuilder.html +1 -1
  38. package/docs/variables/Tasks.html +5 -5
  39. package/package.json +4 -6
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/packages",
3
- "version": "6.1.1",
3
+ "version": "7.0.0",
4
4
  "description": "",
5
5
  "main": "./dist/src/index.js",
6
6
  "author": "SUPERCHIEFYT (Elara-Discord-Bots, Elara-Services)",
@@ -33,12 +33,10 @@
33
33
  "typedoc": "0.24.8",
34
34
  "typescript": "5.1.3"
35
35
  },
36
- "optionalDependencies": {
37
- "@elara-services/fetch": "2.0.1"
38
- },
39
36
  "dependencies": {
40
- "@elara-services/utils": "^2.0.18",
41
- "discord-api-types": "0.37.48",
37
+ "@elara-services/fetch": "^2.0.3",
38
+ "@elara-services/basic-utils": "^1.1.5",
39
+ "discord-api-types": "^0.38.18",
42
40
  "eventemitter3": "^5.0.1",
43
41
  "node-schedule": "^2.1.1"
44
42
  }
@@ -1,4 +1,4 @@
1
- import { APIModalActionRowComponent, APISelectMenuOption, ComponentType } from "discord-api-types/v10";
1
+ import { APISelectMenuOption, ComponentType, ModalSubmitActionRowComponent } from "discord-api-types/v10";
2
2
  export type ButtonStyles = "PRIMARY" | "BLURPLE" | "SECONDARY" | "GREY" | "SUCCESS" | "GREEN" | "DANGER" | "RED" | "LINK" | "URL";
3
3
  export type ButtonNumberStyles = 1 | 2 | 3 | 4 | 5;
4
4
  export interface ButtonOptions {
@@ -36,7 +36,7 @@ export interface ModalOptions {
36
36
  id?: string;
37
37
  components: {
38
38
  type: 1 | ComponentType.ActionRow;
39
- components: APIModalActionRowComponent[];
39
+ components: ModalSubmitActionRowComponent[];
40
40
  }[];
41
41
  }
42
42
  export interface TextInputOptions {
@@ -1,37 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AES = void 0;
4
- const utils_1 = require("@elara-services/utils");
4
+ const basic_utils_1 = require("@elara-services/basic-utils");
5
5
  const crypto_1 = require("crypto");
6
6
  const package_json_1 = require("../../package.json");
7
7
  const header = `[${package_json_1.name}, v${package_json_1.version}]: [AES]`;
8
8
  class AES {
9
9
  constructor(key) {
10
- if (!utils_1.is.string(key)) {
10
+ this.key = key;
11
+ if (!basic_utils_1.is.string(key)) {
11
12
  throw new Error(`${header} You didn't include a key in the constructor.`);
12
13
  }
13
- this.key = key;
14
14
  }
15
15
  encrypt(input) {
16
- const isString = utils_1.is.string(input);
16
+ const isString = basic_utils_1.is.string(input);
17
17
  const isBuffer = Buffer.isBuffer(input);
18
18
  if (!(isString || isBuffer) ||
19
19
  (isString && !input) ||
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
21
  (isBuffer && !Buffer.byteLength(input))) {
21
22
  throw new Error(`${header} Provided invalid 'input', must be a non-empty string or buffer.`);
22
23
  }
23
24
  const sha = (0, crypto_1.createHash)("sha256");
24
25
  sha.update(this.key);
25
26
  const iv = (0, crypto_1.randomBytes)(16);
27
+ // @ts-ignore
26
28
  const cipher = (0, crypto_1.createCipheriv)("aes-256-ctr", sha.digest(), iv);
27
29
  let buffer = input;
28
30
  if (isString) {
31
+ // @ts-ignore
29
32
  buffer = Buffer.from(input);
30
33
  }
34
+ // @ts-ignore
31
35
  const text = cipher.update(buffer);
32
36
  let encrypted = Buffer.concat([
37
+ // @ts-ignore
33
38
  iv,
39
+ // @ts-ignore
34
40
  text,
41
+ // @ts-ignore
35
42
  cipher.final(),
36
43
  ]);
37
44
  if (isString) {
@@ -40,10 +47,11 @@ class AES {
40
47
  return encrypted;
41
48
  }
42
49
  decrypt(encrypted) {
43
- const isString = utils_1.is.string(encrypted);
50
+ const isString = basic_utils_1.is.string(encrypted);
44
51
  const isBuffer = Buffer.isBuffer(encrypted);
45
52
  if (!(isString || isBuffer) ||
46
53
  (isString && !encrypted) ||
54
+ // @ts-ignore
47
55
  (isBuffer && !Buffer.byteLength(encrypted))) {
48
56
  throw new Error(`${header} Provided "encrypted" must be a non-empty string or buffer`);
49
57
  }
@@ -58,10 +66,12 @@ class AES {
58
66
  }
59
67
  }
60
68
  else {
69
+ // @ts-ignore
61
70
  if (Buffer.byteLength(encrypted) < 17) {
62
71
  throw new Error(`${header} Provided "encrypted" must decrypt to a non-empty string or buffer`);
63
72
  }
64
73
  }
74
+ // @ts-ignore
65
75
  const decipher = (0, crypto_1.createDecipheriv)("aes-256-ctr", sha256.digest(), input.slice(0, 16));
66
76
  const ciphertext = input.slice(16);
67
77
  let output;
@@ -73,6 +83,7 @@ class AES {
73
83
  output = Buffer.concat([
74
84
  // @ts-expect-error
75
85
  decipher.update(ciphertext),
86
+ // @ts-ignore
76
87
  decipher.final(),
77
88
  ]);
78
89
  }
@@ -40,7 +40,7 @@ export declare const Interactions: {
40
40
  title: string;
41
41
  components: {
42
42
  type: 1 | ComponentType.ActionRow;
43
- components: import("discord-api-types/v10").APITextInputComponent[];
43
+ components: import("discord-api-types/v10").ModalSubmitActionRowComponent[];
44
44
  }[];
45
45
  };
46
46
  textInput: (options?: TextInputOptions, row?: boolean) => {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SlashBuilder = exports.Duration = exports.Interactions = exports.ButtonStyle = void 0;
4
- const utils_1 = require("@elara-services/utils");
4
+ const basic_utils_1 = require("@elara-services/basic-utils");
5
5
  const v10_1 = require("discord-api-types/v10");
6
6
  exports.ButtonStyle = {
7
7
  PRIMARY: 1,
@@ -58,43 +58,43 @@ exports.Interactions = {
58
58
  type: 3,
59
59
  disabled: false,
60
60
  };
61
- if (utils_1.is.string(options.id)) {
61
+ if (basic_utils_1.is.string(options.id)) {
62
62
  data.custom_id = options.id;
63
63
  }
64
- else if (utils_1.is.string(options.custom_id)) {
64
+ else if (basic_utils_1.is.string(options.custom_id)) {
65
65
  data.custom_id = options.custom_id;
66
66
  }
67
- if (utils_1.is.string(options.placeholder)) {
67
+ if (basic_utils_1.is.string(options.placeholder)) {
68
68
  data.placeholder = options.placeholder;
69
69
  }
70
- else if (utils_1.is.string(options.holder)) {
70
+ else if (basic_utils_1.is.string(options.holder)) {
71
71
  data.placeholder = options.holder;
72
72
  }
73
- if (utils_1.is.number(options.max_values)) {
73
+ if (basic_utils_1.is.number(options.max_values)) {
74
74
  data.max_values = options.max_values;
75
75
  }
76
- else if (utils_1.is.number(options.max)) {
76
+ else if (basic_utils_1.is.number(options.max)) {
77
77
  data.max_values = options.max;
78
78
  }
79
- if (utils_1.is.number(options.min_values)) {
79
+ if (basic_utils_1.is.number(options.min_values)) {
80
80
  data.min_values = options.min_values;
81
81
  }
82
- else if (utils_1.is.number(options.min)) {
82
+ else if (basic_utils_1.is.number(options.min)) {
83
83
  data.min_values = options.min;
84
84
  }
85
- if (utils_1.is.boolean(options.disabled)) {
85
+ if (basic_utils_1.is.boolean(options.disabled)) {
86
86
  data.disabled = options.disabled;
87
87
  }
88
- if (utils_1.is.number(options.type)) {
88
+ if (basic_utils_1.is.number(options.type)) {
89
89
  data.type = options.type;
90
90
  }
91
- if (utils_1.is.array(options.options)) {
91
+ if (basic_utils_1.is.array(options.options)) {
92
92
  data.options = options.options;
93
93
  }
94
94
  return data;
95
95
  },
96
96
  modal: (options = { components: [] }) => {
97
- if (!utils_1.is.array(options.components)) {
97
+ if (!basic_utils_1.is.array(options.components)) {
98
98
  throw new Error(`[Interactions#modal]: 'components' isn't an array, or is empty.`);
99
99
  }
100
100
  const data = {
@@ -102,16 +102,16 @@ exports.Interactions = {
102
102
  title: "",
103
103
  components: options.components,
104
104
  };
105
- if (utils_1.is.string(options.id)) {
105
+ if (basic_utils_1.is.string(options.id)) {
106
106
  data.custom_id = options.id;
107
107
  }
108
- else if (utils_1.is.string(options.custom_id)) {
108
+ else if (basic_utils_1.is.string(options.custom_id)) {
109
109
  data.custom_id = options.custom_id;
110
110
  }
111
- if (utils_1.is.string(options.title)) {
111
+ if (basic_utils_1.is.string(options.title)) {
112
112
  data.title = options.title;
113
113
  }
114
- else if (utils_1.is.string(options.label)) {
114
+ else if (basic_utils_1.is.string(options.label)) {
115
115
  data.title = options.label;
116
116
  }
117
117
  return data;
@@ -128,46 +128,46 @@ exports.Interactions = {
128
128
  value: undefined,
129
129
  required: false,
130
130
  };
131
- if (utils_1.is.number(options.type)) {
131
+ if (basic_utils_1.is.number(options.type)) {
132
132
  data.type = options.type;
133
133
  }
134
- if (utils_1.is.string(options.id)) {
134
+ if (basic_utils_1.is.string(options.id)) {
135
135
  data.custom_id = options.id;
136
136
  }
137
- else if (utils_1.is.string(options.custom_id)) {
137
+ else if (basic_utils_1.is.string(options.custom_id)) {
138
138
  data.custom_id = options.custom_id;
139
139
  }
140
- if (utils_1.is.string(options.label)) {
140
+ if (basic_utils_1.is.string(options.label)) {
141
141
  data.label = options.label;
142
142
  }
143
- else if (utils_1.is.string(options.title)) {
143
+ else if (basic_utils_1.is.string(options.title)) {
144
144
  data.label = options.title;
145
145
  }
146
- if (utils_1.is.string(options.placeholder)) {
146
+ if (basic_utils_1.is.string(options.placeholder)) {
147
147
  data.placeholder = options.placeholder;
148
148
  }
149
- else if (utils_1.is.string(options.holder)) {
149
+ else if (basic_utils_1.is.string(options.holder)) {
150
150
  data.placeholder = options.holder;
151
151
  }
152
- if (utils_1.is.boolean(options.required)) {
152
+ if (basic_utils_1.is.boolean(options.required)) {
153
153
  data.required = options.required;
154
154
  }
155
- if (utils_1.is.string(options.value)) {
155
+ if (basic_utils_1.is.string(options.value)) {
156
156
  data.value = options.value;
157
157
  }
158
- if (utils_1.is.number(options.style)) {
158
+ if (basic_utils_1.is.number(options.style)) {
159
159
  data.style = options.style;
160
160
  }
161
- if (utils_1.is.number(options.min)) {
161
+ if (basic_utils_1.is.number(options.min)) {
162
162
  data.min_length = options.min;
163
163
  }
164
- else if (utils_1.is.number(options.min_length)) {
164
+ else if (basic_utils_1.is.number(options.min_length)) {
165
165
  data.min_length = options.min_length;
166
166
  }
167
- if (utils_1.is.number(options.max)) {
167
+ if (basic_utils_1.is.number(options.max)) {
168
168
  data.max_length = options.max;
169
169
  }
170
- else if (utils_1.is.number(options.max_length)) {
170
+ else if (basic_utils_1.is.number(options.max_length)) {
171
171
  data.max_length = options.max_length;
172
172
  }
173
173
  if (row) {
@@ -209,34 +209,34 @@ exports.Duration = {
209
209
  case "s":
210
210
  case "second":
211
211
  case "seconds":
212
- return 1000;
212
+ return basic_utils_1.get.secs(1);
213
213
  case "m":
214
214
  case "min":
215
215
  case "mins":
216
216
  case "minute":
217
217
  case "minutes":
218
- return 60 * 1000;
218
+ return basic_utils_1.get.mins(1);
219
219
  case "h":
220
220
  case "hr":
221
221
  case "hour":
222
222
  case "hours":
223
- return 60 * 60 * 1000;
223
+ return basic_utils_1.get.hrs(1);
224
224
  case "d":
225
225
  case "day":
226
226
  case "days":
227
- return 24 * 60 * 60 * 1000;
227
+ return basic_utils_1.get.days(1);
228
228
  case "w":
229
229
  case "week":
230
230
  case "weeks":
231
- return 7 * 24 * 60 * 60 * 1000;
231
+ return basic_utils_1.get.days(7);
232
232
  case "mo":
233
233
  case "month":
234
234
  case "months":
235
- return 30 * 24 * 60 * 60 * 1000;
235
+ return 30 * 24 * 60 * 60000;
236
236
  case "y":
237
237
  case "year":
238
238
  case "years":
239
- return 365 * 24 * 60 * 60 * 1000;
239
+ return 365 * 24 * 60 * 60000;
240
240
  default:
241
241
  return 1;
242
242
  }
@@ -355,25 +355,25 @@ exports.SlashBuilder = {
355
355
  if ((_b = options === null || options === void 0 ? void 0 : options.locale) === null || _b === void 0 ? void 0 : _b.descriptions) {
356
356
  obj.description_localizations = options.locale.descriptions;
357
357
  }
358
- if (utils_1.is.array(options.options)) {
358
+ if (basic_utils_1.is.array(options.options)) {
359
359
  obj["options"] = options.options;
360
360
  }
361
- if (utils_1.is.number(options.type)) {
361
+ if (basic_utils_1.is.number(options.type)) {
362
362
  obj.type = options.type;
363
363
  }
364
- if ("dmPermission" in options && utils_1.is.boolean(options.dmPermission)) {
364
+ if ("dmPermission" in options && basic_utils_1.is.boolean(options.dmPermission)) {
365
365
  obj["dm_permission"] = options.dmPermission;
366
366
  }
367
367
  else if ("dm_permission" in options &&
368
- utils_1.is.boolean(options.dm_permission)) {
368
+ basic_utils_1.is.boolean(options.dm_permission)) {
369
369
  obj["dm_permission"] = options.dm_permission;
370
370
  }
371
371
  if ("default_member_permissions" in options &&
372
- utils_1.is.string(options.default_member_permissions)) {
372
+ basic_utils_1.is.string(options.default_member_permissions)) {
373
373
  obj.default_member_permissions = options.default_member_permissions;
374
374
  }
375
375
  else if ("defaultMemberPermissions" in options &&
376
- utils_1.is.string(options.defaultMemberPermissions)) {
376
+ basic_utils_1.is.string(options.defaultMemberPermissions)) {
377
377
  obj.default_member_permissions = options.defaultMemberPermissions;
378
378
  }
379
379
  return obj;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Languages = void 0;
4
- const utils_1 = require("@elara-services/utils");
4
+ const basic_utils_1 = require("@elara-services/basic-utils");
5
5
  const langs = {
6
6
  en: "English",
7
7
  fr: "French",
@@ -112,7 +112,7 @@ const langs = {
112
112
  exports.Languages = {
113
113
  langs,
114
114
  find(name) {
115
- for (const key of (0, utils_1.getKeys)(langs)) {
115
+ for (const key of (0, basic_utils_1.getKeys)(langs)) {
116
116
  if (key === name) {
117
117
  return key;
118
118
  }
@@ -1 +1,21 @@
1
- export declare function fetch<B extends object, T>(url: string, key?: string, body?: B | undefined, postRequest?: boolean, returnRaw?: boolean, addHeaders?: Record<string, string | number>, errors?: (e: Error) => Promise<unknown> | unknown): Promise<T | null>;
1
+ import { StatusFailed } from "@elara-services/basic-utils";
2
+ import { RequestMethod } from "@elara-services/fetch";
3
+ type FetchOptions<B> = Partial<{
4
+ /** Set the 'authorization' header */
5
+ key: string;
6
+ /** Return the raw body for the request. */
7
+ raw: boolean;
8
+ /** The body that you want to send with the request */
9
+ body: B | undefined;
10
+ /** The method you want to use (def: GET) */
11
+ method: RequestMethod;
12
+ /** Any headers you want to include in the request. */
13
+ headers: Record<string, unknown>;
14
+ }>;
15
+ export declare function fetch<B extends object, T>(url: string, options?: FetchOptions<B>,
16
+ /** The retries amount, this is automatically incremented (DO NOT TOUCH) */
17
+ retries?: number): Promise<{
18
+ status: true;
19
+ data: T;
20
+ } | StatusFailed>;
21
+ export {};
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -33,57 +10,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
10
  };
34
11
  Object.defineProperty(exports, "__esModule", { value: true });
35
12
  exports.fetch = void 0;
36
- const utils_1 = require("@elara-services/utils");
37
- function fetch(url, key = "", body = undefined, postRequest = false, returnRaw = false, addHeaders, errors) {
13
+ const basic_utils_1 = require("@elara-services/basic-utils");
14
+ const fetch_1 = require("@elara-services/fetch");
15
+ function fetch(url, options = {},
16
+ /** The retries amount, this is automatically incremented (DO NOT TOUCH) */
17
+ retries = 0) {
18
+ var _a;
38
19
  return __awaiter(this, void 0, void 0, function* () {
39
- try {
40
- const client = yield Promise.resolve().then(() => __importStar(require("@elara-services/fetch"))).catch(() => { });
41
- if (!client) {
42
- throw new Error(`NPM package (@elara-services/fetch) not found`);
43
- }
44
- let headers = {
45
- "user-agent": `Services v${Math.floor(Math.random() * 9999)}`,
46
- authorization: "",
47
- };
48
- if (utils_1.is.object(addHeaders)) {
49
- headers = Object.assign(Object.assign({}, headers), addHeaders);
50
- }
51
- if (utils_1.is.string(key)) {
52
- headers["authorization"] = key;
53
- }
54
- else {
55
- // @ts-expect-error
56
- delete headers["authorization"];
57
- }
58
- const res = yield client
59
- .fetch(url, postRequest ? "POST" : "GET")
60
- .header(headers)
61
- .body(body, "json")
62
- .send()
63
- .catch((e) => new Error(e));
64
- if (res instanceof Error) {
65
- if (errors) {
66
- errors(res);
67
- }
68
- return null;
69
- }
70
- if (res.statusCode !== 200) {
71
- if (errors) {
72
- errors(new Error(`Got (${res.statusCode}) status while trying to fetch ${url}`));
73
- }
74
- return null;
75
- }
76
- if (returnRaw) {
77
- return res.body;
78
- }
79
- return res.json();
20
+ if (!basic_utils_1.is.object(options, true)) {
21
+ options = {};
22
+ }
23
+ let headers = {
24
+ "user-agent": `Services v${Math.floor(Math.random() * 9999)}`,
25
+ };
26
+ if (basic_utils_1.is.object(options.headers, true)) {
27
+ headers = Object.assign(Object.assign({}, headers), options.headers);
28
+ }
29
+ if (basic_utils_1.is.string(options.key)) {
30
+ headers["authorization"] = options.key;
31
+ }
32
+ const req = (0, fetch_1.fetch)(url, options.method || "GET")
33
+ .header(headers);
34
+ if (options.body) {
35
+ req.body(options.body, "json");
80
36
  }
81
- catch (err) {
82
- if (errors) {
83
- errors(err instanceof Error ? err : new Error(err));
84
- }
85
- return null;
37
+ const res = yield req.send().catch((e) => new Error(e));
38
+ if (basic_utils_1.is.error(res)) {
39
+ return basic_utils_1.status.error(`Got an error while trying to fetch the url: ${((_a = res.message) !== null && _a !== void 0 ? _a : res).toString()}`);
40
+ }
41
+ if (res.statusCode === 429 && retries <= 5) {
42
+ yield (0, basic_utils_1.sleep)(basic_utils_1.get.secs(5));
43
+ return yield fetch(url, options, retries + 1);
44
+ }
45
+ if (res.statusCode !== 200) {
46
+ return basic_utils_1.status.error(`Got (${res.statusCode}) status while trying to fetch the url.`);
47
+ }
48
+ if (options.raw === true) {
49
+ return {
50
+ status: true,
51
+ data: res.body,
52
+ };
86
53
  }
54
+ return {
55
+ status: true,
56
+ data: res.json(),
57
+ };
87
58
  });
88
59
  }
89
60
  exports.fetch = fetch;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.randomNumber = exports.randomWords = exports.randomWeight = void 0;
4
- const utils_1 = require("@elara-services/utils");
4
+ const basic_utils_1 = require("@elara-services/basic-utils");
5
5
  function randomWeight(objects) {
6
6
  const randomNumber = Math.random() * objects.reduce((agg, object) => agg + object.weight, 0);
7
7
  let weightSum = 0;
@@ -1973,7 +1973,7 @@ function randomWords(options) {
1973
1973
  let wordUsed = "";
1974
1974
  while (!rightSize) {
1975
1975
  wordUsed = generateRandomWord();
1976
- if (utils_1.is.number(options.maxLength)) {
1976
+ if (basic_utils_1.is.number(options.maxLength)) {
1977
1977
  if (wordUsed.length <= options.maxLength) {
1978
1978
  rightSize = true;
1979
1979
  }
@@ -1982,7 +1982,7 @@ function randomWords(options) {
1982
1982
  return wordUsed;
1983
1983
  };
1984
1984
  const word = () => {
1985
- if (utils_1.is.number(options.maxLength)) {
1985
+ if (basic_utils_1.is.number(options.maxLength)) {
1986
1986
  return generateWordWithMaxLength();
1987
1987
  }
1988
1988
  else {
@@ -1992,21 +1992,21 @@ function randomWords(options) {
1992
1992
  if (!options || typeof options === "number") {
1993
1993
  return generateRandomWord();
1994
1994
  }
1995
- if (utils_1.is.boolean(options.exactly)) {
1995
+ if (basic_utils_1.is.boolean(options.exactly)) {
1996
1996
  options.min = 1;
1997
1997
  options.max = 1;
1998
1998
  }
1999
- if (!utils_1.is.number(options.wordsPerString)) {
1999
+ if (!basic_utils_1.is.number(options.wordsPerString)) {
2000
2000
  options.wordsPerString = 1;
2001
2001
  }
2002
2002
  if (typeof options.formatter !== "function") {
2003
2003
  options.formatter = (word) => word;
2004
2004
  }
2005
- if (!utils_1.is.string(options.separator)) {
2005
+ if (!basic_utils_1.is.string(options.separator)) {
2006
2006
  options.separator = " ";
2007
2007
  }
2008
2008
  let total = 0;
2009
- if (utils_1.is.number(options.min) && utils_1.is.number(options.max)) {
2009
+ if (basic_utils_1.is.number(options.min) && basic_utils_1.is.number(options.max)) {
2010
2010
  total = options.min + randInt(options.max + 1 - options.min);
2011
2011
  }
2012
2012
  let results = [];
@@ -2027,7 +2027,7 @@ function randomWords(options) {
2027
2027
  relativeIndex = 0;
2028
2028
  }
2029
2029
  }
2030
- if (utils_1.is.string(options.join)) {
2030
+ if (basic_utils_1.is.string(options.join)) {
2031
2031
  results = results.join(options.join);
2032
2032
  }
2033
2033
  return results;
@@ -2043,16 +2043,16 @@ function randomNumber(options) {
2043
2043
  }
2044
2044
  exports.randomNumber = randomNumber;
2045
2045
  function getDefaultsForRandomNumber(options) {
2046
- if (!utils_1.is.object(options)) {
2046
+ if (!basic_utils_1.is.object(options)) {
2047
2047
  options = {};
2048
2048
  }
2049
2049
  let min = options.min || 0;
2050
2050
  let max = options.max || 1;
2051
2051
  const integer = options.integer || false;
2052
- if (!utils_1.is.number(min, false)) {
2052
+ if (!basic_utils_1.is.number(min, false)) {
2053
2053
  min = max - 1;
2054
2054
  }
2055
- else if (!utils_1.is.number(max, false)) {
2055
+ else if (!basic_utils_1.is.number(max, false)) {
2056
2056
  max = min + 1;
2057
2057
  }
2058
2058
  if (max < min) {
@@ -1,12 +1,12 @@
1
- import { Collection } from "@elara-services/utils";
1
+ import { PossiblePromise } from "@elara-services/basic-utils";
2
2
  import { type Job } from "node-schedule";
3
- export type TaskCreateRun = (...args: unknown[]) => Promise<unknown> | unknown;
3
+ export type TaskCreateRun = (...args: unknown[]) => PossiblePromise<unknown>;
4
4
  export declare const Tasks: {
5
5
  create: ({ id, time, shouldCancel }: TaskCreate | undefined, run: TaskCreateRun) => string | Job;
6
6
  has: (id: string) => boolean;
7
7
  delete: (id: string) => boolean;
8
8
  cancelAll: () => void;
9
- list: () => Collection<string, Job>;
9
+ list: () => Map<string, Job>;
10
10
  dateFrom: (ms: number) => string;
11
11
  repeat: (id: string, ms: number, run: TaskCreateRun) => void;
12
12
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Tasks = void 0;
4
- const utils_1 = require("@elara-services/utils");
4
+ const basic_utils_1 = require("@elara-services/basic-utils");
5
5
  const node_schedule_1 = require("node-schedule");
6
6
  exports.Tasks = {
7
7
  create: ({ id, time, shouldCancel } = {
@@ -9,7 +9,7 @@ exports.Tasks = {
9
9
  time: "",
10
10
  shouldCancel: true,
11
11
  }, run) => {
12
- if (!utils_1.is.string(id) || !utils_1.is.string(time) || !utils_1.is.boolean(shouldCancel)) {
12
+ if (!basic_utils_1.is.string(id) || !basic_utils_1.is.string(time) || !basic_utils_1.is.boolean(shouldCancel)) {
13
13
  return `You failed to provide one of the following options: 'id', 'time' or 'shouldCancel'`;
14
14
  }
15
15
  if (node_schedule_1.scheduledJobs[id]) {
@@ -30,7 +30,7 @@ exports.Tasks = {
30
30
  }
31
31
  },
32
32
  list: () => {
33
- const list = new utils_1.Collection();
33
+ const list = new Map();
34
34
  for (const v of Object.keys(node_schedule_1.scheduledJobs)) {
35
35
  if (!node_schedule_1.scheduledJobs[v]) {
36
36
  continue;
@@ -42,14 +42,14 @@ exports.Tasks = {
42
42
  dateFrom: (ms) => new Date(Date.now() + ms).toISOString(),
43
43
  repeat: (id, ms, run) => {
44
44
  if (!id.startsWith("repeat-")) {
45
- id = `repeat-${id}-${utils_1.snowflakes.generate()}`;
45
+ id = `repeat-${id}-${basic_utils_1.snowflakes.generate()}`;
46
46
  }
47
47
  const schedule = () => exports.Tasks.create({
48
48
  id,
49
49
  time: exports.Tasks.dateFrom(ms),
50
50
  shouldCancel: true,
51
51
  }, () => {
52
- exports.Tasks.repeat(`${id.split("-").slice(0, 2).join("-")}-${utils_1.snowflakes.generate()}`, ms, run);
52
+ exports.Tasks.repeat(`${id.split("-").slice(0, 2).join("-")}-${basic_utils_1.snowflakes.generate()}`, ms, run);
53
53
  run();
54
54
  });
55
55
  schedule();