@kyro-cms/core 0.10.4 → 0.10.6

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 (301) hide show
  1. package/dist/api-handler-graphql.cjs +1 -49
  2. package/dist/api-handler-graphql.js +1 -46
  3. package/dist/api-handler-trpc.cjs +1 -38
  4. package/dist/api-handler-trpc.js +1 -36
  5. package/dist/api-handler.cjs +1 -44
  6. package/dist/api-handler.js +1 -27
  7. package/dist/bootstrap-HIAV5ZFT.cjs +1 -0
  8. package/dist/bootstrap-P7QPQYQP.js +1 -0
  9. package/dist/chunk-2BTRHVT3.cjs +20 -0
  10. package/dist/chunk-2W4FK6CJ.js +122 -0
  11. package/dist/chunk-4ORJMSJU.cjs +1 -0
  12. package/dist/chunk-65G73T7Z.cjs +2 -0
  13. package/dist/chunk-7N6NKCRT.js +1 -0
  14. package/dist/chunk-7WOX27LK.js +259 -0
  15. package/dist/chunk-AE6GXUT7.js +1 -0
  16. package/dist/chunk-AJAZ7D3W.cjs +259 -0
  17. package/dist/chunk-ATLSIYRH.cjs +1 -0
  18. package/dist/chunk-AU6IWTBO.js +2 -0
  19. package/dist/chunk-CDL7ARXT.js +133 -0
  20. package/dist/chunk-CUTFS6N2.cjs +1 -0
  21. package/dist/chunk-CVVW4LXZ.cjs +1 -0
  22. package/dist/chunk-DGJUBN33.js +1 -0
  23. package/dist/chunk-DV4LFLPL.cjs +1 -0
  24. package/dist/chunk-EEWCANFX.js +1 -0
  25. package/dist/chunk-ELICKLFM.cjs +3 -0
  26. package/dist/chunk-EQUQJBPP.cjs +2 -0
  27. package/dist/chunk-ET6NN2V2.cjs +122 -0
  28. package/dist/chunk-F7P36SLX.cjs +74 -0
  29. package/dist/chunk-F7SR5IDT.cjs +1 -0
  30. package/dist/chunk-FO3HLBC7.js +1 -0
  31. package/dist/chunk-FS7GL2BR.js +73 -0
  32. package/dist/chunk-G6A7OSIG.js +2 -0
  33. package/dist/chunk-GFU7AOI3.cjs +1 -0
  34. package/dist/chunk-GYQMNXXW.cjs +114 -0
  35. package/dist/chunk-HLSB2MCK.js +1 -0
  36. package/dist/chunk-HVXO3OFB.cjs +1 -0
  37. package/dist/chunk-IFJJ44OQ.cjs +133 -0
  38. package/dist/chunk-ISWMETHJ.cjs +1 -0
  39. package/dist/chunk-K6WUOU6P.js +1 -0
  40. package/dist/chunk-KDNYHLD2.js +1 -0
  41. package/dist/chunk-KIW36TG7.cjs +86 -0
  42. package/dist/chunk-L6CZYN3L.cjs +20 -0
  43. package/dist/chunk-LRGAPGG3.js +74 -0
  44. package/dist/chunk-LZ6YFYQM.js +20 -0
  45. package/dist/chunk-MIOMMB23.cjs +1 -0
  46. package/dist/chunk-NGBJKZMT.js +90 -0
  47. package/dist/chunk-NRLIGDYF.js +1 -0
  48. package/dist/chunk-NY47CFVP.cjs +1 -0
  49. package/dist/chunk-NZ35PV5R.js +2 -0
  50. package/dist/chunk-OG7CNQGU.js +1 -0
  51. package/dist/chunk-OQD3WG6Z.cjs +1 -0
  52. package/dist/chunk-P7CESLDJ.js +1 -0
  53. package/dist/chunk-PP5S2UBV.js +0 -0
  54. package/dist/chunk-Q3Q7BJVQ.cjs +1 -0
  55. package/dist/chunk-Q4CSLXCO.cjs +90 -0
  56. package/dist/chunk-QRXDCV6K.js +0 -0
  57. package/dist/chunk-R7DVVXXI.cjs +73 -0
  58. package/dist/chunk-RHCWCG3O.js +114 -0
  59. package/dist/chunk-SL3LZQCF.js +1 -0
  60. package/dist/chunk-UBHFUFD4.cjs +1 -0
  61. package/dist/chunk-UBRYJP2G.js +1 -0
  62. package/dist/chunk-UDSJGML2.cjs +2 -0
  63. package/dist/chunk-UHFDH3PG.js +20 -0
  64. package/dist/chunk-UJNSOOYZ.cjs +1 -0
  65. package/dist/chunk-URCLFIME.js +86 -0
  66. package/dist/chunk-UVTS2IWM.js +1 -0
  67. package/dist/chunk-V65NPSR5.cjs +1 -0
  68. package/dist/chunk-WIZ6C5QZ.cjs +1 -0
  69. package/dist/chunk-ZAQOSRP6.js +1 -0
  70. package/dist/chunk-ZELCS7IC.js +3 -0
  71. package/dist/cli/index.cjs +35 -405
  72. package/dist/cli/index.js +35 -402
  73. package/dist/client.cjs +1 -55
  74. package/dist/client.js +1 -6
  75. package/dist/drizzle/index.cjs +1 -50
  76. package/dist/drizzle/index.d.cts +1 -2
  77. package/dist/drizzle/index.d.ts +1 -2
  78. package/dist/drizzle/index.js +1 -9
  79. package/dist/fields/index.cjs +1 -89
  80. package/dist/fields/index.js +1 -4
  81. package/dist/graphql/index.cjs +1 -31
  82. package/dist/graphql/index.d.cts +1 -1
  83. package/dist/graphql/index.d.ts +1 -1
  84. package/dist/graphql/index.js +1 -6
  85. package/dist/{index-jLs0zlft.d.ts → index-DXr33e0x.d.ts} +1 -1
  86. package/dist/{index-DHbywDs-.d.cts → index-DuuUzWBq.d.cts} +1 -1
  87. package/dist/index.cjs +29 -2464
  88. package/dist/index.d.cts +2 -2
  89. package/dist/index.d.ts +2 -2
  90. package/dist/index.js +29 -1929
  91. package/dist/integration.cjs +1 -10
  92. package/dist/integration.js +1 -4
  93. package/dist/media-NSSMOB7N.cjs +1 -0
  94. package/dist/media-RNMCZYPZ.js +1 -0
  95. package/dist/mongo-auth-adapter-JYJ4GBZE.cjs +1 -0
  96. package/dist/mongo-auth-adapter-XI7EPURZ.js +1 -0
  97. package/dist/mongodb/index.cjs +1 -29
  98. package/dist/mongodb/index.d.cts +1 -2
  99. package/dist/mongodb/index.d.ts +1 -2
  100. package/dist/mongodb/index.js +1 -8
  101. package/dist/postgres-auth-adapter-E7OGMDD4.cjs +1 -0
  102. package/dist/postgres-auth-adapter-F4KLOGAG.js +1 -0
  103. package/dist/redis-adapter-AQJVABYT.cjs +1 -0
  104. package/dist/redis-adapter-AUKOV74G.js +1 -0
  105. package/dist/rest/index.cjs +1 -31
  106. package/dist/rest/index.d.cts +1 -1
  107. package/dist/rest/index.d.ts +1 -1
  108. package/dist/rest/index.js +1 -18
  109. package/dist/schema-5XNROI7I.js +1 -0
  110. package/dist/schema-6O4JTJRU.cjs +1 -0
  111. package/dist/sqlite-adapter-5XFLNJDH.js +1 -0
  112. package/dist/sqlite-adapter-W53Q32N5.cjs +1 -0
  113. package/dist/templates/index.cjs +1 -207
  114. package/dist/templates/index.js +1 -6
  115. package/dist/trpc/index.cjs +1 -48
  116. package/dist/trpc/index.js +1 -7
  117. package/dist/ws/index.cjs +1 -25
  118. package/dist/ws/index.js +1 -4
  119. package/package.json +44 -13
  120. package/dist/api-handler-graphql.cjs.map +0 -1
  121. package/dist/api-handler-graphql.js.map +0 -1
  122. package/dist/api-handler-trpc.cjs.map +0 -1
  123. package/dist/api-handler-trpc.js.map +0 -1
  124. package/dist/api-handler.cjs.map +0 -1
  125. package/dist/api-handler.js.map +0 -1
  126. package/dist/bootstrap-FUAPY2OF.cjs +0 -32
  127. package/dist/bootstrap-FUAPY2OF.cjs.map +0 -1
  128. package/dist/bootstrap-OXNVM7FP.js +0 -7
  129. package/dist/bootstrap-OXNVM7FP.js.map +0 -1
  130. package/dist/chunk-2HFJUUFZ.js +0 -250
  131. package/dist/chunk-2HFJUUFZ.js.map +0 -1
  132. package/dist/chunk-3AKCVYDB.js +0 -162
  133. package/dist/chunk-3AKCVYDB.js.map +0 -1
  134. package/dist/chunk-3KTWGODI.cjs +0 -178
  135. package/dist/chunk-3KTWGODI.cjs.map +0 -1
  136. package/dist/chunk-3YELQL7Z.cjs +0 -4
  137. package/dist/chunk-3YELQL7Z.cjs.map +0 -1
  138. package/dist/chunk-4CV4JOE5.js +0 -24
  139. package/dist/chunk-4CV4JOE5.js.map +0 -1
  140. package/dist/chunk-4OCMVGEY.cjs +0 -173
  141. package/dist/chunk-4OCMVGEY.cjs.map +0 -1
  142. package/dist/chunk-4PWRCMTQ.cjs +0 -15
  143. package/dist/chunk-4PWRCMTQ.cjs.map +0 -1
  144. package/dist/chunk-53NYVYVX.js +0 -3243
  145. package/dist/chunk-53NYVYVX.js.map +0 -1
  146. package/dist/chunk-5GFQPHGT.cjs +0 -156
  147. package/dist/chunk-5GFQPHGT.cjs.map +0 -1
  148. package/dist/chunk-5RPRLTTN.js +0 -861
  149. package/dist/chunk-5RPRLTTN.js.map +0 -1
  150. package/dist/chunk-74YSDAWE.cjs +0 -2749
  151. package/dist/chunk-74YSDAWE.cjs.map +0 -1
  152. package/dist/chunk-7OGPN7MP.js +0 -352
  153. package/dist/chunk-7OGPN7MP.js.map +0 -1
  154. package/dist/chunk-7OS7TX2Q.cjs +0 -495
  155. package/dist/chunk-7OS7TX2Q.cjs.map +0 -1
  156. package/dist/chunk-ADLJSJSN.cjs +0 -13
  157. package/dist/chunk-ADLJSJSN.cjs.map +0 -1
  158. package/dist/chunk-B6X3LN25.cjs +0 -6486
  159. package/dist/chunk-B6X3LN25.cjs.map +0 -1
  160. package/dist/chunk-BYBMTIMT.js +0 -419
  161. package/dist/chunk-BYBMTIMT.js.map +0 -1
  162. package/dist/chunk-CF7OL6HR.js +0 -355
  163. package/dist/chunk-CF7OL6HR.js.map +0 -1
  164. package/dist/chunk-CJX74IYK.js +0 -489
  165. package/dist/chunk-CJX74IYK.js.map +0 -1
  166. package/dist/chunk-CKVOU6MX.cjs +0 -52
  167. package/dist/chunk-CKVOU6MX.cjs.map +0 -1
  168. package/dist/chunk-CZLDE2OZ.cjs +0 -28
  169. package/dist/chunk-CZLDE2OZ.cjs.map +0 -1
  170. package/dist/chunk-DPA3KWPY.cjs +0 -205
  171. package/dist/chunk-DPA3KWPY.cjs.map +0 -1
  172. package/dist/chunk-EEJUFDMF.cjs +0 -424
  173. package/dist/chunk-EEJUFDMF.cjs.map +0 -1
  174. package/dist/chunk-FIAMXNTH.js +0 -220
  175. package/dist/chunk-FIAMXNTH.js.map +0 -1
  176. package/dist/chunk-GAOXD3XT.js +0 -175
  177. package/dist/chunk-GAOXD3XT.js.map +0 -1
  178. package/dist/chunk-GTGRLD4Y.js +0 -3
  179. package/dist/chunk-GTGRLD4Y.js.map +0 -1
  180. package/dist/chunk-GUUB5EAG.cjs +0 -223
  181. package/dist/chunk-GUUB5EAG.cjs.map +0 -1
  182. package/dist/chunk-GXFOGU7N.cjs +0 -359
  183. package/dist/chunk-GXFOGU7N.cjs.map +0 -1
  184. package/dist/chunk-GZS4LMR7.js +0 -422
  185. package/dist/chunk-GZS4LMR7.js.map +0 -1
  186. package/dist/chunk-HY6B7B5A.js +0 -150
  187. package/dist/chunk-HY6B7B5A.js.map +0 -1
  188. package/dist/chunk-HZOMOK5Y.js +0 -2728
  189. package/dist/chunk-HZOMOK5Y.js.map +0 -1
  190. package/dist/chunk-IDVRRRAK.cjs +0 -824
  191. package/dist/chunk-IDVRRRAK.cjs.map +0 -1
  192. package/dist/chunk-KC2GDBLS.cjs +0 -84
  193. package/dist/chunk-KC2GDBLS.cjs.map +0 -1
  194. package/dist/chunk-L4EZKIEX.js +0 -185
  195. package/dist/chunk-L4EZKIEX.js.map +0 -1
  196. package/dist/chunk-LNTFRAHF.cjs +0 -473
  197. package/dist/chunk-LNTFRAHF.cjs.map +0 -1
  198. package/dist/chunk-MTIRYI7F.cjs +0 -4
  199. package/dist/chunk-MTIRYI7F.cjs.map +0 -1
  200. package/dist/chunk-N4GN6Q3V.cjs +0 -869
  201. package/dist/chunk-N4GN6Q3V.cjs.map +0 -1
  202. package/dist/chunk-N4H37VN4.cjs +0 -259
  203. package/dist/chunk-N4H37VN4.cjs.map +0 -1
  204. package/dist/chunk-N5QSHUA6.js +0 -1135
  205. package/dist/chunk-N5QSHUA6.js.map +0 -1
  206. package/dist/chunk-NKPKR5BW.cjs +0 -188
  207. package/dist/chunk-NKPKR5BW.cjs.map +0 -1
  208. package/dist/chunk-OIRG6ZRV.cjs +0 -1073
  209. package/dist/chunk-OIRG6ZRV.cjs.map +0 -1
  210. package/dist/chunk-OJ2AM75W.cjs +0 -253
  211. package/dist/chunk-OJ2AM75W.cjs.map +0 -1
  212. package/dist/chunk-OLV7K22H.js +0 -6457
  213. package/dist/chunk-OLV7K22H.js.map +0 -1
  214. package/dist/chunk-OX6GOIPH.js +0 -516
  215. package/dist/chunk-OX6GOIPH.js.map +0 -1
  216. package/dist/chunk-P2YW545G.js +0 -11
  217. package/dist/chunk-P2YW545G.js.map +0 -1
  218. package/dist/chunk-PHJRNPHY.cjs +0 -3291
  219. package/dist/chunk-PHJRNPHY.cjs.map +0 -1
  220. package/dist/chunk-Q72BOAPK.js +0 -817
  221. package/dist/chunk-Q72BOAPK.js.map +0 -1
  222. package/dist/chunk-QU2RFFH4.js +0 -3
  223. package/dist/chunk-QU2RFFH4.js.map +0 -1
  224. package/dist/chunk-RP7VZUEL.js +0 -49
  225. package/dist/chunk-RP7VZUEL.js.map +0 -1
  226. package/dist/chunk-SHTTJMLT.cjs +0 -361
  227. package/dist/chunk-SHTTJMLT.cjs.map +0 -1
  228. package/dist/chunk-SX76DNOO.js +0 -103
  229. package/dist/chunk-SX76DNOO.js.map +0 -1
  230. package/dist/chunk-THBQG64D.cjs +0 -425
  231. package/dist/chunk-THBQG64D.cjs.map +0 -1
  232. package/dist/chunk-TQG7G7YI.cjs +0 -526
  233. package/dist/chunk-TQG7G7YI.cjs.map +0 -1
  234. package/dist/chunk-U3VVLYXG.cjs +0 -189
  235. package/dist/chunk-U3VVLYXG.cjs.map +0 -1
  236. package/dist/chunk-UUDTPZX6.js +0 -193
  237. package/dist/chunk-UUDTPZX6.js.map +0 -1
  238. package/dist/chunk-V5AWATUP.js +0 -1059
  239. package/dist/chunk-V5AWATUP.js.map +0 -1
  240. package/dist/chunk-VAXLFZCV.cjs +0 -110
  241. package/dist/chunk-VAXLFZCV.cjs.map +0 -1
  242. package/dist/chunk-VKREAIBA.cjs +0 -1139
  243. package/dist/chunk-VKREAIBA.cjs.map +0 -1
  244. package/dist/chunk-WDTTHKDS.js +0 -458
  245. package/dist/chunk-WDTTHKDS.js.map +0 -1
  246. package/dist/chunk-WXVB364T.js +0 -218
  247. package/dist/chunk-WXVB364T.js.map +0 -1
  248. package/dist/chunk-X4BPPD6K.js +0 -181
  249. package/dist/chunk-X4BPPD6K.js.map +0 -1
  250. package/dist/chunk-XEB7PH2E.js +0 -81
  251. package/dist/chunk-XEB7PH2E.js.map +0 -1
  252. package/dist/chunk-YT7HXXVN.js +0 -13
  253. package/dist/chunk-YT7HXXVN.js.map +0 -1
  254. package/dist/cli/index.cjs.map +0 -1
  255. package/dist/cli/index.js.map +0 -1
  256. package/dist/client.cjs.map +0 -1
  257. package/dist/client.js.map +0 -1
  258. package/dist/drizzle/index.cjs.map +0 -1
  259. package/dist/drizzle/index.js.map +0 -1
  260. package/dist/fields/index.cjs.map +0 -1
  261. package/dist/fields/index.js.map +0 -1
  262. package/dist/graphql/index.cjs.map +0 -1
  263. package/dist/graphql/index.js.map +0 -1
  264. package/dist/index.cjs.map +0 -1
  265. package/dist/index.js.map +0 -1
  266. package/dist/integration.cjs.map +0 -1
  267. package/dist/integration.js.map +0 -1
  268. package/dist/media-7WDX4BDJ.js +0 -4
  269. package/dist/media-7WDX4BDJ.js.map +0 -1
  270. package/dist/media-TUSLVRQ6.cjs +0 -17
  271. package/dist/media-TUSLVRQ6.cjs.map +0 -1
  272. package/dist/mongo-auth-adapter-GT4S7SCU.cjs +0 -17
  273. package/dist/mongo-auth-adapter-GT4S7SCU.cjs.map +0 -1
  274. package/dist/mongo-auth-adapter-M7VV4LNB.js +0 -4
  275. package/dist/mongo-auth-adapter-M7VV4LNB.js.map +0 -1
  276. package/dist/mongodb/index.cjs.map +0 -1
  277. package/dist/mongodb/index.js.map +0 -1
  278. package/dist/postgres-auth-adapter-AFAPISH7.js +0 -5
  279. package/dist/postgres-auth-adapter-AFAPISH7.js.map +0 -1
  280. package/dist/postgres-auth-adapter-SFDTLONT.cjs +0 -14
  281. package/dist/postgres-auth-adapter-SFDTLONT.cjs.map +0 -1
  282. package/dist/redis-adapter-UQX4EE3B.cjs +0 -13
  283. package/dist/redis-adapter-UQX4EE3B.cjs.map +0 -1
  284. package/dist/redis-adapter-XALOGWY3.js +0 -4
  285. package/dist/redis-adapter-XALOGWY3.js.map +0 -1
  286. package/dist/rest/index.cjs.map +0 -1
  287. package/dist/rest/index.js.map +0 -1
  288. package/dist/schema-6QL3USNB.cjs +0 -67
  289. package/dist/schema-6QL3USNB.cjs.map +0 -1
  290. package/dist/schema-FNNWEAAW.js +0 -6
  291. package/dist/schema-FNNWEAAW.js.map +0 -1
  292. package/dist/sqlite-adapter-AQB5TCGV.cjs +0 -13
  293. package/dist/sqlite-adapter-AQB5TCGV.cjs.map +0 -1
  294. package/dist/sqlite-adapter-N5H6IM2X.js +0 -4
  295. package/dist/sqlite-adapter-N5H6IM2X.js.map +0 -1
  296. package/dist/templates/index.cjs.map +0 -1
  297. package/dist/templates/index.js.map +0 -1
  298. package/dist/trpc/index.cjs.map +0 -1
  299. package/dist/trpc/index.js.map +0 -1
  300. package/dist/ws/index.cjs.map +0 -1
  301. package/dist/ws/index.js.map +0 -1
@@ -1,1135 +0,0 @@
1
- import { settings } from './chunk-YT7HXXVN.js';
2
-
3
- // src/config/ConfigService.ts
4
- var _settingsTableEnsured = false;
5
- var ConfigService = class _ConfigService {
6
- db;
7
- cache = {};
8
- loaded = false;
9
- static SENSITIVE_KEYS = [
10
- "storage.s3.secret_access_key",
11
- "storage.r2.secret_access_key",
12
- "storage.gcs.private_key",
13
- "storage.backblaze.application_key",
14
- "storage.wasabi.secret_access_key",
15
- "storage.ftp.password",
16
- "storage.bunny.api_key",
17
- "storage.cloudinary.api_secret",
18
- "storage.imgix.sign_key",
19
- "email.smtp.pass",
20
- "auth.jwt_secret",
21
- "auth.github_secret",
22
- "auth.google_secret",
23
- "auth.app_secret",
24
- "database.url",
25
- "redis.url",
26
- "auth.admin_password"
27
- ];
28
- constructor(db) {
29
- this.db = db;
30
- }
31
- /**
32
- * Initialize the service by loading all settings from the database
33
- */
34
- async load() {
35
- if (this.loaded) return;
36
- await this.ensureSettingsTable();
37
- try {
38
- if (typeof this.db?.select === "function") {
39
- const allSettings = await this.db.select().from(settings);
40
- this.cache = allSettings.reduce((acc, row) => {
41
- acc[row.key] = row.value;
42
- return acc;
43
- }, {});
44
- }
45
- await this.loadFromGlobals();
46
- } catch (error) {
47
- console.warn(
48
- "ConfigService: Could not load settings from database, using environment fallbacks."
49
- );
50
- }
51
- this.loaded = true;
52
- }
53
- async ensureSettingsTable() {
54
- if (_settingsTableEnsured) return;
55
- try {
56
- if (typeof this.db?.execute === "function") {
57
- const { sql } = await import('drizzle-orm');
58
- await this.db.execute(sql`
59
- CREATE TABLE IF NOT EXISTS "settings" (
60
- "key" VARCHAR(255) PRIMARY KEY,
61
- "value" TEXT NOT NULL,
62
- "description" TEXT,
63
- "updated_at" TIMESTAMP DEFAULT NOW()
64
- )
65
- `);
66
- _settingsTableEnsured = true;
67
- } else if (typeof this.db?.exec === "function") {
68
- this.db.exec(`
69
- CREATE TABLE IF NOT EXISTS settings (
70
- key TEXT PRIMARY KEY,
71
- value TEXT NOT NULL,
72
- description TEXT,
73
- updated_at TEXT
74
- )
75
- `);
76
- _settingsTableEnsured = true;
77
- }
78
- } catch {
79
- }
80
- }
81
- /**
82
- * Load settings from the _globals_storage-settings table (SQLite fallback)
83
- * Maps nested global structure to flat key-value cache
84
- */
85
- async loadFromGlobals() {
86
- try {
87
- let row = null;
88
- if (typeof this.db?.execute === "function") {
89
- const { sql } = await import('drizzle-orm');
90
- const variants = ['"_globals_storage-settings"', '"_globals_storage_settings"', '"global_storage_settings"'];
91
- for (const name of variants) {
92
- try {
93
- const result = await this.db.execute(sql`SELECT * FROM ${sql.raw(name)} LIMIT 1`);
94
- row = Array.isArray(result) ? result[0] : result?.rows ? result.rows[0] : null;
95
- if (row) break;
96
- } catch {
97
- }
98
- }
99
- } else if (typeof this.db?.prepare === "function") {
100
- const variants = ['"_globals_storage-settings"', '"_globals_storage_settings"', '"global_storage_settings"'];
101
- for (const name of variants) {
102
- try {
103
- row = this.db.prepare(`SELECT * FROM ${name} LIMIT 1`).get();
104
- if (row) break;
105
- } catch {
106
- }
107
- }
108
- }
109
- if (!row) return;
110
- const parseJSON = (val) => {
111
- if (!val) return null;
112
- if (typeof val === "string") {
113
- try {
114
- return JSON.parse(val);
115
- } catch {
116
- return null;
117
- }
118
- }
119
- return val;
120
- };
121
- const provider = row.provider || "local";
122
- this.cache["storage.type"] = provider === "aws" ? "s3" : provider;
123
- if (provider === "local") {
124
- const local = parseJSON(row.local);
125
- this.cache["storage.local.dir"] = local?.uploadDir || "./public/uploads";
126
- this.cache["storage.local.url"] = local?.baseUrl || "/uploads";
127
- }
128
- if (provider === "aws") {
129
- const aws = parseJSON(row.aws);
130
- this.cache["storage.s3.bucket"] = aws?.bucket || "";
131
- this.cache["storage.s3.region"] = aws?.region || "us-east-1";
132
- this.cache["storage.s3.access_key_id"] = aws?.accessKeyId || "";
133
- this.cache["storage.s3.secret_access_key"] = aws?.secretAccessKey || "";
134
- this.cache["storage.s3.endpoint"] = aws?.endpoint || "";
135
- this.cache["storage.s3.cdn_url"] = aws?.cdnUrl || "";
136
- this.cache["storage.s3.prefix"] = aws?.prefix || "";
137
- }
138
- if (provider === "r2") {
139
- const r2 = parseJSON(row.r2);
140
- this.cache["storage.r2.account_id"] = r2?.accountId || "";
141
- this.cache["storage.r2.access_key_id"] = r2?.accessKeyId || "";
142
- this.cache["storage.r2.secret_access_key"] = r2?.secretAccessKey || "";
143
- this.cache["storage.r2.bucket"] = r2?.bucket || "";
144
- this.cache["storage.r2.cdn_url"] = r2?.cdnUrl || "";
145
- this.cache["storage.r2.prefix"] = r2?.prefix || "";
146
- }
147
- if (provider === "cloudinary") {
148
- const cloudinary = parseJSON(row.cloudinary);
149
- this.cache["storage.cloudinary.cloud_name"] = cloudinary?.cloudName || "";
150
- this.cache["storage.cloudinary.api_key"] = cloudinary?.apiKey || "";
151
- this.cache["storage.cloudinary.api_secret"] = cloudinary?.apiSecret || "";
152
- this.cache["storage.cloudinary.folder"] = cloudinary?.folder || "";
153
- }
154
- if (provider === "ftp") {
155
- const ftp = parseJSON(row.ftp);
156
- this.cache["storage.ftp.host"] = ftp?.host || "";
157
- this.cache["storage.ftp.port"] = String(ftp?.port || "21");
158
- this.cache["storage.ftp.user"] = ftp?.user || "";
159
- this.cache["storage.ftp.password"] = ftp?.password || "";
160
- this.cache["storage.ftp.secure"] = ftp?.secure ? "true" : "false";
161
- this.cache["storage.ftp.base_url"] = ftp?.baseUrl || "";
162
- this.cache["storage.ftp.prefix"] = ftp?.prefix || "";
163
- }
164
- } catch (error) {
165
- console.warn("ConfigService: Could not load storage settings from globals table:", error);
166
- }
167
- try {
168
- let row = null;
169
- if (typeof this.db?.execute === "function") {
170
- const { sql } = await import('drizzle-orm');
171
- const variants = ['"_globals_email-settings"', '"_globals_email_settings"', '"global_email_settings"'];
172
- for (const name of variants) {
173
- try {
174
- const result = await this.db.execute(sql`SELECT * FROM ${sql.raw(name)} LIMIT 1`);
175
- row = Array.isArray(result) ? result[0] : result?.rows ? result.rows[0] : null;
176
- if (row) break;
177
- } catch {
178
- }
179
- }
180
- } else if (typeof this.db?.prepare === "function") {
181
- const variants = ['"_globals_email-settings"', '"_globals_email_settings"', '"global_email_settings"'];
182
- for (const name of variants) {
183
- try {
184
- row = this.db.prepare(`SELECT * FROM ${name} LIMIT 1`).get();
185
- if (row) break;
186
- } catch {
187
- }
188
- }
189
- }
190
- if (row) {
191
- const parseJSON = (val) => {
192
- if (!val) return null;
193
- if (typeof val === "string") {
194
- try {
195
- return JSON.parse(val);
196
- } catch {
197
- return null;
198
- }
199
- }
200
- return val;
201
- };
202
- this.cache["email.provider"] = row.provider || "smtp";
203
- this.cache["email.smtp.from"] = row.fromEmail || "";
204
- this.cache["email.smtp.from_name"] = row.fromName || "";
205
- this.cache["email.smtp.reply_to"] = row.replyTo || "";
206
- if (row.provider === "smtp") {
207
- const smtp = parseJSON(row.smtp);
208
- this.cache["email.smtp.host"] = smtp?.host || "";
209
- this.cache["email.smtp.port"] = String(smtp?.port || "587");
210
- this.cache["email.smtp.user"] = smtp?.username || "";
211
- this.cache["email.smtp.pass"] = smtp?.password || "";
212
- this.cache["email.smtp.secure"] = smtp?.secure ? "true" : "false";
213
- } else if (row.provider === "resend") {
214
- const resend = parseJSON(row.resend);
215
- this.cache["email.smtp.pass"] = resend?.apiKey || "";
216
- } else if (row.provider === "sendgrid") {
217
- const sendgrid = parseJSON(row.sendgrid);
218
- this.cache["email.smtp.pass"] = sendgrid?.apiKey || "";
219
- } else if (row.provider === "mailgun") {
220
- const mailgun = parseJSON(row.mailgun);
221
- this.cache["email.smtp.pass"] = mailgun?.apiKey || "";
222
- } else if (row.provider === "ses") {
223
- const ses = parseJSON(row.ses);
224
- this.cache["email.smtp.user"] = ses?.accessKeyId || "";
225
- this.cache["email.smtp.pass"] = ses?.secretAccessKey || "";
226
- }
227
- }
228
- } catch (error) {
229
- console.warn("ConfigService: Could not load email settings from globals table:", error);
230
- }
231
- }
232
- /**
233
- * Get a settings value with environment fallback
234
- */
235
- get(key, envKey, defaultValue) {
236
- if (this.cache[key]) return this.cache[key];
237
- if (envKey && process.env[envKey]) return process.env[envKey];
238
- return defaultValue;
239
- }
240
- /**
241
- * Get storage configuration
242
- */
243
- getStorageConfig() {
244
- return {
245
- type: this.get("storage.type", "STORAGE_TYPE", "local"),
246
- s3: {
247
- bucket: this.get("storage.s3.bucket", "STORAGE_BUCKET"),
248
- region: this.get("storage.s3.region", "STORAGE_REGION", "us-east-1"),
249
- accessKeyId: this.get(
250
- "storage.s3.access_key_id",
251
- "STORAGE_ACCESS_KEY_ID"
252
- ),
253
- secretAccessKey: this.get(
254
- "storage.s3.secret_access_key",
255
- "STORAGE_SECRET_ACCESS_KEY"
256
- ),
257
- endpoint: this.get("storage.s3.endpoint", "STORAGE_ENDPOINT"),
258
- cdnUrl: this.get("storage.s3.cdn_url", "STORAGE_CDN_URL"),
259
- prefix: this.get("storage.s3.prefix", "STORAGE_PREFIX")
260
- },
261
- r2: {
262
- accountId: this.get("storage.r2.account_id", "R2_ACCOUNT_ID"),
263
- accessKeyId: this.get("storage.r2.access_key_id", "R2_ACCESS_KEY_ID"),
264
- secretAccessKey: this.get(
265
- "storage.r2.secret_access_key",
266
- "R2_SECRET_ACCESS_KEY"
267
- ),
268
- bucket: this.get("storage.r2.bucket", "R2_BUCKET"),
269
- cdnUrl: this.get("storage.r2.cdn_url", "R2_CDN_URL"),
270
- prefix: this.get("storage.r2.prefix", "R2_PREFIX")
271
- },
272
- gcs: {
273
- bucket: this.get("storage.gcs.bucket", "GCS_BUCKET"),
274
- projectId: this.get("storage.gcs.project_id", "GCS_PROJECT_ID"),
275
- clientEmail: this.get("storage.gcs.client_email", "GCS_CLIENT_EMAIL"),
276
- privateKey: this.get("storage.gcs.private_key", "GCS_PRIVATE_KEY"),
277
- cdnUrl: this.get("storage.gcs.cdn_url", "GCS_CDN_URL"),
278
- prefix: this.get("storage.gcs.prefix", "GCS_PREFIX")
279
- },
280
- digitalocean: {
281
- bucket: this.get("storage.digitalocean.bucket", "DO_BUCKET"),
282
- region: this.get("storage.digitalocean.region", "DO_REGION", "nyc3"),
283
- accessKeyId: this.get(
284
- "storage.digitalocean.access_key_id",
285
- "DO_ACCESS_KEY_ID"
286
- ),
287
- secretAccessKey: this.get(
288
- "storage.digitalocean.secret_access_key",
289
- "DO_SECRET_ACCESS_KEY"
290
- ),
291
- cdnUrl: this.get("storage.digitalocean.cdn_url", "DO_CDN_URL"),
292
- prefix: this.get("storage.digitalocean.prefix", "DO_PREFIX")
293
- },
294
- backblaze: {
295
- bucket: this.get("storage.backblaze.bucket", "BB_BUCKET"),
296
- accountId: this.get("storage.backblaze.account_id", "BB_ACCOUNT_ID"),
297
- applicationKeyId: this.get(
298
- "storage.backblaze.application_key_id",
299
- "BB_APPLICATION_KEY_ID"
300
- ),
301
- applicationKey: this.get(
302
- "storage.backblaze.application_key",
303
- "BB_APPLICATION_KEY"
304
- ),
305
- cdnUrl: this.get("storage.backblaze.cdn_url", "BB_CDN_URL"),
306
- prefix: this.get("storage.backblaze.prefix", "BB_PREFIX")
307
- },
308
- wasabi: {
309
- bucket: this.get("storage.wasabi.bucket", "WASABI_BUCKET"),
310
- region: this.get("storage.wasabi.region", "WASABI_REGION", "us-east-1"),
311
- accessKeyId: this.get(
312
- "storage.wasabi.access_key_id",
313
- "WASABI_ACCESS_KEY_ID"
314
- ),
315
- secretAccessKey: this.get(
316
- "storage.wasabi.secret_access_key",
317
- "WASABI_SECRET_ACCESS_KEY"
318
- ),
319
- cdnUrl: this.get("storage.wasabi.cdn_url", "WASABI_CDN_URL"),
320
- prefix: this.get("storage.wasabi.prefix", "WASABI_PREFIX")
321
- },
322
- bunny: {
323
- storageZone: this.get(
324
- "storage.bunny.storage_zone",
325
- "BUNNY_STORAGE_ZONE"
326
- ),
327
- apiKey: this.get("storage.bunny.api_key", "BUNNY_API_KEY"),
328
- cdnUrl: this.get("storage.bunny.cdn_url", "BUNNY_CDN_URL"),
329
- prefix: this.get("storage.bunny.prefix", "BUNNY_PREFIX")
330
- },
331
- ftp: {
332
- host: this.get("storage.ftp.host", "FTP_HOST"),
333
- port: parseInt(this.get("storage.ftp.port", "FTP_PORT", "21"), 10),
334
- user: this.get("storage.ftp.user", "FTP_USER"),
335
- password: this.get("storage.ftp.password", "FTP_PASSWORD"),
336
- secure: this.get("storage.ftp.secure", "FTP_SECURE") === "true",
337
- baseUrl: this.get("storage.ftp.base_url", "FTP_BASE_URL"),
338
- prefix: this.get("storage.ftp.prefix", "FTP_PREFIX")
339
- },
340
- cloudinary: {
341
- cloudName: this.get(
342
- "storage.cloudinary.cloud_name",
343
- "CLOUDINARY_CLOUD_NAME"
344
- ),
345
- apiKey: this.get("storage.cloudinary.api_key", "CLOUDINARY_API_KEY"),
346
- apiSecret: this.get(
347
- "storage.cloudinary.api_secret",
348
- "CLOUDINARY_API_SECRET"
349
- ),
350
- folder: this.get("storage.cloudinary.folder", "CLOUDINARY_FOLDER")
351
- },
352
- imgix: {
353
- domain: this.get("storage.imgix.domain", "IMGIX_DOMAIN"),
354
- signKey: this.get("storage.imgix.sign_key", "IMGIX_SIGN_KEY")
355
- },
356
- local: {
357
- uploadDir: this.get("storage.local.dir", "STORAGE_LOCAL_DIR", "./public/uploads"),
358
- baseUrl: this.get("storage.local.url", "STORAGE_LOCAL_URL", "/uploads")
359
- }
360
- };
361
- }
362
- /**
363
- * Get email configuration
364
- */
365
- getEmailConfig() {
366
- return {
367
- provider: this.get("email.provider", "EMAIL_PROVIDER", "smtp"),
368
- host: this.get("email.smtp.host", "SMTP_HOST"),
369
- port: parseInt(this.get("email.smtp.port", "SMTP_PORT", "587"), 10),
370
- secure: this.get("email.smtp.secure", "SMTP_SECURE") === "true",
371
- user: this.get("email.smtp.user", "SMTP_USER"),
372
- pass: this.get("email.smtp.pass", "SMTP_PASS"),
373
- from: this.get("email.smtp.from", "SMTP_FROM", "noreply@example.com"),
374
- fromName: this.get("email.smtp.from_name", "SMTP_FROM_NAME", "Kyro CMS"),
375
- replyTo: this.get("email.smtp.reply_to", "SMTP_REPLY_TO")
376
- };
377
- }
378
- /**
379
- * Mask sensitive values for display
380
- */
381
- maskSensitive(key, value) {
382
- if (!value) return value;
383
- if (_ConfigService.SENSITIVE_KEYS.includes(key)) {
384
- return "********";
385
- }
386
- return value;
387
- }
388
- /**
389
- * Update a setting in the database
390
- */
391
- async set(key, value, description) {
392
- await this.db.insert(settings).values({
393
- key,
394
- value,
395
- description,
396
- updatedAt: /* @__PURE__ */ new Date()
397
- }).onConflictDoUpdate({
398
- target: [settings.key],
399
- set: { value, description, updatedAt: /* @__PURE__ */ new Date() }
400
- });
401
- this.cache[key] = value;
402
- }
403
- };
404
-
405
- // src/auth/nodemailer-transport.ts
406
- var defaultTemplates = {
407
- verifyEmail: (link, userName = "User") => ({
408
- subject: "Verify your email address",
409
- html: `
410
- <!DOCTYPE html>
411
- <html>
412
- <head>
413
- <meta charset="utf-8">
414
- <meta name="viewport" content="width=device-width, initial-scale=1">
415
- <title>Verify Email</title>
416
- <style>
417
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
418
- .container { max-width: 600px; margin: 0 auto; padding: 20px; }
419
- .button { display: inline-block; padding: 12px 24px; background: #0b1222; color: white; text-decoration: none; border-radius: 6px; font-weight: 600; }
420
- .footer { margin-top: 30px; font-size: 12px; color: #666; }
421
- </style>
422
- </head>
423
- <body>
424
- <div class="container">
425
- <h1>Welcome, ${userName}!</h1>
426
- <p>Please verify your email address by clicking the button below:</p>
427
- <p style="text-align: center; margin: 30px 0;">
428
- <a href="${link}" class="button">Verify Email</a>
429
- </p>
430
- <p>Or copy and paste this link into your browser:</p>
431
- <p style="word-break: break-all; color: #666;">${link}</p>
432
- <p>This link will expire in 24 hours.</p>
433
- <div class="footer">
434
- <p>If you didn't create an account, you can safely ignore this email.</p>
435
- </div>
436
- </div>
437
- </body>
438
- </html>
439
- `,
440
- text: `Welcome ${userName}!
441
-
442
- Please verify your email by clicking this link: ${link}
443
-
444
- This link will expire in 24 hours.
445
-
446
- If you didn't create an account, you can safely ignore this email.`
447
- }),
448
- resetPassword: (link, userName = "User") => ({
449
- subject: "Reset your password",
450
- html: `
451
- <!DOCTYPE html>
452
- <html>
453
- <head>
454
- <meta charset="utf-8">
455
- <meta name="viewport" content="width=device-width, initial-scale=1">
456
- <title>Reset Password</title>
457
- <style>
458
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
459
- .container { max-width: 600px; margin: 0 auto; padding: 20px; }
460
- .button { display: inline-block; padding: 12px 24px; background: #dc2626; color: white; text-decoration: none; border-radius: 6px; font-weight: 600; }
461
- .warning { background: #fef3c7; border: 1px solid #f59e0b; padding: 12px; border-radius: 6px; margin: 20px 0; }
462
- .footer { margin-top: 30px; font-size: 12px; color: #666; }
463
- </style>
464
- </head>
465
- <body>
466
- <div class="container">
467
- <h1>Password Reset Request</h1>
468
- <p>Hello ${userName},</p>
469
- <p>We received a request to reset your password. Click the button below to create a new password:</p>
470
- <p style="text-align: center; margin: 30px 0;">
471
- <a href="${link}" class="button">Reset Password</a>
472
- </p>
473
- <p>Or copy and paste this link into your browser:</p>
474
- <p style="word-break: break-all; color: #666;">${link}</p>
475
- <div class="warning">
476
- <strong>\u26A0\uFE0F Important:</strong> This link will expire in 1 hour. If you didn't request a password reset, please ignore this email or contact support if you have concerns.
477
- </div>
478
- <div class="footer">
479
- <p>For security reasons, please don't share this email with anyone.</p>
480
- </div>
481
- </div>
482
- </body>
483
- </html>
484
- `,
485
- text: `Password Reset Request
486
-
487
- Hello ${userName},
488
-
489
- We received a request to reset your password. Click this link to create a new password: ${link}
490
-
491
- This link will expire in 1 hour.
492
-
493
- If you didn't request a password reset, please ignore this email.`
494
- }),
495
- welcome: (userName = "User") => ({
496
- subject: "Welcome to Kyro CMS",
497
- html: `
498
- <!DOCTYPE html>
499
- <html>
500
- <head>
501
- <meta charset="utf-8">
502
- <meta name="viewport" content="width=device-width, initial-scale=1">
503
- <title>Welcome</title>
504
- <style>
505
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
506
- .container { max-width: 600px; margin: 0 auto; padding: 20px; }
507
- .button { display: inline-block; padding: 12px 24px; background: #0b1222; color: white; text-decoration: none; border-radius: 6px; font-weight: 600; }
508
- </style>
509
- </head>
510
- <body>
511
- <div class="container">
512
- <h1>Welcome to Kyro CMS, ${userName}!</h1>
513
- <p>Your account has been created successfully.</p>
514
- <p>You can now:</p>
515
- <ul>
516
- <li>Manage your content collections</li>
517
- <li>Upload and organize media</li>
518
- <li>Configure settings</li>
519
- <li>And much more...</li>
520
- </ul>
521
- <p style="text-align: center; margin: 30px 0;">
522
- <a href="#" class="button">Get Started</a>
523
- </p>
524
- <p>If you have any questions, feel free to reach out to our support team.</p>
525
- </div>
526
- </body>
527
- </html>
528
- `,
529
- text: `Welcome to Kyro CMS, ${userName}!
530
-
531
- Your account has been created successfully.
532
-
533
- You can now:
534
- - Manage your content collections
535
- - Upload and organize media
536
- - Configure settings
537
- - And much more...
538
-
539
- Get started by logging into your dashboard.`
540
- }),
541
- accountLocked: (attempts, duration, userName = "User") => ({
542
- subject: "Account Security Alert - Account Locked",
543
- html: `
544
- <!DOCTYPE html>
545
- <html>
546
- <head>
547
- <meta charset="utf-8">
548
- <meta name="viewport" content="width=device-width, initial-scale=1">
549
- <title>Account Locked</title>
550
- <style>
551
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
552
- .container { max-width: 600px; margin: 0 auto; padding: 20px; }
553
- .alert { background: #fef2f2; border: 1px solid #ef4444; padding: 16px; border-radius: 8px; margin: 20px 0; }
554
- .footer { margin-top: 30px; font-size: 12px; color: #666; }
555
- </style>
556
- </head>
557
- <body>
558
- <div class="container">
559
- <h1>Account Security Alert</h1>
560
- <p>Hello ${userName},</p>
561
- <div class="alert">
562
- <p><strong>\u26A0\uFE0F Your account has been temporarily locked due to multiple failed login attempts.</strong></p>
563
- <p>Failed attempts: ${attempts}</p>
564
- <p>Lockout duration: ${Math.round(duration / 6e4)} minutes</p>
565
- </div>
566
- <p>Your account will automatically unlock after the lockout period expires.</p>
567
- <p>If this wasn't you, we recommend:</p>
568
- <ul>
569
- <li>Using a strong, unique password</li>
570
- <li>Enabling two-factor authentication (coming soon)</li>
571
- <li>Reviewing your recent account activity</li>
572
- </ul>
573
- <div class="footer">
574
- <p>If you need immediate assistance, please contact support.</p>
575
- </div>
576
- </div>
577
- </body>
578
- </html>
579
- `,
580
- text: `Account Security Alert
581
-
582
- Hello ${userName},
583
-
584
- Your account has been temporarily locked due to multiple failed login attempts (${attempts}).
585
-
586
- Lockout duration: ${Math.round(duration / 6e4)} minutes
587
-
588
- Your account will automatically unlock after this period.
589
-
590
- If this wasn't you, we recommend using a strong, unique password.`
591
- }),
592
- passwordChanged: (userName = "User") => ({
593
- subject: "Your password has been changed",
594
- html: `
595
- <!DOCTYPE html>
596
- <html>
597
- <head>
598
- <meta charset="utf-8">
599
- <meta name="viewport" content="width=device-width, initial-scale=1">
600
- <title>Password Changed</title>
601
- <style>
602
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
603
- .container { max-width: 600px; margin: 0 auto; padding: 20px; }
604
- .info { background: #f0fdf4; border: 1px solid #22c55e; padding: 12px; border-radius: 6px; margin: 20px 0; }
605
- </style>
606
- </head>
607
- <body>
608
- <div class="container">
609
- <h1>Password Changed</h1>
610
- <p>Hello ${userName},</p>
611
- <div class="info">
612
- <p>Your password was recently changed.</p>
613
- </div>
614
- <p>If you did this, you can safely ignore this email.</p>
615
- <p><strong>If you didn't change your password</strong>, please contact our support team immediately as your account may have been compromised.</p>
616
- </div>
617
- </body>
618
- </html>
619
- `,
620
- text: `Password Changed
621
-
622
- Hello ${userName},
623
-
624
- Your password was recently changed.
625
-
626
- If you did this, you can safely ignore this email.
627
-
628
- If you didn't change your password, please contact support immediately.`
629
- }),
630
- newLogin: (location, time, userName = "User") => ({
631
- subject: "New login to your account",
632
- html: `
633
- <!DOCTYPE html>
634
- <html>
635
- <head>
636
- <meta charset="utf-8">
637
- <meta name="viewport" content="width=device-width, initial-scale=1">
638
- <title>New Login</title>
639
- <style>
640
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
641
- .container { max-width: 600px; margin: 0 auto; padding: 20px; }
642
- .info-box { background: #f8fafc; border: 1px solid #e2e8f0; padding: 16px; border-radius: 8px; margin: 20px 0; }
643
- .footer { margin-top: 30px; font-size: 12px; color: #666; }
644
- </style>
645
- </head>
646
- <body>
647
- <div class="container">
648
- <h1>New Login Detected</h1>
649
- <p>Hello ${userName},</p>
650
- <p>We detected a new login to your account:</p>
651
- <div class="info-box">
652
- <p><strong>Location:</strong> ${location}</p>
653
- <p><strong>Time:</strong> ${time}</p>
654
- </div>
655
- <p><strong>If this was you</strong>, no action is needed.</p>
656
- <p><strong>If this wasn't you</strong>, your account may be compromised. Please:</p>
657
- <ol>
658
- <li>Change your password immediately</li>
659
- <li>Review your recent account activity</li>
660
- <li>Contact support if needed</li>
661
- </ol>
662
- <div class="footer">
663
- <p>This is an automated security notification.</p>
664
- </div>
665
- </div>
666
- </body>
667
- </html>
668
- `,
669
- text: `New Login Detected
670
-
671
- Hello ${userName},
672
-
673
- We detected a new login to your account:
674
-
675
- Location: ${location}
676
- Time: ${time}
677
-
678
- If this wasn't you, please change your password immediately and contact support.`
679
- })
680
- };
681
- var EmailTransport = class _EmailTransport {
682
- transporter;
683
- config;
684
- templates;
685
- transporterInitialized = false;
686
- constructor(config, templates) {
687
- this.config = config;
688
- this.templates = { ...defaultTemplates, ...templates };
689
- }
690
- async ensureTransporter() {
691
- if (this.transporterInitialized) {
692
- return this.transporter;
693
- }
694
- const { default: nodemailer } = await import('nodemailer');
695
- if (this.config.provider === "smtp" && this.config.smtp) {
696
- this.transporter = nodemailer.createTransport({
697
- host: this.config.smtp.host,
698
- port: this.config.smtp.port,
699
- secure: this.config.smtp.secure,
700
- auth: this.config.smtp.auth
701
- });
702
- } else if (this.config.provider === "ses" && this.config.ses) {
703
- this.transporter = nodemailer.createTransport({
704
- host: `email-smtp.${this.config.ses.region}.amazonaws.com`,
705
- port: 587,
706
- secure: false,
707
- auth: {
708
- user: this.config.ses.accessKeyId,
709
- pass: this.config.ses.secretAccessKey
710
- }
711
- });
712
- }
713
- this.transporterInitialized = true;
714
- return this.transporter;
715
- }
716
- async send(options) {
717
- const { provider, from, fromName, replyTo: configReplyTo } = this.config;
718
- const fromFull = `"${fromName || "Kyro CMS"}" <${from}>`;
719
- const replyTo = options.replyTo || configReplyTo;
720
- try {
721
- let result;
722
- switch (provider) {
723
- case "smtp":
724
- case "ses":
725
- {
726
- const transporter = await this.ensureTransporter();
727
- if (!transporter)
728
- throw new Error(`${provider} transporter not initialized`);
729
- result = await transporter.sendMail({
730
- from: fromFull,
731
- to: Array.isArray(options.to) ? options.to.join(", ") : options.to,
732
- subject: options.subject,
733
- html: options.html,
734
- text: options.text,
735
- replyTo
736
- });
737
- }
738
- break;
739
- case "resend":
740
- result = await this.sendViaResend(fromFull, options, replyTo);
741
- break;
742
- case "sendgrid":
743
- result = await this.sendViaSendGrid(fromFull, options, replyTo);
744
- break;
745
- case "mailgun":
746
- result = await this.sendViaMailgun(fromFull, options, replyTo);
747
- break;
748
- default:
749
- throw new Error(`Unsupported email provider: ${provider}`);
750
- }
751
- return result;
752
- } catch (error) {
753
- console.error(`[EmailTransport] FAILED to send email:`, error.message);
754
- if (error.response) {
755
- console.error(
756
- `[EmailTransport] Provider Error Detail:`,
757
- JSON.stringify(error.response, null, 2)
758
- );
759
- }
760
- throw error;
761
- }
762
- }
763
- async sendViaResend(from, options, replyTo) {
764
- const apiKey = this.config.resend?.apiKey;
765
- if (!apiKey) throw new Error("Resend API Key missing");
766
- const body = {
767
- from,
768
- to: options.to,
769
- subject: options.subject,
770
- html: options.html,
771
- text: options.text,
772
- reply_to: replyTo
773
- };
774
- const resp = await fetch("https://api.resend.com/emails", {
775
- method: "POST",
776
- headers: {
777
- Authorization: `Bearer ${apiKey}`,
778
- "Content-Type": "application/json"
779
- },
780
- body: JSON.stringify(body)
781
- });
782
- if (!resp.ok) {
783
- const error = await resp.json();
784
- throw new Error(`Resend Error: ${JSON.stringify(error)}`);
785
- }
786
- return resp.json();
787
- }
788
- async sendViaSendGrid(from, options, replyTo) {
789
- const apiKey = this.config.sendgrid?.apiKey;
790
- if (!apiKey) throw new Error("SendGrid API Key missing");
791
- const body = {
792
- personalizations: [
793
- {
794
- to: Array.isArray(options.to) ? options.to.map((email) => ({ email })) : [{ email: options.to }]
795
- }
796
- ],
797
- from: {
798
- email: from.match(/<(.+)>/)?.[1] || from,
799
- name: from.match(/"(.+)"/)?.[1]
800
- },
801
- subject: options.subject,
802
- content: [
803
- { type: "text/plain", value: options.text || "" },
804
- { type: "text/html", value: options.html }
805
- ],
806
- reply_to: replyTo ? { email: replyTo } : void 0
807
- };
808
- const resp = await fetch("https://api.sendgrid.com/v3/mail/send", {
809
- method: "POST",
810
- headers: {
811
- Authorization: `Bearer ${apiKey}`,
812
- "Content-Type": "application/json"
813
- },
814
- body: JSON.stringify(body)
815
- });
816
- if (!resp.ok) {
817
- const error = await resp.json();
818
- throw new Error(`SendGrid Error: ${JSON.stringify(error)}`);
819
- }
820
- return { success: true };
821
- }
822
- async sendViaMailgun(from, options, replyTo) {
823
- const { apiKey, domain, region } = this.config.mailgun || {};
824
- if (!apiKey || !domain) throw new Error("Mailgun config missing");
825
- const base = region === "eu" ? "api.eu.mailgun.net" : "api.mailgun.net";
826
- const auth = btoa(`api:${apiKey}`);
827
- const formData = new URLSearchParams();
828
- formData.append("from", from);
829
- const to = Array.isArray(options.to) ? options.to.join(", ") : options.to;
830
- formData.append("to", to);
831
- formData.append("subject", options.subject);
832
- formData.append("html", options.html);
833
- if (options.text) formData.append("text", options.text);
834
- if (replyTo) formData.append("h:Reply-To", replyTo);
835
- const resp = await fetch(`https://${base}/v3/${domain}/messages`, {
836
- method: "POST",
837
- headers: {
838
- Authorization: `Basic ${auth}`,
839
- "Content-Type": "application/x-www-form-urlencoded"
840
- },
841
- body: formData
842
- });
843
- if (!resp.ok) {
844
- const error = await resp.json();
845
- throw new Error(`Mailgun Error: ${JSON.stringify(error)}`);
846
- }
847
- return resp.json();
848
- }
849
- getTemplates() {
850
- return this.templates;
851
- }
852
- async verifyConnection() {
853
- if (this.config.provider === "smtp" || this.config.provider === "ses") {
854
- try {
855
- const transporter = await this.ensureTransporter();
856
- if (transporter) {
857
- await transporter.verify();
858
- return true;
859
- }
860
- } catch {
861
- return false;
862
- }
863
- }
864
- return !!(this.config.resend?.apiKey || this.config.sendgrid?.apiKey || this.config.mailgun?.apiKey);
865
- }
866
- static async fromConfig(db) {
867
- const configService = new ConfigService(db);
868
- await configService.load();
869
- const config = configService.getEmailConfig();
870
- if (!config.provider) {
871
- return this.fromEnv();
872
- }
873
- const transformed = {
874
- provider: config.provider || "smtp",
875
- from: config.from || "noreply@example.com",
876
- fromName: config.fromName,
877
- replyTo: config.replyTo,
878
- smtp: config.provider === "smtp" ? {
879
- host: config.host || "",
880
- port: config.port || 587,
881
- secure: config.secure || false,
882
- auth: { user: config.user || "", pass: config.pass || "" }
883
- } : void 0,
884
- resend: config.provider === "resend" ? { apiKey: config.pass || "" } : void 0,
885
- sendgrid: config.provider === "sendgrid" ? { apiKey: config.pass || "" } : void 0,
886
- mailgun: config.provider === "mailgun" ? {
887
- apiKey: config.pass || "",
888
- domain: config.host || "",
889
- region: config.secure ? "eu" : "us"
890
- } : void 0,
891
- ses: config.provider === "ses" ? {
892
- accessKeyId: config.user || "",
893
- secretAccessKey: config.pass || "",
894
- region: config.host || "us-east-1"
895
- } : void 0
896
- };
897
- return new _EmailTransport(transformed);
898
- }
899
- static fromEnv() {
900
- const provider = process.env.EMAIL_PROVIDER || "smtp";
901
- const from = process.env.SMTP_FROM || process.env.DEFAULT_FROM || "noreply@example.com";
902
- const fromName = process.env.SMTP_FROM_NAME || "Kyro CMS";
903
- const replyTo = process.env.SMTP_REPLY_TO;
904
- if (provider === "smtp") {
905
- const host = process.env.SMTP_HOST;
906
- const user = process.env.SMTP_USER;
907
- const pass = process.env.SMTP_PASS;
908
- if (!host || !user || !pass) return null;
909
- return new _EmailTransport({
910
- provider: "smtp",
911
- from,
912
- fromName,
913
- replyTo,
914
- smtp: {
915
- host,
916
- port: parseInt(process.env.SMTP_PORT || "587", 10),
917
- secure: process.env.SMTP_SECURE === "true",
918
- auth: { user, pass }
919
- }
920
- });
921
- }
922
- if (provider === "resend") {
923
- const apiKey = process.env.RESEND_API_KEY || process.env.SMTP_PASS;
924
- if (!apiKey) return null;
925
- return new _EmailTransport({
926
- provider: "resend",
927
- from,
928
- fromName,
929
- replyTo,
930
- resend: { apiKey }
931
- });
932
- }
933
- if (provider === "sendgrid") {
934
- const apiKey = process.env.SENDGRID_API_KEY || process.env.SMTP_PASS;
935
- if (!apiKey) return null;
936
- return new _EmailTransport({
937
- provider: "sendgrid",
938
- from,
939
- fromName,
940
- replyTo,
941
- sendgrid: { apiKey }
942
- });
943
- }
944
- if (provider === "mailgun") {
945
- const apiKey = process.env.MAILGUN_API_KEY || process.env.SMTP_PASS;
946
- const domain = process.env.MAILGUN_DOMAIN || process.env.SMTP_HOST;
947
- if (!apiKey || !domain) return null;
948
- return new _EmailTransport({
949
- provider: "mailgun",
950
- from,
951
- fromName,
952
- replyTo,
953
- mailgun: {
954
- apiKey,
955
- domain,
956
- region: process.env.MAILGUN_REGION || (process.env.SMTP_SECURE === "true" ? "eu" : "us")
957
- }
958
- });
959
- }
960
- if (provider === "ses") {
961
- const accessKeyId = process.env.AWS_ACCESS_KEY_ID || process.env.SMTP_USER;
962
- const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY || process.env.SMTP_PASS;
963
- const region = process.env.AWS_REGION || process.env.SMTP_HOST || "us-east-1";
964
- if (!accessKeyId || !secretAccessKey) return null;
965
- return new _EmailTransport({
966
- provider: "ses",
967
- from,
968
- fromName,
969
- replyTo,
970
- ses: { accessKeyId, secretAccessKey, region }
971
- });
972
- }
973
- return null;
974
- }
975
- };
976
-
977
- // src/auth/security/password-policy.ts
978
- var DEFAULT_PASSWORD_POLICY = {
979
- minLength: 12,
980
- requireUppercase: true,
981
- requireLowercase: true,
982
- requireNumbers: true,
983
- requireSpecialChars: true,
984
- preventReuse: 5,
985
- maxLength: 128
986
- };
987
- var PasswordPolicy = class {
988
- config;
989
- constructor(config = {}) {
990
- this.config = { ...DEFAULT_PASSWORD_POLICY, ...config };
991
- }
992
- validate(password) {
993
- const errors = [];
994
- if (this.config.maxLength && password.length > this.config.maxLength) {
995
- errors.push(
996
- `Password must not exceed ${this.config.maxLength} characters`
997
- );
998
- }
999
- if (password.length < this.config.minLength) {
1000
- errors.push(
1001
- `Password must be at least ${this.config.minLength} characters`
1002
- );
1003
- }
1004
- if (this.config.requireUppercase && !/[A-Z]/.test(password)) {
1005
- errors.push("Password must contain at least one uppercase letter");
1006
- }
1007
- if (this.config.requireLowercase && !/[a-z]/.test(password)) {
1008
- errors.push("Password must contain at least one lowercase letter");
1009
- }
1010
- if (this.config.requireNumbers && !/[0-9]/.test(password)) {
1011
- errors.push("Password must contain at least one number");
1012
- }
1013
- if (this.config.requireSpecialChars && !/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) {
1014
- errors.push("Password must contain at least one special character");
1015
- }
1016
- const commonPasswords = [
1017
- "password",
1018
- "123456",
1019
- "12345678",
1020
- "qwerty",
1021
- "abc123",
1022
- "monkey",
1023
- "1234567",
1024
- "letmein",
1025
- "trustno1",
1026
- "dragon",
1027
- "baseball",
1028
- "iloveyou",
1029
- "master",
1030
- "sunshine",
1031
- "ashley",
1032
- "football",
1033
- "password1",
1034
- "shadow",
1035
- "123123",
1036
- "654321"
1037
- ];
1038
- if (commonPasswords.includes(password.toLowerCase())) {
1039
- errors.push(
1040
- "This password is too common. Please choose a more secure password"
1041
- );
1042
- }
1043
- if (/^[a-zA-Z]+$/.test(password) || /^[0-9]+$/.test(password)) {
1044
- errors.push(
1045
- "Password must contain a mix of letters, numbers, and/or special characters"
1046
- );
1047
- }
1048
- if (/(.)\1{2,}/.test(password)) {
1049
- errors.push(
1050
- "Password must not contain more than 2 consecutive identical characters"
1051
- );
1052
- }
1053
- if (/^(012|123|234|345|456|567|678|789|890|098|987|876|765|654|543|432|321|210)+$/i.test(
1054
- password
1055
- )) {
1056
- errors.push("Password must not contain sequential numbers or letters");
1057
- }
1058
- return {
1059
- valid: errors.length === 0,
1060
- errors
1061
- };
1062
- }
1063
- async checkReuse(passwordHash, history, verifyFn) {
1064
- return {
1065
- valid: true,
1066
- errors: []
1067
- };
1068
- }
1069
- async isInHistory(password, history, verifyFn) {
1070
- for (const hash of history) {
1071
- if (await verifyFn(password, hash)) {
1072
- return true;
1073
- }
1074
- }
1075
- return false;
1076
- }
1077
- generatePassword(length = 16) {
1078
- const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1079
- const lowercase = "abcdefghijklmnopqrstuvwxyz";
1080
- const numbers = "0123456789";
1081
- const special = "!@#$%^&*()_+-=[]{}|;:,.<>?";
1082
- let password = "";
1083
- password += uppercase[Math.floor(Math.random() * uppercase.length)];
1084
- password += lowercase[Math.floor(Math.random() * lowercase.length)];
1085
- password += numbers[Math.floor(Math.random() * numbers.length)];
1086
- password += special[Math.floor(Math.random() * special.length)];
1087
- const allChars = uppercase + lowercase + numbers + special;
1088
- for (let i = password.length; i < length; i++) {
1089
- password += allChars[Math.floor(Math.random() * allChars.length)];
1090
- }
1091
- return password.split("").sort(() => Math.random() - 0.5).join("");
1092
- }
1093
- getStrength(password) {
1094
- let score = 0;
1095
- const feedback = [];
1096
- if (password.length >= 8) score += 1;
1097
- if (password.length >= 12) score += 1;
1098
- if (password.length >= 16) score += 1;
1099
- if (/[a-z]/.test(password)) score += 1;
1100
- if (/[A-Z]/.test(password)) score += 1;
1101
- if (/[0-9]/.test(password)) score += 1;
1102
- if (/[!@#$%^&*()_+\-=\[\]{}|;:,.<>?]/.test(password)) score += 1;
1103
- if (password.length > 8) score += 1;
1104
- if (password.length > 12) score += 1;
1105
- const uniqueChars = new Set(password).size;
1106
- if (uniqueChars > 6) score += 1;
1107
- if (uniqueChars > 10) score += 1;
1108
- let label;
1109
- if (score <= 3) {
1110
- label = "Weak";
1111
- feedback.push("Add more characters");
1112
- feedback.push("Include uppercase and lowercase letters");
1113
- } else if (score <= 5) {
1114
- label = "Fair";
1115
- feedback.push("Add special characters");
1116
- feedback.push("Consider making it longer");
1117
- } else if (score <= 7) {
1118
- label = "Good";
1119
- feedback.push("Consider making it longer for extra security");
1120
- } else {
1121
- label = "Strong";
1122
- }
1123
- return { score, label, feedback };
1124
- }
1125
- setConfig(config) {
1126
- this.config = { ...this.config, ...config };
1127
- }
1128
- getConfig() {
1129
- return { ...this.config };
1130
- }
1131
- };
1132
-
1133
- export { ConfigService, EmailTransport, PasswordPolicy };
1134
- //# sourceMappingURL=chunk-N5QSHUA6.js.map
1135
- //# sourceMappingURL=chunk-N5QSHUA6.js.map