@makolabs/ripple 1.2.11 → 1.2.12
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { query, command } from '$app/server';
|
|
2
|
+
import { getRequestEvent } from '$app/server';
|
|
2
3
|
import { env } from '$env/dynamic/private';
|
|
3
4
|
const CLIENT_ID = env.CLIENT_ID || 'sharkfin';
|
|
4
5
|
const PERMISSION_PREFIX = env.PERMISSION_PREFIX || 'sharkfin:';
|
|
@@ -299,6 +300,40 @@ export const getUserPermissions = query.batch('unchecked', async (userIds) => {
|
|
|
299
300
|
};
|
|
300
301
|
}
|
|
301
302
|
});
|
|
303
|
+
async function refreshTokenIfSelfUpdate(userId) {
|
|
304
|
+
try {
|
|
305
|
+
const event = getRequestEvent();
|
|
306
|
+
if (!event?.locals)
|
|
307
|
+
return;
|
|
308
|
+
// Try to get current user - this is app-specific, so we check if the method exists
|
|
309
|
+
const getAuth = event.locals.auth;
|
|
310
|
+
if (!getAuth)
|
|
311
|
+
return;
|
|
312
|
+
const currentUser = getAuth();
|
|
313
|
+
const isSelfUpdate = currentUser?.userId === userId;
|
|
314
|
+
if (isSelfUpdate) {
|
|
315
|
+
try {
|
|
316
|
+
// Try to dynamically import token manager - this is app-specific
|
|
317
|
+
// Use Function constructor to avoid TypeScript checking the import path
|
|
318
|
+
const importPath = '$lib/server/auth-hooks/token-manager.server';
|
|
319
|
+
const tokenManager = await new Function('path', 'return import(path)')(importPath).catch(() => null);
|
|
320
|
+
if (tokenManager?.clearTokenCookies &&
|
|
321
|
+
tokenManager?.getAccessToken &&
|
|
322
|
+
tokenManager?.setClientAccessibleToken) {
|
|
323
|
+
tokenManager.clearTokenCookies(event.cookies);
|
|
324
|
+
const newToken = await tokenManager.getAccessToken(event.cookies, event, true);
|
|
325
|
+
tokenManager.setClientAccessibleToken(event.cookies, newToken);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
// Token refresh not available in this app, skip silently
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
// Token refresh not available in this app, skip silently
|
|
335
|
+
}
|
|
336
|
+
}
|
|
302
337
|
export const updateUserPermissions = command('unchecked', async (options) => {
|
|
303
338
|
const { userId, permissions } = options;
|
|
304
339
|
try {
|
|
@@ -308,6 +343,7 @@ export const updateUserPermissions = command('unchecked', async (options) => {
|
|
|
308
343
|
method: 'PUT',
|
|
309
344
|
body: JSON.stringify({ scopes: permissions })
|
|
310
345
|
});
|
|
346
|
+
await refreshTokenIfSelfUpdate(userId);
|
|
311
347
|
return;
|
|
312
348
|
}
|
|
313
349
|
catch {
|
|
@@ -320,10 +356,12 @@ export const updateUserPermissions = command('unchecked', async (options) => {
|
|
|
320
356
|
method: 'PUT',
|
|
321
357
|
body: JSON.stringify({ scopes: permissions })
|
|
322
358
|
});
|
|
359
|
+
await refreshTokenIfSelfUpdate(userId);
|
|
323
360
|
return;
|
|
324
361
|
}
|
|
325
362
|
else {
|
|
326
363
|
await createUserPermissions(userId, permissions);
|
|
364
|
+
await refreshTokenIfSelfUpdate(userId);
|
|
327
365
|
return;
|
|
328
366
|
}
|
|
329
367
|
}
|
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
* @see https://svelte.dev/docs/kit/remote-functions
|
|
8
8
|
*/
|
|
9
9
|
export type { GetUsersOptions, GetUsersResult } from './types.js';
|
|
10
|
-
export * from './
|
|
10
|
+
export * from './UserManagement.remote.js';
|
|
11
|
+
export * as MockUserManagement from './mockUserManagement.js';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @see https://svelte.dev/docs/kit/remote-functions
|
|
8
8
|
*/
|
|
9
|
-
// Export
|
|
10
|
-
export * from './
|
|
11
|
-
//
|
|
12
|
-
|
|
9
|
+
// Export default remote functions implementation
|
|
10
|
+
export * from './UserManagement.remote.js';
|
|
11
|
+
// Export mock adapter functions for testing/storybook (with different names to avoid conflicts)
|
|
12
|
+
export * as MockUserManagement from './mockUserManagement.js';
|
|
@@ -110,6 +110,7 @@ export interface UserManagementProps {
|
|
|
110
110
|
/**
|
|
111
111
|
* Adapter module containing remote functions or async functions
|
|
112
112
|
* Should be imported from a .remote.ts file
|
|
113
|
+
* If not provided, uses the default adapter from @makolabs/ripple
|
|
113
114
|
*
|
|
114
115
|
* Example:
|
|
115
116
|
* ```ts
|
|
@@ -117,7 +118,7 @@ export interface UserManagementProps {
|
|
|
117
118
|
* <UserManagement adapter={adapter} roles={roles} />
|
|
118
119
|
* ```
|
|
119
120
|
*/
|
|
120
|
-
adapter
|
|
121
|
+
adapter?: UserManagementAdapter;
|
|
121
122
|
/**
|
|
122
123
|
* Available roles for user assignment
|
|
123
124
|
*/
|