@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,321 @@
1
+ /**
2
+ * Profiles Plugin Tests
3
+ *
4
+ * Unit tests for the profiles plugin including:
5
+ * - Plugin lifecycle
6
+ * - Profile CRUD operations
7
+ * - Age group calculation
8
+ * - Default profile management
9
+ */
10
+
11
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
12
+ import {
13
+ createProfilesPlugin,
14
+ getProfileStore,
15
+ createProfile,
16
+ getProfileById,
17
+ updateProfile,
18
+ deleteProfile,
19
+ listUserProfiles,
20
+ setDefaultProfile,
21
+ } from '../profiles-plugin.js';
22
+ import type { ProfileStore, Profile, AgeGroup } from '../types.js';
23
+ import type { PluginRegistry } from '../../../core/plugin-registry.js';
24
+
25
+ describe('Profiles Plugin', () => {
26
+ // Mock profile data
27
+ const mockProfile: Profile = {
28
+ id: 'profile-id-123',
29
+ org_id: 'org-123',
30
+ user_id: 'user-123',
31
+ name: 'Emma',
32
+ avatar: 'robot_pink',
33
+ birth_date: new Date('2018-06-15'),
34
+ age: 6,
35
+ age_group: 'child',
36
+ content_filter_level: 'strict',
37
+ daily_time_limit_minutes: 60,
38
+ allowed_hours_start: '08:00',
39
+ allowed_hours_end: '20:00',
40
+ is_active: true,
41
+ is_default: false,
42
+ metadata: { voice_id: 'en-US-child-1' },
43
+ created_at: new Date(),
44
+ updated_at: new Date(),
45
+ };
46
+
47
+ // Mock store factory
48
+ const createMockStore = (): ProfileStore => ({
49
+ name: 'mock',
50
+ initialize: vi.fn().mockResolvedValue(undefined),
51
+ getById: vi.fn().mockResolvedValue(mockProfile),
52
+ create: vi.fn().mockResolvedValue(mockProfile),
53
+ update: vi.fn().mockResolvedValue(mockProfile),
54
+ delete: vi.fn().mockResolvedValue(true),
55
+ search: vi.fn().mockResolvedValue({
56
+ profiles: [mockProfile],
57
+ total: 1,
58
+ page: 1,
59
+ limit: 20,
60
+ totalPages: 1,
61
+ }),
62
+ listByUser: vi.fn().mockResolvedValue([mockProfile]),
63
+ getDefaultProfile: vi.fn().mockResolvedValue(mockProfile),
64
+ getProfileCount: vi.fn().mockResolvedValue(1),
65
+ getByAgeGroup: vi.fn().mockResolvedValue([mockProfile]),
66
+ setDefaultProfile: vi.fn().mockResolvedValue(true),
67
+ shutdown: vi.fn().mockResolvedValue(undefined),
68
+ });
69
+
70
+ // Mock registry factory
71
+ const createMockRegistry = (): PluginRegistry =>
72
+ ({
73
+ hasPlugin: vi.fn().mockReturnValue(false),
74
+ getPlugin: vi.fn().mockReturnValue(null),
75
+ listPlugins: vi.fn().mockReturnValue([]),
76
+ addRoute: vi.fn(),
77
+ addMenuItem: vi.fn(),
78
+ addPage: vi.fn(),
79
+ addWidget: vi.fn(),
80
+ getRoutes: vi.fn().mockReturnValue([]),
81
+ getMenuItems: vi.fn().mockReturnValue([]),
82
+ getPages: vi.fn().mockReturnValue([]),
83
+ getWidgets: vi.fn().mockReturnValue([]),
84
+ getConfig: vi.fn().mockReturnValue({}),
85
+ setConfig: vi.fn().mockResolvedValue(undefined),
86
+ subscribe: vi.fn().mockReturnValue(() => {}),
87
+ emit: vi.fn(),
88
+ registerHealthCheck: vi.fn(),
89
+ getApp: vi.fn().mockReturnValue({} as any),
90
+ getRouter: vi.fn().mockReturnValue({} as any),
91
+ getLogger: vi.fn().mockReturnValue({
92
+ debug: vi.fn(),
93
+ info: vi.fn(),
94
+ warn: vi.fn(),
95
+ error: vi.fn(),
96
+ }),
97
+ }) as unknown as PluginRegistry;
98
+
99
+ let mockStore: ProfileStore;
100
+ let mockRegistry: PluginRegistry;
101
+
102
+ beforeEach(() => {
103
+ vi.clearAllMocks();
104
+ mockStore = createMockStore();
105
+ mockRegistry = createMockRegistry();
106
+ });
107
+
108
+ afterEach(async () => {
109
+ // Clean up by stopping the plugin if it was started
110
+ const store = getProfileStore();
111
+ if (store) {
112
+ const plugin = createProfilesPlugin({ store: mockStore });
113
+ await plugin.onStop?.();
114
+ }
115
+ });
116
+
117
+ describe('createProfilesPlugin', () => {
118
+ it('should create a plugin with correct id', () => {
119
+ const plugin = createProfilesPlugin({ store: mockStore });
120
+ expect(plugin.id).toBe('profiles');
121
+ });
122
+
123
+ it('should create a plugin with correct name', () => {
124
+ const plugin = createProfilesPlugin({ store: mockStore });
125
+ expect(plugin.name).toBe('Profiles');
126
+ });
127
+
128
+ it('should create a plugin with version', () => {
129
+ const plugin = createProfilesPlugin({ store: mockStore });
130
+ expect(plugin.version).toBe('1.0.0');
131
+ });
132
+ });
133
+
134
+ describe('onStart', () => {
135
+ it('should initialize store on start', async () => {
136
+ const plugin = createProfilesPlugin({ store: mockStore });
137
+ await plugin.onStart({}, mockRegistry);
138
+
139
+ expect(mockStore.initialize).toHaveBeenCalled();
140
+ });
141
+
142
+ it('should register health check', async () => {
143
+ const plugin = createProfilesPlugin({ store: mockStore });
144
+ await plugin.onStart({}, mockRegistry);
145
+
146
+ expect(mockRegistry.registerHealthCheck).toHaveBeenCalledWith(
147
+ expect.objectContaining({
148
+ name: 'profiles-store',
149
+ type: 'custom',
150
+ })
151
+ );
152
+ });
153
+
154
+ it('should register CRUD routes by default', async () => {
155
+ const plugin = createProfilesPlugin({ store: mockStore });
156
+ await plugin.onStart({}, mockRegistry);
157
+
158
+ // GET /profiles, GET /profiles/:id, POST /profiles, PUT /profiles/:id,
159
+ // DELETE /profiles/:id, POST /profiles/:id/default
160
+ expect(mockRegistry.addRoute).toHaveBeenCalled();
161
+ });
162
+ });
163
+
164
+ describe('onStop', () => {
165
+ it('should shutdown store', async () => {
166
+ const plugin = createProfilesPlugin({ store: mockStore });
167
+ await plugin.onStart({}, mockRegistry);
168
+ await plugin.onStop?.();
169
+
170
+ expect(mockStore.shutdown).toHaveBeenCalled();
171
+ });
172
+
173
+ it('should clear store reference', async () => {
174
+ const plugin = createProfilesPlugin({ store: mockStore });
175
+ await plugin.onStart({}, mockRegistry);
176
+ await plugin.onStop?.();
177
+
178
+ expect(getProfileStore()).toBeNull();
179
+ });
180
+ });
181
+
182
+ describe('helper functions', () => {
183
+ describe('getProfileStore', () => {
184
+ it('should return null when plugin not started', () => {
185
+ expect(getProfileStore()).toBeNull();
186
+ });
187
+
188
+ it('should return store when plugin started', async () => {
189
+ const plugin = createProfilesPlugin({ store: mockStore });
190
+ await plugin.onStart({}, mockRegistry);
191
+
192
+ expect(getProfileStore()).toBe(mockStore);
193
+ });
194
+ });
195
+
196
+ describe('createProfile', () => {
197
+ it('should throw when plugin not initialized', async () => {
198
+ await expect(
199
+ createProfile({ user_id: 'user-123', name: 'Test' })
200
+ ).rejects.toThrow('Profiles plugin not initialized');
201
+ });
202
+
203
+ it('should create profile', async () => {
204
+ const plugin = createProfilesPlugin({ store: mockStore });
205
+ await plugin.onStart({}, mockRegistry);
206
+
207
+ const result = await createProfile({
208
+ user_id: 'user-123',
209
+ name: 'Emma',
210
+ age: 6,
211
+ });
212
+
213
+ expect(result.id).toBe(mockProfile.id);
214
+ expect(mockStore.create).toHaveBeenCalled();
215
+ });
216
+ });
217
+
218
+ describe('getProfileById', () => {
219
+ it('should throw when plugin not initialized', async () => {
220
+ await expect(getProfileById('profile-id')).rejects.toThrow(
221
+ 'Profiles plugin not initialized'
222
+ );
223
+ });
224
+
225
+ it('should return profile when found', async () => {
226
+ const plugin = createProfilesPlugin({ store: mockStore });
227
+ await plugin.onStart({}, mockRegistry);
228
+
229
+ const result = await getProfileById(mockProfile.id);
230
+ expect(result).toEqual(mockProfile);
231
+ });
232
+
233
+ it('should return null when not found', async () => {
234
+ const plugin = createProfilesPlugin({ store: mockStore });
235
+ await plugin.onStart({}, mockRegistry);
236
+
237
+ (mockStore.getById as any).mockResolvedValue(null);
238
+
239
+ const result = await getProfileById('non-existent');
240
+ expect(result).toBeNull();
241
+ });
242
+ });
243
+
244
+ describe('updateProfile', () => {
245
+ it('should throw when plugin not initialized', async () => {
246
+ await expect(
247
+ updateProfile('profile-id', { name: 'New Name' })
248
+ ).rejects.toThrow('Profiles plugin not initialized');
249
+ });
250
+
251
+ it('should update profile', async () => {
252
+ const plugin = createProfilesPlugin({ store: mockStore });
253
+ await plugin.onStart({}, mockRegistry);
254
+
255
+ const updated = { ...mockProfile, name: 'Updated Name' };
256
+ (mockStore.update as any).mockResolvedValue(updated);
257
+
258
+ const result = await updateProfile(mockProfile.id, { name: 'Updated Name' });
259
+
260
+ expect(result?.name).toBe('Updated Name');
261
+ });
262
+ });
263
+
264
+ describe('deleteProfile', () => {
265
+ it('should throw when plugin not initialized', async () => {
266
+ await expect(deleteProfile('profile-id')).rejects.toThrow(
267
+ 'Profiles plugin not initialized'
268
+ );
269
+ });
270
+
271
+ it('should delete profile', async () => {
272
+ const plugin = createProfilesPlugin({ store: mockStore });
273
+ await plugin.onStart({}, mockRegistry);
274
+
275
+ const result = await deleteProfile(mockProfile.id);
276
+
277
+ expect(result).toBe(true);
278
+ expect(mockStore.delete).toHaveBeenCalledWith(mockProfile.id);
279
+ });
280
+ });
281
+
282
+ describe('listUserProfiles', () => {
283
+ it('should throw when plugin not initialized', async () => {
284
+ await expect(listUserProfiles('user-id')).rejects.toThrow(
285
+ 'Profiles plugin not initialized'
286
+ );
287
+ });
288
+
289
+ it('should return user profiles', async () => {
290
+ const plugin = createProfilesPlugin({ store: mockStore });
291
+ await plugin.onStart({}, mockRegistry);
292
+
293
+ const result = await listUserProfiles('user-123');
294
+
295
+ expect(result).toHaveLength(1);
296
+ expect(result[0]).toEqual(mockProfile);
297
+ });
298
+ });
299
+
300
+ describe('setDefaultProfile', () => {
301
+ it('should throw when plugin not initialized', async () => {
302
+ await expect(
303
+ setDefaultProfile('profile-id', 'user-id')
304
+ ).rejects.toThrow('Profiles plugin not initialized');
305
+ });
306
+
307
+ it('should set default profile', async () => {
308
+ const plugin = createProfilesPlugin({ store: mockStore });
309
+ await plugin.onStart({}, mockRegistry);
310
+
311
+ const result = await setDefaultProfile(mockProfile.id, 'user-123');
312
+
313
+ expect(result).toBe(true);
314
+ expect(mockStore.setDefaultProfile).toHaveBeenCalledWith(
315
+ mockProfile.id,
316
+ 'user-123'
317
+ );
318
+ });
319
+ });
320
+ });
321
+ });
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Profiles Plugin
3
+ *
4
+ * Generic multi-profile management with age support.
5
+ * Exports all profile-related functionality.
6
+ *
7
+ * Copyright (c) 2025 QwickApps.com. All rights reserved.
8
+ */
9
+
10
+ // Main plugin
11
+ export {
12
+ createProfilesPlugin,
13
+ getProfileStore,
14
+ createProfile,
15
+ getProfileById,
16
+ updateProfile,
17
+ deleteProfile,
18
+ listUserProfiles,
19
+ getDefaultProfile,
20
+ setDefaultProfile,
21
+ getProfilesByAgeGroup,
22
+ getChildProfiles,
23
+ getProfileAge,
24
+ checkTimeRestrictions,
25
+ getContentFilterLevel,
26
+ canAccessContent,
27
+ } from './profiles-plugin.js';
28
+
29
+ // Types
30
+ export type {
31
+ Profile,
32
+ CreateProfileInput,
33
+ UpdateProfileInput,
34
+ ProfileSearchParams,
35
+ ProfileListResponse,
36
+ TimeRestrictionResult,
37
+ ContentFilterLevel,
38
+ AgeGroup,
39
+ ProfileStore,
40
+ ProfilesPluginConfig,
41
+ ProfilesApiConfig,
42
+ PostgresProfileStoreConfig,
43
+ AgeThresholds,
44
+ QwickBotProfileMetadata,
45
+ GamingProfileMetadata,
46
+ } from './types.js';
47
+
48
+ // Stores
49
+ export { postgresProfileStore } from './stores/index.js';