@qwickapps/server 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (395) hide show
  1. package/README.md +157 -0
  2. package/dist/core/control-panel.d.ts.map +1 -1
  3. package/dist/core/control-panel.js +114 -0
  4. package/dist/core/control-panel.js.map +1 -1
  5. package/dist/core/types.d.ts +19 -0
  6. package/dist/core/types.d.ts.map +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +15 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/plugins/auth/adapter-wrapper.d.ts +47 -0
  12. package/dist/plugins/auth/adapter-wrapper.d.ts.map +1 -0
  13. package/dist/plugins/auth/adapter-wrapper.js +166 -0
  14. package/dist/plugins/auth/adapter-wrapper.js.map +1 -0
  15. package/dist/plugins/auth/adapter-wrapper.test.d.ts +7 -0
  16. package/dist/plugins/auth/adapter-wrapper.test.d.ts.map +1 -0
  17. package/dist/plugins/auth/adapter-wrapper.test.js +303 -0
  18. package/dist/plugins/auth/adapter-wrapper.test.js.map +1 -0
  19. package/dist/plugins/auth/config-store.d.ts +11 -0
  20. package/dist/plugins/auth/config-store.d.ts.map +1 -0
  21. package/dist/plugins/auth/config-store.js +232 -0
  22. package/dist/plugins/auth/config-store.js.map +1 -0
  23. package/dist/plugins/auth/config-store.test.d.ts +7 -0
  24. package/dist/plugins/auth/config-store.test.d.ts.map +1 -0
  25. package/dist/plugins/auth/config-store.test.js +299 -0
  26. package/dist/plugins/auth/config-store.test.js.map +1 -0
  27. package/dist/plugins/auth/env-config.d.ts +51 -1
  28. package/dist/plugins/auth/env-config.d.ts.map +1 -1
  29. package/dist/plugins/auth/env-config.js +640 -7
  30. package/dist/plugins/auth/env-config.js.map +1 -1
  31. package/dist/plugins/auth/index.d.ts +6 -2
  32. package/dist/plugins/auth/index.d.ts.map +1 -1
  33. package/dist/plugins/auth/index.js +5 -1
  34. package/dist/plugins/auth/index.js.map +1 -1
  35. package/dist/plugins/auth/types.d.ts +106 -0
  36. package/dist/plugins/auth/types.d.ts.map +1 -1
  37. package/dist/plugins/bans/bans-plugin.d.ts.map +1 -1
  38. package/dist/plugins/bans/bans-plugin.js +12 -3
  39. package/dist/plugins/bans/bans-plugin.js.map +1 -1
  40. package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts +11 -0
  41. package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts.map +1 -0
  42. package/dist/plugins/devices/__tests__/devices-plugin.test.js +410 -0
  43. package/dist/plugins/devices/__tests__/devices-plugin.test.js.map +1 -0
  44. package/dist/plugins/devices/__tests__/token-utils.test.d.ts +7 -0
  45. package/dist/plugins/devices/__tests__/token-utils.test.d.ts.map +1 -0
  46. package/dist/plugins/devices/__tests__/token-utils.test.js +197 -0
  47. package/dist/plugins/devices/__tests__/token-utils.test.js.map +1 -0
  48. package/dist/plugins/devices/adapters/compute-adapter.d.ts +36 -0
  49. package/dist/plugins/devices/adapters/compute-adapter.d.ts.map +1 -0
  50. package/dist/plugins/devices/adapters/compute-adapter.js +100 -0
  51. package/dist/plugins/devices/adapters/compute-adapter.js.map +1 -0
  52. package/dist/plugins/devices/adapters/index.d.ts +12 -0
  53. package/dist/plugins/devices/adapters/index.d.ts.map +1 -0
  54. package/dist/plugins/devices/adapters/index.js +10 -0
  55. package/dist/plugins/devices/adapters/index.js.map +1 -0
  56. package/dist/plugins/devices/adapters/mobile-adapter.d.ts +41 -0
  57. package/dist/plugins/devices/adapters/mobile-adapter.d.ts.map +1 -0
  58. package/dist/plugins/devices/adapters/mobile-adapter.js +131 -0
  59. package/dist/plugins/devices/adapters/mobile-adapter.js.map +1 -0
  60. package/dist/plugins/devices/devices-plugin.d.ts +70 -0
  61. package/dist/plugins/devices/devices-plugin.d.ts.map +1 -0
  62. package/dist/plugins/devices/devices-plugin.js +453 -0
  63. package/dist/plugins/devices/devices-plugin.js.map +1 -0
  64. package/dist/plugins/devices/index.d.ts +18 -0
  65. package/dist/plugins/devices/index.d.ts.map +1 -0
  66. package/dist/plugins/devices/index.js +18 -0
  67. package/dist/plugins/devices/index.js.map +1 -0
  68. package/dist/plugins/devices/stores/index.d.ts +9 -0
  69. package/dist/plugins/devices/stores/index.d.ts.map +1 -0
  70. package/dist/plugins/devices/stores/index.js +9 -0
  71. package/dist/plugins/devices/stores/index.js.map +1 -0
  72. package/dist/plugins/devices/stores/postgres-store.d.ts +26 -0
  73. package/dist/plugins/devices/stores/postgres-store.d.ts.map +1 -0
  74. package/dist/plugins/devices/stores/postgres-store.js +199 -0
  75. package/dist/plugins/devices/stores/postgres-store.js.map +1 -0
  76. package/dist/plugins/devices/token-utils.d.ts +100 -0
  77. package/dist/plugins/devices/token-utils.d.ts.map +1 -0
  78. package/dist/plugins/devices/token-utils.js +162 -0
  79. package/dist/plugins/devices/token-utils.js.map +1 -0
  80. package/dist/plugins/devices/types.d.ts +307 -0
  81. package/dist/plugins/devices/types.d.ts.map +1 -0
  82. package/dist/plugins/devices/types.js +10 -0
  83. package/dist/plugins/devices/types.js.map +1 -0
  84. package/dist/plugins/index.d.ts +18 -4
  85. package/dist/plugins/index.d.ts.map +1 -1
  86. package/dist/plugins/index.js +16 -2
  87. package/dist/plugins/index.js.map +1 -1
  88. package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts +5 -0
  89. package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts.map +1 -0
  90. package/dist/plugins/notifications/__tests__/notifications-manager.test.js +470 -0
  91. package/dist/plugins/notifications/__tests__/notifications-manager.test.js.map +1 -0
  92. package/dist/plugins/notifications/index.d.ts +71 -0
  93. package/dist/plugins/notifications/index.d.ts.map +1 -0
  94. package/dist/plugins/notifications/index.js +72 -0
  95. package/dist/plugins/notifications/index.js.map +1 -0
  96. package/dist/plugins/notifications/notifications-manager.d.ts +182 -0
  97. package/dist/plugins/notifications/notifications-manager.d.ts.map +1 -0
  98. package/dist/plugins/notifications/notifications-manager.js +610 -0
  99. package/dist/plugins/notifications/notifications-manager.js.map +1 -0
  100. package/dist/plugins/notifications/notifications-plugin.d.ts +83 -0
  101. package/dist/plugins/notifications/notifications-plugin.d.ts.map +1 -0
  102. package/dist/plugins/notifications/notifications-plugin.js +337 -0
  103. package/dist/plugins/notifications/notifications-plugin.js.map +1 -0
  104. package/dist/plugins/notifications/types.d.ts +164 -0
  105. package/dist/plugins/notifications/types.d.ts.map +1 -0
  106. package/dist/plugins/notifications/types.js +9 -0
  107. package/dist/plugins/notifications/types.js.map +1 -0
  108. package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts +12 -0
  109. package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts.map +1 -0
  110. package/dist/plugins/parental/__tests__/parental-plugin.test.js +349 -0
  111. package/dist/plugins/parental/__tests__/parental-plugin.test.js.map +1 -0
  112. package/dist/plugins/parental/adapters/index.d.ts +8 -0
  113. package/dist/plugins/parental/adapters/index.d.ts.map +1 -0
  114. package/dist/plugins/parental/adapters/index.js +7 -0
  115. package/dist/plugins/parental/adapters/index.js.map +1 -0
  116. package/dist/plugins/parental/adapters/kids-adapter.d.ts +24 -0
  117. package/dist/plugins/parental/adapters/kids-adapter.d.ts.map +1 -0
  118. package/dist/plugins/parental/adapters/kids-adapter.js +174 -0
  119. package/dist/plugins/parental/adapters/kids-adapter.js.map +1 -0
  120. package/dist/plugins/parental/index.d.ts +14 -0
  121. package/dist/plugins/parental/index.d.ts.map +1 -0
  122. package/dist/plugins/parental/index.js +15 -0
  123. package/dist/plugins/parental/index.js.map +1 -0
  124. package/dist/plugins/parental/parental-plugin.d.ts +88 -0
  125. package/dist/plugins/parental/parental-plugin.d.ts.map +1 -0
  126. package/dist/plugins/parental/parental-plugin.js +666 -0
  127. package/dist/plugins/parental/parental-plugin.js.map +1 -0
  128. package/dist/plugins/parental/stores/index.d.ts +7 -0
  129. package/dist/plugins/parental/stores/index.d.ts.map +1 -0
  130. package/dist/plugins/parental/stores/index.js +7 -0
  131. package/dist/plugins/parental/stores/index.js.map +1 -0
  132. package/dist/plugins/parental/stores/postgres-store.d.ts +10 -0
  133. package/dist/plugins/parental/stores/postgres-store.d.ts.map +1 -0
  134. package/dist/plugins/parental/stores/postgres-store.js +209 -0
  135. package/dist/plugins/parental/stores/postgres-store.js.map +1 -0
  136. package/dist/plugins/parental/types.d.ts +154 -0
  137. package/dist/plugins/parental/types.d.ts.map +1 -0
  138. package/dist/plugins/parental/types.js +10 -0
  139. package/dist/plugins/parental/types.js.map +1 -0
  140. package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts +11 -0
  141. package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts.map +1 -0
  142. package/dist/plugins/profiles/__tests__/profiles-plugin.test.js +243 -0
  143. package/dist/plugins/profiles/__tests__/profiles-plugin.test.js.map +1 -0
  144. package/dist/plugins/profiles/index.d.ts +12 -0
  145. package/dist/plugins/profiles/index.d.ts.map +1 -0
  146. package/dist/plugins/profiles/index.js +13 -0
  147. package/dist/plugins/profiles/index.js.map +1 -0
  148. package/dist/plugins/profiles/profiles-plugin.d.ts +71 -0
  149. package/dist/plugins/profiles/profiles-plugin.d.ts.map +1 -0
  150. package/dist/plugins/profiles/profiles-plugin.js +481 -0
  151. package/dist/plugins/profiles/profiles-plugin.js.map +1 -0
  152. package/dist/plugins/profiles/stores/index.d.ts +9 -0
  153. package/dist/plugins/profiles/stores/index.d.ts.map +1 -0
  154. package/dist/plugins/profiles/stores/index.js +9 -0
  155. package/dist/plugins/profiles/stores/index.js.map +1 -0
  156. package/dist/plugins/profiles/stores/postgres-store.d.ts +18 -0
  157. package/dist/plugins/profiles/stores/postgres-store.d.ts.map +1 -0
  158. package/dist/plugins/profiles/stores/postgres-store.js +310 -0
  159. package/dist/plugins/profiles/stores/postgres-store.js.map +1 -0
  160. package/dist/plugins/profiles/types.d.ts +289 -0
  161. package/dist/plugins/profiles/types.d.ts.map +1 -0
  162. package/dist/plugins/profiles/types.js +10 -0
  163. package/dist/plugins/profiles/types.js.map +1 -0
  164. package/dist/plugins/rate-limit/__tests__/rate-limit-plugin.test.d.ts +7 -0
  165. package/dist/plugins/rate-limit/__tests__/rate-limit-plugin.test.d.ts.map +1 -0
  166. package/dist/plugins/rate-limit/__tests__/rate-limit-plugin.test.js +220 -0
  167. package/dist/plugins/rate-limit/__tests__/rate-limit-plugin.test.js.map +1 -0
  168. package/dist/plugins/rate-limit/cleanup.d.ts +40 -0
  169. package/dist/plugins/rate-limit/cleanup.d.ts.map +1 -0
  170. package/dist/plugins/rate-limit/cleanup.js +72 -0
  171. package/dist/plugins/rate-limit/cleanup.js.map +1 -0
  172. package/dist/plugins/rate-limit/env-config.d.ts +91 -0
  173. package/dist/plugins/rate-limit/env-config.d.ts.map +1 -0
  174. package/dist/plugins/rate-limit/env-config.js +318 -0
  175. package/dist/plugins/rate-limit/env-config.js.map +1 -0
  176. package/dist/plugins/rate-limit/index.d.ts +76 -0
  177. package/dist/plugins/rate-limit/index.d.ts.map +1 -0
  178. package/dist/plugins/rate-limit/index.js +79 -0
  179. package/dist/plugins/rate-limit/index.js.map +1 -0
  180. package/dist/plugins/rate-limit/middleware.d.ts +40 -0
  181. package/dist/plugins/rate-limit/middleware.d.ts.map +1 -0
  182. package/dist/plugins/rate-limit/middleware.js +169 -0
  183. package/dist/plugins/rate-limit/middleware.js.map +1 -0
  184. package/dist/plugins/rate-limit/rate-limit-plugin.d.ts +44 -0
  185. package/dist/plugins/rate-limit/rate-limit-plugin.d.ts.map +1 -0
  186. package/dist/plugins/rate-limit/rate-limit-plugin.js +354 -0
  187. package/dist/plugins/rate-limit/rate-limit-plugin.js.map +1 -0
  188. package/dist/plugins/rate-limit/rate-limit-service.d.ts +110 -0
  189. package/dist/plugins/rate-limit/rate-limit-service.d.ts.map +1 -0
  190. package/dist/plugins/rate-limit/rate-limit-service.js +172 -0
  191. package/dist/plugins/rate-limit/rate-limit-service.js.map +1 -0
  192. package/dist/plugins/rate-limit/stores/cache-store.d.ts +33 -0
  193. package/dist/plugins/rate-limit/stores/cache-store.d.ts.map +1 -0
  194. package/dist/plugins/rate-limit/stores/cache-store.js +225 -0
  195. package/dist/plugins/rate-limit/stores/cache-store.js.map +1 -0
  196. package/dist/plugins/rate-limit/stores/index.d.ts +8 -0
  197. package/dist/plugins/rate-limit/stores/index.d.ts.map +1 -0
  198. package/dist/plugins/rate-limit/stores/index.js +8 -0
  199. package/dist/plugins/rate-limit/stores/index.js.map +1 -0
  200. package/dist/plugins/rate-limit/stores/postgres-store.d.ts +34 -0
  201. package/dist/plugins/rate-limit/stores/postgres-store.d.ts.map +1 -0
  202. package/dist/plugins/rate-limit/stores/postgres-store.js +320 -0
  203. package/dist/plugins/rate-limit/stores/postgres-store.js.map +1 -0
  204. package/dist/plugins/rate-limit/strategies/fixed-window.d.ts +21 -0
  205. package/dist/plugins/rate-limit/strategies/fixed-window.d.ts.map +1 -0
  206. package/dist/plugins/rate-limit/strategies/fixed-window.js +97 -0
  207. package/dist/plugins/rate-limit/strategies/fixed-window.js.map +1 -0
  208. package/dist/plugins/rate-limit/strategies/index.d.ts +14 -0
  209. package/dist/plugins/rate-limit/strategies/index.d.ts.map +1 -0
  210. package/dist/plugins/rate-limit/strategies/index.js +27 -0
  211. package/dist/plugins/rate-limit/strategies/index.js.map +1 -0
  212. package/dist/plugins/rate-limit/strategies/sliding-window.d.ts +22 -0
  213. package/dist/plugins/rate-limit/strategies/sliding-window.d.ts.map +1 -0
  214. package/dist/plugins/rate-limit/strategies/sliding-window.js +122 -0
  215. package/dist/plugins/rate-limit/strategies/sliding-window.js.map +1 -0
  216. package/dist/plugins/rate-limit/strategies/token-bucket.d.ts +28 -0
  217. package/dist/plugins/rate-limit/strategies/token-bucket.d.ts.map +1 -0
  218. package/dist/plugins/rate-limit/strategies/token-bucket.js +121 -0
  219. package/dist/plugins/rate-limit/strategies/token-bucket.js.map +1 -0
  220. package/dist/plugins/rate-limit/types.d.ts +265 -0
  221. package/dist/plugins/rate-limit/types.d.ts.map +1 -0
  222. package/dist/plugins/rate-limit/types.js +9 -0
  223. package/dist/plugins/rate-limit/types.js.map +1 -0
  224. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts +11 -0
  225. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts.map +1 -0
  226. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js +305 -0
  227. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js.map +1 -0
  228. package/dist/plugins/subscriptions/index.d.ts +12 -0
  229. package/dist/plugins/subscriptions/index.d.ts.map +1 -0
  230. package/dist/plugins/subscriptions/index.js +13 -0
  231. package/dist/plugins/subscriptions/index.js.map +1 -0
  232. package/dist/plugins/subscriptions/stores/index.d.ts +9 -0
  233. package/dist/plugins/subscriptions/stores/index.d.ts.map +1 -0
  234. package/dist/plugins/subscriptions/stores/index.js +9 -0
  235. package/dist/plugins/subscriptions/stores/index.js.map +1 -0
  236. package/dist/plugins/subscriptions/stores/postgres-store.d.ts +14 -0
  237. package/dist/plugins/subscriptions/stores/postgres-store.d.ts.map +1 -0
  238. package/dist/plugins/subscriptions/stores/postgres-store.js +359 -0
  239. package/dist/plugins/subscriptions/stores/postgres-store.js.map +1 -0
  240. package/dist/plugins/subscriptions/subscriptions-plugin.d.ts +82 -0
  241. package/dist/plugins/subscriptions/subscriptions-plugin.d.ts.map +1 -0
  242. package/dist/plugins/subscriptions/subscriptions-plugin.js +449 -0
  243. package/dist/plugins/subscriptions/subscriptions-plugin.js.map +1 -0
  244. package/dist/plugins/subscriptions/types.d.ts +308 -0
  245. package/dist/plugins/subscriptions/types.d.ts.map +1 -0
  246. package/dist/plugins/subscriptions/types.js +10 -0
  247. package/dist/plugins/subscriptions/types.js.map +1 -0
  248. package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts +11 -0
  249. package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts.map +1 -0
  250. package/dist/plugins/usage/__tests__/usage-plugin.test.js +218 -0
  251. package/dist/plugins/usage/__tests__/usage-plugin.test.js.map +1 -0
  252. package/dist/plugins/usage/index.d.ts +12 -0
  253. package/dist/plugins/usage/index.d.ts.map +1 -0
  254. package/dist/plugins/usage/index.js +13 -0
  255. package/dist/plugins/usage/index.js.map +1 -0
  256. package/dist/plugins/usage/stores/index.d.ts +9 -0
  257. package/dist/plugins/usage/stores/index.d.ts.map +1 -0
  258. package/dist/plugins/usage/stores/index.js +9 -0
  259. package/dist/plugins/usage/stores/index.js.map +1 -0
  260. package/dist/plugins/usage/stores/postgres-store.d.ts +14 -0
  261. package/dist/plugins/usage/stores/postgres-store.d.ts.map +1 -0
  262. package/dist/plugins/usage/stores/postgres-store.js +146 -0
  263. package/dist/plugins/usage/stores/postgres-store.js.map +1 -0
  264. package/dist/plugins/usage/types.d.ts +195 -0
  265. package/dist/plugins/usage/types.d.ts.map +1 -0
  266. package/dist/plugins/usage/types.js +10 -0
  267. package/dist/plugins/usage/types.js.map +1 -0
  268. package/dist/plugins/usage/usage-plugin.d.ts +51 -0
  269. package/dist/plugins/usage/usage-plugin.d.ts.map +1 -0
  270. package/dist/plugins/usage/usage-plugin.js +412 -0
  271. package/dist/plugins/usage/usage-plugin.js.map +1 -0
  272. package/dist/plugins/users/__tests__/postgres-store.test.d.ts +10 -0
  273. package/dist/plugins/users/__tests__/postgres-store.test.d.ts.map +1 -0
  274. package/dist/plugins/users/__tests__/postgres-store.test.js +229 -0
  275. package/dist/plugins/users/__tests__/postgres-store.test.js.map +1 -0
  276. package/dist/plugins/users/__tests__/users-plugin.test.js +3 -0
  277. package/dist/plugins/users/__tests__/users-plugin.test.js.map +1 -1
  278. package/dist/plugins/users/index.d.ts +2 -2
  279. package/dist/plugins/users/index.d.ts.map +1 -1
  280. package/dist/plugins/users/index.js +1 -1
  281. package/dist/plugins/users/index.js.map +1 -1
  282. package/dist/plugins/users/stores/postgres-store.d.ts.map +1 -1
  283. package/dist/plugins/users/stores/postgres-store.js +76 -0
  284. package/dist/plugins/users/stores/postgres-store.js.map +1 -1
  285. package/dist/plugins/users/types.d.ts +74 -6
  286. package/dist/plugins/users/types.d.ts.map +1 -1
  287. package/dist/plugins/users/users-plugin.d.ts +15 -1
  288. package/dist/plugins/users/users-plugin.d.ts.map +1 -1
  289. package/dist/plugins/users/users-plugin.js +29 -0
  290. package/dist/plugins/users/users-plugin.js.map +1 -1
  291. package/dist-ui/assets/index-CynOqPkb.js +469 -0
  292. package/dist-ui/assets/{index-BY8OxNgO.js.map → index-CynOqPkb.js.map} +1 -1
  293. package/dist-ui/index.html +1 -1
  294. package/dist-ui-lib/api/controlPanelApi.d.ts +187 -0
  295. package/dist-ui-lib/components/StatCard.d.ts +16 -0
  296. package/dist-ui-lib/dashboard/widgets/AuthStatusWidget.d.ts +9 -0
  297. package/dist-ui-lib/dashboard/widgets/IntegrationStatusWidget.d.ts +9 -0
  298. package/dist-ui-lib/dashboard/widgets/NotificationsStatsWidget.d.ts +12 -0
  299. package/dist-ui-lib/dashboard/widgets/index.d.ts +3 -0
  300. package/dist-ui-lib/index.js +3579 -2379
  301. package/dist-ui-lib/index.js.map +1 -1
  302. package/dist-ui-lib/pages/IntegrationsPage.d.ts +1 -0
  303. package/dist-ui-lib/pages/NotificationsPage.d.ts +9 -0
  304. package/dist-ui-lib/pages/RateLimitPage.d.ts +1 -0
  305. package/dist-ui-lib/utils/formatters.d.ts +19 -0
  306. package/package.json +1 -1
  307. package/src/core/control-panel.ts +128 -0
  308. package/src/core/types.ts +17 -0
  309. package/src/index.ts +216 -0
  310. package/src/plugins/auth/adapter-wrapper.test.ts +395 -0
  311. package/src/plugins/auth/adapter-wrapper.ts +205 -0
  312. package/src/plugins/auth/config-store.test.ts +417 -0
  313. package/src/plugins/auth/config-store.ts +305 -0
  314. package/src/plugins/auth/env-config.ts +714 -7
  315. package/src/plugins/auth/index.ts +22 -1
  316. package/src/plugins/auth/types.ts +138 -0
  317. package/src/plugins/bans/bans-plugin.ts +15 -3
  318. package/src/plugins/devices/__tests__/devices-plugin.test.ts +551 -0
  319. package/src/plugins/devices/__tests__/token-utils.test.ts +264 -0
  320. package/src/plugins/devices/adapters/compute-adapter.ts +139 -0
  321. package/src/plugins/devices/adapters/index.ts +13 -0
  322. package/src/plugins/devices/adapters/mobile-adapter.ts +179 -0
  323. package/src/plugins/devices/devices-plugin.ts +538 -0
  324. package/src/plugins/devices/index.ts +69 -0
  325. package/src/plugins/devices/stores/index.ts +9 -0
  326. package/src/plugins/devices/stores/postgres-store.ts +304 -0
  327. package/src/plugins/devices/token-utils.ts +213 -0
  328. package/src/plugins/devices/types.ts +351 -0
  329. package/src/plugins/index.ts +267 -0
  330. package/src/plugins/notifications/__tests__/notifications-manager.test.ts +637 -0
  331. package/src/plugins/notifications/index.ts +91 -0
  332. package/src/plugins/notifications/notifications-manager.ts +773 -0
  333. package/src/plugins/notifications/notifications-plugin.ts +398 -0
  334. package/src/plugins/notifications/types.ts +207 -0
  335. package/src/plugins/parental/__tests__/parental-plugin.test.ts +465 -0
  336. package/src/plugins/parental/adapters/index.ts +8 -0
  337. package/src/plugins/parental/adapters/kids-adapter.ts +206 -0
  338. package/src/plugins/parental/index.ts +55 -0
  339. package/src/plugins/parental/parental-plugin.ts +759 -0
  340. package/src/plugins/parental/stores/index.ts +7 -0
  341. package/src/plugins/parental/stores/postgres-store.ts +304 -0
  342. package/src/plugins/parental/types.ts +180 -0
  343. package/src/plugins/profiles/__tests__/profiles-plugin.test.ts +321 -0
  344. package/src/plugins/profiles/index.ts +49 -0
  345. package/src/plugins/profiles/profiles-plugin.ts +546 -0
  346. package/src/plugins/profiles/stores/index.ts +9 -0
  347. package/src/plugins/profiles/stores/postgres-store.ts +439 -0
  348. package/src/plugins/profiles/types.ts +338 -0
  349. package/src/plugins/rate-limit/__tests__/rate-limit-plugin.test.ts +259 -0
  350. package/src/plugins/rate-limit/cleanup.ts +117 -0
  351. package/src/plugins/rate-limit/env-config.ts +400 -0
  352. package/src/plugins/rate-limit/index.ts +128 -0
  353. package/src/plugins/rate-limit/middleware.ts +212 -0
  354. package/src/plugins/rate-limit/rate-limit-plugin.ts +400 -0
  355. package/src/plugins/rate-limit/rate-limit-service.ts +228 -0
  356. package/src/plugins/rate-limit/stores/cache-store.ts +261 -0
  357. package/src/plugins/rate-limit/stores/index.ts +8 -0
  358. package/src/plugins/rate-limit/stores/postgres-store.ts +402 -0
  359. package/src/plugins/rate-limit/strategies/fixed-window.ts +116 -0
  360. package/src/plugins/rate-limit/strategies/index.ts +30 -0
  361. package/src/plugins/rate-limit/strategies/sliding-window.ts +157 -0
  362. package/src/plugins/rate-limit/strategies/token-bucket.ts +154 -0
  363. package/src/plugins/rate-limit/types.ts +338 -0
  364. package/src/plugins/subscriptions/__tests__/subscriptions-plugin.test.ts +404 -0
  365. package/src/plugins/subscriptions/index.ts +51 -0
  366. package/src/plugins/subscriptions/stores/index.ts +9 -0
  367. package/src/plugins/subscriptions/stores/postgres-store.ts +482 -0
  368. package/src/plugins/subscriptions/subscriptions-plugin.ts +530 -0
  369. package/src/plugins/subscriptions/types.ts +355 -0
  370. package/src/plugins/usage/__tests__/usage-plugin.test.ts +288 -0
  371. package/src/plugins/usage/index.ts +39 -0
  372. package/src/plugins/usage/stores/index.ts +9 -0
  373. package/src/plugins/usage/stores/postgres-store.ts +213 -0
  374. package/src/plugins/usage/types.ts +222 -0
  375. package/src/plugins/usage/usage-plugin.ts +484 -0
  376. package/src/plugins/users/__tests__/postgres-store.test.ts +326 -0
  377. package/src/plugins/users/__tests__/users-plugin.test.ts +3 -0
  378. package/src/plugins/users/index.ts +6 -0
  379. package/src/plugins/users/stores/postgres-store.ts +104 -0
  380. package/src/plugins/users/types.ts +82 -6
  381. package/src/plugins/users/users-plugin.ts +37 -0
  382. package/ui/src/App.tsx +36 -14
  383. package/ui/src/api/controlPanelApi.ts +329 -6
  384. package/ui/src/components/StatCard.tsx +58 -0
  385. package/ui/src/dashboard/builtInWidgets.tsx +7 -1
  386. package/ui/src/dashboard/widgets/AuthStatusWidget.tsx +143 -0
  387. package/ui/src/dashboard/widgets/IntegrationStatusWidget.tsx +135 -0
  388. package/ui/src/dashboard/widgets/NotificationsStatsWidget.tsx +167 -0
  389. package/ui/src/dashboard/widgets/index.ts +3 -0
  390. package/ui/src/pages/AuthPage.tsx +986 -142
  391. package/ui/src/pages/IntegrationsPage.tsx +288 -0
  392. package/ui/src/pages/NotificationsPage.tsx +417 -0
  393. package/ui/src/pages/RateLimitPage.tsx +292 -0
  394. package/ui/src/utils/formatters.ts +33 -0
  395. package/dist-ui/assets/index-BY8OxNgO.js +0 -465
@@ -18,6 +18,12 @@ let currentStatus = {
18
18
  state: 'disabled',
19
19
  adapter: null,
20
20
  };
21
+ // Runtime configuration store (PostgreSQL-backed)
22
+ let configStore = null;
23
+ // Adapter wrapper for hot-reload support
24
+ let adapterWrapper = null;
25
+ // Unsubscribe function for config change listener
26
+ let configUnsubscribe = null;
21
27
  // ═══════════════════════════════════════════════════════════════════════════
22
28
  // Environment Variable Helpers
23
29
  // ═══════════════════════════════════════════════════════════════════════════
@@ -404,31 +410,301 @@ function getMaskedConfig(adapter) {
404
410
  * Register config API routes
405
411
  */
406
412
  function registerConfigRoutes(registry) {
407
- // GET /api/auth/config/status - Get current auth status
413
+ // GET /auth/config/status - Get current auth status
408
414
  registry.addRoute({
409
415
  method: 'get',
410
- path: '/api/auth/config/status',
416
+ path: '/auth/config/status',
411
417
  pluginId: 'auth',
412
418
  handler: (_req, res) => {
413
419
  res.json(getAuthStatus());
414
420
  },
415
421
  });
416
- // GET /api/auth/config - Get current configuration (masked)
422
+ // GET /auth/config - Get current configuration (masked)
417
423
  registry.addRoute({
418
424
  method: 'get',
419
- path: '/api/auth/config',
425
+ path: '/auth/config',
420
426
  pluginId: 'auth',
421
- handler: (_req, res) => {
427
+ handler: async (_req, res) => {
422
428
  const status = getAuthStatus();
423
- res.json({
429
+ const response = {
424
430
  state: status.state,
425
431
  adapter: status.adapter,
426
432
  config: status.config || {},
427
433
  error: status.error,
428
434
  missingVars: status.missingVars,
429
- });
435
+ };
436
+ // Include runtime config if available from store
437
+ if (configStore) {
438
+ try {
439
+ const runtimeConfig = await configStore.load();
440
+ if (runtimeConfig) {
441
+ response.runtimeConfig = runtimeConfig;
442
+ }
443
+ }
444
+ catch (err) {
445
+ console.error('[AuthPlugin] Failed to load runtime config:', err);
446
+ }
447
+ }
448
+ res.json(response);
449
+ },
450
+ });
451
+ // PUT /auth/config - Save new configuration
452
+ registry.addRoute({
453
+ method: 'put',
454
+ path: '/auth/config',
455
+ pluginId: 'auth',
456
+ handler: async (req, res) => {
457
+ try {
458
+ // Check if config store is available
459
+ if (!configStore) {
460
+ return res.status(503).json({
461
+ error: 'Configuration store not available',
462
+ message: 'Runtime configuration requires a config store (PostgreSQL)',
463
+ });
464
+ }
465
+ // Parse and validate request body
466
+ const body = req.body;
467
+ if (!body || !body.adapter) {
468
+ return res.status(400).json({
469
+ error: 'Invalid request',
470
+ message: 'Request body must include adapter type',
471
+ });
472
+ }
473
+ // Validate adapter type
474
+ if (!VALID_ADAPTERS.includes(body.adapter)) {
475
+ return res.status(400).json({
476
+ error: 'Invalid adapter',
477
+ message: `Valid adapters: ${VALID_ADAPTERS.join(', ')}`,
478
+ });
479
+ }
480
+ // Validate adapter config
481
+ const validation = validateAdapterConfig(body.adapter, body.config || {});
482
+ if (!validation.valid) {
483
+ return res.status(400).json({
484
+ error: 'Invalid configuration',
485
+ message: validation.errors.join(', '),
486
+ errors: validation.errors,
487
+ });
488
+ }
489
+ // Build runtime config
490
+ const runtimeConfig = {
491
+ adapter: body.adapter,
492
+ config: {
493
+ [body.adapter]: body.config,
494
+ },
495
+ settings: body.settings || {},
496
+ updatedAt: new Date().toISOString(),
497
+ };
498
+ // Save to store
499
+ await configStore.save(runtimeConfig);
500
+ // Apply config immediately (hot-reload)
501
+ if (adapterWrapper) {
502
+ const adapter = createAdapterFromConfig(body.adapter, runtimeConfig.config);
503
+ if (adapter) {
504
+ await adapterWrapper.setAdapter(adapter);
505
+ }
506
+ }
507
+ // Update status
508
+ currentStatus = {
509
+ state: 'enabled',
510
+ adapter: body.adapter,
511
+ config: getMaskedRuntimeConfig(runtimeConfig),
512
+ };
513
+ res.json({
514
+ success: true,
515
+ status: getAuthStatus(),
516
+ });
517
+ }
518
+ catch (error) {
519
+ console.error('[AuthPlugin] Failed to save config:', error);
520
+ res.status(500).json({
521
+ error: 'Failed to save configuration',
522
+ message: error instanceof Error ? error.message : 'Unknown error',
523
+ });
524
+ }
525
+ },
526
+ });
527
+ // DELETE /auth/config - Revert to environment variables
528
+ registry.addRoute({
529
+ method: 'delete',
530
+ path: '/auth/config',
531
+ pluginId: 'auth',
532
+ handler: async (_req, res) => {
533
+ try {
534
+ // Check if config store is available
535
+ if (!configStore) {
536
+ return res.status(503).json({
537
+ error: 'Configuration store not available',
538
+ message: 'Runtime configuration requires a config store (PostgreSQL)',
539
+ });
540
+ }
541
+ // Delete from store
542
+ await configStore.delete();
543
+ // Revert to env vars
544
+ const adapterName = getEnv('AUTH_ADAPTER')?.toLowerCase();
545
+ if (adapterName && VALID_ADAPTERS.includes(adapterName)) {
546
+ const parseResult = getParseResultForAdapter(adapterName);
547
+ if (parseResult.config && adapterWrapper) {
548
+ const adapter = createAdapterForName(adapterName, parseResult.config);
549
+ await adapterWrapper.setAdapter(adapter);
550
+ currentStatus = {
551
+ state: 'enabled',
552
+ adapter: adapterName,
553
+ config: getMaskedConfig(adapterName),
554
+ };
555
+ }
556
+ else if (parseResult.errors.length > 0) {
557
+ currentStatus = {
558
+ state: 'error',
559
+ adapter: adapterName,
560
+ error: `Missing env vars: ${parseResult.errors.join(', ')}`,
561
+ missingVars: parseResult.errors,
562
+ };
563
+ }
564
+ }
565
+ else {
566
+ currentStatus = {
567
+ state: 'disabled',
568
+ adapter: null,
569
+ };
570
+ }
571
+ res.json({
572
+ success: true,
573
+ status: getAuthStatus(),
574
+ });
575
+ }
576
+ catch (error) {
577
+ console.error('[AuthPlugin] Failed to delete config:', error);
578
+ res.status(500).json({
579
+ error: 'Failed to delete configuration',
580
+ message: error instanceof Error ? error.message : 'Unknown error',
581
+ });
582
+ }
430
583
  },
431
584
  });
585
+ // POST /auth/test-provider - Test provider connection
586
+ registry.addRoute({
587
+ method: 'post',
588
+ path: '/auth/test-provider',
589
+ pluginId: 'auth',
590
+ handler: async (req, res) => {
591
+ try {
592
+ const body = req.body;
593
+ if (!body || !body.adapter) {
594
+ return res.status(400).json({
595
+ error: 'Invalid request',
596
+ message: 'Request body must include adapter type',
597
+ });
598
+ }
599
+ // Validate adapter type
600
+ if (!VALID_ADAPTERS.includes(body.adapter)) {
601
+ return res.status(400).json({
602
+ error: 'Invalid adapter',
603
+ message: `Valid adapters: ${VALID_ADAPTERS.join(', ')}`,
604
+ });
605
+ }
606
+ // Test the connection
607
+ const result = await testProviderConnection(body.adapter, body.config || {});
608
+ res.json(result);
609
+ }
610
+ catch (error) {
611
+ console.error('[AuthPlugin] Test provider error:', error);
612
+ res.status(500).json({
613
+ success: false,
614
+ message: error instanceof Error ? error.message : 'Unknown error',
615
+ });
616
+ }
617
+ },
618
+ });
619
+ // POST /auth/test-current - Test current auth configuration (env-based or runtime)
620
+ registry.addRoute({
621
+ method: 'post',
622
+ path: '/auth/test-current',
623
+ pluginId: 'auth',
624
+ handler: async (_req, res) => {
625
+ try {
626
+ const status = getAuthStatus();
627
+ if (status.state !== 'enabled' || !status.adapter) {
628
+ return res.status(400).json({
629
+ success: false,
630
+ message: 'No active auth configuration to test',
631
+ });
632
+ }
633
+ // Get the current configuration from env vars
634
+ const adapterName = status.adapter;
635
+ const parseResult = getParseResultForAdapter(adapterName);
636
+ if (parseResult.errors.length > 0) {
637
+ return res.json({
638
+ success: false,
639
+ message: `Missing configuration: ${parseResult.errors.join(', ')}`,
640
+ });
641
+ }
642
+ // Test the connection using the current env-based config
643
+ // Use JSON round-trip for safe conversion to plain object
644
+ const configObj = JSON.parse(JSON.stringify(parseResult.config));
645
+ const result = await testProviderConnection(adapterName, configObj);
646
+ res.json(result);
647
+ }
648
+ catch (error) {
649
+ console.error('[AuthPlugin] Test current provider error:', error);
650
+ res.status(500).json({
651
+ success: false,
652
+ message: error instanceof Error ? error.message : 'Unknown error',
653
+ });
654
+ }
655
+ },
656
+ });
657
+ // Register UI menu item for auth configuration
658
+ registry.addMenuItem({
659
+ pluginId: 'auth',
660
+ id: 'auth:sidebar',
661
+ label: 'Authentication',
662
+ icon: 'security',
663
+ route: '/auth',
664
+ order: 50, // After Entitlements (35)
665
+ });
666
+ // Register page contribution
667
+ registry.addPage({
668
+ pluginId: 'auth',
669
+ id: 'auth:config-page',
670
+ route: '/auth',
671
+ component: 'AuthPage',
672
+ });
673
+ // Register dashboard widget
674
+ registry.addWidget({
675
+ id: 'auth-status',
676
+ title: 'Authentication',
677
+ component: 'AuthStatusWidget',
678
+ priority: 40, // Show before integrations
679
+ showByDefault: true,
680
+ pluginId: 'auth',
681
+ });
682
+ // Register health check for auth provider connection
683
+ const status = getAuthStatus();
684
+ if (status.state === 'enabled' && status.adapter) {
685
+ registry.registerHealthCheck({
686
+ name: `auth-${status.adapter}`,
687
+ type: 'custom',
688
+ check: async () => {
689
+ const currentStatus = getAuthStatus();
690
+ if (currentStatus.state !== 'enabled' || !currentStatus.adapter) {
691
+ return { healthy: false, message: 'Auth not configured' };
692
+ }
693
+ const adapterName = currentStatus.adapter;
694
+ const parseResult = getParseResultForAdapter(adapterName);
695
+ if (parseResult.errors.length > 0) {
696
+ return { healthy: false, message: `Missing config: ${parseResult.errors.join(', ')}` };
697
+ }
698
+ const configObj = JSON.parse(JSON.stringify(parseResult.config));
699
+ const result = await testProviderConnection(adapterName, configObj);
700
+ return {
701
+ healthy: result.success,
702
+ message: result.message,
703
+ details: result.details,
704
+ };
705
+ },
706
+ });
707
+ }
432
708
  }
433
709
  // ═══════════════════════════════════════════════════════════════════════════
434
710
  // Disabled & Error Plugins
@@ -471,6 +747,360 @@ function createErrorPlugin(error) {
471
747
  },
472
748
  };
473
749
  }
750
+ /**
751
+ * Create an adapter from runtime configuration
752
+ */
753
+ function createAdapterFromConfig(adapterType, config) {
754
+ switch (adapterType) {
755
+ case 'supertokens':
756
+ if (config.supertokens) {
757
+ return supertokensAdapter(config.supertokens);
758
+ }
759
+ break;
760
+ case 'auth0':
761
+ if (config.auth0) {
762
+ return auth0Adapter(config.auth0);
763
+ }
764
+ break;
765
+ case 'supabase':
766
+ if (config.supabase) {
767
+ return supabaseAdapter(config.supabase);
768
+ }
769
+ break;
770
+ case 'basic':
771
+ if (config.basic) {
772
+ return basicAdapter(config.basic);
773
+ }
774
+ break;
775
+ }
776
+ return null;
777
+ }
778
+ /**
779
+ * Validate adapter configuration
780
+ */
781
+ function validateAdapterConfig(adapterType, config) {
782
+ const errors = [];
783
+ switch (adapterType) {
784
+ case 'supertokens':
785
+ if (!config.connectionUri)
786
+ errors.push('connectionUri is required');
787
+ if (!config.appName)
788
+ errors.push('appName is required');
789
+ if (!config.apiDomain)
790
+ errors.push('apiDomain is required');
791
+ if (!config.websiteDomain)
792
+ errors.push('websiteDomain is required');
793
+ break;
794
+ case 'auth0':
795
+ if (!config.domain)
796
+ errors.push('domain is required');
797
+ if (!config.clientId)
798
+ errors.push('clientId is required');
799
+ if (!config.clientSecret)
800
+ errors.push('clientSecret is required');
801
+ if (!config.baseUrl)
802
+ errors.push('baseUrl is required');
803
+ if (!config.secret)
804
+ errors.push('secret is required');
805
+ break;
806
+ case 'supabase':
807
+ if (!config.url)
808
+ errors.push('url is required');
809
+ if (!config.anonKey)
810
+ errors.push('anonKey is required');
811
+ break;
812
+ case 'basic':
813
+ if (!config.username)
814
+ errors.push('username is required');
815
+ if (!config.password)
816
+ errors.push('password is required');
817
+ break;
818
+ }
819
+ return { valid: errors.length === 0, errors };
820
+ }
821
+ /**
822
+ * Validate a URL for security (prevent SSRF attacks)
823
+ */
824
+ function validateUrl(urlString) {
825
+ const url = new URL(urlString);
826
+ if (!['http:', 'https:'].includes(url.protocol)) {
827
+ throw new Error('URL must use http or https protocol');
828
+ }
829
+ // Block private/internal IPs (basic SSRF protection)
830
+ const hostname = url.hostname.toLowerCase();
831
+ if (hostname === 'localhost' ||
832
+ hostname === '127.0.0.1' ||
833
+ hostname === '::1' ||
834
+ hostname.startsWith('192.168.') ||
835
+ hostname.startsWith('10.') ||
836
+ hostname.startsWith('172.') ||
837
+ hostname.endsWith('.internal') ||
838
+ hostname.endsWith('.local')) {
839
+ // Allow localhost for dev/testing, but log it
840
+ console.warn(`[AuthPlugin] Testing connection to internal address: ${hostname}`);
841
+ }
842
+ return url;
843
+ }
844
+ /**
845
+ * Test a provider connection
846
+ */
847
+ async function testProviderConnection(adapterType, config) {
848
+ const startTime = Date.now();
849
+ try {
850
+ // Validate config first
851
+ const validation = validateAdapterConfig(adapterType, config);
852
+ if (!validation.valid) {
853
+ return {
854
+ success: false,
855
+ message: `Invalid configuration: ${validation.errors.join(', ')}`,
856
+ };
857
+ }
858
+ // Test connection based on adapter type
859
+ switch (adapterType) {
860
+ case 'supertokens': {
861
+ // Try to connect to Supertokens core
862
+ const connectionUri = config.connectionUri;
863
+ validateUrl(connectionUri); // Validate URL before making request
864
+ const apiKey = config.apiKey;
865
+ const headers = {
866
+ 'Content-Type': 'application/json',
867
+ };
868
+ if (apiKey) {
869
+ headers['api-key'] = apiKey;
870
+ }
871
+ const response = await fetch(`${connectionUri}/apiversion`, { headers });
872
+ if (!response.ok) {
873
+ return {
874
+ success: false,
875
+ message: `Failed to connect to Supertokens core: ${response.status} ${response.statusText}`,
876
+ };
877
+ }
878
+ const data = (await response.json());
879
+ return {
880
+ success: true,
881
+ message: 'Successfully connected to Supertokens core',
882
+ details: {
883
+ latency: Date.now() - startTime,
884
+ version: data.versions?.[0],
885
+ },
886
+ };
887
+ }
888
+ case 'auth0': {
889
+ // Test Auth0 domain is reachable
890
+ const domain = config.domain;
891
+ const response = await fetch(`https://${domain}/.well-known/openid-configuration`);
892
+ if (!response.ok) {
893
+ return {
894
+ success: false,
895
+ message: `Failed to connect to Auth0: ${response.status} ${response.statusText}`,
896
+ };
897
+ }
898
+ return {
899
+ success: true,
900
+ message: 'Successfully connected to Auth0',
901
+ details: {
902
+ latency: Date.now() - startTime,
903
+ },
904
+ };
905
+ }
906
+ case 'supabase': {
907
+ // Test Supabase endpoint
908
+ const url = config.url;
909
+ validateUrl(url); // Validate URL before making request
910
+ const anonKey = config.anonKey;
911
+ const response = await fetch(`${url}/rest/v1/`, {
912
+ headers: {
913
+ apikey: anonKey,
914
+ Authorization: `Bearer ${anonKey}`,
915
+ },
916
+ });
917
+ // Supabase returns 200 even without tables
918
+ if (!response.ok && response.status !== 404) {
919
+ return {
920
+ success: false,
921
+ message: `Failed to connect to Supabase: ${response.status} ${response.statusText}`,
922
+ };
923
+ }
924
+ return {
925
+ success: true,
926
+ message: 'Successfully connected to Supabase',
927
+ details: {
928
+ latency: Date.now() - startTime,
929
+ },
930
+ };
931
+ }
932
+ case 'basic': {
933
+ // Basic auth just validates credentials are present
934
+ return {
935
+ success: true,
936
+ message: 'Basic auth configuration is valid',
937
+ details: {
938
+ latency: Date.now() - startTime,
939
+ },
940
+ };
941
+ }
942
+ default:
943
+ return {
944
+ success: false,
945
+ message: `Unknown adapter type: ${adapterType}`,
946
+ };
947
+ }
948
+ }
949
+ catch (error) {
950
+ // Provide more helpful error messages for common network errors
951
+ let message = 'Connection test failed';
952
+ if (error instanceof Error) {
953
+ const errorWithCause = error;
954
+ if (error.message === 'fetch failed' || errorWithCause.cause) {
955
+ // Network error - server not reachable
956
+ const cause = errorWithCause.cause;
957
+ if (cause?.message?.includes('ECONNREFUSED')) {
958
+ const uri = adapterType === 'supertokens' ? config.connectionUri :
959
+ adapterType === 'supabase' ? config.url :
960
+ adapterType === 'auth0' ? `https://${config.domain}` : 'server';
961
+ message = `Cannot connect to ${adapterType} at ${uri}. Is the server running?`;
962
+ }
963
+ else {
964
+ message = `Network error: Unable to reach the ${adapterType} server. Check if it's running and accessible.`;
965
+ }
966
+ }
967
+ else {
968
+ message = `Connection test failed: ${error.message}`;
969
+ }
970
+ }
971
+ return {
972
+ success: false,
973
+ message,
974
+ };
975
+ }
976
+ }
977
+ /**
978
+ * Handle configuration change (from database)
979
+ * Called when pg_notify fires on another instance
980
+ */
981
+ async function handleConfigChange(newConfig) {
982
+ if (!adapterWrapper)
983
+ return;
984
+ if (!newConfig || !newConfig.adapter) {
985
+ // No config in database - revert to env vars
986
+ const adapterName = getEnv('AUTH_ADAPTER')?.toLowerCase();
987
+ if (adapterName && VALID_ADAPTERS.includes(adapterName)) {
988
+ // Re-create adapter from env vars
989
+ const parseResult = getParseResultForAdapter(adapterName);
990
+ if (parseResult.config) {
991
+ const adapter = createAdapterForName(adapterName, parseResult.config);
992
+ if (adapter) {
993
+ await adapterWrapper.setAdapter(adapter);
994
+ currentStatus = {
995
+ state: 'enabled',
996
+ adapter: adapterName,
997
+ config: getMaskedConfig(adapterName),
998
+ };
999
+ }
1000
+ }
1001
+ }
1002
+ else {
1003
+ // No env config either - disable
1004
+ currentStatus = {
1005
+ state: 'disabled',
1006
+ adapter: null,
1007
+ };
1008
+ }
1009
+ return;
1010
+ }
1011
+ // Apply new config
1012
+ const adapter = createAdapterFromConfig(newConfig.adapter, newConfig.config);
1013
+ if (adapter) {
1014
+ await adapterWrapper.setAdapter(adapter);
1015
+ currentStatus = {
1016
+ state: 'enabled',
1017
+ adapter: newConfig.adapter,
1018
+ config: getMaskedRuntimeConfig(newConfig),
1019
+ };
1020
+ }
1021
+ }
1022
+ /**
1023
+ * Get masked runtime configuration
1024
+ */
1025
+ function getMaskedRuntimeConfig(config) {
1026
+ const result = {};
1027
+ if (!config.adapter)
1028
+ return result;
1029
+ const sensitiveKeys = ['secret', 'password', 'key', 'token', 'anonKey', 'clientSecret', 'apiKey'];
1030
+ const isSensitive = (key) => sensitiveKeys.some((s) => key.toLowerCase().includes(s.toLowerCase()));
1031
+ // Get adapter-specific config
1032
+ const adapterConfig = config.config[config.adapter];
1033
+ if (adapterConfig) {
1034
+ for (const [key, value] of Object.entries(adapterConfig)) {
1035
+ if (typeof value === 'string') {
1036
+ result[key] = isSensitive(key) ? maskValue(value) : value;
1037
+ }
1038
+ else if (typeof value === 'boolean' || typeof value === 'number') {
1039
+ result[key] = String(value);
1040
+ }
1041
+ }
1042
+ }
1043
+ result['AUTH_ADAPTER'] = config.adapter;
1044
+ return result;
1045
+ }
1046
+ /**
1047
+ * Helper to get parse result for a given adapter
1048
+ */
1049
+ function getParseResultForAdapter(adapterName) {
1050
+ switch (adapterName) {
1051
+ case 'supertokens':
1052
+ return parseSupertokensEnv();
1053
+ case 'auth0':
1054
+ return parseAuth0Env();
1055
+ case 'supabase':
1056
+ return parseSupabaseEnv();
1057
+ case 'basic':
1058
+ return parseBasicAuthEnv();
1059
+ }
1060
+ }
1061
+ /**
1062
+ * Helper to create adapter for a given name and config
1063
+ */
1064
+ function createAdapterForName(adapterName, config) {
1065
+ switch (adapterName) {
1066
+ case 'supertokens':
1067
+ return supertokensAdapter(config);
1068
+ case 'auth0':
1069
+ return auth0Adapter(config);
1070
+ case 'supabase':
1071
+ return supabaseAdapter(config);
1072
+ case 'basic':
1073
+ return basicAdapter(config);
1074
+ }
1075
+ }
1076
+ /**
1077
+ * Set the configuration store for runtime auth config persistence.
1078
+ *
1079
+ * This must be called during application startup to enable runtime configuration
1080
+ * features. Without a config store, the PUT/DELETE endpoints will return 503.
1081
+ *
1082
+ * @param store - PostgreSQL-backed config store from `postgresAuthConfigStore()`
1083
+ *
1084
+ * @example
1085
+ * ```typescript
1086
+ * import { Pool } from 'pg';
1087
+ * import { setAuthConfigStore, postgresAuthConfigStore } from '@qwickapps/server';
1088
+ *
1089
+ * const pool = new Pool({ connectionString: process.env.DATABASE_URL });
1090
+ * const configStore = postgresAuthConfigStore({ pool });
1091
+ * await configStore.initialize();
1092
+ * setAuthConfigStore(configStore);
1093
+ * ```
1094
+ */
1095
+ export function setAuthConfigStore(store) {
1096
+ configStore = store;
1097
+ }
1098
+ /**
1099
+ * Get the current adapter wrapper
1100
+ */
1101
+ export function getAdapterWrapper() {
1102
+ return adapterWrapper;
1103
+ }
474
1104
  // ═══════════════════════════════════════════════════════════════════════════
475
1105
  // Exports for Testing
476
1106
  // ═══════════════════════════════════════════════════════════════════════════
@@ -485,5 +1115,8 @@ export const __testing = {
485
1115
  getEnvList,
486
1116
  maskValue,
487
1117
  VALID_ADAPTERS,
1118
+ validateAdapterConfig,
1119
+ testProviderConnection,
1120
+ createAdapterFromConfig,
488
1121
  };
489
1122
  //# sourceMappingURL=env-config.js.map