@qwickapps/server 1.7.1 → 1.7.2

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 (157) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/src/plugins/api-keys/api-keys-plugin.d.ts +5 -2
  3. package/dist/src/plugins/api-keys/api-keys-plugin.d.ts.map +1 -1
  4. package/dist/src/plugins/api-keys/api-keys-plugin.js +61 -19
  5. package/dist/src/plugins/api-keys/api-keys-plugin.js.map +1 -1
  6. package/dist/src/plugins/api-keys/index.d.ts +0 -4
  7. package/dist/src/plugins/api-keys/index.d.ts.map +1 -1
  8. package/dist/src/plugins/api-keys/index.js +2 -3
  9. package/dist/src/plugins/api-keys/index.js.map +1 -1
  10. package/dist/src/plugins/api-keys/types.d.ts +9 -3
  11. package/dist/src/plugins/api-keys/types.d.ts.map +1 -1
  12. package/dist/src/plugins/api-keys/types.js.map +1 -1
  13. package/dist/src/plugins/auth/index.d.ts +0 -4
  14. package/dist/src/plugins/auth/index.d.ts.map +1 -1
  15. package/dist/src/plugins/auth/index.js +2 -3
  16. package/dist/src/plugins/auth/index.js.map +1 -1
  17. package/dist/src/plugins/bans/bans-plugin.d.ts +5 -2
  18. package/dist/src/plugins/bans/bans-plugin.d.ts.map +1 -1
  19. package/dist/src/plugins/bans/bans-plugin.js +71 -25
  20. package/dist/src/plugins/bans/bans-plugin.js.map +1 -1
  21. package/dist/src/plugins/bans/index.d.ts +0 -4
  22. package/dist/src/plugins/bans/index.d.ts.map +1 -1
  23. package/dist/src/plugins/bans/index.js +2 -3
  24. package/dist/src/plugins/bans/index.js.map +1 -1
  25. package/dist/src/plugins/bans/types.d.ts +13 -6
  26. package/dist/src/plugins/bans/types.d.ts.map +1 -1
  27. package/dist/src/plugins/devices/devices-plugin.d.ts +5 -2
  28. package/dist/src/plugins/devices/devices-plugin.d.ts.map +1 -1
  29. package/dist/src/plugins/devices/devices-plugin.js +62 -26
  30. package/dist/src/plugins/devices/devices-plugin.js.map +1 -1
  31. package/dist/src/plugins/devices/index.d.ts +0 -4
  32. package/dist/src/plugins/devices/index.d.ts.map +1 -1
  33. package/dist/src/plugins/devices/index.js +2 -3
  34. package/dist/src/plugins/devices/index.js.map +1 -1
  35. package/dist/src/plugins/entitlements/entitlements-plugin.d.ts +5 -2
  36. package/dist/src/plugins/entitlements/entitlements-plugin.d.ts.map +1 -1
  37. package/dist/src/plugins/entitlements/entitlements-plugin.js +78 -41
  38. package/dist/src/plugins/entitlements/entitlements-plugin.js.map +1 -1
  39. package/dist/src/plugins/entitlements/index.d.ts +0 -4
  40. package/dist/src/plugins/entitlements/index.d.ts.map +1 -1
  41. package/dist/src/plugins/entitlements/index.js +2 -3
  42. package/dist/src/plugins/entitlements/index.js.map +1 -1
  43. package/dist/src/plugins/entitlements/types.d.ts +9 -2
  44. package/dist/src/plugins/entitlements/types.d.ts.map +1 -1
  45. package/dist/src/plugins/notifications/index.d.ts +0 -4
  46. package/dist/src/plugins/notifications/index.d.ts.map +1 -1
  47. package/dist/src/plugins/notifications/index.js +2 -3
  48. package/dist/src/plugins/notifications/index.js.map +1 -1
  49. package/dist/src/plugins/notifications/notifications-plugin.d.ts +5 -2
  50. package/dist/src/plugins/notifications/notifications-plugin.d.ts.map +1 -1
  51. package/dist/src/plugins/notifications/notifications-plugin.js +45 -13
  52. package/dist/src/plugins/notifications/notifications-plugin.js.map +1 -1
  53. package/dist/src/plugins/parental/index.d.ts +0 -4
  54. package/dist/src/plugins/parental/index.d.ts.map +1 -1
  55. package/dist/src/plugins/parental/index.js +2 -3
  56. package/dist/src/plugins/parental/index.js.map +1 -1
  57. package/dist/src/plugins/parental/parental-plugin.d.ts +5 -2
  58. package/dist/src/plugins/parental/parental-plugin.d.ts.map +1 -1
  59. package/dist/src/plugins/parental/parental-plugin.js +60 -24
  60. package/dist/src/plugins/parental/parental-plugin.js.map +1 -1
  61. package/dist/src/plugins/preferences/index.d.ts +0 -4
  62. package/dist/src/plugins/preferences/index.d.ts.map +1 -1
  63. package/dist/src/plugins/preferences/index.js +2 -3
  64. package/dist/src/plugins/preferences/index.js.map +1 -1
  65. package/dist/src/plugins/preferences/preferences-plugin.d.ts +5 -2
  66. package/dist/src/plugins/preferences/preferences-plugin.d.ts.map +1 -1
  67. package/dist/src/plugins/preferences/preferences-plugin.js +63 -19
  68. package/dist/src/plugins/preferences/preferences-plugin.js.map +1 -1
  69. package/dist/src/plugins/profiles/index.d.ts +0 -4
  70. package/dist/src/plugins/profiles/index.d.ts.map +1 -1
  71. package/dist/src/plugins/profiles/index.js +2 -3
  72. package/dist/src/plugins/profiles/index.js.map +1 -1
  73. package/dist/src/plugins/profiles/profiles-plugin.d.ts +5 -2
  74. package/dist/src/plugins/profiles/profiles-plugin.d.ts.map +1 -1
  75. package/dist/src/plugins/profiles/profiles-plugin.js +60 -26
  76. package/dist/src/plugins/profiles/profiles-plugin.js.map +1 -1
  77. package/dist/src/plugins/profiles/types.d.ts +9 -2
  78. package/dist/src/plugins/profiles/types.d.ts.map +1 -1
  79. package/dist/src/plugins/qwickbrain/index.d.ts +0 -4
  80. package/dist/src/plugins/qwickbrain/index.d.ts.map +1 -1
  81. package/dist/src/plugins/qwickbrain/index.js +2 -3
  82. package/dist/src/plugins/qwickbrain/index.js.map +1 -1
  83. package/dist/src/plugins/qwickbrain/qwickbrain-plugin.d.ts.map +1 -1
  84. package/dist/src/plugins/qwickbrain/qwickbrain-plugin.js +117 -0
  85. package/dist/src/plugins/qwickbrain/qwickbrain-plugin.js.map +1 -1
  86. package/dist/src/plugins/rate-limit/index.d.ts +0 -4
  87. package/dist/src/plugins/rate-limit/index.d.ts.map +1 -1
  88. package/dist/src/plugins/rate-limit/index.js +2 -3
  89. package/dist/src/plugins/rate-limit/index.js.map +1 -1
  90. package/dist/src/plugins/subscriptions/index.d.ts +0 -4
  91. package/dist/src/plugins/subscriptions/index.d.ts.map +1 -1
  92. package/dist/src/plugins/subscriptions/index.js +2 -3
  93. package/dist/src/plugins/subscriptions/index.js.map +1 -1
  94. package/dist/src/plugins/subscriptions/subscriptions-plugin.d.ts +5 -2
  95. package/dist/src/plugins/subscriptions/subscriptions-plugin.d.ts.map +1 -1
  96. package/dist/src/plugins/subscriptions/subscriptions-plugin.js +63 -29
  97. package/dist/src/plugins/subscriptions/subscriptions-plugin.js.map +1 -1
  98. package/dist/src/plugins/subscriptions/types.d.ts +8 -2
  99. package/dist/src/plugins/subscriptions/types.d.ts.map +1 -1
  100. package/dist/src/plugins/tenants/tenants-plugin.d.ts +5 -2
  101. package/dist/src/plugins/tenants/tenants-plugin.d.ts.map +1 -1
  102. package/dist/src/plugins/tenants/tenants-plugin.js +91 -58
  103. package/dist/src/plugins/tenants/tenants-plugin.js.map +1 -1
  104. package/dist/src/plugins/tenants/types.d.ts +8 -2
  105. package/dist/src/plugins/tenants/types.d.ts.map +1 -1
  106. package/dist/src/plugins/usage/index.d.ts +0 -4
  107. package/dist/src/plugins/usage/index.d.ts.map +1 -1
  108. package/dist/src/plugins/usage/index.js +2 -3
  109. package/dist/src/plugins/usage/index.js.map +1 -1
  110. package/dist/src/plugins/usage/usage-plugin.d.ts +5 -2
  111. package/dist/src/plugins/usage/usage-plugin.d.ts.map +1 -1
  112. package/dist/src/plugins/usage/usage-plugin.js +57 -23
  113. package/dist/src/plugins/usage/usage-plugin.js.map +1 -1
  114. package/dist/src/plugins/users/types.d.ts +7 -2
  115. package/dist/src/plugins/users/types.d.ts.map +1 -1
  116. package/dist/src/plugins/users/users-plugin.d.ts +5 -2
  117. package/dist/src/plugins/users/users-plugin.d.ts.map +1 -1
  118. package/dist/src/plugins/users/users-plugin.js +56 -23
  119. package/dist/src/plugins/users/users-plugin.js.map +1 -1
  120. package/dist-ui/assets/index-0gzisPdy.js +528 -0
  121. package/dist-ui/assets/{index-8y0jDGcd.js.map → index-0gzisPdy.js.map} +1 -1
  122. package/dist-ui/index.html +1 -1
  123. package/package.json +8 -5
  124. package/src/plugins/api-keys/api-keys-plugin.ts +64 -20
  125. package/src/plugins/api-keys/index.ts +2 -5
  126. package/src/plugins/api-keys/types.ts +9 -3
  127. package/src/plugins/auth/index.ts +3 -5
  128. package/src/plugins/bans/bans-plugin.ts +71 -26
  129. package/src/plugins/bans/index.ts +3 -5
  130. package/src/plugins/bans/types.ts +13 -6
  131. package/src/plugins/devices/devices-plugin.ts +62 -27
  132. package/src/plugins/devices/index.ts +3 -5
  133. package/src/plugins/entitlements/entitlements-plugin.ts +81 -43
  134. package/src/plugins/entitlements/index.ts +3 -5
  135. package/src/plugins/entitlements/types.ts +9 -2
  136. package/src/plugins/notifications/index.ts +3 -5
  137. package/src/plugins/notifications/notifications-plugin.ts +48 -19
  138. package/src/plugins/parental/index.ts +3 -5
  139. package/src/plugins/parental/parental-plugin.ts +63 -25
  140. package/src/plugins/preferences/index.ts +3 -5
  141. package/src/plugins/preferences/preferences-plugin.ts +66 -20
  142. package/src/plugins/profiles/index.ts +3 -5
  143. package/src/plugins/profiles/profiles-plugin.ts +60 -27
  144. package/src/plugins/profiles/types.ts +9 -2
  145. package/src/plugins/qwickbrain/index.ts +3 -5
  146. package/src/plugins/qwickbrain/qwickbrain-plugin.ts +135 -0
  147. package/src/plugins/rate-limit/index.ts +3 -5
  148. package/src/plugins/subscriptions/index.ts +3 -5
  149. package/src/plugins/subscriptions/subscriptions-plugin.ts +63 -30
  150. package/src/plugins/subscriptions/types.ts +8 -2
  151. package/src/plugins/tenants/tenants-plugin.ts +95 -60
  152. package/src/plugins/tenants/types.ts +8 -2
  153. package/src/plugins/usage/index.ts +3 -5
  154. package/src/plugins/usage/usage-plugin.ts +60 -26
  155. package/src/plugins/users/types.ts +7 -2
  156. package/src/plugins/users/users-plugin.ts +56 -24
  157. package/dist-ui/assets/index-8y0jDGcd.js +0 -528
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Control Panel</title>
7
- <script type="module" crossorigin src="/assets/index-8y0jDGcd.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-0gzisPdy.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-DQED0KPI.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@qwickapps/server",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Plugin-based application server framework for building websites, APIs, admin dashboards, and full-stack products",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/src/index.d.ts",
10
- "import": "./dist/src/index.js"
10
+ "import": "./dist/src/index.js",
11
+ "require": "./dist/src/index.js"
11
12
  },
12
13
  "./plugins": {
13
14
  "types": "./dist/src/plugins/index.d.ts",
14
- "import": "./dist/src/plugins/index.js"
15
+ "import": "./dist/src/plugins/index.js",
16
+ "require": "./dist/src/plugins/index.js"
15
17
  },
16
18
  "./ui": {
17
19
  "types": "./dist-ui-lib/src/components/index.d.ts",
18
- "import": "./dist-ui-lib/index.js"
20
+ "import": "./dist-ui-lib/index.js",
21
+ "require": "./dist-ui-lib/index.js"
19
22
  }
20
23
  },
21
24
  "files": [
@@ -65,7 +68,7 @@
65
68
  "@mui/material": "^7.2.0",
66
69
  "@mui/x-data-grid": "^7.29.12",
67
70
  "@playwright/test": "^1.57.0",
68
- "@qwickapps/auth-client": "^1.0.0",
71
+ "@qwickapps/auth-client": "^1.1.0",
69
72
  "@qwickapps/react-framework": "^1.5.5",
70
73
  "@testing-library/jest-dom": "^6.0.0",
71
74
  "@testing-library/react": "^14.0.0",
@@ -23,22 +23,25 @@ import {
23
23
  CreateApiKeySchema,
24
24
  UpdateApiKeySchema,
25
25
  } from './types.js';
26
+ import { hasPostgres, getPostgres } from '../postgres-plugin.js';
27
+ import { postgresApiKeyStore } from './stores/index.js';
26
28
 
27
29
  // Store instance for helper access
28
30
  let currentStore: ApiKeyStore | null = null;
29
31
 
30
32
  /**
31
- * Create the API Keys plugin
33
+ * Create the API Keys plugin with smart defaults
34
+ *
35
+ * Config is optional - plugin will use defaults and get dependencies from registry.
36
+ * Gracefully handles missing dependencies with clear log messages.
32
37
  */
33
- export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
34
- const debug = config.debug || false;
35
- // Framework automatically prefixes routes with plugin slug, so use root path
36
- const apiPrefix = config.api?.prefix || '/';
37
- const apiEnabled = config.api?.enabled !== false;
38
-
39
- function log(message: string, data?: Record<string, unknown>) {
40
- if (debug) {
41
- console.log(`[ApiKeysPlugin] ${message}`, data || '');
38
+ export function createApiKeysPlugin(config: Partial<ApiKeysPluginConfig> = {}): Plugin {
39
+ function log(message: string, data?: Record<string, unknown>, isError = false) {
40
+ const prefix = '[ApiKeysPlugin]';
41
+ if (isError) {
42
+ console.error(`${prefix} ${message}`, data || '');
43
+ } else if (config.debug) {
44
+ console.log(`${prefix} ${message}`, data || '');
42
45
  }
43
46
  }
44
47
 
@@ -48,15 +51,56 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
48
51
  version: '1.0.0',
49
52
 
50
53
  async onStart(_pluginConfig: PluginConfig, registry: PluginRegistry): Promise<void> {
51
- log('Starting API keys plugin');
54
+ const logger = registry.getLogger('api-keys');
52
55
 
53
56
  // Check for users plugin dependency
54
57
  if (!registry.hasPlugin('users')) {
55
- throw new Error('API Keys plugin requires Users plugin to be loaded first');
58
+ logger.warn('Users plugin not loaded! API Keys plugin disabled.');
59
+ registry.registerHealthCheck({
60
+ name: 'api-keys-store',
61
+ type: 'custom',
62
+ check: async () => ({
63
+ healthy: false,
64
+ details: {
65
+ error: 'Users plugin not available',
66
+ state: 'disabled',
67
+ },
68
+ }),
69
+ });
70
+ return;
56
71
  }
57
72
 
73
+ // Check for postgres in registry
74
+ if (!hasPostgres()) {
75
+ logger.warn('No Database! API Keys plugin disabled.');
76
+ registry.registerHealthCheck({
77
+ name: 'api-keys-store',
78
+ type: 'custom',
79
+ check: async () => ({
80
+ healthy: false,
81
+ details: {
82
+ error: 'PostgreSQL not available',
83
+ state: 'disabled',
84
+ },
85
+ }),
86
+ });
87
+ return;
88
+ }
89
+
90
+ // Smart defaults - get dependencies from registry
91
+ const store = config.store ?? postgresApiKeyStore({
92
+ pool: () => getPostgres().getPool(),
93
+ autoCreateTables: true,
94
+ });
95
+
96
+ const debug = config.debug ?? false;
97
+ const apiPrefix = config.api?.prefix ?? '/api-keys';
98
+ const apiEnabled = config.api?.enabled ?? true;
99
+
100
+ log('Starting API keys plugin');
101
+
58
102
  // Initialize the store (creates tables and RLS policies if needed)
59
- await config.store.initialize();
103
+ await store.initialize();
60
104
  log('API keys store initialized');
61
105
 
62
106
  // Initialize optional Phase 2 stores
@@ -71,7 +115,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
71
115
  }
72
116
 
73
117
  // Store reference for helper access
74
- currentStore = config.store;
118
+ currentStore = store;
75
119
 
76
120
  // Register health check
77
121
  registry.registerHealthCheck({
@@ -117,7 +161,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
117
161
  };
118
162
 
119
163
  // Create the API key
120
- const apiKey = await config.store.create(params);
164
+ const apiKey = await store.create(params);
121
165
 
122
166
  // Return the key with plaintext (ONLY time plaintext is accessible)
123
167
  res.status(201).json({
@@ -152,7 +196,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
152
196
  return res.status(401).json({ error: 'Authentication required' });
153
197
  }
154
198
 
155
- const keys = await config.store.list(userId);
199
+ const keys = await store.list(userId);
156
200
 
157
201
  // Remove sensitive fields from response
158
202
  const sanitized = keys.map(key => ({
@@ -191,7 +235,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
191
235
  }
192
236
 
193
237
  const { id } = req.params;
194
- const key = await config.store.get(userId, id);
238
+ const key = await store.get(userId, id);
195
239
 
196
240
  if (!key) {
197
241
  return res.status(404).json({ error: 'API key not found' });
@@ -244,7 +288,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
244
288
  const { id } = req.params;
245
289
  const params: UpdateApiKeyParams = validation.data;
246
290
 
247
- const updated = await config.store.update(userId, id, params);
291
+ const updated = await store.update(userId, id, params);
248
292
 
249
293
  if (!updated) {
250
294
  return res.status(404).json({ error: 'API key not found' });
@@ -287,7 +331,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
287
331
  }
288
332
 
289
333
  const { id } = req.params;
290
- const deleted = await config.store.delete(userId, id);
334
+ const deleted = await store.delete(userId, id);
291
335
 
292
336
  if (!deleted) {
293
337
  return res.status(404).json({ error: 'API key not found' });
@@ -357,7 +401,7 @@ export function createApiKeysPlugin(config: ApiKeysPluginConfig): Plugin {
357
401
  const { id: keyId } = req.params;
358
402
 
359
403
  // Verify key belongs to user
360
- const key = await config.store.get(userId, keyId);
404
+ const key = await store.get(userId, keyId);
361
405
  if (!key) {
362
406
  return res.status(404).json({ error: 'API key not found' });
363
407
  }
@@ -48,8 +48,5 @@ export { postgresApiKeyStore } from './stores/index.js';
48
48
  // Middleware
49
49
  export { bearerTokenAuth } from './middleware/index.js';
50
50
 
51
- // UI Components
52
- export { ApiKeysStatusWidget } from './ApiKeysStatusWidget.js';
53
- export type { ApiKeysStatusWidgetProps } from './ApiKeysStatusWidget.js';
54
- export { ApiKeysManagementPage } from './ApiKeysManagementPage.js';
55
- export type { ApiKeysManagementPageProps } from './ApiKeysManagementPage.js';
51
+ // UI Components are exported from main package index (@qwickapps/server)
52
+ // Do NOT export here to avoid loading UI dependencies when importing plugins
@@ -230,17 +230,23 @@ export interface ApiKeysApiConfig {
230
230
 
231
231
  /**
232
232
  * API keys plugin configuration
233
+ *
234
+ * All properties are optional - plugin will use smart defaults:
235
+ * - store: Postgres API key store using registry's postgres instance
236
+ * - api.prefix: '/api-keys'
237
+ * - api.enabled: true
238
+ * - debug: false
233
239
  */
234
240
  export interface ApiKeysPluginConfig {
235
- /** API key storage backend */
236
- store: ApiKeyStore;
241
+ /** API key storage backend (default: postgres API key store from registry) */
242
+ store?: ApiKeyStore;
237
243
  /** Plugin scope storage backend (optional, for Phase 2) */
238
244
  scopeStore?: import('./stores/plugin-scope-store.js').PluginScopeStore;
239
245
  /** Usage log storage backend (optional, for Phase 2) */
240
246
  usageStore?: import('./stores/usage-log-store.js').UsageLogStore;
241
247
  /** API configuration */
242
248
  api?: ApiKeysApiConfig;
243
- /** Enable debug logging */
249
+ /** Enable debug logging (default: false) */
244
250
  debug?: boolean;
245
251
  }
246
252
 
@@ -65,8 +65,6 @@ export { basicAdapter } from './adapters/basic-adapter.js';
65
65
  export { supabaseAdapter } from './adapters/supabase-adapter.js';
66
66
  export { supertokensAdapter } from './adapters/supertokens-adapter.js';
67
67
 
68
- // UI Components
69
- export { AuthStatusWidget } from './AuthStatusWidget.js';
70
- export type { AuthStatusWidgetProps } from './AuthStatusWidget.js';
71
- export { AuthManagementPage } from './AuthManagementPage.js';
72
- export type { AuthManagementPageProps } from './AuthManagementPage.js';
68
+ // UI Components are exported from main package index (@qwickapps/server)
69
+ // Do NOT export here to avoid loading UI dependencies when importing plugins
70
+
@@ -22,6 +22,8 @@ import type {
22
22
  } from './types.js';
23
23
  import type { AuthenticatedRequest } from '../auth/types.js';
24
24
  import { getUserByEmail, getUserById, getUsersByIds } from '../users/users-plugin.js';
25
+ import { hasPostgres, getPostgres } from '../postgres-plugin.js';
26
+ import { postgresBanStore } from './stores/index.js';
25
27
 
26
28
  // Store instance for helper access
27
29
  let currentStore: BanStore | null = null;
@@ -29,17 +31,18 @@ let banCleanupInterval: NodeJS.Timeout | null = null;
29
31
  let pluginConfig: BansPluginConfig | null = null;
30
32
 
31
33
  /**
32
- * Create the Bans plugin
34
+ * Create the Bans plugin with smart defaults
35
+ *
36
+ * Config is optional - plugin will use defaults and get dependencies from registry.
37
+ * Gracefully handles missing dependencies with clear log messages.
33
38
  */
34
- export function createBansPlugin(config: BansPluginConfig): Plugin {
35
- const debug = config.debug || false;
36
- // Routes are mounted under /api by the control panel, so don't include /api in prefix
37
- const apiPrefix = config.api?.prefix || '/'; // Framework adds /bans prefix automatically
38
- const apiEnabled = config.api?.enabled !== false;
39
-
40
- function log(message: string, data?: Record<string, unknown>) {
41
- if (debug) {
42
- console.log(`[BansPlugin] ${message}`, data || '');
39
+ export function createBansPlugin(config: Partial<BansPluginConfig> = {}): Plugin {
40
+ function log(message: string, data?: Record<string, unknown>, isError = false) {
41
+ const prefix = '[BansPlugin]';
42
+ if (isError) {
43
+ console.error(`${prefix} ${message}`, data || '');
44
+ } else if (config.debug) {
45
+ console.log(`${prefix} ${message}`, data || '');
43
46
  }
44
47
  }
45
48
 
@@ -49,26 +52,68 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
49
52
  version: '1.0.0',
50
53
 
51
54
  async onStart(_pluginConfig: PluginConfig, registry: PluginRegistry): Promise<void> {
52
- log('Starting bans plugin');
55
+ const logger = registry.getLogger('bans');
53
56
 
54
57
  // Check for users plugin dependency
55
58
  if (!registry.hasPlugin('users')) {
56
- throw new Error('Bans plugin requires Users plugin to be loaded first');
59
+ logger.warn('Users plugin not loaded! Bans plugin disabled.');
60
+ registry.registerHealthCheck({
61
+ name: 'bans-store',
62
+ type: 'custom',
63
+ check: async () => ({
64
+ healthy: false,
65
+ details: {
66
+ error: 'Users plugin not available',
67
+ state: 'disabled',
68
+ },
69
+ }),
70
+ });
71
+ return;
72
+ }
73
+
74
+ // Check for postgres in registry
75
+ if (!hasPostgres()) {
76
+ logger.warn('No Database! Bans plugin disabled.');
77
+ registry.registerHealthCheck({
78
+ name: 'bans-store',
79
+ type: 'custom',
80
+ check: async () => ({
81
+ healthy: false,
82
+ details: {
83
+ error: 'PostgreSQL not available',
84
+ state: 'disabled',
85
+ },
86
+ }),
87
+ });
88
+ return;
57
89
  }
58
90
 
91
+ // Smart defaults - get dependencies from registry
92
+ const store = config.store ?? postgresBanStore({
93
+ pool: () => getPostgres().getPool(),
94
+ autoCreateTables: true,
95
+ });
96
+
97
+ const debug = config.debug ?? false;
98
+ const apiPrefix = config.api?.prefix ?? '/bans';
99
+ const apiEnabled = config.api?.enabled ?? true;
100
+ const supportTemporary = config.supportTemporary ?? true;
101
+
102
+ log('Starting bans plugin');
103
+
59
104
  // Initialize the store (creates tables if needed)
60
- await config.store.initialize();
105
+ await store.initialize();
61
106
  log('Bans plugin migrations complete');
62
107
 
63
108
  // Store references for helper access
64
- currentStore = config.store;
65
- pluginConfig = config;
109
+ currentStore = store;
110
+ pluginConfig = { ...config, store, debug, supportTemporary };
66
111
 
67
112
  // Start ban cleanup interval if temporary bans are supported
68
- if (config.supportTemporary) {
113
+ if (supportTemporary) {
69
114
  banCleanupInterval = setInterval(async () => {
70
115
  try {
71
- const cleaned = await config.store.cleanupExpiredBans();
116
+ const cleaned = await store.cleanupExpiredBans();
72
117
  if (cleaned > 0) {
73
118
  log('Cleaned up expired bans', { count: cleaned });
74
119
  }
@@ -85,7 +130,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
85
130
  check: async () => {
86
131
  try {
87
132
  // Simple health check - list with limit 0
88
- await config.store.listActiveBans({ limit: 0 });
133
+ await store.listActiveBans({ limit: 0 });
89
134
  return { healthy: true };
90
135
  } catch {
91
136
  return { healthy: false };
@@ -105,7 +150,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
105
150
  const limit = Math.min(parseInt(req.query.limit as string) || 50, 100);
106
151
  const offset = parseInt(req.query.offset as string) || 0;
107
152
 
108
- const result = await config.store.listActiveBans({ limit, offset });
153
+ const result = await store.listActiveBans({ limit, offset });
109
154
 
110
155
  // Batch fetch users for all bans (single query instead of N queries)
111
156
  const userIds = [...new Set(result.bans.map((ban) => ban.user_id))];
@@ -133,7 +178,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
133
178
  pluginId: 'bans',
134
179
  handler: async (req: Request, res: Response) => {
135
180
  try {
136
- const ban = await config.store.getActiveBan(req.params.userId);
181
+ const ban = await store.getActiveBan(req.params.userId);
137
182
  res.json({
138
183
  isBanned: ban !== null,
139
184
  ban,
@@ -152,7 +197,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
152
197
  pluginId: 'bans',
153
198
  handler: async (req: Request, res: Response) => {
154
199
  try {
155
- const bans = await config.store.listBans(req.params.userId);
200
+ const bans = await store.listBans(req.params.userId);
156
201
  res.json({ bans });
157
202
  } catch (error) {
158
203
  console.error('[BansPlugin] Get ban history error:', error);
@@ -185,7 +230,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
185
230
  return res.status(404).json({ error: 'User not found' });
186
231
  }
187
232
 
188
- const ban = await config.store.createBan(input);
233
+ const ban = await store.createBan(input);
189
234
 
190
235
  // Call onBan callback if provided
191
236
  if (config.callbacks?.onBan) {
@@ -227,7 +272,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
227
272
  note: req.body?.note,
228
273
  };
229
274
 
230
- const removed = await config.store.removeBan(input);
275
+ const removed = await store.removeBan(input);
231
276
  if (!removed) {
232
277
  return res.status(404).json({ error: 'No active ban found' });
233
278
  }
@@ -292,7 +337,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
292
337
  metadata: req.body.metadata,
293
338
  };
294
339
 
295
- const ban = await config.store.createBan(input);
340
+ const ban = await store.createBan(input);
296
341
 
297
342
  // Call onBan callback if provided
298
343
  if (config.callbacks?.onBan) {
@@ -335,7 +380,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
335
380
  note: req.body?.note,
336
381
  };
337
382
 
338
- const removed = await config.store.removeBan(input);
383
+ const removed = await store.removeBan(input);
339
384
  if (!removed) {
340
385
  return res.status(404).json({ error: 'No active ban found' });
341
386
  }
@@ -370,7 +415,7 @@ export function createBansPlugin(config: BansPluginConfig): Plugin {
370
415
  banCleanupInterval = null;
371
416
  }
372
417
 
373
- await config.store.shutdown();
418
+ if (currentStore) { await currentStore.shutdown(); };
374
419
  currentStore = null;
375
420
  pluginConfig = null;
376
421
 
@@ -30,8 +30,6 @@ export type {
30
30
  // Stores
31
31
  export { postgresBanStore, inMemoryBanStore } from './stores/index.js';
32
32
 
33
- // UI Components
34
- export { BansStatusWidget } from './BansStatusWidget.js';
35
- export type { BansStatusWidgetProps } from './BansStatusWidget.js';
36
- export { BansManagementPage } from './BansManagementPage.js';
37
- export type { BansManagementPageProps } from './BansManagementPage.js';
33
+ // UI Components are exported from main package index (@qwickapps/server)
34
+ // Do NOT export here to avoid loading UI dependencies when importing plugins
35
+
@@ -107,22 +107,29 @@ export interface BanCallbacks {
107
107
 
108
108
  /**
109
109
  * Bans plugin configuration
110
+ *
111
+ * All properties are optional - plugin will use smart defaults:
112
+ * - store: Postgres ban store using registry's postgres instance
113
+ * - supportTemporary: true
114
+ * - api.prefix: '/bans'
115
+ * - api.enabled: true
116
+ * - debug: false
110
117
  */
111
118
  export interface BansPluginConfig {
112
- /** Ban storage backend */
113
- store: BanStore;
114
- /** Support temporary bans (with expiration) */
119
+ /** Ban storage backend (default: postgres ban store from registry) */
120
+ store?: BanStore;
121
+ /** Support temporary bans (with expiration) (default: true) */
115
122
  supportTemporary?: boolean;
116
123
  /** Callbacks */
117
124
  callbacks?: BanCallbacks;
118
125
  /** API configuration */
119
126
  api?: {
120
- /** API route prefix (default: '/api/bans') */
127
+ /** API route prefix (default: '/bans') */
121
128
  prefix?: string;
122
- /** Enable API endpoints */
129
+ /** Enable API endpoints (default: true) */
123
130
  enabled?: boolean;
124
131
  };
125
- /** Enable debug logging */
132
+ /** Enable debug logging (default: false) */
126
133
  debug?: boolean;
127
134
  }
128
135