@makolabs/ripple 1.2.13 → 1.2.16

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.
@@ -2,23 +2,20 @@
2
2
  * Mock User Management Functions
3
3
  *
4
4
  * Mock implementation of user management functions for testing and development.
5
- * These are regular async functions that match the UserManagementAdapter interface.
6
- * They store data in memory.
5
+ * These are regular async functions (NOT remote functions) that match the UserManagementAdapter interface.
6
+ * They store data in memory and work in both SvelteKit and non-SvelteKit contexts (like Storybook).
7
7
  *
8
- * Note: This file uses .remote.ts extension for naming consistency, but these are
9
- * NOT actual SvelteKit remote functions. They are regular async functions that
10
- * work in both test and library contexts.
11
- *
12
- * For actual remote functions in your app, see UserManagement.remote.ts template.
8
+ * Note: These are NOT actual remote functions because remote functions require a SvelteKit server context
9
+ * which doesn't exist in Storybook/tests. They're regular async functions that match the adapter interface.
13
10
  *
14
11
  * To set initial data, use the resetState function:
15
12
  * ```ts
16
- * import { resetState } from './mockUserManagement.js';
13
+ * import { resetState } from '@makolabs/ripple/funcs/mock-user-management';
17
14
  * await resetState({ initialUsers: [...], simulateDelay: false });
18
15
  * ```
19
16
  */
20
- import type { User } from '../user-management.js';
21
- import type { GetUsersOptions, GetUsersResult } from './types.js';
17
+ import type { User } from '../user-management/user-management.js';
18
+ import type { GetUsersOptions, GetUsersResult } from '../user-management/types.js';
22
19
  /**
23
20
  * Reset mock adapter state
24
21
  */
@@ -68,3 +65,16 @@ export declare function updateUserPermissions(options: {
68
65
  userId: string;
69
66
  permissions: string[];
70
67
  }): Promise<void>;
68
+ /**
69
+ * Generate API key (mock implementation)
70
+ * Matches UserManagementAdapter.generateApiKey signature
71
+ */
72
+ export declare function generateApiKey(options: {
73
+ userId: string;
74
+ permissions: string[];
75
+ revokeOld?: boolean;
76
+ }): Promise<{
77
+ success: boolean;
78
+ apiKey: string;
79
+ message: string;
80
+ }>;
@@ -2,18 +2,15 @@
2
2
  * Mock User Management Functions
3
3
  *
4
4
  * Mock implementation of user management functions for testing and development.
5
- * These are regular async functions that match the UserManagementAdapter interface.
6
- * They store data in memory.
5
+ * These are regular async functions (NOT remote functions) that match the UserManagementAdapter interface.
6
+ * They store data in memory and work in both SvelteKit and non-SvelteKit contexts (like Storybook).
7
7
  *
8
- * Note: This file uses .remote.ts extension for naming consistency, but these are
9
- * NOT actual SvelteKit remote functions. They are regular async functions that
10
- * work in both test and library contexts.
11
- *
12
- * For actual remote functions in your app, see UserManagement.remote.ts template.
8
+ * Note: These are NOT actual remote functions because remote functions require a SvelteKit server context
9
+ * which doesn't exist in Storybook/tests. They're regular async functions that match the adapter interface.
13
10
  *
14
11
  * To set initial data, use the resetState function:
15
12
  * ```ts
16
- * import { resetState } from './mockUserManagement.js';
13
+ * import { resetState } from '@makolabs/ripple/funcs/mock-user-management';
17
14
  * await resetState({ initialUsers: [...], simulateDelay: false });
18
15
  * ```
19
16
  */
@@ -21,11 +18,6 @@
21
18
  let mockUsers = [];
22
19
  let simulateDelay = false;
23
20
  let delayMs = 300;
24
- async function delay() {
25
- if (simulateDelay) {
26
- await new Promise((resolve) => setTimeout(resolve, delayMs));
27
- }
28
- }
29
21
  /**
30
22
  * Reset mock adapter state
31
23
  */
@@ -34,6 +26,11 @@ export async function resetState(options = {}) {
34
26
  simulateDelay = options.simulateDelay ?? false;
35
27
  delayMs = options.delayMs ?? 300;
36
28
  }
29
+ async function delay() {
30
+ if (simulateDelay) {
31
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
32
+ }
33
+ }
37
34
  /**
38
35
  * Get users with pagination and sorting
39
36
  * Matches UserManagementAdapter.getUsers signature
@@ -133,7 +130,7 @@ export async function updateUser(options) {
133
130
  const updatedUser = {
134
131
  ...mockUsers[userIndex],
135
132
  ...userData,
136
- id: userId // Ensure ID doesn't change
133
+ id: userId
137
134
  };
138
135
  mockUsers[userIndex] = updatedUser;
139
136
  return updatedUser;
@@ -185,3 +182,27 @@ export async function updateUserPermissions(options) {
185
182
  }
186
183
  user.permissions = permissions;
187
184
  }
185
+ /**
186
+ * Generate API key (mock implementation)
187
+ * Matches UserManagementAdapter.generateApiKey signature
188
+ */
189
+ export async function generateApiKey(options) {
190
+ await delay();
191
+ const { userId } = options;
192
+ const user = mockUsers.find((u) => u.id === userId);
193
+ if (!user) {
194
+ throw new Error(`User with ID ${userId} not found`);
195
+ }
196
+ const apiKey = `mock_api_key_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
197
+ if (!user.private_metadata) {
198
+ user.private_metadata = {};
199
+ }
200
+ user.private_metadata.mako_api_key = apiKey;
201
+ return {
202
+ success: true,
203
+ apiKey,
204
+ message: options.revokeOld
205
+ ? 'New API key generated and old key revoked successfully'
206
+ : 'API key generated successfully'
207
+ };
208
+ }
@@ -1,5 +1,5 @@
1
- import type { User } from '../user-management.js';
2
- import type { GetUsersOptions, GetUsersResult } from './types.js';
1
+ import type { User } from '../user-management/user-management.js';
2
+ import type { GetUsersOptions, GetUsersResult } from '../user-management/types.js';
3
3
  export declare const getUsers: import("@sveltejs/kit").RemoteQueryFunction<GetUsersOptions, GetUsersResult>;
4
4
  export declare const createUser: import("@sveltejs/kit").RemoteCommand<Partial<User>, Promise<User>>;
5
5
  export declare const updateUser: import("@sveltejs/kit").RemoteCommand<{
@@ -6,10 +6,9 @@
6
6
  import UserViewModal from './UserViewModal.svelte';
7
7
  import type { User, UserManagementProps, Role, Permission } from './user-management.js';
8
8
  import { SvelteSet } from 'svelte/reactivity';
9
- import * as UserManagementAdapter from './adapters/index.js';
10
9
 
11
10
  let {
12
- adapter = UserManagementAdapter,
11
+ adapter,
13
12
  roles: initialRoles = [],
14
13
  permissions: initialPermissions = [],
15
14
  class: className
@@ -42,6 +41,7 @@
42
41
  async function loadUsers() {
43
42
  try {
44
43
  loading = true;
44
+ console.log('loading users', adapter);
45
45
  const result = await adapter.getUsers({
46
46
  page: currentPage,
47
47
  pageSize,
@@ -2,8 +2,8 @@
2
2
  import { onMount } from 'svelte';
3
3
  import UserManagement from './UserManagement.svelte';
4
4
  import type { UserManagementProps } from './user-management.js';
5
- import * as mockAdapter from './adapters/mockUserManagement.js';
6
- import { resetState } from './adapters/mockUserManagement.js';
5
+ import * as mockAdapter from '../funcs/mock-user-management.js';
6
+ import { resetState } from '../funcs/mock-user-management.js';
7
7
  import type { User, Role, Permission } from './user-management.js';
8
8
 
9
9
  interface Props extends Omit<UserManagementProps, 'adapter'> {
@@ -7,6 +7,7 @@ export { default as UserTable } from './UserTable.svelte';
7
7
  export { default as UserModal } from './UserModal.svelte';
8
8
  export { default as UserViewModal } from './UserViewModal.svelte';
9
9
  export type { User, UserEmail, UserPhone, Permission, Role, UserTableProps, UserModalProps, UserViewModalProps, UserManagementProps, FormErrors } from './user-management.js';
10
- export type { GetUsersOptions, GetUsersResult } from './adapters/index.js';
10
+ export type { GetUsersOptions, GetUsersResult } from './types.js';
11
11
  export type { UserManagementAdapter } from './user-management.js';
12
- export { createUser, getUserDisplayName, getUserInitials } from './user-management.js';
12
+ export { getUsers, createUser as createUserRemote, updateUser, deleteUser, deleteUsers, getUserPermissions, updateUserPermissions, generateApiKey } from '../funcs/user-management.remote.js';
13
+ export { getUserDisplayName, getUserInitials } from './user-management.js';
@@ -7,5 +7,7 @@ export { default as UserManagement } from './UserManagement.svelte';
7
7
  export { default as UserTable } from './UserTable.svelte';
8
8
  export { default as UserModal } from './UserModal.svelte';
9
9
  export { default as UserViewModal } from './UserViewModal.svelte';
10
+ // Remote Functions - export all remote functions for direct use
11
+ export { getUsers, createUser as createUserRemote, updateUser, deleteUser, deleteUsers, getUserPermissions, updateUserPermissions, generateApiKey } from '../funcs/user-management.remote.js';
10
12
  // Utilities
11
- export { createUser, getUserDisplayName, getUserInitials } from './user-management.js';
13
+ export { getUserDisplayName, getUserInitials } from './user-management.js';
@@ -1,10 +1,9 @@
1
1
  /**
2
- * User Management Adapter Types
2
+ * User Management Types
3
3
  *
4
- * Shared types for user management adapters.
5
- * These types are used by both remote function modules and the component.
4
+ * Shared types for user management remote functions.
6
5
  */
7
- import type { User } from '../user-management.js';
6
+ import type { User } from './user-management.js';
8
7
  /**
9
8
  * Options for fetching users
10
9
  */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * User Management Types
3
+ *
4
+ * Shared types for user management remote functions.
5
+ */
6
+ export {};
@@ -72,7 +72,7 @@ export interface UserViewModalProps {
72
72
  onClose: () => void;
73
73
  class?: ClassValue;
74
74
  }
75
- import type { GetUsersOptions, GetUsersResult } from './adapters/types.js';
75
+ import type { GetUsersOptions, GetUsersResult } from './types.js';
76
76
  /**
77
77
  * User Management Adapter Interface
78
78
  *
@@ -118,7 +118,7 @@ export interface UserManagementProps {
118
118
  * <UserManagement adapter={adapter} roles={roles} />
119
119
  * ```
120
120
  */
121
- adapter?: UserManagementAdapter;
121
+ adapter: UserManagementAdapter;
122
122
  /**
123
123
  * Available roles for user assignment
124
124
  */
@@ -132,6 +132,5 @@ export interface UserManagementProps {
132
132
  export interface FormErrors {
133
133
  [key: string]: string;
134
134
  }
135
- export declare function createUser(partial?: Partial<User>): User;
136
135
  export declare function getUserDisplayName(user: User | null): string;
137
136
  export declare function getUserInitials(user: User | null): string;
@@ -2,19 +2,6 @@
2
2
  * User Management Types
3
3
  * Type definitions for user management components
4
4
  */
5
- // Export convenience function to create a user object
6
- export function createUser(partial = {}) {
7
- return {
8
- id: '',
9
- first_name: '',
10
- last_name: '',
11
- username: '',
12
- email_addresses: [],
13
- phone_numbers: [],
14
- permissions: [],
15
- ...partial
16
- };
17
- }
18
5
  // Export convenience function to format user display name
19
6
  export function getUserDisplayName(user) {
20
7
  if (!user)
@@ -0,0 +1,7 @@
1
+ /**
2
+ * User Management Remote Functions
3
+ *
4
+ * Re-export from funcs for backward compatibility and internal use.
5
+ * The actual implementation is in ../funcs/user-management.remote.ts
6
+ */
7
+ export * from '../funcs/user-management.remote.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * User Management Remote Functions
3
+ *
4
+ * Re-export from funcs for backward compatibility and internal use.
5
+ * The actual implementation is in ../funcs/user-management.remote.ts
6
+ */
7
+ export * from '../funcs/user-management.remote.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makolabs/ripple",
3
- "version": "1.2.13",
3
+ "version": "1.2.16",
4
4
  "description": "Simple Svelte 5 powered component library ✨",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -1,11 +0,0 @@
1
- /**
2
- * User Management Adapters
3
- *
4
- * Adapters are remote function modules (.remote.ts files) that export
5
- * query/command functions.
6
- *
7
- * @see https://svelte.dev/docs/kit/remote-functions
8
- */
9
- export type { GetUsersOptions, GetUsersResult } from './types.js';
10
- export * from './UserManagement.remote.js';
11
- export * as MockUserManagement from './mockUserManagement.js';
@@ -1,12 +0,0 @@
1
- /**
2
- * User Management Adapters
3
- *
4
- * Adapters are remote function modules (.remote.ts files) that export
5
- * query/command functions.
6
- *
7
- * @see https://svelte.dev/docs/kit/remote-functions
8
- */
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';
@@ -1,7 +0,0 @@
1
- /**
2
- * User Management Adapter Types
3
- *
4
- * Shared types for user management adapters.
5
- * These types are used by both remote function modules and the component.
6
- */
7
- export {};