@20syldev/api 5.6.0 → 5.7.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 (129) hide show
  1. package/.prettierignore +5 -0
  2. package/README.md +204 -80
  3. package/dist/app.d.ts +2 -0
  4. package/dist/config/env.d.ts +21 -0
  5. package/dist/config/env.js +10 -2
  6. package/dist/config/env.js.map +1 -1
  7. package/dist/config/plans.d.ts +26 -0
  8. package/dist/config/versions.d.ts +18 -0
  9. package/dist/constants.d.ts +39 -0
  10. package/dist/constants.js +0 -1
  11. package/dist/constants.js.map +1 -1
  12. package/dist/middleware/cors.d.ts +2 -0
  13. package/dist/middleware/cors.js +2 -1
  14. package/dist/middleware/cors.js.map +1 -1
  15. package/dist/middleware/error.d.ts +4 -0
  16. package/dist/middleware/json.d.ts +2 -0
  17. package/dist/middleware/logger.d.ts +26 -0
  18. package/dist/middleware/logger.js +34 -1
  19. package/dist/middleware/logger.js.map +1 -1
  20. package/dist/middleware/ratelimit.d.ts +2 -0
  21. package/dist/middleware/version.d.ts +3 -0
  22. package/dist/middleware/version.js +2 -2
  23. package/dist/middleware/version.js.map +1 -1
  24. package/dist/modules/v3/algorithms.d.ts +82 -0
  25. package/dist/modules/v3/captcha.d.ts +8 -0
  26. package/dist/modules/v3/chat.d.ts +9 -0
  27. package/dist/modules/v3/chat.js +3 -3
  28. package/dist/modules/v3/chat.js.map +1 -1
  29. package/dist/modules/v3/color.d.ts +6 -0
  30. package/dist/modules/v3/convert.d.ts +10 -0
  31. package/dist/modules/v3/domain.d.ts +6 -0
  32. package/dist/modules/v3/hash.d.ts +8 -0
  33. package/dist/modules/v3/hyperplanning.d.ts +9 -0
  34. package/dist/modules/v3/levenshtein.d.ts +9 -0
  35. package/dist/modules/v3/personal.d.ts +6 -0
  36. package/dist/modules/v3/qrcode.d.ts +8 -0
  37. package/dist/modules/v3/tic_tac_toe.d.ts +9 -0
  38. package/dist/modules/v3/tic_tac_toe.js +3 -3
  39. package/dist/modules/v3/tic_tac_toe.js.map +1 -1
  40. package/dist/modules/v3/time.d.ts +12 -0
  41. package/dist/modules/v3/token.d.ts +9 -0
  42. package/dist/modules/v3/username.d.ts +6 -0
  43. package/dist/modules/v3/utils.d.ts +50 -0
  44. package/dist/modules/v3.d.ts +15 -0
  45. package/dist/modules/v4/address.d.ts +20 -0
  46. package/dist/modules/v4/agent.d.ts +30 -0
  47. package/dist/modules/v4/algorithms.d.ts +90 -0
  48. package/dist/modules/v4/avatar.d.ts +23 -0
  49. package/dist/modules/v4/barcode.d.ts +27 -0
  50. package/dist/modules/v4/captcha.d.ts +22 -0
  51. package/dist/modules/v4/chat.d.ts +21 -0
  52. package/dist/modules/v4/chat.js +3 -3
  53. package/dist/modules/v4/chat.js.map +1 -1
  54. package/dist/modules/v4/color.d.ts +16 -0
  55. package/dist/modules/v4/convert.d.ts +15 -0
  56. package/dist/modules/v4/credit.d.ts +22 -0
  57. package/dist/modules/v4/cron.d.ts +17 -0
  58. package/dist/modules/v4/dice.d.ts +16 -0
  59. package/dist/modules/v4/domain.d.ts +6 -0
  60. package/dist/modules/v4/encode.d.ts +81 -0
  61. package/dist/modules/v4/geo.d.ts +30 -0
  62. package/dist/modules/v4/hash.d.ts +15 -0
  63. package/dist/modules/v4/hyperplanning.d.ts +19 -0
  64. package/dist/modules/v4/ip.d.ts +19 -0
  65. package/dist/modules/v4/levenshtein.d.ts +13 -0
  66. package/dist/modules/v4/palette.d.ts +19 -0
  67. package/dist/modules/v4/password.d.ts +25 -0
  68. package/dist/modules/v4/personal.d.ts +6 -0
  69. package/dist/modules/v4/placeholder.d.ts +30 -0
  70. package/dist/modules/v4/qrcode.d.ts +25 -0
  71. package/dist/modules/v4/regex.d.ts +23 -0
  72. package/dist/modules/v4/statistics.d.ts +20 -0
  73. package/dist/modules/v4/text.d.ts +43 -0
  74. package/dist/modules/v4/tic_tac_toe.d.ts +19 -0
  75. package/dist/modules/v4/tic_tac_toe.js +3 -3
  76. package/dist/modules/v4/tic_tac_toe.js.map +1 -1
  77. package/dist/modules/v4/time.d.ts +15 -0
  78. package/dist/modules/v4/token.d.ts +9 -0
  79. package/dist/modules/v4/username.d.ts +6 -0
  80. package/dist/modules/v4/validate.d.ts +34 -0
  81. package/dist/modules/v4.d.ts +32 -0
  82. package/dist/modules/v5/address.d.ts +5 -0
  83. package/dist/modules/v5/algorithms.d.ts +9 -0
  84. package/dist/modules/v5/asymmetric.d.ts +26 -0
  85. package/dist/modules/v5/barcode.d.ts +27 -0
  86. package/dist/modules/v5/case.d.ts +10 -0
  87. package/dist/modules/v5/chart.d.ts +53 -0
  88. package/dist/modules/v5/chat.d.ts +21 -0
  89. package/dist/modules/v5/chat.js +3 -3
  90. package/dist/modules/v5/chat.js.map +1 -1
  91. package/dist/modules/v5/csv.d.ts +29 -0
  92. package/dist/modules/v5/evaluate.d.ts +14 -0
  93. package/dist/modules/v5/jwt.d.ts +11 -0
  94. package/dist/modules/v5/matrix.d.ts +77 -0
  95. package/dist/modules/v5/otp.d.ts +30 -0
  96. package/dist/modules/v5/symmetric.d.ts +15 -0
  97. package/dist/modules/v5/text.d.ts +5 -0
  98. package/dist/modules/v5/tic_tac_toe.d.ts +19 -0
  99. package/dist/modules/v5/tic_tac_toe.js +3 -3
  100. package/dist/modules/v5/tic_tac_toe.js.map +1 -1
  101. package/dist/modules/v5/url.d.ts +18 -0
  102. package/dist/modules/v5/url.js +12 -3
  103. package/dist/modules/v5/url.js.map +1 -1
  104. package/dist/modules/v5.d.ts +17 -0
  105. package/dist/routes/delete.d.ts +2 -0
  106. package/dist/routes/delete.js +2 -2
  107. package/dist/routes/delete.js.map +1 -1
  108. package/dist/routes/get.d.ts +2 -0
  109. package/dist/routes/get.js +84 -85
  110. package/dist/routes/get.js.map +1 -1
  111. package/dist/routes/index.d.ts +2 -0
  112. package/dist/routes/index.js +8 -4
  113. package/dist/routes/index.js.map +1 -1
  114. package/dist/routes/patch.d.ts +2 -0
  115. package/dist/routes/patch.js +1 -1
  116. package/dist/routes/patch.js.map +1 -1
  117. package/dist/routes/post.d.ts +2 -0
  118. package/dist/routes/post.js +32 -32
  119. package/dist/routes/post.js.map +1 -1
  120. package/dist/storage/index.d.ts +4 -0
  121. package/dist/types/storage.d.ts +49 -0
  122. package/dist/utils/colors.d.ts +44 -0
  123. package/dist/utils/helpers.d.ts +55 -0
  124. package/dist/utils/response.d.ts +9 -0
  125. package/dist/utils/response.js +2 -4
  126. package/dist/utils/response.js.map +1 -1
  127. package/package.json +17 -16
  128. package/robots.txt +74 -0
  129. package/src/favicon.ico +0 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Tracks requests per user and throws if the rate limit is exceeded.
3
+ *
4
+ * @param rateLimits - Store of timestamps per user
5
+ * @param userId - Identifier of the requesting user
6
+ * @param timestamp - Current timestamp in milliseconds
7
+ * @param window - Time window in milliseconds
8
+ * @param limit - Maximum requests allowed in the window
9
+ * @returns false if within limits
10
+ * @throws Error if rate limit is exceeded
11
+ */
12
+ export declare function checkRateLimit(rateLimits: Record<string, number[]>, userId: string, timestamp: number, window?: number, limit?: number): boolean;
13
+ /**
14
+ * Parses a space-separated environment variable into an array.
15
+ *
16
+ * @param key - The environment variable name
17
+ * @returns The parsed array, or null if not set
18
+ */
19
+ export declare function envList(key: string): string[] | null;
20
+ /**
21
+ * Formats a Date to ISO string without timezone suffix.
22
+ *
23
+ * @param date - The date to format
24
+ * @returns ISO-formatted string without trailing Z
25
+ */
26
+ export declare function formatDate(date: Date): string;
27
+ /**
28
+ * Generates a random IPv4 address.
29
+ *
30
+ * @returns A string in the format "X.X.X.X"
31
+ */
32
+ export declare function genIP(): string;
33
+ /**
34
+ * Returns a random element from an array.
35
+ *
36
+ * @param arr - The source array
37
+ * @returns A random element
38
+ */
39
+ export declare function random<T>(arr: T[]): T;
40
+ /**
41
+ * Returns a random integer between min and max (inclusive).
42
+ *
43
+ * @param min - Lower bound
44
+ * @param max - Upper bound
45
+ * @returns A random integer in [min, max]
46
+ */
47
+ export declare function randomNumber(min: number, max: number): number;
48
+ /**
49
+ * Checks if a version string is at least the given minimum.
50
+ *
51
+ * @param version - Version string (e.g. "v4")
52
+ * @param min - Minimum version number
53
+ * @returns true if the version is >= min
54
+ */
55
+ export declare function since(version: string, min: number): boolean;
@@ -0,0 +1,9 @@
1
+ import type { Response } from 'express';
2
+ /**
3
+ * Sends a standardized JSON error response.
4
+ *
5
+ * @param res - Express response object
6
+ * @param status - HTTP status code
7
+ * @param message - Error description
8
+ */
9
+ export declare function error(res: Response, status: number, message: string): void;
@@ -1,17 +1,15 @@
1
- import { DOCS_URL, STATUS_MESSAGES } from '../constants.js';
1
+ import { STATUS_MESSAGES } from '../constants.js';
2
2
  /**
3
3
  * Sends a standardized JSON error response.
4
4
  *
5
5
  * @param res - Express response object
6
6
  * @param status - HTTP status code
7
7
  * @param message - Error description
8
- * @param docPath - Optional documentation path appended to the base URL
9
8
  */
10
- export function error(res, status, message, docPath) {
9
+ export function error(res, status, message) {
11
10
  const body = {
12
11
  message: STATUS_MESSAGES[status] ?? 'Error',
13
12
  error: message,
14
- documentation: docPath ? `${DOCS_URL}/${docPath}` : DOCS_URL,
15
13
  status: String(status),
16
14
  };
17
15
  if (typeof res.jsonResponse === 'function') {
@@ -1 +1 @@
1
- {"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,GAAa,EAAE,MAAc,EAAE,OAAe,EAAE,OAAgB;IAClF,MAAM,IAAI,GAAG;QACT,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,OAAO;QAC3C,KAAK,EAAE,OAAO;QACd,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ;QAC5D,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,GAAG,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QACzC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACJ,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;aACb,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;aAC7C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,GAAa,EAAE,MAAc,EAAE,OAAe;IAChE,MAAM,IAAI,GAAG;QACT,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,OAAO;QAC3C,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,GAAG,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QACzC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACJ,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;aACb,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;aAC7C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,32 +1,36 @@
1
1
  {
2
- "version": "5.6.0",
2
+ "version": "5.7.0",
3
3
  "name": "@20syldev/api",
4
4
  "description": "Node.js API with multiple features. Check the documentation at https://docs.sylvain.sh",
5
- "main": "dist/app.js",
5
+ "main": "./dist/modules/v5.js",
6
+ "types": "./dist/modules/v5.d.ts",
6
7
  "type": "module",
7
8
  "scripts": {
8
9
  "prepare": "tsc",
9
10
  "dev": "tsx watch src/app.ts",
10
11
  "start": "node dist/app.js",
11
12
  "build": "tsc",
12
- "check": "tsc --noEmit -p tsconfig.test.json && eslint src/ tests/",
13
- "format": "prettier --write src/ tests/ && eslint --fix src/ tests/",
14
- "test": "NODE_ENV=test node --import tsx --test --test-force-exit tests/unit/*.test.ts tests/integration/*.test.ts",
15
- "upgrade:minor": "npm upgrade",
16
- "upgrade:major": "npx npm-check-updates -u && npm install"
13
+ "check": "tsc --noEmit -p tsconfig.test.json && eslint src/ tests/ && prettier --check .",
14
+ "format": "prettier --write . && eslint --fix src/ tests/",
15
+ "test": "NODE_ENV=test DOCS_URL=https://docs.example.test node --import tsx --test tests/unit/*.test.ts tests/integration/*.test.ts"
17
16
  },
18
17
  "engines": {
19
- "node": ">=22.0.0"
18
+ "node": ">=22.12.0"
20
19
  },
21
20
  "exports": {
22
- "./v1": "./dist/modules/v1.js",
23
- "./v2": "./dist/modules/v2.js",
24
- "./v3": "./dist/modules/v3.js",
25
- "./v4": "./dist/modules/v4.js",
26
- "./v5": "./dist/modules/v5.js"
21
+ ".": { "types": "./dist/modules/v5.d.ts", "default": "./dist/modules/v5.js" },
22
+ "./server": { "types": "./dist/app.d.ts", "default": "./dist/app.js" },
23
+ "./v1": { "types": "./dist/modules/v3.d.ts", "default": "./dist/modules/v3.js" },
24
+ "./v2": { "types": "./dist/modules/v3.d.ts", "default": "./dist/modules/v3.js" },
25
+ "./v3": { "types": "./dist/modules/v3.d.ts", "default": "./dist/modules/v3.js" },
26
+ "./v4": { "types": "./dist/modules/v4.d.ts", "default": "./dist/modules/v4.js" },
27
+ "./v5": { "types": "./dist/modules/v5.d.ts", "default": "./dist/modules/v5.js" },
28
+ "./package.json": "./package.json"
27
29
  },
28
30
  "dependencies": {
29
31
  "@20syldev/logger.ts": "^1.0.1",
32
+ "@types/express": "^5.0.0",
33
+ "@types/node": "^22.19.17",
30
34
  "canvas": "^3.1.0",
31
35
  "cors": "^2.8.5",
32
36
  "dotenv": "^16.4.7",
@@ -39,14 +43,11 @@
39
43
  "devDependencies": {
40
44
  "@eslint/js": "^9.24.0",
41
45
  "@types/cors": "^2.8.17",
42
- "@types/express": "^5.0.0",
43
- "@types/node": "^22.19.17",
44
46
  "@types/qrcode": "^1.5.6",
45
47
  "@types/uuid": "^10.0.0",
46
48
  "eslint": "^9.24.0",
47
49
  "eslint-config-prettier": "^10.1.1",
48
50
  "eslint-plugin-simple-import-sort": "^13.0.0",
49
- "npm-check-updates": "^18.0.1",
50
51
  "prettier": "^3.5.3",
51
52
  "tsx": "^4.19.0",
52
53
  "typescript": "^5.7.0",
package/robots.txt ADDED
@@ -0,0 +1,74 @@
1
+ User-agent: 360Spider
2
+ User-agent: 360Spider-Image
3
+ User-agent: 360Spider-Video
4
+ User-agent: AdsBot-Google
5
+ User-agent: AdsBot-Google-Mobile
6
+ User-agent: AdsBot-Google-Mobile-Apps
7
+ User-agent: adidxbot
8
+ User-agent: Applebot
9
+ User-agent: AppleNewsBot
10
+ User-agent: Baiduspider
11
+ User-agent: Baiduspider-image
12
+ User-agent: Baiduspider-news
13
+ User-agent: Baiduspider-video
14
+ User-agent: bingbot
15
+ User-agent: BingPreview
16
+ User-agent: BublupBot
17
+ User-agent: CCBot
18
+ User-agent: Cliqzbot
19
+ User-agent: coccoc
20
+ User-agent: coccocbot-image
21
+ User-agent: coccocbot-web
22
+ User-agent: Daumoa
23
+ User-agent: Dazoobot
24
+ User-agent: DeuSu
25
+ User-agent: DuckDuckBot
26
+ User-agent: DuckDuckGo-Favicons-Bot
27
+ User-agent: EuripBot
28
+ User-agent: Exploratodo
29
+ User-agent: Facebot
30
+ User-agent: Feedly
31
+ User-agent: Findxbot
32
+ User-agent: Googlebot
33
+ User-agent: Googlebot-Image
34
+ User-agent: Googlebot-Mobile
35
+ User-agent: Googlebot-News
36
+ User-agent: Googlebot-Video
37
+ User-agent: HaoSouSpider
38
+ User-agent: ichiro
39
+ User-agent: istellabot
40
+ User-agent: JikeSpider
41
+ User-agent: Lycos
42
+ User-agent: Mail.Ru
43
+ User-agent: Mediapartners-Google
44
+ User-agent: MojeekBot
45
+ User-agent: msnbot
46
+ User-agent: msnbot-media
47
+ User-agent: OrangeBot
48
+ User-agent: Pinterest
49
+ User-agent: Plukkie
50
+ User-agent: Qwantify
51
+ User-agent: Rambler
52
+ User-agent: SeznamBot
53
+ User-agent: Sosospider
54
+ User-agent: Slurp
55
+ User-agent: Sogou blog
56
+ User-agent: Sogou inst spider
57
+ User-agent: Sogou News Spider
58
+ User-agent: Sogou Orion spider
59
+ User-agent: Sogou spider2
60
+ User-agent: Sogou web spider
61
+ User-agent: SputnikBot
62
+ User-agent: Teoma
63
+ User-agent: Twitterbot
64
+ User-agent: wotbox
65
+ User-agent: yacybot
66
+ User-agent: Yandex
67
+ User-agent: YandexMobileBot
68
+ User-agent: Yeti
69
+ User-agent: YioopBot
70
+ User-agent: yoozBot
71
+ User-agent: YoudaoBot
72
+ Disallow:
73
+ User-agent: *
74
+ Disallow: /
Binary file