@qwickapps/server 1.1.9 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -0
- package/dist/core/control-panel.d.ts +7 -2
- package/dist/core/control-panel.d.ts.map +1 -1
- package/dist/core/control-panel.js +99 -60
- package/dist/core/control-panel.js.map +1 -1
- package/dist/core/gateway.d.ts +159 -79
- package/dist/core/gateway.d.ts.map +1 -1
- package/dist/core/gateway.js +683 -315
- package/dist/core/gateway.js.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/plugin-registry.d.ts +271 -0
- package/dist/core/plugin-registry.d.ts.map +1 -0
- package/dist/core/plugin-registry.js +326 -0
- package/dist/core/plugin-registry.js.map +1 -0
- package/dist/core/types.d.ts +16 -33
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/dist/plugins/auth/adapters/auth0-adapter.d.ts +14 -0
- package/dist/plugins/auth/adapters/auth0-adapter.d.ts.map +1 -0
- package/dist/plugins/auth/adapters/auth0-adapter.js +179 -0
- package/dist/plugins/auth/adapters/auth0-adapter.js.map +1 -0
- package/dist/plugins/auth/adapters/basic-adapter.d.ts +13 -0
- package/dist/plugins/auth/adapters/basic-adapter.d.ts.map +1 -0
- package/dist/plugins/auth/adapters/basic-adapter.js +51 -0
- package/dist/plugins/auth/adapters/basic-adapter.js.map +1 -0
- package/dist/plugins/auth/adapters/index.d.ts +9 -0
- package/dist/plugins/auth/adapters/index.d.ts.map +1 -0
- package/dist/plugins/auth/adapters/index.js +9 -0
- package/dist/plugins/auth/adapters/index.js.map +1 -0
- package/dist/plugins/auth/adapters/supabase-adapter.d.ts +13 -0
- package/dist/plugins/auth/adapters/supabase-adapter.d.ts.map +1 -0
- package/dist/plugins/auth/adapters/supabase-adapter.js +109 -0
- package/dist/plugins/auth/adapters/supabase-adapter.js.map +1 -0
- package/dist/plugins/auth/auth-plugin.d.ts +40 -0
- package/dist/plugins/auth/auth-plugin.d.ts.map +1 -0
- package/dist/plugins/auth/auth-plugin.js +255 -0
- package/dist/plugins/auth/auth-plugin.js.map +1 -0
- package/dist/plugins/auth/auth-plugin.test.d.ts +9 -0
- package/dist/plugins/auth/auth-plugin.test.d.ts.map +1 -0
- package/dist/plugins/auth/auth-plugin.test.js +147 -0
- package/dist/plugins/auth/auth-plugin.test.js.map +1 -0
- package/dist/plugins/auth/index.d.ts +12 -0
- package/dist/plugins/auth/index.d.ts.map +1 -0
- package/dist/plugins/auth/index.js +13 -0
- package/dist/plugins/auth/index.js.map +1 -0
- package/dist/plugins/auth/types.d.ts +148 -0
- package/dist/plugins/auth/types.d.ts.map +1 -0
- package/dist/plugins/auth/types.js +14 -0
- package/dist/plugins/auth/types.js.map +1 -0
- package/dist/plugins/bans/bans-plugin.d.ts +59 -0
- package/dist/plugins/bans/bans-plugin.d.ts.map +1 -0
- package/dist/plugins/bans/bans-plugin.js +428 -0
- package/dist/plugins/bans/bans-plugin.js.map +1 -0
- package/dist/plugins/bans/index.d.ts +9 -0
- package/dist/plugins/bans/index.d.ts.map +1 -0
- package/dist/plugins/bans/index.js +10 -0
- package/dist/plugins/bans/index.js.map +1 -0
- package/dist/plugins/bans/stores/index.d.ts +7 -0
- package/dist/plugins/bans/stores/index.d.ts.map +1 -0
- package/dist/plugins/bans/stores/index.js +7 -0
- package/dist/plugins/bans/stores/index.js.map +1 -0
- package/dist/plugins/bans/stores/postgres-store.d.ts +29 -0
- package/dist/plugins/bans/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/bans/stores/postgres-store.js +132 -0
- package/dist/plugins/bans/stores/postgres-store.js.map +1 -0
- package/dist/plugins/bans/types.d.ts +128 -0
- package/dist/plugins/bans/types.d.ts.map +1 -0
- package/dist/plugins/bans/types.js +11 -0
- package/dist/plugins/bans/types.js.map +1 -0
- package/dist/plugins/cache-plugin.d.ts +14 -3
- package/dist/plugins/cache-plugin.d.ts.map +1 -1
- package/dist/plugins/cache-plugin.js +27 -7
- package/dist/plugins/cache-plugin.js.map +1 -1
- package/dist/plugins/cache-plugin.test.js +96 -32
- package/dist/plugins/cache-plugin.test.js.map +1 -1
- package/dist/plugins/config-plugin.d.ts +3 -2
- package/dist/plugins/config-plugin.d.ts.map +1 -1
- package/dist/plugins/config-plugin.js +17 -10
- package/dist/plugins/config-plugin.js.map +1 -1
- package/dist/plugins/diagnostics-plugin.d.ts +2 -2
- package/dist/plugins/diagnostics-plugin.d.ts.map +1 -1
- package/dist/plugins/diagnostics-plugin.js +17 -10
- package/dist/plugins/diagnostics-plugin.js.map +1 -1
- package/dist/plugins/entitlements/entitlements-plugin.d.ts +95 -0
- package/dist/plugins/entitlements/entitlements-plugin.d.ts.map +1 -0
- package/dist/plugins/entitlements/entitlements-plugin.js +707 -0
- package/dist/plugins/entitlements/entitlements-plugin.js.map +1 -0
- package/dist/plugins/entitlements/index.d.ts +12 -0
- package/dist/plugins/entitlements/index.d.ts.map +1 -0
- package/dist/plugins/entitlements/index.js +16 -0
- package/dist/plugins/entitlements/index.js.map +1 -0
- package/dist/plugins/entitlements/sources/index.d.ts +9 -0
- package/dist/plugins/entitlements/sources/index.d.ts.map +1 -0
- package/dist/plugins/entitlements/sources/index.js +9 -0
- package/dist/plugins/entitlements/sources/index.js.map +1 -0
- package/dist/plugins/entitlements/sources/postgres-source.d.ts +29 -0
- package/dist/plugins/entitlements/sources/postgres-source.d.ts.map +1 -0
- package/dist/plugins/entitlements/sources/postgres-source.js +169 -0
- package/dist/plugins/entitlements/sources/postgres-source.js.map +1 -0
- package/dist/plugins/entitlements/types.d.ts +232 -0
- package/dist/plugins/entitlements/types.d.ts.map +1 -0
- package/dist/plugins/entitlements/types.js +11 -0
- package/dist/plugins/entitlements/types.js.map +1 -0
- package/dist/plugins/frontend-app-plugin.d.ts +9 -3
- package/dist/plugins/frontend-app-plugin.d.ts.map +1 -1
- package/dist/plugins/frontend-app-plugin.js +14 -9
- package/dist/plugins/frontend-app-plugin.js.map +1 -1
- package/dist/plugins/health-plugin.d.ts +5 -2
- package/dist/plugins/health-plugin.d.ts.map +1 -1
- package/dist/plugins/health-plugin.js +20 -5
- package/dist/plugins/health-plugin.js.map +1 -1
- package/dist/plugins/index.d.ts +8 -2
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +8 -2
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/logs-plugin.d.ts +3 -2
- package/dist/plugins/logs-plugin.d.ts.map +1 -1
- package/dist/plugins/logs-plugin.js +21 -12
- package/dist/plugins/logs-plugin.js.map +1 -1
- package/dist/plugins/postgres-plugin.d.ts +3 -3
- package/dist/plugins/postgres-plugin.d.ts.map +1 -1
- package/dist/plugins/postgres-plugin.js +9 -7
- package/dist/plugins/postgres-plugin.js.map +1 -1
- package/dist/plugins/postgres-plugin.test.js +47 -29
- package/dist/plugins/postgres-plugin.test.js.map +1 -1
- package/dist/plugins/users/index.d.ts +12 -0
- package/dist/plugins/users/index.d.ts.map +1 -0
- package/dist/plugins/users/index.js +13 -0
- package/dist/plugins/users/index.js.map +1 -0
- package/dist/plugins/users/stores/index.d.ts +7 -0
- package/dist/plugins/users/stores/index.d.ts.map +1 -0
- package/dist/plugins/users/stores/index.js +7 -0
- package/dist/plugins/users/stores/index.js.map +1 -0
- package/dist/plugins/users/stores/postgres-store.d.ts +28 -0
- package/dist/plugins/users/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/users/stores/postgres-store.js +157 -0
- package/dist/plugins/users/stores/postgres-store.js.map +1 -0
- package/dist/plugins/users/types.d.ts +189 -0
- package/dist/plugins/users/types.d.ts.map +1 -0
- package/dist/plugins/users/types.js +12 -0
- package/dist/plugins/users/types.js.map +1 -0
- package/dist/plugins/users/users-plugin.d.ts +39 -0
- package/dist/plugins/users/users-plugin.d.ts.map +1 -0
- package/dist/plugins/users/users-plugin.js +242 -0
- package/dist/plugins/users/users-plugin.js.map +1 -0
- package/dist-ui/assets/index-Bsp2ntcw.js +465 -0
- package/dist-ui/assets/index-Bsp2ntcw.js.map +1 -0
- package/dist-ui/index.html +1 -1
- package/dist-ui-lib/api/controlPanelApi.d.ts +232 -0
- package/dist-ui-lib/components/ControlPanelApp.d.ts +61 -0
- package/dist-ui-lib/components/index.d.ts +18 -0
- package/dist-ui-lib/config/AppConfig.d.ts +7 -0
- package/dist-ui-lib/dashboard/DashboardWidgetRegistry.d.ts +62 -0
- package/dist-ui-lib/dashboard/DashboardWidgetRenderer.d.ts +8 -0
- package/dist-ui-lib/dashboard/PluginWidgetRenderer.d.ts +19 -0
- package/dist-ui-lib/dashboard/WidgetComponentRegistry.d.ts +44 -0
- package/dist-ui-lib/dashboard/builtInWidgets.d.ts +19 -0
- package/dist-ui-lib/dashboard/index.d.ts +13 -0
- package/dist-ui-lib/dashboard/widgets/ServiceHealthWidget.d.ts +12 -0
- package/dist-ui-lib/dashboard/widgets/index.d.ts +6 -0
- package/dist-ui-lib/index.js +6441 -0
- package/dist-ui-lib/index.js.map +1 -0
- package/dist-ui-lib/pages/ConfigPage.d.ts +1 -0
- package/dist-ui-lib/pages/DashboardPage.d.ts +1 -0
- package/dist-ui-lib/pages/DiagnosticsPage.d.ts +1 -0
- package/dist-ui-lib/pages/EntitlementsPage.d.ts +17 -0
- package/dist-ui-lib/pages/LogsPage.d.ts +1 -0
- package/dist-ui-lib/pages/NotFoundPage.d.ts +1 -0
- package/dist-ui-lib/pages/PluginPage.d.ts +15 -0
- package/dist-ui-lib/pages/SystemPage.d.ts +1 -0
- package/dist-ui-lib/pages/UsersPage.d.ts +22 -0
- package/package.json +18 -6
- package/src/core/control-panel.ts +122 -68
- package/src/core/gateway.ts +870 -399
- package/src/core/index.ts +21 -2
- package/src/core/plugin-registry.ts +653 -0
- package/src/core/types.ts +31 -37
- package/src/index.ts +118 -19
- package/src/plugins/auth/adapters/auth0-adapter.ts +214 -0
- package/src/plugins/auth/adapters/basic-adapter.ts +61 -0
- package/src/plugins/auth/adapters/index.ts +9 -0
- package/src/plugins/auth/adapters/supabase-adapter.ts +141 -0
- package/src/plugins/auth/auth-plugin.test.ts +176 -0
- package/src/plugins/auth/auth-plugin.ts +303 -0
- package/src/plugins/auth/index.ts +33 -0
- package/src/plugins/auth/types.ts +165 -0
- package/src/plugins/bans/bans-plugin.ts +485 -0
- package/src/plugins/bans/index.ts +31 -0
- package/src/plugins/bans/stores/index.ts +7 -0
- package/src/plugins/bans/stores/postgres-store.ts +195 -0
- package/src/plugins/bans/types.ts +141 -0
- package/src/plugins/cache-plugin.test.ts +105 -32
- package/src/plugins/cache-plugin.ts +40 -9
- package/src/plugins/config-plugin.ts +23 -12
- package/src/plugins/diagnostics-plugin.ts +22 -12
- package/src/plugins/entitlements/entitlements-plugin.ts +820 -0
- package/src/plugins/entitlements/index.ts +51 -0
- package/src/plugins/entitlements/sources/index.ts +9 -0
- package/src/plugins/entitlements/sources/postgres-source.ts +253 -0
- package/src/plugins/entitlements/types.ts +256 -0
- package/src/plugins/frontend-app-plugin.ts +24 -12
- package/src/plugins/health-plugin.ts +27 -7
- package/src/plugins/index.ts +106 -4
- package/src/plugins/logs-plugin.ts +28 -14
- package/src/plugins/postgres-plugin.test.ts +49 -29
- package/src/plugins/postgres-plugin.ts +11 -9
- package/src/plugins/users/index.ts +35 -0
- package/src/plugins/users/stores/index.ts +7 -0
- package/src/plugins/users/stores/postgres-store.ts +225 -0
- package/src/plugins/users/types.ts +209 -0
- package/src/plugins/users/users-plugin.ts +281 -0
- package/ui/src/App.tsx +185 -31
- package/ui/src/api/controlPanelApi.ts +354 -1
- package/ui/src/components/ControlPanelApp.tsx +209 -0
- package/ui/src/components/index.ts +62 -0
- package/ui/src/dashboard/DashboardWidgetRegistry.tsx +129 -0
- package/ui/src/dashboard/DashboardWidgetRenderer.tsx +34 -0
- package/ui/src/dashboard/PluginWidgetRenderer.tsx +115 -0
- package/ui/src/dashboard/WidgetComponentRegistry.tsx +116 -0
- package/ui/src/dashboard/builtInWidgets.tsx +29 -0
- package/ui/src/dashboard/index.ts +35 -0
- package/ui/src/dashboard/widgets/ServiceHealthWidget.tsx +140 -0
- package/ui/src/dashboard/widgets/index.ts +7 -0
- package/ui/src/pages/DashboardPage.tsx +28 -149
- package/ui/src/pages/EntitlementsPage.tsx +557 -0
- package/ui/src/pages/LogsPage.tsx +174 -8
- package/ui/src/pages/PluginPage.tsx +148 -0
- package/ui/src/pages/SystemPage.tsx +445 -0
- package/ui/src/pages/UsersPage.tsx +837 -0
- package/ui/tsconfig.lib.json +11 -0
- package/ui/vite.lib.config.ts +51 -0
- package/dist-ui/assets/index-CW1BviRn.js +0 -465
- package/dist-ui/assets/index-CW1BviRn.js.map +0 -1
- package/ui/src/pages/HealthPage.tsx +0 -204
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Users Plugin
|
|
3
|
+
*
|
|
4
|
+
* User identity management plugin for @qwickapps/server.
|
|
5
|
+
* Provides CRUD operations, search, and user lookup functionality.
|
|
6
|
+
*
|
|
7
|
+
* Note: Ban management is handled by the separate Bans Plugin.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
10
|
+
*/
|
|
11
|
+
// Store instance for helper access
|
|
12
|
+
let currentStore = null;
|
|
13
|
+
/**
|
|
14
|
+
* Create the Users plugin
|
|
15
|
+
*/
|
|
16
|
+
export function createUsersPlugin(config) {
|
|
17
|
+
const debug = config.debug || false;
|
|
18
|
+
// Routes are mounted under /api by the control panel, so don't include /api in prefix
|
|
19
|
+
const apiPrefix = config.api?.prefix || '/users';
|
|
20
|
+
function log(message, data) {
|
|
21
|
+
if (debug) {
|
|
22
|
+
console.log(`[UsersPlugin] ${message}`, data || '');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
id: 'users',
|
|
27
|
+
name: 'Users',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
async onStart(_pluginConfig, registry) {
|
|
30
|
+
log('Starting users plugin');
|
|
31
|
+
// Initialize the store (creates tables if needed)
|
|
32
|
+
await config.store.initialize();
|
|
33
|
+
log('Users plugin migrations complete');
|
|
34
|
+
// Store reference for helper access
|
|
35
|
+
currentStore = config.store;
|
|
36
|
+
// Register health check
|
|
37
|
+
registry.registerHealthCheck({
|
|
38
|
+
name: 'users-store',
|
|
39
|
+
type: 'custom',
|
|
40
|
+
check: async () => {
|
|
41
|
+
try {
|
|
42
|
+
// Simple health check - try to search with limit 1
|
|
43
|
+
await config.store.search({ limit: 1 });
|
|
44
|
+
return { healthy: true };
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { healthy: false };
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
// Add API routes if enabled
|
|
52
|
+
if (config.api?.crud !== false) {
|
|
53
|
+
// List/Search users
|
|
54
|
+
registry.addRoute({
|
|
55
|
+
method: 'get',
|
|
56
|
+
path: apiPrefix,
|
|
57
|
+
pluginId: 'users',
|
|
58
|
+
handler: async (req, res) => {
|
|
59
|
+
try {
|
|
60
|
+
const params = {
|
|
61
|
+
query: req.query.q,
|
|
62
|
+
provider: req.query.provider,
|
|
63
|
+
page: parseInt(req.query.page) || 1,
|
|
64
|
+
limit: Math.min(parseInt(req.query.limit) || 20, 100),
|
|
65
|
+
sortBy: req.query.sortBy || 'created_at',
|
|
66
|
+
sortOrder: req.query.sortOrder || 'desc',
|
|
67
|
+
};
|
|
68
|
+
const result = await config.store.search(params);
|
|
69
|
+
res.json(result);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('[UsersPlugin] Search error:', error);
|
|
73
|
+
res.status(500).json({ error: 'Failed to search users' });
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
// Get user by ID
|
|
78
|
+
registry.addRoute({
|
|
79
|
+
method: 'get',
|
|
80
|
+
path: `${apiPrefix}/:id`,
|
|
81
|
+
pluginId: 'users',
|
|
82
|
+
handler: async (req, res) => {
|
|
83
|
+
try {
|
|
84
|
+
const user = await config.store.getById(req.params.id);
|
|
85
|
+
if (!user) {
|
|
86
|
+
return res.status(404).json({ error: 'User not found' });
|
|
87
|
+
}
|
|
88
|
+
res.json(user);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('[UsersPlugin] Get user error:', error);
|
|
92
|
+
res.status(500).json({ error: 'Failed to get user' });
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
// Create user
|
|
97
|
+
registry.addRoute({
|
|
98
|
+
method: 'post',
|
|
99
|
+
path: apiPrefix,
|
|
100
|
+
pluginId: 'users',
|
|
101
|
+
handler: async (req, res) => {
|
|
102
|
+
try {
|
|
103
|
+
const input = {
|
|
104
|
+
email: req.body.email,
|
|
105
|
+
name: req.body.name,
|
|
106
|
+
external_id: req.body.external_id,
|
|
107
|
+
provider: req.body.provider,
|
|
108
|
+
picture: req.body.picture,
|
|
109
|
+
metadata: req.body.metadata,
|
|
110
|
+
};
|
|
111
|
+
if (!input.email) {
|
|
112
|
+
return res.status(400).json({ error: 'Email is required' });
|
|
113
|
+
}
|
|
114
|
+
// Check if user already exists
|
|
115
|
+
const existing = await config.store.getByEmail(input.email);
|
|
116
|
+
if (existing) {
|
|
117
|
+
return res.status(409).json({ error: 'User with this email already exists' });
|
|
118
|
+
}
|
|
119
|
+
const user = await config.store.create(input);
|
|
120
|
+
res.status(201).json(user);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error('[UsersPlugin] Create user error:', error);
|
|
124
|
+
res.status(500).json({ error: 'Failed to create user' });
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
// Update user
|
|
129
|
+
registry.addRoute({
|
|
130
|
+
method: 'put',
|
|
131
|
+
path: `${apiPrefix}/:id`,
|
|
132
|
+
pluginId: 'users',
|
|
133
|
+
handler: async (req, res) => {
|
|
134
|
+
try {
|
|
135
|
+
const input = {
|
|
136
|
+
name: req.body.name,
|
|
137
|
+
picture: req.body.picture,
|
|
138
|
+
metadata: req.body.metadata,
|
|
139
|
+
};
|
|
140
|
+
const user = await config.store.update(req.params.id, input);
|
|
141
|
+
if (!user) {
|
|
142
|
+
return res.status(404).json({ error: 'User not found' });
|
|
143
|
+
}
|
|
144
|
+
res.json(user);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error('[UsersPlugin] Update user error:', error);
|
|
148
|
+
res.status(500).json({ error: 'Failed to update user' });
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
// Delete user
|
|
153
|
+
registry.addRoute({
|
|
154
|
+
method: 'delete',
|
|
155
|
+
path: `${apiPrefix}/:id`,
|
|
156
|
+
pluginId: 'users',
|
|
157
|
+
handler: async (req, res) => {
|
|
158
|
+
try {
|
|
159
|
+
const deleted = await config.store.delete(req.params.id);
|
|
160
|
+
if (!deleted) {
|
|
161
|
+
return res.status(404).json({ error: 'User not found' });
|
|
162
|
+
}
|
|
163
|
+
res.status(204).send();
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.error('[UsersPlugin] Delete user error:', error);
|
|
167
|
+
res.status(500).json({ error: 'Failed to delete user' });
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
log('Users plugin started');
|
|
173
|
+
},
|
|
174
|
+
async onStop() {
|
|
175
|
+
log('Stopping users plugin');
|
|
176
|
+
await config.store.shutdown();
|
|
177
|
+
currentStore = null;
|
|
178
|
+
log('Users plugin stopped');
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
// ========================================
|
|
183
|
+
// Helper Functions
|
|
184
|
+
// ========================================
|
|
185
|
+
/**
|
|
186
|
+
* Get the current user store instance
|
|
187
|
+
*/
|
|
188
|
+
export function getUserStore() {
|
|
189
|
+
return currentStore;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get a user by ID
|
|
193
|
+
*/
|
|
194
|
+
export async function getUserById(id) {
|
|
195
|
+
if (!currentStore) {
|
|
196
|
+
throw new Error('Users plugin not initialized');
|
|
197
|
+
}
|
|
198
|
+
return currentStore.getById(id);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get a user by email
|
|
202
|
+
*/
|
|
203
|
+
export async function getUserByEmail(email) {
|
|
204
|
+
if (!currentStore) {
|
|
205
|
+
throw new Error('Users plugin not initialized');
|
|
206
|
+
}
|
|
207
|
+
return currentStore.getByEmail(email);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Find or create a user from auth provider data
|
|
211
|
+
*/
|
|
212
|
+
export async function findOrCreateUser(data) {
|
|
213
|
+
if (!currentStore) {
|
|
214
|
+
throw new Error('Users plugin not initialized');
|
|
215
|
+
}
|
|
216
|
+
// Try to find by external ID first
|
|
217
|
+
let user = await currentStore.getByExternalId(data.external_id, data.provider);
|
|
218
|
+
if (user) {
|
|
219
|
+
await currentStore.updateLastLogin(user.id);
|
|
220
|
+
return user;
|
|
221
|
+
}
|
|
222
|
+
// Try to find by email
|
|
223
|
+
user = await currentStore.getByEmail(data.email);
|
|
224
|
+
if (user) {
|
|
225
|
+
// Update with external ID if not set
|
|
226
|
+
if (!user.external_id) {
|
|
227
|
+
await currentStore.update(user.id, {});
|
|
228
|
+
}
|
|
229
|
+
await currentStore.updateLastLogin(user.id);
|
|
230
|
+
return user;
|
|
231
|
+
}
|
|
232
|
+
// Create new user
|
|
233
|
+
user = await currentStore.create({
|
|
234
|
+
email: data.email,
|
|
235
|
+
name: data.name,
|
|
236
|
+
external_id: data.external_id,
|
|
237
|
+
provider: data.provider,
|
|
238
|
+
picture: data.picture,
|
|
239
|
+
});
|
|
240
|
+
return user;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=users-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users-plugin.js","sourceRoot":"","sources":["../../../src/plugins/users/users-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,mCAAmC;AACnC,IAAI,YAAY,GAAqB,IAAI,CAAC;AAE1C;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAyB;IACzD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;IACpC,sFAAsF;IACtF,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,IAAI,QAAQ,CAAC;IAEjD,SAAS,GAAG,CAAC,OAAe,EAAE,IAA8B;QAC1D,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,GAAG,CAAC,iBAAiB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,OAAO;QAEhB,KAAK,CAAC,OAAO,CAAC,aAA2B,EAAE,QAAwB;YACjE,GAAG,CAAC,uBAAuB,CAAC,CAAC;YAE7B,kDAAkD;YAClD,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YAChC,GAAG,CAAC,kCAAkC,CAAC,CAAC;YAExC,oCAAoC;YACpC,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC;YAE5B,wBAAwB;YACxB,QAAQ,CAAC,mBAAmB,CAAC;gBAC3B,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,KAAK,IAAI,EAAE;oBAChB,IAAI,CAAC;wBACH,mDAAmD;wBACnD,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;wBACxC,OAAO,EAAE,OA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