@vitnode/core 1.2.0-canary.60 → 1.2.0-canary.61

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 (274) hide show
  1. package/dist/scripts/get-config.js +15 -0
  2. package/dist/scripts/plugin.js +188 -0
  3. package/dist/scripts/prepare-database.js +177 -0
  4. package/dist/scripts/prepare-plugins-files.js +134 -0
  5. package/dist/scripts/run-interactive-shell-command.js +21 -0
  6. package/dist/scripts/scripts.js +39 -13
  7. package/dist/scripts/shared/file-utils.js +203 -0
  8. package/dist/src/api/adapters/sso/discord.js +1 -77
  9. package/dist/src/api/adapters/sso/facebook.js +1 -76
  10. package/dist/src/api/adapters/sso/google.js +1 -87
  11. package/dist/src/api/config.js +1 -67
  12. package/dist/src/api/lib/check-plugin-id.js +1 -43
  13. package/dist/src/api/lib/cron.js +1 -22
  14. package/dist/src/api/lib/logger-middleware.js +1 -35
  15. package/dist/src/api/lib/module.js +1 -22
  16. package/dist/src/api/lib/plugin.js +1 -22
  17. package/dist/src/api/lib/route.js +1 -27
  18. package/dist/src/api/lib/with-pagination.js +1 -83
  19. package/dist/src/api/middlewares/captcha.middleware.js +1 -63
  20. package/dist/src/api/middlewares/cron-auth.middleware.js +1 -19
  21. package/dist/src/api/middlewares/global.middleware.js +1 -93
  22. package/dist/src/api/middlewares/rate-limiter.middleware.js +1 -32
  23. package/dist/src/api/models/device.js +1 -61
  24. package/dist/src/api/models/email.js +1 -76
  25. package/dist/src/api/models/password.js +1 -36
  26. package/dist/src/api/models/session-admin.js +1 -106
  27. package/dist/src/api/models/session.js +1 -85
  28. package/dist/src/api/models/sso.js +1 -120
  29. package/dist/src/api/models/user/get-user-by-id.js +1 -19
  30. package/dist/src/api/models/user/sign-in-with-passwords.js +1 -22
  31. package/dist/src/api/models/user/sign-up.js +1 -73
  32. package/dist/src/api/models/user.js +1 -8
  33. package/dist/src/api/modules/admin/admin.module.js +1 -19
  34. package/dist/src/api/modules/admin/advanced/advanced.admin.module.js +1 -11
  35. package/dist/src/api/modules/admin/advanced/cron/cron.admin.module.js +1 -12
  36. package/dist/src/api/modules/admin/advanced/cron/routes/get.route.js +1 -66
  37. package/dist/src/api/modules/admin/advanced/cron/routes/run.route.js +1 -95
  38. package/dist/src/api/modules/admin/debug/debug.admin.module.js +1 -10
  39. package/dist/src/api/modules/admin/debug/routes/logs.route.js +1 -94
  40. package/dist/src/api/modules/admin/routes/session.route.js +1 -47
  41. package/dist/src/api/modules/admin/users/routes/list.route.js +1 -79
  42. package/dist/src/api/modules/admin/users/routes/users.route.js +1 -84
  43. package/dist/src/api/modules/admin/users/users.admin.module.js +1 -10
  44. package/dist/src/api/modules/cron/cron/clean.cron.js +1 -24
  45. package/dist/src/api/modules/cron/cron.module.js +1 -14
  46. package/dist/src/api/modules/cron/helpers/process-cron-jobs.d.ts.map +1 -1
  47. package/dist/src/api/modules/cron/helpers/process-cron-jobs.js +1 -76
  48. package/dist/src/api/modules/cron/routes/cron.route.js +1 -101
  49. package/dist/src/api/modules/middleware/middleware.module.js +1 -10
  50. package/dist/src/api/modules/middleware/route.js +1 -49
  51. package/dist/src/api/modules/users/avatar-color.js +1 -43
  52. package/dist/src/api/modules/users/routes/change-password.route.js +1 -58
  53. package/dist/src/api/modules/users/routes/reset-passowrd.route.js +1 -91
  54. package/dist/src/api/modules/users/routes/session.route.js +1 -46
  55. package/dist/src/api/modules/users/routes/sign-in.route.js +1 -71
  56. package/dist/src/api/modules/users/routes/sign-out.route.js +1 -43
  57. package/dist/src/api/modules/users/routes/sign-up.route.js +1 -77
  58. package/dist/src/api/modules/users/routes/test.route.js +1 -33
  59. package/dist/src/api/modules/users/sso/routes/callback.route.js +1 -52
  60. package/dist/src/api/modules/users/sso/routes/create-url.route.js +1 -36
  61. package/dist/src/api/modules/users/sso/sso.module.js +1 -12
  62. package/dist/src/api/modules/users/users.module.js +1 -26
  63. package/dist/src/api/plugin.js +1 -15
  64. package/dist/src/app/login/page.js +1 -16
  65. package/dist/src/app/login/reset-password/page.js +1 -18
  66. package/dist/src/app/login/sso/[providerId]/page.js +1 -10
  67. package/dist/src/app/register/page.js +1 -16
  68. package/dist/src/app_admin/core/advanced/cron/page.js +1 -42
  69. package/dist/src/app_admin/core/debug/page.js +1 -45
  70. package/dist/src/app_admin/core/page.js +1 -5
  71. package/dist/src/app_admin/core/test/page.js +1 -5
  72. package/dist/src/app_admin/core/users/page.js +1 -38
  73. package/dist/src/components/avatar.js +1 -14
  74. package/dist/src/components/confirm-action/confirm-action-alert-dialog.js +1 -42
  75. package/dist/src/components/confirm-action/content.js +1 -31
  76. package/dist/src/components/date-format.js +1 -41
  77. package/dist/src/components/form/auto-form.js +1 -103
  78. package/dist/src/components/form/common/desc.js +1 -9
  79. package/dist/src/components/form/common/label.js +1 -18
  80. package/dist/src/components/form/fields/checkbox.js +1 -37
  81. package/dist/src/components/form/fields/combobox-async.js +1 -123
  82. package/dist/src/components/form/fields/combobox.js +1 -87
  83. package/dist/src/components/form/fields/input.js +1 -39
  84. package/dist/src/components/form/fields/radio-group.js +1 -50
  85. package/dist/src/components/form/fields/select.js +1 -58
  86. package/dist/src/components/form/fields/switch.js +1 -36
  87. package/dist/src/components/form/fields/textarea.js +1 -36
  88. package/dist/src/components/i18n-provider.js +1 -43
  89. package/dist/src/components/logo-vitnode.js +1 -119
  90. package/dist/src/components/switchers/langs/language-switcher.js +1 -47
  91. package/dist/src/components/switchers/themes/theme-switcher.js +1 -28
  92. package/dist/src/components/table/content.js +1 -81
  93. package/dist/src/components/table/data-table.js +1 -68
  94. package/dist/src/components/table/order-table-head.js +1 -50
  95. package/dist/src/components/table/pagination.js +1 -122
  96. package/dist/src/components/tiptap/extension.js +1 -33
  97. package/dist/src/components/tiptap/toolbar/actions/alignment-action.js +1 -91
  98. package/dist/src/components/tiptap/toolbar/actions/bold-action.js +1 -39
  99. package/dist/src/components/tiptap/toolbar/actions/headings-action.js +1 -93
  100. package/dist/src/components/tiptap/toolbar/actions/italic-action.js +1 -38
  101. package/dist/src/components/tiptap/toolbar/actions/list-action.js +1 -61
  102. package/dist/src/components/tiptap/toolbar/actions/text-format-more/text-format-more.js +1 -59
  103. package/dist/src/components/tiptap/toolbar/actions/underline-action.js +1 -38
  104. package/dist/src/components/tiptap/toolbar/actions/undo-redo-actions.js +1 -63
  105. package/dist/src/components/tiptap/toolbar/actions/utils/tooltip-shortcut.js +1 -11
  106. package/dist/src/components/tiptap/toolbar/tiptap-toolbar.js +1 -55
  107. package/dist/src/components/tiptap/toolbar/use-toolbar-editor.js +1 -5
  108. package/dist/src/components/ui/accordion.js +1 -46
  109. package/dist/src/components/ui/alert-dialog.js +1 -123
  110. package/dist/src/components/ui/alert.js +1 -39
  111. package/dist/src/components/ui/badge.js +1 -28
  112. package/dist/src/components/ui/button-client.js +1 -57
  113. package/dist/src/components/ui/button.js +1 -32
  114. package/dist/src/components/ui/card.js +1 -52
  115. package/dist/src/components/ui/checkbox.js +1 -20
  116. package/dist/src/components/ui/collapsible.js +1 -22
  117. package/dist/src/components/ui/command.js +1 -98
  118. package/dist/src/components/ui/context-menu.js +1 -140
  119. package/dist/src/components/ui/dialog.js +1 -189
  120. package/dist/src/components/ui/drawer.js +1 -83
  121. package/dist/src/components/ui/dropdown-menu.js +1 -141
  122. package/dist/src/components/ui/editor-content.js +1 -10
  123. package/dist/src/components/ui/editor.js +1 -35
  124. package/dist/src/components/ui/form.js +1 -148
  125. package/dist/src/components/ui/header-content.js +1 -30
  126. package/dist/src/components/ui/hover-card.js +1 -29
  127. package/dist/src/components/ui/input-otp.js +1 -48
  128. package/dist/src/components/ui/input.js +1 -11
  129. package/dist/src/components/ui/label.js +1 -12
  130. package/dist/src/components/ui/loader.js +1 -16
  131. package/dist/src/components/ui/menubar.js +1 -151
  132. package/dist/src/components/ui/navigation-menu.js +1 -82
  133. package/dist/src/components/ui/popover.js +1 -35
  134. package/dist/src/components/ui/progress.js +1 -19
  135. package/dist/src/components/ui/radio-group.js +1 -27
  136. package/dist/src/components/ui/scroll-area.js +1 -33
  137. package/dist/src/components/ui/select.js +1 -113
  138. package/dist/src/components/ui/separator.js +1 -14
  139. package/dist/src/components/ui/sheet.js +1 -92
  140. package/dist/src/components/ui/sidebar.js +1 -433
  141. package/dist/src/components/ui/skeleton.js +1 -10
  142. package/dist/src/components/ui/slider.js +1 -50
  143. package/dist/src/components/ui/sonner.js +1 -26
  144. package/dist/src/components/ui/switch.js +1 -16
  145. package/dist/src/components/ui/table.js +1 -63
  146. package/dist/src/components/ui/tabs.js +1 -33
  147. package/dist/src/components/ui/textarea.js +1 -10
  148. package/dist/src/components/ui/toggle-group.js +1 -45
  149. package/dist/src/components/ui/toggle.js +1 -34
  150. package/dist/src/components/ui/tooltip.js +1 -57
  151. package/dist/src/config.js +1 -4
  152. package/dist/src/database/admins.js +1 -74
  153. package/dist/src/database/cron.js +1 -22
  154. package/dist/src/database/languages.js +1 -52
  155. package/dist/src/database/logs.js +1 -34
  156. package/dist/src/database/moderators.js +1 -37
  157. package/dist/src/database/roles.js +1 -13
  158. package/dist/src/database/sessions.js +1 -60
  159. package/dist/src/database/users.js +1 -145
  160. package/dist/src/drizzle.config.js +1 -67
  161. package/dist/src/emails/default-template.js +1 -99
  162. package/dist/src/emails/reset-password.js +1 -132
  163. package/dist/src/emails/ui/button.js +1 -36
  164. package/dist/src/emails/ui/card.js +1 -39
  165. package/dist/src/hooks/use-before-unload.js +1 -30
  166. package/dist/src/hooks/use-captcha.js +1 -122
  167. package/dist/src/hooks/use-mobile.js +1 -16
  168. package/dist/src/lib/api/get-middleware-api.js +1 -13
  169. package/dist/src/lib/api/get-next-cron-run-date.js +1 -14
  170. package/dist/src/lib/api/get-next-cron-run-date.test.js +1 -55
  171. package/dist/src/lib/api/get-session-admin-api.js +1 -19
  172. package/dist/src/lib/api/get-session-api.js +1 -14
  173. package/dist/src/lib/api/should-cron-job-run.js +1 -16
  174. package/dist/src/lib/api/should-cron-job-run.test.js +1 -213
  175. package/dist/src/lib/api/validate-cron-schedule.d.ts +2 -0
  176. package/dist/src/lib/api/validate-cron-schedule.d.ts.map +1 -0
  177. package/dist/src/lib/api/validate-cron-schedule.js +1 -0
  178. package/dist/src/lib/api/validate-cron-schedule.test.d.ts +2 -0
  179. package/dist/src/lib/api/validate-cron-schedule.test.d.ts.map +1 -0
  180. package/dist/src/lib/api/validate-cron-schedule.test.js +1 -0
  181. package/dist/src/lib/colors.js +1 -140
  182. package/dist/src/lib/colors.test.js +1 -173
  183. package/dist/src/lib/config.js +1 -14
  184. package/dist/src/lib/ctrl-or-command-character.js +1 -5
  185. package/dist/src/lib/fetcher/cookie-from-string-to-object.js +1 -12
  186. package/dist/src/lib/fetcher/cookie-from-string-to-object.test.js +1 -78
  187. package/dist/src/lib/fetcher/core.js +3 -48
  188. package/dist/src/lib/fetcher/helpers-server.js +1 -18
  189. package/dist/src/lib/fetcher/helpers.js +1 -16
  190. package/dist/src/lib/fetcher/helpers.test.js +1 -37
  191. package/dist/src/lib/fetcher/types.js +1 -1
  192. package/dist/src/lib/fetcher-client.js +1 -17
  193. package/dist/src/lib/fetcher.js +1 -33
  194. package/dist/src/lib/helpers/auto-form.js +1 -98
  195. package/dist/src/lib/helpers/auto-form.test.js +1 -336
  196. package/dist/src/lib/navigation.js +1 -11
  197. package/dist/src/lib/plugin.js +1 -3
  198. package/dist/src/lib/special-characters.js +1 -4
  199. package/dist/src/lib/special-characters.test.js +1 -56
  200. package/dist/src/lib/utils.js +1 -5
  201. package/dist/src/locales/en.json +308 -0
  202. package/dist/src/tests/setup.js +1 -6
  203. package/dist/src/views/admin/layouts/admin-layout.js +1 -73
  204. package/dist/src/views/admin/layouts/sidebar/nav/item.js +1 -98
  205. package/dist/src/views/admin/layouts/sidebar/nav/nav.js +1 -60
  206. package/dist/src/views/admin/layouts/sidebar/sidebar.js +1 -28
  207. package/dist/src/views/admin/layouts/sidebar/sign-out.js +1 -14
  208. package/dist/src/views/admin/layouts/user-bar/client.js +1 -69
  209. package/dist/src/views/admin/layouts/user-bar/user-bar.js +1 -32
  210. package/dist/src/views/admin/sign-in/sign-in-admin-view.js +1 -27
  211. package/dist/src/views/admin/views/core/advanced/cron/cron-table-view.js +1 -97
  212. package/dist/src/views/admin/views/core/advanced/cron/run-action/mutation-api.js +1 -23
  213. package/dist/src/views/admin/views/core/advanced/cron/run-action/run-action.js +1 -38
  214. package/dist/src/views/admin/views/core/dashboard/dashboard-admin-view.js +1 -44
  215. package/dist/src/views/admin/views/core/debug/actions/clear-cache/clear-cache.js +1 -35
  216. package/dist/src/views/admin/views/core/debug/actions/clear-cache/mutation-api.js +1 -5
  217. package/dist/src/views/admin/views/core/debug/system-logs/actions/more/content.js +1 -281
  218. package/dist/src/views/admin/views/core/debug/system-logs/actions/more/more.js +1 -67
  219. package/dist/src/views/admin/views/core/debug/system-logs/badges/badge-status.js +1 -14
  220. package/dist/src/views/admin/views/core/debug/system-logs/badges/badge-type-log.js +1 -30
  221. package/dist/src/views/admin/views/core/debug/system-logs/system-logs-view.js +1 -96
  222. package/dist/src/views/admin/views/core/test.js +1 -161
  223. package/dist/src/views/admin/views/core/users/users-admin-view.js +1 -89
  224. package/dist/src/views/auth/password-reset/change-password-form/form.js +1 -48
  225. package/dist/src/views/auth/password-reset/change-password-form/mutation-api.js +1 -22
  226. package/dist/src/views/auth/password-reset/change-password-form/use-form.js +1 -36
  227. package/dist/src/views/auth/password-reset/form/form.js +1 -104
  228. package/dist/src/views/auth/password-reset/form/mutation-api.js +1 -21
  229. package/dist/src/views/auth/password-reset/form/use-form.js +1 -33
  230. package/dist/src/views/auth/password-reset/password-reset-view.js +1 -37
  231. package/dist/src/views/auth/sign-in/form/form.js +1 -64
  232. package/dist/src/views/auth/sign-in/form/mutation-api.js +1 -33
  233. package/dist/src/views/auth/sign-in/form/use-form.js +1 -38
  234. package/dist/src/views/auth/sign-in/sign-in-view.js +1 -61
  235. package/dist/src/views/auth/sign-up/components/password-input.js +1 -96
  236. package/dist/src/views/auth/sign-up/email-confirmation-view.js +1 -55
  237. package/dist/src/views/auth/sign-up/form/form.js +1 -89
  238. package/dist/src/views/auth/sign-up/form/mutation-api.js +1 -30
  239. package/dist/src/views/auth/sign-up/form/use-form.js +1 -70
  240. package/dist/src/views/auth/sign-up/sign-up-view.js +1 -65
  241. package/dist/src/views/auth/sign-up/wrapper.js +1 -22
  242. package/dist/src/views/auth/sso/buttons/client.js +1 -22
  243. package/dist/src/views/auth/sso/buttons/mutation-api.js +1 -24
  244. package/dist/src/views/auth/sso/buttons/sso-buttons.js +1 -56
  245. package/dist/src/views/auth/sso/callback/callback-sso-view.js +1 -32
  246. package/dist/src/views/auth/sso/callback/client/client.js +1 -68
  247. package/dist/src/views/auth/sso/callback/client/mutation-api.js +1 -32
  248. package/dist/src/views/error/back-button.js +1 -14
  249. package/dist/src/views/error/error-view.js +1 -58
  250. package/dist/src/views/error/global-error-view.js +1 -50
  251. package/dist/src/views/layouts/provider.js +1 -44
  252. package/dist/src/views/layouts/root-layout.js +1 -25
  253. package/dist/src/views/layouts/theme/header/header.js +1 -38
  254. package/dist/src/views/layouts/theme/header/user/auth/auth.js +1 -33
  255. package/dist/src/views/layouts/theme/header/user/auth/client.js +1 -47
  256. package/dist/src/views/layouts/theme/header/user/auth/log-out-mutation-api.js +1 -27
  257. package/dist/src/views/layouts/theme/header/user/user.js +1 -32
  258. package/dist/src/views/layouts/theme/layout.js +1 -16
  259. package/dist/src/vitnode.config.js +1 -42
  260. package/dist/tsconfig.tsbuildinfo +1 -1
  261. package/dist/tsup.config.js +18 -0
  262. package/dist/vitest.config.d.ts.map +1 -1
  263. package/dist/vitest.config.js +49 -0
  264. package/eslint.config.mjs +2 -0
  265. package/package.json +6 -10
  266. package/dist/src/api/adapters/cron/node-cron.adapter.d.ts +0 -3
  267. package/dist/src/api/adapters/cron/node-cron.adapter.d.ts.map +0 -1
  268. package/dist/src/api/adapters/cron/node-cron.adapter.js +0 -11
  269. package/dist/src/api/adapters/email/nodemailer.d.ts +0 -10
  270. package/dist/src/api/adapters/email/nodemailer.d.ts.map +0 -1
  271. package/dist/src/api/adapters/email/nodemailer.js +0 -30
  272. package/dist/src/api/adapters/email/resend.d.ts +0 -6
  273. package/dist/src/api/adapters/email/resend.d.ts.map +0 -1
  274. package/dist/src/api/adapters/email/resend.js +0 -21
@@ -1,140 +1 @@
1
- export const convertColor = {
2
- hslToHex: ({ h, l, s })=>{
3
- l /= 100;
4
- const a = s * Math.min(l, 1 - l) / 100;
5
- const f = (n)=>{
6
- const k = (n + h / 30) % 12;
7
- const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
8
- return Math.round(255 * color).toString(16).padStart(2, "0");
9
- };
10
- return `${f(0)}${f(8)}${f(4)}`;
11
- },
12
- hexToHSL: (hex)=>{
13
- if (!hexRegex.test(hex)) return undefined;
14
- let b = 0;
15
- let g = 0;
16
- let r = 0;
17
- // 3 digits
18
- if (hex.length === 4) {
19
- r = parseInt(hex[1] + hex[1], 16);
20
- g = parseInt(hex[2] + hex[2], 16);
21
- b = parseInt(hex[3] + hex[3], 16);
22
- } else if (hex.length === 7) {
23
- r = parseInt(hex[1] + hex[2], 16);
24
- g = parseInt(hex[3] + hex[4], 16);
25
- b = parseInt(hex[5] + hex[6], 16);
26
- } else {
27
- return undefined;
28
- }
29
- // Check if any of the parsed values are NaN
30
- if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
31
- return undefined;
32
- }
33
- r /= 255;
34
- g /= 255;
35
- b /= 255;
36
- const max = Math.max(r, g, b);
37
- const min = Math.min(r, g, b);
38
- const l = (max + min) / 2;
39
- let h = 0;
40
- let s = 0;
41
- if (max === min) {
42
- h = s = 0; // achromatic
43
- } else {
44
- const d = max - min;
45
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
46
- switch(max){
47
- case b:
48
- h = (r - g) / d + 4;
49
- break;
50
- case g:
51
- h = (b - r) / d + 2;
52
- break;
53
- case r:
54
- h = (g - b) / d + (g < b ? 6 : 0);
55
- break;
56
- }
57
- h /= 6;
58
- }
59
- return {
60
- h: Math.round(h * 360),
61
- s: Math.round(s * 100),
62
- l: Math.round(l * 100)
63
- };
64
- },
65
- RGBToHSL (r, g, b) {
66
- // Make r, g, and b fractions of 1
67
- r /= 255;
68
- g /= 255;
69
- b /= 255;
70
- // Find greatest and smallest channel values
71
- const cmax = Math.max(r, g, b);
72
- const cmin = Math.min(r, g, b);
73
- const delta = cmax - cmin;
74
- let h = 0;
75
- let l = 0;
76
- let s = 0;
77
- // Calculate hue
78
- if (delta === 0) h = 0;
79
- else if (cmax === r) h = (g - b) / delta % 6;
80
- else if (cmax === g) h = (b - r) / delta + 2;
81
- else h = (r - g) / delta + 4;
82
- h = Math.round(h * 60);
83
- // Make negative hues positive behind 360°
84
- if (h < 0) h += 360;
85
- // Calculate lightness
86
- l = (cmax + cmin) / 2;
87
- // Calculate saturation
88
- s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
89
- // Multiply l and s by 100
90
- s = +(s * 100).toFixed(1);
91
- l = +(l * 100).toFixed(1);
92
- return {
93
- h,
94
- s,
95
- l
96
- };
97
- },
98
- hslToRgb (h, s, l) {
99
- l /= 100;
100
- const a = s * Math.min(l, 1 - l) / 100;
101
- const f = (n)=>{
102
- const k = (n + h / 30) % 12;
103
- const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
104
- return Math.round(255 * color).toString(16).padStart(2, "0"); // convert to Hex and prefix "0" if needed
105
- };
106
- return {
107
- r: f(0),
108
- g: f(8),
109
- b: f(4)
110
- };
111
- }
112
- };
113
- export const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
114
- export const hslRegex = /^hsl\(\s*(?:36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])\s*,\s*(?:100|[1-9]?[0-9])%\s*,\s*(?:100|[1-9]?[0-9])%\s*\)$/;
115
- export const rgbWithCommaRegex = /^rgb\(\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*\)$/;
116
- export const rgbWithoutCommaRegex = /^rgb\(\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s+([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s+([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*\)$/;
117
- export const checkColorType = (strColor)=>{
118
- if (hexRegex.test(strColor)) {
119
- return "hex";
120
- }
121
- if (hslRegex.test(strColor)) {
122
- return "hsl";
123
- }
124
- if (rgbWithoutCommaRegex.test(strColor) || rgbWithCommaRegex.test(strColor)) {
125
- return "rgb";
126
- }
127
- return null;
128
- };
129
- export const getHSLFromString = (string)=>{
130
- if (!hslRegex.test(string)) return null;
131
- const [h, s, l] = string.replaceAll("hsl(", "").replaceAll(")", "").replaceAll("%", "").split(",").map(Number);
132
- return {
133
- h,
134
- s,
135
- l
136
- };
137
- };
138
- export const getStringFromHSL = ({ h, l, s })=>{
139
- return `hsl(${h}, ${s}%, ${l}%)`;
140
- };
1
+ export const convertColor={hslToHex:({h,l,s})=>{l/=100;const a=s*Math.min(l,1-l)/100;const f=n=>{const k=(n+h/30)%12;const color=l-a*Math.max(Math.min(k-3,9-k,1),-1);return Math.round(255*color).toString(16).padStart(2,"0")};return`${f(0)}${f(8)}${f(4)}`},hexToHSL:hex=>{if(!hexRegex.test(hex))return undefined;let b=0;let g=0;let r=0;if(hex.length===4){r=parseInt(hex[1]+hex[1],16);g=parseInt(hex[2]+hex[2],16);b=parseInt(hex[3]+hex[3],16)}else if(hex.length===7){r=parseInt(hex[1]+hex[2],16);g=parseInt(hex[3]+hex[4],16);b=parseInt(hex[5]+hex[6],16)}else{return undefined}if(Number.isNaN(r)||Number.isNaN(g)||Number.isNaN(b)){return undefined}r/=255;g/=255;b/=255;const max=Math.max(r,g,b);const min=Math.min(r,g,b);const l=(max+min)/2;let h=0;let s=0;if(max===min){h=s=0}else{const d=max-min;s=l>.5?d/(2-max-min):d/(max+min);switch(max){case b:h=(r-g)/d+4;break;case g:h=(b-r)/d+2;break;case r:h=(g-b)/d+(g<b?6:0);break}h/=6}return{h:Math.round(h*360),s:Math.round(s*100),l:Math.round(l*100)}},RGBToHSL(r,g,b){r/=255;g/=255;b/=255;const cmax=Math.max(r,g,b);const cmin=Math.min(r,g,b);const delta=cmax-cmin;let h=0;let l=0;let s=0;if(delta===0)h=0;else if(cmax===r)h=(g-b)/delta%6;else if(cmax===g)h=(b-r)/delta+2;else h=(r-g)/delta+4;h=Math.round(h*60);if(h<0)h+=360;l=(cmax+cmin)/2;s=delta===0?0:delta/(1-Math.abs(2*l-1));s=+(s*100).toFixed(1);l=+(l*100).toFixed(1);return{h,s,l}},hslToRgb(h,s,l){l/=100;const a=s*Math.min(l,1-l)/100;const f=n=>{const k=(n+h/30)%12;const color=l-a*Math.max(Math.min(k-3,9-k,1),-1);return Math.round(255*color).toString(16).padStart(2,"0")};return{r:f(0),g:f(8),b:f(4)}}};export const hexRegex=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;export const hslRegex=/^hsl\(\s*(?:36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])\s*,\s*(?:100|[1-9]?[0-9])%\s*,\s*(?:100|[1-9]?[0-9])%\s*\)$/;export const rgbWithCommaRegex=/^rgb\(\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*\)$/;export const rgbWithoutCommaRegex=/^rgb\(\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s+([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s+([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*\)$/;export const checkColorType=strColor=>{if(hexRegex.test(strColor)){return"hex"}if(hslRegex.test(strColor)){return"hsl"}if(rgbWithoutCommaRegex.test(strColor)||rgbWithCommaRegex.test(strColor)){return"rgb"}return null};export const getHSLFromString=string=>{if(!hslRegex.test(string))return null;const[h,s,l]=string.replaceAll("hsl(","").replaceAll(")","").replaceAll("%","").split(",").map(Number);return{h,s,l}};export const getStringFromHSL=({h,l,s})=>{return`hsl(${h}, ${s}%, ${l}%)`};
@@ -1,173 +1 @@
1
- import { describe, expect, it } from "vitest";
2
- import { checkColorType, convertColor, getHSLFromString, getStringFromHSL } from "./colors.js";
3
- describe("convertColor", ()=>{
4
- describe("hslToHex", ()=>{
5
- it("should convert HSL to hex correctly", ()=>{
6
- const hsl = {
7
- h: 0,
8
- s: 100,
9
- l: 50
10
- }; // Red
11
- expect(convertColor.hslToHex(hsl)).toBe("ff0000");
12
- const hsl2 = {
13
- h: 120,
14
- s: 100,
15
- l: 50
16
- }; // Green
17
- expect(convertColor.hslToHex(hsl2)).toBe("00ff00");
18
- const hsl3 = {
19
- h: 240,
20
- s: 100,
21
- l: 50
22
- }; // Blue
23
- expect(convertColor.hslToHex(hsl3)).toBe("0000ff");
24
- });
25
- });
26
- describe("hexToHSL", ()=>{
27
- it("should convert 6-digit hex to HSL correctly", ()=>{
28
- expect(convertColor.hexToHSL("#ff0000")).toEqual({
29
- h: 0,
30
- s: 100,
31
- l: 50
32
- });
33
- expect(convertColor.hexToHSL("#00ff00")).toEqual({
34
- h: 120,
35
- s: 100,
36
- l: 50
37
- });
38
- expect(convertColor.hexToHSL("#0000ff")).toEqual({
39
- h: 240,
40
- s: 100,
41
- l: 50
42
- });
43
- });
44
- it("should convert 3-digit hex to HSL correctly", ()=>{
45
- expect(convertColor.hexToHSL("#f00")).toEqual({
46
- h: 0,
47
- s: 100,
48
- l: 50
49
- });
50
- expect(convertColor.hexToHSL("#0f0")).toEqual({
51
- h: 120,
52
- s: 100,
53
- l: 50
54
- });
55
- expect(convertColor.hexToHSL("#00f")).toEqual({
56
- h: 240,
57
- s: 100,
58
- l: 50
59
- });
60
- });
61
- it("should return undefined for invalid hex values", ()=>{
62
- expect(convertColor.hexToHSL("#xyz")).toBeUndefined();
63
- expect(convertColor.hexToHSL("#12")).toBeUndefined();
64
- expect(convertColor.hexToHSL("invalid")).toBeUndefined();
65
- });
66
- });
67
- describe("RGBToHSL", ()=>{
68
- it("should convert RGB to HSL correctly", ()=>{
69
- expect(convertColor.RGBToHSL(255, 0, 0)).toEqual({
70
- h: 0,
71
- s: 100,
72
- l: 50
73
- });
74
- expect(convertColor.RGBToHSL(0, 255, 0)).toEqual({
75
- h: 120,
76
- s: 100,
77
- l: 50
78
- });
79
- expect(convertColor.RGBToHSL(0, 0, 255)).toEqual({
80
- h: 240,
81
- s: 100,
82
- l: 50
83
- });
84
- expect(convertColor.RGBToHSL(255, 255, 255)).toEqual({
85
- h: 0,
86
- s: 0,
87
- l: 100
88
- });
89
- expect(convertColor.RGBToHSL(0, 0, 0)).toEqual({
90
- h: 0,
91
- s: 0,
92
- l: 0
93
- });
94
- });
95
- });
96
- describe("hslToRgb", ()=>{
97
- it("should convert HSL to RGB correctly", ()=>{
98
- expect(convertColor.hslToRgb(0, 100, 50)).toEqual({
99
- r: "ff",
100
- g: "00",
101
- b: "00"
102
- });
103
- expect(convertColor.hslToRgb(120, 100, 50)).toEqual({
104
- r: "00",
105
- g: "ff",
106
- b: "00"
107
- });
108
- expect(convertColor.hslToRgb(240, 100, 50)).toEqual({
109
- r: "00",
110
- g: "00",
111
- b: "ff"
112
- });
113
- });
114
- });
115
- });
116
- describe("checkColorType", ()=>{
117
- it("should identify hex colors correctly", ()=>{
118
- expect(checkColorType("#fff")).toBe("hex");
119
- expect(checkColorType("#ffffff")).toBe("hex");
120
- expect(checkColorType("#FF0000")).toBe("hex");
121
- });
122
- it("should identify HSL colors correctly", ()=>{
123
- expect(checkColorType("hsl(0, 100%, 50%)")).toBe("hsl");
124
- expect(checkColorType("hsl(120, 60%, 70%)")).toBe("hsl");
125
- });
126
- it("should identify RGB colors correctly", ()=>{
127
- expect(checkColorType("rgb(255, 0, 0)")).toBe("rgb");
128
- expect(checkColorType("rgb(255 0 0)")).toBe("rgb");
129
- });
130
- it("should return null for invalid colors", ()=>{
131
- expect(checkColorType("invalid")).toBeNull();
132
- expect(checkColorType("rgb(300, 0, 0)")).toBeNull();
133
- expect(checkColorType("hsl(400, 100%, 50%)")).toBeNull();
134
- });
135
- });
136
- describe("getHSLFromString", ()=>{
137
- it("should parse valid HSL strings correctly", ()=>{
138
- expect(getHSLFromString("hsl(0, 100%, 50%)")).toEqual({
139
- h: 0,
140
- s: 100,
141
- l: 50
142
- });
143
- expect(getHSLFromString("hsl(120, 60%, 70%)")).toEqual({
144
- h: 120,
145
- s: 60,
146
- l: 70
147
- });
148
- });
149
- it("should return null for invalid HSL strings", ()=>{
150
- expect(getHSLFromString("invalid")).toBeNull();
151
- expect(getHSLFromString("rgb(255, 0, 0)")).toBeNull();
152
- expect(getHSLFromString("hsl(400, 100%, 50%")).toBeNull();
153
- });
154
- });
155
- describe("getStringFromHSL", ()=>{
156
- it("should format HSL color object to string correctly", ()=>{
157
- expect(getStringFromHSL({
158
- h: 0,
159
- s: 100,
160
- l: 50
161
- })).toBe("hsl(0, 100%, 50%)");
162
- expect(getStringFromHSL({
163
- h: 120,
164
- s: 60,
165
- l: 70
166
- })).toBe("hsl(120, 60%, 70%)");
167
- expect(getStringFromHSL({
168
- h: 240,
169
- s: 50,
170
- l: 30
171
- })).toBe("hsl(240, 50%, 30%)");
172
- });
173
- });
1
+ import{describe,expect,it}from"vitest";import{checkColorType,convertColor,getHSLFromString,getStringFromHSL}from"./colors.js";describe("convertColor",()=>{describe("hslToHex",()=>{it("should convert HSL to hex correctly",()=>{const hsl={h:0,s:100,l:50};expect(convertColor.hslToHex(hsl)).toBe("ff0000");const hsl2={h:120,s:100,l:50};expect(convertColor.hslToHex(hsl2)).toBe("00ff00");const hsl3={h:240,s:100,l:50};expect(convertColor.hslToHex(hsl3)).toBe("0000ff")})});describe("hexToHSL",()=>{it("should convert 6-digit hex to HSL correctly",()=>{expect(convertColor.hexToHSL("#ff0000")).toEqual({h:0,s:100,l:50});expect(convertColor.hexToHSL("#00ff00")).toEqual({h:120,s:100,l:50});expect(convertColor.hexToHSL("#0000ff")).toEqual({h:240,s:100,l:50})});it("should convert 3-digit hex to HSL correctly",()=>{expect(convertColor.hexToHSL("#f00")).toEqual({h:0,s:100,l:50});expect(convertColor.hexToHSL("#0f0")).toEqual({h:120,s:100,l:50});expect(convertColor.hexToHSL("#00f")).toEqual({h:240,s:100,l:50})});it("should return undefined for invalid hex values",()=>{expect(convertColor.hexToHSL("#xyz")).toBeUndefined();expect(convertColor.hexToHSL("#12")).toBeUndefined();expect(convertColor.hexToHSL("invalid")).toBeUndefined()})});describe("RGBToHSL",()=>{it("should convert RGB to HSL correctly",()=>{expect(convertColor.RGBToHSL(255,0,0)).toEqual({h:0,s:100,l:50});expect(convertColor.RGBToHSL(0,255,0)).toEqual({h:120,s:100,l:50});expect(convertColor.RGBToHSL(0,0,255)).toEqual({h:240,s:100,l:50});expect(convertColor.RGBToHSL(255,255,255)).toEqual({h:0,s:0,l:100});expect(convertColor.RGBToHSL(0,0,0)).toEqual({h:0,s:0,l:0})})});describe("hslToRgb",()=>{it("should convert HSL to RGB correctly",()=>{expect(convertColor.hslToRgb(0,100,50)).toEqual({r:"ff",g:"00",b:"00"});expect(convertColor.hslToRgb(120,100,50)).toEqual({r:"00",g:"ff",b:"00"});expect(convertColor.hslToRgb(240,100,50)).toEqual({r:"00",g:"00",b:"ff"})})})});describe("checkColorType",()=>{it("should identify hex colors correctly",()=>{expect(checkColorType("#fff")).toBe("hex");expect(checkColorType("#ffffff")).toBe("hex");expect(checkColorType("#FF0000")).toBe("hex")});it("should identify HSL colors correctly",()=>{expect(checkColorType("hsl(0, 100%, 50%)")).toBe("hsl");expect(checkColorType("hsl(120, 60%, 70%)")).toBe("hsl")});it("should identify RGB colors correctly",()=>{expect(checkColorType("rgb(255, 0, 0)")).toBe("rgb");expect(checkColorType("rgb(255 0 0)")).toBe("rgb")});it("should return null for invalid colors",()=>{expect(checkColorType("invalid")).toBeNull();expect(checkColorType("rgb(300, 0, 0)")).toBeNull();expect(checkColorType("hsl(400, 100%, 50%)")).toBeNull()})});describe("getHSLFromString",()=>{it("should parse valid HSL strings correctly",()=>{expect(getHSLFromString("hsl(0, 100%, 50%)")).toEqual({h:0,s:100,l:50});expect(getHSLFromString("hsl(120, 60%, 70%)")).toEqual({h:120,s:60,l:70})});it("should return null for invalid HSL strings",()=>{expect(getHSLFromString("invalid")).toBeNull();expect(getHSLFromString("rgb(255, 0, 0)")).toBeNull();expect(getHSLFromString("hsl(400, 100%, 50%")).toBeNull()})});describe("getStringFromHSL",()=>{it("should format HSL color object to string correctly",()=>{expect(getStringFromHSL({h:0,s:100,l:50})).toBe("hsl(0, 100%, 50%)");expect(getStringFromHSL({h:120,s:60,l:70})).toBe("hsl(120, 60%, 70%)");expect(getStringFromHSL({h:240,s:50,l:30})).toBe("hsl(240, 50%, 30%)")})});
@@ -1,14 +1 @@
1
- const ENVS = {
2
- apiUrl: process.env.NEXT_PUBLIC_API_URL,
3
- webUrl: process.env.NEXT_PUBLIC_WEB_URL,
4
- cronConfig: process.env.CRON_SECRET ?? "default-cron-secret-change-in-production"
5
- };
6
- const urls = {
7
- api: new URL(ENVS.apiUrl ?? "http://localhost:3000"),
8
- web: new URL(ENVS.webUrl ?? "http://localhost:3000")
9
- };
10
- export const CONFIG = {
11
- node_development: process.env.NODE_ENV === "development",
12
- ...urls,
13
- cronJobSecret: ENVS.cronConfig
14
- };
1
+ const ENVS={apiUrl:process.env.NEXT_PUBLIC_API_URL,webUrl:process.env.NEXT_PUBLIC_WEB_URL,cronConfig:process.env.CRON_SECRET??"default-cron-secret-change-in-production"};const urls={api:new URL(ENVS.apiUrl??"http://localhost:3000"),web:new URL(ENVS.webUrl??"http://localhost:3000")};export const CONFIG={node_development:process.env.NODE_ENV==="development",...urls,cronJobSecret:ENVS.cronConfig};
@@ -1,5 +1 @@
1
- export const CtrlOrCommandCharacter = ()=>{
2
- const isWindows = typeof window !== "undefined" && window.navigator.userAgent.includes("Windows");
3
- const key = isWindows ? "Ctrl" : "⌘";
4
- return key;
5
- };
1
+ export const CtrlOrCommandCharacter=()=>{const isWindows=typeof window!=="undefined"&&window.navigator.userAgent.includes("Windows");const key=isWindows?"Ctrl":"⌘";return key};
@@ -1,12 +1 @@
1
- export const cookieFromStringToObject = (str)=>{
2
- return str.map((item)=>Object.fromEntries(item.split("; ").map((v)=>{
3
- const current = v.split(/=(.*)/s).map(decodeURIComponent);
4
- if (current.length === 1) {
5
- return [
6
- current[0],
7
- true
8
- ];
9
- }
10
- return current;
11
- })));
12
- };
1
+ export const cookieFromStringToObject=str=>{return str.map(item=>Object.fromEntries(item.split("; ").map(v=>{const current=v.split(/=(.*)/s).map(decodeURIComponent);if(current.length===1){return[current[0],true]}return current})))};
@@ -1,78 +1 @@
1
- import { describe, expect, it } from "vitest";
2
- import { cookieFromStringToObject } from "./cookie-from-string-to-object.js";
3
- describe("cookieFromStringToObject", ()=>{
4
- it("should parse a simple cookie string", ()=>{
5
- const cookies = [
6
- "token=abc123; Path=/; HttpOnly"
7
- ];
8
- const result = cookieFromStringToObject(cookies);
9
- expect(result).toEqual([
10
- {
11
- token: "abc123",
12
- Path: "/",
13
- HttpOnly: true
14
- }
15
- ]);
16
- });
17
- it("should parse multiple cookie attributes", ()=>{
18
- const cookies = [
19
- "sessionId=xyz789; Domain=example.com; Path=/; HttpOnly; Secure; SameSite=strict; Expires=Wed, 21 Oct 2025 07:28:00 GMT"
20
- ];
21
- const result = cookieFromStringToObject(cookies);
22
- expect(result).toEqual([
23
- {
24
- sessionId: "xyz789",
25
- Domain: "example.com",
26
- Path: "/",
27
- HttpOnly: true,
28
- Secure: true,
29
- SameSite: "strict",
30
- Expires: "Wed, 21 Oct 2025 07:28:00 GMT"
31
- }
32
- ]);
33
- });
34
- it("should handle multiple cookies", ()=>{
35
- const cookies = [
36
- "token=abc123; Path=/; HttpOnly",
37
- "theme=dark; Path=/; SameSite=lax"
38
- ];
39
- const result = cookieFromStringToObject(cookies);
40
- expect(result).toEqual([
41
- {
42
- token: "abc123",
43
- Path: "/",
44
- HttpOnly: true
45
- },
46
- {
47
- theme: "dark",
48
- Path: "/",
49
- SameSite: "lax"
50
- }
51
- ]);
52
- });
53
- it("should handle URL encoded values", ()=>{
54
- const cookies = [
55
- "data=hello%20world; Path=/"
56
- ];
57
- const result = cookieFromStringToObject(cookies);
58
- expect(result).toEqual([
59
- {
60
- data: "hello world",
61
- Path: "/"
62
- }
63
- ]);
64
- });
65
- it("should handle boolean flags without values", ()=>{
66
- const cookies = [
67
- "token=123; HttpOnly; Secure"
68
- ];
69
- const result = cookieFromStringToObject(cookies);
70
- expect(result).toEqual([
71
- {
72
- token: "123",
73
- HttpOnly: true,
74
- Secure: true
75
- }
76
- ]);
77
- });
78
- });
1
+ import{describe,expect,it}from"vitest";import{cookieFromStringToObject}from"./cookie-from-string-to-object.js";describe("cookieFromStringToObject",()=>{it("should parse a simple cookie string",()=>{const cookies=["token=abc123; Path=/; HttpOnly"];const result=cookieFromStringToObject(cookies);expect(result).toEqual([{token:"abc123",Path:"/",HttpOnly:true}])});it("should parse multiple cookie attributes",()=>{const cookies=["sessionId=xyz789; Domain=example.com; Path=/; HttpOnly; Secure; SameSite=strict; Expires=Wed, 21 Oct 2025 07:28:00 GMT"];const result=cookieFromStringToObject(cookies);expect(result).toEqual([{sessionId:"xyz789",Domain:"example.com",Path:"/",HttpOnly:true,Secure:true,SameSite:"strict",Expires:"Wed, 21 Oct 2025 07:28:00 GMT"}])});it("should handle multiple cookies",()=>{const cookies=["token=abc123; Path=/; HttpOnly","theme=dark; Path=/; SameSite=lax"];const result=cookieFromStringToObject(cookies);expect(result).toEqual([{token:"abc123",Path:"/",HttpOnly:true},{theme:"dark",Path:"/",SameSite:"lax"}])});it("should handle URL encoded values",()=>{const cookies=["data=hello%20world; Path=/"];const result=cookieFromStringToObject(cookies);expect(result).toEqual([{data:"hello world",Path:"/"}])});it("should handle boolean flags without values",()=>{const cookies=["token=123; HttpOnly; Secure"];const result=cookieFromStringToObject(cookies);expect(result).toEqual([{token:"123",HttpOnly:true,Secure:true}])})});
@@ -1,48 +1,3 @@
1
- import { CONFIG } from "../config.js";
2
- import { buildSearchParams } from "./helpers.js";
3
- export async function coreFetcher({ pluginId }, { path, method, module, args, options, additionalHeaders = {}, withPagination = false, prefixPath = "" }) {
4
- let currentPath = path;
5
- // Replace path parameters
6
- if (args && "params" in args && args.params) {
7
- for (const [key, value] of Object.entries(args.params)){
8
- currentPath = currentPath.replaceAll(`{${key}}`, String(value));
9
- }
10
- }
11
- // Ensure path starts with a slash
12
- const formattedPath = currentPath.startsWith("/") ? currentPath : `/${currentPath}`;
13
- // Construct the base URL
14
- const url = new URL(`/api/${pluginId}${prefixPath}/${module}${formattedPath === "/" ? "" : formattedPath}`, CONFIG.api.origin);
15
- // Add query parameters if they exist
16
- if (args && "query" in args && args.query) {
17
- const queryParams = args.query;
18
- const searchParams = buildSearchParams({
19
- ...args.query,
20
- ...withPagination && {
21
- first: queryParams.last ? undefined : queryParams.first ?? "10",
22
- search: queryParams.search ?? ""
23
- }
24
- });
25
- url.search = searchParams.toString();
26
- }
27
- // Build headers
28
- const headers = new Headers({
29
- "Content-Type": "application/json",
30
- ...additionalHeaders
31
- });
32
- const response = await fetch(url, {
33
- method: method.toUpperCase(),
34
- headers,
35
- body: args && "body" in args ? JSON.stringify(args.body) : undefined,
36
- ...options
37
- });
38
- if (response.status === 500) {
39
- const errorText = await response.text();
40
- throw new Error(`${response.status} - ${url.toString()}\n${response.statusText ?? errorText}`);
41
- }
42
- if (response.status >= 400) {
43
- const errorText = await response.text();
44
- // eslint-disable-next-line no-console
45
- console.error(`\x1b[34m[VitNode - API]\x1b[0m \x1b[31m${response.status}\x1b[0m - \x1b[33m${url.toString()}\x1b[0m\n\x1b[36mError: ${errorText}\x1b[0m`);
46
- }
47
- return response;
48
- }
1
+ import{CONFIG}from"../config.js";import{buildSearchParams}from"./helpers.js";export async function coreFetcher({pluginId},{path,method,module,args,options,additionalHeaders={},withPagination=false,prefixPath=""}){let currentPath=path;if(args&&"params"in args&&args.params){for(const[key,value]of Object.entries(args.params)){currentPath=currentPath.replaceAll(`{${key}}`,String(value))}}const formattedPath=currentPath.startsWith("/")?currentPath:`/${currentPath}`;const url=new URL(`/api/${pluginId}${prefixPath}/${module}${formattedPath==="/"?"":formattedPath}`,CONFIG.api.origin);if(args&&"query"in args&&args.query){const queryParams=args.query;const searchParams=buildSearchParams({...args.query,...withPagination&&{first:queryParams.last?undefined:queryParams.first??"10",search:queryParams.search??""}});url.search=searchParams.toString()}const headers=new Headers({"Content-Type":"application/json",...additionalHeaders});const response=await fetch(url,{method:method.toUpperCase(),headers,body:args&&"body"in args?JSON.stringify(args.body):undefined,...options});if(response.status===500){const errorText=await response.text();throw new Error(`${response.status} - ${url.toString()}
2
+ ${response.statusText??errorText}`)}if(response.status>=400){const errorText=await response.text();console.error(`\x1b[34m[VitNode - API]\x1b[0m \x1b[31m${response.status}\x1b[0m - \x1b[33m${url.toString()}\x1b[0m
3
+ \x1b[36mError: ${errorText}\x1b[0m`)}return response}
@@ -1,18 +1 @@
1
- import "server-only";
2
- import { cookies } from "next/headers";
3
- import { cookieFromStringToObject } from "./cookie-from-string-to-object.js";
4
- export const handleSetCookiesFetcher = async (res)=>{
5
- await Promise.all(cookieFromStringToObject(res.headers.getSetCookie()).map(async (cookie)=>{
6
- const key = Object.keys(cookie)[0];
7
- const value = Object.values(cookie)[0];
8
- if (typeof value !== "string" || typeof key !== "string") return;
9
- (await cookies()).set(key, value, {
10
- domain: cookie.Domain,
11
- path: cookie.Path,
12
- expires: new Date(cookie.Expires),
13
- secure: cookie.Secure,
14
- httpOnly: cookie.HttpOnly,
15
- sameSite: cookie.SameSite
16
- });
17
- }));
18
- };
1
+ import"server-only";import{cookies}from"next/headers";import{cookieFromStringToObject}from"./cookie-from-string-to-object.js";export const handleSetCookiesFetcher=async res=>{await Promise.all(cookieFromStringToObject(res.headers.getSetCookie()).map(async cookie=>{const key=Object.keys(cookie)[0];const value=Object.values(cookie)[0];if(typeof value!=="string"||typeof key!=="string")return;(await cookies()).set(key,value,{domain:cookie.Domain,path:cookie.Path,expires:new Date(cookie.Expires),secure:cookie.Secure,httpOnly:cookie.HttpOnly,sameSite:cookie.SameSite})}))};
@@ -1,16 +1 @@
1
- export const buildSearchParams = (query)=>{
2
- const searchParams = new URLSearchParams();
3
- for (const [k, v] of Object.entries(query)){
4
- if (v === undefined) {
5
- continue;
6
- }
7
- if (Array.isArray(v)) {
8
- for (const v2 of v){
9
- searchParams.append(k, v2);
10
- }
11
- } else {
12
- searchParams.set(k, v);
13
- }
14
- }
15
- return searchParams;
16
- };
1
+ export const buildSearchParams=query=>{const searchParams=new URLSearchParams;for(const[k,v]of Object.entries(query)){if(v===undefined){continue}if(Array.isArray(v)){for(const v2 of v){searchParams.append(k,v2)}}else{searchParams.set(k,v)}}return searchParams};
@@ -1,37 +1 @@
1
- import { describe, expect, it } from "vitest";
2
- import { buildSearchParams } from "./helpers.js";
3
- describe("buildSearchParams", ()=>{
4
- it("should handle empty query object", ()=>{
5
- const params = buildSearchParams({});
6
- expect(params.toString()).toBe("");
7
- });
8
- it("should handle single string values", ()=>{
9
- const params = buildSearchParams({
10
- key: "value"
11
- });
12
- expect(params.toString()).toBe("key=value");
13
- });
14
- it("should handle multiple string values", ()=>{
15
- const params = buildSearchParams({
16
- key1: "value1",
17
- key2: "value2"
18
- });
19
- expect(params.toString()).toBe("key1=value1&key2=value2");
20
- });
21
- it("should handle array values", ()=>{
22
- const params = buildSearchParams({
23
- key: [
24
- "value1",
25
- "value2"
26
- ]
27
- });
28
- expect(params.toString()).toBe("key=value1&key=value2");
29
- });
30
- it("should skip undefined values", ()=>{
31
- const params = buildSearchParams({
32
- key1: "value1",
33
- key2: undefined
34
- });
35
- expect(params.toString()).toBe("key1=value1");
36
- });
37
- });
1
+ import{describe,expect,it}from"vitest";import{buildSearchParams}from"./helpers.js";describe("buildSearchParams",()=>{it("should handle empty query object",()=>{const params=buildSearchParams({});expect(params.toString()).toBe("")});it("should handle single string values",()=>{const params=buildSearchParams({key:"value"});expect(params.toString()).toBe("key=value")});it("should handle multiple string values",()=>{const params=buildSearchParams({key1:"value1",key2:"value2"});expect(params.toString()).toBe("key1=value1&key2=value2")});it("should handle array values",()=>{const params=buildSearchParams({key:["value1","value2"]});expect(params.toString()).toBe("key=value1&key=value2")});it("should skip undefined values",()=>{const params=buildSearchParams({key1:"value1",key2:undefined});expect(params.toString()).toBe("key1=value1")})});
@@ -1 +1 @@
1
- export { };
1
+ export{};
@@ -1,17 +1 @@
1
- import { coreFetcher } from "./fetcher/core.js";
2
- export async function fetcherClient(moduleReturn, { path, method, module, args, options, withPagination = false, prefixPath = "", captchaToken }) {
3
- const additionalHeaders = {};
4
- if (captchaToken) {
5
- additionalHeaders["x-vitnode-captcha-token"] = captchaToken;
6
- }
7
- return await coreFetcher(moduleReturn, {
8
- path,
9
- method,
10
- module,
11
- args,
12
- options,
13
- withPagination,
14
- prefixPath,
15
- additionalHeaders
16
- });
17
- }
1
+ import{coreFetcher}from"./fetcher/core.js";export async function fetcherClient(moduleReturn,{path,method,module,args,options,withPagination=false,prefixPath="",captchaToken}){const additionalHeaders={};if(captchaToken){additionalHeaders["x-vitnode-captcha-token"]=captchaToken}return await coreFetcher(moduleReturn,{path,method,module,args,options,withPagination,prefixPath,additionalHeaders})}
@@ -1,33 +1 @@
1
- import "server-only";
2
- import { cookies, headers } from "next/headers";
3
- import { coreFetcher } from "./fetcher/core.js";
4
- import { handleSetCookiesFetcher } from "./fetcher/helpers-server.js";
5
- export async function fetcher(moduleReturn, { path, method, module, args, options, allowSaveCookies = false, withPagination = false, prefixPath = "", captchaToken }) {
6
- const [nextInternalHeaders, cookie] = await Promise.all([
7
- headers(),
8
- cookies()
9
- ]);
10
- const additionalHeaders = {
11
- Cookie: cookie.toString(),
12
- ["user-agent"]: nextInternalHeaders.get("user-agent") ?? "node",
13
- ["x-forwarded-for"]: nextInternalHeaders.get("x-forwarded-for") ?? "0.0.0.0"
14
- };
15
- if (captchaToken) {
16
- additionalHeaders["x-vitnode-captcha-token"] = captchaToken;
17
- }
18
- const response = await coreFetcher(moduleReturn, {
19
- path,
20
- method,
21
- module,
22
- args,
23
- options,
24
- withPagination,
25
- prefixPath,
26
- additionalHeaders
27
- });
28
- // Handle cookies on server-side for successful responses
29
- if (response.status >= 200 && response.status < 300 && allowSaveCookies) {
30
- await handleSetCookiesFetcher(response);
31
- }
32
- return response;
33
- }
1
+ import"server-only";import{cookies,headers}from"next/headers";import{coreFetcher}from"./fetcher/core.js";import{handleSetCookiesFetcher}from"./fetcher/helpers-server.js";export async function fetcher(moduleReturn,{path,method,module,args,options,allowSaveCookies=false,withPagination=false,prefixPath="",captchaToken}){const[nextInternalHeaders,cookie]=await Promise.all([headers(),cookies()]);const additionalHeaders={Cookie:cookie.toString(),["user-agent"]:nextInternalHeaders.get("user-agent")??"node",["x-forwarded-for"]:nextInternalHeaders.get("x-forwarded-for")??"0.0.0.0"};if(captchaToken){additionalHeaders["x-vitnode-captcha-token"]=captchaToken}const response=await coreFetcher(moduleReturn,{path,method,module,args,options,withPagination,prefixPath,additionalHeaders});if(response.status>=200&&response.status<300&&allowSaveCookies){await handleSetCookiesFetcher(response)}return response}