@20syldev/api 4.7.0 → 4.9.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 (191) hide show
  1. package/README.md +84 -47
  2. package/dist/app.js +6 -6
  3. package/dist/app.js.map +1 -1
  4. package/dist/config/env.js.map +1 -1
  5. package/dist/config/versions.js +22 -3
  6. package/dist/config/versions.js.map +1 -1
  7. package/dist/constants.js +27 -12
  8. package/dist/constants.js.map +1 -1
  9. package/dist/middleware/error.js +2 -2
  10. package/dist/middleware/error.js.map +1 -1
  11. package/dist/middleware/logger.js.map +1 -1
  12. package/dist/middleware/ratelimit.js +2 -2
  13. package/dist/middleware/ratelimit.js.map +1 -1
  14. package/dist/middleware/version.js.map +1 -1
  15. package/dist/modules/v3.js +1 -1
  16. package/dist/modules/v3.js.map +1 -1
  17. package/{src/modules/v4/address.ts → dist/modules/v4/address.js} +14 -46
  18. package/dist/modules/v4/address.js.map +1 -0
  19. package/{src/modules/v4/agent.ts → dist/modules/v4/agent.js} +26 -38
  20. package/dist/modules/v4/agent.js.map +1 -0
  21. package/dist/modules/v4/algorithms.js +79 -0
  22. package/dist/modules/v4/algorithms.js.map +1 -1
  23. package/dist/modules/v4/avatar.js +136 -0
  24. package/dist/modules/v4/avatar.js.map +1 -0
  25. package/dist/modules/v4/barcode.js +440 -0
  26. package/dist/modules/v4/barcode.js.map +1 -0
  27. package/dist/modules/v4/captcha.js +7 -0
  28. package/dist/modules/v4/captcha.js.map +1 -1
  29. package/dist/modules/v4/chat.js +9 -1
  30. package/dist/modules/v4/chat.js.map +1 -1
  31. package/dist/modules/v4/color.js +8 -1
  32. package/dist/modules/v4/color.js.map +1 -1
  33. package/dist/modules/v4/convert.js +9 -0
  34. package/dist/modules/v4/convert.js.map +1 -1
  35. package/dist/modules/v4/credit.js +104 -0
  36. package/dist/modules/v4/credit.js.map +1 -0
  37. package/dist/modules/v4/cron.js +202 -0
  38. package/dist/modules/v4/cron.js.map +1 -0
  39. package/dist/modules/v4/dice.js +7 -0
  40. package/dist/modules/v4/dice.js.map +1 -1
  41. package/dist/modules/v4/domain.js +6 -1
  42. package/dist/modules/v4/domain.js.map +1 -1
  43. package/dist/modules/v4/encode.js +71 -0
  44. package/dist/modules/v4/encode.js.map +1 -1
  45. package/dist/modules/v4/geo.js +11 -1
  46. package/dist/modules/v4/geo.js.map +1 -1
  47. package/dist/modules/v4/hash.js +10 -1
  48. package/dist/modules/v4/hash.js.map +1 -1
  49. package/dist/modules/v4/hyperplanning.js +9 -1
  50. package/dist/modules/v4/hyperplanning.js.map +1 -1
  51. package/{src/modules/v4/ip.ts → dist/modules/v4/ip.js} +58 -60
  52. package/dist/modules/v4/ip.js.map +1 -0
  53. package/dist/modules/v4/levenshtein.js +8 -0
  54. package/dist/modules/v4/levenshtein.js.map +1 -1
  55. package/dist/modules/v4/palette.js +9 -1
  56. package/dist/modules/v4/palette.js.map +1 -1
  57. package/{src/modules/v4/password.ts → dist/modules/v4/password.js} +25 -63
  58. package/dist/modules/v4/password.js.map +1 -0
  59. package/dist/modules/v4/personal.js +14 -18
  60. package/dist/modules/v4/personal.js.map +1 -1
  61. package/dist/modules/v4/placeholder.js +8 -0
  62. package/dist/modules/v4/placeholder.js.map +1 -1
  63. package/dist/modules/v4/qrcode.js +10 -3
  64. package/dist/modules/v4/qrcode.js.map +1 -1
  65. package/dist/modules/v4/regex.js +48 -0
  66. package/dist/modules/v4/regex.js.map +1 -0
  67. package/dist/modules/v4/statistics.js +7 -0
  68. package/dist/modules/v4/statistics.js.map +1 -1
  69. package/dist/modules/v4/text.js +30 -0
  70. package/dist/modules/v4/text.js.map +1 -1
  71. package/dist/modules/v4/tic_tac_toe.js +9 -1
  72. package/dist/modules/v4/tic_tac_toe.js.map +1 -1
  73. package/dist/modules/v4/time.js +62 -11
  74. package/dist/modules/v4/time.js.map +1 -1
  75. package/dist/modules/v4/token.js +17 -8
  76. package/dist/modules/v4/token.js.map +1 -1
  77. package/dist/modules/v4/username.js +5 -0
  78. package/dist/modules/v4/username.js.map +1 -1
  79. package/dist/modules/v4/validate.js +21 -0
  80. package/dist/modules/v4/validate.js.map +1 -1
  81. package/dist/modules/v4.js +10 -1
  82. package/dist/modules/v4.js.map +1 -1
  83. package/dist/routes/delete.js.map +1 -1
  84. package/dist/routes/get.js +208 -48
  85. package/dist/routes/get.js.map +1 -1
  86. package/dist/routes/index.js +2 -2
  87. package/dist/routes/index.js.map +1 -1
  88. package/dist/routes/patch.js.map +1 -1
  89. package/dist/routes/post.js +2 -2
  90. package/dist/routes/post.js.map +1 -1
  91. package/dist/utils/response.js.map +1 -1
  92. package/package.json +2 -1
  93. package/.github/FUNDING.yml +0 -1
  94. package/.prettierrc +0 -7
  95. package/eslint.config.js +0 -24
  96. package/robots.txt +0 -74
  97. package/src/app.ts +0 -53
  98. package/src/config/env.ts +0 -87
  99. package/src/config/plans.ts +0 -61
  100. package/src/config/versions.ts +0 -119
  101. package/src/constants.ts +0 -46
  102. package/src/favicon.ico +0 -0
  103. package/src/middleware/cors.ts +0 -23
  104. package/src/middleware/error.ts +0 -16
  105. package/src/middleware/json.ts +0 -9
  106. package/src/middleware/logger.ts +0 -32
  107. package/src/middleware/ratelimit.ts +0 -89
  108. package/src/middleware/version.ts +0 -40
  109. package/src/modules/v3/algorithms.js +0 -218
  110. package/src/modules/v3/captcha.js +0 -60
  111. package/src/modules/v3/chat.js +0 -111
  112. package/src/modules/v3/color.js +0 -60
  113. package/src/modules/v3/convert.js +0 -39
  114. package/src/modules/v3/domain.js +0 -86
  115. package/src/modules/v3/hash.js +0 -16
  116. package/src/modules/v3/hyperplanning.js +0 -56
  117. package/src/modules/v3/levenshtein.js +0 -46
  118. package/src/modules/v3/personal.js +0 -139
  119. package/src/modules/v3/qrcode.js +0 -20
  120. package/src/modules/v3/tic_tac_toe.js +0 -242
  121. package/src/modules/v3/time.js +0 -98
  122. package/src/modules/v3/token.js +0 -54
  123. package/src/modules/v3/username.js +0 -94
  124. package/src/modules/v3/utils.js +0 -77
  125. package/src/modules/v3.js +0 -15
  126. package/src/modules/v4/algorithms.ts +0 -276
  127. package/src/modules/v4/captcha.ts +0 -114
  128. package/src/modules/v4/chat.ts +0 -130
  129. package/src/modules/v4/color.ts +0 -75
  130. package/src/modules/v4/convert.ts +0 -127
  131. package/src/modules/v4/dice.ts +0 -46
  132. package/src/modules/v4/domain.ts +0 -86
  133. package/src/modules/v4/encode.ts +0 -241
  134. package/src/modules/v4/geo.ts +0 -63
  135. package/src/modules/v4/hash.ts +0 -32
  136. package/src/modules/v4/hyperplanning.ts +0 -93
  137. package/src/modules/v4/levenshtein.ts +0 -46
  138. package/src/modules/v4/palette.ts +0 -71
  139. package/src/modules/v4/personal.ts +0 -140
  140. package/src/modules/v4/placeholder.ts +0 -197
  141. package/src/modules/v4/qrcode.ts +0 -121
  142. package/src/modules/v4/statistics.ts +0 -62
  143. package/src/modules/v4/text.ts +0 -330
  144. package/src/modules/v4/tic_tac_toe.ts +0 -264
  145. package/src/modules/v4/time.ts +0 -103
  146. package/src/modules/v4/token.ts +0 -53
  147. package/src/modules/v4/username.ts +0 -94
  148. package/src/modules/v4/validate.ts +0 -76
  149. package/src/modules/v4.ts +0 -27
  150. package/src/routes/delete.ts +0 -72
  151. package/src/routes/get.ts +0 -835
  152. package/src/routes/index.ts +0 -59
  153. package/src/routes/patch.ts +0 -45
  154. package/src/routes/post.ts +0 -209
  155. package/src/storage/index.ts +0 -16
  156. package/src/types/express.d.ts +0 -17
  157. package/src/types/storage.ts +0 -48
  158. package/src/utils/colors.ts +0 -91
  159. package/src/utils/helpers.ts +0 -90
  160. package/src/utils/response.ts +0 -28
  161. package/tests/integration/api.test.ts +0 -716
  162. package/tests/tsconfig.json +0 -3
  163. package/tests/unit/address.test.ts +0 -84
  164. package/tests/unit/agent.test.ts +0 -113
  165. package/tests/unit/algorithms.test.ts +0 -121
  166. package/tests/unit/captcha.test.ts +0 -62
  167. package/tests/unit/chat.test.ts +0 -54
  168. package/tests/unit/color.test.ts +0 -54
  169. package/tests/unit/convert.test.ts +0 -68
  170. package/tests/unit/dice.test.ts +0 -58
  171. package/tests/unit/domain.test.ts +0 -48
  172. package/tests/unit/encode.test.ts +0 -109
  173. package/tests/unit/geo.test.ts +0 -46
  174. package/tests/unit/hash.test.ts +0 -45
  175. package/tests/unit/hyperplanning.test.ts +0 -97
  176. package/tests/unit/ip.test.ts +0 -140
  177. package/tests/unit/levenshtein.test.ts +0 -35
  178. package/tests/unit/palette.test.ts +0 -54
  179. package/tests/unit/password.test.ts +0 -86
  180. package/tests/unit/personal.test.ts +0 -66
  181. package/tests/unit/placeholder.test.ts +0 -58
  182. package/tests/unit/qrcode.test.ts +0 -83
  183. package/tests/unit/statistics.test.ts +0 -58
  184. package/tests/unit/text.test.ts +0 -108
  185. package/tests/unit/tic_tac_toe.test.ts +0 -56
  186. package/tests/unit/time.test.ts +0 -68
  187. package/tests/unit/token.test.ts +0 -62
  188. package/tests/unit/username.test.ts +0 -35
  189. package/tests/unit/validate.test.ts +0 -72
  190. package/tsconfig.json +0 -17
  191. package/tsconfig.test.json +0 -9
@@ -1,53 +0,0 @@
1
- import { randomBytes, randomInt } from 'crypto';
2
- import { v4 } from 'uuid';
3
-
4
- import { MAX_TOKEN_LENGTH, MIN_TOKEN_LENGTH } from '../../constants.js';
5
-
6
- /**
7
- * Generates a cryptographically random token of the specified length and type.
8
- *
9
- * @param len - Token length (must be between 12 and 4096)
10
- * @param type - Character set to use: "alpha", "alphanum", "base64", "hex", "num", "punct", "urlsafe", or "uuid"
11
- * @returns The generated token string
12
- * @throws Error if length is out of range or the type is not valid
13
- */
14
- export default function token(len: number, type: string = 'alphanum'): string {
15
- if (isNaN(len) || len < MIN_TOKEN_LENGTH) {
16
- throw new Error('Length must be a number greater than or equal to 12');
17
- }
18
-
19
- if (len > MAX_TOKEN_LENGTH) {
20
- throw new Error('Length cannot exceed 4096');
21
- }
22
-
23
- const genToken = (chars: string, length: number): string =>
24
- Array.from({ length }, () => chars[randomInt(chars.length)]).join('');
25
-
26
- const tokenTypes: Record<string, () => string> = {
27
- alpha: () => genToken('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', len),
28
- alphanum: () => genToken('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', len),
29
- base64: () =>
30
- randomBytes(Math.ceil(len * 0.75))
31
- .toString('base64')
32
- .slice(0, len),
33
- hex: () =>
34
- randomBytes(Math.ceil(len * 0.5))
35
- .toString('hex')
36
- .slice(0, len),
37
- num: () => genToken('0123456789', len),
38
- punct: () => genToken('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~', len),
39
- urlsafe: () => genToken('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_', len),
40
- uuid: () => {
41
- let result = '';
42
- while (result.length < len) result += v4().replace(/-/g, '');
43
- return result.slice(0, len);
44
- },
45
- };
46
-
47
- const lowerType = type.toLowerCase();
48
- if (!tokenTypes[lowerType]) {
49
- throw new Error(`Invalid token type. Valid types: ${Object.keys(tokenTypes).join(', ')}`);
50
- }
51
-
52
- return tokenTypes[lowerType]!();
53
- }
@@ -1,94 +0,0 @@
1
- import { random, randomNumber } from '../../utils/helpers.js';
2
-
3
- /**
4
- * Generates a random username combining adjectives, animals, and job titles.
5
- *
6
- * @returns Object containing the generated username, the number used, and the components (adjective, animal, job)
7
- */
8
- export default function username(): Record<string, unknown> {
9
- const adj = [
10
- 'Happy',
11
- 'Silly',
12
- 'Clever',
13
- 'Creative',
14
- 'Brave',
15
- 'Gentle',
16
- 'Kind',
17
- 'Funny',
18
- 'Wise',
19
- 'Charming',
20
- 'Sincere',
21
- 'Resourceful',
22
- 'Patient',
23
- 'Energetic',
24
- 'Adventurous',
25
- 'Ambitious',
26
- 'Courageous',
27
- 'Courteous',
28
- 'Determined',
29
- ];
30
- const ani = [
31
- 'Cat',
32
- 'Dog',
33
- 'Tiger',
34
- 'Elephant',
35
- 'Monkey',
36
- 'Penguin',
37
- 'Dolphin',
38
- 'Lion',
39
- 'Bear',
40
- 'Fox',
41
- 'Owl',
42
- 'Giraffe',
43
- 'Zebra',
44
- 'Koala',
45
- 'Rabbit',
46
- 'Squirrel',
47
- 'Panda',
48
- 'Horse',
49
- 'Wolf',
50
- 'Eagle',
51
- ];
52
- const job = [
53
- 'Writer',
54
- 'Artist',
55
- 'Musician',
56
- 'Explorer',
57
- 'Scientist',
58
- 'Engineer',
59
- 'Athlete',
60
- 'Chef',
61
- 'Doctor',
62
- 'Teacher',
63
- 'Lawyer',
64
- 'Entrepreneur',
65
- 'Actor',
66
- 'Dancer',
67
- 'Photographer',
68
- 'Architect',
69
- 'Pilot',
70
- 'Designer',
71
- 'Journalist',
72
- 'Veterinarian',
73
- ];
74
-
75
- const nombre = randomNumber(0, 99);
76
- const choix: Record<string, () => string> = {
77
- adj_num: () => random(adj) + nombre,
78
- ani_num: () => random(ani) + nombre,
79
- pro_num: () => random(job) + nombre,
80
- adj_ani: () => random(adj) + random(ani),
81
- adj_ani_num: () => random(adj) + random(ani) + nombre,
82
- adj_pro: () => random(adj) + random(job),
83
- pro_ani: () => random(job) + random(ani),
84
- pro_ani_num: () => random(job) + random(ani) + nombre,
85
- };
86
-
87
- return {
88
- username: choix[random(Object.keys(choix))]!(),
89
- number: nombre,
90
- adjective: random(adj),
91
- animal: random(ani),
92
- job: random(job),
93
- };
94
- }
@@ -1,76 +0,0 @@
1
- import { MAX_STRING_LENGTH } from '../../constants.js';
2
-
3
- function checkValue(value: string): void {
4
- if (!value) throw new Error('A value is required');
5
- if (typeof value !== 'string') throw new Error('Value must be a string');
6
- if (value.length > MAX_STRING_LENGTH)
7
- throw new Error(`Value must be less than ${MAX_STRING_LENGTH} characters long`);
8
- }
9
-
10
- /**
11
- * Validates a credit/debit card number using the Luhn algorithm.
12
- *
13
- * @param value - Card number string (digits, spaces, or dashes allowed)
14
- * @returns Object containing the validity result and the sanitized digit string
15
- * @throws Error if value is missing, contains non-digit characters, or has an invalid length
16
- */
17
- export function luhn(value: string): { valid: boolean; value: string } {
18
- checkValue(value);
19
- const digits = value.replace(/\s|-/g, '');
20
- if (!/^\d+$/.test(digits)) throw new Error('Value must contain only digits, spaces or dashes');
21
- if (digits.length < 12 || digits.length > 19) throw new Error('Card number must have between 12 and 19 digits');
22
-
23
- let sum = 0;
24
- let alt = false;
25
- for (let i = digits.length - 1; i >= 0; i--) {
26
- let n = parseInt(digits[i]!, 10);
27
- if (alt) {
28
- n *= 2;
29
- if (n > 9) n -= 9;
30
- }
31
- sum += n;
32
- alt = !alt;
33
- }
34
-
35
- return { valid: sum % 10 === 0, value: digits };
36
- }
37
-
38
- /**
39
- * Validates an IBAN using the mod-97 checksum algorithm.
40
- *
41
- * @param value - IBAN string (spaces allowed)
42
- * @returns Object containing the validity result, sanitized IBAN, and country code
43
- * @throws Error if value is missing, has an invalid format, or is out of length bounds
44
- */
45
- export function iban(value: string): { valid: boolean; value: string; country?: string } {
46
- checkValue(value);
47
- const cleaned = value.replace(/\s/g, '').toUpperCase();
48
- if (!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(cleaned)) throw new Error('Invalid IBAN format');
49
- if (cleaned.length < 15 || cleaned.length > 34) throw new Error('IBAN length must be between 15 and 34 characters');
50
-
51
- const rearranged = cleaned.slice(4) + cleaned.slice(0, 4);
52
- const numeric = rearranged
53
- .split('')
54
- .map((c) => (c >= 'A' && c <= 'Z' ? (c.charCodeAt(0) - 55).toString() : c))
55
- .join('');
56
-
57
- let remainder = 0;
58
- for (const char of numeric) {
59
- remainder = (remainder * 10 + parseInt(char, 10)) % 97;
60
- }
61
-
62
- return { valid: remainder === 1, value: cleaned, country: cleaned.slice(0, 2) };
63
- }
64
-
65
- /**
66
- * Validates an email address against a basic format check.
67
- *
68
- * @param value - The email address string to validate
69
- * @returns Object containing the validity result and the original value
70
- * @throws Error if value is missing, not a string, or too long
71
- */
72
- export function email(value: string): { valid: boolean; value: string } {
73
- checkValue(value);
74
- const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
75
- return { valid: regex.test(value), value };
76
- }
package/src/modules/v4.ts DELETED
@@ -1,27 +0,0 @@
1
- export { default as address } from './v4/address.js';
2
- export { default as agent } from './v4/agent.js';
3
- export * as algorithms from './v4/algorithms.js';
4
- export { default as captcha } from './v4/captcha.js';
5
- export { default as chat } from './v4/chat.js';
6
- export { default as color } from './v4/color.js';
7
- export { default as convert } from './v4/convert.js';
8
- export { default as dice } from './v4/dice.js';
9
- export { default as domain } from './v4/domain.js';
10
- export * as encode from './v4/encode.js';
11
- export { default as geo } from './v4/geo.js';
12
- export { default as hash } from './v4/hash.js';
13
- export { default as hyperplanning } from './v4/hyperplanning.js';
14
- export { default as ip } from './v4/ip.js';
15
- export { default as levenshtein } from './v4/levenshtein.js';
16
- export { default as palette } from './v4/palette.js';
17
- export { default as password } from './v4/password.js';
18
- export { default as personal } from './v4/personal.js';
19
- export { default as placeholder } from './v4/placeholder.js';
20
- export { default as qrcode } from './v4/qrcode.js';
21
- export { default as statistics } from './v4/statistics.js';
22
- export * as text from './v4/text.js';
23
- export { default as tic_tac_toe } from './v4/tic_tac_toe.js';
24
- export { default as time } from './v4/time.js';
25
- export { default as token } from './v4/token.js';
26
- export { default as username } from './v4/username.js';
27
- export * as validate from './v4/validate.js';
@@ -1,72 +0,0 @@
1
- import { type Request, type Response, Router } from 'express';
2
-
3
- import { chatStorage, ticTacToeStorage } from '../storage/index.js';
4
- import { error } from '../utils/response.js';
5
-
6
- const router = Router();
7
-
8
- // Clear a private chat
9
- router.delete('/:version/chat/:token', (req: Request, res: Response) => {
10
- if (req.version !== 'v4') {
11
- error(res, 405, 'DELETE is only supported in v4+.', `${req.version}/chat`);
12
- return;
13
- }
14
-
15
- const token = req.params.token as string;
16
- const { username, session } = (req.body as Record<string, string>) || {};
17
-
18
- if (!username) {
19
- error(res, 400, 'Please provide a username (?username={username})');
20
- return;
21
- }
22
- if (!session) {
23
- error(res, 400, 'Please provide a valid session ID (&session={ID})');
24
- return;
25
- }
26
-
27
- try {
28
- const result = req.module.chat('clear', {
29
- username,
30
- token,
31
- session,
32
- storage: chatStorage,
33
- });
34
- res.jsonResponse(result);
35
- } catch (err) {
36
- error(res, 400, (err as Error).message);
37
- }
38
- });
39
-
40
- // Forfeit a tic-tac-toe game
41
- router.delete('/:version/tic-tac-toe/:game', (req: Request, res: Response) => {
42
- if (req.version !== 'v4') {
43
- error(res, 405, 'DELETE is only supported in v4+.', `${req.version}/tic-tac-toe`);
44
- return;
45
- }
46
-
47
- const game = req.params.game as string;
48
- const { username, session } = (req.body as Record<string, string>) || {};
49
-
50
- if (!username) {
51
- error(res, 400, 'Please provide a username (?username={username})');
52
- return;
53
- }
54
- if (!session) {
55
- error(res, 400, 'Please provide a valid session ID (&session={ID})');
56
- return;
57
- }
58
-
59
- try {
60
- const result = req.module.tic_tac_toe('forfeit', {
61
- username,
62
- session,
63
- game,
64
- storage: ticTacToeStorage,
65
- });
66
- res.jsonResponse(result);
67
- } catch (err) {
68
- error(res, 400, (err as Error).message);
69
- }
70
- });
71
-
72
- export default router;