@qwickapps/server 1.4.0 → 1.5.1

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 (273) hide show
  1. package/CHANGELOG.md +507 -0
  2. package/README.md +9 -0
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +12 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/plugins/bans/bans-plugin.d.ts.map +1 -1
  8. package/dist/plugins/bans/bans-plugin.js +12 -3
  9. package/dist/plugins/bans/bans-plugin.js.map +1 -1
  10. package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts +11 -0
  11. package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts.map +1 -0
  12. package/dist/plugins/devices/__tests__/devices-plugin.test.js +410 -0
  13. package/dist/plugins/devices/__tests__/devices-plugin.test.js.map +1 -0
  14. package/dist/plugins/devices/__tests__/token-utils.test.d.ts +7 -0
  15. package/dist/plugins/devices/__tests__/token-utils.test.d.ts.map +1 -0
  16. package/dist/plugins/devices/__tests__/token-utils.test.js +197 -0
  17. package/dist/plugins/devices/__tests__/token-utils.test.js.map +1 -0
  18. package/dist/plugins/devices/adapters/compute-adapter.d.ts +36 -0
  19. package/dist/plugins/devices/adapters/compute-adapter.d.ts.map +1 -0
  20. package/dist/plugins/devices/adapters/compute-adapter.js +100 -0
  21. package/dist/plugins/devices/adapters/compute-adapter.js.map +1 -0
  22. package/dist/plugins/devices/adapters/index.d.ts +12 -0
  23. package/dist/plugins/devices/adapters/index.d.ts.map +1 -0
  24. package/dist/plugins/devices/adapters/index.js +10 -0
  25. package/dist/plugins/devices/adapters/index.js.map +1 -0
  26. package/dist/plugins/devices/adapters/mobile-adapter.d.ts +41 -0
  27. package/dist/plugins/devices/adapters/mobile-adapter.d.ts.map +1 -0
  28. package/dist/plugins/devices/adapters/mobile-adapter.js +131 -0
  29. package/dist/plugins/devices/adapters/mobile-adapter.js.map +1 -0
  30. package/dist/plugins/devices/devices-plugin.d.ts +70 -0
  31. package/dist/plugins/devices/devices-plugin.d.ts.map +1 -0
  32. package/dist/plugins/devices/devices-plugin.js +453 -0
  33. package/dist/plugins/devices/devices-plugin.js.map +1 -0
  34. package/dist/plugins/devices/index.d.ts +18 -0
  35. package/dist/plugins/devices/index.d.ts.map +1 -0
  36. package/dist/plugins/devices/index.js +18 -0
  37. package/dist/plugins/devices/index.js.map +1 -0
  38. package/dist/plugins/devices/stores/index.d.ts +9 -0
  39. package/dist/plugins/devices/stores/index.d.ts.map +1 -0
  40. package/dist/plugins/devices/stores/index.js +9 -0
  41. package/dist/plugins/devices/stores/index.js.map +1 -0
  42. package/dist/plugins/devices/stores/postgres-store.d.ts +26 -0
  43. package/dist/plugins/devices/stores/postgres-store.d.ts.map +1 -0
  44. package/dist/plugins/devices/stores/postgres-store.js +199 -0
  45. package/dist/plugins/devices/stores/postgres-store.js.map +1 -0
  46. package/dist/plugins/devices/token-utils.d.ts +100 -0
  47. package/dist/plugins/devices/token-utils.d.ts.map +1 -0
  48. package/dist/plugins/devices/token-utils.js +162 -0
  49. package/dist/plugins/devices/token-utils.js.map +1 -0
  50. package/dist/plugins/devices/types.d.ts +307 -0
  51. package/dist/plugins/devices/types.d.ts.map +1 -0
  52. package/dist/plugins/devices/types.js +10 -0
  53. package/dist/plugins/devices/types.js.map +1 -0
  54. package/dist/plugins/index.d.ts +14 -2
  55. package/dist/plugins/index.d.ts.map +1 -1
  56. package/dist/plugins/index.js +13 -1
  57. package/dist/plugins/index.js.map +1 -1
  58. package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts +5 -0
  59. package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts.map +1 -0
  60. package/dist/plugins/notifications/__tests__/notifications-manager.test.js +470 -0
  61. package/dist/plugins/notifications/__tests__/notifications-manager.test.js.map +1 -0
  62. package/dist/plugins/notifications/index.d.ts +71 -0
  63. package/dist/plugins/notifications/index.d.ts.map +1 -0
  64. package/dist/plugins/notifications/index.js +72 -0
  65. package/dist/plugins/notifications/index.js.map +1 -0
  66. package/dist/plugins/notifications/notifications-manager.d.ts +182 -0
  67. package/dist/plugins/notifications/notifications-manager.d.ts.map +1 -0
  68. package/dist/plugins/notifications/notifications-manager.js +610 -0
  69. package/dist/plugins/notifications/notifications-manager.js.map +1 -0
  70. package/dist/plugins/notifications/notifications-plugin.d.ts +83 -0
  71. package/dist/plugins/notifications/notifications-plugin.d.ts.map +1 -0
  72. package/dist/plugins/notifications/notifications-plugin.js +337 -0
  73. package/dist/plugins/notifications/notifications-plugin.js.map +1 -0
  74. package/dist/plugins/notifications/types.d.ts +164 -0
  75. package/dist/plugins/notifications/types.d.ts.map +1 -0
  76. package/dist/plugins/notifications/types.js +9 -0
  77. package/dist/plugins/notifications/types.js.map +1 -0
  78. package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts +12 -0
  79. package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts.map +1 -0
  80. package/dist/plugins/parental/__tests__/parental-plugin.test.js +349 -0
  81. package/dist/plugins/parental/__tests__/parental-plugin.test.js.map +1 -0
  82. package/dist/plugins/parental/adapters/index.d.ts +8 -0
  83. package/dist/plugins/parental/adapters/index.d.ts.map +1 -0
  84. package/dist/plugins/parental/adapters/index.js +7 -0
  85. package/dist/plugins/parental/adapters/index.js.map +1 -0
  86. package/dist/plugins/parental/adapters/kids-adapter.d.ts +24 -0
  87. package/dist/plugins/parental/adapters/kids-adapter.d.ts.map +1 -0
  88. package/dist/plugins/parental/adapters/kids-adapter.js +174 -0
  89. package/dist/plugins/parental/adapters/kids-adapter.js.map +1 -0
  90. package/dist/plugins/parental/index.d.ts +14 -0
  91. package/dist/plugins/parental/index.d.ts.map +1 -0
  92. package/dist/plugins/parental/index.js +15 -0
  93. package/dist/plugins/parental/index.js.map +1 -0
  94. package/dist/plugins/parental/parental-plugin.d.ts +88 -0
  95. package/dist/plugins/parental/parental-plugin.d.ts.map +1 -0
  96. package/dist/plugins/parental/parental-plugin.js +666 -0
  97. package/dist/plugins/parental/parental-plugin.js.map +1 -0
  98. package/dist/plugins/parental/stores/index.d.ts +7 -0
  99. package/dist/plugins/parental/stores/index.d.ts.map +1 -0
  100. package/dist/plugins/parental/stores/index.js +7 -0
  101. package/dist/plugins/parental/stores/index.js.map +1 -0
  102. package/dist/plugins/parental/stores/postgres-store.d.ts +10 -0
  103. package/dist/plugins/parental/stores/postgres-store.d.ts.map +1 -0
  104. package/dist/plugins/parental/stores/postgres-store.js +209 -0
  105. package/dist/plugins/parental/stores/postgres-store.js.map +1 -0
  106. package/dist/plugins/parental/types.d.ts +154 -0
  107. package/dist/plugins/parental/types.d.ts.map +1 -0
  108. package/dist/plugins/parental/types.js +10 -0
  109. package/dist/plugins/parental/types.js.map +1 -0
  110. package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts +11 -0
  111. package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts.map +1 -0
  112. package/dist/plugins/profiles/__tests__/profiles-plugin.test.js +243 -0
  113. package/dist/plugins/profiles/__tests__/profiles-plugin.test.js.map +1 -0
  114. package/dist/plugins/profiles/index.d.ts +12 -0
  115. package/dist/plugins/profiles/index.d.ts.map +1 -0
  116. package/dist/plugins/profiles/index.js +13 -0
  117. package/dist/plugins/profiles/index.js.map +1 -0
  118. package/dist/plugins/profiles/profiles-plugin.d.ts +71 -0
  119. package/dist/plugins/profiles/profiles-plugin.d.ts.map +1 -0
  120. package/dist/plugins/profiles/profiles-plugin.js +481 -0
  121. package/dist/plugins/profiles/profiles-plugin.js.map +1 -0
  122. package/dist/plugins/profiles/stores/index.d.ts +9 -0
  123. package/dist/plugins/profiles/stores/index.d.ts.map +1 -0
  124. package/dist/plugins/profiles/stores/index.js +9 -0
  125. package/dist/plugins/profiles/stores/index.js.map +1 -0
  126. package/dist/plugins/profiles/stores/postgres-store.d.ts +18 -0
  127. package/dist/plugins/profiles/stores/postgres-store.d.ts.map +1 -0
  128. package/dist/plugins/profiles/stores/postgres-store.js +310 -0
  129. package/dist/plugins/profiles/stores/postgres-store.js.map +1 -0
  130. package/dist/plugins/profiles/types.d.ts +289 -0
  131. package/dist/plugins/profiles/types.d.ts.map +1 -0
  132. package/dist/plugins/profiles/types.js +10 -0
  133. package/dist/plugins/profiles/types.js.map +1 -0
  134. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts +11 -0
  135. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts.map +1 -0
  136. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js +305 -0
  137. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js.map +1 -0
  138. package/dist/plugins/subscriptions/index.d.ts +12 -0
  139. package/dist/plugins/subscriptions/index.d.ts.map +1 -0
  140. package/dist/plugins/subscriptions/index.js +13 -0
  141. package/dist/plugins/subscriptions/index.js.map +1 -0
  142. package/dist/plugins/subscriptions/stores/index.d.ts +9 -0
  143. package/dist/plugins/subscriptions/stores/index.d.ts.map +1 -0
  144. package/dist/plugins/subscriptions/stores/index.js +9 -0
  145. package/dist/plugins/subscriptions/stores/index.js.map +1 -0
  146. package/dist/plugins/subscriptions/stores/postgres-store.d.ts +14 -0
  147. package/dist/plugins/subscriptions/stores/postgres-store.d.ts.map +1 -0
  148. package/dist/plugins/subscriptions/stores/postgres-store.js +359 -0
  149. package/dist/plugins/subscriptions/stores/postgres-store.js.map +1 -0
  150. package/dist/plugins/subscriptions/subscriptions-plugin.d.ts +82 -0
  151. package/dist/plugins/subscriptions/subscriptions-plugin.d.ts.map +1 -0
  152. package/dist/plugins/subscriptions/subscriptions-plugin.js +449 -0
  153. package/dist/plugins/subscriptions/subscriptions-plugin.js.map +1 -0
  154. package/dist/plugins/subscriptions/types.d.ts +308 -0
  155. package/dist/plugins/subscriptions/types.d.ts.map +1 -0
  156. package/dist/plugins/subscriptions/types.js +10 -0
  157. package/dist/plugins/subscriptions/types.js.map +1 -0
  158. package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts +11 -0
  159. package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts.map +1 -0
  160. package/dist/plugins/usage/__tests__/usage-plugin.test.js +218 -0
  161. package/dist/plugins/usage/__tests__/usage-plugin.test.js.map +1 -0
  162. package/dist/plugins/usage/index.d.ts +12 -0
  163. package/dist/plugins/usage/index.d.ts.map +1 -0
  164. package/dist/plugins/usage/index.js +13 -0
  165. package/dist/plugins/usage/index.js.map +1 -0
  166. package/dist/plugins/usage/stores/index.d.ts +9 -0
  167. package/dist/plugins/usage/stores/index.d.ts.map +1 -0
  168. package/dist/plugins/usage/stores/index.js +9 -0
  169. package/dist/plugins/usage/stores/index.js.map +1 -0
  170. package/dist/plugins/usage/stores/postgres-store.d.ts +14 -0
  171. package/dist/plugins/usage/stores/postgres-store.d.ts.map +1 -0
  172. package/dist/plugins/usage/stores/postgres-store.js +146 -0
  173. package/dist/plugins/usage/stores/postgres-store.js.map +1 -0
  174. package/dist/plugins/usage/types.d.ts +195 -0
  175. package/dist/plugins/usage/types.d.ts.map +1 -0
  176. package/dist/plugins/usage/types.js +10 -0
  177. package/dist/plugins/usage/types.js.map +1 -0
  178. package/dist/plugins/usage/usage-plugin.d.ts +51 -0
  179. package/dist/plugins/usage/usage-plugin.d.ts.map +1 -0
  180. package/dist/plugins/usage/usage-plugin.js +412 -0
  181. package/dist/plugins/usage/usage-plugin.js.map +1 -0
  182. package/dist/plugins/users/__tests__/postgres-store.test.d.ts +10 -0
  183. package/dist/plugins/users/__tests__/postgres-store.test.d.ts.map +1 -0
  184. package/dist/plugins/users/__tests__/postgres-store.test.js +229 -0
  185. package/dist/plugins/users/__tests__/postgres-store.test.js.map +1 -0
  186. package/dist/plugins/users/__tests__/users-plugin.test.js +3 -0
  187. package/dist/plugins/users/__tests__/users-plugin.test.js.map +1 -1
  188. package/dist/plugins/users/index.d.ts +2 -2
  189. package/dist/plugins/users/index.d.ts.map +1 -1
  190. package/dist/plugins/users/index.js +1 -1
  191. package/dist/plugins/users/index.js.map +1 -1
  192. package/dist/plugins/users/stores/postgres-store.d.ts.map +1 -1
  193. package/dist/plugins/users/stores/postgres-store.js +76 -0
  194. package/dist/plugins/users/stores/postgres-store.js.map +1 -1
  195. package/dist/plugins/users/types.d.ts +74 -6
  196. package/dist/plugins/users/types.d.ts.map +1 -1
  197. package/dist/plugins/users/users-plugin.d.ts +15 -1
  198. package/dist/plugins/users/users-plugin.d.ts.map +1 -1
  199. package/dist/plugins/users/users-plugin.js +29 -0
  200. package/dist/plugins/users/users-plugin.js.map +1 -1
  201. package/dist-ui/assets/index-CynOqPkb.js +469 -0
  202. package/dist-ui/assets/index-CynOqPkb.js.map +1 -0
  203. package/dist-ui/index.html +1 -1
  204. package/dist-ui-lib/api/controlPanelApi.d.ts +46 -0
  205. package/dist-ui-lib/components/StatCard.d.ts +16 -0
  206. package/dist-ui-lib/dashboard/widgets/NotificationsStatsWidget.d.ts +12 -0
  207. package/dist-ui-lib/dashboard/widgets/index.d.ts +1 -0
  208. package/dist-ui-lib/index.js +1822 -1611
  209. package/dist-ui-lib/index.js.map +1 -1
  210. package/dist-ui-lib/pages/NotificationsPage.d.ts +9 -0
  211. package/dist-ui-lib/utils/formatters.d.ts +19 -0
  212. package/package.json +3 -2
  213. package/src/index.ts +178 -0
  214. package/src/plugins/bans/bans-plugin.ts +15 -3
  215. package/src/plugins/devices/__tests__/devices-plugin.test.ts +551 -0
  216. package/src/plugins/devices/__tests__/token-utils.test.ts +264 -0
  217. package/src/plugins/devices/adapters/compute-adapter.ts +139 -0
  218. package/src/plugins/devices/adapters/index.ts +13 -0
  219. package/src/plugins/devices/adapters/mobile-adapter.ts +179 -0
  220. package/src/plugins/devices/devices-plugin.ts +538 -0
  221. package/src/plugins/devices/index.ts +69 -0
  222. package/src/plugins/devices/stores/index.ts +9 -0
  223. package/src/plugins/devices/stores/postgres-store.ts +304 -0
  224. package/src/plugins/devices/token-utils.ts +213 -0
  225. package/src/plugins/devices/types.ts +351 -0
  226. package/src/plugins/index.ts +218 -0
  227. package/src/plugins/notifications/__tests__/notifications-manager.test.ts +637 -0
  228. package/src/plugins/notifications/index.ts +91 -0
  229. package/src/plugins/notifications/notifications-manager.ts +773 -0
  230. package/src/plugins/notifications/notifications-plugin.ts +398 -0
  231. package/src/plugins/notifications/types.ts +207 -0
  232. package/src/plugins/parental/__tests__/parental-plugin.test.ts +465 -0
  233. package/src/plugins/parental/adapters/index.ts +8 -0
  234. package/src/plugins/parental/adapters/kids-adapter.ts +206 -0
  235. package/src/plugins/parental/index.ts +55 -0
  236. package/src/plugins/parental/parental-plugin.ts +759 -0
  237. package/src/plugins/parental/stores/index.ts +7 -0
  238. package/src/plugins/parental/stores/postgres-store.ts +304 -0
  239. package/src/plugins/parental/types.ts +180 -0
  240. package/src/plugins/profiles/__tests__/profiles-plugin.test.ts +321 -0
  241. package/src/plugins/profiles/index.ts +49 -0
  242. package/src/plugins/profiles/profiles-plugin.ts +546 -0
  243. package/src/plugins/profiles/stores/index.ts +9 -0
  244. package/src/plugins/profiles/stores/postgres-store.ts +439 -0
  245. package/src/plugins/profiles/types.ts +338 -0
  246. package/src/plugins/subscriptions/__tests__/subscriptions-plugin.test.ts +404 -0
  247. package/src/plugins/subscriptions/index.ts +51 -0
  248. package/src/plugins/subscriptions/stores/index.ts +9 -0
  249. package/src/plugins/subscriptions/stores/postgres-store.ts +482 -0
  250. package/src/plugins/subscriptions/subscriptions-plugin.ts +530 -0
  251. package/src/plugins/subscriptions/types.ts +355 -0
  252. package/src/plugins/usage/__tests__/usage-plugin.test.ts +288 -0
  253. package/src/plugins/usage/index.ts +39 -0
  254. package/src/plugins/usage/stores/index.ts +9 -0
  255. package/src/plugins/usage/stores/postgres-store.ts +213 -0
  256. package/src/plugins/usage/types.ts +222 -0
  257. package/src/plugins/usage/usage-plugin.ts +484 -0
  258. package/src/plugins/users/__tests__/postgres-store.test.ts +326 -0
  259. package/src/plugins/users/__tests__/users-plugin.test.ts +3 -0
  260. package/src/plugins/users/index.ts +6 -0
  261. package/src/plugins/users/stores/postgres-store.ts +104 -0
  262. package/src/plugins/users/types.ts +82 -6
  263. package/src/plugins/users/users-plugin.ts +37 -0
  264. package/ui/src/App.tsx +5 -1
  265. package/ui/src/api/controlPanelApi.ts +103 -6
  266. package/ui/src/components/StatCard.tsx +58 -0
  267. package/ui/src/dashboard/builtInWidgets.tsx +3 -1
  268. package/ui/src/dashboard/widgets/NotificationsStatsWidget.tsx +167 -0
  269. package/ui/src/dashboard/widgets/index.ts +1 -0
  270. package/ui/src/pages/NotificationsPage.tsx +417 -0
  271. package/ui/src/utils/formatters.ts +33 -0
  272. package/dist-ui/assets/index-D7DoZ9rL.js +0 -478
  273. package/dist-ui/assets/index-D7DoZ9rL.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-store.d.ts","sourceRoot":"","sources":["../../../../src/plugins/usage/stores/postgres-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,UAAU,EAGV,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAsBrB;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,UAAU,CA6K/E"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * PostgreSQL Usage Store
3
+ *
4
+ * Usage tracking storage implementation using PostgreSQL.
5
+ * Tracks daily and monthly usage counters.
6
+ *
7
+ * Copyright (c) 2025 QwickApps.com. All rights reserved.
8
+ */
9
+ /**
10
+ * Get current date in YYYY-MM-DD format
11
+ */
12
+ function getCurrentDate() {
13
+ return new Date().toISOString().split('T')[0];
14
+ }
15
+ /**
16
+ * Get current year-month in YYYY-MM format
17
+ */
18
+ function getCurrentYearMonth() {
19
+ const now = new Date();
20
+ return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
21
+ }
22
+ /**
23
+ * Create a PostgreSQL usage store
24
+ */
25
+ export function postgresUsageStore(config) {
26
+ const { pool: poolOrFn, dailyTable = 'usage_daily', monthlyTable = 'usage_monthly', schema = 'public', autoCreateTables = true, } = config;
27
+ // Helper to get pool (supports lazy initialization via function)
28
+ const getPool = () => {
29
+ const pool = typeof poolOrFn === 'function' ? poolOrFn() : poolOrFn;
30
+ return pool;
31
+ };
32
+ const dailyTableFull = `"${schema}"."${dailyTable}"`;
33
+ const monthlyTableFull = `"${schema}"."${monthlyTable}"`;
34
+ return {
35
+ name: 'postgres',
36
+ async initialize() {
37
+ if (!autoCreateTables)
38
+ return;
39
+ // Create usage_daily table
40
+ await getPool().query(`
41
+ CREATE TABLE IF NOT EXISTS ${dailyTableFull} (
42
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
43
+ user_id UUID NOT NULL,
44
+ feature_code VARCHAR(100) NOT NULL,
45
+ date DATE NOT NULL DEFAULT CURRENT_DATE,
46
+ count INTEGER DEFAULT 0,
47
+ metadata JSONB DEFAULT '{}',
48
+ created_at TIMESTAMPTZ DEFAULT NOW(),
49
+ updated_at TIMESTAMPTZ DEFAULT NOW(),
50
+ UNIQUE(user_id, feature_code, date)
51
+ );
52
+
53
+ CREATE INDEX IF NOT EXISTS idx_${dailyTable}_user_date ON ${dailyTableFull}(user_id, date);
54
+ CREATE INDEX IF NOT EXISTS idx_${dailyTable}_feature ON ${dailyTableFull}(feature_code);
55
+ CREATE INDEX IF NOT EXISTS idx_${dailyTable}_date ON ${dailyTableFull}(date);
56
+ `);
57
+ // Create usage_monthly table
58
+ await getPool().query(`
59
+ CREATE TABLE IF NOT EXISTS ${monthlyTableFull} (
60
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
61
+ user_id UUID NOT NULL,
62
+ feature_code VARCHAR(100) NOT NULL,
63
+ year_month VARCHAR(7) NOT NULL,
64
+ count INTEGER DEFAULT 0,
65
+ metadata JSONB DEFAULT '{}',
66
+ created_at TIMESTAMPTZ DEFAULT NOW(),
67
+ updated_at TIMESTAMPTZ DEFAULT NOW(),
68
+ UNIQUE(user_id, feature_code, year_month)
69
+ );
70
+
71
+ CREATE INDEX IF NOT EXISTS idx_${monthlyTable}_user ON ${monthlyTableFull}(user_id, year_month);
72
+ CREATE INDEX IF NOT EXISTS idx_${monthlyTable}_feature ON ${monthlyTableFull}(feature_code);
73
+ `);
74
+ },
75
+ async getDailyUsage(userId, featureCode, date) {
76
+ const targetDate = date || getCurrentDate();
77
+ const result = await getPool().query(`SELECT * FROM ${dailyTableFull}
78
+ WHERE user_id = $1 AND feature_code = $2 AND date = $3`, [userId, featureCode, targetDate]);
79
+ return result.rows[0] || null;
80
+ },
81
+ async getMonthlyUsage(userId, featureCode, yearMonth) {
82
+ const targetMonth = yearMonth || getCurrentYearMonth();
83
+ const result = await getPool().query(`SELECT * FROM ${monthlyTableFull}
84
+ WHERE user_id = $1 AND feature_code = $2 AND year_month = $3`, [userId, featureCode, targetMonth]);
85
+ return result.rows[0] || null;
86
+ },
87
+ async incrementDaily(userId, featureCode, amount = 1, date) {
88
+ const targetDate = date || getCurrentDate();
89
+ const yearMonth = targetDate.substring(0, 7); // Extract YYYY-MM from YYYY-MM-DD
90
+ // Increment daily usage (upsert)
91
+ const dailyResult = await getPool().query(`INSERT INTO ${dailyTableFull} (user_id, feature_code, date, count)
92
+ VALUES ($1, $2, $3, $4)
93
+ ON CONFLICT (user_id, feature_code, date)
94
+ DO UPDATE SET count = ${dailyTableFull}.count + $4, updated_at = NOW()
95
+ RETURNING count`, [userId, featureCode, targetDate, amount]);
96
+ const newCount = dailyResult.rows[0].count;
97
+ // Also increment monthly usage
98
+ await getPool().query(`INSERT INTO ${monthlyTableFull} (user_id, feature_code, year_month, count)
99
+ VALUES ($1, $2, $3, $4)
100
+ ON CONFLICT (user_id, feature_code, year_month)
101
+ DO UPDATE SET count = ${monthlyTableFull}.count + $4, updated_at = NOW()`, [userId, featureCode, yearMonth, amount]);
102
+ return newCount;
103
+ },
104
+ async getAllDailyUsage(userId, date) {
105
+ const targetDate = date || getCurrentDate();
106
+ const result = await getPool().query(`SELECT * FROM ${dailyTableFull}
107
+ WHERE user_id = $1 AND date = $2
108
+ ORDER BY feature_code`, [userId, targetDate]);
109
+ return result.rows;
110
+ },
111
+ async getAllMonthlyUsage(userId, yearMonth) {
112
+ const targetMonth = yearMonth || getCurrentYearMonth();
113
+ const result = await getPool().query(`SELECT * FROM ${monthlyTableFull}
114
+ WHERE user_id = $1 AND year_month = $2
115
+ ORDER BY feature_code`, [userId, targetMonth]);
116
+ return result.rows;
117
+ },
118
+ async resetDailyUsage(userId, featureCode, date) {
119
+ const targetDate = date || getCurrentDate();
120
+ await getPool().query(`UPDATE ${dailyTableFull}
121
+ SET count = 0, updated_at = NOW()
122
+ WHERE user_id = $1 AND feature_code = $2 AND date = $3`, [userId, featureCode, targetDate]);
123
+ },
124
+ async cleanupOldDaily(daysToKeep) {
125
+ // Calculate cutoff date to avoid SQL interpolation
126
+ const cutoffDate = new Date();
127
+ cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
128
+ const cutoffDateStr = cutoffDate.toISOString().split('T')[0];
129
+ const result = await getPool().query(`DELETE FROM ${dailyTableFull} WHERE date < $1`, [cutoffDateStr]);
130
+ return result.rowCount ?? 0;
131
+ },
132
+ async cleanupOldMonthly(monthsToKeep) {
133
+ // Calculate the cutoff year-month
134
+ const now = new Date();
135
+ now.setMonth(now.getMonth() - monthsToKeep);
136
+ const cutoffMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
137
+ const result = await getPool().query(`DELETE FROM ${monthlyTableFull}
138
+ WHERE year_month < $1`, [cutoffMonth]);
139
+ return result.rowCount ?? 0;
140
+ },
141
+ async shutdown() {
142
+ // Pool is managed externally, nothing to do here
143
+ },
144
+ };
145
+ }
146
+ //# sourceMappingURL=postgres-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-store.js","sourceRoot":"","sources":["../../../../src/plugins/usage/stores/postgres-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH;;GAEG;AACH,SAAS,cAAc;IACrB,OAAO,IAAI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C,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;YACtD,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAE7D,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC,KAAK,CAClC,eAAe,cAAc,kBAAkB,EAC/C,CAAC,aAAa,CAAC,CAChB,CAAC;YACF,OAAO,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;QAC9B,CAAC;QAED,KAAK,CAAC,iBAAiB,CAAC,YAAoB;YAC1C,kCAAkC;YAClC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC,CAAC;YAC5C,MAAM,WAAW,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;YAE1F,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC,KAAK,CAClC,eAAe,gBAAgB;+BACR,EACvB,CAAC,WAAW,CAAC,CACd,CAAC;YACF,OAAO,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;QAC9B,CAAC;QAED,KAAK,CAAC,QAAQ;YACZ,iDAAiD;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Usage Plugin Types
3
+ *
4
+ * Type definitions for usage tracking with daily/monthly counters.
5
+ * Integrates with subscriptions-plugin for limit enforcement.
6
+ *
7
+ * Copyright (c) 2025 QwickApps.com. All rights reserved.
8
+ */
9
+ /**
10
+ * Daily usage record
11
+ */
12
+ export interface DailyUsage {
13
+ /** Primary key - UUID */
14
+ id: string;
15
+ /** User ID */
16
+ user_id: string;
17
+ /** Feature code (e.g., 'ai_messages', 'vision_calls') */
18
+ feature_code: string;
19
+ /** Date (YYYY-MM-DD) */
20
+ date: string;
21
+ /** Usage count */
22
+ count: number;
23
+ /** Additional metadata */
24
+ metadata: Record<string, unknown>;
25
+ /** When the record was created */
26
+ created_at: Date;
27
+ /** When the record was last updated */
28
+ updated_at: Date;
29
+ }
30
+ /**
31
+ * Monthly usage record
32
+ */
33
+ export interface MonthlyUsage {
34
+ /** Primary key - UUID */
35
+ id: string;
36
+ /** User ID */
37
+ user_id: string;
38
+ /** Feature code */
39
+ feature_code: string;
40
+ /** Year-month (YYYY-MM) */
41
+ year_month: string;
42
+ /** Usage count */
43
+ count: number;
44
+ /** Additional metadata */
45
+ metadata: Record<string, unknown>;
46
+ /** When the record was created */
47
+ created_at: Date;
48
+ /** When the record was last updated */
49
+ updated_at: Date;
50
+ }
51
+ /**
52
+ * Usage increment result
53
+ */
54
+ export interface UsageIncrementResult {
55
+ /** Whether the increment was allowed */
56
+ allowed: boolean;
57
+ /** Current count after increment (if allowed) */
58
+ current_count: number;
59
+ /** Limit value (-1 = unlimited) */
60
+ limit: number | null;
61
+ /** Remaining quota */
62
+ remaining: number | null;
63
+ /** When the counter resets */
64
+ resets_at?: Date;
65
+ /** Reason if not allowed */
66
+ reason?: string;
67
+ }
68
+ /**
69
+ * Usage status for a feature
70
+ */
71
+ export interface UsageStatus {
72
+ /** Feature code */
73
+ feature_code: string;
74
+ /** Current usage count */
75
+ current: number;
76
+ /** Limit value (-1 = unlimited, null = no subscription) */
77
+ limit: number | null;
78
+ /** Remaining quota (-1 = unlimited) */
79
+ remaining: number | null;
80
+ /** When the counter resets */
81
+ resets_at: Date;
82
+ /** Percentage used (0-100, null if unlimited) */
83
+ percentage_used: number | null;
84
+ }
85
+ /**
86
+ * Usage summary for a user
87
+ */
88
+ export interface UsageSummary {
89
+ /** User ID */
90
+ user_id: string;
91
+ /** Period (daily or monthly) */
92
+ period: 'daily' | 'monthly';
93
+ /** Period date/month */
94
+ period_value: string;
95
+ /** Usage by feature */
96
+ features: UsageStatus[];
97
+ }
98
+ /**
99
+ * Usage store interface
100
+ */
101
+ export interface UsageStore {
102
+ /** Store name (e.g., 'postgres') */
103
+ name: string;
104
+ /**
105
+ * Initialize the store (create tables, etc.)
106
+ */
107
+ initialize(): Promise<void>;
108
+ /**
109
+ * Get daily usage for a user and feature
110
+ */
111
+ getDailyUsage(userId: string, featureCode: string, date?: string): Promise<DailyUsage | null>;
112
+ /**
113
+ * Get monthly usage for a user and feature
114
+ */
115
+ getMonthlyUsage(userId: string, featureCode: string, yearMonth?: string): Promise<MonthlyUsage | null>;
116
+ /**
117
+ * Increment daily usage (also updates monthly)
118
+ */
119
+ incrementDaily(userId: string, featureCode: string, amount?: number, date?: string): Promise<number>;
120
+ /**
121
+ * Get all daily usage for a user on a date
122
+ */
123
+ getAllDailyUsage(userId: string, date?: string): Promise<DailyUsage[]>;
124
+ /**
125
+ * Get all monthly usage for a user
126
+ */
127
+ getAllMonthlyUsage(userId: string, yearMonth?: string): Promise<MonthlyUsage[]>;
128
+ /**
129
+ * Reset daily usage for a user and feature
130
+ */
131
+ resetDailyUsage(userId: string, featureCode: string, date?: string): Promise<void>;
132
+ /**
133
+ * Cleanup old daily records
134
+ */
135
+ cleanupOldDaily(daysToKeep: number): Promise<number>;
136
+ /**
137
+ * Cleanup old monthly records
138
+ */
139
+ cleanupOldMonthly(monthsToKeep: number): Promise<number>;
140
+ /**
141
+ * Shutdown the store
142
+ */
143
+ shutdown(): Promise<void>;
144
+ }
145
+ /**
146
+ * PostgreSQL usage store configuration
147
+ */
148
+ export interface PostgresUsageStoreConfig {
149
+ /** PostgreSQL pool instance or a function that returns one */
150
+ pool: unknown | (() => unknown);
151
+ /** Daily usage table name (default: 'usage_daily') */
152
+ dailyTable?: string;
153
+ /** Monthly usage table name (default: 'usage_monthly') */
154
+ monthlyTable?: string;
155
+ /** Schema name (default: 'public') */
156
+ schema?: string;
157
+ /** Auto-create tables on init (default: true) */
158
+ autoCreateTables?: boolean;
159
+ }
160
+ /**
161
+ * API configuration
162
+ */
163
+ export interface UsageApiConfig {
164
+ /** API route prefix (default: '/usage') */
165
+ prefix?: string;
166
+ /** Enable usage endpoints */
167
+ enabled?: boolean;
168
+ }
169
+ /**
170
+ * Cleanup configuration
171
+ */
172
+ export interface UsageCleanupConfig {
173
+ /** Days to keep daily records (default: 90) */
174
+ dailyRetentionDays?: number;
175
+ /** Months to keep monthly records (default: 24) */
176
+ monthlyRetentionMonths?: number;
177
+ /** Run cleanup on startup */
178
+ runOnStartup?: boolean;
179
+ /** Cleanup interval in hours (0 = disabled) */
180
+ cleanupIntervalHours?: number;
181
+ }
182
+ /**
183
+ * Usage plugin configuration
184
+ */
185
+ export interface UsagePluginConfig {
186
+ /** Usage storage backend */
187
+ store: UsageStore;
188
+ /** API configuration */
189
+ api?: UsageApiConfig;
190
+ /** Cleanup configuration */
191
+ cleanup?: UsageCleanupConfig;
192
+ /** Enable debug logging */
193
+ debug?: boolean;
194
+ }
195
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/usage/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,kCAAkC;IAClC,UAAU,EAAE,IAAI,CAAC;IACjB,uCAAuC;IACvC,UAAU,EAAE,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yBAAyB;IACzB,E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AAC,CAAC;IAEzD;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAMD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,8DAA8D;IAC9D,IAAI,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IAChC,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mDAAmD;IACnD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,6BAA6B;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,+CAA+C;IAC/C,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,wBAAwB;IACxB,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Usage Plugin Types
3
+ *
4
+ * Type definitions for usage tracking with daily/monthly counters.
5
+ * Integrates with subscriptions-plugin for limit enforcement.
6
+ *
7
+ * Copyright (c) 2025 QwickApps.com. All rights reserved.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/usage/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Usage Plugin
3
+ *
4
+ * Usage tracking plugin for @qwickapps/server.
5
+ * Tracks daily/monthly feature usage and enforces limits.
6
+ *
7
+ * Copyright (c) 2025 QwickApps.com. All rights reserved.
8
+ */
9
+ import type { Plugin } from '../../core/plugin-registry.js';
10
+ import type { UsagePluginConfig, UsageStore, UsageIncrementResult, UsageStatus, UsageSummary } from './types.js';
11
+ /**
12
+ * Create the Usage plugin
13
+ */
14
+ export declare function createUsagePlugin(config: UsagePluginConfig): Plugin;
15
+ /**
16
+ * Get the current usage store instance
17
+ */
18
+ export declare function getUsageStore(): UsageStore | null;
19
+ /**
20
+ * Get current daily usage for a feature
21
+ */
22
+ export declare function getDailyUsage(userId: string, featureCode: string): Promise<number>;
23
+ /**
24
+ * Increment usage and check limit
25
+ */
26
+ export declare function incrementUsage(userId: string, featureCode: string, amount?: number): Promise<UsageIncrementResult>;
27
+ /**
28
+ * Check if usage is within limit (without incrementing)
29
+ */
30
+ export declare function checkUsageLimit(userId: string, featureCode: string, amount?: number): Promise<UsageIncrementResult>;
31
+ /**
32
+ * Get usage status for a specific feature
33
+ */
34
+ export declare function getFeatureUsageStatus(userId: string, featureCode: string): Promise<UsageStatus>;
35
+ /**
36
+ * Get daily usage summary for all features
37
+ */
38
+ export declare function getDailyUsageSummary(userId: string, date?: string): Promise<UsageSummary>;
39
+ /**
40
+ * Reset usage for a feature (admin function)
41
+ */
42
+ export declare function resetUsage(userId: string, featureCode: string): Promise<void>;
43
+ /**
44
+ * Get remaining quota for a feature
45
+ */
46
+ export declare function getRemainingQuota(userId: string, featureCode: string): Promise<number | null>;
47
+ /**
48
+ * Check if user can use a feature (has remaining quota)
49
+ */
50
+ export declare function canUseFeature(userId: string, featureCode: string, amount?: number): Promise<boolean>;
51
+ //# sourceMappingURL=usage-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/usage/usage-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,+BAA+B,CAAC;AAC1F,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EAEV,oBAAoB,EACpB,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AA2BpB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CA2KnE;AAMD;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,GAAG,IAAI,CAEjD;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxF;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,SAAI,GACT,OAAO,CAAC,oBAAoB,CAAC,CA0D/B;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,SAAI,GACT,OAAO,CAAC,oBAAoB,CAAC,CA4C/B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAoCrG;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAgD/F;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,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