@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.
- package/dist/package.json +4 -6
- package/dist/src/interfaces/discord.d.ts +2 -2
- package/dist/src/lib/AES.js +16 -5
- package/dist/src/lib/discord.d.ts +1 -1
- package/dist/src/lib/discord.js +44 -44
- package/dist/src/lib/languages.js +2 -2
- package/dist/src/lib/misc.d.ts +21 -1
- package/dist/src/lib/misc.js +42 -71
- package/dist/src/lib/random.js +11 -11
- package/dist/src/lib/tasks.d.ts +3 -3
- package/dist/src/lib/tasks.js +5 -5
- package/docs/classes/AES.html +5 -5
- package/docs/classes/Minesweeper.html +11 -11
- package/docs/functions/fetch.html +8 -24
- package/docs/functions/randomNumber.html +1 -1
- package/docs/functions/randomWeight.html +1 -1
- package/docs/functions/randomWords.html +1 -1
- package/docs/interfaces/ButtonOptions.html +10 -10
- package/docs/interfaces/ModalOptions.html +8 -8
- package/docs/interfaces/RandomNumberOptions.html +4 -4
- package/docs/interfaces/RandomWord.html +9 -9
- package/docs/interfaces/SelectOptions.html +12 -12
- package/docs/interfaces/Slash.html +8 -8
- package/docs/interfaces/SlashOptions.html +14 -14
- package/docs/interfaces/TaskCreate.html +4 -4
- package/docs/interfaces/TextInputOptions.html +15 -15
- package/docs/types/ButtonNumberStyles.html +1 -1
- package/docs/types/ButtonStyles.html +1 -1
- package/docs/types/ChannelTypes.html +1 -1
- package/docs/types/Lang.html +1 -1
- package/docs/types/LangName.html +1 -1
- package/docs/types/TaskCreateRun.html +4 -4
- package/docs/variables/ButtonStyle.html +1 -1
- package/docs/variables/Duration.html +1 -1
- package/docs/variables/Interactions.html +6 -6
- package/docs/variables/Languages.html +2 -2
- package/docs/variables/SlashBuilder.html +1 -1
- package/docs/variables/Tasks.html +5 -5
- package/package.json +4 -6
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@elara-services/packages",
|
3
|
-
"version": "
|
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/
|
41
|
-
"
|
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 {
|
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:
|
39
|
+
components: ModalSubmitActionRowComponent[];
|
40
40
|
}[];
|
41
41
|
}
|
42
42
|
export interface TextInputOptions {
|
package/dist/src/lib/AES.js
CHANGED
@@ -1,37 +1,44 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.AES = void 0;
|
4
|
-
const
|
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
|
-
|
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 =
|
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 =
|
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").
|
43
|
+
components: import("discord-api-types/v10").ModalSubmitActionRowComponent[];
|
44
44
|
}[];
|
45
45
|
};
|
46
46
|
textInput: (options?: TextInputOptions, row?: boolean) => {
|
package/dist/src/lib/discord.js
CHANGED
@@ -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
|
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 (
|
61
|
+
if (basic_utils_1.is.string(options.id)) {
|
62
62
|
data.custom_id = options.id;
|
63
63
|
}
|
64
|
-
else if (
|
64
|
+
else if (basic_utils_1.is.string(options.custom_id)) {
|
65
65
|
data.custom_id = options.custom_id;
|
66
66
|
}
|
67
|
-
if (
|
67
|
+
if (basic_utils_1.is.string(options.placeholder)) {
|
68
68
|
data.placeholder = options.placeholder;
|
69
69
|
}
|
70
|
-
else if (
|
70
|
+
else if (basic_utils_1.is.string(options.holder)) {
|
71
71
|
data.placeholder = options.holder;
|
72
72
|
}
|
73
|
-
if (
|
73
|
+
if (basic_utils_1.is.number(options.max_values)) {
|
74
74
|
data.max_values = options.max_values;
|
75
75
|
}
|
76
|
-
else if (
|
76
|
+
else if (basic_utils_1.is.number(options.max)) {
|
77
77
|
data.max_values = options.max;
|
78
78
|
}
|
79
|
-
if (
|
79
|
+
if (basic_utils_1.is.number(options.min_values)) {
|
80
80
|
data.min_values = options.min_values;
|
81
81
|
}
|
82
|
-
else if (
|
82
|
+
else if (basic_utils_1.is.number(options.min)) {
|
83
83
|
data.min_values = options.min;
|
84
84
|
}
|
85
|
-
if (
|
85
|
+
if (basic_utils_1.is.boolean(options.disabled)) {
|
86
86
|
data.disabled = options.disabled;
|
87
87
|
}
|
88
|
-
if (
|
88
|
+
if (basic_utils_1.is.number(options.type)) {
|
89
89
|
data.type = options.type;
|
90
90
|
}
|
91
|
-
if (
|
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 (!
|
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 (
|
105
|
+
if (basic_utils_1.is.string(options.id)) {
|
106
106
|
data.custom_id = options.id;
|
107
107
|
}
|
108
|
-
else if (
|
108
|
+
else if (basic_utils_1.is.string(options.custom_id)) {
|
109
109
|
data.custom_id = options.custom_id;
|
110
110
|
}
|
111
|
-
if (
|
111
|
+
if (basic_utils_1.is.string(options.title)) {
|
112
112
|
data.title = options.title;
|
113
113
|
}
|
114
|
-
else if (
|
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 (
|
131
|
+
if (basic_utils_1.is.number(options.type)) {
|
132
132
|
data.type = options.type;
|
133
133
|
}
|
134
|
-
if (
|
134
|
+
if (basic_utils_1.is.string(options.id)) {
|
135
135
|
data.custom_id = options.id;
|
136
136
|
}
|
137
|
-
else if (
|
137
|
+
else if (basic_utils_1.is.string(options.custom_id)) {
|
138
138
|
data.custom_id = options.custom_id;
|
139
139
|
}
|
140
|
-
if (
|
140
|
+
if (basic_utils_1.is.string(options.label)) {
|
141
141
|
data.label = options.label;
|
142
142
|
}
|
143
|
-
else if (
|
143
|
+
else if (basic_utils_1.is.string(options.title)) {
|
144
144
|
data.label = options.title;
|
145
145
|
}
|
146
|
-
if (
|
146
|
+
if (basic_utils_1.is.string(options.placeholder)) {
|
147
147
|
data.placeholder = options.placeholder;
|
148
148
|
}
|
149
|
-
else if (
|
149
|
+
else if (basic_utils_1.is.string(options.holder)) {
|
150
150
|
data.placeholder = options.holder;
|
151
151
|
}
|
152
|
-
if (
|
152
|
+
if (basic_utils_1.is.boolean(options.required)) {
|
153
153
|
data.required = options.required;
|
154
154
|
}
|
155
|
-
if (
|
155
|
+
if (basic_utils_1.is.string(options.value)) {
|
156
156
|
data.value = options.value;
|
157
157
|
}
|
158
|
-
if (
|
158
|
+
if (basic_utils_1.is.number(options.style)) {
|
159
159
|
data.style = options.style;
|
160
160
|
}
|
161
|
-
if (
|
161
|
+
if (basic_utils_1.is.number(options.min)) {
|
162
162
|
data.min_length = options.min;
|
163
163
|
}
|
164
|
-
else if (
|
164
|
+
else if (basic_utils_1.is.number(options.min_length)) {
|
165
165
|
data.min_length = options.min_length;
|
166
166
|
}
|
167
|
-
if (
|
167
|
+
if (basic_utils_1.is.number(options.max)) {
|
168
168
|
data.max_length = options.max;
|
169
169
|
}
|
170
|
-
else if (
|
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
|
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
|
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
|
223
|
+
return basic_utils_1.get.hrs(1);
|
224
224
|
case "d":
|
225
225
|
case "day":
|
226
226
|
case "days":
|
227
|
-
return
|
227
|
+
return basic_utils_1.get.days(1);
|
228
228
|
case "w":
|
229
229
|
case "week":
|
230
230
|
case "weeks":
|
231
|
-
return 7
|
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 *
|
235
|
+
return 30 * 24 * 60 * 60000;
|
236
236
|
case "y":
|
237
237
|
case "year":
|
238
238
|
case "years":
|
239
|
-
return 365 * 24 * 60 *
|
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 (
|
358
|
+
if (basic_utils_1.is.array(options.options)) {
|
359
359
|
obj["options"] = options.options;
|
360
360
|
}
|
361
|
-
if (
|
361
|
+
if (basic_utils_1.is.number(options.type)) {
|
362
362
|
obj.type = options.type;
|
363
363
|
}
|
364
|
-
if ("dmPermission" in options &&
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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,
|
115
|
+
for (const key of (0, basic_utils_1.getKeys)(langs)) {
|
116
116
|
if (key === name) {
|
117
117
|
return key;
|
118
118
|
}
|
package/dist/src/lib/misc.d.ts
CHANGED
@@ -1 +1,21 @@
|
|
1
|
-
|
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 {};
|
package/dist/src/lib/misc.js
CHANGED
@@ -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
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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 (
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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;
|
package/dist/src/lib/random.js
CHANGED
@@ -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
|
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 (
|
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 (
|
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 (
|
1995
|
+
if (basic_utils_1.is.boolean(options.exactly)) {
|
1996
1996
|
options.min = 1;
|
1997
1997
|
options.max = 1;
|
1998
1998
|
}
|
1999
|
-
if (!
|
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 (!
|
2005
|
+
if (!basic_utils_1.is.string(options.separator)) {
|
2006
2006
|
options.separator = " ";
|
2007
2007
|
}
|
2008
2008
|
let total = 0;
|
2009
|
-
if (
|
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 (
|
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 (!
|
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 (!
|
2052
|
+
if (!basic_utils_1.is.number(min, false)) {
|
2053
2053
|
min = max - 1;
|
2054
2054
|
}
|
2055
|
-
else if (!
|
2055
|
+
else if (!basic_utils_1.is.number(max, false)) {
|
2056
2056
|
max = min + 1;
|
2057
2057
|
}
|
2058
2058
|
if (max < min) {
|
package/dist/src/lib/tasks.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { PossiblePromise } from "@elara-services/basic-utils";
|
2
2
|
import { type Job } from "node-schedule";
|
3
|
-
export type TaskCreateRun = (...args: 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: () =>
|
9
|
+
list: () => Map<string, Job>;
|
10
10
|
dateFrom: (ms: number) => string;
|
11
11
|
repeat: (id: string, ms: number, run: TaskCreateRun) => void;
|
12
12
|
};
|
package/dist/src/lib/tasks.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Tasks = void 0;
|
4
|
-
const
|
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 (!
|
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
|
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}-${
|
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("-")}-${
|
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();
|